go-libwebp

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

libwebp_windows_arm64.go (2132688B)


      1 // Code generated for windows/arm64 by 'ccgo --goos=windows --goarch=arm64 --package-name=webp -ignore-asm-errors --cpp=x86_64-w64-mingw32-gcc -o /home/jfm/Source/Personal/go-libwebp/tools/../lib/transpiled/webp/libwebp_windows_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 windows && 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 E2BIG = 7
     37 const EACCES = 13
     38 const EADDRINUSE = 100
     39 const EADDRNOTAVAIL = 101
     40 const EAFNOSUPPORT = 102
     41 const EAGAIN = 11
     42 const EALREADY = 103
     43 const EBADF = 9
     44 const EBADMSG = 104
     45 const EBUSY = 16
     46 const ECANCELED = 105
     47 const ECHILD = 10
     48 const ECONNABORTED = 106
     49 const ECONNREFUSED = 107
     50 const ECONNRESET = 108
     51 const EDEADLK = 36
     52 const EDEADLOCK = "EDEADLK"
     53 const EDESTADDRREQ = 109
     54 const EDOM = 33
     55 const EEXIST = 17
     56 const EFAULT = 14
     57 const EFBIG = 27
     58 const EHOSTUNREACH = 110
     59 const EIDRM = 111
     60 const EILSEQ = 42
     61 const EINPROGRESS = 112
     62 const EINTR = 4
     63 const EINVAL = 22
     64 const EIO = 5
     65 const EISCONN = 113
     66 const EISDIR = 21
     67 const ELOOP = 114
     68 const EMFILE = 24
     69 const EMLINK = 31
     70 const EMSGSIZE = 115
     71 const ENAMETOOLONG = 38
     72 const ENETDOWN = 116
     73 const ENETRESET = 117
     74 const ENETUNREACH = 118
     75 const ENFILE = 23
     76 const ENOBUFS = 119
     77 const ENODATA = 120
     78 const ENODEV = 19
     79 const ENOENT = 2
     80 const ENOEXEC = 8
     81 const ENOFILE = "ENOENT"
     82 const ENOLCK = 39
     83 const ENOLINK = 121
     84 const ENOMEM = 12
     85 const ENOMSG = 122
     86 const ENOPROTOOPT = 123
     87 const ENOSPC = 28
     88 const ENOSR = 124
     89 const ENOSTR = 125
     90 const ENOSYS = 40
     91 const ENOTCONN = 126
     92 const ENOTDIR = 20
     93 const ENOTEMPTY = 41
     94 const ENOTRECOVERABLE = 127
     95 const ENOTSOCK = 128
     96 const ENOTSUP = 129
     97 const ENOTTY = 25
     98 const ENXIO = 6
     99 const EOPNOTSUPP = 130
    100 const EOVERFLOW = 132
    101 const EOWNERDEAD = 133
    102 const EPERM = 1
    103 const EPIPE = 32
    104 const EPROTO = 134
    105 const EPROTONOSUPPORT = 135
    106 const EPROTOTYPE = 136
    107 const ERANGE = 34
    108 const EROFS = 30
    109 const ESPIPE = 29
    110 const ESRCH = 3
    111 const ETIME = 137
    112 const ETIMEDOUT = 138
    113 const ETXTBSY = 139
    114 const EWOULDBLOCK = 140
    115 const EXDEV = 18
    116 const EXIT_FAILURE = 1
    117 const EXIT_SUCCESS = 0
    118 const HAVE_BUILTIN_BSWAP16 = 1
    119 const HAVE_BUILTIN_BSWAP32 = 1
    120 const HAVE_BUILTIN_BSWAP64 = 1
    121 const HAVE_CONFIG_H = 1
    122 const HUFFMAN_CODES_PER_META_CODE = 5
    123 const HUFFMAN_PACKED_BITS = 6
    124 const HUFFMAN_TABLE_BITS = 8
    125 const INT16_MAX = 32767
    126 const INT32_MAX = 2147483647
    127 const INT64_MAX = 9223372036854775807
    128 const INT8_MAX = 127
    129 const INTMAX_MAX = "INT64_MAX"
    130 const INTMAX_MIN = "INT64_MIN"
    131 const INTPTR_MAX = "INT64_MAX"
    132 const INTPTR_MIN = "INT64_MIN"
    133 const INT_FAST16_MAX = "INT16_MAX"
    134 const INT_FAST16_MIN = "INT16_MIN"
    135 const INT_FAST32_MAX = "INT32_MAX"
    136 const INT_FAST32_MIN = "INT32_MIN"
    137 const INT_FAST64_MAX = "INT64_MAX"
    138 const INT_FAST64_MIN = "INT64_MIN"
    139 const INT_FAST8_MAX = "INT8_MAX"
    140 const INT_FAST8_MIN = "INT8_MIN"
    141 const INT_LEAST16_MAX = "INT16_MAX"
    142 const INT_LEAST16_MIN = "INT16_MIN"
    143 const INT_LEAST32_MAX = "INT32_MAX"
    144 const INT_LEAST32_MIN = "INT32_MIN"
    145 const INT_LEAST64_MAX = "INT64_MAX"
    146 const INT_LEAST64_MIN = "INT64_MIN"
    147 const INT_LEAST8_MAX = "INT8_MAX"
    148 const INT_LEAST8_MIN = "INT8_MIN"
    149 const LENGTHS_TABLE_BITS = 7
    150 const LOCAL_CLANG_VERSION = 0
    151 const MAX_ALLOWED_CODE_LENGTH = 15
    152 const MAX_CACHE_BITS = 11
    153 const MAX_COEFF_THRESH = 31
    154 const MAX_PALETTE_SIZE = 256
    155 const MB_LEN_MAX = 5
    156 const MIN_HUFFMAN_BITS = 2
    157 const MIN_TRANSFORM_BITS = 2
    158 const MIN_WIDTH_FOR_THREADS = 512
    159 const NDEBUG = 1
    160 const NUM_DISTANCE_CODES = 40
    161 const NUM_HUFFMAN_BITS = 3
    162 const NUM_LENGTH_CODES = 24
    163 const NUM_LITERAL_CODES = 256
    164 const NUM_TRANSFORMS = 4
    165 const NUM_TRANSFORM_BITS = 3
    166 const PATH_MAX = 260
    167 const PRIX16 = "X"
    168 const PRIX32 = "X"
    169 const PRIX64 = "llX"
    170 const PRIX8 = "X"
    171 const PRIXFAST16 = "X"
    172 const PRIXFAST32 = "X"
    173 const PRIXFAST64 = "PRIX64"
    174 const PRIXFAST8 = "X"
    175 const PRIXLEAST16 = "X"
    176 const PRIXLEAST32 = "X"
    177 const PRIXLEAST64 = "PRIX64"
    178 const PRIXLEAST8 = "X"
    179 const PRIXMAX = "PRIX64"
    180 const PRIXPTR = "PRIX64"
    181 const PRId16 = "d"
    182 const PRId32 = "d"
    183 const PRId64 = "lld"
    184 const PRId8 = "d"
    185 const PRIdFAST16 = "d"
    186 const PRIdFAST32 = "d"
    187 const PRIdFAST64 = "PRId64"
    188 const PRIdFAST8 = "d"
    189 const PRIdLEAST16 = "d"
    190 const PRIdLEAST32 = "d"
    191 const PRIdLEAST64 = "PRId64"
    192 const PRIdLEAST8 = "d"
    193 const PRIdMAX = "PRId64"
    194 const PRIdPTR = "PRId64"
    195 const PRIi16 = "i"
    196 const PRIi32 = "i"
    197 const PRIi64 = "lli"
    198 const PRIi8 = "i"
    199 const PRIiFAST16 = "i"
    200 const PRIiFAST32 = "i"
    201 const PRIiFAST64 = "PRIi64"
    202 const PRIiFAST8 = "i"
    203 const PRIiLEAST16 = "i"
    204 const PRIiLEAST32 = "i"
    205 const PRIiLEAST64 = "PRIi64"
    206 const PRIiLEAST8 = "i"
    207 const PRIiMAX = "PRIi64"
    208 const PRIiPTR = "PRIi64"
    209 const PRIo16 = "o"
    210 const PRIo32 = "o"
    211 const PRIo64 = "llo"
    212 const PRIo8 = "o"
    213 const PRIoFAST16 = "o"
    214 const PRIoFAST32 = "o"
    215 const PRIoFAST64 = "PRIo64"
    216 const PRIoFAST8 = "o"
    217 const PRIoLEAST16 = "o"
    218 const PRIoLEAST32 = "o"
    219 const PRIoLEAST64 = "PRIo64"
    220 const PRIoLEAST8 = "o"
    221 const PRIoMAX = "PRIo64"
    222 const PRIoPTR = "PRIo64"
    223 const PRIu16 = "u"
    224 const PRIu32 = "u"
    225 const PRIu64 = "llu"
    226 const PRIu8 = "u"
    227 const PRIuFAST16 = "u"
    228 const PRIuFAST32 = "u"
    229 const PRIuFAST64 = "PRIu64"
    230 const PRIuFAST8 = "u"
    231 const PRIuLEAST16 = "u"
    232 const PRIuLEAST32 = "u"
    233 const PRIuLEAST64 = "PRIu64"
    234 const PRIuLEAST8 = "u"
    235 const PRIuMAX = "PRIu64"
    236 const PRIuPTR = "PRIu64"
    237 const PRIx16 = "x"
    238 const PRIx32 = "x"
    239 const PRIx64 = "llx"
    240 const PRIx8 = "x"
    241 const PRIxFAST16 = "x"
    242 const PRIxFAST32 = "x"
    243 const PRIxFAST64 = "PRIx64"
    244 const PRIxFAST8 = "x"
    245 const PRIxLEAST16 = "x"
    246 const PRIxLEAST32 = "x"
    247 const PRIxLEAST64 = "PRIx64"
    248 const PRIxLEAST8 = "x"
    249 const PRIxMAX = "PRIx64"
    250 const PRIxPTR = "PRIx64"
    251 const PTRDIFF_MAX = "INT64_MAX"
    252 const PTRDIFF_MIN = "INT64_MIN"
    253 const RAND_MAX = 0x7fff
    254 const RIFF_HEADER_SIZE = 12
    255 const SCNd16 = "hd"
    256 const SCNd32 = "d"
    257 const SCNd64 = "PRId64"
    258 const SCNd8 = "hhd"
    259 const SCNdFAST16 = "hd"
    260 const SCNdFAST32 = "d"
    261 const SCNdFAST64 = "PRId64"
    262 const SCNdFAST8 = "hhd"
    263 const SCNdLEAST16 = "hd"
    264 const SCNdLEAST32 = "d"
    265 const SCNdLEAST64 = "PRId64"
    266 const SCNdLEAST8 = "hhd"
    267 const SCNdMAX = "PRId64"
    268 const SCNdPTR = "PRId64"
    269 const SCNi16 = "hi"
    270 const SCNi32 = "i"
    271 const SCNi64 = "PRIi64"
    272 const SCNi8 = "hhi"
    273 const SCNiFAST16 = "hi"
    274 const SCNiFAST32 = "i"
    275 const SCNiFAST64 = "PRIi64"
    276 const SCNiFAST8 = "hhi"
    277 const SCNiLEAST16 = "hi"
    278 const SCNiLEAST32 = "i"
    279 const SCNiLEAST64 = "PRIi64"
    280 const SCNiLEAST8 = "hhi"
    281 const SCNiMAX = "PRIi64"
    282 const SCNiPTR = "PRIi64"
    283 const SCNo16 = "ho"
    284 const SCNo32 = "o"
    285 const SCNo64 = "PRIo64"
    286 const SCNo8 = "hho"
    287 const SCNoFAST16 = "ho"
    288 const SCNoFAST32 = "o"
    289 const SCNoFAST64 = "PRIo64"
    290 const SCNoFAST8 = "hho"
    291 const SCNoLEAST16 = "ho"
    292 const SCNoLEAST32 = "o"
    293 const SCNoLEAST64 = "PRIo64"
    294 const SCNoLEAST8 = "hho"
    295 const SCNoMAX = "PRIo64"
    296 const SCNoPTR = "PRIo64"
    297 const SCNu16 = "hu"
    298 const SCNu32 = "u"
    299 const SCNu64 = "PRIu64"
    300 const SCNu8 = "hhu"
    301 const SCNuFAST16 = "hu"
    302 const SCNuFAST32 = "u"
    303 const SCNuFAST64 = "PRIu64"
    304 const SCNuFAST8 = "hhu"
    305 const SCNuLEAST16 = "hu"
    306 const SCNuLEAST32 = "u"
    307 const SCNuLEAST64 = "PRIu64"
    308 const SCNuLEAST8 = "hhu"
    309 const SCNuMAX = "PRIu64"
    310 const SCNuPTR = "PRIu64"
    311 const SCNx16 = "hx"
    312 const SCNx32 = "x"
    313 const SCNx64 = "PRIx64"
    314 const SCNx8 = "hhx"
    315 const SCNxFAST16 = "hx"
    316 const SCNxFAST32 = "x"
    317 const SCNxFAST64 = "PRIx64"
    318 const SCNxFAST8 = "hhx"
    319 const SCNxLEAST16 = "hx"
    320 const SCNxLEAST32 = "x"
    321 const SCNxLEAST64 = "PRIx64"
    322 const SCNxLEAST8 = "hhx"
    323 const SCNxMAX = "PRIx64"
    324 const SCNxPTR = "PRIx64"
    325 const SIG_ATOMIC_MAX = "INT32_MAX"
    326 const SIG_ATOMIC_MIN = "INT32_MIN"
    327 const SIZE_MAX = "_UI64_MAX"
    328 const SSIZE_MAX = "_I64_MAX"
    329 const STRUNCATE = 80
    330 const TAG_SIZE = 4
    331 const TRANSFORM_PRESENT = 1
    332 const UINT16_MAX = 65535
    333 const UINT32_MAX = 0xffffffff
    334 const UINT64_MAX = "0xffffffffffffffffU"
    335 const UINT8_MAX = 255
    336 const UINTMAX_MAX = "UINT64_MAX"
    337 const UINTPTR_MAX = "UINT64_MAX"
    338 const UINT_FAST16_MAX = "UINT16_MAX"
    339 const UINT_FAST32_MAX = "UINT32_MAX"
    340 const UINT_FAST64_MAX = "UINT64_MAX"
    341 const UINT_FAST8_MAX = "UINT8_MAX"
    342 const UINT_LEAST16_MAX = "UINT16_MAX"
    343 const UINT_LEAST32_MAX = "UINT32_MAX"
    344 const UINT_LEAST64_MAX = "UINT64_MAX"
    345 const UINT_LEAST8_MAX = "UINT8_MAX"
    346 const UNALIGNED = "__unaligned"
    347 const USE___UUIDOF = 0
    348 const VP8L_FRAME_HEADER_SIZE = 5
    349 const VP8L_IMAGE_SIZE_BITS = 14
    350 const VP8L_LBITS = 64
    351 const VP8L_MAGIC_BYTE = 0x2f
    352 const VP8L_MAX_NUM_BIT_READ = 24
    353 const VP8L_SIGNATURE_SIZE = 1
    354 const VP8L_VERSION = 0
    355 const VP8L_VERSION_BITS = 3
    356 const VP8L_WBITS = 32
    357 const VP8X_CHUNK_SIZE = 10
    358 const VP8_DITHER_AMP_BITS = 7
    359 const VP8_DITHER_DESCALE = 4
    360 const VP8_FRAME_HEADER_SIZE = 10
    361 const VP8_RANDOM_DITHER_FIX = 8
    362 const VP8_RANDOM_TABLE_SIZE = 55
    363 const VP8_SIGNATURE = 0x9d012a
    364 const VP8_SSIM_KERNEL = 3
    365 const WCHAR_MAX = 0xffff
    366 const WCHAR_MIN = 0
    367 const WEBP_AARCH64 = 0
    368 const WEBP_ALIGN_CST = 31
    369 const WEBP_DECODER_ABI_VERSION = 528
    370 const WEBP_DSP_OMIT_C_CODE = 1
    371 const WEBP_INLINE = "inline"
    372 const WEBP_NEON_OMIT_C_CODE = 0
    373 const WEBP_NEON_WORK_AROUND_GCC = 0
    374 const WEBP_RESCALER_RFIX = 32
    375 const WEBP_RESTRICT = "__restrict__"
    376 const WEBP_SWAP_16BIT_CSP = 0
    377 const WEBP_TRANSFORM_AC3_C1 = 20091
    378 const WEBP_TRANSFORM_AC3_C2 = 35468
    379 const WIN32 = 1
    380 const WIN64 = 1
    381 const WINNT = 1
    382 const WINT_MAX = 0xffff
    383 const WINT_MIN = 0
    384 const _ALLOCA_S_HEAP_MARKER = 56797
    385 const _ALLOCA_S_MARKER_SIZE = 16
    386 const _ALLOCA_S_STACK_MARKER = 0xCCCC
    387 const _ALLOCA_S_THRESHOLD = 1024
    388 const _ANONYMOUS_STRUCT = "__MINGW_EXTENSION"
    389 const _ANONYMOUS_UNION = "__MINGW_EXTENSION"
    390 const _ARGMAX = 100
    391 const _CALL_REPORTFAULT = 0x2
    392 const _CRTIMP2 = "_CRTIMP"
    393 const _CRTIMP_ALTERNATIVE = "_CRTIMP"
    394 const _CRTIMP_NOIA64 = "_CRTIMP"
    395 const _CRTIMP_PURE = "_CRTIMP"
    396 const _FREEENTRY = 0
    397 const _HEAP_MAXREQ = 0xFFFFFFFFFFFFFFE0
    398 const _I16_MAX = 32767
    399 const _I32_MAX = 2147483647
    400 const _I64_MAX = "9223372036854775807ll"
    401 const _I8_MAX = 127
    402 const _INTEGRAL_MAX_BITS = 64
    403 const _MAX_DIR = 256
    404 const _MAX_DRIVE = 3
    405 const _MAX_ENV = 32767
    406 const _MAX_EXT = 256
    407 const _MAX_FNAME = 256
    408 const _MAX_PATH = 260
    409 const _MAX_WAIT_MALLOC_CRT = 60000
    410 const _MCRTIMP = "_CRTIMP"
    411 const _MRTIMP2 = "_CRTIMP"
    412 const _M_AMD64 = 100
    413 const _M_X64 = 100
    414 const _NLSCMPERROR = 2147483647
    415 const _OUT_TO_DEFAULT = 0
    416 const _OUT_TO_MSGBOX = 2
    417 const _OUT_TO_STDERR = 1
    418 const _REENTRANT = 1
    419 const _REPORT_ERRMODE = 3
    420 const _SECURECRT_FILL_BUFFER_PATTERN = 0xFD
    421 const _UI16_MAX = "0xffffu"
    422 const _UI32_MAX = "0xffffffffu"
    423 const _UI64_MAX = "0xffffffffffffffffull"
    424 const _UI8_MAX = "0xffu"
    425 const _USEDENTRY = 1
    426 const _WConst_return = "_CONST_RETURN"
    427 const _WIN32 = 1
    428 const _WIN32_WINNT = 0xa00
    429 const _WIN64 = 1
    430 const _WRITE_ABORT_MSG = 0x1
    431 const __ATOMIC_ACQUIRE = 2
    432 const __ATOMIC_ACQ_REL = 4
    433 const __ATOMIC_CONSUME = 1
    434 const __ATOMIC_HLE_ACQUIRE = 65536
    435 const __ATOMIC_HLE_RELEASE = 131072
    436 const __ATOMIC_RELAXED = 0
    437 const __ATOMIC_RELEASE = 3
    438 const __ATOMIC_SEQ_CST = 5
    439 const __BFLT16_DECIMAL_DIG__ = 4
    440 const __BFLT16_DENORM_MIN__ = "9.18354961579912115600575419704879436e-41B"
    441 const __BFLT16_DIG__ = 2
    442 const __BFLT16_EPSILON__ = "7.81250000000000000000000000000000000e-3B"
    443 const __BFLT16_HAS_DENORM__ = 1
    444 const __BFLT16_HAS_INFINITY__ = 1
    445 const __BFLT16_HAS_QUIET_NAN__ = 1
    446 const __BFLT16_IS_IEC_60559__ = 0
    447 const __BFLT16_MANT_DIG__ = 8
    448 const __BFLT16_MAX_10_EXP__ = 38
    449 const __BFLT16_MAX_EXP__ = 128
    450 const __BFLT16_MAX__ = "3.38953138925153547590470800371487867e+38B"
    451 const __BFLT16_MIN__ = "1.17549435082228750796873653722224568e-38B"
    452 const __BFLT16_NORM_MAX__ = "3.38953138925153547590470800371487867e+38B"
    453 const __BIGGEST_ALIGNMENT__ = 16
    454 const __BITINT_MAXWIDTH__ = 65535
    455 const __BYTE_ORDER__ = "__ORDER_LITTLE_ENDIAN__"
    456 const __C89_NAMELESS = "__MINGW_EXTENSION"
    457 const __CCGO__ = 1
    458 const __CHAR_BIT__ = 8
    459 const __CRTDECL = "__cdecl"
    460 const __DBL_DECIMAL_DIG__ = 17
    461 const __DBL_DIG__ = 15
    462 const __DBL_HAS_DENORM__ = 1
    463 const __DBL_HAS_INFINITY__ = 1
    464 const __DBL_HAS_QUIET_NAN__ = 1
    465 const __DBL_IS_IEC_60559__ = 1
    466 const __DBL_MANT_DIG__ = 53
    467 const __DBL_MAX_10_EXP__ = 308
    468 const __DBL_MAX_EXP__ = 1024
    469 const __DEC128_EPSILON__ = 1e-33
    470 const __DEC128_MANT_DIG__ = 34
    471 const __DEC128_MAX_EXP__ = 6145
    472 const __DEC128_MAX__ = "9.999999999999999999999999999999999E6144"
    473 const __DEC128_MIN__ = 1e-6143
    474 const __DEC128_SUBNORMAL_MIN__ = 0.000000000000000000000000000000001e-6143
    475 const __DEC32_EPSILON__ = 1e-6
    476 const __DEC32_MANT_DIG__ = 7
    477 const __DEC32_MAX_EXP__ = 97
    478 const __DEC32_MAX__ = 9.999999e96
    479 const __DEC32_MIN__ = 1e-95
    480 const __DEC32_SUBNORMAL_MIN__ = 0.000001e-95
    481 const __DEC64X_EPSILON__ = "1E-33D64x"
    482 const __DEC64X_MANT_DIG__ = 34
    483 const __DEC64X_MAX_EXP__ = 6145
    484 const __DEC64X_MAX__ = "9.999999999999999999999999999999999E6144D64x"
    485 const __DEC64X_MIN__ = "1E-6143D64x"
    486 const __DEC64X_SUBNORMAL_MIN__ = "0.000000000000000000000000000000001E-6143D64x"
    487 const __DEC64_EPSILON__ = 1e-15
    488 const __DEC64_MANT_DIG__ = 16
    489 const __DEC64_MAX_EXP__ = 385
    490 const __DEC64_MAX__ = "9.999999999999999E384"
    491 const __DEC64_MIN__ = 1e-383
    492 const __DEC64_SUBNORMAL_MIN__ = 0.000000000000001e-383
    493 const __DECIMAL_BID_FORMAT__ = 1
    494 const __DECIMAL_DIG__ = 21
    495 const __DEC_EVAL_METHOD__ = 2
    496 const __FINITE_MATH_ONLY__ = 0
    497 const __FLOAT_WORD_ORDER__ = "__ORDER_LITTLE_ENDIAN__"
    498 const __FLT128_DECIMAL_DIG__ = 36
    499 const __FLT128_DENORM_MIN__ = 6.47517511943802511092443895822764655e-4966
    500 const __FLT128_DIG__ = 33
    501 const __FLT128_EPSILON__ = 1.92592994438723585305597794258492732e-34
    502 const __FLT128_HAS_DENORM__ = 1
    503 const __FLT128_HAS_INFINITY__ = 1
    504 const __FLT128_HAS_QUIET_NAN__ = 1
    505 const __FLT128_IS_IEC_60559__ = 1
    506 const __FLT128_MANT_DIG__ = 113
    507 const __FLT128_MAX_10_EXP__ = 4932
    508 const __FLT128_MAX_EXP__ = 16384
    509 const __FLT128_MAX__ = "1.18973149535723176508575932662800702e+4932"
    510 const __FLT128_MIN__ = 3.36210314311209350626267781732175260e-4932
    511 const __FLT128_NORM_MAX__ = "1.18973149535723176508575932662800702e+4932"
    512 const __FLT16_DECIMAL_DIG__ = 5
    513 const __FLT16_DENORM_MIN__ = 5.96046447753906250000000000000000000e-8
    514 const __FLT16_DIG__ = 3
    515 const __FLT16_EPSILON__ = 9.76562500000000000000000000000000000e-4
    516 const __FLT16_HAS_DENORM__ = 1
    517 const __FLT16_HAS_INFINITY__ = 1
    518 const __FLT16_HAS_QUIET_NAN__ = 1
    519 const __FLT16_IS_IEC_60559__ = 1
    520 const __FLT16_MANT_DIG__ = 11
    521 const __FLT16_MAX_10_EXP__ = 4
    522 const __FLT16_MAX_EXP__ = 16
    523 const __FLT16_MAX__ = 6.55040000000000000000000000000000000e+4
    524 const __FLT16_MIN__ = 6.10351562500000000000000000000000000e-5
    525 const __FLT16_NORM_MAX__ = 6.55040000000000000000000000000000000e+4
    526 const __FLT32X_DECIMAL_DIG__ = 17
    527 const __FLT32X_DENORM_MIN__ = 4.94065645841246544176568792868221372e-324
    528 const __FLT32X_DIG__ = 15
    529 const __FLT32X_EPSILON__ = 2.22044604925031308084726333618164062e-16
    530 const __FLT32X_HAS_DENORM__ = 1
    531 const __FLT32X_HAS_INFINITY__ = 1
    532 const __FLT32X_HAS_QUIET_NAN__ = 1
    533 const __FLT32X_IS_IEC_60559__ = 1
    534 const __FLT32X_MANT_DIG__ = 53
    535 const __FLT32X_MAX_10_EXP__ = 308
    536 const __FLT32X_MAX_EXP__ = 1024
    537 const __FLT32X_MAX__ = 1.79769313486231570814527423731704357e+308
    538 const __FLT32X_MIN__ = 2.22507385850720138309023271733240406e-308
    539 const __FLT32X_NORM_MAX__ = 1.79769313486231570814527423731704357e+308
    540 const __FLT32_DECIMAL_DIG__ = 9
    541 const __FLT32_DENORM_MIN__ = 1.40129846432481707092372958328991613e-45
    542 const __FLT32_DIG__ = 6
    543 const __FLT32_EPSILON__ = 1.19209289550781250000000000000000000e-7
    544 const __FLT32_HAS_DENORM__ = 1
    545 const __FLT32_HAS_INFINITY__ = 1
    546 const __FLT32_HAS_QUIET_NAN__ = 1
    547 const __FLT32_IS_IEC_60559__ = 1
    548 const __FLT32_MANT_DIG__ = 24
    549 const __FLT32_MAX_10_EXP__ = 38
    550 const __FLT32_MAX_EXP__ = 128
    551 const __FLT32_MAX__ = 3.40282346638528859811704183484516925e+38
    552 const __FLT32_MIN__ = 1.17549435082228750796873653722224568e-38
    553 const __FLT32_NORM_MAX__ = 3.40282346638528859811704183484516925e+38
    554 const __FLT64X_DECIMAL_DIG__ = 21
    555 const __FLT64X_DENORM_MIN__ = 3.64519953188247460252840593361941982e-4951
    556 const __FLT64X_DIG__ = 18
    557 const __FLT64X_EPSILON__ = 1.08420217248550443400745280086994171e-19
    558 const __FLT64X_HAS_DENORM__ = 1
    559 const __FLT64X_HAS_INFINITY__ = 1
    560 const __FLT64X_HAS_QUIET_NAN__ = 1
    561 const __FLT64X_IS_IEC_60559__ = 1
    562 const __FLT64X_MANT_DIG__ = 64
    563 const __FLT64X_MAX_10_EXP__ = 4932
    564 const __FLT64X_MAX_EXP__ = 16384
    565 const __FLT64X_MAX__ = "1.18973149535723176502126385303097021e+4932"
    566 const __FLT64X_MIN__ = 3.36210314311209350626267781732175260e-4932
    567 const __FLT64X_NORM_MAX__ = "1.18973149535723176502126385303097021e+4932"
    568 const __FLT64_DECIMAL_DIG__ = 17
    569 const __FLT64_DENORM_MIN__ = 4.94065645841246544176568792868221372e-324
    570 const __FLT64_DIG__ = 15
    571 const __FLT64_EPSILON__ = 2.22044604925031308084726333618164062e-16
    572 const __FLT64_HAS_DENORM__ = 1
    573 const __FLT64_HAS_INFINITY__ = 1
    574 const __FLT64_HAS_QUIET_NAN__ = 1
    575 const __FLT64_IS_IEC_60559__ = 1
    576 const __FLT64_MANT_DIG__ = 53
    577 const __FLT64_MAX_10_EXP__ = 308
    578 const __FLT64_MAX_EXP__ = 1024
    579 const __FLT64_MAX__ = 1.79769313486231570814527423731704357e+308
    580 const __FLT64_MIN__ = 2.22507385850720138309023271733240406e-308
    581 const __FLT64_NORM_MAX__ = 1.79769313486231570814527423731704357e+308
    582 const __FLT_DECIMAL_DIG__ = 9
    583 const __FLT_DENORM_MIN__ = 1.40129846432481707092372958328991613e-45
    584 const __FLT_DIG__ = 6
    585 const __FLT_EPSILON__ = 1.19209289550781250000000000000000000e-7
    586 const __FLT_EVAL_METHOD_TS_18661_3__ = 0
    587 const __FLT_EVAL_METHOD__ = 0
    588 const __FLT_HAS_DENORM__ = 1
    589 const __FLT_HAS_INFINITY__ = 1
    590 const __FLT_HAS_QUIET_NAN__ = 1
    591 const __FLT_IS_IEC_60559__ = 1
    592 const __FLT_MANT_DIG__ = 24
    593 const __FLT_MAX_10_EXP__ = 38
    594 const __FLT_MAX_EXP__ = 128
    595 const __FLT_MAX__ = 3.40282346638528859811704183484516925e+38
    596 const __FLT_MIN__ = 1.17549435082228750796873653722224568e-38
    597 const __FLT_NORM_MAX__ = 3.40282346638528859811704183484516925e+38
    598 const __FLT_RADIX__ = 2
    599 const __FUNCTION__ = "__func__"
    600 const __FXSR__ = 1
    601 const __GCC_ASM_FLAG_OUTPUTS__ = 1
    602 const __GCC_ATOMIC_BOOL_LOCK_FREE = 2
    603 const __GCC_ATOMIC_CHAR16_T_LOCK_FREE = 2
    604 const __GCC_ATOMIC_CHAR32_T_LOCK_FREE = 2
    605 const __GCC_ATOMIC_CHAR8_T_LOCK_FREE = 2
    606 const __GCC_ATOMIC_CHAR_LOCK_FREE = 2
    607 const __GCC_ATOMIC_INT_LOCK_FREE = 2
    608 const __GCC_ATOMIC_LLONG_LOCK_FREE = 2
    609 const __GCC_ATOMIC_LONG_LOCK_FREE = 2
    610 const __GCC_ATOMIC_POINTER_LOCK_FREE = 2
    611 const __GCC_ATOMIC_SHORT_LOCK_FREE = 2
    612 const __GCC_ATOMIC_TEST_AND_SET_TRUEVAL = 1
    613 const __GCC_ATOMIC_WCHAR_T_LOCK_FREE = 2
    614 const __GCC_CONSTRUCTIVE_SIZE = 64
    615 const __GCC_DESTRUCTIVE_SIZE = 64
    616 const __GCC_HAVE_SYNC_COMPARE_AND_SWAP_1 = 1
    617 const __GCC_HAVE_SYNC_COMPARE_AND_SWAP_2 = 1
    618 const __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4 = 1
    619 const __GCC_HAVE_SYNC_COMPARE_AND_SWAP_8 = 1
    620 const __GCC_IEC_559 = 2
    621 const __GCC_IEC_559_COMPLEX = 2
    622 const __GNUC_EXECUTION_CHARSET_NAME = "UTF-8"
    623 const __GNUC_MINOR__ = 2
    624 const __GNUC_PATCHLEVEL__ = 0
    625 const __GNUC_STDC_INLINE__ = 1
    626 const __GNUC_WIDE_EXECUTION_CHARSET_NAME = "UTF-16LE"
    627 const __GNUC__ = 16
    628 const __GNU_EXTENSION = "__MINGW_EXTENSION"
    629 const __GOT_SECURE_LIB__ = "__STDC_SECURE_LIB__"
    630 const __GXX_ABI_VERSION = 1021
    631 const __GXX_MERGED_TYPEINFO_NAMES = 0
    632 const __GXX_TYPEINFO_EQUALITY_INLINE = 0
    633 const __HAVE_SPECULATION_SAFE_VALUE = 1
    634 const __INT16_MAX__ = 0x7fff
    635 const __INT32_MAX__ = 0x7fffffff
    636 const __INT32_TYPE__ = "int"
    637 const __INT64_MAX__ = 0x7fffffffffffffff
    638 const __INT8_MAX__ = 0x7f
    639 const __INTMAX_MAX__ = 0x7fffffffffffffff
    640 const __INTMAX_WIDTH__ = 64
    641 const __INTPTR_MAX__ = 0x7fffffffffffffff
    642 const __INTPTR_WIDTH__ = 64
    643 const __INT_FAST16_MAX__ = 0x7fff
    644 const __INT_FAST16_WIDTH__ = 16
    645 const __INT_FAST32_MAX__ = 0x7fffffff
    646 const __INT_FAST32_TYPE__ = "int"
    647 const __INT_FAST32_WIDTH__ = 32
    648 const __INT_FAST64_MAX__ = 0x7fffffffffffffff
    649 const __INT_FAST64_WIDTH__ = 64
    650 const __INT_FAST8_MAX__ = 0x7f
    651 const __INT_FAST8_WIDTH__ = 8
    652 const __INT_LEAST16_MAX__ = 0x7fff
    653 const __INT_LEAST16_WIDTH__ = 16
    654 const __INT_LEAST32_MAX__ = 0x7fffffff
    655 const __INT_LEAST32_TYPE__ = "int"
    656 const __INT_LEAST32_WIDTH__ = 32
    657 const __INT_LEAST64_MAX__ = 0x7fffffffffffffff
    658 const __INT_LEAST64_WIDTH__ = 64
    659 const __INT_LEAST8_MAX__ = 0x7f
    660 const __INT_LEAST8_WIDTH__ = 8
    661 const __INT_MAX__ = 0x7fffffff
    662 const __INT_WIDTH__ = 32
    663 const __LDBL_DECIMAL_DIG__ = 21
    664 const __LDBL_DENORM_MIN__ = 3.64519953188247460252840593361941982e-4951
    665 const __LDBL_DIG__ = 18
    666 const __LDBL_EPSILON__ = 1.08420217248550443400745280086994171e-19
    667 const __LDBL_HAS_DENORM__ = 1
    668 const __LDBL_HAS_INFINITY__ = 1
    669 const __LDBL_HAS_QUIET_NAN__ = 1
    670 const __LDBL_IS_IEC_60559__ = 1
    671 const __LDBL_MANT_DIG__ = 64
    672 const __LDBL_MAX_10_EXP__ = 4932
    673 const __LDBL_MAX_EXP__ = 16384
    674 const __LDBL_MAX__ = "1.18973149535723176502126385303097021e+4932"
    675 const __LDBL_MIN__ = 3.36210314311209350626267781732175260e-4932
    676 const __LDBL_NORM_MAX__ = "1.18973149535723176502126385303097021e+4932"
    677 const __LONG32 = "long"
    678 const __LONG_LONG_MAX__ = 0x7fffffffffffffff
    679 const __LONG_LONG_WIDTH__ = 64
    680 const __LONG_MAX__ = 0x7fffffff
    681 const __LONG_WIDTH__ = 32
    682 const __MINGW32_MAJOR_VERSION = 3
    683 const __MINGW32_MINOR_VERSION = 11
    684 const __MINGW32__ = 1
    685 const __MINGW64_VERSION_BUGFIX = 0
    686 const __MINGW64_VERSION_MAJOR = 14
    687 const __MINGW64_VERSION_MINOR = 0
    688 const __MINGW64_VERSION_RC = 0
    689 const __MINGW64_VERSION_STATE = "alpha"
    690 const __MINGW64__ = 1
    691 const __MINGW_DEBUGBREAK_IMPL = 1
    692 const __MINGW_FASTFAIL_IMPL = 1
    693 const __MINGW_FORTIFY_LEVEL = 0
    694 const __MINGW_FORTIFY_VA_ARG = 0
    695 const __MINGW_HAVE_ANSI_C99_PRINTF = 1
    696 const __MINGW_HAVE_ANSI_C99_SCANF = 1
    697 const __MINGW_HAVE_WIDE_C99_PRINTF = 1
    698 const __MINGW_HAVE_WIDE_C99_SCANF = 1
    699 const __MINGW_MSVC2005_DEPREC_STR = "This POSIX function is deprecated beginning in Visual C++ 2005, use _CRT_NONSTDC_NO_DEPRECATE to disable deprecation"
    700 const __MINGW_PREFETCH_IMPL = 1
    701 const __MINGW_SEC_WARN_STR = "This function or variable may be unsafe, use _CRT_SECURE_NO_WARNINGS to disable deprecation"
    702 const __MINGW_USE_UNDERSCORE_PREFIX = 0
    703 const __MMX_WITH_SSE__ = 1
    704 const __MMX__ = 1
    705 const __MSVCRT_VERSION__ = 0xE00
    706 const __MSVCRT__ = 1
    707 const __NO_INLINE__ = 1
    708 const __ORDER_BIG_ENDIAN__ = 4321
    709 const __ORDER_LITTLE_ENDIAN__ = 1234
    710 const __ORDER_PDP_ENDIAN__ = 3412
    711 const __PIC__ = 1
    712 const __PRAGMA_REDEFINE_EXTNAME = 1
    713 const __PRETTY_FUNCTION__ = "__func__"
    714 const __PTRDIFF_MAX__ = 0x7fffffffffffffff
    715 const __PTRDIFF_WIDTH__ = 64
    716 const __SCHAR_MAX__ = 0x7f
    717 const __SCHAR_WIDTH__ = 8
    718 const __SEG_FS = 1
    719 const __SEG_GS = 1
    720 const __SEH__ = 1
    721 const __SHRT_MAX__ = 0x7fff
    722 const __SHRT_WIDTH__ = 16
    723 const __SIG_ATOMIC_MAX__ = 0x7fffffff
    724 const __SIG_ATOMIC_TYPE__ = "int"
    725 const __SIG_ATOMIC_WIDTH__ = 32
    726 const __SIZEOF_DOUBLE__ = 8
    727 const __SIZEOF_FLOAT128__ = 16
    728 const __SIZEOF_FLOAT80__ = 16
    729 const __SIZEOF_FLOAT__ = 4
    730 const __SIZEOF_INT128__ = 16
    731 const __SIZEOF_INT__ = 4
    732 const __SIZEOF_LONG_DOUBLE__ = 8
    733 const __SIZEOF_LONG_LONG__ = 8
    734 const __SIZEOF_LONG__ = 4
    735 const __SIZEOF_POINTER__ = 8
    736 const __SIZEOF_PTRDIFF_T__ = 8
    737 const __SIZEOF_SHORT__ = 2
    738 const __SIZEOF_SIZE_T__ = 8
    739 const __SIZEOF_WCHAR_T__ = 2
    740 const __SIZEOF_WINT_T__ = 2
    741 const __SIZE_MAX__ = "0xffffffffffffffffU"
    742 const __SIZE_WIDTH__ = 64
    743 const __SSE2_MATH__ = 1
    744 const __SSE2__ = 1
    745 const __SSE_MATH__ = 1
    746 const __SSE__ = 1
    747 const __STDC_EMBED_EMPTY__ = 2
    748 const __STDC_EMBED_FOUND__ = 1
    749 const __STDC_EMBED_NOT_FOUND__ = 0
    750 const __STDC_HOSTED__ = 1
    751 const __STDC_SECURE_LIB__ = 200411
    752 const __STDC_UTF_16__ = 1
    753 const __STDC_UTF_32__ = 1
    754 const __STDC_VERSION_LIMITS_H__ = 202311
    755 const __STDC_VERSION__ = 202311
    756 const __STDC__ = 1
    757 const __UINT16_MAX__ = 0xffff
    758 const __UINT32_MAX__ = 0xffffffff
    759 const __UINT64_MAX__ = "0xffffffffffffffffU"
    760 const __UINT8_MAX__ = 0xff
    761 const __UINTMAX_MAX__ = "0xffffffffffffffffU"
    762 const __UINTPTR_MAX__ = "0xffffffffffffffffU"
    763 const __UINT_FAST16_MAX__ = 0xffff
    764 const __UINT_FAST32_MAX__ = 0xffffffff
    765 const __UINT_FAST64_MAX__ = "0xffffffffffffffffU"
    766 const __UINT_FAST8_MAX__ = 0xff
    767 const __UINT_LEAST16_MAX__ = 0xffff
    768 const __UINT_LEAST32_MAX__ = 0xffffffff
    769 const __UINT_LEAST64_MAX__ = "0xffffffffffffffffU"
    770 const __UINT_LEAST8_MAX__ = 0xff
    771 const __USE_MINGW_ANSI_STDIO = 0
    772 const __USING_POSIXTHREAD__ = 1
    773 const __VERSION__ = "16.2.0"
    774 const __WCHAR_MAX__ = 0xffff
    775 const __WCHAR_MIN__ = 0
    776 const __WCHAR_WIDTH__ = 16
    777 const __WIN32 = 1
    778 const __WIN32__ = 1
    779 const __WIN64 = 1
    780 const __WIN64__ = 1
    781 const __WINNT = 1
    782 const __WINNT__ = 1
    783 const __WINT_MAX__ = 0xffff
    784 const __WINT_MIN__ = 0
    785 const __WINT_WIDTH__ = 16
    786 const __amd64 = 1
    787 const __amd64__ = 1
    788 const __code_model_medium__ = 1
    789 const __int16 = "short"
    790 const __int32 = "int"
    791 const __int8 = "char"
    792 const __k8 = 1
    793 const __k8__ = 1
    794 const __mingw_bos_ovr = "__mingw_ovr"
    795 const __pic__ = 1
    796 const __x86_64 = 1
    797 const __x86_64__ = 1
    798 const _inline = "__inline"
    799 const environ1 = "_environ"
    800 const false1 = 0
    801 const onexit_t = "_onexit_t"
    802 const sys_errlist = "_sys_errlist"
    803 const sys_nerr = "_sys_nerr"
    804 const true1 = 1
    805 const wcswcs = "wcsstr"
    806 
    807 /* C23 keywords, no longer defined as macros by <stdbool.h> and <stddef.h>. */
    808 
    809 type __builtin_va_list = uintptr
    810 
    811 type __predefined_size_t = uint64
    812 
    813 type __predefined_wchar_t = uint16
    814 
    815 type __predefined_ptrdiff_t = int64
    816 
    817 type __gnuc_va_list = uintptr
    818 
    819 type va_list = uintptr
    820 
    821 type size_t = uint64
    822 
    823 type ssize_t = int64
    824 
    825 type rsize_t = uint64
    826 
    827 type intptr_t = int64
    828 
    829 type uintptr_t = uint64
    830 
    831 type ptrdiff_t = int64
    832 
    833 type wchar_t = uint16
    834 
    835 type wint_t = uint16
    836 
    837 type wctype_t = uint16
    838 
    839 type errno_t = int32
    840 
    841 type __time32_t = int32
    842 
    843 type __time64_t = int64
    844 
    845 type time_t = int64
    846 
    847 type threadlocaleinfostruct = struct {
    848 	F_locale_pctype      uintptr
    849 	F_locale_mb_cur_max  int32
    850 	F_locale_lc_codepage uint32
    851 }
    852 
    853 type pthreadlocinfo = uintptr
    854 
    855 type pthreadmbcinfo = uintptr
    856 
    857 type _locale_tstruct = struct {
    858 	Flocinfo pthreadlocinfo
    859 	Fmbcinfo pthreadmbcinfo
    860 }
    861 
    862 type localeinfo_struct = _locale_tstruct
    863 
    864 type _locale_t = uintptr
    865 
    866 type LC_ID = struct {
    867 	FwLanguage uint16
    868 	FwCountry  uint16
    869 	FwCodePage uint16
    870 }
    871 
    872 type tagLC_ID = LC_ID
    873 
    874 type LPLC_ID = uintptr
    875 
    876 type threadlocinfo = struct {
    877 	F_locale_pctype      uintptr
    878 	F_locale_mb_cur_max  int32
    879 	F_locale_lc_codepage uint32
    880 }
    881 
    882 type _onexit_t = uintptr
    883 
    884 type div_t = struct {
    885 	Fquot int32
    886 	Frem  int32
    887 }
    888 
    889 type _div_t = div_t
    890 
    891 type ldiv_t = struct {
    892 	Fquot int32
    893 	Frem  int32
    894 }
    895 
    896 type _ldiv_t = ldiv_t
    897 
    898 type _LDOUBLE = struct {
    899 	Fld [10]uint8
    900 }
    901 
    902 type _CRT_DOUBLE = struct {
    903 	Fx float64
    904 }
    905 
    906 type _CRT_FLOAT = struct {
    907 	Ff float32
    908 }
    909 
    910 type _LONGDOUBLE = struct {
    911 	Fx float64
    912 }
    913 
    914 type _LDBL12 = struct {
    915 	Fld12 [12]uint8
    916 }
    917 
    918 type _purecall_handler = uintptr
    919 
    920 type _invalid_parameter_handler = uintptr
    921 
    922 type lldiv_t = struct {
    923 	Fquot int64
    924 	Frem  int64
    925 }
    926 
    927 type _HEAPINFO = struct {
    928 	F_pentry  uintptr
    929 	F_size    size_t
    930 	F_useflag int32
    931 }
    932 
    933 type _heapinfo = _HEAPINFO
    934 
    935 type max_align_t = struct {
    936 	F__max_align_ll int64
    937 	F__max_align_ld float64
    938 }
    939 
    940 type int8_t = int8
    941 
    942 type uint8_t = uint8
    943 
    944 type int16_t = int16
    945 
    946 type uint16_t = uint16
    947 
    948 type int32_t = int32
    949 
    950 type uint32_t = uint32
    951 
    952 type int64_t = int64
    953 
    954 type uint64_t = uint64
    955 
    956 type int_least8_t = int8
    957 
    958 type uint_least8_t = uint8
    959 
    960 type int_least16_t = int16
    961 
    962 type uint_least16_t = uint16
    963 
    964 type int_least32_t = int32
    965 
    966 type uint_least32_t = uint32
    967 
    968 type int_least64_t = int64
    969 
    970 type uint_least64_t = uint64
    971 
    972 type int_fast8_t = int8
    973 
    974 type uint_fast8_t = uint8
    975 
    976 type int_fast16_t = int16
    977 
    978 type uint_fast16_t = uint16
    979 
    980 type int_fast32_t = int32
    981 
    982 type uint_fast32_t = uint32
    983 
    984 type int_fast64_t = int64
    985 
    986 type uint_fast64_t = uint64
    987 
    988 type intmax_t = int64
    989 
    990 type uintmax_t = uint64
    991 
    992 type imaxdiv_t = struct {
    993 	Fquot intmax_t
    994 	Frem  intmax_t
    995 }
    996 
    997 type WebPRGBABuffer = struct {
    998 	Frgba   uintptr
    999 	Fstride int32
   1000 	Fsize   size_t
   1001 }
   1002 
   1003 type WebPYUVABuffer = struct {
   1004 	Fy        uintptr
   1005 	Fu        uintptr
   1006 	Fv        uintptr
   1007 	Fa        uintptr
   1008 	Fy_stride int32
   1009 	Fu_stride int32
   1010 	Fv_stride int32
   1011 	Fa_stride int32
   1012 	Fy_size   size_t
   1013 	Fu_size   size_t
   1014 	Fv_size   size_t
   1015 	Fa_size   size_t
   1016 }
   1017 
   1018 type WebPDecBuffer = struct {
   1019 	Fcolorspace         WEBP_CSP_MODE1
   1020 	Fwidth              int32
   1021 	Fheight             int32
   1022 	Fis_external_memory int32
   1023 	Fu                  struct {
   1024 		FYUVA        [0]WebPYUVABuffer
   1025 		FRGBA        WebPRGBABuffer
   1026 		F__ccgo_pad2 [56]byte
   1027 	}
   1028 	Fpad            [4]uint32_t
   1029 	Fprivate_memory uintptr
   1030 }
   1031 
   1032 type WEBP_CSP_MODE = int32
   1033 
   1034 const MODE_RGB = 0
   1035 const MODE_RGBA = 1
   1036 const MODE_BGR = 2
   1037 const MODE_BGRA = 3
   1038 const MODE_ARGB = 4
   1039 const MODE_RGBA_4444 = 5
   1040 const MODE_RGB_565 = 6
   1041 const MODE_rgbA = 7
   1042 const MODE_bgrA = 8
   1043 const MODE_Argb = 9
   1044 const MODE_rgbA_4444 = 10
   1045 const MODE_YUV = 11
   1046 const MODE_YUVA = 12
   1047 const MODE_LAST = 13
   1048 
   1049 type WebPBitstreamFeatures = struct {
   1050 	Fwidth         int32
   1051 	Fheight        int32
   1052 	Fhas_alpha     int32
   1053 	Fhas_animation int32
   1054 	Fformat        int32
   1055 	Fpad           [5]uint32_t
   1056 }
   1057 
   1058 type WebPDecoderOptions = struct {
   1059 	Fbypass_filtering         int32
   1060 	Fno_fancy_upsampling      int32
   1061 	Fuse_cropping             int32
   1062 	Fcrop_left                int32
   1063 	Fcrop_top                 int32
   1064 	Fcrop_width               int32
   1065 	Fcrop_height              int32
   1066 	Fuse_scaling              int32
   1067 	Fscaled_width             int32
   1068 	Fscaled_height            int32
   1069 	Fuse_threads              int32
   1070 	Fdithering_strength       int32
   1071 	Fflip                     int32
   1072 	Falpha_dithering_strength int32
   1073 	Fpad                      [5]uint32_t
   1074 }
   1075 
   1076 type WebPDecoderConfig = struct {
   1077 	Finput   WebPBitstreamFeatures
   1078 	Foutput  WebPDecBuffer
   1079 	Foptions WebPDecoderOptions
   1080 }
   1081 
   1082 type WEBP_CSP_MODE1 = int32
   1083 
   1084 type VP8StatusCode1 = int32
   1085 
   1086 type VP8StatusCode = int32
   1087 
   1088 const VP8_STATUS_OK = 0
   1089 const VP8_STATUS_OUT_OF_MEMORY = 1
   1090 const VP8_STATUS_INVALID_PARAM = 2
   1091 const VP8_STATUS_BITSTREAM_ERROR = 3
   1092 const VP8_STATUS_UNSUPPORTED_FEATURE = 4
   1093 const VP8_STATUS_SUSPENDED = 5
   1094 const VP8_STATUS_USER_ABORT = 6
   1095 const VP8_STATUS_NOT_ENOUGH_DATA = 7
   1096 
   1097 type VP8Io = struct {
   1098 	Fwidth            int32
   1099 	Fheight           int32
   1100 	Fmb_y             int32
   1101 	Fmb_w             int32
   1102 	Fmb_h             int32
   1103 	Fy                uintptr
   1104 	Fu                uintptr
   1105 	Fv                uintptr
   1106 	Fy_stride         int32
   1107 	Fuv_stride        int32
   1108 	Fopaque           uintptr
   1109 	Fput              VP8IoPutHook
   1110 	Fsetup            VP8IoSetupHook
   1111 	Fteardown         VP8IoTeardownHook
   1112 	Ffancy_upsampling int32
   1113 	Fdata_size        size_t
   1114 	Fdata             uintptr
   1115 	Fbypass_filtering int32
   1116 	Fuse_cropping     int32
   1117 	Fcrop_left        int32
   1118 	Fcrop_right       int32
   1119 	Fcrop_top         int32
   1120 	Fcrop_bottom      int32
   1121 	Fuse_scaling      int32
   1122 	Fscaled_width     int32
   1123 	Fscaled_height    int32
   1124 	Fa                uintptr
   1125 }
   1126 
   1127 type VP8IoPutHook = uintptr
   1128 
   1129 type VP8IoSetupHook = uintptr
   1130 
   1131 type VP8IoTeardownHook = uintptr
   1132 
   1133 type VP8Decoder = struct {
   1134 	Fstatus              VP8StatusCode1
   1135 	Fready               int32
   1136 	Ferror_msg           uintptr
   1137 	Fbr                  VP8BitReader
   1138 	Fincremental         int32
   1139 	Ffrm_hdr             VP8FrameHeader
   1140 	Fpic_hdr             VP8PictureHeader
   1141 	Ffilter_hdr          VP8FilterHeader
   1142 	Fsegment_hdr         VP8SegmentHeader
   1143 	Fworker              WebPWorker
   1144 	Fmt_method           int32
   1145 	Fcache_id            int32
   1146 	Fnum_caches          int32
   1147 	Fthread_ctx          VP8ThreadContext
   1148 	Fmb_w                int32
   1149 	Fmb_h                int32
   1150 	Ftl_mb_x             int32
   1151 	Ftl_mb_y             int32
   1152 	Fbr_mb_x             int32
   1153 	Fbr_mb_y             int32
   1154 	Fnum_parts_minus_one uint32_t
   1155 	Fparts               [8]VP8BitReader
   1156 	Fdither              int32
   1157 	Fdithering_rg        VP8Random
   1158 	Fdqm                 [4]VP8QuantMatrix
   1159 	Fproba               VP8Proba
   1160 	Fuse_skip_proba      int32
   1161 	Fskip_p              uint8_t
   1162 	Fintra_t             uintptr
   1163 	Fintra_l             [4]uint8_t
   1164 	Fyuv_t               uintptr
   1165 	Fmb_info             uintptr
   1166 	Ff_info              uintptr
   1167 	Fyuv_b               uintptr
   1168 	Fcache_y             uintptr
   1169 	Fcache_u             uintptr
   1170 	Fcache_v             uintptr
   1171 	Fcache_y_stride      int32
   1172 	Fcache_uv_stride     int32
   1173 	Fmem                 uintptr
   1174 	Fmem_size            size_t
   1175 	Fmb_x                int32
   1176 	Fmb_y                int32
   1177 	Fmb_data             uintptr
   1178 	Ffilter_type         int32
   1179 	Ffstrengths          [4][2]VP8FInfo
   1180 	Falph_dec            uintptr
   1181 	Falpha_data          uintptr
   1182 	Falpha_data_size     size_t
   1183 	Fis_alpha_decoded    int32
   1184 	Falpha_plane_mem     uintptr
   1185 	Falpha_plane         uintptr
   1186 	Falpha_prev_line     uintptr
   1187 	Falpha_dithering     int32
   1188 }
   1189 
   1190 type rescaler_t = uint32
   1191 
   1192 type WebPRescaler = struct {
   1193 	Fx_expand     int32
   1194 	Fy_expand     int32
   1195 	Fnum_channels int32
   1196 	Ffx_scale     uint32_t
   1197 	Ffy_scale     uint32_t
   1198 	Ffxy_scale    uint32_t
   1199 	Fy_accum      int32
   1200 	Fy_add        int32
   1201 	Fy_sub        int32
   1202 	Fx_add        int32
   1203 	Fx_sub        int32
   1204 	Fsrc_width    int32
   1205 	Fsrc_height   int32
   1206 	Fdst_width    int32
   1207 	Fdst_height   int32
   1208 	Fsrc_y        int32
   1209 	Fdst_y        int32
   1210 	Fdst          uintptr
   1211 	Fdst_stride   int32
   1212 	Firow         uintptr
   1213 	Ffrow         uintptr
   1214 }
   1215 
   1216 type WebPDecParams = struct {
   1217 	Foutput         uintptr
   1218 	Ftmp_y          uintptr
   1219 	Ftmp_u          uintptr
   1220 	Ftmp_v          uintptr
   1221 	Flast_y         int32
   1222 	Foptions        uintptr
   1223 	Fscaler_y       uintptr
   1224 	Fscaler_u       uintptr
   1225 	Fscaler_v       uintptr
   1226 	Fscaler_a       uintptr
   1227 	Fmemory         uintptr
   1228 	Femit           OutputFunc
   1229 	Femit_alpha     OutputAlphaFunc
   1230 	Femit_alpha_row OutputRowFunc
   1231 }
   1232 
   1233 type OutputFunc = uintptr
   1234 
   1235 type OutputAlphaFunc = uintptr
   1236 
   1237 type OutputRowFunc = uintptr
   1238 
   1239 type WebPHeaderStructure = struct {
   1240 	Fdata            uintptr
   1241 	Fdata_size       size_t
   1242 	Fhave_all_data   int32
   1243 	Foffset          size_t
   1244 	Falpha_data      uintptr
   1245 	Falpha_data_size size_t
   1246 	Fcompressed_size size_t
   1247 	Friff_size       size_t
   1248 	Fis_lossless     int32
   1249 }
   1250 
   1251 type CPUFeature = int32
   1252 
   1253 const kSSE2 = 0
   1254 const kSSE3 = 1
   1255 const kSlowSSSE3 = 2
   1256 const kSSE4_1 = 3
   1257 const kAVX = 4
   1258 const kAVX2 = 5
   1259 const kNEON = 6
   1260 const kMIPS32 = 7
   1261 const kMIPSdspR2 = 8
   1262 const kMSA = 9
   1263 
   1264 type VP8CPUInfo = uintptr
   1265 
   1266 type VP8Idct = uintptr
   1267 
   1268 type VP8Fdct = uintptr
   1269 
   1270 type VP8WHT = uintptr
   1271 
   1272 type VP8IntraPreds = uintptr
   1273 
   1274 type VP8Intra4Preds = uintptr
   1275 
   1276 type VP8Metric = uintptr
   1277 
   1278 type VP8WMetric = uintptr
   1279 
   1280 type VP8MeanMetric = uintptr
   1281 
   1282 type VP8BlockCopy = uintptr
   1283 
   1284 type VP8QuantizeBlock = uintptr
   1285 
   1286 type VP8Quantize2Blocks = uintptr
   1287 
   1288 type VP8QuantizeBlockWHT = uintptr
   1289 
   1290 type VP8Histogram = struct {
   1291 	Fmax_value     int32
   1292 	Flast_non_zero int32
   1293 }
   1294 
   1295 type VP8CHisto = uintptr
   1296 
   1297 type VP8SetResidualCoeffsFunc = uintptr
   1298 
   1299 type VP8GetResidualCostFunc = uintptr
   1300 
   1301 type VP8DistoStats = struct {
   1302 	Fw   uint32_t
   1303 	Fxm  uint32_t
   1304 	Fym  uint32_t
   1305 	Fxxm uint32_t
   1306 	Fxym uint32_t
   1307 	Fyym uint32_t
   1308 }
   1309 
   1310 type VP8SSIMGetClippedFunc = uintptr
   1311 
   1312 type VP8SSIMGetFunc = uintptr
   1313 
   1314 type VP8AccumulateSSEFunc = uintptr
   1315 
   1316 type VP8DecIdct = uintptr
   1317 
   1318 type VP8DecIdct2 = uintptr
   1319 
   1320 type VP8PredFunc = uintptr
   1321 
   1322 type VP8SimpleFilterFunc = uintptr
   1323 
   1324 type VP8LumaFilterFunc = uintptr
   1325 
   1326 type VP8ChromaFilterFunc = uintptr
   1327 
   1328 type WebPUpsampleLinePairFunc = uintptr
   1329 
   1330 type WebPSamplerRowFunc = uintptr
   1331 
   1332 type WebPYUV444Converter = uintptr
   1333 
   1334 type WebPRescalerImportRowFunc = uintptr
   1335 
   1336 type WebPRescalerExportRowFunc = uintptr
   1337 
   1338 type WEBP_FILTER_TYPE = int32
   1339 
   1340 const WEBP_FILTER_NONE = 0
   1341 const WEBP_FILTER_HORIZONTAL = 1
   1342 const WEBP_FILTER_VERTICAL = 2
   1343 const WEBP_FILTER_GRADIENT = 3
   1344 const WEBP_FILTER_LAST = 4
   1345 const WEBP_FILTER_BEST = 5
   1346 const WEBP_FILTER_FAST = 6
   1347 
   1348 type WebPFilterFunc = uintptr
   1349 
   1350 type WebPUnfilterFunc = uintptr
   1351 
   1352 type VP8LDecoder = struct {
   1353 	Fstatus           VP8StatusCode1
   1354 	Fstate            VP8LDecodeState
   1355 	Fio               uintptr
   1356 	Foutput           uintptr
   1357 	Fpixels           uintptr
   1358 	Fargb_cache       uintptr
   1359 	Fbr               VP8LBitReader
   1360 	Fincremental      int32
   1361 	Fsaved_br         VP8LBitReader
   1362 	Fsaved_last_pixel int32
   1363 	Fwidth            int32
   1364 	Fheight           int32
   1365 	Flast_row         int32
   1366 	Flast_pixel       int32
   1367 	Flast_out_row     int32
   1368 	Fhdr              VP8LMetadata
   1369 	Fnext_transform   int32
   1370 	Ftransforms       [4]VP8LTransform
   1371 	Ftransforms_seen  uint32_t
   1372 	Frescaler_memory  uintptr
   1373 	Frescaler         uintptr
   1374 }
   1375 
   1376 const READ_DATA = 0
   1377 const READ_HDR = 1
   1378 const READ_DIM = 2
   1379 
   1380 type ALPHDecoder = struct {
   1381 	Fwidth          int32
   1382 	Fheight         int32
   1383 	Fmethod         int32
   1384 	Ffilter         WEBP_FILTER_TYPE
   1385 	Fpre_processing int32
   1386 	Fvp8l_dec       uintptr
   1387 	Fio             VP8Io
   1388 	Fuse_8b_decode  int32
   1389 	Foutput         uintptr
   1390 	Fprev_line      uintptr
   1391 }
   1392 
   1393 const B_DC_PRED = 0
   1394 const B_TM_PRED = 1
   1395 const B_VE_PRED = 2
   1396 const B_HE_PRED = 3
   1397 const B_RD_PRED = 4
   1398 const B_VR_PRED = 5
   1399 const B_LD_PRED = 6
   1400 const B_VL_PRED = 7
   1401 const B_HD_PRED = 8
   1402 const B_HU_PRED = 9
   1403 const NUM_BMODES = 10
   1404 const DC_PRED = 0
   1405 const V_PRED = 2
   1406 const H_PRED = 3
   1407 const TM_PRED = 1
   1408 const B_PRED = 10
   1409 const NUM_PRED_MODES = 4
   1410 const B_DC_PRED_NOTOP = 4
   1411 const B_DC_PRED_NOLEFT = 5
   1412 const B_DC_PRED_NOTOPLEFT = 6
   1413 const NUM_B_DC_MODES = 7
   1414 const MB_FEATURE_TREE_PROBS = 3
   1415 const NUM_MB_SEGMENTS = 4
   1416 const NUM_REF_LF_DELTAS = 4
   1417 const NUM_MODE_LF_DELTAS = 4
   1418 const MAX_NUM_PARTITIONS = 8
   1419 const NUM_TYPES = 4
   1420 const NUM_BANDS = 8
   1421 const NUM_CTX = 3
   1422 const NUM_PROBAS = 11
   1423 
   1424 type bit_t = uint64
   1425 
   1426 type range_t = uint32
   1427 
   1428 type VP8BitReader = struct {
   1429 	Fvalue   bit_t
   1430 	Frange1  range_t
   1431 	Fbits    int32
   1432 	Fbuf     uintptr
   1433 	Fbuf_end uintptr
   1434 	Fbuf_max uintptr
   1435 	Feof     int32
   1436 }
   1437 
   1438 type vp8l_val_t = uint64
   1439 
   1440 type VP8LBitReader = struct {
   1441 	Fval     vp8l_val_t
   1442 	Fbuf     uintptr
   1443 	Flen1    size_t
   1444 	Fpos     size_t
   1445 	Fbit_pos int32
   1446 	Feos     int32
   1447 }
   1448 
   1449 type VP8LColorCache = struct {
   1450 	Fcolors     uintptr
   1451 	Fhash_shift int32
   1452 	Fhash_bits  int32
   1453 }
   1454 
   1455 var kHashMul = uint32(0x1e35a7bd)
   1456 
   1457 type VP8LImageTransformType = int32
   1458 
   1459 const PREDICTOR_TRANSFORM = 0
   1460 const CROSS_COLOR_TRANSFORM = 1
   1461 const SUBTRACT_GREEN_TRANSFORM = 2
   1462 const COLOR_INDEXING_TRANSFORM = 3
   1463 
   1464 type HuffmanCode = struct {
   1465 	Fbits  uint8_t
   1466 	Fvalue uint16_t
   1467 }
   1468 
   1469 type HuffmanCode32 = struct {
   1470 	Fbits  int32
   1471 	Fvalue uint32_t
   1472 }
   1473 
   1474 type HuffmanTablesSegment = struct {
   1475 	Fstart      uintptr
   1476 	Fcurr_table uintptr
   1477 	Fnext       uintptr
   1478 	Fsize       int32
   1479 }
   1480 
   1481 type HuffmanTables = struct {
   1482 	Froot         HuffmanTablesSegment
   1483 	Fcurr_segment uintptr
   1484 }
   1485 
   1486 type HTreeGroup = struct {
   1487 	Fhtrees             [5]uintptr
   1488 	Fis_trivial_literal int32
   1489 	Fliteral_arb        uint32_t
   1490 	Fis_trivial_code    int32
   1491 	Fuse_packed_table   int32
   1492 	Fpacked_table       [64]HuffmanCode32
   1493 }
   1494 
   1495 type VP8LDecodeState = int32
   1496 
   1497 type VP8LTransform = struct {
   1498 	Ftype1 VP8LImageTransformType
   1499 	Fbits  int32
   1500 	Fxsize int32
   1501 	Fysize int32
   1502 	Fdata  uintptr
   1503 }
   1504 
   1505 type VP8LMetadata = struct {
   1506 	Fcolor_cache_size       int32
   1507 	Fcolor_cache            VP8LColorCache
   1508 	Fsaved_color_cache      VP8LColorCache
   1509 	Fhuffman_mask           int32
   1510 	Fhuffman_subsample_bits int32
   1511 	Fhuffman_xsize          int32
   1512 	Fhuffman_image          uintptr
   1513 	Fnum_htree_groups       int32
   1514 	Fhtree_groups           uintptr
   1515 	Fhuffman_tables         HuffmanTables
   1516 }
   1517 
   1518 type VP8Random = struct {
   1519 	Findex1 int32
   1520 	Findex2 int32
   1521 	Ftab    [55]uint32_t
   1522 	Famp    int32
   1523 }
   1524 
   1525 type WebPWorkerStatus = int32
   1526 
   1527 const NOT_OK = 0
   1528 const OK = 1
   1529 const WORK = 2
   1530 
   1531 type WebPWorkerHook = uintptr
   1532 
   1533 type WebPWorker = struct {
   1534 	Fimpl      uintptr
   1535 	Fstatus    WebPWorkerStatus
   1536 	Fhook      WebPWorkerHook
   1537 	Fdata1     uintptr
   1538 	Fdata2     uintptr
   1539 	Fhad_error int32
   1540 }
   1541 
   1542 type WebPWorkerInterface = struct {
   1543 	FInit    uintptr
   1544 	FReset   uintptr
   1545 	FSync    uintptr
   1546 	FLaunch  uintptr
   1547 	FExecute uintptr
   1548 	FEnd     uintptr
   1549 }
   1550 
   1551 type VP8FrameHeader = struct {
   1552 	Fkey_frame        uint8_t
   1553 	Fprofile          uint8_t
   1554 	Fshow             uint8_t
   1555 	Fpartition_length uint32_t
   1556 }
   1557 
   1558 type VP8PictureHeader = struct {
   1559 	Fwidth      uint16_t
   1560 	Fheight     uint16_t
   1561 	Fxscale     uint8_t
   1562 	Fyscale     uint8_t
   1563 	Fcolorspace uint8_t
   1564 	Fclamp_type uint8_t
   1565 }
   1566 
   1567 type VP8SegmentHeader = struct {
   1568 	Fuse_segment     int32
   1569 	Fupdate_map      int32
   1570 	Fabsolute_delta  int32
   1571 	Fquantizer       [4]int8_t
   1572 	Ffilter_strength [4]int8_t
   1573 }
   1574 
   1575 type VP8ProbaArray = [11]uint8_t
   1576 
   1577 type VP8BandProbas = struct {
   1578 	Fprobas [3]VP8ProbaArray
   1579 }
   1580 
   1581 type VP8Proba = struct {
   1582 	Fsegments  [3]uint8_t
   1583 	Fbands     [4][8]VP8BandProbas
   1584 	Fbands_ptr [4][17]uintptr
   1585 }
   1586 
   1587 type VP8FilterHeader = struct {
   1588 	Fsimple        int32
   1589 	Flevel         int32
   1590 	Fsharpness     int32
   1591 	Fuse_lf_delta  int32
   1592 	Fref_lf_delta  [4]int32
   1593 	Fmode_lf_delta [4]int32
   1594 }
   1595 
   1596 type VP8FInfo = struct {
   1597 	Ff_limit    uint8_t
   1598 	Ff_ilevel   uint8_t
   1599 	Ff_inner    uint8_t
   1600 	Fhev_thresh uint8_t
   1601 }
   1602 
   1603 type VP8MB = struct {
   1604 	Fnz    uint8_t
   1605 	Fnz_dc uint8_t
   1606 }
   1607 
   1608 type quant_t = [2]int32
   1609 
   1610 type VP8QuantMatrix = struct {
   1611 	Fy1_mat   quant_t
   1612 	Fy2_mat   quant_t
   1613 	Fuv_mat   quant_t
   1614 	Fuv_quant int32
   1615 	Fdither   int32
   1616 }
   1617 
   1618 type VP8MBData = struct {
   1619 	Fcoeffs      [384]int16_t
   1620 	Fis_i4x4     uint8_t
   1621 	Fimodes      [16]uint8_t
   1622 	Fuvmode      uint8_t
   1623 	Fnon_zero_y  uint32_t
   1624 	Fnon_zero_uv uint32_t
   1625 	Fdither      uint8_t
   1626 	Fskip        uint8_t
   1627 	Fsegment     uint8_t
   1628 }
   1629 
   1630 type VP8ThreadContext = struct {
   1631 	Fid         int32
   1632 	Fmb_y       int32
   1633 	Ffilter_row int32
   1634 	Ff_info     uintptr
   1635 	Fmb_data    uintptr
   1636 	Fio         VP8Io
   1637 }
   1638 
   1639 type VP8TopSamples = struct {
   1640 	Fy [16]uint8_t
   1641 	Fu [8]uint8_t
   1642 	Fv [8]uint8_t
   1643 }
   1644 
   1645 //------------------------------------------------------------------------------
   1646 
   1647 // Copyright 2010 Google Inc. All Rights Reserved.
   1648 //
   1649 // Use of this source code is governed by a BSD-style license
   1650 // that can be found in the COPYING file in the root of the source
   1651 // tree. An additional intellectual property rights grant can be found
   1652 // in the file PATENTS. All contributing project authors may
   1653 // be found in the AUTHORS file in the root of the source tree.
   1654 // -----------------------------------------------------------------------------
   1655 //
   1656 //  Main decoding functions for WebP images.
   1657 //
   1658 // Author: Skal (pascal.massimino@gmail.com)
   1659 
   1660 // Copyright 2012 Google Inc. All Rights Reserved.
   1661 //
   1662 // Use of this source code is governed by a BSD-style license
   1663 // that can be found in the COPYING file in the root of the source
   1664 // tree. An additional intellectual property rights grant can be found
   1665 // in the file PATENTS. All contributing project authors may
   1666 // be found in the AUTHORS file in the root of the source tree.
   1667 // -----------------------------------------------------------------------------
   1668 //
   1669 //  Internal header for constants related to WebP file format.
   1670 //
   1671 // Author: Urvang (urvang@google.com)
   1672 
   1673 // Copyright 2010 Google Inc. All Rights Reserved.
   1674 //
   1675 // Use of this source code is governed by a BSD-style license
   1676 // that can be found in the COPYING file in the root of the source
   1677 // tree. An additional intellectual property rights grant can be found
   1678 // in the file PATENTS. All contributing project authors may
   1679 // be found in the AUTHORS file in the root of the source tree.
   1680 // -----------------------------------------------------------------------------
   1681 //
   1682 //  Common types + memory wrappers
   1683 //
   1684 // Author: Skal (pascal.massimino@gmail.com)
   1685 
   1686 //------------------------------------------------------------------------------
   1687 // ALPHDecoder object.
   1688 
   1689 // C documentation
   1690 //
   1691 //	// Allocates a new alpha decoder instance.
   1692 func ALPHNew(tls *libc.TLS) (r uintptr) {
   1693 	var dec uintptr
   1694 	_ = dec
   1695 	dec = WebPSafeCalloc(tls, uint64(1), uint64(216))
   1696 	return dec
   1697 }
   1698 
   1699 // C documentation
   1700 //
   1701 //	// Clears and deallocates an alpha decoder instance.
   1702 func ALPHDelete(tls *libc.TLS, dec uintptr) {
   1703 	if dec != libc.UintptrFromInt32(0) {
   1704 		VP8LDelete(tls, (*ALPHDecoder)(unsafe.Pointer(dec)).Fvp8l_dec)
   1705 		(*ALPHDecoder)(unsafe.Pointer(dec)).Fvp8l_dec = libc.UintptrFromInt32(0)
   1706 		WebPSafeFree(tls, dec)
   1707 	}
   1708 }
   1709 
   1710 //------------------------------------------------------------------------------
   1711 // Decoding.
   1712 
   1713 // C documentation
   1714 //
   1715 //	// Initialize alpha decoding by parsing the alpha header and decoding the image
   1716 //	// header for alpha data stored using lossless compression.
   1717 //	// Returns false in case of error in alpha header (data too short, invalid
   1718 //	// compression method or filter, error in lossless header data etc).
   1719 func ALPHInit(tls *libc.TLS, dec uintptr, data uintptr, data_size size_t, src_io uintptr, output uintptr) (r int32) {
   1720 	var alpha_data, io1 uintptr
   1721 	var alpha_data_size, alpha_decoded_size size_t
   1722 	var ok, rsrv, v1 int32
   1723 	_, _, _, _, _, _, _ = alpha_data, alpha_data_size, alpha_decoded_size, io1, ok, rsrv, v1
   1724 	ok = 0
   1725 	alpha_data = data + uintptr(ALPHA_HEADER_LEN)
   1726 	alpha_data_size = data_size - uint64(ALPHA_HEADER_LEN)
   1727 	io1 = dec + 32
   1728 	VP8FiltersInit(tls)
   1729 	(*ALPHDecoder)(unsafe.Pointer(dec)).Foutput = output
   1730 	(*ALPHDecoder)(unsafe.Pointer(dec)).Fwidth = (*VP8Io)(unsafe.Pointer(src_io)).Fwidth
   1731 	(*ALPHDecoder)(unsafe.Pointer(dec)).Fheight = (*VP8Io)(unsafe.Pointer(src_io)).Fheight
   1732 	if data_size <= uint64(ALPHA_HEADER_LEN) {
   1733 		return 0
   1734 	}
   1735 	(*ALPHDecoder)(unsafe.Pointer(dec)).Fmethod = int32(**(**uint8_t)(__ccgo_up(data))) >> 0 & int32(0x03)
   1736 	(*ALPHDecoder)(unsafe.Pointer(dec)).Ffilter = int32(**(**uint8_t)(__ccgo_up(data))) >> libc.Int32FromInt32(2) & libc.Int32FromInt32(0x03)
   1737 	(*ALPHDecoder)(unsafe.Pointer(dec)).Fpre_processing = int32(**(**uint8_t)(__ccgo_up(data))) >> int32(4) & int32(0x03)
   1738 	rsrv = int32(**(**uint8_t)(__ccgo_up(data))) >> int32(6) & int32(0x03)
   1739 	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 {
   1740 		return 0
   1741 	}
   1742 	// Copy the necessary parameters from src_io to io
   1743 	v1 = VP8InitIoInternal(tls, io1, int32(WEBP_DECODER_ABI_VERSION))
   1744 	goto _2
   1745 _2:
   1746 	if !(v1 != 0) {
   1747 		return 0
   1748 	}
   1749 	WebPInitCustomIo(tls, libc.UintptrFromInt32(0), io1)
   1750 	(*VP8Io)(unsafe.Pointer(io1)).Fopaque = dec
   1751 	(*VP8Io)(unsafe.Pointer(io1)).Fwidth = (*VP8Io)(unsafe.Pointer(src_io)).Fwidth
   1752 	(*VP8Io)(unsafe.Pointer(io1)).Fheight = (*VP8Io)(unsafe.Pointer(src_io)).Fheight
   1753 	(*VP8Io)(unsafe.Pointer(io1)).Fuse_cropping = (*VP8Io)(unsafe.Pointer(src_io)).Fuse_cropping
   1754 	(*VP8Io)(unsafe.Pointer(io1)).Fcrop_left = (*VP8Io)(unsafe.Pointer(src_io)).Fcrop_left
   1755 	(*VP8Io)(unsafe.Pointer(io1)).Fcrop_right = (*VP8Io)(unsafe.Pointer(src_io)).Fcrop_right
   1756 	(*VP8Io)(unsafe.Pointer(io1)).Fcrop_top = (*VP8Io)(unsafe.Pointer(src_io)).Fcrop_top
   1757 	(*VP8Io)(unsafe.Pointer(io1)).Fcrop_bottom = (*VP8Io)(unsafe.Pointer(src_io)).Fcrop_bottom
   1758 	// No need to copy the scaling parameters.
   1759 	if (*ALPHDecoder)(unsafe.Pointer(dec)).Fmethod == ALPHA_NO_COMPRESSION {
   1760 		alpha_decoded_size = uint64((*ALPHDecoder)(unsafe.Pointer(dec)).Fwidth * (*ALPHDecoder)(unsafe.Pointer(dec)).Fheight)
   1761 		ok = libc.BoolInt32(alpha_data_size >= alpha_decoded_size)
   1762 	} else {
   1763 		ok = VP8LDecodeAlphaHeader(tls, dec, alpha_data, alpha_data_size)
   1764 	}
   1765 	return ok
   1766 }
   1767 
   1768 // C documentation
   1769 //
   1770 //	// Decodes, unfilters and dequantizes *at least* 'num_rows' rows of alpha
   1771 //	// starting from row number 'row'. It assumes that rows up to (row - 1) have
   1772 //	// already been decoded.
   1773 //	// Returns false in case of bitstream error.
   1774 func ALPHDecode(tls *libc.TLS, dec uintptr, row int32, num_rows int32) (r int32) {
   1775 	var alph_dec, deltas, dst, prev_line uintptr
   1776 	var height, width, y int32
   1777 	_, _, _, _, _, _, _ = alph_dec, deltas, dst, height, prev_line, width, y
   1778 	alph_dec = (*VP8Decoder)(unsafe.Pointer(dec)).Falph_dec
   1779 	width = (*ALPHDecoder)(unsafe.Pointer(alph_dec)).Fwidth
   1780 	height = (*ALPHDecoder)(unsafe.Pointer(alph_dec)).Fio.Fcrop_bottom
   1781 	if (*ALPHDecoder)(unsafe.Pointer(alph_dec)).Fmethod == ALPHA_NO_COMPRESSION {
   1782 		prev_line = (*VP8Decoder)(unsafe.Pointer(dec)).Falpha_prev_line
   1783 		deltas = (*VP8Decoder)(unsafe.Pointer(dec)).Falpha_data + uintptr(ALPHA_HEADER_LEN) + uintptr(row*width)
   1784 		dst = (*VP8Decoder)(unsafe.Pointer(dec)).Falpha_plane + uintptr(row*width)
   1785 		y = 0
   1786 		for {
   1787 			if !(y < num_rows) {
   1788 				break
   1789 			}
   1790 			(*(*func(*libc.TLS, uintptr, uintptr, uintptr, int32))(unsafe.Pointer(&struct{ uintptr }{WebPUnfilters[(*ALPHDecoder)(unsafe.Pointer(alph_dec)).Ffilter]})))(tls, prev_line, deltas, dst, width)
   1791 			prev_line = dst
   1792 			dst = dst + uintptr(width)
   1793 			deltas = deltas + uintptr(width)
   1794 			goto _1
   1795 		_1:
   1796 			;
   1797 			y = y + 1
   1798 		}
   1799 		(*VP8Decoder)(unsafe.Pointer(dec)).Falpha_prev_line = prev_line
   1800 	} else { // alph_dec->method == ALPHA_LOSSLESS_COMPRESSION
   1801 		if !(VP8LDecodeAlphaImageStream(tls, alph_dec, row+num_rows) != 0) {
   1802 			return 0
   1803 		}
   1804 	}
   1805 	if row+num_rows >= height {
   1806 		(*VP8Decoder)(unsafe.Pointer(dec)).Fis_alpha_decoded = int32(1)
   1807 	}
   1808 	return int32(1)
   1809 }
   1810 
   1811 func AllocateAlphaPlane(tls *libc.TLS, dec uintptr, io uintptr) (r int32) {
   1812 	var alpha_size uint64_t
   1813 	var height, stride int32
   1814 	_, _, _ = alpha_size, height, stride
   1815 	stride = (*VP8Io)(unsafe.Pointer(io)).Fwidth
   1816 	height = (*VP8Io)(unsafe.Pointer(io)).Fcrop_bottom
   1817 	alpha_size = uint64(stride) * uint64(height)
   1818 	(*VP8Decoder)(unsafe.Pointer(dec)).Falpha_plane_mem = WebPSafeMalloc(tls, alpha_size, uint64(1))
   1819 	if (*VP8Decoder)(unsafe.Pointer(dec)).Falpha_plane_mem == libc.UintptrFromInt32(0) {
   1820 		return VP8SetError(tls, dec, int32(VP8_STATUS_OUT_OF_MEMORY), __ccgo_ts)
   1821 	}
   1822 	(*VP8Decoder)(unsafe.Pointer(dec)).Falpha_plane = (*VP8Decoder)(unsafe.Pointer(dec)).Falpha_plane_mem
   1823 	(*VP8Decoder)(unsafe.Pointer(dec)).Falpha_prev_line = libc.UintptrFromInt32(0)
   1824 	return int32(1)
   1825 }
   1826 
   1827 func WebPDeallocateAlphaMemory(tls *libc.TLS, dec uintptr) {
   1828 	WebPSafeFree(tls, (*VP8Decoder)(unsafe.Pointer(dec)).Falpha_plane_mem)
   1829 	(*VP8Decoder)(unsafe.Pointer(dec)).Falpha_plane_mem = libc.UintptrFromInt32(0)
   1830 	(*VP8Decoder)(unsafe.Pointer(dec)).Falpha_plane = libc.UintptrFromInt32(0)
   1831 	ALPHDelete(tls, (*VP8Decoder)(unsafe.Pointer(dec)).Falph_dec)
   1832 	(*VP8Decoder)(unsafe.Pointer(dec)).Falph_dec = libc.UintptrFromInt32(0)
   1833 }
   1834 
   1835 // ------------------------------------------------------------------------------
   1836 // Main entry point.
   1837 func VP8DecompressAlphaRows(tls *libc.TLS, dec uintptr, io uintptr, row int32, num_rows int32) (r uintptr) {
   1838 	var alpha, vp8l_dec uintptr
   1839 	var height, width, v1 int32
   1840 	_, _, _, _, _ = alpha, height, vp8l_dec, width, v1
   1841 	width = (*VP8Io)(unsafe.Pointer(io)).Fwidth
   1842 	height = (*VP8Io)(unsafe.Pointer(io)).Fcrop_bottom
   1843 	if row < 0 || num_rows <= 0 || row+num_rows > height {
   1844 		return libc.UintptrFromInt32(0)
   1845 	}
   1846 	if !((*VP8Decoder)(unsafe.Pointer(dec)).Fis_alpha_decoded != 0) {
   1847 		if (*VP8Decoder)(unsafe.Pointer(dec)).Falph_dec == libc.UintptrFromInt32(0) { // Initialize decoder.
   1848 			(*VP8Decoder)(unsafe.Pointer(dec)).Falph_dec = ALPHNew(tls)
   1849 			if (*VP8Decoder)(unsafe.Pointer(dec)).Falph_dec == libc.UintptrFromInt32(0) {
   1850 				VP8SetError(tls, dec, int32(VP8_STATUS_OUT_OF_MEMORY), __ccgo_ts)
   1851 				return libc.UintptrFromInt32(0)
   1852 			}
   1853 			if !(AllocateAlphaPlane(tls, dec, io) != 0) {
   1854 				goto Error
   1855 			}
   1856 			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) {
   1857 				vp8l_dec = (*ALPHDecoder)(unsafe.Pointer((*VP8Decoder)(unsafe.Pointer(dec)).Falph_dec)).Fvp8l_dec
   1858 				if vp8l_dec == libc.UintptrFromInt32(0) {
   1859 					v1 = int32(VP8_STATUS_OUT_OF_MEMORY)
   1860 				} else {
   1861 					v1 = (*VP8LDecoder)(unsafe.Pointer(vp8l_dec)).Fstatus
   1862 				}
   1863 				VP8SetError(tls, dec, v1, __ccgo_ts)
   1864 				goto Error
   1865 			}
   1866 			// if we allowed use of alpha dithering, check whether it's needed at all
   1867 			if (*ALPHDecoder)(unsafe.Pointer((*VP8Decoder)(unsafe.Pointer(dec)).Falph_dec)).Fpre_processing != int32(ALPHA_PREPROCESSED_LEVELS) {
   1868 				(*VP8Decoder)(unsafe.Pointer(dec)).Falpha_dithering = 0 // disable dithering
   1869 			} else {
   1870 				num_rows = height - row // decode everything in one pass
   1871 			}
   1872 		}
   1873 		if !(ALPHDecode(tls, dec, row, num_rows) != 0) {
   1874 			goto Error
   1875 		}
   1876 		if (*VP8Decoder)(unsafe.Pointer(dec)).Fis_alpha_decoded != 0 { // finished?
   1877 			ALPHDelete(tls, (*VP8Decoder)(unsafe.Pointer(dec)).Falph_dec)
   1878 			(*VP8Decoder)(unsafe.Pointer(dec)).Falph_dec = libc.UintptrFromInt32(0)
   1879 			if (*VP8Decoder)(unsafe.Pointer(dec)).Falpha_dithering > 0 {
   1880 				alpha = (*VP8Decoder)(unsafe.Pointer(dec)).Falpha_plane + uintptr((*VP8Io)(unsafe.Pointer(io)).Fcrop_top*width) + uintptr((*VP8Io)(unsafe.Pointer(io)).Fcrop_left)
   1881 				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) {
   1882 					goto Error
   1883 				}
   1884 			}
   1885 		}
   1886 	}
   1887 	// Return a pointer to the current decoded row.
   1888 	return (*VP8Decoder)(unsafe.Pointer(dec)).Falpha_plane + uintptr(row*width)
   1889 	goto Error
   1890 Error:
   1891 	;
   1892 	WebPDeallocateAlphaMemory(tls, dec)
   1893 	return libc.UintptrFromInt32(0)
   1894 }
   1895 
   1896 var kHashMul1 = uint32(0x1e35a7bd)
   1897 
   1898 //------------------------------------------------------------------------------
   1899 
   1900 // Copyright 2010 Google Inc. All Rights Reserved.
   1901 //
   1902 // Use of this source code is governed by a BSD-style license
   1903 // that can be found in the COPYING file in the root of the source
   1904 // tree. An additional intellectual property rights grant can be found
   1905 // in the file PATENTS. All contributing project authors may
   1906 // be found in the AUTHORS file in the root of the source tree.
   1907 // -----------------------------------------------------------------------------
   1908 //
   1909 //  Main decoding functions for WebP images.
   1910 //
   1911 // Author: Skal (pascal.massimino@gmail.com)
   1912 
   1913 // Copyright 2010 Google Inc. All Rights Reserved.
   1914 //
   1915 // Use of this source code is governed by a BSD-style license
   1916 // that can be found in the COPYING file in the root of the source
   1917 // tree. An additional intellectual property rights grant can be found
   1918 // in the file PATENTS. All contributing project authors may
   1919 // be found in the AUTHORS file in the root of the source tree.
   1920 // -----------------------------------------------------------------------------
   1921 //
   1922 //  Common types + memory wrappers
   1923 //
   1924 // Author: Skal (pascal.massimino@gmail.com)
   1925 
   1926 //------------------------------------------------------------------------------
   1927 // WebPDecBuffer
   1928 
   1929 // C documentation
   1930 //
   1931 //	// Number of bytes per pixel for the different color-spaces.
   1932 var kModeBpp = [13]uint8_t{
   1933 	0:  uint8(3),
   1934 	1:  uint8(4),
   1935 	2:  uint8(3),
   1936 	3:  uint8(4),
   1937 	4:  uint8(4),
   1938 	5:  uint8(2),
   1939 	6:  uint8(2),
   1940 	7:  uint8(4),
   1941 	8:  uint8(4),
   1942 	9:  uint8(4),
   1943 	10: uint8(2),
   1944 	11: uint8(1),
   1945 	12: uint8(1),
   1946 }
   1947 
   1948 // C documentation
   1949 //
   1950 //	// Convert to an integer to handle both the unsigned/signed enum cases
   1951 //	// without the need for casting to remove type limit warnings.
   1952 func IsValidColorspace(tls *libc.TLS, webp_csp_mode int32) (r int32) {
   1953 	return libc.BoolInt32(webp_csp_mode >= int32(MODE_RGB) && webp_csp_mode < int32(MODE_LAST))
   1954 }
   1955 
   1956 // strictly speaking, the very last (or first, if flipped) row
   1957 // doesn't require padding.
   1958 
   1959 func CheckDecBuffer(tls *libc.TLS, buffer uintptr) (r VP8StatusCode1) {
   1960 	var a_size, size, u_size, v_size, y_size uint64_t
   1961 	var a_stride, height, ok, stride, u_stride, uv_height, uv_width, v_stride, width, y_stride, v1 int32
   1962 	var buf, buf1 uintptr
   1963 	var mode1 WEBP_CSP_MODE1
   1964 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
   1965 	ok = int32(1)
   1966 	mode1 = (*WebPDecBuffer)(unsafe.Pointer(buffer)).Fcolorspace
   1967 	width = (*WebPDecBuffer)(unsafe.Pointer(buffer)).Fwidth
   1968 	height = (*WebPDecBuffer)(unsafe.Pointer(buffer)).Fheight
   1969 	if !(IsValidColorspace(tls, mode1) != 0) {
   1970 		ok = 0
   1971 	} else {
   1972 		v1 = libc.BoolInt32(mode1 < int32(MODE_YUV))
   1973 		goto _2
   1974 	_2:
   1975 		if !(v1 != 0) { // YUV checks
   1976 			buf = buffer + 16
   1977 			uv_width = (width + int32(1)) / int32(2)
   1978 			uv_height = (height + int32(1)) / int32(2)
   1979 			y_stride = libc.Xabs(tls, (*WebPYUVABuffer)(unsafe.Pointer(buf)).Fy_stride)
   1980 			u_stride = libc.Xabs(tls, (*WebPYUVABuffer)(unsafe.Pointer(buf)).Fu_stride)
   1981 			v_stride = libc.Xabs(tls, (*WebPYUVABuffer)(unsafe.Pointer(buf)).Fv_stride)
   1982 			a_stride = libc.Xabs(tls, (*WebPYUVABuffer)(unsafe.Pointer(buf)).Fa_stride)
   1983 			y_size = uint64(y_stride)*uint64(height-libc.Int32FromInt32(1)) + uint64(width)
   1984 			u_size = uint64(u_stride)*uint64(uv_height-libc.Int32FromInt32(1)) + uint64(uv_width)
   1985 			v_size = uint64(v_stride)*uint64(uv_height-libc.Int32FromInt32(1)) + uint64(uv_width)
   1986 			a_size = uint64(a_stride)*uint64(height-libc.Int32FromInt32(1)) + uint64(width)
   1987 			ok = ok & libc.BoolInt32(y_size <= (*WebPYUVABuffer)(unsafe.Pointer(buf)).Fy_size)
   1988 			ok = ok & libc.BoolInt32(u_size <= (*WebPYUVABuffer)(unsafe.Pointer(buf)).Fu_size)
   1989 			ok = ok & libc.BoolInt32(v_size <= (*WebPYUVABuffer)(unsafe.Pointer(buf)).Fv_size)
   1990 			ok = ok & libc.BoolInt32(y_stride >= width)
   1991 			ok = ok & libc.BoolInt32(u_stride >= uv_width)
   1992 			ok = ok & libc.BoolInt32(v_stride >= uv_width)
   1993 			ok = ok & libc.BoolInt32((*WebPYUVABuffer)(unsafe.Pointer(buf)).Fy != libc.UintptrFromInt32(0))
   1994 			ok = ok & libc.BoolInt32((*WebPYUVABuffer)(unsafe.Pointer(buf)).Fu != libc.UintptrFromInt32(0))
   1995 			ok = ok & libc.BoolInt32((*WebPYUVABuffer)(unsafe.Pointer(buf)).Fv != libc.UintptrFromInt32(0))
   1996 			if mode1 == int32(MODE_YUVA) {
   1997 				ok = ok & libc.BoolInt32(a_stride >= width)
   1998 				ok = ok & libc.BoolInt32(a_size <= (*WebPYUVABuffer)(unsafe.Pointer(buf)).Fa_size)
   1999 				ok = ok & libc.BoolInt32((*WebPYUVABuffer)(unsafe.Pointer(buf)).Fa != libc.UintptrFromInt32(0))
   2000 			}
   2001 		} else { // RGB checks
   2002 			buf1 = buffer + 16
   2003 			stride = libc.Xabs(tls, (*WebPRGBABuffer)(unsafe.Pointer(buf1)).Fstride)
   2004 			size = uint64(stride)*uint64(height-libc.Int32FromInt32(1)) + uint64(width)*uint64(kModeBpp[mode1])
   2005 			ok = ok & libc.BoolInt32(size <= (*WebPRGBABuffer)(unsafe.Pointer(buf1)).Fsize)
   2006 			ok = ok & libc.BoolInt32(stride >= width*int32(kModeBpp[mode1]))
   2007 			ok = ok & libc.BoolInt32((*WebPRGBABuffer)(unsafe.Pointer(buf1)).Frgba != libc.UintptrFromInt32(0))
   2008 		}
   2009 	}
   2010 	if ok != 0 {
   2011 		v1 = int32(VP8_STATUS_OK)
   2012 	} else {
   2013 		v1 = int32(VP8_STATUS_INVALID_PARAM)
   2014 	}
   2015 	return v1
   2016 }
   2017 
   2018 func AllocateBuffer(tls *libc.TLS, buffer uintptr) (r VP8StatusCode1) {
   2019 	var a_size, size, total_size, uv_size uint64_t
   2020 	var a_stride, h, stride, uv_stride, w, v1 int32
   2021 	var buf, buf1, output uintptr
   2022 	var mode1 WEBP_CSP_MODE1
   2023 	_, _, _, _, _, _, _, _, _, _, _, _, _, _ = a_size, a_stride, buf, buf1, h, mode1, output, size, stride, total_size, uv_size, uv_stride, w, v1
   2024 	w = (*WebPDecBuffer)(unsafe.Pointer(buffer)).Fwidth
   2025 	h = (*WebPDecBuffer)(unsafe.Pointer(buffer)).Fheight
   2026 	mode1 = (*WebPDecBuffer)(unsafe.Pointer(buffer)).Fcolorspace
   2027 	if w <= 0 || h <= 0 || !(IsValidColorspace(tls, mode1) != 0) {
   2028 		return int32(VP8_STATUS_INVALID_PARAM)
   2029 	}
   2030 	if (*WebPDecBuffer)(unsafe.Pointer(buffer)).Fis_external_memory <= 0 && (*WebPDecBuffer)(unsafe.Pointer(buffer)).Fprivate_memory == libc.UintptrFromInt32(0) {
   2031 		uv_stride = 0
   2032 		a_stride = 0
   2033 		uv_size = uint64(0)
   2034 		a_size = uint64(0)
   2035 		if uint64(w)*uint64(kModeBpp[mode1]) >= libc.Uint64FromUint64(1)<<libc.Int32FromInt32(31) {
   2036 			return int32(VP8_STATUS_INVALID_PARAM)
   2037 		}
   2038 		stride = w * int32(kModeBpp[mode1])
   2039 		size = uint64(stride) * uint64(h)
   2040 		v1 = libc.BoolInt32(mode1 < int32(MODE_YUV))
   2041 		goto _2
   2042 	_2:
   2043 		if !(v1 != 0) {
   2044 			uv_stride = (w + int32(1)) / int32(2)
   2045 			uv_size = uint64(uv_stride) * uint64((h+libc.Int32FromInt32(1))/libc.Int32FromInt32(2))
   2046 			if mode1 == int32(MODE_YUVA) {
   2047 				a_stride = w
   2048 				a_size = uint64(a_stride) * uint64(h)
   2049 			}
   2050 		}
   2051 		total_size = size + uint64(2)*uv_size + a_size
   2052 		output = WebPSafeMalloc(tls, total_size, uint64(1))
   2053 		if output == libc.UintptrFromInt32(0) {
   2054 			return int32(VP8_STATUS_OUT_OF_MEMORY)
   2055 		}
   2056 		(*WebPDecBuffer)(unsafe.Pointer(buffer)).Fprivate_memory = output
   2057 		v1 = libc.BoolInt32(mode1 < int32(MODE_YUV))
   2058 		goto _4
   2059 	_4:
   2060 		if !(v1 != 0) { // YUVA initialization
   2061 			buf = buffer + 16
   2062 			(*WebPYUVABuffer)(unsafe.Pointer(buf)).Fy = output
   2063 			(*WebPYUVABuffer)(unsafe.Pointer(buf)).Fy_stride = stride
   2064 			(*WebPYUVABuffer)(unsafe.Pointer(buf)).Fy_size = size
   2065 			(*WebPYUVABuffer)(unsafe.Pointer(buf)).Fu = output + uintptr(size)
   2066 			(*WebPYUVABuffer)(unsafe.Pointer(buf)).Fu_stride = uv_stride
   2067 			(*WebPYUVABuffer)(unsafe.Pointer(buf)).Fu_size = uv_size
   2068 			(*WebPYUVABuffer)(unsafe.Pointer(buf)).Fv = output + uintptr(size) + uintptr(uv_size)
   2069 			(*WebPYUVABuffer)(unsafe.Pointer(buf)).Fv_stride = uv_stride
   2070 			(*WebPYUVABuffer)(unsafe.Pointer(buf)).Fv_size = uv_size
   2071 			if mode1 == int32(MODE_YUVA) {
   2072 				(*WebPYUVABuffer)(unsafe.Pointer(buf)).Fa = output + uintptr(size) + uintptr(uint64(2)*uv_size)
   2073 			}
   2074 			(*WebPYUVABuffer)(unsafe.Pointer(buf)).Fa_size = a_size
   2075 			(*WebPYUVABuffer)(unsafe.Pointer(buf)).Fa_stride = a_stride
   2076 		} else { // RGBA initialization
   2077 			buf1 = buffer + 16
   2078 			(*WebPRGBABuffer)(unsafe.Pointer(buf1)).Frgba = output
   2079 			(*WebPRGBABuffer)(unsafe.Pointer(buf1)).Fstride = stride
   2080 			(*WebPRGBABuffer)(unsafe.Pointer(buf1)).Fsize = size
   2081 		}
   2082 	}
   2083 	return CheckDecBuffer(tls, buffer)
   2084 }
   2085 
   2086 func WebPFlipBuffer(tls *libc.TLS, buffer uintptr) (r VP8StatusCode1) {
   2087 	var H int64_t
   2088 	var buf, buf1 uintptr
   2089 	var v1 int32
   2090 	_, _, _, _ = H, buf, buf1, v1
   2091 	if buffer == libc.UintptrFromInt32(0) {
   2092 		return int32(VP8_STATUS_INVALID_PARAM)
   2093 	}
   2094 	v1 = libc.BoolInt32((*WebPDecBuffer)(unsafe.Pointer(buffer)).Fcolorspace < int32(MODE_YUV))
   2095 	goto _2
   2096 _2:
   2097 	if v1 != 0 {
   2098 		buf = buffer + 16
   2099 		**(**uintptr)(__ccgo_up(buf)) += uintptr(int64((*WebPDecBuffer)(unsafe.Pointer(buffer)).Fheight-libc.Int32FromInt32(1)) * int64((*WebPRGBABuffer)(unsafe.Pointer(buf)).Fstride))
   2100 		(*WebPRGBABuffer)(unsafe.Pointer(buf)).Fstride = -(*WebPRGBABuffer)(unsafe.Pointer(buf)).Fstride
   2101 	} else {
   2102 		buf1 = buffer + 16
   2103 		H = int64((*WebPDecBuffer)(unsafe.Pointer(buffer)).Fheight)
   2104 		**(**uintptr)(__ccgo_up(buf1)) += uintptr((H - int64(1)) * int64((*WebPYUVABuffer)(unsafe.Pointer(buf1)).Fy_stride))
   2105 		(*WebPYUVABuffer)(unsafe.Pointer(buf1)).Fy_stride = -(*WebPYUVABuffer)(unsafe.Pointer(buf1)).Fy_stride
   2106 		**(**uintptr)(__ccgo_up(buf1 + 8)) += uintptr((H - int64(1)) >> int32(1) * int64((*WebPYUVABuffer)(unsafe.Pointer(buf1)).Fu_stride))
   2107 		(*WebPYUVABuffer)(unsafe.Pointer(buf1)).Fu_stride = -(*WebPYUVABuffer)(unsafe.Pointer(buf1)).Fu_stride
   2108 		**(**uintptr)(__ccgo_up(buf1 + 16)) += uintptr((H - int64(1)) >> int32(1) * int64((*WebPYUVABuffer)(unsafe.Pointer(buf1)).Fv_stride))
   2109 		(*WebPYUVABuffer)(unsafe.Pointer(buf1)).Fv_stride = -(*WebPYUVABuffer)(unsafe.Pointer(buf1)).Fv_stride
   2110 		if (*WebPYUVABuffer)(unsafe.Pointer(buf1)).Fa != libc.UintptrFromInt32(0) {
   2111 			**(**uintptr)(__ccgo_up(buf1 + 24)) += uintptr((H - int64(1)) * int64((*WebPYUVABuffer)(unsafe.Pointer(buf1)).Fa_stride))
   2112 			(*WebPYUVABuffer)(unsafe.Pointer(buf1)).Fa_stride = -(*WebPYUVABuffer)(unsafe.Pointer(buf1)).Fa_stride
   2113 		}
   2114 	}
   2115 	return int32(VP8_STATUS_OK)
   2116 }
   2117 
   2118 func WebPAllocateDecBuffer(tls *libc.TLS, width int32, height int32, options uintptr, buffer uintptr) (r VP8StatusCode1) {
   2119 	bp := tls.Alloc(16)
   2120 	defer tls.Free(16)
   2121 	var ch, cw, x, y int32
   2122 	var status VP8StatusCode1
   2123 	var _ /* scaled_height at bp+4 */ int32
   2124 	var _ /* scaled_width at bp+0 */ int32
   2125 	_, _, _, _, _ = ch, cw, status, x, y
   2126 	if buffer == libc.UintptrFromInt32(0) || width <= 0 || height <= 0 {
   2127 		return int32(VP8_STATUS_INVALID_PARAM)
   2128 	}
   2129 	if options != libc.UintptrFromInt32(0) { // First, apply options if there is any.
   2130 		if (*WebPDecoderOptions)(unsafe.Pointer(options)).Fuse_cropping != 0 {
   2131 			cw = (*WebPDecoderOptions)(unsafe.Pointer(options)).Fcrop_width
   2132 			ch = (*WebPDecoderOptions)(unsafe.Pointer(options)).Fcrop_height
   2133 			x = (*WebPDecoderOptions)(unsafe.Pointer(options)).Fcrop_left & ^libc.Int32FromInt32(1)
   2134 			y = (*WebPDecoderOptions)(unsafe.Pointer(options)).Fcrop_top & ^libc.Int32FromInt32(1)
   2135 			if !(WebPCheckCropDimensions(tls, width, height, x, y, cw, ch) != 0) {
   2136 				return int32(VP8_STATUS_INVALID_PARAM) // out of frame boundary.
   2137 			}
   2138 			width = cw
   2139 			height = ch
   2140 		}
   2141 		if (*WebPDecoderOptions)(unsafe.Pointer(options)).Fuse_scaling != 0 {
   2142 			**(**int32)(__ccgo_up(bp)) = (*WebPDecoderOptions)(unsafe.Pointer(options)).Fscaled_width
   2143 			**(**int32)(__ccgo_up(bp + 4)) = (*WebPDecoderOptions)(unsafe.Pointer(options)).Fscaled_height
   2144 			if !(WebPRescalerGetScaledDimensions(tls, width, height, bp, bp+4) != 0) {
   2145 				return int32(VP8_STATUS_INVALID_PARAM)
   2146 			}
   2147 			width = **(**int32)(__ccgo_up(bp))
   2148 			height = **(**int32)(__ccgo_up(bp + 4))
   2149 		}
   2150 	}
   2151 	(*WebPDecBuffer)(unsafe.Pointer(buffer)).Fwidth = width
   2152 	(*WebPDecBuffer)(unsafe.Pointer(buffer)).Fheight = height
   2153 	// Then, allocate buffer for real.
   2154 	status = AllocateBuffer(tls, buffer)
   2155 	if status != int32(VP8_STATUS_OK) {
   2156 		return status
   2157 	}
   2158 	// Use the stride trick if vertical flip is needed.
   2159 	if options != libc.UintptrFromInt32(0) && (*WebPDecoderOptions)(unsafe.Pointer(options)).Fflip != 0 {
   2160 		status = WebPFlipBuffer(tls, buffer)
   2161 	}
   2162 	return status
   2163 }
   2164 
   2165 //------------------------------------------------------------------------------
   2166 // constructors / destructors
   2167 
   2168 func WebPInitDecBufferInternal(tls *libc.TLS, buffer uintptr, version int32) (r int32) {
   2169 	if version>>int32(8) != libc.Int32FromInt32(WEBP_DECODER_ABI_VERSION)>>libc.Int32FromInt32(8) {
   2170 		return 0 // version mismatch
   2171 	}
   2172 	if buffer == libc.UintptrFromInt32(0) {
   2173 		return 0
   2174 	}
   2175 	libc.Xmemset(tls, buffer, 0, uint64(120))
   2176 	return int32(1)
   2177 }
   2178 
   2179 func WebPFreeDecBuffer(tls *libc.TLS, buffer uintptr) {
   2180 	if buffer != libc.UintptrFromInt32(0) {
   2181 		if (*WebPDecBuffer)(unsafe.Pointer(buffer)).Fis_external_memory <= 0 {
   2182 			WebPSafeFree(tls, (*WebPDecBuffer)(unsafe.Pointer(buffer)).Fprivate_memory)
   2183 		}
   2184 		(*WebPDecBuffer)(unsafe.Pointer(buffer)).Fprivate_memory = libc.UintptrFromInt32(0)
   2185 	}
   2186 }
   2187 
   2188 func WebPCopyDecBuffer(tls *libc.TLS, src uintptr, dst uintptr) {
   2189 	if src != libc.UintptrFromInt32(0) && dst != libc.UintptrFromInt32(0) {
   2190 		**(**WebPDecBuffer)(__ccgo_up(dst)) = **(**WebPDecBuffer)(__ccgo_up(src))
   2191 		if (*WebPDecBuffer)(unsafe.Pointer(src)).Fprivate_memory != libc.UintptrFromInt32(0) {
   2192 			(*WebPDecBuffer)(unsafe.Pointer(dst)).Fis_external_memory = int32(1) // dst buffer doesn't own the memory.
   2193 			(*WebPDecBuffer)(unsafe.Pointer(dst)).Fprivate_memory = libc.UintptrFromInt32(0)
   2194 		}
   2195 	}
   2196 }
   2197 
   2198 // C documentation
   2199 //
   2200 //	// Copy and transfer ownership from src to dst (beware of parameter order!)
   2201 func WebPGrabDecBuffer(tls *libc.TLS, src uintptr, dst uintptr) {
   2202 	if src != libc.UintptrFromInt32(0) && dst != libc.UintptrFromInt32(0) {
   2203 		**(**WebPDecBuffer)(__ccgo_up(dst)) = **(**WebPDecBuffer)(__ccgo_up(src))
   2204 		if (*WebPDecBuffer)(unsafe.Pointer(src)).Fprivate_memory != libc.UintptrFromInt32(0) {
   2205 			(*WebPDecBuffer)(unsafe.Pointer(src)).Fis_external_memory = int32(1) // src relinquishes ownership
   2206 			(*WebPDecBuffer)(unsafe.Pointer(src)).Fprivate_memory = libc.UintptrFromInt32(0)
   2207 		}
   2208 	}
   2209 }
   2210 
   2211 func WebPCopyDecBufferPixels(tls *libc.TLS, src_buf uintptr, dst_buf uintptr) (r VP8StatusCode1) {
   2212 	var dst, dst1, src, src1 uintptr
   2213 	var v1, v4 int32
   2214 	var v3, v6 WEBP_CSP_MODE1
   2215 	var v9 bool
   2216 	_, _, _, _, _, _, _, _, _ = dst, dst1, src, src1, v1, v3, v4, v6, v9
   2217 	(*WebPDecBuffer)(unsafe.Pointer(dst_buf)).Fwidth = (*WebPDecBuffer)(unsafe.Pointer(src_buf)).Fwidth
   2218 	(*WebPDecBuffer)(unsafe.Pointer(dst_buf)).Fheight = (*WebPDecBuffer)(unsafe.Pointer(src_buf)).Fheight
   2219 	if CheckDecBuffer(tls, dst_buf) != int32(VP8_STATUS_OK) {
   2220 		return int32(VP8_STATUS_INVALID_PARAM)
   2221 	}
   2222 	v1 = libc.BoolInt32((*WebPDecBuffer)(unsafe.Pointer(src_buf)).Fcolorspace < int32(MODE_YUV))
   2223 	goto _2
   2224 _2:
   2225 	if v1 != 0 {
   2226 		src = src_buf + 16
   2227 		dst = dst_buf + 16
   2228 		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*int32(kModeBpp[(*WebPDecBuffer)(unsafe.Pointer(src_buf)).Fcolorspace]), (*WebPDecBuffer)(unsafe.Pointer(src_buf)).Fheight)
   2229 	} else {
   2230 		src1 = src_buf + 16
   2231 		dst1 = dst_buf + 16
   2232 		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)
   2233 		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))
   2234 		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))
   2235 		v3 = (*WebPDecBuffer)(unsafe.Pointer(src_buf)).Fcolorspace
   2236 		if v9 = v3 == int32(MODE_RGBA) || v3 == int32(MODE_BGRA) || v3 == int32(MODE_ARGB) || v3 == int32(MODE_RGBA_4444) || v3 == int32(MODE_YUVA); !v9 {
   2237 			v6 = v3
   2238 			v4 = libc.BoolInt32(v6 == int32(MODE_rgbA) || v6 == int32(MODE_bgrA) || v6 == int32(MODE_Argb) || v6 == int32(MODE_rgbA_4444))
   2239 			goto _8
   2240 		_8:
   2241 		}
   2242 		v1 = libc.BoolInt32(v9 || v4 != 0)
   2243 		goto _5
   2244 	_5:
   2245 		if v1 != 0 {
   2246 			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)
   2247 		}
   2248 	}
   2249 	return int32(VP8_STATUS_OK)
   2250 }
   2251 
   2252 func WebPAvoidSlowMemory(tls *libc.TLS, output uintptr, features uintptr) (r int32) {
   2253 	var v1 WEBP_CSP_MODE1
   2254 	var v2 int32
   2255 	var v4 bool
   2256 	_, _, _ = v1, v2, v4
   2257 	if v4 = (*WebPDecBuffer)(unsafe.Pointer(output)).Fis_external_memory >= int32(2); v4 {
   2258 		v1 = (*WebPDecBuffer)(unsafe.Pointer(output)).Fcolorspace
   2259 		v2 = libc.BoolInt32(v1 == int32(MODE_rgbA) || v1 == int32(MODE_bgrA) || v1 == int32(MODE_Argb) || v1 == int32(MODE_rgbA_4444))
   2260 		goto _3
   2261 	_3:
   2262 	}
   2263 	return libc.BoolInt32(v4 && v2 != 0 && (features != libc.UintptrFromInt32(0) && (*WebPBitstreamFeatures)(unsafe.Pointer(features)).Fhas_alpha != 0))
   2264 }
   2265 
   2266 const DITHER_AMP_TAB_SIZE = 12
   2267 const MIN_DITHER_AMP = 4
   2268 
   2269 var kHashMul2 = uint32(0x1e35a7bd)
   2270 
   2271 //------------------------------------------------------------------------------
   2272 
   2273 // Copyright 2010 Google Inc. All Rights Reserved.
   2274 //
   2275 // Use of this source code is governed by a BSD-style license
   2276 // that can be found in the COPYING file in the root of the source
   2277 // tree. An additional intellectual property rights grant can be found
   2278 // in the file PATENTS. All contributing project authors may
   2279 // be found in the AUTHORS file in the root of the source tree.
   2280 // -----------------------------------------------------------------------------
   2281 //
   2282 //  Main decoding functions for WebP images.
   2283 //
   2284 // Author: Skal (pascal.massimino@gmail.com)
   2285 
   2286 // Copyright 2010 Google Inc. All Rights Reserved.
   2287 //
   2288 // Use of this source code is governed by a BSD-style license
   2289 // that can be found in the COPYING file in the root of the source
   2290 // tree. An additional intellectual property rights grant can be found
   2291 // in the file PATENTS. All contributing project authors may
   2292 // be found in the AUTHORS file in the root of the source tree.
   2293 // -----------------------------------------------------------------------------
   2294 //
   2295 //  Common types + memory wrappers
   2296 //
   2297 // Author: Skal (pascal.massimino@gmail.com)
   2298 
   2299 //------------------------------------------------------------------------------
   2300 // Main reconstruction function.
   2301 
   2302 var kScan = [16]uint16_t{
   2303 	1:  uint16(libc.Int32FromInt32(4) + libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)),
   2304 	2:  uint16(libc.Int32FromInt32(8) + libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)),
   2305 	3:  uint16(libc.Int32FromInt32(12) + libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)),
   2306 	4:  uint16(libc.Int32FromInt32(0) + libc.Int32FromInt32(4)*libc.Int32FromInt32(BPS)),
   2307 	5:  uint16(libc.Int32FromInt32(4) + libc.Int32FromInt32(4)*libc.Int32FromInt32(BPS)),
   2308 	6:  uint16(libc.Int32FromInt32(8) + libc.Int32FromInt32(4)*libc.Int32FromInt32(BPS)),
   2309 	7:  uint16(libc.Int32FromInt32(12) + libc.Int32FromInt32(4)*libc.Int32FromInt32(BPS)),
   2310 	8:  uint16(libc.Int32FromInt32(0) + libc.Int32FromInt32(8)*libc.Int32FromInt32(BPS)),
   2311 	9:  uint16(libc.Int32FromInt32(4) + libc.Int32FromInt32(8)*libc.Int32FromInt32(BPS)),
   2312 	10: uint16(libc.Int32FromInt32(8) + libc.Int32FromInt32(8)*libc.Int32FromInt32(BPS)),
   2313 	11: uint16(libc.Int32FromInt32(12) + libc.Int32FromInt32(8)*libc.Int32FromInt32(BPS)),
   2314 	12: uint16(libc.Int32FromInt32(0) + libc.Int32FromInt32(12)*libc.Int32FromInt32(BPS)),
   2315 	13: uint16(libc.Int32FromInt32(4) + libc.Int32FromInt32(12)*libc.Int32FromInt32(BPS)),
   2316 	14: uint16(libc.Int32FromInt32(8) + libc.Int32FromInt32(12)*libc.Int32FromInt32(BPS)),
   2317 	15: uint16(libc.Int32FromInt32(12) + libc.Int32FromInt32(12)*libc.Int32FromInt32(BPS)),
   2318 }
   2319 
   2320 func CheckMode(tls *libc.TLS, mb_x int32, mb_y int32, mode int32) (r int32) {
   2321 	var v1 int32
   2322 	_ = v1
   2323 	if mode == int32(B_DC_PRED) {
   2324 		if mb_x == 0 {
   2325 			if mb_y == 0 {
   2326 				v1 = int32(B_DC_PRED_NOTOPLEFT)
   2327 			} else {
   2328 				v1 = int32(B_DC_PRED_NOLEFT)
   2329 			}
   2330 			return v1
   2331 		} else {
   2332 			if mb_y == 0 {
   2333 				v1 = int32(B_DC_PRED_NOTOP)
   2334 			} else {
   2335 				v1 = int32(B_DC_PRED)
   2336 			}
   2337 			return v1
   2338 		}
   2339 	}
   2340 	return mode
   2341 }
   2342 
   2343 func Copy32b(tls *libc.TLS, dst uintptr, src uintptr) {
   2344 	libc.Xmemcpy(tls, dst, src, uint64(4))
   2345 }
   2346 
   2347 func DoTransform(tls *libc.TLS, bits uint32_t, src uintptr, dst uintptr) {
   2348 	switch bits >> libc.Int32FromInt32(30) {
   2349 	case uint32(3):
   2350 		(*(*func(*libc.TLS, uintptr, uintptr, int32))(unsafe.Pointer(&struct{ uintptr }{VP8Transform})))(tls, src, dst, 0)
   2351 	case uint32(2):
   2352 		(*(*func(*libc.TLS, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8TransformAC3})))(tls, src, dst)
   2353 	case uint32(1):
   2354 		(*(*func(*libc.TLS, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8TransformDC})))(tls, src, dst)
   2355 	default:
   2356 		break
   2357 	}
   2358 }
   2359 
   2360 func DoUVTransform(tls *libc.TLS, bits uint32_t, src uintptr, dst uintptr) {
   2361 	if bits&uint32(0xff) != 0 { // any non-zero coeff at all?
   2362 		if bits&uint32(0xaa) != 0 { // any non-zero AC coefficient?
   2363 			(*(*func(*libc.TLS, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8TransformUV})))(tls, src, dst) // note we don't use the AC3 variant for U/V
   2364 		} else {
   2365 			(*(*func(*libc.TLS, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8TransformDCUV})))(tls, src, dst)
   2366 		}
   2367 	}
   2368 }
   2369 
   2370 func ReconstructRow(tls *libc.TLS, dec uintptr, ctx uintptr) {
   2371 	var bits, bits_uv, v8, v9 uint32_t
   2372 	var block, coeffs, dst, top_right, top_yuv, u_dst, u_out, v_dst, v_out, y_dst, y_out uintptr
   2373 	var cache_id, j, mb_x, mb_y, n, pred_func, pred_func1, uv_offset, y_offset int32
   2374 	var v3, v4 uint8_t
   2375 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
   2376 	mb_y = (*VP8ThreadContext)(unsafe.Pointer(ctx)).Fmb_y
   2377 	cache_id = (*VP8ThreadContext)(unsafe.Pointer(ctx)).Fid
   2378 	y_dst = (*VP8Decoder)(unsafe.Pointer(dec)).Fyuv_b + uintptr(libc.Int32FromInt32(BPS)*libc.Int32FromInt32(1)+libc.Int32FromInt32(8))
   2379 	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))
   2380 	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))
   2381 	// Initialize left-most block.
   2382 	j = 0
   2383 	for {
   2384 		if !(j < int32(16)) {
   2385 			break
   2386 		}
   2387 		**(**uint8_t)(__ccgo_up(y_dst + uintptr(j*int32(BPS)-int32(1)))) = uint8(129)
   2388 		goto _1
   2389 	_1:
   2390 		;
   2391 		j = j + 1
   2392 	}
   2393 	j = 0
   2394 	for {
   2395 		if !(j < int32(8)) {
   2396 			break
   2397 		}
   2398 		**(**uint8_t)(__ccgo_up(u_dst + uintptr(j*int32(BPS)-int32(1)))) = uint8(129)
   2399 		**(**uint8_t)(__ccgo_up(v_dst + uintptr(j*int32(BPS)-int32(1)))) = uint8(129)
   2400 		goto _2
   2401 	_2:
   2402 		;
   2403 		j = j + 1
   2404 	}
   2405 	// Init top-left sample on left column too.
   2406 	if mb_y > 0 {
   2407 		v4 = libc.Uint8FromInt32(129)
   2408 		**(**uint8_t)(__ccgo_up(v_dst + uintptr(-libc.Int32FromInt32(1)-libc.Int32FromInt32(BPS)))) = v4
   2409 		v3 = v4
   2410 		**(**uint8_t)(__ccgo_up(u_dst + uintptr(-libc.Int32FromInt32(1)-libc.Int32FromInt32(BPS)))) = v3
   2411 		**(**uint8_t)(__ccgo_up(y_dst + uintptr(-libc.Int32FromInt32(1)-libc.Int32FromInt32(BPS)))) = v3
   2412 	} else {
   2413 		// we only need to do this init once at block (0,0).
   2414 		// Afterward, it remains valid for the whole topmost row.
   2415 		libc.Xmemset(tls, y_dst-uintptr(BPS)-uintptr(1), int32(127), uint64(libc.Int32FromInt32(16)+libc.Int32FromInt32(4)+libc.Int32FromInt32(1)))
   2416 		libc.Xmemset(tls, u_dst-uintptr(BPS)-uintptr(1), int32(127), uint64(libc.Int32FromInt32(8)+libc.Int32FromInt32(1)))
   2417 		libc.Xmemset(tls, v_dst-uintptr(BPS)-uintptr(1), int32(127), uint64(libc.Int32FromInt32(8)+libc.Int32FromInt32(1)))
   2418 	}
   2419 	// Reconstruct one row.
   2420 	mb_x = 0
   2421 	for {
   2422 		if !(mb_x < (*VP8Decoder)(unsafe.Pointer(dec)).Fmb_w) {
   2423 			break
   2424 		}
   2425 		block = (*VP8ThreadContext)(unsafe.Pointer(ctx)).Fmb_data + uintptr(mb_x)*800
   2426 		// Rotate in the left samples from previously decoded block. We move four
   2427 		// pixels at a time for alignment reason, and because of in-loop filter.
   2428 		if mb_x > 0 {
   2429 			j = -int32(1)
   2430 			for {
   2431 				if !(j < int32(16)) {
   2432 					break
   2433 				}
   2434 				Copy32b(tls, y_dst+uintptr(j*int32(BPS)-int32(4)), y_dst+uintptr(j*int32(BPS)+int32(12)))
   2435 				goto _6
   2436 			_6:
   2437 				;
   2438 				j = j + 1
   2439 			}
   2440 			j = -int32(1)
   2441 			for {
   2442 				if !(j < int32(8)) {
   2443 					break
   2444 				}
   2445 				Copy32b(tls, u_dst+uintptr(j*int32(BPS)-int32(4)), u_dst+uintptr(j*int32(BPS)+int32(4)))
   2446 				Copy32b(tls, v_dst+uintptr(j*int32(BPS)-int32(4)), v_dst+uintptr(j*int32(BPS)+int32(4)))
   2447 				goto _7
   2448 			_7:
   2449 				;
   2450 				j = j + 1
   2451 			}
   2452 		}
   2453 		// bring top samples into the cache
   2454 		top_yuv = (*VP8Decoder)(unsafe.Pointer(dec)).Fyuv_t + uintptr(mb_x)*32
   2455 		coeffs = block
   2456 		bits = (*VP8MBData)(unsafe.Pointer(block)).Fnon_zero_y
   2457 		if mb_y > 0 {
   2458 			libc.Xmemcpy(tls, y_dst-uintptr(BPS), top_yuv, uint64(16))
   2459 			libc.Xmemcpy(tls, u_dst-uintptr(BPS), top_yuv+16, uint64(8))
   2460 			libc.Xmemcpy(tls, v_dst-uintptr(BPS), top_yuv+24, uint64(8))
   2461 		}
   2462 		// predict and add residuals
   2463 		if (*VP8MBData)(unsafe.Pointer(block)).Fis_i4x4 != 0 { // 4x4
   2464 			top_right = y_dst - libc.UintptrFromInt32(BPS) + libc.UintptrFromInt32(16)
   2465 			if mb_y > 0 {
   2466 				if mb_x >= (*VP8Decoder)(unsafe.Pointer(dec)).Fmb_w-int32(1) { // on rightmost border
   2467 					libc.Xmemset(tls, top_right, int32(**(**uint8_t)(__ccgo_up(top_yuv + 15))), uint64(4))
   2468 				} else {
   2469 					libc.Xmemcpy(tls, top_right, top_yuv+1*32, uint64(4))
   2470 				}
   2471 			}
   2472 			// replicate the top-right pixels below
   2473 			v9 = **(**uint32_t)(__ccgo_up(top_right))
   2474 			**(**uint32_t)(__ccgo_up(top_right + uintptr(libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS))*4)) = v9
   2475 			v8 = v9
   2476 			**(**uint32_t)(__ccgo_up(top_right + uintptr(libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS))*4)) = v8
   2477 			**(**uint32_t)(__ccgo_up(top_right + 32*4)) = v8
   2478 			// predict and add residuals for all 4x4 blocks in turn.
   2479 			n = 0
   2480 			for {
   2481 				if !(n < int32(16)) {
   2482 					break
   2483 				}
   2484 				dst = y_dst + uintptr(kScan[n])
   2485 				(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8PredLuma4[**(**uint8_t)(__ccgo_up(block + 769 + uintptr(n)))]})))(tls, dst)
   2486 				DoTransform(tls, bits, coeffs+uintptr(n*int32(16))*2, dst)
   2487 				goto _10
   2488 			_10:
   2489 				;
   2490 				n = n + 1
   2491 				bits = bits << uint32(2)
   2492 			}
   2493 		} else { // 16x16
   2494 			pred_func = CheckMode(tls, mb_x, mb_y, int32(**(**uint8_t)(__ccgo_up(block + 769))))
   2495 			(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8PredLuma16[pred_func]})))(tls, y_dst)
   2496 			if bits != uint32(0) {
   2497 				n = 0
   2498 				for {
   2499 					if !(n < int32(16)) {
   2500 						break
   2501 					}
   2502 					DoTransform(tls, bits, coeffs+uintptr(n*int32(16))*2, y_dst+uintptr(kScan[n]))
   2503 					goto _11
   2504 				_11:
   2505 					;
   2506 					n = n + 1
   2507 					bits = bits << uint32(2)
   2508 				}
   2509 			}
   2510 		}
   2511 		// Chroma
   2512 		bits_uv = (*VP8MBData)(unsafe.Pointer(block)).Fnon_zero_uv
   2513 		pred_func1 = CheckMode(tls, mb_x, mb_y, int32((*VP8MBData)(unsafe.Pointer(block)).Fuvmode))
   2514 		(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8PredChroma8[pred_func1]})))(tls, u_dst)
   2515 		(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8PredChroma8[pred_func1]})))(tls, v_dst)
   2516 		DoUVTransform(tls, bits_uv>>0, coeffs+uintptr(libc.Int32FromInt32(16)*libc.Int32FromInt32(16))*2, u_dst)
   2517 		DoUVTransform(tls, bits_uv>>int32(8), coeffs+uintptr(libc.Int32FromInt32(20)*libc.Int32FromInt32(16))*2, v_dst)
   2518 		// stash away top samples for next block
   2519 		if mb_y < (*VP8Decoder)(unsafe.Pointer(dec)).Fmb_h-int32(1) {
   2520 			libc.Xmemcpy(tls, top_yuv, y_dst+uintptr(libc.Int32FromInt32(15)*libc.Int32FromInt32(BPS)), uint64(16))
   2521 			libc.Xmemcpy(tls, top_yuv+16, u_dst+uintptr(libc.Int32FromInt32(7)*libc.Int32FromInt32(BPS)), uint64(8))
   2522 			libc.Xmemcpy(tls, top_yuv+24, v_dst+uintptr(libc.Int32FromInt32(7)*libc.Int32FromInt32(BPS)), uint64(8))
   2523 		}
   2524 		// Transfer reconstructed samples from yuv_b cache to final destination.
   2525 		y_offset = cache_id * int32(16) * (*VP8Decoder)(unsafe.Pointer(dec)).Fcache_y_stride
   2526 		uv_offset = cache_id * int32(8) * (*VP8Decoder)(unsafe.Pointer(dec)).Fcache_uv_stride
   2527 		y_out = (*VP8Decoder)(unsafe.Pointer(dec)).Fcache_y + uintptr(mb_x*int32(16)) + uintptr(y_offset)
   2528 		u_out = (*VP8Decoder)(unsafe.Pointer(dec)).Fcache_u + uintptr(mb_x*int32(8)) + uintptr(uv_offset)
   2529 		v_out = (*VP8Decoder)(unsafe.Pointer(dec)).Fcache_v + uintptr(mb_x*int32(8)) + uintptr(uv_offset)
   2530 		j = 0
   2531 		for {
   2532 			if !(j < int32(16)) {
   2533 				break
   2534 			}
   2535 			libc.Xmemcpy(tls, y_out+uintptr(j*(*VP8Decoder)(unsafe.Pointer(dec)).Fcache_y_stride), y_dst+uintptr(j*int32(BPS)), uint64(16))
   2536 			goto _12
   2537 		_12:
   2538 			;
   2539 			j = j + 1
   2540 		}
   2541 		j = 0
   2542 		for {
   2543 			if !(j < int32(8)) {
   2544 				break
   2545 			}
   2546 			libc.Xmemcpy(tls, u_out+uintptr(j*(*VP8Decoder)(unsafe.Pointer(dec)).Fcache_uv_stride), u_dst+uintptr(j*int32(BPS)), uint64(8))
   2547 			libc.Xmemcpy(tls, v_out+uintptr(j*(*VP8Decoder)(unsafe.Pointer(dec)).Fcache_uv_stride), v_dst+uintptr(j*int32(BPS)), uint64(8))
   2548 			goto _13
   2549 		_13:
   2550 			;
   2551 			j = j + 1
   2552 		}
   2553 		goto _5
   2554 	_5:
   2555 		;
   2556 		mb_x = mb_x + 1
   2557 	}
   2558 }
   2559 
   2560 //------------------------------------------------------------------------------
   2561 // Filtering
   2562 
   2563 // C documentation
   2564 //
   2565 //	// kFilterExtraRows[] = How many extra lines are needed on the MB boundary
   2566 //	// for caching, given a filtering level.
   2567 //	// Simple filter:  up to 2 luma samples are read and 1 is written.
   2568 //	// Complex filter: up to 4 luma samples are read and 3 are written. Same for
   2569 //	//                 U/V, so it's 8 samples total (because of the 2x upsampling).
   2570 var kFilterExtraRows = [3]uint8_t{
   2571 	1: uint8(2),
   2572 	2: uint8(8),
   2573 }
   2574 
   2575 func DoFilter(tls *libc.TLS, dec uintptr, mb_x int32, mb_y int32) {
   2576 	var cache_id, hev_thresh, ilevel, limit, uv_bps, y_bps int32
   2577 	var ctx, f_info, u_dst, v_dst, y_dst uintptr
   2578 	_, _, _, _, _, _, _, _, _, _, _ = cache_id, ctx, f_info, hev_thresh, ilevel, limit, u_dst, uv_bps, v_dst, y_bps, y_dst
   2579 	ctx = dec + 216
   2580 	cache_id = (*VP8ThreadContext)(unsafe.Pointer(ctx)).Fid
   2581 	y_bps = (*VP8Decoder)(unsafe.Pointer(dec)).Fcache_y_stride
   2582 	f_info = (*VP8ThreadContext)(unsafe.Pointer(ctx)).Ff_info + uintptr(mb_x)*4
   2583 	y_dst = (*VP8Decoder)(unsafe.Pointer(dec)).Fcache_y + uintptr(cache_id*int32(16)*y_bps) + uintptr(mb_x*int32(16))
   2584 	ilevel = int32((*VP8FInfo)(unsafe.Pointer(f_info)).Ff_ilevel)
   2585 	limit = int32((*VP8FInfo)(unsafe.Pointer(f_info)).Ff_limit)
   2586 	if limit == 0 {
   2587 		return
   2588 	}
   2589 	if (*VP8Decoder)(unsafe.Pointer(dec)).Ffilter_type == int32(1) { // simple
   2590 		if mb_x > 0 {
   2591 			(*(*func(*libc.TLS, uintptr, int32, int32))(unsafe.Pointer(&struct{ uintptr }{VP8SimpleHFilter16})))(tls, y_dst, y_bps, limit+int32(4))
   2592 		}
   2593 		if (*VP8FInfo)(unsafe.Pointer(f_info)).Ff_inner != 0 {
   2594 			(*(*func(*libc.TLS, uintptr, int32, int32))(unsafe.Pointer(&struct{ uintptr }{VP8SimpleHFilter16i})))(tls, y_dst, y_bps, limit)
   2595 		}
   2596 		if mb_y > 0 {
   2597 			(*(*func(*libc.TLS, uintptr, int32, int32))(unsafe.Pointer(&struct{ uintptr }{VP8SimpleVFilter16})))(tls, y_dst, y_bps, limit+int32(4))
   2598 		}
   2599 		if (*VP8FInfo)(unsafe.Pointer(f_info)).Ff_inner != 0 {
   2600 			(*(*func(*libc.TLS, uintptr, int32, int32))(unsafe.Pointer(&struct{ uintptr }{VP8SimpleVFilter16i})))(tls, y_dst, y_bps, limit)
   2601 		}
   2602 	} else { // complex
   2603 		uv_bps = (*VP8Decoder)(unsafe.Pointer(dec)).Fcache_uv_stride
   2604 		u_dst = (*VP8Decoder)(unsafe.Pointer(dec)).Fcache_u + uintptr(cache_id*int32(8)*uv_bps) + uintptr(mb_x*int32(8))
   2605 		v_dst = (*VP8Decoder)(unsafe.Pointer(dec)).Fcache_v + uintptr(cache_id*int32(8)*uv_bps) + uintptr(mb_x*int32(8))
   2606 		hev_thresh = int32((*VP8FInfo)(unsafe.Pointer(f_info)).Fhev_thresh)
   2607 		if mb_x > 0 {
   2608 			(*(*func(*libc.TLS, uintptr, int32, int32, int32, int32))(unsafe.Pointer(&struct{ uintptr }{VP8HFilter16})))(tls, y_dst, y_bps, limit+int32(4), ilevel, hev_thresh)
   2609 			(*(*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)
   2610 		}
   2611 		if (*VP8FInfo)(unsafe.Pointer(f_info)).Ff_inner != 0 {
   2612 			(*(*func(*libc.TLS, uintptr, int32, int32, int32, int32))(unsafe.Pointer(&struct{ uintptr }{VP8HFilter16i})))(tls, y_dst, y_bps, limit, ilevel, hev_thresh)
   2613 			(*(*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)
   2614 		}
   2615 		if mb_y > 0 {
   2616 			(*(*func(*libc.TLS, uintptr, int32, int32, int32, int32))(unsafe.Pointer(&struct{ uintptr }{VP8VFilter16})))(tls, y_dst, y_bps, limit+int32(4), ilevel, hev_thresh)
   2617 			(*(*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)
   2618 		}
   2619 		if (*VP8FInfo)(unsafe.Pointer(f_info)).Ff_inner != 0 {
   2620 			(*(*func(*libc.TLS, uintptr, int32, int32, int32, int32))(unsafe.Pointer(&struct{ uintptr }{VP8VFilter16i})))(tls, y_dst, y_bps, limit, ilevel, hev_thresh)
   2621 			(*(*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)
   2622 		}
   2623 	}
   2624 }
   2625 
   2626 // C documentation
   2627 //
   2628 //	// Filter the decoded macroblock row (if needed)
   2629 func FilterRow(tls *libc.TLS, dec uintptr) {
   2630 	var mb_x, mb_y int32
   2631 	_, _ = mb_x, mb_y
   2632 	mb_y = (*VP8Decoder)(unsafe.Pointer(dec)).Fthread_ctx.Fmb_y
   2633 	mb_x = (*VP8Decoder)(unsafe.Pointer(dec)).Ftl_mb_x
   2634 	for {
   2635 		if !(mb_x < (*VP8Decoder)(unsafe.Pointer(dec)).Fbr_mb_x) {
   2636 			break
   2637 		}
   2638 		DoFilter(tls, dec, mb_x, mb_y)
   2639 		goto _1
   2640 	_1:
   2641 		;
   2642 		mb_x = mb_x + 1
   2643 	}
   2644 }
   2645 
   2646 //------------------------------------------------------------------------------
   2647 // Precompute the filtering strength for each segment and each i4x4/i16x16 mode.
   2648 
   2649 func PrecomputeFilterStrengths(tls *libc.TLS, dec uintptr) {
   2650 	var base_level, i4x4, ilevel, level, s, v3, v4 int32
   2651 	var hdr, info uintptr
   2652 	_, _, _, _, _, _, _, _, _ = base_level, hdr, i4x4, ilevel, info, level, s, v3, v4
   2653 	if (*VP8Decoder)(unsafe.Pointer(dec)).Ffilter_type > 0 {
   2654 		hdr = dec + 84
   2655 		s = 0
   2656 		for {
   2657 			if !(s < int32(NUM_MB_SEGMENTS)) {
   2658 				break
   2659 			}
   2660 			if (*VP8Decoder)(unsafe.Pointer(dec)).Fsegment_hdr.Fuse_segment != 0 {
   2661 				base_level = int32(**(**int8_t)(__ccgo_up(dec + 132 + 16 + uintptr(s))))
   2662 				if !((*VP8Decoder)(unsafe.Pointer(dec)).Fsegment_hdr.Fabsolute_delta != 0) {
   2663 					base_level = base_level + (*VP8FilterHeader)(unsafe.Pointer(hdr)).Flevel
   2664 				}
   2665 			} else {
   2666 				base_level = (*VP8FilterHeader)(unsafe.Pointer(hdr)).Flevel
   2667 			}
   2668 			i4x4 = 0
   2669 			for {
   2670 				if !(i4x4 <= int32(1)) {
   2671 					break
   2672 				}
   2673 				info = dec + 2924 + uintptr(s)*8 + uintptr(i4x4)*4
   2674 				level = base_level
   2675 				if (*VP8FilterHeader)(unsafe.Pointer(hdr)).Fuse_lf_delta != 0 {
   2676 					level = level + **(**int32)(__ccgo_up(hdr + 16))
   2677 					if i4x4 != 0 {
   2678 						level = level + **(**int32)(__ccgo_up(hdr + 32))
   2679 					}
   2680 				}
   2681 				if level < 0 {
   2682 					v3 = 0
   2683 				} else {
   2684 					if level > int32(63) {
   2685 						v4 = int32(63)
   2686 					} else {
   2687 						v4 = level
   2688 					}
   2689 					v3 = v4
   2690 				}
   2691 				level = v3
   2692 				if level > 0 {
   2693 					ilevel = level
   2694 					if (*VP8FilterHeader)(unsafe.Pointer(hdr)).Fsharpness > 0 {
   2695 						if (*VP8FilterHeader)(unsafe.Pointer(hdr)).Fsharpness > int32(4) {
   2696 							ilevel = ilevel >> int32(2)
   2697 						} else {
   2698 							ilevel = ilevel >> int32(1)
   2699 						}
   2700 						if ilevel > int32(9)-(*VP8FilterHeader)(unsafe.Pointer(hdr)).Fsharpness {
   2701 							ilevel = int32(9) - (*VP8FilterHeader)(unsafe.Pointer(hdr)).Fsharpness
   2702 						}
   2703 					}
   2704 					if ilevel < int32(1) {
   2705 						ilevel = int32(1)
   2706 					}
   2707 					(*VP8FInfo)(unsafe.Pointer(info)).Ff_ilevel = uint8(ilevel)
   2708 					(*VP8FInfo)(unsafe.Pointer(info)).Ff_limit = uint8(int32(2)*level + ilevel)
   2709 					if level >= int32(40) {
   2710 						v3 = int32(2)
   2711 					} else {
   2712 						if level >= int32(15) {
   2713 							v4 = int32(1)
   2714 						} else {
   2715 							v4 = 0
   2716 						}
   2717 						v3 = v4
   2718 					}
   2719 					(*VP8FInfo)(unsafe.Pointer(info)).Fhev_thresh = uint8(v3)
   2720 				} else {
   2721 					(*VP8FInfo)(unsafe.Pointer(info)).Ff_limit = uint8(0) // no filtering
   2722 				}
   2723 				(*VP8FInfo)(unsafe.Pointer(info)).Ff_inner = uint8(i4x4)
   2724 				goto _2
   2725 			_2:
   2726 				;
   2727 				i4x4 = i4x4 + 1
   2728 			}
   2729 			goto _1
   2730 		_1:
   2731 			;
   2732 			s = s + 1
   2733 		}
   2734 	}
   2735 }
   2736 
   2737 //------------------------------------------------------------------------------
   2738 // Dithering
   2739 
   2740 // minimal amp that will provide a non-zero dithering effect
   2741 
   2742 var kQuantToDitherAmp = [12]uint8_t{
   2743 	0:  uint8(8),
   2744 	1:  uint8(7),
   2745 	2:  uint8(6),
   2746 	3:  uint8(4),
   2747 	4:  uint8(4),
   2748 	5:  uint8(2),
   2749 	6:  uint8(2),
   2750 	7:  uint8(2),
   2751 	8:  uint8(1),
   2752 	9:  uint8(1),
   2753 	10: uint8(1),
   2754 	11: uint8(1),
   2755 }
   2756 
   2757 func VP8InitDithering(tls *libc.TLS, options uintptr, dec uintptr) {
   2758 	var all_amp, d, f, idx, max_amp, s, v1, v2, v4 int32
   2759 	var dqm uintptr
   2760 	_, _, _, _, _, _, _, _, _, _ = all_amp, d, dqm, f, idx, max_amp, s, v1, v2, v4
   2761 	if options != libc.UintptrFromInt32(0) {
   2762 		d = (*WebPDecoderOptions)(unsafe.Pointer(options)).Fdithering_strength
   2763 		max_amp = libc.Int32FromInt32(1)<<libc.Int32FromInt32(VP8_RANDOM_DITHER_FIX) - libc.Int32FromInt32(1)
   2764 		if d < 0 {
   2765 			v1 = 0
   2766 		} else {
   2767 			if d > int32(100) {
   2768 				v2 = max_amp
   2769 			} else {
   2770 				v2 = d * max_amp / int32(100)
   2771 			}
   2772 			v1 = v2
   2773 		}
   2774 		f = v1
   2775 		if f > 0 {
   2776 			all_amp = 0
   2777 			s = 0
   2778 			for {
   2779 				if !(s < int32(NUM_MB_SEGMENTS)) {
   2780 					break
   2781 				}
   2782 				dqm = dec + 1060 + uintptr(s)*32
   2783 				if (*VP8QuantMatrix)(unsafe.Pointer(dqm)).Fuv_quant < int32(DITHER_AMP_TAB_SIZE) {
   2784 					if (*VP8QuantMatrix)(unsafe.Pointer(dqm)).Fuv_quant < 0 {
   2785 						v4 = 0
   2786 					} else {
   2787 						v4 = (*VP8QuantMatrix)(unsafe.Pointer(dqm)).Fuv_quant
   2788 					}
   2789 					idx = v4
   2790 					(*VP8QuantMatrix)(unsafe.Pointer(dqm)).Fdither = f * int32(kQuantToDitherAmp[idx]) >> int32(3)
   2791 				}
   2792 				all_amp = all_amp | (*VP8QuantMatrix)(unsafe.Pointer(dqm)).Fdither
   2793 				goto _3
   2794 			_3:
   2795 				;
   2796 				s = s + 1
   2797 			}
   2798 			if all_amp != 0 {
   2799 				VP8InitRandom(tls, dec+828, libc.Float32FromFloat32(1))
   2800 				(*VP8Decoder)(unsafe.Pointer(dec)).Fdither = int32(1)
   2801 			}
   2802 		}
   2803 		// potentially allow alpha dithering
   2804 		(*VP8Decoder)(unsafe.Pointer(dec)).Falpha_dithering = (*WebPDecoderOptions)(unsafe.Pointer(options)).Falpha_dithering_strength
   2805 		if (*VP8Decoder)(unsafe.Pointer(dec)).Falpha_dithering > int32(100) {
   2806 			(*VP8Decoder)(unsafe.Pointer(dec)).Falpha_dithering = int32(100)
   2807 		} else {
   2808 			if (*VP8Decoder)(unsafe.Pointer(dec)).Falpha_dithering < 0 {
   2809 				(*VP8Decoder)(unsafe.Pointer(dec)).Falpha_dithering = 0
   2810 			}
   2811 		}
   2812 	}
   2813 }
   2814 
   2815 // C documentation
   2816 //
   2817 //	// Convert to range: [-2,2] for dither=50, [-4,4] for dither=100
   2818 func Dither8x8(tls *libc.TLS, rg1 uintptr, dst uintptr, bps int32, amp1 int32) {
   2819 	bp := tls.Alloc(64)
   2820 	defer tls.Free(64)
   2821 	var diff, i, v3, v4, v6, v8 int32
   2822 	var v2, v5, v7 uintptr
   2823 	var _ /* dither at bp+0 */ [64]uint8_t
   2824 	_, _, _, _, _, _, _, _, _ = diff, i, v2, v3, v4, v5, v6, v7, v8
   2825 	i = 0
   2826 	for {
   2827 		if !(i < libc.Int32FromInt32(8)*libc.Int32FromInt32(8)) {
   2828 			break
   2829 		}
   2830 		v2 = rg1
   2831 		v3 = libc.Int32FromInt32(VP8_DITHER_AMP_BITS) + libc.Int32FromInt32(1)
   2832 		diff = int32(**(**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)))
   2833 		if diff < libc.Int32FromInt32(0) {
   2834 			diff = int32(uint32(diff) + libc.Uint32FromUint32(1)<<libc.Int32FromInt32(31))
   2835 		}
   2836 		**(**uint32_t)(__ccgo_up(v2 + 8 + uintptr((*VP8Random)(unsafe.Pointer(v2)).Findex1)*4)) = uint32(diff)
   2837 		v5 = v2
   2838 		*(*int32)(unsafe.Pointer(v5)) = *(*int32)(unsafe.Pointer(v5)) + 1
   2839 		v4 = *(*int32)(unsafe.Pointer(v5))
   2840 		if v4 == libc.Int32FromInt32(VP8_RANDOM_TABLE_SIZE) {
   2841 			(*VP8Random)(unsafe.Pointer(v2)).Findex1 = 0
   2842 		}
   2843 		v7 = v2 + 4
   2844 		*(*int32)(unsafe.Pointer(v7)) = *(*int32)(unsafe.Pointer(v7)) + 1
   2845 		v6 = *(*int32)(unsafe.Pointer(v7))
   2846 		if v6 == libc.Int32FromInt32(VP8_RANDOM_TABLE_SIZE) {
   2847 			(*VP8Random)(unsafe.Pointer(v2)).Findex2 = 0
   2848 		}
   2849 		diff = int32(uint32(diff)<<libc.Int32FromInt32(1)) >> (int32(32) - v3)
   2850 		diff = diff * amp1 >> int32(VP8_RANDOM_DITHER_FIX)
   2851 		diff = diff + int32(1)<<(v3-int32(1))
   2852 		v8 = diff
   2853 		goto _9
   2854 	_9:
   2855 		(**(**[64]uint8_t)(__ccgo_up(bp)))[i] = uint8(v8)
   2856 		goto _1
   2857 	_1:
   2858 		;
   2859 		i = i + 1
   2860 	}
   2861 	(*(*func(*libc.TLS, uintptr, uintptr, int32))(unsafe.Pointer(&struct{ uintptr }{VP8DitherCombine8x8})))(tls, bp, dst, bps)
   2862 }
   2863 
   2864 func DitherRow(tls *libc.TLS, dec uintptr) {
   2865 	var cache_id, mb_x, uv_bps int32
   2866 	var ctx, data, u_dst, v_dst uintptr
   2867 	_, _, _, _, _, _, _ = cache_id, ctx, data, mb_x, u_dst, uv_bps, v_dst
   2868 	mb_x = (*VP8Decoder)(unsafe.Pointer(dec)).Ftl_mb_x
   2869 	for {
   2870 		if !(mb_x < (*VP8Decoder)(unsafe.Pointer(dec)).Fbr_mb_x) {
   2871 			break
   2872 		}
   2873 		ctx = dec + 216
   2874 		data = (*VP8ThreadContext)(unsafe.Pointer(ctx)).Fmb_data + uintptr(mb_x)*800
   2875 		cache_id = (*VP8ThreadContext)(unsafe.Pointer(ctx)).Fid
   2876 		uv_bps = (*VP8Decoder)(unsafe.Pointer(dec)).Fcache_uv_stride
   2877 		if int32((*VP8MBData)(unsafe.Pointer(data)).Fdither) >= int32(MIN_DITHER_AMP) {
   2878 			u_dst = (*VP8Decoder)(unsafe.Pointer(dec)).Fcache_u + uintptr(cache_id*int32(8)*uv_bps) + uintptr(mb_x*int32(8))
   2879 			v_dst = (*VP8Decoder)(unsafe.Pointer(dec)).Fcache_v + uintptr(cache_id*int32(8)*uv_bps) + uintptr(mb_x*int32(8))
   2880 			Dither8x8(tls, dec+828, u_dst, uv_bps, int32((*VP8MBData)(unsafe.Pointer(data)).Fdither))
   2881 			Dither8x8(tls, dec+828, v_dst, uv_bps, int32((*VP8MBData)(unsafe.Pointer(data)).Fdither))
   2882 		}
   2883 		goto _1
   2884 	_1:
   2885 		;
   2886 		mb_x = mb_x + 1
   2887 	}
   2888 }
   2889 
   2890 //------------------------------------------------------------------------------
   2891 // This function is called after a row of macroblocks is finished decoding.
   2892 // It also takes into account the following restrictions:
   2893 //  * In case of in-loop filtering, we must hold off sending some of the bottom
   2894 //    pixels as they are yet unfiltered. They will be when the next macroblock
   2895 //    row is decoded. Meanwhile, we must preserve them by rotating them in the
   2896 //    cache area. This doesn't hold for the very bottom row of the uncropped
   2897 //    picture of course.
   2898 //  * we must clip the remaining pixels against the cropping area. The VP8Io
   2899 //    struct must have the following fields set correctly before calling put():
   2900 
   2901 // C documentation
   2902 //
   2903 //	// Finalize and transmit a complete row. Return false in case of user-abort.
   2904 func FinishRow(tls *libc.TLS, arg1 uintptr, arg2 uintptr) (r int32) {
   2905 	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
   2906 	var ctx, dec, io, udst, vdst, ydst uintptr
   2907 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
   2908 	dec = arg1
   2909 	io = arg2
   2910 	ok = int32(1)
   2911 	ctx = dec + 216
   2912 	cache_id = (*VP8ThreadContext)(unsafe.Pointer(ctx)).Fid
   2913 	extra_y_rows = int32(kFilterExtraRows[(*VP8Decoder)(unsafe.Pointer(dec)).Ffilter_type])
   2914 	ysize = extra_y_rows * (*VP8Decoder)(unsafe.Pointer(dec)).Fcache_y_stride
   2915 	uvsize = extra_y_rows / int32(2) * (*VP8Decoder)(unsafe.Pointer(dec)).Fcache_uv_stride
   2916 	y_offset = cache_id * int32(16) * (*VP8Decoder)(unsafe.Pointer(dec)).Fcache_y_stride
   2917 	uv_offset = cache_id * int32(8) * (*VP8Decoder)(unsafe.Pointer(dec)).Fcache_uv_stride
   2918 	ydst = (*VP8Decoder)(unsafe.Pointer(dec)).Fcache_y - uintptr(ysize) + uintptr(y_offset)
   2919 	udst = (*VP8Decoder)(unsafe.Pointer(dec)).Fcache_u - uintptr(uvsize) + uintptr(uv_offset)
   2920 	vdst = (*VP8Decoder)(unsafe.Pointer(dec)).Fcache_v - uintptr(uvsize) + uintptr(uv_offset)
   2921 	mb_y = (*VP8ThreadContext)(unsafe.Pointer(ctx)).Fmb_y
   2922 	is_first_row = libc.BoolInt32(mb_y == libc.Int32FromInt32(0))
   2923 	is_last_row = libc.BoolInt32(mb_y >= (*VP8Decoder)(unsafe.Pointer(dec)).Fbr_mb_y-libc.Int32FromInt32(1))
   2924 	if (*VP8Decoder)(unsafe.Pointer(dec)).Fmt_method == int32(2) {
   2925 		ReconstructRow(tls, dec, ctx)
   2926 	}
   2927 	if (*VP8ThreadContext)(unsafe.Pointer(ctx)).Ffilter_row != 0 {
   2928 		FilterRow(tls, dec)
   2929 	}
   2930 	if (*VP8Decoder)(unsafe.Pointer(dec)).Fdither != 0 {
   2931 		DitherRow(tls, dec)
   2932 	}
   2933 	if (*VP8Io)(unsafe.Pointer(io)).Fput != libc.UintptrFromInt32(0) {
   2934 		y_start = mb_y * int32(16)
   2935 		y_end = (mb_y + int32(1)) * int32(16)
   2936 		if !(is_first_row != 0) {
   2937 			y_start = y_start - extra_y_rows
   2938 			(*VP8Io)(unsafe.Pointer(io)).Fy = ydst
   2939 			(*VP8Io)(unsafe.Pointer(io)).Fu = udst
   2940 			(*VP8Io)(unsafe.Pointer(io)).Fv = vdst
   2941 		} else {
   2942 			(*VP8Io)(unsafe.Pointer(io)).Fy = (*VP8Decoder)(unsafe.Pointer(dec)).Fcache_y + uintptr(y_offset)
   2943 			(*VP8Io)(unsafe.Pointer(io)).Fu = (*VP8Decoder)(unsafe.Pointer(dec)).Fcache_u + uintptr(uv_offset)
   2944 			(*VP8Io)(unsafe.Pointer(io)).Fv = (*VP8Decoder)(unsafe.Pointer(dec)).Fcache_v + uintptr(uv_offset)
   2945 		}
   2946 		if !(is_last_row != 0) {
   2947 			y_end = y_end - extra_y_rows
   2948 		}
   2949 		if y_end > (*VP8Io)(unsafe.Pointer(io)).Fcrop_bottom {
   2950 			y_end = (*VP8Io)(unsafe.Pointer(io)).Fcrop_bottom // make sure we don't overflow on last row.
   2951 		}
   2952 		// If dec->alpha_data is not NULL, we have some alpha plane present.
   2953 		(*VP8Io)(unsafe.Pointer(io)).Fa = libc.UintptrFromInt32(0)
   2954 		if (*VP8Decoder)(unsafe.Pointer(dec)).Falpha_data != libc.UintptrFromInt32(0) && y_start < y_end {
   2955 			(*VP8Io)(unsafe.Pointer(io)).Fa = VP8DecompressAlphaRows(tls, dec, io, y_start, y_end-y_start)
   2956 			if (*VP8Io)(unsafe.Pointer(io)).Fa == libc.UintptrFromInt32(0) {
   2957 				return VP8SetError(tls, dec, int32(VP8_STATUS_BITSTREAM_ERROR), __ccgo_ts+37)
   2958 			}
   2959 		}
   2960 		if y_start < (*VP8Io)(unsafe.Pointer(io)).Fcrop_top {
   2961 			delta_y = (*VP8Io)(unsafe.Pointer(io)).Fcrop_top - y_start
   2962 			y_start = (*VP8Io)(unsafe.Pointer(io)).Fcrop_top
   2963 			**(**uintptr)(__ccgo_up(io + 24)) += uintptr((*VP8Decoder)(unsafe.Pointer(dec)).Fcache_y_stride * delta_y)
   2964 			**(**uintptr)(__ccgo_up(io + 32)) += uintptr((*VP8Decoder)(unsafe.Pointer(dec)).Fcache_uv_stride * (delta_y >> libc.Int32FromInt32(1)))
   2965 			**(**uintptr)(__ccgo_up(io + 40)) += uintptr((*VP8Decoder)(unsafe.Pointer(dec)).Fcache_uv_stride * (delta_y >> libc.Int32FromInt32(1)))
   2966 			if (*VP8Io)(unsafe.Pointer(io)).Fa != libc.UintptrFromInt32(0) {
   2967 				**(**uintptr)(__ccgo_up(io + 152)) += uintptr((*VP8Io)(unsafe.Pointer(io)).Fwidth * delta_y)
   2968 			}
   2969 		}
   2970 		if y_start < y_end {
   2971 			**(**uintptr)(__ccgo_up(io + 24)) += uintptr((*VP8Io)(unsafe.Pointer(io)).Fcrop_left)
   2972 			**(**uintptr)(__ccgo_up(io + 32)) += uintptr((*VP8Io)(unsafe.Pointer(io)).Fcrop_left >> int32(1))
   2973 			**(**uintptr)(__ccgo_up(io + 40)) += uintptr((*VP8Io)(unsafe.Pointer(io)).Fcrop_left >> int32(1))
   2974 			if (*VP8Io)(unsafe.Pointer(io)).Fa != libc.UintptrFromInt32(0) {
   2975 				**(**uintptr)(__ccgo_up(io + 152)) += uintptr((*VP8Io)(unsafe.Pointer(io)).Fcrop_left)
   2976 			}
   2977 			(*VP8Io)(unsafe.Pointer(io)).Fmb_y = y_start - (*VP8Io)(unsafe.Pointer(io)).Fcrop_top
   2978 			(*VP8Io)(unsafe.Pointer(io)).Fmb_w = (*VP8Io)(unsafe.Pointer(io)).Fcrop_right - (*VP8Io)(unsafe.Pointer(io)).Fcrop_left
   2979 			(*VP8Io)(unsafe.Pointer(io)).Fmb_h = y_end - y_start
   2980 			ok = (*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*VP8Io)(unsafe.Pointer(io)).Fput})))(tls, io)
   2981 		}
   2982 	}
   2983 	// rotate top samples if needed
   2984 	if cache_id+int32(1) == (*VP8Decoder)(unsafe.Pointer(dec)).Fnum_caches {
   2985 		if !(is_last_row != 0) {
   2986 			libc.Xmemcpy(tls, (*VP8Decoder)(unsafe.Pointer(dec)).Fcache_y-uintptr(ysize), ydst+uintptr(int32(16)*(*VP8Decoder)(unsafe.Pointer(dec)).Fcache_y_stride), uint64(ysize))
   2987 			libc.Xmemcpy(tls, (*VP8Decoder)(unsafe.Pointer(dec)).Fcache_u-uintptr(uvsize), udst+uintptr(int32(8)*(*VP8Decoder)(unsafe.Pointer(dec)).Fcache_uv_stride), uint64(uvsize))
   2988 			libc.Xmemcpy(tls, (*VP8Decoder)(unsafe.Pointer(dec)).Fcache_v-uintptr(uvsize), vdst+uintptr(int32(8)*(*VP8Decoder)(unsafe.Pointer(dec)).Fcache_uv_stride), uint64(uvsize))
   2989 		}
   2990 	}
   2991 	return ok
   2992 }
   2993 
   2994 //------------------------------------------------------------------------------
   2995 
   2996 func VP8ProcessRow(tls *libc.TLS, dec uintptr, io uintptr) (r int32) {
   2997 	var ctx, tmp, tmp1, worker, v2 uintptr
   2998 	var filter_row, ok, v1 int32
   2999 	_, _, _, _, _, _, _, _ = ctx, filter_row, ok, tmp, tmp1, worker, v1, v2
   3000 	ok = int32(1)
   3001 	ctx = dec + 216
   3002 	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)
   3003 	if (*VP8Decoder)(unsafe.Pointer(dec)).Fmt_method == 0 {
   3004 		// ctx->id and ctx->f_info are already set
   3005 		(*VP8ThreadContext)(unsafe.Pointer(ctx)).Fmb_y = (*VP8Decoder)(unsafe.Pointer(dec)).Fmb_y
   3006 		(*VP8ThreadContext)(unsafe.Pointer(ctx)).Ffilter_row = filter_row
   3007 		ReconstructRow(tls, dec, ctx)
   3008 		ok = FinishRow(tls, dec, io)
   3009 	} else {
   3010 		worker = dec + 152
   3011 		// Finish previous job *before* updating context
   3012 		ok = ok & (*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*WebPWorkerInterface)(unsafe.Pointer(WebPGetWorkerInterface(tls))).FSync})))(tls, worker)
   3013 		if ok != 0 { // spawn a new deblocking/output job
   3014 			(*VP8ThreadContext)(unsafe.Pointer(ctx)).Fio = **(**VP8Io)(__ccgo_up(io))
   3015 			(*VP8ThreadContext)(unsafe.Pointer(ctx)).Fid = (*VP8Decoder)(unsafe.Pointer(dec)).Fcache_id
   3016 			(*VP8ThreadContext)(unsafe.Pointer(ctx)).Fmb_y = (*VP8Decoder)(unsafe.Pointer(dec)).Fmb_y
   3017 			(*VP8ThreadContext)(unsafe.Pointer(ctx)).Ffilter_row = filter_row
   3018 			if (*VP8Decoder)(unsafe.Pointer(dec)).Fmt_method == int32(2) { // swap macroblock data
   3019 				tmp = (*VP8ThreadContext)(unsafe.Pointer(ctx)).Fmb_data
   3020 				(*VP8ThreadContext)(unsafe.Pointer(ctx)).Fmb_data = (*VP8Decoder)(unsafe.Pointer(dec)).Fmb_data
   3021 				(*VP8Decoder)(unsafe.Pointer(dec)).Fmb_data = tmp
   3022 			} else {
   3023 				// perform reconstruction directly in main thread
   3024 				ReconstructRow(tls, dec, ctx)
   3025 			}
   3026 			if filter_row != 0 { // swap filter info
   3027 				tmp1 = (*VP8ThreadContext)(unsafe.Pointer(ctx)).Ff_info
   3028 				(*VP8ThreadContext)(unsafe.Pointer(ctx)).Ff_info = (*VP8Decoder)(unsafe.Pointer(dec)).Ff_info
   3029 				(*VP8Decoder)(unsafe.Pointer(dec)).Ff_info = tmp1
   3030 			}
   3031 			// (reconstruct)+filter in parallel
   3032 			(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(&struct{ uintptr }{(*WebPWorkerInterface)(unsafe.Pointer(WebPGetWorkerInterface(tls))).FLaunch})))(tls, worker)
   3033 			v2 = dec + 204
   3034 			*(*int32)(unsafe.Pointer(v2)) = *(*int32)(unsafe.Pointer(v2)) + 1
   3035 			v1 = *(*int32)(unsafe.Pointer(v2))
   3036 			if v1 == (*VP8Decoder)(unsafe.Pointer(dec)).Fnum_caches {
   3037 				(*VP8Decoder)(unsafe.Pointer(dec)).Fcache_id = 0
   3038 			}
   3039 		}
   3040 	}
   3041 	return ok
   3042 }
   3043 
   3044 //------------------------------------------------------------------------------
   3045 // Finish setting up the decoding parameter once user's setup() is called.
   3046 
   3047 func VP8EnterCritical(tls *libc.TLS, dec uintptr, io uintptr) (r VP8StatusCode1) {
   3048 	var extra_pixels int32
   3049 	_ = extra_pixels
   3050 	// Call setup() first. This may trigger additional decoding features on 'io'.
   3051 	// Note: Afterward, we must call teardown() no matter what.
   3052 	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) {
   3053 		VP8SetError(tls, dec, int32(VP8_STATUS_USER_ABORT), __ccgo_ts+66)
   3054 		return (*VP8Decoder)(unsafe.Pointer(dec)).Fstatus
   3055 	}
   3056 	// Disable filtering per user request
   3057 	if (*VP8Io)(unsafe.Pointer(io)).Fbypass_filtering != 0 {
   3058 		(*VP8Decoder)(unsafe.Pointer(dec)).Ffilter_type = 0
   3059 	}
   3060 	// Define the area where we can skip in-loop filtering, in case of cropping.
   3061 	//
   3062 	// 'Simple' filter reads two luma samples outside of the macroblock
   3063 	// and filters one. It doesn't filter the chroma samples. Hence, we can
   3064 	// avoid doing the in-loop filtering before crop_top/crop_left position.
   3065 	// For the 'Complex' filter, 3 samples are read and up to 3 are filtered.
   3066 	// Means: there's a dependency chain that goes all the way up to the
   3067 	// top-left corner of the picture (MB #0). We must filter all the previous
   3068 	// macroblocks.
   3069 	extra_pixels = int32(kFilterExtraRows[(*VP8Decoder)(unsafe.Pointer(dec)).Ffilter_type])
   3070 	if (*VP8Decoder)(unsafe.Pointer(dec)).Ffilter_type == int32(2) {
   3071 		// For complex filter, we need to preserve the dependency chain.
   3072 		(*VP8Decoder)(unsafe.Pointer(dec)).Ftl_mb_x = 0
   3073 		(*VP8Decoder)(unsafe.Pointer(dec)).Ftl_mb_y = 0
   3074 	} else {
   3075 		// For simple filter, we can filter only the cropped region.
   3076 		// We include 'extra_pixels' on the other side of the boundary, since
   3077 		// vertical or horizontal filtering of the previous macroblock can
   3078 		// modify some abutting pixels.
   3079 		(*VP8Decoder)(unsafe.Pointer(dec)).Ftl_mb_x = ((*VP8Io)(unsafe.Pointer(io)).Fcrop_left - extra_pixels) >> int32(4)
   3080 		(*VP8Decoder)(unsafe.Pointer(dec)).Ftl_mb_y = ((*VP8Io)(unsafe.Pointer(io)).Fcrop_top - extra_pixels) >> int32(4)
   3081 		if (*VP8Decoder)(unsafe.Pointer(dec)).Ftl_mb_x < 0 {
   3082 			(*VP8Decoder)(unsafe.Pointer(dec)).Ftl_mb_x = 0
   3083 		}
   3084 		if (*VP8Decoder)(unsafe.Pointer(dec)).Ftl_mb_y < 0 {
   3085 			(*VP8Decoder)(unsafe.Pointer(dec)).Ftl_mb_y = 0
   3086 		}
   3087 	}
   3088 	// We need some 'extra' pixels on the right/bottom.
   3089 	(*VP8Decoder)(unsafe.Pointer(dec)).Fbr_mb_y = ((*VP8Io)(unsafe.Pointer(io)).Fcrop_bottom + int32(15) + extra_pixels) >> int32(4)
   3090 	(*VP8Decoder)(unsafe.Pointer(dec)).Fbr_mb_x = ((*VP8Io)(unsafe.Pointer(io)).Fcrop_right + int32(15) + extra_pixels) >> int32(4)
   3091 	if (*VP8Decoder)(unsafe.Pointer(dec)).Fbr_mb_x > (*VP8Decoder)(unsafe.Pointer(dec)).Fmb_w {
   3092 		(*VP8Decoder)(unsafe.Pointer(dec)).Fbr_mb_x = (*VP8Decoder)(unsafe.Pointer(dec)).Fmb_w
   3093 	}
   3094 	if (*VP8Decoder)(unsafe.Pointer(dec)).Fbr_mb_y > (*VP8Decoder)(unsafe.Pointer(dec)).Fmb_h {
   3095 		(*VP8Decoder)(unsafe.Pointer(dec)).Fbr_mb_y = (*VP8Decoder)(unsafe.Pointer(dec)).Fmb_h
   3096 	}
   3097 	PrecomputeFilterStrengths(tls, dec)
   3098 	return int32(VP8_STATUS_OK)
   3099 }
   3100 
   3101 func VP8ExitCritical(tls *libc.TLS, dec uintptr, io uintptr) (r int32) {
   3102 	var ok int32
   3103 	_ = ok
   3104 	ok = int32(1)
   3105 	if (*VP8Decoder)(unsafe.Pointer(dec)).Fmt_method > 0 {
   3106 		ok = (*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*WebPWorkerInterface)(unsafe.Pointer(WebPGetWorkerInterface(tls))).FSync})))(tls, dec+152)
   3107 	}
   3108 	if (*VP8Io)(unsafe.Pointer(io)).Fteardown != libc.UintptrFromInt32(0) {
   3109 		(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(&struct{ uintptr }{(*VP8Io)(unsafe.Pointer(io)).Fteardown})))(tls, io)
   3110 	}
   3111 	return ok
   3112 }
   3113 
   3114 //------------------------------------------------------------------------------
   3115 // For multi-threaded decoding we need to use 3 rows of 16 pixels as delay line.
   3116 //
   3117 // Reason is: the deblocking filter cannot deblock the bottom horizontal edges
   3118 // immediately, and needs to wait for first few rows of the next macroblock to
   3119 // be decoded. Hence, deblocking is lagging behind by 4 or 8 pixels (depending
   3120 // on strength).
   3121 // With two threads, the vertical positions of the rows being decoded are:
   3122 // Decode:  [ 0..15][16..31][32..47][48..63][64..79][...
   3123 // Deblock:         [ 0..11][12..27][28..43][44..59][...
   3124 // If we use two threads and two caches of 16 pixels, the sequence would be:
   3125 // Decode:  [ 0..15][16..31][ 0..15!!][16..31][ 0..15][...
   3126 // Deblock:         [ 0..11][12..27!!][-4..11][12..27][...
   3127 // The problem occurs during row [12..15!!] that both the decoding and
   3128 // deblocking threads are writing simultaneously.
   3129 // With 3 cache lines, one get a safe write pattern:
   3130 // Decode:  [ 0..15][16..31][32..47][ 0..15][16..31][32..47][0..
   3131 // Deblock:         [ 0..11][12..27][28..43][-4..11][12..27][28...
   3132 // Note that multi-threaded output _without_ deblocking can make use of two
   3133 // cache lines of 16 pixels only, since there's no lagging behind. The decoding
   3134 // and output process have non-concurrent writing:
   3135 // Decode:  [ 0..15][16..31][ 0..15][16..31][...
   3136 // io->put:         [ 0..15][16..31][ 0..15][...
   3137 
   3138 // C documentation
   3139 //
   3140 //	// Initialize multi/single-thread worker
   3141 func InitThreadContext(tls *libc.TLS, dec uintptr) (r int32) {
   3142 	var worker uintptr
   3143 	var v1 int32
   3144 	_, _ = worker, v1
   3145 	(*VP8Decoder)(unsafe.Pointer(dec)).Fcache_id = 0
   3146 	if (*VP8Decoder)(unsafe.Pointer(dec)).Fmt_method > 0 {
   3147 		worker = dec + 152
   3148 		if !((*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*WebPWorkerInterface)(unsafe.Pointer(WebPGetWorkerInterface(tls))).FReset})))(tls, worker) != 0) {
   3149 			return VP8SetError(tls, dec, int32(VP8_STATUS_OUT_OF_MEMORY), __ccgo_ts+85)
   3150 		}
   3151 		(*WebPWorker)(unsafe.Pointer(worker)).Fdata1 = dec
   3152 		(*WebPWorker)(unsafe.Pointer(worker)).Fdata2 = dec + 216 + 32
   3153 		(*WebPWorker)(unsafe.Pointer(worker)).Fhook = __ccgo_fp(FinishRow)
   3154 		if (*VP8Decoder)(unsafe.Pointer(dec)).Ffilter_type > 0 {
   3155 			v1 = int32(3)
   3156 		} else {
   3157 			v1 = libc.Int32FromInt32(3) - libc.Int32FromInt32(1)
   3158 		}
   3159 		(*VP8Decoder)(unsafe.Pointer(dec)).Fnum_caches = v1
   3160 	} else {
   3161 		(*VP8Decoder)(unsafe.Pointer(dec)).Fnum_caches = int32(1)
   3162 	}
   3163 	return int32(1)
   3164 }
   3165 
   3166 func VP8GetThreadMethod(tls *libc.TLS, options uintptr, headers uintptr, width int32, height int32) (r int32) {
   3167 	if options == libc.UintptrFromInt32(0) || (*WebPDecoderOptions)(unsafe.Pointer(options)).Fuse_threads == 0 {
   3168 		return 0
   3169 	}
   3170 	_ = headers
   3171 	_ = width
   3172 	_ = height
   3173 	return 0
   3174 }
   3175 
   3176 //------------------------------------------------------------------------------
   3177 // Memory setup
   3178 
   3179 func AllocateMemory(tls *libc.TLS, dec uintptr) (r int32) {
   3180 	var alpha_size, needed, v5 uint64_t
   3181 	var cache_height, cache_size, f_info_size, intra_pred_mode_size, mb_data_size, mb_info_size, top_size, yuv_size size_t
   3182 	var extra_rows, extra_uv, extra_y, mb_w, num_caches, v2, v3, v6 int32
   3183 	var mem, v8 uintptr
   3184 	var v1, v4 uint64
   3185 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
   3186 	num_caches = (*VP8Decoder)(unsafe.Pointer(dec)).Fnum_caches
   3187 	mb_w = (*VP8Decoder)(unsafe.Pointer(dec)).Fmb_w
   3188 	// Note: we use 'size_t' when there's no overflow risk, uint64_t otherwise.
   3189 	intra_pred_mode_size = uint64(int32(4)*mb_w) * uint64(1)
   3190 	top_size = uint64(32) * uint64(mb_w)
   3191 	mb_info_size = uint64(mb_w+libc.Int32FromInt32(1)) * uint64(2)
   3192 	if (*VP8Decoder)(unsafe.Pointer(dec)).Ffilter_type > 0 {
   3193 		if (*VP8Decoder)(unsafe.Pointer(dec)).Fmt_method > 0 {
   3194 			v2 = int32(2)
   3195 		} else {
   3196 			v2 = int32(1)
   3197 		}
   3198 		v1 = uint64(mb_w*v2) * uint64(4)
   3199 	} else {
   3200 		v1 = uint64(0)
   3201 	}
   3202 	f_info_size = v1
   3203 	yuv_size = uint64(libc.Int32FromInt32(BPS)*libc.Int32FromInt32(17)+libc.Int32FromInt32(BPS)*libc.Int32FromInt32(9)) * libc.Uint64FromInt64(1)
   3204 	if (*VP8Decoder)(unsafe.Pointer(dec)).Fmt_method == int32(2) {
   3205 		v3 = int32(2)
   3206 	} else {
   3207 		v3 = int32(1)
   3208 	}
   3209 	mb_data_size = uint64(v3*mb_w) * uint64(800)
   3210 	cache_height = uint64((int32(16)*num_caches + int32(kFilterExtraRows[(*VP8Decoder)(unsafe.Pointer(dec)).Ffilter_type])) * int32(3) / int32(2))
   3211 	cache_size = top_size * cache_height
   3212 	if (*VP8Decoder)(unsafe.Pointer(dec)).Falpha_data != libc.UintptrFromInt32(0) {
   3213 		v4 = uint64((*VP8Decoder)(unsafe.Pointer(dec)).Fpic_hdr.Fwidth) * uint64((*VP8Decoder)(unsafe.Pointer(dec)).Fpic_hdr.Fheight)
   3214 	} else {
   3215 		v4 = 0
   3216 	}
   3217 	// alpha_size is the only one that scales as width x height.
   3218 	alpha_size = v4
   3219 	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)
   3220 	v5 = needed
   3221 	v6 = libc.BoolInt32(v5 == v5)
   3222 	goto _7
   3223 _7:
   3224 	if !(v6 != 0) {
   3225 		return 0
   3226 	} // check for overflow
   3227 	if needed > (*VP8Decoder)(unsafe.Pointer(dec)).Fmem_size {
   3228 		WebPSafeFree(tls, (*VP8Decoder)(unsafe.Pointer(dec)).Fmem)
   3229 		(*VP8Decoder)(unsafe.Pointer(dec)).Fmem_size = uint64(0)
   3230 		(*VP8Decoder)(unsafe.Pointer(dec)).Fmem = WebPSafeMalloc(tls, needed, uint64(1))
   3231 		if (*VP8Decoder)(unsafe.Pointer(dec)).Fmem == libc.UintptrFromInt32(0) {
   3232 			return VP8SetError(tls, dec, int32(VP8_STATUS_OUT_OF_MEMORY), __ccgo_ts+115)
   3233 		}
   3234 		// down-cast is ok, thanks to WebPSafeMalloc() above.
   3235 		(*VP8Decoder)(unsafe.Pointer(dec)).Fmem_size = needed
   3236 	}
   3237 	mem = (*VP8Decoder)(unsafe.Pointer(dec)).Fmem
   3238 	(*VP8Decoder)(unsafe.Pointer(dec)).Fintra_t = mem
   3239 	mem = mem + uintptr(intra_pred_mode_size)
   3240 	(*VP8Decoder)(unsafe.Pointer(dec)).Fyuv_t = mem
   3241 	mem = mem + uintptr(top_size)
   3242 	(*VP8Decoder)(unsafe.Pointer(dec)).Fmb_info = mem + uintptr(1)*2
   3243 	mem = mem + uintptr(mb_info_size)
   3244 	if f_info_size != 0 {
   3245 		v8 = mem
   3246 	} else {
   3247 		v8 = libc.UintptrFromInt32(0)
   3248 	}
   3249 	(*VP8Decoder)(unsafe.Pointer(dec)).Ff_info = v8
   3250 	mem = mem + uintptr(f_info_size)
   3251 	(*VP8Decoder)(unsafe.Pointer(dec)).Fthread_ctx.Fid = 0
   3252 	(*VP8Decoder)(unsafe.Pointer(dec)).Fthread_ctx.Ff_info = (*VP8Decoder)(unsafe.Pointer(dec)).Ff_info
   3253 	if (*VP8Decoder)(unsafe.Pointer(dec)).Ffilter_type > 0 && (*VP8Decoder)(unsafe.Pointer(dec)).Fmt_method > 0 {
   3254 		// secondary cache line. The deblocking process need to make use of the
   3255 		// filtering strength from previous macroblock row, while the new ones
   3256 		// are being decoded in parallel. We'll just swap the pointers.
   3257 		(*VP8Decoder)(unsafe.Pointer(dec)).Fthread_ctx.Ff_info += uintptr(mb_w) * 4
   3258 	}
   3259 	mem = uintptr((uint64(mem) + libc.Uint64FromInt32(WEBP_ALIGN_CST)) & ^libc.Uint64FromInt32(WEBP_ALIGN_CST))
   3260 	(*VP8Decoder)(unsafe.Pointer(dec)).Fyuv_b = mem
   3261 	mem = mem + uintptr(yuv_size)
   3262 	(*VP8Decoder)(unsafe.Pointer(dec)).Fmb_data = mem
   3263 	(*VP8Decoder)(unsafe.Pointer(dec)).Fthread_ctx.Fmb_data = mem
   3264 	if (*VP8Decoder)(unsafe.Pointer(dec)).Fmt_method == int32(2) {
   3265 		(*VP8Decoder)(unsafe.Pointer(dec)).Fthread_ctx.Fmb_data += uintptr(mb_w) * 800
   3266 	}
   3267 	mem = mem + uintptr(mb_data_size)
   3268 	(*VP8Decoder)(unsafe.Pointer(dec)).Fcache_y_stride = int32(16) * mb_w
   3269 	(*VP8Decoder)(unsafe.Pointer(dec)).Fcache_uv_stride = int32(8) * mb_w
   3270 	extra_rows = int32(kFilterExtraRows[(*VP8Decoder)(unsafe.Pointer(dec)).Ffilter_type])
   3271 	extra_y = extra_rows * (*VP8Decoder)(unsafe.Pointer(dec)).Fcache_y_stride
   3272 	extra_uv = extra_rows / int32(2) * (*VP8Decoder)(unsafe.Pointer(dec)).Fcache_uv_stride
   3273 	(*VP8Decoder)(unsafe.Pointer(dec)).Fcache_y = mem + uintptr(extra_y)
   3274 	(*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)
   3275 	(*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)
   3276 	(*VP8Decoder)(unsafe.Pointer(dec)).Fcache_id = 0
   3277 	mem = mem + uintptr(cache_size)
   3278 	// alpha plane
   3279 	if alpha_size != 0 {
   3280 		v8 = mem
   3281 	} else {
   3282 		v8 = libc.UintptrFromInt32(0)
   3283 	}
   3284 	(*VP8Decoder)(unsafe.Pointer(dec)).Falpha_plane = v8
   3285 	mem = mem + uintptr(alpha_size)
   3286 	// note: left/top-info is initialized once for all.
   3287 	libc.Xmemset(tls, (*VP8Decoder)(unsafe.Pointer(dec)).Fmb_info-uintptr(1)*2, 0, mb_info_size)
   3288 	VP8InitScanline(tls, dec) // initialize left too.
   3289 	// initialize top
   3290 	libc.Xmemset(tls, (*VP8Decoder)(unsafe.Pointer(dec)).Fintra_t, int32(B_DC_PRED), intra_pred_mode_size)
   3291 	return int32(1)
   3292 }
   3293 
   3294 func InitIo(tls *libc.TLS, dec uintptr, io uintptr) {
   3295 	// prepare 'io'
   3296 	(*VP8Io)(unsafe.Pointer(io)).Fmb_y = 0
   3297 	(*VP8Io)(unsafe.Pointer(io)).Fy = (*VP8Decoder)(unsafe.Pointer(dec)).Fcache_y
   3298 	(*VP8Io)(unsafe.Pointer(io)).Fu = (*VP8Decoder)(unsafe.Pointer(dec)).Fcache_u
   3299 	(*VP8Io)(unsafe.Pointer(io)).Fv = (*VP8Decoder)(unsafe.Pointer(dec)).Fcache_v
   3300 	(*VP8Io)(unsafe.Pointer(io)).Fy_stride = (*VP8Decoder)(unsafe.Pointer(dec)).Fcache_y_stride
   3301 	(*VP8Io)(unsafe.Pointer(io)).Fuv_stride = (*VP8Decoder)(unsafe.Pointer(dec)).Fcache_uv_stride
   3302 	(*VP8Io)(unsafe.Pointer(io)).Fa = libc.UintptrFromInt32(0)
   3303 }
   3304 
   3305 func VP8InitFrame(tls *libc.TLS, dec uintptr, io uintptr) (r int32) {
   3306 	if !(InitThreadContext(tls, dec) != 0) {
   3307 		return 0
   3308 	} // call first. Sets dec->num_caches.
   3309 	if !(AllocateMemory(tls, dec) != 0) {
   3310 		return 0
   3311 	}
   3312 	InitIo(tls, dec, io)
   3313 	VP8DspInit(tls) // Init critical function pointers and look-up tables.
   3314 	return int32(1)
   3315 }
   3316 
   3317 const CHUNK_SIZE = 4096
   3318 const MAX_MB_SIZE = 4096
   3319 
   3320 type WebPIDecoder = struct {
   3321 	Fstate        DecState
   3322 	Fparams       WebPDecParams
   3323 	Fis_lossless  int32
   3324 	Fdec          uintptr
   3325 	Fio           VP8Io
   3326 	Fmem          MemBuffer
   3327 	Foutput       WebPDecBuffer
   3328 	Ffinal_output uintptr
   3329 	Fchunk_size   size_t
   3330 	Flast_mb_y    int32
   3331 }
   3332 
   3333 const STATE_WEBP_HEADER = 0
   3334 const // All the data before that of the VP8/VP8L chunk.
   3335 STATE_VP8_HEADER = 1
   3336 const // The VP8 Frame header (within the VP8 chunk).
   3337 STATE_VP8_PARTS0 = 2
   3338 const STATE_VP8_DATA = 3
   3339 const STATE_VP8L_HEADER = 4
   3340 const STATE_VP8L_DATA = 5
   3341 const STATE_DONE = 6
   3342 const STATE_ERROR = 7
   3343 
   3344 var kHashMul3 = uint32(0x1e35a7bd)
   3345 
   3346 //------------------------------------------------------------------------------
   3347 
   3348 // Copyright 2010 Google Inc. All Rights Reserved.
   3349 //
   3350 // Use of this source code is governed by a BSD-style license
   3351 // that can be found in the COPYING file in the root of the source
   3352 // tree. An additional intellectual property rights grant can be found
   3353 // in the file PATENTS. All contributing project authors may
   3354 // be found in the AUTHORS file in the root of the source tree.
   3355 // -----------------------------------------------------------------------------
   3356 //
   3357 //  Main decoding functions for WebP images.
   3358 //
   3359 // Author: Skal (pascal.massimino@gmail.com)
   3360 
   3361 // Copyright 2012 Google Inc. All Rights Reserved.
   3362 //
   3363 // Use of this source code is governed by a BSD-style license
   3364 // that can be found in the COPYING file in the root of the source
   3365 // tree. An additional intellectual property rights grant can be found
   3366 // in the file PATENTS. All contributing project authors may
   3367 // be found in the AUTHORS file in the root of the source tree.
   3368 // -----------------------------------------------------------------------------
   3369 //
   3370 //  Internal header for constants related to WebP file format.
   3371 //
   3372 // Author: Urvang (urvang@google.com)
   3373 
   3374 // Copyright 2010 Google Inc. All Rights Reserved.
   3375 //
   3376 // Use of this source code is governed by a BSD-style license
   3377 // that can be found in the COPYING file in the root of the source
   3378 // tree. An additional intellectual property rights grant can be found
   3379 // in the file PATENTS. All contributing project authors may
   3380 // be found in the AUTHORS file in the root of the source tree.
   3381 // -----------------------------------------------------------------------------
   3382 //
   3383 //  Common types + memory wrappers
   3384 //
   3385 // Author: Skal (pascal.massimino@gmail.com)
   3386 
   3387 // In append mode, buffer allocations increase as multiples of this value.
   3388 // Needs to be a power of 2.
   3389 
   3390 //------------------------------------------------------------------------------
   3391 // Data structures for memory and states
   3392 
   3393 // C documentation
   3394 //
   3395 //	// Decoding states. State normally flows as:
   3396 //	// WEBP_HEADER->VP8_HEADER->VP8_PARTS0->VP8_DATA->DONE for a lossy image, and
   3397 //	// WEBP_HEADER->VP8L_HEADER->VP8L_DATA->DONE for a lossless image.
   3398 //	// If there is any error the decoder goes into state ERROR.
   3399 type DecState = int32
   3400 
   3401 // C documentation
   3402 //
   3403 //	// Operating state for the MemBuffer
   3404 type MemBufferMode = int32
   3405 
   3406 const MEM_MODE_NONE = 0
   3407 const MEM_MODE_APPEND = 1
   3408 const MEM_MODE_MAP = 2
   3409 
   3410 // C documentation
   3411 //
   3412 //	// storage for partition #0 and partial data (in a rolling fashion)
   3413 type MemBuffer = struct {
   3414 	Fmode       MemBufferMode
   3415 	Fstart      size_t
   3416 	Fend        size_t
   3417 	Fbuf_size   size_t
   3418 	Fbuf        uintptr
   3419 	Fpart0_size size_t
   3420 	Fpart0_buf  uintptr
   3421 }
   3422 
   3423 // C documentation
   3424 //
   3425 //	// MB context to restore in case VP8DecodeMB() fails
   3426 type MBContext = struct {
   3427 	Fleft     VP8MB
   3428 	Finfo     VP8MB
   3429 	Ftoken_br VP8BitReader
   3430 }
   3431 
   3432 //------------------------------------------------------------------------------
   3433 // MemBuffer: incoming data handling
   3434 
   3435 func MemDataSize(tls *libc.TLS, mem uintptr) (r size_t) {
   3436 	return (*MemBuffer)(unsafe.Pointer(mem)).Fend - (*MemBuffer)(unsafe.Pointer(mem)).Fstart
   3437 }
   3438 
   3439 // C documentation
   3440 //
   3441 //	// Check if we need to preserve the compressed alpha data, as it may not have
   3442 //	// been decoded yet.
   3443 func NeedCompressedAlpha(tls *libc.TLS, idec uintptr) (r int32) {
   3444 	var dec uintptr
   3445 	_ = dec
   3446 	if (*WebPIDecoder)(unsafe.Pointer(idec)).Fstate == int32(STATE_WEBP_HEADER) {
   3447 		// We haven't parsed the headers yet, so we don't know whether the image is
   3448 		// lossy or lossless. This also means that we haven't parsed the ALPH chunk.
   3449 		return 0
   3450 	}
   3451 	if (*WebPIDecoder)(unsafe.Pointer(idec)).Fis_lossless != 0 {
   3452 		return 0 // ALPH chunk is not present for lossless images.
   3453 	} else {
   3454 		dec = (*WebPIDecoder)(unsafe.Pointer(idec)).Fdec
   3455 		// Must be true as idec->state != STATE_WEBP_HEADER.
   3456 		return libc.BoolInt32((*VP8Decoder)(unsafe.Pointer(dec)).Falpha_data != libc.UintptrFromInt32(0) && !((*VP8Decoder)(unsafe.Pointer(dec)).Fis_alpha_decoded != 0))
   3457 	}
   3458 	return r
   3459 }
   3460 
   3461 func DoRemap(tls *libc.TLS, idec uintptr, offset ptrdiff_t) {
   3462 	var alph_dec, alph_vp8l_dec, dec, dec1, last_start, mem, new_base uintptr
   3463 	var last_part, p uint32_t
   3464 	_, _, _, _, _, _, _, _, _ = alph_dec, alph_vp8l_dec, dec, dec1, last_part, last_start, mem, new_base, p
   3465 	mem = idec + 296
   3466 	new_base = (*MemBuffer)(unsafe.Pointer(mem)).Fbuf + uintptr((*MemBuffer)(unsafe.Pointer(mem)).Fstart)
   3467 	// note: for VP8, setting up idec->io is only really needed at the beginning
   3468 	// of the decoding, till partition #0 is complete.
   3469 	(*WebPIDecoder)(unsafe.Pointer(idec)).Fio.Fdata = new_base
   3470 	(*WebPIDecoder)(unsafe.Pointer(idec)).Fio.Fdata_size = MemDataSize(tls, mem)
   3471 	if (*WebPIDecoder)(unsafe.Pointer(idec)).Fdec != libc.UintptrFromInt32(0) {
   3472 		if !((*WebPIDecoder)(unsafe.Pointer(idec)).Fis_lossless != 0) {
   3473 			dec = (*WebPIDecoder)(unsafe.Pointer(idec)).Fdec
   3474 			last_part = (*VP8Decoder)(unsafe.Pointer(dec)).Fnum_parts_minus_one
   3475 			if offset != 0 {
   3476 				p = uint32(0)
   3477 				for {
   3478 					if !(p <= last_part) {
   3479 						break
   3480 					}
   3481 					VP8RemapBitReader(tls, dec+440+uintptr(p)*48, offset)
   3482 					goto _1
   3483 				_1:
   3484 					;
   3485 					p = p + 1
   3486 				}
   3487 				// Remap partition #0 data pointer to new offset, but only in MAP
   3488 				// mode (in APPEND mode, partition #0 is copied into a fixed memory).
   3489 				if (*MemBuffer)(unsafe.Pointer(mem)).Fmode == int32(MEM_MODE_MAP) {
   3490 					VP8RemapBitReader(tls, dec+16, offset)
   3491 				}
   3492 			}
   3493 			last_start = (**(**VP8BitReader)(__ccgo_up(dec + 440 + uintptr(last_part)*48))).Fbuf
   3494 			// 'last_start' will be NULL when 'idec->state' is < STATE_VP8_PARTS0
   3495 			// and through a portion of that state (when there isn't enough data to
   3496 			// parse the partitions). The bitreader is only used meaningfully when
   3497 			// there is enough data to begin parsing partition 0.
   3498 			if last_start != libc.UintptrFromInt32(0) {
   3499 				VP8BitReaderSetBuffer(tls, dec+440+uintptr(last_part)*48, last_start, uint64(int64((*MemBuffer)(unsafe.Pointer(mem)).Fbuf+uintptr((*MemBuffer)(unsafe.Pointer(mem)).Fend))-int64(last_start)))
   3500 			}
   3501 			if NeedCompressedAlpha(tls, idec) != 0 {
   3502 				alph_dec = (*VP8Decoder)(unsafe.Pointer(dec)).Falph_dec
   3503 				**(**uintptr)(__ccgo_up(dec + 2968)) += uintptr(offset)
   3504 				if alph_dec != libc.UintptrFromInt32(0) && (*ALPHDecoder)(unsafe.Pointer(alph_dec)).Fvp8l_dec != libc.UintptrFromInt32(0) {
   3505 					if (*ALPHDecoder)(unsafe.Pointer(alph_dec)).Fmethod == int32(ALPHA_LOSSLESS_COMPRESSION) {
   3506 						alph_vp8l_dec = (*ALPHDecoder)(unsafe.Pointer(alph_dec)).Fvp8l_dec
   3507 						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))
   3508 					} else { // alph_dec->method == ALPHA_NO_COMPRESSION
   3509 						// Nothing special to do in this case.
   3510 					}
   3511 				}
   3512 			}
   3513 		} else { // Resize lossless bitreader
   3514 			dec1 = (*WebPIDecoder)(unsafe.Pointer(idec)).Fdec
   3515 			VP8LBitReaderSetBuffer(tls, dec1+40, new_base, MemDataSize(tls, mem))
   3516 		}
   3517 	}
   3518 }
   3519 
   3520 // C documentation
   3521 //
   3522 //	// Appends data to the end of MemBuffer->buf. It expands the allocated memory
   3523 //	// size if required and also updates VP8BitReader's if new memory is allocated.
   3524 func AppendToMemBuffer(tls *libc.TLS, idec uintptr, data uintptr, data_size size_t) (r int32) {
   3525 	var current_size, new_mem_start size_t
   3526 	var dec, mem, new_buf, old_base, old_start, v1, v2 uintptr
   3527 	var extra_size, new_size uint64_t
   3528 	var need_compressed_alpha int32
   3529 	_, _, _, _, _, _, _, _, _, _, _, _ = current_size, dec, extra_size, mem, need_compressed_alpha, new_buf, new_mem_start, new_size, old_base, old_start, v1, v2
   3530 	dec = (*WebPIDecoder)(unsafe.Pointer(idec)).Fdec
   3531 	mem = idec + 296
   3532 	need_compressed_alpha = NeedCompressedAlpha(tls, idec)
   3533 	if (*MemBuffer)(unsafe.Pointer(mem)).Fbuf == libc.UintptrFromInt32(0) {
   3534 		v1 = libc.UintptrFromInt32(0)
   3535 	} else {
   3536 		v1 = (*MemBuffer)(unsafe.Pointer(mem)).Fbuf + uintptr((*MemBuffer)(unsafe.Pointer(mem)).Fstart)
   3537 	}
   3538 	old_start = v1
   3539 	if need_compressed_alpha != 0 {
   3540 		v2 = (*VP8Decoder)(unsafe.Pointer(dec)).Falpha_data
   3541 	} else {
   3542 		v2 = old_start
   3543 	}
   3544 	old_base = v2
   3545 	if data_size > uint64(^libc.Uint32FromUint32(0)-libc.Uint32FromInt32(CHUNK_HEADER_SIZE)-libc.Uint32FromInt32(1)) {
   3546 		// security safeguard: trying to allocate more than what the format
   3547 		// allows for a chunk should be considered a smoke smell.
   3548 		return 0
   3549 	}
   3550 	if (*MemBuffer)(unsafe.Pointer(mem)).Fend+data_size > (*MemBuffer)(unsafe.Pointer(mem)).Fbuf_size { // Need some free memory
   3551 		new_mem_start = uint64(int64(old_start) - int64(old_base))
   3552 		current_size = MemDataSize(tls, mem) + new_mem_start
   3553 		new_size = current_size + data_size
   3554 		extra_size = (new_size + uint64(CHUNK_SIZE) - uint64(1)) & uint64(^(libc.Int32FromInt32(CHUNK_SIZE) - libc.Int32FromInt32(1)))
   3555 		new_buf = WebPSafeMalloc(tls, extra_size, uint64(1))
   3556 		if new_buf == libc.UintptrFromInt32(0) {
   3557 			return 0
   3558 		}
   3559 		if old_base != libc.UintptrFromInt32(0) {
   3560 			libc.Xmemcpy(tls, new_buf, old_base, current_size)
   3561 		}
   3562 		WebPSafeFree(tls, (*MemBuffer)(unsafe.Pointer(mem)).Fbuf)
   3563 		(*MemBuffer)(unsafe.Pointer(mem)).Fbuf = new_buf
   3564 		(*MemBuffer)(unsafe.Pointer(mem)).Fbuf_size = extra_size
   3565 		(*MemBuffer)(unsafe.Pointer(mem)).Fstart = new_mem_start
   3566 		(*MemBuffer)(unsafe.Pointer(mem)).Fend = current_size
   3567 	}
   3568 	libc.Xmemcpy(tls, (*MemBuffer)(unsafe.Pointer(mem)).Fbuf+uintptr((*MemBuffer)(unsafe.Pointer(mem)).Fend), data, data_size)
   3569 	**(**size_t)(__ccgo_up(mem + 16)) += data_size
   3570 	DoRemap(tls, idec, int64((*MemBuffer)(unsafe.Pointer(mem)).Fbuf+uintptr((*MemBuffer)(unsafe.Pointer(mem)).Fstart))-int64(old_start))
   3571 	return int32(1)
   3572 }
   3573 
   3574 func RemapMemBuffer(tls *libc.TLS, idec uintptr, data uintptr, data_size size_t) (r int32) {
   3575 	var mem, old_buf, old_start, v1 uintptr
   3576 	var v2 size_t
   3577 	_, _, _, _, _ = mem, old_buf, old_start, v1, v2
   3578 	mem = idec + 296
   3579 	old_buf = (*MemBuffer)(unsafe.Pointer(mem)).Fbuf
   3580 	if old_buf == libc.UintptrFromInt32(0) {
   3581 		v1 = libc.UintptrFromInt32(0)
   3582 	} else {
   3583 		v1 = old_buf + uintptr((*MemBuffer)(unsafe.Pointer(mem)).Fstart)
   3584 	}
   3585 	old_start = v1
   3586 	if data_size < (*MemBuffer)(unsafe.Pointer(mem)).Fbuf_size {
   3587 		return 0
   3588 	} // can't remap to a shorter buffer!
   3589 	(*MemBuffer)(unsafe.Pointer(mem)).Fbuf = data
   3590 	v2 = data_size
   3591 	(*MemBuffer)(unsafe.Pointer(mem)).Fbuf_size = v2
   3592 	(*MemBuffer)(unsafe.Pointer(mem)).Fend = v2
   3593 	DoRemap(tls, idec, int64((*MemBuffer)(unsafe.Pointer(mem)).Fbuf+uintptr((*MemBuffer)(unsafe.Pointer(mem)).Fstart))-int64(old_start))
   3594 	return int32(1)
   3595 }
   3596 
   3597 func InitMemBuffer(tls *libc.TLS, mem uintptr) {
   3598 	(*MemBuffer)(unsafe.Pointer(mem)).Fmode = int32(MEM_MODE_NONE)
   3599 	(*MemBuffer)(unsafe.Pointer(mem)).Fbuf = libc.UintptrFromInt32(0)
   3600 	(*MemBuffer)(unsafe.Pointer(mem)).Fbuf_size = uint64(0)
   3601 	(*MemBuffer)(unsafe.Pointer(mem)).Fpart0_buf = libc.UintptrFromInt32(0)
   3602 	(*MemBuffer)(unsafe.Pointer(mem)).Fpart0_size = uint64(0)
   3603 }
   3604 
   3605 func ClearMemBuffer(tls *libc.TLS, mem uintptr) {
   3606 	if (*MemBuffer)(unsafe.Pointer(mem)).Fmode == int32(MEM_MODE_APPEND) {
   3607 		WebPSafeFree(tls, (*MemBuffer)(unsafe.Pointer(mem)).Fbuf)
   3608 		WebPSafeFree(tls, (*MemBuffer)(unsafe.Pointer(mem)).Fpart0_buf)
   3609 	}
   3610 }
   3611 
   3612 func CheckMemBufferMode(tls *libc.TLS, mem uintptr, expected MemBufferMode) (r int32) {
   3613 	if (*MemBuffer)(unsafe.Pointer(mem)).Fmode == int32(MEM_MODE_NONE) {
   3614 		(*MemBuffer)(unsafe.Pointer(mem)).Fmode = expected // switch to the expected mode
   3615 	} else {
   3616 		if (*MemBuffer)(unsafe.Pointer(mem)).Fmode != expected {
   3617 			return 0 // we mixed the modes => error
   3618 		}
   3619 	}
   3620 	// mode is ok
   3621 	return int32(1)
   3622 }
   3623 
   3624 // C documentation
   3625 //
   3626 //	// To be called last.
   3627 func FinishDecoding(tls *libc.TLS, idec uintptr) (r VP8StatusCode1) {
   3628 	var options, output uintptr
   3629 	var status, status1 VP8StatusCode1
   3630 	_, _, _, _ = options, output, status, status1
   3631 	options = (*WebPIDecoder)(unsafe.Pointer(idec)).Fparams.Foptions
   3632 	output = (*WebPIDecoder)(unsafe.Pointer(idec)).Fparams.Foutput
   3633 	(*WebPIDecoder)(unsafe.Pointer(idec)).Fstate = int32(STATE_DONE)
   3634 	if options != libc.UintptrFromInt32(0) && (*WebPDecoderOptions)(unsafe.Pointer(options)).Fflip != 0 {
   3635 		status = WebPFlipBuffer(tls, output)
   3636 		if status != int32(VP8_STATUS_OK) {
   3637 			return status
   3638 		}
   3639 	}
   3640 	if (*WebPIDecoder)(unsafe.Pointer(idec)).Ffinal_output != libc.UintptrFromInt32(0) {
   3641 		status1 = WebPCopyDecBufferPixels(tls, output, (*WebPIDecoder)(unsafe.Pointer(idec)).Ffinal_output) // do the slow-copy
   3642 		WebPFreeDecBuffer(tls, idec+352)
   3643 		if status1 != int32(VP8_STATUS_OK) {
   3644 			return status1
   3645 		}
   3646 		**(**WebPDecBuffer)(__ccgo_up(output)) = **(**WebPDecBuffer)(__ccgo_up((*WebPIDecoder)(unsafe.Pointer(idec)).Ffinal_output))
   3647 		(*WebPIDecoder)(unsafe.Pointer(idec)).Ffinal_output = libc.UintptrFromInt32(0)
   3648 	}
   3649 	return int32(VP8_STATUS_OK)
   3650 }
   3651 
   3652 //------------------------------------------------------------------------------
   3653 // Macroblock-decoding contexts
   3654 
   3655 func SaveContext(tls *libc.TLS, dec uintptr, token_br uintptr, context uintptr) {
   3656 	(*MBContext)(unsafe.Pointer(context)).Fleft = **(**VP8MB)(__ccgo_up((*VP8Decoder)(unsafe.Pointer(dec)).Fmb_info + uintptr(-libc.Int32FromInt32(1))*2))
   3657 	(*MBContext)(unsafe.Pointer(context)).Finfo = **(**VP8MB)(__ccgo_up((*VP8Decoder)(unsafe.Pointer(dec)).Fmb_info + uintptr((*VP8Decoder)(unsafe.Pointer(dec)).Fmb_x)*2))
   3658 	(*MBContext)(unsafe.Pointer(context)).Ftoken_br = **(**VP8BitReader)(__ccgo_up(token_br))
   3659 }
   3660 
   3661 func RestoreContext(tls *libc.TLS, context uintptr, dec uintptr, token_br uintptr) {
   3662 	**(**VP8MB)(__ccgo_up((*VP8Decoder)(unsafe.Pointer(dec)).Fmb_info + uintptr(-libc.Int32FromInt32(1))*2)) = (*MBContext)(unsafe.Pointer(context)).Fleft
   3663 	**(**VP8MB)(__ccgo_up((*VP8Decoder)(unsafe.Pointer(dec)).Fmb_info + uintptr((*VP8Decoder)(unsafe.Pointer(dec)).Fmb_x)*2)) = (*MBContext)(unsafe.Pointer(context)).Finfo
   3664 	**(**VP8BitReader)(__ccgo_up(token_br)) = (*MBContext)(unsafe.Pointer(context)).Ftoken_br
   3665 }
   3666 
   3667 //------------------------------------------------------------------------------
   3668 
   3669 func IDecError(tls *libc.TLS, idec uintptr, error1 VP8StatusCode1) (r VP8StatusCode1) {
   3670 	if (*WebPIDecoder)(unsafe.Pointer(idec)).Fstate == int32(STATE_VP8_DATA) {
   3671 		// Synchronize the thread, clean-up and check for errors.
   3672 		VP8ExitCritical(tls, (*WebPIDecoder)(unsafe.Pointer(idec)).Fdec, idec+136)
   3673 	}
   3674 	(*WebPIDecoder)(unsafe.Pointer(idec)).Fstate = int32(STATE_ERROR)
   3675 	return error1
   3676 }
   3677 
   3678 func ChangeState(tls *libc.TLS, idec uintptr, new_state DecState, consumed_bytes size_t) {
   3679 	var mem uintptr
   3680 	_ = mem
   3681 	mem = idec + 296
   3682 	(*WebPIDecoder)(unsafe.Pointer(idec)).Fstate = new_state
   3683 	**(**size_t)(__ccgo_up(mem + 8)) += consumed_bytes
   3684 	(*WebPIDecoder)(unsafe.Pointer(idec)).Fio.Fdata = (*MemBuffer)(unsafe.Pointer(mem)).Fbuf + uintptr((*MemBuffer)(unsafe.Pointer(mem)).Fstart)
   3685 	(*WebPIDecoder)(unsafe.Pointer(idec)).Fio.Fdata_size = MemDataSize(tls, mem)
   3686 }
   3687 
   3688 // C documentation
   3689 //
   3690 //	// Headers
   3691 func DecodeWebPHeaders(tls *libc.TLS, idec uintptr) (r VP8StatusCode1) {
   3692 	bp := tls.Alloc(80)
   3693 	defer tls.Free(80)
   3694 	var curr_size size_t
   3695 	var data, dec, dec1, mem uintptr
   3696 	var status VP8StatusCode1
   3697 	var _ /* headers at bp+0 */ WebPHeaderStructure
   3698 	_, _, _, _, _, _ = curr_size, data, dec, dec1, mem, status
   3699 	mem = idec + 296
   3700 	data = (*MemBuffer)(unsafe.Pointer(mem)).Fbuf + uintptr((*MemBuffer)(unsafe.Pointer(mem)).Fstart)
   3701 	curr_size = MemDataSize(tls, mem)
   3702 	(**(**WebPHeaderStructure)(__ccgo_up(bp))).Fdata = data
   3703 	(**(**WebPHeaderStructure)(__ccgo_up(bp))).Fdata_size = curr_size
   3704 	(**(**WebPHeaderStructure)(__ccgo_up(bp))).Fhave_all_data = 0
   3705 	status = WebPParseHeaders(tls, bp)
   3706 	if status == int32(VP8_STATUS_NOT_ENOUGH_DATA) {
   3707 		return int32(VP8_STATUS_SUSPENDED) // We haven't found a VP8 chunk yet.
   3708 	} else {
   3709 		if status != int32(VP8_STATUS_OK) {
   3710 			return IDecError(tls, idec, status)
   3711 		}
   3712 	}
   3713 	(*WebPIDecoder)(unsafe.Pointer(idec)).Fchunk_size = (**(**WebPHeaderStructure)(__ccgo_up(bp))).Fcompressed_size
   3714 	(*WebPIDecoder)(unsafe.Pointer(idec)).Fis_lossless = (**(**WebPHeaderStructure)(__ccgo_up(bp))).Fis_lossless
   3715 	if !((*WebPIDecoder)(unsafe.Pointer(idec)).Fis_lossless != 0) {
   3716 		dec = VP8New(tls)
   3717 		if dec == libc.UintptrFromInt32(0) {
   3718 			return int32(VP8_STATUS_OUT_OF_MEMORY)
   3719 		}
   3720 		(*VP8Decoder)(unsafe.Pointer(dec)).Fincremental = int32(1)
   3721 		(*WebPIDecoder)(unsafe.Pointer(idec)).Fdec = dec
   3722 		(*VP8Decoder)(unsafe.Pointer(dec)).Falpha_data = (**(**WebPHeaderStructure)(__ccgo_up(bp))).Falpha_data
   3723 		(*VP8Decoder)(unsafe.Pointer(dec)).Falpha_data_size = (**(**WebPHeaderStructure)(__ccgo_up(bp))).Falpha_data_size
   3724 		ChangeState(tls, idec, int32(STATE_VP8_HEADER), (**(**WebPHeaderStructure)(__ccgo_up(bp))).Foffset)
   3725 	} else {
   3726 		dec1 = VP8LNew(tls)
   3727 		if dec1 == libc.UintptrFromInt32(0) {
   3728 			return int32(VP8_STATUS_OUT_OF_MEMORY)
   3729 		}
   3730 		(*WebPIDecoder)(unsafe.Pointer(idec)).Fdec = dec1
   3731 		ChangeState(tls, idec, int32(STATE_VP8L_HEADER), (**(**WebPHeaderStructure)(__ccgo_up(bp))).Foffset)
   3732 	}
   3733 	return int32(VP8_STATUS_OK)
   3734 }
   3735 
   3736 func DecodeVP8FrameHeader(tls *libc.TLS, idec uintptr) (r VP8StatusCode1) {
   3737 	bp := tls.Alloc(16)
   3738 	defer tls.Free(16)
   3739 	var bits uint32_t
   3740 	var curr_size size_t
   3741 	var data uintptr
   3742 	var _ /* height at bp+4 */ int32
   3743 	var _ /* width at bp+0 */ int32
   3744 	_, _, _ = bits, curr_size, data
   3745 	data = (*WebPIDecoder)(unsafe.Pointer(idec)).Fmem.Fbuf + uintptr((*WebPIDecoder)(unsafe.Pointer(idec)).Fmem.Fstart)
   3746 	curr_size = MemDataSize(tls, idec+296)
   3747 	if curr_size < uint64(VP8_FRAME_HEADER_SIZE) {
   3748 		// Not enough data bytes to extract VP8 Frame Header.
   3749 		return int32(VP8_STATUS_SUSPENDED)
   3750 	}
   3751 	if !(VP8GetInfo(tls, data, curr_size, (*WebPIDecoder)(unsafe.Pointer(idec)).Fchunk_size, bp, bp+4) != 0) {
   3752 		return IDecError(tls, idec, int32(VP8_STATUS_BITSTREAM_ERROR))
   3753 	}
   3754 	bits = uint32(int32(**(**uint8_t)(__ccgo_up(data))) | int32(**(**uint8_t)(__ccgo_up(data + 1)))<<int32(8) | int32(**(**uint8_t)(__ccgo_up(data + 2)))<<int32(16))
   3755 	(*WebPIDecoder)(unsafe.Pointer(idec)).Fmem.Fpart0_size = uint64(bits>>libc.Int32FromInt32(5) + uint32(VP8_FRAME_HEADER_SIZE))
   3756 	(*WebPIDecoder)(unsafe.Pointer(idec)).Fio.Fdata = data
   3757 	(*WebPIDecoder)(unsafe.Pointer(idec)).Fio.Fdata_size = curr_size
   3758 	(*WebPIDecoder)(unsafe.Pointer(idec)).Fstate = int32(STATE_VP8_PARTS0)
   3759 	return int32(VP8_STATUS_OK)
   3760 }
   3761 
   3762 // C documentation
   3763 //
   3764 //	// Partition #0
   3765 func CopyParts0Data(tls *libc.TLS, idec uintptr) (r VP8StatusCode1) {
   3766 	var br, dec, mem, part0_buf uintptr
   3767 	var part_size size_t
   3768 	_, _, _, _, _ = br, dec, mem, part0_buf, part_size
   3769 	dec = (*WebPIDecoder)(unsafe.Pointer(idec)).Fdec
   3770 	br = dec + 16
   3771 	part_size = uint64(int64((*VP8BitReader)(unsafe.Pointer(br)).Fbuf_end) - int64((*VP8BitReader)(unsafe.Pointer(br)).Fbuf))
   3772 	mem = idec + 296
   3773 	// the following is a format limitation, no need for runtime check:
   3774 	if part_size == uint64(0) { // can't have zero-size partition #0
   3775 		return int32(VP8_STATUS_BITSTREAM_ERROR)
   3776 	}
   3777 	if (*MemBuffer)(unsafe.Pointer(mem)).Fmode == int32(MEM_MODE_APPEND) {
   3778 		// We copy and grab ownership of the partition #0 data.
   3779 		part0_buf = WebPSafeMalloc(tls, uint64(1), part_size)
   3780 		if part0_buf == libc.UintptrFromInt32(0) {
   3781 			return int32(VP8_STATUS_OUT_OF_MEMORY)
   3782 		}
   3783 		libc.Xmemcpy(tls, part0_buf, (*VP8BitReader)(unsafe.Pointer(br)).Fbuf, part_size)
   3784 		(*MemBuffer)(unsafe.Pointer(mem)).Fpart0_buf = part0_buf
   3785 		VP8BitReaderSetBuffer(tls, br, part0_buf, part_size)
   3786 	} else {
   3787 		// Else: just keep pointers to the partition #0's data in dec->br.
   3788 	}
   3789 	**(**size_t)(__ccgo_up(mem + 8)) += part_size
   3790 	return int32(VP8_STATUS_OK)
   3791 }
   3792 
   3793 func DecodePartition0(tls *libc.TLS, idec uintptr) (r VP8StatusCode1) {
   3794 	var dec, io, output, params uintptr
   3795 	var status VP8StatusCode1
   3796 	_, _, _, _, _ = dec, io, output, params, status
   3797 	dec = (*WebPIDecoder)(unsafe.Pointer(idec)).Fdec
   3798 	io = idec + 136
   3799 	params = idec + 8
   3800 	output = (*WebPDecParams)(unsafe.Pointer(params)).Foutput
   3801 	// Wait till we have enough data for the whole partition #0
   3802 	if MemDataSize(tls, idec+296) < (*WebPIDecoder)(unsafe.Pointer(idec)).Fmem.Fpart0_size {
   3803 		return int32(VP8_STATUS_SUSPENDED)
   3804 	}
   3805 	if !(VP8GetHeaders(tls, dec, io) != 0) {
   3806 		status = (*VP8Decoder)(unsafe.Pointer(dec)).Fstatus
   3807 		if status == int32(VP8_STATUS_SUSPENDED) || status == int32(VP8_STATUS_NOT_ENOUGH_DATA) {
   3808 			// treating NOT_ENOUGH_DATA as SUSPENDED state
   3809 			return int32(VP8_STATUS_SUSPENDED)
   3810 		}
   3811 		return IDecError(tls, idec, status)
   3812 	}
   3813 	// Allocate/Verify output buffer now
   3814 	(*VP8Decoder)(unsafe.Pointer(dec)).Fstatus = WebPAllocateDecBuffer(tls, (*VP8Io)(unsafe.Pointer(io)).Fwidth, (*VP8Io)(unsafe.Pointer(io)).Fheight, (*WebPDecParams)(unsafe.Pointer(params)).Foptions, output)
   3815 	if (*VP8Decoder)(unsafe.Pointer(dec)).Fstatus != int32(VP8_STATUS_OK) {
   3816 		return IDecError(tls, idec, (*VP8Decoder)(unsafe.Pointer(dec)).Fstatus)
   3817 	}
   3818 	// This change must be done before calling VP8InitFrame()
   3819 	(*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)
   3820 	VP8InitDithering(tls, (*WebPDecParams)(unsafe.Pointer(params)).Foptions, dec)
   3821 	(*VP8Decoder)(unsafe.Pointer(dec)).Fstatus = CopyParts0Data(tls, idec)
   3822 	if (*VP8Decoder)(unsafe.Pointer(dec)).Fstatus != int32(VP8_STATUS_OK) {
   3823 		return IDecError(tls, idec, (*VP8Decoder)(unsafe.Pointer(dec)).Fstatus)
   3824 	}
   3825 	// Finish setting up the decoding parameters. Will call io->setup().
   3826 	if VP8EnterCritical(tls, dec, io) != int32(VP8_STATUS_OK) {
   3827 		return IDecError(tls, idec, (*VP8Decoder)(unsafe.Pointer(dec)).Fstatus)
   3828 	}
   3829 	// Note: past this point, teardown() must always be called
   3830 	// in case of error.
   3831 	(*WebPIDecoder)(unsafe.Pointer(idec)).Fstate = int32(STATE_VP8_DATA)
   3832 	// Allocate memory and prepare everything.
   3833 	if !(VP8InitFrame(tls, dec, io) != 0) {
   3834 		return IDecError(tls, idec, (*VP8Decoder)(unsafe.Pointer(dec)).Fstatus)
   3835 	}
   3836 	return int32(VP8_STATUS_OK)
   3837 }
   3838 
   3839 // C documentation
   3840 //
   3841 //	// Remaining partitions
   3842 func DecodeRemaining(tls *libc.TLS, idec uintptr) (r VP8StatusCode1) {
   3843 	bp := tls.Alloc(64)
   3844 	defer tls.Free(64)
   3845 	var dec, io, token_br uintptr
   3846 	var _ /* context at bp+0 */ MBContext
   3847 	_, _, _ = dec, io, token_br
   3848 	dec = (*WebPIDecoder)(unsafe.Pointer(idec)).Fdec
   3849 	io = idec + 136
   3850 	// Make sure partition #0 has been read before, to set dec to ready.
   3851 	if !((*VP8Decoder)(unsafe.Pointer(dec)).Fready != 0) {
   3852 		return IDecError(tls, idec, int32(VP8_STATUS_BITSTREAM_ERROR))
   3853 	}
   3854 	for {
   3855 		if !((*VP8Decoder)(unsafe.Pointer(dec)).Fmb_y < (*VP8Decoder)(unsafe.Pointer(dec)).Fmb_h) {
   3856 			break
   3857 		}
   3858 		if (*WebPIDecoder)(unsafe.Pointer(idec)).Flast_mb_y != (*VP8Decoder)(unsafe.Pointer(dec)).Fmb_y {
   3859 			if !(VP8ParseIntraModeRow(tls, dec+16, dec) != 0) {
   3860 				// note: normally, error shouldn't occur since we already have the whole
   3861 				// partition0 available here in DecodeRemaining(). Reaching EOF while
   3862 				// reading intra modes really means a BITSTREAM_ERROR.
   3863 				return IDecError(tls, idec, int32(VP8_STATUS_BITSTREAM_ERROR))
   3864 			}
   3865 			(*WebPIDecoder)(unsafe.Pointer(idec)).Flast_mb_y = (*VP8Decoder)(unsafe.Pointer(dec)).Fmb_y
   3866 		}
   3867 		for {
   3868 			if !((*VP8Decoder)(unsafe.Pointer(dec)).Fmb_x < (*VP8Decoder)(unsafe.Pointer(dec)).Fmb_w) {
   3869 				break
   3870 			}
   3871 			token_br = dec + 440 + uintptr(uint32((*VP8Decoder)(unsafe.Pointer(dec)).Fmb_y)&(*VP8Decoder)(unsafe.Pointer(dec)).Fnum_parts_minus_one)*48
   3872 			SaveContext(tls, dec, token_br, bp)
   3873 			if !(VP8DecodeMB(tls, dec, token_br) != 0) {
   3874 				// We shouldn't fail when MAX_MB data was available
   3875 				if (*VP8Decoder)(unsafe.Pointer(dec)).Fnum_parts_minus_one == uint32(0) && MemDataSize(tls, idec+296) > uint64(MAX_MB_SIZE) {
   3876 					return IDecError(tls, idec, int32(VP8_STATUS_BITSTREAM_ERROR))
   3877 				}
   3878 				// Synchronize the threads.
   3879 				if (*VP8Decoder)(unsafe.Pointer(dec)).Fmt_method > 0 {
   3880 					if !((*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*WebPWorkerInterface)(unsafe.Pointer(WebPGetWorkerInterface(tls))).FSync})))(tls, dec+152) != 0) {
   3881 						return IDecError(tls, idec, int32(VP8_STATUS_BITSTREAM_ERROR))
   3882 					}
   3883 				}
   3884 				RestoreContext(tls, bp, dec, token_br)
   3885 				return int32(VP8_STATUS_SUSPENDED)
   3886 			}
   3887 			// Release buffer only if there is only one partition
   3888 			if (*VP8Decoder)(unsafe.Pointer(dec)).Fnum_parts_minus_one == uint32(0) {
   3889 				(*WebPIDecoder)(unsafe.Pointer(idec)).Fmem.Fstart = uint64(int64((*VP8BitReader)(unsafe.Pointer(token_br)).Fbuf) - int64((*WebPIDecoder)(unsafe.Pointer(idec)).Fmem.Fbuf))
   3890 			}
   3891 			goto _2
   3892 		_2:
   3893 			;
   3894 			(*VP8Decoder)(unsafe.Pointer(dec)).Fmb_x = (*VP8Decoder)(unsafe.Pointer(dec)).Fmb_x + 1
   3895 		}
   3896 		VP8InitScanline(tls, dec) // Prepare for next scanline
   3897 		// Reconstruct, filter and emit the row.
   3898 		if !(VP8ProcessRow(tls, dec, io) != 0) {
   3899 			return IDecError(tls, idec, int32(VP8_STATUS_USER_ABORT))
   3900 		}
   3901 		goto _1
   3902 	_1:
   3903 		;
   3904 		(*VP8Decoder)(unsafe.Pointer(dec)).Fmb_y = (*VP8Decoder)(unsafe.Pointer(dec)).Fmb_y + 1
   3905 	}
   3906 	// Synchronize the thread and check for errors.
   3907 	if !(VP8ExitCritical(tls, dec, io) != 0) {
   3908 		(*WebPIDecoder)(unsafe.Pointer(idec)).Fstate = int32(STATE_ERROR) // prevent re-entry in IDecError
   3909 		return IDecError(tls, idec, int32(VP8_STATUS_USER_ABORT))
   3910 	}
   3911 	(*VP8Decoder)(unsafe.Pointer(dec)).Fready = 0
   3912 	return FinishDecoding(tls, idec)
   3913 }
   3914 
   3915 func ErrorStatusLossless(tls *libc.TLS, idec uintptr, status VP8StatusCode1) (r VP8StatusCode1) {
   3916 	if status == int32(VP8_STATUS_SUSPENDED) || status == int32(VP8_STATUS_NOT_ENOUGH_DATA) {
   3917 		return int32(VP8_STATUS_SUSPENDED)
   3918 	}
   3919 	return IDecError(tls, idec, status)
   3920 }
   3921 
   3922 func DecodeVP8LHeader(tls *libc.TLS, idec uintptr) (r VP8StatusCode1) {
   3923 	var curr_size size_t
   3924 	var dec, io, output, params uintptr
   3925 	_, _, _, _, _ = curr_size, dec, io, output, params
   3926 	io = idec + 136
   3927 	dec = (*WebPIDecoder)(unsafe.Pointer(idec)).Fdec
   3928 	params = idec + 8
   3929 	output = (*WebPDecParams)(unsafe.Pointer(params)).Foutput
   3930 	curr_size = MemDataSize(tls, idec+296)
   3931 	// Wait until there's enough data for decoding header.
   3932 	if curr_size < (*WebPIDecoder)(unsafe.Pointer(idec)).Fchunk_size>>libc.Int32FromInt32(3) {
   3933 		(*VP8LDecoder)(unsafe.Pointer(dec)).Fstatus = int32(VP8_STATUS_SUSPENDED)
   3934 		return ErrorStatusLossless(tls, idec, (*VP8LDecoder)(unsafe.Pointer(dec)).Fstatus)
   3935 	}
   3936 	if !(VP8LDecodeHeader(tls, dec, io) != 0) {
   3937 		if (*VP8LDecoder)(unsafe.Pointer(dec)).Fstatus == int32(VP8_STATUS_BITSTREAM_ERROR) && curr_size < (*WebPIDecoder)(unsafe.Pointer(idec)).Fchunk_size {
   3938 			(*VP8LDecoder)(unsafe.Pointer(dec)).Fstatus = int32(VP8_STATUS_SUSPENDED)
   3939 		}
   3940 		return ErrorStatusLossless(tls, idec, (*VP8LDecoder)(unsafe.Pointer(dec)).Fstatus)
   3941 	}
   3942 	// Allocate/verify output buffer now.
   3943 	(*VP8LDecoder)(unsafe.Pointer(dec)).Fstatus = WebPAllocateDecBuffer(tls, (*VP8Io)(unsafe.Pointer(io)).Fwidth, (*VP8Io)(unsafe.Pointer(io)).Fheight, (*WebPDecParams)(unsafe.Pointer(params)).Foptions, output)
   3944 	if (*VP8LDecoder)(unsafe.Pointer(dec)).Fstatus != int32(VP8_STATUS_OK) {
   3945 		return IDecError(tls, idec, (*VP8LDecoder)(unsafe.Pointer(dec)).Fstatus)
   3946 	}
   3947 	(*WebPIDecoder)(unsafe.Pointer(idec)).Fstate = int32(STATE_VP8L_DATA)
   3948 	return int32(VP8_STATUS_OK)
   3949 }
   3950 
   3951 func DecodeVP8LData(tls *libc.TLS, idec uintptr) (r VP8StatusCode1) {
   3952 	var curr_size size_t
   3953 	var dec uintptr
   3954 	var v1 int32
   3955 	_, _, _ = curr_size, dec, v1
   3956 	dec = (*WebPIDecoder)(unsafe.Pointer(idec)).Fdec
   3957 	curr_size = MemDataSize(tls, idec+296)
   3958 	// Switch to incremental decoding if we don't have all the bytes available.
   3959 	(*VP8LDecoder)(unsafe.Pointer(dec)).Fincremental = libc.BoolInt32(curr_size < (*WebPIDecoder)(unsafe.Pointer(idec)).Fchunk_size)
   3960 	if !(VP8LDecodeImage(tls, dec) != 0) {
   3961 		return ErrorStatusLossless(tls, idec, (*VP8LDecoder)(unsafe.Pointer(dec)).Fstatus)
   3962 	}
   3963 	if (*VP8LDecoder)(unsafe.Pointer(dec)).Fstatus == int32(VP8_STATUS_SUSPENDED) {
   3964 		v1 = (*VP8LDecoder)(unsafe.Pointer(dec)).Fstatus
   3965 	} else {
   3966 		v1 = FinishDecoding(tls, idec)
   3967 	}
   3968 	return v1
   3969 }
   3970 
   3971 // C documentation
   3972 //
   3973 //	// Main decoding loop
   3974 func IDecode(tls *libc.TLS, idec uintptr) (r VP8StatusCode1) {
   3975 	var dec uintptr
   3976 	var status VP8StatusCode1
   3977 	_, _ = dec, status
   3978 	status = int32(VP8_STATUS_SUSPENDED)
   3979 	if (*WebPIDecoder)(unsafe.Pointer(idec)).Fstate == int32(STATE_WEBP_HEADER) {
   3980 		status = DecodeWebPHeaders(tls, idec)
   3981 	} else {
   3982 		if (*WebPIDecoder)(unsafe.Pointer(idec)).Fdec == libc.UintptrFromInt32(0) {
   3983 			return int32(VP8_STATUS_SUSPENDED) // can't continue if we have no decoder.
   3984 		}
   3985 	}
   3986 	if (*WebPIDecoder)(unsafe.Pointer(idec)).Fstate == int32(STATE_VP8_HEADER) {
   3987 		status = DecodeVP8FrameHeader(tls, idec)
   3988 	}
   3989 	if (*WebPIDecoder)(unsafe.Pointer(idec)).Fstate == int32(STATE_VP8_PARTS0) {
   3990 		status = DecodePartition0(tls, idec)
   3991 	}
   3992 	if (*WebPIDecoder)(unsafe.Pointer(idec)).Fstate == int32(STATE_VP8_DATA) {
   3993 		dec = (*WebPIDecoder)(unsafe.Pointer(idec)).Fdec
   3994 		if dec == libc.UintptrFromInt32(0) {
   3995 			return int32(VP8_STATUS_SUSPENDED) // can't continue if we have no decoder.
   3996 		}
   3997 		status = DecodeRemaining(tls, idec)
   3998 	}
   3999 	if (*WebPIDecoder)(unsafe.Pointer(idec)).Fstate == int32(STATE_VP8L_HEADER) {
   4000 		status = DecodeVP8LHeader(tls, idec)
   4001 	}
   4002 	if (*WebPIDecoder)(unsafe.Pointer(idec)).Fstate == int32(STATE_VP8L_DATA) {
   4003 		status = DecodeVP8LData(tls, idec)
   4004 	}
   4005 	return status
   4006 }
   4007 
   4008 // ------------------------------------------------------------------------------
   4009 // Internal constructor
   4010 func NewDecoder(tls *libc.TLS, output_buffer uintptr, features uintptr) (r uintptr) {
   4011 	var idec uintptr
   4012 	var v1, v3 int32
   4013 	var v5 bool
   4014 	_, _, _, _ = idec, v1, v3, v5
   4015 	idec = WebPSafeCalloc(tls, uint64(1), uint64(496))
   4016 	if idec == libc.UintptrFromInt32(0) {
   4017 		return libc.UintptrFromInt32(0)
   4018 	}
   4019 	(*WebPIDecoder)(unsafe.Pointer(idec)).Fstate = int32(STATE_WEBP_HEADER)
   4020 	(*WebPIDecoder)(unsafe.Pointer(idec)).Fchunk_size = uint64(0)
   4021 	(*WebPIDecoder)(unsafe.Pointer(idec)).Flast_mb_y = -int32(1)
   4022 	InitMemBuffer(tls, idec+296)
   4023 	v1 = WebPInitDecBufferInternal(tls, idec+352, int32(WEBP_DECODER_ABI_VERSION))
   4024 	goto _2
   4025 _2:
   4026 	;
   4027 	if v5 = !(v1 != 0); !v5 {
   4028 		v3 = VP8InitIoInternal(tls, idec+136, int32(WEBP_DECODER_ABI_VERSION))
   4029 		goto _4
   4030 	_4:
   4031 	}
   4032 	if v5 || !(v3 != 0) {
   4033 		WebPSafeFree(tls, idec)
   4034 		return libc.UintptrFromInt32(0)
   4035 	}
   4036 	WebPResetDecParams(tls, idec+8)
   4037 	if output_buffer == libc.UintptrFromInt32(0) || WebPAvoidSlowMemory(tls, output_buffer, features) != 0 {
   4038 		(*WebPIDecoder)(unsafe.Pointer(idec)).Fparams.Foutput = idec + 352
   4039 		(*WebPIDecoder)(unsafe.Pointer(idec)).Ffinal_output = output_buffer
   4040 		if output_buffer != libc.UintptrFromInt32(0) {
   4041 			(*WebPDecBuffer)(unsafe.Pointer((*WebPIDecoder)(unsafe.Pointer(idec)).Fparams.Foutput)).Fcolorspace = (*WebPDecBuffer)(unsafe.Pointer(output_buffer)).Fcolorspace
   4042 		}
   4043 	} else {
   4044 		(*WebPIDecoder)(unsafe.Pointer(idec)).Fparams.Foutput = output_buffer
   4045 		(*WebPIDecoder)(unsafe.Pointer(idec)).Ffinal_output = libc.UintptrFromInt32(0)
   4046 	}
   4047 	WebPInitCustomIo(tls, idec+8, idec+136) // Plug the I/O functions.
   4048 	return idec
   4049 }
   4050 
   4051 //------------------------------------------------------------------------------
   4052 // Public functions
   4053 
   4054 func WebPINewDecoder(tls *libc.TLS, output_buffer uintptr) (r uintptr) {
   4055 	return NewDecoder(tls, output_buffer, libc.UintptrFromInt32(0))
   4056 }
   4057 
   4058 func WebPIDecode(tls *libc.TLS, data1 uintptr, data_size1 size_t, config uintptr) (r uintptr) {
   4059 	bp := tls.Alloc(48)
   4060 	defer tls.Free(48)
   4061 	var features1, idec, v1 uintptr
   4062 	var v2 VP8StatusCode1
   4063 	var _ /* tmp_features at bp+0 */ WebPBitstreamFeatures
   4064 	_, _, _, _ = features1, idec, v1, v2
   4065 	if config == libc.UintptrFromInt32(0) {
   4066 		v1 = bp
   4067 	} else {
   4068 		v1 = config
   4069 	}
   4070 	features1 = v1
   4071 	libc.Xmemset(tls, bp, 0, uint64(40))
   4072 	// Parse the bitstream's features, if requested:
   4073 	if data1 != libc.UintptrFromInt32(0) && data_size1 > uint64(0) {
   4074 		v2 = WebPGetFeaturesInternal(tls, data1, data_size1, features1, int32(WEBP_DECODER_ABI_VERSION))
   4075 		goto _3
   4076 	_3:
   4077 		if v2 != int32(VP8_STATUS_OK) {
   4078 			return libc.UintptrFromInt32(0)
   4079 		}
   4080 	}
   4081 	// Create an instance of the incremental decoder
   4082 	if config != libc.UintptrFromInt32(0) {
   4083 		v1 = NewDecoder(tls, config+40, features1)
   4084 	} else {
   4085 		v1 = NewDecoder(tls, libc.UintptrFromInt32(0), features1)
   4086 	}
   4087 	idec = v1
   4088 	if idec == libc.UintptrFromInt32(0) {
   4089 		return libc.UintptrFromInt32(0)
   4090 	}
   4091 	// Finish initialization
   4092 	if config != libc.UintptrFromInt32(0) {
   4093 		(*WebPIDecoder)(unsafe.Pointer(idec)).Fparams.Foptions = config + 160
   4094 	}
   4095 	return idec
   4096 }
   4097 
   4098 func WebPIDelete(tls *libc.TLS, idec uintptr) {
   4099 	if idec == libc.UintptrFromInt32(0) {
   4100 		return
   4101 	}
   4102 	if (*WebPIDecoder)(unsafe.Pointer(idec)).Fdec != libc.UintptrFromInt32(0) {
   4103 		if !((*WebPIDecoder)(unsafe.Pointer(idec)).Fis_lossless != 0) {
   4104 			if (*WebPIDecoder)(unsafe.Pointer(idec)).Fstate == int32(STATE_VP8_DATA) {
   4105 				// Synchronize the thread, clean-up and check for errors.
   4106 				// TODO(vrabaud) do we care about the return result?
   4107 				VP8ExitCritical(tls, (*WebPIDecoder)(unsafe.Pointer(idec)).Fdec, idec+136)
   4108 			}
   4109 			VP8Delete(tls, (*WebPIDecoder)(unsafe.Pointer(idec)).Fdec)
   4110 		} else {
   4111 			VP8LDelete(tls, (*WebPIDecoder)(unsafe.Pointer(idec)).Fdec)
   4112 		}
   4113 	}
   4114 	ClearMemBuffer(tls, idec+296)
   4115 	WebPFreeDecBuffer(tls, idec+352)
   4116 	WebPSafeFree(tls, idec)
   4117 }
   4118 
   4119 //------------------------------------------------------------------------------
   4120 // Wrapper toward WebPINewDecoder
   4121 
   4122 func WebPINewRGB(tls *libc.TLS, csp WEBP_CSP_MODE1, output_buffer uintptr, output_buffer_size size_t, output_stride int32) (r uintptr) {
   4123 	var idec uintptr
   4124 	var is_external_memory, v1 int32
   4125 	_, _, _ = idec, is_external_memory, v1
   4126 	if output_buffer != libc.UintptrFromInt32(0) {
   4127 		v1 = int32(1)
   4128 	} else {
   4129 		v1 = 0
   4130 	}
   4131 	is_external_memory = v1
   4132 	if csp >= int32(MODE_YUV) {
   4133 		return libc.UintptrFromInt32(0)
   4134 	}
   4135 	if is_external_memory == 0 { // Overwrite parameters to sane values.
   4136 		output_buffer_size = uint64(0)
   4137 		output_stride = 0
   4138 	} else { // A buffer was passed. Validate the other params.
   4139 		if output_stride == 0 || output_buffer_size == uint64(0) {
   4140 			return libc.UintptrFromInt32(0) // invalid parameter.
   4141 		}
   4142 	}
   4143 	idec = WebPINewDecoder(tls, libc.UintptrFromInt32(0))
   4144 	if idec == libc.UintptrFromInt32(0) {
   4145 		return libc.UintptrFromInt32(0)
   4146 	}
   4147 	(*WebPIDecoder)(unsafe.Pointer(idec)).Foutput.Fcolorspace = csp
   4148 	(*WebPIDecoder)(unsafe.Pointer(idec)).Foutput.Fis_external_memory = is_external_memory
   4149 	*(*uintptr)(unsafe.Pointer(idec + 352 + 16)) = output_buffer
   4150 	*(*int32)(unsafe.Pointer(idec + 352 + 16 + 8)) = output_stride
   4151 	*(*size_t)(unsafe.Pointer(idec + 352 + 16 + 16)) = output_buffer_size
   4152 	return idec
   4153 }
   4154 
   4155 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) {
   4156 	var colorspace WEBP_CSP_MODE1
   4157 	var idec, v8, v9 uintptr
   4158 	var is_external_memory, v1, v5, v6 int32
   4159 	var v2, v3, v4 size_t
   4160 	_, _, _, _, _, _, _, _, _, _, _ = colorspace, idec, is_external_memory, v1, v2, v3, v4, v5, v6, v8, v9
   4161 	if luma != libc.UintptrFromInt32(0) {
   4162 		v1 = int32(1)
   4163 	} else {
   4164 		v1 = 0
   4165 	}
   4166 	is_external_memory = v1
   4167 	if is_external_memory == 0 { // Overwrite parameters to sane values.
   4168 		v4 = libc.Uint64FromInt32(0)
   4169 		a_size = v4
   4170 		v3 = v4
   4171 		v_size = v3
   4172 		v2 = v3
   4173 		u_size = v2
   4174 		luma_size = v2
   4175 		v6 = libc.Int32FromInt32(0)
   4176 		a_stride = v6
   4177 		v5 = v6
   4178 		v_stride = v5
   4179 		v1 = v5
   4180 		u_stride = v1
   4181 		luma_stride = v1
   4182 		v9 = libc.UintptrFromInt32(0)
   4183 		a = v9
   4184 		v8 = v9
   4185 		v = v8
   4186 		u = v8
   4187 		colorspace = int32(MODE_YUVA)
   4188 	} else { // A luma buffer was passed. Validate the other parameters.
   4189 		if u == libc.UintptrFromInt32(0) || v == libc.UintptrFromInt32(0) {
   4190 			return libc.UintptrFromInt32(0)
   4191 		}
   4192 		if luma_size == uint64(0) || u_size == uint64(0) || v_size == uint64(0) {
   4193 			return libc.UintptrFromInt32(0)
   4194 		}
   4195 		if luma_stride == 0 || u_stride == 0 || v_stride == 0 {
   4196 			return libc.UintptrFromInt32(0)
   4197 		}
   4198 		if a != libc.UintptrFromInt32(0) {
   4199 			if a_size == uint64(0) || a_stride == 0 {
   4200 				return libc.UintptrFromInt32(0)
   4201 			}
   4202 		}
   4203 		if a == libc.UintptrFromInt32(0) {
   4204 			v1 = int32(MODE_YUV)
   4205 		} else {
   4206 			v1 = int32(MODE_YUVA)
   4207 		}
   4208 		colorspace = v1
   4209 	}
   4210 	idec = WebPINewDecoder(tls, libc.UintptrFromInt32(0))
   4211 	if idec == libc.UintptrFromInt32(0) {
   4212 		return libc.UintptrFromInt32(0)
   4213 	}
   4214 	(*WebPIDecoder)(unsafe.Pointer(idec)).Foutput.Fcolorspace = colorspace
   4215 	(*WebPIDecoder)(unsafe.Pointer(idec)).Foutput.Fis_external_memory = is_external_memory
   4216 	*(*uintptr)(unsafe.Pointer(idec + 352 + 16)) = luma
   4217 	*(*int32)(unsafe.Pointer(idec + 352 + 16 + 32)) = luma_stride
   4218 	*(*size_t)(unsafe.Pointer(idec + 352 + 16 + 48)) = luma_size
   4219 	*(*uintptr)(unsafe.Pointer(idec + 352 + 16 + 8)) = u
   4220 	*(*int32)(unsafe.Pointer(idec + 352 + 16 + 36)) = u_stride
   4221 	*(*size_t)(unsafe.Pointer(idec + 352 + 16 + 56)) = u_size
   4222 	*(*uintptr)(unsafe.Pointer(idec + 352 + 16 + 16)) = v
   4223 	*(*int32)(unsafe.Pointer(idec + 352 + 16 + 40)) = v_stride
   4224 	*(*size_t)(unsafe.Pointer(idec + 352 + 16 + 64)) = v_size
   4225 	*(*uintptr)(unsafe.Pointer(idec + 352 + 16 + 24)) = a
   4226 	*(*int32)(unsafe.Pointer(idec + 352 + 16 + 44)) = a_stride
   4227 	*(*size_t)(unsafe.Pointer(idec + 352 + 16 + 72)) = a_size
   4228 	return idec
   4229 }
   4230 
   4231 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) {
   4232 	return WebPINewYUVA(tls, luma, luma_size, luma_stride, u, u_size, u_stride, v, v_size, v_stride, libc.UintptrFromInt32(0), uint64(0), 0)
   4233 }
   4234 
   4235 //------------------------------------------------------------------------------
   4236 
   4237 func IDecCheckStatus(tls *libc.TLS, idec uintptr) (r VP8StatusCode1) {
   4238 	if (*WebPIDecoder)(unsafe.Pointer(idec)).Fstate == int32(STATE_ERROR) {
   4239 		return int32(VP8_STATUS_BITSTREAM_ERROR)
   4240 	}
   4241 	if (*WebPIDecoder)(unsafe.Pointer(idec)).Fstate == int32(STATE_DONE) {
   4242 		return int32(VP8_STATUS_OK)
   4243 	}
   4244 	return int32(VP8_STATUS_SUSPENDED)
   4245 }
   4246 
   4247 func WebPIAppend(tls *libc.TLS, idec uintptr, data uintptr, data_size size_t) (r VP8StatusCode1) {
   4248 	var status VP8StatusCode1
   4249 	_ = status
   4250 	if idec == libc.UintptrFromInt32(0) || data == libc.UintptrFromInt32(0) {
   4251 		return int32(VP8_STATUS_INVALID_PARAM)
   4252 	}
   4253 	status = IDecCheckStatus(tls, idec)
   4254 	if status != int32(VP8_STATUS_SUSPENDED) {
   4255 		return status
   4256 	}
   4257 	// Check mixed calls between RemapMemBuffer and AppendToMemBuffer.
   4258 	if !(CheckMemBufferMode(tls, idec+296, int32(MEM_MODE_APPEND)) != 0) {
   4259 		return int32(VP8_STATUS_INVALID_PARAM)
   4260 	}
   4261 	// Append data to memory buffer
   4262 	if !(AppendToMemBuffer(tls, idec, data, data_size) != 0) {
   4263 		return int32(VP8_STATUS_OUT_OF_MEMORY)
   4264 	}
   4265 	return IDecode(tls, idec)
   4266 }
   4267 
   4268 func WebPIUpdate(tls *libc.TLS, idec uintptr, data uintptr, data_size size_t) (r VP8StatusCode1) {
   4269 	var status VP8StatusCode1
   4270 	_ = status
   4271 	if idec == libc.UintptrFromInt32(0) || data == libc.UintptrFromInt32(0) {
   4272 		return int32(VP8_STATUS_INVALID_PARAM)
   4273 	}
   4274 	status = IDecCheckStatus(tls, idec)
   4275 	if status != int32(VP8_STATUS_SUSPENDED) {
   4276 		return status
   4277 	}
   4278 	// Check mixed calls between RemapMemBuffer and AppendToMemBuffer.
   4279 	if !(CheckMemBufferMode(tls, idec+296, int32(MEM_MODE_MAP)) != 0) {
   4280 		return int32(VP8_STATUS_INVALID_PARAM)
   4281 	}
   4282 	// Make the memory buffer point to the new buffer
   4283 	if !(RemapMemBuffer(tls, idec, data, data_size) != 0) {
   4284 		return int32(VP8_STATUS_INVALID_PARAM)
   4285 	}
   4286 	return IDecode(tls, idec)
   4287 }
   4288 
   4289 //------------------------------------------------------------------------------
   4290 
   4291 func GetOutputBuffer(tls *libc.TLS, idec uintptr) (r uintptr) {
   4292 	if idec == libc.UintptrFromInt32(0) || (*WebPIDecoder)(unsafe.Pointer(idec)).Fdec == libc.UintptrFromInt32(0) {
   4293 		return libc.UintptrFromInt32(0)
   4294 	}
   4295 	if (*WebPIDecoder)(unsafe.Pointer(idec)).Fstate <= int32(STATE_VP8_PARTS0) {
   4296 		return libc.UintptrFromInt32(0)
   4297 	}
   4298 	if (*WebPIDecoder)(unsafe.Pointer(idec)).Ffinal_output != libc.UintptrFromInt32(0) {
   4299 		return libc.UintptrFromInt32(0) // not yet slow-copied
   4300 	}
   4301 	return (*WebPIDecoder)(unsafe.Pointer(idec)).Fparams.Foutput
   4302 }
   4303 
   4304 func WebPIDecodedArea(tls *libc.TLS, idec uintptr, left uintptr, top uintptr, width uintptr, height uintptr) (r uintptr) {
   4305 	var src uintptr
   4306 	_ = src
   4307 	src = GetOutputBuffer(tls, idec)
   4308 	if left != libc.UintptrFromInt32(0) {
   4309 		**(**int32)(__ccgo_up(left)) = 0
   4310 	}
   4311 	if top != libc.UintptrFromInt32(0) {
   4312 		**(**int32)(__ccgo_up(top)) = 0
   4313 	}
   4314 	if src != libc.UintptrFromInt32(0) {
   4315 		if width != libc.UintptrFromInt32(0) {
   4316 			**(**int32)(__ccgo_up(width)) = (*WebPDecBuffer)(unsafe.Pointer(src)).Fwidth
   4317 		}
   4318 		if height != libc.UintptrFromInt32(0) {
   4319 			**(**int32)(__ccgo_up(height)) = (*WebPIDecoder)(unsafe.Pointer(idec)).Fparams.Flast_y
   4320 		}
   4321 	} else {
   4322 		if width != libc.UintptrFromInt32(0) {
   4323 			**(**int32)(__ccgo_up(width)) = 0
   4324 		}
   4325 		if height != libc.UintptrFromInt32(0) {
   4326 			**(**int32)(__ccgo_up(height)) = 0
   4327 		}
   4328 	}
   4329 	return src
   4330 }
   4331 
   4332 func WebPIDecGetRGB(tls *libc.TLS, idec uintptr, last_y uintptr, width uintptr, height uintptr, stride uintptr) (r uintptr) {
   4333 	var src uintptr
   4334 	_ = src
   4335 	src = GetOutputBuffer(tls, idec)
   4336 	if src == libc.UintptrFromInt32(0) {
   4337 		return libc.UintptrFromInt32(0)
   4338 	}
   4339 	if (*WebPDecBuffer)(unsafe.Pointer(src)).Fcolorspace >= int32(MODE_YUV) {
   4340 		return libc.UintptrFromInt32(0)
   4341 	}
   4342 	if last_y != libc.UintptrFromInt32(0) {
   4343 		**(**int32)(__ccgo_up(last_y)) = (*WebPIDecoder)(unsafe.Pointer(idec)).Fparams.Flast_y
   4344 	}
   4345 	if width != libc.UintptrFromInt32(0) {
   4346 		**(**int32)(__ccgo_up(width)) = (*WebPDecBuffer)(unsafe.Pointer(src)).Fwidth
   4347 	}
   4348 	if height != libc.UintptrFromInt32(0) {
   4349 		**(**int32)(__ccgo_up(height)) = (*WebPDecBuffer)(unsafe.Pointer(src)).Fheight
   4350 	}
   4351 	if stride != libc.UintptrFromInt32(0) {
   4352 		**(**int32)(__ccgo_up(stride)) = (*WebPDecBuffer)(unsafe.Pointer(src)).Fu.FRGBA.Fstride
   4353 	}
   4354 	return (*WebPDecBuffer)(unsafe.Pointer(src)).Fu.FRGBA.Frgba
   4355 }
   4356 
   4357 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) {
   4358 	var src uintptr
   4359 	_ = src
   4360 	src = GetOutputBuffer(tls, idec)
   4361 	if src == libc.UintptrFromInt32(0) {
   4362 		return libc.UintptrFromInt32(0)
   4363 	}
   4364 	if (*WebPDecBuffer)(unsafe.Pointer(src)).Fcolorspace < int32(MODE_YUV) {
   4365 		return libc.UintptrFromInt32(0)
   4366 	}
   4367 	if last_y != libc.UintptrFromInt32(0) {
   4368 		**(**int32)(__ccgo_up(last_y)) = (*WebPIDecoder)(unsafe.Pointer(idec)).Fparams.Flast_y
   4369 	}
   4370 	if u != libc.UintptrFromInt32(0) {
   4371 		**(**uintptr)(__ccgo_up(u)) = (*(*WebPYUVABuffer)(unsafe.Pointer(src + 16))).Fu
   4372 	}
   4373 	if v != libc.UintptrFromInt32(0) {
   4374 		**(**uintptr)(__ccgo_up(v)) = (*(*WebPYUVABuffer)(unsafe.Pointer(src + 16))).Fv
   4375 	}
   4376 	if a != libc.UintptrFromInt32(0) {
   4377 		**(**uintptr)(__ccgo_up(a)) = (*(*WebPYUVABuffer)(unsafe.Pointer(src + 16))).Fa
   4378 	}
   4379 	if width != libc.UintptrFromInt32(0) {
   4380 		**(**int32)(__ccgo_up(width)) = (*WebPDecBuffer)(unsafe.Pointer(src)).Fwidth
   4381 	}
   4382 	if height != libc.UintptrFromInt32(0) {
   4383 		**(**int32)(__ccgo_up(height)) = (*WebPDecBuffer)(unsafe.Pointer(src)).Fheight
   4384 	}
   4385 	if stride != libc.UintptrFromInt32(0) {
   4386 		**(**int32)(__ccgo_up(stride)) = (*(*WebPYUVABuffer)(unsafe.Pointer(src + 16))).Fy_stride
   4387 	}
   4388 	if uv_stride != libc.UintptrFromInt32(0) {
   4389 		**(**int32)(__ccgo_up(uv_stride)) = (*(*WebPYUVABuffer)(unsafe.Pointer(src + 16))).Fu_stride
   4390 	}
   4391 	if a_stride != libc.UintptrFromInt32(0) {
   4392 		**(**int32)(__ccgo_up(a_stride)) = (*(*WebPYUVABuffer)(unsafe.Pointer(src + 16))).Fa_stride
   4393 	}
   4394 	return (*(*WebPYUVABuffer)(unsafe.Pointer(src + 16))).Fy
   4395 }
   4396 
   4397 type __ccgo_fp__XWebPISetIOHooks_1 = func(*libc.TLS, uintptr) int32
   4398 
   4399 type __ccgo_fp__XWebPISetIOHooks_2 = func(*libc.TLS, uintptr) int32
   4400 
   4401 type __ccgo_fp__XWebPISetIOHooks_3 = func(*libc.TLS, uintptr)
   4402 
   4403 func WebPISetIOHooks(tls *libc.TLS, idec uintptr, __ccgo_fp_put VP8IoPutHook, __ccgo_fp_setup VP8IoSetupHook, __ccgo_fp_teardown VP8IoTeardownHook, user_data uintptr) (r int32) {
   4404 	if idec == libc.UintptrFromInt32(0) || (*WebPIDecoder)(unsafe.Pointer(idec)).Fstate > int32(STATE_WEBP_HEADER) {
   4405 		return 0
   4406 	}
   4407 	(*WebPIDecoder)(unsafe.Pointer(idec)).Fio.Fput = __ccgo_fp_put
   4408 	(*WebPIDecoder)(unsafe.Pointer(idec)).Fio.Fsetup = __ccgo_fp_setup
   4409 	(*WebPIDecoder)(unsafe.Pointer(idec)).Fio.Fteardown = __ccgo_fp_teardown
   4410 	(*WebPIDecoder)(unsafe.Pointer(idec)).Fio.Fopaque = user_data
   4411 	return int32(1)
   4412 }
   4413 
   4414 var kHashMul4 = uint32(0x1e35a7bd)
   4415 
   4416 const YUV_FIX = 16
   4417 const YUV_HALF = 32768
   4418 const YUV_FIX2 = 6
   4419 const YUV_MASK2 = 16383
   4420 
   4421 //------------------------------------------------------------------------------
   4422 
   4423 // Copyright 2010 Google Inc. All Rights Reserved.
   4424 //
   4425 // Use of this source code is governed by a BSD-style license
   4426 // that can be found in the COPYING file in the root of the source
   4427 // tree. An additional intellectual property rights grant can be found
   4428 // in the file PATENTS. All contributing project authors may
   4429 // be found in the AUTHORS file in the root of the source tree.
   4430 // -----------------------------------------------------------------------------
   4431 //
   4432 //  Main decoding functions for WebP images.
   4433 //
   4434 // Author: Skal (pascal.massimino@gmail.com)
   4435 
   4436 //------------------------------------------------------------------------------
   4437 // Main YUV<->RGB conversion functions
   4438 
   4439 func EmitYUV(tls *libc.TLS, io uintptr, p uintptr) (r int32) {
   4440 	var buf, output, u_dst, v_dst, y_dst uintptr
   4441 	var mb_h, mb_w, uv_h, uv_w int32
   4442 	_, _, _, _, _, _, _, _, _ = buf, mb_h, mb_w, output, u_dst, uv_h, uv_w, v_dst, y_dst
   4443 	output = (*WebPDecParams)(unsafe.Pointer(p)).Foutput
   4444 	buf = output + 16
   4445 	y_dst = (*WebPYUVABuffer)(unsafe.Pointer(buf)).Fy + uintptr(int64((*VP8Io)(unsafe.Pointer(io)).Fmb_y)*int64((*WebPYUVABuffer)(unsafe.Pointer(buf)).Fy_stride))
   4446 	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))
   4447 	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))
   4448 	mb_w = (*VP8Io)(unsafe.Pointer(io)).Fmb_w
   4449 	mb_h = (*VP8Io)(unsafe.Pointer(io)).Fmb_h
   4450 	uv_w = (mb_w + int32(1)) / int32(2)
   4451 	uv_h = (mb_h + int32(1)) / int32(2)
   4452 	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)
   4453 	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)
   4454 	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)
   4455 	return (*VP8Io)(unsafe.Pointer(io)).Fmb_h
   4456 }
   4457 
   4458 // C documentation
   4459 //
   4460 //	// Point-sampling U/V sampler.
   4461 func EmitSampledRGB(tls *libc.TLS, io uintptr, p uintptr) (r int32) {
   4462 	var buf, dst, output uintptr
   4463 	_, _, _ = buf, dst, output
   4464 	output = (*WebPDecParams)(unsafe.Pointer(p)).Foutput
   4465 	buf = output + 16
   4466 	dst = (*WebPRGBABuffer)(unsafe.Pointer(buf)).Frgba + uintptr(int64((*VP8Io)(unsafe.Pointer(io)).Fmb_y)*int64((*WebPRGBABuffer)(unsafe.Pointer(buf)).Fstride))
   4467 	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])
   4468 	return (*VP8Io)(unsafe.Pointer(io)).Fmb_h
   4469 }
   4470 
   4471 //------------------------------------------------------------------------------
   4472 // Fancy upsampling
   4473 
   4474 func EmitFancyRGB(tls *libc.TLS, io uintptr, p uintptr) (r int32) {
   4475 	var buf, cur_u, cur_v, cur_y, dst, top_u, top_v uintptr
   4476 	var mb_w, num_lines_out, uv_w, y, y_end int32
   4477 	var upsample WebPUpsampleLinePairFunc
   4478 	_, _, _, _, _, _, _, _, _, _, _, _, _ = buf, cur_u, cur_v, cur_y, dst, mb_w, num_lines_out, top_u, top_v, upsample, uv_w, y, y_end
   4479 	num_lines_out = (*VP8Io)(unsafe.Pointer(io)).Fmb_h // a priori guess
   4480 	buf = (*WebPDecParams)(unsafe.Pointer(p)).Foutput + 16
   4481 	dst = (*WebPRGBABuffer)(unsafe.Pointer(buf)).Frgba + uintptr(int64((*VP8Io)(unsafe.Pointer(io)).Fmb_y)*int64((*WebPRGBABuffer)(unsafe.Pointer(buf)).Fstride))
   4482 	upsample = WebPUpsamplers[(*WebPDecBuffer)(unsafe.Pointer((*WebPDecParams)(unsafe.Pointer(p)).Foutput)).Fcolorspace]
   4483 	cur_y = (*VP8Io)(unsafe.Pointer(io)).Fy
   4484 	cur_u = (*VP8Io)(unsafe.Pointer(io)).Fu
   4485 	cur_v = (*VP8Io)(unsafe.Pointer(io)).Fv
   4486 	top_u = (*WebPDecParams)(unsafe.Pointer(p)).Ftmp_u
   4487 	top_v = (*WebPDecParams)(unsafe.Pointer(p)).Ftmp_v
   4488 	y = (*VP8Io)(unsafe.Pointer(io)).Fmb_y
   4489 	y_end = (*VP8Io)(unsafe.Pointer(io)).Fmb_y + (*VP8Io)(unsafe.Pointer(io)).Fmb_h
   4490 	mb_w = (*VP8Io)(unsafe.Pointer(io)).Fmb_w
   4491 	uv_w = (mb_w + int32(1)) / int32(2)
   4492 	if y == 0 {
   4493 		// First line is special cased. We mirror the u/v samples at boundary.
   4494 		(*(*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)
   4495 	} else {
   4496 		// We can finish the left-over line from previous call.
   4497 		(*(*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)
   4498 		num_lines_out = num_lines_out + 1
   4499 	}
   4500 	// Loop over each output pairs of row.
   4501 	for {
   4502 		if !(y+int32(2) < y_end) {
   4503 			break
   4504 		}
   4505 		top_u = cur_u
   4506 		top_v = cur_v
   4507 		cur_u = cur_u + uintptr((*VP8Io)(unsafe.Pointer(io)).Fuv_stride)
   4508 		cur_v = cur_v + uintptr((*VP8Io)(unsafe.Pointer(io)).Fuv_stride)
   4509 		dst = dst + uintptr(int32(2)*(*WebPRGBABuffer)(unsafe.Pointer(buf)).Fstride)
   4510 		cur_y = cur_y + uintptr(int32(2)*(*VP8Io)(unsafe.Pointer(io)).Fy_stride)
   4511 		(*(*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)
   4512 		goto _1
   4513 	_1:
   4514 		;
   4515 		y = y + int32(2)
   4516 	}
   4517 	// move to last row
   4518 	cur_y = cur_y + uintptr((*VP8Io)(unsafe.Pointer(io)).Fy_stride)
   4519 	if (*VP8Io)(unsafe.Pointer(io)).Fcrop_top+y_end < (*VP8Io)(unsafe.Pointer(io)).Fcrop_bottom {
   4520 		// Save the unfinished samples for next call (as we're not done yet).
   4521 		libc.Xmemcpy(tls, (*WebPDecParams)(unsafe.Pointer(p)).Ftmp_y, cur_y, uint64(mb_w)*uint64(1))
   4522 		libc.Xmemcpy(tls, (*WebPDecParams)(unsafe.Pointer(p)).Ftmp_u, cur_u, uint64(uv_w)*uint64(1))
   4523 		libc.Xmemcpy(tls, (*WebPDecParams)(unsafe.Pointer(p)).Ftmp_v, cur_v, uint64(uv_w)*uint64(1))
   4524 		// The fancy upsampler leaves a row unfinished behind
   4525 		// (except for the very last row)
   4526 		num_lines_out = num_lines_out - 1
   4527 	} else {
   4528 		// Process the very last row of even-sized picture
   4529 		if !(y_end&libc.Int32FromInt32(1) != 0) {
   4530 			(*(*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)
   4531 		}
   4532 	}
   4533 	return num_lines_out
   4534 }
   4535 
   4536 //------------------------------------------------------------------------------
   4537 
   4538 func FillAlphaPlane(tls *libc.TLS, dst uintptr, w int32, h int32, stride int32) {
   4539 	var j int32
   4540 	_ = j
   4541 	j = 0
   4542 	for {
   4543 		if !(j < h) {
   4544 			break
   4545 		}
   4546 		libc.Xmemset(tls, dst, int32(0xff), uint64(w)*uint64(1))
   4547 		dst = dst + uintptr(stride)
   4548 		goto _1
   4549 	_1:
   4550 		;
   4551 		j = j + 1
   4552 	}
   4553 }
   4554 
   4555 func EmitAlphaYUV(tls *libc.TLS, io uintptr, p uintptr, expected_num_lines_out int32) (r int32) {
   4556 	var alpha, buf, dst uintptr
   4557 	var j, mb_h, mb_w int32
   4558 	_, _, _, _, _, _ = alpha, buf, dst, j, mb_h, mb_w
   4559 	alpha = (*VP8Io)(unsafe.Pointer(io)).Fa
   4560 	buf = (*WebPDecParams)(unsafe.Pointer(p)).Foutput + 16
   4561 	mb_w = (*VP8Io)(unsafe.Pointer(io)).Fmb_w
   4562 	mb_h = (*VP8Io)(unsafe.Pointer(io)).Fmb_h
   4563 	dst = (*WebPYUVABuffer)(unsafe.Pointer(buf)).Fa + uintptr(int64((*VP8Io)(unsafe.Pointer(io)).Fmb_y)*int64((*WebPYUVABuffer)(unsafe.Pointer(buf)).Fa_stride))
   4564 	_ = expected_num_lines_out
   4565 	if alpha != libc.UintptrFromInt32(0) {
   4566 		j = 0
   4567 		for {
   4568 			if !(j < mb_h) {
   4569 				break
   4570 			}
   4571 			libc.Xmemcpy(tls, dst, alpha, uint64(mb_w)*uint64(1))
   4572 			alpha = alpha + uintptr((*VP8Io)(unsafe.Pointer(io)).Fwidth)
   4573 			dst = dst + uintptr((*WebPYUVABuffer)(unsafe.Pointer(buf)).Fa_stride)
   4574 			goto _1
   4575 		_1:
   4576 			;
   4577 			j = j + 1
   4578 		}
   4579 	} else {
   4580 		if (*WebPYUVABuffer)(unsafe.Pointer(buf)).Fa != libc.UintptrFromInt32(0) {
   4581 			// the user requested alpha, but there is none, set it to opaque.
   4582 			FillAlphaPlane(tls, dst, mb_w, mb_h, (*WebPYUVABuffer)(unsafe.Pointer(buf)).Fa_stride)
   4583 		}
   4584 	}
   4585 	return 0
   4586 }
   4587 
   4588 func GetAlphaSourceRow(tls *libc.TLS, io uintptr, alpha uintptr, num_rows uintptr) (r int32) {
   4589 	var start_y int32
   4590 	_ = start_y
   4591 	start_y = (*VP8Io)(unsafe.Pointer(io)).Fmb_y
   4592 	**(**int32)(__ccgo_up(num_rows)) = (*VP8Io)(unsafe.Pointer(io)).Fmb_h
   4593 	// Compensate for the 1-line delay of the fancy upscaler.
   4594 	// This is similar to EmitFancyRGB().
   4595 	if (*VP8Io)(unsafe.Pointer(io)).Ffancy_upsampling != 0 {
   4596 		if start_y == 0 {
   4597 			// We don't process the last row yet. It'll be done during the next call.
   4598 			**(**int32)(__ccgo_up(num_rows)) = **(**int32)(__ccgo_up(num_rows)) - 1
   4599 		} else {
   4600 			start_y = start_y - 1
   4601 			// Fortunately, *alpha data is persistent, so we can go back
   4602 			// one row and finish alpha blending, now that the fancy upscaler
   4603 			// completed the YUV->RGB interpolation.
   4604 			**(**uintptr)(__ccgo_up(alpha)) -= uintptr((*VP8Io)(unsafe.Pointer(io)).Fwidth)
   4605 		}
   4606 		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 {
   4607 			// If it's the very last call, we process all the remaining rows!
   4608 			**(**int32)(__ccgo_up(num_rows)) = (*VP8Io)(unsafe.Pointer(io)).Fcrop_bottom - (*VP8Io)(unsafe.Pointer(io)).Fcrop_top - start_y
   4609 		}
   4610 	}
   4611 	return start_y
   4612 }
   4613 
   4614 func EmitAlphaRGB(tls *libc.TLS, io uintptr, p uintptr, expected_num_lines_out int32) (r int32) {
   4615 	bp := tls.Alloc(16)
   4616 	defer tls.Free(16)
   4617 	var alpha_first, has_alpha, mb_w, start_y, v1 int32
   4618 	var base_rgba, buf, dst uintptr
   4619 	var colorspace, v2 WEBP_CSP_MODE1
   4620 	var v5 bool
   4621 	var _ /* alpha at bp+0 */ uintptr
   4622 	var _ /* num_rows at bp+8 */ int32
   4623 	_, _, _, _, _, _, _, _, _, _, _ = alpha_first, base_rgba, buf, colorspace, dst, has_alpha, mb_w, start_y, v1, v2, v5
   4624 	**(**uintptr)(__ccgo_up(bp)) = (*VP8Io)(unsafe.Pointer(io)).Fa
   4625 	if **(**uintptr)(__ccgo_up(bp)) != libc.UintptrFromInt32(0) {
   4626 		mb_w = (*VP8Io)(unsafe.Pointer(io)).Fmb_w
   4627 		colorspace = (*WebPDecBuffer)(unsafe.Pointer((*WebPDecParams)(unsafe.Pointer(p)).Foutput)).Fcolorspace
   4628 		alpha_first = libc.BoolInt32(colorspace == int32(MODE_ARGB) || colorspace == int32(MODE_Argb))
   4629 		buf = (*WebPDecParams)(unsafe.Pointer(p)).Foutput + 16
   4630 		start_y = GetAlphaSourceRow(tls, io, bp, bp+8)
   4631 		base_rgba = (*WebPRGBABuffer)(unsafe.Pointer(buf)).Frgba + uintptr(int64(start_y)*int64((*WebPRGBABuffer)(unsafe.Pointer(buf)).Fstride))
   4632 		if alpha_first != 0 {
   4633 			v1 = 0
   4634 		} else {
   4635 			v1 = int32(3)
   4636 		}
   4637 		dst = base_rgba + uintptr(v1)
   4638 		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)
   4639 		_ = expected_num_lines_out
   4640 		// has_alpha is true if there's non-trivial alpha to premultiply with.
   4641 		if v5 = has_alpha != 0; v5 {
   4642 			v2 = colorspace
   4643 			v1 = libc.BoolInt32(v2 == int32(MODE_rgbA) || v2 == int32(MODE_bgrA) || v2 == int32(MODE_Argb) || v2 == int32(MODE_rgbA_4444))
   4644 			goto _4
   4645 		_4:
   4646 		}
   4647 		if v5 && v1 != 0 {
   4648 			(*(*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)
   4649 		}
   4650 	}
   4651 	return 0
   4652 }
   4653 
   4654 func EmitAlphaRGBA4444(tls *libc.TLS, io uintptr, p uintptr, expected_num_lines_out int32) (r int32) {
   4655 	bp := tls.Alloc(16)
   4656 	defer tls.Free(16)
   4657 	var alpha_dst, base_rgba, buf uintptr
   4658 	var alpha_mask, alpha_value uint32_t
   4659 	var colorspace, v3 WEBP_CSP_MODE1
   4660 	var i, j, mb_w, start_y, v4 int32
   4661 	var v6 bool
   4662 	var _ /* alpha at bp+0 */ uintptr
   4663 	var _ /* num_rows at bp+8 */ int32
   4664 	_, _, _, _, _, _, _, _, _, _, _, _, _ = alpha_dst, alpha_mask, alpha_value, base_rgba, buf, colorspace, i, j, mb_w, start_y, v3, v4, v6
   4665 	**(**uintptr)(__ccgo_up(bp)) = (*VP8Io)(unsafe.Pointer(io)).Fa
   4666 	if **(**uintptr)(__ccgo_up(bp)) != libc.UintptrFromInt32(0) {
   4667 		mb_w = (*VP8Io)(unsafe.Pointer(io)).Fmb_w
   4668 		colorspace = (*WebPDecBuffer)(unsafe.Pointer((*WebPDecParams)(unsafe.Pointer(p)).Foutput)).Fcolorspace
   4669 		buf = (*WebPDecParams)(unsafe.Pointer(p)).Foutput + 16
   4670 		start_y = GetAlphaSourceRow(tls, io, bp, bp+8)
   4671 		base_rgba = (*WebPRGBABuffer)(unsafe.Pointer(buf)).Frgba + uintptr(int64(start_y)*int64((*WebPRGBABuffer)(unsafe.Pointer(buf)).Fstride))
   4672 		alpha_dst = base_rgba + uintptr(1)
   4673 		alpha_mask = uint32(0x0f)
   4674 		j = 0
   4675 		for {
   4676 			if !(j < **(**int32)(__ccgo_up(bp + 8))) {
   4677 				break
   4678 			}
   4679 			i = 0
   4680 			for {
   4681 				if !(i < mb_w) {
   4682 					break
   4683 				}
   4684 				// Fill in the alpha value (converted to 4 bits).
   4685 				alpha_value = uint32(int32(**(**uint8_t)(__ccgo_up(**(**uintptr)(__ccgo_up(bp)) + uintptr(i)))) >> int32(4))
   4686 				**(**uint8_t)(__ccgo_up(alpha_dst + uintptr(int32(2)*i))) = uint8(uint32(int32(**(**uint8_t)(__ccgo_up(alpha_dst + uintptr(int32(2)*i))))&libc.Int32FromInt32(0xf0)) | alpha_value)
   4687 				alpha_mask = alpha_mask & alpha_value
   4688 				goto _2
   4689 			_2:
   4690 				;
   4691 				i = i + 1
   4692 			}
   4693 			**(**uintptr)(__ccgo_up(bp)) = **(**uintptr)(__ccgo_up(bp)) + uintptr((*VP8Io)(unsafe.Pointer(io)).Fwidth)
   4694 			alpha_dst = alpha_dst + uintptr((*WebPRGBABuffer)(unsafe.Pointer(buf)).Fstride)
   4695 			goto _1
   4696 		_1:
   4697 			;
   4698 			j = j + 1
   4699 		}
   4700 		_ = expected_num_lines_out
   4701 		if v6 = alpha_mask != uint32(0x0f); v6 {
   4702 			v3 = colorspace
   4703 			v4 = libc.BoolInt32(v3 == int32(MODE_rgbA) || v3 == int32(MODE_bgrA) || v3 == int32(MODE_Argb) || v3 == int32(MODE_rgbA_4444))
   4704 			goto _5
   4705 		_5:
   4706 		}
   4707 		if v6 && v4 != 0 {
   4708 			(*(*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)
   4709 		}
   4710 	}
   4711 	return 0
   4712 }
   4713 
   4714 //------------------------------------------------------------------------------
   4715 // YUV rescaling (no final RGB conversion needed)
   4716 
   4717 func Rescale(tls *libc.TLS, src uintptr, src_stride int32, new_lines int32, wrk uintptr) (r int32) {
   4718 	var lines_in, num_lines_out int32
   4719 	_, _ = lines_in, num_lines_out
   4720 	num_lines_out = 0
   4721 	for new_lines > 0 { // import new contributions of source rows.
   4722 		lines_in = WebPRescalerImport(tls, wrk, new_lines, src, src_stride)
   4723 		src = src + uintptr(lines_in*src_stride)
   4724 		new_lines = new_lines - lines_in
   4725 		num_lines_out = num_lines_out + WebPRescalerExport(tls, wrk) // emit output row(s)
   4726 	}
   4727 	return num_lines_out
   4728 }
   4729 
   4730 func EmitRescaledYUV(tls *libc.TLS, io uintptr, p uintptr) (r int32) {
   4731 	var mb_h, num_lines_out, uv_mb_h, v2, v5 int32
   4732 	var scaler uintptr
   4733 	var v1, v4 WEBP_CSP_MODE1
   4734 	var v7 bool
   4735 	_, _, _, _, _, _, _, _, _ = mb_h, num_lines_out, scaler, uv_mb_h, v1, v2, v4, v5, v7
   4736 	mb_h = (*VP8Io)(unsafe.Pointer(io)).Fmb_h
   4737 	uv_mb_h = (mb_h + int32(1)) >> int32(1)
   4738 	scaler = (*WebPDecParams)(unsafe.Pointer(p)).Fscaler_y
   4739 	num_lines_out = 0
   4740 	v1 = (*WebPDecBuffer)(unsafe.Pointer((*WebPDecParams)(unsafe.Pointer(p)).Foutput)).Fcolorspace
   4741 	if v7 = v1 == int32(MODE_RGBA) || v1 == int32(MODE_BGRA) || v1 == int32(MODE_ARGB) || v1 == int32(MODE_RGBA_4444) || v1 == int32(MODE_YUVA); !v7 {
   4742 		v4 = v1
   4743 		v5 = libc.BoolInt32(v4 == int32(MODE_rgbA) || v4 == int32(MODE_bgrA) || v4 == int32(MODE_Argb) || v4 == int32(MODE_rgbA_4444))
   4744 		goto _6
   4745 	_6:
   4746 	}
   4747 	v2 = libc.BoolInt32(v7 || v5 != 0)
   4748 	goto _3
   4749 _3:
   4750 	;
   4751 	if v2 != 0 && (*VP8Io)(unsafe.Pointer(io)).Fa != libc.UintptrFromInt32(0) {
   4752 		// Before rescaling, we premultiply the luma directly into the io->y
   4753 		// internal buffer. This is OK since these samples are not used for
   4754 		// intra-prediction (the top samples are saved in cache_y/u/v).
   4755 		// But we need to cast the const away, though.
   4756 		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)
   4757 	}
   4758 	num_lines_out = Rescale(tls, (*VP8Io)(unsafe.Pointer(io)).Fy, (*VP8Io)(unsafe.Pointer(io)).Fy_stride, mb_h, scaler)
   4759 	Rescale(tls, (*VP8Io)(unsafe.Pointer(io)).Fu, (*VP8Io)(unsafe.Pointer(io)).Fuv_stride, uv_mb_h, (*WebPDecParams)(unsafe.Pointer(p)).Fscaler_u)
   4760 	Rescale(tls, (*VP8Io)(unsafe.Pointer(io)).Fv, (*VP8Io)(unsafe.Pointer(io)).Fuv_stride, uv_mb_h, (*WebPDecParams)(unsafe.Pointer(p)).Fscaler_v)
   4761 	return num_lines_out
   4762 }
   4763 
   4764 func EmitRescaledAlphaYUV(tls *libc.TLS, io uintptr, p uintptr, expected_num_lines_out int32) (r int32) {
   4765 	var buf, dst_a, dst_y uintptr
   4766 	var num_lines_out int32
   4767 	_, _, _, _ = buf, dst_a, dst_y, num_lines_out
   4768 	buf = (*WebPDecParams)(unsafe.Pointer(p)).Foutput + 16
   4769 	dst_a = (*WebPYUVABuffer)(unsafe.Pointer(buf)).Fa + uintptr(int64((*WebPDecParams)(unsafe.Pointer(p)).Flast_y)*int64((*WebPYUVABuffer)(unsafe.Pointer(buf)).Fa_stride))
   4770 	if (*VP8Io)(unsafe.Pointer(io)).Fa != libc.UintptrFromInt32(0) {
   4771 		dst_y = (*WebPYUVABuffer)(unsafe.Pointer(buf)).Fy + uintptr(int64((*WebPDecParams)(unsafe.Pointer(p)).Flast_y)*int64((*WebPYUVABuffer)(unsafe.Pointer(buf)).Fy_stride))
   4772 		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)
   4773 		if num_lines_out > 0 { // unmultiply the Y
   4774 			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))
   4775 		}
   4776 	} else {
   4777 		if (*WebPYUVABuffer)(unsafe.Pointer(buf)).Fa != libc.UintptrFromInt32(0) {
   4778 			// the user requested alpha, but there is none, set it to opaque.
   4779 			FillAlphaPlane(tls, dst_a, (*VP8Io)(unsafe.Pointer(io)).Fscaled_width, expected_num_lines_out, (*WebPYUVABuffer)(unsafe.Pointer(buf)).Fa_stride)
   4780 		}
   4781 	}
   4782 	return 0
   4783 }
   4784 
   4785 func InitYUVRescaler(tls *libc.TLS, io uintptr, p uintptr) (r int32) {
   4786 	var buf, scalers, work, v12 uintptr
   4787 	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
   4788 	var rescaler_size, uv_work_size, work_size size_t
   4789 	var total_size, v9 uint64_t
   4790 	var v1, v4 WEBP_CSP_MODE1
   4791 	var v7 bool
   4792 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
   4793 	v1 = (*WebPDecBuffer)(unsafe.Pointer((*WebPDecParams)(unsafe.Pointer(p)).Foutput)).Fcolorspace
   4794 	if v7 = v1 == int32(MODE_RGBA) || v1 == int32(MODE_BGRA) || v1 == int32(MODE_ARGB) || v1 == int32(MODE_RGBA_4444) || v1 == int32(MODE_YUVA); !v7 {
   4795 		v4 = v1
   4796 		v5 = libc.BoolInt32(v4 == int32(MODE_rgbA) || v4 == int32(MODE_bgrA) || v4 == int32(MODE_Argb) || v4 == int32(MODE_rgbA_4444))
   4797 		goto _6
   4798 	_6:
   4799 	}
   4800 	v2 = libc.BoolInt32(v7 || v5 != 0)
   4801 	goto _3
   4802 _3:
   4803 	has_alpha = v2
   4804 	buf = (*WebPDecParams)(unsafe.Pointer(p)).Foutput + 16
   4805 	out_width = (*VP8Io)(unsafe.Pointer(io)).Fscaled_width
   4806 	out_height = (*VP8Io)(unsafe.Pointer(io)).Fscaled_height
   4807 	uv_out_width = (out_width + int32(1)) >> int32(1)
   4808 	uv_out_height = (out_height + int32(1)) >> int32(1)
   4809 	uv_in_width = ((*VP8Io)(unsafe.Pointer(io)).Fmb_w + int32(1)) >> int32(1)
   4810 	uv_in_height = ((*VP8Io)(unsafe.Pointer(io)).Fmb_h + int32(1)) >> int32(1)
   4811 	// scratch memory for luma rescaler
   4812 	work_size = uint64(2) * uint64(out_width)
   4813 	uv_work_size = uint64(int32(2) * uv_out_width)
   4814 	if has_alpha != 0 {
   4815 		v8 = int32(4)
   4816 	} else {
   4817 		v8 = int32(3)
   4818 	}
   4819 	num_rescalers = v8
   4820 	total_size = (work_size + uint64(2)*uv_work_size) * uint64(4)
   4821 	if has_alpha != 0 {
   4822 		total_size = total_size + work_size*uint64(4)
   4823 	}
   4824 	rescaler_size = uint64(num_rescalers)*uint64(104) + uint64(WEBP_ALIGN_CST)
   4825 	total_size = total_size + rescaler_size
   4826 	v9 = total_size
   4827 	v2 = libc.BoolInt32(v9 == v9)
   4828 	goto _11
   4829 _11:
   4830 	if !(v2 != 0) {
   4831 		return 0
   4832 	}
   4833 	(*WebPDecParams)(unsafe.Pointer(p)).Fmemory = WebPSafeMalloc(tls, uint64(1), total_size)
   4834 	if (*WebPDecParams)(unsafe.Pointer(p)).Fmemory == libc.UintptrFromInt32(0) {
   4835 		return 0 // memory error
   4836 	}
   4837 	work = (*WebPDecParams)(unsafe.Pointer(p)).Fmemory
   4838 	scalers = uintptr((uint64(work+uintptr(total_size)-uintptr(rescaler_size)) + libc.Uint64FromInt32(WEBP_ALIGN_CST)) & ^libc.Uint64FromInt32(WEBP_ALIGN_CST))
   4839 	(*WebPDecParams)(unsafe.Pointer(p)).Fscaler_y = scalers
   4840 	(*WebPDecParams)(unsafe.Pointer(p)).Fscaler_u = scalers + 1*104
   4841 	(*WebPDecParams)(unsafe.Pointer(p)).Fscaler_v = scalers + 2*104
   4842 	if has_alpha != 0 {
   4843 		v12 = scalers + 3*104
   4844 	} else {
   4845 		v12 = libc.UintptrFromInt32(0)
   4846 	}
   4847 	(*WebPDecParams)(unsafe.Pointer(p)).Fscaler_a = v12
   4848 	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) {
   4849 		return 0
   4850 	}
   4851 	(*WebPDecParams)(unsafe.Pointer(p)).Femit = __ccgo_fp(EmitRescaledYUV)
   4852 	if has_alpha != 0 {
   4853 		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) {
   4854 			return 0
   4855 		}
   4856 		(*WebPDecParams)(unsafe.Pointer(p)).Femit_alpha = __ccgo_fp(EmitRescaledAlphaYUV)
   4857 		WebPInitAlphaProcessing(tls)
   4858 	}
   4859 	return int32(1)
   4860 }
   4861 
   4862 //------------------------------------------------------------------------------
   4863 // RGBA rescaling
   4864 
   4865 func ExportRGB(tls *libc.TLS, p uintptr, y_pos int32) (r int32) {
   4866 	var buf, dst, v1, v10, v4, v7 uintptr
   4867 	var convert WebPYUV444Converter
   4868 	var num_lines_out, v11, v2, v5, v8 int32
   4869 	var v13 bool
   4870 	_, _, _, _, _, _, _, _, _, _, _, _, _ = buf, convert, dst, num_lines_out, v1, v10, v11, v13, v2, v4, v5, v7, v8
   4871 	convert = WebPYUV444Converters[(*WebPDecBuffer)(unsafe.Pointer((*WebPDecParams)(unsafe.Pointer(p)).Foutput)).Fcolorspace]
   4872 	buf = (*WebPDecParams)(unsafe.Pointer(p)).Foutput + 16
   4873 	dst = (*WebPRGBABuffer)(unsafe.Pointer(buf)).Frgba + uintptr(int64(y_pos)*int64((*WebPRGBABuffer)(unsafe.Pointer(buf)).Fstride))
   4874 	num_lines_out = 0
   4875 	// For RGB rescaling, because of the YUV420, current scan position
   4876 	// U/V can be +1/-1 line from the Y one.  Hence the double test.
   4877 	for {
   4878 		v1 = (*WebPDecParams)(unsafe.Pointer(p)).Fscaler_y
   4879 		v4 = v1
   4880 		v5 = libc.BoolInt32((*WebPRescaler)(unsafe.Pointer(v4)).Fdst_y >= (*WebPRescaler)(unsafe.Pointer(v4)).Fdst_height)
   4881 		goto _6
   4882 	_6:
   4883 		;
   4884 		v2 = libc.BoolInt32(!(v5 != 0) && (*WebPRescaler)(unsafe.Pointer(v1)).Fy_accum <= 0)
   4885 		goto _3
   4886 	_3:
   4887 		;
   4888 		if v13 = v2 != 0; v13 {
   4889 			v7 = (*WebPDecParams)(unsafe.Pointer(p)).Fscaler_u
   4890 			v10 = v7
   4891 			v11 = libc.BoolInt32((*WebPRescaler)(unsafe.Pointer(v10)).Fdst_y >= (*WebPRescaler)(unsafe.Pointer(v10)).Fdst_height)
   4892 			goto _12
   4893 		_12:
   4894 			;
   4895 			v8 = libc.BoolInt32(!(v11 != 0) && (*WebPRescaler)(unsafe.Pointer(v7)).Fy_accum <= 0)
   4896 			goto _9
   4897 		_9:
   4898 		}
   4899 		if !(v13 && v8 != 0) {
   4900 			break
   4901 		}
   4902 		WebPRescalerExportRow(tls, (*WebPDecParams)(unsafe.Pointer(p)).Fscaler_y)
   4903 		WebPRescalerExportRow(tls, (*WebPDecParams)(unsafe.Pointer(p)).Fscaler_u)
   4904 		WebPRescalerExportRow(tls, (*WebPDecParams)(unsafe.Pointer(p)).Fscaler_v)
   4905 		(*(*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)
   4906 		dst = dst + uintptr((*WebPRGBABuffer)(unsafe.Pointer(buf)).Fstride)
   4907 		num_lines_out = num_lines_out + 1
   4908 	}
   4909 	return num_lines_out
   4910 }
   4911 
   4912 func EmitRescaledRGB(tls *libc.TLS, io uintptr, p uintptr) (r int32) {
   4913 	var j, mb_h, num_lines_out, u_lines_in, uv_j, uv_mb_h, v_lines_in, y_lines_in int32
   4914 	_, _, _, _, _, _, _, _ = j, mb_h, num_lines_out, u_lines_in, uv_j, uv_mb_h, v_lines_in, y_lines_in
   4915 	mb_h = (*VP8Io)(unsafe.Pointer(io)).Fmb_h
   4916 	uv_mb_h = (mb_h + int32(1)) >> int32(1)
   4917 	j = 0
   4918 	uv_j = 0
   4919 	num_lines_out = 0
   4920 	for j < mb_h {
   4921 		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)
   4922 		j = j + y_lines_in
   4923 		if WebPRescaleNeededLines(tls, (*WebPDecParams)(unsafe.Pointer(p)).Fscaler_u, uv_mb_h-uv_j) != 0 {
   4924 			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)
   4925 			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)
   4926 			_ = v_lines_in // remove a gcc warning
   4927 			uv_j = uv_j + u_lines_in
   4928 		}
   4929 		num_lines_out = num_lines_out + ExportRGB(tls, p, (*WebPDecParams)(unsafe.Pointer(p)).Flast_y+num_lines_out)
   4930 	}
   4931 	return num_lines_out
   4932 }
   4933 
   4934 func ExportAlpha(tls *libc.TLS, p uintptr, y_pos int32, max_lines_out int32) (r int32) {
   4935 	var alpha_first, is_premult_alpha, num_lines_out, width, v1, v3, v6, v9 int32
   4936 	var base_rgba, buf, dst, v5, v8 uintptr
   4937 	var colorspace, v2 WEBP_CSP_MODE1
   4938 	var non_opaque uint32_t
   4939 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = alpha_first, base_rgba, buf, colorspace, dst, is_premult_alpha, non_opaque, num_lines_out, width, v1, v2, v3, v5, v6, v8, v9
   4940 	buf = (*WebPDecParams)(unsafe.Pointer(p)).Foutput + 16
   4941 	base_rgba = (*WebPRGBABuffer)(unsafe.Pointer(buf)).Frgba + uintptr(int64(y_pos)*int64((*WebPRGBABuffer)(unsafe.Pointer(buf)).Fstride))
   4942 	colorspace = (*WebPDecBuffer)(unsafe.Pointer((*WebPDecParams)(unsafe.Pointer(p)).Foutput)).Fcolorspace
   4943 	alpha_first = libc.BoolInt32(colorspace == int32(MODE_ARGB) || colorspace == int32(MODE_Argb))
   4944 	if alpha_first != 0 {
   4945 		v1 = 0
   4946 	} else {
   4947 		v1 = int32(3)
   4948 	}
   4949 	dst = base_rgba + uintptr(v1)
   4950 	num_lines_out = 0
   4951 	v2 = colorspace
   4952 	v3 = libc.BoolInt32(v2 == int32(MODE_rgbA) || v2 == int32(MODE_bgrA) || v2 == int32(MODE_Argb) || v2 == int32(MODE_rgbA_4444))
   4953 	goto _4
   4954 _4:
   4955 	is_premult_alpha = v3
   4956 	non_opaque = uint32(0)
   4957 	width = (*WebPRescaler)(unsafe.Pointer((*WebPDecParams)(unsafe.Pointer(p)).Fscaler_a)).Fdst_width
   4958 	for {
   4959 		v5 = (*WebPDecParams)(unsafe.Pointer(p)).Fscaler_a
   4960 		v8 = v5
   4961 		v9 = libc.BoolInt32((*WebPRescaler)(unsafe.Pointer(v8)).Fdst_y >= (*WebPRescaler)(unsafe.Pointer(v8)).Fdst_height)
   4962 		goto _10
   4963 	_10:
   4964 		;
   4965 		v6 = libc.BoolInt32(!(v9 != 0) && (*WebPRescaler)(unsafe.Pointer(v5)).Fy_accum <= 0)
   4966 		goto _7
   4967 	_7:
   4968 		;
   4969 		if !(v6 != 0 && num_lines_out < max_lines_out) {
   4970 			break
   4971 		}
   4972 		WebPRescalerExportRow(tls, (*WebPDecParams)(unsafe.Pointer(p)).Fscaler_a)
   4973 		non_opaque = non_opaque | uint32((*(*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))
   4974 		dst = dst + uintptr((*WebPRGBABuffer)(unsafe.Pointer(buf)).Fstride)
   4975 		num_lines_out = num_lines_out + 1
   4976 	}
   4977 	if is_premult_alpha != 0 && non_opaque != 0 {
   4978 		(*(*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)
   4979 	}
   4980 	return num_lines_out
   4981 }
   4982 
   4983 func ExportAlphaRGBA4444(tls *libc.TLS, p uintptr, y_pos int32, max_lines_out int32) (r int32) {
   4984 	var alpha_dst, base_rgba, buf, v4, v7 uintptr
   4985 	var alpha_mask, alpha_value uint32_t
   4986 	var colorspace, v1 WEBP_CSP_MODE1
   4987 	var i, is_premult_alpha, num_lines_out, width, v2, v5, v8 int32
   4988 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = alpha_dst, alpha_mask, alpha_value, base_rgba, buf, colorspace, i, is_premult_alpha, num_lines_out, width, v1, v2, v4, v5, v7, v8
   4989 	buf = (*WebPDecParams)(unsafe.Pointer(p)).Foutput + 16
   4990 	base_rgba = (*WebPRGBABuffer)(unsafe.Pointer(buf)).Frgba + uintptr(int64(y_pos)*int64((*WebPRGBABuffer)(unsafe.Pointer(buf)).Fstride))
   4991 	alpha_dst = base_rgba + uintptr(1)
   4992 	num_lines_out = 0
   4993 	colorspace = (*WebPDecBuffer)(unsafe.Pointer((*WebPDecParams)(unsafe.Pointer(p)).Foutput)).Fcolorspace
   4994 	width = (*WebPRescaler)(unsafe.Pointer((*WebPDecParams)(unsafe.Pointer(p)).Fscaler_a)).Fdst_width
   4995 	v1 = colorspace
   4996 	v2 = libc.BoolInt32(v1 == int32(MODE_rgbA) || v1 == int32(MODE_bgrA) || v1 == int32(MODE_Argb) || v1 == int32(MODE_rgbA_4444))
   4997 	goto _3
   4998 _3:
   4999 	is_premult_alpha = v2
   5000 	alpha_mask = uint32(0x0f)
   5001 	for {
   5002 		v4 = (*WebPDecParams)(unsafe.Pointer(p)).Fscaler_a
   5003 		v7 = v4
   5004 		v8 = libc.BoolInt32((*WebPRescaler)(unsafe.Pointer(v7)).Fdst_y >= (*WebPRescaler)(unsafe.Pointer(v7)).Fdst_height)
   5005 		goto _9
   5006 	_9:
   5007 		;
   5008 		v5 = libc.BoolInt32(!(v8 != 0) && (*WebPRescaler)(unsafe.Pointer(v4)).Fy_accum <= 0)
   5009 		goto _6
   5010 	_6:
   5011 		;
   5012 		if !(v5 != 0 && num_lines_out < max_lines_out) {
   5013 			break
   5014 		}
   5015 		WebPRescalerExportRow(tls, (*WebPDecParams)(unsafe.Pointer(p)).Fscaler_a)
   5016 		i = 0
   5017 		for {
   5018 			if !(i < width) {
   5019 				break
   5020 			}
   5021 			// Fill in the alpha value (converted to 4 bits).
   5022 			alpha_value = uint32(int32(**(**uint8_t)(__ccgo_up((*WebPRescaler)(unsafe.Pointer((*WebPDecParams)(unsafe.Pointer(p)).Fscaler_a)).Fdst + uintptr(i)))) >> int32(4))
   5023 			**(**uint8_t)(__ccgo_up(alpha_dst + uintptr(int32(2)*i))) = uint8(uint32(int32(**(**uint8_t)(__ccgo_up(alpha_dst + uintptr(int32(2)*i))))&libc.Int32FromInt32(0xf0)) | alpha_value)
   5024 			alpha_mask = alpha_mask & alpha_value
   5025 			goto _10
   5026 		_10:
   5027 			;
   5028 			i = i + 1
   5029 		}
   5030 		alpha_dst = alpha_dst + uintptr((*WebPRGBABuffer)(unsafe.Pointer(buf)).Fstride)
   5031 		num_lines_out = num_lines_out + 1
   5032 	}
   5033 	if is_premult_alpha != 0 && alpha_mask != uint32(0x0f) {
   5034 		(*(*func(*libc.TLS, uintptr, int32, int32, int32))(unsafe.Pointer(&struct{ uintptr }{WebPApplyAlphaMultiply4444})))(tls, base_rgba, width, num_lines_out, (*WebPRGBABuffer)(unsafe.Pointer(buf)).Fstride)
   5035 	}
   5036 	return num_lines_out
   5037 }
   5038 
   5039 func EmitRescaledAlphaRGB(tls *libc.TLS, io uintptr, p uintptr, expected_num_out_lines int32) (r int32) {
   5040 	var lines_left, y_end int32
   5041 	var row_offset int64_t
   5042 	var scaler uintptr
   5043 	_, _, _, _ = lines_left, row_offset, scaler, y_end
   5044 	if (*VP8Io)(unsafe.Pointer(io)).Fa != libc.UintptrFromInt32(0) {
   5045 		scaler = (*WebPDecParams)(unsafe.Pointer(p)).Fscaler_a
   5046 		lines_left = expected_num_out_lines
   5047 		y_end = (*WebPDecParams)(unsafe.Pointer(p)).Flast_y + lines_left
   5048 		for lines_left > 0 {
   5049 			row_offset = int64((*WebPRescaler)(unsafe.Pointer(scaler)).Fsrc_y) - int64((*VP8Io)(unsafe.Pointer(io)).Fmb_y)
   5050 			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)
   5051 			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)
   5052 		}
   5053 	}
   5054 	return 0
   5055 }
   5056 
   5057 func InitRGBRescaler(tls *libc.TLS, io uintptr, p uintptr) (r int32) {
   5058 	var has_alpha, num_rescalers, out_height, out_width, uv_in_height, uv_in_width, v2, v5, v8 int32
   5059 	var rescaler_size, work_size size_t
   5060 	var scalers, tmp, work, v12 uintptr
   5061 	var tmp_size1, tmp_size2, total_size, v9 uint64_t
   5062 	var v1, v4 WEBP_CSP_MODE1
   5063 	var v7 bool
   5064 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
   5065 	v1 = (*WebPDecBuffer)(unsafe.Pointer((*WebPDecParams)(unsafe.Pointer(p)).Foutput)).Fcolorspace
   5066 	if v7 = v1 == int32(MODE_RGBA) || v1 == int32(MODE_BGRA) || v1 == int32(MODE_ARGB) || v1 == int32(MODE_RGBA_4444) || v1 == int32(MODE_YUVA); !v7 {
   5067 		v4 = v1
   5068 		v5 = libc.BoolInt32(v4 == int32(MODE_rgbA) || v4 == int32(MODE_bgrA) || v4 == int32(MODE_Argb) || v4 == int32(MODE_rgbA_4444))
   5069 		goto _6
   5070 	_6:
   5071 	}
   5072 	v2 = libc.BoolInt32(v7 || v5 != 0)
   5073 	goto _3
   5074 _3:
   5075 	has_alpha = v2
   5076 	out_width = (*VP8Io)(unsafe.Pointer(io)).Fscaled_width
   5077 	out_height = (*VP8Io)(unsafe.Pointer(io)).Fscaled_height
   5078 	uv_in_width = ((*VP8Io)(unsafe.Pointer(io)).Fmb_w + int32(1)) >> int32(1)
   5079 	uv_in_height = ((*VP8Io)(unsafe.Pointer(io)).Fmb_h + int32(1)) >> int32(1)
   5080 	// scratch memory for one rescaler
   5081 	work_size = uint64(2) * uint64(out_width)
   5082 	if has_alpha != 0 {
   5083 		v8 = int32(4)
   5084 	} else {
   5085 		v8 = int32(3)
   5086 	}
   5087 	num_rescalers = v8
   5088 	tmp_size1 = uint64(num_rescalers) * work_size
   5089 	tmp_size2 = uint64(num_rescalers) * uint64(out_width)
   5090 	total_size = tmp_size1*uint64(4) + tmp_size2*uint64(1)
   5091 	rescaler_size = uint64(num_rescalers)*uint64(104) + uint64(WEBP_ALIGN_CST)
   5092 	total_size = total_size + rescaler_size
   5093 	v9 = total_size
   5094 	v2 = libc.BoolInt32(v9 == v9)
   5095 	goto _11
   5096 _11:
   5097 	if !(v2 != 0) {
   5098 		return 0
   5099 	}
   5100 	(*WebPDecParams)(unsafe.Pointer(p)).Fmemory = WebPSafeMalloc(tls, uint64(1), total_size)
   5101 	if (*WebPDecParams)(unsafe.Pointer(p)).Fmemory == libc.UintptrFromInt32(0) {
   5102 		return 0 // memory error
   5103 	}
   5104 	work = (*WebPDecParams)(unsafe.Pointer(p)).Fmemory
   5105 	tmp = work + uintptr(tmp_size1)*4
   5106 	scalers = uintptr((uint64(work+uintptr(total_size)-uintptr(rescaler_size)) + libc.Uint64FromInt32(WEBP_ALIGN_CST)) & ^libc.Uint64FromInt32(WEBP_ALIGN_CST))
   5107 	(*WebPDecParams)(unsafe.Pointer(p)).Fscaler_y = scalers
   5108 	(*WebPDecParams)(unsafe.Pointer(p)).Fscaler_u = scalers + 1*104
   5109 	(*WebPDecParams)(unsafe.Pointer(p)).Fscaler_v = scalers + 2*104
   5110 	if has_alpha != 0 {
   5111 		v12 = scalers + 3*104
   5112 	} else {
   5113 		v12 = libc.UintptrFromInt32(0)
   5114 	}
   5115 	(*WebPDecParams)(unsafe.Pointer(p)).Fscaler_a = v12
   5116 	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) {
   5117 		return 0
   5118 	}
   5119 	(*WebPDecParams)(unsafe.Pointer(p)).Femit = __ccgo_fp(EmitRescaledRGB)
   5120 	WebPInitYUV444Converters(tls)
   5121 	if has_alpha != 0 {
   5122 		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) {
   5123 			return 0
   5124 		}
   5125 		(*WebPDecParams)(unsafe.Pointer(p)).Femit_alpha = __ccgo_fp(EmitRescaledAlphaRGB)
   5126 		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) {
   5127 			(*WebPDecParams)(unsafe.Pointer(p)).Femit_alpha_row = __ccgo_fp(ExportAlphaRGBA4444)
   5128 		} else {
   5129 			(*WebPDecParams)(unsafe.Pointer(p)).Femit_alpha_row = __ccgo_fp(ExportAlpha)
   5130 		}
   5131 		WebPInitAlphaProcessing(tls)
   5132 	}
   5133 	return int32(1)
   5134 }
   5135 
   5136 //------------------------------------------------------------------------------
   5137 // Default custom functions
   5138 
   5139 func CustomSetup(tls *libc.TLS, io uintptr) (r int32) {
   5140 	var colorspace, v3, v6 WEBP_CSP_MODE1
   5141 	var is_alpha, is_rgb, ok, uv_width, v1, v4, v7 int32
   5142 	var p, v16, v17 uintptr
   5143 	var v9 bool
   5144 	_, _, _, _, _, _, _, _, _, _, _, _, _, _ = colorspace, is_alpha, is_rgb, ok, p, uv_width, v1, v16, v17, v3, v4, v6, v7, v9
   5145 	p = (*VP8Io)(unsafe.Pointer(io)).Fopaque
   5146 	colorspace = (*WebPDecBuffer)(unsafe.Pointer((*WebPDecParams)(unsafe.Pointer(p)).Foutput)).Fcolorspace
   5147 	v1 = libc.BoolInt32(colorspace < int32(MODE_YUV))
   5148 	goto _2
   5149 _2:
   5150 	is_rgb = v1
   5151 	v3 = colorspace
   5152 	if v9 = v3 == int32(MODE_RGBA) || v3 == int32(MODE_BGRA) || v3 == int32(MODE_ARGB) || v3 == int32(MODE_RGBA_4444) || v3 == int32(MODE_YUVA); !v9 {
   5153 		v6 = v3
   5154 		v7 = libc.BoolInt32(v6 == int32(MODE_rgbA) || v6 == int32(MODE_bgrA) || v6 == int32(MODE_Argb) || v6 == int32(MODE_rgbA_4444))
   5155 		goto _8
   5156 	_8:
   5157 	}
   5158 	v4 = libc.BoolInt32(v9 || v7 != 0)
   5159 	goto _5
   5160 _5:
   5161 	is_alpha = v4
   5162 	(*WebPDecParams)(unsafe.Pointer(p)).Fmemory = libc.UintptrFromInt32(0)
   5163 	(*WebPDecParams)(unsafe.Pointer(p)).Femit = libc.UintptrFromInt32(0)
   5164 	(*WebPDecParams)(unsafe.Pointer(p)).Femit_alpha = libc.UintptrFromInt32(0)
   5165 	(*WebPDecParams)(unsafe.Pointer(p)).Femit_alpha_row = libc.UintptrFromInt32(0)
   5166 	if is_alpha != 0 {
   5167 		v1 = int32(MODE_YUV)
   5168 	} else {
   5169 		v1 = int32(MODE_YUVA)
   5170 	}
   5171 	if !(WebPIoInitFromOptions(tls, (*WebPDecParams)(unsafe.Pointer(p)).Foptions, io, v1) != 0) {
   5172 		return 0
   5173 	}
   5174 	if v9 = is_alpha != 0; v9 {
   5175 		v3 = colorspace
   5176 		v1 = libc.BoolInt32(v3 == int32(MODE_rgbA) || v3 == int32(MODE_bgrA) || v3 == int32(MODE_Argb) || v3 == int32(MODE_rgbA_4444))
   5177 		goto _13
   5178 	_13:
   5179 	}
   5180 	if v9 && v1 != 0 {
   5181 		WebPInitUpsamplers(tls)
   5182 	}
   5183 	if (*VP8Io)(unsafe.Pointer(io)).Fuse_scaling != 0 {
   5184 		if is_rgb != 0 {
   5185 			v1 = InitRGBRescaler(tls, io, p)
   5186 		} else {
   5187 			v1 = InitYUVRescaler(tls, io, p)
   5188 		}
   5189 		ok = v1
   5190 		if !(ok != 0) {
   5191 			return 0 // memory error
   5192 		}
   5193 	} else {
   5194 		if is_rgb != 0 {
   5195 			WebPInitSamplers(tls)
   5196 			(*WebPDecParams)(unsafe.Pointer(p)).Femit = __ccgo_fp(EmitSampledRGB) // default
   5197 			if (*VP8Io)(unsafe.Pointer(io)).Ffancy_upsampling != 0 {
   5198 				uv_width = ((*VP8Io)(unsafe.Pointer(io)).Fmb_w + int32(1)) >> int32(1)
   5199 				(*WebPDecParams)(unsafe.Pointer(p)).Fmemory = WebPSafeMalloc(tls, uint64(1), uint64((*VP8Io)(unsafe.Pointer(io)).Fmb_w+libc.Int32FromInt32(2)*uv_width))
   5200 				if (*WebPDecParams)(unsafe.Pointer(p)).Fmemory == libc.UintptrFromInt32(0) {
   5201 					return 0 // memory error.
   5202 				}
   5203 				(*WebPDecParams)(unsafe.Pointer(p)).Ftmp_y = (*WebPDecParams)(unsafe.Pointer(p)).Fmemory
   5204 				(*WebPDecParams)(unsafe.Pointer(p)).Ftmp_u = (*WebPDecParams)(unsafe.Pointer(p)).Ftmp_y + uintptr((*VP8Io)(unsafe.Pointer(io)).Fmb_w)
   5205 				(*WebPDecParams)(unsafe.Pointer(p)).Ftmp_v = (*WebPDecParams)(unsafe.Pointer(p)).Ftmp_u + uintptr(uv_width)
   5206 				(*WebPDecParams)(unsafe.Pointer(p)).Femit = __ccgo_fp(EmitFancyRGB)
   5207 				WebPInitUpsamplers(tls)
   5208 			}
   5209 		} else {
   5210 			(*WebPDecParams)(unsafe.Pointer(p)).Femit = __ccgo_fp(EmitYUV)
   5211 		}
   5212 		if is_alpha != 0 { // need transparency output
   5213 			if colorspace == int32(MODE_RGBA_4444) || colorspace == int32(MODE_rgbA_4444) {
   5214 				v16 = __ccgo_fp(EmitAlphaRGBA4444)
   5215 			} else {
   5216 				if is_rgb != 0 {
   5217 					v17 = __ccgo_fp(EmitAlphaRGB)
   5218 				} else {
   5219 					v17 = __ccgo_fp(EmitAlphaYUV)
   5220 				}
   5221 				v16 = v17
   5222 			}
   5223 			(*WebPDecParams)(unsafe.Pointer(p)).Femit_alpha = v16
   5224 			if is_rgb != 0 {
   5225 				WebPInitAlphaProcessing(tls)
   5226 			}
   5227 		}
   5228 	}
   5229 	return int32(1)
   5230 }
   5231 
   5232 //------------------------------------------------------------------------------
   5233 
   5234 func CustomPut(tls *libc.TLS, io uintptr) (r int32) {
   5235 	var mb_h, mb_w, num_lines_out int32
   5236 	var p uintptr
   5237 	_, _, _, _ = mb_h, mb_w, num_lines_out, p
   5238 	p = (*VP8Io)(unsafe.Pointer(io)).Fopaque
   5239 	mb_w = (*VP8Io)(unsafe.Pointer(io)).Fmb_w
   5240 	mb_h = (*VP8Io)(unsafe.Pointer(io)).Fmb_h
   5241 	if mb_w <= 0 || mb_h <= 0 {
   5242 		return 0
   5243 	}
   5244 	num_lines_out = (*(*func(*libc.TLS, uintptr, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*WebPDecParams)(unsafe.Pointer(p)).Femit})))(tls, io, p)
   5245 	if (*WebPDecParams)(unsafe.Pointer(p)).Femit_alpha != libc.UintptrFromInt32(0) {
   5246 		(*(*func(*libc.TLS, uintptr, uintptr, int32) int32)(unsafe.Pointer(&struct{ uintptr }{(*WebPDecParams)(unsafe.Pointer(p)).Femit_alpha})))(tls, io, p, num_lines_out)
   5247 	}
   5248 	**(**int32)(__ccgo_up(p + 32)) += num_lines_out
   5249 	return int32(1)
   5250 }
   5251 
   5252 //------------------------------------------------------------------------------
   5253 
   5254 func CustomTeardown(tls *libc.TLS, io uintptr) {
   5255 	var p uintptr
   5256 	_ = p
   5257 	p = (*VP8Io)(unsafe.Pointer(io)).Fopaque
   5258 	WebPSafeFree(tls, (*WebPDecParams)(unsafe.Pointer(p)).Fmemory)
   5259 	(*WebPDecParams)(unsafe.Pointer(p)).Fmemory = libc.UintptrFromInt32(0)
   5260 }
   5261 
   5262 //------------------------------------------------------------------------------
   5263 // Main entry point
   5264 
   5265 func WebPInitCustomIo(tls *libc.TLS, params uintptr, io uintptr) {
   5266 	(*VP8Io)(unsafe.Pointer(io)).Fput = __ccgo_fp(CustomPut)
   5267 	(*VP8Io)(unsafe.Pointer(io)).Fsetup = __ccgo_fp(CustomSetup)
   5268 	(*VP8Io)(unsafe.Pointer(io)).Fteardown = __ccgo_fp(CustomTeardown)
   5269 	(*VP8Io)(unsafe.Pointer(io)).Fopaque = params
   5270 }
   5271 
   5272 const SIZE_MAX1 = "UINT64_MAX"
   5273 
   5274 var kHashMul5 = uint32(0x1e35a7bd)
   5275 
   5276 //------------------------------------------------------------------------------
   5277 
   5278 // Copyright 2010 Google Inc. All Rights Reserved.
   5279 //
   5280 // Use of this source code is governed by a BSD-style license
   5281 // that can be found in the COPYING file in the root of the source
   5282 // tree. An additional intellectual property rights grant can be found
   5283 // in the file PATENTS. All contributing project authors may
   5284 // be found in the AUTHORS file in the root of the source tree.
   5285 // -----------------------------------------------------------------------------
   5286 //
   5287 // Boolean decoder
   5288 //
   5289 // Author: Skal (pascal.massimino@gmail.com)
   5290 //         Vikas Arora (vikaas.arora@gmail.com)
   5291 
   5292 // Copyright 2010 Google Inc. All Rights Reserved.
   5293 //
   5294 // Use of this source code is governed by a BSD-style license
   5295 // that can be found in the COPYING file in the root of the source
   5296 // tree. An additional intellectual property rights grant can be found
   5297 // in the file PATENTS. All contributing project authors may
   5298 // be found in the AUTHORS file in the root of the source tree.
   5299 // -----------------------------------------------------------------------------
   5300 //
   5301 //  Common types + memory wrappers
   5302 //
   5303 // Author: Skal (pascal.massimino@gmail.com)
   5304 
   5305 func clip(tls *libc.TLS, v int32, M int32) (r int32) {
   5306 	var v1, v2 int32
   5307 	_, _ = v1, v2
   5308 	if v < 0 {
   5309 		v1 = 0
   5310 	} else {
   5311 		if v > M {
   5312 			v2 = M
   5313 		} else {
   5314 			v2 = v
   5315 		}
   5316 		v1 = v2
   5317 	}
   5318 	return v1
   5319 }
   5320 
   5321 // C documentation
   5322 //
   5323 //	// Paragraph 14.1
   5324 var kDcTable = [128]uint8_t{
   5325 	0:   uint8(4),
   5326 	1:   uint8(5),
   5327 	2:   uint8(6),
   5328 	3:   uint8(7),
   5329 	4:   uint8(8),
   5330 	5:   uint8(9),
   5331 	6:   uint8(10),
   5332 	7:   uint8(10),
   5333 	8:   uint8(11),
   5334 	9:   uint8(12),
   5335 	10:  uint8(13),
   5336 	11:  uint8(14),
   5337 	12:  uint8(15),
   5338 	13:  uint8(16),
   5339 	14:  uint8(17),
   5340 	15:  uint8(17),
   5341 	16:  uint8(18),
   5342 	17:  uint8(19),
   5343 	18:  uint8(20),
   5344 	19:  uint8(20),
   5345 	20:  uint8(21),
   5346 	21:  uint8(21),
   5347 	22:  uint8(22),
   5348 	23:  uint8(22),
   5349 	24:  uint8(23),
   5350 	25:  uint8(23),
   5351 	26:  uint8(24),
   5352 	27:  uint8(25),
   5353 	28:  uint8(25),
   5354 	29:  uint8(26),
   5355 	30:  uint8(27),
   5356 	31:  uint8(28),
   5357 	32:  uint8(29),
   5358 	33:  uint8(30),
   5359 	34:  uint8(31),
   5360 	35:  uint8(32),
   5361 	36:  uint8(33),
   5362 	37:  uint8(34),
   5363 	38:  uint8(35),
   5364 	39:  uint8(36),
   5365 	40:  uint8(37),
   5366 	41:  uint8(37),
   5367 	42:  uint8(38),
   5368 	43:  uint8(39),
   5369 	44:  uint8(40),
   5370 	45:  uint8(41),
   5371 	46:  uint8(42),
   5372 	47:  uint8(43),
   5373 	48:  uint8(44),
   5374 	49:  uint8(45),
   5375 	50:  uint8(46),
   5376 	51:  uint8(46),
   5377 	52:  uint8(47),
   5378 	53:  uint8(48),
   5379 	54:  uint8(49),
   5380 	55:  uint8(50),
   5381 	56:  uint8(51),
   5382 	57:  uint8(52),
   5383 	58:  uint8(53),
   5384 	59:  uint8(54),
   5385 	60:  uint8(55),
   5386 	61:  uint8(56),
   5387 	62:  uint8(57),
   5388 	63:  uint8(58),
   5389 	64:  uint8(59),
   5390 	65:  uint8(60),
   5391 	66:  uint8(61),
   5392 	67:  uint8(62),
   5393 	68:  uint8(63),
   5394 	69:  uint8(64),
   5395 	70:  uint8(65),
   5396 	71:  uint8(66),
   5397 	72:  uint8(67),
   5398 	73:  uint8(68),
   5399 	74:  uint8(69),
   5400 	75:  uint8(70),
   5401 	76:  uint8(71),
   5402 	77:  uint8(72),
   5403 	78:  uint8(73),
   5404 	79:  uint8(74),
   5405 	80:  uint8(75),
   5406 	81:  uint8(76),
   5407 	82:  uint8(76),
   5408 	83:  uint8(77),
   5409 	84:  uint8(78),
   5410 	85:  uint8(79),
   5411 	86:  uint8(80),
   5412 	87:  uint8(81),
   5413 	88:  uint8(82),
   5414 	89:  uint8(83),
   5415 	90:  uint8(84),
   5416 	91:  uint8(85),
   5417 	92:  uint8(86),
   5418 	93:  uint8(87),
   5419 	94:  uint8(88),
   5420 	95:  uint8(89),
   5421 	96:  uint8(91),
   5422 	97:  uint8(93),
   5423 	98:  uint8(95),
   5424 	99:  uint8(96),
   5425 	100: uint8(98),
   5426 	101: uint8(100),
   5427 	102: uint8(101),
   5428 	103: uint8(102),
   5429 	104: uint8(104),
   5430 	105: uint8(106),
   5431 	106: uint8(108),
   5432 	107: uint8(110),
   5433 	108: uint8(112),
   5434 	109: uint8(114),
   5435 	110: uint8(116),
   5436 	111: uint8(118),
   5437 	112: uint8(122),
   5438 	113: uint8(124),
   5439 	114: uint8(126),
   5440 	115: uint8(128),
   5441 	116: uint8(130),
   5442 	117: uint8(132),
   5443 	118: uint8(134),
   5444 	119: uint8(136),
   5445 	120: uint8(138),
   5446 	121: uint8(140),
   5447 	122: uint8(143),
   5448 	123: uint8(145),
   5449 	124: uint8(148),
   5450 	125: uint8(151),
   5451 	126: uint8(154),
   5452 	127: uint8(157),
   5453 }
   5454 
   5455 var kAcTable = [128]uint16_t{
   5456 	0:   uint16(4),
   5457 	1:   uint16(5),
   5458 	2:   uint16(6),
   5459 	3:   uint16(7),
   5460 	4:   uint16(8),
   5461 	5:   uint16(9),
   5462 	6:   uint16(10),
   5463 	7:   uint16(11),
   5464 	8:   uint16(12),
   5465 	9:   uint16(13),
   5466 	10:  uint16(14),
   5467 	11:  uint16(15),
   5468 	12:  uint16(16),
   5469 	13:  uint16(17),
   5470 	14:  uint16(18),
   5471 	15:  uint16(19),
   5472 	16:  uint16(20),
   5473 	17:  uint16(21),
   5474 	18:  uint16(22),
   5475 	19:  uint16(23),
   5476 	20:  uint16(24),
   5477 	21:  uint16(25),
   5478 	22:  uint16(26),
   5479 	23:  uint16(27),
   5480 	24:  uint16(28),
   5481 	25:  uint16(29),
   5482 	26:  uint16(30),
   5483 	27:  uint16(31),
   5484 	28:  uint16(32),
   5485 	29:  uint16(33),
   5486 	30:  uint16(34),
   5487 	31:  uint16(35),
   5488 	32:  uint16(36),
   5489 	33:  uint16(37),
   5490 	34:  uint16(38),
   5491 	35:  uint16(39),
   5492 	36:  uint16(40),
   5493 	37:  uint16(41),
   5494 	38:  uint16(42),
   5495 	39:  uint16(43),
   5496 	40:  uint16(44),
   5497 	41:  uint16(45),
   5498 	42:  uint16(46),
   5499 	43:  uint16(47),
   5500 	44:  uint16(48),
   5501 	45:  uint16(49),
   5502 	46:  uint16(50),
   5503 	47:  uint16(51),
   5504 	48:  uint16(52),
   5505 	49:  uint16(53),
   5506 	50:  uint16(54),
   5507 	51:  uint16(55),
   5508 	52:  uint16(56),
   5509 	53:  uint16(57),
   5510 	54:  uint16(58),
   5511 	55:  uint16(60),
   5512 	56:  uint16(62),
   5513 	57:  uint16(64),
   5514 	58:  uint16(66),
   5515 	59:  uint16(68),
   5516 	60:  uint16(70),
   5517 	61:  uint16(72),
   5518 	62:  uint16(74),
   5519 	63:  uint16(76),
   5520 	64:  uint16(78),
   5521 	65:  uint16(80),
   5522 	66:  uint16(82),
   5523 	67:  uint16(84),
   5524 	68:  uint16(86),
   5525 	69:  uint16(88),
   5526 	70:  uint16(90),
   5527 	71:  uint16(92),
   5528 	72:  uint16(94),
   5529 	73:  uint16(96),
   5530 	74:  uint16(98),
   5531 	75:  uint16(100),
   5532 	76:  uint16(102),
   5533 	77:  uint16(104),
   5534 	78:  uint16(106),
   5535 	79:  uint16(108),
   5536 	80:  uint16(110),
   5537 	81:  uint16(112),
   5538 	82:  uint16(114),
   5539 	83:  uint16(116),
   5540 	84:  uint16(119),
   5541 	85:  uint16(122),
   5542 	86:  uint16(125),
   5543 	87:  uint16(128),
   5544 	88:  uint16(131),
   5545 	89:  uint16(134),
   5546 	90:  uint16(137),
   5547 	91:  uint16(140),
   5548 	92:  uint16(143),
   5549 	93:  uint16(146),
   5550 	94:  uint16(149),
   5551 	95:  uint16(152),
   5552 	96:  uint16(155),
   5553 	97:  uint16(158),
   5554 	98:  uint16(161),
   5555 	99:  uint16(164),
   5556 	100: uint16(167),
   5557 	101: uint16(170),
   5558 	102: uint16(173),
   5559 	103: uint16(177),
   5560 	104: uint16(181),
   5561 	105: uint16(185),
   5562 	106: uint16(189),
   5563 	107: uint16(193),
   5564 	108: uint16(197),
   5565 	109: uint16(201),
   5566 	110: uint16(205),
   5567 	111: uint16(209),
   5568 	112: uint16(213),
   5569 	113: uint16(217),
   5570 	114: uint16(221),
   5571 	115: uint16(225),
   5572 	116: uint16(229),
   5573 	117: uint16(234),
   5574 	118: uint16(239),
   5575 	119: uint16(245),
   5576 	120: uint16(249),
   5577 	121: uint16(254),
   5578 	122: uint16(259),
   5579 	123: uint16(264),
   5580 	124: uint16(269),
   5581 	125: uint16(274),
   5582 	126: uint16(279),
   5583 	127: uint16(284),
   5584 }
   5585 
   5586 //------------------------------------------------------------------------------
   5587 // Paragraph 9.6
   5588 
   5589 func VP8ParseQuant(tls *libc.TLS, dec uintptr) {
   5590 	var base_q0, dquv_ac, dquv_dc, dqy1_dc, dqy2_ac, dqy2_dc, i, q, v1, v2, v3, v4, v5 int32
   5591 	var br, hdr, m uintptr
   5592 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = base_q0, br, dquv_ac, dquv_dc, dqy1_dc, dqy2_ac, dqy2_dc, hdr, i, m, q, v1, v2, v3, v4, v5
   5593 	br = dec + 16
   5594 	base_q0 = int32(VP8GetValue(tls, br, int32(7)))
   5595 	if VP8GetValue(tls, br, int32(1)) != 0 {
   5596 		v1 = VP8GetSignedValue(tls, br, int32(4))
   5597 	} else {
   5598 		v1 = 0
   5599 	}
   5600 	dqy1_dc = v1
   5601 	if VP8GetValue(tls, br, int32(1)) != 0 {
   5602 		v2 = VP8GetSignedValue(tls, br, int32(4))
   5603 	} else {
   5604 		v2 = 0
   5605 	}
   5606 	dqy2_dc = v2
   5607 	if VP8GetValue(tls, br, int32(1)) != 0 {
   5608 		v3 = VP8GetSignedValue(tls, br, int32(4))
   5609 	} else {
   5610 		v3 = 0
   5611 	}
   5612 	dqy2_ac = v3
   5613 	if VP8GetValue(tls, br, int32(1)) != 0 {
   5614 		v4 = VP8GetSignedValue(tls, br, int32(4))
   5615 	} else {
   5616 		v4 = 0
   5617 	}
   5618 	dquv_dc = v4
   5619 	if VP8GetValue(tls, br, int32(1)) != 0 {
   5620 		v5 = VP8GetSignedValue(tls, br, int32(4))
   5621 	} else {
   5622 		v5 = 0
   5623 	}
   5624 	dquv_ac = v5
   5625 	hdr = dec + 132
   5626 	i = 0
   5627 	for {
   5628 		if !(i < int32(NUM_MB_SEGMENTS)) {
   5629 			break
   5630 		}
   5631 		if (*VP8SegmentHeader)(unsafe.Pointer(hdr)).Fuse_segment != 0 {
   5632 			q = int32(**(**int8_t)(__ccgo_up(hdr + 12 + uintptr(i))))
   5633 			if !((*VP8SegmentHeader)(unsafe.Pointer(hdr)).Fabsolute_delta != 0) {
   5634 				q = q + base_q0
   5635 			}
   5636 		} else {
   5637 			if i > 0 {
   5638 				**(**VP8QuantMatrix)(__ccgo_up(dec + 1060 + uintptr(i)*32)) = **(**VP8QuantMatrix)(__ccgo_up(dec + 1060))
   5639 				goto _6
   5640 			} else {
   5641 				q = base_q0
   5642 			}
   5643 		}
   5644 		m = dec + 1060 + uintptr(i)*32
   5645 		**(**int32)(__ccgo_up(m)) = int32(kDcTable[clip(tls, q+dqy1_dc, int32(127))])
   5646 		**(**int32)(__ccgo_up(m + 1*4)) = int32(kAcTable[clip(tls, q+0, int32(127))])
   5647 		**(**int32)(__ccgo_up(m + 8)) = int32(kDcTable[clip(tls, q+dqy2_dc, int32(127))]) * int32(2)
   5648 		// For all x in [0..284], x*155/100 is bitwise equal to (x*101581) >> 16.
   5649 		// The smallest precision for that is '(x*6349) >> 12' but 16 is a good
   5650 		// word size.
   5651 		**(**int32)(__ccgo_up(m + 8 + 1*4)) = int32(kAcTable[clip(tls, q+dqy2_ac, int32(127))]) * int32(101581) >> int32(16)
   5652 		if **(**int32)(__ccgo_up(m + 8 + 1*4)) < int32(8) {
   5653 			**(**int32)(__ccgo_up(m + 8 + 1*4)) = int32(8)
   5654 		}
   5655 		**(**int32)(__ccgo_up(m + 16)) = int32(kDcTable[clip(tls, q+dquv_dc, int32(117))])
   5656 		**(**int32)(__ccgo_up(m + 16 + 1*4)) = int32(kAcTable[clip(tls, q+dquv_ac, int32(127))])
   5657 		(*VP8QuantMatrix)(unsafe.Pointer(m)).Fuv_quant = q + dquv_ac // for dithering strength evaluation
   5658 		goto _6
   5659 	_6:
   5660 		;
   5661 		i = i + 1
   5662 	}
   5663 }
   5664 
   5665 const USE_GENERIC_TREE = 1
   5666 
   5667 var kHashMul6 = uint32(0x1e35a7bd)
   5668 
   5669 type lbit_t = uint64
   5670 
   5671 // Copyright 2010 Google Inc. All Rights Reserved.
   5672 //
   5673 // Use of this source code is governed by a BSD-style license
   5674 // that can be found in the COPYING file in the root of the source
   5675 // tree. An additional intellectual property rights grant can be found
   5676 // in the file PATENTS. All contributing project authors may
   5677 // be found in the AUTHORS file in the root of the source tree.
   5678 // -----------------------------------------------------------------------------
   5679 //
   5680 // Boolean decoder
   5681 //
   5682 // Author: Skal (pascal.massimino@gmail.com)
   5683 //         Vikas Arora (vikaas.arora@gmail.com)
   5684 
   5685 // using a table is ~1-2% slower on ARM. Prefer the coded-tree approach then.
   5686 
   5687 var kYModesIntra4 = [18]int8_t{
   5688 	1:  int8(1),
   5689 	2:  int8(-int32(B_TM_PRED)),
   5690 	3:  int8(2),
   5691 	4:  int8(-int32(B_VE_PRED)),
   5692 	5:  int8(3),
   5693 	6:  int8(4),
   5694 	7:  int8(6),
   5695 	8:  int8(-int32(B_HE_PRED)),
   5696 	9:  int8(5),
   5697 	10: int8(-int32(B_RD_PRED)),
   5698 	11: int8(-int32(B_VR_PRED)),
   5699 	12: int8(-int32(B_LD_PRED)),
   5700 	13: int8(7),
   5701 	14: int8(-int32(B_VL_PRED)),
   5702 	15: int8(8),
   5703 	16: int8(-int32(B_HD_PRED)),
   5704 	17: int8(-int32(B_HU_PRED)),
   5705 }
   5706 
   5707 //------------------------------------------------------------------------------
   5708 // Default probabilities
   5709 
   5710 // C documentation
   5711 //
   5712 //	// Paragraph 13.5
   5713 
   5714 var CoeffsProba0 = [4][8][3][11]uint8_t{
   5715 	0: {
   5716 		0: {
   5717 			0: {
   5718 				0:  uint8(128),
   5719 				1:  uint8(128),
   5720 				2:  uint8(128),
   5721 				3:  uint8(128),
   5722 				4:  uint8(128),
   5723 				5:  uint8(128),
   5724 				6:  uint8(128),
   5725 				7:  uint8(128),
   5726 				8:  uint8(128),
   5727 				9:  uint8(128),
   5728 				10: uint8(128),
   5729 			},
   5730 			1: {
   5731 				0:  uint8(128),
   5732 				1:  uint8(128),
   5733 				2:  uint8(128),
   5734 				3:  uint8(128),
   5735 				4:  uint8(128),
   5736 				5:  uint8(128),
   5737 				6:  uint8(128),
   5738 				7:  uint8(128),
   5739 				8:  uint8(128),
   5740 				9:  uint8(128),
   5741 				10: uint8(128),
   5742 			},
   5743 			2: {
   5744 				0:  uint8(128),
   5745 				1:  uint8(128),
   5746 				2:  uint8(128),
   5747 				3:  uint8(128),
   5748 				4:  uint8(128),
   5749 				5:  uint8(128),
   5750 				6:  uint8(128),
   5751 				7:  uint8(128),
   5752 				8:  uint8(128),
   5753 				9:  uint8(128),
   5754 				10: uint8(128),
   5755 			},
   5756 		},
   5757 		1: {
   5758 			0: {
   5759 				0:  uint8(253),
   5760 				1:  uint8(136),
   5761 				2:  uint8(254),
   5762 				3:  uint8(255),
   5763 				4:  uint8(228),
   5764 				5:  uint8(219),
   5765 				6:  uint8(128),
   5766 				7:  uint8(128),
   5767 				8:  uint8(128),
   5768 				9:  uint8(128),
   5769 				10: uint8(128),
   5770 			},
   5771 			1: {
   5772 				0:  uint8(189),
   5773 				1:  uint8(129),
   5774 				2:  uint8(242),
   5775 				3:  uint8(255),
   5776 				4:  uint8(227),
   5777 				5:  uint8(213),
   5778 				6:  uint8(255),
   5779 				7:  uint8(219),
   5780 				8:  uint8(128),
   5781 				9:  uint8(128),
   5782 				10: uint8(128),
   5783 			},
   5784 			2: {
   5785 				0:  uint8(106),
   5786 				1:  uint8(126),
   5787 				2:  uint8(227),
   5788 				3:  uint8(252),
   5789 				4:  uint8(214),
   5790 				5:  uint8(209),
   5791 				6:  uint8(255),
   5792 				7:  uint8(255),
   5793 				8:  uint8(128),
   5794 				9:  uint8(128),
   5795 				10: uint8(128),
   5796 			},
   5797 		},
   5798 		2: {
   5799 			0: {
   5800 				0:  uint8(1),
   5801 				1:  uint8(98),
   5802 				2:  uint8(248),
   5803 				3:  uint8(255),
   5804 				4:  uint8(236),
   5805 				5:  uint8(226),
   5806 				6:  uint8(255),
   5807 				7:  uint8(255),
   5808 				8:  uint8(128),
   5809 				9:  uint8(128),
   5810 				10: uint8(128),
   5811 			},
   5812 			1: {
   5813 				0:  uint8(181),
   5814 				1:  uint8(133),
   5815 				2:  uint8(238),
   5816 				3:  uint8(254),
   5817 				4:  uint8(221),
   5818 				5:  uint8(234),
   5819 				6:  uint8(255),
   5820 				7:  uint8(154),
   5821 				8:  uint8(128),
   5822 				9:  uint8(128),
   5823 				10: uint8(128),
   5824 			},
   5825 			2: {
   5826 				0:  uint8(78),
   5827 				1:  uint8(134),
   5828 				2:  uint8(202),
   5829 				3:  uint8(247),
   5830 				4:  uint8(198),
   5831 				5:  uint8(180),
   5832 				6:  uint8(255),
   5833 				7:  uint8(219),
   5834 				8:  uint8(128),
   5835 				9:  uint8(128),
   5836 				10: uint8(128),
   5837 			},
   5838 		},
   5839 		3: {
   5840 			0: {
   5841 				0:  uint8(1),
   5842 				1:  uint8(185),
   5843 				2:  uint8(249),
   5844 				3:  uint8(255),
   5845 				4:  uint8(243),
   5846 				5:  uint8(255),
   5847 				6:  uint8(128),
   5848 				7:  uint8(128),
   5849 				8:  uint8(128),
   5850 				9:  uint8(128),
   5851 				10: uint8(128),
   5852 			},
   5853 			1: {
   5854 				0:  uint8(184),
   5855 				1:  uint8(150),
   5856 				2:  uint8(247),
   5857 				3:  uint8(255),
   5858 				4:  uint8(236),
   5859 				5:  uint8(224),
   5860 				6:  uint8(128),
   5861 				7:  uint8(128),
   5862 				8:  uint8(128),
   5863 				9:  uint8(128),
   5864 				10: uint8(128),
   5865 			},
   5866 			2: {
   5867 				0:  uint8(77),
   5868 				1:  uint8(110),
   5869 				2:  uint8(216),
   5870 				3:  uint8(255),
   5871 				4:  uint8(236),
   5872 				5:  uint8(230),
   5873 				6:  uint8(128),
   5874 				7:  uint8(128),
   5875 				8:  uint8(128),
   5876 				9:  uint8(128),
   5877 				10: uint8(128),
   5878 			},
   5879 		},
   5880 		4: {
   5881 			0: {
   5882 				0:  uint8(1),
   5883 				1:  uint8(101),
   5884 				2:  uint8(251),
   5885 				3:  uint8(255),
   5886 				4:  uint8(241),
   5887 				5:  uint8(255),
   5888 				6:  uint8(128),
   5889 				7:  uint8(128),
   5890 				8:  uint8(128),
   5891 				9:  uint8(128),
   5892 				10: uint8(128),
   5893 			},
   5894 			1: {
   5895 				0:  uint8(170),
   5896 				1:  uint8(139),
   5897 				2:  uint8(241),
   5898 				3:  uint8(252),
   5899 				4:  uint8(236),
   5900 				5:  uint8(209),
   5901 				6:  uint8(255),
   5902 				7:  uint8(255),
   5903 				8:  uint8(128),
   5904 				9:  uint8(128),
   5905 				10: uint8(128),
   5906 			},
   5907 			2: {
   5908 				0:  uint8(37),
   5909 				1:  uint8(116),
   5910 				2:  uint8(196),
   5911 				3:  uint8(243),
   5912 				4:  uint8(228),
   5913 				5:  uint8(255),
   5914 				6:  uint8(255),
   5915 				7:  uint8(255),
   5916 				8:  uint8(128),
   5917 				9:  uint8(128),
   5918 				10: uint8(128),
   5919 			},
   5920 		},
   5921 		5: {
   5922 			0: {
   5923 				0:  uint8(1),
   5924 				1:  uint8(204),
   5925 				2:  uint8(254),
   5926 				3:  uint8(255),
   5927 				4:  uint8(245),
   5928 				5:  uint8(255),
   5929 				6:  uint8(128),
   5930 				7:  uint8(128),
   5931 				8:  uint8(128),
   5932 				9:  uint8(128),
   5933 				10: uint8(128),
   5934 			},
   5935 			1: {
   5936 				0:  uint8(207),
   5937 				1:  uint8(160),
   5938 				2:  uint8(250),
   5939 				3:  uint8(255),
   5940 				4:  uint8(238),
   5941 				5:  uint8(128),
   5942 				6:  uint8(128),
   5943 				7:  uint8(128),
   5944 				8:  uint8(128),
   5945 				9:  uint8(128),
   5946 				10: uint8(128),
   5947 			},
   5948 			2: {
   5949 				0:  uint8(102),
   5950 				1:  uint8(103),
   5951 				2:  uint8(231),
   5952 				3:  uint8(255),
   5953 				4:  uint8(211),
   5954 				5:  uint8(171),
   5955 				6:  uint8(128),
   5956 				7:  uint8(128),
   5957 				8:  uint8(128),
   5958 				9:  uint8(128),
   5959 				10: uint8(128),
   5960 			},
   5961 		},
   5962 		6: {
   5963 			0: {
   5964 				0:  uint8(1),
   5965 				1:  uint8(152),
   5966 				2:  uint8(252),
   5967 				3:  uint8(255),
   5968 				4:  uint8(240),
   5969 				5:  uint8(255),
   5970 				6:  uint8(128),
   5971 				7:  uint8(128),
   5972 				8:  uint8(128),
   5973 				9:  uint8(128),
   5974 				10: uint8(128),
   5975 			},
   5976 			1: {
   5977 				0:  uint8(177),
   5978 				1:  uint8(135),
   5979 				2:  uint8(243),
   5980 				3:  uint8(255),
   5981 				4:  uint8(234),
   5982 				5:  uint8(225),
   5983 				6:  uint8(128),
   5984 				7:  uint8(128),
   5985 				8:  uint8(128),
   5986 				9:  uint8(128),
   5987 				10: uint8(128),
   5988 			},
   5989 			2: {
   5990 				0:  uint8(80),
   5991 				1:  uint8(129),
   5992 				2:  uint8(211),
   5993 				3:  uint8(255),
   5994 				4:  uint8(194),
   5995 				5:  uint8(224),
   5996 				6:  uint8(128),
   5997 				7:  uint8(128),
   5998 				8:  uint8(128),
   5999 				9:  uint8(128),
   6000 				10: uint8(128),
   6001 			},
   6002 		},
   6003 		7: {
   6004 			0: {
   6005 				0:  uint8(1),
   6006 				1:  uint8(1),
   6007 				2:  uint8(255),
   6008 				3:  uint8(128),
   6009 				4:  uint8(128),
   6010 				5:  uint8(128),
   6011 				6:  uint8(128),
   6012 				7:  uint8(128),
   6013 				8:  uint8(128),
   6014 				9:  uint8(128),
   6015 				10: uint8(128),
   6016 			},
   6017 			1: {
   6018 				0:  uint8(246),
   6019 				1:  uint8(1),
   6020 				2:  uint8(255),
   6021 				3:  uint8(128),
   6022 				4:  uint8(128),
   6023 				5:  uint8(128),
   6024 				6:  uint8(128),
   6025 				7:  uint8(128),
   6026 				8:  uint8(128),
   6027 				9:  uint8(128),
   6028 				10: uint8(128),
   6029 			},
   6030 			2: {
   6031 				0:  uint8(255),
   6032 				1:  uint8(128),
   6033 				2:  uint8(128),
   6034 				3:  uint8(128),
   6035 				4:  uint8(128),
   6036 				5:  uint8(128),
   6037 				6:  uint8(128),
   6038 				7:  uint8(128),
   6039 				8:  uint8(128),
   6040 				9:  uint8(128),
   6041 				10: uint8(128),
   6042 			},
   6043 		},
   6044 	},
   6045 	1: {
   6046 		0: {
   6047 			0: {
   6048 				0:  uint8(198),
   6049 				1:  uint8(35),
   6050 				2:  uint8(237),
   6051 				3:  uint8(223),
   6052 				4:  uint8(193),
   6053 				5:  uint8(187),
   6054 				6:  uint8(162),
   6055 				7:  uint8(160),
   6056 				8:  uint8(145),
   6057 				9:  uint8(155),
   6058 				10: uint8(62),
   6059 			},
   6060 			1: {
   6061 				0:  uint8(131),
   6062 				1:  uint8(45),
   6063 				2:  uint8(198),
   6064 				3:  uint8(221),
   6065 				4:  uint8(172),
   6066 				5:  uint8(176),
   6067 				6:  uint8(220),
   6068 				7:  uint8(157),
   6069 				8:  uint8(252),
   6070 				9:  uint8(221),
   6071 				10: uint8(1),
   6072 			},
   6073 			2: {
   6074 				0:  uint8(68),
   6075 				1:  uint8(47),
   6076 				2:  uint8(146),
   6077 				3:  uint8(208),
   6078 				4:  uint8(149),
   6079 				5:  uint8(167),
   6080 				6:  uint8(221),
   6081 				7:  uint8(162),
   6082 				8:  uint8(255),
   6083 				9:  uint8(223),
   6084 				10: uint8(128),
   6085 			},
   6086 		},
   6087 		1: {
   6088 			0: {
   6089 				0:  uint8(1),
   6090 				1:  uint8(149),
   6091 				2:  uint8(241),
   6092 				3:  uint8(255),
   6093 				4:  uint8(221),
   6094 				5:  uint8(224),
   6095 				6:  uint8(255),
   6096 				7:  uint8(255),
   6097 				8:  uint8(128),
   6098 				9:  uint8(128),
   6099 				10: uint8(128),
   6100 			},
   6101 			1: {
   6102 				0:  uint8(184),
   6103 				1:  uint8(141),
   6104 				2:  uint8(234),
   6105 				3:  uint8(253),
   6106 				4:  uint8(222),
   6107 				5:  uint8(220),
   6108 				6:  uint8(255),
   6109 				7:  uint8(199),
   6110 				8:  uint8(128),
   6111 				9:  uint8(128),
   6112 				10: uint8(128),
   6113 			},
   6114 			2: {
   6115 				0:  uint8(81),
   6116 				1:  uint8(99),
   6117 				2:  uint8(181),
   6118 				3:  uint8(242),
   6119 				4:  uint8(176),
   6120 				5:  uint8(190),
   6121 				6:  uint8(249),
   6122 				7:  uint8(202),
   6123 				8:  uint8(255),
   6124 				9:  uint8(255),
   6125 				10: uint8(128),
   6126 			},
   6127 		},
   6128 		2: {
   6129 			0: {
   6130 				0:  uint8(1),
   6131 				1:  uint8(129),
   6132 				2:  uint8(232),
   6133 				3:  uint8(253),
   6134 				4:  uint8(214),
   6135 				5:  uint8(197),
   6136 				6:  uint8(242),
   6137 				7:  uint8(196),
   6138 				8:  uint8(255),
   6139 				9:  uint8(255),
   6140 				10: uint8(128),
   6141 			},
   6142 			1: {
   6143 				0:  uint8(99),
   6144 				1:  uint8(121),
   6145 				2:  uint8(210),
   6146 				3:  uint8(250),
   6147 				4:  uint8(201),
   6148 				5:  uint8(198),
   6149 				6:  uint8(255),
   6150 				7:  uint8(202),
   6151 				8:  uint8(128),
   6152 				9:  uint8(128),
   6153 				10: uint8(128),
   6154 			},
   6155 			2: {
   6156 				0:  uint8(23),
   6157 				1:  uint8(91),
   6158 				2:  uint8(163),
   6159 				3:  uint8(242),
   6160 				4:  uint8(170),
   6161 				5:  uint8(187),
   6162 				6:  uint8(247),
   6163 				7:  uint8(210),
   6164 				8:  uint8(255),
   6165 				9:  uint8(255),
   6166 				10: uint8(128),
   6167 			},
   6168 		},
   6169 		3: {
   6170 			0: {
   6171 				0:  uint8(1),
   6172 				1:  uint8(200),
   6173 				2:  uint8(246),
   6174 				3:  uint8(255),
   6175 				4:  uint8(234),
   6176 				5:  uint8(255),
   6177 				6:  uint8(128),
   6178 				7:  uint8(128),
   6179 				8:  uint8(128),
   6180 				9:  uint8(128),
   6181 				10: uint8(128),
   6182 			},
   6183 			1: {
   6184 				0:  uint8(109),
   6185 				1:  uint8(178),
   6186 				2:  uint8(241),
   6187 				3:  uint8(255),
   6188 				4:  uint8(231),
   6189 				5:  uint8(245),
   6190 				6:  uint8(255),
   6191 				7:  uint8(255),
   6192 				8:  uint8(128),
   6193 				9:  uint8(128),
   6194 				10: uint8(128),
   6195 			},
   6196 			2: {
   6197 				0:  uint8(44),
   6198 				1:  uint8(130),
   6199 				2:  uint8(201),
   6200 				3:  uint8(253),
   6201 				4:  uint8(205),
   6202 				5:  uint8(192),
   6203 				6:  uint8(255),
   6204 				7:  uint8(255),
   6205 				8:  uint8(128),
   6206 				9:  uint8(128),
   6207 				10: uint8(128),
   6208 			},
   6209 		},
   6210 		4: {
   6211 			0: {
   6212 				0:  uint8(1),
   6213 				1:  uint8(132),
   6214 				2:  uint8(239),
   6215 				3:  uint8(251),
   6216 				4:  uint8(219),
   6217 				5:  uint8(209),
   6218 				6:  uint8(255),
   6219 				7:  uint8(165),
   6220 				8:  uint8(128),
   6221 				9:  uint8(128),
   6222 				10: uint8(128),
   6223 			},
   6224 			1: {
   6225 				0:  uint8(94),
   6226 				1:  uint8(136),
   6227 				2:  uint8(225),
   6228 				3:  uint8(251),
   6229 				4:  uint8(218),
   6230 				5:  uint8(190),
   6231 				6:  uint8(255),
   6232 				7:  uint8(255),
   6233 				8:  uint8(128),
   6234 				9:  uint8(128),
   6235 				10: uint8(128),
   6236 			},
   6237 			2: {
   6238 				0:  uint8(22),
   6239 				1:  uint8(100),
   6240 				2:  uint8(174),
   6241 				3:  uint8(245),
   6242 				4:  uint8(186),
   6243 				5:  uint8(161),
   6244 				6:  uint8(255),
   6245 				7:  uint8(199),
   6246 				8:  uint8(128),
   6247 				9:  uint8(128),
   6248 				10: uint8(128),
   6249 			},
   6250 		},
   6251 		5: {
   6252 			0: {
   6253 				0:  uint8(1),
   6254 				1:  uint8(182),
   6255 				2:  uint8(249),
   6256 				3:  uint8(255),
   6257 				4:  uint8(232),
   6258 				5:  uint8(235),
   6259 				6:  uint8(128),
   6260 				7:  uint8(128),
   6261 				8:  uint8(128),
   6262 				9:  uint8(128),
   6263 				10: uint8(128),
   6264 			},
   6265 			1: {
   6266 				0:  uint8(124),
   6267 				1:  uint8(143),
   6268 				2:  uint8(241),
   6269 				3:  uint8(255),
   6270 				4:  uint8(227),
   6271 				5:  uint8(234),
   6272 				6:  uint8(128),
   6273 				7:  uint8(128),
   6274 				8:  uint8(128),
   6275 				9:  uint8(128),
   6276 				10: uint8(128),
   6277 			},
   6278 			2: {
   6279 				0:  uint8(35),
   6280 				1:  uint8(77),
   6281 				2:  uint8(181),
   6282 				3:  uint8(251),
   6283 				4:  uint8(193),
   6284 				5:  uint8(211),
   6285 				6:  uint8(255),
   6286 				7:  uint8(205),
   6287 				8:  uint8(128),
   6288 				9:  uint8(128),
   6289 				10: uint8(128),
   6290 			},
   6291 		},
   6292 		6: {
   6293 			0: {
   6294 				0:  uint8(1),
   6295 				1:  uint8(157),
   6296 				2:  uint8(247),
   6297 				3:  uint8(255),
   6298 				4:  uint8(236),
   6299 				5:  uint8(231),
   6300 				6:  uint8(255),
   6301 				7:  uint8(255),
   6302 				8:  uint8(128),
   6303 				9:  uint8(128),
   6304 				10: uint8(128),
   6305 			},
   6306 			1: {
   6307 				0:  uint8(121),
   6308 				1:  uint8(141),
   6309 				2:  uint8(235),
   6310 				3:  uint8(255),
   6311 				4:  uint8(225),
   6312 				5:  uint8(227),
   6313 				6:  uint8(255),
   6314 				7:  uint8(255),
   6315 				8:  uint8(128),
   6316 				9:  uint8(128),
   6317 				10: uint8(128),
   6318 			},
   6319 			2: {
   6320 				0:  uint8(45),
   6321 				1:  uint8(99),
   6322 				2:  uint8(188),
   6323 				3:  uint8(251),
   6324 				4:  uint8(195),
   6325 				5:  uint8(217),
   6326 				6:  uint8(255),
   6327 				7:  uint8(224),
   6328 				8:  uint8(128),
   6329 				9:  uint8(128),
   6330 				10: uint8(128),
   6331 			},
   6332 		},
   6333 		7: {
   6334 			0: {
   6335 				0:  uint8(1),
   6336 				1:  uint8(1),
   6337 				2:  uint8(251),
   6338 				3:  uint8(255),
   6339 				4:  uint8(213),
   6340 				5:  uint8(255),
   6341 				6:  uint8(128),
   6342 				7:  uint8(128),
   6343 				8:  uint8(128),
   6344 				9:  uint8(128),
   6345 				10: uint8(128),
   6346 			},
   6347 			1: {
   6348 				0:  uint8(203),
   6349 				1:  uint8(1),
   6350 				2:  uint8(248),
   6351 				3:  uint8(255),
   6352 				4:  uint8(255),
   6353 				5:  uint8(128),
   6354 				6:  uint8(128),
   6355 				7:  uint8(128),
   6356 				8:  uint8(128),
   6357 				9:  uint8(128),
   6358 				10: uint8(128),
   6359 			},
   6360 			2: {
   6361 				0:  uint8(137),
   6362 				1:  uint8(1),
   6363 				2:  uint8(177),
   6364 				3:  uint8(255),
   6365 				4:  uint8(224),
   6366 				5:  uint8(255),
   6367 				6:  uint8(128),
   6368 				7:  uint8(128),
   6369 				8:  uint8(128),
   6370 				9:  uint8(128),
   6371 				10: uint8(128),
   6372 			},
   6373 		},
   6374 	},
   6375 	2: {
   6376 		0: {
   6377 			0: {
   6378 				0:  uint8(253),
   6379 				1:  uint8(9),
   6380 				2:  uint8(248),
   6381 				3:  uint8(251),
   6382 				4:  uint8(207),
   6383 				5:  uint8(208),
   6384 				6:  uint8(255),
   6385 				7:  uint8(192),
   6386 				8:  uint8(128),
   6387 				9:  uint8(128),
   6388 				10: uint8(128),
   6389 			},
   6390 			1: {
   6391 				0:  uint8(175),
   6392 				1:  uint8(13),
   6393 				2:  uint8(224),
   6394 				3:  uint8(243),
   6395 				4:  uint8(193),
   6396 				5:  uint8(185),
   6397 				6:  uint8(249),
   6398 				7:  uint8(198),
   6399 				8:  uint8(255),
   6400 				9:  uint8(255),
   6401 				10: uint8(128),
   6402 			},
   6403 			2: {
   6404 				0:  uint8(73),
   6405 				1:  uint8(17),
   6406 				2:  uint8(171),
   6407 				3:  uint8(221),
   6408 				4:  uint8(161),
   6409 				5:  uint8(179),
   6410 				6:  uint8(236),
   6411 				7:  uint8(167),
   6412 				8:  uint8(255),
   6413 				9:  uint8(234),
   6414 				10: uint8(128),
   6415 			},
   6416 		},
   6417 		1: {
   6418 			0: {
   6419 				0:  uint8(1),
   6420 				1:  uint8(95),
   6421 				2:  uint8(247),
   6422 				3:  uint8(253),
   6423 				4:  uint8(212),
   6424 				5:  uint8(183),
   6425 				6:  uint8(255),
   6426 				7:  uint8(255),
   6427 				8:  uint8(128),
   6428 				9:  uint8(128),
   6429 				10: uint8(128),
   6430 			},
   6431 			1: {
   6432 				0:  uint8(239),
   6433 				1:  uint8(90),
   6434 				2:  uint8(244),
   6435 				3:  uint8(250),
   6436 				4:  uint8(211),
   6437 				5:  uint8(209),
   6438 				6:  uint8(255),
   6439 				7:  uint8(255),
   6440 				8:  uint8(128),
   6441 				9:  uint8(128),
   6442 				10: uint8(128),
   6443 			},
   6444 			2: {
   6445 				0:  uint8(155),
   6446 				1:  uint8(77),
   6447 				2:  uint8(195),
   6448 				3:  uint8(248),
   6449 				4:  uint8(188),
   6450 				5:  uint8(195),
   6451 				6:  uint8(255),
   6452 				7:  uint8(255),
   6453 				8:  uint8(128),
   6454 				9:  uint8(128),
   6455 				10: uint8(128),
   6456 			},
   6457 		},
   6458 		2: {
   6459 			0: {
   6460 				0:  uint8(1),
   6461 				1:  uint8(24),
   6462 				2:  uint8(239),
   6463 				3:  uint8(251),
   6464 				4:  uint8(218),
   6465 				5:  uint8(219),
   6466 				6:  uint8(255),
   6467 				7:  uint8(205),
   6468 				8:  uint8(128),
   6469 				9:  uint8(128),
   6470 				10: uint8(128),
   6471 			},
   6472 			1: {
   6473 				0:  uint8(201),
   6474 				1:  uint8(51),
   6475 				2:  uint8(219),
   6476 				3:  uint8(255),
   6477 				4:  uint8(196),
   6478 				5:  uint8(186),
   6479 				6:  uint8(128),
   6480 				7:  uint8(128),
   6481 				8:  uint8(128),
   6482 				9:  uint8(128),
   6483 				10: uint8(128),
   6484 			},
   6485 			2: {
   6486 				0:  uint8(69),
   6487 				1:  uint8(46),
   6488 				2:  uint8(190),
   6489 				3:  uint8(239),
   6490 				4:  uint8(201),
   6491 				5:  uint8(218),
   6492 				6:  uint8(255),
   6493 				7:  uint8(228),
   6494 				8:  uint8(128),
   6495 				9:  uint8(128),
   6496 				10: uint8(128),
   6497 			},
   6498 		},
   6499 		3: {
   6500 			0: {
   6501 				0:  uint8(1),
   6502 				1:  uint8(191),
   6503 				2:  uint8(251),
   6504 				3:  uint8(255),
   6505 				4:  uint8(255),
   6506 				5:  uint8(128),
   6507 				6:  uint8(128),
   6508 				7:  uint8(128),
   6509 				8:  uint8(128),
   6510 				9:  uint8(128),
   6511 				10: uint8(128),
   6512 			},
   6513 			1: {
   6514 				0:  uint8(223),
   6515 				1:  uint8(165),
   6516 				2:  uint8(249),
   6517 				3:  uint8(255),
   6518 				4:  uint8(213),
   6519 				5:  uint8(255),
   6520 				6:  uint8(128),
   6521 				7:  uint8(128),
   6522 				8:  uint8(128),
   6523 				9:  uint8(128),
   6524 				10: uint8(128),
   6525 			},
   6526 			2: {
   6527 				0:  uint8(141),
   6528 				1:  uint8(124),
   6529 				2:  uint8(248),
   6530 				3:  uint8(255),
   6531 				4:  uint8(255),
   6532 				5:  uint8(128),
   6533 				6:  uint8(128),
   6534 				7:  uint8(128),
   6535 				8:  uint8(128),
   6536 				9:  uint8(128),
   6537 				10: uint8(128),
   6538 			},
   6539 		},
   6540 		4: {
   6541 			0: {
   6542 				0:  uint8(1),
   6543 				1:  uint8(16),
   6544 				2:  uint8(248),
   6545 				3:  uint8(255),
   6546 				4:  uint8(255),
   6547 				5:  uint8(128),
   6548 				6:  uint8(128),
   6549 				7:  uint8(128),
   6550 				8:  uint8(128),
   6551 				9:  uint8(128),
   6552 				10: uint8(128),
   6553 			},
   6554 			1: {
   6555 				0:  uint8(190),
   6556 				1:  uint8(36),
   6557 				2:  uint8(230),
   6558 				3:  uint8(255),
   6559 				4:  uint8(236),
   6560 				5:  uint8(255),
   6561 				6:  uint8(128),
   6562 				7:  uint8(128),
   6563 				8:  uint8(128),
   6564 				9:  uint8(128),
   6565 				10: uint8(128),
   6566 			},
   6567 			2: {
   6568 				0:  uint8(149),
   6569 				1:  uint8(1),
   6570 				2:  uint8(255),
   6571 				3:  uint8(128),
   6572 				4:  uint8(128),
   6573 				5:  uint8(128),
   6574 				6:  uint8(128),
   6575 				7:  uint8(128),
   6576 				8:  uint8(128),
   6577 				9:  uint8(128),
   6578 				10: uint8(128),
   6579 			},
   6580 		},
   6581 		5: {
   6582 			0: {
   6583 				0:  uint8(1),
   6584 				1:  uint8(226),
   6585 				2:  uint8(255),
   6586 				3:  uint8(128),
   6587 				4:  uint8(128),
   6588 				5:  uint8(128),
   6589 				6:  uint8(128),
   6590 				7:  uint8(128),
   6591 				8:  uint8(128),
   6592 				9:  uint8(128),
   6593 				10: uint8(128),
   6594 			},
   6595 			1: {
   6596 				0:  uint8(247),
   6597 				1:  uint8(192),
   6598 				2:  uint8(255),
   6599 				3:  uint8(128),
   6600 				4:  uint8(128),
   6601 				5:  uint8(128),
   6602 				6:  uint8(128),
   6603 				7:  uint8(128),
   6604 				8:  uint8(128),
   6605 				9:  uint8(128),
   6606 				10: uint8(128),
   6607 			},
   6608 			2: {
   6609 				0:  uint8(240),
   6610 				1:  uint8(128),
   6611 				2:  uint8(255),
   6612 				3:  uint8(128),
   6613 				4:  uint8(128),
   6614 				5:  uint8(128),
   6615 				6:  uint8(128),
   6616 				7:  uint8(128),
   6617 				8:  uint8(128),
   6618 				9:  uint8(128),
   6619 				10: uint8(128),
   6620 			},
   6621 		},
   6622 		6: {
   6623 			0: {
   6624 				0:  uint8(1),
   6625 				1:  uint8(134),
   6626 				2:  uint8(252),
   6627 				3:  uint8(255),
   6628 				4:  uint8(255),
   6629 				5:  uint8(128),
   6630 				6:  uint8(128),
   6631 				7:  uint8(128),
   6632 				8:  uint8(128),
   6633 				9:  uint8(128),
   6634 				10: uint8(128),
   6635 			},
   6636 			1: {
   6637 				0:  uint8(213),
   6638 				1:  uint8(62),
   6639 				2:  uint8(250),
   6640 				3:  uint8(255),
   6641 				4:  uint8(255),
   6642 				5:  uint8(128),
   6643 				6:  uint8(128),
   6644 				7:  uint8(128),
   6645 				8:  uint8(128),
   6646 				9:  uint8(128),
   6647 				10: uint8(128),
   6648 			},
   6649 			2: {
   6650 				0:  uint8(55),
   6651 				1:  uint8(93),
   6652 				2:  uint8(255),
   6653 				3:  uint8(128),
   6654 				4:  uint8(128),
   6655 				5:  uint8(128),
   6656 				6:  uint8(128),
   6657 				7:  uint8(128),
   6658 				8:  uint8(128),
   6659 				9:  uint8(128),
   6660 				10: uint8(128),
   6661 			},
   6662 		},
   6663 		7: {
   6664 			0: {
   6665 				0:  uint8(128),
   6666 				1:  uint8(128),
   6667 				2:  uint8(128),
   6668 				3:  uint8(128),
   6669 				4:  uint8(128),
   6670 				5:  uint8(128),
   6671 				6:  uint8(128),
   6672 				7:  uint8(128),
   6673 				8:  uint8(128),
   6674 				9:  uint8(128),
   6675 				10: uint8(128),
   6676 			},
   6677 			1: {
   6678 				0:  uint8(128),
   6679 				1:  uint8(128),
   6680 				2:  uint8(128),
   6681 				3:  uint8(128),
   6682 				4:  uint8(128),
   6683 				5:  uint8(128),
   6684 				6:  uint8(128),
   6685 				7:  uint8(128),
   6686 				8:  uint8(128),
   6687 				9:  uint8(128),
   6688 				10: uint8(128),
   6689 			},
   6690 			2: {
   6691 				0:  uint8(128),
   6692 				1:  uint8(128),
   6693 				2:  uint8(128),
   6694 				3:  uint8(128),
   6695 				4:  uint8(128),
   6696 				5:  uint8(128),
   6697 				6:  uint8(128),
   6698 				7:  uint8(128),
   6699 				8:  uint8(128),
   6700 				9:  uint8(128),
   6701 				10: uint8(128),
   6702 			},
   6703 		},
   6704 	},
   6705 	3: {
   6706 		0: {
   6707 			0: {
   6708 				0:  uint8(202),
   6709 				1:  uint8(24),
   6710 				2:  uint8(213),
   6711 				3:  uint8(235),
   6712 				4:  uint8(186),
   6713 				5:  uint8(191),
   6714 				6:  uint8(220),
   6715 				7:  uint8(160),
   6716 				8:  uint8(240),
   6717 				9:  uint8(175),
   6718 				10: uint8(255),
   6719 			},
   6720 			1: {
   6721 				0:  uint8(126),
   6722 				1:  uint8(38),
   6723 				2:  uint8(182),
   6724 				3:  uint8(232),
   6725 				4:  uint8(169),
   6726 				5:  uint8(184),
   6727 				6:  uint8(228),
   6728 				7:  uint8(174),
   6729 				8:  uint8(255),
   6730 				9:  uint8(187),
   6731 				10: uint8(128),
   6732 			},
   6733 			2: {
   6734 				0:  uint8(61),
   6735 				1:  uint8(46),
   6736 				2:  uint8(138),
   6737 				3:  uint8(219),
   6738 				4:  uint8(151),
   6739 				5:  uint8(178),
   6740 				6:  uint8(240),
   6741 				7:  uint8(170),
   6742 				8:  uint8(255),
   6743 				9:  uint8(216),
   6744 				10: uint8(128),
   6745 			},
   6746 		},
   6747 		1: {
   6748 			0: {
   6749 				0:  uint8(1),
   6750 				1:  uint8(112),
   6751 				2:  uint8(230),
   6752 				3:  uint8(250),
   6753 				4:  uint8(199),
   6754 				5:  uint8(191),
   6755 				6:  uint8(247),
   6756 				7:  uint8(159),
   6757 				8:  uint8(255),
   6758 				9:  uint8(255),
   6759 				10: uint8(128),
   6760 			},
   6761 			1: {
   6762 				0:  uint8(166),
   6763 				1:  uint8(109),
   6764 				2:  uint8(228),
   6765 				3:  uint8(252),
   6766 				4:  uint8(211),
   6767 				5:  uint8(215),
   6768 				6:  uint8(255),
   6769 				7:  uint8(174),
   6770 				8:  uint8(128),
   6771 				9:  uint8(128),
   6772 				10: uint8(128),
   6773 			},
   6774 			2: {
   6775 				0:  uint8(39),
   6776 				1:  uint8(77),
   6777 				2:  uint8(162),
   6778 				3:  uint8(232),
   6779 				4:  uint8(172),
   6780 				5:  uint8(180),
   6781 				6:  uint8(245),
   6782 				7:  uint8(178),
   6783 				8:  uint8(255),
   6784 				9:  uint8(255),
   6785 				10: uint8(128),
   6786 			},
   6787 		},
   6788 		2: {
   6789 			0: {
   6790 				0:  uint8(1),
   6791 				1:  uint8(52),
   6792 				2:  uint8(220),
   6793 				3:  uint8(246),
   6794 				4:  uint8(198),
   6795 				5:  uint8(199),
   6796 				6:  uint8(249),
   6797 				7:  uint8(220),
   6798 				8:  uint8(255),
   6799 				9:  uint8(255),
   6800 				10: uint8(128),
   6801 			},
   6802 			1: {
   6803 				0:  uint8(124),
   6804 				1:  uint8(74),
   6805 				2:  uint8(191),
   6806 				3:  uint8(243),
   6807 				4:  uint8(183),
   6808 				5:  uint8(193),
   6809 				6:  uint8(250),
   6810 				7:  uint8(221),
   6811 				8:  uint8(255),
   6812 				9:  uint8(255),
   6813 				10: uint8(128),
   6814 			},
   6815 			2: {
   6816 				0:  uint8(24),
   6817 				1:  uint8(71),
   6818 				2:  uint8(130),
   6819 				3:  uint8(219),
   6820 				4:  uint8(154),
   6821 				5:  uint8(170),
   6822 				6:  uint8(243),
   6823 				7:  uint8(182),
   6824 				8:  uint8(255),
   6825 				9:  uint8(255),
   6826 				10: uint8(128),
   6827 			},
   6828 		},
   6829 		3: {
   6830 			0: {
   6831 				0:  uint8(1),
   6832 				1:  uint8(182),
   6833 				2:  uint8(225),
   6834 				3:  uint8(249),
   6835 				4:  uint8(219),
   6836 				5:  uint8(240),
   6837 				6:  uint8(255),
   6838 				7:  uint8(224),
   6839 				8:  uint8(128),
   6840 				9:  uint8(128),
   6841 				10: uint8(128),
   6842 			},
   6843 			1: {
   6844 				0:  uint8(149),
   6845 				1:  uint8(150),
   6846 				2:  uint8(226),
   6847 				3:  uint8(252),
   6848 				4:  uint8(216),
   6849 				5:  uint8(205),
   6850 				6:  uint8(255),
   6851 				7:  uint8(171),
   6852 				8:  uint8(128),
   6853 				9:  uint8(128),
   6854 				10: uint8(128),
   6855 			},
   6856 			2: {
   6857 				0:  uint8(28),
   6858 				1:  uint8(108),
   6859 				2:  uint8(170),
   6860 				3:  uint8(242),
   6861 				4:  uint8(183),
   6862 				5:  uint8(194),
   6863 				6:  uint8(254),
   6864 				7:  uint8(223),
   6865 				8:  uint8(255),
   6866 				9:  uint8(255),
   6867 				10: uint8(128),
   6868 			},
   6869 		},
   6870 		4: {
   6871 			0: {
   6872 				0:  uint8(1),
   6873 				1:  uint8(81),
   6874 				2:  uint8(230),
   6875 				3:  uint8(252),
   6876 				4:  uint8(204),
   6877 				5:  uint8(203),
   6878 				6:  uint8(255),
   6879 				7:  uint8(192),
   6880 				8:  uint8(128),
   6881 				9:  uint8(128),
   6882 				10: uint8(128),
   6883 			},
   6884 			1: {
   6885 				0:  uint8(123),
   6886 				1:  uint8(102),
   6887 				2:  uint8(209),
   6888 				3:  uint8(247),
   6889 				4:  uint8(188),
   6890 				5:  uint8(196),
   6891 				6:  uint8(255),
   6892 				7:  uint8(233),
   6893 				8:  uint8(128),
   6894 				9:  uint8(128),
   6895 				10: uint8(128),
   6896 			},
   6897 			2: {
   6898 				0:  uint8(20),
   6899 				1:  uint8(95),
   6900 				2:  uint8(153),
   6901 				3:  uint8(243),
   6902 				4:  uint8(164),
   6903 				5:  uint8(173),
   6904 				6:  uint8(255),
   6905 				7:  uint8(203),
   6906 				8:  uint8(128),
   6907 				9:  uint8(128),
   6908 				10: uint8(128),
   6909 			},
   6910 		},
   6911 		5: {
   6912 			0: {
   6913 				0:  uint8(1),
   6914 				1:  uint8(222),
   6915 				2:  uint8(248),
   6916 				3:  uint8(255),
   6917 				4:  uint8(216),
   6918 				5:  uint8(213),
   6919 				6:  uint8(128),
   6920 				7:  uint8(128),
   6921 				8:  uint8(128),
   6922 				9:  uint8(128),
   6923 				10: uint8(128),
   6924 			},
   6925 			1: {
   6926 				0:  uint8(168),
   6927 				1:  uint8(175),
   6928 				2:  uint8(246),
   6929 				3:  uint8(252),
   6930 				4:  uint8(235),
   6931 				5:  uint8(205),
   6932 				6:  uint8(255),
   6933 				7:  uint8(255),
   6934 				8:  uint8(128),
   6935 				9:  uint8(128),
   6936 				10: uint8(128),
   6937 			},
   6938 			2: {
   6939 				0:  uint8(47),
   6940 				1:  uint8(116),
   6941 				2:  uint8(215),
   6942 				3:  uint8(255),
   6943 				4:  uint8(211),
   6944 				5:  uint8(212),
   6945 				6:  uint8(255),
   6946 				7:  uint8(255),
   6947 				8:  uint8(128),
   6948 				9:  uint8(128),
   6949 				10: uint8(128),
   6950 			},
   6951 		},
   6952 		6: {
   6953 			0: {
   6954 				0:  uint8(1),
   6955 				1:  uint8(121),
   6956 				2:  uint8(236),
   6957 				3:  uint8(253),
   6958 				4:  uint8(212),
   6959 				5:  uint8(214),
   6960 				6:  uint8(255),
   6961 				7:  uint8(255),
   6962 				8:  uint8(128),
   6963 				9:  uint8(128),
   6964 				10: uint8(128),
   6965 			},
   6966 			1: {
   6967 				0:  uint8(141),
   6968 				1:  uint8(84),
   6969 				2:  uint8(213),
   6970 				3:  uint8(252),
   6971 				4:  uint8(201),
   6972 				5:  uint8(202),
   6973 				6:  uint8(255),
   6974 				7:  uint8(219),
   6975 				8:  uint8(128),
   6976 				9:  uint8(128),
   6977 				10: uint8(128),
   6978 			},
   6979 			2: {
   6980 				0:  uint8(42),
   6981 				1:  uint8(80),
   6982 				2:  uint8(160),
   6983 				3:  uint8(240),
   6984 				4:  uint8(162),
   6985 				5:  uint8(185),
   6986 				6:  uint8(255),
   6987 				7:  uint8(205),
   6988 				8:  uint8(128),
   6989 				9:  uint8(128),
   6990 				10: uint8(128),
   6991 			},
   6992 		},
   6993 		7: {
   6994 			0: {
   6995 				0:  uint8(1),
   6996 				1:  uint8(1),
   6997 				2:  uint8(255),
   6998 				3:  uint8(128),
   6999 				4:  uint8(128),
   7000 				5:  uint8(128),
   7001 				6:  uint8(128),
   7002 				7:  uint8(128),
   7003 				8:  uint8(128),
   7004 				9:  uint8(128),
   7005 				10: uint8(128),
   7006 			},
   7007 			1: {
   7008 				0:  uint8(244),
   7009 				1:  uint8(1),
   7010 				2:  uint8(255),
   7011 				3:  uint8(128),
   7012 				4:  uint8(128),
   7013 				5:  uint8(128),
   7014 				6:  uint8(128),
   7015 				7:  uint8(128),
   7016 				8:  uint8(128),
   7017 				9:  uint8(128),
   7018 				10: uint8(128),
   7019 			},
   7020 			2: {
   7021 				0:  uint8(238),
   7022 				1:  uint8(1),
   7023 				2:  uint8(255),
   7024 				3:  uint8(128),
   7025 				4:  uint8(128),
   7026 				5:  uint8(128),
   7027 				6:  uint8(128),
   7028 				7:  uint8(128),
   7029 				8:  uint8(128),
   7030 				9:  uint8(128),
   7031 				10: uint8(128),
   7032 			},
   7033 		},
   7034 	},
   7035 }
   7036 
   7037 // C documentation
   7038 //
   7039 //	// Paragraph 11.5
   7040 var kBModesProba = [10][10][9]uint8_t{
   7041 	0: {
   7042 		0: {
   7043 			0: uint8(231),
   7044 			1: uint8(120),
   7045 			2: uint8(48),
   7046 			3: uint8(89),
   7047 			4: uint8(115),
   7048 			5: uint8(113),
   7049 			6: uint8(120),
   7050 			7: uint8(152),
   7051 			8: uint8(112),
   7052 		},
   7053 		1: {
   7054 			0: uint8(152),
   7055 			1: uint8(179),
   7056 			2: uint8(64),
   7057 			3: uint8(126),
   7058 			4: uint8(170),
   7059 			5: uint8(118),
   7060 			6: uint8(46),
   7061 			7: uint8(70),
   7062 			8: uint8(95),
   7063 		},
   7064 		2: {
   7065 			0: uint8(175),
   7066 			1: uint8(69),
   7067 			2: uint8(143),
   7068 			3: uint8(80),
   7069 			4: uint8(85),
   7070 			5: uint8(82),
   7071 			6: uint8(72),
   7072 			7: uint8(155),
   7073 			8: uint8(103),
   7074 		},
   7075 		3: {
   7076 			0: uint8(56),
   7077 			1: uint8(58),
   7078 			2: uint8(10),
   7079 			3: uint8(171),
   7080 			4: uint8(218),
   7081 			5: uint8(189),
   7082 			6: uint8(17),
   7083 			7: uint8(13),
   7084 			8: uint8(152),
   7085 		},
   7086 		4: {
   7087 			0: uint8(114),
   7088 			1: uint8(26),
   7089 			2: uint8(17),
   7090 			3: uint8(163),
   7091 			4: uint8(44),
   7092 			5: uint8(195),
   7093 			6: uint8(21),
   7094 			7: uint8(10),
   7095 			8: uint8(173),
   7096 		},
   7097 		5: {
   7098 			0: uint8(121),
   7099 			1: uint8(24),
   7100 			2: uint8(80),
   7101 			3: uint8(195),
   7102 			4: uint8(26),
   7103 			5: uint8(62),
   7104 			6: uint8(44),
   7105 			7: uint8(64),
   7106 			8: uint8(85),
   7107 		},
   7108 		6: {
   7109 			0: uint8(144),
   7110 			1: uint8(71),
   7111 			2: uint8(10),
   7112 			3: uint8(38),
   7113 			4: uint8(171),
   7114 			5: uint8(213),
   7115 			6: uint8(144),
   7116 			7: uint8(34),
   7117 			8: uint8(26),
   7118 		},
   7119 		7: {
   7120 			0: uint8(170),
   7121 			1: uint8(46),
   7122 			2: uint8(55),
   7123 			3: uint8(19),
   7124 			4: uint8(136),
   7125 			5: uint8(160),
   7126 			6: uint8(33),
   7127 			7: uint8(206),
   7128 			8: uint8(71),
   7129 		},
   7130 		8: {
   7131 			0: uint8(63),
   7132 			1: uint8(20),
   7133 			2: uint8(8),
   7134 			3: uint8(114),
   7135 			4: uint8(114),
   7136 			5: uint8(208),
   7137 			6: uint8(12),
   7138 			7: uint8(9),
   7139 			8: uint8(226),
   7140 		},
   7141 		9: {
   7142 			0: uint8(81),
   7143 			1: uint8(40),
   7144 			2: uint8(11),
   7145 			3: uint8(96),
   7146 			4: uint8(182),
   7147 			5: uint8(84),
   7148 			6: uint8(29),
   7149 			7: uint8(16),
   7150 			8: uint8(36),
   7151 		},
   7152 	},
   7153 	1: {
   7154 		0: {
   7155 			0: uint8(134),
   7156 			1: uint8(183),
   7157 			2: uint8(89),
   7158 			3: uint8(137),
   7159 			4: uint8(98),
   7160 			5: uint8(101),
   7161 			6: uint8(106),
   7162 			7: uint8(165),
   7163 			8: uint8(148),
   7164 		},
   7165 		1: {
   7166 			0: uint8(72),
   7167 			1: uint8(187),
   7168 			2: uint8(100),
   7169 			3: uint8(130),
   7170 			4: uint8(157),
   7171 			5: uint8(111),
   7172 			6: uint8(32),
   7173 			7: uint8(75),
   7174 			8: uint8(80),
   7175 		},
   7176 		2: {
   7177 			0: uint8(66),
   7178 			1: uint8(102),
   7179 			2: uint8(167),
   7180 			3: uint8(99),
   7181 			4: uint8(74),
   7182 			5: uint8(62),
   7183 			6: uint8(40),
   7184 			7: uint8(234),
   7185 			8: uint8(128),
   7186 		},
   7187 		3: {
   7188 			0: uint8(41),
   7189 			1: uint8(53),
   7190 			2: uint8(9),
   7191 			3: uint8(178),
   7192 			4: uint8(241),
   7193 			5: uint8(141),
   7194 			6: uint8(26),
   7195 			7: uint8(8),
   7196 			8: uint8(107),
   7197 		},
   7198 		4: {
   7199 			0: uint8(74),
   7200 			1: uint8(43),
   7201 			2: uint8(26),
   7202 			3: uint8(146),
   7203 			4: uint8(73),
   7204 			5: uint8(166),
   7205 			6: uint8(49),
   7206 			7: uint8(23),
   7207 			8: uint8(157),
   7208 		},
   7209 		5: {
   7210 			0: uint8(65),
   7211 			1: uint8(38),
   7212 			2: uint8(105),
   7213 			3: uint8(160),
   7214 			4: uint8(51),
   7215 			5: uint8(52),
   7216 			6: uint8(31),
   7217 			7: uint8(115),
   7218 			8: uint8(128),
   7219 		},
   7220 		6: {
   7221 			0: uint8(104),
   7222 			1: uint8(79),
   7223 			2: uint8(12),
   7224 			3: uint8(27),
   7225 			4: uint8(217),
   7226 			5: uint8(255),
   7227 			6: uint8(87),
   7228 			7: uint8(17),
   7229 			8: uint8(7),
   7230 		},
   7231 		7: {
   7232 			0: uint8(87),
   7233 			1: uint8(68),
   7234 			2: uint8(71),
   7235 			3: uint8(44),
   7236 			4: uint8(114),
   7237 			5: uint8(51),
   7238 			6: uint8(15),
   7239 			7: uint8(186),
   7240 			8: uint8(23),
   7241 		},
   7242 		8: {
   7243 			0: uint8(47),
   7244 			1: uint8(41),
   7245 			2: uint8(14),
   7246 			3: uint8(110),
   7247 			4: uint8(182),
   7248 			5: uint8(183),
   7249 			6: uint8(21),
   7250 			7: uint8(17),
   7251 			8: uint8(194),
   7252 		},
   7253 		9: {
   7254 			0: uint8(66),
   7255 			1: uint8(45),
   7256 			2: uint8(25),
   7257 			3: uint8(102),
   7258 			4: uint8(197),
   7259 			5: uint8(189),
   7260 			6: uint8(23),
   7261 			7: uint8(18),
   7262 			8: uint8(22),
   7263 		},
   7264 	},
   7265 	2: {
   7266 		0: {
   7267 			0: uint8(88),
   7268 			1: uint8(88),
   7269 			2: uint8(147),
   7270 			3: uint8(150),
   7271 			4: uint8(42),
   7272 			5: uint8(46),
   7273 			6: uint8(45),
   7274 			7: uint8(196),
   7275 			8: uint8(205),
   7276 		},
   7277 		1: {
   7278 			0: uint8(43),
   7279 			1: uint8(97),
   7280 			2: uint8(183),
   7281 			3: uint8(117),
   7282 			4: uint8(85),
   7283 			5: uint8(38),
   7284 			6: uint8(35),
   7285 			7: uint8(179),
   7286 			8: uint8(61),
   7287 		},
   7288 		2: {
   7289 			0: uint8(39),
   7290 			1: uint8(53),
   7291 			2: uint8(200),
   7292 			3: uint8(87),
   7293 			4: uint8(26),
   7294 			5: uint8(21),
   7295 			6: uint8(43),
   7296 			7: uint8(232),
   7297 			8: uint8(171),
   7298 		},
   7299 		3: {
   7300 			0: uint8(56),
   7301 			1: uint8(34),
   7302 			2: uint8(51),
   7303 			3: uint8(104),
   7304 			4: uint8(114),
   7305 			5: uint8(102),
   7306 			6: uint8(29),
   7307 			7: uint8(93),
   7308 			8: uint8(77),
   7309 		},
   7310 		4: {
   7311 			0: uint8(39),
   7312 			1: uint8(28),
   7313 			2: uint8(85),
   7314 			3: uint8(171),
   7315 			4: uint8(58),
   7316 			5: uint8(165),
   7317 			6: uint8(90),
   7318 			7: uint8(98),
   7319 			8: uint8(64),
   7320 		},
   7321 		5: {
   7322 			0: uint8(34),
   7323 			1: uint8(22),
   7324 			2: uint8(116),
   7325 			3: uint8(206),
   7326 			4: uint8(23),
   7327 			5: uint8(34),
   7328 			6: uint8(43),
   7329 			7: uint8(166),
   7330 			8: uint8(73),
   7331 		},
   7332 		6: {
   7333 			0: uint8(107),
   7334 			1: uint8(54),
   7335 			2: uint8(32),
   7336 			3: uint8(26),
   7337 			4: uint8(51),
   7338 			5: uint8(1),
   7339 			6: uint8(81),
   7340 			7: uint8(43),
   7341 			8: uint8(31),
   7342 		},
   7343 		7: {
   7344 			0: uint8(68),
   7345 			1: uint8(25),
   7346 			2: uint8(106),
   7347 			3: uint8(22),
   7348 			4: uint8(64),
   7349 			5: uint8(171),
   7350 			6: uint8(36),
   7351 			7: uint8(225),
   7352 			8: uint8(114),
   7353 		},
   7354 		8: {
   7355 			0: uint8(34),
   7356 			1: uint8(19),
   7357 			2: uint8(21),
   7358 			3: uint8(102),
   7359 			4: uint8(132),
   7360 			5: uint8(188),
   7361 			6: uint8(16),
   7362 			7: uint8(76),
   7363 			8: uint8(124),
   7364 		},
   7365 		9: {
   7366 			0: uint8(62),
   7367 			1: uint8(18),
   7368 			2: uint8(78),
   7369 			3: uint8(95),
   7370 			4: uint8(85),
   7371 			5: uint8(57),
   7372 			6: uint8(50),
   7373 			7: uint8(48),
   7374 			8: uint8(51),
   7375 		},
   7376 	},
   7377 	3: {
   7378 		0: {
   7379 			0: uint8(193),
   7380 			1: uint8(101),
   7381 			2: uint8(35),
   7382 			3: uint8(159),
   7383 			4: uint8(215),
   7384 			5: uint8(111),
   7385 			6: uint8(89),
   7386 			7: uint8(46),
   7387 			8: uint8(111),
   7388 		},
   7389 		1: {
   7390 			0: uint8(60),
   7391 			1: uint8(148),
   7392 			2: uint8(31),
   7393 			3: uint8(172),
   7394 			4: uint8(219),
   7395 			5: uint8(228),
   7396 			6: uint8(21),
   7397 			7: uint8(18),
   7398 			8: uint8(111),
   7399 		},
   7400 		2: {
   7401 			0: uint8(112),
   7402 			1: uint8(113),
   7403 			2: uint8(77),
   7404 			3: uint8(85),
   7405 			4: uint8(179),
   7406 			5: uint8(255),
   7407 			6: uint8(38),
   7408 			7: uint8(120),
   7409 			8: uint8(114),
   7410 		},
   7411 		3: {
   7412 			0: uint8(40),
   7413 			1: uint8(42),
   7414 			2: uint8(1),
   7415 			3: uint8(196),
   7416 			4: uint8(245),
   7417 			5: uint8(209),
   7418 			6: uint8(10),
   7419 			7: uint8(25),
   7420 			8: uint8(109),
   7421 		},
   7422 		4: {
   7423 			0: uint8(88),
   7424 			1: uint8(43),
   7425 			2: uint8(29),
   7426 			3: uint8(140),
   7427 			4: uint8(166),
   7428 			5: uint8(213),
   7429 			6: uint8(37),
   7430 			7: uint8(43),
   7431 			8: uint8(154),
   7432 		},
   7433 		5: {
   7434 			0: uint8(61),
   7435 			1: uint8(63),
   7436 			2: uint8(30),
   7437 			3: uint8(155),
   7438 			4: uint8(67),
   7439 			5: uint8(45),
   7440 			6: uint8(68),
   7441 			7: uint8(1),
   7442 			8: uint8(209),
   7443 		},
   7444 		6: {
   7445 			0: uint8(100),
   7446 			1: uint8(80),
   7447 			2: uint8(8),
   7448 			3: uint8(43),
   7449 			4: uint8(154),
   7450 			5: uint8(1),
   7451 			6: uint8(51),
   7452 			7: uint8(26),
   7453 			8: uint8(71),
   7454 		},
   7455 		7: {
   7456 			0: uint8(142),
   7457 			1: uint8(78),
   7458 			2: uint8(78),
   7459 			3: uint8(16),
   7460 			4: uint8(255),
   7461 			5: uint8(128),
   7462 			6: uint8(34),
   7463 			7: uint8(197),
   7464 			8: uint8(171),
   7465 		},
   7466 		8: {
   7467 			0: uint8(41),
   7468 			1: uint8(40),
   7469 			2: uint8(5),
   7470 			3: uint8(102),
   7471 			4: uint8(211),
   7472 			5: uint8(183),
   7473 			6: uint8(4),
   7474 			7: uint8(1),
   7475 			8: uint8(221),
   7476 		},
   7477 		9: {
   7478 			0: uint8(51),
   7479 			1: uint8(50),
   7480 			2: uint8(17),
   7481 			3: uint8(168),
   7482 			4: uint8(209),
   7483 			5: uint8(192),
   7484 			6: uint8(23),
   7485 			7: uint8(25),
   7486 			8: uint8(82),
   7487 		},
   7488 	},
   7489 	4: {
   7490 		0: {
   7491 			0: uint8(138),
   7492 			1: uint8(31),
   7493 			2: uint8(36),
   7494 			3: uint8(171),
   7495 			4: uint8(27),
   7496 			5: uint8(166),
   7497 			6: uint8(38),
   7498 			7: uint8(44),
   7499 			8: uint8(229),
   7500 		},
   7501 		1: {
   7502 			0: uint8(67),
   7503 			1: uint8(87),
   7504 			2: uint8(58),
   7505 			3: uint8(169),
   7506 			4: uint8(82),
   7507 			5: uint8(115),
   7508 			6: uint8(26),
   7509 			7: uint8(59),
   7510 			8: uint8(179),
   7511 		},
   7512 		2: {
   7513 			0: uint8(63),
   7514 			1: uint8(59),
   7515 			2: uint8(90),
   7516 			3: uint8(180),
   7517 			4: uint8(59),
   7518 			5: uint8(166),
   7519 			6: uint8(93),
   7520 			7: uint8(73),
   7521 			8: uint8(154),
   7522 		},
   7523 		3: {
   7524 			0: uint8(40),
   7525 			1: uint8(40),
   7526 			2: uint8(21),
   7527 			3: uint8(116),
   7528 			4: uint8(143),
   7529 			5: uint8(209),
   7530 			6: uint8(34),
   7531 			7: uint8(39),
   7532 			8: uint8(175),
   7533 		},
   7534 		4: {
   7535 			0: uint8(47),
   7536 			1: uint8(15),
   7537 			2: uint8(16),
   7538 			3: uint8(183),
   7539 			4: uint8(34),
   7540 			5: uint8(223),
   7541 			6: uint8(49),
   7542 			7: uint8(45),
   7543 			8: uint8(183),
   7544 		},
   7545 		5: {
   7546 			0: uint8(46),
   7547 			1: uint8(17),
   7548 			2: uint8(33),
   7549 			3: uint8(183),
   7550 			4: uint8(6),
   7551 			5: uint8(98),
   7552 			6: uint8(15),
   7553 			7: uint8(32),
   7554 			8: uint8(183),
   7555 		},
   7556 		6: {
   7557 			0: uint8(57),
   7558 			1: uint8(46),
   7559 			2: uint8(22),
   7560 			3: uint8(24),
   7561 			4: uint8(128),
   7562 			5: uint8(1),
   7563 			6: uint8(54),
   7564 			7: uint8(17),
   7565 			8: uint8(37),
   7566 		},
   7567 		7: {
   7568 			0: uint8(65),
   7569 			1: uint8(32),
   7570 			2: uint8(73),
   7571 			3: uint8(115),
   7572 			4: uint8(28),
   7573 			5: uint8(128),
   7574 			6: uint8(23),
   7575 			7: uint8(128),
   7576 			8: uint8(205),
   7577 		},
   7578 		8: {
   7579 			0: uint8(40),
   7580 			1: uint8(3),
   7581 			2: uint8(9),
   7582 			3: uint8(115),
   7583 			4: uint8(51),
   7584 			5: uint8(192),
   7585 			6: uint8(18),
   7586 			7: uint8(6),
   7587 			8: uint8(223),
   7588 		},
   7589 		9: {
   7590 			0: uint8(87),
   7591 			1: uint8(37),
   7592 			2: uint8(9),
   7593 			3: uint8(115),
   7594 			4: uint8(59),
   7595 			5: uint8(77),
   7596 			6: uint8(64),
   7597 			7: uint8(21),
   7598 			8: uint8(47),
   7599 		},
   7600 	},
   7601 	5: {
   7602 		0: {
   7603 			0: uint8(104),
   7604 			1: uint8(55),
   7605 			2: uint8(44),
   7606 			3: uint8(218),
   7607 			4: uint8(9),
   7608 			5: uint8(54),
   7609 			6: uint8(53),
   7610 			7: uint8(130),
   7611 			8: uint8(226),
   7612 		},
   7613 		1: {
   7614 			0: uint8(64),
   7615 			1: uint8(90),
   7616 			2: uint8(70),
   7617 			3: uint8(205),
   7618 			4: uint8(40),
   7619 			5: uint8(41),
   7620 			6: uint8(23),
   7621 			7: uint8(26),
   7622 			8: uint8(57),
   7623 		},
   7624 		2: {
   7625 			0: uint8(54),
   7626 			1: uint8(57),
   7627 			2: uint8(112),
   7628 			3: uint8(184),
   7629 			4: uint8(5),
   7630 			5: uint8(41),
   7631 			6: uint8(38),
   7632 			7: uint8(166),
   7633 			8: uint8(213),
   7634 		},
   7635 		3: {
   7636 			0: uint8(30),
   7637 			1: uint8(34),
   7638 			2: uint8(26),
   7639 			3: uint8(133),
   7640 			4: uint8(152),
   7641 			5: uint8(116),
   7642 			6: uint8(10),
   7643 			7: uint8(32),
   7644 			8: uint8(134),
   7645 		},
   7646 		4: {
   7647 			0: uint8(39),
   7648 			1: uint8(19),
   7649 			2: uint8(53),
   7650 			3: uint8(221),
   7651 			4: uint8(26),
   7652 			5: uint8(114),
   7653 			6: uint8(32),
   7654 			7: uint8(73),
   7655 			8: uint8(255),
   7656 		},
   7657 		5: {
   7658 			0: uint8(31),
   7659 			1: uint8(9),
   7660 			2: uint8(65),
   7661 			3: uint8(234),
   7662 			4: uint8(2),
   7663 			5: uint8(15),
   7664 			6: uint8(1),
   7665 			7: uint8(118),
   7666 			8: uint8(73),
   7667 		},
   7668 		6: {
   7669 			0: uint8(75),
   7670 			1: uint8(32),
   7671 			2: uint8(12),
   7672 			3: uint8(51),
   7673 			4: uint8(192),
   7674 			5: uint8(255),
   7675 			6: uint8(160),
   7676 			7: uint8(43),
   7677 			8: uint8(51),
   7678 		},
   7679 		7: {
   7680 			0: uint8(88),
   7681 			1: uint8(31),
   7682 			2: uint8(35),
   7683 			3: uint8(67),
   7684 			4: uint8(102),
   7685 			5: uint8(85),
   7686 			6: uint8(55),
   7687 			7: uint8(186),
   7688 			8: uint8(85),
   7689 		},
   7690 		8: {
   7691 			0: uint8(56),
   7692 			1: uint8(21),
   7693 			2: uint8(23),
   7694 			3: uint8(111),
   7695 			4: uint8(59),
   7696 			5: uint8(205),
   7697 			6: uint8(45),
   7698 			7: uint8(37),
   7699 			8: uint8(192),
   7700 		},
   7701 		9: {
   7702 			0: uint8(55),
   7703 			1: uint8(38),
   7704 			2: uint8(70),
   7705 			3: uint8(124),
   7706 			4: uint8(73),
   7707 			5: uint8(102),
   7708 			6: uint8(1),
   7709 			7: uint8(34),
   7710 			8: uint8(98),
   7711 		},
   7712 	},
   7713 	6: {
   7714 		0: {
   7715 			0: uint8(125),
   7716 			1: uint8(98),
   7717 			2: uint8(42),
   7718 			3: uint8(88),
   7719 			4: uint8(104),
   7720 			5: uint8(85),
   7721 			6: uint8(117),
   7722 			7: uint8(175),
   7723 			8: uint8(82),
   7724 		},
   7725 		1: {
   7726 			0: uint8(95),
   7727 			1: uint8(84),
   7728 			2: uint8(53),
   7729 			3: uint8(89),
   7730 			4: uint8(128),
   7731 			5: uint8(100),
   7732 			6: uint8(113),
   7733 			7: uint8(101),
   7734 			8: uint8(45),
   7735 		},
   7736 		2: {
   7737 			0: uint8(75),
   7738 			1: uint8(79),
   7739 			2: uint8(123),
   7740 			3: uint8(47),
   7741 			4: uint8(51),
   7742 			5: uint8(128),
   7743 			6: uint8(81),
   7744 			7: uint8(171),
   7745 			8: uint8(1),
   7746 		},
   7747 		3: {
   7748 			0: uint8(57),
   7749 			1: uint8(17),
   7750 			2: uint8(5),
   7751 			3: uint8(71),
   7752 			4: uint8(102),
   7753 			5: uint8(57),
   7754 			6: uint8(53),
   7755 			7: uint8(41),
   7756 			8: uint8(49),
   7757 		},
   7758 		4: {
   7759 			0: uint8(38),
   7760 			1: uint8(33),
   7761 			2: uint8(13),
   7762 			3: uint8(121),
   7763 			4: uint8(57),
   7764 			5: uint8(73),
   7765 			6: uint8(26),
   7766 			7: uint8(1),
   7767 			8: uint8(85),
   7768 		},
   7769 		5: {
   7770 			0: uint8(41),
   7771 			1: uint8(10),
   7772 			2: uint8(67),
   7773 			3: uint8(138),
   7774 			4: uint8(77),
   7775 			5: uint8(110),
   7776 			6: uint8(90),
   7777 			7: uint8(47),
   7778 			8: uint8(114),
   7779 		},
   7780 		6: {
   7781 			0: uint8(115),
   7782 			1: uint8(21),
   7783 			2: uint8(2),
   7784 			3: uint8(10),
   7785 			4: uint8(102),
   7786 			5: uint8(255),
   7787 			6: uint8(166),
   7788 			7: uint8(23),
   7789 			8: uint8(6),
   7790 		},
   7791 		7: {
   7792 			0: uint8(101),
   7793 			1: uint8(29),
   7794 			2: uint8(16),
   7795 			3: uint8(10),
   7796 			4: uint8(85),
   7797 			5: uint8(128),
   7798 			6: uint8(101),
   7799 			7: uint8(196),
   7800 			8: uint8(26),
   7801 		},
   7802 		8: {
   7803 			0: uint8(57),
   7804 			1: uint8(18),
   7805 			2: uint8(10),
   7806 			3: uint8(102),
   7807 			4: uint8(102),
   7808 			5: uint8(213),
   7809 			6: uint8(34),
   7810 			7: uint8(20),
   7811 			8: uint8(43),
   7812 		},
   7813 		9: {
   7814 			0: uint8(117),
   7815 			1: uint8(20),
   7816 			2: uint8(15),
   7817 			3: uint8(36),
   7818 			4: uint8(163),
   7819 			5: uint8(128),
   7820 			6: uint8(68),
   7821 			7: uint8(1),
   7822 			8: uint8(26),
   7823 		},
   7824 	},
   7825 	7: {
   7826 		0: {
   7827 			0: uint8(102),
   7828 			1: uint8(61),
   7829 			2: uint8(71),
   7830 			3: uint8(37),
   7831 			4: uint8(34),
   7832 			5: uint8(53),
   7833 			6: uint8(31),
   7834 			7: uint8(243),
   7835 			8: uint8(192),
   7836 		},
   7837 		1: {
   7838 			0: uint8(69),
   7839 			1: uint8(60),
   7840 			2: uint8(71),
   7841 			3: uint8(38),
   7842 			4: uint8(73),
   7843 			5: uint8(119),
   7844 			6: uint8(28),
   7845 			7: uint8(222),
   7846 			8: uint8(37),
   7847 		},
   7848 		2: {
   7849 			0: uint8(68),
   7850 			1: uint8(45),
   7851 			2: uint8(128),
   7852 			3: uint8(34),
   7853 			4: uint8(1),
   7854 			5: uint8(47),
   7855 			6: uint8(11),
   7856 			7: uint8(245),
   7857 			8: uint8(171),
   7858 		},
   7859 		3: {
   7860 			0: uint8(62),
   7861 			1: uint8(17),
   7862 			2: uint8(19),
   7863 			3: uint8(70),
   7864 			4: uint8(146),
   7865 			5: uint8(85),
   7866 			6: uint8(55),
   7867 			7: uint8(62),
   7868 			8: uint8(70),
   7869 		},
   7870 		4: {
   7871 			0: uint8(37),
   7872 			1: uint8(43),
   7873 			2: uint8(37),
   7874 			3: uint8(154),
   7875 			4: uint8(100),
   7876 			5: uint8(163),
   7877 			6: uint8(85),
   7878 			7: uint8(160),
   7879 			8: uint8(1),
   7880 		},
   7881 		5: {
   7882 			0: uint8(63),
   7883 			1: uint8(9),
   7884 			2: uint8(92),
   7885 			3: uint8(136),
   7886 			4: uint8(28),
   7887 			5: uint8(64),
   7888 			6: uint8(32),
   7889 			7: uint8(201),
   7890 			8: uint8(85),
   7891 		},
   7892 		6: {
   7893 			0: uint8(75),
   7894 			1: uint8(15),
   7895 			2: uint8(9),
   7896 			3: uint8(9),
   7897 			4: uint8(64),
   7898 			5: uint8(255),
   7899 			6: uint8(184),
   7900 			7: uint8(119),
   7901 			8: uint8(16),
   7902 		},
   7903 		7: {
   7904 			0: uint8(86),
   7905 			1: uint8(6),
   7906 			2: uint8(28),
   7907 			3: uint8(5),
   7908 			4: uint8(64),
   7909 			5: uint8(255),
   7910 			6: uint8(25),
   7911 			7: uint8(248),
   7912 			8: uint8(1),
   7913 		},
   7914 		8: {
   7915 			0: uint8(56),
   7916 			1: uint8(8),
   7917 			2: uint8(17),
   7918 			3: uint8(132),
   7919 			4: uint8(137),
   7920 			5: uint8(255),
   7921 			6: uint8(55),
   7922 			7: uint8(116),
   7923 			8: uint8(128),
   7924 		},
   7925 		9: {
   7926 			0: uint8(58),
   7927 			1: uint8(15),
   7928 			2: uint8(20),
   7929 			3: uint8(82),
   7930 			4: uint8(135),
   7931 			5: uint8(57),
   7932 			6: uint8(26),
   7933 			7: uint8(121),
   7934 			8: uint8(40),
   7935 		},
   7936 	},
   7937 	8: {
   7938 		0: {
   7939 			0: uint8(164),
   7940 			1: uint8(50),
   7941 			2: uint8(31),
   7942 			3: uint8(137),
   7943 			4: uint8(154),
   7944 			5: uint8(133),
   7945 			6: uint8(25),
   7946 			7: uint8(35),
   7947 			8: uint8(218),
   7948 		},
   7949 		1: {
   7950 			0: uint8(51),
   7951 			1: uint8(103),
   7952 			2: uint8(44),
   7953 			3: uint8(131),
   7954 			4: uint8(131),
   7955 			5: uint8(123),
   7956 			6: uint8(31),
   7957 			7: uint8(6),
   7958 			8: uint8(158),
   7959 		},
   7960 		2: {
   7961 			0: uint8(86),
   7962 			1: uint8(40),
   7963 			2: uint8(64),
   7964 			3: uint8(135),
   7965 			4: uint8(148),
   7966 			5: uint8(224),
   7967 			6: uint8(45),
   7968 			7: uint8(183),
   7969 			8: uint8(128),
   7970 		},
   7971 		3: {
   7972 			0: uint8(22),
   7973 			1: uint8(26),
   7974 			2: uint8(17),
   7975 			3: uint8(131),
   7976 			4: uint8(240),
   7977 			5: uint8(154),
   7978 			6: uint8(14),
   7979 			7: uint8(1),
   7980 			8: uint8(209),
   7981 		},
   7982 		4: {
   7983 			0: uint8(45),
   7984 			1: uint8(16),
   7985 			2: uint8(21),
   7986 			3: uint8(91),
   7987 			4: uint8(64),
   7988 			5: uint8(222),
   7989 			6: uint8(7),
   7990 			7: uint8(1),
   7991 			8: uint8(197),
   7992 		},
   7993 		5: {
   7994 			0: uint8(56),
   7995 			1: uint8(21),
   7996 			2: uint8(39),
   7997 			3: uint8(155),
   7998 			4: uint8(60),
   7999 			5: uint8(138),
   8000 			6: uint8(23),
   8001 			7: uint8(102),
   8002 			8: uint8(213),
   8003 		},
   8004 		6: {
   8005 			0: uint8(83),
   8006 			1: uint8(12),
   8007 			2: uint8(13),
   8008 			3: uint8(54),
   8009 			4: uint8(192),
   8010 			5: uint8(255),
   8011 			6: uint8(68),
   8012 			7: uint8(47),
   8013 			8: uint8(28),
   8014 		},
   8015 		7: {
   8016 			0: uint8(85),
   8017 			1: uint8(26),
   8018 			2: uint8(85),
   8019 			3: uint8(85),
   8020 			4: uint8(128),
   8021 			5: uint8(128),
   8022 			6: uint8(32),
   8023 			7: uint8(146),
   8024 			8: uint8(171),
   8025 		},
   8026 		8: {
   8027 			0: uint8(18),
   8028 			1: uint8(11),
   8029 			2: uint8(7),
   8030 			3: uint8(63),
   8031 			4: uint8(144),
   8032 			5: uint8(171),
   8033 			6: uint8(4),
   8034 			7: uint8(4),
   8035 			8: uint8(246),
   8036 		},
   8037 		9: {
   8038 			0: uint8(35),
   8039 			1: uint8(27),
   8040 			2: uint8(10),
   8041 			3: uint8(146),
   8042 			4: uint8(174),
   8043 			5: uint8(171),
   8044 			6: uint8(12),
   8045 			7: uint8(26),
   8046 			8: uint8(128),
   8047 		},
   8048 	},
   8049 	9: {
   8050 		0: {
   8051 			0: uint8(190),
   8052 			1: uint8(80),
   8053 			2: uint8(35),
   8054 			3: uint8(99),
   8055 			4: uint8(180),
   8056 			5: uint8(80),
   8057 			6: uint8(126),
   8058 			7: uint8(54),
   8059 			8: uint8(45),
   8060 		},
   8061 		1: {
   8062 			0: uint8(85),
   8063 			1: uint8(126),
   8064 			2: uint8(47),
   8065 			3: uint8(87),
   8066 			4: uint8(176),
   8067 			5: uint8(51),
   8068 			6: uint8(41),
   8069 			7: uint8(20),
   8070 			8: uint8(32),
   8071 		},
   8072 		2: {
   8073 			0: uint8(101),
   8074 			1: uint8(75),
   8075 			2: uint8(128),
   8076 			3: uint8(139),
   8077 			4: uint8(118),
   8078 			5: uint8(146),
   8079 			6: uint8(116),
   8080 			7: uint8(128),
   8081 			8: uint8(85),
   8082 		},
   8083 		3: {
   8084 			0: uint8(56),
   8085 			1: uint8(41),
   8086 			2: uint8(15),
   8087 			3: uint8(176),
   8088 			4: uint8(236),
   8089 			5: uint8(85),
   8090 			6: uint8(37),
   8091 			7: uint8(9),
   8092 			8: uint8(62),
   8093 		},
   8094 		4: {
   8095 			0: uint8(71),
   8096 			1: uint8(30),
   8097 			2: uint8(17),
   8098 			3: uint8(119),
   8099 			4: uint8(118),
   8100 			5: uint8(255),
   8101 			6: uint8(17),
   8102 			7: uint8(18),
   8103 			8: uint8(138),
   8104 		},
   8105 		5: {
   8106 			0: uint8(101),
   8107 			1: uint8(38),
   8108 			2: uint8(60),
   8109 			3: uint8(138),
   8110 			4: uint8(55),
   8111 			5: uint8(70),
   8112 			6: uint8(43),
   8113 			7: uint8(26),
   8114 			8: uint8(142),
   8115 		},
   8116 		6: {
   8117 			0: uint8(146),
   8118 			1: uint8(36),
   8119 			2: uint8(19),
   8120 			3: uint8(30),
   8121 			4: uint8(171),
   8122 			5: uint8(255),
   8123 			6: uint8(97),
   8124 			7: uint8(27),
   8125 			8: uint8(20),
   8126 		},
   8127 		7: {
   8128 			0: uint8(138),
   8129 			1: uint8(45),
   8130 			2: uint8(61),
   8131 			3: uint8(62),
   8132 			4: uint8(219),
   8133 			5: uint8(1),
   8134 			6: uint8(81),
   8135 			7: uint8(188),
   8136 			8: uint8(64),
   8137 		},
   8138 		8: {
   8139 			0: uint8(32),
   8140 			1: uint8(41),
   8141 			2: uint8(20),
   8142 			3: uint8(117),
   8143 			4: uint8(151),
   8144 			5: uint8(142),
   8145 			6: uint8(20),
   8146 			7: uint8(21),
   8147 			8: uint8(163),
   8148 		},
   8149 		9: {
   8150 			0: uint8(112),
   8151 			1: uint8(19),
   8152 			2: uint8(12),
   8153 			3: uint8(61),
   8154 			4: uint8(195),
   8155 			5: uint8(128),
   8156 			6: uint8(48),
   8157 			7: uint8(4),
   8158 			8: uint8(24),
   8159 		},
   8160 	},
   8161 }
   8162 
   8163 func VP8ResetProba(tls *libc.TLS, proba uintptr) {
   8164 	libc.Xmemset(tls, proba, libc.Int32FromUint32(255), uint64(3))
   8165 	// proba->bands[][] is initialized later
   8166 }
   8167 
   8168 func ParseIntraMode(tls *libc.TLS, br2 uintptr, dec uintptr, mb_x int32) {
   8169 	bp := tls.Alloc(16)
   8170 	defer tls.Free(16)
   8171 	var bit, i, pos, shift, x1, y, ymode, ymode1, v1, v14, v16, v22, v24, v30, v32, v6, v8 int32
   8172 	var bits bit_t
   8173 	var block, left, modes, prob1, top, v10, v11, v18, v19, v2, v3 uintptr
   8174 	var range1, split, value range_t
   8175 	var v12, v20, v4 uint64_t
   8176 	var _ /* in_bits at bp+0 */ lbit_t
   8177 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = bit, bits, block, i, left, modes, pos, prob1, range1, shift, split, top, value, x1, y, ymode, ymode1, v1, v10, v11, v12, v14, v16, v18, v19, v2, v20, v22, v24, v3, v30, v32, v4, v6, v8
   8178 	top = (*VP8Decoder)(unsafe.Pointer(dec)).Fintra_t + uintptr(int32(4)*mb_x)
   8179 	left = dec + 2816
   8180 	block = (*VP8Decoder)(unsafe.Pointer(dec)).Fmb_data + uintptr(mb_x)*800
   8181 	// Note: we don't save segment map (yet), as we don't expect
   8182 	// to decode more than 1 keyframe.
   8183 	if (*VP8Decoder)(unsafe.Pointer(dec)).Fsegment_hdr.Fupdate_map != 0 {
   8184 		// Hardcoded tree parsing
   8185 		v2 = br2
   8186 		range1 = (*VP8BitReader)(unsafe.Pointer(v2)).Frange1
   8187 		if (*VP8BitReader)(unsafe.Pointer(v2)).Fbits < libc.Int32FromInt32(0) {
   8188 			v3 = v2
   8189 			if (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf < (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf_max {
   8190 				libc.Xmemcpy(tls, bp, (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf, uint64(8))
   8191 				**(**uintptr)(__ccgo_up(v3 + 16)) += uintptr(libc.Int32FromInt32(BITS) >> libc.Int32FromInt32(3))
   8192 				v4 = libc.X__builtin_bswap64(tls, **(**lbit_t)(__ccgo_up(bp)))
   8193 				goto _5
   8194 			_5:
   8195 				bits = v4
   8196 				bits = bits >> uint64(libc.Int32FromInt32(64)-libc.Int32FromInt32(BITS))
   8197 				(*VP8BitReader)(unsafe.Pointer(v3)).Fvalue = bits | (*VP8BitReader)(unsafe.Pointer(v3)).Fvalue<<libc.Int32FromInt32(BITS)
   8198 				**(**int32)(__ccgo_up(v3 + 12)) += int32(BITS)
   8199 			} else {
   8200 				VP8LoadFinalBytes(tls, v3)
   8201 			}
   8202 		}
   8203 		pos = (*VP8BitReader)(unsafe.Pointer(v2)).Fbits
   8204 		split = range1 * uint32(int32(**(**uint8_t)(__ccgo_up(dec + 1192)))) >> int32(8)
   8205 		value = uint32((*VP8BitReader)(unsafe.Pointer(v2)).Fvalue >> pos)
   8206 		bit = libc.BoolInt32(value > split)
   8207 		if bit != 0 {
   8208 			range1 = range1 - split
   8209 			**(**bit_t)(__ccgo_up(v2)) -= uint64(split+libc.Uint32FromInt32(1)) << pos
   8210 		} else {
   8211 			range1 = split + uint32(1)
   8212 		}
   8213 		v6 = int32(31) ^ libc.X__builtin_clz(tls, range1)
   8214 		goto _7
   8215 	_7:
   8216 		shift = int32(7) ^ v6
   8217 		range1 = range1 << uint32(shift)
   8218 		**(**int32)(__ccgo_up(v2 + 12)) -= shift
   8219 		(*VP8BitReader)(unsafe.Pointer(v2)).Frange1 = range1 - uint32(1)
   8220 		v8 = bit
   8221 		goto _9
   8222 	_9:
   8223 		if !(v8 != 0) {
   8224 			v10 = br2
   8225 			range1 = (*VP8BitReader)(unsafe.Pointer(v10)).Frange1
   8226 			if (*VP8BitReader)(unsafe.Pointer(v10)).Fbits < libc.Int32FromInt32(0) {
   8227 				v11 = v10
   8228 				if (*VP8BitReader)(unsafe.Pointer(v11)).Fbuf < (*VP8BitReader)(unsafe.Pointer(v11)).Fbuf_max {
   8229 					libc.Xmemcpy(tls, bp, (*VP8BitReader)(unsafe.Pointer(v11)).Fbuf, uint64(8))
   8230 					**(**uintptr)(__ccgo_up(v11 + 16)) += uintptr(libc.Int32FromInt32(BITS) >> libc.Int32FromInt32(3))
   8231 					v12 = libc.X__builtin_bswap64(tls, **(**lbit_t)(__ccgo_up(bp)))
   8232 					goto _13
   8233 				_13:
   8234 					bits = v12
   8235 					bits = bits >> uint64(libc.Int32FromInt32(64)-libc.Int32FromInt32(BITS))
   8236 					(*VP8BitReader)(unsafe.Pointer(v11)).Fvalue = bits | (*VP8BitReader)(unsafe.Pointer(v11)).Fvalue<<libc.Int32FromInt32(BITS)
   8237 					**(**int32)(__ccgo_up(v11 + 12)) += int32(BITS)
   8238 				} else {
   8239 					VP8LoadFinalBytes(tls, v11)
   8240 				}
   8241 			}
   8242 			pos = (*VP8BitReader)(unsafe.Pointer(v10)).Fbits
   8243 			split = range1 * uint32(int32(**(**uint8_t)(__ccgo_up(dec + 1192 + 1)))) >> int32(8)
   8244 			value = uint32((*VP8BitReader)(unsafe.Pointer(v10)).Fvalue >> pos)
   8245 			bit = libc.BoolInt32(value > split)
   8246 			if bit != 0 {
   8247 				range1 = range1 - split
   8248 				**(**bit_t)(__ccgo_up(v10)) -= uint64(split+libc.Uint32FromInt32(1)) << pos
   8249 			} else {
   8250 				range1 = split + uint32(1)
   8251 			}
   8252 			v14 = int32(31) ^ libc.X__builtin_clz(tls, range1)
   8253 			goto _15
   8254 		_15:
   8255 			shift = int32(7) ^ v14
   8256 			range1 = range1 << uint32(shift)
   8257 			**(**int32)(__ccgo_up(v10 + 12)) -= shift
   8258 			(*VP8BitReader)(unsafe.Pointer(v10)).Frange1 = range1 - uint32(1)
   8259 			v16 = bit
   8260 			goto _17
   8261 		_17:
   8262 			v1 = v16
   8263 		} else {
   8264 			v18 = br2
   8265 			range1 = (*VP8BitReader)(unsafe.Pointer(v18)).Frange1
   8266 			if (*VP8BitReader)(unsafe.Pointer(v18)).Fbits < libc.Int32FromInt32(0) {
   8267 				v19 = v18
   8268 				if (*VP8BitReader)(unsafe.Pointer(v19)).Fbuf < (*VP8BitReader)(unsafe.Pointer(v19)).Fbuf_max {
   8269 					libc.Xmemcpy(tls, bp, (*VP8BitReader)(unsafe.Pointer(v19)).Fbuf, uint64(8))
   8270 					**(**uintptr)(__ccgo_up(v19 + 16)) += uintptr(libc.Int32FromInt32(BITS) >> libc.Int32FromInt32(3))
   8271 					v20 = libc.X__builtin_bswap64(tls, **(**lbit_t)(__ccgo_up(bp)))
   8272 					goto _21
   8273 				_21:
   8274 					bits = v20
   8275 					bits = bits >> uint64(libc.Int32FromInt32(64)-libc.Int32FromInt32(BITS))
   8276 					(*VP8BitReader)(unsafe.Pointer(v19)).Fvalue = bits | (*VP8BitReader)(unsafe.Pointer(v19)).Fvalue<<libc.Int32FromInt32(BITS)
   8277 					**(**int32)(__ccgo_up(v19 + 12)) += int32(BITS)
   8278 				} else {
   8279 					VP8LoadFinalBytes(tls, v19)
   8280 				}
   8281 			}
   8282 			pos = (*VP8BitReader)(unsafe.Pointer(v18)).Fbits
   8283 			split = range1 * uint32(int32(**(**uint8_t)(__ccgo_up(dec + 1192 + 2)))) >> int32(8)
   8284 			value = uint32((*VP8BitReader)(unsafe.Pointer(v18)).Fvalue >> pos)
   8285 			bit = libc.BoolInt32(value > split)
   8286 			if bit != 0 {
   8287 				range1 = range1 - split
   8288 				**(**bit_t)(__ccgo_up(v18)) -= uint64(split+libc.Uint32FromInt32(1)) << pos
   8289 			} else {
   8290 				range1 = split + uint32(1)
   8291 			}
   8292 			v22 = int32(31) ^ libc.X__builtin_clz(tls, range1)
   8293 			goto _23
   8294 		_23:
   8295 			shift = int32(7) ^ v22
   8296 			range1 = range1 << uint32(shift)
   8297 			**(**int32)(__ccgo_up(v18 + 12)) -= shift
   8298 			(*VP8BitReader)(unsafe.Pointer(v18)).Frange1 = range1 - uint32(1)
   8299 			v24 = bit
   8300 			goto _25
   8301 		_25:
   8302 			v1 = v24 + int32(2)
   8303 		}
   8304 		(*VP8MBData)(unsafe.Pointer(block)).Fsegment = uint8(v1)
   8305 	} else {
   8306 		(*VP8MBData)(unsafe.Pointer(block)).Fsegment = uint8(0) // default for intra
   8307 	}
   8308 	if (*VP8Decoder)(unsafe.Pointer(dec)).Fuse_skip_proba != 0 {
   8309 		v2 = br2
   8310 		range1 = (*VP8BitReader)(unsafe.Pointer(v2)).Frange1
   8311 		if (*VP8BitReader)(unsafe.Pointer(v2)).Fbits < libc.Int32FromInt32(0) {
   8312 			v3 = v2
   8313 			if (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf < (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf_max {
   8314 				libc.Xmemcpy(tls, bp, (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf, uint64(8))
   8315 				**(**uintptr)(__ccgo_up(v3 + 16)) += uintptr(libc.Int32FromInt32(BITS) >> libc.Int32FromInt32(3))
   8316 				v4 = libc.X__builtin_bswap64(tls, **(**lbit_t)(__ccgo_up(bp)))
   8317 				goto _29
   8318 			_29:
   8319 				bits = v4
   8320 				bits = bits >> uint64(libc.Int32FromInt32(64)-libc.Int32FromInt32(BITS))
   8321 				(*VP8BitReader)(unsafe.Pointer(v3)).Fvalue = bits | (*VP8BitReader)(unsafe.Pointer(v3)).Fvalue<<libc.Int32FromInt32(BITS)
   8322 				**(**int32)(__ccgo_up(v3 + 12)) += int32(BITS)
   8323 			} else {
   8324 				VP8LoadFinalBytes(tls, v3)
   8325 			}
   8326 		}
   8327 		pos = (*VP8BitReader)(unsafe.Pointer(v2)).Fbits
   8328 		split = range1 * uint32(int32((*VP8Decoder)(unsafe.Pointer(dec)).Fskip_p)) >> int32(8)
   8329 		value = uint32((*VP8BitReader)(unsafe.Pointer(v2)).Fvalue >> pos)
   8330 		bit = libc.BoolInt32(value > split)
   8331 		if bit != 0 {
   8332 			range1 = range1 - split
   8333 			**(**bit_t)(__ccgo_up(v2)) -= uint64(split+libc.Uint32FromInt32(1)) << pos
   8334 		} else {
   8335 			range1 = split + uint32(1)
   8336 		}
   8337 		v1 = int32(31) ^ libc.X__builtin_clz(tls, range1)
   8338 		goto _31
   8339 	_31:
   8340 		shift = int32(7) ^ v1
   8341 		range1 = range1 << uint32(shift)
   8342 		**(**int32)(__ccgo_up(v2 + 12)) -= shift
   8343 		(*VP8BitReader)(unsafe.Pointer(v2)).Frange1 = range1 - uint32(1)
   8344 		v6 = bit
   8345 		goto _33
   8346 	_33:
   8347 		(*VP8MBData)(unsafe.Pointer(block)).Fskip = uint8(v6)
   8348 	}
   8349 	v2 = br2
   8350 	range1 = (*VP8BitReader)(unsafe.Pointer(v2)).Frange1
   8351 	if (*VP8BitReader)(unsafe.Pointer(v2)).Fbits < libc.Int32FromInt32(0) {
   8352 		v3 = v2
   8353 		if (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf < (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf_max {
   8354 			libc.Xmemcpy(tls, bp, (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf, uint64(8))
   8355 			**(**uintptr)(__ccgo_up(v3 + 16)) += uintptr(libc.Int32FromInt32(BITS) >> libc.Int32FromInt32(3))
   8356 			v4 = libc.X__builtin_bswap64(tls, **(**lbit_t)(__ccgo_up(bp)))
   8357 			goto _37
   8358 		_37:
   8359 			bits = v4
   8360 			bits = bits >> uint64(libc.Int32FromInt32(64)-libc.Int32FromInt32(BITS))
   8361 			(*VP8BitReader)(unsafe.Pointer(v3)).Fvalue = bits | (*VP8BitReader)(unsafe.Pointer(v3)).Fvalue<<libc.Int32FromInt32(BITS)
   8362 			**(**int32)(__ccgo_up(v3 + 12)) += int32(BITS)
   8363 		} else {
   8364 			VP8LoadFinalBytes(tls, v3)
   8365 		}
   8366 	}
   8367 	pos = (*VP8BitReader)(unsafe.Pointer(v2)).Fbits
   8368 	split = range1 * uint32(int32(145)) >> int32(8)
   8369 	value = uint32((*VP8BitReader)(unsafe.Pointer(v2)).Fvalue >> pos)
   8370 	bit = libc.BoolInt32(value > split)
   8371 	if bit != 0 {
   8372 		range1 = range1 - split
   8373 		**(**bit_t)(__ccgo_up(v2)) -= uint64(split+libc.Uint32FromInt32(1)) << pos
   8374 	} else {
   8375 		range1 = split + uint32(1)
   8376 	}
   8377 	v1 = int32(31) ^ libc.X__builtin_clz(tls, range1)
   8378 	goto _39
   8379 _39:
   8380 	shift = int32(7) ^ v1
   8381 	range1 = range1 << uint32(shift)
   8382 	**(**int32)(__ccgo_up(v2 + 12)) -= shift
   8383 	(*VP8BitReader)(unsafe.Pointer(v2)).Frange1 = range1 - uint32(1)
   8384 	v6 = bit
   8385 	goto _41
   8386 _41:
   8387 	(*VP8MBData)(unsafe.Pointer(block)).Fis_i4x4 = libc.BoolUint8(!(v6 != 0))
   8388 	if !((*VP8MBData)(unsafe.Pointer(block)).Fis_i4x4 != 0) {
   8389 		v2 = br2
   8390 		range1 = (*VP8BitReader)(unsafe.Pointer(v2)).Frange1
   8391 		if (*VP8BitReader)(unsafe.Pointer(v2)).Fbits < libc.Int32FromInt32(0) {
   8392 			v3 = v2
   8393 			if (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf < (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf_max {
   8394 				libc.Xmemcpy(tls, bp, (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf, uint64(8))
   8395 				**(**uintptr)(__ccgo_up(v3 + 16)) += uintptr(libc.Int32FromInt32(BITS) >> libc.Int32FromInt32(3))
   8396 				v4 = libc.X__builtin_bswap64(tls, **(**lbit_t)(__ccgo_up(bp)))
   8397 				goto _46
   8398 			_46:
   8399 				bits = v4
   8400 				bits = bits >> uint64(libc.Int32FromInt32(64)-libc.Int32FromInt32(BITS))
   8401 				(*VP8BitReader)(unsafe.Pointer(v3)).Fvalue = bits | (*VP8BitReader)(unsafe.Pointer(v3)).Fvalue<<libc.Int32FromInt32(BITS)
   8402 				**(**int32)(__ccgo_up(v3 + 12)) += int32(BITS)
   8403 			} else {
   8404 				VP8LoadFinalBytes(tls, v3)
   8405 			}
   8406 		}
   8407 		pos = (*VP8BitReader)(unsafe.Pointer(v2)).Fbits
   8408 		split = range1 * uint32(int32(156)) >> int32(8)
   8409 		value = uint32((*VP8BitReader)(unsafe.Pointer(v2)).Fvalue >> pos)
   8410 		bit = libc.BoolInt32(value > split)
   8411 		if bit != 0 {
   8412 			range1 = range1 - split
   8413 			**(**bit_t)(__ccgo_up(v2)) -= uint64(split+libc.Uint32FromInt32(1)) << pos
   8414 		} else {
   8415 			range1 = split + uint32(1)
   8416 		}
   8417 		v6 = int32(31) ^ libc.X__builtin_clz(tls, range1)
   8418 		goto _48
   8419 	_48:
   8420 		shift = int32(7) ^ v6
   8421 		range1 = range1 << uint32(shift)
   8422 		**(**int32)(__ccgo_up(v2 + 12)) -= shift
   8423 		(*VP8BitReader)(unsafe.Pointer(v2)).Frange1 = range1 - uint32(1)
   8424 		v8 = bit
   8425 		goto _50
   8426 	_50:
   8427 		if v8 != 0 {
   8428 			v10 = br2
   8429 			range1 = (*VP8BitReader)(unsafe.Pointer(v10)).Frange1
   8430 			if (*VP8BitReader)(unsafe.Pointer(v10)).Fbits < libc.Int32FromInt32(0) {
   8431 				v11 = v10
   8432 				if (*VP8BitReader)(unsafe.Pointer(v11)).Fbuf < (*VP8BitReader)(unsafe.Pointer(v11)).Fbuf_max {
   8433 					libc.Xmemcpy(tls, bp, (*VP8BitReader)(unsafe.Pointer(v11)).Fbuf, uint64(8))
   8434 					**(**uintptr)(__ccgo_up(v11 + 16)) += uintptr(libc.Int32FromInt32(BITS) >> libc.Int32FromInt32(3))
   8435 					v12 = libc.X__builtin_bswap64(tls, **(**lbit_t)(__ccgo_up(bp)))
   8436 					goto _55
   8437 				_55:
   8438 					bits = v12
   8439 					bits = bits >> uint64(libc.Int32FromInt32(64)-libc.Int32FromInt32(BITS))
   8440 					(*VP8BitReader)(unsafe.Pointer(v11)).Fvalue = bits | (*VP8BitReader)(unsafe.Pointer(v11)).Fvalue<<libc.Int32FromInt32(BITS)
   8441 					**(**int32)(__ccgo_up(v11 + 12)) += int32(BITS)
   8442 				} else {
   8443 					VP8LoadFinalBytes(tls, v11)
   8444 				}
   8445 			}
   8446 			pos = (*VP8BitReader)(unsafe.Pointer(v10)).Fbits
   8447 			split = range1 * uint32(int32(128)) >> int32(8)
   8448 			value = uint32((*VP8BitReader)(unsafe.Pointer(v10)).Fvalue >> pos)
   8449 			bit = libc.BoolInt32(value > split)
   8450 			if bit != 0 {
   8451 				range1 = range1 - split
   8452 				**(**bit_t)(__ccgo_up(v10)) -= uint64(split+libc.Uint32FromInt32(1)) << pos
   8453 			} else {
   8454 				range1 = split + uint32(1)
   8455 			}
   8456 			v16 = int32(31) ^ libc.X__builtin_clz(tls, range1)
   8457 			goto _57
   8458 		_57:
   8459 			shift = int32(7) ^ v16
   8460 			range1 = range1 << uint32(shift)
   8461 			**(**int32)(__ccgo_up(v10 + 12)) -= shift
   8462 			(*VP8BitReader)(unsafe.Pointer(v10)).Frange1 = range1 - uint32(1)
   8463 			v22 = bit
   8464 			goto _59
   8465 		_59:
   8466 			if v22 != 0 {
   8467 				v14 = int32(TM_PRED)
   8468 			} else {
   8469 				v14 = int32(H_PRED)
   8470 			}
   8471 			v1 = v14
   8472 		} else {
   8473 			v18 = br2
   8474 			range1 = (*VP8BitReader)(unsafe.Pointer(v18)).Frange1
   8475 			if (*VP8BitReader)(unsafe.Pointer(v18)).Fbits < libc.Int32FromInt32(0) {
   8476 				v19 = v18
   8477 				if (*VP8BitReader)(unsafe.Pointer(v19)).Fbuf < (*VP8BitReader)(unsafe.Pointer(v19)).Fbuf_max {
   8478 					libc.Xmemcpy(tls, bp, (*VP8BitReader)(unsafe.Pointer(v19)).Fbuf, uint64(8))
   8479 					**(**uintptr)(__ccgo_up(v19 + 16)) += uintptr(libc.Int32FromInt32(BITS) >> libc.Int32FromInt32(3))
   8480 					v20 = libc.X__builtin_bswap64(tls, **(**lbit_t)(__ccgo_up(bp)))
   8481 					goto _64
   8482 				_64:
   8483 					bits = v20
   8484 					bits = bits >> uint64(libc.Int32FromInt32(64)-libc.Int32FromInt32(BITS))
   8485 					(*VP8BitReader)(unsafe.Pointer(v19)).Fvalue = bits | (*VP8BitReader)(unsafe.Pointer(v19)).Fvalue<<libc.Int32FromInt32(BITS)
   8486 					**(**int32)(__ccgo_up(v19 + 12)) += int32(BITS)
   8487 				} else {
   8488 					VP8LoadFinalBytes(tls, v19)
   8489 				}
   8490 			}
   8491 			pos = (*VP8BitReader)(unsafe.Pointer(v18)).Fbits
   8492 			split = range1 * uint32(int32(163)) >> int32(8)
   8493 			value = uint32((*VP8BitReader)(unsafe.Pointer(v18)).Fvalue >> pos)
   8494 			bit = libc.BoolInt32(value > split)
   8495 			if bit != 0 {
   8496 				range1 = range1 - split
   8497 				**(**bit_t)(__ccgo_up(v18)) -= uint64(split+libc.Uint32FromInt32(1)) << pos
   8498 			} else {
   8499 				range1 = split + uint32(1)
   8500 			}
   8501 			v30 = int32(31) ^ libc.X__builtin_clz(tls, range1)
   8502 			goto _66
   8503 		_66:
   8504 			shift = int32(7) ^ v30
   8505 			range1 = range1 << uint32(shift)
   8506 			**(**int32)(__ccgo_up(v18 + 12)) -= shift
   8507 			(*VP8BitReader)(unsafe.Pointer(v18)).Frange1 = range1 - uint32(1)
   8508 			v32 = bit
   8509 			goto _68
   8510 		_68:
   8511 			if v32 != 0 {
   8512 				v24 = int32(V_PRED)
   8513 			} else {
   8514 				v24 = int32(DC_PRED)
   8515 			}
   8516 			v1 = v24
   8517 		}
   8518 		// Hardcoded 16x16 intra-mode decision tree.
   8519 		ymode = v1
   8520 		**(**uint8_t)(__ccgo_up(block + 769)) = uint8(ymode)
   8521 		libc.Xmemset(tls, top, ymode, libc.Uint64FromInt32(4)*libc.Uint64FromInt64(1))
   8522 		libc.Xmemset(tls, left, ymode, libc.Uint64FromInt32(4)*libc.Uint64FromInt64(1))
   8523 	} else {
   8524 		modes = block + 769
   8525 		y = 0
   8526 		for {
   8527 			if !(y < int32(4)) {
   8528 				break
   8529 			}
   8530 			ymode1 = int32(**(**uint8_t)(__ccgo_up(left + uintptr(y))))
   8531 			x1 = 0
   8532 			for {
   8533 				if !(x1 < int32(4)) {
   8534 					break
   8535 				}
   8536 				prob1 = uintptr(unsafe.Pointer(&kBModesProba)) + uintptr(**(**uint8_t)(__ccgo_up(top + uintptr(x1))))*90 + uintptr(ymode1)*9
   8537 				v2 = br2
   8538 				range1 = (*VP8BitReader)(unsafe.Pointer(v2)).Frange1
   8539 				if (*VP8BitReader)(unsafe.Pointer(v2)).Fbits < libc.Int32FromInt32(0) {
   8540 					v3 = v2
   8541 					if (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf < (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf_max {
   8542 						libc.Xmemcpy(tls, bp, (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf, uint64(8))
   8543 						**(**uintptr)(__ccgo_up(v3 + 16)) += uintptr(libc.Int32FromInt32(BITS) >> libc.Int32FromInt32(3))
   8544 						v4 = libc.X__builtin_bswap64(tls, **(**lbit_t)(__ccgo_up(bp)))
   8545 						goto _74
   8546 					_74:
   8547 						bits = v4
   8548 						bits = bits >> uint64(libc.Int32FromInt32(64)-libc.Int32FromInt32(BITS))
   8549 						(*VP8BitReader)(unsafe.Pointer(v3)).Fvalue = bits | (*VP8BitReader)(unsafe.Pointer(v3)).Fvalue<<libc.Int32FromInt32(BITS)
   8550 						**(**int32)(__ccgo_up(v3 + 12)) += int32(BITS)
   8551 					} else {
   8552 						VP8LoadFinalBytes(tls, v3)
   8553 					}
   8554 				}
   8555 				pos = (*VP8BitReader)(unsafe.Pointer(v2)).Fbits
   8556 				split = range1 * uint32(int32(**(**uint8_t)(__ccgo_up(prob1)))) >> int32(8)
   8557 				value = uint32((*VP8BitReader)(unsafe.Pointer(v2)).Fvalue >> pos)
   8558 				bit = libc.BoolInt32(value > split)
   8559 				if bit != 0 {
   8560 					range1 = range1 - split
   8561 					**(**bit_t)(__ccgo_up(v2)) -= uint64(split+libc.Uint32FromInt32(1)) << pos
   8562 				} else {
   8563 					range1 = split + uint32(1)
   8564 				}
   8565 				v1 = int32(31) ^ libc.X__builtin_clz(tls, range1)
   8566 				goto _76
   8567 			_76:
   8568 				shift = int32(7) ^ v1
   8569 				range1 = range1 << uint32(shift)
   8570 				**(**int32)(__ccgo_up(v2 + 12)) -= shift
   8571 				(*VP8BitReader)(unsafe.Pointer(v2)).Frange1 = range1 - uint32(1)
   8572 				v6 = bit
   8573 				goto _78
   8574 			_78:
   8575 				// Generic tree-parsing
   8576 				i = int32(kYModesIntra4[v6])
   8577 				for i > 0 {
   8578 					v10 = br2
   8579 					range1 = (*VP8BitReader)(unsafe.Pointer(v10)).Frange1
   8580 					if (*VP8BitReader)(unsafe.Pointer(v10)).Fbits < libc.Int32FromInt32(0) {
   8581 						v11 = v10
   8582 						if (*VP8BitReader)(unsafe.Pointer(v11)).Fbuf < (*VP8BitReader)(unsafe.Pointer(v11)).Fbuf_max {
   8583 							libc.Xmemcpy(tls, bp, (*VP8BitReader)(unsafe.Pointer(v11)).Fbuf, uint64(8))
   8584 							**(**uintptr)(__ccgo_up(v11 + 16)) += uintptr(libc.Int32FromInt32(BITS) >> libc.Int32FromInt32(3))
   8585 							v12 = libc.X__builtin_bswap64(tls, **(**lbit_t)(__ccgo_up(bp)))
   8586 							goto _82
   8587 						_82:
   8588 							bits = v12
   8589 							bits = bits >> uint64(libc.Int32FromInt32(64)-libc.Int32FromInt32(BITS))
   8590 							(*VP8BitReader)(unsafe.Pointer(v11)).Fvalue = bits | (*VP8BitReader)(unsafe.Pointer(v11)).Fvalue<<libc.Int32FromInt32(BITS)
   8591 							**(**int32)(__ccgo_up(v11 + 12)) += int32(BITS)
   8592 						} else {
   8593 							VP8LoadFinalBytes(tls, v11)
   8594 						}
   8595 					}
   8596 					pos = (*VP8BitReader)(unsafe.Pointer(v10)).Fbits
   8597 					split = range1 * uint32(int32(**(**uint8_t)(__ccgo_up(prob1 + uintptr(i))))) >> int32(8)
   8598 					value = uint32((*VP8BitReader)(unsafe.Pointer(v10)).Fvalue >> pos)
   8599 					bit = libc.BoolInt32(value > split)
   8600 					if bit != 0 {
   8601 						range1 = range1 - split
   8602 						**(**bit_t)(__ccgo_up(v10)) -= uint64(split+libc.Uint32FromInt32(1)) << pos
   8603 					} else {
   8604 						range1 = split + uint32(1)
   8605 					}
   8606 					v8 = int32(31) ^ libc.X__builtin_clz(tls, range1)
   8607 					goto _84
   8608 				_84:
   8609 					shift = int32(7) ^ v8
   8610 					range1 = range1 << uint32(shift)
   8611 					**(**int32)(__ccgo_up(v10 + 12)) -= shift
   8612 					(*VP8BitReader)(unsafe.Pointer(v10)).Frange1 = range1 - uint32(1)
   8613 					v14 = bit
   8614 					goto _86
   8615 				_86:
   8616 					i = int32(kYModesIntra4[int32(2)*i+v14])
   8617 				}
   8618 				ymode1 = -i
   8619 				**(**uint8_t)(__ccgo_up(top + uintptr(x1))) = uint8(ymode1)
   8620 				goto _70
   8621 			_70:
   8622 				;
   8623 				x1 = x1 + 1
   8624 			}
   8625 			libc.Xmemcpy(tls, modes, top, libc.Uint64FromInt32(4)*libc.Uint64FromInt64(1))
   8626 			modes = modes + uintptr(4)
   8627 			**(**uint8_t)(__ccgo_up(left + uintptr(y))) = uint8(ymode1)
   8628 			goto _69
   8629 		_69:
   8630 			;
   8631 			y = y + 1
   8632 		}
   8633 	}
   8634 	// Hardcoded UVMode decision tree
   8635 	v2 = br2
   8636 	range1 = (*VP8BitReader)(unsafe.Pointer(v2)).Frange1
   8637 	if (*VP8BitReader)(unsafe.Pointer(v2)).Fbits < libc.Int32FromInt32(0) {
   8638 		v3 = v2
   8639 		if (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf < (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf_max {
   8640 			libc.Xmemcpy(tls, bp, (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf, uint64(8))
   8641 			**(**uintptr)(__ccgo_up(v3 + 16)) += uintptr(libc.Int32FromInt32(BITS) >> libc.Int32FromInt32(3))
   8642 			v4 = libc.X__builtin_bswap64(tls, **(**lbit_t)(__ccgo_up(bp)))
   8643 			goto _91
   8644 		_91:
   8645 			bits = v4
   8646 			bits = bits >> uint64(libc.Int32FromInt32(64)-libc.Int32FromInt32(BITS))
   8647 			(*VP8BitReader)(unsafe.Pointer(v3)).Fvalue = bits | (*VP8BitReader)(unsafe.Pointer(v3)).Fvalue<<libc.Int32FromInt32(BITS)
   8648 			**(**int32)(__ccgo_up(v3 + 12)) += int32(BITS)
   8649 		} else {
   8650 			VP8LoadFinalBytes(tls, v3)
   8651 		}
   8652 	}
   8653 	pos = (*VP8BitReader)(unsafe.Pointer(v2)).Fbits
   8654 	split = range1 * uint32(int32(142)) >> int32(8)
   8655 	value = uint32((*VP8BitReader)(unsafe.Pointer(v2)).Fvalue >> pos)
   8656 	bit = libc.BoolInt32(value > split)
   8657 	if bit != 0 {
   8658 		range1 = range1 - split
   8659 		**(**bit_t)(__ccgo_up(v2)) -= uint64(split+libc.Uint32FromInt32(1)) << pos
   8660 	} else {
   8661 		range1 = split + uint32(1)
   8662 	}
   8663 	v6 = int32(31) ^ libc.X__builtin_clz(tls, range1)
   8664 	goto _93
   8665 _93:
   8666 	shift = int32(7) ^ v6
   8667 	range1 = range1 << uint32(shift)
   8668 	**(**int32)(__ccgo_up(v2 + 12)) -= shift
   8669 	(*VP8BitReader)(unsafe.Pointer(v2)).Frange1 = range1 - uint32(1)
   8670 	v8 = bit
   8671 	goto _95
   8672 _95:
   8673 	if !(v8 != 0) {
   8674 		v1 = int32(DC_PRED)
   8675 	} else {
   8676 		v10 = br2
   8677 		range1 = (*VP8BitReader)(unsafe.Pointer(v10)).Frange1
   8678 		if (*VP8BitReader)(unsafe.Pointer(v10)).Fbits < libc.Int32FromInt32(0) {
   8679 			v11 = v10
   8680 			if (*VP8BitReader)(unsafe.Pointer(v11)).Fbuf < (*VP8BitReader)(unsafe.Pointer(v11)).Fbuf_max {
   8681 				libc.Xmemcpy(tls, bp, (*VP8BitReader)(unsafe.Pointer(v11)).Fbuf, uint64(8))
   8682 				**(**uintptr)(__ccgo_up(v11 + 16)) += uintptr(libc.Int32FromInt32(BITS) >> libc.Int32FromInt32(3))
   8683 				v12 = libc.X__builtin_bswap64(tls, **(**lbit_t)(__ccgo_up(bp)))
   8684 				goto _100
   8685 			_100:
   8686 				bits = v12
   8687 				bits = bits >> uint64(libc.Int32FromInt32(64)-libc.Int32FromInt32(BITS))
   8688 				(*VP8BitReader)(unsafe.Pointer(v11)).Fvalue = bits | (*VP8BitReader)(unsafe.Pointer(v11)).Fvalue<<libc.Int32FromInt32(BITS)
   8689 				**(**int32)(__ccgo_up(v11 + 12)) += int32(BITS)
   8690 			} else {
   8691 				VP8LoadFinalBytes(tls, v11)
   8692 			}
   8693 		}
   8694 		pos = (*VP8BitReader)(unsafe.Pointer(v10)).Fbits
   8695 		split = range1 * uint32(int32(114)) >> int32(8)
   8696 		value = uint32((*VP8BitReader)(unsafe.Pointer(v10)).Fvalue >> pos)
   8697 		bit = libc.BoolInt32(value > split)
   8698 		if bit != 0 {
   8699 			range1 = range1 - split
   8700 			**(**bit_t)(__ccgo_up(v10)) -= uint64(split+libc.Uint32FromInt32(1)) << pos
   8701 		} else {
   8702 			range1 = split + uint32(1)
   8703 		}
   8704 		v16 = int32(31) ^ libc.X__builtin_clz(tls, range1)
   8705 		goto _102
   8706 	_102:
   8707 		shift = int32(7) ^ v16
   8708 		range1 = range1 << uint32(shift)
   8709 		**(**int32)(__ccgo_up(v10 + 12)) -= shift
   8710 		(*VP8BitReader)(unsafe.Pointer(v10)).Frange1 = range1 - uint32(1)
   8711 		v22 = bit
   8712 		goto _104
   8713 	_104:
   8714 		if !(v22 != 0) {
   8715 			v14 = int32(V_PRED)
   8716 		} else {
   8717 			v18 = br2
   8718 			range1 = (*VP8BitReader)(unsafe.Pointer(v18)).Frange1
   8719 			if (*VP8BitReader)(unsafe.Pointer(v18)).Fbits < libc.Int32FromInt32(0) {
   8720 				v19 = v18
   8721 				if (*VP8BitReader)(unsafe.Pointer(v19)).Fbuf < (*VP8BitReader)(unsafe.Pointer(v19)).Fbuf_max {
   8722 					libc.Xmemcpy(tls, bp, (*VP8BitReader)(unsafe.Pointer(v19)).Fbuf, uint64(8))
   8723 					**(**uintptr)(__ccgo_up(v19 + 16)) += uintptr(libc.Int32FromInt32(BITS) >> libc.Int32FromInt32(3))
   8724 					v20 = libc.X__builtin_bswap64(tls, **(**lbit_t)(__ccgo_up(bp)))
   8725 					goto _109
   8726 				_109:
   8727 					bits = v20
   8728 					bits = bits >> uint64(libc.Int32FromInt32(64)-libc.Int32FromInt32(BITS))
   8729 					(*VP8BitReader)(unsafe.Pointer(v19)).Fvalue = bits | (*VP8BitReader)(unsafe.Pointer(v19)).Fvalue<<libc.Int32FromInt32(BITS)
   8730 					**(**int32)(__ccgo_up(v19 + 12)) += int32(BITS)
   8731 				} else {
   8732 					VP8LoadFinalBytes(tls, v19)
   8733 				}
   8734 			}
   8735 			pos = (*VP8BitReader)(unsafe.Pointer(v18)).Fbits
   8736 			split = range1 * uint32(int32(183)) >> int32(8)
   8737 			value = uint32((*VP8BitReader)(unsafe.Pointer(v18)).Fvalue >> pos)
   8738 			bit = libc.BoolInt32(value > split)
   8739 			if bit != 0 {
   8740 				range1 = range1 - split
   8741 				**(**bit_t)(__ccgo_up(v18)) -= uint64(split+libc.Uint32FromInt32(1)) << pos
   8742 			} else {
   8743 				range1 = split + uint32(1)
   8744 			}
   8745 			v30 = int32(31) ^ libc.X__builtin_clz(tls, range1)
   8746 			goto _111
   8747 		_111:
   8748 			shift = int32(7) ^ v30
   8749 			range1 = range1 << uint32(shift)
   8750 			**(**int32)(__ccgo_up(v18 + 12)) -= shift
   8751 			(*VP8BitReader)(unsafe.Pointer(v18)).Frange1 = range1 - uint32(1)
   8752 			v32 = bit
   8753 			goto _113
   8754 		_113:
   8755 			if v32 != 0 {
   8756 				v24 = int32(TM_PRED)
   8757 			} else {
   8758 				v24 = int32(H_PRED)
   8759 			}
   8760 			v14 = v24
   8761 		}
   8762 		v1 = v14
   8763 	}
   8764 	(*VP8MBData)(unsafe.Pointer(block)).Fuvmode = uint8(v1)
   8765 }
   8766 
   8767 func VP8ParseIntraModeRow(tls *libc.TLS, br uintptr, dec uintptr) (r int32) {
   8768 	var mb_x int32
   8769 	_ = mb_x
   8770 	mb_x = 0
   8771 	for {
   8772 		if !(mb_x < (*VP8Decoder)(unsafe.Pointer(dec)).Fmb_w) {
   8773 			break
   8774 		}
   8775 		ParseIntraMode(tls, br, dec, mb_x)
   8776 		goto _1
   8777 	_1:
   8778 		;
   8779 		mb_x = mb_x + 1
   8780 	}
   8781 	return libc.BoolInt32(!((*VP8Decoder)(unsafe.Pointer(dec)).Fbr.Feof != 0))
   8782 }
   8783 
   8784 //------------------------------------------------------------------------------
   8785 // Paragraph 13
   8786 
   8787 var CoeffsUpdateProba = [4][8][3][11]uint8_t{
   8788 	0: {
   8789 		0: {
   8790 			0: {
   8791 				0:  uint8(255),
   8792 				1:  uint8(255),
   8793 				2:  uint8(255),
   8794 				3:  uint8(255),
   8795 				4:  uint8(255),
   8796 				5:  uint8(255),
   8797 				6:  uint8(255),
   8798 				7:  uint8(255),
   8799 				8:  uint8(255),
   8800 				9:  uint8(255),
   8801 				10: uint8(255),
   8802 			},
   8803 			1: {
   8804 				0:  uint8(255),
   8805 				1:  uint8(255),
   8806 				2:  uint8(255),
   8807 				3:  uint8(255),
   8808 				4:  uint8(255),
   8809 				5:  uint8(255),
   8810 				6:  uint8(255),
   8811 				7:  uint8(255),
   8812 				8:  uint8(255),
   8813 				9:  uint8(255),
   8814 				10: uint8(255),
   8815 			},
   8816 			2: {
   8817 				0:  uint8(255),
   8818 				1:  uint8(255),
   8819 				2:  uint8(255),
   8820 				3:  uint8(255),
   8821 				4:  uint8(255),
   8822 				5:  uint8(255),
   8823 				6:  uint8(255),
   8824 				7:  uint8(255),
   8825 				8:  uint8(255),
   8826 				9:  uint8(255),
   8827 				10: uint8(255),
   8828 			},
   8829 		},
   8830 		1: {
   8831 			0: {
   8832 				0:  uint8(176),
   8833 				1:  uint8(246),
   8834 				2:  uint8(255),
   8835 				3:  uint8(255),
   8836 				4:  uint8(255),
   8837 				5:  uint8(255),
   8838 				6:  uint8(255),
   8839 				7:  uint8(255),
   8840 				8:  uint8(255),
   8841 				9:  uint8(255),
   8842 				10: uint8(255),
   8843 			},
   8844 			1: {
   8845 				0:  uint8(223),
   8846 				1:  uint8(241),
   8847 				2:  uint8(252),
   8848 				3:  uint8(255),
   8849 				4:  uint8(255),
   8850 				5:  uint8(255),
   8851 				6:  uint8(255),
   8852 				7:  uint8(255),
   8853 				8:  uint8(255),
   8854 				9:  uint8(255),
   8855 				10: uint8(255),
   8856 			},
   8857 			2: {
   8858 				0:  uint8(249),
   8859 				1:  uint8(253),
   8860 				2:  uint8(253),
   8861 				3:  uint8(255),
   8862 				4:  uint8(255),
   8863 				5:  uint8(255),
   8864 				6:  uint8(255),
   8865 				7:  uint8(255),
   8866 				8:  uint8(255),
   8867 				9:  uint8(255),
   8868 				10: uint8(255),
   8869 			},
   8870 		},
   8871 		2: {
   8872 			0: {
   8873 				0:  uint8(255),
   8874 				1:  uint8(244),
   8875 				2:  uint8(252),
   8876 				3:  uint8(255),
   8877 				4:  uint8(255),
   8878 				5:  uint8(255),
   8879 				6:  uint8(255),
   8880 				7:  uint8(255),
   8881 				8:  uint8(255),
   8882 				9:  uint8(255),
   8883 				10: uint8(255),
   8884 			},
   8885 			1: {
   8886 				0:  uint8(234),
   8887 				1:  uint8(254),
   8888 				2:  uint8(254),
   8889 				3:  uint8(255),
   8890 				4:  uint8(255),
   8891 				5:  uint8(255),
   8892 				6:  uint8(255),
   8893 				7:  uint8(255),
   8894 				8:  uint8(255),
   8895 				9:  uint8(255),
   8896 				10: uint8(255),
   8897 			},
   8898 			2: {
   8899 				0:  uint8(253),
   8900 				1:  uint8(255),
   8901 				2:  uint8(255),
   8902 				3:  uint8(255),
   8903 				4:  uint8(255),
   8904 				5:  uint8(255),
   8905 				6:  uint8(255),
   8906 				7:  uint8(255),
   8907 				8:  uint8(255),
   8908 				9:  uint8(255),
   8909 				10: uint8(255),
   8910 			},
   8911 		},
   8912 		3: {
   8913 			0: {
   8914 				0:  uint8(255),
   8915 				1:  uint8(246),
   8916 				2:  uint8(254),
   8917 				3:  uint8(255),
   8918 				4:  uint8(255),
   8919 				5:  uint8(255),
   8920 				6:  uint8(255),
   8921 				7:  uint8(255),
   8922 				8:  uint8(255),
   8923 				9:  uint8(255),
   8924 				10: uint8(255),
   8925 			},
   8926 			1: {
   8927 				0:  uint8(239),
   8928 				1:  uint8(253),
   8929 				2:  uint8(254),
   8930 				3:  uint8(255),
   8931 				4:  uint8(255),
   8932 				5:  uint8(255),
   8933 				6:  uint8(255),
   8934 				7:  uint8(255),
   8935 				8:  uint8(255),
   8936 				9:  uint8(255),
   8937 				10: uint8(255),
   8938 			},
   8939 			2: {
   8940 				0:  uint8(254),
   8941 				1:  uint8(255),
   8942 				2:  uint8(254),
   8943 				3:  uint8(255),
   8944 				4:  uint8(255),
   8945 				5:  uint8(255),
   8946 				6:  uint8(255),
   8947 				7:  uint8(255),
   8948 				8:  uint8(255),
   8949 				9:  uint8(255),
   8950 				10: uint8(255),
   8951 			},
   8952 		},
   8953 		4: {
   8954 			0: {
   8955 				0:  uint8(255),
   8956 				1:  uint8(248),
   8957 				2:  uint8(254),
   8958 				3:  uint8(255),
   8959 				4:  uint8(255),
   8960 				5:  uint8(255),
   8961 				6:  uint8(255),
   8962 				7:  uint8(255),
   8963 				8:  uint8(255),
   8964 				9:  uint8(255),
   8965 				10: uint8(255),
   8966 			},
   8967 			1: {
   8968 				0:  uint8(251),
   8969 				1:  uint8(255),
   8970 				2:  uint8(254),
   8971 				3:  uint8(255),
   8972 				4:  uint8(255),
   8973 				5:  uint8(255),
   8974 				6:  uint8(255),
   8975 				7:  uint8(255),
   8976 				8:  uint8(255),
   8977 				9:  uint8(255),
   8978 				10: uint8(255),
   8979 			},
   8980 			2: {
   8981 				0:  uint8(255),
   8982 				1:  uint8(255),
   8983 				2:  uint8(255),
   8984 				3:  uint8(255),
   8985 				4:  uint8(255),
   8986 				5:  uint8(255),
   8987 				6:  uint8(255),
   8988 				7:  uint8(255),
   8989 				8:  uint8(255),
   8990 				9:  uint8(255),
   8991 				10: uint8(255),
   8992 			},
   8993 		},
   8994 		5: {
   8995 			0: {
   8996 				0:  uint8(255),
   8997 				1:  uint8(253),
   8998 				2:  uint8(254),
   8999 				3:  uint8(255),
   9000 				4:  uint8(255),
   9001 				5:  uint8(255),
   9002 				6:  uint8(255),
   9003 				7:  uint8(255),
   9004 				8:  uint8(255),
   9005 				9:  uint8(255),
   9006 				10: uint8(255),
   9007 			},
   9008 			1: {
   9009 				0:  uint8(251),
   9010 				1:  uint8(254),
   9011 				2:  uint8(254),
   9012 				3:  uint8(255),
   9013 				4:  uint8(255),
   9014 				5:  uint8(255),
   9015 				6:  uint8(255),
   9016 				7:  uint8(255),
   9017 				8:  uint8(255),
   9018 				9:  uint8(255),
   9019 				10: uint8(255),
   9020 			},
   9021 			2: {
   9022 				0:  uint8(254),
   9023 				1:  uint8(255),
   9024 				2:  uint8(254),
   9025 				3:  uint8(255),
   9026 				4:  uint8(255),
   9027 				5:  uint8(255),
   9028 				6:  uint8(255),
   9029 				7:  uint8(255),
   9030 				8:  uint8(255),
   9031 				9:  uint8(255),
   9032 				10: uint8(255),
   9033 			},
   9034 		},
   9035 		6: {
   9036 			0: {
   9037 				0:  uint8(255),
   9038 				1:  uint8(254),
   9039 				2:  uint8(253),
   9040 				3:  uint8(255),
   9041 				4:  uint8(254),
   9042 				5:  uint8(255),
   9043 				6:  uint8(255),
   9044 				7:  uint8(255),
   9045 				8:  uint8(255),
   9046 				9:  uint8(255),
   9047 				10: uint8(255),
   9048 			},
   9049 			1: {
   9050 				0:  uint8(250),
   9051 				1:  uint8(255),
   9052 				2:  uint8(254),
   9053 				3:  uint8(255),
   9054 				4:  uint8(254),
   9055 				5:  uint8(255),
   9056 				6:  uint8(255),
   9057 				7:  uint8(255),
   9058 				8:  uint8(255),
   9059 				9:  uint8(255),
   9060 				10: uint8(255),
   9061 			},
   9062 			2: {
   9063 				0:  uint8(254),
   9064 				1:  uint8(255),
   9065 				2:  uint8(255),
   9066 				3:  uint8(255),
   9067 				4:  uint8(255),
   9068 				5:  uint8(255),
   9069 				6:  uint8(255),
   9070 				7:  uint8(255),
   9071 				8:  uint8(255),
   9072 				9:  uint8(255),
   9073 				10: uint8(255),
   9074 			},
   9075 		},
   9076 		7: {
   9077 			0: {
   9078 				0:  uint8(255),
   9079 				1:  uint8(255),
   9080 				2:  uint8(255),
   9081 				3:  uint8(255),
   9082 				4:  uint8(255),
   9083 				5:  uint8(255),
   9084 				6:  uint8(255),
   9085 				7:  uint8(255),
   9086 				8:  uint8(255),
   9087 				9:  uint8(255),
   9088 				10: uint8(255),
   9089 			},
   9090 			1: {
   9091 				0:  uint8(255),
   9092 				1:  uint8(255),
   9093 				2:  uint8(255),
   9094 				3:  uint8(255),
   9095 				4:  uint8(255),
   9096 				5:  uint8(255),
   9097 				6:  uint8(255),
   9098 				7:  uint8(255),
   9099 				8:  uint8(255),
   9100 				9:  uint8(255),
   9101 				10: uint8(255),
   9102 			},
   9103 			2: {
   9104 				0:  uint8(255),
   9105 				1:  uint8(255),
   9106 				2:  uint8(255),
   9107 				3:  uint8(255),
   9108 				4:  uint8(255),
   9109 				5:  uint8(255),
   9110 				6:  uint8(255),
   9111 				7:  uint8(255),
   9112 				8:  uint8(255),
   9113 				9:  uint8(255),
   9114 				10: uint8(255),
   9115 			},
   9116 		},
   9117 	},
   9118 	1: {
   9119 		0: {
   9120 			0: {
   9121 				0:  uint8(217),
   9122 				1:  uint8(255),
   9123 				2:  uint8(255),
   9124 				3:  uint8(255),
   9125 				4:  uint8(255),
   9126 				5:  uint8(255),
   9127 				6:  uint8(255),
   9128 				7:  uint8(255),
   9129 				8:  uint8(255),
   9130 				9:  uint8(255),
   9131 				10: uint8(255),
   9132 			},
   9133 			1: {
   9134 				0:  uint8(225),
   9135 				1:  uint8(252),
   9136 				2:  uint8(241),
   9137 				3:  uint8(253),
   9138 				4:  uint8(255),
   9139 				5:  uint8(255),
   9140 				6:  uint8(254),
   9141 				7:  uint8(255),
   9142 				8:  uint8(255),
   9143 				9:  uint8(255),
   9144 				10: uint8(255),
   9145 			},
   9146 			2: {
   9147 				0:  uint8(234),
   9148 				1:  uint8(250),
   9149 				2:  uint8(241),
   9150 				3:  uint8(250),
   9151 				4:  uint8(253),
   9152 				5:  uint8(255),
   9153 				6:  uint8(253),
   9154 				7:  uint8(254),
   9155 				8:  uint8(255),
   9156 				9:  uint8(255),
   9157 				10: uint8(255),
   9158 			},
   9159 		},
   9160 		1: {
   9161 			0: {
   9162 				0:  uint8(255),
   9163 				1:  uint8(254),
   9164 				2:  uint8(255),
   9165 				3:  uint8(255),
   9166 				4:  uint8(255),
   9167 				5:  uint8(255),
   9168 				6:  uint8(255),
   9169 				7:  uint8(255),
   9170 				8:  uint8(255),
   9171 				9:  uint8(255),
   9172 				10: uint8(255),
   9173 			},
   9174 			1: {
   9175 				0:  uint8(223),
   9176 				1:  uint8(254),
   9177 				2:  uint8(254),
   9178 				3:  uint8(255),
   9179 				4:  uint8(255),
   9180 				5:  uint8(255),
   9181 				6:  uint8(255),
   9182 				7:  uint8(255),
   9183 				8:  uint8(255),
   9184 				9:  uint8(255),
   9185 				10: uint8(255),
   9186 			},
   9187 			2: {
   9188 				0:  uint8(238),
   9189 				1:  uint8(253),
   9190 				2:  uint8(254),
   9191 				3:  uint8(254),
   9192 				4:  uint8(255),
   9193 				5:  uint8(255),
   9194 				6:  uint8(255),
   9195 				7:  uint8(255),
   9196 				8:  uint8(255),
   9197 				9:  uint8(255),
   9198 				10: uint8(255),
   9199 			},
   9200 		},
   9201 		2: {
   9202 			0: {
   9203 				0:  uint8(255),
   9204 				1:  uint8(248),
   9205 				2:  uint8(254),
   9206 				3:  uint8(255),
   9207 				4:  uint8(255),
   9208 				5:  uint8(255),
   9209 				6:  uint8(255),
   9210 				7:  uint8(255),
   9211 				8:  uint8(255),
   9212 				9:  uint8(255),
   9213 				10: uint8(255),
   9214 			},
   9215 			1: {
   9216 				0:  uint8(249),
   9217 				1:  uint8(254),
   9218 				2:  uint8(255),
   9219 				3:  uint8(255),
   9220 				4:  uint8(255),
   9221 				5:  uint8(255),
   9222 				6:  uint8(255),
   9223 				7:  uint8(255),
   9224 				8:  uint8(255),
   9225 				9:  uint8(255),
   9226 				10: uint8(255),
   9227 			},
   9228 			2: {
   9229 				0:  uint8(255),
   9230 				1:  uint8(255),
   9231 				2:  uint8(255),
   9232 				3:  uint8(255),
   9233 				4:  uint8(255),
   9234 				5:  uint8(255),
   9235 				6:  uint8(255),
   9236 				7:  uint8(255),
   9237 				8:  uint8(255),
   9238 				9:  uint8(255),
   9239 				10: uint8(255),
   9240 			},
   9241 		},
   9242 		3: {
   9243 			0: {
   9244 				0:  uint8(255),
   9245 				1:  uint8(253),
   9246 				2:  uint8(255),
   9247 				3:  uint8(255),
   9248 				4:  uint8(255),
   9249 				5:  uint8(255),
   9250 				6:  uint8(255),
   9251 				7:  uint8(255),
   9252 				8:  uint8(255),
   9253 				9:  uint8(255),
   9254 				10: uint8(255),
   9255 			},
   9256 			1: {
   9257 				0:  uint8(247),
   9258 				1:  uint8(254),
   9259 				2:  uint8(255),
   9260 				3:  uint8(255),
   9261 				4:  uint8(255),
   9262 				5:  uint8(255),
   9263 				6:  uint8(255),
   9264 				7:  uint8(255),
   9265 				8:  uint8(255),
   9266 				9:  uint8(255),
   9267 				10: uint8(255),
   9268 			},
   9269 			2: {
   9270 				0:  uint8(255),
   9271 				1:  uint8(255),
   9272 				2:  uint8(255),
   9273 				3:  uint8(255),
   9274 				4:  uint8(255),
   9275 				5:  uint8(255),
   9276 				6:  uint8(255),
   9277 				7:  uint8(255),
   9278 				8:  uint8(255),
   9279 				9:  uint8(255),
   9280 				10: uint8(255),
   9281 			},
   9282 		},
   9283 		4: {
   9284 			0: {
   9285 				0:  uint8(255),
   9286 				1:  uint8(253),
   9287 				2:  uint8(254),
   9288 				3:  uint8(255),
   9289 				4:  uint8(255),
   9290 				5:  uint8(255),
   9291 				6:  uint8(255),
   9292 				7:  uint8(255),
   9293 				8:  uint8(255),
   9294 				9:  uint8(255),
   9295 				10: uint8(255),
   9296 			},
   9297 			1: {
   9298 				0:  uint8(252),
   9299 				1:  uint8(255),
   9300 				2:  uint8(255),
   9301 				3:  uint8(255),
   9302 				4:  uint8(255),
   9303 				5:  uint8(255),
   9304 				6:  uint8(255),
   9305 				7:  uint8(255),
   9306 				8:  uint8(255),
   9307 				9:  uint8(255),
   9308 				10: uint8(255),
   9309 			},
   9310 			2: {
   9311 				0:  uint8(255),
   9312 				1:  uint8(255),
   9313 				2:  uint8(255),
   9314 				3:  uint8(255),
   9315 				4:  uint8(255),
   9316 				5:  uint8(255),
   9317 				6:  uint8(255),
   9318 				7:  uint8(255),
   9319 				8:  uint8(255),
   9320 				9:  uint8(255),
   9321 				10: uint8(255),
   9322 			},
   9323 		},
   9324 		5: {
   9325 			0: {
   9326 				0:  uint8(255),
   9327 				1:  uint8(254),
   9328 				2:  uint8(254),
   9329 				3:  uint8(255),
   9330 				4:  uint8(255),
   9331 				5:  uint8(255),
   9332 				6:  uint8(255),
   9333 				7:  uint8(255),
   9334 				8:  uint8(255),
   9335 				9:  uint8(255),
   9336 				10: uint8(255),
   9337 			},
   9338 			1: {
   9339 				0:  uint8(253),
   9340 				1:  uint8(255),
   9341 				2:  uint8(255),
   9342 				3:  uint8(255),
   9343 				4:  uint8(255),
   9344 				5:  uint8(255),
   9345 				6:  uint8(255),
   9346 				7:  uint8(255),
   9347 				8:  uint8(255),
   9348 				9:  uint8(255),
   9349 				10: uint8(255),
   9350 			},
   9351 			2: {
   9352 				0:  uint8(255),
   9353 				1:  uint8(255),
   9354 				2:  uint8(255),
   9355 				3:  uint8(255),
   9356 				4:  uint8(255),
   9357 				5:  uint8(255),
   9358 				6:  uint8(255),
   9359 				7:  uint8(255),
   9360 				8:  uint8(255),
   9361 				9:  uint8(255),
   9362 				10: uint8(255),
   9363 			},
   9364 		},
   9365 		6: {
   9366 			0: {
   9367 				0:  uint8(255),
   9368 				1:  uint8(254),
   9369 				2:  uint8(253),
   9370 				3:  uint8(255),
   9371 				4:  uint8(255),
   9372 				5:  uint8(255),
   9373 				6:  uint8(255),
   9374 				7:  uint8(255),
   9375 				8:  uint8(255),
   9376 				9:  uint8(255),
   9377 				10: uint8(255),
   9378 			},
   9379 			1: {
   9380 				0:  uint8(250),
   9381 				1:  uint8(255),
   9382 				2:  uint8(255),
   9383 				3:  uint8(255),
   9384 				4:  uint8(255),
   9385 				5:  uint8(255),
   9386 				6:  uint8(255),
   9387 				7:  uint8(255),
   9388 				8:  uint8(255),
   9389 				9:  uint8(255),
   9390 				10: uint8(255),
   9391 			},
   9392 			2: {
   9393 				0:  uint8(254),
   9394 				1:  uint8(255),
   9395 				2:  uint8(255),
   9396 				3:  uint8(255),
   9397 				4:  uint8(255),
   9398 				5:  uint8(255),
   9399 				6:  uint8(255),
   9400 				7:  uint8(255),
   9401 				8:  uint8(255),
   9402 				9:  uint8(255),
   9403 				10: uint8(255),
   9404 			},
   9405 		},
   9406 		7: {
   9407 			0: {
   9408 				0:  uint8(255),
   9409 				1:  uint8(255),
   9410 				2:  uint8(255),
   9411 				3:  uint8(255),
   9412 				4:  uint8(255),
   9413 				5:  uint8(255),
   9414 				6:  uint8(255),
   9415 				7:  uint8(255),
   9416 				8:  uint8(255),
   9417 				9:  uint8(255),
   9418 				10: uint8(255),
   9419 			},
   9420 			1: {
   9421 				0:  uint8(255),
   9422 				1:  uint8(255),
   9423 				2:  uint8(255),
   9424 				3:  uint8(255),
   9425 				4:  uint8(255),
   9426 				5:  uint8(255),
   9427 				6:  uint8(255),
   9428 				7:  uint8(255),
   9429 				8:  uint8(255),
   9430 				9:  uint8(255),
   9431 				10: uint8(255),
   9432 			},
   9433 			2: {
   9434 				0:  uint8(255),
   9435 				1:  uint8(255),
   9436 				2:  uint8(255),
   9437 				3:  uint8(255),
   9438 				4:  uint8(255),
   9439 				5:  uint8(255),
   9440 				6:  uint8(255),
   9441 				7:  uint8(255),
   9442 				8:  uint8(255),
   9443 				9:  uint8(255),
   9444 				10: uint8(255),
   9445 			},
   9446 		},
   9447 	},
   9448 	2: {
   9449 		0: {
   9450 			0: {
   9451 				0:  uint8(186),
   9452 				1:  uint8(251),
   9453 				2:  uint8(250),
   9454 				3:  uint8(255),
   9455 				4:  uint8(255),
   9456 				5:  uint8(255),
   9457 				6:  uint8(255),
   9458 				7:  uint8(255),
   9459 				8:  uint8(255),
   9460 				9:  uint8(255),
   9461 				10: uint8(255),
   9462 			},
   9463 			1: {
   9464 				0:  uint8(234),
   9465 				1:  uint8(251),
   9466 				2:  uint8(244),
   9467 				3:  uint8(254),
   9468 				4:  uint8(255),
   9469 				5:  uint8(255),
   9470 				6:  uint8(255),
   9471 				7:  uint8(255),
   9472 				8:  uint8(255),
   9473 				9:  uint8(255),
   9474 				10: uint8(255),
   9475 			},
   9476 			2: {
   9477 				0:  uint8(251),
   9478 				1:  uint8(251),
   9479 				2:  uint8(243),
   9480 				3:  uint8(253),
   9481 				4:  uint8(254),
   9482 				5:  uint8(255),
   9483 				6:  uint8(254),
   9484 				7:  uint8(255),
   9485 				8:  uint8(255),
   9486 				9:  uint8(255),
   9487 				10: uint8(255),
   9488 			},
   9489 		},
   9490 		1: {
   9491 			0: {
   9492 				0:  uint8(255),
   9493 				1:  uint8(253),
   9494 				2:  uint8(254),
   9495 				3:  uint8(255),
   9496 				4:  uint8(255),
   9497 				5:  uint8(255),
   9498 				6:  uint8(255),
   9499 				7:  uint8(255),
   9500 				8:  uint8(255),
   9501 				9:  uint8(255),
   9502 				10: uint8(255),
   9503 			},
   9504 			1: {
   9505 				0:  uint8(236),
   9506 				1:  uint8(253),
   9507 				2:  uint8(254),
   9508 				3:  uint8(255),
   9509 				4:  uint8(255),
   9510 				5:  uint8(255),
   9511 				6:  uint8(255),
   9512 				7:  uint8(255),
   9513 				8:  uint8(255),
   9514 				9:  uint8(255),
   9515 				10: uint8(255),
   9516 			},
   9517 			2: {
   9518 				0:  uint8(251),
   9519 				1:  uint8(253),
   9520 				2:  uint8(253),
   9521 				3:  uint8(254),
   9522 				4:  uint8(254),
   9523 				5:  uint8(255),
   9524 				6:  uint8(255),
   9525 				7:  uint8(255),
   9526 				8:  uint8(255),
   9527 				9:  uint8(255),
   9528 				10: uint8(255),
   9529 			},
   9530 		},
   9531 		2: {
   9532 			0: {
   9533 				0:  uint8(255),
   9534 				1:  uint8(254),
   9535 				2:  uint8(254),
   9536 				3:  uint8(255),
   9537 				4:  uint8(255),
   9538 				5:  uint8(255),
   9539 				6:  uint8(255),
   9540 				7:  uint8(255),
   9541 				8:  uint8(255),
   9542 				9:  uint8(255),
   9543 				10: uint8(255),
   9544 			},
   9545 			1: {
   9546 				0:  uint8(254),
   9547 				1:  uint8(254),
   9548 				2:  uint8(254),
   9549 				3:  uint8(255),
   9550 				4:  uint8(255),
   9551 				5:  uint8(255),
   9552 				6:  uint8(255),
   9553 				7:  uint8(255),
   9554 				8:  uint8(255),
   9555 				9:  uint8(255),
   9556 				10: uint8(255),
   9557 			},
   9558 			2: {
   9559 				0:  uint8(255),
   9560 				1:  uint8(255),
   9561 				2:  uint8(255),
   9562 				3:  uint8(255),
   9563 				4:  uint8(255),
   9564 				5:  uint8(255),
   9565 				6:  uint8(255),
   9566 				7:  uint8(255),
   9567 				8:  uint8(255),
   9568 				9:  uint8(255),
   9569 				10: uint8(255),
   9570 			},
   9571 		},
   9572 		3: {
   9573 			0: {
   9574 				0:  uint8(255),
   9575 				1:  uint8(254),
   9576 				2:  uint8(255),
   9577 				3:  uint8(255),
   9578 				4:  uint8(255),
   9579 				5:  uint8(255),
   9580 				6:  uint8(255),
   9581 				7:  uint8(255),
   9582 				8:  uint8(255),
   9583 				9:  uint8(255),
   9584 				10: uint8(255),
   9585 			},
   9586 			1: {
   9587 				0:  uint8(254),
   9588 				1:  uint8(254),
   9589 				2:  uint8(255),
   9590 				3:  uint8(255),
   9591 				4:  uint8(255),
   9592 				5:  uint8(255),
   9593 				6:  uint8(255),
   9594 				7:  uint8(255),
   9595 				8:  uint8(255),
   9596 				9:  uint8(255),
   9597 				10: uint8(255),
   9598 			},
   9599 			2: {
   9600 				0:  uint8(254),
   9601 				1:  uint8(255),
   9602 				2:  uint8(255),
   9603 				3:  uint8(255),
   9604 				4:  uint8(255),
   9605 				5:  uint8(255),
   9606 				6:  uint8(255),
   9607 				7:  uint8(255),
   9608 				8:  uint8(255),
   9609 				9:  uint8(255),
   9610 				10: uint8(255),
   9611 			},
   9612 		},
   9613 		4: {
   9614 			0: {
   9615 				0:  uint8(255),
   9616 				1:  uint8(255),
   9617 				2:  uint8(255),
   9618 				3:  uint8(255),
   9619 				4:  uint8(255),
   9620 				5:  uint8(255),
   9621 				6:  uint8(255),
   9622 				7:  uint8(255),
   9623 				8:  uint8(255),
   9624 				9:  uint8(255),
   9625 				10: uint8(255),
   9626 			},
   9627 			1: {
   9628 				0:  uint8(254),
   9629 				1:  uint8(255),
   9630 				2:  uint8(255),
   9631 				3:  uint8(255),
   9632 				4:  uint8(255),
   9633 				5:  uint8(255),
   9634 				6:  uint8(255),
   9635 				7:  uint8(255),
   9636 				8:  uint8(255),
   9637 				9:  uint8(255),
   9638 				10: uint8(255),
   9639 			},
   9640 			2: {
   9641 				0:  uint8(255),
   9642 				1:  uint8(255),
   9643 				2:  uint8(255),
   9644 				3:  uint8(255),
   9645 				4:  uint8(255),
   9646 				5:  uint8(255),
   9647 				6:  uint8(255),
   9648 				7:  uint8(255),
   9649 				8:  uint8(255),
   9650 				9:  uint8(255),
   9651 				10: uint8(255),
   9652 			},
   9653 		},
   9654 		5: {
   9655 			0: {
   9656 				0:  uint8(255),
   9657 				1:  uint8(255),
   9658 				2:  uint8(255),
   9659 				3:  uint8(255),
   9660 				4:  uint8(255),
   9661 				5:  uint8(255),
   9662 				6:  uint8(255),
   9663 				7:  uint8(255),
   9664 				8:  uint8(255),
   9665 				9:  uint8(255),
   9666 				10: uint8(255),
   9667 			},
   9668 			1: {
   9669 				0:  uint8(255),
   9670 				1:  uint8(255),
   9671 				2:  uint8(255),
   9672 				3:  uint8(255),
   9673 				4:  uint8(255),
   9674 				5:  uint8(255),
   9675 				6:  uint8(255),
   9676 				7:  uint8(255),
   9677 				8:  uint8(255),
   9678 				9:  uint8(255),
   9679 				10: uint8(255),
   9680 			},
   9681 			2: {
   9682 				0:  uint8(255),
   9683 				1:  uint8(255),
   9684 				2:  uint8(255),
   9685 				3:  uint8(255),
   9686 				4:  uint8(255),
   9687 				5:  uint8(255),
   9688 				6:  uint8(255),
   9689 				7:  uint8(255),
   9690 				8:  uint8(255),
   9691 				9:  uint8(255),
   9692 				10: uint8(255),
   9693 			},
   9694 		},
   9695 		6: {
   9696 			0: {
   9697 				0:  uint8(255),
   9698 				1:  uint8(255),
   9699 				2:  uint8(255),
   9700 				3:  uint8(255),
   9701 				4:  uint8(255),
   9702 				5:  uint8(255),
   9703 				6:  uint8(255),
   9704 				7:  uint8(255),
   9705 				8:  uint8(255),
   9706 				9:  uint8(255),
   9707 				10: uint8(255),
   9708 			},
   9709 			1: {
   9710 				0:  uint8(255),
   9711 				1:  uint8(255),
   9712 				2:  uint8(255),
   9713 				3:  uint8(255),
   9714 				4:  uint8(255),
   9715 				5:  uint8(255),
   9716 				6:  uint8(255),
   9717 				7:  uint8(255),
   9718 				8:  uint8(255),
   9719 				9:  uint8(255),
   9720 				10: uint8(255),
   9721 			},
   9722 			2: {
   9723 				0:  uint8(255),
   9724 				1:  uint8(255),
   9725 				2:  uint8(255),
   9726 				3:  uint8(255),
   9727 				4:  uint8(255),
   9728 				5:  uint8(255),
   9729 				6:  uint8(255),
   9730 				7:  uint8(255),
   9731 				8:  uint8(255),
   9732 				9:  uint8(255),
   9733 				10: uint8(255),
   9734 			},
   9735 		},
   9736 		7: {
   9737 			0: {
   9738 				0:  uint8(255),
   9739 				1:  uint8(255),
   9740 				2:  uint8(255),
   9741 				3:  uint8(255),
   9742 				4:  uint8(255),
   9743 				5:  uint8(255),
   9744 				6:  uint8(255),
   9745 				7:  uint8(255),
   9746 				8:  uint8(255),
   9747 				9:  uint8(255),
   9748 				10: uint8(255),
   9749 			},
   9750 			1: {
   9751 				0:  uint8(255),
   9752 				1:  uint8(255),
   9753 				2:  uint8(255),
   9754 				3:  uint8(255),
   9755 				4:  uint8(255),
   9756 				5:  uint8(255),
   9757 				6:  uint8(255),
   9758 				7:  uint8(255),
   9759 				8:  uint8(255),
   9760 				9:  uint8(255),
   9761 				10: uint8(255),
   9762 			},
   9763 			2: {
   9764 				0:  uint8(255),
   9765 				1:  uint8(255),
   9766 				2:  uint8(255),
   9767 				3:  uint8(255),
   9768 				4:  uint8(255),
   9769 				5:  uint8(255),
   9770 				6:  uint8(255),
   9771 				7:  uint8(255),
   9772 				8:  uint8(255),
   9773 				9:  uint8(255),
   9774 				10: uint8(255),
   9775 			},
   9776 		},
   9777 	},
   9778 	3: {
   9779 		0: {
   9780 			0: {
   9781 				0:  uint8(248),
   9782 				1:  uint8(255),
   9783 				2:  uint8(255),
   9784 				3:  uint8(255),
   9785 				4:  uint8(255),
   9786 				5:  uint8(255),
   9787 				6:  uint8(255),
   9788 				7:  uint8(255),
   9789 				8:  uint8(255),
   9790 				9:  uint8(255),
   9791 				10: uint8(255),
   9792 			},
   9793 			1: {
   9794 				0:  uint8(250),
   9795 				1:  uint8(254),
   9796 				2:  uint8(252),
   9797 				3:  uint8(254),
   9798 				4:  uint8(255),
   9799 				5:  uint8(255),
   9800 				6:  uint8(255),
   9801 				7:  uint8(255),
   9802 				8:  uint8(255),
   9803 				9:  uint8(255),
   9804 				10: uint8(255),
   9805 			},
   9806 			2: {
   9807 				0:  uint8(248),
   9808 				1:  uint8(254),
   9809 				2:  uint8(249),
   9810 				3:  uint8(253),
   9811 				4:  uint8(255),
   9812 				5:  uint8(255),
   9813 				6:  uint8(255),
   9814 				7:  uint8(255),
   9815 				8:  uint8(255),
   9816 				9:  uint8(255),
   9817 				10: uint8(255),
   9818 			},
   9819 		},
   9820 		1: {
   9821 			0: {
   9822 				0:  uint8(255),
   9823 				1:  uint8(253),
   9824 				2:  uint8(253),
   9825 				3:  uint8(255),
   9826 				4:  uint8(255),
   9827 				5:  uint8(255),
   9828 				6:  uint8(255),
   9829 				7:  uint8(255),
   9830 				8:  uint8(255),
   9831 				9:  uint8(255),
   9832 				10: uint8(255),
   9833 			},
   9834 			1: {
   9835 				0:  uint8(246),
   9836 				1:  uint8(253),
   9837 				2:  uint8(253),
   9838 				3:  uint8(255),
   9839 				4:  uint8(255),
   9840 				5:  uint8(255),
   9841 				6:  uint8(255),
   9842 				7:  uint8(255),
   9843 				8:  uint8(255),
   9844 				9:  uint8(255),
   9845 				10: uint8(255),
   9846 			},
   9847 			2: {
   9848 				0:  uint8(252),
   9849 				1:  uint8(254),
   9850 				2:  uint8(251),
   9851 				3:  uint8(254),
   9852 				4:  uint8(254),
   9853 				5:  uint8(255),
   9854 				6:  uint8(255),
   9855 				7:  uint8(255),
   9856 				8:  uint8(255),
   9857 				9:  uint8(255),
   9858 				10: uint8(255),
   9859 			},
   9860 		},
   9861 		2: {
   9862 			0: {
   9863 				0:  uint8(255),
   9864 				1:  uint8(254),
   9865 				2:  uint8(252),
   9866 				3:  uint8(255),
   9867 				4:  uint8(255),
   9868 				5:  uint8(255),
   9869 				6:  uint8(255),
   9870 				7:  uint8(255),
   9871 				8:  uint8(255),
   9872 				9:  uint8(255),
   9873 				10: uint8(255),
   9874 			},
   9875 			1: {
   9876 				0:  uint8(248),
   9877 				1:  uint8(254),
   9878 				2:  uint8(253),
   9879 				3:  uint8(255),
   9880 				4:  uint8(255),
   9881 				5:  uint8(255),
   9882 				6:  uint8(255),
   9883 				7:  uint8(255),
   9884 				8:  uint8(255),
   9885 				9:  uint8(255),
   9886 				10: uint8(255),
   9887 			},
   9888 			2: {
   9889 				0:  uint8(253),
   9890 				1:  uint8(255),
   9891 				2:  uint8(254),
   9892 				3:  uint8(254),
   9893 				4:  uint8(255),
   9894 				5:  uint8(255),
   9895 				6:  uint8(255),
   9896 				7:  uint8(255),
   9897 				8:  uint8(255),
   9898 				9:  uint8(255),
   9899 				10: uint8(255),
   9900 			},
   9901 		},
   9902 		3: {
   9903 			0: {
   9904 				0:  uint8(255),
   9905 				1:  uint8(251),
   9906 				2:  uint8(254),
   9907 				3:  uint8(255),
   9908 				4:  uint8(255),
   9909 				5:  uint8(255),
   9910 				6:  uint8(255),
   9911 				7:  uint8(255),
   9912 				8:  uint8(255),
   9913 				9:  uint8(255),
   9914 				10: uint8(255),
   9915 			},
   9916 			1: {
   9917 				0:  uint8(245),
   9918 				1:  uint8(251),
   9919 				2:  uint8(254),
   9920 				3:  uint8(255),
   9921 				4:  uint8(255),
   9922 				5:  uint8(255),
   9923 				6:  uint8(255),
   9924 				7:  uint8(255),
   9925 				8:  uint8(255),
   9926 				9:  uint8(255),
   9927 				10: uint8(255),
   9928 			},
   9929 			2: {
   9930 				0:  uint8(253),
   9931 				1:  uint8(253),
   9932 				2:  uint8(254),
   9933 				3:  uint8(255),
   9934 				4:  uint8(255),
   9935 				5:  uint8(255),
   9936 				6:  uint8(255),
   9937 				7:  uint8(255),
   9938 				8:  uint8(255),
   9939 				9:  uint8(255),
   9940 				10: uint8(255),
   9941 			},
   9942 		},
   9943 		4: {
   9944 			0: {
   9945 				0:  uint8(255),
   9946 				1:  uint8(251),
   9947 				2:  uint8(253),
   9948 				3:  uint8(255),
   9949 				4:  uint8(255),
   9950 				5:  uint8(255),
   9951 				6:  uint8(255),
   9952 				7:  uint8(255),
   9953 				8:  uint8(255),
   9954 				9:  uint8(255),
   9955 				10: uint8(255),
   9956 			},
   9957 			1: {
   9958 				0:  uint8(252),
   9959 				1:  uint8(253),
   9960 				2:  uint8(254),
   9961 				3:  uint8(255),
   9962 				4:  uint8(255),
   9963 				5:  uint8(255),
   9964 				6:  uint8(255),
   9965 				7:  uint8(255),
   9966 				8:  uint8(255),
   9967 				9:  uint8(255),
   9968 				10: uint8(255),
   9969 			},
   9970 			2: {
   9971 				0:  uint8(255),
   9972 				1:  uint8(254),
   9973 				2:  uint8(255),
   9974 				3:  uint8(255),
   9975 				4:  uint8(255),
   9976 				5:  uint8(255),
   9977 				6:  uint8(255),
   9978 				7:  uint8(255),
   9979 				8:  uint8(255),
   9980 				9:  uint8(255),
   9981 				10: uint8(255),
   9982 			},
   9983 		},
   9984 		5: {
   9985 			0: {
   9986 				0:  uint8(255),
   9987 				1:  uint8(252),
   9988 				2:  uint8(255),
   9989 				3:  uint8(255),
   9990 				4:  uint8(255),
   9991 				5:  uint8(255),
   9992 				6:  uint8(255),
   9993 				7:  uint8(255),
   9994 				8:  uint8(255),
   9995 				9:  uint8(255),
   9996 				10: uint8(255),
   9997 			},
   9998 			1: {
   9999 				0:  uint8(249),
  10000 				1:  uint8(255),
  10001 				2:  uint8(254),
  10002 				3:  uint8(255),
  10003 				4:  uint8(255),
  10004 				5:  uint8(255),
  10005 				6:  uint8(255),
  10006 				7:  uint8(255),
  10007 				8:  uint8(255),
  10008 				9:  uint8(255),
  10009 				10: uint8(255),
  10010 			},
  10011 			2: {
  10012 				0:  uint8(255),
  10013 				1:  uint8(255),
  10014 				2:  uint8(254),
  10015 				3:  uint8(255),
  10016 				4:  uint8(255),
  10017 				5:  uint8(255),
  10018 				6:  uint8(255),
  10019 				7:  uint8(255),
  10020 				8:  uint8(255),
  10021 				9:  uint8(255),
  10022 				10: uint8(255),
  10023 			},
  10024 		},
  10025 		6: {
  10026 			0: {
  10027 				0:  uint8(255),
  10028 				1:  uint8(255),
  10029 				2:  uint8(253),
  10030 				3:  uint8(255),
  10031 				4:  uint8(255),
  10032 				5:  uint8(255),
  10033 				6:  uint8(255),
  10034 				7:  uint8(255),
  10035 				8:  uint8(255),
  10036 				9:  uint8(255),
  10037 				10: uint8(255),
  10038 			},
  10039 			1: {
  10040 				0:  uint8(250),
  10041 				1:  uint8(255),
  10042 				2:  uint8(255),
  10043 				3:  uint8(255),
  10044 				4:  uint8(255),
  10045 				5:  uint8(255),
  10046 				6:  uint8(255),
  10047 				7:  uint8(255),
  10048 				8:  uint8(255),
  10049 				9:  uint8(255),
  10050 				10: uint8(255),
  10051 			},
  10052 			2: {
  10053 				0:  uint8(255),
  10054 				1:  uint8(255),
  10055 				2:  uint8(255),
  10056 				3:  uint8(255),
  10057 				4:  uint8(255),
  10058 				5:  uint8(255),
  10059 				6:  uint8(255),
  10060 				7:  uint8(255),
  10061 				8:  uint8(255),
  10062 				9:  uint8(255),
  10063 				10: uint8(255),
  10064 			},
  10065 		},
  10066 		7: {
  10067 			0: {
  10068 				0:  uint8(255),
  10069 				1:  uint8(255),
  10070 				2:  uint8(255),
  10071 				3:  uint8(255),
  10072 				4:  uint8(255),
  10073 				5:  uint8(255),
  10074 				6:  uint8(255),
  10075 				7:  uint8(255),
  10076 				8:  uint8(255),
  10077 				9:  uint8(255),
  10078 				10: uint8(255),
  10079 			},
  10080 			1: {
  10081 				0:  uint8(254),
  10082 				1:  uint8(255),
  10083 				2:  uint8(255),
  10084 				3:  uint8(255),
  10085 				4:  uint8(255),
  10086 				5:  uint8(255),
  10087 				6:  uint8(255),
  10088 				7:  uint8(255),
  10089 				8:  uint8(255),
  10090 				9:  uint8(255),
  10091 				10: uint8(255),
  10092 			},
  10093 			2: {
  10094 				0:  uint8(255),
  10095 				1:  uint8(255),
  10096 				2:  uint8(255),
  10097 				3:  uint8(255),
  10098 				4:  uint8(255),
  10099 				5:  uint8(255),
  10100 				6:  uint8(255),
  10101 				7:  uint8(255),
  10102 				8:  uint8(255),
  10103 				9:  uint8(255),
  10104 				10: uint8(255),
  10105 			},
  10106 		},
  10107 	},
  10108 }
  10109 
  10110 // Paragraph 9.9
  10111 
  10112 var kBands = [17]uint8_t{
  10113 	1:  uint8(1),
  10114 	2:  uint8(2),
  10115 	3:  uint8(3),
  10116 	4:  uint8(6),
  10117 	5:  uint8(4),
  10118 	6:  uint8(5),
  10119 	7:  uint8(6),
  10120 	8:  uint8(6),
  10121 	9:  uint8(6),
  10122 	10: uint8(6),
  10123 	11: uint8(6),
  10124 	12: uint8(6),
  10125 	13: uint8(6),
  10126 	14: uint8(6),
  10127 	15: uint8(7),
  10128 }
  10129 
  10130 func VP8ParseProba(tls *libc.TLS, br2 uintptr, dec uintptr) {
  10131 	bp := tls.Alloc(16)
  10132 	defer tls.Free(16)
  10133 	var b, bit, c, p, pos, shift, t, v, v10, v12 int32
  10134 	var bits bit_t
  10135 	var proba, v6, v7 uintptr
  10136 	var range1, split, value range_t
  10137 	var v5 uint32
  10138 	var v8 uint64_t
  10139 	var _ /* in_bits at bp+0 */ lbit_t
  10140 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = b, bit, bits, c, p, pos, proba, range1, shift, split, t, v, value, v10, v12, v5, v6, v7, v8
  10141 	proba = dec + 1192
  10142 	t = 0
  10143 	for {
  10144 		if !(t < int32(NUM_TYPES)) {
  10145 			break
  10146 		}
  10147 		b = 0
  10148 		for {
  10149 			if !(b < int32(NUM_BANDS)) {
  10150 				break
  10151 			}
  10152 			c = 0
  10153 			for {
  10154 				if !(c < int32(NUM_CTX)) {
  10155 					break
  10156 				}
  10157 				p = 0
  10158 				for {
  10159 					if !(p < int32(NUM_PROBAS)) {
  10160 						break
  10161 					}
  10162 					v6 = br2
  10163 					range1 = (*VP8BitReader)(unsafe.Pointer(v6)).Frange1
  10164 					if (*VP8BitReader)(unsafe.Pointer(v6)).Fbits < libc.Int32FromInt32(0) {
  10165 						v7 = v6
  10166 						if (*VP8BitReader)(unsafe.Pointer(v7)).Fbuf < (*VP8BitReader)(unsafe.Pointer(v7)).Fbuf_max {
  10167 							libc.Xmemcpy(tls, bp, (*VP8BitReader)(unsafe.Pointer(v7)).Fbuf, uint64(8))
  10168 							**(**uintptr)(__ccgo_up(v7 + 16)) += uintptr(libc.Int32FromInt32(BITS) >> libc.Int32FromInt32(3))
  10169 							v8 = libc.X__builtin_bswap64(tls, **(**lbit_t)(__ccgo_up(bp)))
  10170 							goto _9
  10171 						_9:
  10172 							bits = v8
  10173 							bits = bits >> uint64(libc.Int32FromInt32(64)-libc.Int32FromInt32(BITS))
  10174 							(*VP8BitReader)(unsafe.Pointer(v7)).Fvalue = bits | (*VP8BitReader)(unsafe.Pointer(v7)).Fvalue<<libc.Int32FromInt32(BITS)
  10175 							**(**int32)(__ccgo_up(v7 + 12)) += int32(BITS)
  10176 						} else {
  10177 							VP8LoadFinalBytes(tls, v7)
  10178 						}
  10179 					}
  10180 					pos = (*VP8BitReader)(unsafe.Pointer(v6)).Fbits
  10181 					split = range1 * uint32(int32(**(**uint8_t)(__ccgo_up(uintptr(unsafe.Pointer(&CoeffsUpdateProba)) + uintptr(t)*264 + uintptr(b)*33 + uintptr(c)*11 + uintptr(p))))) >> int32(8)
  10182 					value = uint32((*VP8BitReader)(unsafe.Pointer(v6)).Fvalue >> pos)
  10183 					bit = libc.BoolInt32(value > split)
  10184 					if bit != 0 {
  10185 						range1 = range1 - split
  10186 						**(**bit_t)(__ccgo_up(v6)) -= uint64(split+libc.Uint32FromInt32(1)) << pos
  10187 					} else {
  10188 						range1 = split + uint32(1)
  10189 					}
  10190 					v10 = int32(31) ^ libc.X__builtin_clz(tls, range1)
  10191 					goto _11
  10192 				_11:
  10193 					shift = int32(7) ^ v10
  10194 					range1 = range1 << uint32(shift)
  10195 					**(**int32)(__ccgo_up(v6 + 12)) -= shift
  10196 					(*VP8BitReader)(unsafe.Pointer(v6)).Frange1 = range1 - uint32(1)
  10197 					v12 = bit
  10198 					goto _13
  10199 				_13:
  10200 					if v12 != 0 {
  10201 						v5 = VP8GetValue(tls, br2, int32(8))
  10202 					} else {
  10203 						v5 = uint32(**(**uint8_t)(__ccgo_up(uintptr(unsafe.Pointer(&CoeffsProba0)) + uintptr(t)*264 + uintptr(b)*33 + uintptr(c)*11 + uintptr(p))))
  10204 					}
  10205 					v = int32(v5)
  10206 					**(**uint8_t)(__ccgo_up(proba + 3 + uintptr(t)*264 + uintptr(b)*33 + uintptr(c)*11 + uintptr(p))) = uint8(v)
  10207 					goto _4
  10208 				_4:
  10209 					;
  10210 					p = p + 1
  10211 				}
  10212 				goto _3
  10213 			_3:
  10214 				;
  10215 				c = c + 1
  10216 			}
  10217 			goto _2
  10218 		_2:
  10219 			;
  10220 			b = b + 1
  10221 		}
  10222 		b = 0
  10223 		for {
  10224 			if !(b < libc.Int32FromInt32(16)+libc.Int32FromInt32(1)) {
  10225 				break
  10226 			}
  10227 			**(**uintptr)(__ccgo_up(proba + 1064 + uintptr(t)*136 + uintptr(b)*8)) = proba + 3 + uintptr(t)*264 + uintptr(kBands[b])*33
  10228 			goto _14
  10229 		_14:
  10230 			;
  10231 			b = b + 1
  10232 		}
  10233 		goto _1
  10234 	_1:
  10235 		;
  10236 		t = t + 1
  10237 	}
  10238 	(*VP8Decoder)(unsafe.Pointer(dec)).Fuse_skip_proba = int32(VP8GetValue(tls, br2, int32(1)))
  10239 	if (*VP8Decoder)(unsafe.Pointer(dec)).Fuse_skip_proba != 0 {
  10240 		(*VP8Decoder)(unsafe.Pointer(dec)).Fskip_p = uint8(VP8GetValue(tls, br2, int32(8)))
  10241 	}
  10242 }
  10243 
  10244 const SIZE_MAX2 = "_UI64_MAX"
  10245 
  10246 var kHashMul7 = uint32(0x1e35a7bd)
  10247 
  10248 // Copyright 2010 Google Inc. All Rights Reserved.
  10249 //
  10250 // Use of this source code is governed by a BSD-style license
  10251 // that can be found in the COPYING file in the root of the source
  10252 // tree. An additional intellectual property rights grant can be found
  10253 // in the file PATENTS. All contributing project authors may
  10254 // be found in the AUTHORS file in the root of the source tree.
  10255 // -----------------------------------------------------------------------------
  10256 //
  10257 // Boolean decoder
  10258 //
  10259 // Author: Skal (pascal.massimino@gmail.com)
  10260 //         Vikas Arora (vikaas.arora@gmail.com)
  10261 
  10262 // Copyright 2011 Google Inc. All Rights Reserved.
  10263 //
  10264 // Use of this source code is governed by a BSD-style license
  10265 // that can be found in the COPYING file in the root of the source
  10266 // tree. An additional intellectual property rights grant can be found
  10267 // in the file PATENTS. All contributing project authors may
  10268 // be found in the AUTHORS file in the root of the source tree.
  10269 // -----------------------------------------------------------------------------
  10270 //
  10271 // Multi-threaded worker
  10272 //
  10273 // Author: Skal (pascal.massimino@gmail.com)
  10274 
  10275 // Copyright 2012 Google Inc. All Rights Reserved.
  10276 //
  10277 // Use of this source code is governed by a BSD-style license
  10278 // that can be found in the COPYING file in the root of the source
  10279 // tree. An additional intellectual property rights grant can be found
  10280 // in the file PATENTS. All contributing project authors may
  10281 // be found in the AUTHORS file in the root of the source tree.
  10282 // -----------------------------------------------------------------------------
  10283 //
  10284 // Misc. common utility functions
  10285 //
  10286 // Authors: Skal (pascal.massimino@gmail.com)
  10287 //          Urvang (urvang@google.com)
  10288 
  10289 // Copyright 2010 Google Inc. All Rights Reserved.
  10290 //
  10291 // Use of this source code is governed by a BSD-style license
  10292 // that can be found in the COPYING file in the root of the source
  10293 // tree. An additional intellectual property rights grant can be found
  10294 // in the file PATENTS. All contributing project authors may
  10295 // be found in the AUTHORS file in the root of the source tree.
  10296 // -----------------------------------------------------------------------------
  10297 //
  10298 //  Main decoding functions for WebP images.
  10299 //
  10300 // Author: Skal (pascal.massimino@gmail.com)
  10301 
  10302 // Copyright 2012 Google Inc. All Rights Reserved.
  10303 //
  10304 // Use of this source code is governed by a BSD-style license
  10305 // that can be found in the COPYING file in the root of the source
  10306 // tree. An additional intellectual property rights grant can be found
  10307 // in the file PATENTS. All contributing project authors may
  10308 // be found in the AUTHORS file in the root of the source tree.
  10309 // -----------------------------------------------------------------------------
  10310 //
  10311 //  Internal header for constants related to WebP file format.
  10312 //
  10313 // Author: Urvang (urvang@google.com)
  10314 
  10315 // Copyright 2010 Google Inc. All Rights Reserved.
  10316 //
  10317 // Use of this source code is governed by a BSD-style license
  10318 // that can be found in the COPYING file in the root of the source
  10319 // tree. An additional intellectual property rights grant can be found
  10320 // in the file PATENTS. All contributing project authors may
  10321 // be found in the AUTHORS file in the root of the source tree.
  10322 // -----------------------------------------------------------------------------
  10323 //
  10324 //  Common types + memory wrappers
  10325 //
  10326 // Author: Skal (pascal.massimino@gmail.com)
  10327 
  10328 //------------------------------------------------------------------------------
  10329 
  10330 func WebPGetDecoderVersion(tls *libc.TLS) (r int32) {
  10331 	return libc.Int32FromInt32(DEC_MAJ_VERSION)<<libc.Int32FromInt32(16) | libc.Int32FromInt32(DEC_MIN_VERSION)<<libc.Int32FromInt32(8) | libc.Int32FromInt32(DEC_REV_VERSION)
  10332 }
  10333 
  10334 //------------------------------------------------------------------------------
  10335 // Signature and pointer-to-function for GetCoeffs() variants below.
  10336 
  10337 type GetCoeffsFunc = uintptr
  10338 
  10339 var GetCoeffs = uintptr(0)
  10340 
  10341 func init() {
  10342 	p := unsafe.Pointer(&GetCoeffs)
  10343 	*(*uintptr)(unsafe.Add(p, 0)) = libc.UintptrFromInt32(0)
  10344 }
  10345 
  10346 //------------------------------------------------------------------------------
  10347 // VP8Decoder
  10348 
  10349 func SetOk(tls *libc.TLS, dec uintptr) {
  10350 	(*VP8Decoder)(unsafe.Pointer(dec)).Fstatus = int32(VP8_STATUS_OK)
  10351 	(*VP8Decoder)(unsafe.Pointer(dec)).Ferror_msg = __ccgo_ts + 154
  10352 }
  10353 
  10354 func VP8InitIoInternal(tls *libc.TLS, io uintptr, version int32) (r int32) {
  10355 	if version>>int32(8) != libc.Int32FromInt32(WEBP_DECODER_ABI_VERSION)>>libc.Int32FromInt32(8) {
  10356 		return 0 // mismatch error
  10357 	}
  10358 	if io != libc.UintptrFromInt32(0) {
  10359 		libc.Xmemset(tls, io, 0, uint64(160))
  10360 	}
  10361 	return int32(1)
  10362 }
  10363 
  10364 func VP8New(tls *libc.TLS) (r uintptr) {
  10365 	var dec uintptr
  10366 	_ = dec
  10367 	dec = WebPSafeCalloc(tls, uint64(1), uint64(3024))
  10368 	if dec != libc.UintptrFromInt32(0) {
  10369 		SetOk(tls, dec)
  10370 		(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(&struct{ uintptr }{(*WebPWorkerInterface)(unsafe.Pointer(WebPGetWorkerInterface(tls))).FInit})))(tls, dec+152)
  10371 		(*VP8Decoder)(unsafe.Pointer(dec)).Fready = 0
  10372 		(*VP8Decoder)(unsafe.Pointer(dec)).Fnum_parts_minus_one = uint32(0)
  10373 		InitGetCoeffs(tls)
  10374 	}
  10375 	return dec
  10376 }
  10377 
  10378 func VP8Status(tls *libc.TLS, dec uintptr) (r VP8StatusCode1) {
  10379 	if !(dec != 0) {
  10380 		return int32(VP8_STATUS_INVALID_PARAM)
  10381 	}
  10382 	return (*VP8Decoder)(unsafe.Pointer(dec)).Fstatus
  10383 }
  10384 
  10385 func VP8StatusMessage(tls *libc.TLS, dec uintptr) (r uintptr) {
  10386 	if dec == libc.UintptrFromInt32(0) {
  10387 		return __ccgo_ts + 157
  10388 	}
  10389 	if !((*VP8Decoder)(unsafe.Pointer(dec)).Ferror_msg != 0) {
  10390 		return __ccgo_ts + 154
  10391 	}
  10392 	return (*VP8Decoder)(unsafe.Pointer(dec)).Ferror_msg
  10393 }
  10394 
  10395 func VP8Delete(tls *libc.TLS, dec uintptr) {
  10396 	if dec != libc.UintptrFromInt32(0) {
  10397 		VP8Clear(tls, dec)
  10398 		WebPSafeFree(tls, dec)
  10399 	}
  10400 }
  10401 
  10402 func VP8SetError(tls *libc.TLS, dec uintptr, error1 VP8StatusCode1, msg uintptr) (r int32) {
  10403 	// VP8_STATUS_SUSPENDED is only meaningful in incremental decoding.
  10404 	// The oldest error reported takes precedence over the new one.
  10405 	if (*VP8Decoder)(unsafe.Pointer(dec)).Fstatus == int32(VP8_STATUS_OK) {
  10406 		(*VP8Decoder)(unsafe.Pointer(dec)).Fstatus = error1
  10407 		(*VP8Decoder)(unsafe.Pointer(dec)).Ferror_msg = msg
  10408 		(*VP8Decoder)(unsafe.Pointer(dec)).Fready = 0
  10409 	}
  10410 	return 0
  10411 }
  10412 
  10413 //------------------------------------------------------------------------------
  10414 
  10415 func VP8CheckSignature(tls *libc.TLS, data uintptr, data_size size_t) (r int32) {
  10416 	return libc.BoolInt32(data_size >= uint64(3) && int32(**(**uint8_t)(__ccgo_up(data))) == int32(0x9d) && int32(**(**uint8_t)(__ccgo_up(data + 1))) == int32(0x01) && int32(**(**uint8_t)(__ccgo_up(data + 2))) == int32(0x2a))
  10417 }
  10418 
  10419 func VP8GetInfo(tls *libc.TLS, data uintptr, data_size size_t, chunk_size size_t, width uintptr, height uintptr) (r int32) {
  10420 	var bits uint32_t
  10421 	var h, key_frame, w int32
  10422 	_, _, _, _ = bits, h, key_frame, w
  10423 	if data == libc.UintptrFromInt32(0) || data_size < uint64(VP8_FRAME_HEADER_SIZE) {
  10424 		return 0 // not enough data
  10425 	}
  10426 	// check signature
  10427 	if !(VP8CheckSignature(tls, data+uintptr(3), data_size-uint64(3)) != 0) {
  10428 		return 0 // Wrong signature.
  10429 	} else {
  10430 		bits = uint32(int32(**(**uint8_t)(__ccgo_up(data))) | int32(**(**uint8_t)(__ccgo_up(data + 1)))<<int32(8) | int32(**(**uint8_t)(__ccgo_up(data + 2)))<<int32(16))
  10431 		key_frame = libc.BoolInt32(!(bits&libc.Uint32FromInt32(1) != 0))
  10432 		w = (int32(**(**uint8_t)(__ccgo_up(data + 7)))<<int32(8) | int32(**(**uint8_t)(__ccgo_up(data + 6)))) & int32(0x3fff)
  10433 		h = (int32(**(**uint8_t)(__ccgo_up(data + 9)))<<int32(8) | int32(**(**uint8_t)(__ccgo_up(data + 8)))) & int32(0x3fff)
  10434 		if !(key_frame != 0) { // Not a keyframe.
  10435 			return 0
  10436 		}
  10437 		if bits>>libc.Int32FromInt32(1)&uint32(7) > uint32(3) {
  10438 			return 0 // unknown profile
  10439 		}
  10440 		if !(bits>>libc.Int32FromInt32(4)&libc.Uint32FromInt32(1) != 0) {
  10441 			return 0 // first frame is invisible!
  10442 		}
  10443 		if uint64(bits>>libc.Int32FromInt32(5)) >= chunk_size { // partition_length
  10444 			return 0 // inconsistent size information.
  10445 		}
  10446 		if w == 0 || h == 0 {
  10447 			return 0 // We don't support both width and height to be zero.
  10448 		}
  10449 		if width != 0 {
  10450 			**(**int32)(__ccgo_up(width)) = w
  10451 		}
  10452 		if height != 0 {
  10453 			**(**int32)(__ccgo_up(height)) = h
  10454 		}
  10455 		return int32(1)
  10456 	}
  10457 	return r
  10458 }
  10459 
  10460 //------------------------------------------------------------------------------
  10461 // Header parsing
  10462 
  10463 func ResetSegmentHeader(tls *libc.TLS, hdr uintptr) {
  10464 	(*VP8SegmentHeader)(unsafe.Pointer(hdr)).Fuse_segment = 0
  10465 	(*VP8SegmentHeader)(unsafe.Pointer(hdr)).Fupdate_map = 0
  10466 	(*VP8SegmentHeader)(unsafe.Pointer(hdr)).Fabsolute_delta = int32(1)
  10467 	libc.Xmemset(tls, hdr+12, 0, uint64(4))
  10468 	libc.Xmemset(tls, hdr+16, 0, uint64(4))
  10469 }
  10470 
  10471 // C documentation
  10472 //
  10473 //	// Paragraph 9.3
  10474 func ParseSegmentHeader(tls *libc.TLS, br uintptr, hdr uintptr, proba uintptr) (r int32) {
  10475 	var s, s1, v2 int32
  10476 	var v6 uint32
  10477 	_, _, _, _ = s, s1, v2, v6
  10478 	(*VP8SegmentHeader)(unsafe.Pointer(hdr)).Fuse_segment = int32(VP8GetValue(tls, br, int32(1)))
  10479 	if (*VP8SegmentHeader)(unsafe.Pointer(hdr)).Fuse_segment != 0 {
  10480 		(*VP8SegmentHeader)(unsafe.Pointer(hdr)).Fupdate_map = int32(VP8GetValue(tls, br, int32(1)))
  10481 		if VP8GetValue(tls, br, int32(1)) != 0 {
  10482 			(*VP8SegmentHeader)(unsafe.Pointer(hdr)).Fabsolute_delta = int32(VP8GetValue(tls, br, int32(1)))
  10483 			s = 0
  10484 			for {
  10485 				if !(s < int32(NUM_MB_SEGMENTS)) {
  10486 					break
  10487 				}
  10488 				if VP8GetValue(tls, br, int32(1)) != 0 {
  10489 					v2 = VP8GetSignedValue(tls, br, int32(7))
  10490 				} else {
  10491 					v2 = 0
  10492 				}
  10493 				**(**int8_t)(__ccgo_up(hdr + 12 + uintptr(s))) = int8(v2)
  10494 				goto _1
  10495 			_1:
  10496 				;
  10497 				s = s + 1
  10498 			}
  10499 			s = 0
  10500 			for {
  10501 				if !(s < int32(NUM_MB_SEGMENTS)) {
  10502 					break
  10503 				}
  10504 				if VP8GetValue(tls, br, int32(1)) != 0 {
  10505 					v2 = VP8GetSignedValue(tls, br, int32(6))
  10506 				} else {
  10507 					v2 = 0
  10508 				}
  10509 				**(**int8_t)(__ccgo_up(hdr + 16 + uintptr(s))) = int8(v2)
  10510 				goto _3
  10511 			_3:
  10512 				;
  10513 				s = s + 1
  10514 			}
  10515 		}
  10516 		if (*VP8SegmentHeader)(unsafe.Pointer(hdr)).Fupdate_map != 0 {
  10517 			s1 = 0
  10518 			for {
  10519 				if !(s1 < int32(MB_FEATURE_TREE_PROBS)) {
  10520 					break
  10521 				}
  10522 				if VP8GetValue(tls, br, int32(1)) != 0 {
  10523 					v6 = VP8GetValue(tls, br, int32(8))
  10524 				} else {
  10525 					v6 = uint32(255)
  10526 				}
  10527 				**(**uint8_t)(__ccgo_up(proba + uintptr(s1))) = uint8(v6)
  10528 				goto _5
  10529 			_5:
  10530 				;
  10531 				s1 = s1 + 1
  10532 			}
  10533 		}
  10534 	} else {
  10535 		(*VP8SegmentHeader)(unsafe.Pointer(hdr)).Fupdate_map = 0
  10536 	}
  10537 	return libc.BoolInt32(!((*VP8BitReader)(unsafe.Pointer(br)).Feof != 0))
  10538 }
  10539 
  10540 // C documentation
  10541 //
  10542 //	// Paragraph 9.5
  10543 //	// If we don't have all the necessary data in 'buf', this function returns
  10544 //	// VP8_STATUS_SUSPENDED in incremental decoding, VP8_STATUS_NOT_ENOUGH_DATA
  10545 //	// otherwise.
  10546 //	// In incremental decoding, this case is not necessarily an error. Still, no
  10547 //	// bitreader is ever initialized to make it possible to read unavailable memory.
  10548 //	// If we don't even have the partitions' sizes, then VP8_STATUS_NOT_ENOUGH_DATA
  10549 //	// is returned, and this is an unrecoverable error.
  10550 //	// If the partitions were positioned ok, VP8_STATUS_OK is returned.
  10551 func ParsePartitions(tls *libc.TLS, dec uintptr, buf uintptr, size size_t) (r VP8StatusCode1) {
  10552 	var br, buf_end, part_start, sz uintptr
  10553 	var last_part, p, psize, size_left size_t
  10554 	var v2 int32
  10555 	_, _, _, _, _, _, _, _, _ = br, buf_end, last_part, p, part_start, psize, size_left, sz, v2
  10556 	br = dec + 16
  10557 	sz = buf
  10558 	buf_end = buf + uintptr(size)
  10559 	size_left = size
  10560 	(*VP8Decoder)(unsafe.Pointer(dec)).Fnum_parts_minus_one = uint32(int32(1)<<VP8GetValue(tls, br, int32(2)) - int32(1))
  10561 	last_part = uint64((*VP8Decoder)(unsafe.Pointer(dec)).Fnum_parts_minus_one)
  10562 	if size < uint64(3)*last_part {
  10563 		// we can't even read the sizes with sz[]! That's a failure.
  10564 		return int32(VP8_STATUS_NOT_ENOUGH_DATA)
  10565 	}
  10566 	part_start = buf + uintptr(last_part*uint64(3))
  10567 	size_left = size_left - last_part*uint64(3)
  10568 	p = uint64(0)
  10569 	for {
  10570 		if !(p < last_part) {
  10571 			break
  10572 		}
  10573 		psize = uint64(int32(**(**uint8_t)(__ccgo_up(sz))) | int32(**(**uint8_t)(__ccgo_up(sz + 1)))<<int32(8) | int32(**(**uint8_t)(__ccgo_up(sz + 2)))<<int32(16))
  10574 		if psize > size_left {
  10575 			psize = size_left
  10576 		}
  10577 		VP8InitBitReader(tls, dec+440+uintptr(p)*48, part_start, psize)
  10578 		part_start = part_start + uintptr(psize)
  10579 		size_left = size_left - psize
  10580 		sz = sz + uintptr(3)
  10581 		goto _1
  10582 	_1:
  10583 		;
  10584 		p = p + 1
  10585 	}
  10586 	VP8InitBitReader(tls, dec+440+uintptr(last_part)*48, part_start, size_left)
  10587 	if part_start < buf_end {
  10588 		return int32(VP8_STATUS_OK)
  10589 	}
  10590 	if (*VP8Decoder)(unsafe.Pointer(dec)).Fincremental != 0 {
  10591 		v2 = int32(VP8_STATUS_SUSPENDED)
  10592 	} else {
  10593 		v2 = int32(VP8_STATUS_NOT_ENOUGH_DATA)
  10594 	}
  10595 	return v2
  10596 }
  10597 
  10598 // C documentation
  10599 //
  10600 //	// Paragraph 9.4
  10601 func ParseFilterHeader(tls *libc.TLS, br uintptr, dec uintptr) (r int32) {
  10602 	var hdr uintptr
  10603 	var i, v3, v4 int32
  10604 	_, _, _, _ = hdr, i, v3, v4
  10605 	hdr = dec + 84
  10606 	(*VP8FilterHeader)(unsafe.Pointer(hdr)).Fsimple = int32(VP8GetValue(tls, br, int32(1)))
  10607 	(*VP8FilterHeader)(unsafe.Pointer(hdr)).Flevel = int32(VP8GetValue(tls, br, int32(6)))
  10608 	(*VP8FilterHeader)(unsafe.Pointer(hdr)).Fsharpness = int32(VP8GetValue(tls, br, int32(3)))
  10609 	(*VP8FilterHeader)(unsafe.Pointer(hdr)).Fuse_lf_delta = int32(VP8GetValue(tls, br, int32(1)))
  10610 	if (*VP8FilterHeader)(unsafe.Pointer(hdr)).Fuse_lf_delta != 0 {
  10611 		if VP8GetValue(tls, br, int32(1)) != 0 {
  10612 			i = 0
  10613 			for {
  10614 				if !(i < int32(NUM_REF_LF_DELTAS)) {
  10615 					break
  10616 				}
  10617 				if VP8GetValue(tls, br, int32(1)) != 0 {
  10618 					**(**int32)(__ccgo_up(hdr + 16 + uintptr(i)*4)) = VP8GetSignedValue(tls, br, int32(6))
  10619 				}
  10620 				goto _1
  10621 			_1:
  10622 				;
  10623 				i = i + 1
  10624 			}
  10625 			i = 0
  10626 			for {
  10627 				if !(i < int32(NUM_MODE_LF_DELTAS)) {
  10628 					break
  10629 				}
  10630 				if VP8GetValue(tls, br, int32(1)) != 0 {
  10631 					**(**int32)(__ccgo_up(hdr + 32 + uintptr(i)*4)) = VP8GetSignedValue(tls, br, int32(6))
  10632 				}
  10633 				goto _2
  10634 			_2:
  10635 				;
  10636 				i = i + 1
  10637 			}
  10638 		}
  10639 	}
  10640 	if (*VP8FilterHeader)(unsafe.Pointer(hdr)).Flevel == 0 {
  10641 		v3 = 0
  10642 	} else {
  10643 		if (*VP8FilterHeader)(unsafe.Pointer(hdr)).Fsimple != 0 {
  10644 			v4 = int32(1)
  10645 		} else {
  10646 			v4 = int32(2)
  10647 		}
  10648 		v3 = v4
  10649 	}
  10650 	(*VP8Decoder)(unsafe.Pointer(dec)).Ffilter_type = v3
  10651 	return libc.BoolInt32(!((*VP8BitReader)(unsafe.Pointer(br)).Feof != 0))
  10652 }
  10653 
  10654 // C documentation
  10655 //
  10656 //	// Topmost call
  10657 func VP8GetHeaders(tls *libc.TLS, dec uintptr, io uintptr) (r int32) {
  10658 	var bits uint32_t
  10659 	var br, buf, frm_hdr, pic_hdr uintptr
  10660 	var buf_size size_t
  10661 	var status VP8StatusCode1
  10662 	_, _, _, _, _, _, _ = bits, br, buf, buf_size, frm_hdr, pic_hdr, status
  10663 	if dec == libc.UintptrFromInt32(0) {
  10664 		return 0
  10665 	}
  10666 	SetOk(tls, dec)
  10667 	if io == libc.UintptrFromInt32(0) {
  10668 		return VP8SetError(tls, dec, int32(VP8_STATUS_INVALID_PARAM), __ccgo_ts+167)
  10669 	}
  10670 	buf = (*VP8Io)(unsafe.Pointer(io)).Fdata
  10671 	buf_size = (*VP8Io)(unsafe.Pointer(io)).Fdata_size
  10672 	if buf_size < uint64(4) {
  10673 		return VP8SetError(tls, dec, int32(VP8_STATUS_NOT_ENOUGH_DATA), __ccgo_ts+204)
  10674 	}
  10675 	// Paragraph 9.1
  10676 	bits = uint32(int32(**(**uint8_t)(__ccgo_up(buf))) | int32(**(**uint8_t)(__ccgo_up(buf + 1)))<<int32(8) | int32(**(**uint8_t)(__ccgo_up(buf + 2)))<<int32(16))
  10677 	frm_hdr = dec + 68
  10678 	(*VP8FrameHeader)(unsafe.Pointer(frm_hdr)).Fkey_frame = libc.BoolUint8(!(bits&libc.Uint32FromInt32(1) != 0))
  10679 	(*VP8FrameHeader)(unsafe.Pointer(frm_hdr)).Fprofile = uint8(bits >> libc.Int32FromInt32(1) & uint32(7))
  10680 	(*VP8FrameHeader)(unsafe.Pointer(frm_hdr)).Fshow = uint8(bits >> libc.Int32FromInt32(4) & uint32(1))
  10681 	(*VP8FrameHeader)(unsafe.Pointer(frm_hdr)).Fpartition_length = bits >> libc.Int32FromInt32(5)
  10682 	if int32((*VP8FrameHeader)(unsafe.Pointer(frm_hdr)).Fprofile) > int32(3) {
  10683 		return VP8SetError(tls, dec, int32(VP8_STATUS_BITSTREAM_ERROR), __ccgo_ts+222)
  10684 	}
  10685 	if !((*VP8FrameHeader)(unsafe.Pointer(frm_hdr)).Fshow != 0) {
  10686 		return VP8SetError(tls, dec, int32(VP8_STATUS_UNSUPPORTED_FEATURE), __ccgo_ts+253)
  10687 	}
  10688 	buf = buf + uintptr(3)
  10689 	buf_size = buf_size - uint64(3)
  10690 	pic_hdr = dec + 76
  10691 	if (*VP8FrameHeader)(unsafe.Pointer(frm_hdr)).Fkey_frame != 0 {
  10692 		// Paragraph 9.2
  10693 		if buf_size < uint64(7) {
  10694 			return VP8SetError(tls, dec, int32(VP8_STATUS_NOT_ENOUGH_DATA), __ccgo_ts+276)
  10695 		}
  10696 		if !(VP8CheckSignature(tls, buf, buf_size) != 0) {
  10697 			return VP8SetError(tls, dec, int32(VP8_STATUS_BITSTREAM_ERROR), __ccgo_ts+304)
  10698 		}
  10699 		(*VP8PictureHeader)(unsafe.Pointer(pic_hdr)).Fwidth = uint16((int32(**(**uint8_t)(__ccgo_up(buf + 4)))<<int32(8) | int32(**(**uint8_t)(__ccgo_up(buf + 3)))) & int32(0x3fff))
  10700 		(*VP8PictureHeader)(unsafe.Pointer(pic_hdr)).Fxscale = uint8(int32(**(**uint8_t)(__ccgo_up(buf + 4))) >> int32(6)) // ratio: 1, 5/4 5/3 or 2
  10701 		(*VP8PictureHeader)(unsafe.Pointer(pic_hdr)).Fheight = uint16((int32(**(**uint8_t)(__ccgo_up(buf + 6)))<<int32(8) | int32(**(**uint8_t)(__ccgo_up(buf + 5)))) & int32(0x3fff))
  10702 		(*VP8PictureHeader)(unsafe.Pointer(pic_hdr)).Fyscale = uint8(int32(**(**uint8_t)(__ccgo_up(buf + 6))) >> int32(6))
  10703 		buf = buf + uintptr(7)
  10704 		buf_size = buf_size - uint64(7)
  10705 		(*VP8Decoder)(unsafe.Pointer(dec)).Fmb_w = (int32((*VP8PictureHeader)(unsafe.Pointer(pic_hdr)).Fwidth) + int32(15)) >> int32(4)
  10706 		(*VP8Decoder)(unsafe.Pointer(dec)).Fmb_h = (int32((*VP8PictureHeader)(unsafe.Pointer(pic_hdr)).Fheight) + int32(15)) >> int32(4)
  10707 		// Setup default output area (can be later modified during io->setup())
  10708 		(*VP8Io)(unsafe.Pointer(io)).Fwidth = int32((*VP8PictureHeader)(unsafe.Pointer(pic_hdr)).Fwidth)
  10709 		(*VP8Io)(unsafe.Pointer(io)).Fheight = int32((*VP8PictureHeader)(unsafe.Pointer(pic_hdr)).Fheight)
  10710 		// IMPORTANT! use some sane dimensions in crop* and scaled* fields.
  10711 		// So they can be used interchangeably without always testing for
  10712 		// 'use_cropping'.
  10713 		(*VP8Io)(unsafe.Pointer(io)).Fuse_cropping = 0
  10714 		(*VP8Io)(unsafe.Pointer(io)).Fcrop_top = 0
  10715 		(*VP8Io)(unsafe.Pointer(io)).Fcrop_left = 0
  10716 		(*VP8Io)(unsafe.Pointer(io)).Fcrop_right = (*VP8Io)(unsafe.Pointer(io)).Fwidth
  10717 		(*VP8Io)(unsafe.Pointer(io)).Fcrop_bottom = (*VP8Io)(unsafe.Pointer(io)).Fheight
  10718 		(*VP8Io)(unsafe.Pointer(io)).Fuse_scaling = 0
  10719 		(*VP8Io)(unsafe.Pointer(io)).Fscaled_width = (*VP8Io)(unsafe.Pointer(io)).Fwidth
  10720 		(*VP8Io)(unsafe.Pointer(io)).Fscaled_height = (*VP8Io)(unsafe.Pointer(io)).Fheight
  10721 		(*VP8Io)(unsafe.Pointer(io)).Fmb_w = (*VP8Io)(unsafe.Pointer(io)).Fwidth  // for soundness
  10722 		(*VP8Io)(unsafe.Pointer(io)).Fmb_h = (*VP8Io)(unsafe.Pointer(io)).Fheight // ditto
  10723 		VP8ResetProba(tls, dec+1192)
  10724 		ResetSegmentHeader(tls, dec+132)
  10725 	}
  10726 	// Check if we have all the partition #0 available, and initialize dec->br
  10727 	// to read this partition (and this partition only).
  10728 	if uint64((*VP8FrameHeader)(unsafe.Pointer(frm_hdr)).Fpartition_length) > buf_size {
  10729 		return VP8SetError(tls, dec, int32(VP8_STATUS_NOT_ENOUGH_DATA), __ccgo_ts+318)
  10730 	}
  10731 	br = dec + 16
  10732 	VP8InitBitReader(tls, br, buf, uint64((*VP8FrameHeader)(unsafe.Pointer(frm_hdr)).Fpartition_length))
  10733 	buf = buf + uintptr((*VP8FrameHeader)(unsafe.Pointer(frm_hdr)).Fpartition_length)
  10734 	buf_size = buf_size - uint64((*VP8FrameHeader)(unsafe.Pointer(frm_hdr)).Fpartition_length)
  10735 	if (*VP8FrameHeader)(unsafe.Pointer(frm_hdr)).Fkey_frame != 0 {
  10736 		(*VP8PictureHeader)(unsafe.Pointer(pic_hdr)).Fcolorspace = uint8(VP8GetValue(tls, br, int32(1)))
  10737 		(*VP8PictureHeader)(unsafe.Pointer(pic_hdr)).Fclamp_type = uint8(VP8GetValue(tls, br, int32(1)))
  10738 	}
  10739 	if !(ParseSegmentHeader(tls, br, dec+132, dec+1192) != 0) {
  10740 		return VP8SetError(tls, dec, int32(VP8_STATUS_BITSTREAM_ERROR), __ccgo_ts+339)
  10741 	}
  10742 	// Filter specs
  10743 	if !(ParseFilterHeader(tls, br, dec) != 0) {
  10744 		return VP8SetError(tls, dec, int32(VP8_STATUS_BITSTREAM_ERROR), __ccgo_ts+367)
  10745 	}
  10746 	status = ParsePartitions(tls, dec, buf, buf_size)
  10747 	if status != int32(VP8_STATUS_OK) {
  10748 		return VP8SetError(tls, dec, status, __ccgo_ts+394)
  10749 	}
  10750 	// quantizer change
  10751 	VP8ParseQuant(tls, dec)
  10752 	// Frame buffer marking
  10753 	if !((*VP8FrameHeader)(unsafe.Pointer(frm_hdr)).Fkey_frame != 0) {
  10754 		return VP8SetError(tls, dec, int32(VP8_STATUS_UNSUPPORTED_FEATURE), __ccgo_ts+418)
  10755 	}
  10756 	VP8GetValue(tls, br, int32(1)) // ignore the value of 'update_proba'
  10757 	VP8ParseProba(tls, br, dec)
  10758 	// sanitized state
  10759 	(*VP8Decoder)(unsafe.Pointer(dec)).Fready = int32(1)
  10760 	return int32(1)
  10761 }
  10762 
  10763 //------------------------------------------------------------------------------
  10764 // Residual decoding (Paragraph 13.2 / 13.3)
  10765 
  10766 var kCat3 = [4]uint8_t{
  10767 	0: uint8(173),
  10768 	1: uint8(148),
  10769 	2: uint8(140),
  10770 }
  10771 var kCat4 = [5]uint8_t{
  10772 	0: uint8(176),
  10773 	1: uint8(155),
  10774 	2: uint8(140),
  10775 	3: uint8(135),
  10776 }
  10777 var kCat5 = [6]uint8_t{
  10778 	0: uint8(180),
  10779 	1: uint8(157),
  10780 	2: uint8(141),
  10781 	3: uint8(134),
  10782 	4: uint8(130),
  10783 }
  10784 var kCat6 = [12]uint8_t{
  10785 	0:  uint8(254),
  10786 	1:  uint8(254),
  10787 	2:  uint8(243),
  10788 	3:  uint8(230),
  10789 	4:  uint8(196),
  10790 	5:  uint8(177),
  10791 	6:  uint8(153),
  10792 	7:  uint8(140),
  10793 	8:  uint8(133),
  10794 	9:  uint8(130),
  10795 	10: uint8(129),
  10796 }
  10797 var kCat3456 = [4]uintptr{
  10798 	0: uintptr(unsafe.Pointer(&kCat3)),
  10799 	1: uintptr(unsafe.Pointer(&kCat4)),
  10800 	2: uintptr(unsafe.Pointer(&kCat5)),
  10801 	3: uintptr(unsafe.Pointer(&kCat6)),
  10802 }
  10803 var kZigzag = [16]uint8_t{
  10804 	1:  uint8(1),
  10805 	2:  uint8(4),
  10806 	3:  uint8(8),
  10807 	4:  uint8(5),
  10808 	5:  uint8(2),
  10809 	6:  uint8(3),
  10810 	7:  uint8(6),
  10811 	8:  uint8(9),
  10812 	9:  uint8(12),
  10813 	10: uint8(13),
  10814 	11: uint8(10),
  10815 	12: uint8(7),
  10816 	13: uint8(11),
  10817 	14: uint8(14),
  10818 	15: uint8(15),
  10819 }
  10820 
  10821 // C documentation
  10822 //
  10823 //	// See section 13-2: https://datatracker.ietf.org/doc/html/rfc6386#section-13.2
  10824 func GetLargeValue(tls *libc.TLS, br2 uintptr, p uintptr) (r int32) {
  10825 	bp := tls.Alloc(16)
  10826 	defer tls.Free(16)
  10827 	var bit, bit0, bit1, cat, pos, shift, v, v13, v15, v21, v23, v5, v7 int32
  10828 	var bits bit_t
  10829 	var range1, split, value range_t
  10830 	var tab, v1, v10, v17, v18, v2, v9 uintptr
  10831 	var v11, v19, v3 uint64_t
  10832 	var _ /* in_bits at bp+0 */ lbit_t
  10833 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  10834 	v1 = br2
  10835 	range1 = (*VP8BitReader)(unsafe.Pointer(v1)).Frange1
  10836 	if (*VP8BitReader)(unsafe.Pointer(v1)).Fbits < libc.Int32FromInt32(0) {
  10837 		v2 = v1
  10838 		if (*VP8BitReader)(unsafe.Pointer(v2)).Fbuf < (*VP8BitReader)(unsafe.Pointer(v2)).Fbuf_max {
  10839 			libc.Xmemcpy(tls, bp, (*VP8BitReader)(unsafe.Pointer(v2)).Fbuf, uint64(8))
  10840 			**(**uintptr)(__ccgo_up(v2 + 16)) += uintptr(libc.Int32FromInt32(BITS) >> libc.Int32FromInt32(3))
  10841 			v3 = libc.X__builtin_bswap64(tls, **(**lbit_t)(__ccgo_up(bp)))
  10842 			goto _4
  10843 		_4:
  10844 			bits = v3
  10845 			bits = bits >> uint64(libc.Int32FromInt32(64)-libc.Int32FromInt32(BITS))
  10846 			(*VP8BitReader)(unsafe.Pointer(v2)).Fvalue = bits | (*VP8BitReader)(unsafe.Pointer(v2)).Fvalue<<libc.Int32FromInt32(BITS)
  10847 			**(**int32)(__ccgo_up(v2 + 12)) += int32(BITS)
  10848 		} else {
  10849 			VP8LoadFinalBytes(tls, v2)
  10850 		}
  10851 	}
  10852 	pos = (*VP8BitReader)(unsafe.Pointer(v1)).Fbits
  10853 	split = range1 * uint32(int32(**(**uint8_t)(__ccgo_up(p + 3)))) >> int32(8)
  10854 	value = uint32((*VP8BitReader)(unsafe.Pointer(v1)).Fvalue >> pos)
  10855 	bit = libc.BoolInt32(value > split)
  10856 	if bit != 0 {
  10857 		range1 = range1 - split
  10858 		**(**bit_t)(__ccgo_up(v1)) -= uint64(split+libc.Uint32FromInt32(1)) << pos
  10859 	} else {
  10860 		range1 = split + uint32(1)
  10861 	}
  10862 	v5 = int32(31) ^ libc.X__builtin_clz(tls, range1)
  10863 	goto _6
  10864 _6:
  10865 	shift = int32(7) ^ v5
  10866 	range1 = range1 << uint32(shift)
  10867 	**(**int32)(__ccgo_up(v1 + 12)) -= shift
  10868 	(*VP8BitReader)(unsafe.Pointer(v1)).Frange1 = range1 - uint32(1)
  10869 	v7 = bit
  10870 	goto _8
  10871 _8:
  10872 	if !(v7 != 0) {
  10873 		v9 = br2
  10874 		range1 = (*VP8BitReader)(unsafe.Pointer(v9)).Frange1
  10875 		if (*VP8BitReader)(unsafe.Pointer(v9)).Fbits < libc.Int32FromInt32(0) {
  10876 			v10 = v9
  10877 			if (*VP8BitReader)(unsafe.Pointer(v10)).Fbuf < (*VP8BitReader)(unsafe.Pointer(v10)).Fbuf_max {
  10878 				libc.Xmemcpy(tls, bp, (*VP8BitReader)(unsafe.Pointer(v10)).Fbuf, uint64(8))
  10879 				**(**uintptr)(__ccgo_up(v10 + 16)) += uintptr(libc.Int32FromInt32(BITS) >> libc.Int32FromInt32(3))
  10880 				v11 = libc.X__builtin_bswap64(tls, **(**lbit_t)(__ccgo_up(bp)))
  10881 				goto _12
  10882 			_12:
  10883 				bits = v11
  10884 				bits = bits >> uint64(libc.Int32FromInt32(64)-libc.Int32FromInt32(BITS))
  10885 				(*VP8BitReader)(unsafe.Pointer(v10)).Fvalue = bits | (*VP8BitReader)(unsafe.Pointer(v10)).Fvalue<<libc.Int32FromInt32(BITS)
  10886 				**(**int32)(__ccgo_up(v10 + 12)) += int32(BITS)
  10887 			} else {
  10888 				VP8LoadFinalBytes(tls, v10)
  10889 			}
  10890 		}
  10891 		pos = (*VP8BitReader)(unsafe.Pointer(v9)).Fbits
  10892 		split = range1 * uint32(int32(**(**uint8_t)(__ccgo_up(p + 4)))) >> int32(8)
  10893 		value = uint32((*VP8BitReader)(unsafe.Pointer(v9)).Fvalue >> pos)
  10894 		bit = libc.BoolInt32(value > split)
  10895 		if bit != 0 {
  10896 			range1 = range1 - split
  10897 			**(**bit_t)(__ccgo_up(v9)) -= uint64(split+libc.Uint32FromInt32(1)) << pos
  10898 		} else {
  10899 			range1 = split + uint32(1)
  10900 		}
  10901 		v13 = int32(31) ^ libc.X__builtin_clz(tls, range1)
  10902 		goto _14
  10903 	_14:
  10904 		shift = int32(7) ^ v13
  10905 		range1 = range1 << uint32(shift)
  10906 		**(**int32)(__ccgo_up(v9 + 12)) -= shift
  10907 		(*VP8BitReader)(unsafe.Pointer(v9)).Frange1 = range1 - uint32(1)
  10908 		v15 = bit
  10909 		goto _16
  10910 	_16:
  10911 		if !(v15 != 0) {
  10912 			v = int32(2)
  10913 		} else {
  10914 			v1 = br2
  10915 			range1 = (*VP8BitReader)(unsafe.Pointer(v1)).Frange1
  10916 			if (*VP8BitReader)(unsafe.Pointer(v1)).Fbits < libc.Int32FromInt32(0) {
  10917 				v2 = v1
  10918 				if (*VP8BitReader)(unsafe.Pointer(v2)).Fbuf < (*VP8BitReader)(unsafe.Pointer(v2)).Fbuf_max {
  10919 					libc.Xmemcpy(tls, bp, (*VP8BitReader)(unsafe.Pointer(v2)).Fbuf, uint64(8))
  10920 					**(**uintptr)(__ccgo_up(v2 + 16)) += uintptr(libc.Int32FromInt32(BITS) >> libc.Int32FromInt32(3))
  10921 					v3 = libc.X__builtin_bswap64(tls, **(**lbit_t)(__ccgo_up(bp)))
  10922 					goto _20
  10923 				_20:
  10924 					bits = v3
  10925 					bits = bits >> uint64(libc.Int32FromInt32(64)-libc.Int32FromInt32(BITS))
  10926 					(*VP8BitReader)(unsafe.Pointer(v2)).Fvalue = bits | (*VP8BitReader)(unsafe.Pointer(v2)).Fvalue<<libc.Int32FromInt32(BITS)
  10927 					**(**int32)(__ccgo_up(v2 + 12)) += int32(BITS)
  10928 				} else {
  10929 					VP8LoadFinalBytes(tls, v2)
  10930 				}
  10931 			}
  10932 			pos = (*VP8BitReader)(unsafe.Pointer(v1)).Fbits
  10933 			split = range1 * uint32(int32(**(**uint8_t)(__ccgo_up(p + 5)))) >> int32(8)
  10934 			value = uint32((*VP8BitReader)(unsafe.Pointer(v1)).Fvalue >> pos)
  10935 			bit = libc.BoolInt32(value > split)
  10936 			if bit != 0 {
  10937 				range1 = range1 - split
  10938 				**(**bit_t)(__ccgo_up(v1)) -= uint64(split+libc.Uint32FromInt32(1)) << pos
  10939 			} else {
  10940 				range1 = split + uint32(1)
  10941 			}
  10942 			v5 = int32(31) ^ libc.X__builtin_clz(tls, range1)
  10943 			goto _22
  10944 		_22:
  10945 			shift = int32(7) ^ v5
  10946 			range1 = range1 << uint32(shift)
  10947 			**(**int32)(__ccgo_up(v1 + 12)) -= shift
  10948 			(*VP8BitReader)(unsafe.Pointer(v1)).Frange1 = range1 - uint32(1)
  10949 			v7 = bit
  10950 			goto _24
  10951 		_24:
  10952 			v = int32(3) + v7
  10953 		}
  10954 	} else {
  10955 		v1 = br2
  10956 		range1 = (*VP8BitReader)(unsafe.Pointer(v1)).Frange1
  10957 		if (*VP8BitReader)(unsafe.Pointer(v1)).Fbits < libc.Int32FromInt32(0) {
  10958 			v2 = v1
  10959 			if (*VP8BitReader)(unsafe.Pointer(v2)).Fbuf < (*VP8BitReader)(unsafe.Pointer(v2)).Fbuf_max {
  10960 				libc.Xmemcpy(tls, bp, (*VP8BitReader)(unsafe.Pointer(v2)).Fbuf, uint64(8))
  10961 				**(**uintptr)(__ccgo_up(v2 + 16)) += uintptr(libc.Int32FromInt32(BITS) >> libc.Int32FromInt32(3))
  10962 				v3 = libc.X__builtin_bswap64(tls, **(**lbit_t)(__ccgo_up(bp)))
  10963 				goto _28
  10964 			_28:
  10965 				bits = v3
  10966 				bits = bits >> uint64(libc.Int32FromInt32(64)-libc.Int32FromInt32(BITS))
  10967 				(*VP8BitReader)(unsafe.Pointer(v2)).Fvalue = bits | (*VP8BitReader)(unsafe.Pointer(v2)).Fvalue<<libc.Int32FromInt32(BITS)
  10968 				**(**int32)(__ccgo_up(v2 + 12)) += int32(BITS)
  10969 			} else {
  10970 				VP8LoadFinalBytes(tls, v2)
  10971 			}
  10972 		}
  10973 		pos = (*VP8BitReader)(unsafe.Pointer(v1)).Fbits
  10974 		split = range1 * uint32(int32(**(**uint8_t)(__ccgo_up(p + 6)))) >> int32(8)
  10975 		value = uint32((*VP8BitReader)(unsafe.Pointer(v1)).Fvalue >> pos)
  10976 		bit = libc.BoolInt32(value > split)
  10977 		if bit != 0 {
  10978 			range1 = range1 - split
  10979 			**(**bit_t)(__ccgo_up(v1)) -= uint64(split+libc.Uint32FromInt32(1)) << pos
  10980 		} else {
  10981 			range1 = split + uint32(1)
  10982 		}
  10983 		v5 = int32(31) ^ libc.X__builtin_clz(tls, range1)
  10984 		goto _30
  10985 	_30:
  10986 		shift = int32(7) ^ v5
  10987 		range1 = range1 << uint32(shift)
  10988 		**(**int32)(__ccgo_up(v1 + 12)) -= shift
  10989 		(*VP8BitReader)(unsafe.Pointer(v1)).Frange1 = range1 - uint32(1)
  10990 		v7 = bit
  10991 		goto _32
  10992 	_32:
  10993 		if !(v7 != 0) {
  10994 			v9 = br2
  10995 			range1 = (*VP8BitReader)(unsafe.Pointer(v9)).Frange1
  10996 			if (*VP8BitReader)(unsafe.Pointer(v9)).Fbits < libc.Int32FromInt32(0) {
  10997 				v10 = v9
  10998 				if (*VP8BitReader)(unsafe.Pointer(v10)).Fbuf < (*VP8BitReader)(unsafe.Pointer(v10)).Fbuf_max {
  10999 					libc.Xmemcpy(tls, bp, (*VP8BitReader)(unsafe.Pointer(v10)).Fbuf, uint64(8))
  11000 					**(**uintptr)(__ccgo_up(v10 + 16)) += uintptr(libc.Int32FromInt32(BITS) >> libc.Int32FromInt32(3))
  11001 					v11 = libc.X__builtin_bswap64(tls, **(**lbit_t)(__ccgo_up(bp)))
  11002 					goto _36
  11003 				_36:
  11004 					bits = v11
  11005 					bits = bits >> uint64(libc.Int32FromInt32(64)-libc.Int32FromInt32(BITS))
  11006 					(*VP8BitReader)(unsafe.Pointer(v10)).Fvalue = bits | (*VP8BitReader)(unsafe.Pointer(v10)).Fvalue<<libc.Int32FromInt32(BITS)
  11007 					**(**int32)(__ccgo_up(v10 + 12)) += int32(BITS)
  11008 				} else {
  11009 					VP8LoadFinalBytes(tls, v10)
  11010 				}
  11011 			}
  11012 			pos = (*VP8BitReader)(unsafe.Pointer(v9)).Fbits
  11013 			split = range1 * uint32(int32(**(**uint8_t)(__ccgo_up(p + 7)))) >> int32(8)
  11014 			value = uint32((*VP8BitReader)(unsafe.Pointer(v9)).Fvalue >> pos)
  11015 			bit = libc.BoolInt32(value > split)
  11016 			if bit != 0 {
  11017 				range1 = range1 - split
  11018 				**(**bit_t)(__ccgo_up(v9)) -= uint64(split+libc.Uint32FromInt32(1)) << pos
  11019 			} else {
  11020 				range1 = split + uint32(1)
  11021 			}
  11022 			v13 = int32(31) ^ libc.X__builtin_clz(tls, range1)
  11023 			goto _38
  11024 		_38:
  11025 			shift = int32(7) ^ v13
  11026 			range1 = range1 << uint32(shift)
  11027 			**(**int32)(__ccgo_up(v9 + 12)) -= shift
  11028 			(*VP8BitReader)(unsafe.Pointer(v9)).Frange1 = range1 - uint32(1)
  11029 			v15 = bit
  11030 			goto _40
  11031 		_40:
  11032 			if !(v15 != 0) {
  11033 				v17 = br2
  11034 				range1 = (*VP8BitReader)(unsafe.Pointer(v17)).Frange1
  11035 				if (*VP8BitReader)(unsafe.Pointer(v17)).Fbits < libc.Int32FromInt32(0) {
  11036 					v18 = v17
  11037 					if (*VP8BitReader)(unsafe.Pointer(v18)).Fbuf < (*VP8BitReader)(unsafe.Pointer(v18)).Fbuf_max {
  11038 						libc.Xmemcpy(tls, bp, (*VP8BitReader)(unsafe.Pointer(v18)).Fbuf, uint64(8))
  11039 						**(**uintptr)(__ccgo_up(v18 + 16)) += uintptr(libc.Int32FromInt32(BITS) >> libc.Int32FromInt32(3))
  11040 						v19 = libc.X__builtin_bswap64(tls, **(**lbit_t)(__ccgo_up(bp)))
  11041 						goto _44
  11042 					_44:
  11043 						bits = v19
  11044 						bits = bits >> uint64(libc.Int32FromInt32(64)-libc.Int32FromInt32(BITS))
  11045 						(*VP8BitReader)(unsafe.Pointer(v18)).Fvalue = bits | (*VP8BitReader)(unsafe.Pointer(v18)).Fvalue<<libc.Int32FromInt32(BITS)
  11046 						**(**int32)(__ccgo_up(v18 + 12)) += int32(BITS)
  11047 					} else {
  11048 						VP8LoadFinalBytes(tls, v18)
  11049 					}
  11050 				}
  11051 				pos = (*VP8BitReader)(unsafe.Pointer(v17)).Fbits
  11052 				split = range1 * uint32(int32(159)) >> int32(8)
  11053 				value = uint32((*VP8BitReader)(unsafe.Pointer(v17)).Fvalue >> pos)
  11054 				bit = libc.BoolInt32(value > split)
  11055 				if bit != 0 {
  11056 					range1 = range1 - split
  11057 					**(**bit_t)(__ccgo_up(v17)) -= uint64(split+libc.Uint32FromInt32(1)) << pos
  11058 				} else {
  11059 					range1 = split + uint32(1)
  11060 				}
  11061 				v21 = int32(31) ^ libc.X__builtin_clz(tls, range1)
  11062 				goto _46
  11063 			_46:
  11064 				shift = int32(7) ^ v21
  11065 				range1 = range1 << uint32(shift)
  11066 				**(**int32)(__ccgo_up(v17 + 12)) -= shift
  11067 				(*VP8BitReader)(unsafe.Pointer(v17)).Frange1 = range1 - uint32(1)
  11068 				v23 = bit
  11069 				goto _48
  11070 			_48:
  11071 				v = int32(5) + v23
  11072 			} else {
  11073 				v1 = br2
  11074 				range1 = (*VP8BitReader)(unsafe.Pointer(v1)).Frange1
  11075 				if (*VP8BitReader)(unsafe.Pointer(v1)).Fbits < libc.Int32FromInt32(0) {
  11076 					v2 = v1
  11077 					if (*VP8BitReader)(unsafe.Pointer(v2)).Fbuf < (*VP8BitReader)(unsafe.Pointer(v2)).Fbuf_max {
  11078 						libc.Xmemcpy(tls, bp, (*VP8BitReader)(unsafe.Pointer(v2)).Fbuf, uint64(8))
  11079 						**(**uintptr)(__ccgo_up(v2 + 16)) += uintptr(libc.Int32FromInt32(BITS) >> libc.Int32FromInt32(3))
  11080 						v3 = libc.X__builtin_bswap64(tls, **(**lbit_t)(__ccgo_up(bp)))
  11081 						goto _52
  11082 					_52:
  11083 						bits = v3
  11084 						bits = bits >> uint64(libc.Int32FromInt32(64)-libc.Int32FromInt32(BITS))
  11085 						(*VP8BitReader)(unsafe.Pointer(v2)).Fvalue = bits | (*VP8BitReader)(unsafe.Pointer(v2)).Fvalue<<libc.Int32FromInt32(BITS)
  11086 						**(**int32)(__ccgo_up(v2 + 12)) += int32(BITS)
  11087 					} else {
  11088 						VP8LoadFinalBytes(tls, v2)
  11089 					}
  11090 				}
  11091 				pos = (*VP8BitReader)(unsafe.Pointer(v1)).Fbits
  11092 				split = range1 * uint32(int32(165)) >> int32(8)
  11093 				value = uint32((*VP8BitReader)(unsafe.Pointer(v1)).Fvalue >> pos)
  11094 				bit = libc.BoolInt32(value > split)
  11095 				if bit != 0 {
  11096 					range1 = range1 - split
  11097 					**(**bit_t)(__ccgo_up(v1)) -= uint64(split+libc.Uint32FromInt32(1)) << pos
  11098 				} else {
  11099 					range1 = split + uint32(1)
  11100 				}
  11101 				v5 = int32(31) ^ libc.X__builtin_clz(tls, range1)
  11102 				goto _54
  11103 			_54:
  11104 				shift = int32(7) ^ v5
  11105 				range1 = range1 << uint32(shift)
  11106 				**(**int32)(__ccgo_up(v1 + 12)) -= shift
  11107 				(*VP8BitReader)(unsafe.Pointer(v1)).Frange1 = range1 - uint32(1)
  11108 				v7 = bit
  11109 				goto _56
  11110 			_56:
  11111 				v = int32(7) + int32(2)*v7
  11112 				v1 = br2
  11113 				range1 = (*VP8BitReader)(unsafe.Pointer(v1)).Frange1
  11114 				if (*VP8BitReader)(unsafe.Pointer(v1)).Fbits < libc.Int32FromInt32(0) {
  11115 					v2 = v1
  11116 					if (*VP8BitReader)(unsafe.Pointer(v2)).Fbuf < (*VP8BitReader)(unsafe.Pointer(v2)).Fbuf_max {
  11117 						libc.Xmemcpy(tls, bp, (*VP8BitReader)(unsafe.Pointer(v2)).Fbuf, uint64(8))
  11118 						**(**uintptr)(__ccgo_up(v2 + 16)) += uintptr(libc.Int32FromInt32(BITS) >> libc.Int32FromInt32(3))
  11119 						v3 = libc.X__builtin_bswap64(tls, **(**lbit_t)(__ccgo_up(bp)))
  11120 						goto _60
  11121 					_60:
  11122 						bits = v3
  11123 						bits = bits >> uint64(libc.Int32FromInt32(64)-libc.Int32FromInt32(BITS))
  11124 						(*VP8BitReader)(unsafe.Pointer(v2)).Fvalue = bits | (*VP8BitReader)(unsafe.Pointer(v2)).Fvalue<<libc.Int32FromInt32(BITS)
  11125 						**(**int32)(__ccgo_up(v2 + 12)) += int32(BITS)
  11126 					} else {
  11127 						VP8LoadFinalBytes(tls, v2)
  11128 					}
  11129 				}
  11130 				pos = (*VP8BitReader)(unsafe.Pointer(v1)).Fbits
  11131 				split = range1 * uint32(int32(145)) >> int32(8)
  11132 				value = uint32((*VP8BitReader)(unsafe.Pointer(v1)).Fvalue >> pos)
  11133 				bit = libc.BoolInt32(value > split)
  11134 				if bit != 0 {
  11135 					range1 = range1 - split
  11136 					**(**bit_t)(__ccgo_up(v1)) -= uint64(split+libc.Uint32FromInt32(1)) << pos
  11137 				} else {
  11138 					range1 = split + uint32(1)
  11139 				}
  11140 				v5 = int32(31) ^ libc.X__builtin_clz(tls, range1)
  11141 				goto _62
  11142 			_62:
  11143 				shift = int32(7) ^ v5
  11144 				range1 = range1 << uint32(shift)
  11145 				**(**int32)(__ccgo_up(v1 + 12)) -= shift
  11146 				(*VP8BitReader)(unsafe.Pointer(v1)).Frange1 = range1 - uint32(1)
  11147 				v7 = bit
  11148 				goto _64
  11149 			_64:
  11150 				v = v + v7
  11151 			}
  11152 		} else {
  11153 			v1 = br2
  11154 			range1 = (*VP8BitReader)(unsafe.Pointer(v1)).Frange1
  11155 			if (*VP8BitReader)(unsafe.Pointer(v1)).Fbits < libc.Int32FromInt32(0) {
  11156 				v2 = v1
  11157 				if (*VP8BitReader)(unsafe.Pointer(v2)).Fbuf < (*VP8BitReader)(unsafe.Pointer(v2)).Fbuf_max {
  11158 					libc.Xmemcpy(tls, bp, (*VP8BitReader)(unsafe.Pointer(v2)).Fbuf, uint64(8))
  11159 					**(**uintptr)(__ccgo_up(v2 + 16)) += uintptr(libc.Int32FromInt32(BITS) >> libc.Int32FromInt32(3))
  11160 					v3 = libc.X__builtin_bswap64(tls, **(**lbit_t)(__ccgo_up(bp)))
  11161 					goto _68
  11162 				_68:
  11163 					bits = v3
  11164 					bits = bits >> uint64(libc.Int32FromInt32(64)-libc.Int32FromInt32(BITS))
  11165 					(*VP8BitReader)(unsafe.Pointer(v2)).Fvalue = bits | (*VP8BitReader)(unsafe.Pointer(v2)).Fvalue<<libc.Int32FromInt32(BITS)
  11166 					**(**int32)(__ccgo_up(v2 + 12)) += int32(BITS)
  11167 				} else {
  11168 					VP8LoadFinalBytes(tls, v2)
  11169 				}
  11170 			}
  11171 			pos = (*VP8BitReader)(unsafe.Pointer(v1)).Fbits
  11172 			split = range1 * uint32(int32(**(**uint8_t)(__ccgo_up(p + 8)))) >> int32(8)
  11173 			value = uint32((*VP8BitReader)(unsafe.Pointer(v1)).Fvalue >> pos)
  11174 			bit = libc.BoolInt32(value > split)
  11175 			if bit != 0 {
  11176 				range1 = range1 - split
  11177 				**(**bit_t)(__ccgo_up(v1)) -= uint64(split+libc.Uint32FromInt32(1)) << pos
  11178 			} else {
  11179 				range1 = split + uint32(1)
  11180 			}
  11181 			v5 = int32(31) ^ libc.X__builtin_clz(tls, range1)
  11182 			goto _70
  11183 		_70:
  11184 			shift = int32(7) ^ v5
  11185 			range1 = range1 << uint32(shift)
  11186 			**(**int32)(__ccgo_up(v1 + 12)) -= shift
  11187 			(*VP8BitReader)(unsafe.Pointer(v1)).Frange1 = range1 - uint32(1)
  11188 			v7 = bit
  11189 			goto _72
  11190 		_72:
  11191 			bit1 = v7
  11192 			v9 = br2
  11193 			range1 = (*VP8BitReader)(unsafe.Pointer(v9)).Frange1
  11194 			if (*VP8BitReader)(unsafe.Pointer(v9)).Fbits < libc.Int32FromInt32(0) {
  11195 				v10 = v9
  11196 				if (*VP8BitReader)(unsafe.Pointer(v10)).Fbuf < (*VP8BitReader)(unsafe.Pointer(v10)).Fbuf_max {
  11197 					libc.Xmemcpy(tls, bp, (*VP8BitReader)(unsafe.Pointer(v10)).Fbuf, uint64(8))
  11198 					**(**uintptr)(__ccgo_up(v10 + 16)) += uintptr(libc.Int32FromInt32(BITS) >> libc.Int32FromInt32(3))
  11199 					v11 = libc.X__builtin_bswap64(tls, **(**lbit_t)(__ccgo_up(bp)))
  11200 					goto _76
  11201 				_76:
  11202 					bits = v11
  11203 					bits = bits >> uint64(libc.Int32FromInt32(64)-libc.Int32FromInt32(BITS))
  11204 					(*VP8BitReader)(unsafe.Pointer(v10)).Fvalue = bits | (*VP8BitReader)(unsafe.Pointer(v10)).Fvalue<<libc.Int32FromInt32(BITS)
  11205 					**(**int32)(__ccgo_up(v10 + 12)) += int32(BITS)
  11206 				} else {
  11207 					VP8LoadFinalBytes(tls, v10)
  11208 				}
  11209 			}
  11210 			pos = (*VP8BitReader)(unsafe.Pointer(v9)).Fbits
  11211 			split = range1 * uint32(int32(**(**uint8_t)(__ccgo_up(p + uintptr(int32(9)+bit1))))) >> int32(8)
  11212 			value = uint32((*VP8BitReader)(unsafe.Pointer(v9)).Fvalue >> pos)
  11213 			bit = libc.BoolInt32(value > split)
  11214 			if bit != 0 {
  11215 				range1 = range1 - split
  11216 				**(**bit_t)(__ccgo_up(v9)) -= uint64(split+libc.Uint32FromInt32(1)) << pos
  11217 			} else {
  11218 				range1 = split + uint32(1)
  11219 			}
  11220 			v13 = int32(31) ^ libc.X__builtin_clz(tls, range1)
  11221 			goto _78
  11222 		_78:
  11223 			shift = int32(7) ^ v13
  11224 			range1 = range1 << uint32(shift)
  11225 			**(**int32)(__ccgo_up(v9 + 12)) -= shift
  11226 			(*VP8BitReader)(unsafe.Pointer(v9)).Frange1 = range1 - uint32(1)
  11227 			v15 = bit
  11228 			goto _80
  11229 		_80:
  11230 			bit0 = v15
  11231 			cat = int32(2)*bit1 + bit0
  11232 			v = 0
  11233 			tab = kCat3456[cat]
  11234 			for {
  11235 				if !(**(**uint8_t)(__ccgo_up(tab)) != 0) {
  11236 					break
  11237 				}
  11238 				v1 = br2
  11239 				range1 = (*VP8BitReader)(unsafe.Pointer(v1)).Frange1
  11240 				if (*VP8BitReader)(unsafe.Pointer(v1)).Fbits < libc.Int32FromInt32(0) {
  11241 					v2 = v1
  11242 					if (*VP8BitReader)(unsafe.Pointer(v2)).Fbuf < (*VP8BitReader)(unsafe.Pointer(v2)).Fbuf_max {
  11243 						libc.Xmemcpy(tls, bp, (*VP8BitReader)(unsafe.Pointer(v2)).Fbuf, uint64(8))
  11244 						**(**uintptr)(__ccgo_up(v2 + 16)) += uintptr(libc.Int32FromInt32(BITS) >> libc.Int32FromInt32(3))
  11245 						v3 = libc.X__builtin_bswap64(tls, **(**lbit_t)(__ccgo_up(bp)))
  11246 						goto _85
  11247 					_85:
  11248 						bits = v3
  11249 						bits = bits >> uint64(libc.Int32FromInt32(64)-libc.Int32FromInt32(BITS))
  11250 						(*VP8BitReader)(unsafe.Pointer(v2)).Fvalue = bits | (*VP8BitReader)(unsafe.Pointer(v2)).Fvalue<<libc.Int32FromInt32(BITS)
  11251 						**(**int32)(__ccgo_up(v2 + 12)) += int32(BITS)
  11252 					} else {
  11253 						VP8LoadFinalBytes(tls, v2)
  11254 					}
  11255 				}
  11256 				pos = (*VP8BitReader)(unsafe.Pointer(v1)).Fbits
  11257 				split = range1 * uint32(int32(**(**uint8_t)(__ccgo_up(tab)))) >> int32(8)
  11258 				value = uint32((*VP8BitReader)(unsafe.Pointer(v1)).Fvalue >> pos)
  11259 				bit = libc.BoolInt32(value > split)
  11260 				if bit != 0 {
  11261 					range1 = range1 - split
  11262 					**(**bit_t)(__ccgo_up(v1)) -= uint64(split+libc.Uint32FromInt32(1)) << pos
  11263 				} else {
  11264 					range1 = split + uint32(1)
  11265 				}
  11266 				v5 = int32(31) ^ libc.X__builtin_clz(tls, range1)
  11267 				goto _87
  11268 			_87:
  11269 				shift = int32(7) ^ v5
  11270 				range1 = range1 << uint32(shift)
  11271 				**(**int32)(__ccgo_up(v1 + 12)) -= shift
  11272 				(*VP8BitReader)(unsafe.Pointer(v1)).Frange1 = range1 - uint32(1)
  11273 				v7 = bit
  11274 				goto _89
  11275 			_89:
  11276 				v = v + (v + v7)
  11277 				goto _81
  11278 			_81:
  11279 				;
  11280 				tab = tab + 1
  11281 			}
  11282 			v = v + (int32(3) + int32(8)<<cat)
  11283 		}
  11284 	}
  11285 	return v
  11286 }
  11287 
  11288 // C documentation
  11289 //
  11290 //	// Returns the position of the last non-zero coeff plus one
  11291 func GetCoeffsFast(tls *libc.TLS, br3 uintptr, prob1 uintptr, ctx int32, dq uintptr, n1 int32, out uintptr) (r int32) {
  11292 	bp := tls.Alloc(16)
  11293 	defer tls.Free(16)
  11294 	var bit, pos, pos1, shift, v1, v14, v6, v8 int32
  11295 	var bits bit_t
  11296 	var mask int32_t
  11297 	var p, p_ctx, v2, v3 uintptr
  11298 	var range1, split, split1, value, value1 range_t
  11299 	var v4 uint64_t
  11300 	var _ /* in_bits at bp+0 */ lbit_t
  11301 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = bit, bits, mask, p, p_ctx, pos, pos1, range1, shift, split, split1, v1, value, value1, v14, v2, v3, v4, v6, v8
  11302 	p = **(**uintptr)(__ccgo_up(prob1 + uintptr(n1)*8)) + uintptr(ctx)*11
  11303 	for {
  11304 		if !(n1 < int32(16)) {
  11305 			break
  11306 		}
  11307 		v2 = br3
  11308 		range1 = (*VP8BitReader)(unsafe.Pointer(v2)).Frange1
  11309 		if (*VP8BitReader)(unsafe.Pointer(v2)).Fbits < libc.Int32FromInt32(0) {
  11310 			v3 = v2
  11311 			if (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf < (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf_max {
  11312 				libc.Xmemcpy(tls, bp, (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf, uint64(8))
  11313 				**(**uintptr)(__ccgo_up(v3 + 16)) += uintptr(libc.Int32FromInt32(BITS) >> libc.Int32FromInt32(3))
  11314 				v4 = libc.X__builtin_bswap64(tls, **(**lbit_t)(__ccgo_up(bp)))
  11315 				goto _5
  11316 			_5:
  11317 				bits = v4
  11318 				bits = bits >> uint64(libc.Int32FromInt32(64)-libc.Int32FromInt32(BITS))
  11319 				(*VP8BitReader)(unsafe.Pointer(v3)).Fvalue = bits | (*VP8BitReader)(unsafe.Pointer(v3)).Fvalue<<libc.Int32FromInt32(BITS)
  11320 				**(**int32)(__ccgo_up(v3 + 12)) += int32(BITS)
  11321 			} else {
  11322 				VP8LoadFinalBytes(tls, v3)
  11323 			}
  11324 		}
  11325 		pos = (*VP8BitReader)(unsafe.Pointer(v2)).Fbits
  11326 		split = range1 * uint32(int32(**(**uint8_t)(__ccgo_up(p)))) >> int32(8)
  11327 		value = uint32((*VP8BitReader)(unsafe.Pointer(v2)).Fvalue >> pos)
  11328 		bit = libc.BoolInt32(value > split)
  11329 		if bit != 0 {
  11330 			range1 = range1 - split
  11331 			**(**bit_t)(__ccgo_up(v2)) -= uint64(split+libc.Uint32FromInt32(1)) << pos
  11332 		} else {
  11333 			range1 = split + uint32(1)
  11334 		}
  11335 		v6 = int32(31) ^ libc.X__builtin_clz(tls, range1)
  11336 		goto _7
  11337 	_7:
  11338 		shift = int32(7) ^ v6
  11339 		range1 = range1 << uint32(shift)
  11340 		**(**int32)(__ccgo_up(v2 + 12)) -= shift
  11341 		(*VP8BitReader)(unsafe.Pointer(v2)).Frange1 = range1 - uint32(1)
  11342 		v8 = bit
  11343 		goto _9
  11344 	_9:
  11345 		if !(v8 != 0) {
  11346 			return n1 // previous coeff was last non-zero coeff
  11347 		}
  11348 		for {
  11349 			v2 = br3
  11350 			range1 = (*VP8BitReader)(unsafe.Pointer(v2)).Frange1
  11351 			if (*VP8BitReader)(unsafe.Pointer(v2)).Fbits < libc.Int32FromInt32(0) {
  11352 				v3 = v2
  11353 				if (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf < (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf_max {
  11354 					libc.Xmemcpy(tls, bp, (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf, uint64(8))
  11355 					**(**uintptr)(__ccgo_up(v3 + 16)) += uintptr(libc.Int32FromInt32(BITS) >> libc.Int32FromInt32(3))
  11356 					v4 = libc.X__builtin_bswap64(tls, **(**lbit_t)(__ccgo_up(bp)))
  11357 					goto _13
  11358 				_13:
  11359 					bits = v4
  11360 					bits = bits >> uint64(libc.Int32FromInt32(64)-libc.Int32FromInt32(BITS))
  11361 					(*VP8BitReader)(unsafe.Pointer(v3)).Fvalue = bits | (*VP8BitReader)(unsafe.Pointer(v3)).Fvalue<<libc.Int32FromInt32(BITS)
  11362 					**(**int32)(__ccgo_up(v3 + 12)) += int32(BITS)
  11363 				} else {
  11364 					VP8LoadFinalBytes(tls, v3)
  11365 				}
  11366 			}
  11367 			pos = (*VP8BitReader)(unsafe.Pointer(v2)).Fbits
  11368 			split = range1 * uint32(int32(**(**uint8_t)(__ccgo_up(p + 1)))) >> int32(8)
  11369 			value = uint32((*VP8BitReader)(unsafe.Pointer(v2)).Fvalue >> pos)
  11370 			bit = libc.BoolInt32(value > split)
  11371 			if bit != 0 {
  11372 				range1 = range1 - split
  11373 				**(**bit_t)(__ccgo_up(v2)) -= uint64(split+libc.Uint32FromInt32(1)) << pos
  11374 			} else {
  11375 				range1 = split + uint32(1)
  11376 			}
  11377 			v6 = int32(31) ^ libc.X__builtin_clz(tls, range1)
  11378 			goto _15
  11379 		_15:
  11380 			shift = int32(7) ^ v6
  11381 			range1 = range1 << uint32(shift)
  11382 			**(**int32)(__ccgo_up(v2 + 12)) -= shift
  11383 			(*VP8BitReader)(unsafe.Pointer(v2)).Frange1 = range1 - uint32(1)
  11384 			v8 = bit
  11385 			goto _17
  11386 		_17:
  11387 			if !!(v8 != 0) {
  11388 				break
  11389 			} // sequence of zero coeffs
  11390 			n1 = n1 + 1
  11391 			v14 = n1
  11392 			p = **(**uintptr)(__ccgo_up(prob1 + uintptr(v14)*8))
  11393 			if n1 == int32(16) {
  11394 				return int32(16)
  11395 			}
  11396 		}
  11397 		// non zero coeff
  11398 		p_ctx = **(**uintptr)(__ccgo_up(prob1 + uintptr(n1+int32(1))*8))
  11399 		v2 = br3
  11400 		range1 = (*VP8BitReader)(unsafe.Pointer(v2)).Frange1
  11401 		if (*VP8BitReader)(unsafe.Pointer(v2)).Fbits < libc.Int32FromInt32(0) {
  11402 			v3 = v2
  11403 			if (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf < (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf_max {
  11404 				libc.Xmemcpy(tls, bp, (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf, uint64(8))
  11405 				**(**uintptr)(__ccgo_up(v3 + 16)) += uintptr(libc.Int32FromInt32(BITS) >> libc.Int32FromInt32(3))
  11406 				v4 = libc.X__builtin_bswap64(tls, **(**lbit_t)(__ccgo_up(bp)))
  11407 				goto _22
  11408 			_22:
  11409 				bits = v4
  11410 				bits = bits >> uint64(libc.Int32FromInt32(64)-libc.Int32FromInt32(BITS))
  11411 				(*VP8BitReader)(unsafe.Pointer(v3)).Fvalue = bits | (*VP8BitReader)(unsafe.Pointer(v3)).Fvalue<<libc.Int32FromInt32(BITS)
  11412 				**(**int32)(__ccgo_up(v3 + 12)) += int32(BITS)
  11413 			} else {
  11414 				VP8LoadFinalBytes(tls, v3)
  11415 			}
  11416 		}
  11417 		pos = (*VP8BitReader)(unsafe.Pointer(v2)).Fbits
  11418 		split = range1 * uint32(int32(**(**uint8_t)(__ccgo_up(p + 2)))) >> int32(8)
  11419 		value = uint32((*VP8BitReader)(unsafe.Pointer(v2)).Fvalue >> pos)
  11420 		bit = libc.BoolInt32(value > split)
  11421 		if bit != 0 {
  11422 			range1 = range1 - split
  11423 			**(**bit_t)(__ccgo_up(v2)) -= uint64(split+libc.Uint32FromInt32(1)) << pos
  11424 		} else {
  11425 			range1 = split + uint32(1)
  11426 		}
  11427 		v6 = int32(31) ^ libc.X__builtin_clz(tls, range1)
  11428 		goto _24
  11429 	_24:
  11430 		shift = int32(7) ^ v6
  11431 		range1 = range1 << uint32(shift)
  11432 		**(**int32)(__ccgo_up(v2 + 12)) -= shift
  11433 		(*VP8BitReader)(unsafe.Pointer(v2)).Frange1 = range1 - uint32(1)
  11434 		v8 = bit
  11435 		goto _26
  11436 	_26:
  11437 		if !(v8 != 0) {
  11438 			v1 = int32(1)
  11439 			p = p_ctx + 1*11
  11440 		} else {
  11441 			v1 = GetLargeValue(tls, br3, p)
  11442 			p = p_ctx + 2*11
  11443 		}
  11444 		v2 = br3
  11445 		if (*VP8BitReader)(unsafe.Pointer(v2)).Fbits < libc.Int32FromInt32(0) {
  11446 			v3 = v2
  11447 			if (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf < (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf_max {
  11448 				libc.Xmemcpy(tls, bp, (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf, uint64(8))
  11449 				**(**uintptr)(__ccgo_up(v3 + 16)) += uintptr(libc.Int32FromInt32(BITS) >> libc.Int32FromInt32(3))
  11450 				v4 = libc.X__builtin_bswap64(tls, **(**lbit_t)(__ccgo_up(bp)))
  11451 				goto _30
  11452 			_30:
  11453 				bits = v4
  11454 				bits = bits >> uint64(libc.Int32FromInt32(64)-libc.Int32FromInt32(BITS))
  11455 				(*VP8BitReader)(unsafe.Pointer(v3)).Fvalue = bits | (*VP8BitReader)(unsafe.Pointer(v3)).Fvalue<<libc.Int32FromInt32(BITS)
  11456 				**(**int32)(__ccgo_up(v3 + 12)) += int32(BITS)
  11457 			} else {
  11458 				VP8LoadFinalBytes(tls, v3)
  11459 			}
  11460 		}
  11461 		pos1 = (*VP8BitReader)(unsafe.Pointer(v2)).Fbits
  11462 		split1 = (*VP8BitReader)(unsafe.Pointer(v2)).Frange1 >> int32(1)
  11463 		value1 = uint32((*VP8BitReader)(unsafe.Pointer(v2)).Fvalue >> pos1)
  11464 		mask = int32(split1-value1) >> int32(31)
  11465 		**(**int32)(__ccgo_up(v2 + 12)) -= int32(1)
  11466 		**(**range_t)(__ccgo_up(v2 + 8)) += uint32(mask)
  11467 		**(**range_t)(__ccgo_up(v2 + 8)) |= uint32(1)
  11468 		**(**bit_t)(__ccgo_up(v2)) -= uint64((split1+libc.Uint32FromInt32(1))&uint32(mask)) << pos1
  11469 		v6 = v1 ^ mask - mask
  11470 		goto _32
  11471 	_32:
  11472 		**(**int16_t)(__ccgo_up(out + uintptr(kZigzag[n1])*2)) = int16(v6 * **(**int32)(__ccgo_up(dq + libc.BoolUintptr(n1 > 0)*4)))
  11473 		goto _1
  11474 	_1:
  11475 		;
  11476 		n1 = n1 + 1
  11477 	}
  11478 	return int32(16)
  11479 }
  11480 
  11481 // C documentation
  11482 //
  11483 //	// This version of GetCoeffs() uses VP8GetBitAlt() which is an alternate version
  11484 //	// of VP8GetBitAlt() targeting specific platforms.
  11485 func GetCoeffsAlt(tls *libc.TLS, br3 uintptr, prob1 uintptr, ctx int32, dq uintptr, n int32, out uintptr) (r int32) {
  11486 	bp := tls.Alloc(16)
  11487 	defer tls.Free(16)
  11488 	var bit, pos, pos1, shift, v1, v12, v6 int32
  11489 	var bits bit_t
  11490 	var mask int32_t
  11491 	var p, p_ctx, v2, v3 uintptr
  11492 	var range1, split, split1, value, value1 range_t
  11493 	var v4 uint64_t
  11494 	var _ /* in_bits at bp+0 */ lbit_t
  11495 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = bit, bits, mask, p, p_ctx, pos, pos1, range1, shift, split, split1, v1, value, value1, v12, v2, v3, v4, v6
  11496 	p = **(**uintptr)(__ccgo_up(prob1 + uintptr(n)*8)) + uintptr(ctx)*11
  11497 	for {
  11498 		if !(n < int32(16)) {
  11499 			break
  11500 		}
  11501 		v2 = br3
  11502 		range1 = (*VP8BitReader)(unsafe.Pointer(v2)).Frange1
  11503 		if (*VP8BitReader)(unsafe.Pointer(v2)).Fbits < libc.Int32FromInt32(0) {
  11504 			v3 = v2
  11505 			if (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf < (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf_max {
  11506 				libc.Xmemcpy(tls, bp, (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf, uint64(8))
  11507 				**(**uintptr)(__ccgo_up(v3 + 16)) += uintptr(libc.Int32FromInt32(BITS) >> libc.Int32FromInt32(3))
  11508 				v4 = libc.X__builtin_bswap64(tls, **(**lbit_t)(__ccgo_up(bp)))
  11509 				goto _5
  11510 			_5:
  11511 				bits = v4
  11512 				bits = bits >> uint64(libc.Int32FromInt32(64)-libc.Int32FromInt32(BITS))
  11513 				(*VP8BitReader)(unsafe.Pointer(v3)).Fvalue = bits | (*VP8BitReader)(unsafe.Pointer(v3)).Fvalue<<libc.Int32FromInt32(BITS)
  11514 				**(**int32)(__ccgo_up(v3 + 12)) += int32(BITS)
  11515 			} else {
  11516 				VP8LoadFinalBytes(tls, v3)
  11517 			}
  11518 		}
  11519 		pos1 = (*VP8BitReader)(unsafe.Pointer(v2)).Fbits
  11520 		split1 = range1 * uint32(int32(**(**uint8_t)(__ccgo_up(p)))) >> int32(8)
  11521 		value1 = uint32((*VP8BitReader)(unsafe.Pointer(v2)).Fvalue >> pos1)
  11522 		if value1 > split1 {
  11523 			range1 = range1 - (split1 + uint32(1))
  11524 			**(**bit_t)(__ccgo_up(v2)) -= uint64(split1+libc.Uint32FromInt32(1)) << pos1
  11525 			bit = int32(1)
  11526 		} else {
  11527 			range1 = split1
  11528 			bit = 0
  11529 		}
  11530 		if range1 <= libc.Uint32FromInt32(0x7e) {
  11531 			shift = int32(kVP8Log2Range[range1])
  11532 			range1 = uint32(kVP8NewRange[range1])
  11533 			**(**int32)(__ccgo_up(v2 + 12)) -= shift
  11534 		}
  11535 		(*VP8BitReader)(unsafe.Pointer(v2)).Frange1 = range1
  11536 		v6 = bit
  11537 		goto _7
  11538 	_7:
  11539 		if !(v6 != 0) {
  11540 			return n // previous coeff was last non-zero coeff
  11541 		}
  11542 		for {
  11543 			v2 = br3
  11544 			range1 = (*VP8BitReader)(unsafe.Pointer(v2)).Frange1
  11545 			if (*VP8BitReader)(unsafe.Pointer(v2)).Fbits < libc.Int32FromInt32(0) {
  11546 				v3 = v2
  11547 				if (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf < (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf_max {
  11548 					libc.Xmemcpy(tls, bp, (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf, uint64(8))
  11549 					**(**uintptr)(__ccgo_up(v3 + 16)) += uintptr(libc.Int32FromInt32(BITS) >> libc.Int32FromInt32(3))
  11550 					v4 = libc.X__builtin_bswap64(tls, **(**lbit_t)(__ccgo_up(bp)))
  11551 					goto _11
  11552 				_11:
  11553 					bits = v4
  11554 					bits = bits >> uint64(libc.Int32FromInt32(64)-libc.Int32FromInt32(BITS))
  11555 					(*VP8BitReader)(unsafe.Pointer(v3)).Fvalue = bits | (*VP8BitReader)(unsafe.Pointer(v3)).Fvalue<<libc.Int32FromInt32(BITS)
  11556 					**(**int32)(__ccgo_up(v3 + 12)) += int32(BITS)
  11557 				} else {
  11558 					VP8LoadFinalBytes(tls, v3)
  11559 				}
  11560 			}
  11561 			pos1 = (*VP8BitReader)(unsafe.Pointer(v2)).Fbits
  11562 			split1 = range1 * uint32(int32(**(**uint8_t)(__ccgo_up(p + 1)))) >> int32(8)
  11563 			value1 = uint32((*VP8BitReader)(unsafe.Pointer(v2)).Fvalue >> pos1)
  11564 			if value1 > split1 {
  11565 				range1 = range1 - (split1 + uint32(1))
  11566 				**(**bit_t)(__ccgo_up(v2)) -= uint64(split1+libc.Uint32FromInt32(1)) << pos1
  11567 				bit = int32(1)
  11568 			} else {
  11569 				range1 = split1
  11570 				bit = 0
  11571 			}
  11572 			if range1 <= libc.Uint32FromInt32(0x7e) {
  11573 				shift = int32(kVP8Log2Range[range1])
  11574 				range1 = uint32(kVP8NewRange[range1])
  11575 				**(**int32)(__ccgo_up(v2 + 12)) -= shift
  11576 			}
  11577 			(*VP8BitReader)(unsafe.Pointer(v2)).Frange1 = range1
  11578 			v6 = bit
  11579 			goto _13
  11580 		_13:
  11581 			if !!(v6 != 0) {
  11582 				break
  11583 			} // sequence of zero coeffs
  11584 			n = n + 1
  11585 			v12 = n
  11586 			p = **(**uintptr)(__ccgo_up(prob1 + uintptr(v12)*8))
  11587 			if n == int32(16) {
  11588 				return int32(16)
  11589 			}
  11590 		}
  11591 		// non zero coeff
  11592 		p_ctx = **(**uintptr)(__ccgo_up(prob1 + uintptr(n+int32(1))*8))
  11593 		v2 = br3
  11594 		range1 = (*VP8BitReader)(unsafe.Pointer(v2)).Frange1
  11595 		if (*VP8BitReader)(unsafe.Pointer(v2)).Fbits < libc.Int32FromInt32(0) {
  11596 			v3 = v2
  11597 			if (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf < (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf_max {
  11598 				libc.Xmemcpy(tls, bp, (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf, uint64(8))
  11599 				**(**uintptr)(__ccgo_up(v3 + 16)) += uintptr(libc.Int32FromInt32(BITS) >> libc.Int32FromInt32(3))
  11600 				v4 = libc.X__builtin_bswap64(tls, **(**lbit_t)(__ccgo_up(bp)))
  11601 				goto _18
  11602 			_18:
  11603 				bits = v4
  11604 				bits = bits >> uint64(libc.Int32FromInt32(64)-libc.Int32FromInt32(BITS))
  11605 				(*VP8BitReader)(unsafe.Pointer(v3)).Fvalue = bits | (*VP8BitReader)(unsafe.Pointer(v3)).Fvalue<<libc.Int32FromInt32(BITS)
  11606 				**(**int32)(__ccgo_up(v3 + 12)) += int32(BITS)
  11607 			} else {
  11608 				VP8LoadFinalBytes(tls, v3)
  11609 			}
  11610 		}
  11611 		pos1 = (*VP8BitReader)(unsafe.Pointer(v2)).Fbits
  11612 		split1 = range1 * uint32(int32(**(**uint8_t)(__ccgo_up(p + 2)))) >> int32(8)
  11613 		value1 = uint32((*VP8BitReader)(unsafe.Pointer(v2)).Fvalue >> pos1)
  11614 		if value1 > split1 {
  11615 			range1 = range1 - (split1 + uint32(1))
  11616 			**(**bit_t)(__ccgo_up(v2)) -= uint64(split1+libc.Uint32FromInt32(1)) << pos1
  11617 			bit = int32(1)
  11618 		} else {
  11619 			range1 = split1
  11620 			bit = 0
  11621 		}
  11622 		if range1 <= libc.Uint32FromInt32(0x7e) {
  11623 			shift = int32(kVP8Log2Range[range1])
  11624 			range1 = uint32(kVP8NewRange[range1])
  11625 			**(**int32)(__ccgo_up(v2 + 12)) -= shift
  11626 		}
  11627 		(*VP8BitReader)(unsafe.Pointer(v2)).Frange1 = range1
  11628 		v6 = bit
  11629 		goto _20
  11630 	_20:
  11631 		if !(v6 != 0) {
  11632 			v1 = int32(1)
  11633 			p = p_ctx + 1*11
  11634 		} else {
  11635 			v1 = GetLargeValue(tls, br3, p)
  11636 			p = p_ctx + 2*11
  11637 		}
  11638 		v2 = br3
  11639 		if (*VP8BitReader)(unsafe.Pointer(v2)).Fbits < libc.Int32FromInt32(0) {
  11640 			v3 = v2
  11641 			if (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf < (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf_max {
  11642 				libc.Xmemcpy(tls, bp, (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf, uint64(8))
  11643 				**(**uintptr)(__ccgo_up(v3 + 16)) += uintptr(libc.Int32FromInt32(BITS) >> libc.Int32FromInt32(3))
  11644 				v4 = libc.X__builtin_bswap64(tls, **(**lbit_t)(__ccgo_up(bp)))
  11645 				goto _24
  11646 			_24:
  11647 				bits = v4
  11648 				bits = bits >> uint64(libc.Int32FromInt32(64)-libc.Int32FromInt32(BITS))
  11649 				(*VP8BitReader)(unsafe.Pointer(v3)).Fvalue = bits | (*VP8BitReader)(unsafe.Pointer(v3)).Fvalue<<libc.Int32FromInt32(BITS)
  11650 				**(**int32)(__ccgo_up(v3 + 12)) += int32(BITS)
  11651 			} else {
  11652 				VP8LoadFinalBytes(tls, v3)
  11653 			}
  11654 		}
  11655 		pos = (*VP8BitReader)(unsafe.Pointer(v2)).Fbits
  11656 		split = (*VP8BitReader)(unsafe.Pointer(v2)).Frange1 >> int32(1)
  11657 		value = uint32((*VP8BitReader)(unsafe.Pointer(v2)).Fvalue >> pos)
  11658 		mask = int32(split-value) >> int32(31)
  11659 		**(**int32)(__ccgo_up(v2 + 12)) -= int32(1)
  11660 		**(**range_t)(__ccgo_up(v2 + 8)) += uint32(mask)
  11661 		**(**range_t)(__ccgo_up(v2 + 8)) |= uint32(1)
  11662 		**(**bit_t)(__ccgo_up(v2)) -= uint64((split+libc.Uint32FromInt32(1))&uint32(mask)) << pos
  11663 		v6 = v1 ^ mask - mask
  11664 		goto _26
  11665 	_26:
  11666 		**(**int16_t)(__ccgo_up(out + uintptr(kZigzag[n])*2)) = int16(v6 * **(**int32)(__ccgo_up(dq + libc.BoolUintptr(n > 0)*4)))
  11667 		goto _1
  11668 	_1:
  11669 		;
  11670 		n = n + 1
  11671 	}
  11672 	return int32(16)
  11673 }
  11674 
  11675 func InitGetCoeffs(tls *libc.TLS) {
  11676 	if libc.AtomicLoadPUintptr(uintptr(unsafe.Pointer(&InitGetCoeffs_body_last_cpuinfo_used))) == VP8GetCPUInfo {
  11677 		goto _1
  11678 	}
  11679 	InitGetCoeffs_body(tls)
  11680 	libc.AtomicStorePUintptr(uintptr(unsafe.Pointer(&InitGetCoeffs_body_last_cpuinfo_used)), VP8GetCPUInfo)
  11681 	goto _2
  11682 _2:
  11683 	;
  11684 	goto _1
  11685 _1: /**/ //
  11686 }
  11687 
  11688 var InitGetCoeffs_body_last_cpuinfo_used = uintptr(0)
  11689 
  11690 func init() {
  11691 	p := unsafe.Pointer(&InitGetCoeffs_body_last_cpuinfo_used)
  11692 	*(*uintptr)(unsafe.Add(p, 0)) = uintptr(unsafe.Pointer(&InitGetCoeffs_body_last_cpuinfo_used))
  11693 }
  11694 
  11695 func InitGetCoeffs_body(tls *libc.TLS) {
  11696 	if VP8GetCPUInfo != libc.UintptrFromInt32(0) && (*(*func(*libc.TLS, CPUFeature) int32)(unsafe.Pointer(&struct{ uintptr }{VP8GetCPUInfo})))(tls, int32(kSlowSSSE3)) != 0 {
  11697 		GetCoeffs = __ccgo_fp(GetCoeffsAlt)
  11698 	} else {
  11699 		GetCoeffs = __ccgo_fp(GetCoeffsFast)
  11700 	}
  11701 }
  11702 
  11703 func NzCodeBits(tls *libc.TLS, nz_coeffs uint32_t, nz int32, dc_nz int32) (r uint32_t) {
  11704 	var v1, v2 int32
  11705 	_, _ = v1, v2
  11706 	nz_coeffs = nz_coeffs << uint32(2)
  11707 	if nz > int32(3) {
  11708 		v1 = int32(3)
  11709 	} else {
  11710 		if nz > int32(1) {
  11711 			v2 = int32(2)
  11712 		} else {
  11713 			v2 = dc_nz
  11714 		}
  11715 		v1 = v2
  11716 	}
  11717 	nz_coeffs = nz_coeffs | uint32(v1)
  11718 	return nz_coeffs
  11719 }
  11720 
  11721 func ParseResiduals(tls *libc.TLS, dec uintptr, mb uintptr, token_br uintptr) (r int32) {
  11722 	bp := tls.Alloc(32)
  11723 	defer tls.Free(32)
  11724 	var ac_proba, bands, block, dst, left_mb, q uintptr
  11725 	var ch, ctx, ctx1, ctx2, dc0, first, i, l, l1, nz, nz1, nz2, x, y, v8 int32
  11726 	var lnz, tnz, v1 uint8_t
  11727 	var non_zero_uv, non_zero_y, nz_coeffs, nz_coeffs1, out_l_nz, out_t_nz uint32_t
  11728 	var _ /* dc at bp+0 */ [16]int16_t
  11729 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  11730 	bands = dec + 1192 + 1064
  11731 	block = (*VP8Decoder)(unsafe.Pointer(dec)).Fmb_data + uintptr((*VP8Decoder)(unsafe.Pointer(dec)).Fmb_x)*800
  11732 	q = dec + 1060 + uintptr((*VP8MBData)(unsafe.Pointer(block)).Fsegment)*32
  11733 	dst = block
  11734 	left_mb = (*VP8Decoder)(unsafe.Pointer(dec)).Fmb_info - uintptr(1)*2
  11735 	non_zero_y = uint32(0)
  11736 	non_zero_uv = uint32(0)
  11737 	libc.Xmemset(tls, dst, 0, libc.Uint64FromInt32(384)*libc.Uint64FromInt64(2))
  11738 	if !((*VP8MBData)(unsafe.Pointer(block)).Fis_i4x4 != 0) { // parse DC
  11739 		**(**[16]int16_t)(__ccgo_up(bp)) = [16]int16_t{}
  11740 		ctx = int32((*VP8MB)(unsafe.Pointer(mb)).Fnz_dc) + int32((*VP8MB)(unsafe.Pointer(left_mb)).Fnz_dc)
  11741 		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)
  11742 		v1 = libc.BoolUint8(nz > libc.Int32FromInt32(0))
  11743 		(*VP8MB)(unsafe.Pointer(left_mb)).Fnz_dc = v1
  11744 		(*VP8MB)(unsafe.Pointer(mb)).Fnz_dc = v1
  11745 		if nz > int32(1) { // more than just the DC -> perform the full transform
  11746 			(*(*func(*libc.TLS, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8TransformWHT})))(tls, bp, dst)
  11747 		} else {
  11748 			dc0 = (int32((**(**[16]int16_t)(__ccgo_up(bp)))[0]) + int32(3)) >> int32(3)
  11749 			i = 0
  11750 			for {
  11751 				if !(i < libc.Int32FromInt32(16)*libc.Int32FromInt32(16)) {
  11752 					break
  11753 				}
  11754 				**(**int16_t)(__ccgo_up(dst + uintptr(i)*2)) = int16(dc0)
  11755 				goto _2
  11756 			_2:
  11757 				;
  11758 				i = i + int32(16)
  11759 			}
  11760 		}
  11761 		first = int32(1)
  11762 		ac_proba = bands
  11763 	} else {
  11764 		first = 0
  11765 		ac_proba = bands + 3*136
  11766 	}
  11767 	tnz = uint8(int32((*VP8MB)(unsafe.Pointer(mb)).Fnz) & int32(0x0f))
  11768 	lnz = uint8(int32((*VP8MB)(unsafe.Pointer(left_mb)).Fnz) & int32(0x0f))
  11769 	y = 0
  11770 	for {
  11771 		if !(y < int32(4)) {
  11772 			break
  11773 		}
  11774 		l = int32(lnz) & int32(1)
  11775 		nz_coeffs = uint32(0)
  11776 		x = 0
  11777 		for {
  11778 			if !(x < int32(4)) {
  11779 				break
  11780 			}
  11781 			ctx1 = l + int32(tnz)&int32(1)
  11782 			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)
  11783 			l = libc.BoolInt32(nz1 > first)
  11784 			tnz = uint8(int32(tnz)>>int32(1) | l<<int32(7))
  11785 			nz_coeffs = NzCodeBits(tls, nz_coeffs, nz1, libc.BoolInt32(int32(**(**int16_t)(__ccgo_up(dst))) != 0))
  11786 			dst = dst + uintptr(16)*2
  11787 			goto _4
  11788 		_4:
  11789 			;
  11790 			x = x + 1
  11791 		}
  11792 		tnz = uint8(int32(tnz) >> libc.Int32FromInt32(4))
  11793 		lnz = uint8(int32(lnz)>>int32(1) | l<<int32(7))
  11794 		non_zero_y = non_zero_y<<libc.Int32FromInt32(8) | nz_coeffs
  11795 		goto _3
  11796 	_3:
  11797 		;
  11798 		y = y + 1
  11799 	}
  11800 	out_t_nz = uint32(tnz)
  11801 	out_l_nz = uint32(int32(lnz) >> int32(4))
  11802 	ch = 0
  11803 	for {
  11804 		if !(ch < int32(4)) {
  11805 			break
  11806 		}
  11807 		nz_coeffs1 = uint32(0)
  11808 		tnz = uint8(int32((*VP8MB)(unsafe.Pointer(mb)).Fnz) >> (int32(4) + ch))
  11809 		lnz = uint8(int32((*VP8MB)(unsafe.Pointer(left_mb)).Fnz) >> (int32(4) + ch))
  11810 		y = 0
  11811 		for {
  11812 			if !(y < int32(2)) {
  11813 				break
  11814 			}
  11815 			l1 = int32(lnz) & int32(1)
  11816 			x = 0
  11817 			for {
  11818 				if !(x < int32(2)) {
  11819 					break
  11820 				}
  11821 				ctx2 = l1 + int32(tnz)&int32(1)
  11822 				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)
  11823 				l1 = libc.BoolInt32(nz2 > 0)
  11824 				tnz = uint8(int32(tnz)>>int32(1) | l1<<int32(3))
  11825 				nz_coeffs1 = NzCodeBits(tls, nz_coeffs1, nz2, libc.BoolInt32(int32(**(**int16_t)(__ccgo_up(dst))) != 0))
  11826 				dst = dst + uintptr(16)*2
  11827 				goto _7
  11828 			_7:
  11829 				;
  11830 				x = x + 1
  11831 			}
  11832 			tnz = uint8(int32(tnz) >> libc.Int32FromInt32(2))
  11833 			lnz = uint8(int32(lnz)>>int32(1) | l1<<int32(5))
  11834 			goto _6
  11835 		_6:
  11836 			;
  11837 			y = y + 1
  11838 		}
  11839 		// Note: we don't really need the per-4x4 details for U/V blocks.
  11840 		non_zero_uv = non_zero_uv | nz_coeffs1<<(int32(4)*ch)
  11841 		out_t_nz = out_t_nz | uint32(int32(tnz)<<int32(4)<<ch)
  11842 		out_l_nz = out_l_nz | uint32(int32(lnz)&int32(0xf0)<<ch)
  11843 		goto _5
  11844 	_5:
  11845 		;
  11846 		ch = ch + int32(2)
  11847 	}
  11848 	(*VP8MB)(unsafe.Pointer(mb)).Fnz = uint8(out_t_nz)
  11849 	(*VP8MB)(unsafe.Pointer(left_mb)).Fnz = uint8(out_l_nz)
  11850 	(*VP8MBData)(unsafe.Pointer(block)).Fnon_zero_y = non_zero_y
  11851 	(*VP8MBData)(unsafe.Pointer(block)).Fnon_zero_uv = non_zero_uv
  11852 	// We look at the mode-code of each block and check if some blocks have less
  11853 	// than three non-zero coeffs (code < 2). This is to avoid dithering flat and
  11854 	// empty blocks.
  11855 	if non_zero_uv&uint32(0xaaaa) != 0 {
  11856 		v8 = 0
  11857 	} else {
  11858 		v8 = (*VP8QuantMatrix)(unsafe.Pointer(q)).Fdither
  11859 	}
  11860 	(*VP8MBData)(unsafe.Pointer(block)).Fdither = uint8(v8)
  11861 	return libc.BoolInt32(!(non_zero_y|non_zero_uv != 0)) // will be used for further optimization
  11862 }
  11863 
  11864 //------------------------------------------------------------------------------
  11865 // Main loop
  11866 
  11867 func VP8DecodeMB(tls *libc.TLS, dec uintptr, token_br uintptr) (r int32) {
  11868 	var block, finfo, left, mb, v4 uintptr
  11869 	var skip, v1 int32
  11870 	var v2 uint8_t
  11871 	_, _, _, _, _, _, _, _ = block, finfo, left, mb, skip, v1, v2, v4
  11872 	left = (*VP8Decoder)(unsafe.Pointer(dec)).Fmb_info - uintptr(1)*2
  11873 	mb = (*VP8Decoder)(unsafe.Pointer(dec)).Fmb_info + uintptr((*VP8Decoder)(unsafe.Pointer(dec)).Fmb_x)*2
  11874 	block = (*VP8Decoder)(unsafe.Pointer(dec)).Fmb_data + uintptr((*VP8Decoder)(unsafe.Pointer(dec)).Fmb_x)*800
  11875 	if (*VP8Decoder)(unsafe.Pointer(dec)).Fuse_skip_proba != 0 {
  11876 		v1 = int32((*VP8MBData)(unsafe.Pointer(block)).Fskip)
  11877 	} else {
  11878 		v1 = 0
  11879 	}
  11880 	skip = v1
  11881 	if !(skip != 0) {
  11882 		skip = ParseResiduals(tls, dec, mb, token_br)
  11883 	} else {
  11884 		v2 = libc.Uint8FromInt32(0)
  11885 		(*VP8MB)(unsafe.Pointer(mb)).Fnz = v2
  11886 		(*VP8MB)(unsafe.Pointer(left)).Fnz = v2
  11887 		if !((*VP8MBData)(unsafe.Pointer(block)).Fis_i4x4 != 0) {
  11888 			v2 = libc.Uint8FromInt32(0)
  11889 			(*VP8MB)(unsafe.Pointer(mb)).Fnz_dc = v2
  11890 			(*VP8MB)(unsafe.Pointer(left)).Fnz_dc = v2
  11891 		}
  11892 		(*VP8MBData)(unsafe.Pointer(block)).Fnon_zero_y = uint32(0)
  11893 		(*VP8MBData)(unsafe.Pointer(block)).Fnon_zero_uv = uint32(0)
  11894 		(*VP8MBData)(unsafe.Pointer(block)).Fdither = uint8(0)
  11895 	}
  11896 	if (*VP8Decoder)(unsafe.Pointer(dec)).Ffilter_type > 0 { // store filter info
  11897 		finfo = (*VP8Decoder)(unsafe.Pointer(dec)).Ff_info + uintptr((*VP8Decoder)(unsafe.Pointer(dec)).Fmb_x)*4
  11898 		**(**VP8FInfo)(__ccgo_up(finfo)) = **(**VP8FInfo)(__ccgo_up(dec + 2924 + uintptr((*VP8MBData)(unsafe.Pointer(block)).Fsegment)*8 + uintptr((*VP8MBData)(unsafe.Pointer(block)).Fis_i4x4)*4))
  11899 		v4 = finfo + 2
  11900 		*(*uint8_t)(unsafe.Pointer(v4)) = uint8_t(int32(*(*uint8_t)(unsafe.Pointer(v4))) | libc.BoolInt32(!(skip != 0)))
  11901 	}
  11902 	return libc.BoolInt32(!((*VP8BitReader)(unsafe.Pointer(token_br)).Feof != 0))
  11903 }
  11904 
  11905 func VP8InitScanline(tls *libc.TLS, dec uintptr) {
  11906 	var left uintptr
  11907 	_ = left
  11908 	left = (*VP8Decoder)(unsafe.Pointer(dec)).Fmb_info - uintptr(1)*2
  11909 	(*VP8MB)(unsafe.Pointer(left)).Fnz = uint8(0)
  11910 	(*VP8MB)(unsafe.Pointer(left)).Fnz_dc = uint8(0)
  11911 	libc.Xmemset(tls, dec+2816, int32(B_DC_PRED), uint64(4))
  11912 	(*VP8Decoder)(unsafe.Pointer(dec)).Fmb_x = 0
  11913 }
  11914 
  11915 func ParseFrame(tls *libc.TLS, dec uintptr, io uintptr) (r int32) {
  11916 	var token_br uintptr
  11917 	_ = token_br
  11918 	(*VP8Decoder)(unsafe.Pointer(dec)).Fmb_y = 0
  11919 	for {
  11920 		if !((*VP8Decoder)(unsafe.Pointer(dec)).Fmb_y < (*VP8Decoder)(unsafe.Pointer(dec)).Fbr_mb_y) {
  11921 			break
  11922 		}
  11923 		// Parse bitstream for this row.
  11924 		token_br = dec + 440 + uintptr(uint32((*VP8Decoder)(unsafe.Pointer(dec)).Fmb_y)&(*VP8Decoder)(unsafe.Pointer(dec)).Fnum_parts_minus_one)*48
  11925 		if !(VP8ParseIntraModeRow(tls, dec+16, dec) != 0) {
  11926 			return VP8SetError(tls, dec, int32(VP8_STATUS_NOT_ENOUGH_DATA), __ccgo_ts+435)
  11927 		}
  11928 		for {
  11929 			if !((*VP8Decoder)(unsafe.Pointer(dec)).Fmb_x < (*VP8Decoder)(unsafe.Pointer(dec)).Fmb_w) {
  11930 				break
  11931 			}
  11932 			if !(VP8DecodeMB(tls, dec, token_br) != 0) {
  11933 				return VP8SetError(tls, dec, int32(VP8_STATUS_NOT_ENOUGH_DATA), __ccgo_ts+476)
  11934 			}
  11935 			goto _2
  11936 		_2:
  11937 			;
  11938 			(*VP8Decoder)(unsafe.Pointer(dec)).Fmb_x = (*VP8Decoder)(unsafe.Pointer(dec)).Fmb_x + 1
  11939 		}
  11940 		VP8InitScanline(tls, dec) // Prepare for next scanline
  11941 		// Reconstruct, filter and emit the row.
  11942 		if !(VP8ProcessRow(tls, dec, io) != 0) {
  11943 			return VP8SetError(tls, dec, int32(VP8_STATUS_USER_ABORT), __ccgo_ts+511)
  11944 		}
  11945 		goto _1
  11946 	_1:
  11947 		;
  11948 		(*VP8Decoder)(unsafe.Pointer(dec)).Fmb_y = (*VP8Decoder)(unsafe.Pointer(dec)).Fmb_y + 1
  11949 	}
  11950 	if (*VP8Decoder)(unsafe.Pointer(dec)).Fmt_method > 0 {
  11951 		if !((*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*WebPWorkerInterface)(unsafe.Pointer(WebPGetWorkerInterface(tls))).FSync})))(tls, dec+152) != 0) {
  11952 			return 0
  11953 		}
  11954 	}
  11955 	return int32(1)
  11956 }
  11957 
  11958 // C documentation
  11959 //
  11960 //	// Main entry point
  11961 func VP8Decode(tls *libc.TLS, dec uintptr, io uintptr) (r int32) {
  11962 	var ok int32
  11963 	_ = ok
  11964 	ok = 0
  11965 	if dec == libc.UintptrFromInt32(0) {
  11966 		return 0
  11967 	}
  11968 	if io == libc.UintptrFromInt32(0) {
  11969 		return VP8SetError(tls, dec, int32(VP8_STATUS_INVALID_PARAM), __ccgo_ts+527)
  11970 	}
  11971 	if !((*VP8Decoder)(unsafe.Pointer(dec)).Fready != 0) {
  11972 		if !(VP8GetHeaders(tls, dec, io) != 0) {
  11973 			return 0
  11974 		}
  11975 	}
  11976 	// Finish setting up the decoding parameter. Will call io->setup().
  11977 	ok = libc.BoolInt32(VP8EnterCritical(tls, dec, io) == int32(VP8_STATUS_OK))
  11978 	if ok != 0 { // good to go.
  11979 		// Will allocate memory and prepare everything.
  11980 		if ok != 0 {
  11981 			ok = VP8InitFrame(tls, dec, io)
  11982 		}
  11983 		// Main decoding loop
  11984 		if ok != 0 {
  11985 			ok = ParseFrame(tls, dec, io)
  11986 		}
  11987 		// Exit.
  11988 		ok = ok & VP8ExitCritical(tls, dec, io)
  11989 	}
  11990 	if !(ok != 0) {
  11991 		VP8Clear(tls, dec)
  11992 		return 0
  11993 	}
  11994 	(*VP8Decoder)(unsafe.Pointer(dec)).Fready = 0
  11995 	return ok
  11996 }
  11997 
  11998 func VP8Clear(tls *libc.TLS, dec uintptr) {
  11999 	if dec == libc.UintptrFromInt32(0) {
  12000 		return
  12001 	}
  12002 	(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(&struct{ uintptr }{(*WebPWorkerInterface)(unsafe.Pointer(WebPGetWorkerInterface(tls))).FEnd})))(tls, dec+152)
  12003 	WebPDeallocateAlphaMemory(tls, dec)
  12004 	WebPSafeFree(tls, (*VP8Decoder)(unsafe.Pointer(dec)).Fmem)
  12005 	(*VP8Decoder)(unsafe.Pointer(dec)).Fmem = libc.UintptrFromInt32(0)
  12006 	(*VP8Decoder)(unsafe.Pointer(dec)).Fmem_size = uint64(0)
  12007 	libc.Xmemset(tls, dec+16, 0, uint64(48))
  12008 	(*VP8Decoder)(unsafe.Pointer(dec)).Fready = 0
  12009 }
  12010 
  12011 const APPROX_LOG_MAX = 4096
  12012 const APPROX_LOG_WITH_CORRECTION_MAX = 65536
  12013 const BITS_SPECIAL_MARKER = 256
  12014 const CODE_TO_PLANE_CODES = 120
  12015 const LOG_2_PRECISION_BITS = 23
  12016 const LOG_2_RECIPROCAL = 1.44269504088896338700465094007086
  12017 const LOG_2_RECIPROCAL_FIXED_DOUBLE = 12102203.161561485379934310913085937500
  12018 const LOG_LOOKUP_IDX_MAX = 256
  12019 const NUM_ARGB_CACHE_ROWS = 16
  12020 const NUM_CODE_LENGTH_CODES = 19
  12021 const PACKED_NON_LITERAL_CODE = 0
  12022 const PREFIX_LOOKUP_IDX_MAX = 512
  12023 const SYNC_EVERY_N_ROWS = 8
  12024 const VP8L_MAGIC_BYTE1 = 47
  12025 
  12026 var kHashMul8 = uint32(0x1e35a7bd)
  12027 
  12028 type VP8LPredictorFunc = uintptr
  12029 
  12030 type VP8LPredictorAddSubFunc = uintptr
  12031 
  12032 type VP8LProcessDecBlueAndRedFunc = uintptr
  12033 
  12034 type VP8LMultipliers = struct {
  12035 	Fgreen_to_red  uint8_t
  12036 	Fgreen_to_blue uint8_t
  12037 	Fred_to_blue   uint8_t
  12038 }
  12039 
  12040 type VP8LTransformColorInverseFunc = uintptr
  12041 
  12042 type VP8LConvertFunc = uintptr
  12043 
  12044 type VP8LMapARGBFunc = uintptr
  12045 
  12046 type VP8LMapAlphaFunc = uintptr
  12047 
  12048 type VP8LProcessEncBlueAndRedFunc = uintptr
  12049 
  12050 type VP8LTransformColorFunc = uintptr
  12051 
  12052 type VP8LCollectColorBlueTransformsFunc = uintptr
  12053 
  12054 type VP8LCollectColorRedTransformsFunc = uintptr
  12055 
  12056 type VP8LCostFunc = uintptr
  12057 
  12058 type VP8LCombinedShannonEntropyFunc = uintptr
  12059 
  12060 type VP8LShannonEntropyFunc = uintptr
  12061 
  12062 type VP8LStreaks = struct {
  12063 	Fcounts  [2]int32
  12064 	Fstreaks [2][2]int32
  12065 }
  12066 
  12067 type VP8LBitEntropy = struct {
  12068 	Fentropy      uint64_t
  12069 	Fsum          uint32_t
  12070 	Fnonzeros     int32
  12071 	Fmax_val      uint32_t
  12072 	Fnonzero_code uint32_t
  12073 }
  12074 
  12075 type VP8LGetCombinedEntropyUnrefinedFunc = uintptr
  12076 
  12077 type VP8LGetEntropyUnrefinedFunc = uintptr
  12078 
  12079 type VP8LAddVectorFunc = uintptr
  12080 
  12081 type VP8LAddVectorEqFunc = uintptr
  12082 
  12083 type VP8LVectorMismatchFunc = uintptr
  12084 
  12085 type VP8LBundleColorMapFunc = uintptr
  12086 
  12087 type VP8LFastLog2SlowFunc = uintptr
  12088 
  12089 type VP8LFastSLog2SlowFunc = uintptr
  12090 
  12091 type VP8LPrefixCode = struct {
  12092 	Fcode       int8_t
  12093 	Fextra_bits int8_t
  12094 }
  12095 
  12096 //------------------------------------------------------------------------------
  12097 // Transform-related functions used in both encoding and decoding.
  12098 
  12099 // Macros used to create a batch predictor that iteratively uses a
  12100 // one-pixel predictor.
  12101 
  12102 // The predictor is added to the output pixel (which
  12103 // is therefore considered as a residual) to get the final prediction.
  12104 
  12105 // Copyright 2010 Google Inc. All Rights Reserved.
  12106 //
  12107 // Use of this source code is governed by a BSD-style license
  12108 // that can be found in the COPYING file in the root of the source
  12109 // tree. An additional intellectual property rights grant can be found
  12110 // in the file PATENTS. All contributing project authors may
  12111 // be found in the AUTHORS file in the root of the source tree.
  12112 // -----------------------------------------------------------------------------
  12113 //
  12114 // Boolean decoder
  12115 //
  12116 // Author: Skal (pascal.massimino@gmail.com)
  12117 //         Vikas Arora (vikaas.arora@gmail.com)
  12118 
  12119 // Copyright 2012 Google Inc. All Rights Reserved.
  12120 //
  12121 // Use of this source code is governed by a BSD-style license
  12122 // that can be found in the COPYING file in the root of the source
  12123 // tree. An additional intellectual property rights grant can be found
  12124 // in the file PATENTS. All contributing project authors may
  12125 // be found in the AUTHORS file in the root of the source tree.
  12126 // -----------------------------------------------------------------------------
  12127 //
  12128 // Color Cache for WebP Lossless
  12129 //
  12130 // Authors: Jyrki Alakuijala (jyrki@google.com)
  12131 //          Urvang Joshi (urvang@google.com)
  12132 
  12133 // Copyright 2012 Google Inc. All Rights Reserved.
  12134 //
  12135 // Use of this source code is governed by a BSD-style license
  12136 // that can be found in the COPYING file in the root of the source
  12137 // tree. An additional intellectual property rights grant can be found
  12138 // in the file PATENTS. All contributing project authors may
  12139 // be found in the AUTHORS file in the root of the source tree.
  12140 // -----------------------------------------------------------------------------
  12141 //
  12142 // Utilities for building and looking up Huffman trees.
  12143 //
  12144 // Author: Urvang Joshi (urvang@google.com)
  12145 
  12146 // Copyright 2012 Google Inc. All Rights Reserved.
  12147 //
  12148 // Use of this source code is governed by a BSD-style license
  12149 // that can be found in the COPYING file in the root of the source
  12150 // tree. An additional intellectual property rights grant can be found
  12151 // in the file PATENTS. All contributing project authors may
  12152 // be found in the AUTHORS file in the root of the source tree.
  12153 // -----------------------------------------------------------------------------
  12154 //
  12155 // Rescaling functions
  12156 //
  12157 // Author: Skal (pascal.massimino@gmail.com)
  12158 
  12159 // Copyright 2012 Google Inc. All Rights Reserved.
  12160 //
  12161 // Use of this source code is governed by a BSD-style license
  12162 // that can be found in the COPYING file in the root of the source
  12163 // tree. An additional intellectual property rights grant can be found
  12164 // in the file PATENTS. All contributing project authors may
  12165 // be found in the AUTHORS file in the root of the source tree.
  12166 // -----------------------------------------------------------------------------
  12167 //
  12168 // Misc. common utility functions
  12169 //
  12170 // Authors: Skal (pascal.massimino@gmail.com)
  12171 //          Urvang (urvang@google.com)
  12172 
  12173 // Copyright 2010 Google Inc. All Rights Reserved.
  12174 //
  12175 // Use of this source code is governed by a BSD-style license
  12176 // that can be found in the COPYING file in the root of the source
  12177 // tree. An additional intellectual property rights grant can be found
  12178 // in the file PATENTS. All contributing project authors may
  12179 // be found in the AUTHORS file in the root of the source tree.
  12180 // -----------------------------------------------------------------------------
  12181 //
  12182 //  Main decoding functions for WebP images.
  12183 //
  12184 // Author: Skal (pascal.massimino@gmail.com)
  12185 
  12186 // Copyright 2012 Google Inc. All Rights Reserved.
  12187 //
  12188 // Use of this source code is governed by a BSD-style license
  12189 // that can be found in the COPYING file in the root of the source
  12190 // tree. An additional intellectual property rights grant can be found
  12191 // in the file PATENTS. All contributing project authors may
  12192 // be found in the AUTHORS file in the root of the source tree.
  12193 // -----------------------------------------------------------------------------
  12194 //
  12195 //  Internal header for constants related to WebP file format.
  12196 //
  12197 // Author: Urvang (urvang@google.com)
  12198 
  12199 // Copyright 2010 Google Inc. All Rights Reserved.
  12200 //
  12201 // Use of this source code is governed by a BSD-style license
  12202 // that can be found in the COPYING file in the root of the source
  12203 // tree. An additional intellectual property rights grant can be found
  12204 // in the file PATENTS. All contributing project authors may
  12205 // be found in the AUTHORS file in the root of the source tree.
  12206 // -----------------------------------------------------------------------------
  12207 //
  12208 //  Common types + memory wrappers
  12209 //
  12210 // Author: Skal (pascal.massimino@gmail.com)
  12211 
  12212 var kCodeLengthLiterals = int32(16)
  12213 var kCodeLengthRepeatCode = int32(16)
  12214 var kCodeLengthExtraBits = [3]uint8_t{
  12215 	0: uint8(2),
  12216 	1: uint8(3),
  12217 	2: uint8(7),
  12218 }
  12219 var kCodeLengthRepeatOffsets = [3]uint8_t{
  12220 	0: uint8(3),
  12221 	1: uint8(3),
  12222 	2: uint8(11),
  12223 }
  12224 
  12225 // C documentation
  12226 //
  12227 //	// -----------------------------------------------------------------------------
  12228 //	//  Five Huffman codes are used at each meta code:
  12229 //	//  1. green + length prefix codes + color cache codes,
  12230 //	//  2. alpha,
  12231 //	//  3. red,
  12232 //	//  4. blue, and,
  12233 //	//  5. distance prefix codes.
  12234 type HuffIndex = int32
  12235 
  12236 const GREEN = 0
  12237 const RED = 1
  12238 const BLUE = 2
  12239 const ALPHA = 3
  12240 const DIST = 4
  12241 
  12242 var kAlphabetSize = [5]uint16_t{
  12243 	0: uint16(libc.Int32FromInt32(NUM_LITERAL_CODES) + libc.Int32FromInt32(NUM_LENGTH_CODES)),
  12244 	1: uint16(NUM_LITERAL_CODES),
  12245 	2: uint16(NUM_LITERAL_CODES),
  12246 	3: uint16(NUM_LITERAL_CODES),
  12247 	4: uint16(NUM_DISTANCE_CODES),
  12248 }
  12249 
  12250 var kLiteralMap = [5]uint8_t{
  12251 	1: uint8(1),
  12252 	2: uint8(1),
  12253 	3: uint8(1),
  12254 }
  12255 
  12256 var kCodeLengthCodeOrder = [19]uint8_t{
  12257 	0:  uint8(17),
  12258 	1:  uint8(18),
  12259 	3:  uint8(1),
  12260 	4:  uint8(2),
  12261 	5:  uint8(3),
  12262 	6:  uint8(4),
  12263 	7:  uint8(5),
  12264 	8:  uint8(16),
  12265 	9:  uint8(6),
  12266 	10: uint8(7),
  12267 	11: uint8(8),
  12268 	12: uint8(9),
  12269 	13: uint8(10),
  12270 	14: uint8(11),
  12271 	15: uint8(12),
  12272 	16: uint8(13),
  12273 	17: uint8(14),
  12274 	18: uint8(15),
  12275 }
  12276 
  12277 var kCodeToPlane = [120]uint8_t{
  12278 	0:   uint8(0x18),
  12279 	1:   uint8(0x07),
  12280 	2:   uint8(0x17),
  12281 	3:   uint8(0x19),
  12282 	4:   uint8(0x28),
  12283 	5:   uint8(0x06),
  12284 	6:   uint8(0x27),
  12285 	7:   uint8(0x29),
  12286 	8:   uint8(0x16),
  12287 	9:   uint8(0x1a),
  12288 	10:  uint8(0x26),
  12289 	11:  uint8(0x2a),
  12290 	12:  uint8(0x38),
  12291 	13:  uint8(0x05),
  12292 	14:  uint8(0x37),
  12293 	15:  uint8(0x39),
  12294 	16:  uint8(0x15),
  12295 	17:  uint8(0x1b),
  12296 	18:  uint8(0x36),
  12297 	19:  uint8(0x3a),
  12298 	20:  uint8(0x25),
  12299 	21:  uint8(0x2b),
  12300 	22:  uint8(0x48),
  12301 	23:  uint8(0x04),
  12302 	24:  uint8(0x47),
  12303 	25:  uint8(0x49),
  12304 	26:  uint8(0x14),
  12305 	27:  uint8(0x1c),
  12306 	28:  uint8(0x35),
  12307 	29:  uint8(0x3b),
  12308 	30:  uint8(0x46),
  12309 	31:  uint8(0x4a),
  12310 	32:  uint8(0x24),
  12311 	33:  uint8(0x2c),
  12312 	34:  uint8(0x58),
  12313 	35:  uint8(0x45),
  12314 	36:  uint8(0x4b),
  12315 	37:  uint8(0x34),
  12316 	38:  uint8(0x3c),
  12317 	39:  uint8(0x03),
  12318 	40:  uint8(0x57),
  12319 	41:  uint8(0x59),
  12320 	42:  uint8(0x13),
  12321 	43:  uint8(0x1d),
  12322 	44:  uint8(0x56),
  12323 	45:  uint8(0x5a),
  12324 	46:  uint8(0x23),
  12325 	47:  uint8(0x2d),
  12326 	48:  uint8(0x44),
  12327 	49:  uint8(0x4c),
  12328 	50:  uint8(0x55),
  12329 	51:  uint8(0x5b),
  12330 	52:  uint8(0x33),
  12331 	53:  uint8(0x3d),
  12332 	54:  uint8(0x68),
  12333 	55:  uint8(0x02),
  12334 	56:  uint8(0x67),
  12335 	57:  uint8(0x69),
  12336 	58:  uint8(0x12),
  12337 	59:  uint8(0x1e),
  12338 	60:  uint8(0x66),
  12339 	61:  uint8(0x6a),
  12340 	62:  uint8(0x22),
  12341 	63:  uint8(0x2e),
  12342 	64:  uint8(0x54),
  12343 	65:  uint8(0x5c),
  12344 	66:  uint8(0x43),
  12345 	67:  uint8(0x4d),
  12346 	68:  uint8(0x65),
  12347 	69:  uint8(0x6b),
  12348 	70:  uint8(0x32),
  12349 	71:  uint8(0x3e),
  12350 	72:  uint8(0x78),
  12351 	73:  uint8(0x01),
  12352 	74:  uint8(0x77),
  12353 	75:  uint8(0x79),
  12354 	76:  uint8(0x53),
  12355 	77:  uint8(0x5d),
  12356 	78:  uint8(0x11),
  12357 	79:  uint8(0x1f),
  12358 	80:  uint8(0x64),
  12359 	81:  uint8(0x6c),
  12360 	82:  uint8(0x42),
  12361 	83:  uint8(0x4e),
  12362 	84:  uint8(0x76),
  12363 	85:  uint8(0x7a),
  12364 	86:  uint8(0x21),
  12365 	87:  uint8(0x2f),
  12366 	88:  uint8(0x75),
  12367 	89:  uint8(0x7b),
  12368 	90:  uint8(0x31),
  12369 	91:  uint8(0x3f),
  12370 	92:  uint8(0x63),
  12371 	93:  uint8(0x6d),
  12372 	94:  uint8(0x52),
  12373 	95:  uint8(0x5e),
  12374 	97:  uint8(0x74),
  12375 	98:  uint8(0x7c),
  12376 	99:  uint8(0x41),
  12377 	100: uint8(0x4f),
  12378 	101: uint8(0x10),
  12379 	102: uint8(0x20),
  12380 	103: uint8(0x62),
  12381 	104: uint8(0x6e),
  12382 	105: uint8(0x30),
  12383 	106: uint8(0x73),
  12384 	107: uint8(0x7d),
  12385 	108: uint8(0x51),
  12386 	109: uint8(0x5f),
  12387 	110: uint8(0x40),
  12388 	111: uint8(0x72),
  12389 	112: uint8(0x7e),
  12390 	113: uint8(0x61),
  12391 	114: uint8(0x6f),
  12392 	115: uint8(0x50),
  12393 	116: uint8(0x71),
  12394 	117: uint8(0x7f),
  12395 	118: uint8(0x60),
  12396 	119: uint8(0x70),
  12397 }
  12398 
  12399 // C documentation
  12400 //
  12401 //	// Memory needed for lookup tables of one Huffman tree group. Red, blue, alpha
  12402 //	// and distance alphabets are constant (256 for red, blue and alpha, 40 for
  12403 //	// distance) and lookup table sizes for them in worst case are 630 and 410
  12404 //	// respectively. Size of green alphabet depends on color cache size and is equal
  12405 //	// to 256 (green component values) + 24 (length prefix values)
  12406 //	// + color_cache_size (between 0 and 2048).
  12407 //	// All values computed for 8-bit first level lookup with Mark Adler's tool:
  12408 //	// https://github.com/madler/zlib/blob/v1.2.5/examples/enough.c
  12409 var kTableSize = [12]uint16_t{
  12410 	0:  uint16(libc.Int32FromInt32(630)*libc.Int32FromInt32(3) + libc.Int32FromInt32(410) + libc.Int32FromInt32(654)),
  12411 	1:  uint16(libc.Int32FromInt32(630)*libc.Int32FromInt32(3) + libc.Int32FromInt32(410) + libc.Int32FromInt32(656)),
  12412 	2:  uint16(libc.Int32FromInt32(630)*libc.Int32FromInt32(3) + libc.Int32FromInt32(410) + libc.Int32FromInt32(658)),
  12413 	3:  uint16(libc.Int32FromInt32(630)*libc.Int32FromInt32(3) + libc.Int32FromInt32(410) + libc.Int32FromInt32(662)),
  12414 	4:  uint16(libc.Int32FromInt32(630)*libc.Int32FromInt32(3) + libc.Int32FromInt32(410) + libc.Int32FromInt32(670)),
  12415 	5:  uint16(libc.Int32FromInt32(630)*libc.Int32FromInt32(3) + libc.Int32FromInt32(410) + libc.Int32FromInt32(686)),
  12416 	6:  uint16(libc.Int32FromInt32(630)*libc.Int32FromInt32(3) + libc.Int32FromInt32(410) + libc.Int32FromInt32(718)),
  12417 	7:  uint16(libc.Int32FromInt32(630)*libc.Int32FromInt32(3) + libc.Int32FromInt32(410) + libc.Int32FromInt32(782)),
  12418 	8:  uint16(libc.Int32FromInt32(630)*libc.Int32FromInt32(3) + libc.Int32FromInt32(410) + libc.Int32FromInt32(912)),
  12419 	9:  uint16(libc.Int32FromInt32(630)*libc.Int32FromInt32(3) + libc.Int32FromInt32(410) + libc.Int32FromInt32(1168)),
  12420 	10: uint16(libc.Int32FromInt32(630)*libc.Int32FromInt32(3) + libc.Int32FromInt32(410) + libc.Int32FromInt32(1680)),
  12421 	11: uint16(libc.Int32FromInt32(630)*libc.Int32FromInt32(3) + libc.Int32FromInt32(410) + libc.Int32FromInt32(2704)),
  12422 }
  12423 
  12424 func VP8LSetError(tls *libc.TLS, dec uintptr, error1 VP8StatusCode1) (r int32) {
  12425 	// The oldest error reported takes precedence over the new one.
  12426 	if (*VP8LDecoder)(unsafe.Pointer(dec)).Fstatus == int32(VP8_STATUS_OK) || (*VP8LDecoder)(unsafe.Pointer(dec)).Fstatus == int32(VP8_STATUS_SUSPENDED) {
  12427 		(*VP8LDecoder)(unsafe.Pointer(dec)).Fstatus = error1
  12428 	}
  12429 	return 0
  12430 }
  12431 
  12432 //------------------------------------------------------------------------------
  12433 
  12434 func VP8LCheckSignature(tls *libc.TLS, data uintptr, size size_t) (r int32) {
  12435 	return libc.BoolInt32(size >= uint64(VP8L_FRAME_HEADER_SIZE) && int32(**(**uint8_t)(__ccgo_up(data))) == int32(VP8L_MAGIC_BYTE1) && int32(**(**uint8_t)(__ccgo_up(data + 4)))>>int32(5) == 0) // version
  12436 }
  12437 
  12438 func ReadImageInfo(tls *libc.TLS, br uintptr, width uintptr, height uintptr, has_alpha uintptr) (r int32) {
  12439 	if VP8LReadBits(tls, br, int32(8)) != uint32(VP8L_MAGIC_BYTE1) {
  12440 		return 0
  12441 	}
  12442 	**(**int32)(__ccgo_up(width)) = int32(VP8LReadBits(tls, br, int32(VP8L_IMAGE_SIZE_BITS)) + uint32(1))
  12443 	**(**int32)(__ccgo_up(height)) = int32(VP8LReadBits(tls, br, int32(VP8L_IMAGE_SIZE_BITS)) + uint32(1))
  12444 	**(**int32)(__ccgo_up(has_alpha)) = int32(VP8LReadBits(tls, br, int32(1)))
  12445 	if VP8LReadBits(tls, br, int32(VP8L_VERSION_BITS)) != uint32(0) {
  12446 		return 0
  12447 	}
  12448 	return libc.BoolInt32(!((*VP8LBitReader)(unsafe.Pointer(br)).Feos != 0))
  12449 }
  12450 
  12451 func VP8LGetInfo(tls *libc.TLS, data uintptr, data_size size_t, width uintptr, height uintptr, has_alpha uintptr) (r int32) {
  12452 	bp := tls.Alloc(64)
  12453 	defer tls.Free(64)
  12454 	var _ /* a at bp+8 */ int32
  12455 	var _ /* br at bp+16 */ VP8LBitReader
  12456 	var _ /* h at bp+4 */ int32
  12457 	var _ /* w at bp+0 */ int32
  12458 	if data == libc.UintptrFromInt32(0) || data_size < uint64(VP8L_FRAME_HEADER_SIZE) {
  12459 		return 0 // not enough data
  12460 	} else {
  12461 		if !(VP8LCheckSignature(tls, data, data_size) != 0) {
  12462 			return 0 // bad signature
  12463 		} else {
  12464 			VP8LInitBitReader(tls, bp+16, data, data_size)
  12465 			if !(ReadImageInfo(tls, bp+16, bp, bp+4, bp+8) != 0) {
  12466 				return 0
  12467 			}
  12468 			if width != libc.UintptrFromInt32(0) {
  12469 				**(**int32)(__ccgo_up(width)) = **(**int32)(__ccgo_up(bp))
  12470 			}
  12471 			if height != libc.UintptrFromInt32(0) {
  12472 				**(**int32)(__ccgo_up(height)) = **(**int32)(__ccgo_up(bp + 4))
  12473 			}
  12474 			if has_alpha != libc.UintptrFromInt32(0) {
  12475 				**(**int32)(__ccgo_up(has_alpha)) = **(**int32)(__ccgo_up(bp + 8))
  12476 			}
  12477 			return int32(1)
  12478 		}
  12479 	}
  12480 	return r
  12481 }
  12482 
  12483 //------------------------------------------------------------------------------
  12484 
  12485 func GetCopyDistance(tls *libc.TLS, distance_symbol int32, br uintptr) (r int32) {
  12486 	var extra_bits, offset int32
  12487 	_, _ = extra_bits, offset
  12488 	if distance_symbol < int32(4) {
  12489 		return distance_symbol + int32(1)
  12490 	}
  12491 	extra_bits = (distance_symbol - int32(2)) >> int32(1)
  12492 	offset = (int32(2) + distance_symbol&int32(1)) << extra_bits
  12493 	return int32(uint32(offset) + VP8LReadBits(tls, br, extra_bits) + uint32(1))
  12494 }
  12495 
  12496 func GetCopyLength(tls *libc.TLS, length_symbol int32, br uintptr) (r int32) {
  12497 	// Length and distance prefixes are encoded the same way.
  12498 	return GetCopyDistance(tls, length_symbol, br)
  12499 }
  12500 
  12501 func PlaneCodeToDistance(tls *libc.TLS, xsize int32, plane_code int32) (r int32) {
  12502 	var dist, dist_code, xoffset, yoffset, v1 int32
  12503 	_, _, _, _, _ = dist, dist_code, xoffset, yoffset, v1
  12504 	if plane_code > int32(CODE_TO_PLANE_CODES) {
  12505 		return plane_code - int32(CODE_TO_PLANE_CODES)
  12506 	} else {
  12507 		dist_code = int32(kCodeToPlane[plane_code-int32(1)])
  12508 		yoffset = dist_code >> int32(4)
  12509 		xoffset = int32(8) - dist_code&int32(0xf)
  12510 		dist = yoffset*xsize + xoffset
  12511 		if dist >= int32(1) {
  12512 			v1 = dist
  12513 		} else {
  12514 			v1 = int32(1)
  12515 		}
  12516 		return v1 // dist<1 can happen if xsize is very small
  12517 	}
  12518 	return r
  12519 }
  12520 
  12521 // C documentation
  12522 //
  12523 //	//------------------------------------------------------------------------------
  12524 //	// Decodes the next Huffman code from bit-stream.
  12525 //	// VP8LFillBitWindow(br) needs to be called at minimum every second call
  12526 //	// to ReadSymbol, in order to pre-fetch enough bits.
  12527 func ReadSymbol(tls *libc.TLS, table uintptr, br2 uintptr) (r int32) {
  12528 	var nbits int32
  12529 	var val1, v2 uint32_t
  12530 	var v1 uintptr
  12531 	_, _, _, _ = nbits, val1, v1, v2
  12532 	v1 = br2
  12533 	v2 = uint32((*VP8LBitReader)(unsafe.Pointer(v1)).Fval >> ((*VP8LBitReader)(unsafe.Pointer(v1)).Fbit_pos & (libc.Int32FromInt32(VP8L_LBITS) - libc.Int32FromInt32(1))))
  12534 	goto _3
  12535 _3:
  12536 	val1 = v2
  12537 	table = table + uintptr(val1&uint32(libc.Int32FromInt32(1)<<libc.Int32FromInt32(HUFFMAN_TABLE_BITS)-libc.Int32FromInt32(1)))*4
  12538 	nbits = int32((*HuffmanCode)(unsafe.Pointer(table)).Fbits) - int32(HUFFMAN_TABLE_BITS)
  12539 	if nbits > 0 {
  12540 		(*VP8LBitReader)(unsafe.Pointer(br2)).Fbit_pos = (*VP8LBitReader)(unsafe.Pointer(br2)).Fbit_pos + int32(HUFFMAN_TABLE_BITS)
  12541 		v1 = br2
  12542 		v2 = uint32((*VP8LBitReader)(unsafe.Pointer(v1)).Fval >> ((*VP8LBitReader)(unsafe.Pointer(v1)).Fbit_pos & (libc.Int32FromInt32(VP8L_LBITS) - libc.Int32FromInt32(1))))
  12543 		goto _6
  12544 	_6:
  12545 		val1 = v2
  12546 		table = table + uintptr((*HuffmanCode)(unsafe.Pointer(table)).Fvalue)*4
  12547 		table = table + uintptr(val1&uint32(libc.Int32FromInt32(1)<<nbits-libc.Int32FromInt32(1)))*4
  12548 	}
  12549 	(*VP8LBitReader)(unsafe.Pointer(br2)).Fbit_pos = (*VP8LBitReader)(unsafe.Pointer(br2)).Fbit_pos + int32((*HuffmanCode)(unsafe.Pointer(table)).Fbits)
  12550 	return int32((*HuffmanCode)(unsafe.Pointer(table)).Fvalue)
  12551 }
  12552 
  12553 // C documentation
  12554 //
  12555 //	// Reads packed symbol depending on GREEN channel
  12556 func ReadPackedSymbols(tls *libc.TLS, group uintptr, br2 uintptr, dst uintptr) (r int32) {
  12557 	var code HuffmanCode32
  12558 	var val1, v2 uint32_t
  12559 	var v1 uintptr
  12560 	_, _, _, _ = code, val1, v1, v2
  12561 	v1 = br2
  12562 	v2 = uint32((*VP8LBitReader)(unsafe.Pointer(v1)).Fval >> ((*VP8LBitReader)(unsafe.Pointer(v1)).Fbit_pos & (libc.Int32FromInt32(VP8L_LBITS) - libc.Int32FromInt32(1))))
  12563 	goto _3
  12564 _3:
  12565 	val1 = v2 & (libc.Uint32FromUint32(1)<<libc.Int32FromInt32(HUFFMAN_PACKED_BITS) - libc.Uint32FromInt32(1))
  12566 	code = **(**HuffmanCode32)(__ccgo_up(group + 56 + uintptr(val1)*8))
  12567 	if code.Fbits < int32(BITS_SPECIAL_MARKER) {
  12568 		(*VP8LBitReader)(unsafe.Pointer(br2)).Fbit_pos = (*VP8LBitReader)(unsafe.Pointer(br2)).Fbit_pos + code.Fbits
  12569 		**(**uint32_t)(__ccgo_up(dst)) = code.Fvalue
  12570 		return PACKED_NON_LITERAL_CODE
  12571 	} else {
  12572 		(*VP8LBitReader)(unsafe.Pointer(br2)).Fbit_pos = (*VP8LBitReader)(unsafe.Pointer(br2)).Fbit_pos + code.Fbits - int32(BITS_SPECIAL_MARKER)
  12573 		return int32(code.Fvalue)
  12574 	}
  12575 	return r
  12576 }
  12577 
  12578 func AccumulateHCode(tls *libc.TLS, hcode HuffmanCode, shift int32, huff uintptr) (r int32) {
  12579 	**(**int32)(__ccgo_up(huff)) += int32(hcode.Fbits)
  12580 	**(**uint32_t)(__ccgo_up(huff + 4)) |= uint32(hcode.Fvalue) << shift
  12581 	return int32(hcode.Fbits)
  12582 }
  12583 
  12584 func BuildPackedTable(tls *libc.TLS, htree_group uintptr) {
  12585 	var bits, code uint32_t
  12586 	var hcode HuffmanCode
  12587 	var huff uintptr
  12588 	_, _, _, _ = bits, code, hcode, huff
  12589 	code = uint32(0)
  12590 	for {
  12591 		if !(code < libc.Uint32FromUint32(1)<<libc.Int32FromInt32(HUFFMAN_PACKED_BITS)) {
  12592 			break
  12593 		}
  12594 		bits = code
  12595 		huff = htree_group + 56 + uintptr(bits)*8
  12596 		hcode = **(**HuffmanCode)(__ccgo_up(**(**uintptr)(__ccgo_up(htree_group + uintptr(GREEN)*8)) + uintptr(bits)*4))
  12597 		if int32(hcode.Fvalue) >= int32(NUM_LITERAL_CODES) {
  12598 			(*HuffmanCode32)(unsafe.Pointer(huff)).Fbits = int32(hcode.Fbits) + int32(BITS_SPECIAL_MARKER)
  12599 			(*HuffmanCode32)(unsafe.Pointer(huff)).Fvalue = uint32(hcode.Fvalue)
  12600 		} else {
  12601 			(*HuffmanCode32)(unsafe.Pointer(huff)).Fbits = 0
  12602 			(*HuffmanCode32)(unsafe.Pointer(huff)).Fvalue = uint32(0)
  12603 			bits = bits >> uint32(AccumulateHCode(tls, hcode, int32(8), huff))
  12604 			bits = bits >> uint32(AccumulateHCode(tls, **(**HuffmanCode)(__ccgo_up(**(**uintptr)(__ccgo_up(htree_group + uintptr(RED)*8)) + uintptr(bits)*4)), int32(16), huff))
  12605 			bits = bits >> uint32(AccumulateHCode(tls, **(**HuffmanCode)(__ccgo_up(**(**uintptr)(__ccgo_up(htree_group + uintptr(BLUE)*8)) + uintptr(bits)*4)), 0, huff))
  12606 			bits = bits >> uint32(AccumulateHCode(tls, **(**HuffmanCode)(__ccgo_up(**(**uintptr)(__ccgo_up(htree_group + uintptr(ALPHA)*8)) + uintptr(bits)*4)), int32(24), huff))
  12607 			_ = bits
  12608 		}
  12609 		goto _1
  12610 	_1:
  12611 		;
  12612 		code = code + 1
  12613 	}
  12614 }
  12615 
  12616 func ReadHuffmanCodeLengths(tls *libc.TLS, dec uintptr, code_length_code_lengths uintptr, num_symbols int32, code_lengths uintptr) (r int32) {
  12617 	bp := tls.Alloc(48)
  12618 	defer tls.Free(48)
  12619 	var br3, p, v2 uintptr
  12620 	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
  12621 	var v4 uint32_t
  12622 	var _ /* tables at bp+0 */ HuffmanTables
  12623 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  12624 	ok = 0
  12625 	br3 = dec + 40
  12626 	prev_code_len = int32(DEFAULT_CODE_LENGTH)
  12627 	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) {
  12628 		goto End
  12629 	}
  12630 	if VP8LReadBits(tls, br3, int32(1)) != 0 { // use length
  12631 		length_nbits = int32(uint32(2) + uint32(2)*VP8LReadBits(tls, br3, int32(3)))
  12632 		max_symbol = int32(uint32(2) + VP8LReadBits(tls, br3, length_nbits))
  12633 		if max_symbol > num_symbols {
  12634 			goto End
  12635 		}
  12636 	} else {
  12637 		max_symbol = num_symbols
  12638 	}
  12639 	symbol = 0
  12640 	for symbol < num_symbols {
  12641 		v1 = max_symbol
  12642 		max_symbol = max_symbol - 1
  12643 		if v1 == 0 {
  12644 			break
  12645 		}
  12646 		v2 = br3
  12647 		if (*VP8LBitReader)(unsafe.Pointer(v2)).Fbit_pos >= libc.Int32FromInt32(VP8L_WBITS) {
  12648 			VP8LDoFillBitWindow(tls, v2)
  12649 		}
  12650 		v2 = br3
  12651 		v4 = uint32((*VP8LBitReader)(unsafe.Pointer(v2)).Fval >> ((*VP8LBitReader)(unsafe.Pointer(v2)).Fbit_pos & (libc.Int32FromInt32(VP8L_LBITS) - libc.Int32FromInt32(1))))
  12652 		goto _5
  12653 	_5:
  12654 		p = (*HuffmanTablesSegment)(unsafe.Pointer((**(**HuffmanTables)(__ccgo_up(bp))).Fcurr_segment)).Fstart + uintptr(v4&uint32(libc.Int32FromInt32(1)<<libc.Int32FromInt32(LENGTHS_TABLE_BITS)-libc.Int32FromInt32(1)))*4
  12655 		(*VP8LBitReader)(unsafe.Pointer(br3)).Fbit_pos = (*VP8LBitReader)(unsafe.Pointer(br3)).Fbit_pos + int32((*HuffmanCode)(unsafe.Pointer(p)).Fbits)
  12656 		code_len = int32((*HuffmanCode)(unsafe.Pointer(p)).Fvalue)
  12657 		if code_len < kCodeLengthLiterals {
  12658 			v1 = symbol
  12659 			symbol = symbol + 1
  12660 			**(**int32)(__ccgo_up(code_lengths + uintptr(v1)*4)) = code_len
  12661 			if code_len != 0 {
  12662 				prev_code_len = code_len
  12663 			}
  12664 		} else {
  12665 			use_prev = libc.BoolInt32(code_len == kCodeLengthRepeatCode)
  12666 			slot = code_len - kCodeLengthLiterals
  12667 			extra_bits = int32(kCodeLengthExtraBits[slot])
  12668 			repeat_offset = int32(kCodeLengthRepeatOffsets[slot])
  12669 			repeat = int32(VP8LReadBits(tls, br3, extra_bits) + uint32(repeat_offset))
  12670 			if symbol+repeat > num_symbols {
  12671 				goto End
  12672 			} else {
  12673 				if use_prev != 0 {
  12674 					v1 = prev_code_len
  12675 				} else {
  12676 					v1 = 0
  12677 				}
  12678 				length = v1
  12679 				for {
  12680 					v6 = repeat
  12681 					repeat = repeat - 1
  12682 					if !(v6 > 0) {
  12683 						break
  12684 					}
  12685 					v7 = symbol
  12686 					symbol = symbol + 1
  12687 					**(**int32)(__ccgo_up(code_lengths + uintptr(v7)*4)) = length
  12688 				}
  12689 			}
  12690 		}
  12691 	}
  12692 	ok = int32(1)
  12693 	goto End
  12694 End:
  12695 	;
  12696 	VP8LHuffmanTablesDeallocate(tls, bp)
  12697 	if !(ok != 0) {
  12698 		return VP8LSetError(tls, dec, int32(VP8_STATUS_BITSTREAM_ERROR))
  12699 	}
  12700 	return ok
  12701 }
  12702 
  12703 // C documentation
  12704 //
  12705 //	// 'code_lengths' is pre-allocated temporary buffer, used for creating Huffman
  12706 //	// tree.
  12707 func ReadHuffmanCode(tls *libc.TLS, alphabet_size int32, dec uintptr, code_lengths uintptr, table uintptr) (r int32) {
  12708 	bp := tls.Alloc(80)
  12709 	defer tls.Free(80)
  12710 	var br uintptr
  12711 	var first_symbol_len_code, i, num_codes, num_symbols, ok, simple_code, size, symbol, v1 int32
  12712 	var _ /* code_length_code_lengths at bp+0 */ [19]int32
  12713 	_, _, _, _, _, _, _, _, _, _ = br, first_symbol_len_code, i, num_codes, num_symbols, ok, simple_code, size, symbol, v1
  12714 	ok = 0
  12715 	size = 0
  12716 	br = dec + 40
  12717 	simple_code = int32(VP8LReadBits(tls, br, int32(1)))
  12718 	libc.Xmemset(tls, code_lengths, 0, uint64(alphabet_size)*uint64(4))
  12719 	if simple_code != 0 { // Read symbols, codes & code lengths directly.
  12720 		num_symbols = int32(VP8LReadBits(tls, br, int32(1)) + uint32(1))
  12721 		first_symbol_len_code = int32(VP8LReadBits(tls, br, int32(1)))
  12722 		if first_symbol_len_code == 0 {
  12723 			v1 = int32(1)
  12724 		} else {
  12725 			v1 = int32(8)
  12726 		}
  12727 		// The first code is either 1 bit or 8 bit code.
  12728 		symbol = int32(VP8LReadBits(tls, br, v1))
  12729 		**(**int32)(__ccgo_up(code_lengths + uintptr(symbol)*4)) = int32(1)
  12730 		// The second code (if present), is always 8 bits long.
  12731 		if num_symbols == int32(2) {
  12732 			symbol = int32(VP8LReadBits(tls, br, int32(8)))
  12733 			**(**int32)(__ccgo_up(code_lengths + uintptr(symbol)*4)) = int32(1)
  12734 		}
  12735 		ok = int32(1)
  12736 	} else {
  12737 		**(**[19]int32)(__ccgo_up(bp)) = [19]int32{}
  12738 		num_codes = int32(VP8LReadBits(tls, br, int32(4)) + uint32(4))
  12739 		i = 0
  12740 		for {
  12741 			if !(i < num_codes) {
  12742 				break
  12743 			}
  12744 			(**(**[19]int32)(__ccgo_up(bp)))[kCodeLengthCodeOrder[i]] = int32(VP8LReadBits(tls, br, int32(3)))
  12745 			goto _2
  12746 		_2:
  12747 			;
  12748 			i = i + 1
  12749 		}
  12750 		ok = ReadHuffmanCodeLengths(tls, dec, bp, alphabet_size, code_lengths)
  12751 	}
  12752 	ok = libc.BoolInt32(ok != 0 && !((*VP8LBitReader)(unsafe.Pointer(br)).Feos != 0))
  12753 	if ok != 0 {
  12754 		size = VP8LBuildHuffmanTable(tls, table, int32(HUFFMAN_TABLE_BITS), code_lengths, alphabet_size)
  12755 	}
  12756 	if !(ok != 0) || size == 0 {
  12757 		return VP8LSetError(tls, dec, int32(VP8_STATUS_BITSTREAM_ERROR))
  12758 	}
  12759 	return size
  12760 }
  12761 
  12762 func ReadHuffmanCodes(tls *libc.TLS, dec uintptr, xsize int32, ysize int32, color_cache_bits int32, allow_recursion int32) (r int32) {
  12763 	bp := tls.Alloc(16)
  12764 	defer tls.Free(16)
  12765 	var br, hdr, huffman_tables, mapped_group, mapping uintptr
  12766 	var group, huffman_pixs, huffman_precision, huffman_xsize, huffman_ysize, i, num_htree_groups, num_htree_groups_max, ok, v9 int32
  12767 	var v1, v2, v4, v5 uint32_t
  12768 	var _ /* htree_groups at bp+8 */ uintptr
  12769 	var _ /* huffman_image at bp+0 */ uintptr
  12770 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  12771 	br = dec + 40
  12772 	hdr = dec + 152
  12773 	**(**uintptr)(__ccgo_up(bp)) = libc.UintptrFromInt32(0)
  12774 	**(**uintptr)(__ccgo_up(bp + 8)) = libc.UintptrFromInt32(0)
  12775 	huffman_tables = hdr + 80
  12776 	num_htree_groups = int32(1)
  12777 	num_htree_groups_max = int32(1)
  12778 	mapping = libc.UintptrFromInt32(0)
  12779 	ok = 0
  12780 	// Check the table has been 0 initialized (through InitMetadata).
  12781 	if allow_recursion != 0 && VP8LReadBits(tls, br, int32(1)) != 0 {
  12782 		// use meta Huffman codes.
  12783 		huffman_precision = int32(uint32(MIN_HUFFMAN_BITS) + VP8LReadBits(tls, br, int32(NUM_HUFFMAN_BITS)))
  12784 		v1 = uint32(huffman_precision)
  12785 		v2 = (uint32(xsize) + uint32(libc.Int32FromInt32(1)<<v1) - uint32(1)) >> v1
  12786 		goto _3
  12787 	_3:
  12788 		huffman_xsize = int32(v2)
  12789 		v4 = uint32(huffman_precision)
  12790 		v5 = (uint32(ysize) + uint32(libc.Int32FromInt32(1)<<v4) - uint32(1)) >> v4
  12791 		goto _6
  12792 	_6:
  12793 		huffman_ysize = int32(v5)
  12794 		huffman_pixs = huffman_xsize * huffman_ysize
  12795 		if !(DecodeImageStream(tls, huffman_xsize, huffman_ysize, 0, dec, bp) != 0) {
  12796 			goto Error
  12797 		}
  12798 		(*VP8LMetadata)(unsafe.Pointer(hdr)).Fhuffman_subsample_bits = huffman_precision
  12799 		i = 0
  12800 		for {
  12801 			if !(i < huffman_pixs) {
  12802 				break
  12803 			}
  12804 			// The huffman data is stored in red and green bytes.
  12805 			group = int32(**(**uint32_t)(__ccgo_up(**(**uintptr)(__ccgo_up(bp)) + uintptr(i)*4)) >> libc.Int32FromInt32(8) & uint32(0xffff))
  12806 			**(**uint32_t)(__ccgo_up(**(**uintptr)(__ccgo_up(bp)) + uintptr(i)*4)) = uint32(group)
  12807 			if group >= num_htree_groups_max {
  12808 				num_htree_groups_max = group + int32(1)
  12809 			}
  12810 			goto _7
  12811 		_7:
  12812 			;
  12813 			i = i + 1
  12814 		}
  12815 		// Check the validity of num_htree_groups_max. If it seems too big, use a
  12816 		// smaller value for later. This will prevent big memory allocations to end
  12817 		// up with a bad bitstream anyway.
  12818 		// The value of 1000 is totally arbitrary. We know that num_htree_groups_max
  12819 		// is smaller than (1 << 16) and should be smaller than the number of pixels
  12820 		// (though the format allows it to be bigger).
  12821 		if num_htree_groups_max > int32(1000) || num_htree_groups_max > xsize*ysize {
  12822 			// Create a mapping from the used indices to the minimal set of used
  12823 			// values [0, num_htree_groups)
  12824 			mapping = WebPSafeMalloc(tls, uint64(num_htree_groups_max), uint64(4))
  12825 			if mapping == libc.UintptrFromInt32(0) {
  12826 				VP8LSetError(tls, dec, int32(VP8_STATUS_OUT_OF_MEMORY))
  12827 				goto Error
  12828 			}
  12829 			// -1 means a value is unmapped, and therefore unused in the Huffman
  12830 			// image.
  12831 			libc.Xmemset(tls, mapping, int32(0xff), uint64(num_htree_groups_max)*uint64(4))
  12832 			num_htree_groups = 0
  12833 			i = libc.Int32FromInt32(0)
  12834 			for {
  12835 				if !(i < huffman_pixs) {
  12836 					break
  12837 				}
  12838 				// Get the current mapping for the group and remap the Huffman image.
  12839 				mapped_group = mapping + uintptr(**(**uint32_t)(__ccgo_up(**(**uintptr)(__ccgo_up(bp)) + uintptr(i)*4)))*4
  12840 				if **(**int32)(__ccgo_up(mapped_group)) == -int32(1) {
  12841 					v9 = num_htree_groups
  12842 					num_htree_groups = num_htree_groups + 1
  12843 					**(**int32)(__ccgo_up(mapped_group)) = v9
  12844 				}
  12845 				**(**uint32_t)(__ccgo_up(**(**uintptr)(__ccgo_up(bp)) + uintptr(i)*4)) = uint32(**(**int32)(__ccgo_up(mapped_group)))
  12846 				goto _8
  12847 			_8:
  12848 				;
  12849 				i = i + 1
  12850 			}
  12851 		} else {
  12852 			num_htree_groups = num_htree_groups_max
  12853 		}
  12854 	}
  12855 	if (*VP8LBitReader)(unsafe.Pointer(br)).Feos != 0 {
  12856 		goto Error
  12857 	}
  12858 	if !(ReadHuffmanCodesHelper(tls, color_cache_bits, num_htree_groups, num_htree_groups_max, mapping, dec, huffman_tables, bp+8) != 0) {
  12859 		goto Error
  12860 	}
  12861 	ok = int32(1)
  12862 	// All OK. Finalize pointers.
  12863 	(*VP8LMetadata)(unsafe.Pointer(hdr)).Fhuffman_image = **(**uintptr)(__ccgo_up(bp))
  12864 	(*VP8LMetadata)(unsafe.Pointer(hdr)).Fnum_htree_groups = num_htree_groups
  12865 	(*VP8LMetadata)(unsafe.Pointer(hdr)).Fhtree_groups = **(**uintptr)(__ccgo_up(bp + 8))
  12866 	goto Error
  12867 Error:
  12868 	;
  12869 	WebPSafeFree(tls, mapping)
  12870 	if !(ok != 0) {
  12871 		WebPSafeFree(tls, **(**uintptr)(__ccgo_up(bp)))
  12872 		VP8LHuffmanTablesDeallocate(tls, huffman_tables)
  12873 		VP8LHtreeGroupsFree(tls, **(**uintptr)(__ccgo_up(bp + 8)))
  12874 	}
  12875 	return ok
  12876 }
  12877 
  12878 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) {
  12879 	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
  12880 	var code_lengths, htree_group, htrees uintptr
  12881 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  12882 	ok = 0
  12883 	if color_cache_bits > 0 {
  12884 		v1 = int32(1) << color_cache_bits
  12885 	} else {
  12886 		v1 = 0
  12887 	}
  12888 	max_alphabet_size = int32(kAlphabetSize[0]) + v1
  12889 	table_size = int32(kTableSize[color_cache_bits])
  12890 	code_lengths = libc.UintptrFromInt32(0)
  12891 	if mapping == libc.UintptrFromInt32(0) && num_htree_groups != num_htree_groups_max || num_htree_groups > num_htree_groups_max {
  12892 		goto Error
  12893 	}
  12894 	code_lengths = WebPSafeCalloc(tls, uint64(max_alphabet_size), uint64(4))
  12895 	**(**uintptr)(__ccgo_up(htree_groups)) = VP8LHtreeGroupsNew(tls, num_htree_groups)
  12896 	if **(**uintptr)(__ccgo_up(htree_groups)) == libc.UintptrFromInt32(0) || code_lengths == libc.UintptrFromInt32(0) || !(VP8LHuffmanTablesAllocate(tls, num_htree_groups*table_size, huffman_tables) != 0) {
  12897 		VP8LSetError(tls, dec, int32(VP8_STATUS_OUT_OF_MEMORY))
  12898 		goto Error
  12899 	}
  12900 	i = 0
  12901 	for {
  12902 		if !(i < num_htree_groups_max) {
  12903 			break
  12904 		}
  12905 		// If the index "i" is unused in the Huffman image, just make sure the
  12906 		// coefficients are valid but do not store them.
  12907 		if mapping != libc.UintptrFromInt32(0) && **(**int32)(__ccgo_up(mapping + uintptr(i)*4)) == -int32(1) {
  12908 			j = 0
  12909 			for {
  12910 				if !(j < int32(HUFFMAN_CODES_PER_META_CODE)) {
  12911 					break
  12912 				}
  12913 				alphabet_size = int32(kAlphabetSize[j])
  12914 				if j == 0 && color_cache_bits > 0 {
  12915 					alphabet_size = alphabet_size + int32(1)<<color_cache_bits
  12916 				}
  12917 				// Passing in NULL so that nothing gets filled.
  12918 				if !(ReadHuffmanCode(tls, alphabet_size, dec, code_lengths, libc.UintptrFromInt32(0)) != 0) {
  12919 					goto Error
  12920 				}
  12921 				goto _3
  12922 			_3:
  12923 				;
  12924 				j = j + 1
  12925 			}
  12926 		} else {
  12927 			if mapping == libc.UintptrFromInt32(0) {
  12928 				v1 = i
  12929 			} else {
  12930 				v1 = **(**int32)(__ccgo_up(mapping + uintptr(i)*4))
  12931 			}
  12932 			htree_group = **(**uintptr)(__ccgo_up(htree_groups)) + uintptr(v1)*568
  12933 			htrees = htree_group
  12934 			total_size = 0
  12935 			is_trivial_literal = int32(1)
  12936 			max_bits = 0
  12937 			j = 0
  12938 			for {
  12939 				if !(j < int32(HUFFMAN_CODES_PER_META_CODE)) {
  12940 					break
  12941 				}
  12942 				alphabet_size1 = int32(kAlphabetSize[j])
  12943 				if j == 0 && color_cache_bits > 0 {
  12944 					alphabet_size1 = alphabet_size1 + int32(1)<<color_cache_bits
  12945 				}
  12946 				size = ReadHuffmanCode(tls, alphabet_size1, dec, code_lengths, huffman_tables)
  12947 				**(**uintptr)(__ccgo_up(htrees + uintptr(j)*8)) = (*HuffmanTablesSegment)(unsafe.Pointer((*HuffmanTables)(unsafe.Pointer(huffman_tables)).Fcurr_segment)).Fcurr_table
  12948 				if size == 0 {
  12949 					goto Error
  12950 				}
  12951 				if is_trivial_literal != 0 && int32(kLiteralMap[j]) == int32(1) {
  12952 					is_trivial_literal = libc.BoolInt32(int32((*HuffmanCode)(unsafe.Pointer(**(**uintptr)(__ccgo_up(htrees + uintptr(j)*8)))).Fbits) == 0)
  12953 				}
  12954 				total_size = total_size + int32((*HuffmanCode)(unsafe.Pointer(**(**uintptr)(__ccgo_up(htrees + uintptr(j)*8)))).Fbits)
  12955 				**(**uintptr)(__ccgo_up((*HuffmanTables)(unsafe.Pointer(huffman_tables)).Fcurr_segment + 8)) += uintptr(size) * 4
  12956 				if j <= int32(ALPHA) {
  12957 					local_max_bits = **(**int32)(__ccgo_up(code_lengths))
  12958 					k = int32(1)
  12959 					for {
  12960 						if !(k < alphabet_size1) {
  12961 							break
  12962 						}
  12963 						if **(**int32)(__ccgo_up(code_lengths + uintptr(k)*4)) > local_max_bits {
  12964 							local_max_bits = **(**int32)(__ccgo_up(code_lengths + uintptr(k)*4))
  12965 						}
  12966 						goto _6
  12967 					_6:
  12968 						;
  12969 						k = k + 1
  12970 					}
  12971 					max_bits = max_bits + local_max_bits
  12972 				}
  12973 				goto _5
  12974 			_5:
  12975 				;
  12976 				j = j + 1
  12977 			}
  12978 			(*HTreeGroup)(unsafe.Pointer(htree_group)).Fis_trivial_literal = is_trivial_literal
  12979 			(*HTreeGroup)(unsafe.Pointer(htree_group)).Fis_trivial_code = 0
  12980 			if is_trivial_literal != 0 {
  12981 				red = int32((**(**HuffmanCode)(__ccgo_up(**(**uintptr)(__ccgo_up(htrees + uintptr(RED)*8))))).Fvalue)
  12982 				blue = int32((**(**HuffmanCode)(__ccgo_up(**(**uintptr)(__ccgo_up(htrees + uintptr(BLUE)*8))))).Fvalue)
  12983 				alpha = int32((**(**HuffmanCode)(__ccgo_up(**(**uintptr)(__ccgo_up(htrees + uintptr(ALPHA)*8))))).Fvalue)
  12984 				(*HTreeGroup)(unsafe.Pointer(htree_group)).Fliteral_arb = uint32(alpha)<<libc.Int32FromInt32(24) | uint32(red<<libc.Int32FromInt32(16)) | uint32(blue)
  12985 				if total_size == 0 && int32((**(**HuffmanCode)(__ccgo_up(**(**uintptr)(__ccgo_up(htrees + uintptr(GREEN)*8))))).Fvalue) < int32(NUM_LITERAL_CODES) {
  12986 					(*HTreeGroup)(unsafe.Pointer(htree_group)).Fis_trivial_code = int32(1)
  12987 					**(**uint32_t)(__ccgo_up(htree_group + 44)) |= uint32(int32((**(**HuffmanCode)(__ccgo_up(**(**uintptr)(__ccgo_up(htrees + uintptr(GREEN)*8))))).Fvalue) << int32(8))
  12988 				}
  12989 			}
  12990 			(*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))
  12991 			if (*HTreeGroup)(unsafe.Pointer(htree_group)).Fuse_packed_table != 0 {
  12992 				BuildPackedTable(tls, htree_group)
  12993 			}
  12994 		}
  12995 		goto _2
  12996 	_2:
  12997 		;
  12998 		i = i + 1
  12999 	}
  13000 	ok = int32(1)
  13001 	goto Error
  13002 Error:
  13003 	;
  13004 	WebPSafeFree(tls, code_lengths)
  13005 	if !(ok != 0) {
  13006 		VP8LHuffmanTablesDeallocate(tls, huffman_tables)
  13007 		VP8LHtreeGroupsFree(tls, **(**uintptr)(__ccgo_up(htree_groups)))
  13008 		**(**uintptr)(__ccgo_up(htree_groups)) = libc.UintptrFromInt32(0)
  13009 	}
  13010 	return ok
  13011 }
  13012 
  13013 //------------------------------------------------------------------------------
  13014 // Scaling.
  13015 
  13016 func AllocateAndInitRescaler(tls *libc.TLS, dec uintptr, io uintptr) (r int32) {
  13017 	var in_height, in_width, num_channels, out_height, out_width int32
  13018 	var memory, scaled_data, work uintptr
  13019 	var memory_size, scaled_data_size, work_size uint64_t
  13020 	_, _, _, _, _, _, _, _, _, _, _ = in_height, in_width, memory, memory_size, num_channels, out_height, out_width, scaled_data, scaled_data_size, work, work_size
  13021 	num_channels = int32(4)
  13022 	in_width = (*VP8Io)(unsafe.Pointer(io)).Fmb_w
  13023 	out_width = (*VP8Io)(unsafe.Pointer(io)).Fscaled_width
  13024 	in_height = (*VP8Io)(unsafe.Pointer(io)).Fmb_h
  13025 	out_height = (*VP8Io)(unsafe.Pointer(io)).Fscaled_height
  13026 	work_size = uint64(int32(2)*num_channels) * uint64(out_width) // Rescaler work area.
  13027 	scaled_data_size = uint64(out_width)                          // Temporary storage for scaled BGRA data.
  13028 	memory_size = uint64(104) + work_size*uint64(4) + scaled_data_size*uint64(4)
  13029 	memory = WebPSafeMalloc(tls, memory_size, uint64(1))
  13030 	if memory == libc.UintptrFromInt32(0) {
  13031 		return VP8LSetError(tls, dec, int32(VP8_STATUS_OUT_OF_MEMORY))
  13032 	}
  13033 	(*VP8LDecoder)(unsafe.Pointer(dec)).Frescaler_memory = memory
  13034 	(*VP8LDecoder)(unsafe.Pointer(dec)).Frescaler = memory
  13035 	memory = memory + uintptr(104)
  13036 	work = memory
  13037 	memory = memory + uintptr(work_size*uint64(4))
  13038 	scaled_data = memory
  13039 	if !(WebPRescalerInit(tls, (*VP8LDecoder)(unsafe.Pointer(dec)).Frescaler, in_width, in_height, scaled_data, out_width, out_height, 0, num_channels, work) != 0) {
  13040 		return 0
  13041 	}
  13042 	return int32(1)
  13043 }
  13044 
  13045 //------------------------------------------------------------------------------
  13046 // Export to ARGB
  13047 
  13048 // C documentation
  13049 //
  13050 //	// We have special "export" function since we need to convert from BGRA
  13051 func Export(tls *libc.TLS, rescaler2 uintptr, colorspace WEBP_CSP_MODE1, rgba_stride int32, rgba uintptr) (r int32) {
  13052 	var dst, src, v1, v4 uintptr
  13053 	var dst_width, num_lines_out, v2, v5 int32
  13054 	_, _, _, _, _, _, _, _ = dst, dst_width, num_lines_out, src, v1, v2, v4, v5
  13055 	src = (*WebPRescaler)(unsafe.Pointer(rescaler2)).Fdst
  13056 	dst = rgba
  13057 	dst_width = (*WebPRescaler)(unsafe.Pointer(rescaler2)).Fdst_width
  13058 	num_lines_out = 0
  13059 	for {
  13060 		v1 = rescaler2
  13061 		v4 = v1
  13062 		v5 = libc.BoolInt32((*WebPRescaler)(unsafe.Pointer(v4)).Fdst_y >= (*WebPRescaler)(unsafe.Pointer(v4)).Fdst_height)
  13063 		goto _6
  13064 	_6:
  13065 		;
  13066 		v2 = libc.BoolInt32(!(v5 != 0) && (*WebPRescaler)(unsafe.Pointer(v1)).Fy_accum <= 0)
  13067 		goto _3
  13068 	_3:
  13069 		if !(v2 != 0) {
  13070 			break
  13071 		}
  13072 		WebPRescalerExportRow(tls, rescaler2)
  13073 		(*(*func(*libc.TLS, uintptr, int32, int32))(unsafe.Pointer(&struct{ uintptr }{WebPMultARGBRow})))(tls, src, dst_width, int32(1))
  13074 		VP8LConvertFromBGRA(tls, src, dst_width, colorspace, dst)
  13075 		dst = dst + uintptr(rgba_stride)
  13076 		num_lines_out = num_lines_out + 1
  13077 	}
  13078 	return num_lines_out
  13079 }
  13080 
  13081 // C documentation
  13082 //
  13083 //	// Emit scaled rows.
  13084 func EmitRescaledRowsRGBA(tls *libc.TLS, dec uintptr, in uintptr, in_stride int32, mb_h int32, out uintptr, out_stride int32) (r int32) {
  13085 	var colorspace WEBP_CSP_MODE1
  13086 	var lines_imported, lines_left, needed_lines, num_lines_in, num_lines_out int32
  13087 	var row_in, row_out uintptr
  13088 	_, _, _, _, _, _, _, _ = colorspace, lines_imported, lines_left, needed_lines, num_lines_in, num_lines_out, row_in, row_out
  13089 	colorspace = (*WebPDecBuffer)(unsafe.Pointer((*VP8LDecoder)(unsafe.Pointer(dec)).Foutput)).Fcolorspace
  13090 	num_lines_in = 0
  13091 	num_lines_out = 0
  13092 	for num_lines_in < mb_h {
  13093 		row_in = in + uintptr(int64(num_lines_in)*int64(in_stride))
  13094 		row_out = out + uintptr(int64(num_lines_out)*int64(out_stride))
  13095 		lines_left = mb_h - num_lines_in
  13096 		needed_lines = WebPRescaleNeededLines(tls, (*VP8LDecoder)(unsafe.Pointer(dec)).Frescaler, lines_left)
  13097 		WebPMultARGBRows(tls, row_in, in_stride, (*WebPRescaler)(unsafe.Pointer((*VP8LDecoder)(unsafe.Pointer(dec)).Frescaler)).Fsrc_width, needed_lines, 0)
  13098 		lines_imported = WebPRescalerImport(tls, (*VP8LDecoder)(unsafe.Pointer(dec)).Frescaler, lines_left, row_in, in_stride)
  13099 		num_lines_in = num_lines_in + lines_imported
  13100 		num_lines_out = num_lines_out + Export(tls, (*VP8LDecoder)(unsafe.Pointer(dec)).Frescaler, colorspace, out_stride, row_out)
  13101 	}
  13102 	return num_lines_out
  13103 }
  13104 
  13105 // C documentation
  13106 //
  13107 //	// Emit rows without any scaling.
  13108 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) {
  13109 	var lines, v1 int32
  13110 	var row_out uintptr
  13111 	_, _, _ = lines, row_out, v1
  13112 	lines = mb_h
  13113 	row_out = out
  13114 	for {
  13115 		v1 = lines
  13116 		lines = lines - 1
  13117 		if !(v1 > 0) {
  13118 			break
  13119 		}
  13120 		VP8LConvertFromBGRA(tls, row_in, mb_w, colorspace, row_out)
  13121 		row_in = row_in + uintptr(in_stride)
  13122 		row_out = row_out + uintptr(out_stride)
  13123 	}
  13124 	return mb_h // Num rows out == num rows in.
  13125 }
  13126 
  13127 //------------------------------------------------------------------------------
  13128 // Export to YUVA
  13129 
  13130 func ConvertToYUVA(tls *libc.TLS, src uintptr, width int32, y_pos int32, output uintptr) {
  13131 	var a, buf, u, v uintptr
  13132 	_, _, _, _ = a, buf, u, v
  13133 	buf = output + 16
  13134 	// first, the luma plane
  13135 	(*(*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)
  13136 	// then U/V planes
  13137 	u = (*WebPYUVABuffer)(unsafe.Pointer(buf)).Fu + uintptr(y_pos>>int32(1)*(*WebPYUVABuffer)(unsafe.Pointer(buf)).Fu_stride)
  13138 	v = (*WebPYUVABuffer)(unsafe.Pointer(buf)).Fv + uintptr(y_pos>>int32(1)*(*WebPYUVABuffer)(unsafe.Pointer(buf)).Fv_stride)
  13139 	// even lines: store values
  13140 	// odd lines: average with previous values
  13141 	(*(*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)))
  13142 	// Lastly, store alpha if needed.
  13143 	if (*WebPYUVABuffer)(unsafe.Pointer(buf)).Fa != libc.UintptrFromInt32(0) {
  13144 		a = (*WebPYUVABuffer)(unsafe.Pointer(buf)).Fa + uintptr(y_pos*(*WebPYUVABuffer)(unsafe.Pointer(buf)).Fa_stride)
  13145 		(*(*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)
  13146 	}
  13147 }
  13148 
  13149 func ExportYUVA(tls *libc.TLS, dec uintptr, y_pos int32) (r int32) {
  13150 	var dst_width, num_lines_out, v2, v5 int32
  13151 	var rescaler2, src, v1, v4 uintptr
  13152 	_, _, _, _, _, _, _, _ = dst_width, num_lines_out, rescaler2, src, v1, v2, v4, v5
  13153 	rescaler2 = (*VP8LDecoder)(unsafe.Pointer(dec)).Frescaler
  13154 	src = (*WebPRescaler)(unsafe.Pointer(rescaler2)).Fdst
  13155 	dst_width = (*WebPRescaler)(unsafe.Pointer(rescaler2)).Fdst_width
  13156 	num_lines_out = 0
  13157 	for {
  13158 		v1 = rescaler2
  13159 		v4 = v1
  13160 		v5 = libc.BoolInt32((*WebPRescaler)(unsafe.Pointer(v4)).Fdst_y >= (*WebPRescaler)(unsafe.Pointer(v4)).Fdst_height)
  13161 		goto _6
  13162 	_6:
  13163 		;
  13164 		v2 = libc.BoolInt32(!(v5 != 0) && (*WebPRescaler)(unsafe.Pointer(v1)).Fy_accum <= 0)
  13165 		goto _3
  13166 	_3:
  13167 		if !(v2 != 0) {
  13168 			break
  13169 		}
  13170 		WebPRescalerExportRow(tls, rescaler2)
  13171 		(*(*func(*libc.TLS, uintptr, int32, int32))(unsafe.Pointer(&struct{ uintptr }{WebPMultARGBRow})))(tls, src, dst_width, int32(1))
  13172 		ConvertToYUVA(tls, src, dst_width, y_pos, (*VP8LDecoder)(unsafe.Pointer(dec)).Foutput)
  13173 		y_pos = y_pos + 1
  13174 		num_lines_out = num_lines_out + 1
  13175 	}
  13176 	return num_lines_out
  13177 }
  13178 
  13179 func EmitRescaledRowsYUVA(tls *libc.TLS, dec uintptr, in uintptr, in_stride int32, mb_h int32) (r int32) {
  13180 	var lines_imported, lines_left, needed_lines, num_lines_in, y_pos int32
  13181 	_, _, _, _, _ = lines_imported, lines_left, needed_lines, num_lines_in, y_pos
  13182 	num_lines_in = 0
  13183 	y_pos = (*VP8LDecoder)(unsafe.Pointer(dec)).Flast_out_row
  13184 	for num_lines_in < mb_h {
  13185 		lines_left = mb_h - num_lines_in
  13186 		needed_lines = WebPRescaleNeededLines(tls, (*VP8LDecoder)(unsafe.Pointer(dec)).Frescaler, lines_left)
  13187 		WebPMultARGBRows(tls, in, in_stride, (*WebPRescaler)(unsafe.Pointer((*VP8LDecoder)(unsafe.Pointer(dec)).Frescaler)).Fsrc_width, needed_lines, 0)
  13188 		lines_imported = WebPRescalerImport(tls, (*VP8LDecoder)(unsafe.Pointer(dec)).Frescaler, lines_left, in, in_stride)
  13189 		num_lines_in = num_lines_in + lines_imported
  13190 		in = in + uintptr(needed_lines*in_stride)
  13191 		y_pos = y_pos + ExportYUVA(tls, dec, y_pos)
  13192 	}
  13193 	return y_pos
  13194 }
  13195 
  13196 func EmitRowsYUVA(tls *libc.TLS, dec uintptr, in uintptr, in_stride int32, mb_w int32, num_rows int32) (r int32) {
  13197 	var y_pos, v1 int32
  13198 	_, _ = y_pos, v1
  13199 	y_pos = (*VP8LDecoder)(unsafe.Pointer(dec)).Flast_out_row
  13200 	for {
  13201 		v1 = num_rows
  13202 		num_rows = num_rows - 1
  13203 		if !(v1 > 0) {
  13204 			break
  13205 		}
  13206 		ConvertToYUVA(tls, in, mb_w, y_pos, (*VP8LDecoder)(unsafe.Pointer(dec)).Foutput)
  13207 		in = in + uintptr(in_stride)
  13208 		y_pos = y_pos + 1
  13209 	}
  13210 	return y_pos
  13211 }
  13212 
  13213 //------------------------------------------------------------------------------
  13214 // Cropping.
  13215 
  13216 // C documentation
  13217 //
  13218 //	// Sets io->mb_y, io->mb_h & io->mb_w according to start row, end row and
  13219 //	// crop options. Also updates the input data pointer, so that it points to the
  13220 //	// start of the cropped window. Note that pixels are in ARGB format even if
  13221 //	// 'in_data' is uint8_t*.
  13222 //	// Returns true if the crop window is not empty.
  13223 func SetCropWindow(tls *libc.TLS, io uintptr, y_start int32, y_end int32, in_data uintptr, pixel_stride int32) (r int32) {
  13224 	var delta int32
  13225 	_ = delta
  13226 	if y_end > (*VP8Io)(unsafe.Pointer(io)).Fcrop_bottom {
  13227 		y_end = (*VP8Io)(unsafe.Pointer(io)).Fcrop_bottom // make sure we don't overflow on last row.
  13228 	}
  13229 	if y_start < (*VP8Io)(unsafe.Pointer(io)).Fcrop_top {
  13230 		delta = (*VP8Io)(unsafe.Pointer(io)).Fcrop_top - y_start
  13231 		y_start = (*VP8Io)(unsafe.Pointer(io)).Fcrop_top
  13232 		**(**uintptr)(__ccgo_up(in_data)) += uintptr(delta * pixel_stride)
  13233 	}
  13234 	if y_start >= y_end {
  13235 		return 0
  13236 	} // Crop window is empty.
  13237 	**(**uintptr)(__ccgo_up(in_data)) += uintptr(uint64((*VP8Io)(unsafe.Pointer(io)).Fcrop_left) * uint64(4))
  13238 	(*VP8Io)(unsafe.Pointer(io)).Fmb_y = y_start - (*VP8Io)(unsafe.Pointer(io)).Fcrop_top
  13239 	(*VP8Io)(unsafe.Pointer(io)).Fmb_w = (*VP8Io)(unsafe.Pointer(io)).Fcrop_right - (*VP8Io)(unsafe.Pointer(io)).Fcrop_left
  13240 	(*VP8Io)(unsafe.Pointer(io)).Fmb_h = y_end - y_start
  13241 	return int32(1) // Non-empty crop window.
  13242 }
  13243 
  13244 //------------------------------------------------------------------------------
  13245 
  13246 func GetMetaIndex(tls *libc.TLS, image uintptr, xsize int32, bits int32, x int32, y int32) (r int32) {
  13247 	if bits == 0 {
  13248 		return 0
  13249 	}
  13250 	return int32(**(**uint32_t)(__ccgo_up(image + uintptr(xsize*(y>>bits)+x>>bits)*4)))
  13251 }
  13252 
  13253 func GetHtreeGroupForPos(tls *libc.TLS, hdr uintptr, x int32, y int32) (r uintptr) {
  13254 	var meta_index int32
  13255 	_ = meta_index
  13256 	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)
  13257 	return (*VP8LMetadata)(unsafe.Pointer(hdr)).Fhtree_groups + uintptr(meta_index)*568
  13258 }
  13259 
  13260 //------------------------------------------------------------------------------
  13261 // Main loop, with custom row-processing function
  13262 
  13263 type ProcessRowsFunc = uintptr
  13264 
  13265 func ApplyInverseTransforms(tls *libc.TLS, dec uintptr, start_row int32, num_rows int32, rows uintptr) {
  13266 	var cache_pixs, end_row, n, v1 int32
  13267 	var rows_in, rows_out, transform uintptr
  13268 	_, _, _, _, _, _, _ = cache_pixs, end_row, n, rows_in, rows_out, transform, v1
  13269 	n = (*VP8LDecoder)(unsafe.Pointer(dec)).Fnext_transform
  13270 	cache_pixs = (*VP8LDecoder)(unsafe.Pointer(dec)).Fwidth * num_rows
  13271 	end_row = start_row + num_rows
  13272 	rows_in = rows
  13273 	rows_out = (*VP8LDecoder)(unsafe.Pointer(dec)).Fargb_cache
  13274 	// Inverse transforms.
  13275 	for {
  13276 		v1 = n
  13277 		n = n - 1
  13278 		if !(v1 > 0) {
  13279 			break
  13280 		}
  13281 		transform = dec + 280 + uintptr(n)*24
  13282 		VP8LInverseTransform(tls, transform, start_row, end_row, rows_in, rows_out)
  13283 		rows_in = rows_out
  13284 	}
  13285 	if rows_in != rows_out {
  13286 		// No transform called, hence just copy.
  13287 		libc.Xmemcpy(tls, rows_out, rows_in, uint64(cache_pixs)*uint64(4))
  13288 	}
  13289 }
  13290 
  13291 // C documentation
  13292 //
  13293 //	// Processes (transforms, scales & color-converts) the rows decoded after the
  13294 //	// last call.
  13295 func ProcessRows(tls *libc.TLS, dec uintptr, row int32) {
  13296 	bp := tls.Alloc(16)
  13297 	defer tls.Free(16)
  13298 	var buf, io, output, rgba, rows uintptr
  13299 	var in_stride, num_rows, num_rows_out, v1, v3 int32
  13300 	var _ /* rows_data at bp+0 */ uintptr
  13301 	_, _, _, _, _, _, _, _, _, _ = buf, in_stride, io, num_rows, num_rows_out, output, rgba, rows, v1, v3
  13302 	rows = (*VP8LDecoder)(unsafe.Pointer(dec)).Fpixels + uintptr((*VP8LDecoder)(unsafe.Pointer(dec)).Fwidth*(*VP8LDecoder)(unsafe.Pointer(dec)).Flast_row)*4
  13303 	num_rows = row - (*VP8LDecoder)(unsafe.Pointer(dec)).Flast_row
  13304 	// We can't process more than NUM_ARGB_CACHE_ROWS at a time (that's the size
  13305 	// of argb_cache), but we currently don't need more than that.
  13306 	if num_rows > 0 { // Emit output.
  13307 		io = (*VP8LDecoder)(unsafe.Pointer(dec)).Fio
  13308 		**(**uintptr)(__ccgo_up(bp)) = (*VP8LDecoder)(unsafe.Pointer(dec)).Fargb_cache
  13309 		in_stride = int32(uint64((*VP8Io)(unsafe.Pointer(io)).Fwidth) * uint64(4)) // in unit of RGBA
  13310 		ApplyInverseTransforms(tls, dec, (*VP8LDecoder)(unsafe.Pointer(dec)).Flast_row, num_rows, rows)
  13311 		if !(SetCropWindow(tls, io, (*VP8LDecoder)(unsafe.Pointer(dec)).Flast_row, row, bp, in_stride) != 0) {
  13312 			// Nothing to output (this time).
  13313 		} else {
  13314 			output = (*VP8LDecoder)(unsafe.Pointer(dec)).Foutput
  13315 			v1 = libc.BoolInt32((*WebPDecBuffer)(unsafe.Pointer(output)).Fcolorspace < int32(MODE_YUV))
  13316 			goto _2
  13317 		_2:
  13318 			if v1 != 0 { // convert to RGBA
  13319 				buf = output + 16
  13320 				rgba = (*WebPRGBABuffer)(unsafe.Pointer(buf)).Frgba + uintptr(int64((*VP8LDecoder)(unsafe.Pointer(dec)).Flast_out_row)*int64((*WebPRGBABuffer)(unsafe.Pointer(buf)).Fstride))
  13321 				if (*VP8Io)(unsafe.Pointer(io)).Fuse_scaling != 0 {
  13322 					v3 = EmitRescaledRowsRGBA(tls, dec, **(**uintptr)(__ccgo_up(bp)), in_stride, (*VP8Io)(unsafe.Pointer(io)).Fmb_h, rgba, (*WebPRGBABuffer)(unsafe.Pointer(buf)).Fstride)
  13323 				} else {
  13324 					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)
  13325 				}
  13326 				num_rows_out = v3
  13327 				// Update 'last_out_row'.
  13328 				**(**int32)(__ccgo_up(dec + 148)) += num_rows_out
  13329 			} else { // convert to YUVA
  13330 				if (*VP8Io)(unsafe.Pointer(io)).Fuse_scaling != 0 {
  13331 					v1 = EmitRescaledRowsYUVA(tls, dec, **(**uintptr)(__ccgo_up(bp)), in_stride, (*VP8Io)(unsafe.Pointer(io)).Fmb_h)
  13332 				} else {
  13333 					v1 = EmitRowsYUVA(tls, dec, **(**uintptr)(__ccgo_up(bp)), in_stride, (*VP8Io)(unsafe.Pointer(io)).Fmb_w, (*VP8Io)(unsafe.Pointer(io)).Fmb_h)
  13334 				}
  13335 				(*VP8LDecoder)(unsafe.Pointer(dec)).Flast_out_row = v1
  13336 			}
  13337 		}
  13338 	}
  13339 	// Update 'last_row'.
  13340 	(*VP8LDecoder)(unsafe.Pointer(dec)).Flast_row = row
  13341 }
  13342 
  13343 // C documentation
  13344 //
  13345 //	// Row-processing for the special case when alpha data contains only one
  13346 //	// transform (color indexing), and trivial non-green literals.
  13347 func Is8bOptimizable(tls *libc.TLS, hdr uintptr) (r int32) {
  13348 	var htrees uintptr
  13349 	var i int32
  13350 	_, _ = htrees, i
  13351 	if (*VP8LMetadata)(unsafe.Pointer(hdr)).Fcolor_cache_size > 0 {
  13352 		return 0
  13353 	}
  13354 	// When the Huffman tree contains only one symbol, we can skip the
  13355 	// call to ReadSymbol() for red/blue/alpha channels.
  13356 	i = 0
  13357 	for {
  13358 		if !(i < (*VP8LMetadata)(unsafe.Pointer(hdr)).Fnum_htree_groups) {
  13359 			break
  13360 		}
  13361 		htrees = (*VP8LMetadata)(unsafe.Pointer(hdr)).Fhtree_groups + uintptr(i)*568
  13362 		if int32((**(**HuffmanCode)(__ccgo_up(**(**uintptr)(__ccgo_up(htrees + uintptr(RED)*8))))).Fbits) > 0 {
  13363 			return 0
  13364 		}
  13365 		if int32((**(**HuffmanCode)(__ccgo_up(**(**uintptr)(__ccgo_up(htrees + uintptr(BLUE)*8))))).Fbits) > 0 {
  13366 			return 0
  13367 		}
  13368 		if int32((**(**HuffmanCode)(__ccgo_up(**(**uintptr)(__ccgo_up(htrees + uintptr(ALPHA)*8))))).Fbits) > 0 {
  13369 			return 0
  13370 		}
  13371 		goto _1
  13372 	_1:
  13373 		;
  13374 		i = i + 1
  13375 	}
  13376 	return int32(1)
  13377 }
  13378 
  13379 func AlphaApplyFilter(tls *libc.TLS, alph_dec uintptr, first_row int32, last_row int32, out uintptr, stride int32) {
  13380 	var prev_line uintptr
  13381 	var y int32
  13382 	_, _ = prev_line, y
  13383 	if (*ALPHDecoder)(unsafe.Pointer(alph_dec)).Ffilter != int32(WEBP_FILTER_NONE) {
  13384 		prev_line = (*ALPHDecoder)(unsafe.Pointer(alph_dec)).Fprev_line
  13385 		y = first_row
  13386 		for {
  13387 			if !(y < last_row) {
  13388 				break
  13389 			}
  13390 			(*(*func(*libc.TLS, uintptr, uintptr, uintptr, int32))(unsafe.Pointer(&struct{ uintptr }{WebPUnfilters[(*ALPHDecoder)(unsafe.Pointer(alph_dec)).Ffilter]})))(tls, prev_line, out, out, stride)
  13391 			prev_line = out
  13392 			out = out + uintptr(stride)
  13393 			goto _1
  13394 		_1:
  13395 			;
  13396 			y = y + 1
  13397 		}
  13398 		(*ALPHDecoder)(unsafe.Pointer(alph_dec)).Fprev_line = prev_line
  13399 	}
  13400 }
  13401 
  13402 func ExtractPalettedAlphaRows(tls *libc.TLS, dec uintptr, last_row int32) {
  13403 	var alph_dec, in, out, transform uintptr
  13404 	var first_row, top_row, width, v1, v2 int32
  13405 	_, _, _, _, _, _, _, _, _ = alph_dec, first_row, in, out, top_row, transform, width, v1, v2
  13406 	// For vertical and gradient filtering, we need to decode the part above the
  13407 	// crop_top row, in order to have the correct spatial predictors.
  13408 	alph_dec = (*VP8Io)(unsafe.Pointer((*VP8LDecoder)(unsafe.Pointer(dec)).Fio)).Fopaque
  13409 	if (*ALPHDecoder)(unsafe.Pointer(alph_dec)).Ffilter == int32(WEBP_FILTER_NONE) || (*ALPHDecoder)(unsafe.Pointer(alph_dec)).Ffilter == int32(WEBP_FILTER_HORIZONTAL) {
  13410 		v1 = (*VP8Io)(unsafe.Pointer((*VP8LDecoder)(unsafe.Pointer(dec)).Fio)).Fcrop_top
  13411 	} else {
  13412 		v1 = (*VP8LDecoder)(unsafe.Pointer(dec)).Flast_row
  13413 	}
  13414 	top_row = v1
  13415 	if (*VP8LDecoder)(unsafe.Pointer(dec)).Flast_row < top_row {
  13416 		v2 = top_row
  13417 	} else {
  13418 		v2 = (*VP8LDecoder)(unsafe.Pointer(dec)).Flast_row
  13419 	}
  13420 	first_row = v2
  13421 	if last_row > first_row {
  13422 		// Special method for paletted alpha data. We only process the cropped area.
  13423 		width = (*VP8Io)(unsafe.Pointer((*VP8LDecoder)(unsafe.Pointer(dec)).Fio)).Fwidth
  13424 		out = (*ALPHDecoder)(unsafe.Pointer(alph_dec)).Foutput + uintptr(width*first_row)
  13425 		in = (*VP8LDecoder)(unsafe.Pointer(dec)).Fpixels + uintptr((*VP8LDecoder)(unsafe.Pointer(dec)).Fwidth*first_row)
  13426 		transform = dec + 280
  13427 		VP8LColorIndexInverseTransformAlpha(tls, transform, first_row, last_row, in, out)
  13428 		AlphaApplyFilter(tls, alph_dec, first_row, last_row, out, width)
  13429 	}
  13430 	v1 = last_row
  13431 	(*VP8LDecoder)(unsafe.Pointer(dec)).Flast_out_row = v1
  13432 	(*VP8LDecoder)(unsafe.Pointer(dec)).Flast_row = v1
  13433 }
  13434 
  13435 //------------------------------------------------------------------------------
  13436 // Helper functions for fast pattern copy (8b and 32b)
  13437 
  13438 // C documentation
  13439 //
  13440 //	// cyclic rotation of pattern word
  13441 func Rotate8b(tls *libc.TLS, V uint32_t) (r uint32_t) {
  13442 	return V&uint32(0xff)<<int32(24) | V>>libc.Int32FromInt32(8)
  13443 }
  13444 
  13445 // C documentation
  13446 //
  13447 //	// copy 1, 2 or 4-bytes pattern
  13448 func CopySmallPattern8b(tls *libc.TLS, src uintptr, dst uintptr, length int32, pattern uint32_t) {
  13449 	var i int32
  13450 	var v1, v2 uintptr
  13451 	_, _, _ = i, v1, v2
  13452 	// align 'dst' to 4-bytes boundary. Adjust the pattern along the way.
  13453 	for uint64(dst)&uint64(3) != 0 {
  13454 		v1 = dst
  13455 		dst = dst + 1
  13456 		v2 = src
  13457 		src = src + 1
  13458 		**(**uint8_t)(__ccgo_up(v1)) = **(**uint8_t)(__ccgo_up(v2))
  13459 		pattern = Rotate8b(tls, pattern)
  13460 		length = length - 1
  13461 	}
  13462 	// Copy the pattern 4 bytes at a time.
  13463 	i = 0
  13464 	for {
  13465 		if !(i < length>>int32(2)) {
  13466 			break
  13467 		}
  13468 		**(**uint32_t)(__ccgo_up(dst + uintptr(i)*4)) = pattern
  13469 		goto _3
  13470 	_3:
  13471 		;
  13472 		i = i + 1
  13473 	}
  13474 	// Finish with left-overs. 'pattern' is still correctly positioned,
  13475 	// so no Rotate8b() call is needed.
  13476 	i = i << int32(2)
  13477 	for {
  13478 		if !(i < length) {
  13479 			break
  13480 		}
  13481 		**(**uint8_t)(__ccgo_up(dst + uintptr(i))) = **(**uint8_t)(__ccgo_up(src + uintptr(i)))
  13482 		goto _4
  13483 	_4:
  13484 		;
  13485 		i = i + 1
  13486 	}
  13487 }
  13488 
  13489 func CopyBlock8b(tls *libc.TLS, dst uintptr, dist int32, length int32) {
  13490 	bp := tls.Alloc(16)
  13491 	defer tls.Free(16)
  13492 	var i int32
  13493 	var src uintptr
  13494 	var _ /* pattern at bp+0 */ uint32_t
  13495 	_, _ = i, src
  13496 	src = dst - uintptr(dist)
  13497 	if length >= int32(8) {
  13498 		**(**uint32_t)(__ccgo_up(bp)) = uint32(0)
  13499 		switch dist {
  13500 		case int32(1):
  13501 			**(**uint32_t)(__ccgo_up(bp)) = uint32(**(**uint8_t)(__ccgo_up(src)))
  13502 			**(**uint32_t)(__ccgo_up(bp)) = uint32(0x01010101) * **(**uint32_t)(__ccgo_up(bp))
  13503 		case int32(2):
  13504 			libc.Xmemcpy(tls, bp, src, uint64(2))
  13505 			**(**uint32_t)(__ccgo_up(bp)) = uint32(0x00010001) * **(**uint32_t)(__ccgo_up(bp))
  13506 		case int32(4):
  13507 			libc.Xmemcpy(tls, bp, src, uint64(4))
  13508 		default:
  13509 			goto Copy
  13510 		}
  13511 		CopySmallPattern8b(tls, src, dst, length, **(**uint32_t)(__ccgo_up(bp)))
  13512 		return
  13513 	}
  13514 	goto Copy
  13515 Copy:
  13516 	;
  13517 	if dist >= length { // no overlap -> use memcpy()
  13518 		libc.Xmemcpy(tls, dst, src, uint64(length)*uint64(1))
  13519 	} else {
  13520 		i = 0
  13521 		for {
  13522 			if !(i < length) {
  13523 				break
  13524 			}
  13525 			**(**uint8_t)(__ccgo_up(dst + uintptr(i))) = **(**uint8_t)(__ccgo_up(src + uintptr(i)))
  13526 			goto _1
  13527 		_1:
  13528 			;
  13529 			i = i + 1
  13530 		}
  13531 	}
  13532 }
  13533 
  13534 // C documentation
  13535 //
  13536 //	// copy pattern of 1 or 2 uint32_t's
  13537 func CopySmallPattern32b(tls *libc.TLS, src uintptr, dst uintptr, length int32, pattern uint64_t) {
  13538 	var i int32
  13539 	var v1, v2 uintptr
  13540 	_, _, _ = i, v1, v2
  13541 	if uint64(dst)&uint64(4) != 0 { // Align 'dst' to 8-bytes boundary.
  13542 		v1 = dst
  13543 		dst += 4
  13544 		v2 = src
  13545 		src += 4
  13546 		**(**uint32_t)(__ccgo_up(v1)) = **(**uint32_t)(__ccgo_up(v2))
  13547 		pattern = pattern>>libc.Int32FromInt32(32) | pattern<<libc.Int32FromInt32(32)
  13548 		length = length - 1
  13549 	}
  13550 	i = 0
  13551 	for {
  13552 		if !(i < length>>int32(1)) {
  13553 			break
  13554 		}
  13555 		**(**uint64_t)(__ccgo_up(dst + uintptr(i)*8)) = pattern // Copy the pattern 8 bytes at a time.
  13556 		goto _3
  13557 	_3:
  13558 		;
  13559 		i = i + 1
  13560 	}
  13561 	if length&int32(1) != 0 { // Finish with left-over.
  13562 		**(**uint32_t)(__ccgo_up(dst + uintptr(i<<int32(1))*4)) = **(**uint32_t)(__ccgo_up(src + uintptr(i<<int32(1))*4))
  13563 	}
  13564 }
  13565 
  13566 func CopyBlock32b(tls *libc.TLS, dst uintptr, dist int32, length int32) {
  13567 	bp := tls.Alloc(16)
  13568 	defer tls.Free(16)
  13569 	var i int32
  13570 	var src uintptr
  13571 	var _ /* pattern at bp+0 */ uint64_t
  13572 	_, _ = i, src
  13573 	src = dst - uintptr(dist)*4
  13574 	if dist <= int32(2) && length >= int32(4) && uint64(dst)&uint64(3) == uint64(0) {
  13575 		if dist == int32(1) {
  13576 			**(**uint64_t)(__ccgo_up(bp)) = uint64(**(**uint32_t)(__ccgo_up(src)))
  13577 			**(**uint64_t)(__ccgo_up(bp)) = **(**uint64_t)(__ccgo_up(bp)) | **(**uint64_t)(__ccgo_up(bp))<<int32(32)
  13578 		} else {
  13579 			libc.Xmemcpy(tls, bp, src, uint64(8))
  13580 		}
  13581 		CopySmallPattern32b(tls, src, dst, length, **(**uint64_t)(__ccgo_up(bp)))
  13582 	} else {
  13583 		if dist >= length { // no overlap
  13584 			libc.Xmemcpy(tls, dst, src, uint64(length)*uint64(4))
  13585 		} else {
  13586 			i = 0
  13587 			for {
  13588 				if !(i < length) {
  13589 					break
  13590 				}
  13591 				**(**uint32_t)(__ccgo_up(dst + uintptr(i)*4)) = **(**uint32_t)(__ccgo_up(src + uintptr(i)*4))
  13592 				goto _1
  13593 			_1:
  13594 				;
  13595 				i = i + 1
  13596 			}
  13597 		}
  13598 	}
  13599 }
  13600 
  13601 //------------------------------------------------------------------------------
  13602 
  13603 func DecodeAlphaData(tls *libc.TLS, dec uintptr, data uintptr, width int32, height int32, last_row int32) (r int32) {
  13604 	var br2, hdr, htree_group, v1 uintptr
  13605 	var code, col, dist, dist_code, dist_symbol, end, last, len_code_limit, length, length_sym, mask, ok, pos, row, v5 int32
  13606 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  13607 	ok = int32(1)
  13608 	row = (*VP8LDecoder)(unsafe.Pointer(dec)).Flast_pixel / width
  13609 	col = (*VP8LDecoder)(unsafe.Pointer(dec)).Flast_pixel % width
  13610 	br2 = dec + 40
  13611 	hdr = dec + 152
  13612 	pos = (*VP8LDecoder)(unsafe.Pointer(dec)).Flast_pixel // current position
  13613 	end = width * height                                  // End of data
  13614 	last = width * last_row                               // Last pixel to decode
  13615 	len_code_limit = libc.Int32FromInt32(NUM_LITERAL_CODES) + libc.Int32FromInt32(NUM_LENGTH_CODES)
  13616 	mask = (*VP8LMetadata)(unsafe.Pointer(hdr)).Fhuffman_mask
  13617 	if pos < last {
  13618 		v1 = GetHtreeGroupForPos(tls, hdr, col, row)
  13619 	} else {
  13620 		v1 = libc.UintptrFromInt32(0)
  13621 	}
  13622 	htree_group = v1
  13623 	for !((*VP8LBitReader)(unsafe.Pointer(br2)).Feos != 0) && pos < last {
  13624 		// Only update when changing tile.
  13625 		if col&mask == 0 {
  13626 			htree_group = GetHtreeGroupForPos(tls, hdr, col, row)
  13627 		}
  13628 		v1 = br2
  13629 		if (*VP8LBitReader)(unsafe.Pointer(v1)).Fbit_pos >= libc.Int32FromInt32(VP8L_WBITS) {
  13630 			VP8LDoFillBitWindow(tls, v1)
  13631 		}
  13632 		code = ReadSymbol(tls, **(**uintptr)(__ccgo_up(htree_group + uintptr(GREEN)*8)), br2)
  13633 		if code < int32(NUM_LITERAL_CODES) { // Literal
  13634 			**(**uint8_t)(__ccgo_up(data + uintptr(pos))) = uint8(code)
  13635 			pos = pos + 1
  13636 			col = col + 1
  13637 			if col >= width {
  13638 				col = 0
  13639 				row = row + 1
  13640 				if row <= last_row && row%int32(NUM_ARGB_CACHE_ROWS) == 0 {
  13641 					ExtractPalettedAlphaRows(tls, dec, row)
  13642 				}
  13643 			}
  13644 		} else {
  13645 			if code < len_code_limit {
  13646 				length_sym = code - int32(NUM_LITERAL_CODES)
  13647 				length = GetCopyLength(tls, length_sym, br2)
  13648 				dist_symbol = ReadSymbol(tls, **(**uintptr)(__ccgo_up(htree_group + uintptr(DIST)*8)), br2)
  13649 				v1 = br2
  13650 				if (*VP8LBitReader)(unsafe.Pointer(v1)).Fbit_pos >= libc.Int32FromInt32(VP8L_WBITS) {
  13651 					VP8LDoFillBitWindow(tls, v1)
  13652 				}
  13653 				dist_code = GetCopyDistance(tls, dist_symbol, br2)
  13654 				dist = PlaneCodeToDistance(tls, width, dist_code)
  13655 				if pos >= dist && end-pos >= length {
  13656 					CopyBlock8b(tls, data+uintptr(pos), dist, length)
  13657 				} else {
  13658 					ok = 0
  13659 					goto End
  13660 				}
  13661 				pos = pos + length
  13662 				col = col + length
  13663 				for col >= width {
  13664 					col = col - width
  13665 					row = row + 1
  13666 					if row <= last_row && row%int32(NUM_ARGB_CACHE_ROWS) == 0 {
  13667 						ExtractPalettedAlphaRows(tls, dec, row)
  13668 					}
  13669 				}
  13670 				if pos < last && col&mask != 0 {
  13671 					htree_group = GetHtreeGroupForPos(tls, hdr, col, row)
  13672 				}
  13673 			} else { // Not reached
  13674 				ok = 0
  13675 				goto End
  13676 			}
  13677 		}
  13678 		v1 = br2
  13679 		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))
  13680 		goto _6
  13681 	_6:
  13682 		(*VP8LBitReader)(unsafe.Pointer(br2)).Feos = v5
  13683 	}
  13684 	// Process the remaining rows corresponding to last row-block.
  13685 	if row > last_row {
  13686 		v5 = last_row
  13687 	} else {
  13688 		v5 = row
  13689 	}
  13690 	ExtractPalettedAlphaRows(tls, dec, v5)
  13691 	goto End
  13692 End:
  13693 	;
  13694 	v1 = br2
  13695 	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))
  13696 	goto _10
  13697 _10:
  13698 	(*VP8LBitReader)(unsafe.Pointer(br2)).Feos = v5
  13699 	if !(ok != 0) || (*VP8LBitReader)(unsafe.Pointer(br2)).Feos != 0 && pos < end {
  13700 		if (*VP8LBitReader)(unsafe.Pointer(br2)).Feos != 0 {
  13701 			v5 = int32(VP8_STATUS_SUSPENDED)
  13702 		} else {
  13703 			v5 = int32(VP8_STATUS_BITSTREAM_ERROR)
  13704 		}
  13705 		return VP8LSetError(tls, dec, v5)
  13706 	}
  13707 	(*VP8LDecoder)(unsafe.Pointer(dec)).Flast_pixel = pos
  13708 	return ok
  13709 }
  13710 
  13711 func SaveState(tls *libc.TLS, dec uintptr, last_pixel int32) {
  13712 	(*VP8LDecoder)(unsafe.Pointer(dec)).Fsaved_br = (*VP8LDecoder)(unsafe.Pointer(dec)).Fbr
  13713 	(*VP8LDecoder)(unsafe.Pointer(dec)).Fsaved_last_pixel = last_pixel
  13714 	if (*VP8LDecoder)(unsafe.Pointer(dec)).Fhdr.Fcolor_cache_size > 0 {
  13715 		VP8LColorCacheCopy(tls, dec+152+8, dec+152+24)
  13716 	}
  13717 }
  13718 
  13719 func RestoreState(tls *libc.TLS, dec uintptr) {
  13720 	(*VP8LDecoder)(unsafe.Pointer(dec)).Fstatus = int32(VP8_STATUS_SUSPENDED)
  13721 	(*VP8LDecoder)(unsafe.Pointer(dec)).Fbr = (*VP8LDecoder)(unsafe.Pointer(dec)).Fsaved_br
  13722 	(*VP8LDecoder)(unsafe.Pointer(dec)).Flast_pixel = (*VP8LDecoder)(unsafe.Pointer(dec)).Fsaved_last_pixel
  13723 	if (*VP8LDecoder)(unsafe.Pointer(dec)).Fhdr.Fcolor_cache_size > 0 {
  13724 		VP8LColorCacheCopy(tls, dec+152+24, dec+152+8)
  13725 	}
  13726 }
  13727 
  13728 func DecodeImageData(tls *libc.TLS, dec uintptr, data uintptr, width int32, height int32, last_row int32, __ccgo_fp_process_func ProcessRowsFunc) (r int32) {
  13729 	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
  13730 	var br2, color_cache, hdr, htree_group, last_cached, src, src_end, src_last, v2, v3 uintptr
  13731 	var v21 uint32_t
  13732 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  13733 	row = (*VP8LDecoder)(unsafe.Pointer(dec)).Flast_pixel / width
  13734 	col = (*VP8LDecoder)(unsafe.Pointer(dec)).Flast_pixel % width
  13735 	br2 = dec + 40
  13736 	hdr = dec + 152
  13737 	src = data + uintptr((*VP8LDecoder)(unsafe.Pointer(dec)).Flast_pixel)*4
  13738 	last_cached = src
  13739 	src_end = data + uintptr(width*height)*4    // End of data
  13740 	src_last = data + uintptr(width*last_row)*4 // Last pixel to decode
  13741 	len_code_limit = libc.Int32FromInt32(NUM_LITERAL_CODES) + libc.Int32FromInt32(NUM_LENGTH_CODES)
  13742 	color_cache_limit = len_code_limit + (*VP8LMetadata)(unsafe.Pointer(hdr)).Fcolor_cache_size
  13743 	if (*VP8LDecoder)(unsafe.Pointer(dec)).Fincremental != 0 {
  13744 		v1 = row
  13745 	} else {
  13746 		v1 = libc.Int32FromInt32(1) << libc.Int32FromInt32(24)
  13747 	}
  13748 	next_sync_row = v1
  13749 	if (*VP8LMetadata)(unsafe.Pointer(hdr)).Fcolor_cache_size > 0 {
  13750 		v2 = hdr + 8
  13751 	} else {
  13752 		v2 = libc.UintptrFromInt32(0)
  13753 	}
  13754 	color_cache = v2
  13755 	mask = (*VP8LMetadata)(unsafe.Pointer(hdr)).Fhuffman_mask
  13756 	if src < src_last {
  13757 		v3 = GetHtreeGroupForPos(tls, hdr, col, row)
  13758 	} else {
  13759 		v3 = libc.UintptrFromInt32(0)
  13760 	}
  13761 	htree_group = v3
  13762 _5:
  13763 	;
  13764 	if !(src < src_last) {
  13765 		goto _4
  13766 	}
  13767 	if row >= next_sync_row {
  13768 		SaveState(tls, dec, int32((int64(src)-int64(data))/4))
  13769 		next_sync_row = row + int32(SYNC_EVERY_N_ROWS)
  13770 	}
  13771 	// Only update when changing tile. Note we could use this test:
  13772 	// if "((((prev_col ^ col) | prev_row ^ row)) > mask)" -> tile changed
  13773 	// but that's actually slower and needs storing the previous col/row.
  13774 	if col&mask == 0 {
  13775 		htree_group = GetHtreeGroupForPos(tls, hdr, col, row)
  13776 	}
  13777 	if (*HTreeGroup)(unsafe.Pointer(htree_group)).Fis_trivial_code != 0 {
  13778 		**(**uint32_t)(__ccgo_up(src)) = (*HTreeGroup)(unsafe.Pointer(htree_group)).Fliteral_arb
  13779 		goto AdvanceByOne
  13780 	}
  13781 	v2 = br2
  13782 	if (*VP8LBitReader)(unsafe.Pointer(v2)).Fbit_pos >= libc.Int32FromInt32(VP8L_WBITS) {
  13783 		VP8LDoFillBitWindow(tls, v2)
  13784 	}
  13785 	if (*HTreeGroup)(unsafe.Pointer(htree_group)).Fuse_packed_table != 0 {
  13786 		code = ReadPackedSymbols(tls, htree_group, br2, src)
  13787 		v2 = br2
  13788 		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))
  13789 		goto _9
  13790 	_9:
  13791 		if v1 != 0 {
  13792 			goto _4
  13793 		}
  13794 		if code == PACKED_NON_LITERAL_CODE {
  13795 			goto AdvanceByOne
  13796 		}
  13797 	} else {
  13798 		code = ReadSymbol(tls, **(**uintptr)(__ccgo_up(htree_group + uintptr(GREEN)*8)), br2)
  13799 	}
  13800 	v2 = br2
  13801 	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))
  13802 	goto _12
  13803 _12:
  13804 	if v1 != 0 {
  13805 		goto _4
  13806 	}
  13807 	if !(code < int32(NUM_LITERAL_CODES)) {
  13808 		goto _13
  13809 	} // Literal
  13810 	if (*HTreeGroup)(unsafe.Pointer(htree_group)).Fis_trivial_literal != 0 {
  13811 		**(**uint32_t)(__ccgo_up(src)) = (*HTreeGroup)(unsafe.Pointer(htree_group)).Fliteral_arb | uint32(code<<libc.Int32FromInt32(8))
  13812 	} else {
  13813 		red = ReadSymbol(tls, **(**uintptr)(__ccgo_up(htree_group + uintptr(RED)*8)), br2)
  13814 		v2 = br2
  13815 		if (*VP8LBitReader)(unsafe.Pointer(v2)).Fbit_pos >= libc.Int32FromInt32(VP8L_WBITS) {
  13816 			VP8LDoFillBitWindow(tls, v2)
  13817 		}
  13818 		blue = ReadSymbol(tls, **(**uintptr)(__ccgo_up(htree_group + uintptr(BLUE)*8)), br2)
  13819 		alpha = ReadSymbol(tls, **(**uintptr)(__ccgo_up(htree_group + uintptr(ALPHA)*8)), br2)
  13820 		v2 = br2
  13821 		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))
  13822 		goto _18
  13823 	_18:
  13824 		if v1 != 0 {
  13825 			goto _4
  13826 		}
  13827 		**(**uint32_t)(__ccgo_up(src)) = uint32(alpha)<<libc.Int32FromInt32(24) | uint32(red<<libc.Int32FromInt32(16)) | uint32(code<<libc.Int32FromInt32(8)) | uint32(blue)
  13828 	}
  13829 	goto AdvanceByOne
  13830 AdvanceByOne:
  13831 	;
  13832 	src += 4
  13833 	col = col + 1
  13834 	if col >= width {
  13835 		col = 0
  13836 		row = row + 1
  13837 		if __ccgo_fp_process_func != libc.UintptrFromInt32(0) {
  13838 			if row <= last_row && row%int32(NUM_ARGB_CACHE_ROWS) == 0 {
  13839 				(*(*func(*libc.TLS, uintptr, int32))(unsafe.Pointer(&struct{ uintptr }{__ccgo_fp_process_func})))(tls, dec, row)
  13840 			}
  13841 		}
  13842 		if color_cache != libc.UintptrFromInt32(0) {
  13843 			for last_cached < src {
  13844 				v2 = last_cached
  13845 				last_cached += 4
  13846 				v3 = color_cache
  13847 				v21 = **(**uint32_t)(__ccgo_up(v2))
  13848 				v1 = int32(v21 * kHashMul8 >> (*VP8LColorCache)(unsafe.Pointer(v3)).Fhash_shift)
  13849 				goto _23
  13850 			_23:
  13851 				key1 = v1
  13852 				**(**uint32_t)(__ccgo_up((*VP8LColorCache)(unsafe.Pointer(v3)).Fcolors + uintptr(key1)*4)) = v21
  13853 			}
  13854 		}
  13855 	}
  13856 	goto _14
  13857 _13:
  13858 	;
  13859 	if code < len_code_limit {
  13860 		length_sym = code - int32(NUM_LITERAL_CODES)
  13861 		length = GetCopyLength(tls, length_sym, br2)
  13862 		dist_symbol = ReadSymbol(tls, **(**uintptr)(__ccgo_up(htree_group + uintptr(DIST)*8)), br2)
  13863 		v2 = br2
  13864 		if (*VP8LBitReader)(unsafe.Pointer(v2)).Fbit_pos >= libc.Int32FromInt32(VP8L_WBITS) {
  13865 			VP8LDoFillBitWindow(tls, v2)
  13866 		}
  13867 		dist_code = GetCopyDistance(tls, dist_symbol, br2)
  13868 		dist = PlaneCodeToDistance(tls, width, dist_code)
  13869 		v2 = br2
  13870 		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))
  13871 		goto _27
  13872 	_27:
  13873 		if v1 != 0 {
  13874 			goto _4
  13875 		}
  13876 		if (int64(src)-int64(data))/4 < int64(dist) || (int64(src_end)-int64(src))/4 < int64(length) {
  13877 			goto Error
  13878 		} else {
  13879 			CopyBlock32b(tls, src, dist, length)
  13880 		}
  13881 		src = src + uintptr(length)*4
  13882 		col = col + length
  13883 		for col >= width {
  13884 			col = col - width
  13885 			row = row + 1
  13886 			if __ccgo_fp_process_func != libc.UintptrFromInt32(0) {
  13887 				if row <= last_row && row%int32(NUM_ARGB_CACHE_ROWS) == 0 {
  13888 					(*(*func(*libc.TLS, uintptr, int32))(unsafe.Pointer(&struct{ uintptr }{__ccgo_fp_process_func})))(tls, dec, row)
  13889 				}
  13890 			}
  13891 		}
  13892 		// Because of the check done above (before 'src' was incremented by
  13893 		// 'length'), the following holds true.
  13894 		if col&mask != 0 {
  13895 			htree_group = GetHtreeGroupForPos(tls, hdr, col, row)
  13896 		}
  13897 		if color_cache != libc.UintptrFromInt32(0) {
  13898 			for last_cached < src {
  13899 				v2 = last_cached
  13900 				last_cached += 4
  13901 				v3 = color_cache
  13902 				v21 = **(**uint32_t)(__ccgo_up(v2))
  13903 				v1 = int32(v21 * kHashMul8 >> (*VP8LColorCache)(unsafe.Pointer(v3)).Fhash_shift)
  13904 				goto _32
  13905 			_32:
  13906 				key1 = v1
  13907 				**(**uint32_t)(__ccgo_up((*VP8LColorCache)(unsafe.Pointer(v3)).Fcolors + uintptr(key1)*4)) = v21
  13908 			}
  13909 		}
  13910 	} else {
  13911 		if code < color_cache_limit { // Color cache
  13912 			key2 = code - len_code_limit
  13913 			for last_cached < src {
  13914 				v2 = last_cached
  13915 				last_cached += 4
  13916 				v3 = color_cache
  13917 				v21 = **(**uint32_t)(__ccgo_up(v2))
  13918 				v1 = int32(v21 * kHashMul8 >> (*VP8LColorCache)(unsafe.Pointer(v3)).Fhash_shift)
  13919 				goto _37
  13920 			_37:
  13921 				key1 = v1
  13922 				**(**uint32_t)(__ccgo_up((*VP8LColorCache)(unsafe.Pointer(v3)).Fcolors + uintptr(key1)*4)) = v21
  13923 			}
  13924 			v21 = **(**uint32_t)(__ccgo_up((*VP8LColorCache)(unsafe.Pointer(color_cache)).Fcolors + uintptr(uint32(key2))*4))
  13925 			goto _39
  13926 		_39:
  13927 			**(**uint32_t)(__ccgo_up(src)) = v21
  13928 			goto AdvanceByOne
  13929 		} else { // Not reached
  13930 			goto Error
  13931 		}
  13932 	}
  13933 _14:
  13934 	;
  13935 	goto _5
  13936 _4:
  13937 	;
  13938 	v2 = br2
  13939 	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))
  13940 	goto _42
  13941 _42:
  13942 	(*VP8LBitReader)(unsafe.Pointer(br2)).Feos = v1
  13943 	// In incremental decoding:
  13944 	// br->eos && src < src_last: if 'br' reached the end of the buffer and
  13945 	// 'src_last' has not been reached yet, there is not enough data. 'dec' has to
  13946 	// be reset until there is more data.
  13947 	// !br->eos && src < src_last: this cannot happen as either the buffer is
  13948 	// fully read, either enough has been read to reach 'src_last'.
  13949 	// src >= src_last: 'src_last' is reached, all is fine. 'src' can actually go
  13950 	// beyond 'src_last' in case the image is cropped and an LZ77 goes further.
  13951 	// The buffer might have been enough or there is some left. 'br->eos' does
  13952 	// not matter.
  13953 	if (*VP8LDecoder)(unsafe.Pointer(dec)).Fincremental != 0 && (*VP8LBitReader)(unsafe.Pointer(br2)).Feos != 0 && src < src_last {
  13954 		RestoreState(tls, dec)
  13955 	} else {
  13956 		if (*VP8LDecoder)(unsafe.Pointer(dec)).Fincremental != 0 && src >= src_last || !((*VP8LBitReader)(unsafe.Pointer(br2)).Feos != 0) {
  13957 			// Process the remaining rows corresponding to last row-block.
  13958 			if __ccgo_fp_process_func != libc.UintptrFromInt32(0) {
  13959 				if row > last_row {
  13960 					v1 = last_row
  13961 				} else {
  13962 					v1 = row
  13963 				}
  13964 				(*(*func(*libc.TLS, uintptr, int32))(unsafe.Pointer(&struct{ uintptr }{__ccgo_fp_process_func})))(tls, dec, v1)
  13965 			}
  13966 			(*VP8LDecoder)(unsafe.Pointer(dec)).Fstatus = int32(VP8_STATUS_OK)
  13967 			(*VP8LDecoder)(unsafe.Pointer(dec)).Flast_pixel = int32((int64(src) - int64(data)) / 4) // end-of-scan marker
  13968 		} else {
  13969 			// if not incremental, and we are past the end of buffer (eos=1), then this
  13970 			// is a real bitstream error.
  13971 			goto Error
  13972 		}
  13973 	}
  13974 	return int32(1)
  13975 	goto Error
  13976 Error:
  13977 	;
  13978 	return VP8LSetError(tls, dec, int32(VP8_STATUS_BITSTREAM_ERROR))
  13979 	return r
  13980 }
  13981 
  13982 // -----------------------------------------------------------------------------
  13983 // VP8LTransform
  13984 
  13985 func ClearTransform(tls *libc.TLS, transform uintptr) {
  13986 	WebPSafeFree(tls, (*VP8LTransform)(unsafe.Pointer(transform)).Fdata)
  13987 	(*VP8LTransform)(unsafe.Pointer(transform)).Fdata = libc.UintptrFromInt32(0)
  13988 }
  13989 
  13990 // C documentation
  13991 //
  13992 //	// For security reason, we need to remap the color map to span
  13993 //	// the total possible bundled values, and not just the num_colors.
  13994 func ExpandColorMap(tls *libc.TLS, num_colors int32, transform uintptr) (r int32) {
  13995 	var data, new_color_map, new_data uintptr
  13996 	var final_num_colors, i int32
  13997 	_, _, _, _, _ = data, final_num_colors, i, new_color_map, new_data
  13998 	final_num_colors = int32(1) << (int32(8) >> (*VP8LTransform)(unsafe.Pointer(transform)).Fbits)
  13999 	new_color_map = WebPSafeMalloc(tls, uint64(final_num_colors), uint64(4))
  14000 	if new_color_map == libc.UintptrFromInt32(0) {
  14001 		return 0
  14002 	} else {
  14003 		data = (*VP8LTransform)(unsafe.Pointer(transform)).Fdata
  14004 		new_data = new_color_map
  14005 		**(**uint32_t)(__ccgo_up(new_color_map)) = **(**uint32_t)(__ccgo_up((*VP8LTransform)(unsafe.Pointer(transform)).Fdata))
  14006 		i = int32(4)
  14007 		for {
  14008 			if !(i < int32(4)*num_colors) {
  14009 				break
  14010 			}
  14011 			// Equivalent to VP8LAddPixels(), on a byte-basis.
  14012 			**(**uint8_t)(__ccgo_up(new_data + uintptr(i))) = uint8((int32(**(**uint8_t)(__ccgo_up(data + uintptr(i)))) + int32(**(**uint8_t)(__ccgo_up(new_data + uintptr(i-int32(4)))))) & int32(0xff))
  14013 			goto _1
  14014 		_1:
  14015 			;
  14016 			i = i + 1
  14017 		}
  14018 		for {
  14019 			if !(i < int32(4)*final_num_colors) {
  14020 				break
  14021 			}
  14022 			**(**uint8_t)(__ccgo_up(new_data + uintptr(i))) = uint8(0) // black tail.
  14023 			goto _2
  14024 		_2:
  14025 			;
  14026 			i = i + 1
  14027 		}
  14028 		WebPSafeFree(tls, (*VP8LTransform)(unsafe.Pointer(transform)).Fdata)
  14029 		(*VP8LTransform)(unsafe.Pointer(transform)).Fdata = new_color_map
  14030 	}
  14031 	return int32(1)
  14032 }
  14033 
  14034 func ReadTransform(tls *libc.TLS, xsize uintptr, ysize uintptr, dec uintptr) (r int32) {
  14035 	var bits, num_colors, ok, v7, v8, v9 int32
  14036 	var br, transform uintptr
  14037 	var type1 VP8LImageTransformType
  14038 	var v1, v2, v4, v5 uint32_t
  14039 	_, _, _, _, _, _, _, _, _, _, _, _, _ = bits, br, num_colors, ok, transform, type1, v1, v2, v4, v5, v7, v8, v9
  14040 	ok = int32(1)
  14041 	br = dec + 40
  14042 	transform = dec + 280 + uintptr((*VP8LDecoder)(unsafe.Pointer(dec)).Fnext_transform)*24
  14043 	type1 = int32(VP8LReadBits(tls, br, int32(2)))
  14044 	// Each transform type can only be present once in the stream.
  14045 	if (*VP8LDecoder)(unsafe.Pointer(dec)).Ftransforms_seen&(uint32(1)<<type1) != 0 {
  14046 		return 0 // Already there, let's not accept the second same transform.
  14047 	}
  14048 	**(**uint32_t)(__ccgo_up(dec + 376)) |= uint32(1) << type1
  14049 	(*VP8LTransform)(unsafe.Pointer(transform)).Ftype1 = type1
  14050 	(*VP8LTransform)(unsafe.Pointer(transform)).Fxsize = **(**int32)(__ccgo_up(xsize))
  14051 	(*VP8LTransform)(unsafe.Pointer(transform)).Fysize = **(**int32)(__ccgo_up(ysize))
  14052 	(*VP8LTransform)(unsafe.Pointer(transform)).Fdata = libc.UintptrFromInt32(0)
  14053 	(*VP8LDecoder)(unsafe.Pointer(dec)).Fnext_transform = (*VP8LDecoder)(unsafe.Pointer(dec)).Fnext_transform + 1
  14054 	switch type1 {
  14055 	case int32(PREDICTOR_TRANSFORM):
  14056 		fallthrough
  14057 	case int32(CROSS_COLOR_TRANSFORM):
  14058 		(*VP8LTransform)(unsafe.Pointer(transform)).Fbits = int32(uint32(MIN_TRANSFORM_BITS) + VP8LReadBits(tls, br, int32(NUM_TRANSFORM_BITS)))
  14059 		v1 = uint32((*VP8LTransform)(unsafe.Pointer(transform)).Fbits)
  14060 		v2 = (uint32((*VP8LTransform)(unsafe.Pointer(transform)).Fxsize) + uint32(libc.Int32FromInt32(1)<<v1) - uint32(1)) >> v1
  14061 		goto _3
  14062 	_3:
  14063 		v4 = uint32((*VP8LTransform)(unsafe.Pointer(transform)).Fbits)
  14064 		v5 = (uint32((*VP8LTransform)(unsafe.Pointer(transform)).Fysize) + uint32(libc.Int32FromInt32(1)<<v4) - uint32(1)) >> v4
  14065 		goto _6
  14066 	_6:
  14067 		ok = DecodeImageStream(tls, int32(v2), int32(v5), 0, dec, transform+16)
  14068 	case int32(COLOR_INDEXING_TRANSFORM):
  14069 		num_colors = int32(VP8LReadBits(tls, br, int32(8)) + uint32(1))
  14070 		if num_colors > int32(16) {
  14071 			v7 = 0
  14072 		} else {
  14073 			if num_colors > int32(4) {
  14074 				v8 = int32(1)
  14075 			} else {
  14076 				if num_colors > int32(2) {
  14077 					v9 = int32(2)
  14078 				} else {
  14079 					v9 = int32(3)
  14080 				}
  14081 				v8 = v9
  14082 			}
  14083 			v7 = v8
  14084 		}
  14085 		bits = v7
  14086 		v1 = uint32(bits)
  14087 		v2 = (uint32((*VP8LTransform)(unsafe.Pointer(transform)).Fxsize) + uint32(libc.Int32FromInt32(1)<<v1) - uint32(1)) >> v1
  14088 		goto _12
  14089 	_12:
  14090 		**(**int32)(__ccgo_up(xsize)) = int32(v2)
  14091 		(*VP8LTransform)(unsafe.Pointer(transform)).Fbits = bits
  14092 		ok = DecodeImageStream(tls, num_colors, int32(1), 0, dec, transform+16)
  14093 		if ok != 0 && !(ExpandColorMap(tls, num_colors, transform) != 0) {
  14094 			return VP8LSetError(tls, dec, int32(VP8_STATUS_OUT_OF_MEMORY))
  14095 		}
  14096 	case int32(SUBTRACT_GREEN_TRANSFORM):
  14097 	default:
  14098 		// can't happen
  14099 		break
  14100 	}
  14101 	return ok
  14102 }
  14103 
  14104 // -----------------------------------------------------------------------------
  14105 // VP8LMetadata
  14106 
  14107 func InitMetadata(tls *libc.TLS, hdr uintptr) {
  14108 	libc.Xmemset(tls, hdr, 0, uint64(120))
  14109 }
  14110 
  14111 func ClearMetadata(tls *libc.TLS, hdr uintptr) {
  14112 	WebPSafeFree(tls, (*VP8LMetadata)(unsafe.Pointer(hdr)).Fhuffman_image)
  14113 	VP8LHuffmanTablesDeallocate(tls, hdr+80)
  14114 	VP8LHtreeGroupsFree(tls, (*VP8LMetadata)(unsafe.Pointer(hdr)).Fhtree_groups)
  14115 	VP8LColorCacheClear(tls, hdr+8)
  14116 	VP8LColorCacheClear(tls, hdr+24)
  14117 	InitMetadata(tls, hdr)
  14118 }
  14119 
  14120 // -----------------------------------------------------------------------------
  14121 // VP8LDecoder
  14122 
  14123 func VP8LNew(tls *libc.TLS) (r uintptr) {
  14124 	var dec uintptr
  14125 	_ = dec
  14126 	dec = WebPSafeCalloc(tls, uint64(1), uint64(400))
  14127 	if dec == libc.UintptrFromInt32(0) {
  14128 		return libc.UintptrFromInt32(0)
  14129 	}
  14130 	(*VP8LDecoder)(unsafe.Pointer(dec)).Fstatus = int32(VP8_STATUS_OK)
  14131 	(*VP8LDecoder)(unsafe.Pointer(dec)).Fstate = int32(READ_DIM)
  14132 	VP8LDspInit(tls) // Init critical function pointers.
  14133 	return dec
  14134 }
  14135 
  14136 // C documentation
  14137 //
  14138 //	// Resets the decoder in its initial state, reclaiming memory.
  14139 //	// Preserves the dec->status value.
  14140 func VP8LClear(tls *libc.TLS, dec uintptr) {
  14141 	var i int32
  14142 	_ = i
  14143 	if dec == libc.UintptrFromInt32(0) {
  14144 		return
  14145 	}
  14146 	ClearMetadata(tls, dec+152)
  14147 	WebPSafeFree(tls, (*VP8LDecoder)(unsafe.Pointer(dec)).Fpixels)
  14148 	(*VP8LDecoder)(unsafe.Pointer(dec)).Fpixels = libc.UintptrFromInt32(0)
  14149 	i = 0
  14150 	for {
  14151 		if !(i < (*VP8LDecoder)(unsafe.Pointer(dec)).Fnext_transform) {
  14152 			break
  14153 		}
  14154 		ClearTransform(tls, dec+280+uintptr(i)*24)
  14155 		goto _1
  14156 	_1:
  14157 		;
  14158 		i = i + 1
  14159 	}
  14160 	(*VP8LDecoder)(unsafe.Pointer(dec)).Fnext_transform = 0
  14161 	(*VP8LDecoder)(unsafe.Pointer(dec)).Ftransforms_seen = uint32(0)
  14162 	WebPSafeFree(tls, (*VP8LDecoder)(unsafe.Pointer(dec)).Frescaler_memory)
  14163 	(*VP8LDecoder)(unsafe.Pointer(dec)).Frescaler_memory = libc.UintptrFromInt32(0)
  14164 	(*VP8LDecoder)(unsafe.Pointer(dec)).Foutput = libc.UintptrFromInt32(0) // leave no trace behind
  14165 }
  14166 
  14167 func VP8LDelete(tls *libc.TLS, dec uintptr) {
  14168 	if dec != libc.UintptrFromInt32(0) {
  14169 		VP8LClear(tls, dec)
  14170 		WebPSafeFree(tls, dec)
  14171 	}
  14172 }
  14173 
  14174 func UpdateDecoder(tls *libc.TLS, dec uintptr, width int32, height int32) {
  14175 	var hdr uintptr
  14176 	var num_bits, v4 int32
  14177 	var v1, v2 uint32_t
  14178 	_, _, _, _, _ = hdr, num_bits, v1, v2, v4
  14179 	hdr = dec + 152
  14180 	num_bits = (*VP8LMetadata)(unsafe.Pointer(hdr)).Fhuffman_subsample_bits
  14181 	(*VP8LDecoder)(unsafe.Pointer(dec)).Fwidth = width
  14182 	(*VP8LDecoder)(unsafe.Pointer(dec)).Fheight = height
  14183 	v1 = uint32(num_bits)
  14184 	v2 = (uint32(width) + uint32(libc.Int32FromInt32(1)<<v1) - uint32(1)) >> v1
  14185 	goto _3
  14186 _3:
  14187 	(*VP8LMetadata)(unsafe.Pointer(hdr)).Fhuffman_xsize = int32(v2)
  14188 	if num_bits == 0 {
  14189 		v4 = ^libc.Int32FromInt32(0)
  14190 	} else {
  14191 		v4 = int32(1)<<num_bits - int32(1)
  14192 	}
  14193 	(*VP8LMetadata)(unsafe.Pointer(hdr)).Fhuffman_mask = v4
  14194 }
  14195 
  14196 func DecodeImageStream(tls *libc.TLS, xsize int32, ysize int32, is_level0 int32, dec uintptr, decoded_data uintptr) (r int32) {
  14197 	bp := tls.Alloc(16)
  14198 	defer tls.Free(16)
  14199 	var br, data, hdr uintptr
  14200 	var color_cache_bits, ok int32
  14201 	var total_size uint64_t
  14202 	var _ /* transform_xsize at bp+0 */ int32
  14203 	var _ /* transform_ysize at bp+4 */ int32
  14204 	_, _, _, _, _, _ = br, color_cache_bits, data, hdr, ok, total_size
  14205 	ok = int32(1)
  14206 	**(**int32)(__ccgo_up(bp)) = xsize
  14207 	**(**int32)(__ccgo_up(bp + 4)) = ysize
  14208 	br = dec + 40
  14209 	hdr = dec + 152
  14210 	data = libc.UintptrFromInt32(0)
  14211 	color_cache_bits = 0
  14212 	// Read the transforms (may recurse).
  14213 	if is_level0 != 0 {
  14214 		for ok != 0 && VP8LReadBits(tls, br, int32(1)) != 0 {
  14215 			ok = ReadTransform(tls, bp, bp+4, dec)
  14216 		}
  14217 	}
  14218 	// Color cache
  14219 	if ok != 0 && VP8LReadBits(tls, br, int32(1)) != 0 {
  14220 		color_cache_bits = int32(VP8LReadBits(tls, br, int32(4)))
  14221 		ok = libc.BoolInt32(color_cache_bits >= int32(1) && color_cache_bits <= int32(MAX_CACHE_BITS))
  14222 		if !(ok != 0) {
  14223 			VP8LSetError(tls, dec, int32(VP8_STATUS_BITSTREAM_ERROR))
  14224 			goto End
  14225 		}
  14226 	}
  14227 	// Read the Huffman codes (may recurse).
  14228 	ok = libc.BoolInt32(ok != 0 && ReadHuffmanCodes(tls, dec, **(**int32)(__ccgo_up(bp)), **(**int32)(__ccgo_up(bp + 4)), color_cache_bits, is_level0) != 0)
  14229 	if !(ok != 0) {
  14230 		VP8LSetError(tls, dec, int32(VP8_STATUS_BITSTREAM_ERROR))
  14231 		goto End
  14232 	}
  14233 	// Finish setting up the color-cache
  14234 	if color_cache_bits > 0 {
  14235 		(*VP8LMetadata)(unsafe.Pointer(hdr)).Fcolor_cache_size = int32(1) << color_cache_bits
  14236 		if !(VP8LColorCacheInit(tls, hdr+8, color_cache_bits) != 0) {
  14237 			ok = VP8LSetError(tls, dec, int32(VP8_STATUS_OUT_OF_MEMORY))
  14238 			goto End
  14239 		}
  14240 	} else {
  14241 		(*VP8LMetadata)(unsafe.Pointer(hdr)).Fcolor_cache_size = 0
  14242 	}
  14243 	UpdateDecoder(tls, dec, **(**int32)(__ccgo_up(bp)), **(**int32)(__ccgo_up(bp + 4)))
  14244 	if is_level0 != 0 { // level 0 complete
  14245 		(*VP8LDecoder)(unsafe.Pointer(dec)).Fstate = int32(READ_HDR)
  14246 		goto End
  14247 	}
  14248 	total_size = uint64(**(**int32)(__ccgo_up(bp))) * uint64(**(**int32)(__ccgo_up(bp + 4)))
  14249 	data = WebPSafeMalloc(tls, total_size, uint64(4))
  14250 	if data == libc.UintptrFromInt32(0) {
  14251 		ok = VP8LSetError(tls, dec, int32(VP8_STATUS_OUT_OF_MEMORY))
  14252 		goto End
  14253 	}
  14254 	// Use the Huffman trees to decode the LZ77 encoded data.
  14255 	ok = DecodeImageData(tls, dec, data, **(**int32)(__ccgo_up(bp)), **(**int32)(__ccgo_up(bp + 4)), **(**int32)(__ccgo_up(bp + 4)), libc.UintptrFromInt32(0))
  14256 	ok = libc.BoolInt32(ok != 0 && !((*VP8LBitReader)(unsafe.Pointer(br)).Feos != 0))
  14257 	goto End
  14258 End:
  14259 	;
  14260 	if !(ok != 0) {
  14261 		WebPSafeFree(tls, data)
  14262 		ClearMetadata(tls, hdr)
  14263 	} else {
  14264 		if decoded_data != libc.UintptrFromInt32(0) {
  14265 			**(**uintptr)(__ccgo_up(decoded_data)) = data
  14266 		} else {
  14267 			// We allocate image data in this function only for transforms. At level 0
  14268 			// (that is: not the transforms), we shouldn't have allocated anything.
  14269 		}
  14270 		(*VP8LDecoder)(unsafe.Pointer(dec)).Flast_pixel = 0 // Reset for future DECODE_DATA_FUNC() calls.
  14271 		if !(is_level0 != 0) {
  14272 			ClearMetadata(tls, hdr)
  14273 		} // Clean up temporary data behind.
  14274 	}
  14275 	return ok
  14276 }
  14277 
  14278 // C documentation
  14279 //
  14280 //	//------------------------------------------------------------------------------
  14281 //	// Allocate internal buffers dec->pixels and dec->argb_cache.
  14282 func AllocateInternalBuffers32b(tls *libc.TLS, dec uintptr, final_width int32) (r int32) {
  14283 	var cache_pixels, cache_top_pixels, num_pixels, total_num_pixels uint64_t
  14284 	_, _, _, _ = cache_pixels, cache_top_pixels, num_pixels, total_num_pixels
  14285 	num_pixels = uint64((*VP8LDecoder)(unsafe.Pointer(dec)).Fwidth) * uint64((*VP8LDecoder)(unsafe.Pointer(dec)).Fheight)
  14286 	// Scratch buffer corresponding to top-prediction row for transforming the
  14287 	// first row in the row-blocks. Not needed for paletted alpha.
  14288 	cache_top_pixels = uint64(uint16(final_width))
  14289 	// Scratch buffer for temporary BGRA storage. Not needed for paletted alpha.
  14290 	cache_pixels = uint64(final_width) * uint64(NUM_ARGB_CACHE_ROWS)
  14291 	total_num_pixels = num_pixels + cache_top_pixels + cache_pixels
  14292 	(*VP8LDecoder)(unsafe.Pointer(dec)).Fpixels = WebPSafeMalloc(tls, total_num_pixels, uint64(4))
  14293 	if (*VP8LDecoder)(unsafe.Pointer(dec)).Fpixels == libc.UintptrFromInt32(0) {
  14294 		(*VP8LDecoder)(unsafe.Pointer(dec)).Fargb_cache = libc.UintptrFromInt32(0) // for soundness
  14295 		return VP8LSetError(tls, dec, int32(VP8_STATUS_OUT_OF_MEMORY))
  14296 	}
  14297 	(*VP8LDecoder)(unsafe.Pointer(dec)).Fargb_cache = (*VP8LDecoder)(unsafe.Pointer(dec)).Fpixels + uintptr(num_pixels)*4 + uintptr(cache_top_pixels)*4
  14298 	return int32(1)
  14299 }
  14300 
  14301 func AllocateInternalBuffers8b(tls *libc.TLS, dec uintptr) (r int32) {
  14302 	var total_num_pixels uint64_t
  14303 	_ = total_num_pixels
  14304 	total_num_pixels = uint64((*VP8LDecoder)(unsafe.Pointer(dec)).Fwidth) * uint64((*VP8LDecoder)(unsafe.Pointer(dec)).Fheight)
  14305 	(*VP8LDecoder)(unsafe.Pointer(dec)).Fargb_cache = libc.UintptrFromInt32(0) // for soundness
  14306 	(*VP8LDecoder)(unsafe.Pointer(dec)).Fpixels = WebPSafeMalloc(tls, total_num_pixels, uint64(1))
  14307 	if (*VP8LDecoder)(unsafe.Pointer(dec)).Fpixels == libc.UintptrFromInt32(0) {
  14308 		return VP8LSetError(tls, dec, int32(VP8_STATUS_OUT_OF_MEMORY))
  14309 	}
  14310 	return int32(1)
  14311 }
  14312 
  14313 //------------------------------------------------------------------------------
  14314 
  14315 // C documentation
  14316 //
  14317 //	// Special row-processing that only stores the alpha data.
  14318 func ExtractAlphaRows(tls *libc.TLS, dec uintptr, last_row int32) {
  14319 	var alph_dec, dst, in, output, src uintptr
  14320 	var cache_pixs, cur_row, num_rows, num_rows_to_process, width, v1 int32
  14321 	_, _, _, _, _, _, _, _, _, _, _ = alph_dec, cache_pixs, cur_row, dst, in, num_rows, num_rows_to_process, output, src, width, v1
  14322 	cur_row = (*VP8LDecoder)(unsafe.Pointer(dec)).Flast_row
  14323 	num_rows = last_row - cur_row
  14324 	in = (*VP8LDecoder)(unsafe.Pointer(dec)).Fpixels + uintptr((*VP8LDecoder)(unsafe.Pointer(dec)).Fwidth*cur_row)*4
  14325 	for num_rows > 0 {
  14326 		if num_rows > int32(NUM_ARGB_CACHE_ROWS) {
  14327 			v1 = int32(NUM_ARGB_CACHE_ROWS)
  14328 		} else {
  14329 			v1 = num_rows
  14330 		}
  14331 		num_rows_to_process = v1
  14332 		// Extract alpha (which is stored in the green plane).
  14333 		alph_dec = (*VP8Io)(unsafe.Pointer((*VP8LDecoder)(unsafe.Pointer(dec)).Fio)).Fopaque
  14334 		output = (*ALPHDecoder)(unsafe.Pointer(alph_dec)).Foutput
  14335 		width = (*VP8Io)(unsafe.Pointer((*VP8LDecoder)(unsafe.Pointer(dec)).Fio)).Fwidth // the final width (!= dec->width)
  14336 		cache_pixs = width * num_rows_to_process
  14337 		dst = output + uintptr(width*cur_row)
  14338 		src = (*VP8LDecoder)(unsafe.Pointer(dec)).Fargb_cache
  14339 		ApplyInverseTransforms(tls, dec, cur_row, num_rows_to_process, in)
  14340 		(*(*func(*libc.TLS, uintptr, uintptr, int32))(unsafe.Pointer(&struct{ uintptr }{WebPExtractGreen})))(tls, src, dst, cache_pixs)
  14341 		AlphaApplyFilter(tls, alph_dec, cur_row, cur_row+num_rows_to_process, dst, width)
  14342 		num_rows = num_rows - num_rows_to_process
  14343 		in = in + uintptr(num_rows_to_process*(*VP8LDecoder)(unsafe.Pointer(dec)).Fwidth)*4
  14344 		cur_row = cur_row + num_rows_to_process
  14345 	}
  14346 	v1 = last_row
  14347 	(*VP8LDecoder)(unsafe.Pointer(dec)).Flast_out_row = v1
  14348 	(*VP8LDecoder)(unsafe.Pointer(dec)).Flast_row = v1
  14349 }
  14350 
  14351 func VP8LDecodeAlphaHeader(tls *libc.TLS, alph_dec uintptr, data uintptr, data_size size_t) (r int32) {
  14352 	var dec uintptr
  14353 	var ok int32
  14354 	_, _ = dec, ok
  14355 	ok = 0
  14356 	dec = VP8LNew(tls)
  14357 	if dec == libc.UintptrFromInt32(0) {
  14358 		return 0
  14359 	}
  14360 	(*VP8LDecoder)(unsafe.Pointer(dec)).Fwidth = (*ALPHDecoder)(unsafe.Pointer(alph_dec)).Fwidth
  14361 	(*VP8LDecoder)(unsafe.Pointer(dec)).Fheight = (*ALPHDecoder)(unsafe.Pointer(alph_dec)).Fheight
  14362 	(*VP8LDecoder)(unsafe.Pointer(dec)).Fio = alph_dec + 32
  14363 	(*VP8Io)(unsafe.Pointer((*VP8LDecoder)(unsafe.Pointer(dec)).Fio)).Fopaque = alph_dec
  14364 	(*VP8Io)(unsafe.Pointer((*VP8LDecoder)(unsafe.Pointer(dec)).Fio)).Fwidth = (*ALPHDecoder)(unsafe.Pointer(alph_dec)).Fwidth
  14365 	(*VP8Io)(unsafe.Pointer((*VP8LDecoder)(unsafe.Pointer(dec)).Fio)).Fheight = (*ALPHDecoder)(unsafe.Pointer(alph_dec)).Fheight
  14366 	(*VP8LDecoder)(unsafe.Pointer(dec)).Fstatus = int32(VP8_STATUS_OK)
  14367 	VP8LInitBitReader(tls, dec+40, data, data_size)
  14368 	if !(DecodeImageStream(tls, (*ALPHDecoder)(unsafe.Pointer(alph_dec)).Fwidth, (*ALPHDecoder)(unsafe.Pointer(alph_dec)).Fheight, int32(1), dec, libc.UintptrFromInt32(0)) != 0) {
  14369 		goto Err
  14370 	}
  14371 	// Special case: if alpha data uses only the color indexing transform and
  14372 	// doesn't use color cache (a frequent case), we will use DecodeAlphaData()
  14373 	// method that only needs allocation of 1 byte per pixel (alpha channel).
  14374 	if (*VP8LDecoder)(unsafe.Pointer(dec)).Fnext_transform == int32(1) && (**(**VP8LTransform)(__ccgo_up(dec + 280))).Ftype1 == int32(COLOR_INDEXING_TRANSFORM) && Is8bOptimizable(tls, dec+152) != 0 {
  14375 		(*ALPHDecoder)(unsafe.Pointer(alph_dec)).Fuse_8b_decode = int32(1)
  14376 		ok = AllocateInternalBuffers8b(tls, dec)
  14377 	} else {
  14378 		// Allocate internal buffers (note that dec->width may have changed here).
  14379 		(*ALPHDecoder)(unsafe.Pointer(alph_dec)).Fuse_8b_decode = 0
  14380 		ok = AllocateInternalBuffers32b(tls, dec, (*ALPHDecoder)(unsafe.Pointer(alph_dec)).Fwidth)
  14381 	}
  14382 	if !(ok != 0) {
  14383 		goto Err
  14384 	}
  14385 	// Only set here, once we are sure it is valid (to avoid thread races).
  14386 	(*ALPHDecoder)(unsafe.Pointer(alph_dec)).Fvp8l_dec = dec
  14387 	return int32(1)
  14388 	goto Err
  14389 Err:
  14390 	;
  14391 	VP8LDelete(tls, dec)
  14392 	return 0
  14393 }
  14394 
  14395 func VP8LDecodeAlphaImageStream(tls *libc.TLS, alph_dec uintptr, last_row int32) (r int32) {
  14396 	var dec uintptr
  14397 	var v1 int32
  14398 	_, _ = dec, v1
  14399 	dec = (*ALPHDecoder)(unsafe.Pointer(alph_dec)).Fvp8l_dec
  14400 	if (*VP8LDecoder)(unsafe.Pointer(dec)).Flast_row >= last_row {
  14401 		return int32(1) // done
  14402 	}
  14403 	if !((*ALPHDecoder)(unsafe.Pointer(alph_dec)).Fuse_8b_decode != 0) {
  14404 		WebPInitAlphaProcessing(tls)
  14405 	}
  14406 	// Decode (with special row processing).
  14407 	if (*ALPHDecoder)(unsafe.Pointer(alph_dec)).Fuse_8b_decode != 0 {
  14408 		v1 = DecodeAlphaData(tls, dec, (*VP8LDecoder)(unsafe.Pointer(dec)).Fpixels, (*VP8LDecoder)(unsafe.Pointer(dec)).Fwidth, (*VP8LDecoder)(unsafe.Pointer(dec)).Fheight, last_row)
  14409 	} else {
  14410 		v1 = DecodeImageData(tls, dec, (*VP8LDecoder)(unsafe.Pointer(dec)).Fpixels, (*VP8LDecoder)(unsafe.Pointer(dec)).Fwidth, (*VP8LDecoder)(unsafe.Pointer(dec)).Fheight, last_row, __ccgo_fp(ExtractAlphaRows))
  14411 	}
  14412 	return v1
  14413 }
  14414 
  14415 //------------------------------------------------------------------------------
  14416 
  14417 func VP8LDecodeHeader(tls *libc.TLS, dec uintptr, io uintptr) (r int32) {
  14418 	bp := tls.Alloc(16)
  14419 	defer tls.Free(16)
  14420 	var _ /* has_alpha at bp+8 */ int32
  14421 	var _ /* height at bp+4 */ int32
  14422 	var _ /* width at bp+0 */ int32
  14423 	if dec == libc.UintptrFromInt32(0) {
  14424 		return 0
  14425 	}
  14426 	if io == libc.UintptrFromInt32(0) {
  14427 		return VP8LSetError(tls, dec, int32(VP8_STATUS_INVALID_PARAM))
  14428 	}
  14429 	(*VP8LDecoder)(unsafe.Pointer(dec)).Fio = io
  14430 	(*VP8LDecoder)(unsafe.Pointer(dec)).Fstatus = int32(VP8_STATUS_OK)
  14431 	VP8LInitBitReader(tls, dec+40, (*VP8Io)(unsafe.Pointer(io)).Fdata, (*VP8Io)(unsafe.Pointer(io)).Fdata_size)
  14432 	if !(ReadImageInfo(tls, dec+40, bp, bp+4, bp+8) != 0) {
  14433 		VP8LSetError(tls, dec, int32(VP8_STATUS_BITSTREAM_ERROR))
  14434 		goto Error
  14435 	}
  14436 	(*VP8LDecoder)(unsafe.Pointer(dec)).Fstate = int32(READ_DIM)
  14437 	(*VP8Io)(unsafe.Pointer(io)).Fwidth = **(**int32)(__ccgo_up(bp))
  14438 	(*VP8Io)(unsafe.Pointer(io)).Fheight = **(**int32)(__ccgo_up(bp + 4))
  14439 	if !(DecodeImageStream(tls, **(**int32)(__ccgo_up(bp)), **(**int32)(__ccgo_up(bp + 4)), int32(1), dec, libc.UintptrFromInt32(0)) != 0) {
  14440 		goto Error
  14441 	}
  14442 	return int32(1)
  14443 	goto Error
  14444 Error:
  14445 	;
  14446 	VP8LClear(tls, dec)
  14447 	return 0
  14448 }
  14449 
  14450 func VP8LDecodeImage(tls *libc.TLS, dec uintptr) (r int32) {
  14451 	var io, params uintptr
  14452 	var v1 WEBP_CSP_MODE1
  14453 	var v2 int32
  14454 	var v4 bool
  14455 	_, _, _, _, _ = io, params, v1, v2, v4
  14456 	io = libc.UintptrFromInt32(0)
  14457 	params = libc.UintptrFromInt32(0)
  14458 	if dec == libc.UintptrFromInt32(0) {
  14459 		return 0
  14460 	}
  14461 	io = (*VP8LDecoder)(unsafe.Pointer(dec)).Fio
  14462 	params = (*VP8Io)(unsafe.Pointer(io)).Fopaque
  14463 	// Initialization.
  14464 	if (*VP8LDecoder)(unsafe.Pointer(dec)).Fstate != int32(READ_DATA) {
  14465 		(*VP8LDecoder)(unsafe.Pointer(dec)).Foutput = (*WebPDecParams)(unsafe.Pointer(params)).Foutput
  14466 		if !(WebPIoInitFromOptions(tls, (*WebPDecParams)(unsafe.Pointer(params)).Foptions, io, int32(MODE_BGRA)) != 0) {
  14467 			VP8LSetError(tls, dec, int32(VP8_STATUS_INVALID_PARAM))
  14468 			goto Err
  14469 		}
  14470 		if !(AllocateInternalBuffers32b(tls, dec, (*VP8Io)(unsafe.Pointer(io)).Fwidth) != 0) {
  14471 			goto Err
  14472 		}
  14473 		if (*VP8Io)(unsafe.Pointer(io)).Fuse_scaling != 0 && !(AllocateAndInitRescaler(tls, dec, io) != 0) {
  14474 			goto Err
  14475 		}
  14476 		if v4 = (*VP8Io)(unsafe.Pointer(io)).Fuse_scaling != 0; !v4 {
  14477 			v1 = (*WebPDecBuffer)(unsafe.Pointer((*VP8LDecoder)(unsafe.Pointer(dec)).Foutput)).Fcolorspace
  14478 			v2 = libc.BoolInt32(v1 == int32(MODE_rgbA) || v1 == int32(MODE_bgrA) || v1 == int32(MODE_Argb) || v1 == int32(MODE_rgbA_4444))
  14479 			goto _3
  14480 		_3:
  14481 		}
  14482 		if v4 || v2 != 0 {
  14483 			// need the alpha-multiply functions for premultiplied output or rescaling
  14484 			WebPInitAlphaProcessing(tls)
  14485 		}
  14486 		v2 = libc.BoolInt32((*WebPDecBuffer)(unsafe.Pointer((*VP8LDecoder)(unsafe.Pointer(dec)).Foutput)).Fcolorspace < int32(MODE_YUV))
  14487 		goto _6
  14488 	_6:
  14489 		if !(v2 != 0) {
  14490 			WebPInitConvertARGBToYUV(tls)
  14491 			if (*(*WebPYUVABuffer)(unsafe.Pointer((*VP8LDecoder)(unsafe.Pointer(dec)).Foutput + 16))).Fa != libc.UintptrFromInt32(0) {
  14492 				WebPInitAlphaProcessing(tls)
  14493 			}
  14494 		}
  14495 		if (*VP8LDecoder)(unsafe.Pointer(dec)).Fincremental != 0 {
  14496 			if (*VP8LDecoder)(unsafe.Pointer(dec)).Fhdr.Fcolor_cache_size > 0 && (*VP8LDecoder)(unsafe.Pointer(dec)).Fhdr.Fsaved_color_cache.Fcolors == libc.UintptrFromInt32(0) {
  14497 				if !(VP8LColorCacheInit(tls, dec+152+24, (*VP8LDecoder)(unsafe.Pointer(dec)).Fhdr.Fcolor_cache.Fhash_bits) != 0) {
  14498 					VP8LSetError(tls, dec, int32(VP8_STATUS_OUT_OF_MEMORY))
  14499 					goto Err
  14500 				}
  14501 			}
  14502 		}
  14503 		(*VP8LDecoder)(unsafe.Pointer(dec)).Fstate = int32(READ_DATA)
  14504 	}
  14505 	// Decode.
  14506 	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) {
  14507 		goto Err
  14508 	}
  14509 	(*WebPDecParams)(unsafe.Pointer(params)).Flast_y = (*VP8LDecoder)(unsafe.Pointer(dec)).Flast_out_row
  14510 	return int32(1)
  14511 	goto Err
  14512 Err:
  14513 	;
  14514 	VP8LClear(tls, dec)
  14515 	return 0
  14516 }
  14517 
  14518 const VP8L_MAGIC_BYTE2 = 0x2f
  14519 
  14520 var kHashMul9 = uint32(0x1e35a7bd)
  14521 
  14522 type WebPData = struct {
  14523 	Fbytes uintptr
  14524 	Fsize  size_t
  14525 }
  14526 
  14527 type WebPFeatureFlags1 = int32
  14528 
  14529 type WebPFeatureFlags = int32
  14530 
  14531 const ANIMATION_FLAG = 2
  14532 const XMP_FLAG = 4
  14533 const EXIF_FLAG = 8
  14534 const ALPHA_FLAG = 16
  14535 const ICCP_FLAG = 32
  14536 const ALL_VALID_FLAGS = 62
  14537 
  14538 type WebPMuxAnimDispose1 = int32
  14539 
  14540 type WebPMuxAnimDispose = int32
  14541 
  14542 const WEBP_MUX_DISPOSE_NONE = 0
  14543 const WEBP_MUX_DISPOSE_BACKGROUND = 1
  14544 
  14545 type WebPMuxAnimBlend1 = int32
  14546 
  14547 type WebPMuxAnimBlend = int32
  14548 
  14549 const WEBP_MUX_BLEND = 0
  14550 const WEBP_MUX_NO_BLEND = 1
  14551 
  14552 // Copyright 2010 Google Inc. All Rights Reserved.
  14553 //
  14554 // Use of this source code is governed by a BSD-style license
  14555 // that can be found in the COPYING file in the root of the source
  14556 // tree. An additional intellectual property rights grant can be found
  14557 // in the file PATENTS. All contributing project authors may
  14558 // be found in the AUTHORS file in the root of the source tree.
  14559 // -----------------------------------------------------------------------------
  14560 //
  14561 //  Common types + memory wrappers
  14562 //
  14563 // Author: Skal (pascal.massimino@gmail.com)
  14564 
  14565 //------------------------------------------------------------------------------
  14566 // RIFF layout is:
  14567 //   Offset  tag
  14568 //   0...3   "RIFF" 4-byte tag
  14569 //   4...7   size of image data (including metadata) starting at offset 8
  14570 //   8...11  "WEBP"   our form-type signature
  14571 // The RIFF container (12 bytes) is followed by appropriate chunks:
  14572 //   12..15  "VP8 ": 4-bytes tags, signaling the use of VP8 video format
  14573 //   16..19  size of the raw VP8 image data, starting at offset 20
  14574 //   20....  the VP8 bytes
  14575 // Or,
  14576 //   12..15  "VP8L": 4-bytes tags, signaling the use of VP8L lossless format
  14577 //   16..19  size of the raw VP8L image data, starting at offset 20
  14578 //   20....  the VP8L bytes
  14579 // Or,
  14580 //   12..15  "VP8X": 4-bytes tags, describing the extended-VP8 chunk.
  14581 //   16..19  size of the VP8X chunk starting at offset 20.
  14582 //   20..23  VP8X flags bit-map corresponding to the chunk-types present.
  14583 //   24..26  Width of the Canvas Image.
  14584 //   27..29  Height of the Canvas Image.
  14585 // There can be extra chunks after the "VP8X" chunk (ICCP, ANMF, VP8, VP8L,
  14586 // XMP, EXIF  ...)
  14587 // All sizes are in little-endian order.
  14588 // Note: chunk data size must be padded to multiple of 2 when written.
  14589 
  14590 // C documentation
  14591 //
  14592 //	// Validates the RIFF container (if detected) and skips over it.
  14593 //	// If a RIFF container is detected, returns:
  14594 //	//     VP8_STATUS_BITSTREAM_ERROR for invalid header,
  14595 //	//     VP8_STATUS_NOT_ENOUGH_DATA for truncated data if have_all_data is true,
  14596 //	// and VP8_STATUS_OK otherwise.
  14597 //	// In case there are not enough bytes (partial RIFF container), return 0 for
  14598 //	// *riff_size. Else return the RIFF size extracted from the header.
  14599 func ParseRIFF(tls *libc.TLS, data2 uintptr, data_size uintptr, have_all_data int32, riff_size uintptr) (r VP8StatusCode1) {
  14600 	var size, v2 uint32_t
  14601 	var v1, v4, v7 uintptr
  14602 	var v5, v8 int32
  14603 	_, _, _, _, _, _, _ = size, v1, v2, v4, v5, v7, v8
  14604 	**(**size_t)(__ccgo_up(riff_size)) = uint64(0) // Default: no RIFF present.
  14605 	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) {
  14606 		if libc.Xmemcmp(tls, **(**uintptr)(__ccgo_up(data2))+uintptr(8), __ccgo_ts+569, uint64(TAG_SIZE)) != 0 {
  14607 			return int32(VP8_STATUS_BITSTREAM_ERROR) // Wrong image file signature.
  14608 		} else {
  14609 			v1 = **(**uintptr)(__ccgo_up(data2)) + uintptr(TAG_SIZE)
  14610 			v4 = v1
  14611 			v5 = int32(**(**uint8_t)(__ccgo_up(v4)))<<libc.Int32FromInt32(0) | int32(**(**uint8_t)(__ccgo_up(v4 + 1)))<<int32(8)
  14612 			goto _6
  14613 		_6:
  14614 			v7 = v1 + uintptr(2)
  14615 			v8 = int32(**(**uint8_t)(__ccgo_up(v7)))<<libc.Int32FromInt32(0) | int32(**(**uint8_t)(__ccgo_up(v7 + 1)))<<int32(8)
  14616 			goto _9
  14617 		_9:
  14618 			v2 = uint32(v5) | uint32(v8)<<libc.Int32FromInt32(16)
  14619 			goto _3
  14620 		_3:
  14621 			size = v2
  14622 			// Check that we have at least one chunk (i.e "WEBP" + "VP8?nnnn").
  14623 			if size < uint32(libc.Int32FromInt32(TAG_SIZE)+libc.Int32FromInt32(CHUNK_HEADER_SIZE)) {
  14624 				return int32(VP8_STATUS_BITSTREAM_ERROR)
  14625 			}
  14626 			if size > ^libc.Uint32FromUint32(0)-libc.Uint32FromInt32(CHUNK_HEADER_SIZE)-libc.Uint32FromInt32(1) {
  14627 				return int32(VP8_STATUS_BITSTREAM_ERROR)
  14628 			}
  14629 			if have_all_data != 0 && uint64(size) > **(**size_t)(__ccgo_up(data_size))-uint64(CHUNK_HEADER_SIZE) {
  14630 				return int32(VP8_STATUS_NOT_ENOUGH_DATA) // Truncated bitstream.
  14631 			}
  14632 			// We have a RIFF container. Skip it.
  14633 			**(**size_t)(__ccgo_up(riff_size)) = uint64(size)
  14634 			**(**uintptr)(__ccgo_up(data2)) += uintptr(RIFF_HEADER_SIZE)
  14635 			**(**size_t)(__ccgo_up(data_size)) -= uint64(RIFF_HEADER_SIZE)
  14636 		}
  14637 	}
  14638 	return int32(VP8_STATUS_OK)
  14639 }
  14640 
  14641 // C documentation
  14642 //
  14643 //	// Validates the VP8X header and skips over it.
  14644 //	// Returns VP8_STATUS_BITSTREAM_ERROR for invalid VP8X header,
  14645 //	//         VP8_STATUS_NOT_ENOUGH_DATA in case of insufficient data, and
  14646 //	//         VP8_STATUS_OK otherwise.
  14647 //	// If a VP8X chunk is found, found_vp8x is set to true and *width_ptr,
  14648 //	// *height_ptr and *flags_ptr are set to the corresponding values extracted
  14649 //	// from the VP8X chunk.
  14650 func ParseVP8X(tls *libc.TLS, data3 uintptr, data_size uintptr, found_vp8x uintptr, width_ptr uintptr, height_ptr uintptr, flags_ptr uintptr) (r VP8StatusCode1) {
  14651 	var chunk_size, flags, vp8x_size, v2 uint32_t
  14652 	var height, width, v5, v8 int32
  14653 	var v1, v4, v7 uintptr
  14654 	_, _, _, _, _, _, _, _, _, _, _ = chunk_size, flags, height, vp8x_size, width, v1, v2, v4, v5, v7, v8
  14655 	vp8x_size = uint32(libc.Int32FromInt32(CHUNK_HEADER_SIZE) + libc.Int32FromInt32(VP8X_CHUNK_SIZE))
  14656 	**(**int32)(__ccgo_up(found_vp8x)) = 0
  14657 	if **(**size_t)(__ccgo_up(data_size)) < uint64(CHUNK_HEADER_SIZE) {
  14658 		return int32(VP8_STATUS_NOT_ENOUGH_DATA) // Insufficient data.
  14659 	}
  14660 	if !(libc.Xmemcmp(tls, **(**uintptr)(__ccgo_up(data3)), __ccgo_ts+574, uint64(TAG_SIZE)) != 0) {
  14661 		v1 = **(**uintptr)(__ccgo_up(data3)) + uintptr(TAG_SIZE)
  14662 		v4 = v1
  14663 		v5 = int32(**(**uint8_t)(__ccgo_up(v4)))<<libc.Int32FromInt32(0) | int32(**(**uint8_t)(__ccgo_up(v4 + 1)))<<int32(8)
  14664 		goto _6
  14665 	_6:
  14666 		v7 = v1 + uintptr(2)
  14667 		v8 = int32(**(**uint8_t)(__ccgo_up(v7)))<<libc.Int32FromInt32(0) | int32(**(**uint8_t)(__ccgo_up(v7 + 1)))<<int32(8)
  14668 		goto _9
  14669 	_9:
  14670 		v2 = uint32(v5) | uint32(v8)<<libc.Int32FromInt32(16)
  14671 		goto _3
  14672 	_3:
  14673 		chunk_size = v2
  14674 		if chunk_size != uint32(VP8X_CHUNK_SIZE) {
  14675 			return int32(VP8_STATUS_BITSTREAM_ERROR) // Wrong chunk size.
  14676 		}
  14677 		// Verify if enough data is available to validate the VP8X chunk.
  14678 		if **(**size_t)(__ccgo_up(data_size)) < uint64(vp8x_size) {
  14679 			return int32(VP8_STATUS_NOT_ENOUGH_DATA) // Insufficient data.
  14680 		}
  14681 		v1 = **(**uintptr)(__ccgo_up(data3)) + uintptr(8)
  14682 		v4 = v1
  14683 		v5 = int32(**(**uint8_t)(__ccgo_up(v4)))<<libc.Int32FromInt32(0) | int32(**(**uint8_t)(__ccgo_up(v4 + 1)))<<int32(8)
  14684 		goto _15
  14685 	_15:
  14686 		v7 = v1 + uintptr(2)
  14687 		v8 = int32(**(**uint8_t)(__ccgo_up(v7)))<<libc.Int32FromInt32(0) | int32(**(**uint8_t)(__ccgo_up(v7 + 1)))<<int32(8)
  14688 		goto _18
  14689 	_18:
  14690 		v2 = uint32(v5) | uint32(v8)<<libc.Int32FromInt32(16)
  14691 		goto _12
  14692 	_12:
  14693 		flags = v2
  14694 		v1 = **(**uintptr)(__ccgo_up(data3)) + uintptr(12)
  14695 		v4 = v1
  14696 		v8 = int32(**(**uint8_t)(__ccgo_up(v4)))<<libc.Int32FromInt32(0) | int32(**(**uint8_t)(__ccgo_up(v4 + 1)))<<int32(8)
  14697 		goto _24
  14698 	_24:
  14699 		v5 = v8 | int32(**(**uint8_t)(__ccgo_up(v1 + 2)))<<int32(16)
  14700 		goto _21
  14701 	_21:
  14702 		width = int32(1) + v5
  14703 		v1 = **(**uintptr)(__ccgo_up(data3)) + uintptr(15)
  14704 		v4 = v1
  14705 		v8 = int32(**(**uint8_t)(__ccgo_up(v4)))<<libc.Int32FromInt32(0) | int32(**(**uint8_t)(__ccgo_up(v4 + 1)))<<int32(8)
  14706 		goto _30
  14707 	_30:
  14708 		v5 = v8 | int32(**(**uint8_t)(__ccgo_up(v1 + 2)))<<int32(16)
  14709 		goto _27
  14710 	_27:
  14711 		height = int32(1) + v5
  14712 		if uint64(width)*uint64(height) >= libc.Uint64FromUint64(1)<<libc.Int32FromInt32(32) {
  14713 			return int32(VP8_STATUS_BITSTREAM_ERROR) // image is too large
  14714 		}
  14715 		if flags_ptr != libc.UintptrFromInt32(0) {
  14716 			**(**uint32_t)(__ccgo_up(flags_ptr)) = flags
  14717 		}
  14718 		if width_ptr != libc.UintptrFromInt32(0) {
  14719 			**(**int32)(__ccgo_up(width_ptr)) = width
  14720 		}
  14721 		if height_ptr != libc.UintptrFromInt32(0) {
  14722 			**(**int32)(__ccgo_up(height_ptr)) = height
  14723 		}
  14724 		// Skip over VP8X header bytes.
  14725 		**(**uintptr)(__ccgo_up(data3)) += uintptr(vp8x_size)
  14726 		**(**size_t)(__ccgo_up(data_size)) -= uint64(vp8x_size)
  14727 		**(**int32)(__ccgo_up(found_vp8x)) = int32(1)
  14728 	}
  14729 	return int32(VP8_STATUS_OK)
  14730 }
  14731 
  14732 // C documentation
  14733 //
  14734 //	// Skips to the next VP8/VP8L chunk header in the data given the size of the
  14735 //	// RIFF chunk 'riff_size'.
  14736 //	// Returns VP8_STATUS_BITSTREAM_ERROR if any invalid chunk size is encountered,
  14737 //	//         VP8_STATUS_NOT_ENOUGH_DATA in case of insufficient data, and
  14738 //	//         VP8_STATUS_OK otherwise.
  14739 //	// If an alpha chunk is found, *alpha_data and *alpha_size are set
  14740 //	// appropriately.
  14741 func ParseOptionalChunks(tls *libc.TLS, data2 uintptr, data_size uintptr, riff_size size_t, alpha_data uintptr, alpha_size uintptr) (r VP8StatusCode1) {
  14742 	var buf, v1, v4, v7 uintptr
  14743 	var buf_size size_t
  14744 	var chunk_size, disk_chunk_size, total_size, v2 uint32_t
  14745 	var v5, v8 int32
  14746 	_, _, _, _, _, _, _, _, _, _, _ = buf, buf_size, chunk_size, disk_chunk_size, total_size, v1, v2, v4, v5, v7, v8
  14747 	total_size = uint32(libc.Int32FromInt32(TAG_SIZE) + libc.Int32FromInt32(CHUNK_HEADER_SIZE) + libc.Int32FromInt32(VP8X_CHUNK_SIZE)) // data.
  14748 	buf = **(**uintptr)(__ccgo_up(data2))
  14749 	buf_size = **(**size_t)(__ccgo_up(data_size))
  14750 	**(**uintptr)(__ccgo_up(alpha_data)) = libc.UintptrFromInt32(0)
  14751 	**(**size_t)(__ccgo_up(alpha_size)) = uint64(0)
  14752 	for int32(1) != 0 { // chunk_size with padding
  14753 		**(**uintptr)(__ccgo_up(data2)) = buf
  14754 		**(**size_t)(__ccgo_up(data_size)) = buf_size
  14755 		if buf_size < uint64(CHUNK_HEADER_SIZE) { // Insufficient data.
  14756 			return int32(VP8_STATUS_NOT_ENOUGH_DATA)
  14757 		}
  14758 		v1 = buf + uintptr(TAG_SIZE)
  14759 		v4 = v1
  14760 		v5 = int32(**(**uint8_t)(__ccgo_up(v4)))<<libc.Int32FromInt32(0) | int32(**(**uint8_t)(__ccgo_up(v4 + 1)))<<int32(8)
  14761 		goto _6
  14762 	_6:
  14763 		v7 = v1 + uintptr(2)
  14764 		v8 = int32(**(**uint8_t)(__ccgo_up(v7)))<<libc.Int32FromInt32(0) | int32(**(**uint8_t)(__ccgo_up(v7 + 1)))<<int32(8)
  14765 		goto _9
  14766 	_9:
  14767 		v2 = uint32(v5) | uint32(v8)<<libc.Int32FromInt32(16)
  14768 		goto _3
  14769 	_3:
  14770 		chunk_size = v2
  14771 		if chunk_size > ^libc.Uint32FromUint32(0)-libc.Uint32FromInt32(CHUNK_HEADER_SIZE)-libc.Uint32FromInt32(1) {
  14772 			return int32(VP8_STATUS_BITSTREAM_ERROR) // Not a valid chunk size.
  14773 		}
  14774 		// For odd-sized chunk-payload, there's one byte padding at the end.
  14775 		disk_chunk_size = (uint32(CHUNK_HEADER_SIZE) + chunk_size + uint32(1)) & ^libc.Uint32FromUint32(1)
  14776 		total_size = total_size + disk_chunk_size
  14777 		// Check that total bytes skipped so far does not exceed riff_size.
  14778 		if riff_size > uint64(0) && uint64(total_size) > riff_size {
  14779 			return int32(VP8_STATUS_BITSTREAM_ERROR) // Not a valid chunk size.
  14780 		}
  14781 		// Start of a (possibly incomplete) VP8/VP8L chunk implies that we have
  14782 		// parsed all the optional chunks.
  14783 		// Note: This check must occur before the check 'buf_size < disk_chunk_size'
  14784 		// below to allow incomplete VP8/VP8L chunks.
  14785 		if !(libc.Xmemcmp(tls, buf, __ccgo_ts+579, uint64(TAG_SIZE)) != 0) || !(libc.Xmemcmp(tls, buf, __ccgo_ts+584, uint64(TAG_SIZE)) != 0) {
  14786 			return int32(VP8_STATUS_OK)
  14787 		}
  14788 		if buf_size < uint64(disk_chunk_size) { // Insufficient data.
  14789 			return int32(VP8_STATUS_NOT_ENOUGH_DATA)
  14790 		}
  14791 		if !(libc.Xmemcmp(tls, buf, __ccgo_ts+589, uint64(TAG_SIZE)) != 0) { // A valid ALPH header.
  14792 			**(**uintptr)(__ccgo_up(alpha_data)) = buf + uintptr(CHUNK_HEADER_SIZE)
  14793 			**(**size_t)(__ccgo_up(alpha_size)) = uint64(chunk_size)
  14794 		}
  14795 		// We have a full and valid chunk; skip it.
  14796 		buf = buf + uintptr(disk_chunk_size)
  14797 		buf_size = buf_size - uint64(disk_chunk_size)
  14798 	}
  14799 	return r
  14800 }
  14801 
  14802 // C documentation
  14803 //
  14804 //	// Validates the VP8/VP8L Header ("VP8 nnnn" or "VP8L nnnn") and skips over it.
  14805 //	// Returns VP8_STATUS_BITSTREAM_ERROR for invalid (chunk larger than
  14806 //	//         riff_size) VP8/VP8L header,
  14807 //	//         VP8_STATUS_NOT_ENOUGH_DATA in case of insufficient data, and
  14808 //	//         VP8_STATUS_OK otherwise.
  14809 //	// If a VP8/VP8L chunk is found, *chunk_size is set to the total number of bytes
  14810 //	// extracted from the VP8/VP8L chunk header.
  14811 //	// The flag '*is_lossless' is set to 1 in case of VP8L chunk / raw VP8L data.
  14812 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) {
  14813 	var data2, v1, v4, v7 uintptr
  14814 	var is_vp8, is_vp8l, v5, v8 int32
  14815 	var minimal_size, size, v2 uint32_t
  14816 	_, _, _, _, _, _, _, _, _, _, _ = data2, is_vp8, is_vp8l, minimal_size, size, v1, v2, v4, v5, v7, v8
  14817 	data2 = **(**uintptr)(__ccgo_up(data_ptr))
  14818 	is_vp8 = libc.BoolInt32(!(libc.Xmemcmp(tls, data2, __ccgo_ts+579, uint64(TAG_SIZE)) != 0))
  14819 	is_vp8l = libc.BoolInt32(!(libc.Xmemcmp(tls, data2, __ccgo_ts+584, uint64(TAG_SIZE)) != 0))
  14820 	minimal_size = uint32(libc.Int32FromInt32(TAG_SIZE) + libc.Int32FromInt32(CHUNK_HEADER_SIZE)) // "WEBP" + "VP8 nnnn" OR
  14821 	// "WEBP" + "VP8Lnnnn"
  14822 	if **(**size_t)(__ccgo_up(data_size)) < uint64(CHUNK_HEADER_SIZE) {
  14823 		return int32(VP8_STATUS_NOT_ENOUGH_DATA) // Insufficient data.
  14824 	}
  14825 	if is_vp8 != 0 || is_vp8l != 0 {
  14826 		v1 = data2 + uintptr(TAG_SIZE)
  14827 		v4 = v1
  14828 		v5 = int32(**(**uint8_t)(__ccgo_up(v4)))<<libc.Int32FromInt32(0) | int32(**(**uint8_t)(__ccgo_up(v4 + 1)))<<int32(8)
  14829 		goto _6
  14830 	_6:
  14831 		v7 = v1 + uintptr(2)
  14832 		v8 = int32(**(**uint8_t)(__ccgo_up(v7)))<<libc.Int32FromInt32(0) | int32(**(**uint8_t)(__ccgo_up(v7 + 1)))<<int32(8)
  14833 		goto _9
  14834 	_9:
  14835 		v2 = uint32(v5) | uint32(v8)<<libc.Int32FromInt32(16)
  14836 		goto _3
  14837 	_3:
  14838 		// Bitstream contains VP8/VP8L header.
  14839 		size = v2
  14840 		if riff_size >= uint64(minimal_size) && uint64(size) > riff_size-uint64(minimal_size) {
  14841 			return int32(VP8_STATUS_BITSTREAM_ERROR) // Inconsistent size information.
  14842 		}
  14843 		if have_all_data != 0 && uint64(size) > **(**size_t)(__ccgo_up(data_size))-uint64(CHUNK_HEADER_SIZE) {
  14844 			return int32(VP8_STATUS_NOT_ENOUGH_DATA) // Truncated bitstream.
  14845 		}
  14846 		// Skip over CHUNK_HEADER_SIZE bytes from VP8/VP8L Header.
  14847 		**(**size_t)(__ccgo_up(chunk_size)) = uint64(size)
  14848 		**(**uintptr)(__ccgo_up(data_ptr)) += uintptr(CHUNK_HEADER_SIZE)
  14849 		**(**size_t)(__ccgo_up(data_size)) -= uint64(CHUNK_HEADER_SIZE)
  14850 		**(**int32)(__ccgo_up(is_lossless)) = is_vp8l
  14851 	} else {
  14852 		// Raw VP8/VP8L bitstream (no header).
  14853 		**(**int32)(__ccgo_up(is_lossless)) = VP8LCheckSignature(tls, data2, **(**size_t)(__ccgo_up(data_size)))
  14854 		**(**size_t)(__ccgo_up(chunk_size)) = **(**size_t)(__ccgo_up(data_size))
  14855 	}
  14856 	return int32(VP8_STATUS_OK)
  14857 }
  14858 
  14859 //------------------------------------------------------------------------------
  14860 
  14861 // C documentation
  14862 //
  14863 //	// Fetch '*width', '*height', '*has_alpha' and fill out 'headers' based on
  14864 //	// 'data'. All the output parameters may be NULL. If 'headers' is NULL only the
  14865 //	// minimal amount will be read to fetch the remaining parameters.
  14866 //	// If 'headers' is non-NULL this function will attempt to locate both alpha
  14867 //	// data (with or without a VP8X chunk) and the bitstream chunk (VP8/VP8L).
  14868 //	// Note: The following chunk sequences (before the raw VP8/VP8L data) are
  14869 //	// considered valid by this function:
  14870 //	// RIFF + VP8(L)
  14871 //	// RIFF + VP8X + (optional chunks) + VP8(L)
  14872 //	// ALPH + VP8 <-- Not a valid WebP format: only allowed for internal purpose.
  14873 //	// VP8(L)     <-- Not a valid WebP format: only allowed for internal purpose.
  14874 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) {
  14875 	bp := tls.Alloc(128)
  14876 	defer tls.Free(128)
  14877 	*(*uintptr)(unsafe.Pointer(bp)) = _data
  14878 	*(*size_t)(unsafe.Pointer(bp + 8)) = _data_size
  14879 	var animation_present, found_riff, have_all_data, v1 int32
  14880 	var status VP8StatusCode1
  14881 	var _ /* canvas_height at bp+20 */ int32
  14882 	var _ /* canvas_width at bp+16 */ int32
  14883 	var _ /* flags at bp+112 */ uint32_t
  14884 	var _ /* found_vp8x at bp+32 */ int32
  14885 	var _ /* hdrs at bp+40 */ WebPHeaderStructure
  14886 	var _ /* image_height at bp+28 */ int32
  14887 	var _ /* image_width at bp+24 */ int32
  14888 	_, _, _, _, _ = animation_present, found_riff, have_all_data, status, v1
  14889 	**(**int32)(__ccgo_up(bp + 16)) = 0
  14890 	**(**int32)(__ccgo_up(bp + 20)) = 0
  14891 	**(**int32)(__ccgo_up(bp + 24)) = 0
  14892 	**(**int32)(__ccgo_up(bp + 28)) = 0
  14893 	found_riff = 0
  14894 	**(**int32)(__ccgo_up(bp + 32)) = 0
  14895 	animation_present = 0
  14896 	if headers != libc.UintptrFromInt32(0) {
  14897 		v1 = (*WebPHeaderStructure)(unsafe.Pointer(headers)).Fhave_all_data
  14898 	} else {
  14899 		v1 = 0
  14900 	}
  14901 	have_all_data = v1
  14902 	if **(**uintptr)(__ccgo_up(bp)) == libc.UintptrFromInt32(0) || **(**size_t)(__ccgo_up(bp + 8)) < uint64(RIFF_HEADER_SIZE) {
  14903 		return int32(VP8_STATUS_NOT_ENOUGH_DATA)
  14904 	}
  14905 	libc.Xmemset(tls, bp+40, 0, uint64(72))
  14906 	(**(**WebPHeaderStructure)(__ccgo_up(bp + 40))).Fdata = **(**uintptr)(__ccgo_up(bp))
  14907 	(**(**WebPHeaderStructure)(__ccgo_up(bp + 40))).Fdata_size = **(**size_t)(__ccgo_up(bp + 8))
  14908 	// Skip over RIFF header.
  14909 	status = ParseRIFF(tls, bp, bp+8, have_all_data, bp+40+56)
  14910 	if status != int32(VP8_STATUS_OK) {
  14911 		return status // Wrong RIFF header / insufficient data.
  14912 	}
  14913 	found_riff = libc.BoolInt32((**(**WebPHeaderStructure)(__ccgo_up(bp + 40))).Friff_size > uint64(0))
  14914 	// Skip over VP8X.
  14915 	**(**uint32_t)(__ccgo_up(bp + 112)) = uint32(0)
  14916 	status = ParseVP8X(tls, bp, bp+8, bp+32, bp+16, bp+20, bp+112)
  14917 	if status != int32(VP8_STATUS_OK) {
  14918 		return status // Wrong VP8X / insufficient data.
  14919 	}
  14920 	animation_present = libc.BoolInt32(!!(**(**uint32_t)(__ccgo_up(bp + 112))&uint32(ANIMATION_FLAG) != 0))
  14921 	if !(found_riff != 0) && **(**int32)(__ccgo_up(bp + 32)) != 0 {
  14922 		// Note: This restriction may be removed in the future, if it becomes
  14923 		// necessary to send VP8X chunk to the decoder.
  14924 		return int32(VP8_STATUS_BITSTREAM_ERROR)
  14925 	}
  14926 	if has_alpha != libc.UintptrFromInt32(0) {
  14927 		**(**int32)(__ccgo_up(has_alpha)) = libc.BoolInt32(!!(**(**uint32_t)(__ccgo_up(bp + 112))&uint32(ALPHA_FLAG) != 0))
  14928 	}
  14929 	if has_animation != libc.UintptrFromInt32(0) {
  14930 		**(**int32)(__ccgo_up(has_animation)) = animation_present
  14931 	}
  14932 	if format != libc.UintptrFromInt32(0) {
  14933 		**(**int32)(__ccgo_up(format)) = 0
  14934 	} // default = undefined
  14935 	**(**int32)(__ccgo_up(bp + 24)) = **(**int32)(__ccgo_up(bp + 16))
  14936 	**(**int32)(__ccgo_up(bp + 28)) = **(**int32)(__ccgo_up(bp + 20))
  14937 	if **(**int32)(__ccgo_up(bp + 32)) != 0 && animation_present != 0 && headers == libc.UintptrFromInt32(0) {
  14938 		status = int32(VP8_STATUS_OK)
  14939 		goto ReturnWidthHeight // Just return features from VP8X header.
  14940 	}
  14941 	if **(**size_t)(__ccgo_up(bp + 8)) < uint64(TAG_SIZE) {
  14942 		status = int32(VP8_STATUS_NOT_ENOUGH_DATA)
  14943 		goto ReturnWidthHeight
  14944 	}
  14945 	// Skip over optional chunks if data started with "RIFF + VP8X" or "ALPH".
  14946 	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) {
  14947 		status = ParseOptionalChunks(tls, bp, bp+8, (**(**WebPHeaderStructure)(__ccgo_up(bp + 40))).Friff_size, bp+40+32, bp+40+40)
  14948 		if status != int32(VP8_STATUS_OK) {
  14949 			goto ReturnWidthHeight // Invalid chunk size / insufficient data.
  14950 		}
  14951 	}
  14952 	// Skip over VP8/VP8L header.
  14953 	status = ParseVP8Header(tls, bp, bp+8, have_all_data, (**(**WebPHeaderStructure)(__ccgo_up(bp + 40))).Friff_size, bp+40+48, bp+40+64)
  14954 	if status != int32(VP8_STATUS_OK) {
  14955 		goto ReturnWidthHeight // Wrong VP8/VP8L chunk-header / insufficient data.
  14956 	}
  14957 	if (**(**WebPHeaderStructure)(__ccgo_up(bp + 40))).Fcompressed_size > uint64(^libc.Uint32FromUint32(0)-libc.Uint32FromInt32(CHUNK_HEADER_SIZE)-libc.Uint32FromInt32(1)) {
  14958 		return int32(VP8_STATUS_BITSTREAM_ERROR)
  14959 	}
  14960 	if format != libc.UintptrFromInt32(0) && !(animation_present != 0) {
  14961 		if (**(**WebPHeaderStructure)(__ccgo_up(bp + 40))).Fis_lossless != 0 {
  14962 			v1 = int32(2)
  14963 		} else {
  14964 			v1 = int32(1)
  14965 		}
  14966 		**(**int32)(__ccgo_up(format)) = v1
  14967 	}
  14968 	if !((**(**WebPHeaderStructure)(__ccgo_up(bp + 40))).Fis_lossless != 0) {
  14969 		if **(**size_t)(__ccgo_up(bp + 8)) < uint64(VP8_FRAME_HEADER_SIZE) {
  14970 			status = int32(VP8_STATUS_NOT_ENOUGH_DATA)
  14971 			goto ReturnWidthHeight
  14972 		}
  14973 		// Validates raw VP8 data.
  14974 		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) {
  14975 			return int32(VP8_STATUS_BITSTREAM_ERROR)
  14976 		}
  14977 	} else {
  14978 		if **(**size_t)(__ccgo_up(bp + 8)) < uint64(VP8L_FRAME_HEADER_SIZE) {
  14979 			status = int32(VP8_STATUS_NOT_ENOUGH_DATA)
  14980 			goto ReturnWidthHeight
  14981 		}
  14982 		// Validates raw VP8L data.
  14983 		if !(VP8LGetInfo(tls, **(**uintptr)(__ccgo_up(bp)), **(**size_t)(__ccgo_up(bp + 8)), bp+24, bp+28, has_alpha) != 0) {
  14984 			return int32(VP8_STATUS_BITSTREAM_ERROR)
  14985 		}
  14986 	}
  14987 	// Validates image size coherency.
  14988 	if **(**int32)(__ccgo_up(bp + 32)) != 0 {
  14989 		if **(**int32)(__ccgo_up(bp + 16)) != **(**int32)(__ccgo_up(bp + 24)) || **(**int32)(__ccgo_up(bp + 20)) != **(**int32)(__ccgo_up(bp + 28)) {
  14990 			return int32(VP8_STATUS_BITSTREAM_ERROR)
  14991 		}
  14992 	}
  14993 	if headers != libc.UintptrFromInt32(0) {
  14994 		**(**WebPHeaderStructure)(__ccgo_up(headers)) = **(**WebPHeaderStructure)(__ccgo_up(bp + 40))
  14995 		(*WebPHeaderStructure)(unsafe.Pointer(headers)).Foffset = uint64(int64(**(**uintptr)(__ccgo_up(bp))) - int64((*WebPHeaderStructure)(unsafe.Pointer(headers)).Fdata))
  14996 	}
  14997 	goto ReturnWidthHeight
  14998 ReturnWidthHeight:
  14999 	;
  15000 	if status == int32(VP8_STATUS_OK) || status == int32(VP8_STATUS_NOT_ENOUGH_DATA) && **(**int32)(__ccgo_up(bp + 32)) != 0 && headers == libc.UintptrFromInt32(0) {
  15001 		if has_alpha != libc.UintptrFromInt32(0) {
  15002 			// If the data did not contain a VP8X/VP8L chunk the only definitive way
  15003 			// to set this is by looking for alpha data (from an ALPH chunk).
  15004 			**(**int32)(__ccgo_up(has_alpha)) |= libc.BoolInt32((**(**WebPHeaderStructure)(__ccgo_up(bp + 40))).Falpha_data != libc.UintptrFromInt32(0))
  15005 		}
  15006 		if width != libc.UintptrFromInt32(0) {
  15007 			**(**int32)(__ccgo_up(width)) = **(**int32)(__ccgo_up(bp + 24))
  15008 		}
  15009 		if height != libc.UintptrFromInt32(0) {
  15010 			**(**int32)(__ccgo_up(height)) = **(**int32)(__ccgo_up(bp + 28))
  15011 		}
  15012 		return int32(VP8_STATUS_OK)
  15013 	} else {
  15014 		return status
  15015 	}
  15016 	return r
  15017 }
  15018 
  15019 func WebPParseHeaders(tls *libc.TLS, headers uintptr) (r VP8StatusCode1) {
  15020 	bp := tls.Alloc(16)
  15021 	defer tls.Free(16)
  15022 	var status VP8StatusCode1
  15023 	var _ /* has_animation at bp+0 */ int32
  15024 	_ = status
  15025 	**(**int32)(__ccgo_up(bp)) = 0
  15026 	// fill out headers, ignore width/height/has_alpha.
  15027 	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)
  15028 	if status == int32(VP8_STATUS_OK) || status == int32(VP8_STATUS_NOT_ENOUGH_DATA) {
  15029 		// The WebPDemux API + libwebp can be used to decode individual
  15030 		// uncomposited frames or the WebPAnimDecoder can be used to fully
  15031 		// reconstruct them (see webp/demux.h).
  15032 		if **(**int32)(__ccgo_up(bp)) != 0 {
  15033 			status = int32(VP8_STATUS_UNSUPPORTED_FEATURE)
  15034 		}
  15035 	}
  15036 	return status
  15037 }
  15038 
  15039 //------------------------------------------------------------------------------
  15040 // WebPDecParams
  15041 
  15042 func WebPResetDecParams(tls *libc.TLS, params uintptr) {
  15043 	if params != libc.UintptrFromInt32(0) {
  15044 		libc.Xmemset(tls, params, 0, uint64(112))
  15045 	}
  15046 }
  15047 
  15048 //------------------------------------------------------------------------------
  15049 // "Into" decoding variants
  15050 
  15051 // C documentation
  15052 //
  15053 //	// Main flow
  15054 func DecodeInto(tls *libc.TLS, data uintptr, data_size size_t, params uintptr) (r VP8StatusCode1) {
  15055 	bp := tls.Alloc(240)
  15056 	defer tls.Free(240)
  15057 	var dec, dec1 uintptr
  15058 	var status VP8StatusCode1
  15059 	var v1 int32
  15060 	var _ /* headers at bp+160 */ WebPHeaderStructure
  15061 	var _ /* io at bp+0 */ VP8Io
  15062 	_, _, _, _ = dec, dec1, status, v1
  15063 	(**(**WebPHeaderStructure)(__ccgo_up(bp + 160))).Fdata = data
  15064 	(**(**WebPHeaderStructure)(__ccgo_up(bp + 160))).Fdata_size = data_size
  15065 	(**(**WebPHeaderStructure)(__ccgo_up(bp + 160))).Fhave_all_data = int32(1)
  15066 	status = WebPParseHeaders(tls, bp+160) // Process Pre-VP8 chunks.
  15067 	if status != int32(VP8_STATUS_OK) {
  15068 		return status
  15069 	}
  15070 	v1 = VP8InitIoInternal(tls, bp, int32(WEBP_DECODER_ABI_VERSION))
  15071 	goto _2
  15072 _2:
  15073 	if !(v1 != 0) {
  15074 		return int32(VP8_STATUS_INVALID_PARAM)
  15075 	}
  15076 	(**(**VP8Io)(__ccgo_up(bp))).Fdata = (**(**WebPHeaderStructure)(__ccgo_up(bp + 160))).Fdata + uintptr((**(**WebPHeaderStructure)(__ccgo_up(bp + 160))).Foffset)
  15077 	(**(**VP8Io)(__ccgo_up(bp))).Fdata_size = (**(**WebPHeaderStructure)(__ccgo_up(bp + 160))).Fdata_size - (**(**WebPHeaderStructure)(__ccgo_up(bp + 160))).Foffset
  15078 	WebPInitCustomIo(tls, params, bp) // Plug the I/O functions.
  15079 	if !((**(**WebPHeaderStructure)(__ccgo_up(bp + 160))).Fis_lossless != 0) {
  15080 		dec = VP8New(tls)
  15081 		if dec == libc.UintptrFromInt32(0) {
  15082 			return int32(VP8_STATUS_OUT_OF_MEMORY)
  15083 		}
  15084 		(*VP8Decoder)(unsafe.Pointer(dec)).Falpha_data = (**(**WebPHeaderStructure)(__ccgo_up(bp + 160))).Falpha_data
  15085 		(*VP8Decoder)(unsafe.Pointer(dec)).Falpha_data_size = (**(**WebPHeaderStructure)(__ccgo_up(bp + 160))).Falpha_data_size
  15086 		// Decode bitstream header, update io->width/io->height.
  15087 		if !(VP8GetHeaders(tls, dec, bp) != 0) {
  15088 			status = (*VP8Decoder)(unsafe.Pointer(dec)).Fstatus // An error occurred. Grab error status.
  15089 		} else {
  15090 			// Allocate/check output buffers.
  15091 			status = WebPAllocateDecBuffer(tls, (**(**VP8Io)(__ccgo_up(bp))).Fwidth, (**(**VP8Io)(__ccgo_up(bp))).Fheight, (*WebPDecParams)(unsafe.Pointer(params)).Foptions, (*WebPDecParams)(unsafe.Pointer(params)).Foutput)
  15092 			if status == int32(VP8_STATUS_OK) { // Decode
  15093 				// This change must be done before calling VP8Decode()
  15094 				(*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)
  15095 				VP8InitDithering(tls, (*WebPDecParams)(unsafe.Pointer(params)).Foptions, dec)
  15096 				if !(VP8Decode(tls, dec, bp) != 0) {
  15097 					status = (*VP8Decoder)(unsafe.Pointer(dec)).Fstatus
  15098 				}
  15099 			}
  15100 		}
  15101 		VP8Delete(tls, dec)
  15102 	} else {
  15103 		dec1 = VP8LNew(tls)
  15104 		if dec1 == libc.UintptrFromInt32(0) {
  15105 			return int32(VP8_STATUS_OUT_OF_MEMORY)
  15106 		}
  15107 		if !(VP8LDecodeHeader(tls, dec1, bp) != 0) {
  15108 			status = (*VP8LDecoder)(unsafe.Pointer(dec1)).Fstatus // An error occurred. Grab error status.
  15109 		} else {
  15110 			// Allocate/check output buffers.
  15111 			status = WebPAllocateDecBuffer(tls, (**(**VP8Io)(__ccgo_up(bp))).Fwidth, (**(**VP8Io)(__ccgo_up(bp))).Fheight, (*WebPDecParams)(unsafe.Pointer(params)).Foptions, (*WebPDecParams)(unsafe.Pointer(params)).Foutput)
  15112 			if status == int32(VP8_STATUS_OK) { // Decode
  15113 				if !(VP8LDecodeImage(tls, dec1) != 0) {
  15114 					status = (*VP8LDecoder)(unsafe.Pointer(dec1)).Fstatus
  15115 				}
  15116 			}
  15117 		}
  15118 		VP8LDelete(tls, dec1)
  15119 	}
  15120 	if status != int32(VP8_STATUS_OK) {
  15121 		WebPFreeDecBuffer(tls, (*WebPDecParams)(unsafe.Pointer(params)).Foutput)
  15122 	} else {
  15123 		if (*WebPDecParams)(unsafe.Pointer(params)).Foptions != libc.UintptrFromInt32(0) && (*WebPDecoderOptions)(unsafe.Pointer((*WebPDecParams)(unsafe.Pointer(params)).Foptions)).Fflip != 0 {
  15124 			// This restores the original stride values if options->flip was used
  15125 			// during the call to WebPAllocateDecBuffer above.
  15126 			status = WebPFlipBuffer(tls, (*WebPDecParams)(unsafe.Pointer(params)).Foutput)
  15127 		}
  15128 	}
  15129 	return status
  15130 }
  15131 
  15132 // C documentation
  15133 //
  15134 //	// Helpers
  15135 func DecodeIntoRGBABuffer(tls *libc.TLS, colorspace WEBP_CSP_MODE1, data uintptr, data_size size_t, rgba uintptr, stride int32, size size_t) (r uintptr) {
  15136 	bp := tls.Alloc(240)
  15137 	defer tls.Free(240)
  15138 	var v1 int32
  15139 	var v3 bool
  15140 	var _ /* buf at bp+112 */ WebPDecBuffer
  15141 	var _ /* params at bp+0 */ WebPDecParams
  15142 	_, _ = v1, v3
  15143 	if v3 = rgba == libc.UintptrFromInt32(0); !v3 {
  15144 		v1 = WebPInitDecBufferInternal(tls, bp+112, int32(WEBP_DECODER_ABI_VERSION))
  15145 		goto _2
  15146 	_2:
  15147 	}
  15148 	if v3 || !(v1 != 0) {
  15149 		return libc.UintptrFromInt32(0)
  15150 	}
  15151 	WebPResetDecParams(tls, bp)
  15152 	(**(**WebPDecParams)(__ccgo_up(bp))).Foutput = bp + 112
  15153 	(**(**WebPDecBuffer)(__ccgo_up(bp + 112))).Fcolorspace = colorspace
  15154 	*(*uintptr)(unsafe.Pointer(bp + 112 + 16)) = rgba
  15155 	*(*int32)(unsafe.Pointer(bp + 112 + 16 + 8)) = stride
  15156 	*(*size_t)(unsafe.Pointer(bp + 112 + 16 + 16)) = size
  15157 	(**(**WebPDecBuffer)(__ccgo_up(bp + 112))).Fis_external_memory = int32(1)
  15158 	if DecodeInto(tls, data, data_size, bp) != int32(VP8_STATUS_OK) {
  15159 		return libc.UintptrFromInt32(0)
  15160 	}
  15161 	return rgba
  15162 }
  15163 
  15164 func WebPDecodeRGBInto(tls *libc.TLS, data uintptr, data_size size_t, output uintptr, size size_t, stride int32) (r uintptr) {
  15165 	return DecodeIntoRGBABuffer(tls, int32(MODE_RGB), data, data_size, output, stride, size)
  15166 }
  15167 
  15168 func WebPDecodeRGBAInto(tls *libc.TLS, data uintptr, data_size size_t, output uintptr, size size_t, stride int32) (r uintptr) {
  15169 	return DecodeIntoRGBABuffer(tls, int32(MODE_RGBA), data, data_size, output, stride, size)
  15170 }
  15171 
  15172 func WebPDecodeARGBInto(tls *libc.TLS, data uintptr, data_size size_t, output uintptr, size size_t, stride int32) (r uintptr) {
  15173 	return DecodeIntoRGBABuffer(tls, int32(MODE_ARGB), data, data_size, output, stride, size)
  15174 }
  15175 
  15176 func WebPDecodeBGRInto(tls *libc.TLS, data uintptr, data_size size_t, output uintptr, size size_t, stride int32) (r uintptr) {
  15177 	return DecodeIntoRGBABuffer(tls, int32(MODE_BGR), data, data_size, output, stride, size)
  15178 }
  15179 
  15180 func WebPDecodeBGRAInto(tls *libc.TLS, data uintptr, data_size size_t, output uintptr, size size_t, stride int32) (r uintptr) {
  15181 	return DecodeIntoRGBABuffer(tls, int32(MODE_BGRA), data, data_size, output, stride, size)
  15182 }
  15183 
  15184 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) {
  15185 	bp := tls.Alloc(240)
  15186 	defer tls.Free(240)
  15187 	var v1 int32
  15188 	var v3 bool
  15189 	var _ /* output at bp+112 */ WebPDecBuffer
  15190 	var _ /* params at bp+0 */ WebPDecParams
  15191 	_, _ = v1, v3
  15192 	if v3 = luma == libc.UintptrFromInt32(0); !v3 {
  15193 		v1 = WebPInitDecBufferInternal(tls, bp+112, int32(WEBP_DECODER_ABI_VERSION))
  15194 		goto _2
  15195 	_2:
  15196 	}
  15197 	if v3 || !(v1 != 0) {
  15198 		return libc.UintptrFromInt32(0)
  15199 	}
  15200 	WebPResetDecParams(tls, bp)
  15201 	(**(**WebPDecParams)(__ccgo_up(bp))).Foutput = bp + 112
  15202 	(**(**WebPDecBuffer)(__ccgo_up(bp + 112))).Fcolorspace = int32(MODE_YUV)
  15203 	*(*uintptr)(unsafe.Pointer(bp + 112 + 16)) = luma
  15204 	*(*int32)(unsafe.Pointer(bp + 112 + 16 + 32)) = luma_stride
  15205 	*(*size_t)(unsafe.Pointer(bp + 112 + 16 + 48)) = luma_size
  15206 	*(*uintptr)(unsafe.Pointer(bp + 112 + 16 + 8)) = u
  15207 	*(*int32)(unsafe.Pointer(bp + 112 + 16 + 36)) = u_stride
  15208 	*(*size_t)(unsafe.Pointer(bp + 112 + 16 + 56)) = u_size
  15209 	*(*uintptr)(unsafe.Pointer(bp + 112 + 16 + 16)) = v
  15210 	*(*int32)(unsafe.Pointer(bp + 112 + 16 + 40)) = v_stride
  15211 	*(*size_t)(unsafe.Pointer(bp + 112 + 16 + 64)) = v_size
  15212 	(**(**WebPDecBuffer)(__ccgo_up(bp + 112))).Fis_external_memory = int32(1)
  15213 	if DecodeInto(tls, data, data_size, bp) != int32(VP8_STATUS_OK) {
  15214 		return libc.UintptrFromInt32(0)
  15215 	}
  15216 	return luma
  15217 }
  15218 
  15219 // ------------------------------------------------------------------------------
  15220 func Decode(tls *libc.TLS, mode1 WEBP_CSP_MODE1, data uintptr, data_size size_t, width uintptr, height uintptr, keep_info uintptr) (r uintptr) {
  15221 	bp := tls.Alloc(240)
  15222 	defer tls.Free(240)
  15223 	var v1 int32
  15224 	var v3 uintptr
  15225 	var _ /* output at bp+112 */ WebPDecBuffer
  15226 	var _ /* params at bp+0 */ WebPDecParams
  15227 	_, _ = v1, v3
  15228 	v1 = WebPInitDecBufferInternal(tls, bp+112, int32(WEBP_DECODER_ABI_VERSION))
  15229 	goto _2
  15230 _2:
  15231 	if !(v1 != 0) {
  15232 		return libc.UintptrFromInt32(0)
  15233 	}
  15234 	WebPResetDecParams(tls, bp)
  15235 	(**(**WebPDecParams)(__ccgo_up(bp))).Foutput = bp + 112
  15236 	(**(**WebPDecBuffer)(__ccgo_up(bp + 112))).Fcolorspace = mode1
  15237 	// Retrieve (and report back) the required dimensions from bitstream.
  15238 	if !(WebPGetInfo(tls, data, data_size, bp+112+4, bp+112+8) != 0) {
  15239 		return libc.UintptrFromInt32(0)
  15240 	}
  15241 	if width != libc.UintptrFromInt32(0) {
  15242 		**(**int32)(__ccgo_up(width)) = (**(**WebPDecBuffer)(__ccgo_up(bp + 112))).Fwidth
  15243 	}
  15244 	if height != libc.UintptrFromInt32(0) {
  15245 		**(**int32)(__ccgo_up(height)) = (**(**WebPDecBuffer)(__ccgo_up(bp + 112))).Fheight
  15246 	}
  15247 	// Decode
  15248 	if DecodeInto(tls, data, data_size, bp) != int32(VP8_STATUS_OK) {
  15249 		return libc.UintptrFromInt32(0)
  15250 	}
  15251 	if keep_info != libc.UintptrFromInt32(0) { // keep track of the side-info
  15252 		WebPCopyDecBuffer(tls, bp+112, keep_info)
  15253 	}
  15254 	// return decoded samples (don't clear 'output'!)
  15255 	v1 = libc.BoolInt32(mode1 < int32(MODE_YUV))
  15256 	goto _5
  15257 _5:
  15258 	if v1 != 0 {
  15259 		v3 = *(*uintptr)(unsafe.Pointer(bp + 112 + 16))
  15260 	} else {
  15261 		v3 = *(*uintptr)(unsafe.Pointer(bp + 112 + 16))
  15262 	}
  15263 	return v3
  15264 }
  15265 
  15266 func WebPDecodeRGB(tls *libc.TLS, data uintptr, data_size size_t, width uintptr, height uintptr) (r uintptr) {
  15267 	return Decode(tls, int32(MODE_RGB), data, data_size, width, height, libc.UintptrFromInt32(0))
  15268 }
  15269 
  15270 func WebPDecodeRGBA(tls *libc.TLS, data uintptr, data_size size_t, width uintptr, height uintptr) (r uintptr) {
  15271 	return Decode(tls, int32(MODE_RGBA), data, data_size, width, height, libc.UintptrFromInt32(0))
  15272 }
  15273 
  15274 func WebPDecodeARGB(tls *libc.TLS, data uintptr, data_size size_t, width uintptr, height uintptr) (r uintptr) {
  15275 	return Decode(tls, int32(MODE_ARGB), data, data_size, width, height, libc.UintptrFromInt32(0))
  15276 }
  15277 
  15278 func WebPDecodeBGR(tls *libc.TLS, data uintptr, data_size size_t, width uintptr, height uintptr) (r uintptr) {
  15279 	return Decode(tls, int32(MODE_BGR), data, data_size, width, height, libc.UintptrFromInt32(0))
  15280 }
  15281 
  15282 func WebPDecodeBGRA(tls *libc.TLS, data uintptr, data_size size_t, width uintptr, height uintptr) (r uintptr) {
  15283 	return Decode(tls, int32(MODE_BGRA), data, data_size, width, height, libc.UintptrFromInt32(0))
  15284 }
  15285 
  15286 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) {
  15287 	bp := tls.Alloc(128)
  15288 	defer tls.Free(128)
  15289 	var buf, out uintptr
  15290 	var _ /* output at bp+0 */ WebPDecBuffer
  15291 	_, _ = buf, out
  15292 	// data, width and height are checked by Decode().
  15293 	if u == libc.UintptrFromInt32(0) || v == libc.UintptrFromInt32(0) || stride == libc.UintptrFromInt32(0) || uv_stride == libc.UintptrFromInt32(0) {
  15294 		return libc.UintptrFromInt32(0)
  15295 	}
  15296 	// only to preserve the side-infos
  15297 	out = Decode(tls, int32(MODE_YUV), data, data_size, width, height, bp)
  15298 	if out != libc.UintptrFromInt32(0) {
  15299 		buf = bp + 16
  15300 		**(**uintptr)(__ccgo_up(u)) = (*WebPYUVABuffer)(unsafe.Pointer(buf)).Fu
  15301 		**(**uintptr)(__ccgo_up(v)) = (*WebPYUVABuffer)(unsafe.Pointer(buf)).Fv
  15302 		**(**int32)(__ccgo_up(stride)) = (*WebPYUVABuffer)(unsafe.Pointer(buf)).Fy_stride
  15303 		**(**int32)(__ccgo_up(uv_stride)) = (*WebPYUVABuffer)(unsafe.Pointer(buf)).Fu_stride
  15304 	}
  15305 	return out
  15306 	return r
  15307 }
  15308 
  15309 func DefaultFeatures(tls *libc.TLS, features uintptr) {
  15310 	libc.Xmemset(tls, features, 0, uint64(40))
  15311 }
  15312 
  15313 func GetFeatures(tls *libc.TLS, data uintptr, data_size size_t, features uintptr) (r VP8StatusCode1) {
  15314 	if features == libc.UintptrFromInt32(0) || data == libc.UintptrFromInt32(0) {
  15315 		return int32(VP8_STATUS_INVALID_PARAM)
  15316 	}
  15317 	DefaultFeatures(tls, features)
  15318 	// Only parse enough of the data to retrieve the features.
  15319 	return ParseHeadersInternal(tls, data, data_size, features, features+4, features+8, features+12, features+16, libc.UintptrFromInt32(0))
  15320 }
  15321 
  15322 //------------------------------------------------------------------------------
  15323 // WebPGetInfo()
  15324 
  15325 func WebPGetInfo(tls *libc.TLS, data uintptr, data_size size_t, width uintptr, height uintptr) (r int32) {
  15326 	bp := tls.Alloc(48)
  15327 	defer tls.Free(48)
  15328 	var _ /* features at bp+0 */ WebPBitstreamFeatures
  15329 	if GetFeatures(tls, data, data_size, bp) != int32(VP8_STATUS_OK) {
  15330 		return 0
  15331 	}
  15332 	if width != libc.UintptrFromInt32(0) {
  15333 		**(**int32)(__ccgo_up(width)) = (**(**WebPBitstreamFeatures)(__ccgo_up(bp))).Fwidth
  15334 	}
  15335 	if height != libc.UintptrFromInt32(0) {
  15336 		**(**int32)(__ccgo_up(height)) = (**(**WebPBitstreamFeatures)(__ccgo_up(bp))).Fheight
  15337 	}
  15338 	return int32(1)
  15339 }
  15340 
  15341 //------------------------------------------------------------------------------
  15342 // Advance decoding API
  15343 
  15344 func WebPInitDecoderConfigInternal(tls *libc.TLS, config uintptr, version int32) (r int32) {
  15345 	var v1 int32
  15346 	_ = v1
  15347 	if version>>int32(8) != libc.Int32FromInt32(WEBP_DECODER_ABI_VERSION)>>libc.Int32FromInt32(8) {
  15348 		return 0 // version mismatch
  15349 	}
  15350 	if config == libc.UintptrFromInt32(0) {
  15351 		return 0
  15352 	}
  15353 	libc.Xmemset(tls, config, 0, uint64(240))
  15354 	DefaultFeatures(tls, config)
  15355 	v1 = WebPInitDecBufferInternal(tls, config+40, int32(WEBP_DECODER_ABI_VERSION))
  15356 	goto _2
  15357 _2:
  15358 	if !(v1 != 0) {
  15359 		return 0
  15360 	}
  15361 	return int32(1)
  15362 }
  15363 
  15364 func WebPCheckCropDimensionsBasic(tls *libc.TLS, x int32, y int32, w int32, h int32) (r int32) {
  15365 	return libc.BoolInt32(!(x < 0 || y < 0 || w <= 0 || h <= 0))
  15366 }
  15367 
  15368 func WebPValidateDecoderConfig(tls *libc.TLS, config uintptr) (r int32) {
  15369 	bp := tls.Alloc(16)
  15370 	defer tls.Free(16)
  15371 	var options uintptr
  15372 	var _ /* scaled_height at bp+4 */ int32
  15373 	var _ /* scaled_width at bp+0 */ int32
  15374 	_ = options
  15375 	if config == libc.UintptrFromInt32(0) {
  15376 		return 0
  15377 	}
  15378 	if !(IsValidColorspace(tls, (*WebPDecoderConfig)(unsafe.Pointer(config)).Foutput.Fcolorspace) != 0) {
  15379 		return 0
  15380 	}
  15381 	options = config + 160
  15382 	// bypass_filtering, no_fancy_upsampling, use_cropping, use_scaling,
  15383 	// use_threads, flip can be any integer and are interpreted as boolean.
  15384 	// Check for cropping.
  15385 	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) {
  15386 		return 0
  15387 	}
  15388 	// Check for scaling.
  15389 	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) {
  15390 		return 0
  15391 	}
  15392 	// In case the WebPBitstreamFeatures has been filled in, check further.
  15393 	if (*WebPDecoderConfig)(unsafe.Pointer(config)).Finput.Fwidth > 0 || (*WebPDecoderConfig)(unsafe.Pointer(config)).Finput.Fheight > 0 {
  15394 		**(**int32)(__ccgo_up(bp)) = (*WebPDecoderOptions)(unsafe.Pointer(options)).Fscaled_width
  15395 		**(**int32)(__ccgo_up(bp + 4)) = (*WebPDecoderOptions)(unsafe.Pointer(options)).Fscaled_height
  15396 		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) {
  15397 			return 0
  15398 		}
  15399 		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) {
  15400 			return 0
  15401 		}
  15402 	}
  15403 	// Check for dithering.
  15404 	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) {
  15405 		return 0
  15406 	}
  15407 	return int32(1)
  15408 }
  15409 
  15410 func WebPGetFeaturesInternal(tls *libc.TLS, data uintptr, data_size size_t, features uintptr, version int32) (r VP8StatusCode1) {
  15411 	if version>>int32(8) != libc.Int32FromInt32(WEBP_DECODER_ABI_VERSION)>>libc.Int32FromInt32(8) {
  15412 		return int32(VP8_STATUS_INVALID_PARAM) // version mismatch
  15413 	}
  15414 	if features == libc.UintptrFromInt32(0) {
  15415 		return int32(VP8_STATUS_INVALID_PARAM)
  15416 	}
  15417 	return GetFeatures(tls, data, data_size, features)
  15418 }
  15419 
  15420 func WebPDecode(tls *libc.TLS, data uintptr, data_size size_t, config uintptr) (r VP8StatusCode1) {
  15421 	bp := tls.Alloc(240)
  15422 	defer tls.Free(240)
  15423 	var status VP8StatusCode1
  15424 	var v1 int32
  15425 	var _ /* in_mem_buffer at bp+112 */ WebPDecBuffer
  15426 	var _ /* params at bp+0 */ WebPDecParams
  15427 	_, _ = status, v1
  15428 	if config == libc.UintptrFromInt32(0) {
  15429 		return int32(VP8_STATUS_INVALID_PARAM)
  15430 	}
  15431 	status = GetFeatures(tls, data, data_size, config)
  15432 	if status != int32(VP8_STATUS_OK) {
  15433 		if status == int32(VP8_STATUS_NOT_ENOUGH_DATA) {
  15434 			return int32(VP8_STATUS_BITSTREAM_ERROR) // Not-enough-data treated as error.
  15435 		}
  15436 		return status
  15437 	}
  15438 	WebPResetDecParams(tls, bp)
  15439 	(**(**WebPDecParams)(__ccgo_up(bp))).Foptions = config + 160
  15440 	(**(**WebPDecParams)(__ccgo_up(bp))).Foutput = config + 40
  15441 	if WebPAvoidSlowMemory(tls, (**(**WebPDecParams)(__ccgo_up(bp))).Foutput, config) != 0 {
  15442 		v1 = WebPInitDecBufferInternal(tls, bp+112, int32(WEBP_DECODER_ABI_VERSION))
  15443 		goto _2
  15444 	_2:
  15445 		if !(v1 != 0) {
  15446 			return int32(VP8_STATUS_INVALID_PARAM)
  15447 		}
  15448 		(**(**WebPDecBuffer)(__ccgo_up(bp + 112))).Fcolorspace = (*WebPDecoderConfig)(unsafe.Pointer(config)).Foutput.Fcolorspace
  15449 		(**(**WebPDecBuffer)(__ccgo_up(bp + 112))).Fwidth = (*WebPDecoderConfig)(unsafe.Pointer(config)).Finput.Fwidth
  15450 		(**(**WebPDecBuffer)(__ccgo_up(bp + 112))).Fheight = (*WebPDecoderConfig)(unsafe.Pointer(config)).Finput.Fheight
  15451 		(**(**WebPDecParams)(__ccgo_up(bp))).Foutput = bp + 112
  15452 		status = DecodeInto(tls, data, data_size, bp)
  15453 		if status == int32(VP8_STATUS_OK) { // do the slow-copy
  15454 			status = WebPCopyDecBufferPixels(tls, bp+112, config+40)
  15455 		}
  15456 		WebPFreeDecBuffer(tls, bp+112)
  15457 	} else {
  15458 		status = DecodeInto(tls, data, data_size, bp)
  15459 	}
  15460 	return status
  15461 }
  15462 
  15463 //------------------------------------------------------------------------------
  15464 // Cropping and rescaling.
  15465 
  15466 func WebPCheckCropDimensions(tls *libc.TLS, image_width int32, image_height int32, x int32, y int32, w int32, h int32) (r int32) {
  15467 	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))
  15468 }
  15469 
  15470 func WebPIoInitFromOptions(tls *libc.TLS, options uintptr, io uintptr, src_colorspace WEBP_CSP_MODE1) (r int32) {
  15471 	bp := tls.Alloc(16)
  15472 	defer tls.Free(16)
  15473 	var H, W, h, w, x, y, v1 int32
  15474 	var _ /* scaled_height at bp+4 */ int32
  15475 	var _ /* scaled_width at bp+0 */ int32
  15476 	_, _, _, _, _, _, _ = H, W, h, w, x, y, v1
  15477 	W = (*VP8Io)(unsafe.Pointer(io)).Fwidth
  15478 	H = (*VP8Io)(unsafe.Pointer(io)).Fheight
  15479 	x = 0
  15480 	y = 0
  15481 	w = W
  15482 	h = H
  15483 	// Cropping
  15484 	(*VP8Io)(unsafe.Pointer(io)).Fuse_cropping = libc.BoolInt32(options != libc.UintptrFromInt32(0) && (*WebPDecoderOptions)(unsafe.Pointer(options)).Fuse_cropping != 0)
  15485 	if (*VP8Io)(unsafe.Pointer(io)).Fuse_cropping != 0 {
  15486 		w = (*WebPDecoderOptions)(unsafe.Pointer(options)).Fcrop_width
  15487 		h = (*WebPDecoderOptions)(unsafe.Pointer(options)).Fcrop_height
  15488 		x = (*WebPDecoderOptions)(unsafe.Pointer(options)).Fcrop_left
  15489 		y = (*WebPDecoderOptions)(unsafe.Pointer(options)).Fcrop_top
  15490 		v1 = libc.BoolInt32(src_colorspace < int32(MODE_YUV))
  15491 		goto _2
  15492 	_2:
  15493 		if !(v1 != 0) { // only snap for YUV420
  15494 			x = x & ^libc.Int32FromInt32(1)
  15495 			y = y & ^libc.Int32FromInt32(1)
  15496 		}
  15497 		if !(WebPCheckCropDimensions(tls, W, H, x, y, w, h) != 0) {
  15498 			return 0 // out of frame boundary error
  15499 		}
  15500 	}
  15501 	(*VP8Io)(unsafe.Pointer(io)).Fcrop_left = x
  15502 	(*VP8Io)(unsafe.Pointer(io)).Fcrop_top = y
  15503 	(*VP8Io)(unsafe.Pointer(io)).Fcrop_right = x + w
  15504 	(*VP8Io)(unsafe.Pointer(io)).Fcrop_bottom = y + h
  15505 	(*VP8Io)(unsafe.Pointer(io)).Fmb_w = w
  15506 	(*VP8Io)(unsafe.Pointer(io)).Fmb_h = h
  15507 	// Scaling
  15508 	(*VP8Io)(unsafe.Pointer(io)).Fuse_scaling = libc.BoolInt32(options != libc.UintptrFromInt32(0) && (*WebPDecoderOptions)(unsafe.Pointer(options)).Fuse_scaling != 0)
  15509 	if (*VP8Io)(unsafe.Pointer(io)).Fuse_scaling != 0 {
  15510 		**(**int32)(__ccgo_up(bp)) = (*WebPDecoderOptions)(unsafe.Pointer(options)).Fscaled_width
  15511 		**(**int32)(__ccgo_up(bp + 4)) = (*WebPDecoderOptions)(unsafe.Pointer(options)).Fscaled_height
  15512 		if !(WebPRescalerGetScaledDimensions(tls, w, h, bp, bp+4) != 0) {
  15513 			return 0
  15514 		}
  15515 		(*VP8Io)(unsafe.Pointer(io)).Fscaled_width = **(**int32)(__ccgo_up(bp))
  15516 		(*VP8Io)(unsafe.Pointer(io)).Fscaled_height = **(**int32)(__ccgo_up(bp + 4))
  15517 	}
  15518 	// Filter
  15519 	(*VP8Io)(unsafe.Pointer(io)).Fbypass_filtering = libc.BoolInt32(options != libc.UintptrFromInt32(0) && (*WebPDecoderOptions)(unsafe.Pointer(options)).Fbypass_filtering != 0)
  15520 	// Fancy upsampler
  15521 	(*VP8Io)(unsafe.Pointer(io)).Ffancy_upsampling = libc.BoolInt32(options == libc.UintptrFromInt32(0) || !((*WebPDecoderOptions)(unsafe.Pointer(options)).Fno_fancy_upsampling != 0))
  15522 	if (*VP8Io)(unsafe.Pointer(io)).Fuse_scaling != 0 {
  15523 		// disable filter (only for large downscaling ratio).
  15524 		**(**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))
  15525 		(*VP8Io)(unsafe.Pointer(io)).Ffancy_upsampling = 0
  15526 	}
  15527 	return int32(1)
  15528 }
  15529 
  15530 const ENC_MAJ_VERSION = 1
  15531 const ENC_MIN_VERSION = 6
  15532 const ENC_REV_VERSION = 0
  15533 const ERROR_DIFFUSION_QUALITY = 98
  15534 const HASH_BITS = 18
  15535 const MAX_COLOR_CACHE_BITS = 10
  15536 const MAX_LENGTH_BITS = 12
  15537 const MAX_REFS_BLOCK_PER_IMAGE = 16
  15538 const QFIX = 17
  15539 const U_OFF_ENC = 16
  15540 const VP8L_WRITER_BITS = 32
  15541 const VP8L_WRITER_BYTES = 4
  15542 const VP8L_WRITER_MAX_BITS = 64
  15543 const WEBP_ENCODER_ABI_VERSION = 528
  15544 const WEBP_MAX_DIMENSION = 16383
  15545 const WEBP_NEAR_LOSSLESS = 1
  15546 const WINDOW_SIZE_BITS = 20
  15547 const WSWAP = "HToLE32"
  15548 const Y_OFF_ENC = 0
  15549 
  15550 type VP8Matrix = struct {
  15551 	Fq       [16]uint16_t
  15552 	Fiq      [16]uint16_t
  15553 	Fbias    [16]uint32_t
  15554 	Fzthresh [16]uint32_t
  15555 	Fsharpen [16]uint16_t
  15556 }
  15557 
  15558 type VP8BitWriter = struct {
  15559 	Frange1  int32_t
  15560 	Fvalue   int32_t
  15561 	Frun     int32
  15562 	Fnb_bits int32
  15563 	Fbuf     uintptr
  15564 	Fpos     size_t
  15565 	Fmax_pos size_t
  15566 	Ferror1  int32
  15567 }
  15568 
  15569 type vp8l_atype_t = uint64
  15570 
  15571 type vp8l_wtype_t = uint32
  15572 
  15573 type VP8LBitWriter = struct {
  15574 	Fbits   vp8l_atype_t
  15575 	Fused   int32
  15576 	Fbuf    uintptr
  15577 	Fcur    uintptr
  15578 	Fend    uintptr
  15579 	Ferror1 int32
  15580 }
  15581 
  15582 type WebPPicture = struct {
  15583 	Fuse_argb        int32
  15584 	Fcolorspace      WebPEncCSP1
  15585 	Fwidth           int32
  15586 	Fheight          int32
  15587 	Fy               uintptr
  15588 	Fu               uintptr
  15589 	Fv               uintptr
  15590 	Fy_stride        int32
  15591 	Fuv_stride       int32
  15592 	Fa               uintptr
  15593 	Fa_stride        int32
  15594 	Fpad1            [2]uint32_t
  15595 	Fargb            uintptr
  15596 	Fargb_stride     int32
  15597 	Fpad2            [3]uint32_t
  15598 	Fwriter          WebPWriterFunction
  15599 	Fcustom_ptr      uintptr
  15600 	Fextra_info_type int32
  15601 	Fextra_info      uintptr
  15602 	Fstats           uintptr
  15603 	Ferror_code      WebPEncodingError1
  15604 	Fprogress_hook   WebPProgressHook
  15605 	Fuser_data       uintptr
  15606 	Fpad3            [3]uint32_t
  15607 	Fpad4            uintptr
  15608 	Fpad5            uintptr
  15609 	Fpad6            [8]uint32_t
  15610 	Fmemory_         uintptr
  15611 	Fmemory_argb_    uintptr
  15612 	Fpad7            [2]uintptr
  15613 }
  15614 
  15615 type WebPEncCSP = int32
  15616 
  15617 const WEBP_YUV420 = 0
  15618 const WEBP_YUV420A = 4
  15619 const WEBP_CSP_UV_MASK = 3
  15620 const WEBP_CSP_ALPHA_BIT = 4
  15621 
  15622 type WebPEncodingError = int32
  15623 
  15624 const VP8_ENC_OK = 0
  15625 const VP8_ENC_ERROR_OUT_OF_MEMORY = 1
  15626 const VP8_ENC_ERROR_BITSTREAM_OUT_OF_MEMORY = 2
  15627 const VP8_ENC_ERROR_NULL_PARAMETER = 3
  15628 const VP8_ENC_ERROR_INVALID_CONFIGURATION = 4
  15629 const VP8_ENC_ERROR_BAD_DIMENSION = 5
  15630 const VP8_ENC_ERROR_PARTITION0_OVERFLOW = 6
  15631 const VP8_ENC_ERROR_PARTITION_OVERFLOW = 7
  15632 const VP8_ENC_ERROR_BAD_WRITE = 8
  15633 const VP8_ENC_ERROR_FILE_TOO_BIG = 9
  15634 const VP8_ENC_ERROR_USER_ABORT = 10
  15635 const VP8_ENC_ERROR_LAST = 11
  15636 
  15637 type WebPConfig = struct {
  15638 	Flossless          int32
  15639 	Fquality           float32
  15640 	Fmethod            int32
  15641 	Fimage_hint        WebPImageHint1
  15642 	Ftarget_size       int32
  15643 	Ftarget_PSNR       float32
  15644 	Fsegments          int32
  15645 	Fsns_strength      int32
  15646 	Ffilter_strength   int32
  15647 	Ffilter_sharpness  int32
  15648 	Ffilter_type       int32
  15649 	Fautofilter        int32
  15650 	Falpha_compression int32
  15651 	Falpha_filtering   int32
  15652 	Falpha_quality     int32
  15653 	Fpass              int32
  15654 	Fshow_compressed   int32
  15655 	Fpreprocessing     int32
  15656 	Fpartitions        int32
  15657 	Fpartition_limit   int32
  15658 	Femulate_jpeg_size int32
  15659 	Fthread_level      int32
  15660 	Flow_memory        int32
  15661 	Fnear_lossless     int32
  15662 	Fexact             int32
  15663 	Fuse_delta_palette int32
  15664 	Fuse_sharp_yuv     int32
  15665 	Fqmin              int32
  15666 	Fqmax              int32
  15667 }
  15668 
  15669 type WebPImageHint = int32
  15670 
  15671 const WEBP_HINT_DEFAULT = 0
  15672 const WEBP_HINT_PICTURE = 1
  15673 const WEBP_HINT_PHOTO = 2
  15674 const WEBP_HINT_GRAPH = 3
  15675 const WEBP_HINT_LAST = 4
  15676 
  15677 type WebPAuxStats = struct {
  15678 	Fcoded_size                 int32
  15679 	FPSNR                       [5]float32
  15680 	Fblock_count                [3]int32
  15681 	Fheader_bytes               [2]int32
  15682 	Fresidual_bytes             [3][4]int32
  15683 	Fsegment_size               [4]int32
  15684 	Fsegment_quant              [4]int32
  15685 	Fsegment_level              [4]int32
  15686 	Falpha_data_size            int32
  15687 	Flayer_data_size            int32
  15688 	Flossless_features          uint32_t
  15689 	Fhistogram_bits             int32
  15690 	Ftransform_bits             int32
  15691 	Fcache_bits                 int32
  15692 	Fpalette_size               int32
  15693 	Flossless_size              int32
  15694 	Flossless_hdr_size          int32
  15695 	Flossless_data_size         int32
  15696 	Fcross_color_transform_bits int32
  15697 	Fpad                        [1]uint32_t
  15698 }
  15699 
  15700 type WebPMemoryWriter = struct {
  15701 	Fmem      uintptr
  15702 	Fsize     size_t
  15703 	Fmax_size size_t
  15704 	Fpad      [1]uint32_t
  15705 }
  15706 
  15707 type WebPImageHint1 = int32
  15708 
  15709 type WebPPreset1 = int32
  15710 
  15711 type WebPPreset = int32
  15712 
  15713 const WEBP_PRESET_DEFAULT = 0
  15714 const WEBP_PRESET_PICTURE = 1
  15715 const WEBP_PRESET_PHOTO = 2
  15716 const WEBP_PRESET_DRAWING = 3
  15717 const WEBP_PRESET_ICON = 4
  15718 const WEBP_PRESET_TEXT = 5
  15719 
  15720 type WebPWriterFunction = uintptr
  15721 
  15722 type WebPProgressHook = uintptr
  15723 
  15724 type WebPEncCSP1 = int32
  15725 
  15726 type WebPEncodingError1 = int32
  15727 
  15728 const MAX_LF_LEVELS = 64
  15729 const MAX_VARIABLE_LEVEL = 67
  15730 const MAX_LEVEL = 2047
  15731 
  15732 type VP8RDLevel = int32
  15733 
  15734 const RD_OPT_NONE = 0
  15735 const RD_OPT_BASIC = 1
  15736 const RD_OPT_TRELLIS = 2
  15737 const RD_OPT_TRELLIS_ALL = 3
  15738 
  15739 type score_t = int64
  15740 
  15741 type proba_t = uint32
  15742 
  15743 type ProbaArray = [3][11]uint8_t
  15744 
  15745 type StatsArray = [3][11]proba_t
  15746 
  15747 type CostArray = [3][68]uint16_t
  15748 
  15749 type CostArrayPtr = uintptr
  15750 
  15751 type CostArrayMap = [16][3]uintptr
  15752 
  15753 type LFStats = [4][64]float64
  15754 
  15755 type VP8Encoder = struct {
  15756 	Fconfig             uintptr
  15757 	Fpic                uintptr
  15758 	Ffilter_hdr         VP8EncFilterHeader
  15759 	Fsegment_hdr        VP8EncSegmentHeader
  15760 	Fprofile            int32
  15761 	Fmb_w               int32
  15762 	Fmb_h               int32
  15763 	Fpreds_w            int32
  15764 	Fnum_parts          int32
  15765 	Fbw                 VP8BitWriter
  15766 	Fparts              [8]VP8BitWriter
  15767 	Ftokens             VP8TBuffer
  15768 	Fpercent            int32
  15769 	Fhas_alpha          int32
  15770 	Falpha_data         uintptr
  15771 	Falpha_data_size    uint32_t
  15772 	Falpha_worker       WebPWorker
  15773 	Fdqm                [4]VP8SegmentInfo
  15774 	Fbase_quant         int32
  15775 	Falpha              int32
  15776 	Fuv_alpha           int32
  15777 	Fdq_y1_dc           int32
  15778 	Fdq_y2_dc           int32
  15779 	Fdq_y2_ac           int32
  15780 	Fdq_uv_dc           int32
  15781 	Fdq_uv_ac           int32
  15782 	Fproba              VP8EncProba
  15783 	Fsse                [4]uint64_t
  15784 	Fsse_count          uint64_t
  15785 	Fcoded_size         int32
  15786 	Fresidual_bytes     [3][4]int32
  15787 	Fblock_count        [3]int32
  15788 	Fmethod             int32
  15789 	Frd_opt_level       VP8RDLevel
  15790 	Fmax_i4_header_bits int32
  15791 	Fmb_header_limit    int32
  15792 	Fthread_level       int32
  15793 	Fdo_search          int32
  15794 	Fuse_tokens         int32
  15795 	Fmb_info            uintptr
  15796 	Fpreds              uintptr
  15797 	Fnz                 uintptr
  15798 	Fy_top              uintptr
  15799 	Fuv_top             uintptr
  15800 	Flf_stats           uintptr
  15801 	Ftop_derr           uintptr
  15802 }
  15803 
  15804 type VP8EncSegmentHeader = struct {
  15805 	Fnum_segments int32
  15806 	Fupdate_map   int32
  15807 	Fsize         int32
  15808 }
  15809 
  15810 type VP8EncProba = struct {
  15811 	Fsegments       [3]uint8_t
  15812 	Fskip_proba     uint8_t
  15813 	Fcoeffs         [4][8]ProbaArray
  15814 	Fstats          [4][8]StatsArray
  15815 	Flevel_cost     [4][8]CostArray
  15816 	Fremapped_costs [4]CostArrayMap
  15817 	Fdirty          int32
  15818 	Fuse_skip_proba int32
  15819 	Fnb_skip        int32
  15820 }
  15821 
  15822 type VP8EncFilterHeader = struct {
  15823 	Fsimple        int32
  15824 	Flevel         int32
  15825 	Fsharpness     int32
  15826 	Fi4x4_lf_delta int32
  15827 }
  15828 
  15829 type VP8MBInfo = struct {
  15830 	F__ccgo_align [0]uint32
  15831 	F__ccgo0      uint8
  15832 	Falpha        uint8_t
  15833 }
  15834 
  15835 type VP8SegmentInfo = struct {
  15836 	Fy1                 VP8Matrix
  15837 	Fy2                 VP8Matrix
  15838 	Fuv                 VP8Matrix
  15839 	Falpha              int32
  15840 	Fbeta               int32
  15841 	Fquant              int32
  15842 	Ffstrength          int32
  15843 	Fmax_edge           int32
  15844 	Fmin_disto          int32
  15845 	Flambda_i16         int32
  15846 	Flambda_i4          int32
  15847 	Flambda_uv          int32
  15848 	Flambda_mode        int32
  15849 	Flambda_trellis     int32
  15850 	Ftlambda            int32
  15851 	Flambda_trellis_i16 int32
  15852 	Flambda_trellis_i4  int32
  15853 	Flambda_trellis_uv  int32
  15854 	Fi4_penalty         score_t
  15855 }
  15856 
  15857 type DError = [2][2]int8_t
  15858 
  15859 type VP8ModeScore = struct {
  15860 	FD           score_t
  15861 	FSD          score_t
  15862 	FH           score_t
  15863 	FR           score_t
  15864 	Fscore       score_t
  15865 	Fy_dc_levels [16]int16_t
  15866 	Fy_ac_levels [16][16]int16_t
  15867 	Fuv_levels   [8][16]int16_t
  15868 	Fmode_i16    int32
  15869 	Fmodes_i4    [16]uint8_t
  15870 	Fmode_uv     int32
  15871 	Fnz          uint32_t
  15872 	Fderr        [2][3]int8_t
  15873 }
  15874 
  15875 type VP8EncIterator = struct {
  15876 	Fx            int32
  15877 	Fy            int32
  15878 	Fyuv_in       uintptr
  15879 	Fyuv_out      uintptr
  15880 	Fyuv_out2     uintptr
  15881 	Fyuv_p        uintptr
  15882 	Fenc          uintptr
  15883 	Fmb           uintptr
  15884 	Fbw           uintptr
  15885 	Fpreds        uintptr
  15886 	Fnz           uintptr
  15887 	Fi4_boundary  [37]uint8_t
  15888 	Fi4_top       uintptr
  15889 	Fi4           int32
  15890 	Ftop_nz       [9]int32
  15891 	Fleft_nz      [9]int32
  15892 	Fbit_count    [4][3]uint64_t
  15893 	Fluma_bits    uint64_t
  15894 	Fuv_bits      uint64_t
  15895 	Flf_stats     uintptr
  15896 	Fdo_trellis   int32
  15897 	Fcount_down   int32
  15898 	Fcount_down0  int32
  15899 	Fpercent0     int32
  15900 	Fleft_derr    DError
  15901 	Ftop_derr     uintptr
  15902 	Fy_left       uintptr
  15903 	Fu_left       uintptr
  15904 	Fv_left       uintptr
  15905 	Fy_top        uintptr
  15906 	Fuv_top       uintptr
  15907 	Fyuv_left_mem [88]uint8_t
  15908 	Fyuv_mem      [3359]uint8_t
  15909 }
  15910 
  15911 type VP8TBuffer = struct {
  15912 	Fpages     uintptr
  15913 	Flast_page uintptr
  15914 	Ftokens    uintptr
  15915 	Fleft      int32
  15916 	Fpage_size int32
  15917 	Ferror1    int32
  15918 }
  15919 
  15920 type Mode = int32
  15921 
  15922 const kLiteral = 0
  15923 const kCacheIdx = 1
  15924 const kCopy = 2
  15925 const kNone = 3
  15926 
  15927 type PixOrCopy = struct {
  15928 	Fmode             uint8_t
  15929 	Flen1             uint16_t
  15930 	Fargb_or_distance uint32_t
  15931 }
  15932 
  15933 type VP8LHashChain = struct {
  15934 	Foffset_length uintptr
  15935 	Fsize          int32
  15936 }
  15937 
  15938 type VP8LBackwardRefs = struct {
  15939 	Fblock_size  int32
  15940 	Ferror1      int32
  15941 	Frefs        uintptr
  15942 	Ftail        uintptr
  15943 	Ffree_blocks uintptr
  15944 	Flast_block  uintptr
  15945 }
  15946 
  15947 type VP8LRefsCursor = struct {
  15948 	Fcur_pos   uintptr
  15949 	Fcur_block uintptr
  15950 	Flast_pos  uintptr
  15951 }
  15952 
  15953 type VP8LLZ77Type = int32
  15954 
  15955 const kLZ77Standard = 1
  15956 const kLZ77RLE = 2
  15957 const kLZ77Box = 4
  15958 
  15959 type VP8LHistogram = struct {
  15960 	Fliteral           uintptr
  15961 	Fred               [256]uint32_t
  15962 	Fblue              [256]uint32_t
  15963 	Falpha             [256]uint32_t
  15964 	Fdistance          [40]uint32_t
  15965 	Fpalette_code_bits int32
  15966 	Ftrivial_symbol    [5]uint16_t
  15967 	Fbit_cost          uint64_t
  15968 	Fcosts             [5]uint64_t
  15969 	Fis_used           [5]uint8_t
  15970 	Fbin_id            uint16_t
  15971 }
  15972 
  15973 type VP8LHistogramSet = struct {
  15974 	Fsize       int32
  15975 	Fmax_size   int32
  15976 	Fhistograms uintptr
  15977 }
  15978 
  15979 type VP8LEncoderARGBContent = int32
  15980 
  15981 const kEncoderNone = 0
  15982 const kEncoderARGB = 1
  15983 const kEncoderNearLossless = 2
  15984 const kEncoderPalette = 3
  15985 
  15986 type VP8LEncoder = struct {
  15987 	Fconfig                     uintptr
  15988 	Fpic                        uintptr
  15989 	Fargb                       uintptr
  15990 	Fargb_content               VP8LEncoderARGBContent
  15991 	Fargb_scratch               uintptr
  15992 	Ftransform_data             uintptr
  15993 	Ftransform_mem              uintptr
  15994 	Ftransform_mem_size         size_t
  15995 	Fcurrent_width              int32
  15996 	Fhisto_bits                 int32
  15997 	Fpredictor_transform_bits   int32
  15998 	Fcross_color_transform_bits int32
  15999 	Fcache_bits                 int32
  16000 	Fuse_cross_color            int32
  16001 	Fuse_subtract_green         int32
  16002 	Fuse_predict                int32
  16003 	Fuse_palette                int32
  16004 	Fpalette_size               int32
  16005 	Fpalette                    [256]uint32_t
  16006 	Fpalette_sorted             [256]uint32_t
  16007 	Frefs                       [4]VP8LBackwardRefs
  16008 	Fhash_chain                 VP8LHashChain
  16009 }
  16010 
  16011 //------------------------------------------------------------------------------
  16012 
  16013 func EncodeLossless(tls *libc.TLS, data uintptr, width int32, height int32, effort_level int32, use_quality_100 int32, bw uintptr, stats uintptr) (r int32) {
  16014 	bp := tls.Alloc(384)
  16015 	defer tls.Free(384)
  16016 	var ok, v1 int32
  16017 	var v5 float32
  16018 	var _ /* config at bp+0 */ WebPConfig
  16019 	var _ /* picture at bp+120 */ WebPPicture
  16020 	_, _, _ = ok, v1, v5
  16021 	ok = 0
  16022 	v1 = WebPPictureInitInternal(tls, bp+120, int32(WEBP_ENCODER_ABI_VERSION))
  16023 	goto _2
  16024 _2:
  16025 	if !(v1 != 0) {
  16026 		return 0
  16027 	}
  16028 	(**(**WebPPicture)(__ccgo_up(bp + 120))).Fwidth = width
  16029 	(**(**WebPPicture)(__ccgo_up(bp + 120))).Fheight = height
  16030 	(**(**WebPPicture)(__ccgo_up(bp + 120))).Fuse_argb = int32(1)
  16031 	(**(**WebPPicture)(__ccgo_up(bp + 120))).Fstats = stats
  16032 	if !(WebPPictureAlloc(tls, bp+120) != 0) {
  16033 		return 0
  16034 	}
  16035 	// Transfer the alpha values to the green channel.
  16036 	(*(*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)
  16037 	v1 = WebPConfigInitInternal(tls, bp, int32(WEBP_PRESET_DEFAULT), libc.Float32FromFloat32(75), int32(WEBP_ENCODER_ABI_VERSION))
  16038 	goto _4
  16039 _4:
  16040 	if !(v1 != 0) {
  16041 		return 0
  16042 	}
  16043 	(**(**WebPConfig)(__ccgo_up(bp))).Flossless = int32(1)
  16044 	// Enable exact, or it would alter RGB values of transparent alpha, which is
  16045 	// normally OK but not here since we are not encoding the input image but  an
  16046 	// internal encoding-related image containing necessary exact information in
  16047 	// RGB channels.
  16048 	(**(**WebPConfig)(__ccgo_up(bp))).Fexact = int32(1)
  16049 	(**(**WebPConfig)(__ccgo_up(bp))).Fmethod = effort_level // impact is very small
  16050 	// Set a low default quality for encoding alpha. Ensure that Alpha quality at
  16051 	// lower methods (3 and below) is less than the threshold for triggering
  16052 	// costly 'BackwardReferencesTraceBackwards'.
  16053 	// If the alpha quality is set to 100 and the method to 6, allow for a high
  16054 	// lossless quality to trigger the cruncher.
  16055 	if use_quality_100 != 0 && effort_level == int32(6) {
  16056 		v5 = libc.Float32FromInt32(100)
  16057 	} else {
  16058 		v5 = float32(libc.Float32FromFloat32(8) * float32(effort_level))
  16059 	}
  16060 	(**(**WebPConfig)(__ccgo_up(bp))).Fquality = v5
  16061 	ok = VP8LEncodeStream(tls, bp, bp+120, bw)
  16062 	WebPPictureFree(tls, bp+120)
  16063 	ok = libc.BoolInt32(ok != 0 && !((*VP8LBitWriter)(unsafe.Pointer(bw)).Ferror1 != 0))
  16064 	if !(ok != 0) {
  16065 		VP8LBitWriterWipeOut(tls, bw)
  16066 		return 0
  16067 	}
  16068 	return int32(1)
  16069 }
  16070 
  16071 // -----------------------------------------------------------------------------
  16072 
  16073 // C documentation
  16074 //
  16075 //	// Small struct to hold the result of a filter mode compression attempt.
  16076 type FilterTrial = struct {
  16077 	Fscore size_t
  16078 	Fbw    VP8BitWriter
  16079 	Fstats WebPAuxStats
  16080 }
  16081 
  16082 // C documentation
  16083 //
  16084 //	// This function always returns an initialized 'bw' object, even upon error.
  16085 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) {
  16086 	bp := tls.Alloc(64)
  16087 	defer tls.Free(64)
  16088 	var alpha_src, output, v1 uintptr
  16089 	var data_size, output_size, v2 size_t
  16090 	var filter_func WebPFilterFunc
  16091 	var ok int32
  16092 	var _ /* header at bp+0 */ uint8_t
  16093 	var _ /* tmp_bw at bp+8 */ VP8LBitWriter
  16094 	_, _, _, _, _, _, _, _ = alpha_src, data_size, filter_func, ok, output, output_size, v1, v2
  16095 	ok = 0
  16096 	data_size = uint64(width * height)
  16097 	output = libc.UintptrFromInt32(0)
  16098 	output_size = uint64(0)
  16099 	// as per spec
  16100 	filter_func = WebPFilters[filter]
  16101 	if filter_func != libc.UintptrFromInt32(0) {
  16102 		(*(*func(*libc.TLS, uintptr, int32, int32, int32, uintptr))(unsafe.Pointer(&struct{ uintptr }{filter_func})))(tls, data, width, height, width, tmp_alpha)
  16103 		alpha_src = tmp_alpha
  16104 	} else {
  16105 		alpha_src = data
  16106 	}
  16107 	if method != ALPHA_NO_COMPRESSION {
  16108 		ok = VP8LBitWriterInit(tls, bp+8, data_size>>int32(3))
  16109 		ok = libc.BoolInt32(ok != 0 && EncodeLossless(tls, alpha_src, width, height, effort_level, libc.BoolInt32(!(reduce_levels != 0)), bp+8, result+56) != 0)
  16110 		if ok != 0 {
  16111 			output = VP8LBitWriterFinish(tls, bp+8)
  16112 			if (**(**VP8LBitWriter)(__ccgo_up(bp + 8))).Ferror1 != 0 {
  16113 				VP8LBitWriterWipeOut(tls, bp+8)
  16114 				libc.Xmemset(tls, result+8, 0, uint64(48))
  16115 				return 0
  16116 			}
  16117 			v1 = bp + 8
  16118 			v2 = uint64(int64((*VP8LBitWriter)(unsafe.Pointer(v1)).Fcur) - int64((*VP8LBitWriter)(unsafe.Pointer(v1)).Fbuf) + int64(((*VP8LBitWriter)(unsafe.Pointer(v1)).Fused+libc.Int32FromInt32(7))>>libc.Int32FromInt32(3)))
  16119 			goto _3
  16120 		_3:
  16121 			output_size = v2
  16122 			if output_size > data_size {
  16123 				// compressed size is larger than source! Revert to uncompressed mode.
  16124 				method = ALPHA_NO_COMPRESSION
  16125 				VP8LBitWriterWipeOut(tls, bp+8)
  16126 			}
  16127 		} else {
  16128 			VP8LBitWriterWipeOut(tls, bp+8)
  16129 			libc.Xmemset(tls, result+8, 0, uint64(48))
  16130 			return 0
  16131 		}
  16132 	}
  16133 	if method == ALPHA_NO_COMPRESSION {
  16134 		output = alpha_src
  16135 		output_size = data_size
  16136 		ok = int32(1)
  16137 	}
  16138 	// Emit final result.
  16139 	**(**uint8_t)(__ccgo_up(bp)) = uint8(method | filter<<int32(2))
  16140 	if reduce_levels != 0 {
  16141 		**(**uint8_t)(__ccgo_up(bp)) = uint8(int32(**(**uint8_t)(__ccgo_up(bp))) | libc.Int32FromInt32(ALPHA_PREPROCESSED_LEVELS)<<libc.Int32FromInt32(4))
  16142 	}
  16143 	if !(VP8BitWriterInit(tls, result+8, uint64(ALPHA_HEADER_LEN)+output_size) != 0) {
  16144 		ok = 0
  16145 	}
  16146 	ok = libc.BoolInt32(ok != 0 && VP8BitWriterAppend(tls, result+8, bp, uint64(ALPHA_HEADER_LEN)) != 0)
  16147 	ok = libc.BoolInt32(ok != 0 && VP8BitWriterAppend(tls, result+8, output, output_size) != 0)
  16148 	if method != ALPHA_NO_COMPRESSION {
  16149 		VP8LBitWriterWipeOut(tls, bp+8)
  16150 	}
  16151 	ok = libc.BoolInt32(ok != 0 && !((*FilterTrial)(unsafe.Pointer(result)).Fbw.Ferror1 != 0))
  16152 	v2 = (*VP8BitWriter)(unsafe.Pointer(result + 8)).Fpos
  16153 	goto _5
  16154 _5:
  16155 	(*FilterTrial)(unsafe.Pointer(result)).Fscore = v2
  16156 	return ok
  16157 }
  16158 
  16159 // -----------------------------------------------------------------------------
  16160 
  16161 func GetNumColors(tls *libc.TLS, data uintptr, width int32, height int32, stride int32) (r int32) {
  16162 	var color [256]uint8_t
  16163 	var colors, i, j int32
  16164 	var p uintptr
  16165 	_, _, _, _, _ = color, colors, i, j, p
  16166 	colors = 0
  16167 	color = [256]uint8_t{}
  16168 	j = 0
  16169 	for {
  16170 		if !(j < height) {
  16171 			break
  16172 		}
  16173 		p = data + uintptr(j*stride)
  16174 		i = 0
  16175 		for {
  16176 			if !(i < width) {
  16177 				break
  16178 			}
  16179 			color[**(**uint8_t)(__ccgo_up(p + uintptr(i)))] = uint8(1)
  16180 			goto _2
  16181 		_2:
  16182 			;
  16183 			i = i + 1
  16184 		}
  16185 		goto _1
  16186 	_1:
  16187 		;
  16188 		j = j + 1
  16189 	}
  16190 	j = 0
  16191 	for {
  16192 		if !(j < int32(256)) {
  16193 			break
  16194 		}
  16195 		if int32(color[j]) > 0 {
  16196 			colors = colors + 1
  16197 		}
  16198 		goto _3
  16199 	_3:
  16200 		;
  16201 		j = j + 1
  16202 	}
  16203 	return colors
  16204 }
  16205 
  16206 // C documentation
  16207 //
  16208 //	// Given the input 'filter' option, return an OR'd bit-set of filters to try.
  16209 func GetFilterMap(tls *libc.TLS, alpha uintptr, width int32, height int32, filter int32, effort_level int32) (r uint32_t) {
  16210 	var bit_map uint32_t
  16211 	var kMaxColorsForFilterNone, kMinColorsForFilterNone, num_colors, try_filter_none, v1 int32
  16212 	_, _, _, _, _, _ = bit_map, kMaxColorsForFilterNone, kMinColorsForFilterNone, num_colors, try_filter_none, v1
  16213 	bit_map = 0
  16214 	if filter == int32(WEBP_FILTER_FAST) {
  16215 		// Quick estimate of the best candidate.
  16216 		try_filter_none = libc.BoolInt32(effort_level > int32(3))
  16217 		kMinColorsForFilterNone = int32(16)
  16218 		kMaxColorsForFilterNone = int32(192)
  16219 		num_colors = GetNumColors(tls, alpha, width, height, width)
  16220 		// For low number of colors, NONE yields better compression.
  16221 		if num_colors <= kMinColorsForFilterNone {
  16222 			v1 = int32(WEBP_FILTER_NONE)
  16223 		} else {
  16224 			v1 = WebPEstimateBestFilter(tls, alpha, width, height, width)
  16225 		}
  16226 		filter = v1
  16227 		bit_map = bit_map | uint32(int32(1)<<filter)
  16228 		// For large number of colors, try FILTER_NONE in addition to the best
  16229 		// filter as well.
  16230 		if try_filter_none != 0 || num_colors > kMaxColorsForFilterNone {
  16231 			bit_map = bit_map | uint32(libc.Int32FromInt32(1)<<int32(WEBP_FILTER_NONE))
  16232 		}
  16233 	} else {
  16234 		if filter == int32(WEBP_FILTER_NONE) {
  16235 			bit_map = uint32(libc.Int32FromInt32(1) << int32(WEBP_FILTER_NONE))
  16236 		} else { // WEBP_FILTER_BEST -> try all
  16237 			bit_map = uint32(libc.Int32FromInt32(1)<<int32(WEBP_FILTER_LAST) - libc.Int32FromInt32(1))
  16238 		}
  16239 	}
  16240 	return bit_map
  16241 }
  16242 
  16243 func InitFilterTrial(tls *libc.TLS, score uintptr) {
  16244 	(*FilterTrial)(unsafe.Pointer(score)).Fscore = uint64(^libc.Uint32FromUint32(0))
  16245 	VP8BitWriterInit(tls, score+8, uint64(0))
  16246 }
  16247 
  16248 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) {
  16249 	bp := tls.Alloc(496)
  16250 	defer tls.Free(496)
  16251 	var filtered_alpha, v4 uintptr
  16252 	var ok int32
  16253 	var try_map uint32_t
  16254 	var v2 size_t
  16255 	var _ /* best at bp+0 */ FilterTrial
  16256 	var _ /* trial at bp+248 */ FilterTrial
  16257 	_, _, _, _, _ = filtered_alpha, ok, try_map, v2, v4
  16258 	ok = int32(1)
  16259 	try_map = GetFilterMap(tls, alpha, width, height, filter, effort_level)
  16260 	InitFilterTrial(tls, bp)
  16261 	if try_map != uint32(libc.Int32FromInt32(1)<<int32(WEBP_FILTER_NONE)) {
  16262 		filtered_alpha = WebPSafeMalloc(tls, uint64(1), data_size)
  16263 		if filtered_alpha == libc.UintptrFromInt32(0) {
  16264 			return 0
  16265 		}
  16266 		filter = int32(WEBP_FILTER_NONE)
  16267 		for {
  16268 			if !(ok != 0 && try_map != 0) {
  16269 				break
  16270 			}
  16271 			if try_map&uint32(1) != 0 {
  16272 				ok = EncodeAlphaInternal(tls, alpha, width, height, method, filter, reduce_levels, effort_level, filtered_alpha, bp+248)
  16273 				if ok != 0 && (**(**FilterTrial)(__ccgo_up(bp + 248))).Fscore < (**(**FilterTrial)(__ccgo_up(bp))).Fscore {
  16274 					VP8BitWriterWipeOut(tls, bp+8)
  16275 					**(**FilterTrial)(__ccgo_up(bp)) = **(**FilterTrial)(__ccgo_up(bp + 248))
  16276 				} else {
  16277 					VP8BitWriterWipeOut(tls, bp+248+8)
  16278 				}
  16279 			}
  16280 			goto _1
  16281 		_1:
  16282 			;
  16283 			filter = filter + 1
  16284 			try_map = try_map >> uint32(1)
  16285 		}
  16286 		WebPSafeFree(tls, filtered_alpha)
  16287 	} else {
  16288 		ok = EncodeAlphaInternal(tls, alpha, width, height, method, int32(WEBP_FILTER_NONE), reduce_levels, effort_level, libc.UintptrFromInt32(0), bp)
  16289 	}
  16290 	if ok != 0 {
  16291 		if stats != libc.UintptrFromInt32(0) {
  16292 			(*WebPAuxStats)(unsafe.Pointer(stats)).Flossless_features = (**(**FilterTrial)(__ccgo_up(bp))).Fstats.Flossless_features
  16293 			(*WebPAuxStats)(unsafe.Pointer(stats)).Fhistogram_bits = (**(**FilterTrial)(__ccgo_up(bp))).Fstats.Fhistogram_bits
  16294 			(*WebPAuxStats)(unsafe.Pointer(stats)).Ftransform_bits = (**(**FilterTrial)(__ccgo_up(bp))).Fstats.Ftransform_bits
  16295 			(*WebPAuxStats)(unsafe.Pointer(stats)).Fcross_color_transform_bits = (**(**FilterTrial)(__ccgo_up(bp))).Fstats.Fcross_color_transform_bits
  16296 			(*WebPAuxStats)(unsafe.Pointer(stats)).Fcache_bits = (**(**FilterTrial)(__ccgo_up(bp))).Fstats.Fcache_bits
  16297 			(*WebPAuxStats)(unsafe.Pointer(stats)).Fpalette_size = (**(**FilterTrial)(__ccgo_up(bp))).Fstats.Fpalette_size
  16298 			(*WebPAuxStats)(unsafe.Pointer(stats)).Flossless_size = (**(**FilterTrial)(__ccgo_up(bp))).Fstats.Flossless_size
  16299 			(*WebPAuxStats)(unsafe.Pointer(stats)).Flossless_hdr_size = (**(**FilterTrial)(__ccgo_up(bp))).Fstats.Flossless_hdr_size
  16300 			(*WebPAuxStats)(unsafe.Pointer(stats)).Flossless_data_size = (**(**FilterTrial)(__ccgo_up(bp))).Fstats.Flossless_data_size
  16301 		}
  16302 		v2 = (*VP8BitWriter)(unsafe.Pointer(bp + 8)).Fpos
  16303 		goto _3
  16304 	_3:
  16305 		**(**size_t)(__ccgo_up(output_size)) = v2
  16306 		v4 = (*VP8BitWriter)(unsafe.Pointer(bp + 8)).Fbuf
  16307 		goto _5
  16308 	_5:
  16309 		**(**uintptr)(__ccgo_up(output)) = v4
  16310 	} else {
  16311 		VP8BitWriterWipeOut(tls, bp+8)
  16312 	}
  16313 	return ok
  16314 }
  16315 
  16316 func EncodeAlpha(tls *libc.TLS, enc uintptr, quality int32, method int32, filter int32, effort_level int32, output uintptr, output_size uintptr) (r int32) {
  16317 	bp := tls.Alloc(16)
  16318 	defer tls.Free(16)
  16319 	var alpha_levels, height, ok, reduce_levels, width, v1 int32
  16320 	var data_size size_t
  16321 	var pic, quant_alpha uintptr
  16322 	var _ /* sse at bp+0 */ uint64_t
  16323 	_, _, _, _, _, _, _, _, _ = alpha_levels, data_size, height, ok, pic, quant_alpha, reduce_levels, width, v1
  16324 	pic = (*VP8Encoder)(unsafe.Pointer(enc)).Fpic
  16325 	width = (*WebPPicture)(unsafe.Pointer(pic)).Fwidth
  16326 	height = (*WebPPicture)(unsafe.Pointer(pic)).Fheight
  16327 	quant_alpha = libc.UintptrFromInt32(0)
  16328 	data_size = uint64(width * height)
  16329 	**(**uint64_t)(__ccgo_up(bp)) = uint64(0)
  16330 	ok = int32(1)
  16331 	reduce_levels = libc.BoolInt32(quality < libc.Int32FromInt32(100))
  16332 	// quick correctness checks
  16333 	// as per spec
  16334 	if quality < 0 || quality > int32(100) {
  16335 		return WebPEncodingSetError(tls, pic, int32(VP8_ENC_ERROR_INVALID_CONFIGURATION))
  16336 	}
  16337 	if method < ALPHA_NO_COMPRESSION || method > int32(ALPHA_LOSSLESS_COMPRESSION) {
  16338 		return WebPEncodingSetError(tls, pic, int32(VP8_ENC_ERROR_INVALID_CONFIGURATION))
  16339 	}
  16340 	if method == ALPHA_NO_COMPRESSION {
  16341 		// Don't filter, as filtering will make no impact on compressed size.
  16342 		filter = int32(WEBP_FILTER_NONE)
  16343 	}
  16344 	quant_alpha = WebPSafeMalloc(tls, uint64(1), data_size)
  16345 	if quant_alpha == libc.UintptrFromInt32(0) {
  16346 		return WebPEncodingSetError(tls, pic, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  16347 	}
  16348 	// Extract alpha data (width x height) from raw_data (stride x height).
  16349 	WebPCopyPlane(tls, (*WebPPicture)(unsafe.Pointer(pic)).Fa, (*WebPPicture)(unsafe.Pointer(pic)).Fa_stride, quant_alpha, width, width, height)
  16350 	if reduce_levels != 0 {
  16351 		if quality <= int32(70) {
  16352 			v1 = int32(2) + quality/int32(5)
  16353 		} else {
  16354 			v1 = int32(16) + (quality-int32(70))*int32(8)
  16355 		} // No Quantization required for 'quality = 100'.
  16356 		// 16 alpha levels gives quite a low MSE w.r.t original alpha plane hence
  16357 		// mapped to moderate quality 70. Hence Quality:[0, 70] -> Levels:[2, 16]
  16358 		// and Quality:]70, 100] -> Levels:]16, 256].
  16359 		alpha_levels = v1
  16360 		ok = QuantizeLevels(tls, quant_alpha, width, height, alpha_levels, bp)
  16361 	}
  16362 	if ok != 0 {
  16363 		VP8FiltersInit(tls)
  16364 		ok = ApplyFiltersAndEncode(tls, quant_alpha, width, height, data_size, method, filter, reduce_levels, effort_level, output, output_size, (*WebPPicture)(unsafe.Pointer(pic)).Fstats)
  16365 		if !(ok != 0) {
  16366 			WebPEncodingSetError(tls, pic, int32(VP8_ENC_ERROR_OUT_OF_MEMORY)) // imprecise
  16367 		}
  16368 		if (*WebPPicture)(unsafe.Pointer(pic)).Fstats != libc.UintptrFromInt32(0) { // need stats?
  16369 			**(**int32)(__ccgo_up((*WebPPicture)(unsafe.Pointer(pic)).Fstats)) += int32(**(**size_t)(__ccgo_up(output_size)))
  16370 			**(**uint64_t)(__ccgo_up(enc + 23512 + 3*8)) = **(**uint64_t)(__ccgo_up(bp))
  16371 		}
  16372 	}
  16373 	WebPSafeFree(tls, quant_alpha)
  16374 	return ok
  16375 }
  16376 
  16377 //------------------------------------------------------------------------------
  16378 // Main calls
  16379 
  16380 func CompressAlphaJob(tls *libc.TLS, arg1 uintptr, unused uintptr) (r int32) {
  16381 	bp := tls.Alloc(16)
  16382 	defer tls.Free(16)
  16383 	var config, enc uintptr
  16384 	var effort_level, v1, v2 int32
  16385 	var filter WEBP_FILTER_TYPE
  16386 	var _ /* alpha_data at bp+0 */ uintptr
  16387 	var _ /* alpha_size at bp+8 */ size_t
  16388 	_, _, _, _, _, _ = config, effort_level, enc, filter, v1, v2
  16389 	enc = arg1
  16390 	config = (*VP8Encoder)(unsafe.Pointer(enc)).Fconfig
  16391 	**(**uintptr)(__ccgo_up(bp)) = libc.UintptrFromInt32(0)
  16392 	**(**size_t)(__ccgo_up(bp + 8)) = uint64(0)
  16393 	effort_level = (*WebPConfig)(unsafe.Pointer(config)).Fmethod
  16394 	if (*WebPConfig)(unsafe.Pointer(config)).Falpha_filtering == 0 {
  16395 		v1 = int32(WEBP_FILTER_NONE)
  16396 	} else {
  16397 		if (*WebPConfig)(unsafe.Pointer(config)).Falpha_filtering == int32(1) {
  16398 			v2 = int32(WEBP_FILTER_FAST)
  16399 		} else {
  16400 			v2 = int32(WEBP_FILTER_BEST)
  16401 		}
  16402 		v1 = v2
  16403 	} // maps to [0..6]
  16404 	filter = v1
  16405 	if !(EncodeAlpha(tls, enc, (*WebPConfig)(unsafe.Pointer(config)).Falpha_quality, (*WebPConfig)(unsafe.Pointer(config)).Falpha_compression, filter, effort_level, bp, bp+8) != 0) {
  16406 		return 0
  16407 	}
  16408 	if **(**size_t)(__ccgo_up(bp + 8)) != uint64(uint32(**(**size_t)(__ccgo_up(bp + 8)))) { // Soundness check.
  16409 		WebPSafeFree(tls, **(**uintptr)(__ccgo_up(bp)))
  16410 		return 0
  16411 	}
  16412 	(*VP8Encoder)(unsafe.Pointer(enc)).Falpha_data_size = uint32(**(**size_t)(__ccgo_up(bp + 8)))
  16413 	(*VP8Encoder)(unsafe.Pointer(enc)).Falpha_data = **(**uintptr)(__ccgo_up(bp))
  16414 	_ = unused
  16415 	return int32(1)
  16416 }
  16417 
  16418 func VP8EncInitAlpha(tls *libc.TLS, enc uintptr) {
  16419 	var worker uintptr
  16420 	_ = worker
  16421 	WebPInitAlphaProcessing(tls)
  16422 	(*VP8Encoder)(unsafe.Pointer(enc)).Fhas_alpha = WebPPictureHasTransparency(tls, (*VP8Encoder)(unsafe.Pointer(enc)).Fpic)
  16423 	(*VP8Encoder)(unsafe.Pointer(enc)).Falpha_data = libc.UintptrFromInt32(0)
  16424 	(*VP8Encoder)(unsafe.Pointer(enc)).Falpha_data_size = uint32(0)
  16425 	if (*VP8Encoder)(unsafe.Pointer(enc)).Fthread_level > 0 {
  16426 		worker = enc + 560
  16427 		(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(&struct{ uintptr }{(*WebPWorkerInterface)(unsafe.Pointer(WebPGetWorkerInterface(tls))).FInit})))(tls, worker)
  16428 		(*WebPWorker)(unsafe.Pointer(worker)).Fdata1 = enc
  16429 		(*WebPWorker)(unsafe.Pointer(worker)).Fdata2 = libc.UintptrFromInt32(0)
  16430 		(*WebPWorker)(unsafe.Pointer(worker)).Fhook = __ccgo_fp(CompressAlphaJob)
  16431 	}
  16432 }
  16433 
  16434 func VP8EncStartAlpha(tls *libc.TLS, enc uintptr) (r int32) {
  16435 	var worker uintptr
  16436 	_ = worker
  16437 	if (*VP8Encoder)(unsafe.Pointer(enc)).Fhas_alpha != 0 {
  16438 		if (*VP8Encoder)(unsafe.Pointer(enc)).Fthread_level > 0 {
  16439 			worker = enc + 560
  16440 			// Makes sure worker is good to go.
  16441 			if !((*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*WebPWorkerInterface)(unsafe.Pointer(WebPGetWorkerInterface(tls))).FReset})))(tls, worker) != 0) {
  16442 				return WebPEncodingSetError(tls, (*VP8Encoder)(unsafe.Pointer(enc)).Fpic, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  16443 			}
  16444 			(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(&struct{ uintptr }{(*WebPWorkerInterface)(unsafe.Pointer(WebPGetWorkerInterface(tls))).FLaunch})))(tls, worker)
  16445 			return int32(1)
  16446 		} else {
  16447 			return CompressAlphaJob(tls, enc, libc.UintptrFromInt32(0)) // just do the job right away
  16448 		}
  16449 	}
  16450 	return int32(1)
  16451 }
  16452 
  16453 func VP8EncFinishAlpha(tls *libc.TLS, enc uintptr) (r int32) {
  16454 	var worker uintptr
  16455 	_ = worker
  16456 	if (*VP8Encoder)(unsafe.Pointer(enc)).Fhas_alpha != 0 {
  16457 		if (*VP8Encoder)(unsafe.Pointer(enc)).Fthread_level > 0 {
  16458 			worker = enc + 560
  16459 			if !((*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*WebPWorkerInterface)(unsafe.Pointer(WebPGetWorkerInterface(tls))).FSync})))(tls, worker) != 0) {
  16460 				return 0
  16461 			} // error
  16462 		}
  16463 	}
  16464 	return WebPReportProgress(tls, (*VP8Encoder)(unsafe.Pointer(enc)).Fpic, (*VP8Encoder)(unsafe.Pointer(enc)).Fpercent+int32(20), enc+536)
  16465 }
  16466 
  16467 func VP8EncDeleteAlpha(tls *libc.TLS, enc uintptr) (r int32) {
  16468 	var ok int32
  16469 	var worker uintptr
  16470 	_, _ = ok, worker
  16471 	ok = int32(1)
  16472 	if (*VP8Encoder)(unsafe.Pointer(enc)).Fthread_level > 0 {
  16473 		worker = enc + 560
  16474 		// finish anything left in flight
  16475 		ok = (*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*WebPWorkerInterface)(unsafe.Pointer(WebPGetWorkerInterface(tls))).FSync})))(tls, worker)
  16476 		// still need to end the worker, even if !ok
  16477 		(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(&struct{ uintptr }{(*WebPWorkerInterface)(unsafe.Pointer(WebPGetWorkerInterface(tls))).FEnd})))(tls, worker)
  16478 	}
  16479 	WebPSafeFree(tls, (*VP8Encoder)(unsafe.Pointer(enc)).Falpha_data)
  16480 	(*VP8Encoder)(unsafe.Pointer(enc)).Falpha_data = libc.UintptrFromInt32(0)
  16481 	(*VP8Encoder)(unsafe.Pointer(enc)).Falpha_data_size = uint32(0)
  16482 	(*VP8Encoder)(unsafe.Pointer(enc)).Fhas_alpha = 0
  16483 	return ok
  16484 }
  16485 
  16486 const MAX_ALPHA = 255
  16487 const MAX_INTRA16_MODE = 2
  16488 const MAX_INTRA4_MODE = 2
  16489 const MAX_ITERS_K_MEANS = 6
  16490 const MAX_UV_MODE = 2
  16491 
  16492 //------------------------------------------------------------------------------
  16493 
  16494 // Copyright 2011 Google Inc. All Rights Reserved.
  16495 //
  16496 // Use of this source code is governed by a BSD-style license
  16497 // that can be found in the COPYING file in the root of the source
  16498 // tree. An additional intellectual property rights grant can be found
  16499 // in the file PATENTS. All contributing project authors may
  16500 // be found in the AUTHORS file in the root of the source tree.
  16501 // -----------------------------------------------------------------------------
  16502 //
  16503 // Multi-threaded worker
  16504 //
  16505 // Author: Skal (pascal.massimino@gmail.com)
  16506 
  16507 // Copyright 2012 Google Inc. All Rights Reserved.
  16508 //
  16509 // Use of this source code is governed by a BSD-style license
  16510 // that can be found in the COPYING file in the root of the source
  16511 // tree. An additional intellectual property rights grant can be found
  16512 // in the file PATENTS. All contributing project authors may
  16513 // be found in the AUTHORS file in the root of the source tree.
  16514 // -----------------------------------------------------------------------------
  16515 //
  16516 // Misc. common utility functions
  16517 //
  16518 // Authors: Skal (pascal.massimino@gmail.com)
  16519 //          Urvang (urvang@google.com)
  16520 
  16521 // Copyright 2011 Google Inc. All Rights Reserved.
  16522 //
  16523 // Use of this source code is governed by a BSD-style license
  16524 // that can be found in the COPYING file in the root of the source
  16525 // tree. An additional intellectual property rights grant can be found
  16526 // in the file PATENTS. All contributing project authors may
  16527 // be found in the AUTHORS file in the root of the source tree.
  16528 // -----------------------------------------------------------------------------
  16529 //
  16530 //   WebP encoder: main interface
  16531 //
  16532 // Author: Skal (pascal.massimino@gmail.com)
  16533 
  16534 // Copyright 2010 Google Inc. All Rights Reserved.
  16535 //
  16536 // Use of this source code is governed by a BSD-style license
  16537 // that can be found in the COPYING file in the root of the source
  16538 // tree. An additional intellectual property rights grant can be found
  16539 // in the file PATENTS. All contributing project authors may
  16540 // be found in the AUTHORS file in the root of the source tree.
  16541 // -----------------------------------------------------------------------------
  16542 //
  16543 //  Common types + memory wrappers
  16544 //
  16545 // Author: Skal (pascal.massimino@gmail.com)
  16546 
  16547 //------------------------------------------------------------------------------
  16548 // Smooth the segment map by replacing isolated block by the majority of its
  16549 // neighbours.
  16550 
  16551 func SmoothSegmentMap(tls *libc.TLS, enc uintptr) {
  16552 	var cnt [4]int32
  16553 	var h, majority_cnt_3_x_3_grid, majority_seg, n, w, x, y int32
  16554 	var mb, mb1, tmp uintptr
  16555 	_, _, _, _, _, _, _, _, _, _, _ = cnt, h, majority_cnt_3_x_3_grid, majority_seg, mb, mb1, n, tmp, w, x, y
  16556 	w = (*VP8Encoder)(unsafe.Pointer(enc)).Fmb_w
  16557 	h = (*VP8Encoder)(unsafe.Pointer(enc)).Fmb_h
  16558 	majority_cnt_3_x_3_grid = int32(5)
  16559 	tmp = WebPSafeMalloc(tls, uint64(w*h), uint64(1))
  16560 	// no overflow, as per spec
  16561 	if tmp == libc.UintptrFromInt32(0) {
  16562 		return
  16563 	}
  16564 	y = int32(1)
  16565 	for {
  16566 		if !(y < h-int32(1)) {
  16567 			break
  16568 		}
  16569 		x = int32(1)
  16570 		for {
  16571 			if !(x < w-int32(1)) {
  16572 				break
  16573 			}
  16574 			cnt = [4]int32{}
  16575 			mb = (*VP8Encoder)(unsafe.Pointer(enc)).Fmb_info + uintptr(x+w*y)*4
  16576 			majority_seg = int32(uint32(*(*uint8)(unsafe.Pointer(mb + 0)) & 0x60 >> 5))
  16577 			// Check the 8 neighbouring segment values.
  16578 			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
  16579 			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
  16580 			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
  16581 			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
  16582 			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
  16583 			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
  16584 			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
  16585 			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
  16586 			n = 0
  16587 			for {
  16588 				if !(n < int32(NUM_MB_SEGMENTS)) {
  16589 					break
  16590 				}
  16591 				if cnt[n] >= majority_cnt_3_x_3_grid {
  16592 					majority_seg = n
  16593 					break
  16594 				}
  16595 				goto _3
  16596 			_3:
  16597 				;
  16598 				n = n + 1
  16599 			}
  16600 			**(**uint8_t)(__ccgo_up(tmp + uintptr(x+y*w))) = uint8(majority_seg)
  16601 			goto _2
  16602 		_2:
  16603 			;
  16604 			x = x + 1
  16605 		}
  16606 		goto _1
  16607 	_1:
  16608 		;
  16609 		y = y + 1
  16610 	}
  16611 	y = int32(1)
  16612 	for {
  16613 		if !(y < h-int32(1)) {
  16614 			break
  16615 		}
  16616 		x = int32(1)
  16617 		for {
  16618 			if !(x < w-int32(1)) {
  16619 				break
  16620 			}
  16621 			mb1 = (*VP8Encoder)(unsafe.Pointer(enc)).Fmb_info + uintptr(x+w*y)*4
  16622 			libc.SetBitFieldPtr8Uint32(mb1+0, uint32(**(**uint8_t)(__ccgo_up(tmp + uintptr(x+y*w)))), 5, 0x60)
  16623 			goto _5
  16624 		_5:
  16625 			;
  16626 			x = x + 1
  16627 		}
  16628 		goto _4
  16629 	_4:
  16630 		;
  16631 		y = y + 1
  16632 	}
  16633 	WebPSafeFree(tls, tmp)
  16634 }
  16635 
  16636 //------------------------------------------------------------------------------
  16637 // set segment susceptibility 'alpha' / 'beta'
  16638 
  16639 func clip1(tls *libc.TLS, v int32, m int32, M int32) (r int32) {
  16640 	var v1, v2 int32
  16641 	_, _ = v1, v2
  16642 	if v < m {
  16643 		v1 = m
  16644 	} else {
  16645 		if v > M {
  16646 			v2 = M
  16647 		} else {
  16648 			v2 = v
  16649 		}
  16650 		v1 = v2
  16651 	}
  16652 	return v1
  16653 }
  16654 
  16655 func SetSegmentAlphas(tls *libc.TLS, enc uintptr, centers uintptr, mid int32) {
  16656 	var alpha, beta, max, min, n, nb int32
  16657 	_, _, _, _, _, _ = alpha, beta, max, min, n, nb
  16658 	nb = (*VP8Encoder)(unsafe.Pointer(enc)).Fsegment_hdr.Fnum_segments
  16659 	min = **(**int32)(__ccgo_up(centers))
  16660 	max = **(**int32)(__ccgo_up(centers))
  16661 	if nb > int32(1) {
  16662 		n = 0
  16663 		for {
  16664 			if !(n < nb) {
  16665 				break
  16666 			}
  16667 			if min > **(**int32)(__ccgo_up(centers + uintptr(n)*4)) {
  16668 				min = **(**int32)(__ccgo_up(centers + uintptr(n)*4))
  16669 			}
  16670 			if max < **(**int32)(__ccgo_up(centers + uintptr(n)*4)) {
  16671 				max = **(**int32)(__ccgo_up(centers + uintptr(n)*4))
  16672 			}
  16673 			goto _1
  16674 		_1:
  16675 			;
  16676 			n = n + 1
  16677 		}
  16678 	}
  16679 	if max == min {
  16680 		max = min + int32(1)
  16681 	}
  16682 	n = 0
  16683 	for {
  16684 		if !(n < nb) {
  16685 			break
  16686 		}
  16687 		alpha = int32(255) * (**(**int32)(__ccgo_up(centers + uintptr(n)*4)) - mid) / (max - min)
  16688 		beta = int32(255) * (**(**int32)(__ccgo_up(centers + uintptr(n)*4)) - min) / (max - min)
  16689 		(**(**VP8SegmentInfo)(__ccgo_up(enc + 608 + uintptr(n)*744))).Falpha = clip1(tls, alpha, -int32(127), int32(127))
  16690 		(**(**VP8SegmentInfo)(__ccgo_up(enc + 608 + uintptr(n)*744))).Fbeta = clip1(tls, beta, 0, int32(255))
  16691 		goto _2
  16692 	_2:
  16693 		;
  16694 		n = n + 1
  16695 	}
  16696 }
  16697 
  16698 //------------------------------------------------------------------------------
  16699 // Compute susceptibility based on DCT-coeff histograms:
  16700 // the higher, the "easier" the macroblock is to compress.
  16701 
  16702 func FinalAlphaValue(tls *libc.TLS, alpha int32) (r int32) {
  16703 	alpha = int32(MAX_ALPHA) - alpha
  16704 	return clip1(tls, alpha, 0, int32(MAX_ALPHA))
  16705 }
  16706 
  16707 func GetAlpha(tls *libc.TLS, histo uintptr) (r int32) {
  16708 	var alpha, last_non_zero, max_value, v1 int32
  16709 	_, _, _, _ = alpha, last_non_zero, max_value, v1
  16710 	// 'alpha' will later be clipped to [0..MAX_ALPHA] range, clamping outer
  16711 	// values which happen to be mostly noise. This leaves the maximum precision
  16712 	// for handling the useful small values which contribute most.
  16713 	max_value = (*VP8Histogram)(unsafe.Pointer(histo)).Fmax_value
  16714 	last_non_zero = (*VP8Histogram)(unsafe.Pointer(histo)).Flast_non_zero
  16715 	if max_value > int32(1) {
  16716 		v1 = libc.Int32FromInt32(2) * libc.Int32FromInt32(MAX_ALPHA) * last_non_zero / max_value
  16717 	} else {
  16718 		v1 = 0
  16719 	}
  16720 	alpha = v1
  16721 	return alpha
  16722 }
  16723 
  16724 func InitHistogram(tls *libc.TLS, histo uintptr) {
  16725 	(*VP8Histogram)(unsafe.Pointer(histo)).Fmax_value = 0
  16726 	(*VP8Histogram)(unsafe.Pointer(histo)).Flast_non_zero = int32(1)
  16727 }
  16728 
  16729 //------------------------------------------------------------------------------
  16730 // Simplified k-Means, to assign Nb segments based on alpha-histogram
  16731 
  16732 func AssignSegments(tls *libc.TLS, enc uintptr, alphas uintptr) {
  16733 	bp := tls.Alloc(48)
  16734 	defer tls.Free(48)
  16735 	var a, alpha, displaced, k, max_a, min_a, n, nb, new_center, range_a, smooth, total_weight, weighted_average, v1 int32
  16736 	var map1 [256]int32
  16737 	var mb uintptr
  16738 	var _ /* accum at bp+16 */ [4]int32
  16739 	var _ /* centers at bp+0 */ [4]int32
  16740 	var _ /* dist_accum at bp+32 */ [4]int32
  16741 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = a, alpha, displaced, k, map1, max_a, mb, min_a, n, nb, new_center, range_a, smooth, total_weight, weighted_average, v1
  16742 	if (*VP8Encoder)(unsafe.Pointer(enc)).Fsegment_hdr.Fnum_segments < int32(NUM_MB_SEGMENTS) {
  16743 		v1 = (*VP8Encoder)(unsafe.Pointer(enc)).Fsegment_hdr.Fnum_segments
  16744 	} else {
  16745 		v1 = int32(NUM_MB_SEGMENTS)
  16746 	}
  16747 	// 'num_segments' is previously validated and <= NUM_MB_SEGMENTS, but an
  16748 	// explicit check is needed to avoid spurious warning about 'n + 1' exceeding
  16749 	// array bounds of 'centers' with some compilers (noticed with gcc-4.9).
  16750 	nb = v1
  16751 	weighted_average = 0
  16752 	min_a = 0
  16753 	max_a = int32(MAX_ALPHA)
  16754 	// bracket the input
  16755 	n = 0
  16756 	for {
  16757 		if !(n <= int32(MAX_ALPHA) && **(**int32)(__ccgo_up(alphas + uintptr(n)*4)) == 0) {
  16758 			break
  16759 		}
  16760 		goto _2
  16761 	_2:
  16762 		;
  16763 		n = n + 1
  16764 	}
  16765 	min_a = n
  16766 	n = int32(MAX_ALPHA)
  16767 	for {
  16768 		if !(n > min_a && **(**int32)(__ccgo_up(alphas + uintptr(n)*4)) == 0) {
  16769 			break
  16770 		}
  16771 		goto _3
  16772 	_3:
  16773 		;
  16774 		n = n - 1
  16775 	}
  16776 	max_a = n
  16777 	range_a = max_a - min_a
  16778 	// Spread initial centers evenly
  16779 	k = 0
  16780 	n = libc.Int32FromInt32(1)
  16781 	for {
  16782 		if !(k < nb) {
  16783 			break
  16784 		}
  16785 		(**(**[4]int32)(__ccgo_up(bp)))[k] = min_a + n*range_a/(int32(2)*nb)
  16786 		goto _4
  16787 	_4:
  16788 		;
  16789 		k = k + 1
  16790 		n = n + int32(2)
  16791 	}
  16792 	k = 0
  16793 	for {
  16794 		if !(k < int32(MAX_ITERS_K_MEANS)) {
  16795 			break
  16796 		}
  16797 		// Reset stats
  16798 		n = 0
  16799 		for {
  16800 			if !(n < nb) {
  16801 				break
  16802 			}
  16803 			(**(**[4]int32)(__ccgo_up(bp + 16)))[n] = 0
  16804 			(**(**[4]int32)(__ccgo_up(bp + 32)))[n] = 0
  16805 			goto _6
  16806 		_6:
  16807 			;
  16808 			n = n + 1
  16809 		}
  16810 		// Assign nearest center for each 'a'
  16811 		n = 0 // track the nearest center for current 'a'
  16812 		a = min_a
  16813 		for {
  16814 			if !(a <= max_a) {
  16815 				break
  16816 			}
  16817 			if **(**int32)(__ccgo_up(alphas + uintptr(a)*4)) != 0 {
  16818 				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]) {
  16819 					n = n + 1
  16820 				}
  16821 				map1[a] = n
  16822 				// accumulate contribution into best centroid
  16823 				**(**int32)(__ccgo_up(bp + 32 + uintptr(n)*4)) += a * **(**int32)(__ccgo_up(alphas + uintptr(a)*4))
  16824 				**(**int32)(__ccgo_up(bp + 16 + uintptr(n)*4)) += **(**int32)(__ccgo_up(alphas + uintptr(a)*4))
  16825 			}
  16826 			goto _7
  16827 		_7:
  16828 			;
  16829 			a = a + 1
  16830 		}
  16831 		// All point are classified. Move the centroids to the
  16832 		// center of their respective cloud.
  16833 		displaced = 0
  16834 		weighted_average = 0
  16835 		total_weight = 0
  16836 		n = 0
  16837 		for {
  16838 			if !(n < nb) {
  16839 				break
  16840 			}
  16841 			if (**(**[4]int32)(__ccgo_up(bp + 16)))[n] != 0 {
  16842 				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]
  16843 				displaced = displaced + libc.Xabs(tls, (**(**[4]int32)(__ccgo_up(bp)))[n]-new_center)
  16844 				(**(**[4]int32)(__ccgo_up(bp)))[n] = new_center
  16845 				weighted_average = weighted_average + new_center*(**(**[4]int32)(__ccgo_up(bp + 16)))[n]
  16846 				total_weight = total_weight + (**(**[4]int32)(__ccgo_up(bp + 16)))[n]
  16847 			}
  16848 			goto _8
  16849 		_8:
  16850 			;
  16851 			n = n + 1
  16852 		}
  16853 		weighted_average = (weighted_average + total_weight/int32(2)) / total_weight
  16854 		if displaced < int32(5) {
  16855 			break
  16856 		} // no need to keep on looping...
  16857 		goto _5
  16858 	_5:
  16859 		;
  16860 		k = k + 1
  16861 	}
  16862 	// Map each original value to the closest centroid
  16863 	n = 0
  16864 	for {
  16865 		if !(n < (*VP8Encoder)(unsafe.Pointer(enc)).Fmb_w*(*VP8Encoder)(unsafe.Pointer(enc)).Fmb_h) {
  16866 			break
  16867 		}
  16868 		mb = (*VP8Encoder)(unsafe.Pointer(enc)).Fmb_info + uintptr(n)*4
  16869 		alpha = int32((*VP8MBInfo)(unsafe.Pointer(mb)).Falpha)
  16870 		libc.SetBitFieldPtr8Uint32(mb+0, uint32(map1[alpha]), 5, 0x60)
  16871 		(*VP8MBInfo)(unsafe.Pointer(mb)).Falpha = uint8((**(**[4]int32)(__ccgo_up(bp)))[map1[alpha]]) // for the record.
  16872 		goto _9
  16873 	_9:
  16874 		;
  16875 		n = n + 1
  16876 	}
  16877 	if nb > int32(1) {
  16878 		smooth = (*WebPConfig)(unsafe.Pointer((*VP8Encoder)(unsafe.Pointer(enc)).Fconfig)).Fpreprocessing & libc.Int32FromInt32(1)
  16879 		if smooth != 0 {
  16880 			SmoothSegmentMap(tls, enc)
  16881 		}
  16882 	}
  16883 	SetSegmentAlphas(tls, enc, bp, weighted_average) // pick some alphas.
  16884 }
  16885 
  16886 //------------------------------------------------------------------------------
  16887 // Macroblock analysis: collect histogram for each mode, deduce the maximal
  16888 // susceptibility and set best modes for this macroblock.
  16889 // Segment assignment is done later.
  16890 
  16891 // Number of modes to inspect for 'alpha' evaluation. We don't need to test all
  16892 // the possible modes during the analysis phase: we risk falling into a local
  16893 // optimum, or be subject to boundary effect
  16894 
  16895 func MBAnalyzeBestIntra16Mode(tls *libc.TLS, it uintptr) (r int32) {
  16896 	bp := tls.Alloc(16)
  16897 	defer tls.Free(16)
  16898 	var alpha, best_alpha, best_mode, max_mode, mode int32
  16899 	var _ /* histo at bp+0 */ VP8Histogram
  16900 	_, _, _, _, _ = alpha, best_alpha, best_mode, max_mode, mode
  16901 	max_mode = int32(MAX_INTRA16_MODE)
  16902 	best_alpha = -int32(1)
  16903 	best_mode = 0
  16904 	VP8MakeLuma16Preds(tls, it)
  16905 	mode = 0
  16906 	for {
  16907 		if !(mode < max_mode) {
  16908 			break
  16909 		}
  16910 		InitHistogram(tls, bp)
  16911 		(*(*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)
  16912 		alpha = GetAlpha(tls, bp)
  16913 		if alpha > best_alpha {
  16914 			best_alpha = alpha
  16915 			best_mode = mode
  16916 		}
  16917 		goto _1
  16918 	_1:
  16919 		;
  16920 		mode = mode + 1
  16921 	}
  16922 	VP8SetIntra16Mode(tls, it, best_mode)
  16923 	return best_alpha
  16924 }
  16925 
  16926 func FastMBAnalyze(tls *libc.TLS, it uintptr) (r int32) {
  16927 	bp := tls.Alloc(80)
  16928 	defer tls.Free(80)
  16929 	var k, q int32
  16930 	var kThreshold, m, m2 uint32_t
  16931 	var _ /* dc at bp+0 */ [16]uint32_t
  16932 	var _ /* modes at bp+64 */ [16]uint8_t
  16933 	_, _, _, _, _ = k, kThreshold, m, m2, q
  16934 	// Empirical cut-off value, should be around 16 (~=block size). We use the
  16935 	// [8-17] range and favor intra4 at high quality, intra16 for low quality.
  16936 	q = int32((*WebPConfig)(unsafe.Pointer((*VP8Encoder)(unsafe.Pointer((*VP8EncIterator)(unsafe.Pointer(it)).Fenc)).Fconfig)).Fquality)
  16937 	kThreshold = uint32(int32(8) + (libc.Int32FromInt32(17)-libc.Int32FromInt32(8))*q/int32(100))
  16938 	k = 0
  16939 	for {
  16940 		if !(k < int32(16)) {
  16941 			break
  16942 		}
  16943 		(*(*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)
  16944 		goto _1
  16945 	_1:
  16946 		;
  16947 		k = k + int32(4)
  16948 	}
  16949 	m = uint32(0)
  16950 	m2 = uint32(0)
  16951 	k = libc.Int32FromInt32(0)
  16952 	for {
  16953 		if !(k < int32(16)) {
  16954 			break
  16955 		}
  16956 		m = m + (**(**[16]uint32_t)(__ccgo_up(bp)))[k]
  16957 		m2 = m2 + (**(**[16]uint32_t)(__ccgo_up(bp)))[k]*(**(**[16]uint32_t)(__ccgo_up(bp)))[k]
  16958 		goto _2
  16959 	_2:
  16960 		;
  16961 		k = k + 1
  16962 	}
  16963 	if kThreshold*m2 < m*m {
  16964 		VP8SetIntra16Mode(tls, it, 0) // DC16
  16965 	} else {
  16966 		**(**[16]uint8_t)(__ccgo_up(bp + 64)) = [16]uint8_t{} // DC4
  16967 		VP8SetIntra4Mode(tls, it, bp+64)
  16968 	}
  16969 	return 0
  16970 }
  16971 
  16972 func MBAnalyzeBestUVMode(tls *libc.TLS, it uintptr) (r int32) {
  16973 	bp := tls.Alloc(16)
  16974 	defer tls.Free(16)
  16975 	var alpha, best_alpha, best_mode, max_mode, mode, smallest_alpha int32
  16976 	var _ /* histo at bp+0 */ VP8Histogram
  16977 	_, _, _, _, _, _ = alpha, best_alpha, best_mode, max_mode, mode, smallest_alpha
  16978 	best_alpha = -int32(1)
  16979 	smallest_alpha = 0
  16980 	best_mode = 0
  16981 	max_mode = int32(MAX_UV_MODE)
  16982 	VP8MakeChroma8Preds(tls, it)
  16983 	mode = 0
  16984 	for {
  16985 		if !(mode < max_mode) {
  16986 			break
  16987 		}
  16988 		InitHistogram(tls, bp)
  16989 		(*(*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)
  16990 		alpha = GetAlpha(tls, bp)
  16991 		if alpha > best_alpha {
  16992 			best_alpha = alpha
  16993 		}
  16994 		// The best prediction mode tends to be the one with the smallest alpha.
  16995 		if mode == 0 || alpha < smallest_alpha {
  16996 			smallest_alpha = alpha
  16997 			best_mode = mode
  16998 		}
  16999 		goto _1
  17000 	_1:
  17001 		;
  17002 		mode = mode + 1
  17003 	}
  17004 	VP8SetIntraUVMode(tls, it, best_mode)
  17005 	return best_alpha
  17006 }
  17007 
  17008 func MBAnalyze(tls *libc.TLS, it uintptr, alphas uintptr, alpha uintptr, uv_alpha uintptr) {
  17009 	var best_alpha, best_uv_alpha int32
  17010 	var enc uintptr
  17011 	_, _, _ = best_alpha, best_uv_alpha, enc
  17012 	enc = (*VP8EncIterator)(unsafe.Pointer(it)).Fenc
  17013 	VP8SetIntra16Mode(tls, it, 0) // default: Intra16, DC_PRED
  17014 	VP8SetSkip(tls, it, 0)        // not skipped
  17015 	VP8SetSegment(tls, it, 0)     // default segment, spec-wise.
  17016 	if (*VP8Encoder)(unsafe.Pointer(enc)).Fmethod <= int32(1) {
  17017 		best_alpha = FastMBAnalyze(tls, it)
  17018 	} else {
  17019 		best_alpha = MBAnalyzeBestIntra16Mode(tls, it)
  17020 	}
  17021 	best_uv_alpha = MBAnalyzeBestUVMode(tls, it)
  17022 	// Final susceptibility mix
  17023 	best_alpha = (int32(3)*best_alpha + best_uv_alpha + int32(2)) >> int32(2)
  17024 	best_alpha = FinalAlphaValue(tls, best_alpha)
  17025 	**(**int32)(__ccgo_up(alphas + uintptr(best_alpha)*4)) = **(**int32)(__ccgo_up(alphas + uintptr(best_alpha)*4)) + 1
  17026 	(*VP8MBInfo)(unsafe.Pointer((*VP8EncIterator)(unsafe.Pointer(it)).Fmb)).Falpha = uint8(best_alpha) // for later remapping.
  17027 	// Accumulate for later complexity analysis.
  17028 	**(**int32)(__ccgo_up(alpha)) += best_alpha // mixed susceptibility (not just luma)
  17029 	**(**int32)(__ccgo_up(uv_alpha)) += best_uv_alpha
  17030 }
  17031 
  17032 func DefaultMBInfo(tls *libc.TLS, mb uintptr) {
  17033 	libc.SetBitFieldPtr8Uint32(mb+0, libc.Uint32FromInt32(1), 0, 0x3) // I16x16
  17034 	libc.SetBitFieldPtr8Uint32(mb+0, libc.Uint32FromInt32(0), 2, 0xc)
  17035 	libc.SetBitFieldPtr8Uint32(mb+0, libc.Uint32FromInt32(0), 4, 0x10) // not skipped
  17036 	libc.SetBitFieldPtr8Uint32(mb+0, libc.Uint32FromInt32(0), 5, 0x60) // default segment
  17037 	(*VP8MBInfo)(unsafe.Pointer(mb)).Falpha = uint8(0)
  17038 }
  17039 
  17040 //------------------------------------------------------------------------------
  17041 // Main analysis loop:
  17042 // Collect all susceptibilities for each macroblock and record their
  17043 // distribution in alphas[]. Segments is assigned a-posteriori, based on
  17044 // this histogram.
  17045 // We also pick an intra16 prediction mode, which shouldn't be considered
  17046 // final except for fast-encode settings. We can also pick some intra4 modes
  17047 // and decide intra4/intra16, but that's usually almost always a bad choice at
  17048 // this stage.
  17049 
  17050 func ResetAllMBInfo(tls *libc.TLS, enc uintptr) {
  17051 	var n int32
  17052 	_ = n
  17053 	n = 0
  17054 	for {
  17055 		if !(n < (*VP8Encoder)(unsafe.Pointer(enc)).Fmb_w*(*VP8Encoder)(unsafe.Pointer(enc)).Fmb_h) {
  17056 			break
  17057 		}
  17058 		DefaultMBInfo(tls, (*VP8Encoder)(unsafe.Pointer(enc)).Fmb_info+uintptr(n)*4)
  17059 		goto _1
  17060 	_1:
  17061 		;
  17062 		n = n + 1
  17063 	}
  17064 	// Default susceptibilities.
  17065 	(**(**VP8SegmentInfo)(__ccgo_up(enc + 608))).Falpha = 0
  17066 	(**(**VP8SegmentInfo)(__ccgo_up(enc + 608))).Fbeta = 0
  17067 	// Note: we can't compute this 'alpha' / 'uv_alpha' -> set to default value.
  17068 	(*VP8Encoder)(unsafe.Pointer(enc)).Falpha = 0
  17069 	(*VP8Encoder)(unsafe.Pointer(enc)).Fuv_alpha = 0
  17070 	WebPReportProgress(tls, (*VP8Encoder)(unsafe.Pointer(enc)).Fpic, (*VP8Encoder)(unsafe.Pointer(enc)).Fpercent+int32(20), enc+536)
  17071 }
  17072 
  17073 // C documentation
  17074 //
  17075 //	// struct used to collect job result
  17076 type SegmentJob = struct {
  17077 	Fworker         WebPWorker
  17078 	Falphas         [256]int32
  17079 	Falpha          int32
  17080 	Fuv_alpha       int32
  17081 	Fit             VP8EncIterator
  17082 	Fdelta_progress int32
  17083 }
  17084 
  17085 // C documentation
  17086 //
  17087 //	// main work call
  17088 func DoSegmentsJob(tls *libc.TLS, arg1 uintptr, arg2 uintptr) (r int32) {
  17089 	bp := tls.Alloc(64)
  17090 	defer tls.Free(64)
  17091 	var it, job, scratch uintptr
  17092 	var ok int32
  17093 	var _ /* tmp at bp+0 */ [63]uint8_t
  17094 	_, _, _, _ = it, job, ok, scratch
  17095 	job = arg1
  17096 	it = arg2
  17097 	ok = int32(1)
  17098 	if !(VP8IteratorIsDone(tls, it) != 0) {
  17099 		scratch = uintptr((uintptr_t(bp) + libc.Uint64FromInt32(WEBP_ALIGN_CST)) & ^libc.Uint64FromInt32(WEBP_ALIGN_CST))
  17100 		for cond := true; cond; cond = ok != 0 && VP8IteratorNext(tls, it) != 0 {
  17101 			// Let's pretend we have perfect lossless reconstruction.
  17102 			VP8IteratorImport(tls, it, scratch)
  17103 			MBAnalyze(tls, it, job+48, job+1072, job+1076)
  17104 			ok = VP8IteratorProgress(tls, it, (*SegmentJob)(unsafe.Pointer(job)).Fdelta_progress)
  17105 		}
  17106 	}
  17107 	return ok
  17108 }
  17109 
  17110 // C documentation
  17111 //
  17112 //	// initialize the job struct with some tasks to perform
  17113 func InitSegmentJob(tls *libc.TLS, enc uintptr, job uintptr, start_row int32, end_row int32) {
  17114 	var v1 int32
  17115 	_ = v1
  17116 	(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(&struct{ uintptr }{(*WebPWorkerInterface)(unsafe.Pointer(WebPGetWorkerInterface(tls))).FInit})))(tls, job)
  17117 	(*SegmentJob)(unsafe.Pointer(job)).Fworker.Fdata1 = job
  17118 	(*SegmentJob)(unsafe.Pointer(job)).Fworker.Fdata2 = job + 1080
  17119 	(*SegmentJob)(unsafe.Pointer(job)).Fworker.Fhook = __ccgo_fp(DoSegmentsJob)
  17120 	VP8IteratorInit(tls, enc, job+1080)
  17121 	VP8IteratorSetRow(tls, job+1080, start_row)
  17122 	VP8IteratorSetCountDown(tls, job+1080, (end_row-start_row)*(*VP8Encoder)(unsafe.Pointer(enc)).Fmb_w)
  17123 	libc.Xmemset(tls, job+48, 0, uint64(1024))
  17124 	(*SegmentJob)(unsafe.Pointer(job)).Falpha = 0
  17125 	(*SegmentJob)(unsafe.Pointer(job)).Fuv_alpha = 0
  17126 	// only one of both jobs can record the progress, since we don't
  17127 	// expect the user's hook to be multi-thread safe
  17128 	if start_row == 0 {
  17129 		v1 = int32(20)
  17130 	} else {
  17131 		v1 = 0
  17132 	}
  17133 	(*SegmentJob)(unsafe.Pointer(job)).Fdelta_progress = v1
  17134 }
  17135 
  17136 // C documentation
  17137 //
  17138 //	// main entry point
  17139 func VP8EncAnalyze(tls *libc.TLS, enc uintptr) (r int32) {
  17140 	bp := tls.Alloc(4944)
  17141 	defer tls.Free(4944)
  17142 	var do_mt, do_segments, last_row, ok, total_mb int32
  17143 	var worker_interface uintptr
  17144 	var _ /* main_job at bp+0 */ SegmentJob
  17145 	_, _, _, _, _, _ = do_mt, do_segments, last_row, ok, total_mb, worker_interface
  17146 	ok = int32(1)
  17147 	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.
  17148 	if do_segments != 0 {
  17149 		last_row = (*VP8Encoder)(unsafe.Pointer(enc)).Fmb_h
  17150 		total_mb = last_row * (*VP8Encoder)(unsafe.Pointer(enc)).Fmb_w
  17151 		do_mt = 0
  17152 		worker_interface = WebPGetWorkerInterface(tls)
  17153 		if do_mt != 0 {
  17154 		} else {
  17155 			// Even for single-thread case, we use the generic Worker tools.
  17156 			InitSegmentJob(tls, enc, bp, 0, last_row)
  17157 			(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(&struct{ uintptr }{(*WebPWorkerInterface)(unsafe.Pointer(worker_interface)).FExecute})))(tls, bp)
  17158 			ok = ok & (*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*WebPWorkerInterface)(unsafe.Pointer(worker_interface)).FSync})))(tls, bp)
  17159 		}
  17160 		(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(&struct{ uintptr }{(*WebPWorkerInterface)(unsafe.Pointer(worker_interface)).FEnd})))(tls, bp)
  17161 		if ok != 0 {
  17162 			(*VP8Encoder)(unsafe.Pointer(enc)).Falpha = (**(**SegmentJob)(__ccgo_up(bp))).Falpha / total_mb
  17163 			(*VP8Encoder)(unsafe.Pointer(enc)).Fuv_alpha = (**(**SegmentJob)(__ccgo_up(bp))).Fuv_alpha / total_mb
  17164 			AssignSegments(tls, enc, bp+48)
  17165 		}
  17166 	} else { // Use only one default segment.
  17167 		ResetAllMBInfo(tls, enc)
  17168 	}
  17169 	if !(ok != 0) {
  17170 		return WebPEncodingSetError(tls, (*VP8Encoder)(unsafe.Pointer(enc)).Fpic, int32(VP8_ENC_ERROR_OUT_OF_MEMORY)) // imprecise
  17171 	}
  17172 	return ok
  17173 }
  17174 
  17175 const COST_CACHE_INTERVAL_SIZE_MAX = 500
  17176 const COST_MANAGER_MAX_FREE_LIST = 10
  17177 const SIZE_MAX3 = "UINT64_MAX"
  17178 const VALUES_IN_BYTE = 256
  17179 
  17180 var kHashMul10 = uint32(0x1e35a7bd)
  17181 
  17182 type CostModel = struct {
  17183 	Falpha    [256]uint32_t
  17184 	Fred      [256]uint32_t
  17185 	Fblue     [256]uint32_t
  17186 	Fdistance [40]uint32_t
  17187 	Fliteral  uintptr
  17188 }
  17189 
  17190 func ConvertPopulationCountTableToBitEstimates(tls *libc.TLS, num_symbols int32, population_counts uintptr, output uintptr) {
  17191 	var i, nonzeros int32
  17192 	var logsum, sum, v2, v3, v7, v8 uint32_t
  17193 	var v10, v5 uint32
  17194 	_, _, _, _, _, _, _, _, _, _ = i, logsum, nonzeros, sum, v10, v2, v3, v5, v7, v8
  17195 	sum = uint32(0)
  17196 	nonzeros = 0
  17197 	i = 0
  17198 	for {
  17199 		if !(i < num_symbols) {
  17200 			break
  17201 		}
  17202 		sum = sum + **(**uint32_t)(__ccgo_up(population_counts + uintptr(i)*4))
  17203 		if **(**uint32_t)(__ccgo_up(population_counts + uintptr(i)*4)) > uint32(0) {
  17204 			nonzeros = nonzeros + 1
  17205 		}
  17206 		goto _1
  17207 	_1:
  17208 		;
  17209 		i = i + 1
  17210 	}
  17211 	if nonzeros <= int32(1) {
  17212 		libc.Xmemset(tls, output, 0, uint64(num_symbols)*uint64(4))
  17213 	} else {
  17214 		v2 = sum
  17215 		if v2 < uint32(LOG_LOOKUP_IDX_MAX) {
  17216 			v5 = kLog2Table[v2]
  17217 		} else {
  17218 			v5 = (*(*func(*libc.TLS, uint32_t) uint32_t)(unsafe.Pointer(&struct{ uintptr }{VP8LFastLog2Slow})))(tls, v2)
  17219 		}
  17220 		v3 = v5
  17221 		goto _4
  17222 	_4:
  17223 		logsum = v3
  17224 		i = 0
  17225 		for {
  17226 			if !(i < num_symbols) {
  17227 				break
  17228 			}
  17229 			v7 = **(**uint32_t)(__ccgo_up(population_counts + uintptr(i)*4))
  17230 			if v7 < uint32(LOG_LOOKUP_IDX_MAX) {
  17231 				v10 = kLog2Table[v7]
  17232 			} else {
  17233 				v10 = (*(*func(*libc.TLS, uint32_t) uint32_t)(unsafe.Pointer(&struct{ uintptr }{VP8LFastLog2Slow})))(tls, v7)
  17234 			}
  17235 			v8 = v10
  17236 			goto _9
  17237 		_9:
  17238 			**(**uint32_t)(__ccgo_up(output + uintptr(i)*4)) = logsum - v8
  17239 			goto _6
  17240 		_6:
  17241 			;
  17242 			i = i + 1
  17243 		}
  17244 	}
  17245 }
  17246 
  17247 func CostModelBuild(tls *libc.TLS, m uintptr, xsize int32, cache_bits int32, refs uintptr) (r int32) {
  17248 	var histo uintptr
  17249 	var ok, v1, v2, v4 int32
  17250 	_, _, _, _, _ = histo, ok, v1, v2, v4
  17251 	ok = 0
  17252 	histo = VP8LAllocateHistogram(tls, cache_bits)
  17253 	if histo == libc.UintptrFromInt32(0) {
  17254 		goto Error
  17255 	}
  17256 	// The following code is similar to VP8LHistogramCreate but converts the
  17257 	// distance to plane code.
  17258 	VP8LHistogramInit(tls, histo, cache_bits, int32(1))
  17259 	VP8LHistogramStoreRefs(tls, refs, __ccgo_fp(VP8LDistanceToPlaneCode), xsize, histo)
  17260 	v1 = (*VP8LHistogram)(unsafe.Pointer(histo)).Fpalette_code_bits
  17261 	if v1 > 0 {
  17262 		v4 = int32(1) << v1
  17263 	} else {
  17264 		v4 = 0
  17265 	}
  17266 	v2 = libc.Int32FromInt32(NUM_LITERAL_CODES) + libc.Int32FromInt32(NUM_LENGTH_CODES) + v4
  17267 	goto _3
  17268 _3:
  17269 	ConvertPopulationCountTableToBitEstimates(tls, v2, (*VP8LHistogram)(unsafe.Pointer(histo)).Fliteral, (*CostModel)(unsafe.Pointer(m)).Fliteral)
  17270 	ConvertPopulationCountTableToBitEstimates(tls, int32(VALUES_IN_BYTE), histo+8, m+1024)
  17271 	ConvertPopulationCountTableToBitEstimates(tls, int32(VALUES_IN_BYTE), histo+1032, m+2048)
  17272 	ConvertPopulationCountTableToBitEstimates(tls, int32(VALUES_IN_BYTE), histo+2056, m)
  17273 	ConvertPopulationCountTableToBitEstimates(tls, int32(NUM_DISTANCE_CODES), histo+3080, m+3072)
  17274 	ok = int32(1)
  17275 	goto Error
  17276 Error:
  17277 	;
  17278 	VP8LFreeHistogram(tls, histo)
  17279 	return ok
  17280 }
  17281 
  17282 func GetLiteralCost(tls *libc.TLS, m uintptr, v uint32_t) (r int64_t) {
  17283 	return int64(**(**uint32_t)(__ccgo_up(m + uintptr(v>>int32(24))*4))) + int64(**(**uint32_t)(__ccgo_up(m + 1024 + uintptr(v>>libc.Int32FromInt32(16)&uint32(0xff))*4))) + int64(**(**uint32_t)(__ccgo_up((*CostModel)(unsafe.Pointer(m)).Fliteral + uintptr(v>>libc.Int32FromInt32(8)&uint32(0xff))*4))) + int64(**(**uint32_t)(__ccgo_up(m + 2048 + uintptr(v&uint32(0xff))*4)))
  17284 }
  17285 
  17286 func GetCacheCost(tls *libc.TLS, m uintptr, idx uint32_t) (r int64_t) {
  17287 	var literal_idx int32
  17288 	_ = literal_idx
  17289 	literal_idx = int32(uint32(libc.Int32FromInt32(VALUES_IN_BYTE)+libc.Int32FromInt32(NUM_LENGTH_CODES)) + idx)
  17290 	return int64(**(**uint32_t)(__ccgo_up((*CostModel)(unsafe.Pointer(m)).Fliteral + uintptr(literal_idx)*4)))
  17291 }
  17292 
  17293 func GetLengthCost(tls *libc.TLS, m uintptr, length uint32_t) (r int64_t) {
  17294 	bp := tls.Alloc(16)
  17295 	defer tls.Free(16)
  17296 	var highest_bit, second_highest_bit, v1, v4, v5, v6 int32
  17297 	var prefix_code VP8LPrefixCode
  17298 	var v2, v3 uintptr
  17299 	var _ /* code at bp+0 */ int32
  17300 	var _ /* extra_bits at bp+4 */ int32
  17301 	_, _, _, _, _, _, _, _, _ = highest_bit, prefix_code, second_highest_bit, v1, v2, v3, v4, v5, v6
  17302 	v1 = int32(length)
  17303 	v2 = bp
  17304 	v3 = bp + 4
  17305 	if v1 < libc.Int32FromInt32(PREFIX_LOOKUP_IDX_MAX) {
  17306 		prefix_code = kPrefixEncodeCode[v1]
  17307 		**(**int32)(__ccgo_up(v2)) = int32(prefix_code.Fcode)
  17308 		**(**int32)(__ccgo_up(v3)) = int32(prefix_code.Fextra_bits)
  17309 	} else {
  17310 		v4 = v1
  17311 		v4 = v4 - 1
  17312 		v5 = v4
  17313 		v6 = int32(31) ^ libc.X__builtin_clz(tls, uint32(v5))
  17314 		goto _7
  17315 	_7:
  17316 		highest_bit = v6
  17317 		second_highest_bit = v4 >> (highest_bit - int32(1)) & int32(1)
  17318 		**(**int32)(__ccgo_up(v3)) = highest_bit - int32(1)
  17319 		**(**int32)(__ccgo_up(v2)) = int32(2)*highest_bit + second_highest_bit
  17320 	}
  17321 	return int64(**(**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)
  17322 }
  17323 
  17324 func GetDistanceCost(tls *libc.TLS, m uintptr, distance2 uint32_t) (r int64_t) {
  17325 	bp := tls.Alloc(16)
  17326 	defer tls.Free(16)
  17327 	var highest_bit, second_highest_bit, v1, v4, v5, v6 int32
  17328 	var prefix_code VP8LPrefixCode
  17329 	var v2, v3 uintptr
  17330 	var _ /* code at bp+0 */ int32
  17331 	var _ /* extra_bits at bp+4 */ int32
  17332 	_, _, _, _, _, _, _, _, _ = highest_bit, prefix_code, second_highest_bit, v1, v2, v3, v4, v5, v6
  17333 	v1 = int32(distance2)
  17334 	v2 = bp
  17335 	v3 = bp + 4
  17336 	if v1 < libc.Int32FromInt32(PREFIX_LOOKUP_IDX_MAX) {
  17337 		prefix_code = kPrefixEncodeCode[v1]
  17338 		**(**int32)(__ccgo_up(v2)) = int32(prefix_code.Fcode)
  17339 		**(**int32)(__ccgo_up(v3)) = int32(prefix_code.Fextra_bits)
  17340 	} else {
  17341 		v4 = v1
  17342 		v4 = v4 - 1
  17343 		v5 = v4
  17344 		v6 = int32(31) ^ libc.X__builtin_clz(tls, uint32(v5))
  17345 		goto _7
  17346 	_7:
  17347 		highest_bit = v6
  17348 		second_highest_bit = v4 >> (highest_bit - int32(1)) & int32(1)
  17349 		**(**int32)(__ccgo_up(v3)) = highest_bit - int32(1)
  17350 		**(**int32)(__ccgo_up(v2)) = int32(2)*highest_bit + second_highest_bit
  17351 	}
  17352 	return int64(**(**uint32_t)(__ccgo_up(m + 3072 + uintptr(**(**int32)(__ccgo_up(bp)))*4))) + int64(**(**int32)(__ccgo_up(bp + 4)))<<libc.Int32FromInt32(LOG_2_PRECISION_BITS)
  17353 }
  17354 
  17355 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) {
  17356 	var color, v3 uint32_t
  17357 	var cost_val, v10, v11, v9 int64_t
  17358 	var ix, key, key1, v1, v4, v6, v8 int32
  17359 	var v13 int64
  17360 	var v2 uintptr
  17361 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = color, cost_val, ix, key, key1, v1, v10, v11, v13, v2, v3, v4, v6, v8, v9
  17362 	cost_val = prev_cost
  17363 	color = **(**uint32_t)(__ccgo_up(argb3 + uintptr(idx)*4))
  17364 	if use_color_cache != 0 {
  17365 		v2 = hashers
  17366 		v3 = color
  17367 		v4 = int32(v3 * kHashMul10 >> (*VP8LColorCache)(unsafe.Pointer(v2)).Fhash_shift)
  17368 		goto _5
  17369 	_5:
  17370 		key1 = v4
  17371 		if **(**uint32_t)(__ccgo_up((*VP8LColorCache)(unsafe.Pointer(v2)).Fcolors + uintptr(key1)*4)) == v3 {
  17372 			v8 = key1
  17373 		} else {
  17374 			v8 = -int32(1)
  17375 		}
  17376 		v6 = v8
  17377 		goto _7
  17378 	_7:
  17379 		v1 = v6
  17380 	} else {
  17381 		v1 = -int32(1)
  17382 	}
  17383 	ix = v1
  17384 	if ix >= 0 {
  17385 		// use_color_cache is true and hashers contains color
  17386 		v9 = GetCacheCost(tls, cost_model, uint32(ix)) * int64(68)
  17387 		v10 = int64(100)
  17388 		if libc.BoolInt32(v9 < 0) == libc.BoolInt32(v10 < 0) {
  17389 			v13 = (v9 + v10/int64(2)) / v10
  17390 		} else {
  17391 			v13 = (v9 - v10/int64(2)) / v10
  17392 		}
  17393 		v11 = v13
  17394 		goto _12
  17395 	_12:
  17396 		cost_val = cost_val + v11
  17397 	} else {
  17398 		if use_color_cache != 0 {
  17399 			v2 = hashers
  17400 			v3 = color
  17401 			v1 = int32(v3 * kHashMul10 >> (*VP8LColorCache)(unsafe.Pointer(v2)).Fhash_shift)
  17402 			goto _17
  17403 		_17:
  17404 			key = v1
  17405 			**(**uint32_t)(__ccgo_up((*VP8LColorCache)(unsafe.Pointer(v2)).Fcolors + uintptr(key)*4)) = v3
  17406 		}
  17407 		v9 = GetLiteralCost(tls, cost_model, color) * int64(82)
  17408 		v10 = int64(100)
  17409 		if libc.BoolInt32(v9 < 0) == libc.BoolInt32(v10 < 0) {
  17410 			v13 = (v9 + v10/int64(2)) / v10
  17411 		} else {
  17412 			v13 = (v9 - v10/int64(2)) / v10
  17413 		}
  17414 		v11 = v13
  17415 		goto _21
  17416 	_21:
  17417 		cost_val = cost_val + v11
  17418 	}
  17419 	if **(**int64_t)(__ccgo_up(cost + uintptr(idx)*8)) > cost_val {
  17420 		**(**int64_t)(__ccgo_up(cost + uintptr(idx)*8)) = cost_val
  17421 		**(**uint16_t)(__ccgo_up(dist_array + uintptr(idx)*2)) = uint16(1) // only one is inserted.
  17422 	}
  17423 }
  17424 
  17425 // -----------------------------------------------------------------------------
  17426 // CostManager and interval handling
  17427 
  17428 // Empirical value to avoid high memory consumption but good for performance.
  17429 
  17430 // C documentation
  17431 //
  17432 //	// To perform backward reference every pixel at index 'index' is considered and
  17433 //	// the cost for the MAX_LENGTH following pixels computed. Those following pixels
  17434 //	// at index 'index' + k (k from 0 to MAX_LENGTH) have a cost of:
  17435 //	//     cost = distance cost at index + GetLengthCost(cost_model, k)
  17436 //	// and the minimum value is kept. GetLengthCost(cost_model, k) is cached in an
  17437 //	// array of size MAX_LENGTH.
  17438 //	// Instead of performing MAX_LENGTH comparisons per pixel, we keep track of the
  17439 //	// minimal values using intervals of constant cost.
  17440 //	// An interval is defined by the 'index' of the pixel that generated it and
  17441 //	// is only useful in a range of indices from 'start' to 'end' (exclusive), i.e.
  17442 //	// it contains the minimum value for pixels between start and end.
  17443 //	// Intervals are stored in a linked list and ordered by 'start'. When a new
  17444 //	// interval has a better value, old intervals are split or removed. There are
  17445 //	// therefore no overlapping intervals.
  17446 type CostInterval = struct {
  17447 	Fcost     int64_t
  17448 	Fstart    int32
  17449 	Fend      int32
  17450 	Findex    int32
  17451 	Fprevious uintptr
  17452 	Fnext     uintptr
  17453 }
  17454 
  17455 // C documentation
  17456 //
  17457 //	// The GetLengthCost(cost_model, k) are cached in a CostCacheInterval.
  17458 type CostCacheInterval = struct {
  17459 	Fcost  int64_t
  17460 	Fstart int32
  17461 	Fend   int32
  17462 }
  17463 
  17464 // C documentation
  17465 //
  17466 //	// This structure is in charge of managing intervals and costs.
  17467 //	// It caches the different CostCacheInterval, caches the different
  17468 //	// GetLengthCost(cost_model, k) in cost_cache and the CostInterval's (whose
  17469 //	// 'count' is limited by COST_CACHE_INTERVAL_SIZE_MAX).
  17470 type CostManager = struct {
  17471 	Fhead                 uintptr
  17472 	Fcount                int32
  17473 	Fcache_intervals      uintptr
  17474 	Fcache_intervals_size size_t
  17475 	Fcost_cache           [4095]int64_t
  17476 	Fcosts                uintptr
  17477 	Fdist_array           uintptr
  17478 	Fintervals            [10]CostInterval
  17479 	Ffree_intervals       uintptr
  17480 	Frecycled_intervals   uintptr
  17481 }
  17482 
  17483 func CostIntervalAddToFreeList(tls *libc.TLS, manager uintptr, interval uintptr) {
  17484 	(*CostInterval)(unsafe.Pointer(interval)).Fnext = (*CostManager)(unsafe.Pointer(manager)).Ffree_intervals
  17485 	(*CostManager)(unsafe.Pointer(manager)).Ffree_intervals = interval
  17486 }
  17487 
  17488 func CostIntervalIsInFreeList(tls *libc.TLS, manager uintptr, interval uintptr) (r int32) {
  17489 	return libc.BoolInt32(interval >= manager+32808 && interval <= manager+32808+uintptr(libc.Int32FromInt32(COST_MANAGER_MAX_FREE_LIST)-libc.Int32FromInt32(1))*40)
  17490 }
  17491 
  17492 func CostManagerInitFreeList(tls *libc.TLS, manager uintptr) {
  17493 	var i int32
  17494 	_ = i
  17495 	(*CostManager)(unsafe.Pointer(manager)).Ffree_intervals = libc.UintptrFromInt32(0)
  17496 	i = 0
  17497 	for {
  17498 		if !(i < int32(COST_MANAGER_MAX_FREE_LIST)) {
  17499 			break
  17500 		}
  17501 		CostIntervalAddToFreeList(tls, manager, manager+32808+uintptr(i)*40)
  17502 		goto _1
  17503 	_1:
  17504 		;
  17505 		i = i + 1
  17506 	}
  17507 }
  17508 
  17509 func DeleteIntervalList(tls *libc.TLS, manager uintptr, interval uintptr) {
  17510 	var next uintptr
  17511 	_ = next
  17512 	for interval != libc.UintptrFromInt32(0) {
  17513 		next = (*CostInterval)(unsafe.Pointer(interval)).Fnext
  17514 		if !(CostIntervalIsInFreeList(tls, manager, interval) != 0) {
  17515 			WebPSafeFree(tls, interval)
  17516 		} // else: do nothing
  17517 		interval = next
  17518 	}
  17519 }
  17520 
  17521 func CostManagerClear(tls *libc.TLS, manager uintptr) {
  17522 	if manager == libc.UintptrFromInt32(0) {
  17523 		return
  17524 	}
  17525 	WebPSafeFree(tls, (*CostManager)(unsafe.Pointer(manager)).Fcosts)
  17526 	WebPSafeFree(tls, (*CostManager)(unsafe.Pointer(manager)).Fcache_intervals)
  17527 	// Clear the interval lists.
  17528 	DeleteIntervalList(tls, manager, (*CostManager)(unsafe.Pointer(manager)).Fhead)
  17529 	(*CostManager)(unsafe.Pointer(manager)).Fhead = libc.UintptrFromInt32(0)
  17530 	DeleteIntervalList(tls, manager, (*CostManager)(unsafe.Pointer(manager)).Frecycled_intervals)
  17531 	(*CostManager)(unsafe.Pointer(manager)).Frecycled_intervals = libc.UintptrFromInt32(0)
  17532 	// Reset pointers, 'count' and 'cache_intervals_size'.
  17533 	libc.Xmemset(tls, manager, 0, uint64(33224))
  17534 	CostManagerInitFreeList(tls, manager)
  17535 }
  17536 
  17537 func CostManagerInit(tls *libc.TLS, manager uintptr, dist_array uintptr, pix_count int32, cost_model uintptr) (r int32) {
  17538 	var cost_cache_size, i, v1 int32
  17539 	var cost_val int64_t
  17540 	var cur uintptr
  17541 	_, _, _, _, _ = cost_cache_size, cost_val, cur, i, v1
  17542 	if pix_count > libc.Int32FromInt32(1)<<libc.Int32FromInt32(MAX_LENGTH_BITS)-libc.Int32FromInt32(1) {
  17543 		v1 = libc.Int32FromInt32(1)<<libc.Int32FromInt32(MAX_LENGTH_BITS) - libc.Int32FromInt32(1)
  17544 	} else {
  17545 		v1 = pix_count
  17546 	}
  17547 	cost_cache_size = v1
  17548 	(*CostManager)(unsafe.Pointer(manager)).Fcosts = libc.UintptrFromInt32(0)
  17549 	(*CostManager)(unsafe.Pointer(manager)).Fcache_intervals = libc.UintptrFromInt32(0)
  17550 	(*CostManager)(unsafe.Pointer(manager)).Fhead = libc.UintptrFromInt32(0)
  17551 	(*CostManager)(unsafe.Pointer(manager)).Frecycled_intervals = libc.UintptrFromInt32(0)
  17552 	(*CostManager)(unsafe.Pointer(manager)).Fcount = 0
  17553 	(*CostManager)(unsafe.Pointer(manager)).Fdist_array = dist_array
  17554 	CostManagerInitFreeList(tls, manager)
  17555 	// Fill in the 'cost_cache'.
  17556 	// Has to be done in two passes due to a GCC bug on i686
  17557 	// related to https://gcc.gnu.org/bugzilla/show_bug.cgi?id=323
  17558 	i = 0
  17559 	for {
  17560 		if !(i < cost_cache_size) {
  17561 			break
  17562 		}
  17563 		**(**int64_t)(__ccgo_up(manager + 32 + uintptr(i)*8)) = GetLengthCost(tls, cost_model, uint32(i))
  17564 		goto _2
  17565 	_2:
  17566 		;
  17567 		i = i + 1
  17568 	}
  17569 	(*CostManager)(unsafe.Pointer(manager)).Fcache_intervals_size = uint64(1)
  17570 	i = int32(1)
  17571 	for {
  17572 		if !(i < cost_cache_size) {
  17573 			break
  17574 		}
  17575 		// Get the number of bound intervals.
  17576 		if **(**int64_t)(__ccgo_up(manager + 32 + uintptr(i)*8)) != **(**int64_t)(__ccgo_up(manager + 32 + uintptr(i-int32(1))*8)) {
  17577 			(*CostManager)(unsafe.Pointer(manager)).Fcache_intervals_size = (*CostManager)(unsafe.Pointer(manager)).Fcache_intervals_size + 1
  17578 		}
  17579 		goto _3
  17580 	_3:
  17581 		;
  17582 		i = i + 1
  17583 	}
  17584 	// With the current cost model, we usually have below 20 intervals.
  17585 	// The worst case scenario with a cost model would be if every length has a
  17586 	// different cost, hence MAX_LENGTH but that is impossible with the current
  17587 	// implementation that spirals around a pixel.
  17588 	(*CostManager)(unsafe.Pointer(manager)).Fcache_intervals = WebPSafeMalloc(tls, (*CostManager)(unsafe.Pointer(manager)).Fcache_intervals_size, uint64(16))
  17589 	if (*CostManager)(unsafe.Pointer(manager)).Fcache_intervals == libc.UintptrFromInt32(0) {
  17590 		CostManagerClear(tls, manager)
  17591 		return 0
  17592 	}
  17593 	// Fill in the 'cache_intervals'.
  17594 	cur = (*CostManager)(unsafe.Pointer(manager)).Fcache_intervals
  17595 	// Consecutive values in 'cost_cache' are compared and if a big enough
  17596 	// difference is found, a new interval is created and bounded.
  17597 	(*CostCacheInterval)(unsafe.Pointer(cur)).Fstart = 0
  17598 	(*CostCacheInterval)(unsafe.Pointer(cur)).Fend = int32(1)
  17599 	(*CostCacheInterval)(unsafe.Pointer(cur)).Fcost = **(**int64_t)(__ccgo_up(manager + 32))
  17600 	i = int32(1)
  17601 	for {
  17602 		if !(i < cost_cache_size) {
  17603 			break
  17604 		}
  17605 		cost_val = **(**int64_t)(__ccgo_up(manager + 32 + uintptr(i)*8))
  17606 		if cost_val != (*CostCacheInterval)(unsafe.Pointer(cur)).Fcost {
  17607 			cur += 16
  17608 			// Initialize an interval.
  17609 			(*CostCacheInterval)(unsafe.Pointer(cur)).Fstart = i
  17610 			(*CostCacheInterval)(unsafe.Pointer(cur)).Fcost = cost_val
  17611 		}
  17612 		(*CostCacheInterval)(unsafe.Pointer(cur)).Fend = i + int32(1)
  17613 		goto _4
  17614 	_4:
  17615 		;
  17616 		i = i + 1
  17617 	}
  17618 	(*CostManager)(unsafe.Pointer(manager)).Fcosts = WebPSafeMalloc(tls, uint64(pix_count), uint64(8))
  17619 	if (*CostManager)(unsafe.Pointer(manager)).Fcosts == libc.UintptrFromInt32(0) {
  17620 		CostManagerClear(tls, manager)
  17621 		return 0
  17622 	}
  17623 	// Set the initial 'costs' to INT64_MAX for every pixel as we will keep the
  17624 	// minimum.
  17625 	i = 0
  17626 	for {
  17627 		if !(i < pix_count) {
  17628 			break
  17629 		}
  17630 		**(**int64_t)(__ccgo_up((*CostManager)(unsafe.Pointer(manager)).Fcosts + uintptr(i)*8)) = int64(libc.Uint64FromUint64(1)<<libc.Int32FromInt32(63) - libc.Uint64FromInt32(1))
  17631 		goto _5
  17632 	_5:
  17633 		;
  17634 		i = i + 1
  17635 	}
  17636 	return int32(1)
  17637 }
  17638 
  17639 // C documentation
  17640 //
  17641 //	// Given the cost and the position that define an interval, update the cost at
  17642 //	// pixel 'i' if it is smaller than the previously computed value.
  17643 func UpdateCost(tls *libc.TLS, manager uintptr, i int32, position int32, cost int64_t) {
  17644 	var k int32
  17645 	_ = k
  17646 	k = i - position
  17647 	if **(**int64_t)(__ccgo_up((*CostManager)(unsafe.Pointer(manager)).Fcosts + uintptr(i)*8)) > cost {
  17648 		**(**int64_t)(__ccgo_up((*CostManager)(unsafe.Pointer(manager)).Fcosts + uintptr(i)*8)) = cost
  17649 		**(**uint16_t)(__ccgo_up((*CostManager)(unsafe.Pointer(manager)).Fdist_array + uintptr(i)*2)) = uint16(k + int32(1))
  17650 	}
  17651 }
  17652 
  17653 // C documentation
  17654 //
  17655 //	// Given the cost and the position that define an interval, update the cost for
  17656 //	// all the pixels between 'start' and 'end' excluded.
  17657 func UpdateCostPerInterval(tls *libc.TLS, manager uintptr, start int32, end int32, position int32, cost int64_t) {
  17658 	var i int32
  17659 	_ = i
  17660 	i = start
  17661 	for {
  17662 		if !(i < end) {
  17663 			break
  17664 		}
  17665 		UpdateCost(tls, manager, i, position, cost)
  17666 		goto _1
  17667 	_1:
  17668 		;
  17669 		i = i + 1
  17670 	}
  17671 }
  17672 
  17673 // C documentation
  17674 //
  17675 //	// Given two intervals, make 'prev' be the previous one of 'next' in 'manager'.
  17676 func ConnectIntervals(tls *libc.TLS, manager uintptr, prev uintptr, next uintptr) {
  17677 	if prev != libc.UintptrFromInt32(0) {
  17678 		(*CostInterval)(unsafe.Pointer(prev)).Fnext = next
  17679 	} else {
  17680 		(*CostManager)(unsafe.Pointer(manager)).Fhead = next
  17681 	}
  17682 	if next != libc.UintptrFromInt32(0) {
  17683 		(*CostInterval)(unsafe.Pointer(next)).Fprevious = prev
  17684 	}
  17685 }
  17686 
  17687 // C documentation
  17688 //
  17689 //	// Pop an interval in the manager.
  17690 func PopInterval(tls *libc.TLS, manager uintptr, interval uintptr) {
  17691 	if interval == libc.UintptrFromInt32(0) {
  17692 		return
  17693 	}
  17694 	ConnectIntervals(tls, manager, (*CostInterval)(unsafe.Pointer(interval)).Fprevious, (*CostInterval)(unsafe.Pointer(interval)).Fnext)
  17695 	if CostIntervalIsInFreeList(tls, manager, interval) != 0 {
  17696 		CostIntervalAddToFreeList(tls, manager, interval)
  17697 	} else { // recycle regularly malloc'd intervals too
  17698 		(*CostInterval)(unsafe.Pointer(interval)).Fnext = (*CostManager)(unsafe.Pointer(manager)).Frecycled_intervals
  17699 		(*CostManager)(unsafe.Pointer(manager)).Frecycled_intervals = interval
  17700 	}
  17701 	(*CostManager)(unsafe.Pointer(manager)).Fcount = (*CostManager)(unsafe.Pointer(manager)).Fcount - 1
  17702 }
  17703 
  17704 // C documentation
  17705 //
  17706 //	// Update the cost at index i by going over all the stored intervals that
  17707 //	// overlap with i.
  17708 //	// If 'do_clean_intervals' is set to something different than 0, intervals that
  17709 //	// end before 'i' will be popped.
  17710 func UpdateCostAtIndex(tls *libc.TLS, manager uintptr, i int32, do_clean_intervals int32) {
  17711 	var current, next uintptr
  17712 	_, _ = current, next
  17713 	current = (*CostManager)(unsafe.Pointer(manager)).Fhead
  17714 	for current != libc.UintptrFromInt32(0) && (*CostInterval)(unsafe.Pointer(current)).Fstart <= i {
  17715 		next = (*CostInterval)(unsafe.Pointer(current)).Fnext
  17716 		if (*CostInterval)(unsafe.Pointer(current)).Fend <= i {
  17717 			if do_clean_intervals != 0 {
  17718 				// We have an outdated interval, remove it.
  17719 				PopInterval(tls, manager, current)
  17720 			}
  17721 		} else {
  17722 			UpdateCost(tls, manager, i, (*CostInterval)(unsafe.Pointer(current)).Findex, (*CostInterval)(unsafe.Pointer(current)).Fcost)
  17723 		}
  17724 		current = next
  17725 	}
  17726 }
  17727 
  17728 // C documentation
  17729 //
  17730 //	// Given a current orphan interval and its previous interval, before
  17731 //	// it was orphaned (which can be NULL), set it at the right place in the list
  17732 //	// of intervals using the 'start' ordering and the previous interval as a hint.
  17733 func PositionOrphanInterval(tls *libc.TLS, manager uintptr, current uintptr, previous uintptr) {
  17734 	if previous == libc.UintptrFromInt32(0) {
  17735 		previous = (*CostManager)(unsafe.Pointer(manager)).Fhead
  17736 	}
  17737 	for previous != libc.UintptrFromInt32(0) && (*CostInterval)(unsafe.Pointer(current)).Fstart < (*CostInterval)(unsafe.Pointer(previous)).Fstart {
  17738 		previous = (*CostInterval)(unsafe.Pointer(previous)).Fprevious
  17739 	}
  17740 	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 {
  17741 		previous = (*CostInterval)(unsafe.Pointer(previous)).Fnext
  17742 	}
  17743 	if previous != libc.UintptrFromInt32(0) {
  17744 		ConnectIntervals(tls, manager, current, (*CostInterval)(unsafe.Pointer(previous)).Fnext)
  17745 	} else {
  17746 		ConnectIntervals(tls, manager, current, (*CostManager)(unsafe.Pointer(manager)).Fhead)
  17747 	}
  17748 	ConnectIntervals(tls, manager, previous, current)
  17749 }
  17750 
  17751 // C documentation
  17752 //
  17753 //	// Insert an interval in the list contained in the manager by starting at
  17754 //	// 'interval_in' as a hint. The intervals are sorted by 'start' value.
  17755 func InsertInterval(tls *libc.TLS, manager uintptr, interval_in uintptr, cost int64_t, position int32, start int32, end int32) {
  17756 	var interval_new uintptr
  17757 	_ = interval_new
  17758 	if start >= end {
  17759 		return
  17760 	}
  17761 	if (*CostManager)(unsafe.Pointer(manager)).Fcount >= int32(COST_CACHE_INTERVAL_SIZE_MAX) {
  17762 		// Serialize the interval if we cannot store it.
  17763 		UpdateCostPerInterval(tls, manager, start, end, position, cost)
  17764 		return
  17765 	}
  17766 	if (*CostManager)(unsafe.Pointer(manager)).Ffree_intervals != libc.UintptrFromInt32(0) {
  17767 		interval_new = (*CostManager)(unsafe.Pointer(manager)).Ffree_intervals
  17768 		(*CostManager)(unsafe.Pointer(manager)).Ffree_intervals = (*CostInterval)(unsafe.Pointer(interval_new)).Fnext
  17769 	} else {
  17770 		if (*CostManager)(unsafe.Pointer(manager)).Frecycled_intervals != libc.UintptrFromInt32(0) {
  17771 			interval_new = (*CostManager)(unsafe.Pointer(manager)).Frecycled_intervals
  17772 			(*CostManager)(unsafe.Pointer(manager)).Frecycled_intervals = (*CostInterval)(unsafe.Pointer(interval_new)).Fnext
  17773 		} else { // malloc for good
  17774 			interval_new = WebPSafeMalloc(tls, uint64(1), uint64(40))
  17775 			if interval_new == libc.UintptrFromInt32(0) {
  17776 				// Write down the interval if we cannot create it.
  17777 				UpdateCostPerInterval(tls, manager, start, end, position, cost)
  17778 				return
  17779 			}
  17780 		}
  17781 	}
  17782 	(*CostInterval)(unsafe.Pointer(interval_new)).Fcost = cost
  17783 	(*CostInterval)(unsafe.Pointer(interval_new)).Findex = position
  17784 	(*CostInterval)(unsafe.Pointer(interval_new)).Fstart = start
  17785 	(*CostInterval)(unsafe.Pointer(interval_new)).Fend = end
  17786 	PositionOrphanInterval(tls, manager, interval_new, interval_in)
  17787 	(*CostManager)(unsafe.Pointer(manager)).Fcount = (*CostManager)(unsafe.Pointer(manager)).Fcount + 1
  17788 }
  17789 
  17790 // C documentation
  17791 //
  17792 //	// Given a new cost interval defined by its start at position, its length value
  17793 //	// and distance_cost, add its contributions to the previous intervals and costs.
  17794 //	// If handling the interval or one of its subintervals becomes to heavy, its
  17795 //	// contribution is added to the costs right away.
  17796 func PushInterval(tls *libc.TLS, manager uintptr, distance_cost int64_t, position int32, len1 int32) {
  17797 	var cost, cost_tmp int64_t
  17798 	var cost_cache_intervals, interval, interval_next uintptr
  17799 	var end, end_original, j, k, kSkipDistance, start, start_new, v3 int32
  17800 	var i size_t
  17801 	_, _, _, _, _, _, _, _, _, _, _, _, _, _ = cost, cost_cache_intervals, cost_tmp, end, end_original, i, interval, interval_next, j, k, kSkipDistance, start, start_new, v3
  17802 	interval = (*CostManager)(unsafe.Pointer(manager)).Fhead
  17803 	cost_cache_intervals = (*CostManager)(unsafe.Pointer(manager)).Fcache_intervals
  17804 	// If the interval is small enough, no need to deal with the heavy
  17805 	// interval logic, just serialize it right away. This constant is empirical.
  17806 	kSkipDistance = int32(10)
  17807 	if len1 < kSkipDistance {
  17808 		j = position
  17809 		for {
  17810 			if !(j < position+len1) {
  17811 				break
  17812 			}
  17813 			k = j - position
  17814 			cost_tmp = distance_cost + **(**int64_t)(__ccgo_up(manager + 32 + uintptr(k)*8))
  17815 			if **(**int64_t)(__ccgo_up((*CostManager)(unsafe.Pointer(manager)).Fcosts + uintptr(j)*8)) > cost_tmp {
  17816 				**(**int64_t)(__ccgo_up((*CostManager)(unsafe.Pointer(manager)).Fcosts + uintptr(j)*8)) = cost_tmp
  17817 				**(**uint16_t)(__ccgo_up((*CostManager)(unsafe.Pointer(manager)).Fdist_array + uintptr(j)*2)) = uint16(k + int32(1))
  17818 			}
  17819 			goto _1
  17820 		_1:
  17821 			;
  17822 			j = j + 1
  17823 		}
  17824 		return
  17825 	}
  17826 	i = uint64(0)
  17827 	for {
  17828 		if !(i < (*CostManager)(unsafe.Pointer(manager)).Fcache_intervals_size && (**(**CostCacheInterval)(__ccgo_up(cost_cache_intervals + uintptr(i)*16))).Fstart < len1) {
  17829 			break
  17830 		}
  17831 		// Define the intersection of the ith interval with the new one.
  17832 		start = position + (**(**CostCacheInterval)(__ccgo_up(cost_cache_intervals + uintptr(i)*16))).Fstart
  17833 		if (**(**CostCacheInterval)(__ccgo_up(cost_cache_intervals + uintptr(i)*16))).Fend > len1 {
  17834 			v3 = len1
  17835 		} else {
  17836 			v3 = (**(**CostCacheInterval)(__ccgo_up(cost_cache_intervals + uintptr(i)*16))).Fend
  17837 		}
  17838 		end = position + v3
  17839 		cost = distance_cost + (**(**CostCacheInterval)(__ccgo_up(cost_cache_intervals + uintptr(i)*16))).Fcost
  17840 		for {
  17841 			if !(interval != libc.UintptrFromInt32(0) && (*CostInterval)(unsafe.Pointer(interval)).Fstart < end) {
  17842 				break
  17843 			}
  17844 			interval_next = (*CostInterval)(unsafe.Pointer(interval)).Fnext
  17845 			// Make sure we have some overlap
  17846 			if start >= (*CostInterval)(unsafe.Pointer(interval)).Fend {
  17847 				goto _4
  17848 			}
  17849 			if cost >= (*CostInterval)(unsafe.Pointer(interval)).Fcost {
  17850 				// When intervals are represented, the lower, the better.
  17851 				// [**********************************************************[
  17852 				// start                                                    end
  17853 				//                   [----------------------------------[
  17854 				//                   interval->start        interval->end
  17855 				// If we are worse than what we already have, add whatever we have so
  17856 				// far up to interval.
  17857 				start_new = (*CostInterval)(unsafe.Pointer(interval)).Fend
  17858 				InsertInterval(tls, manager, interval, cost, position, start, (*CostInterval)(unsafe.Pointer(interval)).Fstart)
  17859 				start = start_new
  17860 				if start >= end {
  17861 					break
  17862 				}
  17863 				goto _4
  17864 			}
  17865 			if start <= (*CostInterval)(unsafe.Pointer(interval)).Fstart {
  17866 				if (*CostInterval)(unsafe.Pointer(interval)).Fend <= end {
  17867 					//                   [----------------------------------[
  17868 					//                   interval->start        interval->end
  17869 					// [**************************************************************[
  17870 					// start                                                        end
  17871 					// We can safely remove the old interval as it is fully included.
  17872 					PopInterval(tls, manager, interval)
  17873 				} else {
  17874 					//              [------------------------------------[
  17875 					//              interval->start          interval->end
  17876 					// [*****************************[
  17877 					// start                       end
  17878 					(*CostInterval)(unsafe.Pointer(interval)).Fstart = end
  17879 					break
  17880 				}
  17881 			} else {
  17882 				if end < (*CostInterval)(unsafe.Pointer(interval)).Fend {
  17883 					// [--------------------------------------------------------------[
  17884 					// interval->start                                    interval->end
  17885 					//                     [*****************************[
  17886 					//                     start                       end
  17887 					// We have to split the old interval as it fully contains the new one.
  17888 					end_original = (*CostInterval)(unsafe.Pointer(interval)).Fend
  17889 					(*CostInterval)(unsafe.Pointer(interval)).Fend = start
  17890 					InsertInterval(tls, manager, interval, (*CostInterval)(unsafe.Pointer(interval)).Fcost, (*CostInterval)(unsafe.Pointer(interval)).Findex, end, end_original)
  17891 					interval = (*CostInterval)(unsafe.Pointer(interval)).Fnext
  17892 					break
  17893 				} else {
  17894 					// [------------------------------------[
  17895 					// interval->start          interval->end
  17896 					//                     [*****************************[
  17897 					//                     start                       end
  17898 					(*CostInterval)(unsafe.Pointer(interval)).Fend = start
  17899 				}
  17900 			}
  17901 			goto _4
  17902 		_4:
  17903 			;
  17904 			interval = interval_next
  17905 		}
  17906 		// Insert the remaining interval from start to end.
  17907 		InsertInterval(tls, manager, interval, cost, position, start, end)
  17908 		goto _2
  17909 	_2:
  17910 		;
  17911 		i = i + 1
  17912 	}
  17913 }
  17914 
  17915 func BackwardReferencesHashChainDistanceOnly(tls *libc.TLS, xsize int32, ysize int32, argb uintptr, cache_bits int32, hash_chain uintptr, refs uintptr, dist_array uintptr) (r int32) {
  17916 	bp := tls.Alloc(32)
  17917 	defer tls.Free(32)
  17918 	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
  17919 	var cost_manager, cost_model, v6 uintptr
  17920 	var cost_model_size, literal_array_size size_t
  17921 	var offset_cost, prev_cost int64_t
  17922 	var _ /* hashers at bp+0 */ VP8LColorCache
  17923 	var _ /* len at bp+20 */ int32
  17924 	var _ /* len_j at bp+28 */ int32
  17925 	var _ /* offset at bp+16 */ int32
  17926 	var _ /* offset_j at bp+24 */ int32
  17927 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  17928 	ok = 0
  17929 	cc_init = 0
  17930 	pix_count = xsize * ysize
  17931 	use_color_cache = libc.BoolInt32(cache_bits > libc.Int32FromInt32(0))
  17932 	v1 = cache_bits
  17933 	if v1 > 0 {
  17934 		v4 = int32(1) << v1
  17935 	} else {
  17936 		v4 = 0
  17937 	}
  17938 	v2 = libc.Int32FromInt32(NUM_LITERAL_CODES) + libc.Int32FromInt32(NUM_LENGTH_CODES) + v4
  17939 	goto _3
  17940 _3:
  17941 	literal_array_size = uint64(4) * uint64(v2)
  17942 	cost_model_size = uint64(3240) + literal_array_size
  17943 	cost_model = WebPSafeCalloc(tls, uint64(1), cost_model_size)
  17944 	cost_manager = WebPSafeCalloc(tls, uint64(1), uint64(33224))
  17945 	offset_prev = -int32(1)
  17946 	len_prev = -int32(1)
  17947 	offset_cost = int64(-int32(1))
  17948 	first_offset_is_constant = -int32(1) // initialized with 'impossible' value
  17949 	reach = 0
  17950 	if cost_model == libc.UintptrFromInt32(0) || cost_manager == libc.UintptrFromInt32(0) {
  17951 		goto Error
  17952 	}
  17953 	(*CostModel)(unsafe.Pointer(cost_model)).Fliteral = cost_model + libc.UintptrFromInt32(1)*3240
  17954 	if use_color_cache != 0 {
  17955 		cc_init = VP8LColorCacheInit(tls, bp, cache_bits)
  17956 		if !(cc_init != 0) {
  17957 			goto Error
  17958 		}
  17959 	}
  17960 	if !(CostModelBuild(tls, cost_model, xsize, cache_bits, refs) != 0) {
  17961 		goto Error
  17962 	}
  17963 	if !(CostManagerInit(tls, cost_manager, dist_array, pix_count, cost_model) != 0) {
  17964 		goto Error
  17965 	}
  17966 	// We loop one pixel at a time, but store all currently best points to
  17967 	// non-processed locations from this point.
  17968 	**(**uint16_t)(__ccgo_up(dist_array)) = uint16(0)
  17969 	// Add first pixel as literal.
  17970 	AddSingleLiteralWithCostModel(tls, argb, bp, cost_model, 0, use_color_cache, 0, (*CostManager)(unsafe.Pointer(cost_manager)).Fcosts, dist_array)
  17971 	i = int32(1)
  17972 	for {
  17973 		if !(i < pix_count) {
  17974 			break
  17975 		}
  17976 		prev_cost = **(**int64_t)(__ccgo_up((*CostManager)(unsafe.Pointer(cost_manager)).Fcosts + uintptr(i-int32(1))*8))
  17977 		v6 = hash_chain
  17978 		v1 = i
  17979 		v2 = int32(**(**uint32_t)(__ccgo_up((*VP8LHashChain)(unsafe.Pointer(v6)).Foffset_length + uintptr(v1)*4)) >> int32(MAX_LENGTH_BITS))
  17980 		goto _9
  17981 	_9:
  17982 		**(**int32)(__ccgo_up(bp + 16)) = v2
  17983 		v4 = int32(**(**uint32_t)(__ccgo_up((*VP8LHashChain)(unsafe.Pointer(v6)).Foffset_length + uintptr(v1)*4)) & (libc.Uint32FromUint32(1)<<libc.Int32FromInt32(MAX_LENGTH_BITS) - libc.Uint32FromInt32(1)))
  17984 		goto _11
  17985 	_11:
  17986 		**(**int32)(__ccgo_up(bp + 20)) = v4
  17987 		// Try adding the pixel as a literal.
  17988 		AddSingleLiteralWithCostModel(tls, argb, bp, cost_model, i, use_color_cache, prev_cost, (*CostManager)(unsafe.Pointer(cost_manager)).Fcosts, dist_array)
  17989 		// If we are dealing with a non-literal.
  17990 		if **(**int32)(__ccgo_up(bp + 20)) >= int32(2) {
  17991 			if **(**int32)(__ccgo_up(bp + 16)) != offset_prev {
  17992 				code = VP8LDistanceToPlaneCode(tls, xsize, **(**int32)(__ccgo_up(bp + 16)))
  17993 				offset_cost = GetDistanceCost(tls, cost_model, uint32(code))
  17994 				first_offset_is_constant = int32(1)
  17995 				PushInterval(tls, cost_manager, prev_cost+offset_cost, i, **(**int32)(__ccgo_up(bp + 20)))
  17996 			} else {
  17997 				// Instead of considering all contributions from a pixel i by calling:
  17998 				//         PushInterval(cost_manager, prev_cost + offset_cost, i, len);
  17999 				// we optimize these contributions in case offset_cost stays the same
  18000 				// for consecutive pixels. This describes a set of pixels similar to a
  18001 				// previous set (e.g. constant color regions).
  18002 				if first_offset_is_constant != 0 {
  18003 					reach = i - int32(1) + len_prev - int32(1)
  18004 					first_offset_is_constant = 0
  18005 				}
  18006 				if i+**(**int32)(__ccgo_up(bp + 20))-int32(1) > reach {
  18007 					**(**int32)(__ccgo_up(bp + 28)) = 0
  18008 					// Figure out the last consecutive pixel within [i, reach + 1] with
  18009 					// the same offset.
  18010 					j = i
  18011 					for {
  18012 						if !(j <= reach) {
  18013 							break
  18014 						}
  18015 						v6 = hash_chain
  18016 						v1 = j + int32(1)
  18017 						v2 = int32(**(**uint32_t)(__ccgo_up((*VP8LHashChain)(unsafe.Pointer(v6)).Foffset_length + uintptr(v1)*4)) >> int32(MAX_LENGTH_BITS))
  18018 						goto _16
  18019 					_16:
  18020 						**(**int32)(__ccgo_up(bp + 24)) = v2
  18021 						v4 = int32(**(**uint32_t)(__ccgo_up((*VP8LHashChain)(unsafe.Pointer(v6)).Foffset_length + uintptr(v1)*4)) & (libc.Uint32FromUint32(1)<<libc.Int32FromInt32(MAX_LENGTH_BITS) - libc.Uint32FromInt32(1)))
  18022 						goto _18
  18023 					_18:
  18024 						**(**int32)(__ccgo_up(bp + 28)) = v4
  18025 						if **(**int32)(__ccgo_up(bp + 24)) != **(**int32)(__ccgo_up(bp + 16)) {
  18026 							v6 = hash_chain
  18027 							v1 = j
  18028 							v2 = int32(**(**uint32_t)(__ccgo_up((*VP8LHashChain)(unsafe.Pointer(v6)).Foffset_length + uintptr(v1)*4)) >> int32(MAX_LENGTH_BITS))
  18029 							goto _22
  18030 						_22:
  18031 							**(**int32)(__ccgo_up(bp + 24)) = v2
  18032 							v4 = int32(**(**uint32_t)(__ccgo_up((*VP8LHashChain)(unsafe.Pointer(v6)).Foffset_length + uintptr(v1)*4)) & (libc.Uint32FromUint32(1)<<libc.Int32FromInt32(MAX_LENGTH_BITS) - libc.Uint32FromInt32(1)))
  18033 							goto _24
  18034 						_24:
  18035 							**(**int32)(__ccgo_up(bp + 28)) = v4
  18036 							break
  18037 						}
  18038 						goto _12
  18039 					_12:
  18040 						;
  18041 						j = j + 1
  18042 					}
  18043 					// Update the cost at j - 1 and j.
  18044 					UpdateCostAtIndex(tls, cost_manager, j-int32(1), 0)
  18045 					UpdateCostAtIndex(tls, cost_manager, j, 0)
  18046 					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)))
  18047 					reach = j + **(**int32)(__ccgo_up(bp + 28)) - int32(1)
  18048 				}
  18049 			}
  18050 		}
  18051 		UpdateCostAtIndex(tls, cost_manager, i, int32(1))
  18052 		offset_prev = **(**int32)(__ccgo_up(bp + 16))
  18053 		len_prev = **(**int32)(__ccgo_up(bp + 20))
  18054 		goto _5
  18055 	_5:
  18056 		;
  18057 		i = i + 1
  18058 	}
  18059 	ok = libc.BoolInt32(!((*VP8LBackwardRefs)(unsafe.Pointer(refs)).Ferror1 != 0))
  18060 	goto Error
  18061 Error:
  18062 	;
  18063 	if cc_init != 0 {
  18064 		VP8LColorCacheClear(tls, bp)
  18065 	}
  18066 	CostManagerClear(tls, cost_manager)
  18067 	WebPSafeFree(tls, cost_model)
  18068 	WebPSafeFree(tls, cost_manager)
  18069 	return ok
  18070 }
  18071 
  18072 // C documentation
  18073 //
  18074 //	// We pack the path at the end of *dist_array and return
  18075 //	// a pointer to this part of the array. Example:
  18076 //	// dist_array = [1x2xx3x2] => packed [1x2x1232], chosen_path = [1232]
  18077 func TraceBackwards(tls *libc.TLS, dist_array uintptr, dist_array_size int32, chosen_path uintptr, chosen_path_size uintptr) {
  18078 	var cur, path uintptr
  18079 	var k int32
  18080 	_, _, _ = cur, k, path
  18081 	path = dist_array + uintptr(dist_array_size)*2
  18082 	cur = dist_array + uintptr(dist_array_size)*2 - uintptr(1)*2
  18083 	for cur >= dist_array {
  18084 		k = int32(**(**uint16_t)(__ccgo_up(cur)))
  18085 		path -= 2
  18086 		**(**uint16_t)(__ccgo_up(path)) = uint16(k)
  18087 		cur = cur - uintptr(k)*2
  18088 	}
  18089 	**(**uintptr)(__ccgo_up(chosen_path)) = path
  18090 	**(**int32)(__ccgo_up(chosen_path_size)) = int32((int64(dist_array+uintptr(dist_array_size)*2) - int64(path)) / 2)
  18091 }
  18092 
  18093 func BackwardReferencesHashChainFollowChosenPath(tls *libc.TLS, argb4 uintptr, cache_bits int32, chosen_path uintptr, chosen_path_size int32, hash_chain uintptr, refs uintptr) (r int32) {
  18094 	bp := tls.Alloc(16)
  18095 	defer tls.Free(16)
  18096 	var cc_init, i, idx1, ix, k, key, key1, len1, offset, ok, use_color_cache, v11, v14, v2, v9 int32
  18097 	var retval, retval1, retval2, v, v4 PixOrCopy
  18098 	var v7 uintptr
  18099 	var v8 uint32_t
  18100 	var _ /* hashers at bp+0 */ VP8LColorCache
  18101 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  18102 	use_color_cache = libc.BoolInt32(cache_bits > libc.Int32FromInt32(0))
  18103 	i = 0
  18104 	ok = 0
  18105 	cc_init = 0
  18106 	if use_color_cache != 0 {
  18107 		cc_init = VP8LColorCacheInit(tls, bp, cache_bits)
  18108 		if !(cc_init != 0) {
  18109 			goto Error
  18110 		}
  18111 	}
  18112 	VP8LClearBackwardRefs(tls, refs)
  18113 	ix = 0
  18114 	for {
  18115 		if !(ix < chosen_path_size) {
  18116 			break
  18117 		}
  18118 		len1 = int32(**(**uint16_t)(__ccgo_up(chosen_path + uintptr(ix)*2)))
  18119 		if len1 != int32(1) {
  18120 			v2 = int32(**(**uint32_t)(__ccgo_up((*VP8LHashChain)(unsafe.Pointer(hash_chain)).Foffset_length + uintptr(i)*4)) >> int32(MAX_LENGTH_BITS))
  18121 			goto _3
  18122 		_3:
  18123 			offset = v2
  18124 			retval.Fmode = uint8(kCopy)
  18125 			retval.Fargb_or_distance = uint32(offset)
  18126 			retval.Flen1 = uint16(len1)
  18127 			v4 = retval
  18128 			goto _5
  18129 		_5:
  18130 			VP8LBackwardRefsCursorAdd(tls, refs, v4)
  18131 			if use_color_cache != 0 {
  18132 				k = 0
  18133 				for {
  18134 					if !(k < len1) {
  18135 						break
  18136 					}
  18137 					v7 = bp
  18138 					v8 = **(**uint32_t)(__ccgo_up(argb4 + uintptr(i+k)*4))
  18139 					v2 = int32(v8 * kHashMul10 >> (*VP8LColorCache)(unsafe.Pointer(v7)).Fhash_shift)
  18140 					goto _10
  18141 				_10:
  18142 					key = v2
  18143 					**(**uint32_t)(__ccgo_up((*VP8LColorCache)(unsafe.Pointer(v7)).Fcolors + uintptr(key)*4)) = v8
  18144 					goto _6
  18145 				_6:
  18146 					;
  18147 					k = k + 1
  18148 				}
  18149 			}
  18150 			i = i + len1
  18151 		} else {
  18152 			if use_color_cache != 0 {
  18153 				v7 = bp
  18154 				v8 = **(**uint32_t)(__ccgo_up(argb4 + uintptr(i)*4))
  18155 				v9 = int32(v8 * kHashMul10 >> (*VP8LColorCache)(unsafe.Pointer(v7)).Fhash_shift)
  18156 				goto _15
  18157 			_15:
  18158 				key1 = v9
  18159 				if **(**uint32_t)(__ccgo_up((*VP8LColorCache)(unsafe.Pointer(v7)).Fcolors + uintptr(key1)*4)) == v8 {
  18160 					v14 = key1
  18161 				} else {
  18162 					v14 = -int32(1)
  18163 				}
  18164 				v11 = v14
  18165 				goto _17
  18166 			_17:
  18167 				v2 = v11
  18168 			} else {
  18169 				v2 = -int32(1)
  18170 			}
  18171 			idx1 = v2
  18172 			if idx1 >= 0 {
  18173 				// use_color_cache is true and hashers contains argb[i]
  18174 				// push pixel as a color cache index
  18175 				retval1.Fmode = uint8(kCacheIdx)
  18176 				retval1.Fargb_or_distance = uint32(idx1)
  18177 				retval1.Flen1 = uint16(1)
  18178 				v4 = retval1
  18179 				goto _20
  18180 			_20:
  18181 				v = v4
  18182 			} else {
  18183 				if use_color_cache != 0 {
  18184 					v7 = bp
  18185 					v8 = **(**uint32_t)(__ccgo_up(argb4 + uintptr(i)*4))
  18186 					v2 = int32(v8 * kHashMul10 >> (*VP8LColorCache)(unsafe.Pointer(v7)).Fhash_shift)
  18187 					goto _24
  18188 				_24:
  18189 					key = v2
  18190 					**(**uint32_t)(__ccgo_up((*VP8LColorCache)(unsafe.Pointer(v7)).Fcolors + uintptr(key)*4)) = v8
  18191 				}
  18192 				retval2.Fmode = uint8(kLiteral)
  18193 				retval2.Fargb_or_distance = **(**uint32_t)(__ccgo_up(argb4 + uintptr(i)*4))
  18194 				retval2.Flen1 = uint16(1)
  18195 				v4 = retval2
  18196 				goto _26
  18197 			_26:
  18198 				v = v4
  18199 			}
  18200 			VP8LBackwardRefsCursorAdd(tls, refs, v)
  18201 			i = i + 1
  18202 		}
  18203 		goto _1
  18204 	_1:
  18205 		;
  18206 		ix = ix + 1
  18207 	}
  18208 	ok = libc.BoolInt32(!((*VP8LBackwardRefs)(unsafe.Pointer(refs)).Ferror1 != 0))
  18209 	goto Error
  18210 Error:
  18211 	;
  18212 	if cc_init != 0 {
  18213 		VP8LColorCacheClear(tls, bp)
  18214 	}
  18215 	return ok
  18216 }
  18217 
  18218 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) {
  18219 	bp := tls.Alloc(16)
  18220 	defer tls.Free(16)
  18221 	var dist_array uintptr
  18222 	var dist_array_size, ok int32
  18223 	var _ /* chosen_path at bp+0 */ uintptr
  18224 	var _ /* chosen_path_size at bp+8 */ int32
  18225 	_, _, _ = dist_array, dist_array_size, ok
  18226 	ok = 0
  18227 	dist_array_size = xsize * ysize
  18228 	**(**uintptr)(__ccgo_up(bp)) = libc.UintptrFromInt32(0)
  18229 	**(**int32)(__ccgo_up(bp + 8)) = 0
  18230 	dist_array = WebPSafeMalloc(tls, uint64(dist_array_size), uint64(2))
  18231 	if dist_array == libc.UintptrFromInt32(0) {
  18232 		goto Error
  18233 	}
  18234 	if !(BackwardReferencesHashChainDistanceOnly(tls, xsize, ysize, argb, cache_bits, hash_chain, refs_src, dist_array) != 0) {
  18235 		goto Error
  18236 	}
  18237 	TraceBackwards(tls, dist_array, dist_array_size, bp, bp+8)
  18238 	if !(BackwardReferencesHashChainFollowChosenPath(tls, argb, cache_bits, **(**uintptr)(__ccgo_up(bp)), **(**int32)(__ccgo_up(bp + 8)), hash_chain, refs_dst) != 0) {
  18239 		goto Error
  18240 	}
  18241 	ok = int32(1)
  18242 	goto Error
  18243 Error:
  18244 	;
  18245 	WebPSafeFree(tls, dist_array)
  18246 	return ok
  18247 }
  18248 
  18249 const MIN_BLOCK_SIZE = 256
  18250 const MIN_LENGTH = 4
  18251 const SIZE_MAX4 = "_UI64_MAX"
  18252 const WINDOW_OFFSETS_SIZE_MAX = 32
  18253 
  18254 type PixOrCopyBlock = struct {
  18255 	Fnext  uintptr
  18256 	Fstart uintptr
  18257 	Fsize  int32
  18258 }
  18259 
  18260 var kHashMul11 = uint32(0x1e35a7bd)
  18261 
  18262 //------------------------------------------------------------------------------
  18263 
  18264 // Copyright 2012 Google Inc. All Rights Reserved.
  18265 //
  18266 // Use of this source code is governed by a BSD-style license
  18267 // that can be found in the COPYING file in the root of the source
  18268 // tree. An additional intellectual property rights grant can be found
  18269 // in the file PATENTS. All contributing project authors may
  18270 // be found in the AUTHORS file in the root of the source tree.
  18271 // -----------------------------------------------------------------------------
  18272 //
  18273 // Misc. common utility functions
  18274 //
  18275 // Authors: Skal (pascal.massimino@gmail.com)
  18276 //          Urvang (urvang@google.com)
  18277 
  18278 // Copyright 2011 Google Inc. All Rights Reserved.
  18279 //
  18280 // Use of this source code is governed by a BSD-style license
  18281 // that can be found in the COPYING file in the root of the source
  18282 // tree. An additional intellectual property rights grant can be found
  18283 // in the file PATENTS. All contributing project authors may
  18284 // be found in the AUTHORS file in the root of the source tree.
  18285 // -----------------------------------------------------------------------------
  18286 //
  18287 //   WebP encoder: main interface
  18288 //
  18289 // Author: Skal (pascal.massimino@gmail.com)
  18290 
  18291 // Copyright 2012 Google Inc. All Rights Reserved.
  18292 //
  18293 // Use of this source code is governed by a BSD-style license
  18294 // that can be found in the COPYING file in the root of the source
  18295 // tree. An additional intellectual property rights grant can be found
  18296 // in the file PATENTS. All contributing project authors may
  18297 // be found in the AUTHORS file in the root of the source tree.
  18298 // -----------------------------------------------------------------------------
  18299 //
  18300 //  Internal header for constants related to WebP file format.
  18301 //
  18302 // Author: Urvang (urvang@google.com)
  18303 
  18304 // Copyright 2010 Google Inc. All Rights Reserved.
  18305 //
  18306 // Use of this source code is governed by a BSD-style license
  18307 // that can be found in the COPYING file in the root of the source
  18308 // tree. An additional intellectual property rights grant can be found
  18309 // in the file PATENTS. All contributing project authors may
  18310 // be found in the AUTHORS file in the root of the source tree.
  18311 // -----------------------------------------------------------------------------
  18312 //
  18313 //  Common types + memory wrappers
  18314 //
  18315 // Author: Skal (pascal.massimino@gmail.com)
  18316 
  18317 // 1M window (4M bytes) minus 120 special codes for short distances.
  18318 
  18319 // Minimum number of pixels for which it is cheaper to encode a
  18320 // distance + length instead of each pixel as a literal.
  18321 
  18322 // -----------------------------------------------------------------------------
  18323 
  18324 var plane_to_code_lut = [128]uint8_t{
  18325 	0:   uint8(96),
  18326 	1:   uint8(73),
  18327 	2:   uint8(55),
  18328 	3:   uint8(39),
  18329 	4:   uint8(23),
  18330 	5:   uint8(13),
  18331 	6:   uint8(5),
  18332 	7:   uint8(1),
  18333 	8:   uint8(255),
  18334 	9:   uint8(255),
  18335 	10:  uint8(255),
  18336 	11:  uint8(255),
  18337 	12:  uint8(255),
  18338 	13:  uint8(255),
  18339 	14:  uint8(255),
  18340 	15:  uint8(255),
  18341 	16:  uint8(101),
  18342 	17:  uint8(78),
  18343 	18:  uint8(58),
  18344 	19:  uint8(42),
  18345 	20:  uint8(26),
  18346 	21:  uint8(16),
  18347 	22:  uint8(8),
  18348 	23:  uint8(2),
  18349 	25:  uint8(3),
  18350 	26:  uint8(9),
  18351 	27:  uint8(17),
  18352 	28:  uint8(27),
  18353 	29:  uint8(43),
  18354 	30:  uint8(59),
  18355 	31:  uint8(79),
  18356 	32:  uint8(102),
  18357 	33:  uint8(86),
  18358 	34:  uint8(62),
  18359 	35:  uint8(46),
  18360 	36:  uint8(32),
  18361 	37:  uint8(20),
  18362 	38:  uint8(10),
  18363 	39:  uint8(6),
  18364 	40:  uint8(4),
  18365 	41:  uint8(7),
  18366 	42:  uint8(11),
  18367 	43:  uint8(21),
  18368 	44:  uint8(33),
  18369 	45:  uint8(47),
  18370 	46:  uint8(63),
  18371 	47:  uint8(87),
  18372 	48:  uint8(105),
  18373 	49:  uint8(90),
  18374 	50:  uint8(70),
  18375 	51:  uint8(52),
  18376 	52:  uint8(37),
  18377 	53:  uint8(28),
  18378 	54:  uint8(18),
  18379 	55:  uint8(14),
  18380 	56:  uint8(12),
  18381 	57:  uint8(15),
  18382 	58:  uint8(19),
  18383 	59:  uint8(29),
  18384 	60:  uint8(38),
  18385 	61:  uint8(53),
  18386 	62:  uint8(71),
  18387 	63:  uint8(91),
  18388 	64:  uint8(110),
  18389 	65:  uint8(99),
  18390 	66:  uint8(82),
  18391 	67:  uint8(66),
  18392 	68:  uint8(48),
  18393 	69:  uint8(35),
  18394 	70:  uint8(30),
  18395 	71:  uint8(24),
  18396 	72:  uint8(22),
  18397 	73:  uint8(25),
  18398 	74:  uint8(31),
  18399 	75:  uint8(36),
  18400 	76:  uint8(49),
  18401 	77:  uint8(67),
  18402 	78:  uint8(83),
  18403 	79:  uint8(100),
  18404 	80:  uint8(115),
  18405 	81:  uint8(108),
  18406 	82:  uint8(94),
  18407 	83:  uint8(76),
  18408 	84:  uint8(64),
  18409 	85:  uint8(50),
  18410 	86:  uint8(44),
  18411 	87:  uint8(40),
  18412 	88:  uint8(34),
  18413 	89:  uint8(41),
  18414 	90:  uint8(45),
  18415 	91:  uint8(51),
  18416 	92:  uint8(65),
  18417 	93:  uint8(77),
  18418 	94:  uint8(95),
  18419 	95:  uint8(109),
  18420 	96:  uint8(118),
  18421 	97:  uint8(113),
  18422 	98:  uint8(103),
  18423 	99:  uint8(92),
  18424 	100: uint8(80),
  18425 	101: uint8(68),
  18426 	102: uint8(60),
  18427 	103: uint8(56),
  18428 	104: uint8(54),
  18429 	105: uint8(57),
  18430 	106: uint8(61),
  18431 	107: uint8(69),
  18432 	108: uint8(81),
  18433 	109: uint8(93),
  18434 	110: uint8(104),
  18435 	111: uint8(114),
  18436 	112: uint8(119),
  18437 	113: uint8(116),
  18438 	114: uint8(111),
  18439 	115: uint8(106),
  18440 	116: uint8(97),
  18441 	117: uint8(88),
  18442 	118: uint8(84),
  18443 	119: uint8(74),
  18444 	120: uint8(72),
  18445 	121: uint8(75),
  18446 	122: uint8(85),
  18447 	123: uint8(89),
  18448 	124: uint8(98),
  18449 	125: uint8(107),
  18450 	126: uint8(112),
  18451 	127: uint8(117),
  18452 }
  18453 
  18454 func VP8LDistanceToPlaneCode(tls *libc.TLS, xsize int32, dist int32) (r int32) {
  18455 	var xoffset, yoffset int32
  18456 	_, _ = xoffset, yoffset
  18457 	yoffset = dist / xsize
  18458 	xoffset = dist - yoffset*xsize
  18459 	if xoffset <= int32(8) && yoffset < int32(8) {
  18460 		return int32(plane_to_code_lut[yoffset*int32(16)+int32(8)-xoffset]) + int32(1)
  18461 	} else {
  18462 		if xoffset > xsize-int32(8) && yoffset < int32(7) {
  18463 			return int32(plane_to_code_lut[(yoffset+int32(1))*int32(16)+int32(8)+(xsize-xoffset)]) + int32(1)
  18464 		}
  18465 	}
  18466 	return dist + int32(120)
  18467 }
  18468 
  18469 // C documentation
  18470 //
  18471 //	// Returns the exact index where array1 and array2 are different. For an index
  18472 //	// inferior or equal to best_len_match, the return value just has to be strictly
  18473 //	// inferior to best_len_match. The current behavior is to return 0 if this index
  18474 //	// is best_len_match, and the index itself otherwise.
  18475 //	// If no two elements are the same, it returns max_limit.
  18476 func FindMatchLength(tls *libc.TLS, array1 uintptr, array2 uintptr, best_len_match int32, max_limit int32) (r int32) {
  18477 	// Before 'expensive' linear match, check if the two arrays match at the
  18478 	// current best length index.
  18479 	if **(**uint32_t)(__ccgo_up(array1 + uintptr(best_len_match)*4)) != **(**uint32_t)(__ccgo_up(array2 + uintptr(best_len_match)*4)) {
  18480 		return 0
  18481 	}
  18482 	return (*(*func(*libc.TLS, uintptr, uintptr, int32) int32)(unsafe.Pointer(&struct{ uintptr }{VP8LVectorMismatch})))(tls, array1, array2, max_limit)
  18483 }
  18484 
  18485 func VP8LClearBackwardRefs(tls *libc.TLS, refs uintptr) {
  18486 	if (*VP8LBackwardRefs)(unsafe.Pointer(refs)).Ftail != libc.UintptrFromInt32(0) {
  18487 		**(**uintptr)(__ccgo_up((*VP8LBackwardRefs)(unsafe.Pointer(refs)).Ftail)) = (*VP8LBackwardRefs)(unsafe.Pointer(refs)).Ffree_blocks // recycle all blocks at once
  18488 	}
  18489 	(*VP8LBackwardRefs)(unsafe.Pointer(refs)).Ffree_blocks = (*VP8LBackwardRefs)(unsafe.Pointer(refs)).Frefs
  18490 	(*VP8LBackwardRefs)(unsafe.Pointer(refs)).Ftail = refs + 8
  18491 	(*VP8LBackwardRefs)(unsafe.Pointer(refs)).Flast_block = libc.UintptrFromInt32(0)
  18492 	(*VP8LBackwardRefs)(unsafe.Pointer(refs)).Frefs = libc.UintptrFromInt32(0)
  18493 }
  18494 
  18495 func VP8LBackwardRefsClear(tls *libc.TLS, refs uintptr) {
  18496 	var next uintptr
  18497 	_ = next
  18498 	VP8LClearBackwardRefs(tls, refs)
  18499 	for (*VP8LBackwardRefs)(unsafe.Pointer(refs)).Ffree_blocks != libc.UintptrFromInt32(0) {
  18500 		next = (*PixOrCopyBlock)(unsafe.Pointer((*VP8LBackwardRefs)(unsafe.Pointer(refs)).Ffree_blocks)).Fnext
  18501 		WebPSafeFree(tls, (*VP8LBackwardRefs)(unsafe.Pointer(refs)).Ffree_blocks)
  18502 		(*VP8LBackwardRefs)(unsafe.Pointer(refs)).Ffree_blocks = next
  18503 	}
  18504 }
  18505 
  18506 // C documentation
  18507 //
  18508 //	// Swaps the content of two VP8LBackwardRefs.
  18509 func BackwardRefsSwap(tls *libc.TLS, refs1 uintptr, refs2 uintptr) {
  18510 	var point_to_refs1, point_to_refs2 int32
  18511 	var tmp VP8LBackwardRefs
  18512 	_, _, _ = point_to_refs1, point_to_refs2, tmp
  18513 	point_to_refs1 = libc.BoolInt32((*VP8LBackwardRefs)(unsafe.Pointer(refs1)).Ftail != libc.UintptrFromInt32(0) && (*VP8LBackwardRefs)(unsafe.Pointer(refs1)).Ftail == refs1+8)
  18514 	point_to_refs2 = libc.BoolInt32((*VP8LBackwardRefs)(unsafe.Pointer(refs2)).Ftail != libc.UintptrFromInt32(0) && (*VP8LBackwardRefs)(unsafe.Pointer(refs2)).Ftail == refs2+8)
  18515 	tmp = **(**VP8LBackwardRefs)(__ccgo_up(refs1))
  18516 	**(**VP8LBackwardRefs)(__ccgo_up(refs1)) = **(**VP8LBackwardRefs)(__ccgo_up(refs2))
  18517 	**(**VP8LBackwardRefs)(__ccgo_up(refs2)) = tmp
  18518 	if point_to_refs2 != 0 {
  18519 		(*VP8LBackwardRefs)(unsafe.Pointer(refs1)).Ftail = refs1 + 8
  18520 	}
  18521 	if point_to_refs1 != 0 {
  18522 		(*VP8LBackwardRefs)(unsafe.Pointer(refs2)).Ftail = refs2 + 8
  18523 	}
  18524 }
  18525 
  18526 func VP8LBackwardRefsInit(tls *libc.TLS, refs uintptr, block_size int32) {
  18527 	var v1 int32
  18528 	_ = v1
  18529 	libc.Xmemset(tls, refs, 0, uint64(40))
  18530 	(*VP8LBackwardRefs)(unsafe.Pointer(refs)).Ftail = refs + 8
  18531 	if block_size < int32(MIN_BLOCK_SIZE) {
  18532 		v1 = int32(MIN_BLOCK_SIZE)
  18533 	} else {
  18534 		v1 = block_size
  18535 	}
  18536 	(*VP8LBackwardRefs)(unsafe.Pointer(refs)).Fblock_size = v1
  18537 }
  18538 
  18539 func VP8LRefsCursorInit(tls *libc.TLS, refs uintptr) (r VP8LRefsCursor) {
  18540 	var c VP8LRefsCursor
  18541 	_ = c
  18542 	c.Fcur_block = (*VP8LBackwardRefs)(unsafe.Pointer(refs)).Frefs
  18543 	if (*VP8LBackwardRefs)(unsafe.Pointer(refs)).Frefs != libc.UintptrFromInt32(0) {
  18544 		c.Fcur_pos = (*PixOrCopyBlock)(unsafe.Pointer(c.Fcur_block)).Fstart
  18545 		c.Flast_pos = c.Fcur_pos + uintptr((*PixOrCopyBlock)(unsafe.Pointer(c.Fcur_block)).Fsize)*8
  18546 	} else {
  18547 		c.Fcur_pos = libc.UintptrFromInt32(0)
  18548 		c.Flast_pos = libc.UintptrFromInt32(0)
  18549 	}
  18550 	return c
  18551 }
  18552 
  18553 func VP8LRefsCursorNextBlock(tls *libc.TLS, c uintptr) {
  18554 	var b, v1 uintptr
  18555 	_, _ = b, v1
  18556 	b = (*PixOrCopyBlock)(unsafe.Pointer((*VP8LRefsCursor)(unsafe.Pointer(c)).Fcur_block)).Fnext
  18557 	if b == libc.UintptrFromInt32(0) {
  18558 		v1 = libc.UintptrFromInt32(0)
  18559 	} else {
  18560 		v1 = (*PixOrCopyBlock)(unsafe.Pointer(b)).Fstart
  18561 	}
  18562 	(*VP8LRefsCursor)(unsafe.Pointer(c)).Fcur_pos = v1
  18563 	if b == libc.UintptrFromInt32(0) {
  18564 		v1 = libc.UintptrFromInt32(0)
  18565 	} else {
  18566 		v1 = (*PixOrCopyBlock)(unsafe.Pointer(b)).Fstart + uintptr((*PixOrCopyBlock)(unsafe.Pointer(b)).Fsize)*8
  18567 	}
  18568 	(*VP8LRefsCursor)(unsafe.Pointer(c)).Flast_pos = v1
  18569 	(*VP8LRefsCursor)(unsafe.Pointer(c)).Fcur_block = b
  18570 }
  18571 
  18572 // C documentation
  18573 //
  18574 //	// Create a new block, either from the free list or allocated
  18575 func BackwardRefsNewBlock(tls *libc.TLS, refs uintptr) (r uintptr) {
  18576 	var b uintptr
  18577 	var total_size size_t
  18578 	_, _ = b, total_size
  18579 	b = (*VP8LBackwardRefs)(unsafe.Pointer(refs)).Ffree_blocks
  18580 	if b == libc.UintptrFromInt32(0) { // allocate new memory chunk
  18581 		total_size = uint64(24) + uint64((*VP8LBackwardRefs)(unsafe.Pointer(refs)).Fblock_size)*uint64(8)
  18582 		b = WebPSafeMalloc(tls, uint64(1), total_size)
  18583 		if b == libc.UintptrFromInt32(0) {
  18584 			**(**int32)(__ccgo_up(refs + 4)) |= int32(1)
  18585 			return libc.UintptrFromInt32(0)
  18586 		}
  18587 		(*PixOrCopyBlock)(unsafe.Pointer(b)).Fstart = b + libc.UintptrFromInt64(24) // not always aligned
  18588 	} else { // recycle from free-list
  18589 		(*VP8LBackwardRefs)(unsafe.Pointer(refs)).Ffree_blocks = (*PixOrCopyBlock)(unsafe.Pointer(b)).Fnext
  18590 	}
  18591 	**(**uintptr)(__ccgo_up((*VP8LBackwardRefs)(unsafe.Pointer(refs)).Ftail)) = b
  18592 	(*VP8LBackwardRefs)(unsafe.Pointer(refs)).Ftail = b
  18593 	(*VP8LBackwardRefs)(unsafe.Pointer(refs)).Flast_block = b
  18594 	(*PixOrCopyBlock)(unsafe.Pointer(b)).Fnext = libc.UintptrFromInt32(0)
  18595 	(*PixOrCopyBlock)(unsafe.Pointer(b)).Fsize = 0
  18596 	return b
  18597 }
  18598 
  18599 // C documentation
  18600 //
  18601 //	// Return 1 on success, 0 on error.
  18602 func BackwardRefsClone(tls *libc.TLS, from uintptr, to uintptr) (r int32) {
  18603 	var block_from, block_to uintptr
  18604 	_, _ = block_from, block_to
  18605 	block_from = (*VP8LBackwardRefs)(unsafe.Pointer(from)).Frefs
  18606 	VP8LClearBackwardRefs(tls, to)
  18607 	for block_from != libc.UintptrFromInt32(0) {
  18608 		block_to = BackwardRefsNewBlock(tls, to)
  18609 		if block_to == libc.UintptrFromInt32(0) {
  18610 			return 0
  18611 		}
  18612 		libc.Xmemcpy(tls, (*PixOrCopyBlock)(unsafe.Pointer(block_to)).Fstart, (*PixOrCopyBlock)(unsafe.Pointer(block_from)).Fstart, uint64((*PixOrCopyBlock)(unsafe.Pointer(block_from)).Fsize)*uint64(8))
  18613 		(*PixOrCopyBlock)(unsafe.Pointer(block_to)).Fsize = (*PixOrCopyBlock)(unsafe.Pointer(block_from)).Fsize
  18614 		block_from = (*PixOrCopyBlock)(unsafe.Pointer(block_from)).Fnext
  18615 	}
  18616 	return int32(1)
  18617 }
  18618 
  18619 func VP8LBackwardRefsCursorAdd(tls *libc.TLS, refs uintptr, v PixOrCopy) {
  18620 	var b, v2 uintptr
  18621 	var v1 int32
  18622 	_, _, _ = b, v1, v2
  18623 	b = (*VP8LBackwardRefs)(unsafe.Pointer(refs)).Flast_block
  18624 	if b == libc.UintptrFromInt32(0) || (*PixOrCopyBlock)(unsafe.Pointer(b)).Fsize == (*VP8LBackwardRefs)(unsafe.Pointer(refs)).Fblock_size {
  18625 		b = BackwardRefsNewBlock(tls, refs)
  18626 		if b == libc.UintptrFromInt32(0) {
  18627 			return
  18628 		} // refs->error is set
  18629 	}
  18630 	v2 = b + 16
  18631 	v1 = *(*int32)(unsafe.Pointer(v2))
  18632 	*(*int32)(unsafe.Pointer(v2)) = *(*int32)(unsafe.Pointer(v2)) + 1
  18633 	**(**PixOrCopy)(__ccgo_up((*PixOrCopyBlock)(unsafe.Pointer(b)).Fstart + uintptr(v1)*8)) = v
  18634 }
  18635 
  18636 // -----------------------------------------------------------------------------
  18637 // Hash chains
  18638 
  18639 func VP8LHashChainInit(tls *libc.TLS, p uintptr, size int32) (r int32) {
  18640 	(*VP8LHashChain)(unsafe.Pointer(p)).Foffset_length = WebPSafeMalloc(tls, uint64(size), uint64(4))
  18641 	if (*VP8LHashChain)(unsafe.Pointer(p)).Foffset_length == libc.UintptrFromInt32(0) {
  18642 		return 0
  18643 	}
  18644 	(*VP8LHashChain)(unsafe.Pointer(p)).Fsize = size
  18645 	return int32(1)
  18646 }
  18647 
  18648 func VP8LHashChainClear(tls *libc.TLS, p uintptr) {
  18649 	WebPSafeFree(tls, (*VP8LHashChain)(unsafe.Pointer(p)).Foffset_length)
  18650 	(*VP8LHashChain)(unsafe.Pointer(p)).Fsize = 0
  18651 	(*VP8LHashChain)(unsafe.Pointer(p)).Foffset_length = libc.UintptrFromInt32(0)
  18652 }
  18653 
  18654 // -----------------------------------------------------------------------------
  18655 
  18656 var kHashMultiplierHi = uint32(0xc6a4a793)
  18657 var kHashMultiplierLo = uint32(0x5bd1e996)
  18658 
  18659 func GetPixPairHash64(tls *libc.TLS, argb uintptr) (r uint32_t) {
  18660 	var key uint32_t
  18661 	_ = key
  18662 	key = **(**uint32_t)(__ccgo_up(argb + 1*4)) * kHashMultiplierHi
  18663 	key = key + **(**uint32_t)(__ccgo_up(argb))*kHashMultiplierLo
  18664 	key = key >> (libc.Int32FromInt32(32) - libc.Int32FromInt32(HASH_BITS))
  18665 	return key
  18666 }
  18667 
  18668 // C documentation
  18669 //
  18670 //	// Returns the maximum number of hash chain lookups to do for a
  18671 //	// given compression quality. Return value in range [8, 86].
  18672 func GetMaxItersForQuality(tls *libc.TLS, quality int32) (r int32) {
  18673 	return int32(8) + quality*quality/int32(128)
  18674 }
  18675 
  18676 func GetWindowSizeForHashChain(tls *libc.TLS, quality int32, xsize int32) (r int32) {
  18677 	var max_window_size, v1, v2, v3 int32
  18678 	_, _, _, _ = max_window_size, v1, v2, v3
  18679 	if quality > int32(75) {
  18680 		v1 = libc.Int32FromInt32(1)<<libc.Int32FromInt32(WINDOW_SIZE_BITS) - libc.Int32FromInt32(120)
  18681 	} else {
  18682 		if quality > int32(50) {
  18683 			v2 = xsize << int32(8)
  18684 		} else {
  18685 			if quality > int32(25) {
  18686 				v3 = xsize << int32(6)
  18687 			} else {
  18688 				v3 = xsize << int32(4)
  18689 			}
  18690 			v2 = v3
  18691 		}
  18692 		v1 = v2
  18693 	}
  18694 	max_window_size = v1
  18695 	if max_window_size > libc.Int32FromInt32(1)<<libc.Int32FromInt32(WINDOW_SIZE_BITS)-libc.Int32FromInt32(120) {
  18696 		v1 = libc.Int32FromInt32(1)<<libc.Int32FromInt32(WINDOW_SIZE_BITS) - libc.Int32FromInt32(120)
  18697 	} else {
  18698 		v1 = max_window_size
  18699 	}
  18700 	return v1
  18701 }
  18702 
  18703 func MaxFindCopyLength(tls *libc.TLS, len1 int32) (r int32) {
  18704 	var v1 int32
  18705 	_ = v1
  18706 	if len1 < libc.Int32FromInt32(1)<<libc.Int32FromInt32(MAX_LENGTH_BITS)-libc.Int32FromInt32(1) {
  18707 		v1 = len1
  18708 	} else {
  18709 		v1 = libc.Int32FromInt32(1)<<libc.Int32FromInt32(MAX_LENGTH_BITS) - libc.Int32FromInt32(1)
  18710 	}
  18711 	return v1
  18712 }
  18713 
  18714 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) {
  18715 	bp := tls.Alloc(16)
  18716 	defer tls.Free(16)
  18717 	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
  18718 	var argb_start, chain, hash_to_first_index uintptr
  18719 	var base_position, best_argb, best_distance, hash_code, len1, max_base_position, window_size, v1 uint32_t
  18720 	var v12 bool
  18721 	var v8 uint32
  18722 	var _ /* tmp at bp+0 */ [2]uint32_t
  18723 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  18724 	size = xsize * ysize
  18725 	iter_max = GetMaxItersForQuality(tls, quality)
  18726 	window_size = uint32(GetWindowSizeForHashChain(tls, quality, xsize))
  18727 	remaining_percent = percent_range
  18728 	percent_start = **(**int32)(__ccgo_up(percent))
  18729 	// Temporarily use the p->offset_length as a hash chain.
  18730 	chain = (*VP8LHashChain)(unsafe.Pointer(p)).Foffset_length
  18731 	if size <= int32(2) {
  18732 		v1 = libc.Uint32FromInt32(0)
  18733 		**(**uint32_t)(__ccgo_up((*VP8LHashChain)(unsafe.Pointer(p)).Foffset_length + uintptr(size-int32(1))*4)) = v1
  18734 		**(**uint32_t)(__ccgo_up((*VP8LHashChain)(unsafe.Pointer(p)).Foffset_length)) = v1
  18735 		return int32(1)
  18736 	}
  18737 	hash_to_first_index = WebPSafeMalloc(tls, uint64(libc.Int32FromInt32(1)<<libc.Int32FromInt32(HASH_BITS)), uint64(4))
  18738 	if hash_to_first_index == libc.UintptrFromInt32(0) {
  18739 		return WebPEncodingSetError(tls, pic, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  18740 	}
  18741 	percent_range = remaining_percent / int32(2)
  18742 	remaining_percent = remaining_percent - percent_range
  18743 	// Set the int32_t array to -1.
  18744 	libc.Xmemset(tls, hash_to_first_index, int32(0xff), uint64(libc.Int32FromInt32(1)<<libc.Int32FromInt32(HASH_BITS))*libc.Uint64FromInt64(4))
  18745 	// Fill the chain linking pixels with the same hash.
  18746 	argb_comp = libc.BoolInt32(**(**uint32_t)(__ccgo_up(argb)) == **(**uint32_t)(__ccgo_up(argb + 1*4)))
  18747 	pos = 0
  18748 	for {
  18749 		if !(pos < size-int32(2)) {
  18750 			break
  18751 		}
  18752 		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)))
  18753 		if argb_comp != 0 && argb_comp_next != 0 {
  18754 			len1 = uint32(1)
  18755 			(**(**[2]uint32_t)(__ccgo_up(bp)))[0] = **(**uint32_t)(__ccgo_up(argb + uintptr(pos)*4))
  18756 			// Figure out how far the pixels are the same.
  18757 			// The last pixel has a different 64 bit hash, as its next pixel does
  18758 			// not have the same color, so we just need to get to the last pixel equal
  18759 			// to its follower.
  18760 			for pos+int32(len1)+int32(2) < size && **(**uint32_t)(__ccgo_up(argb + uintptr(uint32(pos)+len1+uint32(2))*4)) == **(**uint32_t)(__ccgo_up(argb + uintptr(pos)*4)) {
  18761 				len1 = len1 + 1
  18762 			}
  18763 			if len1 > uint32(libc.Int32FromInt32(1)<<libc.Int32FromInt32(MAX_LENGTH_BITS)-libc.Int32FromInt32(1)) {
  18764 				// Skip the pixels that match for distance=1 and length>MAX_LENGTH
  18765 				// because they are linked to their predecessor and we automatically
  18766 				// check that in the main for loop below. Skipping means setting no
  18767 				// predecessor in the chain, hence -1.
  18768 				libc.Xmemset(tls, chain+uintptr(pos)*4, int32(0xff), uint64(len1-uint32(libc.Int32FromInt32(1)<<libc.Int32FromInt32(MAX_LENGTH_BITS)-libc.Int32FromInt32(1)))*uint64(4))
  18769 				pos = int32(uint32(pos) + (len1 - uint32(libc.Int32FromInt32(1)<<libc.Int32FromInt32(MAX_LENGTH_BITS)-libc.Int32FromInt32(1))))
  18770 				len1 = uint32(libc.Int32FromInt32(1)<<libc.Int32FromInt32(MAX_LENGTH_BITS) - libc.Int32FromInt32(1))
  18771 			}
  18772 			// Process the rest of the hash chain.
  18773 			for len1 != 0 {
  18774 				v1 = len1
  18775 				len1 = len1 - 1
  18776 				(**(**[2]uint32_t)(__ccgo_up(bp)))[int32(1)] = v1
  18777 				hash_code = GetPixPairHash64(tls, bp)
  18778 				**(**int32_t)(__ccgo_up(chain + uintptr(pos)*4)) = **(**int32_t)(__ccgo_up(hash_to_first_index + uintptr(hash_code)*4))
  18779 				v4 = pos
  18780 				pos = pos + 1
  18781 				**(**int32_t)(__ccgo_up(hash_to_first_index + uintptr(hash_code)*4)) = v4
  18782 			}
  18783 			argb_comp = 0
  18784 		} else {
  18785 			// Just move one pixel forward.
  18786 			hash_code = GetPixPairHash64(tls, argb+uintptr(pos)*4)
  18787 			**(**int32_t)(__ccgo_up(chain + uintptr(pos)*4)) = **(**int32_t)(__ccgo_up(hash_to_first_index + uintptr(hash_code)*4))
  18788 			v4 = pos
  18789 			pos = pos + 1
  18790 			**(**int32_t)(__ccgo_up(hash_to_first_index + uintptr(hash_code)*4)) = v4
  18791 			argb_comp = argb_comp_next
  18792 		}
  18793 		if !(WebPReportProgress(tls, pic, percent_start+percent_range*pos/(size-int32(2)), percent) != 0) {
  18794 			WebPSafeFree(tls, hash_to_first_index)
  18795 			return 0
  18796 		}
  18797 		goto _2
  18798 	_2:
  18799 	}
  18800 	// Process the penultimate pixel.
  18801 	**(**int32_t)(__ccgo_up(chain + uintptr(pos)*4)) = **(**int32_t)(__ccgo_up(hash_to_first_index + uintptr(GetPixPairHash64(tls, argb+uintptr(pos)*4))*4))
  18802 	WebPSafeFree(tls, hash_to_first_index)
  18803 	percent_start = percent_start + percent_range
  18804 	if !(WebPReportProgress(tls, pic, percent_start, percent) != 0) {
  18805 		return 0
  18806 	}
  18807 	percent_range = remaining_percent
  18808 	// Find the best match interval at each pixel, defined by an offset to the
  18809 	// pixel and a length. The right-most pixel cannot match anything to the right
  18810 	// (hence a best length of 0) and the left-most pixel nothing to the left
  18811 	// (hence an offset of 0).
  18812 	v1 = libc.Uint32FromInt32(0)
  18813 	**(**uint32_t)(__ccgo_up((*VP8LHashChain)(unsafe.Pointer(p)).Foffset_length + uintptr(size-int32(1))*4)) = v1
  18814 	**(**uint32_t)(__ccgo_up((*VP8LHashChain)(unsafe.Pointer(p)).Foffset_length)) = v1
  18815 	base_position = uint32(size - int32(2))
  18816 	for {
  18817 		if !(base_position > uint32(0)) {
  18818 			break
  18819 		}
  18820 		max_len = MaxFindCopyLength(tls, int32(uint32(size-int32(1))-base_position))
  18821 		argb_start = argb + uintptr(base_position)*4
  18822 		iter = iter_max
  18823 		best_length = 0
  18824 		best_distance = uint32(0)
  18825 		if base_position > window_size {
  18826 			v8 = base_position - window_size
  18827 		} else {
  18828 			v8 = uint32(0)
  18829 		}
  18830 		min_pos = int32(v8)
  18831 		if max_len < int32(256) {
  18832 			v4 = max_len
  18833 		} else {
  18834 			v4 = int32(256)
  18835 		}
  18836 		length_max = v4
  18837 		pos = **(**int32_t)(__ccgo_up(chain + uintptr(base_position)*4))
  18838 		if !(low_effort != 0) {
  18839 			// Heuristic: use the comparison with the above line as an initialization.
  18840 			if base_position >= uint32(xsize) {
  18841 				curr_length = FindMatchLength(tls, argb_start-uintptr(xsize)*4, argb_start, best_length, max_len)
  18842 				if curr_length > best_length {
  18843 					best_length = curr_length
  18844 					best_distance = uint32(xsize)
  18845 				}
  18846 				iter = iter - 1
  18847 			}
  18848 			// Heuristic: compare to the previous pixel.
  18849 			curr_length = FindMatchLength(tls, argb_start-uintptr(1)*4, argb_start, best_length, max_len)
  18850 			if curr_length > best_length {
  18851 				best_length = curr_length
  18852 				best_distance = uint32(1)
  18853 			}
  18854 			iter = iter - 1
  18855 			// Skip the for loop if we already have the maximum.
  18856 			if best_length == libc.Int32FromInt32(1)<<libc.Int32FromInt32(MAX_LENGTH_BITS)-libc.Int32FromInt32(1) {
  18857 				pos = min_pos - int32(1)
  18858 			}
  18859 		}
  18860 		best_argb = **(**uint32_t)(__ccgo_up(argb_start + uintptr(best_length)*4))
  18861 		for {
  18862 			if v12 = pos >= min_pos; v12 {
  18863 				iter = iter - 1
  18864 				v4 = iter
  18865 			}
  18866 			if !(v12 && v4 != 0) {
  18867 				break
  18868 			}
  18869 			if **(**uint32_t)(__ccgo_up(argb + uintptr(pos+best_length)*4)) != best_argb {
  18870 				goto _10
  18871 			}
  18872 			curr_length1 = (*(*func(*libc.TLS, uintptr, uintptr, int32) int32)(unsafe.Pointer(&struct{ uintptr }{VP8LVectorMismatch})))(tls, argb+uintptr(pos)*4, argb_start, max_len)
  18873 			if best_length < curr_length1 {
  18874 				best_length = curr_length1
  18875 				best_distance = base_position - uint32(pos)
  18876 				best_argb = **(**uint32_t)(__ccgo_up(argb_start + uintptr(best_length)*4))
  18877 				// Stop if we have reached a good enough length.
  18878 				if best_length >= length_max {
  18879 					break
  18880 				}
  18881 			}
  18882 			goto _10
  18883 		_10:
  18884 			;
  18885 			pos = **(**int32_t)(__ccgo_up(chain + uintptr(pos)*4))
  18886 		}
  18887 		// We have the best match but in case the two intervals continue matching
  18888 		// to the left, we have the best matches for the left-extended pixels.
  18889 		max_base_position = base_position
  18890 		for int32(1) != 0 {
  18891 			**(**uint32_t)(__ccgo_up((*VP8LHashChain)(unsafe.Pointer(p)).Foffset_length + uintptr(base_position)*4)) = best_distance<<libc.Int32FromInt32(MAX_LENGTH_BITS) | uint32(best_length)
  18892 			base_position = base_position - 1
  18893 			// Stop if we don't have a match or if we are out of bounds.
  18894 			if best_distance == uint32(0) || base_position == uint32(0) {
  18895 				break
  18896 			}
  18897 			// Stop if we cannot extend the matching intervals to the left.
  18898 			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)) {
  18899 				break
  18900 			}
  18901 			// Stop if we are matching at its limit because there could be a closer
  18902 			// matching interval with the same maximum length. Then again, if the
  18903 			// matching interval is as close as possible (best_distance == 1), we will
  18904 			// never find anything better so let's continue.
  18905 			if best_length == libc.Int32FromInt32(1)<<libc.Int32FromInt32(MAX_LENGTH_BITS)-libc.Int32FromInt32(1) && best_distance != uint32(1) && base_position+uint32(libc.Int32FromInt32(1)<<libc.Int32FromInt32(MAX_LENGTH_BITS)-libc.Int32FromInt32(1)) < max_base_position {
  18906 				break
  18907 			}
  18908 			if best_length < libc.Int32FromInt32(1)<<libc.Int32FromInt32(MAX_LENGTH_BITS)-libc.Int32FromInt32(1) {
  18909 				best_length = best_length + 1
  18910 				max_base_position = base_position
  18911 			}
  18912 		}
  18913 		if !(WebPReportProgress(tls, pic, int32(uint32(percent_start)+uint32(percent_range)*(uint32(size-int32(2))-base_position)/uint32(size-libc.Int32FromInt32(2))), percent) != 0) {
  18914 			return 0
  18915 		}
  18916 		goto _7
  18917 	_7:
  18918 	}
  18919 	return WebPReportProgress(tls, pic, percent_start+percent_range, percent)
  18920 }
  18921 
  18922 func AddSingleLiteral(tls *libc.TLS, pixel uint32_t, use_color_cache int32, hashers uintptr, refs uintptr) {
  18923 	var key2, v5 uint32_t
  18924 	var retval, retval1, v, v7 PixOrCopy
  18925 	var v1, v3 int32
  18926 	_, _, _, _, _, _, _, _ = key2, retval, retval1, v, v1, v3, v5, v7
  18927 	if use_color_cache != 0 {
  18928 		v3 = int32(pixel * kHashMul11 >> (*VP8LColorCache)(unsafe.Pointer(hashers)).Fhash_shift)
  18929 		goto _4
  18930 	_4:
  18931 		v1 = v3
  18932 		goto _2
  18933 	_2:
  18934 		key2 = uint32(v1)
  18935 		v5 = **(**uint32_t)(__ccgo_up((*VP8LColorCache)(unsafe.Pointer(hashers)).Fcolors + uintptr(key2)*4))
  18936 		goto _6
  18937 	_6:
  18938 		if v5 == pixel {
  18939 			retval.Fmode = uint8(kCacheIdx)
  18940 			retval.Fargb_or_distance = uint32(int32(key2))
  18941 			retval.Flen1 = uint16(1)
  18942 			v7 = retval
  18943 			goto _8
  18944 		_8:
  18945 			v = v7
  18946 		} else {
  18947 			retval1.Fmode = uint8(kLiteral)
  18948 			retval1.Fargb_or_distance = pixel
  18949 			retval1.Flen1 = uint16(1)
  18950 			v7 = retval1
  18951 			goto _10
  18952 		_10:
  18953 			v = v7
  18954 			**(**uint32_t)(__ccgo_up((*VP8LColorCache)(unsafe.Pointer(hashers)).Fcolors + uintptr(key2)*4)) = pixel
  18955 		}
  18956 	} else {
  18957 		retval1.Fmode = uint8(kLiteral)
  18958 		retval1.Fargb_or_distance = pixel
  18959 		retval1.Flen1 = uint16(1)
  18960 		v7 = retval1
  18961 		goto _12
  18962 	_12:
  18963 		v = v7
  18964 	}
  18965 	VP8LBackwardRefsCursorAdd(tls, refs, v)
  18966 }
  18967 
  18968 func BackwardReferencesRle(tls *libc.TLS, xsize int32, ysize int32, argb2 uintptr, cache_bits int32, refs uintptr) (r int32) {
  18969 	bp := tls.Alloc(16)
  18970 	defer tls.Free(16)
  18971 	var i, k, key, max_len, pix_count, prev_row_len, rle_len, use_color_cache, v1 int32
  18972 	var retval, v2 PixOrCopy
  18973 	var v7 uintptr
  18974 	var v8 uint32_t
  18975 	var _ /* hashers at bp+0 */ VP8LColorCache
  18976 	_, _, _, _, _, _, _, _, _, _, _, _, _ = i, k, key, max_len, pix_count, prev_row_len, retval, rle_len, use_color_cache, v1, v2, v7, v8
  18977 	pix_count = xsize * ysize
  18978 	use_color_cache = libc.BoolInt32(cache_bits > libc.Int32FromInt32(0))
  18979 	if use_color_cache != 0 && !(VP8LColorCacheInit(tls, bp, cache_bits) != 0) {
  18980 		return 0
  18981 	}
  18982 	VP8LClearBackwardRefs(tls, refs)
  18983 	// Add first pixel as literal.
  18984 	AddSingleLiteral(tls, **(**uint32_t)(__ccgo_up(argb2)), use_color_cache, bp, refs)
  18985 	i = int32(1)
  18986 	for i < pix_count {
  18987 		max_len = MaxFindCopyLength(tls, pix_count-i)
  18988 		rle_len = FindMatchLength(tls, argb2+uintptr(i)*4, argb2+uintptr(i)*4-uintptr(1)*4, 0, max_len)
  18989 		if i < xsize {
  18990 			v1 = 0
  18991 		} else {
  18992 			v1 = FindMatchLength(tls, argb2+uintptr(i)*4, argb2+uintptr(i)*4-uintptr(xsize)*4, 0, max_len)
  18993 		}
  18994 		prev_row_len = v1
  18995 		if rle_len >= prev_row_len && rle_len >= int32(MIN_LENGTH) {
  18996 			retval.Fmode = uint8(kCopy)
  18997 			retval.Fargb_or_distance = uint32(1)
  18998 			retval.Flen1 = uint16(rle_len)
  18999 			v2 = retval
  19000 			goto _3
  19001 		_3:
  19002 			VP8LBackwardRefsCursorAdd(tls, refs, v2)
  19003 			// We don't need to update the color cache here since it is always the
  19004 			// same pixel being copied, and that does not change the color cache
  19005 			// state.
  19006 			i = i + rle_len
  19007 		} else {
  19008 			if prev_row_len >= int32(MIN_LENGTH) {
  19009 				retval.Fmode = uint8(kCopy)
  19010 				retval.Fargb_or_distance = uint32(xsize)
  19011 				retval.Flen1 = uint16(prev_row_len)
  19012 				v2 = retval
  19013 				goto _5
  19014 			_5:
  19015 				VP8LBackwardRefsCursorAdd(tls, refs, v2)
  19016 				if use_color_cache != 0 {
  19017 					k = 0
  19018 					for {
  19019 						if !(k < prev_row_len) {
  19020 							break
  19021 						}
  19022 						v7 = bp
  19023 						v8 = **(**uint32_t)(__ccgo_up(argb2 + uintptr(i+k)*4))
  19024 						v1 = int32(v8 * kHashMul11 >> (*VP8LColorCache)(unsafe.Pointer(v7)).Fhash_shift)
  19025 						goto _10
  19026 					_10:
  19027 						key = v1
  19028 						**(**uint32_t)(__ccgo_up((*VP8LColorCache)(unsafe.Pointer(v7)).Fcolors + uintptr(key)*4)) = v8
  19029 						goto _6
  19030 					_6:
  19031 						;
  19032 						k = k + 1
  19033 					}
  19034 				}
  19035 				i = i + prev_row_len
  19036 			} else {
  19037 				AddSingleLiteral(tls, **(**uint32_t)(__ccgo_up(argb2 + uintptr(i)*4)), use_color_cache, bp, refs)
  19038 				i = i + 1
  19039 			}
  19040 		}
  19041 	}
  19042 	if use_color_cache != 0 {
  19043 		VP8LColorCacheClear(tls, bp)
  19044 	}
  19045 	return libc.BoolInt32(!((*VP8LBackwardRefs)(unsafe.Pointer(refs)).Ferror1 != 0))
  19046 }
  19047 
  19048 func BackwardReferencesLz77(tls *libc.TLS, xsize int32, ysize int32, argb2 uintptr, cache_bits int32, hash_chain uintptr, refs uintptr) (r int32) {
  19049 	bp := tls.Alloc(32)
  19050 	defer tls.Free(32)
  19051 	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
  19052 	var retval, v14 PixOrCopy
  19053 	var v2 uintptr
  19054 	var v18 uint32_t
  19055 	var _ /* hashers at bp+0 */ VP8LColorCache
  19056 	var _ /* len at bp+20 */ int32
  19057 	var _ /* offset at bp+16 */ int32
  19058 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  19059 	i_last_check = -int32(1)
  19060 	ok = 0
  19061 	cc_init = 0
  19062 	use_color_cache = libc.BoolInt32(cache_bits > libc.Int32FromInt32(0))
  19063 	pix_count = xsize * ysize
  19064 	if use_color_cache != 0 {
  19065 		cc_init = VP8LColorCacheInit(tls, bp, cache_bits)
  19066 		if !(cc_init != 0) {
  19067 			goto Error
  19068 		}
  19069 	}
  19070 	VP8LClearBackwardRefs(tls, refs)
  19071 	i = 0
  19072 	for {
  19073 		if !(i < pix_count) {
  19074 			break
  19075 		}
  19076 		// Alternative#1: Code the pixels starting at 'i' using backward reference.
  19077 		**(**int32)(__ccgo_up(bp + 16)) = 0
  19078 		**(**int32)(__ccgo_up(bp + 20)) = 0
  19079 		v2 = hash_chain
  19080 		v3 = i
  19081 		v4 = int32(**(**uint32_t)(__ccgo_up((*VP8LHashChain)(unsafe.Pointer(v2)).Foffset_length + uintptr(v3)*4)) >> int32(MAX_LENGTH_BITS))
  19082 		goto _5
  19083 	_5:
  19084 		**(**int32)(__ccgo_up(bp + 16)) = v4
  19085 		v6 = int32(**(**uint32_t)(__ccgo_up((*VP8LHashChain)(unsafe.Pointer(v2)).Foffset_length + uintptr(v3)*4)) & (libc.Uint32FromUint32(1)<<libc.Int32FromInt32(MAX_LENGTH_BITS) - libc.Uint32FromInt32(1)))
  19086 		goto _7
  19087 	_7:
  19088 		**(**int32)(__ccgo_up(bp + 20)) = v6
  19089 		if **(**int32)(__ccgo_up(bp + 20)) >= int32(MIN_LENGTH) {
  19090 			len_ini = **(**int32)(__ccgo_up(bp + 20))
  19091 			max_reach = 0
  19092 			if i+len_ini >= pix_count {
  19093 				v3 = pix_count - int32(1)
  19094 			} else {
  19095 				v3 = i + len_ini
  19096 			}
  19097 			j_max = v3
  19098 			// Only start from what we have not checked already.
  19099 			if i > i_last_check {
  19100 				v4 = i
  19101 			} else {
  19102 				v4 = i_last_check
  19103 			}
  19104 			i_last_check = v4
  19105 			// We know the best match for the current pixel but we try to find the
  19106 			// best matches for the current pixel AND the next one combined.
  19107 			// The naive method would use the intervals:
  19108 			// [i,i+len) + [i+len, length of best match at i+len)
  19109 			// while we check if we can use:
  19110 			// [i,j) (where j<=i+len) + [j, length of best match at j)
  19111 			j = i_last_check + int32(1)
  19112 			for {
  19113 				if !(j <= j_max) {
  19114 					break
  19115 				}
  19116 				v3 = int32(**(**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)))
  19117 				goto _12
  19118 			_12:
  19119 				len_j = v3
  19120 				if len_j >= int32(MIN_LENGTH) {
  19121 					v4 = len_j
  19122 				} else {
  19123 					v4 = int32(1)
  19124 				}
  19125 				reach = j + v4 // 1 for single literal.
  19126 				if reach > max_reach {
  19127 					**(**int32)(__ccgo_up(bp + 20)) = j - i
  19128 					max_reach = reach
  19129 					if max_reach >= pix_count {
  19130 						break
  19131 					}
  19132 				}
  19133 				goto _10
  19134 			_10:
  19135 				;
  19136 				j = j + 1
  19137 			}
  19138 		} else {
  19139 			**(**int32)(__ccgo_up(bp + 20)) = int32(1)
  19140 		}
  19141 		// Go with literal or backward reference.
  19142 		if **(**int32)(__ccgo_up(bp + 20)) == int32(1) {
  19143 			AddSingleLiteral(tls, **(**uint32_t)(__ccgo_up(argb2 + uintptr(i)*4)), use_color_cache, bp, refs)
  19144 		} else {
  19145 			retval.Fmode = uint8(kCopy)
  19146 			retval.Fargb_or_distance = uint32(**(**int32)(__ccgo_up(bp + 16)))
  19147 			retval.Flen1 = uint16(**(**int32)(__ccgo_up(bp + 20)))
  19148 			v14 = retval
  19149 			goto _15
  19150 		_15:
  19151 			VP8LBackwardRefsCursorAdd(tls, refs, v14)
  19152 			if use_color_cache != 0 {
  19153 				j = i
  19154 				for {
  19155 					if !(j < i+**(**int32)(__ccgo_up(bp + 20))) {
  19156 						break
  19157 					}
  19158 					v2 = bp
  19159 					v18 = **(**uint32_t)(__ccgo_up(argb2 + uintptr(j)*4))
  19160 					v3 = int32(v18 * kHashMul11 >> (*VP8LColorCache)(unsafe.Pointer(v2)).Fhash_shift)
  19161 					goto _20
  19162 				_20:
  19163 					key = v3
  19164 					**(**uint32_t)(__ccgo_up((*VP8LColorCache)(unsafe.Pointer(v2)).Fcolors + uintptr(key)*4)) = v18
  19165 					goto _16
  19166 				_16:
  19167 					;
  19168 					j = j + 1
  19169 				}
  19170 			}
  19171 		}
  19172 		i = i + **(**int32)(__ccgo_up(bp + 20))
  19173 		goto _1
  19174 	_1:
  19175 	}
  19176 	ok = libc.BoolInt32(!((*VP8LBackwardRefs)(unsafe.Pointer(refs)).Ferror1 != 0))
  19177 	goto Error
  19178 Error:
  19179 	;
  19180 	if cc_init != 0 {
  19181 		VP8LColorCacheClear(tls, bp)
  19182 	}
  19183 	return ok
  19184 }
  19185 
  19186 // C documentation
  19187 //
  19188 //	// Compute an LZ77 by forcing matches to happen within a given distance cost.
  19189 //	// We therefore limit the algorithm to the lowest 32 values in the PlaneCode
  19190 //	// definition.
  19191 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) {
  19192 	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
  19193 	var counts, counts_ini uintptr
  19194 	var window_offsets, window_offsets_new [32]int32
  19195 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  19196 	pix_count = xsize * ysize
  19197 	window_offsets = [32]int32{}
  19198 	window_offsets_new = [32]int32{}
  19199 	window_offsets_size = 0
  19200 	window_offsets_new_size = 0
  19201 	counts_ini = WebPSafeMalloc(tls, uint64(xsize*ysize), uint64(2))
  19202 	best_offset_prev = -int32(1)
  19203 	best_length_prev = -int32(1)
  19204 	if counts_ini == libc.UintptrFromInt32(0) {
  19205 		return 0
  19206 	}
  19207 	// counts[i] counts how many times a pixel is repeated starting at position i.
  19208 	i = pix_count - int32(2)
  19209 	counts = counts_ini + uintptr(i)*2
  19210 	**(**uint16_t)(__ccgo_up(counts + 1*2)) = uint16(1)
  19211 	for {
  19212 		if !(i >= 0) {
  19213 			break
  19214 		}
  19215 		if **(**uint32_t)(__ccgo_up(argb + uintptr(i)*4)) == **(**uint32_t)(__ccgo_up(argb + uintptr(i+int32(1))*4)) {
  19216 			// Max out the counts to MAX_LENGTH.
  19217 			**(**uint16_t)(__ccgo_up(counts)) = uint16(int32(**(**uint16_t)(__ccgo_up(counts + 1*2))) + libc.BoolInt32(int32(**(**uint16_t)(__ccgo_up(counts + 1*2))) != libc.Int32FromInt32(1)<<libc.Int32FromInt32(MAX_LENGTH_BITS)-libc.Int32FromInt32(1)))
  19218 		} else {
  19219 			**(**uint16_t)(__ccgo_up(counts)) = uint16(1)
  19220 		}
  19221 		goto _1
  19222 	_1:
  19223 		;
  19224 		i = i - 1
  19225 		counts -= 2
  19226 	}
  19227 	// Figure out the window offsets around a pixel. They are stored in a
  19228 	// spiraling order around the pixel as defined by VP8LDistanceToPlaneCode.
  19229 	y = 0
  19230 	for {
  19231 		if !(y <= int32(6)) {
  19232 			break
  19233 		}
  19234 		x = -int32(6)
  19235 		for {
  19236 			if !(x <= int32(6)) {
  19237 				break
  19238 			}
  19239 			offset = y*xsize + x
  19240 			// Ignore offsets that bring us after the pixel.
  19241 			if offset <= 0 {
  19242 				goto _3
  19243 			}
  19244 			plane_code = VP8LDistanceToPlaneCode(tls, xsize, offset) - int32(1)
  19245 			if plane_code >= int32(WINDOW_OFFSETS_SIZE_MAX) {
  19246 				goto _3
  19247 			}
  19248 			window_offsets[plane_code] = offset
  19249 			goto _3
  19250 		_3:
  19251 			;
  19252 			x = x + 1
  19253 		}
  19254 		goto _2
  19255 	_2:
  19256 		;
  19257 		y = y + 1
  19258 	}
  19259 	// For narrow images, not all plane codes are reached, so remove those.
  19260 	i = 0
  19261 	for {
  19262 		if !(i < int32(WINDOW_OFFSETS_SIZE_MAX)) {
  19263 			break
  19264 		}
  19265 		if window_offsets[i] == 0 {
  19266 			goto _4
  19267 		}
  19268 		v5 = window_offsets_size
  19269 		window_offsets_size = window_offsets_size + 1
  19270 		window_offsets[v5] = window_offsets[i]
  19271 		goto _4
  19272 	_4:
  19273 		;
  19274 		i = i + 1
  19275 	}
  19276 	// Given a pixel P, find the offsets that reach pixels unreachable from P-1
  19277 	// with any of the offsets in window_offsets[].
  19278 	i = 0
  19279 	for {
  19280 		if !(i < window_offsets_size) {
  19281 			break
  19282 		}
  19283 		is_reachable = 0
  19284 		j = 0
  19285 		for {
  19286 			if !(j < window_offsets_size && !(is_reachable != 0)) {
  19287 				break
  19288 			}
  19289 			is_reachable = is_reachable | libc.BoolInt32(window_offsets[i] == window_offsets[j]+int32(1))
  19290 			goto _7
  19291 		_7:
  19292 			;
  19293 			j = j + 1
  19294 		}
  19295 		if !(is_reachable != 0) {
  19296 			window_offsets_new[window_offsets_new_size] = window_offsets[i]
  19297 			window_offsets_new_size = window_offsets_new_size + 1
  19298 		}
  19299 		goto _6
  19300 	_6:
  19301 		;
  19302 		i = i + 1
  19303 	}
  19304 	**(**uint32_t)(__ccgo_up((*VP8LHashChain)(unsafe.Pointer(hash_chain)).Foffset_length)) = uint32(0)
  19305 	i = int32(1)
  19306 	for {
  19307 		if !(i < pix_count) {
  19308 			break
  19309 		}
  19310 		v5 = int32(**(**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)))
  19311 		goto _10
  19312 	_10:
  19313 		best_length = v5
  19314 		do_compute = int32(1)
  19315 		if best_length >= libc.Int32FromInt32(1)<<libc.Int32FromInt32(MAX_LENGTH_BITS)-libc.Int32FromInt32(1) {
  19316 			// Do not recompute the best match if we already have a maximal one in the
  19317 			// window.
  19318 			v9 = int32(**(**uint32_t)(__ccgo_up((*VP8LHashChain)(unsafe.Pointer(hash_chain_best)).Foffset_length + uintptr(i)*4)) >> int32(MAX_LENGTH_BITS))
  19319 			goto _12
  19320 		_12:
  19321 			best_offset = v9
  19322 			ind = 0
  19323 			for {
  19324 				if !(ind < window_offsets_size) {
  19325 					break
  19326 				}
  19327 				if best_offset == window_offsets[ind] {
  19328 					do_compute = 0
  19329 					break
  19330 				}
  19331 				goto _13
  19332 			_13:
  19333 				;
  19334 				ind = ind + 1
  19335 			}
  19336 		}
  19337 		if do_compute != 0 {
  19338 			// Figure out if we should use the offset/length from the previous pixel
  19339 			// as an initial guess and therefore only inspect the offsets in
  19340 			// window_offsets_new[].
  19341 			use_prev = libc.BoolInt32(best_length_prev > int32(1) && best_length_prev < libc.Int32FromInt32(1)<<libc.Int32FromInt32(MAX_LENGTH_BITS)-libc.Int32FromInt32(1))
  19342 			if use_prev != 0 {
  19343 				v5 = window_offsets_new_size
  19344 			} else {
  19345 				v5 = window_offsets_size
  19346 			}
  19347 			num_ind = v5
  19348 			if use_prev != 0 {
  19349 				v9 = best_length_prev - int32(1)
  19350 			} else {
  19351 				v9 = 0
  19352 			}
  19353 			best_length = v9
  19354 			if use_prev != 0 {
  19355 				v5 = best_offset_prev
  19356 			} else {
  19357 				v5 = 0
  19358 			}
  19359 			best_offset = v5
  19360 			// Find the longest match in a window around the pixel.
  19361 			ind = 0
  19362 			for {
  19363 				if !(ind < num_ind) {
  19364 					break
  19365 				}
  19366 				curr_length = 0
  19367 				j1 = i
  19368 				if use_prev != 0 {
  19369 					v5 = i - window_offsets_new[ind]
  19370 				} else {
  19371 					v5 = i - window_offsets[ind]
  19372 				}
  19373 				j_offset = v5
  19374 				if j_offset < 0 || **(**uint32_t)(__ccgo_up(argb + uintptr(j_offset)*4)) != **(**uint32_t)(__ccgo_up(argb + uintptr(i)*4)) {
  19375 					goto _17
  19376 				}
  19377 				// The longest match is the sum of how many times each pixel is
  19378 				// repeated.
  19379 				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)) {
  19380 					counts_j_offset = int32(**(**uint16_t)(__ccgo_up(counts_ini + uintptr(j_offset)*2)))
  19381 					counts_j = int32(**(**uint16_t)(__ccgo_up(counts_ini + uintptr(j1)*2)))
  19382 					if counts_j_offset != counts_j {
  19383 						if counts_j_offset < counts_j {
  19384 							v5 = counts_j_offset
  19385 						} else {
  19386 							v5 = counts_j
  19387 						}
  19388 						curr_length = curr_length + v5
  19389 						break
  19390 					}
  19391 					// The same color is repeated counts_pos times at j_offset and j.
  19392 					curr_length = curr_length + counts_j_offset
  19393 					j_offset = j_offset + counts_j_offset
  19394 					j1 = j1 + counts_j_offset
  19395 				}
  19396 				if best_length < curr_length {
  19397 					if use_prev != 0 {
  19398 						v5 = window_offsets_new[ind]
  19399 					} else {
  19400 						v5 = window_offsets[ind]
  19401 					}
  19402 					best_offset = v5
  19403 					if curr_length >= libc.Int32FromInt32(1)<<libc.Int32FromInt32(MAX_LENGTH_BITS)-libc.Int32FromInt32(1) {
  19404 						best_length = libc.Int32FromInt32(1)<<libc.Int32FromInt32(MAX_LENGTH_BITS) - libc.Int32FromInt32(1)
  19405 						break
  19406 					} else {
  19407 						best_length = curr_length
  19408 					}
  19409 				}
  19410 				goto _17
  19411 			_17:
  19412 				;
  19413 				ind = ind + 1
  19414 			}
  19415 		}
  19416 		if best_length <= int32(MIN_LENGTH) {
  19417 			**(**uint32_t)(__ccgo_up((*VP8LHashChain)(unsafe.Pointer(hash_chain)).Foffset_length + uintptr(i)*4)) = uint32(0)
  19418 			best_offset_prev = 0
  19419 			best_length_prev = 0
  19420 		} else {
  19421 			**(**uint32_t)(__ccgo_up((*VP8LHashChain)(unsafe.Pointer(hash_chain)).Foffset_length + uintptr(i)*4)) = uint32(best_offset<<libc.Int32FromInt32(MAX_LENGTH_BITS)) | uint32(best_length)
  19422 			best_offset_prev = best_offset
  19423 			best_length_prev = best_length
  19424 		}
  19425 		goto _8
  19426 	_8:
  19427 		;
  19428 		i = i + 1
  19429 	}
  19430 	**(**uint32_t)(__ccgo_up((*VP8LHashChain)(unsafe.Pointer(hash_chain)).Foffset_length)) = uint32(0)
  19431 	WebPSafeFree(tls, counts_ini)
  19432 	return BackwardReferencesLz77(tls, xsize, ysize, argb, cache_bits, hash_chain, refs)
  19433 }
  19434 
  19435 // -----------------------------------------------------------------------------
  19436 
  19437 func BackwardReferences2DLocality(tls *libc.TLS, xsize int32, refs uintptr) {
  19438 	bp := tls.Alloc(32)
  19439 	defer tls.Free(32)
  19440 	var dist, transformed_dist, v1, v3 int32
  19441 	var v5, v6, v7 uintptr
  19442 	var _ /* c at bp+0 */ VP8LRefsCursor
  19443 	_, _, _, _, _, _, _ = dist, transformed_dist, v1, v3, v5, v6, v7
  19444 	**(**VP8LRefsCursor)(__ccgo_up(bp)) = VP8LRefsCursorInit(tls, refs)
  19445 	for {
  19446 		v1 = libc.BoolInt32((*VP8LRefsCursor)(unsafe.Pointer(bp)).Fcur_pos != libc.UintptrFromInt32(0))
  19447 		goto _2
  19448 	_2:
  19449 		if !(v1 != 0) {
  19450 			break
  19451 		}
  19452 		v3 = libc.BoolInt32(int32((*PixOrCopy)(unsafe.Pointer((**(**VP8LRefsCursor)(__ccgo_up(bp))).Fcur_pos)).Fmode) == int32(kCopy))
  19453 		goto _4
  19454 	_4:
  19455 		if v3 != 0 {
  19456 			dist = int32((*PixOrCopy)(unsafe.Pointer((**(**VP8LRefsCursor)(__ccgo_up(bp))).Fcur_pos)).Fargb_or_distance)
  19457 			transformed_dist = VP8LDistanceToPlaneCode(tls, xsize, dist)
  19458 			(*PixOrCopy)(unsafe.Pointer((**(**VP8LRefsCursor)(__ccgo_up(bp))).Fcur_pos)).Fargb_or_distance = uint32(transformed_dist)
  19459 		}
  19460 		v5 = bp
  19461 		v7 = v5
  19462 		*(*uintptr)(unsafe.Pointer(v7)) += 8
  19463 		v6 = *(*uintptr)(unsafe.Pointer(v7))
  19464 		if v6 == (*VP8LRefsCursor)(unsafe.Pointer(v5)).Flast_pos {
  19465 			VP8LRefsCursorNextBlock(tls, v5)
  19466 		}
  19467 	}
  19468 }
  19469 
  19470 // C documentation
  19471 //
  19472 //	// Evaluate optimal cache bits for the local color cache.
  19473 //	// The input *best_cache_bits sets the maximum cache bits to use (passing 0
  19474 //	// implies disabling the local color cache). The local color cache is also
  19475 //	// disabled for the lower (<= 25) quality.
  19476 //	// Returns 0 in case of memory error.
  19477 func CalculateBestCacheSize(tls *libc.TLS, argb2 uintptr, quality int32, refs uintptr, best_cache_bits uintptr) (r1 int32) {
  19478 	bp := tls.Alloc(224)
  19479 	defer tls.Free(224)
  19480 	var a, argb_prev, b, g, pix, r, v11 uint32_t
  19481 	var cache_bits_max, highest_bit, i, key2, key3, len1, ok, second_highest_bit, v1, v3, v5, v8 int32
  19482 	var cc_init [11]int32
  19483 	var entropy, entropy_min uint64_t
  19484 	var histos [11]uintptr
  19485 	var prefix_code VP8LPrefixCode
  19486 	var v, v16, v17, v18, v7 uintptr
  19487 	var _ /* c at bp+176 */ VP8LRefsCursor
  19488 	var _ /* code at bp+200 */ int32
  19489 	var _ /* extra_bits at bp+204 */ int32
  19490 	var _ /* extra_bits_value at bp+208 */ int32
  19491 	var _ /* hashers at bp+0 */ [11]VP8LColorCache
  19492 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  19493 	if quality <= int32(25) {
  19494 		v1 = 0
  19495 	} else {
  19496 		v1 = **(**int32)(__ccgo_up(best_cache_bits))
  19497 	}
  19498 	cache_bits_max = v1
  19499 	entropy_min = ^libc.Uint64FromUint64(0)
  19500 	cc_init = [11]int32{}
  19501 	**(**VP8LRefsCursor)(__ccgo_up(bp + 176)) = VP8LRefsCursorInit(tls, refs)
  19502 	histos = [11]uintptr{}
  19503 	ok = 0
  19504 	if cache_bits_max == 0 {
  19505 		**(**int32)(__ccgo_up(best_cache_bits)) = 0
  19506 		// Local color cache is disabled.
  19507 		return int32(1)
  19508 	}
  19509 	// Allocate data.
  19510 	i = 0
  19511 	for {
  19512 		if !(i <= cache_bits_max) {
  19513 			break
  19514 		}
  19515 		histos[i] = VP8LAllocateHistogram(tls, i)
  19516 		if histos[i] == libc.UintptrFromInt32(0) {
  19517 			goto Error
  19518 		}
  19519 		VP8LHistogramInit(tls, histos[i], i, int32(1))
  19520 		if i == 0 {
  19521 			goto _2
  19522 		}
  19523 		cc_init[i] = VP8LColorCacheInit(tls, bp+uintptr(i)*16, i)
  19524 		if !(cc_init[i] != 0) {
  19525 			goto Error
  19526 		}
  19527 		goto _2
  19528 	_2:
  19529 		;
  19530 		i = i + 1
  19531 	}
  19532 	// Find the cache_bits giving the lowest entropy. The search is done in a
  19533 	// brute-force way as the function (entropy w.r.t cache_bits) can be
  19534 	// anything in practice.
  19535 	for {
  19536 		v1 = libc.BoolInt32((*VP8LRefsCursor)(unsafe.Pointer(bp+176)).Fcur_pos != libc.UintptrFromInt32(0))
  19537 		goto _4
  19538 	_4:
  19539 		if !(v1 != 0) {
  19540 			break
  19541 		}
  19542 		v = (**(**VP8LRefsCursor)(__ccgo_up(bp + 176))).Fcur_pos
  19543 		v3 = libc.BoolInt32(int32((*PixOrCopy)(unsafe.Pointer(v)).Fmode) == int32(kLiteral))
  19544 		goto _6
  19545 	_6:
  19546 		if v3 != 0 {
  19547 			v7 = argb2
  19548 			argb2 += 4
  19549 			pix = **(**uint32_t)(__ccgo_up(v7))
  19550 			a = pix >> libc.Int32FromInt32(24) & uint32(0xff)
  19551 			r = pix >> libc.Int32FromInt32(16) & uint32(0xff)
  19552 			g = pix >> libc.Int32FromInt32(8) & uint32(0xff)
  19553 			b = pix >> libc.Int32FromInt32(0) & uint32(0xff)
  19554 			v5 = int32(pix * kHashMul11 >> (int32(32) - cache_bits_max))
  19555 			goto _9
  19556 		_9:
  19557 			// The keys of the caches can be derived from the longest one.
  19558 			key2 = v5
  19559 			// Do not use the color cache for cache_bits = 0.
  19560 			**(**uint32_t)(__ccgo_up(histos[0] + 1032 + uintptr(b)*4)) = **(**uint32_t)(__ccgo_up(histos[0] + 1032 + uintptr(b)*4)) + 1
  19561 			**(**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
  19562 			**(**uint32_t)(__ccgo_up(histos[0] + 8 + uintptr(r)*4)) = **(**uint32_t)(__ccgo_up(histos[0] + 8 + uintptr(r)*4)) + 1
  19563 			**(**uint32_t)(__ccgo_up(histos[0] + 2056 + uintptr(a)*4)) = **(**uint32_t)(__ccgo_up(histos[0] + 2056 + uintptr(a)*4)) + 1
  19564 			// Deal with cache_bits > 0.
  19565 			i = cache_bits_max
  19566 			for {
  19567 				if !(i >= int32(1)) {
  19568 					break
  19569 				}
  19570 				v11 = **(**uint32_t)(__ccgo_up((*VP8LColorCache)(unsafe.Pointer(bp+uintptr(i)*16)).Fcolors + uintptr(uint32(key2))*4))
  19571 				goto _12
  19572 			_12:
  19573 				if v11 == pix {
  19574 					**(**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
  19575 				} else {
  19576 					**(**uint32_t)(__ccgo_up((*VP8LColorCache)(unsafe.Pointer(bp+uintptr(i)*16)).Fcolors + uintptr(uint32(key2))*4)) = pix
  19577 					**(**uint32_t)(__ccgo_up(histos[i] + 1032 + uintptr(b)*4)) = **(**uint32_t)(__ccgo_up(histos[i] + 1032 + uintptr(b)*4)) + 1
  19578 					**(**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
  19579 					**(**uint32_t)(__ccgo_up(histos[i] + 8 + uintptr(r)*4)) = **(**uint32_t)(__ccgo_up(histos[i] + 8 + uintptr(r)*4)) + 1
  19580 					**(**uint32_t)(__ccgo_up(histos[i] + 2056 + uintptr(a)*4)) = **(**uint32_t)(__ccgo_up(histos[i] + 2056 + uintptr(a)*4)) + 1
  19581 				}
  19582 				goto _10
  19583 			_10:
  19584 				;
  19585 				i = i - 1
  19586 				key2 = key2 >> int32(1)
  19587 			}
  19588 		} else {
  19589 			v11 = uint32((*PixOrCopy)(unsafe.Pointer(v)).Flen1)
  19590 			goto _14
  19591 		_14:
  19592 			// We should compute the contribution of the (distance,length)
  19593 			// histograms but those are the same independently from the cache size.
  19594 			// As those constant contributions are in the end added to the other
  19595 			// histogram contributions, we can ignore them, except for the length
  19596 			// prefix that is part of the 'literal' histogram.
  19597 			len1 = int32(v11)
  19598 			argb_prev = **(**uint32_t)(__ccgo_up(argb2)) ^ uint32(0xffffffff)
  19599 			v1 = len1
  19600 			v7 = bp + 200
  19601 			v16 = bp + 204
  19602 			v17 = bp + 208
  19603 			if v1 < libc.Int32FromInt32(PREFIX_LOOKUP_IDX_MAX) {
  19604 				prefix_code = kPrefixEncodeCode[v1]
  19605 				**(**int32)(__ccgo_up(v7)) = int32(prefix_code.Fcode)
  19606 				**(**int32)(__ccgo_up(v16)) = int32(prefix_code.Fextra_bits)
  19607 				**(**int32)(__ccgo_up(v17)) = int32(kPrefixEncodeExtraBitsValue[v1])
  19608 			} else {
  19609 				v3 = v1
  19610 				v18 = v16
  19611 				v3 = v3 - 1
  19612 				v5 = v3
  19613 				v8 = int32(31) ^ libc.X__builtin_clz(tls, uint32(v5))
  19614 				goto _23
  19615 			_23:
  19616 				highest_bit = v8
  19617 				second_highest_bit = v3 >> (highest_bit - int32(1)) & int32(1)
  19618 				**(**int32)(__ccgo_up(v18)) = highest_bit - int32(1)
  19619 				**(**int32)(__ccgo_up(v17)) = v3 & (int32(1)<<**(**int32)(__ccgo_up(v18)) - int32(1))
  19620 				**(**int32)(__ccgo_up(v7)) = int32(2)*highest_bit + second_highest_bit
  19621 			}
  19622 			i = 0
  19623 			for {
  19624 				if !(i <= cache_bits_max) {
  19625 					break
  19626 				}
  19627 				**(**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
  19628 				goto _24
  19629 			_24:
  19630 				;
  19631 				i = i + 1
  19632 			}
  19633 			// Update the color caches.
  19634 			for {
  19635 				if **(**uint32_t)(__ccgo_up(argb2)) != argb_prev {
  19636 					v3 = int32(**(**uint32_t)(__ccgo_up(argb2)) * kHashMul11 >> (int32(32) - cache_bits_max))
  19637 					goto _28
  19638 				_28:
  19639 					// Efficiency: insert only if the color changes.
  19640 					key3 = v3
  19641 					i = cache_bits_max
  19642 					for {
  19643 						if !(i >= int32(1)) {
  19644 							break
  19645 						}
  19646 						**(**uint32_t)(__ccgo_up((**(**[11]VP8LColorCache)(__ccgo_up(bp)))[i].Fcolors + uintptr(key3)*4)) = **(**uint32_t)(__ccgo_up(argb2))
  19647 						goto _29
  19648 					_29:
  19649 						;
  19650 						i = i - 1
  19651 						key3 = key3 >> int32(1)
  19652 					}
  19653 					argb_prev = **(**uint32_t)(__ccgo_up(argb2))
  19654 				}
  19655 				argb2 += 4
  19656 				goto _26
  19657 			_26:
  19658 				;
  19659 				len1 = len1 - 1
  19660 				v1 = len1
  19661 				if !(v1 != 0) {
  19662 					break
  19663 				}
  19664 			}
  19665 		}
  19666 		v7 = bp + 176
  19667 		v17 = v7
  19668 		*(*uintptr)(unsafe.Pointer(v17)) += 8
  19669 		v16 = *(*uintptr)(unsafe.Pointer(v17))
  19670 		if v16 == (*VP8LRefsCursor)(unsafe.Pointer(v7)).Flast_pos {
  19671 			VP8LRefsCursorNextBlock(tls, v7)
  19672 		}
  19673 	}
  19674 	i = 0
  19675 	for {
  19676 		if !(i <= cache_bits_max) {
  19677 			break
  19678 		}
  19679 		entropy = VP8LHistogramEstimateBits(tls, histos[i])
  19680 		if i == 0 || entropy < entropy_min {
  19681 			entropy_min = entropy
  19682 			**(**int32)(__ccgo_up(best_cache_bits)) = i
  19683 		}
  19684 		goto _33
  19685 	_33:
  19686 		;
  19687 		i = i + 1
  19688 	}
  19689 	ok = int32(1)
  19690 	goto Error
  19691 Error:
  19692 	;
  19693 	i = 0
  19694 	for {
  19695 		if !(i <= cache_bits_max) {
  19696 			break
  19697 		}
  19698 		if cc_init[i] != 0 {
  19699 			VP8LColorCacheClear(tls, bp+uintptr(i)*16)
  19700 		}
  19701 		VP8LFreeHistogram(tls, histos[i])
  19702 		goto _34
  19703 	_34:
  19704 		;
  19705 		i = i + 1
  19706 	}
  19707 	return ok
  19708 }
  19709 
  19710 // C documentation
  19711 //
  19712 //	// Update (in-place) backward references for specified cache_bits.
  19713 func BackwardRefsWithLocalCache(tls *libc.TLS, argb3 uintptr, cache_bits int32, refs uintptr) (r int32) {
  19714 	bp := tls.Alloc(48)
  19715 	defer tls.Free(48)
  19716 	var argb_literal, v6 uint32_t
  19717 	var ix, k, key, key1, pixel_index, v1, v11, v3, v7, v9 int32
  19718 	var retval, v12 PixOrCopy
  19719 	var v, v14, v20, v5 uintptr
  19720 	var _ /* c at bp+16 */ VP8LRefsCursor
  19721 	var _ /* hashers at bp+0 */ VP8LColorCache
  19722 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = argb_literal, ix, k, key, key1, pixel_index, retval, v, v1, v11, v12, v14, v20, v3, v5, v6, v7, v9
  19723 	pixel_index = 0
  19724 	**(**VP8LRefsCursor)(__ccgo_up(bp + 16)) = VP8LRefsCursorInit(tls, refs)
  19725 	if !(VP8LColorCacheInit(tls, bp, cache_bits) != 0) {
  19726 		return 0
  19727 	}
  19728 	for {
  19729 		v1 = libc.BoolInt32((*VP8LRefsCursor)(unsafe.Pointer(bp+16)).Fcur_pos != libc.UintptrFromInt32(0))
  19730 		goto _2
  19731 	_2:
  19732 		if !(v1 != 0) {
  19733 			break
  19734 		}
  19735 		v = (**(**VP8LRefsCursor)(__ccgo_up(bp + 16))).Fcur_pos
  19736 		v3 = libc.BoolInt32(int32((*PixOrCopy)(unsafe.Pointer(v)).Fmode) == int32(kLiteral))
  19737 		goto _4
  19738 	_4:
  19739 		if v3 != 0 {
  19740 			argb_literal = (*PixOrCopy)(unsafe.Pointer(v)).Fargb_or_distance
  19741 			v5 = bp
  19742 			v6 = argb_literal
  19743 			v7 = int32(v6 * kHashMul11 >> (*VP8LColorCache)(unsafe.Pointer(v5)).Fhash_shift)
  19744 			goto _8
  19745 		_8:
  19746 			key1 = v7
  19747 			if **(**uint32_t)(__ccgo_up((*VP8LColorCache)(unsafe.Pointer(v5)).Fcolors + uintptr(key1)*4)) == v6 {
  19748 				v11 = key1
  19749 			} else {
  19750 				v11 = -int32(1)
  19751 			}
  19752 			v9 = v11
  19753 			goto _10
  19754 		_10:
  19755 			ix = v9
  19756 			if ix >= 0 {
  19757 				// hashers contains argb_literal
  19758 				retval.Fmode = uint8(kCacheIdx)
  19759 				retval.Fargb_or_distance = uint32(ix)
  19760 				retval.Flen1 = uint16(1)
  19761 				v12 = retval
  19762 				goto _13
  19763 			_13:
  19764 				**(**PixOrCopy)(__ccgo_up(v)) = v12
  19765 			} else {
  19766 				v5 = bp
  19767 				v6 = argb_literal
  19768 				v1 = int32(v6 * kHashMul11 >> (*VP8LColorCache)(unsafe.Pointer(v5)).Fhash_shift)
  19769 				goto _17
  19770 			_17:
  19771 				key = v1
  19772 				**(**uint32_t)(__ccgo_up((*VP8LColorCache)(unsafe.Pointer(v5)).Fcolors + uintptr(key)*4)) = v6
  19773 			}
  19774 			pixel_index = pixel_index + 1
  19775 		} else {
  19776 			k = 0
  19777 			for {
  19778 				if !(k < int32((*PixOrCopy)(unsafe.Pointer(v)).Flen1)) {
  19779 					break
  19780 				}
  19781 				v1 = pixel_index
  19782 				pixel_index = pixel_index + 1
  19783 				v5 = bp
  19784 				v6 = **(**uint32_t)(__ccgo_up(argb3 + uintptr(v1)*4))
  19785 				v3 = int32(v6 * kHashMul11 >> (*VP8LColorCache)(unsafe.Pointer(v5)).Fhash_shift)
  19786 				goto _23
  19787 			_23:
  19788 				key = v3
  19789 				**(**uint32_t)(__ccgo_up((*VP8LColorCache)(unsafe.Pointer(v5)).Fcolors + uintptr(key)*4)) = v6
  19790 				goto _18
  19791 			_18:
  19792 				;
  19793 				k = k + 1
  19794 			}
  19795 		}
  19796 		v5 = bp + 16
  19797 		v20 = v5
  19798 		*(*uintptr)(unsafe.Pointer(v20)) += 8
  19799 		v14 = *(*uintptr)(unsafe.Pointer(v20))
  19800 		if v14 == (*VP8LRefsCursor)(unsafe.Pointer(v5)).Flast_pos {
  19801 			VP8LRefsCursorNextBlock(tls, v5)
  19802 		}
  19803 	}
  19804 	VP8LColorCacheClear(tls, bp)
  19805 	return int32(1)
  19806 }
  19807 
  19808 func GetBackwardReferencesLowEffort(tls *libc.TLS, width int32, height int32, argb uintptr, cache_bits uintptr, hash_chain uintptr, refs_lz77 uintptr) (r uintptr) {
  19809 	**(**int32)(__ccgo_up(cache_bits)) = 0
  19810 	if !(BackwardReferencesLz77(tls, width, height, argb, 0, hash_chain, refs_lz77) != 0) {
  19811 		return libc.UintptrFromInt32(0)
  19812 	}
  19813 	BackwardReferences2DLocality(tls, width, refs_lz77)
  19814 	return refs_lz77
  19815 }
  19816 
  19817 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) {
  19818 	bp := tls.Alloc(32)
  19819 	defer tls.Free(32)
  19820 	var bit_cost, bit_cost_trace uint64_t
  19821 	var bit_costs_best [2]uint64_t
  19822 	var cache_bits1, i, lz77_type, res, status, v1 int32
  19823 	var hash_chain_tmp, histo, refs_tmp, v6 uintptr
  19824 	var lz77_types_best [2]int32
  19825 	var _ /* cache_bits at bp+16 */ int32
  19826 	var _ /* hash_chain_box at bp+0 */ VP8LHashChain
  19827 	_, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  19828 	histo = libc.UintptrFromInt32(0)
  19829 	// Index 0 is for a color cache, index 1 for no cache (if needed).
  19830 	lz77_types_best = [2]int32{}
  19831 	bit_costs_best = [2]uint64_t{
  19832 		0: ^libc.Uint64FromUint64(0),
  19833 		1: ^libc.Uint64FromUint64(0),
  19834 	}
  19835 	if do_no_cache != 0 {
  19836 		v1 = int32(2)
  19837 	} else {
  19838 		v1 = int32(1)
  19839 	}
  19840 	refs_tmp = refs + uintptr(v1)*40
  19841 	status = 0
  19842 	libc.Xmemset(tls, bp, 0, uint64(16))
  19843 	histo = VP8LAllocateHistogram(tls, int32(MAX_COLOR_CACHE_BITS))
  19844 	if histo == libc.UintptrFromInt32(0) {
  19845 		goto Error
  19846 	}
  19847 	lz77_type = int32(1)
  19848 	for {
  19849 		if !(lz77_types_to_try != 0) {
  19850 			break
  19851 		}
  19852 		res = 0
  19853 		bit_cost = 0
  19854 		if lz77_types_to_try&lz77_type == 0 {
  19855 			goto _2
  19856 		}
  19857 		switch lz77_type {
  19858 		case int32(kLZ77RLE):
  19859 			res = BackwardReferencesRle(tls, width, height, argb, 0, refs_tmp)
  19860 		case int32(kLZ77Standard):
  19861 			// Compute LZ77 with no cache (0 bits), as the ideal LZ77 with a color
  19862 			// cache is not that different in practice.
  19863 			res = BackwardReferencesLz77(tls, width, height, argb, 0, hash_chain, refs_tmp)
  19864 		case int32(kLZ77Box):
  19865 			if !(VP8LHashChainInit(tls, bp, width*height) != 0) {
  19866 				goto Error
  19867 			}
  19868 			res = BackwardReferencesLz77Box(tls, width, height, argb, 0, hash_chain, bp, refs_tmp)
  19869 		default:
  19870 		}
  19871 		if !(res != 0) {
  19872 			goto Error
  19873 		}
  19874 		// Start with the no color cache case.
  19875 		i = int32(1)
  19876 		for {
  19877 			if !(i >= 0) {
  19878 				break
  19879 			}
  19880 			if i == int32(1) {
  19881 				v1 = 0
  19882 			} else {
  19883 				v1 = cache_bits_max
  19884 			}
  19885 			**(**int32)(__ccgo_up(bp + 16)) = v1
  19886 			if i == int32(1) && !(do_no_cache != 0) {
  19887 				goto _3
  19888 			}
  19889 			if i == 0 {
  19890 				// Try with a color cache.
  19891 				if !(CalculateBestCacheSize(tls, argb, quality, refs_tmp, bp+16) != 0) {
  19892 					goto Error
  19893 				}
  19894 				if **(**int32)(__ccgo_up(bp + 16)) > 0 {
  19895 					if !(BackwardRefsWithLocalCache(tls, argb, **(**int32)(__ccgo_up(bp + 16)), refs_tmp) != 0) {
  19896 						goto Error
  19897 					}
  19898 				}
  19899 			}
  19900 			if i == 0 && do_no_cache != 0 && **(**int32)(__ccgo_up(bp + 16)) == 0 {
  19901 				// No need to re-compute bit_cost as it was computed at i == 1.
  19902 			} else {
  19903 				VP8LHistogramCreate(tls, histo, refs_tmp, **(**int32)(__ccgo_up(bp + 16)))
  19904 				bit_cost = VP8LHistogramEstimateBits(tls, histo)
  19905 			}
  19906 			if bit_cost < bit_costs_best[i] {
  19907 				if i == int32(1) {
  19908 					// Do not swap as the full cache analysis would have the wrong
  19909 					// VP8LBackwardRefs to start with.
  19910 					if !(BackwardRefsClone(tls, refs_tmp, refs+1*40) != 0) {
  19911 						goto Error
  19912 					}
  19913 				} else {
  19914 					BackwardRefsSwap(tls, refs_tmp, refs)
  19915 				}
  19916 				bit_costs_best[i] = bit_cost
  19917 				lz77_types_best[i] = lz77_type
  19918 				if i == 0 {
  19919 					**(**int32)(__ccgo_up(cache_bits_best)) = **(**int32)(__ccgo_up(bp + 16))
  19920 				}
  19921 			}
  19922 			goto _3
  19923 		_3:
  19924 			;
  19925 			i = i - 1
  19926 		}
  19927 		goto _2
  19928 	_2:
  19929 		;
  19930 		lz77_types_to_try = lz77_types_to_try & ^lz77_type
  19931 		lz77_type = lz77_type << int32(1)
  19932 	}
  19933 	// Improve on simple LZ77 but only for high quality (TraceBackwards is
  19934 	// costly).
  19935 	i = int32(1)
  19936 	for {
  19937 		if !(i >= 0) {
  19938 			break
  19939 		}
  19940 		if i == int32(1) && !(do_no_cache != 0) {
  19941 			goto _5
  19942 		}
  19943 		if (lz77_types_best[i] == int32(kLZ77Standard) || lz77_types_best[i] == int32(kLZ77Box)) && quality >= int32(25) {
  19944 			if lz77_types_best[i] == int32(kLZ77Standard) {
  19945 				v6 = hash_chain
  19946 			} else {
  19947 				v6 = bp
  19948 			}
  19949 			hash_chain_tmp = v6
  19950 			if i == int32(1) {
  19951 				v1 = 0
  19952 			} else {
  19953 				v1 = **(**int32)(__ccgo_up(cache_bits_best))
  19954 			}
  19955 			cache_bits1 = v1
  19956 			if !(VP8LBackwardReferencesTraceBackwards(tls, width, height, argb, cache_bits1, hash_chain_tmp, refs+uintptr(i)*40, refs_tmp) != 0) {
  19957 				goto Error
  19958 			}
  19959 			VP8LHistogramCreate(tls, histo, refs_tmp, cache_bits1)
  19960 			bit_cost_trace = VP8LHistogramEstimateBits(tls, histo)
  19961 			if bit_cost_trace < bit_costs_best[i] {
  19962 				BackwardRefsSwap(tls, refs_tmp, refs+uintptr(i)*40)
  19963 			}
  19964 		}
  19965 		BackwardReferences2DLocality(tls, width, refs+uintptr(i)*40)
  19966 		if i == int32(1) && lz77_types_best[0] == lz77_types_best[int32(1)] && **(**int32)(__ccgo_up(cache_bits_best)) == 0 {
  19967 			// If the best cache size is 0 and we have the same best LZ77, just copy
  19968 			// the data over and stop here.
  19969 			if !(BackwardRefsClone(tls, refs+1*40, refs) != 0) {
  19970 				goto Error
  19971 			}
  19972 			break
  19973 		}
  19974 		goto _5
  19975 	_5:
  19976 		;
  19977 		i = i - 1
  19978 	}
  19979 	status = int32(1)
  19980 	goto Error
  19981 Error:
  19982 	;
  19983 	VP8LHashChainClear(tls, bp)
  19984 	VP8LFreeHistogram(tls, histo)
  19985 	return status
  19986 }
  19987 
  19988 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) {
  19989 	var refs_best uintptr
  19990 	_ = refs_best
  19991 	if low_effort != 0 {
  19992 		**(**int32)(__ccgo_up(cache_bits_best)) = cache_bits_max
  19993 		refs_best = GetBackwardReferencesLowEffort(tls, width, height, argb, cache_bits_best, hash_chain, refs)
  19994 		if refs_best == libc.UintptrFromInt32(0) {
  19995 			return WebPEncodingSetError(tls, pic, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  19996 		}
  19997 		// Set it in first position.
  19998 		BackwardRefsSwap(tls, refs_best, refs)
  19999 	} else {
  20000 		if !(GetBackwardReferences(tls, width, height, argb, quality, lz77_types_to_try, cache_bits_max, do_no_cache, hash_chain, refs, cache_bits_best) != 0) {
  20001 			return WebPEncodingSetError(tls, pic, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  20002 		}
  20003 	}
  20004 	return WebPReportProgress(tls, pic, **(**int32)(__ccgo_up(percent))+percent_range, percent)
  20005 }
  20006 
  20007 const MAX_LEVEL1 = 9
  20008 const SIZE_MAX5 = "UINT64_MAX"
  20009 
  20010 //------------------------------------------------------------------------------
  20011 
  20012 // Copyright 2010 Google Inc. All Rights Reserved.
  20013 //
  20014 // Use of this source code is governed by a BSD-style license
  20015 // that can be found in the COPYING file in the root of the source
  20016 // tree. An additional intellectual property rights grant can be found
  20017 // in the file PATENTS. All contributing project authors may
  20018 // be found in the AUTHORS file in the root of the source tree.
  20019 // -----------------------------------------------------------------------------
  20020 //
  20021 //  Common types + memory wrappers
  20022 //
  20023 // Author: Skal (pascal.massimino@gmail.com)
  20024 
  20025 //------------------------------------------------------------------------------
  20026 // WebPConfig
  20027 //------------------------------------------------------------------------------
  20028 
  20029 func WebPConfigInitInternal(tls *libc.TLS, config uintptr, preset WebPPreset1, quality float32, version int32) (r int32) {
  20030 	if version>>int32(8) != libc.Int32FromInt32(WEBP_ENCODER_ABI_VERSION)>>libc.Int32FromInt32(8) {
  20031 		return 0 // caller/system version mismatch!
  20032 	}
  20033 	if config == libc.UintptrFromInt32(0) {
  20034 		return 0
  20035 	}
  20036 	(*WebPConfig)(unsafe.Pointer(config)).Fquality = quality
  20037 	(*WebPConfig)(unsafe.Pointer(config)).Ftarget_size = 0
  20038 	(*WebPConfig)(unsafe.Pointer(config)).Ftarget_PSNR = float32(0)
  20039 	(*WebPConfig)(unsafe.Pointer(config)).Fmethod = int32(4)
  20040 	(*WebPConfig)(unsafe.Pointer(config)).Fsns_strength = int32(50)
  20041 	(*WebPConfig)(unsafe.Pointer(config)).Ffilter_strength = int32(60) // mid-filtering
  20042 	(*WebPConfig)(unsafe.Pointer(config)).Ffilter_sharpness = 0
  20043 	(*WebPConfig)(unsafe.Pointer(config)).Ffilter_type = int32(1) // default: strong (so U/V is filtered too)
  20044 	(*WebPConfig)(unsafe.Pointer(config)).Fpartitions = 0
  20045 	(*WebPConfig)(unsafe.Pointer(config)).Fsegments = int32(4)
  20046 	(*WebPConfig)(unsafe.Pointer(config)).Fpass = int32(1)
  20047 	(*WebPConfig)(unsafe.Pointer(config)).Fqmin = 0
  20048 	(*WebPConfig)(unsafe.Pointer(config)).Fqmax = int32(100)
  20049 	(*WebPConfig)(unsafe.Pointer(config)).Fshow_compressed = 0
  20050 	(*WebPConfig)(unsafe.Pointer(config)).Fpreprocessing = 0
  20051 	(*WebPConfig)(unsafe.Pointer(config)).Fautofilter = 0
  20052 	(*WebPConfig)(unsafe.Pointer(config)).Fpartition_limit = 0
  20053 	(*WebPConfig)(unsafe.Pointer(config)).Falpha_compression = int32(1)
  20054 	(*WebPConfig)(unsafe.Pointer(config)).Falpha_filtering = int32(1)
  20055 	(*WebPConfig)(unsafe.Pointer(config)).Falpha_quality = int32(100)
  20056 	(*WebPConfig)(unsafe.Pointer(config)).Flossless = 0
  20057 	(*WebPConfig)(unsafe.Pointer(config)).Fexact = 0
  20058 	(*WebPConfig)(unsafe.Pointer(config)).Fimage_hint = int32(WEBP_HINT_DEFAULT)
  20059 	(*WebPConfig)(unsafe.Pointer(config)).Femulate_jpeg_size = 0
  20060 	(*WebPConfig)(unsafe.Pointer(config)).Fthread_level = 0
  20061 	(*WebPConfig)(unsafe.Pointer(config)).Flow_memory = 0
  20062 	(*WebPConfig)(unsafe.Pointer(config)).Fnear_lossless = int32(100)
  20063 	(*WebPConfig)(unsafe.Pointer(config)).Fuse_sharp_yuv = 0
  20064 	// TODO(skal): tune.
  20065 	switch preset {
  20066 	case int32(WEBP_PRESET_PICTURE):
  20067 		(*WebPConfig)(unsafe.Pointer(config)).Fsns_strength = int32(80)
  20068 		(*WebPConfig)(unsafe.Pointer(config)).Ffilter_sharpness = int32(4)
  20069 		(*WebPConfig)(unsafe.Pointer(config)).Ffilter_strength = int32(35)
  20070 		**(**int32)(__ccgo_up(config + 68)) &= ^libc.Int32FromInt32(2) // no dithering
  20071 	case int32(WEBP_PRESET_PHOTO):
  20072 		(*WebPConfig)(unsafe.Pointer(config)).Fsns_strength = int32(80)
  20073 		(*WebPConfig)(unsafe.Pointer(config)).Ffilter_sharpness = int32(3)
  20074 		(*WebPConfig)(unsafe.Pointer(config)).Ffilter_strength = int32(30)
  20075 		**(**int32)(__ccgo_up(config + 68)) |= int32(2)
  20076 	case int32(WEBP_PRESET_DRAWING):
  20077 		(*WebPConfig)(unsafe.Pointer(config)).Fsns_strength = int32(25)
  20078 		(*WebPConfig)(unsafe.Pointer(config)).Ffilter_sharpness = int32(6)
  20079 		(*WebPConfig)(unsafe.Pointer(config)).Ffilter_strength = int32(10)
  20080 	case int32(WEBP_PRESET_ICON):
  20081 		(*WebPConfig)(unsafe.Pointer(config)).Fsns_strength = 0
  20082 		(*WebPConfig)(unsafe.Pointer(config)).Ffilter_strength = 0     // disable filtering to retain sharpness
  20083 		**(**int32)(__ccgo_up(config + 68)) &= ^libc.Int32FromInt32(2) // no dithering
  20084 	case int32(WEBP_PRESET_TEXT):
  20085 		(*WebPConfig)(unsafe.Pointer(config)).Fsns_strength = 0
  20086 		(*WebPConfig)(unsafe.Pointer(config)).Ffilter_strength = 0     // disable filtering to retain sharpness
  20087 		**(**int32)(__ccgo_up(config + 68)) &= ^libc.Int32FromInt32(2) // no dithering
  20088 		(*WebPConfig)(unsafe.Pointer(config)).Fsegments = int32(2)
  20089 	case int32(WEBP_PRESET_DEFAULT):
  20090 		fallthrough
  20091 	default:
  20092 		break
  20093 	}
  20094 	return WebPValidateConfig(tls, config)
  20095 }
  20096 
  20097 func WebPValidateConfig(tls *libc.TLS, config uintptr) (r int32) {
  20098 	if config == libc.UintptrFromInt32(0) {
  20099 		return 0
  20100 	}
  20101 	if (*WebPConfig)(unsafe.Pointer(config)).Fquality < libc.Float32FromInt32(0) || (*WebPConfig)(unsafe.Pointer(config)).Fquality > libc.Float32FromInt32(100) {
  20102 		return 0
  20103 	}
  20104 	if (*WebPConfig)(unsafe.Pointer(config)).Ftarget_size < 0 {
  20105 		return 0
  20106 	}
  20107 	if (*WebPConfig)(unsafe.Pointer(config)).Ftarget_PSNR < libc.Float32FromInt32(0) {
  20108 		return 0
  20109 	}
  20110 	if (*WebPConfig)(unsafe.Pointer(config)).Fmethod < 0 || (*WebPConfig)(unsafe.Pointer(config)).Fmethod > int32(6) {
  20111 		return 0
  20112 	}
  20113 	if (*WebPConfig)(unsafe.Pointer(config)).Fsegments < int32(1) || (*WebPConfig)(unsafe.Pointer(config)).Fsegments > int32(4) {
  20114 		return 0
  20115 	}
  20116 	if (*WebPConfig)(unsafe.Pointer(config)).Fsns_strength < 0 || (*WebPConfig)(unsafe.Pointer(config)).Fsns_strength > int32(100) {
  20117 		return 0
  20118 	}
  20119 	if (*WebPConfig)(unsafe.Pointer(config)).Ffilter_strength < 0 || (*WebPConfig)(unsafe.Pointer(config)).Ffilter_strength > int32(100) {
  20120 		return 0
  20121 	}
  20122 	if (*WebPConfig)(unsafe.Pointer(config)).Ffilter_sharpness < 0 || (*WebPConfig)(unsafe.Pointer(config)).Ffilter_sharpness > int32(7) {
  20123 		return 0
  20124 	}
  20125 	if (*WebPConfig)(unsafe.Pointer(config)).Ffilter_type < 0 || (*WebPConfig)(unsafe.Pointer(config)).Ffilter_type > int32(1) {
  20126 		return 0
  20127 	}
  20128 	if (*WebPConfig)(unsafe.Pointer(config)).Fautofilter < 0 || (*WebPConfig)(unsafe.Pointer(config)).Fautofilter > int32(1) {
  20129 		return 0
  20130 	}
  20131 	if (*WebPConfig)(unsafe.Pointer(config)).Fpass < int32(1) || (*WebPConfig)(unsafe.Pointer(config)).Fpass > int32(10) {
  20132 		return 0
  20133 	}
  20134 	if (*WebPConfig)(unsafe.Pointer(config)).Fqmin < 0 || (*WebPConfig)(unsafe.Pointer(config)).Fqmax > int32(100) || (*WebPConfig)(unsafe.Pointer(config)).Fqmin > (*WebPConfig)(unsafe.Pointer(config)).Fqmax {
  20135 		return 0
  20136 	}
  20137 	if (*WebPConfig)(unsafe.Pointer(config)).Fshow_compressed < 0 || (*WebPConfig)(unsafe.Pointer(config)).Fshow_compressed > int32(1) {
  20138 		return 0
  20139 	}
  20140 	if (*WebPConfig)(unsafe.Pointer(config)).Fpreprocessing < 0 || (*WebPConfig)(unsafe.Pointer(config)).Fpreprocessing > int32(7) {
  20141 		return 0
  20142 	}
  20143 	if (*WebPConfig)(unsafe.Pointer(config)).Fpartitions < 0 || (*WebPConfig)(unsafe.Pointer(config)).Fpartitions > int32(3) {
  20144 		return 0
  20145 	}
  20146 	if (*WebPConfig)(unsafe.Pointer(config)).Fpartition_limit < 0 || (*WebPConfig)(unsafe.Pointer(config)).Fpartition_limit > int32(100) {
  20147 		return 0
  20148 	}
  20149 	if (*WebPConfig)(unsafe.Pointer(config)).Falpha_compression < 0 {
  20150 		return 0
  20151 	}
  20152 	if (*WebPConfig)(unsafe.Pointer(config)).Falpha_filtering < 0 {
  20153 		return 0
  20154 	}
  20155 	if (*WebPConfig)(unsafe.Pointer(config)).Falpha_quality < 0 || (*WebPConfig)(unsafe.Pointer(config)).Falpha_quality > int32(100) {
  20156 		return 0
  20157 	}
  20158 	if (*WebPConfig)(unsafe.Pointer(config)).Flossless < 0 || (*WebPConfig)(unsafe.Pointer(config)).Flossless > int32(1) {
  20159 		return 0
  20160 	}
  20161 	if (*WebPConfig)(unsafe.Pointer(config)).Fnear_lossless < 0 || (*WebPConfig)(unsafe.Pointer(config)).Fnear_lossless > int32(100) {
  20162 		return 0
  20163 	}
  20164 	if (*WebPConfig)(unsafe.Pointer(config)).Fimage_hint >= int32(WEBP_HINT_LAST) {
  20165 		return 0
  20166 	}
  20167 	if (*WebPConfig)(unsafe.Pointer(config)).Femulate_jpeg_size < 0 || (*WebPConfig)(unsafe.Pointer(config)).Femulate_jpeg_size > int32(1) {
  20168 		return 0
  20169 	}
  20170 	if (*WebPConfig)(unsafe.Pointer(config)).Fthread_level < 0 || (*WebPConfig)(unsafe.Pointer(config)).Fthread_level > int32(1) {
  20171 		return 0
  20172 	}
  20173 	if (*WebPConfig)(unsafe.Pointer(config)).Flow_memory < 0 || (*WebPConfig)(unsafe.Pointer(config)).Flow_memory > int32(1) {
  20174 		return 0
  20175 	}
  20176 	if (*WebPConfig)(unsafe.Pointer(config)).Fexact < 0 || (*WebPConfig)(unsafe.Pointer(config)).Fexact > int32(1) {
  20177 		return 0
  20178 	}
  20179 	if (*WebPConfig)(unsafe.Pointer(config)).Fuse_sharp_yuv < 0 || (*WebPConfig)(unsafe.Pointer(config)).Fuse_sharp_yuv > int32(1) {
  20180 		return 0
  20181 	}
  20182 	return int32(1)
  20183 }
  20184 
  20185 //------------------------------------------------------------------------------
  20186 
  20187 // C documentation
  20188 //
  20189 //	// Mapping between -z level and -m / -q parameter settings.
  20190 var kLosslessPresets = [10]struct {
  20191 	Fmethod  uint8_t
  20192 	Fquality uint8_t
  20193 }{
  20194 	0: {},
  20195 	1: {
  20196 		Fmethod:  uint8(1),
  20197 		Fquality: uint8(20),
  20198 	},
  20199 	2: {
  20200 		Fmethod:  uint8(2),
  20201 		Fquality: uint8(25),
  20202 	},
  20203 	3: {
  20204 		Fmethod:  uint8(3),
  20205 		Fquality: uint8(30),
  20206 	},
  20207 	4: {
  20208 		Fmethod:  uint8(3),
  20209 		Fquality: uint8(50),
  20210 	},
  20211 	5: {
  20212 		Fmethod:  uint8(4),
  20213 		Fquality: uint8(50),
  20214 	},
  20215 	6: {
  20216 		Fmethod:  uint8(4),
  20217 		Fquality: uint8(75),
  20218 	},
  20219 	7: {
  20220 		Fmethod:  uint8(4),
  20221 		Fquality: uint8(90),
  20222 	},
  20223 	8: {
  20224 		Fmethod:  uint8(5),
  20225 		Fquality: uint8(90),
  20226 	},
  20227 	9: {
  20228 		Fmethod:  uint8(6),
  20229 		Fquality: uint8(100),
  20230 	},
  20231 }
  20232 
  20233 func WebPConfigLosslessPreset(tls *libc.TLS, config uintptr, level int32) (r int32) {
  20234 	if config == libc.UintptrFromInt32(0) || level < 0 || level > int32(MAX_LEVEL1) {
  20235 		return 0
  20236 	}
  20237 	(*WebPConfig)(unsafe.Pointer(config)).Flossless = int32(1)
  20238 	(*WebPConfig)(unsafe.Pointer(config)).Fmethod = int32(kLosslessPresets[level].Fmethod)
  20239 	(*WebPConfig)(unsafe.Pointer(config)).Fquality = float32(kLosslessPresets[level].Fquality)
  20240 	return int32(1)
  20241 }
  20242 
  20243 const SIZE_MAX6 = "_UI64_MAX"
  20244 
  20245 type VP8Residual = struct {
  20246 	Ffirst      int32
  20247 	Flast       int32
  20248 	Fcoeffs     uintptr
  20249 	Fcoeff_type int32
  20250 	Fprob       uintptr
  20251 	Fstats      uintptr
  20252 	Fcosts      CostArrayPtr
  20253 }
  20254 
  20255 //------------------------------------------------------------------------------
  20256 
  20257 // Copyright 2011 Google Inc. All Rights Reserved.
  20258 //
  20259 // Use of this source code is governed by a BSD-style license
  20260 // that can be found in the COPYING file in the root of the source
  20261 // tree. An additional intellectual property rights grant can be found
  20262 // in the file PATENTS. All contributing project authors may
  20263 // be found in the AUTHORS file in the root of the source tree.
  20264 // -----------------------------------------------------------------------------
  20265 //
  20266 //   WebP encoder: internal header.
  20267 //
  20268 // Author: Skal (pascal.massimino@gmail.com)
  20269 
  20270 //------------------------------------------------------------------------------
  20271 // Level cost tables
  20272 
  20273 // C documentation
  20274 //
  20275 //	// For each given level, the following table gives the pattern of contexts to
  20276 //	// use for coding it (in [][0]) as well as the bit value to use for each
  20277 //	// context (in [][1]).
  20278 var VP8LevelCodes = [67][2]uint16_t{
  20279 	0: {
  20280 		0: uint16(0x001),
  20281 	},
  20282 	1: {
  20283 		0: uint16(0x007),
  20284 		1: uint16(0x001),
  20285 	},
  20286 	2: {
  20287 		0: uint16(0x00f),
  20288 		1: uint16(0x005),
  20289 	},
  20290 	3: {
  20291 		0: uint16(0x00f),
  20292 		1: uint16(0x00d),
  20293 	},
  20294 	4: {
  20295 		0: uint16(0x033),
  20296 		1: uint16(0x003),
  20297 	},
  20298 	5: {
  20299 		0: uint16(0x033),
  20300 		1: uint16(0x003),
  20301 	},
  20302 	6: {
  20303 		0: uint16(0x033),
  20304 		1: uint16(0x023),
  20305 	},
  20306 	7: {
  20307 		0: uint16(0x033),
  20308 		1: uint16(0x023),
  20309 	},
  20310 	8: {
  20311 		0: uint16(0x033),
  20312 		1: uint16(0x023),
  20313 	},
  20314 	9: {
  20315 		0: uint16(0x033),
  20316 		1: uint16(0x023),
  20317 	},
  20318 	10: {
  20319 		0: uint16(0x0d3),
  20320 		1: uint16(0x013),
  20321 	},
  20322 	11: {
  20323 		0: uint16(0x0d3),
  20324 		1: uint16(0x013),
  20325 	},
  20326 	12: {
  20327 		0: uint16(0x0d3),
  20328 		1: uint16(0x013),
  20329 	},
  20330 	13: {
  20331 		0: uint16(0x0d3),
  20332 		1: uint16(0x013),
  20333 	},
  20334 	14: {
  20335 		0: uint16(0x0d3),
  20336 		1: uint16(0x013),
  20337 	},
  20338 	15: {
  20339 		0: uint16(0x0d3),
  20340 		1: uint16(0x013),
  20341 	},
  20342 	16: {
  20343 		0: uint16(0x0d3),
  20344 		1: uint16(0x013),
  20345 	},
  20346 	17: {
  20347 		0: uint16(0x0d3),
  20348 		1: uint16(0x013),
  20349 	},
  20350 	18: {
  20351 		0: uint16(0x0d3),
  20352 		1: uint16(0x093),
  20353 	},
  20354 	19: {
  20355 		0: uint16(0x0d3),
  20356 		1: uint16(0x093),
  20357 	},
  20358 	20: {
  20359 		0: uint16(0x0d3),
  20360 		1: uint16(0x093),
  20361 	},
  20362 	21: {
  20363 		0: uint16(0x0d3),
  20364 		1: uint16(0x093),
  20365 	},
  20366 	22: {
  20367 		0: uint16(0x0d3),
  20368 		1: uint16(0x093),
  20369 	},
  20370 	23: {
  20371 		0: uint16(0x0d3),
  20372 		1: uint16(0x093),
  20373 	},
  20374 	24: {
  20375 		0: uint16(0x0d3),
  20376 		1: uint16(0x093),
  20377 	},
  20378 	25: {
  20379 		0: uint16(0x0d3),
  20380 		1: uint16(0x093),
  20381 	},
  20382 	26: {
  20383 		0: uint16(0x0d3),
  20384 		1: uint16(0x093),
  20385 	},
  20386 	27: {
  20387 		0: uint16(0x0d3),
  20388 		1: uint16(0x093),
  20389 	},
  20390 	28: {
  20391 		0: uint16(0x0d3),
  20392 		1: uint16(0x093),
  20393 	},
  20394 	29: {
  20395 		0: uint16(0x0d3),
  20396 		1: uint16(0x093),
  20397 	},
  20398 	30: {
  20399 		0: uint16(0x0d3),
  20400 		1: uint16(0x093),
  20401 	},
  20402 	31: {
  20403 		0: uint16(0x0d3),
  20404 		1: uint16(0x093),
  20405 	},
  20406 	32: {
  20407 		0: uint16(0x0d3),
  20408 		1: uint16(0x093),
  20409 	},
  20410 	33: {
  20411 		0: uint16(0x0d3),
  20412 		1: uint16(0x093),
  20413 	},
  20414 	34: {
  20415 		0: uint16(0x153),
  20416 		1: uint16(0x053),
  20417 	},
  20418 	35: {
  20419 		0: uint16(0x153),
  20420 		1: uint16(0x053),
  20421 	},
  20422 	36: {
  20423 		0: uint16(0x153),
  20424 		1: uint16(0x053),
  20425 	},
  20426 	37: {
  20427 		0: uint16(0x153),
  20428 		1: uint16(0x053),
  20429 	},
  20430 	38: {
  20431 		0: uint16(0x153),
  20432 		1: uint16(0x053),
  20433 	},
  20434 	39: {
  20435 		0: uint16(0x153),
  20436 		1: uint16(0x053),
  20437 	},
  20438 	40: {
  20439 		0: uint16(0x153),
  20440 		1: uint16(0x053),
  20441 	},
  20442 	41: {
  20443 		0: uint16(0x153),
  20444 		1: uint16(0x053),
  20445 	},
  20446 	42: {
  20447 		0: uint16(0x153),
  20448 		1: uint16(0x053),
  20449 	},
  20450 	43: {
  20451 		0: uint16(0x153),
  20452 		1: uint16(0x053),
  20453 	},
  20454 	44: {
  20455 		0: uint16(0x153),
  20456 		1: uint16(0x053),
  20457 	},
  20458 	45: {
  20459 		0: uint16(0x153),
  20460 		1: uint16(0x053),
  20461 	},
  20462 	46: {
  20463 		0: uint16(0x153),
  20464 		1: uint16(0x053),
  20465 	},
  20466 	47: {
  20467 		0: uint16(0x153),
  20468 		1: uint16(0x053),
  20469 	},
  20470 	48: {
  20471 		0: uint16(0x153),
  20472 		1: uint16(0x053),
  20473 	},
  20474 	49: {
  20475 		0: uint16(0x153),
  20476 		1: uint16(0x053),
  20477 	},
  20478 	50: {
  20479 		0: uint16(0x153),
  20480 		1: uint16(0x053),
  20481 	},
  20482 	51: {
  20483 		0: uint16(0x153),
  20484 		1: uint16(0x053),
  20485 	},
  20486 	52: {
  20487 		0: uint16(0x153),
  20488 		1: uint16(0x053),
  20489 	},
  20490 	53: {
  20491 		0: uint16(0x153),
  20492 		1: uint16(0x053),
  20493 	},
  20494 	54: {
  20495 		0: uint16(0x153),
  20496 		1: uint16(0x053),
  20497 	},
  20498 	55: {
  20499 		0: uint16(0x153),
  20500 		1: uint16(0x053),
  20501 	},
  20502 	56: {
  20503 		0: uint16(0x153),
  20504 		1: uint16(0x053),
  20505 	},
  20506 	57: {
  20507 		0: uint16(0x153),
  20508 		1: uint16(0x053),
  20509 	},
  20510 	58: {
  20511 		0: uint16(0x153),
  20512 		1: uint16(0x053),
  20513 	},
  20514 	59: {
  20515 		0: uint16(0x153),
  20516 		1: uint16(0x053),
  20517 	},
  20518 	60: {
  20519 		0: uint16(0x153),
  20520 		1: uint16(0x053),
  20521 	},
  20522 	61: {
  20523 		0: uint16(0x153),
  20524 		1: uint16(0x053),
  20525 	},
  20526 	62: {
  20527 		0: uint16(0x153),
  20528 		1: uint16(0x053),
  20529 	},
  20530 	63: {
  20531 		0: uint16(0x153),
  20532 		1: uint16(0x053),
  20533 	},
  20534 	64: {
  20535 		0: uint16(0x153),
  20536 		1: uint16(0x053),
  20537 	},
  20538 	65: {
  20539 		0: uint16(0x153),
  20540 		1: uint16(0x053),
  20541 	},
  20542 	66: {
  20543 		0: uint16(0x153),
  20544 		1: uint16(0x153),
  20545 	},
  20546 }
  20547 
  20548 func VariableLevelCost(tls *libc.TLS, level int32, probas uintptr) (r int32) {
  20549 	var bits, cost, i, pattern, v3, v5 int32
  20550 	var v2 uint8_t
  20551 	_, _, _, _, _, _, _ = bits, cost, i, pattern, v2, v3, v5
  20552 	pattern = int32(**(**uint16_t)(__ccgo_up(uintptr(unsafe.Pointer(&VP8LevelCodes)) + uintptr(level-int32(1))*4)))
  20553 	bits = int32(**(**uint16_t)(__ccgo_up(uintptr(unsafe.Pointer(&VP8LevelCodes)) + uintptr(level-int32(1))*4 + 1*2)))
  20554 	cost = 0
  20555 	i = int32(2)
  20556 	for {
  20557 		if !(pattern != 0) {
  20558 			break
  20559 		}
  20560 		if pattern&int32(1) != 0 {
  20561 			v2 = **(**uint8_t)(__ccgo_up(probas + uintptr(i)))
  20562 			if !(bits&int32(1) != 0) {
  20563 				v5 = int32(VP8EntropyCost[v2])
  20564 			} else {
  20565 				v5 = int32(VP8EntropyCost[int32(255)-int32(v2)])
  20566 			}
  20567 			v3 = v5
  20568 			goto _4
  20569 		_4:
  20570 			cost = cost + v3
  20571 		}
  20572 		bits = bits >> int32(1)
  20573 		pattern = pattern >> int32(1)
  20574 		goto _1
  20575 	_1:
  20576 		;
  20577 		i = i + 1
  20578 	}
  20579 	return cost
  20580 }
  20581 
  20582 //------------------------------------------------------------------------------
  20583 // Pre-calc level costs once for all
  20584 
  20585 func VP8CalculateLevelCosts(tls *libc.TLS, proba1 uintptr) {
  20586 	var band, cost0, cost_base, ctx, ctype, n, v, v10, v12, v14, v16, v4, v6, v8 int32
  20587 	var p, table uintptr
  20588 	var v13, v5, v9 uint8_t
  20589 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = band, cost0, cost_base, ctx, ctype, n, p, table, v, v10, v12, v13, v14, v16, v4, v5, v6, v8, v9
  20590 	if !((*VP8EncProba)(unsafe.Pointer(proba1)).Fdirty != 0) {
  20591 		return
  20592 	} // nothing to do.
  20593 	ctype = 0
  20594 	for {
  20595 		if !(ctype < int32(NUM_TYPES)) {
  20596 			break
  20597 		}
  20598 		band = 0
  20599 		for {
  20600 			if !(band < int32(NUM_BANDS)) {
  20601 				break
  20602 			}
  20603 			ctx = 0
  20604 			for {
  20605 				if !(ctx < int32(NUM_CTX)) {
  20606 					break
  20607 				}
  20608 				p = proba1 + 4 + uintptr(ctype)*264 + uintptr(band)*33 + uintptr(ctx)*11
  20609 				table = proba1 + 5284 + uintptr(ctype)*3264 + uintptr(band)*408 + uintptr(ctx)*136
  20610 				if ctx > 0 {
  20611 					v5 = **(**uint8_t)(__ccgo_up(p))
  20612 					if !(int32(1) != 0) {
  20613 						v8 = int32(VP8EntropyCost[v5])
  20614 					} else {
  20615 						v8 = int32(VP8EntropyCost[int32(255)-int32(v5)])
  20616 					}
  20617 					v6 = v8
  20618 					goto _7
  20619 				_7:
  20620 					v4 = v6
  20621 				} else {
  20622 					v4 = 0
  20623 				}
  20624 				cost0 = v4
  20625 				v9 = **(**uint8_t)(__ccgo_up(p + 1))
  20626 				if !(int32(1) != 0) {
  20627 					v12 = int32(VP8EntropyCost[v9])
  20628 				} else {
  20629 					v12 = int32(VP8EntropyCost[int32(255)-int32(v9)])
  20630 				}
  20631 				v10 = v12
  20632 				goto _11
  20633 			_11:
  20634 				cost_base = v10 + cost0
  20635 				v13 = **(**uint8_t)(__ccgo_up(p + 1))
  20636 				if !(0 != 0) {
  20637 					v16 = int32(VP8EntropyCost[v13])
  20638 				} else {
  20639 					v16 = int32(VP8EntropyCost[int32(255)-int32(v13)])
  20640 				}
  20641 				v14 = v16
  20642 				goto _15
  20643 			_15:
  20644 				**(**uint16_t)(__ccgo_up(table)) = uint16(v14 + cost0)
  20645 				v = int32(1)
  20646 				for {
  20647 					if !(v <= int32(MAX_VARIABLE_LEVEL)) {
  20648 						break
  20649 					}
  20650 					**(**uint16_t)(__ccgo_up(table + uintptr(v)*2)) = uint16(cost_base + VariableLevelCost(tls, v, p))
  20651 					goto _17
  20652 				_17:
  20653 					;
  20654 					v = v + 1
  20655 				}
  20656 				// Starting at level 67 and up, the variable part of the cost is
  20657 				// actually constant.
  20658 				goto _3
  20659 			_3:
  20660 				;
  20661 				ctx = ctx + 1
  20662 			}
  20663 			goto _2
  20664 		_2:
  20665 			;
  20666 			band = band + 1
  20667 		}
  20668 		n = 0
  20669 		for {
  20670 			if !(n < int32(16)) {
  20671 				break
  20672 			} // replicate bands. We don't need to sentinel.
  20673 			ctx = 0
  20674 			for {
  20675 				if !(ctx < int32(NUM_CTX)) {
  20676 					break
  20677 				}
  20678 				**(**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
  20679 				goto _19
  20680 			_19:
  20681 				;
  20682 				ctx = ctx + 1
  20683 			}
  20684 			goto _18
  20685 		_18:
  20686 			;
  20687 			n = n + 1
  20688 		}
  20689 		goto _1
  20690 	_1:
  20691 		;
  20692 		ctype = ctype + 1
  20693 	}
  20694 	(*VP8EncProba)(unsafe.Pointer(proba1)).Fdirty = 0
  20695 }
  20696 
  20697 //------------------------------------------------------------------------------
  20698 // helper functions for residuals struct VP8Residual.
  20699 
  20700 func VP8InitResidual(tls *libc.TLS, first int32, coeff_type int32, enc uintptr, res uintptr) {
  20701 	(*VP8Residual)(unsafe.Pointer(res)).Fcoeff_type = coeff_type
  20702 	(*VP8Residual)(unsafe.Pointer(res)).Fprob = enc + 3616 + 4 + uintptr(coeff_type)*264
  20703 	(*VP8Residual)(unsafe.Pointer(res)).Fstats = enc + 3616 + 1060 + uintptr(coeff_type)*1056
  20704 	(*VP8Residual)(unsafe.Pointer(res)).Fcosts = enc + 3616 + 18344 + uintptr(coeff_type)*384
  20705 	(*VP8Residual)(unsafe.Pointer(res)).Ffirst = first
  20706 }
  20707 
  20708 //------------------------------------------------------------------------------
  20709 // Mode costs
  20710 
  20711 func VP8GetCostLuma4(tls *libc.TLS, it uintptr, levels uintptr) (r int32) {
  20712 	bp := tls.Alloc(48)
  20713 	defer tls.Free(48)
  20714 	var R, ctx, x, y int32
  20715 	var enc uintptr
  20716 	var _ /* res at bp+0 */ VP8Residual
  20717 	_, _, _, _, _ = R, ctx, enc, x, y
  20718 	x = (*VP8EncIterator)(unsafe.Pointer(it)).Fi4 & libc.Int32FromInt32(3)
  20719 	y = (*VP8EncIterator)(unsafe.Pointer(it)).Fi4 >> libc.Int32FromInt32(2)
  20720 	enc = (*VP8EncIterator)(unsafe.Pointer(it)).Fenc
  20721 	R = 0
  20722 	VP8InitResidual(tls, 0, int32(3), enc, bp)
  20723 	ctx = **(**int32)(__ccgo_up(it + 132 + uintptr(x)*4)) + **(**int32)(__ccgo_up(it + 168 + uintptr(y)*4))
  20724 	(*(*func(*libc.TLS, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8SetResidualCoeffs})))(tls, levels, bp)
  20725 	R = R + (*(*func(*libc.TLS, int32, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{VP8GetResidualCost})))(tls, ctx, bp)
  20726 	return R
  20727 }
  20728 
  20729 func VP8GetCostLuma16(tls *libc.TLS, it uintptr, rd uintptr) (r int32) {
  20730 	bp := tls.Alloc(48)
  20731 	defer tls.Free(48)
  20732 	var R, ctx, x, y, v3 int32
  20733 	var enc uintptr
  20734 	var _ /* res at bp+0 */ VP8Residual
  20735 	_, _, _, _, _, _ = R, ctx, enc, x, y, v3
  20736 	enc = (*VP8EncIterator)(unsafe.Pointer(it)).Fenc
  20737 	R = 0
  20738 	VP8IteratorNzToBytes(tls, it) // re-import the non-zero context
  20739 	// DC
  20740 	VP8InitResidual(tls, 0, int32(1), enc, bp)
  20741 	(*(*func(*libc.TLS, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8SetResidualCoeffs})))(tls, rd+40, bp)
  20742 	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)
  20743 	// AC
  20744 	VP8InitResidual(tls, int32(1), 0, enc, bp)
  20745 	y = 0
  20746 	for {
  20747 		if !(y < int32(4)) {
  20748 			break
  20749 		}
  20750 		x = 0
  20751 		for {
  20752 			if !(x < int32(4)) {
  20753 				break
  20754 			}
  20755 			ctx = **(**int32)(__ccgo_up(it + 132 + uintptr(x)*4)) + **(**int32)(__ccgo_up(it + 168 + uintptr(y)*4))
  20756 			(*(*func(*libc.TLS, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8SetResidualCoeffs})))(tls, rd+72+uintptr(x+y*int32(4))*32, bp)
  20757 			R = R + (*(*func(*libc.TLS, int32, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{VP8GetResidualCost})))(tls, ctx, bp)
  20758 			v3 = libc.BoolInt32((**(**VP8Residual)(__ccgo_up(bp))).Flast >= libc.Int32FromInt32(0))
  20759 			**(**int32)(__ccgo_up(it + 168 + uintptr(y)*4)) = v3
  20760 			**(**int32)(__ccgo_up(it + 132 + uintptr(x)*4)) = v3
  20761 			goto _2
  20762 		_2:
  20763 			;
  20764 			x = x + 1
  20765 		}
  20766 		goto _1
  20767 	_1:
  20768 		;
  20769 		y = y + 1
  20770 	}
  20771 	return R
  20772 }
  20773 
  20774 func VP8GetCostUV(tls *libc.TLS, it uintptr, rd uintptr) (r int32) {
  20775 	bp := tls.Alloc(48)
  20776 	defer tls.Free(48)
  20777 	var R, ch, ctx, x, y, v4 int32
  20778 	var enc uintptr
  20779 	var _ /* res at bp+0 */ VP8Residual
  20780 	_, _, _, _, _, _, _ = R, ch, ctx, enc, x, y, v4
  20781 	enc = (*VP8EncIterator)(unsafe.Pointer(it)).Fenc
  20782 	R = 0
  20783 	VP8IteratorNzToBytes(tls, it) // re-import the non-zero context
  20784 	VP8InitResidual(tls, 0, int32(2), enc, bp)
  20785 	ch = 0
  20786 	for {
  20787 		if !(ch <= int32(2)) {
  20788 			break
  20789 		}
  20790 		y = 0
  20791 		for {
  20792 			if !(y < int32(2)) {
  20793 				break
  20794 			}
  20795 			x = 0
  20796 			for {
  20797 				if !(x < int32(2)) {
  20798 					break
  20799 				}
  20800 				ctx = **(**int32)(__ccgo_up(it + 132 + uintptr(int32(4)+ch+x)*4)) + **(**int32)(__ccgo_up(it + 168 + uintptr(int32(4)+ch+y)*4))
  20801 				(*(*func(*libc.TLS, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8SetResidualCoeffs})))(tls, rd+584+uintptr(ch*int32(2)+x+y*int32(2))*32, bp)
  20802 				R = R + (*(*func(*libc.TLS, int32, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{VP8GetResidualCost})))(tls, ctx, bp)
  20803 				v4 = libc.BoolInt32((**(**VP8Residual)(__ccgo_up(bp))).Flast >= libc.Int32FromInt32(0))
  20804 				**(**int32)(__ccgo_up(it + 168 + uintptr(int32(4)+ch+y)*4)) = v4
  20805 				**(**int32)(__ccgo_up(it + 132 + uintptr(int32(4)+ch+x)*4)) = v4
  20806 				goto _3
  20807 			_3:
  20808 				;
  20809 				x = x + 1
  20810 			}
  20811 			goto _2
  20812 		_2:
  20813 			;
  20814 			y = y + 1
  20815 		}
  20816 		goto _1
  20817 	_1:
  20818 		;
  20819 		ch = ch + int32(2)
  20820 	}
  20821 	return R
  20822 }
  20823 
  20824 //------------------------------------------------------------------------------
  20825 // Recording of token probabilities.
  20826 
  20827 // We keep the table-free variant around for reference, in case.
  20828 
  20829 // C documentation
  20830 //
  20831 //	// Simulate block coding, but only record statistics.
  20832 //	// Note: no need to record the fixed probas.
  20833 func VP8RecordCoeffs(tls *libc.TLS, ctx int32, res uintptr) (r int32) {
  20834 	var bits, i, mask, n, pattern, v, v1, v4, v7 int32
  20835 	var p proba_t
  20836 	var s, v2 uintptr
  20837 	_, _, _, _, _, _, _, _, _, _, _, _ = bits, i, mask, n, p, pattern, s, v, v1, v2, v4, v7
  20838 	n = (*VP8Residual)(unsafe.Pointer(res)).Ffirst
  20839 	// should be stats[VP8EncBands[n]], but it's equivalent for n=0 or 1
  20840 	s = (*VP8Residual)(unsafe.Pointer(res)).Fstats + uintptr(n)*132 + uintptr(ctx)*44
  20841 	if (*VP8Residual)(unsafe.Pointer(res)).Flast < 0 {
  20842 		v1 = 0
  20843 		v2 = s + uintptr(0)*4
  20844 		p = **(**proba_t)(__ccgo_up(v2))
  20845 		if p >= libc.Uint32FromUint32(0xfffe0000) {
  20846 			p = (p + uint32(1)) >> int32(1) & uint32(0x7fff7fff)
  20847 		}
  20848 		p = p + (uint32(0x00010000) + uint32(v1))
  20849 		**(**proba_t)(__ccgo_up(v2)) = p
  20850 		_ = v1
  20851 		goto _3
  20852 	_3:
  20853 		;
  20854 		return 0
  20855 	}
  20856 	for n <= (*VP8Residual)(unsafe.Pointer(res)).Flast {
  20857 		v1 = int32(1)
  20858 		v2 = s + uintptr(0)*4
  20859 		p = **(**proba_t)(__ccgo_up(v2))
  20860 		if p >= libc.Uint32FromUint32(0xfffe0000) {
  20861 			p = (p + uint32(1)) >> int32(1) & uint32(0x7fff7fff)
  20862 		}
  20863 		p = p + (uint32(0x00010000) + uint32(v1))
  20864 		**(**proba_t)(__ccgo_up(v2)) = p
  20865 		_ = v1
  20866 		goto _6
  20867 	_6:
  20868 		; // order of record doesn't matter
  20869 		for {
  20870 			v4 = n
  20871 			n = n + 1
  20872 			v1 = int32(**(**int16_t)(__ccgo_up((*VP8Residual)(unsafe.Pointer(res)).Fcoeffs + uintptr(v4)*2)))
  20873 			v = v1
  20874 			if !(v1 == 0) {
  20875 				break
  20876 			}
  20877 			v7 = 0
  20878 			v2 = s + uintptr(1)*4
  20879 			p = **(**proba_t)(__ccgo_up(v2))
  20880 			if p >= libc.Uint32FromUint32(0xfffe0000) {
  20881 				p = (p + uint32(1)) >> int32(1) & uint32(0x7fff7fff)
  20882 			}
  20883 			p = p + (uint32(0x00010000) + uint32(v7))
  20884 			**(**proba_t)(__ccgo_up(v2)) = p
  20885 			_ = v7
  20886 			goto _11
  20887 		_11:
  20888 			;
  20889 			s = (*VP8Residual)(unsafe.Pointer(res)).Fstats + uintptr(VP8EncBands[n])*132
  20890 		}
  20891 		v1 = int32(1)
  20892 		v2 = s + uintptr(1)*4
  20893 		p = **(**proba_t)(__ccgo_up(v2))
  20894 		if p >= libc.Uint32FromUint32(0xfffe0000) {
  20895 			p = (p + uint32(1)) >> int32(1) & uint32(0x7fff7fff)
  20896 		}
  20897 		p = p + (uint32(0x00010000) + uint32(v1))
  20898 		**(**proba_t)(__ccgo_up(v2)) = p
  20899 		_ = v1
  20900 		goto _14
  20901 	_14:
  20902 		;
  20903 		v1 = libc.BoolInt32(uint32(2) < uint32(v+libc.Int32FromInt32(1)))
  20904 		v2 = s + uintptr(2)*4
  20905 		p = **(**proba_t)(__ccgo_up(v2))
  20906 		if p >= libc.Uint32FromUint32(0xfffe0000) {
  20907 			p = (p + uint32(1)) >> int32(1) & uint32(0x7fff7fff)
  20908 		}
  20909 		p = p + (uint32(0x00010000) + uint32(v1))
  20910 		**(**proba_t)(__ccgo_up(v2)) = p
  20911 		v4 = v1
  20912 		goto _18
  20913 	_18:
  20914 		if !(v4 != 0) { // v = -1 or 1
  20915 			s = (*VP8Residual)(unsafe.Pointer(res)).Fstats + uintptr(VP8EncBands[n])*132 + 1*44
  20916 		} else {
  20917 			v = libc.Xabs(tls, v)
  20918 			if v > int32(MAX_VARIABLE_LEVEL) {
  20919 				v = int32(MAX_VARIABLE_LEVEL)
  20920 			}
  20921 			bits = int32(**(**uint16_t)(__ccgo_up(uintptr(unsafe.Pointer(&VP8LevelCodes)) + uintptr(v-int32(1))*4 + 1*2)))
  20922 			pattern = int32(**(**uint16_t)(__ccgo_up(uintptr(unsafe.Pointer(&VP8LevelCodes)) + uintptr(v-int32(1))*4)))
  20923 			i = 0
  20924 			for {
  20925 				pattern = pattern >> int32(1)
  20926 				if !(pattern != 0) {
  20927 					break
  20928 				}
  20929 				mask = int32(2) << i
  20930 				if pattern&int32(1) != 0 {
  20931 					v1 = libc.BoolInt32(!!(bits&mask != 0))
  20932 					v2 = s + uintptr(3)*4 + uintptr(i)*4
  20933 					p = **(**proba_t)(__ccgo_up(v2))
  20934 					if p >= libc.Uint32FromUint32(0xfffe0000) {
  20935 						p = (p + uint32(1)) >> int32(1) & uint32(0x7fff7fff)
  20936 					}
  20937 					p = p + (uint32(0x00010000) + uint32(v1))
  20938 					**(**proba_t)(__ccgo_up(v2)) = p
  20939 					_ = v1
  20940 					goto _22
  20941 				_22:
  20942 				}
  20943 				goto _19
  20944 			_19:
  20945 				;
  20946 				i = i + 1
  20947 			}
  20948 			s = (*VP8Residual)(unsafe.Pointer(res)).Fstats + uintptr(VP8EncBands[n])*132 + 2*44
  20949 		}
  20950 	}
  20951 	if n < int32(16) {
  20952 		v1 = 0
  20953 		v2 = s + uintptr(0)*4
  20954 		p = **(**proba_t)(__ccgo_up(v2))
  20955 		if p >= libc.Uint32FromUint32(0xfffe0000) {
  20956 			p = (p + uint32(1)) >> int32(1) & uint32(0x7fff7fff)
  20957 		}
  20958 		p = p + (uint32(0x00010000) + uint32(v1))
  20959 		**(**proba_t)(__ccgo_up(v2)) = p
  20960 		_ = v1
  20961 		goto _25
  20962 	_25:
  20963 	}
  20964 	return int32(1)
  20965 }
  20966 
  20967 const MAX_DELTA_SIZE = 64
  20968 const SIZE_MAX7 = "UINT64_MAX"
  20969 
  20970 //------------------------------------------------------------------------------
  20971 
  20972 // C documentation
  20973 //
  20974 //	// This table gives, for a given sharpness, the filtering strength to be
  20975 //	// used (at least) in order to filter a given edge step delta.
  20976 //	// This is constructed by brute force inspection: for all delta, we iterate
  20977 //	// over all possible filtering strength / thresh until needs_filter() returns
  20978 //	// true.
  20979 var kLevelsFromDelta = [8][64]uint8_t{
  20980 	0: {
  20981 		1:  uint8(1),
  20982 		2:  uint8(2),
  20983 		3:  uint8(3),
  20984 		4:  uint8(4),
  20985 		5:  uint8(5),
  20986 		6:  uint8(6),
  20987 		7:  uint8(7),
  20988 		8:  uint8(8),
  20989 		9:  uint8(9),
  20990 		10: uint8(10),
  20991 		11: uint8(11),
  20992 		12: uint8(12),
  20993 		13: uint8(13),
  20994 		14: uint8(14),
  20995 		15: uint8(15),
  20996 		16: uint8(16),
  20997 		17: uint8(17),
  20998 		18: uint8(18),
  20999 		19: uint8(19),
  21000 		20: uint8(20),
  21001 		21: uint8(21),
  21002 		22: uint8(22),
  21003 		23: uint8(23),
  21004 		24: uint8(24),
  21005 		25: uint8(25),
  21006 		26: uint8(26),
  21007 		27: uint8(27),
  21008 		28: uint8(28),
  21009 		29: uint8(29),
  21010 		30: uint8(30),
  21011 		31: uint8(31),
  21012 		32: uint8(32),
  21013 		33: uint8(33),
  21014 		34: uint8(34),
  21015 		35: uint8(35),
  21016 		36: uint8(36),
  21017 		37: uint8(37),
  21018 		38: uint8(38),
  21019 		39: uint8(39),
  21020 		40: uint8(40),
  21021 		41: uint8(41),
  21022 		42: uint8(42),
  21023 		43: uint8(43),
  21024 		44: uint8(44),
  21025 		45: uint8(45),
  21026 		46: uint8(46),
  21027 		47: uint8(47),
  21028 		48: uint8(48),
  21029 		49: uint8(49),
  21030 		50: uint8(50),
  21031 		51: uint8(51),
  21032 		52: uint8(52),
  21033 		53: uint8(53),
  21034 		54: uint8(54),
  21035 		55: uint8(55),
  21036 		56: uint8(56),
  21037 		57: uint8(57),
  21038 		58: uint8(58),
  21039 		59: uint8(59),
  21040 		60: uint8(60),
  21041 		61: uint8(61),
  21042 		62: uint8(62),
  21043 		63: uint8(63),
  21044 	},
  21045 	1: {
  21046 		1:  uint8(1),
  21047 		2:  uint8(2),
  21048 		3:  uint8(3),
  21049 		4:  uint8(5),
  21050 		5:  uint8(6),
  21051 		6:  uint8(7),
  21052 		7:  uint8(8),
  21053 		8:  uint8(9),
  21054 		9:  uint8(11),
  21055 		10: uint8(12),
  21056 		11: uint8(13),
  21057 		12: uint8(14),
  21058 		13: uint8(15),
  21059 		14: uint8(17),
  21060 		15: uint8(18),
  21061 		16: uint8(20),
  21062 		17: uint8(21),
  21063 		18: uint8(23),
  21064 		19: uint8(24),
  21065 		20: uint8(26),
  21066 		21: uint8(27),
  21067 		22: uint8(29),
  21068 		23: uint8(30),
  21069 		24: uint8(32),
  21070 		25: uint8(33),
  21071 		26: uint8(35),
  21072 		27: uint8(36),
  21073 		28: uint8(38),
  21074 		29: uint8(39),
  21075 		30: uint8(41),
  21076 		31: uint8(42),
  21077 		32: uint8(44),
  21078 		33: uint8(45),
  21079 		34: uint8(47),
  21080 		35: uint8(48),
  21081 		36: uint8(50),
  21082 		37: uint8(51),
  21083 		38: uint8(53),
  21084 		39: uint8(54),
  21085 		40: uint8(56),
  21086 		41: uint8(57),
  21087 		42: uint8(59),
  21088 		43: uint8(60),
  21089 		44: uint8(62),
  21090 		45: uint8(63),
  21091 		46: uint8(63),
  21092 		47: uint8(63),
  21093 		48: uint8(63),
  21094 		49: uint8(63),
  21095 		50: uint8(63),
  21096 		51: uint8(63),
  21097 		52: uint8(63),
  21098 		53: uint8(63),
  21099 		54: uint8(63),
  21100 		55: uint8(63),
  21101 		56: uint8(63),
  21102 		57: uint8(63),
  21103 		58: uint8(63),
  21104 		59: uint8(63),
  21105 		60: uint8(63),
  21106 		61: uint8(63),
  21107 		62: uint8(63),
  21108 		63: uint8(63),
  21109 	},
  21110 	2: {
  21111 		1:  uint8(1),
  21112 		2:  uint8(2),
  21113 		3:  uint8(3),
  21114 		4:  uint8(5),
  21115 		5:  uint8(6),
  21116 		6:  uint8(7),
  21117 		7:  uint8(8),
  21118 		8:  uint8(9),
  21119 		9:  uint8(11),
  21120 		10: uint8(12),
  21121 		11: uint8(13),
  21122 		12: uint8(14),
  21123 		13: uint8(16),
  21124 		14: uint8(17),
  21125 		15: uint8(19),
  21126 		16: uint8(20),
  21127 		17: uint8(22),
  21128 		18: uint8(23),
  21129 		19: uint8(25),
  21130 		20: uint8(26),
  21131 		21: uint8(28),
  21132 		22: uint8(29),
  21133 		23: uint8(31),
  21134 		24: uint8(32),
  21135 		25: uint8(34),
  21136 		26: uint8(35),
  21137 		27: uint8(37),
  21138 		28: uint8(38),
  21139 		29: uint8(40),
  21140 		30: uint8(41),
  21141 		31: uint8(43),
  21142 		32: uint8(44),
  21143 		33: uint8(46),
  21144 		34: uint8(47),
  21145 		35: uint8(49),
  21146 		36: uint8(50),
  21147 		37: uint8(52),
  21148 		38: uint8(53),
  21149 		39: uint8(55),
  21150 		40: uint8(56),
  21151 		41: uint8(58),
  21152 		42: uint8(59),
  21153 		43: uint8(61),
  21154 		44: uint8(62),
  21155 		45: uint8(63),
  21156 		46: uint8(63),
  21157 		47: uint8(63),
  21158 		48: uint8(63),
  21159 		49: uint8(63),
  21160 		50: uint8(63),
  21161 		51: uint8(63),
  21162 		52: uint8(63),
  21163 		53: uint8(63),
  21164 		54: uint8(63),
  21165 		55: uint8(63),
  21166 		56: uint8(63),
  21167 		57: uint8(63),
  21168 		58: uint8(63),
  21169 		59: uint8(63),
  21170 		60: uint8(63),
  21171 		61: uint8(63),
  21172 		62: uint8(63),
  21173 		63: uint8(63),
  21174 	},
  21175 	3: {
  21176 		1:  uint8(1),
  21177 		2:  uint8(2),
  21178 		3:  uint8(3),
  21179 		4:  uint8(5),
  21180 		5:  uint8(6),
  21181 		6:  uint8(7),
  21182 		7:  uint8(8),
  21183 		8:  uint8(9),
  21184 		9:  uint8(11),
  21185 		10: uint8(12),
  21186 		11: uint8(13),
  21187 		12: uint8(15),
  21188 		13: uint8(16),
  21189 		14: uint8(18),
  21190 		15: uint8(19),
  21191 		16: uint8(21),
  21192 		17: uint8(22),
  21193 		18: uint8(24),
  21194 		19: uint8(25),
  21195 		20: uint8(27),
  21196 		21: uint8(28),
  21197 		22: uint8(30),
  21198 		23: uint8(31),
  21199 		24: uint8(33),
  21200 		25: uint8(34),
  21201 		26: uint8(36),
  21202 		27: uint8(37),
  21203 		28: uint8(39),
  21204 		29: uint8(40),
  21205 		30: uint8(42),
  21206 		31: uint8(43),
  21207 		32: uint8(45),
  21208 		33: uint8(46),
  21209 		34: uint8(48),
  21210 		35: uint8(49),
  21211 		36: uint8(51),
  21212 		37: uint8(52),
  21213 		38: uint8(54),
  21214 		39: uint8(55),
  21215 		40: uint8(57),
  21216 		41: uint8(58),
  21217 		42: uint8(60),
  21218 		43: uint8(61),
  21219 		44: uint8(63),
  21220 		45: uint8(63),
  21221 		46: uint8(63),
  21222 		47: uint8(63),
  21223 		48: uint8(63),
  21224 		49: uint8(63),
  21225 		50: uint8(63),
  21226 		51: uint8(63),
  21227 		52: uint8(63),
  21228 		53: uint8(63),
  21229 		54: uint8(63),
  21230 		55: uint8(63),
  21231 		56: uint8(63),
  21232 		57: uint8(63),
  21233 		58: uint8(63),
  21234 		59: uint8(63),
  21235 		60: uint8(63),
  21236 		61: uint8(63),
  21237 		62: uint8(63),
  21238 		63: uint8(63),
  21239 	},
  21240 	4: {
  21241 		1:  uint8(1),
  21242 		2:  uint8(2),
  21243 		3:  uint8(3),
  21244 		4:  uint8(5),
  21245 		5:  uint8(6),
  21246 		6:  uint8(7),
  21247 		7:  uint8(8),
  21248 		8:  uint8(9),
  21249 		9:  uint8(11),
  21250 		10: uint8(12),
  21251 		11: uint8(14),
  21252 		12: uint8(15),
  21253 		13: uint8(17),
  21254 		14: uint8(18),
  21255 		15: uint8(20),
  21256 		16: uint8(21),
  21257 		17: uint8(23),
  21258 		18: uint8(24),
  21259 		19: uint8(26),
  21260 		20: uint8(27),
  21261 		21: uint8(29),
  21262 		22: uint8(30),
  21263 		23: uint8(32),
  21264 		24: uint8(33),
  21265 		25: uint8(35),
  21266 		26: uint8(36),
  21267 		27: uint8(38),
  21268 		28: uint8(39),
  21269 		29: uint8(41),
  21270 		30: uint8(42),
  21271 		31: uint8(44),
  21272 		32: uint8(45),
  21273 		33: uint8(47),
  21274 		34: uint8(48),
  21275 		35: uint8(50),
  21276 		36: uint8(51),
  21277 		37: uint8(53),
  21278 		38: uint8(54),
  21279 		39: uint8(56),
  21280 		40: uint8(57),
  21281 		41: uint8(59),
  21282 		42: uint8(60),
  21283 		43: uint8(62),
  21284 		44: uint8(63),
  21285 		45: uint8(63),
  21286 		46: uint8(63),
  21287 		47: uint8(63),
  21288 		48: uint8(63),
  21289 		49: uint8(63),
  21290 		50: uint8(63),
  21291 		51: uint8(63),
  21292 		52: uint8(63),
  21293 		53: uint8(63),
  21294 		54: uint8(63),
  21295 		55: uint8(63),
  21296 		56: uint8(63),
  21297 		57: uint8(63),
  21298 		58: uint8(63),
  21299 		59: uint8(63),
  21300 		60: uint8(63),
  21301 		61: uint8(63),
  21302 		62: uint8(63),
  21303 		63: uint8(63),
  21304 	},
  21305 	5: {
  21306 		1:  uint8(1),
  21307 		2:  uint8(2),
  21308 		3:  uint8(4),
  21309 		4:  uint8(5),
  21310 		5:  uint8(7),
  21311 		6:  uint8(8),
  21312 		7:  uint8(9),
  21313 		8:  uint8(11),
  21314 		9:  uint8(12),
  21315 		10: uint8(13),
  21316 		11: uint8(15),
  21317 		12: uint8(16),
  21318 		13: uint8(17),
  21319 		14: uint8(19),
  21320 		15: uint8(20),
  21321 		16: uint8(22),
  21322 		17: uint8(23),
  21323 		18: uint8(25),
  21324 		19: uint8(26),
  21325 		20: uint8(28),
  21326 		21: uint8(29),
  21327 		22: uint8(31),
  21328 		23: uint8(32),
  21329 		24: uint8(34),
  21330 		25: uint8(35),
  21331 		26: uint8(37),
  21332 		27: uint8(38),
  21333 		28: uint8(40),
  21334 		29: uint8(41),
  21335 		30: uint8(43),
  21336 		31: uint8(44),
  21337 		32: uint8(46),
  21338 		33: uint8(47),
  21339 		34: uint8(49),
  21340 		35: uint8(50),
  21341 		36: uint8(52),
  21342 		37: uint8(53),
  21343 		38: uint8(55),
  21344 		39: uint8(56),
  21345 		40: uint8(58),
  21346 		41: uint8(59),
  21347 		42: uint8(61),
  21348 		43: uint8(62),
  21349 		44: uint8(63),
  21350 		45: uint8(63),
  21351 		46: uint8(63),
  21352 		47: uint8(63),
  21353 		48: uint8(63),
  21354 		49: uint8(63),
  21355 		50: uint8(63),
  21356 		51: uint8(63),
  21357 		52: uint8(63),
  21358 		53: uint8(63),
  21359 		54: uint8(63),
  21360 		55: uint8(63),
  21361 		56: uint8(63),
  21362 		57: uint8(63),
  21363 		58: uint8(63),
  21364 		59: uint8(63),
  21365 		60: uint8(63),
  21366 		61: uint8(63),
  21367 		62: uint8(63),
  21368 		63: uint8(63),
  21369 	},
  21370 	6: {
  21371 		1:  uint8(1),
  21372 		2:  uint8(2),
  21373 		3:  uint8(4),
  21374 		4:  uint8(5),
  21375 		5:  uint8(7),
  21376 		6:  uint8(8),
  21377 		7:  uint8(9),
  21378 		8:  uint8(11),
  21379 		9:  uint8(12),
  21380 		10: uint8(13),
  21381 		11: uint8(15),
  21382 		12: uint8(16),
  21383 		13: uint8(18),
  21384 		14: uint8(19),
  21385 		15: uint8(21),
  21386 		16: uint8(22),
  21387 		17: uint8(24),
  21388 		18: uint8(25),
  21389 		19: uint8(27),
  21390 		20: uint8(28),
  21391 		21: uint8(30),
  21392 		22: uint8(31),
  21393 		23: uint8(33),
  21394 		24: uint8(34),
  21395 		25: uint8(36),
  21396 		26: uint8(37),
  21397 		27: uint8(39),
  21398 		28: uint8(40),
  21399 		29: uint8(42),
  21400 		30: uint8(43),
  21401 		31: uint8(45),
  21402 		32: uint8(46),
  21403 		33: uint8(48),
  21404 		34: uint8(49),
  21405 		35: uint8(51),
  21406 		36: uint8(52),
  21407 		37: uint8(54),
  21408 		38: uint8(55),
  21409 		39: uint8(57),
  21410 		40: uint8(58),
  21411 		41: uint8(60),
  21412 		42: uint8(61),
  21413 		43: uint8(63),
  21414 		44: uint8(63),
  21415 		45: uint8(63),
  21416 		46: uint8(63),
  21417 		47: uint8(63),
  21418 		48: uint8(63),
  21419 		49: uint8(63),
  21420 		50: uint8(63),
  21421 		51: uint8(63),
  21422 		52: uint8(63),
  21423 		53: uint8(63),
  21424 		54: uint8(63),
  21425 		55: uint8(63),
  21426 		56: uint8(63),
  21427 		57: uint8(63),
  21428 		58: uint8(63),
  21429 		59: uint8(63),
  21430 		60: uint8(63),
  21431 		61: uint8(63),
  21432 		62: uint8(63),
  21433 		63: uint8(63),
  21434 	},
  21435 	7: {
  21436 		1:  uint8(1),
  21437 		2:  uint8(2),
  21438 		3:  uint8(4),
  21439 		4:  uint8(5),
  21440 		5:  uint8(7),
  21441 		6:  uint8(8),
  21442 		7:  uint8(9),
  21443 		8:  uint8(11),
  21444 		9:  uint8(12),
  21445 		10: uint8(14),
  21446 		11: uint8(15),
  21447 		12: uint8(17),
  21448 		13: uint8(18),
  21449 		14: uint8(20),
  21450 		15: uint8(21),
  21451 		16: uint8(23),
  21452 		17: uint8(24),
  21453 		18: uint8(26),
  21454 		19: uint8(27),
  21455 		20: uint8(29),
  21456 		21: uint8(30),
  21457 		22: uint8(32),
  21458 		23: uint8(33),
  21459 		24: uint8(35),
  21460 		25: uint8(36),
  21461 		26: uint8(38),
  21462 		27: uint8(39),
  21463 		28: uint8(41),
  21464 		29: uint8(42),
  21465 		30: uint8(44),
  21466 		31: uint8(45),
  21467 		32: uint8(47),
  21468 		33: uint8(48),
  21469 		34: uint8(50),
  21470 		35: uint8(51),
  21471 		36: uint8(53),
  21472 		37: uint8(54),
  21473 		38: uint8(56),
  21474 		39: uint8(57),
  21475 		40: uint8(59),
  21476 		41: uint8(60),
  21477 		42: uint8(62),
  21478 		43: uint8(63),
  21479 		44: uint8(63),
  21480 		45: uint8(63),
  21481 		46: uint8(63),
  21482 		47: uint8(63),
  21483 		48: uint8(63),
  21484 		49: uint8(63),
  21485 		50: uint8(63),
  21486 		51: uint8(63),
  21487 		52: uint8(63),
  21488 		53: uint8(63),
  21489 		54: uint8(63),
  21490 		55: uint8(63),
  21491 		56: uint8(63),
  21492 		57: uint8(63),
  21493 		58: uint8(63),
  21494 		59: uint8(63),
  21495 		60: uint8(63),
  21496 		61: uint8(63),
  21497 		62: uint8(63),
  21498 		63: uint8(63),
  21499 	},
  21500 }
  21501 
  21502 func VP8FilterStrengthFromDelta(tls *libc.TLS, sharpness int32, delta int32) (r int32) {
  21503 	var pos, v1 int32
  21504 	_, _ = pos, v1
  21505 	if delta < int32(MAX_DELTA_SIZE) {
  21506 		v1 = delta
  21507 	} else {
  21508 		v1 = libc.Int32FromInt32(MAX_DELTA_SIZE) - libc.Int32FromInt32(1)
  21509 	}
  21510 	pos = v1
  21511 	return int32(**(**uint8_t)(__ccgo_up(uintptr(unsafe.Pointer(&kLevelsFromDelta)) + uintptr(sharpness)*64 + uintptr(pos))))
  21512 }
  21513 
  21514 //------------------------------------------------------------------------------
  21515 // Paragraph 15.4: compute the inner-edge filtering strength
  21516 
  21517 func GetILevel(tls *libc.TLS, sharpness int32, level int32) (r int32) {
  21518 	if sharpness > 0 {
  21519 		if sharpness > int32(4) {
  21520 			level = level >> int32(2)
  21521 		} else {
  21522 			level = level >> int32(1)
  21523 		}
  21524 		if level > int32(9)-sharpness {
  21525 			level = int32(9) - sharpness
  21526 		}
  21527 	}
  21528 	if level < int32(1) {
  21529 		level = int32(1)
  21530 	}
  21531 	return level
  21532 }
  21533 
  21534 func DoFilter1(tls *libc.TLS, it uintptr, level int32) {
  21535 	var enc, u_dst, v_dst, y_dst uintptr
  21536 	var hev_thresh, ilevel, limit, v1, v2 int32
  21537 	_, _, _, _, _, _, _, _, _ = enc, hev_thresh, ilevel, limit, u_dst, v_dst, y_dst, v1, v2
  21538 	enc = (*VP8EncIterator)(unsafe.Pointer(it)).Fenc
  21539 	ilevel = GetILevel(tls, (*WebPConfig)(unsafe.Pointer((*VP8Encoder)(unsafe.Pointer(enc)).Fconfig)).Ffilter_sharpness, level)
  21540 	limit = int32(2)*level + ilevel
  21541 	y_dst = (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_out2 + uintptr(libc.Int32FromInt32(Y_OFF_ENC))
  21542 	u_dst = (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_out2 + uintptr(libc.Int32FromInt32(U_OFF_ENC))
  21543 	v_dst = (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_out2 + uintptr(libc.Int32FromInt32(16)+libc.Int32FromInt32(8))
  21544 	// copy current block to yuv_out2
  21545 	libc.Xmemcpy(tls, y_dst, (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_out, uint64(libc.Int32FromInt32(BPS)*libc.Int32FromInt32(16))*libc.Uint64FromInt64(1))
  21546 	if (*VP8Encoder)(unsafe.Pointer(enc)).Ffilter_hdr.Fsimple == int32(1) { // simple
  21547 		(*(*func(*libc.TLS, uintptr, int32, int32))(unsafe.Pointer(&struct{ uintptr }{VP8SimpleHFilter16i})))(tls, y_dst, int32(BPS), limit)
  21548 		(*(*func(*libc.TLS, uintptr, int32, int32))(unsafe.Pointer(&struct{ uintptr }{VP8SimpleVFilter16i})))(tls, y_dst, int32(BPS), limit)
  21549 	} else {
  21550 		if level >= int32(40) {
  21551 			v1 = int32(2)
  21552 		} else {
  21553 			if level >= int32(15) {
  21554 				v2 = int32(1)
  21555 			} else {
  21556 				v2 = 0
  21557 			}
  21558 			v1 = v2
  21559 		} // complex
  21560 		hev_thresh = v1
  21561 		(*(*func(*libc.TLS, uintptr, int32, int32, int32, int32))(unsafe.Pointer(&struct{ uintptr }{VP8HFilter16i})))(tls, y_dst, int32(BPS), limit, ilevel, hev_thresh)
  21562 		(*(*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)
  21563 		(*(*func(*libc.TLS, uintptr, int32, int32, int32, int32))(unsafe.Pointer(&struct{ uintptr }{VP8VFilter16i})))(tls, y_dst, int32(BPS), limit, ilevel, hev_thresh)
  21564 		(*(*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)
  21565 	}
  21566 }
  21567 
  21568 //------------------------------------------------------------------------------
  21569 // SSIM metric for one macroblock
  21570 
  21571 func GetMBSSIM(tls *libc.TLS, yuv1 uintptr, yuv2 uintptr) (r float64) {
  21572 	var sum float64
  21573 	var x, y int32
  21574 	_, _, _ = sum, x, y
  21575 	sum = float64(0)
  21576 	// compute SSIM in a 10 x 10 window
  21577 	y = int32(VP8_SSIM_KERNEL)
  21578 	for {
  21579 		if !(y < libc.Int32FromInt32(16)-libc.Int32FromInt32(VP8_SSIM_KERNEL)) {
  21580 			break
  21581 		}
  21582 		x = int32(VP8_SSIM_KERNEL)
  21583 		for {
  21584 			if !(x < libc.Int32FromInt32(16)-libc.Int32FromInt32(VP8_SSIM_KERNEL)) {
  21585 				break
  21586 			}
  21587 			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))
  21588 			goto _2
  21589 		_2:
  21590 			;
  21591 			x = x + 1
  21592 		}
  21593 		goto _1
  21594 	_1:
  21595 		;
  21596 		y = y + 1
  21597 	}
  21598 	x = int32(1)
  21599 	for {
  21600 		if !(x < int32(7)) {
  21601 			break
  21602 		}
  21603 		y = int32(1)
  21604 		for {
  21605 			if !(y < int32(7)) {
  21606 				break
  21607 			}
  21608 			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))
  21609 			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))
  21610 			goto _4
  21611 		_4:
  21612 			;
  21613 			y = y + 1
  21614 		}
  21615 		goto _3
  21616 	_3:
  21617 		;
  21618 		x = x + 1
  21619 	}
  21620 	return sum
  21621 }
  21622 
  21623 //------------------------------------------------------------------------------
  21624 // Exposed APIs: Encoder should call the following 3 functions to adjust
  21625 // loop filter strength
  21626 
  21627 func VP8InitFilter(tls *libc.TLS, it uintptr) {
  21628 	var i, s int32
  21629 	_, _ = i, s
  21630 	if (*VP8EncIterator)(unsafe.Pointer(it)).Flf_stats != libc.UintptrFromInt32(0) {
  21631 		s = 0
  21632 		for {
  21633 			if !(s < int32(NUM_MB_SEGMENTS)) {
  21634 				break
  21635 			}
  21636 			i = 0
  21637 			for {
  21638 				if !(i < int32(MAX_LF_LEVELS)) {
  21639 					break
  21640 				}
  21641 				**(**float64)(__ccgo_up((*VP8EncIterator)(unsafe.Pointer(it)).Flf_stats + uintptr(s)*512 + uintptr(i)*8)) = libc.Float64FromInt32(0)
  21642 				goto _2
  21643 			_2:
  21644 				;
  21645 				i = i + 1
  21646 			}
  21647 			goto _1
  21648 		_1:
  21649 			;
  21650 			s = s + 1
  21651 		}
  21652 		VP8SSIMDspInit(tls)
  21653 	}
  21654 }
  21655 
  21656 func VP8StoreFilterStats(tls *libc.TLS, it uintptr) {
  21657 	var d, delta_max, delta_min, level, level0, s, step_size, v1 int32
  21658 	var enc uintptr
  21659 	_, _, _, _, _, _, _, _, _ = d, delta_max, delta_min, enc, level, level0, s, step_size, v1
  21660 	enc = (*VP8EncIterator)(unsafe.Pointer(it)).Fenc
  21661 	s = int32(uint32(*(*uint8)(unsafe.Pointer((*VP8EncIterator)(unsafe.Pointer(it)).Fmb + 0)) & 0x60 >> 5))
  21662 	level0 = (**(**VP8SegmentInfo)(__ccgo_up(enc + 608 + uintptr(s)*744))).Ffstrength
  21663 	// explore +/-quant range of values around level0
  21664 	delta_min = -(**(**VP8SegmentInfo)(__ccgo_up(enc + 608 + uintptr(s)*744))).Fquant
  21665 	delta_max = (**(**VP8SegmentInfo)(__ccgo_up(enc + 608 + uintptr(s)*744))).Fquant
  21666 	if delta_max-delta_min >= int32(4) {
  21667 		v1 = int32(4)
  21668 	} else {
  21669 		v1 = int32(1)
  21670 	}
  21671 	step_size = v1
  21672 	if (*VP8EncIterator)(unsafe.Pointer(it)).Flf_stats == libc.UintptrFromInt32(0) {
  21673 		return
  21674 	}
  21675 	// NOTE: Currently we are applying filter only across the sublock edges
  21676 	// There are two reasons for that.
  21677 	// 1. Applying filter on macro block edges will change the pixels in
  21678 	// the left and top macro blocks. That will be hard to restore
  21679 	// 2. Macro Blocks on the bottom and right are not yet compressed. So we
  21680 	// cannot apply filter on the right and bottom macro block edges.
  21681 	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 {
  21682 		return
  21683 	}
  21684 	// Always try filter level  zero
  21685 	**(**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)
  21686 	d = delta_min
  21687 	for {
  21688 		if !(d <= delta_max) {
  21689 			break
  21690 		}
  21691 		level = level0 + d
  21692 		if level <= 0 || level >= int32(MAX_LF_LEVELS) {
  21693 			goto _2
  21694 		}
  21695 		DoFilter1(tls, it, level)
  21696 		**(**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)
  21697 		goto _2
  21698 	_2:
  21699 		;
  21700 		d = d + step_size
  21701 	}
  21702 }
  21703 
  21704 func VP8AdjustFilterStrength(tls *libc.TLS, it uintptr) {
  21705 	var best_level, delta, i, level, max_level, s, s1 int32
  21706 	var best_v, v float64
  21707 	var dqm, enc uintptr
  21708 	_, _, _, _, _, _, _, _, _, _, _ = best_level, best_v, delta, dqm, enc, i, level, max_level, s, s1, v
  21709 	enc = (*VP8EncIterator)(unsafe.Pointer(it)).Fenc
  21710 	if (*VP8EncIterator)(unsafe.Pointer(it)).Flf_stats != libc.UintptrFromInt32(0) {
  21711 		s = 0
  21712 		for {
  21713 			if !(s < int32(NUM_MB_SEGMENTS)) {
  21714 				break
  21715 			}
  21716 			best_level = 0
  21717 			// Improvement over filter level 0 should be at least 1e-5 (relatively)
  21718 			best_v = float64(float64(1.00001) * **(**float64)(__ccgo_up((*VP8EncIterator)(unsafe.Pointer(it)).Flf_stats + uintptr(s)*512)))
  21719 			i = int32(1)
  21720 			for {
  21721 				if !(i < int32(MAX_LF_LEVELS)) {
  21722 					break
  21723 				}
  21724 				v = **(**float64)(__ccgo_up((*VP8EncIterator)(unsafe.Pointer(it)).Flf_stats + uintptr(s)*512 + uintptr(i)*8))
  21725 				if v > best_v {
  21726 					best_v = v
  21727 					best_level = i
  21728 				}
  21729 				goto _2
  21730 			_2:
  21731 				;
  21732 				i = i + 1
  21733 			}
  21734 			(**(**VP8SegmentInfo)(__ccgo_up(enc + 608 + uintptr(s)*744))).Ffstrength = best_level
  21735 			goto _1
  21736 		_1:
  21737 			;
  21738 			s = s + 1
  21739 		}
  21740 		return
  21741 	}
  21742 	if (*WebPConfig)(unsafe.Pointer((*VP8Encoder)(unsafe.Pointer(enc)).Fconfig)).Ffilter_strength > 0 {
  21743 		max_level = 0
  21744 		s1 = 0
  21745 		for {
  21746 			if !(s1 < int32(NUM_MB_SEGMENTS)) {
  21747 				break
  21748 			}
  21749 			dqm = enc + 608 + uintptr(s1)*744
  21750 			// this '>> 3' accounts for some inverse WHT scaling
  21751 			delta = (*VP8SegmentInfo)(unsafe.Pointer(dqm)).Fmax_edge * int32(**(**uint16_t)(__ccgo_up(dqm + 224 + 1*2))) >> int32(3)
  21752 			level = VP8FilterStrengthFromDelta(tls, (*VP8Encoder)(unsafe.Pointer(enc)).Ffilter_hdr.Fsharpness, delta)
  21753 			if level > (*VP8SegmentInfo)(unsafe.Pointer(dqm)).Ffstrength {
  21754 				(*VP8SegmentInfo)(unsafe.Pointer(dqm)).Ffstrength = level
  21755 			}
  21756 			if max_level < (*VP8SegmentInfo)(unsafe.Pointer(dqm)).Ffstrength {
  21757 				max_level = (*VP8SegmentInfo)(unsafe.Pointer(dqm)).Ffstrength
  21758 			}
  21759 			goto _3
  21760 		_3:
  21761 			;
  21762 			s1 = s1 + 1
  21763 		}
  21764 		(*VP8Encoder)(unsafe.Pointer(enc)).Ffilter_hdr.Flevel = max_level
  21765 	}
  21766 }
  21767 
  21768 const DEBUG_SEARCH = 0
  21769 const DOMAIN = "_DOMAIN"
  21770 const DQ_LIMIT = 0.4
  21771 const FP_NAN = 0x0100
  21772 const FP_NDENORM = "_FPCLASS_ND"
  21773 const FP_NINF = "_FPCLASS_NINF"
  21774 const FP_NNORM = "_FPCLASS_NN"
  21775 const FP_NORMAL = 0x0400
  21776 const FP_NZERO = "_FPCLASS_NZ"
  21777 const FP_PDENORM = "_FPCLASS_PD"
  21778 const FP_PINF = "_FPCLASS_PINF"
  21779 const FP_PNORM = "_FPCLASS_PN"
  21780 const FP_PZERO = "_FPCLASS_PZ"
  21781 const FP_QNAN = "_FPCLASS_QNAN"
  21782 const FP_SNAN = "_FPCLASS_SNAN"
  21783 const FP_ZERO = 0x4000
  21784 const HUGE = "_HUGE"
  21785 const MATH_ERREXCEPT = 2
  21786 const MATH_ERRNO = 1
  21787 const MIN_COUNT = 96
  21788 const M_1_PI = 0.31830988618379067154
  21789 const M_2_PI = 0.63661977236758134308
  21790 const M_2_SQRTPI = 1.12837916709551257390
  21791 const M_E = 2.7182818284590452354
  21792 const M_LN10 = 2.30258509299404568402
  21793 const M_LN2 = 0.69314718055994530942
  21794 const M_LOG10E = 0.43429448190325182765
  21795 const M_LOG2E = 1.4426950408889634074
  21796 const M_PI = 3.14159265358979323846
  21797 const M_PI_2 = 1.57079632679489661923
  21798 const M_PI_4 = 0.78539816339744830962
  21799 const M_SQRT1_2 = 0.70710678118654752440
  21800 const M_SQRT2 = 1.41421356237309504880
  21801 const OVERFLOW = "_OVERFLOW"
  21802 const PLOSS = "_PLOSS"
  21803 const SEGMENT_VISU = 0
  21804 const SING = "_SING"
  21805 const SKIP_PROBA_THRESHOLD = 250
  21806 const TLOSS = "_TLOSS"
  21807 const UNDERFLOW = "_UNDERFLOW"
  21808 const _DOMAIN = 1
  21809 const _FPCLASS_ND = 0x0010
  21810 const _FPCLASS_NINF = 0x0004
  21811 const _FPCLASS_NN = 0x0008
  21812 const _FPCLASS_NZ = 0x0020
  21813 const _FPCLASS_PD = 0x0080
  21814 const _FPCLASS_PINF = 0x0200
  21815 const _FPCLASS_PN = 0x0100
  21816 const _FPCLASS_PZ = 0x0040
  21817 const _FPCLASS_QNAN = 0x0002
  21818 const _FPCLASS_SNAN = 0x0001
  21819 const _OVERFLOW = 3
  21820 const _PLOSS = 6
  21821 const _SING = 2
  21822 const _TLOSS = 5
  21823 const _UNDERFLOW = 4
  21824 const __MINGW_FPCLASS_DEFINED = 1
  21825 const __mingw_choose_expr = "__builtin_choose_expr"
  21826 const __setusermatherr = "__mingw_setusermatherr"
  21827 const _copysignl = "copysignl"
  21828 const _hypotl = "hypotl"
  21829 const matherr = "_matherr"
  21830 
  21831 type _exception = struct {
  21832 	Ftype1  int32
  21833 	Fname   uintptr
  21834 	Farg1   float64
  21835 	Farg2   float64
  21836 	Fretval float64
  21837 }
  21838 
  21839 type __mingw_dbl_type_t = struct {
  21840 	Fval [0]uint64
  21841 	Flh  [0]struct {
  21842 		Flow  uint32
  21843 		Fhigh uint32
  21844 	}
  21845 	Fx float64
  21846 }
  21847 
  21848 type __mingw_flt_type_t = struct {
  21849 	Fval [0]uint32
  21850 	Fx   float32
  21851 }
  21852 
  21853 type __mingw_ldbl_type_t = struct {
  21854 	Flh [0]struct {
  21855 		Flow      uint32
  21856 		Fhigh     uint32
  21857 		F__ccgo8  uint32
  21858 		F__ccgo12 uint32
  21859 	}
  21860 	Fx           float64
  21861 	F__ccgo_pad2 [8]byte
  21862 }
  21863 
  21864 type _complex = struct {
  21865 	Fx float64
  21866 	Fy float64
  21867 }
  21868 
  21869 type float_t = float32
  21870 
  21871 type double_t = float64
  21872 
  21873 // Alpha related constants.
  21874 
  21875 // Mux related constants.
  21876 
  21877 // Maximum chunk payload is such that adding the header and padding won't
  21878 // overflow a uint32_t.
  21879 
  21880 //------------------------------------------------------------------------------
  21881 // multi-pass convergence
  21882 
  21883 // we allow 2k of extra head-room in PARTITION0 limit.
  21884 
  21885 func Clamp(tls *libc.TLS, v float32, min float32, max float32) (r float32) {
  21886 	var v1, v2 float32
  21887 	_, _ = v1, v2
  21888 	if v < min {
  21889 		v1 = min
  21890 	} else {
  21891 		if v > max {
  21892 			v2 = max
  21893 		} else {
  21894 			v2 = v
  21895 		}
  21896 		v1 = v2
  21897 	}
  21898 	return v1
  21899 }
  21900 
  21901 type PassStats = struct {
  21902 	Fis_first       int32
  21903 	Fdq             float32
  21904 	Fq              float32
  21905 	Flast_q         float32
  21906 	Fqmin           float32
  21907 	Fqmax           float32
  21908 	Fvalue          float64
  21909 	Flast_value     float64
  21910 	Ftarget         float64
  21911 	Fdo_size_search int32
  21912 }
  21913 
  21914 func InitPassStats(tls *libc.TLS, enc uintptr, s uintptr) (r int32) {
  21915 	var do_size_search int32
  21916 	var target_PSNR, v1 float32
  21917 	var target_size uint64_t
  21918 	var v2, v3 float64
  21919 	_, _, _, _, _, _ = do_size_search, target_PSNR, target_size, v1, v2, v3
  21920 	target_size = uint64((*WebPConfig)(unsafe.Pointer((*VP8Encoder)(unsafe.Pointer(enc)).Fconfig)).Ftarget_size)
  21921 	do_size_search = libc.BoolInt32(target_size != libc.Uint64FromInt32(0))
  21922 	target_PSNR = (*WebPConfig)(unsafe.Pointer((*VP8Encoder)(unsafe.Pointer(enc)).Fconfig)).Ftarget_PSNR
  21923 	(*PassStats)(unsafe.Pointer(s)).Fis_first = int32(1)
  21924 	(*PassStats)(unsafe.Pointer(s)).Fdq = libc.Float32FromFloat32(10)
  21925 	(*PassStats)(unsafe.Pointer(s)).Fqmin = float32(libc.Float32FromFloat32(1) * float32((*WebPConfig)(unsafe.Pointer((*VP8Encoder)(unsafe.Pointer(enc)).Fconfig)).Fqmin))
  21926 	(*PassStats)(unsafe.Pointer(s)).Fqmax = float32(libc.Float32FromFloat32(1) * float32((*WebPConfig)(unsafe.Pointer((*VP8Encoder)(unsafe.Pointer(enc)).Fconfig)).Fqmax))
  21927 	v1 = Clamp(tls, (*WebPConfig)(unsafe.Pointer((*VP8Encoder)(unsafe.Pointer(enc)).Fconfig)).Fquality, (*PassStats)(unsafe.Pointer(s)).Fqmin, (*PassStats)(unsafe.Pointer(s)).Fqmax)
  21928 	(*PassStats)(unsafe.Pointer(s)).Flast_q = v1
  21929 	(*PassStats)(unsafe.Pointer(s)).Fq = v1
  21930 	if do_size_search != 0 {
  21931 		v2 = float64(target_size)
  21932 	} else {
  21933 		if float64(target_PSNR) > float64(0) {
  21934 			v3 = float64(target_PSNR)
  21935 		} else {
  21936 			v3 = float64(40)
  21937 		}
  21938 		v2 = v3
  21939 	}
  21940 	(*PassStats)(unsafe.Pointer(s)).Ftarget = v2 // default, just in case
  21941 	v2 = libc.Float64FromFloat64(0)
  21942 	(*PassStats)(unsafe.Pointer(s)).Flast_value = v2
  21943 	(*PassStats)(unsafe.Pointer(s)).Fvalue = v2
  21944 	(*PassStats)(unsafe.Pointer(s)).Fdo_size_search = do_size_search
  21945 	return do_size_search
  21946 }
  21947 
  21948 func ComputeNextQ(tls *libc.TLS, s uintptr) (r float32) {
  21949 	var dq, v1 float32
  21950 	var slope float64
  21951 	_, _, _ = dq, slope, v1
  21952 	if (*PassStats)(unsafe.Pointer(s)).Fis_first != 0 {
  21953 		if (*PassStats)(unsafe.Pointer(s)).Fvalue > (*PassStats)(unsafe.Pointer(s)).Ftarget {
  21954 			v1 = -(*PassStats)(unsafe.Pointer(s)).Fdq
  21955 		} else {
  21956 			v1 = (*PassStats)(unsafe.Pointer(s)).Fdq
  21957 		}
  21958 		dq = v1
  21959 		(*PassStats)(unsafe.Pointer(s)).Fis_first = 0
  21960 	} else {
  21961 		if (*PassStats)(unsafe.Pointer(s)).Fvalue != (*PassStats)(unsafe.Pointer(s)).Flast_value {
  21962 			slope = ((*PassStats)(unsafe.Pointer(s)).Ftarget - (*PassStats)(unsafe.Pointer(s)).Fvalue) / ((*PassStats)(unsafe.Pointer(s)).Flast_value - (*PassStats)(unsafe.Pointer(s)).Fvalue)
  21963 			dq = float32(float64(slope * float64((*PassStats)(unsafe.Pointer(s)).Flast_q-(*PassStats)(unsafe.Pointer(s)).Fq)))
  21964 		} else {
  21965 			dq = float32(0) // we're done?!
  21966 		}
  21967 	}
  21968 	// Limit variable to avoid large swings.
  21969 	(*PassStats)(unsafe.Pointer(s)).Fdq = Clamp(tls, dq, -libc.Float32FromFloat32(30), libc.Float32FromFloat32(30))
  21970 	(*PassStats)(unsafe.Pointer(s)).Flast_q = (*PassStats)(unsafe.Pointer(s)).Fq
  21971 	(*PassStats)(unsafe.Pointer(s)).Flast_value = (*PassStats)(unsafe.Pointer(s)).Fvalue
  21972 	(*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)
  21973 	return (*PassStats)(unsafe.Pointer(s)).Fq
  21974 }
  21975 
  21976 //------------------------------------------------------------------------------
  21977 // Reset the statistics about: number of skips, token proba, level cost,...
  21978 
  21979 func ResetStats(tls *libc.TLS, enc uintptr) {
  21980 	var proba uintptr
  21981 	_ = proba
  21982 	proba = enc + 3616
  21983 	VP8CalculateLevelCosts(tls, proba)
  21984 	(*VP8EncProba)(unsafe.Pointer(proba)).Fnb_skip = 0
  21985 }
  21986 
  21987 //------------------------------------------------------------------------------
  21988 // Skip decision probability
  21989 
  21990 func CalcSkipProba(tls *libc.TLS, nb uint64_t, total uint64_t) (r int32) {
  21991 	var v1 uint64
  21992 	_ = v1
  21993 	if total != 0 {
  21994 		v1 = (total - nb) * uint64(255) / total
  21995 	} else {
  21996 		v1 = uint64(255)
  21997 	}
  21998 	return int32(v1)
  21999 }
  22000 
  22001 // C documentation
  22002 //
  22003 //	// Returns the bit-cost for coding the skip probability.
  22004 func FinalizeSkipProba(tls *libc.TLS, enc uintptr) (r int32) {
  22005 	var nb_events, nb_mbs, size, v2, v4, v6, v8 int32
  22006 	var proba1 uintptr
  22007 	var v1, v5 uint8_t
  22008 	_, _, _, _, _, _, _, _, _, _ = nb_events, nb_mbs, proba1, size, v1, v2, v4, v5, v6, v8
  22009 	proba1 = enc + 3616
  22010 	nb_mbs = (*VP8Encoder)(unsafe.Pointer(enc)).Fmb_w * (*VP8Encoder)(unsafe.Pointer(enc)).Fmb_h
  22011 	nb_events = (*VP8EncProba)(unsafe.Pointer(proba1)).Fnb_skip
  22012 	(*VP8EncProba)(unsafe.Pointer(proba1)).Fskip_proba = uint8(CalcSkipProba(tls, uint64(nb_events), uint64(nb_mbs)))
  22013 	(*VP8EncProba)(unsafe.Pointer(proba1)).Fuse_skip_proba = libc.BoolInt32(int32((*VP8EncProba)(unsafe.Pointer(proba1)).Fskip_proba) < int32(SKIP_PROBA_THRESHOLD))
  22014 	size = int32(256) // 'use_skip_proba' bit
  22015 	if (*VP8EncProba)(unsafe.Pointer(proba1)).Fuse_skip_proba != 0 {
  22016 		v1 = (*VP8EncProba)(unsafe.Pointer(proba1)).Fskip_proba
  22017 		if !(int32(1) != 0) {
  22018 			v4 = int32(VP8EntropyCost[v1])
  22019 		} else {
  22020 			v4 = int32(VP8EntropyCost[int32(255)-int32(v1)])
  22021 		}
  22022 		v2 = v4
  22023 		goto _3
  22024 	_3:
  22025 		v5 = (*VP8EncProba)(unsafe.Pointer(proba1)).Fskip_proba
  22026 		if !(0 != 0) {
  22027 			v8 = int32(VP8EntropyCost[v5])
  22028 		} else {
  22029 			v8 = int32(VP8EntropyCost[int32(255)-int32(v5)])
  22030 		}
  22031 		v6 = v8
  22032 		goto _7
  22033 	_7:
  22034 		size = size + (nb_events*v2 + (nb_mbs-nb_events)*v6)
  22035 		size = size + libc.Int32FromInt32(8)*libc.Int32FromInt32(256) // cost of signaling the 'skip_proba' itself.
  22036 	}
  22037 	return size
  22038 }
  22039 
  22040 // C documentation
  22041 //
  22042 //	// Collect statistics and deduce probabilities for next coding pass.
  22043 //	// Return the total bit-cost for coding the probability updates.
  22044 func CalcTokenProba(tls *libc.TLS, nb int32, total int32) (r int32) {
  22045 	var v1 int32
  22046 	_ = v1
  22047 	if nb != 0 {
  22048 		v1 = int32(255) - nb*int32(255)/total
  22049 	} else {
  22050 		v1 = int32(255)
  22051 	}
  22052 	return v1
  22053 }
  22054 
  22055 // C documentation
  22056 //
  22057 //	// Cost of coding 'nb' 1's and 'total-nb' 0's using 'proba' probability.
  22058 func BranchCost(tls *libc.TLS, nb int32, total int32, proba1 int32) (r int32) {
  22059 	var v1, v5 uint8_t
  22060 	var v2, v4, v6, v8 int32
  22061 	_, _, _, _, _, _ = v1, v2, v4, v5, v6, v8
  22062 	v1 = uint8(proba1)
  22063 	if !(int32(1) != 0) {
  22064 		v4 = int32(VP8EntropyCost[v1])
  22065 	} else {
  22066 		v4 = int32(VP8EntropyCost[int32(255)-int32(v1)])
  22067 	}
  22068 	v2 = v4
  22069 	goto _3
  22070 _3:
  22071 	v5 = uint8(proba1)
  22072 	if !(0 != 0) {
  22073 		v8 = int32(VP8EntropyCost[v5])
  22074 	} else {
  22075 		v8 = int32(VP8EntropyCost[int32(255)-int32(v5)])
  22076 	}
  22077 	v6 = v8
  22078 	goto _7
  22079 _7:
  22080 	return nb*v2 + (total-nb)*v6
  22081 }
  22082 
  22083 func ResetTokenStats(tls *libc.TLS, enc uintptr) {
  22084 	var proba uintptr
  22085 	_ = proba
  22086 	proba = enc + 3616
  22087 	libc.Xmemset(tls, proba+1060, 0, uint64(4224))
  22088 }
  22089 
  22090 func FinalizeTokenProbas(tls *libc.TLS, proba1 uintptr) (r int32) {
  22091 	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
  22092 	var stats proba_t
  22093 	var v13, v5, v9 uint8_t
  22094 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  22095 	has_changed = 0
  22096 	size = 0
  22097 	t = 0
  22098 	for {
  22099 		if !(t < int32(NUM_TYPES)) {
  22100 			break
  22101 		}
  22102 		b = 0
  22103 		for {
  22104 			if !(b < int32(NUM_BANDS)) {
  22105 				break
  22106 			}
  22107 			c = 0
  22108 			for {
  22109 				if !(c < int32(NUM_CTX)) {
  22110 					break
  22111 				}
  22112 				p = 0
  22113 				for {
  22114 					if !(p < int32(NUM_PROBAS)) {
  22115 						break
  22116 					}
  22117 					stats = **(**proba_t)(__ccgo_up(proba1 + 1060 + uintptr(t)*1056 + uintptr(b)*132 + uintptr(c)*44 + uintptr(p)*4))
  22118 					nb = int32(stats >> libc.Int32FromInt32(0) & uint32(0xffff))
  22119 					total = int32(stats >> libc.Int32FromInt32(16) & uint32(0xffff))
  22120 					update_proba = int32(**(**uint8_t)(__ccgo_up(uintptr(unsafe.Pointer(&VP8CoeffsUpdateProba)) + uintptr(t)*264 + uintptr(b)*33 + uintptr(c)*11 + uintptr(p))))
  22121 					old_p = int32(**(**uint8_t)(__ccgo_up(uintptr(unsafe.Pointer(&VP8CoeffsProba0)) + uintptr(t)*264 + uintptr(b)*33 + uintptr(c)*11 + uintptr(p))))
  22122 					new_p = CalcTokenProba(tls, nb, total)
  22123 					v5 = uint8(update_proba)
  22124 					if !(0 != 0) {
  22125 						v8 = int32(VP8EntropyCost[v5])
  22126 					} else {
  22127 						v8 = int32(VP8EntropyCost[int32(255)-int32(v5)])
  22128 					}
  22129 					v6 = v8
  22130 					goto _7
  22131 				_7:
  22132 					old_cost = BranchCost(tls, nb, total, old_p) + v6
  22133 					v9 = uint8(update_proba)
  22134 					if !(int32(1) != 0) {
  22135 						v12 = int32(VP8EntropyCost[v9])
  22136 					} else {
  22137 						v12 = int32(VP8EntropyCost[int32(255)-int32(v9)])
  22138 					}
  22139 					v10 = v12
  22140 					goto _11
  22141 				_11:
  22142 					new_cost = BranchCost(tls, nb, total, new_p) + v10 + libc.Int32FromInt32(8)*libc.Int32FromInt32(256)
  22143 					use_new_p = libc.BoolInt32(old_cost > new_cost)
  22144 					v13 = uint8(update_proba)
  22145 					if !(use_new_p != 0) {
  22146 						v16 = int32(VP8EntropyCost[v13])
  22147 					} else {
  22148 						v16 = int32(VP8EntropyCost[int32(255)-int32(v13)])
  22149 					}
  22150 					v14 = v16
  22151 					goto _15
  22152 				_15:
  22153 					size = size + v14
  22154 					if use_new_p != 0 { // only use proba that seem meaningful enough.
  22155 						**(**uint8_t)(__ccgo_up(proba1 + 4 + uintptr(t)*264 + uintptr(b)*33 + uintptr(c)*11 + uintptr(p))) = uint8(new_p)
  22156 						has_changed = has_changed | libc.BoolInt32(new_p != old_p)
  22157 						size = size + libc.Int32FromInt32(8)*libc.Int32FromInt32(256)
  22158 					} else {
  22159 						**(**uint8_t)(__ccgo_up(proba1 + 4 + uintptr(t)*264 + uintptr(b)*33 + uintptr(c)*11 + uintptr(p))) = uint8(old_p)
  22160 					}
  22161 					goto _4
  22162 				_4:
  22163 					;
  22164 					p = p + 1
  22165 				}
  22166 				goto _3
  22167 			_3:
  22168 				;
  22169 				c = c + 1
  22170 			}
  22171 			goto _2
  22172 		_2:
  22173 			;
  22174 			b = b + 1
  22175 		}
  22176 		goto _1
  22177 	_1:
  22178 		;
  22179 		t = t + 1
  22180 	}
  22181 	(*VP8EncProba)(unsafe.Pointer(proba1)).Fdirty = has_changed
  22182 	return size
  22183 }
  22184 
  22185 //------------------------------------------------------------------------------
  22186 // Finalize Segment probability based on the coding tree
  22187 
  22188 func GetProba(tls *libc.TLS, a int32, b int32) (r int32) {
  22189 	var total, v1 int32
  22190 	_, _ = total, v1
  22191 	total = a + b
  22192 	if total == 0 {
  22193 		v1 = int32(255)
  22194 	} else {
  22195 		v1 = (int32(255)*a + total/int32(2)) / total
  22196 	}
  22197 	return v1 // rounded proba
  22198 }
  22199 
  22200 func ResetSegments(tls *libc.TLS, enc uintptr) {
  22201 	var n int32
  22202 	_ = n
  22203 	n = 0
  22204 	for {
  22205 		if !(n < (*VP8Encoder)(unsafe.Pointer(enc)).Fmb_w*(*VP8Encoder)(unsafe.Pointer(enc)).Fmb_h) {
  22206 			break
  22207 		}
  22208 		libc.SetBitFieldPtr8Uint32((*VP8Encoder)(unsafe.Pointer(enc)).Fmb_info+uintptr(n)*4+0, libc.Uint32FromInt32(0), 5, 0x60)
  22209 		goto _1
  22210 	_1:
  22211 		;
  22212 		n = n + 1
  22213 	}
  22214 }
  22215 
  22216 func SetSegmentProbas(tls *libc.TLS, enc uintptr) {
  22217 	var mb, probas uintptr
  22218 	var n, v10, v12, v14, v16, v18, v20, v22, v24, v26, v28, v30, v32, v34, v4, v6, v8 int32
  22219 	var p [4]int32
  22220 	var v11, v15, v19, v23, v27, v3, v31, v7 uint8_t
  22221 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  22222 	p = [4]int32{}
  22223 	n = 0
  22224 	for {
  22225 		if !(n < (*VP8Encoder)(unsafe.Pointer(enc)).Fmb_w*(*VP8Encoder)(unsafe.Pointer(enc)).Fmb_h) {
  22226 			break
  22227 		}
  22228 		mb = (*VP8Encoder)(unsafe.Pointer(enc)).Fmb_info + uintptr(n)*4
  22229 		p[int32(uint32(*(*uint8)(unsafe.Pointer(mb + 0))&0x60>>5))] = p[int32(uint32(*(*uint8)(unsafe.Pointer(mb + 0))&0x60>>5))] + 1
  22230 		goto _1
  22231 	_1:
  22232 		;
  22233 		n = n + 1
  22234 	}
  22235 	if (*WebPPicture)(unsafe.Pointer((*VP8Encoder)(unsafe.Pointer(enc)).Fpic)).Fstats != libc.UintptrFromInt32(0) {
  22236 		n = 0
  22237 		for {
  22238 			if !(n < int32(NUM_MB_SEGMENTS)) {
  22239 				break
  22240 			}
  22241 			**(**int32)(__ccgo_up((*WebPPicture)(unsafe.Pointer((*VP8Encoder)(unsafe.Pointer(enc)).Fpic)).Fstats + 92 + uintptr(n)*4)) = p[n]
  22242 			goto _2
  22243 		_2:
  22244 			;
  22245 			n = n + 1
  22246 		}
  22247 	}
  22248 	if (*VP8Encoder)(unsafe.Pointer(enc)).Fsegment_hdr.Fnum_segments > int32(1) {
  22249 		probas = enc + 3616
  22250 		**(**uint8_t)(__ccgo_up(probas)) = uint8(GetProba(tls, p[0]+p[int32(1)], p[int32(2)]+p[int32(3)]))
  22251 		**(**uint8_t)(__ccgo_up(probas + 1)) = uint8(GetProba(tls, p[0], p[int32(1)]))
  22252 		**(**uint8_t)(__ccgo_up(probas + 2)) = uint8(GetProba(tls, p[int32(2)], p[int32(3)]))
  22253 		(*VP8Encoder)(unsafe.Pointer(enc)).Fsegment_hdr.Fupdate_map = libc.BoolInt32(int32(**(**uint8_t)(__ccgo_up(probas))) != int32(255) || int32(**(**uint8_t)(__ccgo_up(probas + 1))) != int32(255) || int32(**(**uint8_t)(__ccgo_up(probas + 2))) != int32(255))
  22254 		if !((*VP8Encoder)(unsafe.Pointer(enc)).Fsegment_hdr.Fupdate_map != 0) {
  22255 			ResetSegments(tls, enc)
  22256 		}
  22257 		v3 = **(**uint8_t)(__ccgo_up(probas))
  22258 		if !(0 != 0) {
  22259 			v6 = int32(VP8EntropyCost[v3])
  22260 		} else {
  22261 			v6 = int32(VP8EntropyCost[int32(255)-int32(v3)])
  22262 		}
  22263 		v4 = v6
  22264 		goto _5
  22265 	_5:
  22266 		v7 = **(**uint8_t)(__ccgo_up(probas + 1))
  22267 		if !(0 != 0) {
  22268 			v10 = int32(VP8EntropyCost[v7])
  22269 		} else {
  22270 			v10 = int32(VP8EntropyCost[int32(255)-int32(v7)])
  22271 		}
  22272 		v8 = v10
  22273 		goto _9
  22274 	_9:
  22275 		v11 = **(**uint8_t)(__ccgo_up(probas))
  22276 		if !(0 != 0) {
  22277 			v14 = int32(VP8EntropyCost[v11])
  22278 		} else {
  22279 			v14 = int32(VP8EntropyCost[int32(255)-int32(v11)])
  22280 		}
  22281 		v12 = v14
  22282 		goto _13
  22283 	_13:
  22284 		v15 = **(**uint8_t)(__ccgo_up(probas + 1))
  22285 		if !(int32(1) != 0) {
  22286 			v18 = int32(VP8EntropyCost[v15])
  22287 		} else {
  22288 			v18 = int32(VP8EntropyCost[int32(255)-int32(v15)])
  22289 		}
  22290 		v16 = v18
  22291 		goto _17
  22292 	_17:
  22293 		v19 = **(**uint8_t)(__ccgo_up(probas))
  22294 		if !(int32(1) != 0) {
  22295 			v22 = int32(VP8EntropyCost[v19])
  22296 		} else {
  22297 			v22 = int32(VP8EntropyCost[int32(255)-int32(v19)])
  22298 		}
  22299 		v20 = v22
  22300 		goto _21
  22301 	_21:
  22302 		v23 = **(**uint8_t)(__ccgo_up(probas + 2))
  22303 		if !(0 != 0) {
  22304 			v26 = int32(VP8EntropyCost[v23])
  22305 		} else {
  22306 			v26 = int32(VP8EntropyCost[int32(255)-int32(v23)])
  22307 		}
  22308 		v24 = v26
  22309 		goto _25
  22310 	_25:
  22311 		v27 = **(**uint8_t)(__ccgo_up(probas))
  22312 		if !(int32(1) != 0) {
  22313 			v30 = int32(VP8EntropyCost[v27])
  22314 		} else {
  22315 			v30 = int32(VP8EntropyCost[int32(255)-int32(v27)])
  22316 		}
  22317 		v28 = v30
  22318 		goto _29
  22319 	_29:
  22320 		v31 = **(**uint8_t)(__ccgo_up(probas + 2))
  22321 		if !(int32(1) != 0) {
  22322 			v34 = int32(VP8EntropyCost[v31])
  22323 		} else {
  22324 			v34 = int32(VP8EntropyCost[int32(255)-int32(v31)])
  22325 		}
  22326 		v32 = v34
  22327 		goto _33
  22328 	_33:
  22329 		(*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)
  22330 	} else {
  22331 		(*VP8Encoder)(unsafe.Pointer(enc)).Fsegment_hdr.Fupdate_map = 0
  22332 		(*VP8Encoder)(unsafe.Pointer(enc)).Fsegment_hdr.Fsize = 0
  22333 	}
  22334 }
  22335 
  22336 //------------------------------------------------------------------------------
  22337 // Coefficient coding
  22338 
  22339 func PutCoeffs(tls *libc.TLS, bw uintptr, ctx int32, res uintptr) (r int32) {
  22340 	var c, mask, n, sign, v, v1, v2 int32
  22341 	var p, tab, v3 uintptr
  22342 	_, _, _, _, _, _, _, _, _, _ = c, mask, n, p, sign, tab, v, v1, v2, v3
  22343 	n = (*VP8Residual)(unsafe.Pointer(res)).Ffirst
  22344 	// should be prob[VP8EncBands[n]], but it's equivalent for n=0 or 1
  22345 	p = (*VP8Residual)(unsafe.Pointer(res)).Fprob + uintptr(n)*33 + uintptr(ctx)*11
  22346 	if !(VP8PutBit(tls, bw, libc.BoolInt32((*VP8Residual)(unsafe.Pointer(res)).Flast >= 0), int32(**(**uint8_t)(__ccgo_up(p)))) != 0) {
  22347 		return 0
  22348 	}
  22349 	for n < int32(16) {
  22350 		v1 = n
  22351 		n = n + 1
  22352 		c = int32(**(**int16_t)(__ccgo_up((*VP8Residual)(unsafe.Pointer(res)).Fcoeffs + uintptr(v1)*2)))
  22353 		sign = libc.BoolInt32(c < 0)
  22354 		if sign != 0 {
  22355 			v2 = -c
  22356 		} else {
  22357 			v2 = c
  22358 		}
  22359 		v = v2
  22360 		if !(VP8PutBit(tls, bw, libc.BoolInt32(v != 0), int32(**(**uint8_t)(__ccgo_up(p + 1)))) != 0) {
  22361 			p = (*VP8Residual)(unsafe.Pointer(res)).Fprob + uintptr(VP8EncBands[n])*33
  22362 			continue
  22363 		}
  22364 		if !(VP8PutBit(tls, bw, libc.BoolInt32(v > int32(1)), int32(**(**uint8_t)(__ccgo_up(p + 2)))) != 0) {
  22365 			p = (*VP8Residual)(unsafe.Pointer(res)).Fprob + uintptr(VP8EncBands[n])*33 + 1*11
  22366 		} else {
  22367 			if !(VP8PutBit(tls, bw, libc.BoolInt32(v > int32(4)), int32(**(**uint8_t)(__ccgo_up(p + 3)))) != 0) {
  22368 				if VP8PutBit(tls, bw, libc.BoolInt32(v != int32(2)), int32(**(**uint8_t)(__ccgo_up(p + 4)))) != 0 {
  22369 					VP8PutBit(tls, bw, libc.BoolInt32(v == int32(4)), int32(**(**uint8_t)(__ccgo_up(p + 5))))
  22370 				}
  22371 			} else {
  22372 				if !(VP8PutBit(tls, bw, libc.BoolInt32(v > int32(10)), int32(**(**uint8_t)(__ccgo_up(p + 6)))) != 0) {
  22373 					if !(VP8PutBit(tls, bw, libc.BoolInt32(v > int32(6)), int32(**(**uint8_t)(__ccgo_up(p + 7)))) != 0) {
  22374 						VP8PutBit(tls, bw, libc.BoolInt32(v == int32(6)), int32(159))
  22375 					} else {
  22376 						VP8PutBit(tls, bw, libc.BoolInt32(v >= int32(9)), int32(165))
  22377 						VP8PutBit(tls, bw, libc.BoolInt32(!(v&libc.Int32FromInt32(1) != 0)), int32(145))
  22378 					}
  22379 				} else {
  22380 					if v < libc.Int32FromInt32(3)+libc.Int32FromInt32(8)<<libc.Int32FromInt32(1) { // VP8Cat3  (3b)
  22381 						VP8PutBit(tls, bw, 0, int32(**(**uint8_t)(__ccgo_up(p + 8))))
  22382 						VP8PutBit(tls, bw, 0, int32(**(**uint8_t)(__ccgo_up(p + 9))))
  22383 						v = v - (libc.Int32FromInt32(3) + libc.Int32FromInt32(8)<<libc.Int32FromInt32(0))
  22384 						mask = libc.Int32FromInt32(1) << libc.Int32FromInt32(2)
  22385 						tab = uintptr(unsafe.Pointer(&VP8Cat3))
  22386 					} else {
  22387 						if v < libc.Int32FromInt32(3)+libc.Int32FromInt32(8)<<libc.Int32FromInt32(2) { // VP8Cat4  (4b)
  22388 							VP8PutBit(tls, bw, 0, int32(**(**uint8_t)(__ccgo_up(p + 8))))
  22389 							VP8PutBit(tls, bw, int32(1), int32(**(**uint8_t)(__ccgo_up(p + 9))))
  22390 							v = v - (libc.Int32FromInt32(3) + libc.Int32FromInt32(8)<<libc.Int32FromInt32(1))
  22391 							mask = libc.Int32FromInt32(1) << libc.Int32FromInt32(3)
  22392 							tab = uintptr(unsafe.Pointer(&VP8Cat4))
  22393 						} else {
  22394 							if v < libc.Int32FromInt32(3)+libc.Int32FromInt32(8)<<libc.Int32FromInt32(3) { // VP8Cat5  (5b)
  22395 								VP8PutBit(tls, bw, int32(1), int32(**(**uint8_t)(__ccgo_up(p + 8))))
  22396 								VP8PutBit(tls, bw, 0, int32(**(**uint8_t)(__ccgo_up(p + 10))))
  22397 								v = v - (libc.Int32FromInt32(3) + libc.Int32FromInt32(8)<<libc.Int32FromInt32(2))
  22398 								mask = libc.Int32FromInt32(1) << libc.Int32FromInt32(4)
  22399 								tab = uintptr(unsafe.Pointer(&VP8Cat5))
  22400 							} else { // VP8Cat6 (11b)
  22401 								VP8PutBit(tls, bw, int32(1), int32(**(**uint8_t)(__ccgo_up(p + 8))))
  22402 								VP8PutBit(tls, bw, int32(1), int32(**(**uint8_t)(__ccgo_up(p + 10))))
  22403 								v = v - (libc.Int32FromInt32(3) + libc.Int32FromInt32(8)<<libc.Int32FromInt32(3))
  22404 								mask = libc.Int32FromInt32(1) << libc.Int32FromInt32(10)
  22405 								tab = uintptr(unsafe.Pointer(&VP8Cat6))
  22406 							}
  22407 						}
  22408 					}
  22409 					for mask != 0 {
  22410 						v3 = tab
  22411 						tab = tab + 1
  22412 						VP8PutBit(tls, bw, libc.BoolInt32(!!(v&mask != 0)), int32(**(**uint8_t)(__ccgo_up(v3))))
  22413 						mask = mask >> int32(1)
  22414 					}
  22415 				}
  22416 			}
  22417 			p = (*VP8Residual)(unsafe.Pointer(res)).Fprob + uintptr(VP8EncBands[n])*33 + 2*11
  22418 		}
  22419 		VP8PutBitUniform(tls, bw, sign)
  22420 		if n == int32(16) || !(VP8PutBit(tls, bw, libc.BoolInt32(n <= (*VP8Residual)(unsafe.Pointer(res)).Flast), int32(**(**uint8_t)(__ccgo_up(p)))) != 0) {
  22421 			return int32(1) // EOB
  22422 		}
  22423 	}
  22424 	return int32(1)
  22425 }
  22426 
  22427 func CodeResiduals(tls *libc.TLS, bw1 uintptr, it uintptr, rd uintptr) {
  22428 	bp := tls.Alloc(48)
  22429 	defer tls.Free(48)
  22430 	var ch, ctx, ctx1, i16, segment, x, y, v4 int32
  22431 	var enc, v1 uintptr
  22432 	var nb_bits, pos1, pos2, pos3, v2 uint64_t
  22433 	var _ /* res at bp+0 */ VP8Residual
  22434 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = ch, ctx, ctx1, enc, i16, nb_bits, pos1, pos2, pos3, segment, x, y, v1, v2, v4
  22435 	i16 = libc.BoolInt32(int32(uint32(*(*uint8)(unsafe.Pointer((*VP8EncIterator)(unsafe.Pointer(it)).Fmb + 0))&0x3>>0)) == libc.Int32FromInt32(1))
  22436 	segment = int32(uint32(*(*uint8)(unsafe.Pointer((*VP8EncIterator)(unsafe.Pointer(it)).Fmb + 0)) & 0x60 >> 5))
  22437 	enc = (*VP8EncIterator)(unsafe.Pointer(it)).Fenc
  22438 	VP8IteratorNzToBytes(tls, it)
  22439 	v1 = bw1
  22440 	nb_bits = uint64(int32(8) + (*VP8BitWriter)(unsafe.Pointer(v1)).Fnb_bits)
  22441 	v2 = ((*VP8BitWriter)(unsafe.Pointer(v1)).Fpos+uint64((*VP8BitWriter)(unsafe.Pointer(v1)).Frun))*uint64(8) + nb_bits
  22442 	goto _3
  22443 _3:
  22444 	pos1 = v2
  22445 	if i16 != 0 {
  22446 		VP8InitResidual(tls, 0, int32(1), enc, bp)
  22447 		(*(*func(*libc.TLS, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8SetResidualCoeffs})))(tls, rd+40, bp)
  22448 		v4 = PutCoeffs(tls, bw1, **(**int32)(__ccgo_up(it + 132 + 8*4))+**(**int32)(__ccgo_up(it + 168 + 8*4)), bp)
  22449 		**(**int32)(__ccgo_up(it + 168 + 8*4)) = v4
  22450 		**(**int32)(__ccgo_up(it + 132 + 8*4)) = v4
  22451 		VP8InitResidual(tls, int32(1), 0, enc, bp)
  22452 	} else {
  22453 		VP8InitResidual(tls, 0, int32(3), enc, bp)
  22454 	}
  22455 	// luma-AC
  22456 	y = 0
  22457 	for {
  22458 		if !(y < int32(4)) {
  22459 			break
  22460 		}
  22461 		x = 0
  22462 		for {
  22463 			if !(x < int32(4)) {
  22464 				break
  22465 			}
  22466 			ctx = **(**int32)(__ccgo_up(it + 132 + uintptr(x)*4)) + **(**int32)(__ccgo_up(it + 168 + uintptr(y)*4))
  22467 			(*(*func(*libc.TLS, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8SetResidualCoeffs})))(tls, rd+72+uintptr(x+y*int32(4))*32, bp)
  22468 			v4 = PutCoeffs(tls, bw1, ctx, bp)
  22469 			**(**int32)(__ccgo_up(it + 168 + uintptr(y)*4)) = v4
  22470 			**(**int32)(__ccgo_up(it + 132 + uintptr(x)*4)) = v4
  22471 			goto _6
  22472 		_6:
  22473 			;
  22474 			x = x + 1
  22475 		}
  22476 		goto _5
  22477 	_5:
  22478 		;
  22479 		y = y + 1
  22480 	}
  22481 	v1 = bw1
  22482 	nb_bits = uint64(int32(8) + (*VP8BitWriter)(unsafe.Pointer(v1)).Fnb_bits)
  22483 	v2 = ((*VP8BitWriter)(unsafe.Pointer(v1)).Fpos+uint64((*VP8BitWriter)(unsafe.Pointer(v1)).Frun))*uint64(8) + nb_bits
  22484 	goto _10
  22485 _10:
  22486 	pos2 = v2
  22487 	// U/V
  22488 	VP8InitResidual(tls, 0, int32(2), enc, bp)
  22489 	ch = 0
  22490 	for {
  22491 		if !(ch <= int32(2)) {
  22492 			break
  22493 		}
  22494 		y = 0
  22495 		for {
  22496 			if !(y < int32(2)) {
  22497 				break
  22498 			}
  22499 			x = 0
  22500 			for {
  22501 				if !(x < int32(2)) {
  22502 					break
  22503 				}
  22504 				ctx1 = **(**int32)(__ccgo_up(it + 132 + uintptr(int32(4)+ch+x)*4)) + **(**int32)(__ccgo_up(it + 168 + uintptr(int32(4)+ch+y)*4))
  22505 				(*(*func(*libc.TLS, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8SetResidualCoeffs})))(tls, rd+584+uintptr(ch*int32(2)+x+y*int32(2))*32, bp)
  22506 				v4 = PutCoeffs(tls, bw1, ctx1, bp)
  22507 				**(**int32)(__ccgo_up(it + 168 + uintptr(int32(4)+ch+y)*4)) = v4
  22508 				**(**int32)(__ccgo_up(it + 132 + uintptr(int32(4)+ch+x)*4)) = v4
  22509 				goto _13
  22510 			_13:
  22511 				;
  22512 				x = x + 1
  22513 			}
  22514 			goto _12
  22515 		_12:
  22516 			;
  22517 			y = y + 1
  22518 		}
  22519 		goto _11
  22520 	_11:
  22521 		;
  22522 		ch = ch + int32(2)
  22523 	}
  22524 	v1 = bw1
  22525 	nb_bits = uint64(int32(8) + (*VP8BitWriter)(unsafe.Pointer(v1)).Fnb_bits)
  22526 	v2 = ((*VP8BitWriter)(unsafe.Pointer(v1)).Fpos+uint64((*VP8BitWriter)(unsafe.Pointer(v1)).Frun))*uint64(8) + nb_bits
  22527 	goto _17
  22528 _17:
  22529 	pos3 = v2
  22530 	(*VP8EncIterator)(unsafe.Pointer(it)).Fluma_bits = pos2 - pos1
  22531 	(*VP8EncIterator)(unsafe.Pointer(it)).Fuv_bits = pos3 - pos2
  22532 	**(**uint64_t)(__ccgo_up(it + 208 + uintptr(segment)*24 + uintptr(i16)*8)) += (*VP8EncIterator)(unsafe.Pointer(it)).Fluma_bits
  22533 	**(**uint64_t)(__ccgo_up(it + 208 + uintptr(segment)*24 + 2*8)) += (*VP8EncIterator)(unsafe.Pointer(it)).Fuv_bits
  22534 	VP8IteratorBytesToNz(tls, it)
  22535 }
  22536 
  22537 // C documentation
  22538 //
  22539 //	// Same as CodeResiduals, but doesn't actually write anything.
  22540 //	// Instead, it just records the event distribution.
  22541 func RecordResiduals(tls *libc.TLS, it uintptr, rd uintptr) {
  22542 	bp := tls.Alloc(48)
  22543 	defer tls.Free(48)
  22544 	var ch, ctx, ctx1, x, y, v1 int32
  22545 	var enc uintptr
  22546 	var _ /* res at bp+0 */ VP8Residual
  22547 	_, _, _, _, _, _, _ = ch, ctx, ctx1, enc, x, y, v1
  22548 	enc = (*VP8EncIterator)(unsafe.Pointer(it)).Fenc
  22549 	VP8IteratorNzToBytes(tls, it)
  22550 	if int32(uint32(*(*uint8)(unsafe.Pointer((*VP8EncIterator)(unsafe.Pointer(it)).Fmb + 0))&0x3>>0)) == int32(1) { // i16x16
  22551 		VP8InitResidual(tls, 0, int32(1), enc, bp)
  22552 		(*(*func(*libc.TLS, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8SetResidualCoeffs})))(tls, rd+40, bp)
  22553 		v1 = VP8RecordCoeffs(tls, **(**int32)(__ccgo_up(it + 132 + 8*4))+**(**int32)(__ccgo_up(it + 168 + 8*4)), bp)
  22554 		**(**int32)(__ccgo_up(it + 168 + 8*4)) = v1
  22555 		**(**int32)(__ccgo_up(it + 132 + 8*4)) = v1
  22556 		VP8InitResidual(tls, int32(1), 0, enc, bp)
  22557 	} else {
  22558 		VP8InitResidual(tls, 0, int32(3), enc, bp)
  22559 	}
  22560 	// luma-AC
  22561 	y = 0
  22562 	for {
  22563 		if !(y < int32(4)) {
  22564 			break
  22565 		}
  22566 		x = 0
  22567 		for {
  22568 			if !(x < int32(4)) {
  22569 				break
  22570 			}
  22571 			ctx = **(**int32)(__ccgo_up(it + 132 + uintptr(x)*4)) + **(**int32)(__ccgo_up(it + 168 + uintptr(y)*4))
  22572 			(*(*func(*libc.TLS, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8SetResidualCoeffs})))(tls, rd+72+uintptr(x+y*int32(4))*32, bp)
  22573 			v1 = VP8RecordCoeffs(tls, ctx, bp)
  22574 			**(**int32)(__ccgo_up(it + 168 + uintptr(y)*4)) = v1
  22575 			**(**int32)(__ccgo_up(it + 132 + uintptr(x)*4)) = v1
  22576 			goto _3
  22577 		_3:
  22578 			;
  22579 			x = x + 1
  22580 		}
  22581 		goto _2
  22582 	_2:
  22583 		;
  22584 		y = y + 1
  22585 	}
  22586 	// U/V
  22587 	VP8InitResidual(tls, 0, int32(2), enc, bp)
  22588 	ch = 0
  22589 	for {
  22590 		if !(ch <= int32(2)) {
  22591 			break
  22592 		}
  22593 		y = 0
  22594 		for {
  22595 			if !(y < int32(2)) {
  22596 				break
  22597 			}
  22598 			x = 0
  22599 			for {
  22600 				if !(x < int32(2)) {
  22601 					break
  22602 				}
  22603 				ctx1 = **(**int32)(__ccgo_up(it + 132 + uintptr(int32(4)+ch+x)*4)) + **(**int32)(__ccgo_up(it + 168 + uintptr(int32(4)+ch+y)*4))
  22604 				(*(*func(*libc.TLS, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8SetResidualCoeffs})))(tls, rd+584+uintptr(ch*int32(2)+x+y*int32(2))*32, bp)
  22605 				v1 = VP8RecordCoeffs(tls, ctx1, bp)
  22606 				**(**int32)(__ccgo_up(it + 168 + uintptr(int32(4)+ch+y)*4)) = v1
  22607 				**(**int32)(__ccgo_up(it + 132 + uintptr(int32(4)+ch+x)*4)) = v1
  22608 				goto _7
  22609 			_7:
  22610 				;
  22611 				x = x + 1
  22612 			}
  22613 			goto _6
  22614 		_6:
  22615 			;
  22616 			y = y + 1
  22617 		}
  22618 		goto _5
  22619 	_5:
  22620 		;
  22621 		ch = ch + int32(2)
  22622 	}
  22623 	VP8IteratorBytesToNz(tls, it)
  22624 }
  22625 
  22626 //------------------------------------------------------------------------------
  22627 // Token buffer
  22628 
  22629 func RecordTokens(tls *libc.TLS, it uintptr, rd uintptr, tokens uintptr) (r int32) {
  22630 	bp := tls.Alloc(48)
  22631 	defer tls.Free(48)
  22632 	var ch, ctx, ctx1, ctx2, x, y, v1 int32
  22633 	var enc uintptr
  22634 	var _ /* res at bp+0 */ VP8Residual
  22635 	_, _, _, _, _, _, _, _ = ch, ctx, ctx1, ctx2, enc, x, y, v1
  22636 	enc = (*VP8EncIterator)(unsafe.Pointer(it)).Fenc
  22637 	VP8IteratorNzToBytes(tls, it)
  22638 	if int32(uint32(*(*uint8)(unsafe.Pointer((*VP8EncIterator)(unsafe.Pointer(it)).Fmb + 0))&0x3>>0)) == int32(1) { // i16x16
  22639 		ctx = **(**int32)(__ccgo_up(it + 132 + 8*4)) + **(**int32)(__ccgo_up(it + 168 + 8*4))
  22640 		VP8InitResidual(tls, 0, int32(1), enc, bp)
  22641 		(*(*func(*libc.TLS, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8SetResidualCoeffs})))(tls, rd+40, bp)
  22642 		v1 = VP8RecordCoeffTokens(tls, ctx, bp, tokens)
  22643 		**(**int32)(__ccgo_up(it + 168 + 8*4)) = v1
  22644 		**(**int32)(__ccgo_up(it + 132 + 8*4)) = v1
  22645 		VP8InitResidual(tls, int32(1), 0, enc, bp)
  22646 	} else {
  22647 		VP8InitResidual(tls, 0, int32(3), enc, bp)
  22648 	}
  22649 	// luma-AC
  22650 	y = 0
  22651 	for {
  22652 		if !(y < int32(4)) {
  22653 			break
  22654 		}
  22655 		x = 0
  22656 		for {
  22657 			if !(x < int32(4)) {
  22658 				break
  22659 			}
  22660 			ctx1 = **(**int32)(__ccgo_up(it + 132 + uintptr(x)*4)) + **(**int32)(__ccgo_up(it + 168 + uintptr(y)*4))
  22661 			(*(*func(*libc.TLS, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8SetResidualCoeffs})))(tls, rd+72+uintptr(x+y*int32(4))*32, bp)
  22662 			v1 = VP8RecordCoeffTokens(tls, ctx1, bp, tokens)
  22663 			**(**int32)(__ccgo_up(it + 168 + uintptr(y)*4)) = v1
  22664 			**(**int32)(__ccgo_up(it + 132 + uintptr(x)*4)) = v1
  22665 			goto _3
  22666 		_3:
  22667 			;
  22668 			x = x + 1
  22669 		}
  22670 		goto _2
  22671 	_2:
  22672 		;
  22673 		y = y + 1
  22674 	}
  22675 	// U/V
  22676 	VP8InitResidual(tls, 0, int32(2), enc, bp)
  22677 	ch = 0
  22678 	for {
  22679 		if !(ch <= int32(2)) {
  22680 			break
  22681 		}
  22682 		y = 0
  22683 		for {
  22684 			if !(y < int32(2)) {
  22685 				break
  22686 			}
  22687 			x = 0
  22688 			for {
  22689 				if !(x < int32(2)) {
  22690 					break
  22691 				}
  22692 				ctx2 = **(**int32)(__ccgo_up(it + 132 + uintptr(int32(4)+ch+x)*4)) + **(**int32)(__ccgo_up(it + 168 + uintptr(int32(4)+ch+y)*4))
  22693 				(*(*func(*libc.TLS, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8SetResidualCoeffs})))(tls, rd+584+uintptr(ch*int32(2)+x+y*int32(2))*32, bp)
  22694 				v1 = VP8RecordCoeffTokens(tls, ctx2, bp, tokens)
  22695 				**(**int32)(__ccgo_up(it + 168 + uintptr(int32(4)+ch+y)*4)) = v1
  22696 				**(**int32)(__ccgo_up(it + 132 + uintptr(int32(4)+ch+x)*4)) = v1
  22697 				goto _7
  22698 			_7:
  22699 				;
  22700 				x = x + 1
  22701 			}
  22702 			goto _6
  22703 		_6:
  22704 			;
  22705 			y = y + 1
  22706 		}
  22707 		goto _5
  22708 	_5:
  22709 		;
  22710 		ch = ch + int32(2)
  22711 	}
  22712 	VP8IteratorBytesToNz(tls, it)
  22713 	return libc.BoolInt32(!((*VP8TBuffer)(unsafe.Pointer(tokens)).Ferror1 != 0))
  22714 }
  22715 
  22716 //------------------------------------------------------------------------------
  22717 // ExtraInfo map / Debug function
  22718 
  22719 func ResetSSE(tls *libc.TLS, enc uintptr) {
  22720 	**(**uint64_t)(__ccgo_up(enc + 23512)) = uint64(0)
  22721 	**(**uint64_t)(__ccgo_up(enc + 23512 + 1*8)) = uint64(0)
  22722 	**(**uint64_t)(__ccgo_up(enc + 23512 + 2*8)) = uint64(0)
  22723 	// Note: enc->sse[3] is managed by alpha.c
  22724 	(*VP8Encoder)(unsafe.Pointer(enc)).Fsse_count = uint64(0)
  22725 }
  22726 
  22727 func StoreSSE(tls *libc.TLS, it uintptr) {
  22728 	var enc, in, out uintptr
  22729 	_, _, _ = enc, in, out
  22730 	enc = (*VP8EncIterator)(unsafe.Pointer(it)).Fenc
  22731 	in = (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_in
  22732 	out = (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_out
  22733 	// Note: not totally accurate at boundary. And doesn't include in-loop filter.
  22734 	**(**uint64_t)(__ccgo_up(enc + 23512)) += uint64((*(*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))))
  22735 	**(**uint64_t)(__ccgo_up(enc + 23512 + 1*8)) += uint64((*(*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))))
  22736 	**(**uint64_t)(__ccgo_up(enc + 23512 + 2*8)) += uint64((*(*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))))
  22737 	**(**uint64_t)(__ccgo_up(enc + 23544)) += uint64(libc.Int32FromInt32(16) * libc.Int32FromInt32(16))
  22738 }
  22739 
  22740 func StoreSideInfo(tls *libc.TLS, it uintptr) {
  22741 	var b, v1 int32
  22742 	var enc, info, mb, pic uintptr
  22743 	_, _, _, _, _, _ = b, enc, info, mb, pic, v1
  22744 	enc = (*VP8EncIterator)(unsafe.Pointer(it)).Fenc
  22745 	mb = (*VP8EncIterator)(unsafe.Pointer(it)).Fmb
  22746 	pic = (*VP8Encoder)(unsafe.Pointer(enc)).Fpic
  22747 	if (*WebPPicture)(unsafe.Pointer(pic)).Fstats != libc.UintptrFromInt32(0) {
  22748 		StoreSSE(tls, it)
  22749 		**(**int32)(__ccgo_up(enc + 23604)) += libc.BoolInt32(int32(uint32(*(*uint8)(unsafe.Pointer(mb + 0))&0x3>>0)) == 0)
  22750 		**(**int32)(__ccgo_up(enc + 23604 + 1*4)) += libc.BoolInt32(int32(uint32(*(*uint8)(unsafe.Pointer(mb + 0))&0x3>>0)) == int32(1))
  22751 		**(**int32)(__ccgo_up(enc + 23604 + 2*4)) += libc.BoolInt32(int32(uint32(*(*uint8)(unsafe.Pointer(mb + 0))&0x10>>4)) != 0)
  22752 	}
  22753 	if (*WebPPicture)(unsafe.Pointer(pic)).Fextra_info != libc.UintptrFromInt32(0) {
  22754 		info = (*WebPPicture)(unsafe.Pointer(pic)).Fextra_info + uintptr((*VP8EncIterator)(unsafe.Pointer(it)).Fx+(*VP8EncIterator)(unsafe.Pointer(it)).Fy*(*VP8Encoder)(unsafe.Pointer(enc)).Fmb_w)
  22755 		switch (*WebPPicture)(unsafe.Pointer(pic)).Fextra_info_type {
  22756 		case int32(1):
  22757 			**(**uint8_t)(__ccgo_up(info)) = uint8(int32(uint32(*(*uint8)(unsafe.Pointer(mb + 0)) & 0x3 >> 0)))
  22758 		case int32(2):
  22759 			**(**uint8_t)(__ccgo_up(info)) = uint8(int32(uint32(*(*uint8)(unsafe.Pointer(mb + 0)) & 0x60 >> 5)))
  22760 		case int32(3):
  22761 			**(**uint8_t)(__ccgo_up(info)) = uint8((**(**VP8SegmentInfo)(__ccgo_up(enc + 608 + uintptr(int32(uint32(*(*uint8)(unsafe.Pointer(mb + 0))&0x60>>5)))*744))).Fquant)
  22762 		case int32(4):
  22763 			if int32(uint32(*(*uint8)(unsafe.Pointer(mb + 0))&0x3>>0)) == int32(1) {
  22764 				v1 = int32(**(**uint8_t)(__ccgo_up((*VP8EncIterator)(unsafe.Pointer(it)).Fpreds)))
  22765 			} else {
  22766 				v1 = int32(0xff)
  22767 			}
  22768 			**(**uint8_t)(__ccgo_up(info)) = uint8(v1)
  22769 		case int32(5):
  22770 			**(**uint8_t)(__ccgo_up(info)) = uint8(int32(uint32(*(*uint8)(unsafe.Pointer(mb + 0)) & 0xc >> 2)))
  22771 		case int32(6):
  22772 			b = int32(((*VP8EncIterator)(unsafe.Pointer(it)).Fluma_bits + (*VP8EncIterator)(unsafe.Pointer(it)).Fuv_bits + libc.Uint64FromInt32(7)) >> libc.Int32FromInt32(3))
  22773 			if b > int32(255) {
  22774 				v1 = int32(255)
  22775 			} else {
  22776 				v1 = b
  22777 			}
  22778 			**(**uint8_t)(__ccgo_up(info)) = uint8(v1)
  22779 		case int32(7):
  22780 			**(**uint8_t)(__ccgo_up(info)) = (*VP8MBInfo)(unsafe.Pointer(mb)).Falpha
  22781 		default:
  22782 			**(**uint8_t)(__ccgo_up(info)) = uint8(0)
  22783 			break
  22784 		}
  22785 	}
  22786 }
  22787 
  22788 func ResetSideInfo(tls *libc.TLS, it uintptr) {
  22789 	var enc, pic uintptr
  22790 	_, _ = enc, pic
  22791 	enc = (*VP8EncIterator)(unsafe.Pointer(it)).Fenc
  22792 	pic = (*VP8Encoder)(unsafe.Pointer(enc)).Fpic
  22793 	if (*WebPPicture)(unsafe.Pointer(pic)).Fstats != libc.UintptrFromInt32(0) {
  22794 		libc.Xmemset(tls, enc+23604, 0, uint64(12))
  22795 	}
  22796 	ResetSSE(tls, enc)
  22797 }
  22798 
  22799 func GetPSNR(tls *libc.TLS, mse uint64_t, size uint64_t) (r float64) {
  22800 	var v1 float64
  22801 	_ = v1
  22802 	if mse > uint64(0) && size > uint64(0) {
  22803 		v1 = float64(float64(10) * libc.Xlog10(tls, float64(float64(libc.Float64FromFloat64(255)*libc.Float64FromFloat64(255))*float64(size))/float64(mse)))
  22804 	} else {
  22805 		v1 = libc.Float64FromInt32(99)
  22806 	}
  22807 	return v1
  22808 }
  22809 
  22810 //------------------------------------------------------------------------------
  22811 //  StatLoop(): only collect statistics (number of skips, token usage, ...).
  22812 //  This is used for deciding optimal probabilities. It also modifies the
  22813 //  quantizer value if some target (size, PSNR) was specified.
  22814 
  22815 func SetLoopParams(tls *libc.TLS, enc uintptr, q float32) {
  22816 	// Make sure the quality parameter is inside valid bounds
  22817 	q = Clamp(tls, q, libc.Float32FromFloat32(0), libc.Float32FromFloat32(100))
  22818 	VP8SetSegmentParams(tls, enc, q) // setup segment quantizations and filters
  22819 	SetSegmentProbas(tls, enc)       // compute segment probabilities
  22820 	ResetStats(tls, enc)
  22821 	ResetSSE(tls, enc)
  22822 }
  22823 
  22824 func OneStatPass(tls *libc.TLS, enc uintptr, rd_opt VP8RDLevel, nb_mbs int32, percent_delta int32, s uintptr) (r uint64_t) {
  22825 	bp := tls.Alloc(4736)
  22826 	defer tls.Free(4736)
  22827 	var distortion, pixel_count, size, size_p0 uint64_t
  22828 	var v1 int32
  22829 	var v2 bool
  22830 	var _ /* info at bp+3848 */ VP8ModeScore
  22831 	var _ /* it at bp+0 */ VP8EncIterator
  22832 	_, _, _, _, _, _ = distortion, pixel_count, size, size_p0, v1, v2
  22833 	size = uint64(0)
  22834 	size_p0 = uint64(0)
  22835 	distortion = uint64(0)
  22836 	pixel_count = uint64(nb_mbs) * uint64(384)
  22837 	VP8IteratorInit(tls, enc, bp)
  22838 	SetLoopParams(tls, enc, (*PassStats)(unsafe.Pointer(s)).Fq)
  22839 	for {
  22840 		VP8IteratorImport(tls, bp, libc.UintptrFromInt32(0))
  22841 		if VP8Decimate(tls, bp, bp+3848, rd_opt) != 0 {
  22842 			// Just record the number of skips and act like skip_proba is not used.
  22843 			(*VP8Encoder)(unsafe.Pointer(enc)).Fproba.Fnb_skip = (*VP8Encoder)(unsafe.Pointer(enc)).Fproba.Fnb_skip + 1
  22844 		}
  22845 		RecordResiduals(tls, bp, bp+3848)
  22846 		size = size + uint64((**(**VP8ModeScore)(__ccgo_up(bp + 3848))).FR+(**(**VP8ModeScore)(__ccgo_up(bp + 3848))).FH)
  22847 		size_p0 = size_p0 + uint64((**(**VP8ModeScore)(__ccgo_up(bp + 3848))).FH)
  22848 		distortion = distortion + uint64((**(**VP8ModeScore)(__ccgo_up(bp + 3848))).FD)
  22849 		if percent_delta != 0 && !(VP8IteratorProgress(tls, bp, percent_delta) != 0) {
  22850 			return uint64(0)
  22851 		}
  22852 		VP8IteratorSaveBoundary(tls, bp)
  22853 		goto _3
  22854 	_3:
  22855 		;
  22856 		if v2 = VP8IteratorNext(tls, bp) != 0; v2 {
  22857 			nb_mbs = nb_mbs - 1
  22858 			v1 = nb_mbs
  22859 		}
  22860 		if !(v2 && v1 > 0) {
  22861 			break
  22862 		}
  22863 	}
  22864 	size_p0 = size_p0 + uint64((*VP8Encoder)(unsafe.Pointer(enc)).Fsegment_hdr.Fsize)
  22865 	if (*PassStats)(unsafe.Pointer(s)).Fdo_size_search != 0 {
  22866 		size = size + uint64(FinalizeSkipProba(tls, enc))
  22867 		size = size + uint64(FinalizeTokenProbas(tls, enc+3616))
  22868 		size = (size+size_p0+uint64(1024))>>int32(11) + uint64(libc.Int32FromInt32(RIFF_HEADER_SIZE)+libc.Int32FromInt32(CHUNK_HEADER_SIZE)+libc.Int32FromInt32(VP8_FRAME_HEADER_SIZE))
  22869 		(*PassStats)(unsafe.Pointer(s)).Fvalue = float64(size)
  22870 	} else {
  22871 		(*PassStats)(unsafe.Pointer(s)).Fvalue = GetPSNR(tls, distortion, pixel_count)
  22872 	}
  22873 	return size_p0
  22874 }
  22875 
  22876 func StatLoop(tls *libc.TLS, enc uintptr) (r int32) {
  22877 	bp := tls.Alloc(64)
  22878 	defer tls.Free(64)
  22879 	var do_search, fast_probe, final_percent, is_last_pass, method, nb_mbs, num_pass_left, percent_per_pass, task_percent, v1 int32
  22880 	var rd_opt VP8RDLevel
  22881 	var size_p0 uint64_t
  22882 	var _ /* stats at bp+0 */ PassStats
  22883 	_, _, _, _, _, _, _, _, _, _, _, _ = 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
  22884 	method = (*VP8Encoder)(unsafe.Pointer(enc)).Fmethod
  22885 	do_search = (*VP8Encoder)(unsafe.Pointer(enc)).Fdo_search
  22886 	fast_probe = libc.BoolInt32((method == 0 || method == int32(3)) && !(do_search != 0))
  22887 	num_pass_left = (*WebPConfig)(unsafe.Pointer((*VP8Encoder)(unsafe.Pointer(enc)).Fconfig)).Fpass
  22888 	task_percent = int32(20)
  22889 	percent_per_pass = (task_percent + num_pass_left/int32(2)) / num_pass_left
  22890 	final_percent = (*VP8Encoder)(unsafe.Pointer(enc)).Fpercent + task_percent
  22891 	if method >= int32(3) || do_search != 0 {
  22892 		v1 = int32(RD_OPT_BASIC)
  22893 	} else {
  22894 		v1 = int32(RD_OPT_NONE)
  22895 	}
  22896 	rd_opt = v1
  22897 	nb_mbs = (*VP8Encoder)(unsafe.Pointer(enc)).Fmb_w * (*VP8Encoder)(unsafe.Pointer(enc)).Fmb_h
  22898 	InitPassStats(tls, enc, bp)
  22899 	ResetTokenStats(tls, enc)
  22900 	// Fast mode: quick analysis pass over few mbs. Better than nothing.
  22901 	if fast_probe != 0 {
  22902 		if method == int32(3) { // we need more stats for method 3 to be reliable.
  22903 			if nb_mbs > int32(200) {
  22904 				v1 = nb_mbs >> int32(1)
  22905 			} else {
  22906 				v1 = int32(100)
  22907 			}
  22908 			nb_mbs = v1
  22909 		} else {
  22910 			if nb_mbs > int32(200) {
  22911 				v1 = nb_mbs >> int32(2)
  22912 			} else {
  22913 				v1 = int32(50)
  22914 			}
  22915 			nb_mbs = v1
  22916 		}
  22917 	}
  22918 	for {
  22919 		v1 = num_pass_left
  22920 		num_pass_left = num_pass_left - 1
  22921 		if !(v1 > 0) {
  22922 			break
  22923 		}
  22924 		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)
  22925 		size_p0 = OneStatPass(tls, enc, rd_opt, nb_mbs, percent_per_pass, bp)
  22926 		if size_p0 == uint64(0) {
  22927 			return 0
  22928 		}
  22929 		if (*VP8Encoder)(unsafe.Pointer(enc)).Fmax_i4_header_bits > 0 && size_p0 > (uint64(libc.Int32FromInt32(1)<<libc.Int32FromInt32(19))-libc.Uint64FromUint64(2048))<<libc.Int32FromInt32(11) {
  22930 			num_pass_left = num_pass_left + 1
  22931 			**(**int32)(__ccgo_up(enc + 23624)) >>= int32(1) // strengthen header bit limitation...
  22932 			continue                                         // ...and start over
  22933 		}
  22934 		if is_last_pass != 0 {
  22935 			break
  22936 		}
  22937 		// If no target size: just do several pass without changing 'q'
  22938 		if do_search != 0 {
  22939 			ComputeNextQ(tls, bp)
  22940 			if libc.Xfabs(tls, float64((**(**PassStats)(__ccgo_up(bp))).Fdq)) <= float64(DQ_LIMIT) {
  22941 				break
  22942 			}
  22943 		}
  22944 	}
  22945 	if !(do_search != 0) || !((**(**PassStats)(__ccgo_up(bp))).Fdo_size_search != 0) {
  22946 		// Need to finalize probas now, since it wasn't done during the search.
  22947 		FinalizeSkipProba(tls, enc)
  22948 		FinalizeTokenProbas(tls, enc+3616)
  22949 	}
  22950 	VP8CalculateLevelCosts(tls, enc+3616) // finalize costs
  22951 	return WebPReportProgress(tls, (*VP8Encoder)(unsafe.Pointer(enc)).Fpic, final_percent, enc+536)
  22952 }
  22953 
  22954 //------------------------------------------------------------------------------
  22955 // Main loops
  22956 //
  22957 
  22958 var kAverageBytesPerMB = [8]uint8_t{
  22959 	0: uint8(50),
  22960 	1: uint8(24),
  22961 	2: uint8(16),
  22962 	3: uint8(9),
  22963 	4: uint8(7),
  22964 	5: uint8(5),
  22965 	6: uint8(3),
  22966 	7: uint8(2),
  22967 }
  22968 
  22969 func PreLoopInitialize(tls *libc.TLS, enc uintptr) (r int32) {
  22970 	var average_bytes_per_MB, bytes_per_parts, ok, p int32
  22971 	_, _, _, _ = average_bytes_per_MB, bytes_per_parts, ok, p
  22972 	ok = int32(1)
  22973 	average_bytes_per_MB = int32(kAverageBytesPerMB[(*VP8Encoder)(unsafe.Pointer(enc)).Fbase_quant>>int32(4)])
  22974 	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
  22975 	// Initialize the bit-writers
  22976 	p = 0
  22977 	for {
  22978 		if !(ok != 0 && p < (*VP8Encoder)(unsafe.Pointer(enc)).Fnum_parts) {
  22979 			break
  22980 		}
  22981 		ok = VP8BitWriterInit(tls, enc+112+uintptr(p)*48, uint64(bytes_per_parts))
  22982 		goto _1
  22983 	_1:
  22984 		;
  22985 		p = p + 1
  22986 	}
  22987 	if !(ok != 0) {
  22988 		VP8EncFreeBitWriters(tls, enc) // malloc error occurred
  22989 		return WebPEncodingSetError(tls, (*VP8Encoder)(unsafe.Pointer(enc)).Fpic, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  22990 	}
  22991 	return ok
  22992 }
  22993 
  22994 func PostLoopFinalize(tls *libc.TLS, it uintptr, ok int32) (r int32) {
  22995 	var enc uintptr
  22996 	var i, p, s int32
  22997 	_, _, _, _ = enc, i, p, s
  22998 	enc = (*VP8EncIterator)(unsafe.Pointer(it)).Fenc
  22999 	if ok != 0 {
  23000 		p = 0
  23001 		for {
  23002 			if !(p < (*VP8Encoder)(unsafe.Pointer(enc)).Fnum_parts) {
  23003 				break
  23004 			}
  23005 			VP8BitWriterFinish(tls, enc+112+uintptr(p)*48)
  23006 			ok = ok & libc.BoolInt32(!((**(**VP8BitWriter)(__ccgo_up(enc + 112 + uintptr(p)*48))).Ferror1 != 0))
  23007 			goto _1
  23008 		_1:
  23009 			;
  23010 			p = p + 1
  23011 		}
  23012 	}
  23013 	if ok != 0 { // All good. Finish up.
  23014 		if (*WebPPicture)(unsafe.Pointer((*VP8Encoder)(unsafe.Pointer(enc)).Fpic)).Fstats != libc.UintptrFromInt32(0) {
  23015 			i = 0
  23016 			for {
  23017 				if !(i <= int32(2)) {
  23018 					break
  23019 				}
  23020 				s = 0
  23021 				for {
  23022 					if !(s < int32(NUM_MB_SEGMENTS)) {
  23023 						break
  23024 					}
  23025 					**(**int32)(__ccgo_up(enc + 23556 + uintptr(i)*16 + uintptr(s)*4)) = int32((**(**uint64_t)(__ccgo_up(it + 208 + uintptr(s)*24 + uintptr(i)*8)) + libc.Uint64FromInt32(7)) >> libc.Int32FromInt32(3))
  23026 					goto _3
  23027 				_3:
  23028 					;
  23029 					s = s + 1
  23030 				}
  23031 				goto _2
  23032 			_2:
  23033 				;
  23034 				i = i + 1
  23035 			}
  23036 		}
  23037 		VP8AdjustFilterStrength(tls, it) // ...and store filter stats.
  23038 	} else {
  23039 		// Something bad happened -> need to do some memory cleanup.
  23040 		VP8EncFreeBitWriters(tls, enc)
  23041 		return WebPEncodingSetError(tls, (*VP8Encoder)(unsafe.Pointer(enc)).Fpic, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  23042 	}
  23043 	return ok
  23044 }
  23045 
  23046 //------------------------------------------------------------------------------
  23047 //  VP8EncLoop(): does the final bitstream coding.
  23048 
  23049 func ResetAfterSkip(tls *libc.TLS, it uintptr) {
  23050 	if int32(uint32(*(*uint8)(unsafe.Pointer((*VP8EncIterator)(unsafe.Pointer(it)).Fmb + 0))&0x3>>0)) == int32(1) {
  23051 		**(**uint32_t)(__ccgo_up((*VP8EncIterator)(unsafe.Pointer(it)).Fnz)) = uint32(0) // reset all predictors
  23052 		**(**int32)(__ccgo_up(it + 168 + 8*4)) = 0
  23053 	} else {
  23054 		**(**uint32_t)(__ccgo_up((*VP8EncIterator)(unsafe.Pointer(it)).Fnz)) &= uint32(libc.Int32FromInt32(1) << libc.Int32FromInt32(24)) // preserve the dc_nz bit
  23055 	}
  23056 }
  23057 
  23058 func VP8EncLoop(tls *libc.TLS, enc uintptr) (r int32) {
  23059 	bp := tls.Alloc(4736)
  23060 	defer tls.Free(4736)
  23061 	var dont_use_skip, ok int32
  23062 	var rd_opt VP8RDLevel
  23063 	var _ /* info at bp+3848 */ VP8ModeScore
  23064 	var _ /* it at bp+0 */ VP8EncIterator
  23065 	_, _, _ = dont_use_skip, ok, rd_opt
  23066 	ok = PreLoopInitialize(tls, enc)
  23067 	if !(ok != 0) {
  23068 		return 0
  23069 	}
  23070 	StatLoop(tls, enc) // stats-collection loop
  23071 	VP8IteratorInit(tls, enc, bp)
  23072 	VP8InitFilter(tls, bp)
  23073 	for cond := true; cond; cond = ok != 0 && VP8IteratorNext(tls, bp) != 0 {
  23074 		dont_use_skip = libc.BoolInt32(!((*VP8Encoder)(unsafe.Pointer(enc)).Fproba.Fuse_skip_proba != 0))
  23075 		rd_opt = (*VP8Encoder)(unsafe.Pointer(enc)).Frd_opt_level
  23076 		VP8IteratorImport(tls, bp, libc.UintptrFromInt32(0))
  23077 		// Warning! order is important: first call VP8Decimate() and
  23078 		// *then* decide how to code the skip decision if there's one.
  23079 		if !(VP8Decimate(tls, bp, bp+3848, rd_opt) != 0) || dont_use_skip != 0 {
  23080 			CodeResiduals(tls, (**(**VP8EncIterator)(__ccgo_up(bp))).Fbw, bp, bp+3848)
  23081 			if (*VP8BitWriter)(unsafe.Pointer((**(**VP8EncIterator)(__ccgo_up(bp))).Fbw)).Ferror1 != 0 {
  23082 				// enc->pic->error_code is set in PostLoopFinalize().
  23083 				ok = 0
  23084 				break
  23085 			}
  23086 		} else { // reset predictors after a skip
  23087 			ResetAfterSkip(tls, bp)
  23088 		}
  23089 		StoreSideInfo(tls, bp)
  23090 		VP8StoreFilterStats(tls, bp)
  23091 		VP8IteratorExport(tls, bp)
  23092 		ok = VP8IteratorProgress(tls, bp, int32(20))
  23093 		VP8IteratorSaveBoundary(tls, bp)
  23094 	}
  23095 	return PostLoopFinalize(tls, bp, ok)
  23096 }
  23097 
  23098 //------------------------------------------------------------------------------
  23099 // Single pass using Token Buffer.
  23100 
  23101 func VP8EncTokenLoop(tls *libc.TLS, enc uintptr) (r int32) {
  23102 	bp := tls.Alloc(4784)
  23103 	defer tls.Free(4784)
  23104 	var cnt, do_search, is_last_pass, max_count, num_pass_left, ok, pass_progress, remaining_progress, v1 int32
  23105 	var distortion, pixel_count, size, size_p0 uint64_t
  23106 	var proba uintptr
  23107 	var rd_opt VP8RDLevel
  23108 	var v2 bool
  23109 	var _ /* info at bp+3904 */ VP8ModeScore
  23110 	var _ /* it at bp+0 */ VP8EncIterator
  23111 	var _ /* stats at bp+3848 */ PassStats
  23112 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  23113 	// Roughly refresh the proba eight times per pass
  23114 	max_count = (*VP8Encoder)(unsafe.Pointer(enc)).Fmb_w * (*VP8Encoder)(unsafe.Pointer(enc)).Fmb_h >> int32(3)
  23115 	num_pass_left = (*WebPConfig)(unsafe.Pointer((*VP8Encoder)(unsafe.Pointer(enc)).Fconfig)).Fpass
  23116 	remaining_progress = int32(40) // percents
  23117 	do_search = (*VP8Encoder)(unsafe.Pointer(enc)).Fdo_search
  23118 	proba = enc + 3616
  23119 	rd_opt = (*VP8Encoder)(unsafe.Pointer(enc)).Frd_opt_level
  23120 	pixel_count = uint64((*VP8Encoder)(unsafe.Pointer(enc)).Fmb_w) * uint64((*VP8Encoder)(unsafe.Pointer(enc)).Fmb_h) * uint64(384)
  23121 	InitPassStats(tls, enc, bp+3848)
  23122 	ok = PreLoopInitialize(tls, enc)
  23123 	if !(ok != 0) {
  23124 		return 0
  23125 	}
  23126 	if max_count < int32(MIN_COUNT) {
  23127 		max_count = int32(MIN_COUNT)
  23128 	}
  23129 	// otherwise, token-buffer won't be useful
  23130 	for {
  23131 		if v2 = ok != 0; v2 {
  23132 			v1 = num_pass_left
  23133 			num_pass_left = num_pass_left - 1
  23134 		}
  23135 		if !(v2 && v1 > 0) {
  23136 			break
  23137 		}
  23138 		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)
  23139 		size_p0 = uint64(0)
  23140 		distortion = uint64(0)
  23141 		cnt = max_count
  23142 		// The final number of passes is not trivial to know in advance.
  23143 		pass_progress = remaining_progress / (int32(2) + num_pass_left)
  23144 		remaining_progress = remaining_progress - pass_progress
  23145 		VP8IteratorInit(tls, enc, bp)
  23146 		SetLoopParams(tls, enc, (**(**PassStats)(__ccgo_up(bp + 3848))).Fq)
  23147 		if is_last_pass != 0 {
  23148 			ResetTokenStats(tls, enc)
  23149 			VP8InitFilter(tls, bp) // don't collect stats until last pass (too costly)
  23150 		}
  23151 		VP8TBufferClear(tls, enc+496)
  23152 		for cond := true; cond; cond = ok != 0 && VP8IteratorNext(tls, bp) != 0 {
  23153 			VP8IteratorImport(tls, bp, libc.UintptrFromInt32(0))
  23154 			cnt = cnt - 1
  23155 			v1 = cnt
  23156 			if v1 < 0 {
  23157 				FinalizeTokenProbas(tls, proba)
  23158 				VP8CalculateLevelCosts(tls, proba) // refresh cost tables for rd-opt
  23159 				cnt = max_count
  23160 			}
  23161 			VP8Decimate(tls, bp, bp+3904, rd_opt)
  23162 			ok = RecordTokens(tls, bp, bp+3904, enc+496)
  23163 			if !(ok != 0) {
  23164 				WebPEncodingSetError(tls, (*VP8Encoder)(unsafe.Pointer(enc)).Fpic, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  23165 				break
  23166 			}
  23167 			size_p0 = size_p0 + uint64((**(**VP8ModeScore)(__ccgo_up(bp + 3904))).FH)
  23168 			distortion = distortion + uint64((**(**VP8ModeScore)(__ccgo_up(bp + 3904))).FD)
  23169 			if is_last_pass != 0 {
  23170 				StoreSideInfo(tls, bp)
  23171 				VP8StoreFilterStats(tls, bp)
  23172 				VP8IteratorExport(tls, bp)
  23173 				ok = VP8IteratorProgress(tls, bp, pass_progress)
  23174 			}
  23175 			VP8IteratorSaveBoundary(tls, bp)
  23176 		}
  23177 		if !(ok != 0) {
  23178 			break
  23179 		}
  23180 		size_p0 = size_p0 + uint64((*VP8Encoder)(unsafe.Pointer(enc)).Fsegment_hdr.Fsize)
  23181 		if (**(**PassStats)(__ccgo_up(bp + 3848))).Fdo_size_search != 0 {
  23182 			size = uint64(FinalizeTokenProbas(tls, enc+3616))
  23183 			size = size + VP8EstimateTokenSize(tls, enc+496, proba+4)
  23184 			size = (size + size_p0 + uint64(1024)) >> int32(11) // -> size in bytes
  23185 			size = size + uint64(libc.Int32FromInt32(RIFF_HEADER_SIZE)+libc.Int32FromInt32(CHUNK_HEADER_SIZE)+libc.Int32FromInt32(VP8_FRAME_HEADER_SIZE))
  23186 			(**(**PassStats)(__ccgo_up(bp + 3848))).Fvalue = float64(size)
  23187 		} else { // compute and store PSNR
  23188 			(**(**PassStats)(__ccgo_up(bp + 3848))).Fvalue = GetPSNR(tls, distortion, pixel_count)
  23189 		}
  23190 		if (*VP8Encoder)(unsafe.Pointer(enc)).Fmax_i4_header_bits > 0 && size_p0 > (uint64(libc.Int32FromInt32(1)<<libc.Int32FromInt32(19))-libc.Uint64FromUint64(2048))<<libc.Int32FromInt32(11) {
  23191 			num_pass_left = num_pass_left + 1
  23192 			**(**int32)(__ccgo_up(enc + 23624)) >>= int32(1) // strengthen header bit limitation...
  23193 			if is_last_pass != 0 {
  23194 				ResetSideInfo(tls, bp)
  23195 			}
  23196 			continue // ...and start over
  23197 		}
  23198 		if is_last_pass != 0 {
  23199 			break // done
  23200 		}
  23201 		if do_search != 0 {
  23202 			ComputeNextQ(tls, bp+3848) // Adjust q
  23203 		}
  23204 	}
  23205 	if ok != 0 {
  23206 		if !((**(**PassStats)(__ccgo_up(bp + 3848))).Fdo_size_search != 0) {
  23207 			FinalizeTokenProbas(tls, enc+3616)
  23208 		}
  23209 		ok = VP8EmitTokens(tls, enc+496, enc+112+uintptr(0)*48, proba+4, int32(1))
  23210 	}
  23211 	ok = libc.BoolInt32(ok != 0 && WebPReportProgress(tls, (*VP8Encoder)(unsafe.Pointer(enc)).Fpic, (*VP8Encoder)(unsafe.Pointer(enc)).Fpercent+remaining_progress, enc+536) != 0)
  23212 	return PostLoopFinalize(tls, bp, ok)
  23213 }
  23214 
  23215 const MAX_HISTO_GREEDY = 100
  23216 const NUM_PARTITIONS = 4
  23217 const SIZE_MAX8 = "_UI64_MAX"
  23218 
  23219 //------------------------------------------------------------------------------
  23220 
  23221 // Copyright 2012 Google Inc. All Rights Reserved.
  23222 //
  23223 // Use of this source code is governed by a BSD-style license
  23224 // that can be found in the COPYING file in the root of the source
  23225 // tree. An additional intellectual property rights grant can be found
  23226 // in the file PATENTS. All contributing project authors may
  23227 // be found in the AUTHORS file in the root of the source tree.
  23228 // -----------------------------------------------------------------------------
  23229 //
  23230 // Misc. common utility functions
  23231 //
  23232 // Authors: Skal (pascal.massimino@gmail.com)
  23233 //          Urvang (urvang@google.com)
  23234 
  23235 // Copyright 2011 Google Inc. All Rights Reserved.
  23236 //
  23237 // Use of this source code is governed by a BSD-style license
  23238 // that can be found in the COPYING file in the root of the source
  23239 // tree. An additional intellectual property rights grant can be found
  23240 // in the file PATENTS. All contributing project authors may
  23241 // be found in the AUTHORS file in the root of the source tree.
  23242 // -----------------------------------------------------------------------------
  23243 //
  23244 //   WebP encoder: main interface
  23245 //
  23246 // Author: Skal (pascal.massimino@gmail.com)
  23247 
  23248 // Copyright 2012 Google Inc. All Rights Reserved.
  23249 //
  23250 // Use of this source code is governed by a BSD-style license
  23251 // that can be found in the COPYING file in the root of the source
  23252 // tree. An additional intellectual property rights grant can be found
  23253 // in the file PATENTS. All contributing project authors may
  23254 // be found in the AUTHORS file in the root of the source tree.
  23255 // -----------------------------------------------------------------------------
  23256 //
  23257 //  Internal header for constants related to WebP file format.
  23258 //
  23259 // Author: Urvang (urvang@google.com)
  23260 
  23261 // Copyright 2010 Google Inc. All Rights Reserved.
  23262 //
  23263 // Use of this source code is governed by a BSD-style license
  23264 // that can be found in the COPYING file in the root of the source
  23265 // tree. An additional intellectual property rights grant can be found
  23266 // in the file PATENTS. All contributing project authors may
  23267 // be found in the AUTHORS file in the root of the source tree.
  23268 // -----------------------------------------------------------------------------
  23269 //
  23270 //  Common types + memory wrappers
  23271 //
  23272 // Author: Skal (pascal.massimino@gmail.com)
  23273 
  23274 // Number of partitions for the three dominant (literal, red and blue) symbol
  23275 // costs.
  23276 // The size of the bin-hash corresponding to the three dominant costs.
  23277 // Maximum number of histograms allowed in greedy combining algorithm.
  23278 
  23279 // C documentation
  23280 //
  23281 //	// Enum to meaningfully access the elements of the Histogram arrays.
  23282 type HistogramIndex = int32
  23283 
  23284 const LITERAL = 0
  23285 const DISTANCE = 4
  23286 
  23287 // C documentation
  23288 //
  23289 //	// Return the size of the histogram for a given cache_bits.
  23290 func GetHistogramSize(tls *libc.TLS, cache_bits int32) (r int32) {
  23291 	var literal_size, v1, v2, v4 int32
  23292 	var total_size size_t
  23293 	_, _, _, _, _ = literal_size, total_size, v1, v2, v4
  23294 	v1 = cache_bits
  23295 	if v1 > 0 {
  23296 		v4 = int32(1) << v1
  23297 	} else {
  23298 		v4 = 0
  23299 	}
  23300 	v2 = libc.Int32FromInt32(NUM_LITERAL_CODES) + libc.Int32FromInt32(NUM_LENGTH_CODES) + v4
  23301 	goto _3
  23302 _3:
  23303 	literal_size = v2
  23304 	total_size = uint64(3312) + uint64(4)*uint64(literal_size)
  23305 	return int32(total_size)
  23306 }
  23307 
  23308 func HistogramStatsClear(tls *libc.TLS, h uintptr) {
  23309 	var i int32
  23310 	_ = i
  23311 	i = 0
  23312 	for {
  23313 		if !(i < int32(5)) {
  23314 			break
  23315 		}
  23316 		**(**uint16_t)(__ccgo_up(h + 3244 + uintptr(i)*2)) = uint16(libc.Int32FromInt32(0xffff))
  23317 		// By default, the histogram is assumed to be used.
  23318 		**(**uint8_t)(__ccgo_up(h + 3304 + uintptr(i))) = uint8(1)
  23319 		goto _1
  23320 	_1:
  23321 		;
  23322 		i = i + 1
  23323 	}
  23324 	(*VP8LHistogram)(unsafe.Pointer(h)).Fbit_cost = uint64(0)
  23325 	libc.Xmemset(tls, h+3264, 0, uint64(40))
  23326 }
  23327 
  23328 func HistogramClear(tls *libc.TLS, h uintptr) {
  23329 	var cache_bits, histo_size int32
  23330 	var literal uintptr
  23331 	_, _, _ = cache_bits, histo_size, literal
  23332 	literal = (*VP8LHistogram)(unsafe.Pointer(h)).Fliteral
  23333 	cache_bits = (*VP8LHistogram)(unsafe.Pointer(h)).Fpalette_code_bits
  23334 	histo_size = GetHistogramSize(tls, cache_bits)
  23335 	libc.Xmemset(tls, h, 0, uint64(histo_size))
  23336 	(*VP8LHistogram)(unsafe.Pointer(h)).Fpalette_code_bits = cache_bits
  23337 	(*VP8LHistogram)(unsafe.Pointer(h)).Fliteral = literal
  23338 	HistogramStatsClear(tls, h)
  23339 }
  23340 
  23341 // C documentation
  23342 //
  23343 //	// Swap two histogram pointers.
  23344 func HistogramSwap(tls *libc.TLS, h1 uintptr, h2 uintptr) {
  23345 	var tmp uintptr
  23346 	_ = tmp
  23347 	tmp = **(**uintptr)(__ccgo_up(h1))
  23348 	**(**uintptr)(__ccgo_up(h1)) = **(**uintptr)(__ccgo_up(h2))
  23349 	**(**uintptr)(__ccgo_up(h2)) = tmp
  23350 }
  23351 
  23352 func HistogramCopy(tls *libc.TLS, src uintptr, dst uintptr) {
  23353 	var dst_cache_bits, histo_size, literal_size, v1, v2, v4 int32
  23354 	var dst_literal uintptr
  23355 	_, _, _, _, _, _, _ = dst_cache_bits, dst_literal, histo_size, literal_size, v1, v2, v4
  23356 	dst_literal = (*VP8LHistogram)(unsafe.Pointer(dst)).Fliteral
  23357 	dst_cache_bits = (*VP8LHistogram)(unsafe.Pointer(dst)).Fpalette_code_bits
  23358 	v1 = dst_cache_bits
  23359 	if v1 > 0 {
  23360 		v4 = int32(1) << v1
  23361 	} else {
  23362 		v4 = 0
  23363 	}
  23364 	v2 = libc.Int32FromInt32(NUM_LITERAL_CODES) + libc.Int32FromInt32(NUM_LENGTH_CODES) + v4
  23365 	goto _3
  23366 _3:
  23367 	literal_size = v2
  23368 	histo_size = GetHistogramSize(tls, dst_cache_bits)
  23369 	libc.Xmemcpy(tls, dst, src, uint64(histo_size))
  23370 	(*VP8LHistogram)(unsafe.Pointer(dst)).Fliteral = dst_literal
  23371 	libc.Xmemcpy(tls, (*VP8LHistogram)(unsafe.Pointer(dst)).Fliteral, (*VP8LHistogram)(unsafe.Pointer(src)).Fliteral, uint64(literal_size)*uint64(4))
  23372 }
  23373 
  23374 func VP8LFreeHistogram(tls *libc.TLS, h uintptr) {
  23375 	WebPSafeFree(tls, h)
  23376 }
  23377 
  23378 func VP8LFreeHistogramSet(tls *libc.TLS, histograms uintptr) {
  23379 	WebPSafeFree(tls, histograms)
  23380 }
  23381 
  23382 func VP8LHistogramCreate(tls *libc.TLS, h uintptr, refs uintptr, palette_code_bits int32) {
  23383 	if palette_code_bits >= 0 {
  23384 		(*VP8LHistogram)(unsafe.Pointer(h)).Fpalette_code_bits = palette_code_bits
  23385 	}
  23386 	HistogramClear(tls, h)
  23387 	VP8LHistogramStoreRefs(tls, refs, libc.UintptrFromInt32(0), 0, h)
  23388 }
  23389 
  23390 func VP8LHistogramInit(tls *libc.TLS, h uintptr, palette_code_bits int32, init_arrays int32) {
  23391 	(*VP8LHistogram)(unsafe.Pointer(h)).Fpalette_code_bits = palette_code_bits
  23392 	if init_arrays != 0 {
  23393 		HistogramClear(tls, h)
  23394 	} else {
  23395 		HistogramStatsClear(tls, h)
  23396 	}
  23397 }
  23398 
  23399 func VP8LAllocateHistogram(tls *libc.TLS, cache_bits int32) (r uintptr) {
  23400 	var histo, memory uintptr
  23401 	var total_size int32
  23402 	_, _, _ = histo, memory, total_size
  23403 	histo = libc.UintptrFromInt32(0)
  23404 	total_size = GetHistogramSize(tls, cache_bits)
  23405 	memory = WebPSafeMalloc(tls, uint64(total_size), uint64(1))
  23406 	if memory == libc.UintptrFromInt32(0) {
  23407 		return libc.UintptrFromInt32(0)
  23408 	}
  23409 	histo = memory
  23410 	// 'literal' won't necessary be aligned.
  23411 	(*VP8LHistogram)(unsafe.Pointer(histo)).Fliteral = memory + libc.UintptrFromInt64(3312)
  23412 	VP8LHistogramInit(tls, histo, cache_bits, 0)
  23413 	return histo
  23414 }
  23415 
  23416 // C documentation
  23417 //
  23418 //	// Resets the pointers of the histograms to point to the bit buffer in the set.
  23419 func HistogramSetResetPointers(tls *libc.TLS, set uintptr, cache_bits int32) {
  23420 	var histo_size, i int32
  23421 	var memory uintptr
  23422 	_, _, _ = histo_size, i, memory
  23423 	histo_size = GetHistogramSize(tls, cache_bits)
  23424 	memory = (*VP8LHistogramSet)(unsafe.Pointer(set)).Fhistograms
  23425 	memory = memory + uintptr(uint64((*VP8LHistogramSet)(unsafe.Pointer(set)).Fmax_size)*uint64(8))
  23426 	i = 0
  23427 	for {
  23428 		if !(i < (*VP8LHistogramSet)(unsafe.Pointer(set)).Fmax_size) {
  23429 			break
  23430 		}
  23431 		memory = uintptr((uint64(memory) + libc.Uint64FromInt32(WEBP_ALIGN_CST)) & ^libc.Uint64FromInt32(WEBP_ALIGN_CST))
  23432 		**(**uintptr)(__ccgo_up((*VP8LHistogramSet)(unsafe.Pointer(set)).Fhistograms + uintptr(i)*8)) = memory
  23433 		// 'literal' won't necessary be aligned.
  23434 		(*VP8LHistogram)(unsafe.Pointer(**(**uintptr)(__ccgo_up((*VP8LHistogramSet)(unsafe.Pointer(set)).Fhistograms + uintptr(i)*8)))).Fliteral = memory + libc.UintptrFromInt64(3312)
  23435 		memory = memory + uintptr(histo_size)
  23436 		goto _1
  23437 	_1:
  23438 		;
  23439 		i = i + 1
  23440 	}
  23441 }
  23442 
  23443 // C documentation
  23444 //
  23445 //	// Returns the total size of the VP8LHistogramSet.
  23446 func HistogramSetTotalSize(tls *libc.TLS, size int32, cache_bits int32) (r size_t) {
  23447 	var histo_size int32
  23448 	_ = histo_size
  23449 	histo_size = GetHistogramSize(tls, cache_bits)
  23450 	return libc.Uint64FromInt64(16) + uint64(size)*(libc.Uint64FromInt64(8)+uint64(histo_size)+libc.Uint64FromInt32(WEBP_ALIGN_CST))
  23451 }
  23452 
  23453 func VP8LAllocateHistogramSet(tls *libc.TLS, size int32, cache_bits int32) (r uintptr) {
  23454 	var i int32
  23455 	var memory, set uintptr
  23456 	var total_size size_t
  23457 	_, _, _, _ = i, memory, set, total_size
  23458 	total_size = HistogramSetTotalSize(tls, size, cache_bits)
  23459 	memory = WebPSafeMalloc(tls, total_size, uint64(1))
  23460 	if memory == libc.UintptrFromInt32(0) {
  23461 		return libc.UintptrFromInt32(0)
  23462 	}
  23463 	set = memory
  23464 	memory = memory + uintptr(16)
  23465 	(*VP8LHistogramSet)(unsafe.Pointer(set)).Fhistograms = memory
  23466 	(*VP8LHistogramSet)(unsafe.Pointer(set)).Fmax_size = size
  23467 	(*VP8LHistogramSet)(unsafe.Pointer(set)).Fsize = size
  23468 	HistogramSetResetPointers(tls, set, cache_bits)
  23469 	i = 0
  23470 	for {
  23471 		if !(i < size) {
  23472 			break
  23473 		}
  23474 		VP8LHistogramInit(tls, **(**uintptr)(__ccgo_up((*VP8LHistogramSet)(unsafe.Pointer(set)).Fhistograms + uintptr(i)*8)), cache_bits, 0)
  23475 		goto _1
  23476 	_1:
  23477 		;
  23478 		i = i + 1
  23479 	}
  23480 	return set
  23481 }
  23482 
  23483 func VP8LHistogramSetClear(tls *libc.TLS, set uintptr) {
  23484 	var cache_bits, i, size int32
  23485 	var memory uintptr
  23486 	var total_size size_t
  23487 	_, _, _, _, _ = cache_bits, i, memory, size, total_size
  23488 	cache_bits = (*VP8LHistogram)(unsafe.Pointer(**(**uintptr)(__ccgo_up((*VP8LHistogramSet)(unsafe.Pointer(set)).Fhistograms)))).Fpalette_code_bits
  23489 	size = (*VP8LHistogramSet)(unsafe.Pointer(set)).Fmax_size
  23490 	total_size = HistogramSetTotalSize(tls, size, cache_bits)
  23491 	memory = set
  23492 	libc.Xmemset(tls, memory, 0, total_size)
  23493 	memory = memory + uintptr(16)
  23494 	(*VP8LHistogramSet)(unsafe.Pointer(set)).Fhistograms = memory
  23495 	(*VP8LHistogramSet)(unsafe.Pointer(set)).Fmax_size = size
  23496 	(*VP8LHistogramSet)(unsafe.Pointer(set)).Fsize = size
  23497 	HistogramSetResetPointers(tls, set, cache_bits)
  23498 	i = 0
  23499 	for {
  23500 		if !(i < size) {
  23501 			break
  23502 		}
  23503 		(*VP8LHistogram)(unsafe.Pointer(**(**uintptr)(__ccgo_up((*VP8LHistogramSet)(unsafe.Pointer(set)).Fhistograms + uintptr(i)*8)))).Fpalette_code_bits = cache_bits
  23504 		goto _1
  23505 	_1:
  23506 		;
  23507 		i = i + 1
  23508 	}
  23509 }
  23510 
  23511 // C documentation
  23512 //
  23513 //	// Removes the histogram 'i' from 'set'.
  23514 func HistogramSetRemoveHistogram(tls *libc.TLS, set uintptr, i int32) {
  23515 	**(**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))
  23516 	(*VP8LHistogramSet)(unsafe.Pointer(set)).Fsize = (*VP8LHistogramSet)(unsafe.Pointer(set)).Fsize - 1
  23517 }
  23518 
  23519 // -----------------------------------------------------------------------------
  23520 
  23521 func HistogramAddSinglePixOrCopy(tls *libc.TLS, histo uintptr, v uintptr, __ccgo_fp_distance_modifier uintptr, distance_modifier_arg0 int32) {
  23522 	bp := tls.Alloc(16)
  23523 	defer tls.Free(16)
  23524 	var highest_bit, literal_ix, second_highest_bit, v1, v11, v17, v20 int32
  23525 	var prefix_code VP8LPrefixCode
  23526 	var v3 uint32_t
  23527 	var v18, v19 uintptr
  23528 	var _ /* code at bp+0 */ int32
  23529 	var _ /* extra_bits at bp+4 */ int32
  23530 	_, _, _, _, _, _, _, _, _, _, _ = highest_bit, literal_ix, prefix_code, second_highest_bit, v1, v11, v17, v18, v19, v20, v3
  23531 	v1 = libc.BoolInt32(int32((*PixOrCopy)(unsafe.Pointer(v)).Fmode) == int32(kLiteral))
  23532 	goto _2
  23533 _2:
  23534 	if v1 != 0 {
  23535 		v3 = (*PixOrCopy)(unsafe.Pointer(v)).Fargb_or_distance >> (int32(3) * libc.Int32FromInt32(8)) & uint32(0xff)
  23536 		goto _4
  23537 	_4:
  23538 		**(**uint32_t)(__ccgo_up(histo + 2056 + uintptr(v3)*4)) = **(**uint32_t)(__ccgo_up(histo + 2056 + uintptr(v3)*4)) + 1
  23539 		v3 = (*PixOrCopy)(unsafe.Pointer(v)).Fargb_or_distance >> (int32(2) * libc.Int32FromInt32(8)) & uint32(0xff)
  23540 		goto _6
  23541 	_6:
  23542 		**(**uint32_t)(__ccgo_up(histo + 8 + uintptr(v3)*4)) = **(**uint32_t)(__ccgo_up(histo + 8 + uintptr(v3)*4)) + 1
  23543 		v3 = (*PixOrCopy)(unsafe.Pointer(v)).Fargb_or_distance >> (int32(1) * libc.Int32FromInt32(8)) & uint32(0xff)
  23544 		goto _8
  23545 	_8:
  23546 		**(**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
  23547 		v3 = (*PixOrCopy)(unsafe.Pointer(v)).Fargb_or_distance >> (0 * libc.Int32FromInt32(8)) & uint32(0xff)
  23548 		goto _10
  23549 	_10:
  23550 		**(**uint32_t)(__ccgo_up(histo + 1032 + uintptr(v3)*4)) = **(**uint32_t)(__ccgo_up(histo + 1032 + uintptr(v3)*4)) + 1
  23551 	} else {
  23552 		v1 = libc.BoolInt32(int32((*PixOrCopy)(unsafe.Pointer(v)).Fmode) == int32(kCacheIdx))
  23553 		goto _12
  23554 	_12:
  23555 		if v1 != 0 {
  23556 			v3 = (*PixOrCopy)(unsafe.Pointer(v)).Fargb_or_distance
  23557 			goto _14
  23558 		_14:
  23559 			literal_ix = int32(uint32(libc.Int32FromInt32(NUM_LITERAL_CODES)+libc.Int32FromInt32(NUM_LENGTH_CODES)) + v3)
  23560 			**(**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
  23561 		} else {
  23562 			v3 = uint32((*PixOrCopy)(unsafe.Pointer(v)).Flen1)
  23563 			goto _16
  23564 		_16:
  23565 			v1 = int32(v3)
  23566 			v18 = bp
  23567 			v19 = bp + 4
  23568 			if v1 < libc.Int32FromInt32(PREFIX_LOOKUP_IDX_MAX) {
  23569 				prefix_code = kPrefixEncodeCode[v1]
  23570 				**(**int32)(__ccgo_up(v18)) = int32(prefix_code.Fcode)
  23571 				**(**int32)(__ccgo_up(v19)) = int32(prefix_code.Fextra_bits)
  23572 			} else {
  23573 				v11 = v1
  23574 				v11 = v11 - 1
  23575 				v17 = v11
  23576 				v20 = int32(31) ^ libc.X__builtin_clz(tls, uint32(v17))
  23577 				goto _23
  23578 			_23:
  23579 				highest_bit = v20
  23580 				second_highest_bit = v11 >> (highest_bit - int32(1)) & int32(1)
  23581 				**(**int32)(__ccgo_up(v19)) = highest_bit - int32(1)
  23582 				**(**int32)(__ccgo_up(v18)) = int32(2)*highest_bit + second_highest_bit
  23583 			}
  23584 			**(**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
  23585 			if __ccgo_fp_distance_modifier == libc.UintptrFromInt32(0) {
  23586 				v3 = (*PixOrCopy)(unsafe.Pointer(v)).Fargb_or_distance
  23587 				goto _25
  23588 			_25:
  23589 				v1 = int32(v3)
  23590 				v18 = bp
  23591 				v19 = bp + 4
  23592 				if v1 < libc.Int32FromInt32(PREFIX_LOOKUP_IDX_MAX) {
  23593 					prefix_code = kPrefixEncodeCode[v1]
  23594 					**(**int32)(__ccgo_up(v18)) = int32(prefix_code.Fcode)
  23595 					**(**int32)(__ccgo_up(v19)) = int32(prefix_code.Fextra_bits)
  23596 				} else {
  23597 					v11 = v1
  23598 					v11 = v11 - 1
  23599 					v17 = v11
  23600 					v20 = int32(31) ^ libc.X__builtin_clz(tls, uint32(v17))
  23601 					goto _32
  23602 				_32:
  23603 					highest_bit = v20
  23604 					second_highest_bit = v11 >> (highest_bit - int32(1)) & int32(1)
  23605 					**(**int32)(__ccgo_up(v19)) = highest_bit - int32(1)
  23606 					**(**int32)(__ccgo_up(v18)) = int32(2)*highest_bit + second_highest_bit
  23607 				}
  23608 			} else {
  23609 				v3 = (*PixOrCopy)(unsafe.Pointer(v)).Fargb_or_distance
  23610 				goto _34
  23611 			_34:
  23612 				v1 = (*(*func(*libc.TLS, int32, int32) int32)(unsafe.Pointer(&struct{ uintptr }{__ccgo_fp_distance_modifier})))(tls, distance_modifier_arg0, int32(v3))
  23613 				v18 = bp
  23614 				v19 = bp + 4
  23615 				if v1 < libc.Int32FromInt32(PREFIX_LOOKUP_IDX_MAX) {
  23616 					prefix_code = kPrefixEncodeCode[v1]
  23617 					**(**int32)(__ccgo_up(v18)) = int32(prefix_code.Fcode)
  23618 					**(**int32)(__ccgo_up(v19)) = int32(prefix_code.Fextra_bits)
  23619 				} else {
  23620 					v11 = v1
  23621 					v11 = v11 - 1
  23622 					v17 = v11
  23623 					v20 = int32(31) ^ libc.X__builtin_clz(tls, uint32(v17))
  23624 					goto _41
  23625 				_41:
  23626 					highest_bit = v20
  23627 					second_highest_bit = v11 >> (highest_bit - int32(1)) & int32(1)
  23628 					**(**int32)(__ccgo_up(v19)) = highest_bit - int32(1)
  23629 					**(**int32)(__ccgo_up(v18)) = int32(2)*highest_bit + second_highest_bit
  23630 				}
  23631 			}
  23632 			**(**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
  23633 		}
  23634 	}
  23635 }
  23636 
  23637 type __ccgo_fp__XVP8LHistogramStoreRefs_1 = func(*libc.TLS, int32, int32) int32
  23638 
  23639 func VP8LHistogramStoreRefs(tls *libc.TLS, refs uintptr, __ccgo_fp_distance_modifier uintptr, distance_modifier_arg0 int32, histo uintptr) {
  23640 	bp := tls.Alloc(32)
  23641 	defer tls.Free(32)
  23642 	var v1 int32
  23643 	var v3, v4, v5 uintptr
  23644 	var _ /* c at bp+0 */ VP8LRefsCursor
  23645 	_, _, _, _ = v1, v3, v4, v5
  23646 	**(**VP8LRefsCursor)(__ccgo_up(bp)) = VP8LRefsCursorInit(tls, refs)
  23647 	for {
  23648 		v1 = libc.BoolInt32((*VP8LRefsCursor)(unsafe.Pointer(bp)).Fcur_pos != libc.UintptrFromInt32(0))
  23649 		goto _2
  23650 	_2:
  23651 		if !(v1 != 0) {
  23652 			break
  23653 		}
  23654 		HistogramAddSinglePixOrCopy(tls, histo, (**(**VP8LRefsCursor)(__ccgo_up(bp))).Fcur_pos, __ccgo_fp_distance_modifier, distance_modifier_arg0)
  23655 		v3 = bp
  23656 		v5 = v3
  23657 		*(*uintptr)(unsafe.Pointer(v5)) += 8
  23658 		v4 = *(*uintptr)(unsafe.Pointer(v5))
  23659 		if v4 == (*VP8LRefsCursor)(unsafe.Pointer(v3)).Flast_pos {
  23660 			VP8LRefsCursorNextBlock(tls, v3)
  23661 		}
  23662 	}
  23663 }
  23664 
  23665 // -----------------------------------------------------------------------------
  23666 // Entropy-related functions.
  23667 
  23668 func BitsEntropyRefine(tls *libc.TLS, entropy uintptr) (r uint64_t) {
  23669 	var min_limit, mix uint64_t
  23670 	var v1, v2, v3 int64_t
  23671 	var v5 int64
  23672 	var v11 uint64
  23673 	_, _, _, _, _, _, _ = min_limit, mix, v1, v11, v2, v3, v5
  23674 	if (*VP8LBitEntropy)(unsafe.Pointer(entropy)).Fnonzeros < int32(5) {
  23675 		if (*VP8LBitEntropy)(unsafe.Pointer(entropy)).Fnonzeros <= int32(1) {
  23676 			return uint64(0)
  23677 		}
  23678 		// Two symbols, they will be 0 and 1 in a Huffman code.
  23679 		// Let's mix in a bit of entropy to favor good clustering when
  23680 		// distributions of these are combined.
  23681 		if (*VP8LBitEntropy)(unsafe.Pointer(entropy)).Fnonzeros == int32(2) {
  23682 			v1 = int64(uint64(99)*(uint64((*VP8LBitEntropy)(unsafe.Pointer(entropy)).Fsum)<<libc.Int32FromInt32(LOG_2_PRECISION_BITS)) + (*VP8LBitEntropy)(unsafe.Pointer(entropy)).Fentropy)
  23683 			v2 = int64(100)
  23684 			if libc.BoolInt32(v1 < 0) == libc.BoolInt32(v2 < 0) {
  23685 				v5 = (v1 + v2/int64(2)) / v2
  23686 			} else {
  23687 				v5 = (v1 - v2/int64(2)) / v2
  23688 			}
  23689 			v3 = v5
  23690 			goto _4
  23691 		_4:
  23692 			return uint64(v3)
  23693 		}
  23694 		// No matter what the entropy says, we cannot be better than min_limit
  23695 		// with Huffman coding. I am mixing a bit of entropy into the
  23696 		// min_limit since it produces much better (~0.5 %) compression results
  23697 		// perhaps because of better entropy clustering.
  23698 		if (*VP8LBitEntropy)(unsafe.Pointer(entropy)).Fnonzeros == int32(3) {
  23699 			mix = uint64(950)
  23700 		} else {
  23701 			mix = uint64(700) // nonzeros == 4.
  23702 		}
  23703 	} else {
  23704 		mix = uint64(627)
  23705 	}
  23706 	min_limit = uint64(libc.Uint32FromInt32(2)*(*VP8LBitEntropy)(unsafe.Pointer(entropy)).Fsum-(*VP8LBitEntropy)(unsafe.Pointer(entropy)).Fmax_val) << int32(LOG_2_PRECISION_BITS)
  23707 	v1 = int64(mix*min_limit + (uint64(1000)-mix)*(*VP8LBitEntropy)(unsafe.Pointer(entropy)).Fentropy)
  23708 	v2 = int64(1000)
  23709 	if libc.BoolInt32(v1 < 0) == libc.BoolInt32(v2 < 0) {
  23710 		v5 = (v1 + v2/int64(2)) / v2
  23711 	} else {
  23712 		v5 = (v1 - v2/int64(2)) / v2
  23713 	}
  23714 	v3 = v5
  23715 	goto _9
  23716 _9:
  23717 	min_limit = uint64(v3)
  23718 	if (*VP8LBitEntropy)(unsafe.Pointer(entropy)).Fentropy < min_limit {
  23719 		v11 = min_limit
  23720 	} else {
  23721 		v11 = (*VP8LBitEntropy)(unsafe.Pointer(entropy)).Fentropy
  23722 	}
  23723 	return v11
  23724 	return r
  23725 }
  23726 
  23727 func VP8LBitsEntropy(tls *libc.TLS, array uintptr, n int32) (r uint64_t) {
  23728 	bp := tls.Alloc(32)
  23729 	defer tls.Free(32)
  23730 	var _ /* entropy at bp+0 */ VP8LBitEntropy
  23731 	VP8LBitsEntropyUnrefined(tls, array, n, bp)
  23732 	return BitsEntropyRefine(tls, bp)
  23733 }
  23734 
  23735 func InitialHuffmanCost(tls *libc.TLS) (r uint64_t) {
  23736 	var v1, v2, v3 int64_t
  23737 	var v5 int64
  23738 	_, _, _, _ = v1, v2, v3, v5
  23739 	// Subtract a bias of 9.1.
  23740 	v1 = libc.Int64FromInt64(91) << libc.Int32FromInt32(LOG_2_PRECISION_BITS)
  23741 	v2 = int64(10)
  23742 	if libc.BoolInt32(v1 < 0) == libc.BoolInt32(v2 < 0) {
  23743 		v5 = (v1 + v2/int64(2)) / v2
  23744 	} else {
  23745 		v5 = (v1 - v2/int64(2)) / v2
  23746 	}
  23747 	v3 = v5
  23748 	goto _4
  23749 _4:
  23750 	return kHuffmanCodeOfHuffmanCodeSize<<libc.Int32FromInt32(LOG_2_PRECISION_BITS) - uint64(v3)
  23751 }
  23752 
  23753 // Small bias because Huffman code length is typically not stored in
  23754 // full length.
  23755 var kHuffmanCodeOfHuffmanCodeSize = uint64(libc.Int32FromInt32(CODE_LENGTH_CODES) * libc.Int32FromInt32(3))
  23756 
  23757 // C documentation
  23758 //
  23759 //	// Finalize the Huffman cost based on streak numbers and length type (<3 or >=3)
  23760 func FinalHuffmanCost(tls *libc.TLS, stats uintptr) (r uint64_t) {
  23761 	var retval uint64_t
  23762 	var retval_extra uint32_t
  23763 	_, _ = retval, retval_extra
  23764 	// The constants in this function are empirical and got rounded from
  23765 	// their original values in 1/8 when switched to 1/1024.
  23766 	retval = InitialHuffmanCost(tls)
  23767 	// Second coefficient: Many zeros in the histogram are covered efficiently
  23768 	// by a run-length encode. Originally 2/8.
  23769 	retval_extra = uint32(**(**int32)(__ccgo_up(stats))*int32(1600) + int32(240)***(**int32)(__ccgo_up(stats + 8 + 1*4)))
  23770 	// Second coefficient: Constant values are encoded less efficiently, but still
  23771 	// RLE'ed. Originally 6/8.
  23772 	retval_extra = retval_extra + uint32(**(**int32)(__ccgo_up(stats + 1*4))*int32(2640)+int32(720)***(**int32)(__ccgo_up(stats + 8 + 1*8 + 1*4)))
  23773 	// 0s are usually encoded more efficiently than non-0s.
  23774 	// Originally 15/8.
  23775 	retval_extra = retval_extra + uint32(int32(1840)***(**int32)(__ccgo_up(stats + 8)))
  23776 	// Originally 26/8.
  23777 	retval_extra = retval_extra + uint32(int32(3360)***(**int32)(__ccgo_up(stats + 8 + 1*8)))
  23778 	return retval + uint64(retval_extra)<<(libc.Int32FromInt32(LOG_2_PRECISION_BITS)-libc.Int32FromInt32(10))
  23779 }
  23780 
  23781 // C documentation
  23782 //
  23783 //	// Get the symbol entropy for the distribution 'population'.
  23784 //	// Set 'trivial_sym', if there's only one symbol present in the distribution.
  23785 func PopulationCost(tls *libc.TLS, population uintptr, length int32, trivial_sym uintptr, is_used uintptr) (r uint64_t) {
  23786 	bp := tls.Alloc(48)
  23787 	defer tls.Free(48)
  23788 	var v1 uint32
  23789 	var _ /* bit_entropy at bp+0 */ VP8LBitEntropy
  23790 	var _ /* stats at bp+24 */ VP8LStreaks
  23791 	_ = v1
  23792 	(*(*func(*libc.TLS, uintptr, int32, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8LGetEntropyUnrefined})))(tls, population, length, bp, bp+24)
  23793 	if trivial_sym != libc.UintptrFromInt32(0) {
  23794 		if (**(**VP8LBitEntropy)(__ccgo_up(bp))).Fnonzeros == int32(1) {
  23795 			v1 = (**(**VP8LBitEntropy)(__ccgo_up(bp))).Fnonzero_code
  23796 		} else {
  23797 			v1 = uint32(uint16(libc.Int32FromInt32(0xffff)))
  23798 		}
  23799 		**(**uint16_t)(__ccgo_up(trivial_sym)) = uint16(v1)
  23800 	}
  23801 	if is_used != libc.UintptrFromInt32(0) {
  23802 		// The histogram is used if there is at least one non-zero streak.
  23803 		**(**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)
  23804 	}
  23805 	return BitsEntropyRefine(tls, bp) + FinalHuffmanCost(tls, bp+24)
  23806 }
  23807 
  23808 func GetPopulationInfo(tls *libc.TLS, histo uintptr, index HistogramIndex, population uintptr, length uintptr) {
  23809 	var v1, v2, v4 int32
  23810 	_, _, _ = v1, v2, v4
  23811 	switch index {
  23812 	case int32(LITERAL):
  23813 		**(**uintptr)(__ccgo_up(population)) = (*VP8LHistogram)(unsafe.Pointer(histo)).Fliteral
  23814 		v1 = (*VP8LHistogram)(unsafe.Pointer(histo)).Fpalette_code_bits
  23815 		if v1 > 0 {
  23816 			v4 = int32(1) << v1
  23817 		} else {
  23818 			v4 = 0
  23819 		}
  23820 		v2 = libc.Int32FromInt32(NUM_LITERAL_CODES) + libc.Int32FromInt32(NUM_LENGTH_CODES) + v4
  23821 		goto _3
  23822 	_3:
  23823 		**(**int32)(__ccgo_up(length)) = v2
  23824 	case int32(RED):
  23825 		**(**uintptr)(__ccgo_up(population)) = histo + 8
  23826 		**(**int32)(__ccgo_up(length)) = int32(NUM_LITERAL_CODES)
  23827 	case int32(BLUE):
  23828 		**(**uintptr)(__ccgo_up(population)) = histo + 1032
  23829 		**(**int32)(__ccgo_up(length)) = int32(NUM_LITERAL_CODES)
  23830 	case int32(ALPHA):
  23831 		**(**uintptr)(__ccgo_up(population)) = histo + 2056
  23832 		**(**int32)(__ccgo_up(length)) = int32(NUM_LITERAL_CODES)
  23833 	case int32(DISTANCE):
  23834 		**(**uintptr)(__ccgo_up(population)) = histo + 3080
  23835 		**(**int32)(__ccgo_up(length)) = int32(NUM_DISTANCE_CODES)
  23836 		break
  23837 	}
  23838 }
  23839 
  23840 // C documentation
  23841 //
  23842 //	// trivial_at_end is 1 if the two histograms only have one element that is
  23843 //	// non-zero: both the zero-th one, or both the last one.
  23844 //	// 'index' is the index of the symbol in the histogram (literal, red, blue,
  23845 //	// alpha, distance).
  23846 func GetCombinedEntropy(tls *libc.TLS, h1 uintptr, h2 uintptr, index HistogramIndex) (r uint64_t) {
  23847 	bp := tls.Alloc(80)
  23848 	defer tls.Free(80)
  23849 	var is_h1_used, is_h2_used, is_trivial int32
  23850 	var _ /* X at bp+0 */ uintptr
  23851 	var _ /* Y at bp+8 */ uintptr
  23852 	var _ /* bit_entropy at bp+48 */ VP8LBitEntropy
  23853 	var _ /* length at bp+16 */ int32
  23854 	var _ /* stats at bp+20 */ VP8LStreaks
  23855 	_, _, _ = is_h1_used, is_h2_used, is_trivial
  23856 	is_h1_used = int32(**(**uint8_t)(__ccgo_up(h1 + 3304 + uintptr(index))))
  23857 	is_h2_used = int32(**(**uint8_t)(__ccgo_up(h2 + 3304 + uintptr(index))))
  23858 	is_trivial = libc.BoolInt32(int32(**(**uint16_t)(__ccgo_up(h1 + 3244 + uintptr(index)*2))) != int32(uint16(libc.Int32FromInt32(0xffff))) && int32(**(**uint16_t)(__ccgo_up(h1 + 3244 + uintptr(index)*2))) == int32(**(**uint16_t)(__ccgo_up(h2 + 3244 + uintptr(index)*2))))
  23859 	if is_trivial != 0 || !(is_h1_used != 0) || !(is_h2_used != 0) {
  23860 		if is_h1_used != 0 {
  23861 			return **(**uint64_t)(__ccgo_up(h1 + 3264 + uintptr(index)*8))
  23862 		}
  23863 		return **(**uint64_t)(__ccgo_up(h2 + 3264 + uintptr(index)*8))
  23864 	}
  23865 	GetPopulationInfo(tls, h1, index, bp, bp+16)
  23866 	GetPopulationInfo(tls, h2, index, bp+8, bp+16)
  23867 	(*(*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)
  23868 	return BitsEntropyRefine(tls, bp+48) + FinalHuffmanCost(tls, bp+20)
  23869 }
  23870 
  23871 // C documentation
  23872 //
  23873 //	// Estimates the Entropy + Huffman + other block overhead size cost.
  23874 func VP8LHistogramEstimateBits(tls *libc.TLS, h uintptr) (r uint64_t) {
  23875 	bp := tls.Alloc(16)
  23876 	defer tls.Free(16)
  23877 	var cost uint64_t
  23878 	var i int32
  23879 	var _ /* length at bp+0 */ int32
  23880 	var _ /* population at bp+8 */ uintptr
  23881 	_, _ = cost, i
  23882 	cost = uint64(0)
  23883 	i = 0
  23884 	for {
  23885 		if !(i < int32(5)) {
  23886 			break
  23887 		}
  23888 		GetPopulationInfo(tls, h, i, bp+8, bp)
  23889 		cost = cost + PopulationCost(tls, **(**uintptr)(__ccgo_up(bp + 8)), **(**int32)(__ccgo_up(bp)), libc.UintptrFromInt32(0), libc.UintptrFromInt32(0))
  23890 		goto _1
  23891 	_1:
  23892 		;
  23893 		i = i + 1
  23894 	}
  23895 	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)
  23896 	return cost
  23897 }
  23898 
  23899 // -----------------------------------------------------------------------------
  23900 // Various histogram combine/cost-eval functions
  23901 
  23902 // C documentation
  23903 //
  23904 //	// Set a + b in b, saturating at WEBP_INT64_MAX.
  23905 func SaturateAdd(tls *libc.TLS, a uint64_t, b uintptr) {
  23906 	if **(**int64_t)(__ccgo_up(b)) < 0 || int64(a) <= int64(libc.Uint64FromUint64(1)<<libc.Int32FromInt32(63)-libc.Uint64FromInt32(1))-**(**int64_t)(__ccgo_up(b)) {
  23907 		**(**int64_t)(__ccgo_up(b)) += int64(a)
  23908 	} else {
  23909 		**(**int64_t)(__ccgo_up(b)) = int64(libc.Uint64FromUint64(1)<<libc.Int32FromInt32(63) - libc.Uint64FromInt32(1))
  23910 	}
  23911 }
  23912 
  23913 // C documentation
  23914 //
  23915 //	// Returns 1 if the cost of the combined histogram is less than the threshold.
  23916 //	// Otherwise returns 0 and the cost is invalid due to early bail-out.
  23917 func GetCombinedHistogramEntropy(tls *libc.TLS, a uintptr, b uintptr, cost_threshold_in int64_t, cost uintptr, costs uintptr) (r int32) {
  23918 	var cost_threshold uint64_t
  23919 	var i int32
  23920 	_, _ = cost_threshold, i
  23921 	cost_threshold = uint64(cost_threshold_in)
  23922 	if cost_threshold_in <= 0 {
  23923 		return 0
  23924 	}
  23925 	**(**uint64_t)(__ccgo_up(cost)) = uint64(0)
  23926 	// No need to add the extra cost for length and distance as it is a constant
  23927 	// that does not influence the histograms.
  23928 	i = 0
  23929 	for {
  23930 		if !(i < int32(5)) {
  23931 			break
  23932 		}
  23933 		**(**uint64_t)(__ccgo_up(costs + uintptr(i)*8)) = GetCombinedEntropy(tls, a, b, i)
  23934 		**(**uint64_t)(__ccgo_up(cost)) += **(**uint64_t)(__ccgo_up(costs + uintptr(i)*8))
  23935 		if **(**uint64_t)(__ccgo_up(cost)) >= cost_threshold {
  23936 			return 0
  23937 		}
  23938 		goto _1
  23939 	_1:
  23940 		;
  23941 		i = i + 1
  23942 	}
  23943 	return int32(1)
  23944 }
  23945 
  23946 func HistogramAdd(tls *libc.TLS, h1 uintptr, h2 uintptr, hout uintptr) {
  23947 	bp := tls.Alloc(32)
  23948 	defer tls.Free(32)
  23949 	var i, v3 int32
  23950 	var pout uintptr
  23951 	var _ /* length at bp+0 */ int32
  23952 	var _ /* p1 at bp+8 */ uintptr
  23953 	var _ /* p2 at bp+16 */ uintptr
  23954 	var _ /* pout_const at bp+24 */ uintptr
  23955 	_, _, _ = i, pout, v3
  23956 	i = 0
  23957 	for {
  23958 		if !(i < int32(5)) {
  23959 			break
  23960 		}
  23961 		GetPopulationInfo(tls, h1, i, bp+8, bp)
  23962 		GetPopulationInfo(tls, h2, i, bp+16, bp)
  23963 		GetPopulationInfo(tls, hout, i, bp+24, bp)
  23964 		pout = **(**uintptr)(__ccgo_up(bp + 24))
  23965 		if h2 == hout {
  23966 			if **(**uint8_t)(__ccgo_up(h1 + 3304 + uintptr(i))) != 0 {
  23967 				if **(**uint8_t)(__ccgo_up(hout + 3304 + uintptr(i))) != 0 {
  23968 					(*(*func(*libc.TLS, uintptr, uintptr, int32))(unsafe.Pointer(&struct{ uintptr }{VP8LAddVectorEq})))(tls, **(**uintptr)(__ccgo_up(bp + 8)), pout, **(**int32)(__ccgo_up(bp)))
  23969 				} else {
  23970 					libc.Xmemcpy(tls, pout, **(**uintptr)(__ccgo_up(bp + 8)), uint64(**(**int32)(__ccgo_up(bp)))*uint64(4))
  23971 				}
  23972 			}
  23973 		} else {
  23974 			if **(**uint8_t)(__ccgo_up(h1 + 3304 + uintptr(i))) != 0 {
  23975 				if **(**uint8_t)(__ccgo_up(h2 + 3304 + uintptr(i))) != 0 {
  23976 					(*(*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)))
  23977 				} else {
  23978 					libc.Xmemcpy(tls, pout, **(**uintptr)(__ccgo_up(bp + 8)), uint64(**(**int32)(__ccgo_up(bp)))*uint64(4))
  23979 				}
  23980 			} else {
  23981 				if **(**uint8_t)(__ccgo_up(h2 + 3304 + uintptr(i))) != 0 {
  23982 					libc.Xmemcpy(tls, pout, **(**uintptr)(__ccgo_up(bp + 16)), uint64(**(**int32)(__ccgo_up(bp)))*uint64(4))
  23983 				} else {
  23984 					libc.Xmemset(tls, pout, 0, uint64(**(**int32)(__ccgo_up(bp)))*uint64(4))
  23985 				}
  23986 			}
  23987 		}
  23988 		goto _1
  23989 	_1:
  23990 		;
  23991 		i = i + 1
  23992 	}
  23993 	i = 0
  23994 	for {
  23995 		if !(i < int32(5)) {
  23996 			break
  23997 		}
  23998 		if int32(**(**uint16_t)(__ccgo_up(h1 + 3244 + uintptr(i)*2))) == int32(**(**uint16_t)(__ccgo_up(h2 + 3244 + uintptr(i)*2))) {
  23999 			v3 = int32(**(**uint16_t)(__ccgo_up(h1 + 3244 + uintptr(i)*2)))
  24000 		} else {
  24001 			v3 = int32(uint16(libc.Int32FromInt32(0xffff)))
  24002 		}
  24003 		**(**uint16_t)(__ccgo_up(hout + 3244 + uintptr(i)*2)) = uint16(v3)
  24004 		**(**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)
  24005 		goto _2
  24006 	_2:
  24007 		;
  24008 		i = i + 1
  24009 	}
  24010 }
  24011 
  24012 func UpdateHistogramCost(tls *libc.TLS, bit_cost uint64_t, costs uintptr, h uintptr) {
  24013 	var i int32
  24014 	_ = i
  24015 	(*VP8LHistogram)(unsafe.Pointer(h)).Fbit_cost = bit_cost
  24016 	i = 0
  24017 	for {
  24018 		if !(i < int32(5)) {
  24019 			break
  24020 		}
  24021 		**(**uint64_t)(__ccgo_up(h + 3264 + uintptr(i)*8)) = **(**uint64_t)(__ccgo_up(costs + uintptr(i)*8))
  24022 		goto _1
  24023 	_1:
  24024 		;
  24025 		i = i + 1
  24026 	}
  24027 }
  24028 
  24029 // C documentation
  24030 //
  24031 //	// Performs out = a + b, computing the cost C(a+b) - C(a) - C(b) while comparing
  24032 //	// to the threshold value 'cost_threshold'. The score returned is
  24033 //	//  Score = C(a+b) - C(a) - C(b), where C(a) + C(b) is known and fixed.
  24034 //	// Since the previous score passed is 'cost_threshold', we only need to compare
  24035 //	// the partial cost against 'cost_threshold + C(a) + C(b)' to possibly bail-out
  24036 //	// early.
  24037 //	// Returns 1 if the cost is less than the threshold.
  24038 //	// Otherwise returns 0 and the cost is invalid due to early bail-out.
  24039 func HistogramAddEval(tls *libc.TLS, a uintptr, b uintptr, out uintptr, _cost_threshold int64_t) (r int32) {
  24040 	bp := tls.Alloc(64)
  24041 	defer tls.Free(64)
  24042 	*(*int64_t)(unsafe.Pointer(bp)) = _cost_threshold
  24043 	var sum_cost uint64_t
  24044 	var _ /* bit_cost at bp+8 */ uint64_t
  24045 	var _ /* costs at bp+16 */ [5]uint64_t
  24046 	_ = sum_cost
  24047 	sum_cost = (*VP8LHistogram)(unsafe.Pointer(a)).Fbit_cost + (*VP8LHistogram)(unsafe.Pointer(b)).Fbit_cost
  24048 	SaturateAdd(tls, sum_cost, bp)
  24049 	if !(GetCombinedHistogramEntropy(tls, a, b, **(**int64_t)(__ccgo_up(bp)), bp+8, bp+16) != 0) {
  24050 		return 0
  24051 	}
  24052 	HistogramAdd(tls, a, b, out)
  24053 	UpdateHistogramCost(tls, **(**uint64_t)(__ccgo_up(bp + 8)), bp+16, out)
  24054 	return int32(1)
  24055 }
  24056 
  24057 // C documentation
  24058 //
  24059 //	// Same as HistogramAddEval(), except that the resulting histogram
  24060 //	// is not stored. Only the cost C(a+b) - C(a) is evaluated. We omit
  24061 //	// the term C(b) which is constant over all the evaluations.
  24062 //	// Returns 1 if the cost is less than the threshold.
  24063 //	// Otherwise returns 0 and the cost is invalid due to early bail-out.
  24064 func HistogramAddThresh(tls *libc.TLS, a uintptr, b uintptr, _cost_threshold int64_t, cost_out uintptr) (r int32) {
  24065 	bp := tls.Alloc(64)
  24066 	defer tls.Free(64)
  24067 	*(*int64_t)(unsafe.Pointer(bp)) = _cost_threshold
  24068 	var _ /* cost at bp+8 */ uint64_t
  24069 	var _ /* costs at bp+16 */ [5]uint64_t
  24070 	SaturateAdd(tls, (*VP8LHistogram)(unsafe.Pointer(a)).Fbit_cost, bp)
  24071 	if !(GetCombinedHistogramEntropy(tls, a, b, **(**int64_t)(__ccgo_up(bp)), bp+8, bp+16) != 0) {
  24072 		return 0
  24073 	}
  24074 	**(**int64_t)(__ccgo_up(cost_out)) = int64(**(**uint64_t)(__ccgo_up(bp + 8))) - int64((*VP8LHistogram)(unsafe.Pointer(a)).Fbit_cost)
  24075 	return int32(1)
  24076 }
  24077 
  24078 // -----------------------------------------------------------------------------
  24079 
  24080 // C documentation
  24081 //
  24082 //	// The structure to keep track of cost range for the three dominant entropy
  24083 //	// symbols.
  24084 type DominantCostRange = struct {
  24085 	Fliteral_max uint64_t
  24086 	Fliteral_min uint64_t
  24087 	Fred_max     uint64_t
  24088 	Fred_min     uint64_t
  24089 	Fblue_max    uint64_t
  24090 	Fblue_min    uint64_t
  24091 }
  24092 
  24093 func DominantCostRangeInit(tls *libc.TLS, c uintptr) {
  24094 	(*DominantCostRange)(unsafe.Pointer(c)).Fliteral_max = uint64(0)
  24095 	(*DominantCostRange)(unsafe.Pointer(c)).Fliteral_min = ^libc.Uint64FromUint64(0)
  24096 	(*DominantCostRange)(unsafe.Pointer(c)).Fred_max = uint64(0)
  24097 	(*DominantCostRange)(unsafe.Pointer(c)).Fred_min = ^libc.Uint64FromUint64(0)
  24098 	(*DominantCostRange)(unsafe.Pointer(c)).Fblue_max = uint64(0)
  24099 	(*DominantCostRange)(unsafe.Pointer(c)).Fblue_min = ^libc.Uint64FromUint64(0)
  24100 }
  24101 
  24102 func UpdateDominantCostRange(tls *libc.TLS, h uintptr, c uintptr) {
  24103 	if (*DominantCostRange)(unsafe.Pointer(c)).Fliteral_max < **(**uint64_t)(__ccgo_up(h + 3264 + uintptr(LITERAL)*8)) {
  24104 		(*DominantCostRange)(unsafe.Pointer(c)).Fliteral_max = **(**uint64_t)(__ccgo_up(h + 3264 + uintptr(LITERAL)*8))
  24105 	}
  24106 	if (*DominantCostRange)(unsafe.Pointer(c)).Fliteral_min > **(**uint64_t)(__ccgo_up(h + 3264 + uintptr(LITERAL)*8)) {
  24107 		(*DominantCostRange)(unsafe.Pointer(c)).Fliteral_min = **(**uint64_t)(__ccgo_up(h + 3264 + uintptr(LITERAL)*8))
  24108 	}
  24109 	if (*DominantCostRange)(unsafe.Pointer(c)).Fred_max < **(**uint64_t)(__ccgo_up(h + 3264 + uintptr(RED)*8)) {
  24110 		(*DominantCostRange)(unsafe.Pointer(c)).Fred_max = **(**uint64_t)(__ccgo_up(h + 3264 + uintptr(RED)*8))
  24111 	}
  24112 	if (*DominantCostRange)(unsafe.Pointer(c)).Fred_min > **(**uint64_t)(__ccgo_up(h + 3264 + uintptr(RED)*8)) {
  24113 		(*DominantCostRange)(unsafe.Pointer(c)).Fred_min = **(**uint64_t)(__ccgo_up(h + 3264 + uintptr(RED)*8))
  24114 	}
  24115 	if (*DominantCostRange)(unsafe.Pointer(c)).Fblue_max < **(**uint64_t)(__ccgo_up(h + 3264 + uintptr(BLUE)*8)) {
  24116 		(*DominantCostRange)(unsafe.Pointer(c)).Fblue_max = **(**uint64_t)(__ccgo_up(h + 3264 + uintptr(BLUE)*8))
  24117 	}
  24118 	if (*DominantCostRange)(unsafe.Pointer(c)).Fblue_min > **(**uint64_t)(__ccgo_up(h + 3264 + uintptr(BLUE)*8)) {
  24119 		(*DominantCostRange)(unsafe.Pointer(c)).Fblue_min = **(**uint64_t)(__ccgo_up(h + 3264 + uintptr(BLUE)*8))
  24120 	}
  24121 }
  24122 
  24123 func ComputeHistogramCost(tls *libc.TLS, h uintptr) {
  24124 	bp := tls.Alloc(16)
  24125 	defer tls.Free(16)
  24126 	var i int32
  24127 	var _ /* length at bp+8 */ int32
  24128 	var _ /* population at bp+0 */ uintptr
  24129 	_ = i
  24130 	// No need to add the extra cost for length and distance as it is a constant
  24131 	// that does not influence the histograms.
  24132 	i = 0
  24133 	for {
  24134 		if !(i < int32(5)) {
  24135 			break
  24136 		}
  24137 		GetPopulationInfo(tls, h, i, bp, bp+8)
  24138 		**(**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))
  24139 		goto _1
  24140 	_1:
  24141 		;
  24142 		i = i + 1
  24143 	}
  24144 	(*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))
  24145 }
  24146 
  24147 func GetBinIdForEntropy(tls *libc.TLS, min uint64_t, max uint64_t, val uint64_t) (r int32) {
  24148 	var delta, range1 uint64_t
  24149 	_, _ = delta, range1
  24150 	range1 = max - min
  24151 	if range1 > uint64(0) {
  24152 		delta = val - min
  24153 		return int32(float64((libc.Float64FromInt32(NUM_PARTITIONS)-libc.Float64FromFloat64(1e-06))*float64(delta)) / float64(range1))
  24154 	} else {
  24155 		return 0
  24156 	}
  24157 	return r
  24158 }
  24159 
  24160 func GetHistoBinIndex(tls *libc.TLS, h uintptr, c uintptr, low_effort int32) (r int32) {
  24161 	var bin_id int32
  24162 	_ = bin_id
  24163 	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)))
  24164 	if !(low_effort != 0) {
  24165 		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)))
  24166 		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)))
  24167 	}
  24168 	return bin_id
  24169 }
  24170 
  24171 // C documentation
  24172 //
  24173 //	// Construct the histograms from backward references.
  24174 func HistogramBuild(tls *libc.TLS, xsize int32, histo_bits int32, backward_refs uintptr, image_histo uintptr) {
  24175 	bp := tls.Alloc(32)
  24176 	defer tls.Free(32)
  24177 	var histo_xsize, ix, x, y, v4 int32
  24178 	var histograms, v, v10, v8, v9 uintptr
  24179 	var v1, v2 uint32_t
  24180 	var _ /* c at bp+0 */ VP8LRefsCursor
  24181 	_, _, _, _, _, _, _, _, _, _, _, _ = histo_xsize, histograms, ix, v, x, y, v1, v10, v2, v4, v8, v9
  24182 	x = 0
  24183 	y = 0
  24184 	v1 = uint32(histo_bits)
  24185 	v2 = (uint32(xsize) + uint32(libc.Int32FromInt32(1)<<v1) - uint32(1)) >> v1
  24186 	goto _3
  24187 _3:
  24188 	histo_xsize = int32(v2)
  24189 	histograms = (*VP8LHistogramSet)(unsafe.Pointer(image_histo)).Fhistograms
  24190 	**(**VP8LRefsCursor)(__ccgo_up(bp)) = VP8LRefsCursorInit(tls, backward_refs)
  24191 	VP8LHistogramSetClear(tls, image_histo)
  24192 	for {
  24193 		v4 = libc.BoolInt32((*VP8LRefsCursor)(unsafe.Pointer(bp)).Fcur_pos != libc.UintptrFromInt32(0))
  24194 		goto _5
  24195 	_5:
  24196 		if !(v4 != 0) {
  24197 			break
  24198 		}
  24199 		v = (**(**VP8LRefsCursor)(__ccgo_up(bp))).Fcur_pos
  24200 		ix = y>>histo_bits*histo_xsize + x>>histo_bits
  24201 		HistogramAddSinglePixOrCopy(tls, **(**uintptr)(__ccgo_up(histograms + uintptr(ix)*8)), v, libc.UintptrFromInt32(0), 0)
  24202 		v1 = uint32((*PixOrCopy)(unsafe.Pointer(v)).Flen1)
  24203 		goto _7
  24204 	_7:
  24205 		x = int32(uint32(x) + v1)
  24206 		for x >= xsize {
  24207 			x = x - xsize
  24208 			y = y + 1
  24209 		}
  24210 		v8 = bp
  24211 		v10 = v8
  24212 		*(*uintptr)(unsafe.Pointer(v10)) += 8
  24213 		v9 = *(*uintptr)(unsafe.Pointer(v10))
  24214 		if v9 == (*VP8LRefsCursor)(unsafe.Pointer(v8)).Flast_pos {
  24215 			VP8LRefsCursorNextBlock(tls, v8)
  24216 		}
  24217 	}
  24218 }
  24219 
  24220 // C documentation
  24221 //
  24222 //	// Copies the histograms and computes its bit_cost.
  24223 func HistogramCopyAndAnalyze(tls *libc.TLS, orig_histo uintptr, image_histo uintptr) {
  24224 	var histo, histograms, orig_histograms uintptr
  24225 	var i int32
  24226 	_, _, _, _ = histo, histograms, i, orig_histograms
  24227 	orig_histograms = (*VP8LHistogramSet)(unsafe.Pointer(orig_histo)).Fhistograms
  24228 	histograms = (*VP8LHistogramSet)(unsafe.Pointer(image_histo)).Fhistograms
  24229 	(*VP8LHistogramSet)(unsafe.Pointer(image_histo)).Fsize = 0
  24230 	i = 0
  24231 	for {
  24232 		if !(i < (*VP8LHistogramSet)(unsafe.Pointer(orig_histo)).Fmax_size) {
  24233 			break
  24234 		}
  24235 		histo = **(**uintptr)(__ccgo_up(orig_histograms + uintptr(i)*8))
  24236 		ComputeHistogramCost(tls, histo)
  24237 		// Skip the histogram if it is completely empty, which can happen for tiles
  24238 		// with no information (when they are skipped because of LZ77).
  24239 		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) {
  24240 			// The first histogram is always used.
  24241 			**(**uintptr)(__ccgo_up(orig_histograms + uintptr(i)*8)) = libc.UintptrFromInt32(0)
  24242 		} else {
  24243 			// Copy histograms from orig_histo[] to image_histo[].
  24244 			HistogramCopy(tls, histo, **(**uintptr)(__ccgo_up(histograms + uintptr((*VP8LHistogramSet)(unsafe.Pointer(image_histo)).Fsize)*8)))
  24245 			(*VP8LHistogramSet)(unsafe.Pointer(image_histo)).Fsize = (*VP8LHistogramSet)(unsafe.Pointer(image_histo)).Fsize + 1
  24246 		}
  24247 		goto _1
  24248 	_1:
  24249 		;
  24250 		i = i + 1
  24251 	}
  24252 }
  24253 
  24254 // C documentation
  24255 //
  24256 //	// Partition histograms to different entropy bins for three dominant (literal,
  24257 //	// red and blue) symbol costs and compute the histogram aggregate bit_cost.
  24258 func HistogramAnalyzeEntropyBin(tls *libc.TLS, image_histo uintptr, low_effort int32) {
  24259 	bp := tls.Alloc(48)
  24260 	defer tls.Free(48)
  24261 	var histo_size, i int32
  24262 	var histograms uintptr
  24263 	var _ /* cost_range at bp+0 */ DominantCostRange
  24264 	_, _, _ = histo_size, histograms, i
  24265 	histograms = (*VP8LHistogramSet)(unsafe.Pointer(image_histo)).Fhistograms
  24266 	histo_size = (*VP8LHistogramSet)(unsafe.Pointer(image_histo)).Fsize
  24267 	DominantCostRangeInit(tls, bp)
  24268 	// Analyze the dominant (literal, red and blue) entropy costs.
  24269 	i = 0
  24270 	for {
  24271 		if !(i < histo_size) {
  24272 			break
  24273 		}
  24274 		UpdateDominantCostRange(tls, **(**uintptr)(__ccgo_up(histograms + uintptr(i)*8)), bp)
  24275 		goto _1
  24276 	_1:
  24277 		;
  24278 		i = i + 1
  24279 	}
  24280 	// bin-hash histograms on three of the dominant (literal, red and blue)
  24281 	// symbol costs and store the resulting bin_id for each histogram.
  24282 	i = 0
  24283 	for {
  24284 		if !(i < histo_size) {
  24285 			break
  24286 		}
  24287 		(*VP8LHistogram)(unsafe.Pointer(**(**uintptr)(__ccgo_up(histograms + uintptr(i)*8)))).Fbin_id = uint16(GetHistoBinIndex(tls, **(**uintptr)(__ccgo_up(histograms + uintptr(i)*8)), bp, low_effort))
  24288 		goto _2
  24289 	_2:
  24290 		;
  24291 		i = i + 1
  24292 	}
  24293 }
  24294 
  24295 // C documentation
  24296 //
  24297 //	// Merges some histograms with same bin_id together if it's advantageous.
  24298 //	// Sets the remaining histograms to NULL.
  24299 //	// 'combine_cost_factor' has to be divided by 100.
  24300 func HistogramCombineEntropyBin(tls *libc.TLS, image_histo uintptr, _cur_combo uintptr, num_bins int32, combine_cost_factor int32_t, low_effort int32) {
  24301 	bp := tls.Alloc(16)
  24302 	defer tls.Free(16)
  24303 	*(*uintptr)(unsafe.Pointer(bp)) = _cur_combo
  24304 	var bin_id, first, idx, max_combine_failures, try_combine int32
  24305 	var bin_info [64]struct {
  24306 		Ffirst                int16_t
  24307 		Fnum_combine_failures uint16_t
  24308 	}
  24309 	var bit_cost uint64_t
  24310 	var bit_cost_thresh, v3, v4, v5 int64_t
  24311 	var histograms uintptr
  24312 	var v7 int64
  24313 	_, _, _, _, _, _, _, _, _, _, _, _, _ = bin_id, bin_info, bit_cost, bit_cost_thresh, first, histograms, idx, max_combine_failures, try_combine, v3, v4, v5, v7
  24314 	histograms = (*VP8LHistogramSet)(unsafe.Pointer(image_histo)).Fhistograms
  24315 	idx = 0
  24316 	for {
  24317 		if !(idx < num_bins) {
  24318 			break
  24319 		}
  24320 		bin_info[idx].Ffirst = int16(-int32(1))
  24321 		bin_info[idx].Fnum_combine_failures = uint16(0)
  24322 		goto _1
  24323 	_1:
  24324 		;
  24325 		idx = idx + 1
  24326 	}
  24327 	idx = 0
  24328 	for {
  24329 		if !(idx < (*VP8LHistogramSet)(unsafe.Pointer(image_histo)).Fsize) {
  24330 			break
  24331 		}
  24332 		bin_id = int32((*VP8LHistogram)(unsafe.Pointer(**(**uintptr)(__ccgo_up(histograms + uintptr(idx)*8)))).Fbin_id)
  24333 		first = int32(bin_info[bin_id].Ffirst)
  24334 		if first == -int32(1) {
  24335 			bin_info[bin_id].Ffirst = int16(idx)
  24336 			idx = idx + 1
  24337 		} else {
  24338 			if low_effort != 0 {
  24339 				HistogramAdd(tls, **(**uintptr)(__ccgo_up(histograms + uintptr(idx)*8)), **(**uintptr)(__ccgo_up(histograms + uintptr(first)*8)), **(**uintptr)(__ccgo_up(histograms + uintptr(first)*8)))
  24340 				HistogramSetRemoveHistogram(tls, image_histo, idx)
  24341 			} else {
  24342 				// try to merge #idx into #first (both share the same bin_id)
  24343 				bit_cost = (*VP8LHistogram)(unsafe.Pointer(**(**uintptr)(__ccgo_up(histograms + uintptr(idx)*8)))).Fbit_cost
  24344 				v3 = int64(bit_cost) * int64(combine_cost_factor)
  24345 				v4 = int64(100)
  24346 				if libc.BoolInt32(v3 < 0) == libc.BoolInt32(v4 < 0) {
  24347 					v7 = (v3 + v4/int64(2)) / v4
  24348 				} else {
  24349 					v7 = (v3 - v4/int64(2)) / v4
  24350 				}
  24351 				v5 = v7
  24352 				goto _6
  24353 			_6:
  24354 				bit_cost_thresh = -v5
  24355 				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 {
  24356 					max_combine_failures = int32(32)
  24357 					// Try to merge two histograms only if the combo is a trivial one or
  24358 					// the two candidate histograms are already non-trivial.
  24359 					// For some images, 'try_combine' turns out to be false for a lot of
  24360 					// histogram pairs. In that case, we fallback to combining
  24361 					// histograms as usual to avoid increasing the header size.
  24362 					try_combine = libc.BoolInt32(int32(**(**uint16_t)(__ccgo_up(**(**uintptr)(__ccgo_up(bp)) + 3244 + uintptr(RED)*2))) != int32(uint16(libc.Int32FromInt32(0xffff))) && int32(**(**uint16_t)(__ccgo_up(**(**uintptr)(__ccgo_up(bp)) + 3244 + uintptr(BLUE)*2))) != int32(uint16(libc.Int32FromInt32(0xffff))) && int32(**(**uint16_t)(__ccgo_up(**(**uintptr)(__ccgo_up(bp)) + 3244 + uintptr(ALPHA)*2))) != int32(uint16(libc.Int32FromInt32(0xffff))))
  24363 					if !(try_combine != 0) {
  24364 						try_combine = libc.BoolInt32(int32(**(**uint16_t)(__ccgo_up(**(**uintptr)(__ccgo_up(histograms + uintptr(idx)*8)) + 3244 + uintptr(RED)*2))) == int32(uint16(libc.Int32FromInt32(0xffff))) || int32(**(**uint16_t)(__ccgo_up(**(**uintptr)(__ccgo_up(histograms + uintptr(idx)*8)) + 3244 + uintptr(BLUE)*2))) == int32(uint16(libc.Int32FromInt32(0xffff))) || int32(**(**uint16_t)(__ccgo_up(**(**uintptr)(__ccgo_up(histograms + uintptr(idx)*8)) + 3244 + uintptr(ALPHA)*2))) == int32(uint16(libc.Int32FromInt32(0xffff))))
  24365 						try_combine = try_combine & libc.BoolInt32(int32(**(**uint16_t)(__ccgo_up(**(**uintptr)(__ccgo_up(histograms + uintptr(first)*8)) + 3244 + uintptr(RED)*2))) == int32(uint16(libc.Int32FromInt32(0xffff))) || int32(**(**uint16_t)(__ccgo_up(**(**uintptr)(__ccgo_up(histograms + uintptr(first)*8)) + 3244 + uintptr(BLUE)*2))) == int32(uint16(libc.Int32FromInt32(0xffff))) || int32(**(**uint16_t)(__ccgo_up(**(**uintptr)(__ccgo_up(histograms + uintptr(first)*8)) + 3244 + uintptr(ALPHA)*2))) == int32(uint16(libc.Int32FromInt32(0xffff))))
  24366 					}
  24367 					if try_combine != 0 || int32(bin_info[bin_id].Fnum_combine_failures) >= max_combine_failures {
  24368 						// move the (better) merged histogram to its final slot
  24369 						HistogramSwap(tls, bp, histograms+uintptr(first)*8)
  24370 						HistogramSetRemoveHistogram(tls, image_histo, idx)
  24371 					} else {
  24372 						bin_info[bin_id].Fnum_combine_failures = bin_info[bin_id].Fnum_combine_failures + 1
  24373 						idx = idx + 1
  24374 					}
  24375 				} else {
  24376 					idx = idx + 1
  24377 				}
  24378 			}
  24379 		}
  24380 		goto _2
  24381 	_2:
  24382 	}
  24383 	if low_effort != 0 {
  24384 		// for low_effort case, update the final cost when everything is merged
  24385 		idx = 0
  24386 		for {
  24387 			if !(idx < (*VP8LHistogramSet)(unsafe.Pointer(image_histo)).Fsize) {
  24388 				break
  24389 			}
  24390 			ComputeHistogramCost(tls, **(**uintptr)(__ccgo_up(histograms + uintptr(idx)*8)))
  24391 			goto _8
  24392 		_8:
  24393 			;
  24394 			idx = idx + 1
  24395 		}
  24396 	}
  24397 }
  24398 
  24399 // C documentation
  24400 //
  24401 //	// Implement a Lehmer random number generator with a multiplicative constant of
  24402 //	// 48271 and a modulo constant of 2^31 - 1.
  24403 func MyRand(tls *libc.TLS, seed uintptr) (r uint32_t) {
  24404 	**(**uint32_t)(__ccgo_up(seed)) = uint32(uint64(**(**uint32_t)(__ccgo_up(seed))) * libc.Uint64FromUint32(48271) % libc.Uint64FromUint32(2147483647))
  24405 	return **(**uint32_t)(__ccgo_up(seed))
  24406 }
  24407 
  24408 // -----------------------------------------------------------------------------
  24409 // Histogram pairs priority queue
  24410 
  24411 // C documentation
  24412 //
  24413 //	// Pair of histograms. Negative idx1 value means that pair is out-of-date.
  24414 type HistogramPair = struct {
  24415 	Fidx1       int32
  24416 	Fidx2       int32
  24417 	Fcost_diff  int64_t
  24418 	Fcost_combo uint64_t
  24419 	Fcosts      [5]uint64_t
  24420 }
  24421 
  24422 type HistoQueue = struct {
  24423 	Fqueue    uintptr
  24424 	Fsize     int32
  24425 	Fmax_size int32
  24426 }
  24427 
  24428 func HistoQueueInit(tls *libc.TLS, histo_queue uintptr, max_size int32) (r int32) {
  24429 	(*HistoQueue)(unsafe.Pointer(histo_queue)).Fsize = 0
  24430 	(*HistoQueue)(unsafe.Pointer(histo_queue)).Fmax_size = max_size
  24431 	// We allocate max_size + 1 because the last element at index "size" is
  24432 	// used as temporary data (and it could be up to max_size).
  24433 	(*HistoQueue)(unsafe.Pointer(histo_queue)).Fqueue = WebPSafeMalloc(tls, uint64((*HistoQueue)(unsafe.Pointer(histo_queue)).Fmax_size+int32(1)), uint64(64))
  24434 	return libc.BoolInt32((*HistoQueue)(unsafe.Pointer(histo_queue)).Fqueue != libc.UintptrFromInt32(0))
  24435 }
  24436 
  24437 func HistoQueueClear(tls *libc.TLS, histo_queue uintptr) {
  24438 	WebPSafeFree(tls, (*HistoQueue)(unsafe.Pointer(histo_queue)).Fqueue)
  24439 	(*HistoQueue)(unsafe.Pointer(histo_queue)).Fsize = 0
  24440 	(*HistoQueue)(unsafe.Pointer(histo_queue)).Fmax_size = 0
  24441 }
  24442 
  24443 // C documentation
  24444 //
  24445 //	// Pop a specific pair in the queue by replacing it with the last one
  24446 //	// and shrinking the queue.
  24447 func HistoQueuePopPair(tls *libc.TLS, histo_queue uintptr, pair uintptr) {
  24448 	**(**HistogramPair)(__ccgo_up(pair)) = **(**HistogramPair)(__ccgo_up((*HistoQueue)(unsafe.Pointer(histo_queue)).Fqueue + uintptr((*HistoQueue)(unsafe.Pointer(histo_queue)).Fsize-int32(1))*64))
  24449 	(*HistoQueue)(unsafe.Pointer(histo_queue)).Fsize = (*HistoQueue)(unsafe.Pointer(histo_queue)).Fsize - 1
  24450 }
  24451 
  24452 // C documentation
  24453 //
  24454 //	// Check whether a pair in the queue should be updated as head or not.
  24455 func HistoQueueUpdateHead(tls *libc.TLS, histo_queue uintptr, pair uintptr) {
  24456 	var tmp HistogramPair
  24457 	_ = tmp
  24458 	if (*HistogramPair)(unsafe.Pointer(pair)).Fcost_diff < (**(**HistogramPair)(__ccgo_up((*HistoQueue)(unsafe.Pointer(histo_queue)).Fqueue))).Fcost_diff {
  24459 		// Replace the best pair.
  24460 		tmp = **(**HistogramPair)(__ccgo_up((*HistoQueue)(unsafe.Pointer(histo_queue)).Fqueue))
  24461 		**(**HistogramPair)(__ccgo_up((*HistoQueue)(unsafe.Pointer(histo_queue)).Fqueue)) = **(**HistogramPair)(__ccgo_up(pair))
  24462 		**(**HistogramPair)(__ccgo_up(pair)) = tmp
  24463 	}
  24464 }
  24465 
  24466 // C documentation
  24467 //
  24468 //	// Replaces the bad_id with good_id in the pair.
  24469 func HistoQueueFixPair(tls *libc.TLS, bad_id int32, good_id int32, pair uintptr) {
  24470 	var tmp int32
  24471 	_ = tmp
  24472 	if (*HistogramPair)(unsafe.Pointer(pair)).Fidx1 == bad_id {
  24473 		(*HistogramPair)(unsafe.Pointer(pair)).Fidx1 = good_id
  24474 	}
  24475 	if (*HistogramPair)(unsafe.Pointer(pair)).Fidx2 == bad_id {
  24476 		(*HistogramPair)(unsafe.Pointer(pair)).Fidx2 = good_id
  24477 	}
  24478 	if (*HistogramPair)(unsafe.Pointer(pair)).Fidx1 > (*HistogramPair)(unsafe.Pointer(pair)).Fidx2 {
  24479 		tmp = (*HistogramPair)(unsafe.Pointer(pair)).Fidx1
  24480 		(*HistogramPair)(unsafe.Pointer(pair)).Fidx1 = (*HistogramPair)(unsafe.Pointer(pair)).Fidx2
  24481 		(*HistogramPair)(unsafe.Pointer(pair)).Fidx2 = tmp
  24482 	}
  24483 }
  24484 
  24485 // C documentation
  24486 //
  24487 //	// Update the cost diff and combo of a pair of histograms. This needs to be
  24488 //	// called when the histograms have been merged with a third one.
  24489 //	// Returns 1 if the cost diff is less than the threshold.
  24490 //	// Otherwise returns 0 and the cost is invalid due to early bail-out.
  24491 func HistoQueueUpdatePair(tls *libc.TLS, h1 uintptr, h2 uintptr, _cost_threshold int64_t, pair uintptr) (r int32) {
  24492 	bp := tls.Alloc(16)
  24493 	defer tls.Free(16)
  24494 	*(*int64_t)(unsafe.Pointer(bp)) = _cost_threshold
  24495 	var sum_cost int64_t
  24496 	_ = sum_cost
  24497 	sum_cost = int64((*VP8LHistogram)(unsafe.Pointer(h1)).Fbit_cost + (*VP8LHistogram)(unsafe.Pointer(h2)).Fbit_cost)
  24498 	SaturateAdd(tls, uint64(sum_cost), bp)
  24499 	if !(GetCombinedHistogramEntropy(tls, h1, h2, **(**int64_t)(__ccgo_up(bp)), pair+16, pair+24) != 0) {
  24500 		return 0
  24501 	}
  24502 	(*HistogramPair)(unsafe.Pointer(pair)).Fcost_diff = int64((*HistogramPair)(unsafe.Pointer(pair)).Fcost_combo) - sum_cost
  24503 	return int32(1)
  24504 }
  24505 
  24506 // C documentation
  24507 //
  24508 //	// Create a pair from indices "idx1" and "idx2" provided its cost
  24509 //	// is inferior to "threshold", a negative entropy.
  24510 //	// It returns the cost of the pair, or 0 if it superior to threshold.
  24511 func HistoQueuePush(tls *libc.TLS, histo_queue uintptr, histograms uintptr, idx1 int32, idx2 int32, threshold int64_t) (r int64_t) {
  24512 	bp := tls.Alloc(64)
  24513 	defer tls.Free(64)
  24514 	var h1, h2, v2 uintptr
  24515 	var tmp, v1 int32
  24516 	var _ /* pair at bp+0 */ HistogramPair
  24517 	_, _, _, _, _ = h1, h2, tmp, v1, v2
  24518 	// Stop here if the queue is full.
  24519 	if (*HistoQueue)(unsafe.Pointer(histo_queue)).Fsize == (*HistoQueue)(unsafe.Pointer(histo_queue)).Fmax_size {
  24520 		return 0
  24521 	}
  24522 	if idx1 > idx2 {
  24523 		tmp = idx2
  24524 		idx2 = idx1
  24525 		idx1 = tmp
  24526 	}
  24527 	(**(**HistogramPair)(__ccgo_up(bp))).Fidx1 = idx1
  24528 	(**(**HistogramPair)(__ccgo_up(bp))).Fidx2 = idx2
  24529 	h1 = **(**uintptr)(__ccgo_up(histograms + uintptr(idx1)*8))
  24530 	h2 = **(**uintptr)(__ccgo_up(histograms + uintptr(idx2)*8))
  24531 	// Do not even consider the pair if it does not improve the entropy.
  24532 	if !(HistoQueueUpdatePair(tls, h1, h2, threshold, bp) != 0) {
  24533 		return 0
  24534 	}
  24535 	v2 = histo_queue + 8
  24536 	v1 = *(*int32)(unsafe.Pointer(v2))
  24537 	*(*int32)(unsafe.Pointer(v2)) = *(*int32)(unsafe.Pointer(v2)) + 1
  24538 	**(**HistogramPair)(__ccgo_up((*HistoQueue)(unsafe.Pointer(histo_queue)).Fqueue + uintptr(v1)*64)) = **(**HistogramPair)(__ccgo_up(bp))
  24539 	HistoQueueUpdateHead(tls, histo_queue, (*HistoQueue)(unsafe.Pointer(histo_queue)).Fqueue+uintptr((*HistoQueue)(unsafe.Pointer(histo_queue)).Fsize-int32(1))*64)
  24540 	return (**(**HistogramPair)(__ccgo_up(bp))).Fcost_diff
  24541 }
  24542 
  24543 // -----------------------------------------------------------------------------
  24544 
  24545 // C documentation
  24546 //
  24547 //	// Combines histograms by continuously choosing the one with the highest cost
  24548 //	// reduction.
  24549 func HistogramCombineGreedy(tls *libc.TLS, image_histo uintptr) (r int32) {
  24550 	bp := tls.Alloc(16)
  24551 	defer tls.Free(16)
  24552 	var histograms, p uintptr
  24553 	var i, idx1, idx2, image_histo_size, j, ok int32
  24554 	var _ /* histo_queue at bp+0 */ HistoQueue
  24555 	_, _, _, _, _, _, _, _ = histograms, i, idx1, idx2, image_histo_size, j, ok, p
  24556 	ok = 0
  24557 	image_histo_size = (*VP8LHistogramSet)(unsafe.Pointer(image_histo)).Fsize
  24558 	histograms = (*VP8LHistogramSet)(unsafe.Pointer(image_histo)).Fhistograms
  24559 	// image_histo_size^2 for the queue size is safe. If you look at
  24560 	// HistogramCombineGreedy, and imagine that UpdateQueueFront always pushes
  24561 	// data to the queue, you insert at most:
  24562 	// - image_histo_size*(image_histo_size-1)/2 (the first two for loops)
  24563 	// - image_histo_size - 1 in the last for loop at the first iteration of
  24564 	//   the while loop, image_histo_size - 2 at the second iteration ...
  24565 	//   therefore image_histo_size*(image_histo_size-1)/2 overall too
  24566 	if !(HistoQueueInit(tls, bp, image_histo_size*image_histo_size) != 0) {
  24567 		goto End
  24568 	}
  24569 	// Initialize the queue.
  24570 	i = 0
  24571 	for {
  24572 		if !(i < image_histo_size) {
  24573 			break
  24574 		}
  24575 		j = i + int32(1)
  24576 		for {
  24577 			if !(j < image_histo_size) {
  24578 				break
  24579 			}
  24580 			HistoQueuePush(tls, bp, histograms, i, j, 0)
  24581 			goto _2
  24582 		_2:
  24583 			;
  24584 			j = j + 1
  24585 		}
  24586 		goto _1
  24587 	_1:
  24588 		;
  24589 		i = i + 1
  24590 	}
  24591 	for (**(**HistoQueue)(__ccgo_up(bp))).Fsize > 0 {
  24592 		idx1 = (**(**HistogramPair)(__ccgo_up((**(**HistoQueue)(__ccgo_up(bp))).Fqueue))).Fidx1
  24593 		idx2 = (**(**HistogramPair)(__ccgo_up((**(**HistoQueue)(__ccgo_up(bp))).Fqueue))).Fidx2
  24594 		HistogramAdd(tls, **(**uintptr)(__ccgo_up(histograms + uintptr(idx2)*8)), **(**uintptr)(__ccgo_up(histograms + uintptr(idx1)*8)), **(**uintptr)(__ccgo_up(histograms + uintptr(idx1)*8)))
  24595 		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)))
  24596 		// Remove merged histogram.
  24597 		HistogramSetRemoveHistogram(tls, image_histo, idx2)
  24598 		// Remove pairs intersecting the just combined best pair.
  24599 		i = 0
  24600 		for {
  24601 			if !(i < (**(**HistoQueue)(__ccgo_up(bp))).Fsize) {
  24602 				break
  24603 			}
  24604 			p = (**(**HistoQueue)(__ccgo_up(bp))).Fqueue + uintptr(i)*64
  24605 			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 {
  24606 				HistoQueuePopPair(tls, bp, p)
  24607 			} else {
  24608 				HistoQueueFixPair(tls, (*VP8LHistogramSet)(unsafe.Pointer(image_histo)).Fsize, idx2, p)
  24609 				HistoQueueUpdateHead(tls, bp, p)
  24610 				i = i + 1
  24611 			}
  24612 			goto _3
  24613 		_3:
  24614 		}
  24615 		// Push new pairs formed with combined histogram to the queue.
  24616 		i = 0
  24617 		for {
  24618 			if !(i < (*VP8LHistogramSet)(unsafe.Pointer(image_histo)).Fsize) {
  24619 				break
  24620 			}
  24621 			if i == idx1 {
  24622 				goto _4
  24623 			}
  24624 			HistoQueuePush(tls, bp, (*VP8LHistogramSet)(unsafe.Pointer(image_histo)).Fhistograms, idx1, i, 0)
  24625 			goto _4
  24626 		_4:
  24627 			;
  24628 			i = i + 1
  24629 		}
  24630 	}
  24631 	ok = int32(1)
  24632 	goto End
  24633 End:
  24634 	;
  24635 	HistoQueueClear(tls, bp)
  24636 	return ok
  24637 }
  24638 
  24639 // C documentation
  24640 //
  24641 //	// Perform histogram aggregation using a stochastic approach.
  24642 //	// 'do_greedy' is set to 1 if a greedy approach needs to be performed
  24643 //	// afterwards, 0 otherwise.
  24644 func HistogramCombineStochastic(tls *libc.TLS, image_histo uintptr, min_cluster_size int32, do_greedy uintptr) (r int32) {
  24645 	bp := tls.Alloc(32)
  24646 	defer tls.Free(32)
  24647 	var best_cost, curr_cost int64_t
  24648 	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
  24649 	var histograms, p uintptr
  24650 	var idx1, idx2, rand_range, tmp uint32_t
  24651 	var v3 bool
  24652 	var v4 int64
  24653 	var _ /* histo_queue at bp+8 */ HistoQueue
  24654 	var _ /* seed at bp+0 */ uint32_t
  24655 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  24656 	**(**uint32_t)(__ccgo_up(bp)) = uint32(1)
  24657 	tries_with_no_success = 0
  24658 	outer_iters = (*VP8LHistogramSet)(unsafe.Pointer(image_histo)).Fsize
  24659 	num_tries_no_success = outer_iters / int32(2)
  24660 	histograms = (*VP8LHistogramSet)(unsafe.Pointer(image_histo)).Fhistograms
  24661 	kHistoQueueSize = int32(9)
  24662 	ok = 0
  24663 	if (*VP8LHistogramSet)(unsafe.Pointer(image_histo)).Fsize < min_cluster_size {
  24664 		**(**int32)(__ccgo_up(do_greedy)) = int32(1)
  24665 		return int32(1)
  24666 	}
  24667 	if !(HistoQueueInit(tls, bp+8, kHistoQueueSize) != 0) {
  24668 		goto End
  24669 	}
  24670 	// Collapse similar histograms in 'image_histo'.
  24671 	iter = 0
  24672 	for {
  24673 		if v3 = iter < outer_iters && (*VP8LHistogramSet)(unsafe.Pointer(image_histo)).Fsize >= min_cluster_size; v3 {
  24674 			tries_with_no_success = tries_with_no_success + 1
  24675 			v2 = tries_with_no_success
  24676 		}
  24677 		if !(v3 && v2 < num_tries_no_success) {
  24678 			break
  24679 		}
  24680 		if (**(**HistoQueue)(__ccgo_up(bp + 8))).Fsize == 0 {
  24681 			v4 = 0
  24682 		} else {
  24683 			v4 = (**(**HistogramPair)(__ccgo_up((**(**HistoQueue)(__ccgo_up(bp + 8))).Fqueue))).Fcost_diff
  24684 		}
  24685 		best_cost = v4
  24686 		best_idx1 = -int32(1)
  24687 		best_idx2 = int32(1)
  24688 		rand_range = uint32(((*VP8LHistogramSet)(unsafe.Pointer(image_histo)).Fsize - int32(1)) * (*VP8LHistogramSet)(unsafe.Pointer(image_histo)).Fsize)
  24689 		// (image_histo->size) / 2 was chosen empirically. Less means faster but
  24690 		// worse compression.
  24691 		num_tries = (*VP8LHistogramSet)(unsafe.Pointer(image_histo)).Fsize / int32(2)
  24692 		// Pick random samples.
  24693 		j = 0
  24694 		for {
  24695 			if !((*VP8LHistogramSet)(unsafe.Pointer(image_histo)).Fsize >= int32(2) && j < num_tries) {
  24696 				break
  24697 			}
  24698 			// Choose two different histograms at random and try to combine them.
  24699 			tmp = MyRand(tls, bp) % rand_range
  24700 			idx1 = tmp / uint32((*VP8LHistogramSet)(unsafe.Pointer(image_histo)).Fsize-libc.Int32FromInt32(1))
  24701 			idx2 = tmp % uint32((*VP8LHistogramSet)(unsafe.Pointer(image_histo)).Fsize-libc.Int32FromInt32(1))
  24702 			if idx2 >= idx1 {
  24703 				idx2 = idx2 + 1
  24704 			}
  24705 			// Calculate cost reduction on combination.
  24706 			curr_cost = HistoQueuePush(tls, bp+8, histograms, int32(idx1), int32(idx2), best_cost)
  24707 			if curr_cost < 0 { // found a better pair?
  24708 				best_cost = curr_cost
  24709 				// Empty the queue if we reached full capacity.
  24710 				if (**(**HistoQueue)(__ccgo_up(bp + 8))).Fsize == (**(**HistoQueue)(__ccgo_up(bp + 8))).Fmax_size {
  24711 					break
  24712 				}
  24713 			}
  24714 			goto _5
  24715 		_5:
  24716 			;
  24717 			j = j + 1
  24718 		}
  24719 		if (**(**HistoQueue)(__ccgo_up(bp + 8))).Fsize == 0 {
  24720 			goto _1
  24721 		}
  24722 		// Get the best histograms.
  24723 		best_idx1 = (**(**HistogramPair)(__ccgo_up((**(**HistoQueue)(__ccgo_up(bp + 8))).Fqueue))).Fidx1
  24724 		best_idx2 = (**(**HistogramPair)(__ccgo_up((**(**HistoQueue)(__ccgo_up(bp + 8))).Fqueue))).Fidx2
  24725 		// Merge the histograms and remove best_idx2 from the queue.
  24726 		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)))
  24727 		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)))
  24728 		HistogramSetRemoveHistogram(tls, image_histo, best_idx2)
  24729 		// Parse the queue and update each pair that deals with best_idx1,
  24730 		// best_idx2 or image_histo_size.
  24731 		j = 0
  24732 		for {
  24733 			if !(j < (**(**HistoQueue)(__ccgo_up(bp + 8))).Fsize) {
  24734 				break
  24735 			}
  24736 			p = (**(**HistoQueue)(__ccgo_up(bp + 8))).Fqueue + uintptr(j)*64
  24737 			is_idx1_best = libc.BoolInt32((*HistogramPair)(unsafe.Pointer(p)).Fidx1 == best_idx1 || (*HistogramPair)(unsafe.Pointer(p)).Fidx1 == best_idx2)
  24738 			is_idx2_best = libc.BoolInt32((*HistogramPair)(unsafe.Pointer(p)).Fidx2 == best_idx1 || (*HistogramPair)(unsafe.Pointer(p)).Fidx2 == best_idx2)
  24739 			// The front pair could have been duplicated by a random pick so
  24740 			// check for it all the time nevertheless.
  24741 			if is_idx1_best != 0 && is_idx2_best != 0 {
  24742 				HistoQueuePopPair(tls, bp+8, p)
  24743 				goto _6
  24744 			}
  24745 			// Any pair containing one of the two best indices should only refer to
  24746 			// best_idx1. Its cost should also be updated.
  24747 			if is_idx1_best != 0 || is_idx2_best != 0 {
  24748 				HistoQueueFixPair(tls, best_idx2, best_idx1, p)
  24749 				// Re-evaluate the cost of an updated pair.
  24750 				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) {
  24751 					HistoQueuePopPair(tls, bp+8, p)
  24752 					goto _6
  24753 				}
  24754 			}
  24755 			HistoQueueFixPair(tls, (*VP8LHistogramSet)(unsafe.Pointer(image_histo)).Fsize, best_idx2, p)
  24756 			HistoQueueUpdateHead(tls, bp+8, p)
  24757 			j = j + 1
  24758 			goto _6
  24759 		_6:
  24760 		}
  24761 		tries_with_no_success = 0
  24762 		goto _1
  24763 	_1:
  24764 		;
  24765 		iter = iter + 1
  24766 	}
  24767 	**(**int32)(__ccgo_up(do_greedy)) = libc.BoolInt32((*VP8LHistogramSet)(unsafe.Pointer(image_histo)).Fsize <= min_cluster_size)
  24768 	ok = int32(1)
  24769 	goto End
  24770 End:
  24771 	;
  24772 	HistoQueueClear(tls, bp+8)
  24773 	return ok
  24774 }
  24775 
  24776 // -----------------------------------------------------------------------------
  24777 // Histogram refinement
  24778 
  24779 // C documentation
  24780 //
  24781 //	// Find the best 'out' histogram for each of the 'in' histograms.
  24782 //	// At call-time, 'out' contains the histograms of the clusters.
  24783 //	// Note: we assume that out[]->bit_cost is already up-to-date.
  24784 func HistogramRemap(tls *libc.TLS, in uintptr, out uintptr, symbols uintptr) {
  24785 	bp := tls.Alloc(16)
  24786 	defer tls.Free(16)
  24787 	var best_bits int64_t
  24788 	var best_out, i, idx, in_size, k, out_size int32
  24789 	var in_histo, out_histo uintptr
  24790 	var _ /* cur_bits at bp+0 */ int64_t
  24791 	_, _, _, _, _, _, _, _, _ = best_bits, best_out, i, idx, in_histo, in_size, k, out_histo, out_size
  24792 	in_histo = (*VP8LHistogramSet)(unsafe.Pointer(in)).Fhistograms
  24793 	out_histo = (*VP8LHistogramSet)(unsafe.Pointer(out)).Fhistograms
  24794 	in_size = (*VP8LHistogramSet)(unsafe.Pointer(out)).Fmax_size
  24795 	out_size = (*VP8LHistogramSet)(unsafe.Pointer(out)).Fsize
  24796 	if out_size > int32(1) {
  24797 		i = 0
  24798 		for {
  24799 			if !(i < in_size) {
  24800 				break
  24801 			}
  24802 			best_out = 0
  24803 			best_bits = int64(libc.Uint64FromUint64(1)<<libc.Int32FromInt32(63) - libc.Uint64FromInt32(1))
  24804 			if **(**uintptr)(__ccgo_up(in_histo + uintptr(i)*8)) == libc.UintptrFromInt32(0) {
  24805 				// Arbitrarily set to the previous value if unused to help future LZ77.
  24806 				**(**uint32_t)(__ccgo_up(symbols + uintptr(i)*4)) = **(**uint32_t)(__ccgo_up(symbols + uintptr(i-int32(1))*4))
  24807 				goto _1
  24808 			}
  24809 			k = 0
  24810 			for {
  24811 				if !(k < out_size) {
  24812 					break
  24813 				}
  24814 				if HistogramAddThresh(tls, **(**uintptr)(__ccgo_up(out_histo + uintptr(k)*8)), **(**uintptr)(__ccgo_up(in_histo + uintptr(i)*8)), best_bits, bp) != 0 {
  24815 					best_bits = **(**int64_t)(__ccgo_up(bp))
  24816 					best_out = k
  24817 				}
  24818 				goto _2
  24819 			_2:
  24820 				;
  24821 				k = k + 1
  24822 			}
  24823 			**(**uint32_t)(__ccgo_up(symbols + uintptr(i)*4)) = uint32(best_out)
  24824 			goto _1
  24825 		_1:
  24826 			;
  24827 			i = i + 1
  24828 		}
  24829 	} else {
  24830 		i = 0
  24831 		for {
  24832 			if !(i < in_size) {
  24833 				break
  24834 			}
  24835 			**(**uint32_t)(__ccgo_up(symbols + uintptr(i)*4)) = uint32(0)
  24836 			goto _3
  24837 		_3:
  24838 			;
  24839 			i = i + 1
  24840 		}
  24841 	}
  24842 	// Recompute each out based on raw and symbols.
  24843 	VP8LHistogramSetClear(tls, out)
  24844 	(*VP8LHistogramSet)(unsafe.Pointer(out)).Fsize = out_size
  24845 	i = 0
  24846 	for {
  24847 		if !(i < in_size) {
  24848 			break
  24849 		}
  24850 		if **(**uintptr)(__ccgo_up(in_histo + uintptr(i)*8)) == libc.UintptrFromInt32(0) {
  24851 			goto _4
  24852 		}
  24853 		idx = int32(**(**uint32_t)(__ccgo_up(symbols + uintptr(i)*4)))
  24854 		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)))
  24855 		goto _4
  24856 	_4:
  24857 		;
  24858 		i = i + 1
  24859 	}
  24860 }
  24861 
  24862 func GetCombineCostFactor(tls *libc.TLS, histo_size int32, quality int32) (r int32_t) {
  24863 	var combine_cost_factor int32_t
  24864 	_ = combine_cost_factor
  24865 	combine_cost_factor = int32(16)
  24866 	if quality < int32(90) {
  24867 		if histo_size > int32(256) {
  24868 			combine_cost_factor = combine_cost_factor / int32(2)
  24869 		}
  24870 		if histo_size > int32(512) {
  24871 			combine_cost_factor = combine_cost_factor / int32(2)
  24872 		}
  24873 		if histo_size > int32(1024) {
  24874 			combine_cost_factor = combine_cost_factor / int32(2)
  24875 		}
  24876 		if quality <= int32(50) {
  24877 			combine_cost_factor = combine_cost_factor / int32(2)
  24878 		}
  24879 	}
  24880 	return combine_cost_factor
  24881 }
  24882 
  24883 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) {
  24884 	bp := tls.Alloc(16)
  24885 	defer tls.Free(16)
  24886 	var combine_cost_factor int32_t
  24887 	var entropy_combine, entropy_combine_num_bins, histo_xsize, histo_ysize, image_histo_raw_size, threshold_size, v9 int32
  24888 	var orig_histo uintptr
  24889 	var v1, v5 uint32
  24890 	var v10, v11, v12 int64_t
  24891 	var v14 int64
  24892 	var v2, v3, v6, v7 uint32_t
  24893 	var _ /* do_greedy at bp+0 */ int32
  24894 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  24895 	if histogram_bits != 0 {
  24896 		v2 = uint32(histogram_bits)
  24897 		v3 = (uint32(xsize) + uint32(libc.Int32FromInt32(1)<<v2) - uint32(1)) >> v2
  24898 		goto _4
  24899 	_4:
  24900 		v1 = v3
  24901 	} else {
  24902 		v1 = uint32(1)
  24903 	}
  24904 	histo_xsize = int32(v1)
  24905 	if histogram_bits != 0 {
  24906 		v6 = uint32(histogram_bits)
  24907 		v7 = (uint32(ysize) + uint32(libc.Int32FromInt32(1)<<v6) - uint32(1)) >> v6
  24908 		goto _8
  24909 	_8:
  24910 		v5 = v7
  24911 	} else {
  24912 		v5 = uint32(1)
  24913 	}
  24914 	histo_ysize = int32(v5)
  24915 	image_histo_raw_size = histo_xsize * histo_ysize
  24916 	orig_histo = VP8LAllocateHistogramSet(tls, image_histo_raw_size, cache_bits)
  24917 	if low_effort != 0 {
  24918 		v9 = int32(NUM_PARTITIONS)
  24919 	} else {
  24920 		v9 = libc.Int32FromInt32(NUM_PARTITIONS) * libc.Int32FromInt32(NUM_PARTITIONS) * libc.Int32FromInt32(NUM_PARTITIONS)
  24921 	}
  24922 	// Don't attempt linear bin-partition heuristic for
  24923 	// histograms of small sizes (as bin_map will be very sparse) and
  24924 	// maximum quality q==100 (to preserve the compression gains at that level).
  24925 	entropy_combine_num_bins = v9
  24926 	if orig_histo == libc.UintptrFromInt32(0) {
  24927 		WebPEncodingSetError(tls, pic, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  24928 		goto Error
  24929 	}
  24930 	// Construct the histograms from backward references.
  24931 	HistogramBuild(tls, xsize, histogram_bits, refs, orig_histo)
  24932 	HistogramCopyAndAnalyze(tls, orig_histo, image_histo)
  24933 	entropy_combine = libc.BoolInt32((*VP8LHistogramSet)(unsafe.Pointer(image_histo)).Fsize > entropy_combine_num_bins*int32(2) && quality < int32(100))
  24934 	if entropy_combine != 0 {
  24935 		combine_cost_factor = GetCombineCostFactor(tls, image_histo_raw_size, quality)
  24936 		HistogramAnalyzeEntropyBin(tls, image_histo, low_effort)
  24937 		// Collapse histograms with similar entropy.
  24938 		HistogramCombineEntropyBin(tls, image_histo, tmp_histo, entropy_combine_num_bins, combine_cost_factor, low_effort)
  24939 	}
  24940 	// Don't combine the histograms using stochastic and greedy heuristics for
  24941 	// low-effort compression mode.
  24942 	if !(low_effort != 0) || !(entropy_combine != 0) {
  24943 		v10 = int64(quality * quality * quality * (libc.Int32FromInt32(MAX_HISTO_GREEDY) - libc.Int32FromInt32(1)))
  24944 		v11 = int64(libc.Int32FromInt32(100) * libc.Int32FromInt32(100) * libc.Int32FromInt32(100))
  24945 		if libc.BoolInt32(v10 < 0) == libc.BoolInt32(v11 < 0) {
  24946 			v14 = (v10 + v11/int64(2)) / v11
  24947 		} else {
  24948 			v14 = (v10 - v11/int64(2)) / v11
  24949 		}
  24950 		v12 = v14
  24951 		goto _13
  24952 	_13:
  24953 		// cubic ramp between 1 and MAX_HISTO_GREEDY:
  24954 		threshold_size = int32(libc.Int64FromInt32(1) + v12)
  24955 		if !(HistogramCombineStochastic(tls, image_histo, threshold_size, bp) != 0) {
  24956 			WebPEncodingSetError(tls, pic, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  24957 			goto Error
  24958 		}
  24959 		if **(**int32)(__ccgo_up(bp)) != 0 {
  24960 			if !(HistogramCombineGreedy(tls, image_histo) != 0) {
  24961 				WebPEncodingSetError(tls, pic, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  24962 				goto Error
  24963 			}
  24964 		}
  24965 	}
  24966 	// Find the optimal map from original histograms to the final ones.
  24967 	HistogramRemap(tls, orig_histo, image_histo, histogram_symbols)
  24968 	if !(WebPReportProgress(tls, pic, **(**int32)(__ccgo_up(percent))+percent_range, percent) != 0) {
  24969 		goto Error
  24970 	}
  24971 	goto Error
  24972 Error:
  24973 	;
  24974 	VP8LFreeHistogramSet(tls, orig_histo)
  24975 	return libc.BoolInt32((*WebPPicture)(unsafe.Pointer(pic)).Ferror_code == int32(VP8_ENC_OK))
  24976 }
  24977 
  24978 const SIZE_MAX9 = "UINT64_MAX"
  24979 
  24980 //------------------------------------------------------------------------------
  24981 
  24982 // Copyright 2012 Google Inc. All Rights Reserved.
  24983 //
  24984 // Use of this source code is governed by a BSD-style license
  24985 // that can be found in the COPYING file in the root of the source
  24986 // tree. An additional intellectual property rights grant can be found
  24987 // in the file PATENTS. All contributing project authors may
  24988 // be found in the AUTHORS file in the root of the source tree.
  24989 // -----------------------------------------------------------------------------
  24990 //
  24991 // Misc. common utility functions
  24992 //
  24993 // Authors: Skal (pascal.massimino@gmail.com)
  24994 //          Urvang (urvang@google.com)
  24995 
  24996 // Copyright 2010 Google Inc. All Rights Reserved.
  24997 //
  24998 // Use of this source code is governed by a BSD-style license
  24999 // that can be found in the COPYING file in the root of the source
  25000 // tree. An additional intellectual property rights grant can be found
  25001 // in the file PATENTS. All contributing project authors may
  25002 // be found in the AUTHORS file in the root of the source tree.
  25003 // -----------------------------------------------------------------------------
  25004 //
  25005 //  Common types + memory wrappers
  25006 //
  25007 // Author: Skal (pascal.massimino@gmail.com)
  25008 
  25009 //------------------------------------------------------------------------------
  25010 // VP8Iterator
  25011 //------------------------------------------------------------------------------
  25012 
  25013 func InitLeft(tls *libc.TLS, it uintptr) {
  25014 	var v1, v2 uint8_t
  25015 	var v3 int32
  25016 	_, _, _ = v1, v2, v3
  25017 	if (*VP8EncIterator)(unsafe.Pointer(it)).Fy > 0 {
  25018 		v3 = int32(129)
  25019 	} else {
  25020 		v3 = int32(127)
  25021 	}
  25022 	v2 = uint8(v3)
  25023 	**(**uint8_t)(__ccgo_up((*VP8EncIterator)(unsafe.Pointer(it)).Fv_left + uintptr(-libc.Int32FromInt32(1)))) = v2
  25024 	v1 = v2
  25025 	**(**uint8_t)(__ccgo_up((*VP8EncIterator)(unsafe.Pointer(it)).Fu_left + uintptr(-libc.Int32FromInt32(1)))) = v1
  25026 	**(**uint8_t)(__ccgo_up((*VP8EncIterator)(unsafe.Pointer(it)).Fy_left + uintptr(-libc.Int32FromInt32(1)))) = v1
  25027 	libc.Xmemset(tls, (*VP8EncIterator)(unsafe.Pointer(it)).Fy_left, int32(129), uint64(16))
  25028 	libc.Xmemset(tls, (*VP8EncIterator)(unsafe.Pointer(it)).Fu_left, int32(129), uint64(8))
  25029 	libc.Xmemset(tls, (*VP8EncIterator)(unsafe.Pointer(it)).Fv_left, int32(129), uint64(8))
  25030 	**(**int32)(__ccgo_up(it + 168 + 8*4)) = 0
  25031 	if (*VP8EncIterator)(unsafe.Pointer(it)).Ftop_derr != libc.UintptrFromInt32(0) {
  25032 		libc.Xmemset(tls, it+344, 0, uint64(4))
  25033 	}
  25034 }
  25035 
  25036 func InitTop(tls *libc.TLS, it uintptr) {
  25037 	var enc uintptr
  25038 	var top_size size_t
  25039 	_, _ = enc, top_size
  25040 	enc = (*VP8EncIterator)(unsafe.Pointer(it)).Fenc
  25041 	top_size = uint64((*VP8Encoder)(unsafe.Pointer(enc)).Fmb_w * int32(16))
  25042 	libc.Xmemset(tls, (*VP8Encoder)(unsafe.Pointer(enc)).Fy_top, int32(127), uint64(2)*top_size)
  25043 	libc.Xmemset(tls, (*VP8Encoder)(unsafe.Pointer(enc)).Fnz, 0, uint64((*VP8Encoder)(unsafe.Pointer(enc)).Fmb_w)*uint64(4))
  25044 	if (*VP8Encoder)(unsafe.Pointer(enc)).Ftop_derr != libc.UintptrFromInt32(0) {
  25045 		libc.Xmemset(tls, (*VP8Encoder)(unsafe.Pointer(enc)).Ftop_derr, 0, uint64((*VP8Encoder)(unsafe.Pointer(enc)).Fmb_w)*uint64(4))
  25046 	}
  25047 }
  25048 
  25049 func VP8IteratorSetRow(tls *libc.TLS, it uintptr, y int32) {
  25050 	var enc uintptr
  25051 	_ = enc
  25052 	enc = (*VP8EncIterator)(unsafe.Pointer(it)).Fenc
  25053 	(*VP8EncIterator)(unsafe.Pointer(it)).Fx = 0
  25054 	(*VP8EncIterator)(unsafe.Pointer(it)).Fy = y
  25055 	(*VP8EncIterator)(unsafe.Pointer(it)).Fbw = enc + 112 + uintptr(y&((*VP8Encoder)(unsafe.Pointer(enc)).Fnum_parts-int32(1)))*48
  25056 	(*VP8EncIterator)(unsafe.Pointer(it)).Fpreds = (*VP8Encoder)(unsafe.Pointer(enc)).Fpreds + uintptr(y*int32(4)*(*VP8Encoder)(unsafe.Pointer(enc)).Fpreds_w)
  25057 	(*VP8EncIterator)(unsafe.Pointer(it)).Fnz = (*VP8Encoder)(unsafe.Pointer(enc)).Fnz
  25058 	(*VP8EncIterator)(unsafe.Pointer(it)).Fmb = (*VP8Encoder)(unsafe.Pointer(enc)).Fmb_info + uintptr(y*(*VP8Encoder)(unsafe.Pointer(enc)).Fmb_w)*4
  25059 	(*VP8EncIterator)(unsafe.Pointer(it)).Fy_top = (*VP8Encoder)(unsafe.Pointer(enc)).Fy_top
  25060 	(*VP8EncIterator)(unsafe.Pointer(it)).Fuv_top = (*VP8Encoder)(unsafe.Pointer(enc)).Fuv_top
  25061 	InitLeft(tls, it)
  25062 }
  25063 
  25064 // C documentation
  25065 //
  25066 //	// restart a scan
  25067 func VP8IteratorReset(tls *libc.TLS, it uintptr) {
  25068 	var enc uintptr
  25069 	_ = enc
  25070 	enc = (*VP8EncIterator)(unsafe.Pointer(it)).Fenc
  25071 	VP8IteratorSetRow(tls, it, 0)
  25072 	VP8IteratorSetCountDown(tls, it, (*VP8Encoder)(unsafe.Pointer(enc)).Fmb_w*(*VP8Encoder)(unsafe.Pointer(enc)).Fmb_h) // default
  25073 	InitTop(tls, it)
  25074 	libc.Xmemset(tls, it+208, 0, uint64(96))
  25075 	(*VP8EncIterator)(unsafe.Pointer(it)).Fdo_trellis = 0
  25076 }
  25077 
  25078 func VP8IteratorSetCountDown(tls *libc.TLS, it uintptr, count_down int32) {
  25079 	var v1 int32
  25080 	_ = v1
  25081 	v1 = count_down
  25082 	(*VP8EncIterator)(unsafe.Pointer(it)).Fcount_down0 = v1
  25083 	(*VP8EncIterator)(unsafe.Pointer(it)).Fcount_down = v1
  25084 }
  25085 
  25086 func VP8IteratorIsDone(tls *libc.TLS, it uintptr) (r int32) {
  25087 	return libc.BoolInt32((*VP8EncIterator)(unsafe.Pointer(it)).Fcount_down <= 0)
  25088 }
  25089 
  25090 func VP8IteratorInit(tls *libc.TLS, enc uintptr, it uintptr) {
  25091 	(*VP8EncIterator)(unsafe.Pointer(it)).Fenc = enc
  25092 	(*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_in = uintptr((uintptr_t(it+488) + libc.Uint64FromInt32(WEBP_ALIGN_CST)) & ^libc.Uint64FromInt32(WEBP_ALIGN_CST))
  25093 	(*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_out = (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_in + uintptr(libc.Int32FromInt32(BPS)*libc.Int32FromInt32(16))
  25094 	(*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_out2 = (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_out + uintptr(libc.Int32FromInt32(BPS)*libc.Int32FromInt32(16))
  25095 	(*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_p = (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_out2 + uintptr(libc.Int32FromInt32(BPS)*libc.Int32FromInt32(16))
  25096 	(*VP8EncIterator)(unsafe.Pointer(it)).Flf_stats = (*VP8Encoder)(unsafe.Pointer(enc)).Flf_stats
  25097 	(*VP8EncIterator)(unsafe.Pointer(it)).Fpercent0 = (*VP8Encoder)(unsafe.Pointer(enc)).Fpercent
  25098 	(*VP8EncIterator)(unsafe.Pointer(it)).Fy_left = uintptr((uint64(it+400+libc.UintptrFromInt32(1)) + libc.Uint64FromInt32(WEBP_ALIGN_CST)) & ^libc.Uint64FromInt32(WEBP_ALIGN_CST))
  25099 	(*VP8EncIterator)(unsafe.Pointer(it)).Fu_left = (*VP8EncIterator)(unsafe.Pointer(it)).Fy_left + uintptr(16) + uintptr(16)
  25100 	(*VP8EncIterator)(unsafe.Pointer(it)).Fv_left = (*VP8EncIterator)(unsafe.Pointer(it)).Fu_left + uintptr(16)
  25101 	(*VP8EncIterator)(unsafe.Pointer(it)).Ftop_derr = (*VP8Encoder)(unsafe.Pointer(enc)).Ftop_derr
  25102 	VP8IteratorReset(tls, it)
  25103 }
  25104 
  25105 func VP8IteratorProgress(tls *libc.TLS, it uintptr, delta int32) (r int32) {
  25106 	var done, percent, v1 int32
  25107 	var enc uintptr
  25108 	_, _, _, _ = done, enc, percent, v1
  25109 	enc = (*VP8EncIterator)(unsafe.Pointer(it)).Fenc
  25110 	if delta != 0 && (*WebPPicture)(unsafe.Pointer((*VP8Encoder)(unsafe.Pointer(enc)).Fpic)).Fprogress_hook != libc.UintptrFromInt32(0) {
  25111 		done = (*VP8EncIterator)(unsafe.Pointer(it)).Fcount_down0 - (*VP8EncIterator)(unsafe.Pointer(it)).Fcount_down
  25112 		if (*VP8EncIterator)(unsafe.Pointer(it)).Fcount_down0 <= 0 {
  25113 			v1 = (*VP8EncIterator)(unsafe.Pointer(it)).Fpercent0
  25114 		} else {
  25115 			v1 = (*VP8EncIterator)(unsafe.Pointer(it)).Fpercent0 + delta*done/(*VP8EncIterator)(unsafe.Pointer(it)).Fcount_down0
  25116 		}
  25117 		percent = v1
  25118 		return WebPReportProgress(tls, (*VP8Encoder)(unsafe.Pointer(enc)).Fpic, percent, enc+536)
  25119 	}
  25120 	return int32(1)
  25121 }
  25122 
  25123 //------------------------------------------------------------------------------
  25124 // Import the source samples into the cache. Takes care of replicating
  25125 // boundary pixels if necessary.
  25126 
  25127 func MinSize(tls *libc.TLS, a int32, b int32) (r int32) {
  25128 	var v1 int32
  25129 	_ = v1
  25130 	if a < b {
  25131 		v1 = a
  25132 	} else {
  25133 		v1 = b
  25134 	}
  25135 	return v1
  25136 }
  25137 
  25138 func ImportBlock(tls *libc.TLS, src uintptr, src_stride int32, dst uintptr, w int32, h int32, size int32) {
  25139 	var i int32
  25140 	_ = i
  25141 	i = 0
  25142 	for {
  25143 		if !(i < h) {
  25144 			break
  25145 		}
  25146 		libc.Xmemcpy(tls, dst, src, uint64(w))
  25147 		if w < size {
  25148 			libc.Xmemset(tls, dst+uintptr(w), int32(**(**uint8_t)(__ccgo_up(dst + uintptr(w-int32(1))))), uint64(size-w))
  25149 		}
  25150 		dst = dst + uintptr(BPS)
  25151 		src = src + uintptr(src_stride)
  25152 		goto _1
  25153 	_1:
  25154 		;
  25155 		i = i + 1
  25156 	}
  25157 	i = h
  25158 	for {
  25159 		if !(i < size) {
  25160 			break
  25161 		}
  25162 		libc.Xmemcpy(tls, dst, dst-uintptr(BPS), uint64(size))
  25163 		dst = dst + uintptr(BPS)
  25164 		goto _2
  25165 	_2:
  25166 		;
  25167 		i = i + 1
  25168 	}
  25169 }
  25170 
  25171 func ImportLine(tls *libc.TLS, src uintptr, src_stride int32, dst uintptr, len1 int32, total_len int32) {
  25172 	var i int32
  25173 	_ = i
  25174 	i = 0
  25175 	for {
  25176 		if !(i < len1) {
  25177 			break
  25178 		}
  25179 		**(**uint8_t)(__ccgo_up(dst + uintptr(i))) = **(**uint8_t)(__ccgo_up(src))
  25180 		goto _1
  25181 	_1:
  25182 		;
  25183 		i = i + 1
  25184 		src = src + uintptr(src_stride)
  25185 	}
  25186 	for {
  25187 		if !(i < total_len) {
  25188 			break
  25189 		}
  25190 		**(**uint8_t)(__ccgo_up(dst + uintptr(i))) = **(**uint8_t)(__ccgo_up(dst + uintptr(len1-int32(1))))
  25191 		goto _2
  25192 	_2:
  25193 		;
  25194 		i = i + 1
  25195 	}
  25196 }
  25197 
  25198 func VP8IteratorImport(tls *libc.TLS, it uintptr, tmp_32 uintptr) {
  25199 	var enc, pic, usrc, vsrc, ysrc uintptr
  25200 	var h, uv_h, uv_w, w, x, y int32
  25201 	var v1, v2 uint8_t
  25202 	_, _, _, _, _, _, _, _, _, _, _, _, _ = enc, h, pic, usrc, uv_h, uv_w, vsrc, w, x, y, ysrc, v1, v2
  25203 	enc = (*VP8EncIterator)(unsafe.Pointer(it)).Fenc
  25204 	x = (*VP8EncIterator)(unsafe.Pointer(it)).Fx
  25205 	y = (*VP8EncIterator)(unsafe.Pointer(it)).Fy
  25206 	pic = (*VP8Encoder)(unsafe.Pointer(enc)).Fpic
  25207 	ysrc = (*WebPPicture)(unsafe.Pointer(pic)).Fy + uintptr((y*(*WebPPicture)(unsafe.Pointer(pic)).Fy_stride+x)*int32(16))
  25208 	usrc = (*WebPPicture)(unsafe.Pointer(pic)).Fu + uintptr((y*(*WebPPicture)(unsafe.Pointer(pic)).Fuv_stride+x)*int32(8))
  25209 	vsrc = (*WebPPicture)(unsafe.Pointer(pic)).Fv + uintptr((y*(*WebPPicture)(unsafe.Pointer(pic)).Fuv_stride+x)*int32(8))
  25210 	w = MinSize(tls, (*WebPPicture)(unsafe.Pointer(pic)).Fwidth-x*int32(16), int32(16))
  25211 	h = MinSize(tls, (*WebPPicture)(unsafe.Pointer(pic)).Fheight-y*int32(16), int32(16))
  25212 	uv_w = (w + int32(1)) >> int32(1)
  25213 	uv_h = (h + int32(1)) >> int32(1)
  25214 	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))
  25215 	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))
  25216 	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))
  25217 	if tmp_32 == libc.UintptrFromInt32(0) {
  25218 		return
  25219 	}
  25220 	// Import source (uncompressed) samples into boundary.
  25221 	if x == 0 {
  25222 		InitLeft(tls, it)
  25223 	} else {
  25224 		if y == 0 {
  25225 			v2 = libc.Uint8FromInt32(127)
  25226 			**(**uint8_t)(__ccgo_up((*VP8EncIterator)(unsafe.Pointer(it)).Fv_left + uintptr(-libc.Int32FromInt32(1)))) = v2
  25227 			v1 = v2
  25228 			**(**uint8_t)(__ccgo_up((*VP8EncIterator)(unsafe.Pointer(it)).Fu_left + uintptr(-libc.Int32FromInt32(1)))) = v1
  25229 			**(**uint8_t)(__ccgo_up((*VP8EncIterator)(unsafe.Pointer(it)).Fy_left + uintptr(-libc.Int32FromInt32(1)))) = v1
  25230 		} else {
  25231 			**(**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)))
  25232 			**(**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)))
  25233 			**(**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)))
  25234 		}
  25235 		ImportLine(tls, ysrc-uintptr(1), (*WebPPicture)(unsafe.Pointer(pic)).Fy_stride, (*VP8EncIterator)(unsafe.Pointer(it)).Fy_left, h, int32(16))
  25236 		ImportLine(tls, usrc-uintptr(1), (*WebPPicture)(unsafe.Pointer(pic)).Fuv_stride, (*VP8EncIterator)(unsafe.Pointer(it)).Fu_left, uv_h, int32(8))
  25237 		ImportLine(tls, vsrc-uintptr(1), (*WebPPicture)(unsafe.Pointer(pic)).Fuv_stride, (*VP8EncIterator)(unsafe.Pointer(it)).Fv_left, uv_h, int32(8))
  25238 	}
  25239 	(*VP8EncIterator)(unsafe.Pointer(it)).Fy_top = tmp_32 + uintptr(0)
  25240 	(*VP8EncIterator)(unsafe.Pointer(it)).Fuv_top = tmp_32 + uintptr(16)
  25241 	if y == 0 {
  25242 		libc.Xmemset(tls, tmp_32, int32(127), libc.Uint64FromInt32(32)*libc.Uint64FromInt64(1))
  25243 	} else {
  25244 		ImportLine(tls, ysrc-uintptr((*WebPPicture)(unsafe.Pointer(pic)).Fy_stride), int32(1), tmp_32, w, int32(16))
  25245 		ImportLine(tls, usrc-uintptr((*WebPPicture)(unsafe.Pointer(pic)).Fuv_stride), int32(1), tmp_32+uintptr(16), uv_w, int32(8))
  25246 		ImportLine(tls, vsrc-uintptr((*WebPPicture)(unsafe.Pointer(pic)).Fuv_stride), int32(1), tmp_32+uintptr(16)+uintptr(8), uv_w, int32(8))
  25247 	}
  25248 }
  25249 
  25250 //------------------------------------------------------------------------------
  25251 // Copy back the compressed samples into user space if requested.
  25252 
  25253 func ExportBlock(tls *libc.TLS, src uintptr, dst uintptr, dst_stride int32, w int32, h int32) {
  25254 	var v1 int32
  25255 	_ = v1
  25256 	for {
  25257 		v1 = h
  25258 		h = h - 1
  25259 		if !(v1 > 0) {
  25260 			break
  25261 		}
  25262 		libc.Xmemcpy(tls, dst, src, uint64(w))
  25263 		dst = dst + uintptr(dst_stride)
  25264 		src = src + uintptr(BPS)
  25265 	}
  25266 }
  25267 
  25268 func VP8IteratorExport(tls *libc.TLS, it uintptr) {
  25269 	var enc, pic, udst, usrc, vdst, vsrc, ydst, ysrc uintptr
  25270 	var h, uv_h, uv_w, w, x, y int32
  25271 	_, _, _, _, _, _, _, _, _, _, _, _, _, _ = enc, h, pic, udst, usrc, uv_h, uv_w, vdst, vsrc, w, x, y, ydst, ysrc
  25272 	enc = (*VP8EncIterator)(unsafe.Pointer(it)).Fenc
  25273 	if (*WebPConfig)(unsafe.Pointer((*VP8Encoder)(unsafe.Pointer(enc)).Fconfig)).Fshow_compressed != 0 {
  25274 		x = (*VP8EncIterator)(unsafe.Pointer(it)).Fx
  25275 		y = (*VP8EncIterator)(unsafe.Pointer(it)).Fy
  25276 		ysrc = (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_out + uintptr(libc.Int32FromInt32(Y_OFF_ENC))
  25277 		usrc = (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_out + uintptr(libc.Int32FromInt32(U_OFF_ENC))
  25278 		vsrc = (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_out + uintptr(libc.Int32FromInt32(16)+libc.Int32FromInt32(8))
  25279 		pic = (*VP8Encoder)(unsafe.Pointer(enc)).Fpic
  25280 		ydst = (*WebPPicture)(unsafe.Pointer(pic)).Fy + uintptr((y*(*WebPPicture)(unsafe.Pointer(pic)).Fy_stride+x)*int32(16))
  25281 		udst = (*WebPPicture)(unsafe.Pointer(pic)).Fu + uintptr((y*(*WebPPicture)(unsafe.Pointer(pic)).Fuv_stride+x)*int32(8))
  25282 		vdst = (*WebPPicture)(unsafe.Pointer(pic)).Fv + uintptr((y*(*WebPPicture)(unsafe.Pointer(pic)).Fuv_stride+x)*int32(8))
  25283 		w = (*WebPPicture)(unsafe.Pointer(pic)).Fwidth - x*int32(16)
  25284 		h = (*WebPPicture)(unsafe.Pointer(pic)).Fheight - y*int32(16)
  25285 		if w > int32(16) {
  25286 			w = int32(16)
  25287 		}
  25288 		if h > int32(16) {
  25289 			h = int32(16)
  25290 		}
  25291 		// Luma plane
  25292 		ExportBlock(tls, ysrc, ydst, (*WebPPicture)(unsafe.Pointer(pic)).Fy_stride, w, h)
  25293 		// U/V planes
  25294 		uv_w = (w + int32(1)) >> int32(1)
  25295 		uv_h = (h + int32(1)) >> int32(1)
  25296 		ExportBlock(tls, usrc, udst, (*WebPPicture)(unsafe.Pointer(pic)).Fuv_stride, uv_w, uv_h)
  25297 		ExportBlock(tls, vsrc, vdst, (*WebPPicture)(unsafe.Pointer(pic)).Fuv_stride, uv_w, uv_h)
  25298 	}
  25299 }
  25300 
  25301 //------------------------------------------------------------------------------
  25302 // Non-zero contexts setup/teardown
  25303 
  25304 // Nz bits:
  25305 //  0  1  2  3  Y
  25306 //  4  5  6  7
  25307 //  8  9 10 11
  25308 // 12 13 14 15
  25309 // 16 17        U
  25310 // 18 19
  25311 // 20 21        V
  25312 // 22 23
  25313 // 24           DC-intra16
  25314 
  25315 // Convert packed context to byte array
  25316 
  25317 func VP8IteratorNzToBytes(tls *libc.TLS, it uintptr) {
  25318 	var left_nz, top_nz uintptr
  25319 	var lnz, tnz int32
  25320 	_, _, _, _ = left_nz, lnz, tnz, top_nz
  25321 	tnz = int32(**(**uint32_t)(__ccgo_up((*VP8EncIterator)(unsafe.Pointer(it)).Fnz)))
  25322 	lnz = int32(**(**uint32_t)(__ccgo_up((*VP8EncIterator)(unsafe.Pointer(it)).Fnz + uintptr(-libc.Int32FromInt32(1))*4)))
  25323 	top_nz = it + 132
  25324 	left_nz = it + 168
  25325 	// Top-Y
  25326 	**(**int32)(__ccgo_up(top_nz)) = libc.BoolInt32(!!(tnz&(libc.Int32FromInt32(1)<<libc.Int32FromInt32(12)) != 0))
  25327 	**(**int32)(__ccgo_up(top_nz + 1*4)) = libc.BoolInt32(!!(tnz&(libc.Int32FromInt32(1)<<libc.Int32FromInt32(13)) != 0))
  25328 	**(**int32)(__ccgo_up(top_nz + 2*4)) = libc.BoolInt32(!!(tnz&(libc.Int32FromInt32(1)<<libc.Int32FromInt32(14)) != 0))
  25329 	**(**int32)(__ccgo_up(top_nz + 3*4)) = libc.BoolInt32(!!(tnz&(libc.Int32FromInt32(1)<<libc.Int32FromInt32(15)) != 0))
  25330 	// Top-U
  25331 	**(**int32)(__ccgo_up(top_nz + 4*4)) = libc.BoolInt32(!!(tnz&(libc.Int32FromInt32(1)<<libc.Int32FromInt32(18)) != 0))
  25332 	**(**int32)(__ccgo_up(top_nz + 5*4)) = libc.BoolInt32(!!(tnz&(libc.Int32FromInt32(1)<<libc.Int32FromInt32(19)) != 0))
  25333 	// Top-V
  25334 	**(**int32)(__ccgo_up(top_nz + 6*4)) = libc.BoolInt32(!!(tnz&(libc.Int32FromInt32(1)<<libc.Int32FromInt32(22)) != 0))
  25335 	**(**int32)(__ccgo_up(top_nz + 7*4)) = libc.BoolInt32(!!(tnz&(libc.Int32FromInt32(1)<<libc.Int32FromInt32(23)) != 0))
  25336 	// DC
  25337 	**(**int32)(__ccgo_up(top_nz + 8*4)) = libc.BoolInt32(!!(tnz&(libc.Int32FromInt32(1)<<libc.Int32FromInt32(24)) != 0))
  25338 	// left-Y
  25339 	**(**int32)(__ccgo_up(left_nz)) = libc.BoolInt32(!!(lnz&(libc.Int32FromInt32(1)<<libc.Int32FromInt32(3)) != 0))
  25340 	**(**int32)(__ccgo_up(left_nz + 1*4)) = libc.BoolInt32(!!(lnz&(libc.Int32FromInt32(1)<<libc.Int32FromInt32(7)) != 0))
  25341 	**(**int32)(__ccgo_up(left_nz + 2*4)) = libc.BoolInt32(!!(lnz&(libc.Int32FromInt32(1)<<libc.Int32FromInt32(11)) != 0))
  25342 	**(**int32)(__ccgo_up(left_nz + 3*4)) = libc.BoolInt32(!!(lnz&(libc.Int32FromInt32(1)<<libc.Int32FromInt32(15)) != 0))
  25343 	// left-U
  25344 	**(**int32)(__ccgo_up(left_nz + 4*4)) = libc.BoolInt32(!!(lnz&(libc.Int32FromInt32(1)<<libc.Int32FromInt32(17)) != 0))
  25345 	**(**int32)(__ccgo_up(left_nz + 5*4)) = libc.BoolInt32(!!(lnz&(libc.Int32FromInt32(1)<<libc.Int32FromInt32(19)) != 0))
  25346 	// left-V
  25347 	**(**int32)(__ccgo_up(left_nz + 6*4)) = libc.BoolInt32(!!(lnz&(libc.Int32FromInt32(1)<<libc.Int32FromInt32(21)) != 0))
  25348 	**(**int32)(__ccgo_up(left_nz + 7*4)) = libc.BoolInt32(!!(lnz&(libc.Int32FromInt32(1)<<libc.Int32FromInt32(23)) != 0))
  25349 	// left-DC is special, iterated separately
  25350 }
  25351 
  25352 func VP8IteratorBytesToNz(tls *libc.TLS, it uintptr) {
  25353 	var left_nz, top_nz uintptr
  25354 	var nz uint32_t
  25355 	_, _, _ = left_nz, nz, top_nz
  25356 	nz = uint32(0)
  25357 	top_nz = it + 132
  25358 	left_nz = it + 168
  25359 	// top
  25360 	nz = nz | uint32(**(**int32)(__ccgo_up(top_nz))<<libc.Int32FromInt32(12)|**(**int32)(__ccgo_up(top_nz + 1*4))<<libc.Int32FromInt32(13))
  25361 	nz = nz | uint32(**(**int32)(__ccgo_up(top_nz + 2*4))<<libc.Int32FromInt32(14)|**(**int32)(__ccgo_up(top_nz + 3*4))<<libc.Int32FromInt32(15))
  25362 	nz = nz | uint32(**(**int32)(__ccgo_up(top_nz + 4*4))<<libc.Int32FromInt32(18)|**(**int32)(__ccgo_up(top_nz + 5*4))<<libc.Int32FromInt32(19))
  25363 	nz = nz | uint32(**(**int32)(__ccgo_up(top_nz + 6*4))<<libc.Int32FromInt32(22)|**(**int32)(__ccgo_up(top_nz + 7*4))<<libc.Int32FromInt32(23))
  25364 	nz = nz | uint32(**(**int32)(__ccgo_up(top_nz + 8*4))<<libc.Int32FromInt32(24)) // we propagate the _top_ bit, esp. for intra4
  25365 	// left
  25366 	nz = nz | uint32(**(**int32)(__ccgo_up(left_nz))<<libc.Int32FromInt32(3)|**(**int32)(__ccgo_up(left_nz + 1*4))<<libc.Int32FromInt32(7))
  25367 	nz = nz | uint32(**(**int32)(__ccgo_up(left_nz + 2*4))<<libc.Int32FromInt32(11))
  25368 	nz = nz | uint32(**(**int32)(__ccgo_up(left_nz + 4*4))<<libc.Int32FromInt32(17)|**(**int32)(__ccgo_up(left_nz + 6*4))<<libc.Int32FromInt32(21))
  25369 	**(**uint32_t)(__ccgo_up((*VP8EncIterator)(unsafe.Pointer(it)).Fnz)) = nz
  25370 }
  25371 
  25372 //------------------------------------------------------------------------------
  25373 // Advance to the next position, doing the bookkeeping.
  25374 
  25375 func VP8IteratorSaveBoundary(tls *libc.TLS, it uintptr) {
  25376 	var enc, uvsrc, ysrc uintptr
  25377 	var i, x, y int32
  25378 	_, _, _, _, _, _ = enc, i, uvsrc, x, y, ysrc
  25379 	enc = (*VP8EncIterator)(unsafe.Pointer(it)).Fenc
  25380 	x = (*VP8EncIterator)(unsafe.Pointer(it)).Fx
  25381 	y = (*VP8EncIterator)(unsafe.Pointer(it)).Fy
  25382 	ysrc = (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_out + uintptr(libc.Int32FromInt32(Y_OFF_ENC))
  25383 	uvsrc = (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_out + uintptr(libc.Int32FromInt32(U_OFF_ENC))
  25384 	if x < (*VP8Encoder)(unsafe.Pointer(enc)).Fmb_w-int32(1) {
  25385 		i = 0
  25386 		for {
  25387 			if !(i < int32(16)) {
  25388 				break
  25389 			}
  25390 			**(**uint8_t)(__ccgo_up((*VP8EncIterator)(unsafe.Pointer(it)).Fy_left + uintptr(i))) = **(**uint8_t)(__ccgo_up(ysrc + uintptr(int32(15)+i*int32(BPS))))
  25391 			goto _1
  25392 		_1:
  25393 			;
  25394 			i = i + 1
  25395 		}
  25396 		i = 0
  25397 		for {
  25398 			if !(i < int32(8)) {
  25399 				break
  25400 			}
  25401 			**(**uint8_t)(__ccgo_up((*VP8EncIterator)(unsafe.Pointer(it)).Fu_left + uintptr(i))) = **(**uint8_t)(__ccgo_up(uvsrc + uintptr(int32(7)+i*int32(BPS))))
  25402 			**(**uint8_t)(__ccgo_up((*VP8EncIterator)(unsafe.Pointer(it)).Fv_left + uintptr(i))) = **(**uint8_t)(__ccgo_up(uvsrc + uintptr(int32(15)+i*int32(BPS))))
  25403 			goto _2
  25404 		_2:
  25405 			;
  25406 			i = i + 1
  25407 		}
  25408 		// top-left (before 'top'!)
  25409 		**(**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))
  25410 		**(**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))))
  25411 		**(**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))))
  25412 	}
  25413 	if y < (*VP8Encoder)(unsafe.Pointer(enc)).Fmb_h-int32(1) { // top
  25414 		libc.Xmemcpy(tls, (*VP8EncIterator)(unsafe.Pointer(it)).Fy_top, ysrc+uintptr(libc.Int32FromInt32(15)*libc.Int32FromInt32(BPS)), uint64(16))
  25415 		libc.Xmemcpy(tls, (*VP8EncIterator)(unsafe.Pointer(it)).Fuv_top, uvsrc+uintptr(libc.Int32FromInt32(7)*libc.Int32FromInt32(BPS)), uint64(libc.Int32FromInt32(8)+libc.Int32FromInt32(8)))
  25416 	}
  25417 }
  25418 
  25419 func VP8IteratorNext(tls *libc.TLS, it uintptr) (r int32) {
  25420 	var v1, v3 int32
  25421 	var v2, v4 uintptr
  25422 	_, _, _, _ = v1, v2, v3, v4
  25423 	v2 = it
  25424 	*(*int32)(unsafe.Pointer(v2)) = *(*int32)(unsafe.Pointer(v2)) + 1
  25425 	v1 = *(*int32)(unsafe.Pointer(v2))
  25426 	if v1 == (*VP8Encoder)(unsafe.Pointer((*VP8EncIterator)(unsafe.Pointer(it)).Fenc)).Fmb_w {
  25427 		v4 = it + 4
  25428 		*(*int32)(unsafe.Pointer(v4)) = *(*int32)(unsafe.Pointer(v4)) + 1
  25429 		v3 = *(*int32)(unsafe.Pointer(v4))
  25430 		VP8IteratorSetRow(tls, it, v3)
  25431 	} else {
  25432 		**(**uintptr)(__ccgo_up(it + 64)) += uintptr(4)
  25433 		**(**uintptr)(__ccgo_up(it + 48)) += uintptr(1) * 4
  25434 		**(**uintptr)(__ccgo_up(it + 72)) += uintptr(1) * 4
  25435 		**(**uintptr)(__ccgo_up(it + 384)) += uintptr(16)
  25436 		**(**uintptr)(__ccgo_up(it + 392)) += uintptr(16)
  25437 	}
  25438 	v2 = it + 332
  25439 	*(*int32)(unsafe.Pointer(v2)) = *(*int32)(unsafe.Pointer(v2)) - 1
  25440 	v1 = *(*int32)(unsafe.Pointer(v2))
  25441 	return libc.BoolInt32(0 < v1)
  25442 }
  25443 
  25444 //------------------------------------------------------------------------------
  25445 // Helper function to set mode properties
  25446 
  25447 func VP8SetIntra16Mode(tls *libc.TLS, it uintptr, mode int32) {
  25448 	var preds uintptr
  25449 	var y int32
  25450 	_, _ = preds, y
  25451 	preds = (*VP8EncIterator)(unsafe.Pointer(it)).Fpreds
  25452 	y = 0
  25453 	for {
  25454 		if !(y < int32(4)) {
  25455 			break
  25456 		}
  25457 		libc.Xmemset(tls, preds, mode, uint64(4))
  25458 		preds = preds + uintptr((*VP8Encoder)(unsafe.Pointer((*VP8EncIterator)(unsafe.Pointer(it)).Fenc)).Fpreds_w)
  25459 		goto _1
  25460 	_1:
  25461 		;
  25462 		y = y + 1
  25463 	}
  25464 	libc.SetBitFieldPtr8Uint32((*VP8EncIterator)(unsafe.Pointer(it)).Fmb+0, libc.Uint32FromInt32(1), 0, 0x3)
  25465 }
  25466 
  25467 func VP8SetIntra4Mode(tls *libc.TLS, it uintptr, modes uintptr) {
  25468 	var preds uintptr
  25469 	var y int32
  25470 	_, _ = preds, y
  25471 	preds = (*VP8EncIterator)(unsafe.Pointer(it)).Fpreds
  25472 	y = int32(4)
  25473 	for {
  25474 		if !(y > 0) {
  25475 			break
  25476 		}
  25477 		libc.Xmemcpy(tls, preds, modes, libc.Uint64FromInt32(4)*libc.Uint64FromInt64(1))
  25478 		preds = preds + uintptr((*VP8Encoder)(unsafe.Pointer((*VP8EncIterator)(unsafe.Pointer(it)).Fenc)).Fpreds_w)
  25479 		modes = modes + uintptr(4)
  25480 		goto _1
  25481 	_1:
  25482 		;
  25483 		y = y - 1
  25484 	}
  25485 	libc.SetBitFieldPtr8Uint32((*VP8EncIterator)(unsafe.Pointer(it)).Fmb+0, libc.Uint32FromInt32(0), 0, 0x3)
  25486 }
  25487 
  25488 func VP8SetIntraUVMode(tls *libc.TLS, it uintptr, mode int32) {
  25489 	libc.SetBitFieldPtr8Uint32((*VP8EncIterator)(unsafe.Pointer(it)).Fmb+0, uint32(mode), 2, 0xc)
  25490 }
  25491 
  25492 func VP8SetSkip(tls *libc.TLS, it uintptr, skip int32) {
  25493 	libc.SetBitFieldPtr8Uint32((*VP8EncIterator)(unsafe.Pointer(it)).Fmb+0, uint32(skip), 4, 0x10)
  25494 }
  25495 
  25496 func VP8SetSegment(tls *libc.TLS, it uintptr, segment int32) {
  25497 	libc.SetBitFieldPtr8Uint32((*VP8EncIterator)(unsafe.Pointer(it)).Fmb+0, uint32(segment), 5, 0x60)
  25498 }
  25499 
  25500 //------------------------------------------------------------------------------
  25501 // Intra4x4 sub-blocks iteration
  25502 //
  25503 //  We store and update the boundary samples into an array of 37 pixels. They
  25504 //  are updated as we iterate and reconstructs each intra4x4 blocks in turn.
  25505 //  The position of the samples has the following snake pattern:
  25506 //
  25507 // 16|17 18 19 20|21 22 23 24|25 26 27 28|29 30 31 32|33 34 35 36  <- Top-right
  25508 // --+-----------+-----------+-----------+-----------+
  25509 // 15|         19|         23|         27|         31|
  25510 // 14|         18|         22|         26|         30|
  25511 // 13|         17|         21|         25|         29|
  25512 // 12|13 14 15 16|17 18 19 20|21 22 23 24|25 26 27 28|
  25513 // --+-----------+-----------+-----------+-----------+
  25514 // 11|         15|         19|         23|         27|
  25515 // 10|         14|         18|         22|         26|
  25516 //  9|         13|         17|         21|         25|
  25517 //  8| 9 10 11 12|13 14 15 16|17 18 19 20|21 22 23 24|
  25518 // --+-----------+-----------+-----------+-----------+
  25519 //  7|         11|         15|         19|         23|
  25520 //  6|         10|         14|         18|         22|
  25521 //  5|          9|         13|         17|         21|
  25522 //  4| 5  6  7  8| 9 10 11 12|13 14 15 16|17 18 19 20|
  25523 // --+-----------+-----------+-----------+-----------+
  25524 //  3|          7|         11|         15|         19|
  25525 //  2|          6|         10|         14|         18|
  25526 //  1|          5|          9|         13|         17|
  25527 //  0| 1  2  3  4| 5  6  7  8| 9 10 11 12|13 14 15 16|
  25528 // --+-----------+-----------+-----------+-----------+
  25529 
  25530 // C documentation
  25531 //
  25532 //	// Array to record the position of the top sample to pass to the prediction
  25533 //	// functions in dsp.c.
  25534 var VP8TopLeftI4 = [16]uint8_t{
  25535 	0:  uint8(17),
  25536 	1:  uint8(21),
  25537 	2:  uint8(25),
  25538 	3:  uint8(29),
  25539 	4:  uint8(13),
  25540 	5:  uint8(17),
  25541 	6:  uint8(21),
  25542 	7:  uint8(25),
  25543 	8:  uint8(9),
  25544 	9:  uint8(13),
  25545 	10: uint8(17),
  25546 	11: uint8(21),
  25547 	12: uint8(5),
  25548 	13: uint8(9),
  25549 	14: uint8(13),
  25550 	15: uint8(17),
  25551 }
  25552 
  25553 func VP8IteratorStartI4(tls *libc.TLS, it uintptr) {
  25554 	var enc uintptr
  25555 	var i int32
  25556 	_, _ = enc, i
  25557 	enc = (*VP8EncIterator)(unsafe.Pointer(it)).Fenc
  25558 	(*VP8EncIterator)(unsafe.Pointer(it)).Fi4 = 0 // first 4x4 sub-block
  25559 	(*VP8EncIterator)(unsafe.Pointer(it)).Fi4_top = it + 80 + uintptr(VP8TopLeftI4[0])
  25560 	// Import the boundary samples
  25561 	i = 0
  25562 	for {
  25563 		if !(i < int32(17)) {
  25564 			break
  25565 		} // left
  25566 		**(**uint8_t)(__ccgo_up(it + 80 + uintptr(i))) = **(**uint8_t)(__ccgo_up((*VP8EncIterator)(unsafe.Pointer(it)).Fy_left + uintptr(int32(15)-i)))
  25567 		goto _1
  25568 	_1:
  25569 		;
  25570 		i = i + 1
  25571 	}
  25572 	i = 0
  25573 	for {
  25574 		if !(i < int32(16)) {
  25575 			break
  25576 		} // top
  25577 		**(**uint8_t)(__ccgo_up(it + 80 + uintptr(int32(17)+i))) = **(**uint8_t)(__ccgo_up((*VP8EncIterator)(unsafe.Pointer(it)).Fy_top + uintptr(i)))
  25578 		goto _2
  25579 	_2:
  25580 		;
  25581 		i = i + 1
  25582 	}
  25583 	// top-right samples have a special case on the far right of the picture
  25584 	if (*VP8EncIterator)(unsafe.Pointer(it)).Fx < (*VP8Encoder)(unsafe.Pointer(enc)).Fmb_w-int32(1) {
  25585 		i = int32(16)
  25586 		for {
  25587 			if !(i < libc.Int32FromInt32(16)+libc.Int32FromInt32(4)) {
  25588 				break
  25589 			}
  25590 			**(**uint8_t)(__ccgo_up(it + 80 + uintptr(int32(17)+i))) = **(**uint8_t)(__ccgo_up((*VP8EncIterator)(unsafe.Pointer(it)).Fy_top + uintptr(i)))
  25591 			goto _3
  25592 		_3:
  25593 			;
  25594 			i = i + 1
  25595 		}
  25596 	} else { // else, replicate the last valid pixel four times
  25597 		i = int32(16)
  25598 		for {
  25599 			if !(i < libc.Int32FromInt32(16)+libc.Int32FromInt32(4)) {
  25600 				break
  25601 			}
  25602 			**(**uint8_t)(__ccgo_up(it + 80 + uintptr(int32(17)+i))) = **(**uint8_t)(__ccgo_up(it + 80 + uintptr(libc.Int32FromInt32(17)+libc.Int32FromInt32(15))))
  25603 			goto _4
  25604 		_4:
  25605 			;
  25606 			i = i + 1
  25607 		}
  25608 	}
  25609 	VP8IteratorNzToBytes(tls, it) // import the non-zero context
  25610 }
  25611 
  25612 func VP8IteratorRotateI4(tls *libc.TLS, it uintptr, yuv_out uintptr) (r int32) {
  25613 	var blk, top uintptr
  25614 	var i int32
  25615 	_, _, _ = blk, i, top
  25616 	blk = yuv_out + uintptr(VP8Scan[(*VP8EncIterator)(unsafe.Pointer(it)).Fi4])
  25617 	top = (*VP8EncIterator)(unsafe.Pointer(it)).Fi4_top
  25618 	// Update the cache with 7 fresh samples
  25619 	i = 0
  25620 	for {
  25621 		if !(i <= int32(3)) {
  25622 			break
  25623 		}
  25624 		**(**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
  25625 		goto _1
  25626 	_1:
  25627 		;
  25628 		i = i + 1
  25629 	}
  25630 	if (*VP8EncIterator)(unsafe.Pointer(it)).Fi4&int32(3) != int32(3) { // if not on the right sub-blocks #3, #7, #11, #15
  25631 		i = 0
  25632 		for {
  25633 			if !(i <= int32(2)) {
  25634 				break
  25635 			} // store future left samples
  25636 			**(**uint8_t)(__ccgo_up(top + uintptr(i))) = **(**uint8_t)(__ccgo_up(blk + uintptr(int32(3)+(int32(2)-i)*int32(BPS))))
  25637 			goto _2
  25638 		_2:
  25639 			;
  25640 			i = i + 1
  25641 		}
  25642 	} else { // else replicate top-right samples, as says the specs.
  25643 		i = 0
  25644 		for {
  25645 			if !(i <= int32(3)) {
  25646 				break
  25647 			}
  25648 			**(**uint8_t)(__ccgo_up(top + uintptr(i))) = **(**uint8_t)(__ccgo_up(top + uintptr(i+int32(4))))
  25649 			goto _3
  25650 		_3:
  25651 			;
  25652 			i = i + 1
  25653 		}
  25654 	}
  25655 	// move pointers to next sub-block
  25656 	(*VP8EncIterator)(unsafe.Pointer(it)).Fi4 = (*VP8EncIterator)(unsafe.Pointer(it)).Fi4 + 1
  25657 	if (*VP8EncIterator)(unsafe.Pointer(it)).Fi4 == int32(16) { // we're done
  25658 		return 0
  25659 	}
  25660 	(*VP8EncIterator)(unsafe.Pointer(it)).Fi4_top = it + 80 + uintptr(VP8TopLeftI4[(*VP8EncIterator)(unsafe.Pointer(it)).Fi4])
  25661 	return int32(1)
  25662 }
  25663 
  25664 const MAX_LIMIT_BITS = 5
  25665 const MIN_DIM_FOR_NEAR_LOSSLESS = 64
  25666 const SIZE_MAX10 = "_UI64_MAX"
  25667 
  25668 //------------------------------------------------------------------------------
  25669 
  25670 // Copyright 2012 Google Inc. All Rights Reserved.
  25671 //
  25672 // Use of this source code is governed by a BSD-style license
  25673 // that can be found in the COPYING file in the root of the source
  25674 // tree. An additional intellectual property rights grant can be found
  25675 // in the file PATENTS. All contributing project authors may
  25676 // be found in the AUTHORS file in the root of the source tree.
  25677 // -----------------------------------------------------------------------------
  25678 //
  25679 // Misc. common utility functions
  25680 //
  25681 // Authors: Skal (pascal.massimino@gmail.com)
  25682 //          Urvang (urvang@google.com)
  25683 
  25684 // Copyright 2011 Google Inc. All Rights Reserved.
  25685 //
  25686 // Use of this source code is governed by a BSD-style license
  25687 // that can be found in the COPYING file in the root of the source
  25688 // tree. An additional intellectual property rights grant can be found
  25689 // in the file PATENTS. All contributing project authors may
  25690 // be found in the AUTHORS file in the root of the source tree.
  25691 // -----------------------------------------------------------------------------
  25692 //
  25693 //   WebP encoder: main interface
  25694 //
  25695 // Author: Skal (pascal.massimino@gmail.com)
  25696 
  25697 // C documentation
  25698 //
  25699 //	// Quantizes the value up or down to a multiple of 1<<bits (or to 255),
  25700 //	// choosing the closer one, resolving ties using bankers' rounding.
  25701 func FindClosestDiscretized(tls *libc.TLS, a uint32_t, bits int32) (r uint32_t) {
  25702 	var biased, mask uint32_t
  25703 	_, _ = biased, mask
  25704 	mask = uint32(1)<<bits - uint32(1)
  25705 	biased = a + mask>>libc.Int32FromInt32(1) + a>>bits&uint32(1)
  25706 	if biased > uint32(0xff) {
  25707 		return uint32(0xff)
  25708 	}
  25709 	return biased & ^mask
  25710 }
  25711 
  25712 // C documentation
  25713 //
  25714 //	// Applies FindClosestDiscretized to all channels of pixel.
  25715 func ClosestDiscretizedArgb(tls *libc.TLS, a uint32_t, bits int32) (r uint32_t) {
  25716 	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)
  25717 }
  25718 
  25719 // C documentation
  25720 //
  25721 //	// Checks if distance between corresponding channel values of pixels a and b
  25722 //	// is within the given limit.
  25723 func IsNear(tls *libc.TLS, a uint32_t, b uint32_t, limit int32) (r int32) {
  25724 	var delta, k int32
  25725 	_, _ = delta, k
  25726 	k = 0
  25727 	for {
  25728 		if !(k < int32(4)) {
  25729 			break
  25730 		}
  25731 		delta = int32(a>>(k*libc.Int32FromInt32(8))&libc.Uint32FromInt32(0xff)) - int32(b>>(k*libc.Int32FromInt32(8))&libc.Uint32FromInt32(0xff))
  25732 		if delta >= limit || delta <= -limit {
  25733 			return 0
  25734 		}
  25735 		goto _1
  25736 	_1:
  25737 		;
  25738 		k = k + 1
  25739 	}
  25740 	return int32(1)
  25741 }
  25742 
  25743 func IsSmooth(tls *libc.TLS, prev_row uintptr, curr_row uintptr, next_row uintptr, ix int32, limit int32) (r int32) {
  25744 	// Check that all pixels in 4-connected neighborhood are smooth.
  25745 	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)
  25746 }
  25747 
  25748 // C documentation
  25749 //
  25750 //	// Adjusts pixel values of image with given maximum error.
  25751 func NearLossless(tls *libc.TLS, xsize int32, ysize int32, argb_src uintptr, stride int32, limit_bits int32, copy_buffer uintptr, argb_dst uintptr) {
  25752 	var curr_row, next_row, prev_row, temp uintptr
  25753 	var limit, x, y int32
  25754 	_, _, _, _, _, _, _ = curr_row, limit, next_row, prev_row, temp, x, y
  25755 	limit = int32(1) << limit_bits
  25756 	prev_row = copy_buffer
  25757 	curr_row = prev_row + uintptr(xsize)*4
  25758 	next_row = curr_row + uintptr(xsize)*4
  25759 	libc.Xmemcpy(tls, curr_row, argb_src, uint64(xsize)*uint64(4))
  25760 	libc.Xmemcpy(tls, next_row, argb_src+uintptr(stride)*4, uint64(xsize)*uint64(4))
  25761 	y = 0
  25762 	for {
  25763 		if !(y < ysize) {
  25764 			break
  25765 		}
  25766 		if y == 0 || y == ysize-int32(1) {
  25767 			libc.Xmemcpy(tls, argb_dst, argb_src, uint64(xsize)*uint64(4))
  25768 		} else {
  25769 			libc.Xmemcpy(tls, next_row, argb_src+uintptr(stride)*4, uint64(xsize)*uint64(4))
  25770 			**(**uint32_t)(__ccgo_up(argb_dst)) = **(**uint32_t)(__ccgo_up(argb_src))
  25771 			**(**uint32_t)(__ccgo_up(argb_dst + uintptr(xsize-int32(1))*4)) = **(**uint32_t)(__ccgo_up(argb_src + uintptr(xsize-int32(1))*4))
  25772 			x = int32(1)
  25773 			for {
  25774 				if !(x < xsize-int32(1)) {
  25775 					break
  25776 				}
  25777 				if IsSmooth(tls, prev_row, curr_row, next_row, x, limit) != 0 {
  25778 					**(**uint32_t)(__ccgo_up(argb_dst + uintptr(x)*4)) = **(**uint32_t)(__ccgo_up(curr_row + uintptr(x)*4))
  25779 				} else {
  25780 					**(**uint32_t)(__ccgo_up(argb_dst + uintptr(x)*4)) = ClosestDiscretizedArgb(tls, **(**uint32_t)(__ccgo_up(curr_row + uintptr(x)*4)), limit_bits)
  25781 				}
  25782 				goto _2
  25783 			_2:
  25784 				;
  25785 				x = x + 1
  25786 			}
  25787 		}
  25788 		// Three-way swap.
  25789 		temp = prev_row
  25790 		prev_row = curr_row
  25791 		curr_row = next_row
  25792 		next_row = temp
  25793 		goto _1
  25794 	_1:
  25795 		;
  25796 		y = y + 1
  25797 		argb_src = argb_src + uintptr(stride)*4
  25798 		argb_dst = argb_dst + uintptr(xsize)*4
  25799 	}
  25800 }
  25801 
  25802 func VP8ApplyNearLossless(tls *libc.TLS, picture uintptr, quality int32, argb_dst uintptr) (r int32) {
  25803 	var copy_buffer uintptr
  25804 	var i, limit_bits, stride, xsize, ysize, v1 int32
  25805 	_, _, _, _, _, _, _ = copy_buffer, i, limit_bits, stride, xsize, ysize, v1
  25806 	xsize = (*WebPPicture)(unsafe.Pointer(picture)).Fwidth
  25807 	ysize = (*WebPPicture)(unsafe.Pointer(picture)).Fheight
  25808 	stride = (*WebPPicture)(unsafe.Pointer(picture)).Fargb_stride
  25809 	copy_buffer = WebPSafeMalloc(tls, uint64(xsize*int32(3)), uint64(4))
  25810 	v1 = int32(5) - quality/int32(20)
  25811 	goto _2
  25812 _2:
  25813 	limit_bits = v1
  25814 	if copy_buffer == libc.UintptrFromInt32(0) {
  25815 		return 0
  25816 	}
  25817 	// For small icon images, don't attempt to apply near-lossless compression.
  25818 	if xsize < int32(MIN_DIM_FOR_NEAR_LOSSLESS) && ysize < int32(MIN_DIM_FOR_NEAR_LOSSLESS) || ysize < int32(3) {
  25819 		i = 0
  25820 		for {
  25821 			if !(i < ysize) {
  25822 				break
  25823 			}
  25824 			libc.Xmemcpy(tls, argb_dst+uintptr(i*xsize)*4, (*WebPPicture)(unsafe.Pointer(picture)).Fargb+uintptr(i*(*WebPPicture)(unsafe.Pointer(picture)).Fargb_stride)*4, uint64(xsize)*uint64(4))
  25825 			goto _3
  25826 		_3:
  25827 			;
  25828 			i = i + 1
  25829 		}
  25830 		WebPSafeFree(tls, copy_buffer)
  25831 		return int32(1)
  25832 	}
  25833 	NearLossless(tls, xsize, ysize, (*WebPPicture)(unsafe.Pointer(picture)).Fargb, stride, limit_bits, copy_buffer, argb_dst)
  25834 	i = limit_bits - int32(1)
  25835 	for {
  25836 		if !(i != 0) {
  25837 			break
  25838 		}
  25839 		NearLossless(tls, xsize, ysize, argb_dst, xsize, i, copy_buffer, argb_dst)
  25840 		goto _4
  25841 	_4:
  25842 		;
  25843 		i = i - 1
  25844 	}
  25845 	WebPSafeFree(tls, copy_buffer)
  25846 	return int32(1)
  25847 }
  25848 
  25849 const GAMMA_FIX = 12
  25850 const GAMMA_TAB_FIX = 7
  25851 const SHARPYUV_INLINE = "inline"
  25852 const SHARPYUV_VERSION_MAJOR = 0
  25853 const SHARPYUV_VERSION_MINOR = 4
  25854 const SHARPYUV_VERSION_PATCH = 2
  25855 
  25856 type SharpYuvConversionMatrix = struct {
  25857 	Frgb_to_y [4]int32
  25858 	Frgb_to_u [4]int32
  25859 	Frgb_to_v [4]int32
  25860 }
  25861 
  25862 type SharpYuvOptions = struct {
  25863 	Fyuv_matrix    uintptr
  25864 	Ftransfer_type SharpYuvTransferFunctionType1
  25865 }
  25866 
  25867 type SharpYuvTransferFunctionType = int32
  25868 
  25869 const kSharpYuvTransferFunctionBt709 = 1
  25870 const kSharpYuvTransferFunctionBt470M = 4
  25871 const kSharpYuvTransferFunctionBt470Bg = 5
  25872 const kSharpYuvTransferFunctionBt601 = 6
  25873 const kSharpYuvTransferFunctionSmpte240 = 7
  25874 const kSharpYuvTransferFunctionLinear = 8
  25875 const kSharpYuvTransferFunctionLog100 = 9
  25876 const kSharpYuvTransferFunctionLog100_Sqrt10 = 10
  25877 const kSharpYuvTransferFunctionIec61966 = 11
  25878 const kSharpYuvTransferFunctionBt1361 = 12
  25879 const kSharpYuvTransferFunctionSrgb = 13
  25880 const kSharpYuvTransferFunctionBt2020_10Bit = 14
  25881 const kSharpYuvTransferFunctionBt2020_12Bit = 15
  25882 const kSharpYuvTransferFunctionSmpte2084 = 16
  25883 const kSharpYuvTransferFunctionSmpte428 = 17
  25884 const kSharpYuvTransferFunctionHlg = 18
  25885 const kSharpYuvTransferFunctionNum = 19
  25886 
  25887 type SharpYuvTransferFunctionType1 = int32
  25888 
  25889 type SharpYuvRange = int32
  25890 
  25891 const kSharpYuvRangeFull = 0
  25892 const kSharpYuvRangeLimited = 1
  25893 
  25894 type SharpYuvColorSpace = struct {
  25895 	Fkr        float32
  25896 	Fkb        float32
  25897 	Fbit_depth int32
  25898 	Frange1    SharpYuvRange
  25899 }
  25900 
  25901 type SharpYuvMatrixType = int32
  25902 
  25903 const kSharpYuvMatrixWebp = 0
  25904 const kSharpYuvMatrixRec601Limited = 1
  25905 const kSharpYuvMatrixRec601Full = 2
  25906 const kSharpYuvMatrixRec709Limited = 3
  25907 const kSharpYuvMatrixRec709Full = 4
  25908 const kSharpYuvMatrixNum = 5
  25909 
  25910 // Copyright 2012 Google Inc. All Rights Reserved.
  25911 //
  25912 // Use of this source code is governed by a BSD-style license
  25913 // that can be found in the COPYING file in the root of the source
  25914 // tree. An additional intellectual property rights grant can be found
  25915 // in the file PATENTS. All contributing project authors may
  25916 // be found in the AUTHORS file in the root of the source tree.
  25917 // -----------------------------------------------------------------------------
  25918 //
  25919 // Misc. common utility functions
  25920 //
  25921 // Authors: Skal (pascal.massimino@gmail.com)
  25922 //          Urvang (urvang@google.com)
  25923 
  25924 // Copyright 2011 Google Inc. All Rights Reserved.
  25925 //
  25926 // Use of this source code is governed by a BSD-style license
  25927 // that can be found in the COPYING file in the root of the source
  25928 // tree. An additional intellectual property rights grant can be found
  25929 // in the file PATENTS. All contributing project authors may
  25930 // be found in the AUTHORS file in the root of the source tree.
  25931 // -----------------------------------------------------------------------------
  25932 //
  25933 //   WebP encoder: main interface
  25934 //
  25935 // Author: Skal (pascal.massimino@gmail.com)
  25936 
  25937 // Copyright 2010 Google Inc. All Rights Reserved.
  25938 //
  25939 // Use of this source code is governed by a BSD-style license
  25940 // that can be found in the COPYING file in the root of the source
  25941 // tree. An additional intellectual property rights grant can be found
  25942 // in the file PATENTS. All contributing project authors may
  25943 // be found in the AUTHORS file in the root of the source tree.
  25944 // -----------------------------------------------------------------------------
  25945 //
  25946 //  Common types + memory wrappers
  25947 //
  25948 // Author: Skal (pascal.massimino@gmail.com)
  25949 
  25950 // Uncomment to disable gamma-compression during RGB->U/V averaging
  25951 
  25952 // If defined, use table to compute x / alpha.
  25953 
  25954 // uint32_t 0xff000000 is 0x00,00,00,ff in memory
  25955 
  25956 //------------------------------------------------------------------------------
  25957 // Detection of non-trivial transparency
  25958 
  25959 // C documentation
  25960 //
  25961 //	// Returns true if alpha[] has non-0xff values.
  25962 func CheckNonOpaque(tls *libc.TLS, alpha uintptr, width int32, height int32, x_step int32, y_step int32) (r int32) {
  25963 	var v2 int32
  25964 	_ = v2
  25965 	if alpha == libc.UintptrFromInt32(0) {
  25966 		return 0
  25967 	}
  25968 	WebPInitAlphaProcessing(tls)
  25969 	if x_step == int32(1) {
  25970 		for {
  25971 			v2 = height
  25972 			height = height - 1
  25973 			if !(v2 > 0) {
  25974 				break
  25975 			}
  25976 			if (*(*func(*libc.TLS, uintptr, int32) int32)(unsafe.Pointer(&struct{ uintptr }{WebPHasAlpha8b})))(tls, alpha, width) != 0 {
  25977 				return int32(1)
  25978 			}
  25979 			goto _1
  25980 		_1:
  25981 			;
  25982 			alpha = alpha + uintptr(y_step)
  25983 		}
  25984 	} else {
  25985 		for {
  25986 			v2 = height
  25987 			height = height - 1
  25988 			if !(v2 > 0) {
  25989 				break
  25990 			}
  25991 			if (*(*func(*libc.TLS, uintptr, int32) int32)(unsafe.Pointer(&struct{ uintptr }{WebPHasAlpha32b})))(tls, alpha, width) != 0 {
  25992 				return int32(1)
  25993 			}
  25994 			goto _3
  25995 		_3:
  25996 			;
  25997 			alpha = alpha + uintptr(y_step)
  25998 		}
  25999 	}
  26000 	return 0
  26001 }
  26002 
  26003 // C documentation
  26004 //
  26005 //	// Checking for the presence of non-opaque alpha.
  26006 func WebPPictureHasTransparency(tls *libc.TLS, picture uintptr) (r int32) {
  26007 	if picture == libc.UintptrFromInt32(0) {
  26008 		return 0
  26009 	}
  26010 	if (*WebPPicture)(unsafe.Pointer(picture)).Fuse_argb != 0 {
  26011 		if (*WebPPicture)(unsafe.Pointer(picture)).Fargb != libc.UintptrFromInt32(0) {
  26012 			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), int32(uint64((*WebPPicture)(unsafe.Pointer(picture)).Fargb_stride)*uint64(4)))
  26013 		}
  26014 		return 0
  26015 	}
  26016 	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)
  26017 }
  26018 
  26019 //------------------------------------------------------------------------------
  26020 // Code for gamma correction
  26021 
  26022 // C documentation
  26023 //
  26024 //	// Gamma correction compensates loss of resolution during chroma subsampling.
  26025 var kGamma = float64(0.8)
  26026 var kGammaScale = libc.Int32FromInt32(1)<<libc.Int32FromInt32(GAMMA_FIX) - libc.Int32FromInt32(1)
  26027 var kGammaTabScale = libc.Int32FromInt32(1) << libc.Int32FromInt32(GAMMA_TAB_FIX)
  26028 var kGammaTabRounder = libc.Int32FromInt32(1) << libc.Int32FromInt32(GAMMA_TAB_FIX) >> libc.Int32FromInt32(1)
  26029 
  26030 var kLinearToGammaTab [33]int32
  26031 var kGammaToLinearTab [256]uint16_t
  26032 var kGammaTablesOk = int32(0)
  26033 
  26034 func InitGammaTables(tls *libc.TLS) {
  26035 	if libc.AtomicLoadPUintptr(uintptr(unsafe.Pointer(&InitGammaTables_body_last_cpuinfo_used))) == VP8GetCPUInfo {
  26036 		goto _1
  26037 	}
  26038 	InitGammaTables_body(tls)
  26039 	libc.AtomicStorePUintptr(uintptr(unsafe.Pointer(&InitGammaTables_body_last_cpuinfo_used)), VP8GetCPUInfo)
  26040 	goto _2
  26041 _2:
  26042 	;
  26043 	goto _1
  26044 _1: /**/ //
  26045 }
  26046 
  26047 var InitGammaTables_body_last_cpuinfo_used = uintptr(0)
  26048 
  26049 func init() {
  26050 	p := unsafe.Pointer(&InitGammaTables_body_last_cpuinfo_used)
  26051 	*(*uintptr)(unsafe.Add(p, 0)) = uintptr(unsafe.Pointer(&InitGammaTables_body_last_cpuinfo_used))
  26052 }
  26053 
  26054 func InitGammaTables_body(tls *libc.TLS) {
  26055 	var norm, scale float64
  26056 	var v int32
  26057 	_, _, _ = norm, scale, v
  26058 	if !(libc.AtomicLoadPInt32(uintptr(unsafe.Pointer(&kGammaTablesOk))) != 0) {
  26059 		scale = float64(libc.Int32FromInt32(1)<<libc.Int32FromInt32(GAMMA_TAB_FIX)) / float64(kGammaScale)
  26060 		norm = libc.Float64FromFloat64(1) / libc.Float64FromFloat64(255)
  26061 		v = 0
  26062 		for {
  26063 			if !(v <= int32(255)) {
  26064 				break
  26065 			}
  26066 			kGammaToLinearTab[v] = uint16(float64(libc.Xpow(tls, float64(norm*float64(v)), kGamma)*float64(kGammaScale)) + libc.Float64FromFloat64(0.5))
  26067 			goto _1
  26068 		_1:
  26069 			;
  26070 			v = v + 1
  26071 		}
  26072 		v = 0
  26073 		for {
  26074 			if !(v <= libc.Int32FromInt32(1)<<(libc.Int32FromInt32(GAMMA_FIX)-libc.Int32FromInt32(GAMMA_TAB_FIX))) {
  26075 				break
  26076 			}
  26077 			kLinearToGammaTab[v] = int32(float64(libc.Float64FromFloat64(255)*libc.Xpow(tls, float64(scale*float64(v)), float64(1)/kGamma)) + libc.Float64FromFloat64(0.5))
  26078 			goto _2
  26079 		_2:
  26080 			;
  26081 			v = v + 1
  26082 		}
  26083 		libc.AtomicStorePInt32(uintptr(unsafe.Pointer(&kGammaTablesOk)), int32(1))
  26084 	}
  26085 }
  26086 
  26087 func GammaToLinear(tls *libc.TLS, v uint8_t) (r uint32_t) {
  26088 	return uint32(kGammaToLinearTab[v])
  26089 }
  26090 
  26091 func Interpolate(tls *libc.TLS, v int32) (r int32) {
  26092 	var tab_pos, v0, v1, x, y int32
  26093 	_, _, _, _, _ = tab_pos, v0, v1, x, y
  26094 	tab_pos = v >> (libc.Int32FromInt32(GAMMA_TAB_FIX) + libc.Int32FromInt32(2)) // integer part
  26095 	x = v & (kGammaTabScale<<libc.Int32FromInt32(2) - int32(1))                  // fractional part
  26096 	v0 = kLinearToGammaTab[tab_pos]
  26097 	v1 = kLinearToGammaTab[tab_pos+int32(1)]
  26098 	y = v1*x + v0*(kGammaTabScale<<libc.Int32FromInt32(2)-x) // interpolate
  26099 	return y
  26100 }
  26101 
  26102 // C documentation
  26103 //
  26104 //	// Convert a linear value 'v' to YUV_FIX+2 fixed-point precision
  26105 //	// U/V value, suitable for RGBToU/V calls.
  26106 func LinearToGamma(tls *libc.TLS, base_value uint32_t, shift int32) (r int32) {
  26107 	var y int32
  26108 	_ = y
  26109 	y = Interpolate(tls, int32(base_value<<shift))        // final uplifted value
  26110 	return (y + kGammaTabRounder) >> int32(GAMMA_TAB_FIX) // descale
  26111 }
  26112 
  26113 //------------------------------------------------------------------------------
  26114 // RGB -> YUV conversion
  26115 
  26116 func RGBToY(tls *libc.TLS, r1 int32, g1 int32, b1 int32, rg2 uintptr) (r int32) {
  26117 	var diff, luma, v1, v11, v13, v15, v2, v5, v8, v9 int32
  26118 	var v10, v12, v4, v7 uintptr
  26119 	_, _, _, _, _, _, _, _, _, _, _, _, _, _ = diff, luma, v1, v10, v11, v12, v13, v15, v2, v4, v5, v7, v8, v9
  26120 	if rg2 == libc.UintptrFromInt32(0) {
  26121 		luma = int32(16839)*r1 + int32(33059)*g1 + int32(6420)*b1
  26122 		v2 = (luma + int32(YUV_HALF) + libc.Int32FromInt32(16)<<int32(YUV_FIX)) >> int32(YUV_FIX)
  26123 		goto _3
  26124 	_3:
  26125 		v1 = v2
  26126 	} else {
  26127 		v4 = rg2
  26128 		v7 = v4
  26129 		v8 = int32(YUV_FIX)
  26130 		diff = int32(**(**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)))
  26131 		if diff < libc.Int32FromInt32(0) {
  26132 			diff = int32(uint32(diff) + libc.Uint32FromUint32(1)<<libc.Int32FromInt32(31))
  26133 		}
  26134 		**(**uint32_t)(__ccgo_up(v7 + 8 + uintptr((*VP8Random)(unsafe.Pointer(v7)).Findex1)*4)) = uint32(diff)
  26135 		v10 = v7
  26136 		*(*int32)(unsafe.Pointer(v10)) = *(*int32)(unsafe.Pointer(v10)) + 1
  26137 		v9 = *(*int32)(unsafe.Pointer(v10))
  26138 		if v9 == libc.Int32FromInt32(VP8_RANDOM_TABLE_SIZE) {
  26139 			(*VP8Random)(unsafe.Pointer(v7)).Findex1 = 0
  26140 		}
  26141 		v12 = v7 + 4
  26142 		*(*int32)(unsafe.Pointer(v12)) = *(*int32)(unsafe.Pointer(v12)) + 1
  26143 		v11 = *(*int32)(unsafe.Pointer(v12))
  26144 		if v11 == libc.Int32FromInt32(VP8_RANDOM_TABLE_SIZE) {
  26145 			(*VP8Random)(unsafe.Pointer(v7)).Findex2 = 0
  26146 		}
  26147 		diff = int32(uint32(diff)<<libc.Int32FromInt32(1)) >> (int32(32) - v8)
  26148 		diff = diff * (*VP8Random)(unsafe.Pointer(v4)).Famp >> int32(VP8_RANDOM_DITHER_FIX)
  26149 		diff = diff + int32(1)<<(v8-int32(1))
  26150 		v13 = diff
  26151 		goto _14
  26152 	_14:
  26153 		v5 = v13
  26154 		goto _6
  26155 	_6:
  26156 		luma = int32(16839)*r1 + int32(33059)*g1 + int32(6420)*b1
  26157 		v15 = (luma + v5 + libc.Int32FromInt32(16)<<int32(YUV_FIX)) >> int32(YUV_FIX)
  26158 		goto _16
  26159 	_16:
  26160 		v1 = v15
  26161 	}
  26162 	return v1
  26163 }
  26164 
  26165 func RGBToU(tls *libc.TLS, r1 int32, g1 int32, b1 int32, rg2 uintptr) (r int32) {
  26166 	var diff, u, v1, v10, v13, v14, v16, v18, v2, v20, v22, v23, v25, v26, v4, v5, v7, v8 int32
  26167 	var v12, v15, v17, v9 uintptr
  26168 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = diff, u, v1, v10, v12, v13, v14, v15, v16, v17, v18, v2, v20, v22, v23, v25, v26, v4, v5, v7, v8, v9
  26169 	if rg2 == libc.UintptrFromInt32(0) {
  26170 		u = -int32(9719)*r1 - int32(19081)*g1 + int32(28800)*b1
  26171 		v4 = u
  26172 		v4 = (v4 + int32(YUV_HALF)<<libc.Int32FromInt32(2) + libc.Int32FromInt32(128)<<(int32(YUV_FIX)+libc.Int32FromInt32(2))) >> (int32(YUV_FIX) + libc.Int32FromInt32(2))
  26173 		if v4 & ^libc.Int32FromInt32(0xff) == 0 {
  26174 			v7 = v4
  26175 		} else {
  26176 			if v4 < 0 {
  26177 				v8 = 0
  26178 			} else {
  26179 				v8 = int32(255)
  26180 			}
  26181 			v7 = v8
  26182 		}
  26183 		v5 = v7
  26184 		goto _6
  26185 	_6:
  26186 		v2 = v5
  26187 		goto _3
  26188 	_3:
  26189 		v1 = v2
  26190 	} else {
  26191 		v9 = rg2
  26192 		v12 = v9
  26193 		v13 = int32(YUV_FIX) + libc.Int32FromInt32(2)
  26194 		diff = int32(**(**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)))
  26195 		if diff < libc.Int32FromInt32(0) {
  26196 			diff = int32(uint32(diff) + libc.Uint32FromUint32(1)<<libc.Int32FromInt32(31))
  26197 		}
  26198 		**(**uint32_t)(__ccgo_up(v12 + 8 + uintptr((*VP8Random)(unsafe.Pointer(v12)).Findex1)*4)) = uint32(diff)
  26199 		v15 = v12
  26200 		*(*int32)(unsafe.Pointer(v15)) = *(*int32)(unsafe.Pointer(v15)) + 1
  26201 		v14 = *(*int32)(unsafe.Pointer(v15))
  26202 		if v14 == libc.Int32FromInt32(VP8_RANDOM_TABLE_SIZE) {
  26203 			(*VP8Random)(unsafe.Pointer(v12)).Findex1 = 0
  26204 		}
  26205 		v17 = v12 + 4
  26206 		*(*int32)(unsafe.Pointer(v17)) = *(*int32)(unsafe.Pointer(v17)) + 1
  26207 		v16 = *(*int32)(unsafe.Pointer(v17))
  26208 		if v16 == libc.Int32FromInt32(VP8_RANDOM_TABLE_SIZE) {
  26209 			(*VP8Random)(unsafe.Pointer(v12)).Findex2 = 0
  26210 		}
  26211 		diff = int32(uint32(diff)<<libc.Int32FromInt32(1)) >> (int32(32) - v13)
  26212 		diff = diff * (*VP8Random)(unsafe.Pointer(v9)).Famp >> int32(VP8_RANDOM_DITHER_FIX)
  26213 		diff = diff + int32(1)<<(v13-int32(1))
  26214 		v18 = diff
  26215 		goto _19
  26216 	_19:
  26217 		v10 = v18
  26218 		goto _11
  26219 	_11:
  26220 		u = -int32(9719)*r1 - int32(19081)*g1 + int32(28800)*b1
  26221 		v22 = u
  26222 		v22 = (v22 + v10 + libc.Int32FromInt32(128)<<(int32(YUV_FIX)+libc.Int32FromInt32(2))) >> (int32(YUV_FIX) + libc.Int32FromInt32(2))
  26223 		if v22 & ^libc.Int32FromInt32(0xff) == 0 {
  26224 			v25 = v22
  26225 		} else {
  26226 			if v22 < 0 {
  26227 				v26 = 0
  26228 			} else {
  26229 				v26 = int32(255)
  26230 			}
  26231 			v25 = v26
  26232 		}
  26233 		v23 = v25
  26234 		goto _24
  26235 	_24:
  26236 		v20 = v23
  26237 		goto _21
  26238 	_21:
  26239 		v1 = v20
  26240 	}
  26241 	return v1
  26242 }
  26243 
  26244 func RGBToV(tls *libc.TLS, r1 int32, g1 int32, b1 int32, rg2 uintptr) (r int32) {
  26245 	var diff, v, v1, v10, v13, v14, v16, v18, v2, v20, v22, v23, v25, v26, v4, v5, v7, v8 int32
  26246 	var v12, v15, v17, v9 uintptr
  26247 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = diff, v, v1, v10, v12, v13, v14, v15, v16, v17, v18, v2, v20, v22, v23, v25, v26, v4, v5, v7, v8, v9
  26248 	if rg2 == libc.UintptrFromInt32(0) {
  26249 		v = +libc.Int32FromInt32(28800)*r1 - int32(24116)*g1 - int32(4684)*b1
  26250 		v4 = v
  26251 		v4 = (v4 + int32(YUV_HALF)<<libc.Int32FromInt32(2) + libc.Int32FromInt32(128)<<(int32(YUV_FIX)+libc.Int32FromInt32(2))) >> (int32(YUV_FIX) + libc.Int32FromInt32(2))
  26252 		if v4 & ^libc.Int32FromInt32(0xff) == 0 {
  26253 			v7 = v4
  26254 		} else {
  26255 			if v4 < 0 {
  26256 				v8 = 0
  26257 			} else {
  26258 				v8 = int32(255)
  26259 			}
  26260 			v7 = v8
  26261 		}
  26262 		v5 = v7
  26263 		goto _6
  26264 	_6:
  26265 		v2 = v5
  26266 		goto _3
  26267 	_3:
  26268 		v1 = v2
  26269 	} else {
  26270 		v9 = rg2
  26271 		v12 = v9
  26272 		v13 = int32(YUV_FIX) + libc.Int32FromInt32(2)
  26273 		diff = int32(**(**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)))
  26274 		if diff < libc.Int32FromInt32(0) {
  26275 			diff = int32(uint32(diff) + libc.Uint32FromUint32(1)<<libc.Int32FromInt32(31))
  26276 		}
  26277 		**(**uint32_t)(__ccgo_up(v12 + 8 + uintptr((*VP8Random)(unsafe.Pointer(v12)).Findex1)*4)) = uint32(diff)
  26278 		v15 = v12
  26279 		*(*int32)(unsafe.Pointer(v15)) = *(*int32)(unsafe.Pointer(v15)) + 1
  26280 		v14 = *(*int32)(unsafe.Pointer(v15))
  26281 		if v14 == libc.Int32FromInt32(VP8_RANDOM_TABLE_SIZE) {
  26282 			(*VP8Random)(unsafe.Pointer(v12)).Findex1 = 0
  26283 		}
  26284 		v17 = v12 + 4
  26285 		*(*int32)(unsafe.Pointer(v17)) = *(*int32)(unsafe.Pointer(v17)) + 1
  26286 		v16 = *(*int32)(unsafe.Pointer(v17))
  26287 		if v16 == libc.Int32FromInt32(VP8_RANDOM_TABLE_SIZE) {
  26288 			(*VP8Random)(unsafe.Pointer(v12)).Findex2 = 0
  26289 		}
  26290 		diff = int32(uint32(diff)<<libc.Int32FromInt32(1)) >> (int32(32) - v13)
  26291 		diff = diff * (*VP8Random)(unsafe.Pointer(v9)).Famp >> int32(VP8_RANDOM_DITHER_FIX)
  26292 		diff = diff + int32(1)<<(v13-int32(1))
  26293 		v18 = diff
  26294 		goto _19
  26295 	_19:
  26296 		v10 = v18
  26297 		goto _11
  26298 	_11:
  26299 		v = +libc.Int32FromInt32(28800)*r1 - int32(24116)*g1 - int32(4684)*b1
  26300 		v22 = v
  26301 		v22 = (v22 + v10 + libc.Int32FromInt32(128)<<(int32(YUV_FIX)+libc.Int32FromInt32(2))) >> (int32(YUV_FIX) + libc.Int32FromInt32(2))
  26302 		if v22 & ^libc.Int32FromInt32(0xff) == 0 {
  26303 			v25 = v22
  26304 		} else {
  26305 			if v22 < 0 {
  26306 				v26 = 0
  26307 			} else {
  26308 				v26 = int32(255)
  26309 			}
  26310 			v25 = v26
  26311 		}
  26312 		v23 = v25
  26313 		goto _24
  26314 	_24:
  26315 		v20 = v23
  26316 		goto _21
  26317 	_21:
  26318 		v1 = v20
  26319 	}
  26320 	return v1
  26321 }
  26322 
  26323 //------------------------------------------------------------------------------
  26324 // Sharp RGB->YUV conversion
  26325 
  26326 var kMinDimensionIterativeConversion = int32(4)
  26327 
  26328 //------------------------------------------------------------------------------
  26329 // Main function
  26330 
  26331 func PreprocessARGB(tls *libc.TLS, r_ptr uintptr, g_ptr uintptr, b_ptr uintptr, step int32, rgb_stride int32, picture uintptr) (r int32) {
  26332 	var ok int32
  26333 	_ = ok
  26334 	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)))
  26335 	if !(ok != 0) {
  26336 		return WebPEncodingSetError(tls, picture, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  26337 	}
  26338 	return ok
  26339 }
  26340 
  26341 //------------------------------------------------------------------------------
  26342 // "Fast" regular RGB->YUV
  26343 
  26344 var kAlphaFix = int32(19)
  26345 
  26346 // C documentation
  26347 //
  26348 //	// Following table is (1 << kAlphaFix) / a. The (v * kInvAlpha[a]) >> kAlphaFix
  26349 //	// formula is then equal to v / a in most (99.6%) cases. Note that this table
  26350 //	// and constant are adjusted very tightly to fit 32b arithmetic.
  26351 //	// In particular, they use the fact that the operands for 'v / a' are actually
  26352 //	// derived as v = (a0.p0 + a1.p1 + a2.p2 + a3.p3) and a = a0 + a1 + a2 + a3
  26353 //	// with ai in [0..255] and pi in [0..1<<GAMMA_FIX). The constraint to avoid
  26354 //	// overflow is: GAMMA_FIX + kAlphaFix <= 31.
  26355 var kInvAlpha = [1021]uint32_t{
  26356 	1:    uint32(524288),
  26357 	2:    uint32(262144),
  26358 	3:    uint32(174762),
  26359 	4:    uint32(131072),
  26360 	5:    uint32(104857),
  26361 	6:    uint32(87381),
  26362 	7:    uint32(74898),
  26363 	8:    uint32(65536),
  26364 	9:    uint32(58254),
  26365 	10:   uint32(52428),
  26366 	11:   uint32(47662),
  26367 	12:   uint32(43690),
  26368 	13:   uint32(40329),
  26369 	14:   uint32(37449),
  26370 	15:   uint32(34952),
  26371 	16:   uint32(32768),
  26372 	17:   uint32(30840),
  26373 	18:   uint32(29127),
  26374 	19:   uint32(27594),
  26375 	20:   uint32(26214),
  26376 	21:   uint32(24966),
  26377 	22:   uint32(23831),
  26378 	23:   uint32(22795),
  26379 	24:   uint32(21845),
  26380 	25:   uint32(20971),
  26381 	26:   uint32(20164),
  26382 	27:   uint32(19418),
  26383 	28:   uint32(18724),
  26384 	29:   uint32(18078),
  26385 	30:   uint32(17476),
  26386 	31:   uint32(16912),
  26387 	32:   uint32(16384),
  26388 	33:   uint32(15887),
  26389 	34:   uint32(15420),
  26390 	35:   uint32(14979),
  26391 	36:   uint32(14563),
  26392 	37:   uint32(14169),
  26393 	38:   uint32(13797),
  26394 	39:   uint32(13443),
  26395 	40:   uint32(13107),
  26396 	41:   uint32(12787),
  26397 	42:   uint32(12483),
  26398 	43:   uint32(12192),
  26399 	44:   uint32(11915),
  26400 	45:   uint32(11650),
  26401 	46:   uint32(11397),
  26402 	47:   uint32(11155),
  26403 	48:   uint32(10922),
  26404 	49:   uint32(10699),
  26405 	50:   uint32(10485),
  26406 	51:   uint32(10280),
  26407 	52:   uint32(10082),
  26408 	53:   uint32(9892),
  26409 	54:   uint32(9709),
  26410 	55:   uint32(9532),
  26411 	56:   uint32(9362),
  26412 	57:   uint32(9198),
  26413 	58:   uint32(9039),
  26414 	59:   uint32(8886),
  26415 	60:   uint32(8738),
  26416 	61:   uint32(8594),
  26417 	62:   uint32(8456),
  26418 	63:   uint32(8322),
  26419 	64:   uint32(8192),
  26420 	65:   uint32(8065),
  26421 	66:   uint32(7943),
  26422 	67:   uint32(7825),
  26423 	68:   uint32(7710),
  26424 	69:   uint32(7598),
  26425 	70:   uint32(7489),
  26426 	71:   uint32(7384),
  26427 	72:   uint32(7281),
  26428 	73:   uint32(7182),
  26429 	74:   uint32(7084),
  26430 	75:   uint32(6990),
  26431 	76:   uint32(6898),
  26432 	77:   uint32(6808),
  26433 	78:   uint32(6721),
  26434 	79:   uint32(6636),
  26435 	80:   uint32(6553),
  26436 	81:   uint32(6472),
  26437 	82:   uint32(6393),
  26438 	83:   uint32(6316),
  26439 	84:   uint32(6241),
  26440 	85:   uint32(6168),
  26441 	86:   uint32(6096),
  26442 	87:   uint32(6026),
  26443 	88:   uint32(5957),
  26444 	89:   uint32(5890),
  26445 	90:   uint32(5825),
  26446 	91:   uint32(5761),
  26447 	92:   uint32(5698),
  26448 	93:   uint32(5637),
  26449 	94:   uint32(5577),
  26450 	95:   uint32(5518),
  26451 	96:   uint32(5461),
  26452 	97:   uint32(5405),
  26453 	98:   uint32(5349),
  26454 	99:   uint32(5295),
  26455 	100:  uint32(5242),
  26456 	101:  uint32(5190),
  26457 	102:  uint32(5140),
  26458 	103:  uint32(5090),
  26459 	104:  uint32(5041),
  26460 	105:  uint32(4993),
  26461 	106:  uint32(4946),
  26462 	107:  uint32(4899),
  26463 	108:  uint32(4854),
  26464 	109:  uint32(4809),
  26465 	110:  uint32(4766),
  26466 	111:  uint32(4723),
  26467 	112:  uint32(4681),
  26468 	113:  uint32(4639),
  26469 	114:  uint32(4599),
  26470 	115:  uint32(4559),
  26471 	116:  uint32(4519),
  26472 	117:  uint32(4481),
  26473 	118:  uint32(4443),
  26474 	119:  uint32(4405),
  26475 	120:  uint32(4369),
  26476 	121:  uint32(4332),
  26477 	122:  uint32(4297),
  26478 	123:  uint32(4262),
  26479 	124:  uint32(4228),
  26480 	125:  uint32(4194),
  26481 	126:  uint32(4161),
  26482 	127:  uint32(4128),
  26483 	128:  uint32(4096),
  26484 	129:  uint32(4064),
  26485 	130:  uint32(4032),
  26486 	131:  uint32(4002),
  26487 	132:  uint32(3971),
  26488 	133:  uint32(3942),
  26489 	134:  uint32(3912),
  26490 	135:  uint32(3883),
  26491 	136:  uint32(3855),
  26492 	137:  uint32(3826),
  26493 	138:  uint32(3799),
  26494 	139:  uint32(3771),
  26495 	140:  uint32(3744),
  26496 	141:  uint32(3718),
  26497 	142:  uint32(3692),
  26498 	143:  uint32(3666),
  26499 	144:  uint32(3640),
  26500 	145:  uint32(3615),
  26501 	146:  uint32(3591),
  26502 	147:  uint32(3566),
  26503 	148:  uint32(3542),
  26504 	149:  uint32(3518),
  26505 	150:  uint32(3495),
  26506 	151:  uint32(3472),
  26507 	152:  uint32(3449),
  26508 	153:  uint32(3426),
  26509 	154:  uint32(3404),
  26510 	155:  uint32(3382),
  26511 	156:  uint32(3360),
  26512 	157:  uint32(3339),
  26513 	158:  uint32(3318),
  26514 	159:  uint32(3297),
  26515 	160:  uint32(3276),
  26516 	161:  uint32(3256),
  26517 	162:  uint32(3236),
  26518 	163:  uint32(3216),
  26519 	164:  uint32(3196),
  26520 	165:  uint32(3177),
  26521 	166:  uint32(3158),
  26522 	167:  uint32(3139),
  26523 	168:  uint32(3120),
  26524 	169:  uint32(3102),
  26525 	170:  uint32(3084),
  26526 	171:  uint32(3066),
  26527 	172:  uint32(3048),
  26528 	173:  uint32(3030),
  26529 	174:  uint32(3013),
  26530 	175:  uint32(2995),
  26531 	176:  uint32(2978),
  26532 	177:  uint32(2962),
  26533 	178:  uint32(2945),
  26534 	179:  uint32(2928),
  26535 	180:  uint32(2912),
  26536 	181:  uint32(2896),
  26537 	182:  uint32(2880),
  26538 	183:  uint32(2864),
  26539 	184:  uint32(2849),
  26540 	185:  uint32(2833),
  26541 	186:  uint32(2818),
  26542 	187:  uint32(2803),
  26543 	188:  uint32(2788),
  26544 	189:  uint32(2774),
  26545 	190:  uint32(2759),
  26546 	191:  uint32(2744),
  26547 	192:  uint32(2730),
  26548 	193:  uint32(2716),
  26549 	194:  uint32(2702),
  26550 	195:  uint32(2688),
  26551 	196:  uint32(2674),
  26552 	197:  uint32(2661),
  26553 	198:  uint32(2647),
  26554 	199:  uint32(2634),
  26555 	200:  uint32(2621),
  26556 	201:  uint32(2608),
  26557 	202:  uint32(2595),
  26558 	203:  uint32(2582),
  26559 	204:  uint32(2570),
  26560 	205:  uint32(2557),
  26561 	206:  uint32(2545),
  26562 	207:  uint32(2532),
  26563 	208:  uint32(2520),
  26564 	209:  uint32(2508),
  26565 	210:  uint32(2496),
  26566 	211:  uint32(2484),
  26567 	212:  uint32(2473),
  26568 	213:  uint32(2461),
  26569 	214:  uint32(2449),
  26570 	215:  uint32(2438),
  26571 	216:  uint32(2427),
  26572 	217:  uint32(2416),
  26573 	218:  uint32(2404),
  26574 	219:  uint32(2394),
  26575 	220:  uint32(2383),
  26576 	221:  uint32(2372),
  26577 	222:  uint32(2361),
  26578 	223:  uint32(2351),
  26579 	224:  uint32(2340),
  26580 	225:  uint32(2330),
  26581 	226:  uint32(2319),
  26582 	227:  uint32(2309),
  26583 	228:  uint32(2299),
  26584 	229:  uint32(2289),
  26585 	230:  uint32(2279),
  26586 	231:  uint32(2269),
  26587 	232:  uint32(2259),
  26588 	233:  uint32(2250),
  26589 	234:  uint32(2240),
  26590 	235:  uint32(2231),
  26591 	236:  uint32(2221),
  26592 	237:  uint32(2212),
  26593 	238:  uint32(2202),
  26594 	239:  uint32(2193),
  26595 	240:  uint32(2184),
  26596 	241:  uint32(2175),
  26597 	242:  uint32(2166),
  26598 	243:  uint32(2157),
  26599 	244:  uint32(2148),
  26600 	245:  uint32(2139),
  26601 	246:  uint32(2131),
  26602 	247:  uint32(2122),
  26603 	248:  uint32(2114),
  26604 	249:  uint32(2105),
  26605 	250:  uint32(2097),
  26606 	251:  uint32(2088),
  26607 	252:  uint32(2080),
  26608 	253:  uint32(2072),
  26609 	254:  uint32(2064),
  26610 	255:  uint32(2056),
  26611 	256:  uint32(2048),
  26612 	257:  uint32(2040),
  26613 	258:  uint32(2032),
  26614 	259:  uint32(2024),
  26615 	260:  uint32(2016),
  26616 	261:  uint32(2008),
  26617 	262:  uint32(2001),
  26618 	263:  uint32(1993),
  26619 	264:  uint32(1985),
  26620 	265:  uint32(1978),
  26621 	266:  uint32(1971),
  26622 	267:  uint32(1963),
  26623 	268:  uint32(1956),
  26624 	269:  uint32(1949),
  26625 	270:  uint32(1941),
  26626 	271:  uint32(1934),
  26627 	272:  uint32(1927),
  26628 	273:  uint32(1920),
  26629 	274:  uint32(1913),
  26630 	275:  uint32(1906),
  26631 	276:  uint32(1899),
  26632 	277:  uint32(1892),
  26633 	278:  uint32(1885),
  26634 	279:  uint32(1879),
  26635 	280:  uint32(1872),
  26636 	281:  uint32(1865),
  26637 	282:  uint32(1859),
  26638 	283:  uint32(1852),
  26639 	284:  uint32(1846),
  26640 	285:  uint32(1839),
  26641 	286:  uint32(1833),
  26642 	287:  uint32(1826),
  26643 	288:  uint32(1820),
  26644 	289:  uint32(1814),
  26645 	290:  uint32(1807),
  26646 	291:  uint32(1801),
  26647 	292:  uint32(1795),
  26648 	293:  uint32(1789),
  26649 	294:  uint32(1783),
  26650 	295:  uint32(1777),
  26651 	296:  uint32(1771),
  26652 	297:  uint32(1765),
  26653 	298:  uint32(1759),
  26654 	299:  uint32(1753),
  26655 	300:  uint32(1747),
  26656 	301:  uint32(1741),
  26657 	302:  uint32(1736),
  26658 	303:  uint32(1730),
  26659 	304:  uint32(1724),
  26660 	305:  uint32(1718),
  26661 	306:  uint32(1713),
  26662 	307:  uint32(1707),
  26663 	308:  uint32(1702),
  26664 	309:  uint32(1696),
  26665 	310:  uint32(1691),
  26666 	311:  uint32(1685),
  26667 	312:  uint32(1680),
  26668 	313:  uint32(1675),
  26669 	314:  uint32(1669),
  26670 	315:  uint32(1664),
  26671 	316:  uint32(1659),
  26672 	317:  uint32(1653),
  26673 	318:  uint32(1648),
  26674 	319:  uint32(1643),
  26675 	320:  uint32(1638),
  26676 	321:  uint32(1633),
  26677 	322:  uint32(1628),
  26678 	323:  uint32(1623),
  26679 	324:  uint32(1618),
  26680 	325:  uint32(1613),
  26681 	326:  uint32(1608),
  26682 	327:  uint32(1603),
  26683 	328:  uint32(1598),
  26684 	329:  uint32(1593),
  26685 	330:  uint32(1588),
  26686 	331:  uint32(1583),
  26687 	332:  uint32(1579),
  26688 	333:  uint32(1574),
  26689 	334:  uint32(1569),
  26690 	335:  uint32(1565),
  26691 	336:  uint32(1560),
  26692 	337:  uint32(1555),
  26693 	338:  uint32(1551),
  26694 	339:  uint32(1546),
  26695 	340:  uint32(1542),
  26696 	341:  uint32(1537),
  26697 	342:  uint32(1533),
  26698 	343:  uint32(1528),
  26699 	344:  uint32(1524),
  26700 	345:  uint32(1519),
  26701 	346:  uint32(1515),
  26702 	347:  uint32(1510),
  26703 	348:  uint32(1506),
  26704 	349:  uint32(1502),
  26705 	350:  uint32(1497),
  26706 	351:  uint32(1493),
  26707 	352:  uint32(1489),
  26708 	353:  uint32(1485),
  26709 	354:  uint32(1481),
  26710 	355:  uint32(1476),
  26711 	356:  uint32(1472),
  26712 	357:  uint32(1468),
  26713 	358:  uint32(1464),
  26714 	359:  uint32(1460),
  26715 	360:  uint32(1456),
  26716 	361:  uint32(1452),
  26717 	362:  uint32(1448),
  26718 	363:  uint32(1444),
  26719 	364:  uint32(1440),
  26720 	365:  uint32(1436),
  26721 	366:  uint32(1432),
  26722 	367:  uint32(1428),
  26723 	368:  uint32(1424),
  26724 	369:  uint32(1420),
  26725 	370:  uint32(1416),
  26726 	371:  uint32(1413),
  26727 	372:  uint32(1409),
  26728 	373:  uint32(1405),
  26729 	374:  uint32(1401),
  26730 	375:  uint32(1398),
  26731 	376:  uint32(1394),
  26732 	377:  uint32(1390),
  26733 	378:  uint32(1387),
  26734 	379:  uint32(1383),
  26735 	380:  uint32(1379),
  26736 	381:  uint32(1376),
  26737 	382:  uint32(1372),
  26738 	383:  uint32(1368),
  26739 	384:  uint32(1365),
  26740 	385:  uint32(1361),
  26741 	386:  uint32(1358),
  26742 	387:  uint32(1354),
  26743 	388:  uint32(1351),
  26744 	389:  uint32(1347),
  26745 	390:  uint32(1344),
  26746 	391:  uint32(1340),
  26747 	392:  uint32(1337),
  26748 	393:  uint32(1334),
  26749 	394:  uint32(1330),
  26750 	395:  uint32(1327),
  26751 	396:  uint32(1323),
  26752 	397:  uint32(1320),
  26753 	398:  uint32(1317),
  26754 	399:  uint32(1314),
  26755 	400:  uint32(1310),
  26756 	401:  uint32(1307),
  26757 	402:  uint32(1304),
  26758 	403:  uint32(1300),
  26759 	404:  uint32(1297),
  26760 	405:  uint32(1294),
  26761 	406:  uint32(1291),
  26762 	407:  uint32(1288),
  26763 	408:  uint32(1285),
  26764 	409:  uint32(1281),
  26765 	410:  uint32(1278),
  26766 	411:  uint32(1275),
  26767 	412:  uint32(1272),
  26768 	413:  uint32(1269),
  26769 	414:  uint32(1266),
  26770 	415:  uint32(1263),
  26771 	416:  uint32(1260),
  26772 	417:  uint32(1257),
  26773 	418:  uint32(1254),
  26774 	419:  uint32(1251),
  26775 	420:  uint32(1248),
  26776 	421:  uint32(1245),
  26777 	422:  uint32(1242),
  26778 	423:  uint32(1239),
  26779 	424:  uint32(1236),
  26780 	425:  uint32(1233),
  26781 	426:  uint32(1230),
  26782 	427:  uint32(1227),
  26783 	428:  uint32(1224),
  26784 	429:  uint32(1222),
  26785 	430:  uint32(1219),
  26786 	431:  uint32(1216),
  26787 	432:  uint32(1213),
  26788 	433:  uint32(1210),
  26789 	434:  uint32(1208),
  26790 	435:  uint32(1205),
  26791 	436:  uint32(1202),
  26792 	437:  uint32(1199),
  26793 	438:  uint32(1197),
  26794 	439:  uint32(1194),
  26795 	440:  uint32(1191),
  26796 	441:  uint32(1188),
  26797 	442:  uint32(1186),
  26798 	443:  uint32(1183),
  26799 	444:  uint32(1180),
  26800 	445:  uint32(1178),
  26801 	446:  uint32(1175),
  26802 	447:  uint32(1172),
  26803 	448:  uint32(1170),
  26804 	449:  uint32(1167),
  26805 	450:  uint32(1165),
  26806 	451:  uint32(1162),
  26807 	452:  uint32(1159),
  26808 	453:  uint32(1157),
  26809 	454:  uint32(1154),
  26810 	455:  uint32(1152),
  26811 	456:  uint32(1149),
  26812 	457:  uint32(1147),
  26813 	458:  uint32(1144),
  26814 	459:  uint32(1142),
  26815 	460:  uint32(1139),
  26816 	461:  uint32(1137),
  26817 	462:  uint32(1134),
  26818 	463:  uint32(1132),
  26819 	464:  uint32(1129),
  26820 	465:  uint32(1127),
  26821 	466:  uint32(1125),
  26822 	467:  uint32(1122),
  26823 	468:  uint32(1120),
  26824 	469:  uint32(1117),
  26825 	470:  uint32(1115),
  26826 	471:  uint32(1113),
  26827 	472:  uint32(1110),
  26828 	473:  uint32(1108),
  26829 	474:  uint32(1106),
  26830 	475:  uint32(1103),
  26831 	476:  uint32(1101),
  26832 	477:  uint32(1099),
  26833 	478:  uint32(1096),
  26834 	479:  uint32(1094),
  26835 	480:  uint32(1092),
  26836 	481:  uint32(1089),
  26837 	482:  uint32(1087),
  26838 	483:  uint32(1085),
  26839 	484:  uint32(1083),
  26840 	485:  uint32(1081),
  26841 	486:  uint32(1078),
  26842 	487:  uint32(1076),
  26843 	488:  uint32(1074),
  26844 	489:  uint32(1072),
  26845 	490:  uint32(1069),
  26846 	491:  uint32(1067),
  26847 	492:  uint32(1065),
  26848 	493:  uint32(1063),
  26849 	494:  uint32(1061),
  26850 	495:  uint32(1059),
  26851 	496:  uint32(1057),
  26852 	497:  uint32(1054),
  26853 	498:  uint32(1052),
  26854 	499:  uint32(1050),
  26855 	500:  uint32(1048),
  26856 	501:  uint32(1046),
  26857 	502:  uint32(1044),
  26858 	503:  uint32(1042),
  26859 	504:  uint32(1040),
  26860 	505:  uint32(1038),
  26861 	506:  uint32(1036),
  26862 	507:  uint32(1034),
  26863 	508:  uint32(1032),
  26864 	509:  uint32(1030),
  26865 	510:  uint32(1028),
  26866 	511:  uint32(1026),
  26867 	512:  uint32(1024),
  26868 	513:  uint32(1022),
  26869 	514:  uint32(1020),
  26870 	515:  uint32(1018),
  26871 	516:  uint32(1016),
  26872 	517:  uint32(1014),
  26873 	518:  uint32(1012),
  26874 	519:  uint32(1010),
  26875 	520:  uint32(1008),
  26876 	521:  uint32(1006),
  26877 	522:  uint32(1004),
  26878 	523:  uint32(1002),
  26879 	524:  uint32(1000),
  26880 	525:  uint32(998),
  26881 	526:  uint32(996),
  26882 	527:  uint32(994),
  26883 	528:  uint32(992),
  26884 	529:  uint32(991),
  26885 	530:  uint32(989),
  26886 	531:  uint32(987),
  26887 	532:  uint32(985),
  26888 	533:  uint32(983),
  26889 	534:  uint32(981),
  26890 	535:  uint32(979),
  26891 	536:  uint32(978),
  26892 	537:  uint32(976),
  26893 	538:  uint32(974),
  26894 	539:  uint32(972),
  26895 	540:  uint32(970),
  26896 	541:  uint32(969),
  26897 	542:  uint32(967),
  26898 	543:  uint32(965),
  26899 	544:  uint32(963),
  26900 	545:  uint32(961),
  26901 	546:  uint32(960),
  26902 	547:  uint32(958),
  26903 	548:  uint32(956),
  26904 	549:  uint32(954),
  26905 	550:  uint32(953),
  26906 	551:  uint32(951),
  26907 	552:  uint32(949),
  26908 	553:  uint32(948),
  26909 	554:  uint32(946),
  26910 	555:  uint32(944),
  26911 	556:  uint32(942),
  26912 	557:  uint32(941),
  26913 	558:  uint32(939),
  26914 	559:  uint32(937),
  26915 	560:  uint32(936),
  26916 	561:  uint32(934),
  26917 	562:  uint32(932),
  26918 	563:  uint32(931),
  26919 	564:  uint32(929),
  26920 	565:  uint32(927),
  26921 	566:  uint32(926),
  26922 	567:  uint32(924),
  26923 	568:  uint32(923),
  26924 	569:  uint32(921),
  26925 	570:  uint32(919),
  26926 	571:  uint32(918),
  26927 	572:  uint32(916),
  26928 	573:  uint32(914),
  26929 	574:  uint32(913),
  26930 	575:  uint32(911),
  26931 	576:  uint32(910),
  26932 	577:  uint32(908),
  26933 	578:  uint32(907),
  26934 	579:  uint32(905),
  26935 	580:  uint32(903),
  26936 	581:  uint32(902),
  26937 	582:  uint32(900),
  26938 	583:  uint32(899),
  26939 	584:  uint32(897),
  26940 	585:  uint32(896),
  26941 	586:  uint32(894),
  26942 	587:  uint32(893),
  26943 	588:  uint32(891),
  26944 	589:  uint32(890),
  26945 	590:  uint32(888),
  26946 	591:  uint32(887),
  26947 	592:  uint32(885),
  26948 	593:  uint32(884),
  26949 	594:  uint32(882),
  26950 	595:  uint32(881),
  26951 	596:  uint32(879),
  26952 	597:  uint32(878),
  26953 	598:  uint32(876),
  26954 	599:  uint32(875),
  26955 	600:  uint32(873),
  26956 	601:  uint32(872),
  26957 	602:  uint32(870),
  26958 	603:  uint32(869),
  26959 	604:  uint32(868),
  26960 	605:  uint32(866),
  26961 	606:  uint32(865),
  26962 	607:  uint32(863),
  26963 	608:  uint32(862),
  26964 	609:  uint32(860),
  26965 	610:  uint32(859),
  26966 	611:  uint32(858),
  26967 	612:  uint32(856),
  26968 	613:  uint32(855),
  26969 	614:  uint32(853),
  26970 	615:  uint32(852),
  26971 	616:  uint32(851),
  26972 	617:  uint32(849),
  26973 	618:  uint32(848),
  26974 	619:  uint32(846),
  26975 	620:  uint32(845),
  26976 	621:  uint32(844),
  26977 	622:  uint32(842),
  26978 	623:  uint32(841),
  26979 	624:  uint32(840),
  26980 	625:  uint32(838),
  26981 	626:  uint32(837),
  26982 	627:  uint32(836),
  26983 	628:  uint32(834),
  26984 	629:  uint32(833),
  26985 	630:  uint32(832),
  26986 	631:  uint32(830),
  26987 	632:  uint32(829),
  26988 	633:  uint32(828),
  26989 	634:  uint32(826),
  26990 	635:  uint32(825),
  26991 	636:  uint32(824),
  26992 	637:  uint32(823),
  26993 	638:  uint32(821),
  26994 	639:  uint32(820),
  26995 	640:  uint32(819),
  26996 	641:  uint32(817),
  26997 	642:  uint32(816),
  26998 	643:  uint32(815),
  26999 	644:  uint32(814),
  27000 	645:  uint32(812),
  27001 	646:  uint32(811),
  27002 	647:  uint32(810),
  27003 	648:  uint32(809),
  27004 	649:  uint32(807),
  27005 	650:  uint32(806),
  27006 	651:  uint32(805),
  27007 	652:  uint32(804),
  27008 	653:  uint32(802),
  27009 	654:  uint32(801),
  27010 	655:  uint32(800),
  27011 	656:  uint32(799),
  27012 	657:  uint32(798),
  27013 	658:  uint32(796),
  27014 	659:  uint32(795),
  27015 	660:  uint32(794),
  27016 	661:  uint32(793),
  27017 	662:  uint32(791),
  27018 	663:  uint32(790),
  27019 	664:  uint32(789),
  27020 	665:  uint32(788),
  27021 	666:  uint32(787),
  27022 	667:  uint32(786),
  27023 	668:  uint32(784),
  27024 	669:  uint32(783),
  27025 	670:  uint32(782),
  27026 	671:  uint32(781),
  27027 	672:  uint32(780),
  27028 	673:  uint32(779),
  27029 	674:  uint32(777),
  27030 	675:  uint32(776),
  27031 	676:  uint32(775),
  27032 	677:  uint32(774),
  27033 	678:  uint32(773),
  27034 	679:  uint32(772),
  27035 	680:  uint32(771),
  27036 	681:  uint32(769),
  27037 	682:  uint32(768),
  27038 	683:  uint32(767),
  27039 	684:  uint32(766),
  27040 	685:  uint32(765),
  27041 	686:  uint32(764),
  27042 	687:  uint32(763),
  27043 	688:  uint32(762),
  27044 	689:  uint32(760),
  27045 	690:  uint32(759),
  27046 	691:  uint32(758),
  27047 	692:  uint32(757),
  27048 	693:  uint32(756),
  27049 	694:  uint32(755),
  27050 	695:  uint32(754),
  27051 	696:  uint32(753),
  27052 	697:  uint32(752),
  27053 	698:  uint32(751),
  27054 	699:  uint32(750),
  27055 	700:  uint32(748),
  27056 	701:  uint32(747),
  27057 	702:  uint32(746),
  27058 	703:  uint32(745),
  27059 	704:  uint32(744),
  27060 	705:  uint32(743),
  27061 	706:  uint32(742),
  27062 	707:  uint32(741),
  27063 	708:  uint32(740),
  27064 	709:  uint32(739),
  27065 	710:  uint32(738),
  27066 	711:  uint32(737),
  27067 	712:  uint32(736),
  27068 	713:  uint32(735),
  27069 	714:  uint32(734),
  27070 	715:  uint32(733),
  27071 	716:  uint32(732),
  27072 	717:  uint32(731),
  27073 	718:  uint32(730),
  27074 	719:  uint32(729),
  27075 	720:  uint32(728),
  27076 	721:  uint32(727),
  27077 	722:  uint32(726),
  27078 	723:  uint32(725),
  27079 	724:  uint32(724),
  27080 	725:  uint32(723),
  27081 	726:  uint32(722),
  27082 	727:  uint32(721),
  27083 	728:  uint32(720),
  27084 	729:  uint32(719),
  27085 	730:  uint32(718),
  27086 	731:  uint32(717),
  27087 	732:  uint32(716),
  27088 	733:  uint32(715),
  27089 	734:  uint32(714),
  27090 	735:  uint32(713),
  27091 	736:  uint32(712),
  27092 	737:  uint32(711),
  27093 	738:  uint32(710),
  27094 	739:  uint32(709),
  27095 	740:  uint32(708),
  27096 	741:  uint32(707),
  27097 	742:  uint32(706),
  27098 	743:  uint32(705),
  27099 	744:  uint32(704),
  27100 	745:  uint32(703),
  27101 	746:  uint32(702),
  27102 	747:  uint32(701),
  27103 	748:  uint32(700),
  27104 	749:  uint32(699),
  27105 	750:  uint32(699),
  27106 	751:  uint32(698),
  27107 	752:  uint32(697),
  27108 	753:  uint32(696),
  27109 	754:  uint32(695),
  27110 	755:  uint32(694),
  27111 	756:  uint32(693),
  27112 	757:  uint32(692),
  27113 	758:  uint32(691),
  27114 	759:  uint32(690),
  27115 	760:  uint32(689),
  27116 	761:  uint32(688),
  27117 	762:  uint32(688),
  27118 	763:  uint32(687),
  27119 	764:  uint32(686),
  27120 	765:  uint32(685),
  27121 	766:  uint32(684),
  27122 	767:  uint32(683),
  27123 	768:  uint32(682),
  27124 	769:  uint32(681),
  27125 	770:  uint32(680),
  27126 	771:  uint32(680),
  27127 	772:  uint32(679),
  27128 	773:  uint32(678),
  27129 	774:  uint32(677),
  27130 	775:  uint32(676),
  27131 	776:  uint32(675),
  27132 	777:  uint32(674),
  27133 	778:  uint32(673),
  27134 	779:  uint32(673),
  27135 	780:  uint32(672),
  27136 	781:  uint32(671),
  27137 	782:  uint32(670),
  27138 	783:  uint32(669),
  27139 	784:  uint32(668),
  27140 	785:  uint32(667),
  27141 	786:  uint32(667),
  27142 	787:  uint32(666),
  27143 	788:  uint32(665),
  27144 	789:  uint32(664),
  27145 	790:  uint32(663),
  27146 	791:  uint32(662),
  27147 	792:  uint32(661),
  27148 	793:  uint32(661),
  27149 	794:  uint32(660),
  27150 	795:  uint32(659),
  27151 	796:  uint32(658),
  27152 	797:  uint32(657),
  27153 	798:  uint32(657),
  27154 	799:  uint32(656),
  27155 	800:  uint32(655),
  27156 	801:  uint32(654),
  27157 	802:  uint32(653),
  27158 	803:  uint32(652),
  27159 	804:  uint32(652),
  27160 	805:  uint32(651),
  27161 	806:  uint32(650),
  27162 	807:  uint32(649),
  27163 	808:  uint32(648),
  27164 	809:  uint32(648),
  27165 	810:  uint32(647),
  27166 	811:  uint32(646),
  27167 	812:  uint32(645),
  27168 	813:  uint32(644),
  27169 	814:  uint32(644),
  27170 	815:  uint32(643),
  27171 	816:  uint32(642),
  27172 	817:  uint32(641),
  27173 	818:  uint32(640),
  27174 	819:  uint32(640),
  27175 	820:  uint32(639),
  27176 	821:  uint32(638),
  27177 	822:  uint32(637),
  27178 	823:  uint32(637),
  27179 	824:  uint32(636),
  27180 	825:  uint32(635),
  27181 	826:  uint32(634),
  27182 	827:  uint32(633),
  27183 	828:  uint32(633),
  27184 	829:  uint32(632),
  27185 	830:  uint32(631),
  27186 	831:  uint32(630),
  27187 	832:  uint32(630),
  27188 	833:  uint32(629),
  27189 	834:  uint32(628),
  27190 	835:  uint32(627),
  27191 	836:  uint32(627),
  27192 	837:  uint32(626),
  27193 	838:  uint32(625),
  27194 	839:  uint32(624),
  27195 	840:  uint32(624),
  27196 	841:  uint32(623),
  27197 	842:  uint32(622),
  27198 	843:  uint32(621),
  27199 	844:  uint32(621),
  27200 	845:  uint32(620),
  27201 	846:  uint32(619),
  27202 	847:  uint32(618),
  27203 	848:  uint32(618),
  27204 	849:  uint32(617),
  27205 	850:  uint32(616),
  27206 	851:  uint32(616),
  27207 	852:  uint32(615),
  27208 	853:  uint32(614),
  27209 	854:  uint32(613),
  27210 	855:  uint32(613),
  27211 	856:  uint32(612),
  27212 	857:  uint32(611),
  27213 	858:  uint32(611),
  27214 	859:  uint32(610),
  27215 	860:  uint32(609),
  27216 	861:  uint32(608),
  27217 	862:  uint32(608),
  27218 	863:  uint32(607),
  27219 	864:  uint32(606),
  27220 	865:  uint32(606),
  27221 	866:  uint32(605),
  27222 	867:  uint32(604),
  27223 	868:  uint32(604),
  27224 	869:  uint32(603),
  27225 	870:  uint32(602),
  27226 	871:  uint32(601),
  27227 	872:  uint32(601),
  27228 	873:  uint32(600),
  27229 	874:  uint32(599),
  27230 	875:  uint32(599),
  27231 	876:  uint32(598),
  27232 	877:  uint32(597),
  27233 	878:  uint32(597),
  27234 	879:  uint32(596),
  27235 	880:  uint32(595),
  27236 	881:  uint32(595),
  27237 	882:  uint32(594),
  27238 	883:  uint32(593),
  27239 	884:  uint32(593),
  27240 	885:  uint32(592),
  27241 	886:  uint32(591),
  27242 	887:  uint32(591),
  27243 	888:  uint32(590),
  27244 	889:  uint32(589),
  27245 	890:  uint32(589),
  27246 	891:  uint32(588),
  27247 	892:  uint32(587),
  27248 	893:  uint32(587),
  27249 	894:  uint32(586),
  27250 	895:  uint32(585),
  27251 	896:  uint32(585),
  27252 	897:  uint32(584),
  27253 	898:  uint32(583),
  27254 	899:  uint32(583),
  27255 	900:  uint32(582),
  27256 	901:  uint32(581),
  27257 	902:  uint32(581),
  27258 	903:  uint32(580),
  27259 	904:  uint32(579),
  27260 	905:  uint32(579),
  27261 	906:  uint32(578),
  27262 	907:  uint32(578),
  27263 	908:  uint32(577),
  27264 	909:  uint32(576),
  27265 	910:  uint32(576),
  27266 	911:  uint32(575),
  27267 	912:  uint32(574),
  27268 	913:  uint32(574),
  27269 	914:  uint32(573),
  27270 	915:  uint32(572),
  27271 	916:  uint32(572),
  27272 	917:  uint32(571),
  27273 	918:  uint32(571),
  27274 	919:  uint32(570),
  27275 	920:  uint32(569),
  27276 	921:  uint32(569),
  27277 	922:  uint32(568),
  27278 	923:  uint32(568),
  27279 	924:  uint32(567),
  27280 	925:  uint32(566),
  27281 	926:  uint32(566),
  27282 	927:  uint32(565),
  27283 	928:  uint32(564),
  27284 	929:  uint32(564),
  27285 	930:  uint32(563),
  27286 	931:  uint32(563),
  27287 	932:  uint32(562),
  27288 	933:  uint32(561),
  27289 	934:  uint32(561),
  27290 	935:  uint32(560),
  27291 	936:  uint32(560),
  27292 	937:  uint32(559),
  27293 	938:  uint32(558),
  27294 	939:  uint32(558),
  27295 	940:  uint32(557),
  27296 	941:  uint32(557),
  27297 	942:  uint32(556),
  27298 	943:  uint32(555),
  27299 	944:  uint32(555),
  27300 	945:  uint32(554),
  27301 	946:  uint32(554),
  27302 	947:  uint32(553),
  27303 	948:  uint32(553),
  27304 	949:  uint32(552),
  27305 	950:  uint32(551),
  27306 	951:  uint32(551),
  27307 	952:  uint32(550),
  27308 	953:  uint32(550),
  27309 	954:  uint32(549),
  27310 	955:  uint32(548),
  27311 	956:  uint32(548),
  27312 	957:  uint32(547),
  27313 	958:  uint32(547),
  27314 	959:  uint32(546),
  27315 	960:  uint32(546),
  27316 	961:  uint32(545),
  27317 	962:  uint32(544),
  27318 	963:  uint32(544),
  27319 	964:  uint32(543),
  27320 	965:  uint32(543),
  27321 	966:  uint32(542),
  27322 	967:  uint32(542),
  27323 	968:  uint32(541),
  27324 	969:  uint32(541),
  27325 	970:  uint32(540),
  27326 	971:  uint32(539),
  27327 	972:  uint32(539),
  27328 	973:  uint32(538),
  27329 	974:  uint32(538),
  27330 	975:  uint32(537),
  27331 	976:  uint32(537),
  27332 	977:  uint32(536),
  27333 	978:  uint32(536),
  27334 	979:  uint32(535),
  27335 	980:  uint32(534),
  27336 	981:  uint32(534),
  27337 	982:  uint32(533),
  27338 	983:  uint32(533),
  27339 	984:  uint32(532),
  27340 	985:  uint32(532),
  27341 	986:  uint32(531),
  27342 	987:  uint32(531),
  27343 	988:  uint32(530),
  27344 	989:  uint32(530),
  27345 	990:  uint32(529),
  27346 	991:  uint32(529),
  27347 	992:  uint32(528),
  27348 	993:  uint32(527),
  27349 	994:  uint32(527),
  27350 	995:  uint32(526),
  27351 	996:  uint32(526),
  27352 	997:  uint32(525),
  27353 	998:  uint32(525),
  27354 	999:  uint32(524),
  27355 	1000: uint32(524),
  27356 	1001: uint32(523),
  27357 	1002: uint32(523),
  27358 	1003: uint32(522),
  27359 	1004: uint32(522),
  27360 	1005: uint32(521),
  27361 	1006: uint32(521),
  27362 	1007: uint32(520),
  27363 	1008: uint32(520),
  27364 	1009: uint32(519),
  27365 	1010: uint32(519),
  27366 	1011: uint32(518),
  27367 	1012: uint32(518),
  27368 	1013: uint32(517),
  27369 	1014: uint32(517),
  27370 	1015: uint32(516),
  27371 	1016: uint32(516),
  27372 	1017: uint32(515),
  27373 	1018: uint32(515),
  27374 	1019: uint32(514),
  27375 	1020: uint32(514),
  27376 }
  27377 
  27378 // Note that LinearToGamma() expects the values to be premultiplied by 4,
  27379 // so we incorporate this factor 4 inside the DIVIDE_BY_ALPHA macro directly.
  27380 
  27381 func LinearToGammaWeighted(tls *libc.TLS, src uintptr, a_ptr uintptr, total_a uint32_t, step int32, rgb_stride int32) (r int32) {
  27382 	var sum uint32_t
  27383 	_ = sum
  27384 	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))))
  27385 	return LinearToGamma(tls, sum*kInvAlpha[total_a]>>(kAlphaFix-libc.Int32FromInt32(2)), 0)
  27386 }
  27387 
  27388 func ConvertRowToY(tls *libc.TLS, r_ptr uintptr, g_ptr uintptr, b_ptr uintptr, step int32, dst_y uintptr, width int32, rg uintptr) {
  27389 	var i, j int32
  27390 	_, _ = i, j
  27391 	i = 0
  27392 	j = libc.Int32FromInt32(0)
  27393 	for {
  27394 		if !(i < width) {
  27395 			break
  27396 		}
  27397 		**(**uint8_t)(__ccgo_up(dst_y + uintptr(i))) = uint8(RGBToY(tls, int32(**(**uint8_t)(__ccgo_up(r_ptr + uintptr(j)))), int32(**(**uint8_t)(__ccgo_up(g_ptr + uintptr(j)))), int32(**(**uint8_t)(__ccgo_up(b_ptr + uintptr(j)))), rg))
  27398 		goto _1
  27399 	_1:
  27400 		;
  27401 		i = i + int32(1)
  27402 		j = j + step
  27403 	}
  27404 }
  27405 
  27406 func AccumulateRGBA(tls *libc.TLS, r_ptr uintptr, g_ptr uintptr, b_ptr uintptr, a_ptr uintptr, rgb_stride int32, dst uintptr, width int32) {
  27407 	var a, a1 uint32_t
  27408 	var b, b1, g, g1, i, j, r, r1 int32
  27409 	_, _, _, _, _, _, _, _, _, _ = a, a1, b, b1, g, g1, i, j, r, r1
  27410 	// we loop over 2x2 blocks and produce one R/G/B/A value for each.
  27411 	i = 0
  27412 	j = libc.Int32FromInt32(0)
  27413 	for {
  27414 		if !(i < width>>int32(1)) {
  27415 			break
  27416 		}
  27417 		a = uint32(int32(**(**uint8_t)(__ccgo_up(a_ptr + uintptr(j)))) + int32(**(**uint8_t)(__ccgo_up(a_ptr + uintptr(j) + uintptr(rgb_stride)))) + (int32(**(**uint8_t)(__ccgo_up(a_ptr + uintptr(j) + libc.UintptrFromInt32(4)))) + int32(**(**uint8_t)(__ccgo_up(a_ptr + uintptr(j) + libc.UintptrFromInt32(4) + uintptr(rgb_stride))))))
  27418 		if a == uint32(libc.Int32FromInt32(4)*libc.Int32FromInt32(0xff)) || a == uint32(0) {
  27419 			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)
  27420 			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)
  27421 			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)
  27422 		} else {
  27423 			r = LinearToGammaWeighted(tls, r_ptr+uintptr(j), a_ptr+uintptr(j), a, int32(4), rgb_stride)
  27424 			g = LinearToGammaWeighted(tls, g_ptr+uintptr(j), a_ptr+uintptr(j), a, int32(4), rgb_stride)
  27425 			b = LinearToGammaWeighted(tls, b_ptr+uintptr(j), a_ptr+uintptr(j), a, int32(4), rgb_stride)
  27426 		}
  27427 		**(**uint16_t)(__ccgo_up(dst)) = uint16(r)
  27428 		**(**uint16_t)(__ccgo_up(dst + 1*2)) = uint16(g)
  27429 		**(**uint16_t)(__ccgo_up(dst + 2*2)) = uint16(b)
  27430 		**(**uint16_t)(__ccgo_up(dst + 3*2)) = uint16(a)
  27431 		goto _1
  27432 	_1:
  27433 		;
  27434 		i = i + int32(1)
  27435 		j = j + libc.Int32FromInt32(2)*libc.Int32FromInt32(4)
  27436 		dst = dst + uintptr(4)*2
  27437 	}
  27438 	if width&int32(1) != 0 {
  27439 		a1 = uint32(2) * uint32(int32(**(**uint8_t)(__ccgo_up(a_ptr + uintptr(j))))+int32(**(**uint8_t)(__ccgo_up(a_ptr + uintptr(j) + uintptr(rgb_stride)))))
  27440 		if a1 == uint32(libc.Int32FromInt32(4)*libc.Int32FromInt32(0xff)) || a1 == uint32(0) {
  27441 			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))
  27442 			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))
  27443 			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))
  27444 		} else {
  27445 			r1 = LinearToGammaWeighted(tls, r_ptr+uintptr(j), a_ptr+uintptr(j), a1, 0, rgb_stride)
  27446 			g1 = LinearToGammaWeighted(tls, g_ptr+uintptr(j), a_ptr+uintptr(j), a1, 0, rgb_stride)
  27447 			b1 = LinearToGammaWeighted(tls, b_ptr+uintptr(j), a_ptr+uintptr(j), a1, 0, rgb_stride)
  27448 		}
  27449 		**(**uint16_t)(__ccgo_up(dst)) = uint16(r1)
  27450 		**(**uint16_t)(__ccgo_up(dst + 1*2)) = uint16(g1)
  27451 		**(**uint16_t)(__ccgo_up(dst + 2*2)) = uint16(b1)
  27452 		**(**uint16_t)(__ccgo_up(dst + 3*2)) = uint16(a1)
  27453 	}
  27454 }
  27455 
  27456 func AccumulateRGB(tls *libc.TLS, r_ptr uintptr, g_ptr uintptr, b_ptr uintptr, step int32, rgb_stride int32, dst uintptr, width int32) {
  27457 	var i, j int32
  27458 	_, _ = i, j
  27459 	i = 0
  27460 	j = libc.Int32FromInt32(0)
  27461 	for {
  27462 		if !(i < width>>int32(1)) {
  27463 			break
  27464 		}
  27465 		**(**uint16_t)(__ccgo_up(dst)) = uint16(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))
  27466 		**(**uint16_t)(__ccgo_up(dst + 1*2)) = uint16(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))
  27467 		**(**uint16_t)(__ccgo_up(dst + 2*2)) = uint16(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))
  27468 		// MemorySanitizer may raise false positives with data that passes through
  27469 		// RGBA32PackedToPlanar_16b_SSE41() due to incorrect modeling of shuffles.
  27470 		// See https://crbug.com/webp/573.
  27471 		goto _1
  27472 	_1:
  27473 		;
  27474 		i = i + int32(1)
  27475 		j = j + int32(2)*step
  27476 		dst = dst + uintptr(4)*2
  27477 	}
  27478 	if width&int32(1) != 0 {
  27479 		**(**uint16_t)(__ccgo_up(dst)) = uint16(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)))
  27480 		**(**uint16_t)(__ccgo_up(dst + 1*2)) = uint16(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)))
  27481 		**(**uint16_t)(__ccgo_up(dst + 2*2)) = uint16(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)))
  27482 	}
  27483 }
  27484 
  27485 func ConvertRowsToUV(tls *libc.TLS, rgb uintptr, dst_u uintptr, dst_v uintptr, width int32, rg uintptr) {
  27486 	var b, g, i, r int32
  27487 	_, _, _, _ = b, g, i, r
  27488 	i = 0
  27489 	for {
  27490 		if !(i < width) {
  27491 			break
  27492 		}
  27493 		r = int32(**(**uint16_t)(__ccgo_up(rgb)))
  27494 		g = int32(**(**uint16_t)(__ccgo_up(rgb + 1*2)))
  27495 		b = int32(**(**uint16_t)(__ccgo_up(rgb + 2*2)))
  27496 		**(**uint8_t)(__ccgo_up(dst_u + uintptr(i))) = uint8(RGBToU(tls, r, g, b, rg))
  27497 		**(**uint8_t)(__ccgo_up(dst_v + uintptr(i))) = uint8(RGBToV(tls, r, g, b, rg))
  27498 		goto _1
  27499 	_1:
  27500 		;
  27501 		i = i + int32(1)
  27502 		rgb = rgb + uintptr(4)*2
  27503 	}
  27504 }
  27505 
  27506 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) {
  27507 	bp := tls.Alloc(240)
  27508 	defer tls.Free(240)
  27509 	var dst_a, dst_u, dst_v, dst_y, rg, tmp_rgb uintptr
  27510 	var has_alpha, height, is_rgb, row_has_alpha, rows_have_alpha, use_dsp, uv_width, width, y, v1 int32
  27511 	var _ /* base_rg at bp+0 */ VP8Random
  27512 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  27513 	width = (*WebPPicture)(unsafe.Pointer(picture)).Fwidth
  27514 	height = (*WebPPicture)(unsafe.Pointer(picture)).Fheight
  27515 	has_alpha = CheckNonOpaque(tls, a_ptr, width, height, step, rgb_stride)
  27516 	is_rgb = libc.BoolInt32(r_ptr < b_ptr) // otherwise it's bgr
  27517 	if has_alpha != 0 {
  27518 		v1 = int32(WEBP_YUV420A)
  27519 	} else {
  27520 		v1 = int32(WEBP_YUV420)
  27521 	}
  27522 	(*WebPPicture)(unsafe.Pointer(picture)).Fcolorspace = v1
  27523 	(*WebPPicture)(unsafe.Pointer(picture)).Fuse_argb = 0
  27524 	// disable smart conversion if source is too small (overkill).
  27525 	if width < kMinDimensionIterativeConversion || height < kMinDimensionIterativeConversion {
  27526 		use_iterative_conversion = 0
  27527 	}
  27528 	if !(WebPPictureAllocYUVA(tls, picture) != 0) {
  27529 		return 0
  27530 	}
  27531 	if has_alpha != 0 {
  27532 	}
  27533 	if use_iterative_conversion != 0 {
  27534 		SharpYuvInit(tls, VP8GetCPUInfo)
  27535 		if !(PreprocessARGB(tls, r_ptr, g_ptr, b_ptr, step, rgb_stride, picture) != 0) {
  27536 			return 0
  27537 		}
  27538 		if has_alpha != 0 {
  27539 			(*(*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)
  27540 		}
  27541 	} else {
  27542 		uv_width = (width + int32(1)) >> int32(1)
  27543 		use_dsp = libc.BoolInt32(step == int32(3)) // use special function in this case
  27544 		// temporary storage for accumulated R/G/B values during conversion to U/V
  27545 		tmp_rgb = WebPSafeMalloc(tls, uint64(int32(4)*uv_width), uint64(2))
  27546 		dst_y = (*WebPPicture)(unsafe.Pointer(picture)).Fy
  27547 		dst_u = (*WebPPicture)(unsafe.Pointer(picture)).Fu
  27548 		dst_v = (*WebPPicture)(unsafe.Pointer(picture)).Fv
  27549 		dst_a = (*WebPPicture)(unsafe.Pointer(picture)).Fa
  27550 		rg = libc.UintptrFromInt32(0)
  27551 		if float64(dithering) > float64(0) {
  27552 			VP8InitRandom(tls, bp, dithering)
  27553 			rg = bp
  27554 			use_dsp = 0 // can't use dsp in this case
  27555 		}
  27556 		WebPInitConvertARGBToYUV(tls)
  27557 		InitGammaTables(tls)
  27558 		if tmp_rgb == libc.UintptrFromInt32(0) {
  27559 			return WebPEncodingSetError(tls, picture, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  27560 		}
  27561 		// Downsample Y/U/V planes, two rows at a time
  27562 		y = 0
  27563 		for {
  27564 			if !(y < height>>libc.Int32FromInt32(1)) {
  27565 				break
  27566 			}
  27567 			rows_have_alpha = has_alpha
  27568 			if use_dsp != 0 {
  27569 				if is_rgb != 0 {
  27570 					(*(*func(*libc.TLS, uintptr, uintptr, int32))(unsafe.Pointer(&struct{ uintptr }{WebPConvertRGB24ToY})))(tls, r_ptr, dst_y, width)
  27571 					(*(*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)
  27572 				} else {
  27573 					(*(*func(*libc.TLS, uintptr, uintptr, int32))(unsafe.Pointer(&struct{ uintptr }{WebPConvertBGR24ToY})))(tls, b_ptr, dst_y, width)
  27574 					(*(*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)
  27575 				}
  27576 			} else {
  27577 				ConvertRowToY(tls, r_ptr, g_ptr, b_ptr, step, dst_y, width, rg)
  27578 				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)
  27579 			}
  27580 			dst_y = dst_y + uintptr(int32(2)*(*WebPPicture)(unsafe.Pointer(picture)).Fy_stride)
  27581 			if has_alpha != 0 {
  27582 				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))
  27583 				dst_a = dst_a + uintptr(int32(2)*(*WebPPicture)(unsafe.Pointer(picture)).Fa_stride)
  27584 			}
  27585 			// Collect averaged R/G/B(/A)
  27586 			if !(rows_have_alpha != 0) {
  27587 				AccumulateRGB(tls, r_ptr, g_ptr, b_ptr, step, rgb_stride, tmp_rgb, width)
  27588 			} else {
  27589 				AccumulateRGBA(tls, r_ptr, g_ptr, b_ptr, a_ptr, rgb_stride, tmp_rgb, width)
  27590 			}
  27591 			// Convert to U/V
  27592 			if rg == libc.UintptrFromInt32(0) {
  27593 				(*(*func(*libc.TLS, uintptr, uintptr, uintptr, int32))(unsafe.Pointer(&struct{ uintptr }{WebPConvertRGBA32ToUV})))(tls, tmp_rgb, dst_u, dst_v, uv_width)
  27594 			} else {
  27595 				ConvertRowsToUV(tls, tmp_rgb, dst_u, dst_v, uv_width, rg)
  27596 			}
  27597 			dst_u = dst_u + uintptr((*WebPPicture)(unsafe.Pointer(picture)).Fuv_stride)
  27598 			dst_v = dst_v + uintptr((*WebPPicture)(unsafe.Pointer(picture)).Fuv_stride)
  27599 			r_ptr = r_ptr + uintptr(int32(2)*rgb_stride)
  27600 			b_ptr = b_ptr + uintptr(int32(2)*rgb_stride)
  27601 			g_ptr = g_ptr + uintptr(int32(2)*rgb_stride)
  27602 			if has_alpha != 0 {
  27603 				a_ptr = a_ptr + uintptr(int32(2)*rgb_stride)
  27604 			}
  27605 			goto _2
  27606 		_2:
  27607 			;
  27608 			y = y + 1
  27609 		}
  27610 		if height&int32(1) != 0 { // extra last row
  27611 			row_has_alpha = has_alpha
  27612 			if use_dsp != 0 {
  27613 				if r_ptr < b_ptr {
  27614 					(*(*func(*libc.TLS, uintptr, uintptr, int32))(unsafe.Pointer(&struct{ uintptr }{WebPConvertRGB24ToY})))(tls, r_ptr, dst_y, width)
  27615 				} else {
  27616 					(*(*func(*libc.TLS, uintptr, uintptr, int32))(unsafe.Pointer(&struct{ uintptr }{WebPConvertBGR24ToY})))(tls, b_ptr, dst_y, width)
  27617 				}
  27618 			} else {
  27619 				ConvertRowToY(tls, r_ptr, g_ptr, b_ptr, step, dst_y, width, rg)
  27620 			}
  27621 			if row_has_alpha != 0 {
  27622 				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))
  27623 			}
  27624 			// Collect averaged R/G/B(/A)
  27625 			if !(row_has_alpha != 0) {
  27626 				// Collect averaged R/G/B
  27627 				AccumulateRGB(tls, r_ptr, g_ptr, b_ptr, step, 0, tmp_rgb, width)
  27628 			} else {
  27629 				AccumulateRGBA(tls, r_ptr, g_ptr, b_ptr, a_ptr, 0, tmp_rgb, width)
  27630 			}
  27631 			if rg == libc.UintptrFromInt32(0) {
  27632 				(*(*func(*libc.TLS, uintptr, uintptr, uintptr, int32))(unsafe.Pointer(&struct{ uintptr }{WebPConvertRGBA32ToUV})))(tls, tmp_rgb, dst_u, dst_v, uv_width)
  27633 			} else {
  27634 				ConvertRowsToUV(tls, tmp_rgb, dst_u, dst_v, uv_width, rg)
  27635 			}
  27636 		}
  27637 		WebPSafeFree(tls, tmp_rgb)
  27638 	}
  27639 	return int32(1)
  27640 }
  27641 
  27642 //------------------------------------------------------------------------------
  27643 // call for ARGB->YUVA conversion
  27644 
  27645 func PictureARGBToYUVA(tls *libc.TLS, picture uintptr, colorspace WebPEncCSP1, dithering float32, use_iterative_conversion int32) (r1 int32) {
  27646 	var a, argb, b, g, r uintptr
  27647 	_, _, _, _, _ = a, argb, b, g, r
  27648 	if picture == libc.UintptrFromInt32(0) {
  27649 		return 0
  27650 	}
  27651 	if (*WebPPicture)(unsafe.Pointer(picture)).Fargb == libc.UintptrFromInt32(0) {
  27652 		return WebPEncodingSetError(tls, picture, int32(VP8_ENC_ERROR_NULL_PARAMETER))
  27653 	} else {
  27654 		if colorspace&int32(WEBP_CSP_UV_MASK) != int32(WEBP_YUV420) {
  27655 			return WebPEncodingSetError(tls, picture, int32(VP8_ENC_ERROR_INVALID_CONFIGURATION))
  27656 		} else {
  27657 			argb = (*WebPPicture)(unsafe.Pointer(picture)).Fargb
  27658 			a = argb + uintptr(libc.Int32FromInt32(3)-libc.Int32FromInt32(0))
  27659 			r = argb + uintptr(libc.Int32FromInt32(3)-libc.Int32FromInt32(1))
  27660 			g = argb + uintptr(libc.Int32FromInt32(3)-libc.Int32FromInt32(2))
  27661 			b = argb + uintptr(libc.Int32FromInt32(3)-libc.Int32FromInt32(3))
  27662 			(*WebPPicture)(unsafe.Pointer(picture)).Fcolorspace = int32(WEBP_YUV420)
  27663 			return ImportYUVAFromRGBA(tls, r, g, b, a, int32(4), int32(4)*(*WebPPicture)(unsafe.Pointer(picture)).Fargb_stride, dithering, use_iterative_conversion, picture)
  27664 		}
  27665 	}
  27666 	return r1
  27667 }
  27668 
  27669 func WebPPictureARGBToYUVADithered(tls *libc.TLS, picture uintptr, colorspace WebPEncCSP1, dithering float32) (r int32) {
  27670 	return PictureARGBToYUVA(tls, picture, colorspace, dithering, 0)
  27671 }
  27672 
  27673 func WebPPictureARGBToYUVA(tls *libc.TLS, picture uintptr, colorspace WebPEncCSP1) (r int32) {
  27674 	return PictureARGBToYUVA(tls, picture, colorspace, libc.Float32FromFloat32(0), 0)
  27675 }
  27676 
  27677 func WebPPictureSharpARGBToYUVA(tls *libc.TLS, picture uintptr) (r int32) {
  27678 	return PictureARGBToYUVA(tls, picture, int32(WEBP_YUV420), libc.Float32FromFloat32(0), int32(1))
  27679 }
  27680 
  27681 // C documentation
  27682 //
  27683 //	// for backward compatibility
  27684 func WebPPictureSmartARGBToYUVA(tls *libc.TLS, picture uintptr) (r int32) {
  27685 	return WebPPictureSharpARGBToYUVA(tls, picture)
  27686 }
  27687 
  27688 //------------------------------------------------------------------------------
  27689 // call for YUVA -> ARGB conversion
  27690 
  27691 func WebPPictureYUVAToARGB(tls *libc.TLS, picture uintptr) (r int32) {
  27692 	var argb_dst, cur_u, cur_v, cur_y, dst, src, top_u, top_v uintptr
  27693 	var argb_stride, height, width, x, y int32
  27694 	var upsample WebPUpsampleLinePairFunc
  27695 	_, _, _, _, _, _, _, _, _, _, _, _, _, _ = argb_dst, argb_stride, cur_u, cur_v, cur_y, dst, height, src, top_u, top_v, upsample, width, x, y
  27696 	if picture == libc.UintptrFromInt32(0) {
  27697 		return 0
  27698 	}
  27699 	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) {
  27700 		return WebPEncodingSetError(tls, picture, int32(VP8_ENC_ERROR_NULL_PARAMETER))
  27701 	}
  27702 	if (*WebPPicture)(unsafe.Pointer(picture)).Fcolorspace&int32(WEBP_CSP_ALPHA_BIT) != 0 && (*WebPPicture)(unsafe.Pointer(picture)).Fa == libc.UintptrFromInt32(0) {
  27703 		return WebPEncodingSetError(tls, picture, int32(VP8_ENC_ERROR_NULL_PARAMETER))
  27704 	}
  27705 	if (*WebPPicture)(unsafe.Pointer(picture)).Fcolorspace&int32(WEBP_CSP_UV_MASK) != int32(WEBP_YUV420) {
  27706 		return WebPEncodingSetError(tls, picture, int32(VP8_ENC_ERROR_INVALID_CONFIGURATION))
  27707 	}
  27708 	// Allocate a new argb buffer (discarding the previous one).
  27709 	if !(WebPPictureAllocARGB(tls, picture) != 0) {
  27710 		return 0
  27711 	}
  27712 	(*WebPPicture)(unsafe.Pointer(picture)).Fuse_argb = int32(1)
  27713 	// Convert
  27714 	width = (*WebPPicture)(unsafe.Pointer(picture)).Fwidth
  27715 	height = (*WebPPicture)(unsafe.Pointer(picture)).Fheight
  27716 	argb_stride = int32(4) * (*WebPPicture)(unsafe.Pointer(picture)).Fargb_stride
  27717 	dst = (*WebPPicture)(unsafe.Pointer(picture)).Fargb
  27718 	cur_u = (*WebPPicture)(unsafe.Pointer(picture)).Fu
  27719 	cur_v = (*WebPPicture)(unsafe.Pointer(picture)).Fv
  27720 	cur_y = (*WebPPicture)(unsafe.Pointer(picture)).Fy
  27721 	upsample = WebPGetLinePairConverter(tls, libc.BoolInt32(libc.Int32FromInt32(3)-libc.Int32FromInt32(0) > 0))
  27722 	// First row, with replicated top samples.
  27723 	(*(*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)
  27724 	cur_y = cur_y + uintptr((*WebPPicture)(unsafe.Pointer(picture)).Fy_stride)
  27725 	dst = dst + uintptr(argb_stride)
  27726 	// Center rows.
  27727 	y = int32(1)
  27728 	for {
  27729 		if !(y+int32(1) < height) {
  27730 			break
  27731 		}
  27732 		top_u = cur_u
  27733 		top_v = cur_v
  27734 		cur_u = cur_u + uintptr((*WebPPicture)(unsafe.Pointer(picture)).Fuv_stride)
  27735 		cur_v = cur_v + uintptr((*WebPPicture)(unsafe.Pointer(picture)).Fuv_stride)
  27736 		(*(*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)
  27737 		cur_y = cur_y + uintptr(int32(2)*(*WebPPicture)(unsafe.Pointer(picture)).Fy_stride)
  27738 		dst = dst + uintptr(int32(2)*argb_stride)
  27739 		goto _1
  27740 	_1:
  27741 		;
  27742 		y = y + int32(2)
  27743 	}
  27744 	// Last row (if needed), with replicated bottom samples.
  27745 	if height > int32(1) && !(height&libc.Int32FromInt32(1) != 0) {
  27746 		(*(*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)
  27747 	}
  27748 	// Insert alpha values if needed, in replacement for the default 0xff ones.
  27749 	if (*WebPPicture)(unsafe.Pointer(picture)).Fcolorspace&int32(WEBP_CSP_ALPHA_BIT) != 0 {
  27750 		y = 0
  27751 		for {
  27752 			if !(y < height) {
  27753 				break
  27754 			}
  27755 			argb_dst = (*WebPPicture)(unsafe.Pointer(picture)).Fargb + uintptr(y*(*WebPPicture)(unsafe.Pointer(picture)).Fargb_stride)*4
  27756 			src = (*WebPPicture)(unsafe.Pointer(picture)).Fa + uintptr(y*(*WebPPicture)(unsafe.Pointer(picture)).Fa_stride)
  27757 			x = 0
  27758 			for {
  27759 				if !(x < width) {
  27760 					break
  27761 				}
  27762 				**(**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)
  27763 				goto _3
  27764 			_3:
  27765 				;
  27766 				x = x + 1
  27767 			}
  27768 			goto _2
  27769 		_2:
  27770 			;
  27771 			y = y + 1
  27772 		}
  27773 	}
  27774 	return int32(1)
  27775 }
  27776 
  27777 //------------------------------------------------------------------------------
  27778 // automatic import / conversion
  27779 
  27780 func Import(tls *libc.TLS, picture uintptr, rgb uintptr, rgb_stride int32, step int32, swap_rb int32, import_alpha int32) (r int32) {
  27781 	var a_ptr, b_ptr, dst, dst1, g_ptr, r_ptr, v4 uintptr
  27782 	var do_copy, height, width, y, v1, v2, v3 int32
  27783 	_, _, _, _, _, _, _, _, _, _, _, _, _, _ = a_ptr, b_ptr, do_copy, dst, dst1, g_ptr, height, r_ptr, width, y, v1, v2, v3, v4
  27784 	if swap_rb != 0 {
  27785 		v1 = int32(2)
  27786 	} else {
  27787 		v1 = 0
  27788 	}
  27789 	// swap_rb -> b,g,r,a , !swap_rb -> r,g,b,a
  27790 	r_ptr = rgb + uintptr(v1)
  27791 	g_ptr = rgb + uintptr(1)
  27792 	if swap_rb != 0 {
  27793 		v2 = 0
  27794 	} else {
  27795 		v2 = int32(2)
  27796 	}
  27797 	b_ptr = rgb + uintptr(v2)
  27798 	width = (*WebPPicture)(unsafe.Pointer(picture)).Fwidth
  27799 	height = (*WebPPicture)(unsafe.Pointer(picture)).Fheight
  27800 	if import_alpha != 0 {
  27801 		v3 = int32(4)
  27802 	} else {
  27803 		v3 = int32(3)
  27804 	}
  27805 	if libc.Xabs(tls, rgb_stride) < v3*width {
  27806 		return 0
  27807 	}
  27808 	if !((*WebPPicture)(unsafe.Pointer(picture)).Fuse_argb != 0) {
  27809 		if import_alpha != 0 {
  27810 			v4 = rgb + uintptr(3)
  27811 		} else {
  27812 			v4 = libc.UintptrFromInt32(0)
  27813 		}
  27814 		a_ptr = v4
  27815 		return ImportYUVAFromRGBA(tls, r_ptr, g_ptr, b_ptr, a_ptr, step, rgb_stride, libc.Float32FromFloat32(0), 0, picture)
  27816 	}
  27817 	if !(WebPPictureAlloc(tls, picture) != 0) {
  27818 		return 0
  27819 	}
  27820 	VP8LDspInit(tls)
  27821 	WebPInitAlphaProcessing(tls)
  27822 	if import_alpha != 0 {
  27823 		// dst[] byte order is {a,r,g,b} for big-endian, {b,g,r,a} for little endian
  27824 		dst = (*WebPPicture)(unsafe.Pointer(picture)).Fargb
  27825 		do_copy = libc.BoolInt32(libc.Bool(libc.Int32FromInt32(3)-libc.Int32FromInt32(0) == int32(3)) && swap_rb != 0)
  27826 		if do_copy != 0 {
  27827 			y = 0
  27828 			for {
  27829 				if !(y < height) {
  27830 					break
  27831 				}
  27832 				libc.Xmemcpy(tls, dst, rgb, uint64(width*int32(4)))
  27833 				rgb = rgb + uintptr(rgb_stride)
  27834 				dst = dst + uintptr((*WebPPicture)(unsafe.Pointer(picture)).Fargb_stride)*4
  27835 				goto _5
  27836 			_5:
  27837 				;
  27838 				y = y + 1
  27839 			}
  27840 		} else {
  27841 			y = 0
  27842 			for {
  27843 				if !(y < height) {
  27844 					break
  27845 				}
  27846 				// RGBA input order. Need to swap R and B.
  27847 				(*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8LConvertBGRAToRGBA})))(tls, rgb, width, dst)
  27848 				rgb = rgb + uintptr(rgb_stride)
  27849 				dst = dst + uintptr((*WebPPicture)(unsafe.Pointer(picture)).Fargb_stride)*4
  27850 				goto _6
  27851 			_6:
  27852 				;
  27853 				y = y + 1
  27854 			}
  27855 		}
  27856 	} else {
  27857 		dst1 = (*WebPPicture)(unsafe.Pointer(picture)).Fargb
  27858 		y = 0
  27859 		for {
  27860 			if !(y < height) {
  27861 				break
  27862 			}
  27863 			(*(*func(*libc.TLS, uintptr, uintptr, uintptr, int32, int32, uintptr))(unsafe.Pointer(&struct{ uintptr }{WebPPackRGB})))(tls, r_ptr, g_ptr, b_ptr, width, step, dst1)
  27864 			r_ptr = r_ptr + uintptr(rgb_stride)
  27865 			g_ptr = g_ptr + uintptr(rgb_stride)
  27866 			b_ptr = b_ptr + uintptr(rgb_stride)
  27867 			dst1 = dst1 + uintptr((*WebPPicture)(unsafe.Pointer(picture)).Fargb_stride)*4
  27868 			goto _7
  27869 		_7:
  27870 			;
  27871 			y = y + 1
  27872 		}
  27873 	}
  27874 	return int32(1)
  27875 }
  27876 
  27877 // Public API
  27878 
  27879 func WebPPictureImportBGR(tls *libc.TLS, picture uintptr, bgr uintptr, bgr_stride int32) (r int32) {
  27880 	var v1 int32
  27881 	_ = v1
  27882 	if picture != libc.UintptrFromInt32(0) && bgr != libc.UintptrFromInt32(0) {
  27883 		v1 = Import(tls, picture, bgr, bgr_stride, int32(3), int32(1), 0)
  27884 	} else {
  27885 		v1 = 0
  27886 	}
  27887 	return v1
  27888 }
  27889 
  27890 func WebPPictureImportBGRA(tls *libc.TLS, picture uintptr, bgra uintptr, bgra_stride int32) (r int32) {
  27891 	var v1 int32
  27892 	_ = v1
  27893 	if picture != libc.UintptrFromInt32(0) && bgra != libc.UintptrFromInt32(0) {
  27894 		v1 = Import(tls, picture, bgra, bgra_stride, int32(4), int32(1), int32(1))
  27895 	} else {
  27896 		v1 = 0
  27897 	}
  27898 	return v1
  27899 }
  27900 
  27901 func WebPPictureImportBGRX(tls *libc.TLS, picture uintptr, bgrx uintptr, bgrx_stride int32) (r int32) {
  27902 	var v1 int32
  27903 	_ = v1
  27904 	if picture != libc.UintptrFromInt32(0) && bgrx != libc.UintptrFromInt32(0) {
  27905 		v1 = Import(tls, picture, bgrx, bgrx_stride, int32(4), int32(1), 0)
  27906 	} else {
  27907 		v1 = 0
  27908 	}
  27909 	return v1
  27910 }
  27911 
  27912 func WebPPictureImportRGB(tls *libc.TLS, picture uintptr, rgb uintptr, rgb_stride int32) (r int32) {
  27913 	var v1 int32
  27914 	_ = v1
  27915 	if picture != libc.UintptrFromInt32(0) && rgb != libc.UintptrFromInt32(0) {
  27916 		v1 = Import(tls, picture, rgb, rgb_stride, int32(3), 0, 0)
  27917 	} else {
  27918 		v1 = 0
  27919 	}
  27920 	return v1
  27921 }
  27922 
  27923 func WebPPictureImportRGBA(tls *libc.TLS, picture uintptr, rgba uintptr, rgba_stride int32) (r int32) {
  27924 	var v1 int32
  27925 	_ = v1
  27926 	if picture != libc.UintptrFromInt32(0) && rgba != libc.UintptrFromInt32(0) {
  27927 		v1 = Import(tls, picture, rgba, rgba_stride, int32(4), 0, int32(1))
  27928 	} else {
  27929 		v1 = 0
  27930 	}
  27931 	return v1
  27932 }
  27933 
  27934 func WebPPictureImportRGBX(tls *libc.TLS, picture uintptr, rgbx uintptr, rgbx_stride int32) (r int32) {
  27935 	var v1 int32
  27936 	_ = v1
  27937 	if picture != libc.UintptrFromInt32(0) && rgbx != libc.UintptrFromInt32(0) {
  27938 		v1 = Import(tls, picture, rgbx, rgbx_stride, int32(4), 0, 0)
  27939 	} else {
  27940 		v1 = 0
  27941 	}
  27942 	return v1
  27943 }
  27944 
  27945 const LOSSLESS_DEFAULT_QUALITY = 70
  27946 const __INT_MAX__1 = 2147483647
  27947 
  27948 //------------------------------------------------------------------------------
  27949 
  27950 // Copyright 2012 Google Inc. All Rights Reserved.
  27951 //
  27952 // Use of this source code is governed by a BSD-style license
  27953 // that can be found in the COPYING file in the root of the source
  27954 // tree. An additional intellectual property rights grant can be found
  27955 // in the file PATENTS. All contributing project authors may
  27956 // be found in the AUTHORS file in the root of the source tree.
  27957 // -----------------------------------------------------------------------------
  27958 //
  27959 // Misc. common utility functions
  27960 //
  27961 // Authors: Skal (pascal.massimino@gmail.com)
  27962 //          Urvang (urvang@google.com)
  27963 
  27964 // Copyright 2011 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 //   WebP encoder: main interface
  27974 //
  27975 // Author: Skal (pascal.massimino@gmail.com)
  27976 
  27977 // Copyright 2010 Google Inc. All Rights Reserved.
  27978 //
  27979 // Use of this source code is governed by a BSD-style license
  27980 // that can be found in the COPYING file in the root of the source
  27981 // tree. An additional intellectual property rights grant can be found
  27982 // in the file PATENTS. All contributing project authors may
  27983 // be found in the AUTHORS file in the root of the source tree.
  27984 // -----------------------------------------------------------------------------
  27985 //
  27986 //  Common types + memory wrappers
  27987 //
  27988 // Author: Skal (pascal.massimino@gmail.com)
  27989 
  27990 //------------------------------------------------------------------------------
  27991 // WebPPicture
  27992 //------------------------------------------------------------------------------
  27993 
  27994 func DummyWriter(tls *libc.TLS, data uintptr, data_size size_t, picture uintptr) (r int32) {
  27995 	// The following are to prevent 'unused variable' error message.
  27996 	_ = data
  27997 	_ = data_size
  27998 	_ = picture
  27999 	return int32(1)
  28000 }
  28001 
  28002 func WebPPictureInitInternal(tls *libc.TLS, picture uintptr, version int32) (r int32) {
  28003 	if version>>int32(8) != libc.Int32FromInt32(WEBP_ENCODER_ABI_VERSION)>>libc.Int32FromInt32(8) {
  28004 		return 0 // caller/system version mismatch!
  28005 	}
  28006 	if picture != libc.UintptrFromInt32(0) {
  28007 		libc.Xmemset(tls, picture, 0, uint64(256))
  28008 		(*WebPPicture)(unsafe.Pointer(picture)).Fwriter = __ccgo_fp(DummyWriter)
  28009 		WebPEncodingSetError(tls, picture, int32(VP8_ENC_OK))
  28010 	}
  28011 	return int32(1)
  28012 }
  28013 
  28014 //------------------------------------------------------------------------------
  28015 
  28016 func WebPValidatePicture(tls *libc.TLS, picture uintptr) (r int32) {
  28017 	if picture == libc.UintptrFromInt32(0) {
  28018 		return 0
  28019 	}
  28020 	if (*WebPPicture)(unsafe.Pointer(picture)).Fwidth <= 0 || (*WebPPicture)(unsafe.Pointer(picture)).Fheight <= 0 {
  28021 		return WebPEncodingSetError(tls, picture, int32(VP8_ENC_ERROR_BAD_DIMENSION))
  28022 	}
  28023 	if (*WebPPicture)(unsafe.Pointer(picture)).Fwidth <= 0 || (*WebPPicture)(unsafe.Pointer(picture)).Fwidth/int32(4) > libc.Int32FromInt32(__INT_MAX__1)/libc.Int32FromInt32(4) || (*WebPPicture)(unsafe.Pointer(picture)).Fheight <= 0 || (*WebPPicture)(unsafe.Pointer(picture)).Fheight/int32(4) > libc.Int32FromInt32(__INT_MAX__1)/libc.Int32FromInt32(4) {
  28024 		return WebPEncodingSetError(tls, picture, int32(VP8_ENC_ERROR_BAD_DIMENSION))
  28025 	}
  28026 	if (*WebPPicture)(unsafe.Pointer(picture)).Fcolorspace != int32(WEBP_YUV420) && (*WebPPicture)(unsafe.Pointer(picture)).Fcolorspace != int32(WEBP_YUV420A) {
  28027 		return WebPEncodingSetError(tls, picture, int32(VP8_ENC_ERROR_INVALID_CONFIGURATION))
  28028 	}
  28029 	return int32(1)
  28030 }
  28031 
  28032 func WebPPictureResetBufferARGB(tls *libc.TLS, picture uintptr) {
  28033 	(*WebPPicture)(unsafe.Pointer(picture)).Fmemory_argb_ = libc.UintptrFromInt32(0)
  28034 	(*WebPPicture)(unsafe.Pointer(picture)).Fargb = libc.UintptrFromInt32(0)
  28035 	(*WebPPicture)(unsafe.Pointer(picture)).Fargb_stride = 0
  28036 }
  28037 
  28038 func WebPPictureResetBufferYUVA(tls *libc.TLS, picture uintptr) {
  28039 	var v1, v2, v3 uintptr
  28040 	var v4 int32
  28041 	_, _, _, _ = v1, v2, v3, v4
  28042 	(*WebPPicture)(unsafe.Pointer(picture)).Fmemory_ = libc.UintptrFromInt32(0)
  28043 	v3 = libc.UintptrFromInt32(0)
  28044 	(*WebPPicture)(unsafe.Pointer(picture)).Fa = v3
  28045 	v2 = v3
  28046 	(*WebPPicture)(unsafe.Pointer(picture)).Fv = v2
  28047 	v1 = v2
  28048 	(*WebPPicture)(unsafe.Pointer(picture)).Fu = v1
  28049 	(*WebPPicture)(unsafe.Pointer(picture)).Fy = v1
  28050 	v4 = libc.Int32FromInt32(0)
  28051 	(*WebPPicture)(unsafe.Pointer(picture)).Fuv_stride = v4
  28052 	(*WebPPicture)(unsafe.Pointer(picture)).Fy_stride = v4
  28053 	(*WebPPicture)(unsafe.Pointer(picture)).Fa_stride = 0
  28054 }
  28055 
  28056 func WebPPictureResetBuffers(tls *libc.TLS, picture uintptr) {
  28057 	WebPPictureResetBufferARGB(tls, picture)
  28058 	WebPPictureResetBufferYUVA(tls, picture)
  28059 }
  28060 
  28061 func WebPPictureAllocARGB(tls *libc.TLS, picture uintptr) (r int32) {
  28062 	var argb_size uint64_t
  28063 	var height, width int32
  28064 	var memory uintptr
  28065 	_, _, _, _ = argb_size, height, memory, width
  28066 	width = (*WebPPicture)(unsafe.Pointer(picture)).Fwidth
  28067 	height = (*WebPPicture)(unsafe.Pointer(picture)).Fheight
  28068 	argb_size = uint64(width) * uint64(height)
  28069 	if !(WebPValidatePicture(tls, picture) != 0) {
  28070 		return 0
  28071 	}
  28072 	WebPSafeFree(tls, (*WebPPicture)(unsafe.Pointer(picture)).Fmemory_argb_)
  28073 	WebPPictureResetBufferARGB(tls, picture)
  28074 	// allocate a new buffer.
  28075 	memory = WebPSafeMalloc(tls, argb_size+uint64(WEBP_ALIGN_CST), uint64(4))
  28076 	if memory == libc.UintptrFromInt32(0) {
  28077 		return WebPEncodingSetError(tls, picture, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  28078 	}
  28079 	(*WebPPicture)(unsafe.Pointer(picture)).Fmemory_argb_ = memory
  28080 	(*WebPPicture)(unsafe.Pointer(picture)).Fargb = uintptr((uint64(memory) + libc.Uint64FromInt32(WEBP_ALIGN_CST)) & ^libc.Uint64FromInt32(WEBP_ALIGN_CST))
  28081 	(*WebPPicture)(unsafe.Pointer(picture)).Fargb_stride = width
  28082 	return int32(1)
  28083 }
  28084 
  28085 func WebPPictureAllocYUVA(tls *libc.TLS, picture uintptr) (r int32) {
  28086 	var a_size, total_size, uv_size, y_size uint64_t
  28087 	var a_stride, a_width, has_alpha, height, uv_height, uv_stride, uv_width, width, y_stride, v1 int32
  28088 	var mem uintptr
  28089 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  28090 	has_alpha = (*WebPPicture)(unsafe.Pointer(picture)).Fcolorspace & int32(WEBP_CSP_ALPHA_BIT)
  28091 	width = (*WebPPicture)(unsafe.Pointer(picture)).Fwidth
  28092 	height = (*WebPPicture)(unsafe.Pointer(picture)).Fheight
  28093 	y_stride = width
  28094 	uv_width = int32((int64(width) + libc.Int64FromInt32(1)) >> libc.Int32FromInt32(1))
  28095 	uv_height = int32((int64(height) + libc.Int64FromInt32(1)) >> libc.Int32FromInt32(1))
  28096 	uv_stride = uv_width
  28097 	if !(WebPValidatePicture(tls, picture) != 0) {
  28098 		return 0
  28099 	}
  28100 	WebPSafeFree(tls, (*WebPPicture)(unsafe.Pointer(picture)).Fmemory_)
  28101 	WebPPictureResetBufferYUVA(tls, picture)
  28102 	// alpha
  28103 	if has_alpha != 0 {
  28104 		v1 = width
  28105 	} else {
  28106 		v1 = 0
  28107 	}
  28108 	a_width = v1
  28109 	a_stride = a_width
  28110 	y_size = uint64(y_stride) * uint64(height)
  28111 	uv_size = uint64(uv_stride) * uint64(uv_height)
  28112 	a_size = uint64(a_stride) * uint64(height)
  28113 	total_size = y_size + a_size + uint64(2)*uv_size
  28114 	// Security and validation checks
  28115 	if width <= 0 || height <= 0 || uv_width <= 0 || uv_height <= 0 { // u/v param error
  28116 		return WebPEncodingSetError(tls, picture, int32(VP8_ENC_ERROR_BAD_DIMENSION))
  28117 	}
  28118 	// allocate a new buffer.
  28119 	mem = WebPSafeMalloc(tls, total_size, uint64(1))
  28120 	if mem == libc.UintptrFromInt32(0) {
  28121 		return WebPEncodingSetError(tls, picture, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  28122 	}
  28123 	// From now on, we're in the clear, we can no longer fail...
  28124 	(*WebPPicture)(unsafe.Pointer(picture)).Fmemory_ = mem
  28125 	(*WebPPicture)(unsafe.Pointer(picture)).Fy_stride = y_stride
  28126 	(*WebPPicture)(unsafe.Pointer(picture)).Fuv_stride = uv_stride
  28127 	(*WebPPicture)(unsafe.Pointer(picture)).Fa_stride = a_stride
  28128 	// TODO(skal): we could align the y/u/v planes and adjust stride.
  28129 	(*WebPPicture)(unsafe.Pointer(picture)).Fy = mem
  28130 	mem = mem + uintptr(y_size)
  28131 	(*WebPPicture)(unsafe.Pointer(picture)).Fu = mem
  28132 	mem = mem + uintptr(uv_size)
  28133 	(*WebPPicture)(unsafe.Pointer(picture)).Fv = mem
  28134 	mem = mem + uintptr(uv_size)
  28135 	if a_size > uint64(0) {
  28136 		(*WebPPicture)(unsafe.Pointer(picture)).Fa = mem
  28137 		mem = mem + uintptr(a_size)
  28138 	}
  28139 	_ = mem // makes the static analyzer happy
  28140 	return int32(1)
  28141 }
  28142 
  28143 func WebPPictureAlloc(tls *libc.TLS, picture uintptr) (r int32) {
  28144 	if picture != libc.UintptrFromInt32(0) {
  28145 		WebPPictureFree(tls, picture) // erase previous buffer
  28146 		if !((*WebPPicture)(unsafe.Pointer(picture)).Fuse_argb != 0) {
  28147 			return WebPPictureAllocYUVA(tls, picture)
  28148 		} else {
  28149 			return WebPPictureAllocARGB(tls, picture)
  28150 		}
  28151 	}
  28152 	return int32(1)
  28153 }
  28154 
  28155 func WebPPictureFree(tls *libc.TLS, picture uintptr) {
  28156 	if picture != libc.UintptrFromInt32(0) {
  28157 		WebPSafeFree(tls, (*WebPPicture)(unsafe.Pointer(picture)).Fmemory_)
  28158 		WebPSafeFree(tls, (*WebPPicture)(unsafe.Pointer(picture)).Fmemory_argb_)
  28159 		WebPPictureResetBuffers(tls, picture)
  28160 	}
  28161 }
  28162 
  28163 //------------------------------------------------------------------------------
  28164 // WebPMemoryWriter: Write-to-memory
  28165 
  28166 func WebPMemoryWriterInit(tls *libc.TLS, writer uintptr) {
  28167 	(*WebPMemoryWriter)(unsafe.Pointer(writer)).Fmem = libc.UintptrFromInt32(0)
  28168 	(*WebPMemoryWriter)(unsafe.Pointer(writer)).Fsize = uint64(0)
  28169 	(*WebPMemoryWriter)(unsafe.Pointer(writer)).Fmax_size = uint64(0)
  28170 }
  28171 
  28172 func WebPMemoryWrite(tls *libc.TLS, data uintptr, data_size size_t, picture uintptr) (r int32) {
  28173 	var new_mem, w uintptr
  28174 	var next_max_size, next_size uint64_t
  28175 	_, _, _, _ = new_mem, next_max_size, next_size, w
  28176 	w = (*WebPPicture)(unsafe.Pointer(picture)).Fcustom_ptr
  28177 	if w == libc.UintptrFromInt32(0) {
  28178 		return int32(1)
  28179 	}
  28180 	next_size = (*WebPMemoryWriter)(unsafe.Pointer(w)).Fsize + data_size
  28181 	if next_size > (*WebPMemoryWriter)(unsafe.Pointer(w)).Fmax_size {
  28182 		next_max_size = uint64(2) * (*WebPMemoryWriter)(unsafe.Pointer(w)).Fmax_size
  28183 		if next_max_size < next_size {
  28184 			next_max_size = next_size
  28185 		}
  28186 		if next_max_size < uint64(8192) {
  28187 			next_max_size = uint64(8192)
  28188 		}
  28189 		new_mem = WebPSafeMalloc(tls, next_max_size, uint64(1))
  28190 		if new_mem == libc.UintptrFromInt32(0) {
  28191 			return 0
  28192 		}
  28193 		if (*WebPMemoryWriter)(unsafe.Pointer(w)).Fsize > uint64(0) {
  28194 			libc.Xmemcpy(tls, new_mem, (*WebPMemoryWriter)(unsafe.Pointer(w)).Fmem, (*WebPMemoryWriter)(unsafe.Pointer(w)).Fsize)
  28195 		}
  28196 		WebPSafeFree(tls, (*WebPMemoryWriter)(unsafe.Pointer(w)).Fmem)
  28197 		(*WebPMemoryWriter)(unsafe.Pointer(w)).Fmem = new_mem
  28198 		// down-cast is ok, thanks to WebPSafeMalloc
  28199 		(*WebPMemoryWriter)(unsafe.Pointer(w)).Fmax_size = next_max_size
  28200 	}
  28201 	if data_size > uint64(0) {
  28202 		libc.Xmemcpy(tls, (*WebPMemoryWriter)(unsafe.Pointer(w)).Fmem+uintptr((*WebPMemoryWriter)(unsafe.Pointer(w)).Fsize), data, data_size)
  28203 		**(**size_t)(__ccgo_up(w + 8)) += data_size
  28204 	}
  28205 	return int32(1)
  28206 }
  28207 
  28208 func WebPMemoryWriterClear(tls *libc.TLS, writer uintptr) {
  28209 	if writer != libc.UintptrFromInt32(0) {
  28210 		WebPSafeFree(tls, (*WebPMemoryWriter)(unsafe.Pointer(writer)).Fmem)
  28211 		WebPMemoryWriterInit(tls, writer)
  28212 	}
  28213 }
  28214 
  28215 //------------------------------------------------------------------------------
  28216 // Simplest high-level calls:
  28217 
  28218 type Importer = uintptr
  28219 
  28220 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) {
  28221 	bp := tls.Alloc(416)
  28222 	defer tls.Free(416)
  28223 	var ok, v1, v3 int32
  28224 	var v5 bool
  28225 	var _ /* config at bp+256 */ WebPConfig
  28226 	var _ /* pic at bp+0 */ WebPPicture
  28227 	var _ /* wrt at bp+376 */ WebPMemoryWriter
  28228 	_, _, _, _ = ok, v1, v3, v5
  28229 	if output == libc.UintptrFromInt32(0) {
  28230 		return uint64(0)
  28231 	}
  28232 	v1 = WebPConfigInitInternal(tls, bp+256, int32(WEBP_PRESET_DEFAULT), quality_factor, int32(WEBP_ENCODER_ABI_VERSION))
  28233 	goto _2
  28234 _2:
  28235 	;
  28236 	if v5 = !(v1 != 0); !v5 {
  28237 		v3 = WebPPictureInitInternal(tls, bp, int32(WEBP_ENCODER_ABI_VERSION))
  28238 		goto _4
  28239 	_4:
  28240 	}
  28241 	if v5 || !(v3 != 0) {
  28242 		return uint64(0) // shouldn't happen, except if system installation is broken
  28243 	}
  28244 	(**(**WebPConfig)(__ccgo_up(bp + 256))).Flossless = libc.BoolInt32(!!(lossless != 0))
  28245 	(**(**WebPPicture)(__ccgo_up(bp))).Fuse_argb = libc.BoolInt32(!!(lossless != 0))
  28246 	(**(**WebPPicture)(__ccgo_up(bp))).Fwidth = width
  28247 	(**(**WebPPicture)(__ccgo_up(bp))).Fheight = height
  28248 	(**(**WebPPicture)(__ccgo_up(bp))).Fwriter = __ccgo_fp(WebPMemoryWrite)
  28249 	(**(**WebPPicture)(__ccgo_up(bp))).Fcustom_ptr = bp + 376
  28250 	WebPMemoryWriterInit(tls, bp+376)
  28251 	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)
  28252 	WebPPictureFree(tls, bp)
  28253 	if !(ok != 0) {
  28254 		WebPMemoryWriterClear(tls, bp+376)
  28255 		**(**uintptr)(__ccgo_up(output)) = libc.UintptrFromInt32(0)
  28256 		return uint64(0)
  28257 	}
  28258 	**(**uintptr)(__ccgo_up(output)) = (**(**WebPMemoryWriter)(__ccgo_up(bp + 376))).Fmem
  28259 	return (**(**WebPMemoryWriter)(__ccgo_up(bp + 376))).Fsize
  28260 }
  28261 
  28262 func WebPEncodeRGB(tls *libc.TLS, in uintptr, w int32, h int32, bps int32, q float32, out uintptr) (r size_t) {
  28263 	return Encode(tls, in, w, h, bps, __ccgo_fp(WebPPictureImportRGB), q, 0, out)
  28264 }
  28265 
  28266 func WebPEncodeRGBA(tls *libc.TLS, in uintptr, w int32, h int32, bps int32, q float32, out uintptr) (r size_t) {
  28267 	return Encode(tls, in, w, h, bps, __ccgo_fp(WebPPictureImportRGBA), q, 0, out)
  28268 }
  28269 
  28270 func WebPEncodeBGR(tls *libc.TLS, in uintptr, w int32, h int32, bps int32, q float32, out uintptr) (r size_t) {
  28271 	return Encode(tls, in, w, h, bps, __ccgo_fp(WebPPictureImportBGR), q, 0, out)
  28272 }
  28273 
  28274 func WebPEncodeBGRA(tls *libc.TLS, in uintptr, w int32, h int32, bps int32, q float32, out uintptr) (r size_t) {
  28275 	return Encode(tls, in, w, h, bps, __ccgo_fp(WebPPictureImportBGRA), q, 0, out)
  28276 }
  28277 
  28278 func WebPEncodeLosslessRGB(tls *libc.TLS, in uintptr, w int32, h int32, bps int32, out uintptr) (r size_t) {
  28279 	return Encode(tls, in, w, h, bps, __ccgo_fp(WebPPictureImportRGB), float32(70), int32(1), out)
  28280 }
  28281 
  28282 func WebPEncodeLosslessRGBA(tls *libc.TLS, in uintptr, w int32, h int32, bps int32, out uintptr) (r size_t) {
  28283 	return Encode(tls, in, w, h, bps, __ccgo_fp(WebPPictureImportRGBA), float32(70), int32(1), out)
  28284 }
  28285 
  28286 func WebPEncodeLosslessBGR(tls *libc.TLS, in uintptr, w int32, h int32, bps int32, out uintptr) (r size_t) {
  28287 	return Encode(tls, in, w, h, bps, __ccgo_fp(WebPPictureImportBGR), float32(70), int32(1), out)
  28288 }
  28289 
  28290 func WebPEncodeLosslessBGRA(tls *libc.TLS, in uintptr, w int32, h int32, bps int32, out uintptr) (r size_t) {
  28291 	return Encode(tls, in, w, h, bps, __ccgo_fp(WebPPictureImportBGRA), float32(70), int32(1), out)
  28292 }
  28293 
  28294 const SIZE_MAX11 = "UINT64_MAX"
  28295 const __INT_MAX__2 = 0x7fffffff
  28296 
  28297 //------------------------------------------------------------------------------
  28298 
  28299 // Copyright 2012 Google Inc. All Rights Reserved.
  28300 //
  28301 // Use of this source code is governed by a BSD-style license
  28302 // that can be found in the COPYING file in the root of the source
  28303 // tree. An additional intellectual property rights grant can be found
  28304 // in the file PATENTS. All contributing project authors may
  28305 // be found in the AUTHORS file in the root of the source tree.
  28306 // -----------------------------------------------------------------------------
  28307 //
  28308 // Misc. common utility functions
  28309 //
  28310 // Authors: Skal (pascal.massimino@gmail.com)
  28311 //          Urvang (urvang@google.com)
  28312 
  28313 type AccumulateFunc = uintptr
  28314 
  28315 //------------------------------------------------------------------------------
  28316 // local-min distortion
  28317 //
  28318 // For every pixel in the *reference* picture, we search for the local best
  28319 // match in the compressed image. This is not a symmetrical measure.
  28320 
  28321 func AccumulateLSIM(tls *libc.TLS, src uintptr, src_stride int32, ref uintptr, ref_stride int32, w int32, h int32) (r float64) {
  28322 	var best_sse, diff, sse, total_sse, value float64
  28323 	var i, j, x, x_0, x_1, y, y_0, y_1, v2, v3, v5, v6 int32
  28324 	var s uintptr
  28325 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = best_sse, diff, i, j, s, sse, total_sse, value, x, x_0, x_1, y, y_0, y_1, v2, v3, v5, v6
  28326 	total_sse = float64(0)
  28327 	y = 0
  28328 	for {
  28329 		if !(y < h) {
  28330 			break
  28331 		}
  28332 		if y-int32(2) < 0 {
  28333 			v2 = 0
  28334 		} else {
  28335 			v2 = y - int32(2)
  28336 		}
  28337 		y_0 = v2
  28338 		if y+int32(2)+int32(1) >= h {
  28339 			v3 = h
  28340 		} else {
  28341 			v3 = y + int32(2) + int32(1)
  28342 		}
  28343 		y_1 = v3
  28344 		x = 0
  28345 		for {
  28346 			if !(x < w) {
  28347 				break
  28348 			}
  28349 			if x-int32(2) < 0 {
  28350 				v5 = 0
  28351 			} else {
  28352 				v5 = x - int32(2)
  28353 			}
  28354 			x_0 = v5
  28355 			if x+int32(2)+int32(1) >= w {
  28356 				v6 = w
  28357 			} else {
  28358 				v6 = x + int32(2) + int32(1)
  28359 			}
  28360 			x_1 = v6
  28361 			best_sse = float64(libc.Float64FromFloat64(255) * libc.Float64FromFloat64(255))
  28362 			value = float64(**(**uint8_t)(__ccgo_up(ref + uintptr(y*ref_stride+x))))
  28363 			j = y_0
  28364 			for {
  28365 				if !(j < y_1) {
  28366 					break
  28367 				}
  28368 				s = src + uintptr(j*src_stride)
  28369 				i = x_0
  28370 				for {
  28371 					if !(i < x_1) {
  28372 						break
  28373 					}
  28374 					diff = float64(**(**uint8_t)(__ccgo_up(s + uintptr(i)))) - value
  28375 					sse = float64(diff * diff)
  28376 					if sse < best_sse {
  28377 						best_sse = sse
  28378 					}
  28379 					goto _8
  28380 				_8:
  28381 					;
  28382 					i = i + 1
  28383 				}
  28384 				goto _7
  28385 			_7:
  28386 				;
  28387 				j = j + 1
  28388 			}
  28389 			total_sse = total_sse + best_sse
  28390 			goto _4
  28391 		_4:
  28392 			;
  28393 			x = x + 1
  28394 		}
  28395 		goto _1
  28396 	_1:
  28397 		;
  28398 		y = y + 1
  28399 	}
  28400 	return total_sse
  28401 }
  28402 
  28403 func AccumulateSSE(tls *libc.TLS, src uintptr, src_stride int32, ref uintptr, ref_stride int32, w int32, h int32) (r float64) {
  28404 	var total_sse float64
  28405 	var y int32
  28406 	_, _ = total_sse, y
  28407 	total_sse = float64(0)
  28408 	y = 0
  28409 	for {
  28410 		if !(y < h) {
  28411 			break
  28412 		}
  28413 		total_sse = total_sse + float64((*(*func(*libc.TLS, uintptr, uintptr, int32) uint32_t)(unsafe.Pointer(&struct{ uintptr }{VP8AccumulateSSE})))(tls, src, ref, w))
  28414 		src = src + uintptr(src_stride)
  28415 		ref = ref + uintptr(ref_stride)
  28416 		goto _1
  28417 	_1:
  28418 		;
  28419 		y = y + 1
  28420 	}
  28421 	return total_sse
  28422 }
  28423 
  28424 //------------------------------------------------------------------------------
  28425 
  28426 func AccumulateSSIM(tls *libc.TLS, src uintptr, src_stride int32, ref uintptr, ref_stride int32, w int32, h int32) (r float64) {
  28427 	var h0, h1, off1, off2, w0, w1, x, y, v1, v2 int32
  28428 	var sum float64
  28429 	_, _, _, _, _, _, _, _, _, _, _ = h0, h1, off1, off2, sum, w0, w1, x, y, v1, v2
  28430 	if w < int32(VP8_SSIM_KERNEL) {
  28431 		v1 = w
  28432 	} else {
  28433 		v1 = int32(VP8_SSIM_KERNEL)
  28434 	}
  28435 	w0 = v1
  28436 	w1 = w - int32(VP8_SSIM_KERNEL) - int32(1)
  28437 	if h < int32(VP8_SSIM_KERNEL) {
  28438 		v2 = h
  28439 	} else {
  28440 		v2 = int32(VP8_SSIM_KERNEL)
  28441 	}
  28442 	h0 = v2
  28443 	h1 = h - int32(VP8_SSIM_KERNEL) - int32(1)
  28444 	sum = float64(0)
  28445 	y = 0
  28446 	for {
  28447 		if !(y < h0) {
  28448 			break
  28449 		}
  28450 		x = 0
  28451 		for {
  28452 			if !(x < w) {
  28453 				break
  28454 			}
  28455 			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)
  28456 			goto _4
  28457 		_4:
  28458 			;
  28459 			x = x + 1
  28460 		}
  28461 		goto _3
  28462 	_3:
  28463 		;
  28464 		y = y + 1
  28465 	}
  28466 	for {
  28467 		if !(y < h1) {
  28468 			break
  28469 		}
  28470 		x = 0
  28471 		for {
  28472 			if !(x < w0) {
  28473 				break
  28474 			}
  28475 			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)
  28476 			goto _6
  28477 		_6:
  28478 			;
  28479 			x = x + 1
  28480 		}
  28481 		for {
  28482 			if !(x < w1) {
  28483 				break
  28484 			}
  28485 			off1 = x - int32(VP8_SSIM_KERNEL) + (y-int32(VP8_SSIM_KERNEL))*src_stride
  28486 			off2 = x - int32(VP8_SSIM_KERNEL) + (y-int32(VP8_SSIM_KERNEL))*ref_stride
  28487 			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)
  28488 			goto _7
  28489 		_7:
  28490 			;
  28491 			x = x + 1
  28492 		}
  28493 		for {
  28494 			if !(x < w) {
  28495 				break
  28496 			}
  28497 			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)
  28498 			goto _8
  28499 		_8:
  28500 			;
  28501 			x = x + 1
  28502 		}
  28503 		goto _5
  28504 	_5:
  28505 		;
  28506 		y = y + 1
  28507 	}
  28508 	for {
  28509 		if !(y < h) {
  28510 			break
  28511 		}
  28512 		x = 0
  28513 		for {
  28514 			if !(x < w) {
  28515 				break
  28516 			}
  28517 			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)
  28518 			goto _10
  28519 		_10:
  28520 			;
  28521 			x = x + 1
  28522 		}
  28523 		goto _9
  28524 	_9:
  28525 		;
  28526 		y = y + 1
  28527 	}
  28528 	return sum
  28529 }
  28530 
  28531 //------------------------------------------------------------------------------
  28532 // Distortion
  28533 
  28534 // C documentation
  28535 //
  28536 //	// Max value returned in case of exact similarity.
  28537 var kMinDistortion_dB = float64(99)
  28538 
  28539 func GetPSNR1(tls *libc.TLS, v float64, size float64) (r float64) {
  28540 	var v1 float64
  28541 	_ = v1
  28542 	if v > float64(0) && size > float64(0) {
  28543 		v1 = float64(-libc.Float64FromFloat64(4.3429448) * libc.Xlog(tls, v/float64(float64(size*libc.Float64FromInt32(255))*float64(255))))
  28544 	} else {
  28545 		v1 = kMinDistortion_dB
  28546 	}
  28547 	return v1
  28548 }
  28549 
  28550 func GetLogSSIM(tls *libc.TLS, v float64, size float64) (r float64) {
  28551 	var v1 float64
  28552 	_ = v1
  28553 	if size > float64(0) {
  28554 		v1 = v / size
  28555 	} else {
  28556 		v1 = float64(1)
  28557 	}
  28558 	v = v1
  28559 	if v < float64(1) {
  28560 		v1 = float64(-libc.Float64FromFloat64(10) * libc.Xlog10(tls, float64(1)-v))
  28561 	} else {
  28562 		v1 = kMinDistortion_dB
  28563 	}
  28564 	return v1
  28565 }
  28566 
  28567 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) {
  28568 	var allocated, tmp1, tmp2, v1, v2 uintptr
  28569 	var metric AccumulateFunc
  28570 	var x, y int32
  28571 	var v5 float32
  28572 	_, _, _, _, _, _, _, _, _ = allocated, metric, tmp1, tmp2, x, y, v1, v2, v5
  28573 	allocated = libc.UintptrFromInt32(0)
  28574 	if type1 == 0 {
  28575 		v1 = __ccgo_fp(AccumulateSSE)
  28576 	} else {
  28577 		if type1 == int32(1) {
  28578 			v2 = __ccgo_fp(AccumulateSSIM)
  28579 		} else {
  28580 			v2 = __ccgo_fp(AccumulateLSIM)
  28581 		}
  28582 		v1 = v2
  28583 	}
  28584 	metric = v1
  28585 	if src == libc.UintptrFromInt32(0) || ref == libc.UintptrFromInt32(0) || src_stride < x_step*uint64(width) || ref_stride < x_step*uint64(width) || result == libc.UintptrFromInt32(0) || distortion == libc.UintptrFromInt32(0) {
  28586 		return 0
  28587 	}
  28588 	VP8SSIMDspInit(tls)
  28589 	if x_step != uint64(1) {
  28590 		allocated = WebPSafeMalloc(tls, uint64(2)*uint64(width)*uint64(height), uint64(1))
  28591 		if allocated == libc.UintptrFromInt32(0) {
  28592 			return 0
  28593 		}
  28594 		tmp1 = allocated
  28595 		tmp2 = tmp1 + uintptr(uint64(width)*uint64(height))
  28596 		y = 0
  28597 		for {
  28598 			if !(y < height) {
  28599 				break
  28600 			}
  28601 			x = 0
  28602 			for {
  28603 				if !(x < width) {
  28604 					break
  28605 				}
  28606 				**(**uint8_t)(__ccgo_up(tmp1 + uintptr(x+y*width))) = **(**uint8_t)(__ccgo_up(src + uintptr(uint64(x)*x_step+uint64(y)*src_stride)))
  28607 				**(**uint8_t)(__ccgo_up(tmp2 + uintptr(x+y*width))) = **(**uint8_t)(__ccgo_up(ref + uintptr(uint64(x)*x_step+uint64(y)*ref_stride)))
  28608 				goto _4
  28609 			_4:
  28610 				;
  28611 				x = x + 1
  28612 			}
  28613 			goto _3
  28614 		_3:
  28615 			;
  28616 			y = y + 1
  28617 		}
  28618 		src = tmp1
  28619 		ref = tmp2
  28620 	}
  28621 	**(**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))
  28622 	WebPSafeFree(tls, allocated)
  28623 	if type1 == int32(1) {
  28624 		v5 = float32(GetLogSSIM(tls, float64(**(**float32)(__ccgo_up(distortion))), float64(float64(width)*float64(height))))
  28625 	} else {
  28626 		v5 = float32(GetPSNR1(tls, float64(**(**float32)(__ccgo_up(distortion))), float64(float64(width)*float64(height))))
  28627 	}
  28628 	**(**float32)(__ccgo_up(result)) = v5
  28629 	return int32(1)
  28630 }
  28631 
  28632 func WebPPictureDistortion(tls *libc.TLS, src uintptr, ref uintptr, type1 int32, results uintptr) (r int32) {
  28633 	bp := tls.Alloc(528)
  28634 	defer tls.Free(528)
  28635 	var c, h, offset, ok, w, v1, v3 int32
  28636 	var stride0, stride1 size_t
  28637 	var total_distortion, total_size float64
  28638 	var v5 bool
  28639 	var v7 float32
  28640 	var _ /* distortion at bp+512 */ float32
  28641 	var _ /* p0 at bp+0 */ WebPPicture
  28642 	var _ /* p1 at bp+256 */ WebPPicture
  28643 	_, _, _, _, _, _, _, _, _, _, _, _, _ = c, h, offset, ok, stride0, stride1, total_distortion, total_size, w, v1, v3, v5, v7
  28644 	ok = 0
  28645 	total_size = float64(0)
  28646 	total_distortion = float64(0)
  28647 	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) {
  28648 		return 0
  28649 	}
  28650 	VP8SSIMDspInit(tls)
  28651 	v1 = WebPPictureInitInternal(tls, bp, int32(WEBP_ENCODER_ABI_VERSION))
  28652 	goto _2
  28653 _2:
  28654 	;
  28655 	if v5 = !(v1 != 0); !v5 {
  28656 		v3 = WebPPictureInitInternal(tls, bp+256, int32(WEBP_ENCODER_ABI_VERSION))
  28657 		goto _4
  28658 	_4:
  28659 	}
  28660 	if v5 || !(v3 != 0) {
  28661 		return 0
  28662 	}
  28663 	w = (*WebPPicture)(unsafe.Pointer(src)).Fwidth
  28664 	h = (*WebPPicture)(unsafe.Pointer(src)).Fheight
  28665 	if !(WebPPictureView(tls, src, 0, 0, w, h, bp) != 0) {
  28666 		goto Error
  28667 	}
  28668 	if !(WebPPictureView(tls, ref, 0, 0, w, h, bp+256) != 0) {
  28669 		goto Error
  28670 	}
  28671 	// We always measure distortion in ARGB space.
  28672 	if (**(**WebPPicture)(__ccgo_up(bp))).Fuse_argb == 0 && !(WebPPictureYUVAToARGB(tls, bp) != 0) {
  28673 		goto Error
  28674 	}
  28675 	if (**(**WebPPicture)(__ccgo_up(bp + 256))).Fuse_argb == 0 && !(WebPPictureYUVAToARGB(tls, bp+256) != 0) {
  28676 		goto Error
  28677 	}
  28678 	c = 0
  28679 	for {
  28680 		if !(c < int32(4)) {
  28681 			break
  28682 		}
  28683 		stride0 = uint64(4) * uint64((**(**WebPPicture)(__ccgo_up(bp))).Fargb_stride)
  28684 		stride1 = uint64(4) * uint64((**(**WebPPicture)(__ccgo_up(bp + 256))).Fargb_stride)
  28685 		// results are reported as BGRA
  28686 		offset = c ^ 0
  28687 		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) {
  28688 			goto Error
  28689 		}
  28690 		total_distortion = total_distortion + float64(**(**float32)(__ccgo_up(bp + 512)))
  28691 		total_size = total_size + float64(w*h)
  28692 		goto _6
  28693 	_6:
  28694 		;
  28695 		c = c + 1
  28696 	}
  28697 	if type1 == int32(1) {
  28698 		v7 = float32(GetLogSSIM(tls, total_distortion, total_size))
  28699 	} else {
  28700 		v7 = float32(GetPSNR1(tls, total_distortion, total_size))
  28701 	}
  28702 	**(**float32)(__ccgo_up(results + 4*4)) = v7
  28703 	ok = int32(1)
  28704 	goto Error
  28705 Error:
  28706 	;
  28707 	WebPPictureFree(tls, bp)
  28708 	WebPPictureFree(tls, bp+256)
  28709 	return ok
  28710 }
  28711 
  28712 //------------------------------------------------------------------------------
  28713 
  28714 // Copyright 2012 Google Inc. All Rights Reserved.
  28715 //
  28716 // Use of this source code is governed by a BSD-style license
  28717 // that can be found in the COPYING file in the root of the source
  28718 // tree. An additional intellectual property rights grant can be found
  28719 // in the file PATENTS. All contributing project authors may
  28720 // be found in the AUTHORS file in the root of the source tree.
  28721 // -----------------------------------------------------------------------------
  28722 //
  28723 // Misc. common utility functions
  28724 //
  28725 // Authors: Skal (pascal.massimino@gmail.com)
  28726 //          Urvang (urvang@google.com)
  28727 
  28728 // C documentation
  28729 //
  28730 //	// Grab the 'specs' (writer, *opaque, width, height...) from 'src' and copy them
  28731 //	// into 'dst'. Mark 'dst' as not owning any memory.
  28732 func PictureGrabSpecs(tls *libc.TLS, src uintptr, dst uintptr) {
  28733 	**(**WebPPicture)(__ccgo_up(dst)) = **(**WebPPicture)(__ccgo_up(src))
  28734 	WebPPictureResetBuffers(tls, dst)
  28735 }
  28736 
  28737 //------------------------------------------------------------------------------
  28738 
  28739 // C documentation
  28740 //
  28741 //	// Adjust top-left corner to chroma sample position.
  28742 func SnapTopLeftPosition(tls *libc.TLS, pic uintptr, left uintptr, top uintptr) {
  28743 	if !((*WebPPicture)(unsafe.Pointer(pic)).Fuse_argb != 0) {
  28744 		**(**int32)(__ccgo_up(left)) &= ^libc.Int32FromInt32(1)
  28745 		**(**int32)(__ccgo_up(top)) &= ^libc.Int32FromInt32(1)
  28746 	}
  28747 }
  28748 
  28749 // C documentation
  28750 //
  28751 //	// Adjust top-left corner and verify that the sub-rectangle is valid.
  28752 func AdjustAndCheckRectangle(tls *libc.TLS, pic uintptr, left uintptr, top uintptr, width int32, height int32) (r int32) {
  28753 	SnapTopLeftPosition(tls, pic, left, top)
  28754 	if **(**int32)(__ccgo_up(left)) < 0 || **(**int32)(__ccgo_up(top)) < 0 {
  28755 		return 0
  28756 	}
  28757 	if width <= 0 || height <= 0 {
  28758 		return 0
  28759 	}
  28760 	if **(**int32)(__ccgo_up(left))+width > (*WebPPicture)(unsafe.Pointer(pic)).Fwidth {
  28761 		return 0
  28762 	}
  28763 	if **(**int32)(__ccgo_up(top))+height > (*WebPPicture)(unsafe.Pointer(pic)).Fheight {
  28764 		return 0
  28765 	}
  28766 	return int32(1)
  28767 }
  28768 
  28769 func WebPPictureCopy(tls *libc.TLS, src uintptr, dst uintptr) (r int32) {
  28770 	if src == libc.UintptrFromInt32(0) || dst == libc.UintptrFromInt32(0) {
  28771 		return 0
  28772 	}
  28773 	if src == dst {
  28774 		return int32(1)
  28775 	}
  28776 	PictureGrabSpecs(tls, src, dst)
  28777 	if !(WebPPictureAlloc(tls, dst) != 0) {
  28778 		return 0
  28779 	}
  28780 	if !((*WebPPicture)(unsafe.Pointer(src)).Fuse_argb != 0) {
  28781 		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)
  28782 		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))
  28783 		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))
  28784 		if (*WebPPicture)(unsafe.Pointer(dst)).Fa != libc.UintptrFromInt32(0) {
  28785 			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)
  28786 		}
  28787 	} else {
  28788 		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)
  28789 	}
  28790 	return int32(1)
  28791 }
  28792 
  28793 func WebPPictureIsView(tls *libc.TLS, picture uintptr) (r int32) {
  28794 	if picture == libc.UintptrFromInt32(0) {
  28795 		return 0
  28796 	}
  28797 	if (*WebPPicture)(unsafe.Pointer(picture)).Fuse_argb != 0 {
  28798 		return libc.BoolInt32((*WebPPicture)(unsafe.Pointer(picture)).Fmemory_argb_ == libc.UintptrFromInt32(0))
  28799 	}
  28800 	return libc.BoolInt32((*WebPPicture)(unsafe.Pointer(picture)).Fmemory_ == libc.UintptrFromInt32(0))
  28801 }
  28802 
  28803 func WebPPictureView(tls *libc.TLS, src uintptr, _left int32, _top int32, width int32, height int32, dst uintptr) (r int32) {
  28804 	bp := tls.Alloc(16)
  28805 	defer tls.Free(16)
  28806 	*(*int32)(unsafe.Pointer(bp)) = _left
  28807 	*(*int32)(unsafe.Pointer(bp + 4)) = _top
  28808 	if src == libc.UintptrFromInt32(0) || dst == libc.UintptrFromInt32(0) {
  28809 		return 0
  28810 	}
  28811 	// verify rectangle position.
  28812 	if !(AdjustAndCheckRectangle(tls, src, bp, bp+4, width, height) != 0) {
  28813 		return 0
  28814 	}
  28815 	if src != dst { // beware of aliasing! We don't want to leak 'memory_'.
  28816 		PictureGrabSpecs(tls, src, dst)
  28817 	}
  28818 	(*WebPPicture)(unsafe.Pointer(dst)).Fwidth = width
  28819 	(*WebPPicture)(unsafe.Pointer(dst)).Fheight = height
  28820 	if !((*WebPPicture)(unsafe.Pointer(src)).Fuse_argb != 0) {
  28821 		(*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)))
  28822 		(*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))
  28823 		(*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))
  28824 		(*WebPPicture)(unsafe.Pointer(dst)).Fy_stride = (*WebPPicture)(unsafe.Pointer(src)).Fy_stride
  28825 		(*WebPPicture)(unsafe.Pointer(dst)).Fuv_stride = (*WebPPicture)(unsafe.Pointer(src)).Fuv_stride
  28826 		if (*WebPPicture)(unsafe.Pointer(src)).Fa != libc.UintptrFromInt32(0) {
  28827 			(*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)))
  28828 			(*WebPPicture)(unsafe.Pointer(dst)).Fa_stride = (*WebPPicture)(unsafe.Pointer(src)).Fa_stride
  28829 		}
  28830 	} else {
  28831 		(*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
  28832 		(*WebPPicture)(unsafe.Pointer(dst)).Fargb_stride = (*WebPPicture)(unsafe.Pointer(src)).Fargb_stride
  28833 	}
  28834 	return int32(1)
  28835 }
  28836 
  28837 //------------------------------------------------------------------------------
  28838 // Picture cropping
  28839 
  28840 func WebPPictureCrop(tls *libc.TLS, pic uintptr, _left int32, _top int32, width int32, height int32) (r int32) {
  28841 	bp := tls.Alloc(272)
  28842 	defer tls.Free(272)
  28843 	*(*int32)(unsafe.Pointer(bp)) = _left
  28844 	*(*int32)(unsafe.Pointer(bp + 4)) = _top
  28845 	var a_offset, uv_offset, y_offset int32
  28846 	var src uintptr
  28847 	var _ /* tmp at bp+8 */ WebPPicture
  28848 	_, _, _, _ = a_offset, src, uv_offset, y_offset
  28849 	if pic == libc.UintptrFromInt32(0) {
  28850 		return 0
  28851 	}
  28852 	if !(AdjustAndCheckRectangle(tls, pic, bp, bp+4, width, height) != 0) {
  28853 		return 0
  28854 	}
  28855 	PictureGrabSpecs(tls, pic, bp+8)
  28856 	(**(**WebPPicture)(__ccgo_up(bp + 8))).Fwidth = width
  28857 	(**(**WebPPicture)(__ccgo_up(bp + 8))).Fheight = height
  28858 	if !(WebPPictureAlloc(tls, bp+8) != 0) {
  28859 		return WebPEncodingSetError(tls, pic, (**(**WebPPicture)(__ccgo_up(bp + 8))).Ferror_code)
  28860 	}
  28861 	if !((*WebPPicture)(unsafe.Pointer(pic)).Fuse_argb != 0) {
  28862 		y_offset = **(**int32)(__ccgo_up(bp + 4))*(*WebPPicture)(unsafe.Pointer(pic)).Fy_stride + **(**int32)(__ccgo_up(bp))
  28863 		uv_offset = **(**int32)(__ccgo_up(bp + 4))/int32(2)*(*WebPPicture)(unsafe.Pointer(pic)).Fuv_stride + **(**int32)(__ccgo_up(bp))/int32(2)
  28864 		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)
  28865 		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))
  28866 		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))
  28867 		if (**(**WebPPicture)(__ccgo_up(bp + 8))).Fa != libc.UintptrFromInt32(0) {
  28868 			a_offset = **(**int32)(__ccgo_up(bp + 4))*(*WebPPicture)(unsafe.Pointer(pic)).Fa_stride + **(**int32)(__ccgo_up(bp))
  28869 			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)
  28870 		}
  28871 	} else {
  28872 		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
  28873 		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)
  28874 	}
  28875 	WebPPictureFree(tls, pic)
  28876 	**(**WebPPicture)(__ccgo_up(pic)) = **(**WebPPicture)(__ccgo_up(bp + 8))
  28877 	return int32(1)
  28878 }
  28879 
  28880 //------------------------------------------------------------------------------
  28881 // Simple picture rescaler
  28882 
  28883 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) {
  28884 	bp := tls.Alloc(112)
  28885 	defer tls.Free(112)
  28886 	var y int32
  28887 	var _ /* rescaler at bp+0 */ WebPRescaler
  28888 	_ = y
  28889 	y = 0
  28890 	if !(WebPRescalerInit(tls, bp, src_width, src_height, dst, dst_width, dst_height, dst_stride, num_channels, work) != 0) {
  28891 		return 0
  28892 	}
  28893 	for y < src_height {
  28894 		y = y + WebPRescalerImport(tls, bp, src_height-y, src+uintptr(y*src_stride), src_stride)
  28895 		WebPRescalerExport(tls, bp)
  28896 	}
  28897 	return int32(1)
  28898 }
  28899 
  28900 func AlphaMultiplyARGB(tls *libc.TLS, pic uintptr, inverse int32) {
  28901 	WebPMultARGBRows(tls, (*WebPPicture)(unsafe.Pointer(pic)).Fargb, int32(uint64((*WebPPicture)(unsafe.Pointer(pic)).Fargb_stride)*uint64(4)), (*WebPPicture)(unsafe.Pointer(pic)).Fwidth, (*WebPPicture)(unsafe.Pointer(pic)).Fheight, inverse)
  28902 }
  28903 
  28904 func AlphaMultiplyY(tls *libc.TLS, pic uintptr, inverse int32) {
  28905 	if (*WebPPicture)(unsafe.Pointer(pic)).Fa != libc.UintptrFromInt32(0) {
  28906 		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)
  28907 	}
  28908 }
  28909 
  28910 func WebPPictureRescale(tls *libc.TLS, picture uintptr, _width int32, _height int32) (r int32) {
  28911 	bp := tls.Alloc(272)
  28912 	defer tls.Free(272)
  28913 	*(*int32)(unsafe.Pointer(bp)) = _width
  28914 	*(*int32)(unsafe.Pointer(bp + 4)) = _height
  28915 	var prev_height, prev_width int32
  28916 	var work uintptr
  28917 	var _ /* tmp at bp+8 */ WebPPicture
  28918 	_, _, _ = prev_height, prev_width, work
  28919 	if picture == libc.UintptrFromInt32(0) {
  28920 		return 0
  28921 	}
  28922 	prev_width = (*WebPPicture)(unsafe.Pointer(picture)).Fwidth
  28923 	prev_height = (*WebPPicture)(unsafe.Pointer(picture)).Fheight
  28924 	if !(WebPRescalerGetScaledDimensions(tls, prev_width, prev_height, bp, bp+4) != 0) {
  28925 		return WebPEncodingSetError(tls, picture, int32(VP8_ENC_ERROR_BAD_DIMENSION))
  28926 	}
  28927 	PictureGrabSpecs(tls, picture, bp+8)
  28928 	(**(**WebPPicture)(__ccgo_up(bp + 8))).Fwidth = **(**int32)(__ccgo_up(bp))
  28929 	(**(**WebPPicture)(__ccgo_up(bp + 8))).Fheight = **(**int32)(__ccgo_up(bp + 4))
  28930 	if !(WebPPictureAlloc(tls, bp+8) != 0) {
  28931 		return WebPEncodingSetError(tls, picture, (**(**WebPPicture)(__ccgo_up(bp + 8))).Ferror_code)
  28932 	}
  28933 	if !((*WebPPicture)(unsafe.Pointer(picture)).Fuse_argb != 0) {
  28934 		work = WebPSafeMalloc(tls, uint64(2)*uint64(**(**int32)(__ccgo_up(bp))), uint64(4))
  28935 		if work == libc.UintptrFromInt32(0) {
  28936 			WebPPictureFree(tls, bp+8)
  28937 			return WebPEncodingSetError(tls, picture, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  28938 		}
  28939 		// If present, we need to rescale alpha first (for AlphaMultiplyY).
  28940 		if (*WebPPicture)(unsafe.Pointer(picture)).Fa != libc.UintptrFromInt32(0) {
  28941 			WebPInitAlphaProcessing(tls)
  28942 			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) {
  28943 				return WebPEncodingSetError(tls, picture, int32(VP8_ENC_ERROR_BAD_DIMENSION))
  28944 			}
  28945 		}
  28946 		// We take transparency into account on the luma plane only. That's not
  28947 		// totally exact blending, but still is a good approximation.
  28948 		AlphaMultiplyY(tls, picture, 0)
  28949 		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) {
  28950 			return WebPEncodingSetError(tls, picture, int32(VP8_ENC_ERROR_BAD_DIMENSION))
  28951 		}
  28952 		AlphaMultiplyY(tls, bp+8, int32(1))
  28953 	} else {
  28954 		work = WebPSafeMalloc(tls, uint64(2)*uint64(**(**int32)(__ccgo_up(bp)))*uint64(4), uint64(4))
  28955 		if work == libc.UintptrFromInt32(0) {
  28956 			WebPPictureFree(tls, bp+8)
  28957 			return WebPEncodingSetError(tls, picture, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  28958 		}
  28959 		// In order to correctly interpolate colors, we need to apply the alpha
  28960 		// weighting first (black-matting), scale the RGB values, and remove
  28961 		// the premultiplication afterward (while preserving the alpha channel).
  28962 		WebPInitAlphaProcessing(tls)
  28963 		AlphaMultiplyARGB(tls, picture, 0)
  28964 		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) {
  28965 			return WebPEncodingSetError(tls, picture, int32(VP8_ENC_ERROR_BAD_DIMENSION))
  28966 		}
  28967 		AlphaMultiplyARGB(tls, bp+8, int32(1))
  28968 	}
  28969 	WebPPictureFree(tls, picture)
  28970 	WebPSafeFree(tls, work)
  28971 	**(**WebPPicture)(__ccgo_up(picture)) = **(**WebPPicture)(__ccgo_up(bp + 8))
  28972 	return int32(1)
  28973 }
  28974 
  28975 //------------------------------------------------------------------------------
  28976 
  28977 // Copyright 2011 Google Inc. All Rights Reserved.
  28978 //
  28979 // Use of this source code is governed by a BSD-style license
  28980 // that can be found in the COPYING file in the root of the source
  28981 // tree. An additional intellectual property rights grant can be found
  28982 // in the file PATENTS. All contributing project authors may
  28983 // be found in the AUTHORS file in the root of the source tree.
  28984 // -----------------------------------------------------------------------------
  28985 //
  28986 //   WebP encoder: main interface
  28987 //
  28988 // Author: Skal (pascal.massimino@gmail.com)
  28989 
  28990 // Copyright 2010 Google Inc. All Rights Reserved.
  28991 //
  28992 // Use of this source code is governed by a BSD-style license
  28993 // that can be found in the COPYING file in the root of the source
  28994 // tree. An additional intellectual property rights grant can be found
  28995 // in the file PATENTS. All contributing project authors may
  28996 // be found in the AUTHORS file in the root of the source tree.
  28997 // -----------------------------------------------------------------------------
  28998 //
  28999 //  Common types + memory wrappers
  29000 //
  29001 // Author: Skal (pascal.massimino@gmail.com)
  29002 
  29003 //------------------------------------------------------------------------------
  29004 // Helper: clean up fully transparent area to help compressibility.
  29005 
  29006 func IsTransparentARGBArea(tls *libc.TLS, ptr uintptr, stride int32, size int32) (r int32) {
  29007 	var x, y int32
  29008 	_, _ = x, y
  29009 	y = 0
  29010 	for {
  29011 		if !(y < size) {
  29012 			break
  29013 		}
  29014 		x = 0
  29015 		for {
  29016 			if !(x < size) {
  29017 				break
  29018 			}
  29019 			if **(**uint32_t)(__ccgo_up(ptr + uintptr(x)*4))&uint32(0xff000000) != 0 {
  29020 				return 0
  29021 			}
  29022 			goto _2
  29023 		_2:
  29024 			;
  29025 			x = x + 1
  29026 		}
  29027 		ptr = ptr + uintptr(stride)*4
  29028 		goto _1
  29029 	_1:
  29030 		;
  29031 		y = y + 1
  29032 	}
  29033 	return int32(1)
  29034 }
  29035 
  29036 func Flatten(tls *libc.TLS, ptr uintptr, v int32, stride int32, size int32) {
  29037 	var y int32
  29038 	_ = y
  29039 	y = 0
  29040 	for {
  29041 		if !(y < size) {
  29042 			break
  29043 		}
  29044 		libc.Xmemset(tls, ptr, v, uint64(size))
  29045 		ptr = ptr + uintptr(stride)
  29046 		goto _1
  29047 	_1:
  29048 		;
  29049 		y = y + 1
  29050 	}
  29051 }
  29052 
  29053 func FlattenARGB(tls *libc.TLS, ptr uintptr, v uint32_t, stride int32, size int32) {
  29054 	var x, y int32
  29055 	_, _ = x, y
  29056 	y = 0
  29057 	for {
  29058 		if !(y < size) {
  29059 			break
  29060 		}
  29061 		x = 0
  29062 		for {
  29063 			if !(x < size) {
  29064 				break
  29065 			}
  29066 			**(**uint32_t)(__ccgo_up(ptr + uintptr(x)*4)) = v
  29067 			goto _2
  29068 		_2:
  29069 			;
  29070 			x = x + 1
  29071 		}
  29072 		ptr = ptr + uintptr(stride)*4
  29073 		goto _1
  29074 	_1:
  29075 		;
  29076 		y = y + 1
  29077 	}
  29078 }
  29079 
  29080 // C documentation
  29081 //
  29082 //	// Smoothen the luma components of transparent pixels. Return true if the whole
  29083 //	// block is transparent.
  29084 func SmoothenBlock(tls *libc.TLS, a_ptr uintptr, a_stride int32, y_ptr uintptr, y_stride int32, width int32, height int32) (r int32) {
  29085 	var alpha_ptr, luma_ptr uintptr
  29086 	var avg_u8 uint8_t
  29087 	var count, sum, x, y int32
  29088 	_, _, _, _, _, _, _ = alpha_ptr, avg_u8, count, luma_ptr, sum, x, y
  29089 	sum = 0
  29090 	count = 0
  29091 	alpha_ptr = a_ptr
  29092 	luma_ptr = y_ptr
  29093 	y = 0
  29094 	for {
  29095 		if !(y < height) {
  29096 			break
  29097 		}
  29098 		x = 0
  29099 		for {
  29100 			if !(x < width) {
  29101 				break
  29102 			}
  29103 			if int32(**(**uint8_t)(__ccgo_up(alpha_ptr + uintptr(x)))) != 0 {
  29104 				count = count + 1
  29105 				sum = sum + int32(**(**uint8_t)(__ccgo_up(luma_ptr + uintptr(x))))
  29106 			}
  29107 			goto _2
  29108 		_2:
  29109 			;
  29110 			x = x + 1
  29111 		}
  29112 		alpha_ptr = alpha_ptr + uintptr(a_stride)
  29113 		luma_ptr = luma_ptr + uintptr(y_stride)
  29114 		goto _1
  29115 	_1:
  29116 		;
  29117 		y = y + 1
  29118 	}
  29119 	if count > 0 && count < width*height {
  29120 		avg_u8 = uint8(sum / count)
  29121 		alpha_ptr = a_ptr
  29122 		luma_ptr = y_ptr
  29123 		y = 0
  29124 		for {
  29125 			if !(y < height) {
  29126 				break
  29127 			}
  29128 			x = 0
  29129 			for {
  29130 				if !(x < width) {
  29131 					break
  29132 				}
  29133 				if int32(**(**uint8_t)(__ccgo_up(alpha_ptr + uintptr(x)))) == 0 {
  29134 					**(**uint8_t)(__ccgo_up(luma_ptr + uintptr(x))) = avg_u8
  29135 				}
  29136 				goto _4
  29137 			_4:
  29138 				;
  29139 				x = x + 1
  29140 			}
  29141 			alpha_ptr = alpha_ptr + uintptr(a_stride)
  29142 			luma_ptr = luma_ptr + uintptr(y_stride)
  29143 			goto _3
  29144 		_3:
  29145 			;
  29146 			y = y + 1
  29147 		}
  29148 	}
  29149 	return libc.BoolInt32(count == 0)
  29150 }
  29151 
  29152 func WebPReplaceTransparentPixels(tls *libc.TLS, pic uintptr, color uint32_t) {
  29153 	var argb uintptr
  29154 	var y, v1 int32
  29155 	_, _, _ = argb, y, v1
  29156 	if pic != libc.UintptrFromInt32(0) && (*WebPPicture)(unsafe.Pointer(pic)).Fuse_argb != 0 {
  29157 		y = (*WebPPicture)(unsafe.Pointer(pic)).Fheight
  29158 		argb = (*WebPPicture)(unsafe.Pointer(pic)).Fargb
  29159 		color = color & uint32(0xffffff) // force alpha=0
  29160 		WebPInitAlphaProcessing(tls)
  29161 		for {
  29162 			v1 = y
  29163 			y = y - 1
  29164 			if !(v1 > 0) {
  29165 				break
  29166 			}
  29167 			(*(*func(*libc.TLS, uintptr, int32, uint32_t))(unsafe.Pointer(&struct{ uintptr }{WebPAlphaReplace})))(tls, argb, (*WebPPicture)(unsafe.Pointer(pic)).Fwidth, color)
  29168 			argb = argb + uintptr((*WebPPicture)(unsafe.Pointer(pic)).Fargb_stride)*4
  29169 		}
  29170 	}
  29171 }
  29172 
  29173 func WebPCleanupTransparentArea(tls *libc.TLS, pic uintptr) {
  29174 	var a_ptr, u_ptr, v_ptr, y_ptr uintptr
  29175 	var a_stride, h, height, need_reset, need_reset1, off, sub_height, uv_stride, w, width, x, y, y_stride int32
  29176 	var argb_value uint32_t
  29177 	var values [3]int32
  29178 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  29179 	if pic == libc.UintptrFromInt32(0) {
  29180 		return
  29181 	}
  29182 	w = (*WebPPicture)(unsafe.Pointer(pic)).Fwidth / int32(8)
  29183 	h = (*WebPPicture)(unsafe.Pointer(pic)).Fheight / int32(8)
  29184 	// note: we ignore the left-overs on right/bottom, except for SmoothenBlock().
  29185 	if (*WebPPicture)(unsafe.Pointer(pic)).Fuse_argb != 0 {
  29186 		argb_value = uint32(0)
  29187 		y = 0
  29188 		for {
  29189 			if !(y < h) {
  29190 				break
  29191 			}
  29192 			need_reset = int32(1)
  29193 			x = 0
  29194 			for {
  29195 				if !(x < w) {
  29196 					break
  29197 				}
  29198 				off = (y*(*WebPPicture)(unsafe.Pointer(pic)).Fargb_stride + x) * int32(8)
  29199 				if IsTransparentARGBArea(tls, (*WebPPicture)(unsafe.Pointer(pic)).Fargb+uintptr(off)*4, (*WebPPicture)(unsafe.Pointer(pic)).Fargb_stride, int32(8)) != 0 {
  29200 					if need_reset != 0 {
  29201 						argb_value = **(**uint32_t)(__ccgo_up((*WebPPicture)(unsafe.Pointer(pic)).Fargb + uintptr(off)*4))
  29202 						need_reset = 0
  29203 					}
  29204 					FlattenARGB(tls, (*WebPPicture)(unsafe.Pointer(pic)).Fargb+uintptr(off)*4, argb_value, (*WebPPicture)(unsafe.Pointer(pic)).Fargb_stride, int32(8))
  29205 				} else {
  29206 					need_reset = int32(1)
  29207 				}
  29208 				goto _2
  29209 			_2:
  29210 				;
  29211 				x = x + 1
  29212 			}
  29213 			goto _1
  29214 		_1:
  29215 			;
  29216 			y = y + 1
  29217 		}
  29218 	} else {
  29219 		width = (*WebPPicture)(unsafe.Pointer(pic)).Fwidth
  29220 		height = (*WebPPicture)(unsafe.Pointer(pic)).Fheight
  29221 		y_stride = (*WebPPicture)(unsafe.Pointer(pic)).Fy_stride
  29222 		uv_stride = (*WebPPicture)(unsafe.Pointer(pic)).Fuv_stride
  29223 		a_stride = (*WebPPicture)(unsafe.Pointer(pic)).Fa_stride
  29224 		y_ptr = (*WebPPicture)(unsafe.Pointer(pic)).Fy
  29225 		u_ptr = (*WebPPicture)(unsafe.Pointer(pic)).Fu
  29226 		v_ptr = (*WebPPicture)(unsafe.Pointer(pic)).Fv
  29227 		a_ptr = (*WebPPicture)(unsafe.Pointer(pic)).Fa
  29228 		values = [3]int32{}
  29229 		if a_ptr == libc.UintptrFromInt32(0) || y_ptr == libc.UintptrFromInt32(0) || u_ptr == libc.UintptrFromInt32(0) || v_ptr == libc.UintptrFromInt32(0) {
  29230 			return
  29231 		}
  29232 		y = 0
  29233 		for {
  29234 			if !(y+int32(8) <= height) {
  29235 				break
  29236 			}
  29237 			need_reset1 = int32(1)
  29238 			x = 0
  29239 			for {
  29240 				if !(x+int32(8) <= width) {
  29241 					break
  29242 				}
  29243 				if SmoothenBlock(tls, a_ptr+uintptr(x), a_stride, y_ptr+uintptr(x), y_stride, int32(8), int32(8)) != 0 {
  29244 					if need_reset1 != 0 {
  29245 						values[0] = int32(**(**uint8_t)(__ccgo_up(y_ptr + uintptr(x))))
  29246 						values[int32(1)] = int32(**(**uint8_t)(__ccgo_up(u_ptr + uintptr(x>>int32(1)))))
  29247 						values[int32(2)] = int32(**(**uint8_t)(__ccgo_up(v_ptr + uintptr(x>>int32(1)))))
  29248 						need_reset1 = 0
  29249 					}
  29250 					Flatten(tls, y_ptr+uintptr(x), values[0], y_stride, int32(8))
  29251 					Flatten(tls, u_ptr+uintptr(x>>libc.Int32FromInt32(1)), values[int32(1)], uv_stride, libc.Int32FromInt32(8)/libc.Int32FromInt32(2))
  29252 					Flatten(tls, v_ptr+uintptr(x>>libc.Int32FromInt32(1)), values[int32(2)], uv_stride, libc.Int32FromInt32(8)/libc.Int32FromInt32(2))
  29253 				} else {
  29254 					need_reset1 = int32(1)
  29255 				}
  29256 				goto _4
  29257 			_4:
  29258 				;
  29259 				x = x + int32(8)
  29260 			}
  29261 			if x < width {
  29262 				SmoothenBlock(tls, a_ptr+uintptr(x), a_stride, y_ptr+uintptr(x), y_stride, width-x, int32(8))
  29263 			}
  29264 			a_ptr = a_ptr + uintptr(int32(8)*a_stride)
  29265 			y_ptr = y_ptr + uintptr(int32(8)*y_stride)
  29266 			u_ptr = u_ptr + uintptr(libc.Int32FromInt32(8)/libc.Int32FromInt32(2)*uv_stride)
  29267 			v_ptr = v_ptr + uintptr(libc.Int32FromInt32(8)/libc.Int32FromInt32(2)*uv_stride)
  29268 			goto _3
  29269 		_3:
  29270 			;
  29271 			y = y + int32(8)
  29272 		}
  29273 		if y < height {
  29274 			sub_height = height - y
  29275 			x = 0
  29276 			for {
  29277 				if !(x+int32(8) <= width) {
  29278 					break
  29279 				}
  29280 				SmoothenBlock(tls, a_ptr+uintptr(x), a_stride, y_ptr+uintptr(x), y_stride, int32(8), sub_height)
  29281 				goto _5
  29282 			_5:
  29283 				;
  29284 				x = x + int32(8)
  29285 			}
  29286 			if x < width {
  29287 				SmoothenBlock(tls, a_ptr+uintptr(x), a_stride, y_ptr+uintptr(x), y_stride, width-x, sub_height)
  29288 			}
  29289 		}
  29290 	}
  29291 }
  29292 
  29293 //------------------------------------------------------------------------------
  29294 // Blend color and remove transparency info
  29295 
  29296 func MakeARGB32(tls *libc.TLS, r int32, g int32, b int32) (r1 uint32_t) {
  29297 	return libc.Uint32FromUint32(0xff000000) | uint32(r<<libc.Int32FromInt32(16)) | uint32(g<<libc.Int32FromInt32(8)) | uint32(b)
  29298 }
  29299 
  29300 func WebPBlendAlpha(tls *libc.TLS, picture uintptr, background_rgb uint32_t) {
  29301 	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
  29302 	var a_ptr, a_ptr2, argb, u_ptr, v_ptr, y_ptr, v19 uintptr
  29303 	var alpha uint8_t
  29304 	var alpha1, alpha2, background uint32_t
  29305 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  29306 	red = int32(background_rgb >> libc.Int32FromInt32(16) & uint32(0xff))
  29307 	green = int32(background_rgb >> libc.Int32FromInt32(8) & uint32(0xff))
  29308 	blue = int32(background_rgb >> libc.Int32FromInt32(0) & uint32(0xff))
  29309 	if picture == libc.UintptrFromInt32(0) {
  29310 		return
  29311 	}
  29312 	if !((*WebPPicture)(unsafe.Pointer(picture)).Fuse_argb != 0) {
  29313 		// omit last pixel during u/v loop
  29314 		uv_width = (*WebPPicture)(unsafe.Pointer(picture)).Fwidth >> libc.Int32FromInt32(1)
  29315 		luma = int32(16839)*red + int32(33059)*green + int32(6420)*blue
  29316 		v1 = (luma + int32(YUV_HALF) + libc.Int32FromInt32(16)<<int32(YUV_FIX)) >> int32(YUV_FIX)
  29317 		goto _2
  29318 	_2:
  29319 		Y0 = v1
  29320 		u = -int32(9719)*(int32(4)*red) - int32(19081)*(int32(4)*green) + int32(28800)*(int32(4)*blue)
  29321 		v5 = u
  29322 		v5 = (v5 + libc.Int32FromInt32(4)*int32(YUV_HALF) + libc.Int32FromInt32(128)<<(int32(YUV_FIX)+libc.Int32FromInt32(2))) >> (int32(YUV_FIX) + libc.Int32FromInt32(2))
  29323 		if v5 & ^libc.Int32FromInt32(0xff) == 0 {
  29324 			v8 = v5
  29325 		} else {
  29326 			if v5 < 0 {
  29327 				v9 = 0
  29328 			} else {
  29329 				v9 = int32(255)
  29330 			}
  29331 			v8 = v9
  29332 		}
  29333 		v6 = v8
  29334 		goto _7
  29335 	_7:
  29336 		v3 = v6
  29337 		goto _4
  29338 	_4:
  29339 		// VP8RGBToU/V expects the u/v values summed over four pixels
  29340 		U0 = v3
  29341 		v = +libc.Int32FromInt32(28800)*(int32(4)*red) - int32(24116)*(int32(4)*green) - int32(4684)*(int32(4)*blue)
  29342 		v12 = v
  29343 		v12 = (v12 + libc.Int32FromInt32(4)*int32(YUV_HALF) + libc.Int32FromInt32(128)<<(int32(YUV_FIX)+libc.Int32FromInt32(2))) >> (int32(YUV_FIX) + libc.Int32FromInt32(2))
  29344 		if v12 & ^libc.Int32FromInt32(0xff) == 0 {
  29345 			v15 = v12
  29346 		} else {
  29347 			if v12 < 0 {
  29348 				v16 = 0
  29349 			} else {
  29350 				v16 = int32(255)
  29351 			}
  29352 			v15 = v16
  29353 		}
  29354 		v13 = v15
  29355 		goto _14
  29356 	_14:
  29357 		v10 = v13
  29358 		goto _11
  29359 	_11:
  29360 		V0 = v10
  29361 		has_alpha = (*WebPPicture)(unsafe.Pointer(picture)).Fcolorspace & int32(WEBP_CSP_ALPHA_BIT)
  29362 		y_ptr = (*WebPPicture)(unsafe.Pointer(picture)).Fy
  29363 		u_ptr = (*WebPPicture)(unsafe.Pointer(picture)).Fu
  29364 		v_ptr = (*WebPPicture)(unsafe.Pointer(picture)).Fv
  29365 		a_ptr = (*WebPPicture)(unsafe.Pointer(picture)).Fa
  29366 		if !(has_alpha != 0) || a_ptr == libc.UintptrFromInt32(0) {
  29367 			return
  29368 		} // nothing to do
  29369 		y = 0
  29370 		for {
  29371 			if !(y < (*WebPPicture)(unsafe.Pointer(picture)).Fheight) {
  29372 				break
  29373 			}
  29374 			// Luma blending
  29375 			x = 0
  29376 			for {
  29377 				if !(x < (*WebPPicture)(unsafe.Pointer(picture)).Fwidth) {
  29378 					break
  29379 				}
  29380 				alpha = **(**uint8_t)(__ccgo_up(a_ptr + uintptr(x)))
  29381 				if int32(alpha) < int32(0xff) {
  29382 					**(**uint8_t)(__ccgo_up(y_ptr + uintptr(x))) = uint8(((Y0*(libc.Int32FromInt32(255)-int32(alpha))+int32(**(**uint8_t)(__ccgo_up(y_ptr + uintptr(x))))*int32(alpha))*libc.Int32FromInt32(0x101) + libc.Int32FromInt32(256)) >> libc.Int32FromInt32(16))
  29383 				}
  29384 				goto _18
  29385 			_18:
  29386 				;
  29387 				x = x + 1
  29388 			}
  29389 			// Chroma blending every even line
  29390 			if y&int32(1) == 0 {
  29391 				if y+int32(1) == (*WebPPicture)(unsafe.Pointer(picture)).Fheight {
  29392 					v19 = a_ptr
  29393 				} else {
  29394 					v19 = a_ptr + uintptr((*WebPPicture)(unsafe.Pointer(picture)).Fa_stride)
  29395 				}
  29396 				a_ptr2 = v19
  29397 				x = 0
  29398 				for {
  29399 					if !(x < uv_width) {
  29400 						break
  29401 					}
  29402 					// Average four alpha values into a single blending weight.
  29403 					// TODO(skal): might lead to visible contouring. Can we do better?
  29404 					alpha1 = uint32(int32(**(**uint8_t)(__ccgo_up(a_ptr + uintptr(int32(2)*x+0)))) + int32(**(**uint8_t)(__ccgo_up(a_ptr + uintptr(int32(2)*x+int32(1))))) + int32(**(**uint8_t)(__ccgo_up(a_ptr2 + uintptr(int32(2)*x+0)))) + int32(**(**uint8_t)(__ccgo_up(a_ptr2 + uintptr(int32(2)*x+int32(1))))))
  29405 					**(**uint8_t)(__ccgo_up(u_ptr + uintptr(x))) = uint8(((uint32(U0)*(libc.Uint32FromInt32(1020)-alpha1)+uint32(**(**uint8_t)(__ccgo_up(u_ptr + uintptr(x))))*alpha1)*libc.Uint32FromInt32(0x101) + libc.Uint32FromInt32(1024)) >> libc.Int32FromInt32(18))
  29406 					**(**uint8_t)(__ccgo_up(v_ptr + uintptr(x))) = uint8(((uint32(V0)*(libc.Uint32FromInt32(1020)-alpha1)+uint32(**(**uint8_t)(__ccgo_up(v_ptr + uintptr(x))))*alpha1)*libc.Uint32FromInt32(0x101) + libc.Uint32FromInt32(1024)) >> libc.Int32FromInt32(18))
  29407 					goto _20
  29408 				_20:
  29409 					;
  29410 					x = x + 1
  29411 				}
  29412 				if (*WebPPicture)(unsafe.Pointer(picture)).Fwidth&int32(1) != 0 { // rightmost pixel
  29413 					alpha2 = uint32(int32(2) * (int32(**(**uint8_t)(__ccgo_up(a_ptr + uintptr(int32(2)*x+0)))) + int32(**(**uint8_t)(__ccgo_up(a_ptr2 + uintptr(int32(2)*x+0))))))
  29414 					**(**uint8_t)(__ccgo_up(u_ptr + uintptr(x))) = uint8(((uint32(U0)*(libc.Uint32FromInt32(1020)-alpha2)+uint32(**(**uint8_t)(__ccgo_up(u_ptr + uintptr(x))))*alpha2)*libc.Uint32FromInt32(0x101) + libc.Uint32FromInt32(1024)) >> libc.Int32FromInt32(18))
  29415 					**(**uint8_t)(__ccgo_up(v_ptr + uintptr(x))) = uint8(((uint32(V0)*(libc.Uint32FromInt32(1020)-alpha2)+uint32(**(**uint8_t)(__ccgo_up(v_ptr + uintptr(x))))*alpha2)*libc.Uint32FromInt32(0x101) + libc.Uint32FromInt32(1024)) >> libc.Int32FromInt32(18))
  29416 				}
  29417 			} else {
  29418 				u_ptr = u_ptr + uintptr((*WebPPicture)(unsafe.Pointer(picture)).Fuv_stride)
  29419 				v_ptr = v_ptr + uintptr((*WebPPicture)(unsafe.Pointer(picture)).Fuv_stride)
  29420 			}
  29421 			libc.Xmemset(tls, a_ptr, int32(0xff), uint64((*WebPPicture)(unsafe.Pointer(picture)).Fwidth)) // reset alpha value to opaque
  29422 			a_ptr = a_ptr + uintptr((*WebPPicture)(unsafe.Pointer(picture)).Fa_stride)
  29423 			y_ptr = y_ptr + uintptr((*WebPPicture)(unsafe.Pointer(picture)).Fy_stride)
  29424 			goto _17
  29425 		_17:
  29426 			;
  29427 			y = y + 1
  29428 		}
  29429 	} else {
  29430 		argb = (*WebPPicture)(unsafe.Pointer(picture)).Fargb
  29431 		background = MakeARGB32(tls, red, green, blue)
  29432 		y = 0
  29433 		for {
  29434 			if !(y < (*WebPPicture)(unsafe.Pointer(picture)).Fheight) {
  29435 				break
  29436 			}
  29437 			x = 0
  29438 			for {
  29439 				if !(x < (*WebPPicture)(unsafe.Pointer(picture)).Fwidth) {
  29440 					break
  29441 				}
  29442 				alpha3 = int32(**(**uint32_t)(__ccgo_up(argb + uintptr(x)*4)) >> libc.Int32FromInt32(24) & uint32(0xff))
  29443 				if alpha3 != int32(0xff) {
  29444 					if alpha3 > 0 {
  29445 						r3 = int32(**(**uint32_t)(__ccgo_up(argb + uintptr(x)*4)) >> libc.Int32FromInt32(16) & uint32(0xff))
  29446 						g3 = int32(**(**uint32_t)(__ccgo_up(argb + uintptr(x)*4)) >> libc.Int32FromInt32(8) & uint32(0xff))
  29447 						b3 = int32(**(**uint32_t)(__ccgo_up(argb + uintptr(x)*4)) >> libc.Int32FromInt32(0) & uint32(0xff))
  29448 						r3 = ((red*(int32(255)-alpha3)+r3*alpha3)*int32(0x101) + int32(256)) >> int32(16)
  29449 						g3 = ((green*(int32(255)-alpha3)+g3*alpha3)*int32(0x101) + int32(256)) >> int32(16)
  29450 						b3 = ((blue*(int32(255)-alpha3)+b3*alpha3)*int32(0x101) + int32(256)) >> int32(16)
  29451 						**(**uint32_t)(__ccgo_up(argb + uintptr(x)*4)) = MakeARGB32(tls, r3, g3, b3)
  29452 					} else {
  29453 						**(**uint32_t)(__ccgo_up(argb + uintptr(x)*4)) = background
  29454 					}
  29455 				}
  29456 				goto _22
  29457 			_22:
  29458 				;
  29459 				x = x + 1
  29460 			}
  29461 			argb = argb + uintptr((*WebPPicture)(unsafe.Pointer(picture)).Fargb_stride)*4
  29462 			goto _21
  29463 		_21:
  29464 			;
  29465 			y = y + 1
  29466 		}
  29467 	}
  29468 }
  29469 
  29470 const ARGB_BLACK1 = 4278190080
  29471 const SIZE_MAX12 = "_UI64_MAX"
  29472 
  29473 //------------------------------------------------------------------------------
  29474 
  29475 // Copyright 2012 Google Inc. All Rights Reserved.
  29476 //
  29477 // Use of this source code is governed by a BSD-style license
  29478 // that can be found in the COPYING file in the root of the source
  29479 // tree. An additional intellectual property rights grant can be found
  29480 // in the file PATENTS. All contributing project authors may
  29481 // be found in the AUTHORS file in the root of the source tree.
  29482 // -----------------------------------------------------------------------------
  29483 //
  29484 // Misc. common utility functions
  29485 //
  29486 // Authors: Skal (pascal.massimino@gmail.com)
  29487 //          Urvang (urvang@google.com)
  29488 
  29489 // Copyright 2011 Google Inc. All Rights Reserved.
  29490 //
  29491 // Use of this source code is governed by a BSD-style license
  29492 // that can be found in the COPYING file in the root of the source
  29493 // tree. An additional intellectual property rights grant can be found
  29494 // in the file PATENTS. All contributing project authors may
  29495 // be found in the AUTHORS file in the root of the source tree.
  29496 // -----------------------------------------------------------------------------
  29497 //
  29498 //   WebP encoder: main interface
  29499 //
  29500 // Author: Skal (pascal.massimino@gmail.com)
  29501 
  29502 // Copyright 2012 Google Inc. All Rights Reserved.
  29503 //
  29504 // Use of this source code is governed by a BSD-style license
  29505 // that can be found in the COPYING file in the root of the source
  29506 // tree. An additional intellectual property rights grant can be found
  29507 // in the file PATENTS. All contributing project authors may
  29508 // be found in the AUTHORS file in the root of the source tree.
  29509 // -----------------------------------------------------------------------------
  29510 //
  29511 //  Internal header for constants related to WebP file format.
  29512 //
  29513 // Author: Urvang (urvang@google.com)
  29514 
  29515 // Copyright 2010 Google Inc. All Rights Reserved.
  29516 //
  29517 // Use of this source code is governed by a BSD-style license
  29518 // that can be found in the COPYING file in the root of the source
  29519 // tree. An additional intellectual property rights grant can be found
  29520 // in the file PATENTS. All contributing project authors may
  29521 // be found in the AUTHORS file in the root of the source tree.
  29522 // -----------------------------------------------------------------------------
  29523 //
  29524 //  Common types + memory wrappers
  29525 //
  29526 // Author: Skal (pascal.massimino@gmail.com)
  29527 
  29528 var kSpatialPredictorBias = libc.Int64FromInt64(15) << libc.Int32FromInt32(LOG_2_PRECISION_BITS)
  29529 var kPredLowEffort = int32(11)
  29530 var kMaskAlpha = uint32(0xff000000)
  29531 var kNumPredModes = int32(14)
  29532 
  29533 // C documentation
  29534 //
  29535 //	// Mostly used to reduce code size + readability
  29536 func GetMin(tls *libc.TLS, a int32, b int32) (r int32) {
  29537 	var v1 int32
  29538 	_ = v1
  29539 	if a > b {
  29540 		v1 = b
  29541 	} else {
  29542 		v1 = a
  29543 	}
  29544 	return v1
  29545 }
  29546 
  29547 func GetMax(tls *libc.TLS, a int32, b int32) (r int32) {
  29548 	var v1 int32
  29549 	_ = v1
  29550 	if a < b {
  29551 		v1 = b
  29552 	} else {
  29553 		v1 = a
  29554 	}
  29555 	return v1
  29556 }
  29557 
  29558 //------------------------------------------------------------------------------
  29559 // Methods to calculate Entropy (Shannon).
  29560 
  29561 // C documentation
  29562 //
  29563 //	// Compute a bias for prediction entropy using a global heuristic to favor
  29564 //	// values closer to 0. Hence the final negative sign.
  29565 //	// 'exp_val' has a scaling factor of 1/100.
  29566 func PredictionCostBias(tls *libc.TLS, counts uintptr, weight_0 uint64_t, exp_val uint64_t) (r int64_t) {
  29567 	var bits, exp_decay_factor uint64_t
  29568 	var i, significant_symbols int32
  29569 	var v6 int64
  29570 	var v2, v3, v4 int64_t
  29571 	_, _, _, _, _, _, _, _ = bits, exp_decay_factor, i, significant_symbols, v2, v3, v4, v6
  29572 	significant_symbols = libc.Int32FromInt32(256) >> libc.Int32FromInt32(4)
  29573 	exp_decay_factor = uint64(6) // has a scaling factor of 1/10
  29574 	bits = weight_0 * uint64(**(**uint32_t)(__ccgo_up(counts))) << int32(LOG_2_PRECISION_BITS)
  29575 	exp_val = exp_val << uint64(LOG_2_PRECISION_BITS)
  29576 	i = int32(1)
  29577 	for {
  29578 		if !(i < significant_symbols) {
  29579 			break
  29580 		}
  29581 		v2 = int64(exp_val * uint64(**(**uint32_t)(__ccgo_up(counts + uintptr(i)*4))+**(**uint32_t)(__ccgo_up(counts + uintptr(int32(256)-i)*4))))
  29582 		v3 = int64(100)
  29583 		if libc.BoolInt32(v2 < 0) == libc.BoolInt32(v3 < 0) {
  29584 			v6 = (v2 + v3/int64(2)) / v3
  29585 		} else {
  29586 			v6 = (v2 - v3/int64(2)) / v3
  29587 		}
  29588 		v4 = v6
  29589 		goto _5
  29590 	_5:
  29591 		bits = bits + uint64(v4)
  29592 		v2 = int64(exp_decay_factor * exp_val)
  29593 		v3 = int64(10)
  29594 		if libc.BoolInt32(v2 < 0) == libc.BoolInt32(v3 < 0) {
  29595 			v6 = (v2 + v3/int64(2)) / v3
  29596 		} else {
  29597 			v6 = (v2 - v3/int64(2)) / v3
  29598 		}
  29599 		v4 = v6
  29600 		goto _10
  29601 	_10:
  29602 		exp_val = uint64(v4)
  29603 		goto _1
  29604 	_1:
  29605 		;
  29606 		i = i + 1
  29607 	}
  29608 	v2 = int64(bits)
  29609 	v3 = int64(10)
  29610 	if libc.BoolInt32(v2 < 0) == libc.BoolInt32(v3 < 0) {
  29611 		v6 = (v2 + v3/int64(2)) / v3
  29612 	} else {
  29613 		v6 = (v2 - v3/int64(2)) / v3
  29614 	}
  29615 	v4 = v6
  29616 	goto _15
  29617 _15:
  29618 	return -v4
  29619 }
  29620 
  29621 func PredictionCostSpatialHistogram(tls *libc.TLS, accumulated uintptr, tile uintptr, mode int32, left_mode int32, above_mode int32) (r int64_t) {
  29622 	var i int32
  29623 	var kExpValue uint64_t
  29624 	var retval int64_t
  29625 	_, _, _ = i, kExpValue, retval
  29626 	retval = 0
  29627 	i = 0
  29628 	for {
  29629 		if !(i < int32(4)) {
  29630 			break
  29631 		}
  29632 		kExpValue = uint64(94)
  29633 		retval = retval + PredictionCostBias(tls, tile+uintptr(i*int32(256))*4, uint64(1), kExpValue)
  29634 		// Compute the new cost if 'tile' is added to 'accumulate' but also add the
  29635 		// cost of the current histogram to guide the spatial predictor selection.
  29636 		// Basically, favor low entropy, locally and globally.
  29637 		retval = retval + int64((*(*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))
  29638 		goto _1
  29639 	_1:
  29640 		;
  29641 		i = i + 1
  29642 	}
  29643 	// Favor keeping the areas locally similar.
  29644 	if mode == left_mode {
  29645 		retval = retval - kSpatialPredictorBias
  29646 	}
  29647 	if mode == above_mode {
  29648 		retval = retval - kSpatialPredictorBias
  29649 	}
  29650 	return retval
  29651 }
  29652 
  29653 func UpdateHisto(tls *libc.TLS, histo_argb uintptr, argb uint32_t) {
  29654 	**(**uint32_t)(__ccgo_up(histo_argb + uintptr(uint32(libc.Int32FromInt32(0)*libc.Int32FromInt32(256))+argb>>libc.Int32FromInt32(24))*4)) = **(**uint32_t)(__ccgo_up(histo_argb + uintptr(uint32(libc.Int32FromInt32(0)*libc.Int32FromInt32(256))+argb>>libc.Int32FromInt32(24))*4)) + 1
  29655 	**(**uint32_t)(__ccgo_up(histo_argb + uintptr(uint32(libc.Int32FromInt32(1)*libc.Int32FromInt32(256))+argb>>libc.Int32FromInt32(16)&uint32(0xff))*4)) = **(**uint32_t)(__ccgo_up(histo_argb + uintptr(uint32(libc.Int32FromInt32(1)*libc.Int32FromInt32(256))+argb>>libc.Int32FromInt32(16)&uint32(0xff))*4)) + 1
  29656 	**(**uint32_t)(__ccgo_up(histo_argb + uintptr(uint32(libc.Int32FromInt32(2)*libc.Int32FromInt32(256))+argb>>libc.Int32FromInt32(8)&uint32(0xff))*4)) = **(**uint32_t)(__ccgo_up(histo_argb + uintptr(uint32(libc.Int32FromInt32(2)*libc.Int32FromInt32(256))+argb>>libc.Int32FromInt32(8)&uint32(0xff))*4)) + 1
  29657 	**(**uint32_t)(__ccgo_up(histo_argb + uintptr(uint32(libc.Int32FromInt32(3)*libc.Int32FromInt32(256))+argb&uint32(0xff))*4)) = **(**uint32_t)(__ccgo_up(histo_argb + uintptr(uint32(libc.Int32FromInt32(3)*libc.Int32FromInt32(256))+argb&uint32(0xff))*4)) + 1
  29658 }
  29659 
  29660 //------------------------------------------------------------------------------
  29661 // Spatial transform functions.
  29662 
  29663 func PredictBatch(tls *libc.TLS, mode int32, x_start int32, y int32, num_pixels int32, current uintptr, upper uintptr, out uintptr) {
  29664 	if x_start == 0 {
  29665 		if y == 0 {
  29666 			// ARGB_BLACK.
  29667 			(*(*func(*libc.TLS, uintptr, uintptr, int32, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8LPredictorsSub[libc.Int32FromInt32(0)]})))(tls, current, libc.UintptrFromInt32(0), int32(1), out)
  29668 		} else {
  29669 			// Top one.
  29670 			(*(*func(*libc.TLS, uintptr, uintptr, int32, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8LPredictorsSub[libc.Int32FromInt32(2)]})))(tls, current, upper, int32(1), out)
  29671 		}
  29672 		x_start = x_start + 1
  29673 		out += 4
  29674 		num_pixels = num_pixels - 1
  29675 	}
  29676 	if y == 0 {
  29677 		// Left one.
  29678 		(*(*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)
  29679 	} else {
  29680 		(*(*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)
  29681 	}
  29682 }
  29683 
  29684 func MaxDiffBetweenPixels(tls *libc.TLS, p1 uint32_t, p2 uint32_t) (r int32) {
  29685 	var diff_a, diff_b, diff_g, diff_r int32
  29686 	_, _, _, _ = diff_a, diff_b, diff_g, diff_r
  29687 	diff_a = libc.Xabs(tls, int32(p1>>libc.Int32FromInt32(24))-int32(p2>>libc.Int32FromInt32(24)))
  29688 	diff_r = libc.Xabs(tls, int32(p1>>libc.Int32FromInt32(16)&libc.Uint32FromInt32(0xff))-int32(p2>>libc.Int32FromInt32(16)&libc.Uint32FromInt32(0xff)))
  29689 	diff_g = libc.Xabs(tls, int32(p1>>libc.Int32FromInt32(8)&libc.Uint32FromInt32(0xff))-int32(p2>>libc.Int32FromInt32(8)&libc.Uint32FromInt32(0xff)))
  29690 	diff_b = libc.Xabs(tls, int32(p1&libc.Uint32FromInt32(0xff))-int32(p2&libc.Uint32FromInt32(0xff)))
  29691 	return GetMax(tls, GetMax(tls, diff_a, diff_r), GetMax(tls, diff_g, diff_b))
  29692 }
  29693 
  29694 func MaxDiffAroundPixel(tls *libc.TLS, current uint32_t, up uint32_t, down uint32_t, left uint32_t, right uint32_t) (r int32) {
  29695 	var diff_down, diff_left, diff_right, diff_up int32
  29696 	_, _, _, _ = diff_down, diff_left, diff_right, diff_up
  29697 	diff_up = MaxDiffBetweenPixels(tls, current, up)
  29698 	diff_down = MaxDiffBetweenPixels(tls, current, down)
  29699 	diff_left = MaxDiffBetweenPixels(tls, current, left)
  29700 	diff_right = MaxDiffBetweenPixels(tls, current, right)
  29701 	return GetMax(tls, GetMax(tls, diff_up, diff_down), GetMax(tls, diff_left, diff_right))
  29702 }
  29703 
  29704 func AddGreenToBlueAndRed(tls *libc.TLS, argb uint32_t) (r uint32_t) {
  29705 	var green, red_blue uint32_t
  29706 	_, _ = green, red_blue
  29707 	green = argb >> libc.Int32FromInt32(8) & uint32(0xff)
  29708 	red_blue = argb & uint32(0x00ff00ff)
  29709 	red_blue = red_blue + (green<<libc.Int32FromInt32(16) | green)
  29710 	red_blue = red_blue & uint32(0x00ff00ff)
  29711 	return argb&uint32(0xff00ff00) | red_blue
  29712 }
  29713 
  29714 func MaxDiffsForRow(tls *libc.TLS, width int32, stride int32, argb uintptr, max_diffs uintptr, used_subtract_green int32) {
  29715 	var current, down, left, right, up uint32_t
  29716 	var x int32
  29717 	_, _, _, _, _, _ = current, down, left, right, up, x
  29718 	if width <= int32(2) {
  29719 		return
  29720 	}
  29721 	current = **(**uint32_t)(__ccgo_up(argb))
  29722 	right = **(**uint32_t)(__ccgo_up(argb + 1*4))
  29723 	if used_subtract_green != 0 {
  29724 		current = AddGreenToBlueAndRed(tls, current)
  29725 		right = AddGreenToBlueAndRed(tls, right)
  29726 	}
  29727 	// max_diffs[0] and max_diffs[width - 1] are never used.
  29728 	x = int32(1)
  29729 	for {
  29730 		if !(x < width-int32(1)) {
  29731 			break
  29732 		}
  29733 		up = **(**uint32_t)(__ccgo_up(argb + uintptr(-stride+x)*4))
  29734 		down = **(**uint32_t)(__ccgo_up(argb + uintptr(stride+x)*4))
  29735 		left = current
  29736 		current = right
  29737 		right = **(**uint32_t)(__ccgo_up(argb + uintptr(x+int32(1))*4))
  29738 		if used_subtract_green != 0 {
  29739 			up = AddGreenToBlueAndRed(tls, up)
  29740 			down = AddGreenToBlueAndRed(tls, down)
  29741 			right = AddGreenToBlueAndRed(tls, right)
  29742 		}
  29743 		**(**uint8_t)(__ccgo_up(max_diffs + uintptr(x))) = uint8(MaxDiffAroundPixel(tls, current, up, down, left, right))
  29744 		goto _1
  29745 	_1:
  29746 		;
  29747 		x = x + 1
  29748 	}
  29749 }
  29750 
  29751 // C documentation
  29752 //
  29753 //	// Quantize the difference between the actual component value and its prediction
  29754 //	// to a multiple of quantization, working modulo 256, taking care not to cross
  29755 //	// a boundary (inclusive upper limit).
  29756 func NearLosslessComponent(tls *libc.TLS, value uint8_t, predict uint8_t, boundary uint8_t, quantization int32) (r uint8_t) {
  29757 	var bias, boundary_residual, lower, residual, upper int32
  29758 	_, _, _, _, _ = bias, boundary_residual, lower, residual, upper
  29759 	residual = (int32(value) - int32(predict)) & int32(0xff)
  29760 	boundary_residual = (int32(boundary) - int32(predict)) & int32(0xff)
  29761 	lower = residual & ^(quantization - libc.Int32FromInt32(1))
  29762 	upper = lower + quantization
  29763 	// Resolve ties towards a value closer to the prediction (i.e. towards lower
  29764 	// if value comes after prediction and towards upper otherwise).
  29765 	bias = libc.BoolInt32((int32(boundary)-int32(value))&int32(0xff) < boundary_residual)
  29766 	if residual-lower < upper-residual+bias {
  29767 		// lower is closer to residual than upper.
  29768 		if residual > boundary_residual && lower <= boundary_residual {
  29769 			// Halve quantization step to avoid crossing boundary. This midpoint is
  29770 			// on the same side of boundary as residual because midpoint >= residual
  29771 			// (since lower is closer than upper) and residual is above the boundary.
  29772 			return uint8(lower + quantization>>int32(1))
  29773 		}
  29774 		return uint8(lower)
  29775 	} else {
  29776 		// upper is closer to residual than lower.
  29777 		if residual <= boundary_residual && upper > boundary_residual {
  29778 			// Halve quantization step to avoid crossing boundary. This midpoint is
  29779 			// on the same side of boundary as residual because midpoint <= residual
  29780 			// (since upper is closer than lower) and residual is below the boundary.
  29781 			return uint8(lower + quantization>>int32(1))
  29782 		}
  29783 		return uint8(upper & int32(0xff))
  29784 	}
  29785 	return r
  29786 }
  29787 
  29788 func NearLosslessDiff(tls *libc.TLS, a uint8_t, b uint8_t) (r uint8_t) {
  29789 	return uint8((int32(a) - int32(b)) & libc.Int32FromInt32(0xff))
  29790 }
  29791 
  29792 // C documentation
  29793 //
  29794 //	// Quantize every component of the difference between the actual pixel value and
  29795 //	// its prediction to a multiple of a quantization (a power of 2, not larger than
  29796 //	// max_quantization which is a power of 2, smaller than max_diff). Take care if
  29797 //	// value and predict have undergone subtract green, which means that red and
  29798 //	// blue are represented as offsets from green.
  29799 func NearLossless1(tls *libc.TLS, value uint32_t, predict uint32_t, max_quantization int32, max_diff int32, used_subtract_green int32) (r1 uint32_t) {
  29800 	var a1, b1, g, green_diff, new_green, r uint8_t
  29801 	var alpha_and_green, red_and_blue, v1, v2, v3 uint32_t
  29802 	var quantization int32
  29803 	_, _, _, _, _, _, _, _, _, _, _, _ = a1, alpha_and_green, b1, g, green_diff, new_green, quantization, r, red_and_blue, v1, v2, v3
  29804 	new_green = uint8(0)
  29805 	green_diff = uint8(0)
  29806 	if max_diff <= int32(2) {
  29807 		v1 = value
  29808 		v2 = predict
  29809 		alpha_and_green = uint32(0x00ff00ff) + v1&uint32(0xff00ff00) - v2&uint32(0xff00ff00)
  29810 		red_and_blue = uint32(0xff00ff00) + v1&uint32(0x00ff00ff) - v2&uint32(0x00ff00ff)
  29811 		v3 = alpha_and_green&uint32(0xff00ff00) | red_and_blue&uint32(0x00ff00ff)
  29812 		goto _4
  29813 	_4:
  29814 		return v3
  29815 	}
  29816 	quantization = max_quantization
  29817 	for quantization >= max_diff {
  29818 		quantization = quantization >> int32(1)
  29819 	}
  29820 	if value>>libc.Int32FromInt32(24) == uint32(0) || value>>libc.Int32FromInt32(24) == uint32(0xff) {
  29821 		// Preserve transparency of fully transparent or fully opaque pixels.
  29822 		a1 = NearLosslessDiff(tls, uint8(value>>libc.Int32FromInt32(24)&uint32(0xff)), uint8(predict>>libc.Int32FromInt32(24)&uint32(0xff)))
  29823 	} else {
  29824 		a1 = NearLosslessComponent(tls, uint8(value>>int32(24)), uint8(predict>>int32(24)), uint8(0xff), quantization)
  29825 	}
  29826 	g = NearLosslessComponent(tls, uint8(value>>libc.Int32FromInt32(8)&uint32(0xff)), uint8(predict>>libc.Int32FromInt32(8)&uint32(0xff)), uint8(0xff), quantization)
  29827 	if used_subtract_green != 0 {
  29828 		// The green offset will be added to red and blue components during decoding
  29829 		// to obtain the actual red and blue values.
  29830 		new_green = uint8((predict>>libc.Int32FromInt32(8) + uint32(g)) & uint32(0xff))
  29831 		// The amount by which green has been adjusted during quantization. It is
  29832 		// subtracted from red and blue for compensation, to avoid accumulating two
  29833 		// quantization errors in them.
  29834 		green_diff = NearLosslessDiff(tls, new_green, uint8(value>>libc.Int32FromInt32(8)&uint32(0xff)))
  29835 	}
  29836 	r = NearLosslessComponent(tls, NearLosslessDiff(tls, uint8(value>>libc.Int32FromInt32(16)&uint32(0xff)), green_diff), uint8(predict>>libc.Int32FromInt32(16)&uint32(0xff)), uint8(int32(0xff)-int32(new_green)), quantization)
  29837 	b1 = NearLosslessComponent(tls, NearLosslessDiff(tls, uint8(value&uint32(0xff)), green_diff), uint8(predict&uint32(0xff)), uint8(int32(0xff)-int32(new_green)), quantization)
  29838 	return uint32(a1)<<libc.Int32FromInt32(24) | uint32(r)<<libc.Int32FromInt32(16) | uint32(g)<<libc.Int32FromInt32(8) | uint32(b1)
  29839 }
  29840 
  29841 // C documentation
  29842 //
  29843 //	// Stores the difference between the pixel and its prediction in "out".
  29844 //	// In case of a lossy encoding, updates the source image to avoid propagating
  29845 //	// the deviation further to pixels which depend on the current pixel for their
  29846 //	// predictions.
  29847 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) {
  29848 	var alpha_and_green, alpha_and_green1, predict, red_and_blue, red_and_blue1, residual, v3, v4, v5 uint32_t
  29849 	var pred_func VP8LPredictorFunc
  29850 	var x int32
  29851 	var v2 uint32
  29852 	_, _, _, _, _, _, _, _, _, _, _, _ = alpha_and_green, alpha_and_green1, pred_func, predict, red_and_blue, red_and_blue1, residual, x, v2, v3, v4, v5
  29853 	if exact != 0 {
  29854 		PredictBatch(tls, mode, x_start, y, x_end-x_start, current_row, upper_row, out)
  29855 	} else {
  29856 		pred_func = VP8LPredictors[mode]
  29857 		x = x_start
  29858 		for {
  29859 			if !(x < x_end) {
  29860 				break
  29861 			}
  29862 			if y == 0 {
  29863 				if x == 0 {
  29864 					v2 = uint32(ARGB_BLACK1)
  29865 				} else {
  29866 					v2 = **(**uint32_t)(__ccgo_up(current_row + uintptr(x-int32(1))*4))
  29867 				}
  29868 				predict = v2 // Left.
  29869 			} else {
  29870 				if x == 0 {
  29871 					predict = **(**uint32_t)(__ccgo_up(upper_row + uintptr(x)*4)) // Top.
  29872 				} else {
  29873 					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)
  29874 				}
  29875 			}
  29876 			if max_quantization == int32(1) || mode == 0 || y == 0 || y == height-int32(1) || x == 0 || x == width-int32(1) {
  29877 				v3 = **(**uint32_t)(__ccgo_up(current_row + uintptr(x)*4))
  29878 				v4 = predict
  29879 				alpha_and_green1 = uint32(0x00ff00ff) + v3&uint32(0xff00ff00) - v4&uint32(0xff00ff00)
  29880 				red_and_blue1 = uint32(0xff00ff00) + v3&uint32(0x00ff00ff) - v4&uint32(0x00ff00ff)
  29881 				v5 = alpha_and_green1&uint32(0xff00ff00) | red_and_blue1&uint32(0x00ff00ff)
  29882 				goto _6
  29883 			_6:
  29884 				residual = v5
  29885 			} else {
  29886 				residual = NearLossless1(tls, **(**uint32_t)(__ccgo_up(current_row + uintptr(x)*4)), predict, max_quantization, int32(**(**uint8_t)(__ccgo_up(max_diffs + uintptr(x)))), used_subtract_green)
  29887 				// Update the source image.
  29888 				v3 = predict
  29889 				v4 = residual
  29890 				alpha_and_green = v3&uint32(0xff00ff00) + v4&uint32(0xff00ff00)
  29891 				red_and_blue = v3&uint32(0x00ff00ff) + v4&uint32(0x00ff00ff)
  29892 				v5 = alpha_and_green&uint32(0xff00ff00) | red_and_blue&uint32(0x00ff00ff)
  29893 				goto _10
  29894 			_10:
  29895 				**(**uint32_t)(__ccgo_up(current_row + uintptr(x)*4)) = v5
  29896 				// x is never 0 here so we do not need to update upper_row like below.
  29897 			}
  29898 			if **(**uint32_t)(__ccgo_up(current_row + uintptr(x)*4))&kMaskAlpha == uint32(0) {
  29899 				// If alpha is 0, cleanup RGB. We can choose the RGB values of the
  29900 				// residual for best compression. The prediction of alpha itself can be
  29901 				// non-zero and must be kept though. We choose RGB of the residual to be
  29902 				// 0.
  29903 				residual = residual & kMaskAlpha
  29904 				// Update the source image.
  29905 				**(**uint32_t)(__ccgo_up(current_row + uintptr(x)*4)) = predict & ^kMaskAlpha
  29906 				// The prediction for the rightmost pixel in a row uses the leftmost
  29907 				// pixel
  29908 				// in that row as its top-right context pixel. Hence if we change the
  29909 				// leftmost pixel of current_row, the corresponding change must be
  29910 				// applied
  29911 				// to upper_row as well where top-right context is being read from.
  29912 				if x == 0 && y != 0 {
  29913 					**(**uint32_t)(__ccgo_up(upper_row + uintptr(width)*4)) = **(**uint32_t)(__ccgo_up(current_row))
  29914 				}
  29915 			}
  29916 			**(**uint32_t)(__ccgo_up(out + uintptr(x-x_start)*4)) = residual
  29917 			goto _1
  29918 		_1:
  29919 			;
  29920 			x = x + 1
  29921 		}
  29922 	}
  29923 }
  29924 
  29925 // C documentation
  29926 //
  29927 //	// Accessors to residual histograms.
  29928 func GetHistoArgb(tls *libc.TLS, all_histos uintptr, subsampling_index int32, mode int32) (r uintptr) {
  29929 	return all_histos + uintptr((subsampling_index*kNumPredModes+mode)*(libc.Int32FromInt32(4)*libc.Int32FromInt32(256)))*4
  29930 }
  29931 
  29932 func GetHistoArgbConst(tls *libc.TLS, all_histos uintptr, subsampling_index int32, mode int32) (r uintptr) {
  29933 	return all_histos + uintptr(subsampling_index*kNumPredModes*(libc.Int32FromInt32(4)*libc.Int32FromInt32(256))+mode*(libc.Int32FromInt32(4)*libc.Int32FromInt32(256)))*4
  29934 }
  29935 
  29936 // C documentation
  29937 //
  29938 //	// Accessors to accumulated residual histogram.
  29939 func GetAccumulatedHisto(tls *libc.TLS, all_accumulated uintptr, subsampling_index int32) (r uintptr) {
  29940 	return all_accumulated + uintptr(subsampling_index*(libc.Int32FromInt32(4)*libc.Int32FromInt32(256)))*4
  29941 }
  29942 
  29943 // C documentation
  29944 //
  29945 //	// Find and store the best predictor for a tile at subsampling
  29946 //	// 'subsampling_index'.
  29947 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) {
  29948 	var above_mode, left_mode, mode int32
  29949 	var accumulated_argb, best_histo, histo_argb, modes, pred_histos uintptr
  29950 	var best_diff, cur_diff int64_t
  29951 	var best_mode uint32_t
  29952 	var v1, v2 uint32
  29953 	_, _, _, _, _, _, _, _, _, _, _, _, _ = above_mode, accumulated_argb, best_diff, best_histo, best_mode, cur_diff, histo_argb, left_mode, mode, modes, pred_histos, v1, v2
  29954 	accumulated_argb = GetAccumulatedHisto(tls, all_accumulated_argb, subsampling_index)
  29955 	modes = **(**uintptr)(__ccgo_up(all_modes + uintptr(subsampling_index)*8))
  29956 	pred_histos = all_pred_histos + uintptr(subsampling_index*kNumPredModes)*4
  29957 	if tile_x > 0 {
  29958 		v1 = **(**uint32_t)(__ccgo_up(modes + uintptr(tile_y*tiles_per_row+tile_x-int32(1))*4)) >> libc.Int32FromInt32(8) & uint32(0xff)
  29959 	} else {
  29960 		v1 = uint32(0xff)
  29961 	}
  29962 	// Prediction modes of the left and above neighbor tiles.
  29963 	left_mode = int32(v1)
  29964 	if tile_y > 0 {
  29965 		v2 = **(**uint32_t)(__ccgo_up(modes + uintptr((tile_y-int32(1))*tiles_per_row+tile_x)*4)) >> libc.Int32FromInt32(8) & uint32(0xff)
  29966 	} else {
  29967 		v2 = uint32(0xff)
  29968 	}
  29969 	above_mode = int32(v2)
  29970 	best_diff = int64(libc.Uint64FromUint64(1)<<libc.Int32FromInt32(63) - libc.Uint64FromInt32(1))
  29971 	best_mode = uint32(0)
  29972 	best_histo = GetHistoArgbConst(tls, all_argb, 0, int32(best_mode))
  29973 	mode = 0
  29974 	for {
  29975 		if !(mode < kNumPredModes) {
  29976 			break
  29977 		}
  29978 		histo_argb = GetHistoArgbConst(tls, all_argb, subsampling_index, mode)
  29979 		cur_diff = PredictionCostSpatialHistogram(tls, accumulated_argb, histo_argb, mode, left_mode, above_mode)
  29980 		if cur_diff < best_diff {
  29981 			best_histo = histo_argb
  29982 			best_diff = cur_diff
  29983 			best_mode = uint32(mode)
  29984 		}
  29985 		goto _3
  29986 	_3:
  29987 		;
  29988 		mode = mode + 1
  29989 	}
  29990 	// Update the accumulated histogram.
  29991 	(*(*func(*libc.TLS, uintptr, uintptr, int32))(unsafe.Pointer(&struct{ uintptr }{VP8LAddVectorEq})))(tls, best_histo, accumulated_argb, libc.Int32FromInt32(4)*libc.Int32FromInt32(256))
  29992 	**(**uint32_t)(__ccgo_up(modes + uintptr(tile_y*tiles_per_row+tile_x)*4)) = uint32(ARGB_BLACK1) | best_mode<<libc.Int32FromInt32(8)
  29993 	**(**uint32_t)(__ccgo_up(pred_histos + uintptr(best_mode)*4)) = **(**uint32_t)(__ccgo_up(pred_histos + uintptr(best_mode)*4)) + 1
  29994 }
  29995 
  29996 // C documentation
  29997 //
  29998 //	// Computes the residuals for the different predictors.
  29999 //	// If max_quantization > 1, assumes that near lossless processing will be
  30000 //	// applied, quantizing residuals to multiples of quantization levels up to
  30001 //	// max_quantization (the actual quantization level depends on smoothness near
  30002 //	// the given pixel).
  30003 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) {
  30004 	bp := tls.Alloc(2048)
  30005 	defer tls.Free(2048)
  30006 	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
  30007 	var current_row, histo_argb, max_diffs, super_histo, tmp, upper_row uintptr
  30008 	var subsampling_index uint32_t
  30009 	var _ /* residuals at bp+0 */ [512]uint32_t
  30010 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  30011 	start_x = tile_x << min_bits
  30012 	start_y = tile_y << min_bits
  30013 	tile_size = int32(1) << min_bits
  30014 	max_y = GetMin(tls, tile_size, height-start_y)
  30015 	max_x = GetMin(tls, tile_size, width-start_x)
  30016 	// Whether there exist columns just outside the tile.
  30017 	have_left = libc.BoolInt32(start_x > libc.Int32FromInt32(0))
  30018 	// Position and size of the strip covering the tile and adjacent columns if
  30019 	// they exist.
  30020 	context_start_x = start_x - have_left
  30021 	context_width = max_x + have_left + libc.BoolInt32(max_x < width-start_x)
  30022 	// The width of upper_row and current_row is one pixel larger than image width
  30023 	// to allow the top right pixel to point to the leftmost pixel of the next row
  30024 	// when at the right edge.
  30025 	upper_row = argb_scratch
  30026 	current_row = upper_row + uintptr(width)*4 + uintptr(1)*4
  30027 	max_diffs = current_row + uintptr(width)*4 + libc.UintptrFromInt32(1)*4
  30028 	mode = 0
  30029 	for {
  30030 		if !(mode < kNumPredModes) {
  30031 			break
  30032 		}
  30033 		histo_argb = GetHistoArgb(tls, all_argb, 0, mode)
  30034 		if start_y > 0 {
  30035 			// Read the row above the tile which will become the first upper_row.
  30036 			// Include a pixel to the left if it exists; include a pixel to the right
  30037 			// in all cases (wrapping to the leftmost pixel of the next row if it does
  30038 			// not exist).
  30039 			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)*uint64(max_x+have_left+libc.Int32FromInt32(1)))
  30040 		}
  30041 		relative_y = 0
  30042 		for {
  30043 			if !(relative_y < max_y) {
  30044 				break
  30045 			}
  30046 			y = start_y + relative_y
  30047 			tmp = upper_row
  30048 			upper_row = current_row
  30049 			current_row = tmp
  30050 			// Read current_row. Include a pixel to the left if it exists; include a
  30051 			// pixel to the right in all cases except at the bottom right corner of
  30052 			// the image (wrapping to the leftmost pixel of the next row if it does
  30053 			// not exist in the current row).
  30054 			libc.Xmemcpy(tls, current_row+uintptr(context_start_x)*4, argb+uintptr(y*width)*4+uintptr(context_start_x)*4, uint64(4)*uint64(max_x+have_left+libc.BoolInt32(y+libc.Int32FromInt32(1) < height)))
  30055 			if max_quantization > int32(1) && y >= int32(1) && y+int32(1) < height {
  30056 				MaxDiffsForRow(tls, context_width, width, argb+uintptr(y*width)*4+uintptr(context_start_x)*4, max_diffs+uintptr(context_start_x), used_subtract_green)
  30057 			}
  30058 			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)
  30059 			relative_x = 0
  30060 			for {
  30061 				if !(relative_x < max_x) {
  30062 					break
  30063 				}
  30064 				UpdateHisto(tls, histo_argb, (**(**[512]uint32_t)(__ccgo_up(bp)))[relative_x])
  30065 				goto _3
  30066 			_3:
  30067 				;
  30068 				relative_x = relative_x + 1
  30069 			}
  30070 			if update_up_to_index > uint32(0) {
  30071 				subsampling_index = uint32(1)
  30072 				for {
  30073 					if !(subsampling_index <= update_up_to_index) {
  30074 						break
  30075 					}
  30076 					super_histo = GetHistoArgb(tls, all_argb, int32(subsampling_index), mode)
  30077 					relative_x = 0
  30078 					for {
  30079 						if !(relative_x < max_x) {
  30080 							break
  30081 						}
  30082 						UpdateHisto(tls, super_histo, (**(**[512]uint32_t)(__ccgo_up(bp)))[relative_x])
  30083 						goto _5
  30084 					_5:
  30085 						;
  30086 						relative_x = relative_x + 1
  30087 					}
  30088 					goto _4
  30089 				_4:
  30090 					;
  30091 					subsampling_index = subsampling_index + 1
  30092 				}
  30093 			}
  30094 			goto _2
  30095 		_2:
  30096 			;
  30097 			relative_y = relative_y + 1
  30098 		}
  30099 		goto _1
  30100 	_1:
  30101 		;
  30102 		mode = mode + 1
  30103 	}
  30104 }
  30105 
  30106 // C documentation
  30107 //
  30108 //	// Converts pixels of the image to residuals with respect to predictions.
  30109 //	// If max_quantization > 1, applies near lossless processing, quantizing
  30110 //	// residuals to multiples of quantization levels up to max_quantization
  30111 //	// (the actual quantization level depends on smoothness near the given pixel).
  30112 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) {
  30113 	var current_max_diffs, current_row, lower_max_diffs, tmp32, tmp8, upper_row uintptr
  30114 	var mode, tiles_per_row, x, x_end, y int32
  30115 	var v1, v2 uint32_t
  30116 	_, _, _, _, _, _, _, _, _, _, _, _, _ = current_max_diffs, current_row, lower_max_diffs, mode, tiles_per_row, tmp32, tmp8, upper_row, x, x_end, y, v1, v2
  30117 	v1 = uint32(bits)
  30118 	v2 = (uint32(width) + uint32(libc.Int32FromInt32(1)<<v1) - uint32(1)) >> v1
  30119 	goto _3
  30120 _3:
  30121 	tiles_per_row = int32(v2)
  30122 	// The width of upper_row and current_row is one pixel larger than image width
  30123 	// to allow the top right pixel to point to the leftmost pixel of the next row
  30124 	// when at the right edge.
  30125 	upper_row = argb_scratch
  30126 	current_row = upper_row + uintptr(width)*4 + uintptr(1)*4
  30127 	current_max_diffs = current_row + uintptr(width)*4 + libc.UintptrFromInt32(1)*4
  30128 	lower_max_diffs = current_max_diffs + uintptr(width)
  30129 	y = 0
  30130 	for {
  30131 		if !(y < height) {
  30132 			break
  30133 		}
  30134 		tmp32 = upper_row
  30135 		upper_row = current_row
  30136 		current_row = tmp32
  30137 		libc.Xmemcpy(tls, current_row, argb+uintptr(y*width)*4, uint64(4)*uint64(width+libc.BoolInt32(y+libc.Int32FromInt32(1) < height)))
  30138 		if low_effort != 0 {
  30139 			PredictBatch(tls, kPredLowEffort, 0, y, width, current_row, upper_row, argb+uintptr(y*width)*4)
  30140 		} else {
  30141 			if max_quantization > int32(1) {
  30142 				// Compute max_diffs for the lower row now, because that needs the
  30143 				// contents of argb for the current row, which we will overwrite with
  30144 				// residuals before proceeding with the next row.
  30145 				tmp8 = current_max_diffs
  30146 				current_max_diffs = lower_max_diffs
  30147 				lower_max_diffs = tmp8
  30148 				if y+int32(2) < height {
  30149 					MaxDiffsForRow(tls, width, width, argb+uintptr((y+int32(1))*width)*4, lower_max_diffs, used_subtract_green)
  30150 				}
  30151 			}
  30152 			x = 0
  30153 			for {
  30154 				if !(x < width) {
  30155 					break
  30156 				}
  30157 				mode = int32(**(**uint32_t)(__ccgo_up(modes + uintptr(y>>bits*tiles_per_row+x>>bits)*4)) >> libc.Int32FromInt32(8) & uint32(0xff))
  30158 				x_end = x + int32(1)<<bits
  30159 				if x_end > width {
  30160 					x_end = width
  30161 				}
  30162 				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)
  30163 				x = x_end
  30164 				goto _5
  30165 			_5:
  30166 			}
  30167 		}
  30168 		goto _4
  30169 	_4:
  30170 		;
  30171 		y = y + 1
  30172 	}
  30173 }
  30174 
  30175 // C documentation
  30176 //
  30177 //	// Checks whether 'image' can be subsampled by finding the biggest power of 2
  30178 //	// squares (defined by 'best_bits') of uniform value it is made out of.
  30179 func VP8LOptimizeSampling(tls *libc.TLS, image uintptr, full_width int32, full_height int32, bits int32, max_bits int32, best_bits_out uintptr) {
  30180 	var best_bits, height, i, is_good, is_good1, new_square_size, old_width, square_size, width, x, y int32
  30181 	var v1, v2, v4, v5 uint32_t
  30182 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = best_bits, height, i, is_good, is_good1, new_square_size, old_width, square_size, width, x, y, v1, v2, v4, v5
  30183 	v1 = uint32(bits)
  30184 	v2 = (uint32(full_width) + uint32(libc.Int32FromInt32(1)<<v1) - uint32(1)) >> v1
  30185 	goto _3
  30186 _3:
  30187 	width = int32(v2)
  30188 	v4 = uint32(bits)
  30189 	v5 = (uint32(full_height) + uint32(libc.Int32FromInt32(1)<<v4) - uint32(1)) >> v4
  30190 	goto _6
  30191 _6:
  30192 	height = int32(v5)
  30193 	best_bits = bits
  30194 	**(**int32)(__ccgo_up(best_bits_out)) = bits
  30195 	// Check rows first.
  30196 	for best_bits < max_bits {
  30197 		new_square_size = int32(1) << (best_bits + int32(1) - bits)
  30198 		is_good = int32(1)
  30199 		square_size = int32(1) << (best_bits - bits)
  30200 		y = 0
  30201 		for {
  30202 			if !(y+square_size < height) {
  30203 				break
  30204 			}
  30205 			// Check the first lines of consecutive line groups.
  30206 			if libc.Xmemcmp(tls, image+uintptr(y*width)*4, image+uintptr((y+square_size)*width)*4, uint64(width)*uint64(4)) != 0 {
  30207 				is_good = 0
  30208 				break
  30209 			}
  30210 			goto _7
  30211 		_7:
  30212 			;
  30213 			y = y + new_square_size
  30214 		}
  30215 		if is_good != 0 {
  30216 			best_bits = best_bits + 1
  30217 		} else {
  30218 			break
  30219 		}
  30220 	}
  30221 	if best_bits == bits {
  30222 		return
  30223 	}
  30224 	// Check columns.
  30225 	for best_bits > bits {
  30226 		is_good1 = int32(1)
  30227 		square_size = int32(1) << (best_bits - bits)
  30228 		y = 0
  30229 		for {
  30230 			if !(is_good1 != 0 && y < height) {
  30231 				break
  30232 			}
  30233 			x = 0
  30234 			for {
  30235 				if !(is_good1 != 0 && x < width) {
  30236 					break
  30237 				}
  30238 				i = x + int32(1)
  30239 				for {
  30240 					if !(i < GetMin(tls, x+square_size, width)) {
  30241 						break
  30242 					}
  30243 					if **(**uint32_t)(__ccgo_up(image + uintptr(y*width+i)*4)) != **(**uint32_t)(__ccgo_up(image + uintptr(y*width+x)*4)) {
  30244 						is_good1 = 0
  30245 						break
  30246 					}
  30247 					goto _10
  30248 				_10:
  30249 					;
  30250 					i = i + 1
  30251 				}
  30252 				goto _9
  30253 			_9:
  30254 				;
  30255 				x = x + square_size
  30256 			}
  30257 			goto _8
  30258 		_8:
  30259 			;
  30260 			y = y + 1
  30261 		}
  30262 		if is_good1 != 0 {
  30263 			break
  30264 		}
  30265 		best_bits = best_bits - 1
  30266 	}
  30267 	if best_bits == bits {
  30268 		return
  30269 	}
  30270 	// Subsample the image.
  30271 	old_width = width
  30272 	square_size = int32(1) << (best_bits - bits)
  30273 	v1 = uint32(best_bits)
  30274 	v2 = (uint32(full_width) + uint32(libc.Int32FromInt32(1)<<v1) - uint32(1)) >> v1
  30275 	goto _13
  30276 _13:
  30277 	width = int32(v2)
  30278 	v1 = uint32(best_bits)
  30279 	v2 = (uint32(full_height) + uint32(libc.Int32FromInt32(1)<<v1) - uint32(1)) >> v1
  30280 	goto _16
  30281 _16:
  30282 	height = int32(v2)
  30283 	y = 0
  30284 	for {
  30285 		if !(y < height) {
  30286 			break
  30287 		}
  30288 		x = 0
  30289 		for {
  30290 			if !(x < width) {
  30291 				break
  30292 			}
  30293 			**(**uint32_t)(__ccgo_up(image + uintptr(y*width+x)*4)) = **(**uint32_t)(__ccgo_up(image + uintptr(square_size*(y*old_width+x))*4))
  30294 			goto _18
  30295 		_18:
  30296 			;
  30297 			x = x + 1
  30298 		}
  30299 		goto _17
  30300 	_17:
  30301 		;
  30302 		y = y + 1
  30303 	}
  30304 	**(**int32)(__ccgo_up(best_bits_out)) = best_bits
  30305 }
  30306 
  30307 // C documentation
  30308 //
  30309 //	// Computes the best predictor image.
  30310 //	// Finds the best predictors per tile. Once done, finds the best predictor image
  30311 //	// sampling.
  30312 //	// best_bits is set to 0 in case of error.
  30313 //	// The following requires some glossary:
  30314 //	// - a tile is a square of side 2^min_bits pixels.
  30315 //	// - a super-tile of a tile is a square of side 2^bits pixels with bits in
  30316 //	// [min_bits+1, max_bits].
  30317 //	// - the max-tile of a tile is the square of 2^max_bits pixels containing it.
  30318 //	//   If this max-tile crosses the border of an image, it is cropped.
  30319 //	// - tile, super-tiles and max_tile are aligned on powers of 2 in the original
  30320 //	//   image.
  30321 //	// - coordinates for tile, super-tile, max-tile are respectively named
  30322 //	//   tile_x, super_tile_x, max_tile_x at their bit scale.
  30323 //	// - in the max-tile, a tile has local coordinates (local_tile_x, local_tile_y).
  30324 //	// The tiles are processed in the following zigzag order to complete the
  30325 //	// super-tiles as soon as possible:
  30326 //	//   1  2|  5  6
  30327 //	//   3  4|  7  8
  30328 //	// --------------
  30329 //	//   9 10| 13 14
  30330 //	//  11 12| 15 16
  30331 //	// When computing the residuals for a tile, the histogram of the above
  30332 //	// super-tile is updated. If this super-tile is finished, its histogram is used
  30333 //	// to update the histogram of the next super-tile and so on up to the max-tile.
  30334 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) {
  30335 	var accumulated, all_accumulated_argb, all_argb, all_pred_histos, raw_data uintptr
  30336 	var best_cost, cost int64_t
  30337 	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
  30338 	var max_tile_size, num_accumulated_rgb, num_argb, num_predictors, percent_start, plane int32
  30339 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  30340 	v1 = uint32(min_bits)
  30341 	v2 = (uint32(width) + uint32(libc.Int32FromInt32(1)<<v1) - uint32(1)) >> v1
  30342 	goto _3
  30343 _3:
  30344 	tiles_per_row = v2
  30345 	v4 = uint32(min_bits)
  30346 	v5 = (uint32(height) + uint32(libc.Int32FromInt32(1)<<v4) - uint32(1)) >> v4
  30347 	goto _6
  30348 _6:
  30349 	tiles_per_col = v5
  30350 	max_subsampling_index = uint32(max_bits - min_bits)
  30351 	// Compute the needed memory size for residual histograms, accumulated
  30352 	// residual histograms and predictor histograms.
  30353 	num_argb = int32((max_subsampling_index + uint32(1)) * uint32(kNumPredModes) * uint32(libc.Int32FromInt32(4)*libc.Int32FromInt32(256)))
  30354 	num_accumulated_rgb = int32((max_subsampling_index + uint32(1)) * uint32(libc.Int32FromInt32(4)*libc.Int32FromInt32(256)))
  30355 	num_predictors = int32((max_subsampling_index + uint32(1)) * uint32(kNumPredModes))
  30356 	raw_data = WebPSafeCalloc(tls, uint64(num_argb+num_accumulated_rgb+num_predictors), uint64(4))
  30357 	all_argb = raw_data
  30358 	all_accumulated_argb = all_argb + uintptr(num_argb)*4
  30359 	all_pred_histos = all_accumulated_argb + uintptr(num_accumulated_rgb)*4
  30360 	max_tile_size = int32(1) << max_subsampling_index // in tile size
  30361 	percent_start = **(**int32)(__ccgo_up(percent))
  30362 	// When using the residuals of a tile for its super-tiles, you can either:
  30363 	// - use each residual to update the histogram of the super-tile, with a cost
  30364 	//   of 4 * (1<<n)^2 increment operations (4 for the number of channels, and
  30365 	//   (1<<n)^2 for the number of pixels in the tile)
  30366 	// - use the histogram of the tile to update the histogram of the super-tile,
  30367 	//   with a cost of HISTO_SIZE (1024)
  30368 	// The first method is therefore faster until n==4. 'update_up_to_index'
  30369 	// defines the maximum subsampling_index for which the residuals should be
  30370 	// individually added to the super-tile histogram.
  30371 	update_up_to_index = uint32(GetMax(tls, GetMin(tls, int32(4), max_bits), min_bits) - min_bits)
  30372 	// Coordinates in the max-tile in tile units.
  30373 	local_tile_x = uint32(0)
  30374 	local_tile_y = uint32(0)
  30375 	max_tile_x = uint32(0)
  30376 	max_tile_y = uint32(0)
  30377 	tile_x = uint32(0)
  30378 	tile_y = uint32(0)
  30379 	**(**int32)(__ccgo_up(best_bits)) = 0
  30380 	**(**uintptr)(__ccgo_up(best_mode)) = libc.UintptrFromInt32(0)
  30381 	if raw_data == libc.UintptrFromInt32(0) {
  30382 		return
  30383 	}
  30384 	for tile_y < tiles_per_col {
  30385 		ComputeResidualsForTile(tls, width, height, int32(tile_x), int32(tile_y), min_bits, update_up_to_index, all_argb, argb_scratch, argb, max_quantization, exact, used_subtract_green)
  30386 		// Update all the super-tiles that are complete.
  30387 		subsampling_index = uint32(0)
  30388 		for int32(1) != 0 {
  30389 			super_tile_x = tile_x >> subsampling_index
  30390 			super_tile_y = tile_y >> subsampling_index
  30391 			v1 = uint32(min_bits) + subsampling_index
  30392 			v2 = (uint32(width) + uint32(libc.Int32FromInt32(1)<<v1) - uint32(1)) >> v1
  30393 			goto _9
  30394 		_9:
  30395 			super_tiles_per_row = v2
  30396 			GetBestPredictorForTile(tls, all_argb, int32(subsampling_index), int32(super_tile_x), int32(super_tile_y), int32(super_tiles_per_row), all_accumulated_argb, all_modes, all_pred_histos)
  30397 			if subsampling_index == max_subsampling_index {
  30398 				break
  30399 			}
  30400 			// Update the following super-tile histogram if it has not been updated
  30401 			// yet.
  30402 			subsampling_index = subsampling_index + 1
  30403 			if subsampling_index > update_up_to_index && subsampling_index <= max_subsampling_index {
  30404 				(*(*func(*libc.TLS, uintptr, uintptr, int32))(unsafe.Pointer(&struct{ uintptr }{VP8LAddVectorEq})))(tls, GetHistoArgbConst(tls, all_argb, int32(subsampling_index-uint32(1)), 0), GetHistoArgb(tls, all_argb, int32(subsampling_index), 0), libc.Int32FromInt32(4)*libc.Int32FromInt32(256)*kNumPredModes)
  30405 			}
  30406 			// Check whether the super-tile is not complete (if the smallest tile
  30407 			// is not at the end of a line/column or at the beginning of a super-tile
  30408 			// of size (1 << subsampling_index)).
  30409 			if !((tile_x == tiles_per_row-uint32(1) || (local_tile_x+uint32(1))%uint32(libc.Int32FromInt32(1)<<subsampling_index) == uint32(0)) && (tile_y == tiles_per_col-uint32(1) || (local_tile_y+uint32(1))%uint32(libc.Int32FromInt32(1)<<subsampling_index) == uint32(0))) {
  30410 				subsampling_index = subsampling_index - 1
  30411 				// subsampling_index now is the index of the last finished super-tile.
  30412 				break
  30413 			}
  30414 		}
  30415 		// Reset all the histograms belonging to finished tiles.
  30416 		libc.Xmemset(tls, all_argb, 0, uint64(uint32(libc.Int32FromInt32(4)*libc.Int32FromInt32(256)*kNumPredModes)*(subsampling_index+uint32(1)))*uint64(4))
  30417 		if subsampling_index == max_subsampling_index {
  30418 			// If a new max-tile is started.
  30419 			if tile_x == tiles_per_row-uint32(1) {
  30420 				max_tile_x = uint32(0)
  30421 				max_tile_y = max_tile_y + 1
  30422 			} else {
  30423 				max_tile_x = max_tile_x + 1
  30424 			}
  30425 			local_tile_x = uint32(0)
  30426 			local_tile_y = uint32(0)
  30427 		} else {
  30428 			// Proceed with the Z traversal.
  30429 			coord_x = local_tile_x >> subsampling_index
  30430 			coord_y = local_tile_y >> subsampling_index
  30431 			if tile_x == tiles_per_row-uint32(1) && coord_x%uint32(2) == uint32(0) {
  30432 				coord_y = coord_y + 1
  30433 			} else {
  30434 				if coord_x%uint32(2) == uint32(0) {
  30435 					coord_x = coord_x + 1
  30436 				} else {
  30437 					// Z traversal.
  30438 					coord_y = coord_y + 1
  30439 					coord_x = coord_x - 1
  30440 				}
  30441 			}
  30442 			local_tile_x = coord_x << subsampling_index
  30443 			local_tile_y = coord_y << subsampling_index
  30444 		}
  30445 		tile_x = max_tile_x*uint32(max_tile_size) + local_tile_x
  30446 		tile_y = max_tile_y*uint32(max_tile_size) + local_tile_y
  30447 		if tile_x == uint32(0) && !(WebPReportProgress(tls, pic, int32(uint32(percent_start)+uint32(percent_range)*tile_y/tiles_per_col), percent) != 0) {
  30448 			WebPSafeFree(tls, raw_data)
  30449 			return
  30450 		}
  30451 	}
  30452 	// Figure out the best sampling.
  30453 	best_cost = int64(libc.Uint64FromUint64(1)<<libc.Int32FromInt32(63) - libc.Uint64FromInt32(1))
  30454 	subsampling_index = uint32(0)
  30455 	for {
  30456 		if !(subsampling_index <= max_subsampling_index) {
  30457 			break
  30458 		}
  30459 		accumulated = GetAccumulatedHisto(tls, all_accumulated_argb, int32(subsampling_index))
  30460 		cost = int64((*(*func(*libc.TLS, uintptr, int32) uint64_t)(unsafe.Pointer(&struct{ uintptr }{VP8LShannonEntropy})))(tls, all_pred_histos+uintptr(subsampling_index*uint32(kNumPredModes))*4, kNumPredModes))
  30461 		plane = 0
  30462 		for {
  30463 			if !(plane < int32(4)) {
  30464 				break
  30465 			}
  30466 			cost = int64(uint64(cost) + (*(*func(*libc.TLS, uintptr, int32) uint64_t)(unsafe.Pointer(&struct{ uintptr }{VP8LShannonEntropy})))(tls, accumulated+uintptr(plane*int32(256))*4, int32(256)))
  30467 			goto _11
  30468 		_11:
  30469 			;
  30470 			plane = plane + 1
  30471 		}
  30472 		if cost < best_cost {
  30473 			best_cost = cost
  30474 			**(**int32)(__ccgo_up(best_bits)) = int32(uint32(min_bits) + subsampling_index)
  30475 			**(**uintptr)(__ccgo_up(best_mode)) = **(**uintptr)(__ccgo_up(all_modes + uintptr(subsampling_index)*8))
  30476 		}
  30477 		goto _10
  30478 	_10:
  30479 		;
  30480 		subsampling_index = subsampling_index + 1
  30481 	}
  30482 	WebPSafeFree(tls, raw_data)
  30483 	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)
  30484 }
  30485 
  30486 // C documentation
  30487 //
  30488 //	// Finds the best predictor for each tile, and converts the image to residuals
  30489 //	// with respect to predictions. If near_lossless_quality < 100, applies
  30490 //	// near lossless processing, shaving off more bits of residuals for lower
  30491 //	// qualities.
  30492 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) {
  30493 	bp := tls.Alloc(96)
  30494 	defer tls.Free(96)
  30495 	var bits, i, max_quantization, percent_start, tiles_per_col, tiles_per_col1, tiles_per_row, tiles_per_row1, v1 int32
  30496 	var modes_raw uintptr
  30497 	var num_pixels [10]uint32_t
  30498 	var sum_num_pixels, v3, v4, v6, v7 uint32_t
  30499 	var _ /* best_mode at bp+0 */ uintptr
  30500 	var _ /* modes at bp+8 */ [10]uintptr
  30501 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  30502 	percent_start = **(**int32)(__ccgo_up(percent))
  30503 	v1 = int32(5) - near_lossless_quality1/int32(20)
  30504 	goto _2
  30505 _2:
  30506 	max_quantization = int32(1) << v1
  30507 	if low_effort != 0 {
  30508 		v3 = uint32(max_bits)
  30509 		v4 = (uint32(width) + uint32(libc.Int32FromInt32(1)<<v3) - uint32(1)) >> v3
  30510 		goto _5
  30511 	_5:
  30512 		tiles_per_row = int32(v4)
  30513 		v6 = uint32(max_bits)
  30514 		v7 = (uint32(height) + uint32(libc.Int32FromInt32(1)<<v6) - uint32(1)) >> v6
  30515 		goto _8
  30516 	_8:
  30517 		tiles_per_col = int32(v7)
  30518 		i = 0
  30519 		for {
  30520 			if !(i < tiles_per_row*tiles_per_col) {
  30521 				break
  30522 			}
  30523 			**(**uint32_t)(__ccgo_up(image + uintptr(i)*4)) = uint32(ARGB_BLACK1) | uint32(kPredLowEffort<<libc.Int32FromInt32(8))
  30524 			goto _9
  30525 		_9:
  30526 			;
  30527 			i = i + 1
  30528 		}
  30529 		**(**int32)(__ccgo_up(best_bits)) = max_bits
  30530 	} else {
  30531 		sum_num_pixels = 0
  30532 		bits = min_bits
  30533 		for {
  30534 			if !(bits <= max_bits) {
  30535 				break
  30536 			}
  30537 			v3 = uint32(bits)
  30538 			v4 = (uint32(width) + uint32(libc.Int32FromInt32(1)<<v3) - uint32(1)) >> v3
  30539 			goto _13
  30540 		_13:
  30541 			tiles_per_row1 = int32(v4)
  30542 			v6 = uint32(bits)
  30543 			v7 = (uint32(height) + uint32(libc.Int32FromInt32(1)<<v6) - uint32(1)) >> v6
  30544 			goto _16
  30545 		_16:
  30546 			tiles_per_col1 = int32(v7)
  30547 			num_pixels[bits] = uint32(tiles_per_row1 * tiles_per_col1)
  30548 			sum_num_pixels = sum_num_pixels + num_pixels[bits]
  30549 			goto _10
  30550 		_10:
  30551 			;
  30552 			bits = bits + 1
  30553 		}
  30554 		modes_raw = WebPSafeMalloc(tls, uint64(sum_num_pixels), uint64(4))
  30555 		if modes_raw == libc.UintptrFromInt32(0) {
  30556 			return 0
  30557 		}
  30558 		// Have modes point to the right global memory modes_raw.
  30559 		(**(**[10]uintptr)(__ccgo_up(bp + 8)))[min_bits] = modes_raw
  30560 		bits = min_bits + int32(1)
  30561 		for {
  30562 			if !(bits <= max_bits) {
  30563 				break
  30564 			}
  30565 			(**(**[10]uintptr)(__ccgo_up(bp + 8)))[bits] = (**(**[10]uintptr)(__ccgo_up(bp + 8)))[bits-int32(1)] + uintptr(num_pixels[bits-int32(1)])*4
  30566 			goto _17
  30567 		_17:
  30568 			;
  30569 			bits = bits + 1
  30570 		}
  30571 		// Find the best sampling.
  30572 		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)
  30573 		if **(**int32)(__ccgo_up(best_bits)) == 0 {
  30574 			WebPSafeFree(tls, modes_raw)
  30575 			return 0
  30576 		}
  30577 		// Keep the best predictor image.
  30578 		v3 = uint32(**(**int32)(__ccgo_up(best_bits)))
  30579 		v4 = (uint32(width) + uint32(libc.Int32FromInt32(1)<<v3) - uint32(1)) >> v3
  30580 		goto _20
  30581 	_20:
  30582 		v6 = uint32(**(**int32)(__ccgo_up(best_bits)))
  30583 		v7 = (uint32(height) + uint32(libc.Int32FromInt32(1)<<v6) - uint32(1)) >> v6
  30584 		goto _23
  30585 	_23:
  30586 		libc.Xmemcpy(tls, image, **(**uintptr)(__ccgo_up(bp)), uint64(v4*v7)*uint64(4))
  30587 		WebPSafeFree(tls, modes_raw)
  30588 	}
  30589 	CopyImageWithPrediction(tls, width, height, **(**int32)(__ccgo_up(best_bits)), image, argb_scratch, argb, low_effort, max_quantization, exact, used_subtract_green)
  30590 	return WebPReportProgress(tls, pic, percent_start+percent_range, percent)
  30591 }
  30592 
  30593 //------------------------------------------------------------------------------
  30594 // Color transform functions.
  30595 
  30596 func MultipliersClear(tls *libc.TLS, m uintptr) {
  30597 	(*VP8LMultipliers)(unsafe.Pointer(m)).Fgreen_to_red = uint8(0)
  30598 	(*VP8LMultipliers)(unsafe.Pointer(m)).Fgreen_to_blue = uint8(0)
  30599 	(*VP8LMultipliers)(unsafe.Pointer(m)).Fred_to_blue = uint8(0)
  30600 }
  30601 
  30602 func ColorCodeToMultipliers(tls *libc.TLS, color_code uint32_t, m uintptr) {
  30603 	(*VP8LMultipliers)(unsafe.Pointer(m)).Fgreen_to_red = uint8(color_code >> libc.Int32FromInt32(0) & uint32(0xff))
  30604 	(*VP8LMultipliers)(unsafe.Pointer(m)).Fgreen_to_blue = uint8(color_code >> libc.Int32FromInt32(8) & uint32(0xff))
  30605 	(*VP8LMultipliers)(unsafe.Pointer(m)).Fred_to_blue = uint8(color_code >> libc.Int32FromInt32(16) & uint32(0xff))
  30606 }
  30607 
  30608 func MultipliersToColorCode(tls *libc.TLS, m uintptr) (r uint32_t) {
  30609 	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)
  30610 }
  30611 
  30612 func PredictionCostCrossColor(tls *libc.TLS, accumulated uintptr, counts uintptr) (r int64_t) {
  30613 	return int64((*(*func(*libc.TLS, uintptr, uintptr) uint64_t)(unsafe.Pointer(&struct{ uintptr }{VP8LCombinedShannonEntropy})))(tls, counts, accumulated)) + PredictionCostBias(tls, counts, uint64(3), kExpValue)
  30614 }
  30615 
  30616 // Favor low entropy, locally and globally.
  30617 // Favor small absolute values for PredictionCostSpatial
  30618 var kExpValue = uint64(240)
  30619 
  30620 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) {
  30621 	bp := tls.Alloc(1024)
  30622 	defer tls.Free(1024)
  30623 	var cur_diff int64_t
  30624 	var _ /* histo at bp+0 */ [256]uint32_t
  30625 	_ = cur_diff
  30626 	**(**[256]uint32_t)(__ccgo_up(bp)) = [256]uint32_t{}
  30627 	(*(*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)
  30628 	cur_diff = PredictionCostCrossColor(tls, accumulated_red_histo, bp)
  30629 	if int32(uint8(green_to_red)) == int32(prev_x.Fgreen_to_red) {
  30630 		// favor keeping the areas locally similar
  30631 		cur_diff = cur_diff - libc.Int64FromInt64(3)<<libc.Int32FromInt32(LOG_2_PRECISION_BITS)
  30632 	}
  30633 	if int32(uint8(green_to_red)) == int32(prev_y.Fgreen_to_red) {
  30634 		// favor keeping the areas locally similar
  30635 		cur_diff = cur_diff - libc.Int64FromInt64(3)<<libc.Int32FromInt32(LOG_2_PRECISION_BITS)
  30636 	}
  30637 	if green_to_red == 0 {
  30638 		cur_diff = cur_diff - libc.Int64FromInt64(3)<<libc.Int32FromInt32(LOG_2_PRECISION_BITS)
  30639 	}
  30640 	return cur_diff
  30641 }
  30642 
  30643 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) {
  30644 	var best_diff, cur_diff int64_t
  30645 	var delta, green_to_red_best, green_to_red_cur, iter, kMaxIters, offset int32
  30646 	_, _, _, _, _, _, _, _ = best_diff, cur_diff, delta, green_to_red_best, green_to_red_cur, iter, kMaxIters, offset
  30647 	kMaxIters = int32(4) + int32(7)*quality>>int32(8) // in range [4..6]
  30648 	green_to_red_best = 0
  30649 	best_diff = GetPredictionCostCrossColorRed(tls, argb, stride, tile_width, tile_height, prev_x, prev_y, green_to_red_best, accumulated_red_histo)
  30650 	iter = 0
  30651 	for {
  30652 		if !(iter < kMaxIters) {
  30653 			break
  30654 		}
  30655 		// ColorTransformDelta is a 3.5 bit fixed point, so 32 is equal to
  30656 		// one in color computation. Having initial delta here as 1 is sufficient
  30657 		// to explore the range of (-2, 2).
  30658 		delta = int32(32) >> iter
  30659 		// Try a negative and a positive delta from the best known value.
  30660 		offset = -delta
  30661 		for {
  30662 			if !(offset <= delta) {
  30663 				break
  30664 			}
  30665 			green_to_red_cur = offset + green_to_red_best
  30666 			cur_diff = GetPredictionCostCrossColorRed(tls, argb, stride, tile_width, tile_height, prev_x, prev_y, green_to_red_cur, accumulated_red_histo)
  30667 			if cur_diff < best_diff {
  30668 				best_diff = cur_diff
  30669 				green_to_red_best = green_to_red_cur
  30670 			}
  30671 			goto _2
  30672 		_2:
  30673 			;
  30674 			offset = offset + int32(2)*delta
  30675 		}
  30676 		goto _1
  30677 	_1:
  30678 		;
  30679 		iter = iter + 1
  30680 	}
  30681 	(*VP8LMultipliers)(unsafe.Pointer(best_tx)).Fgreen_to_red = uint8(green_to_red_best & libc.Int32FromInt32(0xff))
  30682 }
  30683 
  30684 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) {
  30685 	bp := tls.Alloc(1024)
  30686 	defer tls.Free(1024)
  30687 	var cur_diff int64_t
  30688 	var _ /* histo at bp+0 */ [256]uint32_t
  30689 	_ = cur_diff
  30690 	**(**[256]uint32_t)(__ccgo_up(bp)) = [256]uint32_t{}
  30691 	(*(*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)
  30692 	cur_diff = PredictionCostCrossColor(tls, accumulated_blue_histo, bp)
  30693 	if int32(uint8(green_to_blue)) == int32(prev_x.Fgreen_to_blue) {
  30694 		// favor keeping the areas locally similar
  30695 		cur_diff = cur_diff - libc.Int64FromInt64(3)<<libc.Int32FromInt32(LOG_2_PRECISION_BITS)
  30696 	}
  30697 	if int32(uint8(green_to_blue)) == int32(prev_y.Fgreen_to_blue) {
  30698 		// favor keeping the areas locally similar
  30699 		cur_diff = cur_diff - libc.Int64FromInt64(3)<<libc.Int32FromInt32(LOG_2_PRECISION_BITS)
  30700 	}
  30701 	if int32(uint8(red_to_blue)) == int32(prev_x.Fred_to_blue) {
  30702 		// favor keeping the areas locally similar
  30703 		cur_diff = cur_diff - libc.Int64FromInt64(3)<<libc.Int32FromInt32(LOG_2_PRECISION_BITS)
  30704 	}
  30705 	if int32(uint8(red_to_blue)) == int32(prev_y.Fred_to_blue) {
  30706 		// favor keeping the areas locally similar
  30707 		cur_diff = cur_diff - libc.Int64FromInt64(3)<<libc.Int32FromInt32(LOG_2_PRECISION_BITS)
  30708 	}
  30709 	if green_to_blue == 0 {
  30710 		cur_diff = cur_diff - libc.Int64FromInt64(3)<<libc.Int32FromInt32(LOG_2_PRECISION_BITS)
  30711 	}
  30712 	if red_to_blue == 0 {
  30713 		cur_diff = cur_diff - libc.Int64FromInt64(3)<<libc.Int32FromInt32(LOG_2_PRECISION_BITS)
  30714 	}
  30715 	return cur_diff
  30716 }
  30717 
  30718 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) {
  30719 	bp := tls.Alloc(16)
  30720 	defer tls.Free(16)
  30721 	var axis, delta, green_to_blue_best, green_to_blue_cur, iter, iters, red_to_blue_best, red_to_blue_cur, v1, v2 int32
  30722 	var best_diff, cur_diff int64_t
  30723 	var delta_lut [7]int8_t
  30724 	var _ /* offset at bp+0 */ [8][2]int8_t
  30725 	_, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  30726 	**(**[8][2]int8_t)(__ccgo_up(bp)) = [8][2]int8_t{
  30727 		0: {
  30728 			1: int8(-int32(1)),
  30729 		},
  30730 		1: {
  30731 			1: int8(1),
  30732 		},
  30733 		2: {
  30734 			0: int8(-int32(1)),
  30735 		},
  30736 		3: {
  30737 			0: int8(1),
  30738 		},
  30739 		4: {
  30740 			0: int8(-int32(1)),
  30741 			1: int8(-int32(1)),
  30742 		},
  30743 		5: {
  30744 			0: int8(-int32(1)),
  30745 			1: int8(1),
  30746 		},
  30747 		6: {
  30748 			0: int8(1),
  30749 			1: int8(-int32(1)),
  30750 		},
  30751 		7: {
  30752 			0: int8(1),
  30753 			1: int8(1),
  30754 		},
  30755 	}
  30756 	delta_lut = [7]int8_t{
  30757 		0: int8(16),
  30758 		1: int8(16),
  30759 		2: int8(8),
  30760 		3: int8(4),
  30761 		4: int8(2),
  30762 		5: int8(2),
  30763 		6: int8(2),
  30764 	}
  30765 	if quality < int32(25) {
  30766 		v1 = int32(1)
  30767 	} else {
  30768 		if quality > int32(50) {
  30769 			v2 = int32(7)
  30770 		} else {
  30771 			v2 = int32(4)
  30772 		}
  30773 		v1 = v2
  30774 	}
  30775 	iters = v1
  30776 	green_to_blue_best = 0
  30777 	red_to_blue_best = 0
  30778 	// Initial value at origin:
  30779 	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)
  30780 	iter = 0
  30781 	for {
  30782 		if !(iter < iters) {
  30783 			break
  30784 		}
  30785 		delta = int32(delta_lut[iter])
  30786 		axis = 0
  30787 		for {
  30788 			if !(axis < int32(8)) {
  30789 				break
  30790 			}
  30791 			green_to_blue_cur = int32(**(**int8_t)(__ccgo_up(bp + uintptr(axis)*2)))*delta + green_to_blue_best
  30792 			red_to_blue_cur = int32(**(**int8_t)(__ccgo_up(bp + uintptr(axis)*2 + 1)))*delta + red_to_blue_best
  30793 			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)
  30794 			if cur_diff < best_diff {
  30795 				best_diff = cur_diff
  30796 				green_to_blue_best = green_to_blue_cur
  30797 				red_to_blue_best = red_to_blue_cur
  30798 			}
  30799 			if quality < int32(25) && iter == int32(4) {
  30800 				// Only axis aligned diffs for lower quality.
  30801 				break // next iter.
  30802 			}
  30803 			goto _4
  30804 		_4:
  30805 			;
  30806 			axis = axis + 1
  30807 		}
  30808 		if delta == int32(2) && green_to_blue_best == 0 && red_to_blue_best == 0 {
  30809 			// Further iterations would not help.
  30810 			break // out of iter-loop.
  30811 		}
  30812 		goto _3
  30813 	_3:
  30814 		;
  30815 		iter = iter + 1
  30816 	}
  30817 	(*VP8LMultipliers)(unsafe.Pointer(best_tx)).Fgreen_to_blue = uint8(green_to_blue_best & int32(0xff))
  30818 	(*VP8LMultipliers)(unsafe.Pointer(best_tx)).Fred_to_blue = uint8(red_to_blue_best & int32(0xff))
  30819 }
  30820 
  30821 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) {
  30822 	bp := tls.Alloc(16)
  30823 	defer tls.Free(16)
  30824 	var all_x_max, all_y_max, max_tile_size, tile_height, tile_width, tile_x_offset, tile_y_offset int32
  30825 	var tile_argb uintptr
  30826 	var _ /* best_tx at bp+0 */ VP8LMultipliers
  30827 	_, _, _, _, _, _, _, _ = all_x_max, all_y_max, max_tile_size, tile_argb, tile_height, tile_width, tile_x_offset, tile_y_offset
  30828 	max_tile_size = int32(1) << bits
  30829 	tile_y_offset = tile_y * max_tile_size
  30830 	tile_x_offset = tile_x * max_tile_size
  30831 	all_x_max = GetMin(tls, tile_x_offset+max_tile_size, xsize)
  30832 	all_y_max = GetMin(tls, tile_y_offset+max_tile_size, ysize)
  30833 	tile_width = all_x_max - tile_x_offset
  30834 	tile_height = all_y_max - tile_y_offset
  30835 	tile_argb = argb + uintptr(tile_y_offset*xsize)*4 + uintptr(tile_x_offset)*4
  30836 	MultipliersClear(tls, bp)
  30837 	GetBestGreenToRed(tls, tile_argb, xsize, tile_width, tile_height, prev_x, prev_y, quality, accumulated_red_histo, bp)
  30838 	GetBestGreenRedToBlue(tls, tile_argb, xsize, tile_width, tile_height, prev_x, prev_y, quality, accumulated_blue_histo, bp)
  30839 	return **(**VP8LMultipliers)(__ccgo_up(bp))
  30840 }
  30841 
  30842 func CopyTileWithColorTransform(tls *libc.TLS, xsize int32, ysize int32, tile_x int32, tile_y int32, max_tile_size int32, _color_transform VP8LMultipliers, argb uintptr) {
  30843 	bp := tls.Alloc(16)
  30844 	defer tls.Free(16)
  30845 	*(*VP8LMultipliers)(unsafe.Pointer(bp)) = _color_transform
  30846 	var xscan, yscan, v1 int32
  30847 	_, _, _ = xscan, yscan, v1
  30848 	xscan = GetMin(tls, max_tile_size, xsize-tile_x)
  30849 	yscan = GetMin(tls, max_tile_size, ysize-tile_y)
  30850 	argb = argb + uintptr(tile_y*xsize+tile_x)*4
  30851 	for {
  30852 		v1 = yscan
  30853 		yscan = yscan - 1
  30854 		if !(v1 > 0) {
  30855 			break
  30856 		}
  30857 		(*(*func(*libc.TLS, uintptr, uintptr, int32))(unsafe.Pointer(&struct{ uintptr }{VP8LTransformColor})))(tls, bp, argb, xscan)
  30858 		argb = argb + uintptr(xsize)*4
  30859 	}
  30860 }
  30861 
  30862 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) {
  30863 	bp := tls.Alloc(2064)
  30864 	defer tls.Free(2064)
  30865 	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
  30866 	var pix, v1, v2, v4, v5 uint32_t
  30867 	var _ /* accumulated_blue_histo at bp+1024 */ [256]uint32_t
  30868 	var _ /* accumulated_red_histo at bp+0 */ [256]uint32_t
  30869 	var _ /* prev_x at bp+2049 */ VP8LMultipliers
  30870 	var _ /* prev_y at bp+2052 */ VP8LMultipliers
  30871 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  30872 	max_tile_size = int32(1) << bits
  30873 	v1 = uint32(bits)
  30874 	v2 = (uint32(width) + uint32(libc.Int32FromInt32(1)<<v1) - uint32(1)) >> v1
  30875 	goto _3
  30876 _3:
  30877 	tile_xsize = int32(v2)
  30878 	v4 = uint32(bits)
  30879 	v5 = (uint32(height) + uint32(libc.Int32FromInt32(1)<<v4) - uint32(1)) >> v4
  30880 	goto _6
  30881 _6:
  30882 	tile_ysize = int32(v5)
  30883 	percent_start = **(**int32)(__ccgo_up(percent))
  30884 	**(**[256]uint32_t)(__ccgo_up(bp)) = [256]uint32_t{}
  30885 	**(**[256]uint32_t)(__ccgo_up(bp + 1024)) = [256]uint32_t{}
  30886 	MultipliersClear(tls, bp+2052)
  30887 	MultipliersClear(tls, bp+2049)
  30888 	tile_y = 0
  30889 	for {
  30890 		if !(tile_y < tile_ysize) {
  30891 			break
  30892 		}
  30893 		tile_x = 0
  30894 		for {
  30895 			if !(tile_x < tile_xsize) {
  30896 				break
  30897 			}
  30898 			tile_x_offset = tile_x * max_tile_size
  30899 			tile_y_offset = tile_y * max_tile_size
  30900 			all_x_max = GetMin(tls, tile_x_offset+max_tile_size, width)
  30901 			all_y_max = GetMin(tls, tile_y_offset+max_tile_size, height)
  30902 			offset = tile_y*tile_xsize + tile_x
  30903 			if tile_y != 0 {
  30904 				ColorCodeToMultipliers(tls, **(**uint32_t)(__ccgo_up(image + uintptr(offset-tile_xsize)*4)), bp+2052)
  30905 			}
  30906 			**(**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)
  30907 			**(**uint32_t)(__ccgo_up(image + uintptr(offset)*4)) = MultipliersToColorCode(tls, bp+2049)
  30908 			CopyTileWithColorTransform(tls, width, height, tile_x_offset, tile_y_offset, max_tile_size, **(**VP8LMultipliers)(__ccgo_up(bp + 2049)), argb)
  30909 			// Gather accumulated histogram data.
  30910 			y = tile_y_offset
  30911 			for {
  30912 				if !(y < all_y_max) {
  30913 					break
  30914 				}
  30915 				ix = y*width + tile_x_offset
  30916 				ix_end = ix + all_x_max - tile_x_offset
  30917 				for {
  30918 					if !(ix < ix_end) {
  30919 						break
  30920 					}
  30921 					pix = **(**uint32_t)(__ccgo_up(argb + uintptr(ix)*4))
  30922 					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)) {
  30923 						goto _10 // repeated pixels are handled by backward references
  30924 					}
  30925 					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)) {
  30926 						goto _10 // repeated pixels are handled by backward references
  30927 					}
  30928 					(**(**[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
  30929 					(**(**[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
  30930 					goto _10
  30931 				_10:
  30932 					;
  30933 					ix = ix + 1
  30934 				}
  30935 				goto _9
  30936 			_9:
  30937 				;
  30938 				y = y + 1
  30939 			}
  30940 			goto _8
  30941 		_8:
  30942 			;
  30943 			tile_x = tile_x + 1
  30944 		}
  30945 		if !(WebPReportProgress(tls, pic, percent_start+percent_range*tile_y/tile_ysize, percent) != 0) {
  30946 			return 0
  30947 		}
  30948 		goto _7
  30949 	_7:
  30950 		;
  30951 		tile_y = tile_y + 1
  30952 	}
  30953 	VP8LOptimizeSampling(tls, image, width, height, bits, libc.Int32FromInt32(MIN_TRANSFORM_BITS)+libc.Int32FromInt32(1)<<libc.Int32FromInt32(NUM_TRANSFORM_BITS)-libc.Int32FromInt32(1), best_bits)
  30954 	return int32(1)
  30955 }
  30956 
  30957 const DO_TRELLIS_I16 = 1
  30958 const DO_TRELLIS_I4 = 1
  30959 const DO_TRELLIS_UV = 0
  30960 const FLATNESS_LIMIT_I16 = 0
  30961 const FLATNESS_LIMIT_I4 = 3
  30962 const FLATNESS_LIMIT_UV = 2
  30963 const FLATNESS_PENALTY = 140
  30964 const FSTRENGTH_CUTOFF = 2
  30965 const IsFlat = "IsFlat_C"
  30966 const MAX_ALPHA1 = 100
  30967 const MAX_DELTA = 1
  30968 const MAX_DQ_UV = 6
  30969 const MID_ALPHA = 64
  30970 const MIN_ALPHA = 30
  30971 const MIN_DELTA = 0
  30972 const RD_DISTO_MULT = 256
  30973 const SHARPEN_BITS = 11
  30974 const SNS_TO_DQ = 0.9
  30975 const USE_TDISTO = 1
  30976 
  30977 //------------------------------------------------------------------------------
  30978 
  30979 // Copyright 2011 Google Inc. All Rights Reserved.
  30980 //
  30981 // Use of this source code is governed by a BSD-style license
  30982 // that can be found in the COPYING file in the root of the source
  30983 // tree. An additional intellectual property rights grant can be found
  30984 // in the file PATENTS. All contributing project authors may
  30985 // be found in the AUTHORS file in the root of the source tree.
  30986 // -----------------------------------------------------------------------------
  30987 //
  30988 //   WebP encoder: internal header.
  30989 //
  30990 // Author: Skal (pascal.massimino@gmail.com)
  30991 
  30992 // Copyright 2010 Google Inc. All Rights Reserved.
  30993 //
  30994 // Use of this source code is governed by a BSD-style license
  30995 // that can be found in the COPYING file in the root of the source
  30996 // tree. An additional intellectual property rights grant can be found
  30997 // in the file PATENTS. All contributing project authors may
  30998 // be found in the AUTHORS file in the root of the source tree.
  30999 // -----------------------------------------------------------------------------
  31000 //
  31001 //  Common types + memory wrappers
  31002 //
  31003 // Author: Skal (pascal.massimino@gmail.com)
  31004 
  31005 // power-law modulation. Must be strictly less than 1.
  31006 
  31007 // number of non-zero coeffs below which we consider the block very flat
  31008 // (and apply a penalty to complex predictions)
  31009 
  31010 // #define DEBUG_BLOCK
  31011 
  31012 //------------------------------------------------------------------------------
  31013 
  31014 //------------------------------------------------------------------------------
  31015 
  31016 func clip2(tls *libc.TLS, v int32, m int32, M int32) (r int32) {
  31017 	var v1, v2 int32
  31018 	_, _ = v1, v2
  31019 	if v < m {
  31020 		v1 = m
  31021 	} else {
  31022 		if v > M {
  31023 			v2 = M
  31024 		} else {
  31025 			v2 = v
  31026 		}
  31027 		v1 = v2
  31028 	}
  31029 	return v1
  31030 }
  31031 
  31032 var kZigzag1 = [16]uint8_t{
  31033 	1:  uint8(1),
  31034 	2:  uint8(4),
  31035 	3:  uint8(8),
  31036 	4:  uint8(5),
  31037 	5:  uint8(2),
  31038 	6:  uint8(3),
  31039 	7:  uint8(6),
  31040 	8:  uint8(9),
  31041 	9:  uint8(12),
  31042 	10: uint8(13),
  31043 	11: uint8(10),
  31044 	12: uint8(7),
  31045 	13: uint8(11),
  31046 	14: uint8(14),
  31047 	15: uint8(15),
  31048 }
  31049 
  31050 var kDcTable1 = [128]uint8_t{
  31051 	0:   uint8(4),
  31052 	1:   uint8(5),
  31053 	2:   uint8(6),
  31054 	3:   uint8(7),
  31055 	4:   uint8(8),
  31056 	5:   uint8(9),
  31057 	6:   uint8(10),
  31058 	7:   uint8(10),
  31059 	8:   uint8(11),
  31060 	9:   uint8(12),
  31061 	10:  uint8(13),
  31062 	11:  uint8(14),
  31063 	12:  uint8(15),
  31064 	13:  uint8(16),
  31065 	14:  uint8(17),
  31066 	15:  uint8(17),
  31067 	16:  uint8(18),
  31068 	17:  uint8(19),
  31069 	18:  uint8(20),
  31070 	19:  uint8(20),
  31071 	20:  uint8(21),
  31072 	21:  uint8(21),
  31073 	22:  uint8(22),
  31074 	23:  uint8(22),
  31075 	24:  uint8(23),
  31076 	25:  uint8(23),
  31077 	26:  uint8(24),
  31078 	27:  uint8(25),
  31079 	28:  uint8(25),
  31080 	29:  uint8(26),
  31081 	30:  uint8(27),
  31082 	31:  uint8(28),
  31083 	32:  uint8(29),
  31084 	33:  uint8(30),
  31085 	34:  uint8(31),
  31086 	35:  uint8(32),
  31087 	36:  uint8(33),
  31088 	37:  uint8(34),
  31089 	38:  uint8(35),
  31090 	39:  uint8(36),
  31091 	40:  uint8(37),
  31092 	41:  uint8(37),
  31093 	42:  uint8(38),
  31094 	43:  uint8(39),
  31095 	44:  uint8(40),
  31096 	45:  uint8(41),
  31097 	46:  uint8(42),
  31098 	47:  uint8(43),
  31099 	48:  uint8(44),
  31100 	49:  uint8(45),
  31101 	50:  uint8(46),
  31102 	51:  uint8(46),
  31103 	52:  uint8(47),
  31104 	53:  uint8(48),
  31105 	54:  uint8(49),
  31106 	55:  uint8(50),
  31107 	56:  uint8(51),
  31108 	57:  uint8(52),
  31109 	58:  uint8(53),
  31110 	59:  uint8(54),
  31111 	60:  uint8(55),
  31112 	61:  uint8(56),
  31113 	62:  uint8(57),
  31114 	63:  uint8(58),
  31115 	64:  uint8(59),
  31116 	65:  uint8(60),
  31117 	66:  uint8(61),
  31118 	67:  uint8(62),
  31119 	68:  uint8(63),
  31120 	69:  uint8(64),
  31121 	70:  uint8(65),
  31122 	71:  uint8(66),
  31123 	72:  uint8(67),
  31124 	73:  uint8(68),
  31125 	74:  uint8(69),
  31126 	75:  uint8(70),
  31127 	76:  uint8(71),
  31128 	77:  uint8(72),
  31129 	78:  uint8(73),
  31130 	79:  uint8(74),
  31131 	80:  uint8(75),
  31132 	81:  uint8(76),
  31133 	82:  uint8(76),
  31134 	83:  uint8(77),
  31135 	84:  uint8(78),
  31136 	85:  uint8(79),
  31137 	86:  uint8(80),
  31138 	87:  uint8(81),
  31139 	88:  uint8(82),
  31140 	89:  uint8(83),
  31141 	90:  uint8(84),
  31142 	91:  uint8(85),
  31143 	92:  uint8(86),
  31144 	93:  uint8(87),
  31145 	94:  uint8(88),
  31146 	95:  uint8(89),
  31147 	96:  uint8(91),
  31148 	97:  uint8(93),
  31149 	98:  uint8(95),
  31150 	99:  uint8(96),
  31151 	100: uint8(98),
  31152 	101: uint8(100),
  31153 	102: uint8(101),
  31154 	103: uint8(102),
  31155 	104: uint8(104),
  31156 	105: uint8(106),
  31157 	106: uint8(108),
  31158 	107: uint8(110),
  31159 	108: uint8(112),
  31160 	109: uint8(114),
  31161 	110: uint8(116),
  31162 	111: uint8(118),
  31163 	112: uint8(122),
  31164 	113: uint8(124),
  31165 	114: uint8(126),
  31166 	115: uint8(128),
  31167 	116: uint8(130),
  31168 	117: uint8(132),
  31169 	118: uint8(134),
  31170 	119: uint8(136),
  31171 	120: uint8(138),
  31172 	121: uint8(140),
  31173 	122: uint8(143),
  31174 	123: uint8(145),
  31175 	124: uint8(148),
  31176 	125: uint8(151),
  31177 	126: uint8(154),
  31178 	127: uint8(157),
  31179 }
  31180 
  31181 var kAcTable1 = [128]uint16_t{
  31182 	0:   uint16(4),
  31183 	1:   uint16(5),
  31184 	2:   uint16(6),
  31185 	3:   uint16(7),
  31186 	4:   uint16(8),
  31187 	5:   uint16(9),
  31188 	6:   uint16(10),
  31189 	7:   uint16(11),
  31190 	8:   uint16(12),
  31191 	9:   uint16(13),
  31192 	10:  uint16(14),
  31193 	11:  uint16(15),
  31194 	12:  uint16(16),
  31195 	13:  uint16(17),
  31196 	14:  uint16(18),
  31197 	15:  uint16(19),
  31198 	16:  uint16(20),
  31199 	17:  uint16(21),
  31200 	18:  uint16(22),
  31201 	19:  uint16(23),
  31202 	20:  uint16(24),
  31203 	21:  uint16(25),
  31204 	22:  uint16(26),
  31205 	23:  uint16(27),
  31206 	24:  uint16(28),
  31207 	25:  uint16(29),
  31208 	26:  uint16(30),
  31209 	27:  uint16(31),
  31210 	28:  uint16(32),
  31211 	29:  uint16(33),
  31212 	30:  uint16(34),
  31213 	31:  uint16(35),
  31214 	32:  uint16(36),
  31215 	33:  uint16(37),
  31216 	34:  uint16(38),
  31217 	35:  uint16(39),
  31218 	36:  uint16(40),
  31219 	37:  uint16(41),
  31220 	38:  uint16(42),
  31221 	39:  uint16(43),
  31222 	40:  uint16(44),
  31223 	41:  uint16(45),
  31224 	42:  uint16(46),
  31225 	43:  uint16(47),
  31226 	44:  uint16(48),
  31227 	45:  uint16(49),
  31228 	46:  uint16(50),
  31229 	47:  uint16(51),
  31230 	48:  uint16(52),
  31231 	49:  uint16(53),
  31232 	50:  uint16(54),
  31233 	51:  uint16(55),
  31234 	52:  uint16(56),
  31235 	53:  uint16(57),
  31236 	54:  uint16(58),
  31237 	55:  uint16(60),
  31238 	56:  uint16(62),
  31239 	57:  uint16(64),
  31240 	58:  uint16(66),
  31241 	59:  uint16(68),
  31242 	60:  uint16(70),
  31243 	61:  uint16(72),
  31244 	62:  uint16(74),
  31245 	63:  uint16(76),
  31246 	64:  uint16(78),
  31247 	65:  uint16(80),
  31248 	66:  uint16(82),
  31249 	67:  uint16(84),
  31250 	68:  uint16(86),
  31251 	69:  uint16(88),
  31252 	70:  uint16(90),
  31253 	71:  uint16(92),
  31254 	72:  uint16(94),
  31255 	73:  uint16(96),
  31256 	74:  uint16(98),
  31257 	75:  uint16(100),
  31258 	76:  uint16(102),
  31259 	77:  uint16(104),
  31260 	78:  uint16(106),
  31261 	79:  uint16(108),
  31262 	80:  uint16(110),
  31263 	81:  uint16(112),
  31264 	82:  uint16(114),
  31265 	83:  uint16(116),
  31266 	84:  uint16(119),
  31267 	85:  uint16(122),
  31268 	86:  uint16(125),
  31269 	87:  uint16(128),
  31270 	88:  uint16(131),
  31271 	89:  uint16(134),
  31272 	90:  uint16(137),
  31273 	91:  uint16(140),
  31274 	92:  uint16(143),
  31275 	93:  uint16(146),
  31276 	94:  uint16(149),
  31277 	95:  uint16(152),
  31278 	96:  uint16(155),
  31279 	97:  uint16(158),
  31280 	98:  uint16(161),
  31281 	99:  uint16(164),
  31282 	100: uint16(167),
  31283 	101: uint16(170),
  31284 	102: uint16(173),
  31285 	103: uint16(177),
  31286 	104: uint16(181),
  31287 	105: uint16(185),
  31288 	106: uint16(189),
  31289 	107: uint16(193),
  31290 	108: uint16(197),
  31291 	109: uint16(201),
  31292 	110: uint16(205),
  31293 	111: uint16(209),
  31294 	112: uint16(213),
  31295 	113: uint16(217),
  31296 	114: uint16(221),
  31297 	115: uint16(225),
  31298 	116: uint16(229),
  31299 	117: uint16(234),
  31300 	118: uint16(239),
  31301 	119: uint16(245),
  31302 	120: uint16(249),
  31303 	121: uint16(254),
  31304 	122: uint16(259),
  31305 	123: uint16(264),
  31306 	124: uint16(269),
  31307 	125: uint16(274),
  31308 	126: uint16(279),
  31309 	127: uint16(284),
  31310 }
  31311 
  31312 var kAcTable2 = [128]uint16_t{
  31313 	0:   uint16(8),
  31314 	1:   uint16(8),
  31315 	2:   uint16(9),
  31316 	3:   uint16(10),
  31317 	4:   uint16(12),
  31318 	5:   uint16(13),
  31319 	6:   uint16(15),
  31320 	7:   uint16(17),
  31321 	8:   uint16(18),
  31322 	9:   uint16(20),
  31323 	10:  uint16(21),
  31324 	11:  uint16(23),
  31325 	12:  uint16(24),
  31326 	13:  uint16(26),
  31327 	14:  uint16(27),
  31328 	15:  uint16(29),
  31329 	16:  uint16(31),
  31330 	17:  uint16(32),
  31331 	18:  uint16(34),
  31332 	19:  uint16(35),
  31333 	20:  uint16(37),
  31334 	21:  uint16(38),
  31335 	22:  uint16(40),
  31336 	23:  uint16(41),
  31337 	24:  uint16(43),
  31338 	25:  uint16(44),
  31339 	26:  uint16(46),
  31340 	27:  uint16(48),
  31341 	28:  uint16(49),
  31342 	29:  uint16(51),
  31343 	30:  uint16(52),
  31344 	31:  uint16(54),
  31345 	32:  uint16(55),
  31346 	33:  uint16(57),
  31347 	34:  uint16(58),
  31348 	35:  uint16(60),
  31349 	36:  uint16(62),
  31350 	37:  uint16(63),
  31351 	38:  uint16(65),
  31352 	39:  uint16(66),
  31353 	40:  uint16(68),
  31354 	41:  uint16(69),
  31355 	42:  uint16(71),
  31356 	43:  uint16(72),
  31357 	44:  uint16(74),
  31358 	45:  uint16(75),
  31359 	46:  uint16(77),
  31360 	47:  uint16(79),
  31361 	48:  uint16(80),
  31362 	49:  uint16(82),
  31363 	50:  uint16(83),
  31364 	51:  uint16(85),
  31365 	52:  uint16(86),
  31366 	53:  uint16(88),
  31367 	54:  uint16(89),
  31368 	55:  uint16(93),
  31369 	56:  uint16(96),
  31370 	57:  uint16(99),
  31371 	58:  uint16(102),
  31372 	59:  uint16(105),
  31373 	60:  uint16(108),
  31374 	61:  uint16(111),
  31375 	62:  uint16(114),
  31376 	63:  uint16(117),
  31377 	64:  uint16(120),
  31378 	65:  uint16(124),
  31379 	66:  uint16(127),
  31380 	67:  uint16(130),
  31381 	68:  uint16(133),
  31382 	69:  uint16(136),
  31383 	70:  uint16(139),
  31384 	71:  uint16(142),
  31385 	72:  uint16(145),
  31386 	73:  uint16(148),
  31387 	74:  uint16(151),
  31388 	75:  uint16(155),
  31389 	76:  uint16(158),
  31390 	77:  uint16(161),
  31391 	78:  uint16(164),
  31392 	79:  uint16(167),
  31393 	80:  uint16(170),
  31394 	81:  uint16(173),
  31395 	82:  uint16(176),
  31396 	83:  uint16(179),
  31397 	84:  uint16(184),
  31398 	85:  uint16(189),
  31399 	86:  uint16(193),
  31400 	87:  uint16(198),
  31401 	88:  uint16(203),
  31402 	89:  uint16(207),
  31403 	90:  uint16(212),
  31404 	91:  uint16(217),
  31405 	92:  uint16(221),
  31406 	93:  uint16(226),
  31407 	94:  uint16(230),
  31408 	95:  uint16(235),
  31409 	96:  uint16(240),
  31410 	97:  uint16(244),
  31411 	98:  uint16(249),
  31412 	99:  uint16(254),
  31413 	100: uint16(258),
  31414 	101: uint16(263),
  31415 	102: uint16(268),
  31416 	103: uint16(274),
  31417 	104: uint16(280),
  31418 	105: uint16(286),
  31419 	106: uint16(292),
  31420 	107: uint16(299),
  31421 	108: uint16(305),
  31422 	109: uint16(311),
  31423 	110: uint16(317),
  31424 	111: uint16(323),
  31425 	112: uint16(330),
  31426 	113: uint16(336),
  31427 	114: uint16(342),
  31428 	115: uint16(348),
  31429 	116: uint16(354),
  31430 	117: uint16(362),
  31431 	118: uint16(370),
  31432 	119: uint16(379),
  31433 	120: uint16(385),
  31434 	121: uint16(393),
  31435 	122: uint16(401),
  31436 	123: uint16(409),
  31437 	124: uint16(416),
  31438 	125: uint16(424),
  31439 	126: uint16(432),
  31440 	127: uint16(440),
  31441 }
  31442 
  31443 var kBiasMatrices = [3][2]uint8_t{
  31444 	0: {
  31445 		0: uint8(96),
  31446 		1: uint8(110),
  31447 	},
  31448 	1: {
  31449 		0: uint8(96),
  31450 		1: uint8(108),
  31451 	},
  31452 	2: {
  31453 		0: uint8(110),
  31454 		1: uint8(115),
  31455 	},
  31456 }
  31457 
  31458 // C documentation
  31459 //
  31460 //	// Sharpening by (slightly) raising the hi-frequency coeffs.
  31461 //	// Hack-ish but helpful for mid-bitrate range. Use with care.
  31462 var kFreqSharpening = [16]uint8_t{
  31463 	1:  uint8(30),
  31464 	2:  uint8(60),
  31465 	3:  uint8(90),
  31466 	4:  uint8(30),
  31467 	5:  uint8(60),
  31468 	6:  uint8(90),
  31469 	7:  uint8(90),
  31470 	8:  uint8(60),
  31471 	9:  uint8(90),
  31472 	10: uint8(90),
  31473 	11: uint8(90),
  31474 	12: uint8(90),
  31475 	13: uint8(90),
  31476 	14: uint8(90),
  31477 	15: uint8(90),
  31478 }
  31479 
  31480 //------------------------------------------------------------------------------
  31481 // Initialize quantization parameters in VP8Matrix
  31482 
  31483 // C documentation
  31484 //
  31485 //	// Returns the average quantizer
  31486 func ExpandMatrix(tls *libc.TLS, m uintptr, type1 int32) (r int32) {
  31487 	var bias, i, is_ac_coeff, sum int32
  31488 	_, _, _, _ = bias, i, is_ac_coeff, sum
  31489 	i = 0
  31490 	for {
  31491 		if !(i < int32(2)) {
  31492 			break
  31493 		}
  31494 		is_ac_coeff = libc.BoolInt32(i > libc.Int32FromInt32(0))
  31495 		bias = int32(**(**uint8_t)(__ccgo_up(uintptr(unsafe.Pointer(&kBiasMatrices)) + uintptr(type1)*2 + uintptr(is_ac_coeff))))
  31496 		**(**uint16_t)(__ccgo_up(m + 32 + uintptr(i)*2)) = uint16(libc.Int32FromInt32(1) << libc.Int32FromInt32(QFIX) / int32(**(**uint16_t)(__ccgo_up(m + uintptr(i)*2))))
  31497 		**(**uint32_t)(__ccgo_up(m + 64 + uintptr(i)*4)) = uint32(bias << (libc.Int32FromInt32(QFIX) - libc.Int32FromInt32(8)))
  31498 		// zthresh is the exact value such that QUANTDIV(coeff, iQ, B) is:
  31499 		//   * zero if coeff <= zthresh
  31500 		//   * non-zero if coeff > zthresh
  31501 		**(**uint32_t)(__ccgo_up(m + 128 + uintptr(i)*4)) = (uint32(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)))
  31502 		goto _1
  31503 	_1:
  31504 		;
  31505 		i = i + 1
  31506 	}
  31507 	i = int32(2)
  31508 	for {
  31509 		if !(i < int32(16)) {
  31510 			break
  31511 		}
  31512 		**(**uint16_t)(__ccgo_up(m + uintptr(i)*2)) = **(**uint16_t)(__ccgo_up(m + 1*2))
  31513 		**(**uint16_t)(__ccgo_up(m + 32 + uintptr(i)*2)) = **(**uint16_t)(__ccgo_up(m + 32 + 1*2))
  31514 		**(**uint32_t)(__ccgo_up(m + 64 + uintptr(i)*4)) = **(**uint32_t)(__ccgo_up(m + 64 + 1*4))
  31515 		**(**uint32_t)(__ccgo_up(m + 128 + uintptr(i)*4)) = **(**uint32_t)(__ccgo_up(m + 128 + 1*4))
  31516 		goto _2
  31517 	_2:
  31518 		;
  31519 		i = i + 1
  31520 	}
  31521 	sum = 0
  31522 	i = libc.Int32FromInt32(0)
  31523 	for {
  31524 		if !(i < int32(16)) {
  31525 			break
  31526 		}
  31527 		if type1 == 0 { // we only use sharpening for AC luma coeffs
  31528 			**(**uint16_t)(__ccgo_up(m + 192 + uintptr(i)*2)) = uint16(int32(kFreqSharpening[i]) * int32(**(**uint16_t)(__ccgo_up(m + uintptr(i)*2))) >> int32(SHARPEN_BITS))
  31529 		} else {
  31530 			**(**uint16_t)(__ccgo_up(m + 192 + uintptr(i)*2)) = uint16(0)
  31531 		}
  31532 		sum = sum + int32(**(**uint16_t)(__ccgo_up(m + uintptr(i)*2)))
  31533 		goto _3
  31534 	_3:
  31535 		;
  31536 		i = i + 1
  31537 	}
  31538 	return (sum + int32(8)) >> int32(4)
  31539 }
  31540 
  31541 func CheckLambdaValue(tls *libc.TLS, v uintptr) {
  31542 	if **(**int32)(__ccgo_up(v)) < int32(1) {
  31543 		**(**int32)(__ccgo_up(v)) = int32(1)
  31544 	}
  31545 }
  31546 
  31547 func SetupMatrices(tls *libc.TLS, enc uintptr) {
  31548 	var i, num_segments, q, q_i16, q_i4, q_uv, tlambda_scale, v1 int32
  31549 	var m uintptr
  31550 	_, _, _, _, _, _, _, _, _ = i, m, num_segments, q, q_i16, q_i4, q_uv, tlambda_scale, v1
  31551 	if (*VP8Encoder)(unsafe.Pointer(enc)).Fmethod >= int32(4) {
  31552 		v1 = (*WebPConfig)(unsafe.Pointer((*VP8Encoder)(unsafe.Pointer(enc)).Fconfig)).Fsns_strength
  31553 	} else {
  31554 		v1 = 0
  31555 	}
  31556 	tlambda_scale = v1
  31557 	num_segments = (*VP8Encoder)(unsafe.Pointer(enc)).Fsegment_hdr.Fnum_segments
  31558 	i = 0
  31559 	for {
  31560 		if !(i < num_segments) {
  31561 			break
  31562 		}
  31563 		m = enc + 608 + uintptr(i)*744
  31564 		q = (*VP8SegmentInfo)(unsafe.Pointer(m)).Fquant
  31565 		**(**uint16_t)(__ccgo_up(m)) = uint16(kDcTable1[clip2(tls, q+(*VP8Encoder)(unsafe.Pointer(enc)).Fdq_y1_dc, 0, int32(127))])
  31566 		**(**uint16_t)(__ccgo_up(m + 1*2)) = kAcTable1[clip2(tls, q, 0, int32(127))]
  31567 		**(**uint16_t)(__ccgo_up(m + 224)) = uint16(int32(kDcTable1[clip2(tls, q+(*VP8Encoder)(unsafe.Pointer(enc)).Fdq_y2_dc, 0, int32(127))]) * int32(2))
  31568 		**(**uint16_t)(__ccgo_up(m + 224 + 1*2)) = kAcTable2[clip2(tls, q+(*VP8Encoder)(unsafe.Pointer(enc)).Fdq_y2_ac, 0, int32(127))]
  31569 		**(**uint16_t)(__ccgo_up(m + 448)) = uint16(kDcTable1[clip2(tls, q+(*VP8Encoder)(unsafe.Pointer(enc)).Fdq_uv_dc, 0, int32(117))])
  31570 		**(**uint16_t)(__ccgo_up(m + 448 + 1*2)) = kAcTable1[clip2(tls, q+(*VP8Encoder)(unsafe.Pointer(enc)).Fdq_uv_ac, 0, int32(127))]
  31571 		q_i4 = ExpandMatrix(tls, m, 0)
  31572 		q_i16 = ExpandMatrix(tls, m+224, int32(1))
  31573 		q_uv = ExpandMatrix(tls, m+448, int32(2))
  31574 		(*VP8SegmentInfo)(unsafe.Pointer(m)).Flambda_i4 = int32(3) * q_i4 * q_i4 >> int32(7)
  31575 		(*VP8SegmentInfo)(unsafe.Pointer(m)).Flambda_i16 = int32(3) * q_i16 * q_i16
  31576 		(*VP8SegmentInfo)(unsafe.Pointer(m)).Flambda_uv = int32(3) * q_uv * q_uv >> int32(6)
  31577 		(*VP8SegmentInfo)(unsafe.Pointer(m)).Flambda_mode = int32(1) * q_i4 * q_i4 >> int32(7)
  31578 		(*VP8SegmentInfo)(unsafe.Pointer(m)).Flambda_trellis_i4 = int32(7) * q_i4 * q_i4 >> int32(3)
  31579 		(*VP8SegmentInfo)(unsafe.Pointer(m)).Flambda_trellis_i16 = q_i16 * q_i16 >> int32(2)
  31580 		(*VP8SegmentInfo)(unsafe.Pointer(m)).Flambda_trellis_uv = q_uv * q_uv << int32(1)
  31581 		(*VP8SegmentInfo)(unsafe.Pointer(m)).Ftlambda = tlambda_scale * q_i4 >> int32(5)
  31582 		// none of these constants should be < 1
  31583 		CheckLambdaValue(tls, m+700)
  31584 		CheckLambdaValue(tls, m+696)
  31585 		CheckLambdaValue(tls, m+704)
  31586 		CheckLambdaValue(tls, m+708)
  31587 		CheckLambdaValue(tls, m+724)
  31588 		CheckLambdaValue(tls, m+720)
  31589 		CheckLambdaValue(tls, m+728)
  31590 		CheckLambdaValue(tls, m+716)
  31591 		(*VP8SegmentInfo)(unsafe.Pointer(m)).Fmin_disto = int32(20) * int32(**(**uint16_t)(__ccgo_up(m))) // quantization-aware min disto
  31592 		(*VP8SegmentInfo)(unsafe.Pointer(m)).Fmax_edge = 0
  31593 		(*VP8SegmentInfo)(unsafe.Pointer(m)).Fi4_penalty = int64(int32(1000) * q_i4 * q_i4)
  31594 		goto _2
  31595 	_2:
  31596 		;
  31597 		i = i + 1
  31598 	}
  31599 }
  31600 
  31601 //------------------------------------------------------------------------------
  31602 // Initialize filtering parameters
  31603 
  31604 // Very small filter-strength values have close to no visual effect. So we can
  31605 // save a little decoding-CPU by turning filtering off for these.
  31606 
  31607 func SetupFilterStrength(tls *libc.TLS, enc uintptr) {
  31608 	var base_strength, f, i, level0, qstep, v2, v3 int32
  31609 	var m uintptr
  31610 	_, _, _, _, _, _, _, _ = base_strength, f, i, level0, m, qstep, v2, v3
  31611 	// level0 is in [0..500]. Using '-f 50' as filter_strength is mid-filtering.
  31612 	level0 = int32(5) * (*WebPConfig)(unsafe.Pointer((*VP8Encoder)(unsafe.Pointer(enc)).Fconfig)).Ffilter_strength
  31613 	i = 0
  31614 	for {
  31615 		if !(i < int32(NUM_MB_SEGMENTS)) {
  31616 			break
  31617 		}
  31618 		m = enc + 608 + uintptr(i)*744
  31619 		// We focus on the quantization of AC coeffs.
  31620 		qstep = int32(kAcTable1[clip2(tls, (*VP8SegmentInfo)(unsafe.Pointer(m)).Fquant, 0, int32(127))]) >> int32(2)
  31621 		base_strength = VP8FilterStrengthFromDelta(tls, (*VP8Encoder)(unsafe.Pointer(enc)).Ffilter_hdr.Fsharpness, qstep)
  31622 		// Segments with lower complexity ('beta') will be less filtered.
  31623 		f = base_strength * level0 / (int32(256) + (*VP8SegmentInfo)(unsafe.Pointer(m)).Fbeta)
  31624 		if f < int32(FSTRENGTH_CUTOFF) {
  31625 			v2 = 0
  31626 		} else {
  31627 			if f > int32(63) {
  31628 				v3 = int32(63)
  31629 			} else {
  31630 				v3 = f
  31631 			}
  31632 			v2 = v3
  31633 		}
  31634 		(*VP8SegmentInfo)(unsafe.Pointer(m)).Ffstrength = v2
  31635 		goto _1
  31636 	_1:
  31637 		;
  31638 		i = i + 1
  31639 	}
  31640 	// We record the initial strength (mainly for the case of 1-segment only).
  31641 	(*VP8Encoder)(unsafe.Pointer(enc)).Ffilter_hdr.Flevel = (**(**VP8SegmentInfo)(__ccgo_up(enc + 608))).Ffstrength
  31642 	(*VP8Encoder)(unsafe.Pointer(enc)).Ffilter_hdr.Fsimple = libc.BoolInt32((*WebPConfig)(unsafe.Pointer((*VP8Encoder)(unsafe.Pointer(enc)).Fconfig)).Ffilter_type == 0)
  31643 	(*VP8Encoder)(unsafe.Pointer(enc)).Ffilter_hdr.Fsharpness = (*WebPConfig)(unsafe.Pointer((*VP8Encoder)(unsafe.Pointer(enc)).Fconfig)).Ffilter_sharpness
  31644 }
  31645 
  31646 //------------------------------------------------------------------------------
  31647 
  31648 // Note: if you change the values below, remember that the max range
  31649 // allowed by the syntax for DQ_UV is [-16,16].
  31650 
  31651 // C documentation
  31652 //
  31653 //	// We want to emulate jpeg-like behaviour where the expected "good" quality
  31654 //	// is around q=75. Internally, our "good" middle is around c=50. So we
  31655 //	// map accordingly using linear piece-wise function
  31656 func QualityToCompression(tls *libc.TLS, c float64) (r float64) {
  31657 	var linear_c, v, v1 float64
  31658 	_, _, _ = linear_c, v, v1
  31659 	if c < float64(0.75) {
  31660 		v1 = float64(c * (libc.Float64FromFloat64(2) / libc.Float64FromFloat64(3)))
  31661 	} else {
  31662 		v1 = float64(float64(2)*c) - float64(1)
  31663 	}
  31664 	linear_c = v1
  31665 	// The file size roughly scales as pow(quantizer, 3.). Actually, the
  31666 	// exponent is somewhere between 2.8 and 3.2, but we're mostly interested
  31667 	// in the mid-quant range. So we scale the compressibility inversely to
  31668 	// this power-law: quant ~= compression ^ 1/3. This law holds well for
  31669 	// low quant. Finer modeling for high-quant would make use of kAcTable[]
  31670 	// more explicitly.
  31671 	v = libc.Xpow(tls, linear_c, libc.Float64FromInt32(1)/libc.Float64FromFloat64(3))
  31672 	return v
  31673 }
  31674 
  31675 func QualityToJPEGCompression(tls *libc.TLS, c float64, alpha float64) (r float64) {
  31676 	var amax, amin, exp_max, exp_min, expn, slope, v, v1, v2 float64
  31677 	_, _, _, _, _, _, _, _, _ = amax, amin, exp_max, exp_min, expn, slope, v, v1, v2
  31678 	// We map the complexity 'alpha' and quality setting 'c' to a compression
  31679 	// exponent empirically matched to the compression curve of libjpeg6b.
  31680 	// On average, the WebP output size will be roughly similar to that of a
  31681 	// JPEG file compressed with same quality factor.
  31682 	amin = float64(0.3)
  31683 	amax = float64(0.85)
  31684 	exp_min = float64(0.4)
  31685 	exp_max = float64(0.9)
  31686 	slope = (exp_min - exp_max) / (amax - amin)
  31687 	if alpha > amax {
  31688 		v1 = exp_min
  31689 	} else {
  31690 		if alpha < amin {
  31691 			v2 = exp_max
  31692 		} else {
  31693 			v2 = exp_max + float64(slope*(alpha-amin))
  31694 		}
  31695 		v1 = v2
  31696 	}
  31697 	// Linearly interpolate 'expn' from exp_min to exp_max
  31698 	// in the [amin, amax] range.
  31699 	expn = v1
  31700 	v = libc.Xpow(tls, c, expn)
  31701 	return v
  31702 }
  31703 
  31704 func SegmentsAreEquivalent(tls *libc.TLS, S1 uintptr, S2 uintptr) (r int32) {
  31705 	return libc.BoolInt32((*VP8SegmentInfo)(unsafe.Pointer(S1)).Fquant == (*VP8SegmentInfo)(unsafe.Pointer(S2)).Fquant && (*VP8SegmentInfo)(unsafe.Pointer(S1)).Ffstrength == (*VP8SegmentInfo)(unsafe.Pointer(S2)).Ffstrength)
  31706 }
  31707 
  31708 func SimplifySegments(tls *libc.TLS, enc uintptr) {
  31709 	var S1, S2 uintptr
  31710 	var found, i, num_final_segments, num_segments, s1, s2, v1 int32
  31711 	var map1 [4]int32
  31712 	_, _, _, _, _, _, _, _, _, _ = S1, S2, found, i, map1, num_final_segments, num_segments, s1, s2, v1
  31713 	map1 = [4]int32{
  31714 		1: int32(1),
  31715 		2: int32(2),
  31716 		3: int32(3),
  31717 	}
  31718 	if (*VP8Encoder)(unsafe.Pointer(enc)).Fsegment_hdr.Fnum_segments < int32(NUM_MB_SEGMENTS) {
  31719 		v1 = (*VP8Encoder)(unsafe.Pointer(enc)).Fsegment_hdr.Fnum_segments
  31720 	} else {
  31721 		v1 = int32(NUM_MB_SEGMENTS)
  31722 	}
  31723 	// 'num_segments' is previously validated and <= NUM_MB_SEGMENTS, but an
  31724 	// explicit check is needed to avoid a spurious warning about 'i' exceeding
  31725 	// array bounds of 'dqm' with some compilers (noticed with gcc-4.9).
  31726 	num_segments = v1
  31727 	num_final_segments = int32(1)
  31728 	s1 = int32(1)
  31729 	for {
  31730 		if !(s1 < num_segments) {
  31731 			break
  31732 		} // find similar segments
  31733 		S1 = enc + 608 + uintptr(s1)*744
  31734 		found = 0
  31735 		// check if we already have similar segment
  31736 		s2 = 0
  31737 		for {
  31738 			if !(s2 < num_final_segments) {
  31739 				break
  31740 			}
  31741 			S2 = enc + 608 + uintptr(s2)*744
  31742 			if SegmentsAreEquivalent(tls, S1, S2) != 0 {
  31743 				found = int32(1)
  31744 				break
  31745 			}
  31746 			goto _3
  31747 		_3:
  31748 			;
  31749 			s2 = s2 + 1
  31750 		}
  31751 		map1[s1] = s2
  31752 		if !(found != 0) {
  31753 			if num_final_segments != s1 {
  31754 				**(**VP8SegmentInfo)(__ccgo_up(enc + 608 + uintptr(num_final_segments)*744)) = **(**VP8SegmentInfo)(__ccgo_up(enc + 608 + uintptr(s1)*744))
  31755 			}
  31756 			num_final_segments = num_final_segments + 1
  31757 		}
  31758 		goto _2
  31759 	_2:
  31760 		;
  31761 		s1 = s1 + 1
  31762 	}
  31763 	if num_final_segments < num_segments { // Remap
  31764 		i = (*VP8Encoder)(unsafe.Pointer(enc)).Fmb_w * (*VP8Encoder)(unsafe.Pointer(enc)).Fmb_h
  31765 		for {
  31766 			v1 = i
  31767 			i = i - 1
  31768 			if !(v1 > 0) {
  31769 				break
  31770 			}
  31771 			libc.SetBitFieldPtr8Uint32((*VP8Encoder)(unsafe.Pointer(enc)).Fmb_info+uintptr(i)*4+0, uint32(map1[int32(uint32(*(*uint8)(unsafe.Pointer((*VP8Encoder)(unsafe.Pointer(enc)).Fmb_info + uintptr(i)*4 + 0))&0x60>>5))]), 5, 0x60)
  31772 		}
  31773 		(*VP8Encoder)(unsafe.Pointer(enc)).Fsegment_hdr.Fnum_segments = num_final_segments
  31774 		// Replicate the trailing segment infos (it's mostly cosmetics)
  31775 		i = num_final_segments
  31776 		for {
  31777 			if !(i < num_segments) {
  31778 				break
  31779 			}
  31780 			**(**VP8SegmentInfo)(__ccgo_up(enc + 608 + uintptr(i)*744)) = **(**VP8SegmentInfo)(__ccgo_up(enc + 608 + uintptr(num_final_segments-int32(1))*744))
  31781 			goto _5
  31782 		_5:
  31783 			;
  31784 			i = i + 1
  31785 		}
  31786 	}
  31787 }
  31788 
  31789 func VP8SetSegmentParams(tls *libc.TLS, enc uintptr, quality float32) {
  31790 	var Q, amp, c, c_base, expn, v1 float64
  31791 	var dq_uv_ac, dq_uv_dc, i, num_segments, q int32
  31792 	_, _, _, _, _, _, _, _, _, _, _ = Q, amp, c, c_base, dq_uv_ac, dq_uv_dc, expn, i, num_segments, q, v1
  31793 	num_segments = (*VP8Encoder)(unsafe.Pointer(enc)).Fsegment_hdr.Fnum_segments
  31794 	amp = float64(float64(SNS_TO_DQ)*float64((*WebPConfig)(unsafe.Pointer((*VP8Encoder)(unsafe.Pointer(enc)).Fconfig)).Fsns_strength)) / float64(100) / float64(128)
  31795 	Q = float64(quality) / float64(100)
  31796 	if (*WebPConfig)(unsafe.Pointer((*VP8Encoder)(unsafe.Pointer(enc)).Fconfig)).Femulate_jpeg_size != 0 {
  31797 		v1 = QualityToJPEGCompression(tls, Q, float64((*VP8Encoder)(unsafe.Pointer(enc)).Falpha)/float64(255))
  31798 	} else {
  31799 		v1 = QualityToCompression(tls, Q)
  31800 	}
  31801 	c_base = v1
  31802 	i = 0
  31803 	for {
  31804 		if !(i < num_segments) {
  31805 			break
  31806 		}
  31807 		// We modulate the base coefficient to accommodate for the quantization
  31808 		// susceptibility and allow denser segments to be quantized more.
  31809 		expn = float64(1) - float64(amp*float64((**(**VP8SegmentInfo)(__ccgo_up(enc + 608 + uintptr(i)*744))).Falpha))
  31810 		c = libc.Xpow(tls, c_base, expn)
  31811 		q = int32(float64(libc.Float64FromFloat64(127) * (libc.Float64FromFloat64(1) - c)))
  31812 		(**(**VP8SegmentInfo)(__ccgo_up(enc + 608 + uintptr(i)*744))).Fquant = clip2(tls, q, 0, int32(127))
  31813 		goto _2
  31814 	_2:
  31815 		;
  31816 		i = i + 1
  31817 	}
  31818 	// purely indicative in the bitstream (except for the 1-segment case)
  31819 	(*VP8Encoder)(unsafe.Pointer(enc)).Fbase_quant = (**(**VP8SegmentInfo)(__ccgo_up(enc + 608))).Fquant
  31820 	// fill-in values for the unused segments (required by the syntax)
  31821 	i = num_segments
  31822 	for {
  31823 		if !(i < int32(NUM_MB_SEGMENTS)) {
  31824 			break
  31825 		}
  31826 		(**(**VP8SegmentInfo)(__ccgo_up(enc + 608 + uintptr(i)*744))).Fquant = (*VP8Encoder)(unsafe.Pointer(enc)).Fbase_quant
  31827 		goto _3
  31828 	_3:
  31829 		;
  31830 		i = i + 1
  31831 	}
  31832 	// uv_alpha is normally spread around ~60. The useful range is
  31833 	// typically ~30 (quite bad) to ~100 (ok to decimate UV more).
  31834 	// We map it to the safe maximal range of MAX/MIN_DQ_UV for dq_uv.
  31835 	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))
  31836 	// we rescale by the user-defined strength of adaptation
  31837 	dq_uv_ac = dq_uv_ac * (*WebPConfig)(unsafe.Pointer((*VP8Encoder)(unsafe.Pointer(enc)).Fconfig)).Fsns_strength / int32(100)
  31838 	// and make it safe.
  31839 	dq_uv_ac = clip2(tls, dq_uv_ac, -int32(4), int32(MAX_DQ_UV))
  31840 	// We also boost the dc-uv-quant a little, based on sns-strength, since
  31841 	// U/V channels are quite more reactive to high quants (flat DC-blocks
  31842 	// tend to appear, and are unpleasant).
  31843 	dq_uv_dc = -int32(4) * (*WebPConfig)(unsafe.Pointer((*VP8Encoder)(unsafe.Pointer(enc)).Fconfig)).Fsns_strength / int32(100)
  31844 	dq_uv_dc = clip2(tls, dq_uv_dc, -int32(15), int32(15)) // 4bit-signed max allowed
  31845 	(*VP8Encoder)(unsafe.Pointer(enc)).Fdq_y1_dc = 0       // TODO(skal): dq-lum
  31846 	(*VP8Encoder)(unsafe.Pointer(enc)).Fdq_y2_dc = 0
  31847 	(*VP8Encoder)(unsafe.Pointer(enc)).Fdq_y2_ac = 0
  31848 	(*VP8Encoder)(unsafe.Pointer(enc)).Fdq_uv_dc = dq_uv_dc
  31849 	(*VP8Encoder)(unsafe.Pointer(enc)).Fdq_uv_ac = dq_uv_ac
  31850 	SetupFilterStrength(tls, enc) // initialize segments' filtering, eventually
  31851 	if num_segments > int32(1) {
  31852 		SimplifySegments(tls, enc)
  31853 	}
  31854 	SetupMatrices(tls, enc) // finalize quantization matrices
  31855 }
  31856 
  31857 // C documentation
  31858 //
  31859 //	// Must be indexed using {B_DC_PRED -> B_HU_PRED} as index
  31860 var VP8I4ModeOffsets = [10]uint16_t{
  31861 	0: uint16(libc.Int32FromInt32(3)*libc.Int32FromInt32(16)*libc.Int32FromInt32(BPS) + libc.Int32FromInt32(0)),
  31862 	1: uint16(libc.Int32FromInt32(3)*libc.Int32FromInt32(16)*libc.Int32FromInt32(BPS) + libc.Int32FromInt32(0) + libc.Int32FromInt32(4)),
  31863 	2: uint16(libc.Int32FromInt32(3)*libc.Int32FromInt32(16)*libc.Int32FromInt32(BPS) + libc.Int32FromInt32(0) + libc.Int32FromInt32(8)),
  31864 	3: uint16(libc.Int32FromInt32(3)*libc.Int32FromInt32(16)*libc.Int32FromInt32(BPS) + libc.Int32FromInt32(0) + libc.Int32FromInt32(12)),
  31865 	4: uint16(libc.Int32FromInt32(3)*libc.Int32FromInt32(16)*libc.Int32FromInt32(BPS) + libc.Int32FromInt32(0) + libc.Int32FromInt32(16)),
  31866 	5: uint16(libc.Int32FromInt32(3)*libc.Int32FromInt32(16)*libc.Int32FromInt32(BPS) + libc.Int32FromInt32(0) + libc.Int32FromInt32(20)),
  31867 	6: uint16(libc.Int32FromInt32(3)*libc.Int32FromInt32(16)*libc.Int32FromInt32(BPS) + libc.Int32FromInt32(0) + libc.Int32FromInt32(24)),
  31868 	7: uint16(libc.Int32FromInt32(3)*libc.Int32FromInt32(16)*libc.Int32FromInt32(BPS) + libc.Int32FromInt32(0) + libc.Int32FromInt32(28)),
  31869 	8: uint16(libc.Int32FromInt32(3)*libc.Int32FromInt32(16)*libc.Int32FromInt32(BPS) + libc.Int32FromInt32(4)*libc.Int32FromInt32(BPS)),
  31870 	9: uint16(libc.Int32FromInt32(3)*libc.Int32FromInt32(16)*libc.Int32FromInt32(BPS) + libc.Int32FromInt32(4)*libc.Int32FromInt32(BPS) + libc.Int32FromInt32(4)),
  31871 }
  31872 
  31873 func VP8MakeLuma16Preds(tls *libc.TLS, it uintptr) {
  31874 	var left, top, v1, v2 uintptr
  31875 	_, _, _, _ = left, top, v1, v2
  31876 	if (*VP8EncIterator)(unsafe.Pointer(it)).Fx != 0 {
  31877 		v1 = (*VP8EncIterator)(unsafe.Pointer(it)).Fy_left
  31878 	} else {
  31879 		v1 = libc.UintptrFromInt32(0)
  31880 	}
  31881 	left = v1
  31882 	if (*VP8EncIterator)(unsafe.Pointer(it)).Fy != 0 {
  31883 		v2 = (*VP8EncIterator)(unsafe.Pointer(it)).Fy_top
  31884 	} else {
  31885 		v2 = libc.UintptrFromInt32(0)
  31886 	}
  31887 	top = v2
  31888 	(*(*func(*libc.TLS, uintptr, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8EncPredLuma16})))(tls, (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_p, left, top)
  31889 }
  31890 
  31891 func VP8MakeChroma8Preds(tls *libc.TLS, it uintptr) {
  31892 	var left, top, v1, v2 uintptr
  31893 	_, _, _, _ = left, top, v1, v2
  31894 	if (*VP8EncIterator)(unsafe.Pointer(it)).Fx != 0 {
  31895 		v1 = (*VP8EncIterator)(unsafe.Pointer(it)).Fu_left
  31896 	} else {
  31897 		v1 = libc.UintptrFromInt32(0)
  31898 	}
  31899 	left = v1
  31900 	if (*VP8EncIterator)(unsafe.Pointer(it)).Fy != 0 {
  31901 		v2 = (*VP8EncIterator)(unsafe.Pointer(it)).Fuv_top
  31902 	} else {
  31903 		v2 = libc.UintptrFromInt32(0)
  31904 	}
  31905 	top = v2
  31906 	(*(*func(*libc.TLS, uintptr, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8EncPredChroma8})))(tls, (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_p, left, top)
  31907 }
  31908 
  31909 // C documentation
  31910 //
  31911 //	// Form all the ten Intra4x4 predictions in the 'yuv_p' cache
  31912 //	// for the 4x4 block it->i4
  31913 func MakeIntra4Preds(tls *libc.TLS, it uintptr) {
  31914 	(*(*func(*libc.TLS, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8EncPredLuma4})))(tls, (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_p, (*VP8EncIterator)(unsafe.Pointer(it)).Fi4_top)
  31915 }
  31916 
  31917 var VP8ScanUV = [8]uint16_t{
  31918 	1: uint16(libc.Int32FromInt32(4) + libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)),
  31919 	2: uint16(libc.Int32FromInt32(0) + libc.Int32FromInt32(4)*libc.Int32FromInt32(BPS)),
  31920 	3: uint16(libc.Int32FromInt32(4) + libc.Int32FromInt32(4)*libc.Int32FromInt32(BPS)),
  31921 	4: uint16(libc.Int32FromInt32(8) + libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)),
  31922 	5: uint16(libc.Int32FromInt32(12) + libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)),
  31923 	6: uint16(libc.Int32FromInt32(8) + libc.Int32FromInt32(4)*libc.Int32FromInt32(BPS)),
  31924 	7: uint16(libc.Int32FromInt32(12) + libc.Int32FromInt32(4)*libc.Int32FromInt32(BPS)),
  31925 }
  31926 
  31927 //------------------------------------------------------------------------------
  31928 // Distortion measurement
  31929 
  31930 var kWeightY = [16]uint16_t{
  31931 	0:  uint16(38),
  31932 	1:  uint16(32),
  31933 	2:  uint16(20),
  31934 	3:  uint16(9),
  31935 	4:  uint16(32),
  31936 	5:  uint16(28),
  31937 	6:  uint16(17),
  31938 	7:  uint16(7),
  31939 	8:  uint16(20),
  31940 	9:  uint16(17),
  31941 	10: uint16(10),
  31942 	11: uint16(4),
  31943 	12: uint16(9),
  31944 	13: uint16(7),
  31945 	14: uint16(4),
  31946 	15: uint16(2),
  31947 }
  31948 
  31949 var kWeightTrellis = [16]uint16_t{
  31950 	0:  uint16(30),
  31951 	1:  uint16(27),
  31952 	2:  uint16(19),
  31953 	3:  uint16(11),
  31954 	4:  uint16(27),
  31955 	5:  uint16(24),
  31956 	6:  uint16(17),
  31957 	7:  uint16(10),
  31958 	8:  uint16(19),
  31959 	9:  uint16(17),
  31960 	10: uint16(12),
  31961 	11: uint16(8),
  31962 	12: uint16(11),
  31963 	13: uint16(10),
  31964 	14: uint16(8),
  31965 	15: uint16(6),
  31966 }
  31967 
  31968 // C documentation
  31969 //
  31970 //	// Init/Copy the common fields in score.
  31971 func InitScore(tls *libc.TLS, rd uintptr) {
  31972 	(*VP8ModeScore)(unsafe.Pointer(rd)).FD = 0
  31973 	(*VP8ModeScore)(unsafe.Pointer(rd)).FSD = 0
  31974 	(*VP8ModeScore)(unsafe.Pointer(rd)).FR = 0
  31975 	(*VP8ModeScore)(unsafe.Pointer(rd)).FH = 0
  31976 	(*VP8ModeScore)(unsafe.Pointer(rd)).Fnz = uint32(0)
  31977 	(*VP8ModeScore)(unsafe.Pointer(rd)).Fscore = libc.Int64FromInt64(0x7fffffffffffff)
  31978 }
  31979 
  31980 func CopyScore(tls *libc.TLS, dst uintptr, src uintptr) {
  31981 	(*VP8ModeScore)(unsafe.Pointer(dst)).FD = (*VP8ModeScore)(unsafe.Pointer(src)).FD
  31982 	(*VP8ModeScore)(unsafe.Pointer(dst)).FSD = (*VP8ModeScore)(unsafe.Pointer(src)).FSD
  31983 	(*VP8ModeScore)(unsafe.Pointer(dst)).FR = (*VP8ModeScore)(unsafe.Pointer(src)).FR
  31984 	(*VP8ModeScore)(unsafe.Pointer(dst)).FH = (*VP8ModeScore)(unsafe.Pointer(src)).FH
  31985 	(*VP8ModeScore)(unsafe.Pointer(dst)).Fnz = (*VP8ModeScore)(unsafe.Pointer(src)).Fnz // note that nz is not accumulated, but just copied.
  31986 	(*VP8ModeScore)(unsafe.Pointer(dst)).Fscore = (*VP8ModeScore)(unsafe.Pointer(src)).Fscore
  31987 }
  31988 
  31989 func AddScore(tls *libc.TLS, dst uintptr, src uintptr) {
  31990 	**(**score_t)(__ccgo_up(dst)) += (*VP8ModeScore)(unsafe.Pointer(src)).FD
  31991 	**(**score_t)(__ccgo_up(dst + 8)) += (*VP8ModeScore)(unsafe.Pointer(src)).FSD
  31992 	**(**score_t)(__ccgo_up(dst + 24)) += (*VP8ModeScore)(unsafe.Pointer(src)).FR
  31993 	**(**score_t)(__ccgo_up(dst + 16)) += (*VP8ModeScore)(unsafe.Pointer(src)).FH
  31994 	**(**uint32_t)(__ccgo_up(dst + 864)) |= (*VP8ModeScore)(unsafe.Pointer(src)).Fnz // here, new nz bits are accumulated.
  31995 	**(**score_t)(__ccgo_up(dst + 32)) += (*VP8ModeScore)(unsafe.Pointer(src)).Fscore
  31996 }
  31997 
  31998 //------------------------------------------------------------------------------
  31999 // Performs trellis-optimized quantization.
  32000 
  32001 // C documentation
  32002 //
  32003 //	// Trellis node
  32004 type Node = struct {
  32005 	Fprev  int8_t
  32006 	Fsign  int8_t
  32007 	Flevel int16_t
  32008 }
  32009 
  32010 // C documentation
  32011 //
  32012 //	// Score state
  32013 type ScoreState = struct {
  32014 	Fscore score_t
  32015 	Fcosts uintptr
  32016 }
  32017 
  32018 // If a coefficient was quantized to a value Q (using a neutral bias),
  32019 // we test all alternate possibilities between [Q-MIN_DELTA, Q+MAX_DELTA]
  32020 // We don't test negative values though.
  32021 
  32022 func SetRDScore(tls *libc.TLS, lambda int32, rd uintptr) {
  32023 	(*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)
  32024 }
  32025 
  32026 func RDScoreTrellis(tls *libc.TLS, lambda int32, rate score_t, distortion score_t) (r score_t) {
  32027 	return rate*int64(lambda) + int64(RD_DISTO_MULT)*distortion
  32028 }
  32029 
  32030 const TYPE_I16_AC = 0
  32031 const TYPE_I16_DC = 1
  32032 const TYPE_CHROMA_A = 2
  32033 const TYPE_I4_AC = 3
  32034 
  32035 func TrellisQuantizeBlock(tls *libc.TLS, enc uintptr, in uintptr, out uintptr, ctx0 int32, coeff_type int32, mtx uintptr, lambda int32) (r int32) {
  32036 	bp := tls.Alloc(192)
  32037 	defer tls.Free(192)
  32038 	var B1, Q, coeff0, iQ1 uint32_t
  32039 	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
  32040 	var base_score, best_cur_score, best_score, cost, cost1, last_pos_cost, last_pos_score, rate, score score_t
  32041 	var best_path [3]int32
  32042 	var costs CostArrayPtr
  32043 	var cur, node, probas, ss_cur, ss_prev, tmp uintptr
  32044 	var v3 uint8_t
  32045 	var _ /* nodes at bp+0 */ [16][2]Node
  32046 	var _ /* score_states at bp+128 */ [2][2]ScoreState
  32047 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  32048 	probas = enc + 3616 + 4 + uintptr(coeff_type)*264
  32049 	costs = enc + 3616 + 18344 + uintptr(coeff_type)*384
  32050 	if coeff_type == int32(TYPE_I16_AC) {
  32051 		v1 = int32(1)
  32052 	} else {
  32053 		v1 = 0
  32054 	}
  32055 	first = v1
  32056 	ss_cur = bp + 128 + uintptr(libc.Int32FromInt32(MIN_DELTA)+libc.Int32FromInt32(MIN_DELTA))*16
  32057 	ss_prev = bp + 128 + 1*32 + uintptr(libc.Int32FromInt32(MIN_DELTA)+libc.Int32FromInt32(MIN_DELTA))*16
  32058 	best_path = [3]int32{
  32059 		0: -int32(1),
  32060 		1: -int32(1),
  32061 		2: -int32(1),
  32062 	}
  32063 	thresh = int32(**(**uint16_t)(__ccgo_up(mtx + 1*2))) * int32(**(**uint16_t)(__ccgo_up(mtx + 1*2))) / int32(4)
  32064 	last_proba = int32(**(**uint8_t)(__ccgo_up(probas + uintptr(VP8EncBands[first])*33 + uintptr(ctx0)*11)))
  32065 	// compute the position of the last interesting coefficient
  32066 	last = first - int32(1)
  32067 	n1 = int32(15)
  32068 	for {
  32069 		if !(n1 >= first) {
  32070 			break
  32071 		}
  32072 		j = int32(kZigzag1[n1])
  32073 		err = int32(**(**int16_t)(__ccgo_up(in + uintptr(j)*2))) * int32(**(**int16_t)(__ccgo_up(in + uintptr(j)*2)))
  32074 		if err > thresh {
  32075 			last = n1
  32076 			break
  32077 		}
  32078 		goto _2
  32079 	_2:
  32080 		;
  32081 		n1 = n1 - 1
  32082 	}
  32083 	// we don't need to go inspect up to n = 16 coeffs. We can just go up
  32084 	// to last + 1 (inclusive) without losing much.
  32085 	if last < int32(15) {
  32086 		last = last + 1
  32087 	}
  32088 	// compute 'skip' score. This is the max score one can do.
  32089 	v3 = uint8(last_proba)
  32090 	if !(0 != 0) {
  32091 		v4 = int32(VP8EntropyCost[v3])
  32092 	} else {
  32093 		v4 = int32(VP8EntropyCost[int32(255)-int32(v3)])
  32094 	}
  32095 	v1 = v4
  32096 	goto _5
  32097 _5:
  32098 	cost = int64(v1)
  32099 	best_score = RDScoreTrellis(tls, lambda, cost, 0)
  32100 	// initialize source node.
  32101 	m = -MIN_DELTA
  32102 	for {
  32103 		if !(m <= int32(MAX_DELTA)) {
  32104 			break
  32105 		}
  32106 		if ctx0 == 0 {
  32107 			v3 = uint8(last_proba)
  32108 			if !(int32(1) != 0) {
  32109 				v6 = int32(VP8EntropyCost[v3])
  32110 			} else {
  32111 				v6 = int32(VP8EntropyCost[int32(255)-int32(v3)])
  32112 			}
  32113 			v4 = v6
  32114 			goto _11
  32115 		_11:
  32116 			v1 = v4
  32117 		} else {
  32118 			v1 = 0
  32119 		}
  32120 		rate = int64(v1)
  32121 		(**(**ScoreState)(__ccgo_up(ss_cur + uintptr(m)*16))).Fscore = RDScoreTrellis(tls, lambda, rate, 0)
  32122 		(**(**ScoreState)(__ccgo_up(ss_cur + uintptr(m)*16))).Fcosts = **(**uintptr)(__ccgo_up(costs + uintptr(first)*24 + uintptr(ctx0)*8))
  32123 		goto _7
  32124 	_7:
  32125 		;
  32126 		m = m + 1
  32127 	}
  32128 	// traverse trellis.
  32129 	n1 = first
  32130 	for {
  32131 		if !(n1 <= last) {
  32132 			break
  32133 		}
  32134 		j1 = int32(kZigzag1[n1])
  32135 		Q = uint32(**(**uint16_t)(__ccgo_up(mtx + uintptr(j1)*2)))
  32136 		iQ1 = uint32(**(**uint16_t)(__ccgo_up(mtx + 32 + uintptr(j1)*2)))
  32137 		B1 = uint32(libc.Int32FromInt32(0x00) << (libc.Int32FromInt32(QFIX) - libc.Int32FromInt32(8))) // neutral bias
  32138 		// note: it's important to take sign of the _original_ coeff,
  32139 		// so we don't have to consider level < 0 afterward.
  32140 		sign = libc.BoolInt32(int32(**(**int16_t)(__ccgo_up(in + uintptr(j1)*2))) < libc.Int32FromInt32(0))
  32141 		if sign != 0 {
  32142 			v1 = -int32(**(**int16_t)(__ccgo_up(in + uintptr(j1)*2)))
  32143 		} else {
  32144 			v1 = int32(**(**int16_t)(__ccgo_up(in + uintptr(j1)*2)))
  32145 		}
  32146 		coeff0 = uint32(v1 + int32(**(**uint16_t)(__ccgo_up(mtx + 192 + uintptr(j1)*2))))
  32147 		v4 = int32((coeff0*iQ1 + B1) >> libc.Int32FromInt32(QFIX))
  32148 		goto _16
  32149 	_16:
  32150 		level0 = v4
  32151 		v6 = int32((coeff0*iQ1 + uint32(libc.Int32FromInt32(0x80)<<(libc.Int32FromInt32(QFIX)-libc.Int32FromInt32(8)))) >> libc.Int32FromInt32(QFIX))
  32152 		goto _18
  32153 	_18:
  32154 		thresh_level = v6
  32155 		if thresh_level > int32(MAX_LEVEL) {
  32156 			thresh_level = int32(MAX_LEVEL)
  32157 		}
  32158 		if level0 > int32(MAX_LEVEL) {
  32159 			level0 = int32(MAX_LEVEL)
  32160 		}
  32161 		// Swap current and previous score states
  32162 		tmp = ss_cur
  32163 		ss_cur = ss_prev
  32164 		ss_prev = tmp
  32165 		// test all alternate level values around level0.
  32166 		m = -MIN_DELTA
  32167 		for {
  32168 			if !(m <= int32(MAX_DELTA)) {
  32169 				break
  32170 			}
  32171 			cur = bp + uintptr(n1)*8 + uintptr(m+MIN_DELTA)*4
  32172 			level1 = level0 + m
  32173 			if level1 > int32(2) {
  32174 				v1 = int32(2)
  32175 			} else {
  32176 				v1 = level1
  32177 			}
  32178 			ctx = v1
  32179 			band = int32(VP8EncBands[n1+int32(1)])
  32180 			(**(**ScoreState)(__ccgo_up(ss_cur + uintptr(m)*16))).Fcosts = **(**uintptr)(__ccgo_up(costs + uintptr(n1+int32(1))*24 + uintptr(ctx)*8))
  32181 			if level1 < 0 || level1 > thresh_level {
  32182 				(**(**ScoreState)(__ccgo_up(ss_cur + uintptr(m)*16))).Fscore = libc.Int64FromInt64(0x7fffffffffffff)
  32183 				// Node is dead.
  32184 				goto _19
  32185 			}
  32186 			// Compute delta_error = how much coding this level will
  32187 			// subtract to max_error as distortion.
  32188 			// Here, distortion = sum of (|coeff_i| - level_i * Q_i)^2
  32189 			new_error = int32(coeff0 - uint32(level1)*Q)
  32190 			delta_error = int32(uint32(kWeightTrellis[j1]) * (uint32(new_error*new_error) - coeff0*coeff0))
  32191 			base_score = RDScoreTrellis(tls, lambda, 0, int64(delta_error))
  32192 			// Inspect all possible non-dead predecessors. Retain only the best one.
  32193 			// The base_score is added to all scores so it is only added for the final
  32194 			// value after the loop.
  32195 			v1 = level1
  32196 			if v1 > int32(MAX_VARIABLE_LEVEL) {
  32197 				v6 = int32(MAX_VARIABLE_LEVEL)
  32198 			} else {
  32199 				v6 = v1
  32200 			}
  32201 			v4 = int32(VP8LevelFixedCosts[v1]) + int32(**(**uint16_t)(__ccgo_up((**(**ScoreState)(__ccgo_up(ss_prev + uintptr(-libc.Int32FromInt32(MIN_DELTA))*16))).Fcosts + uintptr(v6)*2)))
  32202 			goto _23
  32203 		_23:
  32204 			cost1 = int64(v4)
  32205 			best_cur_score = (**(**ScoreState)(__ccgo_up(ss_prev + uintptr(-libc.Int32FromInt32(MIN_DELTA))*16))).Fscore + RDScoreTrellis(tls, lambda, cost1, 0)
  32206 			best_prev = -MIN_DELTA
  32207 			p = -libc.Int32FromInt32(MIN_DELTA) + libc.Int32FromInt32(1)
  32208 			for {
  32209 				if !(p <= int32(MAX_DELTA)) {
  32210 					break
  32211 				}
  32212 				// Dead nodes (with ss_prev[p].score >= MAX_COST) are automatically
  32213 				// eliminated since their score can't be better than the current best.
  32214 				v1 = level1
  32215 				if v1 > int32(MAX_VARIABLE_LEVEL) {
  32216 					v6 = int32(MAX_VARIABLE_LEVEL)
  32217 				} else {
  32218 					v6 = v1
  32219 				}
  32220 				v4 = int32(VP8LevelFixedCosts[v1]) + int32(**(**uint16_t)(__ccgo_up((**(**ScoreState)(__ccgo_up(ss_prev + uintptr(p)*16))).Fcosts + uintptr(v6)*2)))
  32221 				goto _28
  32222 			_28:
  32223 				cost1 = int64(v4)
  32224 				// Examine node assuming it's a non-terminal one.
  32225 				score = (**(**ScoreState)(__ccgo_up(ss_prev + uintptr(p)*16))).Fscore + RDScoreTrellis(tls, lambda, cost1, 0)
  32226 				if score < best_cur_score {
  32227 					best_cur_score = score
  32228 					best_prev = p
  32229 				}
  32230 				goto _25
  32231 			_25:
  32232 				;
  32233 				p = p + 1
  32234 			}
  32235 			best_cur_score = best_cur_score + base_score
  32236 			// Store best finding in current node.
  32237 			(*Node)(unsafe.Pointer(cur)).Fsign = int8(sign)
  32238 			(*Node)(unsafe.Pointer(cur)).Flevel = int16(level1)
  32239 			(*Node)(unsafe.Pointer(cur)).Fprev = int8(best_prev)
  32240 			(**(**ScoreState)(__ccgo_up(ss_cur + uintptr(m)*16))).Fscore = best_cur_score
  32241 			// Now, record best terminal node (and thus best entry in the graph).
  32242 			if level1 != 0 && best_cur_score < best_score {
  32243 				if n1 < int32(15) {
  32244 					v3 = **(**uint8_t)(__ccgo_up(probas + uintptr(band)*33 + uintptr(ctx)*11))
  32245 					if !(0 != 0) {
  32246 						v6 = int32(VP8EntropyCost[v3])
  32247 					} else {
  32248 						v6 = int32(VP8EntropyCost[int32(255)-int32(v3)])
  32249 					}
  32250 					v4 = v6
  32251 					goto _33
  32252 				_33:
  32253 					v1 = v4
  32254 				} else {
  32255 					v1 = 0
  32256 				}
  32257 				last_pos_cost = int64(v1)
  32258 				last_pos_score = RDScoreTrellis(tls, lambda, last_pos_cost, 0)
  32259 				score = best_cur_score + last_pos_score
  32260 				if score < best_score {
  32261 					best_score = score
  32262 					best_path[0] = n1               // best eob position
  32263 					best_path[int32(1)] = m         // best node index
  32264 					best_path[int32(2)] = best_prev // best predecessor
  32265 				}
  32266 			}
  32267 			goto _19
  32268 		_19:
  32269 			;
  32270 			m = m + 1
  32271 		}
  32272 		goto _13
  32273 	_13:
  32274 		;
  32275 		n1 = n1 + 1
  32276 	}
  32277 	// Fresh start
  32278 	// Beware! We must preserve in[0]/out[0] value for TYPE_I16_AC case.
  32279 	if coeff_type == int32(TYPE_I16_AC) {
  32280 		libc.Xmemset(tls, in+uintptr(1)*2, 0, libc.Uint64FromInt32(15)*libc.Uint64FromInt64(2))
  32281 		libc.Xmemset(tls, out+uintptr(1)*2, 0, libc.Uint64FromInt32(15)*libc.Uint64FromInt64(2))
  32282 	} else {
  32283 		libc.Xmemset(tls, in, 0, libc.Uint64FromInt32(16)*libc.Uint64FromInt64(2))
  32284 		libc.Xmemset(tls, out, 0, libc.Uint64FromInt32(16)*libc.Uint64FromInt64(2))
  32285 	}
  32286 	if best_path[0] == -int32(1) {
  32287 		return 0 // skip!
  32288 	}
  32289 	// Unwind the best path.
  32290 	// Note: best-prev on terminal node is not necessarily equal to the
  32291 	// best_prev for non-terminal. So we patch best_path[2] in.
  32292 	nz = 0
  32293 	best_node = best_path[int32(1)]
  32294 	n1 = best_path[0]
  32295 	(**(**Node)(__ccgo_up(bp + uintptr(n1)*8 + uintptr(best_node+MIN_DELTA)*4))).Fprev = int8(best_path[int32(2)]) // force best-prev for terminal
  32296 	for {
  32297 		if !(n1 >= first) {
  32298 			break
  32299 		}
  32300 		node = bp + uintptr(n1)*8 + uintptr(best_node+MIN_DELTA)*4
  32301 		j2 = int32(kZigzag1[n1])
  32302 		if (*Node)(unsafe.Pointer(node)).Fsign != 0 {
  32303 			v1 = -int32((*Node)(unsafe.Pointer(node)).Flevel)
  32304 		} else {
  32305 			v1 = int32((*Node)(unsafe.Pointer(node)).Flevel)
  32306 		}
  32307 		**(**int16_t)(__ccgo_up(out + uintptr(n1)*2)) = int16(v1)
  32308 		nz = nz | int32((*Node)(unsafe.Pointer(node)).Flevel)
  32309 		**(**int16_t)(__ccgo_up(in + uintptr(j2)*2)) = int16(int32(**(**int16_t)(__ccgo_up(out + uintptr(n1)*2))) * int32(**(**uint16_t)(__ccgo_up(mtx + uintptr(j2)*2))))
  32310 		best_node = int32((*Node)(unsafe.Pointer(node)).Fprev)
  32311 		goto _35
  32312 	_35:
  32313 		;
  32314 		n1 = n1 - 1
  32315 	}
  32316 	return libc.BoolInt32(nz != 0)
  32317 	return r
  32318 }
  32319 
  32320 //------------------------------------------------------------------------------
  32321 // Performs: difference, transform, quantize, back-transform, add
  32322 // all at once. Output is the reconstructed block in *yuv_out, and the
  32323 // quantized levels in *levels.
  32324 
  32325 func ReconstructIntra16(tls *libc.TLS, it uintptr, rd uintptr, yuv_out uintptr, mode int32) (r int32) {
  32326 	bp := tls.Alloc(544)
  32327 	defer tls.Free(544)
  32328 	var ctx, n, non_zero, nz, x, y, v4 int32
  32329 	var dqm, enc, ref, src uintptr
  32330 	var v6 int16_t
  32331 	var _ /* dc_tmp at bp+512 */ [16]int16_t
  32332 	var _ /* tmp at bp+0 */ [16][16]int16_t
  32333 	_, _, _, _, _, _, _, _, _, _, _, _ = ctx, dqm, enc, n, non_zero, nz, ref, src, x, y, v4, v6
  32334 	enc = (*VP8EncIterator)(unsafe.Pointer(it)).Fenc
  32335 	ref = (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_p + uintptr(VP8I16ModeOffsets[mode])
  32336 	src = (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_in + uintptr(libc.Int32FromInt32(Y_OFF_ENC))
  32337 	dqm = enc + 608 + uintptr(int32(uint32(*(*uint8)(unsafe.Pointer((*VP8EncIterator)(unsafe.Pointer(it)).Fmb + 0))&0x60>>5)))*744
  32338 	nz = 0
  32339 	n = 0
  32340 	for {
  32341 		if !(n < int32(16)) {
  32342 			break
  32343 		}
  32344 		(*(*func(*libc.TLS, uintptr, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8FTransform2})))(tls, src+uintptr(VP8Scan[n]), ref+uintptr(VP8Scan[n]), bp+uintptr(n)*32)
  32345 		goto _1
  32346 	_1:
  32347 		;
  32348 		n = n + int32(2)
  32349 	}
  32350 	(*(*func(*libc.TLS, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8FTransformWHT})))(tls, bp, bp+512)
  32351 	nz = nz | (*(*func(*libc.TLS, uintptr, uintptr, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{VP8EncQuantizeBlockWHT})))(tls, bp+512, rd+40, dqm+224)<<int32(24)
  32352 	if libc.Bool(int32(DO_TRELLIS_I16) != 0) && (*VP8EncIterator)(unsafe.Pointer(it)).Fdo_trellis != 0 {
  32353 		VP8IteratorNzToBytes(tls, it)
  32354 		y = 0
  32355 		n = libc.Int32FromInt32(0)
  32356 		for {
  32357 			if !(y < int32(4)) {
  32358 				break
  32359 			}
  32360 			x = 0
  32361 			for {
  32362 				if !(x < int32(4)) {
  32363 					break
  32364 				}
  32365 				ctx = **(**int32)(__ccgo_up(it + 132 + uintptr(x)*4)) + **(**int32)(__ccgo_up(it + 168 + uintptr(y)*4))
  32366 				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)
  32367 				v4 = non_zero
  32368 				**(**int32)(__ccgo_up(it + 168 + uintptr(y)*4)) = v4
  32369 				**(**int32)(__ccgo_up(it + 132 + uintptr(x)*4)) = v4
  32370 				**(**int16_t)(__ccgo_up(rd + 72 + uintptr(n)*32)) = 0
  32371 				nz = nz | non_zero<<n
  32372 				goto _3
  32373 			_3:
  32374 				;
  32375 				x = x + 1
  32376 				n = n + 1
  32377 			}
  32378 			goto _2
  32379 		_2:
  32380 			;
  32381 			y = y + 1
  32382 		}
  32383 	} else {
  32384 		n = 0
  32385 		for {
  32386 			if !(n < int32(16)) {
  32387 				break
  32388 			}
  32389 			// Zero-out the first coeff, so that: a) nz is correct below, and
  32390 			// b) finding 'last' non-zero coeffs in SetResidualCoeffs() is simplified.
  32391 			v6 = libc.Int16FromInt32(0)
  32392 			**(**int16_t)(__ccgo_up(bp + uintptr(n+int32(1))*32)) = v6
  32393 			**(**int16_t)(__ccgo_up(bp + uintptr(n)*32)) = v6
  32394 			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
  32395 			goto _5
  32396 		_5:
  32397 			;
  32398 			n = n + int32(2)
  32399 		}
  32400 	}
  32401 	// Transform back
  32402 	(*(*func(*libc.TLS, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8TransformWHT})))(tls, bp+512, bp)
  32403 	n = 0
  32404 	for {
  32405 		if !(n < int32(16)) {
  32406 			break
  32407 		}
  32408 		(*(*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))
  32409 		goto _7
  32410 	_7:
  32411 		;
  32412 		n = n + int32(2)
  32413 	}
  32414 	return nz
  32415 }
  32416 
  32417 func ReconstructIntra4(tls *libc.TLS, it uintptr, levels uintptr, src uintptr, yuv_out uintptr, mode int32) (r int32) {
  32418 	bp := tls.Alloc(32)
  32419 	defer tls.Free(32)
  32420 	var ctx, nz, x, y int32
  32421 	var dqm, enc, ref uintptr
  32422 	var _ /* tmp at bp+0 */ [16]int16_t
  32423 	_, _, _, _, _, _, _ = ctx, dqm, enc, nz, ref, x, y
  32424 	enc = (*VP8EncIterator)(unsafe.Pointer(it)).Fenc
  32425 	ref = (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_p + uintptr(VP8I4ModeOffsets[mode])
  32426 	dqm = enc + 608 + uintptr(int32(uint32(*(*uint8)(unsafe.Pointer((*VP8EncIterator)(unsafe.Pointer(it)).Fmb + 0))&0x60>>5)))*744
  32427 	nz = 0
  32428 	(*(*func(*libc.TLS, uintptr, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8FTransform})))(tls, src, ref, bp)
  32429 	if libc.Bool(int32(DO_TRELLIS_I4) != 0) && (*VP8EncIterator)(unsafe.Pointer(it)).Fdo_trellis != 0 {
  32430 		x = (*VP8EncIterator)(unsafe.Pointer(it)).Fi4 & int32(3)
  32431 		y = (*VP8EncIterator)(unsafe.Pointer(it)).Fi4 >> int32(2)
  32432 		ctx = **(**int32)(__ccgo_up(it + 132 + uintptr(x)*4)) + **(**int32)(__ccgo_up(it + 168 + uintptr(y)*4))
  32433 		nz = TrellisQuantizeBlock(tls, enc, bp, levels, ctx, int32(TYPE_I4_AC), dqm, (*VP8SegmentInfo)(unsafe.Pointer(dqm)).Flambda_trellis_i4)
  32434 	} else {
  32435 		nz = (*(*func(*libc.TLS, uintptr, uintptr, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{VP8EncQuantizeBlock})))(tls, bp, levels, dqm)
  32436 	}
  32437 	(*(*func(*libc.TLS, uintptr, uintptr, uintptr, int32))(unsafe.Pointer(&struct{ uintptr }{VP8ITransform})))(tls, ref, bp, yuv_out, 0)
  32438 	return nz
  32439 }
  32440 
  32441 //------------------------------------------------------------------------------
  32442 // DC-error diffusion
  32443 
  32444 // Diffusion weights. We under-correct a bit (15/16th of the error is actually
  32445 // diffused) to avoid 'rainbow' chessboard pattern of blocks at q~=0.
  32446 
  32447 // C documentation
  32448 //
  32449 //	// Quantize as usual, but also compute and return the quantization error.
  32450 //	// Error is already divided by DSHIFT.
  32451 func QuantizeSingle(tls *libc.TLS, v uintptr, mtx uintptr) (r int32) {
  32452 	var V, err, qV, sign, v1, v3 int32
  32453 	_, _, _, _, _, _ = V, err, qV, sign, v1, v3
  32454 	V = int32(**(**int16_t)(__ccgo_up(v)))
  32455 	sign = libc.BoolInt32(V < libc.Int32FromInt32(0))
  32456 	if sign != 0 {
  32457 		V = -V
  32458 	}
  32459 	if V > int32(**(**uint32_t)(__ccgo_up(mtx + 128))) {
  32460 		v1 = int32((uint32(V)*uint32(**(**uint16_t)(__ccgo_up(mtx + 32))) + **(**uint32_t)(__ccgo_up(mtx + 64))) >> libc.Int32FromInt32(QFIX))
  32461 		goto _2
  32462 	_2:
  32463 		qV = v1 * int32(**(**uint16_t)(__ccgo_up(mtx)))
  32464 		err = V - qV
  32465 		if sign != 0 {
  32466 			v3 = -qV
  32467 		} else {
  32468 			v3 = qV
  32469 		}
  32470 		**(**int16_t)(__ccgo_up(v)) = int16(v3)
  32471 		if sign != 0 {
  32472 			v1 = -err
  32473 		} else {
  32474 			v1 = err
  32475 		}
  32476 		return v1 >> int32(1)
  32477 	}
  32478 	**(**int16_t)(__ccgo_up(v)) = 0
  32479 	if sign != 0 {
  32480 		v1 = -V
  32481 	} else {
  32482 		v1 = V
  32483 	}
  32484 	return v1 >> int32(1)
  32485 }
  32486 
  32487 func CorrectDCValues(tls *libc.TLS, it uintptr, mtx uintptr, tmp uintptr, rd uintptr) {
  32488 	var c, left, top, v2 uintptr
  32489 	var ch, err0, err1, err2, err3 int32
  32490 	_, _, _, _, _, _, _, _, _ = c, ch, err0, err1, err2, err3, left, top, v2
  32491 	ch = 0
  32492 	for {
  32493 		if !(ch <= int32(1)) {
  32494 			break
  32495 		}
  32496 		top = (*VP8EncIterator)(unsafe.Pointer(it)).Ftop_derr + uintptr((*VP8EncIterator)(unsafe.Pointer(it)).Fx)*4 + uintptr(ch)*2
  32497 		left = it + 344 + uintptr(ch)*2
  32498 		c = tmp + uintptr(ch*int32(4))*32
  32499 		v2 = c
  32500 		*(*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)))
  32501 		err0 = QuantizeSingle(tls, c, mtx)
  32502 		v2 = c + 1*32
  32503 		*(*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)))
  32504 		err1 = QuantizeSingle(tls, c+1*32, mtx)
  32505 		v2 = c + 2*32
  32506 		*(*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)))
  32507 		err2 = QuantizeSingle(tls, c+2*32, mtx)
  32508 		v2 = c + 3*32
  32509 		*(*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)))
  32510 		err3 = QuantizeSingle(tls, c+3*32, mtx)
  32511 		// error 'err' is bounded by mtx->q[0] which is 132 at max. Hence
  32512 		// err >> DSCALE will fit in an int8_t type if DSCALE>=1.
  32513 		**(**int8_t)(__ccgo_up(rd + 868 + uintptr(ch)*3)) = int8(err1)
  32514 		**(**int8_t)(__ccgo_up(rd + 868 + uintptr(ch)*3 + 1)) = int8(err2)
  32515 		**(**int8_t)(__ccgo_up(rd + 868 + uintptr(ch)*3 + 2)) = int8(err3)
  32516 		goto _1
  32517 	_1:
  32518 		;
  32519 		ch = ch + 1
  32520 	}
  32521 }
  32522 
  32523 func StoreDiffusionErrors(tls *libc.TLS, it uintptr, rd uintptr) {
  32524 	var ch int32
  32525 	var left, top uintptr
  32526 	_, _, _ = ch, left, top
  32527 	ch = 0
  32528 	for {
  32529 		if !(ch <= int32(1)) {
  32530 			break
  32531 		}
  32532 		top = (*VP8EncIterator)(unsafe.Pointer(it)).Ftop_derr + uintptr((*VP8EncIterator)(unsafe.Pointer(it)).Fx)*4 + uintptr(ch)*2
  32533 		left = it + 344 + uintptr(ch)*2
  32534 		**(**int8_t)(__ccgo_up(left)) = **(**int8_t)(__ccgo_up(rd + 868 + uintptr(ch)*3))                                                                // restore err1
  32535 		**(**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
  32536 		**(**int8_t)(__ccgo_up(top)) = **(**int8_t)(__ccgo_up(rd + 868 + uintptr(ch)*3 + 1))                                                             //     ... err2
  32537 		**(**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.
  32538 		goto _1
  32539 	_1:
  32540 		;
  32541 		ch = ch + 1
  32542 	}
  32543 }
  32544 
  32545 //------------------------------------------------------------------------------
  32546 
  32547 func ReconstructUV(tls *libc.TLS, it uintptr, rd uintptr, yuv_out uintptr, mode int32) (r int32) {
  32548 	bp := tls.Alloc(256)
  32549 	defer tls.Free(256)
  32550 	var ch, ctx, n, non_zero, nz, x, y, v5 int32
  32551 	var dqm, enc, ref, src uintptr
  32552 	var _ /* tmp at bp+0 */ [8][16]int16_t
  32553 	_, _, _, _, _, _, _, _, _, _, _, _ = ch, ctx, dqm, enc, n, non_zero, nz, ref, src, x, y, v5
  32554 	enc = (*VP8EncIterator)(unsafe.Pointer(it)).Fenc
  32555 	ref = (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_p + uintptr(VP8UVModeOffsets[mode])
  32556 	src = (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_in + uintptr(libc.Int32FromInt32(U_OFF_ENC))
  32557 	dqm = enc + 608 + uintptr(int32(uint32(*(*uint8)(unsafe.Pointer((*VP8EncIterator)(unsafe.Pointer(it)).Fmb + 0))&0x60>>5)))*744
  32558 	nz = 0
  32559 	n = 0
  32560 	for {
  32561 		if !(n < int32(8)) {
  32562 			break
  32563 		}
  32564 		(*(*func(*libc.TLS, uintptr, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8FTransform2})))(tls, src+uintptr(VP8ScanUV[n]), ref+uintptr(VP8ScanUV[n]), bp+uintptr(n)*32)
  32565 		goto _1
  32566 	_1:
  32567 		;
  32568 		n = n + int32(2)
  32569 	}
  32570 	if (*VP8EncIterator)(unsafe.Pointer(it)).Ftop_derr != libc.UintptrFromInt32(0) {
  32571 		CorrectDCValues(tls, it, dqm+448, bp, rd)
  32572 	}
  32573 	if libc.Bool(DO_TRELLIS_UV != 0) && (*VP8EncIterator)(unsafe.Pointer(it)).Fdo_trellis != 0 {
  32574 		ch = 0
  32575 		n = libc.Int32FromInt32(0)
  32576 		for {
  32577 			if !(ch <= int32(2)) {
  32578 				break
  32579 			}
  32580 			y = 0
  32581 			for {
  32582 				if !(y < int32(2)) {
  32583 					break
  32584 				}
  32585 				x = 0
  32586 				for {
  32587 					if !(x < int32(2)) {
  32588 						break
  32589 					}
  32590 					ctx = **(**int32)(__ccgo_up(it + 132 + uintptr(int32(4)+ch+x)*4)) + **(**int32)(__ccgo_up(it + 168 + uintptr(int32(4)+ch+y)*4))
  32591 					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)
  32592 					v5 = non_zero
  32593 					**(**int32)(__ccgo_up(it + 168 + uintptr(int32(4)+ch+y)*4)) = v5
  32594 					**(**int32)(__ccgo_up(it + 132 + uintptr(int32(4)+ch+x)*4)) = v5
  32595 					nz = nz | non_zero<<n
  32596 					goto _4
  32597 				_4:
  32598 					;
  32599 					x = x + 1
  32600 					n = n + 1
  32601 				}
  32602 				goto _3
  32603 			_3:
  32604 				;
  32605 				y = y + 1
  32606 			}
  32607 			goto _2
  32608 		_2:
  32609 			;
  32610 			ch = ch + int32(2)
  32611 		}
  32612 	} else {
  32613 		n = 0
  32614 		for {
  32615 			if !(n < int32(8)) {
  32616 				break
  32617 			}
  32618 			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
  32619 			goto _6
  32620 		_6:
  32621 			;
  32622 			n = n + int32(2)
  32623 		}
  32624 	}
  32625 	n = 0
  32626 	for {
  32627 		if !(n < int32(8)) {
  32628 			break
  32629 		}
  32630 		(*(*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))
  32631 		goto _7
  32632 	_7:
  32633 		;
  32634 		n = n + int32(2)
  32635 	}
  32636 	return nz << int32(16)
  32637 }
  32638 
  32639 //------------------------------------------------------------------------------
  32640 // RD-opt decision. Reconstruct each modes, evalue distortion and bit-cost.
  32641 // Pick the mode is lower RD-cost = Rate + lambda * Distortion.
  32642 
  32643 func StoreMaxDelta(tls *libc.TLS, dqm uintptr, DCs uintptr) {
  32644 	var max_v, v0, v1, v2, v11, v21 int32
  32645 	_, _, _, _, _, _ = max_v, v0, v1, v2, v11, v21
  32646 	// We look at the first three AC coefficients to determine what is the average
  32647 	// delta between each sub-4x4 block.
  32648 	v0 = libc.Xabs(tls, int32(**(**int16_t)(__ccgo_up(DCs + 1*2))))
  32649 	v1 = libc.Xabs(tls, int32(**(**int16_t)(__ccgo_up(DCs + 2*2))))
  32650 	v2 = libc.Xabs(tls, int32(**(**int16_t)(__ccgo_up(DCs + 4*2))))
  32651 	if v1 > v0 {
  32652 		v11 = v1
  32653 	} else {
  32654 		v11 = v0
  32655 	}
  32656 	max_v = v11
  32657 	if v2 > max_v {
  32658 		v21 = v2
  32659 	} else {
  32660 		v21 = max_v
  32661 	}
  32662 	max_v = v21
  32663 	if max_v > (*VP8SegmentInfo)(unsafe.Pointer(dqm)).Fmax_edge {
  32664 		(*VP8SegmentInfo)(unsafe.Pointer(dqm)).Fmax_edge = max_v
  32665 	}
  32666 }
  32667 
  32668 func SwapModeScore(tls *libc.TLS, a uintptr, b uintptr) {
  32669 	var tmp uintptr
  32670 	_ = tmp
  32671 	tmp = **(**uintptr)(__ccgo_up(a))
  32672 	**(**uintptr)(__ccgo_up(a)) = **(**uintptr)(__ccgo_up(b))
  32673 	**(**uintptr)(__ccgo_up(b)) = tmp
  32674 }
  32675 
  32676 func SwapPtr(tls *libc.TLS, a uintptr, b uintptr) {
  32677 	var tmp uintptr
  32678 	_ = tmp
  32679 	tmp = **(**uintptr)(__ccgo_up(a))
  32680 	**(**uintptr)(__ccgo_up(a)) = **(**uintptr)(__ccgo_up(b))
  32681 	**(**uintptr)(__ccgo_up(b)) = tmp
  32682 }
  32683 
  32684 func SwapOut(tls *libc.TLS, it uintptr) {
  32685 	SwapPtr(tls, it+16, it+24)
  32686 }
  32687 
  32688 func PickBestIntra16(tls *libc.TLS, it uintptr, rd uintptr) {
  32689 	bp := tls.Alloc(912)
  32690 	defer tls.Free(912)
  32691 	var dqm, src1, tmp_dst, v1 uintptr
  32692 	var i, i1, is_flat, kNumBlocks, lambda, mode, score, tlambda, v3, v6, v8 int32
  32693 	var _ /* rd_best at bp+896 */ uintptr
  32694 	var _ /* rd_cur at bp+888 */ uintptr
  32695 	var _ /* rd_tmp at bp+8 */ VP8ModeScore
  32696 	var _ /* v at bp+0 */ uint32_t
  32697 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = dqm, i, i1, is_flat, kNumBlocks, lambda, mode, score, src1, tlambda, tmp_dst, v1, v3, v6, v8
  32698 	kNumBlocks = int32(16)
  32699 	dqm = (*VP8EncIterator)(unsafe.Pointer(it)).Fenc + 608 + uintptr(int32(uint32(*(*uint8)(unsafe.Pointer((*VP8EncIterator)(unsafe.Pointer(it)).Fmb + 0))&0x60>>5)))*744
  32700 	lambda = (*VP8SegmentInfo)(unsafe.Pointer(dqm)).Flambda_i16
  32701 	tlambda = (*VP8SegmentInfo)(unsafe.Pointer(dqm)).Ftlambda
  32702 	src1 = (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_in + uintptr(libc.Int32FromInt32(Y_OFF_ENC))
  32703 	**(**uintptr)(__ccgo_up(bp + 888)) = bp + 8
  32704 	**(**uintptr)(__ccgo_up(bp + 896)) = rd
  32705 	v1 = (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_in + uintptr(libc.Int32FromInt32(Y_OFF_ENC))
  32706 	**(**uint32_t)(__ccgo_up(bp)) = uint32(**(**uint8_t)(__ccgo_up(v1))) * uint32(0x01010101)
  32707 	i1 = libc.Int32FromInt32(0)
  32708 	for {
  32709 		if !(i1 < libc.Int32FromInt32(16)) {
  32710 			break
  32711 		}
  32712 		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 {
  32713 			v3 = 0
  32714 			goto _4
  32715 		}
  32716 		v1 = v1 + uintptr(BPS)
  32717 		goto _2
  32718 	_2:
  32719 		;
  32720 		i1 = i1 + 1
  32721 	}
  32722 	v3 = int32(1)
  32723 	goto _4
  32724 _4:
  32725 	is_flat = v3
  32726 	(*VP8ModeScore)(unsafe.Pointer(rd)).Fmode_i16 = -int32(1)
  32727 	mode = 0
  32728 	for {
  32729 		if !(mode < int32(NUM_PRED_MODES)) {
  32730 			break
  32731 		}
  32732 		tmp_dst = (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_out2 + uintptr(libc.Int32FromInt32(Y_OFF_ENC)) // scratch buffer
  32733 		(*VP8ModeScore)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp + 888)))).Fmode_i16 = mode
  32734 		// Reconstruct
  32735 		(*VP8ModeScore)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp + 888)))).Fnz = uint32(ReconstructIntra16(tls, it, **(**uintptr)(__ccgo_up(bp + 888)), tmp_dst, mode))
  32736 		// Measure RD-score
  32737 		(*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))
  32738 		if tlambda != 0 {
  32739 			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)
  32740 		} else {
  32741 			v3 = 0
  32742 		}
  32743 		(*VP8ModeScore)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp + 888)))).FSD = int64(v3)
  32744 		(*VP8ModeScore)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp + 888)))).FH = int64(VP8FixedCostsI16[mode])
  32745 		(*VP8ModeScore)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp + 888)))).FR = int64(VP8GetCostLuma16(tls, it, **(**uintptr)(__ccgo_up(bp + 888))))
  32746 		if is_flat != 0 {
  32747 			// refine the first impression (which was in pixel space)
  32748 			v1 = **(**uintptr)(__ccgo_up(bp + 888)) + 72
  32749 			v3 = kNumBlocks
  32750 			score = 0
  32751 			for {
  32752 				v6 = v3
  32753 				v3 = v3 - 1
  32754 				if !(v6 > libc.Int32FromInt32(0)) {
  32755 					break
  32756 				}
  32757 				i = libc.Int32FromInt32(1)
  32758 				for {
  32759 					if !(i < libc.Int32FromInt32(16)) {
  32760 						break
  32761 					}
  32762 					score = score + libc.BoolInt32(int32(**(**int16_t)(__ccgo_up(v1 + uintptr(i)*2))) != 0)
  32763 					if score > FLATNESS_LIMIT_I16 {
  32764 						v8 = 0
  32765 						goto _12
  32766 					}
  32767 					goto _10
  32768 				_10:
  32769 					;
  32770 					i = i + 1
  32771 				}
  32772 				v1 = v1 + uintptr(16)*2
  32773 			}
  32774 			v8 = int32(1)
  32775 			goto _12
  32776 		_12:
  32777 			is_flat = v8
  32778 			if is_flat != 0 {
  32779 				// Block is very flat. We put emphasis on the distortion being very low!
  32780 				**(**score_t)(__ccgo_up(**(**uintptr)(__ccgo_up(bp + 888)))) *= int64(2)
  32781 				**(**score_t)(__ccgo_up(**(**uintptr)(__ccgo_up(bp + 888)) + 8)) *= int64(2)
  32782 			}
  32783 		}
  32784 		// Since we always examine Intra16 first, we can overwrite *rd directly.
  32785 		SetRDScore(tls, lambda, **(**uintptr)(__ccgo_up(bp + 888)))
  32786 		if mode == 0 || (*VP8ModeScore)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp + 888)))).Fscore < (*VP8ModeScore)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp + 896)))).Fscore {
  32787 			SwapModeScore(tls, bp+888, bp+896)
  32788 			SwapOut(tls, it)
  32789 		}
  32790 		goto _5
  32791 	_5:
  32792 		;
  32793 		mode = mode + 1
  32794 	}
  32795 	if **(**uintptr)(__ccgo_up(bp + 896)) != rd {
  32796 		libc.Xmemcpy(tls, rd, **(**uintptr)(__ccgo_up(bp + 896)), uint64(880))
  32797 	}
  32798 	SetRDScore(tls, (*VP8SegmentInfo)(unsafe.Pointer(dqm)).Flambda_mode, rd) // finalize score for mode decision.
  32799 	VP8SetIntra16Mode(tls, it, (*VP8ModeScore)(unsafe.Pointer(rd)).Fmode_i16)
  32800 	// we have a blocky macroblock (only DCs are non-zero) with fairly high
  32801 	// distortion, record max delta so we can later adjust the minimal filtering
  32802 	// strength needed to smooth these blocks out.
  32803 	if (*VP8ModeScore)(unsafe.Pointer(rd)).Fnz&uint32(0x100ffff) == uint32(0x1000000) && (*VP8ModeScore)(unsafe.Pointer(rd)).FD > int64((*VP8SegmentInfo)(unsafe.Pointer(dqm)).Fmin_disto) {
  32804 		StoreMaxDelta(tls, dqm, rd+40)
  32805 	}
  32806 }
  32807 
  32808 //------------------------------------------------------------------------------
  32809 
  32810 // C documentation
  32811 //
  32812 //	// return the cost array corresponding to the surrounding prediction modes.
  32813 func GetCostModeI4(tls *libc.TLS, it uintptr, modes uintptr) (r uintptr) {
  32814 	var left, preds_w, top, x, y, v1, v2 int32
  32815 	_, _, _, _, _, _, _ = left, preds_w, top, x, y, v1, v2
  32816 	preds_w = (*VP8Encoder)(unsafe.Pointer((*VP8EncIterator)(unsafe.Pointer(it)).Fenc)).Fpreds_w
  32817 	x = (*VP8EncIterator)(unsafe.Pointer(it)).Fi4 & libc.Int32FromInt32(3)
  32818 	y = (*VP8EncIterator)(unsafe.Pointer(it)).Fi4 >> int32(2)
  32819 	if x == 0 {
  32820 		v1 = int32(**(**uint8_t)(__ccgo_up((*VP8EncIterator)(unsafe.Pointer(it)).Fpreds + uintptr(y*preds_w-int32(1)))))
  32821 	} else {
  32822 		v1 = int32(**(**uint8_t)(__ccgo_up(modes + uintptr((*VP8EncIterator)(unsafe.Pointer(it)).Fi4-int32(1)))))
  32823 	}
  32824 	left = v1
  32825 	if y == 0 {
  32826 		v2 = int32(**(**uint8_t)(__ccgo_up((*VP8EncIterator)(unsafe.Pointer(it)).Fpreds + uintptr(-preds_w+x))))
  32827 	} else {
  32828 		v2 = int32(**(**uint8_t)(__ccgo_up(modes + uintptr((*VP8EncIterator)(unsafe.Pointer(it)).Fi4-int32(4)))))
  32829 	}
  32830 	top = v2
  32831 	return uintptr(unsafe.Pointer(&VP8FixedCostsI4)) + uintptr(top)*200 + uintptr(left)*20
  32832 }
  32833 
  32834 func PickBestIntra4(tls *libc.TLS, it uintptr, rd uintptr) (r int32) {
  32835 	bp := tls.Alloc(2688)
  32836 	defer tls.Free(2688)
  32837 	var best_blocks, dqm, enc, mode_costs, src, src0, v3 uintptr
  32838 	var best_mode, i, kNumBlocks, lambda, mode, score, tlambda, total_header_bits, v2, v4, v5 int32
  32839 	var v9 bool
  32840 	var _ /* best_block at bp+1760 */ uintptr
  32841 	var _ /* rd_best at bp+0 */ VP8ModeScore
  32842 	var _ /* rd_i4 at bp+880 */ VP8ModeScore
  32843 	var _ /* rd_tmp at bp+1776 */ VP8ModeScore
  32844 	var _ /* tmp_dst at bp+1768 */ uintptr
  32845 	var _ /* tmp_levels at bp+2656 */ [16]int16_t
  32846 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = best_blocks, best_mode, dqm, enc, i, kNumBlocks, lambda, mode, mode_costs, score, src, src0, tlambda, total_header_bits, v2, v3, v4, v5, v9
  32847 	enc = (*VP8EncIterator)(unsafe.Pointer(it)).Fenc
  32848 	dqm = enc + 608 + uintptr(int32(uint32(*(*uint8)(unsafe.Pointer((*VP8EncIterator)(unsafe.Pointer(it)).Fmb + 0))&0x60>>5)))*744
  32849 	lambda = (*VP8SegmentInfo)(unsafe.Pointer(dqm)).Flambda_i4
  32850 	tlambda = (*VP8SegmentInfo)(unsafe.Pointer(dqm)).Ftlambda
  32851 	src0 = (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_in + uintptr(libc.Int32FromInt32(Y_OFF_ENC))
  32852 	best_blocks = (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_out2 + uintptr(libc.Int32FromInt32(Y_OFF_ENC))
  32853 	total_header_bits = 0
  32854 	if (*VP8Encoder)(unsafe.Pointer(enc)).Fmax_i4_header_bits == 0 {
  32855 		return 0
  32856 	}
  32857 	InitScore(tls, bp)
  32858 	(**(**VP8ModeScore)(__ccgo_up(bp))).FH = int64(211) // '211' is the value of VP8BitCost(0, 145)
  32859 	SetRDScore(tls, (*VP8SegmentInfo)(unsafe.Pointer(dqm)).Flambda_mode, bp)
  32860 	VP8IteratorStartI4(tls, it)
  32861 	for cond := true; cond; cond = VP8IteratorRotateI4(tls, it, best_blocks) != 0 {
  32862 		kNumBlocks = int32(1)
  32863 		best_mode = -int32(1)
  32864 		src = src0 + uintptr(VP8Scan[(*VP8EncIterator)(unsafe.Pointer(it)).Fi4])
  32865 		mode_costs = GetCostModeI4(tls, it, rd+844)
  32866 		**(**uintptr)(__ccgo_up(bp + 1760)) = best_blocks + uintptr(VP8Scan[(*VP8EncIterator)(unsafe.Pointer(it)).Fi4])
  32867 		**(**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.
  32868 		InitScore(tls, bp+880)
  32869 		MakeIntra4Preds(tls, it)
  32870 		mode = 0
  32871 		for {
  32872 			if !(mode < int32(NUM_BMODES)) {
  32873 				break
  32874 			}
  32875 			// Reconstruct
  32876 			(**(**VP8ModeScore)(__ccgo_up(bp + 1776))).Fnz = uint32(ReconstructIntra4(tls, it, bp+2656, src, **(**uintptr)(__ccgo_up(bp + 1768)), mode) << (*VP8EncIterator)(unsafe.Pointer(it)).Fi4)
  32877 			// Compute RD-score
  32878 			(**(**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))))
  32879 			if tlambda != 0 {
  32880 				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)
  32881 			} else {
  32882 				v2 = 0
  32883 			}
  32884 			(**(**VP8ModeScore)(__ccgo_up(bp + 1776))).FSD = int64(v2)
  32885 			(**(**VP8ModeScore)(__ccgo_up(bp + 1776))).FH = int64(**(**uint16_t)(__ccgo_up(mode_costs + uintptr(mode)*2)))
  32886 			// Add flatness penalty, to avoid flat area to be mispredicted
  32887 			// by a complex mode.
  32888 			if v9 = mode > 0; v9 {
  32889 				v3 = bp + 2656
  32890 				v2 = kNumBlocks
  32891 				score = 0
  32892 				for {
  32893 					v4 = v2
  32894 					v2 = v2 - 1
  32895 					if !(v4 > libc.Int32FromInt32(0)) {
  32896 						break
  32897 					}
  32898 					i = libc.Int32FromInt32(1)
  32899 					for {
  32900 						if !(i < libc.Int32FromInt32(16)) {
  32901 							break
  32902 						}
  32903 						score = score + libc.BoolInt32(int32(**(**int16_t)(__ccgo_up(v3 + uintptr(i)*2))) != 0)
  32904 						if score > int32(FLATNESS_LIMIT_I4) {
  32905 							v5 = 0
  32906 							goto _8
  32907 						}
  32908 						goto _6
  32909 					_6:
  32910 						;
  32911 						i = i + 1
  32912 					}
  32913 					v3 = v3 + uintptr(16)*2
  32914 				}
  32915 				v5 = int32(1)
  32916 				goto _8
  32917 			_8:
  32918 			}
  32919 			if v9 && v5 != 0 {
  32920 				(**(**VP8ModeScore)(__ccgo_up(bp + 1776))).FR = int64(int32(FLATNESS_PENALTY) * kNumBlocks)
  32921 			} else {
  32922 				(**(**VP8ModeScore)(__ccgo_up(bp + 1776))).FR = 0
  32923 			}
  32924 			// early-out check
  32925 			SetRDScore(tls, lambda, bp+1776)
  32926 			if best_mode >= 0 && (**(**VP8ModeScore)(__ccgo_up(bp + 1776))).Fscore >= (**(**VP8ModeScore)(__ccgo_up(bp + 880))).Fscore {
  32927 				goto _1
  32928 			}
  32929 			// finish computing score
  32930 			(**(**VP8ModeScore)(__ccgo_up(bp + 1776))).FR += int64(VP8GetCostLuma4(tls, it, bp+2656))
  32931 			SetRDScore(tls, lambda, bp+1776)
  32932 			if best_mode < 0 || (**(**VP8ModeScore)(__ccgo_up(bp + 1776))).Fscore < (**(**VP8ModeScore)(__ccgo_up(bp + 880))).Fscore {
  32933 				CopyScore(tls, bp+880, bp+1776)
  32934 				best_mode = mode
  32935 				SwapPtr(tls, bp+1768, bp+1760)
  32936 				libc.Xmemcpy(tls, bp+72+uintptr((*VP8EncIterator)(unsafe.Pointer(it)).Fi4)*32, bp+2656, uint64(32))
  32937 			}
  32938 			goto _1
  32939 		_1:
  32940 			;
  32941 			mode = mode + 1
  32942 		}
  32943 		SetRDScore(tls, (*VP8SegmentInfo)(unsafe.Pointer(dqm)).Flambda_mode, bp+880)
  32944 		AddScore(tls, bp, bp+880)
  32945 		if (**(**VP8ModeScore)(__ccgo_up(bp))).Fscore >= (*VP8ModeScore)(unsafe.Pointer(rd)).Fscore {
  32946 			return 0
  32947 		}
  32948 		total_header_bits = total_header_bits + int32((**(**VP8ModeScore)(__ccgo_up(bp + 880))).FH) // <- equal to mode_costs[best_mode];
  32949 		if total_header_bits > (*VP8Encoder)(unsafe.Pointer(enc)).Fmax_i4_header_bits {
  32950 			return 0
  32951 		}
  32952 		// Copy selected samples if not in the right place already.
  32953 		if **(**uintptr)(__ccgo_up(bp + 1760)) != best_blocks+uintptr(VP8Scan[(*VP8EncIterator)(unsafe.Pointer(it)).Fi4]) {
  32954 			(*(*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]))
  32955 		}
  32956 		**(**uint8_t)(__ccgo_up(rd + 844 + uintptr((*VP8EncIterator)(unsafe.Pointer(it)).Fi4))) = uint8(best_mode)
  32957 		if (**(**VP8ModeScore)(__ccgo_up(bp + 880))).Fnz != 0 {
  32958 			v4 = int32(1)
  32959 		} else {
  32960 			v4 = 0
  32961 		}
  32962 		v2 = v4
  32963 		**(**int32)(__ccgo_up(it + 168 + uintptr((*VP8EncIterator)(unsafe.Pointer(it)).Fi4>>int32(2))*4)) = v2
  32964 		**(**int32)(__ccgo_up(it + 132 + uintptr((*VP8EncIterator)(unsafe.Pointer(it)).Fi4&int32(3))*4)) = v2
  32965 	}
  32966 	// finalize state
  32967 	CopyScore(tls, rd, bp)
  32968 	VP8SetIntra4Mode(tls, it, rd+844)
  32969 	SwapOut(tls, it)
  32970 	libc.Xmemcpy(tls, rd+72, bp+72, uint64(512))
  32971 	return int32(1) // select intra4x4 over intra16x16
  32972 }
  32973 
  32974 //------------------------------------------------------------------------------
  32975 
  32976 func PickBestUV(tls *libc.TLS, it uintptr, rd uintptr) {
  32977 	bp := tls.Alloc(1776)
  32978 	defer tls.Free(1776)
  32979 	var dqm, dst0, src, v2 uintptr
  32980 	var i, kNumBlocks, lambda, mode, score, v3, v4, v6 int32
  32981 	var v8 bool
  32982 	var _ /* dst at bp+8 */ uintptr
  32983 	var _ /* rd_best at bp+16 */ VP8ModeScore
  32984 	var _ /* rd_uv at bp+896 */ VP8ModeScore
  32985 	var _ /* tmp_dst at bp+0 */ uintptr
  32986 	_, _, _, _, _, _, _, _, _, _, _, _, _ = dqm, dst0, i, kNumBlocks, lambda, mode, score, src, v2, v3, v4, v6, v8
  32987 	kNumBlocks = int32(8)
  32988 	dqm = (*VP8EncIterator)(unsafe.Pointer(it)).Fenc + 608 + uintptr(int32(uint32(*(*uint8)(unsafe.Pointer((*VP8EncIterator)(unsafe.Pointer(it)).Fmb + 0))&0x60>>5)))*744
  32989 	lambda = (*VP8SegmentInfo)(unsafe.Pointer(dqm)).Flambda_uv
  32990 	src = (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_in + uintptr(libc.Int32FromInt32(U_OFF_ENC))
  32991 	**(**uintptr)(__ccgo_up(bp)) = (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_out2 + uintptr(libc.Int32FromInt32(U_OFF_ENC)) // scratch buffer
  32992 	dst0 = (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_out + uintptr(libc.Int32FromInt32(U_OFF_ENC))
  32993 	**(**uintptr)(__ccgo_up(bp + 8)) = dst0
  32994 	(*VP8ModeScore)(unsafe.Pointer(rd)).Fmode_uv = -int32(1)
  32995 	InitScore(tls, bp+16)
  32996 	mode = 0
  32997 	for {
  32998 		if !(mode < int32(NUM_PRED_MODES)) {
  32999 			break
  33000 		}
  33001 		// Reconstruct
  33002 		(**(**VP8ModeScore)(__ccgo_up(bp + 896))).Fnz = uint32(ReconstructUV(tls, it, bp+896, **(**uintptr)(__ccgo_up(bp)), mode))
  33003 		// Compute RD-score
  33004 		(**(**VP8ModeScore)(__ccgo_up(bp + 896))).FD = int64((*(*func(*libc.TLS, uintptr, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{VP8SSE16x8})))(tls, src, **(**uintptr)(__ccgo_up(bp))))
  33005 		(**(**VP8ModeScore)(__ccgo_up(bp + 896))).FSD = 0 // not calling TDisto here: it tends to flatten areas.
  33006 		(**(**VP8ModeScore)(__ccgo_up(bp + 896))).FH = int64(VP8FixedCostsUV[mode])
  33007 		(**(**VP8ModeScore)(__ccgo_up(bp + 896))).FR = int64(VP8GetCostUV(tls, it, bp+896))
  33008 		if v8 = mode > 0; v8 {
  33009 			v2 = bp + 896 + 584
  33010 			v3 = kNumBlocks
  33011 			score = 0
  33012 			for {
  33013 				v4 = v3
  33014 				v3 = v3 - 1
  33015 				if !(v4 > libc.Int32FromInt32(0)) {
  33016 					break
  33017 				}
  33018 				i = libc.Int32FromInt32(1)
  33019 				for {
  33020 					if !(i < libc.Int32FromInt32(16)) {
  33021 						break
  33022 					}
  33023 					score = score + libc.BoolInt32(int32(**(**int16_t)(__ccgo_up(v2 + uintptr(i)*2))) != 0)
  33024 					if score > int32(FLATNESS_LIMIT_UV) {
  33025 						v6 = 0
  33026 						goto _7
  33027 					}
  33028 					goto _5
  33029 				_5:
  33030 					;
  33031 					i = i + 1
  33032 				}
  33033 				v2 = v2 + uintptr(16)*2
  33034 			}
  33035 			v6 = int32(1)
  33036 			goto _7
  33037 		_7:
  33038 		}
  33039 		if v8 && v6 != 0 {
  33040 			(**(**VP8ModeScore)(__ccgo_up(bp + 896))).FR += int64(int32(FLATNESS_PENALTY) * kNumBlocks)
  33041 		}
  33042 		SetRDScore(tls, lambda, bp+896)
  33043 		if mode == 0 || (**(**VP8ModeScore)(__ccgo_up(bp + 896))).Fscore < (**(**VP8ModeScore)(__ccgo_up(bp + 16))).Fscore {
  33044 			CopyScore(tls, bp+16, bp+896)
  33045 			(*VP8ModeScore)(unsafe.Pointer(rd)).Fmode_uv = mode
  33046 			libc.Xmemcpy(tls, rd+584, bp+896+584, uint64(256))
  33047 			if (*VP8EncIterator)(unsafe.Pointer(it)).Ftop_derr != libc.UintptrFromInt32(0) {
  33048 				libc.Xmemcpy(tls, rd+868, bp+896+868, uint64(6))
  33049 			}
  33050 			SwapPtr(tls, bp+8, bp)
  33051 		}
  33052 		goto _1
  33053 	_1:
  33054 		;
  33055 		mode = mode + 1
  33056 	}
  33057 	VP8SetIntraUVMode(tls, it, (*VP8ModeScore)(unsafe.Pointer(rd)).Fmode_uv)
  33058 	AddScore(tls, rd, bp+16)
  33059 	if **(**uintptr)(__ccgo_up(bp + 8)) != dst0 { // copy 16x8 block if needed
  33060 		(*(*func(*libc.TLS, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8Copy16x8})))(tls, **(**uintptr)(__ccgo_up(bp + 8)), dst0)
  33061 	}
  33062 	if (*VP8EncIterator)(unsafe.Pointer(it)).Ftop_derr != libc.UintptrFromInt32(0) { // store diffusion errors for next block
  33063 		StoreDiffusionErrors(tls, it, rd)
  33064 	}
  33065 }
  33066 
  33067 //------------------------------------------------------------------------------
  33068 // Final reconstruction and quantization.
  33069 
  33070 func SimpleQuantize(tls *libc.TLS, it uintptr, rd uintptr) {
  33071 	var dst, enc, src uintptr
  33072 	var is_i16, mode, nz int32
  33073 	_, _, _, _, _, _ = dst, enc, is_i16, mode, nz, src
  33074 	enc = (*VP8EncIterator)(unsafe.Pointer(it)).Fenc
  33075 	is_i16 = libc.BoolInt32(int32(uint32(*(*uint8)(unsafe.Pointer((*VP8EncIterator)(unsafe.Pointer(it)).Fmb + 0))&0x3>>0)) == libc.Int32FromInt32(1))
  33076 	nz = 0
  33077 	if is_i16 != 0 {
  33078 		nz = ReconstructIntra16(tls, it, rd, (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_out+uintptr(libc.Int32FromInt32(Y_OFF_ENC)), int32(**(**uint8_t)(__ccgo_up((*VP8EncIterator)(unsafe.Pointer(it)).Fpreds))))
  33079 	} else {
  33080 		VP8IteratorStartI4(tls, it)
  33081 		for cond := true; cond; cond = VP8IteratorRotateI4(tls, it, (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_out+uintptr(libc.Int32FromInt32(Y_OFF_ENC))) != 0 {
  33082 			mode = int32(**(**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))))
  33083 			src = (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_in + uintptr(libc.Int32FromInt32(Y_OFF_ENC)) + uintptr(VP8Scan[(*VP8EncIterator)(unsafe.Pointer(it)).Fi4])
  33084 			dst = (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_out + uintptr(libc.Int32FromInt32(Y_OFF_ENC)) + uintptr(VP8Scan[(*VP8EncIterator)(unsafe.Pointer(it)).Fi4])
  33085 			MakeIntra4Preds(tls, it)
  33086 			nz = nz | ReconstructIntra4(tls, it, rd+72+uintptr((*VP8EncIterator)(unsafe.Pointer(it)).Fi4)*32, src, dst, mode)<<(*VP8EncIterator)(unsafe.Pointer(it)).Fi4
  33087 		}
  33088 	}
  33089 	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)))
  33090 	(*VP8ModeScore)(unsafe.Pointer(rd)).Fnz = uint32(nz)
  33091 }
  33092 
  33093 // C documentation
  33094 //
  33095 //	// Refine intra16/intra4 sub-modes based on distortion only (not rate).
  33096 func RefineUsingDistortion(tls *libc.TLS, it uintptr, try_both_modes int32, refine_uv_mode int32, rd uintptr) {
  33097 	bp := tls.Alloc(16)
  33098 	defer tls.Free(16)
  33099 	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
  33100 	var best_i4_score, best_score, best_uv_score, bit_limit, i4_bit_sum, score, score1, score2, score_i4 score_t
  33101 	var dqm, mode_costs, ref, ref1, ref2, src1, src2, src3, tmp_dst, v3 uintptr
  33102 	var v1 int64
  33103 	var _ /* v at bp+0 */ uint32_t
  33104 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  33105 	best_score = libc.Int64FromInt64(0x7fffffffffffff)
  33106 	nz = 0
  33107 	is_i16 = libc.BoolInt32(try_both_modes != 0 || int32(uint32(*(*uint8)(unsafe.Pointer((*VP8EncIterator)(unsafe.Pointer(it)).Fmb + 0))&0x3>>0)) == int32(1))
  33108 	dqm = (*VP8EncIterator)(unsafe.Pointer(it)).Fenc + 608 + uintptr(int32(uint32(*(*uint8)(unsafe.Pointer((*VP8EncIterator)(unsafe.Pointer(it)).Fmb + 0))&0x60>>5)))*744
  33109 	// Some empiric constants, of approximate order of magnitude.
  33110 	lambda_d_i16 = int32(106)
  33111 	lambda_d_i4 = int32(11)
  33112 	lambda_d_uv = int32(120)
  33113 	score_i4 = (*VP8SegmentInfo)(unsafe.Pointer(dqm)).Fi4_penalty
  33114 	i4_bit_sum = 0
  33115 	if try_both_modes != 0 {
  33116 		v1 = int64((*VP8Encoder)(unsafe.Pointer((*VP8EncIterator)(unsafe.Pointer(it)).Fenc)).Fmb_header_limit)
  33117 	} else {
  33118 		v1 = libc.Int64FromInt64(0x7fffffffffffff)
  33119 	}
  33120 	bit_limit = v1   // no early-out allowed
  33121 	if is_i16 != 0 { // First, evaluate Intra16 distortion
  33122 		best_mode = -int32(1)
  33123 		src1 = (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_in + uintptr(libc.Int32FromInt32(Y_OFF_ENC))
  33124 		mode = 0
  33125 		for {
  33126 			if !(mode < int32(NUM_PRED_MODES)) {
  33127 				break
  33128 			}
  33129 			ref = (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_p + uintptr(VP8I16ModeOffsets[mode])
  33130 			score = int64((*(*func(*libc.TLS, uintptr, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{VP8SSE16x16})))(tls, src1, ref))*int64(RD_DISTO_MULT) + int64(int32(VP8FixedCostsI16[mode])*lambda_d_i16)
  33131 			if mode > 0 && int64(VP8FixedCostsI16[mode]) > bit_limit {
  33132 				goto _2
  33133 			}
  33134 			if score < best_score {
  33135 				best_mode = mode
  33136 				best_score = score
  33137 			}
  33138 			goto _2
  33139 		_2:
  33140 			;
  33141 			mode = mode + 1
  33142 		}
  33143 		if (*VP8EncIterator)(unsafe.Pointer(it)).Fx == 0 || (*VP8EncIterator)(unsafe.Pointer(it)).Fy == 0 {
  33144 			// avoid starting a checkerboard resonance from the border. See bug #432.
  33145 			v3 = src1
  33146 			**(**uint32_t)(__ccgo_up(bp)) = uint32(**(**uint8_t)(__ccgo_up(v3))) * uint32(0x01010101)
  33147 			i = libc.Int32FromInt32(0)
  33148 			for {
  33149 				if !(i < libc.Int32FromInt32(16)) {
  33150 					break
  33151 				}
  33152 				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 {
  33153 					v5 = 0
  33154 					goto _6
  33155 				}
  33156 				v3 = v3 + uintptr(BPS)
  33157 				goto _4
  33158 			_4:
  33159 				;
  33160 				i = i + 1
  33161 			}
  33162 			v5 = int32(1)
  33163 			goto _6
  33164 		_6:
  33165 			if v5 != 0 {
  33166 				if (*VP8EncIterator)(unsafe.Pointer(it)).Fx == 0 {
  33167 					v7 = 0
  33168 				} else {
  33169 					v7 = int32(2)
  33170 				}
  33171 				best_mode = v7
  33172 				try_both_modes = 0 // stick to i16
  33173 			}
  33174 		}
  33175 		VP8SetIntra16Mode(tls, it, best_mode)
  33176 		// we'll reconstruct later, if i16 mode actually gets selected
  33177 	}
  33178 	// Next, evaluate Intra4
  33179 	if try_both_modes != 0 || !(is_i16 != 0) {
  33180 		// We don't evaluate the rate here, but just account for it through a
  33181 		// constant penalty (i4 mode usually needs more bits compared to i16).
  33182 		is_i16 = 0
  33183 		VP8IteratorStartI4(tls, it)
  33184 		for cond := true; cond; cond = VP8IteratorRotateI4(tls, it, (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_out2+uintptr(libc.Int32FromInt32(Y_OFF_ENC))) != 0 {
  33185 			best_i4_mode = -int32(1)
  33186 			best_i4_score = libc.Int64FromInt64(0x7fffffffffffff)
  33187 			src2 = (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_in + uintptr(libc.Int32FromInt32(Y_OFF_ENC)) + uintptr(VP8Scan[(*VP8EncIterator)(unsafe.Pointer(it)).Fi4])
  33188 			mode_costs = GetCostModeI4(tls, it, rd+844)
  33189 			MakeIntra4Preds(tls, it)
  33190 			mode = 0
  33191 			for {
  33192 				if !(mode < int32(NUM_BMODES)) {
  33193 					break
  33194 				}
  33195 				ref1 = (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_p + uintptr(VP8I4ModeOffsets[mode])
  33196 				score1 = int64((*(*func(*libc.TLS, uintptr, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{VP8SSE4x4})))(tls, src2, ref1)*int32(RD_DISTO_MULT) + int32(**(**uint16_t)(__ccgo_up(mode_costs + uintptr(mode)*2)))*lambda_d_i4)
  33197 				if score1 < best_i4_score {
  33198 					best_i4_mode = mode
  33199 					best_i4_score = score1
  33200 				}
  33201 				goto _8
  33202 			_8:
  33203 				;
  33204 				mode = mode + 1
  33205 			}
  33206 			i4_bit_sum = i4_bit_sum + int64(**(**uint16_t)(__ccgo_up(mode_costs + uintptr(best_i4_mode)*2)))
  33207 			**(**uint8_t)(__ccgo_up(rd + 844 + uintptr((*VP8EncIterator)(unsafe.Pointer(it)).Fi4))) = uint8(best_i4_mode)
  33208 			score_i4 = score_i4 + best_i4_score
  33209 			if score_i4 >= best_score || i4_bit_sum > bit_limit {
  33210 				// Intra4 won't be better than Intra16. Bail out and pick Intra16.
  33211 				is_i16 = int32(1)
  33212 				break
  33213 			} else { // reconstruct partial block inside yuv_out2 buffer
  33214 				tmp_dst = (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_out2 + uintptr(libc.Int32FromInt32(Y_OFF_ENC)) + uintptr(VP8Scan[(*VP8EncIterator)(unsafe.Pointer(it)).Fi4])
  33215 				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
  33216 			}
  33217 		}
  33218 	}
  33219 	// Final reconstruction, depending on which mode is selected.
  33220 	if !(is_i16 != 0) {
  33221 		VP8SetIntra4Mode(tls, it, rd+844)
  33222 		SwapOut(tls, it)
  33223 		best_score = score_i4
  33224 	} else {
  33225 		nz = ReconstructIntra16(tls, it, rd, (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_out+uintptr(libc.Int32FromInt32(Y_OFF_ENC)), int32(**(**uint8_t)(__ccgo_up((*VP8EncIterator)(unsafe.Pointer(it)).Fpreds))))
  33226 	}
  33227 	// ... and UV!
  33228 	if refine_uv_mode != 0 {
  33229 		best_mode1 = -int32(1)
  33230 		best_uv_score = libc.Int64FromInt64(0x7fffffffffffff)
  33231 		src3 = (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_in + uintptr(libc.Int32FromInt32(U_OFF_ENC))
  33232 		mode = 0
  33233 		for {
  33234 			if !(mode < int32(NUM_PRED_MODES)) {
  33235 				break
  33236 			}
  33237 			ref2 = (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_p + uintptr(VP8UVModeOffsets[mode])
  33238 			score2 = int64((*(*func(*libc.TLS, uintptr, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{VP8SSE16x8})))(tls, src3, ref2)*int32(RD_DISTO_MULT) + int32(VP8FixedCostsUV[mode])*lambda_d_uv)
  33239 			if score2 < best_uv_score {
  33240 				best_mode1 = mode
  33241 				best_uv_score = score2
  33242 			}
  33243 			goto _9
  33244 		_9:
  33245 			;
  33246 			mode = mode + 1
  33247 		}
  33248 		VP8SetIntraUVMode(tls, it, best_mode1)
  33249 	}
  33250 	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)))
  33251 	(*VP8ModeScore)(unsafe.Pointer(rd)).Fnz = uint32(nz)
  33252 	(*VP8ModeScore)(unsafe.Pointer(rd)).Fscore = best_score
  33253 }
  33254 
  33255 //------------------------------------------------------------------------------
  33256 // Entry point
  33257 
  33258 func VP8Decimate(tls *libc.TLS, it uintptr, rd uintptr, rd_opt VP8RDLevel) (r int32) {
  33259 	var is_skipped, method int32
  33260 	_, _ = is_skipped, method
  33261 	method = (*VP8Encoder)(unsafe.Pointer((*VP8EncIterator)(unsafe.Pointer(it)).Fenc)).Fmethod
  33262 	InitScore(tls, rd)
  33263 	// We can perform predictions for Luma16x16 and Chroma8x8 already.
  33264 	// Luma4x4 predictions needs to be done as-we-go.
  33265 	VP8MakeLuma16Preds(tls, it)
  33266 	VP8MakeChroma8Preds(tls, it)
  33267 	if rd_opt > int32(RD_OPT_NONE) {
  33268 		(*VP8EncIterator)(unsafe.Pointer(it)).Fdo_trellis = libc.BoolInt32(rd_opt >= int32(RD_OPT_TRELLIS_ALL))
  33269 		PickBestIntra16(tls, it, rd)
  33270 		if method >= int32(2) {
  33271 			PickBestIntra4(tls, it, rd)
  33272 		}
  33273 		PickBestUV(tls, it, rd)
  33274 		if rd_opt == int32(RD_OPT_TRELLIS) { // finish off with trellis-optim now
  33275 			(*VP8EncIterator)(unsafe.Pointer(it)).Fdo_trellis = int32(1)
  33276 			SimpleQuantize(tls, it, rd)
  33277 		}
  33278 	} else {
  33279 		// At this point we have heuristically decided intra16 / intra4.
  33280 		// For method >= 2, pick the best intra4/intra16 based on SSE (~tad slower).
  33281 		// For method <= 1, we don't re-examine the decision but just go ahead with
  33282 		// quantization/reconstruction.
  33283 		RefineUsingDistortion(tls, it, libc.BoolInt32(method >= int32(2)), libc.BoolInt32(method >= int32(1)), rd)
  33284 	}
  33285 	is_skipped = libc.BoolInt32((*VP8ModeScore)(unsafe.Pointer(rd)).Fnz == uint32(0))
  33286 	VP8SetSkip(tls, it, is_skipped)
  33287 	return is_skipped
  33288 }
  33289 
  33290 const ARGB_BLACK2 = 0xff000000
  33291 const SIZE_MAX13 = "UINT64_MAX"
  33292 const VP8_SIGNATURE1 = 10289450
  33293 
  33294 //------------------------------------------------------------------------------
  33295 // Helper functions
  33296 
  33297 func IsVP8XNeeded(tls *libc.TLS, enc uintptr) (r int32) {
  33298 	return libc.BoolInt32(!!((*VP8Encoder)(unsafe.Pointer(enc)).Fhas_alpha != 0)) // Currently the only case when VP8X is needed.
  33299 	// This could change in the future.
  33300 }
  33301 
  33302 func PutPaddingByte(tls *libc.TLS, pic uintptr) (r int32) {
  33303 	bp := tls.Alloc(16)
  33304 	defer tls.Free(16)
  33305 	var _ /* pad_byte at bp+0 */ [1]uint8_t
  33306 	**(**[1]uint8_t)(__ccgo_up(bp)) = [1]uint8_t{}
  33307 	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))
  33308 }
  33309 
  33310 //------------------------------------------------------------------------------
  33311 // Writers for header's various pieces (in order of appearance)
  33312 
  33313 func PutRIFFHeader(tls *libc.TLS, enc uintptr, riff_size size_t) (r WebPEncodingError1) {
  33314 	bp := tls.Alloc(16)
  33315 	defer tls.Free(16)
  33316 	var pic, v1, v3, v5 uintptr
  33317 	var v2 uint32_t
  33318 	var v4, v6 int32
  33319 	var _ /* riff at bp+0 */ [12]uint8_t
  33320 	_, _, _, _, _, _, _ = pic, v1, v2, v3, v4, v5, v6
  33321 	pic = (*VP8Encoder)(unsafe.Pointer(enc)).Fpic
  33322 	**(**[12]uint8_t)(__ccgo_up(bp)) = [12]uint8_t{
  33323 		0:  uint8('R'),
  33324 		1:  uint8('I'),
  33325 		2:  uint8('F'),
  33326 		3:  uint8('F'),
  33327 		8:  uint8('W'),
  33328 		9:  uint8('E'),
  33329 		10: uint8('B'),
  33330 		11: uint8('P'),
  33331 	}
  33332 	v1 = bp + uintptr(TAG_SIZE)
  33333 	v2 = uint32(riff_size)
  33334 	v3 = v1
  33335 	v4 = int32(v2 & libc.Uint32FromInt32(0xffff))
  33336 	**(**uint8_t)(__ccgo_up(v3)) = uint8(v4 >> 0 & int32(0xff))
  33337 	**(**uint8_t)(__ccgo_up(v3 + 1)) = uint8(v4 >> int32(8) & int32(0xff))
  33338 	v5 = v1 + uintptr(2)
  33339 	v6 = int32(v2 >> libc.Int32FromInt32(16))
  33340 	**(**uint8_t)(__ccgo_up(v5)) = uint8(v6 >> 0 & int32(0xff))
  33341 	**(**uint8_t)(__ccgo_up(v5 + 1)) = uint8(v6 >> int32(8) & int32(0xff))
  33342 	if !((*(*func(*libc.TLS, uintptr, size_t, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*WebPPicture)(unsafe.Pointer(pic)).Fwriter})))(tls, bp, uint64(12), pic) != 0) {
  33343 		return int32(VP8_ENC_ERROR_BAD_WRITE)
  33344 	}
  33345 	return int32(VP8_ENC_OK)
  33346 }
  33347 
  33348 func PutVP8XHeader(tls *libc.TLS, enc uintptr) (r WebPEncodingError1) {
  33349 	bp := tls.Alloc(32)
  33350 	defer tls.Free(32)
  33351 	var flags, v2 uint32_t
  33352 	var pic, v1, v3, v5 uintptr
  33353 	var v4, v6 int32
  33354 	var _ /* vp8x at bp+0 */ [18]uint8_t
  33355 	_, _, _, _, _, _, _, _ = flags, pic, v1, v2, v3, v4, v5, v6
  33356 	pic = (*VP8Encoder)(unsafe.Pointer(enc)).Fpic
  33357 	**(**[18]uint8_t)(__ccgo_up(bp)) = [18]uint8_t{
  33358 		0: uint8('V'),
  33359 		1: uint8('P'),
  33360 		2: uint8('8'),
  33361 		3: uint8('X'),
  33362 	}
  33363 	flags = uint32(0)
  33364 	if (*VP8Encoder)(unsafe.Pointer(enc)).Fhas_alpha != 0 {
  33365 		flags = flags | uint32(ALPHA_FLAG)
  33366 	}
  33367 	v1 = bp + uintptr(TAG_SIZE)
  33368 	v2 = uint32(VP8X_CHUNK_SIZE)
  33369 	v3 = v1
  33370 	v4 = int32(v2 & libc.Uint32FromInt32(0xffff))
  33371 	**(**uint8_t)(__ccgo_up(v3)) = uint8(v4 >> 0 & int32(0xff))
  33372 	**(**uint8_t)(__ccgo_up(v3 + 1)) = uint8(v4 >> int32(8) & int32(0xff))
  33373 	v5 = v1 + uintptr(2)
  33374 	v6 = int32(v2 >> libc.Int32FromInt32(16))
  33375 	**(**uint8_t)(__ccgo_up(v5)) = uint8(v6 >> 0 & int32(0xff))
  33376 	**(**uint8_t)(__ccgo_up(v5 + 1)) = uint8(v6 >> int32(8) & int32(0xff))
  33377 	v1 = bp + uintptr(CHUNK_HEADER_SIZE)
  33378 	v2 = flags
  33379 	v3 = v1
  33380 	v4 = int32(v2 & libc.Uint32FromInt32(0xffff))
  33381 	**(**uint8_t)(__ccgo_up(v3)) = uint8(v4 >> 0 & int32(0xff))
  33382 	**(**uint8_t)(__ccgo_up(v3 + 1)) = uint8(v4 >> int32(8) & int32(0xff))
  33383 	v5 = v1 + uintptr(2)
  33384 	v6 = int32(v2 >> libc.Int32FromInt32(16))
  33385 	**(**uint8_t)(__ccgo_up(v5)) = uint8(v6 >> 0 & int32(0xff))
  33386 	**(**uint8_t)(__ccgo_up(v5 + 1)) = uint8(v6 >> int32(8) & int32(0xff))
  33387 	v1 = bp + uintptr(CHUNK_HEADER_SIZE) + uintptr(4)
  33388 	v4 = (*WebPPicture)(unsafe.Pointer(pic)).Fwidth - int32(1)
  33389 	v3 = v1
  33390 	v6 = v4 & int32(0xffff)
  33391 	**(**uint8_t)(__ccgo_up(v3)) = uint8(v6 >> 0 & int32(0xff))
  33392 	**(**uint8_t)(__ccgo_up(v3 + 1)) = uint8(v6 >> int32(8) & int32(0xff))
  33393 	**(**uint8_t)(__ccgo_up(v1 + 2)) = uint8(v4 >> int32(16) & int32(0xff))
  33394 	v1 = bp + uintptr(CHUNK_HEADER_SIZE) + uintptr(7)
  33395 	v4 = (*WebPPicture)(unsafe.Pointer(pic)).Fheight - int32(1)
  33396 	v3 = v1
  33397 	v6 = v4 & int32(0xffff)
  33398 	**(**uint8_t)(__ccgo_up(v3)) = uint8(v6 >> 0 & int32(0xff))
  33399 	**(**uint8_t)(__ccgo_up(v3 + 1)) = uint8(v6 >> int32(8) & int32(0xff))
  33400 	**(**uint8_t)(__ccgo_up(v1 + 2)) = uint8(v4 >> int32(16) & int32(0xff))
  33401 	if !((*(*func(*libc.TLS, uintptr, size_t, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*WebPPicture)(unsafe.Pointer(pic)).Fwriter})))(tls, bp, uint64(18), pic) != 0) {
  33402 		return int32(VP8_ENC_ERROR_BAD_WRITE)
  33403 	}
  33404 	return int32(VP8_ENC_OK)
  33405 }
  33406 
  33407 func PutAlphaChunk(tls *libc.TLS, enc uintptr) (r WebPEncodingError1) {
  33408 	bp := tls.Alloc(16)
  33409 	defer tls.Free(16)
  33410 	var pic, v1, v3, v5 uintptr
  33411 	var v2 uint32_t
  33412 	var v4, v6 int32
  33413 	var _ /* alpha_chunk_hdr at bp+0 */ [8]uint8_t
  33414 	_, _, _, _, _, _, _ = pic, v1, v2, v3, v4, v5, v6
  33415 	pic = (*VP8Encoder)(unsafe.Pointer(enc)).Fpic
  33416 	**(**[8]uint8_t)(__ccgo_up(bp)) = [8]uint8_t{
  33417 		0: uint8('A'),
  33418 		1: uint8('L'),
  33419 		2: uint8('P'),
  33420 		3: uint8('H'),
  33421 	}
  33422 	// Alpha chunk header.
  33423 	v1 = bp + uintptr(TAG_SIZE)
  33424 	v2 = (*VP8Encoder)(unsafe.Pointer(enc)).Falpha_data_size
  33425 	v3 = v1
  33426 	v4 = int32(v2 & libc.Uint32FromInt32(0xffff))
  33427 	**(**uint8_t)(__ccgo_up(v3)) = uint8(v4 >> 0 & int32(0xff))
  33428 	**(**uint8_t)(__ccgo_up(v3 + 1)) = uint8(v4 >> int32(8) & int32(0xff))
  33429 	v5 = v1 + uintptr(2)
  33430 	v6 = int32(v2 >> libc.Int32FromInt32(16))
  33431 	**(**uint8_t)(__ccgo_up(v5)) = uint8(v6 >> 0 & int32(0xff))
  33432 	**(**uint8_t)(__ccgo_up(v5 + 1)) = uint8(v6 >> int32(8) & int32(0xff))
  33433 	if !((*(*func(*libc.TLS, uintptr, size_t, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*WebPPicture)(unsafe.Pointer(pic)).Fwriter})))(tls, bp, uint64(8), pic) != 0) {
  33434 		return int32(VP8_ENC_ERROR_BAD_WRITE)
  33435 	}
  33436 	// Alpha chunk data.
  33437 	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) {
  33438 		return int32(VP8_ENC_ERROR_BAD_WRITE)
  33439 	}
  33440 	// Padding.
  33441 	if (*VP8Encoder)(unsafe.Pointer(enc)).Falpha_data_size&uint32(1) != 0 && !(PutPaddingByte(tls, pic) != 0) {
  33442 		return int32(VP8_ENC_ERROR_BAD_WRITE)
  33443 	}
  33444 	return int32(VP8_ENC_OK)
  33445 }
  33446 
  33447 func PutVP8Header(tls *libc.TLS, pic uintptr, vp8_size size_t) (r WebPEncodingError1) {
  33448 	bp := tls.Alloc(16)
  33449 	defer tls.Free(16)
  33450 	var v1, v3, v5 uintptr
  33451 	var v2 uint32_t
  33452 	var v4, v6 int32
  33453 	var _ /* vp8_chunk_hdr at bp+0 */ [8]uint8_t
  33454 	_, _, _, _, _, _ = v1, v2, v3, v4, v5, v6
  33455 	**(**[8]uint8_t)(__ccgo_up(bp)) = [8]uint8_t{
  33456 		0: uint8('V'),
  33457 		1: uint8('P'),
  33458 		2: uint8('8'),
  33459 		3: uint8(' '),
  33460 	}
  33461 	v1 = bp + uintptr(TAG_SIZE)
  33462 	v2 = uint32(vp8_size)
  33463 	v3 = v1
  33464 	v4 = int32(v2 & libc.Uint32FromInt32(0xffff))
  33465 	**(**uint8_t)(__ccgo_up(v3)) = uint8(v4 >> 0 & int32(0xff))
  33466 	**(**uint8_t)(__ccgo_up(v3 + 1)) = uint8(v4 >> int32(8) & int32(0xff))
  33467 	v5 = v1 + uintptr(2)
  33468 	v6 = int32(v2 >> libc.Int32FromInt32(16))
  33469 	**(**uint8_t)(__ccgo_up(v5)) = uint8(v6 >> 0 & int32(0xff))
  33470 	**(**uint8_t)(__ccgo_up(v5 + 1)) = uint8(v6 >> int32(8) & int32(0xff))
  33471 	if !((*(*func(*libc.TLS, uintptr, size_t, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*WebPPicture)(unsafe.Pointer(pic)).Fwriter})))(tls, bp, uint64(8), pic) != 0) {
  33472 		return int32(VP8_ENC_ERROR_BAD_WRITE)
  33473 	}
  33474 	return int32(VP8_ENC_OK)
  33475 }
  33476 
  33477 func PutVP8FrameHeader(tls *libc.TLS, pic uintptr, profile int32, size0 size_t) (r WebPEncodingError1) {
  33478 	bp := tls.Alloc(16)
  33479 	defer tls.Free(16)
  33480 	var bits uint32_t
  33481 	var _ /* vp8_frm_hdr at bp+0 */ [10]uint8_t
  33482 	_ = bits
  33483 	if size0 >= uint64(libc.Int32FromInt32(1)<<libc.Int32FromInt32(19)) { // partition #0 is too big to fit
  33484 		return int32(VP8_ENC_ERROR_PARTITION0_OVERFLOW)
  33485 	}
  33486 	// Paragraph 9.1.
  33487 	bits = uint32(0|profile<<int32(1)|libc.Int32FromInt32(1)<<libc.Int32FromInt32(4)) | uint32(size0)<<libc.Int32FromInt32(5) // partition length (19b)
  33488 	(**(**[10]uint8_t)(__ccgo_up(bp)))[0] = uint8(bits >> libc.Int32FromInt32(0) & uint32(0xff))
  33489 	(**(**[10]uint8_t)(__ccgo_up(bp)))[int32(1)] = uint8(bits >> libc.Int32FromInt32(8) & uint32(0xff))
  33490 	(**(**[10]uint8_t)(__ccgo_up(bp)))[int32(2)] = uint8(bits >> libc.Int32FromInt32(16) & uint32(0xff))
  33491 	// signature
  33492 	(**(**[10]uint8_t)(__ccgo_up(bp)))[int32(3)] = uint8(libc.Int32FromInt32(VP8_SIGNATURE1) >> libc.Int32FromInt32(16) & libc.Int32FromInt32(0xff))
  33493 	(**(**[10]uint8_t)(__ccgo_up(bp)))[int32(4)] = uint8(libc.Int32FromInt32(VP8_SIGNATURE1) >> libc.Int32FromInt32(8) & libc.Int32FromInt32(0xff))
  33494 	(**(**[10]uint8_t)(__ccgo_up(bp)))[int32(5)] = uint8(libc.Int32FromInt32(VP8_SIGNATURE1) >> libc.Int32FromInt32(0) & libc.Int32FromInt32(0xff))
  33495 	// dimensions
  33496 	(**(**[10]uint8_t)(__ccgo_up(bp)))[int32(6)] = uint8((*WebPPicture)(unsafe.Pointer(pic)).Fwidth & int32(0xff))
  33497 	(**(**[10]uint8_t)(__ccgo_up(bp)))[int32(7)] = uint8((*WebPPicture)(unsafe.Pointer(pic)).Fwidth >> int32(8))
  33498 	(**(**[10]uint8_t)(__ccgo_up(bp)))[int32(8)] = uint8((*WebPPicture)(unsafe.Pointer(pic)).Fheight & int32(0xff))
  33499 	(**(**[10]uint8_t)(__ccgo_up(bp)))[int32(9)] = uint8((*WebPPicture)(unsafe.Pointer(pic)).Fheight >> int32(8))
  33500 	if !((*(*func(*libc.TLS, uintptr, size_t, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*WebPPicture)(unsafe.Pointer(pic)).Fwriter})))(tls, bp, uint64(10), pic) != 0) {
  33501 		return int32(VP8_ENC_ERROR_BAD_WRITE)
  33502 	}
  33503 	return int32(VP8_ENC_OK)
  33504 }
  33505 
  33506 // C documentation
  33507 //
  33508 //	// WebP Headers.
  33509 func PutWebPHeaders(tls *libc.TLS, enc uintptr, size0 size_t, vp8_size size_t, riff_size size_t) (r int32) {
  33510 	var err WebPEncodingError1
  33511 	var pic uintptr
  33512 	_, _ = err, pic
  33513 	pic = (*VP8Encoder)(unsafe.Pointer(enc)).Fpic
  33514 	err = int32(VP8_ENC_OK)
  33515 	// RIFF header.
  33516 	err = PutRIFFHeader(tls, enc, riff_size)
  33517 	if err != int32(VP8_ENC_OK) {
  33518 		goto Error
  33519 	}
  33520 	// VP8X.
  33521 	if IsVP8XNeeded(tls, enc) != 0 {
  33522 		err = PutVP8XHeader(tls, enc)
  33523 		if err != int32(VP8_ENC_OK) {
  33524 			goto Error
  33525 		}
  33526 	}
  33527 	// Alpha.
  33528 	if (*VP8Encoder)(unsafe.Pointer(enc)).Fhas_alpha != 0 {
  33529 		err = PutAlphaChunk(tls, enc)
  33530 		if err != int32(VP8_ENC_OK) {
  33531 			goto Error
  33532 		}
  33533 	}
  33534 	// VP8 header.
  33535 	err = PutVP8Header(tls, pic, vp8_size)
  33536 	if err != int32(VP8_ENC_OK) {
  33537 		goto Error
  33538 	}
  33539 	// VP8 frame header.
  33540 	err = PutVP8FrameHeader(tls, pic, (*VP8Encoder)(unsafe.Pointer(enc)).Fprofile, size0)
  33541 	if err != int32(VP8_ENC_OK) {
  33542 		goto Error
  33543 	}
  33544 	// All OK.
  33545 	return int32(1)
  33546 	// Error.
  33547 	goto Error
  33548 Error:
  33549 	;
  33550 	return WebPEncodingSetError(tls, pic, err)
  33551 	return r
  33552 }
  33553 
  33554 // C documentation
  33555 //
  33556 //	// Segmentation header
  33557 func PutSegmentHeader(tls *libc.TLS, bw uintptr, enc uintptr) {
  33558 	var hdr, proba uintptr
  33559 	var s, update_data int32
  33560 	_, _, _, _ = hdr, proba, s, update_data
  33561 	hdr = enc + 32
  33562 	proba = enc + 3616
  33563 	if VP8PutBitUniform(tls, bw, libc.BoolInt32((*VP8EncSegmentHeader)(unsafe.Pointer(hdr)).Fnum_segments > int32(1))) != 0 {
  33564 		// We always 'update' the quant and filter strength values
  33565 		update_data = int32(1)
  33566 		VP8PutBitUniform(tls, bw, (*VP8EncSegmentHeader)(unsafe.Pointer(hdr)).Fupdate_map)
  33567 		if VP8PutBitUniform(tls, bw, update_data) != 0 {
  33568 			// we always use absolute values, not relative ones
  33569 			VP8PutBitUniform(tls, bw, int32(1)) // (segment_feature_mode = 1. Paragraph 9.3.)
  33570 			s = 0
  33571 			for {
  33572 				if !(s < int32(NUM_MB_SEGMENTS)) {
  33573 					break
  33574 				}
  33575 				VP8PutSignedBits(tls, bw, (**(**VP8SegmentInfo)(__ccgo_up(enc + 608 + uintptr(s)*744))).Fquant, int32(7))
  33576 				goto _1
  33577 			_1:
  33578 				;
  33579 				s = s + 1
  33580 			}
  33581 			s = 0
  33582 			for {
  33583 				if !(s < int32(NUM_MB_SEGMENTS)) {
  33584 					break
  33585 				}
  33586 				VP8PutSignedBits(tls, bw, (**(**VP8SegmentInfo)(__ccgo_up(enc + 608 + uintptr(s)*744))).Ffstrength, int32(6))
  33587 				goto _2
  33588 			_2:
  33589 				;
  33590 				s = s + 1
  33591 			}
  33592 		}
  33593 		if (*VP8EncSegmentHeader)(unsafe.Pointer(hdr)).Fupdate_map != 0 {
  33594 			s = 0
  33595 			for {
  33596 				if !(s < int32(3)) {
  33597 					break
  33598 				}
  33599 				if VP8PutBitUniform(tls, bw, libc.BoolInt32(uint32(**(**uint8_t)(__ccgo_up(proba + uintptr(s)))) != uint32(255))) != 0 {
  33600 					VP8PutBits(tls, bw, uint32(**(**uint8_t)(__ccgo_up(proba + uintptr(s)))), int32(8))
  33601 				}
  33602 				goto _3
  33603 			_3:
  33604 				;
  33605 				s = s + 1
  33606 			}
  33607 		}
  33608 	}
  33609 }
  33610 
  33611 // C documentation
  33612 //
  33613 //	// Filtering parameters header
  33614 func PutFilterHeader(tls *libc.TLS, bw uintptr, hdr uintptr) {
  33615 	var need_update, use_lf_delta int32
  33616 	_, _ = need_update, use_lf_delta
  33617 	use_lf_delta = libc.BoolInt32((*VP8EncFilterHeader)(unsafe.Pointer(hdr)).Fi4x4_lf_delta != libc.Int32FromInt32(0))
  33618 	VP8PutBitUniform(tls, bw, (*VP8EncFilterHeader)(unsafe.Pointer(hdr)).Fsimple)
  33619 	VP8PutBits(tls, bw, uint32((*VP8EncFilterHeader)(unsafe.Pointer(hdr)).Flevel), int32(6))
  33620 	VP8PutBits(tls, bw, uint32((*VP8EncFilterHeader)(unsafe.Pointer(hdr)).Fsharpness), int32(3))
  33621 	if VP8PutBitUniform(tls, bw, use_lf_delta) != 0 {
  33622 		// '0' is the default value for i4x4_lf_delta at frame #0.
  33623 		need_update = libc.BoolInt32((*VP8EncFilterHeader)(unsafe.Pointer(hdr)).Fi4x4_lf_delta != libc.Int32FromInt32(0))
  33624 		if VP8PutBitUniform(tls, bw, need_update) != 0 {
  33625 			// we don't use ref_lf_delta => emit four 0 bits
  33626 			VP8PutBits(tls, bw, uint32(0), int32(4))
  33627 			// we use mode_lf_delta for i4x4
  33628 			VP8PutSignedBits(tls, bw, (*VP8EncFilterHeader)(unsafe.Pointer(hdr)).Fi4x4_lf_delta, int32(6))
  33629 			VP8PutBits(tls, bw, uint32(0), int32(3)) // all others unused
  33630 		}
  33631 	}
  33632 }
  33633 
  33634 // C documentation
  33635 //
  33636 //	// Nominal quantization parameters
  33637 func PutQuant(tls *libc.TLS, bw uintptr, enc uintptr) {
  33638 	VP8PutBits(tls, bw, uint32((*VP8Encoder)(unsafe.Pointer(enc)).Fbase_quant), int32(7))
  33639 	VP8PutSignedBits(tls, bw, (*VP8Encoder)(unsafe.Pointer(enc)).Fdq_y1_dc, int32(4))
  33640 	VP8PutSignedBits(tls, bw, (*VP8Encoder)(unsafe.Pointer(enc)).Fdq_y2_dc, int32(4))
  33641 	VP8PutSignedBits(tls, bw, (*VP8Encoder)(unsafe.Pointer(enc)).Fdq_y2_ac, int32(4))
  33642 	VP8PutSignedBits(tls, bw, (*VP8Encoder)(unsafe.Pointer(enc)).Fdq_uv_dc, int32(4))
  33643 	VP8PutSignedBits(tls, bw, (*VP8Encoder)(unsafe.Pointer(enc)).Fdq_uv_ac, int32(4))
  33644 }
  33645 
  33646 // C documentation
  33647 //
  33648 //	// Partition sizes
  33649 func EmitPartitionsSize(tls *libc.TLS, enc uintptr, pic uintptr) (r int32) {
  33650 	bp := tls.Alloc(32)
  33651 	defer tls.Free(32)
  33652 	var p int32
  33653 	var part_size, v2 size_t
  33654 	var _ /* buf at bp+0 */ [21]uint8_t
  33655 	_, _, _ = p, part_size, v2
  33656 	p = 0
  33657 	for {
  33658 		if !(p < (*VP8Encoder)(unsafe.Pointer(enc)).Fnum_parts-int32(1)) {
  33659 			break
  33660 		}
  33661 		v2 = (*VP8BitWriter)(unsafe.Pointer(enc + 112 + uintptr(p)*48)).Fpos
  33662 		goto _3
  33663 	_3:
  33664 		part_size = v2
  33665 		if part_size >= uint64(libc.Int32FromInt32(1)<<libc.Int32FromInt32(24)) {
  33666 			return WebPEncodingSetError(tls, pic, int32(VP8_ENC_ERROR_PARTITION_OVERFLOW))
  33667 		}
  33668 		(**(**[21]uint8_t)(__ccgo_up(bp)))[int32(3)*p+0] = uint8(part_size >> libc.Int32FromInt32(0) & uint64(0xff))
  33669 		(**(**[21]uint8_t)(__ccgo_up(bp)))[int32(3)*p+int32(1)] = uint8(part_size >> libc.Int32FromInt32(8) & uint64(0xff))
  33670 		(**(**[21]uint8_t)(__ccgo_up(bp)))[int32(3)*p+int32(2)] = uint8(part_size >> libc.Int32FromInt32(16) & uint64(0xff))
  33671 		goto _1
  33672 	_1:
  33673 		;
  33674 		p = p + 1
  33675 	}
  33676 	if p != 0 && !((*(*func(*libc.TLS, uintptr, size_t, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*WebPPicture)(unsafe.Pointer(pic)).Fwriter})))(tls, bp, uint64(int32(3)*p), pic) != 0) {
  33677 		return WebPEncodingSetError(tls, pic, int32(VP8_ENC_ERROR_BAD_WRITE))
  33678 	}
  33679 	return int32(1)
  33680 }
  33681 
  33682 //------------------------------------------------------------------------------
  33683 
  33684 func GeneratePartition0(tls *libc.TLS, enc uintptr) (r int32) {
  33685 	var bw1, v1 uintptr
  33686 	var mb_size, v4, v5, v6 int32
  33687 	var nb_bits, pos1, pos2, pos3, v2 uint64_t
  33688 	_, _, _, _, _, _, _, _, _, _, _ = bw1, mb_size, nb_bits, pos1, pos2, pos3, v1, v2, v4, v5, v6
  33689 	bw1 = enc + 64
  33690 	mb_size = (*VP8Encoder)(unsafe.Pointer(enc)).Fmb_w * (*VP8Encoder)(unsafe.Pointer(enc)).Fmb_h
  33691 	v1 = bw1
  33692 	nb_bits = uint64(int32(8) + (*VP8BitWriter)(unsafe.Pointer(v1)).Fnb_bits)
  33693 	v2 = ((*VP8BitWriter)(unsafe.Pointer(v1)).Fpos+uint64((*VP8BitWriter)(unsafe.Pointer(v1)).Frun))*uint64(8) + nb_bits
  33694 	goto _3
  33695 _3:
  33696 	pos1 = v2
  33697 	if !(VP8BitWriterInit(tls, bw1, uint64(mb_size*int32(7)/int32(8))) != 0) { // ~7 bits per macroblock
  33698 		return WebPEncodingSetError(tls, (*VP8Encoder)(unsafe.Pointer(enc)).Fpic, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  33699 	}
  33700 	VP8PutBitUniform(tls, bw1, 0) // colorspace
  33701 	VP8PutBitUniform(tls, bw1, 0) // clamp type
  33702 	PutSegmentHeader(tls, bw1, enc)
  33703 	PutFilterHeader(tls, bw1, enc+16)
  33704 	if (*VP8Encoder)(unsafe.Pointer(enc)).Fnum_parts == int32(8) {
  33705 		v4 = int32(3)
  33706 	} else {
  33707 		if (*VP8Encoder)(unsafe.Pointer(enc)).Fnum_parts == int32(4) {
  33708 			v5 = int32(2)
  33709 		} else {
  33710 			if (*VP8Encoder)(unsafe.Pointer(enc)).Fnum_parts == int32(2) {
  33711 				v6 = int32(1)
  33712 			} else {
  33713 				v6 = 0
  33714 			}
  33715 			v5 = v6
  33716 		}
  33717 		v4 = v5
  33718 	}
  33719 	VP8PutBits(tls, bw1, uint32(v4), int32(2))
  33720 	PutQuant(tls, bw1, enc)
  33721 	VP8PutBitUniform(tls, bw1, 0) // no proba update
  33722 	VP8WriteProbas(tls, bw1, enc+3616)
  33723 	v1 = bw1
  33724 	nb_bits = uint64(int32(8) + (*VP8BitWriter)(unsafe.Pointer(v1)).Fnb_bits)
  33725 	v2 = ((*VP8BitWriter)(unsafe.Pointer(v1)).Fpos+uint64((*VP8BitWriter)(unsafe.Pointer(v1)).Frun))*uint64(8) + nb_bits
  33726 	goto _9
  33727 _9:
  33728 	pos2 = v2
  33729 	VP8CodeIntraModes(tls, enc)
  33730 	VP8BitWriterFinish(tls, bw1)
  33731 	v1 = bw1
  33732 	nb_bits = uint64(int32(8) + (*VP8BitWriter)(unsafe.Pointer(v1)).Fnb_bits)
  33733 	v2 = ((*VP8BitWriter)(unsafe.Pointer(v1)).Fpos+uint64((*VP8BitWriter)(unsafe.Pointer(v1)).Frun))*uint64(8) + nb_bits
  33734 	goto _12
  33735 _12:
  33736 	pos3 = v2
  33737 	if (*WebPPicture)(unsafe.Pointer((*VP8Encoder)(unsafe.Pointer(enc)).Fpic)).Fstats != 0 {
  33738 		**(**int32)(__ccgo_up((*WebPPicture)(unsafe.Pointer((*VP8Encoder)(unsafe.Pointer(enc)).Fpic)).Fstats + 36)) = int32((pos2 - pos1 + libc.Uint64FromInt32(7)) >> libc.Int32FromInt32(3))
  33739 		**(**int32)(__ccgo_up((*WebPPicture)(unsafe.Pointer((*VP8Encoder)(unsafe.Pointer(enc)).Fpic)).Fstats + 36 + 1*4)) = int32((pos3 - pos2 + libc.Uint64FromInt32(7)) >> libc.Int32FromInt32(3))
  33740 		(*WebPAuxStats)(unsafe.Pointer((*WebPPicture)(unsafe.Pointer((*VP8Encoder)(unsafe.Pointer(enc)).Fpic)).Fstats)).Falpha_data_size = int32((*VP8Encoder)(unsafe.Pointer(enc)).Falpha_data_size)
  33741 	}
  33742 	if (*VP8BitWriter)(unsafe.Pointer(bw1)).Ferror1 != 0 {
  33743 		return WebPEncodingSetError(tls, (*VP8Encoder)(unsafe.Pointer(enc)).Fpic, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  33744 	}
  33745 	return int32(1)
  33746 }
  33747 
  33748 func VP8EncFreeBitWriters(tls *libc.TLS, enc uintptr) {
  33749 	var p int32
  33750 	_ = p
  33751 	VP8BitWriterWipeOut(tls, enc+64)
  33752 	p = 0
  33753 	for {
  33754 		if !(p < (*VP8Encoder)(unsafe.Pointer(enc)).Fnum_parts) {
  33755 			break
  33756 		}
  33757 		VP8BitWriterWipeOut(tls, enc+112+uintptr(p)*48)
  33758 		goto _1
  33759 	_1:
  33760 		;
  33761 		p = p + 1
  33762 	}
  33763 }
  33764 
  33765 func VP8EncWrite(tls *libc.TLS, enc uintptr) (r int32) {
  33766 	var buf, bw2, part0, pic, v6 uintptr
  33767 	var final_percent, ok, p, percent_per_part, task_percent int32
  33768 	var pad, riff_size, size, size0, vp8_size, v1 size_t
  33769 	var padded_alpha_size uint32_t
  33770 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  33771 	pic = (*VP8Encoder)(unsafe.Pointer(enc)).Fpic
  33772 	bw2 = enc + 64
  33773 	task_percent = int32(19)
  33774 	percent_per_part = task_percent / (*VP8Encoder)(unsafe.Pointer(enc)).Fnum_parts
  33775 	final_percent = (*VP8Encoder)(unsafe.Pointer(enc)).Fpercent + task_percent
  33776 	ok = 0
  33777 	// Partition #0 with header and partition sizes
  33778 	ok = GeneratePartition0(tls, enc)
  33779 	if !(ok != 0) {
  33780 		return 0
  33781 	}
  33782 	// Compute VP8 size
  33783 	v1 = (*VP8BitWriter)(unsafe.Pointer(bw2)).Fpos
  33784 	goto _2
  33785 _2:
  33786 	vp8_size = uint64(VP8_FRAME_HEADER_SIZE) + v1 + uint64(int32(3)*((*VP8Encoder)(unsafe.Pointer(enc)).Fnum_parts-int32(1)))
  33787 	p = 0
  33788 	for {
  33789 		if !(p < (*VP8Encoder)(unsafe.Pointer(enc)).Fnum_parts) {
  33790 			break
  33791 		}
  33792 		v1 = (*VP8BitWriter)(unsafe.Pointer(enc + 112 + uintptr(p)*48)).Fpos
  33793 		goto _5
  33794 	_5:
  33795 		vp8_size = vp8_size + v1
  33796 		goto _3
  33797 	_3:
  33798 		;
  33799 		p = p + 1
  33800 	}
  33801 	pad = vp8_size & uint64(1)
  33802 	vp8_size = vp8_size + pad
  33803 	// Compute RIFF size
  33804 	// At the minimum it is: "WEBPVP8 nnnn" + VP8 data size.
  33805 	riff_size = uint64(libc.Int32FromInt32(TAG_SIZE)+libc.Int32FromInt32(CHUNK_HEADER_SIZE)) + vp8_size
  33806 	if IsVP8XNeeded(tls, enc) != 0 { // Add size for: VP8X header + data.
  33807 		riff_size = riff_size + uint64(libc.Int32FromInt32(CHUNK_HEADER_SIZE)+libc.Int32FromInt32(VP8X_CHUNK_SIZE))
  33808 	}
  33809 	if (*VP8Encoder)(unsafe.Pointer(enc)).Fhas_alpha != 0 { // Add size for: ALPH header + data.
  33810 		padded_alpha_size = (*VP8Encoder)(unsafe.Pointer(enc)).Falpha_data_size + (*VP8Encoder)(unsafe.Pointer(enc)).Falpha_data_size&uint32(1)
  33811 		riff_size = riff_size + uint64(uint32(CHUNK_HEADER_SIZE)+padded_alpha_size)
  33812 	}
  33813 	// RIFF size should fit in 32-bits.
  33814 	if riff_size > uint64(0xfffffffe) {
  33815 		return WebPEncodingSetError(tls, pic, int32(VP8_ENC_ERROR_FILE_TOO_BIG))
  33816 	}
  33817 	// Emit headers and partition #0
  33818 	v6 = (*VP8BitWriter)(unsafe.Pointer(bw2)).Fbuf
  33819 	goto _7
  33820 _7:
  33821 	part0 = v6
  33822 	v1 = (*VP8BitWriter)(unsafe.Pointer(bw2)).Fpos
  33823 	goto _9
  33824 _9:
  33825 	size0 = v1
  33826 	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)
  33827 	VP8BitWriterWipeOut(tls, bw2) // will free the internal buffer.
  33828 	// Token partitions
  33829 	p = 0
  33830 	for {
  33831 		if !(p < (*VP8Encoder)(unsafe.Pointer(enc)).Fnum_parts) {
  33832 			break
  33833 		}
  33834 		v6 = (*VP8BitWriter)(unsafe.Pointer(enc + 112 + uintptr(p)*48)).Fbuf
  33835 		goto _12
  33836 	_12:
  33837 		buf = v6
  33838 		v1 = (*VP8BitWriter)(unsafe.Pointer(enc + 112 + uintptr(p)*48)).Fpos
  33839 		goto _14
  33840 	_14:
  33841 		size = v1
  33842 		if size != 0 {
  33843 			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)
  33844 		}
  33845 		VP8BitWriterWipeOut(tls, enc+112+uintptr(p)*48) // will free the internal buffer.
  33846 		ok = libc.BoolInt32(ok != 0 && WebPReportProgress(tls, pic, (*VP8Encoder)(unsafe.Pointer(enc)).Fpercent+percent_per_part, enc+536) != 0)
  33847 		goto _10
  33848 	_10:
  33849 		;
  33850 		p = p + 1
  33851 	}
  33852 	// Padding byte
  33853 	if ok != 0 && pad != 0 {
  33854 		ok = PutPaddingByte(tls, pic)
  33855 	}
  33856 	(*VP8Encoder)(unsafe.Pointer(enc)).Fcoded_size = int32(libc.Uint64FromInt32(CHUNK_HEADER_SIZE) + riff_size)
  33857 	ok = libc.BoolInt32(ok != 0 && WebPReportProgress(tls, pic, final_percent, enc+536) != 0)
  33858 	if !(ok != 0) {
  33859 		WebPEncodingSetError(tls, pic, int32(VP8_ENC_ERROR_BAD_WRITE))
  33860 	}
  33861 	return ok
  33862 }
  33863 
  33864 const MIN_PAGE_SIZE = 8192
  33865 const SIZE_MAX14 = "_UI64_MAX"
  33866 
  33867 type VP8Tokens = struct {
  33868 	Fnext uintptr
  33869 }
  33870 
  33871 //------------------------------------------------------------------------------
  33872 
  33873 // Copyright 2011 Google Inc. All Rights Reserved.
  33874 //
  33875 // Use of this source code is governed by a BSD-style license
  33876 // that can be found in the COPYING file in the root of the source
  33877 // tree. An additional intellectual property rights grant can be found
  33878 // in the file PATENTS. All contributing project authors may
  33879 // be found in the AUTHORS file in the root of the source tree.
  33880 // -----------------------------------------------------------------------------
  33881 //
  33882 //   WebP encoder: internal header.
  33883 //
  33884 // Author: Skal (pascal.massimino@gmail.com)
  33885 
  33886 // Copyright 2011 Google Inc. All Rights Reserved.
  33887 //
  33888 // Use of this source code is governed by a BSD-style license
  33889 // that can be found in the COPYING file in the root of the source
  33890 // tree. An additional intellectual property rights grant can be found
  33891 // in the file PATENTS. All contributing project authors may
  33892 // be found in the AUTHORS file in the root of the source tree.
  33893 // -----------------------------------------------------------------------------
  33894 //
  33895 // Bit writing and boolean coder
  33896 //
  33897 // Author: Skal (pascal.massimino@gmail.com)
  33898 
  33899 // Copyright 2012 Google Inc. All Rights Reserved.
  33900 //
  33901 // Use of this source code is governed by a BSD-style license
  33902 // that can be found in the COPYING file in the root of the source
  33903 // tree. An additional intellectual property rights grant can be found
  33904 // in the file PATENTS. All contributing project authors may
  33905 // be found in the AUTHORS file in the root of the source tree.
  33906 // -----------------------------------------------------------------------------
  33907 //
  33908 // Misc. common utility functions
  33909 //
  33910 // Authors: Skal (pascal.massimino@gmail.com)
  33911 //          Urvang (urvang@google.com)
  33912 
  33913 // Copyright 2010 Google Inc. All Rights Reserved.
  33914 //
  33915 // Use of this source code is governed by a BSD-style license
  33916 // that can be found in the COPYING file in the root of the source
  33917 // tree. An additional intellectual property rights grant can be found
  33918 // in the file PATENTS. All contributing project authors may
  33919 // be found in the AUTHORS file in the root of the source tree.
  33920 // -----------------------------------------------------------------------------
  33921 //
  33922 //  Common types + memory wrappers
  33923 //
  33924 // Author: Skal (pascal.massimino@gmail.com)
  33925 
  33926 // we use pages to reduce the number of memcpy()
  33927 
  33928 type token_t = uint16
  33929 
  33930 // Token data is located in memory just after the 'next' field.
  33931 // This macro is used to return their address and hide the trick.
  33932 
  33933 //------------------------------------------------------------------------------
  33934 
  33935 func VP8TBufferInit(tls *libc.TLS, b uintptr, page_size int32) {
  33936 	var v1 int32
  33937 	_ = v1
  33938 	(*VP8TBuffer)(unsafe.Pointer(b)).Ftokens = libc.UintptrFromInt32(0)
  33939 	(*VP8TBuffer)(unsafe.Pointer(b)).Fpages = libc.UintptrFromInt32(0)
  33940 	(*VP8TBuffer)(unsafe.Pointer(b)).Flast_page = b
  33941 	(*VP8TBuffer)(unsafe.Pointer(b)).Fleft = 0
  33942 	if page_size < int32(MIN_PAGE_SIZE) {
  33943 		v1 = int32(MIN_PAGE_SIZE)
  33944 	} else {
  33945 		v1 = page_size
  33946 	}
  33947 	(*VP8TBuffer)(unsafe.Pointer(b)).Fpage_size = v1
  33948 	(*VP8TBuffer)(unsafe.Pointer(b)).Ferror1 = 0
  33949 }
  33950 
  33951 func VP8TBufferClear(tls *libc.TLS, b uintptr) {
  33952 	var next, p uintptr
  33953 	_, _ = next, p
  33954 	if b != libc.UintptrFromInt32(0) {
  33955 		p = (*VP8TBuffer)(unsafe.Pointer(b)).Fpages
  33956 		for p != libc.UintptrFromInt32(0) {
  33957 			next = (*VP8Tokens)(unsafe.Pointer(p)).Fnext
  33958 			WebPSafeFree(tls, p)
  33959 			p = next
  33960 		}
  33961 		VP8TBufferInit(tls, b, (*VP8TBuffer)(unsafe.Pointer(b)).Fpage_size)
  33962 	}
  33963 }
  33964 
  33965 func TBufferNewPage(tls *libc.TLS, b uintptr) (r int32) {
  33966 	var page uintptr
  33967 	var size size_t
  33968 	_, _ = page, size
  33969 	page = libc.UintptrFromInt32(0)
  33970 	if !((*VP8TBuffer)(unsafe.Pointer(b)).Ferror1 != 0) {
  33971 		size = uint64(8) + uint64((*VP8TBuffer)(unsafe.Pointer(b)).Fpage_size)*uint64(2)
  33972 		page = WebPSafeMalloc(tls, uint64(1), size)
  33973 	}
  33974 	if page == libc.UintptrFromInt32(0) {
  33975 		(*VP8TBuffer)(unsafe.Pointer(b)).Ferror1 = int32(1)
  33976 		return 0
  33977 	}
  33978 	(*VP8Tokens)(unsafe.Pointer(page)).Fnext = libc.UintptrFromInt32(0)
  33979 	**(**uintptr)(__ccgo_up((*VP8TBuffer)(unsafe.Pointer(b)).Flast_page)) = page
  33980 	(*VP8TBuffer)(unsafe.Pointer(b)).Flast_page = page
  33981 	(*VP8TBuffer)(unsafe.Pointer(b)).Fleft = (*VP8TBuffer)(unsafe.Pointer(b)).Fpage_size
  33982 	(*VP8TBuffer)(unsafe.Pointer(b)).Ftokens = page + 1*8
  33983 	return int32(1)
  33984 }
  33985 
  33986 //------------------------------------------------------------------------------
  33987 
  33988 func AddToken(tls *libc.TLS, b uintptr, bit1 uint32_t, proba_idx uint32_t, stats1 uintptr) (r uint32_t) {
  33989 	var p proba_t
  33990 	var slot, v1 int32
  33991 	var v2 uintptr
  33992 	_, _, _, _ = p, slot, v1, v2
  33993 	if (*VP8TBuffer)(unsafe.Pointer(b)).Fleft > 0 || TBufferNewPage(tls, b) != 0 {
  33994 		v2 = b + 24
  33995 		*(*int32)(unsafe.Pointer(v2)) = *(*int32)(unsafe.Pointer(v2)) - 1
  33996 		v1 = *(*int32)(unsafe.Pointer(v2))
  33997 		slot = v1
  33998 		**(**uint16_t)(__ccgo_up((*VP8TBuffer)(unsafe.Pointer(b)).Ftokens + uintptr(slot)*2)) = uint16(bit1<<libc.Int32FromInt32(15) | proba_idx)
  33999 	}
  34000 	v1 = int32(bit1)
  34001 	v2 = stats1
  34002 	p = **(**proba_t)(__ccgo_up(v2))
  34003 	if p >= libc.Uint32FromUint32(0xfffe0000) {
  34004 		p = (p + uint32(1)) >> int32(1) & uint32(0x7fff7fff)
  34005 	}
  34006 	p = p + (uint32(0x00010000) + uint32(v1))
  34007 	**(**proba_t)(__ccgo_up(v2)) = p
  34008 	_ = v1
  34009 	goto _5
  34010 _5:
  34011 	;
  34012 	return bit1
  34013 }
  34014 
  34015 func AddConstantToken(tls *libc.TLS, b uintptr, bit uint32_t, proba uint32_t) {
  34016 	var slot, v1 int32
  34017 	var v2 uintptr
  34018 	_, _, _ = slot, v1, v2
  34019 	if (*VP8TBuffer)(unsafe.Pointer(b)).Fleft > 0 || TBufferNewPage(tls, b) != 0 {
  34020 		v2 = b + 24
  34021 		*(*int32)(unsafe.Pointer(v2)) = *(*int32)(unsafe.Pointer(v2)) - 1
  34022 		v1 = *(*int32)(unsafe.Pointer(v2))
  34023 		slot = v1
  34024 		**(**uint16_t)(__ccgo_up((*VP8TBuffer)(unsafe.Pointer(b)).Ftokens + uintptr(slot)*2)) = uint16(bit<<libc.Int32FromInt32(15) | libc.Uint32FromUint32(1)<<libc.Int32FromInt32(14) | proba)
  34025 	}
  34026 }
  34027 
  34028 func VP8RecordCoeffTokens(tls *libc.TLS, ctx int32, res uintptr, tokens uintptr) (r int32) {
  34029 	var base_id, residue, v uint32_t
  34030 	var c, coeff_type, last, mask, n, sign, v1, v2 int32
  34031 	var coeffs, s, tab, v3 uintptr
  34032 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = base_id, c, coeff_type, coeffs, last, mask, n, residue, s, sign, tab, v, v1, v2, v3
  34033 	coeffs = (*VP8Residual)(unsafe.Pointer(res)).Fcoeffs
  34034 	coeff_type = (*VP8Residual)(unsafe.Pointer(res)).Fcoeff_type
  34035 	last = (*VP8Residual)(unsafe.Pointer(res)).Flast
  34036 	n = (*VP8Residual)(unsafe.Pointer(res)).Ffirst
  34037 	base_id = uint32(int32(NUM_PROBAS) * (ctx + int32(NUM_CTX)*(n+int32(NUM_BANDS)*coeff_type)))
  34038 	// should be stats[VP8EncBands[n]], but it's equivalent for n=0 or 1
  34039 	s = (*VP8Residual)(unsafe.Pointer(res)).Fstats + uintptr(n)*132 + uintptr(ctx)*44
  34040 	if !(AddToken(tls, tokens, libc.BoolUint32(last >= 0), base_id+uint32(0), s+uintptr(0)*4) != 0) {
  34041 		return 0
  34042 	}
  34043 	for n < int32(16) {
  34044 		v1 = n
  34045 		n = n + 1
  34046 		c = int32(**(**int16_t)(__ccgo_up(coeffs + uintptr(v1)*2)))
  34047 		sign = libc.BoolInt32(c < 0)
  34048 		if sign != 0 {
  34049 			v2 = -c
  34050 		} else {
  34051 			v2 = c
  34052 		}
  34053 		v = uint32(v2)
  34054 		if !(AddToken(tls, tokens, libc.BoolUint32(v != uint32(0)), base_id+uint32(1), s+uintptr(1)*4) != 0) {
  34055 			base_id = uint32(int32(NUM_PROBAS) * (libc.Int32FromInt32(0) + int32(NUM_CTX)*(int32(VP8EncBands[n])+int32(NUM_BANDS)*coeff_type))) // ctx=0
  34056 			s = (*VP8Residual)(unsafe.Pointer(res)).Fstats + uintptr(VP8EncBands[n])*132
  34057 			continue
  34058 		}
  34059 		if !(AddToken(tls, tokens, libc.BoolUint32(v > uint32(1)), base_id+uint32(2), s+uintptr(2)*4) != 0) {
  34060 			base_id = uint32(int32(NUM_PROBAS) * (libc.Int32FromInt32(1) + int32(NUM_CTX)*(int32(VP8EncBands[n])+int32(NUM_BANDS)*coeff_type))) // ctx=1
  34061 			s = (*VP8Residual)(unsafe.Pointer(res)).Fstats + uintptr(VP8EncBands[n])*132 + 1*44
  34062 		} else {
  34063 			if !(AddToken(tls, tokens, libc.BoolUint32(v > uint32(4)), base_id+uint32(3), s+uintptr(3)*4) != 0) {
  34064 				if AddToken(tls, tokens, libc.BoolUint32(v != uint32(2)), base_id+uint32(4), s+uintptr(4)*4) != 0 {
  34065 					AddToken(tls, tokens, libc.BoolUint32(v == uint32(4)), base_id+uint32(5), s+uintptr(5)*4)
  34066 				}
  34067 			} else {
  34068 				if !(AddToken(tls, tokens, libc.BoolUint32(v > uint32(10)), base_id+uint32(6), s+uintptr(6)*4) != 0) {
  34069 					if !(AddToken(tls, tokens, libc.BoolUint32(v > uint32(6)), base_id+uint32(7), s+uintptr(7)*4) != 0) {
  34070 						AddConstantToken(tls, tokens, libc.BoolUint32(v == uint32(6)), uint32(159))
  34071 					} else {
  34072 						AddConstantToken(tls, tokens, libc.BoolUint32(v >= uint32(9)), uint32(165))
  34073 						AddConstantToken(tls, tokens, libc.BoolUint32(!(v&libc.Uint32FromInt32(1) != 0)), uint32(145))
  34074 					}
  34075 				} else {
  34076 					residue = v - uint32(3)
  34077 					if residue < uint32(libc.Int32FromInt32(8)<<libc.Int32FromInt32(1)) { // VP8Cat3  (3b)
  34078 						AddToken(tls, tokens, uint32(0), base_id+uint32(8), s+uintptr(8)*4)
  34079 						AddToken(tls, tokens, uint32(0), base_id+uint32(9), s+uintptr(9)*4)
  34080 						residue = residue - uint32(libc.Int32FromInt32(8)<<libc.Int32FromInt32(0))
  34081 						mask = libc.Int32FromInt32(1) << libc.Int32FromInt32(2)
  34082 						tab = uintptr(unsafe.Pointer(&VP8Cat3))
  34083 					} else {
  34084 						if residue < uint32(libc.Int32FromInt32(8)<<libc.Int32FromInt32(2)) { // VP8Cat4  (4b)
  34085 							AddToken(tls, tokens, uint32(0), base_id+uint32(8), s+uintptr(8)*4)
  34086 							AddToken(tls, tokens, uint32(1), base_id+uint32(9), s+uintptr(9)*4)
  34087 							residue = residue - uint32(libc.Int32FromInt32(8)<<libc.Int32FromInt32(1))
  34088 							mask = libc.Int32FromInt32(1) << libc.Int32FromInt32(3)
  34089 							tab = uintptr(unsafe.Pointer(&VP8Cat4))
  34090 						} else {
  34091 							if residue < uint32(libc.Int32FromInt32(8)<<libc.Int32FromInt32(3)) { // VP8Cat5  (5b)
  34092 								AddToken(tls, tokens, uint32(1), base_id+uint32(8), s+uintptr(8)*4)
  34093 								AddToken(tls, tokens, uint32(0), base_id+uint32(10), s+uintptr(9)*4)
  34094 								residue = residue - uint32(libc.Int32FromInt32(8)<<libc.Int32FromInt32(2))
  34095 								mask = libc.Int32FromInt32(1) << libc.Int32FromInt32(4)
  34096 								tab = uintptr(unsafe.Pointer(&VP8Cat5))
  34097 							} else { // VP8Cat6 (11b)
  34098 								AddToken(tls, tokens, uint32(1), base_id+uint32(8), s+uintptr(8)*4)
  34099 								AddToken(tls, tokens, uint32(1), base_id+uint32(10), s+uintptr(9)*4)
  34100 								residue = residue - uint32(libc.Int32FromInt32(8)<<libc.Int32FromInt32(3))
  34101 								mask = libc.Int32FromInt32(1) << libc.Int32FromInt32(10)
  34102 								tab = uintptr(unsafe.Pointer(&VP8Cat6))
  34103 							}
  34104 						}
  34105 					}
  34106 					for mask != 0 {
  34107 						v3 = tab
  34108 						tab = tab + 1
  34109 						AddConstantToken(tls, tokens, libc.BoolUint32(!!(residue&uint32(mask) != 0)), uint32(**(**uint8_t)(__ccgo_up(v3))))
  34110 						mask = mask >> int32(1)
  34111 					}
  34112 				}
  34113 			}
  34114 			base_id = uint32(int32(NUM_PROBAS) * (libc.Int32FromInt32(2) + int32(NUM_CTX)*(int32(VP8EncBands[n])+int32(NUM_BANDS)*coeff_type))) // ctx=2
  34115 			s = (*VP8Residual)(unsafe.Pointer(res)).Fstats + uintptr(VP8EncBands[n])*132 + 2*44
  34116 		}
  34117 		AddConstantToken(tls, tokens, uint32(sign), uint32(128))
  34118 		if n == int32(16) || !(AddToken(tls, tokens, libc.BoolUint32(n <= last), base_id+uint32(0), s+uintptr(0)*4) != 0) {
  34119 			return int32(1) // EOB
  34120 		}
  34121 	}
  34122 	return int32(1)
  34123 }
  34124 
  34125 //------------------------------------------------------------------------------
  34126 // Final coding pass, with known probabilities
  34127 
  34128 func VP8EmitTokens(tls *libc.TLS, b uintptr, bw uintptr, probas uintptr, final_pass int32) (r int32) {
  34129 	var N, bit, n, v1, v2 int32
  34130 	var next, p, tokens uintptr
  34131 	var token token_t
  34132 	_, _, _, _, _, _, _, _, _ = N, bit, n, next, p, token, tokens, v1, v2
  34133 	p = (*VP8TBuffer)(unsafe.Pointer(b)).Fpages
  34134 	for p != libc.UintptrFromInt32(0) {
  34135 		next = (*VP8Tokens)(unsafe.Pointer(p)).Fnext
  34136 		if next == libc.UintptrFromInt32(0) {
  34137 			v1 = (*VP8TBuffer)(unsafe.Pointer(b)).Fleft
  34138 		} else {
  34139 			v1 = 0
  34140 		}
  34141 		N = v1
  34142 		n = (*VP8TBuffer)(unsafe.Pointer(b)).Fpage_size
  34143 		tokens = p + 1*8
  34144 		for {
  34145 			v2 = n
  34146 			n = n - 1
  34147 			if !(v2 > N) {
  34148 				break
  34149 			}
  34150 			token = **(**token_t)(__ccgo_up(tokens + uintptr(n)*2))
  34151 			bit = int32(token) >> int32(15) & int32(1)
  34152 			if uint32(token)&(libc.Uint32FromUint32(1)<<libc.Int32FromInt32(14)) != 0 {
  34153 				VP8PutBit(tls, bw, bit, int32(uint32(token)&uint32(0xff))) // constant proba
  34154 			} else {
  34155 				VP8PutBit(tls, bw, bit, int32(**(**uint8_t)(__ccgo_up(probas + uintptr(uint32(token)&uint32(0x3fff))))))
  34156 			}
  34157 		}
  34158 		if final_pass != 0 {
  34159 			WebPSafeFree(tls, p)
  34160 		}
  34161 		p = next
  34162 	}
  34163 	if final_pass != 0 {
  34164 		(*VP8TBuffer)(unsafe.Pointer(b)).Fpages = libc.UintptrFromInt32(0)
  34165 	}
  34166 	return int32(1)
  34167 }
  34168 
  34169 // C documentation
  34170 //
  34171 //	// Size estimation
  34172 func VP8EstimateTokenSize(tls *libc.TLS, b uintptr, probas uintptr) (r size_t) {
  34173 	var N, bit1, n, v1, v2, v4, v6 int32
  34174 	var next, p, tokens uintptr
  34175 	var size size_t
  34176 	var token token_t
  34177 	var v3 uint8_t
  34178 	_, _, _, _, _, _, _, _, _, _, _, _, _ = N, bit1, n, next, p, size, token, tokens, v1, v2, v3, v4, v6
  34179 	size = uint64(0)
  34180 	p = (*VP8TBuffer)(unsafe.Pointer(b)).Fpages
  34181 	for p != libc.UintptrFromInt32(0) {
  34182 		next = (*VP8Tokens)(unsafe.Pointer(p)).Fnext
  34183 		if next == libc.UintptrFromInt32(0) {
  34184 			v1 = (*VP8TBuffer)(unsafe.Pointer(b)).Fleft
  34185 		} else {
  34186 			v1 = 0
  34187 		}
  34188 		N = v1
  34189 		n = (*VP8TBuffer)(unsafe.Pointer(b)).Fpage_size
  34190 		tokens = p + 1*8
  34191 		for {
  34192 			v2 = n
  34193 			n = n - 1
  34194 			if !(v2 > N) {
  34195 				break
  34196 			}
  34197 			token = **(**token_t)(__ccgo_up(tokens + uintptr(n)*2))
  34198 			bit1 = int32(token) & (libc.Int32FromInt32(1) << libc.Int32FromInt32(15))
  34199 			if uint32(token)&(libc.Uint32FromUint32(1)<<libc.Int32FromInt32(14)) != 0 {
  34200 				v3 = uint8(uint32(token) & uint32(0xff))
  34201 				if !(bit1 != 0) {
  34202 					v6 = int32(VP8EntropyCost[v3])
  34203 				} else {
  34204 					v6 = int32(VP8EntropyCost[int32(255)-int32(v3)])
  34205 				}
  34206 				v4 = v6
  34207 				goto _5
  34208 			_5:
  34209 				size = size + uint64(v4)
  34210 			} else {
  34211 				v3 = **(**uint8_t)(__ccgo_up(probas + uintptr(uint32(token)&uint32(0x3fff))))
  34212 				if !(bit1 != 0) {
  34213 					v2 = int32(VP8EntropyCost[v3])
  34214 				} else {
  34215 					v2 = int32(VP8EntropyCost[int32(255)-int32(v3)])
  34216 				}
  34217 				v1 = v2
  34218 				goto _9
  34219 			_9:
  34220 				size = size + uint64(v1)
  34221 			}
  34222 		}
  34223 		p = next
  34224 	}
  34225 	return size
  34226 }
  34227 
  34228 const SIZE_MAX15 = "UINT64_MAX"
  34229 
  34230 func VP8DefaultProbas(tls *libc.TLS, enc uintptr) {
  34231 	var probas uintptr
  34232 	_ = probas
  34233 	probas = enc + 3616
  34234 	(*VP8EncProba)(unsafe.Pointer(probas)).Fuse_skip_proba = 0
  34235 	libc.Xmemset(tls, probas, libc.Int32FromUint32(255), uint64(3))
  34236 	libc.Xmemcpy(tls, probas+4, uintptr(unsafe.Pointer(&VP8CoeffsProba0)), uint64(1056))
  34237 	// Note: we could hard-code the level_costs corresponding to VP8CoeffsProba0,
  34238 	// but that's ~11k of static data. Better call VP8CalculateLevelCosts() later.
  34239 	(*VP8EncProba)(unsafe.Pointer(probas)).Fdirty = int32(1)
  34240 }
  34241 
  34242 // C documentation
  34243 //
  34244 //	// Paragraph 11.5.  900bytes.
  34245 var kBModesProba1 = [10][10][9]uint8_t{
  34246 	0: {
  34247 		0: {
  34248 			0: uint8(231),
  34249 			1: uint8(120),
  34250 			2: uint8(48),
  34251 			3: uint8(89),
  34252 			4: uint8(115),
  34253 			5: uint8(113),
  34254 			6: uint8(120),
  34255 			7: uint8(152),
  34256 			8: uint8(112),
  34257 		},
  34258 		1: {
  34259 			0: uint8(152),
  34260 			1: uint8(179),
  34261 			2: uint8(64),
  34262 			3: uint8(126),
  34263 			4: uint8(170),
  34264 			5: uint8(118),
  34265 			6: uint8(46),
  34266 			7: uint8(70),
  34267 			8: uint8(95),
  34268 		},
  34269 		2: {
  34270 			0: uint8(175),
  34271 			1: uint8(69),
  34272 			2: uint8(143),
  34273 			3: uint8(80),
  34274 			4: uint8(85),
  34275 			5: uint8(82),
  34276 			6: uint8(72),
  34277 			7: uint8(155),
  34278 			8: uint8(103),
  34279 		},
  34280 		3: {
  34281 			0: uint8(56),
  34282 			1: uint8(58),
  34283 			2: uint8(10),
  34284 			3: uint8(171),
  34285 			4: uint8(218),
  34286 			5: uint8(189),
  34287 			6: uint8(17),
  34288 			7: uint8(13),
  34289 			8: uint8(152),
  34290 		},
  34291 		4: {
  34292 			0: uint8(114),
  34293 			1: uint8(26),
  34294 			2: uint8(17),
  34295 			3: uint8(163),
  34296 			4: uint8(44),
  34297 			5: uint8(195),
  34298 			6: uint8(21),
  34299 			7: uint8(10),
  34300 			8: uint8(173),
  34301 		},
  34302 		5: {
  34303 			0: uint8(121),
  34304 			1: uint8(24),
  34305 			2: uint8(80),
  34306 			3: uint8(195),
  34307 			4: uint8(26),
  34308 			5: uint8(62),
  34309 			6: uint8(44),
  34310 			7: uint8(64),
  34311 			8: uint8(85),
  34312 		},
  34313 		6: {
  34314 			0: uint8(144),
  34315 			1: uint8(71),
  34316 			2: uint8(10),
  34317 			3: uint8(38),
  34318 			4: uint8(171),
  34319 			5: uint8(213),
  34320 			6: uint8(144),
  34321 			7: uint8(34),
  34322 			8: uint8(26),
  34323 		},
  34324 		7: {
  34325 			0: uint8(170),
  34326 			1: uint8(46),
  34327 			2: uint8(55),
  34328 			3: uint8(19),
  34329 			4: uint8(136),
  34330 			5: uint8(160),
  34331 			6: uint8(33),
  34332 			7: uint8(206),
  34333 			8: uint8(71),
  34334 		},
  34335 		8: {
  34336 			0: uint8(63),
  34337 			1: uint8(20),
  34338 			2: uint8(8),
  34339 			3: uint8(114),
  34340 			4: uint8(114),
  34341 			5: uint8(208),
  34342 			6: uint8(12),
  34343 			7: uint8(9),
  34344 			8: uint8(226),
  34345 		},
  34346 		9: {
  34347 			0: uint8(81),
  34348 			1: uint8(40),
  34349 			2: uint8(11),
  34350 			3: uint8(96),
  34351 			4: uint8(182),
  34352 			5: uint8(84),
  34353 			6: uint8(29),
  34354 			7: uint8(16),
  34355 			8: uint8(36),
  34356 		},
  34357 	},
  34358 	1: {
  34359 		0: {
  34360 			0: uint8(134),
  34361 			1: uint8(183),
  34362 			2: uint8(89),
  34363 			3: uint8(137),
  34364 			4: uint8(98),
  34365 			5: uint8(101),
  34366 			6: uint8(106),
  34367 			7: uint8(165),
  34368 			8: uint8(148),
  34369 		},
  34370 		1: {
  34371 			0: uint8(72),
  34372 			1: uint8(187),
  34373 			2: uint8(100),
  34374 			3: uint8(130),
  34375 			4: uint8(157),
  34376 			5: uint8(111),
  34377 			6: uint8(32),
  34378 			7: uint8(75),
  34379 			8: uint8(80),
  34380 		},
  34381 		2: {
  34382 			0: uint8(66),
  34383 			1: uint8(102),
  34384 			2: uint8(167),
  34385 			3: uint8(99),
  34386 			4: uint8(74),
  34387 			5: uint8(62),
  34388 			6: uint8(40),
  34389 			7: uint8(234),
  34390 			8: uint8(128),
  34391 		},
  34392 		3: {
  34393 			0: uint8(41),
  34394 			1: uint8(53),
  34395 			2: uint8(9),
  34396 			3: uint8(178),
  34397 			4: uint8(241),
  34398 			5: uint8(141),
  34399 			6: uint8(26),
  34400 			7: uint8(8),
  34401 			8: uint8(107),
  34402 		},
  34403 		4: {
  34404 			0: uint8(74),
  34405 			1: uint8(43),
  34406 			2: uint8(26),
  34407 			3: uint8(146),
  34408 			4: uint8(73),
  34409 			5: uint8(166),
  34410 			6: uint8(49),
  34411 			7: uint8(23),
  34412 			8: uint8(157),
  34413 		},
  34414 		5: {
  34415 			0: uint8(65),
  34416 			1: uint8(38),
  34417 			2: uint8(105),
  34418 			3: uint8(160),
  34419 			4: uint8(51),
  34420 			5: uint8(52),
  34421 			6: uint8(31),
  34422 			7: uint8(115),
  34423 			8: uint8(128),
  34424 		},
  34425 		6: {
  34426 			0: uint8(104),
  34427 			1: uint8(79),
  34428 			2: uint8(12),
  34429 			3: uint8(27),
  34430 			4: uint8(217),
  34431 			5: uint8(255),
  34432 			6: uint8(87),
  34433 			7: uint8(17),
  34434 			8: uint8(7),
  34435 		},
  34436 		7: {
  34437 			0: uint8(87),
  34438 			1: uint8(68),
  34439 			2: uint8(71),
  34440 			3: uint8(44),
  34441 			4: uint8(114),
  34442 			5: uint8(51),
  34443 			6: uint8(15),
  34444 			7: uint8(186),
  34445 			8: uint8(23),
  34446 		},
  34447 		8: {
  34448 			0: uint8(47),
  34449 			1: uint8(41),
  34450 			2: uint8(14),
  34451 			3: uint8(110),
  34452 			4: uint8(182),
  34453 			5: uint8(183),
  34454 			6: uint8(21),
  34455 			7: uint8(17),
  34456 			8: uint8(194),
  34457 		},
  34458 		9: {
  34459 			0: uint8(66),
  34460 			1: uint8(45),
  34461 			2: uint8(25),
  34462 			3: uint8(102),
  34463 			4: uint8(197),
  34464 			5: uint8(189),
  34465 			6: uint8(23),
  34466 			7: uint8(18),
  34467 			8: uint8(22),
  34468 		},
  34469 	},
  34470 	2: {
  34471 		0: {
  34472 			0: uint8(88),
  34473 			1: uint8(88),
  34474 			2: uint8(147),
  34475 			3: uint8(150),
  34476 			4: uint8(42),
  34477 			5: uint8(46),
  34478 			6: uint8(45),
  34479 			7: uint8(196),
  34480 			8: uint8(205),
  34481 		},
  34482 		1: {
  34483 			0: uint8(43),
  34484 			1: uint8(97),
  34485 			2: uint8(183),
  34486 			3: uint8(117),
  34487 			4: uint8(85),
  34488 			5: uint8(38),
  34489 			6: uint8(35),
  34490 			7: uint8(179),
  34491 			8: uint8(61),
  34492 		},
  34493 		2: {
  34494 			0: uint8(39),
  34495 			1: uint8(53),
  34496 			2: uint8(200),
  34497 			3: uint8(87),
  34498 			4: uint8(26),
  34499 			5: uint8(21),
  34500 			6: uint8(43),
  34501 			7: uint8(232),
  34502 			8: uint8(171),
  34503 		},
  34504 		3: {
  34505 			0: uint8(56),
  34506 			1: uint8(34),
  34507 			2: uint8(51),
  34508 			3: uint8(104),
  34509 			4: uint8(114),
  34510 			5: uint8(102),
  34511 			6: uint8(29),
  34512 			7: uint8(93),
  34513 			8: uint8(77),
  34514 		},
  34515 		4: {
  34516 			0: uint8(39),
  34517 			1: uint8(28),
  34518 			2: uint8(85),
  34519 			3: uint8(171),
  34520 			4: uint8(58),
  34521 			5: uint8(165),
  34522 			6: uint8(90),
  34523 			7: uint8(98),
  34524 			8: uint8(64),
  34525 		},
  34526 		5: {
  34527 			0: uint8(34),
  34528 			1: uint8(22),
  34529 			2: uint8(116),
  34530 			3: uint8(206),
  34531 			4: uint8(23),
  34532 			5: uint8(34),
  34533 			6: uint8(43),
  34534 			7: uint8(166),
  34535 			8: uint8(73),
  34536 		},
  34537 		6: {
  34538 			0: uint8(107),
  34539 			1: uint8(54),
  34540 			2: uint8(32),
  34541 			3: uint8(26),
  34542 			4: uint8(51),
  34543 			5: uint8(1),
  34544 			6: uint8(81),
  34545 			7: uint8(43),
  34546 			8: uint8(31),
  34547 		},
  34548 		7: {
  34549 			0: uint8(68),
  34550 			1: uint8(25),
  34551 			2: uint8(106),
  34552 			3: uint8(22),
  34553 			4: uint8(64),
  34554 			5: uint8(171),
  34555 			6: uint8(36),
  34556 			7: uint8(225),
  34557 			8: uint8(114),
  34558 		},
  34559 		8: {
  34560 			0: uint8(34),
  34561 			1: uint8(19),
  34562 			2: uint8(21),
  34563 			3: uint8(102),
  34564 			4: uint8(132),
  34565 			5: uint8(188),
  34566 			6: uint8(16),
  34567 			7: uint8(76),
  34568 			8: uint8(124),
  34569 		},
  34570 		9: {
  34571 			0: uint8(62),
  34572 			1: uint8(18),
  34573 			2: uint8(78),
  34574 			3: uint8(95),
  34575 			4: uint8(85),
  34576 			5: uint8(57),
  34577 			6: uint8(50),
  34578 			7: uint8(48),
  34579 			8: uint8(51),
  34580 		},
  34581 	},
  34582 	3: {
  34583 		0: {
  34584 			0: uint8(193),
  34585 			1: uint8(101),
  34586 			2: uint8(35),
  34587 			3: uint8(159),
  34588 			4: uint8(215),
  34589 			5: uint8(111),
  34590 			6: uint8(89),
  34591 			7: uint8(46),
  34592 			8: uint8(111),
  34593 		},
  34594 		1: {
  34595 			0: uint8(60),
  34596 			1: uint8(148),
  34597 			2: uint8(31),
  34598 			3: uint8(172),
  34599 			4: uint8(219),
  34600 			5: uint8(228),
  34601 			6: uint8(21),
  34602 			7: uint8(18),
  34603 			8: uint8(111),
  34604 		},
  34605 		2: {
  34606 			0: uint8(112),
  34607 			1: uint8(113),
  34608 			2: uint8(77),
  34609 			3: uint8(85),
  34610 			4: uint8(179),
  34611 			5: uint8(255),
  34612 			6: uint8(38),
  34613 			7: uint8(120),
  34614 			8: uint8(114),
  34615 		},
  34616 		3: {
  34617 			0: uint8(40),
  34618 			1: uint8(42),
  34619 			2: uint8(1),
  34620 			3: uint8(196),
  34621 			4: uint8(245),
  34622 			5: uint8(209),
  34623 			6: uint8(10),
  34624 			7: uint8(25),
  34625 			8: uint8(109),
  34626 		},
  34627 		4: {
  34628 			0: uint8(88),
  34629 			1: uint8(43),
  34630 			2: uint8(29),
  34631 			3: uint8(140),
  34632 			4: uint8(166),
  34633 			5: uint8(213),
  34634 			6: uint8(37),
  34635 			7: uint8(43),
  34636 			8: uint8(154),
  34637 		},
  34638 		5: {
  34639 			0: uint8(61),
  34640 			1: uint8(63),
  34641 			2: uint8(30),
  34642 			3: uint8(155),
  34643 			4: uint8(67),
  34644 			5: uint8(45),
  34645 			6: uint8(68),
  34646 			7: uint8(1),
  34647 			8: uint8(209),
  34648 		},
  34649 		6: {
  34650 			0: uint8(100),
  34651 			1: uint8(80),
  34652 			2: uint8(8),
  34653 			3: uint8(43),
  34654 			4: uint8(154),
  34655 			5: uint8(1),
  34656 			6: uint8(51),
  34657 			7: uint8(26),
  34658 			8: uint8(71),
  34659 		},
  34660 		7: {
  34661 			0: uint8(142),
  34662 			1: uint8(78),
  34663 			2: uint8(78),
  34664 			3: uint8(16),
  34665 			4: uint8(255),
  34666 			5: uint8(128),
  34667 			6: uint8(34),
  34668 			7: uint8(197),
  34669 			8: uint8(171),
  34670 		},
  34671 		8: {
  34672 			0: uint8(41),
  34673 			1: uint8(40),
  34674 			2: uint8(5),
  34675 			3: uint8(102),
  34676 			4: uint8(211),
  34677 			5: uint8(183),
  34678 			6: uint8(4),
  34679 			7: uint8(1),
  34680 			8: uint8(221),
  34681 		},
  34682 		9: {
  34683 			0: uint8(51),
  34684 			1: uint8(50),
  34685 			2: uint8(17),
  34686 			3: uint8(168),
  34687 			4: uint8(209),
  34688 			5: uint8(192),
  34689 			6: uint8(23),
  34690 			7: uint8(25),
  34691 			8: uint8(82),
  34692 		},
  34693 	},
  34694 	4: {
  34695 		0: {
  34696 			0: uint8(138),
  34697 			1: uint8(31),
  34698 			2: uint8(36),
  34699 			3: uint8(171),
  34700 			4: uint8(27),
  34701 			5: uint8(166),
  34702 			6: uint8(38),
  34703 			7: uint8(44),
  34704 			8: uint8(229),
  34705 		},
  34706 		1: {
  34707 			0: uint8(67),
  34708 			1: uint8(87),
  34709 			2: uint8(58),
  34710 			3: uint8(169),
  34711 			4: uint8(82),
  34712 			5: uint8(115),
  34713 			6: uint8(26),
  34714 			7: uint8(59),
  34715 			8: uint8(179),
  34716 		},
  34717 		2: {
  34718 			0: uint8(63),
  34719 			1: uint8(59),
  34720 			2: uint8(90),
  34721 			3: uint8(180),
  34722 			4: uint8(59),
  34723 			5: uint8(166),
  34724 			6: uint8(93),
  34725 			7: uint8(73),
  34726 			8: uint8(154),
  34727 		},
  34728 		3: {
  34729 			0: uint8(40),
  34730 			1: uint8(40),
  34731 			2: uint8(21),
  34732 			3: uint8(116),
  34733 			4: uint8(143),
  34734 			5: uint8(209),
  34735 			6: uint8(34),
  34736 			7: uint8(39),
  34737 			8: uint8(175),
  34738 		},
  34739 		4: {
  34740 			0: uint8(47),
  34741 			1: uint8(15),
  34742 			2: uint8(16),
  34743 			3: uint8(183),
  34744 			4: uint8(34),
  34745 			5: uint8(223),
  34746 			6: uint8(49),
  34747 			7: uint8(45),
  34748 			8: uint8(183),
  34749 		},
  34750 		5: {
  34751 			0: uint8(46),
  34752 			1: uint8(17),
  34753 			2: uint8(33),
  34754 			3: uint8(183),
  34755 			4: uint8(6),
  34756 			5: uint8(98),
  34757 			6: uint8(15),
  34758 			7: uint8(32),
  34759 			8: uint8(183),
  34760 		},
  34761 		6: {
  34762 			0: uint8(57),
  34763 			1: uint8(46),
  34764 			2: uint8(22),
  34765 			3: uint8(24),
  34766 			4: uint8(128),
  34767 			5: uint8(1),
  34768 			6: uint8(54),
  34769 			7: uint8(17),
  34770 			8: uint8(37),
  34771 		},
  34772 		7: {
  34773 			0: uint8(65),
  34774 			1: uint8(32),
  34775 			2: uint8(73),
  34776 			3: uint8(115),
  34777 			4: uint8(28),
  34778 			5: uint8(128),
  34779 			6: uint8(23),
  34780 			7: uint8(128),
  34781 			8: uint8(205),
  34782 		},
  34783 		8: {
  34784 			0: uint8(40),
  34785 			1: uint8(3),
  34786 			2: uint8(9),
  34787 			3: uint8(115),
  34788 			4: uint8(51),
  34789 			5: uint8(192),
  34790 			6: uint8(18),
  34791 			7: uint8(6),
  34792 			8: uint8(223),
  34793 		},
  34794 		9: {
  34795 			0: uint8(87),
  34796 			1: uint8(37),
  34797 			2: uint8(9),
  34798 			3: uint8(115),
  34799 			4: uint8(59),
  34800 			5: uint8(77),
  34801 			6: uint8(64),
  34802 			7: uint8(21),
  34803 			8: uint8(47),
  34804 		},
  34805 	},
  34806 	5: {
  34807 		0: {
  34808 			0: uint8(104),
  34809 			1: uint8(55),
  34810 			2: uint8(44),
  34811 			3: uint8(218),
  34812 			4: uint8(9),
  34813 			5: uint8(54),
  34814 			6: uint8(53),
  34815 			7: uint8(130),
  34816 			8: uint8(226),
  34817 		},
  34818 		1: {
  34819 			0: uint8(64),
  34820 			1: uint8(90),
  34821 			2: uint8(70),
  34822 			3: uint8(205),
  34823 			4: uint8(40),
  34824 			5: uint8(41),
  34825 			6: uint8(23),
  34826 			7: uint8(26),
  34827 			8: uint8(57),
  34828 		},
  34829 		2: {
  34830 			0: uint8(54),
  34831 			1: uint8(57),
  34832 			2: uint8(112),
  34833 			3: uint8(184),
  34834 			4: uint8(5),
  34835 			5: uint8(41),
  34836 			6: uint8(38),
  34837 			7: uint8(166),
  34838 			8: uint8(213),
  34839 		},
  34840 		3: {
  34841 			0: uint8(30),
  34842 			1: uint8(34),
  34843 			2: uint8(26),
  34844 			3: uint8(133),
  34845 			4: uint8(152),
  34846 			5: uint8(116),
  34847 			6: uint8(10),
  34848 			7: uint8(32),
  34849 			8: uint8(134),
  34850 		},
  34851 		4: {
  34852 			0: uint8(39),
  34853 			1: uint8(19),
  34854 			2: uint8(53),
  34855 			3: uint8(221),
  34856 			4: uint8(26),
  34857 			5: uint8(114),
  34858 			6: uint8(32),
  34859 			7: uint8(73),
  34860 			8: uint8(255),
  34861 		},
  34862 		5: {
  34863 			0: uint8(31),
  34864 			1: uint8(9),
  34865 			2: uint8(65),
  34866 			3: uint8(234),
  34867 			4: uint8(2),
  34868 			5: uint8(15),
  34869 			6: uint8(1),
  34870 			7: uint8(118),
  34871 			8: uint8(73),
  34872 		},
  34873 		6: {
  34874 			0: uint8(75),
  34875 			1: uint8(32),
  34876 			2: uint8(12),
  34877 			3: uint8(51),
  34878 			4: uint8(192),
  34879 			5: uint8(255),
  34880 			6: uint8(160),
  34881 			7: uint8(43),
  34882 			8: uint8(51),
  34883 		},
  34884 		7: {
  34885 			0: uint8(88),
  34886 			1: uint8(31),
  34887 			2: uint8(35),
  34888 			3: uint8(67),
  34889 			4: uint8(102),
  34890 			5: uint8(85),
  34891 			6: uint8(55),
  34892 			7: uint8(186),
  34893 			8: uint8(85),
  34894 		},
  34895 		8: {
  34896 			0: uint8(56),
  34897 			1: uint8(21),
  34898 			2: uint8(23),
  34899 			3: uint8(111),
  34900 			4: uint8(59),
  34901 			5: uint8(205),
  34902 			6: uint8(45),
  34903 			7: uint8(37),
  34904 			8: uint8(192),
  34905 		},
  34906 		9: {
  34907 			0: uint8(55),
  34908 			1: uint8(38),
  34909 			2: uint8(70),
  34910 			3: uint8(124),
  34911 			4: uint8(73),
  34912 			5: uint8(102),
  34913 			6: uint8(1),
  34914 			7: uint8(34),
  34915 			8: uint8(98),
  34916 		},
  34917 	},
  34918 	6: {
  34919 		0: {
  34920 			0: uint8(125),
  34921 			1: uint8(98),
  34922 			2: uint8(42),
  34923 			3: uint8(88),
  34924 			4: uint8(104),
  34925 			5: uint8(85),
  34926 			6: uint8(117),
  34927 			7: uint8(175),
  34928 			8: uint8(82),
  34929 		},
  34930 		1: {
  34931 			0: uint8(95),
  34932 			1: uint8(84),
  34933 			2: uint8(53),
  34934 			3: uint8(89),
  34935 			4: uint8(128),
  34936 			5: uint8(100),
  34937 			6: uint8(113),
  34938 			7: uint8(101),
  34939 			8: uint8(45),
  34940 		},
  34941 		2: {
  34942 			0: uint8(75),
  34943 			1: uint8(79),
  34944 			2: uint8(123),
  34945 			3: uint8(47),
  34946 			4: uint8(51),
  34947 			5: uint8(128),
  34948 			6: uint8(81),
  34949 			7: uint8(171),
  34950 			8: uint8(1),
  34951 		},
  34952 		3: {
  34953 			0: uint8(57),
  34954 			1: uint8(17),
  34955 			2: uint8(5),
  34956 			3: uint8(71),
  34957 			4: uint8(102),
  34958 			5: uint8(57),
  34959 			6: uint8(53),
  34960 			7: uint8(41),
  34961 			8: uint8(49),
  34962 		},
  34963 		4: {
  34964 			0: uint8(38),
  34965 			1: uint8(33),
  34966 			2: uint8(13),
  34967 			3: uint8(121),
  34968 			4: uint8(57),
  34969 			5: uint8(73),
  34970 			6: uint8(26),
  34971 			7: uint8(1),
  34972 			8: uint8(85),
  34973 		},
  34974 		5: {
  34975 			0: uint8(41),
  34976 			1: uint8(10),
  34977 			2: uint8(67),
  34978 			3: uint8(138),
  34979 			4: uint8(77),
  34980 			5: uint8(110),
  34981 			6: uint8(90),
  34982 			7: uint8(47),
  34983 			8: uint8(114),
  34984 		},
  34985 		6: {
  34986 			0: uint8(115),
  34987 			1: uint8(21),
  34988 			2: uint8(2),
  34989 			3: uint8(10),
  34990 			4: uint8(102),
  34991 			5: uint8(255),
  34992 			6: uint8(166),
  34993 			7: uint8(23),
  34994 			8: uint8(6),
  34995 		},
  34996 		7: {
  34997 			0: uint8(101),
  34998 			1: uint8(29),
  34999 			2: uint8(16),
  35000 			3: uint8(10),
  35001 			4: uint8(85),
  35002 			5: uint8(128),
  35003 			6: uint8(101),
  35004 			7: uint8(196),
  35005 			8: uint8(26),
  35006 		},
  35007 		8: {
  35008 			0: uint8(57),
  35009 			1: uint8(18),
  35010 			2: uint8(10),
  35011 			3: uint8(102),
  35012 			4: uint8(102),
  35013 			5: uint8(213),
  35014 			6: uint8(34),
  35015 			7: uint8(20),
  35016 			8: uint8(43),
  35017 		},
  35018 		9: {
  35019 			0: uint8(117),
  35020 			1: uint8(20),
  35021 			2: uint8(15),
  35022 			3: uint8(36),
  35023 			4: uint8(163),
  35024 			5: uint8(128),
  35025 			6: uint8(68),
  35026 			7: uint8(1),
  35027 			8: uint8(26),
  35028 		},
  35029 	},
  35030 	7: {
  35031 		0: {
  35032 			0: uint8(102),
  35033 			1: uint8(61),
  35034 			2: uint8(71),
  35035 			3: uint8(37),
  35036 			4: uint8(34),
  35037 			5: uint8(53),
  35038 			6: uint8(31),
  35039 			7: uint8(243),
  35040 			8: uint8(192),
  35041 		},
  35042 		1: {
  35043 			0: uint8(69),
  35044 			1: uint8(60),
  35045 			2: uint8(71),
  35046 			3: uint8(38),
  35047 			4: uint8(73),
  35048 			5: uint8(119),
  35049 			6: uint8(28),
  35050 			7: uint8(222),
  35051 			8: uint8(37),
  35052 		},
  35053 		2: {
  35054 			0: uint8(68),
  35055 			1: uint8(45),
  35056 			2: uint8(128),
  35057 			3: uint8(34),
  35058 			4: uint8(1),
  35059 			5: uint8(47),
  35060 			6: uint8(11),
  35061 			7: uint8(245),
  35062 			8: uint8(171),
  35063 		},
  35064 		3: {
  35065 			0: uint8(62),
  35066 			1: uint8(17),
  35067 			2: uint8(19),
  35068 			3: uint8(70),
  35069 			4: uint8(146),
  35070 			5: uint8(85),
  35071 			6: uint8(55),
  35072 			7: uint8(62),
  35073 			8: uint8(70),
  35074 		},
  35075 		4: {
  35076 			0: uint8(37),
  35077 			1: uint8(43),
  35078 			2: uint8(37),
  35079 			3: uint8(154),
  35080 			4: uint8(100),
  35081 			5: uint8(163),
  35082 			6: uint8(85),
  35083 			7: uint8(160),
  35084 			8: uint8(1),
  35085 		},
  35086 		5: {
  35087 			0: uint8(63),
  35088 			1: uint8(9),
  35089 			2: uint8(92),
  35090 			3: uint8(136),
  35091 			4: uint8(28),
  35092 			5: uint8(64),
  35093 			6: uint8(32),
  35094 			7: uint8(201),
  35095 			8: uint8(85),
  35096 		},
  35097 		6: {
  35098 			0: uint8(75),
  35099 			1: uint8(15),
  35100 			2: uint8(9),
  35101 			3: uint8(9),
  35102 			4: uint8(64),
  35103 			5: uint8(255),
  35104 			6: uint8(184),
  35105 			7: uint8(119),
  35106 			8: uint8(16),
  35107 		},
  35108 		7: {
  35109 			0: uint8(86),
  35110 			1: uint8(6),
  35111 			2: uint8(28),
  35112 			3: uint8(5),
  35113 			4: uint8(64),
  35114 			5: uint8(255),
  35115 			6: uint8(25),
  35116 			7: uint8(248),
  35117 			8: uint8(1),
  35118 		},
  35119 		8: {
  35120 			0: uint8(56),
  35121 			1: uint8(8),
  35122 			2: uint8(17),
  35123 			3: uint8(132),
  35124 			4: uint8(137),
  35125 			5: uint8(255),
  35126 			6: uint8(55),
  35127 			7: uint8(116),
  35128 			8: uint8(128),
  35129 		},
  35130 		9: {
  35131 			0: uint8(58),
  35132 			1: uint8(15),
  35133 			2: uint8(20),
  35134 			3: uint8(82),
  35135 			4: uint8(135),
  35136 			5: uint8(57),
  35137 			6: uint8(26),
  35138 			7: uint8(121),
  35139 			8: uint8(40),
  35140 		},
  35141 	},
  35142 	8: {
  35143 		0: {
  35144 			0: uint8(164),
  35145 			1: uint8(50),
  35146 			2: uint8(31),
  35147 			3: uint8(137),
  35148 			4: uint8(154),
  35149 			5: uint8(133),
  35150 			6: uint8(25),
  35151 			7: uint8(35),
  35152 			8: uint8(218),
  35153 		},
  35154 		1: {
  35155 			0: uint8(51),
  35156 			1: uint8(103),
  35157 			2: uint8(44),
  35158 			3: uint8(131),
  35159 			4: uint8(131),
  35160 			5: uint8(123),
  35161 			6: uint8(31),
  35162 			7: uint8(6),
  35163 			8: uint8(158),
  35164 		},
  35165 		2: {
  35166 			0: uint8(86),
  35167 			1: uint8(40),
  35168 			2: uint8(64),
  35169 			3: uint8(135),
  35170 			4: uint8(148),
  35171 			5: uint8(224),
  35172 			6: uint8(45),
  35173 			7: uint8(183),
  35174 			8: uint8(128),
  35175 		},
  35176 		3: {
  35177 			0: uint8(22),
  35178 			1: uint8(26),
  35179 			2: uint8(17),
  35180 			3: uint8(131),
  35181 			4: uint8(240),
  35182 			5: uint8(154),
  35183 			6: uint8(14),
  35184 			7: uint8(1),
  35185 			8: uint8(209),
  35186 		},
  35187 		4: {
  35188 			0: uint8(45),
  35189 			1: uint8(16),
  35190 			2: uint8(21),
  35191 			3: uint8(91),
  35192 			4: uint8(64),
  35193 			5: uint8(222),
  35194 			6: uint8(7),
  35195 			7: uint8(1),
  35196 			8: uint8(197),
  35197 		},
  35198 		5: {
  35199 			0: uint8(56),
  35200 			1: uint8(21),
  35201 			2: uint8(39),
  35202 			3: uint8(155),
  35203 			4: uint8(60),
  35204 			5: uint8(138),
  35205 			6: uint8(23),
  35206 			7: uint8(102),
  35207 			8: uint8(213),
  35208 		},
  35209 		6: {
  35210 			0: uint8(83),
  35211 			1: uint8(12),
  35212 			2: uint8(13),
  35213 			3: uint8(54),
  35214 			4: uint8(192),
  35215 			5: uint8(255),
  35216 			6: uint8(68),
  35217 			7: uint8(47),
  35218 			8: uint8(28),
  35219 		},
  35220 		7: {
  35221 			0: uint8(85),
  35222 			1: uint8(26),
  35223 			2: uint8(85),
  35224 			3: uint8(85),
  35225 			4: uint8(128),
  35226 			5: uint8(128),
  35227 			6: uint8(32),
  35228 			7: uint8(146),
  35229 			8: uint8(171),
  35230 		},
  35231 		8: {
  35232 			0: uint8(18),
  35233 			1: uint8(11),
  35234 			2: uint8(7),
  35235 			3: uint8(63),
  35236 			4: uint8(144),
  35237 			5: uint8(171),
  35238 			6: uint8(4),
  35239 			7: uint8(4),
  35240 			8: uint8(246),
  35241 		},
  35242 		9: {
  35243 			0: uint8(35),
  35244 			1: uint8(27),
  35245 			2: uint8(10),
  35246 			3: uint8(146),
  35247 			4: uint8(174),
  35248 			5: uint8(171),
  35249 			6: uint8(12),
  35250 			7: uint8(26),
  35251 			8: uint8(128),
  35252 		},
  35253 	},
  35254 	9: {
  35255 		0: {
  35256 			0: uint8(190),
  35257 			1: uint8(80),
  35258 			2: uint8(35),
  35259 			3: uint8(99),
  35260 			4: uint8(180),
  35261 			5: uint8(80),
  35262 			6: uint8(126),
  35263 			7: uint8(54),
  35264 			8: uint8(45),
  35265 		},
  35266 		1: {
  35267 			0: uint8(85),
  35268 			1: uint8(126),
  35269 			2: uint8(47),
  35270 			3: uint8(87),
  35271 			4: uint8(176),
  35272 			5: uint8(51),
  35273 			6: uint8(41),
  35274 			7: uint8(20),
  35275 			8: uint8(32),
  35276 		},
  35277 		2: {
  35278 			0: uint8(101),
  35279 			1: uint8(75),
  35280 			2: uint8(128),
  35281 			3: uint8(139),
  35282 			4: uint8(118),
  35283 			5: uint8(146),
  35284 			6: uint8(116),
  35285 			7: uint8(128),
  35286 			8: uint8(85),
  35287 		},
  35288 		3: {
  35289 			0: uint8(56),
  35290 			1: uint8(41),
  35291 			2: uint8(15),
  35292 			3: uint8(176),
  35293 			4: uint8(236),
  35294 			5: uint8(85),
  35295 			6: uint8(37),
  35296 			7: uint8(9),
  35297 			8: uint8(62),
  35298 		},
  35299 		4: {
  35300 			0: uint8(71),
  35301 			1: uint8(30),
  35302 			2: uint8(17),
  35303 			3: uint8(119),
  35304 			4: uint8(118),
  35305 			5: uint8(255),
  35306 			6: uint8(17),
  35307 			7: uint8(18),
  35308 			8: uint8(138),
  35309 		},
  35310 		5: {
  35311 			0: uint8(101),
  35312 			1: uint8(38),
  35313 			2: uint8(60),
  35314 			3: uint8(138),
  35315 			4: uint8(55),
  35316 			5: uint8(70),
  35317 			6: uint8(43),
  35318 			7: uint8(26),
  35319 			8: uint8(142),
  35320 		},
  35321 		6: {
  35322 			0: uint8(146),
  35323 			1: uint8(36),
  35324 			2: uint8(19),
  35325 			3: uint8(30),
  35326 			4: uint8(171),
  35327 			5: uint8(255),
  35328 			6: uint8(97),
  35329 			7: uint8(27),
  35330 			8: uint8(20),
  35331 		},
  35332 		7: {
  35333 			0: uint8(138),
  35334 			1: uint8(45),
  35335 			2: uint8(61),
  35336 			3: uint8(62),
  35337 			4: uint8(219),
  35338 			5: uint8(1),
  35339 			6: uint8(81),
  35340 			7: uint8(188),
  35341 			8: uint8(64),
  35342 		},
  35343 		8: {
  35344 			0: uint8(32),
  35345 			1: uint8(41),
  35346 			2: uint8(20),
  35347 			3: uint8(117),
  35348 			4: uint8(151),
  35349 			5: uint8(142),
  35350 			6: uint8(20),
  35351 			7: uint8(21),
  35352 			8: uint8(163),
  35353 		},
  35354 		9: {
  35355 			0: uint8(112),
  35356 			1: uint8(19),
  35357 			2: uint8(12),
  35358 			3: uint8(61),
  35359 			4: uint8(195),
  35360 			5: uint8(128),
  35361 			6: uint8(48),
  35362 			7: uint8(4),
  35363 			8: uint8(24),
  35364 		},
  35365 	},
  35366 }
  35367 
  35368 func PutI4Mode(tls *libc.TLS, bw uintptr, mode int32, prob uintptr) (r int32) {
  35369 	if VP8PutBit(tls, bw, libc.BoolInt32(mode != int32(B_DC_PRED)), int32(**(**uint8_t)(__ccgo_up(prob)))) != 0 {
  35370 		if VP8PutBit(tls, bw, libc.BoolInt32(mode != int32(B_TM_PRED)), int32(**(**uint8_t)(__ccgo_up(prob + 1)))) != 0 {
  35371 			if VP8PutBit(tls, bw, libc.BoolInt32(mode != int32(B_VE_PRED)), int32(**(**uint8_t)(__ccgo_up(prob + 2)))) != 0 {
  35372 				if !(VP8PutBit(tls, bw, libc.BoolInt32(mode >= int32(B_LD_PRED)), int32(**(**uint8_t)(__ccgo_up(prob + 3)))) != 0) {
  35373 					if VP8PutBit(tls, bw, libc.BoolInt32(mode != int32(B_HE_PRED)), int32(**(**uint8_t)(__ccgo_up(prob + 4)))) != 0 {
  35374 						VP8PutBit(tls, bw, libc.BoolInt32(mode != int32(B_RD_PRED)), int32(**(**uint8_t)(__ccgo_up(prob + 5))))
  35375 					}
  35376 				} else {
  35377 					if VP8PutBit(tls, bw, libc.BoolInt32(mode != int32(B_LD_PRED)), int32(**(**uint8_t)(__ccgo_up(prob + 6)))) != 0 {
  35378 						if VP8PutBit(tls, bw, libc.BoolInt32(mode != int32(B_VL_PRED)), int32(**(**uint8_t)(__ccgo_up(prob + 7)))) != 0 {
  35379 							VP8PutBit(tls, bw, libc.BoolInt32(mode != int32(B_HD_PRED)), int32(**(**uint8_t)(__ccgo_up(prob + 8))))
  35380 						}
  35381 					}
  35382 				}
  35383 			}
  35384 		}
  35385 	}
  35386 	return mode
  35387 }
  35388 
  35389 func PutI16Mode(tls *libc.TLS, bw uintptr, mode int32) {
  35390 	if VP8PutBit(tls, bw, libc.BoolInt32(mode == int32(TM_PRED) || mode == int32(H_PRED)), int32(156)) != 0 {
  35391 		VP8PutBit(tls, bw, libc.BoolInt32(mode == int32(TM_PRED)), int32(128)) // TM or HE
  35392 	} else {
  35393 		VP8PutBit(tls, bw, libc.BoolInt32(mode == int32(V_PRED)), int32(163)) // VE or DC
  35394 	}
  35395 }
  35396 
  35397 func PutUVMode(tls *libc.TLS, bw uintptr, uv_mode int32) {
  35398 	if VP8PutBit(tls, bw, libc.BoolInt32(uv_mode != int32(DC_PRED)), int32(142)) != 0 {
  35399 		if VP8PutBit(tls, bw, libc.BoolInt32(uv_mode != int32(V_PRED)), int32(114)) != 0 {
  35400 			VP8PutBit(tls, bw, libc.BoolInt32(uv_mode != int32(H_PRED)), int32(183)) // else: TM_PRED
  35401 		}
  35402 	}
  35403 }
  35404 
  35405 func PutSegment(tls *libc.TLS, bw uintptr, s int32, p uintptr) {
  35406 	if VP8PutBit(tls, bw, libc.BoolInt32(s >= int32(2)), int32(**(**uint8_t)(__ccgo_up(p)))) != 0 {
  35407 		p = p + uintptr(1)
  35408 	}
  35409 	VP8PutBit(tls, bw, s&int32(1), int32(**(**uint8_t)(__ccgo_up(p + 1))))
  35410 }
  35411 
  35412 func VP8CodeIntraModes(tls *libc.TLS, enc uintptr) {
  35413 	bp := tls.Alloc(3856)
  35414 	defer tls.Free(3856)
  35415 	var bw, mb, preds, probas, top_pred uintptr
  35416 	var left, preds_w, x, y int32
  35417 	var _ /* it at bp+0 */ VP8EncIterator
  35418 	_, _, _, _, _, _, _, _, _ = bw, left, mb, preds, preds_w, probas, top_pred, x, y
  35419 	bw = enc + 64
  35420 	VP8IteratorInit(tls, enc, bp)
  35421 	for cond := true; cond; cond = VP8IteratorNext(tls, bp) != 0 {
  35422 		mb = (**(**VP8EncIterator)(__ccgo_up(bp))).Fmb
  35423 		preds = (**(**VP8EncIterator)(__ccgo_up(bp))).Fpreds
  35424 		if (*VP8Encoder)(unsafe.Pointer(enc)).Fsegment_hdr.Fupdate_map != 0 {
  35425 			PutSegment(tls, bw, int32(uint32(*(*uint8)(unsafe.Pointer(mb + 0))&0x60>>5)), enc+3616)
  35426 		}
  35427 		if (*VP8Encoder)(unsafe.Pointer(enc)).Fproba.Fuse_skip_proba != 0 {
  35428 			VP8PutBit(tls, bw, int32(uint32(*(*uint8)(unsafe.Pointer(mb + 0))&0x10>>4)), int32((*VP8Encoder)(unsafe.Pointer(enc)).Fproba.Fskip_proba))
  35429 		}
  35430 		if VP8PutBit(tls, bw, libc.BoolInt32(int32(uint32(*(*uint8)(unsafe.Pointer(mb + 0))&0x3>>0)) != 0), int32(145)) != 0 { // i16x16
  35431 			PutI16Mode(tls, bw, int32(**(**uint8_t)(__ccgo_up(preds))))
  35432 		} else {
  35433 			preds_w = (*VP8Encoder)(unsafe.Pointer(enc)).Fpreds_w
  35434 			top_pred = preds - uintptr(preds_w)
  35435 			y = 0
  35436 			for {
  35437 				if !(y < int32(4)) {
  35438 					break
  35439 				}
  35440 				left = int32(**(**uint8_t)(__ccgo_up(preds + uintptr(-libc.Int32FromInt32(1)))))
  35441 				x = 0
  35442 				for {
  35443 					if !(x < int32(4)) {
  35444 						break
  35445 					}
  35446 					probas = uintptr(unsafe.Pointer(&kBModesProba1)) + uintptr(**(**uint8_t)(__ccgo_up(top_pred + uintptr(x))))*90 + uintptr(left)*9
  35447 					left = PutI4Mode(tls, bw, int32(**(**uint8_t)(__ccgo_up(preds + uintptr(x)))), probas)
  35448 					goto _2
  35449 				_2:
  35450 					;
  35451 					x = x + 1
  35452 				}
  35453 				top_pred = preds
  35454 				preds = preds + uintptr(preds_w)
  35455 				goto _1
  35456 			_1:
  35457 				;
  35458 				y = y + 1
  35459 			}
  35460 		}
  35461 		PutUVMode(tls, bw, int32(uint32(*(*uint8)(unsafe.Pointer(mb + 0))&0xc>>2)))
  35462 	}
  35463 }
  35464 
  35465 func VP8WriteProbas(tls *libc.TLS, bw uintptr, probas uintptr) {
  35466 	var b, c, p, t, update int32
  35467 	var p0 uint8_t
  35468 	_, _, _, _, _, _ = b, c, p, p0, t, update
  35469 	t = 0
  35470 	for {
  35471 		if !(t < int32(NUM_TYPES)) {
  35472 			break
  35473 		}
  35474 		b = 0
  35475 		for {
  35476 			if !(b < int32(NUM_BANDS)) {
  35477 				break
  35478 			}
  35479 			c = 0
  35480 			for {
  35481 				if !(c < int32(NUM_CTX)) {
  35482 					break
  35483 				}
  35484 				p = 0
  35485 				for {
  35486 					if !(p < int32(NUM_PROBAS)) {
  35487 						break
  35488 					}
  35489 					p0 = **(**uint8_t)(__ccgo_up(probas + 4 + uintptr(t)*264 + uintptr(b)*33 + uintptr(c)*11 + uintptr(p)))
  35490 					update = libc.BoolInt32(int32(p0) != int32(**(**uint8_t)(__ccgo_up(uintptr(unsafe.Pointer(&VP8CoeffsProba0)) + uintptr(t)*264 + uintptr(b)*33 + uintptr(c)*11 + uintptr(p)))))
  35491 					if VP8PutBit(tls, bw, update, int32(**(**uint8_t)(__ccgo_up(uintptr(unsafe.Pointer(&VP8CoeffsUpdateProba)) + uintptr(t)*264 + uintptr(b)*33 + uintptr(c)*11 + uintptr(p))))) != 0 {
  35492 						VP8PutBits(tls, bw, uint32(p0), int32(8))
  35493 					}
  35494 					goto _4
  35495 				_4:
  35496 					;
  35497 					p = p + 1
  35498 				}
  35499 				goto _3
  35500 			_3:
  35501 				;
  35502 				c = c + 1
  35503 			}
  35504 			goto _2
  35505 		_2:
  35506 			;
  35507 			b = b + 1
  35508 		}
  35509 		goto _1
  35510 	_1:
  35511 		;
  35512 		t = t + 1
  35513 	}
  35514 	if VP8PutBitUniform(tls, bw, (*VP8EncProba)(unsafe.Pointer(probas)).Fuse_skip_proba) != 0 {
  35515 		VP8PutBits(tls, bw, uint32((*VP8EncProba)(unsafe.Pointer(probas)).Fskip_proba), int32(8))
  35516 	}
  35517 }
  35518 
  35519 const MAX_HUFF_IMAGE_SIZE = 2600
  35520 const NUM_BUCKETS = 256
  35521 const SIZE_MAX16 = "_UI64_MAX"
  35522 const VP8L_MAGIC_BYTE3 = 47
  35523 const VP8_SIGNATURE2 = 0x9d012a
  35524 
  35525 type HuffmanTreeToken = struct {
  35526 	Fcode       uint8_t
  35527 	Fextra_bits uint8_t
  35528 }
  35529 
  35530 type HuffmanTreeCode = struct {
  35531 	Fnum_symbols  int32
  35532 	Fcode_lengths uintptr
  35533 	Fcodes        uintptr
  35534 }
  35535 
  35536 type HuffmanTree = struct {
  35537 	Ftotal_count      uint32_t
  35538 	Fvalue            int32
  35539 	Fpool_index_left  int32
  35540 	Fpool_index_right int32
  35541 }
  35542 
  35543 type PaletteSorting1 = int32
  35544 
  35545 type PaletteSorting = int32
  35546 
  35547 const kSortedDefault = 0
  35548 const kMinimizeDelta = 1
  35549 const kModifiedZeng = 2
  35550 const kUnusedPalette = 3
  35551 const kPaletteSortingNum = 4
  35552 
  35553 // Copyright 2011 Google Inc. All Rights Reserved.
  35554 //
  35555 // Use of this source code is governed by a BSD-style license
  35556 // that can be found in the COPYING file in the root of the source
  35557 // tree. An additional intellectual property rights grant can be found
  35558 // in the file PATENTS. All contributing project authors may
  35559 // be found in the AUTHORS file in the root of the source tree.
  35560 // -----------------------------------------------------------------------------
  35561 //
  35562 // Multi-threaded worker
  35563 //
  35564 // Author: Skal (pascal.massimino@gmail.com)
  35565 
  35566 // Copyright 2012 Google Inc. All Rights Reserved.
  35567 //
  35568 // Use of this source code is governed by a BSD-style license
  35569 // that can be found in the COPYING file in the root of the source
  35570 // tree. An additional intellectual property rights grant can be found
  35571 // in the file PATENTS. All contributing project authors may
  35572 // be found in the AUTHORS file in the root of the source tree.
  35573 // -----------------------------------------------------------------------------
  35574 //
  35575 // Misc. common utility functions
  35576 //
  35577 // Authors: Skal (pascal.massimino@gmail.com)
  35578 //          Urvang (urvang@google.com)
  35579 
  35580 // Copyright 2011 Google Inc. All Rights Reserved.
  35581 //
  35582 // Use of this source code is governed by a BSD-style license
  35583 // that can be found in the COPYING file in the root of the source
  35584 // tree. An additional intellectual property rights grant can be found
  35585 // in the file PATENTS. All contributing project authors may
  35586 // be found in the AUTHORS file in the root of the source tree.
  35587 // -----------------------------------------------------------------------------
  35588 //
  35589 //   WebP encoder: main interface
  35590 //
  35591 // Author: Skal (pascal.massimino@gmail.com)
  35592 
  35593 // Copyright 2012 Google Inc. All Rights Reserved.
  35594 //
  35595 // Use of this source code is governed by a BSD-style license
  35596 // that can be found in the COPYING file in the root of the source
  35597 // tree. An additional intellectual property rights grant can be found
  35598 // in the file PATENTS. All contributing project authors may
  35599 // be found in the AUTHORS file in the root of the source tree.
  35600 // -----------------------------------------------------------------------------
  35601 //
  35602 //  Internal header for constants related to WebP file format.
  35603 //
  35604 // Author: Urvang (urvang@google.com)
  35605 
  35606 // Copyright 2010 Google Inc. All Rights Reserved.
  35607 //
  35608 // Use of this source code is governed by a BSD-style license
  35609 // that can be found in the COPYING file in the root of the source
  35610 // tree. An additional intellectual property rights grant can be found
  35611 // in the file PATENTS. All contributing project authors may
  35612 // be found in the AUTHORS file in the root of the source tree.
  35613 // -----------------------------------------------------------------------------
  35614 //
  35615 //  Common types + memory wrappers
  35616 //
  35617 // Author: Skal (pascal.massimino@gmail.com)
  35618 
  35619 // Maximum number of histogram images (sub-blocks).
  35620 // Empirical value for which it becomes too computationally expensive to
  35621 // compute the best predictor image.
  35622 
  35623 // -----------------------------------------------------------------------------
  35624 // Palette
  35625 
  35626 // C documentation
  35627 //
  35628 //	// These five modes are evaluated and their respective entropy is computed.
  35629 type EntropyIx = int32
  35630 
  35631 const kDirect = 0
  35632 const kSpatial = 1
  35633 const kSubGreen = 2
  35634 const kSpatialSubGreen = 3
  35635 const kPalette = 4
  35636 const kPaletteAndSpatial = 5
  35637 const kNumEntropyIx = 6
  35638 
  35639 type HistoIx = int32
  35640 
  35641 const kHistoAlpha = 0
  35642 const kHistoAlphaPred = 1
  35643 const kHistoGreen = 2
  35644 const kHistoGreenPred = 3
  35645 const kHistoRed = 4
  35646 const kHistoRedPred = 5
  35647 const kHistoBlue = 6
  35648 const kHistoBluePred = 7
  35649 const kHistoRedSubGreen = 8
  35650 const kHistoRedPredSubGreen = 9
  35651 const kHistoBlueSubGreen = 10
  35652 const kHistoBluePredSubGreen = 11
  35653 const kHistoPalette = 12
  35654 const kHistoTotal = 13
  35655 
  35656 type HistogramBuckets = [256]uint32_t
  35657 
  35658 // C documentation
  35659 //
  35660 //	// Keeping track of histograms, indexed by HistoIx.
  35661 //	// Ideally, this would just be a struct with meaningful fields, but the
  35662 //	// calculation of `entropy_comp` uses the index. One refactoring at a time :)
  35663 type Histograms = struct {
  35664 	Fcategory [13]HistogramBuckets
  35665 }
  35666 
  35667 func AddSingleSubGreen(tls *libc.TLS, p uint32_t, r uintptr, b uintptr) {
  35668 	var green int32
  35669 	_ = green
  35670 	green = int32(p) >> int32(8) // The upper bits are masked away later.
  35671 	**(**uint32_t)(__ccgo_up(r + uintptr((int32(p)>>int32(16)-green)&int32(0xff))*4)) = **(**uint32_t)(__ccgo_up(r + uintptr((int32(p)>>int32(16)-green)&int32(0xff))*4)) + 1
  35672 	**(**uint32_t)(__ccgo_up(b + uintptr((int32(p)>>0-green)&int32(0xff))*4)) = **(**uint32_t)(__ccgo_up(b + uintptr((int32(p)>>0-green)&int32(0xff))*4)) + 1
  35673 }
  35674 
  35675 func AddSingle(tls *libc.TLS, p uint32_t, a uintptr, r uintptr, g uintptr, b uintptr) {
  35676 	**(**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
  35677 	**(**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
  35678 	**(**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
  35679 	**(**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
  35680 }
  35681 
  35682 func HashPix(tls *libc.TLS, pix uint32_t) (r uint8_t) {
  35683 	// Note that masking with 0xffffffffu is for preventing an
  35684 	// 'unsigned int overflow' warning. Doesn't impact the compiled code.
  35685 	return uint8((uint64(pix) + uint64(pix>>libc.Int32FromInt32(19))) * uint64(0x39c5fba7) & uint64(0xffffffff) >> int32(24))
  35686 }
  35687 
  35688 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) {
  35689 	bp := tls.Alloc(48)
  35690 	defer tls.Free(48)
  35691 	var alpha_and_green, pix, pix_diff, pix_prev, red_and_blue, v10, v12, v3, v4, v5, v9 uint32_t
  35692 	var blue_histo, curr_row, histo, prev_row, red_histo uintptr
  35693 	var entropy_comp [13]uint64_t
  35694 	var hash uint8_t
  35695 	var i, j, k, last_mode_to_analyze, x, y, v7 int32
  35696 	var v18 uint32
  35697 	var _ /* entropy at bp+0 */ [6]uint64_t
  35698 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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, v3, v4, v5, v7, v9
  35699 	if use_palette != 0 && palette_size <= int32(16) {
  35700 		// In the case of small palettes, we pack 2, 4 or 8 pixels together. In
  35701 		// practice, small palettes are better than any other transform.
  35702 		**(**EntropyIx)(__ccgo_up(min_entropy_ix)) = int32(kPalette)
  35703 		**(**int32)(__ccgo_up(red_and_blue_always_zero)) = int32(1)
  35704 		return int32(1)
  35705 	}
  35706 	histo = WebPSafeCalloc(tls, uint64(1), uint64(13312))
  35707 	if histo != libc.UintptrFromInt32(0) {
  35708 		prev_row = libc.UintptrFromInt32(0)
  35709 		curr_row = argb
  35710 		pix_prev = **(**uint32_t)(__ccgo_up(argb)) // Skip the first pixel.
  35711 		y = 0
  35712 		for {
  35713 			if !(y < height) {
  35714 				break
  35715 			}
  35716 			x = 0
  35717 			for {
  35718 				if !(x < width) {
  35719 					break
  35720 				}
  35721 				pix = **(**uint32_t)(__ccgo_up(curr_row + uintptr(x)*4))
  35722 				v3 = pix
  35723 				v4 = pix_prev
  35724 				alpha_and_green = uint32(0x00ff00ff) + v3&uint32(0xff00ff00) - v4&uint32(0xff00ff00)
  35725 				red_and_blue = uint32(0xff00ff00) + v3&uint32(0x00ff00ff) - v4&uint32(0x00ff00ff)
  35726 				v5 = alpha_and_green&uint32(0xff00ff00) | red_and_blue&uint32(0x00ff00ff)
  35727 				goto _6
  35728 			_6:
  35729 				pix_diff = v5
  35730 				pix_prev = pix
  35731 				if pix_diff == uint32(0) || prev_row != libc.UintptrFromInt32(0) && pix == **(**uint32_t)(__ccgo_up(prev_row + uintptr(x)*4)) {
  35732 					goto _2
  35733 				}
  35734 				AddSingle(tls, pix, histo+uintptr(kHistoAlpha)*1024, histo+uintptr(kHistoRed)*1024, histo+uintptr(kHistoGreen)*1024, histo+uintptr(kHistoBlue)*1024)
  35735 				AddSingle(tls, pix_diff, histo+uintptr(kHistoAlphaPred)*1024, histo+uintptr(kHistoRedPred)*1024, histo+uintptr(kHistoGreenPred)*1024, histo+uintptr(kHistoBluePred)*1024)
  35736 				AddSingleSubGreen(tls, pix, histo+uintptr(kHistoRedSubGreen)*1024, histo+uintptr(kHistoBlueSubGreen)*1024)
  35737 				AddSingleSubGreen(tls, pix_diff, histo+uintptr(kHistoRedPredSubGreen)*1024, histo+uintptr(kHistoBluePredSubGreen)*1024)
  35738 				// Approximate the palette by the entropy of the multiplicative hash.
  35739 				hash = HashPix(tls, pix)
  35740 				**(**uint32_t)(__ccgo_up(histo + uintptr(kHistoPalette)*1024 + uintptr(hash)*4)) = **(**uint32_t)(__ccgo_up(histo + uintptr(kHistoPalette)*1024 + uintptr(hash)*4)) + 1
  35741 				goto _2
  35742 			_2:
  35743 				;
  35744 				x = x + 1
  35745 			}
  35746 			prev_row = curr_row
  35747 			curr_row = curr_row + uintptr(argb_stride)*4
  35748 			goto _1
  35749 		_1:
  35750 			;
  35751 			y = y + 1
  35752 		}
  35753 		if use_palette != 0 {
  35754 			v7 = int32(kPalette)
  35755 		} else {
  35756 			v7 = int32(kSpatialSubGreen)
  35757 		}
  35758 		last_mode_to_analyze = v7
  35759 		// Let's add one zero to the predicted histograms. The zeros are removed
  35760 		// too efficiently by the pix_diff == 0 comparison, at least one of the
  35761 		// zeros is likely to exist.
  35762 		**(**uint32_t)(__ccgo_up(histo + uintptr(kHistoRedPredSubGreen)*1024)) = **(**uint32_t)(__ccgo_up(histo + uintptr(kHistoRedPredSubGreen)*1024)) + 1
  35763 		**(**uint32_t)(__ccgo_up(histo + uintptr(kHistoBluePredSubGreen)*1024)) = **(**uint32_t)(__ccgo_up(histo + uintptr(kHistoBluePredSubGreen)*1024)) + 1
  35764 		**(**uint32_t)(__ccgo_up(histo + uintptr(kHistoRedPred)*1024)) = **(**uint32_t)(__ccgo_up(histo + uintptr(kHistoRedPred)*1024)) + 1
  35765 		**(**uint32_t)(__ccgo_up(histo + uintptr(kHistoGreenPred)*1024)) = **(**uint32_t)(__ccgo_up(histo + uintptr(kHistoGreenPred)*1024)) + 1
  35766 		**(**uint32_t)(__ccgo_up(histo + uintptr(kHistoBluePred)*1024)) = **(**uint32_t)(__ccgo_up(histo + uintptr(kHistoBluePred)*1024)) + 1
  35767 		**(**uint32_t)(__ccgo_up(histo + uintptr(kHistoAlphaPred)*1024)) = **(**uint32_t)(__ccgo_up(histo + uintptr(kHistoAlphaPred)*1024)) + 1
  35768 		j = 0
  35769 		for {
  35770 			if !(j < int32(kHistoTotal)) {
  35771 				break
  35772 			}
  35773 			entropy_comp[j] = VP8LBitsEntropy(tls, histo+uintptr(j)*1024, int32(NUM_BUCKETS))
  35774 			goto _8
  35775 		_8:
  35776 			;
  35777 			j = j + 1
  35778 		}
  35779 		(**(**[6]uint64_t)(__ccgo_up(bp)))[int32(kDirect)] = entropy_comp[int32(kHistoAlpha)] + entropy_comp[int32(kHistoRed)] + entropy_comp[int32(kHistoGreen)] + entropy_comp[int32(kHistoBlue)]
  35780 		(**(**[6]uint64_t)(__ccgo_up(bp)))[int32(kSpatial)] = entropy_comp[int32(kHistoAlphaPred)] + entropy_comp[int32(kHistoRedPred)] + entropy_comp[int32(kHistoGreenPred)] + entropy_comp[int32(kHistoBluePred)]
  35781 		(**(**[6]uint64_t)(__ccgo_up(bp)))[int32(kSubGreen)] = entropy_comp[int32(kHistoAlpha)] + entropy_comp[int32(kHistoRedSubGreen)] + entropy_comp[int32(kHistoGreen)] + entropy_comp[int32(kHistoBlueSubGreen)]
  35782 		(**(**[6]uint64_t)(__ccgo_up(bp)))[int32(kSpatialSubGreen)] = entropy_comp[int32(kHistoAlphaPred)] + entropy_comp[int32(kHistoRedPredSubGreen)] + entropy_comp[int32(kHistoGreenPred)] + entropy_comp[int32(kHistoBluePredSubGreen)]
  35783 		(**(**[6]uint64_t)(__ccgo_up(bp)))[int32(kPalette)] = entropy_comp[int32(kHistoPalette)]
  35784 		// When including transforms, there is an overhead in bits from
  35785 		// storing them. This overhead is small but matters for small images.
  35786 		// For spatial, there are 14 transformations.
  35787 		v3 = uint32(transform_bits)
  35788 		v4 = (uint32(width) + uint32(libc.Int32FromInt32(1)<<v3) - uint32(1)) >> v3
  35789 		goto _11
  35790 	_11:
  35791 		v5 = uint32(transform_bits)
  35792 		v9 = (uint32(height) + uint32(libc.Int32FromInt32(1)<<v5) - uint32(1)) >> v5
  35793 		goto _14
  35794 	_14:
  35795 		v10 = uint32(14)
  35796 		if v10 < uint32(LOG_LOOKUP_IDX_MAX) {
  35797 			v18 = kLog2Table[v10]
  35798 		} else {
  35799 			v18 = (*(*func(*libc.TLS, uint32_t) uint32_t)(unsafe.Pointer(&struct{ uintptr }{VP8LFastLog2Slow})))(tls, v10)
  35800 		}
  35801 		v12 = v18
  35802 		goto _17
  35803 	_17:
  35804 		**(**uint64_t)(__ccgo_up(bp + uintptr(kSpatial)*8)) += uint64(v4) * uint64(v9) * uint64(v12)
  35805 		// For color transforms: 24 as only 3 channels are considered in a
  35806 		// ColorTransformElement.
  35807 		v3 = uint32(transform_bits)
  35808 		v4 = (uint32(width) + uint32(libc.Int32FromInt32(1)<<v3) - uint32(1)) >> v3
  35809 		goto _21
  35810 	_21:
  35811 		v5 = uint32(transform_bits)
  35812 		v9 = (uint32(height) + uint32(libc.Int32FromInt32(1)<<v5) - uint32(1)) >> v5
  35813 		goto _24
  35814 	_24:
  35815 		v10 = uint32(24)
  35816 		if v10 < uint32(LOG_LOOKUP_IDX_MAX) {
  35817 			v18 = kLog2Table[v10]
  35818 		} else {
  35819 			v18 = (*(*func(*libc.TLS, uint32_t) uint32_t)(unsafe.Pointer(&struct{ uintptr }{VP8LFastLog2Slow})))(tls, v10)
  35820 		}
  35821 		v12 = v18
  35822 		goto _27
  35823 	_27:
  35824 		**(**uint64_t)(__ccgo_up(bp + uintptr(kSpatialSubGreen)*8)) += uint64(v4) * uint64(v9) * uint64(v12)
  35825 		// For palettes, add the cost of storing the palette.
  35826 		// We empirically estimate the cost of a compressed entry as 8 bits.
  35827 		// The palette is differential-coded when compressed hence a much
  35828 		// lower cost than sizeof(uint32_t)*8.
  35829 		**(**uint64_t)(__ccgo_up(bp + uintptr(kPalette)*8)) += uint64(palette_size) * uint64(8) << int32(LOG_2_PRECISION_BITS)
  35830 		**(**EntropyIx)(__ccgo_up(min_entropy_ix)) = int32(kDirect)
  35831 		k = int32(kDirect) + libc.Int32FromInt32(1)
  35832 		for {
  35833 			if !(k <= last_mode_to_analyze) {
  35834 				break
  35835 			}
  35836 			if (**(**[6]uint64_t)(__ccgo_up(bp)))[**(**EntropyIx)(__ccgo_up(min_entropy_ix))] > (**(**[6]uint64_t)(__ccgo_up(bp)))[k] {
  35837 				**(**EntropyIx)(__ccgo_up(min_entropy_ix)) = k
  35838 			}
  35839 			goto _29
  35840 		_29:
  35841 			;
  35842 			k = k + 1
  35843 		}
  35844 		**(**int32)(__ccgo_up(red_and_blue_always_zero)) = int32(1)
  35845 		red_histo = histo + uintptr(**(**uint8_t)(__ccgo_up(uintptr(unsafe.Pointer(&kHistoPairs)) + uintptr(**(**EntropyIx)(__ccgo_up(min_entropy_ix)))*2)))*1024
  35846 		blue_histo = histo + uintptr(**(**uint8_t)(__ccgo_up(uintptr(unsafe.Pointer(&kHistoPairs)) + uintptr(**(**EntropyIx)(__ccgo_up(min_entropy_ix)))*2 + 1)))*1024
  35847 		i = int32(1)
  35848 		for {
  35849 			if !(i < int32(NUM_BUCKETS)) {
  35850 				break
  35851 			}
  35852 			if **(**uint32_t)(__ccgo_up(red_histo + uintptr(i)*4))|**(**uint32_t)(__ccgo_up(blue_histo + uintptr(i)*4)) != uint32(0) {
  35853 				**(**int32)(__ccgo_up(red_and_blue_always_zero)) = 0
  35854 				break
  35855 			}
  35856 			goto _30
  35857 		_30:
  35858 			;
  35859 			i = i + 1
  35860 		}
  35861 		WebPSafeFree(tls, histo)
  35862 		return int32(1)
  35863 	} else {
  35864 		return 0
  35865 	}
  35866 	return r
  35867 }
  35868 
  35869 // Let's check if the histogram of the chosen entropy mode has
  35870 // non-zero red and blue values. If all are zero, we can later skip
  35871 // the cross color optimization.
  35872 
  35873 var kHistoPairs = [5][2]uint8_t{
  35874 	0: {
  35875 		0: uint8(kHistoRed),
  35876 		1: uint8(kHistoBlue),
  35877 	},
  35878 	1: {
  35879 		0: uint8(kHistoRedPred),
  35880 		1: uint8(kHistoBluePred),
  35881 	},
  35882 	2: {
  35883 		0: uint8(kHistoRedSubGreen),
  35884 		1: uint8(kHistoBlueSubGreen),
  35885 	},
  35886 	3: {
  35887 		0: uint8(kHistoRedPredSubGreen),
  35888 		1: uint8(kHistoBluePredSubGreen),
  35889 	},
  35890 	4: {
  35891 		0: uint8(kHistoRed),
  35892 		1: uint8(kHistoBlue),
  35893 	},
  35894 }
  35895 
  35896 // C documentation
  35897 //
  35898 //	// Clamp histogram and transform bits.
  35899 func ClampBits(tls *libc.TLS, width int32, height int32, bits int32, min_bits int32, max_bits int32, image_size_max int32) (r int32) {
  35900 	var image_size, v1, v2 int32
  35901 	var v3, v4, v6, v7 uint32_t
  35902 	_, _, _, _, _, _, _ = image_size, v1, v2, v3, v4, v6, v7
  35903 	if bits < min_bits {
  35904 		v1 = min_bits
  35905 	} else {
  35906 		if bits > max_bits {
  35907 			v2 = max_bits
  35908 		} else {
  35909 			v2 = bits
  35910 		}
  35911 		v1 = v2
  35912 	}
  35913 	bits = v1
  35914 	v3 = uint32(bits)
  35915 	v4 = (uint32(width) + uint32(libc.Int32FromInt32(1)<<v3) - uint32(1)) >> v3
  35916 	goto _5
  35917 _5:
  35918 	v6 = uint32(bits)
  35919 	v7 = (uint32(height) + uint32(libc.Int32FromInt32(1)<<v6) - uint32(1)) >> v6
  35920 	goto _8
  35921 _8:
  35922 	image_size = int32(v4 * v7)
  35923 	for bits < max_bits && image_size > image_size_max {
  35924 		bits = bits + 1
  35925 		v3 = uint32(bits)
  35926 		v4 = (uint32(width) + uint32(libc.Int32FromInt32(1)<<v3) - uint32(1)) >> v3
  35927 		goto _11
  35928 	_11:
  35929 		v6 = uint32(bits)
  35930 		v7 = (uint32(height) + uint32(libc.Int32FromInt32(1)<<v6) - uint32(1)) >> v6
  35931 		goto _14
  35932 	_14:
  35933 		image_size = int32(v4 * v7)
  35934 	}
  35935 	// In case the bits reduce the image too much, choose the smallest value
  35936 	// setting the histogram image size to 1.
  35937 	for bits > min_bits && image_size == int32(1) {
  35938 		v3 = uint32(bits - int32(1))
  35939 		v4 = (uint32(width) + uint32(libc.Int32FromInt32(1)<<v3) - uint32(1)) >> v3
  35940 		goto _17
  35941 	_17:
  35942 		v6 = uint32(bits - int32(1))
  35943 		v7 = (uint32(height) + uint32(libc.Int32FromInt32(1)<<v6) - uint32(1)) >> v6
  35944 		goto _20
  35945 	_20:
  35946 		image_size = int32(v4 * v7)
  35947 		if image_size != int32(1) {
  35948 			break
  35949 		}
  35950 		bits = bits - 1
  35951 	}
  35952 	return bits
  35953 }
  35954 
  35955 func GetHistoBits(tls *libc.TLS, method int32, use_palette int32, width int32, height int32) (r int32) {
  35956 	var histo_bits, v1 int32
  35957 	_, _ = histo_bits, v1
  35958 	if use_palette != 0 {
  35959 		v1 = int32(9)
  35960 	} else {
  35961 		v1 = int32(7)
  35962 	}
  35963 	// Make tile size a function of encoding method (Range: 0 to 6).
  35964 	histo_bits = v1 - method
  35965 	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))
  35966 }
  35967 
  35968 func GetTransformBits(tls *libc.TLS, method int32, histo_bits int32) (r int32) {
  35969 	var max_transform_bits, res, v1, v2, v3 int32
  35970 	_, _, _, _, _ = max_transform_bits, res, v1, v2, v3
  35971 	if method < int32(4) {
  35972 		v1 = int32(6)
  35973 	} else {
  35974 		if method > int32(4) {
  35975 			v2 = int32(4)
  35976 		} else {
  35977 			v2 = int32(5)
  35978 		}
  35979 		v1 = v2
  35980 	}
  35981 	max_transform_bits = v1
  35982 	if histo_bits > max_transform_bits {
  35983 		v3 = max_transform_bits
  35984 	} else {
  35985 		v3 = histo_bits
  35986 	}
  35987 	res = v3
  35988 	return res
  35989 }
  35990 
  35991 // C documentation
  35992 //
  35993 //	// Set of parameters to be used in each iteration of the cruncher.
  35994 type CrunchSubConfig = struct {
  35995 	Flz77        int32
  35996 	Fdo_no_cache int32
  35997 }
  35998 
  35999 type CrunchConfig = struct {
  36000 	Fentropy_idx          int32
  36001 	Fpalette_sorting_type PaletteSorting1
  36002 	Fsub_configs          [2]CrunchSubConfig
  36003 	Fsub_configs_size     int32
  36004 }
  36005 
  36006 // +2 because we add a palette sorting configuration for kPalette and
  36007 // kPaletteAndSpatial.
  36008 
  36009 func EncoderAnalyze(tls *libc.TLS, enc uintptr, crunch_configs uintptr, crunch_configs_size uintptr, red_and_blue_always_zero uintptr) (r int32) {
  36010 	bp := tls.Alloc(16)
  36011 	defer tls.Free(16)
  36012 	var config, pic uintptr
  36013 	var do_no_cache, height, i, j, low_effort, method, n_lz77s, sorting_method, transform_bits, use_palette, width, v1 int32
  36014 	var typed_sorting_method PaletteSorting1
  36015 	var _ /* min_entropy_ix at bp+0 */ EntropyIx
  36016 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = config, do_no_cache, height, i, j, low_effort, method, n_lz77s, pic, sorting_method, transform_bits, typed_sorting_method, use_palette, width, v1
  36017 	pic = (*VP8LEncoder)(unsafe.Pointer(enc)).Fpic
  36018 	width = (*WebPPicture)(unsafe.Pointer(pic)).Fwidth
  36019 	height = (*WebPPicture)(unsafe.Pointer(pic)).Fheight
  36020 	config = (*VP8LEncoder)(unsafe.Pointer(enc)).Fconfig
  36021 	method = (*WebPConfig)(unsafe.Pointer(config)).Fmethod
  36022 	low_effort = libc.BoolInt32((*WebPConfig)(unsafe.Pointer(config)).Fmethod == libc.Int32FromInt32(0))
  36023 	// If set to 0, analyze the cache with the computed cache value. If 1, also
  36024 	// analyze with no-cache.
  36025 	do_no_cache = 0
  36026 	// Check whether a palette is possible.
  36027 	(*VP8LEncoder)(unsafe.Pointer(enc)).Fpalette_size = GetColorPalette(tls, pic, enc+1128)
  36028 	use_palette = libc.BoolInt32((*VP8LEncoder)(unsafe.Pointer(enc)).Fpalette_size <= int32(MAX_PALETTE_SIZE))
  36029 	if !(use_palette != 0) {
  36030 		(*VP8LEncoder)(unsafe.Pointer(enc)).Fpalette_size = 0
  36031 	}
  36032 	// Empirical bit sizes.
  36033 	(*VP8LEncoder)(unsafe.Pointer(enc)).Fhisto_bits = GetHistoBits(tls, method, use_palette, (*WebPPicture)(unsafe.Pointer(pic)).Fwidth, (*WebPPicture)(unsafe.Pointer(pic)).Fheight)
  36034 	transform_bits = GetTransformBits(tls, method, (*VP8LEncoder)(unsafe.Pointer(enc)).Fhisto_bits)
  36035 	(*VP8LEncoder)(unsafe.Pointer(enc)).Fpredictor_transform_bits = transform_bits
  36036 	(*VP8LEncoder)(unsafe.Pointer(enc)).Fcross_color_transform_bits = transform_bits
  36037 	if low_effort != 0 {
  36038 		// AnalyzeEntropy is somewhat slow.
  36039 		if use_palette != 0 {
  36040 			v1 = int32(kPalette)
  36041 		} else {
  36042 			v1 = int32(kSpatialSubGreen)
  36043 		}
  36044 		(**(**CrunchConfig)(__ccgo_up(crunch_configs))).Fentropy_idx = v1
  36045 		if use_palette != 0 {
  36046 			v1 = int32(kSortedDefault)
  36047 		} else {
  36048 			v1 = int32(kUnusedPalette)
  36049 		}
  36050 		(**(**CrunchConfig)(__ccgo_up(crunch_configs))).Fpalette_sorting_type = v1
  36051 		n_lz77s = int32(1)
  36052 		**(**int32)(__ccgo_up(crunch_configs_size)) = int32(1)
  36053 	} else {
  36054 		// Try out multiple LZ77 on images with few colors.
  36055 		if (*VP8LEncoder)(unsafe.Pointer(enc)).Fpalette_size > 0 && (*VP8LEncoder)(unsafe.Pointer(enc)).Fpalette_size <= int32(16) {
  36056 			v1 = int32(2)
  36057 		} else {
  36058 			v1 = int32(1)
  36059 		}
  36060 		n_lz77s = v1
  36061 		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) {
  36062 			return 0
  36063 		}
  36064 		if method == int32(6) && (*WebPConfig)(unsafe.Pointer(config)).Fquality == libc.Float32FromInt32(100) {
  36065 			do_no_cache = int32(1)
  36066 			// Go brute force on all transforms.
  36067 			**(**int32)(__ccgo_up(crunch_configs_size)) = 0
  36068 			i = 0
  36069 			for {
  36070 				if !(i < int32(kNumEntropyIx)) {
  36071 					break
  36072 				}
  36073 				// We can only apply kPalette or kPaletteAndSpatial if we can indeed use
  36074 				// a palette.
  36075 				if i != int32(kPalette) && i != int32(kPaletteAndSpatial) || use_palette != 0 {
  36076 					if use_palette != 0 && (i == int32(kPalette) || i == int32(kPaletteAndSpatial)) {
  36077 						sorting_method = 0
  36078 						for {
  36079 							if !(sorting_method < int32(kPaletteSortingNum)) {
  36080 								break
  36081 							}
  36082 							typed_sorting_method = sorting_method
  36083 							// TODO(vrabaud) kSortedDefault should be tested. It is omitted
  36084 							// for now for backward compatibility.
  36085 							if typed_sorting_method == int32(kUnusedPalette) || typed_sorting_method == int32(kSortedDefault) {
  36086 								goto _5
  36087 							}
  36088 							(**(**CrunchConfig)(__ccgo_up(crunch_configs + uintptr(**(**int32)(__ccgo_up(crunch_configs_size)))*28))).Fentropy_idx = i
  36089 							(**(**CrunchConfig)(__ccgo_up(crunch_configs + uintptr(**(**int32)(__ccgo_up(crunch_configs_size)))*28))).Fpalette_sorting_type = typed_sorting_method
  36090 							**(**int32)(__ccgo_up(crunch_configs_size)) = **(**int32)(__ccgo_up(crunch_configs_size)) + 1
  36091 							goto _5
  36092 						_5:
  36093 							;
  36094 							sorting_method = sorting_method + 1
  36095 						}
  36096 					} else {
  36097 						(**(**CrunchConfig)(__ccgo_up(crunch_configs + uintptr(**(**int32)(__ccgo_up(crunch_configs_size)))*28))).Fentropy_idx = i
  36098 						(**(**CrunchConfig)(__ccgo_up(crunch_configs + uintptr(**(**int32)(__ccgo_up(crunch_configs_size)))*28))).Fpalette_sorting_type = int32(kUnusedPalette)
  36099 						**(**int32)(__ccgo_up(crunch_configs_size)) = **(**int32)(__ccgo_up(crunch_configs_size)) + 1
  36100 					}
  36101 				}
  36102 				goto _4
  36103 			_4:
  36104 				;
  36105 				i = i + 1
  36106 			}
  36107 		} else {
  36108 			// Only choose the guessed best transform.
  36109 			**(**int32)(__ccgo_up(crunch_configs_size)) = int32(1)
  36110 			(**(**CrunchConfig)(__ccgo_up(crunch_configs))).Fentropy_idx = **(**EntropyIx)(__ccgo_up(bp))
  36111 			if use_palette != 0 {
  36112 				v1 = int32(kMinimizeDelta)
  36113 			} else {
  36114 				v1 = int32(kUnusedPalette)
  36115 			}
  36116 			(**(**CrunchConfig)(__ccgo_up(crunch_configs))).Fpalette_sorting_type = v1
  36117 			if (*WebPConfig)(unsafe.Pointer(config)).Fquality >= libc.Float32FromInt32(75) && method == int32(5) {
  36118 				// Test with and without color cache.
  36119 				do_no_cache = int32(1)
  36120 				// If we have a palette, also check in combination with spatial.
  36121 				if **(**EntropyIx)(__ccgo_up(bp)) == int32(kPalette) {
  36122 					**(**int32)(__ccgo_up(crunch_configs_size)) = int32(2)
  36123 					(**(**CrunchConfig)(__ccgo_up(crunch_configs + 1*28))).Fentropy_idx = int32(kPaletteAndSpatial)
  36124 					(**(**CrunchConfig)(__ccgo_up(crunch_configs + 1*28))).Fpalette_sorting_type = int32(kMinimizeDelta)
  36125 				}
  36126 			}
  36127 		}
  36128 	}
  36129 	// Fill in the different LZ77s.
  36130 	i = 0
  36131 	for {
  36132 		if !(i < **(**int32)(__ccgo_up(crunch_configs_size))) {
  36133 			break
  36134 		}
  36135 		j = 0
  36136 		for {
  36137 			if !(j < n_lz77s) {
  36138 				break
  36139 			}
  36140 			if j == 0 {
  36141 				v1 = int32(kLZ77Standard) | int32(kLZ77RLE)
  36142 			} else {
  36143 				v1 = int32(kLZ77Box)
  36144 			}
  36145 			(**(**CrunchSubConfig)(__ccgo_up(crunch_configs + uintptr(i)*28 + 8 + uintptr(j)*8))).Flz77 = v1
  36146 			(**(**CrunchSubConfig)(__ccgo_up(crunch_configs + uintptr(i)*28 + 8 + uintptr(j)*8))).Fdo_no_cache = do_no_cache
  36147 			goto _8
  36148 		_8:
  36149 			;
  36150 			j = j + 1
  36151 		}
  36152 		(**(**CrunchConfig)(__ccgo_up(crunch_configs + uintptr(i)*28))).Fsub_configs_size = n_lz77s
  36153 		goto _7
  36154 	_7:
  36155 		;
  36156 		i = i + 1
  36157 	}
  36158 	return int32(1)
  36159 }
  36160 
  36161 func EncoderInit(tls *libc.TLS, enc uintptr) (r int32) {
  36162 	var height, i, pix_cnt, refs_block_size, width int32
  36163 	var pic uintptr
  36164 	_, _, _, _, _, _ = height, i, pic, pix_cnt, refs_block_size, width
  36165 	pic = (*VP8LEncoder)(unsafe.Pointer(enc)).Fpic
  36166 	width = (*WebPPicture)(unsafe.Pointer(pic)).Fwidth
  36167 	height = (*WebPPicture)(unsafe.Pointer(pic)).Fheight
  36168 	pix_cnt = width * height
  36169 	// we round the block size up, so we're guaranteed to have
  36170 	// at most MAX_REFS_BLOCK_PER_IMAGE blocks used:
  36171 	refs_block_size = (pix_cnt-int32(1))/int32(MAX_REFS_BLOCK_PER_IMAGE) + int32(1)
  36172 	if !(VP8LHashChainInit(tls, enc+2312, pix_cnt) != 0) {
  36173 		return 0
  36174 	}
  36175 	i = 0
  36176 	for {
  36177 		if !(i < int32(4)) {
  36178 			break
  36179 		}
  36180 		VP8LBackwardRefsInit(tls, enc+2152+uintptr(i)*40, refs_block_size)
  36181 		goto _1
  36182 	_1:
  36183 		;
  36184 		i = i + 1
  36185 	}
  36186 	return int32(1)
  36187 }
  36188 
  36189 // C documentation
  36190 //
  36191 //	// Returns false in case of memory error.
  36192 func GetHuffBitLengthsAndCodes(tls *libc.TLS, histogram_image uintptr, huffman_codes uintptr) (r int32) {
  36193 	var bit_length, histogram_image_size, i, k, max_num_symbols, num_symbols, ok, v3, v4, v5, v7, v8 int32
  36194 	var buf_rle, codes, codes1, codes2, histo, histo1, huff_tree, lengths, mem_buf uintptr
  36195 	var total_length_size uint64_t
  36196 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  36197 	ok = 0
  36198 	total_length_size = uint64(0)
  36199 	mem_buf = libc.UintptrFromInt32(0)
  36200 	histogram_image_size = (*VP8LHistogramSet)(unsafe.Pointer(histogram_image)).Fsize
  36201 	max_num_symbols = 0
  36202 	buf_rle = libc.UintptrFromInt32(0)
  36203 	huff_tree = libc.UintptrFromInt32(0)
  36204 	// Iterate over all histograms and get the aggregate number of codes used.
  36205 	i = 0
  36206 	for {
  36207 		if !(i < histogram_image_size) {
  36208 			break
  36209 		}
  36210 		histo = **(**uintptr)(__ccgo_up((*VP8LHistogramSet)(unsafe.Pointer(histogram_image)).Fhistograms + uintptr(i)*8))
  36211 		codes = huffman_codes + uintptr(int32(5)*i)*24
  36212 		k = 0
  36213 		for {
  36214 			if !(k < int32(5)) {
  36215 				break
  36216 			}
  36217 			if k == 0 {
  36218 				v4 = (*VP8LHistogram)(unsafe.Pointer(histo)).Fpalette_code_bits
  36219 				if v4 > 0 {
  36220 					v7 = int32(1) << v4
  36221 				} else {
  36222 					v7 = 0
  36223 				}
  36224 				v5 = libc.Int32FromInt32(NUM_LITERAL_CODES) + libc.Int32FromInt32(NUM_LENGTH_CODES) + v7
  36225 				goto _6
  36226 			_6:
  36227 				v3 = v5
  36228 			} else {
  36229 				if k == int32(4) {
  36230 					v8 = int32(NUM_DISTANCE_CODES)
  36231 				} else {
  36232 					v8 = int32(256)
  36233 				}
  36234 				v3 = v8
  36235 			}
  36236 			num_symbols = v3
  36237 			(**(**HuffmanTreeCode)(__ccgo_up(codes + uintptr(k)*24))).Fnum_symbols = num_symbols
  36238 			total_length_size = total_length_size + uint64(num_symbols)
  36239 			goto _2
  36240 		_2:
  36241 			;
  36242 			k = k + 1
  36243 		}
  36244 		goto _1
  36245 	_1:
  36246 		;
  36247 		i = i + 1
  36248 	}
  36249 	// Allocate and Set Huffman codes.
  36250 	mem_buf = WebPSafeCalloc(tls, total_length_size, libc.Uint64FromInt64(1)+libc.Uint64FromInt64(2))
  36251 	if mem_buf == libc.UintptrFromInt32(0) {
  36252 		goto End
  36253 	}
  36254 	codes1 = mem_buf
  36255 	lengths = codes1 + uintptr(total_length_size)*2
  36256 	i = 0
  36257 	for {
  36258 		if !(i < int32(5)*histogram_image_size) {
  36259 			break
  36260 		}
  36261 		bit_length = (**(**HuffmanTreeCode)(__ccgo_up(huffman_codes + uintptr(i)*24))).Fnum_symbols
  36262 		(**(**HuffmanTreeCode)(__ccgo_up(huffman_codes + uintptr(i)*24))).Fcodes = codes1
  36263 		(**(**HuffmanTreeCode)(__ccgo_up(huffman_codes + uintptr(i)*24))).Fcode_lengths = lengths
  36264 		codes1 = codes1 + uintptr(bit_length)*2
  36265 		lengths = lengths + uintptr(bit_length)
  36266 		if max_num_symbols < bit_length {
  36267 			max_num_symbols = bit_length
  36268 		}
  36269 		goto _9
  36270 	_9:
  36271 		;
  36272 		i = i + 1
  36273 	}
  36274 	buf_rle = WebPSafeMalloc(tls, uint64(1), uint64(max_num_symbols))
  36275 	huff_tree = WebPSafeMalloc(tls, uint64(3)*uint64(max_num_symbols), uint64(16))
  36276 	if buf_rle == libc.UintptrFromInt32(0) || huff_tree == libc.UintptrFromInt32(0) {
  36277 		goto End
  36278 	}
  36279 	// Create Huffman trees.
  36280 	i = 0
  36281 	for {
  36282 		if !(i < histogram_image_size) {
  36283 			break
  36284 		}
  36285 		codes2 = huffman_codes + uintptr(int32(5)*i)*24
  36286 		histo1 = **(**uintptr)(__ccgo_up((*VP8LHistogramSet)(unsafe.Pointer(histogram_image)).Fhistograms + uintptr(i)*8))
  36287 		VP8LCreateHuffmanTree(tls, (*VP8LHistogram)(unsafe.Pointer(histo1)).Fliteral, int32(15), buf_rle, huff_tree, codes2+uintptr(0)*24)
  36288 		VP8LCreateHuffmanTree(tls, histo1+8, int32(15), buf_rle, huff_tree, codes2+uintptr(1)*24)
  36289 		VP8LCreateHuffmanTree(tls, histo1+1032, int32(15), buf_rle, huff_tree, codes2+uintptr(2)*24)
  36290 		VP8LCreateHuffmanTree(tls, histo1+2056, int32(15), buf_rle, huff_tree, codes2+uintptr(3)*24)
  36291 		VP8LCreateHuffmanTree(tls, histo1+3080, int32(15), buf_rle, huff_tree, codes2+uintptr(4)*24)
  36292 		goto _10
  36293 	_10:
  36294 		;
  36295 		i = i + 1
  36296 	}
  36297 	ok = int32(1)
  36298 	goto End
  36299 End:
  36300 	;
  36301 	WebPSafeFree(tls, huff_tree)
  36302 	WebPSafeFree(tls, buf_rle)
  36303 	if !(ok != 0) {
  36304 		WebPSafeFree(tls, mem_buf)
  36305 		libc.Xmemset(tls, huffman_codes, 0, uint64(int32(5)*histogram_image_size)*uint64(24))
  36306 	}
  36307 	return ok
  36308 }
  36309 
  36310 func StoreHuffmanTreeOfHuffmanTreeToBitMask(tls *libc.TLS, bw1 uintptr, code_length_bitdepth uintptr) {
  36311 	var codes_to_store, i, v4 int32
  36312 	var v2 uintptr
  36313 	var v3 uint32_t
  36314 	_, _, _, _, _ = codes_to_store, i, v2, v3, v4
  36315 	// Throw away trailing zeros:
  36316 	codes_to_store = int32(CODE_LENGTH_CODES)
  36317 	for {
  36318 		if !(codes_to_store > int32(4)) {
  36319 			break
  36320 		}
  36321 		if int32(**(**uint8_t)(__ccgo_up(code_length_bitdepth + uintptr(kStorageOrder[codes_to_store-int32(1)])))) != 0 {
  36322 			break
  36323 		}
  36324 		goto _1
  36325 	_1:
  36326 		;
  36327 		codes_to_store = codes_to_store - 1
  36328 	}
  36329 	v2 = bw1
  36330 	v3 = uint32(codes_to_store - int32(4))
  36331 	v4 = int32(4)
  36332 	if libc.Uint64FromInt64(4) == libc.Uint64FromInt32(4) {
  36333 		if v4 > libc.Int32FromInt32(0) {
  36334 			if (*VP8LBitWriter)(unsafe.Pointer(v2)).Fused >= libc.Int32FromInt32(32) {
  36335 				VP8LPutBitsFlushBits(tls, v2)
  36336 			}
  36337 			**(**vp8l_atype_t)(__ccgo_up(v2)) |= uint64(v3) << (*VP8LBitWriter)(unsafe.Pointer(v2)).Fused
  36338 			**(**int32)(__ccgo_up(v2 + 8)) += v4
  36339 		}
  36340 	} else {
  36341 		VP8LPutBitsInternal(tls, v2, v3, v4)
  36342 	}
  36343 	i = 0
  36344 	for {
  36345 		if !(i < codes_to_store) {
  36346 			break
  36347 		}
  36348 		v2 = bw1
  36349 		v3 = uint32(**(**uint8_t)(__ccgo_up(code_length_bitdepth + uintptr(kStorageOrder[i]))))
  36350 		v4 = int32(3)
  36351 		if libc.Uint64FromInt64(4) == libc.Uint64FromInt32(4) {
  36352 			if v4 > libc.Int32FromInt32(0) {
  36353 				if (*VP8LBitWriter)(unsafe.Pointer(v2)).Fused >= libc.Int32FromInt32(32) {
  36354 					VP8LPutBitsFlushBits(tls, v2)
  36355 				}
  36356 				**(**vp8l_atype_t)(__ccgo_up(v2)) |= uint64(v3) << (*VP8LBitWriter)(unsafe.Pointer(v2)).Fused
  36357 				**(**int32)(__ccgo_up(v2 + 8)) += v4
  36358 			}
  36359 		} else {
  36360 			VP8LPutBitsInternal(tls, v2, v3, v4)
  36361 		}
  36362 		goto _5
  36363 	_5:
  36364 		;
  36365 		i = i + 1
  36366 	}
  36367 }
  36368 
  36369 // RFC 1951 will calm you down if you are worried about this funny sequence.
  36370 // This sequence is tuned from that, but more weighted for lower symbol count,
  36371 // and more spiking histograms.
  36372 var kStorageOrder = [19]uint8_t{
  36373 	0:  uint8(17),
  36374 	1:  uint8(18),
  36375 	3:  uint8(1),
  36376 	4:  uint8(2),
  36377 	5:  uint8(3),
  36378 	6:  uint8(4),
  36379 	7:  uint8(5),
  36380 	8:  uint8(16),
  36381 	9:  uint8(6),
  36382 	10: uint8(7),
  36383 	11: uint8(8),
  36384 	12: uint8(9),
  36385 	13: uint8(10),
  36386 	14: uint8(11),
  36387 	15: uint8(12),
  36388 	16: uint8(13),
  36389 	17: uint8(14),
  36390 	18: uint8(15),
  36391 }
  36392 
  36393 func ClearHuffmanTreeIfOnlyOneSymbol(tls *libc.TLS, huffman_code uintptr) {
  36394 	var count, k int32
  36395 	_, _ = count, k
  36396 	count = 0
  36397 	k = 0
  36398 	for {
  36399 		if !(k < (*HuffmanTreeCode)(unsafe.Pointer(huffman_code)).Fnum_symbols) {
  36400 			break
  36401 		}
  36402 		if int32(**(**uint8_t)(__ccgo_up((*HuffmanTreeCode)(unsafe.Pointer(huffman_code)).Fcode_lengths + uintptr(k)))) != 0 {
  36403 			count = count + 1
  36404 			if count > int32(1) {
  36405 				return
  36406 			}
  36407 		}
  36408 		goto _1
  36409 	_1:
  36410 		;
  36411 		k = k + 1
  36412 	}
  36413 	k = 0
  36414 	for {
  36415 		if !(k < (*HuffmanTreeCode)(unsafe.Pointer(huffman_code)).Fnum_symbols) {
  36416 			break
  36417 		}
  36418 		**(**uint8_t)(__ccgo_up((*HuffmanTreeCode)(unsafe.Pointer(huffman_code)).Fcode_lengths + uintptr(k))) = uint8(0)
  36419 		**(**uint16_t)(__ccgo_up((*HuffmanTreeCode)(unsafe.Pointer(huffman_code)).Fcodes + uintptr(k)*2)) = uint16(0)
  36420 		goto _2
  36421 	_2:
  36422 		;
  36423 		k = k + 1
  36424 	}
  36425 }
  36426 
  36427 func StoreHuffmanTreeToBitMask(tls *libc.TLS, bw1 uintptr, tokens uintptr, num_tokens int32, huffman_code uintptr) {
  36428 	var extra_bits, i, ix, v4 int32
  36429 	var v2 uintptr
  36430 	var v3 uint32_t
  36431 	_, _, _, _, _, _ = extra_bits, i, ix, v2, v3, v4
  36432 	i = 0
  36433 	for {
  36434 		if !(i < num_tokens) {
  36435 			break
  36436 		}
  36437 		ix = int32((**(**HuffmanTreeToken)(__ccgo_up(tokens + uintptr(i)*2))).Fcode)
  36438 		extra_bits = int32((**(**HuffmanTreeToken)(__ccgo_up(tokens + uintptr(i)*2))).Fextra_bits)
  36439 		v2 = bw1
  36440 		v3 = uint32(**(**uint16_t)(__ccgo_up((*HuffmanTreeCode)(unsafe.Pointer(huffman_code)).Fcodes + uintptr(ix)*2)))
  36441 		v4 = int32(**(**uint8_t)(__ccgo_up((*HuffmanTreeCode)(unsafe.Pointer(huffman_code)).Fcode_lengths + uintptr(ix))))
  36442 		if libc.Uint64FromInt64(4) == libc.Uint64FromInt32(4) {
  36443 			if v4 > libc.Int32FromInt32(0) {
  36444 				if (*VP8LBitWriter)(unsafe.Pointer(v2)).Fused >= libc.Int32FromInt32(32) {
  36445 					VP8LPutBitsFlushBits(tls, v2)
  36446 				}
  36447 				**(**vp8l_atype_t)(__ccgo_up(v2)) |= uint64(v3) << (*VP8LBitWriter)(unsafe.Pointer(v2)).Fused
  36448 				**(**int32)(__ccgo_up(v2 + 8)) += v4
  36449 			}
  36450 		} else {
  36451 			VP8LPutBitsInternal(tls, v2, v3, v4)
  36452 		}
  36453 		switch ix {
  36454 		case int32(16):
  36455 			v2 = bw1
  36456 			v3 = uint32(extra_bits)
  36457 			v4 = int32(2)
  36458 			if libc.Uint64FromInt64(4) == libc.Uint64FromInt32(4) {
  36459 				if v4 > libc.Int32FromInt32(0) {
  36460 					if (*VP8LBitWriter)(unsafe.Pointer(v2)).Fused >= libc.Int32FromInt32(32) {
  36461 						VP8LPutBitsFlushBits(tls, v2)
  36462 					}
  36463 					**(**vp8l_atype_t)(__ccgo_up(v2)) |= uint64(v3) << (*VP8LBitWriter)(unsafe.Pointer(v2)).Fused
  36464 					**(**int32)(__ccgo_up(v2 + 8)) += v4
  36465 				}
  36466 			} else {
  36467 				VP8LPutBitsInternal(tls, v2, v3, v4)
  36468 			}
  36469 		case int32(17):
  36470 			v2 = bw1
  36471 			v3 = uint32(extra_bits)
  36472 			v4 = int32(3)
  36473 			if libc.Uint64FromInt64(4) == libc.Uint64FromInt32(4) {
  36474 				if v4 > libc.Int32FromInt32(0) {
  36475 					if (*VP8LBitWriter)(unsafe.Pointer(v2)).Fused >= libc.Int32FromInt32(32) {
  36476 						VP8LPutBitsFlushBits(tls, v2)
  36477 					}
  36478 					**(**vp8l_atype_t)(__ccgo_up(v2)) |= uint64(v3) << (*VP8LBitWriter)(unsafe.Pointer(v2)).Fused
  36479 					**(**int32)(__ccgo_up(v2 + 8)) += v4
  36480 				}
  36481 			} else {
  36482 				VP8LPutBitsInternal(tls, v2, v3, v4)
  36483 			}
  36484 		case int32(18):
  36485 			v2 = bw1
  36486 			v3 = uint32(extra_bits)
  36487 			v4 = int32(7)
  36488 			if libc.Uint64FromInt64(4) == libc.Uint64FromInt32(4) {
  36489 				if v4 > libc.Int32FromInt32(0) {
  36490 					if (*VP8LBitWriter)(unsafe.Pointer(v2)).Fused >= libc.Int32FromInt32(32) {
  36491 						VP8LPutBitsFlushBits(tls, v2)
  36492 					}
  36493 					**(**vp8l_atype_t)(__ccgo_up(v2)) |= uint64(v3) << (*VP8LBitWriter)(unsafe.Pointer(v2)).Fused
  36494 					**(**int32)(__ccgo_up(v2 + 8)) += v4
  36495 				}
  36496 			} else {
  36497 				VP8LPutBitsInternal(tls, v2, v3, v4)
  36498 			}
  36499 			break
  36500 		}
  36501 		goto _1
  36502 	_1:
  36503 		;
  36504 		i = i + 1
  36505 	}
  36506 }
  36507 
  36508 // C documentation
  36509 //
  36510 //	// 'huff_tree' and 'tokens' are pre-alloacted buffers.
  36511 func StoreFullHuffmanCode(tls *libc.TLS, bw1 uintptr, huff_tree uintptr, tokens uintptr, tree uintptr) {
  36512 	bp := tls.Alloc(192)
  36513 	defer tls.Free(192)
  36514 	var i, i1, ix, length, max_tokens, nbitpairs, nbits, num_tokens, trailing_zero_bits, trimmed_length, write_trimmed_length, v3 int32
  36515 	var v1 uintptr
  36516 	var v2 uint32_t
  36517 	var _ /* buf_rle at bp+164 */ [19]uint8_t
  36518 	var _ /* code_length_bitdepth at bp+0 */ [19]uint8_t
  36519 	var _ /* code_length_bitdepth_symbols at bp+20 */ [19]uint16_t
  36520 	var _ /* histogram at bp+88 */ [19]uint32_t
  36521 	var _ /* huffman_code at bp+64 */ HuffmanTreeCode
  36522 	_, _, _, _, _, _, _, _, _, _, _, _, _, _ = i, i1, ix, length, max_tokens, nbitpairs, nbits, num_tokens, trailing_zero_bits, trimmed_length, write_trimmed_length, v1, v2, v3
  36523 	**(**[19]uint8_t)(__ccgo_up(bp)) = [19]uint8_t{}
  36524 	**(**[19]uint16_t)(__ccgo_up(bp + 20)) = [19]uint16_t{}
  36525 	max_tokens = (*HuffmanTreeCode)(unsafe.Pointer(tree)).Fnum_symbols
  36526 	(**(**HuffmanTreeCode)(__ccgo_up(bp + 64))).Fnum_symbols = int32(CODE_LENGTH_CODES)
  36527 	(**(**HuffmanTreeCode)(__ccgo_up(bp + 64))).Fcode_lengths = bp
  36528 	(**(**HuffmanTreeCode)(__ccgo_up(bp + 64))).Fcodes = bp + 20
  36529 	v1 = bw1
  36530 	v2 = uint32(0)
  36531 	v3 = int32(1)
  36532 	if libc.Uint64FromInt64(4) == libc.Uint64FromInt32(4) {
  36533 		if v3 > libc.Int32FromInt32(0) {
  36534 			if (*VP8LBitWriter)(unsafe.Pointer(v1)).Fused >= libc.Int32FromInt32(32) {
  36535 				VP8LPutBitsFlushBits(tls, v1)
  36536 			}
  36537 			**(**vp8l_atype_t)(__ccgo_up(v1)) |= uint64(v2) << (*VP8LBitWriter)(unsafe.Pointer(v1)).Fused
  36538 			**(**int32)(__ccgo_up(v1 + 8)) += v3
  36539 		}
  36540 	} else {
  36541 		VP8LPutBitsInternal(tls, v1, v2, v3)
  36542 	}
  36543 	num_tokens = VP8LCreateCompressedHuffmanTree(tls, tree, tokens, max_tokens)
  36544 	**(**[19]uint32_t)(__ccgo_up(bp + 88)) = [19]uint32_t{}
  36545 	**(**[19]uint8_t)(__ccgo_up(bp + 164)) = [19]uint8_t{}
  36546 	i = 0
  36547 	for {
  36548 		if !(i < num_tokens) {
  36549 			break
  36550 		}
  36551 		(**(**[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
  36552 		goto _4
  36553 	_4:
  36554 		;
  36555 		i = i + 1
  36556 	}
  36557 	VP8LCreateHuffmanTree(tls, bp+88, int32(7), bp+164, huff_tree, bp+64)
  36558 	StoreHuffmanTreeOfHuffmanTreeToBitMask(tls, bw1, bp)
  36559 	ClearHuffmanTreeIfOnlyOneSymbol(tls, bp+64)
  36560 	trailing_zero_bits = 0
  36561 	trimmed_length = num_tokens
  36562 	i1 = num_tokens
  36563 	for {
  36564 		v3 = i1
  36565 		i1 = i1 - 1
  36566 		if !(v3 > 0) {
  36567 			break
  36568 		}
  36569 		ix = int32((**(**HuffmanTreeToken)(__ccgo_up(tokens + uintptr(i1)*2))).Fcode)
  36570 		if ix == 0 || ix == int32(17) || ix == int32(18) {
  36571 			trimmed_length = trimmed_length - 1 // discount trailing zeros
  36572 			trailing_zero_bits = trailing_zero_bits + int32((**(**[19]uint8_t)(__ccgo_up(bp)))[ix])
  36573 			if ix == int32(17) {
  36574 				trailing_zero_bits = trailing_zero_bits + int32(3)
  36575 			} else {
  36576 				if ix == int32(18) {
  36577 					trailing_zero_bits = trailing_zero_bits + int32(7)
  36578 				}
  36579 			}
  36580 		} else {
  36581 			break
  36582 		}
  36583 	}
  36584 	write_trimmed_length = libc.BoolInt32(trimmed_length > int32(1) && trailing_zero_bits > int32(12))
  36585 	if write_trimmed_length != 0 {
  36586 		v3 = trimmed_length
  36587 	} else {
  36588 		v3 = num_tokens
  36589 	}
  36590 	length = v3
  36591 	v1 = bw1
  36592 	v2 = uint32(write_trimmed_length)
  36593 	v3 = int32(1)
  36594 	if libc.Uint64FromInt64(4) == libc.Uint64FromInt32(4) {
  36595 		if v3 > libc.Int32FromInt32(0) {
  36596 			if (*VP8LBitWriter)(unsafe.Pointer(v1)).Fused >= libc.Int32FromInt32(32) {
  36597 				VP8LPutBitsFlushBits(tls, v1)
  36598 			}
  36599 			**(**vp8l_atype_t)(__ccgo_up(v1)) |= uint64(v2) << (*VP8LBitWriter)(unsafe.Pointer(v1)).Fused
  36600 			**(**int32)(__ccgo_up(v1 + 8)) += v3
  36601 		}
  36602 	} else {
  36603 		VP8LPutBitsInternal(tls, v1, v2, v3)
  36604 	}
  36605 	if write_trimmed_length != 0 {
  36606 		if trimmed_length == int32(2) {
  36607 			v1 = bw1
  36608 			v2 = uint32(0)
  36609 			v3 = libc.Int32FromInt32(3) + libc.Int32FromInt32(2)
  36610 			if libc.Uint64FromInt64(4) == libc.Uint64FromInt32(4) {
  36611 				if v3 > libc.Int32FromInt32(0) {
  36612 					if (*VP8LBitWriter)(unsafe.Pointer(v1)).Fused >= libc.Int32FromInt32(32) {
  36613 						VP8LPutBitsFlushBits(tls, v1)
  36614 					}
  36615 					**(**vp8l_atype_t)(__ccgo_up(v1)) |= uint64(v2) << (*VP8LBitWriter)(unsafe.Pointer(v1)).Fused
  36616 					**(**int32)(__ccgo_up(v1 + 8)) += v3
  36617 				}
  36618 			} else {
  36619 				VP8LPutBitsInternal(tls, v1, v2, v3)
  36620 			} // nbitpairs=1, trimmed_length=2
  36621 		} else {
  36622 			v3 = int32(31) ^ libc.X__builtin_clz(tls, uint32(trimmed_length-int32(2)))
  36623 			goto _14
  36624 		_14:
  36625 			nbits = v3
  36626 			nbitpairs = nbits/int32(2) + int32(1)
  36627 			v1 = bw1
  36628 			v2 = uint32(nbitpairs - int32(1))
  36629 			v3 = int32(3)
  36630 			if libc.Uint64FromInt64(4) == libc.Uint64FromInt32(4) {
  36631 				if v3 > libc.Int32FromInt32(0) {
  36632 					if (*VP8LBitWriter)(unsafe.Pointer(v1)).Fused >= libc.Int32FromInt32(32) {
  36633 						VP8LPutBitsFlushBits(tls, v1)
  36634 					}
  36635 					**(**vp8l_atype_t)(__ccgo_up(v1)) |= uint64(v2) << (*VP8LBitWriter)(unsafe.Pointer(v1)).Fused
  36636 					**(**int32)(__ccgo_up(v1 + 8)) += v3
  36637 				}
  36638 			} else {
  36639 				VP8LPutBitsInternal(tls, v1, v2, v3)
  36640 			}
  36641 			v1 = bw1
  36642 			v2 = uint32(trimmed_length - int32(2))
  36643 			v3 = nbitpairs * int32(2)
  36644 			if libc.Uint64FromInt64(4) == libc.Uint64FromInt32(4) {
  36645 				if v3 > libc.Int32FromInt32(0) {
  36646 					if (*VP8LBitWriter)(unsafe.Pointer(v1)).Fused >= libc.Int32FromInt32(32) {
  36647 						VP8LPutBitsFlushBits(tls, v1)
  36648 					}
  36649 					**(**vp8l_atype_t)(__ccgo_up(v1)) |= uint64(v2) << (*VP8LBitWriter)(unsafe.Pointer(v1)).Fused
  36650 					**(**int32)(__ccgo_up(v1 + 8)) += v3
  36651 				}
  36652 			} else {
  36653 				VP8LPutBitsInternal(tls, v1, v2, v3)
  36654 			}
  36655 		}
  36656 	}
  36657 	StoreHuffmanTreeToBitMask(tls, bw1, tokens, length, bp+64)
  36658 }
  36659 
  36660 // C documentation
  36661 //
  36662 //	// 'huff_tree' and 'tokens' are pre-alloacted buffers.
  36663 func StoreHuffmanCode(tls *libc.TLS, bw1 uintptr, huff_tree uintptr, tokens uintptr, huffman_code uintptr) {
  36664 	var count, i, kMaxBits, kMaxSymbol, v4 int32
  36665 	var symbols [2]int32
  36666 	var v2 uintptr
  36667 	var v3 uint32_t
  36668 	_, _, _, _, _, _, _, _ = count, i, kMaxBits, kMaxSymbol, symbols, v2, v3, v4
  36669 	count = 0
  36670 	symbols = [2]int32{}
  36671 	kMaxBits = int32(8)
  36672 	kMaxSymbol = int32(1) << kMaxBits
  36673 	// Check whether it's a small tree.
  36674 	i = 0
  36675 	for {
  36676 		if !(i < (*HuffmanTreeCode)(unsafe.Pointer(huffman_code)).Fnum_symbols && count < int32(3)) {
  36677 			break
  36678 		}
  36679 		if int32(**(**uint8_t)(__ccgo_up((*HuffmanTreeCode)(unsafe.Pointer(huffman_code)).Fcode_lengths + uintptr(i)))) != 0 {
  36680 			if count < int32(2) {
  36681 				symbols[count] = i
  36682 			}
  36683 			count = count + 1
  36684 		}
  36685 		goto _1
  36686 	_1:
  36687 		;
  36688 		i = i + 1
  36689 	}
  36690 	if count == 0 { // emit minimal tree for empty cases
  36691 		// bits: small tree marker: 1, count-1: 0, large 8-bit code: 0, code: 0
  36692 		v2 = bw1
  36693 		v3 = uint32(0x01)
  36694 		v4 = int32(4)
  36695 		if libc.Uint64FromInt64(4) == libc.Uint64FromInt32(4) {
  36696 			if v4 > libc.Int32FromInt32(0) {
  36697 				if (*VP8LBitWriter)(unsafe.Pointer(v2)).Fused >= libc.Int32FromInt32(32) {
  36698 					VP8LPutBitsFlushBits(tls, v2)
  36699 				}
  36700 				**(**vp8l_atype_t)(__ccgo_up(v2)) |= uint64(v3) << (*VP8LBitWriter)(unsafe.Pointer(v2)).Fused
  36701 				**(**int32)(__ccgo_up(v2 + 8)) += v4
  36702 			}
  36703 		} else {
  36704 			VP8LPutBitsInternal(tls, v2, v3, v4)
  36705 		}
  36706 	} else {
  36707 		if count <= int32(2) && symbols[0] < kMaxSymbol && symbols[int32(1)] < kMaxSymbol {
  36708 			v2 = bw1
  36709 			v3 = uint32(1)
  36710 			v4 = int32(1)
  36711 			if libc.Uint64FromInt64(4) == libc.Uint64FromInt32(4) {
  36712 				if v4 > libc.Int32FromInt32(0) {
  36713 					if (*VP8LBitWriter)(unsafe.Pointer(v2)).Fused >= libc.Int32FromInt32(32) {
  36714 						VP8LPutBitsFlushBits(tls, v2)
  36715 					}
  36716 					**(**vp8l_atype_t)(__ccgo_up(v2)) |= uint64(v3) << (*VP8LBitWriter)(unsafe.Pointer(v2)).Fused
  36717 					**(**int32)(__ccgo_up(v2 + 8)) += v4
  36718 				}
  36719 			} else {
  36720 				VP8LPutBitsInternal(tls, v2, v3, v4)
  36721 			} // Small tree marker to encode 1 or 2 symbols.
  36722 			v2 = bw1
  36723 			v3 = uint32(count - int32(1))
  36724 			v4 = int32(1)
  36725 			if libc.Uint64FromInt64(4) == libc.Uint64FromInt32(4) {
  36726 				if v4 > libc.Int32FromInt32(0) {
  36727 					if (*VP8LBitWriter)(unsafe.Pointer(v2)).Fused >= libc.Int32FromInt32(32) {
  36728 						VP8LPutBitsFlushBits(tls, v2)
  36729 					}
  36730 					**(**vp8l_atype_t)(__ccgo_up(v2)) |= uint64(v3) << (*VP8LBitWriter)(unsafe.Pointer(v2)).Fused
  36731 					**(**int32)(__ccgo_up(v2 + 8)) += v4
  36732 				}
  36733 			} else {
  36734 				VP8LPutBitsInternal(tls, v2, v3, v4)
  36735 			}
  36736 			if symbols[0] <= int32(1) {
  36737 				v2 = bw1
  36738 				v3 = uint32(0)
  36739 				v4 = int32(1)
  36740 				if libc.Uint64FromInt64(4) == libc.Uint64FromInt32(4) {
  36741 					if v4 > libc.Int32FromInt32(0) {
  36742 						if (*VP8LBitWriter)(unsafe.Pointer(v2)).Fused >= libc.Int32FromInt32(32) {
  36743 							VP8LPutBitsFlushBits(tls, v2)
  36744 						}
  36745 						**(**vp8l_atype_t)(__ccgo_up(v2)) |= uint64(v3) << (*VP8LBitWriter)(unsafe.Pointer(v2)).Fused
  36746 						**(**int32)(__ccgo_up(v2 + 8)) += v4
  36747 					}
  36748 				} else {
  36749 					VP8LPutBitsInternal(tls, v2, v3, v4)
  36750 				} // Code bit for small (1 bit) symbol value.
  36751 				v2 = bw1
  36752 				v3 = uint32(symbols[0])
  36753 				v4 = int32(1)
  36754 				if libc.Uint64FromInt64(4) == libc.Uint64FromInt32(4) {
  36755 					if v4 > libc.Int32FromInt32(0) {
  36756 						if (*VP8LBitWriter)(unsafe.Pointer(v2)).Fused >= libc.Int32FromInt32(32) {
  36757 							VP8LPutBitsFlushBits(tls, v2)
  36758 						}
  36759 						**(**vp8l_atype_t)(__ccgo_up(v2)) |= uint64(v3) << (*VP8LBitWriter)(unsafe.Pointer(v2)).Fused
  36760 						**(**int32)(__ccgo_up(v2 + 8)) += v4
  36761 					}
  36762 				} else {
  36763 					VP8LPutBitsInternal(tls, v2, v3, v4)
  36764 				}
  36765 			} else {
  36766 				v2 = bw1
  36767 				v3 = uint32(1)
  36768 				v4 = int32(1)
  36769 				if libc.Uint64FromInt64(4) == libc.Uint64FromInt32(4) {
  36770 					if v4 > libc.Int32FromInt32(0) {
  36771 						if (*VP8LBitWriter)(unsafe.Pointer(v2)).Fused >= libc.Int32FromInt32(32) {
  36772 							VP8LPutBitsFlushBits(tls, v2)
  36773 						}
  36774 						**(**vp8l_atype_t)(__ccgo_up(v2)) |= uint64(v3) << (*VP8LBitWriter)(unsafe.Pointer(v2)).Fused
  36775 						**(**int32)(__ccgo_up(v2 + 8)) += v4
  36776 					}
  36777 				} else {
  36778 					VP8LPutBitsInternal(tls, v2, v3, v4)
  36779 				}
  36780 				v2 = bw1
  36781 				v3 = uint32(symbols[0])
  36782 				v4 = int32(8)
  36783 				if libc.Uint64FromInt64(4) == libc.Uint64FromInt32(4) {
  36784 					if v4 > libc.Int32FromInt32(0) {
  36785 						if (*VP8LBitWriter)(unsafe.Pointer(v2)).Fused >= libc.Int32FromInt32(32) {
  36786 							VP8LPutBitsFlushBits(tls, v2)
  36787 						}
  36788 						**(**vp8l_atype_t)(__ccgo_up(v2)) |= uint64(v3) << (*VP8LBitWriter)(unsafe.Pointer(v2)).Fused
  36789 						**(**int32)(__ccgo_up(v2 + 8)) += v4
  36790 					}
  36791 				} else {
  36792 					VP8LPutBitsInternal(tls, v2, v3, v4)
  36793 				}
  36794 			}
  36795 			if count == int32(2) {
  36796 				v2 = bw1
  36797 				v3 = uint32(symbols[int32(1)])
  36798 				v4 = int32(8)
  36799 				if libc.Uint64FromInt64(4) == libc.Uint64FromInt32(4) {
  36800 					if v4 > libc.Int32FromInt32(0) {
  36801 						if (*VP8LBitWriter)(unsafe.Pointer(v2)).Fused >= libc.Int32FromInt32(32) {
  36802 							VP8LPutBitsFlushBits(tls, v2)
  36803 						}
  36804 						**(**vp8l_atype_t)(__ccgo_up(v2)) |= uint64(v3) << (*VP8LBitWriter)(unsafe.Pointer(v2)).Fused
  36805 						**(**int32)(__ccgo_up(v2 + 8)) += v4
  36806 					}
  36807 				} else {
  36808 					VP8LPutBitsInternal(tls, v2, v3, v4)
  36809 				}
  36810 			}
  36811 		} else {
  36812 			StoreFullHuffmanCode(tls, bw1, huff_tree, tokens, huffman_code)
  36813 		}
  36814 	}
  36815 }
  36816 
  36817 func WriteHuffmanCode(tls *libc.TLS, bw1 uintptr, code uintptr, code_index int32) {
  36818 	var depth, symbol, v3 int32
  36819 	var v1 uintptr
  36820 	var v2 uint32_t
  36821 	_, _, _, _, _ = depth, symbol, v1, v2, v3
  36822 	depth = int32(**(**uint8_t)(__ccgo_up((*HuffmanTreeCode)(unsafe.Pointer(code)).Fcode_lengths + uintptr(code_index))))
  36823 	symbol = int32(**(**uint16_t)(__ccgo_up((*HuffmanTreeCode)(unsafe.Pointer(code)).Fcodes + uintptr(code_index)*2)))
  36824 	v1 = bw1
  36825 	v2 = uint32(symbol)
  36826 	v3 = depth
  36827 	if libc.Uint64FromInt64(4) == libc.Uint64FromInt32(4) {
  36828 		if v3 > libc.Int32FromInt32(0) {
  36829 			if (*VP8LBitWriter)(unsafe.Pointer(v1)).Fused >= libc.Int32FromInt32(32) {
  36830 				VP8LPutBitsFlushBits(tls, v1)
  36831 			}
  36832 			**(**vp8l_atype_t)(__ccgo_up(v1)) |= uint64(v2) << (*VP8LBitWriter)(unsafe.Pointer(v1)).Fused
  36833 			**(**int32)(__ccgo_up(v1 + 8)) += v3
  36834 		}
  36835 	} else {
  36836 		VP8LPutBitsInternal(tls, v1, v2, v3)
  36837 	}
  36838 }
  36839 
  36840 func WriteHuffmanCodeWithExtraBits(tls *libc.TLS, bw1 uintptr, code uintptr, code_index int32, bits1 int32, n_bits1 int32) {
  36841 	var depth, symbol, v3 int32
  36842 	var v1 uintptr
  36843 	var v2 uint32_t
  36844 	_, _, _, _, _ = depth, symbol, v1, v2, v3
  36845 	depth = int32(**(**uint8_t)(__ccgo_up((*HuffmanTreeCode)(unsafe.Pointer(code)).Fcode_lengths + uintptr(code_index))))
  36846 	symbol = int32(**(**uint16_t)(__ccgo_up((*HuffmanTreeCode)(unsafe.Pointer(code)).Fcodes + uintptr(code_index)*2)))
  36847 	v1 = bw1
  36848 	v2 = uint32(bits1<<depth | symbol)
  36849 	v3 = depth + n_bits1
  36850 	if libc.Uint64FromInt64(4) == libc.Uint64FromInt32(4) {
  36851 		if v3 > libc.Int32FromInt32(0) {
  36852 			if (*VP8LBitWriter)(unsafe.Pointer(v1)).Fused >= libc.Int32FromInt32(32) {
  36853 				VP8LPutBitsFlushBits(tls, v1)
  36854 			}
  36855 			**(**vp8l_atype_t)(__ccgo_up(v1)) |= uint64(v2) << (*VP8LBitWriter)(unsafe.Pointer(v1)).Fused
  36856 			**(**int32)(__ccgo_up(v1 + 8)) += v3
  36857 		}
  36858 	} else {
  36859 		VP8LPutBitsInternal(tls, v1, v2, v3)
  36860 	}
  36861 }
  36862 
  36863 func StoreImageToBitMask(tls *libc.TLS, bw1 uintptr, width int32, histo_bits int32, refs uintptr, histogram_symbols uintptr, huffman_codes uintptr, pic uintptr) (r int32) {
  36864 	bp := tls.Alloc(48)
  36865 	defer tls.Free(48)
  36866 	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
  36867 	var codes, v, v20, v21, v22, v24 uintptr
  36868 	var prefix_code VP8LPrefixCode
  36869 	var v1 uint32
  36870 	var v2, v3 uint32_t
  36871 	var _ /* bits at bp+24 */ int32
  36872 	var _ /* c at bp+0 */ VP8LRefsCursor
  36873 	var _ /* code at bp+32 */ int32
  36874 	var _ /* n_bits at bp+28 */ int32
  36875 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  36876 	if histo_bits != 0 {
  36877 		v2 = uint32(histo_bits)
  36878 		v3 = (uint32(width) + uint32(libc.Int32FromInt32(1)<<v2) - uint32(1)) >> v2
  36879 		goto _4
  36880 	_4:
  36881 		v1 = v3
  36882 	} else {
  36883 		v1 = uint32(1)
  36884 	}
  36885 	histo_xsize = int32(v1)
  36886 	if histo_bits == 0 {
  36887 		v5 = 0
  36888 	} else {
  36889 		v5 = -(int32(1) << histo_bits)
  36890 	}
  36891 	tile_mask = v5
  36892 	// x and y trace the position in the image.
  36893 	x = 0
  36894 	y = 0
  36895 	tile_x = x & tile_mask
  36896 	tile_y = y & tile_mask
  36897 	histogram_ix = int32(**(**uint32_t)(__ccgo_up(histogram_symbols)) >> libc.Int32FromInt32(8) & uint32(0xffff))
  36898 	codes = huffman_codes + uintptr(int32(5)*histogram_ix)*24
  36899 	**(**VP8LRefsCursor)(__ccgo_up(bp)) = VP8LRefsCursorInit(tls, refs)
  36900 	for {
  36901 		v6 = libc.BoolInt32((*VP8LRefsCursor)(unsafe.Pointer(bp)).Fcur_pos != libc.UintptrFromInt32(0))
  36902 		goto _7
  36903 	_7:
  36904 		if !(v6 != 0) {
  36905 			break
  36906 		}
  36907 		v = (**(**VP8LRefsCursor)(__ccgo_up(bp))).Fcur_pos
  36908 		if tile_x != x&tile_mask || tile_y != y&tile_mask {
  36909 			tile_x = x & tile_mask
  36910 			tile_y = y & tile_mask
  36911 			histogram_ix = int32(**(**uint32_t)(__ccgo_up(histogram_symbols + uintptr(y>>histo_bits*histo_xsize+x>>histo_bits)*4)) >> libc.Int32FromInt32(8) & uint32(0xffff))
  36912 			codes = huffman_codes + uintptr(int32(5)*histogram_ix)*24
  36913 		}
  36914 		v5 = libc.BoolInt32(int32((*PixOrCopy)(unsafe.Pointer(v)).Fmode) == int32(kLiteral))
  36915 		goto _9
  36916 	_9:
  36917 		if v5 != 0 {
  36918 			k = 0
  36919 			for {
  36920 				if !(k < int32(4)) {
  36921 					break
  36922 				}
  36923 				v2 = (*PixOrCopy)(unsafe.Pointer(v)).Fargb_or_distance >> (int32(order[k]) * libc.Int32FromInt32(8)) & uint32(0xff)
  36924 				goto _12
  36925 			_12:
  36926 				code2 = int32(v2)
  36927 				WriteHuffmanCode(tls, bw1, codes+uintptr(k)*24, code2)
  36928 				goto _10
  36929 			_10:
  36930 				;
  36931 				k = k + 1
  36932 			}
  36933 		} else {
  36934 			v5 = libc.BoolInt32(int32((*PixOrCopy)(unsafe.Pointer(v)).Fmode) == int32(kCacheIdx))
  36935 			goto _14
  36936 		_14:
  36937 			if v5 != 0 {
  36938 				v2 = (*PixOrCopy)(unsafe.Pointer(v)).Fargb_or_distance
  36939 				goto _16
  36940 			_16:
  36941 				code3 = int32(v2)
  36942 				literal_ix = libc.Int32FromInt32(256) + libc.Int32FromInt32(NUM_LENGTH_CODES) + code3
  36943 				WriteHuffmanCode(tls, bw1, codes, literal_ix)
  36944 			} else {
  36945 				v2 = (*PixOrCopy)(unsafe.Pointer(v)).Fargb_or_distance
  36946 				goto _18
  36947 			_18:
  36948 				distance2 = int32(v2)
  36949 				v5 = int32((*PixOrCopy)(unsafe.Pointer(v)).Flen1)
  36950 				v20 = bp + 32
  36951 				v21 = bp + 28
  36952 				v22 = bp + 24
  36953 				if v5 < libc.Int32FromInt32(PREFIX_LOOKUP_IDX_MAX) {
  36954 					prefix_code = kPrefixEncodeCode[v5]
  36955 					**(**int32)(__ccgo_up(v20)) = int32(prefix_code.Fcode)
  36956 					**(**int32)(__ccgo_up(v21)) = int32(prefix_code.Fextra_bits)
  36957 					**(**int32)(__ccgo_up(v22)) = int32(kPrefixEncodeExtraBitsValue[v5])
  36958 				} else {
  36959 					v6 = v5
  36960 					v24 = v21
  36961 					v6 = v6 - 1
  36962 					v8 = v6
  36963 					v13 = int32(31) ^ libc.X__builtin_clz(tls, uint32(v8))
  36964 					goto _27
  36965 				_27:
  36966 					highest_bit = v13
  36967 					second_highest_bit = v6 >> (highest_bit - int32(1)) & int32(1)
  36968 					**(**int32)(__ccgo_up(v24)) = highest_bit - int32(1)
  36969 					**(**int32)(__ccgo_up(v22)) = v6 & (int32(1)<<**(**int32)(__ccgo_up(v24)) - int32(1))
  36970 					**(**int32)(__ccgo_up(v20)) = int32(2)*highest_bit + second_highest_bit
  36971 				}
  36972 				WriteHuffmanCodeWithExtraBits(tls, bw1, codes, int32(256)+**(**int32)(__ccgo_up(bp + 32)), **(**int32)(__ccgo_up(bp + 24)), **(**int32)(__ccgo_up(bp + 28)))
  36973 				// Don't write the distance with the extra bits code since
  36974 				// the distance can be up to 18 bits of extra bits, and the prefix
  36975 				// 15 bits, totaling to 33, and our PutBits only supports up to 32 bits.
  36976 				v5 = distance2
  36977 				v20 = bp + 32
  36978 				v21 = bp + 28
  36979 				v22 = bp + 24
  36980 				if v5 < libc.Int32FromInt32(PREFIX_LOOKUP_IDX_MAX) {
  36981 					prefix_code = kPrefixEncodeCode[v5]
  36982 					**(**int32)(__ccgo_up(v20)) = int32(prefix_code.Fcode)
  36983 					**(**int32)(__ccgo_up(v21)) = int32(prefix_code.Fextra_bits)
  36984 					**(**int32)(__ccgo_up(v22)) = int32(kPrefixEncodeExtraBitsValue[v5])
  36985 				} else {
  36986 					v6 = v5
  36987 					v24 = v21
  36988 					v6 = v6 - 1
  36989 					v8 = v6
  36990 					v13 = int32(31) ^ libc.X__builtin_clz(tls, uint32(v8))
  36991 					goto _36
  36992 				_36:
  36993 					highest_bit = v13
  36994 					second_highest_bit = v6 >> (highest_bit - int32(1)) & int32(1)
  36995 					**(**int32)(__ccgo_up(v24)) = highest_bit - int32(1)
  36996 					**(**int32)(__ccgo_up(v22)) = v6 & (int32(1)<<**(**int32)(__ccgo_up(v24)) - int32(1))
  36997 					**(**int32)(__ccgo_up(v20)) = int32(2)*highest_bit + second_highest_bit
  36998 				}
  36999 				WriteHuffmanCode(tls, bw1, codes+uintptr(4)*24, **(**int32)(__ccgo_up(bp + 32)))
  37000 				v20 = bw1
  37001 				v2 = uint32(**(**int32)(__ccgo_up(bp + 24)))
  37002 				v5 = **(**int32)(__ccgo_up(bp + 28))
  37003 				if libc.Uint64FromInt64(4) == libc.Uint64FromInt32(4) {
  37004 					if v5 > libc.Int32FromInt32(0) {
  37005 						if (*VP8LBitWriter)(unsafe.Pointer(v20)).Fused >= libc.Int32FromInt32(32) {
  37006 							VP8LPutBitsFlushBits(tls, v20)
  37007 						}
  37008 						**(**vp8l_atype_t)(__ccgo_up(v20)) |= uint64(v2) << (*VP8LBitWriter)(unsafe.Pointer(v20)).Fused
  37009 						**(**int32)(__ccgo_up(v20 + 8)) += v5
  37010 					}
  37011 				} else {
  37012 					VP8LPutBitsInternal(tls, v20, v2, v5)
  37013 				}
  37014 			}
  37015 		}
  37016 		v2 = uint32((*PixOrCopy)(unsafe.Pointer(v)).Flen1)
  37017 		goto _41
  37018 	_41:
  37019 		x = int32(uint32(x) + v2)
  37020 		for x >= width {
  37021 			x = x - width
  37022 			y = y + 1
  37023 		}
  37024 		v20 = bp
  37025 		v22 = v20
  37026 		*(*uintptr)(unsafe.Pointer(v22)) += 8
  37027 		v21 = *(*uintptr)(unsafe.Pointer(v22))
  37028 		if v21 == (*VP8LRefsCursor)(unsafe.Pointer(v20)).Flast_pos {
  37029 			VP8LRefsCursorNextBlock(tls, v20)
  37030 		}
  37031 	}
  37032 	if (*VP8LBitWriter)(unsafe.Pointer(bw1)).Ferror1 != 0 {
  37033 		return WebPEncodingSetError(tls, pic, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  37034 	}
  37035 	return int32(1)
  37036 }
  37037 
  37038 var order = [4]uint8_t{
  37039 	0: uint8(1),
  37040 	1: uint8(2),
  37041 	3: uint8(3),
  37042 }
  37043 
  37044 // C documentation
  37045 //
  37046 //	// Special case of EncodeImageInternal() for cache-bits=0, histo_bits=31.
  37047 //	// pic and percent are for progress.
  37048 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) {
  37049 	bp := tls.Alloc(128)
  37050 	defer tls.Free(128)
  37051 	var codes, codes1, histogram_image, huff_tree, refs, tokens, v1 uintptr
  37052 	var i, max_tokens, v3 int32
  37053 	var v2 uint32_t
  37054 	var _ /* cache_bits at bp+124 */ int32
  37055 	var _ /* histogram_symbols at bp+120 */ [1]uint32_t
  37056 	var _ /* huffman_codes at bp+0 */ [5]HuffmanTreeCode
  37057 	_, _, _, _, _, _, _, _, _, _, _ = codes, codes1, histogram_image, huff_tree, i, max_tokens, refs, tokens, v1, v2, v3
  37058 	max_tokens = 0
  37059 	tokens = libc.UintptrFromInt32(0)
  37060 	**(**[5]HuffmanTreeCode)(__ccgo_up(bp)) = [5]HuffmanTreeCode{}
  37061 	**(**[1]uint32_t)(__ccgo_up(bp + 120)) = [1]uint32_t{} // only one tree, one symbol
  37062 	**(**int32)(__ccgo_up(bp + 124)) = 0
  37063 	histogram_image = libc.UintptrFromInt32(0)
  37064 	huff_tree = WebPSafeMalloc(tls, libc.Uint64FromUint64(3)*libc.Uint64FromInt32(CODE_LENGTH_CODES), uint64(16))
  37065 	if huff_tree == libc.UintptrFromInt32(0) {
  37066 		WebPEncodingSetError(tls, pic, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  37067 		goto Error
  37068 	}
  37069 	// Calculate backward references from ARGB image.
  37070 	if !(VP8LHashChainFill(tls, hash_chain, quality, argb, width, height, low_effort, pic, percent_range/int32(2), percent) != 0) {
  37071 		goto Error
  37072 	}
  37073 	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) {
  37074 		goto Error
  37075 	}
  37076 	refs = refs_array
  37077 	histogram_image = VP8LAllocateHistogramSet(tls, int32(1), **(**int32)(__ccgo_up(bp + 124)))
  37078 	if histogram_image == libc.UintptrFromInt32(0) {
  37079 		WebPEncodingSetError(tls, pic, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  37080 		goto Error
  37081 	}
  37082 	VP8LHistogramSetClear(tls, histogram_image)
  37083 	// Build histogram image and symbols from backward references.
  37084 	VP8LHistogramStoreRefs(tls, refs, libc.UintptrFromInt32(0), 0, **(**uintptr)(__ccgo_up((*VP8LHistogramSet)(unsafe.Pointer(histogram_image)).Fhistograms)))
  37085 	// Create Huffman bit lengths and codes for each histogram image.
  37086 	if !(GetHuffBitLengthsAndCodes(tls, histogram_image, bp) != 0) {
  37087 		WebPEncodingSetError(tls, pic, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  37088 		goto Error
  37089 	}
  37090 	// No color cache, no Huffman image.
  37091 	v1 = bw1
  37092 	v2 = uint32(0)
  37093 	v3 = int32(1)
  37094 	if libc.Uint64FromInt64(4) == libc.Uint64FromInt32(4) {
  37095 		if v3 > libc.Int32FromInt32(0) {
  37096 			if (*VP8LBitWriter)(unsafe.Pointer(v1)).Fused >= libc.Int32FromInt32(32) {
  37097 				VP8LPutBitsFlushBits(tls, v1)
  37098 			}
  37099 			**(**vp8l_atype_t)(__ccgo_up(v1)) |= uint64(v2) << (*VP8LBitWriter)(unsafe.Pointer(v1)).Fused
  37100 			**(**int32)(__ccgo_up(v1 + 8)) += v3
  37101 		}
  37102 	} else {
  37103 		VP8LPutBitsInternal(tls, v1, v2, v3)
  37104 	}
  37105 	// Find maximum number of symbols for the huffman tree-set.
  37106 	i = 0
  37107 	for {
  37108 		if !(i < int32(5)) {
  37109 			break
  37110 		}
  37111 		codes = bp + uintptr(i)*24
  37112 		if max_tokens < (*HuffmanTreeCode)(unsafe.Pointer(codes)).Fnum_symbols {
  37113 			max_tokens = (*HuffmanTreeCode)(unsafe.Pointer(codes)).Fnum_symbols
  37114 		}
  37115 		goto _4
  37116 	_4:
  37117 		;
  37118 		i = i + 1
  37119 	}
  37120 	tokens = WebPSafeMalloc(tls, uint64(max_tokens), uint64(2))
  37121 	if tokens == libc.UintptrFromInt32(0) {
  37122 		WebPEncodingSetError(tls, pic, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  37123 		goto Error
  37124 	}
  37125 	// Store Huffman codes.
  37126 	i = 0
  37127 	for {
  37128 		if !(i < int32(5)) {
  37129 			break
  37130 		}
  37131 		codes1 = bp + uintptr(i)*24
  37132 		StoreHuffmanCode(tls, bw1, huff_tree, tokens, codes1)
  37133 		ClearHuffmanTreeIfOnlyOneSymbol(tls, codes1)
  37134 		goto _5
  37135 	_5:
  37136 		;
  37137 		i = i + 1
  37138 	}
  37139 	// Store actual literals.
  37140 	if !(StoreImageToBitMask(tls, bw1, width, 0, refs, bp+120, bp, pic) != 0) {
  37141 		goto Error
  37142 	}
  37143 	goto Error
  37144 Error:
  37145 	;
  37146 	WebPSafeFree(tls, tokens)
  37147 	WebPSafeFree(tls, huff_tree)
  37148 	VP8LFreeHistogramSet(tls, histogram_image)
  37149 	WebPSafeFree(tls, (**(**[5]HuffmanTreeCode)(__ccgo_up(bp)))[0].Fcodes)
  37150 	return libc.BoolInt32((*WebPPicture)(unsafe.Pointer(pic)).Ferror_code == int32(VP8_ENC_OK))
  37151 }
  37152 
  37153 // C documentation
  37154 //
  37155 //	// pic and percent are for progress.
  37156 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) {
  37157 	bp := tls.Alloc(128)
  37158 	defer tls.Free(128)
  37159 	var bit_array_size, bw_size_best, v37, v40 size_t
  37160 	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
  37161 	var codes, codes1, histogram_argb, histogram_image, huff_tree, huffman_codes, sub_config, tmp_histo, tokens, v12, v15 uintptr
  37162 	var histogram_image_size, histogram_image_xysize, i, v1, v2, v4, v5 uint32_t
  37163 	var _ /* bw_best at bp+48 */ VP8LBitWriter
  37164 	var _ /* bw_init at bp+0 */ VP8LBitWriter
  37165 	var _ /* cache_bits_best at bp+112 */ int32
  37166 	var _ /* hash_chain_histogram at bp+96 */ VP8LHashChain
  37167 	var _ /* histogram_bits at bp+116 */ int32
  37168 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  37169 	v1 = uint32(histogram_bits_in)
  37170 	v2 = (uint32(width) + uint32(libc.Int32FromInt32(1)<<v1) - uint32(1)) >> v1
  37171 	goto _3
  37172 _3:
  37173 	v4 = uint32(histogram_bits_in)
  37174 	v5 = (uint32(height) + uint32(libc.Int32FromInt32(1)<<v4) - uint32(1)) >> v4
  37175 	goto _6
  37176 _6:
  37177 	histogram_image_xysize = v2 * v5
  37178 	remaining_percent = percent_range
  37179 	percent_start = **(**int32)(__ccgo_up(percent))
  37180 	histogram_image = libc.UintptrFromInt32(0)
  37181 	tmp_histo = libc.UintptrFromInt32(0)
  37182 	histogram_image_size = uint32(0)
  37183 	bit_array_size = uint64(0)
  37184 	huff_tree = WebPSafeMalloc(tls, libc.Uint64FromUint64(3)*libc.Uint64FromInt32(CODE_LENGTH_CODES), uint64(16))
  37185 	tokens = libc.UintptrFromInt32(0)
  37186 	huffman_codes = libc.UintptrFromInt32(0)
  37187 	histogram_argb = WebPSafeMalloc(tls, uint64(histogram_image_xysize), uint64(4))
  37188 	**(**VP8LBitWriter)(__ccgo_up(bp)) = **(**VP8LBitWriter)(__ccgo_up(bw2)) // histogram image hash chain
  37189 	bw_size_best = ^libc.Uint64FromInt32(0)
  37190 	libc.Xmemset(tls, bp+96, 0, uint64(16))
  37191 	if !(VP8LBitWriterInit(tls, bp+48, uint64(0)) != 0) {
  37192 		WebPEncodingSetError(tls, pic, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  37193 		goto Error
  37194 	}
  37195 	// Make sure we can allocate the different objects.
  37196 	if huff_tree == libc.UintptrFromInt32(0) || histogram_argb == libc.UintptrFromInt32(0) || !(VP8LHashChainInit(tls, bp+96, int32(histogram_image_xysize)) != 0) {
  37197 		WebPEncodingSetError(tls, pic, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  37198 		goto Error
  37199 	}
  37200 	percent_range = remaining_percent / int32(5)
  37201 	if !(VP8LHashChainFill(tls, hash_chain, quality, argb, width, height, low_effort, pic, percent_range, percent) != 0) {
  37202 		goto Error
  37203 	}
  37204 	percent_start = percent_start + percent_range
  37205 	remaining_percent = remaining_percent - percent_range
  37206 	// If the value is different from zero, it has been set during the palette
  37207 	// analysis.
  37208 	if **(**int32)(__ccgo_up(cache_bits)) == 0 {
  37209 		v7 = int32(MAX_COLOR_CACHE_BITS)
  37210 	} else {
  37211 		v7 = **(**int32)(__ccgo_up(cache_bits))
  37212 	}
  37213 	cache_bits_init = v7
  37214 	// If several iterations will happen, clone into bw_best.
  37215 	if ((*CrunchConfig)(unsafe.Pointer(config)).Fsub_configs_size > int32(1) || (**(**CrunchSubConfig)(__ccgo_up(config + 8))).Fdo_no_cache != 0) && !(VP8LBitWriterClone(tls, bw2, bp+48) != 0) {
  37216 		WebPEncodingSetError(tls, pic, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  37217 		goto Error
  37218 	}
  37219 	sub_configs_idx = 0
  37220 	for {
  37221 		if !(sub_configs_idx < (*CrunchConfig)(unsafe.Pointer(config)).Fsub_configs_size) {
  37222 			break
  37223 		}
  37224 		sub_config = config + 8 + uintptr(sub_configs_idx)*8
  37225 		i_remaining_percent = remaining_percent / (*CrunchConfig)(unsafe.Pointer(config)).Fsub_configs_size
  37226 		i_percent_range = i_remaining_percent / int32(4)
  37227 		i_remaining_percent = i_remaining_percent - i_percent_range
  37228 		if !(VP8LGetBackwardReferences(tls, width, height, argb, quality, low_effort, (*CrunchSubConfig)(unsafe.Pointer(sub_config)).Flz77, cache_bits_init, (*CrunchSubConfig)(unsafe.Pointer(sub_config)).Fdo_no_cache, hash_chain, refs_array, bp+112, pic, i_percent_range, percent) != 0) {
  37229 			goto Error
  37230 		}
  37231 		i_cache = 0
  37232 		for {
  37233 			if (*CrunchSubConfig)(unsafe.Pointer(sub_config)).Fdo_no_cache != 0 {
  37234 				v7 = int32(2)
  37235 			} else {
  37236 				v7 = int32(1)
  37237 			}
  37238 			if !(i_cache < v7) {
  37239 				break
  37240 			}
  37241 			if i_cache == 0 {
  37242 				v10 = **(**int32)(__ccgo_up(bp + 112))
  37243 			} else {
  37244 				v10 = 0
  37245 			}
  37246 			cache_bits_tmp = v10
  37247 			**(**int32)(__ccgo_up(bp + 116)) = histogram_bits_in
  37248 			// Speed-up: no need to study the no-cache case if it was already studied
  37249 			// in i_cache == 0.
  37250 			if i_cache == int32(1) && **(**int32)(__ccgo_up(bp + 112)) == 0 {
  37251 				break
  37252 			}
  37253 			// Reset the bit writer for this iteration.
  37254 			VP8LBitWriterReset(tls, bp, bw2)
  37255 			// Build histogram image and symbols from backward references.
  37256 			histogram_image = VP8LAllocateHistogramSet(tls, int32(histogram_image_xysize), cache_bits_tmp)
  37257 			tmp_histo = VP8LAllocateHistogram(tls, cache_bits_tmp)
  37258 			if histogram_image == libc.UintptrFromInt32(0) || tmp_histo == libc.UintptrFromInt32(0) {
  37259 				WebPEncodingSetError(tls, pic, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  37260 				goto Error
  37261 			}
  37262 			i_percent_range = i_remaining_percent / int32(3)
  37263 			i_remaining_percent = i_remaining_percent - i_percent_range
  37264 			if !(VP8LGetHistoImageSymbols(tls, width, height, refs_array+uintptr(i_cache)*40, quality, low_effort, **(**int32)(__ccgo_up(bp + 116)), cache_bits_tmp, histogram_image, tmp_histo, histogram_argb, pic, i_percent_range, percent) != 0) {
  37265 				goto Error
  37266 			}
  37267 			// Create Huffman bit lengths and codes for each histogram image.
  37268 			histogram_image_size = uint32((*VP8LHistogramSet)(unsafe.Pointer(histogram_image)).Fsize)
  37269 			bit_array_size = uint64(uint32(5) * histogram_image_size)
  37270 			huffman_codes = WebPSafeCalloc(tls, bit_array_size, uint64(24))
  37271 			// Note: some histogram_image entries may point to tmp_histos[], so the
  37272 			// latter need to outlive the following call to
  37273 			// GetHuffBitLengthsAndCodes().
  37274 			if huffman_codes == libc.UintptrFromInt32(0) || !(GetHuffBitLengthsAndCodes(tls, histogram_image, huffman_codes) != 0) {
  37275 				WebPEncodingSetError(tls, pic, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  37276 				goto Error
  37277 			}
  37278 			// Free combined histograms.
  37279 			VP8LFreeHistogramSet(tls, histogram_image)
  37280 			histogram_image = libc.UintptrFromInt32(0)
  37281 			// Free scratch histograms.
  37282 			VP8LFreeHistogram(tls, tmp_histo)
  37283 			tmp_histo = libc.UintptrFromInt32(0)
  37284 			// Color Cache parameters.
  37285 			if cache_bits_tmp > 0 {
  37286 				v12 = bw2
  37287 				v1 = uint32(1)
  37288 				v7 = int32(1)
  37289 				if libc.Uint64FromInt64(4) == libc.Uint64FromInt32(4) {
  37290 					if v7 > libc.Int32FromInt32(0) {
  37291 						if (*VP8LBitWriter)(unsafe.Pointer(v12)).Fused >= libc.Int32FromInt32(32) {
  37292 							VP8LPutBitsFlushBits(tls, v12)
  37293 						}
  37294 						**(**vp8l_atype_t)(__ccgo_up(v12)) |= uint64(v1) << (*VP8LBitWriter)(unsafe.Pointer(v12)).Fused
  37295 						**(**int32)(__ccgo_up(v12 + 8)) += v7
  37296 					}
  37297 				} else {
  37298 					VP8LPutBitsInternal(tls, v12, v1, v7)
  37299 				}
  37300 				v12 = bw2
  37301 				v1 = uint32(cache_bits_tmp)
  37302 				v7 = int32(4)
  37303 				if libc.Uint64FromInt64(4) == libc.Uint64FromInt32(4) {
  37304 					if v7 > libc.Int32FromInt32(0) {
  37305 						if (*VP8LBitWriter)(unsafe.Pointer(v12)).Fused >= libc.Int32FromInt32(32) {
  37306 							VP8LPutBitsFlushBits(tls, v12)
  37307 						}
  37308 						**(**vp8l_atype_t)(__ccgo_up(v12)) |= uint64(v1) << (*VP8LBitWriter)(unsafe.Pointer(v12)).Fused
  37309 						**(**int32)(__ccgo_up(v12 + 8)) += v7
  37310 					}
  37311 				} else {
  37312 					VP8LPutBitsInternal(tls, v12, v1, v7)
  37313 				}
  37314 			} else {
  37315 				v12 = bw2
  37316 				v1 = uint32(0)
  37317 				v7 = int32(1)
  37318 				if libc.Uint64FromInt64(4) == libc.Uint64FromInt32(4) {
  37319 					if v7 > libc.Int32FromInt32(0) {
  37320 						if (*VP8LBitWriter)(unsafe.Pointer(v12)).Fused >= libc.Int32FromInt32(32) {
  37321 							VP8LPutBitsFlushBits(tls, v12)
  37322 						}
  37323 						**(**vp8l_atype_t)(__ccgo_up(v12)) |= uint64(v1) << (*VP8LBitWriter)(unsafe.Pointer(v12)).Fused
  37324 						**(**int32)(__ccgo_up(v12 + 8)) += v7
  37325 					}
  37326 				} else {
  37327 					VP8LPutBitsInternal(tls, v12, v1, v7)
  37328 				}
  37329 			}
  37330 			// Huffman image + meta huffman.
  37331 			histogram_image_size = uint32(0)
  37332 			i = uint32(0)
  37333 			for {
  37334 				if !(i < histogram_image_xysize) {
  37335 					break
  37336 				}
  37337 				if **(**uint32_t)(__ccgo_up(histogram_argb + uintptr(i)*4)) >= histogram_image_size {
  37338 					histogram_image_size = **(**uint32_t)(__ccgo_up(histogram_argb + uintptr(i)*4)) + uint32(1)
  37339 				}
  37340 				**(**uint32_t)(__ccgo_up(histogram_argb + uintptr(i)*4)) <<= uint32(8)
  37341 				goto _21
  37342 			_21:
  37343 				;
  37344 				i = i + 1
  37345 			}
  37346 			write_histogram_image = libc.BoolInt32(histogram_image_size > uint32(1))
  37347 			v12 = bw2
  37348 			v1 = uint32(write_histogram_image)
  37349 			v7 = int32(1)
  37350 			if libc.Uint64FromInt64(4) == libc.Uint64FromInt32(4) {
  37351 				if v7 > libc.Int32FromInt32(0) {
  37352 					if (*VP8LBitWriter)(unsafe.Pointer(v12)).Fused >= libc.Int32FromInt32(32) {
  37353 						VP8LPutBitsFlushBits(tls, v12)
  37354 					}
  37355 					**(**vp8l_atype_t)(__ccgo_up(v12)) |= uint64(v1) << (*VP8LBitWriter)(unsafe.Pointer(v12)).Fused
  37356 					**(**int32)(__ccgo_up(v12 + 8)) += v7
  37357 				}
  37358 			} else {
  37359 				VP8LPutBitsInternal(tls, v12, v1, v7)
  37360 			}
  37361 			if write_histogram_image != 0 {
  37362 				VP8LOptimizeSampling(tls, histogram_argb, width, height, histogram_bits_in, libc.Int32FromInt32(MIN_HUFFMAN_BITS)+libc.Int32FromInt32(1)<<libc.Int32FromInt32(NUM_HUFFMAN_BITS)-libc.Int32FromInt32(1), bp+116)
  37363 				v12 = bw2
  37364 				v1 = uint32(**(**int32)(__ccgo_up(bp + 116)) - int32(2))
  37365 				v7 = int32(3)
  37366 				if libc.Uint64FromInt64(4) == libc.Uint64FromInt32(4) {
  37367 					if v7 > libc.Int32FromInt32(0) {
  37368 						if (*VP8LBitWriter)(unsafe.Pointer(v12)).Fused >= libc.Int32FromInt32(32) {
  37369 							VP8LPutBitsFlushBits(tls, v12)
  37370 						}
  37371 						**(**vp8l_atype_t)(__ccgo_up(v12)) |= uint64(v1) << (*VP8LBitWriter)(unsafe.Pointer(v12)).Fused
  37372 						**(**int32)(__ccgo_up(v12 + 8)) += v7
  37373 					}
  37374 				} else {
  37375 					VP8LPutBitsInternal(tls, v12, v1, v7)
  37376 				}
  37377 				i_percent_range = i_remaining_percent / int32(2)
  37378 				i_remaining_percent = i_remaining_percent - i_percent_range
  37379 				v1 = uint32(**(**int32)(__ccgo_up(bp + 116)))
  37380 				v2 = (uint32(width) + uint32(libc.Int32FromInt32(1)<<v1) - uint32(1)) >> v1
  37381 				goto _30
  37382 			_30:
  37383 				v4 = uint32(**(**int32)(__ccgo_up(bp + 116)))
  37384 				v5 = (uint32(height) + uint32(libc.Int32FromInt32(1)<<v4) - uint32(1)) >> v4
  37385 				goto _33
  37386 			_33:
  37387 				if !(EncodeImageNoHuffman(tls, bw2, histogram_argb, bp+96, refs_array+2*40, int32(v2), int32(v5), quality, low_effort, pic, i_percent_range, percent) != 0) {
  37388 					goto Error
  37389 				}
  37390 			}
  37391 			// Store Huffman codes.
  37392 			max_tokens = 0
  37393 			// Find maximum number of symbols for the huffman tree-set.
  37394 			i = uint32(0)
  37395 			for {
  37396 				if !(i < uint32(5)*histogram_image_size) {
  37397 					break
  37398 				}
  37399 				codes = huffman_codes + uintptr(i)*24
  37400 				if max_tokens < (*HuffmanTreeCode)(unsafe.Pointer(codes)).Fnum_symbols {
  37401 					max_tokens = (*HuffmanTreeCode)(unsafe.Pointer(codes)).Fnum_symbols
  37402 				}
  37403 				goto _34
  37404 			_34:
  37405 				;
  37406 				i = i + 1
  37407 			}
  37408 			tokens = WebPSafeMalloc(tls, uint64(max_tokens), uint64(2))
  37409 			if tokens == libc.UintptrFromInt32(0) {
  37410 				WebPEncodingSetError(tls, pic, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  37411 				goto Error
  37412 			}
  37413 			i = uint32(0)
  37414 			for {
  37415 				if !(i < uint32(5)*histogram_image_size) {
  37416 					break
  37417 				}
  37418 				codes1 = huffman_codes + uintptr(i)*24
  37419 				StoreHuffmanCode(tls, bw2, huff_tree, tokens, codes1)
  37420 				ClearHuffmanTreeIfOnlyOneSymbol(tls, codes1)
  37421 				goto _35
  37422 			_35:
  37423 				;
  37424 				i = i + 1
  37425 			}
  37426 			// Store actual literals.
  37427 			v12 = bw2
  37428 			v37 = uint64(int64((*VP8LBitWriter)(unsafe.Pointer(v12)).Fcur) - int64((*VP8LBitWriter)(unsafe.Pointer(v12)).Fbuf) + int64(((*VP8LBitWriter)(unsafe.Pointer(v12)).Fused+libc.Int32FromInt32(7))>>libc.Int32FromInt32(3)))
  37429 			goto _38
  37430 		_38:
  37431 			hdr_size_tmp = int32(v37 - init_byte_position)
  37432 			if !(StoreImageToBitMask(tls, bw2, width, **(**int32)(__ccgo_up(bp + 116)), refs_array+uintptr(i_cache)*40, histogram_argb, huffman_codes, pic) != 0) {
  37433 				goto Error
  37434 			}
  37435 			// Keep track of the smallest image so far.
  37436 			v12 = bw2
  37437 			v37 = uint64(int64((*VP8LBitWriter)(unsafe.Pointer(v12)).Fcur) - int64((*VP8LBitWriter)(unsafe.Pointer(v12)).Fbuf) + int64(((*VP8LBitWriter)(unsafe.Pointer(v12)).Fused+libc.Int32FromInt32(7))>>libc.Int32FromInt32(3)))
  37438 			goto _41
  37439 		_41:
  37440 			if v37 < bw_size_best {
  37441 				v15 = bw2
  37442 				v40 = uint64(int64((*VP8LBitWriter)(unsafe.Pointer(v15)).Fcur) - int64((*VP8LBitWriter)(unsafe.Pointer(v15)).Fbuf) + int64(((*VP8LBitWriter)(unsafe.Pointer(v15)).Fused+libc.Int32FromInt32(7))>>libc.Int32FromInt32(3)))
  37443 				goto _44
  37444 			_44:
  37445 				bw_size_best = v40
  37446 				**(**int32)(__ccgo_up(cache_bits)) = cache_bits_tmp
  37447 				**(**int32)(__ccgo_up(hdr_size)) = hdr_size_tmp
  37448 				v12 = bw2
  37449 				v37 = uint64(int64((*VP8LBitWriter)(unsafe.Pointer(v12)).Fcur) - int64((*VP8LBitWriter)(unsafe.Pointer(v12)).Fbuf) + int64(((*VP8LBitWriter)(unsafe.Pointer(v12)).Fused+libc.Int32FromInt32(7))>>libc.Int32FromInt32(3)))
  37450 				goto _47
  37451 			_47:
  37452 				**(**int32)(__ccgo_up(data_size)) = int32(v37 - init_byte_position - uint64(**(**int32)(__ccgo_up(hdr_size))))
  37453 				VP8LBitWriterSwap(tls, bw2, bp+48)
  37454 			}
  37455 			WebPSafeFree(tls, tokens)
  37456 			tokens = libc.UintptrFromInt32(0)
  37457 			if huffman_codes != libc.UintptrFromInt32(0) {
  37458 				WebPSafeFree(tls, (*HuffmanTreeCode)(unsafe.Pointer(huffman_codes)).Fcodes)
  37459 				WebPSafeFree(tls, huffman_codes)
  37460 				huffman_codes = libc.UintptrFromInt32(0)
  37461 			}
  37462 			goto _9
  37463 		_9:
  37464 			;
  37465 			i_cache = i_cache + 1
  37466 		}
  37467 		goto _8
  37468 	_8:
  37469 		;
  37470 		sub_configs_idx = sub_configs_idx + 1
  37471 	}
  37472 	VP8LBitWriterSwap(tls, bw2, bp+48)
  37473 	if !(WebPReportProgress(tls, pic, percent_start+remaining_percent, percent) != 0) {
  37474 		goto Error
  37475 	}
  37476 	goto Error
  37477 Error:
  37478 	;
  37479 	WebPSafeFree(tls, tokens)
  37480 	WebPSafeFree(tls, huff_tree)
  37481 	VP8LFreeHistogramSet(tls, histogram_image)
  37482 	VP8LFreeHistogram(tls, tmp_histo)
  37483 	VP8LHashChainClear(tls, bp+96)
  37484 	if huffman_codes != libc.UintptrFromInt32(0) {
  37485 		WebPSafeFree(tls, (*HuffmanTreeCode)(unsafe.Pointer(huffman_codes)).Fcodes)
  37486 		WebPSafeFree(tls, huffman_codes)
  37487 	}
  37488 	WebPSafeFree(tls, histogram_argb)
  37489 	VP8LBitWriterWipeOut(tls, bp+48)
  37490 	return libc.BoolInt32((*WebPPicture)(unsafe.Pointer(pic)).Ferror_code == int32(VP8_ENC_OK))
  37491 }
  37492 
  37493 // -----------------------------------------------------------------------------
  37494 // Transforms
  37495 
  37496 func ApplySubtractGreen(tls *libc.TLS, enc uintptr, width int32, height int32, bw1 uintptr) {
  37497 	var v1 uintptr
  37498 	var v2 uint32_t
  37499 	var v3 int32
  37500 	_, _, _ = v1, v2, v3
  37501 	v1 = bw1
  37502 	v2 = uint32(TRANSFORM_PRESENT)
  37503 	v3 = int32(1)
  37504 	if libc.Uint64FromInt64(4) == libc.Uint64FromInt32(4) {
  37505 		if v3 > libc.Int32FromInt32(0) {
  37506 			if (*VP8LBitWriter)(unsafe.Pointer(v1)).Fused >= libc.Int32FromInt32(32) {
  37507 				VP8LPutBitsFlushBits(tls, v1)
  37508 			}
  37509 			**(**vp8l_atype_t)(__ccgo_up(v1)) |= uint64(v2) << (*VP8LBitWriter)(unsafe.Pointer(v1)).Fused
  37510 			**(**int32)(__ccgo_up(v1 + 8)) += v3
  37511 		}
  37512 	} else {
  37513 		VP8LPutBitsInternal(tls, v1, v2, v3)
  37514 	}
  37515 	v1 = bw1
  37516 	v2 = uint32(SUBTRACT_GREEN_TRANSFORM)
  37517 	v3 = int32(2)
  37518 	if libc.Uint64FromInt64(4) == libc.Uint64FromInt32(4) {
  37519 		if v3 > libc.Int32FromInt32(0) {
  37520 			if (*VP8LBitWriter)(unsafe.Pointer(v1)).Fused >= libc.Int32FromInt32(32) {
  37521 				VP8LPutBitsFlushBits(tls, v1)
  37522 			}
  37523 			**(**vp8l_atype_t)(__ccgo_up(v1)) |= uint64(v2) << (*VP8LBitWriter)(unsafe.Pointer(v1)).Fused
  37524 			**(**int32)(__ccgo_up(v1 + 8)) += v3
  37525 		}
  37526 	} else {
  37527 		VP8LPutBitsInternal(tls, v1, v2, v3)
  37528 	}
  37529 	(*(*func(*libc.TLS, uintptr, int32))(unsafe.Pointer(&struct{ uintptr }{VP8LSubtractGreenFromBlueAndRed})))(tls, (*VP8LEncoder)(unsafe.Pointer(enc)).Fargb, width*height)
  37530 }
  37531 
  37532 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) {
  37533 	var max_bits, min_bits, near_lossless_strength, v1, v2 int32
  37534 	var v10, v12, v4, v7 uint32_t
  37535 	var v3 uintptr
  37536 	_, _, _, _, _, _, _, _, _, _ = max_bits, min_bits, near_lossless_strength, v1, v10, v12, v2, v3, v4, v7
  37537 	if (*VP8LEncoder)(unsafe.Pointer(enc)).Fuse_palette != 0 {
  37538 		v1 = int32(100)
  37539 	} else {
  37540 		v1 = (*WebPConfig)(unsafe.Pointer((*VP8LEncoder)(unsafe.Pointer(enc)).Fconfig)).Fnear_lossless
  37541 	}
  37542 	near_lossless_strength = v1
  37543 	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))
  37544 	if (*WebPConfig)(unsafe.Pointer((*VP8LEncoder)(unsafe.Pointer(enc)).Fconfig)).Fmethod > int32(4) {
  37545 		v2 = (*WebPConfig)(unsafe.Pointer((*VP8LEncoder)(unsafe.Pointer(enc)).Fconfig)).Fmethod - int32(4)
  37546 	} else {
  37547 		v2 = 0
  37548 	}
  37549 	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))
  37550 	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) {
  37551 		return 0
  37552 	}
  37553 	v3 = bw1
  37554 	v4 = uint32(TRANSFORM_PRESENT)
  37555 	v1 = int32(1)
  37556 	if libc.Uint64FromInt64(4) == libc.Uint64FromInt32(4) {
  37557 		if v1 > libc.Int32FromInt32(0) {
  37558 			if (*VP8LBitWriter)(unsafe.Pointer(v3)).Fused >= libc.Int32FromInt32(32) {
  37559 				VP8LPutBitsFlushBits(tls, v3)
  37560 			}
  37561 			**(**vp8l_atype_t)(__ccgo_up(v3)) |= uint64(v4) << (*VP8LBitWriter)(unsafe.Pointer(v3)).Fused
  37562 			**(**int32)(__ccgo_up(v3 + 8)) += v1
  37563 		}
  37564 	} else {
  37565 		VP8LPutBitsInternal(tls, v3, v4, v1)
  37566 	}
  37567 	v3 = bw1
  37568 	v4 = uint32(PREDICTOR_TRANSFORM)
  37569 	v1 = int32(2)
  37570 	if libc.Uint64FromInt64(4) == libc.Uint64FromInt32(4) {
  37571 		if v1 > libc.Int32FromInt32(0) {
  37572 			if (*VP8LBitWriter)(unsafe.Pointer(v3)).Fused >= libc.Int32FromInt32(32) {
  37573 				VP8LPutBitsFlushBits(tls, v3)
  37574 			}
  37575 			**(**vp8l_atype_t)(__ccgo_up(v3)) |= uint64(v4) << (*VP8LBitWriter)(unsafe.Pointer(v3)).Fused
  37576 			**(**int32)(__ccgo_up(v3 + 8)) += v1
  37577 		}
  37578 	} else {
  37579 		VP8LPutBitsInternal(tls, v3, v4, v1)
  37580 	}
  37581 	v3 = bw1
  37582 	v4 = uint32(**(**int32)(__ccgo_up(best_bits)) - int32(MIN_TRANSFORM_BITS))
  37583 	v1 = int32(NUM_TRANSFORM_BITS)
  37584 	if libc.Uint64FromInt64(4) == libc.Uint64FromInt32(4) {
  37585 		if v1 > libc.Int32FromInt32(0) {
  37586 			if (*VP8LBitWriter)(unsafe.Pointer(v3)).Fused >= libc.Int32FromInt32(32) {
  37587 				VP8LPutBitsFlushBits(tls, v3)
  37588 			}
  37589 			**(**vp8l_atype_t)(__ccgo_up(v3)) |= uint64(v4) << (*VP8LBitWriter)(unsafe.Pointer(v3)).Fused
  37590 			**(**int32)(__ccgo_up(v3 + 8)) += v1
  37591 		}
  37592 	} else {
  37593 		VP8LPutBitsInternal(tls, v3, v4, v1)
  37594 	}
  37595 	v4 = uint32(**(**int32)(__ccgo_up(best_bits)))
  37596 	v7 = (uint32(width) + uint32(libc.Int32FromInt32(1)<<v4) - uint32(1)) >> v4
  37597 	goto _14
  37598 _14:
  37599 	v10 = uint32(**(**int32)(__ccgo_up(best_bits)))
  37600 	v12 = (uint32(height) + uint32(libc.Int32FromInt32(1)<<v10) - uint32(1)) >> v10
  37601 	goto _17
  37602 _17:
  37603 	return EncodeImageNoHuffman(tls, bw1, (*VP8LEncoder)(unsafe.Pointer(enc)).Ftransform_data, enc+2312, enc+2152, int32(v7), int32(v12), quality, low_effort, (*VP8LEncoder)(unsafe.Pointer(enc)).Fpic, percent_range-percent_range/int32(2), percent)
  37604 }
  37605 
  37606 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) {
  37607 	var min_bits, v3 int32
  37608 	var v1 uintptr
  37609 	var v10, v2, v5, v8 uint32_t
  37610 	_, _, _, _, _, _, _ = min_bits, v1, v10, v2, v3, v5, v8
  37611 	min_bits = (*VP8LEncoder)(unsafe.Pointer(enc)).Fcross_color_transform_bits
  37612 	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) {
  37613 		return 0
  37614 	}
  37615 	v1 = bw1
  37616 	v2 = uint32(TRANSFORM_PRESENT)
  37617 	v3 = int32(1)
  37618 	if libc.Uint64FromInt64(4) == libc.Uint64FromInt32(4) {
  37619 		if v3 > libc.Int32FromInt32(0) {
  37620 			if (*VP8LBitWriter)(unsafe.Pointer(v1)).Fused >= libc.Int32FromInt32(32) {
  37621 				VP8LPutBitsFlushBits(tls, v1)
  37622 			}
  37623 			**(**vp8l_atype_t)(__ccgo_up(v1)) |= uint64(v2) << (*VP8LBitWriter)(unsafe.Pointer(v1)).Fused
  37624 			**(**int32)(__ccgo_up(v1 + 8)) += v3
  37625 		}
  37626 	} else {
  37627 		VP8LPutBitsInternal(tls, v1, v2, v3)
  37628 	}
  37629 	v1 = bw1
  37630 	v2 = uint32(CROSS_COLOR_TRANSFORM)
  37631 	v3 = int32(2)
  37632 	if libc.Uint64FromInt64(4) == libc.Uint64FromInt32(4) {
  37633 		if v3 > libc.Int32FromInt32(0) {
  37634 			if (*VP8LBitWriter)(unsafe.Pointer(v1)).Fused >= libc.Int32FromInt32(32) {
  37635 				VP8LPutBitsFlushBits(tls, v1)
  37636 			}
  37637 			**(**vp8l_atype_t)(__ccgo_up(v1)) |= uint64(v2) << (*VP8LBitWriter)(unsafe.Pointer(v1)).Fused
  37638 			**(**int32)(__ccgo_up(v1 + 8)) += v3
  37639 		}
  37640 	} else {
  37641 		VP8LPutBitsInternal(tls, v1, v2, v3)
  37642 	}
  37643 	v1 = bw1
  37644 	v2 = uint32(**(**int32)(__ccgo_up(best_bits)) - int32(MIN_TRANSFORM_BITS))
  37645 	v3 = int32(NUM_TRANSFORM_BITS)
  37646 	if libc.Uint64FromInt64(4) == libc.Uint64FromInt32(4) {
  37647 		if v3 > libc.Int32FromInt32(0) {
  37648 			if (*VP8LBitWriter)(unsafe.Pointer(v1)).Fused >= libc.Int32FromInt32(32) {
  37649 				VP8LPutBitsFlushBits(tls, v1)
  37650 			}
  37651 			**(**vp8l_atype_t)(__ccgo_up(v1)) |= uint64(v2) << (*VP8LBitWriter)(unsafe.Pointer(v1)).Fused
  37652 			**(**int32)(__ccgo_up(v1 + 8)) += v3
  37653 		}
  37654 	} else {
  37655 		VP8LPutBitsInternal(tls, v1, v2, v3)
  37656 	}
  37657 	v2 = uint32(**(**int32)(__ccgo_up(best_bits)))
  37658 	v5 = (uint32(width) + uint32(libc.Int32FromInt32(1)<<v2) - uint32(1)) >> v2
  37659 	goto _12
  37660 _12:
  37661 	v8 = uint32(**(**int32)(__ccgo_up(best_bits)))
  37662 	v10 = (uint32(height) + uint32(libc.Int32FromInt32(1)<<v8) - uint32(1)) >> v8
  37663 	goto _15
  37664 _15:
  37665 	return EncodeImageNoHuffman(tls, bw1, (*VP8LEncoder)(unsafe.Pointer(enc)).Ftransform_data, enc+2312, enc+2152, int32(v5), int32(v10), quality, low_effort, (*VP8LEncoder)(unsafe.Pointer(enc)).Fpic, percent_range-percent_range/int32(2), percent)
  37666 }
  37667 
  37668 // -----------------------------------------------------------------------------
  37669 
  37670 func WriteRiffHeader(tls *libc.TLS, pic uintptr, riff_size size_t, vp8l_size size_t) (r int32) {
  37671 	bp := tls.Alloc(32)
  37672 	defer tls.Free(32)
  37673 	var v1, v3, v5 uintptr
  37674 	var v4, v6 int32
  37675 	var v2 uint32_t
  37676 	var _ /* riff at bp+0 */ [21]uint8_t
  37677 	_, _, _, _, _, _ = v1, v2, v3, v4, v5, v6
  37678 	**(**[21]uint8_t)(__ccgo_up(bp)) = [21]uint8_t{
  37679 		0:  uint8('R'),
  37680 		1:  uint8('I'),
  37681 		2:  uint8('F'),
  37682 		3:  uint8('F'),
  37683 		8:  uint8('W'),
  37684 		9:  uint8('E'),
  37685 		10: uint8('B'),
  37686 		11: uint8('P'),
  37687 		12: uint8('V'),
  37688 		13: uint8('P'),
  37689 		14: uint8('8'),
  37690 		15: uint8('L'),
  37691 		20: uint8(VP8L_MAGIC_BYTE3),
  37692 	}
  37693 	v1 = bp + uintptr(TAG_SIZE)
  37694 	v2 = uint32(riff_size)
  37695 	v3 = v1
  37696 	v4 = int32(v2 & libc.Uint32FromInt32(0xffff))
  37697 	**(**uint8_t)(__ccgo_up(v3)) = uint8(v4 >> 0 & int32(0xff))
  37698 	**(**uint8_t)(__ccgo_up(v3 + 1)) = uint8(v4 >> int32(8) & int32(0xff))
  37699 	v5 = v1 + uintptr(2)
  37700 	v6 = int32(v2 >> libc.Int32FromInt32(16))
  37701 	**(**uint8_t)(__ccgo_up(v5)) = uint8(v6 >> 0 & int32(0xff))
  37702 	**(**uint8_t)(__ccgo_up(v5 + 1)) = uint8(v6 >> int32(8) & int32(0xff))
  37703 	v1 = bp + uintptr(RIFF_HEADER_SIZE) + uintptr(TAG_SIZE)
  37704 	v2 = uint32(vp8l_size)
  37705 	v3 = v1
  37706 	v4 = int32(v2 & libc.Uint32FromInt32(0xffff))
  37707 	**(**uint8_t)(__ccgo_up(v3)) = uint8(v4 >> 0 & int32(0xff))
  37708 	**(**uint8_t)(__ccgo_up(v3 + 1)) = uint8(v4 >> int32(8) & int32(0xff))
  37709 	v5 = v1 + uintptr(2)
  37710 	v6 = int32(v2 >> libc.Int32FromInt32(16))
  37711 	**(**uint8_t)(__ccgo_up(v5)) = uint8(v6 >> 0 & int32(0xff))
  37712 	**(**uint8_t)(__ccgo_up(v5 + 1)) = uint8(v6 >> int32(8) & int32(0xff))
  37713 	return (*(*func(*libc.TLS, uintptr, size_t, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*WebPPicture)(unsafe.Pointer(pic)).Fwriter})))(tls, bp, uint64(21), pic)
  37714 }
  37715 
  37716 func WriteImageSize(tls *libc.TLS, pic uintptr, bw1 uintptr) (r int32) {
  37717 	var height, width, v3 int32
  37718 	var v1 uintptr
  37719 	var v2 uint32_t
  37720 	_, _, _, _, _ = height, width, v1, v2, v3
  37721 	width = (*WebPPicture)(unsafe.Pointer(pic)).Fwidth - int32(1)
  37722 	height = (*WebPPicture)(unsafe.Pointer(pic)).Fheight - int32(1)
  37723 	v1 = bw1
  37724 	v2 = uint32(width)
  37725 	v3 = int32(VP8L_IMAGE_SIZE_BITS)
  37726 	if libc.Uint64FromInt64(4) == libc.Uint64FromInt32(4) {
  37727 		if v3 > libc.Int32FromInt32(0) {
  37728 			if (*VP8LBitWriter)(unsafe.Pointer(v1)).Fused >= libc.Int32FromInt32(32) {
  37729 				VP8LPutBitsFlushBits(tls, v1)
  37730 			}
  37731 			**(**vp8l_atype_t)(__ccgo_up(v1)) |= uint64(v2) << (*VP8LBitWriter)(unsafe.Pointer(v1)).Fused
  37732 			**(**int32)(__ccgo_up(v1 + 8)) += v3
  37733 		}
  37734 	} else {
  37735 		VP8LPutBitsInternal(tls, v1, v2, v3)
  37736 	}
  37737 	v1 = bw1
  37738 	v2 = uint32(height)
  37739 	v3 = int32(VP8L_IMAGE_SIZE_BITS)
  37740 	if libc.Uint64FromInt64(4) == libc.Uint64FromInt32(4) {
  37741 		if v3 > libc.Int32FromInt32(0) {
  37742 			if (*VP8LBitWriter)(unsafe.Pointer(v1)).Fused >= libc.Int32FromInt32(32) {
  37743 				VP8LPutBitsFlushBits(tls, v1)
  37744 			}
  37745 			**(**vp8l_atype_t)(__ccgo_up(v1)) |= uint64(v2) << (*VP8LBitWriter)(unsafe.Pointer(v1)).Fused
  37746 			**(**int32)(__ccgo_up(v1 + 8)) += v3
  37747 		}
  37748 	} else {
  37749 		VP8LPutBitsInternal(tls, v1, v2, v3)
  37750 	}
  37751 	return libc.BoolInt32(!((*VP8LBitWriter)(unsafe.Pointer(bw1)).Ferror1 != 0))
  37752 }
  37753 
  37754 func WriteRealAlphaAndVersion(tls *libc.TLS, bw1 uintptr, has_alpha int32) (r int32) {
  37755 	var v1 uintptr
  37756 	var v2 uint32_t
  37757 	var v3 int32
  37758 	_, _, _ = v1, v2, v3
  37759 	v1 = bw1
  37760 	v2 = uint32(has_alpha)
  37761 	v3 = int32(1)
  37762 	if libc.Uint64FromInt64(4) == libc.Uint64FromInt32(4) {
  37763 		if v3 > libc.Int32FromInt32(0) {
  37764 			if (*VP8LBitWriter)(unsafe.Pointer(v1)).Fused >= libc.Int32FromInt32(32) {
  37765 				VP8LPutBitsFlushBits(tls, v1)
  37766 			}
  37767 			**(**vp8l_atype_t)(__ccgo_up(v1)) |= uint64(v2) << (*VP8LBitWriter)(unsafe.Pointer(v1)).Fused
  37768 			**(**int32)(__ccgo_up(v1 + 8)) += v3
  37769 		}
  37770 	} else {
  37771 		VP8LPutBitsInternal(tls, v1, v2, v3)
  37772 	}
  37773 	v1 = bw1
  37774 	v2 = uint32(VP8L_VERSION)
  37775 	v3 = int32(VP8L_VERSION_BITS)
  37776 	if libc.Uint64FromInt64(4) == libc.Uint64FromInt32(4) {
  37777 		if v3 > libc.Int32FromInt32(0) {
  37778 			if (*VP8LBitWriter)(unsafe.Pointer(v1)).Fused >= libc.Int32FromInt32(32) {
  37779 				VP8LPutBitsFlushBits(tls, v1)
  37780 			}
  37781 			**(**vp8l_atype_t)(__ccgo_up(v1)) |= uint64(v2) << (*VP8LBitWriter)(unsafe.Pointer(v1)).Fused
  37782 			**(**int32)(__ccgo_up(v1 + 8)) += v3
  37783 		}
  37784 	} else {
  37785 		VP8LPutBitsInternal(tls, v1, v2, v3)
  37786 	}
  37787 	return libc.BoolInt32(!((*VP8LBitWriter)(unsafe.Pointer(bw1)).Ferror1 != 0))
  37788 }
  37789 
  37790 func WriteImage(tls *libc.TLS, pic uintptr, bw1 uintptr, coded_size uintptr) (r int32) {
  37791 	bp := tls.Alloc(16)
  37792 	defer tls.Free(16)
  37793 	var pad, riff_size, vp8l_size, webpll_size, v2 size_t
  37794 	var webpll_data, v1 uintptr
  37795 	var _ /* pad_byte at bp+0 */ [1]uint8_t
  37796 	_, _, _, _, _, _, _ = pad, riff_size, vp8l_size, webpll_data, webpll_size, v1, v2
  37797 	webpll_data = VP8LBitWriterFinish(tls, bw1)
  37798 	v1 = bw1
  37799 	v2 = uint64(int64((*VP8LBitWriter)(unsafe.Pointer(v1)).Fcur) - int64((*VP8LBitWriter)(unsafe.Pointer(v1)).Fbuf) + int64(((*VP8LBitWriter)(unsafe.Pointer(v1)).Fused+libc.Int32FromInt32(7))>>libc.Int32FromInt32(3)))
  37800 	goto _3
  37801 _3:
  37802 	webpll_size = v2
  37803 	vp8l_size = uint64(VP8L_SIGNATURE_SIZE) + webpll_size
  37804 	pad = vp8l_size & uint64(1)
  37805 	riff_size = uint64(libc.Int32FromInt32(TAG_SIZE)+libc.Int32FromInt32(CHUNK_HEADER_SIZE)) + vp8l_size + pad
  37806 	**(**size_t)(__ccgo_up(coded_size)) = uint64(0)
  37807 	if (*VP8LBitWriter)(unsafe.Pointer(bw1)).Ferror1 != 0 {
  37808 		return WebPEncodingSetError(tls, pic, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  37809 	}
  37810 	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) {
  37811 		return WebPEncodingSetError(tls, pic, int32(VP8_ENC_ERROR_BAD_WRITE))
  37812 	}
  37813 	if pad != 0 {
  37814 		**(**[1]uint8_t)(__ccgo_up(bp)) = [1]uint8_t{}
  37815 		if !((*(*func(*libc.TLS, uintptr, size_t, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*WebPPicture)(unsafe.Pointer(pic)).Fwriter})))(tls, bp, uint64(1), pic) != 0) {
  37816 			return WebPEncodingSetError(tls, pic, int32(VP8_ENC_ERROR_BAD_WRITE))
  37817 		}
  37818 	}
  37819 	**(**size_t)(__ccgo_up(coded_size)) = uint64(CHUNK_HEADER_SIZE) + riff_size
  37820 	return int32(1)
  37821 }
  37822 
  37823 // -----------------------------------------------------------------------------
  37824 
  37825 func ClearTransformBuffer(tls *libc.TLS, enc uintptr) {
  37826 	WebPSafeFree(tls, (*VP8LEncoder)(unsafe.Pointer(enc)).Ftransform_mem)
  37827 	(*VP8LEncoder)(unsafe.Pointer(enc)).Ftransform_mem = libc.UintptrFromInt32(0)
  37828 	(*VP8LEncoder)(unsafe.Pointer(enc)).Ftransform_mem_size = uint64(0)
  37829 }
  37830 
  37831 // C documentation
  37832 //
  37833 //	// Allocates the memory for argb (W x H) buffer, 2 rows of context for
  37834 //	// prediction and transform data.
  37835 //	// Flags influencing the memory allocated:
  37836 //	//  enc->transform_bits
  37837 //	//  enc->use_predict, enc->use_cross_color
  37838 func AllocateTransformBuffer(tls *libc.TLS, enc uintptr, width int32, height int32) (r int32) {
  37839 	var argb_scratch_size, image_size, max_alignment_in_words, mem_size, transform_data_size uint64_t
  37840 	var mem uintptr
  37841 	var v1, v2 uint64
  37842 	var v3, v4, v6, v7 uint32_t
  37843 	_, _, _, _, _, _, _, _, _, _, _, _ = argb_scratch_size, image_size, max_alignment_in_words, mem, mem_size, transform_data_size, v1, v2, v3, v4, v6, v7
  37844 	image_size = uint64(width) * uint64(height)
  37845 	if (*VP8LEncoder)(unsafe.Pointer(enc)).Fuse_predict != 0 {
  37846 		v1 = uint64((width+int32(1))*int32(2)) + (uint64(width*int32(2))+uint64(4)-uint64(1))/uint64(4)
  37847 	} else {
  37848 		v1 = uint64(0)
  37849 	}
  37850 	// VP8LResidualImage needs room for 2 scanlines of uint32 pixels with an extra
  37851 	// pixel in each, plus 2 regular scanlines of bytes.
  37852 	// TODO(skal): Clean up by using arithmetic in bytes instead of words.
  37853 	argb_scratch_size = v1
  37854 	if (*VP8LEncoder)(unsafe.Pointer(enc)).Fuse_predict != 0 || (*VP8LEncoder)(unsafe.Pointer(enc)).Fuse_cross_color != 0 {
  37855 		v3 = uint32(MIN_TRANSFORM_BITS)
  37856 		v4 = (uint32(width) + uint32(libc.Int32FromInt32(1)<<v3) - uint32(1)) >> v3
  37857 		goto _5
  37858 	_5:
  37859 		v6 = uint32(MIN_TRANSFORM_BITS)
  37860 		v7 = (uint32(height) + uint32(libc.Int32FromInt32(1)<<v6) - uint32(1)) >> v6
  37861 		goto _8
  37862 	_8:
  37863 		v2 = uint64(v4) * uint64(v7)
  37864 	} else {
  37865 		v2 = uint64(0)
  37866 	}
  37867 	transform_data_size = v2
  37868 	max_alignment_in_words = (libc.Uint64FromInt32(WEBP_ALIGN_CST) + libc.Uint64FromInt64(4) - libc.Uint64FromInt32(1)) / libc.Uint64FromInt64(4)
  37869 	mem_size = image_size + max_alignment_in_words + argb_scratch_size + max_alignment_in_words + transform_data_size
  37870 	mem = (*VP8LEncoder)(unsafe.Pointer(enc)).Ftransform_mem
  37871 	if mem == libc.UintptrFromInt32(0) || mem_size > (*VP8LEncoder)(unsafe.Pointer(enc)).Ftransform_mem_size {
  37872 		ClearTransformBuffer(tls, enc)
  37873 		mem = WebPSafeMalloc(tls, mem_size, uint64(4))
  37874 		if mem == libc.UintptrFromInt32(0) {
  37875 			return WebPEncodingSetError(tls, (*VP8LEncoder)(unsafe.Pointer(enc)).Fpic, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  37876 		}
  37877 		(*VP8LEncoder)(unsafe.Pointer(enc)).Ftransform_mem = mem
  37878 		(*VP8LEncoder)(unsafe.Pointer(enc)).Ftransform_mem_size = mem_size
  37879 		(*VP8LEncoder)(unsafe.Pointer(enc)).Fargb_content = int32(kEncoderNone)
  37880 	}
  37881 	(*VP8LEncoder)(unsafe.Pointer(enc)).Fargb = mem
  37882 	mem = uintptr((uint64(mem+uintptr(image_size)*4) + libc.Uint64FromInt32(WEBP_ALIGN_CST)) & ^libc.Uint64FromInt32(WEBP_ALIGN_CST))
  37883 	(*VP8LEncoder)(unsafe.Pointer(enc)).Fargb_scratch = mem
  37884 	mem = uintptr((uint64(mem+uintptr(argb_scratch_size)*4) + libc.Uint64FromInt32(WEBP_ALIGN_CST)) & ^libc.Uint64FromInt32(WEBP_ALIGN_CST))
  37885 	(*VP8LEncoder)(unsafe.Pointer(enc)).Ftransform_data = mem
  37886 	(*VP8LEncoder)(unsafe.Pointer(enc)).Fcurrent_width = width
  37887 	return int32(1)
  37888 }
  37889 
  37890 func MakeInputImageCopy(tls *libc.TLS, enc uintptr) (r int32) {
  37891 	var dst, picture, src uintptr
  37892 	var height, width, y int32
  37893 	_, _, _, _, _, _ = dst, height, picture, src, width, y
  37894 	picture = (*VP8LEncoder)(unsafe.Pointer(enc)).Fpic
  37895 	width = (*WebPPicture)(unsafe.Pointer(picture)).Fwidth
  37896 	height = (*WebPPicture)(unsafe.Pointer(picture)).Fheight
  37897 	if !(AllocateTransformBuffer(tls, enc, width, height) != 0) {
  37898 		return 0
  37899 	}
  37900 	if (*VP8LEncoder)(unsafe.Pointer(enc)).Fargb_content == int32(kEncoderARGB) {
  37901 		return int32(1)
  37902 	}
  37903 	dst = (*VP8LEncoder)(unsafe.Pointer(enc)).Fargb
  37904 	src = (*WebPPicture)(unsafe.Pointer(picture)).Fargb
  37905 	y = 0
  37906 	for {
  37907 		if !(y < height) {
  37908 			break
  37909 		}
  37910 		libc.Xmemcpy(tls, dst, src, uint64(width)*uint64(4))
  37911 		dst = dst + uintptr(width)*4
  37912 		src = src + uintptr((*WebPPicture)(unsafe.Pointer(picture)).Fargb_stride)*4
  37913 		goto _1
  37914 	_1:
  37915 		;
  37916 		y = y + 1
  37917 	}
  37918 	(*VP8LEncoder)(unsafe.Pointer(enc)).Fargb_content = int32(kEncoderARGB)
  37919 	return int32(1)
  37920 }
  37921 
  37922 // -----------------------------------------------------------------------------
  37923 
  37924 func SearchColorGreedy(tls *libc.TLS, palette uintptr, palette_size int32, color uint32_t) (r uint32_t) {
  37925 	_ = palette_size
  37926 	if color == **(**uint32_t)(__ccgo_up(palette)) {
  37927 		return uint32(0)
  37928 	}
  37929 	if color == **(**uint32_t)(__ccgo_up(palette + 1*4)) {
  37930 		return uint32(1)
  37931 	}
  37932 	if color == **(**uint32_t)(__ccgo_up(palette + 2*4)) {
  37933 		return uint32(2)
  37934 	}
  37935 	return uint32(3)
  37936 }
  37937 
  37938 func ApplyPaletteHash0(tls *libc.TLS, color uint32_t) (r uint32_t) {
  37939 	// Focus on the green color.
  37940 	return color >> libc.Int32FromInt32(8) & uint32(0xff)
  37941 }
  37942 
  37943 func ApplyPaletteHash1(tls *libc.TLS, color uint32_t) (r uint32_t) {
  37944 	// Forget about alpha.
  37945 	return uint32(uint64(color&libc.Uint32FromUint32(0x00ffffff))*libc.Uint64FromUint64(4222244071)) >> (libc.Int32FromInt32(32) - libc.Int32FromInt32(11))
  37946 }
  37947 
  37948 func ApplyPaletteHash2(tls *libc.TLS, color uint32_t) (r uint32_t) {
  37949 	// Forget about alpha.
  37950 	return uint32(uint64(color&libc.Uint32FromUint32(0x00ffffff))*(libc.Uint64FromUint64(1)<<libc.Int32FromInt32(31)-libc.Uint64FromInt32(1))) >> (libc.Int32FromInt32(32) - libc.Int32FromInt32(11))
  37951 }
  37952 
  37953 // Use 1 pixel cache for ARGB pixels.
  37954 
  37955 // C documentation
  37956 //
  37957 //	// Remap argb values in src[] to packed palettes entries in dst[]
  37958 //	// using 'row' as a temporary buffer of size 'width'.
  37959 //	// We assume that all src[] values have a corresponding entry in the palette.
  37960 //	// Note: src[] can be the same as dst[]
  37961 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) {
  37962 	bp := tls.Alloc(6144)
  37963 	defer tls.Free(6144)
  37964 	var hash_functions [3]uintptr
  37965 	var i, j, use_LUT, x, y int32
  37966 	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
  37967 	var tmp_row uintptr
  37968 	var _ /* buffer at bp+0 */ [2048]uint16_t
  37969 	var _ /* idx_map at bp+4096 */ [256]uint32_t
  37970 	var _ /* palette_sorted at bp+5120 */ [256]uint32_t
  37971 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  37972 	// TODO(skal): this tmp buffer is not needed if VP8LBundleColorMap() can be
  37973 	// made to work in-place.
  37974 	tmp_row = WebPSafeMalloc(tls, uint64(width), uint64(1))
  37975 	if tmp_row == libc.UintptrFromInt32(0) {
  37976 		return WebPEncodingSetError(tls, pic, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  37977 	}
  37978 	if palette_size < int32(4) {
  37979 		prev_pix = **(**uint32_t)(__ccgo_up(palette))
  37980 		prev_idx = uint32(0)
  37981 		y = 0
  37982 		for {
  37983 			if !(y < height) {
  37984 				break
  37985 			}
  37986 			x = 0
  37987 			for {
  37988 				if !(x < width) {
  37989 					break
  37990 				}
  37991 				pix = **(**uint32_t)(__ccgo_up(src + uintptr(x)*4))
  37992 				if pix != prev_pix {
  37993 					prev_idx = SearchColorGreedy(tls, palette, palette_size, pix)
  37994 					prev_pix = pix
  37995 				}
  37996 				**(**uint8_t)(__ccgo_up(tmp_row + uintptr(x))) = uint8(prev_idx)
  37997 				goto _2
  37998 			_2:
  37999 				;
  38000 				x = x + 1
  38001 			}
  38002 			(*(*func(*libc.TLS, uintptr, int32, int32, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8LBundleColorMap})))(tls, tmp_row, width, xbits, dst)
  38003 			src = src + uintptr(src_stride)*4
  38004 			dst = dst + uintptr(dst_stride)*4
  38005 			goto _1
  38006 		_1:
  38007 			;
  38008 			y = y + 1
  38009 		}
  38010 	} else {
  38011 		hash_functions = [3]uintptr{
  38012 			0: __ccgo_fp(ApplyPaletteHash0),
  38013 			1: __ccgo_fp(ApplyPaletteHash1),
  38014 			2: __ccgo_fp(ApplyPaletteHash2),
  38015 		}
  38016 		// Try to find a perfect hash function able to go from a color to an index
  38017 		// within 1 << PALETTE_INV_SIZE_BITS in order to build a hash map to go
  38018 		// from color to index in palette.
  38019 		i = 0
  38020 		for {
  38021 			if !(i < int32(3)) {
  38022 				break
  38023 			}
  38024 			use_LUT = int32(1)
  38025 			// Set each element in buffer to max uint16_t.
  38026 			libc.Xmemset(tls, bp, int32(0xff), uint64(4096))
  38027 			j = 0
  38028 			for {
  38029 				if !(j < palette_size) {
  38030 					break
  38031 				}
  38032 				ind = (*(*func(*libc.TLS, uint32_t) uint32_t)(unsafe.Pointer(&struct{ uintptr }{hash_functions[i]})))(tls, **(**uint32_t)(__ccgo_up(palette + uintptr(j)*4)))
  38033 				if uint32((**(**[2048]uint16_t)(__ccgo_up(bp)))[ind]) != uint32(0xffff) {
  38034 					use_LUT = 0
  38035 					break
  38036 				} else {
  38037 					(**(**[2048]uint16_t)(__ccgo_up(bp)))[ind] = uint16(j)
  38038 				}
  38039 				goto _4
  38040 			_4:
  38041 				;
  38042 				j = j + 1
  38043 			}
  38044 			if use_LUT != 0 {
  38045 				break
  38046 			}
  38047 			goto _3
  38048 		_3:
  38049 			;
  38050 			i = i + 1
  38051 		}
  38052 		if i == 0 {
  38053 			prev_pix1 = **(**uint32_t)(__ccgo_up(palette))
  38054 			prev_idx1 = uint32(0)
  38055 			y = 0
  38056 			for {
  38057 				if !(y < height) {
  38058 					break
  38059 				}
  38060 				x = 0
  38061 				for {
  38062 					if !(x < width) {
  38063 						break
  38064 					}
  38065 					pix1 = **(**uint32_t)(__ccgo_up(src + uintptr(x)*4))
  38066 					if pix1 != prev_pix1 {
  38067 						prev_idx1 = uint32((**(**[2048]uint16_t)(__ccgo_up(bp)))[ApplyPaletteHash0(tls, pix1)])
  38068 						prev_pix1 = pix1
  38069 					}
  38070 					**(**uint8_t)(__ccgo_up(tmp_row + uintptr(x))) = uint8(prev_idx1)
  38071 					goto _6
  38072 				_6:
  38073 					;
  38074 					x = x + 1
  38075 				}
  38076 				(*(*func(*libc.TLS, uintptr, int32, int32, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8LBundleColorMap})))(tls, tmp_row, width, xbits, dst)
  38077 				src = src + uintptr(src_stride)*4
  38078 				dst = dst + uintptr(dst_stride)*4
  38079 				goto _5
  38080 			_5:
  38081 				;
  38082 				y = y + 1
  38083 			}
  38084 		} else {
  38085 			if i == int32(1) {
  38086 				prev_pix2 = **(**uint32_t)(__ccgo_up(palette))
  38087 				prev_idx2 = uint32(0)
  38088 				y = 0
  38089 				for {
  38090 					if !(y < height) {
  38091 						break
  38092 					}
  38093 					x = 0
  38094 					for {
  38095 						if !(x < width) {
  38096 							break
  38097 						}
  38098 						pix2 = **(**uint32_t)(__ccgo_up(src + uintptr(x)*4))
  38099 						if pix2 != prev_pix2 {
  38100 							prev_idx2 = uint32((**(**[2048]uint16_t)(__ccgo_up(bp)))[ApplyPaletteHash1(tls, pix2)])
  38101 							prev_pix2 = pix2
  38102 						}
  38103 						**(**uint8_t)(__ccgo_up(tmp_row + uintptr(x))) = uint8(prev_idx2)
  38104 						goto _8
  38105 					_8:
  38106 						;
  38107 						x = x + 1
  38108 					}
  38109 					(*(*func(*libc.TLS, uintptr, int32, int32, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8LBundleColorMap})))(tls, tmp_row, width, xbits, dst)
  38110 					src = src + uintptr(src_stride)*4
  38111 					dst = dst + uintptr(dst_stride)*4
  38112 					goto _7
  38113 				_7:
  38114 					;
  38115 					y = y + 1
  38116 				}
  38117 			} else {
  38118 				if i == int32(2) {
  38119 					prev_pix3 = **(**uint32_t)(__ccgo_up(palette))
  38120 					prev_idx3 = uint32(0)
  38121 					y = 0
  38122 					for {
  38123 						if !(y < height) {
  38124 							break
  38125 						}
  38126 						x = 0
  38127 						for {
  38128 							if !(x < width) {
  38129 								break
  38130 							}
  38131 							pix3 = **(**uint32_t)(__ccgo_up(src + uintptr(x)*4))
  38132 							if pix3 != prev_pix3 {
  38133 								prev_idx3 = uint32((**(**[2048]uint16_t)(__ccgo_up(bp)))[ApplyPaletteHash2(tls, pix3)])
  38134 								prev_pix3 = pix3
  38135 							}
  38136 							**(**uint8_t)(__ccgo_up(tmp_row + uintptr(x))) = uint8(prev_idx3)
  38137 							goto _10
  38138 						_10:
  38139 							;
  38140 							x = x + 1
  38141 						}
  38142 						(*(*func(*libc.TLS, uintptr, int32, int32, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8LBundleColorMap})))(tls, tmp_row, width, xbits, dst)
  38143 						src = src + uintptr(src_stride)*4
  38144 						dst = dst + uintptr(dst_stride)*4
  38145 						goto _9
  38146 					_9:
  38147 						;
  38148 						y = y + 1
  38149 					}
  38150 				} else {
  38151 					PrepareMapToPalette(tls, palette, uint32(palette_size), bp+5120, bp+4096)
  38152 					prev_pix4 = **(**uint32_t)(__ccgo_up(palette))
  38153 					prev_idx4 = uint32(0)
  38154 					y = 0
  38155 					for {
  38156 						if !(y < height) {
  38157 							break
  38158 						}
  38159 						x = 0
  38160 						for {
  38161 							if !(x < width) {
  38162 								break
  38163 							}
  38164 							pix4 = **(**uint32_t)(__ccgo_up(src + uintptr(x)*4))
  38165 							if pix4 != prev_pix4 {
  38166 								prev_idx4 = (**(**[256]uint32_t)(__ccgo_up(bp + 4096)))[SearchColorNoIdx(tls, bp+5120, pix4, palette_size)]
  38167 								prev_pix4 = pix4
  38168 							}
  38169 							**(**uint8_t)(__ccgo_up(tmp_row + uintptr(x))) = uint8(prev_idx4)
  38170 							goto _12
  38171 						_12:
  38172 							;
  38173 							x = x + 1
  38174 						}
  38175 						(*(*func(*libc.TLS, uintptr, int32, int32, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8LBundleColorMap})))(tls, tmp_row, width, xbits, dst)
  38176 						src = src + uintptr(src_stride)*4
  38177 						dst = dst + uintptr(dst_stride)*4
  38178 						goto _11
  38179 					_11:
  38180 						;
  38181 						y = y + 1
  38182 					}
  38183 				}
  38184 			}
  38185 		}
  38186 	}
  38187 	WebPSafeFree(tls, tmp_row)
  38188 	return int32(1)
  38189 }
  38190 
  38191 // C documentation
  38192 //
  38193 //	// Note: Expects "enc->palette" to be set properly.
  38194 func MapImageFromPalette(tls *libc.TLS, enc uintptr) (r int32) {
  38195 	var height, palette_size, width, xbits, v1 int32
  38196 	var palette, pic uintptr
  38197 	var v3, v4 uint32_t
  38198 	_, _, _, _, _, _, _, _, _ = height, palette, palette_size, pic, width, xbits, v1, v3, v4
  38199 	pic = (*VP8LEncoder)(unsafe.Pointer(enc)).Fpic
  38200 	width = (*WebPPicture)(unsafe.Pointer(pic)).Fwidth
  38201 	height = (*WebPPicture)(unsafe.Pointer(pic)).Fheight
  38202 	palette = enc + 104
  38203 	palette_size = (*VP8LEncoder)(unsafe.Pointer(enc)).Fpalette_size
  38204 	// Replace each input pixel by corresponding palette index.
  38205 	// This is done line by line.
  38206 	if palette_size <= int32(4) {
  38207 		if palette_size <= int32(2) {
  38208 			v1 = int32(3)
  38209 		} else {
  38210 			v1 = int32(2)
  38211 		}
  38212 		xbits = v1
  38213 	} else {
  38214 		if palette_size <= int32(16) {
  38215 			v1 = int32(1)
  38216 		} else {
  38217 			v1 = 0
  38218 		}
  38219 		xbits = v1
  38220 	}
  38221 	v3 = uint32(xbits)
  38222 	v4 = (uint32(width) + uint32(libc.Int32FromInt32(1)<<v3) - uint32(1)) >> v3
  38223 	goto _5
  38224 _5:
  38225 	if !(AllocateTransformBuffer(tls, enc, int32(v4), height) != 0) {
  38226 		return 0
  38227 	}
  38228 	if !(ApplyPalette(tls, (*WebPPicture)(unsafe.Pointer(pic)).Fargb, uint32((*WebPPicture)(unsafe.Pointer(pic)).Fargb_stride), (*VP8LEncoder)(unsafe.Pointer(enc)).Fargb, uint32((*VP8LEncoder)(unsafe.Pointer(enc)).Fcurrent_width), palette, palette_size, width, height, xbits, pic) != 0) {
  38229 		return 0
  38230 	}
  38231 	(*VP8LEncoder)(unsafe.Pointer(enc)).Fargb_content = int32(kEncoderPalette)
  38232 	return int32(1)
  38233 }
  38234 
  38235 // C documentation
  38236 //
  38237 //	// Save palette[] to bitstream.
  38238 func EncodePalette(tls *libc.TLS, bw1 uintptr, low_effort int32, enc uintptr, percent_range int32, percent uintptr) (r int32) {
  38239 	bp := tls.Alloc(1024)
  38240 	defer tls.Free(1024)
  38241 	var alpha_and_green, encoded_palette_size, red_and_blue, v3, v6, v9 uint32_t
  38242 	var i, palette_size, v1, v4 int32
  38243 	var palette, v2 uintptr
  38244 	var _ /* tmp_palette at bp+0 */ [256]uint32_t
  38245 	_, _, _, _, _, _, _, _, _, _, _, _ = alpha_and_green, encoded_palette_size, i, palette, palette_size, red_and_blue, v1, v2, v3, v4, v6, v9
  38246 	palette_size = (*VP8LEncoder)(unsafe.Pointer(enc)).Fpalette_size
  38247 	palette = enc + 104
  38248 	if **(**uint32_t)(__ccgo_up(enc + 104 + uintptr(palette_size-int32(1))*4)) == uint32(0) && palette_size > int32(17) {
  38249 		v1 = palette_size - int32(1)
  38250 	} else {
  38251 		v1 = palette_size
  38252 	}
  38253 	// If the last element is 0, do not store it and count on automatic palette
  38254 	// 0-filling. This can only happen if there is no pixel packing, hence if
  38255 	// there are strictly more than 16 colors (after 0 is removed).
  38256 	encoded_palette_size = uint32(v1)
  38257 	v2 = bw1
  38258 	v3 = uint32(TRANSFORM_PRESENT)
  38259 	v4 = int32(1)
  38260 	if libc.Uint64FromInt64(4) == libc.Uint64FromInt32(4) {
  38261 		if v4 > libc.Int32FromInt32(0) {
  38262 			if (*VP8LBitWriter)(unsafe.Pointer(v2)).Fused >= libc.Int32FromInt32(32) {
  38263 				VP8LPutBitsFlushBits(tls, v2)
  38264 			}
  38265 			**(**vp8l_atype_t)(__ccgo_up(v2)) |= uint64(v3) << (*VP8LBitWriter)(unsafe.Pointer(v2)).Fused
  38266 			**(**int32)(__ccgo_up(v2 + 8)) += v4
  38267 		}
  38268 	} else {
  38269 		VP8LPutBitsInternal(tls, v2, v3, v4)
  38270 	}
  38271 	v2 = bw1
  38272 	v3 = uint32(COLOR_INDEXING_TRANSFORM)
  38273 	v1 = int32(2)
  38274 	if libc.Uint64FromInt64(4) == libc.Uint64FromInt32(4) {
  38275 		if v1 > libc.Int32FromInt32(0) {
  38276 			if (*VP8LBitWriter)(unsafe.Pointer(v2)).Fused >= libc.Int32FromInt32(32) {
  38277 				VP8LPutBitsFlushBits(tls, v2)
  38278 			}
  38279 			**(**vp8l_atype_t)(__ccgo_up(v2)) |= uint64(v3) << (*VP8LBitWriter)(unsafe.Pointer(v2)).Fused
  38280 			**(**int32)(__ccgo_up(v2 + 8)) += v1
  38281 		}
  38282 	} else {
  38283 		VP8LPutBitsInternal(tls, v2, v3, v1)
  38284 	}
  38285 	v2 = bw1
  38286 	v3 = encoded_palette_size - uint32(1)
  38287 	v1 = int32(8)
  38288 	if libc.Uint64FromInt64(4) == libc.Uint64FromInt32(4) {
  38289 		if v1 > libc.Int32FromInt32(0) {
  38290 			if (*VP8LBitWriter)(unsafe.Pointer(v2)).Fused >= libc.Int32FromInt32(32) {
  38291 				VP8LPutBitsFlushBits(tls, v2)
  38292 			}
  38293 			**(**vp8l_atype_t)(__ccgo_up(v2)) |= uint64(v3) << (*VP8LBitWriter)(unsafe.Pointer(v2)).Fused
  38294 			**(**int32)(__ccgo_up(v2 + 8)) += v1
  38295 		}
  38296 	} else {
  38297 		VP8LPutBitsInternal(tls, v2, v3, v1)
  38298 	}
  38299 	i = int32(encoded_palette_size - uint32(1))
  38300 	for {
  38301 		if !(i >= int32(1)) {
  38302 			break
  38303 		}
  38304 		v3 = **(**uint32_t)(__ccgo_up(palette + uintptr(i)*4))
  38305 		v6 = **(**uint32_t)(__ccgo_up(palette + uintptr(i-int32(1))*4))
  38306 		alpha_and_green = uint32(0x00ff00ff) + v3&uint32(0xff00ff00) - v6&uint32(0xff00ff00)
  38307 		red_and_blue = uint32(0xff00ff00) + v3&uint32(0x00ff00ff) - v6&uint32(0x00ff00ff)
  38308 		v9 = alpha_and_green&uint32(0xff00ff00) | red_and_blue&uint32(0x00ff00ff)
  38309 		goto _15
  38310 	_15:
  38311 		(**(**[256]uint32_t)(__ccgo_up(bp)))[i] = v9
  38312 		goto _11
  38313 	_11:
  38314 		;
  38315 		i = i - 1
  38316 	}
  38317 	(**(**[256]uint32_t)(__ccgo_up(bp)))[0] = **(**uint32_t)(__ccgo_up(palette))
  38318 	return EncodeImageNoHuffman(tls, bw1, bp, enc+2312, enc+2152, int32(encoded_palette_size), int32(1), int32(20), low_effort, (*VP8LEncoder)(unsafe.Pointer(enc)).Fpic, percent_range, percent)
  38319 }
  38320 
  38321 // -----------------------------------------------------------------------------
  38322 // VP8LEncoder
  38323 
  38324 func VP8LEncoderNew(tls *libc.TLS, config uintptr, picture uintptr) (r uintptr) {
  38325 	var enc uintptr
  38326 	_ = enc
  38327 	enc = WebPSafeCalloc(tls, uint64(1), uint64(2328))
  38328 	if enc == libc.UintptrFromInt32(0) {
  38329 		WebPEncodingSetError(tls, picture, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  38330 		return libc.UintptrFromInt32(0)
  38331 	}
  38332 	(*VP8LEncoder)(unsafe.Pointer(enc)).Fconfig = config
  38333 	(*VP8LEncoder)(unsafe.Pointer(enc)).Fpic = picture
  38334 	(*VP8LEncoder)(unsafe.Pointer(enc)).Fargb_content = int32(kEncoderNone)
  38335 	VP8LEncDspInit(tls)
  38336 	return enc
  38337 }
  38338 
  38339 func VP8LEncoderDelete(tls *libc.TLS, enc uintptr) {
  38340 	var i int32
  38341 	_ = i
  38342 	if enc != libc.UintptrFromInt32(0) {
  38343 		VP8LHashChainClear(tls, enc+2312)
  38344 		i = 0
  38345 		for {
  38346 			if !(i < int32(4)) {
  38347 				break
  38348 			}
  38349 			VP8LBackwardRefsClear(tls, enc+2152+uintptr(i)*40)
  38350 			goto _1
  38351 		_1:
  38352 			;
  38353 			i = i + 1
  38354 		}
  38355 		ClearTransformBuffer(tls, enc)
  38356 		WebPSafeFree(tls, enc)
  38357 	}
  38358 }
  38359 
  38360 // -----------------------------------------------------------------------------
  38361 // Main call
  38362 
  38363 type StreamEncodeContext = struct {
  38364 	Fconfig                   uintptr
  38365 	Fpicture                  uintptr
  38366 	Fbw                       uintptr
  38367 	Fenc                      uintptr
  38368 	Fcrunch_configs           [14]CrunchConfig
  38369 	Fnum_crunch_configs       int32
  38370 	Fred_and_blue_always_zero int32
  38371 	Fstats                    uintptr
  38372 }
  38373 
  38374 func EncodeStreamHook(tls *libc.TLS, input uintptr, data2 uintptr) (r int32) {
  38375 	bp := tls.Alloc(128)
  38376 	defer tls.Free(128)
  38377 	var best_size, byte_position, v12, v2 size_t
  38378 	var bw2, config, crunch_configs, enc, params, picture, stats, v1, v8 uintptr
  38379 	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
  38380 	var v9 uint32_t
  38381 	var _ /* bw_best at bp+64 */ VP8LBitWriter
  38382 	var _ /* bw_init at bp+16 */ VP8LBitWriter
  38383 	var _ /* cross_color_transform_bits at bp+116 */ int32
  38384 	var _ /* data_size at bp+8 */ int32
  38385 	var _ /* hdr_size at bp+4 */ int32
  38386 	var _ /* percent at bp+0 */ int32
  38387 	var _ /* predictor_transform_bits at bp+112 */ int32
  38388 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  38389 	params = input
  38390 	config = (*StreamEncodeContext)(unsafe.Pointer(params)).Fconfig
  38391 	picture = (*StreamEncodeContext)(unsafe.Pointer(params)).Fpicture
  38392 	bw2 = (*StreamEncodeContext)(unsafe.Pointer(params)).Fbw
  38393 	enc = (*StreamEncodeContext)(unsafe.Pointer(params)).Fenc
  38394 	crunch_configs = params + 32
  38395 	num_crunch_configs = (*StreamEncodeContext)(unsafe.Pointer(params)).Fnum_crunch_configs
  38396 	red_and_blue_always_zero = (*StreamEncodeContext)(unsafe.Pointer(params)).Fred_and_blue_always_zero
  38397 	stats = (*StreamEncodeContext)(unsafe.Pointer(params)).Fstats
  38398 	quality = int32((*WebPConfig)(unsafe.Pointer(config)).Fquality)
  38399 	low_effort = libc.BoolInt32((*WebPConfig)(unsafe.Pointer(config)).Fmethod == libc.Int32FromInt32(0))
  38400 	width = (*WebPPicture)(unsafe.Pointer(picture)).Fwidth
  38401 	height = (*WebPPicture)(unsafe.Pointer(picture)).Fheight
  38402 	v1 = bw2
  38403 	v2 = uint64(int64((*VP8LBitWriter)(unsafe.Pointer(v1)).Fcur) - int64((*VP8LBitWriter)(unsafe.Pointer(v1)).Fbuf) + int64(((*VP8LBitWriter)(unsafe.Pointer(v1)).Fused+libc.Int32FromInt32(7))>>libc.Int32FromInt32(3)))
  38404 	goto _3
  38405 _3:
  38406 	byte_position = v2
  38407 	**(**int32)(__ccgo_up(bp)) = int32(2) // for WebPProgressHook
  38408 	use_near_lossless = 0
  38409 	**(**int32)(__ccgo_up(bp + 4)) = 0
  38410 	**(**int32)(__ccgo_up(bp + 8)) = 0
  38411 	best_size = ^libc.Uint64FromInt32(0)
  38412 	**(**VP8LBitWriter)(__ccgo_up(bp + 16)) = **(**VP8LBitWriter)(__ccgo_up(bw2))
  38413 	_ = data2
  38414 	if !(VP8LBitWriterInit(tls, bp+64, uint64(0)) != 0) || num_crunch_configs > int32(1) && !(VP8LBitWriterClone(tls, bw2, bp+64) != 0) {
  38415 		WebPEncodingSetError(tls, picture, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  38416 		goto Error
  38417 	}
  38418 	idx = 0
  38419 	for {
  38420 		if !(idx < num_crunch_configs) {
  38421 			break
  38422 		}
  38423 		entropy_idx = (**(**CrunchConfig)(__ccgo_up(crunch_configs + uintptr(idx)*28))).Fentropy_idx
  38424 		remaining_percent = int32(97) / num_crunch_configs
  38425 		**(**int32)(__ccgo_up(bp + 112)) = 0
  38426 		**(**int32)(__ccgo_up(bp + 116)) = 0
  38427 		(*VP8LEncoder)(unsafe.Pointer(enc)).Fuse_palette = libc.BoolInt32(entropy_idx == int32(kPalette) || entropy_idx == int32(kPaletteAndSpatial))
  38428 		(*VP8LEncoder)(unsafe.Pointer(enc)).Fuse_subtract_green = libc.BoolInt32(entropy_idx == int32(kSubGreen) || entropy_idx == int32(kSpatialSubGreen))
  38429 		(*VP8LEncoder)(unsafe.Pointer(enc)).Fuse_predict = libc.BoolInt32(entropy_idx == int32(kSpatial) || entropy_idx == int32(kSpatialSubGreen) || entropy_idx == int32(kPaletteAndSpatial))
  38430 		// When using a palette, R/B==0, hence no need to test for cross-color.
  38431 		if low_effort != 0 || (*VP8LEncoder)(unsafe.Pointer(enc)).Fuse_palette != 0 {
  38432 			(*VP8LEncoder)(unsafe.Pointer(enc)).Fuse_cross_color = 0
  38433 		} else {
  38434 			if red_and_blue_always_zero != 0 {
  38435 				v5 = 0
  38436 			} else {
  38437 				v5 = (*VP8LEncoder)(unsafe.Pointer(enc)).Fuse_predict
  38438 			}
  38439 			(*VP8LEncoder)(unsafe.Pointer(enc)).Fuse_cross_color = v5
  38440 		}
  38441 		// Reset any parameter in the encoder that is set in the previous iteration.
  38442 		(*VP8LEncoder)(unsafe.Pointer(enc)).Fcache_bits = 0
  38443 		VP8LBackwardRefsClear(tls, enc+2152)
  38444 		VP8LBackwardRefsClear(tls, enc+2152+1*40)
  38445 		// Apply near-lossless preprocessing.
  38446 		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))
  38447 		if use_near_lossless != 0 {
  38448 			if !(AllocateTransformBuffer(tls, enc, width, height) != 0) {
  38449 				goto Error
  38450 			}
  38451 			if (*VP8LEncoder)(unsafe.Pointer(enc)).Fargb_content != int32(kEncoderNearLossless) && !(VP8ApplyNearLossless(tls, picture, (*WebPConfig)(unsafe.Pointer(config)).Fnear_lossless, (*VP8LEncoder)(unsafe.Pointer(enc)).Fargb) != 0) {
  38452 				WebPEncodingSetError(tls, picture, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  38453 				goto Error
  38454 			}
  38455 			(*VP8LEncoder)(unsafe.Pointer(enc)).Fargb_content = int32(kEncoderNearLossless)
  38456 		} else {
  38457 			(*VP8LEncoder)(unsafe.Pointer(enc)).Fargb_content = int32(kEncoderNone)
  38458 		}
  38459 		// Encode palette
  38460 		if (*VP8LEncoder)(unsafe.Pointer(enc)).Fuse_palette != 0 {
  38461 			if !(PaletteSort(tls, (**(**CrunchConfig)(__ccgo_up(crunch_configs + uintptr(idx)*28))).Fpalette_sorting_type, (*VP8LEncoder)(unsafe.Pointer(enc)).Fpic, enc+1128, uint32((*VP8LEncoder)(unsafe.Pointer(enc)).Fpalette_size), enc+104) != 0) {
  38462 				WebPEncodingSetError(tls, (*VP8LEncoder)(unsafe.Pointer(enc)).Fpic, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  38463 				goto Error
  38464 			}
  38465 			percent_range = remaining_percent / int32(4)
  38466 			if !(EncodePalette(tls, bw2, low_effort, enc, percent_range, bp) != 0) {
  38467 				goto Error
  38468 			}
  38469 			remaining_percent = remaining_percent - percent_range
  38470 			if !(MapImageFromPalette(tls, enc) != 0) {
  38471 				goto Error
  38472 			}
  38473 			// If using a color cache, do not have it bigger than the number of
  38474 			// colors.
  38475 			if (*VP8LEncoder)(unsafe.Pointer(enc)).Fpalette_size < libc.Int32FromInt32(1)<<libc.Int32FromInt32(MAX_COLOR_CACHE_BITS) {
  38476 				v5 = int32(31) ^ libc.X__builtin_clz(tls, uint32((*VP8LEncoder)(unsafe.Pointer(enc)).Fpalette_size))
  38477 				goto _7
  38478 			_7:
  38479 				(*VP8LEncoder)(unsafe.Pointer(enc)).Fcache_bits = v5 + int32(1)
  38480 			}
  38481 		}
  38482 		// In case image is not packed.
  38483 		if (*VP8LEncoder)(unsafe.Pointer(enc)).Fargb_content != int32(kEncoderNearLossless) && (*VP8LEncoder)(unsafe.Pointer(enc)).Fargb_content != int32(kEncoderPalette) {
  38484 			if !(MakeInputImageCopy(tls, enc) != 0) {
  38485 				goto Error
  38486 			}
  38487 		}
  38488 		// -------------------------------------------------------------------------
  38489 		// Apply transforms and write transform data.
  38490 		if (*VP8LEncoder)(unsafe.Pointer(enc)).Fuse_subtract_green != 0 {
  38491 			ApplySubtractGreen(tls, enc, (*VP8LEncoder)(unsafe.Pointer(enc)).Fcurrent_width, height, bw2)
  38492 		}
  38493 		if (*VP8LEncoder)(unsafe.Pointer(enc)).Fuse_predict != 0 {
  38494 			percent_range = remaining_percent / int32(3)
  38495 			if !(ApplyPredictFilter(tls, enc, (*VP8LEncoder)(unsafe.Pointer(enc)).Fcurrent_width, height, quality, low_effort, (*VP8LEncoder)(unsafe.Pointer(enc)).Fuse_subtract_green, bw2, percent_range, bp, bp+112) != 0) {
  38496 				goto Error
  38497 			}
  38498 			remaining_percent = remaining_percent - percent_range
  38499 		}
  38500 		if (*VP8LEncoder)(unsafe.Pointer(enc)).Fuse_cross_color != 0 {
  38501 			percent_range = remaining_percent / int32(2)
  38502 			if !(ApplyCrossColorFilter(tls, enc, (*VP8LEncoder)(unsafe.Pointer(enc)).Fcurrent_width, height, quality, low_effort, bw2, percent_range, bp, bp+116) != 0) {
  38503 				goto Error
  38504 			}
  38505 			remaining_percent = remaining_percent - percent_range
  38506 		}
  38507 		v1 = bw2
  38508 		v9 = libc.BoolUint32(!(libc.Int32FromInt32(TRANSFORM_PRESENT) != 0))
  38509 		v5 = int32(1)
  38510 		if libc.Uint64FromInt64(4) == libc.Uint64FromInt32(4) {
  38511 			if v5 > libc.Int32FromInt32(0) {
  38512 				if (*VP8LBitWriter)(unsafe.Pointer(v1)).Fused >= libc.Int32FromInt32(32) {
  38513 					VP8LPutBitsFlushBits(tls, v1)
  38514 				}
  38515 				**(**vp8l_atype_t)(__ccgo_up(v1)) |= uint64(v9) << (*VP8LBitWriter)(unsafe.Pointer(v1)).Fused
  38516 				**(**int32)(__ccgo_up(v1 + 8)) += v5
  38517 			}
  38518 		} else {
  38519 			VP8LPutBitsInternal(tls, v1, v9, v5)
  38520 		} // No more transforms.
  38521 		// -------------------------------------------------------------------------
  38522 		// Encode and write the transformed image.
  38523 		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) {
  38524 			goto Error
  38525 		}
  38526 		// If we are better than what we already have.
  38527 		v1 = bw2
  38528 		v2 = uint64(int64((*VP8LBitWriter)(unsafe.Pointer(v1)).Fcur) - int64((*VP8LBitWriter)(unsafe.Pointer(v1)).Fbuf) + int64(((*VP8LBitWriter)(unsafe.Pointer(v1)).Fused+libc.Int32FromInt32(7))>>libc.Int32FromInt32(3)))
  38529 		goto _13
  38530 	_13:
  38531 		if v2 < best_size {
  38532 			v8 = bw2
  38533 			v12 = uint64(int64((*VP8LBitWriter)(unsafe.Pointer(v8)).Fcur) - int64((*VP8LBitWriter)(unsafe.Pointer(v8)).Fbuf) + int64(((*VP8LBitWriter)(unsafe.Pointer(v8)).Fused+libc.Int32FromInt32(7))>>libc.Int32FromInt32(3)))
  38534 			goto _16
  38535 		_16:
  38536 			best_size = v12
  38537 			// Store the BitWriter.
  38538 			VP8LBitWriterSwap(tls, bw2, bp+64)
  38539 			// Update the stats.
  38540 			if stats != libc.UintptrFromInt32(0) {
  38541 				(*WebPAuxStats)(unsafe.Pointer(stats)).Flossless_features = uint32(0)
  38542 				if (*VP8LEncoder)(unsafe.Pointer(enc)).Fuse_predict != 0 {
  38543 					**(**uint32_t)(__ccgo_up(stats + 148)) |= uint32(1)
  38544 				}
  38545 				if (*VP8LEncoder)(unsafe.Pointer(enc)).Fuse_cross_color != 0 {
  38546 					**(**uint32_t)(__ccgo_up(stats + 148)) |= uint32(2)
  38547 				}
  38548 				if (*VP8LEncoder)(unsafe.Pointer(enc)).Fuse_subtract_green != 0 {
  38549 					**(**uint32_t)(__ccgo_up(stats + 148)) |= uint32(4)
  38550 				}
  38551 				if (*VP8LEncoder)(unsafe.Pointer(enc)).Fuse_palette != 0 {
  38552 					**(**uint32_t)(__ccgo_up(stats + 148)) |= uint32(8)
  38553 				}
  38554 				(*WebPAuxStats)(unsafe.Pointer(stats)).Fhistogram_bits = (*VP8LEncoder)(unsafe.Pointer(enc)).Fhisto_bits
  38555 				(*WebPAuxStats)(unsafe.Pointer(stats)).Ftransform_bits = **(**int32)(__ccgo_up(bp + 112))
  38556 				(*WebPAuxStats)(unsafe.Pointer(stats)).Fcross_color_transform_bits = **(**int32)(__ccgo_up(bp + 116))
  38557 				(*WebPAuxStats)(unsafe.Pointer(stats)).Fcache_bits = (*VP8LEncoder)(unsafe.Pointer(enc)).Fcache_bits
  38558 				(*WebPAuxStats)(unsafe.Pointer(stats)).Fpalette_size = (*VP8LEncoder)(unsafe.Pointer(enc)).Fpalette_size
  38559 				(*WebPAuxStats)(unsafe.Pointer(stats)).Flossless_size = int32(best_size - byte_position)
  38560 				(*WebPAuxStats)(unsafe.Pointer(stats)).Flossless_hdr_size = **(**int32)(__ccgo_up(bp + 4))
  38561 				(*WebPAuxStats)(unsafe.Pointer(stats)).Flossless_data_size = **(**int32)(__ccgo_up(bp + 8))
  38562 			}
  38563 		}
  38564 		// Reset the bit writer for the following iteration if any.
  38565 		if num_crunch_configs > int32(1) {
  38566 			VP8LBitWriterReset(tls, bp+16, bw2)
  38567 		}
  38568 		goto _4
  38569 	_4:
  38570 		;
  38571 		idx = idx + 1
  38572 	}
  38573 	VP8LBitWriterSwap(tls, bp+64, bw2)
  38574 	goto Error
  38575 Error:
  38576 	;
  38577 	VP8LBitWriterWipeOut(tls, bp+64)
  38578 	// The hook should return false in case of error.
  38579 	return libc.BoolInt32((*WebPPicture)(unsafe.Pointer((*StreamEncodeContext)(unsafe.Pointer(params)).Fpicture)).Ferror_code == int32(VP8_ENC_OK))
  38580 }
  38581 
  38582 func VP8LEncodeStream(tls *libc.TLS, config uintptr, picture1 uintptr, bw_main uintptr) (r int32) {
  38583 	bp := tls.Alloc(1872)
  38584 	defer tls.Free(1872)
  38585 	var enc_main, enc_side, param, worker, worker_interface, v7, v8 uintptr
  38586 	var idx, num_crunch_configs_side, ok_main, ok_side, params_size, v1 int32
  38587 	var v11, v14 size_t
  38588 	var _ /* bw_side at bp+1568 */ VP8LBitWriter
  38589 	var _ /* crunch_configs at bp+0 */ [14]CrunchConfig
  38590 	var _ /* num_crunch_configs_main at bp+392 */ int32
  38591 	var _ /* params_main at bp+496 */ StreamEncodeContext
  38592 	var _ /* params_side at bp+936 */ StreamEncodeContext
  38593 	var _ /* picture_side at bp+1616 */ WebPPicture
  38594 	var _ /* red_and_blue_always_zero at bp+396 */ int32
  38595 	var _ /* stats_side at bp+1376 */ WebPAuxStats
  38596 	var _ /* worker_main at bp+400 */ WebPWorker
  38597 	var _ /* worker_side at bp+448 */ WebPWorker
  38598 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = enc_main, enc_side, idx, num_crunch_configs_side, ok_main, ok_side, param, params_size, worker, worker_interface, v1, v11, v14, v7, v8
  38599 	enc_main = VP8LEncoderNew(tls, config, picture1)
  38600 	enc_side = libc.UintptrFromInt32(0)
  38601 	num_crunch_configs_side = 0
  38602 	**(**int32)(__ccgo_up(bp + 396)) = 0
  38603 	worker_interface = WebPGetWorkerInterface(tls)
  38604 	if enc_main == libc.UintptrFromInt32(0) || !(VP8LBitWriterInit(tls, bp+1568, uint64(0)) != 0) {
  38605 		VP8LEncoderDelete(tls, enc_main)
  38606 		return WebPEncodingSetError(tls, picture1, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  38607 	}
  38608 	// Avoid "garbage value" error from Clang's static analysis tool.
  38609 	v1 = WebPPictureInitInternal(tls, bp+1616, int32(WEBP_ENCODER_ABI_VERSION))
  38610 	goto _2
  38611 _2:
  38612 	if !(v1 != 0) {
  38613 		goto Error
  38614 	}
  38615 	// Analyze image (entropy, num_palettes etc)
  38616 	if !(EncoderAnalyze(tls, enc_main, bp, bp+392, bp+396) != 0) || !(EncoderInit(tls, enc_main) != 0) {
  38617 		WebPEncodingSetError(tls, picture1, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  38618 		goto Error
  38619 	}
  38620 	// Split the configs between the main and side threads (if any).
  38621 	if (*WebPConfig)(unsafe.Pointer(config)).Fthread_level > 0 {
  38622 		num_crunch_configs_side = **(**int32)(__ccgo_up(bp + 392)) / int32(2)
  38623 		idx = 0
  38624 		for {
  38625 			if !(idx < num_crunch_configs_side) {
  38626 				break
  38627 			}
  38628 			**(**CrunchConfig)(__ccgo_up(bp + 936 + 32 + uintptr(idx)*28)) = (**(**[14]CrunchConfig)(__ccgo_up(bp)))[**(**int32)(__ccgo_up(bp + 392))-num_crunch_configs_side+idx]
  38629 			goto _3
  38630 		_3:
  38631 			;
  38632 			idx = idx + 1
  38633 		}
  38634 		(**(**StreamEncodeContext)(__ccgo_up(bp + 936))).Fnum_crunch_configs = num_crunch_configs_side
  38635 	}
  38636 	**(**int32)(__ccgo_up(bp + 392)) = **(**int32)(__ccgo_up(bp + 392)) - num_crunch_configs_side
  38637 	idx = 0
  38638 	for {
  38639 		if !(idx < **(**int32)(__ccgo_up(bp + 392))) {
  38640 			break
  38641 		}
  38642 		**(**CrunchConfig)(__ccgo_up(bp + 496 + 32 + uintptr(idx)*28)) = (**(**[14]CrunchConfig)(__ccgo_up(bp)))[idx]
  38643 		goto _4
  38644 	_4:
  38645 		;
  38646 		idx = idx + 1
  38647 	}
  38648 	(**(**StreamEncodeContext)(__ccgo_up(bp + 496))).Fnum_crunch_configs = **(**int32)(__ccgo_up(bp + 392))
  38649 	// Fill in the parameters for the thread workers.
  38650 	if num_crunch_configs_side > 0 {
  38651 		v1 = int32(2)
  38652 	} else {
  38653 		v1 = int32(1)
  38654 	}
  38655 	params_size = v1
  38656 	idx = 0
  38657 	for {
  38658 		if !(idx < params_size) {
  38659 			break
  38660 		}
  38661 		if idx == 0 {
  38662 			v7 = bp + 400
  38663 		} else {
  38664 			v7 = bp + 448
  38665 		}
  38666 		// Create the parameters for each worker.
  38667 		worker = v7
  38668 		if idx == 0 {
  38669 			v8 = bp + 496
  38670 		} else {
  38671 			v8 = bp + 936
  38672 		}
  38673 		param = v8
  38674 		(*StreamEncodeContext)(unsafe.Pointer(param)).Fconfig = config
  38675 		(*StreamEncodeContext)(unsafe.Pointer(param)).Fred_and_blue_always_zero = **(**int32)(__ccgo_up(bp + 396))
  38676 		if idx == 0 {
  38677 			(*StreamEncodeContext)(unsafe.Pointer(param)).Fpicture = picture1
  38678 			(*StreamEncodeContext)(unsafe.Pointer(param)).Fstats = (*WebPPicture)(unsafe.Pointer(picture1)).Fstats
  38679 			(*StreamEncodeContext)(unsafe.Pointer(param)).Fbw = bw_main
  38680 			(*StreamEncodeContext)(unsafe.Pointer(param)).Fenc = enc_main
  38681 		} else {
  38682 			// Create a side picture (error_code is not thread-safe).
  38683 			if !(WebPPictureView(tls, picture1, 0, 0, (*WebPPicture)(unsafe.Pointer(picture1)).Fwidth, (*WebPPicture)(unsafe.Pointer(picture1)).Fheight, bp+1616) != 0) {
  38684 			}
  38685 			(**(**WebPPicture)(__ccgo_up(bp + 1616))).Fprogress_hook = libc.UintptrFromInt32(0) // Progress hook is not thread-safe.
  38686 			(*StreamEncodeContext)(unsafe.Pointer(param)).Fpicture = bp + 1616                  // No need to free a view afterwards.
  38687 			if (*WebPPicture)(unsafe.Pointer(picture1)).Fstats == libc.UintptrFromInt32(0) {
  38688 				v7 = libc.UintptrFromInt32(0)
  38689 			} else {
  38690 				v7 = bp + 1376
  38691 			}
  38692 			(*StreamEncodeContext)(unsafe.Pointer(param)).Fstats = v7
  38693 			// Create a side bit writer.
  38694 			if !(VP8LBitWriterClone(tls, bw_main, bp+1568) != 0) {
  38695 				WebPEncodingSetError(tls, picture1, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  38696 				goto Error
  38697 			}
  38698 			(*StreamEncodeContext)(unsafe.Pointer(param)).Fbw = bp + 1568
  38699 			// Create a side encoder.
  38700 			enc_side = VP8LEncoderNew(tls, config, bp+1616)
  38701 			if enc_side == libc.UintptrFromInt32(0) || !(EncoderInit(tls, enc_side) != 0) {
  38702 				WebPEncodingSetError(tls, picture1, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  38703 				goto Error
  38704 			}
  38705 			// Copy the values that were computed for the main encoder.
  38706 			(*VP8LEncoder)(unsafe.Pointer(enc_side)).Fhisto_bits = (*VP8LEncoder)(unsafe.Pointer(enc_main)).Fhisto_bits
  38707 			(*VP8LEncoder)(unsafe.Pointer(enc_side)).Fpredictor_transform_bits = (*VP8LEncoder)(unsafe.Pointer(enc_main)).Fpredictor_transform_bits
  38708 			(*VP8LEncoder)(unsafe.Pointer(enc_side)).Fcross_color_transform_bits = (*VP8LEncoder)(unsafe.Pointer(enc_main)).Fcross_color_transform_bits
  38709 			(*VP8LEncoder)(unsafe.Pointer(enc_side)).Fpalette_size = (*VP8LEncoder)(unsafe.Pointer(enc_main)).Fpalette_size
  38710 			libc.Xmemcpy(tls, enc_side+104, enc_main+104, uint64(1024))
  38711 			libc.Xmemcpy(tls, enc_side+1128, enc_main+1128, uint64(1024))
  38712 			(*StreamEncodeContext)(unsafe.Pointer(param)).Fenc = enc_side
  38713 		}
  38714 		// Create the workers.
  38715 		(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(&struct{ uintptr }{(*WebPWorkerInterface)(unsafe.Pointer(worker_interface)).FInit})))(tls, worker)
  38716 		(*WebPWorker)(unsafe.Pointer(worker)).Fdata1 = param
  38717 		(*WebPWorker)(unsafe.Pointer(worker)).Fdata2 = libc.UintptrFromInt32(0)
  38718 		(*WebPWorker)(unsafe.Pointer(worker)).Fhook = __ccgo_fp(EncodeStreamHook)
  38719 		goto _6
  38720 	_6:
  38721 		;
  38722 		idx = idx + 1
  38723 	}
  38724 	// Start the second thread if needed.
  38725 	if num_crunch_configs_side != 0 {
  38726 		if !((*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*WebPWorkerInterface)(unsafe.Pointer(worker_interface)).FReset})))(tls, bp+448) != 0) {
  38727 			WebPEncodingSetError(tls, picture1, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  38728 			goto Error
  38729 		}
  38730 		// This line is here and not in the param initialization above to remove a
  38731 		// Clang static analyzer warning.
  38732 		if (*WebPPicture)(unsafe.Pointer(picture1)).Fstats != libc.UintptrFromInt32(0) {
  38733 			libc.Xmemcpy(tls, bp+1376, (*WebPPicture)(unsafe.Pointer(picture1)).Fstats, uint64(188))
  38734 		}
  38735 		(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(&struct{ uintptr }{(*WebPWorkerInterface)(unsafe.Pointer(worker_interface)).FLaunch})))(tls, bp+448)
  38736 	}
  38737 	// Execute the main thread.
  38738 	(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(&struct{ uintptr }{(*WebPWorkerInterface)(unsafe.Pointer(worker_interface)).FExecute})))(tls, bp+400)
  38739 	ok_main = (*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*WebPWorkerInterface)(unsafe.Pointer(worker_interface)).FSync})))(tls, bp+400)
  38740 	(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(&struct{ uintptr }{(*WebPWorkerInterface)(unsafe.Pointer(worker_interface)).FEnd})))(tls, bp+400)
  38741 	if num_crunch_configs_side != 0 {
  38742 		// Wait for the second thread.
  38743 		ok_side = (*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*WebPWorkerInterface)(unsafe.Pointer(worker_interface)).FSync})))(tls, bp+448)
  38744 		(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(&struct{ uintptr }{(*WebPWorkerInterface)(unsafe.Pointer(worker_interface)).FEnd})))(tls, bp+448)
  38745 		if !(ok_main != 0) || !(ok_side != 0) {
  38746 			if (*WebPPicture)(unsafe.Pointer(picture1)).Ferror_code == int32(VP8_ENC_OK) {
  38747 				WebPEncodingSetError(tls, picture1, (**(**WebPPicture)(__ccgo_up(bp + 1616))).Ferror_code)
  38748 			}
  38749 			goto Error
  38750 		}
  38751 		v7 = bp + 1568
  38752 		v11 = uint64(int64((*VP8LBitWriter)(unsafe.Pointer(v7)).Fcur) - int64((*VP8LBitWriter)(unsafe.Pointer(v7)).Fbuf) + int64(((*VP8LBitWriter)(unsafe.Pointer(v7)).Fused+libc.Int32FromInt32(7))>>libc.Int32FromInt32(3)))
  38753 		goto _12
  38754 	_12:
  38755 		v8 = bw_main
  38756 		v14 = uint64(int64((*VP8LBitWriter)(unsafe.Pointer(v8)).Fcur) - int64((*VP8LBitWriter)(unsafe.Pointer(v8)).Fbuf) + int64(((*VP8LBitWriter)(unsafe.Pointer(v8)).Fused+libc.Int32FromInt32(7))>>libc.Int32FromInt32(3)))
  38757 		goto _15
  38758 	_15:
  38759 		if v11 < v14 {
  38760 			VP8LBitWriterSwap(tls, bw_main, bp+1568)
  38761 			if (*WebPPicture)(unsafe.Pointer(picture1)).Fstats != libc.UintptrFromInt32(0) {
  38762 				libc.Xmemcpy(tls, (*WebPPicture)(unsafe.Pointer(picture1)).Fstats, bp+1376, uint64(188))
  38763 			}
  38764 		}
  38765 	}
  38766 	goto Error
  38767 Error:
  38768 	;
  38769 	VP8LBitWriterWipeOut(tls, bp+1568)
  38770 	VP8LEncoderDelete(tls, enc_main)
  38771 	VP8LEncoderDelete(tls, enc_side)
  38772 	return libc.BoolInt32((*WebPPicture)(unsafe.Pointer(picture1)).Ferror_code == int32(VP8_ENC_OK))
  38773 }
  38774 
  38775 func VP8LEncodeImage(tls *libc.TLS, config uintptr, picture uintptr) (r int32) {
  38776 	bp := tls.Alloc(64)
  38777 	defer tls.Free(64)
  38778 	var has_alpha, height, initial_size, mb_h, mb_w, width, v1 int32
  38779 	var stats uintptr
  38780 	var _ /* bw at bp+16 */ VP8LBitWriter
  38781 	var _ /* coded_size at bp+0 */ size_t
  38782 	var _ /* percent at bp+8 */ int32
  38783 	_, _, _, _, _, _, _, _ = has_alpha, height, initial_size, mb_h, mb_w, stats, width, v1
  38784 	**(**int32)(__ccgo_up(bp + 8)) = 0
  38785 	if picture == libc.UintptrFromInt32(0) {
  38786 		return 0
  38787 	}
  38788 	if config == libc.UintptrFromInt32(0) || (*WebPPicture)(unsafe.Pointer(picture)).Fargb == libc.UintptrFromInt32(0) {
  38789 		return WebPEncodingSetError(tls, picture, int32(VP8_ENC_ERROR_NULL_PARAMETER))
  38790 	}
  38791 	width = (*WebPPicture)(unsafe.Pointer(picture)).Fwidth
  38792 	height = (*WebPPicture)(unsafe.Pointer(picture)).Fheight
  38793 	// Initialize BitWriter with size corresponding to 16 bpp to photo images and
  38794 	// 8 bpp for graphical images.
  38795 	if (*WebPConfig)(unsafe.Pointer(config)).Fimage_hint == int32(WEBP_HINT_GRAPH) {
  38796 		v1 = width * height
  38797 	} else {
  38798 		v1 = width * height * int32(2)
  38799 	}
  38800 	initial_size = v1
  38801 	if !(VP8LBitWriterInit(tls, bp+16, uint64(initial_size)) != 0) {
  38802 		WebPEncodingSetError(tls, picture, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  38803 		goto Error
  38804 	}
  38805 	if !!(WebPReportProgress(tls, picture, int32(1), bp+8) != 0) {
  38806 		goto _2
  38807 	}
  38808 	goto UserAbort
  38809 UserAbort:
  38810 	;
  38811 	WebPEncodingSetError(tls, picture, int32(VP8_ENC_ERROR_USER_ABORT))
  38812 	goto Error
  38813 _2:
  38814 	;
  38815 	// Reset stats (for pure lossless coding)
  38816 	if (*WebPPicture)(unsafe.Pointer(picture)).Fstats != libc.UintptrFromInt32(0) {
  38817 		stats = (*WebPPicture)(unsafe.Pointer(picture)).Fstats
  38818 		libc.Xmemset(tls, stats, 0, uint64(188))
  38819 		**(**float32)(__ccgo_up(stats + 4)) = libc.Float32FromFloat32(99)
  38820 		**(**float32)(__ccgo_up(stats + 4 + 1*4)) = libc.Float32FromFloat32(99)
  38821 		**(**float32)(__ccgo_up(stats + 4 + 2*4)) = libc.Float32FromFloat32(99)
  38822 		**(**float32)(__ccgo_up(stats + 4 + 3*4)) = libc.Float32FromFloat32(99)
  38823 		**(**float32)(__ccgo_up(stats + 4 + 4*4)) = libc.Float32FromFloat32(99)
  38824 	}
  38825 	// Write image size.
  38826 	if !(WriteImageSize(tls, picture, bp+16) != 0) {
  38827 		WebPEncodingSetError(tls, picture, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  38828 		goto Error
  38829 	}
  38830 	has_alpha = WebPPictureHasTransparency(tls, picture)
  38831 	// Write the non-trivial Alpha flag and lossless version.
  38832 	if !(WriteRealAlphaAndVersion(tls, bp+16, has_alpha) != 0) {
  38833 		WebPEncodingSetError(tls, picture, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  38834 		goto Error
  38835 	}
  38836 	if !(WebPReportProgress(tls, picture, int32(2), bp+8) != 0) {
  38837 		goto UserAbort
  38838 	}
  38839 	// Encode main image stream.
  38840 	if !(VP8LEncodeStream(tls, config, picture, bp+16) != 0) {
  38841 		goto Error
  38842 	}
  38843 	if !(WebPReportProgress(tls, picture, int32(99), bp+8) != 0) {
  38844 		goto UserAbort
  38845 	}
  38846 	// Finish the RIFF chunk.
  38847 	if !(WriteImage(tls, picture, bp+16, bp) != 0) {
  38848 		goto Error
  38849 	}
  38850 	if !(WebPReportProgress(tls, picture, int32(100), bp+8) != 0) {
  38851 		goto UserAbort
  38852 	}
  38853 	// Save size.
  38854 	if (*WebPPicture)(unsafe.Pointer(picture)).Fstats != libc.UintptrFromInt32(0) {
  38855 		**(**int32)(__ccgo_up((*WebPPicture)(unsafe.Pointer(picture)).Fstats)) += int32(**(**size_t)(__ccgo_up(bp)))
  38856 		(*WebPAuxStats)(unsafe.Pointer((*WebPPicture)(unsafe.Pointer(picture)).Fstats)).Flossless_size = int32(**(**size_t)(__ccgo_up(bp)))
  38857 	}
  38858 	if (*WebPPicture)(unsafe.Pointer(picture)).Fextra_info != libc.UintptrFromInt32(0) {
  38859 		mb_w = (width + int32(15)) >> int32(4)
  38860 		mb_h = (height + int32(15)) >> int32(4)
  38861 		libc.Xmemset(tls, (*WebPPicture)(unsafe.Pointer(picture)).Fextra_info, 0, uint64(mb_w*mb_h)*uint64(1))
  38862 	}
  38863 	goto Error
  38864 Error:
  38865 	;
  38866 	if (**(**VP8LBitWriter)(__ccgo_up(bp + 16))).Ferror1 != 0 {
  38867 		WebPEncodingSetError(tls, picture, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  38868 	}
  38869 	VP8LBitWriterWipeOut(tls, bp+16)
  38870 	return libc.BoolInt32((*WebPPicture)(unsafe.Pointer(picture)).Ferror_code == int32(VP8_ENC_OK))
  38871 }
  38872 
  38873 const VP8L_MAGIC_BYTE4 = 0x2f
  38874 
  38875 //------------------------------------------------------------------------------
  38876 
  38877 // Copyright 2012 Google Inc. All Rights Reserved.
  38878 //
  38879 // Use of this source code is governed by a BSD-style license
  38880 // that can be found in the COPYING file in the root of the source
  38881 // tree. An additional intellectual property rights grant can be found
  38882 // in the file PATENTS. All contributing project authors may
  38883 // be found in the AUTHORS file in the root of the source tree.
  38884 // -----------------------------------------------------------------------------
  38885 //
  38886 // Misc. common utility functions
  38887 //
  38888 // Authors: Skal (pascal.massimino@gmail.com)
  38889 //          Urvang (urvang@google.com)
  38890 
  38891 // Copyright 2011 Google Inc. All Rights Reserved.
  38892 //
  38893 // Use of this source code is governed by a BSD-style license
  38894 // that can be found in the COPYING file in the root of the source
  38895 // tree. An additional intellectual property rights grant can be found
  38896 // in the file PATENTS. All contributing project authors may
  38897 // be found in the AUTHORS file in the root of the source tree.
  38898 // -----------------------------------------------------------------------------
  38899 //
  38900 //   WebP encoder: main interface
  38901 //
  38902 // Author: Skal (pascal.massimino@gmail.com)
  38903 
  38904 // #define PRINT_MEMORY_INFO
  38905 
  38906 //------------------------------------------------------------------------------
  38907 
  38908 func WebPGetEncoderVersion(tls *libc.TLS) (r int32) {
  38909 	return libc.Int32FromInt32(ENC_MAJ_VERSION)<<libc.Int32FromInt32(16) | libc.Int32FromInt32(ENC_MIN_VERSION)<<libc.Int32FromInt32(8) | libc.Int32FromInt32(ENC_REV_VERSION)
  38910 }
  38911 
  38912 //------------------------------------------------------------------------------
  38913 // VP8Encoder
  38914 //------------------------------------------------------------------------------
  38915 
  38916 func ResetSegmentHeader1(tls *libc.TLS, enc uintptr) {
  38917 	var hdr uintptr
  38918 	_ = hdr
  38919 	hdr = enc + 32
  38920 	(*VP8EncSegmentHeader)(unsafe.Pointer(hdr)).Fnum_segments = (*WebPConfig)(unsafe.Pointer((*VP8Encoder)(unsafe.Pointer(enc)).Fconfig)).Fsegments
  38921 	(*VP8EncSegmentHeader)(unsafe.Pointer(hdr)).Fupdate_map = libc.BoolInt32((*VP8EncSegmentHeader)(unsafe.Pointer(hdr)).Fnum_segments > int32(1))
  38922 	(*VP8EncSegmentHeader)(unsafe.Pointer(hdr)).Fsize = 0
  38923 }
  38924 
  38925 func ResetFilterHeader(tls *libc.TLS, enc uintptr) {
  38926 	var hdr uintptr
  38927 	_ = hdr
  38928 	hdr = enc + 16
  38929 	(*VP8EncFilterHeader)(unsafe.Pointer(hdr)).Fsimple = int32(1)
  38930 	(*VP8EncFilterHeader)(unsafe.Pointer(hdr)).Flevel = 0
  38931 	(*VP8EncFilterHeader)(unsafe.Pointer(hdr)).Fsharpness = 0
  38932 	(*VP8EncFilterHeader)(unsafe.Pointer(hdr)).Fi4x4_lf_delta = 0
  38933 }
  38934 
  38935 func ResetBoundaryPredictions(tls *libc.TLS, enc uintptr) {
  38936 	var i int32
  38937 	var left, top uintptr
  38938 	_, _, _ = i, left, top
  38939 	top = (*VP8Encoder)(unsafe.Pointer(enc)).Fpreds - uintptr((*VP8Encoder)(unsafe.Pointer(enc)).Fpreds_w)
  38940 	left = (*VP8Encoder)(unsafe.Pointer(enc)).Fpreds - uintptr(1)
  38941 	i = -int32(1)
  38942 	for {
  38943 		if !(i < int32(4)*(*VP8Encoder)(unsafe.Pointer(enc)).Fmb_w) {
  38944 			break
  38945 		}
  38946 		**(**uint8_t)(__ccgo_up(top + uintptr(i))) = uint8(B_DC_PRED)
  38947 		goto _1
  38948 	_1:
  38949 		;
  38950 		i = i + 1
  38951 	}
  38952 	i = 0
  38953 	for {
  38954 		if !(i < int32(4)*(*VP8Encoder)(unsafe.Pointer(enc)).Fmb_h) {
  38955 			break
  38956 		}
  38957 		**(**uint8_t)(__ccgo_up(left + uintptr(i*(*VP8Encoder)(unsafe.Pointer(enc)).Fpreds_w))) = uint8(B_DC_PRED)
  38958 		goto _2
  38959 	_2:
  38960 		;
  38961 		i = i + 1
  38962 	}
  38963 	**(**uint32_t)(__ccgo_up((*VP8Encoder)(unsafe.Pointer(enc)).Fnz + uintptr(-libc.Int32FromInt32(1))*4)) = uint32(0) // constant
  38964 }
  38965 
  38966 // Mapping from config->method to coding tools used.
  38967 //-------------------+---+---+---+---+---+---+---+
  38968 //   Method          | 0 | 1 | 2 | 3 |(4)| 5 | 6 |
  38969 //-------------------+---+---+---+---+---+---+---+
  38970 // fast probe        | x |   |   | x |   |   |   |
  38971 //-------------------+---+---+---+---+---+---+---+
  38972 // dynamic proba     | ~ | x | x | x | x | x | x |
  38973 //-------------------+---+---+---+---+---+---+---+
  38974 // fast mode analysis|[x]|[x]|   |   | x | x | x |
  38975 //-------------------+---+---+---+---+---+---+---+
  38976 // basic rd-opt      |   |   |   | x | x | x | x |
  38977 //-------------------+---+---+---+---+---+---+---+
  38978 // disto-refine i4/16| x | x | x |   |   |   |   |
  38979 //-------------------+---+---+---+---+---+---+---+
  38980 // disto-refine uv   |   | x | x |   |   |   |   |
  38981 //-------------------+---+---+---+---+---+---+---+
  38982 // rd-opt i4/16      |   |   | ~ | x | x | x | x |
  38983 //-------------------+---+---+---+---+---+---+---+
  38984 // token buffer (opt)|   |   |   | x | x | x | x |
  38985 //-------------------+---+---+---+---+---+---+---+
  38986 // Trellis           |   |   |   |   |   | x |Ful|
  38987 //-------------------+---+---+---+---+---+---+---+
  38988 // full-SNS          |   |   |   |   | x | x | x |
  38989 //-------------------+---+---+---+---+---+---+---+
  38990 
  38991 func MapConfigToTools(tls *libc.TLS, enc uintptr) {
  38992 	var config uintptr
  38993 	var limit, method, v1, v2, v3 int32
  38994 	_, _, _, _, _, _ = config, limit, method, v1, v2, v3
  38995 	config = (*VP8Encoder)(unsafe.Pointer(enc)).Fconfig
  38996 	method = (*WebPConfig)(unsafe.Pointer(config)).Fmethod
  38997 	limit = int32(100) - (*WebPConfig)(unsafe.Pointer(config)).Fpartition_limit
  38998 	(*VP8Encoder)(unsafe.Pointer(enc)).Fmethod = method
  38999 	if method >= int32(6) {
  39000 		v1 = int32(RD_OPT_TRELLIS_ALL)
  39001 	} else {
  39002 		if method >= int32(5) {
  39003 			v2 = int32(RD_OPT_TRELLIS)
  39004 		} else {
  39005 			if method >= int32(3) {
  39006 				v3 = int32(RD_OPT_BASIC)
  39007 			} else {
  39008 				v3 = int32(RD_OPT_NONE)
  39009 			}
  39010 			v2 = v3
  39011 		}
  39012 		v1 = v2
  39013 	}
  39014 	(*VP8Encoder)(unsafe.Pointer(enc)).Frd_opt_level = v1
  39015 	(*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.
  39016 	// partition0 = 512k max.
  39017 	(*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))
  39018 	(*VP8Encoder)(unsafe.Pointer(enc)).Fthread_level = (*WebPConfig)(unsafe.Pointer(config)).Fthread_level
  39019 	(*VP8Encoder)(unsafe.Pointer(enc)).Fdo_search = libc.BoolInt32((*WebPConfig)(unsafe.Pointer(config)).Ftarget_size > 0 || (*WebPConfig)(unsafe.Pointer(config)).Ftarget_PSNR > libc.Float32FromInt32(0))
  39020 	if !((*WebPConfig)(unsafe.Pointer(config)).Flow_memory != 0) {
  39021 		(*VP8Encoder)(unsafe.Pointer(enc)).Fuse_tokens = libc.BoolInt32((*VP8Encoder)(unsafe.Pointer(enc)).Frd_opt_level >= int32(RD_OPT_BASIC)) // need rd stats
  39022 		if (*VP8Encoder)(unsafe.Pointer(enc)).Fuse_tokens != 0 {
  39023 			(*VP8Encoder)(unsafe.Pointer(enc)).Fnum_parts = int32(1) // doesn't work with multi-partition
  39024 		}
  39025 	}
  39026 }
  39027 
  39028 // Memory scaling with dimensions:
  39029 //  memory (bytes) ~= 2.25 * w + 0.0625 * w * h
  39030 //
  39031 // Typical memory footprint (614x440 picture)
  39032 //              encoder: 22111
  39033 //                 info: 4368
  39034 //                preds: 17741
  39035 //          top samples: 1263
  39036 //             non-zero: 175
  39037 //             lf-stats: 0
  39038 //                total: 45658
  39039 // Transient object sizes:
  39040 //       VP8EncIterator: 3360
  39041 //         VP8ModeScore: 872
  39042 //       VP8SegmentInfo: 732
  39043 //          VP8EncProba: 18352
  39044 //              LFStats: 2048
  39045 // Picture size (yuv): 419328
  39046 
  39047 func InitVP8Encoder(tls *libc.TLS, config uintptr, picture uintptr) (r uintptr) {
  39048 	var enc, mem, v3 uintptr
  39049 	var info_size, lf_stats_size, nz_size, preds_size, samples_size, top_derr_size size_t
  39050 	var mb_h, mb_w, preds_h, preds_w, top_stride, use_filter, v5, v6 int32
  39051 	var scale float32
  39052 	var size uint64_t
  39053 	var v1, v2 uint64
  39054 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  39055 	use_filter = libc.BoolInt32((*WebPConfig)(unsafe.Pointer(config)).Ffilter_strength > 0 || (*WebPConfig)(unsafe.Pointer(config)).Fautofilter > 0)
  39056 	mb_w = ((*WebPPicture)(unsafe.Pointer(picture)).Fwidth + int32(15)) >> int32(4)
  39057 	mb_h = ((*WebPPicture)(unsafe.Pointer(picture)).Fheight + int32(15)) >> int32(4)
  39058 	preds_w = int32(4)*mb_w + int32(1)
  39059 	preds_h = int32(4)*mb_h + int32(1)
  39060 	preds_size = uint64(preds_w*preds_h) * uint64(1)
  39061 	top_stride = mb_w * int32(16)
  39062 	nz_size = uint64(mb_w+libc.Int32FromInt32(1))*uint64(4) + uint64(WEBP_ALIGN_CST)
  39063 	info_size = uint64(mb_w*mb_h) * uint64(4)
  39064 	samples_size = uint64(int32(2)*top_stride)*uint64(1) + uint64(WEBP_ALIGN_CST)
  39065 	if (*WebPConfig)(unsafe.Pointer(config)).Fautofilter != 0 {
  39066 		v1 = libc.Uint64FromInt64(2048) + libc.Uint64FromInt32(WEBP_ALIGN_CST)
  39067 	} else {
  39068 		v1 = uint64(0)
  39069 	} // align all
  39070 	lf_stats_size = v1
  39071 	if (*WebPConfig)(unsafe.Pointer(config)).Fquality <= libc.Float32FromInt32(ERROR_DIFFUSION_QUALITY) || (*WebPConfig)(unsafe.Pointer(config)).Fpass > int32(1) {
  39072 		v2 = uint64(mb_w) * uint64(4)
  39073 	} else {
  39074 		v2 = uint64(0)
  39075 	}
  39076 	top_derr_size = v2
  39077 	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
  39078 	mem = WebPSafeMalloc(tls, size, uint64(1))
  39079 	if mem == libc.UintptrFromInt32(0) {
  39080 		WebPEncodingSetError(tls, picture, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  39081 		return libc.UintptrFromInt32(0)
  39082 	}
  39083 	enc = mem
  39084 	mem = uintptr((uint64(mem+libc.UintptrFromInt64(23704)) + libc.Uint64FromInt32(WEBP_ALIGN_CST)) & ^libc.Uint64FromInt32(WEBP_ALIGN_CST))
  39085 	libc.Xmemset(tls, enc, 0, uint64(23704))
  39086 	(*VP8Encoder)(unsafe.Pointer(enc)).Fnum_parts = int32(1) << (*WebPConfig)(unsafe.Pointer(config)).Fpartitions
  39087 	(*VP8Encoder)(unsafe.Pointer(enc)).Fmb_w = mb_w
  39088 	(*VP8Encoder)(unsafe.Pointer(enc)).Fmb_h = mb_h
  39089 	(*VP8Encoder)(unsafe.Pointer(enc)).Fpreds_w = preds_w
  39090 	(*VP8Encoder)(unsafe.Pointer(enc)).Fmb_info = mem
  39091 	mem = mem + uintptr(info_size)
  39092 	(*VP8Encoder)(unsafe.Pointer(enc)).Fpreds = mem + uintptr(1) + uintptr((*VP8Encoder)(unsafe.Pointer(enc)).Fpreds_w)
  39093 	mem = mem + uintptr(preds_size)
  39094 	(*VP8Encoder)(unsafe.Pointer(enc)).Fnz = uintptr(1)*4 + uintptr((uint64(mem)+libc.Uint64FromInt32(WEBP_ALIGN_CST)) & ^libc.Uint64FromInt32(WEBP_ALIGN_CST))
  39095 	mem = mem + uintptr(nz_size)
  39096 	if lf_stats_size != 0 {
  39097 		v3 = uintptr((uint64(mem) + libc.Uint64FromInt32(WEBP_ALIGN_CST)) & ^libc.Uint64FromInt32(WEBP_ALIGN_CST))
  39098 	} else {
  39099 		v3 = libc.UintptrFromInt32(0)
  39100 	}
  39101 	(*VP8Encoder)(unsafe.Pointer(enc)).Flf_stats = v3
  39102 	mem = mem + uintptr(lf_stats_size)
  39103 	// top samples (all 16-aligned)
  39104 	mem = uintptr((uint64(mem) + libc.Uint64FromInt32(WEBP_ALIGN_CST)) & ^libc.Uint64FromInt32(WEBP_ALIGN_CST))
  39105 	(*VP8Encoder)(unsafe.Pointer(enc)).Fy_top = mem
  39106 	(*VP8Encoder)(unsafe.Pointer(enc)).Fuv_top = (*VP8Encoder)(unsafe.Pointer(enc)).Fy_top + uintptr(top_stride)
  39107 	mem = mem + uintptr(int32(2)*top_stride)
  39108 	if top_derr_size != 0 {
  39109 		v3 = mem
  39110 	} else {
  39111 		v3 = libc.UintptrFromInt32(0)
  39112 	}
  39113 	(*VP8Encoder)(unsafe.Pointer(enc)).Ftop_derr = v3
  39114 	mem = mem + uintptr(top_derr_size)
  39115 	(*VP8Encoder)(unsafe.Pointer(enc)).Fconfig = config
  39116 	if use_filter != 0 {
  39117 		if (*WebPConfig)(unsafe.Pointer(config)).Ffilter_type == int32(1) {
  39118 			v6 = 0
  39119 		} else {
  39120 			v6 = int32(1)
  39121 		}
  39122 		v5 = v6
  39123 	} else {
  39124 		v5 = int32(2)
  39125 	}
  39126 	(*VP8Encoder)(unsafe.Pointer(enc)).Fprofile = v5
  39127 	(*VP8Encoder)(unsafe.Pointer(enc)).Fpic = picture
  39128 	(*VP8Encoder)(unsafe.Pointer(enc)).Fpercent = 0
  39129 	MapConfigToTools(tls, enc)
  39130 	VP8EncDspInit(tls)
  39131 	VP8DefaultProbas(tls, enc)
  39132 	ResetSegmentHeader1(tls, enc)
  39133 	ResetFilterHeader(tls, enc)
  39134 	ResetBoundaryPredictions(tls, enc)
  39135 	VP8EncDspCostInit(tls)
  39136 	VP8EncInitAlpha(tls, enc)
  39137 	// lower quality means smaller output -> we modulate a little the page
  39138 	// size based on quality. This is just a crude 1rst-order prediction.
  39139 	scale = libc.Float32FromFloat32(1) + float32((*WebPConfig)(unsafe.Pointer(config)).Fquality*libc.Float32FromFloat32(5))/libc.Float32FromFloat32(100) // in [1,6]
  39140 	VP8TBufferInit(tls, enc+496, int32(float32(float32(mb_w*mb_h*libc.Int32FromInt32(4))*scale)))
  39141 	return enc
  39142 }
  39143 
  39144 func DeleteVP8Encoder(tls *libc.TLS, enc uintptr) (r int32) {
  39145 	var ok int32
  39146 	_ = ok
  39147 	ok = int32(1)
  39148 	if enc != libc.UintptrFromInt32(0) {
  39149 		ok = VP8EncDeleteAlpha(tls, enc)
  39150 		VP8TBufferClear(tls, enc+496)
  39151 		WebPSafeFree(tls, enc)
  39152 	}
  39153 	return ok
  39154 }
  39155 
  39156 //------------------------------------------------------------------------------
  39157 
  39158 func GetPSNR2(tls *libc.TLS, err uint64_t, size uint64_t) (r float64) {
  39159 	var v1 float64
  39160 	_ = v1
  39161 	if err > uint64(0) && size > uint64(0) {
  39162 		v1 = float64(float64(10) * libc.Xlog10(tls, float64(float64(libc.Float64FromFloat64(255)*libc.Float64FromFloat64(255))*float64(size))/float64(err)))
  39163 	} else {
  39164 		v1 = float64(99)
  39165 	}
  39166 	return v1
  39167 }
  39168 
  39169 func FinalizePSNR(tls *libc.TLS, enc uintptr) {
  39170 	var size uint64_t
  39171 	var sse, stats uintptr
  39172 	_, _, _ = size, sse, stats
  39173 	stats = (*WebPPicture)(unsafe.Pointer((*VP8Encoder)(unsafe.Pointer(enc)).Fpic)).Fstats
  39174 	size = (*VP8Encoder)(unsafe.Pointer(enc)).Fsse_count
  39175 	sse = enc + 23512
  39176 	**(**float32)(__ccgo_up(stats + 4)) = float32(GetPSNR2(tls, **(**uint64_t)(__ccgo_up(sse)), size))
  39177 	**(**float32)(__ccgo_up(stats + 4 + 1*4)) = float32(GetPSNR2(tls, **(**uint64_t)(__ccgo_up(sse + 1*8)), size/uint64(4)))
  39178 	**(**float32)(__ccgo_up(stats + 4 + 2*4)) = float32(GetPSNR2(tls, **(**uint64_t)(__ccgo_up(sse + 2*8)), size/uint64(4)))
  39179 	**(**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)))
  39180 	**(**float32)(__ccgo_up(stats + 4 + 4*4)) = float32(GetPSNR2(tls, **(**uint64_t)(__ccgo_up(sse + 3*8)), size))
  39181 }
  39182 
  39183 func StoreStats(tls *libc.TLS, enc uintptr) {
  39184 	var i, s int32
  39185 	var stats uintptr
  39186 	_, _, _ = i, s, stats
  39187 	stats = (*WebPPicture)(unsafe.Pointer((*VP8Encoder)(unsafe.Pointer(enc)).Fpic)).Fstats
  39188 	if stats != libc.UintptrFromInt32(0) {
  39189 		i = 0
  39190 		for {
  39191 			if !(i < int32(NUM_MB_SEGMENTS)) {
  39192 				break
  39193 			}
  39194 			**(**int32)(__ccgo_up(stats + 124 + uintptr(i)*4)) = (**(**VP8SegmentInfo)(__ccgo_up(enc + 608 + uintptr(i)*744))).Ffstrength
  39195 			**(**int32)(__ccgo_up(stats + 108 + uintptr(i)*4)) = (**(**VP8SegmentInfo)(__ccgo_up(enc + 608 + uintptr(i)*744))).Fquant
  39196 			s = 0
  39197 			for {
  39198 				if !(s <= int32(2)) {
  39199 					break
  39200 				}
  39201 				**(**int32)(__ccgo_up(stats + 44 + uintptr(s)*16 + uintptr(i)*4)) = **(**int32)(__ccgo_up(enc + 23556 + uintptr(s)*16 + uintptr(i)*4))
  39202 				goto _2
  39203 			_2:
  39204 				;
  39205 				s = s + 1
  39206 			}
  39207 			goto _1
  39208 		_1:
  39209 			;
  39210 			i = i + 1
  39211 		}
  39212 		FinalizePSNR(tls, enc)
  39213 		(*WebPAuxStats)(unsafe.Pointer(stats)).Fcoded_size = (*VP8Encoder)(unsafe.Pointer(enc)).Fcoded_size
  39214 		i = 0
  39215 		for {
  39216 			if !(i < int32(3)) {
  39217 				break
  39218 			}
  39219 			**(**int32)(__ccgo_up(stats + 24 + uintptr(i)*4)) = **(**int32)(__ccgo_up(enc + 23604 + uintptr(i)*4))
  39220 			goto _3
  39221 		_3:
  39222 			;
  39223 			i = i + 1
  39224 		}
  39225 	}
  39226 }
  39227 
  39228 func WebPEncodingSetError(tls *libc.TLS, pic uintptr, error1 WebPEncodingError1) (r int32) {
  39229 	// The oldest error reported takes precedence over the new one.
  39230 	if (*WebPPicture)(unsafe.Pointer(pic)).Ferror_code == int32(VP8_ENC_OK) {
  39231 		(*WebPPicture)(unsafe.Pointer(pic)).Ferror_code = error1
  39232 	}
  39233 	return 0
  39234 }
  39235 
  39236 func WebPReportProgress(tls *libc.TLS, pic uintptr, percent int32, percent_store uintptr) (r int32) {
  39237 	if percent_store != libc.UintptrFromInt32(0) && percent != **(**int32)(__ccgo_up(percent_store)) {
  39238 		**(**int32)(__ccgo_up(percent_store)) = percent
  39239 		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) {
  39240 			// user abort requested
  39241 			return WebPEncodingSetError(tls, pic, int32(VP8_ENC_ERROR_USER_ABORT))
  39242 		}
  39243 	}
  39244 	return int32(1) // ok
  39245 }
  39246 
  39247 //------------------------------------------------------------------------------
  39248 
  39249 func WebPEncode(tls *libc.TLS, config uintptr, pic uintptr) (r int32) {
  39250 	var dithering, x, x2 float32
  39251 	var enc uintptr
  39252 	var ok int32
  39253 	_, _, _, _, _ = dithering, enc, ok, x, x2
  39254 	ok = 0
  39255 	if pic == libc.UintptrFromInt32(0) {
  39256 		return 0
  39257 	}
  39258 	(*WebPPicture)(unsafe.Pointer(pic)).Ferror_code = int32(VP8_ENC_OK) // all ok so far
  39259 	if config == libc.UintptrFromInt32(0) {                             // bad params
  39260 		return WebPEncodingSetError(tls, pic, int32(VP8_ENC_ERROR_NULL_PARAMETER))
  39261 	}
  39262 	if !(WebPValidateConfig(tls, config) != 0) {
  39263 		return WebPEncodingSetError(tls, pic, int32(VP8_ENC_ERROR_INVALID_CONFIGURATION))
  39264 	}
  39265 	if !(WebPValidatePicture(tls, pic) != 0) {
  39266 		return 0
  39267 	}
  39268 	if (*WebPPicture)(unsafe.Pointer(pic)).Fwidth > int32(WEBP_MAX_DIMENSION) || (*WebPPicture)(unsafe.Pointer(pic)).Fheight > int32(WEBP_MAX_DIMENSION) {
  39269 		return WebPEncodingSetError(tls, pic, int32(VP8_ENC_ERROR_BAD_DIMENSION))
  39270 	}
  39271 	if (*WebPPicture)(unsafe.Pointer(pic)).Fstats != libc.UintptrFromInt32(0) {
  39272 		libc.Xmemset(tls, (*WebPPicture)(unsafe.Pointer(pic)).Fstats, 0, uint64(188))
  39273 	}
  39274 	if !((*WebPConfig)(unsafe.Pointer(config)).Flossless != 0) {
  39275 		enc = libc.UintptrFromInt32(0)
  39276 		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) {
  39277 			// Make sure we have YUVA samples.
  39278 			if (*WebPConfig)(unsafe.Pointer(config)).Fuse_sharp_yuv != 0 || (*WebPConfig)(unsafe.Pointer(config)).Fpreprocessing&int32(4) != 0 {
  39279 				if !(WebPPictureSharpARGBToYUVA(tls, pic) != 0) {
  39280 					return 0
  39281 				}
  39282 			} else {
  39283 				dithering = libc.Float32FromFloat32(0)
  39284 				if (*WebPConfig)(unsafe.Pointer(config)).Fpreprocessing&int32(2) != 0 {
  39285 					x = (*WebPConfig)(unsafe.Pointer(config)).Fquality / libc.Float32FromFloat32(100)
  39286 					x2 = float32(x * x)
  39287 					// slowly decreasing from max dithering at low quality (q->0)
  39288 					// to 0.5 dithering amplitude at high quality (q->100)
  39289 					dithering = libc.Float32FromFloat32(1) + float32(float32((libc.Float32FromFloat32(0.5)-libc.Float32FromFloat32(1))*x2)*x2)
  39290 				}
  39291 				if !(WebPPictureARGBToYUVADithered(tls, pic, int32(WEBP_YUV420), dithering) != 0) {
  39292 					return 0
  39293 				}
  39294 			}
  39295 		}
  39296 		if !((*WebPConfig)(unsafe.Pointer(config)).Fexact != 0) {
  39297 			WebPCleanupTransparentArea(tls, pic)
  39298 		}
  39299 		enc = InitVP8Encoder(tls, config, pic)
  39300 		if enc == libc.UintptrFromInt32(0) {
  39301 			return 0
  39302 		} // pic->error is already set.
  39303 		// Note: each of the tasks below account for 20% in the progress report.
  39304 		ok = VP8EncAnalyze(tls, enc)
  39305 		// Analysis is done, proceed to actual coding.
  39306 		ok = libc.BoolInt32(ok != 0 && VP8EncStartAlpha(tls, enc) != 0) // possibly done in parallel
  39307 		if !((*VP8Encoder)(unsafe.Pointer(enc)).Fuse_tokens != 0) {
  39308 			ok = libc.BoolInt32(ok != 0 && VP8EncLoop(tls, enc) != 0)
  39309 		} else {
  39310 			ok = libc.BoolInt32(ok != 0 && VP8EncTokenLoop(tls, enc) != 0)
  39311 		}
  39312 		ok = libc.BoolInt32(ok != 0 && VP8EncFinishAlpha(tls, enc) != 0)
  39313 		ok = libc.BoolInt32(ok != 0 && VP8EncWrite(tls, enc) != 0)
  39314 		StoreStats(tls, enc)
  39315 		if !(ok != 0) {
  39316 			VP8EncFreeBitWriters(tls, enc)
  39317 		}
  39318 		ok = ok & DeleteVP8Encoder(tls, enc) // must always be called, even if !ok
  39319 	} else {
  39320 		// Make sure we have ARGB samples.
  39321 		if (*WebPPicture)(unsafe.Pointer(pic)).Fargb == libc.UintptrFromInt32(0) && !(WebPPictureYUVAToARGB(tls, pic) != 0) {
  39322 			return 0
  39323 		}
  39324 		if !((*WebPConfig)(unsafe.Pointer(config)).Fexact != 0) {
  39325 			WebPReplaceTransparentPixels(tls, pic, uint32(0x000000))
  39326 		}
  39327 		ok = VP8LEncodeImage(tls, config, pic) // Sets pic->error in case of problem.
  39328 	}
  39329 	return ok
  39330 }
  39331 
  39332 const SIZE_MAX17 = "UINT64_MAX"
  39333 const VP8L_LOG8_WBITS = 4
  39334 
  39335 // Copyright 2010 Google Inc. All Rights Reserved.
  39336 //
  39337 // Use of this source code is governed by a BSD-style license
  39338 // that can be found in the COPYING file in the root of the source
  39339 // tree. An additional intellectual property rights grant can be found
  39340 // in the file PATENTS. All contributing project authors may
  39341 // be found in the AUTHORS file in the root of the source tree.
  39342 // -----------------------------------------------------------------------------
  39343 //
  39344 // Boolean decoder
  39345 //
  39346 // Author: Skal (pascal.massimino@gmail.com)
  39347 //         Vikas Arora (vikaas.arora@gmail.com)
  39348 
  39349 // Copyright 2014 Google Inc. All Rights Reserved.
  39350 //
  39351 // Use of this source code is governed by a BSD-style license
  39352 // that can be found in the COPYING file in the root of the source
  39353 // tree. An additional intellectual property rights grant can be found
  39354 // in the file PATENTS. All contributing project authors may
  39355 // be found in the AUTHORS file in the root of the source tree.
  39356 // -----------------------------------------------------------------------------
  39357 //
  39358 // Endian related functions.
  39359 
  39360 // Copyright 2012 Google Inc. All Rights Reserved.
  39361 //
  39362 // Use of this source code is governed by a BSD-style license
  39363 // that can be found in the COPYING file in the root of the source
  39364 // tree. An additional intellectual property rights grant can be found
  39365 // in the file PATENTS. All contributing project authors may
  39366 // be found in the AUTHORS file in the root of the source tree.
  39367 // -----------------------------------------------------------------------------
  39368 //
  39369 // Misc. common utility functions
  39370 //
  39371 // Authors: Skal (pascal.massimino@gmail.com)
  39372 //          Urvang (urvang@google.com)
  39373 
  39374 //------------------------------------------------------------------------------
  39375 // VP8BitReader
  39376 
  39377 func VP8BitReaderSetBuffer(tls *libc.TLS, br uintptr, start uintptr, size size_t) {
  39378 	var v1 uintptr
  39379 	_ = v1
  39380 	(*VP8BitReader)(unsafe.Pointer(br)).Fbuf = start
  39381 	(*VP8BitReader)(unsafe.Pointer(br)).Fbuf_end = start + uintptr(size)
  39382 	if size >= uint64(8) {
  39383 		v1 = start + uintptr(size) - uintptr(8) + uintptr(1)
  39384 	} else {
  39385 		v1 = start
  39386 	}
  39387 	(*VP8BitReader)(unsafe.Pointer(br)).Fbuf_max = v1
  39388 }
  39389 
  39390 func VP8InitBitReader(tls *libc.TLS, br1 uintptr, start uintptr, size size_t) {
  39391 	bp := tls.Alloc(16)
  39392 	defer tls.Free(16)
  39393 	var bits bit_t
  39394 	var v1 uintptr
  39395 	var v2 uint64_t
  39396 	var _ /* in_bits at bp+0 */ lbit_t
  39397 	_, _, _ = bits, v1, v2
  39398 	// limit ensured by format and upstream checks
  39399 	(*VP8BitReader)(unsafe.Pointer(br1)).Frange1 = uint32(libc.Int32FromInt32(255) - libc.Int32FromInt32(1))
  39400 	(*VP8BitReader)(unsafe.Pointer(br1)).Fvalue = uint64(0)
  39401 	(*VP8BitReader)(unsafe.Pointer(br1)).Fbits = -int32(8) // to load the very first 8bits
  39402 	(*VP8BitReader)(unsafe.Pointer(br1)).Feof = 0
  39403 	VP8BitReaderSetBuffer(tls, br1, start, size)
  39404 	v1 = br1
  39405 	if (*VP8BitReader)(unsafe.Pointer(v1)).Fbuf < (*VP8BitReader)(unsafe.Pointer(v1)).Fbuf_max {
  39406 		libc.Xmemcpy(tls, bp, (*VP8BitReader)(unsafe.Pointer(v1)).Fbuf, uint64(8))
  39407 		**(**uintptr)(__ccgo_up(v1 + 16)) += uintptr(libc.Int32FromInt32(BITS) >> libc.Int32FromInt32(3))
  39408 		v2 = libc.X__builtin_bswap64(tls, **(**lbit_t)(__ccgo_up(bp)))
  39409 		goto _3
  39410 	_3:
  39411 		bits = v2
  39412 		bits = bits >> uint64(libc.Int32FromInt32(64)-libc.Int32FromInt32(BITS))
  39413 		(*VP8BitReader)(unsafe.Pointer(v1)).Fvalue = bits | (*VP8BitReader)(unsafe.Pointer(v1)).Fvalue<<libc.Int32FromInt32(BITS)
  39414 		**(**int32)(__ccgo_up(v1 + 12)) += int32(BITS)
  39415 	} else {
  39416 		VP8LoadFinalBytes(tls, v1)
  39417 	}
  39418 }
  39419 
  39420 func VP8RemapBitReader(tls *libc.TLS, br uintptr, offset ptrdiff_t) {
  39421 	if (*VP8BitReader)(unsafe.Pointer(br)).Fbuf != libc.UintptrFromInt32(0) {
  39422 		**(**uintptr)(__ccgo_up(br + 16)) += uintptr(offset)
  39423 		**(**uintptr)(__ccgo_up(br + 24)) += uintptr(offset)
  39424 		**(**uintptr)(__ccgo_up(br + 32)) += uintptr(offset)
  39425 	}
  39426 }
  39427 
  39428 func VP8LoadFinalBytes(tls *libc.TLS, br uintptr) {
  39429 	var v1, v2 uintptr
  39430 	_, _ = v1, v2
  39431 	// Only read 8bits at a time
  39432 	if (*VP8BitReader)(unsafe.Pointer(br)).Fbuf < (*VP8BitReader)(unsafe.Pointer(br)).Fbuf_end {
  39433 		**(**int32)(__ccgo_up(br + 12)) += int32(8)
  39434 		v2 = br + 16
  39435 		v1 = *(*uintptr)(unsafe.Pointer(v2))
  39436 		*(*uintptr)(unsafe.Pointer(v2)) = *(*uintptr)(unsafe.Pointer(v2)) + 1
  39437 		(*VP8BitReader)(unsafe.Pointer(br)).Fvalue = uint64(**(**uint8_t)(__ccgo_up(v1))) | (*VP8BitReader)(unsafe.Pointer(br)).Fvalue<<libc.Int32FromInt32(8)
  39438 	} else {
  39439 		if !((*VP8BitReader)(unsafe.Pointer(br)).Feof != 0) {
  39440 			**(**bit_t)(__ccgo_up(br)) <<= uint64(8)
  39441 			**(**int32)(__ccgo_up(br + 12)) += int32(8)
  39442 			(*VP8BitReader)(unsafe.Pointer(br)).Feof = int32(1)
  39443 		} else {
  39444 			(*VP8BitReader)(unsafe.Pointer(br)).Fbits = 0 // This is to avoid undefined behaviour with shifts.
  39445 		}
  39446 	}
  39447 }
  39448 
  39449 //------------------------------------------------------------------------------
  39450 // Higher-level calls
  39451 
  39452 func VP8GetValue(tls *libc.TLS, br2 uintptr, bits1 int32) (r uint32_t) {
  39453 	bp := tls.Alloc(16)
  39454 	defer tls.Free(16)
  39455 	var bit, pos, shift, v1, v6, v8 int32
  39456 	var bits bit_t
  39457 	var range1, split, value range_t
  39458 	var v uint32_t
  39459 	var v2, v3 uintptr
  39460 	var v4 uint64_t
  39461 	var _ /* in_bits at bp+0 */ lbit_t
  39462 	_, _, _, _, _, _, _, _, _, _, _, _, _, _ = bit, bits, pos, range1, shift, split, v, value, v1, v2, v3, v4, v6, v8
  39463 	v = uint32(0)
  39464 	for {
  39465 		v1 = bits1
  39466 		bits1 = bits1 - 1
  39467 		if !(v1 > 0) {
  39468 			break
  39469 		}
  39470 		v2 = br2
  39471 		range1 = (*VP8BitReader)(unsafe.Pointer(v2)).Frange1
  39472 		if (*VP8BitReader)(unsafe.Pointer(v2)).Fbits < libc.Int32FromInt32(0) {
  39473 			v3 = v2
  39474 			if (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf < (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf_max {
  39475 				libc.Xmemcpy(tls, bp, (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf, uint64(8))
  39476 				**(**uintptr)(__ccgo_up(v3 + 16)) += uintptr(libc.Int32FromInt32(BITS) >> libc.Int32FromInt32(3))
  39477 				v4 = libc.X__builtin_bswap64(tls, **(**lbit_t)(__ccgo_up(bp)))
  39478 				goto _5
  39479 			_5:
  39480 				bits = v4
  39481 				bits = bits >> uint64(libc.Int32FromInt32(64)-libc.Int32FromInt32(BITS))
  39482 				(*VP8BitReader)(unsafe.Pointer(v3)).Fvalue = bits | (*VP8BitReader)(unsafe.Pointer(v3)).Fvalue<<libc.Int32FromInt32(BITS)
  39483 				**(**int32)(__ccgo_up(v3 + 12)) += int32(BITS)
  39484 			} else {
  39485 				VP8LoadFinalBytes(tls, v3)
  39486 			}
  39487 		}
  39488 		pos = (*VP8BitReader)(unsafe.Pointer(v2)).Fbits
  39489 		split = range1 * uint32(int32(0x80)) >> int32(8)
  39490 		value = uint32((*VP8BitReader)(unsafe.Pointer(v2)).Fvalue >> pos)
  39491 		bit = libc.BoolInt32(value > split)
  39492 		if bit != 0 {
  39493 			range1 = range1 - split
  39494 			**(**bit_t)(__ccgo_up(v2)) -= uint64(split+libc.Uint32FromInt32(1)) << pos
  39495 		} else {
  39496 			range1 = split + uint32(1)
  39497 		}
  39498 		v6 = int32(31) ^ libc.X__builtin_clz(tls, range1)
  39499 		goto _7
  39500 	_7:
  39501 		shift = int32(7) ^ v6
  39502 		range1 = range1 << uint32(shift)
  39503 		**(**int32)(__ccgo_up(v2 + 12)) -= shift
  39504 		(*VP8BitReader)(unsafe.Pointer(v2)).Frange1 = range1 - uint32(1)
  39505 		v8 = bit
  39506 		goto _9
  39507 	_9:
  39508 		v = v | uint32(v8<<bits1)
  39509 	}
  39510 	return v
  39511 }
  39512 
  39513 func VP8GetSignedValue(tls *libc.TLS, br uintptr, bits int32) (r int32_t) {
  39514 	var value, v1 int32
  39515 	_, _ = value, v1
  39516 	value = int32(VP8GetValue(tls, br, bits))
  39517 	if VP8GetValue(tls, br, int32(1)) != 0 {
  39518 		v1 = -value
  39519 	} else {
  39520 		v1 = value
  39521 	}
  39522 	return v1
  39523 }
  39524 
  39525 //------------------------------------------------------------------------------
  39526 // VP8LBitReader
  39527 
  39528 var kBitMask = [25]uint32_t{
  39529 	1:  uint32(0x000001),
  39530 	2:  uint32(0x000003),
  39531 	3:  uint32(0x000007),
  39532 	4:  uint32(0x00000f),
  39533 	5:  uint32(0x00001f),
  39534 	6:  uint32(0x00003f),
  39535 	7:  uint32(0x00007f),
  39536 	8:  uint32(0x0000ff),
  39537 	9:  uint32(0x0001ff),
  39538 	10: uint32(0x0003ff),
  39539 	11: uint32(0x0007ff),
  39540 	12: uint32(0x000fff),
  39541 	13: uint32(0x001fff),
  39542 	14: uint32(0x003fff),
  39543 	15: uint32(0x007fff),
  39544 	16: uint32(0x00ffff),
  39545 	17: uint32(0x01ffff),
  39546 	18: uint32(0x03ffff),
  39547 	19: uint32(0x07ffff),
  39548 	20: uint32(0x0fffff),
  39549 	21: uint32(0x1fffff),
  39550 	22: uint32(0x3fffff),
  39551 	23: uint32(0x7fffff),
  39552 	24: uint32(0xffffff),
  39553 }
  39554 
  39555 func VP8LInitBitReader(tls *libc.TLS, br uintptr, start uintptr, length size_t) {
  39556 	var i size_t
  39557 	var value vp8l_val_t
  39558 	_, _ = i, value
  39559 	value = uint64(0)
  39560 	// can't happen with a RIFF chunk.
  39561 	(*VP8LBitReader)(unsafe.Pointer(br)).Flen1 = length
  39562 	(*VP8LBitReader)(unsafe.Pointer(br)).Fval = uint64(0)
  39563 	(*VP8LBitReader)(unsafe.Pointer(br)).Fbit_pos = 0
  39564 	(*VP8LBitReader)(unsafe.Pointer(br)).Feos = 0
  39565 	if length > uint64(8) {
  39566 		length = uint64(8)
  39567 	}
  39568 	i = uint64(0)
  39569 	for {
  39570 		if !(i < length) {
  39571 			break
  39572 		}
  39573 		value = value | uint64(**(**uint8_t)(__ccgo_up(start + uintptr(i))))<<(uint64(8)*i)
  39574 		goto _1
  39575 	_1:
  39576 		;
  39577 		i = i + 1
  39578 	}
  39579 	(*VP8LBitReader)(unsafe.Pointer(br)).Fval = value
  39580 	(*VP8LBitReader)(unsafe.Pointer(br)).Fpos = length
  39581 	(*VP8LBitReader)(unsafe.Pointer(br)).Fbuf = start
  39582 }
  39583 
  39584 func VP8LBitReaderSetBuffer(tls *libc.TLS, br1 uintptr, buf uintptr, len1 size_t) {
  39585 	var v1 uintptr
  39586 	var v2 int32
  39587 	var v4 bool
  39588 	_, _, _ = v1, v2, v4
  39589 	// can't happen with a RIFF chunk.
  39590 	(*VP8LBitReader)(unsafe.Pointer(br1)).Fbuf = buf
  39591 	(*VP8LBitReader)(unsafe.Pointer(br1)).Flen1 = len1
  39592 	// 'pos' > 'len' should be considered a param error.
  39593 	if v4 = (*VP8LBitReader)(unsafe.Pointer(br1)).Fpos > (*VP8LBitReader)(unsafe.Pointer(br1)).Flen1; !v4 {
  39594 		v1 = br1
  39595 		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))
  39596 		goto _3
  39597 	_3:
  39598 	}
  39599 	(*VP8LBitReader)(unsafe.Pointer(br1)).Feos = libc.BoolInt32(v4 || v2 != 0)
  39600 }
  39601 
  39602 func VP8LSetEndOfStream(tls *libc.TLS, br uintptr) {
  39603 	(*VP8LBitReader)(unsafe.Pointer(br)).Feos = int32(1)
  39604 	(*VP8LBitReader)(unsafe.Pointer(br)).Fbit_pos = 0 // To avoid undefined behaviour with shifts.
  39605 }
  39606 
  39607 // C documentation
  39608 //
  39609 //	// If not at EOS, reload up to VP8L_LBITS byte-by-byte
  39610 func ShiftBytes(tls *libc.TLS, br1 uintptr) {
  39611 	var v1 uintptr
  39612 	var v2 int32
  39613 	_, _ = v1, v2
  39614 	for (*VP8LBitReader)(unsafe.Pointer(br1)).Fbit_pos >= int32(8) && (*VP8LBitReader)(unsafe.Pointer(br1)).Fpos < (*VP8LBitReader)(unsafe.Pointer(br1)).Flen1 {
  39615 		**(**vp8l_val_t)(__ccgo_up(br1)) >>= uint64(8)
  39616 		**(**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))
  39617 		(*VP8LBitReader)(unsafe.Pointer(br1)).Fpos = (*VP8LBitReader)(unsafe.Pointer(br1)).Fpos + 1
  39618 		**(**int32)(__ccgo_up(br1 + 32)) -= int32(8)
  39619 	}
  39620 	v1 = br1
  39621 	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))
  39622 	goto _3
  39623 _3:
  39624 	if v2 != 0 {
  39625 		VP8LSetEndOfStream(tls, br1)
  39626 	}
  39627 }
  39628 
  39629 func VP8LDoFillBitWindow(tls *libc.TLS, br uintptr) {
  39630 	bp := tls.Alloc(16)
  39631 	defer tls.Free(16)
  39632 	var v1 uint32_t
  39633 	var _ /* A at bp+0 */ uint32_t
  39634 	_ = v1
  39635 	if (*VP8LBitReader)(unsafe.Pointer(br)).Fpos+uint64(8) < (*VP8LBitReader)(unsafe.Pointer(br)).Flen1 {
  39636 		**(**vp8l_val_t)(__ccgo_up(br)) >>= uint64(VP8L_WBITS)
  39637 		**(**int32)(__ccgo_up(br + 32)) -= int32(VP8L_WBITS)
  39638 		libc.Xmemcpy(tls, bp, (*VP8LBitReader)(unsafe.Pointer(br)).Fbuf+uintptr((*VP8LBitReader)(unsafe.Pointer(br)).Fpos), uint64(4))
  39639 		v1 = **(**uint32_t)(__ccgo_up(bp))
  39640 		goto _2
  39641 	_2:
  39642 		**(**vp8l_val_t)(__ccgo_up(br)) |= uint64(v1) << (libc.Int32FromInt32(VP8L_LBITS) - libc.Int32FromInt32(VP8L_WBITS))
  39643 		**(**size_t)(__ccgo_up(br + 24)) += uint64(VP8L_LOG8_WBITS)
  39644 		return
  39645 	}
  39646 	ShiftBytes(tls, br) // Slow path.
  39647 }
  39648 
  39649 func VP8LReadBits(tls *libc.TLS, br1 uintptr, n_bits int32) (r uint32_t) {
  39650 	var new_bits int32
  39651 	var val, v2 uint32_t
  39652 	var v1 uintptr
  39653 	_, _, _, _ = new_bits, val, v1, v2
  39654 	// Flag an error if end_of_stream or n_bits is more than allowed limit.
  39655 	if !((*VP8LBitReader)(unsafe.Pointer(br1)).Feos != 0) && n_bits <= int32(VP8L_MAX_NUM_BIT_READ) {
  39656 		v1 = br1
  39657 		v2 = uint32((*VP8LBitReader)(unsafe.Pointer(v1)).Fval >> ((*VP8LBitReader)(unsafe.Pointer(v1)).Fbit_pos & (libc.Int32FromInt32(VP8L_LBITS) - libc.Int32FromInt32(1))))
  39658 		goto _3
  39659 	_3:
  39660 		val = v2 & kBitMask[n_bits]
  39661 		new_bits = (*VP8LBitReader)(unsafe.Pointer(br1)).Fbit_pos + n_bits
  39662 		(*VP8LBitReader)(unsafe.Pointer(br1)).Fbit_pos = new_bits
  39663 		ShiftBytes(tls, br1)
  39664 		return val
  39665 	} else {
  39666 		VP8LSetEndOfStream(tls, br1)
  39667 		return uint32(0)
  39668 	}
  39669 	return r
  39670 }
  39671 
  39672 const MIN_EXTRA_SIZE = 32768
  39673 const SIZE_MAX18 = "_UI64_MAX"
  39674 
  39675 //------------------------------------------------------------------------------
  39676 
  39677 //------------------------------------------------------------------------------
  39678 // VP8BitWriter
  39679 
  39680 func BitWriterResize(tls *libc.TLS, bw uintptr, extra_size size_t) (r int32) {
  39681 	var needed_size, new_size size_t
  39682 	var needed_size_64b uint64_t
  39683 	var new_buf uintptr
  39684 	_, _, _, _ = needed_size, needed_size_64b, new_buf, new_size
  39685 	needed_size_64b = (*VP8BitWriter)(unsafe.Pointer(bw)).Fpos + extra_size
  39686 	needed_size = needed_size_64b
  39687 	if needed_size_64b != needed_size {
  39688 		(*VP8BitWriter)(unsafe.Pointer(bw)).Ferror1 = int32(1)
  39689 		return 0
  39690 	}
  39691 	if needed_size <= (*VP8BitWriter)(unsafe.Pointer(bw)).Fmax_pos {
  39692 		return int32(1)
  39693 	}
  39694 	// If the following line wraps over 32bit, the test just after will catch it.
  39695 	new_size = uint64(2) * (*VP8BitWriter)(unsafe.Pointer(bw)).Fmax_pos
  39696 	if new_size < needed_size {
  39697 		new_size = needed_size
  39698 	}
  39699 	if new_size < uint64(1024) {
  39700 		new_size = uint64(1024)
  39701 	}
  39702 	new_buf = WebPSafeMalloc(tls, uint64(1), new_size)
  39703 	if new_buf == libc.UintptrFromInt32(0) {
  39704 		(*VP8BitWriter)(unsafe.Pointer(bw)).Ferror1 = int32(1)
  39705 		return 0
  39706 	}
  39707 	if (*VP8BitWriter)(unsafe.Pointer(bw)).Fpos > uint64(0) {
  39708 		libc.Xmemcpy(tls, new_buf, (*VP8BitWriter)(unsafe.Pointer(bw)).Fbuf, (*VP8BitWriter)(unsafe.Pointer(bw)).Fpos)
  39709 	}
  39710 	WebPSafeFree(tls, (*VP8BitWriter)(unsafe.Pointer(bw)).Fbuf)
  39711 	(*VP8BitWriter)(unsafe.Pointer(bw)).Fbuf = new_buf
  39712 	(*VP8BitWriter)(unsafe.Pointer(bw)).Fmax_pos = new_size
  39713 	return int32(1)
  39714 }
  39715 
  39716 func Flush(tls *libc.TLS, bw uintptr) {
  39717 	var bits int32_t
  39718 	var pos, v3 size_t
  39719 	var s, value, v1 int32
  39720 	_, _, _, _, _, _ = bits, pos, s, value, v1, v3
  39721 	s = int32(8) + (*VP8BitWriter)(unsafe.Pointer(bw)).Fnb_bits
  39722 	bits = (*VP8BitWriter)(unsafe.Pointer(bw)).Fvalue >> s
  39723 	**(**int32_t)(__ccgo_up(bw + 4)) -= bits << s
  39724 	**(**int32)(__ccgo_up(bw + 12)) -= int32(8)
  39725 	if bits&int32(0xff) != int32(0xff) {
  39726 		pos = (*VP8BitWriter)(unsafe.Pointer(bw)).Fpos
  39727 		if !(BitWriterResize(tls, bw, uint64((*VP8BitWriter)(unsafe.Pointer(bw)).Frun+int32(1))) != 0) {
  39728 			return
  39729 		}
  39730 		if bits&int32(0x100) != 0 { // overflow -> propagate carry over pending 0xff's
  39731 			if pos > uint64(0) {
  39732 				**(**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
  39733 			}
  39734 		}
  39735 		if (*VP8BitWriter)(unsafe.Pointer(bw)).Frun > 0 {
  39736 			if bits&int32(0x100) != 0 {
  39737 				v1 = 0x00
  39738 			} else {
  39739 				v1 = int32(0xff)
  39740 			}
  39741 			value = v1
  39742 			for {
  39743 				if !((*VP8BitWriter)(unsafe.Pointer(bw)).Frun > 0) {
  39744 					break
  39745 				}
  39746 				v3 = pos
  39747 				pos = pos + 1
  39748 				**(**uint8_t)(__ccgo_up((*VP8BitWriter)(unsafe.Pointer(bw)).Fbuf + uintptr(v3))) = uint8(value)
  39749 				goto _2
  39750 			_2:
  39751 				;
  39752 				(*VP8BitWriter)(unsafe.Pointer(bw)).Frun = (*VP8BitWriter)(unsafe.Pointer(bw)).Frun - 1
  39753 			}
  39754 		}
  39755 		v3 = pos
  39756 		pos = pos + 1
  39757 		**(**uint8_t)(__ccgo_up((*VP8BitWriter)(unsafe.Pointer(bw)).Fbuf + uintptr(v3))) = uint8(bits & int32(0xff))
  39758 		(*VP8BitWriter)(unsafe.Pointer(bw)).Fpos = pos
  39759 	} else {
  39760 		(*VP8BitWriter)(unsafe.Pointer(bw)).Frun = (*VP8BitWriter)(unsafe.Pointer(bw)).Frun + 1 // delay writing of bytes 0xff, pending eventual carry.
  39761 	}
  39762 }
  39763 
  39764 //------------------------------------------------------------------------------
  39765 // renormalization
  39766 
  39767 var kNorm = [128]uint8_t{
  39768 	0:   uint8(7),
  39769 	1:   uint8(6),
  39770 	2:   uint8(6),
  39771 	3:   uint8(5),
  39772 	4:   uint8(5),
  39773 	5:   uint8(5),
  39774 	6:   uint8(5),
  39775 	7:   uint8(4),
  39776 	8:   uint8(4),
  39777 	9:   uint8(4),
  39778 	10:  uint8(4),
  39779 	11:  uint8(4),
  39780 	12:  uint8(4),
  39781 	13:  uint8(4),
  39782 	14:  uint8(4),
  39783 	15:  uint8(3),
  39784 	16:  uint8(3),
  39785 	17:  uint8(3),
  39786 	18:  uint8(3),
  39787 	19:  uint8(3),
  39788 	20:  uint8(3),
  39789 	21:  uint8(3),
  39790 	22:  uint8(3),
  39791 	23:  uint8(3),
  39792 	24:  uint8(3),
  39793 	25:  uint8(3),
  39794 	26:  uint8(3),
  39795 	27:  uint8(3),
  39796 	28:  uint8(3),
  39797 	29:  uint8(3),
  39798 	30:  uint8(3),
  39799 	31:  uint8(2),
  39800 	32:  uint8(2),
  39801 	33:  uint8(2),
  39802 	34:  uint8(2),
  39803 	35:  uint8(2),
  39804 	36:  uint8(2),
  39805 	37:  uint8(2),
  39806 	38:  uint8(2),
  39807 	39:  uint8(2),
  39808 	40:  uint8(2),
  39809 	41:  uint8(2),
  39810 	42:  uint8(2),
  39811 	43:  uint8(2),
  39812 	44:  uint8(2),
  39813 	45:  uint8(2),
  39814 	46:  uint8(2),
  39815 	47:  uint8(2),
  39816 	48:  uint8(2),
  39817 	49:  uint8(2),
  39818 	50:  uint8(2),
  39819 	51:  uint8(2),
  39820 	52:  uint8(2),
  39821 	53:  uint8(2),
  39822 	54:  uint8(2),
  39823 	55:  uint8(2),
  39824 	56:  uint8(2),
  39825 	57:  uint8(2),
  39826 	58:  uint8(2),
  39827 	59:  uint8(2),
  39828 	60:  uint8(2),
  39829 	61:  uint8(2),
  39830 	62:  uint8(2),
  39831 	63:  uint8(1),
  39832 	64:  uint8(1),
  39833 	65:  uint8(1),
  39834 	66:  uint8(1),
  39835 	67:  uint8(1),
  39836 	68:  uint8(1),
  39837 	69:  uint8(1),
  39838 	70:  uint8(1),
  39839 	71:  uint8(1),
  39840 	72:  uint8(1),
  39841 	73:  uint8(1),
  39842 	74:  uint8(1),
  39843 	75:  uint8(1),
  39844 	76:  uint8(1),
  39845 	77:  uint8(1),
  39846 	78:  uint8(1),
  39847 	79:  uint8(1),
  39848 	80:  uint8(1),
  39849 	81:  uint8(1),
  39850 	82:  uint8(1),
  39851 	83:  uint8(1),
  39852 	84:  uint8(1),
  39853 	85:  uint8(1),
  39854 	86:  uint8(1),
  39855 	87:  uint8(1),
  39856 	88:  uint8(1),
  39857 	89:  uint8(1),
  39858 	90:  uint8(1),
  39859 	91:  uint8(1),
  39860 	92:  uint8(1),
  39861 	93:  uint8(1),
  39862 	94:  uint8(1),
  39863 	95:  uint8(1),
  39864 	96:  uint8(1),
  39865 	97:  uint8(1),
  39866 	98:  uint8(1),
  39867 	99:  uint8(1),
  39868 	100: uint8(1),
  39869 	101: uint8(1),
  39870 	102: uint8(1),
  39871 	103: uint8(1),
  39872 	104: uint8(1),
  39873 	105: uint8(1),
  39874 	106: uint8(1),
  39875 	107: uint8(1),
  39876 	108: uint8(1),
  39877 	109: uint8(1),
  39878 	110: uint8(1),
  39879 	111: uint8(1),
  39880 	112: uint8(1),
  39881 	113: uint8(1),
  39882 	114: uint8(1),
  39883 	115: uint8(1),
  39884 	116: uint8(1),
  39885 	117: uint8(1),
  39886 	118: uint8(1),
  39887 	119: uint8(1),
  39888 	120: uint8(1),
  39889 	121: uint8(1),
  39890 	122: uint8(1),
  39891 	123: uint8(1),
  39892 	124: uint8(1),
  39893 	125: uint8(1),
  39894 	126: uint8(1),
  39895 }
  39896 
  39897 // C documentation
  39898 //
  39899 //	// range = ((range + 1) << kVP8Log2Range[range]) - 1
  39900 var kNewRange = [128]uint8_t{
  39901 	0:   uint8(127),
  39902 	1:   uint8(127),
  39903 	2:   uint8(191),
  39904 	3:   uint8(127),
  39905 	4:   uint8(159),
  39906 	5:   uint8(191),
  39907 	6:   uint8(223),
  39908 	7:   uint8(127),
  39909 	8:   uint8(143),
  39910 	9:   uint8(159),
  39911 	10:  uint8(175),
  39912 	11:  uint8(191),
  39913 	12:  uint8(207),
  39914 	13:  uint8(223),
  39915 	14:  uint8(239),
  39916 	15:  uint8(127),
  39917 	16:  uint8(135),
  39918 	17:  uint8(143),
  39919 	18:  uint8(151),
  39920 	19:  uint8(159),
  39921 	20:  uint8(167),
  39922 	21:  uint8(175),
  39923 	22:  uint8(183),
  39924 	23:  uint8(191),
  39925 	24:  uint8(199),
  39926 	25:  uint8(207),
  39927 	26:  uint8(215),
  39928 	27:  uint8(223),
  39929 	28:  uint8(231),
  39930 	29:  uint8(239),
  39931 	30:  uint8(247),
  39932 	31:  uint8(127),
  39933 	32:  uint8(131),
  39934 	33:  uint8(135),
  39935 	34:  uint8(139),
  39936 	35:  uint8(143),
  39937 	36:  uint8(147),
  39938 	37:  uint8(151),
  39939 	38:  uint8(155),
  39940 	39:  uint8(159),
  39941 	40:  uint8(163),
  39942 	41:  uint8(167),
  39943 	42:  uint8(171),
  39944 	43:  uint8(175),
  39945 	44:  uint8(179),
  39946 	45:  uint8(183),
  39947 	46:  uint8(187),
  39948 	47:  uint8(191),
  39949 	48:  uint8(195),
  39950 	49:  uint8(199),
  39951 	50:  uint8(203),
  39952 	51:  uint8(207),
  39953 	52:  uint8(211),
  39954 	53:  uint8(215),
  39955 	54:  uint8(219),
  39956 	55:  uint8(223),
  39957 	56:  uint8(227),
  39958 	57:  uint8(231),
  39959 	58:  uint8(235),
  39960 	59:  uint8(239),
  39961 	60:  uint8(243),
  39962 	61:  uint8(247),
  39963 	62:  uint8(251),
  39964 	63:  uint8(127),
  39965 	64:  uint8(129),
  39966 	65:  uint8(131),
  39967 	66:  uint8(133),
  39968 	67:  uint8(135),
  39969 	68:  uint8(137),
  39970 	69:  uint8(139),
  39971 	70:  uint8(141),
  39972 	71:  uint8(143),
  39973 	72:  uint8(145),
  39974 	73:  uint8(147),
  39975 	74:  uint8(149),
  39976 	75:  uint8(151),
  39977 	76:  uint8(153),
  39978 	77:  uint8(155),
  39979 	78:  uint8(157),
  39980 	79:  uint8(159),
  39981 	80:  uint8(161),
  39982 	81:  uint8(163),
  39983 	82:  uint8(165),
  39984 	83:  uint8(167),
  39985 	84:  uint8(169),
  39986 	85:  uint8(171),
  39987 	86:  uint8(173),
  39988 	87:  uint8(175),
  39989 	88:  uint8(177),
  39990 	89:  uint8(179),
  39991 	90:  uint8(181),
  39992 	91:  uint8(183),
  39993 	92:  uint8(185),
  39994 	93:  uint8(187),
  39995 	94:  uint8(189),
  39996 	95:  uint8(191),
  39997 	96:  uint8(193),
  39998 	97:  uint8(195),
  39999 	98:  uint8(197),
  40000 	99:  uint8(199),
  40001 	100: uint8(201),
  40002 	101: uint8(203),
  40003 	102: uint8(205),
  40004 	103: uint8(207),
  40005 	104: uint8(209),
  40006 	105: uint8(211),
  40007 	106: uint8(213),
  40008 	107: uint8(215),
  40009 	108: uint8(217),
  40010 	109: uint8(219),
  40011 	110: uint8(221),
  40012 	111: uint8(223),
  40013 	112: uint8(225),
  40014 	113: uint8(227),
  40015 	114: uint8(229),
  40016 	115: uint8(231),
  40017 	116: uint8(233),
  40018 	117: uint8(235),
  40019 	118: uint8(237),
  40020 	119: uint8(239),
  40021 	120: uint8(241),
  40022 	121: uint8(243),
  40023 	122: uint8(245),
  40024 	123: uint8(247),
  40025 	124: uint8(249),
  40026 	125: uint8(251),
  40027 	126: uint8(253),
  40028 	127: uint8(127),
  40029 }
  40030 
  40031 func VP8PutBit(tls *libc.TLS, bw uintptr, bit int32, prob int32) (r int32) {
  40032 	var shift, split int32
  40033 	_, _ = shift, split
  40034 	split = (*VP8BitWriter)(unsafe.Pointer(bw)).Frange1 * prob >> int32(8)
  40035 	if bit != 0 {
  40036 		**(**int32_t)(__ccgo_up(bw + 4)) += split + int32(1)
  40037 		**(**int32_t)(__ccgo_up(bw)) -= split + int32(1)
  40038 	} else {
  40039 		(*VP8BitWriter)(unsafe.Pointer(bw)).Frange1 = split
  40040 	}
  40041 	if (*VP8BitWriter)(unsafe.Pointer(bw)).Frange1 < int32(127) { // emit 'shift' bits out and renormalize
  40042 		shift = int32(kNorm[(*VP8BitWriter)(unsafe.Pointer(bw)).Frange1])
  40043 		(*VP8BitWriter)(unsafe.Pointer(bw)).Frange1 = int32(kNewRange[(*VP8BitWriter)(unsafe.Pointer(bw)).Frange1])
  40044 		**(**int32_t)(__ccgo_up(bw + 4)) <<= shift
  40045 		**(**int32)(__ccgo_up(bw + 12)) += shift
  40046 		if (*VP8BitWriter)(unsafe.Pointer(bw)).Fnb_bits > 0 {
  40047 			Flush(tls, bw)
  40048 		}
  40049 	}
  40050 	return bit
  40051 }
  40052 
  40053 func VP8PutBitUniform(tls *libc.TLS, bw uintptr, bit int32) (r int32) {
  40054 	var split int32
  40055 	_ = split
  40056 	split = (*VP8BitWriter)(unsafe.Pointer(bw)).Frange1 >> int32(1)
  40057 	if bit != 0 {
  40058 		**(**int32_t)(__ccgo_up(bw + 4)) += split + int32(1)
  40059 		**(**int32_t)(__ccgo_up(bw)) -= split + int32(1)
  40060 	} else {
  40061 		(*VP8BitWriter)(unsafe.Pointer(bw)).Frange1 = split
  40062 	}
  40063 	if (*VP8BitWriter)(unsafe.Pointer(bw)).Frange1 < int32(127) {
  40064 		(*VP8BitWriter)(unsafe.Pointer(bw)).Frange1 = int32(kNewRange[(*VP8BitWriter)(unsafe.Pointer(bw)).Frange1])
  40065 		**(**int32_t)(__ccgo_up(bw + 4)) <<= int32(1)
  40066 		**(**int32)(__ccgo_up(bw + 12)) += int32(1)
  40067 		if (*VP8BitWriter)(unsafe.Pointer(bw)).Fnb_bits > 0 {
  40068 			Flush(tls, bw)
  40069 		}
  40070 	}
  40071 	return bit
  40072 }
  40073 
  40074 func VP8PutBits(tls *libc.TLS, bw uintptr, value uint32_t, nb_bits int32) {
  40075 	var mask uint32_t
  40076 	_ = mask
  40077 	mask = uint32(1) << (nb_bits - int32(1))
  40078 	for {
  40079 		if !(mask != 0) {
  40080 			break
  40081 		}
  40082 		VP8PutBitUniform(tls, bw, int32(value&mask))
  40083 		goto _1
  40084 	_1:
  40085 		;
  40086 		mask = mask >> uint32(1)
  40087 	}
  40088 }
  40089 
  40090 func VP8PutSignedBits(tls *libc.TLS, bw uintptr, value int32, nb_bits int32) {
  40091 	if !(VP8PutBitUniform(tls, bw, libc.BoolInt32(value != 0)) != 0) {
  40092 		return
  40093 	}
  40094 	if value < 0 {
  40095 		VP8PutBits(tls, bw, uint32(-value<<int32(1)|int32(1)), nb_bits+int32(1))
  40096 	} else {
  40097 		VP8PutBits(tls, bw, uint32(value<<int32(1)), nb_bits+int32(1))
  40098 	}
  40099 }
  40100 
  40101 //------------------------------------------------------------------------------
  40102 
  40103 func VP8BitWriterInit(tls *libc.TLS, bw uintptr, expected_size size_t) (r int32) {
  40104 	var v1 int32
  40105 	_ = v1
  40106 	(*VP8BitWriter)(unsafe.Pointer(bw)).Frange1 = libc.Int32FromInt32(255) - libc.Int32FromInt32(1)
  40107 	(*VP8BitWriter)(unsafe.Pointer(bw)).Fvalue = 0
  40108 	(*VP8BitWriter)(unsafe.Pointer(bw)).Frun = 0
  40109 	(*VP8BitWriter)(unsafe.Pointer(bw)).Fnb_bits = -int32(8)
  40110 	(*VP8BitWriter)(unsafe.Pointer(bw)).Fpos = uint64(0)
  40111 	(*VP8BitWriter)(unsafe.Pointer(bw)).Fmax_pos = uint64(0)
  40112 	(*VP8BitWriter)(unsafe.Pointer(bw)).Ferror1 = 0
  40113 	(*VP8BitWriter)(unsafe.Pointer(bw)).Fbuf = libc.UintptrFromInt32(0)
  40114 	if expected_size > uint64(0) {
  40115 		v1 = BitWriterResize(tls, bw, expected_size)
  40116 	} else {
  40117 		v1 = int32(1)
  40118 	}
  40119 	return v1
  40120 }
  40121 
  40122 func VP8BitWriterFinish(tls *libc.TLS, bw uintptr) (r uintptr) {
  40123 	VP8PutBits(tls, bw, uint32(0), int32(9)-(*VP8BitWriter)(unsafe.Pointer(bw)).Fnb_bits)
  40124 	(*VP8BitWriter)(unsafe.Pointer(bw)).Fnb_bits = 0 // pad with zeroes
  40125 	Flush(tls, bw)
  40126 	return (*VP8BitWriter)(unsafe.Pointer(bw)).Fbuf
  40127 }
  40128 
  40129 func VP8BitWriterAppend(tls *libc.TLS, bw uintptr, data uintptr, size size_t) (r int32) {
  40130 	if (*VP8BitWriter)(unsafe.Pointer(bw)).Fnb_bits != -int32(8) {
  40131 		return 0
  40132 	} // Flush() must have been called
  40133 	if !(BitWriterResize(tls, bw, size) != 0) {
  40134 		return 0
  40135 	}
  40136 	libc.Xmemcpy(tls, (*VP8BitWriter)(unsafe.Pointer(bw)).Fbuf+uintptr((*VP8BitWriter)(unsafe.Pointer(bw)).Fpos), data, size)
  40137 	**(**size_t)(__ccgo_up(bw + 24)) += size
  40138 	return int32(1)
  40139 }
  40140 
  40141 func VP8BitWriterWipeOut(tls *libc.TLS, bw uintptr) {
  40142 	if bw != libc.UintptrFromInt32(0) {
  40143 		WebPSafeFree(tls, (*VP8BitWriter)(unsafe.Pointer(bw)).Fbuf)
  40144 		libc.Xmemset(tls, bw, 0, uint64(48))
  40145 	}
  40146 }
  40147 
  40148 //------------------------------------------------------------------------------
  40149 // VP8LBitWriter
  40150 
  40151 // This is the minimum amount of size the memory buffer is guaranteed to grow
  40152 // when extra space is needed.
  40153 
  40154 // C documentation
  40155 //
  40156 //	// Returns 1 on success.
  40157 func VP8LBitWriterResize(tls *libc.TLS, bw uintptr, extra_size size_t) (r int32) {
  40158 	var allocated_buf uintptr
  40159 	var allocated_size, current_size, max_bytes, size_required size_t
  40160 	var size_required_64b uint64_t
  40161 	_, _, _, _, _, _ = allocated_buf, allocated_size, current_size, max_bytes, size_required, size_required_64b
  40162 	max_bytes = uint64(int64((*VP8LBitWriter)(unsafe.Pointer(bw)).Fend) - int64((*VP8LBitWriter)(unsafe.Pointer(bw)).Fbuf))
  40163 	current_size = uint64(int64((*VP8LBitWriter)(unsafe.Pointer(bw)).Fcur) - int64((*VP8LBitWriter)(unsafe.Pointer(bw)).Fbuf))
  40164 	size_required_64b = current_size + extra_size
  40165 	size_required = size_required_64b
  40166 	if size_required != size_required_64b {
  40167 		(*VP8LBitWriter)(unsafe.Pointer(bw)).Ferror1 = int32(1)
  40168 		return 0
  40169 	}
  40170 	if max_bytes > uint64(0) && size_required <= max_bytes {
  40171 		return int32(1)
  40172 	}
  40173 	allocated_size = uint64(3) * max_bytes >> int32(1)
  40174 	if allocated_size < size_required {
  40175 		allocated_size = size_required
  40176 	}
  40177 	// make allocated size multiple of 1k
  40178 	allocated_size = (allocated_size>>libc.Int32FromInt32(10) + libc.Uint64FromInt32(1)) << libc.Int32FromInt32(10)
  40179 	allocated_buf = WebPSafeMalloc(tls, uint64(1), allocated_size)
  40180 	if allocated_buf == libc.UintptrFromInt32(0) {
  40181 		(*VP8LBitWriter)(unsafe.Pointer(bw)).Ferror1 = int32(1)
  40182 		return 0
  40183 	}
  40184 	if current_size > uint64(0) {
  40185 		libc.Xmemcpy(tls, allocated_buf, (*VP8LBitWriter)(unsafe.Pointer(bw)).Fbuf, current_size)
  40186 	}
  40187 	WebPSafeFree(tls, (*VP8LBitWriter)(unsafe.Pointer(bw)).Fbuf)
  40188 	(*VP8LBitWriter)(unsafe.Pointer(bw)).Fbuf = allocated_buf
  40189 	(*VP8LBitWriter)(unsafe.Pointer(bw)).Fcur = (*VP8LBitWriter)(unsafe.Pointer(bw)).Fbuf + uintptr(current_size)
  40190 	(*VP8LBitWriter)(unsafe.Pointer(bw)).Fend = (*VP8LBitWriter)(unsafe.Pointer(bw)).Fbuf + uintptr(allocated_size)
  40191 	return int32(1)
  40192 }
  40193 
  40194 func VP8LBitWriterInit(tls *libc.TLS, bw uintptr, expected_size size_t) (r int32) {
  40195 	libc.Xmemset(tls, bw, 0, uint64(48))
  40196 	return VP8LBitWriterResize(tls, bw, expected_size)
  40197 }
  40198 
  40199 func VP8LBitWriterClone(tls *libc.TLS, src uintptr, dst uintptr) (r int32) {
  40200 	var current_size size_t
  40201 	_ = current_size
  40202 	current_size = uint64(int64((*VP8LBitWriter)(unsafe.Pointer(src)).Fcur) - int64((*VP8LBitWriter)(unsafe.Pointer(src)).Fbuf))
  40203 	if !(VP8LBitWriterResize(tls, dst, current_size) != 0) {
  40204 		return 0
  40205 	}
  40206 	libc.Xmemcpy(tls, (*VP8LBitWriter)(unsafe.Pointer(dst)).Fbuf, (*VP8LBitWriter)(unsafe.Pointer(src)).Fbuf, current_size)
  40207 	(*VP8LBitWriter)(unsafe.Pointer(dst)).Fbits = (*VP8LBitWriter)(unsafe.Pointer(src)).Fbits
  40208 	(*VP8LBitWriter)(unsafe.Pointer(dst)).Fused = (*VP8LBitWriter)(unsafe.Pointer(src)).Fused
  40209 	(*VP8LBitWriter)(unsafe.Pointer(dst)).Ferror1 = (*VP8LBitWriter)(unsafe.Pointer(src)).Ferror1
  40210 	(*VP8LBitWriter)(unsafe.Pointer(dst)).Fcur = (*VP8LBitWriter)(unsafe.Pointer(dst)).Fbuf + uintptr(current_size)
  40211 	return int32(1)
  40212 }
  40213 
  40214 func VP8LBitWriterWipeOut(tls *libc.TLS, bw uintptr) {
  40215 	if bw != libc.UintptrFromInt32(0) {
  40216 		WebPSafeFree(tls, (*VP8LBitWriter)(unsafe.Pointer(bw)).Fbuf)
  40217 		libc.Xmemset(tls, bw, 0, uint64(48))
  40218 	}
  40219 }
  40220 
  40221 func VP8LBitWriterReset(tls *libc.TLS, bw_init uintptr, bw uintptr) {
  40222 	(*VP8LBitWriter)(unsafe.Pointer(bw)).Fbits = (*VP8LBitWriter)(unsafe.Pointer(bw_init)).Fbits
  40223 	(*VP8LBitWriter)(unsafe.Pointer(bw)).Fused = (*VP8LBitWriter)(unsafe.Pointer(bw_init)).Fused
  40224 	(*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))
  40225 	(*VP8LBitWriter)(unsafe.Pointer(bw)).Ferror1 = (*VP8LBitWriter)(unsafe.Pointer(bw_init)).Ferror1
  40226 }
  40227 
  40228 func VP8LBitWriterSwap(tls *libc.TLS, src uintptr, dst uintptr) {
  40229 	var tmp VP8LBitWriter
  40230 	_ = tmp
  40231 	tmp = **(**VP8LBitWriter)(__ccgo_up(src))
  40232 	**(**VP8LBitWriter)(__ccgo_up(src)) = **(**VP8LBitWriter)(__ccgo_up(dst))
  40233 	**(**VP8LBitWriter)(__ccgo_up(dst)) = tmp
  40234 }
  40235 
  40236 func VP8LPutBitsFlushBits(tls *libc.TLS, bw uintptr) {
  40237 	var extra_size, v1 uint64_t
  40238 	var v2 int32
  40239 	_, _, _ = extra_size, v1, v2
  40240 	// If needed, make some room by flushing some bits out.
  40241 	if (*VP8LBitWriter)(unsafe.Pointer(bw)).Fcur+uintptr(VP8L_WRITER_BYTES) > (*VP8LBitWriter)(unsafe.Pointer(bw)).Fend {
  40242 		extra_size = uint64(int64((*VP8LBitWriter)(unsafe.Pointer(bw)).Fend)-int64((*VP8LBitWriter)(unsafe.Pointer(bw)).Fbuf)) + uint64(32768)
  40243 		v1 = extra_size
  40244 		v2 = libc.BoolInt32(v1 == v1)
  40245 		goto _3
  40246 	_3:
  40247 		;
  40248 		if !(v2 != 0) || !(VP8LBitWriterResize(tls, bw, extra_size) != 0) {
  40249 			(*VP8LBitWriter)(unsafe.Pointer(bw)).Fcur = (*VP8LBitWriter)(unsafe.Pointer(bw)).Fbuf
  40250 			(*VP8LBitWriter)(unsafe.Pointer(bw)).Ferror1 = int32(1)
  40251 			return
  40252 		}
  40253 	}
  40254 	**(**vp8l_wtype_t)(__ccgo_up((*VP8LBitWriter)(unsafe.Pointer(bw)).Fcur)) = uint32((*VP8LBitWriter)(unsafe.Pointer(bw)).Fbits)
  40255 	**(**uintptr)(__ccgo_up(bw + 24)) += uintptr(VP8L_WRITER_BYTES)
  40256 	**(**vp8l_atype_t)(__ccgo_up(bw)) >>= uint64(VP8L_WRITER_BITS)
  40257 	**(**int32)(__ccgo_up(bw + 8)) -= int32(VP8L_WRITER_BITS)
  40258 }
  40259 
  40260 func VP8LPutBitsInternal(tls *libc.TLS, bw uintptr, bits uint32_t, n_bits int32) {
  40261 	var extra_size, v1 uint64_t
  40262 	var lbits vp8l_atype_t
  40263 	var used, v2 int32
  40264 	_, _, _, _, _ = extra_size, lbits, used, v1, v2
  40265 	// That's the max we can handle:
  40266 	if n_bits > 0 {
  40267 		lbits = (*VP8LBitWriter)(unsafe.Pointer(bw)).Fbits
  40268 		used = (*VP8LBitWriter)(unsafe.Pointer(bw)).Fused
  40269 		// Special case of overflow handling for 32bit accumulator (2-steps flush).
  40270 		// If needed, make some room by flushing some bits out.
  40271 		for used >= int32(VP8L_WRITER_BITS) {
  40272 			if (*VP8LBitWriter)(unsafe.Pointer(bw)).Fcur+uintptr(VP8L_WRITER_BYTES) > (*VP8LBitWriter)(unsafe.Pointer(bw)).Fend {
  40273 				extra_size = uint64(int64((*VP8LBitWriter)(unsafe.Pointer(bw)).Fend)-int64((*VP8LBitWriter)(unsafe.Pointer(bw)).Fbuf)) + uint64(32768)
  40274 				v1 = extra_size
  40275 				v2 = libc.BoolInt32(v1 == v1)
  40276 				goto _3
  40277 			_3:
  40278 				;
  40279 				if !(v2 != 0) || !(VP8LBitWriterResize(tls, bw, extra_size) != 0) {
  40280 					(*VP8LBitWriter)(unsafe.Pointer(bw)).Fcur = (*VP8LBitWriter)(unsafe.Pointer(bw)).Fbuf
  40281 					(*VP8LBitWriter)(unsafe.Pointer(bw)).Ferror1 = int32(1)
  40282 					return
  40283 				}
  40284 			}
  40285 			**(**vp8l_wtype_t)(__ccgo_up((*VP8LBitWriter)(unsafe.Pointer(bw)).Fcur)) = uint32(lbits)
  40286 			**(**uintptr)(__ccgo_up(bw + 24)) += uintptr(VP8L_WRITER_BYTES)
  40287 			lbits = lbits >> uint64(VP8L_WRITER_BITS)
  40288 			used = used - int32(VP8L_WRITER_BITS)
  40289 		}
  40290 		(*VP8LBitWriter)(unsafe.Pointer(bw)).Fbits = lbits | uint64(bits)<<used
  40291 		(*VP8LBitWriter)(unsafe.Pointer(bw)).Fused = used + n_bits
  40292 	}
  40293 }
  40294 
  40295 func VP8LBitWriterFinish(tls *libc.TLS, bw uintptr) (r uintptr) {
  40296 	var v1, v2 uintptr
  40297 	_, _ = v1, v2
  40298 	// flush leftover bits
  40299 	if VP8LBitWriterResize(tls, bw, uint64(((*VP8LBitWriter)(unsafe.Pointer(bw)).Fused+int32(7))>>int32(3))) != 0 {
  40300 		for (*VP8LBitWriter)(unsafe.Pointer(bw)).Fused > 0 {
  40301 			v2 = bw + 24
  40302 			v1 = *(*uintptr)(unsafe.Pointer(v2))
  40303 			*(*uintptr)(unsafe.Pointer(v2)) = *(*uintptr)(unsafe.Pointer(v2)) + 1
  40304 			**(**uint8_t)(__ccgo_up(v1)) = uint8((*VP8LBitWriter)(unsafe.Pointer(bw)).Fbits)
  40305 			**(**vp8l_atype_t)(__ccgo_up(bw)) >>= uint64(8)
  40306 			**(**int32)(__ccgo_up(bw + 8)) -= int32(8)
  40307 		}
  40308 		(*VP8LBitWriter)(unsafe.Pointer(bw)).Fused = 0
  40309 	}
  40310 	return (*VP8LBitWriter)(unsafe.Pointer(bw)).Fbuf
  40311 }
  40312 
  40313 var kHashMul12 = uint32(0x1e35a7bd)
  40314 
  40315 //------------------------------------------------------------------------------
  40316 
  40317 //------------------------------------------------------------------------------
  40318 // VP8LColorCache.
  40319 
  40320 func VP8LColorCacheInit(tls *libc.TLS, color_cache uintptr, hash_bits int32) (r int32) {
  40321 	var hash_size int32
  40322 	_ = hash_size
  40323 	hash_size = int32(1) << hash_bits
  40324 	(*VP8LColorCache)(unsafe.Pointer(color_cache)).Fcolors = WebPSafeCalloc(tls, uint64(hash_size), uint64(4))
  40325 	if (*VP8LColorCache)(unsafe.Pointer(color_cache)).Fcolors == libc.UintptrFromInt32(0) {
  40326 		return 0
  40327 	}
  40328 	(*VP8LColorCache)(unsafe.Pointer(color_cache)).Fhash_shift = int32(32) - hash_bits
  40329 	(*VP8LColorCache)(unsafe.Pointer(color_cache)).Fhash_bits = hash_bits
  40330 	return int32(1)
  40331 }
  40332 
  40333 func VP8LColorCacheClear(tls *libc.TLS, color_cache uintptr) {
  40334 	if color_cache != libc.UintptrFromInt32(0) {
  40335 		WebPSafeFree(tls, (*VP8LColorCache)(unsafe.Pointer(color_cache)).Fcolors)
  40336 		(*VP8LColorCache)(unsafe.Pointer(color_cache)).Fcolors = libc.UintptrFromInt32(0)
  40337 	}
  40338 }
  40339 
  40340 func VP8LColorCacheCopy(tls *libc.TLS, src uintptr, dst uintptr) {
  40341 	libc.Xmemcpy(tls, (*VP8LColorCache)(unsafe.Pointer(dst)).Fcolors, (*VP8LColorCache)(unsafe.Pointer(src)).Fcolors, libc.Uint64FromUint32(1)<<(*VP8LColorCache)(unsafe.Pointer(dst)).Fhash_bits*uint64(4))
  40342 }
  40343 
  40344 // -----------------------------------------------------------------------------
  40345 // Quick estimate of a potentially interesting filter mode to try.
  40346 
  40347 func GradientPredictor(tls *libc.TLS, a uint8_t, b uint8_t, c uint8_t) (r int32) {
  40348 	var g, v1, v2 int32
  40349 	_, _, _ = g, v1, v2
  40350 	g = int32(a) + int32(b) - int32(c)
  40351 	if g & ^libc.Int32FromInt32(0xff) == 0 {
  40352 		v1 = g
  40353 	} else {
  40354 		if g < 0 {
  40355 			v2 = 0
  40356 		} else {
  40357 			v2 = int32(255)
  40358 		}
  40359 		v1 = v2
  40360 	}
  40361 	return v1 // clip to 8bit
  40362 }
  40363 
  40364 func WebPEstimateBestFilter(tls *libc.TLS, data uintptr, width int32, height int32, stride int32) (r WEBP_FILTER_TYPE) {
  40365 	bp := tls.Alloc(256)
  40366 	defer tls.Free(256)
  40367 	var best_filter WEBP_FILTER_TYPE
  40368 	var best_score, diff0, diff1, diff2, diff3, filter, grad_pred, i, j, mean, score int32
  40369 	var p uintptr
  40370 	var _ /* bins at bp+0 */ [4][16]int32
  40371 	_, _, _, _, _, _, _, _, _, _, _, _, _ = best_filter, best_score, diff0, diff1, diff2, diff3, filter, grad_pred, i, j, mean, p, score
  40372 	libc.Xmemset(tls, bp, 0, uint64(256))
  40373 	// We only sample every other pixels. That's enough.
  40374 	j = int32(2)
  40375 	for {
  40376 		if !(j < height-int32(1)) {
  40377 			break
  40378 		}
  40379 		p = data + uintptr(j*stride)
  40380 		mean = int32(**(**uint8_t)(__ccgo_up(p)))
  40381 		i = int32(2)
  40382 		for {
  40383 			if !(i < width-int32(1)) {
  40384 				break
  40385 			}
  40386 			diff0 = libc.Xabs(tls, int32(**(**uint8_t)(__ccgo_up(p + uintptr(i))))-mean) >> libc.Int32FromInt32(4)
  40387 			diff1 = libc.Xabs(tls, int32(**(**uint8_t)(__ccgo_up(p + uintptr(i))))-int32(**(**uint8_t)(__ccgo_up(p + uintptr(i-int32(1)))))) >> libc.Int32FromInt32(4)
  40388 			diff2 = libc.Xabs(tls, int32(**(**uint8_t)(__ccgo_up(p + uintptr(i))))-int32(**(**uint8_t)(__ccgo_up(p + uintptr(i-width))))) >> libc.Int32FromInt32(4)
  40389 			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)))))
  40390 			diff3 = libc.Xabs(tls, int32(**(**uint8_t)(__ccgo_up(p + uintptr(i))))-grad_pred) >> libc.Int32FromInt32(4)
  40391 			**(**int32)(__ccgo_up(bp + uintptr(WEBP_FILTER_NONE)*64 + uintptr(diff0)*4)) = int32(1)
  40392 			**(**int32)(__ccgo_up(bp + uintptr(WEBP_FILTER_HORIZONTAL)*64 + uintptr(diff1)*4)) = int32(1)
  40393 			**(**int32)(__ccgo_up(bp + uintptr(WEBP_FILTER_VERTICAL)*64 + uintptr(diff2)*4)) = int32(1)
  40394 			**(**int32)(__ccgo_up(bp + uintptr(WEBP_FILTER_GRADIENT)*64 + uintptr(diff3)*4)) = int32(1)
  40395 			mean = (int32(3)*mean + int32(**(**uint8_t)(__ccgo_up(p + uintptr(i)))) + int32(2)) >> int32(2)
  40396 			goto _2
  40397 		_2:
  40398 			;
  40399 			i = i + int32(2)
  40400 		}
  40401 		goto _1
  40402 	_1:
  40403 		;
  40404 		j = j + int32(2)
  40405 	}
  40406 	best_filter = int32(WEBP_FILTER_NONE)
  40407 	best_score = int32(0x7fffffff)
  40408 	filter = int32(WEBP_FILTER_NONE)
  40409 	for {
  40410 		if !(filter < int32(WEBP_FILTER_LAST)) {
  40411 			break
  40412 		}
  40413 		score = 0
  40414 		i = 0
  40415 		for {
  40416 			if !(i < int32(16)) {
  40417 				break
  40418 			}
  40419 			if **(**int32)(__ccgo_up(bp + uintptr(filter)*64 + uintptr(i)*4)) > 0 {
  40420 				score = score + i
  40421 			}
  40422 			goto _4
  40423 		_4:
  40424 			;
  40425 			i = i + 1
  40426 		}
  40427 		if score < best_score {
  40428 			best_score = score
  40429 			best_filter = filter
  40430 		}
  40431 		goto _3
  40432 	_3:
  40433 		;
  40434 		filter = filter + 1
  40435 	}
  40436 	return best_filter
  40437 	return r
  40438 }
  40439 
  40440 // Alpha related constants.
  40441 
  40442 // Mux related constants.
  40443 
  40444 // Maximum chunk payload is such that adding the header and padding won't
  40445 // overflow a uint32_t.
  40446 
  40447 // -----------------------------------------------------------------------------
  40448 // Util function to optimize the symbol map for RLE coding
  40449 
  40450 // C documentation
  40451 //
  40452 //	// Heuristics for selecting the stride ranges to collapse.
  40453 func ValuesShouldBeCollapsedToStrideAverage(tls *libc.TLS, a int32, b int32) (r int32) {
  40454 	return libc.BoolInt32(libc.Xabs(tls, a-b) < int32(4))
  40455 }
  40456 
  40457 // C documentation
  40458 //
  40459 //	// Change the population counts in a way that the consequent
  40460 //	// Huffman tree compression, especially its RLE-part, give smaller output.
  40461 func OptimizeHuffmanForRle(tls *libc.TLS, length int32, good_for_rle uintptr, counts uintptr) {
  40462 	var count, k1, limit, stride1, sum, symbol uint32_t
  40463 	var i, k, stride int32
  40464 	_, _, _, _, _, _, _, _, _ = count, i, k, k1, limit, stride, stride1, sum, symbol
  40465 	for {
  40466 		if !(length >= 0) {
  40467 			break
  40468 		}
  40469 		if length == 0 {
  40470 			return // All zeros.
  40471 		}
  40472 		if **(**uint32_t)(__ccgo_up(counts + uintptr(length-int32(1))*4)) != uint32(0) {
  40473 			// Now counts[0..length - 1] does not have trailing zeros.
  40474 			break
  40475 		}
  40476 		goto _1
  40477 	_1:
  40478 		;
  40479 		length = length - 1
  40480 	}
  40481 	// 2) Let's mark all population counts that already can be encoded
  40482 	// with an rle code.
  40483 	// Let's not spoil any of the existing good rle codes.
  40484 	// Mark any seq of 0's that is longer as 5 as a good_for_rle.
  40485 	// Mark any seq of non-0's that is longer as 7 as a good_for_rle.
  40486 	symbol = **(**uint32_t)(__ccgo_up(counts))
  40487 	stride = 0
  40488 	i = 0
  40489 	for {
  40490 		if !(i < length+int32(1)) {
  40491 			break
  40492 		}
  40493 		if i == length || **(**uint32_t)(__ccgo_up(counts + uintptr(i)*4)) != symbol {
  40494 			if symbol == uint32(0) && stride >= int32(5) || symbol != uint32(0) && stride >= int32(7) {
  40495 				k = 0
  40496 				for {
  40497 					if !(k < stride) {
  40498 						break
  40499 					}
  40500 					**(**uint8_t)(__ccgo_up(good_for_rle + uintptr(i-k-int32(1)))) = uint8(1)
  40501 					goto _3
  40502 				_3:
  40503 					;
  40504 					k = k + 1
  40505 				}
  40506 			}
  40507 			stride = int32(1)
  40508 			if i != length {
  40509 				symbol = **(**uint32_t)(__ccgo_up(counts + uintptr(i)*4))
  40510 			}
  40511 		} else {
  40512 			stride = stride + 1
  40513 		}
  40514 		goto _2
  40515 	_2:
  40516 		;
  40517 		i = i + 1
  40518 	}
  40519 	// 3) Let's replace those population counts that lead to more rle codes.
  40520 	stride1 = uint32(0)
  40521 	limit = **(**uint32_t)(__ccgo_up(counts))
  40522 	sum = uint32(0)
  40523 	i = 0
  40524 	for {
  40525 		if !(i < length+int32(1)) {
  40526 			break
  40527 		}
  40528 		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, int32(**(**uint32_t)(__ccgo_up(counts + uintptr(i)*4))), int32(limit)) != 0) {
  40529 			if stride1 >= uint32(4) || stride1 >= uint32(3) && sum == uint32(0) {
  40530 				// The stride must end, collapse what we have, if we have enough (4).
  40531 				count = (sum + stride1/uint32(2)) / stride1
  40532 				if count < uint32(1) {
  40533 					count = uint32(1)
  40534 				}
  40535 				if sum == uint32(0) {
  40536 					// Don't make an all zeros stride to be upgraded to ones.
  40537 					count = uint32(0)
  40538 				}
  40539 				k1 = uint32(0)
  40540 				for {
  40541 					if !(k1 < stride1) {
  40542 						break
  40543 					}
  40544 					// We don't want to change value at counts[i],
  40545 					// that is already belonging to the next stride. Thus - 1.
  40546 					**(**uint32_t)(__ccgo_up(counts + uintptr(uint32(i)-k1-uint32(1))*4)) = count
  40547 					goto _5
  40548 				_5:
  40549 					;
  40550 					k1 = k1 + 1
  40551 				}
  40552 			}
  40553 			stride1 = uint32(0)
  40554 			sum = uint32(0)
  40555 			if i < length-int32(3) {
  40556 				// All interesting strides have a count of at least 4,
  40557 				// at least when non-zeros.
  40558 				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)
  40559 			} else {
  40560 				if i < length {
  40561 					limit = **(**uint32_t)(__ccgo_up(counts + uintptr(i)*4))
  40562 				} else {
  40563 					limit = uint32(0)
  40564 				}
  40565 			}
  40566 		}
  40567 		stride1 = stride1 + 1
  40568 		if i != length {
  40569 			sum = sum + **(**uint32_t)(__ccgo_up(counts + uintptr(i)*4))
  40570 			if stride1 >= uint32(4) {
  40571 				limit = (sum + stride1/uint32(2)) / stride1
  40572 			}
  40573 		}
  40574 		goto _4
  40575 	_4:
  40576 		;
  40577 		i = i + 1
  40578 	}
  40579 }
  40580 
  40581 // C documentation
  40582 //
  40583 //	// A comparer function for two Huffman trees: sorts first by 'total count'
  40584 //	// (more comes first), and then by 'value' (more comes first).
  40585 func CompareHuffmanTrees(tls *libc.TLS, ptr1 uintptr, ptr2 uintptr) (r int32) {
  40586 	var t1, t2 uintptr
  40587 	var v1 int32
  40588 	_, _, _ = t1, t2, v1
  40589 	t1 = ptr1
  40590 	t2 = ptr2
  40591 	if (*HuffmanTree)(unsafe.Pointer(t1)).Ftotal_count > (*HuffmanTree)(unsafe.Pointer(t2)).Ftotal_count {
  40592 		return -int32(1)
  40593 	} else {
  40594 		if (*HuffmanTree)(unsafe.Pointer(t1)).Ftotal_count < (*HuffmanTree)(unsafe.Pointer(t2)).Ftotal_count {
  40595 			return int32(1)
  40596 		} else {
  40597 			if (*HuffmanTree)(unsafe.Pointer(t1)).Fvalue < (*HuffmanTree)(unsafe.Pointer(t2)).Fvalue {
  40598 				v1 = -int32(1)
  40599 			} else {
  40600 				v1 = int32(1)
  40601 			}
  40602 			return v1
  40603 		}
  40604 	}
  40605 	return r
  40606 }
  40607 
  40608 func SetBitDepths(tls *libc.TLS, tree uintptr, pool uintptr, bit_depths uintptr, level int32) {
  40609 	if (*HuffmanTree)(unsafe.Pointer(tree)).Fpool_index_left >= 0 {
  40610 		SetBitDepths(tls, pool+uintptr((*HuffmanTree)(unsafe.Pointer(tree)).Fpool_index_left)*16, pool, bit_depths, level+int32(1))
  40611 		SetBitDepths(tls, pool+uintptr((*HuffmanTree)(unsafe.Pointer(tree)).Fpool_index_right)*16, pool, bit_depths, level+int32(1))
  40612 	} else {
  40613 		**(**uint8_t)(__ccgo_up(bit_depths + uintptr((*HuffmanTree)(unsafe.Pointer(tree)).Fvalue))) = uint8(level)
  40614 	}
  40615 }
  40616 
  40617 // C documentation
  40618 //
  40619 //	// Create an optimal Huffman tree.
  40620 //	//
  40621 //	// (data,length): population counts.
  40622 //	// tree_limit: maximum bit depth (inclusive) of the codes.
  40623 //	// bit_depths[]: how many bits are used for the symbol.
  40624 //	//
  40625 //	// Returns 0 when an error has occurred.
  40626 //	//
  40627 //	// The catch here is that the tree cannot be arbitrarily deep
  40628 //	//
  40629 //	// count_limit is the value that is to be faked as the minimum value
  40630 //	// and this minimum value is raised until the tree matches the
  40631 //	// maximum length requirement.
  40632 //	//
  40633 //	// This algorithm is not of excellent performance for very long data blocks,
  40634 //	// especially when population counts are longer than 2**tree_limit, but
  40635 //	// we are not planning to use this with extremely long blocks.
  40636 //	//
  40637 //	// See https://en.wikipedia.org/wiki/Huffman_coding
  40638 func GenerateOptimalTree(tls *libc.TLS, histogram uintptr, histogram_size int32, tree uintptr, tree_depth_limit int32, bit_depths uintptr) {
  40639 	var count, count1, count_min uint32_t
  40640 	var i, idx, j, k, max_depth, tree_pool_size, tree_size, tree_size_orig, v5 int32
  40641 	var tree_pool uintptr
  40642 	var v4 uint32
  40643 	_, _, _, _, _, _, _, _, _, _, _, _, _, _ = count, count1, count_min, i, idx, j, k, max_depth, tree_pool, tree_pool_size, tree_size, tree_size_orig, v4, v5
  40644 	tree_size_orig = 0
  40645 	i = 0
  40646 	for {
  40647 		if !(i < histogram_size) {
  40648 			break
  40649 		}
  40650 		if **(**uint32_t)(__ccgo_up(histogram + uintptr(i)*4)) != uint32(0) {
  40651 			tree_size_orig = tree_size_orig + 1
  40652 		}
  40653 		goto _1
  40654 	_1:
  40655 		;
  40656 		i = i + 1
  40657 	}
  40658 	if tree_size_orig == 0 { // pretty optimal already!
  40659 		return
  40660 	}
  40661 	tree_pool = tree + uintptr(tree_size_orig)*16
  40662 	// For block sizes with less than 64k symbols we never need to do a
  40663 	// second iteration of this loop.
  40664 	// If we actually start running inside this loop a lot, we would perhaps
  40665 	// be better off with the Katajainen algorithm.
  40666 	count_min = uint32(1)
  40667 	for {
  40668 		tree_size = tree_size_orig
  40669 		// We need to pack the Huffman tree in tree_depth_limit bits.
  40670 		// So, we try by faking histogram entries to be at least 'count_min'.
  40671 		idx = 0
  40672 		j = 0
  40673 		for {
  40674 			if !(j < histogram_size) {
  40675 				break
  40676 			}
  40677 			if **(**uint32_t)(__ccgo_up(histogram + uintptr(j)*4)) != uint32(0) {
  40678 				if **(**uint32_t)(__ccgo_up(histogram + uintptr(j)*4)) < count_min {
  40679 					v4 = count_min
  40680 				} else {
  40681 					v4 = **(**uint32_t)(__ccgo_up(histogram + uintptr(j)*4))
  40682 				}
  40683 				count = v4
  40684 				(**(**HuffmanTree)(__ccgo_up(tree + uintptr(idx)*16))).Ftotal_count = count
  40685 				(**(**HuffmanTree)(__ccgo_up(tree + uintptr(idx)*16))).Fvalue = j
  40686 				(**(**HuffmanTree)(__ccgo_up(tree + uintptr(idx)*16))).Fpool_index_left = -int32(1)
  40687 				(**(**HuffmanTree)(__ccgo_up(tree + uintptr(idx)*16))).Fpool_index_right = -int32(1)
  40688 				idx = idx + 1
  40689 			}
  40690 			goto _3
  40691 		_3:
  40692 			;
  40693 			j = j + 1
  40694 		}
  40695 		// Build the Huffman tree.
  40696 		libc.Xqsort(tls, tree, uint64(tree_size), uint64(16), __ccgo_fp(CompareHuffmanTrees))
  40697 		if tree_size > int32(1) { // Normal case.
  40698 			tree_pool_size = 0
  40699 			for tree_size > int32(1) {
  40700 				v5 = tree_pool_size
  40701 				tree_pool_size = tree_pool_size + 1
  40702 				**(**HuffmanTree)(__ccgo_up(tree_pool + uintptr(v5)*16)) = **(**HuffmanTree)(__ccgo_up(tree + uintptr(tree_size-int32(1))*16))
  40703 				v5 = tree_pool_size
  40704 				tree_pool_size = tree_pool_size + 1
  40705 				**(**HuffmanTree)(__ccgo_up(tree_pool + uintptr(v5)*16)) = **(**HuffmanTree)(__ccgo_up(tree + uintptr(tree_size-int32(2))*16))
  40706 				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
  40707 				tree_size = tree_size - int32(2)
  40708 				k = 0
  40709 				for {
  40710 					if !(k < tree_size) {
  40711 						break
  40712 					}
  40713 					if (**(**HuffmanTree)(__ccgo_up(tree + uintptr(k)*16))).Ftotal_count <= count1 {
  40714 						break
  40715 					}
  40716 					goto _7
  40717 				_7:
  40718 					;
  40719 					k = k + 1
  40720 				}
  40721 				libc.Xmemmove(tls, tree+uintptr(k+libc.Int32FromInt32(1))*16, tree+uintptr(k)*16, uint64(tree_size-k)*uint64(16))
  40722 				(**(**HuffmanTree)(__ccgo_up(tree + uintptr(k)*16))).Ftotal_count = count1
  40723 				(**(**HuffmanTree)(__ccgo_up(tree + uintptr(k)*16))).Fvalue = -int32(1)
  40724 				(**(**HuffmanTree)(__ccgo_up(tree + uintptr(k)*16))).Fpool_index_left = tree_pool_size - int32(1)
  40725 				(**(**HuffmanTree)(__ccgo_up(tree + uintptr(k)*16))).Fpool_index_right = tree_pool_size - int32(2)
  40726 				tree_size = tree_size + int32(1)
  40727 			}
  40728 			SetBitDepths(tls, tree, tree_pool, bit_depths, 0)
  40729 		} else {
  40730 			if tree_size == int32(1) { // Trivial case: only one element.
  40731 				**(**uint8_t)(__ccgo_up(bit_depths + uintptr((**(**HuffmanTree)(__ccgo_up(tree))).Fvalue))) = uint8(1)
  40732 			}
  40733 		}
  40734 		// Test if this Huffman tree satisfies our 'tree_depth_limit' criteria.
  40735 		max_depth = int32(**(**uint8_t)(__ccgo_up(bit_depths)))
  40736 		j = int32(1)
  40737 		for {
  40738 			if !(j < histogram_size) {
  40739 				break
  40740 			}
  40741 			if max_depth < int32(**(**uint8_t)(__ccgo_up(bit_depths + uintptr(j)))) {
  40742 				max_depth = int32(**(**uint8_t)(__ccgo_up(bit_depths + uintptr(j))))
  40743 			}
  40744 			goto _8
  40745 		_8:
  40746 			;
  40747 			j = j + 1
  40748 		}
  40749 		if max_depth <= tree_depth_limit {
  40750 			break
  40751 		}
  40752 		goto _2
  40753 	_2:
  40754 		;
  40755 		count_min = count_min * uint32(2)
  40756 	}
  40757 }
  40758 
  40759 // -----------------------------------------------------------------------------
  40760 // Coding of the Huffman tree values
  40761 
  40762 func CodeRepeatedValues(tls *libc.TLS, repetitions int32, tokens uintptr, value int32, prev_value int32) (r uintptr) {
  40763 	var i int32
  40764 	_ = i
  40765 	if value != prev_value {
  40766 		(*HuffmanTreeToken)(unsafe.Pointer(tokens)).Fcode = uint8(value)
  40767 		(*HuffmanTreeToken)(unsafe.Pointer(tokens)).Fextra_bits = uint8(0)
  40768 		tokens += 2
  40769 		repetitions = repetitions - 1
  40770 	}
  40771 	for repetitions >= int32(1) {
  40772 		if repetitions < int32(3) {
  40773 			i = 0
  40774 			for {
  40775 				if !(i < repetitions) {
  40776 					break
  40777 				}
  40778 				(*HuffmanTreeToken)(unsafe.Pointer(tokens)).Fcode = uint8(value)
  40779 				(*HuffmanTreeToken)(unsafe.Pointer(tokens)).Fextra_bits = uint8(0)
  40780 				tokens += 2
  40781 				goto _1
  40782 			_1:
  40783 				;
  40784 				i = i + 1
  40785 			}
  40786 			break
  40787 		} else {
  40788 			if repetitions < int32(7) {
  40789 				(*HuffmanTreeToken)(unsafe.Pointer(tokens)).Fcode = uint8(16)
  40790 				(*HuffmanTreeToken)(unsafe.Pointer(tokens)).Fextra_bits = uint8(repetitions - int32(3))
  40791 				tokens += 2
  40792 				break
  40793 			} else {
  40794 				(*HuffmanTreeToken)(unsafe.Pointer(tokens)).Fcode = uint8(16)
  40795 				(*HuffmanTreeToken)(unsafe.Pointer(tokens)).Fextra_bits = uint8(3)
  40796 				tokens += 2
  40797 				repetitions = repetitions - int32(6)
  40798 			}
  40799 		}
  40800 	}
  40801 	return tokens
  40802 }
  40803 
  40804 func CodeRepeatedZeros(tls *libc.TLS, repetitions int32, tokens uintptr) (r uintptr) {
  40805 	var i int32
  40806 	_ = i
  40807 	for repetitions >= int32(1) {
  40808 		if repetitions < int32(3) {
  40809 			i = 0
  40810 			for {
  40811 				if !(i < repetitions) {
  40812 					break
  40813 				}
  40814 				(*HuffmanTreeToken)(unsafe.Pointer(tokens)).Fcode = uint8(0) // 0-value
  40815 				(*HuffmanTreeToken)(unsafe.Pointer(tokens)).Fextra_bits = uint8(0)
  40816 				tokens += 2
  40817 				goto _1
  40818 			_1:
  40819 				;
  40820 				i = i + 1
  40821 			}
  40822 			break
  40823 		} else {
  40824 			if repetitions < int32(11) {
  40825 				(*HuffmanTreeToken)(unsafe.Pointer(tokens)).Fcode = uint8(17)
  40826 				(*HuffmanTreeToken)(unsafe.Pointer(tokens)).Fextra_bits = uint8(repetitions - int32(3))
  40827 				tokens += 2
  40828 				break
  40829 			} else {
  40830 				if repetitions < int32(139) {
  40831 					(*HuffmanTreeToken)(unsafe.Pointer(tokens)).Fcode = uint8(18)
  40832 					(*HuffmanTreeToken)(unsafe.Pointer(tokens)).Fextra_bits = uint8(repetitions - int32(11))
  40833 					tokens += 2
  40834 					break
  40835 				} else {
  40836 					(*HuffmanTreeToken)(unsafe.Pointer(tokens)).Fcode = uint8(18)
  40837 					(*HuffmanTreeToken)(unsafe.Pointer(tokens)).Fextra_bits = uint8(0x7f) // 138 repeated 0s
  40838 					tokens += 2
  40839 					repetitions = repetitions - int32(138)
  40840 				}
  40841 			}
  40842 		}
  40843 	}
  40844 	return tokens
  40845 }
  40846 
  40847 func VP8LCreateCompressedHuffmanTree(tls *libc.TLS, tree uintptr, tokens uintptr, max_tokens int32) (r int32) {
  40848 	var depth_size, i, k, prev_value, runs, value int32
  40849 	var ending_token, starting_token uintptr
  40850 	_, _, _, _, _, _, _, _ = depth_size, ending_token, i, k, prev_value, runs, starting_token, value
  40851 	starting_token = tokens
  40852 	ending_token = tokens + uintptr(max_tokens)*2
  40853 	depth_size = (*HuffmanTreeCode)(unsafe.Pointer(tree)).Fnum_symbols
  40854 	prev_value = int32(8) // 8 is the initial value for rle.
  40855 	i = 0
  40856 	for i < depth_size {
  40857 		value = int32(**(**uint8_t)(__ccgo_up((*HuffmanTreeCode)(unsafe.Pointer(tree)).Fcode_lengths + uintptr(i))))
  40858 		k = i + int32(1)
  40859 		for k < depth_size && int32(**(**uint8_t)(__ccgo_up((*HuffmanTreeCode)(unsafe.Pointer(tree)).Fcode_lengths + uintptr(k)))) == value {
  40860 			k = k + 1
  40861 		}
  40862 		runs = k - i
  40863 		if value == 0 {
  40864 			tokens = CodeRepeatedZeros(tls, runs, tokens)
  40865 		} else {
  40866 			tokens = CodeRepeatedValues(tls, runs, tokens, value, prev_value)
  40867 			prev_value = value
  40868 		}
  40869 		i = i + runs
  40870 	}
  40871 	_ = ending_token // suppress 'unused variable' warning
  40872 	return int32((int64(tokens) - int64(starting_token)) / 2)
  40873 }
  40874 
  40875 // -----------------------------------------------------------------------------
  40876 
  40877 // C documentation
  40878 //
  40879 //	// Pre-reversed 4-bit values.
  40880 var kReversedBits = [16]uint8_t{
  40881 	1:  uint8(0x8),
  40882 	2:  uint8(0x4),
  40883 	3:  uint8(0xc),
  40884 	4:  uint8(0x2),
  40885 	5:  uint8(0xa),
  40886 	6:  uint8(0x6),
  40887 	7:  uint8(0xe),
  40888 	8:  uint8(0x1),
  40889 	9:  uint8(0x9),
  40890 	10: uint8(0x5),
  40891 	11: uint8(0xd),
  40892 	12: uint8(0x3),
  40893 	13: uint8(0xb),
  40894 	14: uint8(0x7),
  40895 	15: uint8(0xf),
  40896 }
  40897 
  40898 func ReverseBits(tls *libc.TLS, num_bits int32, bits uint32_t) (r uint32_t) {
  40899 	var i int32
  40900 	var retval uint32_t
  40901 	_, _ = i, retval
  40902 	retval = uint32(0)
  40903 	i = 0
  40904 	for i < num_bits {
  40905 		i = i + int32(4)
  40906 		retval = retval | uint32(int32(kReversedBits[bits&uint32(0xf)])<<(libc.Int32FromInt32(MAX_ALLOWED_CODE_LENGTH)+libc.Int32FromInt32(1)-i))
  40907 		bits = bits >> uint32(4)
  40908 	}
  40909 	retval = retval >> uint32(libc.Int32FromInt32(MAX_ALLOWED_CODE_LENGTH)+libc.Int32FromInt32(1)-num_bits)
  40910 	return retval
  40911 }
  40912 
  40913 // C documentation
  40914 //
  40915 //	// Get the actual bit values for a tree of bit depths.
  40916 func ConvertBitDepthsToSymbols(tls *libc.TLS, tree uintptr) {
  40917 	bp := tls.Alloc(64)
  40918 	defer tls.Free(64)
  40919 	var code, v4 uint32_t
  40920 	var code_length, code_length1, i, len1 int32
  40921 	var depth_count [16]int32
  40922 	var v5 uintptr
  40923 	var _ /* next_code at bp+0 */ [16]uint32_t
  40924 	_, _, _, _, _, _, _, _ = code, code_length, code_length1, depth_count, i, len1, v4, v5
  40925 	depth_count = [16]int32{}
  40926 	len1 = (*HuffmanTreeCode)(unsafe.Pointer(tree)).Fnum_symbols
  40927 	i = 0
  40928 	for {
  40929 		if !(i < len1) {
  40930 			break
  40931 		}
  40932 		code_length = int32(**(**uint8_t)(__ccgo_up((*HuffmanTreeCode)(unsafe.Pointer(tree)).Fcode_lengths + uintptr(i))))
  40933 		depth_count[code_length] = depth_count[code_length] + 1
  40934 		goto _1
  40935 	_1:
  40936 		;
  40937 		i = i + 1
  40938 	}
  40939 	depth_count[0] = 0 // ignore unused symbol
  40940 	(**(**[16]uint32_t)(__ccgo_up(bp)))[0] = uint32(0)
  40941 	code = uint32(0)
  40942 	i = int32(1)
  40943 	for {
  40944 		if !(i <= int32(MAX_ALLOWED_CODE_LENGTH)) {
  40945 			break
  40946 		}
  40947 		code = (code + uint32(depth_count[i-int32(1)])) << int32(1)
  40948 		(**(**[16]uint32_t)(__ccgo_up(bp)))[i] = code
  40949 		goto _2
  40950 	_2:
  40951 		;
  40952 		i = i + 1
  40953 	}
  40954 	i = 0
  40955 	for {
  40956 		if !(i < len1) {
  40957 			break
  40958 		}
  40959 		code_length1 = int32(**(**uint8_t)(__ccgo_up((*HuffmanTreeCode)(unsafe.Pointer(tree)).Fcode_lengths + uintptr(i))))
  40960 		v5 = bp + uintptr(code_length1)*4
  40961 		v4 = *(*uint32_t)(unsafe.Pointer(v5))
  40962 		*(*uint32_t)(unsafe.Pointer(v5)) = *(*uint32_t)(unsafe.Pointer(v5)) + 1
  40963 		**(**uint16_t)(__ccgo_up((*HuffmanTreeCode)(unsafe.Pointer(tree)).Fcodes + uintptr(i)*2)) = uint16(ReverseBits(tls, code_length1, v4))
  40964 		goto _3
  40965 	_3:
  40966 		;
  40967 		i = i + 1
  40968 	}
  40969 }
  40970 
  40971 // -----------------------------------------------------------------------------
  40972 // Main entry point
  40973 
  40974 func VP8LCreateHuffmanTree(tls *libc.TLS, histogram uintptr, tree_depth_limit int32, buf_rle uintptr, huff_tree uintptr, huff_code uintptr) {
  40975 	var num_symbols int32
  40976 	_ = num_symbols
  40977 	num_symbols = (*HuffmanTreeCode)(unsafe.Pointer(huff_code)).Fnum_symbols
  40978 	libc.Xmemset(tls, buf_rle, 0, uint64(num_symbols)*uint64(1))
  40979 	OptimizeHuffmanForRle(tls, num_symbols, buf_rle, histogram)
  40980 	GenerateOptimalTree(tls, histogram, num_symbols, huff_tree, tree_depth_limit, (*HuffmanTreeCode)(unsafe.Pointer(huff_code)).Fcode_lengths)
  40981 	// Create the actual bit codes for the bit lengths.
  40982 	ConvertBitDepthsToSymbols(tls, huff_code)
  40983 }
  40984 
  40985 const MAX_HTREE_GROUPS = 0x10000
  40986 const SORTED_SIZE_CUTOFF = 512
  40987 
  40988 //------------------------------------------------------------------------------
  40989 
  40990 // Copyright 2012 Google Inc. All Rights Reserved.
  40991 //
  40992 // Use of this source code is governed by a BSD-style license
  40993 // that can be found in the COPYING file in the root of the source
  40994 // tree. An additional intellectual property rights grant can be found
  40995 // in the file PATENTS. All contributing project authors may
  40996 // be found in the AUTHORS file in the root of the source tree.
  40997 // -----------------------------------------------------------------------------
  40998 //
  40999 //  Internal header for constants related to WebP file format.
  41000 //
  41001 // Author: Urvang (urvang@google.com)
  41002 
  41003 // Copyright 2010 Google Inc. All Rights Reserved.
  41004 //
  41005 // Use of this source code is governed by a BSD-style license
  41006 // that can be found in the COPYING file in the root of the source
  41007 // tree. An additional intellectual property rights grant can be found
  41008 // in the file PATENTS. All contributing project authors may
  41009 // be found in the AUTHORS file in the root of the source tree.
  41010 // -----------------------------------------------------------------------------
  41011 //
  41012 //  Common types + memory wrappers
  41013 //
  41014 // Author: Skal (pascal.massimino@gmail.com)
  41015 
  41016 // Huffman data read via DecodeImageStream is represented in two (red and green)
  41017 // bytes.
  41018 
  41019 func VP8LHtreeGroupsNew(tls *libc.TLS, num_htree_groups int32) (r uintptr) {
  41020 	var htree_groups uintptr
  41021 	_ = htree_groups
  41022 	htree_groups = WebPSafeMalloc(tls, uint64(num_htree_groups), uint64(568))
  41023 	if htree_groups == libc.UintptrFromInt32(0) {
  41024 		return libc.UintptrFromInt32(0)
  41025 	}
  41026 	return htree_groups
  41027 }
  41028 
  41029 func VP8LHtreeGroupsFree(tls *libc.TLS, htree_groups uintptr) {
  41030 	if htree_groups != libc.UintptrFromInt32(0) {
  41031 		WebPSafeFree(tls, htree_groups)
  41032 	}
  41033 }
  41034 
  41035 // C documentation
  41036 //
  41037 //	// Returns reverse(reverse(key, len) + 1, len), where reverse(key, len) is the
  41038 //	// bit-wise reversal of the len least significant bits of key.
  41039 func GetNextKey(tls *libc.TLS, key uint32_t, len1 int32) (r uint32_t) {
  41040 	var step uint32_t
  41041 	var v1 uint32
  41042 	_, _ = step, v1
  41043 	step = uint32(int32(1) << (len1 - int32(1)))
  41044 	for key&step != 0 {
  41045 		step = step >> uint32(1)
  41046 	}
  41047 	if step != 0 {
  41048 		v1 = key&(step-uint32(1)) + step
  41049 	} else {
  41050 		v1 = key
  41051 	}
  41052 	return v1
  41053 }
  41054 
  41055 // C documentation
  41056 //
  41057 //	// Stores code in table[0], table[step], table[2*step], ..., table[end].
  41058 //	// Assumes that end is an integer multiple of step.
  41059 func ReplicateValue(tls *libc.TLS, table uintptr, step int32, end int32, code HuffmanCode) {
  41060 	for cond := true; cond; cond = end > 0 {
  41061 		end = end - step
  41062 		**(**HuffmanCode)(__ccgo_up(table + uintptr(end)*4)) = code
  41063 	}
  41064 }
  41065 
  41066 // C documentation
  41067 //
  41068 //	// Returns the table width of the next 2nd level table. count is the histogram
  41069 //	// of bit lengths for the remaining symbols, len is the code length of the next
  41070 //	// processed symbol
  41071 func NextTableBitSize(tls *libc.TLS, count uintptr, len1 int32, root_bits int32) (r int32) {
  41072 	var left int32
  41073 	_ = left
  41074 	left = int32(1) << (len1 - root_bits)
  41075 	for len1 < int32(MAX_ALLOWED_CODE_LENGTH) {
  41076 		left = left - **(**int32)(__ccgo_up(count + uintptr(len1)*4))
  41077 		if left <= 0 {
  41078 			break
  41079 		}
  41080 		len1 = len1 + 1
  41081 		left = left << int32(1)
  41082 	}
  41083 	return len1 - root_bits
  41084 }
  41085 
  41086 // C documentation
  41087 //
  41088 //	// sorted[code_lengths_size] is a pre-allocated array for sorting symbols
  41089 //	// by code length.
  41090 func BuildHuffmanTable(tls *libc.TLS, root_table uintptr, root_bits int32, code_lengths uintptr, code_lengths_size int32, sorted uintptr) (r int32) {
  41091 	bp := tls.Alloc(128)
  41092 	defer tls.Free(128)
  41093 	var code, code1, code2 HuffmanCode
  41094 	var key, low, mask uint32_t
  41095 	var len1, num_nodes, num_open, step, symbol, symbol_code_length, table_bits, table_size, total_size, v4 int32
  41096 	var table, v5 uintptr
  41097 	var _ /* count at bp+0 */ [16]int32
  41098 	var _ /* offset at bp+64 */ [16]int32
  41099 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  41100 	table = root_table                 // next available space in table
  41101 	total_size = int32(1) << root_bits // symbol index in original or sorted table
  41102 	// number of codes of each length:
  41103 	**(**[16]int32)(__ccgo_up(bp)) = [16]int32{}
  41104 	// Build histogram of code lengths.
  41105 	symbol = 0
  41106 	for {
  41107 		if !(symbol < code_lengths_size) {
  41108 			break
  41109 		}
  41110 		if **(**int32)(__ccgo_up(code_lengths + uintptr(symbol)*4)) > int32(MAX_ALLOWED_CODE_LENGTH) {
  41111 			return 0
  41112 		}
  41113 		(**(**[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
  41114 		goto _1
  41115 	_1:
  41116 		;
  41117 		symbol = symbol + 1
  41118 	}
  41119 	// Error, all code lengths are zeros.
  41120 	if (**(**[16]int32)(__ccgo_up(bp)))[0] == code_lengths_size {
  41121 		return 0
  41122 	}
  41123 	// Generate offsets into sorted symbol table by code length.
  41124 	(**(**[16]int32)(__ccgo_up(bp + 64)))[int32(1)] = 0
  41125 	len1 = int32(1)
  41126 	for {
  41127 		if !(len1 < int32(MAX_ALLOWED_CODE_LENGTH)) {
  41128 			break
  41129 		}
  41130 		if (**(**[16]int32)(__ccgo_up(bp)))[len1] > int32(1)<<len1 {
  41131 			return 0
  41132 		}
  41133 		(**(**[16]int32)(__ccgo_up(bp + 64)))[len1+int32(1)] = (**(**[16]int32)(__ccgo_up(bp + 64)))[len1] + (**(**[16]int32)(__ccgo_up(bp)))[len1]
  41134 		goto _2
  41135 	_2:
  41136 		;
  41137 		len1 = len1 + 1
  41138 	}
  41139 	// Sort symbols by length, by symbol order within each length.
  41140 	symbol = 0
  41141 	for {
  41142 		if !(symbol < code_lengths_size) {
  41143 			break
  41144 		}
  41145 		symbol_code_length = **(**int32)(__ccgo_up(code_lengths + uintptr(symbol)*4))
  41146 		if **(**int32)(__ccgo_up(code_lengths + uintptr(symbol)*4)) > 0 {
  41147 			if sorted != libc.UintptrFromInt32(0) {
  41148 				if (**(**[16]int32)(__ccgo_up(bp + 64)))[symbol_code_length] >= code_lengths_size {
  41149 					return 0
  41150 				}
  41151 				v5 = bp + 64 + uintptr(symbol_code_length)*4
  41152 				v4 = *(*int32)(unsafe.Pointer(v5))
  41153 				*(*int32)(unsafe.Pointer(v5)) = *(*int32)(unsafe.Pointer(v5)) + 1
  41154 				**(**uint16_t)(__ccgo_up(sorted + uintptr(v4)*2)) = uint16(symbol)
  41155 			} else {
  41156 				(**(**[16]int32)(__ccgo_up(bp + 64)))[symbol_code_length] = (**(**[16]int32)(__ccgo_up(bp + 64)))[symbol_code_length] + 1
  41157 			}
  41158 		}
  41159 		goto _3
  41160 	_3:
  41161 		;
  41162 		symbol = symbol + 1
  41163 	}
  41164 	// Special case code with only one value.
  41165 	if (**(**[16]int32)(__ccgo_up(bp + 64)))[int32(MAX_ALLOWED_CODE_LENGTH)] == int32(1) {
  41166 		if sorted != libc.UintptrFromInt32(0) {
  41167 			code.Fbits = uint8(0)
  41168 			code.Fvalue = **(**uint16_t)(__ccgo_up(sorted))
  41169 			ReplicateValue(tls, table, int32(1), total_size, code)
  41170 		}
  41171 		return total_size
  41172 	}
  41173 	// step size to replicate values in current table
  41174 	low = uint32(0xffffffff)             // low bits for current root entry
  41175 	mask = uint32(total_size - int32(1)) // mask for low bits
  41176 	key = uint32(0)                      // reversed prefix code
  41177 	num_nodes = int32(1)                 // number of Huffman tree nodes
  41178 	num_open = int32(1)                  // number of open branches in current tree level
  41179 	table_bits = root_bits               // key length of current table
  41180 	table_size = int32(1) << table_bits  // size of current table
  41181 	symbol = 0
  41182 	// Fill in root table.
  41183 	len1 = int32(1)
  41184 	step = libc.Int32FromInt32(2)
  41185 	for {
  41186 		if !(len1 <= root_bits) {
  41187 			break
  41188 		}
  41189 		num_open = num_open << int32(1)
  41190 		num_nodes = num_nodes + num_open
  41191 		num_open = num_open - (**(**[16]int32)(__ccgo_up(bp)))[len1]
  41192 		if num_open < 0 {
  41193 			return 0
  41194 		}
  41195 		if root_table == libc.UintptrFromInt32(0) {
  41196 			goto _6
  41197 		}
  41198 		for {
  41199 			if !((**(**[16]int32)(__ccgo_up(bp)))[len1] > 0) {
  41200 				break
  41201 			}
  41202 			code1.Fbits = uint8(len1)
  41203 			v4 = symbol
  41204 			symbol = symbol + 1
  41205 			code1.Fvalue = **(**uint16_t)(__ccgo_up(sorted + uintptr(v4)*2))
  41206 			ReplicateValue(tls, table+uintptr(key)*4, step, table_size, code1)
  41207 			key = GetNextKey(tls, key, len1)
  41208 			goto _7
  41209 		_7:
  41210 			;
  41211 			(**(**[16]int32)(__ccgo_up(bp)))[len1] = (**(**[16]int32)(__ccgo_up(bp)))[len1] - 1
  41212 		}
  41213 		goto _6
  41214 	_6:
  41215 		;
  41216 		len1 = len1 + 1
  41217 		step = step << int32(1)
  41218 	}
  41219 	// Fill in 2nd level tables and add pointers to root table.
  41220 	len1 = root_bits + int32(1)
  41221 	step = libc.Int32FromInt32(2)
  41222 	for {
  41223 		if !(len1 <= int32(MAX_ALLOWED_CODE_LENGTH)) {
  41224 			break
  41225 		}
  41226 		num_open = num_open << int32(1)
  41227 		num_nodes = num_nodes + num_open
  41228 		num_open = num_open - (**(**[16]int32)(__ccgo_up(bp)))[len1]
  41229 		if num_open < 0 {
  41230 			return 0
  41231 		}
  41232 		for {
  41233 			if !((**(**[16]int32)(__ccgo_up(bp)))[len1] > 0) {
  41234 				break
  41235 			}
  41236 			if key&mask != low {
  41237 				if root_table != libc.UintptrFromInt32(0) {
  41238 					table = table + uintptr(table_size)*4
  41239 				}
  41240 				table_bits = NextTableBitSize(tls, bp, len1, root_bits)
  41241 				table_size = int32(1) << table_bits
  41242 				total_size = total_size + table_size
  41243 				low = key & mask
  41244 				if root_table != libc.UintptrFromInt32(0) {
  41245 					(**(**HuffmanCode)(__ccgo_up(root_table + uintptr(low)*4))).Fbits = uint8(table_bits + root_bits)
  41246 					(**(**HuffmanCode)(__ccgo_up(root_table + uintptr(low)*4))).Fvalue = uint16((int64(table)-int64(root_table))/4 - int64(low))
  41247 				}
  41248 			}
  41249 			if root_table != libc.UintptrFromInt32(0) {
  41250 				code2.Fbits = uint8(len1 - root_bits)
  41251 				v4 = symbol
  41252 				symbol = symbol + 1
  41253 				code2.Fvalue = **(**uint16_t)(__ccgo_up(sorted + uintptr(v4)*2))
  41254 				ReplicateValue(tls, table+uintptr(key>>root_bits)*4, step, table_size, code2)
  41255 			}
  41256 			key = GetNextKey(tls, key, len1)
  41257 			goto _10
  41258 		_10:
  41259 			;
  41260 			(**(**[16]int32)(__ccgo_up(bp)))[len1] = (**(**[16]int32)(__ccgo_up(bp)))[len1] - 1
  41261 		}
  41262 		goto _9
  41263 	_9:
  41264 		;
  41265 		len1 = len1 + 1
  41266 		step = step << int32(1)
  41267 	}
  41268 	// Check if tree is full.
  41269 	if num_nodes != int32(2)*(**(**[16]int32)(__ccgo_up(bp + 64)))[int32(MAX_ALLOWED_CODE_LENGTH)]-int32(1) {
  41270 		return 0
  41271 	}
  41272 	return total_size
  41273 }
  41274 
  41275 // C documentation
  41276 //
  41277 //	// Maximum code_lengths_size is 2328 (reached for 11-bit color_cache_bits).
  41278 //	// More commonly, the value is around ~280.
  41279 //	// Cut-off value for switching between heap and stack allocation.
  41280 func VP8LBuildHuffmanTable(tls *libc.TLS, root_table uintptr, root_bits int32, code_lengths uintptr, code_lengths_size int32) (r int32) {
  41281 	bp := tls.Alloc(1024)
  41282 	defer tls.Free(1024)
  41283 	var next, sorted1 uintptr
  41284 	var segment_size, total_size, v1 int32
  41285 	var _ /* sorted at bp+0 */ [512]uint16_t
  41286 	_, _, _, _, _ = next, segment_size, sorted1, total_size, v1
  41287 	total_size = BuildHuffmanTable(tls, libc.UintptrFromInt32(0), root_bits, code_lengths, code_lengths_size, libc.UintptrFromInt32(0))
  41288 	if total_size == 0 || root_table == libc.UintptrFromInt32(0) {
  41289 		return total_size
  41290 	}
  41291 	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 {
  41292 		// If 'root_table' does not have enough memory, allocate a new segment.
  41293 		// The available part of root_table->curr_segment is left unused because we
  41294 		// need a contiguous buffer.
  41295 		segment_size = (*HuffmanTablesSegment)(unsafe.Pointer((*HuffmanTables)(unsafe.Pointer(root_table)).Fcurr_segment)).Fsize
  41296 		next = WebPSafeMalloc(tls, uint64(1), uint64(32))
  41297 		if next == libc.UintptrFromInt32(0) {
  41298 			return 0
  41299 		}
  41300 		// Fill the new segment.
  41301 		// We need at least 'total_size' but if that value is small, it is better to
  41302 		// allocate a big chunk to prevent more allocations later. 'segment_size' is
  41303 		// therefore chosen (any other arbitrary value could be chosen).
  41304 		if total_size > segment_size {
  41305 			v1 = total_size
  41306 		} else {
  41307 			v1 = segment_size
  41308 		}
  41309 		(*HuffmanTablesSegment)(unsafe.Pointer(next)).Fsize = v1
  41310 		(*HuffmanTablesSegment)(unsafe.Pointer(next)).Fstart = WebPSafeMalloc(tls, uint64((*HuffmanTablesSegment)(unsafe.Pointer(next)).Fsize), uint64(4))
  41311 		if (*HuffmanTablesSegment)(unsafe.Pointer(next)).Fstart == libc.UintptrFromInt32(0) {
  41312 			WebPSafeFree(tls, next)
  41313 			return 0
  41314 		}
  41315 		(*HuffmanTablesSegment)(unsafe.Pointer(next)).Fcurr_table = (*HuffmanTablesSegment)(unsafe.Pointer(next)).Fstart
  41316 		(*HuffmanTablesSegment)(unsafe.Pointer(next)).Fnext = libc.UintptrFromInt32(0)
  41317 		// Point to the new segment.
  41318 		(*HuffmanTablesSegment)(unsafe.Pointer((*HuffmanTables)(unsafe.Pointer(root_table)).Fcurr_segment)).Fnext = next
  41319 		(*HuffmanTables)(unsafe.Pointer(root_table)).Fcurr_segment = next
  41320 	}
  41321 	if code_lengths_size <= int32(SORTED_SIZE_CUTOFF) {
  41322 		BuildHuffmanTable(tls, (*HuffmanTablesSegment)(unsafe.Pointer((*HuffmanTables)(unsafe.Pointer(root_table)).Fcurr_segment)).Fcurr_table, root_bits, code_lengths, code_lengths_size, bp)
  41323 	} else { // rare case. Use heap allocation.
  41324 		sorted1 = WebPSafeMalloc(tls, uint64(code_lengths_size), uint64(2))
  41325 		if sorted1 == libc.UintptrFromInt32(0) {
  41326 			return 0
  41327 		}
  41328 		BuildHuffmanTable(tls, (*HuffmanTablesSegment)(unsafe.Pointer((*HuffmanTables)(unsafe.Pointer(root_table)).Fcurr_segment)).Fcurr_table, root_bits, code_lengths, code_lengths_size, sorted1)
  41329 		WebPSafeFree(tls, sorted1)
  41330 	}
  41331 	return total_size
  41332 }
  41333 
  41334 func VP8LHuffmanTablesAllocate(tls *libc.TLS, size int32, huffman_tables uintptr) (r int32) {
  41335 	var root uintptr
  41336 	_ = root
  41337 	// Have 'segment' point to the first segment for now, 'root'.
  41338 	root = huffman_tables
  41339 	(*HuffmanTables)(unsafe.Pointer(huffman_tables)).Fcurr_segment = root
  41340 	(*HuffmanTablesSegment)(unsafe.Pointer(root)).Fnext = libc.UintptrFromInt32(0)
  41341 	// Allocate root.
  41342 	(*HuffmanTablesSegment)(unsafe.Pointer(root)).Fstart = WebPSafeMalloc(tls, uint64(size), uint64(4))
  41343 	if (*HuffmanTablesSegment)(unsafe.Pointer(root)).Fstart == libc.UintptrFromInt32(0) {
  41344 		return 0
  41345 	}
  41346 	(*HuffmanTablesSegment)(unsafe.Pointer(root)).Fcurr_table = (*HuffmanTablesSegment)(unsafe.Pointer(root)).Fstart
  41347 	(*HuffmanTablesSegment)(unsafe.Pointer(root)).Fsize = size
  41348 	return int32(1)
  41349 }
  41350 
  41351 func VP8LHuffmanTablesDeallocate(tls *libc.TLS, huffman_tables uintptr) {
  41352 	var current, next uintptr
  41353 	_, _ = current, next
  41354 	if huffman_tables == libc.UintptrFromInt32(0) {
  41355 		return
  41356 	}
  41357 	// Free the root node.
  41358 	current = huffman_tables
  41359 	next = (*HuffmanTablesSegment)(unsafe.Pointer(current)).Fnext
  41360 	WebPSafeFree(tls, (*HuffmanTablesSegment)(unsafe.Pointer(current)).Fstart)
  41361 	(*HuffmanTablesSegment)(unsafe.Pointer(current)).Fstart = libc.UintptrFromInt32(0)
  41362 	(*HuffmanTablesSegment)(unsafe.Pointer(current)).Fnext = libc.UintptrFromInt32(0)
  41363 	current = next
  41364 	// Free the following nodes.
  41365 	for current != libc.UintptrFromInt32(0) {
  41366 		next = (*HuffmanTablesSegment)(unsafe.Pointer(current)).Fnext
  41367 		WebPSafeFree(tls, (*HuffmanTablesSegment)(unsafe.Pointer(current)).Fstart)
  41368 		WebPSafeFree(tls, current)
  41369 		current = next
  41370 	}
  41371 }
  41372 
  41373 const SIZE_MAX19 = "UINT64_MAX"
  41374 
  41375 var kHashMul13 = uint32(0x1e35a7bd)
  41376 
  41377 // Alpha related constants.
  41378 
  41379 // Mux related constants.
  41380 
  41381 // Maximum chunk payload is such that adding the header and padding won't
  41382 // overflow a uint32_t.
  41383 
  41384 // Copyright 2010 Google Inc. All Rights Reserved.
  41385 //
  41386 // Use of this source code is governed by a BSD-style license
  41387 // that can be found in the COPYING file in the root of the source
  41388 // tree. An additional intellectual property rights grant can be found
  41389 // in the file PATENTS. All contributing project authors may
  41390 // be found in the AUTHORS file in the root of the source tree.
  41391 // -----------------------------------------------------------------------------
  41392 //
  41393 //  Common types + memory wrappers
  41394 //
  41395 // Author: Skal (pascal.massimino@gmail.com)
  41396 
  41397 // -----------------------------------------------------------------------------
  41398 
  41399 // Palette reordering for smaller sum of deltas (and for smaller storage).
  41400 
  41401 func PaletteCompareColorsForQsort(tls *libc.TLS, p1 uintptr, p2 uintptr) (r int32) {
  41402 	bp := tls.Alloc(16)
  41403 	defer tls.Free(16)
  41404 	var a, b, v1, v3 uint32_t
  41405 	var v5 int32
  41406 	var _ /* A at bp+0 */ uint32_t
  41407 	_, _, _, _, _ = a, b, v1, v3, v5
  41408 	libc.Xmemcpy(tls, bp, p1, uint64(4))
  41409 	v1 = **(**uint32_t)(__ccgo_up(bp))
  41410 	goto _2
  41411 _2:
  41412 	a = v1
  41413 	libc.Xmemcpy(tls, bp, p2, uint64(4))
  41414 	v3 = **(**uint32_t)(__ccgo_up(bp))
  41415 	goto _4
  41416 _4:
  41417 	b = v3
  41418 	if a < b {
  41419 		v5 = -int32(1)
  41420 	} else {
  41421 		v5 = int32(1)
  41422 	}
  41423 	return v5
  41424 }
  41425 
  41426 func PaletteComponentDistance(tls *libc.TLS, v uint32_t) (r uint32_t) {
  41427 	var v1 uint32
  41428 	_ = v1
  41429 	if v <= uint32(128) {
  41430 		v1 = v
  41431 	} else {
  41432 		v1 = uint32(256) - v
  41433 	}
  41434 	return v1
  41435 }
  41436 
  41437 // C documentation
  41438 //
  41439 //	// Computes a value that is related to the entropy created by the
  41440 //	// palette entry diff.
  41441 //	//
  41442 //	// Note that the last & 0xff is a no-operation in the next statement, but
  41443 //	// removed by most compilers and is here only for regularity of the code.
  41444 func PaletteColorDistance(tls *libc.TLS, col1 uint32_t, col2 uint32_t) (r uint32_t) {
  41445 	var alpha_and_green, diff, red_and_blue, score, v1, v2, v3 uint32_t
  41446 	var kMoreWeightForRGBThanForAlpha int32
  41447 	_, _, _, _, _, _, _, _ = alpha_and_green, diff, kMoreWeightForRGBThanForAlpha, red_and_blue, score, v1, v2, v3
  41448 	v1 = col1
  41449 	v2 = col2
  41450 	alpha_and_green = uint32(0x00ff00ff) + v1&uint32(0xff00ff00) - v2&uint32(0xff00ff00)
  41451 	red_and_blue = uint32(0xff00ff00) + v1&uint32(0x00ff00ff) - v2&uint32(0x00ff00ff)
  41452 	v3 = alpha_and_green&uint32(0xff00ff00) | red_and_blue&uint32(0x00ff00ff)
  41453 	goto _4
  41454 _4:
  41455 	diff = v3
  41456 	kMoreWeightForRGBThanForAlpha = int32(9)
  41457 	score = PaletteComponentDistance(tls, diff>>libc.Int32FromInt32(0)&uint32(0xff))
  41458 	score = score + PaletteComponentDistance(tls, diff>>libc.Int32FromInt32(8)&uint32(0xff))
  41459 	score = score + PaletteComponentDistance(tls, diff>>libc.Int32FromInt32(16)&uint32(0xff))
  41460 	score = score * uint32(kMoreWeightForRGBThanForAlpha)
  41461 	score = score + PaletteComponentDistance(tls, diff>>libc.Int32FromInt32(24)&uint32(0xff))
  41462 	return score
  41463 }
  41464 
  41465 func SwapColor(tls *libc.TLS, col1 uintptr, col2 uintptr) {
  41466 	var tmp uint32_t
  41467 	_ = tmp
  41468 	tmp = **(**uint32_t)(__ccgo_up(col1))
  41469 	**(**uint32_t)(__ccgo_up(col1)) = **(**uint32_t)(__ccgo_up(col2))
  41470 	**(**uint32_t)(__ccgo_up(col2)) = tmp
  41471 }
  41472 
  41473 func SearchColorNoIdx(tls *libc.TLS, sorted uintptr, color uint32_t, num_colors int32) (r int32) {
  41474 	var hi, low, mid int32
  41475 	_, _, _ = hi, low, mid
  41476 	low = 0
  41477 	hi = num_colors
  41478 	if **(**uint32_t)(__ccgo_up(sorted + uintptr(low)*4)) == color {
  41479 		return low
  41480 	} // loop invariant: sorted[low] != color
  41481 	for int32(1) != 0 {
  41482 		mid = (low + hi) >> int32(1)
  41483 		if **(**uint32_t)(__ccgo_up(sorted + uintptr(mid)*4)) == color {
  41484 			return mid
  41485 		} else {
  41486 			if **(**uint32_t)(__ccgo_up(sorted + uintptr(mid)*4)) < color {
  41487 				low = mid
  41488 			} else {
  41489 				hi = mid
  41490 			}
  41491 		}
  41492 	}
  41493 	return 0
  41494 }
  41495 
  41496 func PrepareMapToPalette(tls *libc.TLS, palette uintptr, num_colors uint32_t, sorted uintptr, idx_map uintptr) {
  41497 	var i uint32_t
  41498 	_ = i
  41499 	libc.Xmemcpy(tls, sorted, palette, uint64(num_colors)*uint64(4))
  41500 	libc.Xqsort(tls, sorted, uint64(num_colors), uint64(4), __ccgo_fp(PaletteCompareColorsForQsort))
  41501 	i = uint32(0)
  41502 	for {
  41503 		if !(i < num_colors) {
  41504 			break
  41505 		}
  41506 		**(**uint32_t)(__ccgo_up(idx_map + uintptr(SearchColorNoIdx(tls, sorted, **(**uint32_t)(__ccgo_up(palette + uintptr(i)*4)), int32(num_colors)))*4)) = i
  41507 		goto _1
  41508 	_1:
  41509 		;
  41510 		i = i + 1
  41511 	}
  41512 }
  41513 
  41514 //------------------------------------------------------------------------------
  41515 
  41516 func GetColorPalette(tls *libc.TLS, pic uintptr, palette uintptr) (r int32) {
  41517 	var argb1 uintptr
  41518 	var colors [1024]uint32_t
  41519 	var height, i, key, num_colors, width, x, y, v3 int32
  41520 	var in_use [1024]uint8_t
  41521 	var last_pix uint32_t
  41522 	_, _, _, _, _, _, _, _, _, _, _, _ = argb1, colors, height, i, in_use, key, last_pix, num_colors, width, x, y, v3
  41523 	num_colors = 0
  41524 	in_use = [1024]uint8_t{}
  41525 	colors = [1024]uint32_t{}
  41526 	argb1 = (*WebPPicture)(unsafe.Pointer(pic)).Fargb
  41527 	width = (*WebPPicture)(unsafe.Pointer(pic)).Fwidth
  41528 	height = (*WebPPicture)(unsafe.Pointer(pic)).Fheight
  41529 	last_pix = ^**(**uint32_t)(__ccgo_up(argb1)) // so we're sure that last_pix != argb[0]
  41530 	y = 0
  41531 	for {
  41532 		if !(y < height) {
  41533 			break
  41534 		}
  41535 		x = 0
  41536 		for {
  41537 			if !(x < width) {
  41538 				break
  41539 			}
  41540 			if **(**uint32_t)(__ccgo_up(argb1 + uintptr(x)*4)) == last_pix {
  41541 				goto _2
  41542 			}
  41543 			last_pix = **(**uint32_t)(__ccgo_up(argb1 + uintptr(x)*4))
  41544 			v3 = int32(last_pix * kHashMul13 >> int32(22))
  41545 			goto _4
  41546 		_4:
  41547 			key = v3
  41548 			for int32(1) != 0 {
  41549 				if !(in_use[key] != 0) {
  41550 					colors[key] = last_pix
  41551 					in_use[key] = uint8(1)
  41552 					num_colors = num_colors + 1
  41553 					if num_colors > int32(MAX_PALETTE_SIZE) {
  41554 						return libc.Int32FromInt32(MAX_PALETTE_SIZE) + libc.Int32FromInt32(1) // Exact count not needed.
  41555 					}
  41556 					break
  41557 				} else {
  41558 					if colors[key] == last_pix {
  41559 						break // The color is already there.
  41560 					} else {
  41561 						// Some other color sits here, so do linear conflict resolution.
  41562 						key = key + 1
  41563 						key = key & (libc.Int32FromInt32(MAX_PALETTE_SIZE)*libc.Int32FromInt32(4) - libc.Int32FromInt32(1)) // Key mask.
  41564 					}
  41565 				}
  41566 			}
  41567 			goto _2
  41568 		_2:
  41569 			;
  41570 			x = x + 1
  41571 		}
  41572 		argb1 = argb1 + uintptr((*WebPPicture)(unsafe.Pointer(pic)).Fargb_stride)*4
  41573 		goto _1
  41574 	_1:
  41575 		;
  41576 		y = y + 1
  41577 	}
  41578 	if palette != libc.UintptrFromInt32(0) { // Fill the colors into palette.
  41579 		num_colors = 0
  41580 		i = 0
  41581 		for {
  41582 			if !(i < libc.Int32FromInt32(MAX_PALETTE_SIZE)*libc.Int32FromInt32(4)) {
  41583 				break
  41584 			}
  41585 			if in_use[i] != 0 {
  41586 				**(**uint32_t)(__ccgo_up(palette + uintptr(num_colors)*4)) = colors[i]
  41587 				num_colors = num_colors + 1
  41588 			}
  41589 			goto _5
  41590 		_5:
  41591 			;
  41592 			i = i + 1
  41593 		}
  41594 		libc.Xqsort(tls, palette, uint64(num_colors), uint64(4), __ccgo_fp(PaletteCompareColorsForQsort))
  41595 	}
  41596 	return num_colors
  41597 }
  41598 
  41599 // -----------------------------------------------------------------------------
  41600 
  41601 // C documentation
  41602 //
  41603 //	// The palette has been sorted by alpha. This function checks if the other
  41604 //	// components of the palette have a monotonic development with regards to
  41605 //	// position in the palette. If all have monotonic development, there is
  41606 //	// no benefit to re-organize them greedily. A monotonic development
  41607 //	// would be spotted in green-only situations (like lossy alpha) or gray-scale
  41608 //	// images.
  41609 func PaletteHasNonMonotonousDeltas(tls *libc.TLS, palette uintptr, num_colors int32) (r int32) {
  41610 	var alpha_and_green, diff, predict, red_and_blue, v2, v3, v4 uint32_t
  41611 	var bd, gd, rd, sign_found uint8_t
  41612 	var i, v6 int32
  41613 	_, _, _, _, _, _, _, _, _, _, _, _, _ = alpha_and_green, bd, diff, gd, i, predict, rd, red_and_blue, sign_found, v2, v3, v4, v6
  41614 	predict = uint32(0x000000)
  41615 	sign_found = uint8(0x00)
  41616 	i = 0
  41617 	for {
  41618 		if !(i < num_colors) {
  41619 			break
  41620 		}
  41621 		v2 = **(**uint32_t)(__ccgo_up(palette + uintptr(i)*4))
  41622 		v3 = predict
  41623 		alpha_and_green = uint32(0x00ff00ff) + v2&uint32(0xff00ff00) - v3&uint32(0xff00ff00)
  41624 		red_and_blue = uint32(0xff00ff00) + v2&uint32(0x00ff00ff) - v3&uint32(0x00ff00ff)
  41625 		v4 = alpha_and_green&uint32(0xff00ff00) | red_and_blue&uint32(0x00ff00ff)
  41626 		goto _5
  41627 	_5:
  41628 		diff = v4
  41629 		rd = uint8(diff >> libc.Int32FromInt32(16) & uint32(0xff))
  41630 		gd = uint8(diff >> libc.Int32FromInt32(8) & uint32(0xff))
  41631 		bd = uint8(diff >> libc.Int32FromInt32(0) & uint32(0xff))
  41632 		if int32(rd) != 0x00 {
  41633 			if int32(rd) < int32(0x80) {
  41634 				v6 = int32(1)
  41635 			} else {
  41636 				v6 = int32(2)
  41637 			}
  41638 			sign_found = uint8(int32(sign_found) | v6)
  41639 		}
  41640 		if int32(gd) != 0x00 {
  41641 			if int32(gd) < int32(0x80) {
  41642 				v6 = int32(8)
  41643 			} else {
  41644 				v6 = int32(16)
  41645 			}
  41646 			sign_found = uint8(int32(sign_found) | v6)
  41647 		}
  41648 		if int32(bd) != 0x00 {
  41649 			if int32(bd) < int32(0x80) {
  41650 				v6 = int32(64)
  41651 			} else {
  41652 				v6 = int32(128)
  41653 			}
  41654 			sign_found = uint8(int32(sign_found) | v6)
  41655 		}
  41656 		predict = **(**uint32_t)(__ccgo_up(palette + uintptr(i)*4))
  41657 		goto _1
  41658 	_1:
  41659 		;
  41660 		i = i + 1
  41661 	}
  41662 	return libc.BoolInt32(int32(sign_found)&(int32(sign_found)<<int32(1)) != 0) // two consequent signs.
  41663 }
  41664 
  41665 func PaletteSortMinimizeDeltas(tls *libc.TLS, palette_sorted uintptr, num_colors int32, palette uintptr) {
  41666 	var best_ix, i, k int32
  41667 	var best_score, cur_score, predict uint32_t
  41668 	_, _, _, _, _, _ = best_ix, best_score, cur_score, i, k, predict
  41669 	predict = uint32(0x00000000)
  41670 	libc.Xmemcpy(tls, palette, palette_sorted, uint64(num_colors)*uint64(4))
  41671 	if !(PaletteHasNonMonotonousDeltas(tls, palette_sorted, num_colors) != 0) {
  41672 		return
  41673 	}
  41674 	// Find greedily always the closest color of the predicted color to minimize
  41675 	// deltas in the palette. This reduces storage needs since the
  41676 	// palette is stored with delta encoding.
  41677 	if num_colors > int32(17) {
  41678 		if **(**uint32_t)(__ccgo_up(palette)) == uint32(0) {
  41679 			num_colors = num_colors - 1
  41680 			SwapColor(tls, palette+uintptr(num_colors)*4, palette)
  41681 		}
  41682 	}
  41683 	i = 0
  41684 	for {
  41685 		if !(i < num_colors) {
  41686 			break
  41687 		}
  41688 		best_ix = i
  41689 		best_score = ^libc.Uint32FromUint32(0)
  41690 		k = i
  41691 		for {
  41692 			if !(k < num_colors) {
  41693 				break
  41694 			}
  41695 			cur_score = PaletteColorDistance(tls, **(**uint32_t)(__ccgo_up(palette + uintptr(k)*4)), predict)
  41696 			if best_score > cur_score {
  41697 				best_score = cur_score
  41698 				best_ix = k
  41699 			}
  41700 			goto _2
  41701 		_2:
  41702 			;
  41703 			k = k + 1
  41704 		}
  41705 		SwapColor(tls, palette+uintptr(best_ix)*4, palette+uintptr(i)*4)
  41706 		predict = **(**uint32_t)(__ccgo_up(palette + uintptr(i)*4))
  41707 		goto _1
  41708 	_1:
  41709 		;
  41710 		i = i + 1
  41711 	}
  41712 }
  41713 
  41714 // -----------------------------------------------------------------------------
  41715 // Modified Zeng method from "A Survey on Palette Reordering
  41716 // Methods for Improving the Compression of Color-Indexed Images" by Armando J.
  41717 // Pinho and Antonio J. R. Neves.
  41718 
  41719 // C documentation
  41720 //
  41721 //	// Finds the biggest cooccurrence in the matrix.
  41722 func CoOccurrenceFindMax(tls *libc.TLS, cooccurrence uintptr, num_colors uint32_t, c1 uintptr, c2 uintptr) {
  41723 	var best_cooccurrence, best_sum, i, j, sum uint32_t
  41724 	_, _, _, _, _ = best_cooccurrence, best_sum, i, j, sum
  41725 	// Find the index that is most frequently located adjacent to other
  41726 	// (different) indexes.
  41727 	best_sum = 0
  41728 	**(**uint8_t)(__ccgo_up(c1)) = 0
  41729 	i = uint32(0)
  41730 	for {
  41731 		if !(i < num_colors) {
  41732 			break
  41733 		}
  41734 		sum = uint32(0)
  41735 		j = uint32(0)
  41736 		for {
  41737 			if !(j < num_colors) {
  41738 				break
  41739 			}
  41740 			sum = sum + **(**uint32_t)(__ccgo_up(cooccurrence + uintptr(i*num_colors+j)*4))
  41741 			goto _2
  41742 		_2:
  41743 			;
  41744 			j = j + 1
  41745 		}
  41746 		if sum > best_sum {
  41747 			best_sum = sum
  41748 			**(**uint8_t)(__ccgo_up(c1)) = uint8(i)
  41749 		}
  41750 		goto _1
  41751 	_1:
  41752 		;
  41753 		i = i + 1
  41754 	}
  41755 	// Find the index that is most frequently found adjacent to *c1.
  41756 	**(**uint8_t)(__ccgo_up(c2)) = 0
  41757 	best_cooccurrence = 0
  41758 	i = uint32(0)
  41759 	for {
  41760 		if !(i < num_colors) {
  41761 			break
  41762 		}
  41763 		if **(**uint32_t)(__ccgo_up(cooccurrence + uintptr(uint32(**(**uint8_t)(__ccgo_up(c1)))*num_colors+i)*4)) > best_cooccurrence {
  41764 			best_cooccurrence = **(**uint32_t)(__ccgo_up(cooccurrence + uintptr(uint32(**(**uint8_t)(__ccgo_up(c1)))*num_colors+i)*4))
  41765 			**(**uint8_t)(__ccgo_up(c2)) = uint8(i)
  41766 		}
  41767 		goto _3
  41768 	_3:
  41769 		;
  41770 		i = i + 1
  41771 	}
  41772 }
  41773 
  41774 // C documentation
  41775 //
  41776 //	// Builds the cooccurrence matrix
  41777 func CoOccurrenceBuild(tls *libc.TLS, pic uintptr, palette uintptr, num_colors uint32_t, cooccurrence uintptr) (r int32) {
  41778 	bp := tls.Alloc(2048)
  41779 	defer tls.Free(2048)
  41780 	var left_idx, pix, prev_idx, prev_pix, top_idx uint32_t
  41781 	var line_current, line_tmp, line_top, lines, src uintptr
  41782 	var x, y int32
  41783 	var _ /* idx_map at bp+0 */ [256]uint32_t
  41784 	var _ /* palette_sorted at bp+1024 */ [256]uint32_t
  41785 	_, _, _, _, _, _, _, _, _, _, _, _ = left_idx, line_current, line_tmp, line_top, lines, pix, prev_idx, prev_pix, src, top_idx, x, y
  41786 	src = (*WebPPicture)(unsafe.Pointer(pic)).Fargb
  41787 	prev_pix = ^**(**uint32_t)(__ccgo_up(src))
  41788 	prev_idx = 0
  41789 	**(**[256]uint32_t)(__ccgo_up(bp)) = [256]uint32_t{}
  41790 	lines = WebPSafeMalloc(tls, uint64(int32(2)*(*WebPPicture)(unsafe.Pointer(pic)).Fwidth), uint64(4))
  41791 	if lines == libc.UintptrFromInt32(0) {
  41792 		return 0
  41793 	}
  41794 	line_top = lines
  41795 	line_current = lines + uintptr((*WebPPicture)(unsafe.Pointer(pic)).Fwidth)*4
  41796 	PrepareMapToPalette(tls, palette, num_colors, bp+1024, bp)
  41797 	y = 0
  41798 	for {
  41799 		if !(y < (*WebPPicture)(unsafe.Pointer(pic)).Fheight) {
  41800 			break
  41801 		}
  41802 		x = 0
  41803 		for {
  41804 			if !(x < (*WebPPicture)(unsafe.Pointer(pic)).Fwidth) {
  41805 				break
  41806 			}
  41807 			pix = **(**uint32_t)(__ccgo_up(src + uintptr(x)*4))
  41808 			if pix != prev_pix {
  41809 				prev_idx = (**(**[256]uint32_t)(__ccgo_up(bp)))[SearchColorNoIdx(tls, bp+1024, pix, int32(num_colors))]
  41810 				prev_pix = pix
  41811 			}
  41812 			**(**uint32_t)(__ccgo_up(line_current + uintptr(x)*4)) = prev_idx
  41813 			// 4-connectivity is what works best as mentioned in "On the relation
  41814 			// between Memon's and the modified Zeng's palette reordering methods".
  41815 			if x > 0 && prev_idx != **(**uint32_t)(__ccgo_up(line_current + uintptr(x-int32(1))*4)) {
  41816 				left_idx = **(**uint32_t)(__ccgo_up(line_current + uintptr(x-int32(1))*4))
  41817 				**(**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
  41818 				**(**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
  41819 			}
  41820 			if y > 0 && prev_idx != **(**uint32_t)(__ccgo_up(line_top + uintptr(x)*4)) {
  41821 				top_idx = **(**uint32_t)(__ccgo_up(line_top + uintptr(x)*4))
  41822 				**(**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
  41823 				**(**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
  41824 			}
  41825 			goto _2
  41826 		_2:
  41827 			;
  41828 			x = x + 1
  41829 		}
  41830 		line_tmp = line_top
  41831 		line_top = line_current
  41832 		line_current = line_tmp
  41833 		src = src + uintptr((*WebPPicture)(unsafe.Pointer(pic)).Fargb_stride)*4
  41834 		goto _1
  41835 	_1:
  41836 		;
  41837 		y = y + 1
  41838 	}
  41839 	WebPSafeFree(tls, lines)
  41840 	return int32(1)
  41841 }
  41842 
  41843 type Sum = struct {
  41844 	Findex uint8_t
  41845 	Fsum   uint32_t
  41846 }
  41847 
  41848 func PaletteSortModifiedZeng(tls *libc.TLS, pic uintptr, palette_in uintptr, num_colors uint32_t, palette uintptr) (r int32) {
  41849 	bp := tls.Alloc(2304)
  41850 	defer tls.Free(2304)
  41851 	var best_index uint8_t
  41852 	var best_sum, cooccurrence uintptr
  41853 	var delta, n int32_t
  41854 	var first, i, ind, j, last, num_sums uint32_t
  41855 	var l_j uint16_t
  41856 	var v3 uint32
  41857 	var _ /* remapping at bp+0 */ [256]uint8_t
  41858 	var _ /* sums at bp+256 */ [256]Sum
  41859 	_, _, _, _, _, _, _, _, _, _, _, _, _ = best_index, best_sum, cooccurrence, delta, first, i, ind, j, l_j, last, n, num_sums, v3
  41860 	// TODO(vrabaud) check whether one color images should use palette or not.
  41861 	if num_colors <= uint32(1) {
  41862 		return int32(1)
  41863 	}
  41864 	// Build the co-occurrence matrix.
  41865 	cooccurrence = WebPSafeCalloc(tls, uint64(num_colors*num_colors), uint64(4))
  41866 	if cooccurrence == libc.UintptrFromInt32(0) {
  41867 		return 0
  41868 	}
  41869 	if !(CoOccurrenceBuild(tls, pic, palette_in, num_colors, cooccurrence) != 0) {
  41870 		WebPSafeFree(tls, cooccurrence)
  41871 		return 0
  41872 	}
  41873 	// Initialize the mapping list with the two best indices.
  41874 	CoOccurrenceFindMax(tls, cooccurrence, num_colors, bp, bp+1)
  41875 	// We need to append and prepend to the list of remapping. To this end, we
  41876 	// actually define the next start/end of the list as indices in a vector (with
  41877 	// a wrap around when the end is reached).
  41878 	first = uint32(0)
  41879 	last = uint32(1)
  41880 	num_sums = num_colors - uint32(2) // -2 because we know the first two values
  41881 	if num_sums > uint32(0) {
  41882 		// Initialize the sums with the first two remappings and find the best one
  41883 		best_sum = bp + 256
  41884 		(*Sum)(unsafe.Pointer(best_sum)).Findex = 0
  41885 		(*Sum)(unsafe.Pointer(best_sum)).Fsum = 0
  41886 		i = uint32(0)
  41887 		j = libc.Uint32FromInt32(0)
  41888 		for {
  41889 			if !(i < num_colors) {
  41890 				break
  41891 			}
  41892 			if i == uint32((**(**[256]uint8_t)(__ccgo_up(bp)))[0]) || i == uint32((**(**[256]uint8_t)(__ccgo_up(bp)))[int32(1)]) {
  41893 				goto _1
  41894 			}
  41895 			(**(**[256]Sum)(__ccgo_up(bp + 256)))[j].Findex = uint8(i)
  41896 			(**(**[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))
  41897 			if (**(**[256]Sum)(__ccgo_up(bp + 256)))[j].Fsum > (*Sum)(unsafe.Pointer(best_sum)).Fsum {
  41898 				best_sum = bp + 256 + uintptr(j)*8
  41899 			}
  41900 			j = j + 1
  41901 			goto _1
  41902 		_1:
  41903 			;
  41904 			i = i + 1
  41905 		}
  41906 		for num_sums > uint32(0) {
  41907 			best_index = (*Sum)(unsafe.Pointer(best_sum)).Findex
  41908 			// Compute delta to know if we need to prepend or append the best index.
  41909 			delta = 0
  41910 			n = int32(num_colors - num_sums)
  41911 			ind = first
  41912 			j = libc.Uint32FromInt32(0)
  41913 			for {
  41914 				if !((ind+j)%num_colors != last+uint32(1)) {
  41915 					break
  41916 				}
  41917 				l_j = uint16((**(**[256]uint8_t)(__ccgo_up(bp)))[(ind+j)%num_colors])
  41918 				delta = delta + (n-int32(1)-int32(2)*int32(j))*int32(**(**uint32_t)(__ccgo_up(cooccurrence + uintptr(uint32(best_index)*num_colors+uint32(l_j))*4)))
  41919 				goto _2
  41920 			_2:
  41921 				;
  41922 				j = j + 1
  41923 			}
  41924 			if delta > 0 {
  41925 				if first == uint32(0) {
  41926 					v3 = num_colors - uint32(1)
  41927 				} else {
  41928 					v3 = first - uint32(1)
  41929 				}
  41930 				first = v3
  41931 				(**(**[256]uint8_t)(__ccgo_up(bp)))[first] = best_index
  41932 			} else {
  41933 				last = last + 1
  41934 				(**(**[256]uint8_t)(__ccgo_up(bp)))[last] = best_index
  41935 			}
  41936 			// Remove best_sum from sums.
  41937 			**(**Sum)(__ccgo_up(best_sum)) = (**(**[256]Sum)(__ccgo_up(bp + 256)))[num_sums-uint32(1)]
  41938 			num_sums = num_sums - 1
  41939 			// Update all the sums and find the best one.
  41940 			best_sum = bp + 256
  41941 			i = uint32(0)
  41942 			for {
  41943 				if !(i < num_sums) {
  41944 					break
  41945 				}
  41946 				(**(**[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))
  41947 				if (**(**[256]Sum)(__ccgo_up(bp + 256)))[i].Fsum > (*Sum)(unsafe.Pointer(best_sum)).Fsum {
  41948 					best_sum = bp + 256 + uintptr(i)*8
  41949 				}
  41950 				goto _4
  41951 			_4:
  41952 				;
  41953 				i = i + 1
  41954 			}
  41955 		}
  41956 	}
  41957 	WebPSafeFree(tls, cooccurrence)
  41958 	// Re-map the palette.
  41959 	i = uint32(0)
  41960 	for {
  41961 		if !(i < num_colors) {
  41962 			break
  41963 		}
  41964 		**(**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))
  41965 		goto _5
  41966 	_5:
  41967 		;
  41968 		i = i + 1
  41969 	}
  41970 	return int32(1)
  41971 }
  41972 
  41973 // -----------------------------------------------------------------------------
  41974 
  41975 func PaletteSort(tls *libc.TLS, method PaletteSorting1, pic uintptr, palette_sorted uintptr, num_colors uint32_t, palette uintptr) (r int32) {
  41976 	switch method {
  41977 	case int32(kSortedDefault):
  41978 		if **(**uint32_t)(__ccgo_up(palette_sorted)) == uint32(0) && num_colors > uint32(17) {
  41979 			libc.Xmemcpy(tls, palette, palette_sorted+uintptr(1)*4, uint64(num_colors-libc.Uint32FromInt32(1))*uint64(4))
  41980 			**(**uint32_t)(__ccgo_up(palette + uintptr(num_colors-uint32(1))*4)) = uint32(0)
  41981 		} else {
  41982 			libc.Xmemcpy(tls, palette, palette_sorted, uint64(num_colors)*uint64(4))
  41983 		}
  41984 		return int32(1)
  41985 	case int32(kMinimizeDelta):
  41986 		PaletteSortMinimizeDeltas(tls, palette_sorted, int32(num_colors), palette)
  41987 		return int32(1)
  41988 	case int32(kModifiedZeng):
  41989 		return PaletteSortModifiedZeng(tls, pic, palette_sorted, num_colors, palette)
  41990 	case int32(kUnusedPalette):
  41991 		fallthrough
  41992 	case int32(kPaletteSortingNum):
  41993 		break
  41994 	}
  41995 	return 0
  41996 }
  41997 
  41998 const DFIX = 0
  41999 const FIX = 16
  42000 const LFIX = 2
  42001 
  42002 //------------------------------------------------------------------------------
  42003 
  42004 // Copyright 2010 Google Inc. All Rights Reserved.
  42005 //
  42006 // Use of this source code is governed by a BSD-style license
  42007 // that can be found in the COPYING file in the root of the source
  42008 // tree. An additional intellectual property rights grant can be found
  42009 // in the file PATENTS. All contributing project authors may
  42010 // be found in the AUTHORS file in the root of the source tree.
  42011 // -----------------------------------------------------------------------------
  42012 //
  42013 //  Common types + memory wrappers
  42014 //
  42015 // Author: Skal (pascal.massimino@gmail.com)
  42016 
  42017 // #define USE_DITHERING   // uncomment to enable ordered dithering (not vital)
  42018 
  42019 type SmoothParams = struct {
  42020 	Fwidth          int32
  42021 	Fheight         int32
  42022 	Fstride         int32
  42023 	Frow            int32
  42024 	Fsrc            uintptr
  42025 	Fdst            uintptr
  42026 	Fradius         int32
  42027 	Fscale          int32
  42028 	Fmem            uintptr
  42029 	Fstart          uintptr
  42030 	Fcur            uintptr
  42031 	Fend            uintptr
  42032 	Ftop            uintptr
  42033 	Faverage        uintptr
  42034 	Fnum_levels     int32
  42035 	Fmin            int32
  42036 	Fmax            int32
  42037 	Fmin_level_dist int32
  42038 	Fcorrection     uintptr
  42039 }
  42040 
  42041 //------------------------------------------------------------------------------
  42042 
  42043 func clip_8b(tls *libc.TLS, v int32) (r uint8_t) {
  42044 	var v1, v2 uint32
  42045 	_, _ = v1, v2
  42046 	if !(v&int32(^libc.Uint32FromUint32(0)<<(libc.Int32FromInt32(8)+libc.Int32FromInt32(DFIX))) != 0) {
  42047 		v1 = uint32(uint8(v >> libc.Int32FromInt32(DFIX)))
  42048 	} else {
  42049 		if v < 0 {
  42050 			v2 = 0
  42051 		} else {
  42052 			v2 = uint32(255)
  42053 		}
  42054 		v1 = v2
  42055 	}
  42056 	return uint8(v1)
  42057 }
  42058 
  42059 // C documentation
  42060 //
  42061 //	// vertical accumulation
  42062 func VFilter(tls *libc.TLS, p uintptr) {
  42063 	var cur, out, src, top uintptr
  42064 	var new_value, sum uint16_t
  42065 	var w, x int32
  42066 	_, _, _, _, _, _, _, _ = cur, new_value, out, src, sum, top, w, x
  42067 	src = (*SmoothParams)(unsafe.Pointer(p)).Fsrc
  42068 	w = (*SmoothParams)(unsafe.Pointer(p)).Fwidth
  42069 	cur = (*SmoothParams)(unsafe.Pointer(p)).Fcur
  42070 	top = (*SmoothParams)(unsafe.Pointer(p)).Ftop
  42071 	out = (*SmoothParams)(unsafe.Pointer(p)).Fend
  42072 	sum = uint16(0)
  42073 	x = 0
  42074 	for {
  42075 		if !(x < w) {
  42076 			break
  42077 		}
  42078 		sum = uint16(int32(sum) + int32(**(**uint8_t)(__ccgo_up(src + uintptr(x)))))
  42079 		new_value = uint16(int32(**(**uint16_t)(__ccgo_up(top + uintptr(x)*2))) + int32(sum))
  42080 		**(**uint16_t)(__ccgo_up(out + uintptr(x)*2)) = uint16(int32(new_value) - int32(**(**uint16_t)(__ccgo_up(cur + uintptr(x)*2)))) // vertical sum of 'r' pixels.
  42081 		**(**uint16_t)(__ccgo_up(cur + uintptr(x)*2)) = new_value
  42082 		goto _1
  42083 	_1:
  42084 		;
  42085 		x = x + 1
  42086 	}
  42087 	// move input pointers one row down
  42088 	(*SmoothParams)(unsafe.Pointer(p)).Ftop = (*SmoothParams)(unsafe.Pointer(p)).Fcur
  42089 	**(**uintptr)(__ccgo_up(p + 56)) += uintptr(w) * 2
  42090 	if (*SmoothParams)(unsafe.Pointer(p)).Fcur == (*SmoothParams)(unsafe.Pointer(p)).Fend {
  42091 		(*SmoothParams)(unsafe.Pointer(p)).Fcur = (*SmoothParams)(unsafe.Pointer(p)).Fstart
  42092 	} // roll-over
  42093 	// We replicate edges, as it's somewhat easier as a boundary condition.
  42094 	// That's why we don't update the 'src' pointer on top/bottom area:
  42095 	if (*SmoothParams)(unsafe.Pointer(p)).Frow >= 0 && (*SmoothParams)(unsafe.Pointer(p)).Frow < (*SmoothParams)(unsafe.Pointer(p)).Fheight-int32(1) {
  42096 		**(**uintptr)(__ccgo_up(p + 16)) += uintptr((*SmoothParams)(unsafe.Pointer(p)).Fstride)
  42097 	}
  42098 }
  42099 
  42100 // C documentation
  42101 //
  42102 //	// horizontal accumulation. We use mirror replication of missing pixels, as it's
  42103 //	// a little easier to implement (surprisingly).
  42104 func HFilter(tls *libc.TLS, p uintptr) {
  42105 	var delta, delta1, delta2 uint16_t
  42106 	var in, out uintptr
  42107 	var r, w, x int32
  42108 	var scale uint32_t
  42109 	_, _, _, _, _, _, _, _, _ = delta, delta1, delta2, in, out, r, scale, w, x
  42110 	in = (*SmoothParams)(unsafe.Pointer(p)).Fend
  42111 	out = (*SmoothParams)(unsafe.Pointer(p)).Faverage
  42112 	scale = uint32((*SmoothParams)(unsafe.Pointer(p)).Fscale)
  42113 	w = (*SmoothParams)(unsafe.Pointer(p)).Fwidth
  42114 	r = (*SmoothParams)(unsafe.Pointer(p)).Fradius
  42115 	x = 0
  42116 	for {
  42117 		if !(x <= r) {
  42118 			break
  42119 		} // left mirroring
  42120 		delta = uint16(int32(**(**uint16_t)(__ccgo_up(in + uintptr(x+r-int32(1))*2))) + int32(**(**uint16_t)(__ccgo_up(in + uintptr(r-x)*2))))
  42121 		**(**uint16_t)(__ccgo_up(out + uintptr(x)*2)) = uint16(uint32(delta) * scale >> int32(FIX))
  42122 		goto _1
  42123 	_1:
  42124 		;
  42125 		x = x + 1
  42126 	}
  42127 	for {
  42128 		if !(x < w-r) {
  42129 			break
  42130 		} // bulk middle run
  42131 		delta1 = uint16(int32(**(**uint16_t)(__ccgo_up(in + uintptr(x+r)*2))) - int32(**(**uint16_t)(__ccgo_up(in + uintptr(x-r-int32(1))*2))))
  42132 		**(**uint16_t)(__ccgo_up(out + uintptr(x)*2)) = uint16(uint32(delta1) * scale >> int32(FIX))
  42133 		goto _2
  42134 	_2:
  42135 		;
  42136 		x = x + 1
  42137 	}
  42138 	for {
  42139 		if !(x < w) {
  42140 			break
  42141 		} // right mirroring
  42142 		delta2 = uint16(int32(2)*int32(**(**uint16_t)(__ccgo_up(in + uintptr(w-int32(1))*2))) - int32(**(**uint16_t)(__ccgo_up(in + uintptr(int32(2)*w-int32(2)-r-x)*2))) - int32(**(**uint16_t)(__ccgo_up(in + uintptr(x-r-int32(1))*2))))
  42143 		**(**uint16_t)(__ccgo_up(out + uintptr(x)*2)) = uint16(uint32(delta2) * scale >> int32(FIX))
  42144 		goto _3
  42145 	_3:
  42146 		;
  42147 		x = x + 1
  42148 	}
  42149 }
  42150 
  42151 // C documentation
  42152 //
  42153 //	// emit one filtered output row
  42154 func ApplyFilter(tls *libc.TLS, p uintptr) {
  42155 	var average, correction, dst uintptr
  42156 	var c, v, w, x int32
  42157 	_, _, _, _, _, _, _ = average, c, correction, dst, v, w, x
  42158 	average = (*SmoothParams)(unsafe.Pointer(p)).Faverage
  42159 	w = (*SmoothParams)(unsafe.Pointer(p)).Fwidth
  42160 	correction = (*SmoothParams)(unsafe.Pointer(p)).Fcorrection
  42161 	dst = (*SmoothParams)(unsafe.Pointer(p)).Fdst
  42162 	x = 0
  42163 	for {
  42164 		if !(x < w) {
  42165 			break
  42166 		}
  42167 		v = int32(**(**uint8_t)(__ccgo_up(dst + uintptr(x))))
  42168 		if v < (*SmoothParams)(unsafe.Pointer(p)).Fmax && v > (*SmoothParams)(unsafe.Pointer(p)).Fmin {
  42169 			c = v<<libc.Int32FromInt32(DFIX) + int32(**(**int16_t)(__ccgo_up(correction + uintptr(int32(**(**uint16_t)(__ccgo_up(average + uintptr(x)*2)))-v<<libc.Int32FromInt32(LFIX))*2)))
  42170 			**(**uint8_t)(__ccgo_up(dst + uintptr(x))) = clip_8b(tls, c)
  42171 		}
  42172 		goto _1
  42173 	_1:
  42174 		;
  42175 		x = x + 1
  42176 	}
  42177 	**(**uintptr)(__ccgo_up(p + 24)) += uintptr((*SmoothParams)(unsafe.Pointer(p)).Fstride) // advance output pointer
  42178 }
  42179 
  42180 //------------------------------------------------------------------------------
  42181 // Initialize correction table
  42182 
  42183 func InitCorrectionLUT(tls *libc.TLS, lut uintptr, min_dist int32) {
  42184 	var c, delta, i, max_threshold, threshold1, threshold2, v2, v3 int32
  42185 	_, _, _, _, _, _, _, _ = c, delta, i, max_threshold, threshold1, threshold2, v2, v3
  42186 	// The correction curve is:
  42187 	//   f(x) = x for x <= threshold2
  42188 	//   f(x) = 0 for x >= threshold1
  42189 	// and a linear interpolation for range x=[threshold2, threshold1]
  42190 	// (along with f(-x) = -f(x) symmetry).
  42191 	// Note that: threshold2 = 3/4 * threshold1
  42192 	threshold1 = min_dist << int32(LFIX)
  42193 	threshold2 = int32(3) * threshold1 >> int32(2)
  42194 	max_threshold = threshold2 << DFIX
  42195 	delta = threshold1 - threshold2
  42196 	i = int32(1)
  42197 	for {
  42198 		if !(i <= libc.Int32FromInt32(1)<<(libc.Int32FromInt32(8)+libc.Int32FromInt32(LFIX))-libc.Int32FromInt32(1)) {
  42199 			break
  42200 		}
  42201 		if i <= threshold2 {
  42202 			v2 = i << DFIX
  42203 		} else {
  42204 			if i < threshold1 {
  42205 				v3 = max_threshold * (threshold1 - i) / delta
  42206 			} else {
  42207 				v3 = 0
  42208 			}
  42209 			v2 = v3
  42210 		}
  42211 		c = v2
  42212 		c = c >> int32(LFIX)
  42213 		**(**int16_t)(__ccgo_up(lut + uintptr(+i)*2)) = int16(+c)
  42214 		**(**int16_t)(__ccgo_up(lut + uintptr(-i)*2)) = int16(-c)
  42215 		goto _1
  42216 	_1:
  42217 		;
  42218 		i = i + 1
  42219 	}
  42220 	**(**int16_t)(__ccgo_up(lut)) = 0
  42221 }
  42222 
  42223 func CountLevels(tls *libc.TLS, p uintptr) {
  42224 	var data uintptr
  42225 	var i, j, last_level, level_dist, v int32
  42226 	var used_levels [256]uint8_t
  42227 	_, _, _, _, _, _, _ = data, i, j, last_level, level_dist, used_levels, v
  42228 	used_levels = [256]uint8_t{}
  42229 	data = (*SmoothParams)(unsafe.Pointer(p)).Fsrc
  42230 	(*SmoothParams)(unsafe.Pointer(p)).Fmin = int32(255)
  42231 	(*SmoothParams)(unsafe.Pointer(p)).Fmax = 0
  42232 	j = 0
  42233 	for {
  42234 		if !(j < (*SmoothParams)(unsafe.Pointer(p)).Fheight) {
  42235 			break
  42236 		}
  42237 		i = 0
  42238 		for {
  42239 			if !(i < (*SmoothParams)(unsafe.Pointer(p)).Fwidth) {
  42240 				break
  42241 			}
  42242 			v = int32(**(**uint8_t)(__ccgo_up(data + uintptr(i))))
  42243 			if v < (*SmoothParams)(unsafe.Pointer(p)).Fmin {
  42244 				(*SmoothParams)(unsafe.Pointer(p)).Fmin = v
  42245 			}
  42246 			if v > (*SmoothParams)(unsafe.Pointer(p)).Fmax {
  42247 				(*SmoothParams)(unsafe.Pointer(p)).Fmax = v
  42248 			}
  42249 			used_levels[v] = uint8(1)
  42250 			goto _2
  42251 		_2:
  42252 			;
  42253 			i = i + 1
  42254 		}
  42255 		data = data + uintptr((*SmoothParams)(unsafe.Pointer(p)).Fstride)
  42256 		goto _1
  42257 	_1:
  42258 		;
  42259 		j = j + 1
  42260 	}
  42261 	// Compute the mininum distance between two non-zero levels.
  42262 	(*SmoothParams)(unsafe.Pointer(p)).Fmin_level_dist = (*SmoothParams)(unsafe.Pointer(p)).Fmax - (*SmoothParams)(unsafe.Pointer(p)).Fmin
  42263 	last_level = -int32(1)
  42264 	i = 0
  42265 	for {
  42266 		if !(i < int32(256)) {
  42267 			break
  42268 		}
  42269 		if used_levels[i] != 0 {
  42270 			(*SmoothParams)(unsafe.Pointer(p)).Fnum_levels = (*SmoothParams)(unsafe.Pointer(p)).Fnum_levels + 1
  42271 			if last_level >= 0 {
  42272 				level_dist = i - last_level
  42273 				if level_dist < (*SmoothParams)(unsafe.Pointer(p)).Fmin_level_dist {
  42274 					(*SmoothParams)(unsafe.Pointer(p)).Fmin_level_dist = level_dist
  42275 				}
  42276 			}
  42277 			last_level = i
  42278 		}
  42279 		goto _3
  42280 	_3:
  42281 		;
  42282 		i = i + 1
  42283 	}
  42284 }
  42285 
  42286 // C documentation
  42287 //
  42288 //	// Initialize all params.
  42289 func InitParams(tls *libc.TLS, data uintptr, width int32, height int32, stride int32, radius int32, p uintptr) (r int32) {
  42290 	var R int32
  42291 	var mem uintptr
  42292 	var size_lut, size_m, size_scratch_m, total_size size_t
  42293 	_, _, _, _, _, _ = R, mem, size_lut, size_m, size_scratch_m, total_size
  42294 	R = int32(2)*radius + int32(1) // total size of the kernel
  42295 	size_scratch_m = uint64((R+int32(1))*width) * uint64(2)
  42296 	size_m = uint64(width) * uint64(2)
  42297 	size_lut = uint64(libc.Int32FromInt32(1)+libc.Int32FromInt32(2)*(libc.Int32FromInt32(1)<<(libc.Int32FromInt32(8)+libc.Int32FromInt32(LFIX))-libc.Int32FromInt32(1))) * libc.Uint64FromInt64(2)
  42298 	total_size = size_scratch_m + size_m + size_lut
  42299 	mem = WebPSafeMalloc(tls, uint64(1), total_size)
  42300 	if mem == libc.UintptrFromInt32(0) {
  42301 		return 0
  42302 	}
  42303 	(*SmoothParams)(unsafe.Pointer(p)).Fmem = mem
  42304 	(*SmoothParams)(unsafe.Pointer(p)).Fstart = mem
  42305 	(*SmoothParams)(unsafe.Pointer(p)).Fcur = (*SmoothParams)(unsafe.Pointer(p)).Fstart
  42306 	(*SmoothParams)(unsafe.Pointer(p)).Fend = (*SmoothParams)(unsafe.Pointer(p)).Fstart + uintptr(R*width)*2
  42307 	(*SmoothParams)(unsafe.Pointer(p)).Ftop = (*SmoothParams)(unsafe.Pointer(p)).Fend - uintptr(width)*2
  42308 	libc.Xmemset(tls, (*SmoothParams)(unsafe.Pointer(p)).Ftop, 0, uint64(width)*uint64(2))
  42309 	mem = mem + uintptr(size_scratch_m)
  42310 	(*SmoothParams)(unsafe.Pointer(p)).Faverage = mem
  42311 	mem = mem + uintptr(size_m)
  42312 	(*SmoothParams)(unsafe.Pointer(p)).Fwidth = width
  42313 	(*SmoothParams)(unsafe.Pointer(p)).Fheight = height
  42314 	(*SmoothParams)(unsafe.Pointer(p)).Fstride = stride
  42315 	(*SmoothParams)(unsafe.Pointer(p)).Fsrc = data
  42316 	(*SmoothParams)(unsafe.Pointer(p)).Fdst = data
  42317 	(*SmoothParams)(unsafe.Pointer(p)).Fradius = radius
  42318 	(*SmoothParams)(unsafe.Pointer(p)).Fscale = libc.Int32FromInt32(1) << (libc.Int32FromInt32(FIX) + libc.Int32FromInt32(LFIX)) / (R * R) // normalization constant
  42319 	(*SmoothParams)(unsafe.Pointer(p)).Frow = -radius
  42320 	// analyze the input distribution so we can best-fit the threshold
  42321 	CountLevels(tls, p)
  42322 	// correction table
  42323 	(*SmoothParams)(unsafe.Pointer(p)).Fcorrection = mem + uintptr(libc.Int32FromInt32(1)<<(libc.Int32FromInt32(8)+libc.Int32FromInt32(LFIX))-libc.Int32FromInt32(1))*2
  42324 	InitCorrectionLUT(tls, (*SmoothParams)(unsafe.Pointer(p)).Fcorrection, (*SmoothParams)(unsafe.Pointer(p)).Fmin_level_dist)
  42325 	return int32(1)
  42326 }
  42327 
  42328 func CleanupParams(tls *libc.TLS, p uintptr) {
  42329 	WebPSafeFree(tls, (*SmoothParams)(unsafe.Pointer(p)).Fmem)
  42330 }
  42331 
  42332 func WebPDequantizeLevels(tls *libc.TLS, data uintptr, width int32, height int32, stride int32, strength int32) (r int32) {
  42333 	bp := tls.Alloc(112)
  42334 	defer tls.Free(112)
  42335 	var radius int32
  42336 	var _ /* p at bp+0 */ SmoothParams
  42337 	_ = radius
  42338 	radius = int32(4) * strength / int32(100)
  42339 	if strength < 0 || strength > int32(100) {
  42340 		return 0
  42341 	}
  42342 	if data == libc.UintptrFromInt32(0) || width <= 0 || height <= 0 {
  42343 		return 0
  42344 	} // bad params
  42345 	// limit the filter size to not exceed the image dimensions
  42346 	if int32(2)*radius+int32(1) > width {
  42347 		radius = (width - int32(1)) >> int32(1)
  42348 	}
  42349 	if int32(2)*radius+int32(1) > height {
  42350 		radius = (height - int32(1)) >> int32(1)
  42351 	}
  42352 	if radius > 0 {
  42353 		libc.Xmemset(tls, bp, 0, uint64(112))
  42354 		if !(InitParams(tls, data, width, height, stride, radius, bp) != 0) {
  42355 			return 0
  42356 		}
  42357 		if (**(**SmoothParams)(__ccgo_up(bp))).Fnum_levels > int32(2) {
  42358 			for {
  42359 				if !((**(**SmoothParams)(__ccgo_up(bp))).Frow < (**(**SmoothParams)(__ccgo_up(bp))).Fheight) {
  42360 					break
  42361 				}
  42362 				VFilter(tls, bp) // accumulate average of input
  42363 				// Need to wait few rows in order to prime the filter,
  42364 				// before emitting some output.
  42365 				if (**(**SmoothParams)(__ccgo_up(bp))).Frow >= (**(**SmoothParams)(__ccgo_up(bp))).Fradius {
  42366 					HFilter(tls, bp)
  42367 					ApplyFilter(tls, bp)
  42368 				}
  42369 				goto _1
  42370 			_1:
  42371 				;
  42372 				(**(**SmoothParams)(__ccgo_up(bp))).Frow = (**(**SmoothParams)(__ccgo_up(bp))).Frow + 1
  42373 			}
  42374 		}
  42375 		CleanupParams(tls, bp)
  42376 	}
  42377 	return int32(1)
  42378 }
  42379 
  42380 const ERROR_THRESHOLD = 0.0001
  42381 const MAX_ITER = 6
  42382 const NUM_SYMBOLS = 256
  42383 
  42384 // -----------------------------------------------------------------------------
  42385 // Quantize levels.
  42386 
  42387 func QuantizeLevels(tls *libc.TLS, data uintptr, width int32, height int32, num_levels int32, sse uintptr) (r int32) {
  42388 	bp := tls.Alloc(4096)
  42389 	defer tls.Free(4096)
  42390 	var count, err, err_threshold, error1, last_err float64
  42391 	var data_size, n, n1 size_t
  42392 	var freq, q_level [256]int32
  42393 	var i, iter, max_s, min_s, num_levels_in, s, s1, slot, slot1 int32
  42394 	var inv_q_level [256]float64
  42395 	var map1 [256]uint8_t
  42396 	var _ /* q_count at bp+2048 */ [256]float64
  42397 	var _ /* q_sum at bp+0 */ [256]float64
  42398 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  42399 	freq = [256]int32{}
  42400 	q_level = [256]int32{}
  42401 	inv_q_level = [256]float64{}
  42402 	min_s = int32(255)
  42403 	max_s = 0
  42404 	data_size = uint64(height * width)
  42405 	last_err = float64(1e+38)
  42406 	err = float64(0)
  42407 	err_threshold = float64(float64(0.0001) * float64(data_size))
  42408 	if data == libc.UintptrFromInt32(0) {
  42409 		return 0
  42410 	}
  42411 	if width <= 0 || height <= 0 {
  42412 		return 0
  42413 	}
  42414 	if num_levels < int32(2) || num_levels > int32(256) {
  42415 		return 0
  42416 	}
  42417 	num_levels_in = 0
  42418 	n = uint64(0)
  42419 	for {
  42420 		if !(n < data_size) {
  42421 			break
  42422 		}
  42423 		num_levels_in = num_levels_in + libc.BoolInt32(freq[**(**uint8_t)(__ccgo_up(data + uintptr(n)))] == 0)
  42424 		if min_s > int32(**(**uint8_t)(__ccgo_up(data + uintptr(n)))) {
  42425 			min_s = int32(**(**uint8_t)(__ccgo_up(data + uintptr(n))))
  42426 		}
  42427 		if max_s < int32(**(**uint8_t)(__ccgo_up(data + uintptr(n)))) {
  42428 			max_s = int32(**(**uint8_t)(__ccgo_up(data + uintptr(n))))
  42429 		}
  42430 		freq[**(**uint8_t)(__ccgo_up(data + uintptr(n)))] = freq[**(**uint8_t)(__ccgo_up(data + uintptr(n)))] + 1
  42431 		goto _1
  42432 	_1:
  42433 		;
  42434 		n = n + 1
  42435 	}
  42436 	if num_levels_in <= num_levels {
  42437 		goto End
  42438 	} // nothing to do!
  42439 	// Start with uniformly spread centroids.
  42440 	i = 0
  42441 	for {
  42442 		if !(i < num_levels) {
  42443 			break
  42444 		}
  42445 		inv_q_level[i] = float64(min_s) + float64(float64(max_s-min_s)*float64(i))/float64(num_levels-libc.Int32FromInt32(1))
  42446 		goto _2
  42447 	_2:
  42448 		;
  42449 		i = i + 1
  42450 	}
  42451 	// Fixed values. Won't be changed.
  42452 	q_level[min_s] = 0
  42453 	q_level[max_s] = num_levels - int32(1)
  42454 	// k-Means iterations.
  42455 	iter = 0
  42456 	for {
  42457 		if !(iter < int32(MAX_ITER)) {
  42458 			break
  42459 		}
  42460 		**(**[256]float64)(__ccgo_up(bp)) = [256]float64{}
  42461 		**(**[256]float64)(__ccgo_up(bp + 2048)) = [256]float64{}
  42462 		slot = 0
  42463 		// Assign classes to representatives.
  42464 		s = min_s
  42465 		for {
  42466 			if !(s <= max_s) {
  42467 				break
  42468 			}
  42469 			// Keep track of the nearest neighbour 'slot'
  42470 			for slot < num_levels-int32(1) && float64(int32(2)*s) > inv_q_level[slot]+inv_q_level[slot+int32(1)] {
  42471 				slot = slot + 1
  42472 			}
  42473 			if freq[s] > 0 {
  42474 				**(**float64)(__ccgo_up(bp + uintptr(slot)*8)) += float64(s * freq[s])
  42475 				**(**float64)(__ccgo_up(bp + 2048 + uintptr(slot)*8)) += float64(freq[s])
  42476 			}
  42477 			q_level[s] = slot
  42478 			goto _4
  42479 		_4:
  42480 			;
  42481 			s = s + 1
  42482 		}
  42483 		// Assign new representatives to classes.
  42484 		if num_levels > int32(2) {
  42485 			slot = int32(1)
  42486 			for {
  42487 				if !(slot < num_levels-int32(1)) {
  42488 					break
  42489 				}
  42490 				count = (**(**[256]float64)(__ccgo_up(bp + 2048)))[slot]
  42491 				if count > float64(0) {
  42492 					inv_q_level[slot] = (**(**[256]float64)(__ccgo_up(bp)))[slot] / count
  42493 				}
  42494 				goto _5
  42495 			_5:
  42496 				;
  42497 				slot = slot + 1
  42498 			}
  42499 		}
  42500 		// Compute convergence error.
  42501 		err = float64(0)
  42502 		s = min_s
  42503 		for {
  42504 			if !(s <= max_s) {
  42505 				break
  42506 			}
  42507 			error1 = float64(s) - inv_q_level[q_level[s]]
  42508 			err = err + float64(float64(float64(freq[s])*error1)*error1)
  42509 			goto _6
  42510 		_6:
  42511 			;
  42512 			s = s + 1
  42513 		}
  42514 		// Check for convergence: we stop as soon as the error is no
  42515 		// longer improving.
  42516 		if last_err-err < err_threshold {
  42517 			break
  42518 		}
  42519 		last_err = err
  42520 		goto _3
  42521 	_3:
  42522 		;
  42523 		iter = iter + 1
  42524 	}
  42525 	// Remap the alpha plane to quantized values.
  42526 	s1 = min_s
  42527 	for {
  42528 		if !(s1 <= max_s) {
  42529 			break
  42530 		}
  42531 		slot1 = q_level[s1]
  42532 		map1[s1] = uint8(inv_q_level[slot1] + libc.Float64FromFloat64(0.5))
  42533 		goto _7
  42534 	_7:
  42535 		;
  42536 		s1 = s1 + 1
  42537 	}
  42538 	// Final pass.
  42539 	n1 = uint64(0)
  42540 	for {
  42541 		if !(n1 < data_size) {
  42542 			break
  42543 		}
  42544 		**(**uint8_t)(__ccgo_up(data + uintptr(n1))) = map1[**(**uint8_t)(__ccgo_up(data + uintptr(n1)))]
  42545 		goto _8
  42546 	_8:
  42547 		;
  42548 		n1 = n1 + 1
  42549 	}
  42550 	goto End
  42551 End:
  42552 	;
  42553 	// Store sum of squared error if needed.
  42554 	if sse != libc.UintptrFromInt32(0) {
  42555 		**(**uint64_t)(__ccgo_up(sse)) = uint64(err)
  42556 	}
  42557 	return int32(1)
  42558 }
  42559 
  42560 //------------------------------------------------------------------------------
  42561 
  42562 // C documentation
  42563 //
  42564 //	// 31b-range values
  42565 var kRandomTable = [55]uint32_t{
  42566 	0:  uint32(0x0de15230),
  42567 	1:  uint32(0x03b31886),
  42568 	2:  uint32(0x775faccb),
  42569 	3:  uint32(0x1c88626a),
  42570 	4:  uint32(0x68385c55),
  42571 	5:  uint32(0x14b3b828),
  42572 	6:  uint32(0x4a85fef8),
  42573 	7:  uint32(0x49ddb84b),
  42574 	8:  uint32(0x64fcf397),
  42575 	9:  uint32(0x5c550289),
  42576 	10: uint32(0x4a290000),
  42577 	11: uint32(0x0d7ec1da),
  42578 	12: uint32(0x5940b7ab),
  42579 	13: uint32(0x5492577d),
  42580 	14: uint32(0x4e19ca72),
  42581 	15: uint32(0x38d38c69),
  42582 	16: uint32(0x0c01ee65),
  42583 	17: uint32(0x32a1755f),
  42584 	18: uint32(0x5437f652),
  42585 	19: uint32(0x5abb2c32),
  42586 	20: uint32(0x0faa57b1),
  42587 	21: uint32(0x73f533e7),
  42588 	22: uint32(0x685feeda),
  42589 	23: uint32(0x7563cce2),
  42590 	24: uint32(0x6e990e83),
  42591 	25: uint32(0x4730a7ed),
  42592 	26: uint32(0x4fc0d9c6),
  42593 	27: uint32(0x496b153c),
  42594 	28: uint32(0x4f1403fa),
  42595 	29: uint32(0x541afb0c),
  42596 	30: uint32(0x73990b32),
  42597 	31: uint32(0x26d7cb1c),
  42598 	32: uint32(0x6fcc3706),
  42599 	33: uint32(0x2cbb77d8),
  42600 	34: uint32(0x75762f2a),
  42601 	35: uint32(0x6425ccdd),
  42602 	36: uint32(0x24b35461),
  42603 	37: uint32(0x0a7d8715),
  42604 	38: uint32(0x220414a8),
  42605 	39: uint32(0x141ebf67),
  42606 	40: uint32(0x56b41583),
  42607 	41: uint32(0x73e502e3),
  42608 	42: uint32(0x44cab16f),
  42609 	43: uint32(0x28264d42),
  42610 	44: uint32(0x73baaefb),
  42611 	45: uint32(0x0a50ebed),
  42612 	46: uint32(0x1d6ab6fb),
  42613 	47: uint32(0x0d3ad40b),
  42614 	48: uint32(0x35db3b68),
  42615 	49: uint32(0x2b081e83),
  42616 	50: uint32(0x77ce6b95),
  42617 	51: uint32(0x5181e5f0),
  42618 	52: uint32(0x78853bbc),
  42619 	53: uint32(0x009f9494),
  42620 	54: uint32(0x27e5ed3c),
  42621 }
  42622 
  42623 func VP8InitRandom(tls *libc.TLS, rg uintptr, dithering float32) {
  42624 	var v1, v2 uint32
  42625 	_, _ = v1, v2
  42626 	libc.Xmemcpy(tls, rg+8, uintptr(unsafe.Pointer(&kRandomTable)), uint64(220))
  42627 	(*VP8Random)(unsafe.Pointer(rg)).Findex1 = 0
  42628 	(*VP8Random)(unsafe.Pointer(rg)).Findex2 = int32(31)
  42629 	if float64(dithering) < float64(0) {
  42630 		v1 = uint32(0)
  42631 	} else {
  42632 		if float64(dithering) > float64(1) {
  42633 			v2 = uint32(libc.Int32FromInt32(1) << libc.Int32FromInt32(VP8_RANDOM_DITHER_FIX))
  42634 		} else {
  42635 			v2 = uint32(float32(float32(libc.Int32FromInt32(1)<<libc.Int32FromInt32(VP8_RANDOM_DITHER_FIX)) * dithering))
  42636 		}
  42637 		v1 = v2
  42638 	}
  42639 	(*VP8Random)(unsafe.Pointer(rg)).Famp = int32(v1)
  42640 }
  42641 
  42642 const SIZE_MAX20 = "_UI64_MAX"
  42643 const __INT_MAX__3 = 2147483647
  42644 
  42645 //------------------------------------------------------------------------------
  42646 
  42647 //------------------------------------------------------------------------------
  42648 
  42649 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) {
  42650 	var den, num, ratio, total_size, v1 uint64_t
  42651 	var x_add, x_sub, y_add, y_sub, v2 int32
  42652 	_, _, _, _, _, _, _, _, _, _ = den, num, ratio, total_size, x_add, x_sub, y_add, y_sub, v1, v2
  42653 	x_add = src_width
  42654 	x_sub = dst_width
  42655 	y_add = src_height
  42656 	y_sub = dst_height
  42657 	total_size = uint64(2) * uint64(dst_width) * uint64(num_channels) * uint64(4)
  42658 	v1 = total_size
  42659 	v2 = libc.BoolInt32(v1 == v1)
  42660 	goto _3
  42661 _3:
  42662 	if !(v2 != 0) {
  42663 		return 0
  42664 	}
  42665 	(*WebPRescaler)(unsafe.Pointer(rescaler)).Fx_expand = libc.BoolInt32(src_width < dst_width)
  42666 	(*WebPRescaler)(unsafe.Pointer(rescaler)).Fy_expand = libc.BoolInt32(src_height < dst_height)
  42667 	(*WebPRescaler)(unsafe.Pointer(rescaler)).Fsrc_width = src_width
  42668 	(*WebPRescaler)(unsafe.Pointer(rescaler)).Fsrc_height = src_height
  42669 	(*WebPRescaler)(unsafe.Pointer(rescaler)).Fdst_width = dst_width
  42670 	(*WebPRescaler)(unsafe.Pointer(rescaler)).Fdst_height = dst_height
  42671 	(*WebPRescaler)(unsafe.Pointer(rescaler)).Fsrc_y = 0
  42672 	(*WebPRescaler)(unsafe.Pointer(rescaler)).Fdst_y = 0
  42673 	(*WebPRescaler)(unsafe.Pointer(rescaler)).Fdst = dst
  42674 	(*WebPRescaler)(unsafe.Pointer(rescaler)).Fdst_stride = dst_stride
  42675 	(*WebPRescaler)(unsafe.Pointer(rescaler)).Fnum_channels = num_channels
  42676 	// for 'x_expand', we use bilinear interpolation
  42677 	if (*WebPRescaler)(unsafe.Pointer(rescaler)).Fx_expand != 0 {
  42678 		v2 = x_sub - int32(1)
  42679 	} else {
  42680 		v2 = x_add
  42681 	}
  42682 	(*WebPRescaler)(unsafe.Pointer(rescaler)).Fx_add = v2
  42683 	if (*WebPRescaler)(unsafe.Pointer(rescaler)).Fx_expand != 0 {
  42684 		v2 = x_add - int32(1)
  42685 	} else {
  42686 		v2 = x_sub
  42687 	}
  42688 	(*WebPRescaler)(unsafe.Pointer(rescaler)).Fx_sub = v2
  42689 	if !((*WebPRescaler)(unsafe.Pointer(rescaler)).Fx_expand != 0) { // fx_scale is not used otherwise
  42690 		(*WebPRescaler)(unsafe.Pointer(rescaler)).Ffx_scale = uint32(uint64(libc.Int32FromInt32(1)) << libc.Int32FromInt32(WEBP_RESCALER_RFIX) / uint64((*WebPRescaler)(unsafe.Pointer(rescaler)).Fx_sub))
  42691 	}
  42692 	// vertical scaling parameters
  42693 	if (*WebPRescaler)(unsafe.Pointer(rescaler)).Fy_expand != 0 {
  42694 		v2 = y_add - int32(1)
  42695 	} else {
  42696 		v2 = y_add
  42697 	}
  42698 	(*WebPRescaler)(unsafe.Pointer(rescaler)).Fy_add = v2
  42699 	if (*WebPRescaler)(unsafe.Pointer(rescaler)).Fy_expand != 0 {
  42700 		v2 = y_sub - int32(1)
  42701 	} else {
  42702 		v2 = y_sub
  42703 	}
  42704 	(*WebPRescaler)(unsafe.Pointer(rescaler)).Fy_sub = v2
  42705 	if (*WebPRescaler)(unsafe.Pointer(rescaler)).Fy_expand != 0 {
  42706 		v2 = (*WebPRescaler)(unsafe.Pointer(rescaler)).Fy_sub
  42707 	} else {
  42708 		v2 = (*WebPRescaler)(unsafe.Pointer(rescaler)).Fy_add
  42709 	}
  42710 	(*WebPRescaler)(unsafe.Pointer(rescaler)).Fy_accum = v2
  42711 	if !((*WebPRescaler)(unsafe.Pointer(rescaler)).Fy_expand != 0) {
  42712 		// This is WEBP_RESCALER_FRAC(dst_height, x_add * y_add) without the cast.
  42713 		// Its value is <= WEBP_RESCALER_ONE, because dst_height <= rescaler->y_add
  42714 		// and rescaler->x_add >= 1;
  42715 		num = uint64(dst_height) * (libc.Uint64FromUint64(1) << libc.Int32FromInt32(WEBP_RESCALER_RFIX))
  42716 		den = uint64((*WebPRescaler)(unsafe.Pointer(rescaler)).Fx_add) * uint64((*WebPRescaler)(unsafe.Pointer(rescaler)).Fy_add)
  42717 		ratio = num / den
  42718 		if ratio != uint64(uint32(ratio)) {
  42719 			// When ratio == WEBP_RESCALER_ONE, we can't represent the ratio with the
  42720 			// current fixed-point precision. This happens when src_height ==
  42721 			// rescaler->y_add (which == src_height), and rescaler->x_add == 1.
  42722 			// => We special-case fxy_scale = 0, in WebPRescalerExportRow().
  42723 			(*WebPRescaler)(unsafe.Pointer(rescaler)).Ffxy_scale = uint32(0)
  42724 		} else {
  42725 			(*WebPRescaler)(unsafe.Pointer(rescaler)).Ffxy_scale = uint32(ratio)
  42726 		}
  42727 		(*WebPRescaler)(unsafe.Pointer(rescaler)).Ffy_scale = uint32(uint64(libc.Int32FromInt32(1)) << libc.Int32FromInt32(WEBP_RESCALER_RFIX) / uint64((*WebPRescaler)(unsafe.Pointer(rescaler)).Fy_sub))
  42728 	} else {
  42729 		(*WebPRescaler)(unsafe.Pointer(rescaler)).Ffy_scale = uint32(uint64(libc.Int32FromInt32(1)) << libc.Int32FromInt32(WEBP_RESCALER_RFIX) / uint64((*WebPRescaler)(unsafe.Pointer(rescaler)).Fx_add))
  42730 		// rescaler->fxy_scale is unused here.
  42731 	}
  42732 	(*WebPRescaler)(unsafe.Pointer(rescaler)).Firow = work
  42733 	(*WebPRescaler)(unsafe.Pointer(rescaler)).Ffrow = work + uintptr(num_channels*dst_width)*4
  42734 	libc.Xmemset(tls, work, 0, total_size)
  42735 	WebPRescalerDspInit(tls)
  42736 	return int32(1)
  42737 }
  42738 
  42739 func WebPRescalerGetScaledDimensions(tls *libc.TLS, src_width int32, src_height int32, scaled_width uintptr, scaled_height uintptr) (r int32) {
  42740 	var height, max_size, width int32
  42741 	_, _, _ = height, max_size, width
  42742 	width = **(**int32)(__ccgo_up(scaled_width))
  42743 	height = **(**int32)(__ccgo_up(scaled_height))
  42744 	max_size = libc.Int32FromInt32(__INT_MAX__3) / libc.Int32FromInt32(2)
  42745 	// if width is unspecified, scale original proportionally to height ratio.
  42746 	if width == 0 && src_height > 0 {
  42747 		width = int32((uint64(src_width)*uint64(height) + uint64(src_height) - libc.Uint64FromInt32(1)) / uint64(src_height))
  42748 	}
  42749 	// if height is unspecified, scale original proportionally to width ratio.
  42750 	if height == 0 && src_width > 0 {
  42751 		height = int32((uint64(src_height)*uint64(width) + uint64(src_width) - libc.Uint64FromInt32(1)) / uint64(src_width))
  42752 	}
  42753 	// Check if the overall dimensions still make sense.
  42754 	if width <= 0 || height <= 0 || width > max_size || height > max_size {
  42755 		return 0
  42756 	}
  42757 	**(**int32)(__ccgo_up(scaled_width)) = width
  42758 	**(**int32)(__ccgo_up(scaled_height)) = height
  42759 	return int32(1)
  42760 	return r
  42761 }
  42762 
  42763 //------------------------------------------------------------------------------
  42764 // all-in-one calls
  42765 
  42766 func WebPRescaleNeededLines(tls *libc.TLS, rescaler uintptr, max_num_lines int32) (r int32) {
  42767 	var num_lines, v1 int32
  42768 	_, _ = num_lines, v1
  42769 	num_lines = ((*WebPRescaler)(unsafe.Pointer(rescaler)).Fy_accum + (*WebPRescaler)(unsafe.Pointer(rescaler)).Fy_sub - int32(1)) / (*WebPRescaler)(unsafe.Pointer(rescaler)).Fy_sub
  42770 	if num_lines > max_num_lines {
  42771 		v1 = max_num_lines
  42772 	} else {
  42773 		v1 = num_lines
  42774 	}
  42775 	return v1
  42776 }
  42777 
  42778 func WebPRescalerImport(tls *libc.TLS, rescaler2 uintptr, num_lines int32, src uintptr, src_stride int32) (r int32) {
  42779 	var tmp, v1, v4 uintptr
  42780 	var total_imported, x, v2, v5 int32
  42781 	var v7 bool
  42782 	_, _, _, _, _, _, _, _ = tmp, total_imported, x, v1, v2, v4, v5, v7
  42783 	total_imported = 0
  42784 	for {
  42785 		if v7 = total_imported < num_lines; v7 {
  42786 			v1 = rescaler2
  42787 			v4 = v1
  42788 			v5 = libc.BoolInt32((*WebPRescaler)(unsafe.Pointer(v4)).Fdst_y >= (*WebPRescaler)(unsafe.Pointer(v4)).Fdst_height)
  42789 			goto _6
  42790 		_6:
  42791 			;
  42792 			v2 = libc.BoolInt32(!(v5 != 0) && (*WebPRescaler)(unsafe.Pointer(v1)).Fy_accum <= 0)
  42793 			goto _3
  42794 		_3:
  42795 		}
  42796 		if !(v7 && !(v2 != 0)) {
  42797 			break
  42798 		}
  42799 		if (*WebPRescaler)(unsafe.Pointer(rescaler2)).Fy_expand != 0 {
  42800 			tmp = (*WebPRescaler)(unsafe.Pointer(rescaler2)).Firow
  42801 			(*WebPRescaler)(unsafe.Pointer(rescaler2)).Firow = (*WebPRescaler)(unsafe.Pointer(rescaler2)).Ffrow
  42802 			(*WebPRescaler)(unsafe.Pointer(rescaler2)).Ffrow = tmp
  42803 		}
  42804 		WebPRescalerImportRow(tls, rescaler2, src)
  42805 		if !((*WebPRescaler)(unsafe.Pointer(rescaler2)).Fy_expand != 0) {
  42806 			x = 0
  42807 			for {
  42808 				if !(x < (*WebPRescaler)(unsafe.Pointer(rescaler2)).Fnum_channels*(*WebPRescaler)(unsafe.Pointer(rescaler2)).Fdst_width) {
  42809 					break
  42810 				}
  42811 				**(**rescaler_t)(__ccgo_up((*WebPRescaler)(unsafe.Pointer(rescaler2)).Firow + uintptr(x)*4)) += **(**rescaler_t)(__ccgo_up((*WebPRescaler)(unsafe.Pointer(rescaler2)).Ffrow + uintptr(x)*4))
  42812 				goto _8
  42813 			_8:
  42814 				;
  42815 				x = x + 1
  42816 			}
  42817 		}
  42818 		(*WebPRescaler)(unsafe.Pointer(rescaler2)).Fsrc_y = (*WebPRescaler)(unsafe.Pointer(rescaler2)).Fsrc_y + 1
  42819 		src = src + uintptr(src_stride)
  42820 		total_imported = total_imported + 1
  42821 		**(**int32)(__ccgo_up(rescaler2 + 24)) -= (*WebPRescaler)(unsafe.Pointer(rescaler2)).Fy_sub
  42822 	}
  42823 	return total_imported
  42824 }
  42825 
  42826 func WebPRescalerExport(tls *libc.TLS, rescaler2 uintptr) (r int32) {
  42827 	var total_exported, v2, v5 int32
  42828 	var v1, v4 uintptr
  42829 	_, _, _, _, _ = total_exported, v1, v2, v4, v5
  42830 	total_exported = 0
  42831 	for {
  42832 		v1 = rescaler2
  42833 		v4 = v1
  42834 		v5 = libc.BoolInt32((*WebPRescaler)(unsafe.Pointer(v4)).Fdst_y >= (*WebPRescaler)(unsafe.Pointer(v4)).Fdst_height)
  42835 		goto _6
  42836 	_6:
  42837 		;
  42838 		v2 = libc.BoolInt32(!(v5 != 0) && (*WebPRescaler)(unsafe.Pointer(v1)).Fy_accum <= 0)
  42839 		goto _3
  42840 	_3:
  42841 		if !(v2 != 0) {
  42842 			break
  42843 		}
  42844 		WebPRescalerExportRow(tls, rescaler2)
  42845 		total_exported = total_exported + 1
  42846 	}
  42847 	return total_exported
  42848 }
  42849 
  42850 const SIZE_MAX21 = "UINT64_MAX"
  42851 const __INT_MAX__4 = 0x7fffffff
  42852 
  42853 //------------------------------------------------------------------------------
  42854 
  42855 //------------------------------------------------------------------------------
  42856 
  42857 func Init(tls *libc.TLS, worker uintptr) {
  42858 	libc.Xmemset(tls, worker, 0, uint64(48))
  42859 	(*WebPWorker)(unsafe.Pointer(worker)).Fstatus = int32(NOT_OK)
  42860 }
  42861 
  42862 func Sync(tls *libc.TLS, worker uintptr) (r int32) {
  42863 	return libc.BoolInt32(!((*WebPWorker)(unsafe.Pointer(worker)).Fhad_error != 0))
  42864 }
  42865 
  42866 func Reset(tls *libc.TLS, worker uintptr) (r int32) {
  42867 	var ok int32
  42868 	_ = ok
  42869 	ok = int32(1)
  42870 	(*WebPWorker)(unsafe.Pointer(worker)).Fhad_error = 0
  42871 	if (*WebPWorker)(unsafe.Pointer(worker)).Fstatus < int32(OK) {
  42872 		(*WebPWorker)(unsafe.Pointer(worker)).Fstatus = int32(OK)
  42873 	} else {
  42874 		if (*WebPWorker)(unsafe.Pointer(worker)).Fstatus > int32(OK) {
  42875 			ok = Sync(tls, worker)
  42876 		}
  42877 	}
  42878 	return ok
  42879 }
  42880 
  42881 func Execute(tls *libc.TLS, worker uintptr) {
  42882 	if (*WebPWorker)(unsafe.Pointer(worker)).Fhook != libc.UintptrFromInt32(0) {
  42883 		**(**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))
  42884 	}
  42885 }
  42886 
  42887 func Launch(tls *libc.TLS, worker uintptr) {
  42888 	Execute(tls, worker)
  42889 }
  42890 
  42891 func End(tls *libc.TLS, worker uintptr) {
  42892 	(*WebPWorker)(unsafe.Pointer(worker)).Fstatus = int32(NOT_OK)
  42893 }
  42894 
  42895 //------------------------------------------------------------------------------
  42896 
  42897 var g_worker_interface = WebPWorkerInterface{}
  42898 
  42899 func init() {
  42900 	p := unsafe.Pointer(&g_worker_interface)
  42901 	*(*uintptr)(unsafe.Add(p, 0)) = __ccgo_fp(Init)
  42902 	*(*uintptr)(unsafe.Add(p, 8)) = __ccgo_fp(Reset)
  42903 	*(*uintptr)(unsafe.Add(p, 16)) = __ccgo_fp(Sync)
  42904 	*(*uintptr)(unsafe.Add(p, 24)) = __ccgo_fp(Launch)
  42905 	*(*uintptr)(unsafe.Add(p, 32)) = __ccgo_fp(Execute)
  42906 	*(*uintptr)(unsafe.Add(p, 40)) = __ccgo_fp(End)
  42907 }
  42908 
  42909 func WebPSetWorkerInterface(tls *libc.TLS, winterface uintptr) (r int32) {
  42910 	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) {
  42911 		return 0
  42912 	}
  42913 	g_worker_interface = **(**WebPWorkerInterface)(__ccgo_up(winterface))
  42914 	return int32(1)
  42915 }
  42916 
  42917 func WebPGetWorkerInterface(tls *libc.TLS) (r uintptr) {
  42918 	return uintptr(unsafe.Pointer(&g_worker_interface))
  42919 }
  42920 
  42921 //------------------------------------------------------------------------------
  42922 
  42923 // If PRINT_MEM_INFO is defined, extra info (like total memory used, number of
  42924 // alloc/free etc) is printed. For debugging/tuning purpose only (it's slow,
  42925 // and not multi-thread safe!).
  42926 // An interesting alternative is valgrind's 'massif' tool:
  42927 //    https://valgrind.org/docs/manual/ms-manual.html
  42928 // Here is an example command line:
  42929 /*    valgrind --tool=massif --massif-out-file=massif.out                --stacks=yes --alloc-fn=WebPSafeMalloc --alloc-fn=WebPSafeCalloc
  42930       ms_print massif.out
  42931 */
  42932 // In addition:
  42933 // * if PRINT_MEM_TRAFFIC is defined, all the details of the malloc/free cycles
  42934 //   are printed.
  42935 // * if MALLOC_FAIL_AT is defined, the global environment variable
  42936 //   $MALLOC_FAIL_AT is used to simulate a memory error when calloc or malloc
  42937 //   is called for the nth time. Example usage:
  42938 //   export MALLOC_FAIL_AT=50 && ./examples/cwebp input.png
  42939 // * if MALLOC_LIMIT is defined, the global environment variable $MALLOC_LIMIT
  42940 //   sets the maximum amount of memory (in bytes) made available to libwebp.
  42941 //   This can be used to emulate environment with very limited memory.
  42942 //   Example: export MALLOC_LIMIT=64000000 && ./examples/dwebp picture.webp
  42943 
  42944 // #define PRINT_MEM_INFO
  42945 // #define PRINT_MEM_TRAFFIC
  42946 // #define MALLOC_FAIL_AT
  42947 // #define MALLOC_LIMIT
  42948 
  42949 //------------------------------------------------------------------------------
  42950 // Checked memory allocation
  42951 
  42952 // C documentation
  42953 //
  42954 //	// Returns 0 in case of overflow of nmemb * size.
  42955 func CheckSizeArgumentsOverflow(tls *libc.TLS, nmemb uint64_t, size1 size_t) (r int32) {
  42956 	var total_size, v1 uint64_t
  42957 	var v2 int32
  42958 	_, _, _ = total_size, v1, v2
  42959 	total_size = nmemb * size1
  42960 	if nmemb == uint64(0) {
  42961 		return int32(1)
  42962 	}
  42963 	if size1 > libc.Uint64FromUint64(1)<<libc.Int32FromInt32(34)/nmemb {
  42964 		return 0
  42965 	}
  42966 	v1 = total_size
  42967 	v2 = libc.BoolInt32(v1 == v1)
  42968 	goto _3
  42969 _3:
  42970 	if !(v2 != 0) {
  42971 		return 0
  42972 	}
  42973 	return int32(1)
  42974 }
  42975 
  42976 func WebPSafeMalloc(tls *libc.TLS, nmemb uint64_t, size size_t) (r uintptr) {
  42977 	var ptr uintptr
  42978 	_ = ptr
  42979 	if !(CheckSizeArgumentsOverflow(tls, nmemb, size) != 0) {
  42980 		return libc.UintptrFromInt32(0)
  42981 	}
  42982 	ptr = libc.Xmalloc(tls, nmemb*size)
  42983 	return ptr
  42984 }
  42985 
  42986 func WebPSafeCalloc(tls *libc.TLS, nmemb uint64_t, size size_t) (r uintptr) {
  42987 	var ptr uintptr
  42988 	_ = ptr
  42989 	if !(CheckSizeArgumentsOverflow(tls, nmemb, size) != 0) {
  42990 		return libc.UintptrFromInt32(0)
  42991 	}
  42992 	ptr = libc.Xcalloc(tls, nmemb, size)
  42993 	return ptr
  42994 }
  42995 
  42996 func WebPSafeFree(tls *libc.TLS, ptr uintptr) {
  42997 	if ptr != libc.UintptrFromInt32(0) {
  42998 	}
  42999 	libc.Xfree(tls, ptr)
  43000 }
  43001 
  43002 // Public API functions.
  43003 
  43004 func WebPMalloc(tls *libc.TLS, size size_t) (r uintptr) {
  43005 	return WebPSafeMalloc(tls, uint64(1), size)
  43006 }
  43007 
  43008 func WebPFree(tls *libc.TLS, ptr uintptr) {
  43009 	WebPSafeFree(tls, ptr)
  43010 }
  43011 
  43012 //------------------------------------------------------------------------------
  43013 
  43014 func WebPCopyPlane(tls *libc.TLS, src uintptr, src_stride int32, dst uintptr, dst_stride int32, width int32, height int32) {
  43015 	var v1 int32
  43016 	_ = v1
  43017 	for {
  43018 		v1 = height
  43019 		height = height - 1
  43020 		if !(v1 > 0) {
  43021 			break
  43022 		}
  43023 		libc.Xmemcpy(tls, dst, src, uint64(width))
  43024 		src = src + uintptr(src_stride)
  43025 		dst = dst + uintptr(dst_stride)
  43026 	}
  43027 }
  43028 
  43029 func WebPCopyPixels(tls *libc.TLS, src uintptr, dst uintptr) {
  43030 	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)
  43031 }
  43032 
  43033 //------------------------------------------------------------------------------
  43034 
  43035 func WebPGetColorPalette(tls *libc.TLS, pic uintptr, palette uintptr) (r int32) {
  43036 	return GetColorPalette(tls, pic, palette)
  43037 }
  43038 
  43039 const USE_TABLES_FOR_ALPHA_MULT = 0
  43040 
  43041 // Copyright 2010 Google Inc. All Rights Reserved.
  43042 //
  43043 // Use of this source code is governed by a BSD-style license
  43044 // that can be found in the COPYING file in the root of the source
  43045 // tree. An additional intellectual property rights grant can be found
  43046 // in the file PATENTS. All contributing project authors may
  43047 // be found in the AUTHORS file in the root of the source tree.
  43048 // -----------------------------------------------------------------------------
  43049 //
  43050 //  Common types + memory wrappers
  43051 //
  43052 // Author: Skal (pascal.massimino@gmail.com)
  43053 
  43054 // Tables can be faster on some platform but incur some extra binary size (~2k).
  43055 
  43056 // -----------------------------------------------------------------------------
  43057 
  43058 func Mult(tls *libc.TLS, x uint8_t, mult uint32_t) (r uint32_t) {
  43059 	var v uint32_t
  43060 	_ = v
  43061 	v = (uint32(x)*mult + libc.Uint32FromUint32(1)<<libc.Int32FromInt32(24)>>libc.Int32FromInt32(1)) >> int32(24)
  43062 	// <- 24bit precision is enough to ensure that.
  43063 	return v
  43064 }
  43065 
  43066 func GetScale(tls *libc.TLS, a uint32_t, inverse int32) (r uint32_t) {
  43067 	var v1 uint32
  43068 	_ = v1
  43069 	if inverse != 0 {
  43070 		v1 = libc.Uint32FromUint32(255) << libc.Int32FromInt32(24) / a
  43071 	} else {
  43072 		v1 = a * (libc.Uint32FromUint32(1) << libc.Int32FromInt32(24) / libc.Uint32FromUint32(255))
  43073 	}
  43074 	return v1
  43075 }
  43076 
  43077 func WebPMultARGBRow_C(tls *libc.TLS, ptr uintptr, width int32, inverse int32) {
  43078 	var alpha, argb, out, scale uint32_t
  43079 	var x int32
  43080 	_, _, _, _, _ = alpha, argb, out, scale, x
  43081 	x = 0
  43082 	for {
  43083 		if !(x < width) {
  43084 			break
  43085 		}
  43086 		argb = **(**uint32_t)(__ccgo_up(ptr + uintptr(x)*4))
  43087 		if argb < uint32(0xff000000) { // alpha < 255
  43088 			if argb <= uint32(0x00ffffff) { // alpha == 0
  43089 				**(**uint32_t)(__ccgo_up(ptr + uintptr(x)*4)) = uint32(0)
  43090 			} else {
  43091 				alpha = argb >> libc.Int32FromInt32(24) & uint32(0xff)
  43092 				scale = GetScale(tls, alpha, inverse)
  43093 				out = argb & uint32(0xff000000)
  43094 				out = out | Mult(tls, uint8(argb>>0), scale)<<0
  43095 				out = out | Mult(tls, uint8(argb>>int32(8)), scale)<<int32(8)
  43096 				out = out | Mult(tls, uint8(argb>>int32(16)), scale)<<int32(16)
  43097 				**(**uint32_t)(__ccgo_up(ptr + uintptr(x)*4)) = out
  43098 			}
  43099 		}
  43100 		goto _1
  43101 	_1:
  43102 		;
  43103 		x = x + 1
  43104 	}
  43105 }
  43106 
  43107 func WebPMultRow_C(tls *libc.TLS, ptr uintptr, alpha uintptr, width int32, inverse int32) {
  43108 	var a, scale uint32_t
  43109 	var x int32
  43110 	_, _, _ = a, scale, x
  43111 	x = 0
  43112 	for {
  43113 		if !(x < width) {
  43114 			break
  43115 		}
  43116 		a = uint32(**(**uint8_t)(__ccgo_up(alpha + uintptr(x))))
  43117 		if a != uint32(255) {
  43118 			if a == uint32(0) {
  43119 				**(**uint8_t)(__ccgo_up(ptr + uintptr(x))) = uint8(0)
  43120 			} else {
  43121 				scale = GetScale(tls, a, inverse)
  43122 				**(**uint8_t)(__ccgo_up(ptr + uintptr(x))) = uint8(Mult(tls, **(**uint8_t)(__ccgo_up(ptr + uintptr(x))), scale))
  43123 			}
  43124 		}
  43125 		goto _1
  43126 	_1:
  43127 		;
  43128 		x = x + 1
  43129 	}
  43130 }
  43131 
  43132 //------------------------------------------------------------------------------
  43133 // Generic per-plane calls
  43134 
  43135 func WebPMultARGBRows(tls *libc.TLS, ptr uintptr, stride int32, width int32, num_rows int32, inverse int32) {
  43136 	var n int32
  43137 	_ = n
  43138 	n = 0
  43139 	for {
  43140 		if !(n < num_rows) {
  43141 			break
  43142 		}
  43143 		(*(*func(*libc.TLS, uintptr, int32, int32))(unsafe.Pointer(&struct{ uintptr }{WebPMultARGBRow})))(tls, ptr, width, inverse)
  43144 		ptr = ptr + uintptr(stride)
  43145 		goto _1
  43146 	_1:
  43147 		;
  43148 		n = n + 1
  43149 	}
  43150 }
  43151 
  43152 func WebPMultRows(tls *libc.TLS, ptr uintptr, stride int32, alpha uintptr, alpha_stride int32, width int32, num_rows int32, inverse int32) {
  43153 	var n int32
  43154 	_ = n
  43155 	n = 0
  43156 	for {
  43157 		if !(n < num_rows) {
  43158 			break
  43159 		}
  43160 		(*(*func(*libc.TLS, uintptr, uintptr, int32, int32))(unsafe.Pointer(&struct{ uintptr }{WebPMultRow})))(tls, ptr, alpha, width, inverse)
  43161 		ptr = ptr + uintptr(stride)
  43162 		alpha = alpha + uintptr(alpha_stride)
  43163 		goto _1
  43164 	_1:
  43165 		;
  43166 		n = n + 1
  43167 	}
  43168 }
  43169 
  43170 //------------------------------------------------------------------------------
  43171 // Premultiplied modes
  43172 
  43173 // non dithered-modes
  43174 
  43175 // (x * a * 32897) >> 23 is bit-wise equivalent to (int)(x * a / 255.)
  43176 // for all 8bit x or a. For bit-wise equivalence to (int)(x * a / 255. + .5),
  43177 // one can use instead: (x * a * 65793 + (1 << 23)) >> 24
  43178 
  43179 func ApplyAlphaMultiply_C(tls *libc.TLS, rgba uintptr, alpha_first int32, w int32, h int32, stride int32) {
  43180 	var a, mult uint32_t
  43181 	var alpha, rgb uintptr
  43182 	var i, v1, v2, v3 int32
  43183 	_, _, _, _, _, _, _, _ = a, alpha, i, mult, rgb, v1, v2, v3
  43184 	for {
  43185 		v1 = h
  43186 		h = h - 1
  43187 		if !(v1 > 0) {
  43188 			break
  43189 		}
  43190 		if alpha_first != 0 {
  43191 			v2 = int32(1)
  43192 		} else {
  43193 			v2 = 0
  43194 		}
  43195 		rgb = rgba + uintptr(v2)
  43196 		if alpha_first != 0 {
  43197 			v3 = 0
  43198 		} else {
  43199 			v3 = int32(3)
  43200 		}
  43201 		alpha = rgba + uintptr(v3)
  43202 		i = 0
  43203 		for {
  43204 			if !(i < w) {
  43205 				break
  43206 			}
  43207 			a = uint32(**(**uint8_t)(__ccgo_up(alpha + uintptr(int32(4)*i))))
  43208 			if a != uint32(0xff) {
  43209 				mult = a * libc.Uint32FromUint32(32897)
  43210 				**(**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))
  43211 				**(**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))
  43212 				**(**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))
  43213 			}
  43214 			goto _4
  43215 		_4:
  43216 			;
  43217 			i = i + 1
  43218 		}
  43219 		rgba = rgba + uintptr(stride)
  43220 	}
  43221 }
  43222 
  43223 // rgbA4444
  43224 
  43225 func dither_hi(tls *libc.TLS, x uint8_t) (r uint8_t) {
  43226 	return uint8(int32(x)&int32(0xf0) | int32(x)>>int32(4))
  43227 }
  43228 
  43229 func dither_lo(tls *libc.TLS, x uint8_t) (r uint8_t) {
  43230 	return uint8(int32(x)&int32(0x0f) | int32(x)<<int32(4))
  43231 }
  43232 
  43233 func multiply(tls *libc.TLS, x uint8_t, m uint32_t) (r uint8_t) {
  43234 	return uint8(uint32(x) * m >> int32(16))
  43235 }
  43236 
  43237 func ApplyAlphaMultiply4444_C(tls *libc.TLS, rgba4444 uintptr, w int32, h int32, stride int32, rg_byte_pos int32) {
  43238 	var a, b, g, r uint8_t
  43239 	var ba, mult, rg uint32_t
  43240 	var i, v1 int32
  43241 	_, _, _, _, _, _, _, _, _ = a, b, ba, g, i, mult, r, rg, v1
  43242 	for {
  43243 		v1 = h
  43244 		h = h - 1
  43245 		if !(v1 > 0) {
  43246 			break
  43247 		}
  43248 		i = 0
  43249 		for {
  43250 			if !(i < w) {
  43251 				break
  43252 			}
  43253 			rg = uint32(**(**uint8_t)(__ccgo_up(rgba4444 + uintptr(int32(2)*i+rg_byte_pos))))
  43254 			ba = uint32(**(**uint8_t)(__ccgo_up(rgba4444 + uintptr(int32(2)*i+(rg_byte_pos^int32(1))))))
  43255 			a = uint8(ba & uint32(0x0f))
  43256 			mult = uint32(int32(a) * libc.Int32FromInt32(0x1111))
  43257 			r = multiply(tls, dither_hi(tls, uint8(rg)), mult)
  43258 			g = multiply(tls, dither_lo(tls, uint8(rg)), mult)
  43259 			b = multiply(tls, dither_hi(tls, uint8(ba)), mult)
  43260 			**(**uint8_t)(__ccgo_up(rgba4444 + uintptr(int32(2)*i+rg_byte_pos))) = uint8(int32(r)&int32(0xf0) | int32(g)>>int32(4)&int32(0x0f))
  43261 			**(**uint8_t)(__ccgo_up(rgba4444 + uintptr(int32(2)*i+(rg_byte_pos^int32(1))))) = uint8(int32(b)&int32(0xf0) | int32(a))
  43262 			goto _2
  43263 		_2:
  43264 			;
  43265 			i = i + 1
  43266 		}
  43267 		rgba4444 = rgba4444 + uintptr(stride)
  43268 	}
  43269 }
  43270 
  43271 func ApplyAlphaMultiply_16b_C(tls *libc.TLS, rgba4444 uintptr, w int32, h int32, stride int32) {
  43272 	ApplyAlphaMultiply4444_C(tls, rgba4444, w, h, stride, 0)
  43273 }
  43274 
  43275 func DispatchAlpha_C(tls *libc.TLS, alpha uintptr, alpha_stride int32, width int32, height int32, dst uintptr, dst_stride int32) (r int32) {
  43276 	var alpha_mask, alpha_value uint32_t
  43277 	var i, j int32
  43278 	_, _, _, _ = alpha_mask, alpha_value, i, j
  43279 	alpha_mask = uint32(0xff)
  43280 	j = 0
  43281 	for {
  43282 		if !(j < height) {
  43283 			break
  43284 		}
  43285 		i = 0
  43286 		for {
  43287 			if !(i < width) {
  43288 				break
  43289 			}
  43290 			alpha_value = uint32(**(**uint8_t)(__ccgo_up(alpha + uintptr(i))))
  43291 			**(**uint8_t)(__ccgo_up(dst + uintptr(int32(4)*i))) = uint8(alpha_value)
  43292 			alpha_mask = alpha_mask & alpha_value
  43293 			goto _2
  43294 		_2:
  43295 			;
  43296 			i = i + 1
  43297 		}
  43298 		alpha = alpha + uintptr(alpha_stride)
  43299 		dst = dst + uintptr(dst_stride)
  43300 		goto _1
  43301 	_1:
  43302 		;
  43303 		j = j + 1
  43304 	}
  43305 	return libc.BoolInt32(alpha_mask != uint32(0xff))
  43306 }
  43307 
  43308 func DispatchAlphaToGreen_C(tls *libc.TLS, alpha uintptr, alpha_stride int32, width int32, height int32, dst uintptr, dst_stride int32) {
  43309 	var i, j int32
  43310 	_, _ = i, j
  43311 	j = 0
  43312 	for {
  43313 		if !(j < height) {
  43314 			break
  43315 		}
  43316 		i = 0
  43317 		for {
  43318 			if !(i < width) {
  43319 				break
  43320 			}
  43321 			**(**uint32_t)(__ccgo_up(dst + uintptr(i)*4)) = uint32(int32(**(**uint8_t)(__ccgo_up(alpha + uintptr(i)))) << int32(8)) // leave A/R/B channels zero'd.
  43322 			goto _2
  43323 		_2:
  43324 			;
  43325 			i = i + 1
  43326 		}
  43327 		alpha = alpha + uintptr(alpha_stride)
  43328 		dst = dst + uintptr(dst_stride)*4
  43329 		goto _1
  43330 	_1:
  43331 		;
  43332 		j = j + 1
  43333 	}
  43334 }
  43335 
  43336 func ExtractAlpha_C(tls *libc.TLS, argb uintptr, argb_stride int32, width int32, height int32, alpha uintptr, alpha_stride int32) (r int32) {
  43337 	var alpha_mask, alpha_value uint8_t
  43338 	var i, j int32
  43339 	_, _, _, _ = alpha_mask, alpha_value, i, j
  43340 	alpha_mask = uint8(0xff)
  43341 	j = 0
  43342 	for {
  43343 		if !(j < height) {
  43344 			break
  43345 		}
  43346 		i = 0
  43347 		for {
  43348 			if !(i < width) {
  43349 				break
  43350 			}
  43351 			alpha_value = **(**uint8_t)(__ccgo_up(argb + uintptr(int32(4)*i)))
  43352 			**(**uint8_t)(__ccgo_up(alpha + uintptr(i))) = alpha_value
  43353 			alpha_mask = uint8(int32(alpha_mask) & int32(alpha_value))
  43354 			goto _2
  43355 		_2:
  43356 			;
  43357 			i = i + 1
  43358 		}
  43359 		argb = argb + uintptr(argb_stride)
  43360 		alpha = alpha + uintptr(alpha_stride)
  43361 		goto _1
  43362 	_1:
  43363 		;
  43364 		j = j + 1
  43365 	}
  43366 	return libc.BoolInt32(int32(alpha_mask) == int32(0xff))
  43367 }
  43368 
  43369 func ExtractGreen_C(tls *libc.TLS, argb uintptr, alpha uintptr, size int32) {
  43370 	var i int32
  43371 	_ = i
  43372 	i = 0
  43373 	for {
  43374 		if !(i < size) {
  43375 			break
  43376 		}
  43377 		**(**uint8_t)(__ccgo_up(alpha + uintptr(i))) = uint8(**(**uint32_t)(__ccgo_up(argb + uintptr(i)*4)) >> int32(8))
  43378 		goto _1
  43379 	_1:
  43380 		;
  43381 		i = i + 1
  43382 	}
  43383 }
  43384 
  43385 //------------------------------------------------------------------------------
  43386 
  43387 func HasAlpha8b_C(tls *libc.TLS, src uintptr, length int32) (r int32) {
  43388 	var v1 int32
  43389 	var v2 uintptr
  43390 	_, _ = v1, v2
  43391 	for {
  43392 		v1 = length
  43393 		length = length - 1
  43394 		if !(v1 > 0) {
  43395 			break
  43396 		}
  43397 		v2 = src
  43398 		src = src + 1
  43399 		if int32(**(**uint8_t)(__ccgo_up(v2))) != int32(0xff) {
  43400 			return int32(1)
  43401 		}
  43402 	}
  43403 	return 0
  43404 }
  43405 
  43406 func HasAlpha32b_C(tls *libc.TLS, src uintptr, length int32) (r int32) {
  43407 	var x, v2 int32
  43408 	_, _ = x, v2
  43409 	x = 0
  43410 	for {
  43411 		v2 = length
  43412 		length = length - 1
  43413 		if !(v2 > 0) {
  43414 			break
  43415 		}
  43416 		if int32(**(**uint8_t)(__ccgo_up(src + uintptr(x)))) != int32(0xff) {
  43417 			return int32(1)
  43418 		}
  43419 		goto _1
  43420 	_1:
  43421 		;
  43422 		x = x + int32(4)
  43423 	}
  43424 	return 0
  43425 }
  43426 
  43427 func AlphaReplace_C(tls *libc.TLS, src uintptr, length int32, color uint32_t) {
  43428 	var x int32
  43429 	_ = x
  43430 	x = 0
  43431 	for {
  43432 		if !(x < length) {
  43433 			break
  43434 		}
  43435 		if **(**uint32_t)(__ccgo_up(src + uintptr(x)*4))>>libc.Int32FromInt32(24) == uint32(0) {
  43436 			**(**uint32_t)(__ccgo_up(src + uintptr(x)*4)) = color
  43437 		}
  43438 		goto _1
  43439 	_1:
  43440 		;
  43441 		x = x + 1
  43442 	}
  43443 }
  43444 
  43445 //------------------------------------------------------------------------------
  43446 // Simple channel manipulations.
  43447 
  43448 func MakeARGB321(tls *libc.TLS, a int32, r int32, g int32, b int32) (r1 uint32_t) {
  43449 	return uint32(a)<<libc.Int32FromInt32(24) | uint32(r<<libc.Int32FromInt32(16)) | uint32(g<<libc.Int32FromInt32(8)) | uint32(b)
  43450 }
  43451 
  43452 func PackRGB_C(tls *libc.TLS, r uintptr, g uintptr, b uintptr, len1 int32, step int32, out uintptr) {
  43453 	var i, offset int32
  43454 	_, _ = i, offset
  43455 	offset = 0
  43456 	i = 0
  43457 	for {
  43458 		if !(i < len1) {
  43459 			break
  43460 		}
  43461 		**(**uint32_t)(__ccgo_up(out + uintptr(i)*4)) = MakeARGB321(tls, int32(0xff), int32(**(**uint8_t)(__ccgo_up(r + uintptr(offset)))), int32(**(**uint8_t)(__ccgo_up(g + uintptr(offset)))), int32(**(**uint8_t)(__ccgo_up(b + uintptr(offset)))))
  43462 		offset = offset + step
  43463 		goto _1
  43464 	_1:
  43465 		;
  43466 		i = i + 1
  43467 	}
  43468 }
  43469 
  43470 func WebPInitAlphaProcessing(tls *libc.TLS) {
  43471 	if libc.AtomicLoadPUintptr(uintptr(unsafe.Pointer(&WebPInitAlphaProcessing_body_last_cpuinfo_used))) == VP8GetCPUInfo {
  43472 		goto _1
  43473 	}
  43474 	WebPInitAlphaProcessing_body(tls)
  43475 	libc.AtomicStorePUintptr(uintptr(unsafe.Pointer(&WebPInitAlphaProcessing_body_last_cpuinfo_used)), VP8GetCPUInfo)
  43476 	goto _2
  43477 _2:
  43478 	;
  43479 	goto _1
  43480 _1: /**/ //
  43481 }
  43482 
  43483 var WebPInitAlphaProcessing_body_last_cpuinfo_used = uintptr(0)
  43484 
  43485 func init() {
  43486 	p := unsafe.Pointer(&WebPInitAlphaProcessing_body_last_cpuinfo_used)
  43487 	*(*uintptr)(unsafe.Add(p, 0)) = uintptr(unsafe.Pointer(&WebPInitAlphaProcessing_body_last_cpuinfo_used))
  43488 }
  43489 
  43490 func WebPInitAlphaProcessing_body(tls *libc.TLS) {
  43491 	WebPMultARGBRow = __ccgo_fp(WebPMultARGBRow_C)
  43492 	WebPMultRow = __ccgo_fp(WebPMultRow_C)
  43493 	WebPApplyAlphaMultiply4444 = __ccgo_fp(ApplyAlphaMultiply_16b_C)
  43494 	WebPPackRGB = __ccgo_fp(PackRGB_C)
  43495 	WebPApplyAlphaMultiply = __ccgo_fp(ApplyAlphaMultiply_C)
  43496 	WebPDispatchAlpha = __ccgo_fp(DispatchAlpha_C)
  43497 	WebPDispatchAlphaToGreen = __ccgo_fp(DispatchAlphaToGreen_C)
  43498 	WebPExtractAlpha = __ccgo_fp(ExtractAlpha_C)
  43499 	WebPExtractGreen = __ccgo_fp(ExtractGreen_C)
  43500 	WebPHasAlpha8b = __ccgo_fp(HasAlpha8b_C)
  43501 	WebPHasAlpha32b = __ccgo_fp(HasAlpha32b_C)
  43502 	WebPAlphaReplace = __ccgo_fp(AlphaReplace_C)
  43503 	// If defined, use CPUInfo() to overwrite some pointers with faster versions.
  43504 	if VP8GetCPUInfo != libc.UintptrFromInt32(0) {
  43505 	}
  43506 }
  43507 
  43508 func WebPInitAlphaProcessingMIPSdspR2(tls *libc.TLS) {
  43509 }
  43510 
  43511 func WebPInitAlphaProcessingNEON(tls *libc.TLS) {
  43512 }
  43513 
  43514 func WebPInitAlphaProcessingSSE2(tls *libc.TLS) {
  43515 }
  43516 
  43517 func WebPInitAlphaProcessingSSE41(tls *libc.TLS) {
  43518 }
  43519 
  43520 const SIZE_MAX22 = "_UI64_MAX"
  43521 
  43522 //------------------------------------------------------------------------------
  43523 // Mode costs
  43524 
  43525 func GetResidualCost_C(tls *libc.TLS, ctx0 int32, res uintptr) (r int32) {
  43526 	var b, cost, ctx, ctx1, last_p0, n, p0, v, v1, v11, v3, v5, v7, v9 int32
  43527 	var costs CostArrayPtr
  43528 	var t uintptr
  43529 	var v2, v6 uint8_t
  43530 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = b, cost, costs, ctx, ctx1, last_p0, n, p0, t, v, v1, v11, v2, v3, v5, v6, v7, v9
  43531 	n = (*VP8Residual)(unsafe.Pointer(res)).Ffirst
  43532 	// should be prob[VP8EncBands[n]], but it's equivalent for n=0 or 1
  43533 	p0 = int32(**(**uint8_t)(__ccgo_up((*VP8Residual)(unsafe.Pointer(res)).Fprob + uintptr(n)*33 + uintptr(ctx0)*11)))
  43534 	costs = (*VP8Residual)(unsafe.Pointer(res)).Fcosts
  43535 	t = **(**uintptr)(__ccgo_up(costs + uintptr(n)*24 + uintptr(ctx0)*8))
  43536 	if ctx0 == 0 {
  43537 		v2 = uint8(p0)
  43538 		if !(int32(1) != 0) {
  43539 			v5 = int32(VP8EntropyCost[v2])
  43540 		} else {
  43541 			v5 = int32(VP8EntropyCost[int32(255)-int32(v2)])
  43542 		}
  43543 		v3 = v5
  43544 		goto _4
  43545 	_4:
  43546 		v11 = v3
  43547 	} else {
  43548 		v11 = 0
  43549 	}
  43550 	// bit_cost(1, p0) is already incorporated in t[] tables, but only if ctx != 0
  43551 	// (as required by the syntax). For ctx0 == 0, we need to add it here or it'll
  43552 	// be missing during the loop.
  43553 	cost = v11
  43554 	if (*VP8Residual)(unsafe.Pointer(res)).Flast < 0 {
  43555 		v6 = uint8(p0)
  43556 		if !(0 != 0) {
  43557 			v9 = int32(VP8EntropyCost[v6])
  43558 		} else {
  43559 			v9 = int32(VP8EntropyCost[int32(255)-int32(v6)])
  43560 		}
  43561 		v7 = v9
  43562 		goto _8
  43563 	_8:
  43564 		return v7
  43565 	}
  43566 	for {
  43567 		if !(n < (*VP8Residual)(unsafe.Pointer(res)).Flast) {
  43568 			break
  43569 		}
  43570 		v = libc.Xabs(tls, int32(**(**int16_t)(__ccgo_up((*VP8Residual)(unsafe.Pointer(res)).Fcoeffs + uintptr(n)*2))))
  43571 		if v >= int32(2) {
  43572 			v11 = int32(2)
  43573 		} else {
  43574 			v11 = v
  43575 		}
  43576 		ctx = v11
  43577 		v3 = v
  43578 		if v3 > int32(MAX_VARIABLE_LEVEL) {
  43579 			v7 = int32(MAX_VARIABLE_LEVEL)
  43580 		} else {
  43581 			v7 = v3
  43582 		}
  43583 		v5 = int32(VP8LevelFixedCosts[v3]) + int32(**(**uint16_t)(__ccgo_up(t + uintptr(v7)*2)))
  43584 		goto _14
  43585 	_14:
  43586 		cost = cost + v5
  43587 		t = **(**uintptr)(__ccgo_up(costs + uintptr(n+int32(1))*24 + uintptr(ctx)*8))
  43588 		goto _10
  43589 	_10:
  43590 		;
  43591 		n = n + 1
  43592 	}
  43593 	// Last coefficient is always non-zero
  43594 	v1 = libc.Xabs(tls, int32(**(**int16_t)(__ccgo_up((*VP8Residual)(unsafe.Pointer(res)).Fcoeffs + uintptr(n)*2))))
  43595 	v11 = v1
  43596 	if v11 > int32(MAX_VARIABLE_LEVEL) {
  43597 		v5 = int32(MAX_VARIABLE_LEVEL)
  43598 	} else {
  43599 		v5 = v11
  43600 	}
  43601 	v3 = int32(VP8LevelFixedCosts[v11]) + int32(**(**uint16_t)(__ccgo_up(t + uintptr(v5)*2)))
  43602 	goto _18
  43603 _18:
  43604 	cost = cost + v3
  43605 	if n < int32(15) {
  43606 		b = int32(VP8EncBands[n+int32(1)])
  43607 		if v1 == int32(1) {
  43608 			v11 = int32(1)
  43609 		} else {
  43610 			v11 = int32(2)
  43611 		}
  43612 		ctx1 = v11
  43613 		last_p0 = int32(**(**uint8_t)(__ccgo_up((*VP8Residual)(unsafe.Pointer(res)).Fprob + uintptr(b)*33 + uintptr(ctx1)*11)))
  43614 		v2 = uint8(last_p0)
  43615 		if !(0 != 0) {
  43616 			v5 = int32(VP8EntropyCost[v2])
  43617 		} else {
  43618 			v5 = int32(VP8EntropyCost[int32(255)-int32(v2)])
  43619 		}
  43620 		v3 = v5
  43621 		goto _23
  43622 	_23:
  43623 		cost = cost + v3
  43624 	}
  43625 	return cost
  43626 }
  43627 
  43628 func SetResidualCoeffs_C(tls *libc.TLS, coeffs uintptr, res uintptr) {
  43629 	var n int32
  43630 	_ = n
  43631 	(*VP8Residual)(unsafe.Pointer(res)).Flast = -int32(1)
  43632 	n = int32(15)
  43633 	for {
  43634 		if !(n >= 0) {
  43635 			break
  43636 		}
  43637 		if **(**int16_t)(__ccgo_up(coeffs + uintptr(n)*2)) != 0 {
  43638 			(*VP8Residual)(unsafe.Pointer(res)).Flast = n
  43639 			break
  43640 		}
  43641 		goto _1
  43642 	_1:
  43643 		;
  43644 		n = n - 1
  43645 	}
  43646 	(*VP8Residual)(unsafe.Pointer(res)).Fcoeffs = coeffs
  43647 }
  43648 
  43649 func VP8EncDspCostInit(tls *libc.TLS) {
  43650 	if libc.AtomicLoadPUintptr(uintptr(unsafe.Pointer(&VP8EncDspCostInit_body_last_cpuinfo_used))) == VP8GetCPUInfo {
  43651 		goto _1
  43652 	}
  43653 	VP8EncDspCostInit_body(tls)
  43654 	libc.AtomicStorePUintptr(uintptr(unsafe.Pointer(&VP8EncDspCostInit_body_last_cpuinfo_used)), VP8GetCPUInfo)
  43655 	goto _2
  43656 _2:
  43657 	;
  43658 	goto _1
  43659 _1: /**/ //
  43660 }
  43661 
  43662 var VP8EncDspCostInit_body_last_cpuinfo_used = uintptr(0)
  43663 
  43664 func init() {
  43665 	p := unsafe.Pointer(&VP8EncDspCostInit_body_last_cpuinfo_used)
  43666 	*(*uintptr)(unsafe.Add(p, 0)) = uintptr(unsafe.Pointer(&VP8EncDspCostInit_body_last_cpuinfo_used))
  43667 }
  43668 
  43669 func VP8EncDspCostInit_body(tls *libc.TLS) {
  43670 	VP8GetResidualCost = __ccgo_fp(GetResidualCost_C)
  43671 	VP8SetResidualCoeffs = __ccgo_fp(SetResidualCoeffs_C)
  43672 	// If defined, use CPUInfo() to overwrite some pointers with faster versions.
  43673 	if VP8GetCPUInfo != libc.UintptrFromInt32(0) {
  43674 	}
  43675 }
  43676 
  43677 const SIZE_MAX23 = "UINT64_MAX"
  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 /**
  43692  * This file has no copyright assigned and is placed in the Public Domain.
  43693  * This file is part of the mingw-w64 runtime package.
  43694  * No warranty is given; refer to the file DISCLAIMER.PD within this package.
  43695  */
  43696 
  43697 /**
  43698  * This file has no copyright assigned and is placed in the Public Domain.
  43699  * This file is part of the mingw-w64 runtime package.
  43700  * No warranty is given; refer to the file DISCLAIMER.PD within this package.
  43701  */
  43702 
  43703 /*
  43704  * ISO C Standard:  7.17  Common definitions  <stddef.h>
  43705  */
  43706 
  43707 /* Copyright (C) 1989-2026 Free Software Foundation, Inc.
  43708 
  43709 This file is part of GCC.
  43710 
  43711 GCC is free software; you can redistribute it and/or modify
  43712 it under the terms of the GNU General Public License as published by
  43713 the Free Software Foundation; either version 3, or (at your option)
  43714 any later version.
  43715 
  43716 GCC is distributed in the hope that it will be useful,
  43717 but WITHOUT ANY WARRANTY; without even the implied warranty of
  43718 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  43719 GNU General Public License for more details.
  43720 
  43721 Under Section 7 of GPL version 3, you are granted additional
  43722 permissions described in the GCC Runtime Library Exception, version
  43723 3.1, as published by the Free Software Foundation.
  43724 
  43725 You should have received a copy of the GNU General Public License and
  43726 a copy of the GCC Runtime Library Exception along with this program;
  43727 see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
  43728 <http://www.gnu.org/licenses/>.  */
  43729 
  43730 /*
  43731  * ISO C Standard:  7.17  Common definitions  <stddef.h>
  43732  */
  43733 
  43734 // Copyright 2010 Google Inc. All Rights Reserved.
  43735 //
  43736 // Use of this source code is governed by a BSD-style license
  43737 // that can be found in the COPYING file in the root of the source
  43738 // tree. An additional intellectual property rights grant can be found
  43739 // in the file PATENTS. All contributing project authors may
  43740 // be found in the AUTHORS file in the root of the source tree.
  43741 // -----------------------------------------------------------------------------
  43742 //
  43743 //  Common types + memory wrappers
  43744 //
  43745 // Author: Skal (pascal.massimino@gmail.com)
  43746 
  43747 //------------------------------------------------------------------------------
  43748 // SSE2 detection.
  43749 //
  43750 
  43751 // C documentation
  43752 //
  43753 //	// apple/darwin gcc-4.0.1 defines __PIC__, but not __pic__ with -fPIC.
  43754 func GetCPUInfo(tls *libc.TLS, cpu_info uintptr, info_type int32) {
  43755 	//   __asm__ volatile (
  43756 	//     "cpuid\n"
  43757 	//     : "=a"(cpu_info[0]), "=b"(cpu_info[1]), "=c"(cpu_info[2]), "=d"(cpu_info[3])
  43758 	//     : "a"(info_type), "c"(0));
  43759 	libc.X__assert_fail(tls, __ccgo_ts+594, __ccgo_ts+629, 45, __ccgo_ts+635)
  43760 }
  43761 
  43762 // C documentation
  43763 //
  43764 //	// NaCl has no support for xgetbv or the raw opcode.
  43765 func xgetbv(tls *libc.TLS) (r uint64_t) {
  43766 	var eax, ecx, edx uint32_t
  43767 	_, _, _ = eax, ecx, edx
  43768 	ecx = uint32(0)
  43769 	// Use the raw opcode for xgetbv for compatibility with older toolchains.
  43770 	//   // Use the raw opcode for xgetbv for compatibility with older toolchains.
  43771 	//   __asm__ volatile (
  43772 	//     ".byte 0x0f, 0x01, 0xd0\n"
  43773 	//     : "=a"(eax), "=d"(edx) : "c" (ecx));
  43774 	libc.X__assert_fail(tls, __ccgo_ts+594, __ccgo_ts+629, 70, __ccgo_ts+646)
  43775 	return uint64(edx)<<libc.Int32FromInt32(32) | uint64(eax)
  43776 }
  43777 
  43778 // C documentation
  43779 //
  43780 //	// helper function for run-time detection of slow SSSE3 platforms
  43781 func CheckSlowModel(tls *libc.TLS, info int32) (r int32) {
  43782 	var family, model uint32_t
  43783 	var i size_t
  43784 	_, _, _ = family, i, model
  43785 	model = uint32(info&int32(0xf0000)>>int32(12) | info>>int32(4)&int32(0xf))
  43786 	family = uint32(info >> int32(8) & int32(0xf))
  43787 	if family == uint32(0x06) {
  43788 		i = uint64(0)
  43789 		for {
  43790 			if !(i < libc.Uint64FromInt64(6)/libc.Uint64FromInt64(1)) {
  43791 				break
  43792 			}
  43793 			if model == uint32(kSlowModels[i]) {
  43794 				return int32(1)
  43795 			}
  43796 			goto _1
  43797 		_1:
  43798 			;
  43799 			i = i + 1
  43800 		}
  43801 	}
  43802 	return 0
  43803 }
  43804 
  43805 // Table listing display models with longer latencies for the bsr instruction
  43806 // (ie 2 cycles vs 10/16 cycles) and some SSSE3 instructions like pshufb.
  43807 // Refer to Intel 64 and IA-32 Architectures Optimization Reference Manual.
  43808 var kSlowModels = [6]uint8_t{
  43809 	0: uint8(0x37),
  43810 	1: uint8(0x4a),
  43811 	2: uint8(0x4d),
  43812 	3: uint8(0x1c),
  43813 	4: uint8(0x26),
  43814 	5: uint8(0x27),
  43815 }
  43816 
  43817 func x86CPUInfo(tls *libc.TLS, feature CPUFeature) (r int32) {
  43818 	bp := tls.Alloc(16)
  43819 	defer tls.Free(16)
  43820 	var VENDOR_ID_INTEL_EBX, VENDOR_ID_INTEL_ECX, VENDOR_ID_INTEL_EDX, is_intel, max_cpuid_value int32
  43821 	var _ /* cpu_info at bp+0 */ [4]int32
  43822 	_, _, _, _, _ = VENDOR_ID_INTEL_EBX, VENDOR_ID_INTEL_ECX, VENDOR_ID_INTEL_EDX, is_intel, max_cpuid_value
  43823 	is_intel = 0
  43824 	// get the highest feature value cpuid supports
  43825 	GetCPUInfo(tls, bp, 0)
  43826 	max_cpuid_value = (**(**[4]int32)(__ccgo_up(bp)))[0]
  43827 	if max_cpuid_value < int32(1) {
  43828 		return 0
  43829 	} else {
  43830 		VENDOR_ID_INTEL_EBX = int32(0x756e6547)                                                                                                                                                                                             // uneG
  43831 		VENDOR_ID_INTEL_EDX = int32(0x49656e69)                                                                                                                                                                                             // Ieni
  43832 		VENDOR_ID_INTEL_ECX = int32(0x6c65746e)                                                                                                                                                                                             // letn
  43833 		is_intel = libc.BoolInt32((**(**[4]int32)(__ccgo_up(bp)))[int32(1)] == VENDOR_ID_INTEL_EBX && (**(**[4]int32)(__ccgo_up(bp)))[int32(2)] == VENDOR_ID_INTEL_ECX && (**(**[4]int32)(__ccgo_up(bp)))[int32(3)] == VENDOR_ID_INTEL_EDX) // genuine Intel?
  43834 	}
  43835 	GetCPUInfo(tls, bp, int32(1))
  43836 	if feature == int32(kSSE2) {
  43837 		return libc.BoolInt32(!!((**(**[4]int32)(__ccgo_up(bp)))[int32(3)]&(libc.Int32FromInt32(1)<<libc.Int32FromInt32(26)) != 0))
  43838 	}
  43839 	if feature == int32(kSSE3) {
  43840 		return libc.BoolInt32(!!((**(**[4]int32)(__ccgo_up(bp)))[int32(2)]&(libc.Int32FromInt32(1)<<libc.Int32FromInt32(0)) != 0))
  43841 	}
  43842 	if feature == int32(kSlowSSSE3) {
  43843 		if is_intel != 0 && (**(**[4]int32)(__ccgo_up(bp)))[int32(2)]&(libc.Int32FromInt32(1)<<libc.Int32FromInt32(9)) != 0 { // SSSE3?
  43844 			return CheckSlowModel(tls, (**(**[4]int32)(__ccgo_up(bp)))[0])
  43845 		}
  43846 		return 0
  43847 	}
  43848 	if feature == int32(kSSE4_1) {
  43849 		return libc.BoolInt32(!!((**(**[4]int32)(__ccgo_up(bp)))[int32(2)]&(libc.Int32FromInt32(1)<<libc.Int32FromInt32(19)) != 0))
  43850 	}
  43851 	if feature == int32(kAVX) {
  43852 		// bits 27 (OSXSAVE) & 28 (256-bit AVX)
  43853 		if (**(**[4]int32)(__ccgo_up(bp)))[int32(2)]&int32(0x18000000) == int32(0x18000000) {
  43854 			// XMM state and YMM state enabled by the OS.
  43855 			return libc.BoolInt32(xgetbv(tls)&uint64(0x6) == uint64(0x6))
  43856 		}
  43857 	}
  43858 	if feature == int32(kAVX2) {
  43859 		if x86CPUInfo(tls, int32(kAVX)) != 0 && max_cpuid_value >= int32(7) {
  43860 			GetCPUInfo(tls, bp, int32(7))
  43861 			return libc.BoolInt32(!!((**(**[4]int32)(__ccgo_up(bp)))[int32(1)]&(libc.Int32FromInt32(1)<<libc.Int32FromInt32(5)) != 0))
  43862 		}
  43863 	}
  43864 	return 0
  43865 }
  43866 
  43867 func init() {
  43868 	p := unsafe.Pointer(&VP8GetCPUInfo)
  43869 	*(*uintptr)(unsafe.Add(p, 0)) = __ccgo_fp(x86CPUInfo)
  43870 }
  43871 
  43872 var kHashMul14 = uint32(0x1e35a7bd)
  43873 
  43874 //------------------------------------------------------------------------------
  43875 
  43876 // Copyright 2010 Google Inc. All Rights Reserved.
  43877 //
  43878 // Use of this source code is governed by a BSD-style license
  43879 // that can be found in the COPYING file in the root of the source
  43880 // tree. An additional intellectual property rights grant can be found
  43881 // in the file PATENTS. All contributing project authors may
  43882 // be found in the AUTHORS file in the root of the source tree.
  43883 // -----------------------------------------------------------------------------
  43884 //
  43885 //  Common types + memory wrappers
  43886 //
  43887 // Author: Skal (pascal.massimino@gmail.com)
  43888 
  43889 //------------------------------------------------------------------------------
  43890 
  43891 func clip_8b1(tls *libc.TLS, v int32) (r uint8_t) {
  43892 	var v1, v2 int32
  43893 	_, _ = v1, v2
  43894 	if !(v & ^libc.Int32FromInt32(0xff) != 0) {
  43895 		v1 = v
  43896 	} else {
  43897 		if v < 0 {
  43898 			v2 = 0
  43899 		} else {
  43900 			v2 = int32(255)
  43901 		}
  43902 		v1 = v2
  43903 	}
  43904 	return uint8(v1)
  43905 }
  43906 
  43907 //------------------------------------------------------------------------------
  43908 // Transforms (Paragraph 14.4)
  43909 
  43910 func TransformOne_C(tls *libc.TLS, in uintptr, dst uintptr) {
  43911 	bp := tls.Alloc(64)
  43912 	defer tls.Free(64)
  43913 	var a, a1, b, b1, c, c1, d, d1, dc, i int32
  43914 	var tmp uintptr
  43915 	var _ /* C at bp+0 */ [16]int32
  43916 	_, _, _, _, _, _, _, _, _, _, _ = a, a1, b, b1, c, c1, d, d1, dc, i, tmp
  43917 	tmp = bp
  43918 	i = 0
  43919 	for {
  43920 		if !(i < int32(4)) {
  43921 			break
  43922 		} // vertical pass
  43923 		a = int32(**(**int16_t)(__ccgo_up(in))) + int32(**(**int16_t)(__ccgo_up(in + 8*2)))                                                                                                                                       // [-4096, 4094]
  43924 		b = int32(**(**int16_t)(__ccgo_up(in))) - int32(**(**int16_t)(__ccgo_up(in + 8*2)))                                                                                                                                       // [-4095, 4095]
  43925 		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]
  43926 		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]
  43927 		**(**int32)(__ccgo_up(tmp)) = a + d                                                                                                                                                                                       // [-7881, 7875]
  43928 		**(**int32)(__ccgo_up(tmp + 1*4)) = b + c                                                                                                                                                                                 // [-7878, 7878]
  43929 		**(**int32)(__ccgo_up(tmp + 2*4)) = b - c                                                                                                                                                                                 // [-7878, 7878]
  43930 		**(**int32)(__ccgo_up(tmp + 3*4)) = a - d                                                                                                                                                                                 // [-7877, 7879]
  43931 		tmp = tmp + uintptr(4)*4
  43932 		in += 2
  43933 		goto _1
  43934 	_1:
  43935 		;
  43936 		i = i + 1
  43937 	}
  43938 	// Each pass is expanding the dynamic range by ~3.85 (upper bound).
  43939 	// The exact value is (2. + (20091 + 35468) / 65536).
  43940 	// After the second pass, maximum interval is [-3794, 3794], assuming
  43941 	// an input in [-2048, 2047] interval. We then need to add a dst value
  43942 	// in the [0, 255] range.
  43943 	// In the worst case scenario, the input to clip_8b() can be as large as
  43944 	// [-60713, 60968].
  43945 	tmp = bp
  43946 	i = 0
  43947 	for {
  43948 		if !(i < int32(4)) {
  43949 			break
  43950 		} // horizontal pass
  43951 		dc = **(**int32)(__ccgo_up(tmp)) + int32(4)
  43952 		a1 = dc + **(**int32)(__ccgo_up(tmp + 8*4))
  43953 		b1 = dc - **(**int32)(__ccgo_up(tmp + 8*4))
  43954 		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)))
  43955 		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)
  43956 		**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = clip_8b1(tls, int32(**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))))+(a1+d1)>>int32(3))
  43957 		**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = clip_8b1(tls, int32(**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))))+(b1+c1)>>int32(3))
  43958 		**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = clip_8b1(tls, int32(**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))))+(b1-c1)>>int32(3))
  43959 		**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = clip_8b1(tls, int32(**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))))+(a1-d1)>>int32(3))
  43960 		tmp += 4
  43961 		dst = dst + uintptr(BPS)
  43962 		goto _2
  43963 	_2:
  43964 		;
  43965 		i = i + 1
  43966 	}
  43967 }
  43968 
  43969 // C documentation
  43970 //
  43971 //	// Simplified transform when only in[0], in[1] and in[4] are non-zero
  43972 func TransformAC3_C(tls *libc.TLS, in uintptr, dst uintptr) {
  43973 	var DC, DC1, DC2, DC3, a, c1, c4, d1, d4 int32
  43974 	_, _, _, _, _, _, _, _, _ = DC, DC1, DC2, DC3, a, c1, c4, d1, d4
  43975 	a = int32(**(**int16_t)(__ccgo_up(in))) + int32(4)
  43976 	c4 = int32(**(**int16_t)(__ccgo_up(in + 4*2))) * libc.Int32FromInt32(WEBP_TRANSFORM_AC3_C2) >> libc.Int32FromInt32(16)
  43977 	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)))
  43978 	c1 = int32(**(**int16_t)(__ccgo_up(in + 1*2))) * libc.Int32FromInt32(WEBP_TRANSFORM_AC3_C2) >> libc.Int32FromInt32(16)
  43979 	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)))
  43980 	DC = a + d4
  43981 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = clip_8b1(tls, int32(**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))))+(DC+d1)>>int32(3))
  43982 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = clip_8b1(tls, int32(**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))))+(DC+c1)>>int32(3))
  43983 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = clip_8b1(tls, int32(**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))))+(DC-c1)>>int32(3))
  43984 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = clip_8b1(tls, int32(**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))))+(DC-d1)>>int32(3))
  43985 	DC1 = a + c4
  43986 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = clip_8b1(tls, int32(**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))))+(DC1+d1)>>int32(3))
  43987 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = clip_8b1(tls, int32(**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))))+(DC1+c1)>>int32(3))
  43988 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = clip_8b1(tls, int32(**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))))+(DC1-c1)>>int32(3))
  43989 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = clip_8b1(tls, int32(**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))))+(DC1-d1)>>int32(3))
  43990 	DC2 = a - c4
  43991 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = clip_8b1(tls, int32(**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))))+(DC2+d1)>>int32(3))
  43992 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = clip_8b1(tls, int32(**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))))+(DC2+c1)>>int32(3))
  43993 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = clip_8b1(tls, int32(**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))))+(DC2-c1)>>int32(3))
  43994 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = clip_8b1(tls, int32(**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))))+(DC2-d1)>>int32(3))
  43995 	DC3 = a - d4
  43996 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = clip_8b1(tls, int32(**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))))+(DC3+d1)>>int32(3))
  43997 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = clip_8b1(tls, int32(**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))))+(DC3+c1)>>int32(3))
  43998 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = clip_8b1(tls, int32(**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))))+(DC3-c1)>>int32(3))
  43999 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = clip_8b1(tls, int32(**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))))+(DC3-d1)>>int32(3))
  44000 }
  44001 
  44002 func TransformTwo_C(tls *libc.TLS, in uintptr, dst uintptr, do_two int32) {
  44003 	TransformOne_C(tls, in, dst)
  44004 	if do_two != 0 {
  44005 		TransformOne_C(tls, in+uintptr(16)*2, dst+uintptr(4))
  44006 	}
  44007 }
  44008 
  44009 func TransformUV_C(tls *libc.TLS, in uintptr, dst uintptr) {
  44010 	(*(*func(*libc.TLS, uintptr, uintptr, int32))(unsafe.Pointer(&struct{ uintptr }{VP8Transform})))(tls, in+uintptr(libc.Int32FromInt32(0)*libc.Int32FromInt32(16))*2, dst, int32(1))
  44011 	(*(*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))
  44012 }
  44013 
  44014 func TransformDC_C(tls *libc.TLS, in uintptr, dst uintptr) {
  44015 	var DC, i, j int32
  44016 	_, _, _ = DC, i, j
  44017 	DC = int32(**(**int16_t)(__ccgo_up(in))) + int32(4)
  44018 	j = 0
  44019 	for {
  44020 		if !(j < int32(4)) {
  44021 			break
  44022 		}
  44023 		i = 0
  44024 		for {
  44025 			if !(i < int32(4)) {
  44026 				break
  44027 			}
  44028 			**(**uint8_t)(__ccgo_up(dst + uintptr(i+j*int32(BPS)))) = clip_8b1(tls, int32(**(**uint8_t)(__ccgo_up(dst + uintptr(i+j*int32(BPS)))))+DC>>libc.Int32FromInt32(3))
  44029 			goto _2
  44030 		_2:
  44031 			;
  44032 			i = i + 1
  44033 		}
  44034 		goto _1
  44035 	_1:
  44036 		;
  44037 		j = j + 1
  44038 	}
  44039 }
  44040 
  44041 func TransformDCUV_C(tls *libc.TLS, in uintptr, dst uintptr) {
  44042 	if **(**int16_t)(__ccgo_up(in + uintptr(libc.Int32FromInt32(0)*libc.Int32FromInt32(16))*2)) != 0 {
  44043 		(*(*func(*libc.TLS, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8TransformDC})))(tls, in+uintptr(libc.Int32FromInt32(0)*libc.Int32FromInt32(16))*2, dst)
  44044 	}
  44045 	if **(**int16_t)(__ccgo_up(in + uintptr(libc.Int32FromInt32(1)*libc.Int32FromInt32(16))*2)) != 0 {
  44046 		(*(*func(*libc.TLS, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8TransformDC})))(tls, in+uintptr(libc.Int32FromInt32(1)*libc.Int32FromInt32(16))*2, dst+uintptr(4))
  44047 	}
  44048 	if **(**int16_t)(__ccgo_up(in + uintptr(libc.Int32FromInt32(2)*libc.Int32FromInt32(16))*2)) != 0 {
  44049 		(*(*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)))
  44050 	}
  44051 	if **(**int16_t)(__ccgo_up(in + uintptr(libc.Int32FromInt32(3)*libc.Int32FromInt32(16))*2)) != 0 {
  44052 		(*(*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))
  44053 	}
  44054 }
  44055 
  44056 //------------------------------------------------------------------------------
  44057 // Paragraph 14.3
  44058 
  44059 func TransformWHT_C(tls *libc.TLS, in uintptr, out uintptr) {
  44060 	var a0, a01, a1, a11, a2, a21, a3, a31, dc, i int32
  44061 	var tmp [16]int32
  44062 	_, _, _, _, _, _, _, _, _, _, _ = a0, a01, a1, a11, a2, a21, a3, a31, dc, i, tmp
  44063 	i = 0
  44064 	for {
  44065 		if !(i < int32(4)) {
  44066 			break
  44067 		}
  44068 		a0 = int32(**(**int16_t)(__ccgo_up(in + uintptr(0+i)*2))) + int32(**(**int16_t)(__ccgo_up(in + uintptr(int32(12)+i)*2)))
  44069 		a1 = int32(**(**int16_t)(__ccgo_up(in + uintptr(int32(4)+i)*2))) + int32(**(**int16_t)(__ccgo_up(in + uintptr(int32(8)+i)*2)))
  44070 		a2 = int32(**(**int16_t)(__ccgo_up(in + uintptr(int32(4)+i)*2))) - int32(**(**int16_t)(__ccgo_up(in + uintptr(int32(8)+i)*2)))
  44071 		a3 = int32(**(**int16_t)(__ccgo_up(in + uintptr(0+i)*2))) - int32(**(**int16_t)(__ccgo_up(in + uintptr(int32(12)+i)*2)))
  44072 		tmp[0+i] = a0 + a1
  44073 		tmp[int32(8)+i] = a0 - a1
  44074 		tmp[int32(4)+i] = a3 + a2
  44075 		tmp[int32(12)+i] = a3 - a2
  44076 		goto _1
  44077 	_1:
  44078 		;
  44079 		i = i + 1
  44080 	}
  44081 	i = 0
  44082 	for {
  44083 		if !(i < int32(4)) {
  44084 			break
  44085 		}
  44086 		dc = tmp[0+i*int32(4)] + int32(3) // w/ rounder
  44087 		a01 = dc + tmp[int32(3)+i*int32(4)]
  44088 		a11 = tmp[int32(1)+i*int32(4)] + tmp[int32(2)+i*int32(4)]
  44089 		a21 = tmp[int32(1)+i*int32(4)] - tmp[int32(2)+i*int32(4)]
  44090 		a31 = dc - tmp[int32(3)+i*int32(4)]
  44091 		**(**int16_t)(__ccgo_up(out)) = int16((a01 + a11) >> int32(3))
  44092 		**(**int16_t)(__ccgo_up(out + 16*2)) = int16((a31 + a21) >> int32(3))
  44093 		**(**int16_t)(__ccgo_up(out + 32*2)) = int16((a01 - a11) >> int32(3))
  44094 		**(**int16_t)(__ccgo_up(out + 48*2)) = int16((a31 - a21) >> int32(3))
  44095 		out = out + uintptr(64)*2
  44096 		goto _2
  44097 	_2:
  44098 		;
  44099 		i = i + 1
  44100 	}
  44101 }
  44102 
  44103 //------------------------------------------------------------------------------
  44104 // Intra predictions
  44105 
  44106 func TrueMotion(tls *libc.TLS, dst uintptr, size int32) {
  44107 	var clip, clip0, top uintptr
  44108 	var x, y int32
  44109 	_, _, _, _, _ = clip, clip0, top, x, y
  44110 	top = dst - uintptr(BPS)
  44111 	clip0 = VP8kclip1 - uintptr(**(**uint8_t)(__ccgo_up(top + uintptr(-libc.Int32FromInt32(1)))))
  44112 	y = 0
  44113 	for {
  44114 		if !(y < size) {
  44115 			break
  44116 		}
  44117 		clip = clip0 + uintptr(**(**uint8_t)(__ccgo_up(dst + uintptr(-libc.Int32FromInt32(1)))))
  44118 		x = 0
  44119 		for {
  44120 			if !(x < size) {
  44121 				break
  44122 			}
  44123 			**(**uint8_t)(__ccgo_up(dst + uintptr(x))) = **(**uint8_t)(__ccgo_up(clip + uintptr(**(**uint8_t)(__ccgo_up(top + uintptr(x))))))
  44124 			goto _2
  44125 		_2:
  44126 			;
  44127 			x = x + 1
  44128 		}
  44129 		dst = dst + uintptr(BPS)
  44130 		goto _1
  44131 	_1:
  44132 		;
  44133 		y = y + 1
  44134 	}
  44135 }
  44136 
  44137 func TM4_C(tls *libc.TLS, dst uintptr) {
  44138 	TrueMotion(tls, dst, int32(4))
  44139 }
  44140 
  44141 func TM8uv_C(tls *libc.TLS, dst uintptr) {
  44142 	TrueMotion(tls, dst, int32(8))
  44143 }
  44144 
  44145 func TM16_C(tls *libc.TLS, dst uintptr) {
  44146 	TrueMotion(tls, dst, int32(16))
  44147 }
  44148 
  44149 //------------------------------------------------------------------------------
  44150 // 16x16
  44151 
  44152 func VE16_C(tls *libc.TLS, dst uintptr) {
  44153 	var j int32
  44154 	_ = j
  44155 	j = 0
  44156 	for {
  44157 		if !(j < int32(16)) {
  44158 			break
  44159 		}
  44160 		libc.Xmemcpy(tls, dst+uintptr(j*int32(BPS)), dst-uintptr(BPS), uint64(16))
  44161 		goto _1
  44162 	_1:
  44163 		;
  44164 		j = j + 1
  44165 	}
  44166 }
  44167 
  44168 func HE16_C(tls *libc.TLS, dst uintptr) {
  44169 	var j int32
  44170 	_ = j
  44171 	j = int32(16)
  44172 	for {
  44173 		if !(j > 0) {
  44174 			break
  44175 		}
  44176 		libc.Xmemset(tls, dst, int32(**(**uint8_t)(__ccgo_up(dst + uintptr(-libc.Int32FromInt32(1))))), uint64(16))
  44177 		dst = dst + uintptr(BPS)
  44178 		goto _1
  44179 	_1:
  44180 		;
  44181 		j = j - 1
  44182 	}
  44183 }
  44184 
  44185 func Put16(tls *libc.TLS, v int32, dst uintptr) {
  44186 	var j int32
  44187 	_ = j
  44188 	j = 0
  44189 	for {
  44190 		if !(j < int32(16)) {
  44191 			break
  44192 		}
  44193 		libc.Xmemset(tls, dst+uintptr(j*int32(BPS)), v, uint64(16))
  44194 		goto _1
  44195 	_1:
  44196 		;
  44197 		j = j + 1
  44198 	}
  44199 }
  44200 
  44201 func DC16_C(tls *libc.TLS, dst uintptr) {
  44202 	var DC, j int32
  44203 	_, _ = DC, j // DC
  44204 	DC = int32(16)
  44205 	j = 0
  44206 	for {
  44207 		if !(j < int32(16)) {
  44208 			break
  44209 		}
  44210 		DC = DC + (int32(**(**uint8_t)(__ccgo_up(dst + uintptr(-int32(1)+j*int32(BPS))))) + int32(**(**uint8_t)(__ccgo_up(dst + uintptr(j-int32(BPS))))))
  44211 		goto _1
  44212 	_1:
  44213 		;
  44214 		j = j + 1
  44215 	}
  44216 	Put16(tls, DC>>int32(5), dst)
  44217 }
  44218 
  44219 func DC16NoTop_C(tls *libc.TLS, dst uintptr) {
  44220 	var DC, j int32
  44221 	_, _ = DC, j // DC with top samples not available
  44222 	DC = int32(8)
  44223 	j = 0
  44224 	for {
  44225 		if !(j < int32(16)) {
  44226 			break
  44227 		}
  44228 		DC = DC + int32(**(**uint8_t)(__ccgo_up(dst + uintptr(-int32(1)+j*int32(BPS)))))
  44229 		goto _1
  44230 	_1:
  44231 		;
  44232 		j = j + 1
  44233 	}
  44234 	Put16(tls, DC>>int32(4), dst)
  44235 }
  44236 
  44237 func DC16NoLeft_C(tls *libc.TLS, dst uintptr) {
  44238 	var DC, i int32
  44239 	_, _ = DC, i // DC with left samples not available
  44240 	DC = int32(8)
  44241 	i = 0
  44242 	for {
  44243 		if !(i < int32(16)) {
  44244 			break
  44245 		}
  44246 		DC = DC + int32(**(**uint8_t)(__ccgo_up(dst + uintptr(i-int32(BPS)))))
  44247 		goto _1
  44248 	_1:
  44249 		;
  44250 		i = i + 1
  44251 	}
  44252 	Put16(tls, DC>>int32(4), dst)
  44253 }
  44254 
  44255 func DC16NoTopLeft_C(tls *libc.TLS, dst uintptr) {
  44256 	// DC with no top and left samples
  44257 	Put16(tls, int32(0x80), dst)
  44258 }
  44259 
  44260 //------------------------------------------------------------------------------
  44261 // 4x4
  44262 
  44263 func VE4_C(tls *libc.TLS, dst uintptr) {
  44264 	bp := tls.Alloc(16)
  44265 	defer tls.Free(16)
  44266 	var i int32
  44267 	var top uintptr
  44268 	var _ /* vals at bp+0 */ [4]uint8_t
  44269 	_, _ = i, top // vertical
  44270 	top = dst - uintptr(BPS)
  44271 	**(**[4]uint8_t)(__ccgo_up(bp)) = [4]uint8_t{
  44272 		0: uint8((int32(**(**uint8_t)(__ccgo_up(top + uintptr(-libc.Int32FromInt32(1))))) + libc.Int32FromInt32(2)*int32(**(**uint8_t)(__ccgo_up(top))) + int32(**(**uint8_t)(__ccgo_up(top + 1))) + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2)),
  44273 		1: uint8((int32(**(**uint8_t)(__ccgo_up(top))) + libc.Int32FromInt32(2)*int32(**(**uint8_t)(__ccgo_up(top + 1))) + int32(**(**uint8_t)(__ccgo_up(top + 2))) + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2)),
  44274 		2: uint8((int32(**(**uint8_t)(__ccgo_up(top + 1))) + libc.Int32FromInt32(2)*int32(**(**uint8_t)(__ccgo_up(top + 2))) + int32(**(**uint8_t)(__ccgo_up(top + 3))) + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2)),
  44275 		3: uint8((int32(**(**uint8_t)(__ccgo_up(top + 2))) + libc.Int32FromInt32(2)*int32(**(**uint8_t)(__ccgo_up(top + 3))) + int32(**(**uint8_t)(__ccgo_up(top + 4))) + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2)),
  44276 	}
  44277 	i = 0
  44278 	for {
  44279 		if !(i < int32(4)) {
  44280 			break
  44281 		}
  44282 		libc.Xmemcpy(tls, dst+uintptr(i*int32(BPS)), bp, uint64(4))
  44283 		goto _1
  44284 	_1:
  44285 		;
  44286 		i = i + 1
  44287 	}
  44288 }
  44289 
  44290 func HE4_C(tls *libc.TLS, dst uintptr) {
  44291 	bp := tls.Alloc(16)
  44292 	defer tls.Free(16)
  44293 	var A, B, C, D, E int32
  44294 	var v1 uint32_t
  44295 	_, _, _, _, _, _ = A, B, C, D, E, v1 // horizontal
  44296 	A = int32(**(**uint8_t)(__ccgo_up(dst + uintptr(-libc.Int32FromInt32(1)-libc.Int32FromInt32(BPS)))))
  44297 	B = int32(**(**uint8_t)(__ccgo_up(dst + uintptr(-libc.Int32FromInt32(1)))))
  44298 	C = int32(**(**uint8_t)(__ccgo_up(dst + uintptr(-libc.Int32FromInt32(1)+libc.Int32FromInt32(BPS)))))
  44299 	D = int32(**(**uint8_t)(__ccgo_up(dst + uintptr(-libc.Int32FromInt32(1)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))))
  44300 	E = int32(**(**uint8_t)(__ccgo_up(dst + uintptr(-libc.Int32FromInt32(1)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))))
  44301 	v1 = uint32(0x01010101) * uint32(uint8((A+libc.Int32FromInt32(2)*B+C+libc.Int32FromInt32(2))>>libc.Int32FromInt32(2)))
  44302 	*(*uint32_t)(unsafe.Pointer(bp)) = v1
  44303 	libc.Xmemcpy(tls, dst+uintptr(libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)), bp, uint64(4))
  44304 	v1 = uint32(0x01010101) * uint32(uint8((B+libc.Int32FromInt32(2)*C+D+libc.Int32FromInt32(2))>>libc.Int32FromInt32(2)))
  44305 	*(*uint32_t)(unsafe.Pointer(bp)) = v1
  44306 	libc.Xmemcpy(tls, dst+uintptr(libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)), bp, uint64(4))
  44307 	v1 = uint32(0x01010101) * uint32(uint8((C+libc.Int32FromInt32(2)*D+E+libc.Int32FromInt32(2))>>libc.Int32FromInt32(2)))
  44308 	*(*uint32_t)(unsafe.Pointer(bp)) = v1
  44309 	libc.Xmemcpy(tls, dst+uintptr(libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)), bp, uint64(4))
  44310 	v1 = uint32(0x01010101) * uint32(uint8((D+libc.Int32FromInt32(2)*E+E+libc.Int32FromInt32(2))>>libc.Int32FromInt32(2)))
  44311 	*(*uint32_t)(unsafe.Pointer(bp)) = v1
  44312 	libc.Xmemcpy(tls, dst+uintptr(libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)), bp, uint64(4))
  44313 }
  44314 
  44315 func DC4_C(tls *libc.TLS, dst uintptr) {
  44316 	var dc uint32_t
  44317 	var i int32
  44318 	_, _ = dc, i // DC
  44319 	dc = uint32(4)
  44320 	i = 0
  44321 	for {
  44322 		if !(i < int32(4)) {
  44323 			break
  44324 		}
  44325 		dc = dc + uint32(int32(**(**uint8_t)(__ccgo_up(dst + uintptr(i-int32(BPS)))))+int32(**(**uint8_t)(__ccgo_up(dst + uintptr(-int32(1)+i*int32(BPS))))))
  44326 		goto _1
  44327 	_1:
  44328 		;
  44329 		i = i + 1
  44330 	}
  44331 	dc = dc >> uint32(3)
  44332 	i = 0
  44333 	for {
  44334 		if !(i < int32(4)) {
  44335 			break
  44336 		}
  44337 		libc.Xmemset(tls, dst+uintptr(i*int32(BPS)), int32(dc), uint64(4))
  44338 		goto _2
  44339 	_2:
  44340 		;
  44341 		i = i + 1
  44342 	}
  44343 }
  44344 
  44345 func RD4_C(tls *libc.TLS, dst uintptr) {
  44346 	var A, B, C, D, I, J, K, L, X int32
  44347 	var v1, v2, v3 uint8_t
  44348 	_, _, _, _, _, _, _, _, _, _, _, _ = A, B, C, D, I, J, K, L, X, v1, v2, v3 // Down-right
  44349 	I = int32(**(**uint8_t)(__ccgo_up(dst + uintptr(-libc.Int32FromInt32(1)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))))
  44350 	J = int32(**(**uint8_t)(__ccgo_up(dst + uintptr(-libc.Int32FromInt32(1)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))))
  44351 	K = int32(**(**uint8_t)(__ccgo_up(dst + uintptr(-libc.Int32FromInt32(1)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))))
  44352 	L = int32(**(**uint8_t)(__ccgo_up(dst + uintptr(-libc.Int32FromInt32(1)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))))
  44353 	X = int32(**(**uint8_t)(__ccgo_up(dst + uintptr(-libc.Int32FromInt32(1)-libc.Int32FromInt32(BPS)))))
  44354 	A = int32(**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)-libc.Int32FromInt32(BPS)))))
  44355 	B = int32(**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)-libc.Int32FromInt32(BPS)))))
  44356 	C = int32(**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)-libc.Int32FromInt32(BPS)))))
  44357 	D = int32(**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)-libc.Int32FromInt32(BPS)))))
  44358 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = uint8((J + libc.Int32FromInt32(2)*K + L + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  44359 	v1 = uint8((I + libc.Int32FromInt32(2)*J + K + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  44360 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = v1
  44361 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = v1
  44362 	v2 = uint8((X + libc.Int32FromInt32(2)*I + J + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  44363 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = v2
  44364 	v1 = v2
  44365 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = v1
  44366 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = v1
  44367 	v3 = uint8((A + libc.Int32FromInt32(2)*X + I + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  44368 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = v3
  44369 	v2 = v3
  44370 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = v2
  44371 	v1 = v2
  44372 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = v1
  44373 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = v1
  44374 	v2 = uint8((B + libc.Int32FromInt32(2)*A + X + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  44375 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = v2
  44376 	v1 = v2
  44377 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = v1
  44378 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = v1
  44379 	v1 = uint8((C + libc.Int32FromInt32(2)*B + A + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  44380 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = v1
  44381 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = v1
  44382 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = uint8((D + libc.Int32FromInt32(2)*C + B + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  44383 }
  44384 
  44385 func LD4_C(tls *libc.TLS, dst uintptr) {
  44386 	var A, B, C, D, E, F, G, H int32
  44387 	var v1, v2, v3 uint8_t
  44388 	_, _, _, _, _, _, _, _, _, _, _ = A, B, C, D, E, F, G, H, v1, v2, v3 // Down-Left
  44389 	A = int32(**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)-libc.Int32FromInt32(BPS)))))
  44390 	B = int32(**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)-libc.Int32FromInt32(BPS)))))
  44391 	C = int32(**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)-libc.Int32FromInt32(BPS)))))
  44392 	D = int32(**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)-libc.Int32FromInt32(BPS)))))
  44393 	E = int32(**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(4)-libc.Int32FromInt32(BPS)))))
  44394 	F = int32(**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(5)-libc.Int32FromInt32(BPS)))))
  44395 	G = int32(**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(6)-libc.Int32FromInt32(BPS)))))
  44396 	H = int32(**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(7)-libc.Int32FromInt32(BPS)))))
  44397 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = uint8((A + libc.Int32FromInt32(2)*B + C + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  44398 	v1 = uint8((B + libc.Int32FromInt32(2)*C + D + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  44399 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = v1
  44400 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = v1
  44401 	v2 = uint8((C + libc.Int32FromInt32(2)*D + E + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  44402 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = v2
  44403 	v1 = v2
  44404 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = v1
  44405 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = v1
  44406 	v3 = uint8((D + libc.Int32FromInt32(2)*E + F + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  44407 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = v3
  44408 	v2 = v3
  44409 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = v2
  44410 	v1 = v2
  44411 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = v1
  44412 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = v1
  44413 	v2 = uint8((E + libc.Int32FromInt32(2)*F + G + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  44414 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = v2
  44415 	v1 = v2
  44416 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = v1
  44417 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = v1
  44418 	v1 = uint8((F + libc.Int32FromInt32(2)*G + H + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  44419 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = v1
  44420 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = v1
  44421 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = uint8((G + libc.Int32FromInt32(2)*H + H + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  44422 }
  44423 
  44424 func VR4_C(tls *libc.TLS, dst uintptr) {
  44425 	var A, B, C, D, I, J, K, X int32
  44426 	var v1 uint8_t
  44427 	_, _, _, _, _, _, _, _, _ = A, B, C, D, I, J, K, X, v1 // Vertical-Right
  44428 	I = int32(**(**uint8_t)(__ccgo_up(dst + uintptr(-libc.Int32FromInt32(1)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))))
  44429 	J = int32(**(**uint8_t)(__ccgo_up(dst + uintptr(-libc.Int32FromInt32(1)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))))
  44430 	K = int32(**(**uint8_t)(__ccgo_up(dst + uintptr(-libc.Int32FromInt32(1)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))))
  44431 	X = int32(**(**uint8_t)(__ccgo_up(dst + uintptr(-libc.Int32FromInt32(1)-libc.Int32FromInt32(BPS)))))
  44432 	A = int32(**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)-libc.Int32FromInt32(BPS)))))
  44433 	B = int32(**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)-libc.Int32FromInt32(BPS)))))
  44434 	C = int32(**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)-libc.Int32FromInt32(BPS)))))
  44435 	D = int32(**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)-libc.Int32FromInt32(BPS)))))
  44436 	v1 = uint8((X + A + libc.Int32FromInt32(1)) >> libc.Int32FromInt32(1))
  44437 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = v1
  44438 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = v1
  44439 	v1 = uint8((A + B + libc.Int32FromInt32(1)) >> libc.Int32FromInt32(1))
  44440 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = v1
  44441 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = v1
  44442 	v1 = uint8((B + C + libc.Int32FromInt32(1)) >> libc.Int32FromInt32(1))
  44443 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = v1
  44444 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = v1
  44445 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = uint8((C + D + libc.Int32FromInt32(1)) >> libc.Int32FromInt32(1))
  44446 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = uint8((K + libc.Int32FromInt32(2)*J + I + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  44447 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = uint8((J + libc.Int32FromInt32(2)*I + X + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  44448 	v1 = uint8((I + libc.Int32FromInt32(2)*X + A + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  44449 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = v1
  44450 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = v1
  44451 	v1 = uint8((X + libc.Int32FromInt32(2)*A + B + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  44452 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = v1
  44453 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = v1
  44454 	v1 = uint8((A + libc.Int32FromInt32(2)*B + C + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  44455 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = v1
  44456 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = v1
  44457 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = uint8((B + libc.Int32FromInt32(2)*C + D + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  44458 }
  44459 
  44460 func VL4_C(tls *libc.TLS, dst uintptr) {
  44461 	var A, B, C, D, E, F, G, H int32
  44462 	var v1 uint8_t
  44463 	_, _, _, _, _, _, _, _, _ = A, B, C, D, E, F, G, H, v1 // Vertical-Left
  44464 	A = int32(**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)-libc.Int32FromInt32(BPS)))))
  44465 	B = int32(**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)-libc.Int32FromInt32(BPS)))))
  44466 	C = int32(**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)-libc.Int32FromInt32(BPS)))))
  44467 	D = int32(**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)-libc.Int32FromInt32(BPS)))))
  44468 	E = int32(**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(4)-libc.Int32FromInt32(BPS)))))
  44469 	F = int32(**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(5)-libc.Int32FromInt32(BPS)))))
  44470 	G = int32(**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(6)-libc.Int32FromInt32(BPS)))))
  44471 	H = int32(**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(7)-libc.Int32FromInt32(BPS)))))
  44472 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = uint8((A + B + libc.Int32FromInt32(1)) >> libc.Int32FromInt32(1))
  44473 	v1 = uint8((B + C + libc.Int32FromInt32(1)) >> libc.Int32FromInt32(1))
  44474 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = v1
  44475 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = v1
  44476 	v1 = uint8((C + D + libc.Int32FromInt32(1)) >> libc.Int32FromInt32(1))
  44477 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = v1
  44478 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = v1
  44479 	v1 = uint8((D + E + libc.Int32FromInt32(1)) >> libc.Int32FromInt32(1))
  44480 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = v1
  44481 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = v1
  44482 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = uint8((A + libc.Int32FromInt32(2)*B + C + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  44483 	v1 = uint8((B + libc.Int32FromInt32(2)*C + D + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  44484 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = v1
  44485 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = v1
  44486 	v1 = uint8((C + libc.Int32FromInt32(2)*D + E + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  44487 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = v1
  44488 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = v1
  44489 	v1 = uint8((D + libc.Int32FromInt32(2)*E + F + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  44490 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = v1
  44491 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = v1
  44492 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = uint8((E + libc.Int32FromInt32(2)*F + G + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  44493 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = uint8((F + libc.Int32FromInt32(2)*G + H + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  44494 }
  44495 
  44496 func HU4_C(tls *libc.TLS, dst uintptr) {
  44497 	var I, J, K, L int32
  44498 	var v1, v2, v3, v4, v5 uint8_t
  44499 	_, _, _, _, _, _, _, _, _ = I, J, K, L, v1, v2, v3, v4, v5 // Horizontal-Up
  44500 	I = int32(**(**uint8_t)(__ccgo_up(dst + uintptr(-libc.Int32FromInt32(1)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))))
  44501 	J = int32(**(**uint8_t)(__ccgo_up(dst + uintptr(-libc.Int32FromInt32(1)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))))
  44502 	K = int32(**(**uint8_t)(__ccgo_up(dst + uintptr(-libc.Int32FromInt32(1)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))))
  44503 	L = int32(**(**uint8_t)(__ccgo_up(dst + uintptr(-libc.Int32FromInt32(1)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))))
  44504 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = uint8((I + J + libc.Int32FromInt32(1)) >> libc.Int32FromInt32(1))
  44505 	v1 = uint8((J + K + libc.Int32FromInt32(1)) >> libc.Int32FromInt32(1))
  44506 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = v1
  44507 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = v1
  44508 	v1 = uint8((K + L + libc.Int32FromInt32(1)) >> libc.Int32FromInt32(1))
  44509 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = v1
  44510 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = v1
  44511 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = uint8((I + libc.Int32FromInt32(2)*J + K + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  44512 	v1 = uint8((J + libc.Int32FromInt32(2)*K + L + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  44513 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = v1
  44514 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = v1
  44515 	v1 = uint8((K + libc.Int32FromInt32(2)*L + L + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  44516 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = v1
  44517 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = v1
  44518 	v5 = uint8(L)
  44519 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = v5
  44520 	v4 = v5
  44521 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = v4
  44522 	v3 = v4
  44523 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = v3
  44524 	v2 = v3
  44525 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = v2
  44526 	v1 = v2
  44527 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = v1
  44528 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = v1
  44529 }
  44530 
  44531 func HD4_C(tls *libc.TLS, dst uintptr) {
  44532 	var A, B, C, I, J, K, L, X int32
  44533 	var v1 uint8_t
  44534 	_, _, _, _, _, _, _, _, _ = A, B, C, I, J, K, L, X, v1 // Horizontal-Down
  44535 	I = int32(**(**uint8_t)(__ccgo_up(dst + uintptr(-libc.Int32FromInt32(1)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))))
  44536 	J = int32(**(**uint8_t)(__ccgo_up(dst + uintptr(-libc.Int32FromInt32(1)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))))
  44537 	K = int32(**(**uint8_t)(__ccgo_up(dst + uintptr(-libc.Int32FromInt32(1)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))))
  44538 	L = int32(**(**uint8_t)(__ccgo_up(dst + uintptr(-libc.Int32FromInt32(1)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))))
  44539 	X = int32(**(**uint8_t)(__ccgo_up(dst + uintptr(-libc.Int32FromInt32(1)-libc.Int32FromInt32(BPS)))))
  44540 	A = int32(**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)-libc.Int32FromInt32(BPS)))))
  44541 	B = int32(**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)-libc.Int32FromInt32(BPS)))))
  44542 	C = int32(**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)-libc.Int32FromInt32(BPS)))))
  44543 	v1 = uint8((I + X + libc.Int32FromInt32(1)) >> libc.Int32FromInt32(1))
  44544 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = v1
  44545 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = v1
  44546 	v1 = uint8((J + I + libc.Int32FromInt32(1)) >> libc.Int32FromInt32(1))
  44547 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = v1
  44548 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = v1
  44549 	v1 = uint8((K + J + libc.Int32FromInt32(1)) >> libc.Int32FromInt32(1))
  44550 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = v1
  44551 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = v1
  44552 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = uint8((L + K + libc.Int32FromInt32(1)) >> libc.Int32FromInt32(1))
  44553 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = uint8((A + libc.Int32FromInt32(2)*B + C + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  44554 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = uint8((X + libc.Int32FromInt32(2)*A + B + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  44555 	v1 = uint8((I + libc.Int32FromInt32(2)*X + A + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  44556 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = v1
  44557 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = v1
  44558 	v1 = uint8((J + libc.Int32FromInt32(2)*I + X + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  44559 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = v1
  44560 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = v1
  44561 	v1 = uint8((K + libc.Int32FromInt32(2)*J + I + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  44562 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = v1
  44563 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = v1
  44564 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = uint8((L + libc.Int32FromInt32(2)*K + J + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  44565 }
  44566 
  44567 //------------------------------------------------------------------------------
  44568 // Chroma
  44569 
  44570 func VE8uv_C(tls *libc.TLS, dst uintptr) {
  44571 	var j int32
  44572 	_ = j
  44573 	j = 0
  44574 	for {
  44575 		if !(j < int32(8)) {
  44576 			break
  44577 		}
  44578 		libc.Xmemcpy(tls, dst+uintptr(j*int32(BPS)), dst-uintptr(BPS), uint64(8))
  44579 		goto _1
  44580 	_1:
  44581 		;
  44582 		j = j + 1
  44583 	}
  44584 }
  44585 
  44586 func HE8uv_C(tls *libc.TLS, dst uintptr) {
  44587 	var j int32
  44588 	_ = j
  44589 	j = 0
  44590 	for {
  44591 		if !(j < int32(8)) {
  44592 			break
  44593 		}
  44594 		libc.Xmemset(tls, dst, int32(**(**uint8_t)(__ccgo_up(dst + uintptr(-libc.Int32FromInt32(1))))), uint64(8))
  44595 		dst = dst + uintptr(BPS)
  44596 		goto _1
  44597 	_1:
  44598 		;
  44599 		j = j + 1
  44600 	}
  44601 }
  44602 
  44603 // C documentation
  44604 //
  44605 //	// helper for chroma-DC predictions
  44606 func Put8x8uv(tls *libc.TLS, value uint8_t, dst uintptr) {
  44607 	var j int32
  44608 	_ = j
  44609 	j = 0
  44610 	for {
  44611 		if !(j < int32(8)) {
  44612 			break
  44613 		}
  44614 		libc.Xmemset(tls, dst+uintptr(j*int32(BPS)), int32(value), uint64(8))
  44615 		goto _1
  44616 	_1:
  44617 		;
  44618 		j = j + 1
  44619 	}
  44620 }
  44621 
  44622 func DC8uv_C(tls *libc.TLS, dst uintptr) {
  44623 	var dc0, i int32
  44624 	_, _ = dc0, i // DC
  44625 	dc0 = int32(8)
  44626 	i = 0
  44627 	for {
  44628 		if !(i < int32(8)) {
  44629 			break
  44630 		}
  44631 		dc0 = dc0 + (int32(**(**uint8_t)(__ccgo_up(dst + uintptr(i-int32(BPS))))) + int32(**(**uint8_t)(__ccgo_up(dst + uintptr(-int32(1)+i*int32(BPS))))))
  44632 		goto _1
  44633 	_1:
  44634 		;
  44635 		i = i + 1
  44636 	}
  44637 	Put8x8uv(tls, uint8(dc0>>int32(4)), dst)
  44638 }
  44639 
  44640 func DC8uvNoLeft_C(tls *libc.TLS, dst uintptr) {
  44641 	var dc0, i int32
  44642 	_, _ = dc0, i // DC with no left samples
  44643 	dc0 = int32(4)
  44644 	i = 0
  44645 	for {
  44646 		if !(i < int32(8)) {
  44647 			break
  44648 		}
  44649 		dc0 = dc0 + int32(**(**uint8_t)(__ccgo_up(dst + uintptr(i-int32(BPS)))))
  44650 		goto _1
  44651 	_1:
  44652 		;
  44653 		i = i + 1
  44654 	}
  44655 	Put8x8uv(tls, uint8(dc0>>int32(3)), dst)
  44656 }
  44657 
  44658 func DC8uvNoTop_C(tls *libc.TLS, dst uintptr) {
  44659 	var dc0, i int32
  44660 	_, _ = dc0, i // DC with no top samples
  44661 	dc0 = int32(4)
  44662 	i = 0
  44663 	for {
  44664 		if !(i < int32(8)) {
  44665 			break
  44666 		}
  44667 		dc0 = dc0 + int32(**(**uint8_t)(__ccgo_up(dst + uintptr(-int32(1)+i*int32(BPS)))))
  44668 		goto _1
  44669 	_1:
  44670 		;
  44671 		i = i + 1
  44672 	}
  44673 	Put8x8uv(tls, uint8(dc0>>int32(3)), dst)
  44674 }
  44675 
  44676 func DC8uvNoTopLeft_C(tls *libc.TLS, dst uintptr) {
  44677 	// DC with nothing
  44678 	Put8x8uv(tls, uint8(0x80), dst)
  44679 }
  44680 
  44681 //------------------------------------------------------------------------------
  44682 // Edge filtering functions
  44683 
  44684 // C documentation
  44685 //
  44686 //	// 4 pixels in, 2 pixels out
  44687 func DoFilter2_C(tls *libc.TLS, p uintptr, step int32) {
  44688 	var a, a1, a2, p0, p1, q0, q1 int32
  44689 	_, _, _, _, _, _, _ = a, a1, a2, p0, p1, q0, q1
  44690 	p1 = int32(**(**uint8_t)(__ccgo_up(p + uintptr(-int32(2)*step))))
  44691 	p0 = int32(**(**uint8_t)(__ccgo_up(p + uintptr(-step))))
  44692 	q0 = int32(**(**uint8_t)(__ccgo_up(p)))
  44693 	q1 = int32(**(**uint8_t)(__ccgo_up(p + uintptr(step))))
  44694 	a = int32(3)*(q0-p0) + int32(**(**int8_t)(__ccgo_up(VP8ksclip1 + uintptr(p1-q1)))) // in [-893,892]
  44695 	a1 = int32(**(**int8_t)(__ccgo_up(VP8ksclip2 + uintptr((a+int32(4))>>int32(3)))))  // in [-16,15]
  44696 	a2 = int32(**(**int8_t)(__ccgo_up(VP8ksclip2 + uintptr((a+int32(3))>>int32(3)))))
  44697 	**(**uint8_t)(__ccgo_up(p + uintptr(-step))) = **(**uint8_t)(__ccgo_up(VP8kclip1 + uintptr(p0+a2)))
  44698 	**(**uint8_t)(__ccgo_up(p)) = **(**uint8_t)(__ccgo_up(VP8kclip1 + uintptr(q0-a1)))
  44699 }
  44700 
  44701 // C documentation
  44702 //
  44703 //	// 4 pixels in, 4 pixels out
  44704 func DoFilter4_C(tls *libc.TLS, p uintptr, step int32) {
  44705 	var a, a1, a2, a3, p0, p1, q0, q1 int32
  44706 	_, _, _, _, _, _, _, _ = a, a1, a2, a3, p0, p1, q0, q1
  44707 	p1 = int32(**(**uint8_t)(__ccgo_up(p + uintptr(-int32(2)*step))))
  44708 	p0 = int32(**(**uint8_t)(__ccgo_up(p + uintptr(-step))))
  44709 	q0 = int32(**(**uint8_t)(__ccgo_up(p)))
  44710 	q1 = int32(**(**uint8_t)(__ccgo_up(p + uintptr(step))))
  44711 	a = int32(3) * (q0 - p0)
  44712 	a1 = int32(**(**int8_t)(__ccgo_up(VP8ksclip2 + uintptr((a+int32(4))>>int32(3)))))
  44713 	a2 = int32(**(**int8_t)(__ccgo_up(VP8ksclip2 + uintptr((a+int32(3))>>int32(3)))))
  44714 	a3 = (a1 + int32(1)) >> int32(1)
  44715 	**(**uint8_t)(__ccgo_up(p + uintptr(-int32(2)*step))) = **(**uint8_t)(__ccgo_up(VP8kclip1 + uintptr(p1+a3)))
  44716 	**(**uint8_t)(__ccgo_up(p + uintptr(-step))) = **(**uint8_t)(__ccgo_up(VP8kclip1 + uintptr(p0+a2)))
  44717 	**(**uint8_t)(__ccgo_up(p)) = **(**uint8_t)(__ccgo_up(VP8kclip1 + uintptr(q0-a1)))
  44718 	**(**uint8_t)(__ccgo_up(p + uintptr(step))) = **(**uint8_t)(__ccgo_up(VP8kclip1 + uintptr(q1-a3)))
  44719 }
  44720 
  44721 // C documentation
  44722 //
  44723 //	// 6 pixels in, 6 pixels out
  44724 func DoFilter6_C(tls *libc.TLS, p uintptr, step int32) {
  44725 	var a, a1, a2, a3, p0, p1, p2, q0, q1, q2 int32
  44726 	_, _, _, _, _, _, _, _, _, _ = a, a1, a2, a3, p0, p1, p2, q0, q1, q2
  44727 	p2 = int32(**(**uint8_t)(__ccgo_up(p + uintptr(-int32(3)*step))))
  44728 	p1 = int32(**(**uint8_t)(__ccgo_up(p + uintptr(-int32(2)*step))))
  44729 	p0 = int32(**(**uint8_t)(__ccgo_up(p + uintptr(-step))))
  44730 	q0 = int32(**(**uint8_t)(__ccgo_up(p)))
  44731 	q1 = int32(**(**uint8_t)(__ccgo_up(p + uintptr(step))))
  44732 	q2 = int32(**(**uint8_t)(__ccgo_up(p + uintptr(int32(2)*step))))
  44733 	a = int32(**(**int8_t)(__ccgo_up(VP8ksclip1 + uintptr(int32(3)*(q0-p0)+int32(**(**int8_t)(__ccgo_up(VP8ksclip1 + uintptr(p1-q1))))))))
  44734 	// a is in [-128,127], a1 in [-27,27], a2 in [-18,18] and a3 in [-9,9]
  44735 	a1 = (int32(27)*a + int32(63)) >> int32(7) // eq. to ((3 * a + 7) * 9) >> 7
  44736 	a2 = (int32(18)*a + int32(63)) >> int32(7) // eq. to ((2 * a + 7) * 9) >> 7
  44737 	a3 = (int32(9)*a + int32(63)) >> int32(7)  // eq. to ((1 * a + 7) * 9) >> 7
  44738 	**(**uint8_t)(__ccgo_up(p + uintptr(-int32(3)*step))) = **(**uint8_t)(__ccgo_up(VP8kclip1 + uintptr(p2+a3)))
  44739 	**(**uint8_t)(__ccgo_up(p + uintptr(-int32(2)*step))) = **(**uint8_t)(__ccgo_up(VP8kclip1 + uintptr(p1+a2)))
  44740 	**(**uint8_t)(__ccgo_up(p + uintptr(-step))) = **(**uint8_t)(__ccgo_up(VP8kclip1 + uintptr(p0+a1)))
  44741 	**(**uint8_t)(__ccgo_up(p)) = **(**uint8_t)(__ccgo_up(VP8kclip1 + uintptr(q0-a1)))
  44742 	**(**uint8_t)(__ccgo_up(p + uintptr(step))) = **(**uint8_t)(__ccgo_up(VP8kclip1 + uintptr(q1-a2)))
  44743 	**(**uint8_t)(__ccgo_up(p + uintptr(int32(2)*step))) = **(**uint8_t)(__ccgo_up(VP8kclip1 + uintptr(q2-a3)))
  44744 }
  44745 
  44746 func Hev(tls *libc.TLS, p uintptr, step int32, thresh int32) (r int32) {
  44747 	var p0, p1, q0, q1 int32
  44748 	_, _, _, _ = p0, p1, q0, q1
  44749 	p1 = int32(**(**uint8_t)(__ccgo_up(p + uintptr(-int32(2)*step))))
  44750 	p0 = int32(**(**uint8_t)(__ccgo_up(p + uintptr(-step))))
  44751 	q0 = int32(**(**uint8_t)(__ccgo_up(p)))
  44752 	q1 = int32(**(**uint8_t)(__ccgo_up(p + uintptr(step))))
  44753 	return libc.BoolInt32(int32(**(**uint8_t)(__ccgo_up(VP8kabs0 + uintptr(p1-p0)))) > thresh || int32(**(**uint8_t)(__ccgo_up(VP8kabs0 + uintptr(q1-q0)))) > thresh)
  44754 }
  44755 
  44756 func NeedsFilter_C(tls *libc.TLS, p uintptr, step int32, t int32) (r int32) {
  44757 	var p0, p1, q0, q1 int32
  44758 	_, _, _, _ = p0, p1, q0, q1
  44759 	p1 = int32(**(**uint8_t)(__ccgo_up(p + uintptr(-int32(2)*step))))
  44760 	p0 = int32(**(**uint8_t)(__ccgo_up(p + uintptr(-step))))
  44761 	q0 = int32(**(**uint8_t)(__ccgo_up(p)))
  44762 	q1 = int32(**(**uint8_t)(__ccgo_up(p + uintptr(step))))
  44763 	return libc.BoolInt32(int32(4)*int32(**(**uint8_t)(__ccgo_up(VP8kabs0 + uintptr(p0-q0))))+int32(**(**uint8_t)(__ccgo_up(VP8kabs0 + uintptr(p1-q1)))) <= t)
  44764 }
  44765 
  44766 func NeedsFilter2_C(tls *libc.TLS, p uintptr, step int32, t int32, it int32) (r int32) {
  44767 	var p0, p1, p2, p3, q0, q1, q2, q3 int32
  44768 	_, _, _, _, _, _, _, _ = p0, p1, p2, p3, q0, q1, q2, q3
  44769 	p3 = int32(**(**uint8_t)(__ccgo_up(p + uintptr(-int32(4)*step))))
  44770 	p2 = int32(**(**uint8_t)(__ccgo_up(p + uintptr(-int32(3)*step))))
  44771 	p1 = int32(**(**uint8_t)(__ccgo_up(p + uintptr(-int32(2)*step))))
  44772 	p0 = int32(**(**uint8_t)(__ccgo_up(p + uintptr(-step))))
  44773 	q0 = int32(**(**uint8_t)(__ccgo_up(p)))
  44774 	q1 = int32(**(**uint8_t)(__ccgo_up(p + uintptr(step))))
  44775 	q2 = int32(**(**uint8_t)(__ccgo_up(p + uintptr(int32(2)*step))))
  44776 	q3 = int32(**(**uint8_t)(__ccgo_up(p + uintptr(int32(3)*step))))
  44777 	if int32(4)*int32(**(**uint8_t)(__ccgo_up(VP8kabs0 + uintptr(p0-q0))))+int32(**(**uint8_t)(__ccgo_up(VP8kabs0 + uintptr(p1-q1)))) > t {
  44778 		return 0
  44779 	}
  44780 	return libc.BoolInt32(int32(**(**uint8_t)(__ccgo_up(VP8kabs0 + uintptr(p3-p2)))) <= it && int32(**(**uint8_t)(__ccgo_up(VP8kabs0 + uintptr(p2-p1)))) <= it && int32(**(**uint8_t)(__ccgo_up(VP8kabs0 + uintptr(p1-p0)))) <= it && int32(**(**uint8_t)(__ccgo_up(VP8kabs0 + uintptr(q3-q2)))) <= it && int32(**(**uint8_t)(__ccgo_up(VP8kabs0 + uintptr(q2-q1)))) <= it && int32(**(**uint8_t)(__ccgo_up(VP8kabs0 + uintptr(q1-q0)))) <= it)
  44781 }
  44782 
  44783 //------------------------------------------------------------------------------
  44784 // Simple In-loop filtering (Paragraph 15.2)
  44785 
  44786 func SimpleVFilter16_C(tls *libc.TLS, p uintptr, stride int32, thresh int32) {
  44787 	var i, thresh2 int32
  44788 	_, _ = i, thresh2
  44789 	thresh2 = int32(2)*thresh + int32(1)
  44790 	i = 0
  44791 	for {
  44792 		if !(i < int32(16)) {
  44793 			break
  44794 		}
  44795 		if NeedsFilter_C(tls, p+uintptr(i), stride, thresh2) != 0 {
  44796 			DoFilter2_C(tls, p+uintptr(i), stride)
  44797 		}
  44798 		goto _1
  44799 	_1:
  44800 		;
  44801 		i = i + 1
  44802 	}
  44803 }
  44804 
  44805 func SimpleHFilter16_C(tls *libc.TLS, p uintptr, stride int32, thresh int32) {
  44806 	var i, thresh2 int32
  44807 	_, _ = i, thresh2
  44808 	thresh2 = int32(2)*thresh + int32(1)
  44809 	i = 0
  44810 	for {
  44811 		if !(i < int32(16)) {
  44812 			break
  44813 		}
  44814 		if NeedsFilter_C(tls, p+uintptr(i*stride), int32(1), thresh2) != 0 {
  44815 			DoFilter2_C(tls, p+uintptr(i*stride), int32(1))
  44816 		}
  44817 		goto _1
  44818 	_1:
  44819 		;
  44820 		i = i + 1
  44821 	}
  44822 }
  44823 
  44824 func SimpleVFilter16i_C(tls *libc.TLS, p uintptr, stride int32, thresh int32) {
  44825 	var k int32
  44826 	_ = k
  44827 	k = int32(3)
  44828 	for {
  44829 		if !(k > 0) {
  44830 			break
  44831 		}
  44832 		p = p + uintptr(int32(4)*stride)
  44833 		SimpleVFilter16_C(tls, p, stride, thresh)
  44834 		goto _1
  44835 	_1:
  44836 		;
  44837 		k = k - 1
  44838 	}
  44839 }
  44840 
  44841 func SimpleHFilter16i_C(tls *libc.TLS, p uintptr, stride int32, thresh int32) {
  44842 	var k int32
  44843 	_ = k
  44844 	k = int32(3)
  44845 	for {
  44846 		if !(k > 0) {
  44847 			break
  44848 		}
  44849 		p = p + uintptr(4)
  44850 		SimpleHFilter16_C(tls, p, stride, thresh)
  44851 		goto _1
  44852 	_1:
  44853 		;
  44854 		k = k - 1
  44855 	}
  44856 }
  44857 
  44858 //------------------------------------------------------------------------------
  44859 // Complex In-loop filtering (Paragraph 15.3)
  44860 
  44861 func FilterLoop26_C(tls *libc.TLS, p uintptr, hstride int32, vstride int32, size int32, thresh int32, ithresh int32, hev_thresh int32) {
  44862 	var thresh2, v1 int32
  44863 	_, _ = thresh2, v1
  44864 	thresh2 = int32(2)*thresh + int32(1)
  44865 	for {
  44866 		v1 = size
  44867 		size = size - 1
  44868 		if !(v1 > 0) {
  44869 			break
  44870 		}
  44871 		if NeedsFilter2_C(tls, p, hstride, thresh2, ithresh) != 0 {
  44872 			if Hev(tls, p, hstride, hev_thresh) != 0 {
  44873 				DoFilter2_C(tls, p, hstride)
  44874 			} else {
  44875 				DoFilter6_C(tls, p, hstride)
  44876 			}
  44877 		}
  44878 		p = p + uintptr(vstride)
  44879 	}
  44880 }
  44881 
  44882 func FilterLoop24_C(tls *libc.TLS, p uintptr, hstride int32, vstride int32, size int32, thresh int32, ithresh int32, hev_thresh int32) {
  44883 	var thresh2, v1 int32
  44884 	_, _ = thresh2, v1
  44885 	thresh2 = int32(2)*thresh + int32(1)
  44886 	for {
  44887 		v1 = size
  44888 		size = size - 1
  44889 		if !(v1 > 0) {
  44890 			break
  44891 		}
  44892 		if NeedsFilter2_C(tls, p, hstride, thresh2, ithresh) != 0 {
  44893 			if Hev(tls, p, hstride, hev_thresh) != 0 {
  44894 				DoFilter2_C(tls, p, hstride)
  44895 			} else {
  44896 				DoFilter4_C(tls, p, hstride)
  44897 			}
  44898 		}
  44899 		p = p + uintptr(vstride)
  44900 	}
  44901 }
  44902 
  44903 // C documentation
  44904 //
  44905 //	// on macroblock edges
  44906 func VFilter16_C(tls *libc.TLS, p uintptr, stride int32, thresh int32, ithresh int32, hev_thresh int32) {
  44907 	FilterLoop26_C(tls, p, stride, int32(1), int32(16), thresh, ithresh, hev_thresh)
  44908 }
  44909 
  44910 func HFilter16_C(tls *libc.TLS, p uintptr, stride int32, thresh int32, ithresh int32, hev_thresh int32) {
  44911 	FilterLoop26_C(tls, p, int32(1), stride, int32(16), thresh, ithresh, hev_thresh)
  44912 }
  44913 
  44914 // C documentation
  44915 //
  44916 //	// on three inner edges
  44917 func VFilter16i_C(tls *libc.TLS, p uintptr, stride int32, thresh int32, ithresh int32, hev_thresh int32) {
  44918 	var k int32
  44919 	_ = k
  44920 	k = int32(3)
  44921 	for {
  44922 		if !(k > 0) {
  44923 			break
  44924 		}
  44925 		p = p + uintptr(int32(4)*stride)
  44926 		FilterLoop24_C(tls, p, stride, int32(1), int32(16), thresh, ithresh, hev_thresh)
  44927 		goto _1
  44928 	_1:
  44929 		;
  44930 		k = k - 1
  44931 	}
  44932 }
  44933 
  44934 func HFilter16i_C(tls *libc.TLS, p uintptr, stride int32, thresh int32, ithresh int32, hev_thresh int32) {
  44935 	var k int32
  44936 	_ = k
  44937 	k = int32(3)
  44938 	for {
  44939 		if !(k > 0) {
  44940 			break
  44941 		}
  44942 		p = p + uintptr(4)
  44943 		FilterLoop24_C(tls, p, int32(1), stride, int32(16), thresh, ithresh, hev_thresh)
  44944 		goto _1
  44945 	_1:
  44946 		;
  44947 		k = k - 1
  44948 	}
  44949 }
  44950 
  44951 // C documentation
  44952 //
  44953 //	// 8-pixels wide variant, for chroma filtering
  44954 func VFilter8_C(tls *libc.TLS, u uintptr, v uintptr, stride int32, thresh int32, ithresh int32, hev_thresh int32) {
  44955 	FilterLoop26_C(tls, u, stride, int32(1), int32(8), thresh, ithresh, hev_thresh)
  44956 	FilterLoop26_C(tls, v, stride, int32(1), int32(8), thresh, ithresh, hev_thresh)
  44957 }
  44958 
  44959 func HFilter8_C(tls *libc.TLS, u uintptr, v uintptr, stride int32, thresh int32, ithresh int32, hev_thresh int32) {
  44960 	FilterLoop26_C(tls, u, int32(1), stride, int32(8), thresh, ithresh, hev_thresh)
  44961 	FilterLoop26_C(tls, v, int32(1), stride, int32(8), thresh, ithresh, hev_thresh)
  44962 }
  44963 
  44964 func VFilter8i_C(tls *libc.TLS, u uintptr, v uintptr, stride int32, thresh int32, ithresh int32, hev_thresh int32) {
  44965 	FilterLoop24_C(tls, u+uintptr(int32(4)*stride), stride, int32(1), int32(8), thresh, ithresh, hev_thresh)
  44966 	FilterLoop24_C(tls, v+uintptr(int32(4)*stride), stride, int32(1), int32(8), thresh, ithresh, hev_thresh)
  44967 }
  44968 
  44969 func HFilter8i_C(tls *libc.TLS, u uintptr, v uintptr, stride int32, thresh int32, ithresh int32, hev_thresh int32) {
  44970 	FilterLoop24_C(tls, u+uintptr(4), int32(1), stride, int32(8), thresh, ithresh, hev_thresh)
  44971 	FilterLoop24_C(tls, v+uintptr(4), int32(1), stride, int32(8), thresh, ithresh, hev_thresh)
  44972 }
  44973 
  44974 //------------------------------------------------------------------------------
  44975 
  44976 func DitherCombine8x8_C(tls *libc.TLS, dither uintptr, dst uintptr, dst_stride int32) {
  44977 	var delta0, delta1, i, j int32
  44978 	_, _, _, _ = delta0, delta1, i, j
  44979 	j = 0
  44980 	for {
  44981 		if !(j < int32(8)) {
  44982 			break
  44983 		}
  44984 		i = 0
  44985 		for {
  44986 			if !(i < int32(8)) {
  44987 				break
  44988 			}
  44989 			delta0 = int32(**(**uint8_t)(__ccgo_up(dither + uintptr(i)))) - libc.Int32FromInt32(1)<<libc.Int32FromInt32(VP8_DITHER_AMP_BITS)
  44990 			delta1 = (delta0 + libc.Int32FromInt32(1)<<(libc.Int32FromInt32(VP8_DITHER_DESCALE)-libc.Int32FromInt32(1))) >> int32(VP8_DITHER_DESCALE)
  44991 			**(**uint8_t)(__ccgo_up(dst + uintptr(i))) = clip_8b1(tls, int32(**(**uint8_t)(__ccgo_up(dst + uintptr(i))))+delta1)
  44992 			goto _2
  44993 		_2:
  44994 			;
  44995 			i = i + 1
  44996 		}
  44997 		dst = dst + uintptr(dst_stride)
  44998 		dither = dither + uintptr(8)
  44999 		goto _1
  45000 	_1:
  45001 		;
  45002 		j = j + 1
  45003 	}
  45004 }
  45005 
  45006 func VP8DspInit(tls *libc.TLS) {
  45007 	if libc.AtomicLoadPUintptr(uintptr(unsafe.Pointer(&VP8DspInit_body_last_cpuinfo_used))) == VP8GetCPUInfo {
  45008 		goto _1
  45009 	}
  45010 	VP8DspInit_body(tls)
  45011 	libc.AtomicStorePUintptr(uintptr(unsafe.Pointer(&VP8DspInit_body_last_cpuinfo_used)), VP8GetCPUInfo)
  45012 	goto _2
  45013 _2:
  45014 	;
  45015 	goto _1
  45016 _1: /**/ //
  45017 }
  45018 
  45019 var VP8DspInit_body_last_cpuinfo_used = uintptr(0)
  45020 
  45021 func init() {
  45022 	p := unsafe.Pointer(&VP8DspInit_body_last_cpuinfo_used)
  45023 	*(*uintptr)(unsafe.Add(p, 0)) = uintptr(unsafe.Pointer(&VP8DspInit_body_last_cpuinfo_used))
  45024 }
  45025 
  45026 func VP8DspInit_body(tls *libc.TLS) {
  45027 	VP8InitClipTables(tls)
  45028 	VP8TransformWHT = __ccgo_fp(TransformWHT_C)
  45029 	VP8Transform = __ccgo_fp(TransformTwo_C)
  45030 	VP8TransformDC = __ccgo_fp(TransformDC_C)
  45031 	VP8TransformAC3 = __ccgo_fp(TransformAC3_C)
  45032 	VP8TransformUV = __ccgo_fp(TransformUV_C)
  45033 	VP8TransformDCUV = __ccgo_fp(TransformDCUV_C)
  45034 	VP8VFilter16 = __ccgo_fp(VFilter16_C)
  45035 	VP8VFilter16i = __ccgo_fp(VFilter16i_C)
  45036 	VP8HFilter16 = __ccgo_fp(HFilter16_C)
  45037 	VP8VFilter8 = __ccgo_fp(VFilter8_C)
  45038 	VP8VFilter8i = __ccgo_fp(VFilter8i_C)
  45039 	VP8SimpleVFilter16 = __ccgo_fp(SimpleVFilter16_C)
  45040 	VP8SimpleHFilter16 = __ccgo_fp(SimpleHFilter16_C)
  45041 	VP8SimpleVFilter16i = __ccgo_fp(SimpleVFilter16i_C)
  45042 	VP8SimpleHFilter16i = __ccgo_fp(SimpleHFilter16i_C)
  45043 	VP8HFilter16i = __ccgo_fp(HFilter16i_C)
  45044 	VP8HFilter8 = __ccgo_fp(HFilter8_C)
  45045 	VP8HFilter8i = __ccgo_fp(HFilter8i_C)
  45046 	VP8PredLuma4[0] = __ccgo_fp(DC4_C)
  45047 	VP8PredLuma4[int32(1)] = __ccgo_fp(TM4_C)
  45048 	VP8PredLuma4[int32(2)] = __ccgo_fp(VE4_C)
  45049 	VP8PredLuma4[int32(4)] = __ccgo_fp(RD4_C)
  45050 	VP8PredLuma4[int32(6)] = __ccgo_fp(LD4_C)
  45051 	VP8PredLuma4[int32(3)] = __ccgo_fp(HE4_C)
  45052 	VP8PredLuma4[int32(5)] = __ccgo_fp(VR4_C)
  45053 	VP8PredLuma4[int32(7)] = __ccgo_fp(VL4_C)
  45054 	VP8PredLuma4[int32(8)] = __ccgo_fp(HD4_C)
  45055 	VP8PredLuma4[int32(9)] = __ccgo_fp(HU4_C)
  45056 	VP8PredLuma16[0] = __ccgo_fp(DC16_C)
  45057 	VP8PredLuma16[int32(1)] = __ccgo_fp(TM16_C)
  45058 	VP8PredLuma16[int32(2)] = __ccgo_fp(VE16_C)
  45059 	VP8PredLuma16[int32(3)] = __ccgo_fp(HE16_C)
  45060 	VP8PredLuma16[int32(4)] = __ccgo_fp(DC16NoTop_C)
  45061 	VP8PredLuma16[int32(5)] = __ccgo_fp(DC16NoLeft_C)
  45062 	VP8PredLuma16[int32(6)] = __ccgo_fp(DC16NoTopLeft_C)
  45063 	VP8PredChroma8[0] = __ccgo_fp(DC8uv_C)
  45064 	VP8PredChroma8[int32(1)] = __ccgo_fp(TM8uv_C)
  45065 	VP8PredChroma8[int32(2)] = __ccgo_fp(VE8uv_C)
  45066 	VP8PredChroma8[int32(3)] = __ccgo_fp(HE8uv_C)
  45067 	VP8PredChroma8[int32(4)] = __ccgo_fp(DC8uvNoTop_C)
  45068 	VP8PredChroma8[int32(5)] = __ccgo_fp(DC8uvNoLeft_C)
  45069 	VP8PredChroma8[int32(6)] = __ccgo_fp(DC8uvNoTopLeft_C)
  45070 	VP8DitherCombine8x8 = __ccgo_fp(DitherCombine8x8_C)
  45071 	// If defined, use CPUInfo() to overwrite some pointers with faster versions.
  45072 	if VP8GetCPUInfo != libc.UintptrFromInt32(0) {
  45073 	}
  45074 }
  45075 
  45076 const USE_STATIC_TABLES = 1
  45077 
  45078 // define to 0 to have run-time table initialization
  45079 
  45080 var abs0 = [511]uint8_t{
  45081 	0:   uint8(0xff),
  45082 	1:   uint8(0xfe),
  45083 	2:   uint8(0xfd),
  45084 	3:   uint8(0xfc),
  45085 	4:   uint8(0xfb),
  45086 	5:   uint8(0xfa),
  45087 	6:   uint8(0xf9),
  45088 	7:   uint8(0xf8),
  45089 	8:   uint8(0xf7),
  45090 	9:   uint8(0xf6),
  45091 	10:  uint8(0xf5),
  45092 	11:  uint8(0xf4),
  45093 	12:  uint8(0xf3),
  45094 	13:  uint8(0xf2),
  45095 	14:  uint8(0xf1),
  45096 	15:  uint8(0xf0),
  45097 	16:  uint8(0xef),
  45098 	17:  uint8(0xee),
  45099 	18:  uint8(0xed),
  45100 	19:  uint8(0xec),
  45101 	20:  uint8(0xeb),
  45102 	21:  uint8(0xea),
  45103 	22:  uint8(0xe9),
  45104 	23:  uint8(0xe8),
  45105 	24:  uint8(0xe7),
  45106 	25:  uint8(0xe6),
  45107 	26:  uint8(0xe5),
  45108 	27:  uint8(0xe4),
  45109 	28:  uint8(0xe3),
  45110 	29:  uint8(0xe2),
  45111 	30:  uint8(0xe1),
  45112 	31:  uint8(0xe0),
  45113 	32:  uint8(0xdf),
  45114 	33:  uint8(0xde),
  45115 	34:  uint8(0xdd),
  45116 	35:  uint8(0xdc),
  45117 	36:  uint8(0xdb),
  45118 	37:  uint8(0xda),
  45119 	38:  uint8(0xd9),
  45120 	39:  uint8(0xd8),
  45121 	40:  uint8(0xd7),
  45122 	41:  uint8(0xd6),
  45123 	42:  uint8(0xd5),
  45124 	43:  uint8(0xd4),
  45125 	44:  uint8(0xd3),
  45126 	45:  uint8(0xd2),
  45127 	46:  uint8(0xd1),
  45128 	47:  uint8(0xd0),
  45129 	48:  uint8(0xcf),
  45130 	49:  uint8(0xce),
  45131 	50:  uint8(0xcd),
  45132 	51:  uint8(0xcc),
  45133 	52:  uint8(0xcb),
  45134 	53:  uint8(0xca),
  45135 	54:  uint8(0xc9),
  45136 	55:  uint8(0xc8),
  45137 	56:  uint8(0xc7),
  45138 	57:  uint8(0xc6),
  45139 	58:  uint8(0xc5),
  45140 	59:  uint8(0xc4),
  45141 	60:  uint8(0xc3),
  45142 	61:  uint8(0xc2),
  45143 	62:  uint8(0xc1),
  45144 	63:  uint8(0xc0),
  45145 	64:  uint8(0xbf),
  45146 	65:  uint8(0xbe),
  45147 	66:  uint8(0xbd),
  45148 	67:  uint8(0xbc),
  45149 	68:  uint8(0xbb),
  45150 	69:  uint8(0xba),
  45151 	70:  uint8(0xb9),
  45152 	71:  uint8(0xb8),
  45153 	72:  uint8(0xb7),
  45154 	73:  uint8(0xb6),
  45155 	74:  uint8(0xb5),
  45156 	75:  uint8(0xb4),
  45157 	76:  uint8(0xb3),
  45158 	77:  uint8(0xb2),
  45159 	78:  uint8(0xb1),
  45160 	79:  uint8(0xb0),
  45161 	80:  uint8(0xaf),
  45162 	81:  uint8(0xae),
  45163 	82:  uint8(0xad),
  45164 	83:  uint8(0xac),
  45165 	84:  uint8(0xab),
  45166 	85:  uint8(0xaa),
  45167 	86:  uint8(0xa9),
  45168 	87:  uint8(0xa8),
  45169 	88:  uint8(0xa7),
  45170 	89:  uint8(0xa6),
  45171 	90:  uint8(0xa5),
  45172 	91:  uint8(0xa4),
  45173 	92:  uint8(0xa3),
  45174 	93:  uint8(0xa2),
  45175 	94:  uint8(0xa1),
  45176 	95:  uint8(0xa0),
  45177 	96:  uint8(0x9f),
  45178 	97:  uint8(0x9e),
  45179 	98:  uint8(0x9d),
  45180 	99:  uint8(0x9c),
  45181 	100: uint8(0x9b),
  45182 	101: uint8(0x9a),
  45183 	102: uint8(0x99),
  45184 	103: uint8(0x98),
  45185 	104: uint8(0x97),
  45186 	105: uint8(0x96),
  45187 	106: uint8(0x95),
  45188 	107: uint8(0x94),
  45189 	108: uint8(0x93),
  45190 	109: uint8(0x92),
  45191 	110: uint8(0x91),
  45192 	111: uint8(0x90),
  45193 	112: uint8(0x8f),
  45194 	113: uint8(0x8e),
  45195 	114: uint8(0x8d),
  45196 	115: uint8(0x8c),
  45197 	116: uint8(0x8b),
  45198 	117: uint8(0x8a),
  45199 	118: uint8(0x89),
  45200 	119: uint8(0x88),
  45201 	120: uint8(0x87),
  45202 	121: uint8(0x86),
  45203 	122: uint8(0x85),
  45204 	123: uint8(0x84),
  45205 	124: uint8(0x83),
  45206 	125: uint8(0x82),
  45207 	126: uint8(0x81),
  45208 	127: uint8(0x80),
  45209 	128: uint8(0x7f),
  45210 	129: uint8(0x7e),
  45211 	130: uint8(0x7d),
  45212 	131: uint8(0x7c),
  45213 	132: uint8(0x7b),
  45214 	133: uint8(0x7a),
  45215 	134: uint8(0x79),
  45216 	135: uint8(0x78),
  45217 	136: uint8(0x77),
  45218 	137: uint8(0x76),
  45219 	138: uint8(0x75),
  45220 	139: uint8(0x74),
  45221 	140: uint8(0x73),
  45222 	141: uint8(0x72),
  45223 	142: uint8(0x71),
  45224 	143: uint8(0x70),
  45225 	144: uint8(0x6f),
  45226 	145: uint8(0x6e),
  45227 	146: uint8(0x6d),
  45228 	147: uint8(0x6c),
  45229 	148: uint8(0x6b),
  45230 	149: uint8(0x6a),
  45231 	150: uint8(0x69),
  45232 	151: uint8(0x68),
  45233 	152: uint8(0x67),
  45234 	153: uint8(0x66),
  45235 	154: uint8(0x65),
  45236 	155: uint8(0x64),
  45237 	156: uint8(0x63),
  45238 	157: uint8(0x62),
  45239 	158: uint8(0x61),
  45240 	159: uint8(0x60),
  45241 	160: uint8(0x5f),
  45242 	161: uint8(0x5e),
  45243 	162: uint8(0x5d),
  45244 	163: uint8(0x5c),
  45245 	164: uint8(0x5b),
  45246 	165: uint8(0x5a),
  45247 	166: uint8(0x59),
  45248 	167: uint8(0x58),
  45249 	168: uint8(0x57),
  45250 	169: uint8(0x56),
  45251 	170: uint8(0x55),
  45252 	171: uint8(0x54),
  45253 	172: uint8(0x53),
  45254 	173: uint8(0x52),
  45255 	174: uint8(0x51),
  45256 	175: uint8(0x50),
  45257 	176: uint8(0x4f),
  45258 	177: uint8(0x4e),
  45259 	178: uint8(0x4d),
  45260 	179: uint8(0x4c),
  45261 	180: uint8(0x4b),
  45262 	181: uint8(0x4a),
  45263 	182: uint8(0x49),
  45264 	183: uint8(0x48),
  45265 	184: uint8(0x47),
  45266 	185: uint8(0x46),
  45267 	186: uint8(0x45),
  45268 	187: uint8(0x44),
  45269 	188: uint8(0x43),
  45270 	189: uint8(0x42),
  45271 	190: uint8(0x41),
  45272 	191: uint8(0x40),
  45273 	192: uint8(0x3f),
  45274 	193: uint8(0x3e),
  45275 	194: uint8(0x3d),
  45276 	195: uint8(0x3c),
  45277 	196: uint8(0x3b),
  45278 	197: uint8(0x3a),
  45279 	198: uint8(0x39),
  45280 	199: uint8(0x38),
  45281 	200: uint8(0x37),
  45282 	201: uint8(0x36),
  45283 	202: uint8(0x35),
  45284 	203: uint8(0x34),
  45285 	204: uint8(0x33),
  45286 	205: uint8(0x32),
  45287 	206: uint8(0x31),
  45288 	207: uint8(0x30),
  45289 	208: uint8(0x2f),
  45290 	209: uint8(0x2e),
  45291 	210: uint8(0x2d),
  45292 	211: uint8(0x2c),
  45293 	212: uint8(0x2b),
  45294 	213: uint8(0x2a),
  45295 	214: uint8(0x29),
  45296 	215: uint8(0x28),
  45297 	216: uint8(0x27),
  45298 	217: uint8(0x26),
  45299 	218: uint8(0x25),
  45300 	219: uint8(0x24),
  45301 	220: uint8(0x23),
  45302 	221: uint8(0x22),
  45303 	222: uint8(0x21),
  45304 	223: uint8(0x20),
  45305 	224: uint8(0x1f),
  45306 	225: uint8(0x1e),
  45307 	226: uint8(0x1d),
  45308 	227: uint8(0x1c),
  45309 	228: uint8(0x1b),
  45310 	229: uint8(0x1a),
  45311 	230: uint8(0x19),
  45312 	231: uint8(0x18),
  45313 	232: uint8(0x17),
  45314 	233: uint8(0x16),
  45315 	234: uint8(0x15),
  45316 	235: uint8(0x14),
  45317 	236: uint8(0x13),
  45318 	237: uint8(0x12),
  45319 	238: uint8(0x11),
  45320 	239: uint8(0x10),
  45321 	240: uint8(0x0f),
  45322 	241: uint8(0x0e),
  45323 	242: uint8(0x0d),
  45324 	243: uint8(0x0c),
  45325 	244: uint8(0x0b),
  45326 	245: uint8(0x0a),
  45327 	246: uint8(0x09),
  45328 	247: uint8(0x08),
  45329 	248: uint8(0x07),
  45330 	249: uint8(0x06),
  45331 	250: uint8(0x05),
  45332 	251: uint8(0x04),
  45333 	252: uint8(0x03),
  45334 	253: uint8(0x02),
  45335 	254: uint8(0x01),
  45336 	256: uint8(0x01),
  45337 	257: uint8(0x02),
  45338 	258: uint8(0x03),
  45339 	259: uint8(0x04),
  45340 	260: uint8(0x05),
  45341 	261: uint8(0x06),
  45342 	262: uint8(0x07),
  45343 	263: uint8(0x08),
  45344 	264: uint8(0x09),
  45345 	265: uint8(0x0a),
  45346 	266: uint8(0x0b),
  45347 	267: uint8(0x0c),
  45348 	268: uint8(0x0d),
  45349 	269: uint8(0x0e),
  45350 	270: uint8(0x0f),
  45351 	271: uint8(0x10),
  45352 	272: uint8(0x11),
  45353 	273: uint8(0x12),
  45354 	274: uint8(0x13),
  45355 	275: uint8(0x14),
  45356 	276: uint8(0x15),
  45357 	277: uint8(0x16),
  45358 	278: uint8(0x17),
  45359 	279: uint8(0x18),
  45360 	280: uint8(0x19),
  45361 	281: uint8(0x1a),
  45362 	282: uint8(0x1b),
  45363 	283: uint8(0x1c),
  45364 	284: uint8(0x1d),
  45365 	285: uint8(0x1e),
  45366 	286: uint8(0x1f),
  45367 	287: uint8(0x20),
  45368 	288: uint8(0x21),
  45369 	289: uint8(0x22),
  45370 	290: uint8(0x23),
  45371 	291: uint8(0x24),
  45372 	292: uint8(0x25),
  45373 	293: uint8(0x26),
  45374 	294: uint8(0x27),
  45375 	295: uint8(0x28),
  45376 	296: uint8(0x29),
  45377 	297: uint8(0x2a),
  45378 	298: uint8(0x2b),
  45379 	299: uint8(0x2c),
  45380 	300: uint8(0x2d),
  45381 	301: uint8(0x2e),
  45382 	302: uint8(0x2f),
  45383 	303: uint8(0x30),
  45384 	304: uint8(0x31),
  45385 	305: uint8(0x32),
  45386 	306: uint8(0x33),
  45387 	307: uint8(0x34),
  45388 	308: uint8(0x35),
  45389 	309: uint8(0x36),
  45390 	310: uint8(0x37),
  45391 	311: uint8(0x38),
  45392 	312: uint8(0x39),
  45393 	313: uint8(0x3a),
  45394 	314: uint8(0x3b),
  45395 	315: uint8(0x3c),
  45396 	316: uint8(0x3d),
  45397 	317: uint8(0x3e),
  45398 	318: uint8(0x3f),
  45399 	319: uint8(0x40),
  45400 	320: uint8(0x41),
  45401 	321: uint8(0x42),
  45402 	322: uint8(0x43),
  45403 	323: uint8(0x44),
  45404 	324: uint8(0x45),
  45405 	325: uint8(0x46),
  45406 	326: uint8(0x47),
  45407 	327: uint8(0x48),
  45408 	328: uint8(0x49),
  45409 	329: uint8(0x4a),
  45410 	330: uint8(0x4b),
  45411 	331: uint8(0x4c),
  45412 	332: uint8(0x4d),
  45413 	333: uint8(0x4e),
  45414 	334: uint8(0x4f),
  45415 	335: uint8(0x50),
  45416 	336: uint8(0x51),
  45417 	337: uint8(0x52),
  45418 	338: uint8(0x53),
  45419 	339: uint8(0x54),
  45420 	340: uint8(0x55),
  45421 	341: uint8(0x56),
  45422 	342: uint8(0x57),
  45423 	343: uint8(0x58),
  45424 	344: uint8(0x59),
  45425 	345: uint8(0x5a),
  45426 	346: uint8(0x5b),
  45427 	347: uint8(0x5c),
  45428 	348: uint8(0x5d),
  45429 	349: uint8(0x5e),
  45430 	350: uint8(0x5f),
  45431 	351: uint8(0x60),
  45432 	352: uint8(0x61),
  45433 	353: uint8(0x62),
  45434 	354: uint8(0x63),
  45435 	355: uint8(0x64),
  45436 	356: uint8(0x65),
  45437 	357: uint8(0x66),
  45438 	358: uint8(0x67),
  45439 	359: uint8(0x68),
  45440 	360: uint8(0x69),
  45441 	361: uint8(0x6a),
  45442 	362: uint8(0x6b),
  45443 	363: uint8(0x6c),
  45444 	364: uint8(0x6d),
  45445 	365: uint8(0x6e),
  45446 	366: uint8(0x6f),
  45447 	367: uint8(0x70),
  45448 	368: uint8(0x71),
  45449 	369: uint8(0x72),
  45450 	370: uint8(0x73),
  45451 	371: uint8(0x74),
  45452 	372: uint8(0x75),
  45453 	373: uint8(0x76),
  45454 	374: uint8(0x77),
  45455 	375: uint8(0x78),
  45456 	376: uint8(0x79),
  45457 	377: uint8(0x7a),
  45458 	378: uint8(0x7b),
  45459 	379: uint8(0x7c),
  45460 	380: uint8(0x7d),
  45461 	381: uint8(0x7e),
  45462 	382: uint8(0x7f),
  45463 	383: uint8(0x80),
  45464 	384: uint8(0x81),
  45465 	385: uint8(0x82),
  45466 	386: uint8(0x83),
  45467 	387: uint8(0x84),
  45468 	388: uint8(0x85),
  45469 	389: uint8(0x86),
  45470 	390: uint8(0x87),
  45471 	391: uint8(0x88),
  45472 	392: uint8(0x89),
  45473 	393: uint8(0x8a),
  45474 	394: uint8(0x8b),
  45475 	395: uint8(0x8c),
  45476 	396: uint8(0x8d),
  45477 	397: uint8(0x8e),
  45478 	398: uint8(0x8f),
  45479 	399: uint8(0x90),
  45480 	400: uint8(0x91),
  45481 	401: uint8(0x92),
  45482 	402: uint8(0x93),
  45483 	403: uint8(0x94),
  45484 	404: uint8(0x95),
  45485 	405: uint8(0x96),
  45486 	406: uint8(0x97),
  45487 	407: uint8(0x98),
  45488 	408: uint8(0x99),
  45489 	409: uint8(0x9a),
  45490 	410: uint8(0x9b),
  45491 	411: uint8(0x9c),
  45492 	412: uint8(0x9d),
  45493 	413: uint8(0x9e),
  45494 	414: uint8(0x9f),
  45495 	415: uint8(0xa0),
  45496 	416: uint8(0xa1),
  45497 	417: uint8(0xa2),
  45498 	418: uint8(0xa3),
  45499 	419: uint8(0xa4),
  45500 	420: uint8(0xa5),
  45501 	421: uint8(0xa6),
  45502 	422: uint8(0xa7),
  45503 	423: uint8(0xa8),
  45504 	424: uint8(0xa9),
  45505 	425: uint8(0xaa),
  45506 	426: uint8(0xab),
  45507 	427: uint8(0xac),
  45508 	428: uint8(0xad),
  45509 	429: uint8(0xae),
  45510 	430: uint8(0xaf),
  45511 	431: uint8(0xb0),
  45512 	432: uint8(0xb1),
  45513 	433: uint8(0xb2),
  45514 	434: uint8(0xb3),
  45515 	435: uint8(0xb4),
  45516 	436: uint8(0xb5),
  45517 	437: uint8(0xb6),
  45518 	438: uint8(0xb7),
  45519 	439: uint8(0xb8),
  45520 	440: uint8(0xb9),
  45521 	441: uint8(0xba),
  45522 	442: uint8(0xbb),
  45523 	443: uint8(0xbc),
  45524 	444: uint8(0xbd),
  45525 	445: uint8(0xbe),
  45526 	446: uint8(0xbf),
  45527 	447: uint8(0xc0),
  45528 	448: uint8(0xc1),
  45529 	449: uint8(0xc2),
  45530 	450: uint8(0xc3),
  45531 	451: uint8(0xc4),
  45532 	452: uint8(0xc5),
  45533 	453: uint8(0xc6),
  45534 	454: uint8(0xc7),
  45535 	455: uint8(0xc8),
  45536 	456: uint8(0xc9),
  45537 	457: uint8(0xca),
  45538 	458: uint8(0xcb),
  45539 	459: uint8(0xcc),
  45540 	460: uint8(0xcd),
  45541 	461: uint8(0xce),
  45542 	462: uint8(0xcf),
  45543 	463: uint8(0xd0),
  45544 	464: uint8(0xd1),
  45545 	465: uint8(0xd2),
  45546 	466: uint8(0xd3),
  45547 	467: uint8(0xd4),
  45548 	468: uint8(0xd5),
  45549 	469: uint8(0xd6),
  45550 	470: uint8(0xd7),
  45551 	471: uint8(0xd8),
  45552 	472: uint8(0xd9),
  45553 	473: uint8(0xda),
  45554 	474: uint8(0xdb),
  45555 	475: uint8(0xdc),
  45556 	476: uint8(0xdd),
  45557 	477: uint8(0xde),
  45558 	478: uint8(0xdf),
  45559 	479: uint8(0xe0),
  45560 	480: uint8(0xe1),
  45561 	481: uint8(0xe2),
  45562 	482: uint8(0xe3),
  45563 	483: uint8(0xe4),
  45564 	484: uint8(0xe5),
  45565 	485: uint8(0xe6),
  45566 	486: uint8(0xe7),
  45567 	487: uint8(0xe8),
  45568 	488: uint8(0xe9),
  45569 	489: uint8(0xea),
  45570 	490: uint8(0xeb),
  45571 	491: uint8(0xec),
  45572 	492: uint8(0xed),
  45573 	493: uint8(0xee),
  45574 	494: uint8(0xef),
  45575 	495: uint8(0xf0),
  45576 	496: uint8(0xf1),
  45577 	497: uint8(0xf2),
  45578 	498: uint8(0xf3),
  45579 	499: uint8(0xf4),
  45580 	500: uint8(0xf5),
  45581 	501: uint8(0xf6),
  45582 	502: uint8(0xf7),
  45583 	503: uint8(0xf8),
  45584 	504: uint8(0xf9),
  45585 	505: uint8(0xfa),
  45586 	506: uint8(0xfb),
  45587 	507: uint8(0xfc),
  45588 	508: uint8(0xfd),
  45589 	509: uint8(0xfe),
  45590 	510: uint8(0xff),
  45591 }
  45592 
  45593 var sclip1 = [2041]uint8_t{
  45594 	0:    uint8(0x80),
  45595 	1:    uint8(0x80),
  45596 	2:    uint8(0x80),
  45597 	3:    uint8(0x80),
  45598 	4:    uint8(0x80),
  45599 	5:    uint8(0x80),
  45600 	6:    uint8(0x80),
  45601 	7:    uint8(0x80),
  45602 	8:    uint8(0x80),
  45603 	9:    uint8(0x80),
  45604 	10:   uint8(0x80),
  45605 	11:   uint8(0x80),
  45606 	12:   uint8(0x80),
  45607 	13:   uint8(0x80),
  45608 	14:   uint8(0x80),
  45609 	15:   uint8(0x80),
  45610 	16:   uint8(0x80),
  45611 	17:   uint8(0x80),
  45612 	18:   uint8(0x80),
  45613 	19:   uint8(0x80),
  45614 	20:   uint8(0x80),
  45615 	21:   uint8(0x80),
  45616 	22:   uint8(0x80),
  45617 	23:   uint8(0x80),
  45618 	24:   uint8(0x80),
  45619 	25:   uint8(0x80),
  45620 	26:   uint8(0x80),
  45621 	27:   uint8(0x80),
  45622 	28:   uint8(0x80),
  45623 	29:   uint8(0x80),
  45624 	30:   uint8(0x80),
  45625 	31:   uint8(0x80),
  45626 	32:   uint8(0x80),
  45627 	33:   uint8(0x80),
  45628 	34:   uint8(0x80),
  45629 	35:   uint8(0x80),
  45630 	36:   uint8(0x80),
  45631 	37:   uint8(0x80),
  45632 	38:   uint8(0x80),
  45633 	39:   uint8(0x80),
  45634 	40:   uint8(0x80),
  45635 	41:   uint8(0x80),
  45636 	42:   uint8(0x80),
  45637 	43:   uint8(0x80),
  45638 	44:   uint8(0x80),
  45639 	45:   uint8(0x80),
  45640 	46:   uint8(0x80),
  45641 	47:   uint8(0x80),
  45642 	48:   uint8(0x80),
  45643 	49:   uint8(0x80),
  45644 	50:   uint8(0x80),
  45645 	51:   uint8(0x80),
  45646 	52:   uint8(0x80),
  45647 	53:   uint8(0x80),
  45648 	54:   uint8(0x80),
  45649 	55:   uint8(0x80),
  45650 	56:   uint8(0x80),
  45651 	57:   uint8(0x80),
  45652 	58:   uint8(0x80),
  45653 	59:   uint8(0x80),
  45654 	60:   uint8(0x80),
  45655 	61:   uint8(0x80),
  45656 	62:   uint8(0x80),
  45657 	63:   uint8(0x80),
  45658 	64:   uint8(0x80),
  45659 	65:   uint8(0x80),
  45660 	66:   uint8(0x80),
  45661 	67:   uint8(0x80),
  45662 	68:   uint8(0x80),
  45663 	69:   uint8(0x80),
  45664 	70:   uint8(0x80),
  45665 	71:   uint8(0x80),
  45666 	72:   uint8(0x80),
  45667 	73:   uint8(0x80),
  45668 	74:   uint8(0x80),
  45669 	75:   uint8(0x80),
  45670 	76:   uint8(0x80),
  45671 	77:   uint8(0x80),
  45672 	78:   uint8(0x80),
  45673 	79:   uint8(0x80),
  45674 	80:   uint8(0x80),
  45675 	81:   uint8(0x80),
  45676 	82:   uint8(0x80),
  45677 	83:   uint8(0x80),
  45678 	84:   uint8(0x80),
  45679 	85:   uint8(0x80),
  45680 	86:   uint8(0x80),
  45681 	87:   uint8(0x80),
  45682 	88:   uint8(0x80),
  45683 	89:   uint8(0x80),
  45684 	90:   uint8(0x80),
  45685 	91:   uint8(0x80),
  45686 	92:   uint8(0x80),
  45687 	93:   uint8(0x80),
  45688 	94:   uint8(0x80),
  45689 	95:   uint8(0x80),
  45690 	96:   uint8(0x80),
  45691 	97:   uint8(0x80),
  45692 	98:   uint8(0x80),
  45693 	99:   uint8(0x80),
  45694 	100:  uint8(0x80),
  45695 	101:  uint8(0x80),
  45696 	102:  uint8(0x80),
  45697 	103:  uint8(0x80),
  45698 	104:  uint8(0x80),
  45699 	105:  uint8(0x80),
  45700 	106:  uint8(0x80),
  45701 	107:  uint8(0x80),
  45702 	108:  uint8(0x80),
  45703 	109:  uint8(0x80),
  45704 	110:  uint8(0x80),
  45705 	111:  uint8(0x80),
  45706 	112:  uint8(0x80),
  45707 	113:  uint8(0x80),
  45708 	114:  uint8(0x80),
  45709 	115:  uint8(0x80),
  45710 	116:  uint8(0x80),
  45711 	117:  uint8(0x80),
  45712 	118:  uint8(0x80),
  45713 	119:  uint8(0x80),
  45714 	120:  uint8(0x80),
  45715 	121:  uint8(0x80),
  45716 	122:  uint8(0x80),
  45717 	123:  uint8(0x80),
  45718 	124:  uint8(0x80),
  45719 	125:  uint8(0x80),
  45720 	126:  uint8(0x80),
  45721 	127:  uint8(0x80),
  45722 	128:  uint8(0x80),
  45723 	129:  uint8(0x80),
  45724 	130:  uint8(0x80),
  45725 	131:  uint8(0x80),
  45726 	132:  uint8(0x80),
  45727 	133:  uint8(0x80),
  45728 	134:  uint8(0x80),
  45729 	135:  uint8(0x80),
  45730 	136:  uint8(0x80),
  45731 	137:  uint8(0x80),
  45732 	138:  uint8(0x80),
  45733 	139:  uint8(0x80),
  45734 	140:  uint8(0x80),
  45735 	141:  uint8(0x80),
  45736 	142:  uint8(0x80),
  45737 	143:  uint8(0x80),
  45738 	144:  uint8(0x80),
  45739 	145:  uint8(0x80),
  45740 	146:  uint8(0x80),
  45741 	147:  uint8(0x80),
  45742 	148:  uint8(0x80),
  45743 	149:  uint8(0x80),
  45744 	150:  uint8(0x80),
  45745 	151:  uint8(0x80),
  45746 	152:  uint8(0x80),
  45747 	153:  uint8(0x80),
  45748 	154:  uint8(0x80),
  45749 	155:  uint8(0x80),
  45750 	156:  uint8(0x80),
  45751 	157:  uint8(0x80),
  45752 	158:  uint8(0x80),
  45753 	159:  uint8(0x80),
  45754 	160:  uint8(0x80),
  45755 	161:  uint8(0x80),
  45756 	162:  uint8(0x80),
  45757 	163:  uint8(0x80),
  45758 	164:  uint8(0x80),
  45759 	165:  uint8(0x80),
  45760 	166:  uint8(0x80),
  45761 	167:  uint8(0x80),
  45762 	168:  uint8(0x80),
  45763 	169:  uint8(0x80),
  45764 	170:  uint8(0x80),
  45765 	171:  uint8(0x80),
  45766 	172:  uint8(0x80),
  45767 	173:  uint8(0x80),
  45768 	174:  uint8(0x80),
  45769 	175:  uint8(0x80),
  45770 	176:  uint8(0x80),
  45771 	177:  uint8(0x80),
  45772 	178:  uint8(0x80),
  45773 	179:  uint8(0x80),
  45774 	180:  uint8(0x80),
  45775 	181:  uint8(0x80),
  45776 	182:  uint8(0x80),
  45777 	183:  uint8(0x80),
  45778 	184:  uint8(0x80),
  45779 	185:  uint8(0x80),
  45780 	186:  uint8(0x80),
  45781 	187:  uint8(0x80),
  45782 	188:  uint8(0x80),
  45783 	189:  uint8(0x80),
  45784 	190:  uint8(0x80),
  45785 	191:  uint8(0x80),
  45786 	192:  uint8(0x80),
  45787 	193:  uint8(0x80),
  45788 	194:  uint8(0x80),
  45789 	195:  uint8(0x80),
  45790 	196:  uint8(0x80),
  45791 	197:  uint8(0x80),
  45792 	198:  uint8(0x80),
  45793 	199:  uint8(0x80),
  45794 	200:  uint8(0x80),
  45795 	201:  uint8(0x80),
  45796 	202:  uint8(0x80),
  45797 	203:  uint8(0x80),
  45798 	204:  uint8(0x80),
  45799 	205:  uint8(0x80),
  45800 	206:  uint8(0x80),
  45801 	207:  uint8(0x80),
  45802 	208:  uint8(0x80),
  45803 	209:  uint8(0x80),
  45804 	210:  uint8(0x80),
  45805 	211:  uint8(0x80),
  45806 	212:  uint8(0x80),
  45807 	213:  uint8(0x80),
  45808 	214:  uint8(0x80),
  45809 	215:  uint8(0x80),
  45810 	216:  uint8(0x80),
  45811 	217:  uint8(0x80),
  45812 	218:  uint8(0x80),
  45813 	219:  uint8(0x80),
  45814 	220:  uint8(0x80),
  45815 	221:  uint8(0x80),
  45816 	222:  uint8(0x80),
  45817 	223:  uint8(0x80),
  45818 	224:  uint8(0x80),
  45819 	225:  uint8(0x80),
  45820 	226:  uint8(0x80),
  45821 	227:  uint8(0x80),
  45822 	228:  uint8(0x80),
  45823 	229:  uint8(0x80),
  45824 	230:  uint8(0x80),
  45825 	231:  uint8(0x80),
  45826 	232:  uint8(0x80),
  45827 	233:  uint8(0x80),
  45828 	234:  uint8(0x80),
  45829 	235:  uint8(0x80),
  45830 	236:  uint8(0x80),
  45831 	237:  uint8(0x80),
  45832 	238:  uint8(0x80),
  45833 	239:  uint8(0x80),
  45834 	240:  uint8(0x80),
  45835 	241:  uint8(0x80),
  45836 	242:  uint8(0x80),
  45837 	243:  uint8(0x80),
  45838 	244:  uint8(0x80),
  45839 	245:  uint8(0x80),
  45840 	246:  uint8(0x80),
  45841 	247:  uint8(0x80),
  45842 	248:  uint8(0x80),
  45843 	249:  uint8(0x80),
  45844 	250:  uint8(0x80),
  45845 	251:  uint8(0x80),
  45846 	252:  uint8(0x80),
  45847 	253:  uint8(0x80),
  45848 	254:  uint8(0x80),
  45849 	255:  uint8(0x80),
  45850 	256:  uint8(0x80),
  45851 	257:  uint8(0x80),
  45852 	258:  uint8(0x80),
  45853 	259:  uint8(0x80),
  45854 	260:  uint8(0x80),
  45855 	261:  uint8(0x80),
  45856 	262:  uint8(0x80),
  45857 	263:  uint8(0x80),
  45858 	264:  uint8(0x80),
  45859 	265:  uint8(0x80),
  45860 	266:  uint8(0x80),
  45861 	267:  uint8(0x80),
  45862 	268:  uint8(0x80),
  45863 	269:  uint8(0x80),
  45864 	270:  uint8(0x80),
  45865 	271:  uint8(0x80),
  45866 	272:  uint8(0x80),
  45867 	273:  uint8(0x80),
  45868 	274:  uint8(0x80),
  45869 	275:  uint8(0x80),
  45870 	276:  uint8(0x80),
  45871 	277:  uint8(0x80),
  45872 	278:  uint8(0x80),
  45873 	279:  uint8(0x80),
  45874 	280:  uint8(0x80),
  45875 	281:  uint8(0x80),
  45876 	282:  uint8(0x80),
  45877 	283:  uint8(0x80),
  45878 	284:  uint8(0x80),
  45879 	285:  uint8(0x80),
  45880 	286:  uint8(0x80),
  45881 	287:  uint8(0x80),
  45882 	288:  uint8(0x80),
  45883 	289:  uint8(0x80),
  45884 	290:  uint8(0x80),
  45885 	291:  uint8(0x80),
  45886 	292:  uint8(0x80),
  45887 	293:  uint8(0x80),
  45888 	294:  uint8(0x80),
  45889 	295:  uint8(0x80),
  45890 	296:  uint8(0x80),
  45891 	297:  uint8(0x80),
  45892 	298:  uint8(0x80),
  45893 	299:  uint8(0x80),
  45894 	300:  uint8(0x80),
  45895 	301:  uint8(0x80),
  45896 	302:  uint8(0x80),
  45897 	303:  uint8(0x80),
  45898 	304:  uint8(0x80),
  45899 	305:  uint8(0x80),
  45900 	306:  uint8(0x80),
  45901 	307:  uint8(0x80),
  45902 	308:  uint8(0x80),
  45903 	309:  uint8(0x80),
  45904 	310:  uint8(0x80),
  45905 	311:  uint8(0x80),
  45906 	312:  uint8(0x80),
  45907 	313:  uint8(0x80),
  45908 	314:  uint8(0x80),
  45909 	315:  uint8(0x80),
  45910 	316:  uint8(0x80),
  45911 	317:  uint8(0x80),
  45912 	318:  uint8(0x80),
  45913 	319:  uint8(0x80),
  45914 	320:  uint8(0x80),
  45915 	321:  uint8(0x80),
  45916 	322:  uint8(0x80),
  45917 	323:  uint8(0x80),
  45918 	324:  uint8(0x80),
  45919 	325:  uint8(0x80),
  45920 	326:  uint8(0x80),
  45921 	327:  uint8(0x80),
  45922 	328:  uint8(0x80),
  45923 	329:  uint8(0x80),
  45924 	330:  uint8(0x80),
  45925 	331:  uint8(0x80),
  45926 	332:  uint8(0x80),
  45927 	333:  uint8(0x80),
  45928 	334:  uint8(0x80),
  45929 	335:  uint8(0x80),
  45930 	336:  uint8(0x80),
  45931 	337:  uint8(0x80),
  45932 	338:  uint8(0x80),
  45933 	339:  uint8(0x80),
  45934 	340:  uint8(0x80),
  45935 	341:  uint8(0x80),
  45936 	342:  uint8(0x80),
  45937 	343:  uint8(0x80),
  45938 	344:  uint8(0x80),
  45939 	345:  uint8(0x80),
  45940 	346:  uint8(0x80),
  45941 	347:  uint8(0x80),
  45942 	348:  uint8(0x80),
  45943 	349:  uint8(0x80),
  45944 	350:  uint8(0x80),
  45945 	351:  uint8(0x80),
  45946 	352:  uint8(0x80),
  45947 	353:  uint8(0x80),
  45948 	354:  uint8(0x80),
  45949 	355:  uint8(0x80),
  45950 	356:  uint8(0x80),
  45951 	357:  uint8(0x80),
  45952 	358:  uint8(0x80),
  45953 	359:  uint8(0x80),
  45954 	360:  uint8(0x80),
  45955 	361:  uint8(0x80),
  45956 	362:  uint8(0x80),
  45957 	363:  uint8(0x80),
  45958 	364:  uint8(0x80),
  45959 	365:  uint8(0x80),
  45960 	366:  uint8(0x80),
  45961 	367:  uint8(0x80),
  45962 	368:  uint8(0x80),
  45963 	369:  uint8(0x80),
  45964 	370:  uint8(0x80),
  45965 	371:  uint8(0x80),
  45966 	372:  uint8(0x80),
  45967 	373:  uint8(0x80),
  45968 	374:  uint8(0x80),
  45969 	375:  uint8(0x80),
  45970 	376:  uint8(0x80),
  45971 	377:  uint8(0x80),
  45972 	378:  uint8(0x80),
  45973 	379:  uint8(0x80),
  45974 	380:  uint8(0x80),
  45975 	381:  uint8(0x80),
  45976 	382:  uint8(0x80),
  45977 	383:  uint8(0x80),
  45978 	384:  uint8(0x80),
  45979 	385:  uint8(0x80),
  45980 	386:  uint8(0x80),
  45981 	387:  uint8(0x80),
  45982 	388:  uint8(0x80),
  45983 	389:  uint8(0x80),
  45984 	390:  uint8(0x80),
  45985 	391:  uint8(0x80),
  45986 	392:  uint8(0x80),
  45987 	393:  uint8(0x80),
  45988 	394:  uint8(0x80),
  45989 	395:  uint8(0x80),
  45990 	396:  uint8(0x80),
  45991 	397:  uint8(0x80),
  45992 	398:  uint8(0x80),
  45993 	399:  uint8(0x80),
  45994 	400:  uint8(0x80),
  45995 	401:  uint8(0x80),
  45996 	402:  uint8(0x80),
  45997 	403:  uint8(0x80),
  45998 	404:  uint8(0x80),
  45999 	405:  uint8(0x80),
  46000 	406:  uint8(0x80),
  46001 	407:  uint8(0x80),
  46002 	408:  uint8(0x80),
  46003 	409:  uint8(0x80),
  46004 	410:  uint8(0x80),
  46005 	411:  uint8(0x80),
  46006 	412:  uint8(0x80),
  46007 	413:  uint8(0x80),
  46008 	414:  uint8(0x80),
  46009 	415:  uint8(0x80),
  46010 	416:  uint8(0x80),
  46011 	417:  uint8(0x80),
  46012 	418:  uint8(0x80),
  46013 	419:  uint8(0x80),
  46014 	420:  uint8(0x80),
  46015 	421:  uint8(0x80),
  46016 	422:  uint8(0x80),
  46017 	423:  uint8(0x80),
  46018 	424:  uint8(0x80),
  46019 	425:  uint8(0x80),
  46020 	426:  uint8(0x80),
  46021 	427:  uint8(0x80),
  46022 	428:  uint8(0x80),
  46023 	429:  uint8(0x80),
  46024 	430:  uint8(0x80),
  46025 	431:  uint8(0x80),
  46026 	432:  uint8(0x80),
  46027 	433:  uint8(0x80),
  46028 	434:  uint8(0x80),
  46029 	435:  uint8(0x80),
  46030 	436:  uint8(0x80),
  46031 	437:  uint8(0x80),
  46032 	438:  uint8(0x80),
  46033 	439:  uint8(0x80),
  46034 	440:  uint8(0x80),
  46035 	441:  uint8(0x80),
  46036 	442:  uint8(0x80),
  46037 	443:  uint8(0x80),
  46038 	444:  uint8(0x80),
  46039 	445:  uint8(0x80),
  46040 	446:  uint8(0x80),
  46041 	447:  uint8(0x80),
  46042 	448:  uint8(0x80),
  46043 	449:  uint8(0x80),
  46044 	450:  uint8(0x80),
  46045 	451:  uint8(0x80),
  46046 	452:  uint8(0x80),
  46047 	453:  uint8(0x80),
  46048 	454:  uint8(0x80),
  46049 	455:  uint8(0x80),
  46050 	456:  uint8(0x80),
  46051 	457:  uint8(0x80),
  46052 	458:  uint8(0x80),
  46053 	459:  uint8(0x80),
  46054 	460:  uint8(0x80),
  46055 	461:  uint8(0x80),
  46056 	462:  uint8(0x80),
  46057 	463:  uint8(0x80),
  46058 	464:  uint8(0x80),
  46059 	465:  uint8(0x80),
  46060 	466:  uint8(0x80),
  46061 	467:  uint8(0x80),
  46062 	468:  uint8(0x80),
  46063 	469:  uint8(0x80),
  46064 	470:  uint8(0x80),
  46065 	471:  uint8(0x80),
  46066 	472:  uint8(0x80),
  46067 	473:  uint8(0x80),
  46068 	474:  uint8(0x80),
  46069 	475:  uint8(0x80),
  46070 	476:  uint8(0x80),
  46071 	477:  uint8(0x80),
  46072 	478:  uint8(0x80),
  46073 	479:  uint8(0x80),
  46074 	480:  uint8(0x80),
  46075 	481:  uint8(0x80),
  46076 	482:  uint8(0x80),
  46077 	483:  uint8(0x80),
  46078 	484:  uint8(0x80),
  46079 	485:  uint8(0x80),
  46080 	486:  uint8(0x80),
  46081 	487:  uint8(0x80),
  46082 	488:  uint8(0x80),
  46083 	489:  uint8(0x80),
  46084 	490:  uint8(0x80),
  46085 	491:  uint8(0x80),
  46086 	492:  uint8(0x80),
  46087 	493:  uint8(0x80),
  46088 	494:  uint8(0x80),
  46089 	495:  uint8(0x80),
  46090 	496:  uint8(0x80),
  46091 	497:  uint8(0x80),
  46092 	498:  uint8(0x80),
  46093 	499:  uint8(0x80),
  46094 	500:  uint8(0x80),
  46095 	501:  uint8(0x80),
  46096 	502:  uint8(0x80),
  46097 	503:  uint8(0x80),
  46098 	504:  uint8(0x80),
  46099 	505:  uint8(0x80),
  46100 	506:  uint8(0x80),
  46101 	507:  uint8(0x80),
  46102 	508:  uint8(0x80),
  46103 	509:  uint8(0x80),
  46104 	510:  uint8(0x80),
  46105 	511:  uint8(0x80),
  46106 	512:  uint8(0x80),
  46107 	513:  uint8(0x80),
  46108 	514:  uint8(0x80),
  46109 	515:  uint8(0x80),
  46110 	516:  uint8(0x80),
  46111 	517:  uint8(0x80),
  46112 	518:  uint8(0x80),
  46113 	519:  uint8(0x80),
  46114 	520:  uint8(0x80),
  46115 	521:  uint8(0x80),
  46116 	522:  uint8(0x80),
  46117 	523:  uint8(0x80),
  46118 	524:  uint8(0x80),
  46119 	525:  uint8(0x80),
  46120 	526:  uint8(0x80),
  46121 	527:  uint8(0x80),
  46122 	528:  uint8(0x80),
  46123 	529:  uint8(0x80),
  46124 	530:  uint8(0x80),
  46125 	531:  uint8(0x80),
  46126 	532:  uint8(0x80),
  46127 	533:  uint8(0x80),
  46128 	534:  uint8(0x80),
  46129 	535:  uint8(0x80),
  46130 	536:  uint8(0x80),
  46131 	537:  uint8(0x80),
  46132 	538:  uint8(0x80),
  46133 	539:  uint8(0x80),
  46134 	540:  uint8(0x80),
  46135 	541:  uint8(0x80),
  46136 	542:  uint8(0x80),
  46137 	543:  uint8(0x80),
  46138 	544:  uint8(0x80),
  46139 	545:  uint8(0x80),
  46140 	546:  uint8(0x80),
  46141 	547:  uint8(0x80),
  46142 	548:  uint8(0x80),
  46143 	549:  uint8(0x80),
  46144 	550:  uint8(0x80),
  46145 	551:  uint8(0x80),
  46146 	552:  uint8(0x80),
  46147 	553:  uint8(0x80),
  46148 	554:  uint8(0x80),
  46149 	555:  uint8(0x80),
  46150 	556:  uint8(0x80),
  46151 	557:  uint8(0x80),
  46152 	558:  uint8(0x80),
  46153 	559:  uint8(0x80),
  46154 	560:  uint8(0x80),
  46155 	561:  uint8(0x80),
  46156 	562:  uint8(0x80),
  46157 	563:  uint8(0x80),
  46158 	564:  uint8(0x80),
  46159 	565:  uint8(0x80),
  46160 	566:  uint8(0x80),
  46161 	567:  uint8(0x80),
  46162 	568:  uint8(0x80),
  46163 	569:  uint8(0x80),
  46164 	570:  uint8(0x80),
  46165 	571:  uint8(0x80),
  46166 	572:  uint8(0x80),
  46167 	573:  uint8(0x80),
  46168 	574:  uint8(0x80),
  46169 	575:  uint8(0x80),
  46170 	576:  uint8(0x80),
  46171 	577:  uint8(0x80),
  46172 	578:  uint8(0x80),
  46173 	579:  uint8(0x80),
  46174 	580:  uint8(0x80),
  46175 	581:  uint8(0x80),
  46176 	582:  uint8(0x80),
  46177 	583:  uint8(0x80),
  46178 	584:  uint8(0x80),
  46179 	585:  uint8(0x80),
  46180 	586:  uint8(0x80),
  46181 	587:  uint8(0x80),
  46182 	588:  uint8(0x80),
  46183 	589:  uint8(0x80),
  46184 	590:  uint8(0x80),
  46185 	591:  uint8(0x80),
  46186 	592:  uint8(0x80),
  46187 	593:  uint8(0x80),
  46188 	594:  uint8(0x80),
  46189 	595:  uint8(0x80),
  46190 	596:  uint8(0x80),
  46191 	597:  uint8(0x80),
  46192 	598:  uint8(0x80),
  46193 	599:  uint8(0x80),
  46194 	600:  uint8(0x80),
  46195 	601:  uint8(0x80),
  46196 	602:  uint8(0x80),
  46197 	603:  uint8(0x80),
  46198 	604:  uint8(0x80),
  46199 	605:  uint8(0x80),
  46200 	606:  uint8(0x80),
  46201 	607:  uint8(0x80),
  46202 	608:  uint8(0x80),
  46203 	609:  uint8(0x80),
  46204 	610:  uint8(0x80),
  46205 	611:  uint8(0x80),
  46206 	612:  uint8(0x80),
  46207 	613:  uint8(0x80),
  46208 	614:  uint8(0x80),
  46209 	615:  uint8(0x80),
  46210 	616:  uint8(0x80),
  46211 	617:  uint8(0x80),
  46212 	618:  uint8(0x80),
  46213 	619:  uint8(0x80),
  46214 	620:  uint8(0x80),
  46215 	621:  uint8(0x80),
  46216 	622:  uint8(0x80),
  46217 	623:  uint8(0x80),
  46218 	624:  uint8(0x80),
  46219 	625:  uint8(0x80),
  46220 	626:  uint8(0x80),
  46221 	627:  uint8(0x80),
  46222 	628:  uint8(0x80),
  46223 	629:  uint8(0x80),
  46224 	630:  uint8(0x80),
  46225 	631:  uint8(0x80),
  46226 	632:  uint8(0x80),
  46227 	633:  uint8(0x80),
  46228 	634:  uint8(0x80),
  46229 	635:  uint8(0x80),
  46230 	636:  uint8(0x80),
  46231 	637:  uint8(0x80),
  46232 	638:  uint8(0x80),
  46233 	639:  uint8(0x80),
  46234 	640:  uint8(0x80),
  46235 	641:  uint8(0x80),
  46236 	642:  uint8(0x80),
  46237 	643:  uint8(0x80),
  46238 	644:  uint8(0x80),
  46239 	645:  uint8(0x80),
  46240 	646:  uint8(0x80),
  46241 	647:  uint8(0x80),
  46242 	648:  uint8(0x80),
  46243 	649:  uint8(0x80),
  46244 	650:  uint8(0x80),
  46245 	651:  uint8(0x80),
  46246 	652:  uint8(0x80),
  46247 	653:  uint8(0x80),
  46248 	654:  uint8(0x80),
  46249 	655:  uint8(0x80),
  46250 	656:  uint8(0x80),
  46251 	657:  uint8(0x80),
  46252 	658:  uint8(0x80),
  46253 	659:  uint8(0x80),
  46254 	660:  uint8(0x80),
  46255 	661:  uint8(0x80),
  46256 	662:  uint8(0x80),
  46257 	663:  uint8(0x80),
  46258 	664:  uint8(0x80),
  46259 	665:  uint8(0x80),
  46260 	666:  uint8(0x80),
  46261 	667:  uint8(0x80),
  46262 	668:  uint8(0x80),
  46263 	669:  uint8(0x80),
  46264 	670:  uint8(0x80),
  46265 	671:  uint8(0x80),
  46266 	672:  uint8(0x80),
  46267 	673:  uint8(0x80),
  46268 	674:  uint8(0x80),
  46269 	675:  uint8(0x80),
  46270 	676:  uint8(0x80),
  46271 	677:  uint8(0x80),
  46272 	678:  uint8(0x80),
  46273 	679:  uint8(0x80),
  46274 	680:  uint8(0x80),
  46275 	681:  uint8(0x80),
  46276 	682:  uint8(0x80),
  46277 	683:  uint8(0x80),
  46278 	684:  uint8(0x80),
  46279 	685:  uint8(0x80),
  46280 	686:  uint8(0x80),
  46281 	687:  uint8(0x80),
  46282 	688:  uint8(0x80),
  46283 	689:  uint8(0x80),
  46284 	690:  uint8(0x80),
  46285 	691:  uint8(0x80),
  46286 	692:  uint8(0x80),
  46287 	693:  uint8(0x80),
  46288 	694:  uint8(0x80),
  46289 	695:  uint8(0x80),
  46290 	696:  uint8(0x80),
  46291 	697:  uint8(0x80),
  46292 	698:  uint8(0x80),
  46293 	699:  uint8(0x80),
  46294 	700:  uint8(0x80),
  46295 	701:  uint8(0x80),
  46296 	702:  uint8(0x80),
  46297 	703:  uint8(0x80),
  46298 	704:  uint8(0x80),
  46299 	705:  uint8(0x80),
  46300 	706:  uint8(0x80),
  46301 	707:  uint8(0x80),
  46302 	708:  uint8(0x80),
  46303 	709:  uint8(0x80),
  46304 	710:  uint8(0x80),
  46305 	711:  uint8(0x80),
  46306 	712:  uint8(0x80),
  46307 	713:  uint8(0x80),
  46308 	714:  uint8(0x80),
  46309 	715:  uint8(0x80),
  46310 	716:  uint8(0x80),
  46311 	717:  uint8(0x80),
  46312 	718:  uint8(0x80),
  46313 	719:  uint8(0x80),
  46314 	720:  uint8(0x80),
  46315 	721:  uint8(0x80),
  46316 	722:  uint8(0x80),
  46317 	723:  uint8(0x80),
  46318 	724:  uint8(0x80),
  46319 	725:  uint8(0x80),
  46320 	726:  uint8(0x80),
  46321 	727:  uint8(0x80),
  46322 	728:  uint8(0x80),
  46323 	729:  uint8(0x80),
  46324 	730:  uint8(0x80),
  46325 	731:  uint8(0x80),
  46326 	732:  uint8(0x80),
  46327 	733:  uint8(0x80),
  46328 	734:  uint8(0x80),
  46329 	735:  uint8(0x80),
  46330 	736:  uint8(0x80),
  46331 	737:  uint8(0x80),
  46332 	738:  uint8(0x80),
  46333 	739:  uint8(0x80),
  46334 	740:  uint8(0x80),
  46335 	741:  uint8(0x80),
  46336 	742:  uint8(0x80),
  46337 	743:  uint8(0x80),
  46338 	744:  uint8(0x80),
  46339 	745:  uint8(0x80),
  46340 	746:  uint8(0x80),
  46341 	747:  uint8(0x80),
  46342 	748:  uint8(0x80),
  46343 	749:  uint8(0x80),
  46344 	750:  uint8(0x80),
  46345 	751:  uint8(0x80),
  46346 	752:  uint8(0x80),
  46347 	753:  uint8(0x80),
  46348 	754:  uint8(0x80),
  46349 	755:  uint8(0x80),
  46350 	756:  uint8(0x80),
  46351 	757:  uint8(0x80),
  46352 	758:  uint8(0x80),
  46353 	759:  uint8(0x80),
  46354 	760:  uint8(0x80),
  46355 	761:  uint8(0x80),
  46356 	762:  uint8(0x80),
  46357 	763:  uint8(0x80),
  46358 	764:  uint8(0x80),
  46359 	765:  uint8(0x80),
  46360 	766:  uint8(0x80),
  46361 	767:  uint8(0x80),
  46362 	768:  uint8(0x80),
  46363 	769:  uint8(0x80),
  46364 	770:  uint8(0x80),
  46365 	771:  uint8(0x80),
  46366 	772:  uint8(0x80),
  46367 	773:  uint8(0x80),
  46368 	774:  uint8(0x80),
  46369 	775:  uint8(0x80),
  46370 	776:  uint8(0x80),
  46371 	777:  uint8(0x80),
  46372 	778:  uint8(0x80),
  46373 	779:  uint8(0x80),
  46374 	780:  uint8(0x80),
  46375 	781:  uint8(0x80),
  46376 	782:  uint8(0x80),
  46377 	783:  uint8(0x80),
  46378 	784:  uint8(0x80),
  46379 	785:  uint8(0x80),
  46380 	786:  uint8(0x80),
  46381 	787:  uint8(0x80),
  46382 	788:  uint8(0x80),
  46383 	789:  uint8(0x80),
  46384 	790:  uint8(0x80),
  46385 	791:  uint8(0x80),
  46386 	792:  uint8(0x80),
  46387 	793:  uint8(0x80),
  46388 	794:  uint8(0x80),
  46389 	795:  uint8(0x80),
  46390 	796:  uint8(0x80),
  46391 	797:  uint8(0x80),
  46392 	798:  uint8(0x80),
  46393 	799:  uint8(0x80),
  46394 	800:  uint8(0x80),
  46395 	801:  uint8(0x80),
  46396 	802:  uint8(0x80),
  46397 	803:  uint8(0x80),
  46398 	804:  uint8(0x80),
  46399 	805:  uint8(0x80),
  46400 	806:  uint8(0x80),
  46401 	807:  uint8(0x80),
  46402 	808:  uint8(0x80),
  46403 	809:  uint8(0x80),
  46404 	810:  uint8(0x80),
  46405 	811:  uint8(0x80),
  46406 	812:  uint8(0x80),
  46407 	813:  uint8(0x80),
  46408 	814:  uint8(0x80),
  46409 	815:  uint8(0x80),
  46410 	816:  uint8(0x80),
  46411 	817:  uint8(0x80),
  46412 	818:  uint8(0x80),
  46413 	819:  uint8(0x80),
  46414 	820:  uint8(0x80),
  46415 	821:  uint8(0x80),
  46416 	822:  uint8(0x80),
  46417 	823:  uint8(0x80),
  46418 	824:  uint8(0x80),
  46419 	825:  uint8(0x80),
  46420 	826:  uint8(0x80),
  46421 	827:  uint8(0x80),
  46422 	828:  uint8(0x80),
  46423 	829:  uint8(0x80),
  46424 	830:  uint8(0x80),
  46425 	831:  uint8(0x80),
  46426 	832:  uint8(0x80),
  46427 	833:  uint8(0x80),
  46428 	834:  uint8(0x80),
  46429 	835:  uint8(0x80),
  46430 	836:  uint8(0x80),
  46431 	837:  uint8(0x80),
  46432 	838:  uint8(0x80),
  46433 	839:  uint8(0x80),
  46434 	840:  uint8(0x80),
  46435 	841:  uint8(0x80),
  46436 	842:  uint8(0x80),
  46437 	843:  uint8(0x80),
  46438 	844:  uint8(0x80),
  46439 	845:  uint8(0x80),
  46440 	846:  uint8(0x80),
  46441 	847:  uint8(0x80),
  46442 	848:  uint8(0x80),
  46443 	849:  uint8(0x80),
  46444 	850:  uint8(0x80),
  46445 	851:  uint8(0x80),
  46446 	852:  uint8(0x80),
  46447 	853:  uint8(0x80),
  46448 	854:  uint8(0x80),
  46449 	855:  uint8(0x80),
  46450 	856:  uint8(0x80),
  46451 	857:  uint8(0x80),
  46452 	858:  uint8(0x80),
  46453 	859:  uint8(0x80),
  46454 	860:  uint8(0x80),
  46455 	861:  uint8(0x80),
  46456 	862:  uint8(0x80),
  46457 	863:  uint8(0x80),
  46458 	864:  uint8(0x80),
  46459 	865:  uint8(0x80),
  46460 	866:  uint8(0x80),
  46461 	867:  uint8(0x80),
  46462 	868:  uint8(0x80),
  46463 	869:  uint8(0x80),
  46464 	870:  uint8(0x80),
  46465 	871:  uint8(0x80),
  46466 	872:  uint8(0x80),
  46467 	873:  uint8(0x80),
  46468 	874:  uint8(0x80),
  46469 	875:  uint8(0x80),
  46470 	876:  uint8(0x80),
  46471 	877:  uint8(0x80),
  46472 	878:  uint8(0x80),
  46473 	879:  uint8(0x80),
  46474 	880:  uint8(0x80),
  46475 	881:  uint8(0x80),
  46476 	882:  uint8(0x80),
  46477 	883:  uint8(0x80),
  46478 	884:  uint8(0x80),
  46479 	885:  uint8(0x80),
  46480 	886:  uint8(0x80),
  46481 	887:  uint8(0x80),
  46482 	888:  uint8(0x80),
  46483 	889:  uint8(0x80),
  46484 	890:  uint8(0x80),
  46485 	891:  uint8(0x80),
  46486 	892:  uint8(0x80),
  46487 	893:  uint8(0x81),
  46488 	894:  uint8(0x82),
  46489 	895:  uint8(0x83),
  46490 	896:  uint8(0x84),
  46491 	897:  uint8(0x85),
  46492 	898:  uint8(0x86),
  46493 	899:  uint8(0x87),
  46494 	900:  uint8(0x88),
  46495 	901:  uint8(0x89),
  46496 	902:  uint8(0x8a),
  46497 	903:  uint8(0x8b),
  46498 	904:  uint8(0x8c),
  46499 	905:  uint8(0x8d),
  46500 	906:  uint8(0x8e),
  46501 	907:  uint8(0x8f),
  46502 	908:  uint8(0x90),
  46503 	909:  uint8(0x91),
  46504 	910:  uint8(0x92),
  46505 	911:  uint8(0x93),
  46506 	912:  uint8(0x94),
  46507 	913:  uint8(0x95),
  46508 	914:  uint8(0x96),
  46509 	915:  uint8(0x97),
  46510 	916:  uint8(0x98),
  46511 	917:  uint8(0x99),
  46512 	918:  uint8(0x9a),
  46513 	919:  uint8(0x9b),
  46514 	920:  uint8(0x9c),
  46515 	921:  uint8(0x9d),
  46516 	922:  uint8(0x9e),
  46517 	923:  uint8(0x9f),
  46518 	924:  uint8(0xa0),
  46519 	925:  uint8(0xa1),
  46520 	926:  uint8(0xa2),
  46521 	927:  uint8(0xa3),
  46522 	928:  uint8(0xa4),
  46523 	929:  uint8(0xa5),
  46524 	930:  uint8(0xa6),
  46525 	931:  uint8(0xa7),
  46526 	932:  uint8(0xa8),
  46527 	933:  uint8(0xa9),
  46528 	934:  uint8(0xaa),
  46529 	935:  uint8(0xab),
  46530 	936:  uint8(0xac),
  46531 	937:  uint8(0xad),
  46532 	938:  uint8(0xae),
  46533 	939:  uint8(0xaf),
  46534 	940:  uint8(0xb0),
  46535 	941:  uint8(0xb1),
  46536 	942:  uint8(0xb2),
  46537 	943:  uint8(0xb3),
  46538 	944:  uint8(0xb4),
  46539 	945:  uint8(0xb5),
  46540 	946:  uint8(0xb6),
  46541 	947:  uint8(0xb7),
  46542 	948:  uint8(0xb8),
  46543 	949:  uint8(0xb9),
  46544 	950:  uint8(0xba),
  46545 	951:  uint8(0xbb),
  46546 	952:  uint8(0xbc),
  46547 	953:  uint8(0xbd),
  46548 	954:  uint8(0xbe),
  46549 	955:  uint8(0xbf),
  46550 	956:  uint8(0xc0),
  46551 	957:  uint8(0xc1),
  46552 	958:  uint8(0xc2),
  46553 	959:  uint8(0xc3),
  46554 	960:  uint8(0xc4),
  46555 	961:  uint8(0xc5),
  46556 	962:  uint8(0xc6),
  46557 	963:  uint8(0xc7),
  46558 	964:  uint8(0xc8),
  46559 	965:  uint8(0xc9),
  46560 	966:  uint8(0xca),
  46561 	967:  uint8(0xcb),
  46562 	968:  uint8(0xcc),
  46563 	969:  uint8(0xcd),
  46564 	970:  uint8(0xce),
  46565 	971:  uint8(0xcf),
  46566 	972:  uint8(0xd0),
  46567 	973:  uint8(0xd1),
  46568 	974:  uint8(0xd2),
  46569 	975:  uint8(0xd3),
  46570 	976:  uint8(0xd4),
  46571 	977:  uint8(0xd5),
  46572 	978:  uint8(0xd6),
  46573 	979:  uint8(0xd7),
  46574 	980:  uint8(0xd8),
  46575 	981:  uint8(0xd9),
  46576 	982:  uint8(0xda),
  46577 	983:  uint8(0xdb),
  46578 	984:  uint8(0xdc),
  46579 	985:  uint8(0xdd),
  46580 	986:  uint8(0xde),
  46581 	987:  uint8(0xdf),
  46582 	988:  uint8(0xe0),
  46583 	989:  uint8(0xe1),
  46584 	990:  uint8(0xe2),
  46585 	991:  uint8(0xe3),
  46586 	992:  uint8(0xe4),
  46587 	993:  uint8(0xe5),
  46588 	994:  uint8(0xe6),
  46589 	995:  uint8(0xe7),
  46590 	996:  uint8(0xe8),
  46591 	997:  uint8(0xe9),
  46592 	998:  uint8(0xea),
  46593 	999:  uint8(0xeb),
  46594 	1000: uint8(0xec),
  46595 	1001: uint8(0xed),
  46596 	1002: uint8(0xee),
  46597 	1003: uint8(0xef),
  46598 	1004: uint8(0xf0),
  46599 	1005: uint8(0xf1),
  46600 	1006: uint8(0xf2),
  46601 	1007: uint8(0xf3),
  46602 	1008: uint8(0xf4),
  46603 	1009: uint8(0xf5),
  46604 	1010: uint8(0xf6),
  46605 	1011: uint8(0xf7),
  46606 	1012: uint8(0xf8),
  46607 	1013: uint8(0xf9),
  46608 	1014: uint8(0xfa),
  46609 	1015: uint8(0xfb),
  46610 	1016: uint8(0xfc),
  46611 	1017: uint8(0xfd),
  46612 	1018: uint8(0xfe),
  46613 	1019: uint8(0xff),
  46614 	1021: uint8(0x01),
  46615 	1022: uint8(0x02),
  46616 	1023: uint8(0x03),
  46617 	1024: uint8(0x04),
  46618 	1025: uint8(0x05),
  46619 	1026: uint8(0x06),
  46620 	1027: uint8(0x07),
  46621 	1028: uint8(0x08),
  46622 	1029: uint8(0x09),
  46623 	1030: uint8(0x0a),
  46624 	1031: uint8(0x0b),
  46625 	1032: uint8(0x0c),
  46626 	1033: uint8(0x0d),
  46627 	1034: uint8(0x0e),
  46628 	1035: uint8(0x0f),
  46629 	1036: uint8(0x10),
  46630 	1037: uint8(0x11),
  46631 	1038: uint8(0x12),
  46632 	1039: uint8(0x13),
  46633 	1040: uint8(0x14),
  46634 	1041: uint8(0x15),
  46635 	1042: uint8(0x16),
  46636 	1043: uint8(0x17),
  46637 	1044: uint8(0x18),
  46638 	1045: uint8(0x19),
  46639 	1046: uint8(0x1a),
  46640 	1047: uint8(0x1b),
  46641 	1048: uint8(0x1c),
  46642 	1049: uint8(0x1d),
  46643 	1050: uint8(0x1e),
  46644 	1051: uint8(0x1f),
  46645 	1052: uint8(0x20),
  46646 	1053: uint8(0x21),
  46647 	1054: uint8(0x22),
  46648 	1055: uint8(0x23),
  46649 	1056: uint8(0x24),
  46650 	1057: uint8(0x25),
  46651 	1058: uint8(0x26),
  46652 	1059: uint8(0x27),
  46653 	1060: uint8(0x28),
  46654 	1061: uint8(0x29),
  46655 	1062: uint8(0x2a),
  46656 	1063: uint8(0x2b),
  46657 	1064: uint8(0x2c),
  46658 	1065: uint8(0x2d),
  46659 	1066: uint8(0x2e),
  46660 	1067: uint8(0x2f),
  46661 	1068: uint8(0x30),
  46662 	1069: uint8(0x31),
  46663 	1070: uint8(0x32),
  46664 	1071: uint8(0x33),
  46665 	1072: uint8(0x34),
  46666 	1073: uint8(0x35),
  46667 	1074: uint8(0x36),
  46668 	1075: uint8(0x37),
  46669 	1076: uint8(0x38),
  46670 	1077: uint8(0x39),
  46671 	1078: uint8(0x3a),
  46672 	1079: uint8(0x3b),
  46673 	1080: uint8(0x3c),
  46674 	1081: uint8(0x3d),
  46675 	1082: uint8(0x3e),
  46676 	1083: uint8(0x3f),
  46677 	1084: uint8(0x40),
  46678 	1085: uint8(0x41),
  46679 	1086: uint8(0x42),
  46680 	1087: uint8(0x43),
  46681 	1088: uint8(0x44),
  46682 	1089: uint8(0x45),
  46683 	1090: uint8(0x46),
  46684 	1091: uint8(0x47),
  46685 	1092: uint8(0x48),
  46686 	1093: uint8(0x49),
  46687 	1094: uint8(0x4a),
  46688 	1095: uint8(0x4b),
  46689 	1096: uint8(0x4c),
  46690 	1097: uint8(0x4d),
  46691 	1098: uint8(0x4e),
  46692 	1099: uint8(0x4f),
  46693 	1100: uint8(0x50),
  46694 	1101: uint8(0x51),
  46695 	1102: uint8(0x52),
  46696 	1103: uint8(0x53),
  46697 	1104: uint8(0x54),
  46698 	1105: uint8(0x55),
  46699 	1106: uint8(0x56),
  46700 	1107: uint8(0x57),
  46701 	1108: uint8(0x58),
  46702 	1109: uint8(0x59),
  46703 	1110: uint8(0x5a),
  46704 	1111: uint8(0x5b),
  46705 	1112: uint8(0x5c),
  46706 	1113: uint8(0x5d),
  46707 	1114: uint8(0x5e),
  46708 	1115: uint8(0x5f),
  46709 	1116: uint8(0x60),
  46710 	1117: uint8(0x61),
  46711 	1118: uint8(0x62),
  46712 	1119: uint8(0x63),
  46713 	1120: uint8(0x64),
  46714 	1121: uint8(0x65),
  46715 	1122: uint8(0x66),
  46716 	1123: uint8(0x67),
  46717 	1124: uint8(0x68),
  46718 	1125: uint8(0x69),
  46719 	1126: uint8(0x6a),
  46720 	1127: uint8(0x6b),
  46721 	1128: uint8(0x6c),
  46722 	1129: uint8(0x6d),
  46723 	1130: uint8(0x6e),
  46724 	1131: uint8(0x6f),
  46725 	1132: uint8(0x70),
  46726 	1133: uint8(0x71),
  46727 	1134: uint8(0x72),
  46728 	1135: uint8(0x73),
  46729 	1136: uint8(0x74),
  46730 	1137: uint8(0x75),
  46731 	1138: uint8(0x76),
  46732 	1139: uint8(0x77),
  46733 	1140: uint8(0x78),
  46734 	1141: uint8(0x79),
  46735 	1142: uint8(0x7a),
  46736 	1143: uint8(0x7b),
  46737 	1144: uint8(0x7c),
  46738 	1145: uint8(0x7d),
  46739 	1146: uint8(0x7e),
  46740 	1147: uint8(0x7f),
  46741 	1148: uint8(0x7f),
  46742 	1149: uint8(0x7f),
  46743 	1150: uint8(0x7f),
  46744 	1151: uint8(0x7f),
  46745 	1152: uint8(0x7f),
  46746 	1153: uint8(0x7f),
  46747 	1154: uint8(0x7f),
  46748 	1155: uint8(0x7f),
  46749 	1156: uint8(0x7f),
  46750 	1157: uint8(0x7f),
  46751 	1158: uint8(0x7f),
  46752 	1159: uint8(0x7f),
  46753 	1160: uint8(0x7f),
  46754 	1161: uint8(0x7f),
  46755 	1162: uint8(0x7f),
  46756 	1163: uint8(0x7f),
  46757 	1164: uint8(0x7f),
  46758 	1165: uint8(0x7f),
  46759 	1166: uint8(0x7f),
  46760 	1167: uint8(0x7f),
  46761 	1168: uint8(0x7f),
  46762 	1169: uint8(0x7f),
  46763 	1170: uint8(0x7f),
  46764 	1171: uint8(0x7f),
  46765 	1172: uint8(0x7f),
  46766 	1173: uint8(0x7f),
  46767 	1174: uint8(0x7f),
  46768 	1175: uint8(0x7f),
  46769 	1176: uint8(0x7f),
  46770 	1177: uint8(0x7f),
  46771 	1178: uint8(0x7f),
  46772 	1179: uint8(0x7f),
  46773 	1180: uint8(0x7f),
  46774 	1181: uint8(0x7f),
  46775 	1182: uint8(0x7f),
  46776 	1183: uint8(0x7f),
  46777 	1184: uint8(0x7f),
  46778 	1185: uint8(0x7f),
  46779 	1186: uint8(0x7f),
  46780 	1187: uint8(0x7f),
  46781 	1188: uint8(0x7f),
  46782 	1189: uint8(0x7f),
  46783 	1190: uint8(0x7f),
  46784 	1191: uint8(0x7f),
  46785 	1192: uint8(0x7f),
  46786 	1193: uint8(0x7f),
  46787 	1194: uint8(0x7f),
  46788 	1195: uint8(0x7f),
  46789 	1196: uint8(0x7f),
  46790 	1197: uint8(0x7f),
  46791 	1198: uint8(0x7f),
  46792 	1199: uint8(0x7f),
  46793 	1200: uint8(0x7f),
  46794 	1201: uint8(0x7f),
  46795 	1202: uint8(0x7f),
  46796 	1203: uint8(0x7f),
  46797 	1204: uint8(0x7f),
  46798 	1205: uint8(0x7f),
  46799 	1206: uint8(0x7f),
  46800 	1207: uint8(0x7f),
  46801 	1208: uint8(0x7f),
  46802 	1209: uint8(0x7f),
  46803 	1210: uint8(0x7f),
  46804 	1211: uint8(0x7f),
  46805 	1212: uint8(0x7f),
  46806 	1213: uint8(0x7f),
  46807 	1214: uint8(0x7f),
  46808 	1215: uint8(0x7f),
  46809 	1216: uint8(0x7f),
  46810 	1217: uint8(0x7f),
  46811 	1218: uint8(0x7f),
  46812 	1219: uint8(0x7f),
  46813 	1220: uint8(0x7f),
  46814 	1221: uint8(0x7f),
  46815 	1222: uint8(0x7f),
  46816 	1223: uint8(0x7f),
  46817 	1224: uint8(0x7f),
  46818 	1225: uint8(0x7f),
  46819 	1226: uint8(0x7f),
  46820 	1227: uint8(0x7f),
  46821 	1228: uint8(0x7f),
  46822 	1229: uint8(0x7f),
  46823 	1230: uint8(0x7f),
  46824 	1231: uint8(0x7f),
  46825 	1232: uint8(0x7f),
  46826 	1233: uint8(0x7f),
  46827 	1234: uint8(0x7f),
  46828 	1235: uint8(0x7f),
  46829 	1236: uint8(0x7f),
  46830 	1237: uint8(0x7f),
  46831 	1238: uint8(0x7f),
  46832 	1239: uint8(0x7f),
  46833 	1240: uint8(0x7f),
  46834 	1241: uint8(0x7f),
  46835 	1242: uint8(0x7f),
  46836 	1243: uint8(0x7f),
  46837 	1244: uint8(0x7f),
  46838 	1245: uint8(0x7f),
  46839 	1246: uint8(0x7f),
  46840 	1247: uint8(0x7f),
  46841 	1248: uint8(0x7f),
  46842 	1249: uint8(0x7f),
  46843 	1250: uint8(0x7f),
  46844 	1251: uint8(0x7f),
  46845 	1252: uint8(0x7f),
  46846 	1253: uint8(0x7f),
  46847 	1254: uint8(0x7f),
  46848 	1255: uint8(0x7f),
  46849 	1256: uint8(0x7f),
  46850 	1257: uint8(0x7f),
  46851 	1258: uint8(0x7f),
  46852 	1259: uint8(0x7f),
  46853 	1260: uint8(0x7f),
  46854 	1261: uint8(0x7f),
  46855 	1262: uint8(0x7f),
  46856 	1263: uint8(0x7f),
  46857 	1264: uint8(0x7f),
  46858 	1265: uint8(0x7f),
  46859 	1266: uint8(0x7f),
  46860 	1267: uint8(0x7f),
  46861 	1268: uint8(0x7f),
  46862 	1269: uint8(0x7f),
  46863 	1270: uint8(0x7f),
  46864 	1271: uint8(0x7f),
  46865 	1272: uint8(0x7f),
  46866 	1273: uint8(0x7f),
  46867 	1274: uint8(0x7f),
  46868 	1275: uint8(0x7f),
  46869 	1276: uint8(0x7f),
  46870 	1277: uint8(0x7f),
  46871 	1278: uint8(0x7f),
  46872 	1279: uint8(0x7f),
  46873 	1280: uint8(0x7f),
  46874 	1281: uint8(0x7f),
  46875 	1282: uint8(0x7f),
  46876 	1283: uint8(0x7f),
  46877 	1284: uint8(0x7f),
  46878 	1285: uint8(0x7f),
  46879 	1286: uint8(0x7f),
  46880 	1287: uint8(0x7f),
  46881 	1288: uint8(0x7f),
  46882 	1289: uint8(0x7f),
  46883 	1290: uint8(0x7f),
  46884 	1291: uint8(0x7f),
  46885 	1292: uint8(0x7f),
  46886 	1293: uint8(0x7f),
  46887 	1294: uint8(0x7f),
  46888 	1295: uint8(0x7f),
  46889 	1296: uint8(0x7f),
  46890 	1297: uint8(0x7f),
  46891 	1298: uint8(0x7f),
  46892 	1299: uint8(0x7f),
  46893 	1300: uint8(0x7f),
  46894 	1301: uint8(0x7f),
  46895 	1302: uint8(0x7f),
  46896 	1303: uint8(0x7f),
  46897 	1304: uint8(0x7f),
  46898 	1305: uint8(0x7f),
  46899 	1306: uint8(0x7f),
  46900 	1307: uint8(0x7f),
  46901 	1308: uint8(0x7f),
  46902 	1309: uint8(0x7f),
  46903 	1310: uint8(0x7f),
  46904 	1311: uint8(0x7f),
  46905 	1312: uint8(0x7f),
  46906 	1313: uint8(0x7f),
  46907 	1314: uint8(0x7f),
  46908 	1315: uint8(0x7f),
  46909 	1316: uint8(0x7f),
  46910 	1317: uint8(0x7f),
  46911 	1318: uint8(0x7f),
  46912 	1319: uint8(0x7f),
  46913 	1320: uint8(0x7f),
  46914 	1321: uint8(0x7f),
  46915 	1322: uint8(0x7f),
  46916 	1323: uint8(0x7f),
  46917 	1324: uint8(0x7f),
  46918 	1325: uint8(0x7f),
  46919 	1326: uint8(0x7f),
  46920 	1327: uint8(0x7f),
  46921 	1328: uint8(0x7f),
  46922 	1329: uint8(0x7f),
  46923 	1330: uint8(0x7f),
  46924 	1331: uint8(0x7f),
  46925 	1332: uint8(0x7f),
  46926 	1333: uint8(0x7f),
  46927 	1334: uint8(0x7f),
  46928 	1335: uint8(0x7f),
  46929 	1336: uint8(0x7f),
  46930 	1337: uint8(0x7f),
  46931 	1338: uint8(0x7f),
  46932 	1339: uint8(0x7f),
  46933 	1340: uint8(0x7f),
  46934 	1341: uint8(0x7f),
  46935 	1342: uint8(0x7f),
  46936 	1343: uint8(0x7f),
  46937 	1344: uint8(0x7f),
  46938 	1345: uint8(0x7f),
  46939 	1346: uint8(0x7f),
  46940 	1347: uint8(0x7f),
  46941 	1348: uint8(0x7f),
  46942 	1349: uint8(0x7f),
  46943 	1350: uint8(0x7f),
  46944 	1351: uint8(0x7f),
  46945 	1352: uint8(0x7f),
  46946 	1353: uint8(0x7f),
  46947 	1354: uint8(0x7f),
  46948 	1355: uint8(0x7f),
  46949 	1356: uint8(0x7f),
  46950 	1357: uint8(0x7f),
  46951 	1358: uint8(0x7f),
  46952 	1359: uint8(0x7f),
  46953 	1360: uint8(0x7f),
  46954 	1361: uint8(0x7f),
  46955 	1362: uint8(0x7f),
  46956 	1363: uint8(0x7f),
  46957 	1364: uint8(0x7f),
  46958 	1365: uint8(0x7f),
  46959 	1366: uint8(0x7f),
  46960 	1367: uint8(0x7f),
  46961 	1368: uint8(0x7f),
  46962 	1369: uint8(0x7f),
  46963 	1370: uint8(0x7f),
  46964 	1371: uint8(0x7f),
  46965 	1372: uint8(0x7f),
  46966 	1373: uint8(0x7f),
  46967 	1374: uint8(0x7f),
  46968 	1375: uint8(0x7f),
  46969 	1376: uint8(0x7f),
  46970 	1377: uint8(0x7f),
  46971 	1378: uint8(0x7f),
  46972 	1379: uint8(0x7f),
  46973 	1380: uint8(0x7f),
  46974 	1381: uint8(0x7f),
  46975 	1382: uint8(0x7f),
  46976 	1383: uint8(0x7f),
  46977 	1384: uint8(0x7f),
  46978 	1385: uint8(0x7f),
  46979 	1386: uint8(0x7f),
  46980 	1387: uint8(0x7f),
  46981 	1388: uint8(0x7f),
  46982 	1389: uint8(0x7f),
  46983 	1390: uint8(0x7f),
  46984 	1391: uint8(0x7f),
  46985 	1392: uint8(0x7f),
  46986 	1393: uint8(0x7f),
  46987 	1394: uint8(0x7f),
  46988 	1395: uint8(0x7f),
  46989 	1396: uint8(0x7f),
  46990 	1397: uint8(0x7f),
  46991 	1398: uint8(0x7f),
  46992 	1399: uint8(0x7f),
  46993 	1400: uint8(0x7f),
  46994 	1401: uint8(0x7f),
  46995 	1402: uint8(0x7f),
  46996 	1403: uint8(0x7f),
  46997 	1404: uint8(0x7f),
  46998 	1405: uint8(0x7f),
  46999 	1406: uint8(0x7f),
  47000 	1407: uint8(0x7f),
  47001 	1408: uint8(0x7f),
  47002 	1409: uint8(0x7f),
  47003 	1410: uint8(0x7f),
  47004 	1411: uint8(0x7f),
  47005 	1412: uint8(0x7f),
  47006 	1413: uint8(0x7f),
  47007 	1414: uint8(0x7f),
  47008 	1415: uint8(0x7f),
  47009 	1416: uint8(0x7f),
  47010 	1417: uint8(0x7f),
  47011 	1418: uint8(0x7f),
  47012 	1419: uint8(0x7f),
  47013 	1420: uint8(0x7f),
  47014 	1421: uint8(0x7f),
  47015 	1422: uint8(0x7f),
  47016 	1423: uint8(0x7f),
  47017 	1424: uint8(0x7f),
  47018 	1425: uint8(0x7f),
  47019 	1426: uint8(0x7f),
  47020 	1427: uint8(0x7f),
  47021 	1428: uint8(0x7f),
  47022 	1429: uint8(0x7f),
  47023 	1430: uint8(0x7f),
  47024 	1431: uint8(0x7f),
  47025 	1432: uint8(0x7f),
  47026 	1433: uint8(0x7f),
  47027 	1434: uint8(0x7f),
  47028 	1435: uint8(0x7f),
  47029 	1436: uint8(0x7f),
  47030 	1437: uint8(0x7f),
  47031 	1438: uint8(0x7f),
  47032 	1439: uint8(0x7f),
  47033 	1440: uint8(0x7f),
  47034 	1441: uint8(0x7f),
  47035 	1442: uint8(0x7f),
  47036 	1443: uint8(0x7f),
  47037 	1444: uint8(0x7f),
  47038 	1445: uint8(0x7f),
  47039 	1446: uint8(0x7f),
  47040 	1447: uint8(0x7f),
  47041 	1448: uint8(0x7f),
  47042 	1449: uint8(0x7f),
  47043 	1450: uint8(0x7f),
  47044 	1451: uint8(0x7f),
  47045 	1452: uint8(0x7f),
  47046 	1453: uint8(0x7f),
  47047 	1454: uint8(0x7f),
  47048 	1455: uint8(0x7f),
  47049 	1456: uint8(0x7f),
  47050 	1457: uint8(0x7f),
  47051 	1458: uint8(0x7f),
  47052 	1459: uint8(0x7f),
  47053 	1460: uint8(0x7f),
  47054 	1461: uint8(0x7f),
  47055 	1462: uint8(0x7f),
  47056 	1463: uint8(0x7f),
  47057 	1464: uint8(0x7f),
  47058 	1465: uint8(0x7f),
  47059 	1466: uint8(0x7f),
  47060 	1467: uint8(0x7f),
  47061 	1468: uint8(0x7f),
  47062 	1469: uint8(0x7f),
  47063 	1470: uint8(0x7f),
  47064 	1471: uint8(0x7f),
  47065 	1472: uint8(0x7f),
  47066 	1473: uint8(0x7f),
  47067 	1474: uint8(0x7f),
  47068 	1475: uint8(0x7f),
  47069 	1476: uint8(0x7f),
  47070 	1477: uint8(0x7f),
  47071 	1478: uint8(0x7f),
  47072 	1479: uint8(0x7f),
  47073 	1480: uint8(0x7f),
  47074 	1481: uint8(0x7f),
  47075 	1482: uint8(0x7f),
  47076 	1483: uint8(0x7f),
  47077 	1484: uint8(0x7f),
  47078 	1485: uint8(0x7f),
  47079 	1486: uint8(0x7f),
  47080 	1487: uint8(0x7f),
  47081 	1488: uint8(0x7f),
  47082 	1489: uint8(0x7f),
  47083 	1490: uint8(0x7f),
  47084 	1491: uint8(0x7f),
  47085 	1492: uint8(0x7f),
  47086 	1493: uint8(0x7f),
  47087 	1494: uint8(0x7f),
  47088 	1495: uint8(0x7f),
  47089 	1496: uint8(0x7f),
  47090 	1497: uint8(0x7f),
  47091 	1498: uint8(0x7f),
  47092 	1499: uint8(0x7f),
  47093 	1500: uint8(0x7f),
  47094 	1501: uint8(0x7f),
  47095 	1502: uint8(0x7f),
  47096 	1503: uint8(0x7f),
  47097 	1504: uint8(0x7f),
  47098 	1505: uint8(0x7f),
  47099 	1506: uint8(0x7f),
  47100 	1507: uint8(0x7f),
  47101 	1508: uint8(0x7f),
  47102 	1509: uint8(0x7f),
  47103 	1510: uint8(0x7f),
  47104 	1511: uint8(0x7f),
  47105 	1512: uint8(0x7f),
  47106 	1513: uint8(0x7f),
  47107 	1514: uint8(0x7f),
  47108 	1515: uint8(0x7f),
  47109 	1516: uint8(0x7f),
  47110 	1517: uint8(0x7f),
  47111 	1518: uint8(0x7f),
  47112 	1519: uint8(0x7f),
  47113 	1520: uint8(0x7f),
  47114 	1521: uint8(0x7f),
  47115 	1522: uint8(0x7f),
  47116 	1523: uint8(0x7f),
  47117 	1524: uint8(0x7f),
  47118 	1525: uint8(0x7f),
  47119 	1526: uint8(0x7f),
  47120 	1527: uint8(0x7f),
  47121 	1528: uint8(0x7f),
  47122 	1529: uint8(0x7f),
  47123 	1530: uint8(0x7f),
  47124 	1531: uint8(0x7f),
  47125 	1532: uint8(0x7f),
  47126 	1533: uint8(0x7f),
  47127 	1534: uint8(0x7f),
  47128 	1535: uint8(0x7f),
  47129 	1536: uint8(0x7f),
  47130 	1537: uint8(0x7f),
  47131 	1538: uint8(0x7f),
  47132 	1539: uint8(0x7f),
  47133 	1540: uint8(0x7f),
  47134 	1541: uint8(0x7f),
  47135 	1542: uint8(0x7f),
  47136 	1543: uint8(0x7f),
  47137 	1544: uint8(0x7f),
  47138 	1545: uint8(0x7f),
  47139 	1546: uint8(0x7f),
  47140 	1547: uint8(0x7f),
  47141 	1548: uint8(0x7f),
  47142 	1549: uint8(0x7f),
  47143 	1550: uint8(0x7f),
  47144 	1551: uint8(0x7f),
  47145 	1552: uint8(0x7f),
  47146 	1553: uint8(0x7f),
  47147 	1554: uint8(0x7f),
  47148 	1555: uint8(0x7f),
  47149 	1556: uint8(0x7f),
  47150 	1557: uint8(0x7f),
  47151 	1558: uint8(0x7f),
  47152 	1559: uint8(0x7f),
  47153 	1560: uint8(0x7f),
  47154 	1561: uint8(0x7f),
  47155 	1562: uint8(0x7f),
  47156 	1563: uint8(0x7f),
  47157 	1564: uint8(0x7f),
  47158 	1565: uint8(0x7f),
  47159 	1566: uint8(0x7f),
  47160 	1567: uint8(0x7f),
  47161 	1568: uint8(0x7f),
  47162 	1569: uint8(0x7f),
  47163 	1570: uint8(0x7f),
  47164 	1571: uint8(0x7f),
  47165 	1572: uint8(0x7f),
  47166 	1573: uint8(0x7f),
  47167 	1574: uint8(0x7f),
  47168 	1575: uint8(0x7f),
  47169 	1576: uint8(0x7f),
  47170 	1577: uint8(0x7f),
  47171 	1578: uint8(0x7f),
  47172 	1579: uint8(0x7f),
  47173 	1580: uint8(0x7f),
  47174 	1581: uint8(0x7f),
  47175 	1582: uint8(0x7f),
  47176 	1583: uint8(0x7f),
  47177 	1584: uint8(0x7f),
  47178 	1585: uint8(0x7f),
  47179 	1586: uint8(0x7f),
  47180 	1587: uint8(0x7f),
  47181 	1588: uint8(0x7f),
  47182 	1589: uint8(0x7f),
  47183 	1590: uint8(0x7f),
  47184 	1591: uint8(0x7f),
  47185 	1592: uint8(0x7f),
  47186 	1593: uint8(0x7f),
  47187 	1594: uint8(0x7f),
  47188 	1595: uint8(0x7f),
  47189 	1596: uint8(0x7f),
  47190 	1597: uint8(0x7f),
  47191 	1598: uint8(0x7f),
  47192 	1599: uint8(0x7f),
  47193 	1600: uint8(0x7f),
  47194 	1601: uint8(0x7f),
  47195 	1602: uint8(0x7f),
  47196 	1603: uint8(0x7f),
  47197 	1604: uint8(0x7f),
  47198 	1605: uint8(0x7f),
  47199 	1606: uint8(0x7f),
  47200 	1607: uint8(0x7f),
  47201 	1608: uint8(0x7f),
  47202 	1609: uint8(0x7f),
  47203 	1610: uint8(0x7f),
  47204 	1611: uint8(0x7f),
  47205 	1612: uint8(0x7f),
  47206 	1613: uint8(0x7f),
  47207 	1614: uint8(0x7f),
  47208 	1615: uint8(0x7f),
  47209 	1616: uint8(0x7f),
  47210 	1617: uint8(0x7f),
  47211 	1618: uint8(0x7f),
  47212 	1619: uint8(0x7f),
  47213 	1620: uint8(0x7f),
  47214 	1621: uint8(0x7f),
  47215 	1622: uint8(0x7f),
  47216 	1623: uint8(0x7f),
  47217 	1624: uint8(0x7f),
  47218 	1625: uint8(0x7f),
  47219 	1626: uint8(0x7f),
  47220 	1627: uint8(0x7f),
  47221 	1628: uint8(0x7f),
  47222 	1629: uint8(0x7f),
  47223 	1630: uint8(0x7f),
  47224 	1631: uint8(0x7f),
  47225 	1632: uint8(0x7f),
  47226 	1633: uint8(0x7f),
  47227 	1634: uint8(0x7f),
  47228 	1635: uint8(0x7f),
  47229 	1636: uint8(0x7f),
  47230 	1637: uint8(0x7f),
  47231 	1638: uint8(0x7f),
  47232 	1639: uint8(0x7f),
  47233 	1640: uint8(0x7f),
  47234 	1641: uint8(0x7f),
  47235 	1642: uint8(0x7f),
  47236 	1643: uint8(0x7f),
  47237 	1644: uint8(0x7f),
  47238 	1645: uint8(0x7f),
  47239 	1646: uint8(0x7f),
  47240 	1647: uint8(0x7f),
  47241 	1648: uint8(0x7f),
  47242 	1649: uint8(0x7f),
  47243 	1650: uint8(0x7f),
  47244 	1651: uint8(0x7f),
  47245 	1652: uint8(0x7f),
  47246 	1653: uint8(0x7f),
  47247 	1654: uint8(0x7f),
  47248 	1655: uint8(0x7f),
  47249 	1656: uint8(0x7f),
  47250 	1657: uint8(0x7f),
  47251 	1658: uint8(0x7f),
  47252 	1659: uint8(0x7f),
  47253 	1660: uint8(0x7f),
  47254 	1661: uint8(0x7f),
  47255 	1662: uint8(0x7f),
  47256 	1663: uint8(0x7f),
  47257 	1664: uint8(0x7f),
  47258 	1665: uint8(0x7f),
  47259 	1666: uint8(0x7f),
  47260 	1667: uint8(0x7f),
  47261 	1668: uint8(0x7f),
  47262 	1669: uint8(0x7f),
  47263 	1670: uint8(0x7f),
  47264 	1671: uint8(0x7f),
  47265 	1672: uint8(0x7f),
  47266 	1673: uint8(0x7f),
  47267 	1674: uint8(0x7f),
  47268 	1675: uint8(0x7f),
  47269 	1676: uint8(0x7f),
  47270 	1677: uint8(0x7f),
  47271 	1678: uint8(0x7f),
  47272 	1679: uint8(0x7f),
  47273 	1680: uint8(0x7f),
  47274 	1681: uint8(0x7f),
  47275 	1682: uint8(0x7f),
  47276 	1683: uint8(0x7f),
  47277 	1684: uint8(0x7f),
  47278 	1685: uint8(0x7f),
  47279 	1686: uint8(0x7f),
  47280 	1687: uint8(0x7f),
  47281 	1688: uint8(0x7f),
  47282 	1689: uint8(0x7f),
  47283 	1690: uint8(0x7f),
  47284 	1691: uint8(0x7f),
  47285 	1692: uint8(0x7f),
  47286 	1693: uint8(0x7f),
  47287 	1694: uint8(0x7f),
  47288 	1695: uint8(0x7f),
  47289 	1696: uint8(0x7f),
  47290 	1697: uint8(0x7f),
  47291 	1698: uint8(0x7f),
  47292 	1699: uint8(0x7f),
  47293 	1700: uint8(0x7f),
  47294 	1701: uint8(0x7f),
  47295 	1702: uint8(0x7f),
  47296 	1703: uint8(0x7f),
  47297 	1704: uint8(0x7f),
  47298 	1705: uint8(0x7f),
  47299 	1706: uint8(0x7f),
  47300 	1707: uint8(0x7f),
  47301 	1708: uint8(0x7f),
  47302 	1709: uint8(0x7f),
  47303 	1710: uint8(0x7f),
  47304 	1711: uint8(0x7f),
  47305 	1712: uint8(0x7f),
  47306 	1713: uint8(0x7f),
  47307 	1714: uint8(0x7f),
  47308 	1715: uint8(0x7f),
  47309 	1716: uint8(0x7f),
  47310 	1717: uint8(0x7f),
  47311 	1718: uint8(0x7f),
  47312 	1719: uint8(0x7f),
  47313 	1720: uint8(0x7f),
  47314 	1721: uint8(0x7f),
  47315 	1722: uint8(0x7f),
  47316 	1723: uint8(0x7f),
  47317 	1724: uint8(0x7f),
  47318 	1725: uint8(0x7f),
  47319 	1726: uint8(0x7f),
  47320 	1727: uint8(0x7f),
  47321 	1728: uint8(0x7f),
  47322 	1729: uint8(0x7f),
  47323 	1730: uint8(0x7f),
  47324 	1731: uint8(0x7f),
  47325 	1732: uint8(0x7f),
  47326 	1733: uint8(0x7f),
  47327 	1734: uint8(0x7f),
  47328 	1735: uint8(0x7f),
  47329 	1736: uint8(0x7f),
  47330 	1737: uint8(0x7f),
  47331 	1738: uint8(0x7f),
  47332 	1739: uint8(0x7f),
  47333 	1740: uint8(0x7f),
  47334 	1741: uint8(0x7f),
  47335 	1742: uint8(0x7f),
  47336 	1743: uint8(0x7f),
  47337 	1744: uint8(0x7f),
  47338 	1745: uint8(0x7f),
  47339 	1746: uint8(0x7f),
  47340 	1747: uint8(0x7f),
  47341 	1748: uint8(0x7f),
  47342 	1749: uint8(0x7f),
  47343 	1750: uint8(0x7f),
  47344 	1751: uint8(0x7f),
  47345 	1752: uint8(0x7f),
  47346 	1753: uint8(0x7f),
  47347 	1754: uint8(0x7f),
  47348 	1755: uint8(0x7f),
  47349 	1756: uint8(0x7f),
  47350 	1757: uint8(0x7f),
  47351 	1758: uint8(0x7f),
  47352 	1759: uint8(0x7f),
  47353 	1760: uint8(0x7f),
  47354 	1761: uint8(0x7f),
  47355 	1762: uint8(0x7f),
  47356 	1763: uint8(0x7f),
  47357 	1764: uint8(0x7f),
  47358 	1765: uint8(0x7f),
  47359 	1766: uint8(0x7f),
  47360 	1767: uint8(0x7f),
  47361 	1768: uint8(0x7f),
  47362 	1769: uint8(0x7f),
  47363 	1770: uint8(0x7f),
  47364 	1771: uint8(0x7f),
  47365 	1772: uint8(0x7f),
  47366 	1773: uint8(0x7f),
  47367 	1774: uint8(0x7f),
  47368 	1775: uint8(0x7f),
  47369 	1776: uint8(0x7f),
  47370 	1777: uint8(0x7f),
  47371 	1778: uint8(0x7f),
  47372 	1779: uint8(0x7f),
  47373 	1780: uint8(0x7f),
  47374 	1781: uint8(0x7f),
  47375 	1782: uint8(0x7f),
  47376 	1783: uint8(0x7f),
  47377 	1784: uint8(0x7f),
  47378 	1785: uint8(0x7f),
  47379 	1786: uint8(0x7f),
  47380 	1787: uint8(0x7f),
  47381 	1788: uint8(0x7f),
  47382 	1789: uint8(0x7f),
  47383 	1790: uint8(0x7f),
  47384 	1791: uint8(0x7f),
  47385 	1792: uint8(0x7f),
  47386 	1793: uint8(0x7f),
  47387 	1794: uint8(0x7f),
  47388 	1795: uint8(0x7f),
  47389 	1796: uint8(0x7f),
  47390 	1797: uint8(0x7f),
  47391 	1798: uint8(0x7f),
  47392 	1799: uint8(0x7f),
  47393 	1800: uint8(0x7f),
  47394 	1801: uint8(0x7f),
  47395 	1802: uint8(0x7f),
  47396 	1803: uint8(0x7f),
  47397 	1804: uint8(0x7f),
  47398 	1805: uint8(0x7f),
  47399 	1806: uint8(0x7f),
  47400 	1807: uint8(0x7f),
  47401 	1808: uint8(0x7f),
  47402 	1809: uint8(0x7f),
  47403 	1810: uint8(0x7f),
  47404 	1811: uint8(0x7f),
  47405 	1812: uint8(0x7f),
  47406 	1813: uint8(0x7f),
  47407 	1814: uint8(0x7f),
  47408 	1815: uint8(0x7f),
  47409 	1816: uint8(0x7f),
  47410 	1817: uint8(0x7f),
  47411 	1818: uint8(0x7f),
  47412 	1819: uint8(0x7f),
  47413 	1820: uint8(0x7f),
  47414 	1821: uint8(0x7f),
  47415 	1822: uint8(0x7f),
  47416 	1823: uint8(0x7f),
  47417 	1824: uint8(0x7f),
  47418 	1825: uint8(0x7f),
  47419 	1826: uint8(0x7f),
  47420 	1827: uint8(0x7f),
  47421 	1828: uint8(0x7f),
  47422 	1829: uint8(0x7f),
  47423 	1830: uint8(0x7f),
  47424 	1831: uint8(0x7f),
  47425 	1832: uint8(0x7f),
  47426 	1833: uint8(0x7f),
  47427 	1834: uint8(0x7f),
  47428 	1835: uint8(0x7f),
  47429 	1836: uint8(0x7f),
  47430 	1837: uint8(0x7f),
  47431 	1838: uint8(0x7f),
  47432 	1839: uint8(0x7f),
  47433 	1840: uint8(0x7f),
  47434 	1841: uint8(0x7f),
  47435 	1842: uint8(0x7f),
  47436 	1843: uint8(0x7f),
  47437 	1844: uint8(0x7f),
  47438 	1845: uint8(0x7f),
  47439 	1846: uint8(0x7f),
  47440 	1847: uint8(0x7f),
  47441 	1848: uint8(0x7f),
  47442 	1849: uint8(0x7f),
  47443 	1850: uint8(0x7f),
  47444 	1851: uint8(0x7f),
  47445 	1852: uint8(0x7f),
  47446 	1853: uint8(0x7f),
  47447 	1854: uint8(0x7f),
  47448 	1855: uint8(0x7f),
  47449 	1856: uint8(0x7f),
  47450 	1857: uint8(0x7f),
  47451 	1858: uint8(0x7f),
  47452 	1859: uint8(0x7f),
  47453 	1860: uint8(0x7f),
  47454 	1861: uint8(0x7f),
  47455 	1862: uint8(0x7f),
  47456 	1863: uint8(0x7f),
  47457 	1864: uint8(0x7f),
  47458 	1865: uint8(0x7f),
  47459 	1866: uint8(0x7f),
  47460 	1867: uint8(0x7f),
  47461 	1868: uint8(0x7f),
  47462 	1869: uint8(0x7f),
  47463 	1870: uint8(0x7f),
  47464 	1871: uint8(0x7f),
  47465 	1872: uint8(0x7f),
  47466 	1873: uint8(0x7f),
  47467 	1874: uint8(0x7f),
  47468 	1875: uint8(0x7f),
  47469 	1876: uint8(0x7f),
  47470 	1877: uint8(0x7f),
  47471 	1878: uint8(0x7f),
  47472 	1879: uint8(0x7f),
  47473 	1880: uint8(0x7f),
  47474 	1881: uint8(0x7f),
  47475 	1882: uint8(0x7f),
  47476 	1883: uint8(0x7f),
  47477 	1884: uint8(0x7f),
  47478 	1885: uint8(0x7f),
  47479 	1886: uint8(0x7f),
  47480 	1887: uint8(0x7f),
  47481 	1888: uint8(0x7f),
  47482 	1889: uint8(0x7f),
  47483 	1890: uint8(0x7f),
  47484 	1891: uint8(0x7f),
  47485 	1892: uint8(0x7f),
  47486 	1893: uint8(0x7f),
  47487 	1894: uint8(0x7f),
  47488 	1895: uint8(0x7f),
  47489 	1896: uint8(0x7f),
  47490 	1897: uint8(0x7f),
  47491 	1898: uint8(0x7f),
  47492 	1899: uint8(0x7f),
  47493 	1900: uint8(0x7f),
  47494 	1901: uint8(0x7f),
  47495 	1902: uint8(0x7f),
  47496 	1903: uint8(0x7f),
  47497 	1904: uint8(0x7f),
  47498 	1905: uint8(0x7f),
  47499 	1906: uint8(0x7f),
  47500 	1907: uint8(0x7f),
  47501 	1908: uint8(0x7f),
  47502 	1909: uint8(0x7f),
  47503 	1910: uint8(0x7f),
  47504 	1911: uint8(0x7f),
  47505 	1912: uint8(0x7f),
  47506 	1913: uint8(0x7f),
  47507 	1914: uint8(0x7f),
  47508 	1915: uint8(0x7f),
  47509 	1916: uint8(0x7f),
  47510 	1917: uint8(0x7f),
  47511 	1918: uint8(0x7f),
  47512 	1919: uint8(0x7f),
  47513 	1920: uint8(0x7f),
  47514 	1921: uint8(0x7f),
  47515 	1922: uint8(0x7f),
  47516 	1923: uint8(0x7f),
  47517 	1924: uint8(0x7f),
  47518 	1925: uint8(0x7f),
  47519 	1926: uint8(0x7f),
  47520 	1927: uint8(0x7f),
  47521 	1928: uint8(0x7f),
  47522 	1929: uint8(0x7f),
  47523 	1930: uint8(0x7f),
  47524 	1931: uint8(0x7f),
  47525 	1932: uint8(0x7f),
  47526 	1933: uint8(0x7f),
  47527 	1934: uint8(0x7f),
  47528 	1935: uint8(0x7f),
  47529 	1936: uint8(0x7f),
  47530 	1937: uint8(0x7f),
  47531 	1938: uint8(0x7f),
  47532 	1939: uint8(0x7f),
  47533 	1940: uint8(0x7f),
  47534 	1941: uint8(0x7f),
  47535 	1942: uint8(0x7f),
  47536 	1943: uint8(0x7f),
  47537 	1944: uint8(0x7f),
  47538 	1945: uint8(0x7f),
  47539 	1946: uint8(0x7f),
  47540 	1947: uint8(0x7f),
  47541 	1948: uint8(0x7f),
  47542 	1949: uint8(0x7f),
  47543 	1950: uint8(0x7f),
  47544 	1951: uint8(0x7f),
  47545 	1952: uint8(0x7f),
  47546 	1953: uint8(0x7f),
  47547 	1954: uint8(0x7f),
  47548 	1955: uint8(0x7f),
  47549 	1956: uint8(0x7f),
  47550 	1957: uint8(0x7f),
  47551 	1958: uint8(0x7f),
  47552 	1959: uint8(0x7f),
  47553 	1960: uint8(0x7f),
  47554 	1961: uint8(0x7f),
  47555 	1962: uint8(0x7f),
  47556 	1963: uint8(0x7f),
  47557 	1964: uint8(0x7f),
  47558 	1965: uint8(0x7f),
  47559 	1966: uint8(0x7f),
  47560 	1967: uint8(0x7f),
  47561 	1968: uint8(0x7f),
  47562 	1969: uint8(0x7f),
  47563 	1970: uint8(0x7f),
  47564 	1971: uint8(0x7f),
  47565 	1972: uint8(0x7f),
  47566 	1973: uint8(0x7f),
  47567 	1974: uint8(0x7f),
  47568 	1975: uint8(0x7f),
  47569 	1976: uint8(0x7f),
  47570 	1977: uint8(0x7f),
  47571 	1978: uint8(0x7f),
  47572 	1979: uint8(0x7f),
  47573 	1980: uint8(0x7f),
  47574 	1981: uint8(0x7f),
  47575 	1982: uint8(0x7f),
  47576 	1983: uint8(0x7f),
  47577 	1984: uint8(0x7f),
  47578 	1985: uint8(0x7f),
  47579 	1986: uint8(0x7f),
  47580 	1987: uint8(0x7f),
  47581 	1988: uint8(0x7f),
  47582 	1989: uint8(0x7f),
  47583 	1990: uint8(0x7f),
  47584 	1991: uint8(0x7f),
  47585 	1992: uint8(0x7f),
  47586 	1993: uint8(0x7f),
  47587 	1994: uint8(0x7f),
  47588 	1995: uint8(0x7f),
  47589 	1996: uint8(0x7f),
  47590 	1997: uint8(0x7f),
  47591 	1998: uint8(0x7f),
  47592 	1999: uint8(0x7f),
  47593 	2000: uint8(0x7f),
  47594 	2001: uint8(0x7f),
  47595 	2002: uint8(0x7f),
  47596 	2003: uint8(0x7f),
  47597 	2004: uint8(0x7f),
  47598 	2005: uint8(0x7f),
  47599 	2006: uint8(0x7f),
  47600 	2007: uint8(0x7f),
  47601 	2008: uint8(0x7f),
  47602 	2009: uint8(0x7f),
  47603 	2010: uint8(0x7f),
  47604 	2011: uint8(0x7f),
  47605 	2012: uint8(0x7f),
  47606 	2013: uint8(0x7f),
  47607 	2014: uint8(0x7f),
  47608 	2015: uint8(0x7f),
  47609 	2016: uint8(0x7f),
  47610 	2017: uint8(0x7f),
  47611 	2018: uint8(0x7f),
  47612 	2019: uint8(0x7f),
  47613 	2020: uint8(0x7f),
  47614 	2021: uint8(0x7f),
  47615 	2022: uint8(0x7f),
  47616 	2023: uint8(0x7f),
  47617 	2024: uint8(0x7f),
  47618 	2025: uint8(0x7f),
  47619 	2026: uint8(0x7f),
  47620 	2027: uint8(0x7f),
  47621 	2028: uint8(0x7f),
  47622 	2029: uint8(0x7f),
  47623 	2030: uint8(0x7f),
  47624 	2031: uint8(0x7f),
  47625 	2032: uint8(0x7f),
  47626 	2033: uint8(0x7f),
  47627 	2034: uint8(0x7f),
  47628 	2035: uint8(0x7f),
  47629 	2036: uint8(0x7f),
  47630 	2037: uint8(0x7f),
  47631 	2038: uint8(0x7f),
  47632 	2039: uint8(0x7f),
  47633 }
  47634 
  47635 var sclip2 = [225]uint8_t{
  47636 	0:   uint8(0xf0),
  47637 	1:   uint8(0xf0),
  47638 	2:   uint8(0xf0),
  47639 	3:   uint8(0xf0),
  47640 	4:   uint8(0xf0),
  47641 	5:   uint8(0xf0),
  47642 	6:   uint8(0xf0),
  47643 	7:   uint8(0xf0),
  47644 	8:   uint8(0xf0),
  47645 	9:   uint8(0xf0),
  47646 	10:  uint8(0xf0),
  47647 	11:  uint8(0xf0),
  47648 	12:  uint8(0xf0),
  47649 	13:  uint8(0xf0),
  47650 	14:  uint8(0xf0),
  47651 	15:  uint8(0xf0),
  47652 	16:  uint8(0xf0),
  47653 	17:  uint8(0xf0),
  47654 	18:  uint8(0xf0),
  47655 	19:  uint8(0xf0),
  47656 	20:  uint8(0xf0),
  47657 	21:  uint8(0xf0),
  47658 	22:  uint8(0xf0),
  47659 	23:  uint8(0xf0),
  47660 	24:  uint8(0xf0),
  47661 	25:  uint8(0xf0),
  47662 	26:  uint8(0xf0),
  47663 	27:  uint8(0xf0),
  47664 	28:  uint8(0xf0),
  47665 	29:  uint8(0xf0),
  47666 	30:  uint8(0xf0),
  47667 	31:  uint8(0xf0),
  47668 	32:  uint8(0xf0),
  47669 	33:  uint8(0xf0),
  47670 	34:  uint8(0xf0),
  47671 	35:  uint8(0xf0),
  47672 	36:  uint8(0xf0),
  47673 	37:  uint8(0xf0),
  47674 	38:  uint8(0xf0),
  47675 	39:  uint8(0xf0),
  47676 	40:  uint8(0xf0),
  47677 	41:  uint8(0xf0),
  47678 	42:  uint8(0xf0),
  47679 	43:  uint8(0xf0),
  47680 	44:  uint8(0xf0),
  47681 	45:  uint8(0xf0),
  47682 	46:  uint8(0xf0),
  47683 	47:  uint8(0xf0),
  47684 	48:  uint8(0xf0),
  47685 	49:  uint8(0xf0),
  47686 	50:  uint8(0xf0),
  47687 	51:  uint8(0xf0),
  47688 	52:  uint8(0xf0),
  47689 	53:  uint8(0xf0),
  47690 	54:  uint8(0xf0),
  47691 	55:  uint8(0xf0),
  47692 	56:  uint8(0xf0),
  47693 	57:  uint8(0xf0),
  47694 	58:  uint8(0xf0),
  47695 	59:  uint8(0xf0),
  47696 	60:  uint8(0xf0),
  47697 	61:  uint8(0xf0),
  47698 	62:  uint8(0xf0),
  47699 	63:  uint8(0xf0),
  47700 	64:  uint8(0xf0),
  47701 	65:  uint8(0xf0),
  47702 	66:  uint8(0xf0),
  47703 	67:  uint8(0xf0),
  47704 	68:  uint8(0xf0),
  47705 	69:  uint8(0xf0),
  47706 	70:  uint8(0xf0),
  47707 	71:  uint8(0xf0),
  47708 	72:  uint8(0xf0),
  47709 	73:  uint8(0xf0),
  47710 	74:  uint8(0xf0),
  47711 	75:  uint8(0xf0),
  47712 	76:  uint8(0xf0),
  47713 	77:  uint8(0xf0),
  47714 	78:  uint8(0xf0),
  47715 	79:  uint8(0xf0),
  47716 	80:  uint8(0xf0),
  47717 	81:  uint8(0xf0),
  47718 	82:  uint8(0xf0),
  47719 	83:  uint8(0xf0),
  47720 	84:  uint8(0xf0),
  47721 	85:  uint8(0xf0),
  47722 	86:  uint8(0xf0),
  47723 	87:  uint8(0xf0),
  47724 	88:  uint8(0xf0),
  47725 	89:  uint8(0xf0),
  47726 	90:  uint8(0xf0),
  47727 	91:  uint8(0xf0),
  47728 	92:  uint8(0xf0),
  47729 	93:  uint8(0xf0),
  47730 	94:  uint8(0xf0),
  47731 	95:  uint8(0xf0),
  47732 	96:  uint8(0xf0),
  47733 	97:  uint8(0xf1),
  47734 	98:  uint8(0xf2),
  47735 	99:  uint8(0xf3),
  47736 	100: uint8(0xf4),
  47737 	101: uint8(0xf5),
  47738 	102: uint8(0xf6),
  47739 	103: uint8(0xf7),
  47740 	104: uint8(0xf8),
  47741 	105: uint8(0xf9),
  47742 	106: uint8(0xfa),
  47743 	107: uint8(0xfb),
  47744 	108: uint8(0xfc),
  47745 	109: uint8(0xfd),
  47746 	110: uint8(0xfe),
  47747 	111: uint8(0xff),
  47748 	113: uint8(0x01),
  47749 	114: uint8(0x02),
  47750 	115: uint8(0x03),
  47751 	116: uint8(0x04),
  47752 	117: uint8(0x05),
  47753 	118: uint8(0x06),
  47754 	119: uint8(0x07),
  47755 	120: uint8(0x08),
  47756 	121: uint8(0x09),
  47757 	122: uint8(0x0a),
  47758 	123: uint8(0x0b),
  47759 	124: uint8(0x0c),
  47760 	125: uint8(0x0d),
  47761 	126: uint8(0x0e),
  47762 	127: uint8(0x0f),
  47763 	128: uint8(0x0f),
  47764 	129: uint8(0x0f),
  47765 	130: uint8(0x0f),
  47766 	131: uint8(0x0f),
  47767 	132: uint8(0x0f),
  47768 	133: uint8(0x0f),
  47769 	134: uint8(0x0f),
  47770 	135: uint8(0x0f),
  47771 	136: uint8(0x0f),
  47772 	137: uint8(0x0f),
  47773 	138: uint8(0x0f),
  47774 	139: uint8(0x0f),
  47775 	140: uint8(0x0f),
  47776 	141: uint8(0x0f),
  47777 	142: uint8(0x0f),
  47778 	143: uint8(0x0f),
  47779 	144: uint8(0x0f),
  47780 	145: uint8(0x0f),
  47781 	146: uint8(0x0f),
  47782 	147: uint8(0x0f),
  47783 	148: uint8(0x0f),
  47784 	149: uint8(0x0f),
  47785 	150: uint8(0x0f),
  47786 	151: uint8(0x0f),
  47787 	152: uint8(0x0f),
  47788 	153: uint8(0x0f),
  47789 	154: uint8(0x0f),
  47790 	155: uint8(0x0f),
  47791 	156: uint8(0x0f),
  47792 	157: uint8(0x0f),
  47793 	158: uint8(0x0f),
  47794 	159: uint8(0x0f),
  47795 	160: uint8(0x0f),
  47796 	161: uint8(0x0f),
  47797 	162: uint8(0x0f),
  47798 	163: uint8(0x0f),
  47799 	164: uint8(0x0f),
  47800 	165: uint8(0x0f),
  47801 	166: uint8(0x0f),
  47802 	167: uint8(0x0f),
  47803 	168: uint8(0x0f),
  47804 	169: uint8(0x0f),
  47805 	170: uint8(0x0f),
  47806 	171: uint8(0x0f),
  47807 	172: uint8(0x0f),
  47808 	173: uint8(0x0f),
  47809 	174: uint8(0x0f),
  47810 	175: uint8(0x0f),
  47811 	176: uint8(0x0f),
  47812 	177: uint8(0x0f),
  47813 	178: uint8(0x0f),
  47814 	179: uint8(0x0f),
  47815 	180: uint8(0x0f),
  47816 	181: uint8(0x0f),
  47817 	182: uint8(0x0f),
  47818 	183: uint8(0x0f),
  47819 	184: uint8(0x0f),
  47820 	185: uint8(0x0f),
  47821 	186: uint8(0x0f),
  47822 	187: uint8(0x0f),
  47823 	188: uint8(0x0f),
  47824 	189: uint8(0x0f),
  47825 	190: uint8(0x0f),
  47826 	191: uint8(0x0f),
  47827 	192: uint8(0x0f),
  47828 	193: uint8(0x0f),
  47829 	194: uint8(0x0f),
  47830 	195: uint8(0x0f),
  47831 	196: uint8(0x0f),
  47832 	197: uint8(0x0f),
  47833 	198: uint8(0x0f),
  47834 	199: uint8(0x0f),
  47835 	200: uint8(0x0f),
  47836 	201: uint8(0x0f),
  47837 	202: uint8(0x0f),
  47838 	203: uint8(0x0f),
  47839 	204: uint8(0x0f),
  47840 	205: uint8(0x0f),
  47841 	206: uint8(0x0f),
  47842 	207: uint8(0x0f),
  47843 	208: uint8(0x0f),
  47844 	209: uint8(0x0f),
  47845 	210: uint8(0x0f),
  47846 	211: uint8(0x0f),
  47847 	212: uint8(0x0f),
  47848 	213: uint8(0x0f),
  47849 	214: uint8(0x0f),
  47850 	215: uint8(0x0f),
  47851 	216: uint8(0x0f),
  47852 	217: uint8(0x0f),
  47853 	218: uint8(0x0f),
  47854 	219: uint8(0x0f),
  47855 	220: uint8(0x0f),
  47856 	221: uint8(0x0f),
  47857 	222: uint8(0x0f),
  47858 	223: uint8(0x0f),
  47859 }
  47860 
  47861 var clip11 = [767]uint8_t{
  47862 	256: uint8(0x01),
  47863 	257: uint8(0x02),
  47864 	258: uint8(0x03),
  47865 	259: uint8(0x04),
  47866 	260: uint8(0x05),
  47867 	261: uint8(0x06),
  47868 	262: uint8(0x07),
  47869 	263: uint8(0x08),
  47870 	264: uint8(0x09),
  47871 	265: uint8(0x0a),
  47872 	266: uint8(0x0b),
  47873 	267: uint8(0x0c),
  47874 	268: uint8(0x0d),
  47875 	269: uint8(0x0e),
  47876 	270: uint8(0x0f),
  47877 	271: uint8(0x10),
  47878 	272: uint8(0x11),
  47879 	273: uint8(0x12),
  47880 	274: uint8(0x13),
  47881 	275: uint8(0x14),
  47882 	276: uint8(0x15),
  47883 	277: uint8(0x16),
  47884 	278: uint8(0x17),
  47885 	279: uint8(0x18),
  47886 	280: uint8(0x19),
  47887 	281: uint8(0x1a),
  47888 	282: uint8(0x1b),
  47889 	283: uint8(0x1c),
  47890 	284: uint8(0x1d),
  47891 	285: uint8(0x1e),
  47892 	286: uint8(0x1f),
  47893 	287: uint8(0x20),
  47894 	288: uint8(0x21),
  47895 	289: uint8(0x22),
  47896 	290: uint8(0x23),
  47897 	291: uint8(0x24),
  47898 	292: uint8(0x25),
  47899 	293: uint8(0x26),
  47900 	294: uint8(0x27),
  47901 	295: uint8(0x28),
  47902 	296: uint8(0x29),
  47903 	297: uint8(0x2a),
  47904 	298: uint8(0x2b),
  47905 	299: uint8(0x2c),
  47906 	300: uint8(0x2d),
  47907 	301: uint8(0x2e),
  47908 	302: uint8(0x2f),
  47909 	303: uint8(0x30),
  47910 	304: uint8(0x31),
  47911 	305: uint8(0x32),
  47912 	306: uint8(0x33),
  47913 	307: uint8(0x34),
  47914 	308: uint8(0x35),
  47915 	309: uint8(0x36),
  47916 	310: uint8(0x37),
  47917 	311: uint8(0x38),
  47918 	312: uint8(0x39),
  47919 	313: uint8(0x3a),
  47920 	314: uint8(0x3b),
  47921 	315: uint8(0x3c),
  47922 	316: uint8(0x3d),
  47923 	317: uint8(0x3e),
  47924 	318: uint8(0x3f),
  47925 	319: uint8(0x40),
  47926 	320: uint8(0x41),
  47927 	321: uint8(0x42),
  47928 	322: uint8(0x43),
  47929 	323: uint8(0x44),
  47930 	324: uint8(0x45),
  47931 	325: uint8(0x46),
  47932 	326: uint8(0x47),
  47933 	327: uint8(0x48),
  47934 	328: uint8(0x49),
  47935 	329: uint8(0x4a),
  47936 	330: uint8(0x4b),
  47937 	331: uint8(0x4c),
  47938 	332: uint8(0x4d),
  47939 	333: uint8(0x4e),
  47940 	334: uint8(0x4f),
  47941 	335: uint8(0x50),
  47942 	336: uint8(0x51),
  47943 	337: uint8(0x52),
  47944 	338: uint8(0x53),
  47945 	339: uint8(0x54),
  47946 	340: uint8(0x55),
  47947 	341: uint8(0x56),
  47948 	342: uint8(0x57),
  47949 	343: uint8(0x58),
  47950 	344: uint8(0x59),
  47951 	345: uint8(0x5a),
  47952 	346: uint8(0x5b),
  47953 	347: uint8(0x5c),
  47954 	348: uint8(0x5d),
  47955 	349: uint8(0x5e),
  47956 	350: uint8(0x5f),
  47957 	351: uint8(0x60),
  47958 	352: uint8(0x61),
  47959 	353: uint8(0x62),
  47960 	354: uint8(0x63),
  47961 	355: uint8(0x64),
  47962 	356: uint8(0x65),
  47963 	357: uint8(0x66),
  47964 	358: uint8(0x67),
  47965 	359: uint8(0x68),
  47966 	360: uint8(0x69),
  47967 	361: uint8(0x6a),
  47968 	362: uint8(0x6b),
  47969 	363: uint8(0x6c),
  47970 	364: uint8(0x6d),
  47971 	365: uint8(0x6e),
  47972 	366: uint8(0x6f),
  47973 	367: uint8(0x70),
  47974 	368: uint8(0x71),
  47975 	369: uint8(0x72),
  47976 	370: uint8(0x73),
  47977 	371: uint8(0x74),
  47978 	372: uint8(0x75),
  47979 	373: uint8(0x76),
  47980 	374: uint8(0x77),
  47981 	375: uint8(0x78),
  47982 	376: uint8(0x79),
  47983 	377: uint8(0x7a),
  47984 	378: uint8(0x7b),
  47985 	379: uint8(0x7c),
  47986 	380: uint8(0x7d),
  47987 	381: uint8(0x7e),
  47988 	382: uint8(0x7f),
  47989 	383: uint8(0x80),
  47990 	384: uint8(0x81),
  47991 	385: uint8(0x82),
  47992 	386: uint8(0x83),
  47993 	387: uint8(0x84),
  47994 	388: uint8(0x85),
  47995 	389: uint8(0x86),
  47996 	390: uint8(0x87),
  47997 	391: uint8(0x88),
  47998 	392: uint8(0x89),
  47999 	393: uint8(0x8a),
  48000 	394: uint8(0x8b),
  48001 	395: uint8(0x8c),
  48002 	396: uint8(0x8d),
  48003 	397: uint8(0x8e),
  48004 	398: uint8(0x8f),
  48005 	399: uint8(0x90),
  48006 	400: uint8(0x91),
  48007 	401: uint8(0x92),
  48008 	402: uint8(0x93),
  48009 	403: uint8(0x94),
  48010 	404: uint8(0x95),
  48011 	405: uint8(0x96),
  48012 	406: uint8(0x97),
  48013 	407: uint8(0x98),
  48014 	408: uint8(0x99),
  48015 	409: uint8(0x9a),
  48016 	410: uint8(0x9b),
  48017 	411: uint8(0x9c),
  48018 	412: uint8(0x9d),
  48019 	413: uint8(0x9e),
  48020 	414: uint8(0x9f),
  48021 	415: uint8(0xa0),
  48022 	416: uint8(0xa1),
  48023 	417: uint8(0xa2),
  48024 	418: uint8(0xa3),
  48025 	419: uint8(0xa4),
  48026 	420: uint8(0xa5),
  48027 	421: uint8(0xa6),
  48028 	422: uint8(0xa7),
  48029 	423: uint8(0xa8),
  48030 	424: uint8(0xa9),
  48031 	425: uint8(0xaa),
  48032 	426: uint8(0xab),
  48033 	427: uint8(0xac),
  48034 	428: uint8(0xad),
  48035 	429: uint8(0xae),
  48036 	430: uint8(0xaf),
  48037 	431: uint8(0xb0),
  48038 	432: uint8(0xb1),
  48039 	433: uint8(0xb2),
  48040 	434: uint8(0xb3),
  48041 	435: uint8(0xb4),
  48042 	436: uint8(0xb5),
  48043 	437: uint8(0xb6),
  48044 	438: uint8(0xb7),
  48045 	439: uint8(0xb8),
  48046 	440: uint8(0xb9),
  48047 	441: uint8(0xba),
  48048 	442: uint8(0xbb),
  48049 	443: uint8(0xbc),
  48050 	444: uint8(0xbd),
  48051 	445: uint8(0xbe),
  48052 	446: uint8(0xbf),
  48053 	447: uint8(0xc0),
  48054 	448: uint8(0xc1),
  48055 	449: uint8(0xc2),
  48056 	450: uint8(0xc3),
  48057 	451: uint8(0xc4),
  48058 	452: uint8(0xc5),
  48059 	453: uint8(0xc6),
  48060 	454: uint8(0xc7),
  48061 	455: uint8(0xc8),
  48062 	456: uint8(0xc9),
  48063 	457: uint8(0xca),
  48064 	458: uint8(0xcb),
  48065 	459: uint8(0xcc),
  48066 	460: uint8(0xcd),
  48067 	461: uint8(0xce),
  48068 	462: uint8(0xcf),
  48069 	463: uint8(0xd0),
  48070 	464: uint8(0xd1),
  48071 	465: uint8(0xd2),
  48072 	466: uint8(0xd3),
  48073 	467: uint8(0xd4),
  48074 	468: uint8(0xd5),
  48075 	469: uint8(0xd6),
  48076 	470: uint8(0xd7),
  48077 	471: uint8(0xd8),
  48078 	472: uint8(0xd9),
  48079 	473: uint8(0xda),
  48080 	474: uint8(0xdb),
  48081 	475: uint8(0xdc),
  48082 	476: uint8(0xdd),
  48083 	477: uint8(0xde),
  48084 	478: uint8(0xdf),
  48085 	479: uint8(0xe0),
  48086 	480: uint8(0xe1),
  48087 	481: uint8(0xe2),
  48088 	482: uint8(0xe3),
  48089 	483: uint8(0xe4),
  48090 	484: uint8(0xe5),
  48091 	485: uint8(0xe6),
  48092 	486: uint8(0xe7),
  48093 	487: uint8(0xe8),
  48094 	488: uint8(0xe9),
  48095 	489: uint8(0xea),
  48096 	490: uint8(0xeb),
  48097 	491: uint8(0xec),
  48098 	492: uint8(0xed),
  48099 	493: uint8(0xee),
  48100 	494: uint8(0xef),
  48101 	495: uint8(0xf0),
  48102 	496: uint8(0xf1),
  48103 	497: uint8(0xf2),
  48104 	498: uint8(0xf3),
  48105 	499: uint8(0xf4),
  48106 	500: uint8(0xf5),
  48107 	501: uint8(0xf6),
  48108 	502: uint8(0xf7),
  48109 	503: uint8(0xf8),
  48110 	504: uint8(0xf9),
  48111 	505: uint8(0xfa),
  48112 	506: uint8(0xfb),
  48113 	507: uint8(0xfc),
  48114 	508: uint8(0xfd),
  48115 	509: uint8(0xfe),
  48116 	510: uint8(0xff),
  48117 	511: uint8(0xff),
  48118 	512: uint8(0xff),
  48119 	513: uint8(0xff),
  48120 	514: uint8(0xff),
  48121 	515: uint8(0xff),
  48122 	516: uint8(0xff),
  48123 	517: uint8(0xff),
  48124 	518: uint8(0xff),
  48125 	519: uint8(0xff),
  48126 	520: uint8(0xff),
  48127 	521: uint8(0xff),
  48128 	522: uint8(0xff),
  48129 	523: uint8(0xff),
  48130 	524: uint8(0xff),
  48131 	525: uint8(0xff),
  48132 	526: uint8(0xff),
  48133 	527: uint8(0xff),
  48134 	528: uint8(0xff),
  48135 	529: uint8(0xff),
  48136 	530: uint8(0xff),
  48137 	531: uint8(0xff),
  48138 	532: uint8(0xff),
  48139 	533: uint8(0xff),
  48140 	534: uint8(0xff),
  48141 	535: uint8(0xff),
  48142 	536: uint8(0xff),
  48143 	537: uint8(0xff),
  48144 	538: uint8(0xff),
  48145 	539: uint8(0xff),
  48146 	540: uint8(0xff),
  48147 	541: uint8(0xff),
  48148 	542: uint8(0xff),
  48149 	543: uint8(0xff),
  48150 	544: uint8(0xff),
  48151 	545: uint8(0xff),
  48152 	546: uint8(0xff),
  48153 	547: uint8(0xff),
  48154 	548: uint8(0xff),
  48155 	549: uint8(0xff),
  48156 	550: uint8(0xff),
  48157 	551: uint8(0xff),
  48158 	552: uint8(0xff),
  48159 	553: uint8(0xff),
  48160 	554: uint8(0xff),
  48161 	555: uint8(0xff),
  48162 	556: uint8(0xff),
  48163 	557: uint8(0xff),
  48164 	558: uint8(0xff),
  48165 	559: uint8(0xff),
  48166 	560: uint8(0xff),
  48167 	561: uint8(0xff),
  48168 	562: uint8(0xff),
  48169 	563: uint8(0xff),
  48170 	564: uint8(0xff),
  48171 	565: uint8(0xff),
  48172 	566: uint8(0xff),
  48173 	567: uint8(0xff),
  48174 	568: uint8(0xff),
  48175 	569: uint8(0xff),
  48176 	570: uint8(0xff),
  48177 	571: uint8(0xff),
  48178 	572: uint8(0xff),
  48179 	573: uint8(0xff),
  48180 	574: uint8(0xff),
  48181 	575: uint8(0xff),
  48182 	576: uint8(0xff),
  48183 	577: uint8(0xff),
  48184 	578: uint8(0xff),
  48185 	579: uint8(0xff),
  48186 	580: uint8(0xff),
  48187 	581: uint8(0xff),
  48188 	582: uint8(0xff),
  48189 	583: uint8(0xff),
  48190 	584: uint8(0xff),
  48191 	585: uint8(0xff),
  48192 	586: uint8(0xff),
  48193 	587: uint8(0xff),
  48194 	588: uint8(0xff),
  48195 	589: uint8(0xff),
  48196 	590: uint8(0xff),
  48197 	591: uint8(0xff),
  48198 	592: uint8(0xff),
  48199 	593: uint8(0xff),
  48200 	594: uint8(0xff),
  48201 	595: uint8(0xff),
  48202 	596: uint8(0xff),
  48203 	597: uint8(0xff),
  48204 	598: uint8(0xff),
  48205 	599: uint8(0xff),
  48206 	600: uint8(0xff),
  48207 	601: uint8(0xff),
  48208 	602: uint8(0xff),
  48209 	603: uint8(0xff),
  48210 	604: uint8(0xff),
  48211 	605: uint8(0xff),
  48212 	606: uint8(0xff),
  48213 	607: uint8(0xff),
  48214 	608: uint8(0xff),
  48215 	609: uint8(0xff),
  48216 	610: uint8(0xff),
  48217 	611: uint8(0xff),
  48218 	612: uint8(0xff),
  48219 	613: uint8(0xff),
  48220 	614: uint8(0xff),
  48221 	615: uint8(0xff),
  48222 	616: uint8(0xff),
  48223 	617: uint8(0xff),
  48224 	618: uint8(0xff),
  48225 	619: uint8(0xff),
  48226 	620: uint8(0xff),
  48227 	621: uint8(0xff),
  48228 	622: uint8(0xff),
  48229 	623: uint8(0xff),
  48230 	624: uint8(0xff),
  48231 	625: uint8(0xff),
  48232 	626: uint8(0xff),
  48233 	627: uint8(0xff),
  48234 	628: uint8(0xff),
  48235 	629: uint8(0xff),
  48236 	630: uint8(0xff),
  48237 	631: uint8(0xff),
  48238 	632: uint8(0xff),
  48239 	633: uint8(0xff),
  48240 	634: uint8(0xff),
  48241 	635: uint8(0xff),
  48242 	636: uint8(0xff),
  48243 	637: uint8(0xff),
  48244 	638: uint8(0xff),
  48245 	639: uint8(0xff),
  48246 	640: uint8(0xff),
  48247 	641: uint8(0xff),
  48248 	642: uint8(0xff),
  48249 	643: uint8(0xff),
  48250 	644: uint8(0xff),
  48251 	645: uint8(0xff),
  48252 	646: uint8(0xff),
  48253 	647: uint8(0xff),
  48254 	648: uint8(0xff),
  48255 	649: uint8(0xff),
  48256 	650: uint8(0xff),
  48257 	651: uint8(0xff),
  48258 	652: uint8(0xff),
  48259 	653: uint8(0xff),
  48260 	654: uint8(0xff),
  48261 	655: uint8(0xff),
  48262 	656: uint8(0xff),
  48263 	657: uint8(0xff),
  48264 	658: uint8(0xff),
  48265 	659: uint8(0xff),
  48266 	660: uint8(0xff),
  48267 	661: uint8(0xff),
  48268 	662: uint8(0xff),
  48269 	663: uint8(0xff),
  48270 	664: uint8(0xff),
  48271 	665: uint8(0xff),
  48272 	666: uint8(0xff),
  48273 	667: uint8(0xff),
  48274 	668: uint8(0xff),
  48275 	669: uint8(0xff),
  48276 	670: uint8(0xff),
  48277 	671: uint8(0xff),
  48278 	672: uint8(0xff),
  48279 	673: uint8(0xff),
  48280 	674: uint8(0xff),
  48281 	675: uint8(0xff),
  48282 	676: uint8(0xff),
  48283 	677: uint8(0xff),
  48284 	678: uint8(0xff),
  48285 	679: uint8(0xff),
  48286 	680: uint8(0xff),
  48287 	681: uint8(0xff),
  48288 	682: uint8(0xff),
  48289 	683: uint8(0xff),
  48290 	684: uint8(0xff),
  48291 	685: uint8(0xff),
  48292 	686: uint8(0xff),
  48293 	687: uint8(0xff),
  48294 	688: uint8(0xff),
  48295 	689: uint8(0xff),
  48296 	690: uint8(0xff),
  48297 	691: uint8(0xff),
  48298 	692: uint8(0xff),
  48299 	693: uint8(0xff),
  48300 	694: uint8(0xff),
  48301 	695: uint8(0xff),
  48302 	696: uint8(0xff),
  48303 	697: uint8(0xff),
  48304 	698: uint8(0xff),
  48305 	699: uint8(0xff),
  48306 	700: uint8(0xff),
  48307 	701: uint8(0xff),
  48308 	702: uint8(0xff),
  48309 	703: uint8(0xff),
  48310 	704: uint8(0xff),
  48311 	705: uint8(0xff),
  48312 	706: uint8(0xff),
  48313 	707: uint8(0xff),
  48314 	708: uint8(0xff),
  48315 	709: uint8(0xff),
  48316 	710: uint8(0xff),
  48317 	711: uint8(0xff),
  48318 	712: uint8(0xff),
  48319 	713: uint8(0xff),
  48320 	714: uint8(0xff),
  48321 	715: uint8(0xff),
  48322 	716: uint8(0xff),
  48323 	717: uint8(0xff),
  48324 	718: uint8(0xff),
  48325 	719: uint8(0xff),
  48326 	720: uint8(0xff),
  48327 	721: uint8(0xff),
  48328 	722: uint8(0xff),
  48329 	723: uint8(0xff),
  48330 	724: uint8(0xff),
  48331 	725: uint8(0xff),
  48332 	726: uint8(0xff),
  48333 	727: uint8(0xff),
  48334 	728: uint8(0xff),
  48335 	729: uint8(0xff),
  48336 	730: uint8(0xff),
  48337 	731: uint8(0xff),
  48338 	732: uint8(0xff),
  48339 	733: uint8(0xff),
  48340 	734: uint8(0xff),
  48341 	735: uint8(0xff),
  48342 	736: uint8(0xff),
  48343 	737: uint8(0xff),
  48344 	738: uint8(0xff),
  48345 	739: uint8(0xff),
  48346 	740: uint8(0xff),
  48347 	741: uint8(0xff),
  48348 	742: uint8(0xff),
  48349 	743: uint8(0xff),
  48350 	744: uint8(0xff),
  48351 	745: uint8(0xff),
  48352 	746: uint8(0xff),
  48353 	747: uint8(0xff),
  48354 	748: uint8(0xff),
  48355 	749: uint8(0xff),
  48356 	750: uint8(0xff),
  48357 	751: uint8(0xff),
  48358 	752: uint8(0xff),
  48359 	753: uint8(0xff),
  48360 	754: uint8(0xff),
  48361 	755: uint8(0xff),
  48362 	756: uint8(0xff),
  48363 	757: uint8(0xff),
  48364 	758: uint8(0xff),
  48365 	759: uint8(0xff),
  48366 	760: uint8(0xff),
  48367 	761: uint8(0xff),
  48368 	762: uint8(0xff),
  48369 	763: uint8(0xff),
  48370 	764: uint8(0xff),
  48371 	765: uint8(0xff),
  48372 }
  48373 
  48374 func VP8InitClipTables(tls *libc.TLS) {
  48375 }
  48376 
  48377 func VP8DspInitMIPS32(tls *libc.TLS) {
  48378 }
  48379 
  48380 func VP8DspInitMIPSdspR2(tls *libc.TLS) {
  48381 }
  48382 
  48383 func VP8DspInitMSA(tls *libc.TLS) {
  48384 }
  48385 
  48386 func VP8DspInitNEON(tls *libc.TLS) {
  48387 }
  48388 
  48389 func VP8DspInitSSE2(tls *libc.TLS) {
  48390 }
  48391 
  48392 func VP8DspInitSSE41(tls *libc.TLS) {
  48393 }
  48394 
  48395 const SIZE_MAX24 = "_UI64_MAX"
  48396 
  48397 //------------------------------------------------------------------------------
  48398 
  48399 // Copyright 2012 Google Inc. All Rights Reserved.
  48400 //
  48401 // Use of this source code is governed by a BSD-style license
  48402 // that can be found in the COPYING file in the root of the source
  48403 // tree. An additional intellectual property rights grant can be found
  48404 // in the file PATENTS. All contributing project authors may
  48405 // be found in the AUTHORS file in the root of the source tree.
  48406 // -----------------------------------------------------------------------------
  48407 //
  48408 // Misc. common utility functions
  48409 //
  48410 // Authors: Skal (pascal.massimino@gmail.com)
  48411 //          Urvang (urvang@google.com)
  48412 
  48413 // Copyright 2010 Google Inc. All Rights Reserved.
  48414 //
  48415 // Use of this source code is governed by a BSD-style license
  48416 // that can be found in the COPYING file in the root of the source
  48417 // tree. An additional intellectual property rights grant can be found
  48418 // in the file PATENTS. All contributing project authors may
  48419 // be found in the AUTHORS file in the root of the source tree.
  48420 // -----------------------------------------------------------------------------
  48421 //
  48422 //  Common types + memory wrappers
  48423 //
  48424 // Author: Skal (pascal.massimino@gmail.com)
  48425 
  48426 func clip_8b2(tls *libc.TLS, v int32) (r uint8_t) {
  48427 	var v1, v2 int32
  48428 	_, _ = v1, v2
  48429 	if !(v & ^libc.Int32FromInt32(0xff) != 0) {
  48430 		v1 = v
  48431 	} else {
  48432 		if v < 0 {
  48433 			v2 = 0
  48434 		} else {
  48435 			v2 = int32(255)
  48436 		}
  48437 		v1 = v2
  48438 	}
  48439 	return uint8(v1)
  48440 }
  48441 
  48442 func clip_max(tls *libc.TLS, v int32, max int32) (r int32) {
  48443 	var v1 int32
  48444 	_ = v1
  48445 	if v > max {
  48446 		v1 = max
  48447 	} else {
  48448 		v1 = v
  48449 	}
  48450 	return v1
  48451 }
  48452 
  48453 // C documentation
  48454 //
  48455 //	// general-purpose util function
  48456 func VP8SetHistogramData(tls *libc.TLS, distribution uintptr, histo uintptr) {
  48457 	var k, last_non_zero, max_value, value int32
  48458 	_, _, _, _ = k, last_non_zero, max_value, value
  48459 	max_value = 0
  48460 	last_non_zero = int32(1)
  48461 	k = 0
  48462 	for {
  48463 		if !(k <= int32(MAX_COEFF_THRESH)) {
  48464 			break
  48465 		}
  48466 		value = **(**int32)(__ccgo_up(distribution + uintptr(k)*4))
  48467 		if value > 0 {
  48468 			if value > max_value {
  48469 				max_value = value
  48470 			}
  48471 			last_non_zero = k
  48472 		}
  48473 		goto _1
  48474 	_1:
  48475 		;
  48476 		k = k + 1
  48477 	}
  48478 	(*VP8Histogram)(unsafe.Pointer(histo)).Fmax_value = max_value
  48479 	(*VP8Histogram)(unsafe.Pointer(histo)).Flast_non_zero = last_non_zero
  48480 }
  48481 
  48482 func CollectHistogram_C(tls *libc.TLS, ref uintptr, pred uintptr, start_block int32, end_block int32, histo uintptr) {
  48483 	bp := tls.Alloc(160)
  48484 	defer tls.Free(160)
  48485 	var clipped_value, j, k, v int32
  48486 	var _ /* distribution at bp+0 */ [32]int32
  48487 	var _ /* out at bp+128 */ [16]int16_t
  48488 	_, _, _, _ = clipped_value, j, k, v
  48489 	**(**[32]int32)(__ccgo_up(bp)) = [32]int32{}
  48490 	j = start_block
  48491 	for {
  48492 		if !(j < end_block) {
  48493 			break
  48494 		}
  48495 		(*(*func(*libc.TLS, uintptr, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8FTransform})))(tls, ref+uintptr(VP8DspScan[j]), pred+uintptr(VP8DspScan[j]), bp+128)
  48496 		// Convert coefficients to bin.
  48497 		k = 0
  48498 		for {
  48499 			if !(k < int32(16)) {
  48500 				break
  48501 			}
  48502 			v = libc.Xabs(tls, int32((**(**[16]int16_t)(__ccgo_up(bp + 128)))[k])) >> int32(3)
  48503 			clipped_value = clip_max(tls, v, int32(MAX_COEFF_THRESH))
  48504 			(**(**[32]int32)(__ccgo_up(bp)))[clipped_value] = (**(**[32]int32)(__ccgo_up(bp)))[clipped_value] + 1
  48505 			goto _2
  48506 		_2:
  48507 			;
  48508 			k = k + 1
  48509 		}
  48510 		goto _1
  48511 	_1:
  48512 		;
  48513 		j = j + 1
  48514 	}
  48515 	VP8SetHistogramData(tls, bp, histo)
  48516 }
  48517 
  48518 //------------------------------------------------------------------------------
  48519 // run-time tables (~4k)
  48520 
  48521 var clip12 [766]uint8_t // clips [-255,510] to [0,255]
  48522 
  48523 // C documentation
  48524 //
  48525 //	// We declare this variable 'volatile' to prevent instruction reordering
  48526 //	// and make sure it's set to true _last_ (so as to be thread-safe)
  48527 var tables_ok = int32(0)
  48528 
  48529 func InitTables(tls *libc.TLS) {
  48530 	var i int32
  48531 	_ = i
  48532 	if !(libc.AtomicLoadPInt32(uintptr(unsafe.Pointer(&tables_ok))) != 0) {
  48533 		i = -int32(255)
  48534 		for {
  48535 			if !(i <= libc.Int32FromInt32(255)+libc.Int32FromInt32(255)) {
  48536 				break
  48537 			}
  48538 			clip12[int32(255)+i] = clip_8b2(tls, i)
  48539 			goto _1
  48540 		_1:
  48541 			;
  48542 			i = i + 1
  48543 		}
  48544 		libc.AtomicStorePInt32(uintptr(unsafe.Pointer(&tables_ok)), int32(1))
  48545 	}
  48546 }
  48547 
  48548 //------------------------------------------------------------------------------
  48549 // Transforms (Paragraph 14.4)
  48550 
  48551 func ITransformOne(tls *libc.TLS, ref uintptr, in uintptr, dst uintptr) {
  48552 	bp := tls.Alloc(64)
  48553 	defer tls.Free(64)
  48554 	var a, a1, b, b1, c, c1, d, d1, dc, i int32
  48555 	var tmp uintptr
  48556 	var _ /* C at bp+0 */ [16]int32
  48557 	_, _, _, _, _, _, _, _, _, _, _ = a, a1, b, b1, c, c1, d, d1, dc, i, tmp
  48558 	tmp = bp
  48559 	i = 0
  48560 	for {
  48561 		if !(i < int32(4)) {
  48562 			break
  48563 		} // vertical pass
  48564 		a = int32(**(**int16_t)(__ccgo_up(in))) + int32(**(**int16_t)(__ccgo_up(in + 8*2)))
  48565 		b = int32(**(**int16_t)(__ccgo_up(in))) - int32(**(**int16_t)(__ccgo_up(in + 8*2)))
  48566 		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))))
  48567 		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)
  48568 		**(**int32)(__ccgo_up(tmp)) = a + d
  48569 		**(**int32)(__ccgo_up(tmp + 1*4)) = b + c
  48570 		**(**int32)(__ccgo_up(tmp + 2*4)) = b - c
  48571 		**(**int32)(__ccgo_up(tmp + 3*4)) = a - d
  48572 		tmp = tmp + uintptr(4)*4
  48573 		in += 2
  48574 		goto _1
  48575 	_1:
  48576 		;
  48577 		i = i + 1
  48578 	}
  48579 	tmp = bp
  48580 	i = 0
  48581 	for {
  48582 		if !(i < int32(4)) {
  48583 			break
  48584 		} // horizontal pass
  48585 		dc = **(**int32)(__ccgo_up(tmp)) + int32(4)
  48586 		a1 = dc + **(**int32)(__ccgo_up(tmp + 8*4))
  48587 		b1 = dc - **(**int32)(__ccgo_up(tmp + 8*4))
  48588 		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)))
  48589 		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)
  48590 		**(**uint8_t)(__ccgo_up(dst + uintptr(0+i*int32(BPS)))) = clip_8b2(tls, int32(**(**uint8_t)(__ccgo_up(ref + uintptr(0+i*int32(BPS)))))+(a1+d1)>>int32(3))
  48591 		**(**uint8_t)(__ccgo_up(dst + uintptr(int32(1)+i*int32(BPS)))) = clip_8b2(tls, int32(**(**uint8_t)(__ccgo_up(ref + uintptr(int32(1)+i*int32(BPS)))))+(b1+c1)>>int32(3))
  48592 		**(**uint8_t)(__ccgo_up(dst + uintptr(int32(2)+i*int32(BPS)))) = clip_8b2(tls, int32(**(**uint8_t)(__ccgo_up(ref + uintptr(int32(2)+i*int32(BPS)))))+(b1-c1)>>int32(3))
  48593 		**(**uint8_t)(__ccgo_up(dst + uintptr(int32(3)+i*int32(BPS)))) = clip_8b2(tls, int32(**(**uint8_t)(__ccgo_up(ref + uintptr(int32(3)+i*int32(BPS)))))+(a1-d1)>>int32(3))
  48594 		tmp += 4
  48595 		goto _2
  48596 	_2:
  48597 		;
  48598 		i = i + 1
  48599 	}
  48600 }
  48601 
  48602 func ITransform_C(tls *libc.TLS, ref uintptr, in uintptr, dst uintptr, do_two int32) {
  48603 	ITransformOne(tls, ref, in, dst)
  48604 	if do_two != 0 {
  48605 		ITransformOne(tls, ref+uintptr(4), in+uintptr(16)*2, dst+uintptr(4))
  48606 	}
  48607 }
  48608 
  48609 func FTransform_C(tls *libc.TLS, src uintptr, ref uintptr, out uintptr) {
  48610 	var a0, a01, a1, a11, a2, a21, a3, a31, d0, d1, d2, d3, i int32
  48611 	var tmp [16]int32
  48612 	_, _, _, _, _, _, _, _, _, _, _, _, _, _ = a0, a01, a1, a11, a2, a21, a3, a31, d0, d1, d2, d3, i, tmp
  48613 	i = 0
  48614 	for {
  48615 		if !(i < int32(4)) {
  48616 			break
  48617 		}
  48618 		d0 = int32(**(**uint8_t)(__ccgo_up(src))) - int32(**(**uint8_t)(__ccgo_up(ref))) // 9bit dynamic range ([-255,255])
  48619 		d1 = int32(**(**uint8_t)(__ccgo_up(src + 1))) - int32(**(**uint8_t)(__ccgo_up(ref + 1)))
  48620 		d2 = int32(**(**uint8_t)(__ccgo_up(src + 2))) - int32(**(**uint8_t)(__ccgo_up(ref + 2)))
  48621 		d3 = int32(**(**uint8_t)(__ccgo_up(src + 3))) - int32(**(**uint8_t)(__ccgo_up(ref + 3)))
  48622 		a0 = d0 + d3 // 10b                      [-510,510]
  48623 		a1 = d1 + d2
  48624 		a2 = d1 - d2
  48625 		a3 = d0 - d3
  48626 		tmp[0+i*int32(4)] = (a0 + a1) * int32(8)                                               // 14b                      [-8160,8160]
  48627 		tmp[int32(1)+i*int32(4)] = (a2*int32(2217) + a3*int32(5352) + int32(1812)) >> int32(9) // [-7536,7542]
  48628 		tmp[int32(2)+i*int32(4)] = (a0 - a1) * int32(8)
  48629 		tmp[int32(3)+i*int32(4)] = (a3*int32(2217) - a2*int32(5352) + int32(937)) >> int32(9)
  48630 		goto _1
  48631 	_1:
  48632 		;
  48633 		i = i + 1
  48634 		src = src + uintptr(BPS)
  48635 		ref = ref + uintptr(BPS)
  48636 	}
  48637 	i = 0
  48638 	for {
  48639 		if !(i < int32(4)) {
  48640 			break
  48641 		}
  48642 		a01 = tmp[0+i] + tmp[int32(12)+i] // 15b
  48643 		a11 = tmp[int32(4)+i] + tmp[int32(8)+i]
  48644 		a21 = tmp[int32(4)+i] - tmp[int32(8)+i]
  48645 		a31 = tmp[0+i] - tmp[int32(12)+i]
  48646 		**(**int16_t)(__ccgo_up(out + uintptr(0+i)*2)) = int16((a01 + a11 + int32(7)) >> int32(4)) // 12b
  48647 		**(**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))
  48648 		**(**int16_t)(__ccgo_up(out + uintptr(int32(8)+i)*2)) = int16((a01 - a11 + int32(7)) >> int32(4))
  48649 		**(**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))
  48650 		goto _2
  48651 	_2:
  48652 		;
  48653 		i = i + 1
  48654 	}
  48655 }
  48656 
  48657 func FTransform2_C(tls *libc.TLS, src uintptr, ref uintptr, out uintptr) {
  48658 	(*(*func(*libc.TLS, uintptr, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8FTransform})))(tls, src, ref, out)
  48659 	(*(*func(*libc.TLS, uintptr, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8FTransform})))(tls, src+uintptr(4), ref+uintptr(4), out+uintptr(16)*2)
  48660 }
  48661 
  48662 func FTransformWHT_C(tls *libc.TLS, in uintptr, out uintptr) {
  48663 	var a0, a01, a1, a11, a2, a21, a3, a31, b0, b1, b2, b3, i int32
  48664 	var tmp [16]int32_t
  48665 	_, _, _, _, _, _, _, _, _, _, _, _, _, _ = a0, a01, a1, a11, a2, a21, a3, a31, b0, b1, b2, b3, i, tmp
  48666 	i = 0
  48667 	for {
  48668 		if !(i < int32(4)) {
  48669 			break
  48670 		}
  48671 		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
  48672 		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)))
  48673 		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)))
  48674 		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)))
  48675 		tmp[0+i*int32(4)] = a0 + a1 // 14b
  48676 		tmp[int32(1)+i*int32(4)] = a3 + a2
  48677 		tmp[int32(2)+i*int32(4)] = a3 - a2
  48678 		tmp[int32(3)+i*int32(4)] = a0 - a1
  48679 		goto _1
  48680 	_1:
  48681 		;
  48682 		i = i + 1
  48683 		in = in + uintptr(64)*2
  48684 	}
  48685 	i = 0
  48686 	for {
  48687 		if !(i < int32(4)) {
  48688 			break
  48689 		}
  48690 		a01 = tmp[0+i] + tmp[int32(8)+i] // 15b
  48691 		a11 = tmp[int32(4)+i] + tmp[int32(12)+i]
  48692 		a21 = tmp[int32(4)+i] - tmp[int32(12)+i]
  48693 		a31 = tmp[0+i] - tmp[int32(8)+i]
  48694 		b0 = a01 + a11 // 16b
  48695 		b1 = a31 + a21
  48696 		b2 = a31 - a21
  48697 		b3 = a01 - a11
  48698 		**(**int16_t)(__ccgo_up(out + uintptr(0+i)*2)) = int16(b0 >> int32(1)) // 15b
  48699 		**(**int16_t)(__ccgo_up(out + uintptr(int32(4)+i)*2)) = int16(b1 >> int32(1))
  48700 		**(**int16_t)(__ccgo_up(out + uintptr(int32(8)+i)*2)) = int16(b2 >> int32(1))
  48701 		**(**int16_t)(__ccgo_up(out + uintptr(int32(12)+i)*2)) = int16(b3 >> int32(1))
  48702 		goto _2
  48703 	_2:
  48704 		;
  48705 		i = i + 1
  48706 	}
  48707 }
  48708 
  48709 //------------------------------------------------------------------------------
  48710 // Intra predictions
  48711 
  48712 func Fill(tls *libc.TLS, dst uintptr, value int32, size int32) {
  48713 	var j int32
  48714 	_ = j
  48715 	j = 0
  48716 	for {
  48717 		if !(j < size) {
  48718 			break
  48719 		}
  48720 		libc.Xmemset(tls, dst+uintptr(j*int32(BPS)), value, uint64(size))
  48721 		goto _1
  48722 	_1:
  48723 		;
  48724 		j = j + 1
  48725 	}
  48726 }
  48727 
  48728 func VerticalPred(tls *libc.TLS, dst uintptr, top uintptr, size int32) {
  48729 	var j int32
  48730 	_ = j
  48731 	if top != libc.UintptrFromInt32(0) {
  48732 		j = 0
  48733 		for {
  48734 			if !(j < size) {
  48735 				break
  48736 			}
  48737 			libc.Xmemcpy(tls, dst+uintptr(j*int32(BPS)), top, uint64(size))
  48738 			goto _1
  48739 		_1:
  48740 			;
  48741 			j = j + 1
  48742 		}
  48743 	} else {
  48744 		Fill(tls, dst, int32(127), size)
  48745 	}
  48746 }
  48747 
  48748 func HorizontalPred(tls *libc.TLS, dst uintptr, left uintptr, size int32) {
  48749 	var j int32
  48750 	_ = j
  48751 	if left != libc.UintptrFromInt32(0) {
  48752 		j = 0
  48753 		for {
  48754 			if !(j < size) {
  48755 				break
  48756 			}
  48757 			libc.Xmemset(tls, dst+uintptr(j*int32(BPS)), int32(**(**uint8_t)(__ccgo_up(left + uintptr(j)))), uint64(size))
  48758 			goto _1
  48759 		_1:
  48760 			;
  48761 			j = j + 1
  48762 		}
  48763 	} else {
  48764 		Fill(tls, dst, int32(129), size)
  48765 	}
  48766 }
  48767 
  48768 func TrueMotion1(tls *libc.TLS, dst uintptr, left uintptr, top uintptr, size int32) {
  48769 	var clip, clip_table uintptr
  48770 	var x, y int32
  48771 	_, _, _, _ = clip, clip_table, x, y
  48772 	if left != libc.UintptrFromInt32(0) {
  48773 		if top != libc.UintptrFromInt32(0) {
  48774 			clip = uintptr(unsafe.Pointer(&clip12)) + uintptr(255) - uintptr(**(**uint8_t)(__ccgo_up(left + uintptr(-libc.Int32FromInt32(1)))))
  48775 			y = 0
  48776 			for {
  48777 				if !(y < size) {
  48778 					break
  48779 				}
  48780 				clip_table = clip + uintptr(**(**uint8_t)(__ccgo_up(left + uintptr(y))))
  48781 				x = 0
  48782 				for {
  48783 					if !(x < size) {
  48784 						break
  48785 					}
  48786 					**(**uint8_t)(__ccgo_up(dst + uintptr(x))) = **(**uint8_t)(__ccgo_up(clip_table + uintptr(**(**uint8_t)(__ccgo_up(top + uintptr(x))))))
  48787 					goto _2
  48788 				_2:
  48789 					;
  48790 					x = x + 1
  48791 				}
  48792 				dst = dst + uintptr(BPS)
  48793 				goto _1
  48794 			_1:
  48795 				;
  48796 				y = y + 1
  48797 			}
  48798 		} else {
  48799 			HorizontalPred(tls, dst, left, size)
  48800 		}
  48801 	} else {
  48802 		// true motion without left samples (hence: with default 129 value)
  48803 		// is equivalent to VE prediction where you just copy the top samples.
  48804 		// Note that if top samples are not available, the default value is
  48805 		// then 129, and not 127 as in the VerticalPred case.
  48806 		if top != libc.UintptrFromInt32(0) {
  48807 			VerticalPred(tls, dst, top, size)
  48808 		} else {
  48809 			Fill(tls, dst, int32(129), size)
  48810 		}
  48811 	}
  48812 }
  48813 
  48814 func DCMode(tls *libc.TLS, dst uintptr, left uintptr, top uintptr, size int32, round int32, shift int32) {
  48815 	var DC, j int32
  48816 	_, _ = DC, j
  48817 	DC = 0
  48818 	if top != libc.UintptrFromInt32(0) {
  48819 		j = 0
  48820 		for {
  48821 			if !(j < size) {
  48822 				break
  48823 			}
  48824 			DC = DC + int32(**(**uint8_t)(__ccgo_up(top + uintptr(j))))
  48825 			goto _1
  48826 		_1:
  48827 			;
  48828 			j = j + 1
  48829 		}
  48830 		if left != libc.UintptrFromInt32(0) { // top and left present
  48831 			j = 0
  48832 			for {
  48833 				if !(j < size) {
  48834 					break
  48835 				}
  48836 				DC = DC + int32(**(**uint8_t)(__ccgo_up(left + uintptr(j))))
  48837 				goto _2
  48838 			_2:
  48839 				;
  48840 				j = j + 1
  48841 			}
  48842 		} else { // top, but no left
  48843 			DC = DC + DC
  48844 		}
  48845 		DC = (DC + round) >> shift
  48846 	} else {
  48847 		if left != libc.UintptrFromInt32(0) { // left but no top
  48848 			j = 0
  48849 			for {
  48850 				if !(j < size) {
  48851 					break
  48852 				}
  48853 				DC = DC + int32(**(**uint8_t)(__ccgo_up(left + uintptr(j))))
  48854 				goto _3
  48855 			_3:
  48856 				;
  48857 				j = j + 1
  48858 			}
  48859 			DC = DC + DC
  48860 			DC = (DC + round) >> shift
  48861 		} else { // no top, no left, nothing.
  48862 			DC = int32(0x80)
  48863 		}
  48864 	}
  48865 	Fill(tls, dst, DC, size)
  48866 }
  48867 
  48868 //------------------------------------------------------------------------------
  48869 // Chroma 8x8 prediction (paragraph 12.2)
  48870 
  48871 func IntraChromaPreds_C(tls *libc.TLS, dst uintptr, left uintptr, top uintptr) {
  48872 	// U block
  48873 	DCMode(tls, uintptr(libc.Int32FromInt32(2)*libc.Int32FromInt32(16)*libc.Int32FromInt32(BPS))+dst, left, top, int32(8), int32(8), int32(4))
  48874 	VerticalPred(tls, uintptr(libc.Int32FromInt32(2)*libc.Int32FromInt32(16)*libc.Int32FromInt32(BPS)+libc.Int32FromInt32(8)*libc.Int32FromInt32(BPS))+dst, top, int32(8))
  48875 	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))
  48876 	TrueMotion1(tls, uintptr(libc.Int32FromInt32(2)*libc.Int32FromInt32(16)*libc.Int32FromInt32(BPS)+libc.Int32FromInt32(1)*libc.Int32FromInt32(16))+dst, left, top, int32(8))
  48877 	// V block
  48878 	dst = dst + uintptr(8)
  48879 	if top != libc.UintptrFromInt32(0) {
  48880 		top = top + uintptr(8)
  48881 	}
  48882 	if left != libc.UintptrFromInt32(0) {
  48883 		left = left + uintptr(16)
  48884 	}
  48885 	DCMode(tls, uintptr(libc.Int32FromInt32(2)*libc.Int32FromInt32(16)*libc.Int32FromInt32(BPS))+dst, left, top, int32(8), int32(8), int32(4))
  48886 	VerticalPred(tls, uintptr(libc.Int32FromInt32(2)*libc.Int32FromInt32(16)*libc.Int32FromInt32(BPS)+libc.Int32FromInt32(8)*libc.Int32FromInt32(BPS))+dst, top, int32(8))
  48887 	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))
  48888 	TrueMotion1(tls, uintptr(libc.Int32FromInt32(2)*libc.Int32FromInt32(16)*libc.Int32FromInt32(BPS)+libc.Int32FromInt32(1)*libc.Int32FromInt32(16))+dst, left, top, int32(8))
  48889 }
  48890 
  48891 //------------------------------------------------------------------------------
  48892 // luma 16x16 prediction (paragraph 12.3)
  48893 
  48894 func Intra16Preds_C(tls *libc.TLS, dst uintptr, left uintptr, top uintptr) {
  48895 	DCMode(tls, uintptr(libc.Int32FromInt32(0)*libc.Int32FromInt32(16)*libc.Int32FromInt32(BPS))+dst, left, top, int32(16), int32(16), int32(5))
  48896 	VerticalPred(tls, uintptr(libc.Int32FromInt32(1)*libc.Int32FromInt32(16)*libc.Int32FromInt32(BPS))+dst, top, int32(16))
  48897 	HorizontalPred(tls, uintptr(libc.Int32FromInt32(1)*libc.Int32FromInt32(16)*libc.Int32FromInt32(BPS)+libc.Int32FromInt32(16))+dst, left, int32(16))
  48898 	TrueMotion1(tls, uintptr(libc.Int32FromInt32(0)*libc.Int32FromInt32(16)*libc.Int32FromInt32(BPS)+libc.Int32FromInt32(16))+dst, left, top, int32(16))
  48899 }
  48900 
  48901 //------------------------------------------------------------------------------
  48902 // luma 4x4 prediction
  48903 
  48904 // C documentation
  48905 //
  48906 //	// vertical
  48907 func VE4(tls *libc.TLS, dst uintptr, top uintptr) {
  48908 	bp := tls.Alloc(16)
  48909 	defer tls.Free(16)
  48910 	var i int32
  48911 	var _ /* vals at bp+0 */ [4]uint8_t
  48912 	_ = i
  48913 	**(**[4]uint8_t)(__ccgo_up(bp)) = [4]uint8_t{
  48914 		0: uint8((int32(**(**uint8_t)(__ccgo_up(top + uintptr(-libc.Int32FromInt32(1))))) + libc.Int32FromInt32(2)*int32(**(**uint8_t)(__ccgo_up(top))) + int32(**(**uint8_t)(__ccgo_up(top + 1))) + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2)),
  48915 		1: uint8((int32(**(**uint8_t)(__ccgo_up(top))) + libc.Int32FromInt32(2)*int32(**(**uint8_t)(__ccgo_up(top + 1))) + int32(**(**uint8_t)(__ccgo_up(top + 2))) + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2)),
  48916 		2: uint8((int32(**(**uint8_t)(__ccgo_up(top + 1))) + libc.Int32FromInt32(2)*int32(**(**uint8_t)(__ccgo_up(top + 2))) + int32(**(**uint8_t)(__ccgo_up(top + 3))) + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2)),
  48917 		3: uint8((int32(**(**uint8_t)(__ccgo_up(top + 2))) + libc.Int32FromInt32(2)*int32(**(**uint8_t)(__ccgo_up(top + 3))) + int32(**(**uint8_t)(__ccgo_up(top + 4))) + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2)),
  48918 	}
  48919 	i = 0
  48920 	for {
  48921 		if !(i < int32(4)) {
  48922 			break
  48923 		}
  48924 		libc.Xmemcpy(tls, dst+uintptr(i*int32(BPS)), bp, uint64(4))
  48925 		goto _1
  48926 	_1:
  48927 		;
  48928 		i = i + 1
  48929 	}
  48930 }
  48931 
  48932 // C documentation
  48933 //
  48934 //	// horizontal
  48935 func HE4(tls *libc.TLS, dst uintptr, top uintptr) {
  48936 	bp := tls.Alloc(16)
  48937 	defer tls.Free(16)
  48938 	var I, J, K, L, X int32
  48939 	var v1 uint32_t
  48940 	_, _, _, _, _, _ = I, J, K, L, X, v1
  48941 	X = int32(**(**uint8_t)(__ccgo_up(top + uintptr(-libc.Int32FromInt32(1)))))
  48942 	I = int32(**(**uint8_t)(__ccgo_up(top + uintptr(-libc.Int32FromInt32(2)))))
  48943 	J = int32(**(**uint8_t)(__ccgo_up(top + uintptr(-libc.Int32FromInt32(3)))))
  48944 	K = int32(**(**uint8_t)(__ccgo_up(top + uintptr(-libc.Int32FromInt32(4)))))
  48945 	L = int32(**(**uint8_t)(__ccgo_up(top + uintptr(-libc.Int32FromInt32(5)))))
  48946 	v1 = uint32(0x01010101) * uint32(uint8((X+libc.Int32FromInt32(2)*I+J+libc.Int32FromInt32(2))>>libc.Int32FromInt32(2)))
  48947 	*(*uint32_t)(unsafe.Pointer(bp)) = v1
  48948 	libc.Xmemcpy(tls, dst+uintptr(libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)), bp, uint64(4))
  48949 	v1 = uint32(0x01010101) * uint32(uint8((I+libc.Int32FromInt32(2)*J+K+libc.Int32FromInt32(2))>>libc.Int32FromInt32(2)))
  48950 	*(*uint32_t)(unsafe.Pointer(bp)) = v1
  48951 	libc.Xmemcpy(tls, dst+uintptr(libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)), bp, uint64(4))
  48952 	v1 = uint32(0x01010101) * uint32(uint8((J+libc.Int32FromInt32(2)*K+L+libc.Int32FromInt32(2))>>libc.Int32FromInt32(2)))
  48953 	*(*uint32_t)(unsafe.Pointer(bp)) = v1
  48954 	libc.Xmemcpy(tls, dst+uintptr(libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)), bp, uint64(4))
  48955 	v1 = uint32(0x01010101) * uint32(uint8((K+libc.Int32FromInt32(2)*L+L+libc.Int32FromInt32(2))>>libc.Int32FromInt32(2)))
  48956 	*(*uint32_t)(unsafe.Pointer(bp)) = v1
  48957 	libc.Xmemcpy(tls, dst+uintptr(libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)), bp, uint64(4))
  48958 }
  48959 
  48960 func DC4(tls *libc.TLS, dst uintptr, top uintptr) {
  48961 	var dc uint32_t
  48962 	var i int32
  48963 	_, _ = dc, i
  48964 	dc = uint32(4)
  48965 	i = 0
  48966 	for {
  48967 		if !(i < int32(4)) {
  48968 			break
  48969 		}
  48970 		dc = dc + uint32(int32(**(**uint8_t)(__ccgo_up(top + uintptr(i))))+int32(**(**uint8_t)(__ccgo_up(top + uintptr(-int32(5)+i)))))
  48971 		goto _1
  48972 	_1:
  48973 		;
  48974 		i = i + 1
  48975 	}
  48976 	Fill(tls, dst, int32(dc>>int32(3)), int32(4))
  48977 }
  48978 
  48979 func RD4(tls *libc.TLS, dst uintptr, top uintptr) {
  48980 	var A, B, C, D, I, J, K, L, X int32
  48981 	var v1, v2, v3 uint8_t
  48982 	_, _, _, _, _, _, _, _, _, _, _, _ = A, B, C, D, I, J, K, L, X, v1, v2, v3
  48983 	X = int32(**(**uint8_t)(__ccgo_up(top + uintptr(-libc.Int32FromInt32(1)))))
  48984 	I = int32(**(**uint8_t)(__ccgo_up(top + uintptr(-libc.Int32FromInt32(2)))))
  48985 	J = int32(**(**uint8_t)(__ccgo_up(top + uintptr(-libc.Int32FromInt32(3)))))
  48986 	K = int32(**(**uint8_t)(__ccgo_up(top + uintptr(-libc.Int32FromInt32(4)))))
  48987 	L = int32(**(**uint8_t)(__ccgo_up(top + uintptr(-libc.Int32FromInt32(5)))))
  48988 	A = int32(**(**uint8_t)(__ccgo_up(top)))
  48989 	B = int32(**(**uint8_t)(__ccgo_up(top + 1)))
  48990 	C = int32(**(**uint8_t)(__ccgo_up(top + 2)))
  48991 	D = int32(**(**uint8_t)(__ccgo_up(top + 3)))
  48992 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = uint8((J + libc.Int32FromInt32(2)*K + L + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  48993 	v1 = uint8((I + libc.Int32FromInt32(2)*J + K + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  48994 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = v1
  48995 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = v1
  48996 	v2 = uint8((X + libc.Int32FromInt32(2)*I + J + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  48997 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = v2
  48998 	v1 = v2
  48999 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = v1
  49000 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = v1
  49001 	v3 = uint8((A + libc.Int32FromInt32(2)*X + I + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  49002 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = v3
  49003 	v2 = v3
  49004 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = v2
  49005 	v1 = v2
  49006 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = v1
  49007 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = v1
  49008 	v2 = uint8((B + libc.Int32FromInt32(2)*A + X + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  49009 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = v2
  49010 	v1 = v2
  49011 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = v1
  49012 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = v1
  49013 	v1 = uint8((C + libc.Int32FromInt32(2)*B + A + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  49014 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = v1
  49015 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = v1
  49016 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = uint8((D + libc.Int32FromInt32(2)*C + B + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  49017 }
  49018 
  49019 func LD4(tls *libc.TLS, dst uintptr, top uintptr) {
  49020 	var A, B, C, D, E, F, G, H int32
  49021 	var v1, v2, v3 uint8_t
  49022 	_, _, _, _, _, _, _, _, _, _, _ = A, B, C, D, E, F, G, H, v1, v2, v3
  49023 	A = int32(**(**uint8_t)(__ccgo_up(top)))
  49024 	B = int32(**(**uint8_t)(__ccgo_up(top + 1)))
  49025 	C = int32(**(**uint8_t)(__ccgo_up(top + 2)))
  49026 	D = int32(**(**uint8_t)(__ccgo_up(top + 3)))
  49027 	E = int32(**(**uint8_t)(__ccgo_up(top + 4)))
  49028 	F = int32(**(**uint8_t)(__ccgo_up(top + 5)))
  49029 	G = int32(**(**uint8_t)(__ccgo_up(top + 6)))
  49030 	H = int32(**(**uint8_t)(__ccgo_up(top + 7)))
  49031 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = uint8((A + libc.Int32FromInt32(2)*B + C + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  49032 	v1 = uint8((B + libc.Int32FromInt32(2)*C + D + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  49033 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = v1
  49034 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = v1
  49035 	v2 = uint8((C + libc.Int32FromInt32(2)*D + E + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  49036 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = v2
  49037 	v1 = v2
  49038 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = v1
  49039 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = v1
  49040 	v3 = uint8((D + libc.Int32FromInt32(2)*E + F + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  49041 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = v3
  49042 	v2 = v3
  49043 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = v2
  49044 	v1 = v2
  49045 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = v1
  49046 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = v1
  49047 	v2 = uint8((E + libc.Int32FromInt32(2)*F + G + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  49048 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = v2
  49049 	v1 = v2
  49050 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = v1
  49051 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = v1
  49052 	v1 = uint8((F + libc.Int32FromInt32(2)*G + H + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  49053 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = v1
  49054 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = v1
  49055 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = uint8((G + libc.Int32FromInt32(2)*H + H + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  49056 }
  49057 
  49058 func VR4(tls *libc.TLS, dst uintptr, top uintptr) {
  49059 	var A, B, C, D, I, J, K, X int32
  49060 	var v1 uint8_t
  49061 	_, _, _, _, _, _, _, _, _ = A, B, C, D, I, J, K, X, v1
  49062 	X = int32(**(**uint8_t)(__ccgo_up(top + uintptr(-libc.Int32FromInt32(1)))))
  49063 	I = int32(**(**uint8_t)(__ccgo_up(top + uintptr(-libc.Int32FromInt32(2)))))
  49064 	J = int32(**(**uint8_t)(__ccgo_up(top + uintptr(-libc.Int32FromInt32(3)))))
  49065 	K = int32(**(**uint8_t)(__ccgo_up(top + uintptr(-libc.Int32FromInt32(4)))))
  49066 	A = int32(**(**uint8_t)(__ccgo_up(top)))
  49067 	B = int32(**(**uint8_t)(__ccgo_up(top + 1)))
  49068 	C = int32(**(**uint8_t)(__ccgo_up(top + 2)))
  49069 	D = int32(**(**uint8_t)(__ccgo_up(top + 3)))
  49070 	v1 = uint8((X + A + libc.Int32FromInt32(1)) >> libc.Int32FromInt32(1))
  49071 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = v1
  49072 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = v1
  49073 	v1 = uint8((A + B + libc.Int32FromInt32(1)) >> libc.Int32FromInt32(1))
  49074 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = v1
  49075 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = v1
  49076 	v1 = uint8((B + C + libc.Int32FromInt32(1)) >> libc.Int32FromInt32(1))
  49077 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = v1
  49078 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = v1
  49079 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = uint8((C + D + libc.Int32FromInt32(1)) >> libc.Int32FromInt32(1))
  49080 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = uint8((K + libc.Int32FromInt32(2)*J + I + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  49081 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = uint8((J + libc.Int32FromInt32(2)*I + X + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  49082 	v1 = uint8((I + libc.Int32FromInt32(2)*X + A + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  49083 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = v1
  49084 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = v1
  49085 	v1 = uint8((X + libc.Int32FromInt32(2)*A + B + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  49086 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = v1
  49087 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = v1
  49088 	v1 = uint8((A + libc.Int32FromInt32(2)*B + C + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  49089 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = v1
  49090 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = v1
  49091 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = uint8((B + libc.Int32FromInt32(2)*C + D + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  49092 }
  49093 
  49094 func VL4(tls *libc.TLS, dst uintptr, top uintptr) {
  49095 	var A, B, C, D, E, F, G, H int32
  49096 	var v1 uint8_t
  49097 	_, _, _, _, _, _, _, _, _ = A, B, C, D, E, F, G, H, v1
  49098 	A = int32(**(**uint8_t)(__ccgo_up(top)))
  49099 	B = int32(**(**uint8_t)(__ccgo_up(top + 1)))
  49100 	C = int32(**(**uint8_t)(__ccgo_up(top + 2)))
  49101 	D = int32(**(**uint8_t)(__ccgo_up(top + 3)))
  49102 	E = int32(**(**uint8_t)(__ccgo_up(top + 4)))
  49103 	F = int32(**(**uint8_t)(__ccgo_up(top + 5)))
  49104 	G = int32(**(**uint8_t)(__ccgo_up(top + 6)))
  49105 	H = int32(**(**uint8_t)(__ccgo_up(top + 7)))
  49106 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = uint8((A + B + libc.Int32FromInt32(1)) >> libc.Int32FromInt32(1))
  49107 	v1 = uint8((B + C + libc.Int32FromInt32(1)) >> libc.Int32FromInt32(1))
  49108 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = v1
  49109 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = v1
  49110 	v1 = uint8((C + D + libc.Int32FromInt32(1)) >> libc.Int32FromInt32(1))
  49111 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = v1
  49112 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = v1
  49113 	v1 = uint8((D + E + libc.Int32FromInt32(1)) >> libc.Int32FromInt32(1))
  49114 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = v1
  49115 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = v1
  49116 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = uint8((A + libc.Int32FromInt32(2)*B + C + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  49117 	v1 = uint8((B + libc.Int32FromInt32(2)*C + D + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  49118 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = v1
  49119 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = v1
  49120 	v1 = uint8((C + libc.Int32FromInt32(2)*D + E + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  49121 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = v1
  49122 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = v1
  49123 	v1 = uint8((D + libc.Int32FromInt32(2)*E + F + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  49124 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = v1
  49125 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = v1
  49126 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = uint8((E + libc.Int32FromInt32(2)*F + G + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  49127 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = uint8((F + libc.Int32FromInt32(2)*G + H + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  49128 }
  49129 
  49130 func HU4(tls *libc.TLS, dst uintptr, top uintptr) {
  49131 	var I, J, K, L int32
  49132 	var v1, v2, v3, v4, v5 uint8_t
  49133 	_, _, _, _, _, _, _, _, _ = I, J, K, L, v1, v2, v3, v4, v5
  49134 	I = int32(**(**uint8_t)(__ccgo_up(top + uintptr(-libc.Int32FromInt32(2)))))
  49135 	J = int32(**(**uint8_t)(__ccgo_up(top + uintptr(-libc.Int32FromInt32(3)))))
  49136 	K = int32(**(**uint8_t)(__ccgo_up(top + uintptr(-libc.Int32FromInt32(4)))))
  49137 	L = int32(**(**uint8_t)(__ccgo_up(top + uintptr(-libc.Int32FromInt32(5)))))
  49138 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = uint8((I + J + libc.Int32FromInt32(1)) >> libc.Int32FromInt32(1))
  49139 	v1 = uint8((J + K + libc.Int32FromInt32(1)) >> libc.Int32FromInt32(1))
  49140 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = v1
  49141 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = v1
  49142 	v1 = uint8((K + L + libc.Int32FromInt32(1)) >> libc.Int32FromInt32(1))
  49143 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = v1
  49144 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = v1
  49145 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = uint8((I + libc.Int32FromInt32(2)*J + K + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  49146 	v1 = uint8((J + libc.Int32FromInt32(2)*K + L + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  49147 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = v1
  49148 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = v1
  49149 	v1 = uint8((K + libc.Int32FromInt32(2)*L + L + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  49150 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = v1
  49151 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = v1
  49152 	v5 = uint8(L)
  49153 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = v5
  49154 	v4 = v5
  49155 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = v4
  49156 	v3 = v4
  49157 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = v3
  49158 	v2 = v3
  49159 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = v2
  49160 	v1 = v2
  49161 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = v1
  49162 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = v1
  49163 }
  49164 
  49165 func HD4(tls *libc.TLS, dst uintptr, top uintptr) {
  49166 	var A, B, C, I, J, K, L, X int32
  49167 	var v1 uint8_t
  49168 	_, _, _, _, _, _, _, _, _ = A, B, C, I, J, K, L, X, v1
  49169 	X = int32(**(**uint8_t)(__ccgo_up(top + uintptr(-libc.Int32FromInt32(1)))))
  49170 	I = int32(**(**uint8_t)(__ccgo_up(top + uintptr(-libc.Int32FromInt32(2)))))
  49171 	J = int32(**(**uint8_t)(__ccgo_up(top + uintptr(-libc.Int32FromInt32(3)))))
  49172 	K = int32(**(**uint8_t)(__ccgo_up(top + uintptr(-libc.Int32FromInt32(4)))))
  49173 	L = int32(**(**uint8_t)(__ccgo_up(top + uintptr(-libc.Int32FromInt32(5)))))
  49174 	A = int32(**(**uint8_t)(__ccgo_up(top)))
  49175 	B = int32(**(**uint8_t)(__ccgo_up(top + 1)))
  49176 	C = int32(**(**uint8_t)(__ccgo_up(top + 2)))
  49177 	v1 = uint8((I + X + libc.Int32FromInt32(1)) >> libc.Int32FromInt32(1))
  49178 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = v1
  49179 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = v1
  49180 	v1 = uint8((J + I + libc.Int32FromInt32(1)) >> libc.Int32FromInt32(1))
  49181 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = v1
  49182 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = v1
  49183 	v1 = uint8((K + J + libc.Int32FromInt32(1)) >> libc.Int32FromInt32(1))
  49184 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = v1
  49185 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = v1
  49186 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = uint8((L + K + libc.Int32FromInt32(1)) >> libc.Int32FromInt32(1))
  49187 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = uint8((A + libc.Int32FromInt32(2)*B + C + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  49188 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = uint8((X + libc.Int32FromInt32(2)*A + B + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  49189 	v1 = uint8((I + libc.Int32FromInt32(2)*X + A + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  49190 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = v1
  49191 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = v1
  49192 	v1 = uint8((J + libc.Int32FromInt32(2)*I + X + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  49193 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = v1
  49194 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = v1
  49195 	v1 = uint8((K + libc.Int32FromInt32(2)*J + I + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  49196 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = v1
  49197 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = v1
  49198 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = uint8((L + libc.Int32FromInt32(2)*K + J + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  49199 }
  49200 
  49201 func TM4(tls *libc.TLS, dst uintptr, top uintptr) {
  49202 	var clip, clip_table uintptr
  49203 	var x, y int32
  49204 	_, _, _, _ = clip, clip_table, x, y
  49205 	clip = uintptr(unsafe.Pointer(&clip12)) + uintptr(255) - uintptr(**(**uint8_t)(__ccgo_up(top + uintptr(-libc.Int32FromInt32(1)))))
  49206 	y = 0
  49207 	for {
  49208 		if !(y < int32(4)) {
  49209 			break
  49210 		}
  49211 		clip_table = clip + uintptr(**(**uint8_t)(__ccgo_up(top + uintptr(-int32(2)-y))))
  49212 		x = 0
  49213 		for {
  49214 			if !(x < int32(4)) {
  49215 				break
  49216 			}
  49217 			**(**uint8_t)(__ccgo_up(dst + uintptr(x))) = **(**uint8_t)(__ccgo_up(clip_table + uintptr(**(**uint8_t)(__ccgo_up(top + uintptr(x))))))
  49218 			goto _2
  49219 		_2:
  49220 			;
  49221 			x = x + 1
  49222 		}
  49223 		dst = dst + uintptr(BPS)
  49224 		goto _1
  49225 	_1:
  49226 		;
  49227 		y = y + 1
  49228 	}
  49229 }
  49230 
  49231 // C documentation
  49232 //
  49233 //	// Left samples are top[-5 .. -2], top_left is top[-1], top are
  49234 //	// located at top[0..3], and top right is top[4..7]
  49235 func Intra4Preds_C(tls *libc.TLS, dst uintptr, top uintptr) {
  49236 	DC4(tls, uintptr(libc.Int32FromInt32(3)*libc.Int32FromInt32(16)*libc.Int32FromInt32(BPS)+libc.Int32FromInt32(0))+dst, top)
  49237 	TM4(tls, uintptr(libc.Int32FromInt32(3)*libc.Int32FromInt32(16)*libc.Int32FromInt32(BPS)+libc.Int32FromInt32(0)+libc.Int32FromInt32(4))+dst, top)
  49238 	VE4(tls, uintptr(libc.Int32FromInt32(3)*libc.Int32FromInt32(16)*libc.Int32FromInt32(BPS)+libc.Int32FromInt32(0)+libc.Int32FromInt32(8))+dst, top)
  49239 	HE4(tls, uintptr(libc.Int32FromInt32(3)*libc.Int32FromInt32(16)*libc.Int32FromInt32(BPS)+libc.Int32FromInt32(0)+libc.Int32FromInt32(12))+dst, top)
  49240 	RD4(tls, uintptr(libc.Int32FromInt32(3)*libc.Int32FromInt32(16)*libc.Int32FromInt32(BPS)+libc.Int32FromInt32(0)+libc.Int32FromInt32(16))+dst, top)
  49241 	VR4(tls, uintptr(libc.Int32FromInt32(3)*libc.Int32FromInt32(16)*libc.Int32FromInt32(BPS)+libc.Int32FromInt32(0)+libc.Int32FromInt32(20))+dst, top)
  49242 	LD4(tls, uintptr(libc.Int32FromInt32(3)*libc.Int32FromInt32(16)*libc.Int32FromInt32(BPS)+libc.Int32FromInt32(0)+libc.Int32FromInt32(24))+dst, top)
  49243 	VL4(tls, uintptr(libc.Int32FromInt32(3)*libc.Int32FromInt32(16)*libc.Int32FromInt32(BPS)+libc.Int32FromInt32(0)+libc.Int32FromInt32(28))+dst, top)
  49244 	HD4(tls, uintptr(libc.Int32FromInt32(3)*libc.Int32FromInt32(16)*libc.Int32FromInt32(BPS)+libc.Int32FromInt32(4)*libc.Int32FromInt32(BPS))+dst, top)
  49245 	HU4(tls, uintptr(libc.Int32FromInt32(3)*libc.Int32FromInt32(16)*libc.Int32FromInt32(BPS)+libc.Int32FromInt32(4)*libc.Int32FromInt32(BPS)+libc.Int32FromInt32(4))+dst, top)
  49246 }
  49247 
  49248 //------------------------------------------------------------------------------
  49249 // Metric
  49250 
  49251 func GetSSE(tls *libc.TLS, a uintptr, b uintptr, w int32, h int32) (r int32) {
  49252 	var count, diff, x, y int32
  49253 	_, _, _, _ = count, diff, x, y
  49254 	count = 0
  49255 	y = 0
  49256 	for {
  49257 		if !(y < h) {
  49258 			break
  49259 		}
  49260 		x = 0
  49261 		for {
  49262 			if !(x < w) {
  49263 				break
  49264 			}
  49265 			diff = int32(**(**uint8_t)(__ccgo_up(a + uintptr(x)))) - int32(**(**uint8_t)(__ccgo_up(b + uintptr(x))))
  49266 			count = count + diff*diff
  49267 			goto _2
  49268 		_2:
  49269 			;
  49270 			x = x + 1
  49271 		}
  49272 		a = a + uintptr(BPS)
  49273 		b = b + uintptr(BPS)
  49274 		goto _1
  49275 	_1:
  49276 		;
  49277 		y = y + 1
  49278 	}
  49279 	return count
  49280 }
  49281 
  49282 func SSE16x16_C(tls *libc.TLS, a uintptr, b uintptr) (r int32) {
  49283 	return GetSSE(tls, a, b, int32(16), int32(16))
  49284 }
  49285 
  49286 func SSE16x8_C(tls *libc.TLS, a uintptr, b uintptr) (r int32) {
  49287 	return GetSSE(tls, a, b, int32(16), int32(8))
  49288 }
  49289 
  49290 func SSE8x8_C(tls *libc.TLS, a uintptr, b uintptr) (r int32) {
  49291 	return GetSSE(tls, a, b, int32(8), int32(8))
  49292 }
  49293 
  49294 func SSE4x4_C(tls *libc.TLS, a uintptr, b uintptr) (r int32) {
  49295 	return GetSSE(tls, a, b, int32(4), int32(4))
  49296 }
  49297 
  49298 func Mean16x4_C(tls *libc.TLS, ref uintptr, dc uintptr) {
  49299 	var avg uint32_t
  49300 	var k, x, y int32
  49301 	_, _, _, _ = avg, k, x, y
  49302 	k = 0
  49303 	for {
  49304 		if !(k < int32(4)) {
  49305 			break
  49306 		}
  49307 		avg = uint32(0)
  49308 		y = 0
  49309 		for {
  49310 			if !(y < int32(4)) {
  49311 				break
  49312 			}
  49313 			x = 0
  49314 			for {
  49315 				if !(x < int32(4)) {
  49316 					break
  49317 				}
  49318 				avg = avg + uint32(**(**uint8_t)(__ccgo_up(ref + uintptr(x+y*int32(BPS)))))
  49319 				goto _3
  49320 			_3:
  49321 				;
  49322 				x = x + 1
  49323 			}
  49324 			goto _2
  49325 		_2:
  49326 			;
  49327 			y = y + 1
  49328 		}
  49329 		**(**uint32_t)(__ccgo_up(dc + uintptr(k)*4)) = avg
  49330 		ref = ref + uintptr(4) // go to next 4x4 block.
  49331 		goto _1
  49332 	_1:
  49333 		;
  49334 		k = k + 1
  49335 	}
  49336 }
  49337 
  49338 //------------------------------------------------------------------------------
  49339 // Texture distortion
  49340 //
  49341 // We try to match the spectral content (weighted) between source and
  49342 // reconstructed samples.
  49343 
  49344 // C documentation
  49345 //
  49346 //	// Hadamard transform
  49347 //	// Returns the weighted sum of the absolute value of transformed coefficients.
  49348 //	// w[] contains a row-major 4 by 4 symmetric matrix.
  49349 func TTransform(tls *libc.TLS, in uintptr, w uintptr) (r int32) {
  49350 	var a0, a01, a1, a11, a2, a21, a3, a31, b0, b1, b2, b3, i, sum int32
  49351 	var tmp [16]int32
  49352 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = a0, a01, a1, a11, a2, a21, a3, a31, b0, b1, b2, b3, i, sum, tmp
  49353 	sum = 0
  49354 	// horizontal pass
  49355 	i = 0
  49356 	for {
  49357 		if !(i < int32(4)) {
  49358 			break
  49359 		}
  49360 		a0 = int32(**(**uint8_t)(__ccgo_up(in))) + int32(**(**uint8_t)(__ccgo_up(in + 2)))
  49361 		a1 = int32(**(**uint8_t)(__ccgo_up(in + 1))) + int32(**(**uint8_t)(__ccgo_up(in + 3)))
  49362 		a2 = int32(**(**uint8_t)(__ccgo_up(in + 1))) - int32(**(**uint8_t)(__ccgo_up(in + 3)))
  49363 		a3 = int32(**(**uint8_t)(__ccgo_up(in))) - int32(**(**uint8_t)(__ccgo_up(in + 2)))
  49364 		tmp[0+i*int32(4)] = a0 + a1
  49365 		tmp[int32(1)+i*int32(4)] = a3 + a2
  49366 		tmp[int32(2)+i*int32(4)] = a3 - a2
  49367 		tmp[int32(3)+i*int32(4)] = a0 - a1
  49368 		goto _1
  49369 	_1:
  49370 		;
  49371 		i = i + 1
  49372 		in = in + uintptr(BPS)
  49373 	}
  49374 	// vertical pass
  49375 	i = 0
  49376 	for {
  49377 		if !(i < int32(4)) {
  49378 			break
  49379 		}
  49380 		a01 = tmp[0+i] + tmp[int32(8)+i]
  49381 		a11 = tmp[int32(4)+i] + tmp[int32(12)+i]
  49382 		a21 = tmp[int32(4)+i] - tmp[int32(12)+i]
  49383 		a31 = tmp[0+i] - tmp[int32(8)+i]
  49384 		b0 = a01 + a11
  49385 		b1 = a31 + a21
  49386 		b2 = a31 - a21
  49387 		b3 = a01 - a11
  49388 		sum = sum + int32(**(**uint16_t)(__ccgo_up(w)))*libc.Xabs(tls, b0)
  49389 		sum = sum + int32(**(**uint16_t)(__ccgo_up(w + 4*2)))*libc.Xabs(tls, b1)
  49390 		sum = sum + int32(**(**uint16_t)(__ccgo_up(w + 8*2)))*libc.Xabs(tls, b2)
  49391 		sum = sum + int32(**(**uint16_t)(__ccgo_up(w + 12*2)))*libc.Xabs(tls, b3)
  49392 		goto _2
  49393 	_2:
  49394 		;
  49395 		i = i + 1
  49396 		w += 2
  49397 	}
  49398 	return sum
  49399 }
  49400 
  49401 func Disto4x4_C(tls *libc.TLS, a uintptr, b uintptr, w uintptr) (r int32) {
  49402 	var sum1, sum2 int32
  49403 	_, _ = sum1, sum2
  49404 	sum1 = TTransform(tls, a, w)
  49405 	sum2 = TTransform(tls, b, w)
  49406 	return libc.Xabs(tls, sum2-sum1) >> int32(5)
  49407 }
  49408 
  49409 func Disto16x16_C(tls *libc.TLS, a uintptr, b uintptr, w uintptr) (r int32) {
  49410 	var D, x, y int32
  49411 	_, _, _ = D, x, y
  49412 	D = 0
  49413 	y = 0
  49414 	for {
  49415 		if !(y < libc.Int32FromInt32(16)*libc.Int32FromInt32(BPS)) {
  49416 			break
  49417 		}
  49418 		x = 0
  49419 		for {
  49420 			if !(x < int32(16)) {
  49421 				break
  49422 			}
  49423 			D = D + Disto4x4_C(tls, a+uintptr(x)+uintptr(y), b+uintptr(x)+uintptr(y), w)
  49424 			goto _2
  49425 		_2:
  49426 			;
  49427 			x = x + int32(4)
  49428 		}
  49429 		goto _1
  49430 	_1:
  49431 		;
  49432 		y = y + libc.Int32FromInt32(4)*libc.Int32FromInt32(BPS)
  49433 	}
  49434 	return D
  49435 }
  49436 
  49437 //------------------------------------------------------------------------------
  49438 // Quantization
  49439 //
  49440 
  49441 var kZigzag2 = [16]uint8_t{
  49442 	1:  uint8(1),
  49443 	2:  uint8(4),
  49444 	3:  uint8(8),
  49445 	4:  uint8(5),
  49446 	5:  uint8(2),
  49447 	6:  uint8(3),
  49448 	7:  uint8(6),
  49449 	8:  uint8(9),
  49450 	9:  uint8(12),
  49451 	10: uint8(13),
  49452 	11: uint8(10),
  49453 	12: uint8(7),
  49454 	13: uint8(11),
  49455 	14: uint8(14),
  49456 	15: uint8(15),
  49457 }
  49458 
  49459 // C documentation
  49460 //
  49461 //	// Simple quantization
  49462 func QuantizeBlock_C(tls *libc.TLS, in uintptr, out uintptr, mtx uintptr) (r int32) {
  49463 	var B1, Q, coeff, iQ1 uint32_t
  49464 	var j, last, level, n1, sign, v2, v3 int32
  49465 	_, _, _, _, _, _, _, _, _, _, _ = B1, Q, coeff, iQ1, j, last, level, n1, sign, v2, v3
  49466 	last = -int32(1)
  49467 	n1 = 0
  49468 	for {
  49469 		if !(n1 < int32(16)) {
  49470 			break
  49471 		}
  49472 		j = int32(kZigzag2[n1])
  49473 		sign = libc.BoolInt32(int32(**(**int16_t)(__ccgo_up(in + uintptr(j)*2))) < libc.Int32FromInt32(0))
  49474 		if sign != 0 {
  49475 			v2 = -int32(**(**int16_t)(__ccgo_up(in + uintptr(j)*2)))
  49476 		} else {
  49477 			v2 = int32(**(**int16_t)(__ccgo_up(in + uintptr(j)*2)))
  49478 		}
  49479 		coeff = uint32(v2 + int32(**(**uint16_t)(__ccgo_up(mtx + 192 + uintptr(j)*2))))
  49480 		if coeff > **(**uint32_t)(__ccgo_up(mtx + 128 + uintptr(j)*4)) {
  49481 			Q = uint32(**(**uint16_t)(__ccgo_up(mtx + uintptr(j)*2)))
  49482 			iQ1 = uint32(**(**uint16_t)(__ccgo_up(mtx + 32 + uintptr(j)*2)))
  49483 			B1 = **(**uint32_t)(__ccgo_up(mtx + 64 + uintptr(j)*4))
  49484 			v3 = int32((coeff*iQ1 + B1) >> libc.Int32FromInt32(QFIX))
  49485 			goto _4
  49486 		_4:
  49487 			level = v3
  49488 			if level > int32(MAX_LEVEL) {
  49489 				level = int32(MAX_LEVEL)
  49490 			}
  49491 			if sign != 0 {
  49492 				level = -level
  49493 			}
  49494 			**(**int16_t)(__ccgo_up(in + uintptr(j)*2)) = int16(level * int32(Q))
  49495 			**(**int16_t)(__ccgo_up(out + uintptr(n1)*2)) = int16(level)
  49496 			if level != 0 {
  49497 				last = n1
  49498 			}
  49499 		} else {
  49500 			**(**int16_t)(__ccgo_up(out + uintptr(n1)*2)) = 0
  49501 			**(**int16_t)(__ccgo_up(in + uintptr(j)*2)) = 0
  49502 		}
  49503 		goto _1
  49504 	_1:
  49505 		;
  49506 		n1 = n1 + 1
  49507 	}
  49508 	return libc.BoolInt32(last >= 0)
  49509 }
  49510 
  49511 func Quantize2Blocks_C(tls *libc.TLS, in uintptr, out uintptr, mtx uintptr) (r int32) {
  49512 	var nz int32
  49513 	_ = nz
  49514 	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
  49515 	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)
  49516 	return nz
  49517 }
  49518 
  49519 //------------------------------------------------------------------------------
  49520 // Block copy
  49521 
  49522 func Copy(tls *libc.TLS, src uintptr, dst uintptr, w int32, h int32) {
  49523 	var y int32
  49524 	_ = y
  49525 	y = 0
  49526 	for {
  49527 		if !(y < h) {
  49528 			break
  49529 		}
  49530 		libc.Xmemcpy(tls, dst, src, uint64(w))
  49531 		src = src + uintptr(BPS)
  49532 		dst = dst + uintptr(BPS)
  49533 		goto _1
  49534 	_1:
  49535 		;
  49536 		y = y + 1
  49537 	}
  49538 }
  49539 
  49540 func Copy4x4_C(tls *libc.TLS, src uintptr, dst uintptr) {
  49541 	Copy(tls, src, dst, int32(4), int32(4))
  49542 }
  49543 
  49544 func Copy16x8_C(tls *libc.TLS, src uintptr, dst uintptr) {
  49545 	Copy(tls, src, dst, int32(16), int32(8))
  49546 }
  49547 
  49548 func VP8EncDspInit(tls *libc.TLS) {
  49549 	if libc.AtomicLoadPUintptr(uintptr(unsafe.Pointer(&VP8EncDspInit_body_last_cpuinfo_used))) == VP8GetCPUInfo {
  49550 		goto _1
  49551 	}
  49552 	VP8EncDspInit_body(tls)
  49553 	libc.AtomicStorePUintptr(uintptr(unsafe.Pointer(&VP8EncDspInit_body_last_cpuinfo_used)), VP8GetCPUInfo)
  49554 	goto _2
  49555 _2:
  49556 	;
  49557 	goto _1
  49558 _1: /**/ //
  49559 }
  49560 
  49561 var VP8EncDspInit_body_last_cpuinfo_used = uintptr(0)
  49562 
  49563 func init() {
  49564 	p := unsafe.Pointer(&VP8EncDspInit_body_last_cpuinfo_used)
  49565 	*(*uintptr)(unsafe.Add(p, 0)) = uintptr(unsafe.Pointer(&VP8EncDspInit_body_last_cpuinfo_used))
  49566 }
  49567 
  49568 func VP8EncDspInit_body(tls *libc.TLS) {
  49569 	VP8DspInit(tls) // common inverse transforms
  49570 	InitTables(tls)
  49571 	// default C implementations
  49572 	VP8ITransform = __ccgo_fp(ITransform_C)
  49573 	VP8FTransform = __ccgo_fp(FTransform_C)
  49574 	VP8FTransformWHT = __ccgo_fp(FTransformWHT_C)
  49575 	VP8TDisto4x4 = __ccgo_fp(Disto4x4_C)
  49576 	VP8TDisto16x16 = __ccgo_fp(Disto16x16_C)
  49577 	VP8CollectHistogram = __ccgo_fp(CollectHistogram_C)
  49578 	VP8SSE16x16 = __ccgo_fp(SSE16x16_C)
  49579 	VP8SSE16x8 = __ccgo_fp(SSE16x8_C)
  49580 	VP8SSE8x8 = __ccgo_fp(SSE8x8_C)
  49581 	VP8SSE4x4 = __ccgo_fp(SSE4x4_C)
  49582 	VP8EncQuantizeBlock = __ccgo_fp(QuantizeBlock_C)
  49583 	VP8EncQuantize2Blocks = __ccgo_fp(Quantize2Blocks_C)
  49584 	VP8EncQuantizeBlockWHT = __ccgo_fp(QuantizeBlock_C)
  49585 	VP8EncPredLuma4 = __ccgo_fp(Intra4Preds_C)
  49586 	VP8EncPredLuma16 = __ccgo_fp(Intra16Preds_C)
  49587 	VP8FTransform2 = __ccgo_fp(FTransform2_C)
  49588 	VP8EncPredChroma8 = __ccgo_fp(IntraChromaPreds_C)
  49589 	VP8Mean16x4 = __ccgo_fp(Mean16x4_C)
  49590 	VP8Copy4x4 = __ccgo_fp(Copy4x4_C)
  49591 	VP8Copy16x8 = __ccgo_fp(Copy16x8_C)
  49592 	// If defined, use CPUInfo() to overwrite some pointers with faster versions.
  49593 	if VP8GetCPUInfo != libc.UintptrFromInt32(0) {
  49594 	}
  49595 }
  49596 
  49597 const SIZE_MAX25 = "UINT64_MAX"
  49598 
  49599 func VP8EncDspInitMIPS32(tls *libc.TLS) {
  49600 }
  49601 
  49602 func VP8EncDspInitMIPSdspR2(tls *libc.TLS) {
  49603 }
  49604 
  49605 func VP8EncDspInitMSA(tls *libc.TLS) {
  49606 }
  49607 
  49608 func VP8EncDspInitNEON(tls *libc.TLS) {
  49609 }
  49610 
  49611 func VP8EncDspInitSSE2(tls *libc.TLS) {
  49612 }
  49613 
  49614 func VP8EncDspInitSSE41(tls *libc.TLS) {
  49615 }
  49616 
  49617 const SIZE_MAX26 = "_UI64_MAX"
  49618 
  49619 // Copyright 2010 Google Inc. All Rights Reserved.
  49620 //
  49621 // Use of this source code is governed by a BSD-style license
  49622 // that can be found in the COPYING file in the root of the source
  49623 // tree. An additional intellectual property rights grant can be found
  49624 // in the file PATENTS. All contributing project authors may
  49625 // be found in the AUTHORS file in the root of the source tree.
  49626 // -----------------------------------------------------------------------------
  49627 //
  49628 //  Common types + memory wrappers
  49629 //
  49630 // Author: Skal (pascal.massimino@gmail.com)
  49631 
  49632 //------------------------------------------------------------------------------
  49633 // Helpful macro.
  49634 
  49635 func PredictLine_C(tls *libc.TLS, src uintptr, pred uintptr, dst uintptr, length int32) {
  49636 	var i int32
  49637 	_ = i
  49638 	i = 0
  49639 	for {
  49640 		if !(i < length) {
  49641 			break
  49642 		}
  49643 		**(**uint8_t)(__ccgo_up(dst + uintptr(i))) = uint8(int32(**(**uint8_t)(__ccgo_up(src + uintptr(i)))) - int32(**(**uint8_t)(__ccgo_up(pred + uintptr(i)))))
  49644 		goto _1
  49645 	_1:
  49646 		;
  49647 		i = i + 1
  49648 	}
  49649 }
  49650 
  49651 //------------------------------------------------------------------------------
  49652 // Horizontal filter.
  49653 
  49654 func DoHorizontalFilter_C(tls *libc.TLS, in uintptr, width int32, height int32, stride int32, out uintptr) {
  49655 	var preds uintptr
  49656 	var row int32
  49657 	_, _ = preds, row
  49658 	preds = in
  49659 	// Leftmost pixel is the same as input for topmost scanline.
  49660 	**(**uint8_t)(__ccgo_up(out)) = **(**uint8_t)(__ccgo_up(in))
  49661 	PredictLine_C(tls, in+uintptr(1), preds, out+uintptr(1), width-int32(1))
  49662 	preds = preds + uintptr(stride)
  49663 	in = in + uintptr(stride)
  49664 	out = out + uintptr(stride)
  49665 	// Filter line-by-line.
  49666 	row = int32(1)
  49667 	for {
  49668 		if !(row < height) {
  49669 			break
  49670 		}
  49671 		// Leftmost pixel is predicted from above.
  49672 		PredictLine_C(tls, in, preds-uintptr(stride), out, int32(1))
  49673 		PredictLine_C(tls, in+uintptr(1), preds, out+uintptr(1), width-int32(1))
  49674 		preds = preds + uintptr(stride)
  49675 		in = in + uintptr(stride)
  49676 		out = out + uintptr(stride)
  49677 		goto _1
  49678 	_1:
  49679 		;
  49680 		row = row + 1
  49681 	}
  49682 }
  49683 
  49684 //------------------------------------------------------------------------------
  49685 // Vertical filter.
  49686 
  49687 func DoVerticalFilter_C(tls *libc.TLS, in uintptr, width int32, height int32, stride int32, out uintptr) {
  49688 	var preds uintptr
  49689 	var row int32
  49690 	_, _ = preds, row
  49691 	preds = in
  49692 	// Very first top-left pixel is copied.
  49693 	**(**uint8_t)(__ccgo_up(out)) = **(**uint8_t)(__ccgo_up(in))
  49694 	// Rest of top scan-line is left-predicted.
  49695 	PredictLine_C(tls, in+uintptr(1), preds, out+uintptr(1), width-int32(1))
  49696 	in = in + uintptr(stride)
  49697 	out = out + uintptr(stride)
  49698 	// Filter line-by-line.
  49699 	row = int32(1)
  49700 	for {
  49701 		if !(row < height) {
  49702 			break
  49703 		}
  49704 		PredictLine_C(tls, in, preds, out, width)
  49705 		preds = preds + uintptr(stride)
  49706 		in = in + uintptr(stride)
  49707 		out = out + uintptr(stride)
  49708 		goto _1
  49709 	_1:
  49710 		;
  49711 		row = row + 1
  49712 	}
  49713 }
  49714 
  49715 //------------------------------------------------------------------------------
  49716 // Gradient filter.
  49717 
  49718 func GradientPredictor_C(tls *libc.TLS, a uint8_t, b uint8_t, c uint8_t) (r int32) {
  49719 	var g, v1, v2 int32
  49720 	_, _, _ = g, v1, v2
  49721 	g = int32(a) + int32(b) - int32(c)
  49722 	if g & ^libc.Int32FromInt32(0xff) == 0 {
  49723 		v1 = g
  49724 	} else {
  49725 		if g < 0 {
  49726 			v2 = 0
  49727 		} else {
  49728 			v2 = int32(255)
  49729 		}
  49730 		v1 = v2
  49731 	}
  49732 	return v1 // clip to 8bit
  49733 }
  49734 
  49735 func DoGradientFilter_C(tls *libc.TLS, in uintptr, width int32, height int32, stride int32, out uintptr) {
  49736 	var pred, row, w int32
  49737 	var preds uintptr
  49738 	_, _, _, _ = pred, preds, row, w
  49739 	preds = in
  49740 	// left prediction for top scan-line
  49741 	**(**uint8_t)(__ccgo_up(out)) = **(**uint8_t)(__ccgo_up(in))
  49742 	PredictLine_C(tls, in+uintptr(1), preds, out+uintptr(1), width-int32(1))
  49743 	preds = preds + uintptr(stride)
  49744 	in = in + uintptr(stride)
  49745 	out = out + uintptr(stride)
  49746 	// Filter line-by-line.
  49747 	row = int32(1)
  49748 	for {
  49749 		if !(row < height) {
  49750 			break
  49751 		}
  49752 		// leftmost pixel: predict from above.
  49753 		PredictLine_C(tls, in, preds-uintptr(stride), out, int32(1))
  49754 		w = int32(1)
  49755 		for {
  49756 			if !(w < width) {
  49757 				break
  49758 			}
  49759 			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)))))
  49760 			**(**uint8_t)(__ccgo_up(out + uintptr(w))) = uint8(int32(**(**uint8_t)(__ccgo_up(in + uintptr(w)))) - pred)
  49761 			goto _2
  49762 		_2:
  49763 			;
  49764 			w = w + 1
  49765 		}
  49766 		preds = preds + uintptr(stride)
  49767 		in = in + uintptr(stride)
  49768 		out = out + uintptr(stride)
  49769 		goto _1
  49770 	_1:
  49771 		;
  49772 		row = row + 1
  49773 	}
  49774 }
  49775 
  49776 //------------------------------------------------------------------------------
  49777 
  49778 func HorizontalFilter_C(tls *libc.TLS, data uintptr, width int32, height int32, stride int32, filtered_data uintptr) {
  49779 	DoHorizontalFilter_C(tls, data, width, height, stride, filtered_data)
  49780 }
  49781 
  49782 func VerticalFilter_C(tls *libc.TLS, data uintptr, width int32, height int32, stride int32, filtered_data uintptr) {
  49783 	DoVerticalFilter_C(tls, data, width, height, stride, filtered_data)
  49784 }
  49785 
  49786 func GradientFilter_C(tls *libc.TLS, data uintptr, width int32, height int32, stride int32, filtered_data uintptr) {
  49787 	DoGradientFilter_C(tls, data, width, height, stride, filtered_data)
  49788 }
  49789 
  49790 //------------------------------------------------------------------------------
  49791 
  49792 func NoneUnfilter_C(tls *libc.TLS, prev uintptr, in uintptr, out uintptr, width int32) {
  49793 	_ = prev
  49794 	if out != in {
  49795 		libc.Xmemcpy(tls, out, in, uint64(width)*uint64(1))
  49796 	}
  49797 }
  49798 
  49799 func HorizontalUnfilter_C(tls *libc.TLS, prev uintptr, in uintptr, out uintptr, width int32) {
  49800 	var i, v1 int32
  49801 	var pred uint8_t
  49802 	_, _, _ = i, pred, v1
  49803 	if prev == libc.UintptrFromInt32(0) {
  49804 		v1 = 0
  49805 	} else {
  49806 		v1 = int32(**(**uint8_t)(__ccgo_up(prev)))
  49807 	}
  49808 	pred = uint8(v1)
  49809 	i = 0
  49810 	for {
  49811 		if !(i < width) {
  49812 			break
  49813 		}
  49814 		**(**uint8_t)(__ccgo_up(out + uintptr(i))) = uint8(int32(pred) + int32(**(**uint8_t)(__ccgo_up(in + uintptr(i)))))
  49815 		pred = **(**uint8_t)(__ccgo_up(out + uintptr(i)))
  49816 		goto _2
  49817 	_2:
  49818 		;
  49819 		i = i + 1
  49820 	}
  49821 }
  49822 
  49823 func VerticalUnfilter_C(tls *libc.TLS, prev uintptr, in uintptr, out uintptr, width int32) {
  49824 	var i int32
  49825 	_ = i
  49826 	if prev == libc.UintptrFromInt32(0) {
  49827 		HorizontalUnfilter_C(tls, libc.UintptrFromInt32(0), in, out, width)
  49828 	} else {
  49829 		i = 0
  49830 		for {
  49831 			if !(i < width) {
  49832 				break
  49833 			}
  49834 			**(**uint8_t)(__ccgo_up(out + uintptr(i))) = uint8(int32(**(**uint8_t)(__ccgo_up(prev + uintptr(i)))) + int32(**(**uint8_t)(__ccgo_up(in + uintptr(i)))))
  49835 			goto _1
  49836 		_1:
  49837 			;
  49838 			i = i + 1
  49839 		}
  49840 	}
  49841 }
  49842 
  49843 func GradientUnfilter_C(tls *libc.TLS, prev uintptr, in uintptr, out uintptr, width int32) {
  49844 	var i int32
  49845 	var left, top, top_left uint8_t
  49846 	_, _, _, _ = i, left, top, top_left
  49847 	if prev == libc.UintptrFromInt32(0) {
  49848 		HorizontalUnfilter_C(tls, libc.UintptrFromInt32(0), in, out, width)
  49849 	} else {
  49850 		top = **(**uint8_t)(__ccgo_up(prev))
  49851 		top_left = top
  49852 		left = top
  49853 		i = 0
  49854 		for {
  49855 			if !(i < width) {
  49856 				break
  49857 			}
  49858 			top = **(**uint8_t)(__ccgo_up(prev + uintptr(i))) // need to read this first, in case prev==out
  49859 			left = uint8(int32(**(**uint8_t)(__ccgo_up(in + uintptr(i)))) + GradientPredictor_C(tls, left, top, top_left))
  49860 			top_left = top
  49861 			**(**uint8_t)(__ccgo_up(out + uintptr(i))) = left
  49862 			goto _1
  49863 		_1:
  49864 			;
  49865 			i = i + 1
  49866 		}
  49867 	}
  49868 }
  49869 
  49870 func VP8FiltersInit(tls *libc.TLS) {
  49871 	if libc.AtomicLoadPUintptr(uintptr(unsafe.Pointer(&VP8FiltersInit_body_last_cpuinfo_used))) == VP8GetCPUInfo {
  49872 		goto _1
  49873 	}
  49874 	VP8FiltersInit_body(tls)
  49875 	libc.AtomicStorePUintptr(uintptr(unsafe.Pointer(&VP8FiltersInit_body_last_cpuinfo_used)), VP8GetCPUInfo)
  49876 	goto _2
  49877 _2:
  49878 	;
  49879 	goto _1
  49880 _1: /**/ //
  49881 }
  49882 
  49883 var VP8FiltersInit_body_last_cpuinfo_used = uintptr(0)
  49884 
  49885 func init() {
  49886 	p := unsafe.Pointer(&VP8FiltersInit_body_last_cpuinfo_used)
  49887 	*(*uintptr)(unsafe.Add(p, 0)) = uintptr(unsafe.Pointer(&VP8FiltersInit_body_last_cpuinfo_used))
  49888 }
  49889 
  49890 func VP8FiltersInit_body(tls *libc.TLS) {
  49891 	WebPUnfilters[int32(WEBP_FILTER_NONE)] = __ccgo_fp(NoneUnfilter_C)
  49892 	WebPUnfilters[int32(WEBP_FILTER_HORIZONTAL)] = __ccgo_fp(HorizontalUnfilter_C)
  49893 	WebPUnfilters[int32(WEBP_FILTER_VERTICAL)] = __ccgo_fp(VerticalUnfilter_C)
  49894 	WebPUnfilters[int32(WEBP_FILTER_GRADIENT)] = __ccgo_fp(GradientUnfilter_C)
  49895 	WebPFilters[int32(WEBP_FILTER_NONE)] = libc.UintptrFromInt32(0)
  49896 	WebPFilters[int32(WEBP_FILTER_HORIZONTAL)] = __ccgo_fp(HorizontalFilter_C)
  49897 	WebPFilters[int32(WEBP_FILTER_VERTICAL)] = __ccgo_fp(VerticalFilter_C)
  49898 	WebPFilters[int32(WEBP_FILTER_GRADIENT)] = __ccgo_fp(GradientFilter_C)
  49899 	if VP8GetCPUInfo != libc.UintptrFromInt32(0) {
  49900 	}
  49901 }
  49902 
  49903 const SIZE_MAX27 = "UINT64_MAX"
  49904 
  49905 func VP8FiltersInitMIPSdspR2(tls *libc.TLS) {
  49906 }
  49907 
  49908 func VP8FiltersInitMSA(tls *libc.TLS) {
  49909 }
  49910 
  49911 func VP8FiltersInitNEON(tls *libc.TLS) {
  49912 }
  49913 
  49914 func VP8FiltersInitSSE2(tls *libc.TLS) {
  49915 }
  49916 
  49917 func VP8LDspInitAVX2(tls *libc.TLS) {
  49918 }
  49919 
  49920 const ARGB_BLACK3 = 4278190080
  49921 
  49922 var kHashMul15 = uint32(0x1e35a7bd)
  49923 
  49924 // Copyright 2012 Google Inc. All Rights Reserved.
  49925 //
  49926 // Use of this source code is governed by a BSD-style license
  49927 // that can be found in the COPYING file in the root of the source
  49928 // tree. An additional intellectual property rights grant can be found
  49929 // in the file PATENTS. All contributing project authors may
  49930 // be found in the AUTHORS file in the root of the source tree.
  49931 // -----------------------------------------------------------------------------
  49932 //
  49933 // Misc. common utility functions
  49934 //
  49935 // Authors: Skal (pascal.massimino@gmail.com)
  49936 //          Urvang (urvang@google.com)
  49937 
  49938 // Copyright 2010 Google Inc. All Rights Reserved.
  49939 //
  49940 // Use of this source code is governed by a BSD-style license
  49941 // that can be found in the COPYING file in the root of the source
  49942 // tree. An additional intellectual property rights grant can be found
  49943 // in the file PATENTS. All contributing project authors may
  49944 // be found in the AUTHORS file in the root of the source tree.
  49945 // -----------------------------------------------------------------------------
  49946 //
  49947 //  Main decoding functions for WebP images.
  49948 //
  49949 // Author: Skal (pascal.massimino@gmail.com)
  49950 
  49951 // Copyright 2012 Google Inc. All Rights Reserved.
  49952 //
  49953 // Use of this source code is governed by a BSD-style license
  49954 // that can be found in the COPYING file in the root of the source
  49955 // tree. An additional intellectual property rights grant can be found
  49956 // in the file PATENTS. All contributing project authors may
  49957 // be found in the AUTHORS file in the root of the source tree.
  49958 // -----------------------------------------------------------------------------
  49959 //
  49960 //  Internal header for constants related to WebP file format.
  49961 //
  49962 // Author: Urvang (urvang@google.com)
  49963 
  49964 // Copyright 2010 Google Inc. All Rights Reserved.
  49965 //
  49966 // Use of this source code is governed by a BSD-style license
  49967 // that can be found in the COPYING file in the root of the source
  49968 // tree. An additional intellectual property rights grant can be found
  49969 // in the file PATENTS. All contributing project authors may
  49970 // be found in the AUTHORS file in the root of the source tree.
  49971 // -----------------------------------------------------------------------------
  49972 //
  49973 //  Common types + memory wrappers
  49974 //
  49975 // Author: Skal (pascal.massimino@gmail.com)
  49976 
  49977 //------------------------------------------------------------------------------
  49978 // Image transforms.
  49979 
  49980 func Average2(tls *libc.TLS, a0 uint32_t, a1 uint32_t) (r uint32_t) {
  49981 	return (a0^a1)&uint32(0xfefefefe)>>int32(1) + a0&a1
  49982 }
  49983 
  49984 func Average3(tls *libc.TLS, a0 uint32_t, a1 uint32_t, a2 uint32_t) (r uint32_t) {
  49985 	return Average2(tls, Average2(tls, a0, a2), a1)
  49986 }
  49987 
  49988 func Average4(tls *libc.TLS, a0 uint32_t, a1 uint32_t, a2 uint32_t, a3 uint32_t) (r uint32_t) {
  49989 	return Average2(tls, Average2(tls, a0, a1), Average2(tls, a2, a3))
  49990 }
  49991 
  49992 func Clip255(tls *libc.TLS, a uint32_t) (r uint32_t) {
  49993 	if a < uint32(256) {
  49994 		return a
  49995 	}
  49996 	// return 0, when a is a negative integer.
  49997 	// return 255, when a is positive.
  49998 	return ^a >> int32(24)
  49999 }
  50000 
  50001 func AddSubtractComponentFull(tls *libc.TLS, a int32, b int32, c int32) (r int32) {
  50002 	return int32(Clip255(tls, uint32(a+b-c)))
  50003 }
  50004 
  50005 func ClampedAddSubtractFull(tls *libc.TLS, c0 uint32_t, c1 uint32_t, c2 uint32_t) (r1 uint32_t) {
  50006 	var a, b, g, r int32
  50007 	_, _, _, _ = a, b, g, r
  50008 	a = AddSubtractComponentFull(tls, int32(c0>>int32(24)), int32(c1>>int32(24)), int32(c2>>int32(24)))
  50009 	r = AddSubtractComponentFull(tls, int32(c0>>libc.Int32FromInt32(16)&uint32(0xff)), int32(c1>>libc.Int32FromInt32(16)&uint32(0xff)), int32(c2>>libc.Int32FromInt32(16)&uint32(0xff)))
  50010 	g = AddSubtractComponentFull(tls, int32(c0>>libc.Int32FromInt32(8)&uint32(0xff)), int32(c1>>libc.Int32FromInt32(8)&uint32(0xff)), int32(c2>>libc.Int32FromInt32(8)&uint32(0xff)))
  50011 	b = AddSubtractComponentFull(tls, int32(c0&uint32(0xff)), int32(c1&uint32(0xff)), int32(c2&uint32(0xff)))
  50012 	return uint32(a)<<libc.Int32FromInt32(24) | uint32(r<<libc.Int32FromInt32(16)) | uint32(g<<libc.Int32FromInt32(8)) | uint32(b)
  50013 }
  50014 
  50015 func AddSubtractComponentHalf(tls *libc.TLS, a int32, b int32) (r int32) {
  50016 	return int32(Clip255(tls, uint32(a+(a-b)/libc.Int32FromInt32(2))))
  50017 }
  50018 
  50019 func ClampedAddSubtractHalf(tls *libc.TLS, c0 uint32_t, c1 uint32_t, c2 uint32_t) (r1 uint32_t) {
  50020 	var a, b, g, r int32
  50021 	var ave uint32_t
  50022 	_, _, _, _, _ = a, ave, b, g, r
  50023 	ave = Average2(tls, c0, c1)
  50024 	a = AddSubtractComponentHalf(tls, int32(ave>>int32(24)), int32(c2>>int32(24)))
  50025 	r = AddSubtractComponentHalf(tls, int32(ave>>libc.Int32FromInt32(16)&uint32(0xff)), int32(c2>>libc.Int32FromInt32(16)&uint32(0xff)))
  50026 	g = AddSubtractComponentHalf(tls, int32(ave>>libc.Int32FromInt32(8)&uint32(0xff)), int32(c2>>libc.Int32FromInt32(8)&uint32(0xff)))
  50027 	b = AddSubtractComponentHalf(tls, int32(ave>>libc.Int32FromInt32(0)&uint32(0xff)), int32(c2>>libc.Int32FromInt32(0)&uint32(0xff)))
  50028 	return uint32(a)<<libc.Int32FromInt32(24) | uint32(r<<libc.Int32FromInt32(16)) | uint32(g<<libc.Int32FromInt32(8)) | uint32(b)
  50029 }
  50030 
  50031 // gcc <= 4.9 on ARM generates incorrect code in Select() when Sub3() is
  50032 // inlined.
  50033 
  50034 func Sub3(tls *libc.TLS, a int32, b int32, c int32) (r int32) {
  50035 	var pa, pb int32
  50036 	_, _ = pa, pb
  50037 	pb = b - c
  50038 	pa = a - c
  50039 	return libc.Xabs(tls, pb) - libc.Xabs(tls, pa)
  50040 }
  50041 
  50042 func Select(tls *libc.TLS, a uint32_t, b uint32_t, c uint32_t) (r uint32_t) {
  50043 	var pa_minus_pb int32
  50044 	var v1 uint32
  50045 	_, _ = pa_minus_pb, v1
  50046 	pa_minus_pb = Sub3(tls, int32(a>>libc.Int32FromInt32(24)), int32(b>>libc.Int32FromInt32(24)), int32(c>>libc.Int32FromInt32(24))) + Sub3(tls, int32(a>>libc.Int32FromInt32(16)&uint32(0xff)), int32(b>>libc.Int32FromInt32(16)&uint32(0xff)), int32(c>>libc.Int32FromInt32(16)&uint32(0xff))) + Sub3(tls, int32(a>>libc.Int32FromInt32(8)&uint32(0xff)), int32(b>>libc.Int32FromInt32(8)&uint32(0xff)), int32(c>>libc.Int32FromInt32(8)&uint32(0xff))) + Sub3(tls, int32(a&uint32(0xff)), int32(b&uint32(0xff)), int32(c&uint32(0xff)))
  50047 	if pa_minus_pb <= 0 {
  50048 		v1 = a
  50049 	} else {
  50050 		v1 = b
  50051 	}
  50052 	return v1
  50053 }
  50054 
  50055 //------------------------------------------------------------------------------
  50056 // Predictors
  50057 
  50058 func VP8LPredictor0_C(tls *libc.TLS, left uintptr, top uintptr) (r uint32_t) {
  50059 	_ = top
  50060 	_ = left
  50061 	return uint32(ARGB_BLACK3)
  50062 }
  50063 
  50064 func VP8LPredictor1_C(tls *libc.TLS, left uintptr, top uintptr) (r uint32_t) {
  50065 	_ = top
  50066 	return **(**uint32_t)(__ccgo_up(left))
  50067 }
  50068 
  50069 func VP8LPredictor2_C(tls *libc.TLS, left uintptr, top uintptr) (r uint32_t) {
  50070 	_ = left
  50071 	return **(**uint32_t)(__ccgo_up(top))
  50072 }
  50073 
  50074 func VP8LPredictor3_C(tls *libc.TLS, left uintptr, top uintptr) (r uint32_t) {
  50075 	_ = left
  50076 	return **(**uint32_t)(__ccgo_up(top + 1*4))
  50077 }
  50078 
  50079 func VP8LPredictor4_C(tls *libc.TLS, left uintptr, top uintptr) (r uint32_t) {
  50080 	_ = left
  50081 	return **(**uint32_t)(__ccgo_up(top + uintptr(-libc.Int32FromInt32(1))*4))
  50082 }
  50083 
  50084 func VP8LPredictor5_C(tls *libc.TLS, left uintptr, top uintptr) (r uint32_t) {
  50085 	var pred uint32_t
  50086 	_ = pred
  50087 	pred = Average3(tls, **(**uint32_t)(__ccgo_up(left)), **(**uint32_t)(__ccgo_up(top)), **(**uint32_t)(__ccgo_up(top + 1*4)))
  50088 	return pred
  50089 }
  50090 
  50091 func VP8LPredictor6_C(tls *libc.TLS, left uintptr, top uintptr) (r uint32_t) {
  50092 	var pred uint32_t
  50093 	_ = pred
  50094 	pred = Average2(tls, **(**uint32_t)(__ccgo_up(left)), **(**uint32_t)(__ccgo_up(top + uintptr(-libc.Int32FromInt32(1))*4)))
  50095 	return pred
  50096 }
  50097 
  50098 func VP8LPredictor7_C(tls *libc.TLS, left uintptr, top uintptr) (r uint32_t) {
  50099 	var pred uint32_t
  50100 	_ = pred
  50101 	pred = Average2(tls, **(**uint32_t)(__ccgo_up(left)), **(**uint32_t)(__ccgo_up(top)))
  50102 	return pred
  50103 }
  50104 
  50105 func VP8LPredictor8_C(tls *libc.TLS, left uintptr, top uintptr) (r uint32_t) {
  50106 	var pred uint32_t
  50107 	_ = pred
  50108 	pred = Average2(tls, **(**uint32_t)(__ccgo_up(top + uintptr(-libc.Int32FromInt32(1))*4)), **(**uint32_t)(__ccgo_up(top)))
  50109 	_ = left
  50110 	return pred
  50111 }
  50112 
  50113 func VP8LPredictor9_C(tls *libc.TLS, left uintptr, top uintptr) (r uint32_t) {
  50114 	var pred uint32_t
  50115 	_ = pred
  50116 	pred = Average2(tls, **(**uint32_t)(__ccgo_up(top)), **(**uint32_t)(__ccgo_up(top + 1*4)))
  50117 	_ = left
  50118 	return pred
  50119 }
  50120 
  50121 func VP8LPredictor10_C(tls *libc.TLS, left uintptr, top uintptr) (r uint32_t) {
  50122 	var pred uint32_t
  50123 	_ = pred
  50124 	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)))
  50125 	return pred
  50126 }
  50127 
  50128 func VP8LPredictor11_C(tls *libc.TLS, left uintptr, top uintptr) (r uint32_t) {
  50129 	var pred uint32_t
  50130 	_ = pred
  50131 	pred = Select(tls, **(**uint32_t)(__ccgo_up(top)), **(**uint32_t)(__ccgo_up(left)), **(**uint32_t)(__ccgo_up(top + uintptr(-libc.Int32FromInt32(1))*4)))
  50132 	return pred
  50133 }
  50134 
  50135 func VP8LPredictor12_C(tls *libc.TLS, left uintptr, top uintptr) (r uint32_t) {
  50136 	var pred uint32_t
  50137 	_ = pred
  50138 	pred = ClampedAddSubtractFull(tls, **(**uint32_t)(__ccgo_up(left)), **(**uint32_t)(__ccgo_up(top)), **(**uint32_t)(__ccgo_up(top + uintptr(-libc.Int32FromInt32(1))*4)))
  50139 	return pred
  50140 }
  50141 
  50142 func VP8LPredictor13_C(tls *libc.TLS, left uintptr, top uintptr) (r uint32_t) {
  50143 	var pred uint32_t
  50144 	_ = pred
  50145 	pred = ClampedAddSubtractHalf(tls, **(**uint32_t)(__ccgo_up(left)), **(**uint32_t)(__ccgo_up(top)), **(**uint32_t)(__ccgo_up(top + uintptr(-libc.Int32FromInt32(1))*4)))
  50146 	return pred
  50147 }
  50148 
  50149 func PredictorAdd0_C(tls *libc.TLS, in uintptr, upper uintptr, num_pixels int32, out uintptr) {
  50150 	var alpha_and_green, red_and_blue, v2, v3, v4 uint32_t
  50151 	var x int32
  50152 	_, _, _, _, _, _ = alpha_and_green, red_and_blue, x, v2, v3, v4
  50153 	_ = upper
  50154 	x = 0
  50155 	for {
  50156 		if !(x < num_pixels) {
  50157 			break
  50158 		}
  50159 		v2 = **(**uint32_t)(__ccgo_up(in + uintptr(x)*4))
  50160 		v3 = uint32(ARGB_BLACK3)
  50161 		alpha_and_green = v2&uint32(0xff00ff00) + v3&uint32(0xff00ff00)
  50162 		red_and_blue = v2&uint32(0x00ff00ff) + v3&uint32(0x00ff00ff)
  50163 		v4 = alpha_and_green&uint32(0xff00ff00) | red_and_blue&uint32(0x00ff00ff)
  50164 		goto _5
  50165 	_5:
  50166 		**(**uint32_t)(__ccgo_up(out + uintptr(x)*4)) = v4
  50167 		goto _1
  50168 	_1:
  50169 		;
  50170 		x = x + 1
  50171 	}
  50172 }
  50173 
  50174 func PredictorAdd1_C(tls *libc.TLS, in uintptr, upper uintptr, num_pixels int32, out uintptr) {
  50175 	var alpha_and_green, left, red_and_blue, v2, v3, v4, v5 uint32_t
  50176 	var i int32
  50177 	_, _, _, _, _, _, _, _ = alpha_and_green, i, left, red_and_blue, v2, v3, v4, v5
  50178 	left = **(**uint32_t)(__ccgo_up(out + uintptr(-libc.Int32FromInt32(1))*4))
  50179 	_ = upper
  50180 	i = 0
  50181 	for {
  50182 		if !(i < num_pixels) {
  50183 			break
  50184 		}
  50185 		v3 = **(**uint32_t)(__ccgo_up(in + uintptr(i)*4))
  50186 		v4 = left
  50187 		alpha_and_green = v3&uint32(0xff00ff00) + v4&uint32(0xff00ff00)
  50188 		red_and_blue = v3&uint32(0x00ff00ff) + v4&uint32(0x00ff00ff)
  50189 		v5 = alpha_and_green&uint32(0xff00ff00) | red_and_blue&uint32(0x00ff00ff)
  50190 		goto _6
  50191 	_6:
  50192 		v2 = v5
  50193 		left = v2
  50194 		**(**uint32_t)(__ccgo_up(out + uintptr(i)*4)) = v2
  50195 		goto _1
  50196 	_1:
  50197 		;
  50198 		i = i + 1
  50199 	}
  50200 }
  50201 
  50202 func PredictorAdd2_C(tls *libc.TLS, in uintptr, upper uintptr, num_pixels int32, out uintptr) {
  50203 	var alpha_and_green, pred, red_and_blue, v2, v3, v4 uint32_t
  50204 	var x int32
  50205 	_, _, _, _, _, _, _ = alpha_and_green, pred, red_and_blue, x, v2, v3, v4
  50206 	x = 0
  50207 	for {
  50208 		if !(x < num_pixels) {
  50209 			break
  50210 		}
  50211 		pred = VP8LPredictor2_C(tls, out+uintptr(x-int32(1))*4, upper+uintptr(x)*4)
  50212 		v2 = **(**uint32_t)(__ccgo_up(in + uintptr(x)*4))
  50213 		v3 = pred
  50214 		alpha_and_green = v2&uint32(0xff00ff00) + v3&uint32(0xff00ff00)
  50215 		red_and_blue = v2&uint32(0x00ff00ff) + v3&uint32(0x00ff00ff)
  50216 		v4 = alpha_and_green&uint32(0xff00ff00) | red_and_blue&uint32(0x00ff00ff)
  50217 		goto _5
  50218 	_5:
  50219 		**(**uint32_t)(__ccgo_up(out + uintptr(x)*4)) = v4
  50220 		goto _1
  50221 	_1:
  50222 		;
  50223 		x = x + 1
  50224 	}
  50225 }
  50226 
  50227 func PredictorAdd3_C(tls *libc.TLS, in uintptr, upper uintptr, num_pixels int32, out uintptr) {
  50228 	var alpha_and_green, pred, red_and_blue, v2, v3, v4 uint32_t
  50229 	var x int32
  50230 	_, _, _, _, _, _, _ = alpha_and_green, pred, red_and_blue, x, v2, v3, v4
  50231 	x = 0
  50232 	for {
  50233 		if !(x < num_pixels) {
  50234 			break
  50235 		}
  50236 		pred = VP8LPredictor3_C(tls, out+uintptr(x-int32(1))*4, upper+uintptr(x)*4)
  50237 		v2 = **(**uint32_t)(__ccgo_up(in + uintptr(x)*4))
  50238 		v3 = pred
  50239 		alpha_and_green = v2&uint32(0xff00ff00) + v3&uint32(0xff00ff00)
  50240 		red_and_blue = v2&uint32(0x00ff00ff) + v3&uint32(0x00ff00ff)
  50241 		v4 = alpha_and_green&uint32(0xff00ff00) | red_and_blue&uint32(0x00ff00ff)
  50242 		goto _5
  50243 	_5:
  50244 		**(**uint32_t)(__ccgo_up(out + uintptr(x)*4)) = v4
  50245 		goto _1
  50246 	_1:
  50247 		;
  50248 		x = x + 1
  50249 	}
  50250 }
  50251 
  50252 func PredictorAdd4_C(tls *libc.TLS, in uintptr, upper uintptr, num_pixels int32, out uintptr) {
  50253 	var alpha_and_green, pred, red_and_blue, v2, v3, v4 uint32_t
  50254 	var x int32
  50255 	_, _, _, _, _, _, _ = alpha_and_green, pred, red_and_blue, x, v2, v3, v4
  50256 	x = 0
  50257 	for {
  50258 		if !(x < num_pixels) {
  50259 			break
  50260 		}
  50261 		pred = VP8LPredictor4_C(tls, out+uintptr(x-int32(1))*4, upper+uintptr(x)*4)
  50262 		v2 = **(**uint32_t)(__ccgo_up(in + uintptr(x)*4))
  50263 		v3 = pred
  50264 		alpha_and_green = v2&uint32(0xff00ff00) + v3&uint32(0xff00ff00)
  50265 		red_and_blue = v2&uint32(0x00ff00ff) + v3&uint32(0x00ff00ff)
  50266 		v4 = alpha_and_green&uint32(0xff00ff00) | red_and_blue&uint32(0x00ff00ff)
  50267 		goto _5
  50268 	_5:
  50269 		**(**uint32_t)(__ccgo_up(out + uintptr(x)*4)) = v4
  50270 		goto _1
  50271 	_1:
  50272 		;
  50273 		x = x + 1
  50274 	}
  50275 }
  50276 
  50277 func PredictorAdd5_C(tls *libc.TLS, in uintptr, upper uintptr, num_pixels int32, out uintptr) {
  50278 	var alpha_and_green, pred, red_and_blue, v2, v3, v4 uint32_t
  50279 	var x int32
  50280 	_, _, _, _, _, _, _ = alpha_and_green, pred, red_and_blue, x, v2, v3, v4
  50281 	x = 0
  50282 	for {
  50283 		if !(x < num_pixels) {
  50284 			break
  50285 		}
  50286 		pred = VP8LPredictor5_C(tls, out+uintptr(x-int32(1))*4, upper+uintptr(x)*4)
  50287 		v2 = **(**uint32_t)(__ccgo_up(in + uintptr(x)*4))
  50288 		v3 = pred
  50289 		alpha_and_green = v2&uint32(0xff00ff00) + v3&uint32(0xff00ff00)
  50290 		red_and_blue = v2&uint32(0x00ff00ff) + v3&uint32(0x00ff00ff)
  50291 		v4 = alpha_and_green&uint32(0xff00ff00) | red_and_blue&uint32(0x00ff00ff)
  50292 		goto _5
  50293 	_5:
  50294 		**(**uint32_t)(__ccgo_up(out + uintptr(x)*4)) = v4
  50295 		goto _1
  50296 	_1:
  50297 		;
  50298 		x = x + 1
  50299 	}
  50300 }
  50301 
  50302 func PredictorAdd6_C(tls *libc.TLS, in uintptr, upper uintptr, num_pixels int32, out uintptr) {
  50303 	var alpha_and_green, pred, red_and_blue, v2, v3, v4 uint32_t
  50304 	var x int32
  50305 	_, _, _, _, _, _, _ = alpha_and_green, pred, red_and_blue, x, v2, v3, v4
  50306 	x = 0
  50307 	for {
  50308 		if !(x < num_pixels) {
  50309 			break
  50310 		}
  50311 		pred = VP8LPredictor6_C(tls, out+uintptr(x-int32(1))*4, upper+uintptr(x)*4)
  50312 		v2 = **(**uint32_t)(__ccgo_up(in + uintptr(x)*4))
  50313 		v3 = pred
  50314 		alpha_and_green = v2&uint32(0xff00ff00) + v3&uint32(0xff00ff00)
  50315 		red_and_blue = v2&uint32(0x00ff00ff) + v3&uint32(0x00ff00ff)
  50316 		v4 = alpha_and_green&uint32(0xff00ff00) | red_and_blue&uint32(0x00ff00ff)
  50317 		goto _5
  50318 	_5:
  50319 		**(**uint32_t)(__ccgo_up(out + uintptr(x)*4)) = v4
  50320 		goto _1
  50321 	_1:
  50322 		;
  50323 		x = x + 1
  50324 	}
  50325 }
  50326 
  50327 func PredictorAdd7_C(tls *libc.TLS, in uintptr, upper uintptr, num_pixels int32, out uintptr) {
  50328 	var alpha_and_green, pred, red_and_blue, v2, v3, v4 uint32_t
  50329 	var x int32
  50330 	_, _, _, _, _, _, _ = alpha_and_green, pred, red_and_blue, x, v2, v3, v4
  50331 	x = 0
  50332 	for {
  50333 		if !(x < num_pixels) {
  50334 			break
  50335 		}
  50336 		pred = VP8LPredictor7_C(tls, out+uintptr(x-int32(1))*4, upper+uintptr(x)*4)
  50337 		v2 = **(**uint32_t)(__ccgo_up(in + uintptr(x)*4))
  50338 		v3 = pred
  50339 		alpha_and_green = v2&uint32(0xff00ff00) + v3&uint32(0xff00ff00)
  50340 		red_and_blue = v2&uint32(0x00ff00ff) + v3&uint32(0x00ff00ff)
  50341 		v4 = alpha_and_green&uint32(0xff00ff00) | red_and_blue&uint32(0x00ff00ff)
  50342 		goto _5
  50343 	_5:
  50344 		**(**uint32_t)(__ccgo_up(out + uintptr(x)*4)) = v4
  50345 		goto _1
  50346 	_1:
  50347 		;
  50348 		x = x + 1
  50349 	}
  50350 }
  50351 
  50352 func PredictorAdd8_C(tls *libc.TLS, in uintptr, upper uintptr, num_pixels int32, out uintptr) {
  50353 	var alpha_and_green, pred, red_and_blue, v2, v3, v4 uint32_t
  50354 	var x int32
  50355 	_, _, _, _, _, _, _ = alpha_and_green, pred, red_and_blue, x, v2, v3, v4
  50356 	x = 0
  50357 	for {
  50358 		if !(x < num_pixels) {
  50359 			break
  50360 		}
  50361 		pred = VP8LPredictor8_C(tls, out+uintptr(x-int32(1))*4, upper+uintptr(x)*4)
  50362 		v2 = **(**uint32_t)(__ccgo_up(in + uintptr(x)*4))
  50363 		v3 = pred
  50364 		alpha_and_green = v2&uint32(0xff00ff00) + v3&uint32(0xff00ff00)
  50365 		red_and_blue = v2&uint32(0x00ff00ff) + v3&uint32(0x00ff00ff)
  50366 		v4 = alpha_and_green&uint32(0xff00ff00) | red_and_blue&uint32(0x00ff00ff)
  50367 		goto _5
  50368 	_5:
  50369 		**(**uint32_t)(__ccgo_up(out + uintptr(x)*4)) = v4
  50370 		goto _1
  50371 	_1:
  50372 		;
  50373 		x = x + 1
  50374 	}
  50375 }
  50376 
  50377 func PredictorAdd9_C(tls *libc.TLS, in uintptr, upper uintptr, num_pixels int32, out uintptr) {
  50378 	var alpha_and_green, pred, red_and_blue, v2, v3, v4 uint32_t
  50379 	var x int32
  50380 	_, _, _, _, _, _, _ = alpha_and_green, pred, red_and_blue, x, v2, v3, v4
  50381 	x = 0
  50382 	for {
  50383 		if !(x < num_pixels) {
  50384 			break
  50385 		}
  50386 		pred = VP8LPredictor9_C(tls, out+uintptr(x-int32(1))*4, upper+uintptr(x)*4)
  50387 		v2 = **(**uint32_t)(__ccgo_up(in + uintptr(x)*4))
  50388 		v3 = pred
  50389 		alpha_and_green = v2&uint32(0xff00ff00) + v3&uint32(0xff00ff00)
  50390 		red_and_blue = v2&uint32(0x00ff00ff) + v3&uint32(0x00ff00ff)
  50391 		v4 = alpha_and_green&uint32(0xff00ff00) | red_and_blue&uint32(0x00ff00ff)
  50392 		goto _5
  50393 	_5:
  50394 		**(**uint32_t)(__ccgo_up(out + uintptr(x)*4)) = v4
  50395 		goto _1
  50396 	_1:
  50397 		;
  50398 		x = x + 1
  50399 	}
  50400 }
  50401 
  50402 func PredictorAdd10_C(tls *libc.TLS, in uintptr, upper uintptr, num_pixels int32, out uintptr) {
  50403 	var alpha_and_green, pred, red_and_blue, v2, v3, v4 uint32_t
  50404 	var x int32
  50405 	_, _, _, _, _, _, _ = alpha_and_green, pred, red_and_blue, x, v2, v3, v4
  50406 	x = 0
  50407 	for {
  50408 		if !(x < num_pixels) {
  50409 			break
  50410 		}
  50411 		pred = VP8LPredictor10_C(tls, out+uintptr(x-int32(1))*4, upper+uintptr(x)*4)
  50412 		v2 = **(**uint32_t)(__ccgo_up(in + uintptr(x)*4))
  50413 		v3 = pred
  50414 		alpha_and_green = v2&uint32(0xff00ff00) + v3&uint32(0xff00ff00)
  50415 		red_and_blue = v2&uint32(0x00ff00ff) + v3&uint32(0x00ff00ff)
  50416 		v4 = alpha_and_green&uint32(0xff00ff00) | red_and_blue&uint32(0x00ff00ff)
  50417 		goto _5
  50418 	_5:
  50419 		**(**uint32_t)(__ccgo_up(out + uintptr(x)*4)) = v4
  50420 		goto _1
  50421 	_1:
  50422 		;
  50423 		x = x + 1
  50424 	}
  50425 }
  50426 
  50427 func PredictorAdd11_C(tls *libc.TLS, in uintptr, upper uintptr, num_pixels int32, out uintptr) {
  50428 	var alpha_and_green, pred, red_and_blue, v2, v3, v4 uint32_t
  50429 	var x int32
  50430 	_, _, _, _, _, _, _ = alpha_and_green, pred, red_and_blue, x, v2, v3, v4
  50431 	x = 0
  50432 	for {
  50433 		if !(x < num_pixels) {
  50434 			break
  50435 		}
  50436 		pred = VP8LPredictor11_C(tls, out+uintptr(x-int32(1))*4, upper+uintptr(x)*4)
  50437 		v2 = **(**uint32_t)(__ccgo_up(in + uintptr(x)*4))
  50438 		v3 = pred
  50439 		alpha_and_green = v2&uint32(0xff00ff00) + v3&uint32(0xff00ff00)
  50440 		red_and_blue = v2&uint32(0x00ff00ff) + v3&uint32(0x00ff00ff)
  50441 		v4 = alpha_and_green&uint32(0xff00ff00) | red_and_blue&uint32(0x00ff00ff)
  50442 		goto _5
  50443 	_5:
  50444 		**(**uint32_t)(__ccgo_up(out + uintptr(x)*4)) = v4
  50445 		goto _1
  50446 	_1:
  50447 		;
  50448 		x = x + 1
  50449 	}
  50450 }
  50451 
  50452 func PredictorAdd12_C(tls *libc.TLS, in uintptr, upper uintptr, num_pixels int32, out uintptr) {
  50453 	var alpha_and_green, pred, red_and_blue, v2, v3, v4 uint32_t
  50454 	var x int32
  50455 	_, _, _, _, _, _, _ = alpha_and_green, pred, red_and_blue, x, v2, v3, v4
  50456 	x = 0
  50457 	for {
  50458 		if !(x < num_pixels) {
  50459 			break
  50460 		}
  50461 		pred = VP8LPredictor12_C(tls, out+uintptr(x-int32(1))*4, upper+uintptr(x)*4)
  50462 		v2 = **(**uint32_t)(__ccgo_up(in + uintptr(x)*4))
  50463 		v3 = pred
  50464 		alpha_and_green = v2&uint32(0xff00ff00) + v3&uint32(0xff00ff00)
  50465 		red_and_blue = v2&uint32(0x00ff00ff) + v3&uint32(0x00ff00ff)
  50466 		v4 = alpha_and_green&uint32(0xff00ff00) | red_and_blue&uint32(0x00ff00ff)
  50467 		goto _5
  50468 	_5:
  50469 		**(**uint32_t)(__ccgo_up(out + uintptr(x)*4)) = v4
  50470 		goto _1
  50471 	_1:
  50472 		;
  50473 		x = x + 1
  50474 	}
  50475 }
  50476 
  50477 func PredictorAdd13_C(tls *libc.TLS, in uintptr, upper uintptr, num_pixels int32, out uintptr) {
  50478 	var alpha_and_green, pred, red_and_blue, v2, v3, v4 uint32_t
  50479 	var x int32
  50480 	_, _, _, _, _, _, _ = alpha_and_green, pred, red_and_blue, x, v2, v3, v4
  50481 	x = 0
  50482 	for {
  50483 		if !(x < num_pixels) {
  50484 			break
  50485 		}
  50486 		pred = VP8LPredictor13_C(tls, out+uintptr(x-int32(1))*4, upper+uintptr(x)*4)
  50487 		v2 = **(**uint32_t)(__ccgo_up(in + uintptr(x)*4))
  50488 		v3 = pred
  50489 		alpha_and_green = v2&uint32(0xff00ff00) + v3&uint32(0xff00ff00)
  50490 		red_and_blue = v2&uint32(0x00ff00ff) + v3&uint32(0x00ff00ff)
  50491 		v4 = alpha_and_green&uint32(0xff00ff00) | red_and_blue&uint32(0x00ff00ff)
  50492 		goto _5
  50493 	_5:
  50494 		**(**uint32_t)(__ccgo_up(out + uintptr(x)*4)) = v4
  50495 		goto _1
  50496 	_1:
  50497 		;
  50498 		x = x + 1
  50499 	}
  50500 }
  50501 
  50502 //------------------------------------------------------------------------------
  50503 
  50504 // C documentation
  50505 //
  50506 //	// Inverse prediction.
  50507 func PredictorInverseTransform_C(tls *libc.TLS, transform uintptr, y_start int32, y_end int32, in uintptr, out uintptr) {
  50508 	var mask, tile_width, tiles_per_row, width, x, x_end, y int32
  50509 	var pred_func VP8LPredictorAddSubFunc
  50510 	var pred_mode_base, pred_mode_src, v4 uintptr
  50511 	var v1, v2 uint32_t
  50512 	_, _, _, _, _, _, _, _, _, _, _, _, _ = mask, pred_func, pred_mode_base, pred_mode_src, tile_width, tiles_per_row, width, x, x_end, y, v1, v2, v4
  50513 	width = (*VP8LTransform)(unsafe.Pointer(transform)).Fxsize
  50514 	if y_start == 0 { // First Row follows the L (mode=1) mode.
  50515 		PredictorAdd0_C(tls, in, libc.UintptrFromInt32(0), int32(1), out)
  50516 		PredictorAdd1_C(tls, in+uintptr(1)*4, libc.UintptrFromInt32(0), width-int32(1), out+uintptr(1)*4)
  50517 		in = in + uintptr(width)*4
  50518 		out = out + uintptr(width)*4
  50519 		y_start = y_start + 1
  50520 	}
  50521 	y = y_start
  50522 	tile_width = int32(1) << (*VP8LTransform)(unsafe.Pointer(transform)).Fbits
  50523 	mask = tile_width - int32(1)
  50524 	v1 = uint32((*VP8LTransform)(unsafe.Pointer(transform)).Fbits)
  50525 	v2 = (uint32(width) + uint32(libc.Int32FromInt32(1)<<v1) - uint32(1)) >> v1
  50526 	goto _3
  50527 _3:
  50528 	tiles_per_row = int32(v2)
  50529 	pred_mode_base = (*VP8LTransform)(unsafe.Pointer(transform)).Fdata + uintptr(y>>(*VP8LTransform)(unsafe.Pointer(transform)).Fbits*tiles_per_row)*4
  50530 	for y < y_end {
  50531 		pred_mode_src = pred_mode_base
  50532 		x = int32(1)
  50533 		// First pixel follows the T (mode=2) mode.
  50534 		PredictorAdd2_C(tls, in, out-uintptr(width)*4, int32(1), out)
  50535 		// .. the rest:
  50536 		for x < width {
  50537 			v4 = pred_mode_src
  50538 			pred_mode_src += 4
  50539 			pred_func = VP8LPredictorsAdd[**(**uint32_t)(__ccgo_up(v4))>>libc.Int32FromInt32(8)&uint32(0xf)]
  50540 			x_end = x & ^mask + tile_width
  50541 			if x_end > width {
  50542 				x_end = width
  50543 			}
  50544 			(*(*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)
  50545 			x = x_end
  50546 		}
  50547 		in = in + uintptr(width)*4
  50548 		out = out + uintptr(width)*4
  50549 		y = y + 1
  50550 		if y&mask == 0 { // Use the same mask, since tiles are squares.
  50551 			pred_mode_base = pred_mode_base + uintptr(tiles_per_row)*4
  50552 		}
  50553 	}
  50554 }
  50555 
  50556 // C documentation
  50557 //
  50558 //	// Add green to blue and red channels (i.e. perform the inverse transform of
  50559 //	// 'subtract green').
  50560 func VP8LAddGreenToBlueAndRed_C(tls *libc.TLS, src uintptr, num_pixels int32, dst uintptr) {
  50561 	var argb, green, red_blue uint32_t
  50562 	var i int32
  50563 	_, _, _, _ = argb, green, i, red_blue
  50564 	i = 0
  50565 	for {
  50566 		if !(i < num_pixels) {
  50567 			break
  50568 		}
  50569 		argb = **(**uint32_t)(__ccgo_up(src + uintptr(i)*4))
  50570 		green = argb >> libc.Int32FromInt32(8) & libc.Uint32FromInt32(0xff)
  50571 		red_blue = argb & libc.Uint32FromUint32(0x00ff00ff)
  50572 		red_blue = red_blue + (green<<libc.Int32FromInt32(16) | green)
  50573 		red_blue = red_blue & uint32(0x00ff00ff)
  50574 		**(**uint32_t)(__ccgo_up(dst + uintptr(i)*4)) = argb&uint32(0xff00ff00) | red_blue
  50575 		goto _1
  50576 	_1:
  50577 		;
  50578 		i = i + 1
  50579 	}
  50580 }
  50581 
  50582 func ColorTransformDelta(tls *libc.TLS, color_pred int8_t, color int8_t) (r int32) {
  50583 	return int32(color_pred) * int32(color) >> int32(5)
  50584 }
  50585 
  50586 func ColorCodeToMultipliers1(tls *libc.TLS, color_code uint32_t, m uintptr) {
  50587 	(*VP8LMultipliers)(unsafe.Pointer(m)).Fgreen_to_red = uint8(color_code >> libc.Int32FromInt32(0) & uint32(0xff))
  50588 	(*VP8LMultipliers)(unsafe.Pointer(m)).Fgreen_to_blue = uint8(color_code >> libc.Int32FromInt32(8) & uint32(0xff))
  50589 	(*VP8LMultipliers)(unsafe.Pointer(m)).Fred_to_blue = uint8(color_code >> libc.Int32FromInt32(16) & uint32(0xff))
  50590 }
  50591 
  50592 func VP8LTransformColorInverse_C(tls *libc.TLS, m uintptr, src uintptr, num_pixels int32, dst uintptr) {
  50593 	var argb, red uint32_t
  50594 	var green int8_t
  50595 	var i, new_blue, new_red int32
  50596 	_, _, _, _, _, _ = argb, green, i, new_blue, new_red, red
  50597 	i = 0
  50598 	for {
  50599 		if !(i < num_pixels) {
  50600 			break
  50601 		}
  50602 		argb = **(**uint32_t)(__ccgo_up(src + uintptr(i)*4))
  50603 		green = int8(argb >> libc.Int32FromInt32(8))
  50604 		red = argb >> int32(16)
  50605 		new_red = int32(red & uint32(0xff))
  50606 		new_blue = int32(argb & uint32(0xff))
  50607 		new_red = new_red + ColorTransformDelta(tls, int8((*VP8LMultipliers)(unsafe.Pointer(m)).Fgreen_to_red), green)
  50608 		new_red = new_red & int32(0xff)
  50609 		new_blue = new_blue + ColorTransformDelta(tls, int8((*VP8LMultipliers)(unsafe.Pointer(m)).Fgreen_to_blue), green)
  50610 		new_blue = new_blue + ColorTransformDelta(tls, int8((*VP8LMultipliers)(unsafe.Pointer(m)).Fred_to_blue), int8(new_red))
  50611 		new_blue = new_blue & int32(0xff)
  50612 		**(**uint32_t)(__ccgo_up(dst + uintptr(i)*4)) = argb&uint32(0xff00ff00) | uint32(new_red<<libc.Int32FromInt32(16)) | uint32(new_blue)
  50613 		goto _1
  50614 	_1:
  50615 		;
  50616 		i = i + 1
  50617 	}
  50618 }
  50619 
  50620 // C documentation
  50621 //
  50622 //	// Color space inverse transform.
  50623 func ColorSpaceInverseTransform_C(tls *libc.TLS, transform uintptr, y_start int32, y_end int32, src uintptr, dst uintptr) {
  50624 	bp := tls.Alloc(16)
  50625 	defer tls.Free(16)
  50626 	var mask, remaining_width, safe_width, tile_width, tiles_per_row, width, y int32
  50627 	var pred, pred_row, src_end, src_safe_end, v4 uintptr
  50628 	var v1, v2 uint32_t
  50629 	var _ /* m at bp+0 */ VP8LMultipliers
  50630 	_, _, _, _, _, _, _, _, _, _, _, _, _, _ = mask, pred, pred_row, remaining_width, safe_width, src_end, src_safe_end, tile_width, tiles_per_row, width, y, v1, v2, v4
  50631 	width = (*VP8LTransform)(unsafe.Pointer(transform)).Fxsize
  50632 	tile_width = int32(1) << (*VP8LTransform)(unsafe.Pointer(transform)).Fbits
  50633 	mask = tile_width - int32(1)
  50634 	safe_width = width & ^mask
  50635 	remaining_width = width - safe_width
  50636 	v1 = uint32((*VP8LTransform)(unsafe.Pointer(transform)).Fbits)
  50637 	v2 = (uint32(width) + uint32(libc.Int32FromInt32(1)<<v1) - uint32(1)) >> v1
  50638 	goto _3
  50639 _3:
  50640 	tiles_per_row = int32(v2)
  50641 	y = y_start
  50642 	pred_row = (*VP8LTransform)(unsafe.Pointer(transform)).Fdata + uintptr(y>>(*VP8LTransform)(unsafe.Pointer(transform)).Fbits*tiles_per_row)*4
  50643 	for y < y_end {
  50644 		pred = pred_row
  50645 		**(**VP8LMultipliers)(__ccgo_up(bp)) = VP8LMultipliers{}
  50646 		src_safe_end = src + uintptr(safe_width)*4
  50647 		src_end = src + uintptr(width)*4
  50648 		for src < src_safe_end {
  50649 			v4 = pred
  50650 			pred += 4
  50651 			ColorCodeToMultipliers1(tls, **(**uint32_t)(__ccgo_up(v4)), bp)
  50652 			(*(*func(*libc.TLS, uintptr, uintptr, int32, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8LTransformColorInverse})))(tls, bp, src, tile_width, dst)
  50653 			src = src + uintptr(tile_width)*4
  50654 			dst = dst + uintptr(tile_width)*4
  50655 		}
  50656 		if src < src_end { // Left-overs using C-version.
  50657 			v4 = pred
  50658 			pred += 4
  50659 			ColorCodeToMultipliers1(tls, **(**uint32_t)(__ccgo_up(v4)), bp)
  50660 			(*(*func(*libc.TLS, uintptr, uintptr, int32, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8LTransformColorInverse})))(tls, bp, src, remaining_width, dst)
  50661 			src = src + uintptr(remaining_width)*4
  50662 			dst = dst + uintptr(remaining_width)*4
  50663 		}
  50664 		y = y + 1
  50665 		if y&mask == 0 {
  50666 			pred_row = pred_row + uintptr(tiles_per_row)*4
  50667 		}
  50668 	}
  50669 }
  50670 
  50671 // Separate out pixels packed together using pixel-bundling.
  50672 // We define two methods for ARGB data (uint32_t) and alpha-only data (uint8_t).
  50673 func MapARGB_C(tls *libc.TLS, src uintptr, color_map uintptr, dst uintptr, y_start int32, y_end int32, width int32) {
  50674 	var x, y int32
  50675 	var v3, v4 uintptr
  50676 	var v5, v7 uint32_t
  50677 	_, _, _, _, _, _ = x, y, v3, v4, v5, v7
  50678 	y = y_start
  50679 	for {
  50680 		if !(y < y_end) {
  50681 			break
  50682 		}
  50683 		x = 0
  50684 		for {
  50685 			if !(x < width) {
  50686 				break
  50687 			}
  50688 			v3 = dst
  50689 			dst += 4
  50690 			v4 = src
  50691 			src += 4
  50692 			v5 = **(**uint32_t)(__ccgo_up(v4)) >> libc.Int32FromInt32(8) & uint32(0xff)
  50693 			goto _6
  50694 		_6:
  50695 			v7 = **(**uint32_t)(__ccgo_up(color_map + uintptr(v5)*4))
  50696 			goto _8
  50697 		_8:
  50698 			**(**uint32_t)(__ccgo_up(v3)) = v7
  50699 			goto _2
  50700 		_2:
  50701 			;
  50702 			x = x + 1
  50703 		}
  50704 		goto _1
  50705 	_1:
  50706 		;
  50707 		y = y + 1
  50708 	}
  50709 }
  50710 
  50711 func ColorIndexInverseTransform_C(tls *libc.TLS, transform uintptr, y_start int32, y_end int32, src uintptr, dst uintptr) {
  50712 	var bit_mask, packed_pixels, v4 uint32_t
  50713 	var bits_per_pixel, count_mask, pixels_per_byte, width, x, y int32
  50714 	var color_map, v3 uintptr
  50715 	_, _, _, _, _, _, _, _, _, _, _ = bit_mask, bits_per_pixel, color_map, count_mask, packed_pixels, pixels_per_byte, width, x, y, v3, v4
  50716 	bits_per_pixel = int32(8) >> (*VP8LTransform)(unsafe.Pointer(transform)).Fbits
  50717 	width = (*VP8LTransform)(unsafe.Pointer(transform)).Fxsize
  50718 	color_map = (*VP8LTransform)(unsafe.Pointer(transform)).Fdata
  50719 	if bits_per_pixel < int32(8) {
  50720 		pixels_per_byte = int32(1) << (*VP8LTransform)(unsafe.Pointer(transform)).Fbits
  50721 		count_mask = pixels_per_byte - int32(1)
  50722 		bit_mask = uint32(int32(1)<<bits_per_pixel - int32(1))
  50723 		y = y_start
  50724 		for {
  50725 			if !(y < y_end) {
  50726 				break
  50727 			}
  50728 			packed_pixels = uint32(0)
  50729 			x = 0
  50730 			for {
  50731 				if !(x < width) {
  50732 					break
  50733 				} /* 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.                                         */
  50734 				if x&count_mask == 0 {
  50735 					v3 = src
  50736 					src += 4
  50737 					v4 = **(**uint32_t)(__ccgo_up(v3)) >> libc.Int32FromInt32(8) & uint32(0xff)
  50738 					goto _5
  50739 				_5:
  50740 					packed_pixels = v4
  50741 				}
  50742 				v3 = dst
  50743 				dst += 4
  50744 				v4 = **(**uint32_t)(__ccgo_up(color_map + uintptr(packed_pixels&bit_mask)*4))
  50745 				goto _8
  50746 			_8:
  50747 				**(**uint32_t)(__ccgo_up(v3)) = v4
  50748 				packed_pixels = packed_pixels >> uint32(bits_per_pixel)
  50749 				goto _2
  50750 			_2:
  50751 				;
  50752 				x = x + 1
  50753 			}
  50754 			goto _1
  50755 		_1:
  50756 			;
  50757 			y = y + 1
  50758 		}
  50759 	} else {
  50760 		(*(*func(*libc.TLS, uintptr, uintptr, uintptr, int32, int32, int32))(unsafe.Pointer(&struct{ uintptr }{VP8LMapColor32b})))(tls, src, color_map, dst, y_start, y_end, width)
  50761 	}
  50762 }
  50763 
  50764 func MapAlpha_C(tls *libc.TLS, src uintptr, color_map uintptr, dst uintptr, y_start int32, y_end int32, width int32) {
  50765 	var x, y int32
  50766 	var v3, v4 uintptr
  50767 	var v5, v7 uint8_t
  50768 	_, _, _, _, _, _ = x, y, v3, v4, v5, v7
  50769 	y = y_start
  50770 	for {
  50771 		if !(y < y_end) {
  50772 			break
  50773 		}
  50774 		x = 0
  50775 		for {
  50776 			if !(x < width) {
  50777 				break
  50778 			}
  50779 			v3 = dst
  50780 			dst = dst + 1
  50781 			v4 = src
  50782 			src = src + 1
  50783 			v5 = **(**uint8_t)(__ccgo_up(v4))
  50784 			goto _6
  50785 		_6:
  50786 			v7 = uint8(**(**uint32_t)(__ccgo_up(color_map + uintptr(v5)*4)) >> libc.Int32FromInt32(8) & uint32(0xff))
  50787 			goto _8
  50788 		_8:
  50789 			**(**uint8_t)(__ccgo_up(v3)) = v7
  50790 			goto _2
  50791 		_2:
  50792 			;
  50793 			x = x + 1
  50794 		}
  50795 		goto _1
  50796 	_1:
  50797 		;
  50798 		y = y + 1
  50799 	}
  50800 }
  50801 
  50802 func VP8LColorIndexInverseTransformAlpha(tls *libc.TLS, transform uintptr, y_start int32, y_end int32, src uintptr, dst uintptr) {
  50803 	var bit_mask, packed_pixels uint32_t
  50804 	var bits_per_pixel, count_mask, pixels_per_byte, width, x, y int32
  50805 	var color_map, v3 uintptr
  50806 	var v4 uint8_t
  50807 	_, _, _, _, _, _, _, _, _, _, _ = bit_mask, bits_per_pixel, color_map, count_mask, packed_pixels, pixels_per_byte, width, x, y, v3, v4
  50808 	bits_per_pixel = int32(8) >> (*VP8LTransform)(unsafe.Pointer(transform)).Fbits
  50809 	width = (*VP8LTransform)(unsafe.Pointer(transform)).Fxsize
  50810 	color_map = (*VP8LTransform)(unsafe.Pointer(transform)).Fdata
  50811 	if bits_per_pixel < int32(8) {
  50812 		pixels_per_byte = int32(1) << (*VP8LTransform)(unsafe.Pointer(transform)).Fbits
  50813 		count_mask = pixels_per_byte - int32(1)
  50814 		bit_mask = uint32(int32(1)<<bits_per_pixel - int32(1))
  50815 		y = y_start
  50816 		for {
  50817 			if !(y < y_end) {
  50818 				break
  50819 			}
  50820 			packed_pixels = uint32(0)
  50821 			x = 0
  50822 			for {
  50823 				if !(x < width) {
  50824 					break
  50825 				} /* 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.                                         */
  50826 				if x&count_mask == 0 {
  50827 					v3 = src
  50828 					src = src + 1
  50829 					v4 = **(**uint8_t)(__ccgo_up(v3))
  50830 					goto _5
  50831 				_5:
  50832 					packed_pixels = uint32(v4)
  50833 				}
  50834 				v3 = dst
  50835 				dst = dst + 1
  50836 				v4 = uint8(**(**uint32_t)(__ccgo_up(color_map + uintptr(packed_pixels&bit_mask)*4)) >> libc.Int32FromInt32(8) & uint32(0xff))
  50837 				goto _8
  50838 			_8:
  50839 				**(**uint8_t)(__ccgo_up(v3)) = v4
  50840 				packed_pixels = packed_pixels >> uint32(bits_per_pixel)
  50841 				goto _2
  50842 			_2:
  50843 				;
  50844 				x = x + 1
  50845 			}
  50846 			goto _1
  50847 		_1:
  50848 			;
  50849 			y = y + 1
  50850 		}
  50851 	} else {
  50852 		(*(*func(*libc.TLS, uintptr, uintptr, uintptr, int32, int32, int32))(unsafe.Pointer(&struct{ uintptr }{VP8LMapColor8b})))(tls, src, color_map, dst, y_start, y_end, width)
  50853 	}
  50854 }
  50855 
  50856 func VP8LInverseTransform(tls *libc.TLS, transform uintptr, row_start int32, row_end int32, in uintptr, out uintptr) {
  50857 	var in_stride, out_stride, width int32
  50858 	var src uintptr
  50859 	var v1, v2 uint32_t
  50860 	_, _, _, _, _, _ = in_stride, out_stride, src, width, v1, v2
  50861 	width = (*VP8LTransform)(unsafe.Pointer(transform)).Fxsize
  50862 	switch (*VP8LTransform)(unsafe.Pointer(transform)).Ftype1 {
  50863 	case int32(SUBTRACT_GREEN_TRANSFORM):
  50864 		(*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8LAddGreenToBlueAndRed})))(tls, in, (row_end-row_start)*width, out)
  50865 	case int32(PREDICTOR_TRANSFORM):
  50866 		PredictorInverseTransform_C(tls, transform, row_start, row_end, in, out)
  50867 		if row_end != (*VP8LTransform)(unsafe.Pointer(transform)).Fysize {
  50868 			// The last predicted row in this iteration will be the top-pred row
  50869 			// for the first row in next iteration.
  50870 			libc.Xmemcpy(tls, out-uintptr(width)*4, out+uintptr((row_end-row_start-int32(1))*width)*4, uint64(width)*uint64(4))
  50871 		}
  50872 	case int32(CROSS_COLOR_TRANSFORM):
  50873 		ColorSpaceInverseTransform_C(tls, transform, row_start, row_end, in, out)
  50874 	case int32(COLOR_INDEXING_TRANSFORM):
  50875 		if in == out && (*VP8LTransform)(unsafe.Pointer(transform)).Fbits > 0 {
  50876 			// Move packed pixels to the end of unpacked region, so that unpacking
  50877 			// can occur seamlessly.
  50878 			// Also, note that this is the only transform that applies on
  50879 			// the effective width of VP8LSubSampleSize(xsize, bits). All other
  50880 			// transforms work on effective width of 'xsize'.
  50881 			out_stride = (row_end - row_start) * width
  50882 			v1 = uint32((*VP8LTransform)(unsafe.Pointer(transform)).Fbits)
  50883 			v2 = (uint32((*VP8LTransform)(unsafe.Pointer(transform)).Fxsize) + uint32(libc.Int32FromInt32(1)<<v1) - uint32(1)) >> v1
  50884 			goto _3
  50885 		_3:
  50886 			in_stride = int32(uint32(row_end-row_start) * v2)
  50887 			src = out + uintptr(out_stride)*4 - uintptr(in_stride)*4
  50888 			libc.Xmemmove(tls, src, out, uint64(in_stride)*uint64(4))
  50889 			ColorIndexInverseTransform_C(tls, transform, row_start, row_end, src, out)
  50890 		} else {
  50891 			ColorIndexInverseTransform_C(tls, transform, row_start, row_end, in, out)
  50892 		}
  50893 		break
  50894 	}
  50895 }
  50896 
  50897 //------------------------------------------------------------------------------
  50898 // Color space conversion.
  50899 
  50900 func is_big_endian(tls *libc.TLS) (r int32) {
  50901 	return libc.BoolInt32(int32(**(**uint8_t)(__ccgo_up(uintptr(unsafe.Pointer(&tmp))))) != int32(1))
  50902 }
  50903 
  50904 var tmp = *(*struct {
  50905 	Fb [0][2]uint8_t
  50906 	Fw uint16_t
  50907 })(unsafe.Pointer(&[1]uint16{0x1}))
  50908 
  50909 func VP8LConvertBGRAToRGB_C(tls *libc.TLS, src uintptr, num_pixels int32, dst uintptr) {
  50910 	var argb uint32_t
  50911 	var src_end, v1, v2 uintptr
  50912 	_, _, _, _ = argb, src_end, v1, v2
  50913 	src_end = src + uintptr(num_pixels)*4
  50914 	for src < src_end {
  50915 		v1 = src
  50916 		src += 4
  50917 		argb = **(**uint32_t)(__ccgo_up(v1))
  50918 		v2 = dst
  50919 		dst = dst + 1
  50920 		**(**uint8_t)(__ccgo_up(v2)) = uint8(argb >> libc.Int32FromInt32(16) & uint32(0xff))
  50921 		v1 = dst
  50922 		dst = dst + 1
  50923 		**(**uint8_t)(__ccgo_up(v1)) = uint8(argb >> libc.Int32FromInt32(8) & uint32(0xff))
  50924 		v1 = dst
  50925 		dst = dst + 1
  50926 		**(**uint8_t)(__ccgo_up(v1)) = uint8(argb >> libc.Int32FromInt32(0) & uint32(0xff))
  50927 	}
  50928 }
  50929 
  50930 func VP8LConvertBGRAToRGBA_C(tls *libc.TLS, src uintptr, num_pixels int32, dst uintptr) {
  50931 	var argb uint32_t
  50932 	var src_end, v1, v2 uintptr
  50933 	_, _, _, _ = argb, src_end, v1, v2
  50934 	src_end = src + uintptr(num_pixels)*4
  50935 	for src < src_end {
  50936 		v1 = src
  50937 		src += 4
  50938 		argb = **(**uint32_t)(__ccgo_up(v1))
  50939 		v2 = dst
  50940 		dst = dst + 1
  50941 		**(**uint8_t)(__ccgo_up(v2)) = uint8(argb >> libc.Int32FromInt32(16) & uint32(0xff))
  50942 		v1 = dst
  50943 		dst = dst + 1
  50944 		**(**uint8_t)(__ccgo_up(v1)) = uint8(argb >> libc.Int32FromInt32(8) & uint32(0xff))
  50945 		v1 = dst
  50946 		dst = dst + 1
  50947 		**(**uint8_t)(__ccgo_up(v1)) = uint8(argb >> libc.Int32FromInt32(0) & uint32(0xff))
  50948 		v1 = dst
  50949 		dst = dst + 1
  50950 		**(**uint8_t)(__ccgo_up(v1)) = uint8(argb >> libc.Int32FromInt32(24) & uint32(0xff))
  50951 	}
  50952 }
  50953 
  50954 func VP8LConvertBGRAToRGBA4444_C(tls *libc.TLS, src uintptr, num_pixels int32, dst uintptr) {
  50955 	var argb uint32_t
  50956 	var ba, rg uint8_t
  50957 	var src_end, v1, v2 uintptr
  50958 	_, _, _, _, _, _ = argb, ba, rg, src_end, v1, v2
  50959 	src_end = src + uintptr(num_pixels)*4
  50960 	for src < src_end {
  50961 		v1 = src
  50962 		src += 4
  50963 		argb = **(**uint32_t)(__ccgo_up(v1))
  50964 		rg = uint8(argb>>libc.Int32FromInt32(16)&uint32(0xf0) | argb>>libc.Int32FromInt32(12)&uint32(0xf))
  50965 		ba = uint8(argb>>libc.Int32FromInt32(0)&uint32(0xf0) | argb>>libc.Int32FromInt32(28)&uint32(0xf))
  50966 		v2 = dst
  50967 		dst = dst + 1
  50968 		**(**uint8_t)(__ccgo_up(v2)) = rg
  50969 		v1 = dst
  50970 		dst = dst + 1
  50971 		**(**uint8_t)(__ccgo_up(v1)) = ba
  50972 	}
  50973 }
  50974 
  50975 func VP8LConvertBGRAToRGB565_C(tls *libc.TLS, src uintptr, num_pixels int32, dst uintptr) {
  50976 	var argb uint32_t
  50977 	var gb, rg uint8_t
  50978 	var src_end, v1, v2 uintptr
  50979 	_, _, _, _, _, _ = argb, gb, rg, src_end, v1, v2
  50980 	src_end = src + uintptr(num_pixels)*4
  50981 	for src < src_end {
  50982 		v1 = src
  50983 		src += 4
  50984 		argb = **(**uint32_t)(__ccgo_up(v1))
  50985 		rg = uint8(argb>>libc.Int32FromInt32(16)&uint32(0xf8) | argb>>libc.Int32FromInt32(13)&uint32(0x7))
  50986 		gb = uint8(argb>>libc.Int32FromInt32(5)&uint32(0xe0) | argb>>libc.Int32FromInt32(3)&uint32(0x1f))
  50987 		v2 = dst
  50988 		dst = dst + 1
  50989 		**(**uint8_t)(__ccgo_up(v2)) = rg
  50990 		v1 = dst
  50991 		dst = dst + 1
  50992 		**(**uint8_t)(__ccgo_up(v1)) = gb
  50993 	}
  50994 }
  50995 
  50996 func VP8LConvertBGRAToBGR_C(tls *libc.TLS, src uintptr, num_pixels int32, dst uintptr) {
  50997 	var argb uint32_t
  50998 	var src_end, v1, v2 uintptr
  50999 	_, _, _, _ = argb, src_end, v1, v2
  51000 	src_end = src + uintptr(num_pixels)*4
  51001 	for src < src_end {
  51002 		v1 = src
  51003 		src += 4
  51004 		argb = **(**uint32_t)(__ccgo_up(v1))
  51005 		v2 = dst
  51006 		dst = dst + 1
  51007 		**(**uint8_t)(__ccgo_up(v2)) = uint8(argb >> libc.Int32FromInt32(0) & uint32(0xff))
  51008 		v1 = dst
  51009 		dst = dst + 1
  51010 		**(**uint8_t)(__ccgo_up(v1)) = uint8(argb >> libc.Int32FromInt32(8) & uint32(0xff))
  51011 		v1 = dst
  51012 		dst = dst + 1
  51013 		**(**uint8_t)(__ccgo_up(v1)) = uint8(argb >> libc.Int32FromInt32(16) & uint32(0xff))
  51014 	}
  51015 }
  51016 
  51017 func CopyOrSwap(tls *libc.TLS, src uintptr, num_pixels int32, dst uintptr, swap_on_big_endian int32) {
  51018 	bp := tls.Alloc(16)
  51019 	defer tls.Free(16)
  51020 	var argb, v2, v4 uint32_t
  51021 	var src_end, v1 uintptr
  51022 	_, _, _, _, _ = argb, src_end, v1, v2, v4
  51023 	if is_big_endian(tls) == swap_on_big_endian {
  51024 		src_end = src + uintptr(num_pixels)*4
  51025 		for src < src_end {
  51026 			v1 = src
  51027 			src += 4
  51028 			argb = **(**uint32_t)(__ccgo_up(v1))
  51029 			v2 = libc.X__builtin_bswap32(tls, argb)
  51030 			goto _3
  51031 		_3:
  51032 			v4 = v2
  51033 			*(*uint32_t)(unsafe.Pointer(bp)) = v4
  51034 			libc.Xmemcpy(tls, dst, bp, uint64(4))
  51035 			dst = dst + uintptr(4)
  51036 		}
  51037 	} else {
  51038 		libc.Xmemcpy(tls, dst, src, uint64(num_pixels)*uint64(4))
  51039 	}
  51040 }
  51041 
  51042 func VP8LConvertFromBGRA(tls *libc.TLS, in_data uintptr, num_pixels int32, out_colorspace WEBP_CSP_MODE1, rgba uintptr) {
  51043 	switch out_colorspace {
  51044 	case int32(MODE_RGB):
  51045 		(*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8LConvertBGRAToRGB})))(tls, in_data, num_pixels, rgba)
  51046 	case int32(MODE_RGBA):
  51047 		(*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8LConvertBGRAToRGBA})))(tls, in_data, num_pixels, rgba)
  51048 	case int32(MODE_rgbA):
  51049 		(*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8LConvertBGRAToRGBA})))(tls, in_data, num_pixels, rgba)
  51050 		(*(*func(*libc.TLS, uintptr, int32, int32, int32, int32))(unsafe.Pointer(&struct{ uintptr }{WebPApplyAlphaMultiply})))(tls, rgba, 0, num_pixels, int32(1), 0)
  51051 	case int32(MODE_BGR):
  51052 		(*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8LConvertBGRAToBGR})))(tls, in_data, num_pixels, rgba)
  51053 	case int32(MODE_BGRA):
  51054 		CopyOrSwap(tls, in_data, num_pixels, rgba, int32(1))
  51055 	case int32(MODE_bgrA):
  51056 		CopyOrSwap(tls, in_data, num_pixels, rgba, int32(1))
  51057 		(*(*func(*libc.TLS, uintptr, int32, int32, int32, int32))(unsafe.Pointer(&struct{ uintptr }{WebPApplyAlphaMultiply})))(tls, rgba, 0, num_pixels, int32(1), 0)
  51058 	case int32(MODE_ARGB):
  51059 		CopyOrSwap(tls, in_data, num_pixels, rgba, 0)
  51060 	case int32(MODE_Argb):
  51061 		CopyOrSwap(tls, in_data, num_pixels, rgba, 0)
  51062 		(*(*func(*libc.TLS, uintptr, int32, int32, int32, int32))(unsafe.Pointer(&struct{ uintptr }{WebPApplyAlphaMultiply})))(tls, rgba, int32(1), num_pixels, int32(1), 0)
  51063 	case int32(MODE_RGBA_4444):
  51064 		(*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8LConvertBGRAToRGBA4444})))(tls, in_data, num_pixels, rgba)
  51065 	case int32(MODE_rgbA_4444):
  51066 		(*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8LConvertBGRAToRGBA4444})))(tls, in_data, num_pixels, rgba)
  51067 		(*(*func(*libc.TLS, uintptr, int32, int32, int32))(unsafe.Pointer(&struct{ uintptr }{WebPApplyAlphaMultiply4444})))(tls, rgba, num_pixels, int32(1), 0)
  51068 	case int32(MODE_RGB_565):
  51069 		(*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8LConvertBGRAToRGB565})))(tls, in_data, num_pixels, rgba)
  51070 	default:
  51071 		// Code flow should not reach here.
  51072 	}
  51073 }
  51074 
  51075 func VP8LDspInit(tls *libc.TLS) {
  51076 	if libc.AtomicLoadPUintptr(uintptr(unsafe.Pointer(&VP8LDspInit_body_last_cpuinfo_used))) == VP8GetCPUInfo {
  51077 		goto _1
  51078 	}
  51079 	VP8LDspInit_body(tls)
  51080 	libc.AtomicStorePUintptr(uintptr(unsafe.Pointer(&VP8LDspInit_body_last_cpuinfo_used)), VP8GetCPUInfo)
  51081 	goto _2
  51082 _2:
  51083 	;
  51084 	goto _1
  51085 _1: /**/ //
  51086 }
  51087 
  51088 var VP8LDspInit_body_last_cpuinfo_used = uintptr(0)
  51089 
  51090 func init() {
  51091 	p := unsafe.Pointer(&VP8LDspInit_body_last_cpuinfo_used)
  51092 	*(*uintptr)(unsafe.Add(p, 0)) = uintptr(unsafe.Pointer(&VP8LDspInit_body_last_cpuinfo_used))
  51093 }
  51094 
  51095 func VP8LDspInit_body(tls *libc.TLS) {
  51096 	VP8LPredictors[0] = __ccgo_fp(VP8LPredictor0_C)
  51097 	VP8LPredictors[int32(1)] = __ccgo_fp(VP8LPredictor1_C)
  51098 	VP8LPredictors[int32(2)] = __ccgo_fp(VP8LPredictor2_C)
  51099 	VP8LPredictors[int32(3)] = __ccgo_fp(VP8LPredictor3_C)
  51100 	VP8LPredictors[int32(4)] = __ccgo_fp(VP8LPredictor4_C)
  51101 	VP8LPredictors[int32(5)] = __ccgo_fp(VP8LPredictor5_C)
  51102 	VP8LPredictors[int32(6)] = __ccgo_fp(VP8LPredictor6_C)
  51103 	VP8LPredictors[int32(7)] = __ccgo_fp(VP8LPredictor7_C)
  51104 	VP8LPredictors[int32(8)] = __ccgo_fp(VP8LPredictor8_C)
  51105 	VP8LPredictors[int32(9)] = __ccgo_fp(VP8LPredictor9_C)
  51106 	VP8LPredictors[int32(10)] = __ccgo_fp(VP8LPredictor10_C)
  51107 	VP8LPredictors[int32(11)] = __ccgo_fp(VP8LPredictor11_C)
  51108 	VP8LPredictors[int32(12)] = __ccgo_fp(VP8LPredictor12_C)
  51109 	VP8LPredictors[int32(13)] = __ccgo_fp(VP8LPredictor13_C)
  51110 	VP8LPredictors[int32(14)] = __ccgo_fp(VP8LPredictor0_C) /* <- padding security sentinels*/
  51111 	VP8LPredictors[int32(15)] = __ccgo_fp(VP8LPredictor0_C)
  51112 	VP8LPredictorsAdd[0] = __ccgo_fp(PredictorAdd0_C)
  51113 	VP8LPredictorsAdd[int32(1)] = __ccgo_fp(PredictorAdd1_C)
  51114 	VP8LPredictorsAdd[int32(2)] = __ccgo_fp(PredictorAdd2_C)
  51115 	VP8LPredictorsAdd[int32(3)] = __ccgo_fp(PredictorAdd3_C)
  51116 	VP8LPredictorsAdd[int32(4)] = __ccgo_fp(PredictorAdd4_C)
  51117 	VP8LPredictorsAdd[int32(5)] = __ccgo_fp(PredictorAdd5_C)
  51118 	VP8LPredictorsAdd[int32(6)] = __ccgo_fp(PredictorAdd6_C)
  51119 	VP8LPredictorsAdd[int32(7)] = __ccgo_fp(PredictorAdd7_C)
  51120 	VP8LPredictorsAdd[int32(8)] = __ccgo_fp(PredictorAdd8_C)
  51121 	VP8LPredictorsAdd[int32(9)] = __ccgo_fp(PredictorAdd9_C)
  51122 	VP8LPredictorsAdd[int32(10)] = __ccgo_fp(PredictorAdd10_C)
  51123 	VP8LPredictorsAdd[int32(11)] = __ccgo_fp(PredictorAdd11_C)
  51124 	VP8LPredictorsAdd[int32(12)] = __ccgo_fp(PredictorAdd12_C)
  51125 	VP8LPredictorsAdd[int32(13)] = __ccgo_fp(PredictorAdd13_C)
  51126 	VP8LPredictorsAdd[int32(14)] = __ccgo_fp(PredictorAdd0_C) /* <- padding security sentinels*/
  51127 	VP8LPredictorsAdd[int32(15)] = __ccgo_fp(PredictorAdd0_C)
  51128 	VP8LPredictorsAdd_C[0] = __ccgo_fp(PredictorAdd0_C)
  51129 	VP8LPredictorsAdd_C[int32(1)] = __ccgo_fp(PredictorAdd1_C)
  51130 	VP8LPredictorsAdd_C[int32(2)] = __ccgo_fp(PredictorAdd2_C)
  51131 	VP8LPredictorsAdd_C[int32(3)] = __ccgo_fp(PredictorAdd3_C)
  51132 	VP8LPredictorsAdd_C[int32(4)] = __ccgo_fp(PredictorAdd4_C)
  51133 	VP8LPredictorsAdd_C[int32(5)] = __ccgo_fp(PredictorAdd5_C)
  51134 	VP8LPredictorsAdd_C[int32(6)] = __ccgo_fp(PredictorAdd6_C)
  51135 	VP8LPredictorsAdd_C[int32(7)] = __ccgo_fp(PredictorAdd7_C)
  51136 	VP8LPredictorsAdd_C[int32(8)] = __ccgo_fp(PredictorAdd8_C)
  51137 	VP8LPredictorsAdd_C[int32(9)] = __ccgo_fp(PredictorAdd9_C)
  51138 	VP8LPredictorsAdd_C[int32(10)] = __ccgo_fp(PredictorAdd10_C)
  51139 	VP8LPredictorsAdd_C[int32(11)] = __ccgo_fp(PredictorAdd11_C)
  51140 	VP8LPredictorsAdd_C[int32(12)] = __ccgo_fp(PredictorAdd12_C)
  51141 	VP8LPredictorsAdd_C[int32(13)] = __ccgo_fp(PredictorAdd13_C)
  51142 	VP8LPredictorsAdd_C[int32(14)] = __ccgo_fp(PredictorAdd0_C) /* <- padding security sentinels*/
  51143 	VP8LPredictorsAdd_C[int32(15)] = __ccgo_fp(PredictorAdd0_C)
  51144 	VP8LAddGreenToBlueAndRed = __ccgo_fp(VP8LAddGreenToBlueAndRed_C)
  51145 	VP8LTransformColorInverse = __ccgo_fp(VP8LTransformColorInverse_C)
  51146 	VP8LConvertBGRAToRGBA = __ccgo_fp(VP8LConvertBGRAToRGBA_C)
  51147 	VP8LConvertBGRAToRGB = __ccgo_fp(VP8LConvertBGRAToRGB_C)
  51148 	VP8LConvertBGRAToBGR = __ccgo_fp(VP8LConvertBGRAToBGR_C)
  51149 	VP8LConvertBGRAToRGBA4444 = __ccgo_fp(VP8LConvertBGRAToRGBA4444_C)
  51150 	VP8LConvertBGRAToRGB565 = __ccgo_fp(VP8LConvertBGRAToRGB565_C)
  51151 	VP8LMapColor32b = __ccgo_fp(MapARGB_C)
  51152 	VP8LMapColor8b = __ccgo_fp(MapAlpha_C)
  51153 	// If defined, use CPUInfo() to overwrite some pointers with faster versions.
  51154 	if VP8GetCPUInfo != libc.UintptrFromInt32(0) {
  51155 	}
  51156 }
  51157 
  51158 func VP8LEncDspInitAVX2(tls *libc.TLS) {
  51159 }
  51160 
  51161 const LOG_2_RECIPROCAL_FIXED_DOUBLE1 = 1.2102203161561485e+07
  51162 const SIZE_MAX28 = "_UI64_MAX"
  51163 
  51164 func FastSLog2Slow_C(tls *libc.TLS, v uint32_t) (r uint64_t) {
  51165 	var correction, log_cnt, orig_v uint64_t
  51166 	var y uint32_t
  51167 	var v1 int32
  51168 	_, _, _, _, _ = correction, log_cnt, orig_v, y, v1
  51169 	if v < uint32(APPROX_LOG_WITH_CORRECTION_MAX) {
  51170 		orig_v = uint64(v)
  51171 		v1 = int32(31) ^ libc.X__builtin_clz(tls, v)
  51172 		goto _2
  51173 	_2:
  51174 		// use clz if available
  51175 		log_cnt = uint64(v1 - int32(7))
  51176 		y = uint32(int32(1) << log_cnt)
  51177 		v = uint32(uint64(v) >> log_cnt)
  51178 		// vf = (2^log_cnt) * Xf; where y = 2^log_cnt and Xf < 256
  51179 		// Xf = floor(Xf) * (1 + (v % y) / v)
  51180 		// log2(Xf) = log2(floor(Xf)) + log2(1 + (v % y) / v)
  51181 		// The correction factor: log(1 + d) ~ d; for very small d values, so
  51182 		// log2(1 + (v % y) / v) ~ LOG_2_RECIPROCAL * (v % y)/v
  51183 		correction = libc.Uint64FromInt32(12102203) * (orig_v & uint64(y-libc.Uint32FromInt32(1)))
  51184 		return orig_v*(uint64(kLog2Table[v])+log_cnt<<libc.Int32FromInt32(LOG_2_PRECISION_BITS)) + correction
  51185 	} else {
  51186 		return uint64(float64(float64(libc.Float64FromFloat64(1.2102203161561485e+07)*float64(v))*libc.Xlog(tls, float64(v))) + libc.Float64FromFloat64(0.5))
  51187 	}
  51188 	return r
  51189 }
  51190 
  51191 func FastLog2Slow_C(tls *libc.TLS, v uint32_t) (r uint32_t) {
  51192 	var correction uint64_t
  51193 	var log_2, log_cnt, orig_v, y uint32_t
  51194 	var v1 int32
  51195 	var v3, v4, v5 int64_t
  51196 	var v7 int64
  51197 	_, _, _, _, _, _, _, _, _, _ = correction, log_2, log_cnt, orig_v, y, v1, v3, v4, v5, v7
  51198 	if v < uint32(APPROX_LOG_WITH_CORRECTION_MAX) {
  51199 		orig_v = v
  51200 		v1 = int32(31) ^ libc.X__builtin_clz(tls, v)
  51201 		goto _2
  51202 	_2:
  51203 		// use clz if available
  51204 		log_cnt = uint32(v1 - int32(7))
  51205 		y = uint32(int32(1) << log_cnt)
  51206 		v = v >> log_cnt
  51207 		log_2 = kLog2Table[v] + log_cnt<<libc.Int32FromInt32(LOG_2_PRECISION_BITS)
  51208 		if orig_v >= uint32(APPROX_LOG_MAX) {
  51209 			// Since the division is still expensive, add this correction factor only
  51210 			// for large values of 'v'.
  51211 			correction = libc.Uint64FromInt32(12102203) * uint64(orig_v&(y-libc.Uint32FromInt32(1)))
  51212 			v3 = int64(correction)
  51213 			v4 = int64(orig_v)
  51214 			if libc.BoolInt32(v3 < 0) == libc.BoolInt32(v4 < 0) {
  51215 				v7 = (v3 + v4/int64(2)) / v4
  51216 			} else {
  51217 				v7 = (v3 - v4/int64(2)) / v4
  51218 			}
  51219 			v5 = v7
  51220 			goto _6
  51221 		_6:
  51222 			log_2 = log_2 + uint32(v5)
  51223 		}
  51224 		return log_2
  51225 	} else {
  51226 		return uint32(float64(libc.Float64FromFloat64(1.2102203161561485e+07)*libc.Xlog(tls, float64(v))) + libc.Float64FromFloat64(0.5))
  51227 	}
  51228 	return r
  51229 }
  51230 
  51231 //------------------------------------------------------------------------------
  51232 // Methods to calculate Entropy (Shannon).
  51233 
  51234 // C documentation
  51235 //
  51236 //	// Compute the combined Shanon's entropy for distribution {X} and {X+Y}
  51237 func CombinedShannonEntropy_C(tls *libc.TLS, X uintptr, Y uintptr) (r uint64_t) {
  51238 	var i int32
  51239 	var retval, v3, v7 uint64_t
  51240 	var sumX, sumXY, x, xy, v2, v6 uint32_t
  51241 	var v5, v9 uint64
  51242 	_, _, _, _, _, _, _, _, _, _, _, _ = i, retval, sumX, sumXY, x, xy, v2, v3, v5, v6, v7, v9
  51243 	retval = uint64(0)
  51244 	sumX = uint32(0)
  51245 	sumXY = uint32(0)
  51246 	i = 0
  51247 	for {
  51248 		if !(i < int32(256)) {
  51249 			break
  51250 		}
  51251 		x = **(**uint32_t)(__ccgo_up(X + uintptr(i)*4))
  51252 		if x != uint32(0) {
  51253 			xy = x + **(**uint32_t)(__ccgo_up(Y + uintptr(i)*4))
  51254 			sumX = sumX + x
  51255 			v2 = x
  51256 			if v2 < uint32(LOG_LOOKUP_IDX_MAX) {
  51257 				v5 = kSLog2Table[v2]
  51258 			} else {
  51259 				v5 = (*(*func(*libc.TLS, uint32_t) uint64_t)(unsafe.Pointer(&struct{ uintptr }{VP8LFastSLog2Slow})))(tls, v2)
  51260 			}
  51261 			v3 = v5
  51262 			goto _4
  51263 		_4:
  51264 			retval = retval + v3
  51265 			sumXY = sumXY + xy
  51266 			v2 = xy
  51267 			if v2 < uint32(LOG_LOOKUP_IDX_MAX) {
  51268 				v5 = kSLog2Table[v2]
  51269 			} else {
  51270 				v5 = (*(*func(*libc.TLS, uint32_t) uint64_t)(unsafe.Pointer(&struct{ uintptr }{VP8LFastSLog2Slow})))(tls, v2)
  51271 			}
  51272 			v3 = v5
  51273 			goto _8
  51274 		_8:
  51275 			retval = retval + v3
  51276 		} else {
  51277 			if **(**uint32_t)(__ccgo_up(Y + uintptr(i)*4)) != uint32(0) {
  51278 				sumXY = sumXY + **(**uint32_t)(__ccgo_up(Y + uintptr(i)*4))
  51279 				v2 = **(**uint32_t)(__ccgo_up(Y + uintptr(i)*4))
  51280 				if v2 < uint32(LOG_LOOKUP_IDX_MAX) {
  51281 					v5 = kSLog2Table[v2]
  51282 				} else {
  51283 					v5 = (*(*func(*libc.TLS, uint32_t) uint64_t)(unsafe.Pointer(&struct{ uintptr }{VP8LFastSLog2Slow})))(tls, v2)
  51284 				}
  51285 				v3 = v5
  51286 				goto _12
  51287 			_12:
  51288 				retval = retval + v3
  51289 			}
  51290 		}
  51291 		goto _1
  51292 	_1:
  51293 		;
  51294 		i = i + 1
  51295 	}
  51296 	v2 = sumX
  51297 	if v2 < uint32(LOG_LOOKUP_IDX_MAX) {
  51298 		v5 = kSLog2Table[v2]
  51299 	} else {
  51300 		v5 = (*(*func(*libc.TLS, uint32_t) uint64_t)(unsafe.Pointer(&struct{ uintptr }{VP8LFastSLog2Slow})))(tls, v2)
  51301 	}
  51302 	v3 = v5
  51303 	goto _16
  51304 _16:
  51305 	v6 = sumXY
  51306 	if v6 < uint32(LOG_LOOKUP_IDX_MAX) {
  51307 		v9 = kSLog2Table[v6]
  51308 	} else {
  51309 		v9 = (*(*func(*libc.TLS, uint32_t) uint64_t)(unsafe.Pointer(&struct{ uintptr }{VP8LFastSLog2Slow})))(tls, v6)
  51310 	}
  51311 	v7 = v9
  51312 	goto _20
  51313 _20:
  51314 	retval = v3 + v7 - retval
  51315 	return retval
  51316 }
  51317 
  51318 func ShannonEntropy_C(tls *libc.TLS, X uintptr, n int32) (r uint64_t) {
  51319 	var i, x int32
  51320 	var retval, v3 uint64_t
  51321 	var sumX, v2 uint32_t
  51322 	var v5 uint64
  51323 	_, _, _, _, _, _, _ = i, retval, sumX, x, v2, v3, v5
  51324 	retval = uint64(0)
  51325 	sumX = uint32(0)
  51326 	i = 0
  51327 	for {
  51328 		if !(i < n) {
  51329 			break
  51330 		}
  51331 		x = int32(**(**uint32_t)(__ccgo_up(X + uintptr(i)*4)))
  51332 		if x != 0 {
  51333 			sumX = sumX + uint32(x)
  51334 			v2 = uint32(x)
  51335 			if v2 < uint32(LOG_LOOKUP_IDX_MAX) {
  51336 				v5 = kSLog2Table[v2]
  51337 			} else {
  51338 				v5 = (*(*func(*libc.TLS, uint32_t) uint64_t)(unsafe.Pointer(&struct{ uintptr }{VP8LFastSLog2Slow})))(tls, v2)
  51339 			}
  51340 			v3 = v5
  51341 			goto _4
  51342 		_4:
  51343 			retval = retval + v3
  51344 		}
  51345 		goto _1
  51346 	_1:
  51347 		;
  51348 		i = i + 1
  51349 	}
  51350 	v2 = sumX
  51351 	if v2 < uint32(LOG_LOOKUP_IDX_MAX) {
  51352 		v5 = kSLog2Table[v2]
  51353 	} else {
  51354 		v5 = (*(*func(*libc.TLS, uint32_t) uint64_t)(unsafe.Pointer(&struct{ uintptr }{VP8LFastSLog2Slow})))(tls, v2)
  51355 	}
  51356 	v3 = v5
  51357 	goto _8
  51358 _8:
  51359 	retval = v3 - retval
  51360 	return retval
  51361 }
  51362 
  51363 func VP8LBitEntropyInit(tls *libc.TLS, entropy uintptr) {
  51364 	(*VP8LBitEntropy)(unsafe.Pointer(entropy)).Fentropy = uint64(0)
  51365 	(*VP8LBitEntropy)(unsafe.Pointer(entropy)).Fsum = uint32(0)
  51366 	(*VP8LBitEntropy)(unsafe.Pointer(entropy)).Fnonzeros = 0
  51367 	(*VP8LBitEntropy)(unsafe.Pointer(entropy)).Fmax_val = uint32(0)
  51368 	(*VP8LBitEntropy)(unsafe.Pointer(entropy)).Fnonzero_code = uint32(uint16(libc.Int32FromInt32(0xffff)))
  51369 }
  51370 
  51371 func VP8LBitsEntropyUnrefined(tls *libc.TLS, array uintptr, n int32, entropy uintptr) {
  51372 	var i int32
  51373 	var v2 uint32_t
  51374 	var v3 uint64_t
  51375 	var v5 uint64
  51376 	_, _, _, _ = i, v2, v3, v5
  51377 	VP8LBitEntropyInit(tls, entropy)
  51378 	i = 0
  51379 	for {
  51380 		if !(i < n) {
  51381 			break
  51382 		}
  51383 		if **(**uint32_t)(__ccgo_up(array + uintptr(i)*4)) != uint32(0) {
  51384 			**(**uint32_t)(__ccgo_up(entropy + 8)) += **(**uint32_t)(__ccgo_up(array + uintptr(i)*4))
  51385 			(*VP8LBitEntropy)(unsafe.Pointer(entropy)).Fnonzero_code = uint32(i)
  51386 			(*VP8LBitEntropy)(unsafe.Pointer(entropy)).Fnonzeros = (*VP8LBitEntropy)(unsafe.Pointer(entropy)).Fnonzeros + 1
  51387 			v2 = **(**uint32_t)(__ccgo_up(array + uintptr(i)*4))
  51388 			if v2 < uint32(LOG_LOOKUP_IDX_MAX) {
  51389 				v5 = kSLog2Table[v2]
  51390 			} else {
  51391 				v5 = (*(*func(*libc.TLS, uint32_t) uint64_t)(unsafe.Pointer(&struct{ uintptr }{VP8LFastSLog2Slow})))(tls, v2)
  51392 			}
  51393 			v3 = v5
  51394 			goto _4
  51395 		_4:
  51396 			**(**uint64_t)(__ccgo_up(entropy)) += v3
  51397 			if (*VP8LBitEntropy)(unsafe.Pointer(entropy)).Fmax_val < **(**uint32_t)(__ccgo_up(array + uintptr(i)*4)) {
  51398 				(*VP8LBitEntropy)(unsafe.Pointer(entropy)).Fmax_val = **(**uint32_t)(__ccgo_up(array + uintptr(i)*4))
  51399 			}
  51400 		}
  51401 		goto _1
  51402 	_1:
  51403 		;
  51404 		i = i + 1
  51405 	}
  51406 	v2 = (*VP8LBitEntropy)(unsafe.Pointer(entropy)).Fsum
  51407 	if v2 < uint32(LOG_LOOKUP_IDX_MAX) {
  51408 		v5 = kSLog2Table[v2]
  51409 	} else {
  51410 		v5 = (*(*func(*libc.TLS, uint32_t) uint64_t)(unsafe.Pointer(&struct{ uintptr }{VP8LFastSLog2Slow})))(tls, v2)
  51411 	}
  51412 	v3 = v5
  51413 	goto _8
  51414 _8:
  51415 	(*VP8LBitEntropy)(unsafe.Pointer(entropy)).Fentropy = v3 - (*VP8LBitEntropy)(unsafe.Pointer(entropy)).Fentropy
  51416 }
  51417 
  51418 func GetEntropyUnrefinedHelper(tls *libc.TLS, val uint32_t, i int32, val_prev uintptr, i_prev uintptr, bit_entropy uintptr, stats uintptr) {
  51419 	var streak int32
  51420 	var v1 uint32_t
  51421 	var v2 uint64_t
  51422 	var v4 uint64
  51423 	_, _, _, _ = streak, v1, v2, v4
  51424 	streak = i - **(**int32)(__ccgo_up(i_prev))
  51425 	// Gather info for the bit entropy.
  51426 	if **(**uint32_t)(__ccgo_up(val_prev)) != uint32(0) {
  51427 		**(**uint32_t)(__ccgo_up(bit_entropy + 8)) += **(**uint32_t)(__ccgo_up(val_prev)) * uint32(streak)
  51428 		**(**int32)(__ccgo_up(bit_entropy + 12)) += streak
  51429 		(*VP8LBitEntropy)(unsafe.Pointer(bit_entropy)).Fnonzero_code = uint32(**(**int32)(__ccgo_up(i_prev)))
  51430 		v1 = **(**uint32_t)(__ccgo_up(val_prev))
  51431 		if v1 < uint32(LOG_LOOKUP_IDX_MAX) {
  51432 			v4 = kSLog2Table[v1]
  51433 		} else {
  51434 			v4 = (*(*func(*libc.TLS, uint32_t) uint64_t)(unsafe.Pointer(&struct{ uintptr }{VP8LFastSLog2Slow})))(tls, v1)
  51435 		}
  51436 		v2 = v4
  51437 		goto _3
  51438 	_3:
  51439 		**(**uint64_t)(__ccgo_up(bit_entropy)) += v2 * uint64(streak)
  51440 		if (*VP8LBitEntropy)(unsafe.Pointer(bit_entropy)).Fmax_val < **(**uint32_t)(__ccgo_up(val_prev)) {
  51441 			(*VP8LBitEntropy)(unsafe.Pointer(bit_entropy)).Fmax_val = **(**uint32_t)(__ccgo_up(val_prev))
  51442 		}
  51443 	}
  51444 	// Gather info for the Huffman cost.
  51445 	**(**int32)(__ccgo_up(stats + libc.BoolUintptr(**(**uint32_t)(__ccgo_up(val_prev)) != uint32(0))*4)) += libc.BoolInt32(streak > int32(3))
  51446 	**(**int32)(__ccgo_up(stats + 8 + libc.BoolUintptr(**(**uint32_t)(__ccgo_up(val_prev)) != uint32(0))*8 + libc.BoolUintptr(streak > libc.Int32FromInt32(3))*4)) += streak
  51447 	**(**uint32_t)(__ccgo_up(val_prev)) = val
  51448 	**(**int32)(__ccgo_up(i_prev)) = i
  51449 }
  51450 
  51451 func GetEntropyUnrefined_C(tls *libc.TLS, X uintptr, length int32, bit_entropy uintptr, stats uintptr) {
  51452 	bp := tls.Alloc(16)
  51453 	defer tls.Free(16)
  51454 	var i int32
  51455 	var x, v2 uint32_t
  51456 	var v3 uint64_t
  51457 	var v5 uint64
  51458 	var _ /* i_prev at bp+0 */ int32
  51459 	var _ /* x_prev at bp+4 */ uint32_t
  51460 	_, _, _, _, _ = i, x, v2, v3, v5
  51461 	**(**int32)(__ccgo_up(bp)) = 0
  51462 	**(**uint32_t)(__ccgo_up(bp + 4)) = **(**uint32_t)(__ccgo_up(X))
  51463 	libc.Xmemset(tls, stats, 0, uint64(24))
  51464 	VP8LBitEntropyInit(tls, bit_entropy)
  51465 	i = int32(1)
  51466 	for {
  51467 		if !(i < length) {
  51468 			break
  51469 		}
  51470 		x = **(**uint32_t)(__ccgo_up(X + uintptr(i)*4))
  51471 		if x != **(**uint32_t)(__ccgo_up(bp + 4)) {
  51472 			GetEntropyUnrefinedHelper(tls, x, i, bp+4, bp, bit_entropy, stats)
  51473 		}
  51474 		goto _1
  51475 	_1:
  51476 		;
  51477 		i = i + 1
  51478 	}
  51479 	GetEntropyUnrefinedHelper(tls, uint32(0), i, bp+4, bp, bit_entropy, stats)
  51480 	v2 = (*VP8LBitEntropy)(unsafe.Pointer(bit_entropy)).Fsum
  51481 	if v2 < uint32(LOG_LOOKUP_IDX_MAX) {
  51482 		v5 = kSLog2Table[v2]
  51483 	} else {
  51484 		v5 = (*(*func(*libc.TLS, uint32_t) uint64_t)(unsafe.Pointer(&struct{ uintptr }{VP8LFastSLog2Slow})))(tls, v2)
  51485 	}
  51486 	v3 = v5
  51487 	goto _4
  51488 _4:
  51489 	(*VP8LBitEntropy)(unsafe.Pointer(bit_entropy)).Fentropy = v3 - (*VP8LBitEntropy)(unsafe.Pointer(bit_entropy)).Fentropy
  51490 }
  51491 
  51492 func GetCombinedEntropyUnrefined_C(tls *libc.TLS, X uintptr, Y uintptr, length int32, bit_entropy uintptr, stats uintptr) {
  51493 	bp := tls.Alloc(16)
  51494 	defer tls.Free(16)
  51495 	var i int32
  51496 	var xy, v2 uint32_t
  51497 	var v3 uint64_t
  51498 	var v5 uint64
  51499 	var _ /* i_prev at bp+0 */ int32
  51500 	var _ /* xy_prev at bp+4 */ uint32_t
  51501 	_, _, _, _, _ = i, xy, v2, v3, v5
  51502 	i = int32(1)
  51503 	**(**int32)(__ccgo_up(bp)) = 0
  51504 	**(**uint32_t)(__ccgo_up(bp + 4)) = **(**uint32_t)(__ccgo_up(X)) + **(**uint32_t)(__ccgo_up(Y))
  51505 	libc.Xmemset(tls, stats, 0, uint64(24))
  51506 	VP8LBitEntropyInit(tls, bit_entropy)
  51507 	i = int32(1)
  51508 	for {
  51509 		if !(i < length) {
  51510 			break
  51511 		}
  51512 		xy = **(**uint32_t)(__ccgo_up(X + uintptr(i)*4)) + **(**uint32_t)(__ccgo_up(Y + uintptr(i)*4))
  51513 		if xy != **(**uint32_t)(__ccgo_up(bp + 4)) {
  51514 			GetEntropyUnrefinedHelper(tls, xy, i, bp+4, bp, bit_entropy, stats)
  51515 		}
  51516 		goto _1
  51517 	_1:
  51518 		;
  51519 		i = i + 1
  51520 	}
  51521 	GetEntropyUnrefinedHelper(tls, uint32(0), i, bp+4, bp, bit_entropy, stats)
  51522 	v2 = (*VP8LBitEntropy)(unsafe.Pointer(bit_entropy)).Fsum
  51523 	if v2 < uint32(LOG_LOOKUP_IDX_MAX) {
  51524 		v5 = kSLog2Table[v2]
  51525 	} else {
  51526 		v5 = (*(*func(*libc.TLS, uint32_t) uint64_t)(unsafe.Pointer(&struct{ uintptr }{VP8LFastSLog2Slow})))(tls, v2)
  51527 	}
  51528 	v3 = v5
  51529 	goto _4
  51530 _4:
  51531 	(*VP8LBitEntropy)(unsafe.Pointer(bit_entropy)).Fentropy = v3 - (*VP8LBitEntropy)(unsafe.Pointer(bit_entropy)).Fentropy
  51532 }
  51533 
  51534 //------------------------------------------------------------------------------
  51535 
  51536 func VP8LSubtractGreenFromBlueAndRed_C(tls *libc.TLS, argb_data uintptr, num_pixels int32) {
  51537 	var argb, green, i int32
  51538 	var new_b, new_r uint32_t
  51539 	_, _, _, _, _ = argb, green, i, new_b, new_r
  51540 	i = 0
  51541 	for {
  51542 		if !(i < num_pixels) {
  51543 			break
  51544 		}
  51545 		argb = int32(**(**uint32_t)(__ccgo_up(argb_data + uintptr(i)*4)))
  51546 		green = argb >> libc.Int32FromInt32(8) & int32(0xff)
  51547 		new_r = uint32((argb>>libc.Int32FromInt32(16)&int32(0xff) - green) & int32(0xff))
  51548 		new_b = uint32((argb>>libc.Int32FromInt32(0)&int32(0xff) - green) & int32(0xff))
  51549 		**(**uint32_t)(__ccgo_up(argb_data + uintptr(i)*4)) = uint32(argb)&uint32(0xff00ff00) | new_r<<libc.Int32FromInt32(16) | new_b
  51550 		goto _1
  51551 	_1:
  51552 		;
  51553 		i = i + 1
  51554 	}
  51555 }
  51556 
  51557 func ColorTransformDelta1(tls *libc.TLS, color_pred int8_t, color int8_t) (r int32) {
  51558 	return int32(color_pred) * int32(color) >> int32(5)
  51559 }
  51560 
  51561 func U32ToS8(tls *libc.TLS, v uint32_t) (r int8_t) {
  51562 	return int8(v & libc.Uint32FromInt32(0xff))
  51563 }
  51564 
  51565 func VP8LTransformColor_C(tls *libc.TLS, m uintptr, data uintptr, num_pixels int32) {
  51566 	var argb uint32_t
  51567 	var green, red int8_t
  51568 	var i, new_blue, new_red int32
  51569 	_, _, _, _, _, _ = argb, green, i, new_blue, new_red, red
  51570 	i = 0
  51571 	for {
  51572 		if !(i < num_pixels) {
  51573 			break
  51574 		}
  51575 		argb = **(**uint32_t)(__ccgo_up(data + uintptr(i)*4))
  51576 		green = U32ToS8(tls, argb>>int32(8))
  51577 		red = U32ToS8(tls, argb>>int32(16))
  51578 		new_red = int32(red) & int32(0xff)
  51579 		new_blue = int32(argb & uint32(0xff))
  51580 		new_red = new_red - ColorTransformDelta1(tls, int8((*VP8LMultipliers)(unsafe.Pointer(m)).Fgreen_to_red), green)
  51581 		new_red = new_red & int32(0xff)
  51582 		new_blue = new_blue - ColorTransformDelta1(tls, int8((*VP8LMultipliers)(unsafe.Pointer(m)).Fgreen_to_blue), green)
  51583 		new_blue = new_blue - ColorTransformDelta1(tls, int8((*VP8LMultipliers)(unsafe.Pointer(m)).Fred_to_blue), red)
  51584 		new_blue = new_blue & int32(0xff)
  51585 		**(**uint32_t)(__ccgo_up(data + uintptr(i)*4)) = argb&uint32(0xff00ff00) | uint32(new_red<<libc.Int32FromInt32(16)) | uint32(new_blue)
  51586 		goto _1
  51587 	_1:
  51588 		;
  51589 		i = i + 1
  51590 	}
  51591 }
  51592 
  51593 func TransformColorRed(tls *libc.TLS, green_to_red uint8_t, argb uint32_t) (r uint8_t) {
  51594 	var green int8_t
  51595 	var new_red int32
  51596 	_, _ = green, new_red
  51597 	green = U32ToS8(tls, argb>>int32(8))
  51598 	new_red = int32(argb >> int32(16))
  51599 	new_red = new_red - ColorTransformDelta1(tls, int8(green_to_red), green)
  51600 	return uint8(new_red & libc.Int32FromInt32(0xff))
  51601 }
  51602 
  51603 func TransformColorBlue(tls *libc.TLS, green_to_blue uint8_t, red_to_blue uint8_t, argb uint32_t) (r uint8_t) {
  51604 	var green, red int8_t
  51605 	var new_blue int32
  51606 	_, _, _ = green, new_blue, red
  51607 	green = U32ToS8(tls, argb>>int32(8))
  51608 	red = U32ToS8(tls, argb>>int32(16))
  51609 	new_blue = int32(argb & uint32(0xff))
  51610 	new_blue = new_blue - ColorTransformDelta1(tls, int8(green_to_blue), green)
  51611 	new_blue = new_blue - ColorTransformDelta1(tls, int8(red_to_blue), red)
  51612 	return uint8(new_blue & libc.Int32FromInt32(0xff))
  51613 }
  51614 
  51615 func VP8LCollectColorRedTransforms_C(tls *libc.TLS, argb uintptr, stride int32, tile_width int32, tile_height int32, green_to_red int32, histo uintptr) {
  51616 	var x, v1 int32
  51617 	_, _ = x, v1
  51618 	for {
  51619 		v1 = tile_height
  51620 		tile_height = tile_height - 1
  51621 		if !(v1 > 0) {
  51622 			break
  51623 		}
  51624 		x = 0
  51625 		for {
  51626 			if !(x < tile_width) {
  51627 				break
  51628 			}
  51629 			**(**uint32_t)(__ccgo_up(histo + uintptr(TransformColorRed(tls, uint8(green_to_red), **(**uint32_t)(__ccgo_up(argb + uintptr(x)*4))))*4)) = **(**uint32_t)(__ccgo_up(histo + uintptr(TransformColorRed(tls, uint8(green_to_red), **(**uint32_t)(__ccgo_up(argb + uintptr(x)*4))))*4)) + 1
  51630 			goto _2
  51631 		_2:
  51632 			;
  51633 			x = x + 1
  51634 		}
  51635 		argb = argb + uintptr(stride)*4
  51636 	}
  51637 }
  51638 
  51639 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) {
  51640 	var x, v1 int32
  51641 	_, _ = x, v1
  51642 	for {
  51643 		v1 = tile_height
  51644 		tile_height = tile_height - 1
  51645 		if !(v1 > 0) {
  51646 			break
  51647 		}
  51648 		x = 0
  51649 		for {
  51650 			if !(x < tile_width) {
  51651 				break
  51652 			}
  51653 			**(**uint32_t)(__ccgo_up(histo + uintptr(TransformColorBlue(tls, uint8(green_to_blue), uint8(red_to_blue), **(**uint32_t)(__ccgo_up(argb + uintptr(x)*4))))*4)) = **(**uint32_t)(__ccgo_up(histo + uintptr(TransformColorBlue(tls, uint8(green_to_blue), uint8(red_to_blue), **(**uint32_t)(__ccgo_up(argb + uintptr(x)*4))))*4)) + 1
  51654 			goto _2
  51655 		_2:
  51656 			;
  51657 			x = x + 1
  51658 		}
  51659 		argb = argb + uintptr(stride)*4
  51660 	}
  51661 }
  51662 
  51663 //------------------------------------------------------------------------------
  51664 
  51665 func VectorMismatch_C(tls *libc.TLS, array1 uintptr, array2 uintptr, length int32) (r int32) {
  51666 	var match_len int32
  51667 	_ = match_len
  51668 	match_len = 0
  51669 	for match_len < length && **(**uint32_t)(__ccgo_up(array1 + uintptr(match_len)*4)) == **(**uint32_t)(__ccgo_up(array2 + uintptr(match_len)*4)) {
  51670 		match_len = match_len + 1
  51671 	}
  51672 	return match_len
  51673 }
  51674 
  51675 // C documentation
  51676 //
  51677 //	// Bundles multiple (1, 2, 4 or 8) pixels into a single pixel.
  51678 func VP8LBundleColorMap_C(tls *libc.TLS, row uintptr, width int32, xbits int32, dst uintptr) {
  51679 	var bit_depth, mask, x, xsub int32
  51680 	var code uint32_t
  51681 	_, _, _, _, _ = bit_depth, code, mask, x, xsub
  51682 	if xbits > 0 {
  51683 		bit_depth = int32(1) << (int32(3) - xbits)
  51684 		mask = int32(1)<<xbits - int32(1)
  51685 		code = uint32(0xff000000)
  51686 		x = 0
  51687 		for {
  51688 			if !(x < width) {
  51689 				break
  51690 			}
  51691 			xsub = x & mask
  51692 			if xsub == 0 {
  51693 				code = uint32(0xff000000)
  51694 			}
  51695 			code = code | uint32(int32(**(**uint8_t)(__ccgo_up(row + uintptr(x))))<<(int32(8)+bit_depth*xsub))
  51696 			**(**uint32_t)(__ccgo_up(dst + uintptr(x>>xbits)*4)) = code
  51697 			goto _1
  51698 		_1:
  51699 			;
  51700 			x = x + 1
  51701 		}
  51702 	} else {
  51703 		x = 0
  51704 		for {
  51705 			if !(x < width) {
  51706 				break
  51707 			}
  51708 			**(**uint32_t)(__ccgo_up(dst + uintptr(x)*4)) = uint32(0xff000000) | uint32(int32(**(**uint8_t)(__ccgo_up(row + uintptr(x))))<<libc.Int32FromInt32(8))
  51709 			goto _2
  51710 		_2:
  51711 			;
  51712 			x = x + 1
  51713 		}
  51714 	}
  51715 }
  51716 
  51717 //------------------------------------------------------------------------------
  51718 
  51719 func ExtraCost_C(tls *libc.TLS, population uintptr, length int32) (r uint32_t) {
  51720 	var cost uint32_t
  51721 	var i int32
  51722 	_, _ = cost, i
  51723 	cost = **(**uint32_t)(__ccgo_up(population + 4*4)) + **(**uint32_t)(__ccgo_up(population + 5*4))
  51724 	i = int32(2)
  51725 	for {
  51726 		if !(i < length/int32(2)-int32(1)) {
  51727 			break
  51728 		}
  51729 		cost = cost + uint32(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)))
  51730 		goto _1
  51731 	_1:
  51732 		;
  51733 		i = i + 1
  51734 	}
  51735 	return cost
  51736 }
  51737 
  51738 //------------------------------------------------------------------------------
  51739 
  51740 func AddVector_C(tls *libc.TLS, a uintptr, b uintptr, out uintptr, size int32) {
  51741 	var i int32
  51742 	_ = i
  51743 	i = 0
  51744 	for {
  51745 		if !(i < size) {
  51746 			break
  51747 		}
  51748 		**(**uint32_t)(__ccgo_up(out + uintptr(i)*4)) = **(**uint32_t)(__ccgo_up(a + uintptr(i)*4)) + **(**uint32_t)(__ccgo_up(b + uintptr(i)*4))
  51749 		goto _1
  51750 	_1:
  51751 		;
  51752 		i = i + 1
  51753 	}
  51754 }
  51755 
  51756 func AddVectorEq_C(tls *libc.TLS, a uintptr, out uintptr, size int32) {
  51757 	var i int32
  51758 	_ = i
  51759 	i = 0
  51760 	for {
  51761 		if !(i < size) {
  51762 			break
  51763 		}
  51764 		**(**uint32_t)(__ccgo_up(out + uintptr(i)*4)) += **(**uint32_t)(__ccgo_up(a + uintptr(i)*4))
  51765 		goto _1
  51766 	_1:
  51767 		;
  51768 		i = i + 1
  51769 	}
  51770 }
  51771 
  51772 //------------------------------------------------------------------------------
  51773 // Image transforms.
  51774 
  51775 func PredictorSub0_C(tls *libc.TLS, in uintptr, upper uintptr, num_pixels int32, out uintptr) {
  51776 	var alpha_and_green, red_and_blue, v2, v3, v4 uint32_t
  51777 	var i int32
  51778 	_, _, _, _, _, _ = alpha_and_green, i, red_and_blue, v2, v3, v4
  51779 	i = 0
  51780 	for {
  51781 		if !(i < num_pixels) {
  51782 			break
  51783 		}
  51784 		v2 = **(**uint32_t)(__ccgo_up(in + uintptr(i)*4))
  51785 		v3 = uint32(ARGB_BLACK3)
  51786 		alpha_and_green = uint32(0x00ff00ff) + v2&uint32(0xff00ff00) - v3&uint32(0xff00ff00)
  51787 		red_and_blue = uint32(0xff00ff00) + v2&uint32(0x00ff00ff) - v3&uint32(0x00ff00ff)
  51788 		v4 = alpha_and_green&uint32(0xff00ff00) | red_and_blue&uint32(0x00ff00ff)
  51789 		goto _5
  51790 	_5:
  51791 		**(**uint32_t)(__ccgo_up(out + uintptr(i)*4)) = v4
  51792 		goto _1
  51793 	_1:
  51794 		;
  51795 		i = i + 1
  51796 	}
  51797 	_ = upper
  51798 }
  51799 
  51800 func PredictorSub1_C(tls *libc.TLS, in uintptr, upper uintptr, num_pixels int32, out uintptr) {
  51801 	var alpha_and_green, red_and_blue, v2, v3, v4 uint32_t
  51802 	var i int32
  51803 	_, _, _, _, _, _ = alpha_and_green, i, red_and_blue, v2, v3, v4
  51804 	i = 0
  51805 	for {
  51806 		if !(i < num_pixels) {
  51807 			break
  51808 		}
  51809 		v2 = **(**uint32_t)(__ccgo_up(in + uintptr(i)*4))
  51810 		v3 = **(**uint32_t)(__ccgo_up(in + uintptr(i-int32(1))*4))
  51811 		alpha_and_green = uint32(0x00ff00ff) + v2&uint32(0xff00ff00) - v3&uint32(0xff00ff00)
  51812 		red_and_blue = uint32(0xff00ff00) + v2&uint32(0x00ff00ff) - v3&uint32(0x00ff00ff)
  51813 		v4 = alpha_and_green&uint32(0xff00ff00) | red_and_blue&uint32(0x00ff00ff)
  51814 		goto _5
  51815 	_5:
  51816 		**(**uint32_t)(__ccgo_up(out + uintptr(i)*4)) = v4
  51817 		goto _1
  51818 	_1:
  51819 		;
  51820 		i = i + 1
  51821 	}
  51822 	_ = upper
  51823 }
  51824 
  51825 // It subtracts the prediction from the input pixel and stores the residual
  51826 // in the output pixel.
  51827 func PredictorSub2_C(tls *libc.TLS, in uintptr, upper uintptr, num_pixels int32, out uintptr) {
  51828 	var alpha_and_green, pred, red_and_blue, v2, v3, v4 uint32_t
  51829 	var x int32
  51830 	_, _, _, _, _, _, _ = alpha_and_green, pred, red_and_blue, x, v2, v3, v4
  51831 	x = 0
  51832 	for {
  51833 		if !(x < num_pixels) {
  51834 			break
  51835 		}
  51836 		pred = VP8LPredictor2_C(tls, in+uintptr(x-int32(1))*4, upper+uintptr(x)*4)
  51837 		v2 = **(**uint32_t)(__ccgo_up(in + uintptr(x)*4))
  51838 		v3 = pred
  51839 		alpha_and_green = uint32(0x00ff00ff) + v2&uint32(0xff00ff00) - v3&uint32(0xff00ff00)
  51840 		red_and_blue = uint32(0xff00ff00) + v2&uint32(0x00ff00ff) - v3&uint32(0x00ff00ff)
  51841 		v4 = alpha_and_green&uint32(0xff00ff00) | red_and_blue&uint32(0x00ff00ff)
  51842 		goto _5
  51843 	_5:
  51844 		**(**uint32_t)(__ccgo_up(out + uintptr(x)*4)) = v4
  51845 		goto _1
  51846 	_1:
  51847 		;
  51848 		x = x + 1
  51849 	}
  51850 }
  51851 
  51852 func PredictorSub3_C(tls *libc.TLS, in uintptr, upper uintptr, num_pixels int32, out uintptr) {
  51853 	var alpha_and_green, pred, red_and_blue, v2, v3, v4 uint32_t
  51854 	var x int32
  51855 	_, _, _, _, _, _, _ = alpha_and_green, pred, red_and_blue, x, v2, v3, v4
  51856 	x = 0
  51857 	for {
  51858 		if !(x < num_pixels) {
  51859 			break
  51860 		}
  51861 		pred = VP8LPredictor3_C(tls, in+uintptr(x-int32(1))*4, upper+uintptr(x)*4)
  51862 		v2 = **(**uint32_t)(__ccgo_up(in + uintptr(x)*4))
  51863 		v3 = pred
  51864 		alpha_and_green = uint32(0x00ff00ff) + v2&uint32(0xff00ff00) - v3&uint32(0xff00ff00)
  51865 		red_and_blue = uint32(0xff00ff00) + v2&uint32(0x00ff00ff) - v3&uint32(0x00ff00ff)
  51866 		v4 = alpha_and_green&uint32(0xff00ff00) | red_and_blue&uint32(0x00ff00ff)
  51867 		goto _5
  51868 	_5:
  51869 		**(**uint32_t)(__ccgo_up(out + uintptr(x)*4)) = v4
  51870 		goto _1
  51871 	_1:
  51872 		;
  51873 		x = x + 1
  51874 	}
  51875 }
  51876 
  51877 func PredictorSub4_C(tls *libc.TLS, in uintptr, upper uintptr, num_pixels int32, out uintptr) {
  51878 	var alpha_and_green, pred, red_and_blue, v2, v3, v4 uint32_t
  51879 	var x int32
  51880 	_, _, _, _, _, _, _ = alpha_and_green, pred, red_and_blue, x, v2, v3, v4
  51881 	x = 0
  51882 	for {
  51883 		if !(x < num_pixels) {
  51884 			break
  51885 		}
  51886 		pred = VP8LPredictor4_C(tls, in+uintptr(x-int32(1))*4, upper+uintptr(x)*4)
  51887 		v2 = **(**uint32_t)(__ccgo_up(in + uintptr(x)*4))
  51888 		v3 = pred
  51889 		alpha_and_green = uint32(0x00ff00ff) + v2&uint32(0xff00ff00) - v3&uint32(0xff00ff00)
  51890 		red_and_blue = uint32(0xff00ff00) + v2&uint32(0x00ff00ff) - v3&uint32(0x00ff00ff)
  51891 		v4 = alpha_and_green&uint32(0xff00ff00) | red_and_blue&uint32(0x00ff00ff)
  51892 		goto _5
  51893 	_5:
  51894 		**(**uint32_t)(__ccgo_up(out + uintptr(x)*4)) = v4
  51895 		goto _1
  51896 	_1:
  51897 		;
  51898 		x = x + 1
  51899 	}
  51900 }
  51901 
  51902 func PredictorSub5_C(tls *libc.TLS, in uintptr, upper uintptr, num_pixels int32, out uintptr) {
  51903 	var alpha_and_green, pred, red_and_blue, v2, v3, v4 uint32_t
  51904 	var x int32
  51905 	_, _, _, _, _, _, _ = alpha_and_green, pred, red_and_blue, x, v2, v3, v4
  51906 	x = 0
  51907 	for {
  51908 		if !(x < num_pixels) {
  51909 			break
  51910 		}
  51911 		pred = VP8LPredictor5_C(tls, in+uintptr(x-int32(1))*4, upper+uintptr(x)*4)
  51912 		v2 = **(**uint32_t)(__ccgo_up(in + uintptr(x)*4))
  51913 		v3 = pred
  51914 		alpha_and_green = uint32(0x00ff00ff) + v2&uint32(0xff00ff00) - v3&uint32(0xff00ff00)
  51915 		red_and_blue = uint32(0xff00ff00) + v2&uint32(0x00ff00ff) - v3&uint32(0x00ff00ff)
  51916 		v4 = alpha_and_green&uint32(0xff00ff00) | red_and_blue&uint32(0x00ff00ff)
  51917 		goto _5
  51918 	_5:
  51919 		**(**uint32_t)(__ccgo_up(out + uintptr(x)*4)) = v4
  51920 		goto _1
  51921 	_1:
  51922 		;
  51923 		x = x + 1
  51924 	}
  51925 }
  51926 
  51927 func PredictorSub6_C(tls *libc.TLS, in uintptr, upper uintptr, num_pixels int32, out uintptr) {
  51928 	var alpha_and_green, pred, red_and_blue, v2, v3, v4 uint32_t
  51929 	var x int32
  51930 	_, _, _, _, _, _, _ = alpha_and_green, pred, red_and_blue, x, v2, v3, v4
  51931 	x = 0
  51932 	for {
  51933 		if !(x < num_pixels) {
  51934 			break
  51935 		}
  51936 		pred = VP8LPredictor6_C(tls, in+uintptr(x-int32(1))*4, upper+uintptr(x)*4)
  51937 		v2 = **(**uint32_t)(__ccgo_up(in + uintptr(x)*4))
  51938 		v3 = pred
  51939 		alpha_and_green = uint32(0x00ff00ff) + v2&uint32(0xff00ff00) - v3&uint32(0xff00ff00)
  51940 		red_and_blue = uint32(0xff00ff00) + v2&uint32(0x00ff00ff) - v3&uint32(0x00ff00ff)
  51941 		v4 = alpha_and_green&uint32(0xff00ff00) | red_and_blue&uint32(0x00ff00ff)
  51942 		goto _5
  51943 	_5:
  51944 		**(**uint32_t)(__ccgo_up(out + uintptr(x)*4)) = v4
  51945 		goto _1
  51946 	_1:
  51947 		;
  51948 		x = x + 1
  51949 	}
  51950 }
  51951 
  51952 func PredictorSub7_C(tls *libc.TLS, in uintptr, upper uintptr, num_pixels int32, out uintptr) {
  51953 	var alpha_and_green, pred, red_and_blue, v2, v3, v4 uint32_t
  51954 	var x int32
  51955 	_, _, _, _, _, _, _ = alpha_and_green, pred, red_and_blue, x, v2, v3, v4
  51956 	x = 0
  51957 	for {
  51958 		if !(x < num_pixels) {
  51959 			break
  51960 		}
  51961 		pred = VP8LPredictor7_C(tls, in+uintptr(x-int32(1))*4, upper+uintptr(x)*4)
  51962 		v2 = **(**uint32_t)(__ccgo_up(in + uintptr(x)*4))
  51963 		v3 = pred
  51964 		alpha_and_green = uint32(0x00ff00ff) + v2&uint32(0xff00ff00) - v3&uint32(0xff00ff00)
  51965 		red_and_blue = uint32(0xff00ff00) + v2&uint32(0x00ff00ff) - v3&uint32(0x00ff00ff)
  51966 		v4 = alpha_and_green&uint32(0xff00ff00) | red_and_blue&uint32(0x00ff00ff)
  51967 		goto _5
  51968 	_5:
  51969 		**(**uint32_t)(__ccgo_up(out + uintptr(x)*4)) = v4
  51970 		goto _1
  51971 	_1:
  51972 		;
  51973 		x = x + 1
  51974 	}
  51975 }
  51976 
  51977 func PredictorSub8_C(tls *libc.TLS, in uintptr, upper uintptr, num_pixels int32, out uintptr) {
  51978 	var alpha_and_green, pred, red_and_blue, v2, v3, v4 uint32_t
  51979 	var x int32
  51980 	_, _, _, _, _, _, _ = alpha_and_green, pred, red_and_blue, x, v2, v3, v4
  51981 	x = 0
  51982 	for {
  51983 		if !(x < num_pixels) {
  51984 			break
  51985 		}
  51986 		pred = VP8LPredictor8_C(tls, in+uintptr(x-int32(1))*4, upper+uintptr(x)*4)
  51987 		v2 = **(**uint32_t)(__ccgo_up(in + uintptr(x)*4))
  51988 		v3 = pred
  51989 		alpha_and_green = uint32(0x00ff00ff) + v2&uint32(0xff00ff00) - v3&uint32(0xff00ff00)
  51990 		red_and_blue = uint32(0xff00ff00) + v2&uint32(0x00ff00ff) - v3&uint32(0x00ff00ff)
  51991 		v4 = alpha_and_green&uint32(0xff00ff00) | red_and_blue&uint32(0x00ff00ff)
  51992 		goto _5
  51993 	_5:
  51994 		**(**uint32_t)(__ccgo_up(out + uintptr(x)*4)) = v4
  51995 		goto _1
  51996 	_1:
  51997 		;
  51998 		x = x + 1
  51999 	}
  52000 }
  52001 
  52002 func PredictorSub9_C(tls *libc.TLS, in uintptr, upper uintptr, num_pixels int32, out uintptr) {
  52003 	var alpha_and_green, pred, red_and_blue, v2, v3, v4 uint32_t
  52004 	var x int32
  52005 	_, _, _, _, _, _, _ = alpha_and_green, pred, red_and_blue, x, v2, v3, v4
  52006 	x = 0
  52007 	for {
  52008 		if !(x < num_pixels) {
  52009 			break
  52010 		}
  52011 		pred = VP8LPredictor9_C(tls, in+uintptr(x-int32(1))*4, upper+uintptr(x)*4)
  52012 		v2 = **(**uint32_t)(__ccgo_up(in + uintptr(x)*4))
  52013 		v3 = pred
  52014 		alpha_and_green = uint32(0x00ff00ff) + v2&uint32(0xff00ff00) - v3&uint32(0xff00ff00)
  52015 		red_and_blue = uint32(0xff00ff00) + v2&uint32(0x00ff00ff) - v3&uint32(0x00ff00ff)
  52016 		v4 = alpha_and_green&uint32(0xff00ff00) | red_and_blue&uint32(0x00ff00ff)
  52017 		goto _5
  52018 	_5:
  52019 		**(**uint32_t)(__ccgo_up(out + uintptr(x)*4)) = v4
  52020 		goto _1
  52021 	_1:
  52022 		;
  52023 		x = x + 1
  52024 	}
  52025 }
  52026 
  52027 func PredictorSub10_C(tls *libc.TLS, in uintptr, upper uintptr, num_pixels int32, out uintptr) {
  52028 	var alpha_and_green, pred, red_and_blue, v2, v3, v4 uint32_t
  52029 	var x int32
  52030 	_, _, _, _, _, _, _ = alpha_and_green, pred, red_and_blue, x, v2, v3, v4
  52031 	x = 0
  52032 	for {
  52033 		if !(x < num_pixels) {
  52034 			break
  52035 		}
  52036 		pred = VP8LPredictor10_C(tls, in+uintptr(x-int32(1))*4, upper+uintptr(x)*4)
  52037 		v2 = **(**uint32_t)(__ccgo_up(in + uintptr(x)*4))
  52038 		v3 = pred
  52039 		alpha_and_green = uint32(0x00ff00ff) + v2&uint32(0xff00ff00) - v3&uint32(0xff00ff00)
  52040 		red_and_blue = uint32(0xff00ff00) + v2&uint32(0x00ff00ff) - v3&uint32(0x00ff00ff)
  52041 		v4 = alpha_and_green&uint32(0xff00ff00) | red_and_blue&uint32(0x00ff00ff)
  52042 		goto _5
  52043 	_5:
  52044 		**(**uint32_t)(__ccgo_up(out + uintptr(x)*4)) = v4
  52045 		goto _1
  52046 	_1:
  52047 		;
  52048 		x = x + 1
  52049 	}
  52050 }
  52051 
  52052 func PredictorSub11_C(tls *libc.TLS, in uintptr, upper uintptr, num_pixels int32, out uintptr) {
  52053 	var alpha_and_green, pred, red_and_blue, v2, v3, v4 uint32_t
  52054 	var x int32
  52055 	_, _, _, _, _, _, _ = alpha_and_green, pred, red_and_blue, x, v2, v3, v4
  52056 	x = 0
  52057 	for {
  52058 		if !(x < num_pixels) {
  52059 			break
  52060 		}
  52061 		pred = VP8LPredictor11_C(tls, in+uintptr(x-int32(1))*4, upper+uintptr(x)*4)
  52062 		v2 = **(**uint32_t)(__ccgo_up(in + uintptr(x)*4))
  52063 		v3 = pred
  52064 		alpha_and_green = uint32(0x00ff00ff) + v2&uint32(0xff00ff00) - v3&uint32(0xff00ff00)
  52065 		red_and_blue = uint32(0xff00ff00) + v2&uint32(0x00ff00ff) - v3&uint32(0x00ff00ff)
  52066 		v4 = alpha_and_green&uint32(0xff00ff00) | red_and_blue&uint32(0x00ff00ff)
  52067 		goto _5
  52068 	_5:
  52069 		**(**uint32_t)(__ccgo_up(out + uintptr(x)*4)) = v4
  52070 		goto _1
  52071 	_1:
  52072 		;
  52073 		x = x + 1
  52074 	}
  52075 }
  52076 
  52077 func PredictorSub12_C(tls *libc.TLS, in uintptr, upper uintptr, num_pixels int32, out uintptr) {
  52078 	var alpha_and_green, pred, red_and_blue, v2, v3, v4 uint32_t
  52079 	var x int32
  52080 	_, _, _, _, _, _, _ = alpha_and_green, pred, red_and_blue, x, v2, v3, v4
  52081 	x = 0
  52082 	for {
  52083 		if !(x < num_pixels) {
  52084 			break
  52085 		}
  52086 		pred = VP8LPredictor12_C(tls, in+uintptr(x-int32(1))*4, upper+uintptr(x)*4)
  52087 		v2 = **(**uint32_t)(__ccgo_up(in + uintptr(x)*4))
  52088 		v3 = pred
  52089 		alpha_and_green = uint32(0x00ff00ff) + v2&uint32(0xff00ff00) - v3&uint32(0xff00ff00)
  52090 		red_and_blue = uint32(0xff00ff00) + v2&uint32(0x00ff00ff) - v3&uint32(0x00ff00ff)
  52091 		v4 = alpha_and_green&uint32(0xff00ff00) | red_and_blue&uint32(0x00ff00ff)
  52092 		goto _5
  52093 	_5:
  52094 		**(**uint32_t)(__ccgo_up(out + uintptr(x)*4)) = v4
  52095 		goto _1
  52096 	_1:
  52097 		;
  52098 		x = x + 1
  52099 	}
  52100 }
  52101 
  52102 func PredictorSub13_C(tls *libc.TLS, in uintptr, upper uintptr, num_pixels int32, out uintptr) {
  52103 	var alpha_and_green, pred, red_and_blue, v2, v3, v4 uint32_t
  52104 	var x int32
  52105 	_, _, _, _, _, _, _ = alpha_and_green, pred, red_and_blue, x, v2, v3, v4
  52106 	x = 0
  52107 	for {
  52108 		if !(x < num_pixels) {
  52109 			break
  52110 		}
  52111 		pred = VP8LPredictor13_C(tls, in+uintptr(x-int32(1))*4, upper+uintptr(x)*4)
  52112 		v2 = **(**uint32_t)(__ccgo_up(in + uintptr(x)*4))
  52113 		v3 = pred
  52114 		alpha_and_green = uint32(0x00ff00ff) + v2&uint32(0xff00ff00) - v3&uint32(0xff00ff00)
  52115 		red_and_blue = uint32(0xff00ff00) + v2&uint32(0x00ff00ff) - v3&uint32(0x00ff00ff)
  52116 		v4 = alpha_and_green&uint32(0xff00ff00) | red_and_blue&uint32(0x00ff00ff)
  52117 		goto _5
  52118 	_5:
  52119 		**(**uint32_t)(__ccgo_up(out + uintptr(x)*4)) = v4
  52120 		goto _1
  52121 	_1:
  52122 		;
  52123 		x = x + 1
  52124 	}
  52125 }
  52126 
  52127 func VP8LEncDspInit(tls *libc.TLS) {
  52128 	if libc.AtomicLoadPUintptr(uintptr(unsafe.Pointer(&VP8LEncDspInit_body_last_cpuinfo_used))) == VP8GetCPUInfo {
  52129 		goto _1
  52130 	}
  52131 	VP8LEncDspInit_body(tls)
  52132 	libc.AtomicStorePUintptr(uintptr(unsafe.Pointer(&VP8LEncDspInit_body_last_cpuinfo_used)), VP8GetCPUInfo)
  52133 	goto _2
  52134 _2:
  52135 	;
  52136 	goto _1
  52137 _1: /**/ //
  52138 }
  52139 
  52140 var VP8LEncDspInit_body_last_cpuinfo_used = uintptr(0)
  52141 
  52142 func init() {
  52143 	p := unsafe.Pointer(&VP8LEncDspInit_body_last_cpuinfo_used)
  52144 	*(*uintptr)(unsafe.Add(p, 0)) = uintptr(unsafe.Pointer(&VP8LEncDspInit_body_last_cpuinfo_used))
  52145 }
  52146 
  52147 func VP8LEncDspInit_body(tls *libc.TLS) {
  52148 	VP8LDspInit(tls)
  52149 	VP8LSubtractGreenFromBlueAndRed = __ccgo_fp(VP8LSubtractGreenFromBlueAndRed_C)
  52150 	VP8LTransformColor = __ccgo_fp(VP8LTransformColor_C)
  52151 	VP8LCollectColorBlueTransforms = __ccgo_fp(VP8LCollectColorBlueTransforms_C)
  52152 	VP8LCollectColorRedTransforms = __ccgo_fp(VP8LCollectColorRedTransforms_C)
  52153 	VP8LFastLog2Slow = __ccgo_fp(FastLog2Slow_C)
  52154 	VP8LFastSLog2Slow = __ccgo_fp(FastSLog2Slow_C)
  52155 	VP8LExtraCost = __ccgo_fp(ExtraCost_C)
  52156 	VP8LCombinedShannonEntropy = __ccgo_fp(CombinedShannonEntropy_C)
  52157 	VP8LShannonEntropy = __ccgo_fp(ShannonEntropy_C)
  52158 	VP8LGetEntropyUnrefined = __ccgo_fp(GetEntropyUnrefined_C)
  52159 	VP8LGetCombinedEntropyUnrefined = __ccgo_fp(GetCombinedEntropyUnrefined_C)
  52160 	VP8LAddVector = __ccgo_fp(AddVector_C)
  52161 	VP8LAddVectorEq = __ccgo_fp(AddVectorEq_C)
  52162 	VP8LVectorMismatch = __ccgo_fp(VectorMismatch_C)
  52163 	VP8LBundleColorMap = __ccgo_fp(VP8LBundleColorMap_C)
  52164 	VP8LPredictorsSub[0] = __ccgo_fp(PredictorSub0_C)
  52165 	VP8LPredictorsSub[int32(1)] = __ccgo_fp(PredictorSub1_C)
  52166 	VP8LPredictorsSub[int32(2)] = __ccgo_fp(PredictorSub2_C)
  52167 	VP8LPredictorsSub[int32(3)] = __ccgo_fp(PredictorSub3_C)
  52168 	VP8LPredictorsSub[int32(4)] = __ccgo_fp(PredictorSub4_C)
  52169 	VP8LPredictorsSub[int32(5)] = __ccgo_fp(PredictorSub5_C)
  52170 	VP8LPredictorsSub[int32(6)] = __ccgo_fp(PredictorSub6_C)
  52171 	VP8LPredictorsSub[int32(7)] = __ccgo_fp(PredictorSub7_C)
  52172 	VP8LPredictorsSub[int32(8)] = __ccgo_fp(PredictorSub8_C)
  52173 	VP8LPredictorsSub[int32(9)] = __ccgo_fp(PredictorSub9_C)
  52174 	VP8LPredictorsSub[int32(10)] = __ccgo_fp(PredictorSub10_C)
  52175 	VP8LPredictorsSub[int32(11)] = __ccgo_fp(PredictorSub11_C)
  52176 	VP8LPredictorsSub[int32(12)] = __ccgo_fp(PredictorSub12_C)
  52177 	VP8LPredictorsSub[int32(13)] = __ccgo_fp(PredictorSub13_C)
  52178 	VP8LPredictorsSub[int32(14)] = __ccgo_fp(PredictorSub0_C) // <- padding security sentinels
  52179 	VP8LPredictorsSub[int32(15)] = __ccgo_fp(PredictorSub0_C)
  52180 	VP8LPredictorsSub_C[0] = __ccgo_fp(PredictorSub0_C)
  52181 	VP8LPredictorsSub_C[int32(1)] = __ccgo_fp(PredictorSub1_C)
  52182 	VP8LPredictorsSub_C[int32(2)] = __ccgo_fp(PredictorSub2_C)
  52183 	VP8LPredictorsSub_C[int32(3)] = __ccgo_fp(PredictorSub3_C)
  52184 	VP8LPredictorsSub_C[int32(4)] = __ccgo_fp(PredictorSub4_C)
  52185 	VP8LPredictorsSub_C[int32(5)] = __ccgo_fp(PredictorSub5_C)
  52186 	VP8LPredictorsSub_C[int32(6)] = __ccgo_fp(PredictorSub6_C)
  52187 	VP8LPredictorsSub_C[int32(7)] = __ccgo_fp(PredictorSub7_C)
  52188 	VP8LPredictorsSub_C[int32(8)] = __ccgo_fp(PredictorSub8_C)
  52189 	VP8LPredictorsSub_C[int32(9)] = __ccgo_fp(PredictorSub9_C)
  52190 	VP8LPredictorsSub_C[int32(10)] = __ccgo_fp(PredictorSub10_C)
  52191 	VP8LPredictorsSub_C[int32(11)] = __ccgo_fp(PredictorSub11_C)
  52192 	VP8LPredictorsSub_C[int32(12)] = __ccgo_fp(PredictorSub12_C)
  52193 	VP8LPredictorsSub_C[int32(13)] = __ccgo_fp(PredictorSub13_C)
  52194 	VP8LPredictorsSub_C[int32(14)] = __ccgo_fp(PredictorSub0_C) // <- padding security sentinels
  52195 	VP8LPredictorsSub_C[int32(15)] = __ccgo_fp(PredictorSub0_C)
  52196 	// If defined, use CPUInfo() to overwrite some pointers with faster versions.
  52197 	if VP8GetCPUInfo != libc.UintptrFromInt32(0) {
  52198 	}
  52199 }
  52200 
  52201 const LOG_2_RECIPROCAL_FIXED_DOUBLE2 = 12102203.161561485379934310913085937500
  52202 const SIZE_MAX29 = "UINT64_MAX"
  52203 
  52204 func VP8LEncDspInitMIPS32(tls *libc.TLS) {
  52205 }
  52206 
  52207 func VP8LEncDspInitMIPSdspR2(tls *libc.TLS) {
  52208 }
  52209 
  52210 func VP8LEncDspInitMSA(tls *libc.TLS) {
  52211 }
  52212 
  52213 func VP8LEncDspInitNEON(tls *libc.TLS) {
  52214 }
  52215 
  52216 func VP8LEncDspInitSSE2(tls *libc.TLS) {
  52217 }
  52218 
  52219 func VP8LEncDspInitSSE41(tls *libc.TLS) {
  52220 }
  52221 
  52222 func VP8LDspInitMIPSdspR2(tls *libc.TLS) {
  52223 }
  52224 
  52225 func VP8LDspInitMSA(tls *libc.TLS) {
  52226 }
  52227 
  52228 func VP8LDspInitNEON(tls *libc.TLS) {
  52229 }
  52230 
  52231 func VP8LDspInitSSE2(tls *libc.TLS) {
  52232 }
  52233 
  52234 func VP8LDspInitSSE41(tls *libc.TLS) {
  52235 }
  52236 
  52237 //------------------------------------------------------------------------------
  52238 
  52239 //------------------------------------------------------------------------------
  52240 // Implementations of critical functions ImportRow / ExportRow
  52241 
  52242 //------------------------------------------------------------------------------
  52243 // Row import
  52244 
  52245 func WebPRescalerImportRowExpand_C(tls *libc.TLS, wrk uintptr, src uintptr) {
  52246 	var accum, channel, x_in, x_out, x_out_max, x_stride int32
  52247 	var left, right rescaler_t
  52248 	var v2 uint32
  52249 	_, _, _, _, _, _, _, _, _ = accum, channel, left, right, x_in, x_out, x_out_max, x_stride, v2
  52250 	x_stride = (*WebPRescaler)(unsafe.Pointer(wrk)).Fnum_channels
  52251 	x_out_max = (*WebPRescaler)(unsafe.Pointer(wrk)).Fdst_width * (*WebPRescaler)(unsafe.Pointer(wrk)).Fnum_channels
  52252 	channel = 0
  52253 	for {
  52254 		if !(channel < x_stride) {
  52255 			break
  52256 		}
  52257 		x_in = channel
  52258 		x_out = channel
  52259 		// simple bilinear interpolation
  52260 		accum = (*WebPRescaler)(unsafe.Pointer(wrk)).Fx_add
  52261 		left = uint32(**(**uint8_t)(__ccgo_up(src + uintptr(x_in))))
  52262 		if (*WebPRescaler)(unsafe.Pointer(wrk)).Fsrc_width > int32(1) {
  52263 			v2 = uint32(**(**uint8_t)(__ccgo_up(src + uintptr(x_in+x_stride))))
  52264 		} else {
  52265 			v2 = left
  52266 		}
  52267 		right = v2
  52268 		x_in = x_in + x_stride
  52269 		for int32(1) != 0 {
  52270 			**(**rescaler_t)(__ccgo_up((*WebPRescaler)(unsafe.Pointer(wrk)).Ffrow + uintptr(x_out)*4)) = right*uint32((*WebPRescaler)(unsafe.Pointer(wrk)).Fx_add) + (left-right)*uint32(accum)
  52271 			x_out = x_out + x_stride
  52272 			if x_out >= x_out_max {
  52273 				break
  52274 			}
  52275 			accum = accum - (*WebPRescaler)(unsafe.Pointer(wrk)).Fx_sub
  52276 			if accum < 0 {
  52277 				left = right
  52278 				x_in = x_in + x_stride
  52279 				right = uint32(**(**uint8_t)(__ccgo_up(src + uintptr(x_in))))
  52280 				accum = accum + (*WebPRescaler)(unsafe.Pointer(wrk)).Fx_add
  52281 			}
  52282 		}
  52283 		goto _1
  52284 	_1:
  52285 		;
  52286 		channel = channel + 1
  52287 	}
  52288 }
  52289 
  52290 func WebPRescalerImportRowShrink_C(tls *libc.TLS, wrk uintptr, src uintptr) {
  52291 	var accum, channel, x_in, x_out, x_out_max, x_stride int32
  52292 	var base, sum uint32_t
  52293 	var frac rescaler_t
  52294 	_, _, _, _, _, _, _, _, _ = accum, base, channel, frac, sum, x_in, x_out, x_out_max, x_stride
  52295 	x_stride = (*WebPRescaler)(unsafe.Pointer(wrk)).Fnum_channels
  52296 	x_out_max = (*WebPRescaler)(unsafe.Pointer(wrk)).Fdst_width * (*WebPRescaler)(unsafe.Pointer(wrk)).Fnum_channels
  52297 	channel = 0
  52298 	for {
  52299 		if !(channel < x_stride) {
  52300 			break
  52301 		}
  52302 		x_in = channel
  52303 		x_out = channel
  52304 		sum = uint32(0)
  52305 		accum = 0
  52306 		for x_out < x_out_max {
  52307 			base = uint32(0)
  52308 			accum = accum + (*WebPRescaler)(unsafe.Pointer(wrk)).Fx_add
  52309 			for accum > 0 {
  52310 				accum = accum - (*WebPRescaler)(unsafe.Pointer(wrk)).Fx_sub
  52311 				base = uint32(**(**uint8_t)(__ccgo_up(src + uintptr(x_in))))
  52312 				sum = sum + base
  52313 				x_in = x_in + x_stride
  52314 			}
  52315 			// Emit next horizontal pixel.
  52316 			frac = base * uint32(-accum)
  52317 			**(**rescaler_t)(__ccgo_up((*WebPRescaler)(unsafe.Pointer(wrk)).Ffrow + uintptr(x_out)*4)) = sum*uint32((*WebPRescaler)(unsafe.Pointer(wrk)).Fx_sub) - frac
  52318 			// fresh fractional start for next pixel
  52319 			sum = uint32(int32((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)))
  52320 			x_out = x_out + x_stride
  52321 		}
  52322 		goto _1
  52323 	_1:
  52324 		;
  52325 		channel = channel + 1
  52326 	}
  52327 }
  52328 
  52329 //------------------------------------------------------------------------------
  52330 // Row export
  52331 
  52332 func WebPRescalerExportRowExpand_C(tls *libc.TLS, wrk uintptr) {
  52333 	var A, B, J, J1 uint32_t
  52334 	var I uint64_t
  52335 	var dst, frow, irow uintptr
  52336 	var v, v1, x_out, x_out_max int32
  52337 	var v2 uint32
  52338 	_, _, _, _, _, _, _, _, _, _, _, _, _ = A, B, I, J, J1, dst, frow, irow, v, v1, x_out, x_out_max, v2
  52339 	dst = (*WebPRescaler)(unsafe.Pointer(wrk)).Fdst
  52340 	irow = (*WebPRescaler)(unsafe.Pointer(wrk)).Firow
  52341 	x_out_max = (*WebPRescaler)(unsafe.Pointer(wrk)).Fdst_width * (*WebPRescaler)(unsafe.Pointer(wrk)).Fnum_channels
  52342 	frow = (*WebPRescaler)(unsafe.Pointer(wrk)).Ffrow
  52343 	if (*WebPRescaler)(unsafe.Pointer(wrk)).Fy_accum == 0 {
  52344 		x_out = 0
  52345 		for {
  52346 			if !(x_out < x_out_max) {
  52347 				break
  52348 			}
  52349 			J = **(**rescaler_t)(__ccgo_up(frow + uintptr(x_out)*4))
  52350 			v = int32((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))
  52351 			if v > int32(255) {
  52352 				v2 = uint32(255)
  52353 			} else {
  52354 				v2 = uint32(uint8(v))
  52355 			}
  52356 			**(**uint8_t)(__ccgo_up(dst + uintptr(x_out))) = uint8(v2)
  52357 			goto _1
  52358 		_1:
  52359 			;
  52360 			x_out = x_out + 1
  52361 		}
  52362 	} else {
  52363 		B = uint32(uint64(-(*WebPRescaler)(unsafe.Pointer(wrk)).Fy_accum) << libc.Int32FromInt32(WEBP_RESCALER_RFIX) / uint64((*WebPRescaler)(unsafe.Pointer(wrk)).Fy_sub))
  52364 		A = uint32(libc.Uint64FromUint64(1)<<libc.Int32FromInt32(WEBP_RESCALER_RFIX) - uint64(B))
  52365 		x_out = 0
  52366 		for {
  52367 			if !(x_out < x_out_max) {
  52368 				break
  52369 			}
  52370 			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)))
  52371 			J1 = uint32((I + libc.Uint64FromUint64(1)<<libc.Int32FromInt32(WEBP_RESCALER_RFIX)>>libc.Int32FromInt32(1)) >> libc.Int32FromInt32(WEBP_RESCALER_RFIX))
  52372 			v1 = int32((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))
  52373 			if v1 > int32(255) {
  52374 				v2 = uint32(255)
  52375 			} else {
  52376 				v2 = uint32(uint8(v1))
  52377 			}
  52378 			**(**uint8_t)(__ccgo_up(dst + uintptr(x_out))) = uint8(v2)
  52379 			goto _3
  52380 		_3:
  52381 			;
  52382 			x_out = x_out + 1
  52383 		}
  52384 	}
  52385 }
  52386 
  52387 func WebPRescalerExportRowShrink_C(tls *libc.TLS, wrk uintptr) {
  52388 	var dst, frow, irow uintptr
  52389 	var frac, yscale uint32_t
  52390 	var v, v1, x_out, x_out_max int32
  52391 	var v2 uint32
  52392 	_, _, _, _, _, _, _, _, _, _ = dst, frac, frow, irow, v, v1, x_out, x_out_max, yscale, v2
  52393 	dst = (*WebPRescaler)(unsafe.Pointer(wrk)).Fdst
  52394 	irow = (*WebPRescaler)(unsafe.Pointer(wrk)).Firow
  52395 	x_out_max = (*WebPRescaler)(unsafe.Pointer(wrk)).Fdst_width * (*WebPRescaler)(unsafe.Pointer(wrk)).Fnum_channels
  52396 	frow = (*WebPRescaler)(unsafe.Pointer(wrk)).Ffrow
  52397 	yscale = (*WebPRescaler)(unsafe.Pointer(wrk)).Ffy_scale * uint32(-(*WebPRescaler)(unsafe.Pointer(wrk)).Fy_accum)
  52398 	if yscale != 0 {
  52399 		x_out = 0
  52400 		for {
  52401 			if !(x_out < x_out_max) {
  52402 				break
  52403 			}
  52404 			frac = uint32(uint64(**(**rescaler_t)(__ccgo_up(frow + uintptr(x_out)*4))) * uint64(yscale) >> libc.Int32FromInt32(WEBP_RESCALER_RFIX))
  52405 			v = int32((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))
  52406 			if v > int32(255) {
  52407 				v2 = uint32(255)
  52408 			} else {
  52409 				v2 = uint32(uint8(v))
  52410 			}
  52411 			**(**uint8_t)(__ccgo_up(dst + uintptr(x_out))) = uint8(v2)
  52412 			**(**rescaler_t)(__ccgo_up(irow + uintptr(x_out)*4)) = frac // new fractional start
  52413 			goto _1
  52414 		_1:
  52415 			;
  52416 			x_out = x_out + 1
  52417 		}
  52418 	} else {
  52419 		x_out = 0
  52420 		for {
  52421 			if !(x_out < x_out_max) {
  52422 				break
  52423 			}
  52424 			v1 = int32((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))
  52425 			if v1 > int32(255) {
  52426 				v2 = uint32(255)
  52427 			} else {
  52428 				v2 = uint32(uint8(v1))
  52429 			}
  52430 			**(**uint8_t)(__ccgo_up(dst + uintptr(x_out))) = uint8(v2)
  52431 			**(**rescaler_t)(__ccgo_up(irow + uintptr(x_out)*4)) = uint32(0)
  52432 			goto _3
  52433 		_3:
  52434 			;
  52435 			x_out = x_out + 1
  52436 		}
  52437 	}
  52438 }
  52439 
  52440 //------------------------------------------------------------------------------
  52441 // Main entry calls
  52442 
  52443 func WebPRescalerImportRow(tls *libc.TLS, wrk uintptr, src uintptr) {
  52444 	if !((*WebPRescaler)(unsafe.Pointer(wrk)).Fx_expand != 0) {
  52445 		(*(*func(*libc.TLS, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{WebPRescalerImportRowShrink})))(tls, wrk, src)
  52446 	} else {
  52447 		(*(*func(*libc.TLS, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{WebPRescalerImportRowExpand})))(tls, wrk, src)
  52448 	}
  52449 }
  52450 
  52451 func WebPRescalerExportRow(tls *libc.TLS, wrk uintptr) {
  52452 	var i int32
  52453 	_ = i
  52454 	if (*WebPRescaler)(unsafe.Pointer(wrk)).Fy_accum <= 0 {
  52455 		if (*WebPRescaler)(unsafe.Pointer(wrk)).Fy_expand != 0 {
  52456 			(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(&struct{ uintptr }{WebPRescalerExportRowExpand})))(tls, wrk)
  52457 		} else {
  52458 			if (*WebPRescaler)(unsafe.Pointer(wrk)).Ffxy_scale != 0 {
  52459 				(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(&struct{ uintptr }{WebPRescalerExportRowShrink})))(tls, wrk)
  52460 			} else {
  52461 				i = 0
  52462 				for {
  52463 					if !(i < (*WebPRescaler)(unsafe.Pointer(wrk)).Fnum_channels*(*WebPRescaler)(unsafe.Pointer(wrk)).Fdst_width) {
  52464 						break
  52465 					}
  52466 					**(**uint8_t)(__ccgo_up((*WebPRescaler)(unsafe.Pointer(wrk)).Fdst + uintptr(i))) = uint8(**(**rescaler_t)(__ccgo_up((*WebPRescaler)(unsafe.Pointer(wrk)).Firow + uintptr(i)*4)))
  52467 					**(**rescaler_t)(__ccgo_up((*WebPRescaler)(unsafe.Pointer(wrk)).Firow + uintptr(i)*4)) = uint32(0)
  52468 					goto _1
  52469 				_1:
  52470 					;
  52471 					i = i + 1
  52472 				}
  52473 			}
  52474 		}
  52475 		**(**int32)(__ccgo_up(wrk + 24)) += (*WebPRescaler)(unsafe.Pointer(wrk)).Fy_add
  52476 		**(**uintptr)(__ccgo_up(wrk + 72)) += uintptr((*WebPRescaler)(unsafe.Pointer(wrk)).Fdst_stride)
  52477 		(*WebPRescaler)(unsafe.Pointer(wrk)).Fdst_y = (*WebPRescaler)(unsafe.Pointer(wrk)).Fdst_y + 1
  52478 	}
  52479 }
  52480 
  52481 func WebPRescalerDspInit(tls *libc.TLS) {
  52482 	if libc.AtomicLoadPUintptr(uintptr(unsafe.Pointer(&WebPRescalerDspInit_body_last_cpuinfo_used))) == VP8GetCPUInfo {
  52483 		goto _1
  52484 	}
  52485 	WebPRescalerDspInit_body(tls)
  52486 	libc.AtomicStorePUintptr(uintptr(unsafe.Pointer(&WebPRescalerDspInit_body_last_cpuinfo_used)), VP8GetCPUInfo)
  52487 	goto _2
  52488 _2:
  52489 	;
  52490 	goto _1
  52491 _1: /**/ //
  52492 }
  52493 
  52494 var WebPRescalerDspInit_body_last_cpuinfo_used = uintptr(0)
  52495 
  52496 func init() {
  52497 	p := unsafe.Pointer(&WebPRescalerDspInit_body_last_cpuinfo_used)
  52498 	*(*uintptr)(unsafe.Add(p, 0)) = uintptr(unsafe.Pointer(&WebPRescalerDspInit_body_last_cpuinfo_used))
  52499 }
  52500 
  52501 func WebPRescalerDspInit_body(tls *libc.TLS) {
  52502 	WebPRescalerExportRowExpand = __ccgo_fp(WebPRescalerExportRowExpand_C)
  52503 	WebPRescalerExportRowShrink = __ccgo_fp(WebPRescalerExportRowShrink_C)
  52504 	WebPRescalerImportRowExpand = __ccgo_fp(WebPRescalerImportRowExpand_C)
  52505 	WebPRescalerImportRowShrink = __ccgo_fp(WebPRescalerImportRowShrink_C)
  52506 	if VP8GetCPUInfo != libc.UintptrFromInt32(0) {
  52507 	}
  52508 }
  52509 
  52510 func WebPRescalerDspInitMIPS32(tls *libc.TLS) {
  52511 }
  52512 
  52513 func WebPRescalerDspInitMIPSdspR2(tls *libc.TLS) {
  52514 }
  52515 
  52516 func WebPRescalerDspInitMSA(tls *libc.TLS) {
  52517 }
  52518 
  52519 func WebPRescalerDspInitNEON(tls *libc.TLS) {
  52520 }
  52521 
  52522 func WebPRescalerDspInitSSE2(tls *libc.TLS) {
  52523 }
  52524 
  52525 const SIZE_MAX30 = "_UI64_MAX"
  52526 
  52527 // Copyright 2010 Google Inc. All Rights Reserved.
  52528 //
  52529 // Use of this source code is governed by a BSD-style license
  52530 // that can be found in the COPYING file in the root of the source
  52531 // tree. An additional intellectual property rights grant can be found
  52532 // in the file PATENTS. All contributing project authors may
  52533 // be found in the AUTHORS file in the root of the source tree.
  52534 // -----------------------------------------------------------------------------
  52535 //
  52536 //  Common types + memory wrappers
  52537 //
  52538 // Author: Skal (pascal.massimino@gmail.com)
  52539 
  52540 //------------------------------------------------------------------------------
  52541 // SSIM / PSNR
  52542 
  52543 // C documentation
  52544 //
  52545 //	// hat-shaped filter. Sum of coefficients is equal to 16.
  52546 var kWeight = [7]uint32_t{
  52547 	0: uint32(1),
  52548 	1: uint32(2),
  52549 	2: uint32(3),
  52550 	3: uint32(4),
  52551 	4: uint32(3),
  52552 	5: uint32(2),
  52553 	6: uint32(1),
  52554 }
  52555 var kWeightSum = uint32(libc.Int32FromInt32(16) * libc.Int32FromInt32(16)) // sum{kWeight}^2
  52556 
  52557 func SSIMCalculation(tls *libc.TLS, stats uintptr, N uint32_t) (r1 float64) {
  52558 	var C1, C2, C3, w2 uint32_t
  52559 	var den_S, fden, fnum, num_S, sxx, syy, xmxm, ymym uint64_t
  52560 	var r float64
  52561 	var sxy, xmym int64_t
  52562 	var v1 int64
  52563 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = C1, C2, C3, den_S, fden, fnum, num_S, r, sxx, sxy, syy, w2, xmxm, xmym, ymym, v1
  52564 	w2 = N * N
  52565 	C1 = uint32(20) * w2
  52566 	C2 = uint32(60) * w2
  52567 	C3 = uint32(libc.Int32FromInt32(8)*libc.Int32FromInt32(8)) * w2 // 'dark' limit ~= 6
  52568 	xmxm = uint64((*VP8DistoStats)(unsafe.Pointer(stats)).Fxm) * uint64((*VP8DistoStats)(unsafe.Pointer(stats)).Fxm)
  52569 	ymym = uint64((*VP8DistoStats)(unsafe.Pointer(stats)).Fym) * uint64((*VP8DistoStats)(unsafe.Pointer(stats)).Fym)
  52570 	if xmxm+ymym >= uint64(C3) {
  52571 		xmym = int64((*VP8DistoStats)(unsafe.Pointer(stats)).Fxm) * int64((*VP8DistoStats)(unsafe.Pointer(stats)).Fym)
  52572 		sxy = int64((*VP8DistoStats)(unsafe.Pointer(stats)).Fxym)*int64(N) - xmym // can be negative
  52573 		sxx = uint64((*VP8DistoStats)(unsafe.Pointer(stats)).Fxxm)*uint64(N) - xmxm
  52574 		syy = uint64((*VP8DistoStats)(unsafe.Pointer(stats)).Fyym)*uint64(N) - ymym
  52575 		if sxy < 0 {
  52576 			v1 = 0
  52577 		} else {
  52578 			v1 = sxy
  52579 		}
  52580 		// we descale by 8 to prevent overflow during the fnum/fden multiply.
  52581 		num_S = (uint64(2)*uint64(v1) + uint64(C2)) >> int32(8)
  52582 		den_S = (sxx + syy + uint64(C2)) >> int32(8)
  52583 		fnum = uint64(libc.Int64FromInt32(2)*xmym+int64(C1)) * num_S
  52584 		fden = (xmxm + ymym + uint64(C1)) * den_S
  52585 		r = float64(fnum) / float64(fden)
  52586 		return r
  52587 	}
  52588 	return float64(1) // area is too dark to contribute meaningfully
  52589 }
  52590 
  52591 func VP8SSIMFromStats(tls *libc.TLS, stats uintptr) (r float64) {
  52592 	return SSIMCalculation(tls, stats, kWeightSum)
  52593 }
  52594 
  52595 func VP8SSIMFromStatsClipped(tls *libc.TLS, stats uintptr) (r float64) {
  52596 	return SSIMCalculation(tls, stats, (*VP8DistoStats)(unsafe.Pointer(stats)).Fw)
  52597 }
  52598 
  52599 func SSIMGetClipped_C(tls *libc.TLS, src1 uintptr, stride1 int32, src2 uintptr, stride2 int32, xo int32, yo int32, W int32, H int32) (r float64) {
  52600 	bp := tls.Alloc(32)
  52601 	defer tls.Free(32)
  52602 	var s1, s2, w uint32_t
  52603 	var x, xmax, xmin, y, ymax, ymin, v1, v2, v3, v4 int32
  52604 	var _ /* stats at bp+0 */ VP8DistoStats
  52605 	_, _, _, _, _, _, _, _, _, _, _, _, _ = s1, s2, w, x, xmax, xmin, y, ymax, ymin, v1, v2, v3, v4
  52606 	**(**VP8DistoStats)(__ccgo_up(bp)) = VP8DistoStats{}
  52607 	if yo-int32(VP8_SSIM_KERNEL) < 0 {
  52608 		v1 = 0
  52609 	} else {
  52610 		v1 = yo - int32(VP8_SSIM_KERNEL)
  52611 	}
  52612 	ymin = v1
  52613 	if yo+int32(VP8_SSIM_KERNEL) > H-int32(1) {
  52614 		v2 = H - int32(1)
  52615 	} else {
  52616 		v2 = yo + int32(VP8_SSIM_KERNEL)
  52617 	}
  52618 	ymax = v2
  52619 	if xo-int32(VP8_SSIM_KERNEL) < 0 {
  52620 		v3 = 0
  52621 	} else {
  52622 		v3 = xo - int32(VP8_SSIM_KERNEL)
  52623 	}
  52624 	xmin = v3
  52625 	if xo+int32(VP8_SSIM_KERNEL) > W-int32(1) {
  52626 		v4 = W - int32(1)
  52627 	} else {
  52628 		v4 = xo + int32(VP8_SSIM_KERNEL)
  52629 	}
  52630 	xmax = v4
  52631 	src1 = src1 + uintptr(ymin*stride1)
  52632 	src2 = src2 + uintptr(ymin*stride2)
  52633 	y = ymin
  52634 	for {
  52635 		if !(y <= ymax) {
  52636 			break
  52637 		}
  52638 		x = xmin
  52639 		for {
  52640 			if !(x <= xmax) {
  52641 				break
  52642 			}
  52643 			w = kWeight[int32(VP8_SSIM_KERNEL)+x-xo] * kWeight[int32(VP8_SSIM_KERNEL)+y-yo]
  52644 			s1 = uint32(**(**uint8_t)(__ccgo_up(src1 + uintptr(x))))
  52645 			s2 = uint32(**(**uint8_t)(__ccgo_up(src2 + uintptr(x))))
  52646 			(**(**VP8DistoStats)(__ccgo_up(bp))).Fw += w
  52647 			(**(**VP8DistoStats)(__ccgo_up(bp))).Fxm += w * s1
  52648 			(**(**VP8DistoStats)(__ccgo_up(bp))).Fym += w * s2
  52649 			(**(**VP8DistoStats)(__ccgo_up(bp))).Fxxm += w * s1 * s1
  52650 			(**(**VP8DistoStats)(__ccgo_up(bp))).Fxym += w * s1 * s2
  52651 			(**(**VP8DistoStats)(__ccgo_up(bp))).Fyym += w * s2 * s2
  52652 			goto _6
  52653 		_6:
  52654 			;
  52655 			x = x + 1
  52656 		}
  52657 		goto _5
  52658 	_5:
  52659 		;
  52660 		y = y + 1
  52661 		src1 = src1 + uintptr(stride1)
  52662 		src2 = src2 + uintptr(stride2)
  52663 	}
  52664 	return VP8SSIMFromStatsClipped(tls, bp)
  52665 }
  52666 
  52667 func SSIMGet_C(tls *libc.TLS, src1 uintptr, stride1 int32, src2 uintptr, stride2 int32) (r float64) {
  52668 	bp := tls.Alloc(32)
  52669 	defer tls.Free(32)
  52670 	var s1, s2, w uint32_t
  52671 	var x, y int32
  52672 	var _ /* stats at bp+0 */ VP8DistoStats
  52673 	_, _, _, _, _ = s1, s2, w, x, y
  52674 	**(**VP8DistoStats)(__ccgo_up(bp)) = VP8DistoStats{}
  52675 	y = 0
  52676 	for {
  52677 		if !(y <= libc.Int32FromInt32(2)*libc.Int32FromInt32(VP8_SSIM_KERNEL)) {
  52678 			break
  52679 		}
  52680 		x = 0
  52681 		for {
  52682 			if !(x <= libc.Int32FromInt32(2)*libc.Int32FromInt32(VP8_SSIM_KERNEL)) {
  52683 				break
  52684 			}
  52685 			w = kWeight[x] * kWeight[y]
  52686 			s1 = uint32(**(**uint8_t)(__ccgo_up(src1 + uintptr(x))))
  52687 			s2 = uint32(**(**uint8_t)(__ccgo_up(src2 + uintptr(x))))
  52688 			(**(**VP8DistoStats)(__ccgo_up(bp))).Fxm += w * s1
  52689 			(**(**VP8DistoStats)(__ccgo_up(bp))).Fym += w * s2
  52690 			(**(**VP8DistoStats)(__ccgo_up(bp))).Fxxm += w * s1 * s1
  52691 			(**(**VP8DistoStats)(__ccgo_up(bp))).Fxym += w * s1 * s2
  52692 			(**(**VP8DistoStats)(__ccgo_up(bp))).Fyym += w * s2 * s2
  52693 			goto _2
  52694 		_2:
  52695 			;
  52696 			x = x + 1
  52697 		}
  52698 		goto _1
  52699 	_1:
  52700 		;
  52701 		y = y + 1
  52702 		src1 = src1 + uintptr(stride1)
  52703 		src2 = src2 + uintptr(stride2)
  52704 	}
  52705 	return VP8SSIMFromStats(tls, bp)
  52706 }
  52707 
  52708 //------------------------------------------------------------------------------
  52709 
  52710 func AccumulateSSE_C(tls *libc.TLS, src1 uintptr, src2 uintptr, len1 int32) (r uint32_t) {
  52711 	var diff int32_t
  52712 	var i int32
  52713 	var sse2 uint32_t
  52714 	_, _, _ = diff, i, sse2
  52715 	sse2 = uint32(0)
  52716 	// to ensure that accumulation fits within uint32_t
  52717 	i = 0
  52718 	for {
  52719 		if !(i < len1) {
  52720 			break
  52721 		}
  52722 		diff = int32(**(**uint8_t)(__ccgo_up(src1 + uintptr(i)))) - int32(**(**uint8_t)(__ccgo_up(src2 + uintptr(i))))
  52723 		sse2 = sse2 + uint32(diff*diff)
  52724 		goto _1
  52725 	_1:
  52726 		;
  52727 		i = i + 1
  52728 	}
  52729 	return sse2
  52730 }
  52731 
  52732 func VP8SSIMDspInit(tls *libc.TLS) {
  52733 	if libc.AtomicLoadPUintptr(uintptr(unsafe.Pointer(&VP8SSIMDspInit_body_last_cpuinfo_used))) == VP8GetCPUInfo {
  52734 		goto _1
  52735 	}
  52736 	VP8SSIMDspInit_body(tls)
  52737 	libc.AtomicStorePUintptr(uintptr(unsafe.Pointer(&VP8SSIMDspInit_body_last_cpuinfo_used)), VP8GetCPUInfo)
  52738 	goto _2
  52739 _2:
  52740 	;
  52741 	goto _1
  52742 _1: /**/ //
  52743 }
  52744 
  52745 var VP8SSIMDspInit_body_last_cpuinfo_used = uintptr(0)
  52746 
  52747 func init() {
  52748 	p := unsafe.Pointer(&VP8SSIMDspInit_body_last_cpuinfo_used)
  52749 	*(*uintptr)(unsafe.Add(p, 0)) = uintptr(unsafe.Pointer(&VP8SSIMDspInit_body_last_cpuinfo_used))
  52750 }
  52751 
  52752 func VP8SSIMDspInit_body(tls *libc.TLS) {
  52753 	VP8SSIMGetClipped = __ccgo_fp(SSIMGetClipped_C)
  52754 	VP8SSIMGet = __ccgo_fp(SSIMGet_C)
  52755 	VP8AccumulateSSE = __ccgo_fp(AccumulateSSE_C)
  52756 	if VP8GetCPUInfo != libc.UintptrFromInt32(0) {
  52757 	}
  52758 }
  52759 
  52760 const SIZE_MAX31 = "UINT64_MAX"
  52761 
  52762 func VP8SSIMDspInitSSE2(tls *libc.TLS) {
  52763 }
  52764 
  52765 // Given samples laid out in a square as:
  52766 //  [a b]
  52767 //  [c d]
  52768 // we interpolate u/v as:
  52769 //  ([9*a + 3*b + 3*c +   d    3*a + 9*b + 3*c +   d] + [8 8]) / 16
  52770 //  ([3*a +   b + 9*c + 3*d      a + 3*b + 3*c + 9*d]   [8 8]) / 16
  52771 
  52772 // We process u and v together stashed into 32bit (16bit each).
  52773 
  52774 // C documentation
  52775 //
  52776 //	// All variants implemented.
  52777 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) {
  52778 	var avg, diag_03, diag_12, l_uv, t_uv, tl_uv, uv, uv0, uv01, uv02, uv03, uv04, uv05, uv1, uv11 uint32_t
  52779 	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
  52780 	var v1, v5 uintptr
  52781 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  52782 	last_pixel_pair = (len1 - int32(1)) >> int32(1)
  52783 	tl_uv = uint32(int32(**(**uint8_t)(__ccgo_up(top_u))) | int32(**(**uint8_t)(__ccgo_up(top_v)))<<libc.Int32FromInt32(16)) /* top-left sample */
  52784 	l_uv = uint32(int32(**(**uint8_t)(__ccgo_up(cur_u))) | int32(**(**uint8_t)(__ccgo_up(cur_v)))<<libc.Int32FromInt32(16))
  52785 	uv0 = (uint32(3)*tl_uv + l_uv + uint32(0x00020002)) >> int32(2)
  52786 	v1 = top_dst
  52787 	v2 = int32(**(**uint8_t)(__ccgo_up(top_y)))
  52788 	v3 = int32(uint8(uv0 & uint32(0xff)))
  52789 	v4 = int32(uint8(uv0 >> libc.Int32FromInt32(16)))
  52790 	v5 = v1
  52791 	v8 = v2 * int32(19077) >> int32(8)
  52792 	goto _9
  52793 _9:
  52794 	v10 = v4 * int32(26149) >> int32(8)
  52795 	goto _11
  52796 _11:
  52797 	v12 = v8 + v10 - int32(14234)
  52798 	if v12 & ^int32(YUV_MASK2) == 0 {
  52799 		v15 = v12 >> int32(YUV_FIX2)
  52800 	} else {
  52801 		if v12 < 0 {
  52802 			v16 = 0
  52803 		} else {
  52804 			v16 = int32(255)
  52805 		}
  52806 		v15 = v16
  52807 	}
  52808 	v13 = v15
  52809 	goto _14
  52810 _14:
  52811 	v6 = v13
  52812 	goto _7
  52813 _7:
  52814 	**(**uint8_t)(__ccgo_up(v5)) = uint8(v6)
  52815 	v19 = v2 * int32(19077) >> int32(8)
  52816 	goto _20
  52817 _20:
  52818 	v21 = v3 * int32(6419) >> int32(8)
  52819 	goto _22
  52820 _22:
  52821 	v23 = v4 * int32(13320) >> int32(8)
  52822 	goto _24
  52823 _24:
  52824 	v25 = v19 - v21 - v23 + int32(8708)
  52825 	if v25 & ^int32(YUV_MASK2) == 0 {
  52826 		v28 = v25 >> int32(YUV_FIX2)
  52827 	} else {
  52828 		if v25 < 0 {
  52829 			v29 = 0
  52830 		} else {
  52831 			v29 = int32(255)
  52832 		}
  52833 		v28 = v29
  52834 	}
  52835 	v26 = v28
  52836 	goto _27
  52837 _27:
  52838 	v17 = v26
  52839 	goto _18
  52840 _18:
  52841 	**(**uint8_t)(__ccgo_up(v5 + 1)) = uint8(v17)
  52842 	v32 = v2 * int32(19077) >> int32(8)
  52843 	goto _33
  52844 _33:
  52845 	v34 = v3 * int32(33050) >> int32(8)
  52846 	goto _35
  52847 _35:
  52848 	v36 = v32 + v34 - int32(17685)
  52849 	if v36 & ^int32(YUV_MASK2) == 0 {
  52850 		v39 = v36 >> int32(YUV_FIX2)
  52851 	} else {
  52852 		if v36 < 0 {
  52853 			v40 = 0
  52854 		} else {
  52855 			v40 = int32(255)
  52856 		}
  52857 		v39 = v40
  52858 	}
  52859 	v37 = v39
  52860 	goto _38
  52861 _38:
  52862 	v30 = v37
  52863 	goto _31
  52864 _31:
  52865 	**(**uint8_t)(__ccgo_up(v5 + 2)) = uint8(v30)
  52866 	**(**uint8_t)(__ccgo_up(v1 + 3)) = uint8(0xff)
  52867 	if bottom_y != libc.UintptrFromInt32(0) {
  52868 		uv01 = (uint32(3)*l_uv + tl_uv + uint32(0x00020002)) >> int32(2)
  52869 		v1 = bottom_dst
  52870 		v2 = int32(**(**uint8_t)(__ccgo_up(bottom_y)))
  52871 		v3 = int32(uint8(uv01 & uint32(0xff)))
  52872 		v4 = int32(uint8(uv01 >> libc.Int32FromInt32(16)))
  52873 		v5 = v1
  52874 		v8 = v2 * int32(19077) >> int32(8)
  52875 		goto _49
  52876 	_49:
  52877 		v10 = v4 * int32(26149) >> int32(8)
  52878 		goto _51
  52879 	_51:
  52880 		v12 = v8 + v10 - int32(14234)
  52881 		if v12 & ^int32(YUV_MASK2) == 0 {
  52882 			v15 = v12 >> int32(YUV_FIX2)
  52883 		} else {
  52884 			if v12 < 0 {
  52885 				v16 = 0
  52886 			} else {
  52887 				v16 = int32(255)
  52888 			}
  52889 			v15 = v16
  52890 		}
  52891 		v13 = v15
  52892 		goto _54
  52893 	_54:
  52894 		v6 = v13
  52895 		goto _47
  52896 	_47:
  52897 		**(**uint8_t)(__ccgo_up(v5)) = uint8(v6)
  52898 		v19 = v2 * int32(19077) >> int32(8)
  52899 		goto _60
  52900 	_60:
  52901 		v21 = v3 * int32(6419) >> int32(8)
  52902 		goto _62
  52903 	_62:
  52904 		v23 = v4 * int32(13320) >> int32(8)
  52905 		goto _64
  52906 	_64:
  52907 		v25 = v19 - v21 - v23 + int32(8708)
  52908 		if v25 & ^int32(YUV_MASK2) == 0 {
  52909 			v28 = v25 >> int32(YUV_FIX2)
  52910 		} else {
  52911 			if v25 < 0 {
  52912 				v29 = 0
  52913 			} else {
  52914 				v29 = int32(255)
  52915 			}
  52916 			v28 = v29
  52917 		}
  52918 		v26 = v28
  52919 		goto _67
  52920 	_67:
  52921 		v17 = v26
  52922 		goto _58
  52923 	_58:
  52924 		**(**uint8_t)(__ccgo_up(v5 + 1)) = uint8(v17)
  52925 		v32 = v2 * int32(19077) >> int32(8)
  52926 		goto _73
  52927 	_73:
  52928 		v34 = v3 * int32(33050) >> int32(8)
  52929 		goto _75
  52930 	_75:
  52931 		v36 = v32 + v34 - int32(17685)
  52932 		if v36 & ^int32(YUV_MASK2) == 0 {
  52933 			v39 = v36 >> int32(YUV_FIX2)
  52934 		} else {
  52935 			if v36 < 0 {
  52936 				v40 = 0
  52937 			} else {
  52938 				v40 = int32(255)
  52939 			}
  52940 			v39 = v40
  52941 		}
  52942 		v37 = v39
  52943 		goto _78
  52944 	_78:
  52945 		v30 = v37
  52946 		goto _71
  52947 	_71:
  52948 		**(**uint8_t)(__ccgo_up(v5 + 2)) = uint8(v30)
  52949 		**(**uint8_t)(__ccgo_up(v1 + 3)) = uint8(0xff)
  52950 	}
  52951 	x = int32(1)
  52952 	for {
  52953 		if !(x <= last_pixel_pair) {
  52954 			break
  52955 		}
  52956 		t_uv = uint32(int32(**(**uint8_t)(__ccgo_up(top_u + uintptr(x)))) | int32(**(**uint8_t)(__ccgo_up(top_v + uintptr(x))))<<libc.Int32FromInt32(16)) /* top sample */
  52957 		uv = uint32(int32(**(**uint8_t)(__ccgo_up(cur_u + uintptr(x)))) | int32(**(**uint8_t)(__ccgo_up(cur_v + uintptr(x))))<<libc.Int32FromInt32(16))   /* sample */ /* precompute invariant values associated with first and second diagonals*/
  52958 		avg = tl_uv + t_uv + l_uv + uv + uint32(0x00080008)
  52959 		diag_12 = (avg + uint32(2)*(t_uv+l_uv)) >> int32(3)
  52960 		diag_03 = (avg + uint32(2)*(tl_uv+uv)) >> int32(3)
  52961 		uv02 = (diag_12 + tl_uv) >> int32(1)
  52962 		uv1 = (diag_03 + t_uv) >> int32(1)
  52963 		v1 = top_dst + uintptr((int32(2)*x-int32(1))*int32(4))
  52964 		v2 = int32(**(**uint8_t)(__ccgo_up(top_y + uintptr(int32(2)*x-int32(1)))))
  52965 		v3 = int32(uint8(uv02 & uint32(0xff)))
  52966 		v4 = int32(uint8(uv02 >> libc.Int32FromInt32(16)))
  52967 		v5 = v1
  52968 		v8 = v2 * int32(19077) >> int32(8)
  52969 		goto _90
  52970 	_90:
  52971 		v10 = v4 * int32(26149) >> int32(8)
  52972 		goto _92
  52973 	_92:
  52974 		v12 = v8 + v10 - int32(14234)
  52975 		if v12 & ^int32(YUV_MASK2) == 0 {
  52976 			v15 = v12 >> int32(YUV_FIX2)
  52977 		} else {
  52978 			if v12 < 0 {
  52979 				v16 = 0
  52980 			} else {
  52981 				v16 = int32(255)
  52982 			}
  52983 			v15 = v16
  52984 		}
  52985 		v13 = v15
  52986 		goto _95
  52987 	_95:
  52988 		v6 = v13
  52989 		goto _88
  52990 	_88:
  52991 		**(**uint8_t)(__ccgo_up(v5)) = uint8(v6)
  52992 		v19 = v2 * int32(19077) >> int32(8)
  52993 		goto _101
  52994 	_101:
  52995 		v21 = v3 * int32(6419) >> int32(8)
  52996 		goto _103
  52997 	_103:
  52998 		v23 = v4 * int32(13320) >> int32(8)
  52999 		goto _105
  53000 	_105:
  53001 		v25 = v19 - v21 - v23 + int32(8708)
  53002 		if v25 & ^int32(YUV_MASK2) == 0 {
  53003 			v28 = v25 >> int32(YUV_FIX2)
  53004 		} else {
  53005 			if v25 < 0 {
  53006 				v29 = 0
  53007 			} else {
  53008 				v29 = int32(255)
  53009 			}
  53010 			v28 = v29
  53011 		}
  53012 		v26 = v28
  53013 		goto _108
  53014 	_108:
  53015 		v17 = v26
  53016 		goto _99
  53017 	_99:
  53018 		**(**uint8_t)(__ccgo_up(v5 + 1)) = uint8(v17)
  53019 		v32 = v2 * int32(19077) >> int32(8)
  53020 		goto _114
  53021 	_114:
  53022 		v34 = v3 * int32(33050) >> int32(8)
  53023 		goto _116
  53024 	_116:
  53025 		v36 = v32 + v34 - int32(17685)
  53026 		if v36 & ^int32(YUV_MASK2) == 0 {
  53027 			v39 = v36 >> int32(YUV_FIX2)
  53028 		} else {
  53029 			if v36 < 0 {
  53030 				v40 = 0
  53031 			} else {
  53032 				v40 = int32(255)
  53033 			}
  53034 			v39 = v40
  53035 		}
  53036 		v37 = v39
  53037 		goto _119
  53038 	_119:
  53039 		v30 = v37
  53040 		goto _112
  53041 	_112:
  53042 		**(**uint8_t)(__ccgo_up(v5 + 2)) = uint8(v30)
  53043 		**(**uint8_t)(__ccgo_up(v1 + 3)) = uint8(0xff)
  53044 		v1 = top_dst + uintptr((int32(2)*x-0)*int32(4))
  53045 		v2 = int32(**(**uint8_t)(__ccgo_up(top_y + uintptr(int32(2)*x-0))))
  53046 		v3 = int32(uint8(uv1 & uint32(0xff)))
  53047 		v4 = int32(uint8(uv1 >> libc.Int32FromInt32(16)))
  53048 		v5 = v1
  53049 		v8 = v2 * int32(19077) >> int32(8)
  53050 		goto _130
  53051 	_130:
  53052 		v10 = v4 * int32(26149) >> int32(8)
  53053 		goto _132
  53054 	_132:
  53055 		v12 = v8 + v10 - int32(14234)
  53056 		if v12 & ^int32(YUV_MASK2) == 0 {
  53057 			v15 = v12 >> int32(YUV_FIX2)
  53058 		} else {
  53059 			if v12 < 0 {
  53060 				v16 = 0
  53061 			} else {
  53062 				v16 = int32(255)
  53063 			}
  53064 			v15 = v16
  53065 		}
  53066 		v13 = v15
  53067 		goto _135
  53068 	_135:
  53069 		v6 = v13
  53070 		goto _128
  53071 	_128:
  53072 		**(**uint8_t)(__ccgo_up(v5)) = uint8(v6)
  53073 		v19 = v2 * int32(19077) >> int32(8)
  53074 		goto _141
  53075 	_141:
  53076 		v21 = v3 * int32(6419) >> int32(8)
  53077 		goto _143
  53078 	_143:
  53079 		v23 = v4 * int32(13320) >> int32(8)
  53080 		goto _145
  53081 	_145:
  53082 		v25 = v19 - v21 - v23 + int32(8708)
  53083 		if v25 & ^int32(YUV_MASK2) == 0 {
  53084 			v28 = v25 >> int32(YUV_FIX2)
  53085 		} else {
  53086 			if v25 < 0 {
  53087 				v29 = 0
  53088 			} else {
  53089 				v29 = int32(255)
  53090 			}
  53091 			v28 = v29
  53092 		}
  53093 		v26 = v28
  53094 		goto _148
  53095 	_148:
  53096 		v17 = v26
  53097 		goto _139
  53098 	_139:
  53099 		**(**uint8_t)(__ccgo_up(v5 + 1)) = uint8(v17)
  53100 		v32 = v2 * int32(19077) >> int32(8)
  53101 		goto _154
  53102 	_154:
  53103 		v34 = v3 * int32(33050) >> int32(8)
  53104 		goto _156
  53105 	_156:
  53106 		v36 = v32 + v34 - int32(17685)
  53107 		if v36 & ^int32(YUV_MASK2) == 0 {
  53108 			v39 = v36 >> int32(YUV_FIX2)
  53109 		} else {
  53110 			if v36 < 0 {
  53111 				v40 = 0
  53112 			} else {
  53113 				v40 = int32(255)
  53114 			}
  53115 			v39 = v40
  53116 		}
  53117 		v37 = v39
  53118 		goto _159
  53119 	_159:
  53120 		v30 = v37
  53121 		goto _152
  53122 	_152:
  53123 		**(**uint8_t)(__ccgo_up(v5 + 2)) = uint8(v30)
  53124 		**(**uint8_t)(__ccgo_up(v1 + 3)) = uint8(0xff)
  53125 		if bottom_y != libc.UintptrFromInt32(0) {
  53126 			uv03 = (diag_03 + l_uv) >> int32(1)
  53127 			uv11 = (diag_12 + uv) >> int32(1)
  53128 			v1 = bottom_dst + uintptr((int32(2)*x-int32(1))*int32(4))
  53129 			v2 = int32(**(**uint8_t)(__ccgo_up(bottom_y + uintptr(int32(2)*x-int32(1)))))
  53130 			v3 = int32(uint8(uv03 & uint32(0xff)))
  53131 			v4 = int32(uint8(uv03 >> libc.Int32FromInt32(16)))
  53132 			v5 = v1
  53133 			v8 = v2 * int32(19077) >> int32(8)
  53134 			goto _170
  53135 		_170:
  53136 			v10 = v4 * int32(26149) >> int32(8)
  53137 			goto _172
  53138 		_172:
  53139 			v12 = v8 + v10 - int32(14234)
  53140 			if v12 & ^int32(YUV_MASK2) == 0 {
  53141 				v15 = v12 >> int32(YUV_FIX2)
  53142 			} else {
  53143 				if v12 < 0 {
  53144 					v16 = 0
  53145 				} else {
  53146 					v16 = int32(255)
  53147 				}
  53148 				v15 = v16
  53149 			}
  53150 			v13 = v15
  53151 			goto _175
  53152 		_175:
  53153 			v6 = v13
  53154 			goto _168
  53155 		_168:
  53156 			**(**uint8_t)(__ccgo_up(v5)) = uint8(v6)
  53157 			v19 = v2 * int32(19077) >> int32(8)
  53158 			goto _181
  53159 		_181:
  53160 			v21 = v3 * int32(6419) >> int32(8)
  53161 			goto _183
  53162 		_183:
  53163 			v23 = v4 * int32(13320) >> int32(8)
  53164 			goto _185
  53165 		_185:
  53166 			v25 = v19 - v21 - v23 + int32(8708)
  53167 			if v25 & ^int32(YUV_MASK2) == 0 {
  53168 				v28 = v25 >> int32(YUV_FIX2)
  53169 			} else {
  53170 				if v25 < 0 {
  53171 					v29 = 0
  53172 				} else {
  53173 					v29 = int32(255)
  53174 				}
  53175 				v28 = v29
  53176 			}
  53177 			v26 = v28
  53178 			goto _188
  53179 		_188:
  53180 			v17 = v26
  53181 			goto _179
  53182 		_179:
  53183 			**(**uint8_t)(__ccgo_up(v5 + 1)) = uint8(v17)
  53184 			v32 = v2 * int32(19077) >> int32(8)
  53185 			goto _194
  53186 		_194:
  53187 			v34 = v3 * int32(33050) >> int32(8)
  53188 			goto _196
  53189 		_196:
  53190 			v36 = v32 + v34 - int32(17685)
  53191 			if v36 & ^int32(YUV_MASK2) == 0 {
  53192 				v39 = v36 >> int32(YUV_FIX2)
  53193 			} else {
  53194 				if v36 < 0 {
  53195 					v40 = 0
  53196 				} else {
  53197 					v40 = int32(255)
  53198 				}
  53199 				v39 = v40
  53200 			}
  53201 			v37 = v39
  53202 			goto _199
  53203 		_199:
  53204 			v30 = v37
  53205 			goto _192
  53206 		_192:
  53207 			**(**uint8_t)(__ccgo_up(v5 + 2)) = uint8(v30)
  53208 			**(**uint8_t)(__ccgo_up(v1 + 3)) = uint8(0xff)
  53209 			v1 = bottom_dst + uintptr((int32(2)*x+0)*int32(4))
  53210 			v2 = int32(**(**uint8_t)(__ccgo_up(bottom_y + uintptr(int32(2)*x+0))))
  53211 			v3 = int32(uint8(uv11 & uint32(0xff)))
  53212 			v4 = int32(uint8(uv11 >> libc.Int32FromInt32(16)))
  53213 			v5 = v1
  53214 			v8 = v2 * int32(19077) >> int32(8)
  53215 			goto _210
  53216 		_210:
  53217 			v10 = v4 * int32(26149) >> int32(8)
  53218 			goto _212
  53219 		_212:
  53220 			v12 = v8 + v10 - int32(14234)
  53221 			if v12 & ^int32(YUV_MASK2) == 0 {
  53222 				v15 = v12 >> int32(YUV_FIX2)
  53223 			} else {
  53224 				if v12 < 0 {
  53225 					v16 = 0
  53226 				} else {
  53227 					v16 = int32(255)
  53228 				}
  53229 				v15 = v16
  53230 			}
  53231 			v13 = v15
  53232 			goto _215
  53233 		_215:
  53234 			v6 = v13
  53235 			goto _208
  53236 		_208:
  53237 			**(**uint8_t)(__ccgo_up(v5)) = uint8(v6)
  53238 			v19 = v2 * int32(19077) >> int32(8)
  53239 			goto _221
  53240 		_221:
  53241 			v21 = v3 * int32(6419) >> int32(8)
  53242 			goto _223
  53243 		_223:
  53244 			v23 = v4 * int32(13320) >> int32(8)
  53245 			goto _225
  53246 		_225:
  53247 			v25 = v19 - v21 - v23 + int32(8708)
  53248 			if v25 & ^int32(YUV_MASK2) == 0 {
  53249 				v28 = v25 >> int32(YUV_FIX2)
  53250 			} else {
  53251 				if v25 < 0 {
  53252 					v29 = 0
  53253 				} else {
  53254 					v29 = int32(255)
  53255 				}
  53256 				v28 = v29
  53257 			}
  53258 			v26 = v28
  53259 			goto _228
  53260 		_228:
  53261 			v17 = v26
  53262 			goto _219
  53263 		_219:
  53264 			**(**uint8_t)(__ccgo_up(v5 + 1)) = uint8(v17)
  53265 			v32 = v2 * int32(19077) >> int32(8)
  53266 			goto _234
  53267 		_234:
  53268 			v34 = v3 * int32(33050) >> int32(8)
  53269 			goto _236
  53270 		_236:
  53271 			v36 = v32 + v34 - int32(17685)
  53272 			if v36 & ^int32(YUV_MASK2) == 0 {
  53273 				v39 = v36 >> int32(YUV_FIX2)
  53274 			} else {
  53275 				if v36 < 0 {
  53276 					v40 = 0
  53277 				} else {
  53278 					v40 = int32(255)
  53279 				}
  53280 				v39 = v40
  53281 			}
  53282 			v37 = v39
  53283 			goto _239
  53284 		_239:
  53285 			v30 = v37
  53286 			goto _232
  53287 		_232:
  53288 			**(**uint8_t)(__ccgo_up(v5 + 2)) = uint8(v30)
  53289 			**(**uint8_t)(__ccgo_up(v1 + 3)) = uint8(0xff)
  53290 		}
  53291 		tl_uv = t_uv
  53292 		l_uv = uv
  53293 		goto _81
  53294 	_81:
  53295 		;
  53296 		x = x + 1
  53297 	}
  53298 	if !(len1&libc.Int32FromInt32(1) != 0) {
  53299 		uv04 = (uint32(3)*tl_uv + l_uv + uint32(0x00020002)) >> int32(2)
  53300 		v1 = top_dst + uintptr((len1-int32(1))*int32(4))
  53301 		v2 = int32(**(**uint8_t)(__ccgo_up(top_y + uintptr(len1-int32(1)))))
  53302 		v3 = int32(uint8(uv04 & uint32(0xff)))
  53303 		v4 = int32(uint8(uv04 >> libc.Int32FromInt32(16)))
  53304 		v5 = v1
  53305 		v8 = v2 * int32(19077) >> int32(8)
  53306 		goto _250
  53307 	_250:
  53308 		v10 = v4 * int32(26149) >> int32(8)
  53309 		goto _252
  53310 	_252:
  53311 		v12 = v8 + v10 - int32(14234)
  53312 		if v12 & ^int32(YUV_MASK2) == 0 {
  53313 			v15 = v12 >> int32(YUV_FIX2)
  53314 		} else {
  53315 			if v12 < 0 {
  53316 				v16 = 0
  53317 			} else {
  53318 				v16 = int32(255)
  53319 			}
  53320 			v15 = v16
  53321 		}
  53322 		v13 = v15
  53323 		goto _255
  53324 	_255:
  53325 		v6 = v13
  53326 		goto _248
  53327 	_248:
  53328 		**(**uint8_t)(__ccgo_up(v5)) = uint8(v6)
  53329 		v19 = v2 * int32(19077) >> int32(8)
  53330 		goto _261
  53331 	_261:
  53332 		v21 = v3 * int32(6419) >> int32(8)
  53333 		goto _263
  53334 	_263:
  53335 		v23 = v4 * int32(13320) >> int32(8)
  53336 		goto _265
  53337 	_265:
  53338 		v25 = v19 - v21 - v23 + int32(8708)
  53339 		if v25 & ^int32(YUV_MASK2) == 0 {
  53340 			v28 = v25 >> int32(YUV_FIX2)
  53341 		} else {
  53342 			if v25 < 0 {
  53343 				v29 = 0
  53344 			} else {
  53345 				v29 = int32(255)
  53346 			}
  53347 			v28 = v29
  53348 		}
  53349 		v26 = v28
  53350 		goto _268
  53351 	_268:
  53352 		v17 = v26
  53353 		goto _259
  53354 	_259:
  53355 		**(**uint8_t)(__ccgo_up(v5 + 1)) = uint8(v17)
  53356 		v32 = v2 * int32(19077) >> int32(8)
  53357 		goto _274
  53358 	_274:
  53359 		v34 = v3 * int32(33050) >> int32(8)
  53360 		goto _276
  53361 	_276:
  53362 		v36 = v32 + v34 - int32(17685)
  53363 		if v36 & ^int32(YUV_MASK2) == 0 {
  53364 			v39 = v36 >> int32(YUV_FIX2)
  53365 		} else {
  53366 			if v36 < 0 {
  53367 				v40 = 0
  53368 			} else {
  53369 				v40 = int32(255)
  53370 			}
  53371 			v39 = v40
  53372 		}
  53373 		v37 = v39
  53374 		goto _279
  53375 	_279:
  53376 		v30 = v37
  53377 		goto _272
  53378 	_272:
  53379 		**(**uint8_t)(__ccgo_up(v5 + 2)) = uint8(v30)
  53380 		**(**uint8_t)(__ccgo_up(v1 + 3)) = uint8(0xff)
  53381 		if bottom_y != libc.UintptrFromInt32(0) {
  53382 			uv05 = (uint32(3)*l_uv + tl_uv + uint32(0x00020002)) >> int32(2)
  53383 			v1 = bottom_dst + uintptr((len1-int32(1))*int32(4))
  53384 			v2 = int32(**(**uint8_t)(__ccgo_up(bottom_y + uintptr(len1-int32(1)))))
  53385 			v3 = int32(uint8(uv05 & uint32(0xff)))
  53386 			v4 = int32(uint8(uv05 >> libc.Int32FromInt32(16)))
  53387 			v5 = v1
  53388 			v8 = v2 * int32(19077) >> int32(8)
  53389 			goto _290
  53390 		_290:
  53391 			v10 = v4 * int32(26149) >> int32(8)
  53392 			goto _292
  53393 		_292:
  53394 			v12 = v8 + v10 - int32(14234)
  53395 			if v12 & ^int32(YUV_MASK2) == 0 {
  53396 				v15 = v12 >> int32(YUV_FIX2)
  53397 			} else {
  53398 				if v12 < 0 {
  53399 					v16 = 0
  53400 				} else {
  53401 					v16 = int32(255)
  53402 				}
  53403 				v15 = v16
  53404 			}
  53405 			v13 = v15
  53406 			goto _295
  53407 		_295:
  53408 			v6 = v13
  53409 			goto _288
  53410 		_288:
  53411 			**(**uint8_t)(__ccgo_up(v5)) = uint8(v6)
  53412 			v19 = v2 * int32(19077) >> int32(8)
  53413 			goto _301
  53414 		_301:
  53415 			v21 = v3 * int32(6419) >> int32(8)
  53416 			goto _303
  53417 		_303:
  53418 			v23 = v4 * int32(13320) >> int32(8)
  53419 			goto _305
  53420 		_305:
  53421 			v25 = v19 - v21 - v23 + int32(8708)
  53422 			if v25 & ^int32(YUV_MASK2) == 0 {
  53423 				v28 = v25 >> int32(YUV_FIX2)
  53424 			} else {
  53425 				if v25 < 0 {
  53426 					v29 = 0
  53427 				} else {
  53428 					v29 = int32(255)
  53429 				}
  53430 				v28 = v29
  53431 			}
  53432 			v26 = v28
  53433 			goto _308
  53434 		_308:
  53435 			v17 = v26
  53436 			goto _299
  53437 		_299:
  53438 			**(**uint8_t)(__ccgo_up(v5 + 1)) = uint8(v17)
  53439 			v32 = v2 * int32(19077) >> int32(8)
  53440 			goto _314
  53441 		_314:
  53442 			v34 = v3 * int32(33050) >> int32(8)
  53443 			goto _316
  53444 		_316:
  53445 			v36 = v32 + v34 - int32(17685)
  53446 			if v36 & ^int32(YUV_MASK2) == 0 {
  53447 				v39 = v36 >> int32(YUV_FIX2)
  53448 			} else {
  53449 				if v36 < 0 {
  53450 					v40 = 0
  53451 				} else {
  53452 					v40 = int32(255)
  53453 				}
  53454 				v39 = v40
  53455 			}
  53456 			v37 = v39
  53457 			goto _319
  53458 		_319:
  53459 			v30 = v37
  53460 			goto _312
  53461 		_312:
  53462 			**(**uint8_t)(__ccgo_up(v5 + 2)) = uint8(v30)
  53463 			**(**uint8_t)(__ccgo_up(v1 + 3)) = uint8(0xff)
  53464 		}
  53465 	}
  53466 }
  53467 
  53468 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) {
  53469 	var avg, diag_03, diag_12, l_uv, t_uv, tl_uv, uv, uv0, uv01, uv02, uv03, uv04, uv05, uv1, uv11 uint32_t
  53470 	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
  53471 	var v1, v5 uintptr
  53472 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  53473 	last_pixel_pair = (len1 - int32(1)) >> int32(1)
  53474 	tl_uv = uint32(int32(**(**uint8_t)(__ccgo_up(top_u))) | int32(**(**uint8_t)(__ccgo_up(top_v)))<<libc.Int32FromInt32(16)) /* top-left sample */
  53475 	l_uv = uint32(int32(**(**uint8_t)(__ccgo_up(cur_u))) | int32(**(**uint8_t)(__ccgo_up(cur_v)))<<libc.Int32FromInt32(16))
  53476 	uv0 = (uint32(3)*tl_uv + l_uv + uint32(0x00020002)) >> int32(2)
  53477 	v1 = top_dst
  53478 	v2 = int32(**(**uint8_t)(__ccgo_up(top_y)))
  53479 	v3 = int32(uint8(uv0 & uint32(0xff)))
  53480 	v4 = int32(uint8(uv0 >> libc.Int32FromInt32(16)))
  53481 	v5 = v1
  53482 	v8 = v2 * int32(19077) >> int32(8)
  53483 	goto _9
  53484 _9:
  53485 	v10 = v3 * int32(33050) >> int32(8)
  53486 	goto _11
  53487 _11:
  53488 	v12 = v8 + v10 - int32(17685)
  53489 	if v12 & ^int32(YUV_MASK2) == 0 {
  53490 		v15 = v12 >> int32(YUV_FIX2)
  53491 	} else {
  53492 		if v12 < 0 {
  53493 			v16 = 0
  53494 		} else {
  53495 			v16 = int32(255)
  53496 		}
  53497 		v15 = v16
  53498 	}
  53499 	v13 = v15
  53500 	goto _14
  53501 _14:
  53502 	v6 = v13
  53503 	goto _7
  53504 _7:
  53505 	**(**uint8_t)(__ccgo_up(v5)) = uint8(v6)
  53506 	v19 = v2 * int32(19077) >> int32(8)
  53507 	goto _20
  53508 _20:
  53509 	v21 = v3 * int32(6419) >> int32(8)
  53510 	goto _22
  53511 _22:
  53512 	v23 = v4 * int32(13320) >> int32(8)
  53513 	goto _24
  53514 _24:
  53515 	v25 = v19 - v21 - v23 + int32(8708)
  53516 	if v25 & ^int32(YUV_MASK2) == 0 {
  53517 		v28 = v25 >> int32(YUV_FIX2)
  53518 	} else {
  53519 		if v25 < 0 {
  53520 			v29 = 0
  53521 		} else {
  53522 			v29 = int32(255)
  53523 		}
  53524 		v28 = v29
  53525 	}
  53526 	v26 = v28
  53527 	goto _27
  53528 _27:
  53529 	v17 = v26
  53530 	goto _18
  53531 _18:
  53532 	**(**uint8_t)(__ccgo_up(v5 + 1)) = uint8(v17)
  53533 	v32 = v2 * int32(19077) >> int32(8)
  53534 	goto _33
  53535 _33:
  53536 	v34 = v4 * int32(26149) >> int32(8)
  53537 	goto _35
  53538 _35:
  53539 	v36 = v32 + v34 - int32(14234)
  53540 	if v36 & ^int32(YUV_MASK2) == 0 {
  53541 		v39 = v36 >> int32(YUV_FIX2)
  53542 	} else {
  53543 		if v36 < 0 {
  53544 			v40 = 0
  53545 		} else {
  53546 			v40 = int32(255)
  53547 		}
  53548 		v39 = v40
  53549 	}
  53550 	v37 = v39
  53551 	goto _38
  53552 _38:
  53553 	v30 = v37
  53554 	goto _31
  53555 _31:
  53556 	**(**uint8_t)(__ccgo_up(v5 + 2)) = uint8(v30)
  53557 	**(**uint8_t)(__ccgo_up(v1 + 3)) = uint8(0xff)
  53558 	if bottom_y != libc.UintptrFromInt32(0) {
  53559 		uv01 = (uint32(3)*l_uv + tl_uv + uint32(0x00020002)) >> int32(2)
  53560 		v1 = bottom_dst
  53561 		v2 = int32(**(**uint8_t)(__ccgo_up(bottom_y)))
  53562 		v3 = int32(uint8(uv01 & uint32(0xff)))
  53563 		v4 = int32(uint8(uv01 >> libc.Int32FromInt32(16)))
  53564 		v5 = v1
  53565 		v8 = v2 * int32(19077) >> int32(8)
  53566 		goto _49
  53567 	_49:
  53568 		v10 = v3 * int32(33050) >> int32(8)
  53569 		goto _51
  53570 	_51:
  53571 		v12 = v8 + v10 - int32(17685)
  53572 		if v12 & ^int32(YUV_MASK2) == 0 {
  53573 			v15 = v12 >> int32(YUV_FIX2)
  53574 		} else {
  53575 			if v12 < 0 {
  53576 				v16 = 0
  53577 			} else {
  53578 				v16 = int32(255)
  53579 			}
  53580 			v15 = v16
  53581 		}
  53582 		v13 = v15
  53583 		goto _54
  53584 	_54:
  53585 		v6 = v13
  53586 		goto _47
  53587 	_47:
  53588 		**(**uint8_t)(__ccgo_up(v5)) = uint8(v6)
  53589 		v19 = v2 * int32(19077) >> int32(8)
  53590 		goto _60
  53591 	_60:
  53592 		v21 = v3 * int32(6419) >> int32(8)
  53593 		goto _62
  53594 	_62:
  53595 		v23 = v4 * int32(13320) >> int32(8)
  53596 		goto _64
  53597 	_64:
  53598 		v25 = v19 - v21 - v23 + int32(8708)
  53599 		if v25 & ^int32(YUV_MASK2) == 0 {
  53600 			v28 = v25 >> int32(YUV_FIX2)
  53601 		} else {
  53602 			if v25 < 0 {
  53603 				v29 = 0
  53604 			} else {
  53605 				v29 = int32(255)
  53606 			}
  53607 			v28 = v29
  53608 		}
  53609 		v26 = v28
  53610 		goto _67
  53611 	_67:
  53612 		v17 = v26
  53613 		goto _58
  53614 	_58:
  53615 		**(**uint8_t)(__ccgo_up(v5 + 1)) = uint8(v17)
  53616 		v32 = v2 * int32(19077) >> int32(8)
  53617 		goto _73
  53618 	_73:
  53619 		v34 = v4 * int32(26149) >> int32(8)
  53620 		goto _75
  53621 	_75:
  53622 		v36 = v32 + v34 - int32(14234)
  53623 		if v36 & ^int32(YUV_MASK2) == 0 {
  53624 			v39 = v36 >> int32(YUV_FIX2)
  53625 		} else {
  53626 			if v36 < 0 {
  53627 				v40 = 0
  53628 			} else {
  53629 				v40 = int32(255)
  53630 			}
  53631 			v39 = v40
  53632 		}
  53633 		v37 = v39
  53634 		goto _78
  53635 	_78:
  53636 		v30 = v37
  53637 		goto _71
  53638 	_71:
  53639 		**(**uint8_t)(__ccgo_up(v5 + 2)) = uint8(v30)
  53640 		**(**uint8_t)(__ccgo_up(v1 + 3)) = uint8(0xff)
  53641 	}
  53642 	x = int32(1)
  53643 	for {
  53644 		if !(x <= last_pixel_pair) {
  53645 			break
  53646 		}
  53647 		t_uv = uint32(int32(**(**uint8_t)(__ccgo_up(top_u + uintptr(x)))) | int32(**(**uint8_t)(__ccgo_up(top_v + uintptr(x))))<<libc.Int32FromInt32(16)) /* top sample */
  53648 		uv = uint32(int32(**(**uint8_t)(__ccgo_up(cur_u + uintptr(x)))) | int32(**(**uint8_t)(__ccgo_up(cur_v + uintptr(x))))<<libc.Int32FromInt32(16))   /* sample */ /* precompute invariant values associated with first and second diagonals*/
  53649 		avg = tl_uv + t_uv + l_uv + uv + uint32(0x00080008)
  53650 		diag_12 = (avg + uint32(2)*(t_uv+l_uv)) >> int32(3)
  53651 		diag_03 = (avg + uint32(2)*(tl_uv+uv)) >> int32(3)
  53652 		uv02 = (diag_12 + tl_uv) >> int32(1)
  53653 		uv1 = (diag_03 + t_uv) >> int32(1)
  53654 		v1 = top_dst + uintptr((int32(2)*x-int32(1))*int32(4))
  53655 		v2 = int32(**(**uint8_t)(__ccgo_up(top_y + uintptr(int32(2)*x-int32(1)))))
  53656 		v3 = int32(uint8(uv02 & uint32(0xff)))
  53657 		v4 = int32(uint8(uv02 >> libc.Int32FromInt32(16)))
  53658 		v5 = v1
  53659 		v8 = v2 * int32(19077) >> int32(8)
  53660 		goto _90
  53661 	_90:
  53662 		v10 = v3 * int32(33050) >> int32(8)
  53663 		goto _92
  53664 	_92:
  53665 		v12 = v8 + v10 - int32(17685)
  53666 		if v12 & ^int32(YUV_MASK2) == 0 {
  53667 			v15 = v12 >> int32(YUV_FIX2)
  53668 		} else {
  53669 			if v12 < 0 {
  53670 				v16 = 0
  53671 			} else {
  53672 				v16 = int32(255)
  53673 			}
  53674 			v15 = v16
  53675 		}
  53676 		v13 = v15
  53677 		goto _95
  53678 	_95:
  53679 		v6 = v13
  53680 		goto _88
  53681 	_88:
  53682 		**(**uint8_t)(__ccgo_up(v5)) = uint8(v6)
  53683 		v19 = v2 * int32(19077) >> int32(8)
  53684 		goto _101
  53685 	_101:
  53686 		v21 = v3 * int32(6419) >> int32(8)
  53687 		goto _103
  53688 	_103:
  53689 		v23 = v4 * int32(13320) >> int32(8)
  53690 		goto _105
  53691 	_105:
  53692 		v25 = v19 - v21 - v23 + int32(8708)
  53693 		if v25 & ^int32(YUV_MASK2) == 0 {
  53694 			v28 = v25 >> int32(YUV_FIX2)
  53695 		} else {
  53696 			if v25 < 0 {
  53697 				v29 = 0
  53698 			} else {
  53699 				v29 = int32(255)
  53700 			}
  53701 			v28 = v29
  53702 		}
  53703 		v26 = v28
  53704 		goto _108
  53705 	_108:
  53706 		v17 = v26
  53707 		goto _99
  53708 	_99:
  53709 		**(**uint8_t)(__ccgo_up(v5 + 1)) = uint8(v17)
  53710 		v32 = v2 * int32(19077) >> int32(8)
  53711 		goto _114
  53712 	_114:
  53713 		v34 = v4 * int32(26149) >> int32(8)
  53714 		goto _116
  53715 	_116:
  53716 		v36 = v32 + v34 - int32(14234)
  53717 		if v36 & ^int32(YUV_MASK2) == 0 {
  53718 			v39 = v36 >> int32(YUV_FIX2)
  53719 		} else {
  53720 			if v36 < 0 {
  53721 				v40 = 0
  53722 			} else {
  53723 				v40 = int32(255)
  53724 			}
  53725 			v39 = v40
  53726 		}
  53727 		v37 = v39
  53728 		goto _119
  53729 	_119:
  53730 		v30 = v37
  53731 		goto _112
  53732 	_112:
  53733 		**(**uint8_t)(__ccgo_up(v5 + 2)) = uint8(v30)
  53734 		**(**uint8_t)(__ccgo_up(v1 + 3)) = uint8(0xff)
  53735 		v1 = top_dst + uintptr((int32(2)*x-0)*int32(4))
  53736 		v2 = int32(**(**uint8_t)(__ccgo_up(top_y + uintptr(int32(2)*x-0))))
  53737 		v3 = int32(uint8(uv1 & uint32(0xff)))
  53738 		v4 = int32(uint8(uv1 >> libc.Int32FromInt32(16)))
  53739 		v5 = v1
  53740 		v8 = v2 * int32(19077) >> int32(8)
  53741 		goto _130
  53742 	_130:
  53743 		v10 = v3 * int32(33050) >> int32(8)
  53744 		goto _132
  53745 	_132:
  53746 		v12 = v8 + v10 - int32(17685)
  53747 		if v12 & ^int32(YUV_MASK2) == 0 {
  53748 			v15 = v12 >> int32(YUV_FIX2)
  53749 		} else {
  53750 			if v12 < 0 {
  53751 				v16 = 0
  53752 			} else {
  53753 				v16 = int32(255)
  53754 			}
  53755 			v15 = v16
  53756 		}
  53757 		v13 = v15
  53758 		goto _135
  53759 	_135:
  53760 		v6 = v13
  53761 		goto _128
  53762 	_128:
  53763 		**(**uint8_t)(__ccgo_up(v5)) = uint8(v6)
  53764 		v19 = v2 * int32(19077) >> int32(8)
  53765 		goto _141
  53766 	_141:
  53767 		v21 = v3 * int32(6419) >> int32(8)
  53768 		goto _143
  53769 	_143:
  53770 		v23 = v4 * int32(13320) >> int32(8)
  53771 		goto _145
  53772 	_145:
  53773 		v25 = v19 - v21 - v23 + int32(8708)
  53774 		if v25 & ^int32(YUV_MASK2) == 0 {
  53775 			v28 = v25 >> int32(YUV_FIX2)
  53776 		} else {
  53777 			if v25 < 0 {
  53778 				v29 = 0
  53779 			} else {
  53780 				v29 = int32(255)
  53781 			}
  53782 			v28 = v29
  53783 		}
  53784 		v26 = v28
  53785 		goto _148
  53786 	_148:
  53787 		v17 = v26
  53788 		goto _139
  53789 	_139:
  53790 		**(**uint8_t)(__ccgo_up(v5 + 1)) = uint8(v17)
  53791 		v32 = v2 * int32(19077) >> int32(8)
  53792 		goto _154
  53793 	_154:
  53794 		v34 = v4 * int32(26149) >> int32(8)
  53795 		goto _156
  53796 	_156:
  53797 		v36 = v32 + v34 - int32(14234)
  53798 		if v36 & ^int32(YUV_MASK2) == 0 {
  53799 			v39 = v36 >> int32(YUV_FIX2)
  53800 		} else {
  53801 			if v36 < 0 {
  53802 				v40 = 0
  53803 			} else {
  53804 				v40 = int32(255)
  53805 			}
  53806 			v39 = v40
  53807 		}
  53808 		v37 = v39
  53809 		goto _159
  53810 	_159:
  53811 		v30 = v37
  53812 		goto _152
  53813 	_152:
  53814 		**(**uint8_t)(__ccgo_up(v5 + 2)) = uint8(v30)
  53815 		**(**uint8_t)(__ccgo_up(v1 + 3)) = uint8(0xff)
  53816 		if bottom_y != libc.UintptrFromInt32(0) {
  53817 			uv03 = (diag_03 + l_uv) >> int32(1)
  53818 			uv11 = (diag_12 + uv) >> int32(1)
  53819 			v1 = bottom_dst + uintptr((int32(2)*x-int32(1))*int32(4))
  53820 			v2 = int32(**(**uint8_t)(__ccgo_up(bottom_y + uintptr(int32(2)*x-int32(1)))))
  53821 			v3 = int32(uint8(uv03 & uint32(0xff)))
  53822 			v4 = int32(uint8(uv03 >> libc.Int32FromInt32(16)))
  53823 			v5 = v1
  53824 			v8 = v2 * int32(19077) >> int32(8)
  53825 			goto _170
  53826 		_170:
  53827 			v10 = v3 * int32(33050) >> int32(8)
  53828 			goto _172
  53829 		_172:
  53830 			v12 = v8 + v10 - int32(17685)
  53831 			if v12 & ^int32(YUV_MASK2) == 0 {
  53832 				v15 = v12 >> int32(YUV_FIX2)
  53833 			} else {
  53834 				if v12 < 0 {
  53835 					v16 = 0
  53836 				} else {
  53837 					v16 = int32(255)
  53838 				}
  53839 				v15 = v16
  53840 			}
  53841 			v13 = v15
  53842 			goto _175
  53843 		_175:
  53844 			v6 = v13
  53845 			goto _168
  53846 		_168:
  53847 			**(**uint8_t)(__ccgo_up(v5)) = uint8(v6)
  53848 			v19 = v2 * int32(19077) >> int32(8)
  53849 			goto _181
  53850 		_181:
  53851 			v21 = v3 * int32(6419) >> int32(8)
  53852 			goto _183
  53853 		_183:
  53854 			v23 = v4 * int32(13320) >> int32(8)
  53855 			goto _185
  53856 		_185:
  53857 			v25 = v19 - v21 - v23 + int32(8708)
  53858 			if v25 & ^int32(YUV_MASK2) == 0 {
  53859 				v28 = v25 >> int32(YUV_FIX2)
  53860 			} else {
  53861 				if v25 < 0 {
  53862 					v29 = 0
  53863 				} else {
  53864 					v29 = int32(255)
  53865 				}
  53866 				v28 = v29
  53867 			}
  53868 			v26 = v28
  53869 			goto _188
  53870 		_188:
  53871 			v17 = v26
  53872 			goto _179
  53873 		_179:
  53874 			**(**uint8_t)(__ccgo_up(v5 + 1)) = uint8(v17)
  53875 			v32 = v2 * int32(19077) >> int32(8)
  53876 			goto _194
  53877 		_194:
  53878 			v34 = v4 * int32(26149) >> int32(8)
  53879 			goto _196
  53880 		_196:
  53881 			v36 = v32 + v34 - int32(14234)
  53882 			if v36 & ^int32(YUV_MASK2) == 0 {
  53883 				v39 = v36 >> int32(YUV_FIX2)
  53884 			} else {
  53885 				if v36 < 0 {
  53886 					v40 = 0
  53887 				} else {
  53888 					v40 = int32(255)
  53889 				}
  53890 				v39 = v40
  53891 			}
  53892 			v37 = v39
  53893 			goto _199
  53894 		_199:
  53895 			v30 = v37
  53896 			goto _192
  53897 		_192:
  53898 			**(**uint8_t)(__ccgo_up(v5 + 2)) = uint8(v30)
  53899 			**(**uint8_t)(__ccgo_up(v1 + 3)) = uint8(0xff)
  53900 			v1 = bottom_dst + uintptr((int32(2)*x+0)*int32(4))
  53901 			v2 = int32(**(**uint8_t)(__ccgo_up(bottom_y + uintptr(int32(2)*x+0))))
  53902 			v3 = int32(uint8(uv11 & uint32(0xff)))
  53903 			v4 = int32(uint8(uv11 >> libc.Int32FromInt32(16)))
  53904 			v5 = v1
  53905 			v8 = v2 * int32(19077) >> int32(8)
  53906 			goto _210
  53907 		_210:
  53908 			v10 = v3 * int32(33050) >> int32(8)
  53909 			goto _212
  53910 		_212:
  53911 			v12 = v8 + v10 - int32(17685)
  53912 			if v12 & ^int32(YUV_MASK2) == 0 {
  53913 				v15 = v12 >> int32(YUV_FIX2)
  53914 			} else {
  53915 				if v12 < 0 {
  53916 					v16 = 0
  53917 				} else {
  53918 					v16 = int32(255)
  53919 				}
  53920 				v15 = v16
  53921 			}
  53922 			v13 = v15
  53923 			goto _215
  53924 		_215:
  53925 			v6 = v13
  53926 			goto _208
  53927 		_208:
  53928 			**(**uint8_t)(__ccgo_up(v5)) = uint8(v6)
  53929 			v19 = v2 * int32(19077) >> int32(8)
  53930 			goto _221
  53931 		_221:
  53932 			v21 = v3 * int32(6419) >> int32(8)
  53933 			goto _223
  53934 		_223:
  53935 			v23 = v4 * int32(13320) >> int32(8)
  53936 			goto _225
  53937 		_225:
  53938 			v25 = v19 - v21 - v23 + int32(8708)
  53939 			if v25 & ^int32(YUV_MASK2) == 0 {
  53940 				v28 = v25 >> int32(YUV_FIX2)
  53941 			} else {
  53942 				if v25 < 0 {
  53943 					v29 = 0
  53944 				} else {
  53945 					v29 = int32(255)
  53946 				}
  53947 				v28 = v29
  53948 			}
  53949 			v26 = v28
  53950 			goto _228
  53951 		_228:
  53952 			v17 = v26
  53953 			goto _219
  53954 		_219:
  53955 			**(**uint8_t)(__ccgo_up(v5 + 1)) = uint8(v17)
  53956 			v32 = v2 * int32(19077) >> int32(8)
  53957 			goto _234
  53958 		_234:
  53959 			v34 = v4 * int32(26149) >> int32(8)
  53960 			goto _236
  53961 		_236:
  53962 			v36 = v32 + v34 - int32(14234)
  53963 			if v36 & ^int32(YUV_MASK2) == 0 {
  53964 				v39 = v36 >> int32(YUV_FIX2)
  53965 			} else {
  53966 				if v36 < 0 {
  53967 					v40 = 0
  53968 				} else {
  53969 					v40 = int32(255)
  53970 				}
  53971 				v39 = v40
  53972 			}
  53973 			v37 = v39
  53974 			goto _239
  53975 		_239:
  53976 			v30 = v37
  53977 			goto _232
  53978 		_232:
  53979 			**(**uint8_t)(__ccgo_up(v5 + 2)) = uint8(v30)
  53980 			**(**uint8_t)(__ccgo_up(v1 + 3)) = uint8(0xff)
  53981 		}
  53982 		tl_uv = t_uv
  53983 		l_uv = uv
  53984 		goto _81
  53985 	_81:
  53986 		;
  53987 		x = x + 1
  53988 	}
  53989 	if !(len1&libc.Int32FromInt32(1) != 0) {
  53990 		uv04 = (uint32(3)*tl_uv + l_uv + uint32(0x00020002)) >> int32(2)
  53991 		v1 = top_dst + uintptr((len1-int32(1))*int32(4))
  53992 		v2 = int32(**(**uint8_t)(__ccgo_up(top_y + uintptr(len1-int32(1)))))
  53993 		v3 = int32(uint8(uv04 & uint32(0xff)))
  53994 		v4 = int32(uint8(uv04 >> libc.Int32FromInt32(16)))
  53995 		v5 = v1
  53996 		v8 = v2 * int32(19077) >> int32(8)
  53997 		goto _250
  53998 	_250:
  53999 		v10 = v3 * int32(33050) >> int32(8)
  54000 		goto _252
  54001 	_252:
  54002 		v12 = v8 + v10 - int32(17685)
  54003 		if v12 & ^int32(YUV_MASK2) == 0 {
  54004 			v15 = v12 >> int32(YUV_FIX2)
  54005 		} else {
  54006 			if v12 < 0 {
  54007 				v16 = 0
  54008 			} else {
  54009 				v16 = int32(255)
  54010 			}
  54011 			v15 = v16
  54012 		}
  54013 		v13 = v15
  54014 		goto _255
  54015 	_255:
  54016 		v6 = v13
  54017 		goto _248
  54018 	_248:
  54019 		**(**uint8_t)(__ccgo_up(v5)) = uint8(v6)
  54020 		v19 = v2 * int32(19077) >> int32(8)
  54021 		goto _261
  54022 	_261:
  54023 		v21 = v3 * int32(6419) >> int32(8)
  54024 		goto _263
  54025 	_263:
  54026 		v23 = v4 * int32(13320) >> int32(8)
  54027 		goto _265
  54028 	_265:
  54029 		v25 = v19 - v21 - v23 + int32(8708)
  54030 		if v25 & ^int32(YUV_MASK2) == 0 {
  54031 			v28 = v25 >> int32(YUV_FIX2)
  54032 		} else {
  54033 			if v25 < 0 {
  54034 				v29 = 0
  54035 			} else {
  54036 				v29 = int32(255)
  54037 			}
  54038 			v28 = v29
  54039 		}
  54040 		v26 = v28
  54041 		goto _268
  54042 	_268:
  54043 		v17 = v26
  54044 		goto _259
  54045 	_259:
  54046 		**(**uint8_t)(__ccgo_up(v5 + 1)) = uint8(v17)
  54047 		v32 = v2 * int32(19077) >> int32(8)
  54048 		goto _274
  54049 	_274:
  54050 		v34 = v4 * int32(26149) >> int32(8)
  54051 		goto _276
  54052 	_276:
  54053 		v36 = v32 + v34 - int32(14234)
  54054 		if v36 & ^int32(YUV_MASK2) == 0 {
  54055 			v39 = v36 >> int32(YUV_FIX2)
  54056 		} else {
  54057 			if v36 < 0 {
  54058 				v40 = 0
  54059 			} else {
  54060 				v40 = int32(255)
  54061 			}
  54062 			v39 = v40
  54063 		}
  54064 		v37 = v39
  54065 		goto _279
  54066 	_279:
  54067 		v30 = v37
  54068 		goto _272
  54069 	_272:
  54070 		**(**uint8_t)(__ccgo_up(v5 + 2)) = uint8(v30)
  54071 		**(**uint8_t)(__ccgo_up(v1 + 3)) = uint8(0xff)
  54072 		if bottom_y != libc.UintptrFromInt32(0) {
  54073 			uv05 = (uint32(3)*l_uv + tl_uv + uint32(0x00020002)) >> int32(2)
  54074 			v1 = bottom_dst + uintptr((len1-int32(1))*int32(4))
  54075 			v2 = int32(**(**uint8_t)(__ccgo_up(bottom_y + uintptr(len1-int32(1)))))
  54076 			v3 = int32(uint8(uv05 & uint32(0xff)))
  54077 			v4 = int32(uint8(uv05 >> libc.Int32FromInt32(16)))
  54078 			v5 = v1
  54079 			v8 = v2 * int32(19077) >> int32(8)
  54080 			goto _290
  54081 		_290:
  54082 			v10 = v3 * int32(33050) >> int32(8)
  54083 			goto _292
  54084 		_292:
  54085 			v12 = v8 + v10 - int32(17685)
  54086 			if v12 & ^int32(YUV_MASK2) == 0 {
  54087 				v15 = v12 >> int32(YUV_FIX2)
  54088 			} else {
  54089 				if v12 < 0 {
  54090 					v16 = 0
  54091 				} else {
  54092 					v16 = int32(255)
  54093 				}
  54094 				v15 = v16
  54095 			}
  54096 			v13 = v15
  54097 			goto _295
  54098 		_295:
  54099 			v6 = v13
  54100 			goto _288
  54101 		_288:
  54102 			**(**uint8_t)(__ccgo_up(v5)) = uint8(v6)
  54103 			v19 = v2 * int32(19077) >> int32(8)
  54104 			goto _301
  54105 		_301:
  54106 			v21 = v3 * int32(6419) >> int32(8)
  54107 			goto _303
  54108 		_303:
  54109 			v23 = v4 * int32(13320) >> int32(8)
  54110 			goto _305
  54111 		_305:
  54112 			v25 = v19 - v21 - v23 + int32(8708)
  54113 			if v25 & ^int32(YUV_MASK2) == 0 {
  54114 				v28 = v25 >> int32(YUV_FIX2)
  54115 			} else {
  54116 				if v25 < 0 {
  54117 					v29 = 0
  54118 				} else {
  54119 					v29 = int32(255)
  54120 				}
  54121 				v28 = v29
  54122 			}
  54123 			v26 = v28
  54124 			goto _308
  54125 		_308:
  54126 			v17 = v26
  54127 			goto _299
  54128 		_299:
  54129 			**(**uint8_t)(__ccgo_up(v5 + 1)) = uint8(v17)
  54130 			v32 = v2 * int32(19077) >> int32(8)
  54131 			goto _314
  54132 		_314:
  54133 			v34 = v4 * int32(26149) >> int32(8)
  54134 			goto _316
  54135 		_316:
  54136 			v36 = v32 + v34 - int32(14234)
  54137 			if v36 & ^int32(YUV_MASK2) == 0 {
  54138 				v39 = v36 >> int32(YUV_FIX2)
  54139 			} else {
  54140 				if v36 < 0 {
  54141 					v40 = 0
  54142 				} else {
  54143 					v40 = int32(255)
  54144 				}
  54145 				v39 = v40
  54146 			}
  54147 			v37 = v39
  54148 			goto _319
  54149 		_319:
  54150 			v30 = v37
  54151 			goto _312
  54152 		_312:
  54153 			**(**uint8_t)(__ccgo_up(v5 + 2)) = uint8(v30)
  54154 			**(**uint8_t)(__ccgo_up(v1 + 3)) = uint8(0xff)
  54155 		}
  54156 	}
  54157 }
  54158 
  54159 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) {
  54160 	var avg, diag_03, diag_12, l_uv, t_uv, tl_uv, uv, uv0, uv01, uv02, uv03, uv04, uv05, uv1, uv11 uint32_t
  54161 	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
  54162 	var v1, v5 uintptr
  54163 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  54164 	last_pixel_pair = (len1 - int32(1)) >> int32(1)
  54165 	tl_uv = uint32(int32(**(**uint8_t)(__ccgo_up(top_u))) | int32(**(**uint8_t)(__ccgo_up(top_v)))<<libc.Int32FromInt32(16)) /* top-left sample */
  54166 	l_uv = uint32(int32(**(**uint8_t)(__ccgo_up(cur_u))) | int32(**(**uint8_t)(__ccgo_up(cur_v)))<<libc.Int32FromInt32(16))
  54167 	uv0 = (uint32(3)*tl_uv + l_uv + uint32(0x00020002)) >> int32(2)
  54168 	v1 = top_dst
  54169 	**(**uint8_t)(__ccgo_up(v1)) = uint8(0xff)
  54170 	v2 = int32(**(**uint8_t)(__ccgo_up(top_y)))
  54171 	v3 = int32(uint8(uv0 & uint32(0xff)))
  54172 	v4 = int32(uint8(uv0 >> libc.Int32FromInt32(16)))
  54173 	v5 = v1 + uintptr(1)
  54174 	v8 = v2 * int32(19077) >> int32(8)
  54175 	goto _9
  54176 _9:
  54177 	v10 = v4 * int32(26149) >> int32(8)
  54178 	goto _11
  54179 _11:
  54180 	v12 = v8 + v10 - int32(14234)
  54181 	if v12 & ^int32(YUV_MASK2) == 0 {
  54182 		v15 = v12 >> int32(YUV_FIX2)
  54183 	} else {
  54184 		if v12 < 0 {
  54185 			v16 = 0
  54186 		} else {
  54187 			v16 = int32(255)
  54188 		}
  54189 		v15 = v16
  54190 	}
  54191 	v13 = v15
  54192 	goto _14
  54193 _14:
  54194 	v6 = v13
  54195 	goto _7
  54196 _7:
  54197 	**(**uint8_t)(__ccgo_up(v5)) = uint8(v6)
  54198 	v19 = v2 * int32(19077) >> int32(8)
  54199 	goto _20
  54200 _20:
  54201 	v21 = v3 * int32(6419) >> int32(8)
  54202 	goto _22
  54203 _22:
  54204 	v23 = v4 * int32(13320) >> int32(8)
  54205 	goto _24
  54206 _24:
  54207 	v25 = v19 - v21 - v23 + int32(8708)
  54208 	if v25 & ^int32(YUV_MASK2) == 0 {
  54209 		v28 = v25 >> int32(YUV_FIX2)
  54210 	} else {
  54211 		if v25 < 0 {
  54212 			v29 = 0
  54213 		} else {
  54214 			v29 = int32(255)
  54215 		}
  54216 		v28 = v29
  54217 	}
  54218 	v26 = v28
  54219 	goto _27
  54220 _27:
  54221 	v17 = v26
  54222 	goto _18
  54223 _18:
  54224 	**(**uint8_t)(__ccgo_up(v5 + 1)) = uint8(v17)
  54225 	v32 = v2 * int32(19077) >> int32(8)
  54226 	goto _33
  54227 _33:
  54228 	v34 = v3 * int32(33050) >> int32(8)
  54229 	goto _35
  54230 _35:
  54231 	v36 = v32 + v34 - int32(17685)
  54232 	if v36 & ^int32(YUV_MASK2) == 0 {
  54233 		v39 = v36 >> int32(YUV_FIX2)
  54234 	} else {
  54235 		if v36 < 0 {
  54236 			v40 = 0
  54237 		} else {
  54238 			v40 = int32(255)
  54239 		}
  54240 		v39 = v40
  54241 	}
  54242 	v37 = v39
  54243 	goto _38
  54244 _38:
  54245 	v30 = v37
  54246 	goto _31
  54247 _31:
  54248 	**(**uint8_t)(__ccgo_up(v5 + 2)) = uint8(v30)
  54249 	if bottom_y != libc.UintptrFromInt32(0) {
  54250 		uv01 = (uint32(3)*l_uv + tl_uv + uint32(0x00020002)) >> int32(2)
  54251 		v1 = bottom_dst
  54252 		**(**uint8_t)(__ccgo_up(v1)) = uint8(0xff)
  54253 		v2 = int32(**(**uint8_t)(__ccgo_up(bottom_y)))
  54254 		v3 = int32(uint8(uv01 & uint32(0xff)))
  54255 		v4 = int32(uint8(uv01 >> libc.Int32FromInt32(16)))
  54256 		v5 = v1 + uintptr(1)
  54257 		v8 = v2 * int32(19077) >> int32(8)
  54258 		goto _49
  54259 	_49:
  54260 		v10 = v4 * int32(26149) >> int32(8)
  54261 		goto _51
  54262 	_51:
  54263 		v12 = v8 + v10 - int32(14234)
  54264 		if v12 & ^int32(YUV_MASK2) == 0 {
  54265 			v15 = v12 >> int32(YUV_FIX2)
  54266 		} else {
  54267 			if v12 < 0 {
  54268 				v16 = 0
  54269 			} else {
  54270 				v16 = int32(255)
  54271 			}
  54272 			v15 = v16
  54273 		}
  54274 		v13 = v15
  54275 		goto _54
  54276 	_54:
  54277 		v6 = v13
  54278 		goto _47
  54279 	_47:
  54280 		**(**uint8_t)(__ccgo_up(v5)) = uint8(v6)
  54281 		v19 = v2 * int32(19077) >> int32(8)
  54282 		goto _60
  54283 	_60:
  54284 		v21 = v3 * int32(6419) >> int32(8)
  54285 		goto _62
  54286 	_62:
  54287 		v23 = v4 * int32(13320) >> int32(8)
  54288 		goto _64
  54289 	_64:
  54290 		v25 = v19 - v21 - v23 + int32(8708)
  54291 		if v25 & ^int32(YUV_MASK2) == 0 {
  54292 			v28 = v25 >> int32(YUV_FIX2)
  54293 		} else {
  54294 			if v25 < 0 {
  54295 				v29 = 0
  54296 			} else {
  54297 				v29 = int32(255)
  54298 			}
  54299 			v28 = v29
  54300 		}
  54301 		v26 = v28
  54302 		goto _67
  54303 	_67:
  54304 		v17 = v26
  54305 		goto _58
  54306 	_58:
  54307 		**(**uint8_t)(__ccgo_up(v5 + 1)) = uint8(v17)
  54308 		v32 = v2 * int32(19077) >> int32(8)
  54309 		goto _73
  54310 	_73:
  54311 		v34 = v3 * int32(33050) >> int32(8)
  54312 		goto _75
  54313 	_75:
  54314 		v36 = v32 + v34 - int32(17685)
  54315 		if v36 & ^int32(YUV_MASK2) == 0 {
  54316 			v39 = v36 >> int32(YUV_FIX2)
  54317 		} else {
  54318 			if v36 < 0 {
  54319 				v40 = 0
  54320 			} else {
  54321 				v40 = int32(255)
  54322 			}
  54323 			v39 = v40
  54324 		}
  54325 		v37 = v39
  54326 		goto _78
  54327 	_78:
  54328 		v30 = v37
  54329 		goto _71
  54330 	_71:
  54331 		**(**uint8_t)(__ccgo_up(v5 + 2)) = uint8(v30)
  54332 	}
  54333 	x = int32(1)
  54334 	for {
  54335 		if !(x <= last_pixel_pair) {
  54336 			break
  54337 		}
  54338 		t_uv = uint32(int32(**(**uint8_t)(__ccgo_up(top_u + uintptr(x)))) | int32(**(**uint8_t)(__ccgo_up(top_v + uintptr(x))))<<libc.Int32FromInt32(16)) /* top sample */
  54339 		uv = uint32(int32(**(**uint8_t)(__ccgo_up(cur_u + uintptr(x)))) | int32(**(**uint8_t)(__ccgo_up(cur_v + uintptr(x))))<<libc.Int32FromInt32(16))   /* sample */ /* precompute invariant values associated with first and second diagonals*/
  54340 		avg = tl_uv + t_uv + l_uv + uv + uint32(0x00080008)
  54341 		diag_12 = (avg + uint32(2)*(t_uv+l_uv)) >> int32(3)
  54342 		diag_03 = (avg + uint32(2)*(tl_uv+uv)) >> int32(3)
  54343 		uv02 = (diag_12 + tl_uv) >> int32(1)
  54344 		uv1 = (diag_03 + t_uv) >> int32(1)
  54345 		v1 = top_dst + uintptr((int32(2)*x-int32(1))*int32(4))
  54346 		**(**uint8_t)(__ccgo_up(v1)) = uint8(0xff)
  54347 		v2 = int32(**(**uint8_t)(__ccgo_up(top_y + uintptr(int32(2)*x-int32(1)))))
  54348 		v3 = int32(uint8(uv02 & uint32(0xff)))
  54349 		v4 = int32(uint8(uv02 >> libc.Int32FromInt32(16)))
  54350 		v5 = v1 + uintptr(1)
  54351 		v8 = v2 * int32(19077) >> int32(8)
  54352 		goto _90
  54353 	_90:
  54354 		v10 = v4 * int32(26149) >> int32(8)
  54355 		goto _92
  54356 	_92:
  54357 		v12 = v8 + v10 - int32(14234)
  54358 		if v12 & ^int32(YUV_MASK2) == 0 {
  54359 			v15 = v12 >> int32(YUV_FIX2)
  54360 		} else {
  54361 			if v12 < 0 {
  54362 				v16 = 0
  54363 			} else {
  54364 				v16 = int32(255)
  54365 			}
  54366 			v15 = v16
  54367 		}
  54368 		v13 = v15
  54369 		goto _95
  54370 	_95:
  54371 		v6 = v13
  54372 		goto _88
  54373 	_88:
  54374 		**(**uint8_t)(__ccgo_up(v5)) = uint8(v6)
  54375 		v19 = v2 * int32(19077) >> int32(8)
  54376 		goto _101
  54377 	_101:
  54378 		v21 = v3 * int32(6419) >> int32(8)
  54379 		goto _103
  54380 	_103:
  54381 		v23 = v4 * int32(13320) >> int32(8)
  54382 		goto _105
  54383 	_105:
  54384 		v25 = v19 - v21 - v23 + int32(8708)
  54385 		if v25 & ^int32(YUV_MASK2) == 0 {
  54386 			v28 = v25 >> int32(YUV_FIX2)
  54387 		} else {
  54388 			if v25 < 0 {
  54389 				v29 = 0
  54390 			} else {
  54391 				v29 = int32(255)
  54392 			}
  54393 			v28 = v29
  54394 		}
  54395 		v26 = v28
  54396 		goto _108
  54397 	_108:
  54398 		v17 = v26
  54399 		goto _99
  54400 	_99:
  54401 		**(**uint8_t)(__ccgo_up(v5 + 1)) = uint8(v17)
  54402 		v32 = v2 * int32(19077) >> int32(8)
  54403 		goto _114
  54404 	_114:
  54405 		v34 = v3 * int32(33050) >> int32(8)
  54406 		goto _116
  54407 	_116:
  54408 		v36 = v32 + v34 - int32(17685)
  54409 		if v36 & ^int32(YUV_MASK2) == 0 {
  54410 			v39 = v36 >> int32(YUV_FIX2)
  54411 		} else {
  54412 			if v36 < 0 {
  54413 				v40 = 0
  54414 			} else {
  54415 				v40 = int32(255)
  54416 			}
  54417 			v39 = v40
  54418 		}
  54419 		v37 = v39
  54420 		goto _119
  54421 	_119:
  54422 		v30 = v37
  54423 		goto _112
  54424 	_112:
  54425 		**(**uint8_t)(__ccgo_up(v5 + 2)) = uint8(v30)
  54426 		v1 = top_dst + uintptr((int32(2)*x-0)*int32(4))
  54427 		**(**uint8_t)(__ccgo_up(v1)) = uint8(0xff)
  54428 		v2 = int32(**(**uint8_t)(__ccgo_up(top_y + uintptr(int32(2)*x-0))))
  54429 		v3 = int32(uint8(uv1 & uint32(0xff)))
  54430 		v4 = int32(uint8(uv1 >> libc.Int32FromInt32(16)))
  54431 		v5 = v1 + uintptr(1)
  54432 		v8 = v2 * int32(19077) >> int32(8)
  54433 		goto _130
  54434 	_130:
  54435 		v10 = v4 * int32(26149) >> int32(8)
  54436 		goto _132
  54437 	_132:
  54438 		v12 = v8 + v10 - int32(14234)
  54439 		if v12 & ^int32(YUV_MASK2) == 0 {
  54440 			v15 = v12 >> int32(YUV_FIX2)
  54441 		} else {
  54442 			if v12 < 0 {
  54443 				v16 = 0
  54444 			} else {
  54445 				v16 = int32(255)
  54446 			}
  54447 			v15 = v16
  54448 		}
  54449 		v13 = v15
  54450 		goto _135
  54451 	_135:
  54452 		v6 = v13
  54453 		goto _128
  54454 	_128:
  54455 		**(**uint8_t)(__ccgo_up(v5)) = uint8(v6)
  54456 		v19 = v2 * int32(19077) >> int32(8)
  54457 		goto _141
  54458 	_141:
  54459 		v21 = v3 * int32(6419) >> int32(8)
  54460 		goto _143
  54461 	_143:
  54462 		v23 = v4 * int32(13320) >> int32(8)
  54463 		goto _145
  54464 	_145:
  54465 		v25 = v19 - v21 - v23 + int32(8708)
  54466 		if v25 & ^int32(YUV_MASK2) == 0 {
  54467 			v28 = v25 >> int32(YUV_FIX2)
  54468 		} else {
  54469 			if v25 < 0 {
  54470 				v29 = 0
  54471 			} else {
  54472 				v29 = int32(255)
  54473 			}
  54474 			v28 = v29
  54475 		}
  54476 		v26 = v28
  54477 		goto _148
  54478 	_148:
  54479 		v17 = v26
  54480 		goto _139
  54481 	_139:
  54482 		**(**uint8_t)(__ccgo_up(v5 + 1)) = uint8(v17)
  54483 		v32 = v2 * int32(19077) >> int32(8)
  54484 		goto _154
  54485 	_154:
  54486 		v34 = v3 * int32(33050) >> int32(8)
  54487 		goto _156
  54488 	_156:
  54489 		v36 = v32 + v34 - int32(17685)
  54490 		if v36 & ^int32(YUV_MASK2) == 0 {
  54491 			v39 = v36 >> int32(YUV_FIX2)
  54492 		} else {
  54493 			if v36 < 0 {
  54494 				v40 = 0
  54495 			} else {
  54496 				v40 = int32(255)
  54497 			}
  54498 			v39 = v40
  54499 		}
  54500 		v37 = v39
  54501 		goto _159
  54502 	_159:
  54503 		v30 = v37
  54504 		goto _152
  54505 	_152:
  54506 		**(**uint8_t)(__ccgo_up(v5 + 2)) = uint8(v30)
  54507 		if bottom_y != libc.UintptrFromInt32(0) {
  54508 			uv03 = (diag_03 + l_uv) >> int32(1)
  54509 			uv11 = (diag_12 + uv) >> int32(1)
  54510 			v1 = bottom_dst + uintptr((int32(2)*x-int32(1))*int32(4))
  54511 			**(**uint8_t)(__ccgo_up(v1)) = uint8(0xff)
  54512 			v2 = int32(**(**uint8_t)(__ccgo_up(bottom_y + uintptr(int32(2)*x-int32(1)))))
  54513 			v3 = int32(uint8(uv03 & uint32(0xff)))
  54514 			v4 = int32(uint8(uv03 >> libc.Int32FromInt32(16)))
  54515 			v5 = v1 + uintptr(1)
  54516 			v8 = v2 * int32(19077) >> int32(8)
  54517 			goto _170
  54518 		_170:
  54519 			v10 = v4 * int32(26149) >> int32(8)
  54520 			goto _172
  54521 		_172:
  54522 			v12 = v8 + v10 - int32(14234)
  54523 			if v12 & ^int32(YUV_MASK2) == 0 {
  54524 				v15 = v12 >> int32(YUV_FIX2)
  54525 			} else {
  54526 				if v12 < 0 {
  54527 					v16 = 0
  54528 				} else {
  54529 					v16 = int32(255)
  54530 				}
  54531 				v15 = v16
  54532 			}
  54533 			v13 = v15
  54534 			goto _175
  54535 		_175:
  54536 			v6 = v13
  54537 			goto _168
  54538 		_168:
  54539 			**(**uint8_t)(__ccgo_up(v5)) = uint8(v6)
  54540 			v19 = v2 * int32(19077) >> int32(8)
  54541 			goto _181
  54542 		_181:
  54543 			v21 = v3 * int32(6419) >> int32(8)
  54544 			goto _183
  54545 		_183:
  54546 			v23 = v4 * int32(13320) >> int32(8)
  54547 			goto _185
  54548 		_185:
  54549 			v25 = v19 - v21 - v23 + int32(8708)
  54550 			if v25 & ^int32(YUV_MASK2) == 0 {
  54551 				v28 = v25 >> int32(YUV_FIX2)
  54552 			} else {
  54553 				if v25 < 0 {
  54554 					v29 = 0
  54555 				} else {
  54556 					v29 = int32(255)
  54557 				}
  54558 				v28 = v29
  54559 			}
  54560 			v26 = v28
  54561 			goto _188
  54562 		_188:
  54563 			v17 = v26
  54564 			goto _179
  54565 		_179:
  54566 			**(**uint8_t)(__ccgo_up(v5 + 1)) = uint8(v17)
  54567 			v32 = v2 * int32(19077) >> int32(8)
  54568 			goto _194
  54569 		_194:
  54570 			v34 = v3 * int32(33050) >> int32(8)
  54571 			goto _196
  54572 		_196:
  54573 			v36 = v32 + v34 - int32(17685)
  54574 			if v36 & ^int32(YUV_MASK2) == 0 {
  54575 				v39 = v36 >> int32(YUV_FIX2)
  54576 			} else {
  54577 				if v36 < 0 {
  54578 					v40 = 0
  54579 				} else {
  54580 					v40 = int32(255)
  54581 				}
  54582 				v39 = v40
  54583 			}
  54584 			v37 = v39
  54585 			goto _199
  54586 		_199:
  54587 			v30 = v37
  54588 			goto _192
  54589 		_192:
  54590 			**(**uint8_t)(__ccgo_up(v5 + 2)) = uint8(v30)
  54591 			v1 = bottom_dst + uintptr((int32(2)*x+0)*int32(4))
  54592 			**(**uint8_t)(__ccgo_up(v1)) = uint8(0xff)
  54593 			v2 = int32(**(**uint8_t)(__ccgo_up(bottom_y + uintptr(int32(2)*x+0))))
  54594 			v3 = int32(uint8(uv11 & uint32(0xff)))
  54595 			v4 = int32(uint8(uv11 >> libc.Int32FromInt32(16)))
  54596 			v5 = v1 + uintptr(1)
  54597 			v8 = v2 * int32(19077) >> int32(8)
  54598 			goto _210
  54599 		_210:
  54600 			v10 = v4 * int32(26149) >> int32(8)
  54601 			goto _212
  54602 		_212:
  54603 			v12 = v8 + v10 - int32(14234)
  54604 			if v12 & ^int32(YUV_MASK2) == 0 {
  54605 				v15 = v12 >> int32(YUV_FIX2)
  54606 			} else {
  54607 				if v12 < 0 {
  54608 					v16 = 0
  54609 				} else {
  54610 					v16 = int32(255)
  54611 				}
  54612 				v15 = v16
  54613 			}
  54614 			v13 = v15
  54615 			goto _215
  54616 		_215:
  54617 			v6 = v13
  54618 			goto _208
  54619 		_208:
  54620 			**(**uint8_t)(__ccgo_up(v5)) = uint8(v6)
  54621 			v19 = v2 * int32(19077) >> int32(8)
  54622 			goto _221
  54623 		_221:
  54624 			v21 = v3 * int32(6419) >> int32(8)
  54625 			goto _223
  54626 		_223:
  54627 			v23 = v4 * int32(13320) >> int32(8)
  54628 			goto _225
  54629 		_225:
  54630 			v25 = v19 - v21 - v23 + int32(8708)
  54631 			if v25 & ^int32(YUV_MASK2) == 0 {
  54632 				v28 = v25 >> int32(YUV_FIX2)
  54633 			} else {
  54634 				if v25 < 0 {
  54635 					v29 = 0
  54636 				} else {
  54637 					v29 = int32(255)
  54638 				}
  54639 				v28 = v29
  54640 			}
  54641 			v26 = v28
  54642 			goto _228
  54643 		_228:
  54644 			v17 = v26
  54645 			goto _219
  54646 		_219:
  54647 			**(**uint8_t)(__ccgo_up(v5 + 1)) = uint8(v17)
  54648 			v32 = v2 * int32(19077) >> int32(8)
  54649 			goto _234
  54650 		_234:
  54651 			v34 = v3 * int32(33050) >> int32(8)
  54652 			goto _236
  54653 		_236:
  54654 			v36 = v32 + v34 - int32(17685)
  54655 			if v36 & ^int32(YUV_MASK2) == 0 {
  54656 				v39 = v36 >> int32(YUV_FIX2)
  54657 			} else {
  54658 				if v36 < 0 {
  54659 					v40 = 0
  54660 				} else {
  54661 					v40 = int32(255)
  54662 				}
  54663 				v39 = v40
  54664 			}
  54665 			v37 = v39
  54666 			goto _239
  54667 		_239:
  54668 			v30 = v37
  54669 			goto _232
  54670 		_232:
  54671 			**(**uint8_t)(__ccgo_up(v5 + 2)) = uint8(v30)
  54672 		}
  54673 		tl_uv = t_uv
  54674 		l_uv = uv
  54675 		goto _81
  54676 	_81:
  54677 		;
  54678 		x = x + 1
  54679 	}
  54680 	if !(len1&libc.Int32FromInt32(1) != 0) {
  54681 		uv04 = (uint32(3)*tl_uv + l_uv + uint32(0x00020002)) >> int32(2)
  54682 		v1 = top_dst + uintptr((len1-int32(1))*int32(4))
  54683 		**(**uint8_t)(__ccgo_up(v1)) = uint8(0xff)
  54684 		v2 = int32(**(**uint8_t)(__ccgo_up(top_y + uintptr(len1-int32(1)))))
  54685 		v3 = int32(uint8(uv04 & uint32(0xff)))
  54686 		v4 = int32(uint8(uv04 >> libc.Int32FromInt32(16)))
  54687 		v5 = v1 + uintptr(1)
  54688 		v8 = v2 * int32(19077) >> int32(8)
  54689 		goto _250
  54690 	_250:
  54691 		v10 = v4 * int32(26149) >> int32(8)
  54692 		goto _252
  54693 	_252:
  54694 		v12 = v8 + v10 - int32(14234)
  54695 		if v12 & ^int32(YUV_MASK2) == 0 {
  54696 			v15 = v12 >> int32(YUV_FIX2)
  54697 		} else {
  54698 			if v12 < 0 {
  54699 				v16 = 0
  54700 			} else {
  54701 				v16 = int32(255)
  54702 			}
  54703 			v15 = v16
  54704 		}
  54705 		v13 = v15
  54706 		goto _255
  54707 	_255:
  54708 		v6 = v13
  54709 		goto _248
  54710 	_248:
  54711 		**(**uint8_t)(__ccgo_up(v5)) = uint8(v6)
  54712 		v19 = v2 * int32(19077) >> int32(8)
  54713 		goto _261
  54714 	_261:
  54715 		v21 = v3 * int32(6419) >> int32(8)
  54716 		goto _263
  54717 	_263:
  54718 		v23 = v4 * int32(13320) >> int32(8)
  54719 		goto _265
  54720 	_265:
  54721 		v25 = v19 - v21 - v23 + int32(8708)
  54722 		if v25 & ^int32(YUV_MASK2) == 0 {
  54723 			v28 = v25 >> int32(YUV_FIX2)
  54724 		} else {
  54725 			if v25 < 0 {
  54726 				v29 = 0
  54727 			} else {
  54728 				v29 = int32(255)
  54729 			}
  54730 			v28 = v29
  54731 		}
  54732 		v26 = v28
  54733 		goto _268
  54734 	_268:
  54735 		v17 = v26
  54736 		goto _259
  54737 	_259:
  54738 		**(**uint8_t)(__ccgo_up(v5 + 1)) = uint8(v17)
  54739 		v32 = v2 * int32(19077) >> int32(8)
  54740 		goto _274
  54741 	_274:
  54742 		v34 = v3 * int32(33050) >> int32(8)
  54743 		goto _276
  54744 	_276:
  54745 		v36 = v32 + v34 - int32(17685)
  54746 		if v36 & ^int32(YUV_MASK2) == 0 {
  54747 			v39 = v36 >> int32(YUV_FIX2)
  54748 		} else {
  54749 			if v36 < 0 {
  54750 				v40 = 0
  54751 			} else {
  54752 				v40 = int32(255)
  54753 			}
  54754 			v39 = v40
  54755 		}
  54756 		v37 = v39
  54757 		goto _279
  54758 	_279:
  54759 		v30 = v37
  54760 		goto _272
  54761 	_272:
  54762 		**(**uint8_t)(__ccgo_up(v5 + 2)) = uint8(v30)
  54763 		if bottom_y != libc.UintptrFromInt32(0) {
  54764 			uv05 = (uint32(3)*l_uv + tl_uv + uint32(0x00020002)) >> int32(2)
  54765 			v1 = bottom_dst + uintptr((len1-int32(1))*int32(4))
  54766 			**(**uint8_t)(__ccgo_up(v1)) = uint8(0xff)
  54767 			v2 = int32(**(**uint8_t)(__ccgo_up(bottom_y + uintptr(len1-int32(1)))))
  54768 			v3 = int32(uint8(uv05 & uint32(0xff)))
  54769 			v4 = int32(uint8(uv05 >> libc.Int32FromInt32(16)))
  54770 			v5 = v1 + uintptr(1)
  54771 			v8 = v2 * int32(19077) >> int32(8)
  54772 			goto _290
  54773 		_290:
  54774 			v10 = v4 * int32(26149) >> int32(8)
  54775 			goto _292
  54776 		_292:
  54777 			v12 = v8 + v10 - int32(14234)
  54778 			if v12 & ^int32(YUV_MASK2) == 0 {
  54779 				v15 = v12 >> int32(YUV_FIX2)
  54780 			} else {
  54781 				if v12 < 0 {
  54782 					v16 = 0
  54783 				} else {
  54784 					v16 = int32(255)
  54785 				}
  54786 				v15 = v16
  54787 			}
  54788 			v13 = v15
  54789 			goto _295
  54790 		_295:
  54791 			v6 = v13
  54792 			goto _288
  54793 		_288:
  54794 			**(**uint8_t)(__ccgo_up(v5)) = uint8(v6)
  54795 			v19 = v2 * int32(19077) >> int32(8)
  54796 			goto _301
  54797 		_301:
  54798 			v21 = v3 * int32(6419) >> int32(8)
  54799 			goto _303
  54800 		_303:
  54801 			v23 = v4 * int32(13320) >> int32(8)
  54802 			goto _305
  54803 		_305:
  54804 			v25 = v19 - v21 - v23 + int32(8708)
  54805 			if v25 & ^int32(YUV_MASK2) == 0 {
  54806 				v28 = v25 >> int32(YUV_FIX2)
  54807 			} else {
  54808 				if v25 < 0 {
  54809 					v29 = 0
  54810 				} else {
  54811 					v29 = int32(255)
  54812 				}
  54813 				v28 = v29
  54814 			}
  54815 			v26 = v28
  54816 			goto _308
  54817 		_308:
  54818 			v17 = v26
  54819 			goto _299
  54820 		_299:
  54821 			**(**uint8_t)(__ccgo_up(v5 + 1)) = uint8(v17)
  54822 			v32 = v2 * int32(19077) >> int32(8)
  54823 			goto _314
  54824 		_314:
  54825 			v34 = v3 * int32(33050) >> int32(8)
  54826 			goto _316
  54827 		_316:
  54828 			v36 = v32 + v34 - int32(17685)
  54829 			if v36 & ^int32(YUV_MASK2) == 0 {
  54830 				v39 = v36 >> int32(YUV_FIX2)
  54831 			} else {
  54832 				if v36 < 0 {
  54833 					v40 = 0
  54834 				} else {
  54835 					v40 = int32(255)
  54836 				}
  54837 				v39 = v40
  54838 			}
  54839 			v37 = v39
  54840 			goto _319
  54841 		_319:
  54842 			v30 = v37
  54843 			goto _312
  54844 		_312:
  54845 			**(**uint8_t)(__ccgo_up(v5 + 2)) = uint8(v30)
  54846 		}
  54847 	}
  54848 }
  54849 
  54850 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) {
  54851 	var avg, diag_03, diag_12, l_uv, t_uv, tl_uv, uv, uv0, uv01, uv02, uv03, uv04, uv05, uv1, uv11 uint32_t
  54852 	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
  54853 	var v4 uintptr
  54854 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  54855 	last_pixel_pair = (len1 - int32(1)) >> int32(1)
  54856 	tl_uv = uint32(int32(**(**uint8_t)(__ccgo_up(top_u))) | int32(**(**uint8_t)(__ccgo_up(top_v)))<<libc.Int32FromInt32(16)) /* top-left sample */
  54857 	l_uv = uint32(int32(**(**uint8_t)(__ccgo_up(cur_u))) | int32(**(**uint8_t)(__ccgo_up(cur_v)))<<libc.Int32FromInt32(16))
  54858 	uv0 = (uint32(3)*tl_uv + l_uv + uint32(0x00020002)) >> int32(2)
  54859 	v1 = int32(**(**uint8_t)(__ccgo_up(top_y)))
  54860 	v2 = int32(uv0 & uint32(0xff))
  54861 	v3 = int32(uv0 >> libc.Int32FromInt32(16))
  54862 	v4 = top_dst
  54863 	v7 = v1 * int32(19077) >> int32(8)
  54864 	goto _8
  54865 _8:
  54866 	v9 = v3 * int32(26149) >> int32(8)
  54867 	goto _10
  54868 _10:
  54869 	v11 = v7 + v9 - int32(14234)
  54870 	if v11 & ^int32(YUV_MASK2) == 0 {
  54871 		v14 = v11 >> int32(YUV_FIX2)
  54872 	} else {
  54873 		if v11 < 0 {
  54874 			v15 = 0
  54875 		} else {
  54876 			v15 = int32(255)
  54877 		}
  54878 		v14 = v15
  54879 	}
  54880 	v12 = v14
  54881 	goto _13
  54882 _13:
  54883 	v5 = v12
  54884 	goto _6
  54885 _6:
  54886 	**(**uint8_t)(__ccgo_up(v4)) = uint8(v5)
  54887 	v18 = v1 * int32(19077) >> int32(8)
  54888 	goto _19
  54889 _19:
  54890 	v20 = v2 * int32(6419) >> int32(8)
  54891 	goto _21
  54892 _21:
  54893 	v22 = v3 * int32(13320) >> int32(8)
  54894 	goto _23
  54895 _23:
  54896 	v24 = v18 - v20 - v22 + int32(8708)
  54897 	if v24 & ^int32(YUV_MASK2) == 0 {
  54898 		v27 = v24 >> int32(YUV_FIX2)
  54899 	} else {
  54900 		if v24 < 0 {
  54901 			v28 = 0
  54902 		} else {
  54903 			v28 = int32(255)
  54904 		}
  54905 		v27 = v28
  54906 	}
  54907 	v25 = v27
  54908 	goto _26
  54909 _26:
  54910 	v16 = v25
  54911 	goto _17
  54912 _17:
  54913 	**(**uint8_t)(__ccgo_up(v4 + 1)) = uint8(v16)
  54914 	v31 = v1 * int32(19077) >> int32(8)
  54915 	goto _32
  54916 _32:
  54917 	v33 = v2 * int32(33050) >> int32(8)
  54918 	goto _34
  54919 _34:
  54920 	v35 = v31 + v33 - int32(17685)
  54921 	if v35 & ^int32(YUV_MASK2) == 0 {
  54922 		v38 = v35 >> int32(YUV_FIX2)
  54923 	} else {
  54924 		if v35 < 0 {
  54925 			v39 = 0
  54926 		} else {
  54927 			v39 = int32(255)
  54928 		}
  54929 		v38 = v39
  54930 	}
  54931 	v36 = v38
  54932 	goto _37
  54933 _37:
  54934 	v29 = v36
  54935 	goto _30
  54936 _30:
  54937 	**(**uint8_t)(__ccgo_up(v4 + 2)) = uint8(v29)
  54938 	if bottom_y != libc.UintptrFromInt32(0) {
  54939 		uv01 = (uint32(3)*l_uv + tl_uv + uint32(0x00020002)) >> int32(2)
  54940 		v1 = int32(**(**uint8_t)(__ccgo_up(bottom_y)))
  54941 		v2 = int32(uv01 & uint32(0xff))
  54942 		v3 = int32(uv01 >> libc.Int32FromInt32(16))
  54943 		v4 = bottom_dst
  54944 		v7 = v1 * int32(19077) >> int32(8)
  54945 		goto _47
  54946 	_47:
  54947 		v9 = v3 * int32(26149) >> int32(8)
  54948 		goto _49
  54949 	_49:
  54950 		v11 = v7 + v9 - int32(14234)
  54951 		if v11 & ^int32(YUV_MASK2) == 0 {
  54952 			v14 = v11 >> int32(YUV_FIX2)
  54953 		} else {
  54954 			if v11 < 0 {
  54955 				v15 = 0
  54956 			} else {
  54957 				v15 = int32(255)
  54958 			}
  54959 			v14 = v15
  54960 		}
  54961 		v12 = v14
  54962 		goto _52
  54963 	_52:
  54964 		v5 = v12
  54965 		goto _45
  54966 	_45:
  54967 		**(**uint8_t)(__ccgo_up(v4)) = uint8(v5)
  54968 		v18 = v1 * int32(19077) >> int32(8)
  54969 		goto _58
  54970 	_58:
  54971 		v20 = v2 * int32(6419) >> int32(8)
  54972 		goto _60
  54973 	_60:
  54974 		v22 = v3 * int32(13320) >> int32(8)
  54975 		goto _62
  54976 	_62:
  54977 		v24 = v18 - v20 - v22 + int32(8708)
  54978 		if v24 & ^int32(YUV_MASK2) == 0 {
  54979 			v27 = v24 >> int32(YUV_FIX2)
  54980 		} else {
  54981 			if v24 < 0 {
  54982 				v28 = 0
  54983 			} else {
  54984 				v28 = int32(255)
  54985 			}
  54986 			v27 = v28
  54987 		}
  54988 		v25 = v27
  54989 		goto _65
  54990 	_65:
  54991 		v16 = v25
  54992 		goto _56
  54993 	_56:
  54994 		**(**uint8_t)(__ccgo_up(v4 + 1)) = uint8(v16)
  54995 		v31 = v1 * int32(19077) >> int32(8)
  54996 		goto _71
  54997 	_71:
  54998 		v33 = v2 * int32(33050) >> int32(8)
  54999 		goto _73
  55000 	_73:
  55001 		v35 = v31 + v33 - int32(17685)
  55002 		if v35 & ^int32(YUV_MASK2) == 0 {
  55003 			v38 = v35 >> int32(YUV_FIX2)
  55004 		} else {
  55005 			if v35 < 0 {
  55006 				v39 = 0
  55007 			} else {
  55008 				v39 = int32(255)
  55009 			}
  55010 			v38 = v39
  55011 		}
  55012 		v36 = v38
  55013 		goto _76
  55014 	_76:
  55015 		v29 = v36
  55016 		goto _69
  55017 	_69:
  55018 		**(**uint8_t)(__ccgo_up(v4 + 2)) = uint8(v29)
  55019 	}
  55020 	x = int32(1)
  55021 	for {
  55022 		if !(x <= last_pixel_pair) {
  55023 			break
  55024 		}
  55025 		t_uv = uint32(int32(**(**uint8_t)(__ccgo_up(top_u + uintptr(x)))) | int32(**(**uint8_t)(__ccgo_up(top_v + uintptr(x))))<<libc.Int32FromInt32(16)) /* top sample */
  55026 		uv = uint32(int32(**(**uint8_t)(__ccgo_up(cur_u + uintptr(x)))) | int32(**(**uint8_t)(__ccgo_up(cur_v + uintptr(x))))<<libc.Int32FromInt32(16))   /* sample */ /* precompute invariant values associated with first and second diagonals*/
  55027 		avg = tl_uv + t_uv + l_uv + uv + uint32(0x00080008)
  55028 		diag_12 = (avg + uint32(2)*(t_uv+l_uv)) >> int32(3)
  55029 		diag_03 = (avg + uint32(2)*(tl_uv+uv)) >> int32(3)
  55030 		uv02 = (diag_12 + tl_uv) >> int32(1)
  55031 		uv1 = (diag_03 + t_uv) >> int32(1)
  55032 		v1 = int32(**(**uint8_t)(__ccgo_up(top_y + uintptr(int32(2)*x-int32(1)))))
  55033 		v2 = int32(uv02 & uint32(0xff))
  55034 		v3 = int32(uv02 >> libc.Int32FromInt32(16))
  55035 		v4 = top_dst + uintptr((int32(2)*x-int32(1))*int32(3))
  55036 		v7 = v1 * int32(19077) >> int32(8)
  55037 		goto _87
  55038 	_87:
  55039 		v9 = v3 * int32(26149) >> int32(8)
  55040 		goto _89
  55041 	_89:
  55042 		v11 = v7 + v9 - int32(14234)
  55043 		if v11 & ^int32(YUV_MASK2) == 0 {
  55044 			v14 = v11 >> int32(YUV_FIX2)
  55045 		} else {
  55046 			if v11 < 0 {
  55047 				v15 = 0
  55048 			} else {
  55049 				v15 = int32(255)
  55050 			}
  55051 			v14 = v15
  55052 		}
  55053 		v12 = v14
  55054 		goto _92
  55055 	_92:
  55056 		v5 = v12
  55057 		goto _85
  55058 	_85:
  55059 		**(**uint8_t)(__ccgo_up(v4)) = uint8(v5)
  55060 		v18 = v1 * int32(19077) >> int32(8)
  55061 		goto _98
  55062 	_98:
  55063 		v20 = v2 * int32(6419) >> int32(8)
  55064 		goto _100
  55065 	_100:
  55066 		v22 = v3 * int32(13320) >> int32(8)
  55067 		goto _102
  55068 	_102:
  55069 		v24 = v18 - v20 - v22 + int32(8708)
  55070 		if v24 & ^int32(YUV_MASK2) == 0 {
  55071 			v27 = v24 >> int32(YUV_FIX2)
  55072 		} else {
  55073 			if v24 < 0 {
  55074 				v28 = 0
  55075 			} else {
  55076 				v28 = int32(255)
  55077 			}
  55078 			v27 = v28
  55079 		}
  55080 		v25 = v27
  55081 		goto _105
  55082 	_105:
  55083 		v16 = v25
  55084 		goto _96
  55085 	_96:
  55086 		**(**uint8_t)(__ccgo_up(v4 + 1)) = uint8(v16)
  55087 		v31 = v1 * int32(19077) >> int32(8)
  55088 		goto _111
  55089 	_111:
  55090 		v33 = v2 * int32(33050) >> int32(8)
  55091 		goto _113
  55092 	_113:
  55093 		v35 = v31 + v33 - int32(17685)
  55094 		if v35 & ^int32(YUV_MASK2) == 0 {
  55095 			v38 = v35 >> int32(YUV_FIX2)
  55096 		} else {
  55097 			if v35 < 0 {
  55098 				v39 = 0
  55099 			} else {
  55100 				v39 = int32(255)
  55101 			}
  55102 			v38 = v39
  55103 		}
  55104 		v36 = v38
  55105 		goto _116
  55106 	_116:
  55107 		v29 = v36
  55108 		goto _109
  55109 	_109:
  55110 		**(**uint8_t)(__ccgo_up(v4 + 2)) = uint8(v29)
  55111 		v1 = int32(**(**uint8_t)(__ccgo_up(top_y + uintptr(int32(2)*x-0))))
  55112 		v2 = int32(uv1 & uint32(0xff))
  55113 		v3 = int32(uv1 >> libc.Int32FromInt32(16))
  55114 		v4 = top_dst + uintptr((int32(2)*x-0)*int32(3))
  55115 		v7 = v1 * int32(19077) >> int32(8)
  55116 		goto _126
  55117 	_126:
  55118 		v9 = v3 * int32(26149) >> int32(8)
  55119 		goto _128
  55120 	_128:
  55121 		v11 = v7 + v9 - int32(14234)
  55122 		if v11 & ^int32(YUV_MASK2) == 0 {
  55123 			v14 = v11 >> int32(YUV_FIX2)
  55124 		} else {
  55125 			if v11 < 0 {
  55126 				v15 = 0
  55127 			} else {
  55128 				v15 = int32(255)
  55129 			}
  55130 			v14 = v15
  55131 		}
  55132 		v12 = v14
  55133 		goto _131
  55134 	_131:
  55135 		v5 = v12
  55136 		goto _124
  55137 	_124:
  55138 		**(**uint8_t)(__ccgo_up(v4)) = uint8(v5)
  55139 		v18 = v1 * int32(19077) >> int32(8)
  55140 		goto _137
  55141 	_137:
  55142 		v20 = v2 * int32(6419) >> int32(8)
  55143 		goto _139
  55144 	_139:
  55145 		v22 = v3 * int32(13320) >> int32(8)
  55146 		goto _141
  55147 	_141:
  55148 		v24 = v18 - v20 - v22 + int32(8708)
  55149 		if v24 & ^int32(YUV_MASK2) == 0 {
  55150 			v27 = v24 >> int32(YUV_FIX2)
  55151 		} else {
  55152 			if v24 < 0 {
  55153 				v28 = 0
  55154 			} else {
  55155 				v28 = int32(255)
  55156 			}
  55157 			v27 = v28
  55158 		}
  55159 		v25 = v27
  55160 		goto _144
  55161 	_144:
  55162 		v16 = v25
  55163 		goto _135
  55164 	_135:
  55165 		**(**uint8_t)(__ccgo_up(v4 + 1)) = uint8(v16)
  55166 		v31 = v1 * int32(19077) >> int32(8)
  55167 		goto _150
  55168 	_150:
  55169 		v33 = v2 * int32(33050) >> int32(8)
  55170 		goto _152
  55171 	_152:
  55172 		v35 = v31 + v33 - int32(17685)
  55173 		if v35 & ^int32(YUV_MASK2) == 0 {
  55174 			v38 = v35 >> int32(YUV_FIX2)
  55175 		} else {
  55176 			if v35 < 0 {
  55177 				v39 = 0
  55178 			} else {
  55179 				v39 = int32(255)
  55180 			}
  55181 			v38 = v39
  55182 		}
  55183 		v36 = v38
  55184 		goto _155
  55185 	_155:
  55186 		v29 = v36
  55187 		goto _148
  55188 	_148:
  55189 		**(**uint8_t)(__ccgo_up(v4 + 2)) = uint8(v29)
  55190 		if bottom_y != libc.UintptrFromInt32(0) {
  55191 			uv03 = (diag_03 + l_uv) >> int32(1)
  55192 			uv11 = (diag_12 + uv) >> int32(1)
  55193 			v1 = int32(**(**uint8_t)(__ccgo_up(bottom_y + uintptr(int32(2)*x-int32(1)))))
  55194 			v2 = int32(uv03 & uint32(0xff))
  55195 			v3 = int32(uv03 >> libc.Int32FromInt32(16))
  55196 			v4 = bottom_dst + uintptr((int32(2)*x-int32(1))*int32(3))
  55197 			v7 = v1 * int32(19077) >> int32(8)
  55198 			goto _165
  55199 		_165:
  55200 			v9 = v3 * int32(26149) >> int32(8)
  55201 			goto _167
  55202 		_167:
  55203 			v11 = v7 + v9 - int32(14234)
  55204 			if v11 & ^int32(YUV_MASK2) == 0 {
  55205 				v14 = v11 >> int32(YUV_FIX2)
  55206 			} else {
  55207 				if v11 < 0 {
  55208 					v15 = 0
  55209 				} else {
  55210 					v15 = int32(255)
  55211 				}
  55212 				v14 = v15
  55213 			}
  55214 			v12 = v14
  55215 			goto _170
  55216 		_170:
  55217 			v5 = v12
  55218 			goto _163
  55219 		_163:
  55220 			**(**uint8_t)(__ccgo_up(v4)) = uint8(v5)
  55221 			v18 = v1 * int32(19077) >> int32(8)
  55222 			goto _176
  55223 		_176:
  55224 			v20 = v2 * int32(6419) >> int32(8)
  55225 			goto _178
  55226 		_178:
  55227 			v22 = v3 * int32(13320) >> int32(8)
  55228 			goto _180
  55229 		_180:
  55230 			v24 = v18 - v20 - v22 + int32(8708)
  55231 			if v24 & ^int32(YUV_MASK2) == 0 {
  55232 				v27 = v24 >> int32(YUV_FIX2)
  55233 			} else {
  55234 				if v24 < 0 {
  55235 					v28 = 0
  55236 				} else {
  55237 					v28 = int32(255)
  55238 				}
  55239 				v27 = v28
  55240 			}
  55241 			v25 = v27
  55242 			goto _183
  55243 		_183:
  55244 			v16 = v25
  55245 			goto _174
  55246 		_174:
  55247 			**(**uint8_t)(__ccgo_up(v4 + 1)) = uint8(v16)
  55248 			v31 = v1 * int32(19077) >> int32(8)
  55249 			goto _189
  55250 		_189:
  55251 			v33 = v2 * int32(33050) >> int32(8)
  55252 			goto _191
  55253 		_191:
  55254 			v35 = v31 + v33 - int32(17685)
  55255 			if v35 & ^int32(YUV_MASK2) == 0 {
  55256 				v38 = v35 >> int32(YUV_FIX2)
  55257 			} else {
  55258 				if v35 < 0 {
  55259 					v39 = 0
  55260 				} else {
  55261 					v39 = int32(255)
  55262 				}
  55263 				v38 = v39
  55264 			}
  55265 			v36 = v38
  55266 			goto _194
  55267 		_194:
  55268 			v29 = v36
  55269 			goto _187
  55270 		_187:
  55271 			**(**uint8_t)(__ccgo_up(v4 + 2)) = uint8(v29)
  55272 			v1 = int32(**(**uint8_t)(__ccgo_up(bottom_y + uintptr(int32(2)*x+0))))
  55273 			v2 = int32(uv11 & uint32(0xff))
  55274 			v3 = int32(uv11 >> libc.Int32FromInt32(16))
  55275 			v4 = bottom_dst + uintptr((int32(2)*x+0)*int32(3))
  55276 			v7 = v1 * int32(19077) >> int32(8)
  55277 			goto _204
  55278 		_204:
  55279 			v9 = v3 * int32(26149) >> int32(8)
  55280 			goto _206
  55281 		_206:
  55282 			v11 = v7 + v9 - int32(14234)
  55283 			if v11 & ^int32(YUV_MASK2) == 0 {
  55284 				v14 = v11 >> int32(YUV_FIX2)
  55285 			} else {
  55286 				if v11 < 0 {
  55287 					v15 = 0
  55288 				} else {
  55289 					v15 = int32(255)
  55290 				}
  55291 				v14 = v15
  55292 			}
  55293 			v12 = v14
  55294 			goto _209
  55295 		_209:
  55296 			v5 = v12
  55297 			goto _202
  55298 		_202:
  55299 			**(**uint8_t)(__ccgo_up(v4)) = uint8(v5)
  55300 			v18 = v1 * int32(19077) >> int32(8)
  55301 			goto _215
  55302 		_215:
  55303 			v20 = v2 * int32(6419) >> int32(8)
  55304 			goto _217
  55305 		_217:
  55306 			v22 = v3 * int32(13320) >> int32(8)
  55307 			goto _219
  55308 		_219:
  55309 			v24 = v18 - v20 - v22 + int32(8708)
  55310 			if v24 & ^int32(YUV_MASK2) == 0 {
  55311 				v27 = v24 >> int32(YUV_FIX2)
  55312 			} else {
  55313 				if v24 < 0 {
  55314 					v28 = 0
  55315 				} else {
  55316 					v28 = int32(255)
  55317 				}
  55318 				v27 = v28
  55319 			}
  55320 			v25 = v27
  55321 			goto _222
  55322 		_222:
  55323 			v16 = v25
  55324 			goto _213
  55325 		_213:
  55326 			**(**uint8_t)(__ccgo_up(v4 + 1)) = uint8(v16)
  55327 			v31 = v1 * int32(19077) >> int32(8)
  55328 			goto _228
  55329 		_228:
  55330 			v33 = v2 * int32(33050) >> int32(8)
  55331 			goto _230
  55332 		_230:
  55333 			v35 = v31 + v33 - int32(17685)
  55334 			if v35 & ^int32(YUV_MASK2) == 0 {
  55335 				v38 = v35 >> int32(YUV_FIX2)
  55336 			} else {
  55337 				if v35 < 0 {
  55338 					v39 = 0
  55339 				} else {
  55340 					v39 = int32(255)
  55341 				}
  55342 				v38 = v39
  55343 			}
  55344 			v36 = v38
  55345 			goto _233
  55346 		_233:
  55347 			v29 = v36
  55348 			goto _226
  55349 		_226:
  55350 			**(**uint8_t)(__ccgo_up(v4 + 2)) = uint8(v29)
  55351 		}
  55352 		tl_uv = t_uv
  55353 		l_uv = uv
  55354 		goto _79
  55355 	_79:
  55356 		;
  55357 		x = x + 1
  55358 	}
  55359 	if !(len1&libc.Int32FromInt32(1) != 0) {
  55360 		uv04 = (uint32(3)*tl_uv + l_uv + uint32(0x00020002)) >> int32(2)
  55361 		v1 = int32(**(**uint8_t)(__ccgo_up(top_y + uintptr(len1-int32(1)))))
  55362 		v2 = int32(uv04 & uint32(0xff))
  55363 		v3 = int32(uv04 >> libc.Int32FromInt32(16))
  55364 		v4 = top_dst + uintptr((len1-int32(1))*int32(3))
  55365 		v7 = v1 * int32(19077) >> int32(8)
  55366 		goto _243
  55367 	_243:
  55368 		v9 = v3 * int32(26149) >> int32(8)
  55369 		goto _245
  55370 	_245:
  55371 		v11 = v7 + v9 - int32(14234)
  55372 		if v11 & ^int32(YUV_MASK2) == 0 {
  55373 			v14 = v11 >> int32(YUV_FIX2)
  55374 		} else {
  55375 			if v11 < 0 {
  55376 				v15 = 0
  55377 			} else {
  55378 				v15 = int32(255)
  55379 			}
  55380 			v14 = v15
  55381 		}
  55382 		v12 = v14
  55383 		goto _248
  55384 	_248:
  55385 		v5 = v12
  55386 		goto _241
  55387 	_241:
  55388 		**(**uint8_t)(__ccgo_up(v4)) = uint8(v5)
  55389 		v18 = v1 * int32(19077) >> int32(8)
  55390 		goto _254
  55391 	_254:
  55392 		v20 = v2 * int32(6419) >> int32(8)
  55393 		goto _256
  55394 	_256:
  55395 		v22 = v3 * int32(13320) >> int32(8)
  55396 		goto _258
  55397 	_258:
  55398 		v24 = v18 - v20 - v22 + int32(8708)
  55399 		if v24 & ^int32(YUV_MASK2) == 0 {
  55400 			v27 = v24 >> int32(YUV_FIX2)
  55401 		} else {
  55402 			if v24 < 0 {
  55403 				v28 = 0
  55404 			} else {
  55405 				v28 = int32(255)
  55406 			}
  55407 			v27 = v28
  55408 		}
  55409 		v25 = v27
  55410 		goto _261
  55411 	_261:
  55412 		v16 = v25
  55413 		goto _252
  55414 	_252:
  55415 		**(**uint8_t)(__ccgo_up(v4 + 1)) = uint8(v16)
  55416 		v31 = v1 * int32(19077) >> int32(8)
  55417 		goto _267
  55418 	_267:
  55419 		v33 = v2 * int32(33050) >> int32(8)
  55420 		goto _269
  55421 	_269:
  55422 		v35 = v31 + v33 - int32(17685)
  55423 		if v35 & ^int32(YUV_MASK2) == 0 {
  55424 			v38 = v35 >> int32(YUV_FIX2)
  55425 		} else {
  55426 			if v35 < 0 {
  55427 				v39 = 0
  55428 			} else {
  55429 				v39 = int32(255)
  55430 			}
  55431 			v38 = v39
  55432 		}
  55433 		v36 = v38
  55434 		goto _272
  55435 	_272:
  55436 		v29 = v36
  55437 		goto _265
  55438 	_265:
  55439 		**(**uint8_t)(__ccgo_up(v4 + 2)) = uint8(v29)
  55440 		if bottom_y != libc.UintptrFromInt32(0) {
  55441 			uv05 = (uint32(3)*l_uv + tl_uv + uint32(0x00020002)) >> int32(2)
  55442 			v1 = int32(**(**uint8_t)(__ccgo_up(bottom_y + uintptr(len1-int32(1)))))
  55443 			v2 = int32(uv05 & uint32(0xff))
  55444 			v3 = int32(uv05 >> libc.Int32FromInt32(16))
  55445 			v4 = bottom_dst + uintptr((len1-int32(1))*int32(3))
  55446 			v7 = v1 * int32(19077) >> int32(8)
  55447 			goto _282
  55448 		_282:
  55449 			v9 = v3 * int32(26149) >> int32(8)
  55450 			goto _284
  55451 		_284:
  55452 			v11 = v7 + v9 - int32(14234)
  55453 			if v11 & ^int32(YUV_MASK2) == 0 {
  55454 				v14 = v11 >> int32(YUV_FIX2)
  55455 			} else {
  55456 				if v11 < 0 {
  55457 					v15 = 0
  55458 				} else {
  55459 					v15 = int32(255)
  55460 				}
  55461 				v14 = v15
  55462 			}
  55463 			v12 = v14
  55464 			goto _287
  55465 		_287:
  55466 			v5 = v12
  55467 			goto _280
  55468 		_280:
  55469 			**(**uint8_t)(__ccgo_up(v4)) = uint8(v5)
  55470 			v18 = v1 * int32(19077) >> int32(8)
  55471 			goto _293
  55472 		_293:
  55473 			v20 = v2 * int32(6419) >> int32(8)
  55474 			goto _295
  55475 		_295:
  55476 			v22 = v3 * int32(13320) >> int32(8)
  55477 			goto _297
  55478 		_297:
  55479 			v24 = v18 - v20 - v22 + int32(8708)
  55480 			if v24 & ^int32(YUV_MASK2) == 0 {
  55481 				v27 = v24 >> int32(YUV_FIX2)
  55482 			} else {
  55483 				if v24 < 0 {
  55484 					v28 = 0
  55485 				} else {
  55486 					v28 = int32(255)
  55487 				}
  55488 				v27 = v28
  55489 			}
  55490 			v25 = v27
  55491 			goto _300
  55492 		_300:
  55493 			v16 = v25
  55494 			goto _291
  55495 		_291:
  55496 			**(**uint8_t)(__ccgo_up(v4 + 1)) = uint8(v16)
  55497 			v31 = v1 * int32(19077) >> int32(8)
  55498 			goto _306
  55499 		_306:
  55500 			v33 = v2 * int32(33050) >> int32(8)
  55501 			goto _308
  55502 		_308:
  55503 			v35 = v31 + v33 - int32(17685)
  55504 			if v35 & ^int32(YUV_MASK2) == 0 {
  55505 				v38 = v35 >> int32(YUV_FIX2)
  55506 			} else {
  55507 				if v35 < 0 {
  55508 					v39 = 0
  55509 				} else {
  55510 					v39 = int32(255)
  55511 				}
  55512 				v38 = v39
  55513 			}
  55514 			v36 = v38
  55515 			goto _311
  55516 		_311:
  55517 			v29 = v36
  55518 			goto _304
  55519 		_304:
  55520 			**(**uint8_t)(__ccgo_up(v4 + 2)) = uint8(v29)
  55521 		}
  55522 	}
  55523 }
  55524 
  55525 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) {
  55526 	var avg, diag_03, diag_12, l_uv, t_uv, tl_uv, uv, uv0, uv01, uv02, uv03, uv04, uv05, uv1, uv11 uint32_t
  55527 	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
  55528 	var v4 uintptr
  55529 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  55530 	last_pixel_pair = (len1 - int32(1)) >> int32(1)
  55531 	tl_uv = uint32(int32(**(**uint8_t)(__ccgo_up(top_u))) | int32(**(**uint8_t)(__ccgo_up(top_v)))<<libc.Int32FromInt32(16)) /* top-left sample */
  55532 	l_uv = uint32(int32(**(**uint8_t)(__ccgo_up(cur_u))) | int32(**(**uint8_t)(__ccgo_up(cur_v)))<<libc.Int32FromInt32(16))
  55533 	uv0 = (uint32(3)*tl_uv + l_uv + uint32(0x00020002)) >> int32(2)
  55534 	v1 = int32(**(**uint8_t)(__ccgo_up(top_y)))
  55535 	v2 = int32(uv0 & uint32(0xff))
  55536 	v3 = int32(uv0 >> libc.Int32FromInt32(16))
  55537 	v4 = top_dst
  55538 	v7 = v1 * int32(19077) >> int32(8)
  55539 	goto _8
  55540 _8:
  55541 	v9 = v2 * int32(33050) >> int32(8)
  55542 	goto _10
  55543 _10:
  55544 	v11 = v7 + v9 - int32(17685)
  55545 	if v11 & ^int32(YUV_MASK2) == 0 {
  55546 		v14 = v11 >> int32(YUV_FIX2)
  55547 	} else {
  55548 		if v11 < 0 {
  55549 			v15 = 0
  55550 		} else {
  55551 			v15 = int32(255)
  55552 		}
  55553 		v14 = v15
  55554 	}
  55555 	v12 = v14
  55556 	goto _13
  55557 _13:
  55558 	v5 = v12
  55559 	goto _6
  55560 _6:
  55561 	**(**uint8_t)(__ccgo_up(v4)) = uint8(v5)
  55562 	v18 = v1 * int32(19077) >> int32(8)
  55563 	goto _19
  55564 _19:
  55565 	v20 = v2 * int32(6419) >> int32(8)
  55566 	goto _21
  55567 _21:
  55568 	v22 = v3 * int32(13320) >> int32(8)
  55569 	goto _23
  55570 _23:
  55571 	v24 = v18 - v20 - v22 + int32(8708)
  55572 	if v24 & ^int32(YUV_MASK2) == 0 {
  55573 		v27 = v24 >> int32(YUV_FIX2)
  55574 	} else {
  55575 		if v24 < 0 {
  55576 			v28 = 0
  55577 		} else {
  55578 			v28 = int32(255)
  55579 		}
  55580 		v27 = v28
  55581 	}
  55582 	v25 = v27
  55583 	goto _26
  55584 _26:
  55585 	v16 = v25
  55586 	goto _17
  55587 _17:
  55588 	**(**uint8_t)(__ccgo_up(v4 + 1)) = uint8(v16)
  55589 	v31 = v1 * int32(19077) >> int32(8)
  55590 	goto _32
  55591 _32:
  55592 	v33 = v3 * int32(26149) >> int32(8)
  55593 	goto _34
  55594 _34:
  55595 	v35 = v31 + v33 - int32(14234)
  55596 	if v35 & ^int32(YUV_MASK2) == 0 {
  55597 		v38 = v35 >> int32(YUV_FIX2)
  55598 	} else {
  55599 		if v35 < 0 {
  55600 			v39 = 0
  55601 		} else {
  55602 			v39 = int32(255)
  55603 		}
  55604 		v38 = v39
  55605 	}
  55606 	v36 = v38
  55607 	goto _37
  55608 _37:
  55609 	v29 = v36
  55610 	goto _30
  55611 _30:
  55612 	**(**uint8_t)(__ccgo_up(v4 + 2)) = uint8(v29)
  55613 	if bottom_y != libc.UintptrFromInt32(0) {
  55614 		uv01 = (uint32(3)*l_uv + tl_uv + uint32(0x00020002)) >> int32(2)
  55615 		v1 = int32(**(**uint8_t)(__ccgo_up(bottom_y)))
  55616 		v2 = int32(uv01 & uint32(0xff))
  55617 		v3 = int32(uv01 >> libc.Int32FromInt32(16))
  55618 		v4 = bottom_dst
  55619 		v7 = v1 * int32(19077) >> int32(8)
  55620 		goto _47
  55621 	_47:
  55622 		v9 = v2 * int32(33050) >> int32(8)
  55623 		goto _49
  55624 	_49:
  55625 		v11 = v7 + v9 - int32(17685)
  55626 		if v11 & ^int32(YUV_MASK2) == 0 {
  55627 			v14 = v11 >> int32(YUV_FIX2)
  55628 		} else {
  55629 			if v11 < 0 {
  55630 				v15 = 0
  55631 			} else {
  55632 				v15 = int32(255)
  55633 			}
  55634 			v14 = v15
  55635 		}
  55636 		v12 = v14
  55637 		goto _52
  55638 	_52:
  55639 		v5 = v12
  55640 		goto _45
  55641 	_45:
  55642 		**(**uint8_t)(__ccgo_up(v4)) = uint8(v5)
  55643 		v18 = v1 * int32(19077) >> int32(8)
  55644 		goto _58
  55645 	_58:
  55646 		v20 = v2 * int32(6419) >> int32(8)
  55647 		goto _60
  55648 	_60:
  55649 		v22 = v3 * int32(13320) >> int32(8)
  55650 		goto _62
  55651 	_62:
  55652 		v24 = v18 - v20 - v22 + int32(8708)
  55653 		if v24 & ^int32(YUV_MASK2) == 0 {
  55654 			v27 = v24 >> int32(YUV_FIX2)
  55655 		} else {
  55656 			if v24 < 0 {
  55657 				v28 = 0
  55658 			} else {
  55659 				v28 = int32(255)
  55660 			}
  55661 			v27 = v28
  55662 		}
  55663 		v25 = v27
  55664 		goto _65
  55665 	_65:
  55666 		v16 = v25
  55667 		goto _56
  55668 	_56:
  55669 		**(**uint8_t)(__ccgo_up(v4 + 1)) = uint8(v16)
  55670 		v31 = v1 * int32(19077) >> int32(8)
  55671 		goto _71
  55672 	_71:
  55673 		v33 = v3 * int32(26149) >> int32(8)
  55674 		goto _73
  55675 	_73:
  55676 		v35 = v31 + v33 - int32(14234)
  55677 		if v35 & ^int32(YUV_MASK2) == 0 {
  55678 			v38 = v35 >> int32(YUV_FIX2)
  55679 		} else {
  55680 			if v35 < 0 {
  55681 				v39 = 0
  55682 			} else {
  55683 				v39 = int32(255)
  55684 			}
  55685 			v38 = v39
  55686 		}
  55687 		v36 = v38
  55688 		goto _76
  55689 	_76:
  55690 		v29 = v36
  55691 		goto _69
  55692 	_69:
  55693 		**(**uint8_t)(__ccgo_up(v4 + 2)) = uint8(v29)
  55694 	}
  55695 	x = int32(1)
  55696 	for {
  55697 		if !(x <= last_pixel_pair) {
  55698 			break
  55699 		}
  55700 		t_uv = uint32(int32(**(**uint8_t)(__ccgo_up(top_u + uintptr(x)))) | int32(**(**uint8_t)(__ccgo_up(top_v + uintptr(x))))<<libc.Int32FromInt32(16)) /* top sample */
  55701 		uv = uint32(int32(**(**uint8_t)(__ccgo_up(cur_u + uintptr(x)))) | int32(**(**uint8_t)(__ccgo_up(cur_v + uintptr(x))))<<libc.Int32FromInt32(16))   /* sample */ /* precompute invariant values associated with first and second diagonals*/
  55702 		avg = tl_uv + t_uv + l_uv + uv + uint32(0x00080008)
  55703 		diag_12 = (avg + uint32(2)*(t_uv+l_uv)) >> int32(3)
  55704 		diag_03 = (avg + uint32(2)*(tl_uv+uv)) >> int32(3)
  55705 		uv02 = (diag_12 + tl_uv) >> int32(1)
  55706 		uv1 = (diag_03 + t_uv) >> int32(1)
  55707 		v1 = int32(**(**uint8_t)(__ccgo_up(top_y + uintptr(int32(2)*x-int32(1)))))
  55708 		v2 = int32(uv02 & uint32(0xff))
  55709 		v3 = int32(uv02 >> libc.Int32FromInt32(16))
  55710 		v4 = top_dst + uintptr((int32(2)*x-int32(1))*int32(3))
  55711 		v7 = v1 * int32(19077) >> int32(8)
  55712 		goto _87
  55713 	_87:
  55714 		v9 = v2 * int32(33050) >> int32(8)
  55715 		goto _89
  55716 	_89:
  55717 		v11 = v7 + v9 - int32(17685)
  55718 		if v11 & ^int32(YUV_MASK2) == 0 {
  55719 			v14 = v11 >> int32(YUV_FIX2)
  55720 		} else {
  55721 			if v11 < 0 {
  55722 				v15 = 0
  55723 			} else {
  55724 				v15 = int32(255)
  55725 			}
  55726 			v14 = v15
  55727 		}
  55728 		v12 = v14
  55729 		goto _92
  55730 	_92:
  55731 		v5 = v12
  55732 		goto _85
  55733 	_85:
  55734 		**(**uint8_t)(__ccgo_up(v4)) = uint8(v5)
  55735 		v18 = v1 * int32(19077) >> int32(8)
  55736 		goto _98
  55737 	_98:
  55738 		v20 = v2 * int32(6419) >> int32(8)
  55739 		goto _100
  55740 	_100:
  55741 		v22 = v3 * int32(13320) >> int32(8)
  55742 		goto _102
  55743 	_102:
  55744 		v24 = v18 - v20 - v22 + int32(8708)
  55745 		if v24 & ^int32(YUV_MASK2) == 0 {
  55746 			v27 = v24 >> int32(YUV_FIX2)
  55747 		} else {
  55748 			if v24 < 0 {
  55749 				v28 = 0
  55750 			} else {
  55751 				v28 = int32(255)
  55752 			}
  55753 			v27 = v28
  55754 		}
  55755 		v25 = v27
  55756 		goto _105
  55757 	_105:
  55758 		v16 = v25
  55759 		goto _96
  55760 	_96:
  55761 		**(**uint8_t)(__ccgo_up(v4 + 1)) = uint8(v16)
  55762 		v31 = v1 * int32(19077) >> int32(8)
  55763 		goto _111
  55764 	_111:
  55765 		v33 = v3 * int32(26149) >> int32(8)
  55766 		goto _113
  55767 	_113:
  55768 		v35 = v31 + v33 - int32(14234)
  55769 		if v35 & ^int32(YUV_MASK2) == 0 {
  55770 			v38 = v35 >> int32(YUV_FIX2)
  55771 		} else {
  55772 			if v35 < 0 {
  55773 				v39 = 0
  55774 			} else {
  55775 				v39 = int32(255)
  55776 			}
  55777 			v38 = v39
  55778 		}
  55779 		v36 = v38
  55780 		goto _116
  55781 	_116:
  55782 		v29 = v36
  55783 		goto _109
  55784 	_109:
  55785 		**(**uint8_t)(__ccgo_up(v4 + 2)) = uint8(v29)
  55786 		v1 = int32(**(**uint8_t)(__ccgo_up(top_y + uintptr(int32(2)*x-0))))
  55787 		v2 = int32(uv1 & uint32(0xff))
  55788 		v3 = int32(uv1 >> libc.Int32FromInt32(16))
  55789 		v4 = top_dst + uintptr((int32(2)*x-0)*int32(3))
  55790 		v7 = v1 * int32(19077) >> int32(8)
  55791 		goto _126
  55792 	_126:
  55793 		v9 = v2 * int32(33050) >> int32(8)
  55794 		goto _128
  55795 	_128:
  55796 		v11 = v7 + v9 - int32(17685)
  55797 		if v11 & ^int32(YUV_MASK2) == 0 {
  55798 			v14 = v11 >> int32(YUV_FIX2)
  55799 		} else {
  55800 			if v11 < 0 {
  55801 				v15 = 0
  55802 			} else {
  55803 				v15 = int32(255)
  55804 			}
  55805 			v14 = v15
  55806 		}
  55807 		v12 = v14
  55808 		goto _131
  55809 	_131:
  55810 		v5 = v12
  55811 		goto _124
  55812 	_124:
  55813 		**(**uint8_t)(__ccgo_up(v4)) = uint8(v5)
  55814 		v18 = v1 * int32(19077) >> int32(8)
  55815 		goto _137
  55816 	_137:
  55817 		v20 = v2 * int32(6419) >> int32(8)
  55818 		goto _139
  55819 	_139:
  55820 		v22 = v3 * int32(13320) >> int32(8)
  55821 		goto _141
  55822 	_141:
  55823 		v24 = v18 - v20 - v22 + int32(8708)
  55824 		if v24 & ^int32(YUV_MASK2) == 0 {
  55825 			v27 = v24 >> int32(YUV_FIX2)
  55826 		} else {
  55827 			if v24 < 0 {
  55828 				v28 = 0
  55829 			} else {
  55830 				v28 = int32(255)
  55831 			}
  55832 			v27 = v28
  55833 		}
  55834 		v25 = v27
  55835 		goto _144
  55836 	_144:
  55837 		v16 = v25
  55838 		goto _135
  55839 	_135:
  55840 		**(**uint8_t)(__ccgo_up(v4 + 1)) = uint8(v16)
  55841 		v31 = v1 * int32(19077) >> int32(8)
  55842 		goto _150
  55843 	_150:
  55844 		v33 = v3 * int32(26149) >> int32(8)
  55845 		goto _152
  55846 	_152:
  55847 		v35 = v31 + v33 - int32(14234)
  55848 		if v35 & ^int32(YUV_MASK2) == 0 {
  55849 			v38 = v35 >> int32(YUV_FIX2)
  55850 		} else {
  55851 			if v35 < 0 {
  55852 				v39 = 0
  55853 			} else {
  55854 				v39 = int32(255)
  55855 			}
  55856 			v38 = v39
  55857 		}
  55858 		v36 = v38
  55859 		goto _155
  55860 	_155:
  55861 		v29 = v36
  55862 		goto _148
  55863 	_148:
  55864 		**(**uint8_t)(__ccgo_up(v4 + 2)) = uint8(v29)
  55865 		if bottom_y != libc.UintptrFromInt32(0) {
  55866 			uv03 = (diag_03 + l_uv) >> int32(1)
  55867 			uv11 = (diag_12 + uv) >> int32(1)
  55868 			v1 = int32(**(**uint8_t)(__ccgo_up(bottom_y + uintptr(int32(2)*x-int32(1)))))
  55869 			v2 = int32(uv03 & uint32(0xff))
  55870 			v3 = int32(uv03 >> libc.Int32FromInt32(16))
  55871 			v4 = bottom_dst + uintptr((int32(2)*x-int32(1))*int32(3))
  55872 			v7 = v1 * int32(19077) >> int32(8)
  55873 			goto _165
  55874 		_165:
  55875 			v9 = v2 * int32(33050) >> int32(8)
  55876 			goto _167
  55877 		_167:
  55878 			v11 = v7 + v9 - int32(17685)
  55879 			if v11 & ^int32(YUV_MASK2) == 0 {
  55880 				v14 = v11 >> int32(YUV_FIX2)
  55881 			} else {
  55882 				if v11 < 0 {
  55883 					v15 = 0
  55884 				} else {
  55885 					v15 = int32(255)
  55886 				}
  55887 				v14 = v15
  55888 			}
  55889 			v12 = v14
  55890 			goto _170
  55891 		_170:
  55892 			v5 = v12
  55893 			goto _163
  55894 		_163:
  55895 			**(**uint8_t)(__ccgo_up(v4)) = uint8(v5)
  55896 			v18 = v1 * int32(19077) >> int32(8)
  55897 			goto _176
  55898 		_176:
  55899 			v20 = v2 * int32(6419) >> int32(8)
  55900 			goto _178
  55901 		_178:
  55902 			v22 = v3 * int32(13320) >> int32(8)
  55903 			goto _180
  55904 		_180:
  55905 			v24 = v18 - v20 - v22 + int32(8708)
  55906 			if v24 & ^int32(YUV_MASK2) == 0 {
  55907 				v27 = v24 >> int32(YUV_FIX2)
  55908 			} else {
  55909 				if v24 < 0 {
  55910 					v28 = 0
  55911 				} else {
  55912 					v28 = int32(255)
  55913 				}
  55914 				v27 = v28
  55915 			}
  55916 			v25 = v27
  55917 			goto _183
  55918 		_183:
  55919 			v16 = v25
  55920 			goto _174
  55921 		_174:
  55922 			**(**uint8_t)(__ccgo_up(v4 + 1)) = uint8(v16)
  55923 			v31 = v1 * int32(19077) >> int32(8)
  55924 			goto _189
  55925 		_189:
  55926 			v33 = v3 * int32(26149) >> int32(8)
  55927 			goto _191
  55928 		_191:
  55929 			v35 = v31 + v33 - int32(14234)
  55930 			if v35 & ^int32(YUV_MASK2) == 0 {
  55931 				v38 = v35 >> int32(YUV_FIX2)
  55932 			} else {
  55933 				if v35 < 0 {
  55934 					v39 = 0
  55935 				} else {
  55936 					v39 = int32(255)
  55937 				}
  55938 				v38 = v39
  55939 			}
  55940 			v36 = v38
  55941 			goto _194
  55942 		_194:
  55943 			v29 = v36
  55944 			goto _187
  55945 		_187:
  55946 			**(**uint8_t)(__ccgo_up(v4 + 2)) = uint8(v29)
  55947 			v1 = int32(**(**uint8_t)(__ccgo_up(bottom_y + uintptr(int32(2)*x+0))))
  55948 			v2 = int32(uv11 & uint32(0xff))
  55949 			v3 = int32(uv11 >> libc.Int32FromInt32(16))
  55950 			v4 = bottom_dst + uintptr((int32(2)*x+0)*int32(3))
  55951 			v7 = v1 * int32(19077) >> int32(8)
  55952 			goto _204
  55953 		_204:
  55954 			v9 = v2 * int32(33050) >> int32(8)
  55955 			goto _206
  55956 		_206:
  55957 			v11 = v7 + v9 - int32(17685)
  55958 			if v11 & ^int32(YUV_MASK2) == 0 {
  55959 				v14 = v11 >> int32(YUV_FIX2)
  55960 			} else {
  55961 				if v11 < 0 {
  55962 					v15 = 0
  55963 				} else {
  55964 					v15 = int32(255)
  55965 				}
  55966 				v14 = v15
  55967 			}
  55968 			v12 = v14
  55969 			goto _209
  55970 		_209:
  55971 			v5 = v12
  55972 			goto _202
  55973 		_202:
  55974 			**(**uint8_t)(__ccgo_up(v4)) = uint8(v5)
  55975 			v18 = v1 * int32(19077) >> int32(8)
  55976 			goto _215
  55977 		_215:
  55978 			v20 = v2 * int32(6419) >> int32(8)
  55979 			goto _217
  55980 		_217:
  55981 			v22 = v3 * int32(13320) >> int32(8)
  55982 			goto _219
  55983 		_219:
  55984 			v24 = v18 - v20 - v22 + int32(8708)
  55985 			if v24 & ^int32(YUV_MASK2) == 0 {
  55986 				v27 = v24 >> int32(YUV_FIX2)
  55987 			} else {
  55988 				if v24 < 0 {
  55989 					v28 = 0
  55990 				} else {
  55991 					v28 = int32(255)
  55992 				}
  55993 				v27 = v28
  55994 			}
  55995 			v25 = v27
  55996 			goto _222
  55997 		_222:
  55998 			v16 = v25
  55999 			goto _213
  56000 		_213:
  56001 			**(**uint8_t)(__ccgo_up(v4 + 1)) = uint8(v16)
  56002 			v31 = v1 * int32(19077) >> int32(8)
  56003 			goto _228
  56004 		_228:
  56005 			v33 = v3 * int32(26149) >> int32(8)
  56006 			goto _230
  56007 		_230:
  56008 			v35 = v31 + v33 - int32(14234)
  56009 			if v35 & ^int32(YUV_MASK2) == 0 {
  56010 				v38 = v35 >> int32(YUV_FIX2)
  56011 			} else {
  56012 				if v35 < 0 {
  56013 					v39 = 0
  56014 				} else {
  56015 					v39 = int32(255)
  56016 				}
  56017 				v38 = v39
  56018 			}
  56019 			v36 = v38
  56020 			goto _233
  56021 		_233:
  56022 			v29 = v36
  56023 			goto _226
  56024 		_226:
  56025 			**(**uint8_t)(__ccgo_up(v4 + 2)) = uint8(v29)
  56026 		}
  56027 		tl_uv = t_uv
  56028 		l_uv = uv
  56029 		goto _79
  56030 	_79:
  56031 		;
  56032 		x = x + 1
  56033 	}
  56034 	if !(len1&libc.Int32FromInt32(1) != 0) {
  56035 		uv04 = (uint32(3)*tl_uv + l_uv + uint32(0x00020002)) >> int32(2)
  56036 		v1 = int32(**(**uint8_t)(__ccgo_up(top_y + uintptr(len1-int32(1)))))
  56037 		v2 = int32(uv04 & uint32(0xff))
  56038 		v3 = int32(uv04 >> libc.Int32FromInt32(16))
  56039 		v4 = top_dst + uintptr((len1-int32(1))*int32(3))
  56040 		v7 = v1 * int32(19077) >> int32(8)
  56041 		goto _243
  56042 	_243:
  56043 		v9 = v2 * int32(33050) >> int32(8)
  56044 		goto _245
  56045 	_245:
  56046 		v11 = v7 + v9 - int32(17685)
  56047 		if v11 & ^int32(YUV_MASK2) == 0 {
  56048 			v14 = v11 >> int32(YUV_FIX2)
  56049 		} else {
  56050 			if v11 < 0 {
  56051 				v15 = 0
  56052 			} else {
  56053 				v15 = int32(255)
  56054 			}
  56055 			v14 = v15
  56056 		}
  56057 		v12 = v14
  56058 		goto _248
  56059 	_248:
  56060 		v5 = v12
  56061 		goto _241
  56062 	_241:
  56063 		**(**uint8_t)(__ccgo_up(v4)) = uint8(v5)
  56064 		v18 = v1 * int32(19077) >> int32(8)
  56065 		goto _254
  56066 	_254:
  56067 		v20 = v2 * int32(6419) >> int32(8)
  56068 		goto _256
  56069 	_256:
  56070 		v22 = v3 * int32(13320) >> int32(8)
  56071 		goto _258
  56072 	_258:
  56073 		v24 = v18 - v20 - v22 + int32(8708)
  56074 		if v24 & ^int32(YUV_MASK2) == 0 {
  56075 			v27 = v24 >> int32(YUV_FIX2)
  56076 		} else {
  56077 			if v24 < 0 {
  56078 				v28 = 0
  56079 			} else {
  56080 				v28 = int32(255)
  56081 			}
  56082 			v27 = v28
  56083 		}
  56084 		v25 = v27
  56085 		goto _261
  56086 	_261:
  56087 		v16 = v25
  56088 		goto _252
  56089 	_252:
  56090 		**(**uint8_t)(__ccgo_up(v4 + 1)) = uint8(v16)
  56091 		v31 = v1 * int32(19077) >> int32(8)
  56092 		goto _267
  56093 	_267:
  56094 		v33 = v3 * int32(26149) >> int32(8)
  56095 		goto _269
  56096 	_269:
  56097 		v35 = v31 + v33 - int32(14234)
  56098 		if v35 & ^int32(YUV_MASK2) == 0 {
  56099 			v38 = v35 >> int32(YUV_FIX2)
  56100 		} else {
  56101 			if v35 < 0 {
  56102 				v39 = 0
  56103 			} else {
  56104 				v39 = int32(255)
  56105 			}
  56106 			v38 = v39
  56107 		}
  56108 		v36 = v38
  56109 		goto _272
  56110 	_272:
  56111 		v29 = v36
  56112 		goto _265
  56113 	_265:
  56114 		**(**uint8_t)(__ccgo_up(v4 + 2)) = uint8(v29)
  56115 		if bottom_y != libc.UintptrFromInt32(0) {
  56116 			uv05 = (uint32(3)*l_uv + tl_uv + uint32(0x00020002)) >> int32(2)
  56117 			v1 = int32(**(**uint8_t)(__ccgo_up(bottom_y + uintptr(len1-int32(1)))))
  56118 			v2 = int32(uv05 & uint32(0xff))
  56119 			v3 = int32(uv05 >> libc.Int32FromInt32(16))
  56120 			v4 = bottom_dst + uintptr((len1-int32(1))*int32(3))
  56121 			v7 = v1 * int32(19077) >> int32(8)
  56122 			goto _282
  56123 		_282:
  56124 			v9 = v2 * int32(33050) >> int32(8)
  56125 			goto _284
  56126 		_284:
  56127 			v11 = v7 + v9 - int32(17685)
  56128 			if v11 & ^int32(YUV_MASK2) == 0 {
  56129 				v14 = v11 >> int32(YUV_FIX2)
  56130 			} else {
  56131 				if v11 < 0 {
  56132 					v15 = 0
  56133 				} else {
  56134 					v15 = int32(255)
  56135 				}
  56136 				v14 = v15
  56137 			}
  56138 			v12 = v14
  56139 			goto _287
  56140 		_287:
  56141 			v5 = v12
  56142 			goto _280
  56143 		_280:
  56144 			**(**uint8_t)(__ccgo_up(v4)) = uint8(v5)
  56145 			v18 = v1 * int32(19077) >> int32(8)
  56146 			goto _293
  56147 		_293:
  56148 			v20 = v2 * int32(6419) >> int32(8)
  56149 			goto _295
  56150 		_295:
  56151 			v22 = v3 * int32(13320) >> int32(8)
  56152 			goto _297
  56153 		_297:
  56154 			v24 = v18 - v20 - v22 + int32(8708)
  56155 			if v24 & ^int32(YUV_MASK2) == 0 {
  56156 				v27 = v24 >> int32(YUV_FIX2)
  56157 			} else {
  56158 				if v24 < 0 {
  56159 					v28 = 0
  56160 				} else {
  56161 					v28 = int32(255)
  56162 				}
  56163 				v27 = v28
  56164 			}
  56165 			v25 = v27
  56166 			goto _300
  56167 		_300:
  56168 			v16 = v25
  56169 			goto _291
  56170 		_291:
  56171 			**(**uint8_t)(__ccgo_up(v4 + 1)) = uint8(v16)
  56172 			v31 = v1 * int32(19077) >> int32(8)
  56173 			goto _306
  56174 		_306:
  56175 			v33 = v3 * int32(26149) >> int32(8)
  56176 			goto _308
  56177 		_308:
  56178 			v35 = v31 + v33 - int32(14234)
  56179 			if v35 & ^int32(YUV_MASK2) == 0 {
  56180 				v38 = v35 >> int32(YUV_FIX2)
  56181 			} else {
  56182 				if v35 < 0 {
  56183 					v39 = 0
  56184 				} else {
  56185 					v39 = int32(255)
  56186 				}
  56187 				v38 = v39
  56188 			}
  56189 			v36 = v38
  56190 			goto _311
  56191 		_311:
  56192 			v29 = v36
  56193 			goto _304
  56194 		_304:
  56195 			**(**uint8_t)(__ccgo_up(v4 + 2)) = uint8(v29)
  56196 		}
  56197 	}
  56198 }
  56199 
  56200 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) {
  56201 	var avg, diag_03, diag_12, l_uv, t_uv, tl_uv, uv, uv0, uv01, uv02, uv03, uv04, uv05, uv1, uv11 uint32_t
  56202 	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
  56203 	var v4 uintptr
  56204 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  56205 	last_pixel_pair = (len1 - int32(1)) >> int32(1)
  56206 	tl_uv = uint32(int32(**(**uint8_t)(__ccgo_up(top_u))) | int32(**(**uint8_t)(__ccgo_up(top_v)))<<libc.Int32FromInt32(16)) /* top-left sample */
  56207 	l_uv = uint32(int32(**(**uint8_t)(__ccgo_up(cur_u))) | int32(**(**uint8_t)(__ccgo_up(cur_v)))<<libc.Int32FromInt32(16))
  56208 	uv0 = (uint32(3)*tl_uv + l_uv + uint32(0x00020002)) >> int32(2)
  56209 	v1 = int32(**(**uint8_t)(__ccgo_up(top_y)))
  56210 	v2 = int32(uv0 & uint32(0xff))
  56211 	v3 = int32(uv0 >> libc.Int32FromInt32(16))
  56212 	v4 = top_dst
  56213 	v7 = v1 * int32(19077) >> int32(8)
  56214 	goto _8
  56215 _8:
  56216 	v9 = v3 * int32(26149) >> int32(8)
  56217 	goto _10
  56218 _10:
  56219 	v11 = v7 + v9 - int32(14234)
  56220 	if v11 & ^int32(YUV_MASK2) == 0 {
  56221 		v14 = v11 >> int32(YUV_FIX2)
  56222 	} else {
  56223 		if v11 < 0 {
  56224 			v15 = 0
  56225 		} else {
  56226 			v15 = int32(255)
  56227 		}
  56228 		v14 = v15
  56229 	}
  56230 	v12 = v14
  56231 	goto _13
  56232 _13:
  56233 	v5 = v12
  56234 	goto _6
  56235 _6:
  56236 	r = v5
  56237 	v18 = v1 * int32(19077) >> int32(8)
  56238 	goto _19
  56239 _19:
  56240 	v20 = v2 * int32(6419) >> int32(8)
  56241 	goto _21
  56242 _21:
  56243 	v22 = v3 * int32(13320) >> int32(8)
  56244 	goto _23
  56245 _23:
  56246 	v24 = v18 - v20 - v22 + int32(8708)
  56247 	if v24 & ^int32(YUV_MASK2) == 0 {
  56248 		v27 = v24 >> int32(YUV_FIX2)
  56249 	} else {
  56250 		if v24 < 0 {
  56251 			v28 = 0
  56252 		} else {
  56253 			v28 = int32(255)
  56254 		}
  56255 		v27 = v28
  56256 	}
  56257 	v25 = v27
  56258 	goto _26
  56259 _26:
  56260 	v16 = v25
  56261 	goto _17
  56262 _17:
  56263 	g = v16
  56264 	v31 = v1 * int32(19077) >> int32(8)
  56265 	goto _32
  56266 _32:
  56267 	v33 = v2 * int32(33050) >> int32(8)
  56268 	goto _34
  56269 _34:
  56270 	v35 = v31 + v33 - int32(17685)
  56271 	if v35 & ^int32(YUV_MASK2) == 0 {
  56272 		v38 = v35 >> int32(YUV_FIX2)
  56273 	} else {
  56274 		if v35 < 0 {
  56275 			v39 = 0
  56276 		} else {
  56277 			v39 = int32(255)
  56278 		}
  56279 		v38 = v39
  56280 	}
  56281 	v36 = v38
  56282 	goto _37
  56283 _37:
  56284 	v29 = v36
  56285 	goto _30
  56286 _30:
  56287 	b = v29
  56288 	rg = r&int32(0xf0) | g>>libc.Int32FromInt32(4)
  56289 	ba = b&int32(0xf0) | int32(0x0f)
  56290 	**(**uint8_t)(__ccgo_up(v4)) = uint8(rg)
  56291 	**(**uint8_t)(__ccgo_up(v4 + 1)) = uint8(ba)
  56292 	if bottom_y != libc.UintptrFromInt32(0) {
  56293 		uv01 = (uint32(3)*l_uv + tl_uv + uint32(0x00020002)) >> int32(2)
  56294 		v1 = int32(**(**uint8_t)(__ccgo_up(bottom_y)))
  56295 		v2 = int32(uv01 & uint32(0xff))
  56296 		v3 = int32(uv01 >> libc.Int32FromInt32(16))
  56297 		v4 = bottom_dst
  56298 		v7 = v1 * int32(19077) >> int32(8)
  56299 		goto _47
  56300 	_47:
  56301 		v9 = v3 * int32(26149) >> int32(8)
  56302 		goto _49
  56303 	_49:
  56304 		v11 = v7 + v9 - int32(14234)
  56305 		if v11 & ^int32(YUV_MASK2) == 0 {
  56306 			v14 = v11 >> int32(YUV_FIX2)
  56307 		} else {
  56308 			if v11 < 0 {
  56309 				v15 = 0
  56310 			} else {
  56311 				v15 = int32(255)
  56312 			}
  56313 			v14 = v15
  56314 		}
  56315 		v12 = v14
  56316 		goto _52
  56317 	_52:
  56318 		v5 = v12
  56319 		goto _45
  56320 	_45:
  56321 		r = v5
  56322 		v18 = v1 * int32(19077) >> int32(8)
  56323 		goto _58
  56324 	_58:
  56325 		v20 = v2 * int32(6419) >> int32(8)
  56326 		goto _60
  56327 	_60:
  56328 		v22 = v3 * int32(13320) >> int32(8)
  56329 		goto _62
  56330 	_62:
  56331 		v24 = v18 - v20 - v22 + int32(8708)
  56332 		if v24 & ^int32(YUV_MASK2) == 0 {
  56333 			v27 = v24 >> int32(YUV_FIX2)
  56334 		} else {
  56335 			if v24 < 0 {
  56336 				v28 = 0
  56337 			} else {
  56338 				v28 = int32(255)
  56339 			}
  56340 			v27 = v28
  56341 		}
  56342 		v25 = v27
  56343 		goto _65
  56344 	_65:
  56345 		v16 = v25
  56346 		goto _56
  56347 	_56:
  56348 		g = v16
  56349 		v31 = v1 * int32(19077) >> int32(8)
  56350 		goto _71
  56351 	_71:
  56352 		v33 = v2 * int32(33050) >> int32(8)
  56353 		goto _73
  56354 	_73:
  56355 		v35 = v31 + v33 - int32(17685)
  56356 		if v35 & ^int32(YUV_MASK2) == 0 {
  56357 			v38 = v35 >> int32(YUV_FIX2)
  56358 		} else {
  56359 			if v35 < 0 {
  56360 				v39 = 0
  56361 			} else {
  56362 				v39 = int32(255)
  56363 			}
  56364 			v38 = v39
  56365 		}
  56366 		v36 = v38
  56367 		goto _76
  56368 	_76:
  56369 		v29 = v36
  56370 		goto _69
  56371 	_69:
  56372 		b = v29
  56373 		rg = r&int32(0xf0) | g>>libc.Int32FromInt32(4)
  56374 		ba = b&int32(0xf0) | int32(0x0f)
  56375 		**(**uint8_t)(__ccgo_up(v4)) = uint8(rg)
  56376 		**(**uint8_t)(__ccgo_up(v4 + 1)) = uint8(ba)
  56377 	}
  56378 	x = int32(1)
  56379 	for {
  56380 		if !(x <= last_pixel_pair) {
  56381 			break
  56382 		}
  56383 		t_uv = uint32(int32(**(**uint8_t)(__ccgo_up(top_u + uintptr(x)))) | int32(**(**uint8_t)(__ccgo_up(top_v + uintptr(x))))<<libc.Int32FromInt32(16)) /* top sample */
  56384 		uv = uint32(int32(**(**uint8_t)(__ccgo_up(cur_u + uintptr(x)))) | int32(**(**uint8_t)(__ccgo_up(cur_v + uintptr(x))))<<libc.Int32FromInt32(16))   /* sample */ /* precompute invariant values associated with first and second diagonals*/
  56385 		avg = tl_uv + t_uv + l_uv + uv + uint32(0x00080008)
  56386 		diag_12 = (avg + uint32(2)*(t_uv+l_uv)) >> int32(3)
  56387 		diag_03 = (avg + uint32(2)*(tl_uv+uv)) >> int32(3)
  56388 		uv02 = (diag_12 + tl_uv) >> int32(1)
  56389 		uv1 = (diag_03 + t_uv) >> int32(1)
  56390 		v1 = int32(**(**uint8_t)(__ccgo_up(top_y + uintptr(int32(2)*x-int32(1)))))
  56391 		v2 = int32(uv02 & uint32(0xff))
  56392 		v3 = int32(uv02 >> libc.Int32FromInt32(16))
  56393 		v4 = top_dst + uintptr((int32(2)*x-int32(1))*int32(2))
  56394 		v7 = v1 * int32(19077) >> int32(8)
  56395 		goto _87
  56396 	_87:
  56397 		v9 = v3 * int32(26149) >> int32(8)
  56398 		goto _89
  56399 	_89:
  56400 		v11 = v7 + v9 - int32(14234)
  56401 		if v11 & ^int32(YUV_MASK2) == 0 {
  56402 			v14 = v11 >> int32(YUV_FIX2)
  56403 		} else {
  56404 			if v11 < 0 {
  56405 				v15 = 0
  56406 			} else {
  56407 				v15 = int32(255)
  56408 			}
  56409 			v14 = v15
  56410 		}
  56411 		v12 = v14
  56412 		goto _92
  56413 	_92:
  56414 		v5 = v12
  56415 		goto _85
  56416 	_85:
  56417 		r = v5
  56418 		v18 = v1 * int32(19077) >> int32(8)
  56419 		goto _98
  56420 	_98:
  56421 		v20 = v2 * int32(6419) >> int32(8)
  56422 		goto _100
  56423 	_100:
  56424 		v22 = v3 * int32(13320) >> int32(8)
  56425 		goto _102
  56426 	_102:
  56427 		v24 = v18 - v20 - v22 + int32(8708)
  56428 		if v24 & ^int32(YUV_MASK2) == 0 {
  56429 			v27 = v24 >> int32(YUV_FIX2)
  56430 		} else {
  56431 			if v24 < 0 {
  56432 				v28 = 0
  56433 			} else {
  56434 				v28 = int32(255)
  56435 			}
  56436 			v27 = v28
  56437 		}
  56438 		v25 = v27
  56439 		goto _105
  56440 	_105:
  56441 		v16 = v25
  56442 		goto _96
  56443 	_96:
  56444 		g = v16
  56445 		v31 = v1 * int32(19077) >> int32(8)
  56446 		goto _111
  56447 	_111:
  56448 		v33 = v2 * int32(33050) >> int32(8)
  56449 		goto _113
  56450 	_113:
  56451 		v35 = v31 + v33 - int32(17685)
  56452 		if v35 & ^int32(YUV_MASK2) == 0 {
  56453 			v38 = v35 >> int32(YUV_FIX2)
  56454 		} else {
  56455 			if v35 < 0 {
  56456 				v39 = 0
  56457 			} else {
  56458 				v39 = int32(255)
  56459 			}
  56460 			v38 = v39
  56461 		}
  56462 		v36 = v38
  56463 		goto _116
  56464 	_116:
  56465 		v29 = v36
  56466 		goto _109
  56467 	_109:
  56468 		b = v29
  56469 		rg = r&int32(0xf0) | g>>libc.Int32FromInt32(4)
  56470 		ba = b&int32(0xf0) | int32(0x0f)
  56471 		**(**uint8_t)(__ccgo_up(v4)) = uint8(rg)
  56472 		**(**uint8_t)(__ccgo_up(v4 + 1)) = uint8(ba)
  56473 		v1 = int32(**(**uint8_t)(__ccgo_up(top_y + uintptr(int32(2)*x-0))))
  56474 		v2 = int32(uv1 & uint32(0xff))
  56475 		v3 = int32(uv1 >> libc.Int32FromInt32(16))
  56476 		v4 = top_dst + uintptr((int32(2)*x-0)*int32(2))
  56477 		v7 = v1 * int32(19077) >> int32(8)
  56478 		goto _126
  56479 	_126:
  56480 		v9 = v3 * int32(26149) >> int32(8)
  56481 		goto _128
  56482 	_128:
  56483 		v11 = v7 + v9 - int32(14234)
  56484 		if v11 & ^int32(YUV_MASK2) == 0 {
  56485 			v14 = v11 >> int32(YUV_FIX2)
  56486 		} else {
  56487 			if v11 < 0 {
  56488 				v15 = 0
  56489 			} else {
  56490 				v15 = int32(255)
  56491 			}
  56492 			v14 = v15
  56493 		}
  56494 		v12 = v14
  56495 		goto _131
  56496 	_131:
  56497 		v5 = v12
  56498 		goto _124
  56499 	_124:
  56500 		r = v5
  56501 		v18 = v1 * int32(19077) >> int32(8)
  56502 		goto _137
  56503 	_137:
  56504 		v20 = v2 * int32(6419) >> int32(8)
  56505 		goto _139
  56506 	_139:
  56507 		v22 = v3 * int32(13320) >> int32(8)
  56508 		goto _141
  56509 	_141:
  56510 		v24 = v18 - v20 - v22 + int32(8708)
  56511 		if v24 & ^int32(YUV_MASK2) == 0 {
  56512 			v27 = v24 >> int32(YUV_FIX2)
  56513 		} else {
  56514 			if v24 < 0 {
  56515 				v28 = 0
  56516 			} else {
  56517 				v28 = int32(255)
  56518 			}
  56519 			v27 = v28
  56520 		}
  56521 		v25 = v27
  56522 		goto _144
  56523 	_144:
  56524 		v16 = v25
  56525 		goto _135
  56526 	_135:
  56527 		g = v16
  56528 		v31 = v1 * int32(19077) >> int32(8)
  56529 		goto _150
  56530 	_150:
  56531 		v33 = v2 * int32(33050) >> int32(8)
  56532 		goto _152
  56533 	_152:
  56534 		v35 = v31 + v33 - int32(17685)
  56535 		if v35 & ^int32(YUV_MASK2) == 0 {
  56536 			v38 = v35 >> int32(YUV_FIX2)
  56537 		} else {
  56538 			if v35 < 0 {
  56539 				v39 = 0
  56540 			} else {
  56541 				v39 = int32(255)
  56542 			}
  56543 			v38 = v39
  56544 		}
  56545 		v36 = v38
  56546 		goto _155
  56547 	_155:
  56548 		v29 = v36
  56549 		goto _148
  56550 	_148:
  56551 		b = v29
  56552 		rg = r&int32(0xf0) | g>>libc.Int32FromInt32(4)
  56553 		ba = b&int32(0xf0) | int32(0x0f)
  56554 		**(**uint8_t)(__ccgo_up(v4)) = uint8(rg)
  56555 		**(**uint8_t)(__ccgo_up(v4 + 1)) = uint8(ba)
  56556 		if bottom_y != libc.UintptrFromInt32(0) {
  56557 			uv03 = (diag_03 + l_uv) >> int32(1)
  56558 			uv11 = (diag_12 + uv) >> int32(1)
  56559 			v1 = int32(**(**uint8_t)(__ccgo_up(bottom_y + uintptr(int32(2)*x-int32(1)))))
  56560 			v2 = int32(uv03 & uint32(0xff))
  56561 			v3 = int32(uv03 >> libc.Int32FromInt32(16))
  56562 			v4 = bottom_dst + uintptr((int32(2)*x-int32(1))*int32(2))
  56563 			v7 = v1 * int32(19077) >> int32(8)
  56564 			goto _165
  56565 		_165:
  56566 			v9 = v3 * int32(26149) >> int32(8)
  56567 			goto _167
  56568 		_167:
  56569 			v11 = v7 + v9 - int32(14234)
  56570 			if v11 & ^int32(YUV_MASK2) == 0 {
  56571 				v14 = v11 >> int32(YUV_FIX2)
  56572 			} else {
  56573 				if v11 < 0 {
  56574 					v15 = 0
  56575 				} else {
  56576 					v15 = int32(255)
  56577 				}
  56578 				v14 = v15
  56579 			}
  56580 			v12 = v14
  56581 			goto _170
  56582 		_170:
  56583 			v5 = v12
  56584 			goto _163
  56585 		_163:
  56586 			r = v5
  56587 			v18 = v1 * int32(19077) >> int32(8)
  56588 			goto _176
  56589 		_176:
  56590 			v20 = v2 * int32(6419) >> int32(8)
  56591 			goto _178
  56592 		_178:
  56593 			v22 = v3 * int32(13320) >> int32(8)
  56594 			goto _180
  56595 		_180:
  56596 			v24 = v18 - v20 - v22 + int32(8708)
  56597 			if v24 & ^int32(YUV_MASK2) == 0 {
  56598 				v27 = v24 >> int32(YUV_FIX2)
  56599 			} else {
  56600 				if v24 < 0 {
  56601 					v28 = 0
  56602 				} else {
  56603 					v28 = int32(255)
  56604 				}
  56605 				v27 = v28
  56606 			}
  56607 			v25 = v27
  56608 			goto _183
  56609 		_183:
  56610 			v16 = v25
  56611 			goto _174
  56612 		_174:
  56613 			g = v16
  56614 			v31 = v1 * int32(19077) >> int32(8)
  56615 			goto _189
  56616 		_189:
  56617 			v33 = v2 * int32(33050) >> int32(8)
  56618 			goto _191
  56619 		_191:
  56620 			v35 = v31 + v33 - int32(17685)
  56621 			if v35 & ^int32(YUV_MASK2) == 0 {
  56622 				v38 = v35 >> int32(YUV_FIX2)
  56623 			} else {
  56624 				if v35 < 0 {
  56625 					v39 = 0
  56626 				} else {
  56627 					v39 = int32(255)
  56628 				}
  56629 				v38 = v39
  56630 			}
  56631 			v36 = v38
  56632 			goto _194
  56633 		_194:
  56634 			v29 = v36
  56635 			goto _187
  56636 		_187:
  56637 			b = v29
  56638 			rg = r&int32(0xf0) | g>>libc.Int32FromInt32(4)
  56639 			ba = b&int32(0xf0) | int32(0x0f)
  56640 			**(**uint8_t)(__ccgo_up(v4)) = uint8(rg)
  56641 			**(**uint8_t)(__ccgo_up(v4 + 1)) = uint8(ba)
  56642 			v1 = int32(**(**uint8_t)(__ccgo_up(bottom_y + uintptr(int32(2)*x+0))))
  56643 			v2 = int32(uv11 & uint32(0xff))
  56644 			v3 = int32(uv11 >> libc.Int32FromInt32(16))
  56645 			v4 = bottom_dst + uintptr((int32(2)*x+0)*int32(2))
  56646 			v7 = v1 * int32(19077) >> int32(8)
  56647 			goto _204
  56648 		_204:
  56649 			v9 = v3 * int32(26149) >> int32(8)
  56650 			goto _206
  56651 		_206:
  56652 			v11 = v7 + v9 - int32(14234)
  56653 			if v11 & ^int32(YUV_MASK2) == 0 {
  56654 				v14 = v11 >> int32(YUV_FIX2)
  56655 			} else {
  56656 				if v11 < 0 {
  56657 					v15 = 0
  56658 				} else {
  56659 					v15 = int32(255)
  56660 				}
  56661 				v14 = v15
  56662 			}
  56663 			v12 = v14
  56664 			goto _209
  56665 		_209:
  56666 			v5 = v12
  56667 			goto _202
  56668 		_202:
  56669 			r = v5
  56670 			v18 = v1 * int32(19077) >> int32(8)
  56671 			goto _215
  56672 		_215:
  56673 			v20 = v2 * int32(6419) >> int32(8)
  56674 			goto _217
  56675 		_217:
  56676 			v22 = v3 * int32(13320) >> int32(8)
  56677 			goto _219
  56678 		_219:
  56679 			v24 = v18 - v20 - v22 + int32(8708)
  56680 			if v24 & ^int32(YUV_MASK2) == 0 {
  56681 				v27 = v24 >> int32(YUV_FIX2)
  56682 			} else {
  56683 				if v24 < 0 {
  56684 					v28 = 0
  56685 				} else {
  56686 					v28 = int32(255)
  56687 				}
  56688 				v27 = v28
  56689 			}
  56690 			v25 = v27
  56691 			goto _222
  56692 		_222:
  56693 			v16 = v25
  56694 			goto _213
  56695 		_213:
  56696 			g = v16
  56697 			v31 = v1 * int32(19077) >> int32(8)
  56698 			goto _228
  56699 		_228:
  56700 			v33 = v2 * int32(33050) >> int32(8)
  56701 			goto _230
  56702 		_230:
  56703 			v35 = v31 + v33 - int32(17685)
  56704 			if v35 & ^int32(YUV_MASK2) == 0 {
  56705 				v38 = v35 >> int32(YUV_FIX2)
  56706 			} else {
  56707 				if v35 < 0 {
  56708 					v39 = 0
  56709 				} else {
  56710 					v39 = int32(255)
  56711 				}
  56712 				v38 = v39
  56713 			}
  56714 			v36 = v38
  56715 			goto _233
  56716 		_233:
  56717 			v29 = v36
  56718 			goto _226
  56719 		_226:
  56720 			b = v29
  56721 			rg = r&int32(0xf0) | g>>libc.Int32FromInt32(4)
  56722 			ba = b&int32(0xf0) | int32(0x0f)
  56723 			**(**uint8_t)(__ccgo_up(v4)) = uint8(rg)
  56724 			**(**uint8_t)(__ccgo_up(v4 + 1)) = uint8(ba)
  56725 		}
  56726 		tl_uv = t_uv
  56727 		l_uv = uv
  56728 		goto _79
  56729 	_79:
  56730 		;
  56731 		x = x + 1
  56732 	}
  56733 	if !(len1&libc.Int32FromInt32(1) != 0) {
  56734 		uv04 = (uint32(3)*tl_uv + l_uv + uint32(0x00020002)) >> int32(2)
  56735 		v1 = int32(**(**uint8_t)(__ccgo_up(top_y + uintptr(len1-int32(1)))))
  56736 		v2 = int32(uv04 & uint32(0xff))
  56737 		v3 = int32(uv04 >> libc.Int32FromInt32(16))
  56738 		v4 = top_dst + uintptr((len1-int32(1))*int32(2))
  56739 		v7 = v1 * int32(19077) >> int32(8)
  56740 		goto _243
  56741 	_243:
  56742 		v9 = v3 * int32(26149) >> int32(8)
  56743 		goto _245
  56744 	_245:
  56745 		v11 = v7 + v9 - int32(14234)
  56746 		if v11 & ^int32(YUV_MASK2) == 0 {
  56747 			v14 = v11 >> int32(YUV_FIX2)
  56748 		} else {
  56749 			if v11 < 0 {
  56750 				v15 = 0
  56751 			} else {
  56752 				v15 = int32(255)
  56753 			}
  56754 			v14 = v15
  56755 		}
  56756 		v12 = v14
  56757 		goto _248
  56758 	_248:
  56759 		v5 = v12
  56760 		goto _241
  56761 	_241:
  56762 		r = v5
  56763 		v18 = v1 * int32(19077) >> int32(8)
  56764 		goto _254
  56765 	_254:
  56766 		v20 = v2 * int32(6419) >> int32(8)
  56767 		goto _256
  56768 	_256:
  56769 		v22 = v3 * int32(13320) >> int32(8)
  56770 		goto _258
  56771 	_258:
  56772 		v24 = v18 - v20 - v22 + int32(8708)
  56773 		if v24 & ^int32(YUV_MASK2) == 0 {
  56774 			v27 = v24 >> int32(YUV_FIX2)
  56775 		} else {
  56776 			if v24 < 0 {
  56777 				v28 = 0
  56778 			} else {
  56779 				v28 = int32(255)
  56780 			}
  56781 			v27 = v28
  56782 		}
  56783 		v25 = v27
  56784 		goto _261
  56785 	_261:
  56786 		v16 = v25
  56787 		goto _252
  56788 	_252:
  56789 		g = v16
  56790 		v31 = v1 * int32(19077) >> int32(8)
  56791 		goto _267
  56792 	_267:
  56793 		v33 = v2 * int32(33050) >> int32(8)
  56794 		goto _269
  56795 	_269:
  56796 		v35 = v31 + v33 - int32(17685)
  56797 		if v35 & ^int32(YUV_MASK2) == 0 {
  56798 			v38 = v35 >> int32(YUV_FIX2)
  56799 		} else {
  56800 			if v35 < 0 {
  56801 				v39 = 0
  56802 			} else {
  56803 				v39 = int32(255)
  56804 			}
  56805 			v38 = v39
  56806 		}
  56807 		v36 = v38
  56808 		goto _272
  56809 	_272:
  56810 		v29 = v36
  56811 		goto _265
  56812 	_265:
  56813 		b = v29
  56814 		rg = r&int32(0xf0) | g>>libc.Int32FromInt32(4)
  56815 		ba = b&int32(0xf0) | int32(0x0f)
  56816 		**(**uint8_t)(__ccgo_up(v4)) = uint8(rg)
  56817 		**(**uint8_t)(__ccgo_up(v4 + 1)) = uint8(ba)
  56818 		if bottom_y != libc.UintptrFromInt32(0) {
  56819 			uv05 = (uint32(3)*l_uv + tl_uv + uint32(0x00020002)) >> int32(2)
  56820 			v1 = int32(**(**uint8_t)(__ccgo_up(bottom_y + uintptr(len1-int32(1)))))
  56821 			v2 = int32(uv05 & uint32(0xff))
  56822 			v3 = int32(uv05 >> libc.Int32FromInt32(16))
  56823 			v4 = bottom_dst + uintptr((len1-int32(1))*int32(2))
  56824 			v7 = v1 * int32(19077) >> int32(8)
  56825 			goto _282
  56826 		_282:
  56827 			v9 = v3 * int32(26149) >> int32(8)
  56828 			goto _284
  56829 		_284:
  56830 			v11 = v7 + v9 - int32(14234)
  56831 			if v11 & ^int32(YUV_MASK2) == 0 {
  56832 				v14 = v11 >> int32(YUV_FIX2)
  56833 			} else {
  56834 				if v11 < 0 {
  56835 					v15 = 0
  56836 				} else {
  56837 					v15 = int32(255)
  56838 				}
  56839 				v14 = v15
  56840 			}
  56841 			v12 = v14
  56842 			goto _287
  56843 		_287:
  56844 			v5 = v12
  56845 			goto _280
  56846 		_280:
  56847 			r = v5
  56848 			v18 = v1 * int32(19077) >> int32(8)
  56849 			goto _293
  56850 		_293:
  56851 			v20 = v2 * int32(6419) >> int32(8)
  56852 			goto _295
  56853 		_295:
  56854 			v22 = v3 * int32(13320) >> int32(8)
  56855 			goto _297
  56856 		_297:
  56857 			v24 = v18 - v20 - v22 + int32(8708)
  56858 			if v24 & ^int32(YUV_MASK2) == 0 {
  56859 				v27 = v24 >> int32(YUV_FIX2)
  56860 			} else {
  56861 				if v24 < 0 {
  56862 					v28 = 0
  56863 				} else {
  56864 					v28 = int32(255)
  56865 				}
  56866 				v27 = v28
  56867 			}
  56868 			v25 = v27
  56869 			goto _300
  56870 		_300:
  56871 			v16 = v25
  56872 			goto _291
  56873 		_291:
  56874 			g = v16
  56875 			v31 = v1 * int32(19077) >> int32(8)
  56876 			goto _306
  56877 		_306:
  56878 			v33 = v2 * int32(33050) >> int32(8)
  56879 			goto _308
  56880 		_308:
  56881 			v35 = v31 + v33 - int32(17685)
  56882 			if v35 & ^int32(YUV_MASK2) == 0 {
  56883 				v38 = v35 >> int32(YUV_FIX2)
  56884 			} else {
  56885 				if v35 < 0 {
  56886 					v39 = 0
  56887 				} else {
  56888 					v39 = int32(255)
  56889 				}
  56890 				v38 = v39
  56891 			}
  56892 			v36 = v38
  56893 			goto _311
  56894 		_311:
  56895 			v29 = v36
  56896 			goto _304
  56897 		_304:
  56898 			b = v29
  56899 			rg = r&int32(0xf0) | g>>libc.Int32FromInt32(4)
  56900 			ba = b&int32(0xf0) | int32(0x0f)
  56901 			**(**uint8_t)(__ccgo_up(v4)) = uint8(rg)
  56902 			**(**uint8_t)(__ccgo_up(v4 + 1)) = uint8(ba)
  56903 		}
  56904 	}
  56905 }
  56906 
  56907 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) {
  56908 	var avg, diag_03, diag_12, l_uv, t_uv, tl_uv, uv, uv0, uv01, uv02, uv03, uv04, uv05, uv1, uv11 uint32_t
  56909 	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
  56910 	var v4 uintptr
  56911 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  56912 	last_pixel_pair = (len1 - int32(1)) >> int32(1)
  56913 	tl_uv = uint32(int32(**(**uint8_t)(__ccgo_up(top_u))) | int32(**(**uint8_t)(__ccgo_up(top_v)))<<libc.Int32FromInt32(16)) /* top-left sample */
  56914 	l_uv = uint32(int32(**(**uint8_t)(__ccgo_up(cur_u))) | int32(**(**uint8_t)(__ccgo_up(cur_v)))<<libc.Int32FromInt32(16))
  56915 	uv0 = (uint32(3)*tl_uv + l_uv + uint32(0x00020002)) >> int32(2)
  56916 	v1 = int32(**(**uint8_t)(__ccgo_up(top_y)))
  56917 	v2 = int32(uv0 & uint32(0xff))
  56918 	v3 = int32(uv0 >> libc.Int32FromInt32(16))
  56919 	v4 = top_dst
  56920 	v7 = v1 * int32(19077) >> int32(8)
  56921 	goto _8
  56922 _8:
  56923 	v9 = v3 * int32(26149) >> int32(8)
  56924 	goto _10
  56925 _10:
  56926 	v11 = v7 + v9 - int32(14234)
  56927 	if v11 & ^int32(YUV_MASK2) == 0 {
  56928 		v14 = v11 >> int32(YUV_FIX2)
  56929 	} else {
  56930 		if v11 < 0 {
  56931 			v15 = 0
  56932 		} else {
  56933 			v15 = int32(255)
  56934 		}
  56935 		v14 = v15
  56936 	}
  56937 	v12 = v14
  56938 	goto _13
  56939 _13:
  56940 	v5 = v12
  56941 	goto _6
  56942 _6:
  56943 	r = v5
  56944 	v18 = v1 * int32(19077) >> int32(8)
  56945 	goto _19
  56946 _19:
  56947 	v20 = v2 * int32(6419) >> int32(8)
  56948 	goto _21
  56949 _21:
  56950 	v22 = v3 * int32(13320) >> int32(8)
  56951 	goto _23
  56952 _23:
  56953 	v24 = v18 - v20 - v22 + int32(8708)
  56954 	if v24 & ^int32(YUV_MASK2) == 0 {
  56955 		v27 = v24 >> int32(YUV_FIX2)
  56956 	} else {
  56957 		if v24 < 0 {
  56958 			v28 = 0
  56959 		} else {
  56960 			v28 = int32(255)
  56961 		}
  56962 		v27 = v28
  56963 	}
  56964 	v25 = v27
  56965 	goto _26
  56966 _26:
  56967 	v16 = v25
  56968 	goto _17
  56969 _17:
  56970 	g = v16
  56971 	v31 = v1 * int32(19077) >> int32(8)
  56972 	goto _32
  56973 _32:
  56974 	v33 = v2 * int32(33050) >> int32(8)
  56975 	goto _34
  56976 _34:
  56977 	v35 = v31 + v33 - int32(17685)
  56978 	if v35 & ^int32(YUV_MASK2) == 0 {
  56979 		v38 = v35 >> int32(YUV_FIX2)
  56980 	} else {
  56981 		if v35 < 0 {
  56982 			v39 = 0
  56983 		} else {
  56984 			v39 = int32(255)
  56985 		}
  56986 		v38 = v39
  56987 	}
  56988 	v36 = v38
  56989 	goto _37
  56990 _37:
  56991 	v29 = v36
  56992 	goto _30
  56993 _30:
  56994 	b = v29
  56995 	rg = r&int32(0xf8) | g>>libc.Int32FromInt32(5)
  56996 	gb = g<<libc.Int32FromInt32(3)&int32(0xe0) | b>>libc.Int32FromInt32(3)
  56997 	**(**uint8_t)(__ccgo_up(v4)) = uint8(rg)
  56998 	**(**uint8_t)(__ccgo_up(v4 + 1)) = uint8(gb)
  56999 	if bottom_y != libc.UintptrFromInt32(0) {
  57000 		uv01 = (uint32(3)*l_uv + tl_uv + uint32(0x00020002)) >> int32(2)
  57001 		v1 = int32(**(**uint8_t)(__ccgo_up(bottom_y)))
  57002 		v2 = int32(uv01 & uint32(0xff))
  57003 		v3 = int32(uv01 >> libc.Int32FromInt32(16))
  57004 		v4 = bottom_dst
  57005 		v7 = v1 * int32(19077) >> int32(8)
  57006 		goto _47
  57007 	_47:
  57008 		v9 = v3 * int32(26149) >> int32(8)
  57009 		goto _49
  57010 	_49:
  57011 		v11 = v7 + v9 - int32(14234)
  57012 		if v11 & ^int32(YUV_MASK2) == 0 {
  57013 			v14 = v11 >> int32(YUV_FIX2)
  57014 		} else {
  57015 			if v11 < 0 {
  57016 				v15 = 0
  57017 			} else {
  57018 				v15 = int32(255)
  57019 			}
  57020 			v14 = v15
  57021 		}
  57022 		v12 = v14
  57023 		goto _52
  57024 	_52:
  57025 		v5 = v12
  57026 		goto _45
  57027 	_45:
  57028 		r = v5
  57029 		v18 = v1 * int32(19077) >> int32(8)
  57030 		goto _58
  57031 	_58:
  57032 		v20 = v2 * int32(6419) >> int32(8)
  57033 		goto _60
  57034 	_60:
  57035 		v22 = v3 * int32(13320) >> int32(8)
  57036 		goto _62
  57037 	_62:
  57038 		v24 = v18 - v20 - v22 + int32(8708)
  57039 		if v24 & ^int32(YUV_MASK2) == 0 {
  57040 			v27 = v24 >> int32(YUV_FIX2)
  57041 		} else {
  57042 			if v24 < 0 {
  57043 				v28 = 0
  57044 			} else {
  57045 				v28 = int32(255)
  57046 			}
  57047 			v27 = v28
  57048 		}
  57049 		v25 = v27
  57050 		goto _65
  57051 	_65:
  57052 		v16 = v25
  57053 		goto _56
  57054 	_56:
  57055 		g = v16
  57056 		v31 = v1 * int32(19077) >> int32(8)
  57057 		goto _71
  57058 	_71:
  57059 		v33 = v2 * int32(33050) >> int32(8)
  57060 		goto _73
  57061 	_73:
  57062 		v35 = v31 + v33 - int32(17685)
  57063 		if v35 & ^int32(YUV_MASK2) == 0 {
  57064 			v38 = v35 >> int32(YUV_FIX2)
  57065 		} else {
  57066 			if v35 < 0 {
  57067 				v39 = 0
  57068 			} else {
  57069 				v39 = int32(255)
  57070 			}
  57071 			v38 = v39
  57072 		}
  57073 		v36 = v38
  57074 		goto _76
  57075 	_76:
  57076 		v29 = v36
  57077 		goto _69
  57078 	_69:
  57079 		b = v29
  57080 		rg = r&int32(0xf8) | g>>libc.Int32FromInt32(5)
  57081 		gb = g<<libc.Int32FromInt32(3)&int32(0xe0) | b>>libc.Int32FromInt32(3)
  57082 		**(**uint8_t)(__ccgo_up(v4)) = uint8(rg)
  57083 		**(**uint8_t)(__ccgo_up(v4 + 1)) = uint8(gb)
  57084 	}
  57085 	x = int32(1)
  57086 	for {
  57087 		if !(x <= last_pixel_pair) {
  57088 			break
  57089 		}
  57090 		t_uv = uint32(int32(**(**uint8_t)(__ccgo_up(top_u + uintptr(x)))) | int32(**(**uint8_t)(__ccgo_up(top_v + uintptr(x))))<<libc.Int32FromInt32(16)) /* top sample */
  57091 		uv = uint32(int32(**(**uint8_t)(__ccgo_up(cur_u + uintptr(x)))) | int32(**(**uint8_t)(__ccgo_up(cur_v + uintptr(x))))<<libc.Int32FromInt32(16))   /* sample */ /* precompute invariant values associated with first and second diagonals*/
  57092 		avg = tl_uv + t_uv + l_uv + uv + uint32(0x00080008)
  57093 		diag_12 = (avg + uint32(2)*(t_uv+l_uv)) >> int32(3)
  57094 		diag_03 = (avg + uint32(2)*(tl_uv+uv)) >> int32(3)
  57095 		uv02 = (diag_12 + tl_uv) >> int32(1)
  57096 		uv1 = (diag_03 + t_uv) >> int32(1)
  57097 		v1 = int32(**(**uint8_t)(__ccgo_up(top_y + uintptr(int32(2)*x-int32(1)))))
  57098 		v2 = int32(uv02 & uint32(0xff))
  57099 		v3 = int32(uv02 >> libc.Int32FromInt32(16))
  57100 		v4 = top_dst + uintptr((int32(2)*x-int32(1))*int32(2))
  57101 		v7 = v1 * int32(19077) >> int32(8)
  57102 		goto _87
  57103 	_87:
  57104 		v9 = v3 * int32(26149) >> int32(8)
  57105 		goto _89
  57106 	_89:
  57107 		v11 = v7 + v9 - int32(14234)
  57108 		if v11 & ^int32(YUV_MASK2) == 0 {
  57109 			v14 = v11 >> int32(YUV_FIX2)
  57110 		} else {
  57111 			if v11 < 0 {
  57112 				v15 = 0
  57113 			} else {
  57114 				v15 = int32(255)
  57115 			}
  57116 			v14 = v15
  57117 		}
  57118 		v12 = v14
  57119 		goto _92
  57120 	_92:
  57121 		v5 = v12
  57122 		goto _85
  57123 	_85:
  57124 		r = v5
  57125 		v18 = v1 * int32(19077) >> int32(8)
  57126 		goto _98
  57127 	_98:
  57128 		v20 = v2 * int32(6419) >> int32(8)
  57129 		goto _100
  57130 	_100:
  57131 		v22 = v3 * int32(13320) >> int32(8)
  57132 		goto _102
  57133 	_102:
  57134 		v24 = v18 - v20 - v22 + int32(8708)
  57135 		if v24 & ^int32(YUV_MASK2) == 0 {
  57136 			v27 = v24 >> int32(YUV_FIX2)
  57137 		} else {
  57138 			if v24 < 0 {
  57139 				v28 = 0
  57140 			} else {
  57141 				v28 = int32(255)
  57142 			}
  57143 			v27 = v28
  57144 		}
  57145 		v25 = v27
  57146 		goto _105
  57147 	_105:
  57148 		v16 = v25
  57149 		goto _96
  57150 	_96:
  57151 		g = v16
  57152 		v31 = v1 * int32(19077) >> int32(8)
  57153 		goto _111
  57154 	_111:
  57155 		v33 = v2 * int32(33050) >> int32(8)
  57156 		goto _113
  57157 	_113:
  57158 		v35 = v31 + v33 - int32(17685)
  57159 		if v35 & ^int32(YUV_MASK2) == 0 {
  57160 			v38 = v35 >> int32(YUV_FIX2)
  57161 		} else {
  57162 			if v35 < 0 {
  57163 				v39 = 0
  57164 			} else {
  57165 				v39 = int32(255)
  57166 			}
  57167 			v38 = v39
  57168 		}
  57169 		v36 = v38
  57170 		goto _116
  57171 	_116:
  57172 		v29 = v36
  57173 		goto _109
  57174 	_109:
  57175 		b = v29
  57176 		rg = r&int32(0xf8) | g>>libc.Int32FromInt32(5)
  57177 		gb = g<<libc.Int32FromInt32(3)&int32(0xe0) | b>>libc.Int32FromInt32(3)
  57178 		**(**uint8_t)(__ccgo_up(v4)) = uint8(rg)
  57179 		**(**uint8_t)(__ccgo_up(v4 + 1)) = uint8(gb)
  57180 		v1 = int32(**(**uint8_t)(__ccgo_up(top_y + uintptr(int32(2)*x-0))))
  57181 		v2 = int32(uv1 & uint32(0xff))
  57182 		v3 = int32(uv1 >> libc.Int32FromInt32(16))
  57183 		v4 = top_dst + uintptr((int32(2)*x-0)*int32(2))
  57184 		v7 = v1 * int32(19077) >> int32(8)
  57185 		goto _126
  57186 	_126:
  57187 		v9 = v3 * int32(26149) >> int32(8)
  57188 		goto _128
  57189 	_128:
  57190 		v11 = v7 + v9 - int32(14234)
  57191 		if v11 & ^int32(YUV_MASK2) == 0 {
  57192 			v14 = v11 >> int32(YUV_FIX2)
  57193 		} else {
  57194 			if v11 < 0 {
  57195 				v15 = 0
  57196 			} else {
  57197 				v15 = int32(255)
  57198 			}
  57199 			v14 = v15
  57200 		}
  57201 		v12 = v14
  57202 		goto _131
  57203 	_131:
  57204 		v5 = v12
  57205 		goto _124
  57206 	_124:
  57207 		r = v5
  57208 		v18 = v1 * int32(19077) >> int32(8)
  57209 		goto _137
  57210 	_137:
  57211 		v20 = v2 * int32(6419) >> int32(8)
  57212 		goto _139
  57213 	_139:
  57214 		v22 = v3 * int32(13320) >> int32(8)
  57215 		goto _141
  57216 	_141:
  57217 		v24 = v18 - v20 - v22 + int32(8708)
  57218 		if v24 & ^int32(YUV_MASK2) == 0 {
  57219 			v27 = v24 >> int32(YUV_FIX2)
  57220 		} else {
  57221 			if v24 < 0 {
  57222 				v28 = 0
  57223 			} else {
  57224 				v28 = int32(255)
  57225 			}
  57226 			v27 = v28
  57227 		}
  57228 		v25 = v27
  57229 		goto _144
  57230 	_144:
  57231 		v16 = v25
  57232 		goto _135
  57233 	_135:
  57234 		g = v16
  57235 		v31 = v1 * int32(19077) >> int32(8)
  57236 		goto _150
  57237 	_150:
  57238 		v33 = v2 * int32(33050) >> int32(8)
  57239 		goto _152
  57240 	_152:
  57241 		v35 = v31 + v33 - int32(17685)
  57242 		if v35 & ^int32(YUV_MASK2) == 0 {
  57243 			v38 = v35 >> int32(YUV_FIX2)
  57244 		} else {
  57245 			if v35 < 0 {
  57246 				v39 = 0
  57247 			} else {
  57248 				v39 = int32(255)
  57249 			}
  57250 			v38 = v39
  57251 		}
  57252 		v36 = v38
  57253 		goto _155
  57254 	_155:
  57255 		v29 = v36
  57256 		goto _148
  57257 	_148:
  57258 		b = v29
  57259 		rg = r&int32(0xf8) | g>>libc.Int32FromInt32(5)
  57260 		gb = g<<libc.Int32FromInt32(3)&int32(0xe0) | b>>libc.Int32FromInt32(3)
  57261 		**(**uint8_t)(__ccgo_up(v4)) = uint8(rg)
  57262 		**(**uint8_t)(__ccgo_up(v4 + 1)) = uint8(gb)
  57263 		if bottom_y != libc.UintptrFromInt32(0) {
  57264 			uv03 = (diag_03 + l_uv) >> int32(1)
  57265 			uv11 = (diag_12 + uv) >> int32(1)
  57266 			v1 = int32(**(**uint8_t)(__ccgo_up(bottom_y + uintptr(int32(2)*x-int32(1)))))
  57267 			v2 = int32(uv03 & uint32(0xff))
  57268 			v3 = int32(uv03 >> libc.Int32FromInt32(16))
  57269 			v4 = bottom_dst + uintptr((int32(2)*x-int32(1))*int32(2))
  57270 			v7 = v1 * int32(19077) >> int32(8)
  57271 			goto _165
  57272 		_165:
  57273 			v9 = v3 * int32(26149) >> int32(8)
  57274 			goto _167
  57275 		_167:
  57276 			v11 = v7 + v9 - int32(14234)
  57277 			if v11 & ^int32(YUV_MASK2) == 0 {
  57278 				v14 = v11 >> int32(YUV_FIX2)
  57279 			} else {
  57280 				if v11 < 0 {
  57281 					v15 = 0
  57282 				} else {
  57283 					v15 = int32(255)
  57284 				}
  57285 				v14 = v15
  57286 			}
  57287 			v12 = v14
  57288 			goto _170
  57289 		_170:
  57290 			v5 = v12
  57291 			goto _163
  57292 		_163:
  57293 			r = v5
  57294 			v18 = v1 * int32(19077) >> int32(8)
  57295 			goto _176
  57296 		_176:
  57297 			v20 = v2 * int32(6419) >> int32(8)
  57298 			goto _178
  57299 		_178:
  57300 			v22 = v3 * int32(13320) >> int32(8)
  57301 			goto _180
  57302 		_180:
  57303 			v24 = v18 - v20 - v22 + int32(8708)
  57304 			if v24 & ^int32(YUV_MASK2) == 0 {
  57305 				v27 = v24 >> int32(YUV_FIX2)
  57306 			} else {
  57307 				if v24 < 0 {
  57308 					v28 = 0
  57309 				} else {
  57310 					v28 = int32(255)
  57311 				}
  57312 				v27 = v28
  57313 			}
  57314 			v25 = v27
  57315 			goto _183
  57316 		_183:
  57317 			v16 = v25
  57318 			goto _174
  57319 		_174:
  57320 			g = v16
  57321 			v31 = v1 * int32(19077) >> int32(8)
  57322 			goto _189
  57323 		_189:
  57324 			v33 = v2 * int32(33050) >> int32(8)
  57325 			goto _191
  57326 		_191:
  57327 			v35 = v31 + v33 - int32(17685)
  57328 			if v35 & ^int32(YUV_MASK2) == 0 {
  57329 				v38 = v35 >> int32(YUV_FIX2)
  57330 			} else {
  57331 				if v35 < 0 {
  57332 					v39 = 0
  57333 				} else {
  57334 					v39 = int32(255)
  57335 				}
  57336 				v38 = v39
  57337 			}
  57338 			v36 = v38
  57339 			goto _194
  57340 		_194:
  57341 			v29 = v36
  57342 			goto _187
  57343 		_187:
  57344 			b = v29
  57345 			rg = r&int32(0xf8) | g>>libc.Int32FromInt32(5)
  57346 			gb = g<<libc.Int32FromInt32(3)&int32(0xe0) | b>>libc.Int32FromInt32(3)
  57347 			**(**uint8_t)(__ccgo_up(v4)) = uint8(rg)
  57348 			**(**uint8_t)(__ccgo_up(v4 + 1)) = uint8(gb)
  57349 			v1 = int32(**(**uint8_t)(__ccgo_up(bottom_y + uintptr(int32(2)*x+0))))
  57350 			v2 = int32(uv11 & uint32(0xff))
  57351 			v3 = int32(uv11 >> libc.Int32FromInt32(16))
  57352 			v4 = bottom_dst + uintptr((int32(2)*x+0)*int32(2))
  57353 			v7 = v1 * int32(19077) >> int32(8)
  57354 			goto _204
  57355 		_204:
  57356 			v9 = v3 * int32(26149) >> int32(8)
  57357 			goto _206
  57358 		_206:
  57359 			v11 = v7 + v9 - int32(14234)
  57360 			if v11 & ^int32(YUV_MASK2) == 0 {
  57361 				v14 = v11 >> int32(YUV_FIX2)
  57362 			} else {
  57363 				if v11 < 0 {
  57364 					v15 = 0
  57365 				} else {
  57366 					v15 = int32(255)
  57367 				}
  57368 				v14 = v15
  57369 			}
  57370 			v12 = v14
  57371 			goto _209
  57372 		_209:
  57373 			v5 = v12
  57374 			goto _202
  57375 		_202:
  57376 			r = v5
  57377 			v18 = v1 * int32(19077) >> int32(8)
  57378 			goto _215
  57379 		_215:
  57380 			v20 = v2 * int32(6419) >> int32(8)
  57381 			goto _217
  57382 		_217:
  57383 			v22 = v3 * int32(13320) >> int32(8)
  57384 			goto _219
  57385 		_219:
  57386 			v24 = v18 - v20 - v22 + int32(8708)
  57387 			if v24 & ^int32(YUV_MASK2) == 0 {
  57388 				v27 = v24 >> int32(YUV_FIX2)
  57389 			} else {
  57390 				if v24 < 0 {
  57391 					v28 = 0
  57392 				} else {
  57393 					v28 = int32(255)
  57394 				}
  57395 				v27 = v28
  57396 			}
  57397 			v25 = v27
  57398 			goto _222
  57399 		_222:
  57400 			v16 = v25
  57401 			goto _213
  57402 		_213:
  57403 			g = v16
  57404 			v31 = v1 * int32(19077) >> int32(8)
  57405 			goto _228
  57406 		_228:
  57407 			v33 = v2 * int32(33050) >> int32(8)
  57408 			goto _230
  57409 		_230:
  57410 			v35 = v31 + v33 - int32(17685)
  57411 			if v35 & ^int32(YUV_MASK2) == 0 {
  57412 				v38 = v35 >> int32(YUV_FIX2)
  57413 			} else {
  57414 				if v35 < 0 {
  57415 					v39 = 0
  57416 				} else {
  57417 					v39 = int32(255)
  57418 				}
  57419 				v38 = v39
  57420 			}
  57421 			v36 = v38
  57422 			goto _233
  57423 		_233:
  57424 			v29 = v36
  57425 			goto _226
  57426 		_226:
  57427 			b = v29
  57428 			rg = r&int32(0xf8) | g>>libc.Int32FromInt32(5)
  57429 			gb = g<<libc.Int32FromInt32(3)&int32(0xe0) | b>>libc.Int32FromInt32(3)
  57430 			**(**uint8_t)(__ccgo_up(v4)) = uint8(rg)
  57431 			**(**uint8_t)(__ccgo_up(v4 + 1)) = uint8(gb)
  57432 		}
  57433 		tl_uv = t_uv
  57434 		l_uv = uv
  57435 		goto _79
  57436 	_79:
  57437 		;
  57438 		x = x + 1
  57439 	}
  57440 	if !(len1&libc.Int32FromInt32(1) != 0) {
  57441 		uv04 = (uint32(3)*tl_uv + l_uv + uint32(0x00020002)) >> int32(2)
  57442 		v1 = int32(**(**uint8_t)(__ccgo_up(top_y + uintptr(len1-int32(1)))))
  57443 		v2 = int32(uv04 & uint32(0xff))
  57444 		v3 = int32(uv04 >> libc.Int32FromInt32(16))
  57445 		v4 = top_dst + uintptr((len1-int32(1))*int32(2))
  57446 		v7 = v1 * int32(19077) >> int32(8)
  57447 		goto _243
  57448 	_243:
  57449 		v9 = v3 * int32(26149) >> int32(8)
  57450 		goto _245
  57451 	_245:
  57452 		v11 = v7 + v9 - int32(14234)
  57453 		if v11 & ^int32(YUV_MASK2) == 0 {
  57454 			v14 = v11 >> int32(YUV_FIX2)
  57455 		} else {
  57456 			if v11 < 0 {
  57457 				v15 = 0
  57458 			} else {
  57459 				v15 = int32(255)
  57460 			}
  57461 			v14 = v15
  57462 		}
  57463 		v12 = v14
  57464 		goto _248
  57465 	_248:
  57466 		v5 = v12
  57467 		goto _241
  57468 	_241:
  57469 		r = v5
  57470 		v18 = v1 * int32(19077) >> int32(8)
  57471 		goto _254
  57472 	_254:
  57473 		v20 = v2 * int32(6419) >> int32(8)
  57474 		goto _256
  57475 	_256:
  57476 		v22 = v3 * int32(13320) >> int32(8)
  57477 		goto _258
  57478 	_258:
  57479 		v24 = v18 - v20 - v22 + int32(8708)
  57480 		if v24 & ^int32(YUV_MASK2) == 0 {
  57481 			v27 = v24 >> int32(YUV_FIX2)
  57482 		} else {
  57483 			if v24 < 0 {
  57484 				v28 = 0
  57485 			} else {
  57486 				v28 = int32(255)
  57487 			}
  57488 			v27 = v28
  57489 		}
  57490 		v25 = v27
  57491 		goto _261
  57492 	_261:
  57493 		v16 = v25
  57494 		goto _252
  57495 	_252:
  57496 		g = v16
  57497 		v31 = v1 * int32(19077) >> int32(8)
  57498 		goto _267
  57499 	_267:
  57500 		v33 = v2 * int32(33050) >> int32(8)
  57501 		goto _269
  57502 	_269:
  57503 		v35 = v31 + v33 - int32(17685)
  57504 		if v35 & ^int32(YUV_MASK2) == 0 {
  57505 			v38 = v35 >> int32(YUV_FIX2)
  57506 		} else {
  57507 			if v35 < 0 {
  57508 				v39 = 0
  57509 			} else {
  57510 				v39 = int32(255)
  57511 			}
  57512 			v38 = v39
  57513 		}
  57514 		v36 = v38
  57515 		goto _272
  57516 	_272:
  57517 		v29 = v36
  57518 		goto _265
  57519 	_265:
  57520 		b = v29
  57521 		rg = r&int32(0xf8) | g>>libc.Int32FromInt32(5)
  57522 		gb = g<<libc.Int32FromInt32(3)&int32(0xe0) | b>>libc.Int32FromInt32(3)
  57523 		**(**uint8_t)(__ccgo_up(v4)) = uint8(rg)
  57524 		**(**uint8_t)(__ccgo_up(v4 + 1)) = uint8(gb)
  57525 		if bottom_y != libc.UintptrFromInt32(0) {
  57526 			uv05 = (uint32(3)*l_uv + tl_uv + uint32(0x00020002)) >> int32(2)
  57527 			v1 = int32(**(**uint8_t)(__ccgo_up(bottom_y + uintptr(len1-int32(1)))))
  57528 			v2 = int32(uv05 & uint32(0xff))
  57529 			v3 = int32(uv05 >> libc.Int32FromInt32(16))
  57530 			v4 = bottom_dst + uintptr((len1-int32(1))*int32(2))
  57531 			v7 = v1 * int32(19077) >> int32(8)
  57532 			goto _282
  57533 		_282:
  57534 			v9 = v3 * int32(26149) >> int32(8)
  57535 			goto _284
  57536 		_284:
  57537 			v11 = v7 + v9 - int32(14234)
  57538 			if v11 & ^int32(YUV_MASK2) == 0 {
  57539 				v14 = v11 >> int32(YUV_FIX2)
  57540 			} else {
  57541 				if v11 < 0 {
  57542 					v15 = 0
  57543 				} else {
  57544 					v15 = int32(255)
  57545 				}
  57546 				v14 = v15
  57547 			}
  57548 			v12 = v14
  57549 			goto _287
  57550 		_287:
  57551 			v5 = v12
  57552 			goto _280
  57553 		_280:
  57554 			r = v5
  57555 			v18 = v1 * int32(19077) >> int32(8)
  57556 			goto _293
  57557 		_293:
  57558 			v20 = v2 * int32(6419) >> int32(8)
  57559 			goto _295
  57560 		_295:
  57561 			v22 = v3 * int32(13320) >> int32(8)
  57562 			goto _297
  57563 		_297:
  57564 			v24 = v18 - v20 - v22 + int32(8708)
  57565 			if v24 & ^int32(YUV_MASK2) == 0 {
  57566 				v27 = v24 >> int32(YUV_FIX2)
  57567 			} else {
  57568 				if v24 < 0 {
  57569 					v28 = 0
  57570 				} else {
  57571 					v28 = int32(255)
  57572 				}
  57573 				v27 = v28
  57574 			}
  57575 			v25 = v27
  57576 			goto _300
  57577 		_300:
  57578 			v16 = v25
  57579 			goto _291
  57580 		_291:
  57581 			g = v16
  57582 			v31 = v1 * int32(19077) >> int32(8)
  57583 			goto _306
  57584 		_306:
  57585 			v33 = v2 * int32(33050) >> int32(8)
  57586 			goto _308
  57587 		_308:
  57588 			v35 = v31 + v33 - int32(17685)
  57589 			if v35 & ^int32(YUV_MASK2) == 0 {
  57590 				v38 = v35 >> int32(YUV_FIX2)
  57591 			} else {
  57592 				if v35 < 0 {
  57593 					v39 = 0
  57594 				} else {
  57595 					v39 = int32(255)
  57596 				}
  57597 				v38 = v39
  57598 			}
  57599 			v36 = v38
  57600 			goto _311
  57601 		_311:
  57602 			v29 = v36
  57603 			goto _304
  57604 		_304:
  57605 			b = v29
  57606 			rg = r&int32(0xf8) | g>>libc.Int32FromInt32(5)
  57607 			gb = g<<libc.Int32FromInt32(3)&int32(0xe0) | b>>libc.Int32FromInt32(3)
  57608 			**(**uint8_t)(__ccgo_up(v4)) = uint8(rg)
  57609 			**(**uint8_t)(__ccgo_up(v4 + 1)) = uint8(gb)
  57610 		}
  57611 	}
  57612 }
  57613 
  57614 //------------------------------------------------------------------------------
  57615 
  57616 func WebPGetLinePairConverter(tls *libc.TLS, alpha_is_last int32) (r WebPUpsampleLinePairFunc) {
  57617 	var v1 int32
  57618 	_ = v1
  57619 	WebPInitUpsamplers(tls)
  57620 	if alpha_is_last != 0 {
  57621 		v1 = int32(MODE_BGRA)
  57622 	} else {
  57623 		v1 = int32(MODE_ARGB)
  57624 	}
  57625 	return WebPUpsamplers[v1]
  57626 }
  57627 
  57628 func WebPYuv444ToRgba_C(tls *libc.TLS, y5 uintptr, u4 uintptr, v6 uintptr, dst uintptr, len1 int32) {
  57629 	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
  57630 	var v2, v61 uintptr
  57631 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  57632 	i = 0
  57633 	for {
  57634 		if !(i < len1) {
  57635 			break
  57636 		}
  57637 		v2 = dst + uintptr(i*int32(4))
  57638 		v3 = int32(**(**uint8_t)(__ccgo_up(y5 + uintptr(i))))
  57639 		v4 = int32(**(**uint8_t)(__ccgo_up(u4 + uintptr(i))))
  57640 		v5 = int32(**(**uint8_t)(__ccgo_up(v6 + uintptr(i))))
  57641 		v61 = v2
  57642 		v9 = v3 * int32(19077) >> int32(8)
  57643 		goto _10
  57644 	_10:
  57645 		v11 = v5 * int32(26149) >> int32(8)
  57646 		goto _12
  57647 	_12:
  57648 		v13 = v9 + v11 - int32(14234)
  57649 		if v13 & ^int32(YUV_MASK2) == 0 {
  57650 			v16 = v13 >> int32(YUV_FIX2)
  57651 		} else {
  57652 			if v13 < 0 {
  57653 				v17 = 0
  57654 			} else {
  57655 				v17 = int32(255)
  57656 			}
  57657 			v16 = v17
  57658 		}
  57659 		v14 = v16
  57660 		goto _15
  57661 	_15:
  57662 		v7 = v14
  57663 		goto _8
  57664 	_8:
  57665 		**(**uint8_t)(__ccgo_up(v61)) = uint8(v7)
  57666 		v20 = v3 * int32(19077) >> int32(8)
  57667 		goto _21
  57668 	_21:
  57669 		v22 = v4 * int32(6419) >> int32(8)
  57670 		goto _23
  57671 	_23:
  57672 		v24 = v5 * int32(13320) >> int32(8)
  57673 		goto _25
  57674 	_25:
  57675 		v26 = v20 - v22 - v24 + int32(8708)
  57676 		if v26 & ^int32(YUV_MASK2) == 0 {
  57677 			v29 = v26 >> int32(YUV_FIX2)
  57678 		} else {
  57679 			if v26 < 0 {
  57680 				v30 = 0
  57681 			} else {
  57682 				v30 = int32(255)
  57683 			}
  57684 			v29 = v30
  57685 		}
  57686 		v27 = v29
  57687 		goto _28
  57688 	_28:
  57689 		v18 = v27
  57690 		goto _19
  57691 	_19:
  57692 		**(**uint8_t)(__ccgo_up(v61 + 1)) = uint8(v18)
  57693 		v33 = v3 * int32(19077) >> int32(8)
  57694 		goto _34
  57695 	_34:
  57696 		v35 = v4 * int32(33050) >> int32(8)
  57697 		goto _36
  57698 	_36:
  57699 		v37 = v33 + v35 - int32(17685)
  57700 		if v37 & ^int32(YUV_MASK2) == 0 {
  57701 			v40 = v37 >> int32(YUV_FIX2)
  57702 		} else {
  57703 			if v37 < 0 {
  57704 				v41 = 0
  57705 			} else {
  57706 				v41 = int32(255)
  57707 			}
  57708 			v40 = v41
  57709 		}
  57710 		v38 = v40
  57711 		goto _39
  57712 	_39:
  57713 		v31 = v38
  57714 		goto _32
  57715 	_32:
  57716 		**(**uint8_t)(__ccgo_up(v61 + 2)) = uint8(v31)
  57717 		**(**uint8_t)(__ccgo_up(v2 + 3)) = uint8(0xff)
  57718 		goto _1
  57719 	_1:
  57720 		;
  57721 		i = i + 1
  57722 	}
  57723 }
  57724 
  57725 func WebPYuv444ToBgra_C(tls *libc.TLS, y5 uintptr, u4 uintptr, v6 uintptr, dst uintptr, len1 int32) {
  57726 	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
  57727 	var v2, v61 uintptr
  57728 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  57729 	i = 0
  57730 	for {
  57731 		if !(i < len1) {
  57732 			break
  57733 		}
  57734 		v2 = dst + uintptr(i*int32(4))
  57735 		v3 = int32(**(**uint8_t)(__ccgo_up(y5 + uintptr(i))))
  57736 		v4 = int32(**(**uint8_t)(__ccgo_up(u4 + uintptr(i))))
  57737 		v5 = int32(**(**uint8_t)(__ccgo_up(v6 + uintptr(i))))
  57738 		v61 = v2
  57739 		v9 = v3 * int32(19077) >> int32(8)
  57740 		goto _10
  57741 	_10:
  57742 		v11 = v4 * int32(33050) >> int32(8)
  57743 		goto _12
  57744 	_12:
  57745 		v13 = v9 + v11 - int32(17685)
  57746 		if v13 & ^int32(YUV_MASK2) == 0 {
  57747 			v16 = v13 >> int32(YUV_FIX2)
  57748 		} else {
  57749 			if v13 < 0 {
  57750 				v17 = 0
  57751 			} else {
  57752 				v17 = int32(255)
  57753 			}
  57754 			v16 = v17
  57755 		}
  57756 		v14 = v16
  57757 		goto _15
  57758 	_15:
  57759 		v7 = v14
  57760 		goto _8
  57761 	_8:
  57762 		**(**uint8_t)(__ccgo_up(v61)) = uint8(v7)
  57763 		v20 = v3 * int32(19077) >> int32(8)
  57764 		goto _21
  57765 	_21:
  57766 		v22 = v4 * int32(6419) >> int32(8)
  57767 		goto _23
  57768 	_23:
  57769 		v24 = v5 * int32(13320) >> int32(8)
  57770 		goto _25
  57771 	_25:
  57772 		v26 = v20 - v22 - v24 + int32(8708)
  57773 		if v26 & ^int32(YUV_MASK2) == 0 {
  57774 			v29 = v26 >> int32(YUV_FIX2)
  57775 		} else {
  57776 			if v26 < 0 {
  57777 				v30 = 0
  57778 			} else {
  57779 				v30 = int32(255)
  57780 			}
  57781 			v29 = v30
  57782 		}
  57783 		v27 = v29
  57784 		goto _28
  57785 	_28:
  57786 		v18 = v27
  57787 		goto _19
  57788 	_19:
  57789 		**(**uint8_t)(__ccgo_up(v61 + 1)) = uint8(v18)
  57790 		v33 = v3 * int32(19077) >> int32(8)
  57791 		goto _34
  57792 	_34:
  57793 		v35 = v5 * int32(26149) >> int32(8)
  57794 		goto _36
  57795 	_36:
  57796 		v37 = v33 + v35 - int32(14234)
  57797 		if v37 & ^int32(YUV_MASK2) == 0 {
  57798 			v40 = v37 >> int32(YUV_FIX2)
  57799 		} else {
  57800 			if v37 < 0 {
  57801 				v41 = 0
  57802 			} else {
  57803 				v41 = int32(255)
  57804 			}
  57805 			v40 = v41
  57806 		}
  57807 		v38 = v40
  57808 		goto _39
  57809 	_39:
  57810 		v31 = v38
  57811 		goto _32
  57812 	_32:
  57813 		**(**uint8_t)(__ccgo_up(v61 + 2)) = uint8(v31)
  57814 		**(**uint8_t)(__ccgo_up(v2 + 3)) = uint8(0xff)
  57815 		goto _1
  57816 	_1:
  57817 		;
  57818 		i = i + 1
  57819 	}
  57820 }
  57821 
  57822 func WebPYuv444ToRgb_C(tls *libc.TLS, y4 uintptr, u3 uintptr, v5 uintptr, dst uintptr, len1 int32) {
  57823 	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
  57824 	var v51 uintptr
  57825 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  57826 	i = 0
  57827 	for {
  57828 		if !(i < len1) {
  57829 			break
  57830 		}
  57831 		v2 = int32(**(**uint8_t)(__ccgo_up(y4 + uintptr(i))))
  57832 		v3 = int32(**(**uint8_t)(__ccgo_up(u3 + uintptr(i))))
  57833 		v4 = int32(**(**uint8_t)(__ccgo_up(v5 + uintptr(i))))
  57834 		v51 = dst + uintptr(i*int32(3))
  57835 		v8 = v2 * int32(19077) >> int32(8)
  57836 		goto _9
  57837 	_9:
  57838 		v10 = v4 * int32(26149) >> int32(8)
  57839 		goto _11
  57840 	_11:
  57841 		v12 = v8 + v10 - int32(14234)
  57842 		if v12 & ^int32(YUV_MASK2) == 0 {
  57843 			v15 = v12 >> int32(YUV_FIX2)
  57844 		} else {
  57845 			if v12 < 0 {
  57846 				v16 = 0
  57847 			} else {
  57848 				v16 = int32(255)
  57849 			}
  57850 			v15 = v16
  57851 		}
  57852 		v13 = v15
  57853 		goto _14
  57854 	_14:
  57855 		v6 = v13
  57856 		goto _7
  57857 	_7:
  57858 		**(**uint8_t)(__ccgo_up(v51)) = uint8(v6)
  57859 		v19 = v2 * int32(19077) >> int32(8)
  57860 		goto _20
  57861 	_20:
  57862 		v21 = v3 * int32(6419) >> int32(8)
  57863 		goto _22
  57864 	_22:
  57865 		v23 = v4 * int32(13320) >> int32(8)
  57866 		goto _24
  57867 	_24:
  57868 		v25 = v19 - v21 - v23 + int32(8708)
  57869 		if v25 & ^int32(YUV_MASK2) == 0 {
  57870 			v28 = v25 >> int32(YUV_FIX2)
  57871 		} else {
  57872 			if v25 < 0 {
  57873 				v29 = 0
  57874 			} else {
  57875 				v29 = int32(255)
  57876 			}
  57877 			v28 = v29
  57878 		}
  57879 		v26 = v28
  57880 		goto _27
  57881 	_27:
  57882 		v17 = v26
  57883 		goto _18
  57884 	_18:
  57885 		**(**uint8_t)(__ccgo_up(v51 + 1)) = uint8(v17)
  57886 		v32 = v2 * int32(19077) >> int32(8)
  57887 		goto _33
  57888 	_33:
  57889 		v34 = v3 * int32(33050) >> int32(8)
  57890 		goto _35
  57891 	_35:
  57892 		v36 = v32 + v34 - int32(17685)
  57893 		if v36 & ^int32(YUV_MASK2) == 0 {
  57894 			v39 = v36 >> int32(YUV_FIX2)
  57895 		} else {
  57896 			if v36 < 0 {
  57897 				v40 = 0
  57898 			} else {
  57899 				v40 = int32(255)
  57900 			}
  57901 			v39 = v40
  57902 		}
  57903 		v37 = v39
  57904 		goto _38
  57905 	_38:
  57906 		v30 = v37
  57907 		goto _31
  57908 	_31:
  57909 		**(**uint8_t)(__ccgo_up(v51 + 2)) = uint8(v30)
  57910 		goto _1
  57911 	_1:
  57912 		;
  57913 		i = i + 1
  57914 	}
  57915 }
  57916 
  57917 func WebPYuv444ToBgr_C(tls *libc.TLS, y4 uintptr, u3 uintptr, v5 uintptr, dst uintptr, len1 int32) {
  57918 	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
  57919 	var v51 uintptr
  57920 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  57921 	i = 0
  57922 	for {
  57923 		if !(i < len1) {
  57924 			break
  57925 		}
  57926 		v2 = int32(**(**uint8_t)(__ccgo_up(y4 + uintptr(i))))
  57927 		v3 = int32(**(**uint8_t)(__ccgo_up(u3 + uintptr(i))))
  57928 		v4 = int32(**(**uint8_t)(__ccgo_up(v5 + uintptr(i))))
  57929 		v51 = dst + uintptr(i*int32(3))
  57930 		v8 = v2 * int32(19077) >> int32(8)
  57931 		goto _9
  57932 	_9:
  57933 		v10 = v3 * int32(33050) >> int32(8)
  57934 		goto _11
  57935 	_11:
  57936 		v12 = v8 + v10 - int32(17685)
  57937 		if v12 & ^int32(YUV_MASK2) == 0 {
  57938 			v15 = v12 >> int32(YUV_FIX2)
  57939 		} else {
  57940 			if v12 < 0 {
  57941 				v16 = 0
  57942 			} else {
  57943 				v16 = int32(255)
  57944 			}
  57945 			v15 = v16
  57946 		}
  57947 		v13 = v15
  57948 		goto _14
  57949 	_14:
  57950 		v6 = v13
  57951 		goto _7
  57952 	_7:
  57953 		**(**uint8_t)(__ccgo_up(v51)) = uint8(v6)
  57954 		v19 = v2 * int32(19077) >> int32(8)
  57955 		goto _20
  57956 	_20:
  57957 		v21 = v3 * int32(6419) >> int32(8)
  57958 		goto _22
  57959 	_22:
  57960 		v23 = v4 * int32(13320) >> int32(8)
  57961 		goto _24
  57962 	_24:
  57963 		v25 = v19 - v21 - v23 + int32(8708)
  57964 		if v25 & ^int32(YUV_MASK2) == 0 {
  57965 			v28 = v25 >> int32(YUV_FIX2)
  57966 		} else {
  57967 			if v25 < 0 {
  57968 				v29 = 0
  57969 			} else {
  57970 				v29 = int32(255)
  57971 			}
  57972 			v28 = v29
  57973 		}
  57974 		v26 = v28
  57975 		goto _27
  57976 	_27:
  57977 		v17 = v26
  57978 		goto _18
  57979 	_18:
  57980 		**(**uint8_t)(__ccgo_up(v51 + 1)) = uint8(v17)
  57981 		v32 = v2 * int32(19077) >> int32(8)
  57982 		goto _33
  57983 	_33:
  57984 		v34 = v4 * int32(26149) >> int32(8)
  57985 		goto _35
  57986 	_35:
  57987 		v36 = v32 + v34 - int32(14234)
  57988 		if v36 & ^int32(YUV_MASK2) == 0 {
  57989 			v39 = v36 >> int32(YUV_FIX2)
  57990 		} else {
  57991 			if v36 < 0 {
  57992 				v40 = 0
  57993 			} else {
  57994 				v40 = int32(255)
  57995 			}
  57996 			v39 = v40
  57997 		}
  57998 		v37 = v39
  57999 		goto _38
  58000 	_38:
  58001 		v30 = v37
  58002 		goto _31
  58003 	_31:
  58004 		**(**uint8_t)(__ccgo_up(v51 + 2)) = uint8(v30)
  58005 		goto _1
  58006 	_1:
  58007 		;
  58008 		i = i + 1
  58009 	}
  58010 }
  58011 
  58012 func WebPYuv444ToArgb_C(tls *libc.TLS, y5 uintptr, u4 uintptr, v6 uintptr, dst uintptr, len1 int32) {
  58013 	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
  58014 	var v2, v61 uintptr
  58015 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  58016 	i = 0
  58017 	for {
  58018 		if !(i < len1) {
  58019 			break
  58020 		}
  58021 		v2 = dst + uintptr(i*int32(4))
  58022 		**(**uint8_t)(__ccgo_up(v2)) = uint8(0xff)
  58023 		v3 = int32(**(**uint8_t)(__ccgo_up(y5 + uintptr(i))))
  58024 		v4 = int32(**(**uint8_t)(__ccgo_up(u4 + uintptr(i))))
  58025 		v5 = int32(**(**uint8_t)(__ccgo_up(v6 + uintptr(i))))
  58026 		v61 = v2 + uintptr(1)
  58027 		v9 = v3 * int32(19077) >> int32(8)
  58028 		goto _10
  58029 	_10:
  58030 		v11 = v5 * int32(26149) >> int32(8)
  58031 		goto _12
  58032 	_12:
  58033 		v13 = v9 + v11 - int32(14234)
  58034 		if v13 & ^int32(YUV_MASK2) == 0 {
  58035 			v16 = v13 >> int32(YUV_FIX2)
  58036 		} else {
  58037 			if v13 < 0 {
  58038 				v17 = 0
  58039 			} else {
  58040 				v17 = int32(255)
  58041 			}
  58042 			v16 = v17
  58043 		}
  58044 		v14 = v16
  58045 		goto _15
  58046 	_15:
  58047 		v7 = v14
  58048 		goto _8
  58049 	_8:
  58050 		**(**uint8_t)(__ccgo_up(v61)) = uint8(v7)
  58051 		v20 = v3 * int32(19077) >> int32(8)
  58052 		goto _21
  58053 	_21:
  58054 		v22 = v4 * int32(6419) >> int32(8)
  58055 		goto _23
  58056 	_23:
  58057 		v24 = v5 * int32(13320) >> int32(8)
  58058 		goto _25
  58059 	_25:
  58060 		v26 = v20 - v22 - v24 + int32(8708)
  58061 		if v26 & ^int32(YUV_MASK2) == 0 {
  58062 			v29 = v26 >> int32(YUV_FIX2)
  58063 		} else {
  58064 			if v26 < 0 {
  58065 				v30 = 0
  58066 			} else {
  58067 				v30 = int32(255)
  58068 			}
  58069 			v29 = v30
  58070 		}
  58071 		v27 = v29
  58072 		goto _28
  58073 	_28:
  58074 		v18 = v27
  58075 		goto _19
  58076 	_19:
  58077 		**(**uint8_t)(__ccgo_up(v61 + 1)) = uint8(v18)
  58078 		v33 = v3 * int32(19077) >> int32(8)
  58079 		goto _34
  58080 	_34:
  58081 		v35 = v4 * int32(33050) >> int32(8)
  58082 		goto _36
  58083 	_36:
  58084 		v37 = v33 + v35 - int32(17685)
  58085 		if v37 & ^int32(YUV_MASK2) == 0 {
  58086 			v40 = v37 >> int32(YUV_FIX2)
  58087 		} else {
  58088 			if v37 < 0 {
  58089 				v41 = 0
  58090 			} else {
  58091 				v41 = int32(255)
  58092 			}
  58093 			v40 = v41
  58094 		}
  58095 		v38 = v40
  58096 		goto _39
  58097 	_39:
  58098 		v31 = v38
  58099 		goto _32
  58100 	_32:
  58101 		**(**uint8_t)(__ccgo_up(v61 + 2)) = uint8(v31)
  58102 		goto _1
  58103 	_1:
  58104 		;
  58105 		i = i + 1
  58106 	}
  58107 }
  58108 
  58109 func WebPYuv444ToRgba4444_C(tls *libc.TLS, y4 uintptr, u3 uintptr, v5 uintptr, dst uintptr, len1 int32) {
  58110 	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
  58111 	var v51 uintptr
  58112 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  58113 	i = 0
  58114 	for {
  58115 		if !(i < len1) {
  58116 			break
  58117 		}
  58118 		v2 = int32(**(**uint8_t)(__ccgo_up(y4 + uintptr(i))))
  58119 		v3 = int32(**(**uint8_t)(__ccgo_up(u3 + uintptr(i))))
  58120 		v4 = int32(**(**uint8_t)(__ccgo_up(v5 + uintptr(i))))
  58121 		v51 = dst + uintptr(i*int32(2))
  58122 		v8 = v2 * int32(19077) >> int32(8)
  58123 		goto _9
  58124 	_9:
  58125 		v10 = v4 * int32(26149) >> int32(8)
  58126 		goto _11
  58127 	_11:
  58128 		v12 = v8 + v10 - int32(14234)
  58129 		if v12 & ^int32(YUV_MASK2) == 0 {
  58130 			v15 = v12 >> int32(YUV_FIX2)
  58131 		} else {
  58132 			if v12 < 0 {
  58133 				v16 = 0
  58134 			} else {
  58135 				v16 = int32(255)
  58136 			}
  58137 			v15 = v16
  58138 		}
  58139 		v13 = v15
  58140 		goto _14
  58141 	_14:
  58142 		v6 = v13
  58143 		goto _7
  58144 	_7:
  58145 		r = v6
  58146 		v19 = v2 * int32(19077) >> int32(8)
  58147 		goto _20
  58148 	_20:
  58149 		v21 = v3 * int32(6419) >> int32(8)
  58150 		goto _22
  58151 	_22:
  58152 		v23 = v4 * int32(13320) >> int32(8)
  58153 		goto _24
  58154 	_24:
  58155 		v25 = v19 - v21 - v23 + int32(8708)
  58156 		if v25 & ^int32(YUV_MASK2) == 0 {
  58157 			v28 = v25 >> int32(YUV_FIX2)
  58158 		} else {
  58159 			if v25 < 0 {
  58160 				v29 = 0
  58161 			} else {
  58162 				v29 = int32(255)
  58163 			}
  58164 			v28 = v29
  58165 		}
  58166 		v26 = v28
  58167 		goto _27
  58168 	_27:
  58169 		v17 = v26
  58170 		goto _18
  58171 	_18:
  58172 		g = v17
  58173 		v32 = v2 * int32(19077) >> int32(8)
  58174 		goto _33
  58175 	_33:
  58176 		v34 = v3 * int32(33050) >> int32(8)
  58177 		goto _35
  58178 	_35:
  58179 		v36 = v32 + v34 - int32(17685)
  58180 		if v36 & ^int32(YUV_MASK2) == 0 {
  58181 			v39 = v36 >> int32(YUV_FIX2)
  58182 		} else {
  58183 			if v36 < 0 {
  58184 				v40 = 0
  58185 			} else {
  58186 				v40 = int32(255)
  58187 			}
  58188 			v39 = v40
  58189 		}
  58190 		v37 = v39
  58191 		goto _38
  58192 	_38:
  58193 		v30 = v37
  58194 		goto _31
  58195 	_31:
  58196 		b = v30
  58197 		rg = r&int32(0xf0) | g>>libc.Int32FromInt32(4)
  58198 		ba = b&int32(0xf0) | int32(0x0f)
  58199 		**(**uint8_t)(__ccgo_up(v51)) = uint8(rg)
  58200 		**(**uint8_t)(__ccgo_up(v51 + 1)) = uint8(ba)
  58201 		goto _1
  58202 	_1:
  58203 		;
  58204 		i = i + 1
  58205 	}
  58206 }
  58207 
  58208 func WebPYuv444ToRgb565_C(tls *libc.TLS, y4 uintptr, u3 uintptr, v5 uintptr, dst uintptr, len1 int32) {
  58209 	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
  58210 	var v51 uintptr
  58211 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  58212 	i = 0
  58213 	for {
  58214 		if !(i < len1) {
  58215 			break
  58216 		}
  58217 		v2 = int32(**(**uint8_t)(__ccgo_up(y4 + uintptr(i))))
  58218 		v3 = int32(**(**uint8_t)(__ccgo_up(u3 + uintptr(i))))
  58219 		v4 = int32(**(**uint8_t)(__ccgo_up(v5 + uintptr(i))))
  58220 		v51 = dst + uintptr(i*int32(2))
  58221 		v8 = v2 * int32(19077) >> int32(8)
  58222 		goto _9
  58223 	_9:
  58224 		v10 = v4 * int32(26149) >> int32(8)
  58225 		goto _11
  58226 	_11:
  58227 		v12 = v8 + v10 - int32(14234)
  58228 		if v12 & ^int32(YUV_MASK2) == 0 {
  58229 			v15 = v12 >> int32(YUV_FIX2)
  58230 		} else {
  58231 			if v12 < 0 {
  58232 				v16 = 0
  58233 			} else {
  58234 				v16 = int32(255)
  58235 			}
  58236 			v15 = v16
  58237 		}
  58238 		v13 = v15
  58239 		goto _14
  58240 	_14:
  58241 		v6 = v13
  58242 		goto _7
  58243 	_7:
  58244 		r = v6
  58245 		v19 = v2 * int32(19077) >> int32(8)
  58246 		goto _20
  58247 	_20:
  58248 		v21 = v3 * int32(6419) >> int32(8)
  58249 		goto _22
  58250 	_22:
  58251 		v23 = v4 * int32(13320) >> int32(8)
  58252 		goto _24
  58253 	_24:
  58254 		v25 = v19 - v21 - v23 + int32(8708)
  58255 		if v25 & ^int32(YUV_MASK2) == 0 {
  58256 			v28 = v25 >> int32(YUV_FIX2)
  58257 		} else {
  58258 			if v25 < 0 {
  58259 				v29 = 0
  58260 			} else {
  58261 				v29 = int32(255)
  58262 			}
  58263 			v28 = v29
  58264 		}
  58265 		v26 = v28
  58266 		goto _27
  58267 	_27:
  58268 		v17 = v26
  58269 		goto _18
  58270 	_18:
  58271 		g = v17
  58272 		v32 = v2 * int32(19077) >> int32(8)
  58273 		goto _33
  58274 	_33:
  58275 		v34 = v3 * int32(33050) >> int32(8)
  58276 		goto _35
  58277 	_35:
  58278 		v36 = v32 + v34 - int32(17685)
  58279 		if v36 & ^int32(YUV_MASK2) == 0 {
  58280 			v39 = v36 >> int32(YUV_FIX2)
  58281 		} else {
  58282 			if v36 < 0 {
  58283 				v40 = 0
  58284 			} else {
  58285 				v40 = int32(255)
  58286 			}
  58287 			v39 = v40
  58288 		}
  58289 		v37 = v39
  58290 		goto _38
  58291 	_38:
  58292 		v30 = v37
  58293 		goto _31
  58294 	_31:
  58295 		b = v30
  58296 		rg = r&int32(0xf8) | g>>libc.Int32FromInt32(5)
  58297 		gb = g<<libc.Int32FromInt32(3)&int32(0xe0) | b>>libc.Int32FromInt32(3)
  58298 		**(**uint8_t)(__ccgo_up(v51)) = uint8(rg)
  58299 		**(**uint8_t)(__ccgo_up(v51 + 1)) = uint8(gb)
  58300 		goto _1
  58301 	_1:
  58302 		;
  58303 		i = i + 1
  58304 	}
  58305 }
  58306 
  58307 func WebPInitYUV444Converters(tls *libc.TLS) {
  58308 	if libc.AtomicLoadPUintptr(uintptr(unsafe.Pointer(&WebPInitYUV444Converters_body_last_cpuinfo_used))) == VP8GetCPUInfo {
  58309 		goto _1
  58310 	}
  58311 	WebPInitYUV444Converters_body(tls)
  58312 	libc.AtomicStorePUintptr(uintptr(unsafe.Pointer(&WebPInitYUV444Converters_body_last_cpuinfo_used)), VP8GetCPUInfo)
  58313 	goto _2
  58314 _2:
  58315 	;
  58316 	goto _1
  58317 _1: /**/ //
  58318 }
  58319 
  58320 var WebPInitYUV444Converters_body_last_cpuinfo_used = uintptr(0)
  58321 
  58322 func init() {
  58323 	p := unsafe.Pointer(&WebPInitYUV444Converters_body_last_cpuinfo_used)
  58324 	*(*uintptr)(unsafe.Add(p, 0)) = uintptr(unsafe.Pointer(&WebPInitYUV444Converters_body_last_cpuinfo_used))
  58325 }
  58326 
  58327 func WebPInitYUV444Converters_body(tls *libc.TLS) {
  58328 	WebPYUV444Converters[int32(MODE_RGBA)] = __ccgo_fp(WebPYuv444ToRgba_C)
  58329 	WebPYUV444Converters[int32(MODE_BGRA)] = __ccgo_fp(WebPYuv444ToBgra_C)
  58330 	WebPYUV444Converters[int32(MODE_RGB)] = __ccgo_fp(WebPYuv444ToRgb_C)
  58331 	WebPYUV444Converters[int32(MODE_BGR)] = __ccgo_fp(WebPYuv444ToBgr_C)
  58332 	WebPYUV444Converters[int32(MODE_ARGB)] = __ccgo_fp(WebPYuv444ToArgb_C)
  58333 	WebPYUV444Converters[int32(MODE_RGBA_4444)] = __ccgo_fp(WebPYuv444ToRgba4444_C)
  58334 	WebPYUV444Converters[int32(MODE_RGB_565)] = __ccgo_fp(WebPYuv444ToRgb565_C)
  58335 	WebPYUV444Converters[int32(MODE_rgbA)] = __ccgo_fp(WebPYuv444ToRgba_C)
  58336 	WebPYUV444Converters[int32(MODE_bgrA)] = __ccgo_fp(WebPYuv444ToBgra_C)
  58337 	WebPYUV444Converters[int32(MODE_Argb)] = __ccgo_fp(WebPYuv444ToArgb_C)
  58338 	WebPYUV444Converters[int32(MODE_rgbA_4444)] = __ccgo_fp(WebPYuv444ToRgba4444_C)
  58339 	if VP8GetCPUInfo != libc.UintptrFromInt32(0) {
  58340 	}
  58341 }
  58342 
  58343 func WebPInitUpsamplers(tls *libc.TLS) {
  58344 	if libc.AtomicLoadPUintptr(uintptr(unsafe.Pointer(&WebPInitUpsamplers_body_last_cpuinfo_used))) == VP8GetCPUInfo {
  58345 		goto _1
  58346 	}
  58347 	WebPInitUpsamplers_body(tls)
  58348 	libc.AtomicStorePUintptr(uintptr(unsafe.Pointer(&WebPInitUpsamplers_body_last_cpuinfo_used)), VP8GetCPUInfo)
  58349 	goto _2
  58350 _2:
  58351 	;
  58352 	goto _1
  58353 _1: /**/ //
  58354 }
  58355 
  58356 var WebPInitUpsamplers_body_last_cpuinfo_used = uintptr(0)
  58357 
  58358 func init() {
  58359 	p := unsafe.Pointer(&WebPInitUpsamplers_body_last_cpuinfo_used)
  58360 	*(*uintptr)(unsafe.Add(p, 0)) = uintptr(unsafe.Pointer(&WebPInitUpsamplers_body_last_cpuinfo_used))
  58361 }
  58362 
  58363 func WebPInitUpsamplers_body(tls *libc.TLS) {
  58364 	WebPUpsamplers[int32(MODE_RGBA)] = __ccgo_fp(UpsampleRgbaLinePair_C)
  58365 	WebPUpsamplers[int32(MODE_BGRA)] = __ccgo_fp(UpsampleBgraLinePair_C)
  58366 	WebPUpsamplers[int32(MODE_rgbA)] = __ccgo_fp(UpsampleRgbaLinePair_C)
  58367 	WebPUpsamplers[int32(MODE_bgrA)] = __ccgo_fp(UpsampleBgraLinePair_C)
  58368 	WebPUpsamplers[int32(MODE_RGB)] = __ccgo_fp(UpsampleRgbLinePair_C)
  58369 	WebPUpsamplers[int32(MODE_BGR)] = __ccgo_fp(UpsampleBgrLinePair_C)
  58370 	WebPUpsamplers[int32(MODE_ARGB)] = __ccgo_fp(UpsampleArgbLinePair_C)
  58371 	WebPUpsamplers[int32(MODE_RGBA_4444)] = __ccgo_fp(UpsampleRgba4444LinePair_C)
  58372 	WebPUpsamplers[int32(MODE_RGB_565)] = __ccgo_fp(UpsampleRgb565LinePair_C)
  58373 	WebPUpsamplers[int32(MODE_Argb)] = __ccgo_fp(UpsampleArgbLinePair_C)
  58374 	WebPUpsamplers[int32(MODE_rgbA_4444)] = __ccgo_fp(UpsampleRgba4444LinePair_C)
  58375 	// If defined, use CPUInfo() to overwrite some pointers with faster versions.
  58376 	if VP8GetCPUInfo != libc.UintptrFromInt32(0) {
  58377 	}
  58378 }
  58379 
  58380 func WebPInitYUV444ConvertersMIPSdspR2(tls *libc.TLS) {
  58381 }
  58382 
  58383 func WebPInitUpsamplersMIPSdspR2(tls *libc.TLS) {
  58384 }
  58385 
  58386 func WebPInitUpsamplersMSA(tls *libc.TLS) {
  58387 }
  58388 
  58389 func WebPInitUpsamplersNEON(tls *libc.TLS) {
  58390 }
  58391 
  58392 func WebPInitYUV444ConvertersSSE2(tls *libc.TLS) {
  58393 }
  58394 
  58395 func WebPInitUpsamplersSSE2(tls *libc.TLS) {
  58396 }
  58397 
  58398 func WebPInitYUV444ConvertersSSE41(tls *libc.TLS) {
  58399 }
  58400 
  58401 func WebPInitUpsamplersSSE41(tls *libc.TLS) {
  58402 }
  58403 
  58404 const SIZE_MAX32 = "_UI64_MAX"
  58405 
  58406 // Copyright 2010 Google Inc. All Rights Reserved.
  58407 //
  58408 // Use of this source code is governed by a BSD-style license
  58409 // that can be found in the COPYING file in the root of the source
  58410 // tree. An additional intellectual property rights grant can be found
  58411 // in the file PATENTS. All contributing project authors may
  58412 // be found in the AUTHORS file in the root of the source tree.
  58413 // -----------------------------------------------------------------------------
  58414 //
  58415 //  Main decoding functions for WebP images.
  58416 //
  58417 // Author: Skal (pascal.massimino@gmail.com)
  58418 
  58419 //-----------------------------------------------------------------------------
  58420 // Plain-C version
  58421 
  58422 // C documentation
  58423 //
  58424 //	// All variants implemented.
  58425 func YuvToRgbRow(tls *libc.TLS, y4 uintptr, u3 uintptr, v5 uintptr, dst uintptr, len1 int32) {
  58426 	var end, v4 uintptr
  58427 	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
  58428 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  58429 	end = dst + uintptr(len1 & ^libc.Int32FromInt32(1) * int32(3))
  58430 	for dst != end {
  58431 		v1 = int32(**(**uint8_t)(__ccgo_up(y4)))
  58432 		v2 = int32(**(**uint8_t)(__ccgo_up(u3)))
  58433 		v3 = int32(**(**uint8_t)(__ccgo_up(v5)))
  58434 		v4 = dst
  58435 		v7 = v1 * int32(19077) >> int32(8)
  58436 		goto _8
  58437 	_8:
  58438 		v9 = v3 * int32(26149) >> int32(8)
  58439 		goto _10
  58440 	_10:
  58441 		v11 = v7 + v9 - int32(14234)
  58442 		if v11 & ^int32(YUV_MASK2) == 0 {
  58443 			v14 = v11 >> int32(YUV_FIX2)
  58444 		} else {
  58445 			if v11 < 0 {
  58446 				v15 = 0
  58447 			} else {
  58448 				v15 = int32(255)
  58449 			}
  58450 			v14 = v15
  58451 		}
  58452 		v12 = v14
  58453 		goto _13
  58454 	_13:
  58455 		v51 = v12
  58456 		goto _6
  58457 	_6:
  58458 		**(**uint8_t)(__ccgo_up(v4)) = uint8(v51)
  58459 		v18 = v1 * int32(19077) >> int32(8)
  58460 		goto _19
  58461 	_19:
  58462 		v20 = v2 * int32(6419) >> int32(8)
  58463 		goto _21
  58464 	_21:
  58465 		v22 = v3 * int32(13320) >> int32(8)
  58466 		goto _23
  58467 	_23:
  58468 		v24 = v18 - v20 - v22 + int32(8708)
  58469 		if v24 & ^int32(YUV_MASK2) == 0 {
  58470 			v27 = v24 >> int32(YUV_FIX2)
  58471 		} else {
  58472 			if v24 < 0 {
  58473 				v28 = 0
  58474 			} else {
  58475 				v28 = int32(255)
  58476 			}
  58477 			v27 = v28
  58478 		}
  58479 		v25 = v27
  58480 		goto _26
  58481 	_26:
  58482 		v16 = v25
  58483 		goto _17
  58484 	_17:
  58485 		**(**uint8_t)(__ccgo_up(v4 + 1)) = uint8(v16)
  58486 		v31 = v1 * int32(19077) >> int32(8)
  58487 		goto _32
  58488 	_32:
  58489 		v33 = v2 * int32(33050) >> int32(8)
  58490 		goto _34
  58491 	_34:
  58492 		v35 = v31 + v33 - int32(17685)
  58493 		if v35 & ^int32(YUV_MASK2) == 0 {
  58494 			v38 = v35 >> int32(YUV_FIX2)
  58495 		} else {
  58496 			if v35 < 0 {
  58497 				v39 = 0
  58498 			} else {
  58499 				v39 = int32(255)
  58500 			}
  58501 			v38 = v39
  58502 		}
  58503 		v36 = v38
  58504 		goto _37
  58505 	_37:
  58506 		v29 = v36
  58507 		goto _30
  58508 	_30:
  58509 		**(**uint8_t)(__ccgo_up(v4 + 2)) = uint8(v29)
  58510 		v1 = int32(**(**uint8_t)(__ccgo_up(y4 + 1)))
  58511 		v2 = int32(**(**uint8_t)(__ccgo_up(u3)))
  58512 		v3 = int32(**(**uint8_t)(__ccgo_up(v5)))
  58513 		v4 = dst + uintptr(libc.Int32FromInt32(3))
  58514 		v7 = v1 * int32(19077) >> int32(8)
  58515 		goto _47
  58516 	_47:
  58517 		v9 = v3 * int32(26149) >> int32(8)
  58518 		goto _49
  58519 	_49:
  58520 		v11 = v7 + v9 - int32(14234)
  58521 		if v11 & ^int32(YUV_MASK2) == 0 {
  58522 			v14 = v11 >> int32(YUV_FIX2)
  58523 		} else {
  58524 			if v11 < 0 {
  58525 				v15 = 0
  58526 			} else {
  58527 				v15 = int32(255)
  58528 			}
  58529 			v14 = v15
  58530 		}
  58531 		v12 = v14
  58532 		goto _52
  58533 	_52:
  58534 		v51 = v12
  58535 		goto _45
  58536 	_45:
  58537 		**(**uint8_t)(__ccgo_up(v4)) = uint8(v51)
  58538 		v18 = v1 * int32(19077) >> int32(8)
  58539 		goto _58
  58540 	_58:
  58541 		v20 = v2 * int32(6419) >> int32(8)
  58542 		goto _60
  58543 	_60:
  58544 		v22 = v3 * int32(13320) >> int32(8)
  58545 		goto _62
  58546 	_62:
  58547 		v24 = v18 - v20 - v22 + int32(8708)
  58548 		if v24 & ^int32(YUV_MASK2) == 0 {
  58549 			v27 = v24 >> int32(YUV_FIX2)
  58550 		} else {
  58551 			if v24 < 0 {
  58552 				v28 = 0
  58553 			} else {
  58554 				v28 = int32(255)
  58555 			}
  58556 			v27 = v28
  58557 		}
  58558 		v25 = v27
  58559 		goto _65
  58560 	_65:
  58561 		v16 = v25
  58562 		goto _56
  58563 	_56:
  58564 		**(**uint8_t)(__ccgo_up(v4 + 1)) = uint8(v16)
  58565 		v31 = v1 * int32(19077) >> int32(8)
  58566 		goto _71
  58567 	_71:
  58568 		v33 = v2 * int32(33050) >> int32(8)
  58569 		goto _73
  58570 	_73:
  58571 		v35 = v31 + v33 - int32(17685)
  58572 		if v35 & ^int32(YUV_MASK2) == 0 {
  58573 			v38 = v35 >> int32(YUV_FIX2)
  58574 		} else {
  58575 			if v35 < 0 {
  58576 				v39 = 0
  58577 			} else {
  58578 				v39 = int32(255)
  58579 			}
  58580 			v38 = v39
  58581 		}
  58582 		v36 = v38
  58583 		goto _76
  58584 	_76:
  58585 		v29 = v36
  58586 		goto _69
  58587 	_69:
  58588 		**(**uint8_t)(__ccgo_up(v4 + 2)) = uint8(v29)
  58589 		y4 = y4 + uintptr(2)
  58590 		u3 = u3 + 1
  58591 		v5 = v5 + 1
  58592 		dst = dst + uintptr(libc.Int32FromInt32(2)*libc.Int32FromInt32(3))
  58593 	}
  58594 	if len1&int32(1) != 0 {
  58595 		v1 = int32(**(**uint8_t)(__ccgo_up(y4)))
  58596 		v2 = int32(**(**uint8_t)(__ccgo_up(u3)))
  58597 		v3 = int32(**(**uint8_t)(__ccgo_up(v5)))
  58598 		v4 = dst
  58599 		v7 = v1 * int32(19077) >> int32(8)
  58600 		goto _86
  58601 	_86:
  58602 		v9 = v3 * int32(26149) >> int32(8)
  58603 		goto _88
  58604 	_88:
  58605 		v11 = v7 + v9 - int32(14234)
  58606 		if v11 & ^int32(YUV_MASK2) == 0 {
  58607 			v14 = v11 >> int32(YUV_FIX2)
  58608 		} else {
  58609 			if v11 < 0 {
  58610 				v15 = 0
  58611 			} else {
  58612 				v15 = int32(255)
  58613 			}
  58614 			v14 = v15
  58615 		}
  58616 		v12 = v14
  58617 		goto _91
  58618 	_91:
  58619 		v51 = v12
  58620 		goto _84
  58621 	_84:
  58622 		**(**uint8_t)(__ccgo_up(v4)) = uint8(v51)
  58623 		v18 = v1 * int32(19077) >> int32(8)
  58624 		goto _97
  58625 	_97:
  58626 		v20 = v2 * int32(6419) >> int32(8)
  58627 		goto _99
  58628 	_99:
  58629 		v22 = v3 * int32(13320) >> int32(8)
  58630 		goto _101
  58631 	_101:
  58632 		v24 = v18 - v20 - v22 + int32(8708)
  58633 		if v24 & ^int32(YUV_MASK2) == 0 {
  58634 			v27 = v24 >> int32(YUV_FIX2)
  58635 		} else {
  58636 			if v24 < 0 {
  58637 				v28 = 0
  58638 			} else {
  58639 				v28 = int32(255)
  58640 			}
  58641 			v27 = v28
  58642 		}
  58643 		v25 = v27
  58644 		goto _104
  58645 	_104:
  58646 		v16 = v25
  58647 		goto _95
  58648 	_95:
  58649 		**(**uint8_t)(__ccgo_up(v4 + 1)) = uint8(v16)
  58650 		v31 = v1 * int32(19077) >> int32(8)
  58651 		goto _110
  58652 	_110:
  58653 		v33 = v2 * int32(33050) >> int32(8)
  58654 		goto _112
  58655 	_112:
  58656 		v35 = v31 + v33 - int32(17685)
  58657 		if v35 & ^int32(YUV_MASK2) == 0 {
  58658 			v38 = v35 >> int32(YUV_FIX2)
  58659 		} else {
  58660 			if v35 < 0 {
  58661 				v39 = 0
  58662 			} else {
  58663 				v39 = int32(255)
  58664 			}
  58665 			v38 = v39
  58666 		}
  58667 		v36 = v38
  58668 		goto _115
  58669 	_115:
  58670 		v29 = v36
  58671 		goto _108
  58672 	_108:
  58673 		**(**uint8_t)(__ccgo_up(v4 + 2)) = uint8(v29)
  58674 	}
  58675 }
  58676 
  58677 func YuvToBgrRow(tls *libc.TLS, y4 uintptr, u3 uintptr, v5 uintptr, dst uintptr, len1 int32) {
  58678 	var end, v4 uintptr
  58679 	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
  58680 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  58681 	end = dst + uintptr(len1 & ^libc.Int32FromInt32(1) * int32(3))
  58682 	for dst != end {
  58683 		v1 = int32(**(**uint8_t)(__ccgo_up(y4)))
  58684 		v2 = int32(**(**uint8_t)(__ccgo_up(u3)))
  58685 		v3 = int32(**(**uint8_t)(__ccgo_up(v5)))
  58686 		v4 = dst
  58687 		v7 = v1 * int32(19077) >> int32(8)
  58688 		goto _8
  58689 	_8:
  58690 		v9 = v2 * int32(33050) >> int32(8)
  58691 		goto _10
  58692 	_10:
  58693 		v11 = v7 + v9 - int32(17685)
  58694 		if v11 & ^int32(YUV_MASK2) == 0 {
  58695 			v14 = v11 >> int32(YUV_FIX2)
  58696 		} else {
  58697 			if v11 < 0 {
  58698 				v15 = 0
  58699 			} else {
  58700 				v15 = int32(255)
  58701 			}
  58702 			v14 = v15
  58703 		}
  58704 		v12 = v14
  58705 		goto _13
  58706 	_13:
  58707 		v51 = v12
  58708 		goto _6
  58709 	_6:
  58710 		**(**uint8_t)(__ccgo_up(v4)) = uint8(v51)
  58711 		v18 = v1 * int32(19077) >> int32(8)
  58712 		goto _19
  58713 	_19:
  58714 		v20 = v2 * int32(6419) >> int32(8)
  58715 		goto _21
  58716 	_21:
  58717 		v22 = v3 * int32(13320) >> int32(8)
  58718 		goto _23
  58719 	_23:
  58720 		v24 = v18 - v20 - v22 + int32(8708)
  58721 		if v24 & ^int32(YUV_MASK2) == 0 {
  58722 			v27 = v24 >> int32(YUV_FIX2)
  58723 		} else {
  58724 			if v24 < 0 {
  58725 				v28 = 0
  58726 			} else {
  58727 				v28 = int32(255)
  58728 			}
  58729 			v27 = v28
  58730 		}
  58731 		v25 = v27
  58732 		goto _26
  58733 	_26:
  58734 		v16 = v25
  58735 		goto _17
  58736 	_17:
  58737 		**(**uint8_t)(__ccgo_up(v4 + 1)) = uint8(v16)
  58738 		v31 = v1 * int32(19077) >> int32(8)
  58739 		goto _32
  58740 	_32:
  58741 		v33 = v3 * int32(26149) >> int32(8)
  58742 		goto _34
  58743 	_34:
  58744 		v35 = v31 + v33 - int32(14234)
  58745 		if v35 & ^int32(YUV_MASK2) == 0 {
  58746 			v38 = v35 >> int32(YUV_FIX2)
  58747 		} else {
  58748 			if v35 < 0 {
  58749 				v39 = 0
  58750 			} else {
  58751 				v39 = int32(255)
  58752 			}
  58753 			v38 = v39
  58754 		}
  58755 		v36 = v38
  58756 		goto _37
  58757 	_37:
  58758 		v29 = v36
  58759 		goto _30
  58760 	_30:
  58761 		**(**uint8_t)(__ccgo_up(v4 + 2)) = uint8(v29)
  58762 		v1 = int32(**(**uint8_t)(__ccgo_up(y4 + 1)))
  58763 		v2 = int32(**(**uint8_t)(__ccgo_up(u3)))
  58764 		v3 = int32(**(**uint8_t)(__ccgo_up(v5)))
  58765 		v4 = dst + uintptr(libc.Int32FromInt32(3))
  58766 		v7 = v1 * int32(19077) >> int32(8)
  58767 		goto _47
  58768 	_47:
  58769 		v9 = v2 * int32(33050) >> int32(8)
  58770 		goto _49
  58771 	_49:
  58772 		v11 = v7 + v9 - int32(17685)
  58773 		if v11 & ^int32(YUV_MASK2) == 0 {
  58774 			v14 = v11 >> int32(YUV_FIX2)
  58775 		} else {
  58776 			if v11 < 0 {
  58777 				v15 = 0
  58778 			} else {
  58779 				v15 = int32(255)
  58780 			}
  58781 			v14 = v15
  58782 		}
  58783 		v12 = v14
  58784 		goto _52
  58785 	_52:
  58786 		v51 = v12
  58787 		goto _45
  58788 	_45:
  58789 		**(**uint8_t)(__ccgo_up(v4)) = uint8(v51)
  58790 		v18 = v1 * int32(19077) >> int32(8)
  58791 		goto _58
  58792 	_58:
  58793 		v20 = v2 * int32(6419) >> int32(8)
  58794 		goto _60
  58795 	_60:
  58796 		v22 = v3 * int32(13320) >> int32(8)
  58797 		goto _62
  58798 	_62:
  58799 		v24 = v18 - v20 - v22 + int32(8708)
  58800 		if v24 & ^int32(YUV_MASK2) == 0 {
  58801 			v27 = v24 >> int32(YUV_FIX2)
  58802 		} else {
  58803 			if v24 < 0 {
  58804 				v28 = 0
  58805 			} else {
  58806 				v28 = int32(255)
  58807 			}
  58808 			v27 = v28
  58809 		}
  58810 		v25 = v27
  58811 		goto _65
  58812 	_65:
  58813 		v16 = v25
  58814 		goto _56
  58815 	_56:
  58816 		**(**uint8_t)(__ccgo_up(v4 + 1)) = uint8(v16)
  58817 		v31 = v1 * int32(19077) >> int32(8)
  58818 		goto _71
  58819 	_71:
  58820 		v33 = v3 * int32(26149) >> int32(8)
  58821 		goto _73
  58822 	_73:
  58823 		v35 = v31 + v33 - int32(14234)
  58824 		if v35 & ^int32(YUV_MASK2) == 0 {
  58825 			v38 = v35 >> int32(YUV_FIX2)
  58826 		} else {
  58827 			if v35 < 0 {
  58828 				v39 = 0
  58829 			} else {
  58830 				v39 = int32(255)
  58831 			}
  58832 			v38 = v39
  58833 		}
  58834 		v36 = v38
  58835 		goto _76
  58836 	_76:
  58837 		v29 = v36
  58838 		goto _69
  58839 	_69:
  58840 		**(**uint8_t)(__ccgo_up(v4 + 2)) = uint8(v29)
  58841 		y4 = y4 + uintptr(2)
  58842 		u3 = u3 + 1
  58843 		v5 = v5 + 1
  58844 		dst = dst + uintptr(libc.Int32FromInt32(2)*libc.Int32FromInt32(3))
  58845 	}
  58846 	if len1&int32(1) != 0 {
  58847 		v1 = int32(**(**uint8_t)(__ccgo_up(y4)))
  58848 		v2 = int32(**(**uint8_t)(__ccgo_up(u3)))
  58849 		v3 = int32(**(**uint8_t)(__ccgo_up(v5)))
  58850 		v4 = dst
  58851 		v7 = v1 * int32(19077) >> int32(8)
  58852 		goto _86
  58853 	_86:
  58854 		v9 = v2 * int32(33050) >> int32(8)
  58855 		goto _88
  58856 	_88:
  58857 		v11 = v7 + v9 - int32(17685)
  58858 		if v11 & ^int32(YUV_MASK2) == 0 {
  58859 			v14 = v11 >> int32(YUV_FIX2)
  58860 		} else {
  58861 			if v11 < 0 {
  58862 				v15 = 0
  58863 			} else {
  58864 				v15 = int32(255)
  58865 			}
  58866 			v14 = v15
  58867 		}
  58868 		v12 = v14
  58869 		goto _91
  58870 	_91:
  58871 		v51 = v12
  58872 		goto _84
  58873 	_84:
  58874 		**(**uint8_t)(__ccgo_up(v4)) = uint8(v51)
  58875 		v18 = v1 * int32(19077) >> int32(8)
  58876 		goto _97
  58877 	_97:
  58878 		v20 = v2 * int32(6419) >> int32(8)
  58879 		goto _99
  58880 	_99:
  58881 		v22 = v3 * int32(13320) >> int32(8)
  58882 		goto _101
  58883 	_101:
  58884 		v24 = v18 - v20 - v22 + int32(8708)
  58885 		if v24 & ^int32(YUV_MASK2) == 0 {
  58886 			v27 = v24 >> int32(YUV_FIX2)
  58887 		} else {
  58888 			if v24 < 0 {
  58889 				v28 = 0
  58890 			} else {
  58891 				v28 = int32(255)
  58892 			}
  58893 			v27 = v28
  58894 		}
  58895 		v25 = v27
  58896 		goto _104
  58897 	_104:
  58898 		v16 = v25
  58899 		goto _95
  58900 	_95:
  58901 		**(**uint8_t)(__ccgo_up(v4 + 1)) = uint8(v16)
  58902 		v31 = v1 * int32(19077) >> int32(8)
  58903 		goto _110
  58904 	_110:
  58905 		v33 = v3 * int32(26149) >> int32(8)
  58906 		goto _112
  58907 	_112:
  58908 		v35 = v31 + v33 - int32(14234)
  58909 		if v35 & ^int32(YUV_MASK2) == 0 {
  58910 			v38 = v35 >> int32(YUV_FIX2)
  58911 		} else {
  58912 			if v35 < 0 {
  58913 				v39 = 0
  58914 			} else {
  58915 				v39 = int32(255)
  58916 			}
  58917 			v38 = v39
  58918 		}
  58919 		v36 = v38
  58920 		goto _115
  58921 	_115:
  58922 		v29 = v36
  58923 		goto _108
  58924 	_108:
  58925 		**(**uint8_t)(__ccgo_up(v4 + 2)) = uint8(v29)
  58926 	}
  58927 }
  58928 
  58929 func YuvToRgbaRow(tls *libc.TLS, y5 uintptr, u4 uintptr, v6 uintptr, dst uintptr, len1 int32) {
  58930 	var end, v1, v5 uintptr
  58931 	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
  58932 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  58933 	end = dst + uintptr(len1 & ^libc.Int32FromInt32(1) * int32(4))
  58934 	for dst != end {
  58935 		v1 = dst
  58936 		v2 = int32(**(**uint8_t)(__ccgo_up(y5)))
  58937 		v3 = int32(**(**uint8_t)(__ccgo_up(u4)))
  58938 		v4 = int32(**(**uint8_t)(__ccgo_up(v6)))
  58939 		v5 = v1
  58940 		v8 = v2 * int32(19077) >> int32(8)
  58941 		goto _9
  58942 	_9:
  58943 		v10 = v4 * int32(26149) >> int32(8)
  58944 		goto _11
  58945 	_11:
  58946 		v12 = v8 + v10 - int32(14234)
  58947 		if v12 & ^int32(YUV_MASK2) == 0 {
  58948 			v15 = v12 >> int32(YUV_FIX2)
  58949 		} else {
  58950 			if v12 < 0 {
  58951 				v16 = 0
  58952 			} else {
  58953 				v16 = int32(255)
  58954 			}
  58955 			v15 = v16
  58956 		}
  58957 		v13 = v15
  58958 		goto _14
  58959 	_14:
  58960 		v61 = v13
  58961 		goto _7
  58962 	_7:
  58963 		**(**uint8_t)(__ccgo_up(v5)) = uint8(v61)
  58964 		v19 = v2 * int32(19077) >> int32(8)
  58965 		goto _20
  58966 	_20:
  58967 		v21 = v3 * int32(6419) >> int32(8)
  58968 		goto _22
  58969 	_22:
  58970 		v23 = v4 * int32(13320) >> int32(8)
  58971 		goto _24
  58972 	_24:
  58973 		v25 = v19 - v21 - v23 + int32(8708)
  58974 		if v25 & ^int32(YUV_MASK2) == 0 {
  58975 			v28 = v25 >> int32(YUV_FIX2)
  58976 		} else {
  58977 			if v25 < 0 {
  58978 				v29 = 0
  58979 			} else {
  58980 				v29 = int32(255)
  58981 			}
  58982 			v28 = v29
  58983 		}
  58984 		v26 = v28
  58985 		goto _27
  58986 	_27:
  58987 		v17 = v26
  58988 		goto _18
  58989 	_18:
  58990 		**(**uint8_t)(__ccgo_up(v5 + 1)) = uint8(v17)
  58991 		v32 = v2 * int32(19077) >> int32(8)
  58992 		goto _33
  58993 	_33:
  58994 		v34 = v3 * int32(33050) >> int32(8)
  58995 		goto _35
  58996 	_35:
  58997 		v36 = v32 + v34 - int32(17685)
  58998 		if v36 & ^int32(YUV_MASK2) == 0 {
  58999 			v39 = v36 >> int32(YUV_FIX2)
  59000 		} else {
  59001 			if v36 < 0 {
  59002 				v40 = 0
  59003 			} else {
  59004 				v40 = int32(255)
  59005 			}
  59006 			v39 = v40
  59007 		}
  59008 		v37 = v39
  59009 		goto _38
  59010 	_38:
  59011 		v30 = v37
  59012 		goto _31
  59013 	_31:
  59014 		**(**uint8_t)(__ccgo_up(v5 + 2)) = uint8(v30)
  59015 		**(**uint8_t)(__ccgo_up(v1 + 3)) = uint8(0xff)
  59016 		v1 = dst + uintptr(libc.Int32FromInt32(4))
  59017 		v2 = int32(**(**uint8_t)(__ccgo_up(y5 + 1)))
  59018 		v3 = int32(**(**uint8_t)(__ccgo_up(u4)))
  59019 		v4 = int32(**(**uint8_t)(__ccgo_up(v6)))
  59020 		v5 = v1
  59021 		v8 = v2 * int32(19077) >> int32(8)
  59022 		goto _49
  59023 	_49:
  59024 		v10 = v4 * int32(26149) >> int32(8)
  59025 		goto _51
  59026 	_51:
  59027 		v12 = v8 + v10 - int32(14234)
  59028 		if v12 & ^int32(YUV_MASK2) == 0 {
  59029 			v15 = v12 >> int32(YUV_FIX2)
  59030 		} else {
  59031 			if v12 < 0 {
  59032 				v16 = 0
  59033 			} else {
  59034 				v16 = int32(255)
  59035 			}
  59036 			v15 = v16
  59037 		}
  59038 		v13 = v15
  59039 		goto _54
  59040 	_54:
  59041 		v61 = v13
  59042 		goto _47
  59043 	_47:
  59044 		**(**uint8_t)(__ccgo_up(v5)) = uint8(v61)
  59045 		v19 = v2 * int32(19077) >> int32(8)
  59046 		goto _60
  59047 	_60:
  59048 		v21 = v3 * int32(6419) >> int32(8)
  59049 		goto _62
  59050 	_62:
  59051 		v23 = v4 * int32(13320) >> int32(8)
  59052 		goto _64
  59053 	_64:
  59054 		v25 = v19 - v21 - v23 + int32(8708)
  59055 		if v25 & ^int32(YUV_MASK2) == 0 {
  59056 			v28 = v25 >> int32(YUV_FIX2)
  59057 		} else {
  59058 			if v25 < 0 {
  59059 				v29 = 0
  59060 			} else {
  59061 				v29 = int32(255)
  59062 			}
  59063 			v28 = v29
  59064 		}
  59065 		v26 = v28
  59066 		goto _67
  59067 	_67:
  59068 		v17 = v26
  59069 		goto _58
  59070 	_58:
  59071 		**(**uint8_t)(__ccgo_up(v5 + 1)) = uint8(v17)
  59072 		v32 = v2 * int32(19077) >> int32(8)
  59073 		goto _73
  59074 	_73:
  59075 		v34 = v3 * int32(33050) >> int32(8)
  59076 		goto _75
  59077 	_75:
  59078 		v36 = v32 + v34 - int32(17685)
  59079 		if v36 & ^int32(YUV_MASK2) == 0 {
  59080 			v39 = v36 >> int32(YUV_FIX2)
  59081 		} else {
  59082 			if v36 < 0 {
  59083 				v40 = 0
  59084 			} else {
  59085 				v40 = int32(255)
  59086 			}
  59087 			v39 = v40
  59088 		}
  59089 		v37 = v39
  59090 		goto _78
  59091 	_78:
  59092 		v30 = v37
  59093 		goto _71
  59094 	_71:
  59095 		**(**uint8_t)(__ccgo_up(v5 + 2)) = uint8(v30)
  59096 		**(**uint8_t)(__ccgo_up(v1 + 3)) = uint8(0xff)
  59097 		y5 = y5 + uintptr(2)
  59098 		u4 = u4 + 1
  59099 		v6 = v6 + 1
  59100 		dst = dst + uintptr(libc.Int32FromInt32(2)*libc.Int32FromInt32(4))
  59101 	}
  59102 	if len1&int32(1) != 0 {
  59103 		v1 = dst
  59104 		v2 = int32(**(**uint8_t)(__ccgo_up(y5)))
  59105 		v3 = int32(**(**uint8_t)(__ccgo_up(u4)))
  59106 		v4 = int32(**(**uint8_t)(__ccgo_up(v6)))
  59107 		v5 = v1
  59108 		v8 = v2 * int32(19077) >> int32(8)
  59109 		goto _89
  59110 	_89:
  59111 		v10 = v4 * int32(26149) >> int32(8)
  59112 		goto _91
  59113 	_91:
  59114 		v12 = v8 + v10 - int32(14234)
  59115 		if v12 & ^int32(YUV_MASK2) == 0 {
  59116 			v15 = v12 >> int32(YUV_FIX2)
  59117 		} else {
  59118 			if v12 < 0 {
  59119 				v16 = 0
  59120 			} else {
  59121 				v16 = int32(255)
  59122 			}
  59123 			v15 = v16
  59124 		}
  59125 		v13 = v15
  59126 		goto _94
  59127 	_94:
  59128 		v61 = v13
  59129 		goto _87
  59130 	_87:
  59131 		**(**uint8_t)(__ccgo_up(v5)) = uint8(v61)
  59132 		v19 = v2 * int32(19077) >> int32(8)
  59133 		goto _100
  59134 	_100:
  59135 		v21 = v3 * int32(6419) >> int32(8)
  59136 		goto _102
  59137 	_102:
  59138 		v23 = v4 * int32(13320) >> int32(8)
  59139 		goto _104
  59140 	_104:
  59141 		v25 = v19 - v21 - v23 + int32(8708)
  59142 		if v25 & ^int32(YUV_MASK2) == 0 {
  59143 			v28 = v25 >> int32(YUV_FIX2)
  59144 		} else {
  59145 			if v25 < 0 {
  59146 				v29 = 0
  59147 			} else {
  59148 				v29 = int32(255)
  59149 			}
  59150 			v28 = v29
  59151 		}
  59152 		v26 = v28
  59153 		goto _107
  59154 	_107:
  59155 		v17 = v26
  59156 		goto _98
  59157 	_98:
  59158 		**(**uint8_t)(__ccgo_up(v5 + 1)) = uint8(v17)
  59159 		v32 = v2 * int32(19077) >> int32(8)
  59160 		goto _113
  59161 	_113:
  59162 		v34 = v3 * int32(33050) >> int32(8)
  59163 		goto _115
  59164 	_115:
  59165 		v36 = v32 + v34 - int32(17685)
  59166 		if v36 & ^int32(YUV_MASK2) == 0 {
  59167 			v39 = v36 >> int32(YUV_FIX2)
  59168 		} else {
  59169 			if v36 < 0 {
  59170 				v40 = 0
  59171 			} else {
  59172 				v40 = int32(255)
  59173 			}
  59174 			v39 = v40
  59175 		}
  59176 		v37 = v39
  59177 		goto _118
  59178 	_118:
  59179 		v30 = v37
  59180 		goto _111
  59181 	_111:
  59182 		**(**uint8_t)(__ccgo_up(v5 + 2)) = uint8(v30)
  59183 		**(**uint8_t)(__ccgo_up(v1 + 3)) = uint8(0xff)
  59184 	}
  59185 }
  59186 
  59187 func YuvToBgraRow(tls *libc.TLS, y5 uintptr, u4 uintptr, v6 uintptr, dst uintptr, len1 int32) {
  59188 	var end, v1, v5 uintptr
  59189 	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
  59190 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  59191 	end = dst + uintptr(len1 & ^libc.Int32FromInt32(1) * int32(4))
  59192 	for dst != end {
  59193 		v1 = dst
  59194 		v2 = int32(**(**uint8_t)(__ccgo_up(y5)))
  59195 		v3 = int32(**(**uint8_t)(__ccgo_up(u4)))
  59196 		v4 = int32(**(**uint8_t)(__ccgo_up(v6)))
  59197 		v5 = v1
  59198 		v8 = v2 * int32(19077) >> int32(8)
  59199 		goto _9
  59200 	_9:
  59201 		v10 = v3 * int32(33050) >> int32(8)
  59202 		goto _11
  59203 	_11:
  59204 		v12 = v8 + v10 - int32(17685)
  59205 		if v12 & ^int32(YUV_MASK2) == 0 {
  59206 			v15 = v12 >> int32(YUV_FIX2)
  59207 		} else {
  59208 			if v12 < 0 {
  59209 				v16 = 0
  59210 			} else {
  59211 				v16 = int32(255)
  59212 			}
  59213 			v15 = v16
  59214 		}
  59215 		v13 = v15
  59216 		goto _14
  59217 	_14:
  59218 		v61 = v13
  59219 		goto _7
  59220 	_7:
  59221 		**(**uint8_t)(__ccgo_up(v5)) = uint8(v61)
  59222 		v19 = v2 * int32(19077) >> int32(8)
  59223 		goto _20
  59224 	_20:
  59225 		v21 = v3 * int32(6419) >> int32(8)
  59226 		goto _22
  59227 	_22:
  59228 		v23 = v4 * int32(13320) >> int32(8)
  59229 		goto _24
  59230 	_24:
  59231 		v25 = v19 - v21 - v23 + int32(8708)
  59232 		if v25 & ^int32(YUV_MASK2) == 0 {
  59233 			v28 = v25 >> int32(YUV_FIX2)
  59234 		} else {
  59235 			if v25 < 0 {
  59236 				v29 = 0
  59237 			} else {
  59238 				v29 = int32(255)
  59239 			}
  59240 			v28 = v29
  59241 		}
  59242 		v26 = v28
  59243 		goto _27
  59244 	_27:
  59245 		v17 = v26
  59246 		goto _18
  59247 	_18:
  59248 		**(**uint8_t)(__ccgo_up(v5 + 1)) = uint8(v17)
  59249 		v32 = v2 * int32(19077) >> int32(8)
  59250 		goto _33
  59251 	_33:
  59252 		v34 = v4 * int32(26149) >> int32(8)
  59253 		goto _35
  59254 	_35:
  59255 		v36 = v32 + v34 - int32(14234)
  59256 		if v36 & ^int32(YUV_MASK2) == 0 {
  59257 			v39 = v36 >> int32(YUV_FIX2)
  59258 		} else {
  59259 			if v36 < 0 {
  59260 				v40 = 0
  59261 			} else {
  59262 				v40 = int32(255)
  59263 			}
  59264 			v39 = v40
  59265 		}
  59266 		v37 = v39
  59267 		goto _38
  59268 	_38:
  59269 		v30 = v37
  59270 		goto _31
  59271 	_31:
  59272 		**(**uint8_t)(__ccgo_up(v5 + 2)) = uint8(v30)
  59273 		**(**uint8_t)(__ccgo_up(v1 + 3)) = uint8(0xff)
  59274 		v1 = dst + uintptr(libc.Int32FromInt32(4))
  59275 		v2 = int32(**(**uint8_t)(__ccgo_up(y5 + 1)))
  59276 		v3 = int32(**(**uint8_t)(__ccgo_up(u4)))
  59277 		v4 = int32(**(**uint8_t)(__ccgo_up(v6)))
  59278 		v5 = v1
  59279 		v8 = v2 * int32(19077) >> int32(8)
  59280 		goto _49
  59281 	_49:
  59282 		v10 = v3 * int32(33050) >> int32(8)
  59283 		goto _51
  59284 	_51:
  59285 		v12 = v8 + v10 - int32(17685)
  59286 		if v12 & ^int32(YUV_MASK2) == 0 {
  59287 			v15 = v12 >> int32(YUV_FIX2)
  59288 		} else {
  59289 			if v12 < 0 {
  59290 				v16 = 0
  59291 			} else {
  59292 				v16 = int32(255)
  59293 			}
  59294 			v15 = v16
  59295 		}
  59296 		v13 = v15
  59297 		goto _54
  59298 	_54:
  59299 		v61 = v13
  59300 		goto _47
  59301 	_47:
  59302 		**(**uint8_t)(__ccgo_up(v5)) = uint8(v61)
  59303 		v19 = v2 * int32(19077) >> int32(8)
  59304 		goto _60
  59305 	_60:
  59306 		v21 = v3 * int32(6419) >> int32(8)
  59307 		goto _62
  59308 	_62:
  59309 		v23 = v4 * int32(13320) >> int32(8)
  59310 		goto _64
  59311 	_64:
  59312 		v25 = v19 - v21 - v23 + int32(8708)
  59313 		if v25 & ^int32(YUV_MASK2) == 0 {
  59314 			v28 = v25 >> int32(YUV_FIX2)
  59315 		} else {
  59316 			if v25 < 0 {
  59317 				v29 = 0
  59318 			} else {
  59319 				v29 = int32(255)
  59320 			}
  59321 			v28 = v29
  59322 		}
  59323 		v26 = v28
  59324 		goto _67
  59325 	_67:
  59326 		v17 = v26
  59327 		goto _58
  59328 	_58:
  59329 		**(**uint8_t)(__ccgo_up(v5 + 1)) = uint8(v17)
  59330 		v32 = v2 * int32(19077) >> int32(8)
  59331 		goto _73
  59332 	_73:
  59333 		v34 = v4 * int32(26149) >> int32(8)
  59334 		goto _75
  59335 	_75:
  59336 		v36 = v32 + v34 - int32(14234)
  59337 		if v36 & ^int32(YUV_MASK2) == 0 {
  59338 			v39 = v36 >> int32(YUV_FIX2)
  59339 		} else {
  59340 			if v36 < 0 {
  59341 				v40 = 0
  59342 			} else {
  59343 				v40 = int32(255)
  59344 			}
  59345 			v39 = v40
  59346 		}
  59347 		v37 = v39
  59348 		goto _78
  59349 	_78:
  59350 		v30 = v37
  59351 		goto _71
  59352 	_71:
  59353 		**(**uint8_t)(__ccgo_up(v5 + 2)) = uint8(v30)
  59354 		**(**uint8_t)(__ccgo_up(v1 + 3)) = uint8(0xff)
  59355 		y5 = y5 + uintptr(2)
  59356 		u4 = u4 + 1
  59357 		v6 = v6 + 1
  59358 		dst = dst + uintptr(libc.Int32FromInt32(2)*libc.Int32FromInt32(4))
  59359 	}
  59360 	if len1&int32(1) != 0 {
  59361 		v1 = dst
  59362 		v2 = int32(**(**uint8_t)(__ccgo_up(y5)))
  59363 		v3 = int32(**(**uint8_t)(__ccgo_up(u4)))
  59364 		v4 = int32(**(**uint8_t)(__ccgo_up(v6)))
  59365 		v5 = v1
  59366 		v8 = v2 * int32(19077) >> int32(8)
  59367 		goto _89
  59368 	_89:
  59369 		v10 = v3 * int32(33050) >> int32(8)
  59370 		goto _91
  59371 	_91:
  59372 		v12 = v8 + v10 - int32(17685)
  59373 		if v12 & ^int32(YUV_MASK2) == 0 {
  59374 			v15 = v12 >> int32(YUV_FIX2)
  59375 		} else {
  59376 			if v12 < 0 {
  59377 				v16 = 0
  59378 			} else {
  59379 				v16 = int32(255)
  59380 			}
  59381 			v15 = v16
  59382 		}
  59383 		v13 = v15
  59384 		goto _94
  59385 	_94:
  59386 		v61 = v13
  59387 		goto _87
  59388 	_87:
  59389 		**(**uint8_t)(__ccgo_up(v5)) = uint8(v61)
  59390 		v19 = v2 * int32(19077) >> int32(8)
  59391 		goto _100
  59392 	_100:
  59393 		v21 = v3 * int32(6419) >> int32(8)
  59394 		goto _102
  59395 	_102:
  59396 		v23 = v4 * int32(13320) >> int32(8)
  59397 		goto _104
  59398 	_104:
  59399 		v25 = v19 - v21 - v23 + int32(8708)
  59400 		if v25 & ^int32(YUV_MASK2) == 0 {
  59401 			v28 = v25 >> int32(YUV_FIX2)
  59402 		} else {
  59403 			if v25 < 0 {
  59404 				v29 = 0
  59405 			} else {
  59406 				v29 = int32(255)
  59407 			}
  59408 			v28 = v29
  59409 		}
  59410 		v26 = v28
  59411 		goto _107
  59412 	_107:
  59413 		v17 = v26
  59414 		goto _98
  59415 	_98:
  59416 		**(**uint8_t)(__ccgo_up(v5 + 1)) = uint8(v17)
  59417 		v32 = v2 * int32(19077) >> int32(8)
  59418 		goto _113
  59419 	_113:
  59420 		v34 = v4 * int32(26149) >> int32(8)
  59421 		goto _115
  59422 	_115:
  59423 		v36 = v32 + v34 - int32(14234)
  59424 		if v36 & ^int32(YUV_MASK2) == 0 {
  59425 			v39 = v36 >> int32(YUV_FIX2)
  59426 		} else {
  59427 			if v36 < 0 {
  59428 				v40 = 0
  59429 			} else {
  59430 				v40 = int32(255)
  59431 			}
  59432 			v39 = v40
  59433 		}
  59434 		v37 = v39
  59435 		goto _118
  59436 	_118:
  59437 		v30 = v37
  59438 		goto _111
  59439 	_111:
  59440 		**(**uint8_t)(__ccgo_up(v5 + 2)) = uint8(v30)
  59441 		**(**uint8_t)(__ccgo_up(v1 + 3)) = uint8(0xff)
  59442 	}
  59443 }
  59444 
  59445 func YuvToArgbRow(tls *libc.TLS, y5 uintptr, u4 uintptr, v6 uintptr, dst uintptr, len1 int32) {
  59446 	var end, v1, v5 uintptr
  59447 	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
  59448 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  59449 	end = dst + uintptr(len1 & ^libc.Int32FromInt32(1) * int32(4))
  59450 	for dst != end {
  59451 		v1 = dst
  59452 		**(**uint8_t)(__ccgo_up(v1)) = uint8(0xff)
  59453 		v2 = int32(**(**uint8_t)(__ccgo_up(y5)))
  59454 		v3 = int32(**(**uint8_t)(__ccgo_up(u4)))
  59455 		v4 = int32(**(**uint8_t)(__ccgo_up(v6)))
  59456 		v5 = v1 + uintptr(1)
  59457 		v8 = v2 * int32(19077) >> int32(8)
  59458 		goto _9
  59459 	_9:
  59460 		v10 = v4 * int32(26149) >> int32(8)
  59461 		goto _11
  59462 	_11:
  59463 		v12 = v8 + v10 - int32(14234)
  59464 		if v12 & ^int32(YUV_MASK2) == 0 {
  59465 			v15 = v12 >> int32(YUV_FIX2)
  59466 		} else {
  59467 			if v12 < 0 {
  59468 				v16 = 0
  59469 			} else {
  59470 				v16 = int32(255)
  59471 			}
  59472 			v15 = v16
  59473 		}
  59474 		v13 = v15
  59475 		goto _14
  59476 	_14:
  59477 		v61 = v13
  59478 		goto _7
  59479 	_7:
  59480 		**(**uint8_t)(__ccgo_up(v5)) = uint8(v61)
  59481 		v19 = v2 * int32(19077) >> int32(8)
  59482 		goto _20
  59483 	_20:
  59484 		v21 = v3 * int32(6419) >> int32(8)
  59485 		goto _22
  59486 	_22:
  59487 		v23 = v4 * int32(13320) >> int32(8)
  59488 		goto _24
  59489 	_24:
  59490 		v25 = v19 - v21 - v23 + int32(8708)
  59491 		if v25 & ^int32(YUV_MASK2) == 0 {
  59492 			v28 = v25 >> int32(YUV_FIX2)
  59493 		} else {
  59494 			if v25 < 0 {
  59495 				v29 = 0
  59496 			} else {
  59497 				v29 = int32(255)
  59498 			}
  59499 			v28 = v29
  59500 		}
  59501 		v26 = v28
  59502 		goto _27
  59503 	_27:
  59504 		v17 = v26
  59505 		goto _18
  59506 	_18:
  59507 		**(**uint8_t)(__ccgo_up(v5 + 1)) = uint8(v17)
  59508 		v32 = v2 * int32(19077) >> int32(8)
  59509 		goto _33
  59510 	_33:
  59511 		v34 = v3 * int32(33050) >> int32(8)
  59512 		goto _35
  59513 	_35:
  59514 		v36 = v32 + v34 - int32(17685)
  59515 		if v36 & ^int32(YUV_MASK2) == 0 {
  59516 			v39 = v36 >> int32(YUV_FIX2)
  59517 		} else {
  59518 			if v36 < 0 {
  59519 				v40 = 0
  59520 			} else {
  59521 				v40 = int32(255)
  59522 			}
  59523 			v39 = v40
  59524 		}
  59525 		v37 = v39
  59526 		goto _38
  59527 	_38:
  59528 		v30 = v37
  59529 		goto _31
  59530 	_31:
  59531 		**(**uint8_t)(__ccgo_up(v5 + 2)) = uint8(v30)
  59532 		v1 = dst + uintptr(libc.Int32FromInt32(4))
  59533 		**(**uint8_t)(__ccgo_up(v1)) = uint8(0xff)
  59534 		v2 = int32(**(**uint8_t)(__ccgo_up(y5 + 1)))
  59535 		v3 = int32(**(**uint8_t)(__ccgo_up(u4)))
  59536 		v4 = int32(**(**uint8_t)(__ccgo_up(v6)))
  59537 		v5 = v1 + uintptr(1)
  59538 		v8 = v2 * int32(19077) >> int32(8)
  59539 		goto _49
  59540 	_49:
  59541 		v10 = v4 * int32(26149) >> int32(8)
  59542 		goto _51
  59543 	_51:
  59544 		v12 = v8 + v10 - int32(14234)
  59545 		if v12 & ^int32(YUV_MASK2) == 0 {
  59546 			v15 = v12 >> int32(YUV_FIX2)
  59547 		} else {
  59548 			if v12 < 0 {
  59549 				v16 = 0
  59550 			} else {
  59551 				v16 = int32(255)
  59552 			}
  59553 			v15 = v16
  59554 		}
  59555 		v13 = v15
  59556 		goto _54
  59557 	_54:
  59558 		v61 = v13
  59559 		goto _47
  59560 	_47:
  59561 		**(**uint8_t)(__ccgo_up(v5)) = uint8(v61)
  59562 		v19 = v2 * int32(19077) >> int32(8)
  59563 		goto _60
  59564 	_60:
  59565 		v21 = v3 * int32(6419) >> int32(8)
  59566 		goto _62
  59567 	_62:
  59568 		v23 = v4 * int32(13320) >> int32(8)
  59569 		goto _64
  59570 	_64:
  59571 		v25 = v19 - v21 - v23 + int32(8708)
  59572 		if v25 & ^int32(YUV_MASK2) == 0 {
  59573 			v28 = v25 >> int32(YUV_FIX2)
  59574 		} else {
  59575 			if v25 < 0 {
  59576 				v29 = 0
  59577 			} else {
  59578 				v29 = int32(255)
  59579 			}
  59580 			v28 = v29
  59581 		}
  59582 		v26 = v28
  59583 		goto _67
  59584 	_67:
  59585 		v17 = v26
  59586 		goto _58
  59587 	_58:
  59588 		**(**uint8_t)(__ccgo_up(v5 + 1)) = uint8(v17)
  59589 		v32 = v2 * int32(19077) >> int32(8)
  59590 		goto _73
  59591 	_73:
  59592 		v34 = v3 * int32(33050) >> int32(8)
  59593 		goto _75
  59594 	_75:
  59595 		v36 = v32 + v34 - int32(17685)
  59596 		if v36 & ^int32(YUV_MASK2) == 0 {
  59597 			v39 = v36 >> int32(YUV_FIX2)
  59598 		} else {
  59599 			if v36 < 0 {
  59600 				v40 = 0
  59601 			} else {
  59602 				v40 = int32(255)
  59603 			}
  59604 			v39 = v40
  59605 		}
  59606 		v37 = v39
  59607 		goto _78
  59608 	_78:
  59609 		v30 = v37
  59610 		goto _71
  59611 	_71:
  59612 		**(**uint8_t)(__ccgo_up(v5 + 2)) = uint8(v30)
  59613 		y5 = y5 + uintptr(2)
  59614 		u4 = u4 + 1
  59615 		v6 = v6 + 1
  59616 		dst = dst + uintptr(libc.Int32FromInt32(2)*libc.Int32FromInt32(4))
  59617 	}
  59618 	if len1&int32(1) != 0 {
  59619 		v1 = dst
  59620 		**(**uint8_t)(__ccgo_up(v1)) = uint8(0xff)
  59621 		v2 = int32(**(**uint8_t)(__ccgo_up(y5)))
  59622 		v3 = int32(**(**uint8_t)(__ccgo_up(u4)))
  59623 		v4 = int32(**(**uint8_t)(__ccgo_up(v6)))
  59624 		v5 = v1 + uintptr(1)
  59625 		v8 = v2 * int32(19077) >> int32(8)
  59626 		goto _89
  59627 	_89:
  59628 		v10 = v4 * int32(26149) >> int32(8)
  59629 		goto _91
  59630 	_91:
  59631 		v12 = v8 + v10 - int32(14234)
  59632 		if v12 & ^int32(YUV_MASK2) == 0 {
  59633 			v15 = v12 >> int32(YUV_FIX2)
  59634 		} else {
  59635 			if v12 < 0 {
  59636 				v16 = 0
  59637 			} else {
  59638 				v16 = int32(255)
  59639 			}
  59640 			v15 = v16
  59641 		}
  59642 		v13 = v15
  59643 		goto _94
  59644 	_94:
  59645 		v61 = v13
  59646 		goto _87
  59647 	_87:
  59648 		**(**uint8_t)(__ccgo_up(v5)) = uint8(v61)
  59649 		v19 = v2 * int32(19077) >> int32(8)
  59650 		goto _100
  59651 	_100:
  59652 		v21 = v3 * int32(6419) >> int32(8)
  59653 		goto _102
  59654 	_102:
  59655 		v23 = v4 * int32(13320) >> int32(8)
  59656 		goto _104
  59657 	_104:
  59658 		v25 = v19 - v21 - v23 + int32(8708)
  59659 		if v25 & ^int32(YUV_MASK2) == 0 {
  59660 			v28 = v25 >> int32(YUV_FIX2)
  59661 		} else {
  59662 			if v25 < 0 {
  59663 				v29 = 0
  59664 			} else {
  59665 				v29 = int32(255)
  59666 			}
  59667 			v28 = v29
  59668 		}
  59669 		v26 = v28
  59670 		goto _107
  59671 	_107:
  59672 		v17 = v26
  59673 		goto _98
  59674 	_98:
  59675 		**(**uint8_t)(__ccgo_up(v5 + 1)) = uint8(v17)
  59676 		v32 = v2 * int32(19077) >> int32(8)
  59677 		goto _113
  59678 	_113:
  59679 		v34 = v3 * int32(33050) >> int32(8)
  59680 		goto _115
  59681 	_115:
  59682 		v36 = v32 + v34 - int32(17685)
  59683 		if v36 & ^int32(YUV_MASK2) == 0 {
  59684 			v39 = v36 >> int32(YUV_FIX2)
  59685 		} else {
  59686 			if v36 < 0 {
  59687 				v40 = 0
  59688 			} else {
  59689 				v40 = int32(255)
  59690 			}
  59691 			v39 = v40
  59692 		}
  59693 		v37 = v39
  59694 		goto _118
  59695 	_118:
  59696 		v30 = v37
  59697 		goto _111
  59698 	_111:
  59699 		**(**uint8_t)(__ccgo_up(v5 + 2)) = uint8(v30)
  59700 	}
  59701 }
  59702 
  59703 func YuvToRgba4444Row(tls *libc.TLS, y4 uintptr, u3 uintptr, v5 uintptr, dst uintptr, len1 int32) {
  59704 	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
  59705 	var end, v4 uintptr
  59706 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  59707 	end = dst + uintptr(len1 & ^libc.Int32FromInt32(1) * int32(2))
  59708 	for dst != end {
  59709 		v1 = int32(**(**uint8_t)(__ccgo_up(y4)))
  59710 		v2 = int32(**(**uint8_t)(__ccgo_up(u3)))
  59711 		v3 = int32(**(**uint8_t)(__ccgo_up(v5)))
  59712 		v4 = dst
  59713 		v7 = v1 * int32(19077) >> int32(8)
  59714 		goto _8
  59715 	_8:
  59716 		v9 = v3 * int32(26149) >> int32(8)
  59717 		goto _10
  59718 	_10:
  59719 		v11 = v7 + v9 - int32(14234)
  59720 		if v11 & ^int32(YUV_MASK2) == 0 {
  59721 			v14 = v11 >> int32(YUV_FIX2)
  59722 		} else {
  59723 			if v11 < 0 {
  59724 				v15 = 0
  59725 			} else {
  59726 				v15 = int32(255)
  59727 			}
  59728 			v14 = v15
  59729 		}
  59730 		v12 = v14
  59731 		goto _13
  59732 	_13:
  59733 		v51 = v12
  59734 		goto _6
  59735 	_6:
  59736 		r = v51
  59737 		v18 = v1 * int32(19077) >> int32(8)
  59738 		goto _19
  59739 	_19:
  59740 		v20 = v2 * int32(6419) >> int32(8)
  59741 		goto _21
  59742 	_21:
  59743 		v22 = v3 * int32(13320) >> int32(8)
  59744 		goto _23
  59745 	_23:
  59746 		v24 = v18 - v20 - v22 + int32(8708)
  59747 		if v24 & ^int32(YUV_MASK2) == 0 {
  59748 			v27 = v24 >> int32(YUV_FIX2)
  59749 		} else {
  59750 			if v24 < 0 {
  59751 				v28 = 0
  59752 			} else {
  59753 				v28 = int32(255)
  59754 			}
  59755 			v27 = v28
  59756 		}
  59757 		v25 = v27
  59758 		goto _26
  59759 	_26:
  59760 		v16 = v25
  59761 		goto _17
  59762 	_17:
  59763 		g = v16
  59764 		v31 = v1 * int32(19077) >> int32(8)
  59765 		goto _32
  59766 	_32:
  59767 		v33 = v2 * int32(33050) >> int32(8)
  59768 		goto _34
  59769 	_34:
  59770 		v35 = v31 + v33 - int32(17685)
  59771 		if v35 & ^int32(YUV_MASK2) == 0 {
  59772 			v38 = v35 >> int32(YUV_FIX2)
  59773 		} else {
  59774 			if v35 < 0 {
  59775 				v39 = 0
  59776 			} else {
  59777 				v39 = int32(255)
  59778 			}
  59779 			v38 = v39
  59780 		}
  59781 		v36 = v38
  59782 		goto _37
  59783 	_37:
  59784 		v29 = v36
  59785 		goto _30
  59786 	_30:
  59787 		b = v29
  59788 		rg = r&int32(0xf0) | g>>libc.Int32FromInt32(4)
  59789 		ba = b&int32(0xf0) | int32(0x0f)
  59790 		**(**uint8_t)(__ccgo_up(v4)) = uint8(rg)
  59791 		**(**uint8_t)(__ccgo_up(v4 + 1)) = uint8(ba)
  59792 		v1 = int32(**(**uint8_t)(__ccgo_up(y4 + 1)))
  59793 		v2 = int32(**(**uint8_t)(__ccgo_up(u3)))
  59794 		v3 = int32(**(**uint8_t)(__ccgo_up(v5)))
  59795 		v4 = dst + uintptr(libc.Int32FromInt32(2))
  59796 		v7 = v1 * int32(19077) >> int32(8)
  59797 		goto _47
  59798 	_47:
  59799 		v9 = v3 * int32(26149) >> int32(8)
  59800 		goto _49
  59801 	_49:
  59802 		v11 = v7 + v9 - int32(14234)
  59803 		if v11 & ^int32(YUV_MASK2) == 0 {
  59804 			v14 = v11 >> int32(YUV_FIX2)
  59805 		} else {
  59806 			if v11 < 0 {
  59807 				v15 = 0
  59808 			} else {
  59809 				v15 = int32(255)
  59810 			}
  59811 			v14 = v15
  59812 		}
  59813 		v12 = v14
  59814 		goto _52
  59815 	_52:
  59816 		v51 = v12
  59817 		goto _45
  59818 	_45:
  59819 		r = v51
  59820 		v18 = v1 * int32(19077) >> int32(8)
  59821 		goto _58
  59822 	_58:
  59823 		v20 = v2 * int32(6419) >> int32(8)
  59824 		goto _60
  59825 	_60:
  59826 		v22 = v3 * int32(13320) >> int32(8)
  59827 		goto _62
  59828 	_62:
  59829 		v24 = v18 - v20 - v22 + int32(8708)
  59830 		if v24 & ^int32(YUV_MASK2) == 0 {
  59831 			v27 = v24 >> int32(YUV_FIX2)
  59832 		} else {
  59833 			if v24 < 0 {
  59834 				v28 = 0
  59835 			} else {
  59836 				v28 = int32(255)
  59837 			}
  59838 			v27 = v28
  59839 		}
  59840 		v25 = v27
  59841 		goto _65
  59842 	_65:
  59843 		v16 = v25
  59844 		goto _56
  59845 	_56:
  59846 		g = v16
  59847 		v31 = v1 * int32(19077) >> int32(8)
  59848 		goto _71
  59849 	_71:
  59850 		v33 = v2 * int32(33050) >> int32(8)
  59851 		goto _73
  59852 	_73:
  59853 		v35 = v31 + v33 - int32(17685)
  59854 		if v35 & ^int32(YUV_MASK2) == 0 {
  59855 			v38 = v35 >> int32(YUV_FIX2)
  59856 		} else {
  59857 			if v35 < 0 {
  59858 				v39 = 0
  59859 			} else {
  59860 				v39 = int32(255)
  59861 			}
  59862 			v38 = v39
  59863 		}
  59864 		v36 = v38
  59865 		goto _76
  59866 	_76:
  59867 		v29 = v36
  59868 		goto _69
  59869 	_69:
  59870 		b = v29
  59871 		rg = r&int32(0xf0) | g>>libc.Int32FromInt32(4)
  59872 		ba = b&int32(0xf0) | int32(0x0f)
  59873 		**(**uint8_t)(__ccgo_up(v4)) = uint8(rg)
  59874 		**(**uint8_t)(__ccgo_up(v4 + 1)) = uint8(ba)
  59875 		y4 = y4 + uintptr(2)
  59876 		u3 = u3 + 1
  59877 		v5 = v5 + 1
  59878 		dst = dst + uintptr(libc.Int32FromInt32(2)*libc.Int32FromInt32(2))
  59879 	}
  59880 	if len1&int32(1) != 0 {
  59881 		v1 = int32(**(**uint8_t)(__ccgo_up(y4)))
  59882 		v2 = int32(**(**uint8_t)(__ccgo_up(u3)))
  59883 		v3 = int32(**(**uint8_t)(__ccgo_up(v5)))
  59884 		v4 = dst
  59885 		v7 = v1 * int32(19077) >> int32(8)
  59886 		goto _86
  59887 	_86:
  59888 		v9 = v3 * int32(26149) >> int32(8)
  59889 		goto _88
  59890 	_88:
  59891 		v11 = v7 + v9 - int32(14234)
  59892 		if v11 & ^int32(YUV_MASK2) == 0 {
  59893 			v14 = v11 >> int32(YUV_FIX2)
  59894 		} else {
  59895 			if v11 < 0 {
  59896 				v15 = 0
  59897 			} else {
  59898 				v15 = int32(255)
  59899 			}
  59900 			v14 = v15
  59901 		}
  59902 		v12 = v14
  59903 		goto _91
  59904 	_91:
  59905 		v51 = v12
  59906 		goto _84
  59907 	_84:
  59908 		r = v51
  59909 		v18 = v1 * int32(19077) >> int32(8)
  59910 		goto _97
  59911 	_97:
  59912 		v20 = v2 * int32(6419) >> int32(8)
  59913 		goto _99
  59914 	_99:
  59915 		v22 = v3 * int32(13320) >> int32(8)
  59916 		goto _101
  59917 	_101:
  59918 		v24 = v18 - v20 - v22 + int32(8708)
  59919 		if v24 & ^int32(YUV_MASK2) == 0 {
  59920 			v27 = v24 >> int32(YUV_FIX2)
  59921 		} else {
  59922 			if v24 < 0 {
  59923 				v28 = 0
  59924 			} else {
  59925 				v28 = int32(255)
  59926 			}
  59927 			v27 = v28
  59928 		}
  59929 		v25 = v27
  59930 		goto _104
  59931 	_104:
  59932 		v16 = v25
  59933 		goto _95
  59934 	_95:
  59935 		g = v16
  59936 		v31 = v1 * int32(19077) >> int32(8)
  59937 		goto _110
  59938 	_110:
  59939 		v33 = v2 * int32(33050) >> int32(8)
  59940 		goto _112
  59941 	_112:
  59942 		v35 = v31 + v33 - int32(17685)
  59943 		if v35 & ^int32(YUV_MASK2) == 0 {
  59944 			v38 = v35 >> int32(YUV_FIX2)
  59945 		} else {
  59946 			if v35 < 0 {
  59947 				v39 = 0
  59948 			} else {
  59949 				v39 = int32(255)
  59950 			}
  59951 			v38 = v39
  59952 		}
  59953 		v36 = v38
  59954 		goto _115
  59955 	_115:
  59956 		v29 = v36
  59957 		goto _108
  59958 	_108:
  59959 		b = v29
  59960 		rg = r&int32(0xf0) | g>>libc.Int32FromInt32(4)
  59961 		ba = b&int32(0xf0) | int32(0x0f)
  59962 		**(**uint8_t)(__ccgo_up(v4)) = uint8(rg)
  59963 		**(**uint8_t)(__ccgo_up(v4 + 1)) = uint8(ba)
  59964 	}
  59965 }
  59966 
  59967 func YuvToRgb565Row(tls *libc.TLS, y4 uintptr, u3 uintptr, v5 uintptr, dst uintptr, len1 int32) {
  59968 	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
  59969 	var end, v4 uintptr
  59970 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  59971 	end = dst + uintptr(len1 & ^libc.Int32FromInt32(1) * int32(2))
  59972 	for dst != end {
  59973 		v1 = int32(**(**uint8_t)(__ccgo_up(y4)))
  59974 		v2 = int32(**(**uint8_t)(__ccgo_up(u3)))
  59975 		v3 = int32(**(**uint8_t)(__ccgo_up(v5)))
  59976 		v4 = dst
  59977 		v7 = v1 * int32(19077) >> int32(8)
  59978 		goto _8
  59979 	_8:
  59980 		v9 = v3 * int32(26149) >> int32(8)
  59981 		goto _10
  59982 	_10:
  59983 		v11 = v7 + v9 - int32(14234)
  59984 		if v11 & ^int32(YUV_MASK2) == 0 {
  59985 			v14 = v11 >> int32(YUV_FIX2)
  59986 		} else {
  59987 			if v11 < 0 {
  59988 				v15 = 0
  59989 			} else {
  59990 				v15 = int32(255)
  59991 			}
  59992 			v14 = v15
  59993 		}
  59994 		v12 = v14
  59995 		goto _13
  59996 	_13:
  59997 		v51 = v12
  59998 		goto _6
  59999 	_6:
  60000 		r = v51
  60001 		v18 = v1 * int32(19077) >> int32(8)
  60002 		goto _19
  60003 	_19:
  60004 		v20 = v2 * int32(6419) >> int32(8)
  60005 		goto _21
  60006 	_21:
  60007 		v22 = v3 * int32(13320) >> int32(8)
  60008 		goto _23
  60009 	_23:
  60010 		v24 = v18 - v20 - v22 + int32(8708)
  60011 		if v24 & ^int32(YUV_MASK2) == 0 {
  60012 			v27 = v24 >> int32(YUV_FIX2)
  60013 		} else {
  60014 			if v24 < 0 {
  60015 				v28 = 0
  60016 			} else {
  60017 				v28 = int32(255)
  60018 			}
  60019 			v27 = v28
  60020 		}
  60021 		v25 = v27
  60022 		goto _26
  60023 	_26:
  60024 		v16 = v25
  60025 		goto _17
  60026 	_17:
  60027 		g = v16
  60028 		v31 = v1 * int32(19077) >> int32(8)
  60029 		goto _32
  60030 	_32:
  60031 		v33 = v2 * int32(33050) >> int32(8)
  60032 		goto _34
  60033 	_34:
  60034 		v35 = v31 + v33 - int32(17685)
  60035 		if v35 & ^int32(YUV_MASK2) == 0 {
  60036 			v38 = v35 >> int32(YUV_FIX2)
  60037 		} else {
  60038 			if v35 < 0 {
  60039 				v39 = 0
  60040 			} else {
  60041 				v39 = int32(255)
  60042 			}
  60043 			v38 = v39
  60044 		}
  60045 		v36 = v38
  60046 		goto _37
  60047 	_37:
  60048 		v29 = v36
  60049 		goto _30
  60050 	_30:
  60051 		b = v29
  60052 		rg = r&int32(0xf8) | g>>libc.Int32FromInt32(5)
  60053 		gb = g<<libc.Int32FromInt32(3)&int32(0xe0) | b>>libc.Int32FromInt32(3)
  60054 		**(**uint8_t)(__ccgo_up(v4)) = uint8(rg)
  60055 		**(**uint8_t)(__ccgo_up(v4 + 1)) = uint8(gb)
  60056 		v1 = int32(**(**uint8_t)(__ccgo_up(y4 + 1)))
  60057 		v2 = int32(**(**uint8_t)(__ccgo_up(u3)))
  60058 		v3 = int32(**(**uint8_t)(__ccgo_up(v5)))
  60059 		v4 = dst + uintptr(libc.Int32FromInt32(2))
  60060 		v7 = v1 * int32(19077) >> int32(8)
  60061 		goto _47
  60062 	_47:
  60063 		v9 = v3 * int32(26149) >> int32(8)
  60064 		goto _49
  60065 	_49:
  60066 		v11 = v7 + v9 - int32(14234)
  60067 		if v11 & ^int32(YUV_MASK2) == 0 {
  60068 			v14 = v11 >> int32(YUV_FIX2)
  60069 		} else {
  60070 			if v11 < 0 {
  60071 				v15 = 0
  60072 			} else {
  60073 				v15 = int32(255)
  60074 			}
  60075 			v14 = v15
  60076 		}
  60077 		v12 = v14
  60078 		goto _52
  60079 	_52:
  60080 		v51 = v12
  60081 		goto _45
  60082 	_45:
  60083 		r = v51
  60084 		v18 = v1 * int32(19077) >> int32(8)
  60085 		goto _58
  60086 	_58:
  60087 		v20 = v2 * int32(6419) >> int32(8)
  60088 		goto _60
  60089 	_60:
  60090 		v22 = v3 * int32(13320) >> int32(8)
  60091 		goto _62
  60092 	_62:
  60093 		v24 = v18 - v20 - v22 + int32(8708)
  60094 		if v24 & ^int32(YUV_MASK2) == 0 {
  60095 			v27 = v24 >> int32(YUV_FIX2)
  60096 		} else {
  60097 			if v24 < 0 {
  60098 				v28 = 0
  60099 			} else {
  60100 				v28 = int32(255)
  60101 			}
  60102 			v27 = v28
  60103 		}
  60104 		v25 = v27
  60105 		goto _65
  60106 	_65:
  60107 		v16 = v25
  60108 		goto _56
  60109 	_56:
  60110 		g = v16
  60111 		v31 = v1 * int32(19077) >> int32(8)
  60112 		goto _71
  60113 	_71:
  60114 		v33 = v2 * int32(33050) >> int32(8)
  60115 		goto _73
  60116 	_73:
  60117 		v35 = v31 + v33 - int32(17685)
  60118 		if v35 & ^int32(YUV_MASK2) == 0 {
  60119 			v38 = v35 >> int32(YUV_FIX2)
  60120 		} else {
  60121 			if v35 < 0 {
  60122 				v39 = 0
  60123 			} else {
  60124 				v39 = int32(255)
  60125 			}
  60126 			v38 = v39
  60127 		}
  60128 		v36 = v38
  60129 		goto _76
  60130 	_76:
  60131 		v29 = v36
  60132 		goto _69
  60133 	_69:
  60134 		b = v29
  60135 		rg = r&int32(0xf8) | g>>libc.Int32FromInt32(5)
  60136 		gb = g<<libc.Int32FromInt32(3)&int32(0xe0) | b>>libc.Int32FromInt32(3)
  60137 		**(**uint8_t)(__ccgo_up(v4)) = uint8(rg)
  60138 		**(**uint8_t)(__ccgo_up(v4 + 1)) = uint8(gb)
  60139 		y4 = y4 + uintptr(2)
  60140 		u3 = u3 + 1
  60141 		v5 = v5 + 1
  60142 		dst = dst + uintptr(libc.Int32FromInt32(2)*libc.Int32FromInt32(2))
  60143 	}
  60144 	if len1&int32(1) != 0 {
  60145 		v1 = int32(**(**uint8_t)(__ccgo_up(y4)))
  60146 		v2 = int32(**(**uint8_t)(__ccgo_up(u3)))
  60147 		v3 = int32(**(**uint8_t)(__ccgo_up(v5)))
  60148 		v4 = dst
  60149 		v7 = v1 * int32(19077) >> int32(8)
  60150 		goto _86
  60151 	_86:
  60152 		v9 = v3 * int32(26149) >> int32(8)
  60153 		goto _88
  60154 	_88:
  60155 		v11 = v7 + v9 - int32(14234)
  60156 		if v11 & ^int32(YUV_MASK2) == 0 {
  60157 			v14 = v11 >> int32(YUV_FIX2)
  60158 		} else {
  60159 			if v11 < 0 {
  60160 				v15 = 0
  60161 			} else {
  60162 				v15 = int32(255)
  60163 			}
  60164 			v14 = v15
  60165 		}
  60166 		v12 = v14
  60167 		goto _91
  60168 	_91:
  60169 		v51 = v12
  60170 		goto _84
  60171 	_84:
  60172 		r = v51
  60173 		v18 = v1 * int32(19077) >> int32(8)
  60174 		goto _97
  60175 	_97:
  60176 		v20 = v2 * int32(6419) >> int32(8)
  60177 		goto _99
  60178 	_99:
  60179 		v22 = v3 * int32(13320) >> int32(8)
  60180 		goto _101
  60181 	_101:
  60182 		v24 = v18 - v20 - v22 + int32(8708)
  60183 		if v24 & ^int32(YUV_MASK2) == 0 {
  60184 			v27 = v24 >> int32(YUV_FIX2)
  60185 		} else {
  60186 			if v24 < 0 {
  60187 				v28 = 0
  60188 			} else {
  60189 				v28 = int32(255)
  60190 			}
  60191 			v27 = v28
  60192 		}
  60193 		v25 = v27
  60194 		goto _104
  60195 	_104:
  60196 		v16 = v25
  60197 		goto _95
  60198 	_95:
  60199 		g = v16
  60200 		v31 = v1 * int32(19077) >> int32(8)
  60201 		goto _110
  60202 	_110:
  60203 		v33 = v2 * int32(33050) >> int32(8)
  60204 		goto _112
  60205 	_112:
  60206 		v35 = v31 + v33 - int32(17685)
  60207 		if v35 & ^int32(YUV_MASK2) == 0 {
  60208 			v38 = v35 >> int32(YUV_FIX2)
  60209 		} else {
  60210 			if v35 < 0 {
  60211 				v39 = 0
  60212 			} else {
  60213 				v39 = int32(255)
  60214 			}
  60215 			v38 = v39
  60216 		}
  60217 		v36 = v38
  60218 		goto _115
  60219 	_115:
  60220 		v29 = v36
  60221 		goto _108
  60222 	_108:
  60223 		b = v29
  60224 		rg = r&int32(0xf8) | g>>libc.Int32FromInt32(5)
  60225 		gb = g<<libc.Int32FromInt32(3)&int32(0xe0) | b>>libc.Int32FromInt32(3)
  60226 		**(**uint8_t)(__ccgo_up(v4)) = uint8(rg)
  60227 		**(**uint8_t)(__ccgo_up(v4 + 1)) = uint8(gb)
  60228 	}
  60229 }
  60230 
  60231 type __ccgo_fp__XWebPSamplerProcessPlane_9 = func(*libc.TLS, uintptr, uintptr, uintptr, uintptr, int32)
  60232 
  60233 // C documentation
  60234 //
  60235 //	// Main call for processing a plane with a WebPSamplerRowFunc function:
  60236 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) {
  60237 	var j int32
  60238 	_ = j
  60239 	j = 0
  60240 	for {
  60241 		if !(j < height) {
  60242 			break
  60243 		}
  60244 		(*(*func(*libc.TLS, uintptr, uintptr, uintptr, uintptr, int32))(unsafe.Pointer(&struct{ uintptr }{__ccgo_fp_func})))(tls, y, u, v, dst, width)
  60245 		y = y + uintptr(y_stride)
  60246 		if j&int32(1) != 0 {
  60247 			u = u + uintptr(uv_stride)
  60248 			v = v + uintptr(uv_stride)
  60249 		}
  60250 		dst = dst + uintptr(dst_stride)
  60251 		goto _1
  60252 	_1:
  60253 		;
  60254 		j = j + 1
  60255 	}
  60256 }
  60257 
  60258 func WebPInitSamplers(tls *libc.TLS) {
  60259 	if libc.AtomicLoadPUintptr(uintptr(unsafe.Pointer(&WebPInitSamplers_body_last_cpuinfo_used))) == VP8GetCPUInfo {
  60260 		goto _1
  60261 	}
  60262 	WebPInitSamplers_body(tls)
  60263 	libc.AtomicStorePUintptr(uintptr(unsafe.Pointer(&WebPInitSamplers_body_last_cpuinfo_used)), VP8GetCPUInfo)
  60264 	goto _2
  60265 _2:
  60266 	;
  60267 	goto _1
  60268 _1: /**/ //
  60269 }
  60270 
  60271 var WebPInitSamplers_body_last_cpuinfo_used = uintptr(0)
  60272 
  60273 func init() {
  60274 	p := unsafe.Pointer(&WebPInitSamplers_body_last_cpuinfo_used)
  60275 	*(*uintptr)(unsafe.Add(p, 0)) = uintptr(unsafe.Pointer(&WebPInitSamplers_body_last_cpuinfo_used))
  60276 }
  60277 
  60278 func WebPInitSamplers_body(tls *libc.TLS) {
  60279 	WebPSamplers[int32(MODE_RGB)] = __ccgo_fp(YuvToRgbRow)
  60280 	WebPSamplers[int32(MODE_RGBA)] = __ccgo_fp(YuvToRgbaRow)
  60281 	WebPSamplers[int32(MODE_BGR)] = __ccgo_fp(YuvToBgrRow)
  60282 	WebPSamplers[int32(MODE_BGRA)] = __ccgo_fp(YuvToBgraRow)
  60283 	WebPSamplers[int32(MODE_ARGB)] = __ccgo_fp(YuvToArgbRow)
  60284 	WebPSamplers[int32(MODE_RGBA_4444)] = __ccgo_fp(YuvToRgba4444Row)
  60285 	WebPSamplers[int32(MODE_RGB_565)] = __ccgo_fp(YuvToRgb565Row)
  60286 	WebPSamplers[int32(MODE_rgbA)] = __ccgo_fp(YuvToRgbaRow)
  60287 	WebPSamplers[int32(MODE_bgrA)] = __ccgo_fp(YuvToBgraRow)
  60288 	WebPSamplers[int32(MODE_Argb)] = __ccgo_fp(YuvToArgbRow)
  60289 	WebPSamplers[int32(MODE_rgbA_4444)] = __ccgo_fp(YuvToRgba4444Row)
  60290 	// If defined, use CPUInfo() to overwrite some pointers with faster versions.
  60291 	if VP8GetCPUInfo != libc.UintptrFromInt32(0) {
  60292 	}
  60293 }
  60294 
  60295 //-----------------------------------------------------------------------------
  60296 // ARGB -> YUV converters
  60297 
  60298 func ConvertARGBToY_C(tls *libc.TLS, argb uintptr, y uintptr, width int32) {
  60299 	var i, luma, v2 int32
  60300 	var p uint32_t
  60301 	_, _, _, _ = i, luma, p, v2
  60302 	i = 0
  60303 	for {
  60304 		if !(i < width) {
  60305 			break
  60306 		}
  60307 		p = **(**uint32_t)(__ccgo_up(argb + uintptr(i)*4))
  60308 		luma = int32(16839)*int32(p>>libc.Int32FromInt32(16)&uint32(0xff)) + int32(33059)*int32(p>>libc.Int32FromInt32(8)&uint32(0xff)) + int32(6420)*int32(p>>libc.Int32FromInt32(0)&uint32(0xff))
  60309 		v2 = (luma + int32(YUV_HALF) + libc.Int32FromInt32(16)<<int32(YUV_FIX)) >> int32(YUV_FIX)
  60310 		goto _3
  60311 	_3:
  60312 		**(**uint8_t)(__ccgo_up(y + uintptr(i))) = uint8(v2)
  60313 		goto _1
  60314 	_1:
  60315 		;
  60316 		i = i + 1
  60317 	}
  60318 }
  60319 
  60320 func WebPConvertARGBToUV_C(tls *libc.TLS, argb uintptr, u1 uintptr, v1 uintptr, src_width int32, do_store int32) {
  60321 	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
  60322 	var v0, v01, v11 uint32_t
  60323 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  60324 	// No rounding. Last pixel is dealt with separately.
  60325 	uv_width = src_width >> int32(1)
  60326 	i = 0
  60327 	for {
  60328 		if !(i < uv_width) {
  60329 			break
  60330 		}
  60331 		v0 = **(**uint32_t)(__ccgo_up(argb + uintptr(int32(2)*i+0)*4))
  60332 		v11 = **(**uint32_t)(__ccgo_up(argb + uintptr(int32(2)*i+int32(1))*4))
  60333 		// VP8RGBToU/V expects four accumulated pixels. Hence we need to
  60334 		// scale r/g/b value by a factor 2. We just shift v0/v1 one bit less.
  60335 		r2 = int32(v0>>libc.Int32FromInt32(15)&uint32(0x1fe) + v11>>libc.Int32FromInt32(15)&uint32(0x1fe))
  60336 		g2 = int32(v0>>libc.Int32FromInt32(7)&uint32(0x1fe) + v11>>libc.Int32FromInt32(7)&uint32(0x1fe))
  60337 		b2 = int32(v0<<libc.Int32FromInt32(1)&uint32(0x1fe) + v11<<libc.Int32FromInt32(1)&uint32(0x1fe))
  60338 		u = -int32(9719)*r2 - int32(19081)*g2 + int32(28800)*b2
  60339 		v4 = u
  60340 		v4 = (v4 + int32(YUV_HALF)<<libc.Int32FromInt32(2) + libc.Int32FromInt32(128)<<(int32(YUV_FIX)+libc.Int32FromInt32(2))) >> (int32(YUV_FIX) + libc.Int32FromInt32(2))
  60341 		if v4 & ^libc.Int32FromInt32(0xff) == 0 {
  60342 			v7 = v4
  60343 		} else {
  60344 			if v4 < 0 {
  60345 				v8 = 0
  60346 			} else {
  60347 				v8 = int32(255)
  60348 			}
  60349 			v7 = v8
  60350 		}
  60351 		v5 = v7
  60352 		goto _6
  60353 	_6:
  60354 		v2 = v5
  60355 		goto _3
  60356 	_3:
  60357 		tmp_u = v2
  60358 		v = +libc.Int32FromInt32(28800)*r2 - int32(24116)*g2 - int32(4684)*b2
  60359 		v111 = v
  60360 		v111 = (v111 + int32(YUV_HALF)<<libc.Int32FromInt32(2) + libc.Int32FromInt32(128)<<(int32(YUV_FIX)+libc.Int32FromInt32(2))) >> (int32(YUV_FIX) + libc.Int32FromInt32(2))
  60361 		if v111 & ^libc.Int32FromInt32(0xff) == 0 {
  60362 			v14 = v111
  60363 		} else {
  60364 			if v111 < 0 {
  60365 				v15 = 0
  60366 			} else {
  60367 				v15 = int32(255)
  60368 			}
  60369 			v14 = v15
  60370 		}
  60371 		v12 = v14
  60372 		goto _13
  60373 	_13:
  60374 		v9 = v12
  60375 		goto _10
  60376 	_10:
  60377 		tmp_v = v9
  60378 		if do_store != 0 {
  60379 			**(**uint8_t)(__ccgo_up(u1 + uintptr(i))) = uint8(tmp_u)
  60380 			**(**uint8_t)(__ccgo_up(v1 + uintptr(i))) = uint8(tmp_v)
  60381 		} else {
  60382 			// Approximated average-of-four. But it's an acceptable diff.
  60383 			**(**uint8_t)(__ccgo_up(u1 + uintptr(i))) = uint8((int32(**(**uint8_t)(__ccgo_up(u1 + uintptr(i)))) + tmp_u + int32(1)) >> int32(1))
  60384 			**(**uint8_t)(__ccgo_up(v1 + uintptr(i))) = uint8((int32(**(**uint8_t)(__ccgo_up(v1 + uintptr(i)))) + tmp_v + int32(1)) >> int32(1))
  60385 		}
  60386 		goto _1
  60387 	_1:
  60388 		;
  60389 		i = i + 1
  60390 	}
  60391 	if src_width&int32(1) != 0 { // last pixel
  60392 		v01 = **(**uint32_t)(__ccgo_up(argb + uintptr(int32(2)*i+0)*4))
  60393 		r3 = int32(v01 >> libc.Int32FromInt32(14) & uint32(0x3fc))
  60394 		g3 = int32(v01 >> libc.Int32FromInt32(6) & uint32(0x3fc))
  60395 		b3 = int32(v01 << libc.Int32FromInt32(2) & uint32(0x3fc))
  60396 		u = -int32(9719)*r3 - int32(19081)*g3 + int32(28800)*b3
  60397 		v4 = u
  60398 		v4 = (v4 + int32(YUV_HALF)<<libc.Int32FromInt32(2) + libc.Int32FromInt32(128)<<(int32(YUV_FIX)+libc.Int32FromInt32(2))) >> (int32(YUV_FIX) + libc.Int32FromInt32(2))
  60399 		if v4 & ^libc.Int32FromInt32(0xff) == 0 {
  60400 			v7 = v4
  60401 		} else {
  60402 			if v4 < 0 {
  60403 				v8 = 0
  60404 			} else {
  60405 				v8 = int32(255)
  60406 			}
  60407 			v7 = v8
  60408 		}
  60409 		v5 = v7
  60410 		goto _20
  60411 	_20:
  60412 		v2 = v5
  60413 		goto _17
  60414 	_17:
  60415 		tmp_u1 = v2
  60416 		v = +libc.Int32FromInt32(28800)*r3 - int32(24116)*g3 - int32(4684)*b3
  60417 		v111 = v
  60418 		v111 = (v111 + int32(YUV_HALF)<<libc.Int32FromInt32(2) + libc.Int32FromInt32(128)<<(int32(YUV_FIX)+libc.Int32FromInt32(2))) >> (int32(YUV_FIX) + libc.Int32FromInt32(2))
  60419 		if v111 & ^libc.Int32FromInt32(0xff) == 0 {
  60420 			v14 = v111
  60421 		} else {
  60422 			if v111 < 0 {
  60423 				v15 = 0
  60424 			} else {
  60425 				v15 = int32(255)
  60426 			}
  60427 			v14 = v15
  60428 		}
  60429 		v12 = v14
  60430 		goto _27
  60431 	_27:
  60432 		v9 = v12
  60433 		goto _24
  60434 	_24:
  60435 		tmp_v1 = v9
  60436 		if do_store != 0 {
  60437 			**(**uint8_t)(__ccgo_up(u1 + uintptr(i))) = uint8(tmp_u1)
  60438 			**(**uint8_t)(__ccgo_up(v1 + uintptr(i))) = uint8(tmp_v1)
  60439 		} else {
  60440 			**(**uint8_t)(__ccgo_up(u1 + uintptr(i))) = uint8((int32(**(**uint8_t)(__ccgo_up(u1 + uintptr(i)))) + tmp_u1 + int32(1)) >> int32(1))
  60441 			**(**uint8_t)(__ccgo_up(v1 + uintptr(i))) = uint8((int32(**(**uint8_t)(__ccgo_up(v1 + uintptr(i)))) + tmp_v1 + int32(1)) >> int32(1))
  60442 		}
  60443 	}
  60444 }
  60445 
  60446 //-----------------------------------------------------------------------------
  60447 
  60448 func ConvertRGB24ToY_C(tls *libc.TLS, rgb uintptr, y uintptr, width int32) {
  60449 	var i, luma, v2 int32
  60450 	_, _, _ = i, luma, v2
  60451 	i = 0
  60452 	for {
  60453 		if !(i < width) {
  60454 			break
  60455 		}
  60456 		luma = int32(16839)*int32(**(**uint8_t)(__ccgo_up(rgb))) + int32(33059)*int32(**(**uint8_t)(__ccgo_up(rgb + 1))) + int32(6420)*int32(**(**uint8_t)(__ccgo_up(rgb + 2)))
  60457 		v2 = (luma + int32(YUV_HALF) + libc.Int32FromInt32(16)<<int32(YUV_FIX)) >> int32(YUV_FIX)
  60458 		goto _3
  60459 	_3:
  60460 		**(**uint8_t)(__ccgo_up(y + uintptr(i))) = uint8(v2)
  60461 		goto _1
  60462 	_1:
  60463 		;
  60464 		i = i + 1
  60465 		rgb = rgb + uintptr(3)
  60466 	}
  60467 }
  60468 
  60469 func ConvertBGR24ToY_C(tls *libc.TLS, bgr uintptr, y uintptr, width int32) {
  60470 	var i, luma, v2 int32
  60471 	_, _, _ = i, luma, v2
  60472 	i = 0
  60473 	for {
  60474 		if !(i < width) {
  60475 			break
  60476 		}
  60477 		luma = int32(16839)*int32(**(**uint8_t)(__ccgo_up(bgr + 2))) + int32(33059)*int32(**(**uint8_t)(__ccgo_up(bgr + 1))) + int32(6420)*int32(**(**uint8_t)(__ccgo_up(bgr)))
  60478 		v2 = (luma + int32(YUV_HALF) + libc.Int32FromInt32(16)<<int32(YUV_FIX)) >> int32(YUV_FIX)
  60479 		goto _3
  60480 	_3:
  60481 		**(**uint8_t)(__ccgo_up(y + uintptr(i))) = uint8(v2)
  60482 		goto _1
  60483 	_1:
  60484 		;
  60485 		i = i + 1
  60486 		bgr = bgr + uintptr(3)
  60487 	}
  60488 }
  60489 
  60490 func WebPConvertRGBA32ToUV_C(tls *libc.TLS, rgb uintptr, u1 uintptr, v1 uintptr, width int32) {
  60491 	var b2, g2, i, r2, u, v, v2, v4, v5, v7, v8 int32
  60492 	_, _, _, _, _, _, _, _, _, _, _ = b2, g2, i, r2, u, v, v2, v4, v5, v7, v8
  60493 	i = 0
  60494 	for {
  60495 		if !(i < width) {
  60496 			break
  60497 		}
  60498 		r2 = int32(**(**uint16_t)(__ccgo_up(rgb)))
  60499 		g2 = int32(**(**uint16_t)(__ccgo_up(rgb + 1*2)))
  60500 		b2 = int32(**(**uint16_t)(__ccgo_up(rgb + 2*2)))
  60501 		u = -int32(9719)*r2 - int32(19081)*g2 + int32(28800)*b2
  60502 		v4 = u
  60503 		v4 = (v4 + int32(YUV_HALF)<<libc.Int32FromInt32(2) + libc.Int32FromInt32(128)<<(int32(YUV_FIX)+libc.Int32FromInt32(2))) >> (int32(YUV_FIX) + libc.Int32FromInt32(2))
  60504 		if v4 & ^libc.Int32FromInt32(0xff) == 0 {
  60505 			v7 = v4
  60506 		} else {
  60507 			if v4 < 0 {
  60508 				v8 = 0
  60509 			} else {
  60510 				v8 = int32(255)
  60511 			}
  60512 			v7 = v8
  60513 		}
  60514 		v5 = v7
  60515 		goto _6
  60516 	_6:
  60517 		v2 = v5
  60518 		goto _3
  60519 	_3:
  60520 		**(**uint8_t)(__ccgo_up(u1 + uintptr(i))) = uint8(v2)
  60521 		v = +libc.Int32FromInt32(28800)*r2 - int32(24116)*g2 - int32(4684)*b2
  60522 		v4 = v
  60523 		v4 = (v4 + int32(YUV_HALF)<<libc.Int32FromInt32(2) + libc.Int32FromInt32(128)<<(int32(YUV_FIX)+libc.Int32FromInt32(2))) >> (int32(YUV_FIX) + libc.Int32FromInt32(2))
  60524 		if v4 & ^libc.Int32FromInt32(0xff) == 0 {
  60525 			v7 = v4
  60526 		} else {
  60527 			if v4 < 0 {
  60528 				v8 = 0
  60529 			} else {
  60530 				v8 = int32(255)
  60531 			}
  60532 			v7 = v8
  60533 		}
  60534 		v5 = v7
  60535 		goto _13
  60536 	_13:
  60537 		v2 = v5
  60538 		goto _10
  60539 	_10:
  60540 		**(**uint8_t)(__ccgo_up(v1 + uintptr(i))) = uint8(v2)
  60541 		goto _1
  60542 	_1:
  60543 		;
  60544 		i = i + int32(1)
  60545 		rgb = rgb + uintptr(4)*2
  60546 	}
  60547 }
  60548 
  60549 func WebPInitConvertARGBToYUV(tls *libc.TLS) {
  60550 	if libc.AtomicLoadPUintptr(uintptr(unsafe.Pointer(&WebPInitConvertARGBToYUV_body_last_cpuinfo_used))) == VP8GetCPUInfo {
  60551 		goto _1
  60552 	}
  60553 	WebPInitConvertARGBToYUV_body(tls)
  60554 	libc.AtomicStorePUintptr(uintptr(unsafe.Pointer(&WebPInitConvertARGBToYUV_body_last_cpuinfo_used)), VP8GetCPUInfo)
  60555 	goto _2
  60556 _2:
  60557 	;
  60558 	goto _1
  60559 _1: /**/ //
  60560 }
  60561 
  60562 var WebPInitConvertARGBToYUV_body_last_cpuinfo_used = uintptr(0)
  60563 
  60564 func init() {
  60565 	p := unsafe.Pointer(&WebPInitConvertARGBToYUV_body_last_cpuinfo_used)
  60566 	*(*uintptr)(unsafe.Add(p, 0)) = uintptr(unsafe.Pointer(&WebPInitConvertARGBToYUV_body_last_cpuinfo_used))
  60567 }
  60568 
  60569 func WebPInitConvertARGBToYUV_body(tls *libc.TLS) {
  60570 	WebPConvertARGBToY = __ccgo_fp(ConvertARGBToY_C)
  60571 	WebPConvertARGBToUV = __ccgo_fp(WebPConvertARGBToUV_C)
  60572 	WebPConvertRGB24ToY = __ccgo_fp(ConvertRGB24ToY_C)
  60573 	WebPConvertBGR24ToY = __ccgo_fp(ConvertBGR24ToY_C)
  60574 	WebPConvertRGBA32ToUV = __ccgo_fp(WebPConvertRGBA32ToUV_C)
  60575 	if VP8GetCPUInfo != libc.UintptrFromInt32(0) {
  60576 	}
  60577 }
  60578 
  60579 const SIZE_MAX33 = "UINT64_MAX"
  60580 
  60581 func WebPInitSamplersMIPS32(tls *libc.TLS) {
  60582 }
  60583 
  60584 func WebPInitSamplersMIPSdspR2(tls *libc.TLS) {
  60585 }
  60586 
  60587 func WebPInitConvertARGBToYUVNEON(tls *libc.TLS) {
  60588 }
  60589 
  60590 func WebPInitSamplersSSE2(tls *libc.TLS) {
  60591 }
  60592 
  60593 func WebPInitConvertARGBToYUVSSE2(tls *libc.TLS) {
  60594 }
  60595 
  60596 func WebPInitSamplersSSE41(tls *libc.TLS) {
  60597 }
  60598 
  60599 func WebPInitConvertARGBToYUVSSE41(tls *libc.TLS) {
  60600 }
  60601 
  60602 type __ccgo_fp__XSharpYuvInit_0 = func(*libc.TLS, int32) int32
  60603 
  60604 func SharpYuvInit(tls *libc.TLS, __ccgo_fp_cpu_info_func VP8CPUInfo) {
  60605 	_ = __ccgo_fp_cpu_info_func
  60606 }
  60607 
  60608 func SharpYuvGetConversionMatrix(tls *libc.TLS, matrix_type SharpYuvMatrixType) (r uintptr) {
  60609 	_ = matrix_type
  60610 	return libc.UintptrFromInt32(0)
  60611 }
  60612 
  60613 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) {
  60614 	_ = r_ptr
  60615 	_ = g_ptr
  60616 	_ = b_ptr
  60617 	_ = rgb_step
  60618 	_ = rgb_stride
  60619 	_ = rgb_bit_depth
  60620 	_ = y_ptr
  60621 	_ = y_stride
  60622 	_ = u_ptr
  60623 	_ = u_stride
  60624 	_ = v_ptr
  60625 	_ = v_stride
  60626 	_ = yuv_bit_depth
  60627 	_ = width
  60628 	_ = height
  60629 	_ = yuv_matrix
  60630 	return 0
  60631 }
  60632 
  60633 func __ccgo_fp(f interface{}) uintptr {
  60634 	type iface [2]uintptr
  60635 	return (*iface)(unsafe.Pointer(&f))[1]
  60636 }
  60637 
  60638 func __ccgo_up(n uintptr) unsafe.Pointer {
  60639 	return unsafe.Pointer(&n)
  60640 }
  60641 
  60642 var VP8AccumulateSSE VP8AccumulateSSEFunc
  60643 
  60644 //------------------------------------------------------------------------------
  60645 // Tables for level coding
  60646 
  60647 var VP8Cat3 = [3]uint8_t{
  60648 	0: uint8(173),
  60649 	1: uint8(148),
  60650 	2: uint8(140),
  60651 }
  60652 
  60653 var VP8Cat4 = [4]uint8_t{
  60654 	0: uint8(176),
  60655 	1: uint8(155),
  60656 	2: uint8(140),
  60657 	3: uint8(135),
  60658 }
  60659 
  60660 var VP8Cat5 = [5]uint8_t{
  60661 	0: uint8(180),
  60662 	1: uint8(157),
  60663 	2: uint8(141),
  60664 	3: uint8(134),
  60665 	4: uint8(130),
  60666 }
  60667 
  60668 var VP8Cat6 = [11]uint8_t{
  60669 	0:  uint8(254),
  60670 	1:  uint8(254),
  60671 	2:  uint8(243),
  60672 	3:  uint8(230),
  60673 	4:  uint8(196),
  60674 	5:  uint8(177),
  60675 	6:  uint8(153),
  60676 	7:  uint8(140),
  60677 	8:  uint8(133),
  60678 	9:  uint8(130),
  60679 	10: uint8(129),
  60680 }
  60681 
  60682 //------------------------------------------------------------------------------
  60683 
  60684 // Copyright 2011 Google Inc. All Rights Reserved.
  60685 //
  60686 // Use of this source code is governed by a BSD-style license
  60687 // that can be found in the COPYING file in the root of the source
  60688 // tree. An additional intellectual property rights grant can be found
  60689 // in the file PATENTS. All contributing project authors may
  60690 // be found in the AUTHORS file in the root of the source tree.
  60691 // -----------------------------------------------------------------------------
  60692 //
  60693 // Bit writing and boolean coder
  60694 //
  60695 // Author: Skal (pascal.massimino@gmail.com)
  60696 
  60697 //------------------------------------------------------------------------------
  60698 // Default probabilities
  60699 
  60700 // C documentation
  60701 //
  60702 //	// Paragraph 13.5
  60703 
  60704 var VP8CoeffsProba0 = [4][8][3][11]uint8_t{
  60705 	0: {
  60706 		0: {
  60707 			0: {
  60708 				0:  uint8(128),
  60709 				1:  uint8(128),
  60710 				2:  uint8(128),
  60711 				3:  uint8(128),
  60712 				4:  uint8(128),
  60713 				5:  uint8(128),
  60714 				6:  uint8(128),
  60715 				7:  uint8(128),
  60716 				8:  uint8(128),
  60717 				9:  uint8(128),
  60718 				10: uint8(128),
  60719 			},
  60720 			1: {
  60721 				0:  uint8(128),
  60722 				1:  uint8(128),
  60723 				2:  uint8(128),
  60724 				3:  uint8(128),
  60725 				4:  uint8(128),
  60726 				5:  uint8(128),
  60727 				6:  uint8(128),
  60728 				7:  uint8(128),
  60729 				8:  uint8(128),
  60730 				9:  uint8(128),
  60731 				10: uint8(128),
  60732 			},
  60733 			2: {
  60734 				0:  uint8(128),
  60735 				1:  uint8(128),
  60736 				2:  uint8(128),
  60737 				3:  uint8(128),
  60738 				4:  uint8(128),
  60739 				5:  uint8(128),
  60740 				6:  uint8(128),
  60741 				7:  uint8(128),
  60742 				8:  uint8(128),
  60743 				9:  uint8(128),
  60744 				10: uint8(128),
  60745 			},
  60746 		},
  60747 		1: {
  60748 			0: {
  60749 				0:  uint8(253),
  60750 				1:  uint8(136),
  60751 				2:  uint8(254),
  60752 				3:  uint8(255),
  60753 				4:  uint8(228),
  60754 				5:  uint8(219),
  60755 				6:  uint8(128),
  60756 				7:  uint8(128),
  60757 				8:  uint8(128),
  60758 				9:  uint8(128),
  60759 				10: uint8(128),
  60760 			},
  60761 			1: {
  60762 				0:  uint8(189),
  60763 				1:  uint8(129),
  60764 				2:  uint8(242),
  60765 				3:  uint8(255),
  60766 				4:  uint8(227),
  60767 				5:  uint8(213),
  60768 				6:  uint8(255),
  60769 				7:  uint8(219),
  60770 				8:  uint8(128),
  60771 				9:  uint8(128),
  60772 				10: uint8(128),
  60773 			},
  60774 			2: {
  60775 				0:  uint8(106),
  60776 				1:  uint8(126),
  60777 				2:  uint8(227),
  60778 				3:  uint8(252),
  60779 				4:  uint8(214),
  60780 				5:  uint8(209),
  60781 				6:  uint8(255),
  60782 				7:  uint8(255),
  60783 				8:  uint8(128),
  60784 				9:  uint8(128),
  60785 				10: uint8(128),
  60786 			},
  60787 		},
  60788 		2: {
  60789 			0: {
  60790 				0:  uint8(1),
  60791 				1:  uint8(98),
  60792 				2:  uint8(248),
  60793 				3:  uint8(255),
  60794 				4:  uint8(236),
  60795 				5:  uint8(226),
  60796 				6:  uint8(255),
  60797 				7:  uint8(255),
  60798 				8:  uint8(128),
  60799 				9:  uint8(128),
  60800 				10: uint8(128),
  60801 			},
  60802 			1: {
  60803 				0:  uint8(181),
  60804 				1:  uint8(133),
  60805 				2:  uint8(238),
  60806 				3:  uint8(254),
  60807 				4:  uint8(221),
  60808 				5:  uint8(234),
  60809 				6:  uint8(255),
  60810 				7:  uint8(154),
  60811 				8:  uint8(128),
  60812 				9:  uint8(128),
  60813 				10: uint8(128),
  60814 			},
  60815 			2: {
  60816 				0:  uint8(78),
  60817 				1:  uint8(134),
  60818 				2:  uint8(202),
  60819 				3:  uint8(247),
  60820 				4:  uint8(198),
  60821 				5:  uint8(180),
  60822 				6:  uint8(255),
  60823 				7:  uint8(219),
  60824 				8:  uint8(128),
  60825 				9:  uint8(128),
  60826 				10: uint8(128),
  60827 			},
  60828 		},
  60829 		3: {
  60830 			0: {
  60831 				0:  uint8(1),
  60832 				1:  uint8(185),
  60833 				2:  uint8(249),
  60834 				3:  uint8(255),
  60835 				4:  uint8(243),
  60836 				5:  uint8(255),
  60837 				6:  uint8(128),
  60838 				7:  uint8(128),
  60839 				8:  uint8(128),
  60840 				9:  uint8(128),
  60841 				10: uint8(128),
  60842 			},
  60843 			1: {
  60844 				0:  uint8(184),
  60845 				1:  uint8(150),
  60846 				2:  uint8(247),
  60847 				3:  uint8(255),
  60848 				4:  uint8(236),
  60849 				5:  uint8(224),
  60850 				6:  uint8(128),
  60851 				7:  uint8(128),
  60852 				8:  uint8(128),
  60853 				9:  uint8(128),
  60854 				10: uint8(128),
  60855 			},
  60856 			2: {
  60857 				0:  uint8(77),
  60858 				1:  uint8(110),
  60859 				2:  uint8(216),
  60860 				3:  uint8(255),
  60861 				4:  uint8(236),
  60862 				5:  uint8(230),
  60863 				6:  uint8(128),
  60864 				7:  uint8(128),
  60865 				8:  uint8(128),
  60866 				9:  uint8(128),
  60867 				10: uint8(128),
  60868 			},
  60869 		},
  60870 		4: {
  60871 			0: {
  60872 				0:  uint8(1),
  60873 				1:  uint8(101),
  60874 				2:  uint8(251),
  60875 				3:  uint8(255),
  60876 				4:  uint8(241),
  60877 				5:  uint8(255),
  60878 				6:  uint8(128),
  60879 				7:  uint8(128),
  60880 				8:  uint8(128),
  60881 				9:  uint8(128),
  60882 				10: uint8(128),
  60883 			},
  60884 			1: {
  60885 				0:  uint8(170),
  60886 				1:  uint8(139),
  60887 				2:  uint8(241),
  60888 				3:  uint8(252),
  60889 				4:  uint8(236),
  60890 				5:  uint8(209),
  60891 				6:  uint8(255),
  60892 				7:  uint8(255),
  60893 				8:  uint8(128),
  60894 				9:  uint8(128),
  60895 				10: uint8(128),
  60896 			},
  60897 			2: {
  60898 				0:  uint8(37),
  60899 				1:  uint8(116),
  60900 				2:  uint8(196),
  60901 				3:  uint8(243),
  60902 				4:  uint8(228),
  60903 				5:  uint8(255),
  60904 				6:  uint8(255),
  60905 				7:  uint8(255),
  60906 				8:  uint8(128),
  60907 				9:  uint8(128),
  60908 				10: uint8(128),
  60909 			},
  60910 		},
  60911 		5: {
  60912 			0: {
  60913 				0:  uint8(1),
  60914 				1:  uint8(204),
  60915 				2:  uint8(254),
  60916 				3:  uint8(255),
  60917 				4:  uint8(245),
  60918 				5:  uint8(255),
  60919 				6:  uint8(128),
  60920 				7:  uint8(128),
  60921 				8:  uint8(128),
  60922 				9:  uint8(128),
  60923 				10: uint8(128),
  60924 			},
  60925 			1: {
  60926 				0:  uint8(207),
  60927 				1:  uint8(160),
  60928 				2:  uint8(250),
  60929 				3:  uint8(255),
  60930 				4:  uint8(238),
  60931 				5:  uint8(128),
  60932 				6:  uint8(128),
  60933 				7:  uint8(128),
  60934 				8:  uint8(128),
  60935 				9:  uint8(128),
  60936 				10: uint8(128),
  60937 			},
  60938 			2: {
  60939 				0:  uint8(102),
  60940 				1:  uint8(103),
  60941 				2:  uint8(231),
  60942 				3:  uint8(255),
  60943 				4:  uint8(211),
  60944 				5:  uint8(171),
  60945 				6:  uint8(128),
  60946 				7:  uint8(128),
  60947 				8:  uint8(128),
  60948 				9:  uint8(128),
  60949 				10: uint8(128),
  60950 			},
  60951 		},
  60952 		6: {
  60953 			0: {
  60954 				0:  uint8(1),
  60955 				1:  uint8(152),
  60956 				2:  uint8(252),
  60957 				3:  uint8(255),
  60958 				4:  uint8(240),
  60959 				5:  uint8(255),
  60960 				6:  uint8(128),
  60961 				7:  uint8(128),
  60962 				8:  uint8(128),
  60963 				9:  uint8(128),
  60964 				10: uint8(128),
  60965 			},
  60966 			1: {
  60967 				0:  uint8(177),
  60968 				1:  uint8(135),
  60969 				2:  uint8(243),
  60970 				3:  uint8(255),
  60971 				4:  uint8(234),
  60972 				5:  uint8(225),
  60973 				6:  uint8(128),
  60974 				7:  uint8(128),
  60975 				8:  uint8(128),
  60976 				9:  uint8(128),
  60977 				10: uint8(128),
  60978 			},
  60979 			2: {
  60980 				0:  uint8(80),
  60981 				1:  uint8(129),
  60982 				2:  uint8(211),
  60983 				3:  uint8(255),
  60984 				4:  uint8(194),
  60985 				5:  uint8(224),
  60986 				6:  uint8(128),
  60987 				7:  uint8(128),
  60988 				8:  uint8(128),
  60989 				9:  uint8(128),
  60990 				10: uint8(128),
  60991 			},
  60992 		},
  60993 		7: {
  60994 			0: {
  60995 				0:  uint8(1),
  60996 				1:  uint8(1),
  60997 				2:  uint8(255),
  60998 				3:  uint8(128),
  60999 				4:  uint8(128),
  61000 				5:  uint8(128),
  61001 				6:  uint8(128),
  61002 				7:  uint8(128),
  61003 				8:  uint8(128),
  61004 				9:  uint8(128),
  61005 				10: uint8(128),
  61006 			},
  61007 			1: {
  61008 				0:  uint8(246),
  61009 				1:  uint8(1),
  61010 				2:  uint8(255),
  61011 				3:  uint8(128),
  61012 				4:  uint8(128),
  61013 				5:  uint8(128),
  61014 				6:  uint8(128),
  61015 				7:  uint8(128),
  61016 				8:  uint8(128),
  61017 				9:  uint8(128),
  61018 				10: uint8(128),
  61019 			},
  61020 			2: {
  61021 				0:  uint8(255),
  61022 				1:  uint8(128),
  61023 				2:  uint8(128),
  61024 				3:  uint8(128),
  61025 				4:  uint8(128),
  61026 				5:  uint8(128),
  61027 				6:  uint8(128),
  61028 				7:  uint8(128),
  61029 				8:  uint8(128),
  61030 				9:  uint8(128),
  61031 				10: uint8(128),
  61032 			},
  61033 		},
  61034 	},
  61035 	1: {
  61036 		0: {
  61037 			0: {
  61038 				0:  uint8(198),
  61039 				1:  uint8(35),
  61040 				2:  uint8(237),
  61041 				3:  uint8(223),
  61042 				4:  uint8(193),
  61043 				5:  uint8(187),
  61044 				6:  uint8(162),
  61045 				7:  uint8(160),
  61046 				8:  uint8(145),
  61047 				9:  uint8(155),
  61048 				10: uint8(62),
  61049 			},
  61050 			1: {
  61051 				0:  uint8(131),
  61052 				1:  uint8(45),
  61053 				2:  uint8(198),
  61054 				3:  uint8(221),
  61055 				4:  uint8(172),
  61056 				5:  uint8(176),
  61057 				6:  uint8(220),
  61058 				7:  uint8(157),
  61059 				8:  uint8(252),
  61060 				9:  uint8(221),
  61061 				10: uint8(1),
  61062 			},
  61063 			2: {
  61064 				0:  uint8(68),
  61065 				1:  uint8(47),
  61066 				2:  uint8(146),
  61067 				3:  uint8(208),
  61068 				4:  uint8(149),
  61069 				5:  uint8(167),
  61070 				6:  uint8(221),
  61071 				7:  uint8(162),
  61072 				8:  uint8(255),
  61073 				9:  uint8(223),
  61074 				10: uint8(128),
  61075 			},
  61076 		},
  61077 		1: {
  61078 			0: {
  61079 				0:  uint8(1),
  61080 				1:  uint8(149),
  61081 				2:  uint8(241),
  61082 				3:  uint8(255),
  61083 				4:  uint8(221),
  61084 				5:  uint8(224),
  61085 				6:  uint8(255),
  61086 				7:  uint8(255),
  61087 				8:  uint8(128),
  61088 				9:  uint8(128),
  61089 				10: uint8(128),
  61090 			},
  61091 			1: {
  61092 				0:  uint8(184),
  61093 				1:  uint8(141),
  61094 				2:  uint8(234),
  61095 				3:  uint8(253),
  61096 				4:  uint8(222),
  61097 				5:  uint8(220),
  61098 				6:  uint8(255),
  61099 				7:  uint8(199),
  61100 				8:  uint8(128),
  61101 				9:  uint8(128),
  61102 				10: uint8(128),
  61103 			},
  61104 			2: {
  61105 				0:  uint8(81),
  61106 				1:  uint8(99),
  61107 				2:  uint8(181),
  61108 				3:  uint8(242),
  61109 				4:  uint8(176),
  61110 				5:  uint8(190),
  61111 				6:  uint8(249),
  61112 				7:  uint8(202),
  61113 				8:  uint8(255),
  61114 				9:  uint8(255),
  61115 				10: uint8(128),
  61116 			},
  61117 		},
  61118 		2: {
  61119 			0: {
  61120 				0:  uint8(1),
  61121 				1:  uint8(129),
  61122 				2:  uint8(232),
  61123 				3:  uint8(253),
  61124 				4:  uint8(214),
  61125 				5:  uint8(197),
  61126 				6:  uint8(242),
  61127 				7:  uint8(196),
  61128 				8:  uint8(255),
  61129 				9:  uint8(255),
  61130 				10: uint8(128),
  61131 			},
  61132 			1: {
  61133 				0:  uint8(99),
  61134 				1:  uint8(121),
  61135 				2:  uint8(210),
  61136 				3:  uint8(250),
  61137 				4:  uint8(201),
  61138 				5:  uint8(198),
  61139 				6:  uint8(255),
  61140 				7:  uint8(202),
  61141 				8:  uint8(128),
  61142 				9:  uint8(128),
  61143 				10: uint8(128),
  61144 			},
  61145 			2: {
  61146 				0:  uint8(23),
  61147 				1:  uint8(91),
  61148 				2:  uint8(163),
  61149 				3:  uint8(242),
  61150 				4:  uint8(170),
  61151 				5:  uint8(187),
  61152 				6:  uint8(247),
  61153 				7:  uint8(210),
  61154 				8:  uint8(255),
  61155 				9:  uint8(255),
  61156 				10: uint8(128),
  61157 			},
  61158 		},
  61159 		3: {
  61160 			0: {
  61161 				0:  uint8(1),
  61162 				1:  uint8(200),
  61163 				2:  uint8(246),
  61164 				3:  uint8(255),
  61165 				4:  uint8(234),
  61166 				5:  uint8(255),
  61167 				6:  uint8(128),
  61168 				7:  uint8(128),
  61169 				8:  uint8(128),
  61170 				9:  uint8(128),
  61171 				10: uint8(128),
  61172 			},
  61173 			1: {
  61174 				0:  uint8(109),
  61175 				1:  uint8(178),
  61176 				2:  uint8(241),
  61177 				3:  uint8(255),
  61178 				4:  uint8(231),
  61179 				5:  uint8(245),
  61180 				6:  uint8(255),
  61181 				7:  uint8(255),
  61182 				8:  uint8(128),
  61183 				9:  uint8(128),
  61184 				10: uint8(128),
  61185 			},
  61186 			2: {
  61187 				0:  uint8(44),
  61188 				1:  uint8(130),
  61189 				2:  uint8(201),
  61190 				3:  uint8(253),
  61191 				4:  uint8(205),
  61192 				5:  uint8(192),
  61193 				6:  uint8(255),
  61194 				7:  uint8(255),
  61195 				8:  uint8(128),
  61196 				9:  uint8(128),
  61197 				10: uint8(128),
  61198 			},
  61199 		},
  61200 		4: {
  61201 			0: {
  61202 				0:  uint8(1),
  61203 				1:  uint8(132),
  61204 				2:  uint8(239),
  61205 				3:  uint8(251),
  61206 				4:  uint8(219),
  61207 				5:  uint8(209),
  61208 				6:  uint8(255),
  61209 				7:  uint8(165),
  61210 				8:  uint8(128),
  61211 				9:  uint8(128),
  61212 				10: uint8(128),
  61213 			},
  61214 			1: {
  61215 				0:  uint8(94),
  61216 				1:  uint8(136),
  61217 				2:  uint8(225),
  61218 				3:  uint8(251),
  61219 				4:  uint8(218),
  61220 				5:  uint8(190),
  61221 				6:  uint8(255),
  61222 				7:  uint8(255),
  61223 				8:  uint8(128),
  61224 				9:  uint8(128),
  61225 				10: uint8(128),
  61226 			},
  61227 			2: {
  61228 				0:  uint8(22),
  61229 				1:  uint8(100),
  61230 				2:  uint8(174),
  61231 				3:  uint8(245),
  61232 				4:  uint8(186),
  61233 				5:  uint8(161),
  61234 				6:  uint8(255),
  61235 				7:  uint8(199),
  61236 				8:  uint8(128),
  61237 				9:  uint8(128),
  61238 				10: uint8(128),
  61239 			},
  61240 		},
  61241 		5: {
  61242 			0: {
  61243 				0:  uint8(1),
  61244 				1:  uint8(182),
  61245 				2:  uint8(249),
  61246 				3:  uint8(255),
  61247 				4:  uint8(232),
  61248 				5:  uint8(235),
  61249 				6:  uint8(128),
  61250 				7:  uint8(128),
  61251 				8:  uint8(128),
  61252 				9:  uint8(128),
  61253 				10: uint8(128),
  61254 			},
  61255 			1: {
  61256 				0:  uint8(124),
  61257 				1:  uint8(143),
  61258 				2:  uint8(241),
  61259 				3:  uint8(255),
  61260 				4:  uint8(227),
  61261 				5:  uint8(234),
  61262 				6:  uint8(128),
  61263 				7:  uint8(128),
  61264 				8:  uint8(128),
  61265 				9:  uint8(128),
  61266 				10: uint8(128),
  61267 			},
  61268 			2: {
  61269 				0:  uint8(35),
  61270 				1:  uint8(77),
  61271 				2:  uint8(181),
  61272 				3:  uint8(251),
  61273 				4:  uint8(193),
  61274 				5:  uint8(211),
  61275 				6:  uint8(255),
  61276 				7:  uint8(205),
  61277 				8:  uint8(128),
  61278 				9:  uint8(128),
  61279 				10: uint8(128),
  61280 			},
  61281 		},
  61282 		6: {
  61283 			0: {
  61284 				0:  uint8(1),
  61285 				1:  uint8(157),
  61286 				2:  uint8(247),
  61287 				3:  uint8(255),
  61288 				4:  uint8(236),
  61289 				5:  uint8(231),
  61290 				6:  uint8(255),
  61291 				7:  uint8(255),
  61292 				8:  uint8(128),
  61293 				9:  uint8(128),
  61294 				10: uint8(128),
  61295 			},
  61296 			1: {
  61297 				0:  uint8(121),
  61298 				1:  uint8(141),
  61299 				2:  uint8(235),
  61300 				3:  uint8(255),
  61301 				4:  uint8(225),
  61302 				5:  uint8(227),
  61303 				6:  uint8(255),
  61304 				7:  uint8(255),
  61305 				8:  uint8(128),
  61306 				9:  uint8(128),
  61307 				10: uint8(128),
  61308 			},
  61309 			2: {
  61310 				0:  uint8(45),
  61311 				1:  uint8(99),
  61312 				2:  uint8(188),
  61313 				3:  uint8(251),
  61314 				4:  uint8(195),
  61315 				5:  uint8(217),
  61316 				6:  uint8(255),
  61317 				7:  uint8(224),
  61318 				8:  uint8(128),
  61319 				9:  uint8(128),
  61320 				10: uint8(128),
  61321 			},
  61322 		},
  61323 		7: {
  61324 			0: {
  61325 				0:  uint8(1),
  61326 				1:  uint8(1),
  61327 				2:  uint8(251),
  61328 				3:  uint8(255),
  61329 				4:  uint8(213),
  61330 				5:  uint8(255),
  61331 				6:  uint8(128),
  61332 				7:  uint8(128),
  61333 				8:  uint8(128),
  61334 				9:  uint8(128),
  61335 				10: uint8(128),
  61336 			},
  61337 			1: {
  61338 				0:  uint8(203),
  61339 				1:  uint8(1),
  61340 				2:  uint8(248),
  61341 				3:  uint8(255),
  61342 				4:  uint8(255),
  61343 				5:  uint8(128),
  61344 				6:  uint8(128),
  61345 				7:  uint8(128),
  61346 				8:  uint8(128),
  61347 				9:  uint8(128),
  61348 				10: uint8(128),
  61349 			},
  61350 			2: {
  61351 				0:  uint8(137),
  61352 				1:  uint8(1),
  61353 				2:  uint8(177),
  61354 				3:  uint8(255),
  61355 				4:  uint8(224),
  61356 				5:  uint8(255),
  61357 				6:  uint8(128),
  61358 				7:  uint8(128),
  61359 				8:  uint8(128),
  61360 				9:  uint8(128),
  61361 				10: uint8(128),
  61362 			},
  61363 		},
  61364 	},
  61365 	2: {
  61366 		0: {
  61367 			0: {
  61368 				0:  uint8(253),
  61369 				1:  uint8(9),
  61370 				2:  uint8(248),
  61371 				3:  uint8(251),
  61372 				4:  uint8(207),
  61373 				5:  uint8(208),
  61374 				6:  uint8(255),
  61375 				7:  uint8(192),
  61376 				8:  uint8(128),
  61377 				9:  uint8(128),
  61378 				10: uint8(128),
  61379 			},
  61380 			1: {
  61381 				0:  uint8(175),
  61382 				1:  uint8(13),
  61383 				2:  uint8(224),
  61384 				3:  uint8(243),
  61385 				4:  uint8(193),
  61386 				5:  uint8(185),
  61387 				6:  uint8(249),
  61388 				7:  uint8(198),
  61389 				8:  uint8(255),
  61390 				9:  uint8(255),
  61391 				10: uint8(128),
  61392 			},
  61393 			2: {
  61394 				0:  uint8(73),
  61395 				1:  uint8(17),
  61396 				2:  uint8(171),
  61397 				3:  uint8(221),
  61398 				4:  uint8(161),
  61399 				5:  uint8(179),
  61400 				6:  uint8(236),
  61401 				7:  uint8(167),
  61402 				8:  uint8(255),
  61403 				9:  uint8(234),
  61404 				10: uint8(128),
  61405 			},
  61406 		},
  61407 		1: {
  61408 			0: {
  61409 				0:  uint8(1),
  61410 				1:  uint8(95),
  61411 				2:  uint8(247),
  61412 				3:  uint8(253),
  61413 				4:  uint8(212),
  61414 				5:  uint8(183),
  61415 				6:  uint8(255),
  61416 				7:  uint8(255),
  61417 				8:  uint8(128),
  61418 				9:  uint8(128),
  61419 				10: uint8(128),
  61420 			},
  61421 			1: {
  61422 				0:  uint8(239),
  61423 				1:  uint8(90),
  61424 				2:  uint8(244),
  61425 				3:  uint8(250),
  61426 				4:  uint8(211),
  61427 				5:  uint8(209),
  61428 				6:  uint8(255),
  61429 				7:  uint8(255),
  61430 				8:  uint8(128),
  61431 				9:  uint8(128),
  61432 				10: uint8(128),
  61433 			},
  61434 			2: {
  61435 				0:  uint8(155),
  61436 				1:  uint8(77),
  61437 				2:  uint8(195),
  61438 				3:  uint8(248),
  61439 				4:  uint8(188),
  61440 				5:  uint8(195),
  61441 				6:  uint8(255),
  61442 				7:  uint8(255),
  61443 				8:  uint8(128),
  61444 				9:  uint8(128),
  61445 				10: uint8(128),
  61446 			},
  61447 		},
  61448 		2: {
  61449 			0: {
  61450 				0:  uint8(1),
  61451 				1:  uint8(24),
  61452 				2:  uint8(239),
  61453 				3:  uint8(251),
  61454 				4:  uint8(218),
  61455 				5:  uint8(219),
  61456 				6:  uint8(255),
  61457 				7:  uint8(205),
  61458 				8:  uint8(128),
  61459 				9:  uint8(128),
  61460 				10: uint8(128),
  61461 			},
  61462 			1: {
  61463 				0:  uint8(201),
  61464 				1:  uint8(51),
  61465 				2:  uint8(219),
  61466 				3:  uint8(255),
  61467 				4:  uint8(196),
  61468 				5:  uint8(186),
  61469 				6:  uint8(128),
  61470 				7:  uint8(128),
  61471 				8:  uint8(128),
  61472 				9:  uint8(128),
  61473 				10: uint8(128),
  61474 			},
  61475 			2: {
  61476 				0:  uint8(69),
  61477 				1:  uint8(46),
  61478 				2:  uint8(190),
  61479 				3:  uint8(239),
  61480 				4:  uint8(201),
  61481 				5:  uint8(218),
  61482 				6:  uint8(255),
  61483 				7:  uint8(228),
  61484 				8:  uint8(128),
  61485 				9:  uint8(128),
  61486 				10: uint8(128),
  61487 			},
  61488 		},
  61489 		3: {
  61490 			0: {
  61491 				0:  uint8(1),
  61492 				1:  uint8(191),
  61493 				2:  uint8(251),
  61494 				3:  uint8(255),
  61495 				4:  uint8(255),
  61496 				5:  uint8(128),
  61497 				6:  uint8(128),
  61498 				7:  uint8(128),
  61499 				8:  uint8(128),
  61500 				9:  uint8(128),
  61501 				10: uint8(128),
  61502 			},
  61503 			1: {
  61504 				0:  uint8(223),
  61505 				1:  uint8(165),
  61506 				2:  uint8(249),
  61507 				3:  uint8(255),
  61508 				4:  uint8(213),
  61509 				5:  uint8(255),
  61510 				6:  uint8(128),
  61511 				7:  uint8(128),
  61512 				8:  uint8(128),
  61513 				9:  uint8(128),
  61514 				10: uint8(128),
  61515 			},
  61516 			2: {
  61517 				0:  uint8(141),
  61518 				1:  uint8(124),
  61519 				2:  uint8(248),
  61520 				3:  uint8(255),
  61521 				4:  uint8(255),
  61522 				5:  uint8(128),
  61523 				6:  uint8(128),
  61524 				7:  uint8(128),
  61525 				8:  uint8(128),
  61526 				9:  uint8(128),
  61527 				10: uint8(128),
  61528 			},
  61529 		},
  61530 		4: {
  61531 			0: {
  61532 				0:  uint8(1),
  61533 				1:  uint8(16),
  61534 				2:  uint8(248),
  61535 				3:  uint8(255),
  61536 				4:  uint8(255),
  61537 				5:  uint8(128),
  61538 				6:  uint8(128),
  61539 				7:  uint8(128),
  61540 				8:  uint8(128),
  61541 				9:  uint8(128),
  61542 				10: uint8(128),
  61543 			},
  61544 			1: {
  61545 				0:  uint8(190),
  61546 				1:  uint8(36),
  61547 				2:  uint8(230),
  61548 				3:  uint8(255),
  61549 				4:  uint8(236),
  61550 				5:  uint8(255),
  61551 				6:  uint8(128),
  61552 				7:  uint8(128),
  61553 				8:  uint8(128),
  61554 				9:  uint8(128),
  61555 				10: uint8(128),
  61556 			},
  61557 			2: {
  61558 				0:  uint8(149),
  61559 				1:  uint8(1),
  61560 				2:  uint8(255),
  61561 				3:  uint8(128),
  61562 				4:  uint8(128),
  61563 				5:  uint8(128),
  61564 				6:  uint8(128),
  61565 				7:  uint8(128),
  61566 				8:  uint8(128),
  61567 				9:  uint8(128),
  61568 				10: uint8(128),
  61569 			},
  61570 		},
  61571 		5: {
  61572 			0: {
  61573 				0:  uint8(1),
  61574 				1:  uint8(226),
  61575 				2:  uint8(255),
  61576 				3:  uint8(128),
  61577 				4:  uint8(128),
  61578 				5:  uint8(128),
  61579 				6:  uint8(128),
  61580 				7:  uint8(128),
  61581 				8:  uint8(128),
  61582 				9:  uint8(128),
  61583 				10: uint8(128),
  61584 			},
  61585 			1: {
  61586 				0:  uint8(247),
  61587 				1:  uint8(192),
  61588 				2:  uint8(255),
  61589 				3:  uint8(128),
  61590 				4:  uint8(128),
  61591 				5:  uint8(128),
  61592 				6:  uint8(128),
  61593 				7:  uint8(128),
  61594 				8:  uint8(128),
  61595 				9:  uint8(128),
  61596 				10: uint8(128),
  61597 			},
  61598 			2: {
  61599 				0:  uint8(240),
  61600 				1:  uint8(128),
  61601 				2:  uint8(255),
  61602 				3:  uint8(128),
  61603 				4:  uint8(128),
  61604 				5:  uint8(128),
  61605 				6:  uint8(128),
  61606 				7:  uint8(128),
  61607 				8:  uint8(128),
  61608 				9:  uint8(128),
  61609 				10: uint8(128),
  61610 			},
  61611 		},
  61612 		6: {
  61613 			0: {
  61614 				0:  uint8(1),
  61615 				1:  uint8(134),
  61616 				2:  uint8(252),
  61617 				3:  uint8(255),
  61618 				4:  uint8(255),
  61619 				5:  uint8(128),
  61620 				6:  uint8(128),
  61621 				7:  uint8(128),
  61622 				8:  uint8(128),
  61623 				9:  uint8(128),
  61624 				10: uint8(128),
  61625 			},
  61626 			1: {
  61627 				0:  uint8(213),
  61628 				1:  uint8(62),
  61629 				2:  uint8(250),
  61630 				3:  uint8(255),
  61631 				4:  uint8(255),
  61632 				5:  uint8(128),
  61633 				6:  uint8(128),
  61634 				7:  uint8(128),
  61635 				8:  uint8(128),
  61636 				9:  uint8(128),
  61637 				10: uint8(128),
  61638 			},
  61639 			2: {
  61640 				0:  uint8(55),
  61641 				1:  uint8(93),
  61642 				2:  uint8(255),
  61643 				3:  uint8(128),
  61644 				4:  uint8(128),
  61645 				5:  uint8(128),
  61646 				6:  uint8(128),
  61647 				7:  uint8(128),
  61648 				8:  uint8(128),
  61649 				9:  uint8(128),
  61650 				10: uint8(128),
  61651 			},
  61652 		},
  61653 		7: {
  61654 			0: {
  61655 				0:  uint8(128),
  61656 				1:  uint8(128),
  61657 				2:  uint8(128),
  61658 				3:  uint8(128),
  61659 				4:  uint8(128),
  61660 				5:  uint8(128),
  61661 				6:  uint8(128),
  61662 				7:  uint8(128),
  61663 				8:  uint8(128),
  61664 				9:  uint8(128),
  61665 				10: uint8(128),
  61666 			},
  61667 			1: {
  61668 				0:  uint8(128),
  61669 				1:  uint8(128),
  61670 				2:  uint8(128),
  61671 				3:  uint8(128),
  61672 				4:  uint8(128),
  61673 				5:  uint8(128),
  61674 				6:  uint8(128),
  61675 				7:  uint8(128),
  61676 				8:  uint8(128),
  61677 				9:  uint8(128),
  61678 				10: uint8(128),
  61679 			},
  61680 			2: {
  61681 				0:  uint8(128),
  61682 				1:  uint8(128),
  61683 				2:  uint8(128),
  61684 				3:  uint8(128),
  61685 				4:  uint8(128),
  61686 				5:  uint8(128),
  61687 				6:  uint8(128),
  61688 				7:  uint8(128),
  61689 				8:  uint8(128),
  61690 				9:  uint8(128),
  61691 				10: uint8(128),
  61692 			},
  61693 		},
  61694 	},
  61695 	3: {
  61696 		0: {
  61697 			0: {
  61698 				0:  uint8(202),
  61699 				1:  uint8(24),
  61700 				2:  uint8(213),
  61701 				3:  uint8(235),
  61702 				4:  uint8(186),
  61703 				5:  uint8(191),
  61704 				6:  uint8(220),
  61705 				7:  uint8(160),
  61706 				8:  uint8(240),
  61707 				9:  uint8(175),
  61708 				10: uint8(255),
  61709 			},
  61710 			1: {
  61711 				0:  uint8(126),
  61712 				1:  uint8(38),
  61713 				2:  uint8(182),
  61714 				3:  uint8(232),
  61715 				4:  uint8(169),
  61716 				5:  uint8(184),
  61717 				6:  uint8(228),
  61718 				7:  uint8(174),
  61719 				8:  uint8(255),
  61720 				9:  uint8(187),
  61721 				10: uint8(128),
  61722 			},
  61723 			2: {
  61724 				0:  uint8(61),
  61725 				1:  uint8(46),
  61726 				2:  uint8(138),
  61727 				3:  uint8(219),
  61728 				4:  uint8(151),
  61729 				5:  uint8(178),
  61730 				6:  uint8(240),
  61731 				7:  uint8(170),
  61732 				8:  uint8(255),
  61733 				9:  uint8(216),
  61734 				10: uint8(128),
  61735 			},
  61736 		},
  61737 		1: {
  61738 			0: {
  61739 				0:  uint8(1),
  61740 				1:  uint8(112),
  61741 				2:  uint8(230),
  61742 				3:  uint8(250),
  61743 				4:  uint8(199),
  61744 				5:  uint8(191),
  61745 				6:  uint8(247),
  61746 				7:  uint8(159),
  61747 				8:  uint8(255),
  61748 				9:  uint8(255),
  61749 				10: uint8(128),
  61750 			},
  61751 			1: {
  61752 				0:  uint8(166),
  61753 				1:  uint8(109),
  61754 				2:  uint8(228),
  61755 				3:  uint8(252),
  61756 				4:  uint8(211),
  61757 				5:  uint8(215),
  61758 				6:  uint8(255),
  61759 				7:  uint8(174),
  61760 				8:  uint8(128),
  61761 				9:  uint8(128),
  61762 				10: uint8(128),
  61763 			},
  61764 			2: {
  61765 				0:  uint8(39),
  61766 				1:  uint8(77),
  61767 				2:  uint8(162),
  61768 				3:  uint8(232),
  61769 				4:  uint8(172),
  61770 				5:  uint8(180),
  61771 				6:  uint8(245),
  61772 				7:  uint8(178),
  61773 				8:  uint8(255),
  61774 				9:  uint8(255),
  61775 				10: uint8(128),
  61776 			},
  61777 		},
  61778 		2: {
  61779 			0: {
  61780 				0:  uint8(1),
  61781 				1:  uint8(52),
  61782 				2:  uint8(220),
  61783 				3:  uint8(246),
  61784 				4:  uint8(198),
  61785 				5:  uint8(199),
  61786 				6:  uint8(249),
  61787 				7:  uint8(220),
  61788 				8:  uint8(255),
  61789 				9:  uint8(255),
  61790 				10: uint8(128),
  61791 			},
  61792 			1: {
  61793 				0:  uint8(124),
  61794 				1:  uint8(74),
  61795 				2:  uint8(191),
  61796 				3:  uint8(243),
  61797 				4:  uint8(183),
  61798 				5:  uint8(193),
  61799 				6:  uint8(250),
  61800 				7:  uint8(221),
  61801 				8:  uint8(255),
  61802 				9:  uint8(255),
  61803 				10: uint8(128),
  61804 			},
  61805 			2: {
  61806 				0:  uint8(24),
  61807 				1:  uint8(71),
  61808 				2:  uint8(130),
  61809 				3:  uint8(219),
  61810 				4:  uint8(154),
  61811 				5:  uint8(170),
  61812 				6:  uint8(243),
  61813 				7:  uint8(182),
  61814 				8:  uint8(255),
  61815 				9:  uint8(255),
  61816 				10: uint8(128),
  61817 			},
  61818 		},
  61819 		3: {
  61820 			0: {
  61821 				0:  uint8(1),
  61822 				1:  uint8(182),
  61823 				2:  uint8(225),
  61824 				3:  uint8(249),
  61825 				4:  uint8(219),
  61826 				5:  uint8(240),
  61827 				6:  uint8(255),
  61828 				7:  uint8(224),
  61829 				8:  uint8(128),
  61830 				9:  uint8(128),
  61831 				10: uint8(128),
  61832 			},
  61833 			1: {
  61834 				0:  uint8(149),
  61835 				1:  uint8(150),
  61836 				2:  uint8(226),
  61837 				3:  uint8(252),
  61838 				4:  uint8(216),
  61839 				5:  uint8(205),
  61840 				6:  uint8(255),
  61841 				7:  uint8(171),
  61842 				8:  uint8(128),
  61843 				9:  uint8(128),
  61844 				10: uint8(128),
  61845 			},
  61846 			2: {
  61847 				0:  uint8(28),
  61848 				1:  uint8(108),
  61849 				2:  uint8(170),
  61850 				3:  uint8(242),
  61851 				4:  uint8(183),
  61852 				5:  uint8(194),
  61853 				6:  uint8(254),
  61854 				7:  uint8(223),
  61855 				8:  uint8(255),
  61856 				9:  uint8(255),
  61857 				10: uint8(128),
  61858 			},
  61859 		},
  61860 		4: {
  61861 			0: {
  61862 				0:  uint8(1),
  61863 				1:  uint8(81),
  61864 				2:  uint8(230),
  61865 				3:  uint8(252),
  61866 				4:  uint8(204),
  61867 				5:  uint8(203),
  61868 				6:  uint8(255),
  61869 				7:  uint8(192),
  61870 				8:  uint8(128),
  61871 				9:  uint8(128),
  61872 				10: uint8(128),
  61873 			},
  61874 			1: {
  61875 				0:  uint8(123),
  61876 				1:  uint8(102),
  61877 				2:  uint8(209),
  61878 				3:  uint8(247),
  61879 				4:  uint8(188),
  61880 				5:  uint8(196),
  61881 				6:  uint8(255),
  61882 				7:  uint8(233),
  61883 				8:  uint8(128),
  61884 				9:  uint8(128),
  61885 				10: uint8(128),
  61886 			},
  61887 			2: {
  61888 				0:  uint8(20),
  61889 				1:  uint8(95),
  61890 				2:  uint8(153),
  61891 				3:  uint8(243),
  61892 				4:  uint8(164),
  61893 				5:  uint8(173),
  61894 				6:  uint8(255),
  61895 				7:  uint8(203),
  61896 				8:  uint8(128),
  61897 				9:  uint8(128),
  61898 				10: uint8(128),
  61899 			},
  61900 		},
  61901 		5: {
  61902 			0: {
  61903 				0:  uint8(1),
  61904 				1:  uint8(222),
  61905 				2:  uint8(248),
  61906 				3:  uint8(255),
  61907 				4:  uint8(216),
  61908 				5:  uint8(213),
  61909 				6:  uint8(128),
  61910 				7:  uint8(128),
  61911 				8:  uint8(128),
  61912 				9:  uint8(128),
  61913 				10: uint8(128),
  61914 			},
  61915 			1: {
  61916 				0:  uint8(168),
  61917 				1:  uint8(175),
  61918 				2:  uint8(246),
  61919 				3:  uint8(252),
  61920 				4:  uint8(235),
  61921 				5:  uint8(205),
  61922 				6:  uint8(255),
  61923 				7:  uint8(255),
  61924 				8:  uint8(128),
  61925 				9:  uint8(128),
  61926 				10: uint8(128),
  61927 			},
  61928 			2: {
  61929 				0:  uint8(47),
  61930 				1:  uint8(116),
  61931 				2:  uint8(215),
  61932 				3:  uint8(255),
  61933 				4:  uint8(211),
  61934 				5:  uint8(212),
  61935 				6:  uint8(255),
  61936 				7:  uint8(255),
  61937 				8:  uint8(128),
  61938 				9:  uint8(128),
  61939 				10: uint8(128),
  61940 			},
  61941 		},
  61942 		6: {
  61943 			0: {
  61944 				0:  uint8(1),
  61945 				1:  uint8(121),
  61946 				2:  uint8(236),
  61947 				3:  uint8(253),
  61948 				4:  uint8(212),
  61949 				5:  uint8(214),
  61950 				6:  uint8(255),
  61951 				7:  uint8(255),
  61952 				8:  uint8(128),
  61953 				9:  uint8(128),
  61954 				10: uint8(128),
  61955 			},
  61956 			1: {
  61957 				0:  uint8(141),
  61958 				1:  uint8(84),
  61959 				2:  uint8(213),
  61960 				3:  uint8(252),
  61961 				4:  uint8(201),
  61962 				5:  uint8(202),
  61963 				6:  uint8(255),
  61964 				7:  uint8(219),
  61965 				8:  uint8(128),
  61966 				9:  uint8(128),
  61967 				10: uint8(128),
  61968 			},
  61969 			2: {
  61970 				0:  uint8(42),
  61971 				1:  uint8(80),
  61972 				2:  uint8(160),
  61973 				3:  uint8(240),
  61974 				4:  uint8(162),
  61975 				5:  uint8(185),
  61976 				6:  uint8(255),
  61977 				7:  uint8(205),
  61978 				8:  uint8(128),
  61979 				9:  uint8(128),
  61980 				10: uint8(128),
  61981 			},
  61982 		},
  61983 		7: {
  61984 			0: {
  61985 				0:  uint8(1),
  61986 				1:  uint8(1),
  61987 				2:  uint8(255),
  61988 				3:  uint8(128),
  61989 				4:  uint8(128),
  61990 				5:  uint8(128),
  61991 				6:  uint8(128),
  61992 				7:  uint8(128),
  61993 				8:  uint8(128),
  61994 				9:  uint8(128),
  61995 				10: uint8(128),
  61996 			},
  61997 			1: {
  61998 				0:  uint8(244),
  61999 				1:  uint8(1),
  62000 				2:  uint8(255),
  62001 				3:  uint8(128),
  62002 				4:  uint8(128),
  62003 				5:  uint8(128),
  62004 				6:  uint8(128),
  62005 				7:  uint8(128),
  62006 				8:  uint8(128),
  62007 				9:  uint8(128),
  62008 				10: uint8(128),
  62009 			},
  62010 			2: {
  62011 				0:  uint8(238),
  62012 				1:  uint8(1),
  62013 				2:  uint8(255),
  62014 				3:  uint8(128),
  62015 				4:  uint8(128),
  62016 				5:  uint8(128),
  62017 				6:  uint8(128),
  62018 				7:  uint8(128),
  62019 				8:  uint8(128),
  62020 				9:  uint8(128),
  62021 				10: uint8(128),
  62022 			},
  62023 		},
  62024 	},
  62025 }
  62026 
  62027 //------------------------------------------------------------------------------
  62028 // Paragraph 13
  62029 
  62030 var VP8CoeffsUpdateProba = [4][8][3][11]uint8_t{
  62031 	0: {
  62032 		0: {
  62033 			0: {
  62034 				0:  uint8(255),
  62035 				1:  uint8(255),
  62036 				2:  uint8(255),
  62037 				3:  uint8(255),
  62038 				4:  uint8(255),
  62039 				5:  uint8(255),
  62040 				6:  uint8(255),
  62041 				7:  uint8(255),
  62042 				8:  uint8(255),
  62043 				9:  uint8(255),
  62044 				10: uint8(255),
  62045 			},
  62046 			1: {
  62047 				0:  uint8(255),
  62048 				1:  uint8(255),
  62049 				2:  uint8(255),
  62050 				3:  uint8(255),
  62051 				4:  uint8(255),
  62052 				5:  uint8(255),
  62053 				6:  uint8(255),
  62054 				7:  uint8(255),
  62055 				8:  uint8(255),
  62056 				9:  uint8(255),
  62057 				10: uint8(255),
  62058 			},
  62059 			2: {
  62060 				0:  uint8(255),
  62061 				1:  uint8(255),
  62062 				2:  uint8(255),
  62063 				3:  uint8(255),
  62064 				4:  uint8(255),
  62065 				5:  uint8(255),
  62066 				6:  uint8(255),
  62067 				7:  uint8(255),
  62068 				8:  uint8(255),
  62069 				9:  uint8(255),
  62070 				10: uint8(255),
  62071 			},
  62072 		},
  62073 		1: {
  62074 			0: {
  62075 				0:  uint8(176),
  62076 				1:  uint8(246),
  62077 				2:  uint8(255),
  62078 				3:  uint8(255),
  62079 				4:  uint8(255),
  62080 				5:  uint8(255),
  62081 				6:  uint8(255),
  62082 				7:  uint8(255),
  62083 				8:  uint8(255),
  62084 				9:  uint8(255),
  62085 				10: uint8(255),
  62086 			},
  62087 			1: {
  62088 				0:  uint8(223),
  62089 				1:  uint8(241),
  62090 				2:  uint8(252),
  62091 				3:  uint8(255),
  62092 				4:  uint8(255),
  62093 				5:  uint8(255),
  62094 				6:  uint8(255),
  62095 				7:  uint8(255),
  62096 				8:  uint8(255),
  62097 				9:  uint8(255),
  62098 				10: uint8(255),
  62099 			},
  62100 			2: {
  62101 				0:  uint8(249),
  62102 				1:  uint8(253),
  62103 				2:  uint8(253),
  62104 				3:  uint8(255),
  62105 				4:  uint8(255),
  62106 				5:  uint8(255),
  62107 				6:  uint8(255),
  62108 				7:  uint8(255),
  62109 				8:  uint8(255),
  62110 				9:  uint8(255),
  62111 				10: uint8(255),
  62112 			},
  62113 		},
  62114 		2: {
  62115 			0: {
  62116 				0:  uint8(255),
  62117 				1:  uint8(244),
  62118 				2:  uint8(252),
  62119 				3:  uint8(255),
  62120 				4:  uint8(255),
  62121 				5:  uint8(255),
  62122 				6:  uint8(255),
  62123 				7:  uint8(255),
  62124 				8:  uint8(255),
  62125 				9:  uint8(255),
  62126 				10: uint8(255),
  62127 			},
  62128 			1: {
  62129 				0:  uint8(234),
  62130 				1:  uint8(254),
  62131 				2:  uint8(254),
  62132 				3:  uint8(255),
  62133 				4:  uint8(255),
  62134 				5:  uint8(255),
  62135 				6:  uint8(255),
  62136 				7:  uint8(255),
  62137 				8:  uint8(255),
  62138 				9:  uint8(255),
  62139 				10: uint8(255),
  62140 			},
  62141 			2: {
  62142 				0:  uint8(253),
  62143 				1:  uint8(255),
  62144 				2:  uint8(255),
  62145 				3:  uint8(255),
  62146 				4:  uint8(255),
  62147 				5:  uint8(255),
  62148 				6:  uint8(255),
  62149 				7:  uint8(255),
  62150 				8:  uint8(255),
  62151 				9:  uint8(255),
  62152 				10: uint8(255),
  62153 			},
  62154 		},
  62155 		3: {
  62156 			0: {
  62157 				0:  uint8(255),
  62158 				1:  uint8(246),
  62159 				2:  uint8(254),
  62160 				3:  uint8(255),
  62161 				4:  uint8(255),
  62162 				5:  uint8(255),
  62163 				6:  uint8(255),
  62164 				7:  uint8(255),
  62165 				8:  uint8(255),
  62166 				9:  uint8(255),
  62167 				10: uint8(255),
  62168 			},
  62169 			1: {
  62170 				0:  uint8(239),
  62171 				1:  uint8(253),
  62172 				2:  uint8(254),
  62173 				3:  uint8(255),
  62174 				4:  uint8(255),
  62175 				5:  uint8(255),
  62176 				6:  uint8(255),
  62177 				7:  uint8(255),
  62178 				8:  uint8(255),
  62179 				9:  uint8(255),
  62180 				10: uint8(255),
  62181 			},
  62182 			2: {
  62183 				0:  uint8(254),
  62184 				1:  uint8(255),
  62185 				2:  uint8(254),
  62186 				3:  uint8(255),
  62187 				4:  uint8(255),
  62188 				5:  uint8(255),
  62189 				6:  uint8(255),
  62190 				7:  uint8(255),
  62191 				8:  uint8(255),
  62192 				9:  uint8(255),
  62193 				10: uint8(255),
  62194 			},
  62195 		},
  62196 		4: {
  62197 			0: {
  62198 				0:  uint8(255),
  62199 				1:  uint8(248),
  62200 				2:  uint8(254),
  62201 				3:  uint8(255),
  62202 				4:  uint8(255),
  62203 				5:  uint8(255),
  62204 				6:  uint8(255),
  62205 				7:  uint8(255),
  62206 				8:  uint8(255),
  62207 				9:  uint8(255),
  62208 				10: uint8(255),
  62209 			},
  62210 			1: {
  62211 				0:  uint8(251),
  62212 				1:  uint8(255),
  62213 				2:  uint8(254),
  62214 				3:  uint8(255),
  62215 				4:  uint8(255),
  62216 				5:  uint8(255),
  62217 				6:  uint8(255),
  62218 				7:  uint8(255),
  62219 				8:  uint8(255),
  62220 				9:  uint8(255),
  62221 				10: uint8(255),
  62222 			},
  62223 			2: {
  62224 				0:  uint8(255),
  62225 				1:  uint8(255),
  62226 				2:  uint8(255),
  62227 				3:  uint8(255),
  62228 				4:  uint8(255),
  62229 				5:  uint8(255),
  62230 				6:  uint8(255),
  62231 				7:  uint8(255),
  62232 				8:  uint8(255),
  62233 				9:  uint8(255),
  62234 				10: uint8(255),
  62235 			},
  62236 		},
  62237 		5: {
  62238 			0: {
  62239 				0:  uint8(255),
  62240 				1:  uint8(253),
  62241 				2:  uint8(254),
  62242 				3:  uint8(255),
  62243 				4:  uint8(255),
  62244 				5:  uint8(255),
  62245 				6:  uint8(255),
  62246 				7:  uint8(255),
  62247 				8:  uint8(255),
  62248 				9:  uint8(255),
  62249 				10: uint8(255),
  62250 			},
  62251 			1: {
  62252 				0:  uint8(251),
  62253 				1:  uint8(254),
  62254 				2:  uint8(254),
  62255 				3:  uint8(255),
  62256 				4:  uint8(255),
  62257 				5:  uint8(255),
  62258 				6:  uint8(255),
  62259 				7:  uint8(255),
  62260 				8:  uint8(255),
  62261 				9:  uint8(255),
  62262 				10: uint8(255),
  62263 			},
  62264 			2: {
  62265 				0:  uint8(254),
  62266 				1:  uint8(255),
  62267 				2:  uint8(254),
  62268 				3:  uint8(255),
  62269 				4:  uint8(255),
  62270 				5:  uint8(255),
  62271 				6:  uint8(255),
  62272 				7:  uint8(255),
  62273 				8:  uint8(255),
  62274 				9:  uint8(255),
  62275 				10: uint8(255),
  62276 			},
  62277 		},
  62278 		6: {
  62279 			0: {
  62280 				0:  uint8(255),
  62281 				1:  uint8(254),
  62282 				2:  uint8(253),
  62283 				3:  uint8(255),
  62284 				4:  uint8(254),
  62285 				5:  uint8(255),
  62286 				6:  uint8(255),
  62287 				7:  uint8(255),
  62288 				8:  uint8(255),
  62289 				9:  uint8(255),
  62290 				10: uint8(255),
  62291 			},
  62292 			1: {
  62293 				0:  uint8(250),
  62294 				1:  uint8(255),
  62295 				2:  uint8(254),
  62296 				3:  uint8(255),
  62297 				4:  uint8(254),
  62298 				5:  uint8(255),
  62299 				6:  uint8(255),
  62300 				7:  uint8(255),
  62301 				8:  uint8(255),
  62302 				9:  uint8(255),
  62303 				10: uint8(255),
  62304 			},
  62305 			2: {
  62306 				0:  uint8(254),
  62307 				1:  uint8(255),
  62308 				2:  uint8(255),
  62309 				3:  uint8(255),
  62310 				4:  uint8(255),
  62311 				5:  uint8(255),
  62312 				6:  uint8(255),
  62313 				7:  uint8(255),
  62314 				8:  uint8(255),
  62315 				9:  uint8(255),
  62316 				10: uint8(255),
  62317 			},
  62318 		},
  62319 		7: {
  62320 			0: {
  62321 				0:  uint8(255),
  62322 				1:  uint8(255),
  62323 				2:  uint8(255),
  62324 				3:  uint8(255),
  62325 				4:  uint8(255),
  62326 				5:  uint8(255),
  62327 				6:  uint8(255),
  62328 				7:  uint8(255),
  62329 				8:  uint8(255),
  62330 				9:  uint8(255),
  62331 				10: uint8(255),
  62332 			},
  62333 			1: {
  62334 				0:  uint8(255),
  62335 				1:  uint8(255),
  62336 				2:  uint8(255),
  62337 				3:  uint8(255),
  62338 				4:  uint8(255),
  62339 				5:  uint8(255),
  62340 				6:  uint8(255),
  62341 				7:  uint8(255),
  62342 				8:  uint8(255),
  62343 				9:  uint8(255),
  62344 				10: uint8(255),
  62345 			},
  62346 			2: {
  62347 				0:  uint8(255),
  62348 				1:  uint8(255),
  62349 				2:  uint8(255),
  62350 				3:  uint8(255),
  62351 				4:  uint8(255),
  62352 				5:  uint8(255),
  62353 				6:  uint8(255),
  62354 				7:  uint8(255),
  62355 				8:  uint8(255),
  62356 				9:  uint8(255),
  62357 				10: uint8(255),
  62358 			},
  62359 		},
  62360 	},
  62361 	1: {
  62362 		0: {
  62363 			0: {
  62364 				0:  uint8(217),
  62365 				1:  uint8(255),
  62366 				2:  uint8(255),
  62367 				3:  uint8(255),
  62368 				4:  uint8(255),
  62369 				5:  uint8(255),
  62370 				6:  uint8(255),
  62371 				7:  uint8(255),
  62372 				8:  uint8(255),
  62373 				9:  uint8(255),
  62374 				10: uint8(255),
  62375 			},
  62376 			1: {
  62377 				0:  uint8(225),
  62378 				1:  uint8(252),
  62379 				2:  uint8(241),
  62380 				3:  uint8(253),
  62381 				4:  uint8(255),
  62382 				5:  uint8(255),
  62383 				6:  uint8(254),
  62384 				7:  uint8(255),
  62385 				8:  uint8(255),
  62386 				9:  uint8(255),
  62387 				10: uint8(255),
  62388 			},
  62389 			2: {
  62390 				0:  uint8(234),
  62391 				1:  uint8(250),
  62392 				2:  uint8(241),
  62393 				3:  uint8(250),
  62394 				4:  uint8(253),
  62395 				5:  uint8(255),
  62396 				6:  uint8(253),
  62397 				7:  uint8(254),
  62398 				8:  uint8(255),
  62399 				9:  uint8(255),
  62400 				10: uint8(255),
  62401 			},
  62402 		},
  62403 		1: {
  62404 			0: {
  62405 				0:  uint8(255),
  62406 				1:  uint8(254),
  62407 				2:  uint8(255),
  62408 				3:  uint8(255),
  62409 				4:  uint8(255),
  62410 				5:  uint8(255),
  62411 				6:  uint8(255),
  62412 				7:  uint8(255),
  62413 				8:  uint8(255),
  62414 				9:  uint8(255),
  62415 				10: uint8(255),
  62416 			},
  62417 			1: {
  62418 				0:  uint8(223),
  62419 				1:  uint8(254),
  62420 				2:  uint8(254),
  62421 				3:  uint8(255),
  62422 				4:  uint8(255),
  62423 				5:  uint8(255),
  62424 				6:  uint8(255),
  62425 				7:  uint8(255),
  62426 				8:  uint8(255),
  62427 				9:  uint8(255),
  62428 				10: uint8(255),
  62429 			},
  62430 			2: {
  62431 				0:  uint8(238),
  62432 				1:  uint8(253),
  62433 				2:  uint8(254),
  62434 				3:  uint8(254),
  62435 				4:  uint8(255),
  62436 				5:  uint8(255),
  62437 				6:  uint8(255),
  62438 				7:  uint8(255),
  62439 				8:  uint8(255),
  62440 				9:  uint8(255),
  62441 				10: uint8(255),
  62442 			},
  62443 		},
  62444 		2: {
  62445 			0: {
  62446 				0:  uint8(255),
  62447 				1:  uint8(248),
  62448 				2:  uint8(254),
  62449 				3:  uint8(255),
  62450 				4:  uint8(255),
  62451 				5:  uint8(255),
  62452 				6:  uint8(255),
  62453 				7:  uint8(255),
  62454 				8:  uint8(255),
  62455 				9:  uint8(255),
  62456 				10: uint8(255),
  62457 			},
  62458 			1: {
  62459 				0:  uint8(249),
  62460 				1:  uint8(254),
  62461 				2:  uint8(255),
  62462 				3:  uint8(255),
  62463 				4:  uint8(255),
  62464 				5:  uint8(255),
  62465 				6:  uint8(255),
  62466 				7:  uint8(255),
  62467 				8:  uint8(255),
  62468 				9:  uint8(255),
  62469 				10: uint8(255),
  62470 			},
  62471 			2: {
  62472 				0:  uint8(255),
  62473 				1:  uint8(255),
  62474 				2:  uint8(255),
  62475 				3:  uint8(255),
  62476 				4:  uint8(255),
  62477 				5:  uint8(255),
  62478 				6:  uint8(255),
  62479 				7:  uint8(255),
  62480 				8:  uint8(255),
  62481 				9:  uint8(255),
  62482 				10: uint8(255),
  62483 			},
  62484 		},
  62485 		3: {
  62486 			0: {
  62487 				0:  uint8(255),
  62488 				1:  uint8(253),
  62489 				2:  uint8(255),
  62490 				3:  uint8(255),
  62491 				4:  uint8(255),
  62492 				5:  uint8(255),
  62493 				6:  uint8(255),
  62494 				7:  uint8(255),
  62495 				8:  uint8(255),
  62496 				9:  uint8(255),
  62497 				10: uint8(255),
  62498 			},
  62499 			1: {
  62500 				0:  uint8(247),
  62501 				1:  uint8(254),
  62502 				2:  uint8(255),
  62503 				3:  uint8(255),
  62504 				4:  uint8(255),
  62505 				5:  uint8(255),
  62506 				6:  uint8(255),
  62507 				7:  uint8(255),
  62508 				8:  uint8(255),
  62509 				9:  uint8(255),
  62510 				10: uint8(255),
  62511 			},
  62512 			2: {
  62513 				0:  uint8(255),
  62514 				1:  uint8(255),
  62515 				2:  uint8(255),
  62516 				3:  uint8(255),
  62517 				4:  uint8(255),
  62518 				5:  uint8(255),
  62519 				6:  uint8(255),
  62520 				7:  uint8(255),
  62521 				8:  uint8(255),
  62522 				9:  uint8(255),
  62523 				10: uint8(255),
  62524 			},
  62525 		},
  62526 		4: {
  62527 			0: {
  62528 				0:  uint8(255),
  62529 				1:  uint8(253),
  62530 				2:  uint8(254),
  62531 				3:  uint8(255),
  62532 				4:  uint8(255),
  62533 				5:  uint8(255),
  62534 				6:  uint8(255),
  62535 				7:  uint8(255),
  62536 				8:  uint8(255),
  62537 				9:  uint8(255),
  62538 				10: uint8(255),
  62539 			},
  62540 			1: {
  62541 				0:  uint8(252),
  62542 				1:  uint8(255),
  62543 				2:  uint8(255),
  62544 				3:  uint8(255),
  62545 				4:  uint8(255),
  62546 				5:  uint8(255),
  62547 				6:  uint8(255),
  62548 				7:  uint8(255),
  62549 				8:  uint8(255),
  62550 				9:  uint8(255),
  62551 				10: uint8(255),
  62552 			},
  62553 			2: {
  62554 				0:  uint8(255),
  62555 				1:  uint8(255),
  62556 				2:  uint8(255),
  62557 				3:  uint8(255),
  62558 				4:  uint8(255),
  62559 				5:  uint8(255),
  62560 				6:  uint8(255),
  62561 				7:  uint8(255),
  62562 				8:  uint8(255),
  62563 				9:  uint8(255),
  62564 				10: uint8(255),
  62565 			},
  62566 		},
  62567 		5: {
  62568 			0: {
  62569 				0:  uint8(255),
  62570 				1:  uint8(254),
  62571 				2:  uint8(254),
  62572 				3:  uint8(255),
  62573 				4:  uint8(255),
  62574 				5:  uint8(255),
  62575 				6:  uint8(255),
  62576 				7:  uint8(255),
  62577 				8:  uint8(255),
  62578 				9:  uint8(255),
  62579 				10: uint8(255),
  62580 			},
  62581 			1: {
  62582 				0:  uint8(253),
  62583 				1:  uint8(255),
  62584 				2:  uint8(255),
  62585 				3:  uint8(255),
  62586 				4:  uint8(255),
  62587 				5:  uint8(255),
  62588 				6:  uint8(255),
  62589 				7:  uint8(255),
  62590 				8:  uint8(255),
  62591 				9:  uint8(255),
  62592 				10: uint8(255),
  62593 			},
  62594 			2: {
  62595 				0:  uint8(255),
  62596 				1:  uint8(255),
  62597 				2:  uint8(255),
  62598 				3:  uint8(255),
  62599 				4:  uint8(255),
  62600 				5:  uint8(255),
  62601 				6:  uint8(255),
  62602 				7:  uint8(255),
  62603 				8:  uint8(255),
  62604 				9:  uint8(255),
  62605 				10: uint8(255),
  62606 			},
  62607 		},
  62608 		6: {
  62609 			0: {
  62610 				0:  uint8(255),
  62611 				1:  uint8(254),
  62612 				2:  uint8(253),
  62613 				3:  uint8(255),
  62614 				4:  uint8(255),
  62615 				5:  uint8(255),
  62616 				6:  uint8(255),
  62617 				7:  uint8(255),
  62618 				8:  uint8(255),
  62619 				9:  uint8(255),
  62620 				10: uint8(255),
  62621 			},
  62622 			1: {
  62623 				0:  uint8(250),
  62624 				1:  uint8(255),
  62625 				2:  uint8(255),
  62626 				3:  uint8(255),
  62627 				4:  uint8(255),
  62628 				5:  uint8(255),
  62629 				6:  uint8(255),
  62630 				7:  uint8(255),
  62631 				8:  uint8(255),
  62632 				9:  uint8(255),
  62633 				10: uint8(255),
  62634 			},
  62635 			2: {
  62636 				0:  uint8(254),
  62637 				1:  uint8(255),
  62638 				2:  uint8(255),
  62639 				3:  uint8(255),
  62640 				4:  uint8(255),
  62641 				5:  uint8(255),
  62642 				6:  uint8(255),
  62643 				7:  uint8(255),
  62644 				8:  uint8(255),
  62645 				9:  uint8(255),
  62646 				10: uint8(255),
  62647 			},
  62648 		},
  62649 		7: {
  62650 			0: {
  62651 				0:  uint8(255),
  62652 				1:  uint8(255),
  62653 				2:  uint8(255),
  62654 				3:  uint8(255),
  62655 				4:  uint8(255),
  62656 				5:  uint8(255),
  62657 				6:  uint8(255),
  62658 				7:  uint8(255),
  62659 				8:  uint8(255),
  62660 				9:  uint8(255),
  62661 				10: uint8(255),
  62662 			},
  62663 			1: {
  62664 				0:  uint8(255),
  62665 				1:  uint8(255),
  62666 				2:  uint8(255),
  62667 				3:  uint8(255),
  62668 				4:  uint8(255),
  62669 				5:  uint8(255),
  62670 				6:  uint8(255),
  62671 				7:  uint8(255),
  62672 				8:  uint8(255),
  62673 				9:  uint8(255),
  62674 				10: uint8(255),
  62675 			},
  62676 			2: {
  62677 				0:  uint8(255),
  62678 				1:  uint8(255),
  62679 				2:  uint8(255),
  62680 				3:  uint8(255),
  62681 				4:  uint8(255),
  62682 				5:  uint8(255),
  62683 				6:  uint8(255),
  62684 				7:  uint8(255),
  62685 				8:  uint8(255),
  62686 				9:  uint8(255),
  62687 				10: uint8(255),
  62688 			},
  62689 		},
  62690 	},
  62691 	2: {
  62692 		0: {
  62693 			0: {
  62694 				0:  uint8(186),
  62695 				1:  uint8(251),
  62696 				2:  uint8(250),
  62697 				3:  uint8(255),
  62698 				4:  uint8(255),
  62699 				5:  uint8(255),
  62700 				6:  uint8(255),
  62701 				7:  uint8(255),
  62702 				8:  uint8(255),
  62703 				9:  uint8(255),
  62704 				10: uint8(255),
  62705 			},
  62706 			1: {
  62707 				0:  uint8(234),
  62708 				1:  uint8(251),
  62709 				2:  uint8(244),
  62710 				3:  uint8(254),
  62711 				4:  uint8(255),
  62712 				5:  uint8(255),
  62713 				6:  uint8(255),
  62714 				7:  uint8(255),
  62715 				8:  uint8(255),
  62716 				9:  uint8(255),
  62717 				10: uint8(255),
  62718 			},
  62719 			2: {
  62720 				0:  uint8(251),
  62721 				1:  uint8(251),
  62722 				2:  uint8(243),
  62723 				3:  uint8(253),
  62724 				4:  uint8(254),
  62725 				5:  uint8(255),
  62726 				6:  uint8(254),
  62727 				7:  uint8(255),
  62728 				8:  uint8(255),
  62729 				9:  uint8(255),
  62730 				10: uint8(255),
  62731 			},
  62732 		},
  62733 		1: {
  62734 			0: {
  62735 				0:  uint8(255),
  62736 				1:  uint8(253),
  62737 				2:  uint8(254),
  62738 				3:  uint8(255),
  62739 				4:  uint8(255),
  62740 				5:  uint8(255),
  62741 				6:  uint8(255),
  62742 				7:  uint8(255),
  62743 				8:  uint8(255),
  62744 				9:  uint8(255),
  62745 				10: uint8(255),
  62746 			},
  62747 			1: {
  62748 				0:  uint8(236),
  62749 				1:  uint8(253),
  62750 				2:  uint8(254),
  62751 				3:  uint8(255),
  62752 				4:  uint8(255),
  62753 				5:  uint8(255),
  62754 				6:  uint8(255),
  62755 				7:  uint8(255),
  62756 				8:  uint8(255),
  62757 				9:  uint8(255),
  62758 				10: uint8(255),
  62759 			},
  62760 			2: {
  62761 				0:  uint8(251),
  62762 				1:  uint8(253),
  62763 				2:  uint8(253),
  62764 				3:  uint8(254),
  62765 				4:  uint8(254),
  62766 				5:  uint8(255),
  62767 				6:  uint8(255),
  62768 				7:  uint8(255),
  62769 				8:  uint8(255),
  62770 				9:  uint8(255),
  62771 				10: uint8(255),
  62772 			},
  62773 		},
  62774 		2: {
  62775 			0: {
  62776 				0:  uint8(255),
  62777 				1:  uint8(254),
  62778 				2:  uint8(254),
  62779 				3:  uint8(255),
  62780 				4:  uint8(255),
  62781 				5:  uint8(255),
  62782 				6:  uint8(255),
  62783 				7:  uint8(255),
  62784 				8:  uint8(255),
  62785 				9:  uint8(255),
  62786 				10: uint8(255),
  62787 			},
  62788 			1: {
  62789 				0:  uint8(254),
  62790 				1:  uint8(254),
  62791 				2:  uint8(254),
  62792 				3:  uint8(255),
  62793 				4:  uint8(255),
  62794 				5:  uint8(255),
  62795 				6:  uint8(255),
  62796 				7:  uint8(255),
  62797 				8:  uint8(255),
  62798 				9:  uint8(255),
  62799 				10: uint8(255),
  62800 			},
  62801 			2: {
  62802 				0:  uint8(255),
  62803 				1:  uint8(255),
  62804 				2:  uint8(255),
  62805 				3:  uint8(255),
  62806 				4:  uint8(255),
  62807 				5:  uint8(255),
  62808 				6:  uint8(255),
  62809 				7:  uint8(255),
  62810 				8:  uint8(255),
  62811 				9:  uint8(255),
  62812 				10: uint8(255),
  62813 			},
  62814 		},
  62815 		3: {
  62816 			0: {
  62817 				0:  uint8(255),
  62818 				1:  uint8(254),
  62819 				2:  uint8(255),
  62820 				3:  uint8(255),
  62821 				4:  uint8(255),
  62822 				5:  uint8(255),
  62823 				6:  uint8(255),
  62824 				7:  uint8(255),
  62825 				8:  uint8(255),
  62826 				9:  uint8(255),
  62827 				10: uint8(255),
  62828 			},
  62829 			1: {
  62830 				0:  uint8(254),
  62831 				1:  uint8(254),
  62832 				2:  uint8(255),
  62833 				3:  uint8(255),
  62834 				4:  uint8(255),
  62835 				5:  uint8(255),
  62836 				6:  uint8(255),
  62837 				7:  uint8(255),
  62838 				8:  uint8(255),
  62839 				9:  uint8(255),
  62840 				10: uint8(255),
  62841 			},
  62842 			2: {
  62843 				0:  uint8(254),
  62844 				1:  uint8(255),
  62845 				2:  uint8(255),
  62846 				3:  uint8(255),
  62847 				4:  uint8(255),
  62848 				5:  uint8(255),
  62849 				6:  uint8(255),
  62850 				7:  uint8(255),
  62851 				8:  uint8(255),
  62852 				9:  uint8(255),
  62853 				10: uint8(255),
  62854 			},
  62855 		},
  62856 		4: {
  62857 			0: {
  62858 				0:  uint8(255),
  62859 				1:  uint8(255),
  62860 				2:  uint8(255),
  62861 				3:  uint8(255),
  62862 				4:  uint8(255),
  62863 				5:  uint8(255),
  62864 				6:  uint8(255),
  62865 				7:  uint8(255),
  62866 				8:  uint8(255),
  62867 				9:  uint8(255),
  62868 				10: uint8(255),
  62869 			},
  62870 			1: {
  62871 				0:  uint8(254),
  62872 				1:  uint8(255),
  62873 				2:  uint8(255),
  62874 				3:  uint8(255),
  62875 				4:  uint8(255),
  62876 				5:  uint8(255),
  62877 				6:  uint8(255),
  62878 				7:  uint8(255),
  62879 				8:  uint8(255),
  62880 				9:  uint8(255),
  62881 				10: uint8(255),
  62882 			},
  62883 			2: {
  62884 				0:  uint8(255),
  62885 				1:  uint8(255),
  62886 				2:  uint8(255),
  62887 				3:  uint8(255),
  62888 				4:  uint8(255),
  62889 				5:  uint8(255),
  62890 				6:  uint8(255),
  62891 				7:  uint8(255),
  62892 				8:  uint8(255),
  62893 				9:  uint8(255),
  62894 				10: uint8(255),
  62895 			},
  62896 		},
  62897 		5: {
  62898 			0: {
  62899 				0:  uint8(255),
  62900 				1:  uint8(255),
  62901 				2:  uint8(255),
  62902 				3:  uint8(255),
  62903 				4:  uint8(255),
  62904 				5:  uint8(255),
  62905 				6:  uint8(255),
  62906 				7:  uint8(255),
  62907 				8:  uint8(255),
  62908 				9:  uint8(255),
  62909 				10: uint8(255),
  62910 			},
  62911 			1: {
  62912 				0:  uint8(255),
  62913 				1:  uint8(255),
  62914 				2:  uint8(255),
  62915 				3:  uint8(255),
  62916 				4:  uint8(255),
  62917 				5:  uint8(255),
  62918 				6:  uint8(255),
  62919 				7:  uint8(255),
  62920 				8:  uint8(255),
  62921 				9:  uint8(255),
  62922 				10: uint8(255),
  62923 			},
  62924 			2: {
  62925 				0:  uint8(255),
  62926 				1:  uint8(255),
  62927 				2:  uint8(255),
  62928 				3:  uint8(255),
  62929 				4:  uint8(255),
  62930 				5:  uint8(255),
  62931 				6:  uint8(255),
  62932 				7:  uint8(255),
  62933 				8:  uint8(255),
  62934 				9:  uint8(255),
  62935 				10: uint8(255),
  62936 			},
  62937 		},
  62938 		6: {
  62939 			0: {
  62940 				0:  uint8(255),
  62941 				1:  uint8(255),
  62942 				2:  uint8(255),
  62943 				3:  uint8(255),
  62944 				4:  uint8(255),
  62945 				5:  uint8(255),
  62946 				6:  uint8(255),
  62947 				7:  uint8(255),
  62948 				8:  uint8(255),
  62949 				9:  uint8(255),
  62950 				10: uint8(255),
  62951 			},
  62952 			1: {
  62953 				0:  uint8(255),
  62954 				1:  uint8(255),
  62955 				2:  uint8(255),
  62956 				3:  uint8(255),
  62957 				4:  uint8(255),
  62958 				5:  uint8(255),
  62959 				6:  uint8(255),
  62960 				7:  uint8(255),
  62961 				8:  uint8(255),
  62962 				9:  uint8(255),
  62963 				10: uint8(255),
  62964 			},
  62965 			2: {
  62966 				0:  uint8(255),
  62967 				1:  uint8(255),
  62968 				2:  uint8(255),
  62969 				3:  uint8(255),
  62970 				4:  uint8(255),
  62971 				5:  uint8(255),
  62972 				6:  uint8(255),
  62973 				7:  uint8(255),
  62974 				8:  uint8(255),
  62975 				9:  uint8(255),
  62976 				10: uint8(255),
  62977 			},
  62978 		},
  62979 		7: {
  62980 			0: {
  62981 				0:  uint8(255),
  62982 				1:  uint8(255),
  62983 				2:  uint8(255),
  62984 				3:  uint8(255),
  62985 				4:  uint8(255),
  62986 				5:  uint8(255),
  62987 				6:  uint8(255),
  62988 				7:  uint8(255),
  62989 				8:  uint8(255),
  62990 				9:  uint8(255),
  62991 				10: uint8(255),
  62992 			},
  62993 			1: {
  62994 				0:  uint8(255),
  62995 				1:  uint8(255),
  62996 				2:  uint8(255),
  62997 				3:  uint8(255),
  62998 				4:  uint8(255),
  62999 				5:  uint8(255),
  63000 				6:  uint8(255),
  63001 				7:  uint8(255),
  63002 				8:  uint8(255),
  63003 				9:  uint8(255),
  63004 				10: uint8(255),
  63005 			},
  63006 			2: {
  63007 				0:  uint8(255),
  63008 				1:  uint8(255),
  63009 				2:  uint8(255),
  63010 				3:  uint8(255),
  63011 				4:  uint8(255),
  63012 				5:  uint8(255),
  63013 				6:  uint8(255),
  63014 				7:  uint8(255),
  63015 				8:  uint8(255),
  63016 				9:  uint8(255),
  63017 				10: uint8(255),
  63018 			},
  63019 		},
  63020 	},
  63021 	3: {
  63022 		0: {
  63023 			0: {
  63024 				0:  uint8(248),
  63025 				1:  uint8(255),
  63026 				2:  uint8(255),
  63027 				3:  uint8(255),
  63028 				4:  uint8(255),
  63029 				5:  uint8(255),
  63030 				6:  uint8(255),
  63031 				7:  uint8(255),
  63032 				8:  uint8(255),
  63033 				9:  uint8(255),
  63034 				10: uint8(255),
  63035 			},
  63036 			1: {
  63037 				0:  uint8(250),
  63038 				1:  uint8(254),
  63039 				2:  uint8(252),
  63040 				3:  uint8(254),
  63041 				4:  uint8(255),
  63042 				5:  uint8(255),
  63043 				6:  uint8(255),
  63044 				7:  uint8(255),
  63045 				8:  uint8(255),
  63046 				9:  uint8(255),
  63047 				10: uint8(255),
  63048 			},
  63049 			2: {
  63050 				0:  uint8(248),
  63051 				1:  uint8(254),
  63052 				2:  uint8(249),
  63053 				3:  uint8(253),
  63054 				4:  uint8(255),
  63055 				5:  uint8(255),
  63056 				6:  uint8(255),
  63057 				7:  uint8(255),
  63058 				8:  uint8(255),
  63059 				9:  uint8(255),
  63060 				10: uint8(255),
  63061 			},
  63062 		},
  63063 		1: {
  63064 			0: {
  63065 				0:  uint8(255),
  63066 				1:  uint8(253),
  63067 				2:  uint8(253),
  63068 				3:  uint8(255),
  63069 				4:  uint8(255),
  63070 				5:  uint8(255),
  63071 				6:  uint8(255),
  63072 				7:  uint8(255),
  63073 				8:  uint8(255),
  63074 				9:  uint8(255),
  63075 				10: uint8(255),
  63076 			},
  63077 			1: {
  63078 				0:  uint8(246),
  63079 				1:  uint8(253),
  63080 				2:  uint8(253),
  63081 				3:  uint8(255),
  63082 				4:  uint8(255),
  63083 				5:  uint8(255),
  63084 				6:  uint8(255),
  63085 				7:  uint8(255),
  63086 				8:  uint8(255),
  63087 				9:  uint8(255),
  63088 				10: uint8(255),
  63089 			},
  63090 			2: {
  63091 				0:  uint8(252),
  63092 				1:  uint8(254),
  63093 				2:  uint8(251),
  63094 				3:  uint8(254),
  63095 				4:  uint8(254),
  63096 				5:  uint8(255),
  63097 				6:  uint8(255),
  63098 				7:  uint8(255),
  63099 				8:  uint8(255),
  63100 				9:  uint8(255),
  63101 				10: uint8(255),
  63102 			},
  63103 		},
  63104 		2: {
  63105 			0: {
  63106 				0:  uint8(255),
  63107 				1:  uint8(254),
  63108 				2:  uint8(252),
  63109 				3:  uint8(255),
  63110 				4:  uint8(255),
  63111 				5:  uint8(255),
  63112 				6:  uint8(255),
  63113 				7:  uint8(255),
  63114 				8:  uint8(255),
  63115 				9:  uint8(255),
  63116 				10: uint8(255),
  63117 			},
  63118 			1: {
  63119 				0:  uint8(248),
  63120 				1:  uint8(254),
  63121 				2:  uint8(253),
  63122 				3:  uint8(255),
  63123 				4:  uint8(255),
  63124 				5:  uint8(255),
  63125 				6:  uint8(255),
  63126 				7:  uint8(255),
  63127 				8:  uint8(255),
  63128 				9:  uint8(255),
  63129 				10: uint8(255),
  63130 			},
  63131 			2: {
  63132 				0:  uint8(253),
  63133 				1:  uint8(255),
  63134 				2:  uint8(254),
  63135 				3:  uint8(254),
  63136 				4:  uint8(255),
  63137 				5:  uint8(255),
  63138 				6:  uint8(255),
  63139 				7:  uint8(255),
  63140 				8:  uint8(255),
  63141 				9:  uint8(255),
  63142 				10: uint8(255),
  63143 			},
  63144 		},
  63145 		3: {
  63146 			0: {
  63147 				0:  uint8(255),
  63148 				1:  uint8(251),
  63149 				2:  uint8(254),
  63150 				3:  uint8(255),
  63151 				4:  uint8(255),
  63152 				5:  uint8(255),
  63153 				6:  uint8(255),
  63154 				7:  uint8(255),
  63155 				8:  uint8(255),
  63156 				9:  uint8(255),
  63157 				10: uint8(255),
  63158 			},
  63159 			1: {
  63160 				0:  uint8(245),
  63161 				1:  uint8(251),
  63162 				2:  uint8(254),
  63163 				3:  uint8(255),
  63164 				4:  uint8(255),
  63165 				5:  uint8(255),
  63166 				6:  uint8(255),
  63167 				7:  uint8(255),
  63168 				8:  uint8(255),
  63169 				9:  uint8(255),
  63170 				10: uint8(255),
  63171 			},
  63172 			2: {
  63173 				0:  uint8(253),
  63174 				1:  uint8(253),
  63175 				2:  uint8(254),
  63176 				3:  uint8(255),
  63177 				4:  uint8(255),
  63178 				5:  uint8(255),
  63179 				6:  uint8(255),
  63180 				7:  uint8(255),
  63181 				8:  uint8(255),
  63182 				9:  uint8(255),
  63183 				10: uint8(255),
  63184 			},
  63185 		},
  63186 		4: {
  63187 			0: {
  63188 				0:  uint8(255),
  63189 				1:  uint8(251),
  63190 				2:  uint8(253),
  63191 				3:  uint8(255),
  63192 				4:  uint8(255),
  63193 				5:  uint8(255),
  63194 				6:  uint8(255),
  63195 				7:  uint8(255),
  63196 				8:  uint8(255),
  63197 				9:  uint8(255),
  63198 				10: uint8(255),
  63199 			},
  63200 			1: {
  63201 				0:  uint8(252),
  63202 				1:  uint8(253),
  63203 				2:  uint8(254),
  63204 				3:  uint8(255),
  63205 				4:  uint8(255),
  63206 				5:  uint8(255),
  63207 				6:  uint8(255),
  63208 				7:  uint8(255),
  63209 				8:  uint8(255),
  63210 				9:  uint8(255),
  63211 				10: uint8(255),
  63212 			},
  63213 			2: {
  63214 				0:  uint8(255),
  63215 				1:  uint8(254),
  63216 				2:  uint8(255),
  63217 				3:  uint8(255),
  63218 				4:  uint8(255),
  63219 				5:  uint8(255),
  63220 				6:  uint8(255),
  63221 				7:  uint8(255),
  63222 				8:  uint8(255),
  63223 				9:  uint8(255),
  63224 				10: uint8(255),
  63225 			},
  63226 		},
  63227 		5: {
  63228 			0: {
  63229 				0:  uint8(255),
  63230 				1:  uint8(252),
  63231 				2:  uint8(255),
  63232 				3:  uint8(255),
  63233 				4:  uint8(255),
  63234 				5:  uint8(255),
  63235 				6:  uint8(255),
  63236 				7:  uint8(255),
  63237 				8:  uint8(255),
  63238 				9:  uint8(255),
  63239 				10: uint8(255),
  63240 			},
  63241 			1: {
  63242 				0:  uint8(249),
  63243 				1:  uint8(255),
  63244 				2:  uint8(254),
  63245 				3:  uint8(255),
  63246 				4:  uint8(255),
  63247 				5:  uint8(255),
  63248 				6:  uint8(255),
  63249 				7:  uint8(255),
  63250 				8:  uint8(255),
  63251 				9:  uint8(255),
  63252 				10: uint8(255),
  63253 			},
  63254 			2: {
  63255 				0:  uint8(255),
  63256 				1:  uint8(255),
  63257 				2:  uint8(254),
  63258 				3:  uint8(255),
  63259 				4:  uint8(255),
  63260 				5:  uint8(255),
  63261 				6:  uint8(255),
  63262 				7:  uint8(255),
  63263 				8:  uint8(255),
  63264 				9:  uint8(255),
  63265 				10: uint8(255),
  63266 			},
  63267 		},
  63268 		6: {
  63269 			0: {
  63270 				0:  uint8(255),
  63271 				1:  uint8(255),
  63272 				2:  uint8(253),
  63273 				3:  uint8(255),
  63274 				4:  uint8(255),
  63275 				5:  uint8(255),
  63276 				6:  uint8(255),
  63277 				7:  uint8(255),
  63278 				8:  uint8(255),
  63279 				9:  uint8(255),
  63280 				10: uint8(255),
  63281 			},
  63282 			1: {
  63283 				0:  uint8(250),
  63284 				1:  uint8(255),
  63285 				2:  uint8(255),
  63286 				3:  uint8(255),
  63287 				4:  uint8(255),
  63288 				5:  uint8(255),
  63289 				6:  uint8(255),
  63290 				7:  uint8(255),
  63291 				8:  uint8(255),
  63292 				9:  uint8(255),
  63293 				10: uint8(255),
  63294 			},
  63295 			2: {
  63296 				0:  uint8(255),
  63297 				1:  uint8(255),
  63298 				2:  uint8(255),
  63299 				3:  uint8(255),
  63300 				4:  uint8(255),
  63301 				5:  uint8(255),
  63302 				6:  uint8(255),
  63303 				7:  uint8(255),
  63304 				8:  uint8(255),
  63305 				9:  uint8(255),
  63306 				10: uint8(255),
  63307 			},
  63308 		},
  63309 		7: {
  63310 			0: {
  63311 				0:  uint8(255),
  63312 				1:  uint8(255),
  63313 				2:  uint8(255),
  63314 				3:  uint8(255),
  63315 				4:  uint8(255),
  63316 				5:  uint8(255),
  63317 				6:  uint8(255),
  63318 				7:  uint8(255),
  63319 				8:  uint8(255),
  63320 				9:  uint8(255),
  63321 				10: uint8(255),
  63322 			},
  63323 			1: {
  63324 				0:  uint8(254),
  63325 				1:  uint8(255),
  63326 				2:  uint8(255),
  63327 				3:  uint8(255),
  63328 				4:  uint8(255),
  63329 				5:  uint8(255),
  63330 				6:  uint8(255),
  63331 				7:  uint8(255),
  63332 				8:  uint8(255),
  63333 				9:  uint8(255),
  63334 				10: uint8(255),
  63335 			},
  63336 			2: {
  63337 				0:  uint8(255),
  63338 				1:  uint8(255),
  63339 				2:  uint8(255),
  63340 				3:  uint8(255),
  63341 				4:  uint8(255),
  63342 				5:  uint8(255),
  63343 				6:  uint8(255),
  63344 				7:  uint8(255),
  63345 				8:  uint8(255),
  63346 				9:  uint8(255),
  63347 				10: uint8(255),
  63348 			},
  63349 		},
  63350 	},
  63351 }
  63352 
  63353 //------------------------------------------------------------------------------
  63354 // Initialization
  63355 
  63356 // C documentation
  63357 //
  63358 //	// Speed-critical function pointers. We have to initialize them to the default
  63359 //	// implementations within VP8EncDspInit().
  63360 var VP8CollectHistogram VP8CHisto
  63361 
  63362 var VP8Copy16x8 VP8BlockCopy
  63363 
  63364 var VP8Copy4x4 VP8BlockCopy
  63365 
  63366 var VP8DitherCombine8x8 uintptr
  63367 
  63368 //------------------------------------------------------------------------------
  63369 // Compute susceptibility based on DCT-coeff histograms:
  63370 // the higher, the "easier" the macroblock is to compress.
  63371 
  63372 var VP8DspScan = [24]int32{
  63373 	1:  libc.Int32FromInt32(4) + libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS),
  63374 	2:  libc.Int32FromInt32(8) + libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS),
  63375 	3:  libc.Int32FromInt32(12) + libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS),
  63376 	4:  libc.Int32FromInt32(0) + libc.Int32FromInt32(4)*libc.Int32FromInt32(BPS),
  63377 	5:  libc.Int32FromInt32(4) + libc.Int32FromInt32(4)*libc.Int32FromInt32(BPS),
  63378 	6:  libc.Int32FromInt32(8) + libc.Int32FromInt32(4)*libc.Int32FromInt32(BPS),
  63379 	7:  libc.Int32FromInt32(12) + libc.Int32FromInt32(4)*libc.Int32FromInt32(BPS),
  63380 	8:  libc.Int32FromInt32(0) + libc.Int32FromInt32(8)*libc.Int32FromInt32(BPS),
  63381 	9:  libc.Int32FromInt32(4) + libc.Int32FromInt32(8)*libc.Int32FromInt32(BPS),
  63382 	10: libc.Int32FromInt32(8) + libc.Int32FromInt32(8)*libc.Int32FromInt32(BPS),
  63383 	11: libc.Int32FromInt32(12) + libc.Int32FromInt32(8)*libc.Int32FromInt32(BPS),
  63384 	12: libc.Int32FromInt32(0) + libc.Int32FromInt32(12)*libc.Int32FromInt32(BPS),
  63385 	13: libc.Int32FromInt32(4) + libc.Int32FromInt32(12)*libc.Int32FromInt32(BPS),
  63386 	14: libc.Int32FromInt32(8) + libc.Int32FromInt32(12)*libc.Int32FromInt32(BPS),
  63387 	15: libc.Int32FromInt32(12) + libc.Int32FromInt32(12)*libc.Int32FromInt32(BPS),
  63388 	17: libc.Int32FromInt32(4) + libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS),
  63389 	18: libc.Int32FromInt32(0) + libc.Int32FromInt32(4)*libc.Int32FromInt32(BPS),
  63390 	19: libc.Int32FromInt32(4) + libc.Int32FromInt32(4)*libc.Int32FromInt32(BPS),
  63391 	20: libc.Int32FromInt32(8) + libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS),
  63392 	21: libc.Int32FromInt32(12) + libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS),
  63393 	22: libc.Int32FromInt32(8) + libc.Int32FromInt32(4)*libc.Int32FromInt32(BPS),
  63394 	23: libc.Int32FromInt32(12) + libc.Int32FromInt32(4)*libc.Int32FromInt32(BPS),
  63395 }
  63396 
  63397 //------------------------------------------------------------------------------
  63398 // Tables for level coding
  63399 
  63400 var VP8EncBands = [17]uint8_t{
  63401 	1:  uint8(1),
  63402 	2:  uint8(2),
  63403 	3:  uint8(3),
  63404 	4:  uint8(6),
  63405 	5:  uint8(4),
  63406 	6:  uint8(5),
  63407 	7:  uint8(6),
  63408 	8:  uint8(6),
  63409 	9:  uint8(6),
  63410 	10: uint8(6),
  63411 	11: uint8(6),
  63412 	12: uint8(6),
  63413 	13: uint8(6),
  63414 	14: uint8(6),
  63415 	15: uint8(7),
  63416 }
  63417 
  63418 var VP8EncPredChroma8 VP8IntraPreds
  63419 
  63420 var VP8EncPredLuma16 VP8IntraPreds
  63421 
  63422 var VP8EncPredLuma4 VP8Intra4Preds
  63423 
  63424 var VP8EncQuantize2Blocks VP8Quantize2Blocks
  63425 
  63426 var VP8EncQuantizeBlock VP8QuantizeBlock
  63427 
  63428 var VP8EncQuantizeBlockWHT VP8QuantizeBlockWHT
  63429 
  63430 //------------------------------------------------------------------------------
  63431 
  63432 // Copyright 2011 Google Inc. All Rights Reserved.
  63433 //
  63434 // Use of this source code is governed by a BSD-style license
  63435 // that can be found in the COPYING file in the root of the source
  63436 // tree. An additional intellectual property rights grant can be found
  63437 // in the file PATENTS. All contributing project authors may
  63438 // be found in the AUTHORS file in the root of the source tree.
  63439 // -----------------------------------------------------------------------------
  63440 //
  63441 //   WebP encoder: internal header.
  63442 //
  63443 // Author: Skal (pascal.massimino@gmail.com)
  63444 
  63445 //------------------------------------------------------------------------------
  63446 // Boolean-cost cost table
  63447 
  63448 var VP8EntropyCost = [256]uint16_t{
  63449 	0:   uint16(1792),
  63450 	1:   uint16(1792),
  63451 	2:   uint16(1792),
  63452 	3:   uint16(1536),
  63453 	4:   uint16(1536),
  63454 	5:   uint16(1408),
  63455 	6:   uint16(1366),
  63456 	7:   uint16(1280),
  63457 	8:   uint16(1280),
  63458 	9:   uint16(1216),
  63459 	10:  uint16(1178),
  63460 	11:  uint16(1152),
  63461 	12:  uint16(1110),
  63462 	13:  uint16(1076),
  63463 	14:  uint16(1061),
  63464 	15:  uint16(1024),
  63465 	16:  uint16(1024),
  63466 	17:  uint16(992),
  63467 	18:  uint16(968),
  63468 	19:  uint16(951),
  63469 	20:  uint16(939),
  63470 	21:  uint16(911),
  63471 	22:  uint16(896),
  63472 	23:  uint16(878),
  63473 	24:  uint16(871),
  63474 	25:  uint16(854),
  63475 	26:  uint16(838),
  63476 	27:  uint16(820),
  63477 	28:  uint16(811),
  63478 	29:  uint16(794),
  63479 	30:  uint16(786),
  63480 	31:  uint16(768),
  63481 	32:  uint16(768),
  63482 	33:  uint16(752),
  63483 	34:  uint16(740),
  63484 	35:  uint16(732),
  63485 	36:  uint16(720),
  63486 	37:  uint16(709),
  63487 	38:  uint16(704),
  63488 	39:  uint16(690),
  63489 	40:  uint16(683),
  63490 	41:  uint16(672),
  63491 	42:  uint16(666),
  63492 	43:  uint16(655),
  63493 	44:  uint16(647),
  63494 	45:  uint16(640),
  63495 	46:  uint16(631),
  63496 	47:  uint16(622),
  63497 	48:  uint16(615),
  63498 	49:  uint16(607),
  63499 	50:  uint16(598),
  63500 	51:  uint16(592),
  63501 	52:  uint16(586),
  63502 	53:  uint16(576),
  63503 	54:  uint16(572),
  63504 	55:  uint16(564),
  63505 	56:  uint16(559),
  63506 	57:  uint16(555),
  63507 	58:  uint16(547),
  63508 	59:  uint16(541),
  63509 	60:  uint16(534),
  63510 	61:  uint16(528),
  63511 	62:  uint16(522),
  63512 	63:  uint16(512),
  63513 	64:  uint16(512),
  63514 	65:  uint16(504),
  63515 	66:  uint16(500),
  63516 	67:  uint16(494),
  63517 	68:  uint16(488),
  63518 	69:  uint16(483),
  63519 	70:  uint16(477),
  63520 	71:  uint16(473),
  63521 	72:  uint16(467),
  63522 	73:  uint16(461),
  63523 	74:  uint16(458),
  63524 	75:  uint16(452),
  63525 	76:  uint16(448),
  63526 	77:  uint16(443),
  63527 	78:  uint16(438),
  63528 	79:  uint16(434),
  63529 	80:  uint16(427),
  63530 	81:  uint16(424),
  63531 	82:  uint16(419),
  63532 	83:  uint16(415),
  63533 	84:  uint16(410),
  63534 	85:  uint16(406),
  63535 	86:  uint16(403),
  63536 	87:  uint16(399),
  63537 	88:  uint16(394),
  63538 	89:  uint16(390),
  63539 	90:  uint16(384),
  63540 	91:  uint16(384),
  63541 	92:  uint16(377),
  63542 	93:  uint16(374),
  63543 	94:  uint16(370),
  63544 	95:  uint16(366),
  63545 	96:  uint16(362),
  63546 	97:  uint16(359),
  63547 	98:  uint16(355),
  63548 	99:  uint16(351),
  63549 	100: uint16(347),
  63550 	101: uint16(342),
  63551 	102: uint16(342),
  63552 	103: uint16(336),
  63553 	104: uint16(333),
  63554 	105: uint16(330),
  63555 	106: uint16(326),
  63556 	107: uint16(323),
  63557 	108: uint16(320),
  63558 	109: uint16(316),
  63559 	110: uint16(312),
  63560 	111: uint16(308),
  63561 	112: uint16(305),
  63562 	113: uint16(302),
  63563 	114: uint16(299),
  63564 	115: uint16(296),
  63565 	116: uint16(293),
  63566 	117: uint16(288),
  63567 	118: uint16(287),
  63568 	119: uint16(283),
  63569 	120: uint16(280),
  63570 	121: uint16(277),
  63571 	122: uint16(274),
  63572 	123: uint16(272),
  63573 	124: uint16(268),
  63574 	125: uint16(266),
  63575 	126: uint16(262),
  63576 	127: uint16(256),
  63577 	128: uint16(256),
  63578 	129: uint16(256),
  63579 	130: uint16(251),
  63580 	131: uint16(248),
  63581 	132: uint16(245),
  63582 	133: uint16(242),
  63583 	134: uint16(240),
  63584 	135: uint16(237),
  63585 	136: uint16(234),
  63586 	137: uint16(232),
  63587 	138: uint16(228),
  63588 	139: uint16(226),
  63589 	140: uint16(223),
  63590 	141: uint16(221),
  63591 	142: uint16(218),
  63592 	143: uint16(216),
  63593 	144: uint16(214),
  63594 	145: uint16(211),
  63595 	146: uint16(208),
  63596 	147: uint16(205),
  63597 	148: uint16(203),
  63598 	149: uint16(201),
  63599 	150: uint16(198),
  63600 	151: uint16(196),
  63601 	152: uint16(192),
  63602 	153: uint16(191),
  63603 	154: uint16(188),
  63604 	155: uint16(187),
  63605 	156: uint16(183),
  63606 	157: uint16(181),
  63607 	158: uint16(179),
  63608 	159: uint16(176),
  63609 	160: uint16(175),
  63610 	161: uint16(171),
  63611 	162: uint16(171),
  63612 	163: uint16(168),
  63613 	164: uint16(165),
  63614 	165: uint16(163),
  63615 	166: uint16(160),
  63616 	167: uint16(159),
  63617 	168: uint16(156),
  63618 	169: uint16(154),
  63619 	170: uint16(152),
  63620 	171: uint16(150),
  63621 	172: uint16(148),
  63622 	173: uint16(146),
  63623 	174: uint16(144),
  63624 	175: uint16(142),
  63625 	176: uint16(139),
  63626 	177: uint16(138),
  63627 	178: uint16(135),
  63628 	179: uint16(133),
  63629 	180: uint16(131),
  63630 	181: uint16(128),
  63631 	182: uint16(128),
  63632 	183: uint16(125),
  63633 	184: uint16(123),
  63634 	185: uint16(121),
  63635 	186: uint16(119),
  63636 	187: uint16(117),
  63637 	188: uint16(115),
  63638 	189: uint16(113),
  63639 	190: uint16(111),
  63640 	191: uint16(110),
  63641 	192: uint16(107),
  63642 	193: uint16(105),
  63643 	194: uint16(103),
  63644 	195: uint16(102),
  63645 	196: uint16(100),
  63646 	197: uint16(98),
  63647 	198: uint16(96),
  63648 	199: uint16(94),
  63649 	200: uint16(92),
  63650 	201: uint16(91),
  63651 	202: uint16(89),
  63652 	203: uint16(86),
  63653 	204: uint16(86),
  63654 	205: uint16(83),
  63655 	206: uint16(82),
  63656 	207: uint16(80),
  63657 	208: uint16(77),
  63658 	209: uint16(76),
  63659 	210: uint16(74),
  63660 	211: uint16(73),
  63661 	212: uint16(71),
  63662 	213: uint16(69),
  63663 	214: uint16(67),
  63664 	215: uint16(66),
  63665 	216: uint16(64),
  63666 	217: uint16(63),
  63667 	218: uint16(61),
  63668 	219: uint16(59),
  63669 	220: uint16(57),
  63670 	221: uint16(55),
  63671 	222: uint16(54),
  63672 	223: uint16(52),
  63673 	224: uint16(51),
  63674 	225: uint16(49),
  63675 	226: uint16(47),
  63676 	227: uint16(46),
  63677 	228: uint16(44),
  63678 	229: uint16(43),
  63679 	230: uint16(41),
  63680 	231: uint16(40),
  63681 	232: uint16(38),
  63682 	233: uint16(36),
  63683 	234: uint16(35),
  63684 	235: uint16(33),
  63685 	236: uint16(32),
  63686 	237: uint16(30),
  63687 	238: uint16(29),
  63688 	239: uint16(27),
  63689 	240: uint16(25),
  63690 	241: uint16(24),
  63691 	242: uint16(22),
  63692 	243: uint16(21),
  63693 	244: uint16(19),
  63694 	245: uint16(18),
  63695 	246: uint16(16),
  63696 	247: uint16(15),
  63697 	248: uint16(13),
  63698 	249: uint16(12),
  63699 	250: uint16(10),
  63700 	251: uint16(9),
  63701 	252: uint16(7),
  63702 	253: uint16(6),
  63703 	254: uint16(4),
  63704 	255: uint16(3),
  63705 }
  63706 
  63707 var VP8FTransform VP8Fdct
  63708 
  63709 var VP8FTransform2 VP8Fdct
  63710 
  63711 var VP8FTransformWHT VP8WHT
  63712 
  63713 // C documentation
  63714 //
  63715 //	// note: these values include the fixed VP8BitCost(1, 145) mode selection cost.
  63716 var VP8FixedCostsI16 = [4]uint16_t{
  63717 	0: uint16(663),
  63718 	1: uint16(919),
  63719 	2: uint16(872),
  63720 	3: uint16(919),
  63721 }
  63722 
  63723 var VP8FixedCostsI4 = [10][10][10]uint16_t{
  63724 	0: {
  63725 		0: {
  63726 			0: uint16(40),
  63727 			1: uint16(1151),
  63728 			2: uint16(1723),
  63729 			3: uint16(1874),
  63730 			4: uint16(2103),
  63731 			5: uint16(2019),
  63732 			6: uint16(1628),
  63733 			7: uint16(1777),
  63734 			8: uint16(2226),
  63735 			9: uint16(2137),
  63736 		},
  63737 		1: {
  63738 			0: uint16(192),
  63739 			1: uint16(469),
  63740 			2: uint16(1296),
  63741 			3: uint16(1308),
  63742 			4: uint16(1849),
  63743 			5: uint16(1794),
  63744 			6: uint16(1781),
  63745 			7: uint16(1703),
  63746 			8: uint16(1713),
  63747 			9: uint16(1522),
  63748 		},
  63749 		2: {
  63750 			0: uint16(142),
  63751 			1: uint16(910),
  63752 			2: uint16(762),
  63753 			3: uint16(1684),
  63754 			4: uint16(1849),
  63755 			5: uint16(1576),
  63756 			6: uint16(1460),
  63757 			7: uint16(1305),
  63758 			8: uint16(1801),
  63759 			9: uint16(1657),
  63760 		},
  63761 		3: {
  63762 			0: uint16(559),
  63763 			1: uint16(641),
  63764 			2: uint16(1370),
  63765 			3: uint16(421),
  63766 			4: uint16(1182),
  63767 			5: uint16(1569),
  63768 			6: uint16(1612),
  63769 			7: uint16(1725),
  63770 			8: uint16(863),
  63771 			9: uint16(1007),
  63772 		},
  63773 		4: {
  63774 			0: uint16(299),
  63775 			1: uint16(1059),
  63776 			2: uint16(1256),
  63777 			3: uint16(1108),
  63778 			4: uint16(636),
  63779 			5: uint16(1068),
  63780 			6: uint16(1581),
  63781 			7: uint16(1883),
  63782 			8: uint16(869),
  63783 			9: uint16(1142),
  63784 		},
  63785 		5: {
  63786 			0: uint16(277),
  63787 			1: uint16(1111),
  63788 			2: uint16(707),
  63789 			3: uint16(1362),
  63790 			4: uint16(1089),
  63791 			5: uint16(672),
  63792 			6: uint16(1603),
  63793 			7: uint16(1541),
  63794 			8: uint16(1545),
  63795 			9: uint16(1291),
  63796 		},
  63797 		6: {
  63798 			0: uint16(214),
  63799 			1: uint16(781),
  63800 			2: uint16(1609),
  63801 			3: uint16(1303),
  63802 			4: uint16(1632),
  63803 			5: uint16(2229),
  63804 			6: uint16(726),
  63805 			7: uint16(1560),
  63806 			8: uint16(1713),
  63807 			9: uint16(918),
  63808 		},
  63809 		7: {
  63810 			0: uint16(152),
  63811 			1: uint16(1037),
  63812 			2: uint16(1046),
  63813 			3: uint16(1759),
  63814 			4: uint16(1983),
  63815 			5: uint16(2174),
  63816 			6: uint16(1358),
  63817 			7: uint16(742),
  63818 			8: uint16(1740),
  63819 			9: uint16(1390),
  63820 		},
  63821 		8: {
  63822 			0: uint16(512),
  63823 			1: uint16(1046),
  63824 			2: uint16(1420),
  63825 			3: uint16(753),
  63826 			4: uint16(752),
  63827 			5: uint16(1297),
  63828 			6: uint16(1486),
  63829 			7: uint16(1613),
  63830 			8: uint16(460),
  63831 			9: uint16(1207),
  63832 		},
  63833 		9: {
  63834 			0: uint16(424),
  63835 			1: uint16(827),
  63836 			2: uint16(1362),
  63837 			3: uint16(719),
  63838 			4: uint16(1462),
  63839 			5: uint16(1202),
  63840 			6: uint16(1199),
  63841 			7: uint16(1476),
  63842 			8: uint16(1199),
  63843 			9: uint16(538),
  63844 		},
  63845 	},
  63846 	1: {
  63847 		0: {
  63848 			0: uint16(240),
  63849 			1: uint16(402),
  63850 			2: uint16(1134),
  63851 			3: uint16(1491),
  63852 			4: uint16(1659),
  63853 			5: uint16(1505),
  63854 			6: uint16(1517),
  63855 			7: uint16(1555),
  63856 			8: uint16(1979),
  63857 			9: uint16(2099),
  63858 		},
  63859 		1: {
  63860 			0: uint16(467),
  63861 			1: uint16(242),
  63862 			2: uint16(960),
  63863 			3: uint16(1232),
  63864 			4: uint16(1714),
  63865 			5: uint16(1620),
  63866 			6: uint16(1834),
  63867 			7: uint16(1570),
  63868 			8: uint16(1676),
  63869 			9: uint16(1391),
  63870 		},
  63871 		2: {
  63872 			0: uint16(500),
  63873 			1: uint16(455),
  63874 			2: uint16(463),
  63875 			3: uint16(1507),
  63876 			4: uint16(1699),
  63877 			5: uint16(1282),
  63878 			6: uint16(1564),
  63879 			7: uint16(982),
  63880 			8: uint16(2114),
  63881 			9: uint16(2114),
  63882 		},
  63883 		3: {
  63884 			0: uint16(672),
  63885 			1: uint16(643),
  63886 			2: uint16(1372),
  63887 			3: uint16(331),
  63888 			4: uint16(1589),
  63889 			5: uint16(1667),
  63890 			6: uint16(1453),
  63891 			7: uint16(1938),
  63892 			8: uint16(996),
  63893 			9: uint16(876),
  63894 		},
  63895 		4: {
  63896 			0: uint16(458),
  63897 			1: uint16(783),
  63898 			2: uint16(1037),
  63899 			3: uint16(911),
  63900 			4: uint16(738),
  63901 			5: uint16(968),
  63902 			6: uint16(1165),
  63903 			7: uint16(1518),
  63904 			8: uint16(859),
  63905 			9: uint16(1033),
  63906 		},
  63907 		5: {
  63908 			0: uint16(504),
  63909 			1: uint16(815),
  63910 			2: uint16(504),
  63911 			3: uint16(1139),
  63912 			4: uint16(1219),
  63913 			5: uint16(719),
  63914 			6: uint16(1506),
  63915 			7: uint16(1085),
  63916 			8: uint16(1268),
  63917 			9: uint16(1268),
  63918 		},
  63919 		6: {
  63920 			0: uint16(333),
  63921 			1: uint16(630),
  63922 			2: uint16(1445),
  63923 			3: uint16(1239),
  63924 			4: uint16(1883),
  63925 			5: uint16(3672),
  63926 			6: uint16(799),
  63927 			7: uint16(1548),
  63928 			8: uint16(1865),
  63929 			9: uint16(598),
  63930 		},
  63931 		7: {
  63932 			0: uint16(399),
  63933 			1: uint16(644),
  63934 			2: uint16(746),
  63935 			3: uint16(1342),
  63936 			4: uint16(1856),
  63937 			5: uint16(1350),
  63938 			6: uint16(1493),
  63939 			7: uint16(613),
  63940 			8: uint16(1855),
  63941 			9: uint16(1015),
  63942 		},
  63943 		8: {
  63944 			0: uint16(622),
  63945 			1: uint16(749),
  63946 			2: uint16(1205),
  63947 			3: uint16(608),
  63948 			4: uint16(1066),
  63949 			5: uint16(1408),
  63950 			6: uint16(1290),
  63951 			7: uint16(1406),
  63952 			8: uint16(546),
  63953 			9: uint16(971),
  63954 		},
  63955 		9: {
  63956 			0: uint16(500),
  63957 			1: uint16(753),
  63958 			2: uint16(1041),
  63959 			3: uint16(668),
  63960 			4: uint16(1230),
  63961 			5: uint16(1617),
  63962 			6: uint16(1297),
  63963 			7: uint16(1425),
  63964 			8: uint16(1383),
  63965 			9: uint16(523),
  63966 		},
  63967 	},
  63968 	2: {
  63969 		0: {
  63970 			0: uint16(394),
  63971 			1: uint16(553),
  63972 			2: uint16(523),
  63973 			3: uint16(1502),
  63974 			4: uint16(1536),
  63975 			5: uint16(981),
  63976 			6: uint16(1608),
  63977 			7: uint16(1142),
  63978 			8: uint16(1666),
  63979 			9: uint16(2181),
  63980 		},
  63981 		1: {
  63982 			0: uint16(655),
  63983 			1: uint16(430),
  63984 			2: uint16(375),
  63985 			3: uint16(1411),
  63986 			4: uint16(1861),
  63987 			5: uint16(1220),
  63988 			6: uint16(1677),
  63989 			7: uint16(1135),
  63990 			8: uint16(1978),
  63991 			9: uint16(1553),
  63992 		},
  63993 		2: {
  63994 			0: uint16(690),
  63995 			1: uint16(640),
  63996 			2: uint16(245),
  63997 			3: uint16(1954),
  63998 			4: uint16(2070),
  63999 			5: uint16(1194),
  64000 			6: uint16(1528),
  64001 			7: uint16(982),
  64002 			8: uint16(1972),
  64003 			9: uint16(2232),
  64004 		},
  64005 		3: {
  64006 			0: uint16(559),
  64007 			1: uint16(834),
  64008 			2: uint16(741),
  64009 			3: uint16(867),
  64010 			4: uint16(1131),
  64011 			5: uint16(980),
  64012 			6: uint16(1225),
  64013 			7: uint16(852),
  64014 			8: uint16(1092),
  64015 			9: uint16(784),
  64016 		},
  64017 		4: {
  64018 			0: uint16(690),
  64019 			1: uint16(875),
  64020 			2: uint16(516),
  64021 			3: uint16(959),
  64022 			4: uint16(673),
  64023 			5: uint16(894),
  64024 			6: uint16(1056),
  64025 			7: uint16(1190),
  64026 			8: uint16(1528),
  64027 			9: uint16(1126),
  64028 		},
  64029 		5: {
  64030 			0: uint16(740),
  64031 			1: uint16(951),
  64032 			2: uint16(384),
  64033 			3: uint16(1277),
  64034 			4: uint16(1177),
  64035 			5: uint16(492),
  64036 			6: uint16(1579),
  64037 			7: uint16(1155),
  64038 			8: uint16(1846),
  64039 			9: uint16(1513),
  64040 		},
  64041 		6: {
  64042 			0: uint16(323),
  64043 			1: uint16(775),
  64044 			2: uint16(1062),
  64045 			3: uint16(1776),
  64046 			4: uint16(3062),
  64047 			5: uint16(1274),
  64048 			6: uint16(813),
  64049 			7: uint16(1188),
  64050 			8: uint16(1372),
  64051 			9: uint16(655),
  64052 		},
  64053 		7: {
  64054 			0: uint16(488),
  64055 			1: uint16(971),
  64056 			2: uint16(484),
  64057 			3: uint16(1767),
  64058 			4: uint16(1515),
  64059 			5: uint16(1775),
  64060 			6: uint16(1115),
  64061 			7: uint16(503),
  64062 			8: uint16(1539),
  64063 			9: uint16(1461),
  64064 		},
  64065 		8: {
  64066 			0: uint16(740),
  64067 			1: uint16(1006),
  64068 			2: uint16(998),
  64069 			3: uint16(709),
  64070 			4: uint16(851),
  64071 			5: uint16(1230),
  64072 			6: uint16(1337),
  64073 			7: uint16(788),
  64074 			8: uint16(741),
  64075 			9: uint16(721),
  64076 		},
  64077 		9: {
  64078 			0: uint16(522),
  64079 			1: uint16(1073),
  64080 			2: uint16(573),
  64081 			3: uint16(1045),
  64082 			4: uint16(1346),
  64083 			5: uint16(887),
  64084 			6: uint16(1046),
  64085 			7: uint16(1146),
  64086 			8: uint16(1203),
  64087 			9: uint16(697),
  64088 		},
  64089 	},
  64090 	3: {
  64091 		0: {
  64092 			0: uint16(105),
  64093 			1: uint16(864),
  64094 			2: uint16(1442),
  64095 			3: uint16(1009),
  64096 			4: uint16(1934),
  64097 			5: uint16(1840),
  64098 			6: uint16(1519),
  64099 			7: uint16(1920),
  64100 			8: uint16(1673),
  64101 			9: uint16(1579),
  64102 		},
  64103 		1: {
  64104 			0: uint16(534),
  64105 			1: uint16(305),
  64106 			2: uint16(1193),
  64107 			3: uint16(683),
  64108 			4: uint16(1388),
  64109 			5: uint16(2164),
  64110 			6: uint16(1802),
  64111 			7: uint16(1894),
  64112 			8: uint16(1264),
  64113 			9: uint16(1170),
  64114 		},
  64115 		2: {
  64116 			0: uint16(305),
  64117 			1: uint16(518),
  64118 			2: uint16(877),
  64119 			3: uint16(1108),
  64120 			4: uint16(1426),
  64121 			5: uint16(3215),
  64122 			6: uint16(1425),
  64123 			7: uint16(1064),
  64124 			8: uint16(1320),
  64125 			9: uint16(1242),
  64126 		},
  64127 		3: {
  64128 			0: uint16(683),
  64129 			1: uint16(732),
  64130 			2: uint16(1927),
  64131 			3: uint16(257),
  64132 			4: uint16(1493),
  64133 			5: uint16(2048),
  64134 			6: uint16(1858),
  64135 			7: uint16(1552),
  64136 			8: uint16(1055),
  64137 			9: uint16(947),
  64138 		},
  64139 		4: {
  64140 			0: uint16(394),
  64141 			1: uint16(814),
  64142 			2: uint16(1024),
  64143 			3: uint16(660),
  64144 			4: uint16(959),
  64145 			5: uint16(1556),
  64146 			6: uint16(1282),
  64147 			7: uint16(1289),
  64148 			8: uint16(893),
  64149 			9: uint16(1047),
  64150 		},
  64151 		5: {
  64152 			0: uint16(528),
  64153 			1: uint16(615),
  64154 			2: uint16(996),
  64155 			3: uint16(940),
  64156 			4: uint16(1201),
  64157 			5: uint16(635),
  64158 			6: uint16(1094),
  64159 			7: uint16(2515),
  64160 			8: uint16(803),
  64161 			9: uint16(1358),
  64162 		},
  64163 		6: {
  64164 			0: uint16(347),
  64165 			1: uint16(614),
  64166 			2: uint16(1609),
  64167 			3: uint16(1187),
  64168 			4: uint16(3133),
  64169 			5: uint16(1345),
  64170 			6: uint16(1007),
  64171 			7: uint16(1339),
  64172 			8: uint16(1017),
  64173 			9: uint16(667),
  64174 		},
  64175 		7: {
  64176 			0: uint16(218),
  64177 			1: uint16(740),
  64178 			2: uint16(878),
  64179 			3: uint16(1605),
  64180 			4: uint16(3650),
  64181 			5: uint16(3650),
  64182 			6: uint16(1345),
  64183 			7: uint16(758),
  64184 			8: uint16(1357),
  64185 			9: uint16(1617),
  64186 		},
  64187 		8: {
  64188 			0: uint16(672),
  64189 			1: uint16(750),
  64190 			2: uint16(1541),
  64191 			3: uint16(558),
  64192 			4: uint16(1257),
  64193 			5: uint16(1599),
  64194 			6: uint16(1870),
  64195 			7: uint16(2135),
  64196 			8: uint16(402),
  64197 			9: uint16(1087),
  64198 		},
  64199 		9: {
  64200 			0: uint16(592),
  64201 			1: uint16(684),
  64202 			2: uint16(1161),
  64203 			3: uint16(430),
  64204 			4: uint16(1092),
  64205 			5: uint16(1497),
  64206 			6: uint16(1475),
  64207 			7: uint16(1489),
  64208 			8: uint16(1095),
  64209 			9: uint16(822),
  64210 		},
  64211 	},
  64212 	4: {
  64213 		0: {
  64214 			0: uint16(228),
  64215 			1: uint16(1056),
  64216 			2: uint16(1059),
  64217 			3: uint16(1368),
  64218 			4: uint16(752),
  64219 			5: uint16(982),
  64220 			6: uint16(1512),
  64221 			7: uint16(1518),
  64222 			8: uint16(987),
  64223 			9: uint16(1782),
  64224 		},
  64225 		1: {
  64226 			0: uint16(494),
  64227 			1: uint16(514),
  64228 			2: uint16(818),
  64229 			3: uint16(942),
  64230 			4: uint16(965),
  64231 			5: uint16(892),
  64232 			6: uint16(1610),
  64233 			7: uint16(1356),
  64234 			8: uint16(1048),
  64235 			9: uint16(1363),
  64236 		},
  64237 		2: {
  64238 			0: uint16(512),
  64239 			1: uint16(648),
  64240 			2: uint16(591),
  64241 			3: uint16(1042),
  64242 			4: uint16(761),
  64243 			5: uint16(991),
  64244 			6: uint16(1196),
  64245 			7: uint16(1454),
  64246 			8: uint16(1309),
  64247 			9: uint16(1463),
  64248 		},
  64249 		3: {
  64250 			0: uint16(683),
  64251 			1: uint16(749),
  64252 			2: uint16(1043),
  64253 			3: uint16(676),
  64254 			4: uint16(841),
  64255 			5: uint16(1396),
  64256 			6: uint16(1133),
  64257 			7: uint16(1138),
  64258 			8: uint16(654),
  64259 			9: uint16(939),
  64260 		},
  64261 		4: {
  64262 			0: uint16(622),
  64263 			1: uint16(1101),
  64264 			2: uint16(1126),
  64265 			3: uint16(994),
  64266 			4: uint16(361),
  64267 			5: uint16(1077),
  64268 			6: uint16(1203),
  64269 			7: uint16(1318),
  64270 			8: uint16(877),
  64271 			9: uint16(1219),
  64272 		},
  64273 		5: {
  64274 			0: uint16(631),
  64275 			1: uint16(1068),
  64276 			2: uint16(857),
  64277 			3: uint16(1650),
  64278 			4: uint16(651),
  64279 			5: uint16(477),
  64280 			6: uint16(1650),
  64281 			7: uint16(1419),
  64282 			8: uint16(828),
  64283 			9: uint16(1170),
  64284 		},
  64285 		6: {
  64286 			0: uint16(555),
  64287 			1: uint16(727),
  64288 			2: uint16(1068),
  64289 			3: uint16(1335),
  64290 			4: uint16(3127),
  64291 			5: uint16(1339),
  64292 			6: uint16(820),
  64293 			7: uint16(1331),
  64294 			8: uint16(1077),
  64295 			9: uint16(429),
  64296 		},
  64297 		7: {
  64298 			0: uint16(504),
  64299 			1: uint16(879),
  64300 			2: uint16(624),
  64301 			3: uint16(1398),
  64302 			4: uint16(889),
  64303 			5: uint16(889),
  64304 			6: uint16(1392),
  64305 			7: uint16(808),
  64306 			8: uint16(891),
  64307 			9: uint16(1406),
  64308 		},
  64309 		8: {
  64310 			0: uint16(683),
  64311 			1: uint16(1602),
  64312 			2: uint16(1289),
  64313 			3: uint16(977),
  64314 			4: uint16(578),
  64315 			5: uint16(983),
  64316 			6: uint16(1280),
  64317 			7: uint16(1708),
  64318 			8: uint16(406),
  64319 			9: uint16(1122),
  64320 		},
  64321 		9: {
  64322 			0: uint16(399),
  64323 			1: uint16(865),
  64324 			2: uint16(1433),
  64325 			3: uint16(1070),
  64326 			4: uint16(1072),
  64327 			5: uint16(764),
  64328 			6: uint16(968),
  64329 			7: uint16(1477),
  64330 			8: uint16(1223),
  64331 			9: uint16(678),
  64332 		},
  64333 	},
  64334 	5: {
  64335 		0: {
  64336 			0: uint16(333),
  64337 			1: uint16(760),
  64338 			2: uint16(935),
  64339 			3: uint16(1638),
  64340 			4: uint16(1010),
  64341 			5: uint16(529),
  64342 			6: uint16(1646),
  64343 			7: uint16(1410),
  64344 			8: uint16(1472),
  64345 			9: uint16(2219),
  64346 		},
  64347 		1: {
  64348 			0: uint16(512),
  64349 			1: uint16(494),
  64350 			2: uint16(750),
  64351 			3: uint16(1160),
  64352 			4: uint16(1215),
  64353 			5: uint16(610),
  64354 			6: uint16(1870),
  64355 			7: uint16(1868),
  64356 			8: uint16(1628),
  64357 			9: uint16(1169),
  64358 		},
  64359 		2: {
  64360 			0: uint16(572),
  64361 			1: uint16(646),
  64362 			2: uint16(492),
  64363 			3: uint16(1934),
  64364 			4: uint16(1208),
  64365 			5: uint16(603),
  64366 			6: uint16(1580),
  64367 			7: uint16(1099),
  64368 			8: uint16(1398),
  64369 			9: uint16(1995),
  64370 		},
  64371 		3: {
  64372 			0: uint16(786),
  64373 			1: uint16(789),
  64374 			2: uint16(942),
  64375 			3: uint16(581),
  64376 			4: uint16(1018),
  64377 			5: uint16(951),
  64378 			6: uint16(1599),
  64379 			7: uint16(1207),
  64380 			8: uint16(731),
  64381 			9: uint16(768),
  64382 		},
  64383 		4: {
  64384 			0: uint16(690),
  64385 			1: uint16(1015),
  64386 			2: uint16(672),
  64387 			3: uint16(1078),
  64388 			4: uint16(582),
  64389 			5: uint16(504),
  64390 			6: uint16(1693),
  64391 			7: uint16(1438),
  64392 			8: uint16(1108),
  64393 			9: uint16(2897),
  64394 		},
  64395 		5: {
  64396 			0: uint16(768),
  64397 			1: uint16(1267),
  64398 			2: uint16(571),
  64399 			3: uint16(2005),
  64400 			4: uint16(1243),
  64401 			5: uint16(244),
  64402 			6: uint16(2881),
  64403 			7: uint16(1380),
  64404 			8: uint16(1786),
  64405 			9: uint16(1453),
  64406 		},
  64407 		6: {
  64408 			0: uint16(452),
  64409 			1: uint16(899),
  64410 			2: uint16(1293),
  64411 			3: uint16(903),
  64412 			4: uint16(1311),
  64413 			5: uint16(3100),
  64414 			6: uint16(465),
  64415 			7: uint16(1311),
  64416 			8: uint16(1319),
  64417 			9: uint16(813),
  64418 		},
  64419 		7: {
  64420 			0: uint16(394),
  64421 			1: uint16(927),
  64422 			2: uint16(942),
  64423 			3: uint16(1103),
  64424 			4: uint16(1358),
  64425 			5: uint16(1104),
  64426 			6: uint16(946),
  64427 			7: uint16(593),
  64428 			8: uint16(1363),
  64429 			9: uint16(1109),
  64430 		},
  64431 		8: {
  64432 			0: uint16(559),
  64433 			1: uint16(1005),
  64434 			2: uint16(1007),
  64435 			3: uint16(1016),
  64436 			4: uint16(658),
  64437 			5: uint16(1173),
  64438 			6: uint16(1021),
  64439 			7: uint16(1164),
  64440 			8: uint16(623),
  64441 			9: uint16(1028),
  64442 		},
  64443 		9: {
  64444 			0: uint16(564),
  64445 			1: uint16(796),
  64446 			2: uint16(632),
  64447 			3: uint16(1005),
  64448 			4: uint16(1014),
  64449 			5: uint16(863),
  64450 			6: uint16(2316),
  64451 			7: uint16(1268),
  64452 			8: uint16(938),
  64453 			9: uint16(764),
  64454 		},
  64455 	},
  64456 	6: {
  64457 		0: {
  64458 			0: uint16(266),
  64459 			1: uint16(606),
  64460 			2: uint16(1098),
  64461 			3: uint16(1228),
  64462 			4: uint16(1497),
  64463 			5: uint16(1243),
  64464 			6: uint16(948),
  64465 			7: uint16(1030),
  64466 			8: uint16(1734),
  64467 			9: uint16(1461),
  64468 		},
  64469 		1: {
  64470 			0: uint16(366),
  64471 			1: uint16(585),
  64472 			2: uint16(901),
  64473 			3: uint16(1060),
  64474 			4: uint16(1407),
  64475 			5: uint16(1247),
  64476 			6: uint16(876),
  64477 			7: uint16(1134),
  64478 			8: uint16(1620),
  64479 			9: uint16(1054),
  64480 		},
  64481 		2: {
  64482 			0: uint16(452),
  64483 			1: uint16(565),
  64484 			2: uint16(542),
  64485 			3: uint16(1729),
  64486 			4: uint16(1479),
  64487 			5: uint16(1479),
  64488 			6: uint16(1016),
  64489 			7: uint16(886),
  64490 			8: uint16(2938),
  64491 			9: uint16(1150),
  64492 		},
  64493 		3: {
  64494 			0: uint16(555),
  64495 			1: uint16(1088),
  64496 			2: uint16(1533),
  64497 			3: uint16(950),
  64498 			4: uint16(1354),
  64499 			5: uint16(895),
  64500 			6: uint16(834),
  64501 			7: uint16(1019),
  64502 			8: uint16(1021),
  64503 			9: uint16(496),
  64504 		},
  64505 		4: {
  64506 			0: uint16(704),
  64507 			1: uint16(815),
  64508 			2: uint16(1193),
  64509 			3: uint16(971),
  64510 			4: uint16(973),
  64511 			5: uint16(640),
  64512 			6: uint16(1217),
  64513 			7: uint16(2214),
  64514 			8: uint16(832),
  64515 			9: uint16(578),
  64516 		},
  64517 		5: {
  64518 			0: uint16(672),
  64519 			1: uint16(1245),
  64520 			2: uint16(579),
  64521 			3: uint16(871),
  64522 			4: uint16(875),
  64523 			5: uint16(774),
  64524 			6: uint16(872),
  64525 			7: uint16(1273),
  64526 			8: uint16(1027),
  64527 			9: uint16(949),
  64528 		},
  64529 		6: {
  64530 			0: uint16(296),
  64531 			1: uint16(1134),
  64532 			2: uint16(2050),
  64533 			3: uint16(1784),
  64534 			4: uint16(1636),
  64535 			5: uint16(3425),
  64536 			6: uint16(442),
  64537 			7: uint16(1550),
  64538 			8: uint16(2076),
  64539 			9: uint16(722),
  64540 		},
  64541 		7: {
  64542 			0: uint16(342),
  64543 			1: uint16(982),
  64544 			2: uint16(1259),
  64545 			3: uint16(1846),
  64546 			4: uint16(1848),
  64547 			5: uint16(1848),
  64548 			6: uint16(622),
  64549 			7: uint16(568),
  64550 			8: uint16(1847),
  64551 			9: uint16(1052),
  64552 		},
  64553 		8: {
  64554 			0: uint16(555),
  64555 			1: uint16(1064),
  64556 			2: uint16(1304),
  64557 			3: uint16(828),
  64558 			4: uint16(746),
  64559 			5: uint16(1343),
  64560 			6: uint16(1075),
  64561 			7: uint16(1329),
  64562 			8: uint16(1078),
  64563 			9: uint16(494),
  64564 		},
  64565 		9: {
  64566 			0: uint16(288),
  64567 			1: uint16(1167),
  64568 			2: uint16(1285),
  64569 			3: uint16(1174),
  64570 			4: uint16(1639),
  64571 			5: uint16(1639),
  64572 			6: uint16(833),
  64573 			7: uint16(2254),
  64574 			8: uint16(1304),
  64575 			9: uint16(509),
  64576 		},
  64577 	},
  64578 	7: {
  64579 		0: {
  64580 			0: uint16(342),
  64581 			1: uint16(719),
  64582 			2: uint16(767),
  64583 			3: uint16(1866),
  64584 			4: uint16(1757),
  64585 			5: uint16(1270),
  64586 			6: uint16(1246),
  64587 			7: uint16(550),
  64588 			8: uint16(1746),
  64589 			9: uint16(2151),
  64590 		},
  64591 		1: {
  64592 			0: uint16(483),
  64593 			1: uint16(653),
  64594 			2: uint16(694),
  64595 			3: uint16(1509),
  64596 			4: uint16(1459),
  64597 			5: uint16(1410),
  64598 			6: uint16(1218),
  64599 			7: uint16(507),
  64600 			8: uint16(1914),
  64601 			9: uint16(1266),
  64602 		},
  64603 		2: {
  64604 			0: uint16(488),
  64605 			1: uint16(757),
  64606 			2: uint16(447),
  64607 			3: uint16(2979),
  64608 			4: uint16(1813),
  64609 			5: uint16(1268),
  64610 			6: uint16(1654),
  64611 			7: uint16(539),
  64612 			8: uint16(1849),
  64613 			9: uint16(2109),
  64614 		},
  64615 		3: {
  64616 			0: uint16(522),
  64617 			1: uint16(1097),
  64618 			2: uint16(1085),
  64619 			3: uint16(851),
  64620 			4: uint16(1365),
  64621 			5: uint16(1111),
  64622 			6: uint16(851),
  64623 			7: uint16(901),
  64624 			8: uint16(961),
  64625 			9: uint16(605),
  64626 		},
  64627 		4: {
  64628 			0: uint16(709),
  64629 			1: uint16(716),
  64630 			2: uint16(841),
  64631 			3: uint16(728),
  64632 			4: uint16(736),
  64633 			5: uint16(945),
  64634 			6: uint16(941),
  64635 			7: uint16(862),
  64636 			8: uint16(2845),
  64637 			9: uint16(1057),
  64638 		},
  64639 		5: {
  64640 			0: uint16(512),
  64641 			1: uint16(1323),
  64642 			2: uint16(500),
  64643 			3: uint16(1336),
  64644 			4: uint16(1083),
  64645 			5: uint16(681),
  64646 			6: uint16(1342),
  64647 			7: uint16(717),
  64648 			8: uint16(1604),
  64649 			9: uint16(1350),
  64650 		},
  64651 		6: {
  64652 			0: uint16(452),
  64653 			1: uint16(1155),
  64654 			2: uint16(1372),
  64655 			3: uint16(1900),
  64656 			4: uint16(1501),
  64657 			5: uint16(3290),
  64658 			6: uint16(311),
  64659 			7: uint16(944),
  64660 			8: uint16(1919),
  64661 			9: uint16(922),
  64662 		},
  64663 		7: {
  64664 			0: uint16(403),
  64665 			1: uint16(1520),
  64666 			2: uint16(977),
  64667 			3: uint16(2132),
  64668 			4: uint16(1733),
  64669 			5: uint16(3522),
  64670 			6: uint16(1076),
  64671 			7: uint16(276),
  64672 			8: uint16(3335),
  64673 			9: uint16(1547),
  64674 		},
  64675 		8: {
  64676 			0: uint16(559),
  64677 			1: uint16(1374),
  64678 			2: uint16(1101),
  64679 			3: uint16(615),
  64680 			4: uint16(673),
  64681 			5: uint16(2462),
  64682 			6: uint16(974),
  64683 			7: uint16(795),
  64684 			8: uint16(984),
  64685 			9: uint16(984),
  64686 		},
  64687 		9: {
  64688 			0: uint16(547),
  64689 			1: uint16(1122),
  64690 			2: uint16(1062),
  64691 			3: uint16(812),
  64692 			4: uint16(1410),
  64693 			5: uint16(951),
  64694 			6: uint16(1140),
  64695 			7: uint16(622),
  64696 			8: uint16(1268),
  64697 			9: uint16(651),
  64698 		},
  64699 	},
  64700 	8: {
  64701 		0: {
  64702 			0: uint16(165),
  64703 			1: uint16(982),
  64704 			2: uint16(1235),
  64705 			3: uint16(938),
  64706 			4: uint16(1334),
  64707 			5: uint16(1366),
  64708 			6: uint16(1659),
  64709 			7: uint16(1578),
  64710 			8: uint16(964),
  64711 			9: uint16(1612),
  64712 		},
  64713 		1: {
  64714 			0: uint16(592),
  64715 			1: uint16(422),
  64716 			2: uint16(925),
  64717 			3: uint16(847),
  64718 			4: uint16(1139),
  64719 			5: uint16(1112),
  64720 			6: uint16(1387),
  64721 			7: uint16(2036),
  64722 			8: uint16(861),
  64723 			9: uint16(1041),
  64724 		},
  64725 		2: {
  64726 			0: uint16(403),
  64727 			1: uint16(837),
  64728 			2: uint16(732),
  64729 			3: uint16(770),
  64730 			4: uint16(941),
  64731 			5: uint16(1658),
  64732 			6: uint16(1250),
  64733 			7: uint16(809),
  64734 			8: uint16(1407),
  64735 			9: uint16(1407),
  64736 		},
  64737 		3: {
  64738 			0: uint16(896),
  64739 			1: uint16(874),
  64740 			2: uint16(1071),
  64741 			3: uint16(381),
  64742 			4: uint16(1568),
  64743 			5: uint16(1722),
  64744 			6: uint16(1437),
  64745 			7: uint16(2192),
  64746 			8: uint16(480),
  64747 			9: uint16(1035),
  64748 		},
  64749 		4: {
  64750 			0: uint16(640),
  64751 			1: uint16(1098),
  64752 			2: uint16(1012),
  64753 			3: uint16(1032),
  64754 			4: uint16(684),
  64755 			5: uint16(1382),
  64756 			6: uint16(1581),
  64757 			7: uint16(2106),
  64758 			8: uint16(416),
  64759 			9: uint16(865),
  64760 		},
  64761 		5: {
  64762 			0: uint16(559),
  64763 			1: uint16(1005),
  64764 			2: uint16(819),
  64765 			3: uint16(914),
  64766 			4: uint16(710),
  64767 			5: uint16(770),
  64768 			6: uint16(1418),
  64769 			7: uint16(920),
  64770 			8: uint16(838),
  64771 			9: uint16(1435),
  64772 		},
  64773 		6: {
  64774 			0: uint16(415),
  64775 			1: uint16(1258),
  64776 			2: uint16(1245),
  64777 			3: uint16(870),
  64778 			4: uint16(1278),
  64779 			5: uint16(3067),
  64780 			6: uint16(770),
  64781 			7: uint16(1021),
  64782 			8: uint16(1287),
  64783 			9: uint16(522),
  64784 		},
  64785 		7: {
  64786 			0: uint16(406),
  64787 			1: uint16(990),
  64788 			2: uint16(601),
  64789 			3: uint16(1009),
  64790 			4: uint16(1265),
  64791 			5: uint16(1265),
  64792 			6: uint16(1267),
  64793 			7: uint16(759),
  64794 			8: uint16(1017),
  64795 			9: uint16(1277),
  64796 		},
  64797 		8: {
  64798 			0: uint16(968),
  64799 			1: uint16(1182),
  64800 			2: uint16(1329),
  64801 			3: uint16(788),
  64802 			4: uint16(1032),
  64803 			5: uint16(1292),
  64804 			6: uint16(1705),
  64805 			7: uint16(1714),
  64806 			8: uint16(203),
  64807 			9: uint16(1403),
  64808 		},
  64809 		9: {
  64810 			0: uint16(732),
  64811 			1: uint16(877),
  64812 			2: uint16(1279),
  64813 			3: uint16(471),
  64814 			4: uint16(901),
  64815 			5: uint16(1161),
  64816 			6: uint16(1545),
  64817 			7: uint16(1294),
  64818 			8: uint16(755),
  64819 			9: uint16(755),
  64820 		},
  64821 	},
  64822 	9: {
  64823 		0: {
  64824 			0: uint16(111),
  64825 			1: uint16(931),
  64826 			2: uint16(1378),
  64827 			3: uint16(1185),
  64828 			4: uint16(1933),
  64829 			5: uint16(1648),
  64830 			6: uint16(1148),
  64831 			7: uint16(1714),
  64832 			8: uint16(1873),
  64833 			9: uint16(1307),
  64834 		},
  64835 		1: {
  64836 			0: uint16(406),
  64837 			1: uint16(414),
  64838 			2: uint16(1030),
  64839 			3: uint16(1023),
  64840 			4: uint16(1910),
  64841 			5: uint16(1404),
  64842 			6: uint16(1313),
  64843 			7: uint16(1647),
  64844 			8: uint16(1509),
  64845 			9: uint16(793),
  64846 		},
  64847 		2: {
  64848 			0: uint16(342),
  64849 			1: uint16(640),
  64850 			2: uint16(575),
  64851 			3: uint16(1088),
  64852 			4: uint16(1241),
  64853 			5: uint16(1349),
  64854 			6: uint16(1161),
  64855 			7: uint16(1350),
  64856 			8: uint16(1756),
  64857 			9: uint16(1502),
  64858 		},
  64859 		3: {
  64860 			0: uint16(559),
  64861 			1: uint16(766),
  64862 			2: uint16(1185),
  64863 			3: uint16(357),
  64864 			4: uint16(1682),
  64865 			5: uint16(1428),
  64866 			6: uint16(1329),
  64867 			7: uint16(1897),
  64868 			8: uint16(1219),
  64869 			9: uint16(802),
  64870 		},
  64871 		4: {
  64872 			0: uint16(473),
  64873 			1: uint16(909),
  64874 			2: uint16(1164),
  64875 			3: uint16(771),
  64876 			4: uint16(719),
  64877 			5: uint16(2508),
  64878 			6: uint16(1427),
  64879 			7: uint16(1432),
  64880 			8: uint16(722),
  64881 			9: uint16(782),
  64882 		},
  64883 		5: {
  64884 			0: uint16(342),
  64885 			1: uint16(892),
  64886 			2: uint16(785),
  64887 			3: uint16(1145),
  64888 			4: uint16(1150),
  64889 			5: uint16(794),
  64890 			6: uint16(1296),
  64891 			7: uint16(1550),
  64892 			8: uint16(973),
  64893 			9: uint16(1057),
  64894 		},
  64895 		6: {
  64896 			0: uint16(208),
  64897 			1: uint16(1036),
  64898 			2: uint16(1326),
  64899 			3: uint16(1343),
  64900 			4: uint16(1606),
  64901 			5: uint16(3395),
  64902 			6: uint16(815),
  64903 			7: uint16(1455),
  64904 			8: uint16(1618),
  64905 			9: uint16(712),
  64906 		},
  64907 		7: {
  64908 			0: uint16(228),
  64909 			1: uint16(928),
  64910 			2: uint16(890),
  64911 			3: uint16(1046),
  64912 			4: uint16(3499),
  64913 			5: uint16(1711),
  64914 			6: uint16(994),
  64915 			7: uint16(829),
  64916 			8: uint16(1720),
  64917 			9: uint16(1318),
  64918 		},
  64919 		8: {
  64920 			0: uint16(768),
  64921 			1: uint16(724),
  64922 			2: uint16(1058),
  64923 			3: uint16(636),
  64924 			4: uint16(991),
  64925 			5: uint16(1075),
  64926 			6: uint16(1319),
  64927 			7: uint16(1324),
  64928 			8: uint16(616),
  64929 			9: uint16(825),
  64930 		},
  64931 		9: {
  64932 			0: uint16(305),
  64933 			1: uint16(1167),
  64934 			2: uint16(1358),
  64935 			3: uint16(899),
  64936 			4: uint16(1587),
  64937 			5: uint16(1587),
  64938 			6: uint16(987),
  64939 			7: uint16(1988),
  64940 			8: uint16(1332),
  64941 			9: uint16(501),
  64942 		},
  64943 	},
  64944 }
  64945 
  64946 //------------------------------------------------------------------------------
  64947 // Mode cost tables.
  64948 
  64949 // C documentation
  64950 //
  64951 //	// These are the fixed probabilities (in the coding trees) turned into bit-cost
  64952 //	// by calling VP8BitCost().
  64953 var VP8FixedCostsUV = [4]uint16_t{
  64954 	0: uint16(302),
  64955 	1: uint16(984),
  64956 	2: uint16(439),
  64957 	3: uint16(642),
  64958 }
  64959 
  64960 var VP8GetCPUInfo = uintptr(0)
  64961 
  64962 //------------------------------------------------------------------------------
  64963 // init function
  64964 
  64965 var VP8GetResidualCost VP8GetResidualCostFunc
  64966 
  64967 var VP8HFilter16 VP8LumaFilterFunc
  64968 
  64969 var VP8HFilter16i VP8LumaFilterFunc
  64970 
  64971 var VP8HFilter8 VP8ChromaFilterFunc
  64972 
  64973 var VP8HFilter8i VP8ChromaFilterFunc
  64974 
  64975 //------------------------------------------------------------------------------
  64976 // Form the predictions in cache
  64977 
  64978 // C documentation
  64979 //
  64980 //	// Must be ordered using {DC_PRED, TM_PRED, V_PRED, H_PRED} as index
  64981 var VP8I16ModeOffsets = [4]uint16_t{
  64982 	1: uint16(libc.Int32FromInt32(0)*libc.Int32FromInt32(16)*libc.Int32FromInt32(BPS) + libc.Int32FromInt32(16)),
  64983 	2: uint16(libc.Int32FromInt32(1) * libc.Int32FromInt32(16) * libc.Int32FromInt32(BPS)),
  64984 	3: uint16(libc.Int32FromInt32(1)*libc.Int32FromInt32(16)*libc.Int32FromInt32(BPS) + libc.Int32FromInt32(16)),
  64985 }
  64986 
  64987 var VP8ITransform VP8Idct
  64988 
  64989 //------------------------------------------------------------------------------
  64990 
  64991 var VP8LAddGreenToBlueAndRed VP8LProcessDecBlueAndRedFunc
  64992 
  64993 var VP8LAddGreenToBlueAndRed_SSE VP8LProcessDecBlueAndRedFunc
  64994 
  64995 var VP8LAddVector VP8LAddVectorFunc
  64996 
  64997 var VP8LAddVectorEq VP8LAddVectorEqFunc
  64998 
  64999 var VP8LBundleColorMap VP8LBundleColorMapFunc
  65000 
  65001 var VP8LBundleColorMap_SSE VP8LBundleColorMapFunc
  65002 
  65003 var VP8LCollectColorBlueTransforms VP8LCollectColorBlueTransformsFunc
  65004 
  65005 var VP8LCollectColorBlueTransforms_SSE VP8LCollectColorBlueTransformsFunc
  65006 
  65007 var VP8LCollectColorRedTransforms VP8LCollectColorRedTransformsFunc
  65008 
  65009 var VP8LCollectColorRedTransforms_SSE VP8LCollectColorRedTransformsFunc
  65010 
  65011 var VP8LCombinedShannonEntropy VP8LCombinedShannonEntropyFunc
  65012 
  65013 var VP8LConvertBGRAToBGR VP8LConvertFunc
  65014 
  65015 var VP8LConvertBGRAToRGB VP8LConvertFunc
  65016 
  65017 var VP8LConvertBGRAToRGB565 VP8LConvertFunc
  65018 
  65019 var VP8LConvertBGRAToRGBA VP8LConvertFunc
  65020 
  65021 var VP8LConvertBGRAToRGBA4444 VP8LConvertFunc
  65022 
  65023 var VP8LConvertBGRAToRGBA_SSE VP8LConvertFunc
  65024 
  65025 var VP8LConvertBGRAToRGB_SSE VP8LConvertFunc
  65026 
  65027 var VP8LExtraCost VP8LCostFunc
  65028 
  65029 var VP8LFastLog2Slow VP8LFastLog2SlowFunc
  65030 
  65031 var VP8LFastSLog2Slow VP8LFastSLog2SlowFunc
  65032 
  65033 var VP8LGetCombinedEntropyUnrefined VP8LGetCombinedEntropyUnrefinedFunc
  65034 
  65035 var VP8LGetEntropyUnrefined VP8LGetEntropyUnrefinedFunc
  65036 
  65037 var VP8LMapColor32b VP8LMapARGBFunc
  65038 
  65039 var VP8LMapColor8b VP8LMapAlphaFunc
  65040 
  65041 var VP8LPredictors [16]VP8LPredictorFunc
  65042 
  65043 var VP8LPredictorsAdd [16]VP8LPredictorAddSubFunc
  65044 
  65045 // C documentation
  65046 //
  65047 //	// exposed plain-C implementations
  65048 var VP8LPredictorsAdd_C [16]VP8LPredictorAddSubFunc
  65049 
  65050 var VP8LPredictorsAdd_SSE [16]VP8LPredictorAddSubFunc
  65051 
  65052 var VP8LPredictorsSub [16]VP8LPredictorAddSubFunc
  65053 
  65054 var VP8LPredictorsSub_C [16]VP8LPredictorAddSubFunc
  65055 
  65056 var VP8LPredictorsSub_SSE [16]VP8LPredictorAddSubFunc
  65057 
  65058 var VP8LShannonEntropy VP8LShannonEntropyFunc
  65059 
  65060 //------------------------------------------------------------------------------
  65061 
  65062 var VP8LSubtractGreenFromBlueAndRed VP8LProcessEncBlueAndRedFunc
  65063 
  65064 var VP8LSubtractGreenFromBlueAndRed_SSE VP8LProcessEncBlueAndRedFunc
  65065 
  65066 var VP8LTransformColor VP8LTransformColorFunc
  65067 
  65068 var VP8LTransformColorInverse VP8LTransformColorInverseFunc
  65069 
  65070 var VP8LTransformColorInverse_SSE VP8LTransformColorInverseFunc
  65071 
  65072 var VP8LTransformColor_SSE VP8LTransformColorFunc
  65073 
  65074 var VP8LVectorMismatch VP8LVectorMismatchFunc
  65075 
  65076 //------------------------------------------------------------------------------
  65077 // Level cost tables
  65078 
  65079 // C documentation
  65080 //
  65081 //	// fixed costs for coding levels, deduce from the coding tree.
  65082 //	// This is only the part that doesn't depend on the probability state.
  65083 var VP8LevelFixedCosts = [2048]uint16_t{
  65084 	1:    uint16(256),
  65085 	2:    uint16(256),
  65086 	3:    uint16(256),
  65087 	4:    uint16(256),
  65088 	5:    uint16(432),
  65089 	6:    uint16(618),
  65090 	7:    uint16(630),
  65091 	8:    uint16(731),
  65092 	9:    uint16(640),
  65093 	10:   uint16(640),
  65094 	11:   uint16(828),
  65095 	12:   uint16(901),
  65096 	13:   uint16(948),
  65097 	14:   uint16(1021),
  65098 	15:   uint16(1101),
  65099 	16:   uint16(1174),
  65100 	17:   uint16(1221),
  65101 	18:   uint16(1294),
  65102 	19:   uint16(1042),
  65103 	20:   uint16(1085),
  65104 	21:   uint16(1115),
  65105 	22:   uint16(1158),
  65106 	23:   uint16(1202),
  65107 	24:   uint16(1245),
  65108 	25:   uint16(1275),
  65109 	26:   uint16(1318),
  65110 	27:   uint16(1337),
  65111 	28:   uint16(1380),
  65112 	29:   uint16(1410),
  65113 	30:   uint16(1453),
  65114 	31:   uint16(1497),
  65115 	32:   uint16(1540),
  65116 	33:   uint16(1570),
  65117 	34:   uint16(1613),
  65118 	35:   uint16(1280),
  65119 	36:   uint16(1295),
  65120 	37:   uint16(1317),
  65121 	38:   uint16(1332),
  65122 	39:   uint16(1358),
  65123 	40:   uint16(1373),
  65124 	41:   uint16(1395),
  65125 	42:   uint16(1410),
  65126 	43:   uint16(1454),
  65127 	44:   uint16(1469),
  65128 	45:   uint16(1491),
  65129 	46:   uint16(1506),
  65130 	47:   uint16(1532),
  65131 	48:   uint16(1547),
  65132 	49:   uint16(1569),
  65133 	50:   uint16(1584),
  65134 	51:   uint16(1601),
  65135 	52:   uint16(1616),
  65136 	53:   uint16(1638),
  65137 	54:   uint16(1653),
  65138 	55:   uint16(1679),
  65139 	56:   uint16(1694),
  65140 	57:   uint16(1716),
  65141 	58:   uint16(1731),
  65142 	59:   uint16(1775),
  65143 	60:   uint16(1790),
  65144 	61:   uint16(1812),
  65145 	62:   uint16(1827),
  65146 	63:   uint16(1853),
  65147 	64:   uint16(1868),
  65148 	65:   uint16(1890),
  65149 	66:   uint16(1905),
  65150 	67:   uint16(1727),
  65151 	68:   uint16(1733),
  65152 	69:   uint16(1742),
  65153 	70:   uint16(1748),
  65154 	71:   uint16(1759),
  65155 	72:   uint16(1765),
  65156 	73:   uint16(1774),
  65157 	74:   uint16(1780),
  65158 	75:   uint16(1800),
  65159 	76:   uint16(1806),
  65160 	77:   uint16(1815),
  65161 	78:   uint16(1821),
  65162 	79:   uint16(1832),
  65163 	80:   uint16(1838),
  65164 	81:   uint16(1847),
  65165 	82:   uint16(1853),
  65166 	83:   uint16(1878),
  65167 	84:   uint16(1884),
  65168 	85:   uint16(1893),
  65169 	86:   uint16(1899),
  65170 	87:   uint16(1910),
  65171 	88:   uint16(1916),
  65172 	89:   uint16(1925),
  65173 	90:   uint16(1931),
  65174 	91:   uint16(1951),
  65175 	92:   uint16(1957),
  65176 	93:   uint16(1966),
  65177 	94:   uint16(1972),
  65178 	95:   uint16(1983),
  65179 	96:   uint16(1989),
  65180 	97:   uint16(1998),
  65181 	98:   uint16(2004),
  65182 	99:   uint16(2027),
  65183 	100:  uint16(2033),
  65184 	101:  uint16(2042),
  65185 	102:  uint16(2048),
  65186 	103:  uint16(2059),
  65187 	104:  uint16(2065),
  65188 	105:  uint16(2074),
  65189 	106:  uint16(2080),
  65190 	107:  uint16(2100),
  65191 	108:  uint16(2106),
  65192 	109:  uint16(2115),
  65193 	110:  uint16(2121),
  65194 	111:  uint16(2132),
  65195 	112:  uint16(2138),
  65196 	113:  uint16(2147),
  65197 	114:  uint16(2153),
  65198 	115:  uint16(2178),
  65199 	116:  uint16(2184),
  65200 	117:  uint16(2193),
  65201 	118:  uint16(2199),
  65202 	119:  uint16(2210),
  65203 	120:  uint16(2216),
  65204 	121:  uint16(2225),
  65205 	122:  uint16(2231),
  65206 	123:  uint16(2251),
  65207 	124:  uint16(2257),
  65208 	125:  uint16(2266),
  65209 	126:  uint16(2272),
  65210 	127:  uint16(2283),
  65211 	128:  uint16(2289),
  65212 	129:  uint16(2298),
  65213 	130:  uint16(2304),
  65214 	131:  uint16(2168),
  65215 	132:  uint16(2174),
  65216 	133:  uint16(2183),
  65217 	134:  uint16(2189),
  65218 	135:  uint16(2200),
  65219 	136:  uint16(2206),
  65220 	137:  uint16(2215),
  65221 	138:  uint16(2221),
  65222 	139:  uint16(2241),
  65223 	140:  uint16(2247),
  65224 	141:  uint16(2256),
  65225 	142:  uint16(2262),
  65226 	143:  uint16(2273),
  65227 	144:  uint16(2279),
  65228 	145:  uint16(2288),
  65229 	146:  uint16(2294),
  65230 	147:  uint16(2319),
  65231 	148:  uint16(2325),
  65232 	149:  uint16(2334),
  65233 	150:  uint16(2340),
  65234 	151:  uint16(2351),
  65235 	152:  uint16(2357),
  65236 	153:  uint16(2366),
  65237 	154:  uint16(2372),
  65238 	155:  uint16(2392),
  65239 	156:  uint16(2398),
  65240 	157:  uint16(2407),
  65241 	158:  uint16(2413),
  65242 	159:  uint16(2424),
  65243 	160:  uint16(2430),
  65244 	161:  uint16(2439),
  65245 	162:  uint16(2445),
  65246 	163:  uint16(2468),
  65247 	164:  uint16(2474),
  65248 	165:  uint16(2483),
  65249 	166:  uint16(2489),
  65250 	167:  uint16(2500),
  65251 	168:  uint16(2506),
  65252 	169:  uint16(2515),
  65253 	170:  uint16(2521),
  65254 	171:  uint16(2541),
  65255 	172:  uint16(2547),
  65256 	173:  uint16(2556),
  65257 	174:  uint16(2562),
  65258 	175:  uint16(2573),
  65259 	176:  uint16(2579),
  65260 	177:  uint16(2588),
  65261 	178:  uint16(2594),
  65262 	179:  uint16(2619),
  65263 	180:  uint16(2625),
  65264 	181:  uint16(2634),
  65265 	182:  uint16(2640),
  65266 	183:  uint16(2651),
  65267 	184:  uint16(2657),
  65268 	185:  uint16(2666),
  65269 	186:  uint16(2672),
  65270 	187:  uint16(2692),
  65271 	188:  uint16(2698),
  65272 	189:  uint16(2707),
  65273 	190:  uint16(2713),
  65274 	191:  uint16(2724),
  65275 	192:  uint16(2730),
  65276 	193:  uint16(2739),
  65277 	194:  uint16(2745),
  65278 	195:  uint16(2540),
  65279 	196:  uint16(2546),
  65280 	197:  uint16(2555),
  65281 	198:  uint16(2561),
  65282 	199:  uint16(2572),
  65283 	200:  uint16(2578),
  65284 	201:  uint16(2587),
  65285 	202:  uint16(2593),
  65286 	203:  uint16(2613),
  65287 	204:  uint16(2619),
  65288 	205:  uint16(2628),
  65289 	206:  uint16(2634),
  65290 	207:  uint16(2645),
  65291 	208:  uint16(2651),
  65292 	209:  uint16(2660),
  65293 	210:  uint16(2666),
  65294 	211:  uint16(2691),
  65295 	212:  uint16(2697),
  65296 	213:  uint16(2706),
  65297 	214:  uint16(2712),
  65298 	215:  uint16(2723),
  65299 	216:  uint16(2729),
  65300 	217:  uint16(2738),
  65301 	218:  uint16(2744),
  65302 	219:  uint16(2764),
  65303 	220:  uint16(2770),
  65304 	221:  uint16(2779),
  65305 	222:  uint16(2785),
  65306 	223:  uint16(2796),
  65307 	224:  uint16(2802),
  65308 	225:  uint16(2811),
  65309 	226:  uint16(2817),
  65310 	227:  uint16(2840),
  65311 	228:  uint16(2846),
  65312 	229:  uint16(2855),
  65313 	230:  uint16(2861),
  65314 	231:  uint16(2872),
  65315 	232:  uint16(2878),
  65316 	233:  uint16(2887),
  65317 	234:  uint16(2893),
  65318 	235:  uint16(2913),
  65319 	236:  uint16(2919),
  65320 	237:  uint16(2928),
  65321 	238:  uint16(2934),
  65322 	239:  uint16(2945),
  65323 	240:  uint16(2951),
  65324 	241:  uint16(2960),
  65325 	242:  uint16(2966),
  65326 	243:  uint16(2991),
  65327 	244:  uint16(2997),
  65328 	245:  uint16(3006),
  65329 	246:  uint16(3012),
  65330 	247:  uint16(3023),
  65331 	248:  uint16(3029),
  65332 	249:  uint16(3038),
  65333 	250:  uint16(3044),
  65334 	251:  uint16(3064),
  65335 	252:  uint16(3070),
  65336 	253:  uint16(3079),
  65337 	254:  uint16(3085),
  65338 	255:  uint16(3096),
  65339 	256:  uint16(3102),
  65340 	257:  uint16(3111),
  65341 	258:  uint16(3117),
  65342 	259:  uint16(2981),
  65343 	260:  uint16(2987),
  65344 	261:  uint16(2996),
  65345 	262:  uint16(3002),
  65346 	263:  uint16(3013),
  65347 	264:  uint16(3019),
  65348 	265:  uint16(3028),
  65349 	266:  uint16(3034),
  65350 	267:  uint16(3054),
  65351 	268:  uint16(3060),
  65352 	269:  uint16(3069),
  65353 	270:  uint16(3075),
  65354 	271:  uint16(3086),
  65355 	272:  uint16(3092),
  65356 	273:  uint16(3101),
  65357 	274:  uint16(3107),
  65358 	275:  uint16(3132),
  65359 	276:  uint16(3138),
  65360 	277:  uint16(3147),
  65361 	278:  uint16(3153),
  65362 	279:  uint16(3164),
  65363 	280:  uint16(3170),
  65364 	281:  uint16(3179),
  65365 	282:  uint16(3185),
  65366 	283:  uint16(3205),
  65367 	284:  uint16(3211),
  65368 	285:  uint16(3220),
  65369 	286:  uint16(3226),
  65370 	287:  uint16(3237),
  65371 	288:  uint16(3243),
  65372 	289:  uint16(3252),
  65373 	290:  uint16(3258),
  65374 	291:  uint16(3281),
  65375 	292:  uint16(3287),
  65376 	293:  uint16(3296),
  65377 	294:  uint16(3302),
  65378 	295:  uint16(3313),
  65379 	296:  uint16(3319),
  65380 	297:  uint16(3328),
  65381 	298:  uint16(3334),
  65382 	299:  uint16(3354),
  65383 	300:  uint16(3360),
  65384 	301:  uint16(3369),
  65385 	302:  uint16(3375),
  65386 	303:  uint16(3386),
  65387 	304:  uint16(3392),
  65388 	305:  uint16(3401),
  65389 	306:  uint16(3407),
  65390 	307:  uint16(3432),
  65391 	308:  uint16(3438),
  65392 	309:  uint16(3447),
  65393 	310:  uint16(3453),
  65394 	311:  uint16(3464),
  65395 	312:  uint16(3470),
  65396 	313:  uint16(3479),
  65397 	314:  uint16(3485),
  65398 	315:  uint16(3505),
  65399 	316:  uint16(3511),
  65400 	317:  uint16(3520),
  65401 	318:  uint16(3526),
  65402 	319:  uint16(3537),
  65403 	320:  uint16(3543),
  65404 	321:  uint16(3552),
  65405 	322:  uint16(3558),
  65406 	323:  uint16(2816),
  65407 	324:  uint16(2822),
  65408 	325:  uint16(2831),
  65409 	326:  uint16(2837),
  65410 	327:  uint16(2848),
  65411 	328:  uint16(2854),
  65412 	329:  uint16(2863),
  65413 	330:  uint16(2869),
  65414 	331:  uint16(2889),
  65415 	332:  uint16(2895),
  65416 	333:  uint16(2904),
  65417 	334:  uint16(2910),
  65418 	335:  uint16(2921),
  65419 	336:  uint16(2927),
  65420 	337:  uint16(2936),
  65421 	338:  uint16(2942),
  65422 	339:  uint16(2967),
  65423 	340:  uint16(2973),
  65424 	341:  uint16(2982),
  65425 	342:  uint16(2988),
  65426 	343:  uint16(2999),
  65427 	344:  uint16(3005),
  65428 	345:  uint16(3014),
  65429 	346:  uint16(3020),
  65430 	347:  uint16(3040),
  65431 	348:  uint16(3046),
  65432 	349:  uint16(3055),
  65433 	350:  uint16(3061),
  65434 	351:  uint16(3072),
  65435 	352:  uint16(3078),
  65436 	353:  uint16(3087),
  65437 	354:  uint16(3093),
  65438 	355:  uint16(3116),
  65439 	356:  uint16(3122),
  65440 	357:  uint16(3131),
  65441 	358:  uint16(3137),
  65442 	359:  uint16(3148),
  65443 	360:  uint16(3154),
  65444 	361:  uint16(3163),
  65445 	362:  uint16(3169),
  65446 	363:  uint16(3189),
  65447 	364:  uint16(3195),
  65448 	365:  uint16(3204),
  65449 	366:  uint16(3210),
  65450 	367:  uint16(3221),
  65451 	368:  uint16(3227),
  65452 	369:  uint16(3236),
  65453 	370:  uint16(3242),
  65454 	371:  uint16(3267),
  65455 	372:  uint16(3273),
  65456 	373:  uint16(3282),
  65457 	374:  uint16(3288),
  65458 	375:  uint16(3299),
  65459 	376:  uint16(3305),
  65460 	377:  uint16(3314),
  65461 	378:  uint16(3320),
  65462 	379:  uint16(3340),
  65463 	380:  uint16(3346),
  65464 	381:  uint16(3355),
  65465 	382:  uint16(3361),
  65466 	383:  uint16(3372),
  65467 	384:  uint16(3378),
  65468 	385:  uint16(3387),
  65469 	386:  uint16(3393),
  65470 	387:  uint16(3257),
  65471 	388:  uint16(3263),
  65472 	389:  uint16(3272),
  65473 	390:  uint16(3278),
  65474 	391:  uint16(3289),
  65475 	392:  uint16(3295),
  65476 	393:  uint16(3304),
  65477 	394:  uint16(3310),
  65478 	395:  uint16(3330),
  65479 	396:  uint16(3336),
  65480 	397:  uint16(3345),
  65481 	398:  uint16(3351),
  65482 	399:  uint16(3362),
  65483 	400:  uint16(3368),
  65484 	401:  uint16(3377),
  65485 	402:  uint16(3383),
  65486 	403:  uint16(3408),
  65487 	404:  uint16(3414),
  65488 	405:  uint16(3423),
  65489 	406:  uint16(3429),
  65490 	407:  uint16(3440),
  65491 	408:  uint16(3446),
  65492 	409:  uint16(3455),
  65493 	410:  uint16(3461),
  65494 	411:  uint16(3481),
  65495 	412:  uint16(3487),
  65496 	413:  uint16(3496),
  65497 	414:  uint16(3502),
  65498 	415:  uint16(3513),
  65499 	416:  uint16(3519),
  65500 	417:  uint16(3528),
  65501 	418:  uint16(3534),
  65502 	419:  uint16(3557),
  65503 	420:  uint16(3563),
  65504 	421:  uint16(3572),
  65505 	422:  uint16(3578),
  65506 	423:  uint16(3589),
  65507 	424:  uint16(3595),
  65508 	425:  uint16(3604),
  65509 	426:  uint16(3610),
  65510 	427:  uint16(3630),
  65511 	428:  uint16(3636),
  65512 	429:  uint16(3645),
  65513 	430:  uint16(3651),
  65514 	431:  uint16(3662),
  65515 	432:  uint16(3668),
  65516 	433:  uint16(3677),
  65517 	434:  uint16(3683),
  65518 	435:  uint16(3708),
  65519 	436:  uint16(3714),
  65520 	437:  uint16(3723),
  65521 	438:  uint16(3729),
  65522 	439:  uint16(3740),
  65523 	440:  uint16(3746),
  65524 	441:  uint16(3755),
  65525 	442:  uint16(3761),
  65526 	443:  uint16(3781),
  65527 	444:  uint16(3787),
  65528 	445:  uint16(3796),
  65529 	446:  uint16(3802),
  65530 	447:  uint16(3813),
  65531 	448:  uint16(3819),
  65532 	449:  uint16(3828),
  65533 	450:  uint16(3834),
  65534 	451:  uint16(3629),
  65535 	452:  uint16(3635),
  65536 	453:  uint16(3644),
  65537 	454:  uint16(3650),
  65538 	455:  uint16(3661),
  65539 	456:  uint16(3667),
  65540 	457:  uint16(3676),
  65541 	458:  uint16(3682),
  65542 	459:  uint16(3702),
  65543 	460:  uint16(3708),
  65544 	461:  uint16(3717),
  65545 	462:  uint16(3723),
  65546 	463:  uint16(3734),
  65547 	464:  uint16(3740),
  65548 	465:  uint16(3749),
  65549 	466:  uint16(3755),
  65550 	467:  uint16(3780),
  65551 	468:  uint16(3786),
  65552 	469:  uint16(3795),
  65553 	470:  uint16(3801),
  65554 	471:  uint16(3812),
  65555 	472:  uint16(3818),
  65556 	473:  uint16(3827),
  65557 	474:  uint16(3833),
  65558 	475:  uint16(3853),
  65559 	476:  uint16(3859),
  65560 	477:  uint16(3868),
  65561 	478:  uint16(3874),
  65562 	479:  uint16(3885),
  65563 	480:  uint16(3891),
  65564 	481:  uint16(3900),
  65565 	482:  uint16(3906),
  65566 	483:  uint16(3929),
  65567 	484:  uint16(3935),
  65568 	485:  uint16(3944),
  65569 	486:  uint16(3950),
  65570 	487:  uint16(3961),
  65571 	488:  uint16(3967),
  65572 	489:  uint16(3976),
  65573 	490:  uint16(3982),
  65574 	491:  uint16(4002),
  65575 	492:  uint16(4008),
  65576 	493:  uint16(4017),
  65577 	494:  uint16(4023),
  65578 	495:  uint16(4034),
  65579 	496:  uint16(4040),
  65580 	497:  uint16(4049),
  65581 	498:  uint16(4055),
  65582 	499:  uint16(4080),
  65583 	500:  uint16(4086),
  65584 	501:  uint16(4095),
  65585 	502:  uint16(4101),
  65586 	503:  uint16(4112),
  65587 	504:  uint16(4118),
  65588 	505:  uint16(4127),
  65589 	506:  uint16(4133),
  65590 	507:  uint16(4153),
  65591 	508:  uint16(4159),
  65592 	509:  uint16(4168),
  65593 	510:  uint16(4174),
  65594 	511:  uint16(4185),
  65595 	512:  uint16(4191),
  65596 	513:  uint16(4200),
  65597 	514:  uint16(4206),
  65598 	515:  uint16(4070),
  65599 	516:  uint16(4076),
  65600 	517:  uint16(4085),
  65601 	518:  uint16(4091),
  65602 	519:  uint16(4102),
  65603 	520:  uint16(4108),
  65604 	521:  uint16(4117),
  65605 	522:  uint16(4123),
  65606 	523:  uint16(4143),
  65607 	524:  uint16(4149),
  65608 	525:  uint16(4158),
  65609 	526:  uint16(4164),
  65610 	527:  uint16(4175),
  65611 	528:  uint16(4181),
  65612 	529:  uint16(4190),
  65613 	530:  uint16(4196),
  65614 	531:  uint16(4221),
  65615 	532:  uint16(4227),
  65616 	533:  uint16(4236),
  65617 	534:  uint16(4242),
  65618 	535:  uint16(4253),
  65619 	536:  uint16(4259),
  65620 	537:  uint16(4268),
  65621 	538:  uint16(4274),
  65622 	539:  uint16(4294),
  65623 	540:  uint16(4300),
  65624 	541:  uint16(4309),
  65625 	542:  uint16(4315),
  65626 	543:  uint16(4326),
  65627 	544:  uint16(4332),
  65628 	545:  uint16(4341),
  65629 	546:  uint16(4347),
  65630 	547:  uint16(4370),
  65631 	548:  uint16(4376),
  65632 	549:  uint16(4385),
  65633 	550:  uint16(4391),
  65634 	551:  uint16(4402),
  65635 	552:  uint16(4408),
  65636 	553:  uint16(4417),
  65637 	554:  uint16(4423),
  65638 	555:  uint16(4443),
  65639 	556:  uint16(4449),
  65640 	557:  uint16(4458),
  65641 	558:  uint16(4464),
  65642 	559:  uint16(4475),
  65643 	560:  uint16(4481),
  65644 	561:  uint16(4490),
  65645 	562:  uint16(4496),
  65646 	563:  uint16(4521),
  65647 	564:  uint16(4527),
  65648 	565:  uint16(4536),
  65649 	566:  uint16(4542),
  65650 	567:  uint16(4553),
  65651 	568:  uint16(4559),
  65652 	569:  uint16(4568),
  65653 	570:  uint16(4574),
  65654 	571:  uint16(4594),
  65655 	572:  uint16(4600),
  65656 	573:  uint16(4609),
  65657 	574:  uint16(4615),
  65658 	575:  uint16(4626),
  65659 	576:  uint16(4632),
  65660 	577:  uint16(4641),
  65661 	578:  uint16(4647),
  65662 	579:  uint16(3515),
  65663 	580:  uint16(3521),
  65664 	581:  uint16(3530),
  65665 	582:  uint16(3536),
  65666 	583:  uint16(3547),
  65667 	584:  uint16(3553),
  65668 	585:  uint16(3562),
  65669 	586:  uint16(3568),
  65670 	587:  uint16(3588),
  65671 	588:  uint16(3594),
  65672 	589:  uint16(3603),
  65673 	590:  uint16(3609),
  65674 	591:  uint16(3620),
  65675 	592:  uint16(3626),
  65676 	593:  uint16(3635),
  65677 	594:  uint16(3641),
  65678 	595:  uint16(3666),
  65679 	596:  uint16(3672),
  65680 	597:  uint16(3681),
  65681 	598:  uint16(3687),
  65682 	599:  uint16(3698),
  65683 	600:  uint16(3704),
  65684 	601:  uint16(3713),
  65685 	602:  uint16(3719),
  65686 	603:  uint16(3739),
  65687 	604:  uint16(3745),
  65688 	605:  uint16(3754),
  65689 	606:  uint16(3760),
  65690 	607:  uint16(3771),
  65691 	608:  uint16(3777),
  65692 	609:  uint16(3786),
  65693 	610:  uint16(3792),
  65694 	611:  uint16(3815),
  65695 	612:  uint16(3821),
  65696 	613:  uint16(3830),
  65697 	614:  uint16(3836),
  65698 	615:  uint16(3847),
  65699 	616:  uint16(3853),
  65700 	617:  uint16(3862),
  65701 	618:  uint16(3868),
  65702 	619:  uint16(3888),
  65703 	620:  uint16(3894),
  65704 	621:  uint16(3903),
  65705 	622:  uint16(3909),
  65706 	623:  uint16(3920),
  65707 	624:  uint16(3926),
  65708 	625:  uint16(3935),
  65709 	626:  uint16(3941),
  65710 	627:  uint16(3966),
  65711 	628:  uint16(3972),
  65712 	629:  uint16(3981),
  65713 	630:  uint16(3987),
  65714 	631:  uint16(3998),
  65715 	632:  uint16(4004),
  65716 	633:  uint16(4013),
  65717 	634:  uint16(4019),
  65718 	635:  uint16(4039),
  65719 	636:  uint16(4045),
  65720 	637:  uint16(4054),
  65721 	638:  uint16(4060),
  65722 	639:  uint16(4071),
  65723 	640:  uint16(4077),
  65724 	641:  uint16(4086),
  65725 	642:  uint16(4092),
  65726 	643:  uint16(3956),
  65727 	644:  uint16(3962),
  65728 	645:  uint16(3971),
  65729 	646:  uint16(3977),
  65730 	647:  uint16(3988),
  65731 	648:  uint16(3994),
  65732 	649:  uint16(4003),
  65733 	650:  uint16(4009),
  65734 	651:  uint16(4029),
  65735 	652:  uint16(4035),
  65736 	653:  uint16(4044),
  65737 	654:  uint16(4050),
  65738 	655:  uint16(4061),
  65739 	656:  uint16(4067),
  65740 	657:  uint16(4076),
  65741 	658:  uint16(4082),
  65742 	659:  uint16(4107),
  65743 	660:  uint16(4113),
  65744 	661:  uint16(4122),
  65745 	662:  uint16(4128),
  65746 	663:  uint16(4139),
  65747 	664:  uint16(4145),
  65748 	665:  uint16(4154),
  65749 	666:  uint16(4160),
  65750 	667:  uint16(4180),
  65751 	668:  uint16(4186),
  65752 	669:  uint16(4195),
  65753 	670:  uint16(4201),
  65754 	671:  uint16(4212),
  65755 	672:  uint16(4218),
  65756 	673:  uint16(4227),
  65757 	674:  uint16(4233),
  65758 	675:  uint16(4256),
  65759 	676:  uint16(4262),
  65760 	677:  uint16(4271),
  65761 	678:  uint16(4277),
  65762 	679:  uint16(4288),
  65763 	680:  uint16(4294),
  65764 	681:  uint16(4303),
  65765 	682:  uint16(4309),
  65766 	683:  uint16(4329),
  65767 	684:  uint16(4335),
  65768 	685:  uint16(4344),
  65769 	686:  uint16(4350),
  65770 	687:  uint16(4361),
  65771 	688:  uint16(4367),
  65772 	689:  uint16(4376),
  65773 	690:  uint16(4382),
  65774 	691:  uint16(4407),
  65775 	692:  uint16(4413),
  65776 	693:  uint16(4422),
  65777 	694:  uint16(4428),
  65778 	695:  uint16(4439),
  65779 	696:  uint16(4445),
  65780 	697:  uint16(4454),
  65781 	698:  uint16(4460),
  65782 	699:  uint16(4480),
  65783 	700:  uint16(4486),
  65784 	701:  uint16(4495),
  65785 	702:  uint16(4501),
  65786 	703:  uint16(4512),
  65787 	704:  uint16(4518),
  65788 	705:  uint16(4527),
  65789 	706:  uint16(4533),
  65790 	707:  uint16(4328),
  65791 	708:  uint16(4334),
  65792 	709:  uint16(4343),
  65793 	710:  uint16(4349),
  65794 	711:  uint16(4360),
  65795 	712:  uint16(4366),
  65796 	713:  uint16(4375),
  65797 	714:  uint16(4381),
  65798 	715:  uint16(4401),
  65799 	716:  uint16(4407),
  65800 	717:  uint16(4416),
  65801 	718:  uint16(4422),
  65802 	719:  uint16(4433),
  65803 	720:  uint16(4439),
  65804 	721:  uint16(4448),
  65805 	722:  uint16(4454),
  65806 	723:  uint16(4479),
  65807 	724:  uint16(4485),
  65808 	725:  uint16(4494),
  65809 	726:  uint16(4500),
  65810 	727:  uint16(4511),
  65811 	728:  uint16(4517),
  65812 	729:  uint16(4526),
  65813 	730:  uint16(4532),
  65814 	731:  uint16(4552),
  65815 	732:  uint16(4558),
  65816 	733:  uint16(4567),
  65817 	734:  uint16(4573),
  65818 	735:  uint16(4584),
  65819 	736:  uint16(4590),
  65820 	737:  uint16(4599),
  65821 	738:  uint16(4605),
  65822 	739:  uint16(4628),
  65823 	740:  uint16(4634),
  65824 	741:  uint16(4643),
  65825 	742:  uint16(4649),
  65826 	743:  uint16(4660),
  65827 	744:  uint16(4666),
  65828 	745:  uint16(4675),
  65829 	746:  uint16(4681),
  65830 	747:  uint16(4701),
  65831 	748:  uint16(4707),
  65832 	749:  uint16(4716),
  65833 	750:  uint16(4722),
  65834 	751:  uint16(4733),
  65835 	752:  uint16(4739),
  65836 	753:  uint16(4748),
  65837 	754:  uint16(4754),
  65838 	755:  uint16(4779),
  65839 	756:  uint16(4785),
  65840 	757:  uint16(4794),
  65841 	758:  uint16(4800),
  65842 	759:  uint16(4811),
  65843 	760:  uint16(4817),
  65844 	761:  uint16(4826),
  65845 	762:  uint16(4832),
  65846 	763:  uint16(4852),
  65847 	764:  uint16(4858),
  65848 	765:  uint16(4867),
  65849 	766:  uint16(4873),
  65850 	767:  uint16(4884),
  65851 	768:  uint16(4890),
  65852 	769:  uint16(4899),
  65853 	770:  uint16(4905),
  65854 	771:  uint16(4769),
  65855 	772:  uint16(4775),
  65856 	773:  uint16(4784),
  65857 	774:  uint16(4790),
  65858 	775:  uint16(4801),
  65859 	776:  uint16(4807),
  65860 	777:  uint16(4816),
  65861 	778:  uint16(4822),
  65862 	779:  uint16(4842),
  65863 	780:  uint16(4848),
  65864 	781:  uint16(4857),
  65865 	782:  uint16(4863),
  65866 	783:  uint16(4874),
  65867 	784:  uint16(4880),
  65868 	785:  uint16(4889),
  65869 	786:  uint16(4895),
  65870 	787:  uint16(4920),
  65871 	788:  uint16(4926),
  65872 	789:  uint16(4935),
  65873 	790:  uint16(4941),
  65874 	791:  uint16(4952),
  65875 	792:  uint16(4958),
  65876 	793:  uint16(4967),
  65877 	794:  uint16(4973),
  65878 	795:  uint16(4993),
  65879 	796:  uint16(4999),
  65880 	797:  uint16(5008),
  65881 	798:  uint16(5014),
  65882 	799:  uint16(5025),
  65883 	800:  uint16(5031),
  65884 	801:  uint16(5040),
  65885 	802:  uint16(5046),
  65886 	803:  uint16(5069),
  65887 	804:  uint16(5075),
  65888 	805:  uint16(5084),
  65889 	806:  uint16(5090),
  65890 	807:  uint16(5101),
  65891 	808:  uint16(5107),
  65892 	809:  uint16(5116),
  65893 	810:  uint16(5122),
  65894 	811:  uint16(5142),
  65895 	812:  uint16(5148),
  65896 	813:  uint16(5157),
  65897 	814:  uint16(5163),
  65898 	815:  uint16(5174),
  65899 	816:  uint16(5180),
  65900 	817:  uint16(5189),
  65901 	818:  uint16(5195),
  65902 	819:  uint16(5220),
  65903 	820:  uint16(5226),
  65904 	821:  uint16(5235),
  65905 	822:  uint16(5241),
  65906 	823:  uint16(5252),
  65907 	824:  uint16(5258),
  65908 	825:  uint16(5267),
  65909 	826:  uint16(5273),
  65910 	827:  uint16(5293),
  65911 	828:  uint16(5299),
  65912 	829:  uint16(5308),
  65913 	830:  uint16(5314),
  65914 	831:  uint16(5325),
  65915 	832:  uint16(5331),
  65916 	833:  uint16(5340),
  65917 	834:  uint16(5346),
  65918 	835:  uint16(4604),
  65919 	836:  uint16(4610),
  65920 	837:  uint16(4619),
  65921 	838:  uint16(4625),
  65922 	839:  uint16(4636),
  65923 	840:  uint16(4642),
  65924 	841:  uint16(4651),
  65925 	842:  uint16(4657),
  65926 	843:  uint16(4677),
  65927 	844:  uint16(4683),
  65928 	845:  uint16(4692),
  65929 	846:  uint16(4698),
  65930 	847:  uint16(4709),
  65931 	848:  uint16(4715),
  65932 	849:  uint16(4724),
  65933 	850:  uint16(4730),
  65934 	851:  uint16(4755),
  65935 	852:  uint16(4761),
  65936 	853:  uint16(4770),
  65937 	854:  uint16(4776),
  65938 	855:  uint16(4787),
  65939 	856:  uint16(4793),
  65940 	857:  uint16(4802),
  65941 	858:  uint16(4808),
  65942 	859:  uint16(4828),
  65943 	860:  uint16(4834),
  65944 	861:  uint16(4843),
  65945 	862:  uint16(4849),
  65946 	863:  uint16(4860),
  65947 	864:  uint16(4866),
  65948 	865:  uint16(4875),
  65949 	866:  uint16(4881),
  65950 	867:  uint16(4904),
  65951 	868:  uint16(4910),
  65952 	869:  uint16(4919),
  65953 	870:  uint16(4925),
  65954 	871:  uint16(4936),
  65955 	872:  uint16(4942),
  65956 	873:  uint16(4951),
  65957 	874:  uint16(4957),
  65958 	875:  uint16(4977),
  65959 	876:  uint16(4983),
  65960 	877:  uint16(4992),
  65961 	878:  uint16(4998),
  65962 	879:  uint16(5009),
  65963 	880:  uint16(5015),
  65964 	881:  uint16(5024),
  65965 	882:  uint16(5030),
  65966 	883:  uint16(5055),
  65967 	884:  uint16(5061),
  65968 	885:  uint16(5070),
  65969 	886:  uint16(5076),
  65970 	887:  uint16(5087),
  65971 	888:  uint16(5093),
  65972 	889:  uint16(5102),
  65973 	890:  uint16(5108),
  65974 	891:  uint16(5128),
  65975 	892:  uint16(5134),
  65976 	893:  uint16(5143),
  65977 	894:  uint16(5149),
  65978 	895:  uint16(5160),
  65979 	896:  uint16(5166),
  65980 	897:  uint16(5175),
  65981 	898:  uint16(5181),
  65982 	899:  uint16(5045),
  65983 	900:  uint16(5051),
  65984 	901:  uint16(5060),
  65985 	902:  uint16(5066),
  65986 	903:  uint16(5077),
  65987 	904:  uint16(5083),
  65988 	905:  uint16(5092),
  65989 	906:  uint16(5098),
  65990 	907:  uint16(5118),
  65991 	908:  uint16(5124),
  65992 	909:  uint16(5133),
  65993 	910:  uint16(5139),
  65994 	911:  uint16(5150),
  65995 	912:  uint16(5156),
  65996 	913:  uint16(5165),
  65997 	914:  uint16(5171),
  65998 	915:  uint16(5196),
  65999 	916:  uint16(5202),
  66000 	917:  uint16(5211),
  66001 	918:  uint16(5217),
  66002 	919:  uint16(5228),
  66003 	920:  uint16(5234),
  66004 	921:  uint16(5243),
  66005 	922:  uint16(5249),
  66006 	923:  uint16(5269),
  66007 	924:  uint16(5275),
  66008 	925:  uint16(5284),
  66009 	926:  uint16(5290),
  66010 	927:  uint16(5301),
  66011 	928:  uint16(5307),
  66012 	929:  uint16(5316),
  66013 	930:  uint16(5322),
  66014 	931:  uint16(5345),
  66015 	932:  uint16(5351),
  66016 	933:  uint16(5360),
  66017 	934:  uint16(5366),
  66018 	935:  uint16(5377),
  66019 	936:  uint16(5383),
  66020 	937:  uint16(5392),
  66021 	938:  uint16(5398),
  66022 	939:  uint16(5418),
  66023 	940:  uint16(5424),
  66024 	941:  uint16(5433),
  66025 	942:  uint16(5439),
  66026 	943:  uint16(5450),
  66027 	944:  uint16(5456),
  66028 	945:  uint16(5465),
  66029 	946:  uint16(5471),
  66030 	947:  uint16(5496),
  66031 	948:  uint16(5502),
  66032 	949:  uint16(5511),
  66033 	950:  uint16(5517),
  66034 	951:  uint16(5528),
  66035 	952:  uint16(5534),
  66036 	953:  uint16(5543),
  66037 	954:  uint16(5549),
  66038 	955:  uint16(5569),
  66039 	956:  uint16(5575),
  66040 	957:  uint16(5584),
  66041 	958:  uint16(5590),
  66042 	959:  uint16(5601),
  66043 	960:  uint16(5607),
  66044 	961:  uint16(5616),
  66045 	962:  uint16(5622),
  66046 	963:  uint16(5417),
  66047 	964:  uint16(5423),
  66048 	965:  uint16(5432),
  66049 	966:  uint16(5438),
  66050 	967:  uint16(5449),
  66051 	968:  uint16(5455),
  66052 	969:  uint16(5464),
  66053 	970:  uint16(5470),
  66054 	971:  uint16(5490),
  66055 	972:  uint16(5496),
  66056 	973:  uint16(5505),
  66057 	974:  uint16(5511),
  66058 	975:  uint16(5522),
  66059 	976:  uint16(5528),
  66060 	977:  uint16(5537),
  66061 	978:  uint16(5543),
  66062 	979:  uint16(5568),
  66063 	980:  uint16(5574),
  66064 	981:  uint16(5583),
  66065 	982:  uint16(5589),
  66066 	983:  uint16(5600),
  66067 	984:  uint16(5606),
  66068 	985:  uint16(5615),
  66069 	986:  uint16(5621),
  66070 	987:  uint16(5641),
  66071 	988:  uint16(5647),
  66072 	989:  uint16(5656),
  66073 	990:  uint16(5662),
  66074 	991:  uint16(5673),
  66075 	992:  uint16(5679),
  66076 	993:  uint16(5688),
  66077 	994:  uint16(5694),
  66078 	995:  uint16(5717),
  66079 	996:  uint16(5723),
  66080 	997:  uint16(5732),
  66081 	998:  uint16(5738),
  66082 	999:  uint16(5749),
  66083 	1000: uint16(5755),
  66084 	1001: uint16(5764),
  66085 	1002: uint16(5770),
  66086 	1003: uint16(5790),
  66087 	1004: uint16(5796),
  66088 	1005: uint16(5805),
  66089 	1006: uint16(5811),
  66090 	1007: uint16(5822),
  66091 	1008: uint16(5828),
  66092 	1009: uint16(5837),
  66093 	1010: uint16(5843),
  66094 	1011: uint16(5868),
  66095 	1012: uint16(5874),
  66096 	1013: uint16(5883),
  66097 	1014: uint16(5889),
  66098 	1015: uint16(5900),
  66099 	1016: uint16(5906),
  66100 	1017: uint16(5915),
  66101 	1018: uint16(5921),
  66102 	1019: uint16(5941),
  66103 	1020: uint16(5947),
  66104 	1021: uint16(5956),
  66105 	1022: uint16(5962),
  66106 	1023: uint16(5973),
  66107 	1024: uint16(5979),
  66108 	1025: uint16(5988),
  66109 	1026: uint16(5994),
  66110 	1027: uint16(5858),
  66111 	1028: uint16(5864),
  66112 	1029: uint16(5873),
  66113 	1030: uint16(5879),
  66114 	1031: uint16(5890),
  66115 	1032: uint16(5896),
  66116 	1033: uint16(5905),
  66117 	1034: uint16(5911),
  66118 	1035: uint16(5931),
  66119 	1036: uint16(5937),
  66120 	1037: uint16(5946),
  66121 	1038: uint16(5952),
  66122 	1039: uint16(5963),
  66123 	1040: uint16(5969),
  66124 	1041: uint16(5978),
  66125 	1042: uint16(5984),
  66126 	1043: uint16(6009),
  66127 	1044: uint16(6015),
  66128 	1045: uint16(6024),
  66129 	1046: uint16(6030),
  66130 	1047: uint16(6041),
  66131 	1048: uint16(6047),
  66132 	1049: uint16(6056),
  66133 	1050: uint16(6062),
  66134 	1051: uint16(6082),
  66135 	1052: uint16(6088),
  66136 	1053: uint16(6097),
  66137 	1054: uint16(6103),
  66138 	1055: uint16(6114),
  66139 	1056: uint16(6120),
  66140 	1057: uint16(6129),
  66141 	1058: uint16(6135),
  66142 	1059: uint16(6158),
  66143 	1060: uint16(6164),
  66144 	1061: uint16(6173),
  66145 	1062: uint16(6179),
  66146 	1063: uint16(6190),
  66147 	1064: uint16(6196),
  66148 	1065: uint16(6205),
  66149 	1066: uint16(6211),
  66150 	1067: uint16(6231),
  66151 	1068: uint16(6237),
  66152 	1069: uint16(6246),
  66153 	1070: uint16(6252),
  66154 	1071: uint16(6263),
  66155 	1072: uint16(6269),
  66156 	1073: uint16(6278),
  66157 	1074: uint16(6284),
  66158 	1075: uint16(6309),
  66159 	1076: uint16(6315),
  66160 	1077: uint16(6324),
  66161 	1078: uint16(6330),
  66162 	1079: uint16(6341),
  66163 	1080: uint16(6347),
  66164 	1081: uint16(6356),
  66165 	1082: uint16(6362),
  66166 	1083: uint16(6382),
  66167 	1084: uint16(6388),
  66168 	1085: uint16(6397),
  66169 	1086: uint16(6403),
  66170 	1087: uint16(6414),
  66171 	1088: uint16(6420),
  66172 	1089: uint16(6429),
  66173 	1090: uint16(6435),
  66174 	1091: uint16(3515),
  66175 	1092: uint16(3521),
  66176 	1093: uint16(3530),
  66177 	1094: uint16(3536),
  66178 	1095: uint16(3547),
  66179 	1096: uint16(3553),
  66180 	1097: uint16(3562),
  66181 	1098: uint16(3568),
  66182 	1099: uint16(3588),
  66183 	1100: uint16(3594),
  66184 	1101: uint16(3603),
  66185 	1102: uint16(3609),
  66186 	1103: uint16(3620),
  66187 	1104: uint16(3626),
  66188 	1105: uint16(3635),
  66189 	1106: uint16(3641),
  66190 	1107: uint16(3666),
  66191 	1108: uint16(3672),
  66192 	1109: uint16(3681),
  66193 	1110: uint16(3687),
  66194 	1111: uint16(3698),
  66195 	1112: uint16(3704),
  66196 	1113: uint16(3713),
  66197 	1114: uint16(3719),
  66198 	1115: uint16(3739),
  66199 	1116: uint16(3745),
  66200 	1117: uint16(3754),
  66201 	1118: uint16(3760),
  66202 	1119: uint16(3771),
  66203 	1120: uint16(3777),
  66204 	1121: uint16(3786),
  66205 	1122: uint16(3792),
  66206 	1123: uint16(3815),
  66207 	1124: uint16(3821),
  66208 	1125: uint16(3830),
  66209 	1126: uint16(3836),
  66210 	1127: uint16(3847),
  66211 	1128: uint16(3853),
  66212 	1129: uint16(3862),
  66213 	1130: uint16(3868),
  66214 	1131: uint16(3888),
  66215 	1132: uint16(3894),
  66216 	1133: uint16(3903),
  66217 	1134: uint16(3909),
  66218 	1135: uint16(3920),
  66219 	1136: uint16(3926),
  66220 	1137: uint16(3935),
  66221 	1138: uint16(3941),
  66222 	1139: uint16(3966),
  66223 	1140: uint16(3972),
  66224 	1141: uint16(3981),
  66225 	1142: uint16(3987),
  66226 	1143: uint16(3998),
  66227 	1144: uint16(4004),
  66228 	1145: uint16(4013),
  66229 	1146: uint16(4019),
  66230 	1147: uint16(4039),
  66231 	1148: uint16(4045),
  66232 	1149: uint16(4054),
  66233 	1150: uint16(4060),
  66234 	1151: uint16(4071),
  66235 	1152: uint16(4077),
  66236 	1153: uint16(4086),
  66237 	1154: uint16(4092),
  66238 	1155: uint16(3956),
  66239 	1156: uint16(3962),
  66240 	1157: uint16(3971),
  66241 	1158: uint16(3977),
  66242 	1159: uint16(3988),
  66243 	1160: uint16(3994),
  66244 	1161: uint16(4003),
  66245 	1162: uint16(4009),
  66246 	1163: uint16(4029),
  66247 	1164: uint16(4035),
  66248 	1165: uint16(4044),
  66249 	1166: uint16(4050),
  66250 	1167: uint16(4061),
  66251 	1168: uint16(4067),
  66252 	1169: uint16(4076),
  66253 	1170: uint16(4082),
  66254 	1171: uint16(4107),
  66255 	1172: uint16(4113),
  66256 	1173: uint16(4122),
  66257 	1174: uint16(4128),
  66258 	1175: uint16(4139),
  66259 	1176: uint16(4145),
  66260 	1177: uint16(4154),
  66261 	1178: uint16(4160),
  66262 	1179: uint16(4180),
  66263 	1180: uint16(4186),
  66264 	1181: uint16(4195),
  66265 	1182: uint16(4201),
  66266 	1183: uint16(4212),
  66267 	1184: uint16(4218),
  66268 	1185: uint16(4227),
  66269 	1186: uint16(4233),
  66270 	1187: uint16(4256),
  66271 	1188: uint16(4262),
  66272 	1189: uint16(4271),
  66273 	1190: uint16(4277),
  66274 	1191: uint16(4288),
  66275 	1192: uint16(4294),
  66276 	1193: uint16(4303),
  66277 	1194: uint16(4309),
  66278 	1195: uint16(4329),
  66279 	1196: uint16(4335),
  66280 	1197: uint16(4344),
  66281 	1198: uint16(4350),
  66282 	1199: uint16(4361),
  66283 	1200: uint16(4367),
  66284 	1201: uint16(4376),
  66285 	1202: uint16(4382),
  66286 	1203: uint16(4407),
  66287 	1204: uint16(4413),
  66288 	1205: uint16(4422),
  66289 	1206: uint16(4428),
  66290 	1207: uint16(4439),
  66291 	1208: uint16(4445),
  66292 	1209: uint16(4454),
  66293 	1210: uint16(4460),
  66294 	1211: uint16(4480),
  66295 	1212: uint16(4486),
  66296 	1213: uint16(4495),
  66297 	1214: uint16(4501),
  66298 	1215: uint16(4512),
  66299 	1216: uint16(4518),
  66300 	1217: uint16(4527),
  66301 	1218: uint16(4533),
  66302 	1219: uint16(4328),
  66303 	1220: uint16(4334),
  66304 	1221: uint16(4343),
  66305 	1222: uint16(4349),
  66306 	1223: uint16(4360),
  66307 	1224: uint16(4366),
  66308 	1225: uint16(4375),
  66309 	1226: uint16(4381),
  66310 	1227: uint16(4401),
  66311 	1228: uint16(4407),
  66312 	1229: uint16(4416),
  66313 	1230: uint16(4422),
  66314 	1231: uint16(4433),
  66315 	1232: uint16(4439),
  66316 	1233: uint16(4448),
  66317 	1234: uint16(4454),
  66318 	1235: uint16(4479),
  66319 	1236: uint16(4485),
  66320 	1237: uint16(4494),
  66321 	1238: uint16(4500),
  66322 	1239: uint16(4511),
  66323 	1240: uint16(4517),
  66324 	1241: uint16(4526),
  66325 	1242: uint16(4532),
  66326 	1243: uint16(4552),
  66327 	1244: uint16(4558),
  66328 	1245: uint16(4567),
  66329 	1246: uint16(4573),
  66330 	1247: uint16(4584),
  66331 	1248: uint16(4590),
  66332 	1249: uint16(4599),
  66333 	1250: uint16(4605),
  66334 	1251: uint16(4628),
  66335 	1252: uint16(4634),
  66336 	1253: uint16(4643),
  66337 	1254: uint16(4649),
  66338 	1255: uint16(4660),
  66339 	1256: uint16(4666),
  66340 	1257: uint16(4675),
  66341 	1258: uint16(4681),
  66342 	1259: uint16(4701),
  66343 	1260: uint16(4707),
  66344 	1261: uint16(4716),
  66345 	1262: uint16(4722),
  66346 	1263: uint16(4733),
  66347 	1264: uint16(4739),
  66348 	1265: uint16(4748),
  66349 	1266: uint16(4754),
  66350 	1267: uint16(4779),
  66351 	1268: uint16(4785),
  66352 	1269: uint16(4794),
  66353 	1270: uint16(4800),
  66354 	1271: uint16(4811),
  66355 	1272: uint16(4817),
  66356 	1273: uint16(4826),
  66357 	1274: uint16(4832),
  66358 	1275: uint16(4852),
  66359 	1276: uint16(4858),
  66360 	1277: uint16(4867),
  66361 	1278: uint16(4873),
  66362 	1279: uint16(4884),
  66363 	1280: uint16(4890),
  66364 	1281: uint16(4899),
  66365 	1282: uint16(4905),
  66366 	1283: uint16(4769),
  66367 	1284: uint16(4775),
  66368 	1285: uint16(4784),
  66369 	1286: uint16(4790),
  66370 	1287: uint16(4801),
  66371 	1288: uint16(4807),
  66372 	1289: uint16(4816),
  66373 	1290: uint16(4822),
  66374 	1291: uint16(4842),
  66375 	1292: uint16(4848),
  66376 	1293: uint16(4857),
  66377 	1294: uint16(4863),
  66378 	1295: uint16(4874),
  66379 	1296: uint16(4880),
  66380 	1297: uint16(4889),
  66381 	1298: uint16(4895),
  66382 	1299: uint16(4920),
  66383 	1300: uint16(4926),
  66384 	1301: uint16(4935),
  66385 	1302: uint16(4941),
  66386 	1303: uint16(4952),
  66387 	1304: uint16(4958),
  66388 	1305: uint16(4967),
  66389 	1306: uint16(4973),
  66390 	1307: uint16(4993),
  66391 	1308: uint16(4999),
  66392 	1309: uint16(5008),
  66393 	1310: uint16(5014),
  66394 	1311: uint16(5025),
  66395 	1312: uint16(5031),
  66396 	1313: uint16(5040),
  66397 	1314: uint16(5046),
  66398 	1315: uint16(5069),
  66399 	1316: uint16(5075),
  66400 	1317: uint16(5084),
  66401 	1318: uint16(5090),
  66402 	1319: uint16(5101),
  66403 	1320: uint16(5107),
  66404 	1321: uint16(5116),
  66405 	1322: uint16(5122),
  66406 	1323: uint16(5142),
  66407 	1324: uint16(5148),
  66408 	1325: uint16(5157),
  66409 	1326: uint16(5163),
  66410 	1327: uint16(5174),
  66411 	1328: uint16(5180),
  66412 	1329: uint16(5189),
  66413 	1330: uint16(5195),
  66414 	1331: uint16(5220),
  66415 	1332: uint16(5226),
  66416 	1333: uint16(5235),
  66417 	1334: uint16(5241),
  66418 	1335: uint16(5252),
  66419 	1336: uint16(5258),
  66420 	1337: uint16(5267),
  66421 	1338: uint16(5273),
  66422 	1339: uint16(5293),
  66423 	1340: uint16(5299),
  66424 	1341: uint16(5308),
  66425 	1342: uint16(5314),
  66426 	1343: uint16(5325),
  66427 	1344: uint16(5331),
  66428 	1345: uint16(5340),
  66429 	1346: uint16(5346),
  66430 	1347: uint16(4604),
  66431 	1348: uint16(4610),
  66432 	1349: uint16(4619),
  66433 	1350: uint16(4625),
  66434 	1351: uint16(4636),
  66435 	1352: uint16(4642),
  66436 	1353: uint16(4651),
  66437 	1354: uint16(4657),
  66438 	1355: uint16(4677),
  66439 	1356: uint16(4683),
  66440 	1357: uint16(4692),
  66441 	1358: uint16(4698),
  66442 	1359: uint16(4709),
  66443 	1360: uint16(4715),
  66444 	1361: uint16(4724),
  66445 	1362: uint16(4730),
  66446 	1363: uint16(4755),
  66447 	1364: uint16(4761),
  66448 	1365: uint16(4770),
  66449 	1366: uint16(4776),
  66450 	1367: uint16(4787),
  66451 	1368: uint16(4793),
  66452 	1369: uint16(4802),
  66453 	1370: uint16(4808),
  66454 	1371: uint16(4828),
  66455 	1372: uint16(4834),
  66456 	1373: uint16(4843),
  66457 	1374: uint16(4849),
  66458 	1375: uint16(4860),
  66459 	1376: uint16(4866),
  66460 	1377: uint16(4875),
  66461 	1378: uint16(4881),
  66462 	1379: uint16(4904),
  66463 	1380: uint16(4910),
  66464 	1381: uint16(4919),
  66465 	1382: uint16(4925),
  66466 	1383: uint16(4936),
  66467 	1384: uint16(4942),
  66468 	1385: uint16(4951),
  66469 	1386: uint16(4957),
  66470 	1387: uint16(4977),
  66471 	1388: uint16(4983),
  66472 	1389: uint16(4992),
  66473 	1390: uint16(4998),
  66474 	1391: uint16(5009),
  66475 	1392: uint16(5015),
  66476 	1393: uint16(5024),
  66477 	1394: uint16(5030),
  66478 	1395: uint16(5055),
  66479 	1396: uint16(5061),
  66480 	1397: uint16(5070),
  66481 	1398: uint16(5076),
  66482 	1399: uint16(5087),
  66483 	1400: uint16(5093),
  66484 	1401: uint16(5102),
  66485 	1402: uint16(5108),
  66486 	1403: uint16(5128),
  66487 	1404: uint16(5134),
  66488 	1405: uint16(5143),
  66489 	1406: uint16(5149),
  66490 	1407: uint16(5160),
  66491 	1408: uint16(5166),
  66492 	1409: uint16(5175),
  66493 	1410: uint16(5181),
  66494 	1411: uint16(5045),
  66495 	1412: uint16(5051),
  66496 	1413: uint16(5060),
  66497 	1414: uint16(5066),
  66498 	1415: uint16(5077),
  66499 	1416: uint16(5083),
  66500 	1417: uint16(5092),
  66501 	1418: uint16(5098),
  66502 	1419: uint16(5118),
  66503 	1420: uint16(5124),
  66504 	1421: uint16(5133),
  66505 	1422: uint16(5139),
  66506 	1423: uint16(5150),
  66507 	1424: uint16(5156),
  66508 	1425: uint16(5165),
  66509 	1426: uint16(5171),
  66510 	1427: uint16(5196),
  66511 	1428: uint16(5202),
  66512 	1429: uint16(5211),
  66513 	1430: uint16(5217),
  66514 	1431: uint16(5228),
  66515 	1432: uint16(5234),
  66516 	1433: uint16(5243),
  66517 	1434: uint16(5249),
  66518 	1435: uint16(5269),
  66519 	1436: uint16(5275),
  66520 	1437: uint16(5284),
  66521 	1438: uint16(5290),
  66522 	1439: uint16(5301),
  66523 	1440: uint16(5307),
  66524 	1441: uint16(5316),
  66525 	1442: uint16(5322),
  66526 	1443: uint16(5345),
  66527 	1444: uint16(5351),
  66528 	1445: uint16(5360),
  66529 	1446: uint16(5366),
  66530 	1447: uint16(5377),
  66531 	1448: uint16(5383),
  66532 	1449: uint16(5392),
  66533 	1450: uint16(5398),
  66534 	1451: uint16(5418),
  66535 	1452: uint16(5424),
  66536 	1453: uint16(5433),
  66537 	1454: uint16(5439),
  66538 	1455: uint16(5450),
  66539 	1456: uint16(5456),
  66540 	1457: uint16(5465),
  66541 	1458: uint16(5471),
  66542 	1459: uint16(5496),
  66543 	1460: uint16(5502),
  66544 	1461: uint16(5511),
  66545 	1462: uint16(5517),
  66546 	1463: uint16(5528),
  66547 	1464: uint16(5534),
  66548 	1465: uint16(5543),
  66549 	1466: uint16(5549),
  66550 	1467: uint16(5569),
  66551 	1468: uint16(5575),
  66552 	1469: uint16(5584),
  66553 	1470: uint16(5590),
  66554 	1471: uint16(5601),
  66555 	1472: uint16(5607),
  66556 	1473: uint16(5616),
  66557 	1474: uint16(5622),
  66558 	1475: uint16(5417),
  66559 	1476: uint16(5423),
  66560 	1477: uint16(5432),
  66561 	1478: uint16(5438),
  66562 	1479: uint16(5449),
  66563 	1480: uint16(5455),
  66564 	1481: uint16(5464),
  66565 	1482: uint16(5470),
  66566 	1483: uint16(5490),
  66567 	1484: uint16(5496),
  66568 	1485: uint16(5505),
  66569 	1486: uint16(5511),
  66570 	1487: uint16(5522),
  66571 	1488: uint16(5528),
  66572 	1489: uint16(5537),
  66573 	1490: uint16(5543),
  66574 	1491: uint16(5568),
  66575 	1492: uint16(5574),
  66576 	1493: uint16(5583),
  66577 	1494: uint16(5589),
  66578 	1495: uint16(5600),
  66579 	1496: uint16(5606),
  66580 	1497: uint16(5615),
  66581 	1498: uint16(5621),
  66582 	1499: uint16(5641),
  66583 	1500: uint16(5647),
  66584 	1501: uint16(5656),
  66585 	1502: uint16(5662),
  66586 	1503: uint16(5673),
  66587 	1504: uint16(5679),
  66588 	1505: uint16(5688),
  66589 	1506: uint16(5694),
  66590 	1507: uint16(5717),
  66591 	1508: uint16(5723),
  66592 	1509: uint16(5732),
  66593 	1510: uint16(5738),
  66594 	1511: uint16(5749),
  66595 	1512: uint16(5755),
  66596 	1513: uint16(5764),
  66597 	1514: uint16(5770),
  66598 	1515: uint16(5790),
  66599 	1516: uint16(5796),
  66600 	1517: uint16(5805),
  66601 	1518: uint16(5811),
  66602 	1519: uint16(5822),
  66603 	1520: uint16(5828),
  66604 	1521: uint16(5837),
  66605 	1522: uint16(5843),
  66606 	1523: uint16(5868),
  66607 	1524: uint16(5874),
  66608 	1525: uint16(5883),
  66609 	1526: uint16(5889),
  66610 	1527: uint16(5900),
  66611 	1528: uint16(5906),
  66612 	1529: uint16(5915),
  66613 	1530: uint16(5921),
  66614 	1531: uint16(5941),
  66615 	1532: uint16(5947),
  66616 	1533: uint16(5956),
  66617 	1534: uint16(5962),
  66618 	1535: uint16(5973),
  66619 	1536: uint16(5979),
  66620 	1537: uint16(5988),
  66621 	1538: uint16(5994),
  66622 	1539: uint16(5858),
  66623 	1540: uint16(5864),
  66624 	1541: uint16(5873),
  66625 	1542: uint16(5879),
  66626 	1543: uint16(5890),
  66627 	1544: uint16(5896),
  66628 	1545: uint16(5905),
  66629 	1546: uint16(5911),
  66630 	1547: uint16(5931),
  66631 	1548: uint16(5937),
  66632 	1549: uint16(5946),
  66633 	1550: uint16(5952),
  66634 	1551: uint16(5963),
  66635 	1552: uint16(5969),
  66636 	1553: uint16(5978),
  66637 	1554: uint16(5984),
  66638 	1555: uint16(6009),
  66639 	1556: uint16(6015),
  66640 	1557: uint16(6024),
  66641 	1558: uint16(6030),
  66642 	1559: uint16(6041),
  66643 	1560: uint16(6047),
  66644 	1561: uint16(6056),
  66645 	1562: uint16(6062),
  66646 	1563: uint16(6082),
  66647 	1564: uint16(6088),
  66648 	1565: uint16(6097),
  66649 	1566: uint16(6103),
  66650 	1567: uint16(6114),
  66651 	1568: uint16(6120),
  66652 	1569: uint16(6129),
  66653 	1570: uint16(6135),
  66654 	1571: uint16(6158),
  66655 	1572: uint16(6164),
  66656 	1573: uint16(6173),
  66657 	1574: uint16(6179),
  66658 	1575: uint16(6190),
  66659 	1576: uint16(6196),
  66660 	1577: uint16(6205),
  66661 	1578: uint16(6211),
  66662 	1579: uint16(6231),
  66663 	1580: uint16(6237),
  66664 	1581: uint16(6246),
  66665 	1582: uint16(6252),
  66666 	1583: uint16(6263),
  66667 	1584: uint16(6269),
  66668 	1585: uint16(6278),
  66669 	1586: uint16(6284),
  66670 	1587: uint16(6309),
  66671 	1588: uint16(6315),
  66672 	1589: uint16(6324),
  66673 	1590: uint16(6330),
  66674 	1591: uint16(6341),
  66675 	1592: uint16(6347),
  66676 	1593: uint16(6356),
  66677 	1594: uint16(6362),
  66678 	1595: uint16(6382),
  66679 	1596: uint16(6388),
  66680 	1597: uint16(6397),
  66681 	1598: uint16(6403),
  66682 	1599: uint16(6414),
  66683 	1600: uint16(6420),
  66684 	1601: uint16(6429),
  66685 	1602: uint16(6435),
  66686 	1603: uint16(5303),
  66687 	1604: uint16(5309),
  66688 	1605: uint16(5318),
  66689 	1606: uint16(5324),
  66690 	1607: uint16(5335),
  66691 	1608: uint16(5341),
  66692 	1609: uint16(5350),
  66693 	1610: uint16(5356),
  66694 	1611: uint16(5376),
  66695 	1612: uint16(5382),
  66696 	1613: uint16(5391),
  66697 	1614: uint16(5397),
  66698 	1615: uint16(5408),
  66699 	1616: uint16(5414),
  66700 	1617: uint16(5423),
  66701 	1618: uint16(5429),
  66702 	1619: uint16(5454),
  66703 	1620: uint16(5460),
  66704 	1621: uint16(5469),
  66705 	1622: uint16(5475),
  66706 	1623: uint16(5486),
  66707 	1624: uint16(5492),
  66708 	1625: uint16(5501),
  66709 	1626: uint16(5507),
  66710 	1627: uint16(5527),
  66711 	1628: uint16(5533),
  66712 	1629: uint16(5542),
  66713 	1630: uint16(5548),
  66714 	1631: uint16(5559),
  66715 	1632: uint16(5565),
  66716 	1633: uint16(5574),
  66717 	1634: uint16(5580),
  66718 	1635: uint16(5603),
  66719 	1636: uint16(5609),
  66720 	1637: uint16(5618),
  66721 	1638: uint16(5624),
  66722 	1639: uint16(5635),
  66723 	1640: uint16(5641),
  66724 	1641: uint16(5650),
  66725 	1642: uint16(5656),
  66726 	1643: uint16(5676),
  66727 	1644: uint16(5682),
  66728 	1645: uint16(5691),
  66729 	1646: uint16(5697),
  66730 	1647: uint16(5708),
  66731 	1648: uint16(5714),
  66732 	1649: uint16(5723),
  66733 	1650: uint16(5729),
  66734 	1651: uint16(5754),
  66735 	1652: uint16(5760),
  66736 	1653: uint16(5769),
  66737 	1654: uint16(5775),
  66738 	1655: uint16(5786),
  66739 	1656: uint16(5792),
  66740 	1657: uint16(5801),
  66741 	1658: uint16(5807),
  66742 	1659: uint16(5827),
  66743 	1660: uint16(5833),
  66744 	1661: uint16(5842),
  66745 	1662: uint16(5848),
  66746 	1663: uint16(5859),
  66747 	1664: uint16(5865),
  66748 	1665: uint16(5874),
  66749 	1666: uint16(5880),
  66750 	1667: uint16(5744),
  66751 	1668: uint16(5750),
  66752 	1669: uint16(5759),
  66753 	1670: uint16(5765),
  66754 	1671: uint16(5776),
  66755 	1672: uint16(5782),
  66756 	1673: uint16(5791),
  66757 	1674: uint16(5797),
  66758 	1675: uint16(5817),
  66759 	1676: uint16(5823),
  66760 	1677: uint16(5832),
  66761 	1678: uint16(5838),
  66762 	1679: uint16(5849),
  66763 	1680: uint16(5855),
  66764 	1681: uint16(5864),
  66765 	1682: uint16(5870),
  66766 	1683: uint16(5895),
  66767 	1684: uint16(5901),
  66768 	1685: uint16(5910),
  66769 	1686: uint16(5916),
  66770 	1687: uint16(5927),
  66771 	1688: uint16(5933),
  66772 	1689: uint16(5942),
  66773 	1690: uint16(5948),
  66774 	1691: uint16(5968),
  66775 	1692: uint16(5974),
  66776 	1693: uint16(5983),
  66777 	1694: uint16(5989),
  66778 	1695: uint16(6000),
  66779 	1696: uint16(6006),
  66780 	1697: uint16(6015),
  66781 	1698: uint16(6021),
  66782 	1699: uint16(6044),
  66783 	1700: uint16(6050),
  66784 	1701: uint16(6059),
  66785 	1702: uint16(6065),
  66786 	1703: uint16(6076),
  66787 	1704: uint16(6082),
  66788 	1705: uint16(6091),
  66789 	1706: uint16(6097),
  66790 	1707: uint16(6117),
  66791 	1708: uint16(6123),
  66792 	1709: uint16(6132),
  66793 	1710: uint16(6138),
  66794 	1711: uint16(6149),
  66795 	1712: uint16(6155),
  66796 	1713: uint16(6164),
  66797 	1714: uint16(6170),
  66798 	1715: uint16(6195),
  66799 	1716: uint16(6201),
  66800 	1717: uint16(6210),
  66801 	1718: uint16(6216),
  66802 	1719: uint16(6227),
  66803 	1720: uint16(6233),
  66804 	1721: uint16(6242),
  66805 	1722: uint16(6248),
  66806 	1723: uint16(6268),
  66807 	1724: uint16(6274),
  66808 	1725: uint16(6283),
  66809 	1726: uint16(6289),
  66810 	1727: uint16(6300),
  66811 	1728: uint16(6306),
  66812 	1729: uint16(6315),
  66813 	1730: uint16(6321),
  66814 	1731: uint16(6116),
  66815 	1732: uint16(6122),
  66816 	1733: uint16(6131),
  66817 	1734: uint16(6137),
  66818 	1735: uint16(6148),
  66819 	1736: uint16(6154),
  66820 	1737: uint16(6163),
  66821 	1738: uint16(6169),
  66822 	1739: uint16(6189),
  66823 	1740: uint16(6195),
  66824 	1741: uint16(6204),
  66825 	1742: uint16(6210),
  66826 	1743: uint16(6221),
  66827 	1744: uint16(6227),
  66828 	1745: uint16(6236),
  66829 	1746: uint16(6242),
  66830 	1747: uint16(6267),
  66831 	1748: uint16(6273),
  66832 	1749: uint16(6282),
  66833 	1750: uint16(6288),
  66834 	1751: uint16(6299),
  66835 	1752: uint16(6305),
  66836 	1753: uint16(6314),
  66837 	1754: uint16(6320),
  66838 	1755: uint16(6340),
  66839 	1756: uint16(6346),
  66840 	1757: uint16(6355),
  66841 	1758: uint16(6361),
  66842 	1759: uint16(6372),
  66843 	1760: uint16(6378),
  66844 	1761: uint16(6387),
  66845 	1762: uint16(6393),
  66846 	1763: uint16(6416),
  66847 	1764: uint16(6422),
  66848 	1765: uint16(6431),
  66849 	1766: uint16(6437),
  66850 	1767: uint16(6448),
  66851 	1768: uint16(6454),
  66852 	1769: uint16(6463),
  66853 	1770: uint16(6469),
  66854 	1771: uint16(6489),
  66855 	1772: uint16(6495),
  66856 	1773: uint16(6504),
  66857 	1774: uint16(6510),
  66858 	1775: uint16(6521),
  66859 	1776: uint16(6527),
  66860 	1777: uint16(6536),
  66861 	1778: uint16(6542),
  66862 	1779: uint16(6567),
  66863 	1780: uint16(6573),
  66864 	1781: uint16(6582),
  66865 	1782: uint16(6588),
  66866 	1783: uint16(6599),
  66867 	1784: uint16(6605),
  66868 	1785: uint16(6614),
  66869 	1786: uint16(6620),
  66870 	1787: uint16(6640),
  66871 	1788: uint16(6646),
  66872 	1789: uint16(6655),
  66873 	1790: uint16(6661),
  66874 	1791: uint16(6672),
  66875 	1792: uint16(6678),
  66876 	1793: uint16(6687),
  66877 	1794: uint16(6693),
  66878 	1795: uint16(6557),
  66879 	1796: uint16(6563),
  66880 	1797: uint16(6572),
  66881 	1798: uint16(6578),
  66882 	1799: uint16(6589),
  66883 	1800: uint16(6595),
  66884 	1801: uint16(6604),
  66885 	1802: uint16(6610),
  66886 	1803: uint16(6630),
  66887 	1804: uint16(6636),
  66888 	1805: uint16(6645),
  66889 	1806: uint16(6651),
  66890 	1807: uint16(6662),
  66891 	1808: uint16(6668),
  66892 	1809: uint16(6677),
  66893 	1810: uint16(6683),
  66894 	1811: uint16(6708),
  66895 	1812: uint16(6714),
  66896 	1813: uint16(6723),
  66897 	1814: uint16(6729),
  66898 	1815: uint16(6740),
  66899 	1816: uint16(6746),
  66900 	1817: uint16(6755),
  66901 	1818: uint16(6761),
  66902 	1819: uint16(6781),
  66903 	1820: uint16(6787),
  66904 	1821: uint16(6796),
  66905 	1822: uint16(6802),
  66906 	1823: uint16(6813),
  66907 	1824: uint16(6819),
  66908 	1825: uint16(6828),
  66909 	1826: uint16(6834),
  66910 	1827: uint16(6857),
  66911 	1828: uint16(6863),
  66912 	1829: uint16(6872),
  66913 	1830: uint16(6878),
  66914 	1831: uint16(6889),
  66915 	1832: uint16(6895),
  66916 	1833: uint16(6904),
  66917 	1834: uint16(6910),
  66918 	1835: uint16(6930),
  66919 	1836: uint16(6936),
  66920 	1837: uint16(6945),
  66921 	1838: uint16(6951),
  66922 	1839: uint16(6962),
  66923 	1840: uint16(6968),
  66924 	1841: uint16(6977),
  66925 	1842: uint16(6983),
  66926 	1843: uint16(7008),
  66927 	1844: uint16(7014),
  66928 	1845: uint16(7023),
  66929 	1846: uint16(7029),
  66930 	1847: uint16(7040),
  66931 	1848: uint16(7046),
  66932 	1849: uint16(7055),
  66933 	1850: uint16(7061),
  66934 	1851: uint16(7081),
  66935 	1852: uint16(7087),
  66936 	1853: uint16(7096),
  66937 	1854: uint16(7102),
  66938 	1855: uint16(7113),
  66939 	1856: uint16(7119),
  66940 	1857: uint16(7128),
  66941 	1858: uint16(7134),
  66942 	1859: uint16(6392),
  66943 	1860: uint16(6398),
  66944 	1861: uint16(6407),
  66945 	1862: uint16(6413),
  66946 	1863: uint16(6424),
  66947 	1864: uint16(6430),
  66948 	1865: uint16(6439),
  66949 	1866: uint16(6445),
  66950 	1867: uint16(6465),
  66951 	1868: uint16(6471),
  66952 	1869: uint16(6480),
  66953 	1870: uint16(6486),
  66954 	1871: uint16(6497),
  66955 	1872: uint16(6503),
  66956 	1873: uint16(6512),
  66957 	1874: uint16(6518),
  66958 	1875: uint16(6543),
  66959 	1876: uint16(6549),
  66960 	1877: uint16(6558),
  66961 	1878: uint16(6564),
  66962 	1879: uint16(6575),
  66963 	1880: uint16(6581),
  66964 	1881: uint16(6590),
  66965 	1882: uint16(6596),
  66966 	1883: uint16(6616),
  66967 	1884: uint16(6622),
  66968 	1885: uint16(6631),
  66969 	1886: uint16(6637),
  66970 	1887: uint16(6648),
  66971 	1888: uint16(6654),
  66972 	1889: uint16(6663),
  66973 	1890: uint16(6669),
  66974 	1891: uint16(6692),
  66975 	1892: uint16(6698),
  66976 	1893: uint16(6707),
  66977 	1894: uint16(6713),
  66978 	1895: uint16(6724),
  66979 	1896: uint16(6730),
  66980 	1897: uint16(6739),
  66981 	1898: uint16(6745),
  66982 	1899: uint16(6765),
  66983 	1900: uint16(6771),
  66984 	1901: uint16(6780),
  66985 	1902: uint16(6786),
  66986 	1903: uint16(6797),
  66987 	1904: uint16(6803),
  66988 	1905: uint16(6812),
  66989 	1906: uint16(6818),
  66990 	1907: uint16(6843),
  66991 	1908: uint16(6849),
  66992 	1909: uint16(6858),
  66993 	1910: uint16(6864),
  66994 	1911: uint16(6875),
  66995 	1912: uint16(6881),
  66996 	1913: uint16(6890),
  66997 	1914: uint16(6896),
  66998 	1915: uint16(6916),
  66999 	1916: uint16(6922),
  67000 	1917: uint16(6931),
  67001 	1918: uint16(6937),
  67002 	1919: uint16(6948),
  67003 	1920: uint16(6954),
  67004 	1921: uint16(6963),
  67005 	1922: uint16(6969),
  67006 	1923: uint16(6833),
  67007 	1924: uint16(6839),
  67008 	1925: uint16(6848),
  67009 	1926: uint16(6854),
  67010 	1927: uint16(6865),
  67011 	1928: uint16(6871),
  67012 	1929: uint16(6880),
  67013 	1930: uint16(6886),
  67014 	1931: uint16(6906),
  67015 	1932: uint16(6912),
  67016 	1933: uint16(6921),
  67017 	1934: uint16(6927),
  67018 	1935: uint16(6938),
  67019 	1936: uint16(6944),
  67020 	1937: uint16(6953),
  67021 	1938: uint16(6959),
  67022 	1939: uint16(6984),
  67023 	1940: uint16(6990),
  67024 	1941: uint16(6999),
  67025 	1942: uint16(7005),
  67026 	1943: uint16(7016),
  67027 	1944: uint16(7022),
  67028 	1945: uint16(7031),
  67029 	1946: uint16(7037),
  67030 	1947: uint16(7057),
  67031 	1948: uint16(7063),
  67032 	1949: uint16(7072),
  67033 	1950: uint16(7078),
  67034 	1951: uint16(7089),
  67035 	1952: uint16(7095),
  67036 	1953: uint16(7104),
  67037 	1954: uint16(7110),
  67038 	1955: uint16(7133),
  67039 	1956: uint16(7139),
  67040 	1957: uint16(7148),
  67041 	1958: uint16(7154),
  67042 	1959: uint16(7165),
  67043 	1960: uint16(7171),
  67044 	1961: uint16(7180),
  67045 	1962: uint16(7186),
  67046 	1963: uint16(7206),
  67047 	1964: uint16(7212),
  67048 	1965: uint16(7221),
  67049 	1966: uint16(7227),
  67050 	1967: uint16(7238),
  67051 	1968: uint16(7244),
  67052 	1969: uint16(7253),
  67053 	1970: uint16(7259),
  67054 	1971: uint16(7284),
  67055 	1972: uint16(7290),
  67056 	1973: uint16(7299),
  67057 	1974: uint16(7305),
  67058 	1975: uint16(7316),
  67059 	1976: uint16(7322),
  67060 	1977: uint16(7331),
  67061 	1978: uint16(7337),
  67062 	1979: uint16(7357),
  67063 	1980: uint16(7363),
  67064 	1981: uint16(7372),
  67065 	1982: uint16(7378),
  67066 	1983: uint16(7389),
  67067 	1984: uint16(7395),
  67068 	1985: uint16(7404),
  67069 	1986: uint16(7410),
  67070 	1987: uint16(7205),
  67071 	1988: uint16(7211),
  67072 	1989: uint16(7220),
  67073 	1990: uint16(7226),
  67074 	1991: uint16(7237),
  67075 	1992: uint16(7243),
  67076 	1993: uint16(7252),
  67077 	1994: uint16(7258),
  67078 	1995: uint16(7278),
  67079 	1996: uint16(7284),
  67080 	1997: uint16(7293),
  67081 	1998: uint16(7299),
  67082 	1999: uint16(7310),
  67083 	2000: uint16(7316),
  67084 	2001: uint16(7325),
  67085 	2002: uint16(7331),
  67086 	2003: uint16(7356),
  67087 	2004: uint16(7362),
  67088 	2005: uint16(7371),
  67089 	2006: uint16(7377),
  67090 	2007: uint16(7388),
  67091 	2008: uint16(7394),
  67092 	2009: uint16(7403),
  67093 	2010: uint16(7409),
  67094 	2011: uint16(7429),
  67095 	2012: uint16(7435),
  67096 	2013: uint16(7444),
  67097 	2014: uint16(7450),
  67098 	2015: uint16(7461),
  67099 	2016: uint16(7467),
  67100 	2017: uint16(7476),
  67101 	2018: uint16(7482),
  67102 	2019: uint16(7505),
  67103 	2020: uint16(7511),
  67104 	2021: uint16(7520),
  67105 	2022: uint16(7526),
  67106 	2023: uint16(7537),
  67107 	2024: uint16(7543),
  67108 	2025: uint16(7552),
  67109 	2026: uint16(7558),
  67110 	2027: uint16(7578),
  67111 	2028: uint16(7584),
  67112 	2029: uint16(7593),
  67113 	2030: uint16(7599),
  67114 	2031: uint16(7610),
  67115 	2032: uint16(7616),
  67116 	2033: uint16(7625),
  67117 	2034: uint16(7631),
  67118 	2035: uint16(7656),
  67119 	2036: uint16(7662),
  67120 	2037: uint16(7671),
  67121 	2038: uint16(7677),
  67122 	2039: uint16(7688),
  67123 	2040: uint16(7694),
  67124 	2041: uint16(7703),
  67125 	2042: uint16(7709),
  67126 	2043: uint16(7729),
  67127 	2044: uint16(7735),
  67128 	2045: uint16(7744),
  67129 	2046: uint16(7750),
  67130 	2047: uint16(7761),
  67131 }
  67132 
  67133 var VP8Mean16x4 VP8MeanMetric
  67134 
  67135 var VP8PredChroma8 [7]VP8PredFunc
  67136 
  67137 var VP8PredLuma16 [7]VP8PredFunc
  67138 
  67139 var VP8PredLuma4 [10]VP8PredFunc
  67140 
  67141 var VP8SSE16x16 VP8Metric
  67142 
  67143 var VP8SSE16x8 VP8Metric
  67144 
  67145 var VP8SSE4x4 VP8Metric
  67146 
  67147 var VP8SSE8x8 VP8Metric
  67148 
  67149 //------------------------------------------------------------------------------
  67150 
  67151 var VP8SSIMGet VP8SSIMGetFunc
  67152 
  67153 var VP8SSIMGetClipped VP8SSIMGetClippedFunc
  67154 
  67155 //------------------------------------------------------------------------------
  67156 // Quantize
  67157 
  67158 // Layout:
  67159 // +----+----+
  67160 // |YYYY|UUVV| 0
  67161 // |YYYY|UUVV| 4
  67162 // |YYYY|....| 8
  67163 // |YYYY|....| 12
  67164 // +----+----+
  67165 
  67166 var VP8Scan = [16]uint16_t{
  67167 	1:  uint16(libc.Int32FromInt32(4) + libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)),
  67168 	2:  uint16(libc.Int32FromInt32(8) + libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)),
  67169 	3:  uint16(libc.Int32FromInt32(12) + libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)),
  67170 	4:  uint16(libc.Int32FromInt32(0) + libc.Int32FromInt32(4)*libc.Int32FromInt32(BPS)),
  67171 	5:  uint16(libc.Int32FromInt32(4) + libc.Int32FromInt32(4)*libc.Int32FromInt32(BPS)),
  67172 	6:  uint16(libc.Int32FromInt32(8) + libc.Int32FromInt32(4)*libc.Int32FromInt32(BPS)),
  67173 	7:  uint16(libc.Int32FromInt32(12) + libc.Int32FromInt32(4)*libc.Int32FromInt32(BPS)),
  67174 	8:  uint16(libc.Int32FromInt32(0) + libc.Int32FromInt32(8)*libc.Int32FromInt32(BPS)),
  67175 	9:  uint16(libc.Int32FromInt32(4) + libc.Int32FromInt32(8)*libc.Int32FromInt32(BPS)),
  67176 	10: uint16(libc.Int32FromInt32(8) + libc.Int32FromInt32(8)*libc.Int32FromInt32(BPS)),
  67177 	11: uint16(libc.Int32FromInt32(12) + libc.Int32FromInt32(8)*libc.Int32FromInt32(BPS)),
  67178 	12: uint16(libc.Int32FromInt32(0) + libc.Int32FromInt32(12)*libc.Int32FromInt32(BPS)),
  67179 	13: uint16(libc.Int32FromInt32(4) + libc.Int32FromInt32(12)*libc.Int32FromInt32(BPS)),
  67180 	14: uint16(libc.Int32FromInt32(8) + libc.Int32FromInt32(12)*libc.Int32FromInt32(BPS)),
  67181 	15: uint16(libc.Int32FromInt32(12) + libc.Int32FromInt32(12)*libc.Int32FromInt32(BPS)),
  67182 }
  67183 
  67184 var VP8SetResidualCoeffs VP8SetResidualCoeffsFunc
  67185 
  67186 var VP8SimpleHFilter16 VP8SimpleFilterFunc
  67187 
  67188 var VP8SimpleHFilter16i VP8SimpleFilterFunc
  67189 
  67190 var VP8SimpleVFilter16 VP8SimpleFilterFunc
  67191 
  67192 var VP8SimpleVFilter16i VP8SimpleFilterFunc
  67193 
  67194 var VP8TDisto16x16 VP8WMetric
  67195 
  67196 var VP8TDisto4x4 VP8WMetric
  67197 
  67198 //------------------------------------------------------------------------------
  67199 
  67200 var VP8Transform VP8DecIdct2
  67201 
  67202 var VP8TransformAC3 VP8DecIdct
  67203 
  67204 var VP8TransformDC VP8DecIdct
  67205 
  67206 var VP8TransformDCUV VP8DecIdct
  67207 
  67208 var VP8TransformUV VP8DecIdct
  67209 
  67210 var VP8TransformWHT VP8WHT
  67211 
  67212 var VP8UVModeOffsets = [4]uint16_t{
  67213 	0: uint16(libc.Int32FromInt32(2) * libc.Int32FromInt32(16) * libc.Int32FromInt32(BPS)),
  67214 	1: uint16(libc.Int32FromInt32(2)*libc.Int32FromInt32(16)*libc.Int32FromInt32(BPS) + libc.Int32FromInt32(1)*libc.Int32FromInt32(16)),
  67215 	2: uint16(libc.Int32FromInt32(2)*libc.Int32FromInt32(16)*libc.Int32FromInt32(BPS) + libc.Int32FromInt32(8)*libc.Int32FromInt32(BPS)),
  67216 	3: uint16(libc.Int32FromInt32(2)*libc.Int32FromInt32(16)*libc.Int32FromInt32(BPS) + libc.Int32FromInt32(8)*libc.Int32FromInt32(BPS) + libc.Int32FromInt32(1)*libc.Int32FromInt32(16)),
  67217 }
  67218 
  67219 var VP8VFilter16 VP8LumaFilterFunc
  67220 
  67221 var VP8VFilter16i VP8LumaFilterFunc
  67222 
  67223 var VP8VFilter8 VP8ChromaFilterFunc
  67224 
  67225 var VP8VFilter8i VP8ChromaFilterFunc
  67226 
  67227 var VP8kabs0 = uintptr(unsafe.Pointer(&abs0)) + 255
  67228 
  67229 var VP8kclip1 = uintptr(unsafe.Pointer(&clip11)) + 255
  67230 
  67231 var VP8ksclip1 = uintptr(unsafe.Pointer(&sclip1)) + 1020
  67232 
  67233 var VP8ksclip2 = uintptr(unsafe.Pointer(&sclip2)) + 112
  67234 
  67235 var WebPAlphaReplace uintptr
  67236 
  67237 var WebPApplyAlphaMultiply uintptr
  67238 
  67239 var WebPApplyAlphaMultiply4444 uintptr
  67240 
  67241 var WebPConvertARGBToUV uintptr
  67242 
  67243 var WebPConvertARGBToY uintptr
  67244 
  67245 var WebPConvertBGR24ToY uintptr
  67246 
  67247 //-----------------------------------------------------------------------------
  67248 
  67249 var WebPConvertRGB24ToY uintptr
  67250 
  67251 var WebPConvertRGBA32ToUV uintptr
  67252 
  67253 var WebPDispatchAlpha uintptr
  67254 
  67255 var WebPDispatchAlphaToGreen uintptr
  67256 
  67257 var WebPExtractAlpha uintptr
  67258 
  67259 var WebPExtractGreen uintptr
  67260 
  67261 //------------------------------------------------------------------------------
  67262 // Init function
  67263 
  67264 var WebPFilters [4]WebPFilterFunc
  67265 
  67266 var WebPHasAlpha32b uintptr
  67267 
  67268 var WebPHasAlpha8b uintptr
  67269 
  67270 var WebPMultARGBRow uintptr
  67271 
  67272 var WebPMultRow uintptr
  67273 
  67274 var WebPPackRGB uintptr
  67275 
  67276 var WebPRescalerExportRowExpand WebPRescalerExportRowFunc
  67277 
  67278 var WebPRescalerExportRowShrink WebPRescalerExportRowFunc
  67279 
  67280 //------------------------------------------------------------------------------
  67281 
  67282 var WebPRescalerImportRowExpand WebPRescalerImportRowFunc
  67283 
  67284 var WebPRescalerImportRowShrink WebPRescalerImportRowFunc
  67285 
  67286 //-----------------------------------------------------------------------------
  67287 // Main call
  67288 
  67289 var WebPSamplers [13]WebPSamplerRowFunc
  67290 
  67291 var WebPUnfilters [4]WebPUnfilterFunc
  67292 
  67293 // Copyright 2010 Google Inc. All Rights Reserved.
  67294 //
  67295 // Use of this source code is governed by a BSD-style license
  67296 // that can be found in the COPYING file in the root of the source
  67297 // tree. An additional intellectual property rights grant can be found
  67298 // in the file PATENTS. All contributing project authors may
  67299 // be found in the AUTHORS file in the root of the source tree.
  67300 // -----------------------------------------------------------------------------
  67301 //
  67302 //  Main decoding functions for WebP images.
  67303 //
  67304 // Author: Skal (pascal.massimino@gmail.com)
  67305 
  67306 //------------------------------------------------------------------------------
  67307 // Fancy upsampler
  67308 
  67309 // C documentation
  67310 //
  67311 //	// Fancy upsampling functions to convert YUV to RGB
  67312 var WebPUpsamplers [13]WebPUpsampleLinePairFunc
  67313 
  67314 var WebPYUV444Converters [13]WebPYUV444Converter
  67315 
  67316 // Copyright 2012 Google Inc. All Rights Reserved.
  67317 //
  67318 // Use of this source code is governed by a BSD-style license
  67319 // that can be found in the COPYING file in the root of the source
  67320 // tree. An additional intellectual property rights grant can be found
  67321 // in the file PATENTS. All contributing project authors may
  67322 // be found in the AUTHORS file in the root of the source tree.
  67323 // -----------------------------------------------------------------------------
  67324 //
  67325 // Misc. common utility functions
  67326 //
  67327 // Authors: Skal (pascal.massimino@gmail.com)
  67328 //          Urvang (urvang@google.com)
  67329 
  67330 // Copyright 2012 Google Inc. All Rights Reserved.
  67331 //
  67332 // Use of this source code is governed by a BSD-style license
  67333 // that can be found in the COPYING file in the root of the source
  67334 // tree. An additional intellectual property rights grant can be found
  67335 // in the file PATENTS. All contributing project authors may
  67336 // be found in the AUTHORS file in the root of the source tree.
  67337 // -----------------------------------------------------------------------------
  67338 //
  67339 //  Internal header for constants related to WebP file format.
  67340 //
  67341 // Author: Urvang (urvang@google.com)
  67342 
  67343 // Copyright 2010 Google Inc. All Rights Reserved.
  67344 //
  67345 // Use of this source code is governed by a BSD-style license
  67346 // that can be found in the COPYING file in the root of the source
  67347 // tree. An additional intellectual property rights grant can be found
  67348 // in the file PATENTS. All contributing project authors may
  67349 // be found in the AUTHORS file in the root of the source tree.
  67350 // -----------------------------------------------------------------------------
  67351 //
  67352 //  Common types + memory wrappers
  67353 //
  67354 // Author: Skal (pascal.massimino@gmail.com)
  67355 
  67356 // C documentation
  67357 //
  67358 //	// lookup table for small values of log2(int) * (1 << LOG_2_PRECISION_BITS).
  67359 //	// Obtained in Python with:
  67360 //	// a = [ str(round((1<<23)*math.log2(i))) if i else "0" for i in range(256)]
  67361 //	// print(',\n'.join(['  '+','.join(v)
  67362 //	//       for v in batched([i.rjust(9) for i in a],7)]))
  67363 var kLog2Table = [256]uint32_t{
  67364 	2:   uint32(8388608),
  67365 	3:   uint32(13295629),
  67366 	4:   uint32(16777216),
  67367 	5:   uint32(19477745),
  67368 	6:   uint32(21684237),
  67369 	7:   uint32(23549800),
  67370 	8:   uint32(25165824),
  67371 	9:   uint32(26591258),
  67372 	10:  uint32(27866353),
  67373 	11:  uint32(29019816),
  67374 	12:  uint32(30072845),
  67375 	13:  uint32(31041538),
  67376 	14:  uint32(31938408),
  67377 	15:  uint32(32773374),
  67378 	16:  uint32(33554432),
  67379 	17:  uint32(34288123),
  67380 	18:  uint32(34979866),
  67381 	19:  uint32(35634199),
  67382 	20:  uint32(36254961),
  67383 	21:  uint32(36845429),
  67384 	22:  uint32(37408424),
  67385 	23:  uint32(37946388),
  67386 	24:  uint32(38461453),
  67387 	25:  uint32(38955489),
  67388 	26:  uint32(39430146),
  67389 	27:  uint32(39886887),
  67390 	28:  uint32(40327016),
  67391 	29:  uint32(40751698),
  67392 	30:  uint32(41161982),
  67393 	31:  uint32(41558811),
  67394 	32:  uint32(41943040),
  67395 	33:  uint32(42315445),
  67396 	34:  uint32(42676731),
  67397 	35:  uint32(43027545),
  67398 	36:  uint32(43368474),
  67399 	37:  uint32(43700062),
  67400 	38:  uint32(44022807),
  67401 	39:  uint32(44337167),
  67402 	40:  uint32(44643569),
  67403 	41:  uint32(44942404),
  67404 	42:  uint32(45234037),
  67405 	43:  uint32(45518808),
  67406 	44:  uint32(45797032),
  67407 	45:  uint32(46069003),
  67408 	46:  uint32(46334996),
  67409 	47:  uint32(46595268),
  67410 	48:  uint32(46850061),
  67411 	49:  uint32(47099600),
  67412 	50:  uint32(47344097),
  67413 	51:  uint32(47583753),
  67414 	52:  uint32(47818754),
  67415 	53:  uint32(48049279),
  67416 	54:  uint32(48275495),
  67417 	55:  uint32(48497560),
  67418 	56:  uint32(48715624),
  67419 	57:  uint32(48929828),
  67420 	58:  uint32(49140306),
  67421 	59:  uint32(49347187),
  67422 	60:  uint32(49550590),
  67423 	61:  uint32(49750631),
  67424 	62:  uint32(49947419),
  67425 	63:  uint32(50141058),
  67426 	64:  uint32(50331648),
  67427 	65:  uint32(50519283),
  67428 	66:  uint32(50704053),
  67429 	67:  uint32(50886044),
  67430 	68:  uint32(51065339),
  67431 	69:  uint32(51242017),
  67432 	70:  uint32(51416153),
  67433 	71:  uint32(51587818),
  67434 	72:  uint32(51757082),
  67435 	73:  uint32(51924012),
  67436 	74:  uint32(52088670),
  67437 	75:  uint32(52251118),
  67438 	76:  uint32(52411415),
  67439 	77:  uint32(52569616),
  67440 	78:  uint32(52725775),
  67441 	79:  uint32(52879946),
  67442 	80:  uint32(53032177),
  67443 	81:  uint32(53182516),
  67444 	82:  uint32(53331012),
  67445 	83:  uint32(53477707),
  67446 	84:  uint32(53622645),
  67447 	85:  uint32(53765868),
  67448 	86:  uint32(53907416),
  67449 	87:  uint32(54047327),
  67450 	88:  uint32(54185640),
  67451 	89:  uint32(54322389),
  67452 	90:  uint32(54457611),
  67453 	91:  uint32(54591338),
  67454 	92:  uint32(54723604),
  67455 	93:  uint32(54854440),
  67456 	94:  uint32(54983876),
  67457 	95:  uint32(55111943),
  67458 	96:  uint32(55238669),
  67459 	97:  uint32(55364082),
  67460 	98:  uint32(55488208),
  67461 	99:  uint32(55611074),
  67462 	100: uint32(55732705),
  67463 	101: uint32(55853126),
  67464 	102: uint32(55972361),
  67465 	103: uint32(56090432),
  67466 	104: uint32(56207362),
  67467 	105: uint32(56323174),
  67468 	106: uint32(56437887),
  67469 	107: uint32(56551524),
  67470 	108: uint32(56664103),
  67471 	109: uint32(56775645),
  67472 	110: uint32(56886168),
  67473 	111: uint32(56995691),
  67474 	112: uint32(57104232),
  67475 	113: uint32(57211808),
  67476 	114: uint32(57318436),
  67477 	115: uint32(57424133),
  67478 	116: uint32(57528914),
  67479 	117: uint32(57632796),
  67480 	118: uint32(57735795),
  67481 	119: uint32(57837923),
  67482 	120: uint32(57939198),
  67483 	121: uint32(58039632),
  67484 	122: uint32(58139239),
  67485 	123: uint32(58238033),
  67486 	124: uint32(58336027),
  67487 	125: uint32(58433234),
  67488 	126: uint32(58529666),
  67489 	127: uint32(58625336),
  67490 	128: uint32(58720256),
  67491 	129: uint32(58814437),
  67492 	130: uint32(58907891),
  67493 	131: uint32(59000628),
  67494 	132: uint32(59092661),
  67495 	133: uint32(59183999),
  67496 	134: uint32(59274652),
  67497 	135: uint32(59364632),
  67498 	136: uint32(59453947),
  67499 	137: uint32(59542609),
  67500 	138: uint32(59630625),
  67501 	139: uint32(59718006),
  67502 	140: uint32(59804761),
  67503 	141: uint32(59890898),
  67504 	142: uint32(59976426),
  67505 	143: uint32(60061354),
  67506 	144: uint32(60145690),
  67507 	145: uint32(60229443),
  67508 	146: uint32(60312620),
  67509 	147: uint32(60395229),
  67510 	148: uint32(60477278),
  67511 	149: uint32(60558775),
  67512 	150: uint32(60639726),
  67513 	151: uint32(60720140),
  67514 	152: uint32(60800023),
  67515 	153: uint32(60879382),
  67516 	154: uint32(60958224),
  67517 	155: uint32(61036555),
  67518 	156: uint32(61114383),
  67519 	157: uint32(61191714),
  67520 	158: uint32(61268554),
  67521 	159: uint32(61344908),
  67522 	160: uint32(61420785),
  67523 	161: uint32(61496188),
  67524 	162: uint32(61571124),
  67525 	163: uint32(61645600),
  67526 	164: uint32(61719620),
  67527 	165: uint32(61793189),
  67528 	166: uint32(61866315),
  67529 	167: uint32(61939001),
  67530 	168: uint32(62011253),
  67531 	169: uint32(62083076),
  67532 	170: uint32(62154476),
  67533 	171: uint32(62225457),
  67534 	172: uint32(62296024),
  67535 	173: uint32(62366182),
  67536 	174: uint32(62435935),
  67537 	175: uint32(62505289),
  67538 	176: uint32(62574248),
  67539 	177: uint32(62642816),
  67540 	178: uint32(62710997),
  67541 	179: uint32(62778797),
  67542 	180: uint32(62846219),
  67543 	181: uint32(62913267),
  67544 	182: uint32(62979946),
  67545 	183: uint32(63046260),
  67546 	184: uint32(63112212),
  67547 	185: uint32(63177807),
  67548 	186: uint32(63243048),
  67549 	187: uint32(63307939),
  67550 	188: uint32(63372484),
  67551 	189: uint32(63436687),
  67552 	190: uint32(63500551),
  67553 	191: uint32(63564080),
  67554 	192: uint32(63627277),
  67555 	193: uint32(63690146),
  67556 	194: uint32(63752690),
  67557 	195: uint32(63814912),
  67558 	196: uint32(63876816),
  67559 	197: uint32(63938405),
  67560 	198: uint32(63999682),
  67561 	199: uint32(64060650),
  67562 	200: uint32(64121313),
  67563 	201: uint32(64181673),
  67564 	202: uint32(64241734),
  67565 	203: uint32(64301498),
  67566 	204: uint32(64360969),
  67567 	205: uint32(64420148),
  67568 	206: uint32(64479040),
  67569 	207: uint32(64537646),
  67570 	208: uint32(64595970),
  67571 	209: uint32(64654014),
  67572 	210: uint32(64711782),
  67573 	211: uint32(64769274),
  67574 	212: uint32(64826495),
  67575 	213: uint32(64883447),
  67576 	214: uint32(64940132),
  67577 	215: uint32(64996553),
  67578 	216: uint32(65052711),
  67579 	217: uint32(65108611),
  67580 	218: uint32(65164253),
  67581 	219: uint32(65219641),
  67582 	220: uint32(65274776),
  67583 	221: uint32(65329662),
  67584 	222: uint32(65384299),
  67585 	223: uint32(65438691),
  67586 	224: uint32(65492840),
  67587 	225: uint32(65546747),
  67588 	226: uint32(65600416),
  67589 	227: uint32(65653847),
  67590 	228: uint32(65707044),
  67591 	229: uint32(65760008),
  67592 	230: uint32(65812741),
  67593 	231: uint32(65865245),
  67594 	232: uint32(65917522),
  67595 	233: uint32(65969575),
  67596 	234: uint32(66021404),
  67597 	235: uint32(66073013),
  67598 	236: uint32(66124403),
  67599 	237: uint32(66175575),
  67600 	238: uint32(66226531),
  67601 	239: uint32(66277275),
  67602 	240: uint32(66327806),
  67603 	241: uint32(66378127),
  67604 	242: uint32(66428240),
  67605 	243: uint32(66478146),
  67606 	244: uint32(66527847),
  67607 	245: uint32(66577345),
  67608 	246: uint32(66626641),
  67609 	247: uint32(66675737),
  67610 	248: uint32(66724635),
  67611 	249: uint32(66773336),
  67612 	250: uint32(66821842),
  67613 	251: uint32(66870154),
  67614 	252: uint32(66918274),
  67615 	253: uint32(66966204),
  67616 	254: uint32(67013944),
  67617 	255: uint32(67061497),
  67618 }
  67619 
  67620 var kPrefixEncodeCode = [512]VP8LPrefixCode{
  67621 	0: {},
  67622 	1: {},
  67623 	2: {
  67624 		Fcode: int8(1),
  67625 	},
  67626 	3: {
  67627 		Fcode: int8(2),
  67628 	},
  67629 	4: {
  67630 		Fcode: int8(3),
  67631 	},
  67632 	5: {
  67633 		Fcode:       int8(4),
  67634 		Fextra_bits: int8(1),
  67635 	},
  67636 	6: {
  67637 		Fcode:       int8(4),
  67638 		Fextra_bits: int8(1),
  67639 	},
  67640 	7: {
  67641 		Fcode:       int8(5),
  67642 		Fextra_bits: int8(1),
  67643 	},
  67644 	8: {
  67645 		Fcode:       int8(5),
  67646 		Fextra_bits: int8(1),
  67647 	},
  67648 	9: {
  67649 		Fcode:       int8(6),
  67650 		Fextra_bits: int8(2),
  67651 	},
  67652 	10: {
  67653 		Fcode:       int8(6),
  67654 		Fextra_bits: int8(2),
  67655 	},
  67656 	11: {
  67657 		Fcode:       int8(6),
  67658 		Fextra_bits: int8(2),
  67659 	},
  67660 	12: {
  67661 		Fcode:       int8(6),
  67662 		Fextra_bits: int8(2),
  67663 	},
  67664 	13: {
  67665 		Fcode:       int8(7),
  67666 		Fextra_bits: int8(2),
  67667 	},
  67668 	14: {
  67669 		Fcode:       int8(7),
  67670 		Fextra_bits: int8(2),
  67671 	},
  67672 	15: {
  67673 		Fcode:       int8(7),
  67674 		Fextra_bits: int8(2),
  67675 	},
  67676 	16: {
  67677 		Fcode:       int8(7),
  67678 		Fextra_bits: int8(2),
  67679 	},
  67680 	17: {
  67681 		Fcode:       int8(8),
  67682 		Fextra_bits: int8(3),
  67683 	},
  67684 	18: {
  67685 		Fcode:       int8(8),
  67686 		Fextra_bits: int8(3),
  67687 	},
  67688 	19: {
  67689 		Fcode:       int8(8),
  67690 		Fextra_bits: int8(3),
  67691 	},
  67692 	20: {
  67693 		Fcode:       int8(8),
  67694 		Fextra_bits: int8(3),
  67695 	},
  67696 	21: {
  67697 		Fcode:       int8(8),
  67698 		Fextra_bits: int8(3),
  67699 	},
  67700 	22: {
  67701 		Fcode:       int8(8),
  67702 		Fextra_bits: int8(3),
  67703 	},
  67704 	23: {
  67705 		Fcode:       int8(8),
  67706 		Fextra_bits: int8(3),
  67707 	},
  67708 	24: {
  67709 		Fcode:       int8(8),
  67710 		Fextra_bits: int8(3),
  67711 	},
  67712 	25: {
  67713 		Fcode:       int8(9),
  67714 		Fextra_bits: int8(3),
  67715 	},
  67716 	26: {
  67717 		Fcode:       int8(9),
  67718 		Fextra_bits: int8(3),
  67719 	},
  67720 	27: {
  67721 		Fcode:       int8(9),
  67722 		Fextra_bits: int8(3),
  67723 	},
  67724 	28: {
  67725 		Fcode:       int8(9),
  67726 		Fextra_bits: int8(3),
  67727 	},
  67728 	29: {
  67729 		Fcode:       int8(9),
  67730 		Fextra_bits: int8(3),
  67731 	},
  67732 	30: {
  67733 		Fcode:       int8(9),
  67734 		Fextra_bits: int8(3),
  67735 	},
  67736 	31: {
  67737 		Fcode:       int8(9),
  67738 		Fextra_bits: int8(3),
  67739 	},
  67740 	32: {
  67741 		Fcode:       int8(9),
  67742 		Fextra_bits: int8(3),
  67743 	},
  67744 	33: {
  67745 		Fcode:       int8(10),
  67746 		Fextra_bits: int8(4),
  67747 	},
  67748 	34: {
  67749 		Fcode:       int8(10),
  67750 		Fextra_bits: int8(4),
  67751 	},
  67752 	35: {
  67753 		Fcode:       int8(10),
  67754 		Fextra_bits: int8(4),
  67755 	},
  67756 	36: {
  67757 		Fcode:       int8(10),
  67758 		Fextra_bits: int8(4),
  67759 	},
  67760 	37: {
  67761 		Fcode:       int8(10),
  67762 		Fextra_bits: int8(4),
  67763 	},
  67764 	38: {
  67765 		Fcode:       int8(10),
  67766 		Fextra_bits: int8(4),
  67767 	},
  67768 	39: {
  67769 		Fcode:       int8(10),
  67770 		Fextra_bits: int8(4),
  67771 	},
  67772 	40: {
  67773 		Fcode:       int8(10),
  67774 		Fextra_bits: int8(4),
  67775 	},
  67776 	41: {
  67777 		Fcode:       int8(10),
  67778 		Fextra_bits: int8(4),
  67779 	},
  67780 	42: {
  67781 		Fcode:       int8(10),
  67782 		Fextra_bits: int8(4),
  67783 	},
  67784 	43: {
  67785 		Fcode:       int8(10),
  67786 		Fextra_bits: int8(4),
  67787 	},
  67788 	44: {
  67789 		Fcode:       int8(10),
  67790 		Fextra_bits: int8(4),
  67791 	},
  67792 	45: {
  67793 		Fcode:       int8(10),
  67794 		Fextra_bits: int8(4),
  67795 	},
  67796 	46: {
  67797 		Fcode:       int8(10),
  67798 		Fextra_bits: int8(4),
  67799 	},
  67800 	47: {
  67801 		Fcode:       int8(10),
  67802 		Fextra_bits: int8(4),
  67803 	},
  67804 	48: {
  67805 		Fcode:       int8(10),
  67806 		Fextra_bits: int8(4),
  67807 	},
  67808 	49: {
  67809 		Fcode:       int8(11),
  67810 		Fextra_bits: int8(4),
  67811 	},
  67812 	50: {
  67813 		Fcode:       int8(11),
  67814 		Fextra_bits: int8(4),
  67815 	},
  67816 	51: {
  67817 		Fcode:       int8(11),
  67818 		Fextra_bits: int8(4),
  67819 	},
  67820 	52: {
  67821 		Fcode:       int8(11),
  67822 		Fextra_bits: int8(4),
  67823 	},
  67824 	53: {
  67825 		Fcode:       int8(11),
  67826 		Fextra_bits: int8(4),
  67827 	},
  67828 	54: {
  67829 		Fcode:       int8(11),
  67830 		Fextra_bits: int8(4),
  67831 	},
  67832 	55: {
  67833 		Fcode:       int8(11),
  67834 		Fextra_bits: int8(4),
  67835 	},
  67836 	56: {
  67837 		Fcode:       int8(11),
  67838 		Fextra_bits: int8(4),
  67839 	},
  67840 	57: {
  67841 		Fcode:       int8(11),
  67842 		Fextra_bits: int8(4),
  67843 	},
  67844 	58: {
  67845 		Fcode:       int8(11),
  67846 		Fextra_bits: int8(4),
  67847 	},
  67848 	59: {
  67849 		Fcode:       int8(11),
  67850 		Fextra_bits: int8(4),
  67851 	},
  67852 	60: {
  67853 		Fcode:       int8(11),
  67854 		Fextra_bits: int8(4),
  67855 	},
  67856 	61: {
  67857 		Fcode:       int8(11),
  67858 		Fextra_bits: int8(4),
  67859 	},
  67860 	62: {
  67861 		Fcode:       int8(11),
  67862 		Fextra_bits: int8(4),
  67863 	},
  67864 	63: {
  67865 		Fcode:       int8(11),
  67866 		Fextra_bits: int8(4),
  67867 	},
  67868 	64: {
  67869 		Fcode:       int8(11),
  67870 		Fextra_bits: int8(4),
  67871 	},
  67872 	65: {
  67873 		Fcode:       int8(12),
  67874 		Fextra_bits: int8(5),
  67875 	},
  67876 	66: {
  67877 		Fcode:       int8(12),
  67878 		Fextra_bits: int8(5),
  67879 	},
  67880 	67: {
  67881 		Fcode:       int8(12),
  67882 		Fextra_bits: int8(5),
  67883 	},
  67884 	68: {
  67885 		Fcode:       int8(12),
  67886 		Fextra_bits: int8(5),
  67887 	},
  67888 	69: {
  67889 		Fcode:       int8(12),
  67890 		Fextra_bits: int8(5),
  67891 	},
  67892 	70: {
  67893 		Fcode:       int8(12),
  67894 		Fextra_bits: int8(5),
  67895 	},
  67896 	71: {
  67897 		Fcode:       int8(12),
  67898 		Fextra_bits: int8(5),
  67899 	},
  67900 	72: {
  67901 		Fcode:       int8(12),
  67902 		Fextra_bits: int8(5),
  67903 	},
  67904 	73: {
  67905 		Fcode:       int8(12),
  67906 		Fextra_bits: int8(5),
  67907 	},
  67908 	74: {
  67909 		Fcode:       int8(12),
  67910 		Fextra_bits: int8(5),
  67911 	},
  67912 	75: {
  67913 		Fcode:       int8(12),
  67914 		Fextra_bits: int8(5),
  67915 	},
  67916 	76: {
  67917 		Fcode:       int8(12),
  67918 		Fextra_bits: int8(5),
  67919 	},
  67920 	77: {
  67921 		Fcode:       int8(12),
  67922 		Fextra_bits: int8(5),
  67923 	},
  67924 	78: {
  67925 		Fcode:       int8(12),
  67926 		Fextra_bits: int8(5),
  67927 	},
  67928 	79: {
  67929 		Fcode:       int8(12),
  67930 		Fextra_bits: int8(5),
  67931 	},
  67932 	80: {
  67933 		Fcode:       int8(12),
  67934 		Fextra_bits: int8(5),
  67935 	},
  67936 	81: {
  67937 		Fcode:       int8(12),
  67938 		Fextra_bits: int8(5),
  67939 	},
  67940 	82: {
  67941 		Fcode:       int8(12),
  67942 		Fextra_bits: int8(5),
  67943 	},
  67944 	83: {
  67945 		Fcode:       int8(12),
  67946 		Fextra_bits: int8(5),
  67947 	},
  67948 	84: {
  67949 		Fcode:       int8(12),
  67950 		Fextra_bits: int8(5),
  67951 	},
  67952 	85: {
  67953 		Fcode:       int8(12),
  67954 		Fextra_bits: int8(5),
  67955 	},
  67956 	86: {
  67957 		Fcode:       int8(12),
  67958 		Fextra_bits: int8(5),
  67959 	},
  67960 	87: {
  67961 		Fcode:       int8(12),
  67962 		Fextra_bits: int8(5),
  67963 	},
  67964 	88: {
  67965 		Fcode:       int8(12),
  67966 		Fextra_bits: int8(5),
  67967 	},
  67968 	89: {
  67969 		Fcode:       int8(12),
  67970 		Fextra_bits: int8(5),
  67971 	},
  67972 	90: {
  67973 		Fcode:       int8(12),
  67974 		Fextra_bits: int8(5),
  67975 	},
  67976 	91: {
  67977 		Fcode:       int8(12),
  67978 		Fextra_bits: int8(5),
  67979 	},
  67980 	92: {
  67981 		Fcode:       int8(12),
  67982 		Fextra_bits: int8(5),
  67983 	},
  67984 	93: {
  67985 		Fcode:       int8(12),
  67986 		Fextra_bits: int8(5),
  67987 	},
  67988 	94: {
  67989 		Fcode:       int8(12),
  67990 		Fextra_bits: int8(5),
  67991 	},
  67992 	95: {
  67993 		Fcode:       int8(12),
  67994 		Fextra_bits: int8(5),
  67995 	},
  67996 	96: {
  67997 		Fcode:       int8(12),
  67998 		Fextra_bits: int8(5),
  67999 	},
  68000 	97: {
  68001 		Fcode:       int8(13),
  68002 		Fextra_bits: int8(5),
  68003 	},
  68004 	98: {
  68005 		Fcode:       int8(13),
  68006 		Fextra_bits: int8(5),
  68007 	},
  68008 	99: {
  68009 		Fcode:       int8(13),
  68010 		Fextra_bits: int8(5),
  68011 	},
  68012 	100: {
  68013 		Fcode:       int8(13),
  68014 		Fextra_bits: int8(5),
  68015 	},
  68016 	101: {
  68017 		Fcode:       int8(13),
  68018 		Fextra_bits: int8(5),
  68019 	},
  68020 	102: {
  68021 		Fcode:       int8(13),
  68022 		Fextra_bits: int8(5),
  68023 	},
  68024 	103: {
  68025 		Fcode:       int8(13),
  68026 		Fextra_bits: int8(5),
  68027 	},
  68028 	104: {
  68029 		Fcode:       int8(13),
  68030 		Fextra_bits: int8(5),
  68031 	},
  68032 	105: {
  68033 		Fcode:       int8(13),
  68034 		Fextra_bits: int8(5),
  68035 	},
  68036 	106: {
  68037 		Fcode:       int8(13),
  68038 		Fextra_bits: int8(5),
  68039 	},
  68040 	107: {
  68041 		Fcode:       int8(13),
  68042 		Fextra_bits: int8(5),
  68043 	},
  68044 	108: {
  68045 		Fcode:       int8(13),
  68046 		Fextra_bits: int8(5),
  68047 	},
  68048 	109: {
  68049 		Fcode:       int8(13),
  68050 		Fextra_bits: int8(5),
  68051 	},
  68052 	110: {
  68053 		Fcode:       int8(13),
  68054 		Fextra_bits: int8(5),
  68055 	},
  68056 	111: {
  68057 		Fcode:       int8(13),
  68058 		Fextra_bits: int8(5),
  68059 	},
  68060 	112: {
  68061 		Fcode:       int8(13),
  68062 		Fextra_bits: int8(5),
  68063 	},
  68064 	113: {
  68065 		Fcode:       int8(13),
  68066 		Fextra_bits: int8(5),
  68067 	},
  68068 	114: {
  68069 		Fcode:       int8(13),
  68070 		Fextra_bits: int8(5),
  68071 	},
  68072 	115: {
  68073 		Fcode:       int8(13),
  68074 		Fextra_bits: int8(5),
  68075 	},
  68076 	116: {
  68077 		Fcode:       int8(13),
  68078 		Fextra_bits: int8(5),
  68079 	},
  68080 	117: {
  68081 		Fcode:       int8(13),
  68082 		Fextra_bits: int8(5),
  68083 	},
  68084 	118: {
  68085 		Fcode:       int8(13),
  68086 		Fextra_bits: int8(5),
  68087 	},
  68088 	119: {
  68089 		Fcode:       int8(13),
  68090 		Fextra_bits: int8(5),
  68091 	},
  68092 	120: {
  68093 		Fcode:       int8(13),
  68094 		Fextra_bits: int8(5),
  68095 	},
  68096 	121: {
  68097 		Fcode:       int8(13),
  68098 		Fextra_bits: int8(5),
  68099 	},
  68100 	122: {
  68101 		Fcode:       int8(13),
  68102 		Fextra_bits: int8(5),
  68103 	},
  68104 	123: {
  68105 		Fcode:       int8(13),
  68106 		Fextra_bits: int8(5),
  68107 	},
  68108 	124: {
  68109 		Fcode:       int8(13),
  68110 		Fextra_bits: int8(5),
  68111 	},
  68112 	125: {
  68113 		Fcode:       int8(13),
  68114 		Fextra_bits: int8(5),
  68115 	},
  68116 	126: {
  68117 		Fcode:       int8(13),
  68118 		Fextra_bits: int8(5),
  68119 	},
  68120 	127: {
  68121 		Fcode:       int8(13),
  68122 		Fextra_bits: int8(5),
  68123 	},
  68124 	128: {
  68125 		Fcode:       int8(13),
  68126 		Fextra_bits: int8(5),
  68127 	},
  68128 	129: {
  68129 		Fcode:       int8(14),
  68130 		Fextra_bits: int8(6),
  68131 	},
  68132 	130: {
  68133 		Fcode:       int8(14),
  68134 		Fextra_bits: int8(6),
  68135 	},
  68136 	131: {
  68137 		Fcode:       int8(14),
  68138 		Fextra_bits: int8(6),
  68139 	},
  68140 	132: {
  68141 		Fcode:       int8(14),
  68142 		Fextra_bits: int8(6),
  68143 	},
  68144 	133: {
  68145 		Fcode:       int8(14),
  68146 		Fextra_bits: int8(6),
  68147 	},
  68148 	134: {
  68149 		Fcode:       int8(14),
  68150 		Fextra_bits: int8(6),
  68151 	},
  68152 	135: {
  68153 		Fcode:       int8(14),
  68154 		Fextra_bits: int8(6),
  68155 	},
  68156 	136: {
  68157 		Fcode:       int8(14),
  68158 		Fextra_bits: int8(6),
  68159 	},
  68160 	137: {
  68161 		Fcode:       int8(14),
  68162 		Fextra_bits: int8(6),
  68163 	},
  68164 	138: {
  68165 		Fcode:       int8(14),
  68166 		Fextra_bits: int8(6),
  68167 	},
  68168 	139: {
  68169 		Fcode:       int8(14),
  68170 		Fextra_bits: int8(6),
  68171 	},
  68172 	140: {
  68173 		Fcode:       int8(14),
  68174 		Fextra_bits: int8(6),
  68175 	},
  68176 	141: {
  68177 		Fcode:       int8(14),
  68178 		Fextra_bits: int8(6),
  68179 	},
  68180 	142: {
  68181 		Fcode:       int8(14),
  68182 		Fextra_bits: int8(6),
  68183 	},
  68184 	143: {
  68185 		Fcode:       int8(14),
  68186 		Fextra_bits: int8(6),
  68187 	},
  68188 	144: {
  68189 		Fcode:       int8(14),
  68190 		Fextra_bits: int8(6),
  68191 	},
  68192 	145: {
  68193 		Fcode:       int8(14),
  68194 		Fextra_bits: int8(6),
  68195 	},
  68196 	146: {
  68197 		Fcode:       int8(14),
  68198 		Fextra_bits: int8(6),
  68199 	},
  68200 	147: {
  68201 		Fcode:       int8(14),
  68202 		Fextra_bits: int8(6),
  68203 	},
  68204 	148: {
  68205 		Fcode:       int8(14),
  68206 		Fextra_bits: int8(6),
  68207 	},
  68208 	149: {
  68209 		Fcode:       int8(14),
  68210 		Fextra_bits: int8(6),
  68211 	},
  68212 	150: {
  68213 		Fcode:       int8(14),
  68214 		Fextra_bits: int8(6),
  68215 	},
  68216 	151: {
  68217 		Fcode:       int8(14),
  68218 		Fextra_bits: int8(6),
  68219 	},
  68220 	152: {
  68221 		Fcode:       int8(14),
  68222 		Fextra_bits: int8(6),
  68223 	},
  68224 	153: {
  68225 		Fcode:       int8(14),
  68226 		Fextra_bits: int8(6),
  68227 	},
  68228 	154: {
  68229 		Fcode:       int8(14),
  68230 		Fextra_bits: int8(6),
  68231 	},
  68232 	155: {
  68233 		Fcode:       int8(14),
  68234 		Fextra_bits: int8(6),
  68235 	},
  68236 	156: {
  68237 		Fcode:       int8(14),
  68238 		Fextra_bits: int8(6),
  68239 	},
  68240 	157: {
  68241 		Fcode:       int8(14),
  68242 		Fextra_bits: int8(6),
  68243 	},
  68244 	158: {
  68245 		Fcode:       int8(14),
  68246 		Fextra_bits: int8(6),
  68247 	},
  68248 	159: {
  68249 		Fcode:       int8(14),
  68250 		Fextra_bits: int8(6),
  68251 	},
  68252 	160: {
  68253 		Fcode:       int8(14),
  68254 		Fextra_bits: int8(6),
  68255 	},
  68256 	161: {
  68257 		Fcode:       int8(14),
  68258 		Fextra_bits: int8(6),
  68259 	},
  68260 	162: {
  68261 		Fcode:       int8(14),
  68262 		Fextra_bits: int8(6),
  68263 	},
  68264 	163: {
  68265 		Fcode:       int8(14),
  68266 		Fextra_bits: int8(6),
  68267 	},
  68268 	164: {
  68269 		Fcode:       int8(14),
  68270 		Fextra_bits: int8(6),
  68271 	},
  68272 	165: {
  68273 		Fcode:       int8(14),
  68274 		Fextra_bits: int8(6),
  68275 	},
  68276 	166: {
  68277 		Fcode:       int8(14),
  68278 		Fextra_bits: int8(6),
  68279 	},
  68280 	167: {
  68281 		Fcode:       int8(14),
  68282 		Fextra_bits: int8(6),
  68283 	},
  68284 	168: {
  68285 		Fcode:       int8(14),
  68286 		Fextra_bits: int8(6),
  68287 	},
  68288 	169: {
  68289 		Fcode:       int8(14),
  68290 		Fextra_bits: int8(6),
  68291 	},
  68292 	170: {
  68293 		Fcode:       int8(14),
  68294 		Fextra_bits: int8(6),
  68295 	},
  68296 	171: {
  68297 		Fcode:       int8(14),
  68298 		Fextra_bits: int8(6),
  68299 	},
  68300 	172: {
  68301 		Fcode:       int8(14),
  68302 		Fextra_bits: int8(6),
  68303 	},
  68304 	173: {
  68305 		Fcode:       int8(14),
  68306 		Fextra_bits: int8(6),
  68307 	},
  68308 	174: {
  68309 		Fcode:       int8(14),
  68310 		Fextra_bits: int8(6),
  68311 	},
  68312 	175: {
  68313 		Fcode:       int8(14),
  68314 		Fextra_bits: int8(6),
  68315 	},
  68316 	176: {
  68317 		Fcode:       int8(14),
  68318 		Fextra_bits: int8(6),
  68319 	},
  68320 	177: {
  68321 		Fcode:       int8(14),
  68322 		Fextra_bits: int8(6),
  68323 	},
  68324 	178: {
  68325 		Fcode:       int8(14),
  68326 		Fextra_bits: int8(6),
  68327 	},
  68328 	179: {
  68329 		Fcode:       int8(14),
  68330 		Fextra_bits: int8(6),
  68331 	},
  68332 	180: {
  68333 		Fcode:       int8(14),
  68334 		Fextra_bits: int8(6),
  68335 	},
  68336 	181: {
  68337 		Fcode:       int8(14),
  68338 		Fextra_bits: int8(6),
  68339 	},
  68340 	182: {
  68341 		Fcode:       int8(14),
  68342 		Fextra_bits: int8(6),
  68343 	},
  68344 	183: {
  68345 		Fcode:       int8(14),
  68346 		Fextra_bits: int8(6),
  68347 	},
  68348 	184: {
  68349 		Fcode:       int8(14),
  68350 		Fextra_bits: int8(6),
  68351 	},
  68352 	185: {
  68353 		Fcode:       int8(14),
  68354 		Fextra_bits: int8(6),
  68355 	},
  68356 	186: {
  68357 		Fcode:       int8(14),
  68358 		Fextra_bits: int8(6),
  68359 	},
  68360 	187: {
  68361 		Fcode:       int8(14),
  68362 		Fextra_bits: int8(6),
  68363 	},
  68364 	188: {
  68365 		Fcode:       int8(14),
  68366 		Fextra_bits: int8(6),
  68367 	},
  68368 	189: {
  68369 		Fcode:       int8(14),
  68370 		Fextra_bits: int8(6),
  68371 	},
  68372 	190: {
  68373 		Fcode:       int8(14),
  68374 		Fextra_bits: int8(6),
  68375 	},
  68376 	191: {
  68377 		Fcode:       int8(14),
  68378 		Fextra_bits: int8(6),
  68379 	},
  68380 	192: {
  68381 		Fcode:       int8(14),
  68382 		Fextra_bits: int8(6),
  68383 	},
  68384 	193: {
  68385 		Fcode:       int8(15),
  68386 		Fextra_bits: int8(6),
  68387 	},
  68388 	194: {
  68389 		Fcode:       int8(15),
  68390 		Fextra_bits: int8(6),
  68391 	},
  68392 	195: {
  68393 		Fcode:       int8(15),
  68394 		Fextra_bits: int8(6),
  68395 	},
  68396 	196: {
  68397 		Fcode:       int8(15),
  68398 		Fextra_bits: int8(6),
  68399 	},
  68400 	197: {
  68401 		Fcode:       int8(15),
  68402 		Fextra_bits: int8(6),
  68403 	},
  68404 	198: {
  68405 		Fcode:       int8(15),
  68406 		Fextra_bits: int8(6),
  68407 	},
  68408 	199: {
  68409 		Fcode:       int8(15),
  68410 		Fextra_bits: int8(6),
  68411 	},
  68412 	200: {
  68413 		Fcode:       int8(15),
  68414 		Fextra_bits: int8(6),
  68415 	},
  68416 	201: {
  68417 		Fcode:       int8(15),
  68418 		Fextra_bits: int8(6),
  68419 	},
  68420 	202: {
  68421 		Fcode:       int8(15),
  68422 		Fextra_bits: int8(6),
  68423 	},
  68424 	203: {
  68425 		Fcode:       int8(15),
  68426 		Fextra_bits: int8(6),
  68427 	},
  68428 	204: {
  68429 		Fcode:       int8(15),
  68430 		Fextra_bits: int8(6),
  68431 	},
  68432 	205: {
  68433 		Fcode:       int8(15),
  68434 		Fextra_bits: int8(6),
  68435 	},
  68436 	206: {
  68437 		Fcode:       int8(15),
  68438 		Fextra_bits: int8(6),
  68439 	},
  68440 	207: {
  68441 		Fcode:       int8(15),
  68442 		Fextra_bits: int8(6),
  68443 	},
  68444 	208: {
  68445 		Fcode:       int8(15),
  68446 		Fextra_bits: int8(6),
  68447 	},
  68448 	209: {
  68449 		Fcode:       int8(15),
  68450 		Fextra_bits: int8(6),
  68451 	},
  68452 	210: {
  68453 		Fcode:       int8(15),
  68454 		Fextra_bits: int8(6),
  68455 	},
  68456 	211: {
  68457 		Fcode:       int8(15),
  68458 		Fextra_bits: int8(6),
  68459 	},
  68460 	212: {
  68461 		Fcode:       int8(15),
  68462 		Fextra_bits: int8(6),
  68463 	},
  68464 	213: {
  68465 		Fcode:       int8(15),
  68466 		Fextra_bits: int8(6),
  68467 	},
  68468 	214: {
  68469 		Fcode:       int8(15),
  68470 		Fextra_bits: int8(6),
  68471 	},
  68472 	215: {
  68473 		Fcode:       int8(15),
  68474 		Fextra_bits: int8(6),
  68475 	},
  68476 	216: {
  68477 		Fcode:       int8(15),
  68478 		Fextra_bits: int8(6),
  68479 	},
  68480 	217: {
  68481 		Fcode:       int8(15),
  68482 		Fextra_bits: int8(6),
  68483 	},
  68484 	218: {
  68485 		Fcode:       int8(15),
  68486 		Fextra_bits: int8(6),
  68487 	},
  68488 	219: {
  68489 		Fcode:       int8(15),
  68490 		Fextra_bits: int8(6),
  68491 	},
  68492 	220: {
  68493 		Fcode:       int8(15),
  68494 		Fextra_bits: int8(6),
  68495 	},
  68496 	221: {
  68497 		Fcode:       int8(15),
  68498 		Fextra_bits: int8(6),
  68499 	},
  68500 	222: {
  68501 		Fcode:       int8(15),
  68502 		Fextra_bits: int8(6),
  68503 	},
  68504 	223: {
  68505 		Fcode:       int8(15),
  68506 		Fextra_bits: int8(6),
  68507 	},
  68508 	224: {
  68509 		Fcode:       int8(15),
  68510 		Fextra_bits: int8(6),
  68511 	},
  68512 	225: {
  68513 		Fcode:       int8(15),
  68514 		Fextra_bits: int8(6),
  68515 	},
  68516 	226: {
  68517 		Fcode:       int8(15),
  68518 		Fextra_bits: int8(6),
  68519 	},
  68520 	227: {
  68521 		Fcode:       int8(15),
  68522 		Fextra_bits: int8(6),
  68523 	},
  68524 	228: {
  68525 		Fcode:       int8(15),
  68526 		Fextra_bits: int8(6),
  68527 	},
  68528 	229: {
  68529 		Fcode:       int8(15),
  68530 		Fextra_bits: int8(6),
  68531 	},
  68532 	230: {
  68533 		Fcode:       int8(15),
  68534 		Fextra_bits: int8(6),
  68535 	},
  68536 	231: {
  68537 		Fcode:       int8(15),
  68538 		Fextra_bits: int8(6),
  68539 	},
  68540 	232: {
  68541 		Fcode:       int8(15),
  68542 		Fextra_bits: int8(6),
  68543 	},
  68544 	233: {
  68545 		Fcode:       int8(15),
  68546 		Fextra_bits: int8(6),
  68547 	},
  68548 	234: {
  68549 		Fcode:       int8(15),
  68550 		Fextra_bits: int8(6),
  68551 	},
  68552 	235: {
  68553 		Fcode:       int8(15),
  68554 		Fextra_bits: int8(6),
  68555 	},
  68556 	236: {
  68557 		Fcode:       int8(15),
  68558 		Fextra_bits: int8(6),
  68559 	},
  68560 	237: {
  68561 		Fcode:       int8(15),
  68562 		Fextra_bits: int8(6),
  68563 	},
  68564 	238: {
  68565 		Fcode:       int8(15),
  68566 		Fextra_bits: int8(6),
  68567 	},
  68568 	239: {
  68569 		Fcode:       int8(15),
  68570 		Fextra_bits: int8(6),
  68571 	},
  68572 	240: {
  68573 		Fcode:       int8(15),
  68574 		Fextra_bits: int8(6),
  68575 	},
  68576 	241: {
  68577 		Fcode:       int8(15),
  68578 		Fextra_bits: int8(6),
  68579 	},
  68580 	242: {
  68581 		Fcode:       int8(15),
  68582 		Fextra_bits: int8(6),
  68583 	},
  68584 	243: {
  68585 		Fcode:       int8(15),
  68586 		Fextra_bits: int8(6),
  68587 	},
  68588 	244: {
  68589 		Fcode:       int8(15),
  68590 		Fextra_bits: int8(6),
  68591 	},
  68592 	245: {
  68593 		Fcode:       int8(15),
  68594 		Fextra_bits: int8(6),
  68595 	},
  68596 	246: {
  68597 		Fcode:       int8(15),
  68598 		Fextra_bits: int8(6),
  68599 	},
  68600 	247: {
  68601 		Fcode:       int8(15),
  68602 		Fextra_bits: int8(6),
  68603 	},
  68604 	248: {
  68605 		Fcode:       int8(15),
  68606 		Fextra_bits: int8(6),
  68607 	},
  68608 	249: {
  68609 		Fcode:       int8(15),
  68610 		Fextra_bits: int8(6),
  68611 	},
  68612 	250: {
  68613 		Fcode:       int8(15),
  68614 		Fextra_bits: int8(6),
  68615 	},
  68616 	251: {
  68617 		Fcode:       int8(15),
  68618 		Fextra_bits: int8(6),
  68619 	},
  68620 	252: {
  68621 		Fcode:       int8(15),
  68622 		Fextra_bits: int8(6),
  68623 	},
  68624 	253: {
  68625 		Fcode:       int8(15),
  68626 		Fextra_bits: int8(6),
  68627 	},
  68628 	254: {
  68629 		Fcode:       int8(15),
  68630 		Fextra_bits: int8(6),
  68631 	},
  68632 	255: {
  68633 		Fcode:       int8(15),
  68634 		Fextra_bits: int8(6),
  68635 	},
  68636 	256: {
  68637 		Fcode:       int8(15),
  68638 		Fextra_bits: int8(6),
  68639 	},
  68640 	257: {
  68641 		Fcode:       int8(16),
  68642 		Fextra_bits: int8(7),
  68643 	},
  68644 	258: {
  68645 		Fcode:       int8(16),
  68646 		Fextra_bits: int8(7),
  68647 	},
  68648 	259: {
  68649 		Fcode:       int8(16),
  68650 		Fextra_bits: int8(7),
  68651 	},
  68652 	260: {
  68653 		Fcode:       int8(16),
  68654 		Fextra_bits: int8(7),
  68655 	},
  68656 	261: {
  68657 		Fcode:       int8(16),
  68658 		Fextra_bits: int8(7),
  68659 	},
  68660 	262: {
  68661 		Fcode:       int8(16),
  68662 		Fextra_bits: int8(7),
  68663 	},
  68664 	263: {
  68665 		Fcode:       int8(16),
  68666 		Fextra_bits: int8(7),
  68667 	},
  68668 	264: {
  68669 		Fcode:       int8(16),
  68670 		Fextra_bits: int8(7),
  68671 	},
  68672 	265: {
  68673 		Fcode:       int8(16),
  68674 		Fextra_bits: int8(7),
  68675 	},
  68676 	266: {
  68677 		Fcode:       int8(16),
  68678 		Fextra_bits: int8(7),
  68679 	},
  68680 	267: {
  68681 		Fcode:       int8(16),
  68682 		Fextra_bits: int8(7),
  68683 	},
  68684 	268: {
  68685 		Fcode:       int8(16),
  68686 		Fextra_bits: int8(7),
  68687 	},
  68688 	269: {
  68689 		Fcode:       int8(16),
  68690 		Fextra_bits: int8(7),
  68691 	},
  68692 	270: {
  68693 		Fcode:       int8(16),
  68694 		Fextra_bits: int8(7),
  68695 	},
  68696 	271: {
  68697 		Fcode:       int8(16),
  68698 		Fextra_bits: int8(7),
  68699 	},
  68700 	272: {
  68701 		Fcode:       int8(16),
  68702 		Fextra_bits: int8(7),
  68703 	},
  68704 	273: {
  68705 		Fcode:       int8(16),
  68706 		Fextra_bits: int8(7),
  68707 	},
  68708 	274: {
  68709 		Fcode:       int8(16),
  68710 		Fextra_bits: int8(7),
  68711 	},
  68712 	275: {
  68713 		Fcode:       int8(16),
  68714 		Fextra_bits: int8(7),
  68715 	},
  68716 	276: {
  68717 		Fcode:       int8(16),
  68718 		Fextra_bits: int8(7),
  68719 	},
  68720 	277: {
  68721 		Fcode:       int8(16),
  68722 		Fextra_bits: int8(7),
  68723 	},
  68724 	278: {
  68725 		Fcode:       int8(16),
  68726 		Fextra_bits: int8(7),
  68727 	},
  68728 	279: {
  68729 		Fcode:       int8(16),
  68730 		Fextra_bits: int8(7),
  68731 	},
  68732 	280: {
  68733 		Fcode:       int8(16),
  68734 		Fextra_bits: int8(7),
  68735 	},
  68736 	281: {
  68737 		Fcode:       int8(16),
  68738 		Fextra_bits: int8(7),
  68739 	},
  68740 	282: {
  68741 		Fcode:       int8(16),
  68742 		Fextra_bits: int8(7),
  68743 	},
  68744 	283: {
  68745 		Fcode:       int8(16),
  68746 		Fextra_bits: int8(7),
  68747 	},
  68748 	284: {
  68749 		Fcode:       int8(16),
  68750 		Fextra_bits: int8(7),
  68751 	},
  68752 	285: {
  68753 		Fcode:       int8(16),
  68754 		Fextra_bits: int8(7),
  68755 	},
  68756 	286: {
  68757 		Fcode:       int8(16),
  68758 		Fextra_bits: int8(7),
  68759 	},
  68760 	287: {
  68761 		Fcode:       int8(16),
  68762 		Fextra_bits: int8(7),
  68763 	},
  68764 	288: {
  68765 		Fcode:       int8(16),
  68766 		Fextra_bits: int8(7),
  68767 	},
  68768 	289: {
  68769 		Fcode:       int8(16),
  68770 		Fextra_bits: int8(7),
  68771 	},
  68772 	290: {
  68773 		Fcode:       int8(16),
  68774 		Fextra_bits: int8(7),
  68775 	},
  68776 	291: {
  68777 		Fcode:       int8(16),
  68778 		Fextra_bits: int8(7),
  68779 	},
  68780 	292: {
  68781 		Fcode:       int8(16),
  68782 		Fextra_bits: int8(7),
  68783 	},
  68784 	293: {
  68785 		Fcode:       int8(16),
  68786 		Fextra_bits: int8(7),
  68787 	},
  68788 	294: {
  68789 		Fcode:       int8(16),
  68790 		Fextra_bits: int8(7),
  68791 	},
  68792 	295: {
  68793 		Fcode:       int8(16),
  68794 		Fextra_bits: int8(7),
  68795 	},
  68796 	296: {
  68797 		Fcode:       int8(16),
  68798 		Fextra_bits: int8(7),
  68799 	},
  68800 	297: {
  68801 		Fcode:       int8(16),
  68802 		Fextra_bits: int8(7),
  68803 	},
  68804 	298: {
  68805 		Fcode:       int8(16),
  68806 		Fextra_bits: int8(7),
  68807 	},
  68808 	299: {
  68809 		Fcode:       int8(16),
  68810 		Fextra_bits: int8(7),
  68811 	},
  68812 	300: {
  68813 		Fcode:       int8(16),
  68814 		Fextra_bits: int8(7),
  68815 	},
  68816 	301: {
  68817 		Fcode:       int8(16),
  68818 		Fextra_bits: int8(7),
  68819 	},
  68820 	302: {
  68821 		Fcode:       int8(16),
  68822 		Fextra_bits: int8(7),
  68823 	},
  68824 	303: {
  68825 		Fcode:       int8(16),
  68826 		Fextra_bits: int8(7),
  68827 	},
  68828 	304: {
  68829 		Fcode:       int8(16),
  68830 		Fextra_bits: int8(7),
  68831 	},
  68832 	305: {
  68833 		Fcode:       int8(16),
  68834 		Fextra_bits: int8(7),
  68835 	},
  68836 	306: {
  68837 		Fcode:       int8(16),
  68838 		Fextra_bits: int8(7),
  68839 	},
  68840 	307: {
  68841 		Fcode:       int8(16),
  68842 		Fextra_bits: int8(7),
  68843 	},
  68844 	308: {
  68845 		Fcode:       int8(16),
  68846 		Fextra_bits: int8(7),
  68847 	},
  68848 	309: {
  68849 		Fcode:       int8(16),
  68850 		Fextra_bits: int8(7),
  68851 	},
  68852 	310: {
  68853 		Fcode:       int8(16),
  68854 		Fextra_bits: int8(7),
  68855 	},
  68856 	311: {
  68857 		Fcode:       int8(16),
  68858 		Fextra_bits: int8(7),
  68859 	},
  68860 	312: {
  68861 		Fcode:       int8(16),
  68862 		Fextra_bits: int8(7),
  68863 	},
  68864 	313: {
  68865 		Fcode:       int8(16),
  68866 		Fextra_bits: int8(7),
  68867 	},
  68868 	314: {
  68869 		Fcode:       int8(16),
  68870 		Fextra_bits: int8(7),
  68871 	},
  68872 	315: {
  68873 		Fcode:       int8(16),
  68874 		Fextra_bits: int8(7),
  68875 	},
  68876 	316: {
  68877 		Fcode:       int8(16),
  68878 		Fextra_bits: int8(7),
  68879 	},
  68880 	317: {
  68881 		Fcode:       int8(16),
  68882 		Fextra_bits: int8(7),
  68883 	},
  68884 	318: {
  68885 		Fcode:       int8(16),
  68886 		Fextra_bits: int8(7),
  68887 	},
  68888 	319: {
  68889 		Fcode:       int8(16),
  68890 		Fextra_bits: int8(7),
  68891 	},
  68892 	320: {
  68893 		Fcode:       int8(16),
  68894 		Fextra_bits: int8(7),
  68895 	},
  68896 	321: {
  68897 		Fcode:       int8(16),
  68898 		Fextra_bits: int8(7),
  68899 	},
  68900 	322: {
  68901 		Fcode:       int8(16),
  68902 		Fextra_bits: int8(7),
  68903 	},
  68904 	323: {
  68905 		Fcode:       int8(16),
  68906 		Fextra_bits: int8(7),
  68907 	},
  68908 	324: {
  68909 		Fcode:       int8(16),
  68910 		Fextra_bits: int8(7),
  68911 	},
  68912 	325: {
  68913 		Fcode:       int8(16),
  68914 		Fextra_bits: int8(7),
  68915 	},
  68916 	326: {
  68917 		Fcode:       int8(16),
  68918 		Fextra_bits: int8(7),
  68919 	},
  68920 	327: {
  68921 		Fcode:       int8(16),
  68922 		Fextra_bits: int8(7),
  68923 	},
  68924 	328: {
  68925 		Fcode:       int8(16),
  68926 		Fextra_bits: int8(7),
  68927 	},
  68928 	329: {
  68929 		Fcode:       int8(16),
  68930 		Fextra_bits: int8(7),
  68931 	},
  68932 	330: {
  68933 		Fcode:       int8(16),
  68934 		Fextra_bits: int8(7),
  68935 	},
  68936 	331: {
  68937 		Fcode:       int8(16),
  68938 		Fextra_bits: int8(7),
  68939 	},
  68940 	332: {
  68941 		Fcode:       int8(16),
  68942 		Fextra_bits: int8(7),
  68943 	},
  68944 	333: {
  68945 		Fcode:       int8(16),
  68946 		Fextra_bits: int8(7),
  68947 	},
  68948 	334: {
  68949 		Fcode:       int8(16),
  68950 		Fextra_bits: int8(7),
  68951 	},
  68952 	335: {
  68953 		Fcode:       int8(16),
  68954 		Fextra_bits: int8(7),
  68955 	},
  68956 	336: {
  68957 		Fcode:       int8(16),
  68958 		Fextra_bits: int8(7),
  68959 	},
  68960 	337: {
  68961 		Fcode:       int8(16),
  68962 		Fextra_bits: int8(7),
  68963 	},
  68964 	338: {
  68965 		Fcode:       int8(16),
  68966 		Fextra_bits: int8(7),
  68967 	},
  68968 	339: {
  68969 		Fcode:       int8(16),
  68970 		Fextra_bits: int8(7),
  68971 	},
  68972 	340: {
  68973 		Fcode:       int8(16),
  68974 		Fextra_bits: int8(7),
  68975 	},
  68976 	341: {
  68977 		Fcode:       int8(16),
  68978 		Fextra_bits: int8(7),
  68979 	},
  68980 	342: {
  68981 		Fcode:       int8(16),
  68982 		Fextra_bits: int8(7),
  68983 	},
  68984 	343: {
  68985 		Fcode:       int8(16),
  68986 		Fextra_bits: int8(7),
  68987 	},
  68988 	344: {
  68989 		Fcode:       int8(16),
  68990 		Fextra_bits: int8(7),
  68991 	},
  68992 	345: {
  68993 		Fcode:       int8(16),
  68994 		Fextra_bits: int8(7),
  68995 	},
  68996 	346: {
  68997 		Fcode:       int8(16),
  68998 		Fextra_bits: int8(7),
  68999 	},
  69000 	347: {
  69001 		Fcode:       int8(16),
  69002 		Fextra_bits: int8(7),
  69003 	},
  69004 	348: {
  69005 		Fcode:       int8(16),
  69006 		Fextra_bits: int8(7),
  69007 	},
  69008 	349: {
  69009 		Fcode:       int8(16),
  69010 		Fextra_bits: int8(7),
  69011 	},
  69012 	350: {
  69013 		Fcode:       int8(16),
  69014 		Fextra_bits: int8(7),
  69015 	},
  69016 	351: {
  69017 		Fcode:       int8(16),
  69018 		Fextra_bits: int8(7),
  69019 	},
  69020 	352: {
  69021 		Fcode:       int8(16),
  69022 		Fextra_bits: int8(7),
  69023 	},
  69024 	353: {
  69025 		Fcode:       int8(16),
  69026 		Fextra_bits: int8(7),
  69027 	},
  69028 	354: {
  69029 		Fcode:       int8(16),
  69030 		Fextra_bits: int8(7),
  69031 	},
  69032 	355: {
  69033 		Fcode:       int8(16),
  69034 		Fextra_bits: int8(7),
  69035 	},
  69036 	356: {
  69037 		Fcode:       int8(16),
  69038 		Fextra_bits: int8(7),
  69039 	},
  69040 	357: {
  69041 		Fcode:       int8(16),
  69042 		Fextra_bits: int8(7),
  69043 	},
  69044 	358: {
  69045 		Fcode:       int8(16),
  69046 		Fextra_bits: int8(7),
  69047 	},
  69048 	359: {
  69049 		Fcode:       int8(16),
  69050 		Fextra_bits: int8(7),
  69051 	},
  69052 	360: {
  69053 		Fcode:       int8(16),
  69054 		Fextra_bits: int8(7),
  69055 	},
  69056 	361: {
  69057 		Fcode:       int8(16),
  69058 		Fextra_bits: int8(7),
  69059 	},
  69060 	362: {
  69061 		Fcode:       int8(16),
  69062 		Fextra_bits: int8(7),
  69063 	},
  69064 	363: {
  69065 		Fcode:       int8(16),
  69066 		Fextra_bits: int8(7),
  69067 	},
  69068 	364: {
  69069 		Fcode:       int8(16),
  69070 		Fextra_bits: int8(7),
  69071 	},
  69072 	365: {
  69073 		Fcode:       int8(16),
  69074 		Fextra_bits: int8(7),
  69075 	},
  69076 	366: {
  69077 		Fcode:       int8(16),
  69078 		Fextra_bits: int8(7),
  69079 	},
  69080 	367: {
  69081 		Fcode:       int8(16),
  69082 		Fextra_bits: int8(7),
  69083 	},
  69084 	368: {
  69085 		Fcode:       int8(16),
  69086 		Fextra_bits: int8(7),
  69087 	},
  69088 	369: {
  69089 		Fcode:       int8(16),
  69090 		Fextra_bits: int8(7),
  69091 	},
  69092 	370: {
  69093 		Fcode:       int8(16),
  69094 		Fextra_bits: int8(7),
  69095 	},
  69096 	371: {
  69097 		Fcode:       int8(16),
  69098 		Fextra_bits: int8(7),
  69099 	},
  69100 	372: {
  69101 		Fcode:       int8(16),
  69102 		Fextra_bits: int8(7),
  69103 	},
  69104 	373: {
  69105 		Fcode:       int8(16),
  69106 		Fextra_bits: int8(7),
  69107 	},
  69108 	374: {
  69109 		Fcode:       int8(16),
  69110 		Fextra_bits: int8(7),
  69111 	},
  69112 	375: {
  69113 		Fcode:       int8(16),
  69114 		Fextra_bits: int8(7),
  69115 	},
  69116 	376: {
  69117 		Fcode:       int8(16),
  69118 		Fextra_bits: int8(7),
  69119 	},
  69120 	377: {
  69121 		Fcode:       int8(16),
  69122 		Fextra_bits: int8(7),
  69123 	},
  69124 	378: {
  69125 		Fcode:       int8(16),
  69126 		Fextra_bits: int8(7),
  69127 	},
  69128 	379: {
  69129 		Fcode:       int8(16),
  69130 		Fextra_bits: int8(7),
  69131 	},
  69132 	380: {
  69133 		Fcode:       int8(16),
  69134 		Fextra_bits: int8(7),
  69135 	},
  69136 	381: {
  69137 		Fcode:       int8(16),
  69138 		Fextra_bits: int8(7),
  69139 	},
  69140 	382: {
  69141 		Fcode:       int8(16),
  69142 		Fextra_bits: int8(7),
  69143 	},
  69144 	383: {
  69145 		Fcode:       int8(16),
  69146 		Fextra_bits: int8(7),
  69147 	},
  69148 	384: {
  69149 		Fcode:       int8(16),
  69150 		Fextra_bits: int8(7),
  69151 	},
  69152 	385: {
  69153 		Fcode:       int8(17),
  69154 		Fextra_bits: int8(7),
  69155 	},
  69156 	386: {
  69157 		Fcode:       int8(17),
  69158 		Fextra_bits: int8(7),
  69159 	},
  69160 	387: {
  69161 		Fcode:       int8(17),
  69162 		Fextra_bits: int8(7),
  69163 	},
  69164 	388: {
  69165 		Fcode:       int8(17),
  69166 		Fextra_bits: int8(7),
  69167 	},
  69168 	389: {
  69169 		Fcode:       int8(17),
  69170 		Fextra_bits: int8(7),
  69171 	},
  69172 	390: {
  69173 		Fcode:       int8(17),
  69174 		Fextra_bits: int8(7),
  69175 	},
  69176 	391: {
  69177 		Fcode:       int8(17),
  69178 		Fextra_bits: int8(7),
  69179 	},
  69180 	392: {
  69181 		Fcode:       int8(17),
  69182 		Fextra_bits: int8(7),
  69183 	},
  69184 	393: {
  69185 		Fcode:       int8(17),
  69186 		Fextra_bits: int8(7),
  69187 	},
  69188 	394: {
  69189 		Fcode:       int8(17),
  69190 		Fextra_bits: int8(7),
  69191 	},
  69192 	395: {
  69193 		Fcode:       int8(17),
  69194 		Fextra_bits: int8(7),
  69195 	},
  69196 	396: {
  69197 		Fcode:       int8(17),
  69198 		Fextra_bits: int8(7),
  69199 	},
  69200 	397: {
  69201 		Fcode:       int8(17),
  69202 		Fextra_bits: int8(7),
  69203 	},
  69204 	398: {
  69205 		Fcode:       int8(17),
  69206 		Fextra_bits: int8(7),
  69207 	},
  69208 	399: {
  69209 		Fcode:       int8(17),
  69210 		Fextra_bits: int8(7),
  69211 	},
  69212 	400: {
  69213 		Fcode:       int8(17),
  69214 		Fextra_bits: int8(7),
  69215 	},
  69216 	401: {
  69217 		Fcode:       int8(17),
  69218 		Fextra_bits: int8(7),
  69219 	},
  69220 	402: {
  69221 		Fcode:       int8(17),
  69222 		Fextra_bits: int8(7),
  69223 	},
  69224 	403: {
  69225 		Fcode:       int8(17),
  69226 		Fextra_bits: int8(7),
  69227 	},
  69228 	404: {
  69229 		Fcode:       int8(17),
  69230 		Fextra_bits: int8(7),
  69231 	},
  69232 	405: {
  69233 		Fcode:       int8(17),
  69234 		Fextra_bits: int8(7),
  69235 	},
  69236 	406: {
  69237 		Fcode:       int8(17),
  69238 		Fextra_bits: int8(7),
  69239 	},
  69240 	407: {
  69241 		Fcode:       int8(17),
  69242 		Fextra_bits: int8(7),
  69243 	},
  69244 	408: {
  69245 		Fcode:       int8(17),
  69246 		Fextra_bits: int8(7),
  69247 	},
  69248 	409: {
  69249 		Fcode:       int8(17),
  69250 		Fextra_bits: int8(7),
  69251 	},
  69252 	410: {
  69253 		Fcode:       int8(17),
  69254 		Fextra_bits: int8(7),
  69255 	},
  69256 	411: {
  69257 		Fcode:       int8(17),
  69258 		Fextra_bits: int8(7),
  69259 	},
  69260 	412: {
  69261 		Fcode:       int8(17),
  69262 		Fextra_bits: int8(7),
  69263 	},
  69264 	413: {
  69265 		Fcode:       int8(17),
  69266 		Fextra_bits: int8(7),
  69267 	},
  69268 	414: {
  69269 		Fcode:       int8(17),
  69270 		Fextra_bits: int8(7),
  69271 	},
  69272 	415: {
  69273 		Fcode:       int8(17),
  69274 		Fextra_bits: int8(7),
  69275 	},
  69276 	416: {
  69277 		Fcode:       int8(17),
  69278 		Fextra_bits: int8(7),
  69279 	},
  69280 	417: {
  69281 		Fcode:       int8(17),
  69282 		Fextra_bits: int8(7),
  69283 	},
  69284 	418: {
  69285 		Fcode:       int8(17),
  69286 		Fextra_bits: int8(7),
  69287 	},
  69288 	419: {
  69289 		Fcode:       int8(17),
  69290 		Fextra_bits: int8(7),
  69291 	},
  69292 	420: {
  69293 		Fcode:       int8(17),
  69294 		Fextra_bits: int8(7),
  69295 	},
  69296 	421: {
  69297 		Fcode:       int8(17),
  69298 		Fextra_bits: int8(7),
  69299 	},
  69300 	422: {
  69301 		Fcode:       int8(17),
  69302 		Fextra_bits: int8(7),
  69303 	},
  69304 	423: {
  69305 		Fcode:       int8(17),
  69306 		Fextra_bits: int8(7),
  69307 	},
  69308 	424: {
  69309 		Fcode:       int8(17),
  69310 		Fextra_bits: int8(7),
  69311 	},
  69312 	425: {
  69313 		Fcode:       int8(17),
  69314 		Fextra_bits: int8(7),
  69315 	},
  69316 	426: {
  69317 		Fcode:       int8(17),
  69318 		Fextra_bits: int8(7),
  69319 	},
  69320 	427: {
  69321 		Fcode:       int8(17),
  69322 		Fextra_bits: int8(7),
  69323 	},
  69324 	428: {
  69325 		Fcode:       int8(17),
  69326 		Fextra_bits: int8(7),
  69327 	},
  69328 	429: {
  69329 		Fcode:       int8(17),
  69330 		Fextra_bits: int8(7),
  69331 	},
  69332 	430: {
  69333 		Fcode:       int8(17),
  69334 		Fextra_bits: int8(7),
  69335 	},
  69336 	431: {
  69337 		Fcode:       int8(17),
  69338 		Fextra_bits: int8(7),
  69339 	},
  69340 	432: {
  69341 		Fcode:       int8(17),
  69342 		Fextra_bits: int8(7),
  69343 	},
  69344 	433: {
  69345 		Fcode:       int8(17),
  69346 		Fextra_bits: int8(7),
  69347 	},
  69348 	434: {
  69349 		Fcode:       int8(17),
  69350 		Fextra_bits: int8(7),
  69351 	},
  69352 	435: {
  69353 		Fcode:       int8(17),
  69354 		Fextra_bits: int8(7),
  69355 	},
  69356 	436: {
  69357 		Fcode:       int8(17),
  69358 		Fextra_bits: int8(7),
  69359 	},
  69360 	437: {
  69361 		Fcode:       int8(17),
  69362 		Fextra_bits: int8(7),
  69363 	},
  69364 	438: {
  69365 		Fcode:       int8(17),
  69366 		Fextra_bits: int8(7),
  69367 	},
  69368 	439: {
  69369 		Fcode:       int8(17),
  69370 		Fextra_bits: int8(7),
  69371 	},
  69372 	440: {
  69373 		Fcode:       int8(17),
  69374 		Fextra_bits: int8(7),
  69375 	},
  69376 	441: {
  69377 		Fcode:       int8(17),
  69378 		Fextra_bits: int8(7),
  69379 	},
  69380 	442: {
  69381 		Fcode:       int8(17),
  69382 		Fextra_bits: int8(7),
  69383 	},
  69384 	443: {
  69385 		Fcode:       int8(17),
  69386 		Fextra_bits: int8(7),
  69387 	},
  69388 	444: {
  69389 		Fcode:       int8(17),
  69390 		Fextra_bits: int8(7),
  69391 	},
  69392 	445: {
  69393 		Fcode:       int8(17),
  69394 		Fextra_bits: int8(7),
  69395 	},
  69396 	446: {
  69397 		Fcode:       int8(17),
  69398 		Fextra_bits: int8(7),
  69399 	},
  69400 	447: {
  69401 		Fcode:       int8(17),
  69402 		Fextra_bits: int8(7),
  69403 	},
  69404 	448: {
  69405 		Fcode:       int8(17),
  69406 		Fextra_bits: int8(7),
  69407 	},
  69408 	449: {
  69409 		Fcode:       int8(17),
  69410 		Fextra_bits: int8(7),
  69411 	},
  69412 	450: {
  69413 		Fcode:       int8(17),
  69414 		Fextra_bits: int8(7),
  69415 	},
  69416 	451: {
  69417 		Fcode:       int8(17),
  69418 		Fextra_bits: int8(7),
  69419 	},
  69420 	452: {
  69421 		Fcode:       int8(17),
  69422 		Fextra_bits: int8(7),
  69423 	},
  69424 	453: {
  69425 		Fcode:       int8(17),
  69426 		Fextra_bits: int8(7),
  69427 	},
  69428 	454: {
  69429 		Fcode:       int8(17),
  69430 		Fextra_bits: int8(7),
  69431 	},
  69432 	455: {
  69433 		Fcode:       int8(17),
  69434 		Fextra_bits: int8(7),
  69435 	},
  69436 	456: {
  69437 		Fcode:       int8(17),
  69438 		Fextra_bits: int8(7),
  69439 	},
  69440 	457: {
  69441 		Fcode:       int8(17),
  69442 		Fextra_bits: int8(7),
  69443 	},
  69444 	458: {
  69445 		Fcode:       int8(17),
  69446 		Fextra_bits: int8(7),
  69447 	},
  69448 	459: {
  69449 		Fcode:       int8(17),
  69450 		Fextra_bits: int8(7),
  69451 	},
  69452 	460: {
  69453 		Fcode:       int8(17),
  69454 		Fextra_bits: int8(7),
  69455 	},
  69456 	461: {
  69457 		Fcode:       int8(17),
  69458 		Fextra_bits: int8(7),
  69459 	},
  69460 	462: {
  69461 		Fcode:       int8(17),
  69462 		Fextra_bits: int8(7),
  69463 	},
  69464 	463: {
  69465 		Fcode:       int8(17),
  69466 		Fextra_bits: int8(7),
  69467 	},
  69468 	464: {
  69469 		Fcode:       int8(17),
  69470 		Fextra_bits: int8(7),
  69471 	},
  69472 	465: {
  69473 		Fcode:       int8(17),
  69474 		Fextra_bits: int8(7),
  69475 	},
  69476 	466: {
  69477 		Fcode:       int8(17),
  69478 		Fextra_bits: int8(7),
  69479 	},
  69480 	467: {
  69481 		Fcode:       int8(17),
  69482 		Fextra_bits: int8(7),
  69483 	},
  69484 	468: {
  69485 		Fcode:       int8(17),
  69486 		Fextra_bits: int8(7),
  69487 	},
  69488 	469: {
  69489 		Fcode:       int8(17),
  69490 		Fextra_bits: int8(7),
  69491 	},
  69492 	470: {
  69493 		Fcode:       int8(17),
  69494 		Fextra_bits: int8(7),
  69495 	},
  69496 	471: {
  69497 		Fcode:       int8(17),
  69498 		Fextra_bits: int8(7),
  69499 	},
  69500 	472: {
  69501 		Fcode:       int8(17),
  69502 		Fextra_bits: int8(7),
  69503 	},
  69504 	473: {
  69505 		Fcode:       int8(17),
  69506 		Fextra_bits: int8(7),
  69507 	},
  69508 	474: {
  69509 		Fcode:       int8(17),
  69510 		Fextra_bits: int8(7),
  69511 	},
  69512 	475: {
  69513 		Fcode:       int8(17),
  69514 		Fextra_bits: int8(7),
  69515 	},
  69516 	476: {
  69517 		Fcode:       int8(17),
  69518 		Fextra_bits: int8(7),
  69519 	},
  69520 	477: {
  69521 		Fcode:       int8(17),
  69522 		Fextra_bits: int8(7),
  69523 	},
  69524 	478: {
  69525 		Fcode:       int8(17),
  69526 		Fextra_bits: int8(7),
  69527 	},
  69528 	479: {
  69529 		Fcode:       int8(17),
  69530 		Fextra_bits: int8(7),
  69531 	},
  69532 	480: {
  69533 		Fcode:       int8(17),
  69534 		Fextra_bits: int8(7),
  69535 	},
  69536 	481: {
  69537 		Fcode:       int8(17),
  69538 		Fextra_bits: int8(7),
  69539 	},
  69540 	482: {
  69541 		Fcode:       int8(17),
  69542 		Fextra_bits: int8(7),
  69543 	},
  69544 	483: {
  69545 		Fcode:       int8(17),
  69546 		Fextra_bits: int8(7),
  69547 	},
  69548 	484: {
  69549 		Fcode:       int8(17),
  69550 		Fextra_bits: int8(7),
  69551 	},
  69552 	485: {
  69553 		Fcode:       int8(17),
  69554 		Fextra_bits: int8(7),
  69555 	},
  69556 	486: {
  69557 		Fcode:       int8(17),
  69558 		Fextra_bits: int8(7),
  69559 	},
  69560 	487: {
  69561 		Fcode:       int8(17),
  69562 		Fextra_bits: int8(7),
  69563 	},
  69564 	488: {
  69565 		Fcode:       int8(17),
  69566 		Fextra_bits: int8(7),
  69567 	},
  69568 	489: {
  69569 		Fcode:       int8(17),
  69570 		Fextra_bits: int8(7),
  69571 	},
  69572 	490: {
  69573 		Fcode:       int8(17),
  69574 		Fextra_bits: int8(7),
  69575 	},
  69576 	491: {
  69577 		Fcode:       int8(17),
  69578 		Fextra_bits: int8(7),
  69579 	},
  69580 	492: {
  69581 		Fcode:       int8(17),
  69582 		Fextra_bits: int8(7),
  69583 	},
  69584 	493: {
  69585 		Fcode:       int8(17),
  69586 		Fextra_bits: int8(7),
  69587 	},
  69588 	494: {
  69589 		Fcode:       int8(17),
  69590 		Fextra_bits: int8(7),
  69591 	},
  69592 	495: {
  69593 		Fcode:       int8(17),
  69594 		Fextra_bits: int8(7),
  69595 	},
  69596 	496: {
  69597 		Fcode:       int8(17),
  69598 		Fextra_bits: int8(7),
  69599 	},
  69600 	497: {
  69601 		Fcode:       int8(17),
  69602 		Fextra_bits: int8(7),
  69603 	},
  69604 	498: {
  69605 		Fcode:       int8(17),
  69606 		Fextra_bits: int8(7),
  69607 	},
  69608 	499: {
  69609 		Fcode:       int8(17),
  69610 		Fextra_bits: int8(7),
  69611 	},
  69612 	500: {
  69613 		Fcode:       int8(17),
  69614 		Fextra_bits: int8(7),
  69615 	},
  69616 	501: {
  69617 		Fcode:       int8(17),
  69618 		Fextra_bits: int8(7),
  69619 	},
  69620 	502: {
  69621 		Fcode:       int8(17),
  69622 		Fextra_bits: int8(7),
  69623 	},
  69624 	503: {
  69625 		Fcode:       int8(17),
  69626 		Fextra_bits: int8(7),
  69627 	},
  69628 	504: {
  69629 		Fcode:       int8(17),
  69630 		Fextra_bits: int8(7),
  69631 	},
  69632 	505: {
  69633 		Fcode:       int8(17),
  69634 		Fextra_bits: int8(7),
  69635 	},
  69636 	506: {
  69637 		Fcode:       int8(17),
  69638 		Fextra_bits: int8(7),
  69639 	},
  69640 	507: {
  69641 		Fcode:       int8(17),
  69642 		Fextra_bits: int8(7),
  69643 	},
  69644 	508: {
  69645 		Fcode:       int8(17),
  69646 		Fextra_bits: int8(7),
  69647 	},
  69648 	509: {
  69649 		Fcode:       int8(17),
  69650 		Fextra_bits: int8(7),
  69651 	},
  69652 	510: {
  69653 		Fcode:       int8(17),
  69654 		Fextra_bits: int8(7),
  69655 	},
  69656 	511: {
  69657 		Fcode:       int8(17),
  69658 		Fextra_bits: int8(7),
  69659 	},
  69660 }
  69661 
  69662 var kPrefixEncodeExtraBitsValue = [512]uint8_t{
  69663 	6:   uint8(1),
  69664 	8:   uint8(1),
  69665 	10:  uint8(1),
  69666 	11:  uint8(2),
  69667 	12:  uint8(3),
  69668 	14:  uint8(1),
  69669 	15:  uint8(2),
  69670 	16:  uint8(3),
  69671 	18:  uint8(1),
  69672 	19:  uint8(2),
  69673 	20:  uint8(3),
  69674 	21:  uint8(4),
  69675 	22:  uint8(5),
  69676 	23:  uint8(6),
  69677 	24:  uint8(7),
  69678 	26:  uint8(1),
  69679 	27:  uint8(2),
  69680 	28:  uint8(3),
  69681 	29:  uint8(4),
  69682 	30:  uint8(5),
  69683 	31:  uint8(6),
  69684 	32:  uint8(7),
  69685 	34:  uint8(1),
  69686 	35:  uint8(2),
  69687 	36:  uint8(3),
  69688 	37:  uint8(4),
  69689 	38:  uint8(5),
  69690 	39:  uint8(6),
  69691 	40:  uint8(7),
  69692 	41:  uint8(8),
  69693 	42:  uint8(9),
  69694 	43:  uint8(10),
  69695 	44:  uint8(11),
  69696 	45:  uint8(12),
  69697 	46:  uint8(13),
  69698 	47:  uint8(14),
  69699 	48:  uint8(15),
  69700 	50:  uint8(1),
  69701 	51:  uint8(2),
  69702 	52:  uint8(3),
  69703 	53:  uint8(4),
  69704 	54:  uint8(5),
  69705 	55:  uint8(6),
  69706 	56:  uint8(7),
  69707 	57:  uint8(8),
  69708 	58:  uint8(9),
  69709 	59:  uint8(10),
  69710 	60:  uint8(11),
  69711 	61:  uint8(12),
  69712 	62:  uint8(13),
  69713 	63:  uint8(14),
  69714 	64:  uint8(15),
  69715 	66:  uint8(1),
  69716 	67:  uint8(2),
  69717 	68:  uint8(3),
  69718 	69:  uint8(4),
  69719 	70:  uint8(5),
  69720 	71:  uint8(6),
  69721 	72:  uint8(7),
  69722 	73:  uint8(8),
  69723 	74:  uint8(9),
  69724 	75:  uint8(10),
  69725 	76:  uint8(11),
  69726 	77:  uint8(12),
  69727 	78:  uint8(13),
  69728 	79:  uint8(14),
  69729 	80:  uint8(15),
  69730 	81:  uint8(16),
  69731 	82:  uint8(17),
  69732 	83:  uint8(18),
  69733 	84:  uint8(19),
  69734 	85:  uint8(20),
  69735 	86:  uint8(21),
  69736 	87:  uint8(22),
  69737 	88:  uint8(23),
  69738 	89:  uint8(24),
  69739 	90:  uint8(25),
  69740 	91:  uint8(26),
  69741 	92:  uint8(27),
  69742 	93:  uint8(28),
  69743 	94:  uint8(29),
  69744 	95:  uint8(30),
  69745 	96:  uint8(31),
  69746 	98:  uint8(1),
  69747 	99:  uint8(2),
  69748 	100: uint8(3),
  69749 	101: uint8(4),
  69750 	102: uint8(5),
  69751 	103: uint8(6),
  69752 	104: uint8(7),
  69753 	105: uint8(8),
  69754 	106: uint8(9),
  69755 	107: uint8(10),
  69756 	108: uint8(11),
  69757 	109: uint8(12),
  69758 	110: uint8(13),
  69759 	111: uint8(14),
  69760 	112: uint8(15),
  69761 	113: uint8(16),
  69762 	114: uint8(17),
  69763 	115: uint8(18),
  69764 	116: uint8(19),
  69765 	117: uint8(20),
  69766 	118: uint8(21),
  69767 	119: uint8(22),
  69768 	120: uint8(23),
  69769 	121: uint8(24),
  69770 	122: uint8(25),
  69771 	123: uint8(26),
  69772 	124: uint8(27),
  69773 	125: uint8(28),
  69774 	126: uint8(29),
  69775 	127: uint8(30),
  69776 	128: uint8(31),
  69777 	130: uint8(1),
  69778 	131: uint8(2),
  69779 	132: uint8(3),
  69780 	133: uint8(4),
  69781 	134: uint8(5),
  69782 	135: uint8(6),
  69783 	136: uint8(7),
  69784 	137: uint8(8),
  69785 	138: uint8(9),
  69786 	139: uint8(10),
  69787 	140: uint8(11),
  69788 	141: uint8(12),
  69789 	142: uint8(13),
  69790 	143: uint8(14),
  69791 	144: uint8(15),
  69792 	145: uint8(16),
  69793 	146: uint8(17),
  69794 	147: uint8(18),
  69795 	148: uint8(19),
  69796 	149: uint8(20),
  69797 	150: uint8(21),
  69798 	151: uint8(22),
  69799 	152: uint8(23),
  69800 	153: uint8(24),
  69801 	154: uint8(25),
  69802 	155: uint8(26),
  69803 	156: uint8(27),
  69804 	157: uint8(28),
  69805 	158: uint8(29),
  69806 	159: uint8(30),
  69807 	160: uint8(31),
  69808 	161: uint8(32),
  69809 	162: uint8(33),
  69810 	163: uint8(34),
  69811 	164: uint8(35),
  69812 	165: uint8(36),
  69813 	166: uint8(37),
  69814 	167: uint8(38),
  69815 	168: uint8(39),
  69816 	169: uint8(40),
  69817 	170: uint8(41),
  69818 	171: uint8(42),
  69819 	172: uint8(43),
  69820 	173: uint8(44),
  69821 	174: uint8(45),
  69822 	175: uint8(46),
  69823 	176: uint8(47),
  69824 	177: uint8(48),
  69825 	178: uint8(49),
  69826 	179: uint8(50),
  69827 	180: uint8(51),
  69828 	181: uint8(52),
  69829 	182: uint8(53),
  69830 	183: uint8(54),
  69831 	184: uint8(55),
  69832 	185: uint8(56),
  69833 	186: uint8(57),
  69834 	187: uint8(58),
  69835 	188: uint8(59),
  69836 	189: uint8(60),
  69837 	190: uint8(61),
  69838 	191: uint8(62),
  69839 	192: uint8(63),
  69840 	194: uint8(1),
  69841 	195: uint8(2),
  69842 	196: uint8(3),
  69843 	197: uint8(4),
  69844 	198: uint8(5),
  69845 	199: uint8(6),
  69846 	200: uint8(7),
  69847 	201: uint8(8),
  69848 	202: uint8(9),
  69849 	203: uint8(10),
  69850 	204: uint8(11),
  69851 	205: uint8(12),
  69852 	206: uint8(13),
  69853 	207: uint8(14),
  69854 	208: uint8(15),
  69855 	209: uint8(16),
  69856 	210: uint8(17),
  69857 	211: uint8(18),
  69858 	212: uint8(19),
  69859 	213: uint8(20),
  69860 	214: uint8(21),
  69861 	215: uint8(22),
  69862 	216: uint8(23),
  69863 	217: uint8(24),
  69864 	218: uint8(25),
  69865 	219: uint8(26),
  69866 	220: uint8(27),
  69867 	221: uint8(28),
  69868 	222: uint8(29),
  69869 	223: uint8(30),
  69870 	224: uint8(31),
  69871 	225: uint8(32),
  69872 	226: uint8(33),
  69873 	227: uint8(34),
  69874 	228: uint8(35),
  69875 	229: uint8(36),
  69876 	230: uint8(37),
  69877 	231: uint8(38),
  69878 	232: uint8(39),
  69879 	233: uint8(40),
  69880 	234: uint8(41),
  69881 	235: uint8(42),
  69882 	236: uint8(43),
  69883 	237: uint8(44),
  69884 	238: uint8(45),
  69885 	239: uint8(46),
  69886 	240: uint8(47),
  69887 	241: uint8(48),
  69888 	242: uint8(49),
  69889 	243: uint8(50),
  69890 	244: uint8(51),
  69891 	245: uint8(52),
  69892 	246: uint8(53),
  69893 	247: uint8(54),
  69894 	248: uint8(55),
  69895 	249: uint8(56),
  69896 	250: uint8(57),
  69897 	251: uint8(58),
  69898 	252: uint8(59),
  69899 	253: uint8(60),
  69900 	254: uint8(61),
  69901 	255: uint8(62),
  69902 	256: uint8(63),
  69903 	258: uint8(1),
  69904 	259: uint8(2),
  69905 	260: uint8(3),
  69906 	261: uint8(4),
  69907 	262: uint8(5),
  69908 	263: uint8(6),
  69909 	264: uint8(7),
  69910 	265: uint8(8),
  69911 	266: uint8(9),
  69912 	267: uint8(10),
  69913 	268: uint8(11),
  69914 	269: uint8(12),
  69915 	270: uint8(13),
  69916 	271: uint8(14),
  69917 	272: uint8(15),
  69918 	273: uint8(16),
  69919 	274: uint8(17),
  69920 	275: uint8(18),
  69921 	276: uint8(19),
  69922 	277: uint8(20),
  69923 	278: uint8(21),
  69924 	279: uint8(22),
  69925 	280: uint8(23),
  69926 	281: uint8(24),
  69927 	282: uint8(25),
  69928 	283: uint8(26),
  69929 	284: uint8(27),
  69930 	285: uint8(28),
  69931 	286: uint8(29),
  69932 	287: uint8(30),
  69933 	288: uint8(31),
  69934 	289: uint8(32),
  69935 	290: uint8(33),
  69936 	291: uint8(34),
  69937 	292: uint8(35),
  69938 	293: uint8(36),
  69939 	294: uint8(37),
  69940 	295: uint8(38),
  69941 	296: uint8(39),
  69942 	297: uint8(40),
  69943 	298: uint8(41),
  69944 	299: uint8(42),
  69945 	300: uint8(43),
  69946 	301: uint8(44),
  69947 	302: uint8(45),
  69948 	303: uint8(46),
  69949 	304: uint8(47),
  69950 	305: uint8(48),
  69951 	306: uint8(49),
  69952 	307: uint8(50),
  69953 	308: uint8(51),
  69954 	309: uint8(52),
  69955 	310: uint8(53),
  69956 	311: uint8(54),
  69957 	312: uint8(55),
  69958 	313: uint8(56),
  69959 	314: uint8(57),
  69960 	315: uint8(58),
  69961 	316: uint8(59),
  69962 	317: uint8(60),
  69963 	318: uint8(61),
  69964 	319: uint8(62),
  69965 	320: uint8(63),
  69966 	321: uint8(64),
  69967 	322: uint8(65),
  69968 	323: uint8(66),
  69969 	324: uint8(67),
  69970 	325: uint8(68),
  69971 	326: uint8(69),
  69972 	327: uint8(70),
  69973 	328: uint8(71),
  69974 	329: uint8(72),
  69975 	330: uint8(73),
  69976 	331: uint8(74),
  69977 	332: uint8(75),
  69978 	333: uint8(76),
  69979 	334: uint8(77),
  69980 	335: uint8(78),
  69981 	336: uint8(79),
  69982 	337: uint8(80),
  69983 	338: uint8(81),
  69984 	339: uint8(82),
  69985 	340: uint8(83),
  69986 	341: uint8(84),
  69987 	342: uint8(85),
  69988 	343: uint8(86),
  69989 	344: uint8(87),
  69990 	345: uint8(88),
  69991 	346: uint8(89),
  69992 	347: uint8(90),
  69993 	348: uint8(91),
  69994 	349: uint8(92),
  69995 	350: uint8(93),
  69996 	351: uint8(94),
  69997 	352: uint8(95),
  69998 	353: uint8(96),
  69999 	354: uint8(97),
  70000 	355: uint8(98),
  70001 	356: uint8(99),
  70002 	357: uint8(100),
  70003 	358: uint8(101),
  70004 	359: uint8(102),
  70005 	360: uint8(103),
  70006 	361: uint8(104),
  70007 	362: uint8(105),
  70008 	363: uint8(106),
  70009 	364: uint8(107),
  70010 	365: uint8(108),
  70011 	366: uint8(109),
  70012 	367: uint8(110),
  70013 	368: uint8(111),
  70014 	369: uint8(112),
  70015 	370: uint8(113),
  70016 	371: uint8(114),
  70017 	372: uint8(115),
  70018 	373: uint8(116),
  70019 	374: uint8(117),
  70020 	375: uint8(118),
  70021 	376: uint8(119),
  70022 	377: uint8(120),
  70023 	378: uint8(121),
  70024 	379: uint8(122),
  70025 	380: uint8(123),
  70026 	381: uint8(124),
  70027 	382: uint8(125),
  70028 	383: uint8(126),
  70029 	384: uint8(127),
  70030 	386: uint8(1),
  70031 	387: uint8(2),
  70032 	388: uint8(3),
  70033 	389: uint8(4),
  70034 	390: uint8(5),
  70035 	391: uint8(6),
  70036 	392: uint8(7),
  70037 	393: uint8(8),
  70038 	394: uint8(9),
  70039 	395: uint8(10),
  70040 	396: uint8(11),
  70041 	397: uint8(12),
  70042 	398: uint8(13),
  70043 	399: uint8(14),
  70044 	400: uint8(15),
  70045 	401: uint8(16),
  70046 	402: uint8(17),
  70047 	403: uint8(18),
  70048 	404: uint8(19),
  70049 	405: uint8(20),
  70050 	406: uint8(21),
  70051 	407: uint8(22),
  70052 	408: uint8(23),
  70053 	409: uint8(24),
  70054 	410: uint8(25),
  70055 	411: uint8(26),
  70056 	412: uint8(27),
  70057 	413: uint8(28),
  70058 	414: uint8(29),
  70059 	415: uint8(30),
  70060 	416: uint8(31),
  70061 	417: uint8(32),
  70062 	418: uint8(33),
  70063 	419: uint8(34),
  70064 	420: uint8(35),
  70065 	421: uint8(36),
  70066 	422: uint8(37),
  70067 	423: uint8(38),
  70068 	424: uint8(39),
  70069 	425: uint8(40),
  70070 	426: uint8(41),
  70071 	427: uint8(42),
  70072 	428: uint8(43),
  70073 	429: uint8(44),
  70074 	430: uint8(45),
  70075 	431: uint8(46),
  70076 	432: uint8(47),
  70077 	433: uint8(48),
  70078 	434: uint8(49),
  70079 	435: uint8(50),
  70080 	436: uint8(51),
  70081 	437: uint8(52),
  70082 	438: uint8(53),
  70083 	439: uint8(54),
  70084 	440: uint8(55),
  70085 	441: uint8(56),
  70086 	442: uint8(57),
  70087 	443: uint8(58),
  70088 	444: uint8(59),
  70089 	445: uint8(60),
  70090 	446: uint8(61),
  70091 	447: uint8(62),
  70092 	448: uint8(63),
  70093 	449: uint8(64),
  70094 	450: uint8(65),
  70095 	451: uint8(66),
  70096 	452: uint8(67),
  70097 	453: uint8(68),
  70098 	454: uint8(69),
  70099 	455: uint8(70),
  70100 	456: uint8(71),
  70101 	457: uint8(72),
  70102 	458: uint8(73),
  70103 	459: uint8(74),
  70104 	460: uint8(75),
  70105 	461: uint8(76),
  70106 	462: uint8(77),
  70107 	463: uint8(78),
  70108 	464: uint8(79),
  70109 	465: uint8(80),
  70110 	466: uint8(81),
  70111 	467: uint8(82),
  70112 	468: uint8(83),
  70113 	469: uint8(84),
  70114 	470: uint8(85),
  70115 	471: uint8(86),
  70116 	472: uint8(87),
  70117 	473: uint8(88),
  70118 	474: uint8(89),
  70119 	475: uint8(90),
  70120 	476: uint8(91),
  70121 	477: uint8(92),
  70122 	478: uint8(93),
  70123 	479: uint8(94),
  70124 	480: uint8(95),
  70125 	481: uint8(96),
  70126 	482: uint8(97),
  70127 	483: uint8(98),
  70128 	484: uint8(99),
  70129 	485: uint8(100),
  70130 	486: uint8(101),
  70131 	487: uint8(102),
  70132 	488: uint8(103),
  70133 	489: uint8(104),
  70134 	490: uint8(105),
  70135 	491: uint8(106),
  70136 	492: uint8(107),
  70137 	493: uint8(108),
  70138 	494: uint8(109),
  70139 	495: uint8(110),
  70140 	496: uint8(111),
  70141 	497: uint8(112),
  70142 	498: uint8(113),
  70143 	499: uint8(114),
  70144 	500: uint8(115),
  70145 	501: uint8(116),
  70146 	502: uint8(117),
  70147 	503: uint8(118),
  70148 	504: uint8(119),
  70149 	505: uint8(120),
  70150 	506: uint8(121),
  70151 	507: uint8(122),
  70152 	508: uint8(123),
  70153 	509: uint8(124),
  70154 	510: uint8(125),
  70155 	511: uint8(126),
  70156 }
  70157 
  70158 // C documentation
  70159 //
  70160 //	// lookup table for small values of int*log2(int) * (1 << LOG_2_PRECISION_BITS).
  70161 //	// Obtained in Python with:
  70162 //	// a=[ "%d"%i if i<(1<<32) else "%dull"%i
  70163 //	//     for i in [ round((1<<LOG_2_PRECISION_BITS)*math.log2(i)*i) if i
  70164 //	//     else 0 for i in range(256)]]
  70165 //	// print(',\n '.join([','.join(v) for v in batched([i.rjust(15)
  70166 //	//                      for i in a],4)]))
  70167 var kSLog2Table = [256]uint64_t{
  70168 	2:   uint64(16777216),
  70169 	3:   uint64(39886887),
  70170 	4:   uint64(67108864),
  70171 	5:   uint64(97388723),
  70172 	6:   uint64(130105423),
  70173 	7:   uint64(164848600),
  70174 	8:   uint64(201326592),
  70175 	9:   uint64(239321324),
  70176 	10:  uint64(278663526),
  70177 	11:  uint64(319217973),
  70178 	12:  uint64(360874141),
  70179 	13:  uint64(403539997),
  70180 	14:  uint64(447137711),
  70181 	15:  uint64(491600606),
  70182 	16:  uint64(536870912),
  70183 	17:  uint64(582898099),
  70184 	18:  uint64(629637592),
  70185 	19:  uint64(677049776),
  70186 	20:  uint64(725099212),
  70187 	21:  uint64(773754010),
  70188 	22:  uint64(822985323),
  70189 	23:  uint64(872766924),
  70190 	24:  uint64(923074875),
  70191 	25:  uint64(973887230),
  70192 	26:  uint64(1025183802),
  70193 	27:  uint64(1076945958),
  70194 	28:  uint64(1129156447),
  70195 	29:  uint64(1181799249),
  70196 	30:  uint64(1234859451),
  70197 	31:  uint64(1288323135),
  70198 	32:  uint64(1342177280),
  70199 	33:  uint64(1396409681),
  70200 	34:  uint64(1451008871),
  70201 	35:  uint64(1505964059),
  70202 	36:  uint64(1561265072),
  70203 	37:  uint64(1616902301),
  70204 	38:  uint64(1672866655),
  70205 	39:  uint64(1729149526),
  70206 	40:  uint64(1785742744),
  70207 	41:  uint64(1842638548),
  70208 	42:  uint64(1899829557),
  70209 	43:  uint64(1957308741),
  70210 	44:  uint64(2015069397),
  70211 	45:  uint64(2073105127),
  70212 	46:  uint64(2131409817),
  70213 	47:  uint64(2189977618),
  70214 	48:  uint64(2248802933),
  70215 	49:  uint64(2307880396),
  70216 	50:  uint64(2367204859),
  70217 	51:  uint64(2426771383),
  70218 	52:  uint64(2486575220),
  70219 	53:  uint64(2546611805),
  70220 	54:  uint64(2606876748),
  70221 	55:  uint64(2667365819),
  70222 	56:  uint64(2728074942),
  70223 	57:  uint64(2789000187),
  70224 	58:  uint64(2850137762),
  70225 	59:  uint64(2911484006),
  70226 	60:  uint64(2973035382),
  70227 	61:  uint64(3034788471),
  70228 	62:  uint64(3096739966),
  70229 	63:  uint64(3158886666),
  70230 	64:  uint64(3221225472),
  70231 	65:  uint64(3283753383),
  70232 	66:  uint64(3346467489),
  70233 	67:  uint64(3409364969),
  70234 	68:  uint64(3472443085),
  70235 	69:  uint64(3535699182),
  70236 	70:  uint64(3599130679),
  70237 	71:  uint64(3662735070),
  70238 	72:  uint64(3726509920),
  70239 	73:  uint64(3790452862),
  70240 	74:  uint64(3854561593),
  70241 	75:  uint64(3918833872),
  70242 	76:  uint64(3983267519),
  70243 	77:  uint64(4047860410),
  70244 	78:  uint64(4112610476),
  70245 	79:  uint64(4177515704),
  70246 	80:  uint64(4242574127),
  70247 	81:  uint64(4307783833),
  70248 	82:  uint64(4373142952),
  70249 	83:  uint64(4438649662),
  70250 	84:  uint64(4504302186),
  70251 	85:  uint64(4570098787),
  70252 	86:  uint64(4636037770),
  70253 	87:  uint64(4702117480),
  70254 	88:  uint64(4768336298),
  70255 	89:  uint64(4834692645),
  70256 	90:  uint64(4901184974),
  70257 	91:  uint64(4967811774),
  70258 	92:  uint64(5034571569),
  70259 	93:  uint64(5101462912),
  70260 	94:  uint64(5168484389),
  70261 	95:  uint64(5235634615),
  70262 	96:  uint64(5302912235),
  70263 	97:  uint64(5370315922),
  70264 	98:  uint64(5437844376),
  70265 	99:  uint64(5505496324),
  70266 	100: uint64(5573270518),
  70267 	101: uint64(5641165737),
  70268 	102: uint64(5709180782),
  70269 	103: uint64(5777314477),
  70270 	104: uint64(5845565671),
  70271 	105: uint64(5913933235),
  70272 	106: uint64(5982416059),
  70273 	107: uint64(6051013057),
  70274 	108: uint64(6119723161),
  70275 	109: uint64(6188545324),
  70276 	110: uint64(6257478518),
  70277 	111: uint64(6326521733),
  70278 	112: uint64(6395673979),
  70279 	113: uint64(6464934282),
  70280 	114: uint64(6534301685),
  70281 	115: uint64(6603775250),
  70282 	116: uint64(6673354052),
  70283 	117: uint64(6743037185),
  70284 	118: uint64(6812823756),
  70285 	119: uint64(6882712890),
  70286 	120: uint64(6952703725),
  70287 	121: uint64(7022795412),
  70288 	122: uint64(7092987118),
  70289 	123: uint64(7163278025),
  70290 	124: uint64(7233667324),
  70291 	125: uint64(7304154222),
  70292 	126: uint64(7374737939),
  70293 	127: uint64(7445417707),
  70294 	128: uint64(7516192768),
  70295 	129: uint64(7587062379),
  70296 	130: uint64(7658025806),
  70297 	131: uint64(7729082328),
  70298 	132: uint64(7800231234),
  70299 	133: uint64(7871471825),
  70300 	134: uint64(7942803410),
  70301 	135: uint64(8014225311),
  70302 	136: uint64(8085736859),
  70303 	137: uint64(8157337394),
  70304 	138: uint64(8229026267),
  70305 	139: uint64(8300802839),
  70306 	140: uint64(8372666477),
  70307 	141: uint64(8444616560),
  70308 	142: uint64(8516652476),
  70309 	143: uint64(8588773618),
  70310 	144: uint64(8660979393),
  70311 	145: uint64(8733269211),
  70312 	146: uint64(8805642493),
  70313 	147: uint64(8878098667),
  70314 	148: uint64(8950637170),
  70315 	149: uint64(9023257446),
  70316 	150: uint64(9095958945),
  70317 	151: uint64(9168741125),
  70318 	152: uint64(9241603454),
  70319 	153: uint64(9314545403),
  70320 	154: uint64(9387566451),
  70321 	155: uint64(9460666086),
  70322 	156: uint64(9533843800),
  70323 	157: uint64(9607099093),
  70324 	158: uint64(9680431471),
  70325 	159: uint64(9753840445),
  70326 	160: uint64(9827325535),
  70327 	161: uint64(9900886263),
  70328 	162: uint64(9974522161),
  70329 	163: uint64(10048232765),
  70330 	164: uint64(10122017615),
  70331 	165: uint64(10195876260),
  70332 	166: uint64(10269808253),
  70333 	167: uint64(10343813150),
  70334 	168: uint64(10417890516),
  70335 	169: uint64(10492039919),
  70336 	170: uint64(10566260934),
  70337 	171: uint64(10640553138),
  70338 	172: uint64(10714916116),
  70339 	173: uint64(10789349456),
  70340 	174: uint64(10863852751),
  70341 	175: uint64(10938425600),
  70342 	176: uint64(11013067604),
  70343 	177: uint64(11087778372),
  70344 	178: uint64(11162557513),
  70345 	179: uint64(11237404645),
  70346 	180: uint64(11312319387),
  70347 	181: uint64(11387301364),
  70348 	182: uint64(11462350205),
  70349 	183: uint64(11537465541),
  70350 	184: uint64(11612647010),
  70351 	185: uint64(11687894253),
  70352 	186: uint64(11763206912),
  70353 	187: uint64(11838584638),
  70354 	188: uint64(11914027082),
  70355 	189: uint64(11989533899),
  70356 	190: uint64(12065104750),
  70357 	191: uint64(12140739296),
  70358 	192: uint64(12216437206),
  70359 	193: uint64(12292198148),
  70360 	194: uint64(12368021795),
  70361 	195: uint64(12443907826),
  70362 	196: uint64(12519855920),
  70363 	197: uint64(12595865759),
  70364 	198: uint64(12671937032),
  70365 	199: uint64(12748069427),
  70366 	200: uint64(12824262637),
  70367 	201: uint64(12900516358),
  70368 	202: uint64(12976830290),
  70369 	203: uint64(13053204134),
  70370 	204: uint64(13129637595),
  70371 	205: uint64(13206130381),
  70372 	206: uint64(13282682202),
  70373 	207: uint64(13359292772),
  70374 	208: uint64(13435961806),
  70375 	209: uint64(13512689025),
  70376 	210: uint64(13589474149),
  70377 	211: uint64(13666316903),
  70378 	212: uint64(13743217014),
  70379 	213: uint64(13820174211),
  70380 	214: uint64(13897188225),
  70381 	215: uint64(13974258793),
  70382 	216: uint64(14051385649),
  70383 	217: uint64(14128568535),
  70384 	218: uint64(14205807192),
  70385 	219: uint64(14283101363),
  70386 	220: uint64(14360450796),
  70387 	221: uint64(14437855239),
  70388 	222: uint64(14515314443),
  70389 	223: uint64(14592828162),
  70390 	224: uint64(14670396151),
  70391 	225: uint64(14748018167),
  70392 	226: uint64(14825693972),
  70393 	227: uint64(14903423326),
  70394 	228: uint64(14981205995),
  70395 	229: uint64(15059041743),
  70396 	230: uint64(15136930339),
  70397 	231: uint64(15214871554),
  70398 	232: uint64(15292865160),
  70399 	233: uint64(15370910930),
  70400 	234: uint64(15449008641),
  70401 	235: uint64(15527158071),
  70402 	236: uint64(15605359001),
  70403 	237: uint64(15683611210),
  70404 	238: uint64(15761914485),
  70405 	239: uint64(15840268608),
  70406 	240: uint64(15918673369),
  70407 	241: uint64(15997128556),
  70408 	242: uint64(16075633960),
  70409 	243: uint64(16154189373),
  70410 	244: uint64(16232794589),
  70411 	245: uint64(16311449405),
  70412 	246: uint64(16390153617),
  70413 	247: uint64(16468907026),
  70414 	248: uint64(16547709431),
  70415 	249: uint64(16626560636),
  70416 	250: uint64(16705460444),
  70417 	251: uint64(16784408661),
  70418 	252: uint64(16863405094),
  70419 	253: uint64(16942449552),
  70420 	254: uint64(17021541845),
  70421 	255: uint64(17100681785),
  70422 }
  70423 
  70424 var kVP8Log2Range = [128]uint8_t{
  70425 	0:   uint8(7),
  70426 	1:   uint8(6),
  70427 	2:   uint8(6),
  70428 	3:   uint8(5),
  70429 	4:   uint8(5),
  70430 	5:   uint8(5),
  70431 	6:   uint8(5),
  70432 	7:   uint8(4),
  70433 	8:   uint8(4),
  70434 	9:   uint8(4),
  70435 	10:  uint8(4),
  70436 	11:  uint8(4),
  70437 	12:  uint8(4),
  70438 	13:  uint8(4),
  70439 	14:  uint8(4),
  70440 	15:  uint8(3),
  70441 	16:  uint8(3),
  70442 	17:  uint8(3),
  70443 	18:  uint8(3),
  70444 	19:  uint8(3),
  70445 	20:  uint8(3),
  70446 	21:  uint8(3),
  70447 	22:  uint8(3),
  70448 	23:  uint8(3),
  70449 	24:  uint8(3),
  70450 	25:  uint8(3),
  70451 	26:  uint8(3),
  70452 	27:  uint8(3),
  70453 	28:  uint8(3),
  70454 	29:  uint8(3),
  70455 	30:  uint8(3),
  70456 	31:  uint8(2),
  70457 	32:  uint8(2),
  70458 	33:  uint8(2),
  70459 	34:  uint8(2),
  70460 	35:  uint8(2),
  70461 	36:  uint8(2),
  70462 	37:  uint8(2),
  70463 	38:  uint8(2),
  70464 	39:  uint8(2),
  70465 	40:  uint8(2),
  70466 	41:  uint8(2),
  70467 	42:  uint8(2),
  70468 	43:  uint8(2),
  70469 	44:  uint8(2),
  70470 	45:  uint8(2),
  70471 	46:  uint8(2),
  70472 	47:  uint8(2),
  70473 	48:  uint8(2),
  70474 	49:  uint8(2),
  70475 	50:  uint8(2),
  70476 	51:  uint8(2),
  70477 	52:  uint8(2),
  70478 	53:  uint8(2),
  70479 	54:  uint8(2),
  70480 	55:  uint8(2),
  70481 	56:  uint8(2),
  70482 	57:  uint8(2),
  70483 	58:  uint8(2),
  70484 	59:  uint8(2),
  70485 	60:  uint8(2),
  70486 	61:  uint8(2),
  70487 	62:  uint8(2),
  70488 	63:  uint8(1),
  70489 	64:  uint8(1),
  70490 	65:  uint8(1),
  70491 	66:  uint8(1),
  70492 	67:  uint8(1),
  70493 	68:  uint8(1),
  70494 	69:  uint8(1),
  70495 	70:  uint8(1),
  70496 	71:  uint8(1),
  70497 	72:  uint8(1),
  70498 	73:  uint8(1),
  70499 	74:  uint8(1),
  70500 	75:  uint8(1),
  70501 	76:  uint8(1),
  70502 	77:  uint8(1),
  70503 	78:  uint8(1),
  70504 	79:  uint8(1),
  70505 	80:  uint8(1),
  70506 	81:  uint8(1),
  70507 	82:  uint8(1),
  70508 	83:  uint8(1),
  70509 	84:  uint8(1),
  70510 	85:  uint8(1),
  70511 	86:  uint8(1),
  70512 	87:  uint8(1),
  70513 	88:  uint8(1),
  70514 	89:  uint8(1),
  70515 	90:  uint8(1),
  70516 	91:  uint8(1),
  70517 	92:  uint8(1),
  70518 	93:  uint8(1),
  70519 	94:  uint8(1),
  70520 	95:  uint8(1),
  70521 	96:  uint8(1),
  70522 	97:  uint8(1),
  70523 	98:  uint8(1),
  70524 	99:  uint8(1),
  70525 	100: uint8(1),
  70526 	101: uint8(1),
  70527 	102: uint8(1),
  70528 	103: uint8(1),
  70529 	104: uint8(1),
  70530 	105: uint8(1),
  70531 	106: uint8(1),
  70532 	107: uint8(1),
  70533 	108: uint8(1),
  70534 	109: uint8(1),
  70535 	110: uint8(1),
  70536 	111: uint8(1),
  70537 	112: uint8(1),
  70538 	113: uint8(1),
  70539 	114: uint8(1),
  70540 	115: uint8(1),
  70541 	116: uint8(1),
  70542 	117: uint8(1),
  70543 	118: uint8(1),
  70544 	119: uint8(1),
  70545 	120: uint8(1),
  70546 	121: uint8(1),
  70547 	122: uint8(1),
  70548 	123: uint8(1),
  70549 	124: uint8(1),
  70550 	125: uint8(1),
  70551 	126: uint8(1),
  70552 }
  70553 
  70554 // C documentation
  70555 //
  70556 //	// range = ((range - 1) << kVP8Log2Range[range]) + 1
  70557 var kVP8NewRange = [128]uint8_t{
  70558 	0:   uint8(127),
  70559 	1:   uint8(127),
  70560 	2:   uint8(191),
  70561 	3:   uint8(127),
  70562 	4:   uint8(159),
  70563 	5:   uint8(191),
  70564 	6:   uint8(223),
  70565 	7:   uint8(127),
  70566 	8:   uint8(143),
  70567 	9:   uint8(159),
  70568 	10:  uint8(175),
  70569 	11:  uint8(191),
  70570 	12:  uint8(207),
  70571 	13:  uint8(223),
  70572 	14:  uint8(239),
  70573 	15:  uint8(127),
  70574 	16:  uint8(135),
  70575 	17:  uint8(143),
  70576 	18:  uint8(151),
  70577 	19:  uint8(159),
  70578 	20:  uint8(167),
  70579 	21:  uint8(175),
  70580 	22:  uint8(183),
  70581 	23:  uint8(191),
  70582 	24:  uint8(199),
  70583 	25:  uint8(207),
  70584 	26:  uint8(215),
  70585 	27:  uint8(223),
  70586 	28:  uint8(231),
  70587 	29:  uint8(239),
  70588 	30:  uint8(247),
  70589 	31:  uint8(127),
  70590 	32:  uint8(131),
  70591 	33:  uint8(135),
  70592 	34:  uint8(139),
  70593 	35:  uint8(143),
  70594 	36:  uint8(147),
  70595 	37:  uint8(151),
  70596 	38:  uint8(155),
  70597 	39:  uint8(159),
  70598 	40:  uint8(163),
  70599 	41:  uint8(167),
  70600 	42:  uint8(171),
  70601 	43:  uint8(175),
  70602 	44:  uint8(179),
  70603 	45:  uint8(183),
  70604 	46:  uint8(187),
  70605 	47:  uint8(191),
  70606 	48:  uint8(195),
  70607 	49:  uint8(199),
  70608 	50:  uint8(203),
  70609 	51:  uint8(207),
  70610 	52:  uint8(211),
  70611 	53:  uint8(215),
  70612 	54:  uint8(219),
  70613 	55:  uint8(223),
  70614 	56:  uint8(227),
  70615 	57:  uint8(231),
  70616 	58:  uint8(235),
  70617 	59:  uint8(239),
  70618 	60:  uint8(243),
  70619 	61:  uint8(247),
  70620 	62:  uint8(251),
  70621 	63:  uint8(127),
  70622 	64:  uint8(129),
  70623 	65:  uint8(131),
  70624 	66:  uint8(133),
  70625 	67:  uint8(135),
  70626 	68:  uint8(137),
  70627 	69:  uint8(139),
  70628 	70:  uint8(141),
  70629 	71:  uint8(143),
  70630 	72:  uint8(145),
  70631 	73:  uint8(147),
  70632 	74:  uint8(149),
  70633 	75:  uint8(151),
  70634 	76:  uint8(153),
  70635 	77:  uint8(155),
  70636 	78:  uint8(157),
  70637 	79:  uint8(159),
  70638 	80:  uint8(161),
  70639 	81:  uint8(163),
  70640 	82:  uint8(165),
  70641 	83:  uint8(167),
  70642 	84:  uint8(169),
  70643 	85:  uint8(171),
  70644 	86:  uint8(173),
  70645 	87:  uint8(175),
  70646 	88:  uint8(177),
  70647 	89:  uint8(179),
  70648 	90:  uint8(181),
  70649 	91:  uint8(183),
  70650 	92:  uint8(185),
  70651 	93:  uint8(187),
  70652 	94:  uint8(189),
  70653 	95:  uint8(191),
  70654 	96:  uint8(193),
  70655 	97:  uint8(195),
  70656 	98:  uint8(197),
  70657 	99:  uint8(199),
  70658 	100: uint8(201),
  70659 	101: uint8(203),
  70660 	102: uint8(205),
  70661 	103: uint8(207),
  70662 	104: uint8(209),
  70663 	105: uint8(211),
  70664 	106: uint8(213),
  70665 	107: uint8(215),
  70666 	108: uint8(217),
  70667 	109: uint8(219),
  70668 	110: uint8(221),
  70669 	111: uint8(223),
  70670 	112: uint8(225),
  70671 	113: uint8(227),
  70672 	114: uint8(229),
  70673 	115: uint8(231),
  70674 	116: uint8(233),
  70675 	117: uint8(235),
  70676 	118: uint8(237),
  70677 	119: uint8(239),
  70678 	120: uint8(241),
  70679 	121: uint8(243),
  70680 	122: uint8(245),
  70681 	123: uint8(247),
  70682 	124: uint8(249),
  70683 	125: uint8(251),
  70684 	126: uint8(253),
  70685 	127: uint8(127),
  70686 }
  70687 
  70688 var __ccgo_ts = (*reflect.StringHeader)(unsafe.Pointer(&__ccgo_ts1)).Data
  70689 
  70690 var __ccgo_ts1 = "Alpha decoder initialization failed.\x00Could not decode alpha data.\x00Frame setup failed\x00thread initialization failed.\x00no memory during frame initialization.\x00OK\x00no object\x00null VP8Io passed to VP8GetHeaders()\x00Truncated header.\x00Incorrect keyframe parameters.\x00Frame not displayable.\x00cannot parse picture header\x00Bad code word\x00bad partition length\x00cannot parse segment header\x00cannot parse filter header\x00cannot parse partitions\x00Not a key frame.\x00Premature end-of-partition0 encountered.\x00Premature end-of-file encountered.\x00Output aborted.\x00NULL VP8Io parameter in VP8Decode().\x00RIFF\x00WEBP\x00VP8X\x00VP8 \x00VP8L\x00ALPH\x00assembler statements not supported\x00cpu.c\x00GetCPUInfo\x00xgetbv\x00"