go-libwebp

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

libwebp_windows_amd64.go (2132579B)


      1 // Code generated for windows/amd64 by 'ccgo --goos=windows --goarch=amd64 --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_amd64.go -DNDEBUG -DHAVE_CONFIG_H -I/tmp/tmp.jLmqxibQOP -I. src/dec/alpha_dec.c src/dec/buffer_dec.c src/dec/frame_dec.c src/dec/idec_dec.c src/dec/io_dec.c src/dec/quant_dec.c src/dec/tree_dec.c src/dec/vp8_dec.c src/dec/vp8l_dec.c src/dec/webp_dec.c src/enc/alpha_enc.c src/enc/analysis_enc.c src/enc/backward_references_cost_enc.c src/enc/backward_references_enc.c src/enc/config_enc.c src/enc/cost_enc.c src/enc/filter_enc.c src/enc/frame_enc.c src/enc/histogram_enc.c src/enc/iterator_enc.c src/enc/near_lossless_enc.c src/enc/picture_csp_enc.c src/enc/picture_enc.c src/enc/picture_psnr_enc.c src/enc/picture_rescale_enc.c src/enc/picture_tools_enc.c src/enc/predictor_enc.c src/enc/quant_enc.c src/enc/syntax_enc.c src/enc/token_enc.c src/enc/tree_enc.c src/enc/vp8l_enc.c src/enc/webp_enc.c src/utils/bit_reader_utils.c src/utils/bit_writer_utils.c src/utils/color_cache_utils.c src/utils/filters_utils.c src/utils/huffman_encode_utils.c src/utils/huffman_utils.c src/utils/palette.c src/utils/quant_levels_dec_utils.c src/utils/quant_levels_utils.c src/utils/random_utils.c src/utils/rescaler_utils.c src/utils/thread_utils.c src/utils/utils.c src/dsp/alpha_processing.c src/dsp/alpha_processing_mips_dsp_r2.c src/dsp/alpha_processing_neon.c src/dsp/alpha_processing_sse2.c src/dsp/alpha_processing_sse41.c src/dsp/cost.c src/dsp/cost_mips32.c src/dsp/cost_mips_dsp_r2.c src/dsp/cost_neon.c src/dsp/cost_sse2.c src/dsp/cpu.c src/dsp/dec.c src/dsp/dec_clip_tables.c src/dsp/dec_mips32.c src/dsp/dec_mips_dsp_r2.c src/dsp/dec_msa.c src/dsp/dec_neon.c src/dsp/dec_sse2.c src/dsp/dec_sse41.c src/dsp/enc.c src/dsp/enc_mips32.c src/dsp/enc_mips_dsp_r2.c src/dsp/enc_msa.c src/dsp/enc_neon.c src/dsp/enc_sse2.c src/dsp/enc_sse41.c src/dsp/filters.c src/dsp/filters_mips_dsp_r2.c src/dsp/filters_msa.c src/dsp/filters_neon.c src/dsp/filters_sse2.c src/dsp/lossless_avx2.c src/dsp/lossless.c src/dsp/lossless_enc_avx2.c src/dsp/lossless_enc.c src/dsp/lossless_enc_mips32.c src/dsp/lossless_enc_mips_dsp_r2.c src/dsp/lossless_enc_msa.c src/dsp/lossless_enc_neon.c src/dsp/lossless_enc_sse2.c src/dsp/lossless_enc_sse41.c src/dsp/lossless_mips_dsp_r2.c src/dsp/lossless_msa.c src/dsp/lossless_neon.c src/dsp/lossless_sse2.c src/dsp/lossless_sse41.c src/dsp/rescaler.c src/dsp/rescaler_mips32.c src/dsp/rescaler_mips_dsp_r2.c src/dsp/rescaler_msa.c src/dsp/rescaler_neon.c src/dsp/rescaler_sse2.c src/dsp/ssim.c src/dsp/ssim_sse2.c src/dsp/upsampling.c src/dsp/upsampling_mips_dsp_r2.c src/dsp/upsampling_msa.c src/dsp/upsampling_neon.c src/dsp/upsampling_sse2.c src/dsp/upsampling_sse41.c src/dsp/yuv.c src/dsp/yuv_mips32.c src/dsp/yuv_mips_dsp_r2.c src/dsp/yuv_neon.c src/dsp/yuv_sse2.c src/dsp/yuv_sse41.c /home/jfm/Source/Personal/go-libwebp/tools/sharpyuv_stub.c', DO NOT EDIT.
      2 
      3 //go:build windows && amd64
      4 
      5 package webp
      6 
      7 import (
      8 	"math"
      9 	"reflect"
     10 	"unsafe"
     11 
     12 	"modernc.org/libc"
     13 )
     14 
     15 var _ = math.Pi
     16 var _ reflect.Type
     17 var _ unsafe.Pointer
     18 
     19 const ALPHA_HEADER_LEN = 1
     20 const ALPHA_LOSSLESS_COMPRESSION = 1
     21 const ALPHA_NO_COMPRESSION = 0
     22 const ALPHA_PREPROCESSED_LEVELS = 1
     23 const ANIM_CHUNK_SIZE = 6
     24 const ANMF_CHUNK_SIZE = 16
     25 const ARGB_BLACK = 0xff000000
     26 const BITS = 56
     27 const BITTRACE = 0
     28 const BPS = 32
     29 const CHUNK_HEADER_SIZE = 8
     30 const CHUNK_SIZE_BYTES = 4
     31 const CODE_LENGTH_CODES = 19
     32 const DEC_MAJ_VERSION = 1
     33 const DEC_MIN_VERSION = 6
     34 const DEC_REV_VERSION = 0
     35 const DEFAULT_CODE_LENGTH = 8
     36 const 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__ = 17
    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__ = 36
    555 const __FLT64X_DENORM_MIN__ = 6.47517511943802511092443895822764655e-4966
    556 const __FLT64X_DIG__ = 33
    557 const __FLT64X_EPSILON__ = 1.92592994438723585305597794258492732e-34
    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__ = 113
    563 const __FLT64X_MAX_10_EXP__ = 4932
    564 const __FLT64X_MAX_EXP__ = 16384
    565 const __FLT64X_MAX__ = "1.18973149535723176508575932662800702e+4932"
    566 const __FLT64X_MIN__ = 3.36210314311209350626267781732175260e-4932
    567 const __FLT64X_NORM_MAX__ = "1.18973149535723176508575932662800702e+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__ = 2
    587 const __FLT_EVAL_METHOD__ = 2
    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__ = 17
    664 const __LDBL_DENORM_MIN__ = 4.94065645841246544176568792868221372e-324
    665 const __LDBL_DIG__ = 15
    666 const __LDBL_EPSILON__ = 2.22044604925031308084726333618164062e-16
    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__ = 53
    672 const __LDBL_MAX_10_EXP__ = 308
    673 const __LDBL_MAX_EXP__ = 1024
    674 const __LDBL_MAX__ = 1.79769313486231570814527423731704357e+308
    675 const __LDBL_MIN__ = 2.22507385850720138309023271733240406e-308
    676 const __LDBL_NORM_MAX__ = 1.79769313486231570814527423731704357e+308
    677 const __LONG32 = "long"
    678 const __LONG_DOUBLE_64__ = 1
    679 const __LONG_LONG_MAX__ = 0x7fffffffffffffff
    680 const __LONG_LONG_WIDTH__ = 64
    681 const __LONG_MAX__ = 0x7fffffff
    682 const __LONG_WIDTH__ = 32
    683 const __MINGW32_MAJOR_VERSION = 3
    684 const __MINGW32_MINOR_VERSION = 11
    685 const __MINGW32__ = 1
    686 const __MINGW64_VERSION_BUGFIX = 0
    687 const __MINGW64_VERSION_MAJOR = 14
    688 const __MINGW64_VERSION_MINOR = 0
    689 const __MINGW64_VERSION_RC = 0
    690 const __MINGW64_VERSION_STATE = "alpha"
    691 const __MINGW64__ = 1
    692 const __MINGW_DEBUGBREAK_IMPL = 1
    693 const __MINGW_FASTFAIL_IMPL = 1
    694 const __MINGW_FORTIFY_LEVEL = 0
    695 const __MINGW_FORTIFY_VA_ARG = 0
    696 const __MINGW_HAVE_ANSI_C99_PRINTF = 1
    697 const __MINGW_HAVE_ANSI_C99_SCANF = 1
    698 const __MINGW_HAVE_WIDE_C99_PRINTF = 1
    699 const __MINGW_HAVE_WIDE_C99_SCANF = 1
    700 const __MINGW_MSVC2005_DEPREC_STR = "This POSIX function is deprecated beginning in Visual C++ 2005, use _CRT_NONSTDC_NO_DEPRECATE to disable deprecation"
    701 const __MINGW_PREFETCH_IMPL = 1
    702 const __MINGW_SEC_WARN_STR = "This function or variable may be unsafe, use _CRT_SECURE_NO_WARNINGS to disable deprecation"
    703 const __MINGW_USE_UNDERSCORE_PREFIX = 0
    704 const __MSVCRT_VERSION__ = 0xE00
    705 const __MSVCRT__ = 1
    706 const __NO_INLINE__ = 1
    707 const __ORDER_BIG_ENDIAN__ = 4321
    708 const __ORDER_LITTLE_ENDIAN__ = 1234
    709 const __ORDER_PDP_ENDIAN__ = 3412
    710 const __PIC__ = 1
    711 const __PRAGMA_REDEFINE_EXTNAME = 1
    712 const __PRETTY_FUNCTION__ = "__func__"
    713 const __PTRDIFF_MAX__ = 0x7fffffffffffffff
    714 const __PTRDIFF_WIDTH__ = 64
    715 const __SCHAR_MAX__ = 0x7f
    716 const __SCHAR_WIDTH__ = 8
    717 const __SEG_FS = 1
    718 const __SEG_GS = 1
    719 const __SEH__ = 1
    720 const __SHRT_MAX__ = 0x7fff
    721 const __SHRT_WIDTH__ = 16
    722 const __SIG_ATOMIC_MAX__ = 0x7fffffff
    723 const __SIG_ATOMIC_TYPE__ = "int"
    724 const __SIG_ATOMIC_WIDTH__ = 32
    725 const __SIZEOF_DOUBLE__ = 8
    726 const __SIZEOF_FLOAT128__ = 16
    727 const __SIZEOF_FLOAT80__ = 16
    728 const __SIZEOF_FLOAT__ = 4
    729 const __SIZEOF_INT128__ = 16
    730 const __SIZEOF_INT__ = 4
    731 const __SIZEOF_LONG_DOUBLE__ = 8
    732 const __SIZEOF_LONG_LONG__ = 8
    733 const __SIZEOF_LONG__ = 4
    734 const __SIZEOF_POINTER__ = 8
    735 const __SIZEOF_PTRDIFF_T__ = 8
    736 const __SIZEOF_SHORT__ = 2
    737 const __SIZEOF_SIZE_T__ = 8
    738 const __SIZEOF_WCHAR_T__ = 2
    739 const __SIZEOF_WINT_T__ = 2
    740 const __SIZE_MAX__ = "0xffffffffffffffffU"
    741 const __SIZE_WIDTH__ = 64
    742 const __STDC_EMBED_EMPTY__ = 2
    743 const __STDC_EMBED_FOUND__ = 1
    744 const __STDC_EMBED_NOT_FOUND__ = 0
    745 const __STDC_HOSTED__ = 1
    746 const __STDC_SECURE_LIB__ = 200411
    747 const __STDC_UTF_16__ = 1
    748 const __STDC_UTF_32__ = 1
    749 const __STDC_VERSION_LIMITS_H__ = 202311
    750 const __STDC_VERSION__ = 202311
    751 const __STDC__ = 1
    752 const __UINT16_MAX__ = 0xffff
    753 const __UINT32_MAX__ = 0xffffffff
    754 const __UINT64_MAX__ = "0xffffffffffffffffU"
    755 const __UINT8_MAX__ = 0xff
    756 const __UINTMAX_MAX__ = "0xffffffffffffffffU"
    757 const __UINTPTR_MAX__ = "0xffffffffffffffffU"
    758 const __UINT_FAST16_MAX__ = 0xffff
    759 const __UINT_FAST32_MAX__ = 0xffffffff
    760 const __UINT_FAST64_MAX__ = "0xffffffffffffffffU"
    761 const __UINT_FAST8_MAX__ = 0xff
    762 const __UINT_LEAST16_MAX__ = 0xffff
    763 const __UINT_LEAST32_MAX__ = 0xffffffff
    764 const __UINT_LEAST64_MAX__ = "0xffffffffffffffffU"
    765 const __UINT_LEAST8_MAX__ = 0xff
    766 const __USE_MINGW_ANSI_STDIO = 0
    767 const __USING_POSIXTHREAD__ = 1
    768 const __VERSION__ = "16.2.0"
    769 const __WCHAR_MAX__ = 0xffff
    770 const __WCHAR_MIN__ = 0
    771 const __WCHAR_WIDTH__ = 16
    772 const __WIN32 = 1
    773 const __WIN32__ = 1
    774 const __WIN64 = 1
    775 const __WIN64__ = 1
    776 const __WINNT = 1
    777 const __WINNT__ = 1
    778 const __WINT_MAX__ = 0xffff
    779 const __WINT_MIN__ = 0
    780 const __WINT_WIDTH__ = 16
    781 const __amd64 = 1
    782 const __amd64__ = 1
    783 const __code_model_medium__ = 1
    784 const __int16 = "short"
    785 const __int32 = "int"
    786 const __int8 = "char"
    787 const __k8 = 1
    788 const __k8__ = 1
    789 const __mingw_bos_ovr = "__mingw_ovr"
    790 const __pic__ = 1
    791 const __x86_64 = 1
    792 const __x86_64__ = 1
    793 const _inline = "__inline"
    794 const environ1 = "_environ"
    795 const false1 = 0
    796 const onexit_t = "_onexit_t"
    797 const sys_errlist = "_sys_errlist"
    798 const sys_nerr = "_sys_nerr"
    799 const true1 = 1
    800 const wcswcs = "wcsstr"
    801 
    802 /* C23 keywords, no longer defined as macros by <stdbool.h> and <stddef.h>. */
    803 
    804 type __builtin_va_list = uintptr
    805 
    806 type __predefined_size_t = uint64
    807 
    808 type __predefined_wchar_t = uint16
    809 
    810 type __predefined_ptrdiff_t = int64
    811 
    812 type __gnuc_va_list = uintptr
    813 
    814 type va_list = uintptr
    815 
    816 type size_t = uint64
    817 
    818 type ssize_t = int64
    819 
    820 type rsize_t = uint64
    821 
    822 type intptr_t = int64
    823 
    824 type uintptr_t = uint64
    825 
    826 type ptrdiff_t = int64
    827 
    828 type wchar_t = uint16
    829 
    830 type wint_t = uint16
    831 
    832 type wctype_t = uint16
    833 
    834 type errno_t = int32
    835 
    836 type __time32_t = int32
    837 
    838 type __time64_t = int64
    839 
    840 type time_t = int64
    841 
    842 type threadlocaleinfostruct = struct {
    843 	F_locale_pctype      uintptr
    844 	F_locale_mb_cur_max  int32
    845 	F_locale_lc_codepage uint32
    846 }
    847 
    848 type pthreadlocinfo = uintptr
    849 
    850 type pthreadmbcinfo = uintptr
    851 
    852 type _locale_tstruct = struct {
    853 	Flocinfo pthreadlocinfo
    854 	Fmbcinfo pthreadmbcinfo
    855 }
    856 
    857 type localeinfo_struct = _locale_tstruct
    858 
    859 type _locale_t = uintptr
    860 
    861 type LC_ID = struct {
    862 	FwLanguage uint16
    863 	FwCountry  uint16
    864 	FwCodePage uint16
    865 }
    866 
    867 type tagLC_ID = LC_ID
    868 
    869 type LPLC_ID = uintptr
    870 
    871 type threadlocinfo = struct {
    872 	F_locale_pctype      uintptr
    873 	F_locale_mb_cur_max  int32
    874 	F_locale_lc_codepage uint32
    875 }
    876 
    877 type _onexit_t = uintptr
    878 
    879 type div_t = struct {
    880 	Fquot int32
    881 	Frem  int32
    882 }
    883 
    884 type _div_t = div_t
    885 
    886 type ldiv_t = struct {
    887 	Fquot int32
    888 	Frem  int32
    889 }
    890 
    891 type _ldiv_t = ldiv_t
    892 
    893 type _LDOUBLE = struct {
    894 	Fld [10]uint8
    895 }
    896 
    897 type _CRT_DOUBLE = struct {
    898 	Fx float64
    899 }
    900 
    901 type _CRT_FLOAT = struct {
    902 	Ff float32
    903 }
    904 
    905 type _LONGDOUBLE = struct {
    906 	Fx float64
    907 }
    908 
    909 type _LDBL12 = struct {
    910 	Fld12 [12]uint8
    911 }
    912 
    913 type _purecall_handler = uintptr
    914 
    915 type _invalid_parameter_handler = uintptr
    916 
    917 type lldiv_t = struct {
    918 	Fquot int64
    919 	Frem  int64
    920 }
    921 
    922 type _HEAPINFO = struct {
    923 	F_pentry  uintptr
    924 	F_size    size_t
    925 	F_useflag int32
    926 }
    927 
    928 type _heapinfo = _HEAPINFO
    929 
    930 type max_align_t = struct {
    931 	F__max_align_ll int64
    932 	F__max_align_ld float64
    933 }
    934 
    935 type int8_t = int8
    936 
    937 type uint8_t = uint8
    938 
    939 type int16_t = int16
    940 
    941 type uint16_t = uint16
    942 
    943 type int32_t = int32
    944 
    945 type uint32_t = uint32
    946 
    947 type int64_t = int64
    948 
    949 type uint64_t = uint64
    950 
    951 type int_least8_t = int8
    952 
    953 type uint_least8_t = uint8
    954 
    955 type int_least16_t = int16
    956 
    957 type uint_least16_t = uint16
    958 
    959 type int_least32_t = int32
    960 
    961 type uint_least32_t = uint32
    962 
    963 type int_least64_t = int64
    964 
    965 type uint_least64_t = uint64
    966 
    967 type int_fast8_t = int8
    968 
    969 type uint_fast8_t = uint8
    970 
    971 type int_fast16_t = int16
    972 
    973 type uint_fast16_t = uint16
    974 
    975 type int_fast32_t = int32
    976 
    977 type uint_fast32_t = uint32
    978 
    979 type int_fast64_t = int64
    980 
    981 type uint_fast64_t = uint64
    982 
    983 type intmax_t = int64
    984 
    985 type uintmax_t = uint64
    986 
    987 type imaxdiv_t = struct {
    988 	Fquot intmax_t
    989 	Frem  intmax_t
    990 }
    991 
    992 type WebPRGBABuffer = struct {
    993 	Frgba   uintptr
    994 	Fstride int32
    995 	Fsize   size_t
    996 }
    997 
    998 type WebPYUVABuffer = struct {
    999 	Fy        uintptr
   1000 	Fu        uintptr
   1001 	Fv        uintptr
   1002 	Fa        uintptr
   1003 	Fy_stride int32
   1004 	Fu_stride int32
   1005 	Fv_stride int32
   1006 	Fa_stride int32
   1007 	Fy_size   size_t
   1008 	Fu_size   size_t
   1009 	Fv_size   size_t
   1010 	Fa_size   size_t
   1011 }
   1012 
   1013 type WebPDecBuffer = struct {
   1014 	Fcolorspace         WEBP_CSP_MODE1
   1015 	Fwidth              int32
   1016 	Fheight             int32
   1017 	Fis_external_memory int32
   1018 	Fu                  struct {
   1019 		FYUVA        [0]WebPYUVABuffer
   1020 		FRGBA        WebPRGBABuffer
   1021 		F__ccgo_pad2 [56]byte
   1022 	}
   1023 	Fpad            [4]uint32_t
   1024 	Fprivate_memory uintptr
   1025 }
   1026 
   1027 type WEBP_CSP_MODE = int32
   1028 
   1029 const MODE_RGB = 0
   1030 const MODE_RGBA = 1
   1031 const MODE_BGR = 2
   1032 const MODE_BGRA = 3
   1033 const MODE_ARGB = 4
   1034 const MODE_RGBA_4444 = 5
   1035 const MODE_RGB_565 = 6
   1036 const MODE_rgbA = 7
   1037 const MODE_bgrA = 8
   1038 const MODE_Argb = 9
   1039 const MODE_rgbA_4444 = 10
   1040 const MODE_YUV = 11
   1041 const MODE_YUVA = 12
   1042 const MODE_LAST = 13
   1043 
   1044 type WebPBitstreamFeatures = struct {
   1045 	Fwidth         int32
   1046 	Fheight        int32
   1047 	Fhas_alpha     int32
   1048 	Fhas_animation int32
   1049 	Fformat        int32
   1050 	Fpad           [5]uint32_t
   1051 }
   1052 
   1053 type WebPDecoderOptions = struct {
   1054 	Fbypass_filtering         int32
   1055 	Fno_fancy_upsampling      int32
   1056 	Fuse_cropping             int32
   1057 	Fcrop_left                int32
   1058 	Fcrop_top                 int32
   1059 	Fcrop_width               int32
   1060 	Fcrop_height              int32
   1061 	Fuse_scaling              int32
   1062 	Fscaled_width             int32
   1063 	Fscaled_height            int32
   1064 	Fuse_threads              int32
   1065 	Fdithering_strength       int32
   1066 	Fflip                     int32
   1067 	Falpha_dithering_strength int32
   1068 	Fpad                      [5]uint32_t
   1069 }
   1070 
   1071 type WebPDecoderConfig = struct {
   1072 	Finput   WebPBitstreamFeatures
   1073 	Foutput  WebPDecBuffer
   1074 	Foptions WebPDecoderOptions
   1075 }
   1076 
   1077 type WEBP_CSP_MODE1 = int32
   1078 
   1079 type VP8StatusCode1 = int32
   1080 
   1081 type VP8StatusCode = int32
   1082 
   1083 const VP8_STATUS_OK = 0
   1084 const VP8_STATUS_OUT_OF_MEMORY = 1
   1085 const VP8_STATUS_INVALID_PARAM = 2
   1086 const VP8_STATUS_BITSTREAM_ERROR = 3
   1087 const VP8_STATUS_UNSUPPORTED_FEATURE = 4
   1088 const VP8_STATUS_SUSPENDED = 5
   1089 const VP8_STATUS_USER_ABORT = 6
   1090 const VP8_STATUS_NOT_ENOUGH_DATA = 7
   1091 
   1092 type VP8Io = struct {
   1093 	Fwidth            int32
   1094 	Fheight           int32
   1095 	Fmb_y             int32
   1096 	Fmb_w             int32
   1097 	Fmb_h             int32
   1098 	Fy                uintptr
   1099 	Fu                uintptr
   1100 	Fv                uintptr
   1101 	Fy_stride         int32
   1102 	Fuv_stride        int32
   1103 	Fopaque           uintptr
   1104 	Fput              VP8IoPutHook
   1105 	Fsetup            VP8IoSetupHook
   1106 	Fteardown         VP8IoTeardownHook
   1107 	Ffancy_upsampling int32
   1108 	Fdata_size        size_t
   1109 	Fdata             uintptr
   1110 	Fbypass_filtering int32
   1111 	Fuse_cropping     int32
   1112 	Fcrop_left        int32
   1113 	Fcrop_right       int32
   1114 	Fcrop_top         int32
   1115 	Fcrop_bottom      int32
   1116 	Fuse_scaling      int32
   1117 	Fscaled_width     int32
   1118 	Fscaled_height    int32
   1119 	Fa                uintptr
   1120 }
   1121 
   1122 type VP8IoPutHook = uintptr
   1123 
   1124 type VP8IoSetupHook = uintptr
   1125 
   1126 type VP8IoTeardownHook = uintptr
   1127 
   1128 type VP8Decoder = struct {
   1129 	Fstatus              VP8StatusCode1
   1130 	Fready               int32
   1131 	Ferror_msg           uintptr
   1132 	Fbr                  VP8BitReader
   1133 	Fincremental         int32
   1134 	Ffrm_hdr             VP8FrameHeader
   1135 	Fpic_hdr             VP8PictureHeader
   1136 	Ffilter_hdr          VP8FilterHeader
   1137 	Fsegment_hdr         VP8SegmentHeader
   1138 	Fworker              WebPWorker
   1139 	Fmt_method           int32
   1140 	Fcache_id            int32
   1141 	Fnum_caches          int32
   1142 	Fthread_ctx          VP8ThreadContext
   1143 	Fmb_w                int32
   1144 	Fmb_h                int32
   1145 	Ftl_mb_x             int32
   1146 	Ftl_mb_y             int32
   1147 	Fbr_mb_x             int32
   1148 	Fbr_mb_y             int32
   1149 	Fnum_parts_minus_one uint32_t
   1150 	Fparts               [8]VP8BitReader
   1151 	Fdither              int32
   1152 	Fdithering_rg        VP8Random
   1153 	Fdqm                 [4]VP8QuantMatrix
   1154 	Fproba               VP8Proba
   1155 	Fuse_skip_proba      int32
   1156 	Fskip_p              uint8_t
   1157 	Fintra_t             uintptr
   1158 	Fintra_l             [4]uint8_t
   1159 	Fyuv_t               uintptr
   1160 	Fmb_info             uintptr
   1161 	Ff_info              uintptr
   1162 	Fyuv_b               uintptr
   1163 	Fcache_y             uintptr
   1164 	Fcache_u             uintptr
   1165 	Fcache_v             uintptr
   1166 	Fcache_y_stride      int32
   1167 	Fcache_uv_stride     int32
   1168 	Fmem                 uintptr
   1169 	Fmem_size            size_t
   1170 	Fmb_x                int32
   1171 	Fmb_y                int32
   1172 	Fmb_data             uintptr
   1173 	Ffilter_type         int32
   1174 	Ffstrengths          [4][2]VP8FInfo
   1175 	Falph_dec            uintptr
   1176 	Falpha_data          uintptr
   1177 	Falpha_data_size     size_t
   1178 	Fis_alpha_decoded    int32
   1179 	Falpha_plane_mem     uintptr
   1180 	Falpha_plane         uintptr
   1181 	Falpha_prev_line     uintptr
   1182 	Falpha_dithering     int32
   1183 }
   1184 
   1185 type rescaler_t = uint32
   1186 
   1187 type WebPRescaler = struct {
   1188 	Fx_expand     int32
   1189 	Fy_expand     int32
   1190 	Fnum_channels int32
   1191 	Ffx_scale     uint32_t
   1192 	Ffy_scale     uint32_t
   1193 	Ffxy_scale    uint32_t
   1194 	Fy_accum      int32
   1195 	Fy_add        int32
   1196 	Fy_sub        int32
   1197 	Fx_add        int32
   1198 	Fx_sub        int32
   1199 	Fsrc_width    int32
   1200 	Fsrc_height   int32
   1201 	Fdst_width    int32
   1202 	Fdst_height   int32
   1203 	Fsrc_y        int32
   1204 	Fdst_y        int32
   1205 	Fdst          uintptr
   1206 	Fdst_stride   int32
   1207 	Firow         uintptr
   1208 	Ffrow         uintptr
   1209 }
   1210 
   1211 type WebPDecParams = struct {
   1212 	Foutput         uintptr
   1213 	Ftmp_y          uintptr
   1214 	Ftmp_u          uintptr
   1215 	Ftmp_v          uintptr
   1216 	Flast_y         int32
   1217 	Foptions        uintptr
   1218 	Fscaler_y       uintptr
   1219 	Fscaler_u       uintptr
   1220 	Fscaler_v       uintptr
   1221 	Fscaler_a       uintptr
   1222 	Fmemory         uintptr
   1223 	Femit           OutputFunc
   1224 	Femit_alpha     OutputAlphaFunc
   1225 	Femit_alpha_row OutputRowFunc
   1226 }
   1227 
   1228 type OutputFunc = uintptr
   1229 
   1230 type OutputAlphaFunc = uintptr
   1231 
   1232 type OutputRowFunc = uintptr
   1233 
   1234 type WebPHeaderStructure = struct {
   1235 	Fdata            uintptr
   1236 	Fdata_size       size_t
   1237 	Fhave_all_data   int32
   1238 	Foffset          size_t
   1239 	Falpha_data      uintptr
   1240 	Falpha_data_size size_t
   1241 	Fcompressed_size size_t
   1242 	Friff_size       size_t
   1243 	Fis_lossless     int32
   1244 }
   1245 
   1246 type CPUFeature = int32
   1247 
   1248 const kSSE2 = 0
   1249 const kSSE3 = 1
   1250 const kSlowSSSE3 = 2
   1251 const kSSE4_1 = 3
   1252 const kAVX = 4
   1253 const kAVX2 = 5
   1254 const kNEON = 6
   1255 const kMIPS32 = 7
   1256 const kMIPSdspR2 = 8
   1257 const kMSA = 9
   1258 
   1259 type VP8CPUInfo = uintptr
   1260 
   1261 type VP8Idct = uintptr
   1262 
   1263 type VP8Fdct = uintptr
   1264 
   1265 type VP8WHT = uintptr
   1266 
   1267 type VP8IntraPreds = uintptr
   1268 
   1269 type VP8Intra4Preds = uintptr
   1270 
   1271 type VP8Metric = uintptr
   1272 
   1273 type VP8WMetric = uintptr
   1274 
   1275 type VP8MeanMetric = uintptr
   1276 
   1277 type VP8BlockCopy = uintptr
   1278 
   1279 type VP8QuantizeBlock = uintptr
   1280 
   1281 type VP8Quantize2Blocks = uintptr
   1282 
   1283 type VP8QuantizeBlockWHT = uintptr
   1284 
   1285 type VP8Histogram = struct {
   1286 	Fmax_value     int32
   1287 	Flast_non_zero int32
   1288 }
   1289 
   1290 type VP8CHisto = uintptr
   1291 
   1292 type VP8SetResidualCoeffsFunc = uintptr
   1293 
   1294 type VP8GetResidualCostFunc = uintptr
   1295 
   1296 type VP8DistoStats = struct {
   1297 	Fw   uint32_t
   1298 	Fxm  uint32_t
   1299 	Fym  uint32_t
   1300 	Fxxm uint32_t
   1301 	Fxym uint32_t
   1302 	Fyym uint32_t
   1303 }
   1304 
   1305 type VP8SSIMGetClippedFunc = uintptr
   1306 
   1307 type VP8SSIMGetFunc = uintptr
   1308 
   1309 type VP8AccumulateSSEFunc = uintptr
   1310 
   1311 type VP8DecIdct = uintptr
   1312 
   1313 type VP8DecIdct2 = uintptr
   1314 
   1315 type VP8PredFunc = uintptr
   1316 
   1317 type VP8SimpleFilterFunc = uintptr
   1318 
   1319 type VP8LumaFilterFunc = uintptr
   1320 
   1321 type VP8ChromaFilterFunc = uintptr
   1322 
   1323 type WebPUpsampleLinePairFunc = uintptr
   1324 
   1325 type WebPSamplerRowFunc = uintptr
   1326 
   1327 type WebPYUV444Converter = uintptr
   1328 
   1329 type WebPRescalerImportRowFunc = uintptr
   1330 
   1331 type WebPRescalerExportRowFunc = uintptr
   1332 
   1333 type WEBP_FILTER_TYPE = int32
   1334 
   1335 const WEBP_FILTER_NONE = 0
   1336 const WEBP_FILTER_HORIZONTAL = 1
   1337 const WEBP_FILTER_VERTICAL = 2
   1338 const WEBP_FILTER_GRADIENT = 3
   1339 const WEBP_FILTER_LAST = 4
   1340 const WEBP_FILTER_BEST = 5
   1341 const WEBP_FILTER_FAST = 6
   1342 
   1343 type WebPFilterFunc = uintptr
   1344 
   1345 type WebPUnfilterFunc = uintptr
   1346 
   1347 type VP8LDecoder = struct {
   1348 	Fstatus           VP8StatusCode1
   1349 	Fstate            VP8LDecodeState
   1350 	Fio               uintptr
   1351 	Foutput           uintptr
   1352 	Fpixels           uintptr
   1353 	Fargb_cache       uintptr
   1354 	Fbr               VP8LBitReader
   1355 	Fincremental      int32
   1356 	Fsaved_br         VP8LBitReader
   1357 	Fsaved_last_pixel int32
   1358 	Fwidth            int32
   1359 	Fheight           int32
   1360 	Flast_row         int32
   1361 	Flast_pixel       int32
   1362 	Flast_out_row     int32
   1363 	Fhdr              VP8LMetadata
   1364 	Fnext_transform   int32
   1365 	Ftransforms       [4]VP8LTransform
   1366 	Ftransforms_seen  uint32_t
   1367 	Frescaler_memory  uintptr
   1368 	Frescaler         uintptr
   1369 }
   1370 
   1371 const READ_DATA = 0
   1372 const READ_HDR = 1
   1373 const READ_DIM = 2
   1374 
   1375 type ALPHDecoder = struct {
   1376 	Fwidth          int32
   1377 	Fheight         int32
   1378 	Fmethod         int32
   1379 	Ffilter         WEBP_FILTER_TYPE
   1380 	Fpre_processing int32
   1381 	Fvp8l_dec       uintptr
   1382 	Fio             VP8Io
   1383 	Fuse_8b_decode  int32
   1384 	Foutput         uintptr
   1385 	Fprev_line      uintptr
   1386 }
   1387 
   1388 const B_DC_PRED = 0
   1389 const B_TM_PRED = 1
   1390 const B_VE_PRED = 2
   1391 const B_HE_PRED = 3
   1392 const B_RD_PRED = 4
   1393 const B_VR_PRED = 5
   1394 const B_LD_PRED = 6
   1395 const B_VL_PRED = 7
   1396 const B_HD_PRED = 8
   1397 const B_HU_PRED = 9
   1398 const NUM_BMODES = 10
   1399 const DC_PRED = 0
   1400 const V_PRED = 2
   1401 const H_PRED = 3
   1402 const TM_PRED = 1
   1403 const B_PRED = 10
   1404 const NUM_PRED_MODES = 4
   1405 const B_DC_PRED_NOTOP = 4
   1406 const B_DC_PRED_NOLEFT = 5
   1407 const B_DC_PRED_NOTOPLEFT = 6
   1408 const NUM_B_DC_MODES = 7
   1409 const MB_FEATURE_TREE_PROBS = 3
   1410 const NUM_MB_SEGMENTS = 4
   1411 const NUM_REF_LF_DELTAS = 4
   1412 const NUM_MODE_LF_DELTAS = 4
   1413 const MAX_NUM_PARTITIONS = 8
   1414 const NUM_TYPES = 4
   1415 const NUM_BANDS = 8
   1416 const NUM_CTX = 3
   1417 const NUM_PROBAS = 11
   1418 
   1419 type bit_t = uint64
   1420 
   1421 type range_t = uint32
   1422 
   1423 type VP8BitReader = struct {
   1424 	Fvalue   bit_t
   1425 	Frange1  range_t
   1426 	Fbits    int32
   1427 	Fbuf     uintptr
   1428 	Fbuf_end uintptr
   1429 	Fbuf_max uintptr
   1430 	Feof     int32
   1431 }
   1432 
   1433 type vp8l_val_t = uint64
   1434 
   1435 type VP8LBitReader = struct {
   1436 	Fval     vp8l_val_t
   1437 	Fbuf     uintptr
   1438 	Flen1    size_t
   1439 	Fpos     size_t
   1440 	Fbit_pos int32
   1441 	Feos     int32
   1442 }
   1443 
   1444 type VP8LColorCache = struct {
   1445 	Fcolors     uintptr
   1446 	Fhash_shift int32
   1447 	Fhash_bits  int32
   1448 }
   1449 
   1450 var kHashMul = uint32(0x1e35a7bd)
   1451 
   1452 type VP8LImageTransformType = int32
   1453 
   1454 const PREDICTOR_TRANSFORM = 0
   1455 const CROSS_COLOR_TRANSFORM = 1
   1456 const SUBTRACT_GREEN_TRANSFORM = 2
   1457 const COLOR_INDEXING_TRANSFORM = 3
   1458 
   1459 type HuffmanCode = struct {
   1460 	Fbits  uint8_t
   1461 	Fvalue uint16_t
   1462 }
   1463 
   1464 type HuffmanCode32 = struct {
   1465 	Fbits  int32
   1466 	Fvalue uint32_t
   1467 }
   1468 
   1469 type HuffmanTablesSegment = struct {
   1470 	Fstart      uintptr
   1471 	Fcurr_table uintptr
   1472 	Fnext       uintptr
   1473 	Fsize       int32
   1474 }
   1475 
   1476 type HuffmanTables = struct {
   1477 	Froot         HuffmanTablesSegment
   1478 	Fcurr_segment uintptr
   1479 }
   1480 
   1481 type HTreeGroup = struct {
   1482 	Fhtrees             [5]uintptr
   1483 	Fis_trivial_literal int32
   1484 	Fliteral_arb        uint32_t
   1485 	Fis_trivial_code    int32
   1486 	Fuse_packed_table   int32
   1487 	Fpacked_table       [64]HuffmanCode32
   1488 }
   1489 
   1490 type VP8LDecodeState = int32
   1491 
   1492 type VP8LTransform = struct {
   1493 	Ftype1 VP8LImageTransformType
   1494 	Fbits  int32
   1495 	Fxsize int32
   1496 	Fysize int32
   1497 	Fdata  uintptr
   1498 }
   1499 
   1500 type VP8LMetadata = struct {
   1501 	Fcolor_cache_size       int32
   1502 	Fcolor_cache            VP8LColorCache
   1503 	Fsaved_color_cache      VP8LColorCache
   1504 	Fhuffman_mask           int32
   1505 	Fhuffman_subsample_bits int32
   1506 	Fhuffman_xsize          int32
   1507 	Fhuffman_image          uintptr
   1508 	Fnum_htree_groups       int32
   1509 	Fhtree_groups           uintptr
   1510 	Fhuffman_tables         HuffmanTables
   1511 }
   1512 
   1513 type VP8Random = struct {
   1514 	Findex1 int32
   1515 	Findex2 int32
   1516 	Ftab    [55]uint32_t
   1517 	Famp    int32
   1518 }
   1519 
   1520 type WebPWorkerStatus = int32
   1521 
   1522 const NOT_OK = 0
   1523 const OK = 1
   1524 const WORK = 2
   1525 
   1526 type WebPWorkerHook = uintptr
   1527 
   1528 type WebPWorker = struct {
   1529 	Fimpl      uintptr
   1530 	Fstatus    WebPWorkerStatus
   1531 	Fhook      WebPWorkerHook
   1532 	Fdata1     uintptr
   1533 	Fdata2     uintptr
   1534 	Fhad_error int32
   1535 }
   1536 
   1537 type WebPWorkerInterface = struct {
   1538 	FInit    uintptr
   1539 	FReset   uintptr
   1540 	FSync    uintptr
   1541 	FLaunch  uintptr
   1542 	FExecute uintptr
   1543 	FEnd     uintptr
   1544 }
   1545 
   1546 type VP8FrameHeader = struct {
   1547 	Fkey_frame        uint8_t
   1548 	Fprofile          uint8_t
   1549 	Fshow             uint8_t
   1550 	Fpartition_length uint32_t
   1551 }
   1552 
   1553 type VP8PictureHeader = struct {
   1554 	Fwidth      uint16_t
   1555 	Fheight     uint16_t
   1556 	Fxscale     uint8_t
   1557 	Fyscale     uint8_t
   1558 	Fcolorspace uint8_t
   1559 	Fclamp_type uint8_t
   1560 }
   1561 
   1562 type VP8SegmentHeader = struct {
   1563 	Fuse_segment     int32
   1564 	Fupdate_map      int32
   1565 	Fabsolute_delta  int32
   1566 	Fquantizer       [4]int8_t
   1567 	Ffilter_strength [4]int8_t
   1568 }
   1569 
   1570 type VP8ProbaArray = [11]uint8_t
   1571 
   1572 type VP8BandProbas = struct {
   1573 	Fprobas [3]VP8ProbaArray
   1574 }
   1575 
   1576 type VP8Proba = struct {
   1577 	Fsegments  [3]uint8_t
   1578 	Fbands     [4][8]VP8BandProbas
   1579 	Fbands_ptr [4][17]uintptr
   1580 }
   1581 
   1582 type VP8FilterHeader = struct {
   1583 	Fsimple        int32
   1584 	Flevel         int32
   1585 	Fsharpness     int32
   1586 	Fuse_lf_delta  int32
   1587 	Fref_lf_delta  [4]int32
   1588 	Fmode_lf_delta [4]int32
   1589 }
   1590 
   1591 type VP8FInfo = struct {
   1592 	Ff_limit    uint8_t
   1593 	Ff_ilevel   uint8_t
   1594 	Ff_inner    uint8_t
   1595 	Fhev_thresh uint8_t
   1596 }
   1597 
   1598 type VP8MB = struct {
   1599 	Fnz    uint8_t
   1600 	Fnz_dc uint8_t
   1601 }
   1602 
   1603 type quant_t = [2]int32
   1604 
   1605 type VP8QuantMatrix = struct {
   1606 	Fy1_mat   quant_t
   1607 	Fy2_mat   quant_t
   1608 	Fuv_mat   quant_t
   1609 	Fuv_quant int32
   1610 	Fdither   int32
   1611 }
   1612 
   1613 type VP8MBData = struct {
   1614 	Fcoeffs      [384]int16_t
   1615 	Fis_i4x4     uint8_t
   1616 	Fimodes      [16]uint8_t
   1617 	Fuvmode      uint8_t
   1618 	Fnon_zero_y  uint32_t
   1619 	Fnon_zero_uv uint32_t
   1620 	Fdither      uint8_t
   1621 	Fskip        uint8_t
   1622 	Fsegment     uint8_t
   1623 }
   1624 
   1625 type VP8ThreadContext = struct {
   1626 	Fid         int32
   1627 	Fmb_y       int32
   1628 	Ffilter_row int32
   1629 	Ff_info     uintptr
   1630 	Fmb_data    uintptr
   1631 	Fio         VP8Io
   1632 }
   1633 
   1634 type VP8TopSamples = struct {
   1635 	Fy [16]uint8_t
   1636 	Fu [8]uint8_t
   1637 	Fv [8]uint8_t
   1638 }
   1639 
   1640 //------------------------------------------------------------------------------
   1641 
   1642 // Copyright 2010 Google Inc. All Rights Reserved.
   1643 //
   1644 // Use of this source code is governed by a BSD-style license
   1645 // that can be found in the COPYING file in the root of the source
   1646 // tree. An additional intellectual property rights grant can be found
   1647 // in the file PATENTS. All contributing project authors may
   1648 // be found in the AUTHORS file in the root of the source tree.
   1649 // -----------------------------------------------------------------------------
   1650 //
   1651 //  Main decoding functions for WebP images.
   1652 //
   1653 // Author: Skal (pascal.massimino@gmail.com)
   1654 
   1655 // Copyright 2012 Google Inc. All Rights Reserved.
   1656 //
   1657 // Use of this source code is governed by a BSD-style license
   1658 // that can be found in the COPYING file in the root of the source
   1659 // tree. An additional intellectual property rights grant can be found
   1660 // in the file PATENTS. All contributing project authors may
   1661 // be found in the AUTHORS file in the root of the source tree.
   1662 // -----------------------------------------------------------------------------
   1663 //
   1664 //  Internal header for constants related to WebP file format.
   1665 //
   1666 // Author: Urvang (urvang@google.com)
   1667 
   1668 // Copyright 2010 Google Inc. All Rights Reserved.
   1669 //
   1670 // Use of this source code is governed by a BSD-style license
   1671 // that can be found in the COPYING file in the root of the source
   1672 // tree. An additional intellectual property rights grant can be found
   1673 // in the file PATENTS. All contributing project authors may
   1674 // be found in the AUTHORS file in the root of the source tree.
   1675 // -----------------------------------------------------------------------------
   1676 //
   1677 //  Common types + memory wrappers
   1678 //
   1679 // Author: Skal (pascal.massimino@gmail.com)
   1680 
   1681 //------------------------------------------------------------------------------
   1682 // ALPHDecoder object.
   1683 
   1684 // C documentation
   1685 //
   1686 //	// Allocates a new alpha decoder instance.
   1687 func ALPHNew(tls *libc.TLS) (r uintptr) {
   1688 	var dec uintptr
   1689 	_ = dec
   1690 	dec = WebPSafeCalloc(tls, uint64(1), uint64(216))
   1691 	return dec
   1692 }
   1693 
   1694 // C documentation
   1695 //
   1696 //	// Clears and deallocates an alpha decoder instance.
   1697 func ALPHDelete(tls *libc.TLS, dec uintptr) {
   1698 	if dec != libc.UintptrFromInt32(0) {
   1699 		VP8LDelete(tls, (*ALPHDecoder)(unsafe.Pointer(dec)).Fvp8l_dec)
   1700 		(*ALPHDecoder)(unsafe.Pointer(dec)).Fvp8l_dec = libc.UintptrFromInt32(0)
   1701 		WebPSafeFree(tls, dec)
   1702 	}
   1703 }
   1704 
   1705 //------------------------------------------------------------------------------
   1706 // Decoding.
   1707 
   1708 // C documentation
   1709 //
   1710 //	// Initialize alpha decoding by parsing the alpha header and decoding the image
   1711 //	// header for alpha data stored using lossless compression.
   1712 //	// Returns false in case of error in alpha header (data too short, invalid
   1713 //	// compression method or filter, error in lossless header data etc).
   1714 func ALPHInit(tls *libc.TLS, dec uintptr, data uintptr, data_size size_t, src_io uintptr, output uintptr) (r int32) {
   1715 	var alpha_data, io1 uintptr
   1716 	var alpha_data_size, alpha_decoded_size size_t
   1717 	var ok, rsrv, v1 int32
   1718 	_, _, _, _, _, _, _ = alpha_data, alpha_data_size, alpha_decoded_size, io1, ok, rsrv, v1
   1719 	ok = 0
   1720 	alpha_data = data + uintptr(ALPHA_HEADER_LEN)
   1721 	alpha_data_size = data_size - uint64(ALPHA_HEADER_LEN)
   1722 	io1 = dec + 32
   1723 	VP8FiltersInit(tls)
   1724 	(*ALPHDecoder)(unsafe.Pointer(dec)).Foutput = output
   1725 	(*ALPHDecoder)(unsafe.Pointer(dec)).Fwidth = (*VP8Io)(unsafe.Pointer(src_io)).Fwidth
   1726 	(*ALPHDecoder)(unsafe.Pointer(dec)).Fheight = (*VP8Io)(unsafe.Pointer(src_io)).Fheight
   1727 	if data_size <= uint64(ALPHA_HEADER_LEN) {
   1728 		return 0
   1729 	}
   1730 	(*ALPHDecoder)(unsafe.Pointer(dec)).Fmethod = int32(**(**uint8_t)(__ccgo_up(data))) >> 0 & int32(0x03)
   1731 	(*ALPHDecoder)(unsafe.Pointer(dec)).Ffilter = int32(**(**uint8_t)(__ccgo_up(data))) >> libc.Int32FromInt32(2) & libc.Int32FromInt32(0x03)
   1732 	(*ALPHDecoder)(unsafe.Pointer(dec)).Fpre_processing = int32(**(**uint8_t)(__ccgo_up(data))) >> int32(4) & int32(0x03)
   1733 	rsrv = int32(**(**uint8_t)(__ccgo_up(data))) >> int32(6) & int32(0x03)
   1734 	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 {
   1735 		return 0
   1736 	}
   1737 	// Copy the necessary parameters from src_io to io
   1738 	v1 = VP8InitIoInternal(tls, io1, int32(WEBP_DECODER_ABI_VERSION))
   1739 	goto _2
   1740 _2:
   1741 	if !(v1 != 0) {
   1742 		return 0
   1743 	}
   1744 	WebPInitCustomIo(tls, libc.UintptrFromInt32(0), io1)
   1745 	(*VP8Io)(unsafe.Pointer(io1)).Fopaque = dec
   1746 	(*VP8Io)(unsafe.Pointer(io1)).Fwidth = (*VP8Io)(unsafe.Pointer(src_io)).Fwidth
   1747 	(*VP8Io)(unsafe.Pointer(io1)).Fheight = (*VP8Io)(unsafe.Pointer(src_io)).Fheight
   1748 	(*VP8Io)(unsafe.Pointer(io1)).Fuse_cropping = (*VP8Io)(unsafe.Pointer(src_io)).Fuse_cropping
   1749 	(*VP8Io)(unsafe.Pointer(io1)).Fcrop_left = (*VP8Io)(unsafe.Pointer(src_io)).Fcrop_left
   1750 	(*VP8Io)(unsafe.Pointer(io1)).Fcrop_right = (*VP8Io)(unsafe.Pointer(src_io)).Fcrop_right
   1751 	(*VP8Io)(unsafe.Pointer(io1)).Fcrop_top = (*VP8Io)(unsafe.Pointer(src_io)).Fcrop_top
   1752 	(*VP8Io)(unsafe.Pointer(io1)).Fcrop_bottom = (*VP8Io)(unsafe.Pointer(src_io)).Fcrop_bottom
   1753 	// No need to copy the scaling parameters.
   1754 	if (*ALPHDecoder)(unsafe.Pointer(dec)).Fmethod == ALPHA_NO_COMPRESSION {
   1755 		alpha_decoded_size = uint64((*ALPHDecoder)(unsafe.Pointer(dec)).Fwidth * (*ALPHDecoder)(unsafe.Pointer(dec)).Fheight)
   1756 		ok = libc.BoolInt32(alpha_data_size >= alpha_decoded_size)
   1757 	} else {
   1758 		ok = VP8LDecodeAlphaHeader(tls, dec, alpha_data, alpha_data_size)
   1759 	}
   1760 	return ok
   1761 }
   1762 
   1763 // C documentation
   1764 //
   1765 //	// Decodes, unfilters and dequantizes *at least* 'num_rows' rows of alpha
   1766 //	// starting from row number 'row'. It assumes that rows up to (row - 1) have
   1767 //	// already been decoded.
   1768 //	// Returns false in case of bitstream error.
   1769 func ALPHDecode(tls *libc.TLS, dec uintptr, row int32, num_rows int32) (r int32) {
   1770 	var alph_dec, deltas, dst, prev_line uintptr
   1771 	var height, width, y int32
   1772 	_, _, _, _, _, _, _ = alph_dec, deltas, dst, height, prev_line, width, y
   1773 	alph_dec = (*VP8Decoder)(unsafe.Pointer(dec)).Falph_dec
   1774 	width = (*ALPHDecoder)(unsafe.Pointer(alph_dec)).Fwidth
   1775 	height = (*ALPHDecoder)(unsafe.Pointer(alph_dec)).Fio.Fcrop_bottom
   1776 	if (*ALPHDecoder)(unsafe.Pointer(alph_dec)).Fmethod == ALPHA_NO_COMPRESSION {
   1777 		prev_line = (*VP8Decoder)(unsafe.Pointer(dec)).Falpha_prev_line
   1778 		deltas = (*VP8Decoder)(unsafe.Pointer(dec)).Falpha_data + uintptr(ALPHA_HEADER_LEN) + uintptr(row*width)
   1779 		dst = (*VP8Decoder)(unsafe.Pointer(dec)).Falpha_plane + uintptr(row*width)
   1780 		y = 0
   1781 		for {
   1782 			if !(y < num_rows) {
   1783 				break
   1784 			}
   1785 			(*(*func(*libc.TLS, uintptr, uintptr, uintptr, int32))(unsafe.Pointer(&struct{ uintptr }{WebPUnfilters[(*ALPHDecoder)(unsafe.Pointer(alph_dec)).Ffilter]})))(tls, prev_line, deltas, dst, width)
   1786 			prev_line = dst
   1787 			dst = dst + uintptr(width)
   1788 			deltas = deltas + uintptr(width)
   1789 			goto _1
   1790 		_1:
   1791 			;
   1792 			y = y + 1
   1793 		}
   1794 		(*VP8Decoder)(unsafe.Pointer(dec)).Falpha_prev_line = prev_line
   1795 	} else { // alph_dec->method == ALPHA_LOSSLESS_COMPRESSION
   1796 		if !(VP8LDecodeAlphaImageStream(tls, alph_dec, row+num_rows) != 0) {
   1797 			return 0
   1798 		}
   1799 	}
   1800 	if row+num_rows >= height {
   1801 		(*VP8Decoder)(unsafe.Pointer(dec)).Fis_alpha_decoded = int32(1)
   1802 	}
   1803 	return int32(1)
   1804 }
   1805 
   1806 func AllocateAlphaPlane(tls *libc.TLS, dec uintptr, io uintptr) (r int32) {
   1807 	var alpha_size uint64_t
   1808 	var height, stride int32
   1809 	_, _, _ = alpha_size, height, stride
   1810 	stride = (*VP8Io)(unsafe.Pointer(io)).Fwidth
   1811 	height = (*VP8Io)(unsafe.Pointer(io)).Fcrop_bottom
   1812 	alpha_size = uint64(stride) * uint64(height)
   1813 	(*VP8Decoder)(unsafe.Pointer(dec)).Falpha_plane_mem = WebPSafeMalloc(tls, alpha_size, uint64(1))
   1814 	if (*VP8Decoder)(unsafe.Pointer(dec)).Falpha_plane_mem == libc.UintptrFromInt32(0) {
   1815 		return VP8SetError(tls, dec, int32(VP8_STATUS_OUT_OF_MEMORY), __ccgo_ts)
   1816 	}
   1817 	(*VP8Decoder)(unsafe.Pointer(dec)).Falpha_plane = (*VP8Decoder)(unsafe.Pointer(dec)).Falpha_plane_mem
   1818 	(*VP8Decoder)(unsafe.Pointer(dec)).Falpha_prev_line = libc.UintptrFromInt32(0)
   1819 	return int32(1)
   1820 }
   1821 
   1822 func WebPDeallocateAlphaMemory(tls *libc.TLS, dec uintptr) {
   1823 	WebPSafeFree(tls, (*VP8Decoder)(unsafe.Pointer(dec)).Falpha_plane_mem)
   1824 	(*VP8Decoder)(unsafe.Pointer(dec)).Falpha_plane_mem = libc.UintptrFromInt32(0)
   1825 	(*VP8Decoder)(unsafe.Pointer(dec)).Falpha_plane = libc.UintptrFromInt32(0)
   1826 	ALPHDelete(tls, (*VP8Decoder)(unsafe.Pointer(dec)).Falph_dec)
   1827 	(*VP8Decoder)(unsafe.Pointer(dec)).Falph_dec = libc.UintptrFromInt32(0)
   1828 }
   1829 
   1830 // ------------------------------------------------------------------------------
   1831 // Main entry point.
   1832 func VP8DecompressAlphaRows(tls *libc.TLS, dec uintptr, io uintptr, row int32, num_rows int32) (r uintptr) {
   1833 	var alpha, vp8l_dec uintptr
   1834 	var height, width, v1 int32
   1835 	_, _, _, _, _ = alpha, height, vp8l_dec, width, v1
   1836 	width = (*VP8Io)(unsafe.Pointer(io)).Fwidth
   1837 	height = (*VP8Io)(unsafe.Pointer(io)).Fcrop_bottom
   1838 	if row < 0 || num_rows <= 0 || row+num_rows > height {
   1839 		return libc.UintptrFromInt32(0)
   1840 	}
   1841 	if !((*VP8Decoder)(unsafe.Pointer(dec)).Fis_alpha_decoded != 0) {
   1842 		if (*VP8Decoder)(unsafe.Pointer(dec)).Falph_dec == libc.UintptrFromInt32(0) { // Initialize decoder.
   1843 			(*VP8Decoder)(unsafe.Pointer(dec)).Falph_dec = ALPHNew(tls)
   1844 			if (*VP8Decoder)(unsafe.Pointer(dec)).Falph_dec == libc.UintptrFromInt32(0) {
   1845 				VP8SetError(tls, dec, int32(VP8_STATUS_OUT_OF_MEMORY), __ccgo_ts)
   1846 				return libc.UintptrFromInt32(0)
   1847 			}
   1848 			if !(AllocateAlphaPlane(tls, dec, io) != 0) {
   1849 				goto Error
   1850 			}
   1851 			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) {
   1852 				vp8l_dec = (*ALPHDecoder)(unsafe.Pointer((*VP8Decoder)(unsafe.Pointer(dec)).Falph_dec)).Fvp8l_dec
   1853 				if vp8l_dec == libc.UintptrFromInt32(0) {
   1854 					v1 = int32(VP8_STATUS_OUT_OF_MEMORY)
   1855 				} else {
   1856 					v1 = (*VP8LDecoder)(unsafe.Pointer(vp8l_dec)).Fstatus
   1857 				}
   1858 				VP8SetError(tls, dec, v1, __ccgo_ts)
   1859 				goto Error
   1860 			}
   1861 			// if we allowed use of alpha dithering, check whether it's needed at all
   1862 			if (*ALPHDecoder)(unsafe.Pointer((*VP8Decoder)(unsafe.Pointer(dec)).Falph_dec)).Fpre_processing != int32(ALPHA_PREPROCESSED_LEVELS) {
   1863 				(*VP8Decoder)(unsafe.Pointer(dec)).Falpha_dithering = 0 // disable dithering
   1864 			} else {
   1865 				num_rows = height - row // decode everything in one pass
   1866 			}
   1867 		}
   1868 		if !(ALPHDecode(tls, dec, row, num_rows) != 0) {
   1869 			goto Error
   1870 		}
   1871 		if (*VP8Decoder)(unsafe.Pointer(dec)).Fis_alpha_decoded != 0 { // finished?
   1872 			ALPHDelete(tls, (*VP8Decoder)(unsafe.Pointer(dec)).Falph_dec)
   1873 			(*VP8Decoder)(unsafe.Pointer(dec)).Falph_dec = libc.UintptrFromInt32(0)
   1874 			if (*VP8Decoder)(unsafe.Pointer(dec)).Falpha_dithering > 0 {
   1875 				alpha = (*VP8Decoder)(unsafe.Pointer(dec)).Falpha_plane + uintptr((*VP8Io)(unsafe.Pointer(io)).Fcrop_top*width) + uintptr((*VP8Io)(unsafe.Pointer(io)).Fcrop_left)
   1876 				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) {
   1877 					goto Error
   1878 				}
   1879 			}
   1880 		}
   1881 	}
   1882 	// Return a pointer to the current decoded row.
   1883 	return (*VP8Decoder)(unsafe.Pointer(dec)).Falpha_plane + uintptr(row*width)
   1884 	goto Error
   1885 Error:
   1886 	;
   1887 	WebPDeallocateAlphaMemory(tls, dec)
   1888 	return libc.UintptrFromInt32(0)
   1889 }
   1890 
   1891 var kHashMul1 = uint32(0x1e35a7bd)
   1892 
   1893 //------------------------------------------------------------------------------
   1894 
   1895 // Copyright 2010 Google Inc. All Rights Reserved.
   1896 //
   1897 // Use of this source code is governed by a BSD-style license
   1898 // that can be found in the COPYING file in the root of the source
   1899 // tree. An additional intellectual property rights grant can be found
   1900 // in the file PATENTS. All contributing project authors may
   1901 // be found in the AUTHORS file in the root of the source tree.
   1902 // -----------------------------------------------------------------------------
   1903 //
   1904 //  Main decoding functions for WebP images.
   1905 //
   1906 // Author: Skal (pascal.massimino@gmail.com)
   1907 
   1908 // Copyright 2010 Google Inc. All Rights Reserved.
   1909 //
   1910 // Use of this source code is governed by a BSD-style license
   1911 // that can be found in the COPYING file in the root of the source
   1912 // tree. An additional intellectual property rights grant can be found
   1913 // in the file PATENTS. All contributing project authors may
   1914 // be found in the AUTHORS file in the root of the source tree.
   1915 // -----------------------------------------------------------------------------
   1916 //
   1917 //  Common types + memory wrappers
   1918 //
   1919 // Author: Skal (pascal.massimino@gmail.com)
   1920 
   1921 //------------------------------------------------------------------------------
   1922 // WebPDecBuffer
   1923 
   1924 // C documentation
   1925 //
   1926 //	// Number of bytes per pixel for the different color-spaces.
   1927 var kModeBpp = [13]uint8_t{
   1928 	0:  uint8(3),
   1929 	1:  uint8(4),
   1930 	2:  uint8(3),
   1931 	3:  uint8(4),
   1932 	4:  uint8(4),
   1933 	5:  uint8(2),
   1934 	6:  uint8(2),
   1935 	7:  uint8(4),
   1936 	8:  uint8(4),
   1937 	9:  uint8(4),
   1938 	10: uint8(2),
   1939 	11: uint8(1),
   1940 	12: uint8(1),
   1941 }
   1942 
   1943 // C documentation
   1944 //
   1945 //	// Convert to an integer to handle both the unsigned/signed enum cases
   1946 //	// without the need for casting to remove type limit warnings.
   1947 func IsValidColorspace(tls *libc.TLS, webp_csp_mode int32) (r int32) {
   1948 	return libc.BoolInt32(webp_csp_mode >= int32(MODE_RGB) && webp_csp_mode < int32(MODE_LAST))
   1949 }
   1950 
   1951 // strictly speaking, the very last (or first, if flipped) row
   1952 // doesn't require padding.
   1953 
   1954 func CheckDecBuffer(tls *libc.TLS, buffer uintptr) (r VP8StatusCode1) {
   1955 	var a_size, size, u_size, v_size, y_size uint64_t
   1956 	var a_stride, height, ok, stride, u_stride, uv_height, uv_width, v_stride, width, y_stride, v1 int32
   1957 	var buf, buf1 uintptr
   1958 	var mode1 WEBP_CSP_MODE1
   1959 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
   1960 	ok = int32(1)
   1961 	mode1 = (*WebPDecBuffer)(unsafe.Pointer(buffer)).Fcolorspace
   1962 	width = (*WebPDecBuffer)(unsafe.Pointer(buffer)).Fwidth
   1963 	height = (*WebPDecBuffer)(unsafe.Pointer(buffer)).Fheight
   1964 	if !(IsValidColorspace(tls, mode1) != 0) {
   1965 		ok = 0
   1966 	} else {
   1967 		v1 = libc.BoolInt32(mode1 < int32(MODE_YUV))
   1968 		goto _2
   1969 	_2:
   1970 		if !(v1 != 0) { // YUV checks
   1971 			buf = buffer + 16
   1972 			uv_width = (width + int32(1)) / int32(2)
   1973 			uv_height = (height + int32(1)) / int32(2)
   1974 			y_stride = libc.Xabs(tls, (*WebPYUVABuffer)(unsafe.Pointer(buf)).Fy_stride)
   1975 			u_stride = libc.Xabs(tls, (*WebPYUVABuffer)(unsafe.Pointer(buf)).Fu_stride)
   1976 			v_stride = libc.Xabs(tls, (*WebPYUVABuffer)(unsafe.Pointer(buf)).Fv_stride)
   1977 			a_stride = libc.Xabs(tls, (*WebPYUVABuffer)(unsafe.Pointer(buf)).Fa_stride)
   1978 			y_size = uint64(y_stride)*uint64(height-libc.Int32FromInt32(1)) + uint64(width)
   1979 			u_size = uint64(u_stride)*uint64(uv_height-libc.Int32FromInt32(1)) + uint64(uv_width)
   1980 			v_size = uint64(v_stride)*uint64(uv_height-libc.Int32FromInt32(1)) + uint64(uv_width)
   1981 			a_size = uint64(a_stride)*uint64(height-libc.Int32FromInt32(1)) + uint64(width)
   1982 			ok = ok & libc.BoolInt32(y_size <= (*WebPYUVABuffer)(unsafe.Pointer(buf)).Fy_size)
   1983 			ok = ok & libc.BoolInt32(u_size <= (*WebPYUVABuffer)(unsafe.Pointer(buf)).Fu_size)
   1984 			ok = ok & libc.BoolInt32(v_size <= (*WebPYUVABuffer)(unsafe.Pointer(buf)).Fv_size)
   1985 			ok = ok & libc.BoolInt32(y_stride >= width)
   1986 			ok = ok & libc.BoolInt32(u_stride >= uv_width)
   1987 			ok = ok & libc.BoolInt32(v_stride >= uv_width)
   1988 			ok = ok & libc.BoolInt32((*WebPYUVABuffer)(unsafe.Pointer(buf)).Fy != libc.UintptrFromInt32(0))
   1989 			ok = ok & libc.BoolInt32((*WebPYUVABuffer)(unsafe.Pointer(buf)).Fu != libc.UintptrFromInt32(0))
   1990 			ok = ok & libc.BoolInt32((*WebPYUVABuffer)(unsafe.Pointer(buf)).Fv != libc.UintptrFromInt32(0))
   1991 			if mode1 == int32(MODE_YUVA) {
   1992 				ok = ok & libc.BoolInt32(a_stride >= width)
   1993 				ok = ok & libc.BoolInt32(a_size <= (*WebPYUVABuffer)(unsafe.Pointer(buf)).Fa_size)
   1994 				ok = ok & libc.BoolInt32((*WebPYUVABuffer)(unsafe.Pointer(buf)).Fa != libc.UintptrFromInt32(0))
   1995 			}
   1996 		} else { // RGB checks
   1997 			buf1 = buffer + 16
   1998 			stride = libc.Xabs(tls, (*WebPRGBABuffer)(unsafe.Pointer(buf1)).Fstride)
   1999 			size = uint64(stride)*uint64(height-libc.Int32FromInt32(1)) + uint64(width)*uint64(kModeBpp[mode1])
   2000 			ok = ok & libc.BoolInt32(size <= (*WebPRGBABuffer)(unsafe.Pointer(buf1)).Fsize)
   2001 			ok = ok & libc.BoolInt32(stride >= width*int32(kModeBpp[mode1]))
   2002 			ok = ok & libc.BoolInt32((*WebPRGBABuffer)(unsafe.Pointer(buf1)).Frgba != libc.UintptrFromInt32(0))
   2003 		}
   2004 	}
   2005 	if ok != 0 {
   2006 		v1 = int32(VP8_STATUS_OK)
   2007 	} else {
   2008 		v1 = int32(VP8_STATUS_INVALID_PARAM)
   2009 	}
   2010 	return v1
   2011 }
   2012 
   2013 func AllocateBuffer(tls *libc.TLS, buffer uintptr) (r VP8StatusCode1) {
   2014 	var a_size, size, total_size, uv_size uint64_t
   2015 	var a_stride, h, stride, uv_stride, w, v1 int32
   2016 	var buf, buf1, output uintptr
   2017 	var mode1 WEBP_CSP_MODE1
   2018 	_, _, _, _, _, _, _, _, _, _, _, _, _, _ = a_size, a_stride, buf, buf1, h, mode1, output, size, stride, total_size, uv_size, uv_stride, w, v1
   2019 	w = (*WebPDecBuffer)(unsafe.Pointer(buffer)).Fwidth
   2020 	h = (*WebPDecBuffer)(unsafe.Pointer(buffer)).Fheight
   2021 	mode1 = (*WebPDecBuffer)(unsafe.Pointer(buffer)).Fcolorspace
   2022 	if w <= 0 || h <= 0 || !(IsValidColorspace(tls, mode1) != 0) {
   2023 		return int32(VP8_STATUS_INVALID_PARAM)
   2024 	}
   2025 	if (*WebPDecBuffer)(unsafe.Pointer(buffer)).Fis_external_memory <= 0 && (*WebPDecBuffer)(unsafe.Pointer(buffer)).Fprivate_memory == libc.UintptrFromInt32(0) {
   2026 		uv_stride = 0
   2027 		a_stride = 0
   2028 		uv_size = uint64(0)
   2029 		a_size = uint64(0)
   2030 		if uint64(w)*uint64(kModeBpp[mode1]) >= libc.Uint64FromUint64(1)<<libc.Int32FromInt32(31) {
   2031 			return int32(VP8_STATUS_INVALID_PARAM)
   2032 		}
   2033 		stride = w * int32(kModeBpp[mode1])
   2034 		size = uint64(stride) * uint64(h)
   2035 		v1 = libc.BoolInt32(mode1 < int32(MODE_YUV))
   2036 		goto _2
   2037 	_2:
   2038 		if !(v1 != 0) {
   2039 			uv_stride = (w + int32(1)) / int32(2)
   2040 			uv_size = uint64(uv_stride) * uint64((h+libc.Int32FromInt32(1))/libc.Int32FromInt32(2))
   2041 			if mode1 == int32(MODE_YUVA) {
   2042 				a_stride = w
   2043 				a_size = uint64(a_stride) * uint64(h)
   2044 			}
   2045 		}
   2046 		total_size = size + uint64(2)*uv_size + a_size
   2047 		output = WebPSafeMalloc(tls, total_size, uint64(1))
   2048 		if output == libc.UintptrFromInt32(0) {
   2049 			return int32(VP8_STATUS_OUT_OF_MEMORY)
   2050 		}
   2051 		(*WebPDecBuffer)(unsafe.Pointer(buffer)).Fprivate_memory = output
   2052 		v1 = libc.BoolInt32(mode1 < int32(MODE_YUV))
   2053 		goto _4
   2054 	_4:
   2055 		if !(v1 != 0) { // YUVA initialization
   2056 			buf = buffer + 16
   2057 			(*WebPYUVABuffer)(unsafe.Pointer(buf)).Fy = output
   2058 			(*WebPYUVABuffer)(unsafe.Pointer(buf)).Fy_stride = stride
   2059 			(*WebPYUVABuffer)(unsafe.Pointer(buf)).Fy_size = size
   2060 			(*WebPYUVABuffer)(unsafe.Pointer(buf)).Fu = output + uintptr(size)
   2061 			(*WebPYUVABuffer)(unsafe.Pointer(buf)).Fu_stride = uv_stride
   2062 			(*WebPYUVABuffer)(unsafe.Pointer(buf)).Fu_size = uv_size
   2063 			(*WebPYUVABuffer)(unsafe.Pointer(buf)).Fv = output + uintptr(size) + uintptr(uv_size)
   2064 			(*WebPYUVABuffer)(unsafe.Pointer(buf)).Fv_stride = uv_stride
   2065 			(*WebPYUVABuffer)(unsafe.Pointer(buf)).Fv_size = uv_size
   2066 			if mode1 == int32(MODE_YUVA) {
   2067 				(*WebPYUVABuffer)(unsafe.Pointer(buf)).Fa = output + uintptr(size) + uintptr(uint64(2)*uv_size)
   2068 			}
   2069 			(*WebPYUVABuffer)(unsafe.Pointer(buf)).Fa_size = a_size
   2070 			(*WebPYUVABuffer)(unsafe.Pointer(buf)).Fa_stride = a_stride
   2071 		} else { // RGBA initialization
   2072 			buf1 = buffer + 16
   2073 			(*WebPRGBABuffer)(unsafe.Pointer(buf1)).Frgba = output
   2074 			(*WebPRGBABuffer)(unsafe.Pointer(buf1)).Fstride = stride
   2075 			(*WebPRGBABuffer)(unsafe.Pointer(buf1)).Fsize = size
   2076 		}
   2077 	}
   2078 	return CheckDecBuffer(tls, buffer)
   2079 }
   2080 
   2081 func WebPFlipBuffer(tls *libc.TLS, buffer uintptr) (r VP8StatusCode1) {
   2082 	var H int64_t
   2083 	var buf, buf1 uintptr
   2084 	var v1 int32
   2085 	_, _, _, _ = H, buf, buf1, v1
   2086 	if buffer == libc.UintptrFromInt32(0) {
   2087 		return int32(VP8_STATUS_INVALID_PARAM)
   2088 	}
   2089 	v1 = libc.BoolInt32((*WebPDecBuffer)(unsafe.Pointer(buffer)).Fcolorspace < int32(MODE_YUV))
   2090 	goto _2
   2091 _2:
   2092 	if v1 != 0 {
   2093 		buf = buffer + 16
   2094 		**(**uintptr)(__ccgo_up(buf)) += uintptr(int64((*WebPDecBuffer)(unsafe.Pointer(buffer)).Fheight-libc.Int32FromInt32(1)) * int64((*WebPRGBABuffer)(unsafe.Pointer(buf)).Fstride))
   2095 		(*WebPRGBABuffer)(unsafe.Pointer(buf)).Fstride = -(*WebPRGBABuffer)(unsafe.Pointer(buf)).Fstride
   2096 	} else {
   2097 		buf1 = buffer + 16
   2098 		H = int64((*WebPDecBuffer)(unsafe.Pointer(buffer)).Fheight)
   2099 		**(**uintptr)(__ccgo_up(buf1)) += uintptr((H - int64(1)) * int64((*WebPYUVABuffer)(unsafe.Pointer(buf1)).Fy_stride))
   2100 		(*WebPYUVABuffer)(unsafe.Pointer(buf1)).Fy_stride = -(*WebPYUVABuffer)(unsafe.Pointer(buf1)).Fy_stride
   2101 		**(**uintptr)(__ccgo_up(buf1 + 8)) += uintptr((H - int64(1)) >> int32(1) * int64((*WebPYUVABuffer)(unsafe.Pointer(buf1)).Fu_stride))
   2102 		(*WebPYUVABuffer)(unsafe.Pointer(buf1)).Fu_stride = -(*WebPYUVABuffer)(unsafe.Pointer(buf1)).Fu_stride
   2103 		**(**uintptr)(__ccgo_up(buf1 + 16)) += uintptr((H - int64(1)) >> int32(1) * int64((*WebPYUVABuffer)(unsafe.Pointer(buf1)).Fv_stride))
   2104 		(*WebPYUVABuffer)(unsafe.Pointer(buf1)).Fv_stride = -(*WebPYUVABuffer)(unsafe.Pointer(buf1)).Fv_stride
   2105 		if (*WebPYUVABuffer)(unsafe.Pointer(buf1)).Fa != libc.UintptrFromInt32(0) {
   2106 			**(**uintptr)(__ccgo_up(buf1 + 24)) += uintptr((H - int64(1)) * int64((*WebPYUVABuffer)(unsafe.Pointer(buf1)).Fa_stride))
   2107 			(*WebPYUVABuffer)(unsafe.Pointer(buf1)).Fa_stride = -(*WebPYUVABuffer)(unsafe.Pointer(buf1)).Fa_stride
   2108 		}
   2109 	}
   2110 	return int32(VP8_STATUS_OK)
   2111 }
   2112 
   2113 func WebPAllocateDecBuffer(tls *libc.TLS, width int32, height int32, options uintptr, buffer uintptr) (r VP8StatusCode1) {
   2114 	bp := tls.Alloc(16)
   2115 	defer tls.Free(16)
   2116 	var ch, cw, x, y int32
   2117 	var status VP8StatusCode1
   2118 	var _ /* scaled_height at bp+4 */ int32
   2119 	var _ /* scaled_width at bp+0 */ int32
   2120 	_, _, _, _, _ = ch, cw, status, x, y
   2121 	if buffer == libc.UintptrFromInt32(0) || width <= 0 || height <= 0 {
   2122 		return int32(VP8_STATUS_INVALID_PARAM)
   2123 	}
   2124 	if options != libc.UintptrFromInt32(0) { // First, apply options if there is any.
   2125 		if (*WebPDecoderOptions)(unsafe.Pointer(options)).Fuse_cropping != 0 {
   2126 			cw = (*WebPDecoderOptions)(unsafe.Pointer(options)).Fcrop_width
   2127 			ch = (*WebPDecoderOptions)(unsafe.Pointer(options)).Fcrop_height
   2128 			x = (*WebPDecoderOptions)(unsafe.Pointer(options)).Fcrop_left & ^libc.Int32FromInt32(1)
   2129 			y = (*WebPDecoderOptions)(unsafe.Pointer(options)).Fcrop_top & ^libc.Int32FromInt32(1)
   2130 			if !(WebPCheckCropDimensions(tls, width, height, x, y, cw, ch) != 0) {
   2131 				return int32(VP8_STATUS_INVALID_PARAM) // out of frame boundary.
   2132 			}
   2133 			width = cw
   2134 			height = ch
   2135 		}
   2136 		if (*WebPDecoderOptions)(unsafe.Pointer(options)).Fuse_scaling != 0 {
   2137 			**(**int32)(__ccgo_up(bp)) = (*WebPDecoderOptions)(unsafe.Pointer(options)).Fscaled_width
   2138 			**(**int32)(__ccgo_up(bp + 4)) = (*WebPDecoderOptions)(unsafe.Pointer(options)).Fscaled_height
   2139 			if !(WebPRescalerGetScaledDimensions(tls, width, height, bp, bp+4) != 0) {
   2140 				return int32(VP8_STATUS_INVALID_PARAM)
   2141 			}
   2142 			width = **(**int32)(__ccgo_up(bp))
   2143 			height = **(**int32)(__ccgo_up(bp + 4))
   2144 		}
   2145 	}
   2146 	(*WebPDecBuffer)(unsafe.Pointer(buffer)).Fwidth = width
   2147 	(*WebPDecBuffer)(unsafe.Pointer(buffer)).Fheight = height
   2148 	// Then, allocate buffer for real.
   2149 	status = AllocateBuffer(tls, buffer)
   2150 	if status != int32(VP8_STATUS_OK) {
   2151 		return status
   2152 	}
   2153 	// Use the stride trick if vertical flip is needed.
   2154 	if options != libc.UintptrFromInt32(0) && (*WebPDecoderOptions)(unsafe.Pointer(options)).Fflip != 0 {
   2155 		status = WebPFlipBuffer(tls, buffer)
   2156 	}
   2157 	return status
   2158 }
   2159 
   2160 //------------------------------------------------------------------------------
   2161 // constructors / destructors
   2162 
   2163 func WebPInitDecBufferInternal(tls *libc.TLS, buffer uintptr, version int32) (r int32) {
   2164 	if version>>int32(8) != libc.Int32FromInt32(WEBP_DECODER_ABI_VERSION)>>libc.Int32FromInt32(8) {
   2165 		return 0 // version mismatch
   2166 	}
   2167 	if buffer == libc.UintptrFromInt32(0) {
   2168 		return 0
   2169 	}
   2170 	libc.Xmemset(tls, buffer, 0, uint64(120))
   2171 	return int32(1)
   2172 }
   2173 
   2174 func WebPFreeDecBuffer(tls *libc.TLS, buffer uintptr) {
   2175 	if buffer != libc.UintptrFromInt32(0) {
   2176 		if (*WebPDecBuffer)(unsafe.Pointer(buffer)).Fis_external_memory <= 0 {
   2177 			WebPSafeFree(tls, (*WebPDecBuffer)(unsafe.Pointer(buffer)).Fprivate_memory)
   2178 		}
   2179 		(*WebPDecBuffer)(unsafe.Pointer(buffer)).Fprivate_memory = libc.UintptrFromInt32(0)
   2180 	}
   2181 }
   2182 
   2183 func WebPCopyDecBuffer(tls *libc.TLS, src uintptr, dst uintptr) {
   2184 	if src != libc.UintptrFromInt32(0) && dst != libc.UintptrFromInt32(0) {
   2185 		**(**WebPDecBuffer)(__ccgo_up(dst)) = **(**WebPDecBuffer)(__ccgo_up(src))
   2186 		if (*WebPDecBuffer)(unsafe.Pointer(src)).Fprivate_memory != libc.UintptrFromInt32(0) {
   2187 			(*WebPDecBuffer)(unsafe.Pointer(dst)).Fis_external_memory = int32(1) // dst buffer doesn't own the memory.
   2188 			(*WebPDecBuffer)(unsafe.Pointer(dst)).Fprivate_memory = libc.UintptrFromInt32(0)
   2189 		}
   2190 	}
   2191 }
   2192 
   2193 // C documentation
   2194 //
   2195 //	// Copy and transfer ownership from src to dst (beware of parameter order!)
   2196 func WebPGrabDecBuffer(tls *libc.TLS, src uintptr, dst uintptr) {
   2197 	if src != libc.UintptrFromInt32(0) && dst != libc.UintptrFromInt32(0) {
   2198 		**(**WebPDecBuffer)(__ccgo_up(dst)) = **(**WebPDecBuffer)(__ccgo_up(src))
   2199 		if (*WebPDecBuffer)(unsafe.Pointer(src)).Fprivate_memory != libc.UintptrFromInt32(0) {
   2200 			(*WebPDecBuffer)(unsafe.Pointer(src)).Fis_external_memory = int32(1) // src relinquishes ownership
   2201 			(*WebPDecBuffer)(unsafe.Pointer(src)).Fprivate_memory = libc.UintptrFromInt32(0)
   2202 		}
   2203 	}
   2204 }
   2205 
   2206 func WebPCopyDecBufferPixels(tls *libc.TLS, src_buf uintptr, dst_buf uintptr) (r VP8StatusCode1) {
   2207 	var dst, dst1, src, src1 uintptr
   2208 	var v1, v4 int32
   2209 	var v3, v6 WEBP_CSP_MODE1
   2210 	var v9 bool
   2211 	_, _, _, _, _, _, _, _, _ = dst, dst1, src, src1, v1, v3, v4, v6, v9
   2212 	(*WebPDecBuffer)(unsafe.Pointer(dst_buf)).Fwidth = (*WebPDecBuffer)(unsafe.Pointer(src_buf)).Fwidth
   2213 	(*WebPDecBuffer)(unsafe.Pointer(dst_buf)).Fheight = (*WebPDecBuffer)(unsafe.Pointer(src_buf)).Fheight
   2214 	if CheckDecBuffer(tls, dst_buf) != int32(VP8_STATUS_OK) {
   2215 		return int32(VP8_STATUS_INVALID_PARAM)
   2216 	}
   2217 	v1 = libc.BoolInt32((*WebPDecBuffer)(unsafe.Pointer(src_buf)).Fcolorspace < int32(MODE_YUV))
   2218 	goto _2
   2219 _2:
   2220 	if v1 != 0 {
   2221 		src = src_buf + 16
   2222 		dst = dst_buf + 16
   2223 		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)
   2224 	} else {
   2225 		src1 = src_buf + 16
   2226 		dst1 = dst_buf + 16
   2227 		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)
   2228 		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))
   2229 		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))
   2230 		v3 = (*WebPDecBuffer)(unsafe.Pointer(src_buf)).Fcolorspace
   2231 		if v9 = v3 == int32(MODE_RGBA) || v3 == int32(MODE_BGRA) || v3 == int32(MODE_ARGB) || v3 == int32(MODE_RGBA_4444) || v3 == int32(MODE_YUVA); !v9 {
   2232 			v6 = v3
   2233 			v4 = libc.BoolInt32(v6 == int32(MODE_rgbA) || v6 == int32(MODE_bgrA) || v6 == int32(MODE_Argb) || v6 == int32(MODE_rgbA_4444))
   2234 			goto _8
   2235 		_8:
   2236 		}
   2237 		v1 = libc.BoolInt32(v9 || v4 != 0)
   2238 		goto _5
   2239 	_5:
   2240 		if v1 != 0 {
   2241 			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)
   2242 		}
   2243 	}
   2244 	return int32(VP8_STATUS_OK)
   2245 }
   2246 
   2247 func WebPAvoidSlowMemory(tls *libc.TLS, output uintptr, features uintptr) (r int32) {
   2248 	var v1 WEBP_CSP_MODE1
   2249 	var v2 int32
   2250 	var v4 bool
   2251 	_, _, _ = v1, v2, v4
   2252 	if v4 = (*WebPDecBuffer)(unsafe.Pointer(output)).Fis_external_memory >= int32(2); v4 {
   2253 		v1 = (*WebPDecBuffer)(unsafe.Pointer(output)).Fcolorspace
   2254 		v2 = libc.BoolInt32(v1 == int32(MODE_rgbA) || v1 == int32(MODE_bgrA) || v1 == int32(MODE_Argb) || v1 == int32(MODE_rgbA_4444))
   2255 		goto _3
   2256 	_3:
   2257 	}
   2258 	return libc.BoolInt32(v4 && v2 != 0 && (features != libc.UintptrFromInt32(0) && (*WebPBitstreamFeatures)(unsafe.Pointer(features)).Fhas_alpha != 0))
   2259 }
   2260 
   2261 const DITHER_AMP_TAB_SIZE = 12
   2262 const MIN_DITHER_AMP = 4
   2263 
   2264 var kHashMul2 = uint32(0x1e35a7bd)
   2265 
   2266 //------------------------------------------------------------------------------
   2267 
   2268 // Copyright 2010 Google Inc. All Rights Reserved.
   2269 //
   2270 // Use of this source code is governed by a BSD-style license
   2271 // that can be found in the COPYING file in the root of the source
   2272 // tree. An additional intellectual property rights grant can be found
   2273 // in the file PATENTS. All contributing project authors may
   2274 // be found in the AUTHORS file in the root of the source tree.
   2275 // -----------------------------------------------------------------------------
   2276 //
   2277 //  Main decoding functions for WebP images.
   2278 //
   2279 // Author: Skal (pascal.massimino@gmail.com)
   2280 
   2281 // Copyright 2010 Google Inc. All Rights Reserved.
   2282 //
   2283 // Use of this source code is governed by a BSD-style license
   2284 // that can be found in the COPYING file in the root of the source
   2285 // tree. An additional intellectual property rights grant can be found
   2286 // in the file PATENTS. All contributing project authors may
   2287 // be found in the AUTHORS file in the root of the source tree.
   2288 // -----------------------------------------------------------------------------
   2289 //
   2290 //  Common types + memory wrappers
   2291 //
   2292 // Author: Skal (pascal.massimino@gmail.com)
   2293 
   2294 //------------------------------------------------------------------------------
   2295 // Main reconstruction function.
   2296 
   2297 var kScan = [16]uint16_t{
   2298 	1:  uint16(libc.Int32FromInt32(4) + libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)),
   2299 	2:  uint16(libc.Int32FromInt32(8) + libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)),
   2300 	3:  uint16(libc.Int32FromInt32(12) + libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)),
   2301 	4:  uint16(libc.Int32FromInt32(0) + libc.Int32FromInt32(4)*libc.Int32FromInt32(BPS)),
   2302 	5:  uint16(libc.Int32FromInt32(4) + libc.Int32FromInt32(4)*libc.Int32FromInt32(BPS)),
   2303 	6:  uint16(libc.Int32FromInt32(8) + libc.Int32FromInt32(4)*libc.Int32FromInt32(BPS)),
   2304 	7:  uint16(libc.Int32FromInt32(12) + libc.Int32FromInt32(4)*libc.Int32FromInt32(BPS)),
   2305 	8:  uint16(libc.Int32FromInt32(0) + libc.Int32FromInt32(8)*libc.Int32FromInt32(BPS)),
   2306 	9:  uint16(libc.Int32FromInt32(4) + libc.Int32FromInt32(8)*libc.Int32FromInt32(BPS)),
   2307 	10: uint16(libc.Int32FromInt32(8) + libc.Int32FromInt32(8)*libc.Int32FromInt32(BPS)),
   2308 	11: uint16(libc.Int32FromInt32(12) + libc.Int32FromInt32(8)*libc.Int32FromInt32(BPS)),
   2309 	12: uint16(libc.Int32FromInt32(0) + libc.Int32FromInt32(12)*libc.Int32FromInt32(BPS)),
   2310 	13: uint16(libc.Int32FromInt32(4) + libc.Int32FromInt32(12)*libc.Int32FromInt32(BPS)),
   2311 	14: uint16(libc.Int32FromInt32(8) + libc.Int32FromInt32(12)*libc.Int32FromInt32(BPS)),
   2312 	15: uint16(libc.Int32FromInt32(12) + libc.Int32FromInt32(12)*libc.Int32FromInt32(BPS)),
   2313 }
   2314 
   2315 func CheckMode(tls *libc.TLS, mb_x int32, mb_y int32, mode int32) (r int32) {
   2316 	var v1 int32
   2317 	_ = v1
   2318 	if mode == int32(B_DC_PRED) {
   2319 		if mb_x == 0 {
   2320 			if mb_y == 0 {
   2321 				v1 = int32(B_DC_PRED_NOTOPLEFT)
   2322 			} else {
   2323 				v1 = int32(B_DC_PRED_NOLEFT)
   2324 			}
   2325 			return v1
   2326 		} else {
   2327 			if mb_y == 0 {
   2328 				v1 = int32(B_DC_PRED_NOTOP)
   2329 			} else {
   2330 				v1 = int32(B_DC_PRED)
   2331 			}
   2332 			return v1
   2333 		}
   2334 	}
   2335 	return mode
   2336 }
   2337 
   2338 func Copy32b(tls *libc.TLS, dst uintptr, src uintptr) {
   2339 	libc.Xmemcpy(tls, dst, src, uint64(4))
   2340 }
   2341 
   2342 func DoTransform(tls *libc.TLS, bits uint32_t, src uintptr, dst uintptr) {
   2343 	switch bits >> libc.Int32FromInt32(30) {
   2344 	case uint32(3):
   2345 		(*(*func(*libc.TLS, uintptr, uintptr, int32))(unsafe.Pointer(&struct{ uintptr }{VP8Transform})))(tls, src, dst, 0)
   2346 	case uint32(2):
   2347 		(*(*func(*libc.TLS, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8TransformAC3})))(tls, src, dst)
   2348 	case uint32(1):
   2349 		(*(*func(*libc.TLS, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8TransformDC})))(tls, src, dst)
   2350 	default:
   2351 		break
   2352 	}
   2353 }
   2354 
   2355 func DoUVTransform(tls *libc.TLS, bits uint32_t, src uintptr, dst uintptr) {
   2356 	if bits&uint32(0xff) != 0 { // any non-zero coeff at all?
   2357 		if bits&uint32(0xaa) != 0 { // any non-zero AC coefficient?
   2358 			(*(*func(*libc.TLS, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8TransformUV})))(tls, src, dst) // note we don't use the AC3 variant for U/V
   2359 		} else {
   2360 			(*(*func(*libc.TLS, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8TransformDCUV})))(tls, src, dst)
   2361 		}
   2362 	}
   2363 }
   2364 
   2365 func ReconstructRow(tls *libc.TLS, dec uintptr, ctx uintptr) {
   2366 	var bits, bits_uv, v8, v9 uint32_t
   2367 	var block, coeffs, dst, top_right, top_yuv, u_dst, u_out, v_dst, v_out, y_dst, y_out uintptr
   2368 	var cache_id, j, mb_x, mb_y, n, pred_func, pred_func1, uv_offset, y_offset int32
   2369 	var v3, v4 uint8_t
   2370 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
   2371 	mb_y = (*VP8ThreadContext)(unsafe.Pointer(ctx)).Fmb_y
   2372 	cache_id = (*VP8ThreadContext)(unsafe.Pointer(ctx)).Fid
   2373 	y_dst = (*VP8Decoder)(unsafe.Pointer(dec)).Fyuv_b + uintptr(libc.Int32FromInt32(BPS)*libc.Int32FromInt32(1)+libc.Int32FromInt32(8))
   2374 	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))
   2375 	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))
   2376 	// Initialize left-most block.
   2377 	j = 0
   2378 	for {
   2379 		if !(j < int32(16)) {
   2380 			break
   2381 		}
   2382 		**(**uint8_t)(__ccgo_up(y_dst + uintptr(j*int32(BPS)-int32(1)))) = uint8(129)
   2383 		goto _1
   2384 	_1:
   2385 		;
   2386 		j = j + 1
   2387 	}
   2388 	j = 0
   2389 	for {
   2390 		if !(j < int32(8)) {
   2391 			break
   2392 		}
   2393 		**(**uint8_t)(__ccgo_up(u_dst + uintptr(j*int32(BPS)-int32(1)))) = uint8(129)
   2394 		**(**uint8_t)(__ccgo_up(v_dst + uintptr(j*int32(BPS)-int32(1)))) = uint8(129)
   2395 		goto _2
   2396 	_2:
   2397 		;
   2398 		j = j + 1
   2399 	}
   2400 	// Init top-left sample on left column too.
   2401 	if mb_y > 0 {
   2402 		v4 = libc.Uint8FromInt32(129)
   2403 		**(**uint8_t)(__ccgo_up(v_dst + uintptr(-libc.Int32FromInt32(1)-libc.Int32FromInt32(BPS)))) = v4
   2404 		v3 = v4
   2405 		**(**uint8_t)(__ccgo_up(u_dst + uintptr(-libc.Int32FromInt32(1)-libc.Int32FromInt32(BPS)))) = v3
   2406 		**(**uint8_t)(__ccgo_up(y_dst + uintptr(-libc.Int32FromInt32(1)-libc.Int32FromInt32(BPS)))) = v3
   2407 	} else {
   2408 		// we only need to do this init once at block (0,0).
   2409 		// Afterward, it remains valid for the whole topmost row.
   2410 		libc.Xmemset(tls, y_dst-uintptr(BPS)-uintptr(1), int32(127), uint64(libc.Int32FromInt32(16)+libc.Int32FromInt32(4)+libc.Int32FromInt32(1)))
   2411 		libc.Xmemset(tls, u_dst-uintptr(BPS)-uintptr(1), int32(127), uint64(libc.Int32FromInt32(8)+libc.Int32FromInt32(1)))
   2412 		libc.Xmemset(tls, v_dst-uintptr(BPS)-uintptr(1), int32(127), uint64(libc.Int32FromInt32(8)+libc.Int32FromInt32(1)))
   2413 	}
   2414 	// Reconstruct one row.
   2415 	mb_x = 0
   2416 	for {
   2417 		if !(mb_x < (*VP8Decoder)(unsafe.Pointer(dec)).Fmb_w) {
   2418 			break
   2419 		}
   2420 		block = (*VP8ThreadContext)(unsafe.Pointer(ctx)).Fmb_data + uintptr(mb_x)*800
   2421 		// Rotate in the left samples from previously decoded block. We move four
   2422 		// pixels at a time for alignment reason, and because of in-loop filter.
   2423 		if mb_x > 0 {
   2424 			j = -int32(1)
   2425 			for {
   2426 				if !(j < int32(16)) {
   2427 					break
   2428 				}
   2429 				Copy32b(tls, y_dst+uintptr(j*int32(BPS)-int32(4)), y_dst+uintptr(j*int32(BPS)+int32(12)))
   2430 				goto _6
   2431 			_6:
   2432 				;
   2433 				j = j + 1
   2434 			}
   2435 			j = -int32(1)
   2436 			for {
   2437 				if !(j < int32(8)) {
   2438 					break
   2439 				}
   2440 				Copy32b(tls, u_dst+uintptr(j*int32(BPS)-int32(4)), u_dst+uintptr(j*int32(BPS)+int32(4)))
   2441 				Copy32b(tls, v_dst+uintptr(j*int32(BPS)-int32(4)), v_dst+uintptr(j*int32(BPS)+int32(4)))
   2442 				goto _7
   2443 			_7:
   2444 				;
   2445 				j = j + 1
   2446 			}
   2447 		}
   2448 		// bring top samples into the cache
   2449 		top_yuv = (*VP8Decoder)(unsafe.Pointer(dec)).Fyuv_t + uintptr(mb_x)*32
   2450 		coeffs = block
   2451 		bits = (*VP8MBData)(unsafe.Pointer(block)).Fnon_zero_y
   2452 		if mb_y > 0 {
   2453 			libc.Xmemcpy(tls, y_dst-uintptr(BPS), top_yuv, uint64(16))
   2454 			libc.Xmemcpy(tls, u_dst-uintptr(BPS), top_yuv+16, uint64(8))
   2455 			libc.Xmemcpy(tls, v_dst-uintptr(BPS), top_yuv+24, uint64(8))
   2456 		}
   2457 		// predict and add residuals
   2458 		if (*VP8MBData)(unsafe.Pointer(block)).Fis_i4x4 != 0 { // 4x4
   2459 			top_right = y_dst - libc.UintptrFromInt32(BPS) + libc.UintptrFromInt32(16)
   2460 			if mb_y > 0 {
   2461 				if mb_x >= (*VP8Decoder)(unsafe.Pointer(dec)).Fmb_w-int32(1) { // on rightmost border
   2462 					libc.Xmemset(tls, top_right, int32(**(**uint8_t)(__ccgo_up(top_yuv + 15))), uint64(4))
   2463 				} else {
   2464 					libc.Xmemcpy(tls, top_right, top_yuv+1*32, uint64(4))
   2465 				}
   2466 			}
   2467 			// replicate the top-right pixels below
   2468 			v9 = **(**uint32_t)(__ccgo_up(top_right))
   2469 			**(**uint32_t)(__ccgo_up(top_right + uintptr(libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS))*4)) = v9
   2470 			v8 = v9
   2471 			**(**uint32_t)(__ccgo_up(top_right + uintptr(libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS))*4)) = v8
   2472 			**(**uint32_t)(__ccgo_up(top_right + 32*4)) = v8
   2473 			// predict and add residuals for all 4x4 blocks in turn.
   2474 			n = 0
   2475 			for {
   2476 				if !(n < int32(16)) {
   2477 					break
   2478 				}
   2479 				dst = y_dst + uintptr(kScan[n])
   2480 				(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8PredLuma4[**(**uint8_t)(__ccgo_up(block + 769 + uintptr(n)))]})))(tls, dst)
   2481 				DoTransform(tls, bits, coeffs+uintptr(n*int32(16))*2, dst)
   2482 				goto _10
   2483 			_10:
   2484 				;
   2485 				n = n + 1
   2486 				bits = bits << uint32(2)
   2487 			}
   2488 		} else { // 16x16
   2489 			pred_func = CheckMode(tls, mb_x, mb_y, int32(**(**uint8_t)(__ccgo_up(block + 769))))
   2490 			(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8PredLuma16[pred_func]})))(tls, y_dst)
   2491 			if bits != uint32(0) {
   2492 				n = 0
   2493 				for {
   2494 					if !(n < int32(16)) {
   2495 						break
   2496 					}
   2497 					DoTransform(tls, bits, coeffs+uintptr(n*int32(16))*2, y_dst+uintptr(kScan[n]))
   2498 					goto _11
   2499 				_11:
   2500 					;
   2501 					n = n + 1
   2502 					bits = bits << uint32(2)
   2503 				}
   2504 			}
   2505 		}
   2506 		// Chroma
   2507 		bits_uv = (*VP8MBData)(unsafe.Pointer(block)).Fnon_zero_uv
   2508 		pred_func1 = CheckMode(tls, mb_x, mb_y, int32((*VP8MBData)(unsafe.Pointer(block)).Fuvmode))
   2509 		(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8PredChroma8[pred_func1]})))(tls, u_dst)
   2510 		(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8PredChroma8[pred_func1]})))(tls, v_dst)
   2511 		DoUVTransform(tls, bits_uv>>0, coeffs+uintptr(libc.Int32FromInt32(16)*libc.Int32FromInt32(16))*2, u_dst)
   2512 		DoUVTransform(tls, bits_uv>>int32(8), coeffs+uintptr(libc.Int32FromInt32(20)*libc.Int32FromInt32(16))*2, v_dst)
   2513 		// stash away top samples for next block
   2514 		if mb_y < (*VP8Decoder)(unsafe.Pointer(dec)).Fmb_h-int32(1) {
   2515 			libc.Xmemcpy(tls, top_yuv, y_dst+uintptr(libc.Int32FromInt32(15)*libc.Int32FromInt32(BPS)), uint64(16))
   2516 			libc.Xmemcpy(tls, top_yuv+16, u_dst+uintptr(libc.Int32FromInt32(7)*libc.Int32FromInt32(BPS)), uint64(8))
   2517 			libc.Xmemcpy(tls, top_yuv+24, v_dst+uintptr(libc.Int32FromInt32(7)*libc.Int32FromInt32(BPS)), uint64(8))
   2518 		}
   2519 		// Transfer reconstructed samples from yuv_b cache to final destination.
   2520 		y_offset = cache_id * int32(16) * (*VP8Decoder)(unsafe.Pointer(dec)).Fcache_y_stride
   2521 		uv_offset = cache_id * int32(8) * (*VP8Decoder)(unsafe.Pointer(dec)).Fcache_uv_stride
   2522 		y_out = (*VP8Decoder)(unsafe.Pointer(dec)).Fcache_y + uintptr(mb_x*int32(16)) + uintptr(y_offset)
   2523 		u_out = (*VP8Decoder)(unsafe.Pointer(dec)).Fcache_u + uintptr(mb_x*int32(8)) + uintptr(uv_offset)
   2524 		v_out = (*VP8Decoder)(unsafe.Pointer(dec)).Fcache_v + uintptr(mb_x*int32(8)) + uintptr(uv_offset)
   2525 		j = 0
   2526 		for {
   2527 			if !(j < int32(16)) {
   2528 				break
   2529 			}
   2530 			libc.Xmemcpy(tls, y_out+uintptr(j*(*VP8Decoder)(unsafe.Pointer(dec)).Fcache_y_stride), y_dst+uintptr(j*int32(BPS)), uint64(16))
   2531 			goto _12
   2532 		_12:
   2533 			;
   2534 			j = j + 1
   2535 		}
   2536 		j = 0
   2537 		for {
   2538 			if !(j < int32(8)) {
   2539 				break
   2540 			}
   2541 			libc.Xmemcpy(tls, u_out+uintptr(j*(*VP8Decoder)(unsafe.Pointer(dec)).Fcache_uv_stride), u_dst+uintptr(j*int32(BPS)), uint64(8))
   2542 			libc.Xmemcpy(tls, v_out+uintptr(j*(*VP8Decoder)(unsafe.Pointer(dec)).Fcache_uv_stride), v_dst+uintptr(j*int32(BPS)), uint64(8))
   2543 			goto _13
   2544 		_13:
   2545 			;
   2546 			j = j + 1
   2547 		}
   2548 		goto _5
   2549 	_5:
   2550 		;
   2551 		mb_x = mb_x + 1
   2552 	}
   2553 }
   2554 
   2555 //------------------------------------------------------------------------------
   2556 // Filtering
   2557 
   2558 // C documentation
   2559 //
   2560 //	// kFilterExtraRows[] = How many extra lines are needed on the MB boundary
   2561 //	// for caching, given a filtering level.
   2562 //	// Simple filter:  up to 2 luma samples are read and 1 is written.
   2563 //	// Complex filter: up to 4 luma samples are read and 3 are written. Same for
   2564 //	//                 U/V, so it's 8 samples total (because of the 2x upsampling).
   2565 var kFilterExtraRows = [3]uint8_t{
   2566 	1: uint8(2),
   2567 	2: uint8(8),
   2568 }
   2569 
   2570 func DoFilter(tls *libc.TLS, dec uintptr, mb_x int32, mb_y int32) {
   2571 	var cache_id, hev_thresh, ilevel, limit, uv_bps, y_bps int32
   2572 	var ctx, f_info, u_dst, v_dst, y_dst uintptr
   2573 	_, _, _, _, _, _, _, _, _, _, _ = cache_id, ctx, f_info, hev_thresh, ilevel, limit, u_dst, uv_bps, v_dst, y_bps, y_dst
   2574 	ctx = dec + 216
   2575 	cache_id = (*VP8ThreadContext)(unsafe.Pointer(ctx)).Fid
   2576 	y_bps = (*VP8Decoder)(unsafe.Pointer(dec)).Fcache_y_stride
   2577 	f_info = (*VP8ThreadContext)(unsafe.Pointer(ctx)).Ff_info + uintptr(mb_x)*4
   2578 	y_dst = (*VP8Decoder)(unsafe.Pointer(dec)).Fcache_y + uintptr(cache_id*int32(16)*y_bps) + uintptr(mb_x*int32(16))
   2579 	ilevel = int32((*VP8FInfo)(unsafe.Pointer(f_info)).Ff_ilevel)
   2580 	limit = int32((*VP8FInfo)(unsafe.Pointer(f_info)).Ff_limit)
   2581 	if limit == 0 {
   2582 		return
   2583 	}
   2584 	if (*VP8Decoder)(unsafe.Pointer(dec)).Ffilter_type == int32(1) { // simple
   2585 		if mb_x > 0 {
   2586 			(*(*func(*libc.TLS, uintptr, int32, int32))(unsafe.Pointer(&struct{ uintptr }{VP8SimpleHFilter16})))(tls, y_dst, y_bps, limit+int32(4))
   2587 		}
   2588 		if (*VP8FInfo)(unsafe.Pointer(f_info)).Ff_inner != 0 {
   2589 			(*(*func(*libc.TLS, uintptr, int32, int32))(unsafe.Pointer(&struct{ uintptr }{VP8SimpleHFilter16i})))(tls, y_dst, y_bps, limit)
   2590 		}
   2591 		if mb_y > 0 {
   2592 			(*(*func(*libc.TLS, uintptr, int32, int32))(unsafe.Pointer(&struct{ uintptr }{VP8SimpleVFilter16})))(tls, y_dst, y_bps, limit+int32(4))
   2593 		}
   2594 		if (*VP8FInfo)(unsafe.Pointer(f_info)).Ff_inner != 0 {
   2595 			(*(*func(*libc.TLS, uintptr, int32, int32))(unsafe.Pointer(&struct{ uintptr }{VP8SimpleVFilter16i})))(tls, y_dst, y_bps, limit)
   2596 		}
   2597 	} else { // complex
   2598 		uv_bps = (*VP8Decoder)(unsafe.Pointer(dec)).Fcache_uv_stride
   2599 		u_dst = (*VP8Decoder)(unsafe.Pointer(dec)).Fcache_u + uintptr(cache_id*int32(8)*uv_bps) + uintptr(mb_x*int32(8))
   2600 		v_dst = (*VP8Decoder)(unsafe.Pointer(dec)).Fcache_v + uintptr(cache_id*int32(8)*uv_bps) + uintptr(mb_x*int32(8))
   2601 		hev_thresh = int32((*VP8FInfo)(unsafe.Pointer(f_info)).Fhev_thresh)
   2602 		if mb_x > 0 {
   2603 			(*(*func(*libc.TLS, uintptr, int32, int32, int32, int32))(unsafe.Pointer(&struct{ uintptr }{VP8HFilter16})))(tls, y_dst, y_bps, limit+int32(4), ilevel, hev_thresh)
   2604 			(*(*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)
   2605 		}
   2606 		if (*VP8FInfo)(unsafe.Pointer(f_info)).Ff_inner != 0 {
   2607 			(*(*func(*libc.TLS, uintptr, int32, int32, int32, int32))(unsafe.Pointer(&struct{ uintptr }{VP8HFilter16i})))(tls, y_dst, y_bps, limit, ilevel, hev_thresh)
   2608 			(*(*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)
   2609 		}
   2610 		if mb_y > 0 {
   2611 			(*(*func(*libc.TLS, uintptr, int32, int32, int32, int32))(unsafe.Pointer(&struct{ uintptr }{VP8VFilter16})))(tls, y_dst, y_bps, limit+int32(4), ilevel, hev_thresh)
   2612 			(*(*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)
   2613 		}
   2614 		if (*VP8FInfo)(unsafe.Pointer(f_info)).Ff_inner != 0 {
   2615 			(*(*func(*libc.TLS, uintptr, int32, int32, int32, int32))(unsafe.Pointer(&struct{ uintptr }{VP8VFilter16i})))(tls, y_dst, y_bps, limit, ilevel, hev_thresh)
   2616 			(*(*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)
   2617 		}
   2618 	}
   2619 }
   2620 
   2621 // C documentation
   2622 //
   2623 //	// Filter the decoded macroblock row (if needed)
   2624 func FilterRow(tls *libc.TLS, dec uintptr) {
   2625 	var mb_x, mb_y int32
   2626 	_, _ = mb_x, mb_y
   2627 	mb_y = (*VP8Decoder)(unsafe.Pointer(dec)).Fthread_ctx.Fmb_y
   2628 	mb_x = (*VP8Decoder)(unsafe.Pointer(dec)).Ftl_mb_x
   2629 	for {
   2630 		if !(mb_x < (*VP8Decoder)(unsafe.Pointer(dec)).Fbr_mb_x) {
   2631 			break
   2632 		}
   2633 		DoFilter(tls, dec, mb_x, mb_y)
   2634 		goto _1
   2635 	_1:
   2636 		;
   2637 		mb_x = mb_x + 1
   2638 	}
   2639 }
   2640 
   2641 //------------------------------------------------------------------------------
   2642 // Precompute the filtering strength for each segment and each i4x4/i16x16 mode.
   2643 
   2644 func PrecomputeFilterStrengths(tls *libc.TLS, dec uintptr) {
   2645 	var base_level, i4x4, ilevel, level, s, v3, v4 int32
   2646 	var hdr, info uintptr
   2647 	_, _, _, _, _, _, _, _, _ = base_level, hdr, i4x4, ilevel, info, level, s, v3, v4
   2648 	if (*VP8Decoder)(unsafe.Pointer(dec)).Ffilter_type > 0 {
   2649 		hdr = dec + 84
   2650 		s = 0
   2651 		for {
   2652 			if !(s < int32(NUM_MB_SEGMENTS)) {
   2653 				break
   2654 			}
   2655 			if (*VP8Decoder)(unsafe.Pointer(dec)).Fsegment_hdr.Fuse_segment != 0 {
   2656 				base_level = int32(**(**int8_t)(__ccgo_up(dec + 132 + 16 + uintptr(s))))
   2657 				if !((*VP8Decoder)(unsafe.Pointer(dec)).Fsegment_hdr.Fabsolute_delta != 0) {
   2658 					base_level = base_level + (*VP8FilterHeader)(unsafe.Pointer(hdr)).Flevel
   2659 				}
   2660 			} else {
   2661 				base_level = (*VP8FilterHeader)(unsafe.Pointer(hdr)).Flevel
   2662 			}
   2663 			i4x4 = 0
   2664 			for {
   2665 				if !(i4x4 <= int32(1)) {
   2666 					break
   2667 				}
   2668 				info = dec + 2924 + uintptr(s)*8 + uintptr(i4x4)*4
   2669 				level = base_level
   2670 				if (*VP8FilterHeader)(unsafe.Pointer(hdr)).Fuse_lf_delta != 0 {
   2671 					level = level + **(**int32)(__ccgo_up(hdr + 16))
   2672 					if i4x4 != 0 {
   2673 						level = level + **(**int32)(__ccgo_up(hdr + 32))
   2674 					}
   2675 				}
   2676 				if level < 0 {
   2677 					v3 = 0
   2678 				} else {
   2679 					if level > int32(63) {
   2680 						v4 = int32(63)
   2681 					} else {
   2682 						v4 = level
   2683 					}
   2684 					v3 = v4
   2685 				}
   2686 				level = v3
   2687 				if level > 0 {
   2688 					ilevel = level
   2689 					if (*VP8FilterHeader)(unsafe.Pointer(hdr)).Fsharpness > 0 {
   2690 						if (*VP8FilterHeader)(unsafe.Pointer(hdr)).Fsharpness > int32(4) {
   2691 							ilevel = ilevel >> int32(2)
   2692 						} else {
   2693 							ilevel = ilevel >> int32(1)
   2694 						}
   2695 						if ilevel > int32(9)-(*VP8FilterHeader)(unsafe.Pointer(hdr)).Fsharpness {
   2696 							ilevel = int32(9) - (*VP8FilterHeader)(unsafe.Pointer(hdr)).Fsharpness
   2697 						}
   2698 					}
   2699 					if ilevel < int32(1) {
   2700 						ilevel = int32(1)
   2701 					}
   2702 					(*VP8FInfo)(unsafe.Pointer(info)).Ff_ilevel = uint8(ilevel)
   2703 					(*VP8FInfo)(unsafe.Pointer(info)).Ff_limit = uint8(int32(2)*level + ilevel)
   2704 					if level >= int32(40) {
   2705 						v3 = int32(2)
   2706 					} else {
   2707 						if level >= int32(15) {
   2708 							v4 = int32(1)
   2709 						} else {
   2710 							v4 = 0
   2711 						}
   2712 						v3 = v4
   2713 					}
   2714 					(*VP8FInfo)(unsafe.Pointer(info)).Fhev_thresh = uint8(v3)
   2715 				} else {
   2716 					(*VP8FInfo)(unsafe.Pointer(info)).Ff_limit = uint8(0) // no filtering
   2717 				}
   2718 				(*VP8FInfo)(unsafe.Pointer(info)).Ff_inner = uint8(i4x4)
   2719 				goto _2
   2720 			_2:
   2721 				;
   2722 				i4x4 = i4x4 + 1
   2723 			}
   2724 			goto _1
   2725 		_1:
   2726 			;
   2727 			s = s + 1
   2728 		}
   2729 	}
   2730 }
   2731 
   2732 //------------------------------------------------------------------------------
   2733 // Dithering
   2734 
   2735 // minimal amp that will provide a non-zero dithering effect
   2736 
   2737 var kQuantToDitherAmp = [12]uint8_t{
   2738 	0:  uint8(8),
   2739 	1:  uint8(7),
   2740 	2:  uint8(6),
   2741 	3:  uint8(4),
   2742 	4:  uint8(4),
   2743 	5:  uint8(2),
   2744 	6:  uint8(2),
   2745 	7:  uint8(2),
   2746 	8:  uint8(1),
   2747 	9:  uint8(1),
   2748 	10: uint8(1),
   2749 	11: uint8(1),
   2750 }
   2751 
   2752 func VP8InitDithering(tls *libc.TLS, options uintptr, dec uintptr) {
   2753 	var all_amp, d, f, idx, max_amp, s, v1, v2, v4 int32
   2754 	var dqm uintptr
   2755 	_, _, _, _, _, _, _, _, _, _ = all_amp, d, dqm, f, idx, max_amp, s, v1, v2, v4
   2756 	if options != libc.UintptrFromInt32(0) {
   2757 		d = (*WebPDecoderOptions)(unsafe.Pointer(options)).Fdithering_strength
   2758 		max_amp = libc.Int32FromInt32(1)<<libc.Int32FromInt32(VP8_RANDOM_DITHER_FIX) - libc.Int32FromInt32(1)
   2759 		if d < 0 {
   2760 			v1 = 0
   2761 		} else {
   2762 			if d > int32(100) {
   2763 				v2 = max_amp
   2764 			} else {
   2765 				v2 = d * max_amp / int32(100)
   2766 			}
   2767 			v1 = v2
   2768 		}
   2769 		f = v1
   2770 		if f > 0 {
   2771 			all_amp = 0
   2772 			s = 0
   2773 			for {
   2774 				if !(s < int32(NUM_MB_SEGMENTS)) {
   2775 					break
   2776 				}
   2777 				dqm = dec + 1060 + uintptr(s)*32
   2778 				if (*VP8QuantMatrix)(unsafe.Pointer(dqm)).Fuv_quant < int32(DITHER_AMP_TAB_SIZE) {
   2779 					if (*VP8QuantMatrix)(unsafe.Pointer(dqm)).Fuv_quant < 0 {
   2780 						v4 = 0
   2781 					} else {
   2782 						v4 = (*VP8QuantMatrix)(unsafe.Pointer(dqm)).Fuv_quant
   2783 					}
   2784 					idx = v4
   2785 					(*VP8QuantMatrix)(unsafe.Pointer(dqm)).Fdither = f * int32(kQuantToDitherAmp[idx]) >> int32(3)
   2786 				}
   2787 				all_amp = all_amp | (*VP8QuantMatrix)(unsafe.Pointer(dqm)).Fdither
   2788 				goto _3
   2789 			_3:
   2790 				;
   2791 				s = s + 1
   2792 			}
   2793 			if all_amp != 0 {
   2794 				VP8InitRandom(tls, dec+828, libc.Float32FromFloat32(1))
   2795 				(*VP8Decoder)(unsafe.Pointer(dec)).Fdither = int32(1)
   2796 			}
   2797 		}
   2798 		// potentially allow alpha dithering
   2799 		(*VP8Decoder)(unsafe.Pointer(dec)).Falpha_dithering = (*WebPDecoderOptions)(unsafe.Pointer(options)).Falpha_dithering_strength
   2800 		if (*VP8Decoder)(unsafe.Pointer(dec)).Falpha_dithering > int32(100) {
   2801 			(*VP8Decoder)(unsafe.Pointer(dec)).Falpha_dithering = int32(100)
   2802 		} else {
   2803 			if (*VP8Decoder)(unsafe.Pointer(dec)).Falpha_dithering < 0 {
   2804 				(*VP8Decoder)(unsafe.Pointer(dec)).Falpha_dithering = 0
   2805 			}
   2806 		}
   2807 	}
   2808 }
   2809 
   2810 // C documentation
   2811 //
   2812 //	// Convert to range: [-2,2] for dither=50, [-4,4] for dither=100
   2813 func Dither8x8(tls *libc.TLS, rg1 uintptr, dst uintptr, bps int32, amp1 int32) {
   2814 	bp := tls.Alloc(64)
   2815 	defer tls.Free(64)
   2816 	var diff, i, v3, v4, v6, v8 int32
   2817 	var v2, v5, v7 uintptr
   2818 	var _ /* dither at bp+0 */ [64]uint8_t
   2819 	_, _, _, _, _, _, _, _, _ = diff, i, v2, v3, v4, v5, v6, v7, v8
   2820 	i = 0
   2821 	for {
   2822 		if !(i < libc.Int32FromInt32(8)*libc.Int32FromInt32(8)) {
   2823 			break
   2824 		}
   2825 		v2 = rg1
   2826 		v3 = libc.Int32FromInt32(VP8_DITHER_AMP_BITS) + libc.Int32FromInt32(1)
   2827 		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)))
   2828 		if diff < libc.Int32FromInt32(0) {
   2829 			diff = int32(uint32(diff) + libc.Uint32FromUint32(1)<<libc.Int32FromInt32(31))
   2830 		}
   2831 		**(**uint32_t)(__ccgo_up(v2 + 8 + uintptr((*VP8Random)(unsafe.Pointer(v2)).Findex1)*4)) = uint32(diff)
   2832 		v5 = v2
   2833 		*(*int32)(unsafe.Pointer(v5)) = *(*int32)(unsafe.Pointer(v5)) + 1
   2834 		v4 = *(*int32)(unsafe.Pointer(v5))
   2835 		if v4 == libc.Int32FromInt32(VP8_RANDOM_TABLE_SIZE) {
   2836 			(*VP8Random)(unsafe.Pointer(v2)).Findex1 = 0
   2837 		}
   2838 		v7 = v2 + 4
   2839 		*(*int32)(unsafe.Pointer(v7)) = *(*int32)(unsafe.Pointer(v7)) + 1
   2840 		v6 = *(*int32)(unsafe.Pointer(v7))
   2841 		if v6 == libc.Int32FromInt32(VP8_RANDOM_TABLE_SIZE) {
   2842 			(*VP8Random)(unsafe.Pointer(v2)).Findex2 = 0
   2843 		}
   2844 		diff = int32(uint32(diff)<<libc.Int32FromInt32(1)) >> (int32(32) - v3)
   2845 		diff = diff * amp1 >> int32(VP8_RANDOM_DITHER_FIX)
   2846 		diff = diff + int32(1)<<(v3-int32(1))
   2847 		v8 = diff
   2848 		goto _9
   2849 	_9:
   2850 		(**(**[64]uint8_t)(__ccgo_up(bp)))[i] = uint8(v8)
   2851 		goto _1
   2852 	_1:
   2853 		;
   2854 		i = i + 1
   2855 	}
   2856 	(*(*func(*libc.TLS, uintptr, uintptr, int32))(unsafe.Pointer(&struct{ uintptr }{VP8DitherCombine8x8})))(tls, bp, dst, bps)
   2857 }
   2858 
   2859 func DitherRow(tls *libc.TLS, dec uintptr) {
   2860 	var cache_id, mb_x, uv_bps int32
   2861 	var ctx, data, u_dst, v_dst uintptr
   2862 	_, _, _, _, _, _, _ = cache_id, ctx, data, mb_x, u_dst, uv_bps, v_dst
   2863 	mb_x = (*VP8Decoder)(unsafe.Pointer(dec)).Ftl_mb_x
   2864 	for {
   2865 		if !(mb_x < (*VP8Decoder)(unsafe.Pointer(dec)).Fbr_mb_x) {
   2866 			break
   2867 		}
   2868 		ctx = dec + 216
   2869 		data = (*VP8ThreadContext)(unsafe.Pointer(ctx)).Fmb_data + uintptr(mb_x)*800
   2870 		cache_id = (*VP8ThreadContext)(unsafe.Pointer(ctx)).Fid
   2871 		uv_bps = (*VP8Decoder)(unsafe.Pointer(dec)).Fcache_uv_stride
   2872 		if int32((*VP8MBData)(unsafe.Pointer(data)).Fdither) >= int32(MIN_DITHER_AMP) {
   2873 			u_dst = (*VP8Decoder)(unsafe.Pointer(dec)).Fcache_u + uintptr(cache_id*int32(8)*uv_bps) + uintptr(mb_x*int32(8))
   2874 			v_dst = (*VP8Decoder)(unsafe.Pointer(dec)).Fcache_v + uintptr(cache_id*int32(8)*uv_bps) + uintptr(mb_x*int32(8))
   2875 			Dither8x8(tls, dec+828, u_dst, uv_bps, int32((*VP8MBData)(unsafe.Pointer(data)).Fdither))
   2876 			Dither8x8(tls, dec+828, v_dst, uv_bps, int32((*VP8MBData)(unsafe.Pointer(data)).Fdither))
   2877 		}
   2878 		goto _1
   2879 	_1:
   2880 		;
   2881 		mb_x = mb_x + 1
   2882 	}
   2883 }
   2884 
   2885 //------------------------------------------------------------------------------
   2886 // This function is called after a row of macroblocks is finished decoding.
   2887 // It also takes into account the following restrictions:
   2888 //  * In case of in-loop filtering, we must hold off sending some of the bottom
   2889 //    pixels as they are yet unfiltered. They will be when the next macroblock
   2890 //    row is decoded. Meanwhile, we must preserve them by rotating them in the
   2891 //    cache area. This doesn't hold for the very bottom row of the uncropped
   2892 //    picture of course.
   2893 //  * we must clip the remaining pixels against the cropping area. The VP8Io
   2894 //    struct must have the following fields set correctly before calling put():
   2895 
   2896 // C documentation
   2897 //
   2898 //	// Finalize and transmit a complete row. Return false in case of user-abort.
   2899 func FinishRow(tls *libc.TLS, arg1 uintptr, arg2 uintptr) (r int32) {
   2900 	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
   2901 	var ctx, dec, io, udst, vdst, ydst uintptr
   2902 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
   2903 	dec = arg1
   2904 	io = arg2
   2905 	ok = int32(1)
   2906 	ctx = dec + 216
   2907 	cache_id = (*VP8ThreadContext)(unsafe.Pointer(ctx)).Fid
   2908 	extra_y_rows = int32(kFilterExtraRows[(*VP8Decoder)(unsafe.Pointer(dec)).Ffilter_type])
   2909 	ysize = extra_y_rows * (*VP8Decoder)(unsafe.Pointer(dec)).Fcache_y_stride
   2910 	uvsize = extra_y_rows / int32(2) * (*VP8Decoder)(unsafe.Pointer(dec)).Fcache_uv_stride
   2911 	y_offset = cache_id * int32(16) * (*VP8Decoder)(unsafe.Pointer(dec)).Fcache_y_stride
   2912 	uv_offset = cache_id * int32(8) * (*VP8Decoder)(unsafe.Pointer(dec)).Fcache_uv_stride
   2913 	ydst = (*VP8Decoder)(unsafe.Pointer(dec)).Fcache_y - uintptr(ysize) + uintptr(y_offset)
   2914 	udst = (*VP8Decoder)(unsafe.Pointer(dec)).Fcache_u - uintptr(uvsize) + uintptr(uv_offset)
   2915 	vdst = (*VP8Decoder)(unsafe.Pointer(dec)).Fcache_v - uintptr(uvsize) + uintptr(uv_offset)
   2916 	mb_y = (*VP8ThreadContext)(unsafe.Pointer(ctx)).Fmb_y
   2917 	is_first_row = libc.BoolInt32(mb_y == libc.Int32FromInt32(0))
   2918 	is_last_row = libc.BoolInt32(mb_y >= (*VP8Decoder)(unsafe.Pointer(dec)).Fbr_mb_y-libc.Int32FromInt32(1))
   2919 	if (*VP8Decoder)(unsafe.Pointer(dec)).Fmt_method == int32(2) {
   2920 		ReconstructRow(tls, dec, ctx)
   2921 	}
   2922 	if (*VP8ThreadContext)(unsafe.Pointer(ctx)).Ffilter_row != 0 {
   2923 		FilterRow(tls, dec)
   2924 	}
   2925 	if (*VP8Decoder)(unsafe.Pointer(dec)).Fdither != 0 {
   2926 		DitherRow(tls, dec)
   2927 	}
   2928 	if (*VP8Io)(unsafe.Pointer(io)).Fput != libc.UintptrFromInt32(0) {
   2929 		y_start = mb_y * int32(16)
   2930 		y_end = (mb_y + int32(1)) * int32(16)
   2931 		if !(is_first_row != 0) {
   2932 			y_start = y_start - extra_y_rows
   2933 			(*VP8Io)(unsafe.Pointer(io)).Fy = ydst
   2934 			(*VP8Io)(unsafe.Pointer(io)).Fu = udst
   2935 			(*VP8Io)(unsafe.Pointer(io)).Fv = vdst
   2936 		} else {
   2937 			(*VP8Io)(unsafe.Pointer(io)).Fy = (*VP8Decoder)(unsafe.Pointer(dec)).Fcache_y + uintptr(y_offset)
   2938 			(*VP8Io)(unsafe.Pointer(io)).Fu = (*VP8Decoder)(unsafe.Pointer(dec)).Fcache_u + uintptr(uv_offset)
   2939 			(*VP8Io)(unsafe.Pointer(io)).Fv = (*VP8Decoder)(unsafe.Pointer(dec)).Fcache_v + uintptr(uv_offset)
   2940 		}
   2941 		if !(is_last_row != 0) {
   2942 			y_end = y_end - extra_y_rows
   2943 		}
   2944 		if y_end > (*VP8Io)(unsafe.Pointer(io)).Fcrop_bottom {
   2945 			y_end = (*VP8Io)(unsafe.Pointer(io)).Fcrop_bottom // make sure we don't overflow on last row.
   2946 		}
   2947 		// If dec->alpha_data is not NULL, we have some alpha plane present.
   2948 		(*VP8Io)(unsafe.Pointer(io)).Fa = libc.UintptrFromInt32(0)
   2949 		if (*VP8Decoder)(unsafe.Pointer(dec)).Falpha_data != libc.UintptrFromInt32(0) && y_start < y_end {
   2950 			(*VP8Io)(unsafe.Pointer(io)).Fa = VP8DecompressAlphaRows(tls, dec, io, y_start, y_end-y_start)
   2951 			if (*VP8Io)(unsafe.Pointer(io)).Fa == libc.UintptrFromInt32(0) {
   2952 				return VP8SetError(tls, dec, int32(VP8_STATUS_BITSTREAM_ERROR), __ccgo_ts+37)
   2953 			}
   2954 		}
   2955 		if y_start < (*VP8Io)(unsafe.Pointer(io)).Fcrop_top {
   2956 			delta_y = (*VP8Io)(unsafe.Pointer(io)).Fcrop_top - y_start
   2957 			y_start = (*VP8Io)(unsafe.Pointer(io)).Fcrop_top
   2958 			**(**uintptr)(__ccgo_up(io + 24)) += uintptr((*VP8Decoder)(unsafe.Pointer(dec)).Fcache_y_stride * delta_y)
   2959 			**(**uintptr)(__ccgo_up(io + 32)) += uintptr((*VP8Decoder)(unsafe.Pointer(dec)).Fcache_uv_stride * (delta_y >> libc.Int32FromInt32(1)))
   2960 			**(**uintptr)(__ccgo_up(io + 40)) += uintptr((*VP8Decoder)(unsafe.Pointer(dec)).Fcache_uv_stride * (delta_y >> libc.Int32FromInt32(1)))
   2961 			if (*VP8Io)(unsafe.Pointer(io)).Fa != libc.UintptrFromInt32(0) {
   2962 				**(**uintptr)(__ccgo_up(io + 152)) += uintptr((*VP8Io)(unsafe.Pointer(io)).Fwidth * delta_y)
   2963 			}
   2964 		}
   2965 		if y_start < y_end {
   2966 			**(**uintptr)(__ccgo_up(io + 24)) += uintptr((*VP8Io)(unsafe.Pointer(io)).Fcrop_left)
   2967 			**(**uintptr)(__ccgo_up(io + 32)) += uintptr((*VP8Io)(unsafe.Pointer(io)).Fcrop_left >> int32(1))
   2968 			**(**uintptr)(__ccgo_up(io + 40)) += uintptr((*VP8Io)(unsafe.Pointer(io)).Fcrop_left >> int32(1))
   2969 			if (*VP8Io)(unsafe.Pointer(io)).Fa != libc.UintptrFromInt32(0) {
   2970 				**(**uintptr)(__ccgo_up(io + 152)) += uintptr((*VP8Io)(unsafe.Pointer(io)).Fcrop_left)
   2971 			}
   2972 			(*VP8Io)(unsafe.Pointer(io)).Fmb_y = y_start - (*VP8Io)(unsafe.Pointer(io)).Fcrop_top
   2973 			(*VP8Io)(unsafe.Pointer(io)).Fmb_w = (*VP8Io)(unsafe.Pointer(io)).Fcrop_right - (*VP8Io)(unsafe.Pointer(io)).Fcrop_left
   2974 			(*VP8Io)(unsafe.Pointer(io)).Fmb_h = y_end - y_start
   2975 			ok = (*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*VP8Io)(unsafe.Pointer(io)).Fput})))(tls, io)
   2976 		}
   2977 	}
   2978 	// rotate top samples if needed
   2979 	if cache_id+int32(1) == (*VP8Decoder)(unsafe.Pointer(dec)).Fnum_caches {
   2980 		if !(is_last_row != 0) {
   2981 			libc.Xmemcpy(tls, (*VP8Decoder)(unsafe.Pointer(dec)).Fcache_y-uintptr(ysize), ydst+uintptr(int32(16)*(*VP8Decoder)(unsafe.Pointer(dec)).Fcache_y_stride), uint64(ysize))
   2982 			libc.Xmemcpy(tls, (*VP8Decoder)(unsafe.Pointer(dec)).Fcache_u-uintptr(uvsize), udst+uintptr(int32(8)*(*VP8Decoder)(unsafe.Pointer(dec)).Fcache_uv_stride), uint64(uvsize))
   2983 			libc.Xmemcpy(tls, (*VP8Decoder)(unsafe.Pointer(dec)).Fcache_v-uintptr(uvsize), vdst+uintptr(int32(8)*(*VP8Decoder)(unsafe.Pointer(dec)).Fcache_uv_stride), uint64(uvsize))
   2984 		}
   2985 	}
   2986 	return ok
   2987 }
   2988 
   2989 //------------------------------------------------------------------------------
   2990 
   2991 func VP8ProcessRow(tls *libc.TLS, dec uintptr, io uintptr) (r int32) {
   2992 	var ctx, tmp, tmp1, worker, v2 uintptr
   2993 	var filter_row, ok, v1 int32
   2994 	_, _, _, _, _, _, _, _ = ctx, filter_row, ok, tmp, tmp1, worker, v1, v2
   2995 	ok = int32(1)
   2996 	ctx = dec + 216
   2997 	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)
   2998 	if (*VP8Decoder)(unsafe.Pointer(dec)).Fmt_method == 0 {
   2999 		// ctx->id and ctx->f_info are already set
   3000 		(*VP8ThreadContext)(unsafe.Pointer(ctx)).Fmb_y = (*VP8Decoder)(unsafe.Pointer(dec)).Fmb_y
   3001 		(*VP8ThreadContext)(unsafe.Pointer(ctx)).Ffilter_row = filter_row
   3002 		ReconstructRow(tls, dec, ctx)
   3003 		ok = FinishRow(tls, dec, io)
   3004 	} else {
   3005 		worker = dec + 152
   3006 		// Finish previous job *before* updating context
   3007 		ok = ok & (*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*WebPWorkerInterface)(unsafe.Pointer(WebPGetWorkerInterface(tls))).FSync})))(tls, worker)
   3008 		if ok != 0 { // spawn a new deblocking/output job
   3009 			(*VP8ThreadContext)(unsafe.Pointer(ctx)).Fio = **(**VP8Io)(__ccgo_up(io))
   3010 			(*VP8ThreadContext)(unsafe.Pointer(ctx)).Fid = (*VP8Decoder)(unsafe.Pointer(dec)).Fcache_id
   3011 			(*VP8ThreadContext)(unsafe.Pointer(ctx)).Fmb_y = (*VP8Decoder)(unsafe.Pointer(dec)).Fmb_y
   3012 			(*VP8ThreadContext)(unsafe.Pointer(ctx)).Ffilter_row = filter_row
   3013 			if (*VP8Decoder)(unsafe.Pointer(dec)).Fmt_method == int32(2) { // swap macroblock data
   3014 				tmp = (*VP8ThreadContext)(unsafe.Pointer(ctx)).Fmb_data
   3015 				(*VP8ThreadContext)(unsafe.Pointer(ctx)).Fmb_data = (*VP8Decoder)(unsafe.Pointer(dec)).Fmb_data
   3016 				(*VP8Decoder)(unsafe.Pointer(dec)).Fmb_data = tmp
   3017 			} else {
   3018 				// perform reconstruction directly in main thread
   3019 				ReconstructRow(tls, dec, ctx)
   3020 			}
   3021 			if filter_row != 0 { // swap filter info
   3022 				tmp1 = (*VP8ThreadContext)(unsafe.Pointer(ctx)).Ff_info
   3023 				(*VP8ThreadContext)(unsafe.Pointer(ctx)).Ff_info = (*VP8Decoder)(unsafe.Pointer(dec)).Ff_info
   3024 				(*VP8Decoder)(unsafe.Pointer(dec)).Ff_info = tmp1
   3025 			}
   3026 			// (reconstruct)+filter in parallel
   3027 			(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(&struct{ uintptr }{(*WebPWorkerInterface)(unsafe.Pointer(WebPGetWorkerInterface(tls))).FLaunch})))(tls, worker)
   3028 			v2 = dec + 204
   3029 			*(*int32)(unsafe.Pointer(v2)) = *(*int32)(unsafe.Pointer(v2)) + 1
   3030 			v1 = *(*int32)(unsafe.Pointer(v2))
   3031 			if v1 == (*VP8Decoder)(unsafe.Pointer(dec)).Fnum_caches {
   3032 				(*VP8Decoder)(unsafe.Pointer(dec)).Fcache_id = 0
   3033 			}
   3034 		}
   3035 	}
   3036 	return ok
   3037 }
   3038 
   3039 //------------------------------------------------------------------------------
   3040 // Finish setting up the decoding parameter once user's setup() is called.
   3041 
   3042 func VP8EnterCritical(tls *libc.TLS, dec uintptr, io uintptr) (r VP8StatusCode1) {
   3043 	var extra_pixels int32
   3044 	_ = extra_pixels
   3045 	// Call setup() first. This may trigger additional decoding features on 'io'.
   3046 	// Note: Afterward, we must call teardown() no matter what.
   3047 	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) {
   3048 		VP8SetError(tls, dec, int32(VP8_STATUS_USER_ABORT), __ccgo_ts+66)
   3049 		return (*VP8Decoder)(unsafe.Pointer(dec)).Fstatus
   3050 	}
   3051 	// Disable filtering per user request
   3052 	if (*VP8Io)(unsafe.Pointer(io)).Fbypass_filtering != 0 {
   3053 		(*VP8Decoder)(unsafe.Pointer(dec)).Ffilter_type = 0
   3054 	}
   3055 	// Define the area where we can skip in-loop filtering, in case of cropping.
   3056 	//
   3057 	// 'Simple' filter reads two luma samples outside of the macroblock
   3058 	// and filters one. It doesn't filter the chroma samples. Hence, we can
   3059 	// avoid doing the in-loop filtering before crop_top/crop_left position.
   3060 	// For the 'Complex' filter, 3 samples are read and up to 3 are filtered.
   3061 	// Means: there's a dependency chain that goes all the way up to the
   3062 	// top-left corner of the picture (MB #0). We must filter all the previous
   3063 	// macroblocks.
   3064 	extra_pixels = int32(kFilterExtraRows[(*VP8Decoder)(unsafe.Pointer(dec)).Ffilter_type])
   3065 	if (*VP8Decoder)(unsafe.Pointer(dec)).Ffilter_type == int32(2) {
   3066 		// For complex filter, we need to preserve the dependency chain.
   3067 		(*VP8Decoder)(unsafe.Pointer(dec)).Ftl_mb_x = 0
   3068 		(*VP8Decoder)(unsafe.Pointer(dec)).Ftl_mb_y = 0
   3069 	} else {
   3070 		// For simple filter, we can filter only the cropped region.
   3071 		// We include 'extra_pixels' on the other side of the boundary, since
   3072 		// vertical or horizontal filtering of the previous macroblock can
   3073 		// modify some abutting pixels.
   3074 		(*VP8Decoder)(unsafe.Pointer(dec)).Ftl_mb_x = ((*VP8Io)(unsafe.Pointer(io)).Fcrop_left - extra_pixels) >> int32(4)
   3075 		(*VP8Decoder)(unsafe.Pointer(dec)).Ftl_mb_y = ((*VP8Io)(unsafe.Pointer(io)).Fcrop_top - extra_pixels) >> int32(4)
   3076 		if (*VP8Decoder)(unsafe.Pointer(dec)).Ftl_mb_x < 0 {
   3077 			(*VP8Decoder)(unsafe.Pointer(dec)).Ftl_mb_x = 0
   3078 		}
   3079 		if (*VP8Decoder)(unsafe.Pointer(dec)).Ftl_mb_y < 0 {
   3080 			(*VP8Decoder)(unsafe.Pointer(dec)).Ftl_mb_y = 0
   3081 		}
   3082 	}
   3083 	// We need some 'extra' pixels on the right/bottom.
   3084 	(*VP8Decoder)(unsafe.Pointer(dec)).Fbr_mb_y = ((*VP8Io)(unsafe.Pointer(io)).Fcrop_bottom + int32(15) + extra_pixels) >> int32(4)
   3085 	(*VP8Decoder)(unsafe.Pointer(dec)).Fbr_mb_x = ((*VP8Io)(unsafe.Pointer(io)).Fcrop_right + int32(15) + extra_pixels) >> int32(4)
   3086 	if (*VP8Decoder)(unsafe.Pointer(dec)).Fbr_mb_x > (*VP8Decoder)(unsafe.Pointer(dec)).Fmb_w {
   3087 		(*VP8Decoder)(unsafe.Pointer(dec)).Fbr_mb_x = (*VP8Decoder)(unsafe.Pointer(dec)).Fmb_w
   3088 	}
   3089 	if (*VP8Decoder)(unsafe.Pointer(dec)).Fbr_mb_y > (*VP8Decoder)(unsafe.Pointer(dec)).Fmb_h {
   3090 		(*VP8Decoder)(unsafe.Pointer(dec)).Fbr_mb_y = (*VP8Decoder)(unsafe.Pointer(dec)).Fmb_h
   3091 	}
   3092 	PrecomputeFilterStrengths(tls, dec)
   3093 	return int32(VP8_STATUS_OK)
   3094 }
   3095 
   3096 func VP8ExitCritical(tls *libc.TLS, dec uintptr, io uintptr) (r int32) {
   3097 	var ok int32
   3098 	_ = ok
   3099 	ok = int32(1)
   3100 	if (*VP8Decoder)(unsafe.Pointer(dec)).Fmt_method > 0 {
   3101 		ok = (*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*WebPWorkerInterface)(unsafe.Pointer(WebPGetWorkerInterface(tls))).FSync})))(tls, dec+152)
   3102 	}
   3103 	if (*VP8Io)(unsafe.Pointer(io)).Fteardown != libc.UintptrFromInt32(0) {
   3104 		(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(&struct{ uintptr }{(*VP8Io)(unsafe.Pointer(io)).Fteardown})))(tls, io)
   3105 	}
   3106 	return ok
   3107 }
   3108 
   3109 //------------------------------------------------------------------------------
   3110 // For multi-threaded decoding we need to use 3 rows of 16 pixels as delay line.
   3111 //
   3112 // Reason is: the deblocking filter cannot deblock the bottom horizontal edges
   3113 // immediately, and needs to wait for first few rows of the next macroblock to
   3114 // be decoded. Hence, deblocking is lagging behind by 4 or 8 pixels (depending
   3115 // on strength).
   3116 // With two threads, the vertical positions of the rows being decoded are:
   3117 // Decode:  [ 0..15][16..31][32..47][48..63][64..79][...
   3118 // Deblock:         [ 0..11][12..27][28..43][44..59][...
   3119 // If we use two threads and two caches of 16 pixels, the sequence would be:
   3120 // Decode:  [ 0..15][16..31][ 0..15!!][16..31][ 0..15][...
   3121 // Deblock:         [ 0..11][12..27!!][-4..11][12..27][...
   3122 // The problem occurs during row [12..15!!] that both the decoding and
   3123 // deblocking threads are writing simultaneously.
   3124 // With 3 cache lines, one get a safe write pattern:
   3125 // Decode:  [ 0..15][16..31][32..47][ 0..15][16..31][32..47][0..
   3126 // Deblock:         [ 0..11][12..27][28..43][-4..11][12..27][28...
   3127 // Note that multi-threaded output _without_ deblocking can make use of two
   3128 // cache lines of 16 pixels only, since there's no lagging behind. The decoding
   3129 // and output process have non-concurrent writing:
   3130 // Decode:  [ 0..15][16..31][ 0..15][16..31][...
   3131 // io->put:         [ 0..15][16..31][ 0..15][...
   3132 
   3133 // C documentation
   3134 //
   3135 //	// Initialize multi/single-thread worker
   3136 func InitThreadContext(tls *libc.TLS, dec uintptr) (r int32) {
   3137 	var worker uintptr
   3138 	var v1 int32
   3139 	_, _ = worker, v1
   3140 	(*VP8Decoder)(unsafe.Pointer(dec)).Fcache_id = 0
   3141 	if (*VP8Decoder)(unsafe.Pointer(dec)).Fmt_method > 0 {
   3142 		worker = dec + 152
   3143 		if !((*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*WebPWorkerInterface)(unsafe.Pointer(WebPGetWorkerInterface(tls))).FReset})))(tls, worker) != 0) {
   3144 			return VP8SetError(tls, dec, int32(VP8_STATUS_OUT_OF_MEMORY), __ccgo_ts+85)
   3145 		}
   3146 		(*WebPWorker)(unsafe.Pointer(worker)).Fdata1 = dec
   3147 		(*WebPWorker)(unsafe.Pointer(worker)).Fdata2 = dec + 216 + 32
   3148 		(*WebPWorker)(unsafe.Pointer(worker)).Fhook = __ccgo_fp(FinishRow)
   3149 		if (*VP8Decoder)(unsafe.Pointer(dec)).Ffilter_type > 0 {
   3150 			v1 = int32(3)
   3151 		} else {
   3152 			v1 = libc.Int32FromInt32(3) - libc.Int32FromInt32(1)
   3153 		}
   3154 		(*VP8Decoder)(unsafe.Pointer(dec)).Fnum_caches = v1
   3155 	} else {
   3156 		(*VP8Decoder)(unsafe.Pointer(dec)).Fnum_caches = int32(1)
   3157 	}
   3158 	return int32(1)
   3159 }
   3160 
   3161 func VP8GetThreadMethod(tls *libc.TLS, options uintptr, headers uintptr, width int32, height int32) (r int32) {
   3162 	if options == libc.UintptrFromInt32(0) || (*WebPDecoderOptions)(unsafe.Pointer(options)).Fuse_threads == 0 {
   3163 		return 0
   3164 	}
   3165 	_ = headers
   3166 	_ = width
   3167 	_ = height
   3168 	return 0
   3169 }
   3170 
   3171 //------------------------------------------------------------------------------
   3172 // Memory setup
   3173 
   3174 func AllocateMemory(tls *libc.TLS, dec uintptr) (r int32) {
   3175 	var alpha_size, needed, v5 uint64_t
   3176 	var cache_height, cache_size, f_info_size, intra_pred_mode_size, mb_data_size, mb_info_size, top_size, yuv_size size_t
   3177 	var extra_rows, extra_uv, extra_y, mb_w, num_caches, v2, v3, v6 int32
   3178 	var mem, v8 uintptr
   3179 	var v1, v4 uint64
   3180 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
   3181 	num_caches = (*VP8Decoder)(unsafe.Pointer(dec)).Fnum_caches
   3182 	mb_w = (*VP8Decoder)(unsafe.Pointer(dec)).Fmb_w
   3183 	// Note: we use 'size_t' when there's no overflow risk, uint64_t otherwise.
   3184 	intra_pred_mode_size = uint64(int32(4)*mb_w) * uint64(1)
   3185 	top_size = uint64(32) * uint64(mb_w)
   3186 	mb_info_size = uint64(mb_w+libc.Int32FromInt32(1)) * uint64(2)
   3187 	if (*VP8Decoder)(unsafe.Pointer(dec)).Ffilter_type > 0 {
   3188 		if (*VP8Decoder)(unsafe.Pointer(dec)).Fmt_method > 0 {
   3189 			v2 = int32(2)
   3190 		} else {
   3191 			v2 = int32(1)
   3192 		}
   3193 		v1 = uint64(mb_w*v2) * uint64(4)
   3194 	} else {
   3195 		v1 = uint64(0)
   3196 	}
   3197 	f_info_size = v1
   3198 	yuv_size = uint64(libc.Int32FromInt32(BPS)*libc.Int32FromInt32(17)+libc.Int32FromInt32(BPS)*libc.Int32FromInt32(9)) * libc.Uint64FromInt64(1)
   3199 	if (*VP8Decoder)(unsafe.Pointer(dec)).Fmt_method == int32(2) {
   3200 		v3 = int32(2)
   3201 	} else {
   3202 		v3 = int32(1)
   3203 	}
   3204 	mb_data_size = uint64(v3*mb_w) * uint64(800)
   3205 	cache_height = uint64((int32(16)*num_caches + int32(kFilterExtraRows[(*VP8Decoder)(unsafe.Pointer(dec)).Ffilter_type])) * int32(3) / int32(2))
   3206 	cache_size = top_size * cache_height
   3207 	if (*VP8Decoder)(unsafe.Pointer(dec)).Falpha_data != libc.UintptrFromInt32(0) {
   3208 		v4 = uint64((*VP8Decoder)(unsafe.Pointer(dec)).Fpic_hdr.Fwidth) * uint64((*VP8Decoder)(unsafe.Pointer(dec)).Fpic_hdr.Fheight)
   3209 	} else {
   3210 		v4 = 0
   3211 	}
   3212 	// alpha_size is the only one that scales as width x height.
   3213 	alpha_size = v4
   3214 	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)
   3215 	v5 = needed
   3216 	v6 = libc.BoolInt32(v5 == v5)
   3217 	goto _7
   3218 _7:
   3219 	if !(v6 != 0) {
   3220 		return 0
   3221 	} // check for overflow
   3222 	if needed > (*VP8Decoder)(unsafe.Pointer(dec)).Fmem_size {
   3223 		WebPSafeFree(tls, (*VP8Decoder)(unsafe.Pointer(dec)).Fmem)
   3224 		(*VP8Decoder)(unsafe.Pointer(dec)).Fmem_size = uint64(0)
   3225 		(*VP8Decoder)(unsafe.Pointer(dec)).Fmem = WebPSafeMalloc(tls, needed, uint64(1))
   3226 		if (*VP8Decoder)(unsafe.Pointer(dec)).Fmem == libc.UintptrFromInt32(0) {
   3227 			return VP8SetError(tls, dec, int32(VP8_STATUS_OUT_OF_MEMORY), __ccgo_ts+115)
   3228 		}
   3229 		// down-cast is ok, thanks to WebPSafeMalloc() above.
   3230 		(*VP8Decoder)(unsafe.Pointer(dec)).Fmem_size = needed
   3231 	}
   3232 	mem = (*VP8Decoder)(unsafe.Pointer(dec)).Fmem
   3233 	(*VP8Decoder)(unsafe.Pointer(dec)).Fintra_t = mem
   3234 	mem = mem + uintptr(intra_pred_mode_size)
   3235 	(*VP8Decoder)(unsafe.Pointer(dec)).Fyuv_t = mem
   3236 	mem = mem + uintptr(top_size)
   3237 	(*VP8Decoder)(unsafe.Pointer(dec)).Fmb_info = mem + uintptr(1)*2
   3238 	mem = mem + uintptr(mb_info_size)
   3239 	if f_info_size != 0 {
   3240 		v8 = mem
   3241 	} else {
   3242 		v8 = libc.UintptrFromInt32(0)
   3243 	}
   3244 	(*VP8Decoder)(unsafe.Pointer(dec)).Ff_info = v8
   3245 	mem = mem + uintptr(f_info_size)
   3246 	(*VP8Decoder)(unsafe.Pointer(dec)).Fthread_ctx.Fid = 0
   3247 	(*VP8Decoder)(unsafe.Pointer(dec)).Fthread_ctx.Ff_info = (*VP8Decoder)(unsafe.Pointer(dec)).Ff_info
   3248 	if (*VP8Decoder)(unsafe.Pointer(dec)).Ffilter_type > 0 && (*VP8Decoder)(unsafe.Pointer(dec)).Fmt_method > 0 {
   3249 		// secondary cache line. The deblocking process need to make use of the
   3250 		// filtering strength from previous macroblock row, while the new ones
   3251 		// are being decoded in parallel. We'll just swap the pointers.
   3252 		(*VP8Decoder)(unsafe.Pointer(dec)).Fthread_ctx.Ff_info += uintptr(mb_w) * 4
   3253 	}
   3254 	mem = uintptr((uint64(mem) + libc.Uint64FromInt32(WEBP_ALIGN_CST)) & ^libc.Uint64FromInt32(WEBP_ALIGN_CST))
   3255 	(*VP8Decoder)(unsafe.Pointer(dec)).Fyuv_b = mem
   3256 	mem = mem + uintptr(yuv_size)
   3257 	(*VP8Decoder)(unsafe.Pointer(dec)).Fmb_data = mem
   3258 	(*VP8Decoder)(unsafe.Pointer(dec)).Fthread_ctx.Fmb_data = mem
   3259 	if (*VP8Decoder)(unsafe.Pointer(dec)).Fmt_method == int32(2) {
   3260 		(*VP8Decoder)(unsafe.Pointer(dec)).Fthread_ctx.Fmb_data += uintptr(mb_w) * 800
   3261 	}
   3262 	mem = mem + uintptr(mb_data_size)
   3263 	(*VP8Decoder)(unsafe.Pointer(dec)).Fcache_y_stride = int32(16) * mb_w
   3264 	(*VP8Decoder)(unsafe.Pointer(dec)).Fcache_uv_stride = int32(8) * mb_w
   3265 	extra_rows = int32(kFilterExtraRows[(*VP8Decoder)(unsafe.Pointer(dec)).Ffilter_type])
   3266 	extra_y = extra_rows * (*VP8Decoder)(unsafe.Pointer(dec)).Fcache_y_stride
   3267 	extra_uv = extra_rows / int32(2) * (*VP8Decoder)(unsafe.Pointer(dec)).Fcache_uv_stride
   3268 	(*VP8Decoder)(unsafe.Pointer(dec)).Fcache_y = mem + uintptr(extra_y)
   3269 	(*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)
   3270 	(*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)
   3271 	(*VP8Decoder)(unsafe.Pointer(dec)).Fcache_id = 0
   3272 	mem = mem + uintptr(cache_size)
   3273 	// alpha plane
   3274 	if alpha_size != 0 {
   3275 		v8 = mem
   3276 	} else {
   3277 		v8 = libc.UintptrFromInt32(0)
   3278 	}
   3279 	(*VP8Decoder)(unsafe.Pointer(dec)).Falpha_plane = v8
   3280 	mem = mem + uintptr(alpha_size)
   3281 	// note: left/top-info is initialized once for all.
   3282 	libc.Xmemset(tls, (*VP8Decoder)(unsafe.Pointer(dec)).Fmb_info-uintptr(1)*2, 0, mb_info_size)
   3283 	VP8InitScanline(tls, dec) // initialize left too.
   3284 	// initialize top
   3285 	libc.Xmemset(tls, (*VP8Decoder)(unsafe.Pointer(dec)).Fintra_t, int32(B_DC_PRED), intra_pred_mode_size)
   3286 	return int32(1)
   3287 }
   3288 
   3289 func InitIo(tls *libc.TLS, dec uintptr, io uintptr) {
   3290 	// prepare 'io'
   3291 	(*VP8Io)(unsafe.Pointer(io)).Fmb_y = 0
   3292 	(*VP8Io)(unsafe.Pointer(io)).Fy = (*VP8Decoder)(unsafe.Pointer(dec)).Fcache_y
   3293 	(*VP8Io)(unsafe.Pointer(io)).Fu = (*VP8Decoder)(unsafe.Pointer(dec)).Fcache_u
   3294 	(*VP8Io)(unsafe.Pointer(io)).Fv = (*VP8Decoder)(unsafe.Pointer(dec)).Fcache_v
   3295 	(*VP8Io)(unsafe.Pointer(io)).Fy_stride = (*VP8Decoder)(unsafe.Pointer(dec)).Fcache_y_stride
   3296 	(*VP8Io)(unsafe.Pointer(io)).Fuv_stride = (*VP8Decoder)(unsafe.Pointer(dec)).Fcache_uv_stride
   3297 	(*VP8Io)(unsafe.Pointer(io)).Fa = libc.UintptrFromInt32(0)
   3298 }
   3299 
   3300 func VP8InitFrame(tls *libc.TLS, dec uintptr, io uintptr) (r int32) {
   3301 	if !(InitThreadContext(tls, dec) != 0) {
   3302 		return 0
   3303 	} // call first. Sets dec->num_caches.
   3304 	if !(AllocateMemory(tls, dec) != 0) {
   3305 		return 0
   3306 	}
   3307 	InitIo(tls, dec, io)
   3308 	VP8DspInit(tls) // Init critical function pointers and look-up tables.
   3309 	return int32(1)
   3310 }
   3311 
   3312 const CHUNK_SIZE = 4096
   3313 const MAX_MB_SIZE = 4096
   3314 
   3315 type WebPIDecoder = struct {
   3316 	Fstate        DecState
   3317 	Fparams       WebPDecParams
   3318 	Fis_lossless  int32
   3319 	Fdec          uintptr
   3320 	Fio           VP8Io
   3321 	Fmem          MemBuffer
   3322 	Foutput       WebPDecBuffer
   3323 	Ffinal_output uintptr
   3324 	Fchunk_size   size_t
   3325 	Flast_mb_y    int32
   3326 }
   3327 
   3328 const STATE_WEBP_HEADER = 0
   3329 const // All the data before that of the VP8/VP8L chunk.
   3330 STATE_VP8_HEADER = 1
   3331 const // The VP8 Frame header (within the VP8 chunk).
   3332 STATE_VP8_PARTS0 = 2
   3333 const STATE_VP8_DATA = 3
   3334 const STATE_VP8L_HEADER = 4
   3335 const STATE_VP8L_DATA = 5
   3336 const STATE_DONE = 6
   3337 const STATE_ERROR = 7
   3338 
   3339 var kHashMul3 = uint32(0x1e35a7bd)
   3340 
   3341 //------------------------------------------------------------------------------
   3342 
   3343 // Copyright 2010 Google Inc. All Rights Reserved.
   3344 //
   3345 // Use of this source code is governed by a BSD-style license
   3346 // that can be found in the COPYING file in the root of the source
   3347 // tree. An additional intellectual property rights grant can be found
   3348 // in the file PATENTS. All contributing project authors may
   3349 // be found in the AUTHORS file in the root of the source tree.
   3350 // -----------------------------------------------------------------------------
   3351 //
   3352 //  Main decoding functions for WebP images.
   3353 //
   3354 // Author: Skal (pascal.massimino@gmail.com)
   3355 
   3356 // Copyright 2012 Google Inc. All Rights Reserved.
   3357 //
   3358 // Use of this source code is governed by a BSD-style license
   3359 // that can be found in the COPYING file in the root of the source
   3360 // tree. An additional intellectual property rights grant can be found
   3361 // in the file PATENTS. All contributing project authors may
   3362 // be found in the AUTHORS file in the root of the source tree.
   3363 // -----------------------------------------------------------------------------
   3364 //
   3365 //  Internal header for constants related to WebP file format.
   3366 //
   3367 // Author: Urvang (urvang@google.com)
   3368 
   3369 // Copyright 2010 Google Inc. All Rights Reserved.
   3370 //
   3371 // Use of this source code is governed by a BSD-style license
   3372 // that can be found in the COPYING file in the root of the source
   3373 // tree. An additional intellectual property rights grant can be found
   3374 // in the file PATENTS. All contributing project authors may
   3375 // be found in the AUTHORS file in the root of the source tree.
   3376 // -----------------------------------------------------------------------------
   3377 //
   3378 //  Common types + memory wrappers
   3379 //
   3380 // Author: Skal (pascal.massimino@gmail.com)
   3381 
   3382 // In append mode, buffer allocations increase as multiples of this value.
   3383 // Needs to be a power of 2.
   3384 
   3385 //------------------------------------------------------------------------------
   3386 // Data structures for memory and states
   3387 
   3388 // C documentation
   3389 //
   3390 //	// Decoding states. State normally flows as:
   3391 //	// WEBP_HEADER->VP8_HEADER->VP8_PARTS0->VP8_DATA->DONE for a lossy image, and
   3392 //	// WEBP_HEADER->VP8L_HEADER->VP8L_DATA->DONE for a lossless image.
   3393 //	// If there is any error the decoder goes into state ERROR.
   3394 type DecState = int32
   3395 
   3396 // C documentation
   3397 //
   3398 //	// Operating state for the MemBuffer
   3399 type MemBufferMode = int32
   3400 
   3401 const MEM_MODE_NONE = 0
   3402 const MEM_MODE_APPEND = 1
   3403 const MEM_MODE_MAP = 2
   3404 
   3405 // C documentation
   3406 //
   3407 //	// storage for partition #0 and partial data (in a rolling fashion)
   3408 type MemBuffer = struct {
   3409 	Fmode       MemBufferMode
   3410 	Fstart      size_t
   3411 	Fend        size_t
   3412 	Fbuf_size   size_t
   3413 	Fbuf        uintptr
   3414 	Fpart0_size size_t
   3415 	Fpart0_buf  uintptr
   3416 }
   3417 
   3418 // C documentation
   3419 //
   3420 //	// MB context to restore in case VP8DecodeMB() fails
   3421 type MBContext = struct {
   3422 	Fleft     VP8MB
   3423 	Finfo     VP8MB
   3424 	Ftoken_br VP8BitReader
   3425 }
   3426 
   3427 //------------------------------------------------------------------------------
   3428 // MemBuffer: incoming data handling
   3429 
   3430 func MemDataSize(tls *libc.TLS, mem uintptr) (r size_t) {
   3431 	return (*MemBuffer)(unsafe.Pointer(mem)).Fend - (*MemBuffer)(unsafe.Pointer(mem)).Fstart
   3432 }
   3433 
   3434 // C documentation
   3435 //
   3436 //	// Check if we need to preserve the compressed alpha data, as it may not have
   3437 //	// been decoded yet.
   3438 func NeedCompressedAlpha(tls *libc.TLS, idec uintptr) (r int32) {
   3439 	var dec uintptr
   3440 	_ = dec
   3441 	if (*WebPIDecoder)(unsafe.Pointer(idec)).Fstate == int32(STATE_WEBP_HEADER) {
   3442 		// We haven't parsed the headers yet, so we don't know whether the image is
   3443 		// lossy or lossless. This also means that we haven't parsed the ALPH chunk.
   3444 		return 0
   3445 	}
   3446 	if (*WebPIDecoder)(unsafe.Pointer(idec)).Fis_lossless != 0 {
   3447 		return 0 // ALPH chunk is not present for lossless images.
   3448 	} else {
   3449 		dec = (*WebPIDecoder)(unsafe.Pointer(idec)).Fdec
   3450 		// Must be true as idec->state != STATE_WEBP_HEADER.
   3451 		return libc.BoolInt32((*VP8Decoder)(unsafe.Pointer(dec)).Falpha_data != libc.UintptrFromInt32(0) && !((*VP8Decoder)(unsafe.Pointer(dec)).Fis_alpha_decoded != 0))
   3452 	}
   3453 	return r
   3454 }
   3455 
   3456 func DoRemap(tls *libc.TLS, idec uintptr, offset ptrdiff_t) {
   3457 	var alph_dec, alph_vp8l_dec, dec, dec1, last_start, mem, new_base uintptr
   3458 	var last_part, p uint32_t
   3459 	_, _, _, _, _, _, _, _, _ = alph_dec, alph_vp8l_dec, dec, dec1, last_part, last_start, mem, new_base, p
   3460 	mem = idec + 296
   3461 	new_base = (*MemBuffer)(unsafe.Pointer(mem)).Fbuf + uintptr((*MemBuffer)(unsafe.Pointer(mem)).Fstart)
   3462 	// note: for VP8, setting up idec->io is only really needed at the beginning
   3463 	// of the decoding, till partition #0 is complete.
   3464 	(*WebPIDecoder)(unsafe.Pointer(idec)).Fio.Fdata = new_base
   3465 	(*WebPIDecoder)(unsafe.Pointer(idec)).Fio.Fdata_size = MemDataSize(tls, mem)
   3466 	if (*WebPIDecoder)(unsafe.Pointer(idec)).Fdec != libc.UintptrFromInt32(0) {
   3467 		if !((*WebPIDecoder)(unsafe.Pointer(idec)).Fis_lossless != 0) {
   3468 			dec = (*WebPIDecoder)(unsafe.Pointer(idec)).Fdec
   3469 			last_part = (*VP8Decoder)(unsafe.Pointer(dec)).Fnum_parts_minus_one
   3470 			if offset != 0 {
   3471 				p = uint32(0)
   3472 				for {
   3473 					if !(p <= last_part) {
   3474 						break
   3475 					}
   3476 					VP8RemapBitReader(tls, dec+440+uintptr(p)*48, offset)
   3477 					goto _1
   3478 				_1:
   3479 					;
   3480 					p = p + 1
   3481 				}
   3482 				// Remap partition #0 data pointer to new offset, but only in MAP
   3483 				// mode (in APPEND mode, partition #0 is copied into a fixed memory).
   3484 				if (*MemBuffer)(unsafe.Pointer(mem)).Fmode == int32(MEM_MODE_MAP) {
   3485 					VP8RemapBitReader(tls, dec+16, offset)
   3486 				}
   3487 			}
   3488 			last_start = (**(**VP8BitReader)(__ccgo_up(dec + 440 + uintptr(last_part)*48))).Fbuf
   3489 			// 'last_start' will be NULL when 'idec->state' is < STATE_VP8_PARTS0
   3490 			// and through a portion of that state (when there isn't enough data to
   3491 			// parse the partitions). The bitreader is only used meaningfully when
   3492 			// there is enough data to begin parsing partition 0.
   3493 			if last_start != libc.UintptrFromInt32(0) {
   3494 				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)))
   3495 			}
   3496 			if NeedCompressedAlpha(tls, idec) != 0 {
   3497 				alph_dec = (*VP8Decoder)(unsafe.Pointer(dec)).Falph_dec
   3498 				**(**uintptr)(__ccgo_up(dec + 2968)) += uintptr(offset)
   3499 				if alph_dec != libc.UintptrFromInt32(0) && (*ALPHDecoder)(unsafe.Pointer(alph_dec)).Fvp8l_dec != libc.UintptrFromInt32(0) {
   3500 					if (*ALPHDecoder)(unsafe.Pointer(alph_dec)).Fmethod == int32(ALPHA_LOSSLESS_COMPRESSION) {
   3501 						alph_vp8l_dec = (*ALPHDecoder)(unsafe.Pointer(alph_dec)).Fvp8l_dec
   3502 						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))
   3503 					} else { // alph_dec->method == ALPHA_NO_COMPRESSION
   3504 						// Nothing special to do in this case.
   3505 					}
   3506 				}
   3507 			}
   3508 		} else { // Resize lossless bitreader
   3509 			dec1 = (*WebPIDecoder)(unsafe.Pointer(idec)).Fdec
   3510 			VP8LBitReaderSetBuffer(tls, dec1+40, new_base, MemDataSize(tls, mem))
   3511 		}
   3512 	}
   3513 }
   3514 
   3515 // C documentation
   3516 //
   3517 //	// Appends data to the end of MemBuffer->buf. It expands the allocated memory
   3518 //	// size if required and also updates VP8BitReader's if new memory is allocated.
   3519 func AppendToMemBuffer(tls *libc.TLS, idec uintptr, data uintptr, data_size size_t) (r int32) {
   3520 	var current_size, new_mem_start size_t
   3521 	var dec, mem, new_buf, old_base, old_start, v1, v2 uintptr
   3522 	var extra_size, new_size uint64_t
   3523 	var need_compressed_alpha int32
   3524 	_, _, _, _, _, _, _, _, _, _, _, _ = current_size, dec, extra_size, mem, need_compressed_alpha, new_buf, new_mem_start, new_size, old_base, old_start, v1, v2
   3525 	dec = (*WebPIDecoder)(unsafe.Pointer(idec)).Fdec
   3526 	mem = idec + 296
   3527 	need_compressed_alpha = NeedCompressedAlpha(tls, idec)
   3528 	if (*MemBuffer)(unsafe.Pointer(mem)).Fbuf == libc.UintptrFromInt32(0) {
   3529 		v1 = libc.UintptrFromInt32(0)
   3530 	} else {
   3531 		v1 = (*MemBuffer)(unsafe.Pointer(mem)).Fbuf + uintptr((*MemBuffer)(unsafe.Pointer(mem)).Fstart)
   3532 	}
   3533 	old_start = v1
   3534 	if need_compressed_alpha != 0 {
   3535 		v2 = (*VP8Decoder)(unsafe.Pointer(dec)).Falpha_data
   3536 	} else {
   3537 		v2 = old_start
   3538 	}
   3539 	old_base = v2
   3540 	if data_size > uint64(^libc.Uint32FromUint32(0)-libc.Uint32FromInt32(CHUNK_HEADER_SIZE)-libc.Uint32FromInt32(1)) {
   3541 		// security safeguard: trying to allocate more than what the format
   3542 		// allows for a chunk should be considered a smoke smell.
   3543 		return 0
   3544 	}
   3545 	if (*MemBuffer)(unsafe.Pointer(mem)).Fend+data_size > (*MemBuffer)(unsafe.Pointer(mem)).Fbuf_size { // Need some free memory
   3546 		new_mem_start = uint64(int64(old_start) - int64(old_base))
   3547 		current_size = MemDataSize(tls, mem) + new_mem_start
   3548 		new_size = current_size + data_size
   3549 		extra_size = (new_size + uint64(CHUNK_SIZE) - uint64(1)) & uint64(^(libc.Int32FromInt32(CHUNK_SIZE) - libc.Int32FromInt32(1)))
   3550 		new_buf = WebPSafeMalloc(tls, extra_size, uint64(1))
   3551 		if new_buf == libc.UintptrFromInt32(0) {
   3552 			return 0
   3553 		}
   3554 		if old_base != libc.UintptrFromInt32(0) {
   3555 			libc.Xmemcpy(tls, new_buf, old_base, current_size)
   3556 		}
   3557 		WebPSafeFree(tls, (*MemBuffer)(unsafe.Pointer(mem)).Fbuf)
   3558 		(*MemBuffer)(unsafe.Pointer(mem)).Fbuf = new_buf
   3559 		(*MemBuffer)(unsafe.Pointer(mem)).Fbuf_size = extra_size
   3560 		(*MemBuffer)(unsafe.Pointer(mem)).Fstart = new_mem_start
   3561 		(*MemBuffer)(unsafe.Pointer(mem)).Fend = current_size
   3562 	}
   3563 	libc.Xmemcpy(tls, (*MemBuffer)(unsafe.Pointer(mem)).Fbuf+uintptr((*MemBuffer)(unsafe.Pointer(mem)).Fend), data, data_size)
   3564 	**(**size_t)(__ccgo_up(mem + 16)) += data_size
   3565 	DoRemap(tls, idec, int64((*MemBuffer)(unsafe.Pointer(mem)).Fbuf+uintptr((*MemBuffer)(unsafe.Pointer(mem)).Fstart))-int64(old_start))
   3566 	return int32(1)
   3567 }
   3568 
   3569 func RemapMemBuffer(tls *libc.TLS, idec uintptr, data uintptr, data_size size_t) (r int32) {
   3570 	var mem, old_buf, old_start, v1 uintptr
   3571 	var v2 size_t
   3572 	_, _, _, _, _ = mem, old_buf, old_start, v1, v2
   3573 	mem = idec + 296
   3574 	old_buf = (*MemBuffer)(unsafe.Pointer(mem)).Fbuf
   3575 	if old_buf == libc.UintptrFromInt32(0) {
   3576 		v1 = libc.UintptrFromInt32(0)
   3577 	} else {
   3578 		v1 = old_buf + uintptr((*MemBuffer)(unsafe.Pointer(mem)).Fstart)
   3579 	}
   3580 	old_start = v1
   3581 	if data_size < (*MemBuffer)(unsafe.Pointer(mem)).Fbuf_size {
   3582 		return 0
   3583 	} // can't remap to a shorter buffer!
   3584 	(*MemBuffer)(unsafe.Pointer(mem)).Fbuf = data
   3585 	v2 = data_size
   3586 	(*MemBuffer)(unsafe.Pointer(mem)).Fbuf_size = v2
   3587 	(*MemBuffer)(unsafe.Pointer(mem)).Fend = v2
   3588 	DoRemap(tls, idec, int64((*MemBuffer)(unsafe.Pointer(mem)).Fbuf+uintptr((*MemBuffer)(unsafe.Pointer(mem)).Fstart))-int64(old_start))
   3589 	return int32(1)
   3590 }
   3591 
   3592 func InitMemBuffer(tls *libc.TLS, mem uintptr) {
   3593 	(*MemBuffer)(unsafe.Pointer(mem)).Fmode = int32(MEM_MODE_NONE)
   3594 	(*MemBuffer)(unsafe.Pointer(mem)).Fbuf = libc.UintptrFromInt32(0)
   3595 	(*MemBuffer)(unsafe.Pointer(mem)).Fbuf_size = uint64(0)
   3596 	(*MemBuffer)(unsafe.Pointer(mem)).Fpart0_buf = libc.UintptrFromInt32(0)
   3597 	(*MemBuffer)(unsafe.Pointer(mem)).Fpart0_size = uint64(0)
   3598 }
   3599 
   3600 func ClearMemBuffer(tls *libc.TLS, mem uintptr) {
   3601 	if (*MemBuffer)(unsafe.Pointer(mem)).Fmode == int32(MEM_MODE_APPEND) {
   3602 		WebPSafeFree(tls, (*MemBuffer)(unsafe.Pointer(mem)).Fbuf)
   3603 		WebPSafeFree(tls, (*MemBuffer)(unsafe.Pointer(mem)).Fpart0_buf)
   3604 	}
   3605 }
   3606 
   3607 func CheckMemBufferMode(tls *libc.TLS, mem uintptr, expected MemBufferMode) (r int32) {
   3608 	if (*MemBuffer)(unsafe.Pointer(mem)).Fmode == int32(MEM_MODE_NONE) {
   3609 		(*MemBuffer)(unsafe.Pointer(mem)).Fmode = expected // switch to the expected mode
   3610 	} else {
   3611 		if (*MemBuffer)(unsafe.Pointer(mem)).Fmode != expected {
   3612 			return 0 // we mixed the modes => error
   3613 		}
   3614 	}
   3615 	// mode is ok
   3616 	return int32(1)
   3617 }
   3618 
   3619 // C documentation
   3620 //
   3621 //	// To be called last.
   3622 func FinishDecoding(tls *libc.TLS, idec uintptr) (r VP8StatusCode1) {
   3623 	var options, output uintptr
   3624 	var status, status1 VP8StatusCode1
   3625 	_, _, _, _ = options, output, status, status1
   3626 	options = (*WebPIDecoder)(unsafe.Pointer(idec)).Fparams.Foptions
   3627 	output = (*WebPIDecoder)(unsafe.Pointer(idec)).Fparams.Foutput
   3628 	(*WebPIDecoder)(unsafe.Pointer(idec)).Fstate = int32(STATE_DONE)
   3629 	if options != libc.UintptrFromInt32(0) && (*WebPDecoderOptions)(unsafe.Pointer(options)).Fflip != 0 {
   3630 		status = WebPFlipBuffer(tls, output)
   3631 		if status != int32(VP8_STATUS_OK) {
   3632 			return status
   3633 		}
   3634 	}
   3635 	if (*WebPIDecoder)(unsafe.Pointer(idec)).Ffinal_output != libc.UintptrFromInt32(0) {
   3636 		status1 = WebPCopyDecBufferPixels(tls, output, (*WebPIDecoder)(unsafe.Pointer(idec)).Ffinal_output) // do the slow-copy
   3637 		WebPFreeDecBuffer(tls, idec+352)
   3638 		if status1 != int32(VP8_STATUS_OK) {
   3639 			return status1
   3640 		}
   3641 		**(**WebPDecBuffer)(__ccgo_up(output)) = **(**WebPDecBuffer)(__ccgo_up((*WebPIDecoder)(unsafe.Pointer(idec)).Ffinal_output))
   3642 		(*WebPIDecoder)(unsafe.Pointer(idec)).Ffinal_output = libc.UintptrFromInt32(0)
   3643 	}
   3644 	return int32(VP8_STATUS_OK)
   3645 }
   3646 
   3647 //------------------------------------------------------------------------------
   3648 // Macroblock-decoding contexts
   3649 
   3650 func SaveContext(tls *libc.TLS, dec uintptr, token_br uintptr, context uintptr) {
   3651 	(*MBContext)(unsafe.Pointer(context)).Fleft = **(**VP8MB)(__ccgo_up((*VP8Decoder)(unsafe.Pointer(dec)).Fmb_info + uintptr(-libc.Int32FromInt32(1))*2))
   3652 	(*MBContext)(unsafe.Pointer(context)).Finfo = **(**VP8MB)(__ccgo_up((*VP8Decoder)(unsafe.Pointer(dec)).Fmb_info + uintptr((*VP8Decoder)(unsafe.Pointer(dec)).Fmb_x)*2))
   3653 	(*MBContext)(unsafe.Pointer(context)).Ftoken_br = **(**VP8BitReader)(__ccgo_up(token_br))
   3654 }
   3655 
   3656 func RestoreContext(tls *libc.TLS, context uintptr, dec uintptr, token_br uintptr) {
   3657 	**(**VP8MB)(__ccgo_up((*VP8Decoder)(unsafe.Pointer(dec)).Fmb_info + uintptr(-libc.Int32FromInt32(1))*2)) = (*MBContext)(unsafe.Pointer(context)).Fleft
   3658 	**(**VP8MB)(__ccgo_up((*VP8Decoder)(unsafe.Pointer(dec)).Fmb_info + uintptr((*VP8Decoder)(unsafe.Pointer(dec)).Fmb_x)*2)) = (*MBContext)(unsafe.Pointer(context)).Finfo
   3659 	**(**VP8BitReader)(__ccgo_up(token_br)) = (*MBContext)(unsafe.Pointer(context)).Ftoken_br
   3660 }
   3661 
   3662 //------------------------------------------------------------------------------
   3663 
   3664 func IDecError(tls *libc.TLS, idec uintptr, error1 VP8StatusCode1) (r VP8StatusCode1) {
   3665 	if (*WebPIDecoder)(unsafe.Pointer(idec)).Fstate == int32(STATE_VP8_DATA) {
   3666 		// Synchronize the thread, clean-up and check for errors.
   3667 		VP8ExitCritical(tls, (*WebPIDecoder)(unsafe.Pointer(idec)).Fdec, idec+136)
   3668 	}
   3669 	(*WebPIDecoder)(unsafe.Pointer(idec)).Fstate = int32(STATE_ERROR)
   3670 	return error1
   3671 }
   3672 
   3673 func ChangeState(tls *libc.TLS, idec uintptr, new_state DecState, consumed_bytes size_t) {
   3674 	var mem uintptr
   3675 	_ = mem
   3676 	mem = idec + 296
   3677 	(*WebPIDecoder)(unsafe.Pointer(idec)).Fstate = new_state
   3678 	**(**size_t)(__ccgo_up(mem + 8)) += consumed_bytes
   3679 	(*WebPIDecoder)(unsafe.Pointer(idec)).Fio.Fdata = (*MemBuffer)(unsafe.Pointer(mem)).Fbuf + uintptr((*MemBuffer)(unsafe.Pointer(mem)).Fstart)
   3680 	(*WebPIDecoder)(unsafe.Pointer(idec)).Fio.Fdata_size = MemDataSize(tls, mem)
   3681 }
   3682 
   3683 // C documentation
   3684 //
   3685 //	// Headers
   3686 func DecodeWebPHeaders(tls *libc.TLS, idec uintptr) (r VP8StatusCode1) {
   3687 	bp := tls.Alloc(80)
   3688 	defer tls.Free(80)
   3689 	var curr_size size_t
   3690 	var data, dec, dec1, mem uintptr
   3691 	var status VP8StatusCode1
   3692 	var _ /* headers at bp+0 */ WebPHeaderStructure
   3693 	_, _, _, _, _, _ = curr_size, data, dec, dec1, mem, status
   3694 	mem = idec + 296
   3695 	data = (*MemBuffer)(unsafe.Pointer(mem)).Fbuf + uintptr((*MemBuffer)(unsafe.Pointer(mem)).Fstart)
   3696 	curr_size = MemDataSize(tls, mem)
   3697 	(**(**WebPHeaderStructure)(__ccgo_up(bp))).Fdata = data
   3698 	(**(**WebPHeaderStructure)(__ccgo_up(bp))).Fdata_size = curr_size
   3699 	(**(**WebPHeaderStructure)(__ccgo_up(bp))).Fhave_all_data = 0
   3700 	status = WebPParseHeaders(tls, bp)
   3701 	if status == int32(VP8_STATUS_NOT_ENOUGH_DATA) {
   3702 		return int32(VP8_STATUS_SUSPENDED) // We haven't found a VP8 chunk yet.
   3703 	} else {
   3704 		if status != int32(VP8_STATUS_OK) {
   3705 			return IDecError(tls, idec, status)
   3706 		}
   3707 	}
   3708 	(*WebPIDecoder)(unsafe.Pointer(idec)).Fchunk_size = (**(**WebPHeaderStructure)(__ccgo_up(bp))).Fcompressed_size
   3709 	(*WebPIDecoder)(unsafe.Pointer(idec)).Fis_lossless = (**(**WebPHeaderStructure)(__ccgo_up(bp))).Fis_lossless
   3710 	if !((*WebPIDecoder)(unsafe.Pointer(idec)).Fis_lossless != 0) {
   3711 		dec = VP8New(tls)
   3712 		if dec == libc.UintptrFromInt32(0) {
   3713 			return int32(VP8_STATUS_OUT_OF_MEMORY)
   3714 		}
   3715 		(*VP8Decoder)(unsafe.Pointer(dec)).Fincremental = int32(1)
   3716 		(*WebPIDecoder)(unsafe.Pointer(idec)).Fdec = dec
   3717 		(*VP8Decoder)(unsafe.Pointer(dec)).Falpha_data = (**(**WebPHeaderStructure)(__ccgo_up(bp))).Falpha_data
   3718 		(*VP8Decoder)(unsafe.Pointer(dec)).Falpha_data_size = (**(**WebPHeaderStructure)(__ccgo_up(bp))).Falpha_data_size
   3719 		ChangeState(tls, idec, int32(STATE_VP8_HEADER), (**(**WebPHeaderStructure)(__ccgo_up(bp))).Foffset)
   3720 	} else {
   3721 		dec1 = VP8LNew(tls)
   3722 		if dec1 == libc.UintptrFromInt32(0) {
   3723 			return int32(VP8_STATUS_OUT_OF_MEMORY)
   3724 		}
   3725 		(*WebPIDecoder)(unsafe.Pointer(idec)).Fdec = dec1
   3726 		ChangeState(tls, idec, int32(STATE_VP8L_HEADER), (**(**WebPHeaderStructure)(__ccgo_up(bp))).Foffset)
   3727 	}
   3728 	return int32(VP8_STATUS_OK)
   3729 }
   3730 
   3731 func DecodeVP8FrameHeader(tls *libc.TLS, idec uintptr) (r VP8StatusCode1) {
   3732 	bp := tls.Alloc(16)
   3733 	defer tls.Free(16)
   3734 	var bits uint32_t
   3735 	var curr_size size_t
   3736 	var data uintptr
   3737 	var _ /* height at bp+4 */ int32
   3738 	var _ /* width at bp+0 */ int32
   3739 	_, _, _ = bits, curr_size, data
   3740 	data = (*WebPIDecoder)(unsafe.Pointer(idec)).Fmem.Fbuf + uintptr((*WebPIDecoder)(unsafe.Pointer(idec)).Fmem.Fstart)
   3741 	curr_size = MemDataSize(tls, idec+296)
   3742 	if curr_size < uint64(VP8_FRAME_HEADER_SIZE) {
   3743 		// Not enough data bytes to extract VP8 Frame Header.
   3744 		return int32(VP8_STATUS_SUSPENDED)
   3745 	}
   3746 	if !(VP8GetInfo(tls, data, curr_size, (*WebPIDecoder)(unsafe.Pointer(idec)).Fchunk_size, bp, bp+4) != 0) {
   3747 		return IDecError(tls, idec, int32(VP8_STATUS_BITSTREAM_ERROR))
   3748 	}
   3749 	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))
   3750 	(*WebPIDecoder)(unsafe.Pointer(idec)).Fmem.Fpart0_size = uint64(bits>>libc.Int32FromInt32(5) + uint32(VP8_FRAME_HEADER_SIZE))
   3751 	(*WebPIDecoder)(unsafe.Pointer(idec)).Fio.Fdata = data
   3752 	(*WebPIDecoder)(unsafe.Pointer(idec)).Fio.Fdata_size = curr_size
   3753 	(*WebPIDecoder)(unsafe.Pointer(idec)).Fstate = int32(STATE_VP8_PARTS0)
   3754 	return int32(VP8_STATUS_OK)
   3755 }
   3756 
   3757 // C documentation
   3758 //
   3759 //	// Partition #0
   3760 func CopyParts0Data(tls *libc.TLS, idec uintptr) (r VP8StatusCode1) {
   3761 	var br, dec, mem, part0_buf uintptr
   3762 	var part_size size_t
   3763 	_, _, _, _, _ = br, dec, mem, part0_buf, part_size
   3764 	dec = (*WebPIDecoder)(unsafe.Pointer(idec)).Fdec
   3765 	br = dec + 16
   3766 	part_size = uint64(int64((*VP8BitReader)(unsafe.Pointer(br)).Fbuf_end) - int64((*VP8BitReader)(unsafe.Pointer(br)).Fbuf))
   3767 	mem = idec + 296
   3768 	// the following is a format limitation, no need for runtime check:
   3769 	if part_size == uint64(0) { // can't have zero-size partition #0
   3770 		return int32(VP8_STATUS_BITSTREAM_ERROR)
   3771 	}
   3772 	if (*MemBuffer)(unsafe.Pointer(mem)).Fmode == int32(MEM_MODE_APPEND) {
   3773 		// We copy and grab ownership of the partition #0 data.
   3774 		part0_buf = WebPSafeMalloc(tls, uint64(1), part_size)
   3775 		if part0_buf == libc.UintptrFromInt32(0) {
   3776 			return int32(VP8_STATUS_OUT_OF_MEMORY)
   3777 		}
   3778 		libc.Xmemcpy(tls, part0_buf, (*VP8BitReader)(unsafe.Pointer(br)).Fbuf, part_size)
   3779 		(*MemBuffer)(unsafe.Pointer(mem)).Fpart0_buf = part0_buf
   3780 		VP8BitReaderSetBuffer(tls, br, part0_buf, part_size)
   3781 	} else {
   3782 		// Else: just keep pointers to the partition #0's data in dec->br.
   3783 	}
   3784 	**(**size_t)(__ccgo_up(mem + 8)) += part_size
   3785 	return int32(VP8_STATUS_OK)
   3786 }
   3787 
   3788 func DecodePartition0(tls *libc.TLS, idec uintptr) (r VP8StatusCode1) {
   3789 	var dec, io, output, params uintptr
   3790 	var status VP8StatusCode1
   3791 	_, _, _, _, _ = dec, io, output, params, status
   3792 	dec = (*WebPIDecoder)(unsafe.Pointer(idec)).Fdec
   3793 	io = idec + 136
   3794 	params = idec + 8
   3795 	output = (*WebPDecParams)(unsafe.Pointer(params)).Foutput
   3796 	// Wait till we have enough data for the whole partition #0
   3797 	if MemDataSize(tls, idec+296) < (*WebPIDecoder)(unsafe.Pointer(idec)).Fmem.Fpart0_size {
   3798 		return int32(VP8_STATUS_SUSPENDED)
   3799 	}
   3800 	if !(VP8GetHeaders(tls, dec, io) != 0) {
   3801 		status = (*VP8Decoder)(unsafe.Pointer(dec)).Fstatus
   3802 		if status == int32(VP8_STATUS_SUSPENDED) || status == int32(VP8_STATUS_NOT_ENOUGH_DATA) {
   3803 			// treating NOT_ENOUGH_DATA as SUSPENDED state
   3804 			return int32(VP8_STATUS_SUSPENDED)
   3805 		}
   3806 		return IDecError(tls, idec, status)
   3807 	}
   3808 	// Allocate/Verify output buffer now
   3809 	(*VP8Decoder)(unsafe.Pointer(dec)).Fstatus = WebPAllocateDecBuffer(tls, (*VP8Io)(unsafe.Pointer(io)).Fwidth, (*VP8Io)(unsafe.Pointer(io)).Fheight, (*WebPDecParams)(unsafe.Pointer(params)).Foptions, output)
   3810 	if (*VP8Decoder)(unsafe.Pointer(dec)).Fstatus != int32(VP8_STATUS_OK) {
   3811 		return IDecError(tls, idec, (*VP8Decoder)(unsafe.Pointer(dec)).Fstatus)
   3812 	}
   3813 	// This change must be done before calling VP8InitFrame()
   3814 	(*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)
   3815 	VP8InitDithering(tls, (*WebPDecParams)(unsafe.Pointer(params)).Foptions, dec)
   3816 	(*VP8Decoder)(unsafe.Pointer(dec)).Fstatus = CopyParts0Data(tls, idec)
   3817 	if (*VP8Decoder)(unsafe.Pointer(dec)).Fstatus != int32(VP8_STATUS_OK) {
   3818 		return IDecError(tls, idec, (*VP8Decoder)(unsafe.Pointer(dec)).Fstatus)
   3819 	}
   3820 	// Finish setting up the decoding parameters. Will call io->setup().
   3821 	if VP8EnterCritical(tls, dec, io) != int32(VP8_STATUS_OK) {
   3822 		return IDecError(tls, idec, (*VP8Decoder)(unsafe.Pointer(dec)).Fstatus)
   3823 	}
   3824 	// Note: past this point, teardown() must always be called
   3825 	// in case of error.
   3826 	(*WebPIDecoder)(unsafe.Pointer(idec)).Fstate = int32(STATE_VP8_DATA)
   3827 	// Allocate memory and prepare everything.
   3828 	if !(VP8InitFrame(tls, dec, io) != 0) {
   3829 		return IDecError(tls, idec, (*VP8Decoder)(unsafe.Pointer(dec)).Fstatus)
   3830 	}
   3831 	return int32(VP8_STATUS_OK)
   3832 }
   3833 
   3834 // C documentation
   3835 //
   3836 //	// Remaining partitions
   3837 func DecodeRemaining(tls *libc.TLS, idec uintptr) (r VP8StatusCode1) {
   3838 	bp := tls.Alloc(64)
   3839 	defer tls.Free(64)
   3840 	var dec, io, token_br uintptr
   3841 	var _ /* context at bp+0 */ MBContext
   3842 	_, _, _ = dec, io, token_br
   3843 	dec = (*WebPIDecoder)(unsafe.Pointer(idec)).Fdec
   3844 	io = idec + 136
   3845 	// Make sure partition #0 has been read before, to set dec to ready.
   3846 	if !((*VP8Decoder)(unsafe.Pointer(dec)).Fready != 0) {
   3847 		return IDecError(tls, idec, int32(VP8_STATUS_BITSTREAM_ERROR))
   3848 	}
   3849 	for {
   3850 		if !((*VP8Decoder)(unsafe.Pointer(dec)).Fmb_y < (*VP8Decoder)(unsafe.Pointer(dec)).Fmb_h) {
   3851 			break
   3852 		}
   3853 		if (*WebPIDecoder)(unsafe.Pointer(idec)).Flast_mb_y != (*VP8Decoder)(unsafe.Pointer(dec)).Fmb_y {
   3854 			if !(VP8ParseIntraModeRow(tls, dec+16, dec) != 0) {
   3855 				// note: normally, error shouldn't occur since we already have the whole
   3856 				// partition0 available here in DecodeRemaining(). Reaching EOF while
   3857 				// reading intra modes really means a BITSTREAM_ERROR.
   3858 				return IDecError(tls, idec, int32(VP8_STATUS_BITSTREAM_ERROR))
   3859 			}
   3860 			(*WebPIDecoder)(unsafe.Pointer(idec)).Flast_mb_y = (*VP8Decoder)(unsafe.Pointer(dec)).Fmb_y
   3861 		}
   3862 		for {
   3863 			if !((*VP8Decoder)(unsafe.Pointer(dec)).Fmb_x < (*VP8Decoder)(unsafe.Pointer(dec)).Fmb_w) {
   3864 				break
   3865 			}
   3866 			token_br = dec + 440 + uintptr(uint32((*VP8Decoder)(unsafe.Pointer(dec)).Fmb_y)&(*VP8Decoder)(unsafe.Pointer(dec)).Fnum_parts_minus_one)*48
   3867 			SaveContext(tls, dec, token_br, bp)
   3868 			if !(VP8DecodeMB(tls, dec, token_br) != 0) {
   3869 				// We shouldn't fail when MAX_MB data was available
   3870 				if (*VP8Decoder)(unsafe.Pointer(dec)).Fnum_parts_minus_one == uint32(0) && MemDataSize(tls, idec+296) > uint64(MAX_MB_SIZE) {
   3871 					return IDecError(tls, idec, int32(VP8_STATUS_BITSTREAM_ERROR))
   3872 				}
   3873 				// Synchronize the threads.
   3874 				if (*VP8Decoder)(unsafe.Pointer(dec)).Fmt_method > 0 {
   3875 					if !((*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*WebPWorkerInterface)(unsafe.Pointer(WebPGetWorkerInterface(tls))).FSync})))(tls, dec+152) != 0) {
   3876 						return IDecError(tls, idec, int32(VP8_STATUS_BITSTREAM_ERROR))
   3877 					}
   3878 				}
   3879 				RestoreContext(tls, bp, dec, token_br)
   3880 				return int32(VP8_STATUS_SUSPENDED)
   3881 			}
   3882 			// Release buffer only if there is only one partition
   3883 			if (*VP8Decoder)(unsafe.Pointer(dec)).Fnum_parts_minus_one == uint32(0) {
   3884 				(*WebPIDecoder)(unsafe.Pointer(idec)).Fmem.Fstart = uint64(int64((*VP8BitReader)(unsafe.Pointer(token_br)).Fbuf) - int64((*WebPIDecoder)(unsafe.Pointer(idec)).Fmem.Fbuf))
   3885 			}
   3886 			goto _2
   3887 		_2:
   3888 			;
   3889 			(*VP8Decoder)(unsafe.Pointer(dec)).Fmb_x = (*VP8Decoder)(unsafe.Pointer(dec)).Fmb_x + 1
   3890 		}
   3891 		VP8InitScanline(tls, dec) // Prepare for next scanline
   3892 		// Reconstruct, filter and emit the row.
   3893 		if !(VP8ProcessRow(tls, dec, io) != 0) {
   3894 			return IDecError(tls, idec, int32(VP8_STATUS_USER_ABORT))
   3895 		}
   3896 		goto _1
   3897 	_1:
   3898 		;
   3899 		(*VP8Decoder)(unsafe.Pointer(dec)).Fmb_y = (*VP8Decoder)(unsafe.Pointer(dec)).Fmb_y + 1
   3900 	}
   3901 	// Synchronize the thread and check for errors.
   3902 	if !(VP8ExitCritical(tls, dec, io) != 0) {
   3903 		(*WebPIDecoder)(unsafe.Pointer(idec)).Fstate = int32(STATE_ERROR) // prevent re-entry in IDecError
   3904 		return IDecError(tls, idec, int32(VP8_STATUS_USER_ABORT))
   3905 	}
   3906 	(*VP8Decoder)(unsafe.Pointer(dec)).Fready = 0
   3907 	return FinishDecoding(tls, idec)
   3908 }
   3909 
   3910 func ErrorStatusLossless(tls *libc.TLS, idec uintptr, status VP8StatusCode1) (r VP8StatusCode1) {
   3911 	if status == int32(VP8_STATUS_SUSPENDED) || status == int32(VP8_STATUS_NOT_ENOUGH_DATA) {
   3912 		return int32(VP8_STATUS_SUSPENDED)
   3913 	}
   3914 	return IDecError(tls, idec, status)
   3915 }
   3916 
   3917 func DecodeVP8LHeader(tls *libc.TLS, idec uintptr) (r VP8StatusCode1) {
   3918 	var curr_size size_t
   3919 	var dec, io, output, params uintptr
   3920 	_, _, _, _, _ = curr_size, dec, io, output, params
   3921 	io = idec + 136
   3922 	dec = (*WebPIDecoder)(unsafe.Pointer(idec)).Fdec
   3923 	params = idec + 8
   3924 	output = (*WebPDecParams)(unsafe.Pointer(params)).Foutput
   3925 	curr_size = MemDataSize(tls, idec+296)
   3926 	// Wait until there's enough data for decoding header.
   3927 	if curr_size < (*WebPIDecoder)(unsafe.Pointer(idec)).Fchunk_size>>libc.Int32FromInt32(3) {
   3928 		(*VP8LDecoder)(unsafe.Pointer(dec)).Fstatus = int32(VP8_STATUS_SUSPENDED)
   3929 		return ErrorStatusLossless(tls, idec, (*VP8LDecoder)(unsafe.Pointer(dec)).Fstatus)
   3930 	}
   3931 	if !(VP8LDecodeHeader(tls, dec, io) != 0) {
   3932 		if (*VP8LDecoder)(unsafe.Pointer(dec)).Fstatus == int32(VP8_STATUS_BITSTREAM_ERROR) && curr_size < (*WebPIDecoder)(unsafe.Pointer(idec)).Fchunk_size {
   3933 			(*VP8LDecoder)(unsafe.Pointer(dec)).Fstatus = int32(VP8_STATUS_SUSPENDED)
   3934 		}
   3935 		return ErrorStatusLossless(tls, idec, (*VP8LDecoder)(unsafe.Pointer(dec)).Fstatus)
   3936 	}
   3937 	// Allocate/verify output buffer now.
   3938 	(*VP8LDecoder)(unsafe.Pointer(dec)).Fstatus = WebPAllocateDecBuffer(tls, (*VP8Io)(unsafe.Pointer(io)).Fwidth, (*VP8Io)(unsafe.Pointer(io)).Fheight, (*WebPDecParams)(unsafe.Pointer(params)).Foptions, output)
   3939 	if (*VP8LDecoder)(unsafe.Pointer(dec)).Fstatus != int32(VP8_STATUS_OK) {
   3940 		return IDecError(tls, idec, (*VP8LDecoder)(unsafe.Pointer(dec)).Fstatus)
   3941 	}
   3942 	(*WebPIDecoder)(unsafe.Pointer(idec)).Fstate = int32(STATE_VP8L_DATA)
   3943 	return int32(VP8_STATUS_OK)
   3944 }
   3945 
   3946 func DecodeVP8LData(tls *libc.TLS, idec uintptr) (r VP8StatusCode1) {
   3947 	var curr_size size_t
   3948 	var dec uintptr
   3949 	var v1 int32
   3950 	_, _, _ = curr_size, dec, v1
   3951 	dec = (*WebPIDecoder)(unsafe.Pointer(idec)).Fdec
   3952 	curr_size = MemDataSize(tls, idec+296)
   3953 	// Switch to incremental decoding if we don't have all the bytes available.
   3954 	(*VP8LDecoder)(unsafe.Pointer(dec)).Fincremental = libc.BoolInt32(curr_size < (*WebPIDecoder)(unsafe.Pointer(idec)).Fchunk_size)
   3955 	if !(VP8LDecodeImage(tls, dec) != 0) {
   3956 		return ErrorStatusLossless(tls, idec, (*VP8LDecoder)(unsafe.Pointer(dec)).Fstatus)
   3957 	}
   3958 	if (*VP8LDecoder)(unsafe.Pointer(dec)).Fstatus == int32(VP8_STATUS_SUSPENDED) {
   3959 		v1 = (*VP8LDecoder)(unsafe.Pointer(dec)).Fstatus
   3960 	} else {
   3961 		v1 = FinishDecoding(tls, idec)
   3962 	}
   3963 	return v1
   3964 }
   3965 
   3966 // C documentation
   3967 //
   3968 //	// Main decoding loop
   3969 func IDecode(tls *libc.TLS, idec uintptr) (r VP8StatusCode1) {
   3970 	var dec uintptr
   3971 	var status VP8StatusCode1
   3972 	_, _ = dec, status
   3973 	status = int32(VP8_STATUS_SUSPENDED)
   3974 	if (*WebPIDecoder)(unsafe.Pointer(idec)).Fstate == int32(STATE_WEBP_HEADER) {
   3975 		status = DecodeWebPHeaders(tls, idec)
   3976 	} else {
   3977 		if (*WebPIDecoder)(unsafe.Pointer(idec)).Fdec == libc.UintptrFromInt32(0) {
   3978 			return int32(VP8_STATUS_SUSPENDED) // can't continue if we have no decoder.
   3979 		}
   3980 	}
   3981 	if (*WebPIDecoder)(unsafe.Pointer(idec)).Fstate == int32(STATE_VP8_HEADER) {
   3982 		status = DecodeVP8FrameHeader(tls, idec)
   3983 	}
   3984 	if (*WebPIDecoder)(unsafe.Pointer(idec)).Fstate == int32(STATE_VP8_PARTS0) {
   3985 		status = DecodePartition0(tls, idec)
   3986 	}
   3987 	if (*WebPIDecoder)(unsafe.Pointer(idec)).Fstate == int32(STATE_VP8_DATA) {
   3988 		dec = (*WebPIDecoder)(unsafe.Pointer(idec)).Fdec
   3989 		if dec == libc.UintptrFromInt32(0) {
   3990 			return int32(VP8_STATUS_SUSPENDED) // can't continue if we have no decoder.
   3991 		}
   3992 		status = DecodeRemaining(tls, idec)
   3993 	}
   3994 	if (*WebPIDecoder)(unsafe.Pointer(idec)).Fstate == int32(STATE_VP8L_HEADER) {
   3995 		status = DecodeVP8LHeader(tls, idec)
   3996 	}
   3997 	if (*WebPIDecoder)(unsafe.Pointer(idec)).Fstate == int32(STATE_VP8L_DATA) {
   3998 		status = DecodeVP8LData(tls, idec)
   3999 	}
   4000 	return status
   4001 }
   4002 
   4003 // ------------------------------------------------------------------------------
   4004 // Internal constructor
   4005 func NewDecoder(tls *libc.TLS, output_buffer uintptr, features uintptr) (r uintptr) {
   4006 	var idec uintptr
   4007 	var v1, v3 int32
   4008 	var v5 bool
   4009 	_, _, _, _ = idec, v1, v3, v5
   4010 	idec = WebPSafeCalloc(tls, uint64(1), uint64(496))
   4011 	if idec == libc.UintptrFromInt32(0) {
   4012 		return libc.UintptrFromInt32(0)
   4013 	}
   4014 	(*WebPIDecoder)(unsafe.Pointer(idec)).Fstate = int32(STATE_WEBP_HEADER)
   4015 	(*WebPIDecoder)(unsafe.Pointer(idec)).Fchunk_size = uint64(0)
   4016 	(*WebPIDecoder)(unsafe.Pointer(idec)).Flast_mb_y = -int32(1)
   4017 	InitMemBuffer(tls, idec+296)
   4018 	v1 = WebPInitDecBufferInternal(tls, idec+352, int32(WEBP_DECODER_ABI_VERSION))
   4019 	goto _2
   4020 _2:
   4021 	;
   4022 	if v5 = !(v1 != 0); !v5 {
   4023 		v3 = VP8InitIoInternal(tls, idec+136, int32(WEBP_DECODER_ABI_VERSION))
   4024 		goto _4
   4025 	_4:
   4026 	}
   4027 	if v5 || !(v3 != 0) {
   4028 		WebPSafeFree(tls, idec)
   4029 		return libc.UintptrFromInt32(0)
   4030 	}
   4031 	WebPResetDecParams(tls, idec+8)
   4032 	if output_buffer == libc.UintptrFromInt32(0) || WebPAvoidSlowMemory(tls, output_buffer, features) != 0 {
   4033 		(*WebPIDecoder)(unsafe.Pointer(idec)).Fparams.Foutput = idec + 352
   4034 		(*WebPIDecoder)(unsafe.Pointer(idec)).Ffinal_output = output_buffer
   4035 		if output_buffer != libc.UintptrFromInt32(0) {
   4036 			(*WebPDecBuffer)(unsafe.Pointer((*WebPIDecoder)(unsafe.Pointer(idec)).Fparams.Foutput)).Fcolorspace = (*WebPDecBuffer)(unsafe.Pointer(output_buffer)).Fcolorspace
   4037 		}
   4038 	} else {
   4039 		(*WebPIDecoder)(unsafe.Pointer(idec)).Fparams.Foutput = output_buffer
   4040 		(*WebPIDecoder)(unsafe.Pointer(idec)).Ffinal_output = libc.UintptrFromInt32(0)
   4041 	}
   4042 	WebPInitCustomIo(tls, idec+8, idec+136) // Plug the I/O functions.
   4043 	return idec
   4044 }
   4045 
   4046 //------------------------------------------------------------------------------
   4047 // Public functions
   4048 
   4049 func WebPINewDecoder(tls *libc.TLS, output_buffer uintptr) (r uintptr) {
   4050 	return NewDecoder(tls, output_buffer, libc.UintptrFromInt32(0))
   4051 }
   4052 
   4053 func WebPIDecode(tls *libc.TLS, data1 uintptr, data_size1 size_t, config uintptr) (r uintptr) {
   4054 	bp := tls.Alloc(48)
   4055 	defer tls.Free(48)
   4056 	var features1, idec, v1 uintptr
   4057 	var v2 VP8StatusCode1
   4058 	var _ /* tmp_features at bp+0 */ WebPBitstreamFeatures
   4059 	_, _, _, _ = features1, idec, v1, v2
   4060 	if config == libc.UintptrFromInt32(0) {
   4061 		v1 = bp
   4062 	} else {
   4063 		v1 = config
   4064 	}
   4065 	features1 = v1
   4066 	libc.Xmemset(tls, bp, 0, uint64(40))
   4067 	// Parse the bitstream's features, if requested:
   4068 	if data1 != libc.UintptrFromInt32(0) && data_size1 > uint64(0) {
   4069 		v2 = WebPGetFeaturesInternal(tls, data1, data_size1, features1, int32(WEBP_DECODER_ABI_VERSION))
   4070 		goto _3
   4071 	_3:
   4072 		if v2 != int32(VP8_STATUS_OK) {
   4073 			return libc.UintptrFromInt32(0)
   4074 		}
   4075 	}
   4076 	// Create an instance of the incremental decoder
   4077 	if config != libc.UintptrFromInt32(0) {
   4078 		v1 = NewDecoder(tls, config+40, features1)
   4079 	} else {
   4080 		v1 = NewDecoder(tls, libc.UintptrFromInt32(0), features1)
   4081 	}
   4082 	idec = v1
   4083 	if idec == libc.UintptrFromInt32(0) {
   4084 		return libc.UintptrFromInt32(0)
   4085 	}
   4086 	// Finish initialization
   4087 	if config != libc.UintptrFromInt32(0) {
   4088 		(*WebPIDecoder)(unsafe.Pointer(idec)).Fparams.Foptions = config + 160
   4089 	}
   4090 	return idec
   4091 }
   4092 
   4093 func WebPIDelete(tls *libc.TLS, idec uintptr) {
   4094 	if idec == libc.UintptrFromInt32(0) {
   4095 		return
   4096 	}
   4097 	if (*WebPIDecoder)(unsafe.Pointer(idec)).Fdec != libc.UintptrFromInt32(0) {
   4098 		if !((*WebPIDecoder)(unsafe.Pointer(idec)).Fis_lossless != 0) {
   4099 			if (*WebPIDecoder)(unsafe.Pointer(idec)).Fstate == int32(STATE_VP8_DATA) {
   4100 				// Synchronize the thread, clean-up and check for errors.
   4101 				// TODO(vrabaud) do we care about the return result?
   4102 				VP8ExitCritical(tls, (*WebPIDecoder)(unsafe.Pointer(idec)).Fdec, idec+136)
   4103 			}
   4104 			VP8Delete(tls, (*WebPIDecoder)(unsafe.Pointer(idec)).Fdec)
   4105 		} else {
   4106 			VP8LDelete(tls, (*WebPIDecoder)(unsafe.Pointer(idec)).Fdec)
   4107 		}
   4108 	}
   4109 	ClearMemBuffer(tls, idec+296)
   4110 	WebPFreeDecBuffer(tls, idec+352)
   4111 	WebPSafeFree(tls, idec)
   4112 }
   4113 
   4114 //------------------------------------------------------------------------------
   4115 // Wrapper toward WebPINewDecoder
   4116 
   4117 func WebPINewRGB(tls *libc.TLS, csp WEBP_CSP_MODE1, output_buffer uintptr, output_buffer_size size_t, output_stride int32) (r uintptr) {
   4118 	var idec uintptr
   4119 	var is_external_memory, v1 int32
   4120 	_, _, _ = idec, is_external_memory, v1
   4121 	if output_buffer != libc.UintptrFromInt32(0) {
   4122 		v1 = int32(1)
   4123 	} else {
   4124 		v1 = 0
   4125 	}
   4126 	is_external_memory = v1
   4127 	if csp >= int32(MODE_YUV) {
   4128 		return libc.UintptrFromInt32(0)
   4129 	}
   4130 	if is_external_memory == 0 { // Overwrite parameters to sane values.
   4131 		output_buffer_size = uint64(0)
   4132 		output_stride = 0
   4133 	} else { // A buffer was passed. Validate the other params.
   4134 		if output_stride == 0 || output_buffer_size == uint64(0) {
   4135 			return libc.UintptrFromInt32(0) // invalid parameter.
   4136 		}
   4137 	}
   4138 	idec = WebPINewDecoder(tls, libc.UintptrFromInt32(0))
   4139 	if idec == libc.UintptrFromInt32(0) {
   4140 		return libc.UintptrFromInt32(0)
   4141 	}
   4142 	(*WebPIDecoder)(unsafe.Pointer(idec)).Foutput.Fcolorspace = csp
   4143 	(*WebPIDecoder)(unsafe.Pointer(idec)).Foutput.Fis_external_memory = is_external_memory
   4144 	*(*uintptr)(unsafe.Pointer(idec + 352 + 16)) = output_buffer
   4145 	*(*int32)(unsafe.Pointer(idec + 352 + 16 + 8)) = output_stride
   4146 	*(*size_t)(unsafe.Pointer(idec + 352 + 16 + 16)) = output_buffer_size
   4147 	return idec
   4148 }
   4149 
   4150 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) {
   4151 	var colorspace WEBP_CSP_MODE1
   4152 	var idec, v8, v9 uintptr
   4153 	var is_external_memory, v1, v5, v6 int32
   4154 	var v2, v3, v4 size_t
   4155 	_, _, _, _, _, _, _, _, _, _, _ = colorspace, idec, is_external_memory, v1, v2, v3, v4, v5, v6, v8, v9
   4156 	if luma != libc.UintptrFromInt32(0) {
   4157 		v1 = int32(1)
   4158 	} else {
   4159 		v1 = 0
   4160 	}
   4161 	is_external_memory = v1
   4162 	if is_external_memory == 0 { // Overwrite parameters to sane values.
   4163 		v4 = libc.Uint64FromInt32(0)
   4164 		a_size = v4
   4165 		v3 = v4
   4166 		v_size = v3
   4167 		v2 = v3
   4168 		u_size = v2
   4169 		luma_size = v2
   4170 		v6 = libc.Int32FromInt32(0)
   4171 		a_stride = v6
   4172 		v5 = v6
   4173 		v_stride = v5
   4174 		v1 = v5
   4175 		u_stride = v1
   4176 		luma_stride = v1
   4177 		v9 = libc.UintptrFromInt32(0)
   4178 		a = v9
   4179 		v8 = v9
   4180 		v = v8
   4181 		u = v8
   4182 		colorspace = int32(MODE_YUVA)
   4183 	} else { // A luma buffer was passed. Validate the other parameters.
   4184 		if u == libc.UintptrFromInt32(0) || v == libc.UintptrFromInt32(0) {
   4185 			return libc.UintptrFromInt32(0)
   4186 		}
   4187 		if luma_size == uint64(0) || u_size == uint64(0) || v_size == uint64(0) {
   4188 			return libc.UintptrFromInt32(0)
   4189 		}
   4190 		if luma_stride == 0 || u_stride == 0 || v_stride == 0 {
   4191 			return libc.UintptrFromInt32(0)
   4192 		}
   4193 		if a != libc.UintptrFromInt32(0) {
   4194 			if a_size == uint64(0) || a_stride == 0 {
   4195 				return libc.UintptrFromInt32(0)
   4196 			}
   4197 		}
   4198 		if a == libc.UintptrFromInt32(0) {
   4199 			v1 = int32(MODE_YUV)
   4200 		} else {
   4201 			v1 = int32(MODE_YUVA)
   4202 		}
   4203 		colorspace = v1
   4204 	}
   4205 	idec = WebPINewDecoder(tls, libc.UintptrFromInt32(0))
   4206 	if idec == libc.UintptrFromInt32(0) {
   4207 		return libc.UintptrFromInt32(0)
   4208 	}
   4209 	(*WebPIDecoder)(unsafe.Pointer(idec)).Foutput.Fcolorspace = colorspace
   4210 	(*WebPIDecoder)(unsafe.Pointer(idec)).Foutput.Fis_external_memory = is_external_memory
   4211 	*(*uintptr)(unsafe.Pointer(idec + 352 + 16)) = luma
   4212 	*(*int32)(unsafe.Pointer(idec + 352 + 16 + 32)) = luma_stride
   4213 	*(*size_t)(unsafe.Pointer(idec + 352 + 16 + 48)) = luma_size
   4214 	*(*uintptr)(unsafe.Pointer(idec + 352 + 16 + 8)) = u
   4215 	*(*int32)(unsafe.Pointer(idec + 352 + 16 + 36)) = u_stride
   4216 	*(*size_t)(unsafe.Pointer(idec + 352 + 16 + 56)) = u_size
   4217 	*(*uintptr)(unsafe.Pointer(idec + 352 + 16 + 16)) = v
   4218 	*(*int32)(unsafe.Pointer(idec + 352 + 16 + 40)) = v_stride
   4219 	*(*size_t)(unsafe.Pointer(idec + 352 + 16 + 64)) = v_size
   4220 	*(*uintptr)(unsafe.Pointer(idec + 352 + 16 + 24)) = a
   4221 	*(*int32)(unsafe.Pointer(idec + 352 + 16 + 44)) = a_stride
   4222 	*(*size_t)(unsafe.Pointer(idec + 352 + 16 + 72)) = a_size
   4223 	return idec
   4224 }
   4225 
   4226 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) {
   4227 	return WebPINewYUVA(tls, luma, luma_size, luma_stride, u, u_size, u_stride, v, v_size, v_stride, libc.UintptrFromInt32(0), uint64(0), 0)
   4228 }
   4229 
   4230 //------------------------------------------------------------------------------
   4231 
   4232 func IDecCheckStatus(tls *libc.TLS, idec uintptr) (r VP8StatusCode1) {
   4233 	if (*WebPIDecoder)(unsafe.Pointer(idec)).Fstate == int32(STATE_ERROR) {
   4234 		return int32(VP8_STATUS_BITSTREAM_ERROR)
   4235 	}
   4236 	if (*WebPIDecoder)(unsafe.Pointer(idec)).Fstate == int32(STATE_DONE) {
   4237 		return int32(VP8_STATUS_OK)
   4238 	}
   4239 	return int32(VP8_STATUS_SUSPENDED)
   4240 }
   4241 
   4242 func WebPIAppend(tls *libc.TLS, idec uintptr, data uintptr, data_size size_t) (r VP8StatusCode1) {
   4243 	var status VP8StatusCode1
   4244 	_ = status
   4245 	if idec == libc.UintptrFromInt32(0) || data == libc.UintptrFromInt32(0) {
   4246 		return int32(VP8_STATUS_INVALID_PARAM)
   4247 	}
   4248 	status = IDecCheckStatus(tls, idec)
   4249 	if status != int32(VP8_STATUS_SUSPENDED) {
   4250 		return status
   4251 	}
   4252 	// Check mixed calls between RemapMemBuffer and AppendToMemBuffer.
   4253 	if !(CheckMemBufferMode(tls, idec+296, int32(MEM_MODE_APPEND)) != 0) {
   4254 		return int32(VP8_STATUS_INVALID_PARAM)
   4255 	}
   4256 	// Append data to memory buffer
   4257 	if !(AppendToMemBuffer(tls, idec, data, data_size) != 0) {
   4258 		return int32(VP8_STATUS_OUT_OF_MEMORY)
   4259 	}
   4260 	return IDecode(tls, idec)
   4261 }
   4262 
   4263 func WebPIUpdate(tls *libc.TLS, idec uintptr, data uintptr, data_size size_t) (r VP8StatusCode1) {
   4264 	var status VP8StatusCode1
   4265 	_ = status
   4266 	if idec == libc.UintptrFromInt32(0) || data == libc.UintptrFromInt32(0) {
   4267 		return int32(VP8_STATUS_INVALID_PARAM)
   4268 	}
   4269 	status = IDecCheckStatus(tls, idec)
   4270 	if status != int32(VP8_STATUS_SUSPENDED) {
   4271 		return status
   4272 	}
   4273 	// Check mixed calls between RemapMemBuffer and AppendToMemBuffer.
   4274 	if !(CheckMemBufferMode(tls, idec+296, int32(MEM_MODE_MAP)) != 0) {
   4275 		return int32(VP8_STATUS_INVALID_PARAM)
   4276 	}
   4277 	// Make the memory buffer point to the new buffer
   4278 	if !(RemapMemBuffer(tls, idec, data, data_size) != 0) {
   4279 		return int32(VP8_STATUS_INVALID_PARAM)
   4280 	}
   4281 	return IDecode(tls, idec)
   4282 }
   4283 
   4284 //------------------------------------------------------------------------------
   4285 
   4286 func GetOutputBuffer(tls *libc.TLS, idec uintptr) (r uintptr) {
   4287 	if idec == libc.UintptrFromInt32(0) || (*WebPIDecoder)(unsafe.Pointer(idec)).Fdec == libc.UintptrFromInt32(0) {
   4288 		return libc.UintptrFromInt32(0)
   4289 	}
   4290 	if (*WebPIDecoder)(unsafe.Pointer(idec)).Fstate <= int32(STATE_VP8_PARTS0) {
   4291 		return libc.UintptrFromInt32(0)
   4292 	}
   4293 	if (*WebPIDecoder)(unsafe.Pointer(idec)).Ffinal_output != libc.UintptrFromInt32(0) {
   4294 		return libc.UintptrFromInt32(0) // not yet slow-copied
   4295 	}
   4296 	return (*WebPIDecoder)(unsafe.Pointer(idec)).Fparams.Foutput
   4297 }
   4298 
   4299 func WebPIDecodedArea(tls *libc.TLS, idec uintptr, left uintptr, top uintptr, width uintptr, height uintptr) (r uintptr) {
   4300 	var src uintptr
   4301 	_ = src
   4302 	src = GetOutputBuffer(tls, idec)
   4303 	if left != libc.UintptrFromInt32(0) {
   4304 		**(**int32)(__ccgo_up(left)) = 0
   4305 	}
   4306 	if top != libc.UintptrFromInt32(0) {
   4307 		**(**int32)(__ccgo_up(top)) = 0
   4308 	}
   4309 	if src != libc.UintptrFromInt32(0) {
   4310 		if width != libc.UintptrFromInt32(0) {
   4311 			**(**int32)(__ccgo_up(width)) = (*WebPDecBuffer)(unsafe.Pointer(src)).Fwidth
   4312 		}
   4313 		if height != libc.UintptrFromInt32(0) {
   4314 			**(**int32)(__ccgo_up(height)) = (*WebPIDecoder)(unsafe.Pointer(idec)).Fparams.Flast_y
   4315 		}
   4316 	} else {
   4317 		if width != libc.UintptrFromInt32(0) {
   4318 			**(**int32)(__ccgo_up(width)) = 0
   4319 		}
   4320 		if height != libc.UintptrFromInt32(0) {
   4321 			**(**int32)(__ccgo_up(height)) = 0
   4322 		}
   4323 	}
   4324 	return src
   4325 }
   4326 
   4327 func WebPIDecGetRGB(tls *libc.TLS, idec uintptr, last_y uintptr, width uintptr, height uintptr, stride uintptr) (r uintptr) {
   4328 	var src uintptr
   4329 	_ = src
   4330 	src = GetOutputBuffer(tls, idec)
   4331 	if src == libc.UintptrFromInt32(0) {
   4332 		return libc.UintptrFromInt32(0)
   4333 	}
   4334 	if (*WebPDecBuffer)(unsafe.Pointer(src)).Fcolorspace >= int32(MODE_YUV) {
   4335 		return libc.UintptrFromInt32(0)
   4336 	}
   4337 	if last_y != libc.UintptrFromInt32(0) {
   4338 		**(**int32)(__ccgo_up(last_y)) = (*WebPIDecoder)(unsafe.Pointer(idec)).Fparams.Flast_y
   4339 	}
   4340 	if width != libc.UintptrFromInt32(0) {
   4341 		**(**int32)(__ccgo_up(width)) = (*WebPDecBuffer)(unsafe.Pointer(src)).Fwidth
   4342 	}
   4343 	if height != libc.UintptrFromInt32(0) {
   4344 		**(**int32)(__ccgo_up(height)) = (*WebPDecBuffer)(unsafe.Pointer(src)).Fheight
   4345 	}
   4346 	if stride != libc.UintptrFromInt32(0) {
   4347 		**(**int32)(__ccgo_up(stride)) = (*WebPDecBuffer)(unsafe.Pointer(src)).Fu.FRGBA.Fstride
   4348 	}
   4349 	return (*WebPDecBuffer)(unsafe.Pointer(src)).Fu.FRGBA.Frgba
   4350 }
   4351 
   4352 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) {
   4353 	var src uintptr
   4354 	_ = src
   4355 	src = GetOutputBuffer(tls, idec)
   4356 	if src == libc.UintptrFromInt32(0) {
   4357 		return libc.UintptrFromInt32(0)
   4358 	}
   4359 	if (*WebPDecBuffer)(unsafe.Pointer(src)).Fcolorspace < int32(MODE_YUV) {
   4360 		return libc.UintptrFromInt32(0)
   4361 	}
   4362 	if last_y != libc.UintptrFromInt32(0) {
   4363 		**(**int32)(__ccgo_up(last_y)) = (*WebPIDecoder)(unsafe.Pointer(idec)).Fparams.Flast_y
   4364 	}
   4365 	if u != libc.UintptrFromInt32(0) {
   4366 		**(**uintptr)(__ccgo_up(u)) = (*(*WebPYUVABuffer)(unsafe.Pointer(src + 16))).Fu
   4367 	}
   4368 	if v != libc.UintptrFromInt32(0) {
   4369 		**(**uintptr)(__ccgo_up(v)) = (*(*WebPYUVABuffer)(unsafe.Pointer(src + 16))).Fv
   4370 	}
   4371 	if a != libc.UintptrFromInt32(0) {
   4372 		**(**uintptr)(__ccgo_up(a)) = (*(*WebPYUVABuffer)(unsafe.Pointer(src + 16))).Fa
   4373 	}
   4374 	if width != libc.UintptrFromInt32(0) {
   4375 		**(**int32)(__ccgo_up(width)) = (*WebPDecBuffer)(unsafe.Pointer(src)).Fwidth
   4376 	}
   4377 	if height != libc.UintptrFromInt32(0) {
   4378 		**(**int32)(__ccgo_up(height)) = (*WebPDecBuffer)(unsafe.Pointer(src)).Fheight
   4379 	}
   4380 	if stride != libc.UintptrFromInt32(0) {
   4381 		**(**int32)(__ccgo_up(stride)) = (*(*WebPYUVABuffer)(unsafe.Pointer(src + 16))).Fy_stride
   4382 	}
   4383 	if uv_stride != libc.UintptrFromInt32(0) {
   4384 		**(**int32)(__ccgo_up(uv_stride)) = (*(*WebPYUVABuffer)(unsafe.Pointer(src + 16))).Fu_stride
   4385 	}
   4386 	if a_stride != libc.UintptrFromInt32(0) {
   4387 		**(**int32)(__ccgo_up(a_stride)) = (*(*WebPYUVABuffer)(unsafe.Pointer(src + 16))).Fa_stride
   4388 	}
   4389 	return (*(*WebPYUVABuffer)(unsafe.Pointer(src + 16))).Fy
   4390 }
   4391 
   4392 type __ccgo_fp__XWebPISetIOHooks_1 = func(*libc.TLS, uintptr) int32
   4393 
   4394 type __ccgo_fp__XWebPISetIOHooks_2 = func(*libc.TLS, uintptr) int32
   4395 
   4396 type __ccgo_fp__XWebPISetIOHooks_3 = func(*libc.TLS, uintptr)
   4397 
   4398 func WebPISetIOHooks(tls *libc.TLS, idec uintptr, __ccgo_fp_put VP8IoPutHook, __ccgo_fp_setup VP8IoSetupHook, __ccgo_fp_teardown VP8IoTeardownHook, user_data uintptr) (r int32) {
   4399 	if idec == libc.UintptrFromInt32(0) || (*WebPIDecoder)(unsafe.Pointer(idec)).Fstate > int32(STATE_WEBP_HEADER) {
   4400 		return 0
   4401 	}
   4402 	(*WebPIDecoder)(unsafe.Pointer(idec)).Fio.Fput = __ccgo_fp_put
   4403 	(*WebPIDecoder)(unsafe.Pointer(idec)).Fio.Fsetup = __ccgo_fp_setup
   4404 	(*WebPIDecoder)(unsafe.Pointer(idec)).Fio.Fteardown = __ccgo_fp_teardown
   4405 	(*WebPIDecoder)(unsafe.Pointer(idec)).Fio.Fopaque = user_data
   4406 	return int32(1)
   4407 }
   4408 
   4409 var kHashMul4 = uint32(0x1e35a7bd)
   4410 
   4411 const YUV_FIX = 16
   4412 const YUV_HALF = 32768
   4413 const YUV_FIX2 = 6
   4414 const YUV_MASK2 = 16383
   4415 
   4416 //------------------------------------------------------------------------------
   4417 
   4418 // Copyright 2010 Google Inc. All Rights Reserved.
   4419 //
   4420 // Use of this source code is governed by a BSD-style license
   4421 // that can be found in the COPYING file in the root of the source
   4422 // tree. An additional intellectual property rights grant can be found
   4423 // in the file PATENTS. All contributing project authors may
   4424 // be found in the AUTHORS file in the root of the source tree.
   4425 // -----------------------------------------------------------------------------
   4426 //
   4427 //  Main decoding functions for WebP images.
   4428 //
   4429 // Author: Skal (pascal.massimino@gmail.com)
   4430 
   4431 //------------------------------------------------------------------------------
   4432 // Main YUV<->RGB conversion functions
   4433 
   4434 func EmitYUV(tls *libc.TLS, io uintptr, p uintptr) (r int32) {
   4435 	var buf, output, u_dst, v_dst, y_dst uintptr
   4436 	var mb_h, mb_w, uv_h, uv_w int32
   4437 	_, _, _, _, _, _, _, _, _ = buf, mb_h, mb_w, output, u_dst, uv_h, uv_w, v_dst, y_dst
   4438 	output = (*WebPDecParams)(unsafe.Pointer(p)).Foutput
   4439 	buf = output + 16
   4440 	y_dst = (*WebPYUVABuffer)(unsafe.Pointer(buf)).Fy + uintptr(int64((*VP8Io)(unsafe.Pointer(io)).Fmb_y)*int64((*WebPYUVABuffer)(unsafe.Pointer(buf)).Fy_stride))
   4441 	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))
   4442 	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))
   4443 	mb_w = (*VP8Io)(unsafe.Pointer(io)).Fmb_w
   4444 	mb_h = (*VP8Io)(unsafe.Pointer(io)).Fmb_h
   4445 	uv_w = (mb_w + int32(1)) / int32(2)
   4446 	uv_h = (mb_h + int32(1)) / int32(2)
   4447 	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)
   4448 	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)
   4449 	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)
   4450 	return (*VP8Io)(unsafe.Pointer(io)).Fmb_h
   4451 }
   4452 
   4453 // C documentation
   4454 //
   4455 //	// Point-sampling U/V sampler.
   4456 func EmitSampledRGB(tls *libc.TLS, io uintptr, p uintptr) (r int32) {
   4457 	var buf, dst, output uintptr
   4458 	_, _, _ = buf, dst, output
   4459 	output = (*WebPDecParams)(unsafe.Pointer(p)).Foutput
   4460 	buf = output + 16
   4461 	dst = (*WebPRGBABuffer)(unsafe.Pointer(buf)).Frgba + uintptr(int64((*VP8Io)(unsafe.Pointer(io)).Fmb_y)*int64((*WebPRGBABuffer)(unsafe.Pointer(buf)).Fstride))
   4462 	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])
   4463 	return (*VP8Io)(unsafe.Pointer(io)).Fmb_h
   4464 }
   4465 
   4466 //------------------------------------------------------------------------------
   4467 // Fancy upsampling
   4468 
   4469 func EmitFancyRGB(tls *libc.TLS, io uintptr, p uintptr) (r int32) {
   4470 	var buf, cur_u, cur_v, cur_y, dst, top_u, top_v uintptr
   4471 	var mb_w, num_lines_out, uv_w, y, y_end int32
   4472 	var upsample WebPUpsampleLinePairFunc
   4473 	_, _, _, _, _, _, _, _, _, _, _, _, _ = buf, cur_u, cur_v, cur_y, dst, mb_w, num_lines_out, top_u, top_v, upsample, uv_w, y, y_end
   4474 	num_lines_out = (*VP8Io)(unsafe.Pointer(io)).Fmb_h // a priori guess
   4475 	buf = (*WebPDecParams)(unsafe.Pointer(p)).Foutput + 16
   4476 	dst = (*WebPRGBABuffer)(unsafe.Pointer(buf)).Frgba + uintptr(int64((*VP8Io)(unsafe.Pointer(io)).Fmb_y)*int64((*WebPRGBABuffer)(unsafe.Pointer(buf)).Fstride))
   4477 	upsample = WebPUpsamplers[(*WebPDecBuffer)(unsafe.Pointer((*WebPDecParams)(unsafe.Pointer(p)).Foutput)).Fcolorspace]
   4478 	cur_y = (*VP8Io)(unsafe.Pointer(io)).Fy
   4479 	cur_u = (*VP8Io)(unsafe.Pointer(io)).Fu
   4480 	cur_v = (*VP8Io)(unsafe.Pointer(io)).Fv
   4481 	top_u = (*WebPDecParams)(unsafe.Pointer(p)).Ftmp_u
   4482 	top_v = (*WebPDecParams)(unsafe.Pointer(p)).Ftmp_v
   4483 	y = (*VP8Io)(unsafe.Pointer(io)).Fmb_y
   4484 	y_end = (*VP8Io)(unsafe.Pointer(io)).Fmb_y + (*VP8Io)(unsafe.Pointer(io)).Fmb_h
   4485 	mb_w = (*VP8Io)(unsafe.Pointer(io)).Fmb_w
   4486 	uv_w = (mb_w + int32(1)) / int32(2)
   4487 	if y == 0 {
   4488 		// First line is special cased. We mirror the u/v samples at boundary.
   4489 		(*(*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)
   4490 	} else {
   4491 		// We can finish the left-over line from previous call.
   4492 		(*(*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)
   4493 		num_lines_out = num_lines_out + 1
   4494 	}
   4495 	// Loop over each output pairs of row.
   4496 	for {
   4497 		if !(y+int32(2) < y_end) {
   4498 			break
   4499 		}
   4500 		top_u = cur_u
   4501 		top_v = cur_v
   4502 		cur_u = cur_u + uintptr((*VP8Io)(unsafe.Pointer(io)).Fuv_stride)
   4503 		cur_v = cur_v + uintptr((*VP8Io)(unsafe.Pointer(io)).Fuv_stride)
   4504 		dst = dst + uintptr(int32(2)*(*WebPRGBABuffer)(unsafe.Pointer(buf)).Fstride)
   4505 		cur_y = cur_y + uintptr(int32(2)*(*VP8Io)(unsafe.Pointer(io)).Fy_stride)
   4506 		(*(*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)
   4507 		goto _1
   4508 	_1:
   4509 		;
   4510 		y = y + int32(2)
   4511 	}
   4512 	// move to last row
   4513 	cur_y = cur_y + uintptr((*VP8Io)(unsafe.Pointer(io)).Fy_stride)
   4514 	if (*VP8Io)(unsafe.Pointer(io)).Fcrop_top+y_end < (*VP8Io)(unsafe.Pointer(io)).Fcrop_bottom {
   4515 		// Save the unfinished samples for next call (as we're not done yet).
   4516 		libc.Xmemcpy(tls, (*WebPDecParams)(unsafe.Pointer(p)).Ftmp_y, cur_y, uint64(mb_w)*uint64(1))
   4517 		libc.Xmemcpy(tls, (*WebPDecParams)(unsafe.Pointer(p)).Ftmp_u, cur_u, uint64(uv_w)*uint64(1))
   4518 		libc.Xmemcpy(tls, (*WebPDecParams)(unsafe.Pointer(p)).Ftmp_v, cur_v, uint64(uv_w)*uint64(1))
   4519 		// The fancy upsampler leaves a row unfinished behind
   4520 		// (except for the very last row)
   4521 		num_lines_out = num_lines_out - 1
   4522 	} else {
   4523 		// Process the very last row of even-sized picture
   4524 		if !(y_end&libc.Int32FromInt32(1) != 0) {
   4525 			(*(*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)
   4526 		}
   4527 	}
   4528 	return num_lines_out
   4529 }
   4530 
   4531 //------------------------------------------------------------------------------
   4532 
   4533 func FillAlphaPlane(tls *libc.TLS, dst uintptr, w int32, h int32, stride int32) {
   4534 	var j int32
   4535 	_ = j
   4536 	j = 0
   4537 	for {
   4538 		if !(j < h) {
   4539 			break
   4540 		}
   4541 		libc.Xmemset(tls, dst, int32(0xff), uint64(w)*uint64(1))
   4542 		dst = dst + uintptr(stride)
   4543 		goto _1
   4544 	_1:
   4545 		;
   4546 		j = j + 1
   4547 	}
   4548 }
   4549 
   4550 func EmitAlphaYUV(tls *libc.TLS, io uintptr, p uintptr, expected_num_lines_out int32) (r int32) {
   4551 	var alpha, buf, dst uintptr
   4552 	var j, mb_h, mb_w int32
   4553 	_, _, _, _, _, _ = alpha, buf, dst, j, mb_h, mb_w
   4554 	alpha = (*VP8Io)(unsafe.Pointer(io)).Fa
   4555 	buf = (*WebPDecParams)(unsafe.Pointer(p)).Foutput + 16
   4556 	mb_w = (*VP8Io)(unsafe.Pointer(io)).Fmb_w
   4557 	mb_h = (*VP8Io)(unsafe.Pointer(io)).Fmb_h
   4558 	dst = (*WebPYUVABuffer)(unsafe.Pointer(buf)).Fa + uintptr(int64((*VP8Io)(unsafe.Pointer(io)).Fmb_y)*int64((*WebPYUVABuffer)(unsafe.Pointer(buf)).Fa_stride))
   4559 	_ = expected_num_lines_out
   4560 	if alpha != libc.UintptrFromInt32(0) {
   4561 		j = 0
   4562 		for {
   4563 			if !(j < mb_h) {
   4564 				break
   4565 			}
   4566 			libc.Xmemcpy(tls, dst, alpha, uint64(mb_w)*uint64(1))
   4567 			alpha = alpha + uintptr((*VP8Io)(unsafe.Pointer(io)).Fwidth)
   4568 			dst = dst + uintptr((*WebPYUVABuffer)(unsafe.Pointer(buf)).Fa_stride)
   4569 			goto _1
   4570 		_1:
   4571 			;
   4572 			j = j + 1
   4573 		}
   4574 	} else {
   4575 		if (*WebPYUVABuffer)(unsafe.Pointer(buf)).Fa != libc.UintptrFromInt32(0) {
   4576 			// the user requested alpha, but there is none, set it to opaque.
   4577 			FillAlphaPlane(tls, dst, mb_w, mb_h, (*WebPYUVABuffer)(unsafe.Pointer(buf)).Fa_stride)
   4578 		}
   4579 	}
   4580 	return 0
   4581 }
   4582 
   4583 func GetAlphaSourceRow(tls *libc.TLS, io uintptr, alpha uintptr, num_rows uintptr) (r int32) {
   4584 	var start_y int32
   4585 	_ = start_y
   4586 	start_y = (*VP8Io)(unsafe.Pointer(io)).Fmb_y
   4587 	**(**int32)(__ccgo_up(num_rows)) = (*VP8Io)(unsafe.Pointer(io)).Fmb_h
   4588 	// Compensate for the 1-line delay of the fancy upscaler.
   4589 	// This is similar to EmitFancyRGB().
   4590 	if (*VP8Io)(unsafe.Pointer(io)).Ffancy_upsampling != 0 {
   4591 		if start_y == 0 {
   4592 			// We don't process the last row yet. It'll be done during the next call.
   4593 			**(**int32)(__ccgo_up(num_rows)) = **(**int32)(__ccgo_up(num_rows)) - 1
   4594 		} else {
   4595 			start_y = start_y - 1
   4596 			// Fortunately, *alpha data is persistent, so we can go back
   4597 			// one row and finish alpha blending, now that the fancy upscaler
   4598 			// completed the YUV->RGB interpolation.
   4599 			**(**uintptr)(__ccgo_up(alpha)) -= uintptr((*VP8Io)(unsafe.Pointer(io)).Fwidth)
   4600 		}
   4601 		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 {
   4602 			// If it's the very last call, we process all the remaining rows!
   4603 			**(**int32)(__ccgo_up(num_rows)) = (*VP8Io)(unsafe.Pointer(io)).Fcrop_bottom - (*VP8Io)(unsafe.Pointer(io)).Fcrop_top - start_y
   4604 		}
   4605 	}
   4606 	return start_y
   4607 }
   4608 
   4609 func EmitAlphaRGB(tls *libc.TLS, io uintptr, p uintptr, expected_num_lines_out int32) (r int32) {
   4610 	bp := tls.Alloc(16)
   4611 	defer tls.Free(16)
   4612 	var alpha_first, has_alpha, mb_w, start_y, v1 int32
   4613 	var base_rgba, buf, dst uintptr
   4614 	var colorspace, v2 WEBP_CSP_MODE1
   4615 	var v5 bool
   4616 	var _ /* alpha at bp+0 */ uintptr
   4617 	var _ /* num_rows at bp+8 */ int32
   4618 	_, _, _, _, _, _, _, _, _, _, _ = alpha_first, base_rgba, buf, colorspace, dst, has_alpha, mb_w, start_y, v1, v2, v5
   4619 	**(**uintptr)(__ccgo_up(bp)) = (*VP8Io)(unsafe.Pointer(io)).Fa
   4620 	if **(**uintptr)(__ccgo_up(bp)) != libc.UintptrFromInt32(0) {
   4621 		mb_w = (*VP8Io)(unsafe.Pointer(io)).Fmb_w
   4622 		colorspace = (*WebPDecBuffer)(unsafe.Pointer((*WebPDecParams)(unsafe.Pointer(p)).Foutput)).Fcolorspace
   4623 		alpha_first = libc.BoolInt32(colorspace == int32(MODE_ARGB) || colorspace == int32(MODE_Argb))
   4624 		buf = (*WebPDecParams)(unsafe.Pointer(p)).Foutput + 16
   4625 		start_y = GetAlphaSourceRow(tls, io, bp, bp+8)
   4626 		base_rgba = (*WebPRGBABuffer)(unsafe.Pointer(buf)).Frgba + uintptr(int64(start_y)*int64((*WebPRGBABuffer)(unsafe.Pointer(buf)).Fstride))
   4627 		if alpha_first != 0 {
   4628 			v1 = 0
   4629 		} else {
   4630 			v1 = int32(3)
   4631 		}
   4632 		dst = base_rgba + uintptr(v1)
   4633 		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)
   4634 		_ = expected_num_lines_out
   4635 		// has_alpha is true if there's non-trivial alpha to premultiply with.
   4636 		if v5 = has_alpha != 0; v5 {
   4637 			v2 = colorspace
   4638 			v1 = libc.BoolInt32(v2 == int32(MODE_rgbA) || v2 == int32(MODE_bgrA) || v2 == int32(MODE_Argb) || v2 == int32(MODE_rgbA_4444))
   4639 			goto _4
   4640 		_4:
   4641 		}
   4642 		if v5 && v1 != 0 {
   4643 			(*(*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)
   4644 		}
   4645 	}
   4646 	return 0
   4647 }
   4648 
   4649 func EmitAlphaRGBA4444(tls *libc.TLS, io uintptr, p uintptr, expected_num_lines_out int32) (r int32) {
   4650 	bp := tls.Alloc(16)
   4651 	defer tls.Free(16)
   4652 	var alpha_dst, base_rgba, buf uintptr
   4653 	var alpha_mask, alpha_value uint32_t
   4654 	var colorspace, v3 WEBP_CSP_MODE1
   4655 	var i, j, mb_w, start_y, v4 int32
   4656 	var v6 bool
   4657 	var _ /* alpha at bp+0 */ uintptr
   4658 	var _ /* num_rows at bp+8 */ int32
   4659 	_, _, _, _, _, _, _, _, _, _, _, _, _ = alpha_dst, alpha_mask, alpha_value, base_rgba, buf, colorspace, i, j, mb_w, start_y, v3, v4, v6
   4660 	**(**uintptr)(__ccgo_up(bp)) = (*VP8Io)(unsafe.Pointer(io)).Fa
   4661 	if **(**uintptr)(__ccgo_up(bp)) != libc.UintptrFromInt32(0) {
   4662 		mb_w = (*VP8Io)(unsafe.Pointer(io)).Fmb_w
   4663 		colorspace = (*WebPDecBuffer)(unsafe.Pointer((*WebPDecParams)(unsafe.Pointer(p)).Foutput)).Fcolorspace
   4664 		buf = (*WebPDecParams)(unsafe.Pointer(p)).Foutput + 16
   4665 		start_y = GetAlphaSourceRow(tls, io, bp, bp+8)
   4666 		base_rgba = (*WebPRGBABuffer)(unsafe.Pointer(buf)).Frgba + uintptr(int64(start_y)*int64((*WebPRGBABuffer)(unsafe.Pointer(buf)).Fstride))
   4667 		alpha_dst = base_rgba + uintptr(1)
   4668 		alpha_mask = uint32(0x0f)
   4669 		j = 0
   4670 		for {
   4671 			if !(j < **(**int32)(__ccgo_up(bp + 8))) {
   4672 				break
   4673 			}
   4674 			i = 0
   4675 			for {
   4676 				if !(i < mb_w) {
   4677 					break
   4678 				}
   4679 				// Fill in the alpha value (converted to 4 bits).
   4680 				alpha_value = uint32(int32(**(**uint8_t)(__ccgo_up(**(**uintptr)(__ccgo_up(bp)) + uintptr(i)))) >> int32(4))
   4681 				**(**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)
   4682 				alpha_mask = alpha_mask & alpha_value
   4683 				goto _2
   4684 			_2:
   4685 				;
   4686 				i = i + 1
   4687 			}
   4688 			**(**uintptr)(__ccgo_up(bp)) = **(**uintptr)(__ccgo_up(bp)) + uintptr((*VP8Io)(unsafe.Pointer(io)).Fwidth)
   4689 			alpha_dst = alpha_dst + uintptr((*WebPRGBABuffer)(unsafe.Pointer(buf)).Fstride)
   4690 			goto _1
   4691 		_1:
   4692 			;
   4693 			j = j + 1
   4694 		}
   4695 		_ = expected_num_lines_out
   4696 		if v6 = alpha_mask != uint32(0x0f); v6 {
   4697 			v3 = colorspace
   4698 			v4 = libc.BoolInt32(v3 == int32(MODE_rgbA) || v3 == int32(MODE_bgrA) || v3 == int32(MODE_Argb) || v3 == int32(MODE_rgbA_4444))
   4699 			goto _5
   4700 		_5:
   4701 		}
   4702 		if v6 && v4 != 0 {
   4703 			(*(*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)
   4704 		}
   4705 	}
   4706 	return 0
   4707 }
   4708 
   4709 //------------------------------------------------------------------------------
   4710 // YUV rescaling (no final RGB conversion needed)
   4711 
   4712 func Rescale(tls *libc.TLS, src uintptr, src_stride int32, new_lines int32, wrk uintptr) (r int32) {
   4713 	var lines_in, num_lines_out int32
   4714 	_, _ = lines_in, num_lines_out
   4715 	num_lines_out = 0
   4716 	for new_lines > 0 { // import new contributions of source rows.
   4717 		lines_in = WebPRescalerImport(tls, wrk, new_lines, src, src_stride)
   4718 		src = src + uintptr(lines_in*src_stride)
   4719 		new_lines = new_lines - lines_in
   4720 		num_lines_out = num_lines_out + WebPRescalerExport(tls, wrk) // emit output row(s)
   4721 	}
   4722 	return num_lines_out
   4723 }
   4724 
   4725 func EmitRescaledYUV(tls *libc.TLS, io uintptr, p uintptr) (r int32) {
   4726 	var mb_h, num_lines_out, uv_mb_h, v2, v5 int32
   4727 	var scaler uintptr
   4728 	var v1, v4 WEBP_CSP_MODE1
   4729 	var v7 bool
   4730 	_, _, _, _, _, _, _, _, _ = mb_h, num_lines_out, scaler, uv_mb_h, v1, v2, v4, v5, v7
   4731 	mb_h = (*VP8Io)(unsafe.Pointer(io)).Fmb_h
   4732 	uv_mb_h = (mb_h + int32(1)) >> int32(1)
   4733 	scaler = (*WebPDecParams)(unsafe.Pointer(p)).Fscaler_y
   4734 	num_lines_out = 0
   4735 	v1 = (*WebPDecBuffer)(unsafe.Pointer((*WebPDecParams)(unsafe.Pointer(p)).Foutput)).Fcolorspace
   4736 	if v7 = v1 == int32(MODE_RGBA) || v1 == int32(MODE_BGRA) || v1 == int32(MODE_ARGB) || v1 == int32(MODE_RGBA_4444) || v1 == int32(MODE_YUVA); !v7 {
   4737 		v4 = v1
   4738 		v5 = libc.BoolInt32(v4 == int32(MODE_rgbA) || v4 == int32(MODE_bgrA) || v4 == int32(MODE_Argb) || v4 == int32(MODE_rgbA_4444))
   4739 		goto _6
   4740 	_6:
   4741 	}
   4742 	v2 = libc.BoolInt32(v7 || v5 != 0)
   4743 	goto _3
   4744 _3:
   4745 	;
   4746 	if v2 != 0 && (*VP8Io)(unsafe.Pointer(io)).Fa != libc.UintptrFromInt32(0) {
   4747 		// Before rescaling, we premultiply the luma directly into the io->y
   4748 		// internal buffer. This is OK since these samples are not used for
   4749 		// intra-prediction (the top samples are saved in cache_y/u/v).
   4750 		// But we need to cast the const away, though.
   4751 		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)
   4752 	}
   4753 	num_lines_out = Rescale(tls, (*VP8Io)(unsafe.Pointer(io)).Fy, (*VP8Io)(unsafe.Pointer(io)).Fy_stride, mb_h, scaler)
   4754 	Rescale(tls, (*VP8Io)(unsafe.Pointer(io)).Fu, (*VP8Io)(unsafe.Pointer(io)).Fuv_stride, uv_mb_h, (*WebPDecParams)(unsafe.Pointer(p)).Fscaler_u)
   4755 	Rescale(tls, (*VP8Io)(unsafe.Pointer(io)).Fv, (*VP8Io)(unsafe.Pointer(io)).Fuv_stride, uv_mb_h, (*WebPDecParams)(unsafe.Pointer(p)).Fscaler_v)
   4756 	return num_lines_out
   4757 }
   4758 
   4759 func EmitRescaledAlphaYUV(tls *libc.TLS, io uintptr, p uintptr, expected_num_lines_out int32) (r int32) {
   4760 	var buf, dst_a, dst_y uintptr
   4761 	var num_lines_out int32
   4762 	_, _, _, _ = buf, dst_a, dst_y, num_lines_out
   4763 	buf = (*WebPDecParams)(unsafe.Pointer(p)).Foutput + 16
   4764 	dst_a = (*WebPYUVABuffer)(unsafe.Pointer(buf)).Fa + uintptr(int64((*WebPDecParams)(unsafe.Pointer(p)).Flast_y)*int64((*WebPYUVABuffer)(unsafe.Pointer(buf)).Fa_stride))
   4765 	if (*VP8Io)(unsafe.Pointer(io)).Fa != libc.UintptrFromInt32(0) {
   4766 		dst_y = (*WebPYUVABuffer)(unsafe.Pointer(buf)).Fy + uintptr(int64((*WebPDecParams)(unsafe.Pointer(p)).Flast_y)*int64((*WebPYUVABuffer)(unsafe.Pointer(buf)).Fy_stride))
   4767 		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)
   4768 		if num_lines_out > 0 { // unmultiply the Y
   4769 			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))
   4770 		}
   4771 	} else {
   4772 		if (*WebPYUVABuffer)(unsafe.Pointer(buf)).Fa != libc.UintptrFromInt32(0) {
   4773 			// the user requested alpha, but there is none, set it to opaque.
   4774 			FillAlphaPlane(tls, dst_a, (*VP8Io)(unsafe.Pointer(io)).Fscaled_width, expected_num_lines_out, (*WebPYUVABuffer)(unsafe.Pointer(buf)).Fa_stride)
   4775 		}
   4776 	}
   4777 	return 0
   4778 }
   4779 
   4780 func InitYUVRescaler(tls *libc.TLS, io uintptr, p uintptr) (r int32) {
   4781 	var buf, scalers, work, v12 uintptr
   4782 	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
   4783 	var rescaler_size, uv_work_size, work_size size_t
   4784 	var total_size, v9 uint64_t
   4785 	var v1, v4 WEBP_CSP_MODE1
   4786 	var v7 bool
   4787 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
   4788 	v1 = (*WebPDecBuffer)(unsafe.Pointer((*WebPDecParams)(unsafe.Pointer(p)).Foutput)).Fcolorspace
   4789 	if v7 = v1 == int32(MODE_RGBA) || v1 == int32(MODE_BGRA) || v1 == int32(MODE_ARGB) || v1 == int32(MODE_RGBA_4444) || v1 == int32(MODE_YUVA); !v7 {
   4790 		v4 = v1
   4791 		v5 = libc.BoolInt32(v4 == int32(MODE_rgbA) || v4 == int32(MODE_bgrA) || v4 == int32(MODE_Argb) || v4 == int32(MODE_rgbA_4444))
   4792 		goto _6
   4793 	_6:
   4794 	}
   4795 	v2 = libc.BoolInt32(v7 || v5 != 0)
   4796 	goto _3
   4797 _3:
   4798 	has_alpha = v2
   4799 	buf = (*WebPDecParams)(unsafe.Pointer(p)).Foutput + 16
   4800 	out_width = (*VP8Io)(unsafe.Pointer(io)).Fscaled_width
   4801 	out_height = (*VP8Io)(unsafe.Pointer(io)).Fscaled_height
   4802 	uv_out_width = (out_width + int32(1)) >> int32(1)
   4803 	uv_out_height = (out_height + int32(1)) >> int32(1)
   4804 	uv_in_width = ((*VP8Io)(unsafe.Pointer(io)).Fmb_w + int32(1)) >> int32(1)
   4805 	uv_in_height = ((*VP8Io)(unsafe.Pointer(io)).Fmb_h + int32(1)) >> int32(1)
   4806 	// scratch memory for luma rescaler
   4807 	work_size = uint64(2) * uint64(out_width)
   4808 	uv_work_size = uint64(int32(2) * uv_out_width)
   4809 	if has_alpha != 0 {
   4810 		v8 = int32(4)
   4811 	} else {
   4812 		v8 = int32(3)
   4813 	}
   4814 	num_rescalers = v8
   4815 	total_size = (work_size + uint64(2)*uv_work_size) * uint64(4)
   4816 	if has_alpha != 0 {
   4817 		total_size = total_size + work_size*uint64(4)
   4818 	}
   4819 	rescaler_size = uint64(num_rescalers)*uint64(104) + uint64(WEBP_ALIGN_CST)
   4820 	total_size = total_size + rescaler_size
   4821 	v9 = total_size
   4822 	v2 = libc.BoolInt32(v9 == v9)
   4823 	goto _11
   4824 _11:
   4825 	if !(v2 != 0) {
   4826 		return 0
   4827 	}
   4828 	(*WebPDecParams)(unsafe.Pointer(p)).Fmemory = WebPSafeMalloc(tls, uint64(1), total_size)
   4829 	if (*WebPDecParams)(unsafe.Pointer(p)).Fmemory == libc.UintptrFromInt32(0) {
   4830 		return 0 // memory error
   4831 	}
   4832 	work = (*WebPDecParams)(unsafe.Pointer(p)).Fmemory
   4833 	scalers = uintptr((uint64(work+uintptr(total_size)-uintptr(rescaler_size)) + libc.Uint64FromInt32(WEBP_ALIGN_CST)) & ^libc.Uint64FromInt32(WEBP_ALIGN_CST))
   4834 	(*WebPDecParams)(unsafe.Pointer(p)).Fscaler_y = scalers
   4835 	(*WebPDecParams)(unsafe.Pointer(p)).Fscaler_u = scalers + 1*104
   4836 	(*WebPDecParams)(unsafe.Pointer(p)).Fscaler_v = scalers + 2*104
   4837 	if has_alpha != 0 {
   4838 		v12 = scalers + 3*104
   4839 	} else {
   4840 		v12 = libc.UintptrFromInt32(0)
   4841 	}
   4842 	(*WebPDecParams)(unsafe.Pointer(p)).Fscaler_a = v12
   4843 	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) {
   4844 		return 0
   4845 	}
   4846 	(*WebPDecParams)(unsafe.Pointer(p)).Femit = __ccgo_fp(EmitRescaledYUV)
   4847 	if has_alpha != 0 {
   4848 		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) {
   4849 			return 0
   4850 		}
   4851 		(*WebPDecParams)(unsafe.Pointer(p)).Femit_alpha = __ccgo_fp(EmitRescaledAlphaYUV)
   4852 		WebPInitAlphaProcessing(tls)
   4853 	}
   4854 	return int32(1)
   4855 }
   4856 
   4857 //------------------------------------------------------------------------------
   4858 // RGBA rescaling
   4859 
   4860 func ExportRGB(tls *libc.TLS, p uintptr, y_pos int32) (r int32) {
   4861 	var buf, dst, v1, v10, v4, v7 uintptr
   4862 	var convert WebPYUV444Converter
   4863 	var num_lines_out, v11, v2, v5, v8 int32
   4864 	var v13 bool
   4865 	_, _, _, _, _, _, _, _, _, _, _, _, _ = buf, convert, dst, num_lines_out, v1, v10, v11, v13, v2, v4, v5, v7, v8
   4866 	convert = WebPYUV444Converters[(*WebPDecBuffer)(unsafe.Pointer((*WebPDecParams)(unsafe.Pointer(p)).Foutput)).Fcolorspace]
   4867 	buf = (*WebPDecParams)(unsafe.Pointer(p)).Foutput + 16
   4868 	dst = (*WebPRGBABuffer)(unsafe.Pointer(buf)).Frgba + uintptr(int64(y_pos)*int64((*WebPRGBABuffer)(unsafe.Pointer(buf)).Fstride))
   4869 	num_lines_out = 0
   4870 	// For RGB rescaling, because of the YUV420, current scan position
   4871 	// U/V can be +1/-1 line from the Y one.  Hence the double test.
   4872 	for {
   4873 		v1 = (*WebPDecParams)(unsafe.Pointer(p)).Fscaler_y
   4874 		v4 = v1
   4875 		v5 = libc.BoolInt32((*WebPRescaler)(unsafe.Pointer(v4)).Fdst_y >= (*WebPRescaler)(unsafe.Pointer(v4)).Fdst_height)
   4876 		goto _6
   4877 	_6:
   4878 		;
   4879 		v2 = libc.BoolInt32(!(v5 != 0) && (*WebPRescaler)(unsafe.Pointer(v1)).Fy_accum <= 0)
   4880 		goto _3
   4881 	_3:
   4882 		;
   4883 		if v13 = v2 != 0; v13 {
   4884 			v7 = (*WebPDecParams)(unsafe.Pointer(p)).Fscaler_u
   4885 			v10 = v7
   4886 			v11 = libc.BoolInt32((*WebPRescaler)(unsafe.Pointer(v10)).Fdst_y >= (*WebPRescaler)(unsafe.Pointer(v10)).Fdst_height)
   4887 			goto _12
   4888 		_12:
   4889 			;
   4890 			v8 = libc.BoolInt32(!(v11 != 0) && (*WebPRescaler)(unsafe.Pointer(v7)).Fy_accum <= 0)
   4891 			goto _9
   4892 		_9:
   4893 		}
   4894 		if !(v13 && v8 != 0) {
   4895 			break
   4896 		}
   4897 		WebPRescalerExportRow(tls, (*WebPDecParams)(unsafe.Pointer(p)).Fscaler_y)
   4898 		WebPRescalerExportRow(tls, (*WebPDecParams)(unsafe.Pointer(p)).Fscaler_u)
   4899 		WebPRescalerExportRow(tls, (*WebPDecParams)(unsafe.Pointer(p)).Fscaler_v)
   4900 		(*(*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)
   4901 		dst = dst + uintptr((*WebPRGBABuffer)(unsafe.Pointer(buf)).Fstride)
   4902 		num_lines_out = num_lines_out + 1
   4903 	}
   4904 	return num_lines_out
   4905 }
   4906 
   4907 func EmitRescaledRGB(tls *libc.TLS, io uintptr, p uintptr) (r int32) {
   4908 	var j, mb_h, num_lines_out, u_lines_in, uv_j, uv_mb_h, v_lines_in, y_lines_in int32
   4909 	_, _, _, _, _, _, _, _ = j, mb_h, num_lines_out, u_lines_in, uv_j, uv_mb_h, v_lines_in, y_lines_in
   4910 	mb_h = (*VP8Io)(unsafe.Pointer(io)).Fmb_h
   4911 	uv_mb_h = (mb_h + int32(1)) >> int32(1)
   4912 	j = 0
   4913 	uv_j = 0
   4914 	num_lines_out = 0
   4915 	for j < mb_h {
   4916 		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)
   4917 		j = j + y_lines_in
   4918 		if WebPRescaleNeededLines(tls, (*WebPDecParams)(unsafe.Pointer(p)).Fscaler_u, uv_mb_h-uv_j) != 0 {
   4919 			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)
   4920 			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)
   4921 			_ = v_lines_in // remove a gcc warning
   4922 			uv_j = uv_j + u_lines_in
   4923 		}
   4924 		num_lines_out = num_lines_out + ExportRGB(tls, p, (*WebPDecParams)(unsafe.Pointer(p)).Flast_y+num_lines_out)
   4925 	}
   4926 	return num_lines_out
   4927 }
   4928 
   4929 func ExportAlpha(tls *libc.TLS, p uintptr, y_pos int32, max_lines_out int32) (r int32) {
   4930 	var alpha_first, is_premult_alpha, num_lines_out, width, v1, v3, v6, v9 int32
   4931 	var base_rgba, buf, dst, v5, v8 uintptr
   4932 	var colorspace, v2 WEBP_CSP_MODE1
   4933 	var non_opaque uint32_t
   4934 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = alpha_first, base_rgba, buf, colorspace, dst, is_premult_alpha, non_opaque, num_lines_out, width, v1, v2, v3, v5, v6, v8, v9
   4935 	buf = (*WebPDecParams)(unsafe.Pointer(p)).Foutput + 16
   4936 	base_rgba = (*WebPRGBABuffer)(unsafe.Pointer(buf)).Frgba + uintptr(int64(y_pos)*int64((*WebPRGBABuffer)(unsafe.Pointer(buf)).Fstride))
   4937 	colorspace = (*WebPDecBuffer)(unsafe.Pointer((*WebPDecParams)(unsafe.Pointer(p)).Foutput)).Fcolorspace
   4938 	alpha_first = libc.BoolInt32(colorspace == int32(MODE_ARGB) || colorspace == int32(MODE_Argb))
   4939 	if alpha_first != 0 {
   4940 		v1 = 0
   4941 	} else {
   4942 		v1 = int32(3)
   4943 	}
   4944 	dst = base_rgba + uintptr(v1)
   4945 	num_lines_out = 0
   4946 	v2 = colorspace
   4947 	v3 = libc.BoolInt32(v2 == int32(MODE_rgbA) || v2 == int32(MODE_bgrA) || v2 == int32(MODE_Argb) || v2 == int32(MODE_rgbA_4444))
   4948 	goto _4
   4949 _4:
   4950 	is_premult_alpha = v3
   4951 	non_opaque = uint32(0)
   4952 	width = (*WebPRescaler)(unsafe.Pointer((*WebPDecParams)(unsafe.Pointer(p)).Fscaler_a)).Fdst_width
   4953 	for {
   4954 		v5 = (*WebPDecParams)(unsafe.Pointer(p)).Fscaler_a
   4955 		v8 = v5
   4956 		v9 = libc.BoolInt32((*WebPRescaler)(unsafe.Pointer(v8)).Fdst_y >= (*WebPRescaler)(unsafe.Pointer(v8)).Fdst_height)
   4957 		goto _10
   4958 	_10:
   4959 		;
   4960 		v6 = libc.BoolInt32(!(v9 != 0) && (*WebPRescaler)(unsafe.Pointer(v5)).Fy_accum <= 0)
   4961 		goto _7
   4962 	_7:
   4963 		;
   4964 		if !(v6 != 0 && num_lines_out < max_lines_out) {
   4965 			break
   4966 		}
   4967 		WebPRescalerExportRow(tls, (*WebPDecParams)(unsafe.Pointer(p)).Fscaler_a)
   4968 		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))
   4969 		dst = dst + uintptr((*WebPRGBABuffer)(unsafe.Pointer(buf)).Fstride)
   4970 		num_lines_out = num_lines_out + 1
   4971 	}
   4972 	if is_premult_alpha != 0 && non_opaque != 0 {
   4973 		(*(*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)
   4974 	}
   4975 	return num_lines_out
   4976 }
   4977 
   4978 func ExportAlphaRGBA4444(tls *libc.TLS, p uintptr, y_pos int32, max_lines_out int32) (r int32) {
   4979 	var alpha_dst, base_rgba, buf, v4, v7 uintptr
   4980 	var alpha_mask, alpha_value uint32_t
   4981 	var colorspace, v1 WEBP_CSP_MODE1
   4982 	var i, is_premult_alpha, num_lines_out, width, v2, v5, v8 int32
   4983 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = alpha_dst, alpha_mask, alpha_value, base_rgba, buf, colorspace, i, is_premult_alpha, num_lines_out, width, v1, v2, v4, v5, v7, v8
   4984 	buf = (*WebPDecParams)(unsafe.Pointer(p)).Foutput + 16
   4985 	base_rgba = (*WebPRGBABuffer)(unsafe.Pointer(buf)).Frgba + uintptr(int64(y_pos)*int64((*WebPRGBABuffer)(unsafe.Pointer(buf)).Fstride))
   4986 	alpha_dst = base_rgba + uintptr(1)
   4987 	num_lines_out = 0
   4988 	colorspace = (*WebPDecBuffer)(unsafe.Pointer((*WebPDecParams)(unsafe.Pointer(p)).Foutput)).Fcolorspace
   4989 	width = (*WebPRescaler)(unsafe.Pointer((*WebPDecParams)(unsafe.Pointer(p)).Fscaler_a)).Fdst_width
   4990 	v1 = colorspace
   4991 	v2 = libc.BoolInt32(v1 == int32(MODE_rgbA) || v1 == int32(MODE_bgrA) || v1 == int32(MODE_Argb) || v1 == int32(MODE_rgbA_4444))
   4992 	goto _3
   4993 _3:
   4994 	is_premult_alpha = v2
   4995 	alpha_mask = uint32(0x0f)
   4996 	for {
   4997 		v4 = (*WebPDecParams)(unsafe.Pointer(p)).Fscaler_a
   4998 		v7 = v4
   4999 		v8 = libc.BoolInt32((*WebPRescaler)(unsafe.Pointer(v7)).Fdst_y >= (*WebPRescaler)(unsafe.Pointer(v7)).Fdst_height)
   5000 		goto _9
   5001 	_9:
   5002 		;
   5003 		v5 = libc.BoolInt32(!(v8 != 0) && (*WebPRescaler)(unsafe.Pointer(v4)).Fy_accum <= 0)
   5004 		goto _6
   5005 	_6:
   5006 		;
   5007 		if !(v5 != 0 && num_lines_out < max_lines_out) {
   5008 			break
   5009 		}
   5010 		WebPRescalerExportRow(tls, (*WebPDecParams)(unsafe.Pointer(p)).Fscaler_a)
   5011 		i = 0
   5012 		for {
   5013 			if !(i < width) {
   5014 				break
   5015 			}
   5016 			// Fill in the alpha value (converted to 4 bits).
   5017 			alpha_value = uint32(int32(**(**uint8_t)(__ccgo_up((*WebPRescaler)(unsafe.Pointer((*WebPDecParams)(unsafe.Pointer(p)).Fscaler_a)).Fdst + uintptr(i)))) >> int32(4))
   5018 			**(**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)
   5019 			alpha_mask = alpha_mask & alpha_value
   5020 			goto _10
   5021 		_10:
   5022 			;
   5023 			i = i + 1
   5024 		}
   5025 		alpha_dst = alpha_dst + uintptr((*WebPRGBABuffer)(unsafe.Pointer(buf)).Fstride)
   5026 		num_lines_out = num_lines_out + 1
   5027 	}
   5028 	if is_premult_alpha != 0 && alpha_mask != uint32(0x0f) {
   5029 		(*(*func(*libc.TLS, uintptr, int32, int32, int32))(unsafe.Pointer(&struct{ uintptr }{WebPApplyAlphaMultiply4444})))(tls, base_rgba, width, num_lines_out, (*WebPRGBABuffer)(unsafe.Pointer(buf)).Fstride)
   5030 	}
   5031 	return num_lines_out
   5032 }
   5033 
   5034 func EmitRescaledAlphaRGB(tls *libc.TLS, io uintptr, p uintptr, expected_num_out_lines int32) (r int32) {
   5035 	var lines_left, y_end int32
   5036 	var row_offset int64_t
   5037 	var scaler uintptr
   5038 	_, _, _, _ = lines_left, row_offset, scaler, y_end
   5039 	if (*VP8Io)(unsafe.Pointer(io)).Fa != libc.UintptrFromInt32(0) {
   5040 		scaler = (*WebPDecParams)(unsafe.Pointer(p)).Fscaler_a
   5041 		lines_left = expected_num_out_lines
   5042 		y_end = (*WebPDecParams)(unsafe.Pointer(p)).Flast_y + lines_left
   5043 		for lines_left > 0 {
   5044 			row_offset = int64((*WebPRescaler)(unsafe.Pointer(scaler)).Fsrc_y) - int64((*VP8Io)(unsafe.Pointer(io)).Fmb_y)
   5045 			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)
   5046 			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)
   5047 		}
   5048 	}
   5049 	return 0
   5050 }
   5051 
   5052 func InitRGBRescaler(tls *libc.TLS, io uintptr, p uintptr) (r int32) {
   5053 	var has_alpha, num_rescalers, out_height, out_width, uv_in_height, uv_in_width, v2, v5, v8 int32
   5054 	var rescaler_size, work_size size_t
   5055 	var scalers, tmp, work, v12 uintptr
   5056 	var tmp_size1, tmp_size2, total_size, v9 uint64_t
   5057 	var v1, v4 WEBP_CSP_MODE1
   5058 	var v7 bool
   5059 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
   5060 	v1 = (*WebPDecBuffer)(unsafe.Pointer((*WebPDecParams)(unsafe.Pointer(p)).Foutput)).Fcolorspace
   5061 	if v7 = v1 == int32(MODE_RGBA) || v1 == int32(MODE_BGRA) || v1 == int32(MODE_ARGB) || v1 == int32(MODE_RGBA_4444) || v1 == int32(MODE_YUVA); !v7 {
   5062 		v4 = v1
   5063 		v5 = libc.BoolInt32(v4 == int32(MODE_rgbA) || v4 == int32(MODE_bgrA) || v4 == int32(MODE_Argb) || v4 == int32(MODE_rgbA_4444))
   5064 		goto _6
   5065 	_6:
   5066 	}
   5067 	v2 = libc.BoolInt32(v7 || v5 != 0)
   5068 	goto _3
   5069 _3:
   5070 	has_alpha = v2
   5071 	out_width = (*VP8Io)(unsafe.Pointer(io)).Fscaled_width
   5072 	out_height = (*VP8Io)(unsafe.Pointer(io)).Fscaled_height
   5073 	uv_in_width = ((*VP8Io)(unsafe.Pointer(io)).Fmb_w + int32(1)) >> int32(1)
   5074 	uv_in_height = ((*VP8Io)(unsafe.Pointer(io)).Fmb_h + int32(1)) >> int32(1)
   5075 	// scratch memory for one rescaler
   5076 	work_size = uint64(2) * uint64(out_width)
   5077 	if has_alpha != 0 {
   5078 		v8 = int32(4)
   5079 	} else {
   5080 		v8 = int32(3)
   5081 	}
   5082 	num_rescalers = v8
   5083 	tmp_size1 = uint64(num_rescalers) * work_size
   5084 	tmp_size2 = uint64(num_rescalers) * uint64(out_width)
   5085 	total_size = tmp_size1*uint64(4) + tmp_size2*uint64(1)
   5086 	rescaler_size = uint64(num_rescalers)*uint64(104) + uint64(WEBP_ALIGN_CST)
   5087 	total_size = total_size + rescaler_size
   5088 	v9 = total_size
   5089 	v2 = libc.BoolInt32(v9 == v9)
   5090 	goto _11
   5091 _11:
   5092 	if !(v2 != 0) {
   5093 		return 0
   5094 	}
   5095 	(*WebPDecParams)(unsafe.Pointer(p)).Fmemory = WebPSafeMalloc(tls, uint64(1), total_size)
   5096 	if (*WebPDecParams)(unsafe.Pointer(p)).Fmemory == libc.UintptrFromInt32(0) {
   5097 		return 0 // memory error
   5098 	}
   5099 	work = (*WebPDecParams)(unsafe.Pointer(p)).Fmemory
   5100 	tmp = work + uintptr(tmp_size1)*4
   5101 	scalers = uintptr((uint64(work+uintptr(total_size)-uintptr(rescaler_size)) + libc.Uint64FromInt32(WEBP_ALIGN_CST)) & ^libc.Uint64FromInt32(WEBP_ALIGN_CST))
   5102 	(*WebPDecParams)(unsafe.Pointer(p)).Fscaler_y = scalers
   5103 	(*WebPDecParams)(unsafe.Pointer(p)).Fscaler_u = scalers + 1*104
   5104 	(*WebPDecParams)(unsafe.Pointer(p)).Fscaler_v = scalers + 2*104
   5105 	if has_alpha != 0 {
   5106 		v12 = scalers + 3*104
   5107 	} else {
   5108 		v12 = libc.UintptrFromInt32(0)
   5109 	}
   5110 	(*WebPDecParams)(unsafe.Pointer(p)).Fscaler_a = v12
   5111 	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) {
   5112 		return 0
   5113 	}
   5114 	(*WebPDecParams)(unsafe.Pointer(p)).Femit = __ccgo_fp(EmitRescaledRGB)
   5115 	WebPInitYUV444Converters(tls)
   5116 	if has_alpha != 0 {
   5117 		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) {
   5118 			return 0
   5119 		}
   5120 		(*WebPDecParams)(unsafe.Pointer(p)).Femit_alpha = __ccgo_fp(EmitRescaledAlphaRGB)
   5121 		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) {
   5122 			(*WebPDecParams)(unsafe.Pointer(p)).Femit_alpha_row = __ccgo_fp(ExportAlphaRGBA4444)
   5123 		} else {
   5124 			(*WebPDecParams)(unsafe.Pointer(p)).Femit_alpha_row = __ccgo_fp(ExportAlpha)
   5125 		}
   5126 		WebPInitAlphaProcessing(tls)
   5127 	}
   5128 	return int32(1)
   5129 }
   5130 
   5131 //------------------------------------------------------------------------------
   5132 // Default custom functions
   5133 
   5134 func CustomSetup(tls *libc.TLS, io uintptr) (r int32) {
   5135 	var colorspace, v3, v6 WEBP_CSP_MODE1
   5136 	var is_alpha, is_rgb, ok, uv_width, v1, v4, v7 int32
   5137 	var p, v16, v17 uintptr
   5138 	var v9 bool
   5139 	_, _, _, _, _, _, _, _, _, _, _, _, _, _ = colorspace, is_alpha, is_rgb, ok, p, uv_width, v1, v16, v17, v3, v4, v6, v7, v9
   5140 	p = (*VP8Io)(unsafe.Pointer(io)).Fopaque
   5141 	colorspace = (*WebPDecBuffer)(unsafe.Pointer((*WebPDecParams)(unsafe.Pointer(p)).Foutput)).Fcolorspace
   5142 	v1 = libc.BoolInt32(colorspace < int32(MODE_YUV))
   5143 	goto _2
   5144 _2:
   5145 	is_rgb = v1
   5146 	v3 = colorspace
   5147 	if v9 = v3 == int32(MODE_RGBA) || v3 == int32(MODE_BGRA) || v3 == int32(MODE_ARGB) || v3 == int32(MODE_RGBA_4444) || v3 == int32(MODE_YUVA); !v9 {
   5148 		v6 = v3
   5149 		v7 = libc.BoolInt32(v6 == int32(MODE_rgbA) || v6 == int32(MODE_bgrA) || v6 == int32(MODE_Argb) || v6 == int32(MODE_rgbA_4444))
   5150 		goto _8
   5151 	_8:
   5152 	}
   5153 	v4 = libc.BoolInt32(v9 || v7 != 0)
   5154 	goto _5
   5155 _5:
   5156 	is_alpha = v4
   5157 	(*WebPDecParams)(unsafe.Pointer(p)).Fmemory = libc.UintptrFromInt32(0)
   5158 	(*WebPDecParams)(unsafe.Pointer(p)).Femit = libc.UintptrFromInt32(0)
   5159 	(*WebPDecParams)(unsafe.Pointer(p)).Femit_alpha = libc.UintptrFromInt32(0)
   5160 	(*WebPDecParams)(unsafe.Pointer(p)).Femit_alpha_row = libc.UintptrFromInt32(0)
   5161 	if is_alpha != 0 {
   5162 		v1 = int32(MODE_YUV)
   5163 	} else {
   5164 		v1 = int32(MODE_YUVA)
   5165 	}
   5166 	if !(WebPIoInitFromOptions(tls, (*WebPDecParams)(unsafe.Pointer(p)).Foptions, io, v1) != 0) {
   5167 		return 0
   5168 	}
   5169 	if v9 = is_alpha != 0; v9 {
   5170 		v3 = colorspace
   5171 		v1 = libc.BoolInt32(v3 == int32(MODE_rgbA) || v3 == int32(MODE_bgrA) || v3 == int32(MODE_Argb) || v3 == int32(MODE_rgbA_4444))
   5172 		goto _13
   5173 	_13:
   5174 	}
   5175 	if v9 && v1 != 0 {
   5176 		WebPInitUpsamplers(tls)
   5177 	}
   5178 	if (*VP8Io)(unsafe.Pointer(io)).Fuse_scaling != 0 {
   5179 		if is_rgb != 0 {
   5180 			v1 = InitRGBRescaler(tls, io, p)
   5181 		} else {
   5182 			v1 = InitYUVRescaler(tls, io, p)
   5183 		}
   5184 		ok = v1
   5185 		if !(ok != 0) {
   5186 			return 0 // memory error
   5187 		}
   5188 	} else {
   5189 		if is_rgb != 0 {
   5190 			WebPInitSamplers(tls)
   5191 			(*WebPDecParams)(unsafe.Pointer(p)).Femit = __ccgo_fp(EmitSampledRGB) // default
   5192 			if (*VP8Io)(unsafe.Pointer(io)).Ffancy_upsampling != 0 {
   5193 				uv_width = ((*VP8Io)(unsafe.Pointer(io)).Fmb_w + int32(1)) >> int32(1)
   5194 				(*WebPDecParams)(unsafe.Pointer(p)).Fmemory = WebPSafeMalloc(tls, uint64(1), uint64((*VP8Io)(unsafe.Pointer(io)).Fmb_w+libc.Int32FromInt32(2)*uv_width))
   5195 				if (*WebPDecParams)(unsafe.Pointer(p)).Fmemory == libc.UintptrFromInt32(0) {
   5196 					return 0 // memory error.
   5197 				}
   5198 				(*WebPDecParams)(unsafe.Pointer(p)).Ftmp_y = (*WebPDecParams)(unsafe.Pointer(p)).Fmemory
   5199 				(*WebPDecParams)(unsafe.Pointer(p)).Ftmp_u = (*WebPDecParams)(unsafe.Pointer(p)).Ftmp_y + uintptr((*VP8Io)(unsafe.Pointer(io)).Fmb_w)
   5200 				(*WebPDecParams)(unsafe.Pointer(p)).Ftmp_v = (*WebPDecParams)(unsafe.Pointer(p)).Ftmp_u + uintptr(uv_width)
   5201 				(*WebPDecParams)(unsafe.Pointer(p)).Femit = __ccgo_fp(EmitFancyRGB)
   5202 				WebPInitUpsamplers(tls)
   5203 			}
   5204 		} else {
   5205 			(*WebPDecParams)(unsafe.Pointer(p)).Femit = __ccgo_fp(EmitYUV)
   5206 		}
   5207 		if is_alpha != 0 { // need transparency output
   5208 			if colorspace == int32(MODE_RGBA_4444) || colorspace == int32(MODE_rgbA_4444) {
   5209 				v16 = __ccgo_fp(EmitAlphaRGBA4444)
   5210 			} else {
   5211 				if is_rgb != 0 {
   5212 					v17 = __ccgo_fp(EmitAlphaRGB)
   5213 				} else {
   5214 					v17 = __ccgo_fp(EmitAlphaYUV)
   5215 				}
   5216 				v16 = v17
   5217 			}
   5218 			(*WebPDecParams)(unsafe.Pointer(p)).Femit_alpha = v16
   5219 			if is_rgb != 0 {
   5220 				WebPInitAlphaProcessing(tls)
   5221 			}
   5222 		}
   5223 	}
   5224 	return int32(1)
   5225 }
   5226 
   5227 //------------------------------------------------------------------------------
   5228 
   5229 func CustomPut(tls *libc.TLS, io uintptr) (r int32) {
   5230 	var mb_h, mb_w, num_lines_out int32
   5231 	var p uintptr
   5232 	_, _, _, _ = mb_h, mb_w, num_lines_out, p
   5233 	p = (*VP8Io)(unsafe.Pointer(io)).Fopaque
   5234 	mb_w = (*VP8Io)(unsafe.Pointer(io)).Fmb_w
   5235 	mb_h = (*VP8Io)(unsafe.Pointer(io)).Fmb_h
   5236 	if mb_w <= 0 || mb_h <= 0 {
   5237 		return 0
   5238 	}
   5239 	num_lines_out = (*(*func(*libc.TLS, uintptr, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*WebPDecParams)(unsafe.Pointer(p)).Femit})))(tls, io, p)
   5240 	if (*WebPDecParams)(unsafe.Pointer(p)).Femit_alpha != libc.UintptrFromInt32(0) {
   5241 		(*(*func(*libc.TLS, uintptr, uintptr, int32) int32)(unsafe.Pointer(&struct{ uintptr }{(*WebPDecParams)(unsafe.Pointer(p)).Femit_alpha})))(tls, io, p, num_lines_out)
   5242 	}
   5243 	**(**int32)(__ccgo_up(p + 32)) += num_lines_out
   5244 	return int32(1)
   5245 }
   5246 
   5247 //------------------------------------------------------------------------------
   5248 
   5249 func CustomTeardown(tls *libc.TLS, io uintptr) {
   5250 	var p uintptr
   5251 	_ = p
   5252 	p = (*VP8Io)(unsafe.Pointer(io)).Fopaque
   5253 	WebPSafeFree(tls, (*WebPDecParams)(unsafe.Pointer(p)).Fmemory)
   5254 	(*WebPDecParams)(unsafe.Pointer(p)).Fmemory = libc.UintptrFromInt32(0)
   5255 }
   5256 
   5257 //------------------------------------------------------------------------------
   5258 // Main entry point
   5259 
   5260 func WebPInitCustomIo(tls *libc.TLS, params uintptr, io uintptr) {
   5261 	(*VP8Io)(unsafe.Pointer(io)).Fput = __ccgo_fp(CustomPut)
   5262 	(*VP8Io)(unsafe.Pointer(io)).Fsetup = __ccgo_fp(CustomSetup)
   5263 	(*VP8Io)(unsafe.Pointer(io)).Fteardown = __ccgo_fp(CustomTeardown)
   5264 	(*VP8Io)(unsafe.Pointer(io)).Fopaque = params
   5265 }
   5266 
   5267 const SIZE_MAX1 = "UINT64_MAX"
   5268 
   5269 var kHashMul5 = uint32(0x1e35a7bd)
   5270 
   5271 //------------------------------------------------------------------------------
   5272 
   5273 // Copyright 2010 Google Inc. All Rights Reserved.
   5274 //
   5275 // Use of this source code is governed by a BSD-style license
   5276 // that can be found in the COPYING file in the root of the source
   5277 // tree. An additional intellectual property rights grant can be found
   5278 // in the file PATENTS. All contributing project authors may
   5279 // be found in the AUTHORS file in the root of the source tree.
   5280 // -----------------------------------------------------------------------------
   5281 //
   5282 // Boolean decoder
   5283 //
   5284 // Author: Skal (pascal.massimino@gmail.com)
   5285 //         Vikas Arora (vikaas.arora@gmail.com)
   5286 
   5287 // Copyright 2010 Google Inc. All Rights Reserved.
   5288 //
   5289 // Use of this source code is governed by a BSD-style license
   5290 // that can be found in the COPYING file in the root of the source
   5291 // tree. An additional intellectual property rights grant can be found
   5292 // in the file PATENTS. All contributing project authors may
   5293 // be found in the AUTHORS file in the root of the source tree.
   5294 // -----------------------------------------------------------------------------
   5295 //
   5296 //  Common types + memory wrappers
   5297 //
   5298 // Author: Skal (pascal.massimino@gmail.com)
   5299 
   5300 func clip(tls *libc.TLS, v int32, M int32) (r int32) {
   5301 	var v1, v2 int32
   5302 	_, _ = v1, v2
   5303 	if v < 0 {
   5304 		v1 = 0
   5305 	} else {
   5306 		if v > M {
   5307 			v2 = M
   5308 		} else {
   5309 			v2 = v
   5310 		}
   5311 		v1 = v2
   5312 	}
   5313 	return v1
   5314 }
   5315 
   5316 // C documentation
   5317 //
   5318 //	// Paragraph 14.1
   5319 var kDcTable = [128]uint8_t{
   5320 	0:   uint8(4),
   5321 	1:   uint8(5),
   5322 	2:   uint8(6),
   5323 	3:   uint8(7),
   5324 	4:   uint8(8),
   5325 	5:   uint8(9),
   5326 	6:   uint8(10),
   5327 	7:   uint8(10),
   5328 	8:   uint8(11),
   5329 	9:   uint8(12),
   5330 	10:  uint8(13),
   5331 	11:  uint8(14),
   5332 	12:  uint8(15),
   5333 	13:  uint8(16),
   5334 	14:  uint8(17),
   5335 	15:  uint8(17),
   5336 	16:  uint8(18),
   5337 	17:  uint8(19),
   5338 	18:  uint8(20),
   5339 	19:  uint8(20),
   5340 	20:  uint8(21),
   5341 	21:  uint8(21),
   5342 	22:  uint8(22),
   5343 	23:  uint8(22),
   5344 	24:  uint8(23),
   5345 	25:  uint8(23),
   5346 	26:  uint8(24),
   5347 	27:  uint8(25),
   5348 	28:  uint8(25),
   5349 	29:  uint8(26),
   5350 	30:  uint8(27),
   5351 	31:  uint8(28),
   5352 	32:  uint8(29),
   5353 	33:  uint8(30),
   5354 	34:  uint8(31),
   5355 	35:  uint8(32),
   5356 	36:  uint8(33),
   5357 	37:  uint8(34),
   5358 	38:  uint8(35),
   5359 	39:  uint8(36),
   5360 	40:  uint8(37),
   5361 	41:  uint8(37),
   5362 	42:  uint8(38),
   5363 	43:  uint8(39),
   5364 	44:  uint8(40),
   5365 	45:  uint8(41),
   5366 	46:  uint8(42),
   5367 	47:  uint8(43),
   5368 	48:  uint8(44),
   5369 	49:  uint8(45),
   5370 	50:  uint8(46),
   5371 	51:  uint8(46),
   5372 	52:  uint8(47),
   5373 	53:  uint8(48),
   5374 	54:  uint8(49),
   5375 	55:  uint8(50),
   5376 	56:  uint8(51),
   5377 	57:  uint8(52),
   5378 	58:  uint8(53),
   5379 	59:  uint8(54),
   5380 	60:  uint8(55),
   5381 	61:  uint8(56),
   5382 	62:  uint8(57),
   5383 	63:  uint8(58),
   5384 	64:  uint8(59),
   5385 	65:  uint8(60),
   5386 	66:  uint8(61),
   5387 	67:  uint8(62),
   5388 	68:  uint8(63),
   5389 	69:  uint8(64),
   5390 	70:  uint8(65),
   5391 	71:  uint8(66),
   5392 	72:  uint8(67),
   5393 	73:  uint8(68),
   5394 	74:  uint8(69),
   5395 	75:  uint8(70),
   5396 	76:  uint8(71),
   5397 	77:  uint8(72),
   5398 	78:  uint8(73),
   5399 	79:  uint8(74),
   5400 	80:  uint8(75),
   5401 	81:  uint8(76),
   5402 	82:  uint8(76),
   5403 	83:  uint8(77),
   5404 	84:  uint8(78),
   5405 	85:  uint8(79),
   5406 	86:  uint8(80),
   5407 	87:  uint8(81),
   5408 	88:  uint8(82),
   5409 	89:  uint8(83),
   5410 	90:  uint8(84),
   5411 	91:  uint8(85),
   5412 	92:  uint8(86),
   5413 	93:  uint8(87),
   5414 	94:  uint8(88),
   5415 	95:  uint8(89),
   5416 	96:  uint8(91),
   5417 	97:  uint8(93),
   5418 	98:  uint8(95),
   5419 	99:  uint8(96),
   5420 	100: uint8(98),
   5421 	101: uint8(100),
   5422 	102: uint8(101),
   5423 	103: uint8(102),
   5424 	104: uint8(104),
   5425 	105: uint8(106),
   5426 	106: uint8(108),
   5427 	107: uint8(110),
   5428 	108: uint8(112),
   5429 	109: uint8(114),
   5430 	110: uint8(116),
   5431 	111: uint8(118),
   5432 	112: uint8(122),
   5433 	113: uint8(124),
   5434 	114: uint8(126),
   5435 	115: uint8(128),
   5436 	116: uint8(130),
   5437 	117: uint8(132),
   5438 	118: uint8(134),
   5439 	119: uint8(136),
   5440 	120: uint8(138),
   5441 	121: uint8(140),
   5442 	122: uint8(143),
   5443 	123: uint8(145),
   5444 	124: uint8(148),
   5445 	125: uint8(151),
   5446 	126: uint8(154),
   5447 	127: uint8(157),
   5448 }
   5449 
   5450 var kAcTable = [128]uint16_t{
   5451 	0:   uint16(4),
   5452 	1:   uint16(5),
   5453 	2:   uint16(6),
   5454 	3:   uint16(7),
   5455 	4:   uint16(8),
   5456 	5:   uint16(9),
   5457 	6:   uint16(10),
   5458 	7:   uint16(11),
   5459 	8:   uint16(12),
   5460 	9:   uint16(13),
   5461 	10:  uint16(14),
   5462 	11:  uint16(15),
   5463 	12:  uint16(16),
   5464 	13:  uint16(17),
   5465 	14:  uint16(18),
   5466 	15:  uint16(19),
   5467 	16:  uint16(20),
   5468 	17:  uint16(21),
   5469 	18:  uint16(22),
   5470 	19:  uint16(23),
   5471 	20:  uint16(24),
   5472 	21:  uint16(25),
   5473 	22:  uint16(26),
   5474 	23:  uint16(27),
   5475 	24:  uint16(28),
   5476 	25:  uint16(29),
   5477 	26:  uint16(30),
   5478 	27:  uint16(31),
   5479 	28:  uint16(32),
   5480 	29:  uint16(33),
   5481 	30:  uint16(34),
   5482 	31:  uint16(35),
   5483 	32:  uint16(36),
   5484 	33:  uint16(37),
   5485 	34:  uint16(38),
   5486 	35:  uint16(39),
   5487 	36:  uint16(40),
   5488 	37:  uint16(41),
   5489 	38:  uint16(42),
   5490 	39:  uint16(43),
   5491 	40:  uint16(44),
   5492 	41:  uint16(45),
   5493 	42:  uint16(46),
   5494 	43:  uint16(47),
   5495 	44:  uint16(48),
   5496 	45:  uint16(49),
   5497 	46:  uint16(50),
   5498 	47:  uint16(51),
   5499 	48:  uint16(52),
   5500 	49:  uint16(53),
   5501 	50:  uint16(54),
   5502 	51:  uint16(55),
   5503 	52:  uint16(56),
   5504 	53:  uint16(57),
   5505 	54:  uint16(58),
   5506 	55:  uint16(60),
   5507 	56:  uint16(62),
   5508 	57:  uint16(64),
   5509 	58:  uint16(66),
   5510 	59:  uint16(68),
   5511 	60:  uint16(70),
   5512 	61:  uint16(72),
   5513 	62:  uint16(74),
   5514 	63:  uint16(76),
   5515 	64:  uint16(78),
   5516 	65:  uint16(80),
   5517 	66:  uint16(82),
   5518 	67:  uint16(84),
   5519 	68:  uint16(86),
   5520 	69:  uint16(88),
   5521 	70:  uint16(90),
   5522 	71:  uint16(92),
   5523 	72:  uint16(94),
   5524 	73:  uint16(96),
   5525 	74:  uint16(98),
   5526 	75:  uint16(100),
   5527 	76:  uint16(102),
   5528 	77:  uint16(104),
   5529 	78:  uint16(106),
   5530 	79:  uint16(108),
   5531 	80:  uint16(110),
   5532 	81:  uint16(112),
   5533 	82:  uint16(114),
   5534 	83:  uint16(116),
   5535 	84:  uint16(119),
   5536 	85:  uint16(122),
   5537 	86:  uint16(125),
   5538 	87:  uint16(128),
   5539 	88:  uint16(131),
   5540 	89:  uint16(134),
   5541 	90:  uint16(137),
   5542 	91:  uint16(140),
   5543 	92:  uint16(143),
   5544 	93:  uint16(146),
   5545 	94:  uint16(149),
   5546 	95:  uint16(152),
   5547 	96:  uint16(155),
   5548 	97:  uint16(158),
   5549 	98:  uint16(161),
   5550 	99:  uint16(164),
   5551 	100: uint16(167),
   5552 	101: uint16(170),
   5553 	102: uint16(173),
   5554 	103: uint16(177),
   5555 	104: uint16(181),
   5556 	105: uint16(185),
   5557 	106: uint16(189),
   5558 	107: uint16(193),
   5559 	108: uint16(197),
   5560 	109: uint16(201),
   5561 	110: uint16(205),
   5562 	111: uint16(209),
   5563 	112: uint16(213),
   5564 	113: uint16(217),
   5565 	114: uint16(221),
   5566 	115: uint16(225),
   5567 	116: uint16(229),
   5568 	117: uint16(234),
   5569 	118: uint16(239),
   5570 	119: uint16(245),
   5571 	120: uint16(249),
   5572 	121: uint16(254),
   5573 	122: uint16(259),
   5574 	123: uint16(264),
   5575 	124: uint16(269),
   5576 	125: uint16(274),
   5577 	126: uint16(279),
   5578 	127: uint16(284),
   5579 }
   5580 
   5581 //------------------------------------------------------------------------------
   5582 // Paragraph 9.6
   5583 
   5584 func VP8ParseQuant(tls *libc.TLS, dec uintptr) {
   5585 	var base_q0, dquv_ac, dquv_dc, dqy1_dc, dqy2_ac, dqy2_dc, i, q, v1, v2, v3, v4, v5 int32
   5586 	var br, hdr, m uintptr
   5587 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = base_q0, br, dquv_ac, dquv_dc, dqy1_dc, dqy2_ac, dqy2_dc, hdr, i, m, q, v1, v2, v3, v4, v5
   5588 	br = dec + 16
   5589 	base_q0 = int32(VP8GetValue(tls, br, int32(7)))
   5590 	if VP8GetValue(tls, br, int32(1)) != 0 {
   5591 		v1 = VP8GetSignedValue(tls, br, int32(4))
   5592 	} else {
   5593 		v1 = 0
   5594 	}
   5595 	dqy1_dc = v1
   5596 	if VP8GetValue(tls, br, int32(1)) != 0 {
   5597 		v2 = VP8GetSignedValue(tls, br, int32(4))
   5598 	} else {
   5599 		v2 = 0
   5600 	}
   5601 	dqy2_dc = v2
   5602 	if VP8GetValue(tls, br, int32(1)) != 0 {
   5603 		v3 = VP8GetSignedValue(tls, br, int32(4))
   5604 	} else {
   5605 		v3 = 0
   5606 	}
   5607 	dqy2_ac = v3
   5608 	if VP8GetValue(tls, br, int32(1)) != 0 {
   5609 		v4 = VP8GetSignedValue(tls, br, int32(4))
   5610 	} else {
   5611 		v4 = 0
   5612 	}
   5613 	dquv_dc = v4
   5614 	if VP8GetValue(tls, br, int32(1)) != 0 {
   5615 		v5 = VP8GetSignedValue(tls, br, int32(4))
   5616 	} else {
   5617 		v5 = 0
   5618 	}
   5619 	dquv_ac = v5
   5620 	hdr = dec + 132
   5621 	i = 0
   5622 	for {
   5623 		if !(i < int32(NUM_MB_SEGMENTS)) {
   5624 			break
   5625 		}
   5626 		if (*VP8SegmentHeader)(unsafe.Pointer(hdr)).Fuse_segment != 0 {
   5627 			q = int32(**(**int8_t)(__ccgo_up(hdr + 12 + uintptr(i))))
   5628 			if !((*VP8SegmentHeader)(unsafe.Pointer(hdr)).Fabsolute_delta != 0) {
   5629 				q = q + base_q0
   5630 			}
   5631 		} else {
   5632 			if i > 0 {
   5633 				**(**VP8QuantMatrix)(__ccgo_up(dec + 1060 + uintptr(i)*32)) = **(**VP8QuantMatrix)(__ccgo_up(dec + 1060))
   5634 				goto _6
   5635 			} else {
   5636 				q = base_q0
   5637 			}
   5638 		}
   5639 		m = dec + 1060 + uintptr(i)*32
   5640 		**(**int32)(__ccgo_up(m)) = int32(kDcTable[clip(tls, q+dqy1_dc, int32(127))])
   5641 		**(**int32)(__ccgo_up(m + 1*4)) = int32(kAcTable[clip(tls, q+0, int32(127))])
   5642 		**(**int32)(__ccgo_up(m + 8)) = int32(kDcTable[clip(tls, q+dqy2_dc, int32(127))]) * int32(2)
   5643 		// For all x in [0..284], x*155/100 is bitwise equal to (x*101581) >> 16.
   5644 		// The smallest precision for that is '(x*6349) >> 12' but 16 is a good
   5645 		// word size.
   5646 		**(**int32)(__ccgo_up(m + 8 + 1*4)) = int32(kAcTable[clip(tls, q+dqy2_ac, int32(127))]) * int32(101581) >> int32(16)
   5647 		if **(**int32)(__ccgo_up(m + 8 + 1*4)) < int32(8) {
   5648 			**(**int32)(__ccgo_up(m + 8 + 1*4)) = int32(8)
   5649 		}
   5650 		**(**int32)(__ccgo_up(m + 16)) = int32(kDcTable[clip(tls, q+dquv_dc, int32(117))])
   5651 		**(**int32)(__ccgo_up(m + 16 + 1*4)) = int32(kAcTable[clip(tls, q+dquv_ac, int32(127))])
   5652 		(*VP8QuantMatrix)(unsafe.Pointer(m)).Fuv_quant = q + dquv_ac // for dithering strength evaluation
   5653 		goto _6
   5654 	_6:
   5655 		;
   5656 		i = i + 1
   5657 	}
   5658 }
   5659 
   5660 const USE_GENERIC_TREE = 1
   5661 
   5662 var kHashMul6 = uint32(0x1e35a7bd)
   5663 
   5664 type lbit_t = uint64
   5665 
   5666 // Copyright 2010 Google Inc. All Rights Reserved.
   5667 //
   5668 // Use of this source code is governed by a BSD-style license
   5669 // that can be found in the COPYING file in the root of the source
   5670 // tree. An additional intellectual property rights grant can be found
   5671 // in the file PATENTS. All contributing project authors may
   5672 // be found in the AUTHORS file in the root of the source tree.
   5673 // -----------------------------------------------------------------------------
   5674 //
   5675 // Boolean decoder
   5676 //
   5677 // Author: Skal (pascal.massimino@gmail.com)
   5678 //         Vikas Arora (vikaas.arora@gmail.com)
   5679 
   5680 // using a table is ~1-2% slower on ARM. Prefer the coded-tree approach then.
   5681 
   5682 var kYModesIntra4 = [18]int8_t{
   5683 	1:  int8(1),
   5684 	2:  int8(-int32(B_TM_PRED)),
   5685 	3:  int8(2),
   5686 	4:  int8(-int32(B_VE_PRED)),
   5687 	5:  int8(3),
   5688 	6:  int8(4),
   5689 	7:  int8(6),
   5690 	8:  int8(-int32(B_HE_PRED)),
   5691 	9:  int8(5),
   5692 	10: int8(-int32(B_RD_PRED)),
   5693 	11: int8(-int32(B_VR_PRED)),
   5694 	12: int8(-int32(B_LD_PRED)),
   5695 	13: int8(7),
   5696 	14: int8(-int32(B_VL_PRED)),
   5697 	15: int8(8),
   5698 	16: int8(-int32(B_HD_PRED)),
   5699 	17: int8(-int32(B_HU_PRED)),
   5700 }
   5701 
   5702 //------------------------------------------------------------------------------
   5703 // Default probabilities
   5704 
   5705 // C documentation
   5706 //
   5707 //	// Paragraph 13.5
   5708 
   5709 var CoeffsProba0 = [4][8][3][11]uint8_t{
   5710 	0: {
   5711 		0: {
   5712 			0: {
   5713 				0:  uint8(128),
   5714 				1:  uint8(128),
   5715 				2:  uint8(128),
   5716 				3:  uint8(128),
   5717 				4:  uint8(128),
   5718 				5:  uint8(128),
   5719 				6:  uint8(128),
   5720 				7:  uint8(128),
   5721 				8:  uint8(128),
   5722 				9:  uint8(128),
   5723 				10: uint8(128),
   5724 			},
   5725 			1: {
   5726 				0:  uint8(128),
   5727 				1:  uint8(128),
   5728 				2:  uint8(128),
   5729 				3:  uint8(128),
   5730 				4:  uint8(128),
   5731 				5:  uint8(128),
   5732 				6:  uint8(128),
   5733 				7:  uint8(128),
   5734 				8:  uint8(128),
   5735 				9:  uint8(128),
   5736 				10: uint8(128),
   5737 			},
   5738 			2: {
   5739 				0:  uint8(128),
   5740 				1:  uint8(128),
   5741 				2:  uint8(128),
   5742 				3:  uint8(128),
   5743 				4:  uint8(128),
   5744 				5:  uint8(128),
   5745 				6:  uint8(128),
   5746 				7:  uint8(128),
   5747 				8:  uint8(128),
   5748 				9:  uint8(128),
   5749 				10: uint8(128),
   5750 			},
   5751 		},
   5752 		1: {
   5753 			0: {
   5754 				0:  uint8(253),
   5755 				1:  uint8(136),
   5756 				2:  uint8(254),
   5757 				3:  uint8(255),
   5758 				4:  uint8(228),
   5759 				5:  uint8(219),
   5760 				6:  uint8(128),
   5761 				7:  uint8(128),
   5762 				8:  uint8(128),
   5763 				9:  uint8(128),
   5764 				10: uint8(128),
   5765 			},
   5766 			1: {
   5767 				0:  uint8(189),
   5768 				1:  uint8(129),
   5769 				2:  uint8(242),
   5770 				3:  uint8(255),
   5771 				4:  uint8(227),
   5772 				5:  uint8(213),
   5773 				6:  uint8(255),
   5774 				7:  uint8(219),
   5775 				8:  uint8(128),
   5776 				9:  uint8(128),
   5777 				10: uint8(128),
   5778 			},
   5779 			2: {
   5780 				0:  uint8(106),
   5781 				1:  uint8(126),
   5782 				2:  uint8(227),
   5783 				3:  uint8(252),
   5784 				4:  uint8(214),
   5785 				5:  uint8(209),
   5786 				6:  uint8(255),
   5787 				7:  uint8(255),
   5788 				8:  uint8(128),
   5789 				9:  uint8(128),
   5790 				10: uint8(128),
   5791 			},
   5792 		},
   5793 		2: {
   5794 			0: {
   5795 				0:  uint8(1),
   5796 				1:  uint8(98),
   5797 				2:  uint8(248),
   5798 				3:  uint8(255),
   5799 				4:  uint8(236),
   5800 				5:  uint8(226),
   5801 				6:  uint8(255),
   5802 				7:  uint8(255),
   5803 				8:  uint8(128),
   5804 				9:  uint8(128),
   5805 				10: uint8(128),
   5806 			},
   5807 			1: {
   5808 				0:  uint8(181),
   5809 				1:  uint8(133),
   5810 				2:  uint8(238),
   5811 				3:  uint8(254),
   5812 				4:  uint8(221),
   5813 				5:  uint8(234),
   5814 				6:  uint8(255),
   5815 				7:  uint8(154),
   5816 				8:  uint8(128),
   5817 				9:  uint8(128),
   5818 				10: uint8(128),
   5819 			},
   5820 			2: {
   5821 				0:  uint8(78),
   5822 				1:  uint8(134),
   5823 				2:  uint8(202),
   5824 				3:  uint8(247),
   5825 				4:  uint8(198),
   5826 				5:  uint8(180),
   5827 				6:  uint8(255),
   5828 				7:  uint8(219),
   5829 				8:  uint8(128),
   5830 				9:  uint8(128),
   5831 				10: uint8(128),
   5832 			},
   5833 		},
   5834 		3: {
   5835 			0: {
   5836 				0:  uint8(1),
   5837 				1:  uint8(185),
   5838 				2:  uint8(249),
   5839 				3:  uint8(255),
   5840 				4:  uint8(243),
   5841 				5:  uint8(255),
   5842 				6:  uint8(128),
   5843 				7:  uint8(128),
   5844 				8:  uint8(128),
   5845 				9:  uint8(128),
   5846 				10: uint8(128),
   5847 			},
   5848 			1: {
   5849 				0:  uint8(184),
   5850 				1:  uint8(150),
   5851 				2:  uint8(247),
   5852 				3:  uint8(255),
   5853 				4:  uint8(236),
   5854 				5:  uint8(224),
   5855 				6:  uint8(128),
   5856 				7:  uint8(128),
   5857 				8:  uint8(128),
   5858 				9:  uint8(128),
   5859 				10: uint8(128),
   5860 			},
   5861 			2: {
   5862 				0:  uint8(77),
   5863 				1:  uint8(110),
   5864 				2:  uint8(216),
   5865 				3:  uint8(255),
   5866 				4:  uint8(236),
   5867 				5:  uint8(230),
   5868 				6:  uint8(128),
   5869 				7:  uint8(128),
   5870 				8:  uint8(128),
   5871 				9:  uint8(128),
   5872 				10: uint8(128),
   5873 			},
   5874 		},
   5875 		4: {
   5876 			0: {
   5877 				0:  uint8(1),
   5878 				1:  uint8(101),
   5879 				2:  uint8(251),
   5880 				3:  uint8(255),
   5881 				4:  uint8(241),
   5882 				5:  uint8(255),
   5883 				6:  uint8(128),
   5884 				7:  uint8(128),
   5885 				8:  uint8(128),
   5886 				9:  uint8(128),
   5887 				10: uint8(128),
   5888 			},
   5889 			1: {
   5890 				0:  uint8(170),
   5891 				1:  uint8(139),
   5892 				2:  uint8(241),
   5893 				3:  uint8(252),
   5894 				4:  uint8(236),
   5895 				5:  uint8(209),
   5896 				6:  uint8(255),
   5897 				7:  uint8(255),
   5898 				8:  uint8(128),
   5899 				9:  uint8(128),
   5900 				10: uint8(128),
   5901 			},
   5902 			2: {
   5903 				0:  uint8(37),
   5904 				1:  uint8(116),
   5905 				2:  uint8(196),
   5906 				3:  uint8(243),
   5907 				4:  uint8(228),
   5908 				5:  uint8(255),
   5909 				6:  uint8(255),
   5910 				7:  uint8(255),
   5911 				8:  uint8(128),
   5912 				9:  uint8(128),
   5913 				10: uint8(128),
   5914 			},
   5915 		},
   5916 		5: {
   5917 			0: {
   5918 				0:  uint8(1),
   5919 				1:  uint8(204),
   5920 				2:  uint8(254),
   5921 				3:  uint8(255),
   5922 				4:  uint8(245),
   5923 				5:  uint8(255),
   5924 				6:  uint8(128),
   5925 				7:  uint8(128),
   5926 				8:  uint8(128),
   5927 				9:  uint8(128),
   5928 				10: uint8(128),
   5929 			},
   5930 			1: {
   5931 				0:  uint8(207),
   5932 				1:  uint8(160),
   5933 				2:  uint8(250),
   5934 				3:  uint8(255),
   5935 				4:  uint8(238),
   5936 				5:  uint8(128),
   5937 				6:  uint8(128),
   5938 				7:  uint8(128),
   5939 				8:  uint8(128),
   5940 				9:  uint8(128),
   5941 				10: uint8(128),
   5942 			},
   5943 			2: {
   5944 				0:  uint8(102),
   5945 				1:  uint8(103),
   5946 				2:  uint8(231),
   5947 				3:  uint8(255),
   5948 				4:  uint8(211),
   5949 				5:  uint8(171),
   5950 				6:  uint8(128),
   5951 				7:  uint8(128),
   5952 				8:  uint8(128),
   5953 				9:  uint8(128),
   5954 				10: uint8(128),
   5955 			},
   5956 		},
   5957 		6: {
   5958 			0: {
   5959 				0:  uint8(1),
   5960 				1:  uint8(152),
   5961 				2:  uint8(252),
   5962 				3:  uint8(255),
   5963 				4:  uint8(240),
   5964 				5:  uint8(255),
   5965 				6:  uint8(128),
   5966 				7:  uint8(128),
   5967 				8:  uint8(128),
   5968 				9:  uint8(128),
   5969 				10: uint8(128),
   5970 			},
   5971 			1: {
   5972 				0:  uint8(177),
   5973 				1:  uint8(135),
   5974 				2:  uint8(243),
   5975 				3:  uint8(255),
   5976 				4:  uint8(234),
   5977 				5:  uint8(225),
   5978 				6:  uint8(128),
   5979 				7:  uint8(128),
   5980 				8:  uint8(128),
   5981 				9:  uint8(128),
   5982 				10: uint8(128),
   5983 			},
   5984 			2: {
   5985 				0:  uint8(80),
   5986 				1:  uint8(129),
   5987 				2:  uint8(211),
   5988 				3:  uint8(255),
   5989 				4:  uint8(194),
   5990 				5:  uint8(224),
   5991 				6:  uint8(128),
   5992 				7:  uint8(128),
   5993 				8:  uint8(128),
   5994 				9:  uint8(128),
   5995 				10: uint8(128),
   5996 			},
   5997 		},
   5998 		7: {
   5999 			0: {
   6000 				0:  uint8(1),
   6001 				1:  uint8(1),
   6002 				2:  uint8(255),
   6003 				3:  uint8(128),
   6004 				4:  uint8(128),
   6005 				5:  uint8(128),
   6006 				6:  uint8(128),
   6007 				7:  uint8(128),
   6008 				8:  uint8(128),
   6009 				9:  uint8(128),
   6010 				10: uint8(128),
   6011 			},
   6012 			1: {
   6013 				0:  uint8(246),
   6014 				1:  uint8(1),
   6015 				2:  uint8(255),
   6016 				3:  uint8(128),
   6017 				4:  uint8(128),
   6018 				5:  uint8(128),
   6019 				6:  uint8(128),
   6020 				7:  uint8(128),
   6021 				8:  uint8(128),
   6022 				9:  uint8(128),
   6023 				10: uint8(128),
   6024 			},
   6025 			2: {
   6026 				0:  uint8(255),
   6027 				1:  uint8(128),
   6028 				2:  uint8(128),
   6029 				3:  uint8(128),
   6030 				4:  uint8(128),
   6031 				5:  uint8(128),
   6032 				6:  uint8(128),
   6033 				7:  uint8(128),
   6034 				8:  uint8(128),
   6035 				9:  uint8(128),
   6036 				10: uint8(128),
   6037 			},
   6038 		},
   6039 	},
   6040 	1: {
   6041 		0: {
   6042 			0: {
   6043 				0:  uint8(198),
   6044 				1:  uint8(35),
   6045 				2:  uint8(237),
   6046 				3:  uint8(223),
   6047 				4:  uint8(193),
   6048 				5:  uint8(187),
   6049 				6:  uint8(162),
   6050 				7:  uint8(160),
   6051 				8:  uint8(145),
   6052 				9:  uint8(155),
   6053 				10: uint8(62),
   6054 			},
   6055 			1: {
   6056 				0:  uint8(131),
   6057 				1:  uint8(45),
   6058 				2:  uint8(198),
   6059 				3:  uint8(221),
   6060 				4:  uint8(172),
   6061 				5:  uint8(176),
   6062 				6:  uint8(220),
   6063 				7:  uint8(157),
   6064 				8:  uint8(252),
   6065 				9:  uint8(221),
   6066 				10: uint8(1),
   6067 			},
   6068 			2: {
   6069 				0:  uint8(68),
   6070 				1:  uint8(47),
   6071 				2:  uint8(146),
   6072 				3:  uint8(208),
   6073 				4:  uint8(149),
   6074 				5:  uint8(167),
   6075 				6:  uint8(221),
   6076 				7:  uint8(162),
   6077 				8:  uint8(255),
   6078 				9:  uint8(223),
   6079 				10: uint8(128),
   6080 			},
   6081 		},
   6082 		1: {
   6083 			0: {
   6084 				0:  uint8(1),
   6085 				1:  uint8(149),
   6086 				2:  uint8(241),
   6087 				3:  uint8(255),
   6088 				4:  uint8(221),
   6089 				5:  uint8(224),
   6090 				6:  uint8(255),
   6091 				7:  uint8(255),
   6092 				8:  uint8(128),
   6093 				9:  uint8(128),
   6094 				10: uint8(128),
   6095 			},
   6096 			1: {
   6097 				0:  uint8(184),
   6098 				1:  uint8(141),
   6099 				2:  uint8(234),
   6100 				3:  uint8(253),
   6101 				4:  uint8(222),
   6102 				5:  uint8(220),
   6103 				6:  uint8(255),
   6104 				7:  uint8(199),
   6105 				8:  uint8(128),
   6106 				9:  uint8(128),
   6107 				10: uint8(128),
   6108 			},
   6109 			2: {
   6110 				0:  uint8(81),
   6111 				1:  uint8(99),
   6112 				2:  uint8(181),
   6113 				3:  uint8(242),
   6114 				4:  uint8(176),
   6115 				5:  uint8(190),
   6116 				6:  uint8(249),
   6117 				7:  uint8(202),
   6118 				8:  uint8(255),
   6119 				9:  uint8(255),
   6120 				10: uint8(128),
   6121 			},
   6122 		},
   6123 		2: {
   6124 			0: {
   6125 				0:  uint8(1),
   6126 				1:  uint8(129),
   6127 				2:  uint8(232),
   6128 				3:  uint8(253),
   6129 				4:  uint8(214),
   6130 				5:  uint8(197),
   6131 				6:  uint8(242),
   6132 				7:  uint8(196),
   6133 				8:  uint8(255),
   6134 				9:  uint8(255),
   6135 				10: uint8(128),
   6136 			},
   6137 			1: {
   6138 				0:  uint8(99),
   6139 				1:  uint8(121),
   6140 				2:  uint8(210),
   6141 				3:  uint8(250),
   6142 				4:  uint8(201),
   6143 				5:  uint8(198),
   6144 				6:  uint8(255),
   6145 				7:  uint8(202),
   6146 				8:  uint8(128),
   6147 				9:  uint8(128),
   6148 				10: uint8(128),
   6149 			},
   6150 			2: {
   6151 				0:  uint8(23),
   6152 				1:  uint8(91),
   6153 				2:  uint8(163),
   6154 				3:  uint8(242),
   6155 				4:  uint8(170),
   6156 				5:  uint8(187),
   6157 				6:  uint8(247),
   6158 				7:  uint8(210),
   6159 				8:  uint8(255),
   6160 				9:  uint8(255),
   6161 				10: uint8(128),
   6162 			},
   6163 		},
   6164 		3: {
   6165 			0: {
   6166 				0:  uint8(1),
   6167 				1:  uint8(200),
   6168 				2:  uint8(246),
   6169 				3:  uint8(255),
   6170 				4:  uint8(234),
   6171 				5:  uint8(255),
   6172 				6:  uint8(128),
   6173 				7:  uint8(128),
   6174 				8:  uint8(128),
   6175 				9:  uint8(128),
   6176 				10: uint8(128),
   6177 			},
   6178 			1: {
   6179 				0:  uint8(109),
   6180 				1:  uint8(178),
   6181 				2:  uint8(241),
   6182 				3:  uint8(255),
   6183 				4:  uint8(231),
   6184 				5:  uint8(245),
   6185 				6:  uint8(255),
   6186 				7:  uint8(255),
   6187 				8:  uint8(128),
   6188 				9:  uint8(128),
   6189 				10: uint8(128),
   6190 			},
   6191 			2: {
   6192 				0:  uint8(44),
   6193 				1:  uint8(130),
   6194 				2:  uint8(201),
   6195 				3:  uint8(253),
   6196 				4:  uint8(205),
   6197 				5:  uint8(192),
   6198 				6:  uint8(255),
   6199 				7:  uint8(255),
   6200 				8:  uint8(128),
   6201 				9:  uint8(128),
   6202 				10: uint8(128),
   6203 			},
   6204 		},
   6205 		4: {
   6206 			0: {
   6207 				0:  uint8(1),
   6208 				1:  uint8(132),
   6209 				2:  uint8(239),
   6210 				3:  uint8(251),
   6211 				4:  uint8(219),
   6212 				5:  uint8(209),
   6213 				6:  uint8(255),
   6214 				7:  uint8(165),
   6215 				8:  uint8(128),
   6216 				9:  uint8(128),
   6217 				10: uint8(128),
   6218 			},
   6219 			1: {
   6220 				0:  uint8(94),
   6221 				1:  uint8(136),
   6222 				2:  uint8(225),
   6223 				3:  uint8(251),
   6224 				4:  uint8(218),
   6225 				5:  uint8(190),
   6226 				6:  uint8(255),
   6227 				7:  uint8(255),
   6228 				8:  uint8(128),
   6229 				9:  uint8(128),
   6230 				10: uint8(128),
   6231 			},
   6232 			2: {
   6233 				0:  uint8(22),
   6234 				1:  uint8(100),
   6235 				2:  uint8(174),
   6236 				3:  uint8(245),
   6237 				4:  uint8(186),
   6238 				5:  uint8(161),
   6239 				6:  uint8(255),
   6240 				7:  uint8(199),
   6241 				8:  uint8(128),
   6242 				9:  uint8(128),
   6243 				10: uint8(128),
   6244 			},
   6245 		},
   6246 		5: {
   6247 			0: {
   6248 				0:  uint8(1),
   6249 				1:  uint8(182),
   6250 				2:  uint8(249),
   6251 				3:  uint8(255),
   6252 				4:  uint8(232),
   6253 				5:  uint8(235),
   6254 				6:  uint8(128),
   6255 				7:  uint8(128),
   6256 				8:  uint8(128),
   6257 				9:  uint8(128),
   6258 				10: uint8(128),
   6259 			},
   6260 			1: {
   6261 				0:  uint8(124),
   6262 				1:  uint8(143),
   6263 				2:  uint8(241),
   6264 				3:  uint8(255),
   6265 				4:  uint8(227),
   6266 				5:  uint8(234),
   6267 				6:  uint8(128),
   6268 				7:  uint8(128),
   6269 				8:  uint8(128),
   6270 				9:  uint8(128),
   6271 				10: uint8(128),
   6272 			},
   6273 			2: {
   6274 				0:  uint8(35),
   6275 				1:  uint8(77),
   6276 				2:  uint8(181),
   6277 				3:  uint8(251),
   6278 				4:  uint8(193),
   6279 				5:  uint8(211),
   6280 				6:  uint8(255),
   6281 				7:  uint8(205),
   6282 				8:  uint8(128),
   6283 				9:  uint8(128),
   6284 				10: uint8(128),
   6285 			},
   6286 		},
   6287 		6: {
   6288 			0: {
   6289 				0:  uint8(1),
   6290 				1:  uint8(157),
   6291 				2:  uint8(247),
   6292 				3:  uint8(255),
   6293 				4:  uint8(236),
   6294 				5:  uint8(231),
   6295 				6:  uint8(255),
   6296 				7:  uint8(255),
   6297 				8:  uint8(128),
   6298 				9:  uint8(128),
   6299 				10: uint8(128),
   6300 			},
   6301 			1: {
   6302 				0:  uint8(121),
   6303 				1:  uint8(141),
   6304 				2:  uint8(235),
   6305 				3:  uint8(255),
   6306 				4:  uint8(225),
   6307 				5:  uint8(227),
   6308 				6:  uint8(255),
   6309 				7:  uint8(255),
   6310 				8:  uint8(128),
   6311 				9:  uint8(128),
   6312 				10: uint8(128),
   6313 			},
   6314 			2: {
   6315 				0:  uint8(45),
   6316 				1:  uint8(99),
   6317 				2:  uint8(188),
   6318 				3:  uint8(251),
   6319 				4:  uint8(195),
   6320 				5:  uint8(217),
   6321 				6:  uint8(255),
   6322 				7:  uint8(224),
   6323 				8:  uint8(128),
   6324 				9:  uint8(128),
   6325 				10: uint8(128),
   6326 			},
   6327 		},
   6328 		7: {
   6329 			0: {
   6330 				0:  uint8(1),
   6331 				1:  uint8(1),
   6332 				2:  uint8(251),
   6333 				3:  uint8(255),
   6334 				4:  uint8(213),
   6335 				5:  uint8(255),
   6336 				6:  uint8(128),
   6337 				7:  uint8(128),
   6338 				8:  uint8(128),
   6339 				9:  uint8(128),
   6340 				10: uint8(128),
   6341 			},
   6342 			1: {
   6343 				0:  uint8(203),
   6344 				1:  uint8(1),
   6345 				2:  uint8(248),
   6346 				3:  uint8(255),
   6347 				4:  uint8(255),
   6348 				5:  uint8(128),
   6349 				6:  uint8(128),
   6350 				7:  uint8(128),
   6351 				8:  uint8(128),
   6352 				9:  uint8(128),
   6353 				10: uint8(128),
   6354 			},
   6355 			2: {
   6356 				0:  uint8(137),
   6357 				1:  uint8(1),
   6358 				2:  uint8(177),
   6359 				3:  uint8(255),
   6360 				4:  uint8(224),
   6361 				5:  uint8(255),
   6362 				6:  uint8(128),
   6363 				7:  uint8(128),
   6364 				8:  uint8(128),
   6365 				9:  uint8(128),
   6366 				10: uint8(128),
   6367 			},
   6368 		},
   6369 	},
   6370 	2: {
   6371 		0: {
   6372 			0: {
   6373 				0:  uint8(253),
   6374 				1:  uint8(9),
   6375 				2:  uint8(248),
   6376 				3:  uint8(251),
   6377 				4:  uint8(207),
   6378 				5:  uint8(208),
   6379 				6:  uint8(255),
   6380 				7:  uint8(192),
   6381 				8:  uint8(128),
   6382 				9:  uint8(128),
   6383 				10: uint8(128),
   6384 			},
   6385 			1: {
   6386 				0:  uint8(175),
   6387 				1:  uint8(13),
   6388 				2:  uint8(224),
   6389 				3:  uint8(243),
   6390 				4:  uint8(193),
   6391 				5:  uint8(185),
   6392 				6:  uint8(249),
   6393 				7:  uint8(198),
   6394 				8:  uint8(255),
   6395 				9:  uint8(255),
   6396 				10: uint8(128),
   6397 			},
   6398 			2: {
   6399 				0:  uint8(73),
   6400 				1:  uint8(17),
   6401 				2:  uint8(171),
   6402 				3:  uint8(221),
   6403 				4:  uint8(161),
   6404 				5:  uint8(179),
   6405 				6:  uint8(236),
   6406 				7:  uint8(167),
   6407 				8:  uint8(255),
   6408 				9:  uint8(234),
   6409 				10: uint8(128),
   6410 			},
   6411 		},
   6412 		1: {
   6413 			0: {
   6414 				0:  uint8(1),
   6415 				1:  uint8(95),
   6416 				2:  uint8(247),
   6417 				3:  uint8(253),
   6418 				4:  uint8(212),
   6419 				5:  uint8(183),
   6420 				6:  uint8(255),
   6421 				7:  uint8(255),
   6422 				8:  uint8(128),
   6423 				9:  uint8(128),
   6424 				10: uint8(128),
   6425 			},
   6426 			1: {
   6427 				0:  uint8(239),
   6428 				1:  uint8(90),
   6429 				2:  uint8(244),
   6430 				3:  uint8(250),
   6431 				4:  uint8(211),
   6432 				5:  uint8(209),
   6433 				6:  uint8(255),
   6434 				7:  uint8(255),
   6435 				8:  uint8(128),
   6436 				9:  uint8(128),
   6437 				10: uint8(128),
   6438 			},
   6439 			2: {
   6440 				0:  uint8(155),
   6441 				1:  uint8(77),
   6442 				2:  uint8(195),
   6443 				3:  uint8(248),
   6444 				4:  uint8(188),
   6445 				5:  uint8(195),
   6446 				6:  uint8(255),
   6447 				7:  uint8(255),
   6448 				8:  uint8(128),
   6449 				9:  uint8(128),
   6450 				10: uint8(128),
   6451 			},
   6452 		},
   6453 		2: {
   6454 			0: {
   6455 				0:  uint8(1),
   6456 				1:  uint8(24),
   6457 				2:  uint8(239),
   6458 				3:  uint8(251),
   6459 				4:  uint8(218),
   6460 				5:  uint8(219),
   6461 				6:  uint8(255),
   6462 				7:  uint8(205),
   6463 				8:  uint8(128),
   6464 				9:  uint8(128),
   6465 				10: uint8(128),
   6466 			},
   6467 			1: {
   6468 				0:  uint8(201),
   6469 				1:  uint8(51),
   6470 				2:  uint8(219),
   6471 				3:  uint8(255),
   6472 				4:  uint8(196),
   6473 				5:  uint8(186),
   6474 				6:  uint8(128),
   6475 				7:  uint8(128),
   6476 				8:  uint8(128),
   6477 				9:  uint8(128),
   6478 				10: uint8(128),
   6479 			},
   6480 			2: {
   6481 				0:  uint8(69),
   6482 				1:  uint8(46),
   6483 				2:  uint8(190),
   6484 				3:  uint8(239),
   6485 				4:  uint8(201),
   6486 				5:  uint8(218),
   6487 				6:  uint8(255),
   6488 				7:  uint8(228),
   6489 				8:  uint8(128),
   6490 				9:  uint8(128),
   6491 				10: uint8(128),
   6492 			},
   6493 		},
   6494 		3: {
   6495 			0: {
   6496 				0:  uint8(1),
   6497 				1:  uint8(191),
   6498 				2:  uint8(251),
   6499 				3:  uint8(255),
   6500 				4:  uint8(255),
   6501 				5:  uint8(128),
   6502 				6:  uint8(128),
   6503 				7:  uint8(128),
   6504 				8:  uint8(128),
   6505 				9:  uint8(128),
   6506 				10: uint8(128),
   6507 			},
   6508 			1: {
   6509 				0:  uint8(223),
   6510 				1:  uint8(165),
   6511 				2:  uint8(249),
   6512 				3:  uint8(255),
   6513 				4:  uint8(213),
   6514 				5:  uint8(255),
   6515 				6:  uint8(128),
   6516 				7:  uint8(128),
   6517 				8:  uint8(128),
   6518 				9:  uint8(128),
   6519 				10: uint8(128),
   6520 			},
   6521 			2: {
   6522 				0:  uint8(141),
   6523 				1:  uint8(124),
   6524 				2:  uint8(248),
   6525 				3:  uint8(255),
   6526 				4:  uint8(255),
   6527 				5:  uint8(128),
   6528 				6:  uint8(128),
   6529 				7:  uint8(128),
   6530 				8:  uint8(128),
   6531 				9:  uint8(128),
   6532 				10: uint8(128),
   6533 			},
   6534 		},
   6535 		4: {
   6536 			0: {
   6537 				0:  uint8(1),
   6538 				1:  uint8(16),
   6539 				2:  uint8(248),
   6540 				3:  uint8(255),
   6541 				4:  uint8(255),
   6542 				5:  uint8(128),
   6543 				6:  uint8(128),
   6544 				7:  uint8(128),
   6545 				8:  uint8(128),
   6546 				9:  uint8(128),
   6547 				10: uint8(128),
   6548 			},
   6549 			1: {
   6550 				0:  uint8(190),
   6551 				1:  uint8(36),
   6552 				2:  uint8(230),
   6553 				3:  uint8(255),
   6554 				4:  uint8(236),
   6555 				5:  uint8(255),
   6556 				6:  uint8(128),
   6557 				7:  uint8(128),
   6558 				8:  uint8(128),
   6559 				9:  uint8(128),
   6560 				10: uint8(128),
   6561 			},
   6562 			2: {
   6563 				0:  uint8(149),
   6564 				1:  uint8(1),
   6565 				2:  uint8(255),
   6566 				3:  uint8(128),
   6567 				4:  uint8(128),
   6568 				5:  uint8(128),
   6569 				6:  uint8(128),
   6570 				7:  uint8(128),
   6571 				8:  uint8(128),
   6572 				9:  uint8(128),
   6573 				10: uint8(128),
   6574 			},
   6575 		},
   6576 		5: {
   6577 			0: {
   6578 				0:  uint8(1),
   6579 				1:  uint8(226),
   6580 				2:  uint8(255),
   6581 				3:  uint8(128),
   6582 				4:  uint8(128),
   6583 				5:  uint8(128),
   6584 				6:  uint8(128),
   6585 				7:  uint8(128),
   6586 				8:  uint8(128),
   6587 				9:  uint8(128),
   6588 				10: uint8(128),
   6589 			},
   6590 			1: {
   6591 				0:  uint8(247),
   6592 				1:  uint8(192),
   6593 				2:  uint8(255),
   6594 				3:  uint8(128),
   6595 				4:  uint8(128),
   6596 				5:  uint8(128),
   6597 				6:  uint8(128),
   6598 				7:  uint8(128),
   6599 				8:  uint8(128),
   6600 				9:  uint8(128),
   6601 				10: uint8(128),
   6602 			},
   6603 			2: {
   6604 				0:  uint8(240),
   6605 				1:  uint8(128),
   6606 				2:  uint8(255),
   6607 				3:  uint8(128),
   6608 				4:  uint8(128),
   6609 				5:  uint8(128),
   6610 				6:  uint8(128),
   6611 				7:  uint8(128),
   6612 				8:  uint8(128),
   6613 				9:  uint8(128),
   6614 				10: uint8(128),
   6615 			},
   6616 		},
   6617 		6: {
   6618 			0: {
   6619 				0:  uint8(1),
   6620 				1:  uint8(134),
   6621 				2:  uint8(252),
   6622 				3:  uint8(255),
   6623 				4:  uint8(255),
   6624 				5:  uint8(128),
   6625 				6:  uint8(128),
   6626 				7:  uint8(128),
   6627 				8:  uint8(128),
   6628 				9:  uint8(128),
   6629 				10: uint8(128),
   6630 			},
   6631 			1: {
   6632 				0:  uint8(213),
   6633 				1:  uint8(62),
   6634 				2:  uint8(250),
   6635 				3:  uint8(255),
   6636 				4:  uint8(255),
   6637 				5:  uint8(128),
   6638 				6:  uint8(128),
   6639 				7:  uint8(128),
   6640 				8:  uint8(128),
   6641 				9:  uint8(128),
   6642 				10: uint8(128),
   6643 			},
   6644 			2: {
   6645 				0:  uint8(55),
   6646 				1:  uint8(93),
   6647 				2:  uint8(255),
   6648 				3:  uint8(128),
   6649 				4:  uint8(128),
   6650 				5:  uint8(128),
   6651 				6:  uint8(128),
   6652 				7:  uint8(128),
   6653 				8:  uint8(128),
   6654 				9:  uint8(128),
   6655 				10: uint8(128),
   6656 			},
   6657 		},
   6658 		7: {
   6659 			0: {
   6660 				0:  uint8(128),
   6661 				1:  uint8(128),
   6662 				2:  uint8(128),
   6663 				3:  uint8(128),
   6664 				4:  uint8(128),
   6665 				5:  uint8(128),
   6666 				6:  uint8(128),
   6667 				7:  uint8(128),
   6668 				8:  uint8(128),
   6669 				9:  uint8(128),
   6670 				10: uint8(128),
   6671 			},
   6672 			1: {
   6673 				0:  uint8(128),
   6674 				1:  uint8(128),
   6675 				2:  uint8(128),
   6676 				3:  uint8(128),
   6677 				4:  uint8(128),
   6678 				5:  uint8(128),
   6679 				6:  uint8(128),
   6680 				7:  uint8(128),
   6681 				8:  uint8(128),
   6682 				9:  uint8(128),
   6683 				10: uint8(128),
   6684 			},
   6685 			2: {
   6686 				0:  uint8(128),
   6687 				1:  uint8(128),
   6688 				2:  uint8(128),
   6689 				3:  uint8(128),
   6690 				4:  uint8(128),
   6691 				5:  uint8(128),
   6692 				6:  uint8(128),
   6693 				7:  uint8(128),
   6694 				8:  uint8(128),
   6695 				9:  uint8(128),
   6696 				10: uint8(128),
   6697 			},
   6698 		},
   6699 	},
   6700 	3: {
   6701 		0: {
   6702 			0: {
   6703 				0:  uint8(202),
   6704 				1:  uint8(24),
   6705 				2:  uint8(213),
   6706 				3:  uint8(235),
   6707 				4:  uint8(186),
   6708 				5:  uint8(191),
   6709 				6:  uint8(220),
   6710 				7:  uint8(160),
   6711 				8:  uint8(240),
   6712 				9:  uint8(175),
   6713 				10: uint8(255),
   6714 			},
   6715 			1: {
   6716 				0:  uint8(126),
   6717 				1:  uint8(38),
   6718 				2:  uint8(182),
   6719 				3:  uint8(232),
   6720 				4:  uint8(169),
   6721 				5:  uint8(184),
   6722 				6:  uint8(228),
   6723 				7:  uint8(174),
   6724 				8:  uint8(255),
   6725 				9:  uint8(187),
   6726 				10: uint8(128),
   6727 			},
   6728 			2: {
   6729 				0:  uint8(61),
   6730 				1:  uint8(46),
   6731 				2:  uint8(138),
   6732 				3:  uint8(219),
   6733 				4:  uint8(151),
   6734 				5:  uint8(178),
   6735 				6:  uint8(240),
   6736 				7:  uint8(170),
   6737 				8:  uint8(255),
   6738 				9:  uint8(216),
   6739 				10: uint8(128),
   6740 			},
   6741 		},
   6742 		1: {
   6743 			0: {
   6744 				0:  uint8(1),
   6745 				1:  uint8(112),
   6746 				2:  uint8(230),
   6747 				3:  uint8(250),
   6748 				4:  uint8(199),
   6749 				5:  uint8(191),
   6750 				6:  uint8(247),
   6751 				7:  uint8(159),
   6752 				8:  uint8(255),
   6753 				9:  uint8(255),
   6754 				10: uint8(128),
   6755 			},
   6756 			1: {
   6757 				0:  uint8(166),
   6758 				1:  uint8(109),
   6759 				2:  uint8(228),
   6760 				3:  uint8(252),
   6761 				4:  uint8(211),
   6762 				5:  uint8(215),
   6763 				6:  uint8(255),
   6764 				7:  uint8(174),
   6765 				8:  uint8(128),
   6766 				9:  uint8(128),
   6767 				10: uint8(128),
   6768 			},
   6769 			2: {
   6770 				0:  uint8(39),
   6771 				1:  uint8(77),
   6772 				2:  uint8(162),
   6773 				3:  uint8(232),
   6774 				4:  uint8(172),
   6775 				5:  uint8(180),
   6776 				6:  uint8(245),
   6777 				7:  uint8(178),
   6778 				8:  uint8(255),
   6779 				9:  uint8(255),
   6780 				10: uint8(128),
   6781 			},
   6782 		},
   6783 		2: {
   6784 			0: {
   6785 				0:  uint8(1),
   6786 				1:  uint8(52),
   6787 				2:  uint8(220),
   6788 				3:  uint8(246),
   6789 				4:  uint8(198),
   6790 				5:  uint8(199),
   6791 				6:  uint8(249),
   6792 				7:  uint8(220),
   6793 				8:  uint8(255),
   6794 				9:  uint8(255),
   6795 				10: uint8(128),
   6796 			},
   6797 			1: {
   6798 				0:  uint8(124),
   6799 				1:  uint8(74),
   6800 				2:  uint8(191),
   6801 				3:  uint8(243),
   6802 				4:  uint8(183),
   6803 				5:  uint8(193),
   6804 				6:  uint8(250),
   6805 				7:  uint8(221),
   6806 				8:  uint8(255),
   6807 				9:  uint8(255),
   6808 				10: uint8(128),
   6809 			},
   6810 			2: {
   6811 				0:  uint8(24),
   6812 				1:  uint8(71),
   6813 				2:  uint8(130),
   6814 				3:  uint8(219),
   6815 				4:  uint8(154),
   6816 				5:  uint8(170),
   6817 				6:  uint8(243),
   6818 				7:  uint8(182),
   6819 				8:  uint8(255),
   6820 				9:  uint8(255),
   6821 				10: uint8(128),
   6822 			},
   6823 		},
   6824 		3: {
   6825 			0: {
   6826 				0:  uint8(1),
   6827 				1:  uint8(182),
   6828 				2:  uint8(225),
   6829 				3:  uint8(249),
   6830 				4:  uint8(219),
   6831 				5:  uint8(240),
   6832 				6:  uint8(255),
   6833 				7:  uint8(224),
   6834 				8:  uint8(128),
   6835 				9:  uint8(128),
   6836 				10: uint8(128),
   6837 			},
   6838 			1: {
   6839 				0:  uint8(149),
   6840 				1:  uint8(150),
   6841 				2:  uint8(226),
   6842 				3:  uint8(252),
   6843 				4:  uint8(216),
   6844 				5:  uint8(205),
   6845 				6:  uint8(255),
   6846 				7:  uint8(171),
   6847 				8:  uint8(128),
   6848 				9:  uint8(128),
   6849 				10: uint8(128),
   6850 			},
   6851 			2: {
   6852 				0:  uint8(28),
   6853 				1:  uint8(108),
   6854 				2:  uint8(170),
   6855 				3:  uint8(242),
   6856 				4:  uint8(183),
   6857 				5:  uint8(194),
   6858 				6:  uint8(254),
   6859 				7:  uint8(223),
   6860 				8:  uint8(255),
   6861 				9:  uint8(255),
   6862 				10: uint8(128),
   6863 			},
   6864 		},
   6865 		4: {
   6866 			0: {
   6867 				0:  uint8(1),
   6868 				1:  uint8(81),
   6869 				2:  uint8(230),
   6870 				3:  uint8(252),
   6871 				4:  uint8(204),
   6872 				5:  uint8(203),
   6873 				6:  uint8(255),
   6874 				7:  uint8(192),
   6875 				8:  uint8(128),
   6876 				9:  uint8(128),
   6877 				10: uint8(128),
   6878 			},
   6879 			1: {
   6880 				0:  uint8(123),
   6881 				1:  uint8(102),
   6882 				2:  uint8(209),
   6883 				3:  uint8(247),
   6884 				4:  uint8(188),
   6885 				5:  uint8(196),
   6886 				6:  uint8(255),
   6887 				7:  uint8(233),
   6888 				8:  uint8(128),
   6889 				9:  uint8(128),
   6890 				10: uint8(128),
   6891 			},
   6892 			2: {
   6893 				0:  uint8(20),
   6894 				1:  uint8(95),
   6895 				2:  uint8(153),
   6896 				3:  uint8(243),
   6897 				4:  uint8(164),
   6898 				5:  uint8(173),
   6899 				6:  uint8(255),
   6900 				7:  uint8(203),
   6901 				8:  uint8(128),
   6902 				9:  uint8(128),
   6903 				10: uint8(128),
   6904 			},
   6905 		},
   6906 		5: {
   6907 			0: {
   6908 				0:  uint8(1),
   6909 				1:  uint8(222),
   6910 				2:  uint8(248),
   6911 				3:  uint8(255),
   6912 				4:  uint8(216),
   6913 				5:  uint8(213),
   6914 				6:  uint8(128),
   6915 				7:  uint8(128),
   6916 				8:  uint8(128),
   6917 				9:  uint8(128),
   6918 				10: uint8(128),
   6919 			},
   6920 			1: {
   6921 				0:  uint8(168),
   6922 				1:  uint8(175),
   6923 				2:  uint8(246),
   6924 				3:  uint8(252),
   6925 				4:  uint8(235),
   6926 				5:  uint8(205),
   6927 				6:  uint8(255),
   6928 				7:  uint8(255),
   6929 				8:  uint8(128),
   6930 				9:  uint8(128),
   6931 				10: uint8(128),
   6932 			},
   6933 			2: {
   6934 				0:  uint8(47),
   6935 				1:  uint8(116),
   6936 				2:  uint8(215),
   6937 				3:  uint8(255),
   6938 				4:  uint8(211),
   6939 				5:  uint8(212),
   6940 				6:  uint8(255),
   6941 				7:  uint8(255),
   6942 				8:  uint8(128),
   6943 				9:  uint8(128),
   6944 				10: uint8(128),
   6945 			},
   6946 		},
   6947 		6: {
   6948 			0: {
   6949 				0:  uint8(1),
   6950 				1:  uint8(121),
   6951 				2:  uint8(236),
   6952 				3:  uint8(253),
   6953 				4:  uint8(212),
   6954 				5:  uint8(214),
   6955 				6:  uint8(255),
   6956 				7:  uint8(255),
   6957 				8:  uint8(128),
   6958 				9:  uint8(128),
   6959 				10: uint8(128),
   6960 			},
   6961 			1: {
   6962 				0:  uint8(141),
   6963 				1:  uint8(84),
   6964 				2:  uint8(213),
   6965 				3:  uint8(252),
   6966 				4:  uint8(201),
   6967 				5:  uint8(202),
   6968 				6:  uint8(255),
   6969 				7:  uint8(219),
   6970 				8:  uint8(128),
   6971 				9:  uint8(128),
   6972 				10: uint8(128),
   6973 			},
   6974 			2: {
   6975 				0:  uint8(42),
   6976 				1:  uint8(80),
   6977 				2:  uint8(160),
   6978 				3:  uint8(240),
   6979 				4:  uint8(162),
   6980 				5:  uint8(185),
   6981 				6:  uint8(255),
   6982 				7:  uint8(205),
   6983 				8:  uint8(128),
   6984 				9:  uint8(128),
   6985 				10: uint8(128),
   6986 			},
   6987 		},
   6988 		7: {
   6989 			0: {
   6990 				0:  uint8(1),
   6991 				1:  uint8(1),
   6992 				2:  uint8(255),
   6993 				3:  uint8(128),
   6994 				4:  uint8(128),
   6995 				5:  uint8(128),
   6996 				6:  uint8(128),
   6997 				7:  uint8(128),
   6998 				8:  uint8(128),
   6999 				9:  uint8(128),
   7000 				10: uint8(128),
   7001 			},
   7002 			1: {
   7003 				0:  uint8(244),
   7004 				1:  uint8(1),
   7005 				2:  uint8(255),
   7006 				3:  uint8(128),
   7007 				4:  uint8(128),
   7008 				5:  uint8(128),
   7009 				6:  uint8(128),
   7010 				7:  uint8(128),
   7011 				8:  uint8(128),
   7012 				9:  uint8(128),
   7013 				10: uint8(128),
   7014 			},
   7015 			2: {
   7016 				0:  uint8(238),
   7017 				1:  uint8(1),
   7018 				2:  uint8(255),
   7019 				3:  uint8(128),
   7020 				4:  uint8(128),
   7021 				5:  uint8(128),
   7022 				6:  uint8(128),
   7023 				7:  uint8(128),
   7024 				8:  uint8(128),
   7025 				9:  uint8(128),
   7026 				10: uint8(128),
   7027 			},
   7028 		},
   7029 	},
   7030 }
   7031 
   7032 // C documentation
   7033 //
   7034 //	// Paragraph 11.5
   7035 var kBModesProba = [10][10][9]uint8_t{
   7036 	0: {
   7037 		0: {
   7038 			0: uint8(231),
   7039 			1: uint8(120),
   7040 			2: uint8(48),
   7041 			3: uint8(89),
   7042 			4: uint8(115),
   7043 			5: uint8(113),
   7044 			6: uint8(120),
   7045 			7: uint8(152),
   7046 			8: uint8(112),
   7047 		},
   7048 		1: {
   7049 			0: uint8(152),
   7050 			1: uint8(179),
   7051 			2: uint8(64),
   7052 			3: uint8(126),
   7053 			4: uint8(170),
   7054 			5: uint8(118),
   7055 			6: uint8(46),
   7056 			7: uint8(70),
   7057 			8: uint8(95),
   7058 		},
   7059 		2: {
   7060 			0: uint8(175),
   7061 			1: uint8(69),
   7062 			2: uint8(143),
   7063 			3: uint8(80),
   7064 			4: uint8(85),
   7065 			5: uint8(82),
   7066 			6: uint8(72),
   7067 			7: uint8(155),
   7068 			8: uint8(103),
   7069 		},
   7070 		3: {
   7071 			0: uint8(56),
   7072 			1: uint8(58),
   7073 			2: uint8(10),
   7074 			3: uint8(171),
   7075 			4: uint8(218),
   7076 			5: uint8(189),
   7077 			6: uint8(17),
   7078 			7: uint8(13),
   7079 			8: uint8(152),
   7080 		},
   7081 		4: {
   7082 			0: uint8(114),
   7083 			1: uint8(26),
   7084 			2: uint8(17),
   7085 			3: uint8(163),
   7086 			4: uint8(44),
   7087 			5: uint8(195),
   7088 			6: uint8(21),
   7089 			7: uint8(10),
   7090 			8: uint8(173),
   7091 		},
   7092 		5: {
   7093 			0: uint8(121),
   7094 			1: uint8(24),
   7095 			2: uint8(80),
   7096 			3: uint8(195),
   7097 			4: uint8(26),
   7098 			5: uint8(62),
   7099 			6: uint8(44),
   7100 			7: uint8(64),
   7101 			8: uint8(85),
   7102 		},
   7103 		6: {
   7104 			0: uint8(144),
   7105 			1: uint8(71),
   7106 			2: uint8(10),
   7107 			3: uint8(38),
   7108 			4: uint8(171),
   7109 			5: uint8(213),
   7110 			6: uint8(144),
   7111 			7: uint8(34),
   7112 			8: uint8(26),
   7113 		},
   7114 		7: {
   7115 			0: uint8(170),
   7116 			1: uint8(46),
   7117 			2: uint8(55),
   7118 			3: uint8(19),
   7119 			4: uint8(136),
   7120 			5: uint8(160),
   7121 			6: uint8(33),
   7122 			7: uint8(206),
   7123 			8: uint8(71),
   7124 		},
   7125 		8: {
   7126 			0: uint8(63),
   7127 			1: uint8(20),
   7128 			2: uint8(8),
   7129 			3: uint8(114),
   7130 			4: uint8(114),
   7131 			5: uint8(208),
   7132 			6: uint8(12),
   7133 			7: uint8(9),
   7134 			8: uint8(226),
   7135 		},
   7136 		9: {
   7137 			0: uint8(81),
   7138 			1: uint8(40),
   7139 			2: uint8(11),
   7140 			3: uint8(96),
   7141 			4: uint8(182),
   7142 			5: uint8(84),
   7143 			6: uint8(29),
   7144 			7: uint8(16),
   7145 			8: uint8(36),
   7146 		},
   7147 	},
   7148 	1: {
   7149 		0: {
   7150 			0: uint8(134),
   7151 			1: uint8(183),
   7152 			2: uint8(89),
   7153 			3: uint8(137),
   7154 			4: uint8(98),
   7155 			5: uint8(101),
   7156 			6: uint8(106),
   7157 			7: uint8(165),
   7158 			8: uint8(148),
   7159 		},
   7160 		1: {
   7161 			0: uint8(72),
   7162 			1: uint8(187),
   7163 			2: uint8(100),
   7164 			3: uint8(130),
   7165 			4: uint8(157),
   7166 			5: uint8(111),
   7167 			6: uint8(32),
   7168 			7: uint8(75),
   7169 			8: uint8(80),
   7170 		},
   7171 		2: {
   7172 			0: uint8(66),
   7173 			1: uint8(102),
   7174 			2: uint8(167),
   7175 			3: uint8(99),
   7176 			4: uint8(74),
   7177 			5: uint8(62),
   7178 			6: uint8(40),
   7179 			7: uint8(234),
   7180 			8: uint8(128),
   7181 		},
   7182 		3: {
   7183 			0: uint8(41),
   7184 			1: uint8(53),
   7185 			2: uint8(9),
   7186 			3: uint8(178),
   7187 			4: uint8(241),
   7188 			5: uint8(141),
   7189 			6: uint8(26),
   7190 			7: uint8(8),
   7191 			8: uint8(107),
   7192 		},
   7193 		4: {
   7194 			0: uint8(74),
   7195 			1: uint8(43),
   7196 			2: uint8(26),
   7197 			3: uint8(146),
   7198 			4: uint8(73),
   7199 			5: uint8(166),
   7200 			6: uint8(49),
   7201 			7: uint8(23),
   7202 			8: uint8(157),
   7203 		},
   7204 		5: {
   7205 			0: uint8(65),
   7206 			1: uint8(38),
   7207 			2: uint8(105),
   7208 			3: uint8(160),
   7209 			4: uint8(51),
   7210 			5: uint8(52),
   7211 			6: uint8(31),
   7212 			7: uint8(115),
   7213 			8: uint8(128),
   7214 		},
   7215 		6: {
   7216 			0: uint8(104),
   7217 			1: uint8(79),
   7218 			2: uint8(12),
   7219 			3: uint8(27),
   7220 			4: uint8(217),
   7221 			5: uint8(255),
   7222 			6: uint8(87),
   7223 			7: uint8(17),
   7224 			8: uint8(7),
   7225 		},
   7226 		7: {
   7227 			0: uint8(87),
   7228 			1: uint8(68),
   7229 			2: uint8(71),
   7230 			3: uint8(44),
   7231 			4: uint8(114),
   7232 			5: uint8(51),
   7233 			6: uint8(15),
   7234 			7: uint8(186),
   7235 			8: uint8(23),
   7236 		},
   7237 		8: {
   7238 			0: uint8(47),
   7239 			1: uint8(41),
   7240 			2: uint8(14),
   7241 			3: uint8(110),
   7242 			4: uint8(182),
   7243 			5: uint8(183),
   7244 			6: uint8(21),
   7245 			7: uint8(17),
   7246 			8: uint8(194),
   7247 		},
   7248 		9: {
   7249 			0: uint8(66),
   7250 			1: uint8(45),
   7251 			2: uint8(25),
   7252 			3: uint8(102),
   7253 			4: uint8(197),
   7254 			5: uint8(189),
   7255 			6: uint8(23),
   7256 			7: uint8(18),
   7257 			8: uint8(22),
   7258 		},
   7259 	},
   7260 	2: {
   7261 		0: {
   7262 			0: uint8(88),
   7263 			1: uint8(88),
   7264 			2: uint8(147),
   7265 			3: uint8(150),
   7266 			4: uint8(42),
   7267 			5: uint8(46),
   7268 			6: uint8(45),
   7269 			7: uint8(196),
   7270 			8: uint8(205),
   7271 		},
   7272 		1: {
   7273 			0: uint8(43),
   7274 			1: uint8(97),
   7275 			2: uint8(183),
   7276 			3: uint8(117),
   7277 			4: uint8(85),
   7278 			5: uint8(38),
   7279 			6: uint8(35),
   7280 			7: uint8(179),
   7281 			8: uint8(61),
   7282 		},
   7283 		2: {
   7284 			0: uint8(39),
   7285 			1: uint8(53),
   7286 			2: uint8(200),
   7287 			3: uint8(87),
   7288 			4: uint8(26),
   7289 			5: uint8(21),
   7290 			6: uint8(43),
   7291 			7: uint8(232),
   7292 			8: uint8(171),
   7293 		},
   7294 		3: {
   7295 			0: uint8(56),
   7296 			1: uint8(34),
   7297 			2: uint8(51),
   7298 			3: uint8(104),
   7299 			4: uint8(114),
   7300 			5: uint8(102),
   7301 			6: uint8(29),
   7302 			7: uint8(93),
   7303 			8: uint8(77),
   7304 		},
   7305 		4: {
   7306 			0: uint8(39),
   7307 			1: uint8(28),
   7308 			2: uint8(85),
   7309 			3: uint8(171),
   7310 			4: uint8(58),
   7311 			5: uint8(165),
   7312 			6: uint8(90),
   7313 			7: uint8(98),
   7314 			8: uint8(64),
   7315 		},
   7316 		5: {
   7317 			0: uint8(34),
   7318 			1: uint8(22),
   7319 			2: uint8(116),
   7320 			3: uint8(206),
   7321 			4: uint8(23),
   7322 			5: uint8(34),
   7323 			6: uint8(43),
   7324 			7: uint8(166),
   7325 			8: uint8(73),
   7326 		},
   7327 		6: {
   7328 			0: uint8(107),
   7329 			1: uint8(54),
   7330 			2: uint8(32),
   7331 			3: uint8(26),
   7332 			4: uint8(51),
   7333 			5: uint8(1),
   7334 			6: uint8(81),
   7335 			7: uint8(43),
   7336 			8: uint8(31),
   7337 		},
   7338 		7: {
   7339 			0: uint8(68),
   7340 			1: uint8(25),
   7341 			2: uint8(106),
   7342 			3: uint8(22),
   7343 			4: uint8(64),
   7344 			5: uint8(171),
   7345 			6: uint8(36),
   7346 			7: uint8(225),
   7347 			8: uint8(114),
   7348 		},
   7349 		8: {
   7350 			0: uint8(34),
   7351 			1: uint8(19),
   7352 			2: uint8(21),
   7353 			3: uint8(102),
   7354 			4: uint8(132),
   7355 			5: uint8(188),
   7356 			6: uint8(16),
   7357 			7: uint8(76),
   7358 			8: uint8(124),
   7359 		},
   7360 		9: {
   7361 			0: uint8(62),
   7362 			1: uint8(18),
   7363 			2: uint8(78),
   7364 			3: uint8(95),
   7365 			4: uint8(85),
   7366 			5: uint8(57),
   7367 			6: uint8(50),
   7368 			7: uint8(48),
   7369 			8: uint8(51),
   7370 		},
   7371 	},
   7372 	3: {
   7373 		0: {
   7374 			0: uint8(193),
   7375 			1: uint8(101),
   7376 			2: uint8(35),
   7377 			3: uint8(159),
   7378 			4: uint8(215),
   7379 			5: uint8(111),
   7380 			6: uint8(89),
   7381 			7: uint8(46),
   7382 			8: uint8(111),
   7383 		},
   7384 		1: {
   7385 			0: uint8(60),
   7386 			1: uint8(148),
   7387 			2: uint8(31),
   7388 			3: uint8(172),
   7389 			4: uint8(219),
   7390 			5: uint8(228),
   7391 			6: uint8(21),
   7392 			7: uint8(18),
   7393 			8: uint8(111),
   7394 		},
   7395 		2: {
   7396 			0: uint8(112),
   7397 			1: uint8(113),
   7398 			2: uint8(77),
   7399 			3: uint8(85),
   7400 			4: uint8(179),
   7401 			5: uint8(255),
   7402 			6: uint8(38),
   7403 			7: uint8(120),
   7404 			8: uint8(114),
   7405 		},
   7406 		3: {
   7407 			0: uint8(40),
   7408 			1: uint8(42),
   7409 			2: uint8(1),
   7410 			3: uint8(196),
   7411 			4: uint8(245),
   7412 			5: uint8(209),
   7413 			6: uint8(10),
   7414 			7: uint8(25),
   7415 			8: uint8(109),
   7416 		},
   7417 		4: {
   7418 			0: uint8(88),
   7419 			1: uint8(43),
   7420 			2: uint8(29),
   7421 			3: uint8(140),
   7422 			4: uint8(166),
   7423 			5: uint8(213),
   7424 			6: uint8(37),
   7425 			7: uint8(43),
   7426 			8: uint8(154),
   7427 		},
   7428 		5: {
   7429 			0: uint8(61),
   7430 			1: uint8(63),
   7431 			2: uint8(30),
   7432 			3: uint8(155),
   7433 			4: uint8(67),
   7434 			5: uint8(45),
   7435 			6: uint8(68),
   7436 			7: uint8(1),
   7437 			8: uint8(209),
   7438 		},
   7439 		6: {
   7440 			0: uint8(100),
   7441 			1: uint8(80),
   7442 			2: uint8(8),
   7443 			3: uint8(43),
   7444 			4: uint8(154),
   7445 			5: uint8(1),
   7446 			6: uint8(51),
   7447 			7: uint8(26),
   7448 			8: uint8(71),
   7449 		},
   7450 		7: {
   7451 			0: uint8(142),
   7452 			1: uint8(78),
   7453 			2: uint8(78),
   7454 			3: uint8(16),
   7455 			4: uint8(255),
   7456 			5: uint8(128),
   7457 			6: uint8(34),
   7458 			7: uint8(197),
   7459 			8: uint8(171),
   7460 		},
   7461 		8: {
   7462 			0: uint8(41),
   7463 			1: uint8(40),
   7464 			2: uint8(5),
   7465 			3: uint8(102),
   7466 			4: uint8(211),
   7467 			5: uint8(183),
   7468 			6: uint8(4),
   7469 			7: uint8(1),
   7470 			8: uint8(221),
   7471 		},
   7472 		9: {
   7473 			0: uint8(51),
   7474 			1: uint8(50),
   7475 			2: uint8(17),
   7476 			3: uint8(168),
   7477 			4: uint8(209),
   7478 			5: uint8(192),
   7479 			6: uint8(23),
   7480 			7: uint8(25),
   7481 			8: uint8(82),
   7482 		},
   7483 	},
   7484 	4: {
   7485 		0: {
   7486 			0: uint8(138),
   7487 			1: uint8(31),
   7488 			2: uint8(36),
   7489 			3: uint8(171),
   7490 			4: uint8(27),
   7491 			5: uint8(166),
   7492 			6: uint8(38),
   7493 			7: uint8(44),
   7494 			8: uint8(229),
   7495 		},
   7496 		1: {
   7497 			0: uint8(67),
   7498 			1: uint8(87),
   7499 			2: uint8(58),
   7500 			3: uint8(169),
   7501 			4: uint8(82),
   7502 			5: uint8(115),
   7503 			6: uint8(26),
   7504 			7: uint8(59),
   7505 			8: uint8(179),
   7506 		},
   7507 		2: {
   7508 			0: uint8(63),
   7509 			1: uint8(59),
   7510 			2: uint8(90),
   7511 			3: uint8(180),
   7512 			4: uint8(59),
   7513 			5: uint8(166),
   7514 			6: uint8(93),
   7515 			7: uint8(73),
   7516 			8: uint8(154),
   7517 		},
   7518 		3: {
   7519 			0: uint8(40),
   7520 			1: uint8(40),
   7521 			2: uint8(21),
   7522 			3: uint8(116),
   7523 			4: uint8(143),
   7524 			5: uint8(209),
   7525 			6: uint8(34),
   7526 			7: uint8(39),
   7527 			8: uint8(175),
   7528 		},
   7529 		4: {
   7530 			0: uint8(47),
   7531 			1: uint8(15),
   7532 			2: uint8(16),
   7533 			3: uint8(183),
   7534 			4: uint8(34),
   7535 			5: uint8(223),
   7536 			6: uint8(49),
   7537 			7: uint8(45),
   7538 			8: uint8(183),
   7539 		},
   7540 		5: {
   7541 			0: uint8(46),
   7542 			1: uint8(17),
   7543 			2: uint8(33),
   7544 			3: uint8(183),
   7545 			4: uint8(6),
   7546 			5: uint8(98),
   7547 			6: uint8(15),
   7548 			7: uint8(32),
   7549 			8: uint8(183),
   7550 		},
   7551 		6: {
   7552 			0: uint8(57),
   7553 			1: uint8(46),
   7554 			2: uint8(22),
   7555 			3: uint8(24),
   7556 			4: uint8(128),
   7557 			5: uint8(1),
   7558 			6: uint8(54),
   7559 			7: uint8(17),
   7560 			8: uint8(37),
   7561 		},
   7562 		7: {
   7563 			0: uint8(65),
   7564 			1: uint8(32),
   7565 			2: uint8(73),
   7566 			3: uint8(115),
   7567 			4: uint8(28),
   7568 			5: uint8(128),
   7569 			6: uint8(23),
   7570 			7: uint8(128),
   7571 			8: uint8(205),
   7572 		},
   7573 		8: {
   7574 			0: uint8(40),
   7575 			1: uint8(3),
   7576 			2: uint8(9),
   7577 			3: uint8(115),
   7578 			4: uint8(51),
   7579 			5: uint8(192),
   7580 			6: uint8(18),
   7581 			7: uint8(6),
   7582 			8: uint8(223),
   7583 		},
   7584 		9: {
   7585 			0: uint8(87),
   7586 			1: uint8(37),
   7587 			2: uint8(9),
   7588 			3: uint8(115),
   7589 			4: uint8(59),
   7590 			5: uint8(77),
   7591 			6: uint8(64),
   7592 			7: uint8(21),
   7593 			8: uint8(47),
   7594 		},
   7595 	},
   7596 	5: {
   7597 		0: {
   7598 			0: uint8(104),
   7599 			1: uint8(55),
   7600 			2: uint8(44),
   7601 			3: uint8(218),
   7602 			4: uint8(9),
   7603 			5: uint8(54),
   7604 			6: uint8(53),
   7605 			7: uint8(130),
   7606 			8: uint8(226),
   7607 		},
   7608 		1: {
   7609 			0: uint8(64),
   7610 			1: uint8(90),
   7611 			2: uint8(70),
   7612 			3: uint8(205),
   7613 			4: uint8(40),
   7614 			5: uint8(41),
   7615 			6: uint8(23),
   7616 			7: uint8(26),
   7617 			8: uint8(57),
   7618 		},
   7619 		2: {
   7620 			0: uint8(54),
   7621 			1: uint8(57),
   7622 			2: uint8(112),
   7623 			3: uint8(184),
   7624 			4: uint8(5),
   7625 			5: uint8(41),
   7626 			6: uint8(38),
   7627 			7: uint8(166),
   7628 			8: uint8(213),
   7629 		},
   7630 		3: {
   7631 			0: uint8(30),
   7632 			1: uint8(34),
   7633 			2: uint8(26),
   7634 			3: uint8(133),
   7635 			4: uint8(152),
   7636 			5: uint8(116),
   7637 			6: uint8(10),
   7638 			7: uint8(32),
   7639 			8: uint8(134),
   7640 		},
   7641 		4: {
   7642 			0: uint8(39),
   7643 			1: uint8(19),
   7644 			2: uint8(53),
   7645 			3: uint8(221),
   7646 			4: uint8(26),
   7647 			5: uint8(114),
   7648 			6: uint8(32),
   7649 			7: uint8(73),
   7650 			8: uint8(255),
   7651 		},
   7652 		5: {
   7653 			0: uint8(31),
   7654 			1: uint8(9),
   7655 			2: uint8(65),
   7656 			3: uint8(234),
   7657 			4: uint8(2),
   7658 			5: uint8(15),
   7659 			6: uint8(1),
   7660 			7: uint8(118),
   7661 			8: uint8(73),
   7662 		},
   7663 		6: {
   7664 			0: uint8(75),
   7665 			1: uint8(32),
   7666 			2: uint8(12),
   7667 			3: uint8(51),
   7668 			4: uint8(192),
   7669 			5: uint8(255),
   7670 			6: uint8(160),
   7671 			7: uint8(43),
   7672 			8: uint8(51),
   7673 		},
   7674 		7: {
   7675 			0: uint8(88),
   7676 			1: uint8(31),
   7677 			2: uint8(35),
   7678 			3: uint8(67),
   7679 			4: uint8(102),
   7680 			5: uint8(85),
   7681 			6: uint8(55),
   7682 			7: uint8(186),
   7683 			8: uint8(85),
   7684 		},
   7685 		8: {
   7686 			0: uint8(56),
   7687 			1: uint8(21),
   7688 			2: uint8(23),
   7689 			3: uint8(111),
   7690 			4: uint8(59),
   7691 			5: uint8(205),
   7692 			6: uint8(45),
   7693 			7: uint8(37),
   7694 			8: uint8(192),
   7695 		},
   7696 		9: {
   7697 			0: uint8(55),
   7698 			1: uint8(38),
   7699 			2: uint8(70),
   7700 			3: uint8(124),
   7701 			4: uint8(73),
   7702 			5: uint8(102),
   7703 			6: uint8(1),
   7704 			7: uint8(34),
   7705 			8: uint8(98),
   7706 		},
   7707 	},
   7708 	6: {
   7709 		0: {
   7710 			0: uint8(125),
   7711 			1: uint8(98),
   7712 			2: uint8(42),
   7713 			3: uint8(88),
   7714 			4: uint8(104),
   7715 			5: uint8(85),
   7716 			6: uint8(117),
   7717 			7: uint8(175),
   7718 			8: uint8(82),
   7719 		},
   7720 		1: {
   7721 			0: uint8(95),
   7722 			1: uint8(84),
   7723 			2: uint8(53),
   7724 			3: uint8(89),
   7725 			4: uint8(128),
   7726 			5: uint8(100),
   7727 			6: uint8(113),
   7728 			7: uint8(101),
   7729 			8: uint8(45),
   7730 		},
   7731 		2: {
   7732 			0: uint8(75),
   7733 			1: uint8(79),
   7734 			2: uint8(123),
   7735 			3: uint8(47),
   7736 			4: uint8(51),
   7737 			5: uint8(128),
   7738 			6: uint8(81),
   7739 			7: uint8(171),
   7740 			8: uint8(1),
   7741 		},
   7742 		3: {
   7743 			0: uint8(57),
   7744 			1: uint8(17),
   7745 			2: uint8(5),
   7746 			3: uint8(71),
   7747 			4: uint8(102),
   7748 			5: uint8(57),
   7749 			6: uint8(53),
   7750 			7: uint8(41),
   7751 			8: uint8(49),
   7752 		},
   7753 		4: {
   7754 			0: uint8(38),
   7755 			1: uint8(33),
   7756 			2: uint8(13),
   7757 			3: uint8(121),
   7758 			4: uint8(57),
   7759 			5: uint8(73),
   7760 			6: uint8(26),
   7761 			7: uint8(1),
   7762 			8: uint8(85),
   7763 		},
   7764 		5: {
   7765 			0: uint8(41),
   7766 			1: uint8(10),
   7767 			2: uint8(67),
   7768 			3: uint8(138),
   7769 			4: uint8(77),
   7770 			5: uint8(110),
   7771 			6: uint8(90),
   7772 			7: uint8(47),
   7773 			8: uint8(114),
   7774 		},
   7775 		6: {
   7776 			0: uint8(115),
   7777 			1: uint8(21),
   7778 			2: uint8(2),
   7779 			3: uint8(10),
   7780 			4: uint8(102),
   7781 			5: uint8(255),
   7782 			6: uint8(166),
   7783 			7: uint8(23),
   7784 			8: uint8(6),
   7785 		},
   7786 		7: {
   7787 			0: uint8(101),
   7788 			1: uint8(29),
   7789 			2: uint8(16),
   7790 			3: uint8(10),
   7791 			4: uint8(85),
   7792 			5: uint8(128),
   7793 			6: uint8(101),
   7794 			7: uint8(196),
   7795 			8: uint8(26),
   7796 		},
   7797 		8: {
   7798 			0: uint8(57),
   7799 			1: uint8(18),
   7800 			2: uint8(10),
   7801 			3: uint8(102),
   7802 			4: uint8(102),
   7803 			5: uint8(213),
   7804 			6: uint8(34),
   7805 			7: uint8(20),
   7806 			8: uint8(43),
   7807 		},
   7808 		9: {
   7809 			0: uint8(117),
   7810 			1: uint8(20),
   7811 			2: uint8(15),
   7812 			3: uint8(36),
   7813 			4: uint8(163),
   7814 			5: uint8(128),
   7815 			6: uint8(68),
   7816 			7: uint8(1),
   7817 			8: uint8(26),
   7818 		},
   7819 	},
   7820 	7: {
   7821 		0: {
   7822 			0: uint8(102),
   7823 			1: uint8(61),
   7824 			2: uint8(71),
   7825 			3: uint8(37),
   7826 			4: uint8(34),
   7827 			5: uint8(53),
   7828 			6: uint8(31),
   7829 			7: uint8(243),
   7830 			8: uint8(192),
   7831 		},
   7832 		1: {
   7833 			0: uint8(69),
   7834 			1: uint8(60),
   7835 			2: uint8(71),
   7836 			3: uint8(38),
   7837 			4: uint8(73),
   7838 			5: uint8(119),
   7839 			6: uint8(28),
   7840 			7: uint8(222),
   7841 			8: uint8(37),
   7842 		},
   7843 		2: {
   7844 			0: uint8(68),
   7845 			1: uint8(45),
   7846 			2: uint8(128),
   7847 			3: uint8(34),
   7848 			4: uint8(1),
   7849 			5: uint8(47),
   7850 			6: uint8(11),
   7851 			7: uint8(245),
   7852 			8: uint8(171),
   7853 		},
   7854 		3: {
   7855 			0: uint8(62),
   7856 			1: uint8(17),
   7857 			2: uint8(19),
   7858 			3: uint8(70),
   7859 			4: uint8(146),
   7860 			5: uint8(85),
   7861 			6: uint8(55),
   7862 			7: uint8(62),
   7863 			8: uint8(70),
   7864 		},
   7865 		4: {
   7866 			0: uint8(37),
   7867 			1: uint8(43),
   7868 			2: uint8(37),
   7869 			3: uint8(154),
   7870 			4: uint8(100),
   7871 			5: uint8(163),
   7872 			6: uint8(85),
   7873 			7: uint8(160),
   7874 			8: uint8(1),
   7875 		},
   7876 		5: {
   7877 			0: uint8(63),
   7878 			1: uint8(9),
   7879 			2: uint8(92),
   7880 			3: uint8(136),
   7881 			4: uint8(28),
   7882 			5: uint8(64),
   7883 			6: uint8(32),
   7884 			7: uint8(201),
   7885 			8: uint8(85),
   7886 		},
   7887 		6: {
   7888 			0: uint8(75),
   7889 			1: uint8(15),
   7890 			2: uint8(9),
   7891 			3: uint8(9),
   7892 			4: uint8(64),
   7893 			5: uint8(255),
   7894 			6: uint8(184),
   7895 			7: uint8(119),
   7896 			8: uint8(16),
   7897 		},
   7898 		7: {
   7899 			0: uint8(86),
   7900 			1: uint8(6),
   7901 			2: uint8(28),
   7902 			3: uint8(5),
   7903 			4: uint8(64),
   7904 			5: uint8(255),
   7905 			6: uint8(25),
   7906 			7: uint8(248),
   7907 			8: uint8(1),
   7908 		},
   7909 		8: {
   7910 			0: uint8(56),
   7911 			1: uint8(8),
   7912 			2: uint8(17),
   7913 			3: uint8(132),
   7914 			4: uint8(137),
   7915 			5: uint8(255),
   7916 			6: uint8(55),
   7917 			7: uint8(116),
   7918 			8: uint8(128),
   7919 		},
   7920 		9: {
   7921 			0: uint8(58),
   7922 			1: uint8(15),
   7923 			2: uint8(20),
   7924 			3: uint8(82),
   7925 			4: uint8(135),
   7926 			5: uint8(57),
   7927 			6: uint8(26),
   7928 			7: uint8(121),
   7929 			8: uint8(40),
   7930 		},
   7931 	},
   7932 	8: {
   7933 		0: {
   7934 			0: uint8(164),
   7935 			1: uint8(50),
   7936 			2: uint8(31),
   7937 			3: uint8(137),
   7938 			4: uint8(154),
   7939 			5: uint8(133),
   7940 			6: uint8(25),
   7941 			7: uint8(35),
   7942 			8: uint8(218),
   7943 		},
   7944 		1: {
   7945 			0: uint8(51),
   7946 			1: uint8(103),
   7947 			2: uint8(44),
   7948 			3: uint8(131),
   7949 			4: uint8(131),
   7950 			5: uint8(123),
   7951 			6: uint8(31),
   7952 			7: uint8(6),
   7953 			8: uint8(158),
   7954 		},
   7955 		2: {
   7956 			0: uint8(86),
   7957 			1: uint8(40),
   7958 			2: uint8(64),
   7959 			3: uint8(135),
   7960 			4: uint8(148),
   7961 			5: uint8(224),
   7962 			6: uint8(45),
   7963 			7: uint8(183),
   7964 			8: uint8(128),
   7965 		},
   7966 		3: {
   7967 			0: uint8(22),
   7968 			1: uint8(26),
   7969 			2: uint8(17),
   7970 			3: uint8(131),
   7971 			4: uint8(240),
   7972 			5: uint8(154),
   7973 			6: uint8(14),
   7974 			7: uint8(1),
   7975 			8: uint8(209),
   7976 		},
   7977 		4: {
   7978 			0: uint8(45),
   7979 			1: uint8(16),
   7980 			2: uint8(21),
   7981 			3: uint8(91),
   7982 			4: uint8(64),
   7983 			5: uint8(222),
   7984 			6: uint8(7),
   7985 			7: uint8(1),
   7986 			8: uint8(197),
   7987 		},
   7988 		5: {
   7989 			0: uint8(56),
   7990 			1: uint8(21),
   7991 			2: uint8(39),
   7992 			3: uint8(155),
   7993 			4: uint8(60),
   7994 			5: uint8(138),
   7995 			6: uint8(23),
   7996 			7: uint8(102),
   7997 			8: uint8(213),
   7998 		},
   7999 		6: {
   8000 			0: uint8(83),
   8001 			1: uint8(12),
   8002 			2: uint8(13),
   8003 			3: uint8(54),
   8004 			4: uint8(192),
   8005 			5: uint8(255),
   8006 			6: uint8(68),
   8007 			7: uint8(47),
   8008 			8: uint8(28),
   8009 		},
   8010 		7: {
   8011 			0: uint8(85),
   8012 			1: uint8(26),
   8013 			2: uint8(85),
   8014 			3: uint8(85),
   8015 			4: uint8(128),
   8016 			5: uint8(128),
   8017 			6: uint8(32),
   8018 			7: uint8(146),
   8019 			8: uint8(171),
   8020 		},
   8021 		8: {
   8022 			0: uint8(18),
   8023 			1: uint8(11),
   8024 			2: uint8(7),
   8025 			3: uint8(63),
   8026 			4: uint8(144),
   8027 			5: uint8(171),
   8028 			6: uint8(4),
   8029 			7: uint8(4),
   8030 			8: uint8(246),
   8031 		},
   8032 		9: {
   8033 			0: uint8(35),
   8034 			1: uint8(27),
   8035 			2: uint8(10),
   8036 			3: uint8(146),
   8037 			4: uint8(174),
   8038 			5: uint8(171),
   8039 			6: uint8(12),
   8040 			7: uint8(26),
   8041 			8: uint8(128),
   8042 		},
   8043 	},
   8044 	9: {
   8045 		0: {
   8046 			0: uint8(190),
   8047 			1: uint8(80),
   8048 			2: uint8(35),
   8049 			3: uint8(99),
   8050 			4: uint8(180),
   8051 			5: uint8(80),
   8052 			6: uint8(126),
   8053 			7: uint8(54),
   8054 			8: uint8(45),
   8055 		},
   8056 		1: {
   8057 			0: uint8(85),
   8058 			1: uint8(126),
   8059 			2: uint8(47),
   8060 			3: uint8(87),
   8061 			4: uint8(176),
   8062 			5: uint8(51),
   8063 			6: uint8(41),
   8064 			7: uint8(20),
   8065 			8: uint8(32),
   8066 		},
   8067 		2: {
   8068 			0: uint8(101),
   8069 			1: uint8(75),
   8070 			2: uint8(128),
   8071 			3: uint8(139),
   8072 			4: uint8(118),
   8073 			5: uint8(146),
   8074 			6: uint8(116),
   8075 			7: uint8(128),
   8076 			8: uint8(85),
   8077 		},
   8078 		3: {
   8079 			0: uint8(56),
   8080 			1: uint8(41),
   8081 			2: uint8(15),
   8082 			3: uint8(176),
   8083 			4: uint8(236),
   8084 			5: uint8(85),
   8085 			6: uint8(37),
   8086 			7: uint8(9),
   8087 			8: uint8(62),
   8088 		},
   8089 		4: {
   8090 			0: uint8(71),
   8091 			1: uint8(30),
   8092 			2: uint8(17),
   8093 			3: uint8(119),
   8094 			4: uint8(118),
   8095 			5: uint8(255),
   8096 			6: uint8(17),
   8097 			7: uint8(18),
   8098 			8: uint8(138),
   8099 		},
   8100 		5: {
   8101 			0: uint8(101),
   8102 			1: uint8(38),
   8103 			2: uint8(60),
   8104 			3: uint8(138),
   8105 			4: uint8(55),
   8106 			5: uint8(70),
   8107 			6: uint8(43),
   8108 			7: uint8(26),
   8109 			8: uint8(142),
   8110 		},
   8111 		6: {
   8112 			0: uint8(146),
   8113 			1: uint8(36),
   8114 			2: uint8(19),
   8115 			3: uint8(30),
   8116 			4: uint8(171),
   8117 			5: uint8(255),
   8118 			6: uint8(97),
   8119 			7: uint8(27),
   8120 			8: uint8(20),
   8121 		},
   8122 		7: {
   8123 			0: uint8(138),
   8124 			1: uint8(45),
   8125 			2: uint8(61),
   8126 			3: uint8(62),
   8127 			4: uint8(219),
   8128 			5: uint8(1),
   8129 			6: uint8(81),
   8130 			7: uint8(188),
   8131 			8: uint8(64),
   8132 		},
   8133 		8: {
   8134 			0: uint8(32),
   8135 			1: uint8(41),
   8136 			2: uint8(20),
   8137 			3: uint8(117),
   8138 			4: uint8(151),
   8139 			5: uint8(142),
   8140 			6: uint8(20),
   8141 			7: uint8(21),
   8142 			8: uint8(163),
   8143 		},
   8144 		9: {
   8145 			0: uint8(112),
   8146 			1: uint8(19),
   8147 			2: uint8(12),
   8148 			3: uint8(61),
   8149 			4: uint8(195),
   8150 			5: uint8(128),
   8151 			6: uint8(48),
   8152 			7: uint8(4),
   8153 			8: uint8(24),
   8154 		},
   8155 	},
   8156 }
   8157 
   8158 func VP8ResetProba(tls *libc.TLS, proba uintptr) {
   8159 	libc.Xmemset(tls, proba, libc.Int32FromUint32(255), uint64(3))
   8160 	// proba->bands[][] is initialized later
   8161 }
   8162 
   8163 func ParseIntraMode(tls *libc.TLS, br2 uintptr, dec uintptr, mb_x int32) {
   8164 	bp := tls.Alloc(16)
   8165 	defer tls.Free(16)
   8166 	var bit, i, pos, shift, x1, y, ymode, ymode1, v1, v14, v16, v22, v24, v30, v32, v6, v8 int32
   8167 	var bits bit_t
   8168 	var block, left, modes, prob1, top, v10, v11, v18, v19, v2, v3 uintptr
   8169 	var range1, split, value range_t
   8170 	var v12, v20, v4 uint64_t
   8171 	var _ /* in_bits at bp+0 */ lbit_t
   8172 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
   8173 	top = (*VP8Decoder)(unsafe.Pointer(dec)).Fintra_t + uintptr(int32(4)*mb_x)
   8174 	left = dec + 2816
   8175 	block = (*VP8Decoder)(unsafe.Pointer(dec)).Fmb_data + uintptr(mb_x)*800
   8176 	// Note: we don't save segment map (yet), as we don't expect
   8177 	// to decode more than 1 keyframe.
   8178 	if (*VP8Decoder)(unsafe.Pointer(dec)).Fsegment_hdr.Fupdate_map != 0 {
   8179 		// Hardcoded tree parsing
   8180 		v2 = br2
   8181 		range1 = (*VP8BitReader)(unsafe.Pointer(v2)).Frange1
   8182 		if (*VP8BitReader)(unsafe.Pointer(v2)).Fbits < libc.Int32FromInt32(0) {
   8183 			v3 = v2
   8184 			if (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf < (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf_max {
   8185 				libc.Xmemcpy(tls, bp, (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf, uint64(8))
   8186 				**(**uintptr)(__ccgo_up(v3 + 16)) += uintptr(libc.Int32FromInt32(BITS) >> libc.Int32FromInt32(3))
   8187 				v4 = libc.X__builtin_bswap64(tls, **(**lbit_t)(__ccgo_up(bp)))
   8188 				goto _5
   8189 			_5:
   8190 				bits = v4
   8191 				bits = bits >> uint64(libc.Int32FromInt32(64)-libc.Int32FromInt32(BITS))
   8192 				(*VP8BitReader)(unsafe.Pointer(v3)).Fvalue = bits | (*VP8BitReader)(unsafe.Pointer(v3)).Fvalue<<libc.Int32FromInt32(BITS)
   8193 				**(**int32)(__ccgo_up(v3 + 12)) += int32(BITS)
   8194 			} else {
   8195 				VP8LoadFinalBytes(tls, v3)
   8196 			}
   8197 		}
   8198 		pos = (*VP8BitReader)(unsafe.Pointer(v2)).Fbits
   8199 		split = range1 * uint32(int32(**(**uint8_t)(__ccgo_up(dec + 1192)))) >> int32(8)
   8200 		value = uint32((*VP8BitReader)(unsafe.Pointer(v2)).Fvalue >> pos)
   8201 		bit = libc.BoolInt32(value > split)
   8202 		if bit != 0 {
   8203 			range1 = range1 - split
   8204 			**(**bit_t)(__ccgo_up(v2)) -= uint64(split+libc.Uint32FromInt32(1)) << pos
   8205 		} else {
   8206 			range1 = split + uint32(1)
   8207 		}
   8208 		v6 = int32(31) ^ libc.X__builtin_clz(tls, range1)
   8209 		goto _7
   8210 	_7:
   8211 		shift = int32(7) ^ v6
   8212 		range1 = range1 << uint32(shift)
   8213 		**(**int32)(__ccgo_up(v2 + 12)) -= shift
   8214 		(*VP8BitReader)(unsafe.Pointer(v2)).Frange1 = range1 - uint32(1)
   8215 		v8 = bit
   8216 		goto _9
   8217 	_9:
   8218 		if !(v8 != 0) {
   8219 			v10 = br2
   8220 			range1 = (*VP8BitReader)(unsafe.Pointer(v10)).Frange1
   8221 			if (*VP8BitReader)(unsafe.Pointer(v10)).Fbits < libc.Int32FromInt32(0) {
   8222 				v11 = v10
   8223 				if (*VP8BitReader)(unsafe.Pointer(v11)).Fbuf < (*VP8BitReader)(unsafe.Pointer(v11)).Fbuf_max {
   8224 					libc.Xmemcpy(tls, bp, (*VP8BitReader)(unsafe.Pointer(v11)).Fbuf, uint64(8))
   8225 					**(**uintptr)(__ccgo_up(v11 + 16)) += uintptr(libc.Int32FromInt32(BITS) >> libc.Int32FromInt32(3))
   8226 					v12 = libc.X__builtin_bswap64(tls, **(**lbit_t)(__ccgo_up(bp)))
   8227 					goto _13
   8228 				_13:
   8229 					bits = v12
   8230 					bits = bits >> uint64(libc.Int32FromInt32(64)-libc.Int32FromInt32(BITS))
   8231 					(*VP8BitReader)(unsafe.Pointer(v11)).Fvalue = bits | (*VP8BitReader)(unsafe.Pointer(v11)).Fvalue<<libc.Int32FromInt32(BITS)
   8232 					**(**int32)(__ccgo_up(v11 + 12)) += int32(BITS)
   8233 				} else {
   8234 					VP8LoadFinalBytes(tls, v11)
   8235 				}
   8236 			}
   8237 			pos = (*VP8BitReader)(unsafe.Pointer(v10)).Fbits
   8238 			split = range1 * uint32(int32(**(**uint8_t)(__ccgo_up(dec + 1192 + 1)))) >> int32(8)
   8239 			value = uint32((*VP8BitReader)(unsafe.Pointer(v10)).Fvalue >> pos)
   8240 			bit = libc.BoolInt32(value > split)
   8241 			if bit != 0 {
   8242 				range1 = range1 - split
   8243 				**(**bit_t)(__ccgo_up(v10)) -= uint64(split+libc.Uint32FromInt32(1)) << pos
   8244 			} else {
   8245 				range1 = split + uint32(1)
   8246 			}
   8247 			v14 = int32(31) ^ libc.X__builtin_clz(tls, range1)
   8248 			goto _15
   8249 		_15:
   8250 			shift = int32(7) ^ v14
   8251 			range1 = range1 << uint32(shift)
   8252 			**(**int32)(__ccgo_up(v10 + 12)) -= shift
   8253 			(*VP8BitReader)(unsafe.Pointer(v10)).Frange1 = range1 - uint32(1)
   8254 			v16 = bit
   8255 			goto _17
   8256 		_17:
   8257 			v1 = v16
   8258 		} else {
   8259 			v18 = br2
   8260 			range1 = (*VP8BitReader)(unsafe.Pointer(v18)).Frange1
   8261 			if (*VP8BitReader)(unsafe.Pointer(v18)).Fbits < libc.Int32FromInt32(0) {
   8262 				v19 = v18
   8263 				if (*VP8BitReader)(unsafe.Pointer(v19)).Fbuf < (*VP8BitReader)(unsafe.Pointer(v19)).Fbuf_max {
   8264 					libc.Xmemcpy(tls, bp, (*VP8BitReader)(unsafe.Pointer(v19)).Fbuf, uint64(8))
   8265 					**(**uintptr)(__ccgo_up(v19 + 16)) += uintptr(libc.Int32FromInt32(BITS) >> libc.Int32FromInt32(3))
   8266 					v20 = libc.X__builtin_bswap64(tls, **(**lbit_t)(__ccgo_up(bp)))
   8267 					goto _21
   8268 				_21:
   8269 					bits = v20
   8270 					bits = bits >> uint64(libc.Int32FromInt32(64)-libc.Int32FromInt32(BITS))
   8271 					(*VP8BitReader)(unsafe.Pointer(v19)).Fvalue = bits | (*VP8BitReader)(unsafe.Pointer(v19)).Fvalue<<libc.Int32FromInt32(BITS)
   8272 					**(**int32)(__ccgo_up(v19 + 12)) += int32(BITS)
   8273 				} else {
   8274 					VP8LoadFinalBytes(tls, v19)
   8275 				}
   8276 			}
   8277 			pos = (*VP8BitReader)(unsafe.Pointer(v18)).Fbits
   8278 			split = range1 * uint32(int32(**(**uint8_t)(__ccgo_up(dec + 1192 + 2)))) >> int32(8)
   8279 			value = uint32((*VP8BitReader)(unsafe.Pointer(v18)).Fvalue >> pos)
   8280 			bit = libc.BoolInt32(value > split)
   8281 			if bit != 0 {
   8282 				range1 = range1 - split
   8283 				**(**bit_t)(__ccgo_up(v18)) -= uint64(split+libc.Uint32FromInt32(1)) << pos
   8284 			} else {
   8285 				range1 = split + uint32(1)
   8286 			}
   8287 			v22 = int32(31) ^ libc.X__builtin_clz(tls, range1)
   8288 			goto _23
   8289 		_23:
   8290 			shift = int32(7) ^ v22
   8291 			range1 = range1 << uint32(shift)
   8292 			**(**int32)(__ccgo_up(v18 + 12)) -= shift
   8293 			(*VP8BitReader)(unsafe.Pointer(v18)).Frange1 = range1 - uint32(1)
   8294 			v24 = bit
   8295 			goto _25
   8296 		_25:
   8297 			v1 = v24 + int32(2)
   8298 		}
   8299 		(*VP8MBData)(unsafe.Pointer(block)).Fsegment = uint8(v1)
   8300 	} else {
   8301 		(*VP8MBData)(unsafe.Pointer(block)).Fsegment = uint8(0) // default for intra
   8302 	}
   8303 	if (*VP8Decoder)(unsafe.Pointer(dec)).Fuse_skip_proba != 0 {
   8304 		v2 = br2
   8305 		range1 = (*VP8BitReader)(unsafe.Pointer(v2)).Frange1
   8306 		if (*VP8BitReader)(unsafe.Pointer(v2)).Fbits < libc.Int32FromInt32(0) {
   8307 			v3 = v2
   8308 			if (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf < (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf_max {
   8309 				libc.Xmemcpy(tls, bp, (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf, uint64(8))
   8310 				**(**uintptr)(__ccgo_up(v3 + 16)) += uintptr(libc.Int32FromInt32(BITS) >> libc.Int32FromInt32(3))
   8311 				v4 = libc.X__builtin_bswap64(tls, **(**lbit_t)(__ccgo_up(bp)))
   8312 				goto _29
   8313 			_29:
   8314 				bits = v4
   8315 				bits = bits >> uint64(libc.Int32FromInt32(64)-libc.Int32FromInt32(BITS))
   8316 				(*VP8BitReader)(unsafe.Pointer(v3)).Fvalue = bits | (*VP8BitReader)(unsafe.Pointer(v3)).Fvalue<<libc.Int32FromInt32(BITS)
   8317 				**(**int32)(__ccgo_up(v3 + 12)) += int32(BITS)
   8318 			} else {
   8319 				VP8LoadFinalBytes(tls, v3)
   8320 			}
   8321 		}
   8322 		pos = (*VP8BitReader)(unsafe.Pointer(v2)).Fbits
   8323 		split = range1 * uint32(int32((*VP8Decoder)(unsafe.Pointer(dec)).Fskip_p)) >> int32(8)
   8324 		value = uint32((*VP8BitReader)(unsafe.Pointer(v2)).Fvalue >> pos)
   8325 		bit = libc.BoolInt32(value > split)
   8326 		if bit != 0 {
   8327 			range1 = range1 - split
   8328 			**(**bit_t)(__ccgo_up(v2)) -= uint64(split+libc.Uint32FromInt32(1)) << pos
   8329 		} else {
   8330 			range1 = split + uint32(1)
   8331 		}
   8332 		v1 = int32(31) ^ libc.X__builtin_clz(tls, range1)
   8333 		goto _31
   8334 	_31:
   8335 		shift = int32(7) ^ v1
   8336 		range1 = range1 << uint32(shift)
   8337 		**(**int32)(__ccgo_up(v2 + 12)) -= shift
   8338 		(*VP8BitReader)(unsafe.Pointer(v2)).Frange1 = range1 - uint32(1)
   8339 		v6 = bit
   8340 		goto _33
   8341 	_33:
   8342 		(*VP8MBData)(unsafe.Pointer(block)).Fskip = uint8(v6)
   8343 	}
   8344 	v2 = br2
   8345 	range1 = (*VP8BitReader)(unsafe.Pointer(v2)).Frange1
   8346 	if (*VP8BitReader)(unsafe.Pointer(v2)).Fbits < libc.Int32FromInt32(0) {
   8347 		v3 = v2
   8348 		if (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf < (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf_max {
   8349 			libc.Xmemcpy(tls, bp, (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf, uint64(8))
   8350 			**(**uintptr)(__ccgo_up(v3 + 16)) += uintptr(libc.Int32FromInt32(BITS) >> libc.Int32FromInt32(3))
   8351 			v4 = libc.X__builtin_bswap64(tls, **(**lbit_t)(__ccgo_up(bp)))
   8352 			goto _37
   8353 		_37:
   8354 			bits = v4
   8355 			bits = bits >> uint64(libc.Int32FromInt32(64)-libc.Int32FromInt32(BITS))
   8356 			(*VP8BitReader)(unsafe.Pointer(v3)).Fvalue = bits | (*VP8BitReader)(unsafe.Pointer(v3)).Fvalue<<libc.Int32FromInt32(BITS)
   8357 			**(**int32)(__ccgo_up(v3 + 12)) += int32(BITS)
   8358 		} else {
   8359 			VP8LoadFinalBytes(tls, v3)
   8360 		}
   8361 	}
   8362 	pos = (*VP8BitReader)(unsafe.Pointer(v2)).Fbits
   8363 	split = range1 * uint32(int32(145)) >> int32(8)
   8364 	value = uint32((*VP8BitReader)(unsafe.Pointer(v2)).Fvalue >> pos)
   8365 	bit = libc.BoolInt32(value > split)
   8366 	if bit != 0 {
   8367 		range1 = range1 - split
   8368 		**(**bit_t)(__ccgo_up(v2)) -= uint64(split+libc.Uint32FromInt32(1)) << pos
   8369 	} else {
   8370 		range1 = split + uint32(1)
   8371 	}
   8372 	v1 = int32(31) ^ libc.X__builtin_clz(tls, range1)
   8373 	goto _39
   8374 _39:
   8375 	shift = int32(7) ^ v1
   8376 	range1 = range1 << uint32(shift)
   8377 	**(**int32)(__ccgo_up(v2 + 12)) -= shift
   8378 	(*VP8BitReader)(unsafe.Pointer(v2)).Frange1 = range1 - uint32(1)
   8379 	v6 = bit
   8380 	goto _41
   8381 _41:
   8382 	(*VP8MBData)(unsafe.Pointer(block)).Fis_i4x4 = libc.BoolUint8(!(v6 != 0))
   8383 	if !((*VP8MBData)(unsafe.Pointer(block)).Fis_i4x4 != 0) {
   8384 		v2 = br2
   8385 		range1 = (*VP8BitReader)(unsafe.Pointer(v2)).Frange1
   8386 		if (*VP8BitReader)(unsafe.Pointer(v2)).Fbits < libc.Int32FromInt32(0) {
   8387 			v3 = v2
   8388 			if (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf < (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf_max {
   8389 				libc.Xmemcpy(tls, bp, (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf, uint64(8))
   8390 				**(**uintptr)(__ccgo_up(v3 + 16)) += uintptr(libc.Int32FromInt32(BITS) >> libc.Int32FromInt32(3))
   8391 				v4 = libc.X__builtin_bswap64(tls, **(**lbit_t)(__ccgo_up(bp)))
   8392 				goto _46
   8393 			_46:
   8394 				bits = v4
   8395 				bits = bits >> uint64(libc.Int32FromInt32(64)-libc.Int32FromInt32(BITS))
   8396 				(*VP8BitReader)(unsafe.Pointer(v3)).Fvalue = bits | (*VP8BitReader)(unsafe.Pointer(v3)).Fvalue<<libc.Int32FromInt32(BITS)
   8397 				**(**int32)(__ccgo_up(v3 + 12)) += int32(BITS)
   8398 			} else {
   8399 				VP8LoadFinalBytes(tls, v3)
   8400 			}
   8401 		}
   8402 		pos = (*VP8BitReader)(unsafe.Pointer(v2)).Fbits
   8403 		split = range1 * uint32(int32(156)) >> int32(8)
   8404 		value = uint32((*VP8BitReader)(unsafe.Pointer(v2)).Fvalue >> pos)
   8405 		bit = libc.BoolInt32(value > split)
   8406 		if bit != 0 {
   8407 			range1 = range1 - split
   8408 			**(**bit_t)(__ccgo_up(v2)) -= uint64(split+libc.Uint32FromInt32(1)) << pos
   8409 		} else {
   8410 			range1 = split + uint32(1)
   8411 		}
   8412 		v6 = int32(31) ^ libc.X__builtin_clz(tls, range1)
   8413 		goto _48
   8414 	_48:
   8415 		shift = int32(7) ^ v6
   8416 		range1 = range1 << uint32(shift)
   8417 		**(**int32)(__ccgo_up(v2 + 12)) -= shift
   8418 		(*VP8BitReader)(unsafe.Pointer(v2)).Frange1 = range1 - uint32(1)
   8419 		v8 = bit
   8420 		goto _50
   8421 	_50:
   8422 		if v8 != 0 {
   8423 			v10 = br2
   8424 			range1 = (*VP8BitReader)(unsafe.Pointer(v10)).Frange1
   8425 			if (*VP8BitReader)(unsafe.Pointer(v10)).Fbits < libc.Int32FromInt32(0) {
   8426 				v11 = v10
   8427 				if (*VP8BitReader)(unsafe.Pointer(v11)).Fbuf < (*VP8BitReader)(unsafe.Pointer(v11)).Fbuf_max {
   8428 					libc.Xmemcpy(tls, bp, (*VP8BitReader)(unsafe.Pointer(v11)).Fbuf, uint64(8))
   8429 					**(**uintptr)(__ccgo_up(v11 + 16)) += uintptr(libc.Int32FromInt32(BITS) >> libc.Int32FromInt32(3))
   8430 					v12 = libc.X__builtin_bswap64(tls, **(**lbit_t)(__ccgo_up(bp)))
   8431 					goto _55
   8432 				_55:
   8433 					bits = v12
   8434 					bits = bits >> uint64(libc.Int32FromInt32(64)-libc.Int32FromInt32(BITS))
   8435 					(*VP8BitReader)(unsafe.Pointer(v11)).Fvalue = bits | (*VP8BitReader)(unsafe.Pointer(v11)).Fvalue<<libc.Int32FromInt32(BITS)
   8436 					**(**int32)(__ccgo_up(v11 + 12)) += int32(BITS)
   8437 				} else {
   8438 					VP8LoadFinalBytes(tls, v11)
   8439 				}
   8440 			}
   8441 			pos = (*VP8BitReader)(unsafe.Pointer(v10)).Fbits
   8442 			split = range1 * uint32(int32(128)) >> int32(8)
   8443 			value = uint32((*VP8BitReader)(unsafe.Pointer(v10)).Fvalue >> pos)
   8444 			bit = libc.BoolInt32(value > split)
   8445 			if bit != 0 {
   8446 				range1 = range1 - split
   8447 				**(**bit_t)(__ccgo_up(v10)) -= uint64(split+libc.Uint32FromInt32(1)) << pos
   8448 			} else {
   8449 				range1 = split + uint32(1)
   8450 			}
   8451 			v16 = int32(31) ^ libc.X__builtin_clz(tls, range1)
   8452 			goto _57
   8453 		_57:
   8454 			shift = int32(7) ^ v16
   8455 			range1 = range1 << uint32(shift)
   8456 			**(**int32)(__ccgo_up(v10 + 12)) -= shift
   8457 			(*VP8BitReader)(unsafe.Pointer(v10)).Frange1 = range1 - uint32(1)
   8458 			v22 = bit
   8459 			goto _59
   8460 		_59:
   8461 			if v22 != 0 {
   8462 				v14 = int32(TM_PRED)
   8463 			} else {
   8464 				v14 = int32(H_PRED)
   8465 			}
   8466 			v1 = v14
   8467 		} else {
   8468 			v18 = br2
   8469 			range1 = (*VP8BitReader)(unsafe.Pointer(v18)).Frange1
   8470 			if (*VP8BitReader)(unsafe.Pointer(v18)).Fbits < libc.Int32FromInt32(0) {
   8471 				v19 = v18
   8472 				if (*VP8BitReader)(unsafe.Pointer(v19)).Fbuf < (*VP8BitReader)(unsafe.Pointer(v19)).Fbuf_max {
   8473 					libc.Xmemcpy(tls, bp, (*VP8BitReader)(unsafe.Pointer(v19)).Fbuf, uint64(8))
   8474 					**(**uintptr)(__ccgo_up(v19 + 16)) += uintptr(libc.Int32FromInt32(BITS) >> libc.Int32FromInt32(3))
   8475 					v20 = libc.X__builtin_bswap64(tls, **(**lbit_t)(__ccgo_up(bp)))
   8476 					goto _64
   8477 				_64:
   8478 					bits = v20
   8479 					bits = bits >> uint64(libc.Int32FromInt32(64)-libc.Int32FromInt32(BITS))
   8480 					(*VP8BitReader)(unsafe.Pointer(v19)).Fvalue = bits | (*VP8BitReader)(unsafe.Pointer(v19)).Fvalue<<libc.Int32FromInt32(BITS)
   8481 					**(**int32)(__ccgo_up(v19 + 12)) += int32(BITS)
   8482 				} else {
   8483 					VP8LoadFinalBytes(tls, v19)
   8484 				}
   8485 			}
   8486 			pos = (*VP8BitReader)(unsafe.Pointer(v18)).Fbits
   8487 			split = range1 * uint32(int32(163)) >> int32(8)
   8488 			value = uint32((*VP8BitReader)(unsafe.Pointer(v18)).Fvalue >> pos)
   8489 			bit = libc.BoolInt32(value > split)
   8490 			if bit != 0 {
   8491 				range1 = range1 - split
   8492 				**(**bit_t)(__ccgo_up(v18)) -= uint64(split+libc.Uint32FromInt32(1)) << pos
   8493 			} else {
   8494 				range1 = split + uint32(1)
   8495 			}
   8496 			v30 = int32(31) ^ libc.X__builtin_clz(tls, range1)
   8497 			goto _66
   8498 		_66:
   8499 			shift = int32(7) ^ v30
   8500 			range1 = range1 << uint32(shift)
   8501 			**(**int32)(__ccgo_up(v18 + 12)) -= shift
   8502 			(*VP8BitReader)(unsafe.Pointer(v18)).Frange1 = range1 - uint32(1)
   8503 			v32 = bit
   8504 			goto _68
   8505 		_68:
   8506 			if v32 != 0 {
   8507 				v24 = int32(V_PRED)
   8508 			} else {
   8509 				v24 = int32(DC_PRED)
   8510 			}
   8511 			v1 = v24
   8512 		}
   8513 		// Hardcoded 16x16 intra-mode decision tree.
   8514 		ymode = v1
   8515 		**(**uint8_t)(__ccgo_up(block + 769)) = uint8(ymode)
   8516 		libc.Xmemset(tls, top, ymode, libc.Uint64FromInt32(4)*libc.Uint64FromInt64(1))
   8517 		libc.Xmemset(tls, left, ymode, libc.Uint64FromInt32(4)*libc.Uint64FromInt64(1))
   8518 	} else {
   8519 		modes = block + 769
   8520 		y = 0
   8521 		for {
   8522 			if !(y < int32(4)) {
   8523 				break
   8524 			}
   8525 			ymode1 = int32(**(**uint8_t)(__ccgo_up(left + uintptr(y))))
   8526 			x1 = 0
   8527 			for {
   8528 				if !(x1 < int32(4)) {
   8529 					break
   8530 				}
   8531 				prob1 = uintptr(unsafe.Pointer(&kBModesProba)) + uintptr(**(**uint8_t)(__ccgo_up(top + uintptr(x1))))*90 + uintptr(ymode1)*9
   8532 				v2 = br2
   8533 				range1 = (*VP8BitReader)(unsafe.Pointer(v2)).Frange1
   8534 				if (*VP8BitReader)(unsafe.Pointer(v2)).Fbits < libc.Int32FromInt32(0) {
   8535 					v3 = v2
   8536 					if (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf < (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf_max {
   8537 						libc.Xmemcpy(tls, bp, (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf, uint64(8))
   8538 						**(**uintptr)(__ccgo_up(v3 + 16)) += uintptr(libc.Int32FromInt32(BITS) >> libc.Int32FromInt32(3))
   8539 						v4 = libc.X__builtin_bswap64(tls, **(**lbit_t)(__ccgo_up(bp)))
   8540 						goto _74
   8541 					_74:
   8542 						bits = v4
   8543 						bits = bits >> uint64(libc.Int32FromInt32(64)-libc.Int32FromInt32(BITS))
   8544 						(*VP8BitReader)(unsafe.Pointer(v3)).Fvalue = bits | (*VP8BitReader)(unsafe.Pointer(v3)).Fvalue<<libc.Int32FromInt32(BITS)
   8545 						**(**int32)(__ccgo_up(v3 + 12)) += int32(BITS)
   8546 					} else {
   8547 						VP8LoadFinalBytes(tls, v3)
   8548 					}
   8549 				}
   8550 				pos = (*VP8BitReader)(unsafe.Pointer(v2)).Fbits
   8551 				split = range1 * uint32(int32(**(**uint8_t)(__ccgo_up(prob1)))) >> int32(8)
   8552 				value = uint32((*VP8BitReader)(unsafe.Pointer(v2)).Fvalue >> pos)
   8553 				bit = libc.BoolInt32(value > split)
   8554 				if bit != 0 {
   8555 					range1 = range1 - split
   8556 					**(**bit_t)(__ccgo_up(v2)) -= uint64(split+libc.Uint32FromInt32(1)) << pos
   8557 				} else {
   8558 					range1 = split + uint32(1)
   8559 				}
   8560 				v1 = int32(31) ^ libc.X__builtin_clz(tls, range1)
   8561 				goto _76
   8562 			_76:
   8563 				shift = int32(7) ^ v1
   8564 				range1 = range1 << uint32(shift)
   8565 				**(**int32)(__ccgo_up(v2 + 12)) -= shift
   8566 				(*VP8BitReader)(unsafe.Pointer(v2)).Frange1 = range1 - uint32(1)
   8567 				v6 = bit
   8568 				goto _78
   8569 			_78:
   8570 				// Generic tree-parsing
   8571 				i = int32(kYModesIntra4[v6])
   8572 				for i > 0 {
   8573 					v10 = br2
   8574 					range1 = (*VP8BitReader)(unsafe.Pointer(v10)).Frange1
   8575 					if (*VP8BitReader)(unsafe.Pointer(v10)).Fbits < libc.Int32FromInt32(0) {
   8576 						v11 = v10
   8577 						if (*VP8BitReader)(unsafe.Pointer(v11)).Fbuf < (*VP8BitReader)(unsafe.Pointer(v11)).Fbuf_max {
   8578 							libc.Xmemcpy(tls, bp, (*VP8BitReader)(unsafe.Pointer(v11)).Fbuf, uint64(8))
   8579 							**(**uintptr)(__ccgo_up(v11 + 16)) += uintptr(libc.Int32FromInt32(BITS) >> libc.Int32FromInt32(3))
   8580 							v12 = libc.X__builtin_bswap64(tls, **(**lbit_t)(__ccgo_up(bp)))
   8581 							goto _82
   8582 						_82:
   8583 							bits = v12
   8584 							bits = bits >> uint64(libc.Int32FromInt32(64)-libc.Int32FromInt32(BITS))
   8585 							(*VP8BitReader)(unsafe.Pointer(v11)).Fvalue = bits | (*VP8BitReader)(unsafe.Pointer(v11)).Fvalue<<libc.Int32FromInt32(BITS)
   8586 							**(**int32)(__ccgo_up(v11 + 12)) += int32(BITS)
   8587 						} else {
   8588 							VP8LoadFinalBytes(tls, v11)
   8589 						}
   8590 					}
   8591 					pos = (*VP8BitReader)(unsafe.Pointer(v10)).Fbits
   8592 					split = range1 * uint32(int32(**(**uint8_t)(__ccgo_up(prob1 + uintptr(i))))) >> int32(8)
   8593 					value = uint32((*VP8BitReader)(unsafe.Pointer(v10)).Fvalue >> pos)
   8594 					bit = libc.BoolInt32(value > split)
   8595 					if bit != 0 {
   8596 						range1 = range1 - split
   8597 						**(**bit_t)(__ccgo_up(v10)) -= uint64(split+libc.Uint32FromInt32(1)) << pos
   8598 					} else {
   8599 						range1 = split + uint32(1)
   8600 					}
   8601 					v8 = int32(31) ^ libc.X__builtin_clz(tls, range1)
   8602 					goto _84
   8603 				_84:
   8604 					shift = int32(7) ^ v8
   8605 					range1 = range1 << uint32(shift)
   8606 					**(**int32)(__ccgo_up(v10 + 12)) -= shift
   8607 					(*VP8BitReader)(unsafe.Pointer(v10)).Frange1 = range1 - uint32(1)
   8608 					v14 = bit
   8609 					goto _86
   8610 				_86:
   8611 					i = int32(kYModesIntra4[int32(2)*i+v14])
   8612 				}
   8613 				ymode1 = -i
   8614 				**(**uint8_t)(__ccgo_up(top + uintptr(x1))) = uint8(ymode1)
   8615 				goto _70
   8616 			_70:
   8617 				;
   8618 				x1 = x1 + 1
   8619 			}
   8620 			libc.Xmemcpy(tls, modes, top, libc.Uint64FromInt32(4)*libc.Uint64FromInt64(1))
   8621 			modes = modes + uintptr(4)
   8622 			**(**uint8_t)(__ccgo_up(left + uintptr(y))) = uint8(ymode1)
   8623 			goto _69
   8624 		_69:
   8625 			;
   8626 			y = y + 1
   8627 		}
   8628 	}
   8629 	// Hardcoded UVMode decision tree
   8630 	v2 = br2
   8631 	range1 = (*VP8BitReader)(unsafe.Pointer(v2)).Frange1
   8632 	if (*VP8BitReader)(unsafe.Pointer(v2)).Fbits < libc.Int32FromInt32(0) {
   8633 		v3 = v2
   8634 		if (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf < (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf_max {
   8635 			libc.Xmemcpy(tls, bp, (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf, uint64(8))
   8636 			**(**uintptr)(__ccgo_up(v3 + 16)) += uintptr(libc.Int32FromInt32(BITS) >> libc.Int32FromInt32(3))
   8637 			v4 = libc.X__builtin_bswap64(tls, **(**lbit_t)(__ccgo_up(bp)))
   8638 			goto _91
   8639 		_91:
   8640 			bits = v4
   8641 			bits = bits >> uint64(libc.Int32FromInt32(64)-libc.Int32FromInt32(BITS))
   8642 			(*VP8BitReader)(unsafe.Pointer(v3)).Fvalue = bits | (*VP8BitReader)(unsafe.Pointer(v3)).Fvalue<<libc.Int32FromInt32(BITS)
   8643 			**(**int32)(__ccgo_up(v3 + 12)) += int32(BITS)
   8644 		} else {
   8645 			VP8LoadFinalBytes(tls, v3)
   8646 		}
   8647 	}
   8648 	pos = (*VP8BitReader)(unsafe.Pointer(v2)).Fbits
   8649 	split = range1 * uint32(int32(142)) >> int32(8)
   8650 	value = uint32((*VP8BitReader)(unsafe.Pointer(v2)).Fvalue >> pos)
   8651 	bit = libc.BoolInt32(value > split)
   8652 	if bit != 0 {
   8653 		range1 = range1 - split
   8654 		**(**bit_t)(__ccgo_up(v2)) -= uint64(split+libc.Uint32FromInt32(1)) << pos
   8655 	} else {
   8656 		range1 = split + uint32(1)
   8657 	}
   8658 	v6 = int32(31) ^ libc.X__builtin_clz(tls, range1)
   8659 	goto _93
   8660 _93:
   8661 	shift = int32(7) ^ v6
   8662 	range1 = range1 << uint32(shift)
   8663 	**(**int32)(__ccgo_up(v2 + 12)) -= shift
   8664 	(*VP8BitReader)(unsafe.Pointer(v2)).Frange1 = range1 - uint32(1)
   8665 	v8 = bit
   8666 	goto _95
   8667 _95:
   8668 	if !(v8 != 0) {
   8669 		v1 = int32(DC_PRED)
   8670 	} else {
   8671 		v10 = br2
   8672 		range1 = (*VP8BitReader)(unsafe.Pointer(v10)).Frange1
   8673 		if (*VP8BitReader)(unsafe.Pointer(v10)).Fbits < libc.Int32FromInt32(0) {
   8674 			v11 = v10
   8675 			if (*VP8BitReader)(unsafe.Pointer(v11)).Fbuf < (*VP8BitReader)(unsafe.Pointer(v11)).Fbuf_max {
   8676 				libc.Xmemcpy(tls, bp, (*VP8BitReader)(unsafe.Pointer(v11)).Fbuf, uint64(8))
   8677 				**(**uintptr)(__ccgo_up(v11 + 16)) += uintptr(libc.Int32FromInt32(BITS) >> libc.Int32FromInt32(3))
   8678 				v12 = libc.X__builtin_bswap64(tls, **(**lbit_t)(__ccgo_up(bp)))
   8679 				goto _100
   8680 			_100:
   8681 				bits = v12
   8682 				bits = bits >> uint64(libc.Int32FromInt32(64)-libc.Int32FromInt32(BITS))
   8683 				(*VP8BitReader)(unsafe.Pointer(v11)).Fvalue = bits | (*VP8BitReader)(unsafe.Pointer(v11)).Fvalue<<libc.Int32FromInt32(BITS)
   8684 				**(**int32)(__ccgo_up(v11 + 12)) += int32(BITS)
   8685 			} else {
   8686 				VP8LoadFinalBytes(tls, v11)
   8687 			}
   8688 		}
   8689 		pos = (*VP8BitReader)(unsafe.Pointer(v10)).Fbits
   8690 		split = range1 * uint32(int32(114)) >> int32(8)
   8691 		value = uint32((*VP8BitReader)(unsafe.Pointer(v10)).Fvalue >> pos)
   8692 		bit = libc.BoolInt32(value > split)
   8693 		if bit != 0 {
   8694 			range1 = range1 - split
   8695 			**(**bit_t)(__ccgo_up(v10)) -= uint64(split+libc.Uint32FromInt32(1)) << pos
   8696 		} else {
   8697 			range1 = split + uint32(1)
   8698 		}
   8699 		v16 = int32(31) ^ libc.X__builtin_clz(tls, range1)
   8700 		goto _102
   8701 	_102:
   8702 		shift = int32(7) ^ v16
   8703 		range1 = range1 << uint32(shift)
   8704 		**(**int32)(__ccgo_up(v10 + 12)) -= shift
   8705 		(*VP8BitReader)(unsafe.Pointer(v10)).Frange1 = range1 - uint32(1)
   8706 		v22 = bit
   8707 		goto _104
   8708 	_104:
   8709 		if !(v22 != 0) {
   8710 			v14 = int32(V_PRED)
   8711 		} else {
   8712 			v18 = br2
   8713 			range1 = (*VP8BitReader)(unsafe.Pointer(v18)).Frange1
   8714 			if (*VP8BitReader)(unsafe.Pointer(v18)).Fbits < libc.Int32FromInt32(0) {
   8715 				v19 = v18
   8716 				if (*VP8BitReader)(unsafe.Pointer(v19)).Fbuf < (*VP8BitReader)(unsafe.Pointer(v19)).Fbuf_max {
   8717 					libc.Xmemcpy(tls, bp, (*VP8BitReader)(unsafe.Pointer(v19)).Fbuf, uint64(8))
   8718 					**(**uintptr)(__ccgo_up(v19 + 16)) += uintptr(libc.Int32FromInt32(BITS) >> libc.Int32FromInt32(3))
   8719 					v20 = libc.X__builtin_bswap64(tls, **(**lbit_t)(__ccgo_up(bp)))
   8720 					goto _109
   8721 				_109:
   8722 					bits = v20
   8723 					bits = bits >> uint64(libc.Int32FromInt32(64)-libc.Int32FromInt32(BITS))
   8724 					(*VP8BitReader)(unsafe.Pointer(v19)).Fvalue = bits | (*VP8BitReader)(unsafe.Pointer(v19)).Fvalue<<libc.Int32FromInt32(BITS)
   8725 					**(**int32)(__ccgo_up(v19 + 12)) += int32(BITS)
   8726 				} else {
   8727 					VP8LoadFinalBytes(tls, v19)
   8728 				}
   8729 			}
   8730 			pos = (*VP8BitReader)(unsafe.Pointer(v18)).Fbits
   8731 			split = range1 * uint32(int32(183)) >> int32(8)
   8732 			value = uint32((*VP8BitReader)(unsafe.Pointer(v18)).Fvalue >> pos)
   8733 			bit = libc.BoolInt32(value > split)
   8734 			if bit != 0 {
   8735 				range1 = range1 - split
   8736 				**(**bit_t)(__ccgo_up(v18)) -= uint64(split+libc.Uint32FromInt32(1)) << pos
   8737 			} else {
   8738 				range1 = split + uint32(1)
   8739 			}
   8740 			v30 = int32(31) ^ libc.X__builtin_clz(tls, range1)
   8741 			goto _111
   8742 		_111:
   8743 			shift = int32(7) ^ v30
   8744 			range1 = range1 << uint32(shift)
   8745 			**(**int32)(__ccgo_up(v18 + 12)) -= shift
   8746 			(*VP8BitReader)(unsafe.Pointer(v18)).Frange1 = range1 - uint32(1)
   8747 			v32 = bit
   8748 			goto _113
   8749 		_113:
   8750 			if v32 != 0 {
   8751 				v24 = int32(TM_PRED)
   8752 			} else {
   8753 				v24 = int32(H_PRED)
   8754 			}
   8755 			v14 = v24
   8756 		}
   8757 		v1 = v14
   8758 	}
   8759 	(*VP8MBData)(unsafe.Pointer(block)).Fuvmode = uint8(v1)
   8760 }
   8761 
   8762 func VP8ParseIntraModeRow(tls *libc.TLS, br uintptr, dec uintptr) (r int32) {
   8763 	var mb_x int32
   8764 	_ = mb_x
   8765 	mb_x = 0
   8766 	for {
   8767 		if !(mb_x < (*VP8Decoder)(unsafe.Pointer(dec)).Fmb_w) {
   8768 			break
   8769 		}
   8770 		ParseIntraMode(tls, br, dec, mb_x)
   8771 		goto _1
   8772 	_1:
   8773 		;
   8774 		mb_x = mb_x + 1
   8775 	}
   8776 	return libc.BoolInt32(!((*VP8Decoder)(unsafe.Pointer(dec)).Fbr.Feof != 0))
   8777 }
   8778 
   8779 //------------------------------------------------------------------------------
   8780 // Paragraph 13
   8781 
   8782 var CoeffsUpdateProba = [4][8][3][11]uint8_t{
   8783 	0: {
   8784 		0: {
   8785 			0: {
   8786 				0:  uint8(255),
   8787 				1:  uint8(255),
   8788 				2:  uint8(255),
   8789 				3:  uint8(255),
   8790 				4:  uint8(255),
   8791 				5:  uint8(255),
   8792 				6:  uint8(255),
   8793 				7:  uint8(255),
   8794 				8:  uint8(255),
   8795 				9:  uint8(255),
   8796 				10: uint8(255),
   8797 			},
   8798 			1: {
   8799 				0:  uint8(255),
   8800 				1:  uint8(255),
   8801 				2:  uint8(255),
   8802 				3:  uint8(255),
   8803 				4:  uint8(255),
   8804 				5:  uint8(255),
   8805 				6:  uint8(255),
   8806 				7:  uint8(255),
   8807 				8:  uint8(255),
   8808 				9:  uint8(255),
   8809 				10: uint8(255),
   8810 			},
   8811 			2: {
   8812 				0:  uint8(255),
   8813 				1:  uint8(255),
   8814 				2:  uint8(255),
   8815 				3:  uint8(255),
   8816 				4:  uint8(255),
   8817 				5:  uint8(255),
   8818 				6:  uint8(255),
   8819 				7:  uint8(255),
   8820 				8:  uint8(255),
   8821 				9:  uint8(255),
   8822 				10: uint8(255),
   8823 			},
   8824 		},
   8825 		1: {
   8826 			0: {
   8827 				0:  uint8(176),
   8828 				1:  uint8(246),
   8829 				2:  uint8(255),
   8830 				3:  uint8(255),
   8831 				4:  uint8(255),
   8832 				5:  uint8(255),
   8833 				6:  uint8(255),
   8834 				7:  uint8(255),
   8835 				8:  uint8(255),
   8836 				9:  uint8(255),
   8837 				10: uint8(255),
   8838 			},
   8839 			1: {
   8840 				0:  uint8(223),
   8841 				1:  uint8(241),
   8842 				2:  uint8(252),
   8843 				3:  uint8(255),
   8844 				4:  uint8(255),
   8845 				5:  uint8(255),
   8846 				6:  uint8(255),
   8847 				7:  uint8(255),
   8848 				8:  uint8(255),
   8849 				9:  uint8(255),
   8850 				10: uint8(255),
   8851 			},
   8852 			2: {
   8853 				0:  uint8(249),
   8854 				1:  uint8(253),
   8855 				2:  uint8(253),
   8856 				3:  uint8(255),
   8857 				4:  uint8(255),
   8858 				5:  uint8(255),
   8859 				6:  uint8(255),
   8860 				7:  uint8(255),
   8861 				8:  uint8(255),
   8862 				9:  uint8(255),
   8863 				10: uint8(255),
   8864 			},
   8865 		},
   8866 		2: {
   8867 			0: {
   8868 				0:  uint8(255),
   8869 				1:  uint8(244),
   8870 				2:  uint8(252),
   8871 				3:  uint8(255),
   8872 				4:  uint8(255),
   8873 				5:  uint8(255),
   8874 				6:  uint8(255),
   8875 				7:  uint8(255),
   8876 				8:  uint8(255),
   8877 				9:  uint8(255),
   8878 				10: uint8(255),
   8879 			},
   8880 			1: {
   8881 				0:  uint8(234),
   8882 				1:  uint8(254),
   8883 				2:  uint8(254),
   8884 				3:  uint8(255),
   8885 				4:  uint8(255),
   8886 				5:  uint8(255),
   8887 				6:  uint8(255),
   8888 				7:  uint8(255),
   8889 				8:  uint8(255),
   8890 				9:  uint8(255),
   8891 				10: uint8(255),
   8892 			},
   8893 			2: {
   8894 				0:  uint8(253),
   8895 				1:  uint8(255),
   8896 				2:  uint8(255),
   8897 				3:  uint8(255),
   8898 				4:  uint8(255),
   8899 				5:  uint8(255),
   8900 				6:  uint8(255),
   8901 				7:  uint8(255),
   8902 				8:  uint8(255),
   8903 				9:  uint8(255),
   8904 				10: uint8(255),
   8905 			},
   8906 		},
   8907 		3: {
   8908 			0: {
   8909 				0:  uint8(255),
   8910 				1:  uint8(246),
   8911 				2:  uint8(254),
   8912 				3:  uint8(255),
   8913 				4:  uint8(255),
   8914 				5:  uint8(255),
   8915 				6:  uint8(255),
   8916 				7:  uint8(255),
   8917 				8:  uint8(255),
   8918 				9:  uint8(255),
   8919 				10: uint8(255),
   8920 			},
   8921 			1: {
   8922 				0:  uint8(239),
   8923 				1:  uint8(253),
   8924 				2:  uint8(254),
   8925 				3:  uint8(255),
   8926 				4:  uint8(255),
   8927 				5:  uint8(255),
   8928 				6:  uint8(255),
   8929 				7:  uint8(255),
   8930 				8:  uint8(255),
   8931 				9:  uint8(255),
   8932 				10: uint8(255),
   8933 			},
   8934 			2: {
   8935 				0:  uint8(254),
   8936 				1:  uint8(255),
   8937 				2:  uint8(254),
   8938 				3:  uint8(255),
   8939 				4:  uint8(255),
   8940 				5:  uint8(255),
   8941 				6:  uint8(255),
   8942 				7:  uint8(255),
   8943 				8:  uint8(255),
   8944 				9:  uint8(255),
   8945 				10: uint8(255),
   8946 			},
   8947 		},
   8948 		4: {
   8949 			0: {
   8950 				0:  uint8(255),
   8951 				1:  uint8(248),
   8952 				2:  uint8(254),
   8953 				3:  uint8(255),
   8954 				4:  uint8(255),
   8955 				5:  uint8(255),
   8956 				6:  uint8(255),
   8957 				7:  uint8(255),
   8958 				8:  uint8(255),
   8959 				9:  uint8(255),
   8960 				10: uint8(255),
   8961 			},
   8962 			1: {
   8963 				0:  uint8(251),
   8964 				1:  uint8(255),
   8965 				2:  uint8(254),
   8966 				3:  uint8(255),
   8967 				4:  uint8(255),
   8968 				5:  uint8(255),
   8969 				6:  uint8(255),
   8970 				7:  uint8(255),
   8971 				8:  uint8(255),
   8972 				9:  uint8(255),
   8973 				10: uint8(255),
   8974 			},
   8975 			2: {
   8976 				0:  uint8(255),
   8977 				1:  uint8(255),
   8978 				2:  uint8(255),
   8979 				3:  uint8(255),
   8980 				4:  uint8(255),
   8981 				5:  uint8(255),
   8982 				6:  uint8(255),
   8983 				7:  uint8(255),
   8984 				8:  uint8(255),
   8985 				9:  uint8(255),
   8986 				10: uint8(255),
   8987 			},
   8988 		},
   8989 		5: {
   8990 			0: {
   8991 				0:  uint8(255),
   8992 				1:  uint8(253),
   8993 				2:  uint8(254),
   8994 				3:  uint8(255),
   8995 				4:  uint8(255),
   8996 				5:  uint8(255),
   8997 				6:  uint8(255),
   8998 				7:  uint8(255),
   8999 				8:  uint8(255),
   9000 				9:  uint8(255),
   9001 				10: uint8(255),
   9002 			},
   9003 			1: {
   9004 				0:  uint8(251),
   9005 				1:  uint8(254),
   9006 				2:  uint8(254),
   9007 				3:  uint8(255),
   9008 				4:  uint8(255),
   9009 				5:  uint8(255),
   9010 				6:  uint8(255),
   9011 				7:  uint8(255),
   9012 				8:  uint8(255),
   9013 				9:  uint8(255),
   9014 				10: uint8(255),
   9015 			},
   9016 			2: {
   9017 				0:  uint8(254),
   9018 				1:  uint8(255),
   9019 				2:  uint8(254),
   9020 				3:  uint8(255),
   9021 				4:  uint8(255),
   9022 				5:  uint8(255),
   9023 				6:  uint8(255),
   9024 				7:  uint8(255),
   9025 				8:  uint8(255),
   9026 				9:  uint8(255),
   9027 				10: uint8(255),
   9028 			},
   9029 		},
   9030 		6: {
   9031 			0: {
   9032 				0:  uint8(255),
   9033 				1:  uint8(254),
   9034 				2:  uint8(253),
   9035 				3:  uint8(255),
   9036 				4:  uint8(254),
   9037 				5:  uint8(255),
   9038 				6:  uint8(255),
   9039 				7:  uint8(255),
   9040 				8:  uint8(255),
   9041 				9:  uint8(255),
   9042 				10: uint8(255),
   9043 			},
   9044 			1: {
   9045 				0:  uint8(250),
   9046 				1:  uint8(255),
   9047 				2:  uint8(254),
   9048 				3:  uint8(255),
   9049 				4:  uint8(254),
   9050 				5:  uint8(255),
   9051 				6:  uint8(255),
   9052 				7:  uint8(255),
   9053 				8:  uint8(255),
   9054 				9:  uint8(255),
   9055 				10: uint8(255),
   9056 			},
   9057 			2: {
   9058 				0:  uint8(254),
   9059 				1:  uint8(255),
   9060 				2:  uint8(255),
   9061 				3:  uint8(255),
   9062 				4:  uint8(255),
   9063 				5:  uint8(255),
   9064 				6:  uint8(255),
   9065 				7:  uint8(255),
   9066 				8:  uint8(255),
   9067 				9:  uint8(255),
   9068 				10: uint8(255),
   9069 			},
   9070 		},
   9071 		7: {
   9072 			0: {
   9073 				0:  uint8(255),
   9074 				1:  uint8(255),
   9075 				2:  uint8(255),
   9076 				3:  uint8(255),
   9077 				4:  uint8(255),
   9078 				5:  uint8(255),
   9079 				6:  uint8(255),
   9080 				7:  uint8(255),
   9081 				8:  uint8(255),
   9082 				9:  uint8(255),
   9083 				10: uint8(255),
   9084 			},
   9085 			1: {
   9086 				0:  uint8(255),
   9087 				1:  uint8(255),
   9088 				2:  uint8(255),
   9089 				3:  uint8(255),
   9090 				4:  uint8(255),
   9091 				5:  uint8(255),
   9092 				6:  uint8(255),
   9093 				7:  uint8(255),
   9094 				8:  uint8(255),
   9095 				9:  uint8(255),
   9096 				10: uint8(255),
   9097 			},
   9098 			2: {
   9099 				0:  uint8(255),
   9100 				1:  uint8(255),
   9101 				2:  uint8(255),
   9102 				3:  uint8(255),
   9103 				4:  uint8(255),
   9104 				5:  uint8(255),
   9105 				6:  uint8(255),
   9106 				7:  uint8(255),
   9107 				8:  uint8(255),
   9108 				9:  uint8(255),
   9109 				10: uint8(255),
   9110 			},
   9111 		},
   9112 	},
   9113 	1: {
   9114 		0: {
   9115 			0: {
   9116 				0:  uint8(217),
   9117 				1:  uint8(255),
   9118 				2:  uint8(255),
   9119 				3:  uint8(255),
   9120 				4:  uint8(255),
   9121 				5:  uint8(255),
   9122 				6:  uint8(255),
   9123 				7:  uint8(255),
   9124 				8:  uint8(255),
   9125 				9:  uint8(255),
   9126 				10: uint8(255),
   9127 			},
   9128 			1: {
   9129 				0:  uint8(225),
   9130 				1:  uint8(252),
   9131 				2:  uint8(241),
   9132 				3:  uint8(253),
   9133 				4:  uint8(255),
   9134 				5:  uint8(255),
   9135 				6:  uint8(254),
   9136 				7:  uint8(255),
   9137 				8:  uint8(255),
   9138 				9:  uint8(255),
   9139 				10: uint8(255),
   9140 			},
   9141 			2: {
   9142 				0:  uint8(234),
   9143 				1:  uint8(250),
   9144 				2:  uint8(241),
   9145 				3:  uint8(250),
   9146 				4:  uint8(253),
   9147 				5:  uint8(255),
   9148 				6:  uint8(253),
   9149 				7:  uint8(254),
   9150 				8:  uint8(255),
   9151 				9:  uint8(255),
   9152 				10: uint8(255),
   9153 			},
   9154 		},
   9155 		1: {
   9156 			0: {
   9157 				0:  uint8(255),
   9158 				1:  uint8(254),
   9159 				2:  uint8(255),
   9160 				3:  uint8(255),
   9161 				4:  uint8(255),
   9162 				5:  uint8(255),
   9163 				6:  uint8(255),
   9164 				7:  uint8(255),
   9165 				8:  uint8(255),
   9166 				9:  uint8(255),
   9167 				10: uint8(255),
   9168 			},
   9169 			1: {
   9170 				0:  uint8(223),
   9171 				1:  uint8(254),
   9172 				2:  uint8(254),
   9173 				3:  uint8(255),
   9174 				4:  uint8(255),
   9175 				5:  uint8(255),
   9176 				6:  uint8(255),
   9177 				7:  uint8(255),
   9178 				8:  uint8(255),
   9179 				9:  uint8(255),
   9180 				10: uint8(255),
   9181 			},
   9182 			2: {
   9183 				0:  uint8(238),
   9184 				1:  uint8(253),
   9185 				2:  uint8(254),
   9186 				3:  uint8(254),
   9187 				4:  uint8(255),
   9188 				5:  uint8(255),
   9189 				6:  uint8(255),
   9190 				7:  uint8(255),
   9191 				8:  uint8(255),
   9192 				9:  uint8(255),
   9193 				10: uint8(255),
   9194 			},
   9195 		},
   9196 		2: {
   9197 			0: {
   9198 				0:  uint8(255),
   9199 				1:  uint8(248),
   9200 				2:  uint8(254),
   9201 				3:  uint8(255),
   9202 				4:  uint8(255),
   9203 				5:  uint8(255),
   9204 				6:  uint8(255),
   9205 				7:  uint8(255),
   9206 				8:  uint8(255),
   9207 				9:  uint8(255),
   9208 				10: uint8(255),
   9209 			},
   9210 			1: {
   9211 				0:  uint8(249),
   9212 				1:  uint8(254),
   9213 				2:  uint8(255),
   9214 				3:  uint8(255),
   9215 				4:  uint8(255),
   9216 				5:  uint8(255),
   9217 				6:  uint8(255),
   9218 				7:  uint8(255),
   9219 				8:  uint8(255),
   9220 				9:  uint8(255),
   9221 				10: uint8(255),
   9222 			},
   9223 			2: {
   9224 				0:  uint8(255),
   9225 				1:  uint8(255),
   9226 				2:  uint8(255),
   9227 				3:  uint8(255),
   9228 				4:  uint8(255),
   9229 				5:  uint8(255),
   9230 				6:  uint8(255),
   9231 				7:  uint8(255),
   9232 				8:  uint8(255),
   9233 				9:  uint8(255),
   9234 				10: uint8(255),
   9235 			},
   9236 		},
   9237 		3: {
   9238 			0: {
   9239 				0:  uint8(255),
   9240 				1:  uint8(253),
   9241 				2:  uint8(255),
   9242 				3:  uint8(255),
   9243 				4:  uint8(255),
   9244 				5:  uint8(255),
   9245 				6:  uint8(255),
   9246 				7:  uint8(255),
   9247 				8:  uint8(255),
   9248 				9:  uint8(255),
   9249 				10: uint8(255),
   9250 			},
   9251 			1: {
   9252 				0:  uint8(247),
   9253 				1:  uint8(254),
   9254 				2:  uint8(255),
   9255 				3:  uint8(255),
   9256 				4:  uint8(255),
   9257 				5:  uint8(255),
   9258 				6:  uint8(255),
   9259 				7:  uint8(255),
   9260 				8:  uint8(255),
   9261 				9:  uint8(255),
   9262 				10: uint8(255),
   9263 			},
   9264 			2: {
   9265 				0:  uint8(255),
   9266 				1:  uint8(255),
   9267 				2:  uint8(255),
   9268 				3:  uint8(255),
   9269 				4:  uint8(255),
   9270 				5:  uint8(255),
   9271 				6:  uint8(255),
   9272 				7:  uint8(255),
   9273 				8:  uint8(255),
   9274 				9:  uint8(255),
   9275 				10: uint8(255),
   9276 			},
   9277 		},
   9278 		4: {
   9279 			0: {
   9280 				0:  uint8(255),
   9281 				1:  uint8(253),
   9282 				2:  uint8(254),
   9283 				3:  uint8(255),
   9284 				4:  uint8(255),
   9285 				5:  uint8(255),
   9286 				6:  uint8(255),
   9287 				7:  uint8(255),
   9288 				8:  uint8(255),
   9289 				9:  uint8(255),
   9290 				10: uint8(255),
   9291 			},
   9292 			1: {
   9293 				0:  uint8(252),
   9294 				1:  uint8(255),
   9295 				2:  uint8(255),
   9296 				3:  uint8(255),
   9297 				4:  uint8(255),
   9298 				5:  uint8(255),
   9299 				6:  uint8(255),
   9300 				7:  uint8(255),
   9301 				8:  uint8(255),
   9302 				9:  uint8(255),
   9303 				10: uint8(255),
   9304 			},
   9305 			2: {
   9306 				0:  uint8(255),
   9307 				1:  uint8(255),
   9308 				2:  uint8(255),
   9309 				3:  uint8(255),
   9310 				4:  uint8(255),
   9311 				5:  uint8(255),
   9312 				6:  uint8(255),
   9313 				7:  uint8(255),
   9314 				8:  uint8(255),
   9315 				9:  uint8(255),
   9316 				10: uint8(255),
   9317 			},
   9318 		},
   9319 		5: {
   9320 			0: {
   9321 				0:  uint8(255),
   9322 				1:  uint8(254),
   9323 				2:  uint8(254),
   9324 				3:  uint8(255),
   9325 				4:  uint8(255),
   9326 				5:  uint8(255),
   9327 				6:  uint8(255),
   9328 				7:  uint8(255),
   9329 				8:  uint8(255),
   9330 				9:  uint8(255),
   9331 				10: uint8(255),
   9332 			},
   9333 			1: {
   9334 				0:  uint8(253),
   9335 				1:  uint8(255),
   9336 				2:  uint8(255),
   9337 				3:  uint8(255),
   9338 				4:  uint8(255),
   9339 				5:  uint8(255),
   9340 				6:  uint8(255),
   9341 				7:  uint8(255),
   9342 				8:  uint8(255),
   9343 				9:  uint8(255),
   9344 				10: uint8(255),
   9345 			},
   9346 			2: {
   9347 				0:  uint8(255),
   9348 				1:  uint8(255),
   9349 				2:  uint8(255),
   9350 				3:  uint8(255),
   9351 				4:  uint8(255),
   9352 				5:  uint8(255),
   9353 				6:  uint8(255),
   9354 				7:  uint8(255),
   9355 				8:  uint8(255),
   9356 				9:  uint8(255),
   9357 				10: uint8(255),
   9358 			},
   9359 		},
   9360 		6: {
   9361 			0: {
   9362 				0:  uint8(255),
   9363 				1:  uint8(254),
   9364 				2:  uint8(253),
   9365 				3:  uint8(255),
   9366 				4:  uint8(255),
   9367 				5:  uint8(255),
   9368 				6:  uint8(255),
   9369 				7:  uint8(255),
   9370 				8:  uint8(255),
   9371 				9:  uint8(255),
   9372 				10: uint8(255),
   9373 			},
   9374 			1: {
   9375 				0:  uint8(250),
   9376 				1:  uint8(255),
   9377 				2:  uint8(255),
   9378 				3:  uint8(255),
   9379 				4:  uint8(255),
   9380 				5:  uint8(255),
   9381 				6:  uint8(255),
   9382 				7:  uint8(255),
   9383 				8:  uint8(255),
   9384 				9:  uint8(255),
   9385 				10: uint8(255),
   9386 			},
   9387 			2: {
   9388 				0:  uint8(254),
   9389 				1:  uint8(255),
   9390 				2:  uint8(255),
   9391 				3:  uint8(255),
   9392 				4:  uint8(255),
   9393 				5:  uint8(255),
   9394 				6:  uint8(255),
   9395 				7:  uint8(255),
   9396 				8:  uint8(255),
   9397 				9:  uint8(255),
   9398 				10: uint8(255),
   9399 			},
   9400 		},
   9401 		7: {
   9402 			0: {
   9403 				0:  uint8(255),
   9404 				1:  uint8(255),
   9405 				2:  uint8(255),
   9406 				3:  uint8(255),
   9407 				4:  uint8(255),
   9408 				5:  uint8(255),
   9409 				6:  uint8(255),
   9410 				7:  uint8(255),
   9411 				8:  uint8(255),
   9412 				9:  uint8(255),
   9413 				10: uint8(255),
   9414 			},
   9415 			1: {
   9416 				0:  uint8(255),
   9417 				1:  uint8(255),
   9418 				2:  uint8(255),
   9419 				3:  uint8(255),
   9420 				4:  uint8(255),
   9421 				5:  uint8(255),
   9422 				6:  uint8(255),
   9423 				7:  uint8(255),
   9424 				8:  uint8(255),
   9425 				9:  uint8(255),
   9426 				10: uint8(255),
   9427 			},
   9428 			2: {
   9429 				0:  uint8(255),
   9430 				1:  uint8(255),
   9431 				2:  uint8(255),
   9432 				3:  uint8(255),
   9433 				4:  uint8(255),
   9434 				5:  uint8(255),
   9435 				6:  uint8(255),
   9436 				7:  uint8(255),
   9437 				8:  uint8(255),
   9438 				9:  uint8(255),
   9439 				10: uint8(255),
   9440 			},
   9441 		},
   9442 	},
   9443 	2: {
   9444 		0: {
   9445 			0: {
   9446 				0:  uint8(186),
   9447 				1:  uint8(251),
   9448 				2:  uint8(250),
   9449 				3:  uint8(255),
   9450 				4:  uint8(255),
   9451 				5:  uint8(255),
   9452 				6:  uint8(255),
   9453 				7:  uint8(255),
   9454 				8:  uint8(255),
   9455 				9:  uint8(255),
   9456 				10: uint8(255),
   9457 			},
   9458 			1: {
   9459 				0:  uint8(234),
   9460 				1:  uint8(251),
   9461 				2:  uint8(244),
   9462 				3:  uint8(254),
   9463 				4:  uint8(255),
   9464 				5:  uint8(255),
   9465 				6:  uint8(255),
   9466 				7:  uint8(255),
   9467 				8:  uint8(255),
   9468 				9:  uint8(255),
   9469 				10: uint8(255),
   9470 			},
   9471 			2: {
   9472 				0:  uint8(251),
   9473 				1:  uint8(251),
   9474 				2:  uint8(243),
   9475 				3:  uint8(253),
   9476 				4:  uint8(254),
   9477 				5:  uint8(255),
   9478 				6:  uint8(254),
   9479 				7:  uint8(255),
   9480 				8:  uint8(255),
   9481 				9:  uint8(255),
   9482 				10: uint8(255),
   9483 			},
   9484 		},
   9485 		1: {
   9486 			0: {
   9487 				0:  uint8(255),
   9488 				1:  uint8(253),
   9489 				2:  uint8(254),
   9490 				3:  uint8(255),
   9491 				4:  uint8(255),
   9492 				5:  uint8(255),
   9493 				6:  uint8(255),
   9494 				7:  uint8(255),
   9495 				8:  uint8(255),
   9496 				9:  uint8(255),
   9497 				10: uint8(255),
   9498 			},
   9499 			1: {
   9500 				0:  uint8(236),
   9501 				1:  uint8(253),
   9502 				2:  uint8(254),
   9503 				3:  uint8(255),
   9504 				4:  uint8(255),
   9505 				5:  uint8(255),
   9506 				6:  uint8(255),
   9507 				7:  uint8(255),
   9508 				8:  uint8(255),
   9509 				9:  uint8(255),
   9510 				10: uint8(255),
   9511 			},
   9512 			2: {
   9513 				0:  uint8(251),
   9514 				1:  uint8(253),
   9515 				2:  uint8(253),
   9516 				3:  uint8(254),
   9517 				4:  uint8(254),
   9518 				5:  uint8(255),
   9519 				6:  uint8(255),
   9520 				7:  uint8(255),
   9521 				8:  uint8(255),
   9522 				9:  uint8(255),
   9523 				10: uint8(255),
   9524 			},
   9525 		},
   9526 		2: {
   9527 			0: {
   9528 				0:  uint8(255),
   9529 				1:  uint8(254),
   9530 				2:  uint8(254),
   9531 				3:  uint8(255),
   9532 				4:  uint8(255),
   9533 				5:  uint8(255),
   9534 				6:  uint8(255),
   9535 				7:  uint8(255),
   9536 				8:  uint8(255),
   9537 				9:  uint8(255),
   9538 				10: uint8(255),
   9539 			},
   9540 			1: {
   9541 				0:  uint8(254),
   9542 				1:  uint8(254),
   9543 				2:  uint8(254),
   9544 				3:  uint8(255),
   9545 				4:  uint8(255),
   9546 				5:  uint8(255),
   9547 				6:  uint8(255),
   9548 				7:  uint8(255),
   9549 				8:  uint8(255),
   9550 				9:  uint8(255),
   9551 				10: uint8(255),
   9552 			},
   9553 			2: {
   9554 				0:  uint8(255),
   9555 				1:  uint8(255),
   9556 				2:  uint8(255),
   9557 				3:  uint8(255),
   9558 				4:  uint8(255),
   9559 				5:  uint8(255),
   9560 				6:  uint8(255),
   9561 				7:  uint8(255),
   9562 				8:  uint8(255),
   9563 				9:  uint8(255),
   9564 				10: uint8(255),
   9565 			},
   9566 		},
   9567 		3: {
   9568 			0: {
   9569 				0:  uint8(255),
   9570 				1:  uint8(254),
   9571 				2:  uint8(255),
   9572 				3:  uint8(255),
   9573 				4:  uint8(255),
   9574 				5:  uint8(255),
   9575 				6:  uint8(255),
   9576 				7:  uint8(255),
   9577 				8:  uint8(255),
   9578 				9:  uint8(255),
   9579 				10: uint8(255),
   9580 			},
   9581 			1: {
   9582 				0:  uint8(254),
   9583 				1:  uint8(254),
   9584 				2:  uint8(255),
   9585 				3:  uint8(255),
   9586 				4:  uint8(255),
   9587 				5:  uint8(255),
   9588 				6:  uint8(255),
   9589 				7:  uint8(255),
   9590 				8:  uint8(255),
   9591 				9:  uint8(255),
   9592 				10: uint8(255),
   9593 			},
   9594 			2: {
   9595 				0:  uint8(254),
   9596 				1:  uint8(255),
   9597 				2:  uint8(255),
   9598 				3:  uint8(255),
   9599 				4:  uint8(255),
   9600 				5:  uint8(255),
   9601 				6:  uint8(255),
   9602 				7:  uint8(255),
   9603 				8:  uint8(255),
   9604 				9:  uint8(255),
   9605 				10: uint8(255),
   9606 			},
   9607 		},
   9608 		4: {
   9609 			0: {
   9610 				0:  uint8(255),
   9611 				1:  uint8(255),
   9612 				2:  uint8(255),
   9613 				3:  uint8(255),
   9614 				4:  uint8(255),
   9615 				5:  uint8(255),
   9616 				6:  uint8(255),
   9617 				7:  uint8(255),
   9618 				8:  uint8(255),
   9619 				9:  uint8(255),
   9620 				10: uint8(255),
   9621 			},
   9622 			1: {
   9623 				0:  uint8(254),
   9624 				1:  uint8(255),
   9625 				2:  uint8(255),
   9626 				3:  uint8(255),
   9627 				4:  uint8(255),
   9628 				5:  uint8(255),
   9629 				6:  uint8(255),
   9630 				7:  uint8(255),
   9631 				8:  uint8(255),
   9632 				9:  uint8(255),
   9633 				10: uint8(255),
   9634 			},
   9635 			2: {
   9636 				0:  uint8(255),
   9637 				1:  uint8(255),
   9638 				2:  uint8(255),
   9639 				3:  uint8(255),
   9640 				4:  uint8(255),
   9641 				5:  uint8(255),
   9642 				6:  uint8(255),
   9643 				7:  uint8(255),
   9644 				8:  uint8(255),
   9645 				9:  uint8(255),
   9646 				10: uint8(255),
   9647 			},
   9648 		},
   9649 		5: {
   9650 			0: {
   9651 				0:  uint8(255),
   9652 				1:  uint8(255),
   9653 				2:  uint8(255),
   9654 				3:  uint8(255),
   9655 				4:  uint8(255),
   9656 				5:  uint8(255),
   9657 				6:  uint8(255),
   9658 				7:  uint8(255),
   9659 				8:  uint8(255),
   9660 				9:  uint8(255),
   9661 				10: uint8(255),
   9662 			},
   9663 			1: {
   9664 				0:  uint8(255),
   9665 				1:  uint8(255),
   9666 				2:  uint8(255),
   9667 				3:  uint8(255),
   9668 				4:  uint8(255),
   9669 				5:  uint8(255),
   9670 				6:  uint8(255),
   9671 				7:  uint8(255),
   9672 				8:  uint8(255),
   9673 				9:  uint8(255),
   9674 				10: uint8(255),
   9675 			},
   9676 			2: {
   9677 				0:  uint8(255),
   9678 				1:  uint8(255),
   9679 				2:  uint8(255),
   9680 				3:  uint8(255),
   9681 				4:  uint8(255),
   9682 				5:  uint8(255),
   9683 				6:  uint8(255),
   9684 				7:  uint8(255),
   9685 				8:  uint8(255),
   9686 				9:  uint8(255),
   9687 				10: uint8(255),
   9688 			},
   9689 		},
   9690 		6: {
   9691 			0: {
   9692 				0:  uint8(255),
   9693 				1:  uint8(255),
   9694 				2:  uint8(255),
   9695 				3:  uint8(255),
   9696 				4:  uint8(255),
   9697 				5:  uint8(255),
   9698 				6:  uint8(255),
   9699 				7:  uint8(255),
   9700 				8:  uint8(255),
   9701 				9:  uint8(255),
   9702 				10: uint8(255),
   9703 			},
   9704 			1: {
   9705 				0:  uint8(255),
   9706 				1:  uint8(255),
   9707 				2:  uint8(255),
   9708 				3:  uint8(255),
   9709 				4:  uint8(255),
   9710 				5:  uint8(255),
   9711 				6:  uint8(255),
   9712 				7:  uint8(255),
   9713 				8:  uint8(255),
   9714 				9:  uint8(255),
   9715 				10: uint8(255),
   9716 			},
   9717 			2: {
   9718 				0:  uint8(255),
   9719 				1:  uint8(255),
   9720 				2:  uint8(255),
   9721 				3:  uint8(255),
   9722 				4:  uint8(255),
   9723 				5:  uint8(255),
   9724 				6:  uint8(255),
   9725 				7:  uint8(255),
   9726 				8:  uint8(255),
   9727 				9:  uint8(255),
   9728 				10: uint8(255),
   9729 			},
   9730 		},
   9731 		7: {
   9732 			0: {
   9733 				0:  uint8(255),
   9734 				1:  uint8(255),
   9735 				2:  uint8(255),
   9736 				3:  uint8(255),
   9737 				4:  uint8(255),
   9738 				5:  uint8(255),
   9739 				6:  uint8(255),
   9740 				7:  uint8(255),
   9741 				8:  uint8(255),
   9742 				9:  uint8(255),
   9743 				10: uint8(255),
   9744 			},
   9745 			1: {
   9746 				0:  uint8(255),
   9747 				1:  uint8(255),
   9748 				2:  uint8(255),
   9749 				3:  uint8(255),
   9750 				4:  uint8(255),
   9751 				5:  uint8(255),
   9752 				6:  uint8(255),
   9753 				7:  uint8(255),
   9754 				8:  uint8(255),
   9755 				9:  uint8(255),
   9756 				10: uint8(255),
   9757 			},
   9758 			2: {
   9759 				0:  uint8(255),
   9760 				1:  uint8(255),
   9761 				2:  uint8(255),
   9762 				3:  uint8(255),
   9763 				4:  uint8(255),
   9764 				5:  uint8(255),
   9765 				6:  uint8(255),
   9766 				7:  uint8(255),
   9767 				8:  uint8(255),
   9768 				9:  uint8(255),
   9769 				10: uint8(255),
   9770 			},
   9771 		},
   9772 	},
   9773 	3: {
   9774 		0: {
   9775 			0: {
   9776 				0:  uint8(248),
   9777 				1:  uint8(255),
   9778 				2:  uint8(255),
   9779 				3:  uint8(255),
   9780 				4:  uint8(255),
   9781 				5:  uint8(255),
   9782 				6:  uint8(255),
   9783 				7:  uint8(255),
   9784 				8:  uint8(255),
   9785 				9:  uint8(255),
   9786 				10: uint8(255),
   9787 			},
   9788 			1: {
   9789 				0:  uint8(250),
   9790 				1:  uint8(254),
   9791 				2:  uint8(252),
   9792 				3:  uint8(254),
   9793 				4:  uint8(255),
   9794 				5:  uint8(255),
   9795 				6:  uint8(255),
   9796 				7:  uint8(255),
   9797 				8:  uint8(255),
   9798 				9:  uint8(255),
   9799 				10: uint8(255),
   9800 			},
   9801 			2: {
   9802 				0:  uint8(248),
   9803 				1:  uint8(254),
   9804 				2:  uint8(249),
   9805 				3:  uint8(253),
   9806 				4:  uint8(255),
   9807 				5:  uint8(255),
   9808 				6:  uint8(255),
   9809 				7:  uint8(255),
   9810 				8:  uint8(255),
   9811 				9:  uint8(255),
   9812 				10: uint8(255),
   9813 			},
   9814 		},
   9815 		1: {
   9816 			0: {
   9817 				0:  uint8(255),
   9818 				1:  uint8(253),
   9819 				2:  uint8(253),
   9820 				3:  uint8(255),
   9821 				4:  uint8(255),
   9822 				5:  uint8(255),
   9823 				6:  uint8(255),
   9824 				7:  uint8(255),
   9825 				8:  uint8(255),
   9826 				9:  uint8(255),
   9827 				10: uint8(255),
   9828 			},
   9829 			1: {
   9830 				0:  uint8(246),
   9831 				1:  uint8(253),
   9832 				2:  uint8(253),
   9833 				3:  uint8(255),
   9834 				4:  uint8(255),
   9835 				5:  uint8(255),
   9836 				6:  uint8(255),
   9837 				7:  uint8(255),
   9838 				8:  uint8(255),
   9839 				9:  uint8(255),
   9840 				10: uint8(255),
   9841 			},
   9842 			2: {
   9843 				0:  uint8(252),
   9844 				1:  uint8(254),
   9845 				2:  uint8(251),
   9846 				3:  uint8(254),
   9847 				4:  uint8(254),
   9848 				5:  uint8(255),
   9849 				6:  uint8(255),
   9850 				7:  uint8(255),
   9851 				8:  uint8(255),
   9852 				9:  uint8(255),
   9853 				10: uint8(255),
   9854 			},
   9855 		},
   9856 		2: {
   9857 			0: {
   9858 				0:  uint8(255),
   9859 				1:  uint8(254),
   9860 				2:  uint8(252),
   9861 				3:  uint8(255),
   9862 				4:  uint8(255),
   9863 				5:  uint8(255),
   9864 				6:  uint8(255),
   9865 				7:  uint8(255),
   9866 				8:  uint8(255),
   9867 				9:  uint8(255),
   9868 				10: uint8(255),
   9869 			},
   9870 			1: {
   9871 				0:  uint8(248),
   9872 				1:  uint8(254),
   9873 				2:  uint8(253),
   9874 				3:  uint8(255),
   9875 				4:  uint8(255),
   9876 				5:  uint8(255),
   9877 				6:  uint8(255),
   9878 				7:  uint8(255),
   9879 				8:  uint8(255),
   9880 				9:  uint8(255),
   9881 				10: uint8(255),
   9882 			},
   9883 			2: {
   9884 				0:  uint8(253),
   9885 				1:  uint8(255),
   9886 				2:  uint8(254),
   9887 				3:  uint8(254),
   9888 				4:  uint8(255),
   9889 				5:  uint8(255),
   9890 				6:  uint8(255),
   9891 				7:  uint8(255),
   9892 				8:  uint8(255),
   9893 				9:  uint8(255),
   9894 				10: uint8(255),
   9895 			},
   9896 		},
   9897 		3: {
   9898 			0: {
   9899 				0:  uint8(255),
   9900 				1:  uint8(251),
   9901 				2:  uint8(254),
   9902 				3:  uint8(255),
   9903 				4:  uint8(255),
   9904 				5:  uint8(255),
   9905 				6:  uint8(255),
   9906 				7:  uint8(255),
   9907 				8:  uint8(255),
   9908 				9:  uint8(255),
   9909 				10: uint8(255),
   9910 			},
   9911 			1: {
   9912 				0:  uint8(245),
   9913 				1:  uint8(251),
   9914 				2:  uint8(254),
   9915 				3:  uint8(255),
   9916 				4:  uint8(255),
   9917 				5:  uint8(255),
   9918 				6:  uint8(255),
   9919 				7:  uint8(255),
   9920 				8:  uint8(255),
   9921 				9:  uint8(255),
   9922 				10: uint8(255),
   9923 			},
   9924 			2: {
   9925 				0:  uint8(253),
   9926 				1:  uint8(253),
   9927 				2:  uint8(254),
   9928 				3:  uint8(255),
   9929 				4:  uint8(255),
   9930 				5:  uint8(255),
   9931 				6:  uint8(255),
   9932 				7:  uint8(255),
   9933 				8:  uint8(255),
   9934 				9:  uint8(255),
   9935 				10: uint8(255),
   9936 			},
   9937 		},
   9938 		4: {
   9939 			0: {
   9940 				0:  uint8(255),
   9941 				1:  uint8(251),
   9942 				2:  uint8(253),
   9943 				3:  uint8(255),
   9944 				4:  uint8(255),
   9945 				5:  uint8(255),
   9946 				6:  uint8(255),
   9947 				7:  uint8(255),
   9948 				8:  uint8(255),
   9949 				9:  uint8(255),
   9950 				10: uint8(255),
   9951 			},
   9952 			1: {
   9953 				0:  uint8(252),
   9954 				1:  uint8(253),
   9955 				2:  uint8(254),
   9956 				3:  uint8(255),
   9957 				4:  uint8(255),
   9958 				5:  uint8(255),
   9959 				6:  uint8(255),
   9960 				7:  uint8(255),
   9961 				8:  uint8(255),
   9962 				9:  uint8(255),
   9963 				10: uint8(255),
   9964 			},
   9965 			2: {
   9966 				0:  uint8(255),
   9967 				1:  uint8(254),
   9968 				2:  uint8(255),
   9969 				3:  uint8(255),
   9970 				4:  uint8(255),
   9971 				5:  uint8(255),
   9972 				6:  uint8(255),
   9973 				7:  uint8(255),
   9974 				8:  uint8(255),
   9975 				9:  uint8(255),
   9976 				10: uint8(255),
   9977 			},
   9978 		},
   9979 		5: {
   9980 			0: {
   9981 				0:  uint8(255),
   9982 				1:  uint8(252),
   9983 				2:  uint8(255),
   9984 				3:  uint8(255),
   9985 				4:  uint8(255),
   9986 				5:  uint8(255),
   9987 				6:  uint8(255),
   9988 				7:  uint8(255),
   9989 				8:  uint8(255),
   9990 				9:  uint8(255),
   9991 				10: uint8(255),
   9992 			},
   9993 			1: {
   9994 				0:  uint8(249),
   9995 				1:  uint8(255),
   9996 				2:  uint8(254),
   9997 				3:  uint8(255),
   9998 				4:  uint8(255),
   9999 				5:  uint8(255),
  10000 				6:  uint8(255),
  10001 				7:  uint8(255),
  10002 				8:  uint8(255),
  10003 				9:  uint8(255),
  10004 				10: uint8(255),
  10005 			},
  10006 			2: {
  10007 				0:  uint8(255),
  10008 				1:  uint8(255),
  10009 				2:  uint8(254),
  10010 				3:  uint8(255),
  10011 				4:  uint8(255),
  10012 				5:  uint8(255),
  10013 				6:  uint8(255),
  10014 				7:  uint8(255),
  10015 				8:  uint8(255),
  10016 				9:  uint8(255),
  10017 				10: uint8(255),
  10018 			},
  10019 		},
  10020 		6: {
  10021 			0: {
  10022 				0:  uint8(255),
  10023 				1:  uint8(255),
  10024 				2:  uint8(253),
  10025 				3:  uint8(255),
  10026 				4:  uint8(255),
  10027 				5:  uint8(255),
  10028 				6:  uint8(255),
  10029 				7:  uint8(255),
  10030 				8:  uint8(255),
  10031 				9:  uint8(255),
  10032 				10: uint8(255),
  10033 			},
  10034 			1: {
  10035 				0:  uint8(250),
  10036 				1:  uint8(255),
  10037 				2:  uint8(255),
  10038 				3:  uint8(255),
  10039 				4:  uint8(255),
  10040 				5:  uint8(255),
  10041 				6:  uint8(255),
  10042 				7:  uint8(255),
  10043 				8:  uint8(255),
  10044 				9:  uint8(255),
  10045 				10: uint8(255),
  10046 			},
  10047 			2: {
  10048 				0:  uint8(255),
  10049 				1:  uint8(255),
  10050 				2:  uint8(255),
  10051 				3:  uint8(255),
  10052 				4:  uint8(255),
  10053 				5:  uint8(255),
  10054 				6:  uint8(255),
  10055 				7:  uint8(255),
  10056 				8:  uint8(255),
  10057 				9:  uint8(255),
  10058 				10: uint8(255),
  10059 			},
  10060 		},
  10061 		7: {
  10062 			0: {
  10063 				0:  uint8(255),
  10064 				1:  uint8(255),
  10065 				2:  uint8(255),
  10066 				3:  uint8(255),
  10067 				4:  uint8(255),
  10068 				5:  uint8(255),
  10069 				6:  uint8(255),
  10070 				7:  uint8(255),
  10071 				8:  uint8(255),
  10072 				9:  uint8(255),
  10073 				10: uint8(255),
  10074 			},
  10075 			1: {
  10076 				0:  uint8(254),
  10077 				1:  uint8(255),
  10078 				2:  uint8(255),
  10079 				3:  uint8(255),
  10080 				4:  uint8(255),
  10081 				5:  uint8(255),
  10082 				6:  uint8(255),
  10083 				7:  uint8(255),
  10084 				8:  uint8(255),
  10085 				9:  uint8(255),
  10086 				10: uint8(255),
  10087 			},
  10088 			2: {
  10089 				0:  uint8(255),
  10090 				1:  uint8(255),
  10091 				2:  uint8(255),
  10092 				3:  uint8(255),
  10093 				4:  uint8(255),
  10094 				5:  uint8(255),
  10095 				6:  uint8(255),
  10096 				7:  uint8(255),
  10097 				8:  uint8(255),
  10098 				9:  uint8(255),
  10099 				10: uint8(255),
  10100 			},
  10101 		},
  10102 	},
  10103 }
  10104 
  10105 // Paragraph 9.9
  10106 
  10107 var kBands = [17]uint8_t{
  10108 	1:  uint8(1),
  10109 	2:  uint8(2),
  10110 	3:  uint8(3),
  10111 	4:  uint8(6),
  10112 	5:  uint8(4),
  10113 	6:  uint8(5),
  10114 	7:  uint8(6),
  10115 	8:  uint8(6),
  10116 	9:  uint8(6),
  10117 	10: uint8(6),
  10118 	11: uint8(6),
  10119 	12: uint8(6),
  10120 	13: uint8(6),
  10121 	14: uint8(6),
  10122 	15: uint8(7),
  10123 }
  10124 
  10125 func VP8ParseProba(tls *libc.TLS, br2 uintptr, dec uintptr) {
  10126 	bp := tls.Alloc(16)
  10127 	defer tls.Free(16)
  10128 	var b, bit, c, p, pos, shift, t, v, v10, v12 int32
  10129 	var bits bit_t
  10130 	var proba, v6, v7 uintptr
  10131 	var range1, split, value range_t
  10132 	var v5 uint32
  10133 	var v8 uint64_t
  10134 	var _ /* in_bits at bp+0 */ lbit_t
  10135 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = b, bit, bits, c, p, pos, proba, range1, shift, split, t, v, value, v10, v12, v5, v6, v7, v8
  10136 	proba = dec + 1192
  10137 	t = 0
  10138 	for {
  10139 		if !(t < int32(NUM_TYPES)) {
  10140 			break
  10141 		}
  10142 		b = 0
  10143 		for {
  10144 			if !(b < int32(NUM_BANDS)) {
  10145 				break
  10146 			}
  10147 			c = 0
  10148 			for {
  10149 				if !(c < int32(NUM_CTX)) {
  10150 					break
  10151 				}
  10152 				p = 0
  10153 				for {
  10154 					if !(p < int32(NUM_PROBAS)) {
  10155 						break
  10156 					}
  10157 					v6 = br2
  10158 					range1 = (*VP8BitReader)(unsafe.Pointer(v6)).Frange1
  10159 					if (*VP8BitReader)(unsafe.Pointer(v6)).Fbits < libc.Int32FromInt32(0) {
  10160 						v7 = v6
  10161 						if (*VP8BitReader)(unsafe.Pointer(v7)).Fbuf < (*VP8BitReader)(unsafe.Pointer(v7)).Fbuf_max {
  10162 							libc.Xmemcpy(tls, bp, (*VP8BitReader)(unsafe.Pointer(v7)).Fbuf, uint64(8))
  10163 							**(**uintptr)(__ccgo_up(v7 + 16)) += uintptr(libc.Int32FromInt32(BITS) >> libc.Int32FromInt32(3))
  10164 							v8 = libc.X__builtin_bswap64(tls, **(**lbit_t)(__ccgo_up(bp)))
  10165 							goto _9
  10166 						_9:
  10167 							bits = v8
  10168 							bits = bits >> uint64(libc.Int32FromInt32(64)-libc.Int32FromInt32(BITS))
  10169 							(*VP8BitReader)(unsafe.Pointer(v7)).Fvalue = bits | (*VP8BitReader)(unsafe.Pointer(v7)).Fvalue<<libc.Int32FromInt32(BITS)
  10170 							**(**int32)(__ccgo_up(v7 + 12)) += int32(BITS)
  10171 						} else {
  10172 							VP8LoadFinalBytes(tls, v7)
  10173 						}
  10174 					}
  10175 					pos = (*VP8BitReader)(unsafe.Pointer(v6)).Fbits
  10176 					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)
  10177 					value = uint32((*VP8BitReader)(unsafe.Pointer(v6)).Fvalue >> pos)
  10178 					bit = libc.BoolInt32(value > split)
  10179 					if bit != 0 {
  10180 						range1 = range1 - split
  10181 						**(**bit_t)(__ccgo_up(v6)) -= uint64(split+libc.Uint32FromInt32(1)) << pos
  10182 					} else {
  10183 						range1 = split + uint32(1)
  10184 					}
  10185 					v10 = int32(31) ^ libc.X__builtin_clz(tls, range1)
  10186 					goto _11
  10187 				_11:
  10188 					shift = int32(7) ^ v10
  10189 					range1 = range1 << uint32(shift)
  10190 					**(**int32)(__ccgo_up(v6 + 12)) -= shift
  10191 					(*VP8BitReader)(unsafe.Pointer(v6)).Frange1 = range1 - uint32(1)
  10192 					v12 = bit
  10193 					goto _13
  10194 				_13:
  10195 					if v12 != 0 {
  10196 						v5 = VP8GetValue(tls, br2, int32(8))
  10197 					} else {
  10198 						v5 = uint32(**(**uint8_t)(__ccgo_up(uintptr(unsafe.Pointer(&CoeffsProba0)) + uintptr(t)*264 + uintptr(b)*33 + uintptr(c)*11 + uintptr(p))))
  10199 					}
  10200 					v = int32(v5)
  10201 					**(**uint8_t)(__ccgo_up(proba + 3 + uintptr(t)*264 + uintptr(b)*33 + uintptr(c)*11 + uintptr(p))) = uint8(v)
  10202 					goto _4
  10203 				_4:
  10204 					;
  10205 					p = p + 1
  10206 				}
  10207 				goto _3
  10208 			_3:
  10209 				;
  10210 				c = c + 1
  10211 			}
  10212 			goto _2
  10213 		_2:
  10214 			;
  10215 			b = b + 1
  10216 		}
  10217 		b = 0
  10218 		for {
  10219 			if !(b < libc.Int32FromInt32(16)+libc.Int32FromInt32(1)) {
  10220 				break
  10221 			}
  10222 			**(**uintptr)(__ccgo_up(proba + 1064 + uintptr(t)*136 + uintptr(b)*8)) = proba + 3 + uintptr(t)*264 + uintptr(kBands[b])*33
  10223 			goto _14
  10224 		_14:
  10225 			;
  10226 			b = b + 1
  10227 		}
  10228 		goto _1
  10229 	_1:
  10230 		;
  10231 		t = t + 1
  10232 	}
  10233 	(*VP8Decoder)(unsafe.Pointer(dec)).Fuse_skip_proba = int32(VP8GetValue(tls, br2, int32(1)))
  10234 	if (*VP8Decoder)(unsafe.Pointer(dec)).Fuse_skip_proba != 0 {
  10235 		(*VP8Decoder)(unsafe.Pointer(dec)).Fskip_p = uint8(VP8GetValue(tls, br2, int32(8)))
  10236 	}
  10237 }
  10238 
  10239 const SIZE_MAX2 = "_UI64_MAX"
  10240 
  10241 var kHashMul7 = uint32(0x1e35a7bd)
  10242 
  10243 // Copyright 2010 Google Inc. All Rights Reserved.
  10244 //
  10245 // Use of this source code is governed by a BSD-style license
  10246 // that can be found in the COPYING file in the root of the source
  10247 // tree. An additional intellectual property rights grant can be found
  10248 // in the file PATENTS. All contributing project authors may
  10249 // be found in the AUTHORS file in the root of the source tree.
  10250 // -----------------------------------------------------------------------------
  10251 //
  10252 // Boolean decoder
  10253 //
  10254 // Author: Skal (pascal.massimino@gmail.com)
  10255 //         Vikas Arora (vikaas.arora@gmail.com)
  10256 
  10257 // Copyright 2011 Google Inc. All Rights Reserved.
  10258 //
  10259 // Use of this source code is governed by a BSD-style license
  10260 // that can be found in the COPYING file in the root of the source
  10261 // tree. An additional intellectual property rights grant can be found
  10262 // in the file PATENTS. All contributing project authors may
  10263 // be found in the AUTHORS file in the root of the source tree.
  10264 // -----------------------------------------------------------------------------
  10265 //
  10266 // Multi-threaded worker
  10267 //
  10268 // Author: Skal (pascal.massimino@gmail.com)
  10269 
  10270 // Copyright 2012 Google Inc. All Rights Reserved.
  10271 //
  10272 // Use of this source code is governed by a BSD-style license
  10273 // that can be found in the COPYING file in the root of the source
  10274 // tree. An additional intellectual property rights grant can be found
  10275 // in the file PATENTS. All contributing project authors may
  10276 // be found in the AUTHORS file in the root of the source tree.
  10277 // -----------------------------------------------------------------------------
  10278 //
  10279 // Misc. common utility functions
  10280 //
  10281 // Authors: Skal (pascal.massimino@gmail.com)
  10282 //          Urvang (urvang@google.com)
  10283 
  10284 // Copyright 2010 Google Inc. All Rights Reserved.
  10285 //
  10286 // Use of this source code is governed by a BSD-style license
  10287 // that can be found in the COPYING file in the root of the source
  10288 // tree. An additional intellectual property rights grant can be found
  10289 // in the file PATENTS. All contributing project authors may
  10290 // be found in the AUTHORS file in the root of the source tree.
  10291 // -----------------------------------------------------------------------------
  10292 //
  10293 //  Main decoding functions for WebP images.
  10294 //
  10295 // Author: Skal (pascal.massimino@gmail.com)
  10296 
  10297 // Copyright 2012 Google Inc. All Rights Reserved.
  10298 //
  10299 // Use of this source code is governed by a BSD-style license
  10300 // that can be found in the COPYING file in the root of the source
  10301 // tree. An additional intellectual property rights grant can be found
  10302 // in the file PATENTS. All contributing project authors may
  10303 // be found in the AUTHORS file in the root of the source tree.
  10304 // -----------------------------------------------------------------------------
  10305 //
  10306 //  Internal header for constants related to WebP file format.
  10307 //
  10308 // Author: Urvang (urvang@google.com)
  10309 
  10310 // Copyright 2010 Google Inc. All Rights Reserved.
  10311 //
  10312 // Use of this source code is governed by a BSD-style license
  10313 // that can be found in the COPYING file in the root of the source
  10314 // tree. An additional intellectual property rights grant can be found
  10315 // in the file PATENTS. All contributing project authors may
  10316 // be found in the AUTHORS file in the root of the source tree.
  10317 // -----------------------------------------------------------------------------
  10318 //
  10319 //  Common types + memory wrappers
  10320 //
  10321 // Author: Skal (pascal.massimino@gmail.com)
  10322 
  10323 //------------------------------------------------------------------------------
  10324 
  10325 func WebPGetDecoderVersion(tls *libc.TLS) (r int32) {
  10326 	return libc.Int32FromInt32(DEC_MAJ_VERSION)<<libc.Int32FromInt32(16) | libc.Int32FromInt32(DEC_MIN_VERSION)<<libc.Int32FromInt32(8) | libc.Int32FromInt32(DEC_REV_VERSION)
  10327 }
  10328 
  10329 //------------------------------------------------------------------------------
  10330 // Signature and pointer-to-function for GetCoeffs() variants below.
  10331 
  10332 type GetCoeffsFunc = uintptr
  10333 
  10334 var GetCoeffs = uintptr(0)
  10335 
  10336 func init() {
  10337 	p := unsafe.Pointer(&GetCoeffs)
  10338 	*(*uintptr)(unsafe.Add(p, 0)) = libc.UintptrFromInt32(0)
  10339 }
  10340 
  10341 //------------------------------------------------------------------------------
  10342 // VP8Decoder
  10343 
  10344 func SetOk(tls *libc.TLS, dec uintptr) {
  10345 	(*VP8Decoder)(unsafe.Pointer(dec)).Fstatus = int32(VP8_STATUS_OK)
  10346 	(*VP8Decoder)(unsafe.Pointer(dec)).Ferror_msg = __ccgo_ts + 154
  10347 }
  10348 
  10349 func VP8InitIoInternal(tls *libc.TLS, io uintptr, version int32) (r int32) {
  10350 	if version>>int32(8) != libc.Int32FromInt32(WEBP_DECODER_ABI_VERSION)>>libc.Int32FromInt32(8) {
  10351 		return 0 // mismatch error
  10352 	}
  10353 	if io != libc.UintptrFromInt32(0) {
  10354 		libc.Xmemset(tls, io, 0, uint64(160))
  10355 	}
  10356 	return int32(1)
  10357 }
  10358 
  10359 func VP8New(tls *libc.TLS) (r uintptr) {
  10360 	var dec uintptr
  10361 	_ = dec
  10362 	dec = WebPSafeCalloc(tls, uint64(1), uint64(3024))
  10363 	if dec != libc.UintptrFromInt32(0) {
  10364 		SetOk(tls, dec)
  10365 		(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(&struct{ uintptr }{(*WebPWorkerInterface)(unsafe.Pointer(WebPGetWorkerInterface(tls))).FInit})))(tls, dec+152)
  10366 		(*VP8Decoder)(unsafe.Pointer(dec)).Fready = 0
  10367 		(*VP8Decoder)(unsafe.Pointer(dec)).Fnum_parts_minus_one = uint32(0)
  10368 		InitGetCoeffs(tls)
  10369 	}
  10370 	return dec
  10371 }
  10372 
  10373 func VP8Status(tls *libc.TLS, dec uintptr) (r VP8StatusCode1) {
  10374 	if !(dec != 0) {
  10375 		return int32(VP8_STATUS_INVALID_PARAM)
  10376 	}
  10377 	return (*VP8Decoder)(unsafe.Pointer(dec)).Fstatus
  10378 }
  10379 
  10380 func VP8StatusMessage(tls *libc.TLS, dec uintptr) (r uintptr) {
  10381 	if dec == libc.UintptrFromInt32(0) {
  10382 		return __ccgo_ts + 157
  10383 	}
  10384 	if !((*VP8Decoder)(unsafe.Pointer(dec)).Ferror_msg != 0) {
  10385 		return __ccgo_ts + 154
  10386 	}
  10387 	return (*VP8Decoder)(unsafe.Pointer(dec)).Ferror_msg
  10388 }
  10389 
  10390 func VP8Delete(tls *libc.TLS, dec uintptr) {
  10391 	if dec != libc.UintptrFromInt32(0) {
  10392 		VP8Clear(tls, dec)
  10393 		WebPSafeFree(tls, dec)
  10394 	}
  10395 }
  10396 
  10397 func VP8SetError(tls *libc.TLS, dec uintptr, error1 VP8StatusCode1, msg uintptr) (r int32) {
  10398 	// VP8_STATUS_SUSPENDED is only meaningful in incremental decoding.
  10399 	// The oldest error reported takes precedence over the new one.
  10400 	if (*VP8Decoder)(unsafe.Pointer(dec)).Fstatus == int32(VP8_STATUS_OK) {
  10401 		(*VP8Decoder)(unsafe.Pointer(dec)).Fstatus = error1
  10402 		(*VP8Decoder)(unsafe.Pointer(dec)).Ferror_msg = msg
  10403 		(*VP8Decoder)(unsafe.Pointer(dec)).Fready = 0
  10404 	}
  10405 	return 0
  10406 }
  10407 
  10408 //------------------------------------------------------------------------------
  10409 
  10410 func VP8CheckSignature(tls *libc.TLS, data uintptr, data_size size_t) (r int32) {
  10411 	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))
  10412 }
  10413 
  10414 func VP8GetInfo(tls *libc.TLS, data uintptr, data_size size_t, chunk_size size_t, width uintptr, height uintptr) (r int32) {
  10415 	var bits uint32_t
  10416 	var h, key_frame, w int32
  10417 	_, _, _, _ = bits, h, key_frame, w
  10418 	if data == libc.UintptrFromInt32(0) || data_size < uint64(VP8_FRAME_HEADER_SIZE) {
  10419 		return 0 // not enough data
  10420 	}
  10421 	// check signature
  10422 	if !(VP8CheckSignature(tls, data+uintptr(3), data_size-uint64(3)) != 0) {
  10423 		return 0 // Wrong signature.
  10424 	} else {
  10425 		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))
  10426 		key_frame = libc.BoolInt32(!(bits&libc.Uint32FromInt32(1) != 0))
  10427 		w = (int32(**(**uint8_t)(__ccgo_up(data + 7)))<<int32(8) | int32(**(**uint8_t)(__ccgo_up(data + 6)))) & int32(0x3fff)
  10428 		h = (int32(**(**uint8_t)(__ccgo_up(data + 9)))<<int32(8) | int32(**(**uint8_t)(__ccgo_up(data + 8)))) & int32(0x3fff)
  10429 		if !(key_frame != 0) { // Not a keyframe.
  10430 			return 0
  10431 		}
  10432 		if bits>>libc.Int32FromInt32(1)&uint32(7) > uint32(3) {
  10433 			return 0 // unknown profile
  10434 		}
  10435 		if !(bits>>libc.Int32FromInt32(4)&libc.Uint32FromInt32(1) != 0) {
  10436 			return 0 // first frame is invisible!
  10437 		}
  10438 		if uint64(bits>>libc.Int32FromInt32(5)) >= chunk_size { // partition_length
  10439 			return 0 // inconsistent size information.
  10440 		}
  10441 		if w == 0 || h == 0 {
  10442 			return 0 // We don't support both width and height to be zero.
  10443 		}
  10444 		if width != 0 {
  10445 			**(**int32)(__ccgo_up(width)) = w
  10446 		}
  10447 		if height != 0 {
  10448 			**(**int32)(__ccgo_up(height)) = h
  10449 		}
  10450 		return int32(1)
  10451 	}
  10452 	return r
  10453 }
  10454 
  10455 //------------------------------------------------------------------------------
  10456 // Header parsing
  10457 
  10458 func ResetSegmentHeader(tls *libc.TLS, hdr uintptr) {
  10459 	(*VP8SegmentHeader)(unsafe.Pointer(hdr)).Fuse_segment = 0
  10460 	(*VP8SegmentHeader)(unsafe.Pointer(hdr)).Fupdate_map = 0
  10461 	(*VP8SegmentHeader)(unsafe.Pointer(hdr)).Fabsolute_delta = int32(1)
  10462 	libc.Xmemset(tls, hdr+12, 0, uint64(4))
  10463 	libc.Xmemset(tls, hdr+16, 0, uint64(4))
  10464 }
  10465 
  10466 // C documentation
  10467 //
  10468 //	// Paragraph 9.3
  10469 func ParseSegmentHeader(tls *libc.TLS, br uintptr, hdr uintptr, proba uintptr) (r int32) {
  10470 	var s, s1, v2 int32
  10471 	var v6 uint32
  10472 	_, _, _, _ = s, s1, v2, v6
  10473 	(*VP8SegmentHeader)(unsafe.Pointer(hdr)).Fuse_segment = int32(VP8GetValue(tls, br, int32(1)))
  10474 	if (*VP8SegmentHeader)(unsafe.Pointer(hdr)).Fuse_segment != 0 {
  10475 		(*VP8SegmentHeader)(unsafe.Pointer(hdr)).Fupdate_map = int32(VP8GetValue(tls, br, int32(1)))
  10476 		if VP8GetValue(tls, br, int32(1)) != 0 {
  10477 			(*VP8SegmentHeader)(unsafe.Pointer(hdr)).Fabsolute_delta = int32(VP8GetValue(tls, br, int32(1)))
  10478 			s = 0
  10479 			for {
  10480 				if !(s < int32(NUM_MB_SEGMENTS)) {
  10481 					break
  10482 				}
  10483 				if VP8GetValue(tls, br, int32(1)) != 0 {
  10484 					v2 = VP8GetSignedValue(tls, br, int32(7))
  10485 				} else {
  10486 					v2 = 0
  10487 				}
  10488 				**(**int8_t)(__ccgo_up(hdr + 12 + uintptr(s))) = int8(v2)
  10489 				goto _1
  10490 			_1:
  10491 				;
  10492 				s = s + 1
  10493 			}
  10494 			s = 0
  10495 			for {
  10496 				if !(s < int32(NUM_MB_SEGMENTS)) {
  10497 					break
  10498 				}
  10499 				if VP8GetValue(tls, br, int32(1)) != 0 {
  10500 					v2 = VP8GetSignedValue(tls, br, int32(6))
  10501 				} else {
  10502 					v2 = 0
  10503 				}
  10504 				**(**int8_t)(__ccgo_up(hdr + 16 + uintptr(s))) = int8(v2)
  10505 				goto _3
  10506 			_3:
  10507 				;
  10508 				s = s + 1
  10509 			}
  10510 		}
  10511 		if (*VP8SegmentHeader)(unsafe.Pointer(hdr)).Fupdate_map != 0 {
  10512 			s1 = 0
  10513 			for {
  10514 				if !(s1 < int32(MB_FEATURE_TREE_PROBS)) {
  10515 					break
  10516 				}
  10517 				if VP8GetValue(tls, br, int32(1)) != 0 {
  10518 					v6 = VP8GetValue(tls, br, int32(8))
  10519 				} else {
  10520 					v6 = uint32(255)
  10521 				}
  10522 				**(**uint8_t)(__ccgo_up(proba + uintptr(s1))) = uint8(v6)
  10523 				goto _5
  10524 			_5:
  10525 				;
  10526 				s1 = s1 + 1
  10527 			}
  10528 		}
  10529 	} else {
  10530 		(*VP8SegmentHeader)(unsafe.Pointer(hdr)).Fupdate_map = 0
  10531 	}
  10532 	return libc.BoolInt32(!((*VP8BitReader)(unsafe.Pointer(br)).Feof != 0))
  10533 }
  10534 
  10535 // C documentation
  10536 //
  10537 //	// Paragraph 9.5
  10538 //	// If we don't have all the necessary data in 'buf', this function returns
  10539 //	// VP8_STATUS_SUSPENDED in incremental decoding, VP8_STATUS_NOT_ENOUGH_DATA
  10540 //	// otherwise.
  10541 //	// In incremental decoding, this case is not necessarily an error. Still, no
  10542 //	// bitreader is ever initialized to make it possible to read unavailable memory.
  10543 //	// If we don't even have the partitions' sizes, then VP8_STATUS_NOT_ENOUGH_DATA
  10544 //	// is returned, and this is an unrecoverable error.
  10545 //	// If the partitions were positioned ok, VP8_STATUS_OK is returned.
  10546 func ParsePartitions(tls *libc.TLS, dec uintptr, buf uintptr, size size_t) (r VP8StatusCode1) {
  10547 	var br, buf_end, part_start, sz uintptr
  10548 	var last_part, p, psize, size_left size_t
  10549 	var v2 int32
  10550 	_, _, _, _, _, _, _, _, _ = br, buf_end, last_part, p, part_start, psize, size_left, sz, v2
  10551 	br = dec + 16
  10552 	sz = buf
  10553 	buf_end = buf + uintptr(size)
  10554 	size_left = size
  10555 	(*VP8Decoder)(unsafe.Pointer(dec)).Fnum_parts_minus_one = uint32(int32(1)<<VP8GetValue(tls, br, int32(2)) - int32(1))
  10556 	last_part = uint64((*VP8Decoder)(unsafe.Pointer(dec)).Fnum_parts_minus_one)
  10557 	if size < uint64(3)*last_part {
  10558 		// we can't even read the sizes with sz[]! That's a failure.
  10559 		return int32(VP8_STATUS_NOT_ENOUGH_DATA)
  10560 	}
  10561 	part_start = buf + uintptr(last_part*uint64(3))
  10562 	size_left = size_left - last_part*uint64(3)
  10563 	p = uint64(0)
  10564 	for {
  10565 		if !(p < last_part) {
  10566 			break
  10567 		}
  10568 		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))
  10569 		if psize > size_left {
  10570 			psize = size_left
  10571 		}
  10572 		VP8InitBitReader(tls, dec+440+uintptr(p)*48, part_start, psize)
  10573 		part_start = part_start + uintptr(psize)
  10574 		size_left = size_left - psize
  10575 		sz = sz + uintptr(3)
  10576 		goto _1
  10577 	_1:
  10578 		;
  10579 		p = p + 1
  10580 	}
  10581 	VP8InitBitReader(tls, dec+440+uintptr(last_part)*48, part_start, size_left)
  10582 	if part_start < buf_end {
  10583 		return int32(VP8_STATUS_OK)
  10584 	}
  10585 	if (*VP8Decoder)(unsafe.Pointer(dec)).Fincremental != 0 {
  10586 		v2 = int32(VP8_STATUS_SUSPENDED)
  10587 	} else {
  10588 		v2 = int32(VP8_STATUS_NOT_ENOUGH_DATA)
  10589 	}
  10590 	return v2
  10591 }
  10592 
  10593 // C documentation
  10594 //
  10595 //	// Paragraph 9.4
  10596 func ParseFilterHeader(tls *libc.TLS, br uintptr, dec uintptr) (r int32) {
  10597 	var hdr uintptr
  10598 	var i, v3, v4 int32
  10599 	_, _, _, _ = hdr, i, v3, v4
  10600 	hdr = dec + 84
  10601 	(*VP8FilterHeader)(unsafe.Pointer(hdr)).Fsimple = int32(VP8GetValue(tls, br, int32(1)))
  10602 	(*VP8FilterHeader)(unsafe.Pointer(hdr)).Flevel = int32(VP8GetValue(tls, br, int32(6)))
  10603 	(*VP8FilterHeader)(unsafe.Pointer(hdr)).Fsharpness = int32(VP8GetValue(tls, br, int32(3)))
  10604 	(*VP8FilterHeader)(unsafe.Pointer(hdr)).Fuse_lf_delta = int32(VP8GetValue(tls, br, int32(1)))
  10605 	if (*VP8FilterHeader)(unsafe.Pointer(hdr)).Fuse_lf_delta != 0 {
  10606 		if VP8GetValue(tls, br, int32(1)) != 0 {
  10607 			i = 0
  10608 			for {
  10609 				if !(i < int32(NUM_REF_LF_DELTAS)) {
  10610 					break
  10611 				}
  10612 				if VP8GetValue(tls, br, int32(1)) != 0 {
  10613 					**(**int32)(__ccgo_up(hdr + 16 + uintptr(i)*4)) = VP8GetSignedValue(tls, br, int32(6))
  10614 				}
  10615 				goto _1
  10616 			_1:
  10617 				;
  10618 				i = i + 1
  10619 			}
  10620 			i = 0
  10621 			for {
  10622 				if !(i < int32(NUM_MODE_LF_DELTAS)) {
  10623 					break
  10624 				}
  10625 				if VP8GetValue(tls, br, int32(1)) != 0 {
  10626 					**(**int32)(__ccgo_up(hdr + 32 + uintptr(i)*4)) = VP8GetSignedValue(tls, br, int32(6))
  10627 				}
  10628 				goto _2
  10629 			_2:
  10630 				;
  10631 				i = i + 1
  10632 			}
  10633 		}
  10634 	}
  10635 	if (*VP8FilterHeader)(unsafe.Pointer(hdr)).Flevel == 0 {
  10636 		v3 = 0
  10637 	} else {
  10638 		if (*VP8FilterHeader)(unsafe.Pointer(hdr)).Fsimple != 0 {
  10639 			v4 = int32(1)
  10640 		} else {
  10641 			v4 = int32(2)
  10642 		}
  10643 		v3 = v4
  10644 	}
  10645 	(*VP8Decoder)(unsafe.Pointer(dec)).Ffilter_type = v3
  10646 	return libc.BoolInt32(!((*VP8BitReader)(unsafe.Pointer(br)).Feof != 0))
  10647 }
  10648 
  10649 // C documentation
  10650 //
  10651 //	// Topmost call
  10652 func VP8GetHeaders(tls *libc.TLS, dec uintptr, io uintptr) (r int32) {
  10653 	var bits uint32_t
  10654 	var br, buf, frm_hdr, pic_hdr uintptr
  10655 	var buf_size size_t
  10656 	var status VP8StatusCode1
  10657 	_, _, _, _, _, _, _ = bits, br, buf, buf_size, frm_hdr, pic_hdr, status
  10658 	if dec == libc.UintptrFromInt32(0) {
  10659 		return 0
  10660 	}
  10661 	SetOk(tls, dec)
  10662 	if io == libc.UintptrFromInt32(0) {
  10663 		return VP8SetError(tls, dec, int32(VP8_STATUS_INVALID_PARAM), __ccgo_ts+167)
  10664 	}
  10665 	buf = (*VP8Io)(unsafe.Pointer(io)).Fdata
  10666 	buf_size = (*VP8Io)(unsafe.Pointer(io)).Fdata_size
  10667 	if buf_size < uint64(4) {
  10668 		return VP8SetError(tls, dec, int32(VP8_STATUS_NOT_ENOUGH_DATA), __ccgo_ts+204)
  10669 	}
  10670 	// Paragraph 9.1
  10671 	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))
  10672 	frm_hdr = dec + 68
  10673 	(*VP8FrameHeader)(unsafe.Pointer(frm_hdr)).Fkey_frame = libc.BoolUint8(!(bits&libc.Uint32FromInt32(1) != 0))
  10674 	(*VP8FrameHeader)(unsafe.Pointer(frm_hdr)).Fprofile = uint8(bits >> libc.Int32FromInt32(1) & uint32(7))
  10675 	(*VP8FrameHeader)(unsafe.Pointer(frm_hdr)).Fshow = uint8(bits >> libc.Int32FromInt32(4) & uint32(1))
  10676 	(*VP8FrameHeader)(unsafe.Pointer(frm_hdr)).Fpartition_length = bits >> libc.Int32FromInt32(5)
  10677 	if int32((*VP8FrameHeader)(unsafe.Pointer(frm_hdr)).Fprofile) > int32(3) {
  10678 		return VP8SetError(tls, dec, int32(VP8_STATUS_BITSTREAM_ERROR), __ccgo_ts+222)
  10679 	}
  10680 	if !((*VP8FrameHeader)(unsafe.Pointer(frm_hdr)).Fshow != 0) {
  10681 		return VP8SetError(tls, dec, int32(VP8_STATUS_UNSUPPORTED_FEATURE), __ccgo_ts+253)
  10682 	}
  10683 	buf = buf + uintptr(3)
  10684 	buf_size = buf_size - uint64(3)
  10685 	pic_hdr = dec + 76
  10686 	if (*VP8FrameHeader)(unsafe.Pointer(frm_hdr)).Fkey_frame != 0 {
  10687 		// Paragraph 9.2
  10688 		if buf_size < uint64(7) {
  10689 			return VP8SetError(tls, dec, int32(VP8_STATUS_NOT_ENOUGH_DATA), __ccgo_ts+276)
  10690 		}
  10691 		if !(VP8CheckSignature(tls, buf, buf_size) != 0) {
  10692 			return VP8SetError(tls, dec, int32(VP8_STATUS_BITSTREAM_ERROR), __ccgo_ts+304)
  10693 		}
  10694 		(*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))
  10695 		(*VP8PictureHeader)(unsafe.Pointer(pic_hdr)).Fxscale = uint8(int32(**(**uint8_t)(__ccgo_up(buf + 4))) >> int32(6)) // ratio: 1, 5/4 5/3 or 2
  10696 		(*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))
  10697 		(*VP8PictureHeader)(unsafe.Pointer(pic_hdr)).Fyscale = uint8(int32(**(**uint8_t)(__ccgo_up(buf + 6))) >> int32(6))
  10698 		buf = buf + uintptr(7)
  10699 		buf_size = buf_size - uint64(7)
  10700 		(*VP8Decoder)(unsafe.Pointer(dec)).Fmb_w = (int32((*VP8PictureHeader)(unsafe.Pointer(pic_hdr)).Fwidth) + int32(15)) >> int32(4)
  10701 		(*VP8Decoder)(unsafe.Pointer(dec)).Fmb_h = (int32((*VP8PictureHeader)(unsafe.Pointer(pic_hdr)).Fheight) + int32(15)) >> int32(4)
  10702 		// Setup default output area (can be later modified during io->setup())
  10703 		(*VP8Io)(unsafe.Pointer(io)).Fwidth = int32((*VP8PictureHeader)(unsafe.Pointer(pic_hdr)).Fwidth)
  10704 		(*VP8Io)(unsafe.Pointer(io)).Fheight = int32((*VP8PictureHeader)(unsafe.Pointer(pic_hdr)).Fheight)
  10705 		// IMPORTANT! use some sane dimensions in crop* and scaled* fields.
  10706 		// So they can be used interchangeably without always testing for
  10707 		// 'use_cropping'.
  10708 		(*VP8Io)(unsafe.Pointer(io)).Fuse_cropping = 0
  10709 		(*VP8Io)(unsafe.Pointer(io)).Fcrop_top = 0
  10710 		(*VP8Io)(unsafe.Pointer(io)).Fcrop_left = 0
  10711 		(*VP8Io)(unsafe.Pointer(io)).Fcrop_right = (*VP8Io)(unsafe.Pointer(io)).Fwidth
  10712 		(*VP8Io)(unsafe.Pointer(io)).Fcrop_bottom = (*VP8Io)(unsafe.Pointer(io)).Fheight
  10713 		(*VP8Io)(unsafe.Pointer(io)).Fuse_scaling = 0
  10714 		(*VP8Io)(unsafe.Pointer(io)).Fscaled_width = (*VP8Io)(unsafe.Pointer(io)).Fwidth
  10715 		(*VP8Io)(unsafe.Pointer(io)).Fscaled_height = (*VP8Io)(unsafe.Pointer(io)).Fheight
  10716 		(*VP8Io)(unsafe.Pointer(io)).Fmb_w = (*VP8Io)(unsafe.Pointer(io)).Fwidth  // for soundness
  10717 		(*VP8Io)(unsafe.Pointer(io)).Fmb_h = (*VP8Io)(unsafe.Pointer(io)).Fheight // ditto
  10718 		VP8ResetProba(tls, dec+1192)
  10719 		ResetSegmentHeader(tls, dec+132)
  10720 	}
  10721 	// Check if we have all the partition #0 available, and initialize dec->br
  10722 	// to read this partition (and this partition only).
  10723 	if uint64((*VP8FrameHeader)(unsafe.Pointer(frm_hdr)).Fpartition_length) > buf_size {
  10724 		return VP8SetError(tls, dec, int32(VP8_STATUS_NOT_ENOUGH_DATA), __ccgo_ts+318)
  10725 	}
  10726 	br = dec + 16
  10727 	VP8InitBitReader(tls, br, buf, uint64((*VP8FrameHeader)(unsafe.Pointer(frm_hdr)).Fpartition_length))
  10728 	buf = buf + uintptr((*VP8FrameHeader)(unsafe.Pointer(frm_hdr)).Fpartition_length)
  10729 	buf_size = buf_size - uint64((*VP8FrameHeader)(unsafe.Pointer(frm_hdr)).Fpartition_length)
  10730 	if (*VP8FrameHeader)(unsafe.Pointer(frm_hdr)).Fkey_frame != 0 {
  10731 		(*VP8PictureHeader)(unsafe.Pointer(pic_hdr)).Fcolorspace = uint8(VP8GetValue(tls, br, int32(1)))
  10732 		(*VP8PictureHeader)(unsafe.Pointer(pic_hdr)).Fclamp_type = uint8(VP8GetValue(tls, br, int32(1)))
  10733 	}
  10734 	if !(ParseSegmentHeader(tls, br, dec+132, dec+1192) != 0) {
  10735 		return VP8SetError(tls, dec, int32(VP8_STATUS_BITSTREAM_ERROR), __ccgo_ts+339)
  10736 	}
  10737 	// Filter specs
  10738 	if !(ParseFilterHeader(tls, br, dec) != 0) {
  10739 		return VP8SetError(tls, dec, int32(VP8_STATUS_BITSTREAM_ERROR), __ccgo_ts+367)
  10740 	}
  10741 	status = ParsePartitions(tls, dec, buf, buf_size)
  10742 	if status != int32(VP8_STATUS_OK) {
  10743 		return VP8SetError(tls, dec, status, __ccgo_ts+394)
  10744 	}
  10745 	// quantizer change
  10746 	VP8ParseQuant(tls, dec)
  10747 	// Frame buffer marking
  10748 	if !((*VP8FrameHeader)(unsafe.Pointer(frm_hdr)).Fkey_frame != 0) {
  10749 		return VP8SetError(tls, dec, int32(VP8_STATUS_UNSUPPORTED_FEATURE), __ccgo_ts+418)
  10750 	}
  10751 	VP8GetValue(tls, br, int32(1)) // ignore the value of 'update_proba'
  10752 	VP8ParseProba(tls, br, dec)
  10753 	// sanitized state
  10754 	(*VP8Decoder)(unsafe.Pointer(dec)).Fready = int32(1)
  10755 	return int32(1)
  10756 }
  10757 
  10758 //------------------------------------------------------------------------------
  10759 // Residual decoding (Paragraph 13.2 / 13.3)
  10760 
  10761 var kCat3 = [4]uint8_t{
  10762 	0: uint8(173),
  10763 	1: uint8(148),
  10764 	2: uint8(140),
  10765 }
  10766 var kCat4 = [5]uint8_t{
  10767 	0: uint8(176),
  10768 	1: uint8(155),
  10769 	2: uint8(140),
  10770 	3: uint8(135),
  10771 }
  10772 var kCat5 = [6]uint8_t{
  10773 	0: uint8(180),
  10774 	1: uint8(157),
  10775 	2: uint8(141),
  10776 	3: uint8(134),
  10777 	4: uint8(130),
  10778 }
  10779 var kCat6 = [12]uint8_t{
  10780 	0:  uint8(254),
  10781 	1:  uint8(254),
  10782 	2:  uint8(243),
  10783 	3:  uint8(230),
  10784 	4:  uint8(196),
  10785 	5:  uint8(177),
  10786 	6:  uint8(153),
  10787 	7:  uint8(140),
  10788 	8:  uint8(133),
  10789 	9:  uint8(130),
  10790 	10: uint8(129),
  10791 }
  10792 var kCat3456 = [4]uintptr{
  10793 	0: uintptr(unsafe.Pointer(&kCat3)),
  10794 	1: uintptr(unsafe.Pointer(&kCat4)),
  10795 	2: uintptr(unsafe.Pointer(&kCat5)),
  10796 	3: uintptr(unsafe.Pointer(&kCat6)),
  10797 }
  10798 var kZigzag = [16]uint8_t{
  10799 	1:  uint8(1),
  10800 	2:  uint8(4),
  10801 	3:  uint8(8),
  10802 	4:  uint8(5),
  10803 	5:  uint8(2),
  10804 	6:  uint8(3),
  10805 	7:  uint8(6),
  10806 	8:  uint8(9),
  10807 	9:  uint8(12),
  10808 	10: uint8(13),
  10809 	11: uint8(10),
  10810 	12: uint8(7),
  10811 	13: uint8(11),
  10812 	14: uint8(14),
  10813 	15: uint8(15),
  10814 }
  10815 
  10816 // C documentation
  10817 //
  10818 //	// See section 13-2: https://datatracker.ietf.org/doc/html/rfc6386#section-13.2
  10819 func GetLargeValue(tls *libc.TLS, br2 uintptr, p uintptr) (r int32) {
  10820 	bp := tls.Alloc(16)
  10821 	defer tls.Free(16)
  10822 	var bit, bit0, bit1, cat, pos, shift, v, v13, v15, v21, v23, v5, v7 int32
  10823 	var bits bit_t
  10824 	var range1, split, value range_t
  10825 	var tab, v1, v10, v17, v18, v2, v9 uintptr
  10826 	var v11, v19, v3 uint64_t
  10827 	var _ /* in_bits at bp+0 */ lbit_t
  10828 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  10829 	v1 = br2
  10830 	range1 = (*VP8BitReader)(unsafe.Pointer(v1)).Frange1
  10831 	if (*VP8BitReader)(unsafe.Pointer(v1)).Fbits < libc.Int32FromInt32(0) {
  10832 		v2 = v1
  10833 		if (*VP8BitReader)(unsafe.Pointer(v2)).Fbuf < (*VP8BitReader)(unsafe.Pointer(v2)).Fbuf_max {
  10834 			libc.Xmemcpy(tls, bp, (*VP8BitReader)(unsafe.Pointer(v2)).Fbuf, uint64(8))
  10835 			**(**uintptr)(__ccgo_up(v2 + 16)) += uintptr(libc.Int32FromInt32(BITS) >> libc.Int32FromInt32(3))
  10836 			v3 = libc.X__builtin_bswap64(tls, **(**lbit_t)(__ccgo_up(bp)))
  10837 			goto _4
  10838 		_4:
  10839 			bits = v3
  10840 			bits = bits >> uint64(libc.Int32FromInt32(64)-libc.Int32FromInt32(BITS))
  10841 			(*VP8BitReader)(unsafe.Pointer(v2)).Fvalue = bits | (*VP8BitReader)(unsafe.Pointer(v2)).Fvalue<<libc.Int32FromInt32(BITS)
  10842 			**(**int32)(__ccgo_up(v2 + 12)) += int32(BITS)
  10843 		} else {
  10844 			VP8LoadFinalBytes(tls, v2)
  10845 		}
  10846 	}
  10847 	pos = (*VP8BitReader)(unsafe.Pointer(v1)).Fbits
  10848 	split = range1 * uint32(int32(**(**uint8_t)(__ccgo_up(p + 3)))) >> int32(8)
  10849 	value = uint32((*VP8BitReader)(unsafe.Pointer(v1)).Fvalue >> pos)
  10850 	bit = libc.BoolInt32(value > split)
  10851 	if bit != 0 {
  10852 		range1 = range1 - split
  10853 		**(**bit_t)(__ccgo_up(v1)) -= uint64(split+libc.Uint32FromInt32(1)) << pos
  10854 	} else {
  10855 		range1 = split + uint32(1)
  10856 	}
  10857 	v5 = int32(31) ^ libc.X__builtin_clz(tls, range1)
  10858 	goto _6
  10859 _6:
  10860 	shift = int32(7) ^ v5
  10861 	range1 = range1 << uint32(shift)
  10862 	**(**int32)(__ccgo_up(v1 + 12)) -= shift
  10863 	(*VP8BitReader)(unsafe.Pointer(v1)).Frange1 = range1 - uint32(1)
  10864 	v7 = bit
  10865 	goto _8
  10866 _8:
  10867 	if !(v7 != 0) {
  10868 		v9 = br2
  10869 		range1 = (*VP8BitReader)(unsafe.Pointer(v9)).Frange1
  10870 		if (*VP8BitReader)(unsafe.Pointer(v9)).Fbits < libc.Int32FromInt32(0) {
  10871 			v10 = v9
  10872 			if (*VP8BitReader)(unsafe.Pointer(v10)).Fbuf < (*VP8BitReader)(unsafe.Pointer(v10)).Fbuf_max {
  10873 				libc.Xmemcpy(tls, bp, (*VP8BitReader)(unsafe.Pointer(v10)).Fbuf, uint64(8))
  10874 				**(**uintptr)(__ccgo_up(v10 + 16)) += uintptr(libc.Int32FromInt32(BITS) >> libc.Int32FromInt32(3))
  10875 				v11 = libc.X__builtin_bswap64(tls, **(**lbit_t)(__ccgo_up(bp)))
  10876 				goto _12
  10877 			_12:
  10878 				bits = v11
  10879 				bits = bits >> uint64(libc.Int32FromInt32(64)-libc.Int32FromInt32(BITS))
  10880 				(*VP8BitReader)(unsafe.Pointer(v10)).Fvalue = bits | (*VP8BitReader)(unsafe.Pointer(v10)).Fvalue<<libc.Int32FromInt32(BITS)
  10881 				**(**int32)(__ccgo_up(v10 + 12)) += int32(BITS)
  10882 			} else {
  10883 				VP8LoadFinalBytes(tls, v10)
  10884 			}
  10885 		}
  10886 		pos = (*VP8BitReader)(unsafe.Pointer(v9)).Fbits
  10887 		split = range1 * uint32(int32(**(**uint8_t)(__ccgo_up(p + 4)))) >> int32(8)
  10888 		value = uint32((*VP8BitReader)(unsafe.Pointer(v9)).Fvalue >> pos)
  10889 		bit = libc.BoolInt32(value > split)
  10890 		if bit != 0 {
  10891 			range1 = range1 - split
  10892 			**(**bit_t)(__ccgo_up(v9)) -= uint64(split+libc.Uint32FromInt32(1)) << pos
  10893 		} else {
  10894 			range1 = split + uint32(1)
  10895 		}
  10896 		v13 = int32(31) ^ libc.X__builtin_clz(tls, range1)
  10897 		goto _14
  10898 	_14:
  10899 		shift = int32(7) ^ v13
  10900 		range1 = range1 << uint32(shift)
  10901 		**(**int32)(__ccgo_up(v9 + 12)) -= shift
  10902 		(*VP8BitReader)(unsafe.Pointer(v9)).Frange1 = range1 - uint32(1)
  10903 		v15 = bit
  10904 		goto _16
  10905 	_16:
  10906 		if !(v15 != 0) {
  10907 			v = int32(2)
  10908 		} else {
  10909 			v1 = br2
  10910 			range1 = (*VP8BitReader)(unsafe.Pointer(v1)).Frange1
  10911 			if (*VP8BitReader)(unsafe.Pointer(v1)).Fbits < libc.Int32FromInt32(0) {
  10912 				v2 = v1
  10913 				if (*VP8BitReader)(unsafe.Pointer(v2)).Fbuf < (*VP8BitReader)(unsafe.Pointer(v2)).Fbuf_max {
  10914 					libc.Xmemcpy(tls, bp, (*VP8BitReader)(unsafe.Pointer(v2)).Fbuf, uint64(8))
  10915 					**(**uintptr)(__ccgo_up(v2 + 16)) += uintptr(libc.Int32FromInt32(BITS) >> libc.Int32FromInt32(3))
  10916 					v3 = libc.X__builtin_bswap64(tls, **(**lbit_t)(__ccgo_up(bp)))
  10917 					goto _20
  10918 				_20:
  10919 					bits = v3
  10920 					bits = bits >> uint64(libc.Int32FromInt32(64)-libc.Int32FromInt32(BITS))
  10921 					(*VP8BitReader)(unsafe.Pointer(v2)).Fvalue = bits | (*VP8BitReader)(unsafe.Pointer(v2)).Fvalue<<libc.Int32FromInt32(BITS)
  10922 					**(**int32)(__ccgo_up(v2 + 12)) += int32(BITS)
  10923 				} else {
  10924 					VP8LoadFinalBytes(tls, v2)
  10925 				}
  10926 			}
  10927 			pos = (*VP8BitReader)(unsafe.Pointer(v1)).Fbits
  10928 			split = range1 * uint32(int32(**(**uint8_t)(__ccgo_up(p + 5)))) >> int32(8)
  10929 			value = uint32((*VP8BitReader)(unsafe.Pointer(v1)).Fvalue >> pos)
  10930 			bit = libc.BoolInt32(value > split)
  10931 			if bit != 0 {
  10932 				range1 = range1 - split
  10933 				**(**bit_t)(__ccgo_up(v1)) -= uint64(split+libc.Uint32FromInt32(1)) << pos
  10934 			} else {
  10935 				range1 = split + uint32(1)
  10936 			}
  10937 			v5 = int32(31) ^ libc.X__builtin_clz(tls, range1)
  10938 			goto _22
  10939 		_22:
  10940 			shift = int32(7) ^ v5
  10941 			range1 = range1 << uint32(shift)
  10942 			**(**int32)(__ccgo_up(v1 + 12)) -= shift
  10943 			(*VP8BitReader)(unsafe.Pointer(v1)).Frange1 = range1 - uint32(1)
  10944 			v7 = bit
  10945 			goto _24
  10946 		_24:
  10947 			v = int32(3) + v7
  10948 		}
  10949 	} else {
  10950 		v1 = br2
  10951 		range1 = (*VP8BitReader)(unsafe.Pointer(v1)).Frange1
  10952 		if (*VP8BitReader)(unsafe.Pointer(v1)).Fbits < libc.Int32FromInt32(0) {
  10953 			v2 = v1
  10954 			if (*VP8BitReader)(unsafe.Pointer(v2)).Fbuf < (*VP8BitReader)(unsafe.Pointer(v2)).Fbuf_max {
  10955 				libc.Xmemcpy(tls, bp, (*VP8BitReader)(unsafe.Pointer(v2)).Fbuf, uint64(8))
  10956 				**(**uintptr)(__ccgo_up(v2 + 16)) += uintptr(libc.Int32FromInt32(BITS) >> libc.Int32FromInt32(3))
  10957 				v3 = libc.X__builtin_bswap64(tls, **(**lbit_t)(__ccgo_up(bp)))
  10958 				goto _28
  10959 			_28:
  10960 				bits = v3
  10961 				bits = bits >> uint64(libc.Int32FromInt32(64)-libc.Int32FromInt32(BITS))
  10962 				(*VP8BitReader)(unsafe.Pointer(v2)).Fvalue = bits | (*VP8BitReader)(unsafe.Pointer(v2)).Fvalue<<libc.Int32FromInt32(BITS)
  10963 				**(**int32)(__ccgo_up(v2 + 12)) += int32(BITS)
  10964 			} else {
  10965 				VP8LoadFinalBytes(tls, v2)
  10966 			}
  10967 		}
  10968 		pos = (*VP8BitReader)(unsafe.Pointer(v1)).Fbits
  10969 		split = range1 * uint32(int32(**(**uint8_t)(__ccgo_up(p + 6)))) >> int32(8)
  10970 		value = uint32((*VP8BitReader)(unsafe.Pointer(v1)).Fvalue >> pos)
  10971 		bit = libc.BoolInt32(value > split)
  10972 		if bit != 0 {
  10973 			range1 = range1 - split
  10974 			**(**bit_t)(__ccgo_up(v1)) -= uint64(split+libc.Uint32FromInt32(1)) << pos
  10975 		} else {
  10976 			range1 = split + uint32(1)
  10977 		}
  10978 		v5 = int32(31) ^ libc.X__builtin_clz(tls, range1)
  10979 		goto _30
  10980 	_30:
  10981 		shift = int32(7) ^ v5
  10982 		range1 = range1 << uint32(shift)
  10983 		**(**int32)(__ccgo_up(v1 + 12)) -= shift
  10984 		(*VP8BitReader)(unsafe.Pointer(v1)).Frange1 = range1 - uint32(1)
  10985 		v7 = bit
  10986 		goto _32
  10987 	_32:
  10988 		if !(v7 != 0) {
  10989 			v9 = br2
  10990 			range1 = (*VP8BitReader)(unsafe.Pointer(v9)).Frange1
  10991 			if (*VP8BitReader)(unsafe.Pointer(v9)).Fbits < libc.Int32FromInt32(0) {
  10992 				v10 = v9
  10993 				if (*VP8BitReader)(unsafe.Pointer(v10)).Fbuf < (*VP8BitReader)(unsafe.Pointer(v10)).Fbuf_max {
  10994 					libc.Xmemcpy(tls, bp, (*VP8BitReader)(unsafe.Pointer(v10)).Fbuf, uint64(8))
  10995 					**(**uintptr)(__ccgo_up(v10 + 16)) += uintptr(libc.Int32FromInt32(BITS) >> libc.Int32FromInt32(3))
  10996 					v11 = libc.X__builtin_bswap64(tls, **(**lbit_t)(__ccgo_up(bp)))
  10997 					goto _36
  10998 				_36:
  10999 					bits = v11
  11000 					bits = bits >> uint64(libc.Int32FromInt32(64)-libc.Int32FromInt32(BITS))
  11001 					(*VP8BitReader)(unsafe.Pointer(v10)).Fvalue = bits | (*VP8BitReader)(unsafe.Pointer(v10)).Fvalue<<libc.Int32FromInt32(BITS)
  11002 					**(**int32)(__ccgo_up(v10 + 12)) += int32(BITS)
  11003 				} else {
  11004 					VP8LoadFinalBytes(tls, v10)
  11005 				}
  11006 			}
  11007 			pos = (*VP8BitReader)(unsafe.Pointer(v9)).Fbits
  11008 			split = range1 * uint32(int32(**(**uint8_t)(__ccgo_up(p + 7)))) >> int32(8)
  11009 			value = uint32((*VP8BitReader)(unsafe.Pointer(v9)).Fvalue >> pos)
  11010 			bit = libc.BoolInt32(value > split)
  11011 			if bit != 0 {
  11012 				range1 = range1 - split
  11013 				**(**bit_t)(__ccgo_up(v9)) -= uint64(split+libc.Uint32FromInt32(1)) << pos
  11014 			} else {
  11015 				range1 = split + uint32(1)
  11016 			}
  11017 			v13 = int32(31) ^ libc.X__builtin_clz(tls, range1)
  11018 			goto _38
  11019 		_38:
  11020 			shift = int32(7) ^ v13
  11021 			range1 = range1 << uint32(shift)
  11022 			**(**int32)(__ccgo_up(v9 + 12)) -= shift
  11023 			(*VP8BitReader)(unsafe.Pointer(v9)).Frange1 = range1 - uint32(1)
  11024 			v15 = bit
  11025 			goto _40
  11026 		_40:
  11027 			if !(v15 != 0) {
  11028 				v17 = br2
  11029 				range1 = (*VP8BitReader)(unsafe.Pointer(v17)).Frange1
  11030 				if (*VP8BitReader)(unsafe.Pointer(v17)).Fbits < libc.Int32FromInt32(0) {
  11031 					v18 = v17
  11032 					if (*VP8BitReader)(unsafe.Pointer(v18)).Fbuf < (*VP8BitReader)(unsafe.Pointer(v18)).Fbuf_max {
  11033 						libc.Xmemcpy(tls, bp, (*VP8BitReader)(unsafe.Pointer(v18)).Fbuf, uint64(8))
  11034 						**(**uintptr)(__ccgo_up(v18 + 16)) += uintptr(libc.Int32FromInt32(BITS) >> libc.Int32FromInt32(3))
  11035 						v19 = libc.X__builtin_bswap64(tls, **(**lbit_t)(__ccgo_up(bp)))
  11036 						goto _44
  11037 					_44:
  11038 						bits = v19
  11039 						bits = bits >> uint64(libc.Int32FromInt32(64)-libc.Int32FromInt32(BITS))
  11040 						(*VP8BitReader)(unsafe.Pointer(v18)).Fvalue = bits | (*VP8BitReader)(unsafe.Pointer(v18)).Fvalue<<libc.Int32FromInt32(BITS)
  11041 						**(**int32)(__ccgo_up(v18 + 12)) += int32(BITS)
  11042 					} else {
  11043 						VP8LoadFinalBytes(tls, v18)
  11044 					}
  11045 				}
  11046 				pos = (*VP8BitReader)(unsafe.Pointer(v17)).Fbits
  11047 				split = range1 * uint32(int32(159)) >> int32(8)
  11048 				value = uint32((*VP8BitReader)(unsafe.Pointer(v17)).Fvalue >> pos)
  11049 				bit = libc.BoolInt32(value > split)
  11050 				if bit != 0 {
  11051 					range1 = range1 - split
  11052 					**(**bit_t)(__ccgo_up(v17)) -= uint64(split+libc.Uint32FromInt32(1)) << pos
  11053 				} else {
  11054 					range1 = split + uint32(1)
  11055 				}
  11056 				v21 = int32(31) ^ libc.X__builtin_clz(tls, range1)
  11057 				goto _46
  11058 			_46:
  11059 				shift = int32(7) ^ v21
  11060 				range1 = range1 << uint32(shift)
  11061 				**(**int32)(__ccgo_up(v17 + 12)) -= shift
  11062 				(*VP8BitReader)(unsafe.Pointer(v17)).Frange1 = range1 - uint32(1)
  11063 				v23 = bit
  11064 				goto _48
  11065 			_48:
  11066 				v = int32(5) + v23
  11067 			} else {
  11068 				v1 = br2
  11069 				range1 = (*VP8BitReader)(unsafe.Pointer(v1)).Frange1
  11070 				if (*VP8BitReader)(unsafe.Pointer(v1)).Fbits < libc.Int32FromInt32(0) {
  11071 					v2 = v1
  11072 					if (*VP8BitReader)(unsafe.Pointer(v2)).Fbuf < (*VP8BitReader)(unsafe.Pointer(v2)).Fbuf_max {
  11073 						libc.Xmemcpy(tls, bp, (*VP8BitReader)(unsafe.Pointer(v2)).Fbuf, uint64(8))
  11074 						**(**uintptr)(__ccgo_up(v2 + 16)) += uintptr(libc.Int32FromInt32(BITS) >> libc.Int32FromInt32(3))
  11075 						v3 = libc.X__builtin_bswap64(tls, **(**lbit_t)(__ccgo_up(bp)))
  11076 						goto _52
  11077 					_52:
  11078 						bits = v3
  11079 						bits = bits >> uint64(libc.Int32FromInt32(64)-libc.Int32FromInt32(BITS))
  11080 						(*VP8BitReader)(unsafe.Pointer(v2)).Fvalue = bits | (*VP8BitReader)(unsafe.Pointer(v2)).Fvalue<<libc.Int32FromInt32(BITS)
  11081 						**(**int32)(__ccgo_up(v2 + 12)) += int32(BITS)
  11082 					} else {
  11083 						VP8LoadFinalBytes(tls, v2)
  11084 					}
  11085 				}
  11086 				pos = (*VP8BitReader)(unsafe.Pointer(v1)).Fbits
  11087 				split = range1 * uint32(int32(165)) >> int32(8)
  11088 				value = uint32((*VP8BitReader)(unsafe.Pointer(v1)).Fvalue >> pos)
  11089 				bit = libc.BoolInt32(value > split)
  11090 				if bit != 0 {
  11091 					range1 = range1 - split
  11092 					**(**bit_t)(__ccgo_up(v1)) -= uint64(split+libc.Uint32FromInt32(1)) << pos
  11093 				} else {
  11094 					range1 = split + uint32(1)
  11095 				}
  11096 				v5 = int32(31) ^ libc.X__builtin_clz(tls, range1)
  11097 				goto _54
  11098 			_54:
  11099 				shift = int32(7) ^ v5
  11100 				range1 = range1 << uint32(shift)
  11101 				**(**int32)(__ccgo_up(v1 + 12)) -= shift
  11102 				(*VP8BitReader)(unsafe.Pointer(v1)).Frange1 = range1 - uint32(1)
  11103 				v7 = bit
  11104 				goto _56
  11105 			_56:
  11106 				v = int32(7) + int32(2)*v7
  11107 				v1 = br2
  11108 				range1 = (*VP8BitReader)(unsafe.Pointer(v1)).Frange1
  11109 				if (*VP8BitReader)(unsafe.Pointer(v1)).Fbits < libc.Int32FromInt32(0) {
  11110 					v2 = v1
  11111 					if (*VP8BitReader)(unsafe.Pointer(v2)).Fbuf < (*VP8BitReader)(unsafe.Pointer(v2)).Fbuf_max {
  11112 						libc.Xmemcpy(tls, bp, (*VP8BitReader)(unsafe.Pointer(v2)).Fbuf, uint64(8))
  11113 						**(**uintptr)(__ccgo_up(v2 + 16)) += uintptr(libc.Int32FromInt32(BITS) >> libc.Int32FromInt32(3))
  11114 						v3 = libc.X__builtin_bswap64(tls, **(**lbit_t)(__ccgo_up(bp)))
  11115 						goto _60
  11116 					_60:
  11117 						bits = v3
  11118 						bits = bits >> uint64(libc.Int32FromInt32(64)-libc.Int32FromInt32(BITS))
  11119 						(*VP8BitReader)(unsafe.Pointer(v2)).Fvalue = bits | (*VP8BitReader)(unsafe.Pointer(v2)).Fvalue<<libc.Int32FromInt32(BITS)
  11120 						**(**int32)(__ccgo_up(v2 + 12)) += int32(BITS)
  11121 					} else {
  11122 						VP8LoadFinalBytes(tls, v2)
  11123 					}
  11124 				}
  11125 				pos = (*VP8BitReader)(unsafe.Pointer(v1)).Fbits
  11126 				split = range1 * uint32(int32(145)) >> int32(8)
  11127 				value = uint32((*VP8BitReader)(unsafe.Pointer(v1)).Fvalue >> pos)
  11128 				bit = libc.BoolInt32(value > split)
  11129 				if bit != 0 {
  11130 					range1 = range1 - split
  11131 					**(**bit_t)(__ccgo_up(v1)) -= uint64(split+libc.Uint32FromInt32(1)) << pos
  11132 				} else {
  11133 					range1 = split + uint32(1)
  11134 				}
  11135 				v5 = int32(31) ^ libc.X__builtin_clz(tls, range1)
  11136 				goto _62
  11137 			_62:
  11138 				shift = int32(7) ^ v5
  11139 				range1 = range1 << uint32(shift)
  11140 				**(**int32)(__ccgo_up(v1 + 12)) -= shift
  11141 				(*VP8BitReader)(unsafe.Pointer(v1)).Frange1 = range1 - uint32(1)
  11142 				v7 = bit
  11143 				goto _64
  11144 			_64:
  11145 				v = v + v7
  11146 			}
  11147 		} else {
  11148 			v1 = br2
  11149 			range1 = (*VP8BitReader)(unsafe.Pointer(v1)).Frange1
  11150 			if (*VP8BitReader)(unsafe.Pointer(v1)).Fbits < libc.Int32FromInt32(0) {
  11151 				v2 = v1
  11152 				if (*VP8BitReader)(unsafe.Pointer(v2)).Fbuf < (*VP8BitReader)(unsafe.Pointer(v2)).Fbuf_max {
  11153 					libc.Xmemcpy(tls, bp, (*VP8BitReader)(unsafe.Pointer(v2)).Fbuf, uint64(8))
  11154 					**(**uintptr)(__ccgo_up(v2 + 16)) += uintptr(libc.Int32FromInt32(BITS) >> libc.Int32FromInt32(3))
  11155 					v3 = libc.X__builtin_bswap64(tls, **(**lbit_t)(__ccgo_up(bp)))
  11156 					goto _68
  11157 				_68:
  11158 					bits = v3
  11159 					bits = bits >> uint64(libc.Int32FromInt32(64)-libc.Int32FromInt32(BITS))
  11160 					(*VP8BitReader)(unsafe.Pointer(v2)).Fvalue = bits | (*VP8BitReader)(unsafe.Pointer(v2)).Fvalue<<libc.Int32FromInt32(BITS)
  11161 					**(**int32)(__ccgo_up(v2 + 12)) += int32(BITS)
  11162 				} else {
  11163 					VP8LoadFinalBytes(tls, v2)
  11164 				}
  11165 			}
  11166 			pos = (*VP8BitReader)(unsafe.Pointer(v1)).Fbits
  11167 			split = range1 * uint32(int32(**(**uint8_t)(__ccgo_up(p + 8)))) >> int32(8)
  11168 			value = uint32((*VP8BitReader)(unsafe.Pointer(v1)).Fvalue >> pos)
  11169 			bit = libc.BoolInt32(value > split)
  11170 			if bit != 0 {
  11171 				range1 = range1 - split
  11172 				**(**bit_t)(__ccgo_up(v1)) -= uint64(split+libc.Uint32FromInt32(1)) << pos
  11173 			} else {
  11174 				range1 = split + uint32(1)
  11175 			}
  11176 			v5 = int32(31) ^ libc.X__builtin_clz(tls, range1)
  11177 			goto _70
  11178 		_70:
  11179 			shift = int32(7) ^ v5
  11180 			range1 = range1 << uint32(shift)
  11181 			**(**int32)(__ccgo_up(v1 + 12)) -= shift
  11182 			(*VP8BitReader)(unsafe.Pointer(v1)).Frange1 = range1 - uint32(1)
  11183 			v7 = bit
  11184 			goto _72
  11185 		_72:
  11186 			bit1 = v7
  11187 			v9 = br2
  11188 			range1 = (*VP8BitReader)(unsafe.Pointer(v9)).Frange1
  11189 			if (*VP8BitReader)(unsafe.Pointer(v9)).Fbits < libc.Int32FromInt32(0) {
  11190 				v10 = v9
  11191 				if (*VP8BitReader)(unsafe.Pointer(v10)).Fbuf < (*VP8BitReader)(unsafe.Pointer(v10)).Fbuf_max {
  11192 					libc.Xmemcpy(tls, bp, (*VP8BitReader)(unsafe.Pointer(v10)).Fbuf, uint64(8))
  11193 					**(**uintptr)(__ccgo_up(v10 + 16)) += uintptr(libc.Int32FromInt32(BITS) >> libc.Int32FromInt32(3))
  11194 					v11 = libc.X__builtin_bswap64(tls, **(**lbit_t)(__ccgo_up(bp)))
  11195 					goto _76
  11196 				_76:
  11197 					bits = v11
  11198 					bits = bits >> uint64(libc.Int32FromInt32(64)-libc.Int32FromInt32(BITS))
  11199 					(*VP8BitReader)(unsafe.Pointer(v10)).Fvalue = bits | (*VP8BitReader)(unsafe.Pointer(v10)).Fvalue<<libc.Int32FromInt32(BITS)
  11200 					**(**int32)(__ccgo_up(v10 + 12)) += int32(BITS)
  11201 				} else {
  11202 					VP8LoadFinalBytes(tls, v10)
  11203 				}
  11204 			}
  11205 			pos = (*VP8BitReader)(unsafe.Pointer(v9)).Fbits
  11206 			split = range1 * uint32(int32(**(**uint8_t)(__ccgo_up(p + uintptr(int32(9)+bit1))))) >> int32(8)
  11207 			value = uint32((*VP8BitReader)(unsafe.Pointer(v9)).Fvalue >> pos)
  11208 			bit = libc.BoolInt32(value > split)
  11209 			if bit != 0 {
  11210 				range1 = range1 - split
  11211 				**(**bit_t)(__ccgo_up(v9)) -= uint64(split+libc.Uint32FromInt32(1)) << pos
  11212 			} else {
  11213 				range1 = split + uint32(1)
  11214 			}
  11215 			v13 = int32(31) ^ libc.X__builtin_clz(tls, range1)
  11216 			goto _78
  11217 		_78:
  11218 			shift = int32(7) ^ v13
  11219 			range1 = range1 << uint32(shift)
  11220 			**(**int32)(__ccgo_up(v9 + 12)) -= shift
  11221 			(*VP8BitReader)(unsafe.Pointer(v9)).Frange1 = range1 - uint32(1)
  11222 			v15 = bit
  11223 			goto _80
  11224 		_80:
  11225 			bit0 = v15
  11226 			cat = int32(2)*bit1 + bit0
  11227 			v = 0
  11228 			tab = kCat3456[cat]
  11229 			for {
  11230 				if !(**(**uint8_t)(__ccgo_up(tab)) != 0) {
  11231 					break
  11232 				}
  11233 				v1 = br2
  11234 				range1 = (*VP8BitReader)(unsafe.Pointer(v1)).Frange1
  11235 				if (*VP8BitReader)(unsafe.Pointer(v1)).Fbits < libc.Int32FromInt32(0) {
  11236 					v2 = v1
  11237 					if (*VP8BitReader)(unsafe.Pointer(v2)).Fbuf < (*VP8BitReader)(unsafe.Pointer(v2)).Fbuf_max {
  11238 						libc.Xmemcpy(tls, bp, (*VP8BitReader)(unsafe.Pointer(v2)).Fbuf, uint64(8))
  11239 						**(**uintptr)(__ccgo_up(v2 + 16)) += uintptr(libc.Int32FromInt32(BITS) >> libc.Int32FromInt32(3))
  11240 						v3 = libc.X__builtin_bswap64(tls, **(**lbit_t)(__ccgo_up(bp)))
  11241 						goto _85
  11242 					_85:
  11243 						bits = v3
  11244 						bits = bits >> uint64(libc.Int32FromInt32(64)-libc.Int32FromInt32(BITS))
  11245 						(*VP8BitReader)(unsafe.Pointer(v2)).Fvalue = bits | (*VP8BitReader)(unsafe.Pointer(v2)).Fvalue<<libc.Int32FromInt32(BITS)
  11246 						**(**int32)(__ccgo_up(v2 + 12)) += int32(BITS)
  11247 					} else {
  11248 						VP8LoadFinalBytes(tls, v2)
  11249 					}
  11250 				}
  11251 				pos = (*VP8BitReader)(unsafe.Pointer(v1)).Fbits
  11252 				split = range1 * uint32(int32(**(**uint8_t)(__ccgo_up(tab)))) >> int32(8)
  11253 				value = uint32((*VP8BitReader)(unsafe.Pointer(v1)).Fvalue >> pos)
  11254 				bit = libc.BoolInt32(value > split)
  11255 				if bit != 0 {
  11256 					range1 = range1 - split
  11257 					**(**bit_t)(__ccgo_up(v1)) -= uint64(split+libc.Uint32FromInt32(1)) << pos
  11258 				} else {
  11259 					range1 = split + uint32(1)
  11260 				}
  11261 				v5 = int32(31) ^ libc.X__builtin_clz(tls, range1)
  11262 				goto _87
  11263 			_87:
  11264 				shift = int32(7) ^ v5
  11265 				range1 = range1 << uint32(shift)
  11266 				**(**int32)(__ccgo_up(v1 + 12)) -= shift
  11267 				(*VP8BitReader)(unsafe.Pointer(v1)).Frange1 = range1 - uint32(1)
  11268 				v7 = bit
  11269 				goto _89
  11270 			_89:
  11271 				v = v + (v + v7)
  11272 				goto _81
  11273 			_81:
  11274 				;
  11275 				tab = tab + 1
  11276 			}
  11277 			v = v + (int32(3) + int32(8)<<cat)
  11278 		}
  11279 	}
  11280 	return v
  11281 }
  11282 
  11283 // C documentation
  11284 //
  11285 //	// Returns the position of the last non-zero coeff plus one
  11286 func GetCoeffsFast(tls *libc.TLS, br3 uintptr, prob1 uintptr, ctx int32, dq uintptr, n1 int32, out uintptr) (r int32) {
  11287 	bp := tls.Alloc(16)
  11288 	defer tls.Free(16)
  11289 	var bit, pos, pos1, shift, v1, v14, v6, v8 int32
  11290 	var bits bit_t
  11291 	var mask int32_t
  11292 	var p, p_ctx, v2, v3 uintptr
  11293 	var range1, split, split1, value, value1 range_t
  11294 	var v4 uint64_t
  11295 	var _ /* in_bits at bp+0 */ lbit_t
  11296 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = bit, bits, mask, p, p_ctx, pos, pos1, range1, shift, split, split1, v1, value, value1, v14, v2, v3, v4, v6, v8
  11297 	p = **(**uintptr)(__ccgo_up(prob1 + uintptr(n1)*8)) + uintptr(ctx)*11
  11298 	for {
  11299 		if !(n1 < int32(16)) {
  11300 			break
  11301 		}
  11302 		v2 = br3
  11303 		range1 = (*VP8BitReader)(unsafe.Pointer(v2)).Frange1
  11304 		if (*VP8BitReader)(unsafe.Pointer(v2)).Fbits < libc.Int32FromInt32(0) {
  11305 			v3 = v2
  11306 			if (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf < (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf_max {
  11307 				libc.Xmemcpy(tls, bp, (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf, uint64(8))
  11308 				**(**uintptr)(__ccgo_up(v3 + 16)) += uintptr(libc.Int32FromInt32(BITS) >> libc.Int32FromInt32(3))
  11309 				v4 = libc.X__builtin_bswap64(tls, **(**lbit_t)(__ccgo_up(bp)))
  11310 				goto _5
  11311 			_5:
  11312 				bits = v4
  11313 				bits = bits >> uint64(libc.Int32FromInt32(64)-libc.Int32FromInt32(BITS))
  11314 				(*VP8BitReader)(unsafe.Pointer(v3)).Fvalue = bits | (*VP8BitReader)(unsafe.Pointer(v3)).Fvalue<<libc.Int32FromInt32(BITS)
  11315 				**(**int32)(__ccgo_up(v3 + 12)) += int32(BITS)
  11316 			} else {
  11317 				VP8LoadFinalBytes(tls, v3)
  11318 			}
  11319 		}
  11320 		pos = (*VP8BitReader)(unsafe.Pointer(v2)).Fbits
  11321 		split = range1 * uint32(int32(**(**uint8_t)(__ccgo_up(p)))) >> int32(8)
  11322 		value = uint32((*VP8BitReader)(unsafe.Pointer(v2)).Fvalue >> pos)
  11323 		bit = libc.BoolInt32(value > split)
  11324 		if bit != 0 {
  11325 			range1 = range1 - split
  11326 			**(**bit_t)(__ccgo_up(v2)) -= uint64(split+libc.Uint32FromInt32(1)) << pos
  11327 		} else {
  11328 			range1 = split + uint32(1)
  11329 		}
  11330 		v6 = int32(31) ^ libc.X__builtin_clz(tls, range1)
  11331 		goto _7
  11332 	_7:
  11333 		shift = int32(7) ^ v6
  11334 		range1 = range1 << uint32(shift)
  11335 		**(**int32)(__ccgo_up(v2 + 12)) -= shift
  11336 		(*VP8BitReader)(unsafe.Pointer(v2)).Frange1 = range1 - uint32(1)
  11337 		v8 = bit
  11338 		goto _9
  11339 	_9:
  11340 		if !(v8 != 0) {
  11341 			return n1 // previous coeff was last non-zero coeff
  11342 		}
  11343 		for {
  11344 			v2 = br3
  11345 			range1 = (*VP8BitReader)(unsafe.Pointer(v2)).Frange1
  11346 			if (*VP8BitReader)(unsafe.Pointer(v2)).Fbits < libc.Int32FromInt32(0) {
  11347 				v3 = v2
  11348 				if (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf < (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf_max {
  11349 					libc.Xmemcpy(tls, bp, (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf, uint64(8))
  11350 					**(**uintptr)(__ccgo_up(v3 + 16)) += uintptr(libc.Int32FromInt32(BITS) >> libc.Int32FromInt32(3))
  11351 					v4 = libc.X__builtin_bswap64(tls, **(**lbit_t)(__ccgo_up(bp)))
  11352 					goto _13
  11353 				_13:
  11354 					bits = v4
  11355 					bits = bits >> uint64(libc.Int32FromInt32(64)-libc.Int32FromInt32(BITS))
  11356 					(*VP8BitReader)(unsafe.Pointer(v3)).Fvalue = bits | (*VP8BitReader)(unsafe.Pointer(v3)).Fvalue<<libc.Int32FromInt32(BITS)
  11357 					**(**int32)(__ccgo_up(v3 + 12)) += int32(BITS)
  11358 				} else {
  11359 					VP8LoadFinalBytes(tls, v3)
  11360 				}
  11361 			}
  11362 			pos = (*VP8BitReader)(unsafe.Pointer(v2)).Fbits
  11363 			split = range1 * uint32(int32(**(**uint8_t)(__ccgo_up(p + 1)))) >> int32(8)
  11364 			value = uint32((*VP8BitReader)(unsafe.Pointer(v2)).Fvalue >> pos)
  11365 			bit = libc.BoolInt32(value > split)
  11366 			if bit != 0 {
  11367 				range1 = range1 - split
  11368 				**(**bit_t)(__ccgo_up(v2)) -= uint64(split+libc.Uint32FromInt32(1)) << pos
  11369 			} else {
  11370 				range1 = split + uint32(1)
  11371 			}
  11372 			v6 = int32(31) ^ libc.X__builtin_clz(tls, range1)
  11373 			goto _15
  11374 		_15:
  11375 			shift = int32(7) ^ v6
  11376 			range1 = range1 << uint32(shift)
  11377 			**(**int32)(__ccgo_up(v2 + 12)) -= shift
  11378 			(*VP8BitReader)(unsafe.Pointer(v2)).Frange1 = range1 - uint32(1)
  11379 			v8 = bit
  11380 			goto _17
  11381 		_17:
  11382 			if !!(v8 != 0) {
  11383 				break
  11384 			} // sequence of zero coeffs
  11385 			n1 = n1 + 1
  11386 			v14 = n1
  11387 			p = **(**uintptr)(__ccgo_up(prob1 + uintptr(v14)*8))
  11388 			if n1 == int32(16) {
  11389 				return int32(16)
  11390 			}
  11391 		}
  11392 		// non zero coeff
  11393 		p_ctx = **(**uintptr)(__ccgo_up(prob1 + uintptr(n1+int32(1))*8))
  11394 		v2 = br3
  11395 		range1 = (*VP8BitReader)(unsafe.Pointer(v2)).Frange1
  11396 		if (*VP8BitReader)(unsafe.Pointer(v2)).Fbits < libc.Int32FromInt32(0) {
  11397 			v3 = v2
  11398 			if (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf < (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf_max {
  11399 				libc.Xmemcpy(tls, bp, (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf, uint64(8))
  11400 				**(**uintptr)(__ccgo_up(v3 + 16)) += uintptr(libc.Int32FromInt32(BITS) >> libc.Int32FromInt32(3))
  11401 				v4 = libc.X__builtin_bswap64(tls, **(**lbit_t)(__ccgo_up(bp)))
  11402 				goto _22
  11403 			_22:
  11404 				bits = v4
  11405 				bits = bits >> uint64(libc.Int32FromInt32(64)-libc.Int32FromInt32(BITS))
  11406 				(*VP8BitReader)(unsafe.Pointer(v3)).Fvalue = bits | (*VP8BitReader)(unsafe.Pointer(v3)).Fvalue<<libc.Int32FromInt32(BITS)
  11407 				**(**int32)(__ccgo_up(v3 + 12)) += int32(BITS)
  11408 			} else {
  11409 				VP8LoadFinalBytes(tls, v3)
  11410 			}
  11411 		}
  11412 		pos = (*VP8BitReader)(unsafe.Pointer(v2)).Fbits
  11413 		split = range1 * uint32(int32(**(**uint8_t)(__ccgo_up(p + 2)))) >> int32(8)
  11414 		value = uint32((*VP8BitReader)(unsafe.Pointer(v2)).Fvalue >> pos)
  11415 		bit = libc.BoolInt32(value > split)
  11416 		if bit != 0 {
  11417 			range1 = range1 - split
  11418 			**(**bit_t)(__ccgo_up(v2)) -= uint64(split+libc.Uint32FromInt32(1)) << pos
  11419 		} else {
  11420 			range1 = split + uint32(1)
  11421 		}
  11422 		v6 = int32(31) ^ libc.X__builtin_clz(tls, range1)
  11423 		goto _24
  11424 	_24:
  11425 		shift = int32(7) ^ v6
  11426 		range1 = range1 << uint32(shift)
  11427 		**(**int32)(__ccgo_up(v2 + 12)) -= shift
  11428 		(*VP8BitReader)(unsafe.Pointer(v2)).Frange1 = range1 - uint32(1)
  11429 		v8 = bit
  11430 		goto _26
  11431 	_26:
  11432 		if !(v8 != 0) {
  11433 			v1 = int32(1)
  11434 			p = p_ctx + 1*11
  11435 		} else {
  11436 			v1 = GetLargeValue(tls, br3, p)
  11437 			p = p_ctx + 2*11
  11438 		}
  11439 		v2 = br3
  11440 		if (*VP8BitReader)(unsafe.Pointer(v2)).Fbits < libc.Int32FromInt32(0) {
  11441 			v3 = v2
  11442 			if (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf < (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf_max {
  11443 				libc.Xmemcpy(tls, bp, (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf, uint64(8))
  11444 				**(**uintptr)(__ccgo_up(v3 + 16)) += uintptr(libc.Int32FromInt32(BITS) >> libc.Int32FromInt32(3))
  11445 				v4 = libc.X__builtin_bswap64(tls, **(**lbit_t)(__ccgo_up(bp)))
  11446 				goto _30
  11447 			_30:
  11448 				bits = v4
  11449 				bits = bits >> uint64(libc.Int32FromInt32(64)-libc.Int32FromInt32(BITS))
  11450 				(*VP8BitReader)(unsafe.Pointer(v3)).Fvalue = bits | (*VP8BitReader)(unsafe.Pointer(v3)).Fvalue<<libc.Int32FromInt32(BITS)
  11451 				**(**int32)(__ccgo_up(v3 + 12)) += int32(BITS)
  11452 			} else {
  11453 				VP8LoadFinalBytes(tls, v3)
  11454 			}
  11455 		}
  11456 		pos1 = (*VP8BitReader)(unsafe.Pointer(v2)).Fbits
  11457 		split1 = (*VP8BitReader)(unsafe.Pointer(v2)).Frange1 >> int32(1)
  11458 		value1 = uint32((*VP8BitReader)(unsafe.Pointer(v2)).Fvalue >> pos1)
  11459 		mask = int32(split1-value1) >> int32(31)
  11460 		**(**int32)(__ccgo_up(v2 + 12)) -= int32(1)
  11461 		**(**range_t)(__ccgo_up(v2 + 8)) += uint32(mask)
  11462 		**(**range_t)(__ccgo_up(v2 + 8)) |= uint32(1)
  11463 		**(**bit_t)(__ccgo_up(v2)) -= uint64((split1+libc.Uint32FromInt32(1))&uint32(mask)) << pos1
  11464 		v6 = v1 ^ mask - mask
  11465 		goto _32
  11466 	_32:
  11467 		**(**int16_t)(__ccgo_up(out + uintptr(kZigzag[n1])*2)) = int16(v6 * **(**int32)(__ccgo_up(dq + libc.BoolUintptr(n1 > 0)*4)))
  11468 		goto _1
  11469 	_1:
  11470 		;
  11471 		n1 = n1 + 1
  11472 	}
  11473 	return int32(16)
  11474 }
  11475 
  11476 // C documentation
  11477 //
  11478 //	// This version of GetCoeffs() uses VP8GetBitAlt() which is an alternate version
  11479 //	// of VP8GetBitAlt() targeting specific platforms.
  11480 func GetCoeffsAlt(tls *libc.TLS, br3 uintptr, prob1 uintptr, ctx int32, dq uintptr, n int32, out uintptr) (r int32) {
  11481 	bp := tls.Alloc(16)
  11482 	defer tls.Free(16)
  11483 	var bit, pos, pos1, shift, v1, v12, v6 int32
  11484 	var bits bit_t
  11485 	var mask int32_t
  11486 	var p, p_ctx, v2, v3 uintptr
  11487 	var range1, split, split1, value, value1 range_t
  11488 	var v4 uint64_t
  11489 	var _ /* in_bits at bp+0 */ lbit_t
  11490 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = bit, bits, mask, p, p_ctx, pos, pos1, range1, shift, split, split1, v1, value, value1, v12, v2, v3, v4, v6
  11491 	p = **(**uintptr)(__ccgo_up(prob1 + uintptr(n)*8)) + uintptr(ctx)*11
  11492 	for {
  11493 		if !(n < int32(16)) {
  11494 			break
  11495 		}
  11496 		v2 = br3
  11497 		range1 = (*VP8BitReader)(unsafe.Pointer(v2)).Frange1
  11498 		if (*VP8BitReader)(unsafe.Pointer(v2)).Fbits < libc.Int32FromInt32(0) {
  11499 			v3 = v2
  11500 			if (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf < (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf_max {
  11501 				libc.Xmemcpy(tls, bp, (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf, uint64(8))
  11502 				**(**uintptr)(__ccgo_up(v3 + 16)) += uintptr(libc.Int32FromInt32(BITS) >> libc.Int32FromInt32(3))
  11503 				v4 = libc.X__builtin_bswap64(tls, **(**lbit_t)(__ccgo_up(bp)))
  11504 				goto _5
  11505 			_5:
  11506 				bits = v4
  11507 				bits = bits >> uint64(libc.Int32FromInt32(64)-libc.Int32FromInt32(BITS))
  11508 				(*VP8BitReader)(unsafe.Pointer(v3)).Fvalue = bits | (*VP8BitReader)(unsafe.Pointer(v3)).Fvalue<<libc.Int32FromInt32(BITS)
  11509 				**(**int32)(__ccgo_up(v3 + 12)) += int32(BITS)
  11510 			} else {
  11511 				VP8LoadFinalBytes(tls, v3)
  11512 			}
  11513 		}
  11514 		pos1 = (*VP8BitReader)(unsafe.Pointer(v2)).Fbits
  11515 		split1 = range1 * uint32(int32(**(**uint8_t)(__ccgo_up(p)))) >> int32(8)
  11516 		value1 = uint32((*VP8BitReader)(unsafe.Pointer(v2)).Fvalue >> pos1)
  11517 		if value1 > split1 {
  11518 			range1 = range1 - (split1 + uint32(1))
  11519 			**(**bit_t)(__ccgo_up(v2)) -= uint64(split1+libc.Uint32FromInt32(1)) << pos1
  11520 			bit = int32(1)
  11521 		} else {
  11522 			range1 = split1
  11523 			bit = 0
  11524 		}
  11525 		if range1 <= libc.Uint32FromInt32(0x7e) {
  11526 			shift = int32(kVP8Log2Range[range1])
  11527 			range1 = uint32(kVP8NewRange[range1])
  11528 			**(**int32)(__ccgo_up(v2 + 12)) -= shift
  11529 		}
  11530 		(*VP8BitReader)(unsafe.Pointer(v2)).Frange1 = range1
  11531 		v6 = bit
  11532 		goto _7
  11533 	_7:
  11534 		if !(v6 != 0) {
  11535 			return n // previous coeff was last non-zero coeff
  11536 		}
  11537 		for {
  11538 			v2 = br3
  11539 			range1 = (*VP8BitReader)(unsafe.Pointer(v2)).Frange1
  11540 			if (*VP8BitReader)(unsafe.Pointer(v2)).Fbits < libc.Int32FromInt32(0) {
  11541 				v3 = v2
  11542 				if (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf < (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf_max {
  11543 					libc.Xmemcpy(tls, bp, (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf, uint64(8))
  11544 					**(**uintptr)(__ccgo_up(v3 + 16)) += uintptr(libc.Int32FromInt32(BITS) >> libc.Int32FromInt32(3))
  11545 					v4 = libc.X__builtin_bswap64(tls, **(**lbit_t)(__ccgo_up(bp)))
  11546 					goto _11
  11547 				_11:
  11548 					bits = v4
  11549 					bits = bits >> uint64(libc.Int32FromInt32(64)-libc.Int32FromInt32(BITS))
  11550 					(*VP8BitReader)(unsafe.Pointer(v3)).Fvalue = bits | (*VP8BitReader)(unsafe.Pointer(v3)).Fvalue<<libc.Int32FromInt32(BITS)
  11551 					**(**int32)(__ccgo_up(v3 + 12)) += int32(BITS)
  11552 				} else {
  11553 					VP8LoadFinalBytes(tls, v3)
  11554 				}
  11555 			}
  11556 			pos1 = (*VP8BitReader)(unsafe.Pointer(v2)).Fbits
  11557 			split1 = range1 * uint32(int32(**(**uint8_t)(__ccgo_up(p + 1)))) >> int32(8)
  11558 			value1 = uint32((*VP8BitReader)(unsafe.Pointer(v2)).Fvalue >> pos1)
  11559 			if value1 > split1 {
  11560 				range1 = range1 - (split1 + uint32(1))
  11561 				**(**bit_t)(__ccgo_up(v2)) -= uint64(split1+libc.Uint32FromInt32(1)) << pos1
  11562 				bit = int32(1)
  11563 			} else {
  11564 				range1 = split1
  11565 				bit = 0
  11566 			}
  11567 			if range1 <= libc.Uint32FromInt32(0x7e) {
  11568 				shift = int32(kVP8Log2Range[range1])
  11569 				range1 = uint32(kVP8NewRange[range1])
  11570 				**(**int32)(__ccgo_up(v2 + 12)) -= shift
  11571 			}
  11572 			(*VP8BitReader)(unsafe.Pointer(v2)).Frange1 = range1
  11573 			v6 = bit
  11574 			goto _13
  11575 		_13:
  11576 			if !!(v6 != 0) {
  11577 				break
  11578 			} // sequence of zero coeffs
  11579 			n = n + 1
  11580 			v12 = n
  11581 			p = **(**uintptr)(__ccgo_up(prob1 + uintptr(v12)*8))
  11582 			if n == int32(16) {
  11583 				return int32(16)
  11584 			}
  11585 		}
  11586 		// non zero coeff
  11587 		p_ctx = **(**uintptr)(__ccgo_up(prob1 + uintptr(n+int32(1))*8))
  11588 		v2 = br3
  11589 		range1 = (*VP8BitReader)(unsafe.Pointer(v2)).Frange1
  11590 		if (*VP8BitReader)(unsafe.Pointer(v2)).Fbits < libc.Int32FromInt32(0) {
  11591 			v3 = v2
  11592 			if (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf < (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf_max {
  11593 				libc.Xmemcpy(tls, bp, (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf, uint64(8))
  11594 				**(**uintptr)(__ccgo_up(v3 + 16)) += uintptr(libc.Int32FromInt32(BITS) >> libc.Int32FromInt32(3))
  11595 				v4 = libc.X__builtin_bswap64(tls, **(**lbit_t)(__ccgo_up(bp)))
  11596 				goto _18
  11597 			_18:
  11598 				bits = v4
  11599 				bits = bits >> uint64(libc.Int32FromInt32(64)-libc.Int32FromInt32(BITS))
  11600 				(*VP8BitReader)(unsafe.Pointer(v3)).Fvalue = bits | (*VP8BitReader)(unsafe.Pointer(v3)).Fvalue<<libc.Int32FromInt32(BITS)
  11601 				**(**int32)(__ccgo_up(v3 + 12)) += int32(BITS)
  11602 			} else {
  11603 				VP8LoadFinalBytes(tls, v3)
  11604 			}
  11605 		}
  11606 		pos1 = (*VP8BitReader)(unsafe.Pointer(v2)).Fbits
  11607 		split1 = range1 * uint32(int32(**(**uint8_t)(__ccgo_up(p + 2)))) >> int32(8)
  11608 		value1 = uint32((*VP8BitReader)(unsafe.Pointer(v2)).Fvalue >> pos1)
  11609 		if value1 > split1 {
  11610 			range1 = range1 - (split1 + uint32(1))
  11611 			**(**bit_t)(__ccgo_up(v2)) -= uint64(split1+libc.Uint32FromInt32(1)) << pos1
  11612 			bit = int32(1)
  11613 		} else {
  11614 			range1 = split1
  11615 			bit = 0
  11616 		}
  11617 		if range1 <= libc.Uint32FromInt32(0x7e) {
  11618 			shift = int32(kVP8Log2Range[range1])
  11619 			range1 = uint32(kVP8NewRange[range1])
  11620 			**(**int32)(__ccgo_up(v2 + 12)) -= shift
  11621 		}
  11622 		(*VP8BitReader)(unsafe.Pointer(v2)).Frange1 = range1
  11623 		v6 = bit
  11624 		goto _20
  11625 	_20:
  11626 		if !(v6 != 0) {
  11627 			v1 = int32(1)
  11628 			p = p_ctx + 1*11
  11629 		} else {
  11630 			v1 = GetLargeValue(tls, br3, p)
  11631 			p = p_ctx + 2*11
  11632 		}
  11633 		v2 = br3
  11634 		if (*VP8BitReader)(unsafe.Pointer(v2)).Fbits < libc.Int32FromInt32(0) {
  11635 			v3 = v2
  11636 			if (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf < (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf_max {
  11637 				libc.Xmemcpy(tls, bp, (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf, uint64(8))
  11638 				**(**uintptr)(__ccgo_up(v3 + 16)) += uintptr(libc.Int32FromInt32(BITS) >> libc.Int32FromInt32(3))
  11639 				v4 = libc.X__builtin_bswap64(tls, **(**lbit_t)(__ccgo_up(bp)))
  11640 				goto _24
  11641 			_24:
  11642 				bits = v4
  11643 				bits = bits >> uint64(libc.Int32FromInt32(64)-libc.Int32FromInt32(BITS))
  11644 				(*VP8BitReader)(unsafe.Pointer(v3)).Fvalue = bits | (*VP8BitReader)(unsafe.Pointer(v3)).Fvalue<<libc.Int32FromInt32(BITS)
  11645 				**(**int32)(__ccgo_up(v3 + 12)) += int32(BITS)
  11646 			} else {
  11647 				VP8LoadFinalBytes(tls, v3)
  11648 			}
  11649 		}
  11650 		pos = (*VP8BitReader)(unsafe.Pointer(v2)).Fbits
  11651 		split = (*VP8BitReader)(unsafe.Pointer(v2)).Frange1 >> int32(1)
  11652 		value = uint32((*VP8BitReader)(unsafe.Pointer(v2)).Fvalue >> pos)
  11653 		mask = int32(split-value) >> int32(31)
  11654 		**(**int32)(__ccgo_up(v2 + 12)) -= int32(1)
  11655 		**(**range_t)(__ccgo_up(v2 + 8)) += uint32(mask)
  11656 		**(**range_t)(__ccgo_up(v2 + 8)) |= uint32(1)
  11657 		**(**bit_t)(__ccgo_up(v2)) -= uint64((split+libc.Uint32FromInt32(1))&uint32(mask)) << pos
  11658 		v6 = v1 ^ mask - mask
  11659 		goto _26
  11660 	_26:
  11661 		**(**int16_t)(__ccgo_up(out + uintptr(kZigzag[n])*2)) = int16(v6 * **(**int32)(__ccgo_up(dq + libc.BoolUintptr(n > 0)*4)))
  11662 		goto _1
  11663 	_1:
  11664 		;
  11665 		n = n + 1
  11666 	}
  11667 	return int32(16)
  11668 }
  11669 
  11670 func InitGetCoeffs(tls *libc.TLS) {
  11671 	if libc.AtomicLoadPUintptr(uintptr(unsafe.Pointer(&InitGetCoeffs_body_last_cpuinfo_used))) == VP8GetCPUInfo {
  11672 		goto _1
  11673 	}
  11674 	InitGetCoeffs_body(tls)
  11675 	libc.AtomicStorePUintptr(uintptr(unsafe.Pointer(&InitGetCoeffs_body_last_cpuinfo_used)), VP8GetCPUInfo)
  11676 	goto _2
  11677 _2:
  11678 	;
  11679 	goto _1
  11680 _1: /**/ //
  11681 }
  11682 
  11683 var InitGetCoeffs_body_last_cpuinfo_used = uintptr(0)
  11684 
  11685 func init() {
  11686 	p := unsafe.Pointer(&InitGetCoeffs_body_last_cpuinfo_used)
  11687 	*(*uintptr)(unsafe.Add(p, 0)) = uintptr(unsafe.Pointer(&InitGetCoeffs_body_last_cpuinfo_used))
  11688 }
  11689 
  11690 func InitGetCoeffs_body(tls *libc.TLS) {
  11691 	if VP8GetCPUInfo != libc.UintptrFromInt32(0) && (*(*func(*libc.TLS, CPUFeature) int32)(unsafe.Pointer(&struct{ uintptr }{VP8GetCPUInfo})))(tls, int32(kSlowSSSE3)) != 0 {
  11692 		GetCoeffs = __ccgo_fp(GetCoeffsAlt)
  11693 	} else {
  11694 		GetCoeffs = __ccgo_fp(GetCoeffsFast)
  11695 	}
  11696 }
  11697 
  11698 func NzCodeBits(tls *libc.TLS, nz_coeffs uint32_t, nz int32, dc_nz int32) (r uint32_t) {
  11699 	var v1, v2 int32
  11700 	_, _ = v1, v2
  11701 	nz_coeffs = nz_coeffs << uint32(2)
  11702 	if nz > int32(3) {
  11703 		v1 = int32(3)
  11704 	} else {
  11705 		if nz > int32(1) {
  11706 			v2 = int32(2)
  11707 		} else {
  11708 			v2 = dc_nz
  11709 		}
  11710 		v1 = v2
  11711 	}
  11712 	nz_coeffs = nz_coeffs | uint32(v1)
  11713 	return nz_coeffs
  11714 }
  11715 
  11716 func ParseResiduals(tls *libc.TLS, dec uintptr, mb uintptr, token_br uintptr) (r int32) {
  11717 	bp := tls.Alloc(32)
  11718 	defer tls.Free(32)
  11719 	var ac_proba, bands, block, dst, left_mb, q uintptr
  11720 	var ch, ctx, ctx1, ctx2, dc0, first, i, l, l1, nz, nz1, nz2, x, y, v8 int32
  11721 	var lnz, tnz, v1 uint8_t
  11722 	var non_zero_uv, non_zero_y, nz_coeffs, nz_coeffs1, out_l_nz, out_t_nz uint32_t
  11723 	var _ /* dc at bp+0 */ [16]int16_t
  11724 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  11725 	bands = dec + 1192 + 1064
  11726 	block = (*VP8Decoder)(unsafe.Pointer(dec)).Fmb_data + uintptr((*VP8Decoder)(unsafe.Pointer(dec)).Fmb_x)*800
  11727 	q = dec + 1060 + uintptr((*VP8MBData)(unsafe.Pointer(block)).Fsegment)*32
  11728 	dst = block
  11729 	left_mb = (*VP8Decoder)(unsafe.Pointer(dec)).Fmb_info - uintptr(1)*2
  11730 	non_zero_y = uint32(0)
  11731 	non_zero_uv = uint32(0)
  11732 	libc.Xmemset(tls, dst, 0, libc.Uint64FromInt32(384)*libc.Uint64FromInt64(2))
  11733 	if !((*VP8MBData)(unsafe.Pointer(block)).Fis_i4x4 != 0) { // parse DC
  11734 		**(**[16]int16_t)(__ccgo_up(bp)) = [16]int16_t{}
  11735 		ctx = int32((*VP8MB)(unsafe.Pointer(mb)).Fnz_dc) + int32((*VP8MB)(unsafe.Pointer(left_mb)).Fnz_dc)
  11736 		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)
  11737 		v1 = libc.BoolUint8(nz > libc.Int32FromInt32(0))
  11738 		(*VP8MB)(unsafe.Pointer(left_mb)).Fnz_dc = v1
  11739 		(*VP8MB)(unsafe.Pointer(mb)).Fnz_dc = v1
  11740 		if nz > int32(1) { // more than just the DC -> perform the full transform
  11741 			(*(*func(*libc.TLS, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8TransformWHT})))(tls, bp, dst)
  11742 		} else {
  11743 			dc0 = (int32((**(**[16]int16_t)(__ccgo_up(bp)))[0]) + int32(3)) >> int32(3)
  11744 			i = 0
  11745 			for {
  11746 				if !(i < libc.Int32FromInt32(16)*libc.Int32FromInt32(16)) {
  11747 					break
  11748 				}
  11749 				**(**int16_t)(__ccgo_up(dst + uintptr(i)*2)) = int16(dc0)
  11750 				goto _2
  11751 			_2:
  11752 				;
  11753 				i = i + int32(16)
  11754 			}
  11755 		}
  11756 		first = int32(1)
  11757 		ac_proba = bands
  11758 	} else {
  11759 		first = 0
  11760 		ac_proba = bands + 3*136
  11761 	}
  11762 	tnz = uint8(int32((*VP8MB)(unsafe.Pointer(mb)).Fnz) & int32(0x0f))
  11763 	lnz = uint8(int32((*VP8MB)(unsafe.Pointer(left_mb)).Fnz) & int32(0x0f))
  11764 	y = 0
  11765 	for {
  11766 		if !(y < int32(4)) {
  11767 			break
  11768 		}
  11769 		l = int32(lnz) & int32(1)
  11770 		nz_coeffs = uint32(0)
  11771 		x = 0
  11772 		for {
  11773 			if !(x < int32(4)) {
  11774 				break
  11775 			}
  11776 			ctx1 = l + int32(tnz)&int32(1)
  11777 			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)
  11778 			l = libc.BoolInt32(nz1 > first)
  11779 			tnz = uint8(int32(tnz)>>int32(1) | l<<int32(7))
  11780 			nz_coeffs = NzCodeBits(tls, nz_coeffs, nz1, libc.BoolInt32(int32(**(**int16_t)(__ccgo_up(dst))) != 0))
  11781 			dst = dst + uintptr(16)*2
  11782 			goto _4
  11783 		_4:
  11784 			;
  11785 			x = x + 1
  11786 		}
  11787 		tnz = uint8(int32(tnz) >> libc.Int32FromInt32(4))
  11788 		lnz = uint8(int32(lnz)>>int32(1) | l<<int32(7))
  11789 		non_zero_y = non_zero_y<<libc.Int32FromInt32(8) | nz_coeffs
  11790 		goto _3
  11791 	_3:
  11792 		;
  11793 		y = y + 1
  11794 	}
  11795 	out_t_nz = uint32(tnz)
  11796 	out_l_nz = uint32(int32(lnz) >> int32(4))
  11797 	ch = 0
  11798 	for {
  11799 		if !(ch < int32(4)) {
  11800 			break
  11801 		}
  11802 		nz_coeffs1 = uint32(0)
  11803 		tnz = uint8(int32((*VP8MB)(unsafe.Pointer(mb)).Fnz) >> (int32(4) + ch))
  11804 		lnz = uint8(int32((*VP8MB)(unsafe.Pointer(left_mb)).Fnz) >> (int32(4) + ch))
  11805 		y = 0
  11806 		for {
  11807 			if !(y < int32(2)) {
  11808 				break
  11809 			}
  11810 			l1 = int32(lnz) & int32(1)
  11811 			x = 0
  11812 			for {
  11813 				if !(x < int32(2)) {
  11814 					break
  11815 				}
  11816 				ctx2 = l1 + int32(tnz)&int32(1)
  11817 				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)
  11818 				l1 = libc.BoolInt32(nz2 > 0)
  11819 				tnz = uint8(int32(tnz)>>int32(1) | l1<<int32(3))
  11820 				nz_coeffs1 = NzCodeBits(tls, nz_coeffs1, nz2, libc.BoolInt32(int32(**(**int16_t)(__ccgo_up(dst))) != 0))
  11821 				dst = dst + uintptr(16)*2
  11822 				goto _7
  11823 			_7:
  11824 				;
  11825 				x = x + 1
  11826 			}
  11827 			tnz = uint8(int32(tnz) >> libc.Int32FromInt32(2))
  11828 			lnz = uint8(int32(lnz)>>int32(1) | l1<<int32(5))
  11829 			goto _6
  11830 		_6:
  11831 			;
  11832 			y = y + 1
  11833 		}
  11834 		// Note: we don't really need the per-4x4 details for U/V blocks.
  11835 		non_zero_uv = non_zero_uv | nz_coeffs1<<(int32(4)*ch)
  11836 		out_t_nz = out_t_nz | uint32(int32(tnz)<<int32(4)<<ch)
  11837 		out_l_nz = out_l_nz | uint32(int32(lnz)&int32(0xf0)<<ch)
  11838 		goto _5
  11839 	_5:
  11840 		;
  11841 		ch = ch + int32(2)
  11842 	}
  11843 	(*VP8MB)(unsafe.Pointer(mb)).Fnz = uint8(out_t_nz)
  11844 	(*VP8MB)(unsafe.Pointer(left_mb)).Fnz = uint8(out_l_nz)
  11845 	(*VP8MBData)(unsafe.Pointer(block)).Fnon_zero_y = non_zero_y
  11846 	(*VP8MBData)(unsafe.Pointer(block)).Fnon_zero_uv = non_zero_uv
  11847 	// We look at the mode-code of each block and check if some blocks have less
  11848 	// than three non-zero coeffs (code < 2). This is to avoid dithering flat and
  11849 	// empty blocks.
  11850 	if non_zero_uv&uint32(0xaaaa) != 0 {
  11851 		v8 = 0
  11852 	} else {
  11853 		v8 = (*VP8QuantMatrix)(unsafe.Pointer(q)).Fdither
  11854 	}
  11855 	(*VP8MBData)(unsafe.Pointer(block)).Fdither = uint8(v8)
  11856 	return libc.BoolInt32(!(non_zero_y|non_zero_uv != 0)) // will be used for further optimization
  11857 }
  11858 
  11859 //------------------------------------------------------------------------------
  11860 // Main loop
  11861 
  11862 func VP8DecodeMB(tls *libc.TLS, dec uintptr, token_br uintptr) (r int32) {
  11863 	var block, finfo, left, mb, v4 uintptr
  11864 	var skip, v1 int32
  11865 	var v2 uint8_t
  11866 	_, _, _, _, _, _, _, _ = block, finfo, left, mb, skip, v1, v2, v4
  11867 	left = (*VP8Decoder)(unsafe.Pointer(dec)).Fmb_info - uintptr(1)*2
  11868 	mb = (*VP8Decoder)(unsafe.Pointer(dec)).Fmb_info + uintptr((*VP8Decoder)(unsafe.Pointer(dec)).Fmb_x)*2
  11869 	block = (*VP8Decoder)(unsafe.Pointer(dec)).Fmb_data + uintptr((*VP8Decoder)(unsafe.Pointer(dec)).Fmb_x)*800
  11870 	if (*VP8Decoder)(unsafe.Pointer(dec)).Fuse_skip_proba != 0 {
  11871 		v1 = int32((*VP8MBData)(unsafe.Pointer(block)).Fskip)
  11872 	} else {
  11873 		v1 = 0
  11874 	}
  11875 	skip = v1
  11876 	if !(skip != 0) {
  11877 		skip = ParseResiduals(tls, dec, mb, token_br)
  11878 	} else {
  11879 		v2 = libc.Uint8FromInt32(0)
  11880 		(*VP8MB)(unsafe.Pointer(mb)).Fnz = v2
  11881 		(*VP8MB)(unsafe.Pointer(left)).Fnz = v2
  11882 		if !((*VP8MBData)(unsafe.Pointer(block)).Fis_i4x4 != 0) {
  11883 			v2 = libc.Uint8FromInt32(0)
  11884 			(*VP8MB)(unsafe.Pointer(mb)).Fnz_dc = v2
  11885 			(*VP8MB)(unsafe.Pointer(left)).Fnz_dc = v2
  11886 		}
  11887 		(*VP8MBData)(unsafe.Pointer(block)).Fnon_zero_y = uint32(0)
  11888 		(*VP8MBData)(unsafe.Pointer(block)).Fnon_zero_uv = uint32(0)
  11889 		(*VP8MBData)(unsafe.Pointer(block)).Fdither = uint8(0)
  11890 	}
  11891 	if (*VP8Decoder)(unsafe.Pointer(dec)).Ffilter_type > 0 { // store filter info
  11892 		finfo = (*VP8Decoder)(unsafe.Pointer(dec)).Ff_info + uintptr((*VP8Decoder)(unsafe.Pointer(dec)).Fmb_x)*4
  11893 		**(**VP8FInfo)(__ccgo_up(finfo)) = **(**VP8FInfo)(__ccgo_up(dec + 2924 + uintptr((*VP8MBData)(unsafe.Pointer(block)).Fsegment)*8 + uintptr((*VP8MBData)(unsafe.Pointer(block)).Fis_i4x4)*4))
  11894 		v4 = finfo + 2
  11895 		*(*uint8_t)(unsafe.Pointer(v4)) = uint8_t(int32(*(*uint8_t)(unsafe.Pointer(v4))) | libc.BoolInt32(!(skip != 0)))
  11896 	}
  11897 	return libc.BoolInt32(!((*VP8BitReader)(unsafe.Pointer(token_br)).Feof != 0))
  11898 }
  11899 
  11900 func VP8InitScanline(tls *libc.TLS, dec uintptr) {
  11901 	var left uintptr
  11902 	_ = left
  11903 	left = (*VP8Decoder)(unsafe.Pointer(dec)).Fmb_info - uintptr(1)*2
  11904 	(*VP8MB)(unsafe.Pointer(left)).Fnz = uint8(0)
  11905 	(*VP8MB)(unsafe.Pointer(left)).Fnz_dc = uint8(0)
  11906 	libc.Xmemset(tls, dec+2816, int32(B_DC_PRED), uint64(4))
  11907 	(*VP8Decoder)(unsafe.Pointer(dec)).Fmb_x = 0
  11908 }
  11909 
  11910 func ParseFrame(tls *libc.TLS, dec uintptr, io uintptr) (r int32) {
  11911 	var token_br uintptr
  11912 	_ = token_br
  11913 	(*VP8Decoder)(unsafe.Pointer(dec)).Fmb_y = 0
  11914 	for {
  11915 		if !((*VP8Decoder)(unsafe.Pointer(dec)).Fmb_y < (*VP8Decoder)(unsafe.Pointer(dec)).Fbr_mb_y) {
  11916 			break
  11917 		}
  11918 		// Parse bitstream for this row.
  11919 		token_br = dec + 440 + uintptr(uint32((*VP8Decoder)(unsafe.Pointer(dec)).Fmb_y)&(*VP8Decoder)(unsafe.Pointer(dec)).Fnum_parts_minus_one)*48
  11920 		if !(VP8ParseIntraModeRow(tls, dec+16, dec) != 0) {
  11921 			return VP8SetError(tls, dec, int32(VP8_STATUS_NOT_ENOUGH_DATA), __ccgo_ts+435)
  11922 		}
  11923 		for {
  11924 			if !((*VP8Decoder)(unsafe.Pointer(dec)).Fmb_x < (*VP8Decoder)(unsafe.Pointer(dec)).Fmb_w) {
  11925 				break
  11926 			}
  11927 			if !(VP8DecodeMB(tls, dec, token_br) != 0) {
  11928 				return VP8SetError(tls, dec, int32(VP8_STATUS_NOT_ENOUGH_DATA), __ccgo_ts+476)
  11929 			}
  11930 			goto _2
  11931 		_2:
  11932 			;
  11933 			(*VP8Decoder)(unsafe.Pointer(dec)).Fmb_x = (*VP8Decoder)(unsafe.Pointer(dec)).Fmb_x + 1
  11934 		}
  11935 		VP8InitScanline(tls, dec) // Prepare for next scanline
  11936 		// Reconstruct, filter and emit the row.
  11937 		if !(VP8ProcessRow(tls, dec, io) != 0) {
  11938 			return VP8SetError(tls, dec, int32(VP8_STATUS_USER_ABORT), __ccgo_ts+511)
  11939 		}
  11940 		goto _1
  11941 	_1:
  11942 		;
  11943 		(*VP8Decoder)(unsafe.Pointer(dec)).Fmb_y = (*VP8Decoder)(unsafe.Pointer(dec)).Fmb_y + 1
  11944 	}
  11945 	if (*VP8Decoder)(unsafe.Pointer(dec)).Fmt_method > 0 {
  11946 		if !((*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*WebPWorkerInterface)(unsafe.Pointer(WebPGetWorkerInterface(tls))).FSync})))(tls, dec+152) != 0) {
  11947 			return 0
  11948 		}
  11949 	}
  11950 	return int32(1)
  11951 }
  11952 
  11953 // C documentation
  11954 //
  11955 //	// Main entry point
  11956 func VP8Decode(tls *libc.TLS, dec uintptr, io uintptr) (r int32) {
  11957 	var ok int32
  11958 	_ = ok
  11959 	ok = 0
  11960 	if dec == libc.UintptrFromInt32(0) {
  11961 		return 0
  11962 	}
  11963 	if io == libc.UintptrFromInt32(0) {
  11964 		return VP8SetError(tls, dec, int32(VP8_STATUS_INVALID_PARAM), __ccgo_ts+527)
  11965 	}
  11966 	if !((*VP8Decoder)(unsafe.Pointer(dec)).Fready != 0) {
  11967 		if !(VP8GetHeaders(tls, dec, io) != 0) {
  11968 			return 0
  11969 		}
  11970 	}
  11971 	// Finish setting up the decoding parameter. Will call io->setup().
  11972 	ok = libc.BoolInt32(VP8EnterCritical(tls, dec, io) == int32(VP8_STATUS_OK))
  11973 	if ok != 0 { // good to go.
  11974 		// Will allocate memory and prepare everything.
  11975 		if ok != 0 {
  11976 			ok = VP8InitFrame(tls, dec, io)
  11977 		}
  11978 		// Main decoding loop
  11979 		if ok != 0 {
  11980 			ok = ParseFrame(tls, dec, io)
  11981 		}
  11982 		// Exit.
  11983 		ok = ok & VP8ExitCritical(tls, dec, io)
  11984 	}
  11985 	if !(ok != 0) {
  11986 		VP8Clear(tls, dec)
  11987 		return 0
  11988 	}
  11989 	(*VP8Decoder)(unsafe.Pointer(dec)).Fready = 0
  11990 	return ok
  11991 }
  11992 
  11993 func VP8Clear(tls *libc.TLS, dec uintptr) {
  11994 	if dec == libc.UintptrFromInt32(0) {
  11995 		return
  11996 	}
  11997 	(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(&struct{ uintptr }{(*WebPWorkerInterface)(unsafe.Pointer(WebPGetWorkerInterface(tls))).FEnd})))(tls, dec+152)
  11998 	WebPDeallocateAlphaMemory(tls, dec)
  11999 	WebPSafeFree(tls, (*VP8Decoder)(unsafe.Pointer(dec)).Fmem)
  12000 	(*VP8Decoder)(unsafe.Pointer(dec)).Fmem = libc.UintptrFromInt32(0)
  12001 	(*VP8Decoder)(unsafe.Pointer(dec)).Fmem_size = uint64(0)
  12002 	libc.Xmemset(tls, dec+16, 0, uint64(48))
  12003 	(*VP8Decoder)(unsafe.Pointer(dec)).Fready = 0
  12004 }
  12005 
  12006 const APPROX_LOG_MAX = 4096
  12007 const APPROX_LOG_WITH_CORRECTION_MAX = 65536
  12008 const BITS_SPECIAL_MARKER = 256
  12009 const CODE_TO_PLANE_CODES = 120
  12010 const LOG_2_PRECISION_BITS = 23
  12011 const LOG_2_RECIPROCAL = 1.44269504088896338700465094007086
  12012 const LOG_2_RECIPROCAL_FIXED_DOUBLE = 12102203.161561485379934310913085937500
  12013 const LOG_LOOKUP_IDX_MAX = 256
  12014 const NUM_ARGB_CACHE_ROWS = 16
  12015 const NUM_CODE_LENGTH_CODES = 19
  12016 const PACKED_NON_LITERAL_CODE = 0
  12017 const PREFIX_LOOKUP_IDX_MAX = 512
  12018 const SYNC_EVERY_N_ROWS = 8
  12019 const VP8L_MAGIC_BYTE1 = 47
  12020 
  12021 var kHashMul8 = uint32(0x1e35a7bd)
  12022 
  12023 type VP8LPredictorFunc = uintptr
  12024 
  12025 type VP8LPredictorAddSubFunc = uintptr
  12026 
  12027 type VP8LProcessDecBlueAndRedFunc = uintptr
  12028 
  12029 type VP8LMultipliers = struct {
  12030 	Fgreen_to_red  uint8_t
  12031 	Fgreen_to_blue uint8_t
  12032 	Fred_to_blue   uint8_t
  12033 }
  12034 
  12035 type VP8LTransformColorInverseFunc = uintptr
  12036 
  12037 type VP8LConvertFunc = uintptr
  12038 
  12039 type VP8LMapARGBFunc = uintptr
  12040 
  12041 type VP8LMapAlphaFunc = uintptr
  12042 
  12043 type VP8LProcessEncBlueAndRedFunc = uintptr
  12044 
  12045 type VP8LTransformColorFunc = uintptr
  12046 
  12047 type VP8LCollectColorBlueTransformsFunc = uintptr
  12048 
  12049 type VP8LCollectColorRedTransformsFunc = uintptr
  12050 
  12051 type VP8LCostFunc = uintptr
  12052 
  12053 type VP8LCombinedShannonEntropyFunc = uintptr
  12054 
  12055 type VP8LShannonEntropyFunc = uintptr
  12056 
  12057 type VP8LStreaks = struct {
  12058 	Fcounts  [2]int32
  12059 	Fstreaks [2][2]int32
  12060 }
  12061 
  12062 type VP8LBitEntropy = struct {
  12063 	Fentropy      uint64_t
  12064 	Fsum          uint32_t
  12065 	Fnonzeros     int32
  12066 	Fmax_val      uint32_t
  12067 	Fnonzero_code uint32_t
  12068 }
  12069 
  12070 type VP8LGetCombinedEntropyUnrefinedFunc = uintptr
  12071 
  12072 type VP8LGetEntropyUnrefinedFunc = uintptr
  12073 
  12074 type VP8LAddVectorFunc = uintptr
  12075 
  12076 type VP8LAddVectorEqFunc = uintptr
  12077 
  12078 type VP8LVectorMismatchFunc = uintptr
  12079 
  12080 type VP8LBundleColorMapFunc = uintptr
  12081 
  12082 type VP8LFastLog2SlowFunc = uintptr
  12083 
  12084 type VP8LFastSLog2SlowFunc = uintptr
  12085 
  12086 type VP8LPrefixCode = struct {
  12087 	Fcode       int8_t
  12088 	Fextra_bits int8_t
  12089 }
  12090 
  12091 //------------------------------------------------------------------------------
  12092 // Transform-related functions used in both encoding and decoding.
  12093 
  12094 // Macros used to create a batch predictor that iteratively uses a
  12095 // one-pixel predictor.
  12096 
  12097 // The predictor is added to the output pixel (which
  12098 // is therefore considered as a residual) to get the final prediction.
  12099 
  12100 // Copyright 2010 Google Inc. All Rights Reserved.
  12101 //
  12102 // Use of this source code is governed by a BSD-style license
  12103 // that can be found in the COPYING file in the root of the source
  12104 // tree. An additional intellectual property rights grant can be found
  12105 // in the file PATENTS. All contributing project authors may
  12106 // be found in the AUTHORS file in the root of the source tree.
  12107 // -----------------------------------------------------------------------------
  12108 //
  12109 // Boolean decoder
  12110 //
  12111 // Author: Skal (pascal.massimino@gmail.com)
  12112 //         Vikas Arora (vikaas.arora@gmail.com)
  12113 
  12114 // Copyright 2012 Google Inc. All Rights Reserved.
  12115 //
  12116 // Use of this source code is governed by a BSD-style license
  12117 // that can be found in the COPYING file in the root of the source
  12118 // tree. An additional intellectual property rights grant can be found
  12119 // in the file PATENTS. All contributing project authors may
  12120 // be found in the AUTHORS file in the root of the source tree.
  12121 // -----------------------------------------------------------------------------
  12122 //
  12123 // Color Cache for WebP Lossless
  12124 //
  12125 // Authors: Jyrki Alakuijala (jyrki@google.com)
  12126 //          Urvang Joshi (urvang@google.com)
  12127 
  12128 // Copyright 2012 Google Inc. All Rights Reserved.
  12129 //
  12130 // Use of this source code is governed by a BSD-style license
  12131 // that can be found in the COPYING file in the root of the source
  12132 // tree. An additional intellectual property rights grant can be found
  12133 // in the file PATENTS. All contributing project authors may
  12134 // be found in the AUTHORS file in the root of the source tree.
  12135 // -----------------------------------------------------------------------------
  12136 //
  12137 // Utilities for building and looking up Huffman trees.
  12138 //
  12139 // Author: Urvang Joshi (urvang@google.com)
  12140 
  12141 // Copyright 2012 Google Inc. All Rights Reserved.
  12142 //
  12143 // Use of this source code is governed by a BSD-style license
  12144 // that can be found in the COPYING file in the root of the source
  12145 // tree. An additional intellectual property rights grant can be found
  12146 // in the file PATENTS. All contributing project authors may
  12147 // be found in the AUTHORS file in the root of the source tree.
  12148 // -----------------------------------------------------------------------------
  12149 //
  12150 // Rescaling functions
  12151 //
  12152 // Author: Skal (pascal.massimino@gmail.com)
  12153 
  12154 // Copyright 2012 Google Inc. All Rights Reserved.
  12155 //
  12156 // Use of this source code is governed by a BSD-style license
  12157 // that can be found in the COPYING file in the root of the source
  12158 // tree. An additional intellectual property rights grant can be found
  12159 // in the file PATENTS. All contributing project authors may
  12160 // be found in the AUTHORS file in the root of the source tree.
  12161 // -----------------------------------------------------------------------------
  12162 //
  12163 // Misc. common utility functions
  12164 //
  12165 // Authors: Skal (pascal.massimino@gmail.com)
  12166 //          Urvang (urvang@google.com)
  12167 
  12168 // Copyright 2010 Google Inc. All Rights Reserved.
  12169 //
  12170 // Use of this source code is governed by a BSD-style license
  12171 // that can be found in the COPYING file in the root of the source
  12172 // tree. An additional intellectual property rights grant can be found
  12173 // in the file PATENTS. All contributing project authors may
  12174 // be found in the AUTHORS file in the root of the source tree.
  12175 // -----------------------------------------------------------------------------
  12176 //
  12177 //  Main decoding functions for WebP images.
  12178 //
  12179 // Author: Skal (pascal.massimino@gmail.com)
  12180 
  12181 // Copyright 2012 Google Inc. All Rights Reserved.
  12182 //
  12183 // Use of this source code is governed by a BSD-style license
  12184 // that can be found in the COPYING file in the root of the source
  12185 // tree. An additional intellectual property rights grant can be found
  12186 // in the file PATENTS. All contributing project authors may
  12187 // be found in the AUTHORS file in the root of the source tree.
  12188 // -----------------------------------------------------------------------------
  12189 //
  12190 //  Internal header for constants related to WebP file format.
  12191 //
  12192 // Author: Urvang (urvang@google.com)
  12193 
  12194 // Copyright 2010 Google Inc. All Rights Reserved.
  12195 //
  12196 // Use of this source code is governed by a BSD-style license
  12197 // that can be found in the COPYING file in the root of the source
  12198 // tree. An additional intellectual property rights grant can be found
  12199 // in the file PATENTS. All contributing project authors may
  12200 // be found in the AUTHORS file in the root of the source tree.
  12201 // -----------------------------------------------------------------------------
  12202 //
  12203 //  Common types + memory wrappers
  12204 //
  12205 // Author: Skal (pascal.massimino@gmail.com)
  12206 
  12207 var kCodeLengthLiterals = int32(16)
  12208 var kCodeLengthRepeatCode = int32(16)
  12209 var kCodeLengthExtraBits = [3]uint8_t{
  12210 	0: uint8(2),
  12211 	1: uint8(3),
  12212 	2: uint8(7),
  12213 }
  12214 var kCodeLengthRepeatOffsets = [3]uint8_t{
  12215 	0: uint8(3),
  12216 	1: uint8(3),
  12217 	2: uint8(11),
  12218 }
  12219 
  12220 // C documentation
  12221 //
  12222 //	// -----------------------------------------------------------------------------
  12223 //	//  Five Huffman codes are used at each meta code:
  12224 //	//  1. green + length prefix codes + color cache codes,
  12225 //	//  2. alpha,
  12226 //	//  3. red,
  12227 //	//  4. blue, and,
  12228 //	//  5. distance prefix codes.
  12229 type HuffIndex = int32
  12230 
  12231 const GREEN = 0
  12232 const RED = 1
  12233 const BLUE = 2
  12234 const ALPHA = 3
  12235 const DIST = 4
  12236 
  12237 var kAlphabetSize = [5]uint16_t{
  12238 	0: uint16(libc.Int32FromInt32(NUM_LITERAL_CODES) + libc.Int32FromInt32(NUM_LENGTH_CODES)),
  12239 	1: uint16(NUM_LITERAL_CODES),
  12240 	2: uint16(NUM_LITERAL_CODES),
  12241 	3: uint16(NUM_LITERAL_CODES),
  12242 	4: uint16(NUM_DISTANCE_CODES),
  12243 }
  12244 
  12245 var kLiteralMap = [5]uint8_t{
  12246 	1: uint8(1),
  12247 	2: uint8(1),
  12248 	3: uint8(1),
  12249 }
  12250 
  12251 var kCodeLengthCodeOrder = [19]uint8_t{
  12252 	0:  uint8(17),
  12253 	1:  uint8(18),
  12254 	3:  uint8(1),
  12255 	4:  uint8(2),
  12256 	5:  uint8(3),
  12257 	6:  uint8(4),
  12258 	7:  uint8(5),
  12259 	8:  uint8(16),
  12260 	9:  uint8(6),
  12261 	10: uint8(7),
  12262 	11: uint8(8),
  12263 	12: uint8(9),
  12264 	13: uint8(10),
  12265 	14: uint8(11),
  12266 	15: uint8(12),
  12267 	16: uint8(13),
  12268 	17: uint8(14),
  12269 	18: uint8(15),
  12270 }
  12271 
  12272 var kCodeToPlane = [120]uint8_t{
  12273 	0:   uint8(0x18),
  12274 	1:   uint8(0x07),
  12275 	2:   uint8(0x17),
  12276 	3:   uint8(0x19),
  12277 	4:   uint8(0x28),
  12278 	5:   uint8(0x06),
  12279 	6:   uint8(0x27),
  12280 	7:   uint8(0x29),
  12281 	8:   uint8(0x16),
  12282 	9:   uint8(0x1a),
  12283 	10:  uint8(0x26),
  12284 	11:  uint8(0x2a),
  12285 	12:  uint8(0x38),
  12286 	13:  uint8(0x05),
  12287 	14:  uint8(0x37),
  12288 	15:  uint8(0x39),
  12289 	16:  uint8(0x15),
  12290 	17:  uint8(0x1b),
  12291 	18:  uint8(0x36),
  12292 	19:  uint8(0x3a),
  12293 	20:  uint8(0x25),
  12294 	21:  uint8(0x2b),
  12295 	22:  uint8(0x48),
  12296 	23:  uint8(0x04),
  12297 	24:  uint8(0x47),
  12298 	25:  uint8(0x49),
  12299 	26:  uint8(0x14),
  12300 	27:  uint8(0x1c),
  12301 	28:  uint8(0x35),
  12302 	29:  uint8(0x3b),
  12303 	30:  uint8(0x46),
  12304 	31:  uint8(0x4a),
  12305 	32:  uint8(0x24),
  12306 	33:  uint8(0x2c),
  12307 	34:  uint8(0x58),
  12308 	35:  uint8(0x45),
  12309 	36:  uint8(0x4b),
  12310 	37:  uint8(0x34),
  12311 	38:  uint8(0x3c),
  12312 	39:  uint8(0x03),
  12313 	40:  uint8(0x57),
  12314 	41:  uint8(0x59),
  12315 	42:  uint8(0x13),
  12316 	43:  uint8(0x1d),
  12317 	44:  uint8(0x56),
  12318 	45:  uint8(0x5a),
  12319 	46:  uint8(0x23),
  12320 	47:  uint8(0x2d),
  12321 	48:  uint8(0x44),
  12322 	49:  uint8(0x4c),
  12323 	50:  uint8(0x55),
  12324 	51:  uint8(0x5b),
  12325 	52:  uint8(0x33),
  12326 	53:  uint8(0x3d),
  12327 	54:  uint8(0x68),
  12328 	55:  uint8(0x02),
  12329 	56:  uint8(0x67),
  12330 	57:  uint8(0x69),
  12331 	58:  uint8(0x12),
  12332 	59:  uint8(0x1e),
  12333 	60:  uint8(0x66),
  12334 	61:  uint8(0x6a),
  12335 	62:  uint8(0x22),
  12336 	63:  uint8(0x2e),
  12337 	64:  uint8(0x54),
  12338 	65:  uint8(0x5c),
  12339 	66:  uint8(0x43),
  12340 	67:  uint8(0x4d),
  12341 	68:  uint8(0x65),
  12342 	69:  uint8(0x6b),
  12343 	70:  uint8(0x32),
  12344 	71:  uint8(0x3e),
  12345 	72:  uint8(0x78),
  12346 	73:  uint8(0x01),
  12347 	74:  uint8(0x77),
  12348 	75:  uint8(0x79),
  12349 	76:  uint8(0x53),
  12350 	77:  uint8(0x5d),
  12351 	78:  uint8(0x11),
  12352 	79:  uint8(0x1f),
  12353 	80:  uint8(0x64),
  12354 	81:  uint8(0x6c),
  12355 	82:  uint8(0x42),
  12356 	83:  uint8(0x4e),
  12357 	84:  uint8(0x76),
  12358 	85:  uint8(0x7a),
  12359 	86:  uint8(0x21),
  12360 	87:  uint8(0x2f),
  12361 	88:  uint8(0x75),
  12362 	89:  uint8(0x7b),
  12363 	90:  uint8(0x31),
  12364 	91:  uint8(0x3f),
  12365 	92:  uint8(0x63),
  12366 	93:  uint8(0x6d),
  12367 	94:  uint8(0x52),
  12368 	95:  uint8(0x5e),
  12369 	97:  uint8(0x74),
  12370 	98:  uint8(0x7c),
  12371 	99:  uint8(0x41),
  12372 	100: uint8(0x4f),
  12373 	101: uint8(0x10),
  12374 	102: uint8(0x20),
  12375 	103: uint8(0x62),
  12376 	104: uint8(0x6e),
  12377 	105: uint8(0x30),
  12378 	106: uint8(0x73),
  12379 	107: uint8(0x7d),
  12380 	108: uint8(0x51),
  12381 	109: uint8(0x5f),
  12382 	110: uint8(0x40),
  12383 	111: uint8(0x72),
  12384 	112: uint8(0x7e),
  12385 	113: uint8(0x61),
  12386 	114: uint8(0x6f),
  12387 	115: uint8(0x50),
  12388 	116: uint8(0x71),
  12389 	117: uint8(0x7f),
  12390 	118: uint8(0x60),
  12391 	119: uint8(0x70),
  12392 }
  12393 
  12394 // C documentation
  12395 //
  12396 //	// Memory needed for lookup tables of one Huffman tree group. Red, blue, alpha
  12397 //	// and distance alphabets are constant (256 for red, blue and alpha, 40 for
  12398 //	// distance) and lookup table sizes for them in worst case are 630 and 410
  12399 //	// respectively. Size of green alphabet depends on color cache size and is equal
  12400 //	// to 256 (green component values) + 24 (length prefix values)
  12401 //	// + color_cache_size (between 0 and 2048).
  12402 //	// All values computed for 8-bit first level lookup with Mark Adler's tool:
  12403 //	// https://github.com/madler/zlib/blob/v1.2.5/examples/enough.c
  12404 var kTableSize = [12]uint16_t{
  12405 	0:  uint16(libc.Int32FromInt32(630)*libc.Int32FromInt32(3) + libc.Int32FromInt32(410) + libc.Int32FromInt32(654)),
  12406 	1:  uint16(libc.Int32FromInt32(630)*libc.Int32FromInt32(3) + libc.Int32FromInt32(410) + libc.Int32FromInt32(656)),
  12407 	2:  uint16(libc.Int32FromInt32(630)*libc.Int32FromInt32(3) + libc.Int32FromInt32(410) + libc.Int32FromInt32(658)),
  12408 	3:  uint16(libc.Int32FromInt32(630)*libc.Int32FromInt32(3) + libc.Int32FromInt32(410) + libc.Int32FromInt32(662)),
  12409 	4:  uint16(libc.Int32FromInt32(630)*libc.Int32FromInt32(3) + libc.Int32FromInt32(410) + libc.Int32FromInt32(670)),
  12410 	5:  uint16(libc.Int32FromInt32(630)*libc.Int32FromInt32(3) + libc.Int32FromInt32(410) + libc.Int32FromInt32(686)),
  12411 	6:  uint16(libc.Int32FromInt32(630)*libc.Int32FromInt32(3) + libc.Int32FromInt32(410) + libc.Int32FromInt32(718)),
  12412 	7:  uint16(libc.Int32FromInt32(630)*libc.Int32FromInt32(3) + libc.Int32FromInt32(410) + libc.Int32FromInt32(782)),
  12413 	8:  uint16(libc.Int32FromInt32(630)*libc.Int32FromInt32(3) + libc.Int32FromInt32(410) + libc.Int32FromInt32(912)),
  12414 	9:  uint16(libc.Int32FromInt32(630)*libc.Int32FromInt32(3) + libc.Int32FromInt32(410) + libc.Int32FromInt32(1168)),
  12415 	10: uint16(libc.Int32FromInt32(630)*libc.Int32FromInt32(3) + libc.Int32FromInt32(410) + libc.Int32FromInt32(1680)),
  12416 	11: uint16(libc.Int32FromInt32(630)*libc.Int32FromInt32(3) + libc.Int32FromInt32(410) + libc.Int32FromInt32(2704)),
  12417 }
  12418 
  12419 func VP8LSetError(tls *libc.TLS, dec uintptr, error1 VP8StatusCode1) (r int32) {
  12420 	// The oldest error reported takes precedence over the new one.
  12421 	if (*VP8LDecoder)(unsafe.Pointer(dec)).Fstatus == int32(VP8_STATUS_OK) || (*VP8LDecoder)(unsafe.Pointer(dec)).Fstatus == int32(VP8_STATUS_SUSPENDED) {
  12422 		(*VP8LDecoder)(unsafe.Pointer(dec)).Fstatus = error1
  12423 	}
  12424 	return 0
  12425 }
  12426 
  12427 //------------------------------------------------------------------------------
  12428 
  12429 func VP8LCheckSignature(tls *libc.TLS, data uintptr, size size_t) (r int32) {
  12430 	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
  12431 }
  12432 
  12433 func ReadImageInfo(tls *libc.TLS, br uintptr, width uintptr, height uintptr, has_alpha uintptr) (r int32) {
  12434 	if VP8LReadBits(tls, br, int32(8)) != uint32(VP8L_MAGIC_BYTE1) {
  12435 		return 0
  12436 	}
  12437 	**(**int32)(__ccgo_up(width)) = int32(VP8LReadBits(tls, br, int32(VP8L_IMAGE_SIZE_BITS)) + uint32(1))
  12438 	**(**int32)(__ccgo_up(height)) = int32(VP8LReadBits(tls, br, int32(VP8L_IMAGE_SIZE_BITS)) + uint32(1))
  12439 	**(**int32)(__ccgo_up(has_alpha)) = int32(VP8LReadBits(tls, br, int32(1)))
  12440 	if VP8LReadBits(tls, br, int32(VP8L_VERSION_BITS)) != uint32(0) {
  12441 		return 0
  12442 	}
  12443 	return libc.BoolInt32(!((*VP8LBitReader)(unsafe.Pointer(br)).Feos != 0))
  12444 }
  12445 
  12446 func VP8LGetInfo(tls *libc.TLS, data uintptr, data_size size_t, width uintptr, height uintptr, has_alpha uintptr) (r int32) {
  12447 	bp := tls.Alloc(64)
  12448 	defer tls.Free(64)
  12449 	var _ /* a at bp+8 */ int32
  12450 	var _ /* br at bp+16 */ VP8LBitReader
  12451 	var _ /* h at bp+4 */ int32
  12452 	var _ /* w at bp+0 */ int32
  12453 	if data == libc.UintptrFromInt32(0) || data_size < uint64(VP8L_FRAME_HEADER_SIZE) {
  12454 		return 0 // not enough data
  12455 	} else {
  12456 		if !(VP8LCheckSignature(tls, data, data_size) != 0) {
  12457 			return 0 // bad signature
  12458 		} else {
  12459 			VP8LInitBitReader(tls, bp+16, data, data_size)
  12460 			if !(ReadImageInfo(tls, bp+16, bp, bp+4, bp+8) != 0) {
  12461 				return 0
  12462 			}
  12463 			if width != libc.UintptrFromInt32(0) {
  12464 				**(**int32)(__ccgo_up(width)) = **(**int32)(__ccgo_up(bp))
  12465 			}
  12466 			if height != libc.UintptrFromInt32(0) {
  12467 				**(**int32)(__ccgo_up(height)) = **(**int32)(__ccgo_up(bp + 4))
  12468 			}
  12469 			if has_alpha != libc.UintptrFromInt32(0) {
  12470 				**(**int32)(__ccgo_up(has_alpha)) = **(**int32)(__ccgo_up(bp + 8))
  12471 			}
  12472 			return int32(1)
  12473 		}
  12474 	}
  12475 	return r
  12476 }
  12477 
  12478 //------------------------------------------------------------------------------
  12479 
  12480 func GetCopyDistance(tls *libc.TLS, distance_symbol int32, br uintptr) (r int32) {
  12481 	var extra_bits, offset int32
  12482 	_, _ = extra_bits, offset
  12483 	if distance_symbol < int32(4) {
  12484 		return distance_symbol + int32(1)
  12485 	}
  12486 	extra_bits = (distance_symbol - int32(2)) >> int32(1)
  12487 	offset = (int32(2) + distance_symbol&int32(1)) << extra_bits
  12488 	return int32(uint32(offset) + VP8LReadBits(tls, br, extra_bits) + uint32(1))
  12489 }
  12490 
  12491 func GetCopyLength(tls *libc.TLS, length_symbol int32, br uintptr) (r int32) {
  12492 	// Length and distance prefixes are encoded the same way.
  12493 	return GetCopyDistance(tls, length_symbol, br)
  12494 }
  12495 
  12496 func PlaneCodeToDistance(tls *libc.TLS, xsize int32, plane_code int32) (r int32) {
  12497 	var dist, dist_code, xoffset, yoffset, v1 int32
  12498 	_, _, _, _, _ = dist, dist_code, xoffset, yoffset, v1
  12499 	if plane_code > int32(CODE_TO_PLANE_CODES) {
  12500 		return plane_code - int32(CODE_TO_PLANE_CODES)
  12501 	} else {
  12502 		dist_code = int32(kCodeToPlane[plane_code-int32(1)])
  12503 		yoffset = dist_code >> int32(4)
  12504 		xoffset = int32(8) - dist_code&int32(0xf)
  12505 		dist = yoffset*xsize + xoffset
  12506 		if dist >= int32(1) {
  12507 			v1 = dist
  12508 		} else {
  12509 			v1 = int32(1)
  12510 		}
  12511 		return v1 // dist<1 can happen if xsize is very small
  12512 	}
  12513 	return r
  12514 }
  12515 
  12516 // C documentation
  12517 //
  12518 //	//------------------------------------------------------------------------------
  12519 //	// Decodes the next Huffman code from bit-stream.
  12520 //	// VP8LFillBitWindow(br) needs to be called at minimum every second call
  12521 //	// to ReadSymbol, in order to pre-fetch enough bits.
  12522 func ReadSymbol(tls *libc.TLS, table uintptr, br2 uintptr) (r int32) {
  12523 	var nbits int32
  12524 	var val1, v2 uint32_t
  12525 	var v1 uintptr
  12526 	_, _, _, _ = nbits, val1, v1, v2
  12527 	v1 = br2
  12528 	v2 = uint32((*VP8LBitReader)(unsafe.Pointer(v1)).Fval >> ((*VP8LBitReader)(unsafe.Pointer(v1)).Fbit_pos & (libc.Int32FromInt32(VP8L_LBITS) - libc.Int32FromInt32(1))))
  12529 	goto _3
  12530 _3:
  12531 	val1 = v2
  12532 	table = table + uintptr(val1&uint32(libc.Int32FromInt32(1)<<libc.Int32FromInt32(HUFFMAN_TABLE_BITS)-libc.Int32FromInt32(1)))*4
  12533 	nbits = int32((*HuffmanCode)(unsafe.Pointer(table)).Fbits) - int32(HUFFMAN_TABLE_BITS)
  12534 	if nbits > 0 {
  12535 		(*VP8LBitReader)(unsafe.Pointer(br2)).Fbit_pos = (*VP8LBitReader)(unsafe.Pointer(br2)).Fbit_pos + int32(HUFFMAN_TABLE_BITS)
  12536 		v1 = br2
  12537 		v2 = uint32((*VP8LBitReader)(unsafe.Pointer(v1)).Fval >> ((*VP8LBitReader)(unsafe.Pointer(v1)).Fbit_pos & (libc.Int32FromInt32(VP8L_LBITS) - libc.Int32FromInt32(1))))
  12538 		goto _6
  12539 	_6:
  12540 		val1 = v2
  12541 		table = table + uintptr((*HuffmanCode)(unsafe.Pointer(table)).Fvalue)*4
  12542 		table = table + uintptr(val1&uint32(libc.Int32FromInt32(1)<<nbits-libc.Int32FromInt32(1)))*4
  12543 	}
  12544 	(*VP8LBitReader)(unsafe.Pointer(br2)).Fbit_pos = (*VP8LBitReader)(unsafe.Pointer(br2)).Fbit_pos + int32((*HuffmanCode)(unsafe.Pointer(table)).Fbits)
  12545 	return int32((*HuffmanCode)(unsafe.Pointer(table)).Fvalue)
  12546 }
  12547 
  12548 // C documentation
  12549 //
  12550 //	// Reads packed symbol depending on GREEN channel
  12551 func ReadPackedSymbols(tls *libc.TLS, group uintptr, br2 uintptr, dst uintptr) (r int32) {
  12552 	var code HuffmanCode32
  12553 	var val1, v2 uint32_t
  12554 	var v1 uintptr
  12555 	_, _, _, _ = code, val1, v1, v2
  12556 	v1 = br2
  12557 	v2 = uint32((*VP8LBitReader)(unsafe.Pointer(v1)).Fval >> ((*VP8LBitReader)(unsafe.Pointer(v1)).Fbit_pos & (libc.Int32FromInt32(VP8L_LBITS) - libc.Int32FromInt32(1))))
  12558 	goto _3
  12559 _3:
  12560 	val1 = v2 & (libc.Uint32FromUint32(1)<<libc.Int32FromInt32(HUFFMAN_PACKED_BITS) - libc.Uint32FromInt32(1))
  12561 	code = **(**HuffmanCode32)(__ccgo_up(group + 56 + uintptr(val1)*8))
  12562 	if code.Fbits < int32(BITS_SPECIAL_MARKER) {
  12563 		(*VP8LBitReader)(unsafe.Pointer(br2)).Fbit_pos = (*VP8LBitReader)(unsafe.Pointer(br2)).Fbit_pos + code.Fbits
  12564 		**(**uint32_t)(__ccgo_up(dst)) = code.Fvalue
  12565 		return PACKED_NON_LITERAL_CODE
  12566 	} else {
  12567 		(*VP8LBitReader)(unsafe.Pointer(br2)).Fbit_pos = (*VP8LBitReader)(unsafe.Pointer(br2)).Fbit_pos + code.Fbits - int32(BITS_SPECIAL_MARKER)
  12568 		return int32(code.Fvalue)
  12569 	}
  12570 	return r
  12571 }
  12572 
  12573 func AccumulateHCode(tls *libc.TLS, hcode HuffmanCode, shift int32, huff uintptr) (r int32) {
  12574 	**(**int32)(__ccgo_up(huff)) += int32(hcode.Fbits)
  12575 	**(**uint32_t)(__ccgo_up(huff + 4)) |= uint32(hcode.Fvalue) << shift
  12576 	return int32(hcode.Fbits)
  12577 }
  12578 
  12579 func BuildPackedTable(tls *libc.TLS, htree_group uintptr) {
  12580 	var bits, code uint32_t
  12581 	var hcode HuffmanCode
  12582 	var huff uintptr
  12583 	_, _, _, _ = bits, code, hcode, huff
  12584 	code = uint32(0)
  12585 	for {
  12586 		if !(code < libc.Uint32FromUint32(1)<<libc.Int32FromInt32(HUFFMAN_PACKED_BITS)) {
  12587 			break
  12588 		}
  12589 		bits = code
  12590 		huff = htree_group + 56 + uintptr(bits)*8
  12591 		hcode = **(**HuffmanCode)(__ccgo_up(**(**uintptr)(__ccgo_up(htree_group + uintptr(GREEN)*8)) + uintptr(bits)*4))
  12592 		if int32(hcode.Fvalue) >= int32(NUM_LITERAL_CODES) {
  12593 			(*HuffmanCode32)(unsafe.Pointer(huff)).Fbits = int32(hcode.Fbits) + int32(BITS_SPECIAL_MARKER)
  12594 			(*HuffmanCode32)(unsafe.Pointer(huff)).Fvalue = uint32(hcode.Fvalue)
  12595 		} else {
  12596 			(*HuffmanCode32)(unsafe.Pointer(huff)).Fbits = 0
  12597 			(*HuffmanCode32)(unsafe.Pointer(huff)).Fvalue = uint32(0)
  12598 			bits = bits >> uint32(AccumulateHCode(tls, hcode, int32(8), huff))
  12599 			bits = bits >> uint32(AccumulateHCode(tls, **(**HuffmanCode)(__ccgo_up(**(**uintptr)(__ccgo_up(htree_group + uintptr(RED)*8)) + uintptr(bits)*4)), int32(16), huff))
  12600 			bits = bits >> uint32(AccumulateHCode(tls, **(**HuffmanCode)(__ccgo_up(**(**uintptr)(__ccgo_up(htree_group + uintptr(BLUE)*8)) + uintptr(bits)*4)), 0, huff))
  12601 			bits = bits >> uint32(AccumulateHCode(tls, **(**HuffmanCode)(__ccgo_up(**(**uintptr)(__ccgo_up(htree_group + uintptr(ALPHA)*8)) + uintptr(bits)*4)), int32(24), huff))
  12602 			_ = bits
  12603 		}
  12604 		goto _1
  12605 	_1:
  12606 		;
  12607 		code = code + 1
  12608 	}
  12609 }
  12610 
  12611 func ReadHuffmanCodeLengths(tls *libc.TLS, dec uintptr, code_length_code_lengths uintptr, num_symbols int32, code_lengths uintptr) (r int32) {
  12612 	bp := tls.Alloc(48)
  12613 	defer tls.Free(48)
  12614 	var br3, p, v2 uintptr
  12615 	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
  12616 	var v4 uint32_t
  12617 	var _ /* tables at bp+0 */ HuffmanTables
  12618 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  12619 	ok = 0
  12620 	br3 = dec + 40
  12621 	prev_code_len = int32(DEFAULT_CODE_LENGTH)
  12622 	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) {
  12623 		goto End
  12624 	}
  12625 	if VP8LReadBits(tls, br3, int32(1)) != 0 { // use length
  12626 		length_nbits = int32(uint32(2) + uint32(2)*VP8LReadBits(tls, br3, int32(3)))
  12627 		max_symbol = int32(uint32(2) + VP8LReadBits(tls, br3, length_nbits))
  12628 		if max_symbol > num_symbols {
  12629 			goto End
  12630 		}
  12631 	} else {
  12632 		max_symbol = num_symbols
  12633 	}
  12634 	symbol = 0
  12635 	for symbol < num_symbols {
  12636 		v1 = max_symbol
  12637 		max_symbol = max_symbol - 1
  12638 		if v1 == 0 {
  12639 			break
  12640 		}
  12641 		v2 = br3
  12642 		if (*VP8LBitReader)(unsafe.Pointer(v2)).Fbit_pos >= libc.Int32FromInt32(VP8L_WBITS) {
  12643 			VP8LDoFillBitWindow(tls, v2)
  12644 		}
  12645 		v2 = br3
  12646 		v4 = uint32((*VP8LBitReader)(unsafe.Pointer(v2)).Fval >> ((*VP8LBitReader)(unsafe.Pointer(v2)).Fbit_pos & (libc.Int32FromInt32(VP8L_LBITS) - libc.Int32FromInt32(1))))
  12647 		goto _5
  12648 	_5:
  12649 		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
  12650 		(*VP8LBitReader)(unsafe.Pointer(br3)).Fbit_pos = (*VP8LBitReader)(unsafe.Pointer(br3)).Fbit_pos + int32((*HuffmanCode)(unsafe.Pointer(p)).Fbits)
  12651 		code_len = int32((*HuffmanCode)(unsafe.Pointer(p)).Fvalue)
  12652 		if code_len < kCodeLengthLiterals {
  12653 			v1 = symbol
  12654 			symbol = symbol + 1
  12655 			**(**int32)(__ccgo_up(code_lengths + uintptr(v1)*4)) = code_len
  12656 			if code_len != 0 {
  12657 				prev_code_len = code_len
  12658 			}
  12659 		} else {
  12660 			use_prev = libc.BoolInt32(code_len == kCodeLengthRepeatCode)
  12661 			slot = code_len - kCodeLengthLiterals
  12662 			extra_bits = int32(kCodeLengthExtraBits[slot])
  12663 			repeat_offset = int32(kCodeLengthRepeatOffsets[slot])
  12664 			repeat = int32(VP8LReadBits(tls, br3, extra_bits) + uint32(repeat_offset))
  12665 			if symbol+repeat > num_symbols {
  12666 				goto End
  12667 			} else {
  12668 				if use_prev != 0 {
  12669 					v1 = prev_code_len
  12670 				} else {
  12671 					v1 = 0
  12672 				}
  12673 				length = v1
  12674 				for {
  12675 					v6 = repeat
  12676 					repeat = repeat - 1
  12677 					if !(v6 > 0) {
  12678 						break
  12679 					}
  12680 					v7 = symbol
  12681 					symbol = symbol + 1
  12682 					**(**int32)(__ccgo_up(code_lengths + uintptr(v7)*4)) = length
  12683 				}
  12684 			}
  12685 		}
  12686 	}
  12687 	ok = int32(1)
  12688 	goto End
  12689 End:
  12690 	;
  12691 	VP8LHuffmanTablesDeallocate(tls, bp)
  12692 	if !(ok != 0) {
  12693 		return VP8LSetError(tls, dec, int32(VP8_STATUS_BITSTREAM_ERROR))
  12694 	}
  12695 	return ok
  12696 }
  12697 
  12698 // C documentation
  12699 //
  12700 //	// 'code_lengths' is pre-allocated temporary buffer, used for creating Huffman
  12701 //	// tree.
  12702 func ReadHuffmanCode(tls *libc.TLS, alphabet_size int32, dec uintptr, code_lengths uintptr, table uintptr) (r int32) {
  12703 	bp := tls.Alloc(80)
  12704 	defer tls.Free(80)
  12705 	var br uintptr
  12706 	var first_symbol_len_code, i, num_codes, num_symbols, ok, simple_code, size, symbol, v1 int32
  12707 	var _ /* code_length_code_lengths at bp+0 */ [19]int32
  12708 	_, _, _, _, _, _, _, _, _, _ = br, first_symbol_len_code, i, num_codes, num_symbols, ok, simple_code, size, symbol, v1
  12709 	ok = 0
  12710 	size = 0
  12711 	br = dec + 40
  12712 	simple_code = int32(VP8LReadBits(tls, br, int32(1)))
  12713 	libc.Xmemset(tls, code_lengths, 0, uint64(alphabet_size)*uint64(4))
  12714 	if simple_code != 0 { // Read symbols, codes & code lengths directly.
  12715 		num_symbols = int32(VP8LReadBits(tls, br, int32(1)) + uint32(1))
  12716 		first_symbol_len_code = int32(VP8LReadBits(tls, br, int32(1)))
  12717 		if first_symbol_len_code == 0 {
  12718 			v1 = int32(1)
  12719 		} else {
  12720 			v1 = int32(8)
  12721 		}
  12722 		// The first code is either 1 bit or 8 bit code.
  12723 		symbol = int32(VP8LReadBits(tls, br, v1))
  12724 		**(**int32)(__ccgo_up(code_lengths + uintptr(symbol)*4)) = int32(1)
  12725 		// The second code (if present), is always 8 bits long.
  12726 		if num_symbols == int32(2) {
  12727 			symbol = int32(VP8LReadBits(tls, br, int32(8)))
  12728 			**(**int32)(__ccgo_up(code_lengths + uintptr(symbol)*4)) = int32(1)
  12729 		}
  12730 		ok = int32(1)
  12731 	} else {
  12732 		**(**[19]int32)(__ccgo_up(bp)) = [19]int32{}
  12733 		num_codes = int32(VP8LReadBits(tls, br, int32(4)) + uint32(4))
  12734 		i = 0
  12735 		for {
  12736 			if !(i < num_codes) {
  12737 				break
  12738 			}
  12739 			(**(**[19]int32)(__ccgo_up(bp)))[kCodeLengthCodeOrder[i]] = int32(VP8LReadBits(tls, br, int32(3)))
  12740 			goto _2
  12741 		_2:
  12742 			;
  12743 			i = i + 1
  12744 		}
  12745 		ok = ReadHuffmanCodeLengths(tls, dec, bp, alphabet_size, code_lengths)
  12746 	}
  12747 	ok = libc.BoolInt32(ok != 0 && !((*VP8LBitReader)(unsafe.Pointer(br)).Feos != 0))
  12748 	if ok != 0 {
  12749 		size = VP8LBuildHuffmanTable(tls, table, int32(HUFFMAN_TABLE_BITS), code_lengths, alphabet_size)
  12750 	}
  12751 	if !(ok != 0) || size == 0 {
  12752 		return VP8LSetError(tls, dec, int32(VP8_STATUS_BITSTREAM_ERROR))
  12753 	}
  12754 	return size
  12755 }
  12756 
  12757 func ReadHuffmanCodes(tls *libc.TLS, dec uintptr, xsize int32, ysize int32, color_cache_bits int32, allow_recursion int32) (r int32) {
  12758 	bp := tls.Alloc(16)
  12759 	defer tls.Free(16)
  12760 	var br, hdr, huffman_tables, mapped_group, mapping uintptr
  12761 	var group, huffman_pixs, huffman_precision, huffman_xsize, huffman_ysize, i, num_htree_groups, num_htree_groups_max, ok, v9 int32
  12762 	var v1, v2, v4, v5 uint32_t
  12763 	var _ /* htree_groups at bp+8 */ uintptr
  12764 	var _ /* huffman_image at bp+0 */ uintptr
  12765 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  12766 	br = dec + 40
  12767 	hdr = dec + 152
  12768 	**(**uintptr)(__ccgo_up(bp)) = libc.UintptrFromInt32(0)
  12769 	**(**uintptr)(__ccgo_up(bp + 8)) = libc.UintptrFromInt32(0)
  12770 	huffman_tables = hdr + 80
  12771 	num_htree_groups = int32(1)
  12772 	num_htree_groups_max = int32(1)
  12773 	mapping = libc.UintptrFromInt32(0)
  12774 	ok = 0
  12775 	// Check the table has been 0 initialized (through InitMetadata).
  12776 	if allow_recursion != 0 && VP8LReadBits(tls, br, int32(1)) != 0 {
  12777 		// use meta Huffman codes.
  12778 		huffman_precision = int32(uint32(MIN_HUFFMAN_BITS) + VP8LReadBits(tls, br, int32(NUM_HUFFMAN_BITS)))
  12779 		v1 = uint32(huffman_precision)
  12780 		v2 = (uint32(xsize) + uint32(libc.Int32FromInt32(1)<<v1) - uint32(1)) >> v1
  12781 		goto _3
  12782 	_3:
  12783 		huffman_xsize = int32(v2)
  12784 		v4 = uint32(huffman_precision)
  12785 		v5 = (uint32(ysize) + uint32(libc.Int32FromInt32(1)<<v4) - uint32(1)) >> v4
  12786 		goto _6
  12787 	_6:
  12788 		huffman_ysize = int32(v5)
  12789 		huffman_pixs = huffman_xsize * huffman_ysize
  12790 		if !(DecodeImageStream(tls, huffman_xsize, huffman_ysize, 0, dec, bp) != 0) {
  12791 			goto Error
  12792 		}
  12793 		(*VP8LMetadata)(unsafe.Pointer(hdr)).Fhuffman_subsample_bits = huffman_precision
  12794 		i = 0
  12795 		for {
  12796 			if !(i < huffman_pixs) {
  12797 				break
  12798 			}
  12799 			// The huffman data is stored in red and green bytes.
  12800 			group = int32(**(**uint32_t)(__ccgo_up(**(**uintptr)(__ccgo_up(bp)) + uintptr(i)*4)) >> libc.Int32FromInt32(8) & uint32(0xffff))
  12801 			**(**uint32_t)(__ccgo_up(**(**uintptr)(__ccgo_up(bp)) + uintptr(i)*4)) = uint32(group)
  12802 			if group >= num_htree_groups_max {
  12803 				num_htree_groups_max = group + int32(1)
  12804 			}
  12805 			goto _7
  12806 		_7:
  12807 			;
  12808 			i = i + 1
  12809 		}
  12810 		// Check the validity of num_htree_groups_max. If it seems too big, use a
  12811 		// smaller value for later. This will prevent big memory allocations to end
  12812 		// up with a bad bitstream anyway.
  12813 		// The value of 1000 is totally arbitrary. We know that num_htree_groups_max
  12814 		// is smaller than (1 << 16) and should be smaller than the number of pixels
  12815 		// (though the format allows it to be bigger).
  12816 		if num_htree_groups_max > int32(1000) || num_htree_groups_max > xsize*ysize {
  12817 			// Create a mapping from the used indices to the minimal set of used
  12818 			// values [0, num_htree_groups)
  12819 			mapping = WebPSafeMalloc(tls, uint64(num_htree_groups_max), uint64(4))
  12820 			if mapping == libc.UintptrFromInt32(0) {
  12821 				VP8LSetError(tls, dec, int32(VP8_STATUS_OUT_OF_MEMORY))
  12822 				goto Error
  12823 			}
  12824 			// -1 means a value is unmapped, and therefore unused in the Huffman
  12825 			// image.
  12826 			libc.Xmemset(tls, mapping, int32(0xff), uint64(num_htree_groups_max)*uint64(4))
  12827 			num_htree_groups = 0
  12828 			i = libc.Int32FromInt32(0)
  12829 			for {
  12830 				if !(i < huffman_pixs) {
  12831 					break
  12832 				}
  12833 				// Get the current mapping for the group and remap the Huffman image.
  12834 				mapped_group = mapping + uintptr(**(**uint32_t)(__ccgo_up(**(**uintptr)(__ccgo_up(bp)) + uintptr(i)*4)))*4
  12835 				if **(**int32)(__ccgo_up(mapped_group)) == -int32(1) {
  12836 					v9 = num_htree_groups
  12837 					num_htree_groups = num_htree_groups + 1
  12838 					**(**int32)(__ccgo_up(mapped_group)) = v9
  12839 				}
  12840 				**(**uint32_t)(__ccgo_up(**(**uintptr)(__ccgo_up(bp)) + uintptr(i)*4)) = uint32(**(**int32)(__ccgo_up(mapped_group)))
  12841 				goto _8
  12842 			_8:
  12843 				;
  12844 				i = i + 1
  12845 			}
  12846 		} else {
  12847 			num_htree_groups = num_htree_groups_max
  12848 		}
  12849 	}
  12850 	if (*VP8LBitReader)(unsafe.Pointer(br)).Feos != 0 {
  12851 		goto Error
  12852 	}
  12853 	if !(ReadHuffmanCodesHelper(tls, color_cache_bits, num_htree_groups, num_htree_groups_max, mapping, dec, huffman_tables, bp+8) != 0) {
  12854 		goto Error
  12855 	}
  12856 	ok = int32(1)
  12857 	// All OK. Finalize pointers.
  12858 	(*VP8LMetadata)(unsafe.Pointer(hdr)).Fhuffman_image = **(**uintptr)(__ccgo_up(bp))
  12859 	(*VP8LMetadata)(unsafe.Pointer(hdr)).Fnum_htree_groups = num_htree_groups
  12860 	(*VP8LMetadata)(unsafe.Pointer(hdr)).Fhtree_groups = **(**uintptr)(__ccgo_up(bp + 8))
  12861 	goto Error
  12862 Error:
  12863 	;
  12864 	WebPSafeFree(tls, mapping)
  12865 	if !(ok != 0) {
  12866 		WebPSafeFree(tls, **(**uintptr)(__ccgo_up(bp)))
  12867 		VP8LHuffmanTablesDeallocate(tls, huffman_tables)
  12868 		VP8LHtreeGroupsFree(tls, **(**uintptr)(__ccgo_up(bp + 8)))
  12869 	}
  12870 	return ok
  12871 }
  12872 
  12873 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) {
  12874 	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
  12875 	var code_lengths, htree_group, htrees uintptr
  12876 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  12877 	ok = 0
  12878 	if color_cache_bits > 0 {
  12879 		v1 = int32(1) << color_cache_bits
  12880 	} else {
  12881 		v1 = 0
  12882 	}
  12883 	max_alphabet_size = int32(kAlphabetSize[0]) + v1
  12884 	table_size = int32(kTableSize[color_cache_bits])
  12885 	code_lengths = libc.UintptrFromInt32(0)
  12886 	if mapping == libc.UintptrFromInt32(0) && num_htree_groups != num_htree_groups_max || num_htree_groups > num_htree_groups_max {
  12887 		goto Error
  12888 	}
  12889 	code_lengths = WebPSafeCalloc(tls, uint64(max_alphabet_size), uint64(4))
  12890 	**(**uintptr)(__ccgo_up(htree_groups)) = VP8LHtreeGroupsNew(tls, num_htree_groups)
  12891 	if **(**uintptr)(__ccgo_up(htree_groups)) == libc.UintptrFromInt32(0) || code_lengths == libc.UintptrFromInt32(0) || !(VP8LHuffmanTablesAllocate(tls, num_htree_groups*table_size, huffman_tables) != 0) {
  12892 		VP8LSetError(tls, dec, int32(VP8_STATUS_OUT_OF_MEMORY))
  12893 		goto Error
  12894 	}
  12895 	i = 0
  12896 	for {
  12897 		if !(i < num_htree_groups_max) {
  12898 			break
  12899 		}
  12900 		// If the index "i" is unused in the Huffman image, just make sure the
  12901 		// coefficients are valid but do not store them.
  12902 		if mapping != libc.UintptrFromInt32(0) && **(**int32)(__ccgo_up(mapping + uintptr(i)*4)) == -int32(1) {
  12903 			j = 0
  12904 			for {
  12905 				if !(j < int32(HUFFMAN_CODES_PER_META_CODE)) {
  12906 					break
  12907 				}
  12908 				alphabet_size = int32(kAlphabetSize[j])
  12909 				if j == 0 && color_cache_bits > 0 {
  12910 					alphabet_size = alphabet_size + int32(1)<<color_cache_bits
  12911 				}
  12912 				// Passing in NULL so that nothing gets filled.
  12913 				if !(ReadHuffmanCode(tls, alphabet_size, dec, code_lengths, libc.UintptrFromInt32(0)) != 0) {
  12914 					goto Error
  12915 				}
  12916 				goto _3
  12917 			_3:
  12918 				;
  12919 				j = j + 1
  12920 			}
  12921 		} else {
  12922 			if mapping == libc.UintptrFromInt32(0) {
  12923 				v1 = i
  12924 			} else {
  12925 				v1 = **(**int32)(__ccgo_up(mapping + uintptr(i)*4))
  12926 			}
  12927 			htree_group = **(**uintptr)(__ccgo_up(htree_groups)) + uintptr(v1)*568
  12928 			htrees = htree_group
  12929 			total_size = 0
  12930 			is_trivial_literal = int32(1)
  12931 			max_bits = 0
  12932 			j = 0
  12933 			for {
  12934 				if !(j < int32(HUFFMAN_CODES_PER_META_CODE)) {
  12935 					break
  12936 				}
  12937 				alphabet_size1 = int32(kAlphabetSize[j])
  12938 				if j == 0 && color_cache_bits > 0 {
  12939 					alphabet_size1 = alphabet_size1 + int32(1)<<color_cache_bits
  12940 				}
  12941 				size = ReadHuffmanCode(tls, alphabet_size1, dec, code_lengths, huffman_tables)
  12942 				**(**uintptr)(__ccgo_up(htrees + uintptr(j)*8)) = (*HuffmanTablesSegment)(unsafe.Pointer((*HuffmanTables)(unsafe.Pointer(huffman_tables)).Fcurr_segment)).Fcurr_table
  12943 				if size == 0 {
  12944 					goto Error
  12945 				}
  12946 				if is_trivial_literal != 0 && int32(kLiteralMap[j]) == int32(1) {
  12947 					is_trivial_literal = libc.BoolInt32(int32((*HuffmanCode)(unsafe.Pointer(**(**uintptr)(__ccgo_up(htrees + uintptr(j)*8)))).Fbits) == 0)
  12948 				}
  12949 				total_size = total_size + int32((*HuffmanCode)(unsafe.Pointer(**(**uintptr)(__ccgo_up(htrees + uintptr(j)*8)))).Fbits)
  12950 				**(**uintptr)(__ccgo_up((*HuffmanTables)(unsafe.Pointer(huffman_tables)).Fcurr_segment + 8)) += uintptr(size) * 4
  12951 				if j <= int32(ALPHA) {
  12952 					local_max_bits = **(**int32)(__ccgo_up(code_lengths))
  12953 					k = int32(1)
  12954 					for {
  12955 						if !(k < alphabet_size1) {
  12956 							break
  12957 						}
  12958 						if **(**int32)(__ccgo_up(code_lengths + uintptr(k)*4)) > local_max_bits {
  12959 							local_max_bits = **(**int32)(__ccgo_up(code_lengths + uintptr(k)*4))
  12960 						}
  12961 						goto _6
  12962 					_6:
  12963 						;
  12964 						k = k + 1
  12965 					}
  12966 					max_bits = max_bits + local_max_bits
  12967 				}
  12968 				goto _5
  12969 			_5:
  12970 				;
  12971 				j = j + 1
  12972 			}
  12973 			(*HTreeGroup)(unsafe.Pointer(htree_group)).Fis_trivial_literal = is_trivial_literal
  12974 			(*HTreeGroup)(unsafe.Pointer(htree_group)).Fis_trivial_code = 0
  12975 			if is_trivial_literal != 0 {
  12976 				red = int32((**(**HuffmanCode)(__ccgo_up(**(**uintptr)(__ccgo_up(htrees + uintptr(RED)*8))))).Fvalue)
  12977 				blue = int32((**(**HuffmanCode)(__ccgo_up(**(**uintptr)(__ccgo_up(htrees + uintptr(BLUE)*8))))).Fvalue)
  12978 				alpha = int32((**(**HuffmanCode)(__ccgo_up(**(**uintptr)(__ccgo_up(htrees + uintptr(ALPHA)*8))))).Fvalue)
  12979 				(*HTreeGroup)(unsafe.Pointer(htree_group)).Fliteral_arb = uint32(alpha)<<libc.Int32FromInt32(24) | uint32(red<<libc.Int32FromInt32(16)) | uint32(blue)
  12980 				if total_size == 0 && int32((**(**HuffmanCode)(__ccgo_up(**(**uintptr)(__ccgo_up(htrees + uintptr(GREEN)*8))))).Fvalue) < int32(NUM_LITERAL_CODES) {
  12981 					(*HTreeGroup)(unsafe.Pointer(htree_group)).Fis_trivial_code = int32(1)
  12982 					**(**uint32_t)(__ccgo_up(htree_group + 44)) |= uint32(int32((**(**HuffmanCode)(__ccgo_up(**(**uintptr)(__ccgo_up(htrees + uintptr(GREEN)*8))))).Fvalue) << int32(8))
  12983 				}
  12984 			}
  12985 			(*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))
  12986 			if (*HTreeGroup)(unsafe.Pointer(htree_group)).Fuse_packed_table != 0 {
  12987 				BuildPackedTable(tls, htree_group)
  12988 			}
  12989 		}
  12990 		goto _2
  12991 	_2:
  12992 		;
  12993 		i = i + 1
  12994 	}
  12995 	ok = int32(1)
  12996 	goto Error
  12997 Error:
  12998 	;
  12999 	WebPSafeFree(tls, code_lengths)
  13000 	if !(ok != 0) {
  13001 		VP8LHuffmanTablesDeallocate(tls, huffman_tables)
  13002 		VP8LHtreeGroupsFree(tls, **(**uintptr)(__ccgo_up(htree_groups)))
  13003 		**(**uintptr)(__ccgo_up(htree_groups)) = libc.UintptrFromInt32(0)
  13004 	}
  13005 	return ok
  13006 }
  13007 
  13008 //------------------------------------------------------------------------------
  13009 // Scaling.
  13010 
  13011 func AllocateAndInitRescaler(tls *libc.TLS, dec uintptr, io uintptr) (r int32) {
  13012 	var in_height, in_width, num_channels, out_height, out_width int32
  13013 	var memory, scaled_data, work uintptr
  13014 	var memory_size, scaled_data_size, work_size uint64_t
  13015 	_, _, _, _, _, _, _, _, _, _, _ = in_height, in_width, memory, memory_size, num_channels, out_height, out_width, scaled_data, scaled_data_size, work, work_size
  13016 	num_channels = int32(4)
  13017 	in_width = (*VP8Io)(unsafe.Pointer(io)).Fmb_w
  13018 	out_width = (*VP8Io)(unsafe.Pointer(io)).Fscaled_width
  13019 	in_height = (*VP8Io)(unsafe.Pointer(io)).Fmb_h
  13020 	out_height = (*VP8Io)(unsafe.Pointer(io)).Fscaled_height
  13021 	work_size = uint64(int32(2)*num_channels) * uint64(out_width) // Rescaler work area.
  13022 	scaled_data_size = uint64(out_width)                          // Temporary storage for scaled BGRA data.
  13023 	memory_size = uint64(104) + work_size*uint64(4) + scaled_data_size*uint64(4)
  13024 	memory = WebPSafeMalloc(tls, memory_size, uint64(1))
  13025 	if memory == libc.UintptrFromInt32(0) {
  13026 		return VP8LSetError(tls, dec, int32(VP8_STATUS_OUT_OF_MEMORY))
  13027 	}
  13028 	(*VP8LDecoder)(unsafe.Pointer(dec)).Frescaler_memory = memory
  13029 	(*VP8LDecoder)(unsafe.Pointer(dec)).Frescaler = memory
  13030 	memory = memory + uintptr(104)
  13031 	work = memory
  13032 	memory = memory + uintptr(work_size*uint64(4))
  13033 	scaled_data = memory
  13034 	if !(WebPRescalerInit(tls, (*VP8LDecoder)(unsafe.Pointer(dec)).Frescaler, in_width, in_height, scaled_data, out_width, out_height, 0, num_channels, work) != 0) {
  13035 		return 0
  13036 	}
  13037 	return int32(1)
  13038 }
  13039 
  13040 //------------------------------------------------------------------------------
  13041 // Export to ARGB
  13042 
  13043 // C documentation
  13044 //
  13045 //	// We have special "export" function since we need to convert from BGRA
  13046 func Export(tls *libc.TLS, rescaler2 uintptr, colorspace WEBP_CSP_MODE1, rgba_stride int32, rgba uintptr) (r int32) {
  13047 	var dst, src, v1, v4 uintptr
  13048 	var dst_width, num_lines_out, v2, v5 int32
  13049 	_, _, _, _, _, _, _, _ = dst, dst_width, num_lines_out, src, v1, v2, v4, v5
  13050 	src = (*WebPRescaler)(unsafe.Pointer(rescaler2)).Fdst
  13051 	dst = rgba
  13052 	dst_width = (*WebPRescaler)(unsafe.Pointer(rescaler2)).Fdst_width
  13053 	num_lines_out = 0
  13054 	for {
  13055 		v1 = rescaler2
  13056 		v4 = v1
  13057 		v5 = libc.BoolInt32((*WebPRescaler)(unsafe.Pointer(v4)).Fdst_y >= (*WebPRescaler)(unsafe.Pointer(v4)).Fdst_height)
  13058 		goto _6
  13059 	_6:
  13060 		;
  13061 		v2 = libc.BoolInt32(!(v5 != 0) && (*WebPRescaler)(unsafe.Pointer(v1)).Fy_accum <= 0)
  13062 		goto _3
  13063 	_3:
  13064 		if !(v2 != 0) {
  13065 			break
  13066 		}
  13067 		WebPRescalerExportRow(tls, rescaler2)
  13068 		(*(*func(*libc.TLS, uintptr, int32, int32))(unsafe.Pointer(&struct{ uintptr }{WebPMultARGBRow})))(tls, src, dst_width, int32(1))
  13069 		VP8LConvertFromBGRA(tls, src, dst_width, colorspace, dst)
  13070 		dst = dst + uintptr(rgba_stride)
  13071 		num_lines_out = num_lines_out + 1
  13072 	}
  13073 	return num_lines_out
  13074 }
  13075 
  13076 // C documentation
  13077 //
  13078 //	// Emit scaled rows.
  13079 func EmitRescaledRowsRGBA(tls *libc.TLS, dec uintptr, in uintptr, in_stride int32, mb_h int32, out uintptr, out_stride int32) (r int32) {
  13080 	var colorspace WEBP_CSP_MODE1
  13081 	var lines_imported, lines_left, needed_lines, num_lines_in, num_lines_out int32
  13082 	var row_in, row_out uintptr
  13083 	_, _, _, _, _, _, _, _ = colorspace, lines_imported, lines_left, needed_lines, num_lines_in, num_lines_out, row_in, row_out
  13084 	colorspace = (*WebPDecBuffer)(unsafe.Pointer((*VP8LDecoder)(unsafe.Pointer(dec)).Foutput)).Fcolorspace
  13085 	num_lines_in = 0
  13086 	num_lines_out = 0
  13087 	for num_lines_in < mb_h {
  13088 		row_in = in + uintptr(int64(num_lines_in)*int64(in_stride))
  13089 		row_out = out + uintptr(int64(num_lines_out)*int64(out_stride))
  13090 		lines_left = mb_h - num_lines_in
  13091 		needed_lines = WebPRescaleNeededLines(tls, (*VP8LDecoder)(unsafe.Pointer(dec)).Frescaler, lines_left)
  13092 		WebPMultARGBRows(tls, row_in, in_stride, (*WebPRescaler)(unsafe.Pointer((*VP8LDecoder)(unsafe.Pointer(dec)).Frescaler)).Fsrc_width, needed_lines, 0)
  13093 		lines_imported = WebPRescalerImport(tls, (*VP8LDecoder)(unsafe.Pointer(dec)).Frescaler, lines_left, row_in, in_stride)
  13094 		num_lines_in = num_lines_in + lines_imported
  13095 		num_lines_out = num_lines_out + Export(tls, (*VP8LDecoder)(unsafe.Pointer(dec)).Frescaler, colorspace, out_stride, row_out)
  13096 	}
  13097 	return num_lines_out
  13098 }
  13099 
  13100 // C documentation
  13101 //
  13102 //	// Emit rows without any scaling.
  13103 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) {
  13104 	var lines, v1 int32
  13105 	var row_out uintptr
  13106 	_, _, _ = lines, row_out, v1
  13107 	lines = mb_h
  13108 	row_out = out
  13109 	for {
  13110 		v1 = lines
  13111 		lines = lines - 1
  13112 		if !(v1 > 0) {
  13113 			break
  13114 		}
  13115 		VP8LConvertFromBGRA(tls, row_in, mb_w, colorspace, row_out)
  13116 		row_in = row_in + uintptr(in_stride)
  13117 		row_out = row_out + uintptr(out_stride)
  13118 	}
  13119 	return mb_h // Num rows out == num rows in.
  13120 }
  13121 
  13122 //------------------------------------------------------------------------------
  13123 // Export to YUVA
  13124 
  13125 func ConvertToYUVA(tls *libc.TLS, src uintptr, width int32, y_pos int32, output uintptr) {
  13126 	var a, buf, u, v uintptr
  13127 	_, _, _, _ = a, buf, u, v
  13128 	buf = output + 16
  13129 	// first, the luma plane
  13130 	(*(*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)
  13131 	// then U/V planes
  13132 	u = (*WebPYUVABuffer)(unsafe.Pointer(buf)).Fu + uintptr(y_pos>>int32(1)*(*WebPYUVABuffer)(unsafe.Pointer(buf)).Fu_stride)
  13133 	v = (*WebPYUVABuffer)(unsafe.Pointer(buf)).Fv + uintptr(y_pos>>int32(1)*(*WebPYUVABuffer)(unsafe.Pointer(buf)).Fv_stride)
  13134 	// even lines: store values
  13135 	// odd lines: average with previous values
  13136 	(*(*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)))
  13137 	// Lastly, store alpha if needed.
  13138 	if (*WebPYUVABuffer)(unsafe.Pointer(buf)).Fa != libc.UintptrFromInt32(0) {
  13139 		a = (*WebPYUVABuffer)(unsafe.Pointer(buf)).Fa + uintptr(y_pos*(*WebPYUVABuffer)(unsafe.Pointer(buf)).Fa_stride)
  13140 		(*(*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)
  13141 	}
  13142 }
  13143 
  13144 func ExportYUVA(tls *libc.TLS, dec uintptr, y_pos int32) (r int32) {
  13145 	var dst_width, num_lines_out, v2, v5 int32
  13146 	var rescaler2, src, v1, v4 uintptr
  13147 	_, _, _, _, _, _, _, _ = dst_width, num_lines_out, rescaler2, src, v1, v2, v4, v5
  13148 	rescaler2 = (*VP8LDecoder)(unsafe.Pointer(dec)).Frescaler
  13149 	src = (*WebPRescaler)(unsafe.Pointer(rescaler2)).Fdst
  13150 	dst_width = (*WebPRescaler)(unsafe.Pointer(rescaler2)).Fdst_width
  13151 	num_lines_out = 0
  13152 	for {
  13153 		v1 = rescaler2
  13154 		v4 = v1
  13155 		v5 = libc.BoolInt32((*WebPRescaler)(unsafe.Pointer(v4)).Fdst_y >= (*WebPRescaler)(unsafe.Pointer(v4)).Fdst_height)
  13156 		goto _6
  13157 	_6:
  13158 		;
  13159 		v2 = libc.BoolInt32(!(v5 != 0) && (*WebPRescaler)(unsafe.Pointer(v1)).Fy_accum <= 0)
  13160 		goto _3
  13161 	_3:
  13162 		if !(v2 != 0) {
  13163 			break
  13164 		}
  13165 		WebPRescalerExportRow(tls, rescaler2)
  13166 		(*(*func(*libc.TLS, uintptr, int32, int32))(unsafe.Pointer(&struct{ uintptr }{WebPMultARGBRow})))(tls, src, dst_width, int32(1))
  13167 		ConvertToYUVA(tls, src, dst_width, y_pos, (*VP8LDecoder)(unsafe.Pointer(dec)).Foutput)
  13168 		y_pos = y_pos + 1
  13169 		num_lines_out = num_lines_out + 1
  13170 	}
  13171 	return num_lines_out
  13172 }
  13173 
  13174 func EmitRescaledRowsYUVA(tls *libc.TLS, dec uintptr, in uintptr, in_stride int32, mb_h int32) (r int32) {
  13175 	var lines_imported, lines_left, needed_lines, num_lines_in, y_pos int32
  13176 	_, _, _, _, _ = lines_imported, lines_left, needed_lines, num_lines_in, y_pos
  13177 	num_lines_in = 0
  13178 	y_pos = (*VP8LDecoder)(unsafe.Pointer(dec)).Flast_out_row
  13179 	for num_lines_in < mb_h {
  13180 		lines_left = mb_h - num_lines_in
  13181 		needed_lines = WebPRescaleNeededLines(tls, (*VP8LDecoder)(unsafe.Pointer(dec)).Frescaler, lines_left)
  13182 		WebPMultARGBRows(tls, in, in_stride, (*WebPRescaler)(unsafe.Pointer((*VP8LDecoder)(unsafe.Pointer(dec)).Frescaler)).Fsrc_width, needed_lines, 0)
  13183 		lines_imported = WebPRescalerImport(tls, (*VP8LDecoder)(unsafe.Pointer(dec)).Frescaler, lines_left, in, in_stride)
  13184 		num_lines_in = num_lines_in + lines_imported
  13185 		in = in + uintptr(needed_lines*in_stride)
  13186 		y_pos = y_pos + ExportYUVA(tls, dec, y_pos)
  13187 	}
  13188 	return y_pos
  13189 }
  13190 
  13191 func EmitRowsYUVA(tls *libc.TLS, dec uintptr, in uintptr, in_stride int32, mb_w int32, num_rows int32) (r int32) {
  13192 	var y_pos, v1 int32
  13193 	_, _ = y_pos, v1
  13194 	y_pos = (*VP8LDecoder)(unsafe.Pointer(dec)).Flast_out_row
  13195 	for {
  13196 		v1 = num_rows
  13197 		num_rows = num_rows - 1
  13198 		if !(v1 > 0) {
  13199 			break
  13200 		}
  13201 		ConvertToYUVA(tls, in, mb_w, y_pos, (*VP8LDecoder)(unsafe.Pointer(dec)).Foutput)
  13202 		in = in + uintptr(in_stride)
  13203 		y_pos = y_pos + 1
  13204 	}
  13205 	return y_pos
  13206 }
  13207 
  13208 //------------------------------------------------------------------------------
  13209 // Cropping.
  13210 
  13211 // C documentation
  13212 //
  13213 //	// Sets io->mb_y, io->mb_h & io->mb_w according to start row, end row and
  13214 //	// crop options. Also updates the input data pointer, so that it points to the
  13215 //	// start of the cropped window. Note that pixels are in ARGB format even if
  13216 //	// 'in_data' is uint8_t*.
  13217 //	// Returns true if the crop window is not empty.
  13218 func SetCropWindow(tls *libc.TLS, io uintptr, y_start int32, y_end int32, in_data uintptr, pixel_stride int32) (r int32) {
  13219 	var delta int32
  13220 	_ = delta
  13221 	if y_end > (*VP8Io)(unsafe.Pointer(io)).Fcrop_bottom {
  13222 		y_end = (*VP8Io)(unsafe.Pointer(io)).Fcrop_bottom // make sure we don't overflow on last row.
  13223 	}
  13224 	if y_start < (*VP8Io)(unsafe.Pointer(io)).Fcrop_top {
  13225 		delta = (*VP8Io)(unsafe.Pointer(io)).Fcrop_top - y_start
  13226 		y_start = (*VP8Io)(unsafe.Pointer(io)).Fcrop_top
  13227 		**(**uintptr)(__ccgo_up(in_data)) += uintptr(delta * pixel_stride)
  13228 	}
  13229 	if y_start >= y_end {
  13230 		return 0
  13231 	} // Crop window is empty.
  13232 	**(**uintptr)(__ccgo_up(in_data)) += uintptr(uint64((*VP8Io)(unsafe.Pointer(io)).Fcrop_left) * uint64(4))
  13233 	(*VP8Io)(unsafe.Pointer(io)).Fmb_y = y_start - (*VP8Io)(unsafe.Pointer(io)).Fcrop_top
  13234 	(*VP8Io)(unsafe.Pointer(io)).Fmb_w = (*VP8Io)(unsafe.Pointer(io)).Fcrop_right - (*VP8Io)(unsafe.Pointer(io)).Fcrop_left
  13235 	(*VP8Io)(unsafe.Pointer(io)).Fmb_h = y_end - y_start
  13236 	return int32(1) // Non-empty crop window.
  13237 }
  13238 
  13239 //------------------------------------------------------------------------------
  13240 
  13241 func GetMetaIndex(tls *libc.TLS, image uintptr, xsize int32, bits int32, x int32, y int32) (r int32) {
  13242 	if bits == 0 {
  13243 		return 0
  13244 	}
  13245 	return int32(**(**uint32_t)(__ccgo_up(image + uintptr(xsize*(y>>bits)+x>>bits)*4)))
  13246 }
  13247 
  13248 func GetHtreeGroupForPos(tls *libc.TLS, hdr uintptr, x int32, y int32) (r uintptr) {
  13249 	var meta_index int32
  13250 	_ = meta_index
  13251 	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)
  13252 	return (*VP8LMetadata)(unsafe.Pointer(hdr)).Fhtree_groups + uintptr(meta_index)*568
  13253 }
  13254 
  13255 //------------------------------------------------------------------------------
  13256 // Main loop, with custom row-processing function
  13257 
  13258 type ProcessRowsFunc = uintptr
  13259 
  13260 func ApplyInverseTransforms(tls *libc.TLS, dec uintptr, start_row int32, num_rows int32, rows uintptr) {
  13261 	var cache_pixs, end_row, n, v1 int32
  13262 	var rows_in, rows_out, transform uintptr
  13263 	_, _, _, _, _, _, _ = cache_pixs, end_row, n, rows_in, rows_out, transform, v1
  13264 	n = (*VP8LDecoder)(unsafe.Pointer(dec)).Fnext_transform
  13265 	cache_pixs = (*VP8LDecoder)(unsafe.Pointer(dec)).Fwidth * num_rows
  13266 	end_row = start_row + num_rows
  13267 	rows_in = rows
  13268 	rows_out = (*VP8LDecoder)(unsafe.Pointer(dec)).Fargb_cache
  13269 	// Inverse transforms.
  13270 	for {
  13271 		v1 = n
  13272 		n = n - 1
  13273 		if !(v1 > 0) {
  13274 			break
  13275 		}
  13276 		transform = dec + 280 + uintptr(n)*24
  13277 		VP8LInverseTransform(tls, transform, start_row, end_row, rows_in, rows_out)
  13278 		rows_in = rows_out
  13279 	}
  13280 	if rows_in != rows_out {
  13281 		// No transform called, hence just copy.
  13282 		libc.Xmemcpy(tls, rows_out, rows_in, uint64(cache_pixs)*uint64(4))
  13283 	}
  13284 }
  13285 
  13286 // C documentation
  13287 //
  13288 //	// Processes (transforms, scales & color-converts) the rows decoded after the
  13289 //	// last call.
  13290 func ProcessRows(tls *libc.TLS, dec uintptr, row int32) {
  13291 	bp := tls.Alloc(16)
  13292 	defer tls.Free(16)
  13293 	var buf, io, output, rgba, rows uintptr
  13294 	var in_stride, num_rows, num_rows_out, v1, v3 int32
  13295 	var _ /* rows_data at bp+0 */ uintptr
  13296 	_, _, _, _, _, _, _, _, _, _ = buf, in_stride, io, num_rows, num_rows_out, output, rgba, rows, v1, v3
  13297 	rows = (*VP8LDecoder)(unsafe.Pointer(dec)).Fpixels + uintptr((*VP8LDecoder)(unsafe.Pointer(dec)).Fwidth*(*VP8LDecoder)(unsafe.Pointer(dec)).Flast_row)*4
  13298 	num_rows = row - (*VP8LDecoder)(unsafe.Pointer(dec)).Flast_row
  13299 	// We can't process more than NUM_ARGB_CACHE_ROWS at a time (that's the size
  13300 	// of argb_cache), but we currently don't need more than that.
  13301 	if num_rows > 0 { // Emit output.
  13302 		io = (*VP8LDecoder)(unsafe.Pointer(dec)).Fio
  13303 		**(**uintptr)(__ccgo_up(bp)) = (*VP8LDecoder)(unsafe.Pointer(dec)).Fargb_cache
  13304 		in_stride = int32(uint64((*VP8Io)(unsafe.Pointer(io)).Fwidth) * uint64(4)) // in unit of RGBA
  13305 		ApplyInverseTransforms(tls, dec, (*VP8LDecoder)(unsafe.Pointer(dec)).Flast_row, num_rows, rows)
  13306 		if !(SetCropWindow(tls, io, (*VP8LDecoder)(unsafe.Pointer(dec)).Flast_row, row, bp, in_stride) != 0) {
  13307 			// Nothing to output (this time).
  13308 		} else {
  13309 			output = (*VP8LDecoder)(unsafe.Pointer(dec)).Foutput
  13310 			v1 = libc.BoolInt32((*WebPDecBuffer)(unsafe.Pointer(output)).Fcolorspace < int32(MODE_YUV))
  13311 			goto _2
  13312 		_2:
  13313 			if v1 != 0 { // convert to RGBA
  13314 				buf = output + 16
  13315 				rgba = (*WebPRGBABuffer)(unsafe.Pointer(buf)).Frgba + uintptr(int64((*VP8LDecoder)(unsafe.Pointer(dec)).Flast_out_row)*int64((*WebPRGBABuffer)(unsafe.Pointer(buf)).Fstride))
  13316 				if (*VP8Io)(unsafe.Pointer(io)).Fuse_scaling != 0 {
  13317 					v3 = EmitRescaledRowsRGBA(tls, dec, **(**uintptr)(__ccgo_up(bp)), in_stride, (*VP8Io)(unsafe.Pointer(io)).Fmb_h, rgba, (*WebPRGBABuffer)(unsafe.Pointer(buf)).Fstride)
  13318 				} else {
  13319 					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)
  13320 				}
  13321 				num_rows_out = v3
  13322 				// Update 'last_out_row'.
  13323 				**(**int32)(__ccgo_up(dec + 148)) += num_rows_out
  13324 			} else { // convert to YUVA
  13325 				if (*VP8Io)(unsafe.Pointer(io)).Fuse_scaling != 0 {
  13326 					v1 = EmitRescaledRowsYUVA(tls, dec, **(**uintptr)(__ccgo_up(bp)), in_stride, (*VP8Io)(unsafe.Pointer(io)).Fmb_h)
  13327 				} else {
  13328 					v1 = EmitRowsYUVA(tls, dec, **(**uintptr)(__ccgo_up(bp)), in_stride, (*VP8Io)(unsafe.Pointer(io)).Fmb_w, (*VP8Io)(unsafe.Pointer(io)).Fmb_h)
  13329 				}
  13330 				(*VP8LDecoder)(unsafe.Pointer(dec)).Flast_out_row = v1
  13331 			}
  13332 		}
  13333 	}
  13334 	// Update 'last_row'.
  13335 	(*VP8LDecoder)(unsafe.Pointer(dec)).Flast_row = row
  13336 }
  13337 
  13338 // C documentation
  13339 //
  13340 //	// Row-processing for the special case when alpha data contains only one
  13341 //	// transform (color indexing), and trivial non-green literals.
  13342 func Is8bOptimizable(tls *libc.TLS, hdr uintptr) (r int32) {
  13343 	var htrees uintptr
  13344 	var i int32
  13345 	_, _ = htrees, i
  13346 	if (*VP8LMetadata)(unsafe.Pointer(hdr)).Fcolor_cache_size > 0 {
  13347 		return 0
  13348 	}
  13349 	// When the Huffman tree contains only one symbol, we can skip the
  13350 	// call to ReadSymbol() for red/blue/alpha channels.
  13351 	i = 0
  13352 	for {
  13353 		if !(i < (*VP8LMetadata)(unsafe.Pointer(hdr)).Fnum_htree_groups) {
  13354 			break
  13355 		}
  13356 		htrees = (*VP8LMetadata)(unsafe.Pointer(hdr)).Fhtree_groups + uintptr(i)*568
  13357 		if int32((**(**HuffmanCode)(__ccgo_up(**(**uintptr)(__ccgo_up(htrees + uintptr(RED)*8))))).Fbits) > 0 {
  13358 			return 0
  13359 		}
  13360 		if int32((**(**HuffmanCode)(__ccgo_up(**(**uintptr)(__ccgo_up(htrees + uintptr(BLUE)*8))))).Fbits) > 0 {
  13361 			return 0
  13362 		}
  13363 		if int32((**(**HuffmanCode)(__ccgo_up(**(**uintptr)(__ccgo_up(htrees + uintptr(ALPHA)*8))))).Fbits) > 0 {
  13364 			return 0
  13365 		}
  13366 		goto _1
  13367 	_1:
  13368 		;
  13369 		i = i + 1
  13370 	}
  13371 	return int32(1)
  13372 }
  13373 
  13374 func AlphaApplyFilter(tls *libc.TLS, alph_dec uintptr, first_row int32, last_row int32, out uintptr, stride int32) {
  13375 	var prev_line uintptr
  13376 	var y int32
  13377 	_, _ = prev_line, y
  13378 	if (*ALPHDecoder)(unsafe.Pointer(alph_dec)).Ffilter != int32(WEBP_FILTER_NONE) {
  13379 		prev_line = (*ALPHDecoder)(unsafe.Pointer(alph_dec)).Fprev_line
  13380 		y = first_row
  13381 		for {
  13382 			if !(y < last_row) {
  13383 				break
  13384 			}
  13385 			(*(*func(*libc.TLS, uintptr, uintptr, uintptr, int32))(unsafe.Pointer(&struct{ uintptr }{WebPUnfilters[(*ALPHDecoder)(unsafe.Pointer(alph_dec)).Ffilter]})))(tls, prev_line, out, out, stride)
  13386 			prev_line = out
  13387 			out = out + uintptr(stride)
  13388 			goto _1
  13389 		_1:
  13390 			;
  13391 			y = y + 1
  13392 		}
  13393 		(*ALPHDecoder)(unsafe.Pointer(alph_dec)).Fprev_line = prev_line
  13394 	}
  13395 }
  13396 
  13397 func ExtractPalettedAlphaRows(tls *libc.TLS, dec uintptr, last_row int32) {
  13398 	var alph_dec, in, out, transform uintptr
  13399 	var first_row, top_row, width, v1, v2 int32
  13400 	_, _, _, _, _, _, _, _, _ = alph_dec, first_row, in, out, top_row, transform, width, v1, v2
  13401 	// For vertical and gradient filtering, we need to decode the part above the
  13402 	// crop_top row, in order to have the correct spatial predictors.
  13403 	alph_dec = (*VP8Io)(unsafe.Pointer((*VP8LDecoder)(unsafe.Pointer(dec)).Fio)).Fopaque
  13404 	if (*ALPHDecoder)(unsafe.Pointer(alph_dec)).Ffilter == int32(WEBP_FILTER_NONE) || (*ALPHDecoder)(unsafe.Pointer(alph_dec)).Ffilter == int32(WEBP_FILTER_HORIZONTAL) {
  13405 		v1 = (*VP8Io)(unsafe.Pointer((*VP8LDecoder)(unsafe.Pointer(dec)).Fio)).Fcrop_top
  13406 	} else {
  13407 		v1 = (*VP8LDecoder)(unsafe.Pointer(dec)).Flast_row
  13408 	}
  13409 	top_row = v1
  13410 	if (*VP8LDecoder)(unsafe.Pointer(dec)).Flast_row < top_row {
  13411 		v2 = top_row
  13412 	} else {
  13413 		v2 = (*VP8LDecoder)(unsafe.Pointer(dec)).Flast_row
  13414 	}
  13415 	first_row = v2
  13416 	if last_row > first_row {
  13417 		// Special method for paletted alpha data. We only process the cropped area.
  13418 		width = (*VP8Io)(unsafe.Pointer((*VP8LDecoder)(unsafe.Pointer(dec)).Fio)).Fwidth
  13419 		out = (*ALPHDecoder)(unsafe.Pointer(alph_dec)).Foutput + uintptr(width*first_row)
  13420 		in = (*VP8LDecoder)(unsafe.Pointer(dec)).Fpixels + uintptr((*VP8LDecoder)(unsafe.Pointer(dec)).Fwidth*first_row)
  13421 		transform = dec + 280
  13422 		VP8LColorIndexInverseTransformAlpha(tls, transform, first_row, last_row, in, out)
  13423 		AlphaApplyFilter(tls, alph_dec, first_row, last_row, out, width)
  13424 	}
  13425 	v1 = last_row
  13426 	(*VP8LDecoder)(unsafe.Pointer(dec)).Flast_out_row = v1
  13427 	(*VP8LDecoder)(unsafe.Pointer(dec)).Flast_row = v1
  13428 }
  13429 
  13430 //------------------------------------------------------------------------------
  13431 // Helper functions for fast pattern copy (8b and 32b)
  13432 
  13433 // C documentation
  13434 //
  13435 //	// cyclic rotation of pattern word
  13436 func Rotate8b(tls *libc.TLS, V uint32_t) (r uint32_t) {
  13437 	return V&uint32(0xff)<<int32(24) | V>>libc.Int32FromInt32(8)
  13438 }
  13439 
  13440 // C documentation
  13441 //
  13442 //	// copy 1, 2 or 4-bytes pattern
  13443 func CopySmallPattern8b(tls *libc.TLS, src uintptr, dst uintptr, length int32, pattern uint32_t) {
  13444 	var i int32
  13445 	var v1, v2 uintptr
  13446 	_, _, _ = i, v1, v2
  13447 	// align 'dst' to 4-bytes boundary. Adjust the pattern along the way.
  13448 	for uint64(dst)&uint64(3) != 0 {
  13449 		v1 = dst
  13450 		dst = dst + 1
  13451 		v2 = src
  13452 		src = src + 1
  13453 		**(**uint8_t)(__ccgo_up(v1)) = **(**uint8_t)(__ccgo_up(v2))
  13454 		pattern = Rotate8b(tls, pattern)
  13455 		length = length - 1
  13456 	}
  13457 	// Copy the pattern 4 bytes at a time.
  13458 	i = 0
  13459 	for {
  13460 		if !(i < length>>int32(2)) {
  13461 			break
  13462 		}
  13463 		**(**uint32_t)(__ccgo_up(dst + uintptr(i)*4)) = pattern
  13464 		goto _3
  13465 	_3:
  13466 		;
  13467 		i = i + 1
  13468 	}
  13469 	// Finish with left-overs. 'pattern' is still correctly positioned,
  13470 	// so no Rotate8b() call is needed.
  13471 	i = i << int32(2)
  13472 	for {
  13473 		if !(i < length) {
  13474 			break
  13475 		}
  13476 		**(**uint8_t)(__ccgo_up(dst + uintptr(i))) = **(**uint8_t)(__ccgo_up(src + uintptr(i)))
  13477 		goto _4
  13478 	_4:
  13479 		;
  13480 		i = i + 1
  13481 	}
  13482 }
  13483 
  13484 func CopyBlock8b(tls *libc.TLS, dst uintptr, dist int32, length int32) {
  13485 	bp := tls.Alloc(16)
  13486 	defer tls.Free(16)
  13487 	var i int32
  13488 	var src uintptr
  13489 	var _ /* pattern at bp+0 */ uint32_t
  13490 	_, _ = i, src
  13491 	src = dst - uintptr(dist)
  13492 	if length >= int32(8) {
  13493 		**(**uint32_t)(__ccgo_up(bp)) = uint32(0)
  13494 		switch dist {
  13495 		case int32(1):
  13496 			**(**uint32_t)(__ccgo_up(bp)) = uint32(**(**uint8_t)(__ccgo_up(src)))
  13497 			**(**uint32_t)(__ccgo_up(bp)) = uint32(0x01010101) * **(**uint32_t)(__ccgo_up(bp))
  13498 		case int32(2):
  13499 			libc.Xmemcpy(tls, bp, src, uint64(2))
  13500 			**(**uint32_t)(__ccgo_up(bp)) = uint32(0x00010001) * **(**uint32_t)(__ccgo_up(bp))
  13501 		case int32(4):
  13502 			libc.Xmemcpy(tls, bp, src, uint64(4))
  13503 		default:
  13504 			goto Copy
  13505 		}
  13506 		CopySmallPattern8b(tls, src, dst, length, **(**uint32_t)(__ccgo_up(bp)))
  13507 		return
  13508 	}
  13509 	goto Copy
  13510 Copy:
  13511 	;
  13512 	if dist >= length { // no overlap -> use memcpy()
  13513 		libc.Xmemcpy(tls, dst, src, uint64(length)*uint64(1))
  13514 	} else {
  13515 		i = 0
  13516 		for {
  13517 			if !(i < length) {
  13518 				break
  13519 			}
  13520 			**(**uint8_t)(__ccgo_up(dst + uintptr(i))) = **(**uint8_t)(__ccgo_up(src + uintptr(i)))
  13521 			goto _1
  13522 		_1:
  13523 			;
  13524 			i = i + 1
  13525 		}
  13526 	}
  13527 }
  13528 
  13529 // C documentation
  13530 //
  13531 //	// copy pattern of 1 or 2 uint32_t's
  13532 func CopySmallPattern32b(tls *libc.TLS, src uintptr, dst uintptr, length int32, pattern uint64_t) {
  13533 	var i int32
  13534 	var v1, v2 uintptr
  13535 	_, _, _ = i, v1, v2
  13536 	if uint64(dst)&uint64(4) != 0 { // Align 'dst' to 8-bytes boundary.
  13537 		v1 = dst
  13538 		dst += 4
  13539 		v2 = src
  13540 		src += 4
  13541 		**(**uint32_t)(__ccgo_up(v1)) = **(**uint32_t)(__ccgo_up(v2))
  13542 		pattern = pattern>>libc.Int32FromInt32(32) | pattern<<libc.Int32FromInt32(32)
  13543 		length = length - 1
  13544 	}
  13545 	i = 0
  13546 	for {
  13547 		if !(i < length>>int32(1)) {
  13548 			break
  13549 		}
  13550 		**(**uint64_t)(__ccgo_up(dst + uintptr(i)*8)) = pattern // Copy the pattern 8 bytes at a time.
  13551 		goto _3
  13552 	_3:
  13553 		;
  13554 		i = i + 1
  13555 	}
  13556 	if length&int32(1) != 0 { // Finish with left-over.
  13557 		**(**uint32_t)(__ccgo_up(dst + uintptr(i<<int32(1))*4)) = **(**uint32_t)(__ccgo_up(src + uintptr(i<<int32(1))*4))
  13558 	}
  13559 }
  13560 
  13561 func CopyBlock32b(tls *libc.TLS, dst uintptr, dist int32, length int32) {
  13562 	bp := tls.Alloc(16)
  13563 	defer tls.Free(16)
  13564 	var i int32
  13565 	var src uintptr
  13566 	var _ /* pattern at bp+0 */ uint64_t
  13567 	_, _ = i, src
  13568 	src = dst - uintptr(dist)*4
  13569 	if dist <= int32(2) && length >= int32(4) && uint64(dst)&uint64(3) == uint64(0) {
  13570 		if dist == int32(1) {
  13571 			**(**uint64_t)(__ccgo_up(bp)) = uint64(**(**uint32_t)(__ccgo_up(src)))
  13572 			**(**uint64_t)(__ccgo_up(bp)) = **(**uint64_t)(__ccgo_up(bp)) | **(**uint64_t)(__ccgo_up(bp))<<int32(32)
  13573 		} else {
  13574 			libc.Xmemcpy(tls, bp, src, uint64(8))
  13575 		}
  13576 		CopySmallPattern32b(tls, src, dst, length, **(**uint64_t)(__ccgo_up(bp)))
  13577 	} else {
  13578 		if dist >= length { // no overlap
  13579 			libc.Xmemcpy(tls, dst, src, uint64(length)*uint64(4))
  13580 		} else {
  13581 			i = 0
  13582 			for {
  13583 				if !(i < length) {
  13584 					break
  13585 				}
  13586 				**(**uint32_t)(__ccgo_up(dst + uintptr(i)*4)) = **(**uint32_t)(__ccgo_up(src + uintptr(i)*4))
  13587 				goto _1
  13588 			_1:
  13589 				;
  13590 				i = i + 1
  13591 			}
  13592 		}
  13593 	}
  13594 }
  13595 
  13596 //------------------------------------------------------------------------------
  13597 
  13598 func DecodeAlphaData(tls *libc.TLS, dec uintptr, data uintptr, width int32, height int32, last_row int32) (r int32) {
  13599 	var br2, hdr, htree_group, v1 uintptr
  13600 	var code, col, dist, dist_code, dist_symbol, end, last, len_code_limit, length, length_sym, mask, ok, pos, row, v5 int32
  13601 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  13602 	ok = int32(1)
  13603 	row = (*VP8LDecoder)(unsafe.Pointer(dec)).Flast_pixel / width
  13604 	col = (*VP8LDecoder)(unsafe.Pointer(dec)).Flast_pixel % width
  13605 	br2 = dec + 40
  13606 	hdr = dec + 152
  13607 	pos = (*VP8LDecoder)(unsafe.Pointer(dec)).Flast_pixel // current position
  13608 	end = width * height                                  // End of data
  13609 	last = width * last_row                               // Last pixel to decode
  13610 	len_code_limit = libc.Int32FromInt32(NUM_LITERAL_CODES) + libc.Int32FromInt32(NUM_LENGTH_CODES)
  13611 	mask = (*VP8LMetadata)(unsafe.Pointer(hdr)).Fhuffman_mask
  13612 	if pos < last {
  13613 		v1 = GetHtreeGroupForPos(tls, hdr, col, row)
  13614 	} else {
  13615 		v1 = libc.UintptrFromInt32(0)
  13616 	}
  13617 	htree_group = v1
  13618 	for !((*VP8LBitReader)(unsafe.Pointer(br2)).Feos != 0) && pos < last {
  13619 		// Only update when changing tile.
  13620 		if col&mask == 0 {
  13621 			htree_group = GetHtreeGroupForPos(tls, hdr, col, row)
  13622 		}
  13623 		v1 = br2
  13624 		if (*VP8LBitReader)(unsafe.Pointer(v1)).Fbit_pos >= libc.Int32FromInt32(VP8L_WBITS) {
  13625 			VP8LDoFillBitWindow(tls, v1)
  13626 		}
  13627 		code = ReadSymbol(tls, **(**uintptr)(__ccgo_up(htree_group + uintptr(GREEN)*8)), br2)
  13628 		if code < int32(NUM_LITERAL_CODES) { // Literal
  13629 			**(**uint8_t)(__ccgo_up(data + uintptr(pos))) = uint8(code)
  13630 			pos = pos + 1
  13631 			col = col + 1
  13632 			if col >= width {
  13633 				col = 0
  13634 				row = row + 1
  13635 				if row <= last_row && row%int32(NUM_ARGB_CACHE_ROWS) == 0 {
  13636 					ExtractPalettedAlphaRows(tls, dec, row)
  13637 				}
  13638 			}
  13639 		} else {
  13640 			if code < len_code_limit {
  13641 				length_sym = code - int32(NUM_LITERAL_CODES)
  13642 				length = GetCopyLength(tls, length_sym, br2)
  13643 				dist_symbol = ReadSymbol(tls, **(**uintptr)(__ccgo_up(htree_group + uintptr(DIST)*8)), br2)
  13644 				v1 = br2
  13645 				if (*VP8LBitReader)(unsafe.Pointer(v1)).Fbit_pos >= libc.Int32FromInt32(VP8L_WBITS) {
  13646 					VP8LDoFillBitWindow(tls, v1)
  13647 				}
  13648 				dist_code = GetCopyDistance(tls, dist_symbol, br2)
  13649 				dist = PlaneCodeToDistance(tls, width, dist_code)
  13650 				if pos >= dist && end-pos >= length {
  13651 					CopyBlock8b(tls, data+uintptr(pos), dist, length)
  13652 				} else {
  13653 					ok = 0
  13654 					goto End
  13655 				}
  13656 				pos = pos + length
  13657 				col = col + length
  13658 				for col >= width {
  13659 					col = col - width
  13660 					row = row + 1
  13661 					if row <= last_row && row%int32(NUM_ARGB_CACHE_ROWS) == 0 {
  13662 						ExtractPalettedAlphaRows(tls, dec, row)
  13663 					}
  13664 				}
  13665 				if pos < last && col&mask != 0 {
  13666 					htree_group = GetHtreeGroupForPos(tls, hdr, col, row)
  13667 				}
  13668 			} else { // Not reached
  13669 				ok = 0
  13670 				goto End
  13671 			}
  13672 		}
  13673 		v1 = br2
  13674 		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))
  13675 		goto _6
  13676 	_6:
  13677 		(*VP8LBitReader)(unsafe.Pointer(br2)).Feos = v5
  13678 	}
  13679 	// Process the remaining rows corresponding to last row-block.
  13680 	if row > last_row {
  13681 		v5 = last_row
  13682 	} else {
  13683 		v5 = row
  13684 	}
  13685 	ExtractPalettedAlphaRows(tls, dec, v5)
  13686 	goto End
  13687 End:
  13688 	;
  13689 	v1 = br2
  13690 	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))
  13691 	goto _10
  13692 _10:
  13693 	(*VP8LBitReader)(unsafe.Pointer(br2)).Feos = v5
  13694 	if !(ok != 0) || (*VP8LBitReader)(unsafe.Pointer(br2)).Feos != 0 && pos < end {
  13695 		if (*VP8LBitReader)(unsafe.Pointer(br2)).Feos != 0 {
  13696 			v5 = int32(VP8_STATUS_SUSPENDED)
  13697 		} else {
  13698 			v5 = int32(VP8_STATUS_BITSTREAM_ERROR)
  13699 		}
  13700 		return VP8LSetError(tls, dec, v5)
  13701 	}
  13702 	(*VP8LDecoder)(unsafe.Pointer(dec)).Flast_pixel = pos
  13703 	return ok
  13704 }
  13705 
  13706 func SaveState(tls *libc.TLS, dec uintptr, last_pixel int32) {
  13707 	(*VP8LDecoder)(unsafe.Pointer(dec)).Fsaved_br = (*VP8LDecoder)(unsafe.Pointer(dec)).Fbr
  13708 	(*VP8LDecoder)(unsafe.Pointer(dec)).Fsaved_last_pixel = last_pixel
  13709 	if (*VP8LDecoder)(unsafe.Pointer(dec)).Fhdr.Fcolor_cache_size > 0 {
  13710 		VP8LColorCacheCopy(tls, dec+152+8, dec+152+24)
  13711 	}
  13712 }
  13713 
  13714 func RestoreState(tls *libc.TLS, dec uintptr) {
  13715 	(*VP8LDecoder)(unsafe.Pointer(dec)).Fstatus = int32(VP8_STATUS_SUSPENDED)
  13716 	(*VP8LDecoder)(unsafe.Pointer(dec)).Fbr = (*VP8LDecoder)(unsafe.Pointer(dec)).Fsaved_br
  13717 	(*VP8LDecoder)(unsafe.Pointer(dec)).Flast_pixel = (*VP8LDecoder)(unsafe.Pointer(dec)).Fsaved_last_pixel
  13718 	if (*VP8LDecoder)(unsafe.Pointer(dec)).Fhdr.Fcolor_cache_size > 0 {
  13719 		VP8LColorCacheCopy(tls, dec+152+24, dec+152+8)
  13720 	}
  13721 }
  13722 
  13723 func DecodeImageData(tls *libc.TLS, dec uintptr, data uintptr, width int32, height int32, last_row int32, __ccgo_fp_process_func ProcessRowsFunc) (r int32) {
  13724 	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
  13725 	var br2, color_cache, hdr, htree_group, last_cached, src, src_end, src_last, v2, v3 uintptr
  13726 	var v21 uint32_t
  13727 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  13728 	row = (*VP8LDecoder)(unsafe.Pointer(dec)).Flast_pixel / width
  13729 	col = (*VP8LDecoder)(unsafe.Pointer(dec)).Flast_pixel % width
  13730 	br2 = dec + 40
  13731 	hdr = dec + 152
  13732 	src = data + uintptr((*VP8LDecoder)(unsafe.Pointer(dec)).Flast_pixel)*4
  13733 	last_cached = src
  13734 	src_end = data + uintptr(width*height)*4    // End of data
  13735 	src_last = data + uintptr(width*last_row)*4 // Last pixel to decode
  13736 	len_code_limit = libc.Int32FromInt32(NUM_LITERAL_CODES) + libc.Int32FromInt32(NUM_LENGTH_CODES)
  13737 	color_cache_limit = len_code_limit + (*VP8LMetadata)(unsafe.Pointer(hdr)).Fcolor_cache_size
  13738 	if (*VP8LDecoder)(unsafe.Pointer(dec)).Fincremental != 0 {
  13739 		v1 = row
  13740 	} else {
  13741 		v1 = libc.Int32FromInt32(1) << libc.Int32FromInt32(24)
  13742 	}
  13743 	next_sync_row = v1
  13744 	if (*VP8LMetadata)(unsafe.Pointer(hdr)).Fcolor_cache_size > 0 {
  13745 		v2 = hdr + 8
  13746 	} else {
  13747 		v2 = libc.UintptrFromInt32(0)
  13748 	}
  13749 	color_cache = v2
  13750 	mask = (*VP8LMetadata)(unsafe.Pointer(hdr)).Fhuffman_mask
  13751 	if src < src_last {
  13752 		v3 = GetHtreeGroupForPos(tls, hdr, col, row)
  13753 	} else {
  13754 		v3 = libc.UintptrFromInt32(0)
  13755 	}
  13756 	htree_group = v3
  13757 _5:
  13758 	;
  13759 	if !(src < src_last) {
  13760 		goto _4
  13761 	}
  13762 	if row >= next_sync_row {
  13763 		SaveState(tls, dec, int32((int64(src)-int64(data))/4))
  13764 		next_sync_row = row + int32(SYNC_EVERY_N_ROWS)
  13765 	}
  13766 	// Only update when changing tile. Note we could use this test:
  13767 	// if "((((prev_col ^ col) | prev_row ^ row)) > mask)" -> tile changed
  13768 	// but that's actually slower and needs storing the previous col/row.
  13769 	if col&mask == 0 {
  13770 		htree_group = GetHtreeGroupForPos(tls, hdr, col, row)
  13771 	}
  13772 	if (*HTreeGroup)(unsafe.Pointer(htree_group)).Fis_trivial_code != 0 {
  13773 		**(**uint32_t)(__ccgo_up(src)) = (*HTreeGroup)(unsafe.Pointer(htree_group)).Fliteral_arb
  13774 		goto AdvanceByOne
  13775 	}
  13776 	v2 = br2
  13777 	if (*VP8LBitReader)(unsafe.Pointer(v2)).Fbit_pos >= libc.Int32FromInt32(VP8L_WBITS) {
  13778 		VP8LDoFillBitWindow(tls, v2)
  13779 	}
  13780 	if (*HTreeGroup)(unsafe.Pointer(htree_group)).Fuse_packed_table != 0 {
  13781 		code = ReadPackedSymbols(tls, htree_group, br2, src)
  13782 		v2 = br2
  13783 		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))
  13784 		goto _9
  13785 	_9:
  13786 		if v1 != 0 {
  13787 			goto _4
  13788 		}
  13789 		if code == PACKED_NON_LITERAL_CODE {
  13790 			goto AdvanceByOne
  13791 		}
  13792 	} else {
  13793 		code = ReadSymbol(tls, **(**uintptr)(__ccgo_up(htree_group + uintptr(GREEN)*8)), br2)
  13794 	}
  13795 	v2 = br2
  13796 	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))
  13797 	goto _12
  13798 _12:
  13799 	if v1 != 0 {
  13800 		goto _4
  13801 	}
  13802 	if !(code < int32(NUM_LITERAL_CODES)) {
  13803 		goto _13
  13804 	} // Literal
  13805 	if (*HTreeGroup)(unsafe.Pointer(htree_group)).Fis_trivial_literal != 0 {
  13806 		**(**uint32_t)(__ccgo_up(src)) = (*HTreeGroup)(unsafe.Pointer(htree_group)).Fliteral_arb | uint32(code<<libc.Int32FromInt32(8))
  13807 	} else {
  13808 		red = ReadSymbol(tls, **(**uintptr)(__ccgo_up(htree_group + uintptr(RED)*8)), br2)
  13809 		v2 = br2
  13810 		if (*VP8LBitReader)(unsafe.Pointer(v2)).Fbit_pos >= libc.Int32FromInt32(VP8L_WBITS) {
  13811 			VP8LDoFillBitWindow(tls, v2)
  13812 		}
  13813 		blue = ReadSymbol(tls, **(**uintptr)(__ccgo_up(htree_group + uintptr(BLUE)*8)), br2)
  13814 		alpha = ReadSymbol(tls, **(**uintptr)(__ccgo_up(htree_group + uintptr(ALPHA)*8)), br2)
  13815 		v2 = br2
  13816 		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))
  13817 		goto _18
  13818 	_18:
  13819 		if v1 != 0 {
  13820 			goto _4
  13821 		}
  13822 		**(**uint32_t)(__ccgo_up(src)) = uint32(alpha)<<libc.Int32FromInt32(24) | uint32(red<<libc.Int32FromInt32(16)) | uint32(code<<libc.Int32FromInt32(8)) | uint32(blue)
  13823 	}
  13824 	goto AdvanceByOne
  13825 AdvanceByOne:
  13826 	;
  13827 	src += 4
  13828 	col = col + 1
  13829 	if col >= width {
  13830 		col = 0
  13831 		row = row + 1
  13832 		if __ccgo_fp_process_func != libc.UintptrFromInt32(0) {
  13833 			if row <= last_row && row%int32(NUM_ARGB_CACHE_ROWS) == 0 {
  13834 				(*(*func(*libc.TLS, uintptr, int32))(unsafe.Pointer(&struct{ uintptr }{__ccgo_fp_process_func})))(tls, dec, row)
  13835 			}
  13836 		}
  13837 		if color_cache != libc.UintptrFromInt32(0) {
  13838 			for last_cached < src {
  13839 				v2 = last_cached
  13840 				last_cached += 4
  13841 				v3 = color_cache
  13842 				v21 = **(**uint32_t)(__ccgo_up(v2))
  13843 				v1 = int32(v21 * kHashMul8 >> (*VP8LColorCache)(unsafe.Pointer(v3)).Fhash_shift)
  13844 				goto _23
  13845 			_23:
  13846 				key1 = v1
  13847 				**(**uint32_t)(__ccgo_up((*VP8LColorCache)(unsafe.Pointer(v3)).Fcolors + uintptr(key1)*4)) = v21
  13848 			}
  13849 		}
  13850 	}
  13851 	goto _14
  13852 _13:
  13853 	;
  13854 	if code < len_code_limit {
  13855 		length_sym = code - int32(NUM_LITERAL_CODES)
  13856 		length = GetCopyLength(tls, length_sym, br2)
  13857 		dist_symbol = ReadSymbol(tls, **(**uintptr)(__ccgo_up(htree_group + uintptr(DIST)*8)), br2)
  13858 		v2 = br2
  13859 		if (*VP8LBitReader)(unsafe.Pointer(v2)).Fbit_pos >= libc.Int32FromInt32(VP8L_WBITS) {
  13860 			VP8LDoFillBitWindow(tls, v2)
  13861 		}
  13862 		dist_code = GetCopyDistance(tls, dist_symbol, br2)
  13863 		dist = PlaneCodeToDistance(tls, width, dist_code)
  13864 		v2 = br2
  13865 		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))
  13866 		goto _27
  13867 	_27:
  13868 		if v1 != 0 {
  13869 			goto _4
  13870 		}
  13871 		if (int64(src)-int64(data))/4 < int64(dist) || (int64(src_end)-int64(src))/4 < int64(length) {
  13872 			goto Error
  13873 		} else {
  13874 			CopyBlock32b(tls, src, dist, length)
  13875 		}
  13876 		src = src + uintptr(length)*4
  13877 		col = col + length
  13878 		for col >= width {
  13879 			col = col - width
  13880 			row = row + 1
  13881 			if __ccgo_fp_process_func != libc.UintptrFromInt32(0) {
  13882 				if row <= last_row && row%int32(NUM_ARGB_CACHE_ROWS) == 0 {
  13883 					(*(*func(*libc.TLS, uintptr, int32))(unsafe.Pointer(&struct{ uintptr }{__ccgo_fp_process_func})))(tls, dec, row)
  13884 				}
  13885 			}
  13886 		}
  13887 		// Because of the check done above (before 'src' was incremented by
  13888 		// 'length'), the following holds true.
  13889 		if col&mask != 0 {
  13890 			htree_group = GetHtreeGroupForPos(tls, hdr, col, row)
  13891 		}
  13892 		if color_cache != libc.UintptrFromInt32(0) {
  13893 			for last_cached < src {
  13894 				v2 = last_cached
  13895 				last_cached += 4
  13896 				v3 = color_cache
  13897 				v21 = **(**uint32_t)(__ccgo_up(v2))
  13898 				v1 = int32(v21 * kHashMul8 >> (*VP8LColorCache)(unsafe.Pointer(v3)).Fhash_shift)
  13899 				goto _32
  13900 			_32:
  13901 				key1 = v1
  13902 				**(**uint32_t)(__ccgo_up((*VP8LColorCache)(unsafe.Pointer(v3)).Fcolors + uintptr(key1)*4)) = v21
  13903 			}
  13904 		}
  13905 	} else {
  13906 		if code < color_cache_limit { // Color cache
  13907 			key2 = code - len_code_limit
  13908 			for last_cached < src {
  13909 				v2 = last_cached
  13910 				last_cached += 4
  13911 				v3 = color_cache
  13912 				v21 = **(**uint32_t)(__ccgo_up(v2))
  13913 				v1 = int32(v21 * kHashMul8 >> (*VP8LColorCache)(unsafe.Pointer(v3)).Fhash_shift)
  13914 				goto _37
  13915 			_37:
  13916 				key1 = v1
  13917 				**(**uint32_t)(__ccgo_up((*VP8LColorCache)(unsafe.Pointer(v3)).Fcolors + uintptr(key1)*4)) = v21
  13918 			}
  13919 			v21 = **(**uint32_t)(__ccgo_up((*VP8LColorCache)(unsafe.Pointer(color_cache)).Fcolors + uintptr(uint32(key2))*4))
  13920 			goto _39
  13921 		_39:
  13922 			**(**uint32_t)(__ccgo_up(src)) = v21
  13923 			goto AdvanceByOne
  13924 		} else { // Not reached
  13925 			goto Error
  13926 		}
  13927 	}
  13928 _14:
  13929 	;
  13930 	goto _5
  13931 _4:
  13932 	;
  13933 	v2 = br2
  13934 	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))
  13935 	goto _42
  13936 _42:
  13937 	(*VP8LBitReader)(unsafe.Pointer(br2)).Feos = v1
  13938 	// In incremental decoding:
  13939 	// br->eos && src < src_last: if 'br' reached the end of the buffer and
  13940 	// 'src_last' has not been reached yet, there is not enough data. 'dec' has to
  13941 	// be reset until there is more data.
  13942 	// !br->eos && src < src_last: this cannot happen as either the buffer is
  13943 	// fully read, either enough has been read to reach 'src_last'.
  13944 	// src >= src_last: 'src_last' is reached, all is fine. 'src' can actually go
  13945 	// beyond 'src_last' in case the image is cropped and an LZ77 goes further.
  13946 	// The buffer might have been enough or there is some left. 'br->eos' does
  13947 	// not matter.
  13948 	if (*VP8LDecoder)(unsafe.Pointer(dec)).Fincremental != 0 && (*VP8LBitReader)(unsafe.Pointer(br2)).Feos != 0 && src < src_last {
  13949 		RestoreState(tls, dec)
  13950 	} else {
  13951 		if (*VP8LDecoder)(unsafe.Pointer(dec)).Fincremental != 0 && src >= src_last || !((*VP8LBitReader)(unsafe.Pointer(br2)).Feos != 0) {
  13952 			// Process the remaining rows corresponding to last row-block.
  13953 			if __ccgo_fp_process_func != libc.UintptrFromInt32(0) {
  13954 				if row > last_row {
  13955 					v1 = last_row
  13956 				} else {
  13957 					v1 = row
  13958 				}
  13959 				(*(*func(*libc.TLS, uintptr, int32))(unsafe.Pointer(&struct{ uintptr }{__ccgo_fp_process_func})))(tls, dec, v1)
  13960 			}
  13961 			(*VP8LDecoder)(unsafe.Pointer(dec)).Fstatus = int32(VP8_STATUS_OK)
  13962 			(*VP8LDecoder)(unsafe.Pointer(dec)).Flast_pixel = int32((int64(src) - int64(data)) / 4) // end-of-scan marker
  13963 		} else {
  13964 			// if not incremental, and we are past the end of buffer (eos=1), then this
  13965 			// is a real bitstream error.
  13966 			goto Error
  13967 		}
  13968 	}
  13969 	return int32(1)
  13970 	goto Error
  13971 Error:
  13972 	;
  13973 	return VP8LSetError(tls, dec, int32(VP8_STATUS_BITSTREAM_ERROR))
  13974 	return r
  13975 }
  13976 
  13977 // -----------------------------------------------------------------------------
  13978 // VP8LTransform
  13979 
  13980 func ClearTransform(tls *libc.TLS, transform uintptr) {
  13981 	WebPSafeFree(tls, (*VP8LTransform)(unsafe.Pointer(transform)).Fdata)
  13982 	(*VP8LTransform)(unsafe.Pointer(transform)).Fdata = libc.UintptrFromInt32(0)
  13983 }
  13984 
  13985 // C documentation
  13986 //
  13987 //	// For security reason, we need to remap the color map to span
  13988 //	// the total possible bundled values, and not just the num_colors.
  13989 func ExpandColorMap(tls *libc.TLS, num_colors int32, transform uintptr) (r int32) {
  13990 	var data, new_color_map, new_data uintptr
  13991 	var final_num_colors, i int32
  13992 	_, _, _, _, _ = data, final_num_colors, i, new_color_map, new_data
  13993 	final_num_colors = int32(1) << (int32(8) >> (*VP8LTransform)(unsafe.Pointer(transform)).Fbits)
  13994 	new_color_map = WebPSafeMalloc(tls, uint64(final_num_colors), uint64(4))
  13995 	if new_color_map == libc.UintptrFromInt32(0) {
  13996 		return 0
  13997 	} else {
  13998 		data = (*VP8LTransform)(unsafe.Pointer(transform)).Fdata
  13999 		new_data = new_color_map
  14000 		**(**uint32_t)(__ccgo_up(new_color_map)) = **(**uint32_t)(__ccgo_up((*VP8LTransform)(unsafe.Pointer(transform)).Fdata))
  14001 		i = int32(4)
  14002 		for {
  14003 			if !(i < int32(4)*num_colors) {
  14004 				break
  14005 			}
  14006 			// Equivalent to VP8LAddPixels(), on a byte-basis.
  14007 			**(**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))
  14008 			goto _1
  14009 		_1:
  14010 			;
  14011 			i = i + 1
  14012 		}
  14013 		for {
  14014 			if !(i < int32(4)*final_num_colors) {
  14015 				break
  14016 			}
  14017 			**(**uint8_t)(__ccgo_up(new_data + uintptr(i))) = uint8(0) // black tail.
  14018 			goto _2
  14019 		_2:
  14020 			;
  14021 			i = i + 1
  14022 		}
  14023 		WebPSafeFree(tls, (*VP8LTransform)(unsafe.Pointer(transform)).Fdata)
  14024 		(*VP8LTransform)(unsafe.Pointer(transform)).Fdata = new_color_map
  14025 	}
  14026 	return int32(1)
  14027 }
  14028 
  14029 func ReadTransform(tls *libc.TLS, xsize uintptr, ysize uintptr, dec uintptr) (r int32) {
  14030 	var bits, num_colors, ok, v7, v8, v9 int32
  14031 	var br, transform uintptr
  14032 	var type1 VP8LImageTransformType
  14033 	var v1, v2, v4, v5 uint32_t
  14034 	_, _, _, _, _, _, _, _, _, _, _, _, _ = bits, br, num_colors, ok, transform, type1, v1, v2, v4, v5, v7, v8, v9
  14035 	ok = int32(1)
  14036 	br = dec + 40
  14037 	transform = dec + 280 + uintptr((*VP8LDecoder)(unsafe.Pointer(dec)).Fnext_transform)*24
  14038 	type1 = int32(VP8LReadBits(tls, br, int32(2)))
  14039 	// Each transform type can only be present once in the stream.
  14040 	if (*VP8LDecoder)(unsafe.Pointer(dec)).Ftransforms_seen&(uint32(1)<<type1) != 0 {
  14041 		return 0 // Already there, let's not accept the second same transform.
  14042 	}
  14043 	**(**uint32_t)(__ccgo_up(dec + 376)) |= uint32(1) << type1
  14044 	(*VP8LTransform)(unsafe.Pointer(transform)).Ftype1 = type1
  14045 	(*VP8LTransform)(unsafe.Pointer(transform)).Fxsize = **(**int32)(__ccgo_up(xsize))
  14046 	(*VP8LTransform)(unsafe.Pointer(transform)).Fysize = **(**int32)(__ccgo_up(ysize))
  14047 	(*VP8LTransform)(unsafe.Pointer(transform)).Fdata = libc.UintptrFromInt32(0)
  14048 	(*VP8LDecoder)(unsafe.Pointer(dec)).Fnext_transform = (*VP8LDecoder)(unsafe.Pointer(dec)).Fnext_transform + 1
  14049 	switch type1 {
  14050 	case int32(PREDICTOR_TRANSFORM):
  14051 		fallthrough
  14052 	case int32(CROSS_COLOR_TRANSFORM):
  14053 		(*VP8LTransform)(unsafe.Pointer(transform)).Fbits = int32(uint32(MIN_TRANSFORM_BITS) + VP8LReadBits(tls, br, int32(NUM_TRANSFORM_BITS)))
  14054 		v1 = uint32((*VP8LTransform)(unsafe.Pointer(transform)).Fbits)
  14055 		v2 = (uint32((*VP8LTransform)(unsafe.Pointer(transform)).Fxsize) + uint32(libc.Int32FromInt32(1)<<v1) - uint32(1)) >> v1
  14056 		goto _3
  14057 	_3:
  14058 		v4 = uint32((*VP8LTransform)(unsafe.Pointer(transform)).Fbits)
  14059 		v5 = (uint32((*VP8LTransform)(unsafe.Pointer(transform)).Fysize) + uint32(libc.Int32FromInt32(1)<<v4) - uint32(1)) >> v4
  14060 		goto _6
  14061 	_6:
  14062 		ok = DecodeImageStream(tls, int32(v2), int32(v5), 0, dec, transform+16)
  14063 	case int32(COLOR_INDEXING_TRANSFORM):
  14064 		num_colors = int32(VP8LReadBits(tls, br, int32(8)) + uint32(1))
  14065 		if num_colors > int32(16) {
  14066 			v7 = 0
  14067 		} else {
  14068 			if num_colors > int32(4) {
  14069 				v8 = int32(1)
  14070 			} else {
  14071 				if num_colors > int32(2) {
  14072 					v9 = int32(2)
  14073 				} else {
  14074 					v9 = int32(3)
  14075 				}
  14076 				v8 = v9
  14077 			}
  14078 			v7 = v8
  14079 		}
  14080 		bits = v7
  14081 		v1 = uint32(bits)
  14082 		v2 = (uint32((*VP8LTransform)(unsafe.Pointer(transform)).Fxsize) + uint32(libc.Int32FromInt32(1)<<v1) - uint32(1)) >> v1
  14083 		goto _12
  14084 	_12:
  14085 		**(**int32)(__ccgo_up(xsize)) = int32(v2)
  14086 		(*VP8LTransform)(unsafe.Pointer(transform)).Fbits = bits
  14087 		ok = DecodeImageStream(tls, num_colors, int32(1), 0, dec, transform+16)
  14088 		if ok != 0 && !(ExpandColorMap(tls, num_colors, transform) != 0) {
  14089 			return VP8LSetError(tls, dec, int32(VP8_STATUS_OUT_OF_MEMORY))
  14090 		}
  14091 	case int32(SUBTRACT_GREEN_TRANSFORM):
  14092 	default:
  14093 		// can't happen
  14094 		break
  14095 	}
  14096 	return ok
  14097 }
  14098 
  14099 // -----------------------------------------------------------------------------
  14100 // VP8LMetadata
  14101 
  14102 func InitMetadata(tls *libc.TLS, hdr uintptr) {
  14103 	libc.Xmemset(tls, hdr, 0, uint64(120))
  14104 }
  14105 
  14106 func ClearMetadata(tls *libc.TLS, hdr uintptr) {
  14107 	WebPSafeFree(tls, (*VP8LMetadata)(unsafe.Pointer(hdr)).Fhuffman_image)
  14108 	VP8LHuffmanTablesDeallocate(tls, hdr+80)
  14109 	VP8LHtreeGroupsFree(tls, (*VP8LMetadata)(unsafe.Pointer(hdr)).Fhtree_groups)
  14110 	VP8LColorCacheClear(tls, hdr+8)
  14111 	VP8LColorCacheClear(tls, hdr+24)
  14112 	InitMetadata(tls, hdr)
  14113 }
  14114 
  14115 // -----------------------------------------------------------------------------
  14116 // VP8LDecoder
  14117 
  14118 func VP8LNew(tls *libc.TLS) (r uintptr) {
  14119 	var dec uintptr
  14120 	_ = dec
  14121 	dec = WebPSafeCalloc(tls, uint64(1), uint64(400))
  14122 	if dec == libc.UintptrFromInt32(0) {
  14123 		return libc.UintptrFromInt32(0)
  14124 	}
  14125 	(*VP8LDecoder)(unsafe.Pointer(dec)).Fstatus = int32(VP8_STATUS_OK)
  14126 	(*VP8LDecoder)(unsafe.Pointer(dec)).Fstate = int32(READ_DIM)
  14127 	VP8LDspInit(tls) // Init critical function pointers.
  14128 	return dec
  14129 }
  14130 
  14131 // C documentation
  14132 //
  14133 //	// Resets the decoder in its initial state, reclaiming memory.
  14134 //	// Preserves the dec->status value.
  14135 func VP8LClear(tls *libc.TLS, dec uintptr) {
  14136 	var i int32
  14137 	_ = i
  14138 	if dec == libc.UintptrFromInt32(0) {
  14139 		return
  14140 	}
  14141 	ClearMetadata(tls, dec+152)
  14142 	WebPSafeFree(tls, (*VP8LDecoder)(unsafe.Pointer(dec)).Fpixels)
  14143 	(*VP8LDecoder)(unsafe.Pointer(dec)).Fpixels = libc.UintptrFromInt32(0)
  14144 	i = 0
  14145 	for {
  14146 		if !(i < (*VP8LDecoder)(unsafe.Pointer(dec)).Fnext_transform) {
  14147 			break
  14148 		}
  14149 		ClearTransform(tls, dec+280+uintptr(i)*24)
  14150 		goto _1
  14151 	_1:
  14152 		;
  14153 		i = i + 1
  14154 	}
  14155 	(*VP8LDecoder)(unsafe.Pointer(dec)).Fnext_transform = 0
  14156 	(*VP8LDecoder)(unsafe.Pointer(dec)).Ftransforms_seen = uint32(0)
  14157 	WebPSafeFree(tls, (*VP8LDecoder)(unsafe.Pointer(dec)).Frescaler_memory)
  14158 	(*VP8LDecoder)(unsafe.Pointer(dec)).Frescaler_memory = libc.UintptrFromInt32(0)
  14159 	(*VP8LDecoder)(unsafe.Pointer(dec)).Foutput = libc.UintptrFromInt32(0) // leave no trace behind
  14160 }
  14161 
  14162 func VP8LDelete(tls *libc.TLS, dec uintptr) {
  14163 	if dec != libc.UintptrFromInt32(0) {
  14164 		VP8LClear(tls, dec)
  14165 		WebPSafeFree(tls, dec)
  14166 	}
  14167 }
  14168 
  14169 func UpdateDecoder(tls *libc.TLS, dec uintptr, width int32, height int32) {
  14170 	var hdr uintptr
  14171 	var num_bits, v4 int32
  14172 	var v1, v2 uint32_t
  14173 	_, _, _, _, _ = hdr, num_bits, v1, v2, v4
  14174 	hdr = dec + 152
  14175 	num_bits = (*VP8LMetadata)(unsafe.Pointer(hdr)).Fhuffman_subsample_bits
  14176 	(*VP8LDecoder)(unsafe.Pointer(dec)).Fwidth = width
  14177 	(*VP8LDecoder)(unsafe.Pointer(dec)).Fheight = height
  14178 	v1 = uint32(num_bits)
  14179 	v2 = (uint32(width) + uint32(libc.Int32FromInt32(1)<<v1) - uint32(1)) >> v1
  14180 	goto _3
  14181 _3:
  14182 	(*VP8LMetadata)(unsafe.Pointer(hdr)).Fhuffman_xsize = int32(v2)
  14183 	if num_bits == 0 {
  14184 		v4 = ^libc.Int32FromInt32(0)
  14185 	} else {
  14186 		v4 = int32(1)<<num_bits - int32(1)
  14187 	}
  14188 	(*VP8LMetadata)(unsafe.Pointer(hdr)).Fhuffman_mask = v4
  14189 }
  14190 
  14191 func DecodeImageStream(tls *libc.TLS, xsize int32, ysize int32, is_level0 int32, dec uintptr, decoded_data uintptr) (r int32) {
  14192 	bp := tls.Alloc(16)
  14193 	defer tls.Free(16)
  14194 	var br, data, hdr uintptr
  14195 	var color_cache_bits, ok int32
  14196 	var total_size uint64_t
  14197 	var _ /* transform_xsize at bp+0 */ int32
  14198 	var _ /* transform_ysize at bp+4 */ int32
  14199 	_, _, _, _, _, _ = br, color_cache_bits, data, hdr, ok, total_size
  14200 	ok = int32(1)
  14201 	**(**int32)(__ccgo_up(bp)) = xsize
  14202 	**(**int32)(__ccgo_up(bp + 4)) = ysize
  14203 	br = dec + 40
  14204 	hdr = dec + 152
  14205 	data = libc.UintptrFromInt32(0)
  14206 	color_cache_bits = 0
  14207 	// Read the transforms (may recurse).
  14208 	if is_level0 != 0 {
  14209 		for ok != 0 && VP8LReadBits(tls, br, int32(1)) != 0 {
  14210 			ok = ReadTransform(tls, bp, bp+4, dec)
  14211 		}
  14212 	}
  14213 	// Color cache
  14214 	if ok != 0 && VP8LReadBits(tls, br, int32(1)) != 0 {
  14215 		color_cache_bits = int32(VP8LReadBits(tls, br, int32(4)))
  14216 		ok = libc.BoolInt32(color_cache_bits >= int32(1) && color_cache_bits <= int32(MAX_CACHE_BITS))
  14217 		if !(ok != 0) {
  14218 			VP8LSetError(tls, dec, int32(VP8_STATUS_BITSTREAM_ERROR))
  14219 			goto End
  14220 		}
  14221 	}
  14222 	// Read the Huffman codes (may recurse).
  14223 	ok = libc.BoolInt32(ok != 0 && ReadHuffmanCodes(tls, dec, **(**int32)(__ccgo_up(bp)), **(**int32)(__ccgo_up(bp + 4)), color_cache_bits, is_level0) != 0)
  14224 	if !(ok != 0) {
  14225 		VP8LSetError(tls, dec, int32(VP8_STATUS_BITSTREAM_ERROR))
  14226 		goto End
  14227 	}
  14228 	// Finish setting up the color-cache
  14229 	if color_cache_bits > 0 {
  14230 		(*VP8LMetadata)(unsafe.Pointer(hdr)).Fcolor_cache_size = int32(1) << color_cache_bits
  14231 		if !(VP8LColorCacheInit(tls, hdr+8, color_cache_bits) != 0) {
  14232 			ok = VP8LSetError(tls, dec, int32(VP8_STATUS_OUT_OF_MEMORY))
  14233 			goto End
  14234 		}
  14235 	} else {
  14236 		(*VP8LMetadata)(unsafe.Pointer(hdr)).Fcolor_cache_size = 0
  14237 	}
  14238 	UpdateDecoder(tls, dec, **(**int32)(__ccgo_up(bp)), **(**int32)(__ccgo_up(bp + 4)))
  14239 	if is_level0 != 0 { // level 0 complete
  14240 		(*VP8LDecoder)(unsafe.Pointer(dec)).Fstate = int32(READ_HDR)
  14241 		goto End
  14242 	}
  14243 	total_size = uint64(**(**int32)(__ccgo_up(bp))) * uint64(**(**int32)(__ccgo_up(bp + 4)))
  14244 	data = WebPSafeMalloc(tls, total_size, uint64(4))
  14245 	if data == libc.UintptrFromInt32(0) {
  14246 		ok = VP8LSetError(tls, dec, int32(VP8_STATUS_OUT_OF_MEMORY))
  14247 		goto End
  14248 	}
  14249 	// Use the Huffman trees to decode the LZ77 encoded data.
  14250 	ok = DecodeImageData(tls, dec, data, **(**int32)(__ccgo_up(bp)), **(**int32)(__ccgo_up(bp + 4)), **(**int32)(__ccgo_up(bp + 4)), libc.UintptrFromInt32(0))
  14251 	ok = libc.BoolInt32(ok != 0 && !((*VP8LBitReader)(unsafe.Pointer(br)).Feos != 0))
  14252 	goto End
  14253 End:
  14254 	;
  14255 	if !(ok != 0) {
  14256 		WebPSafeFree(tls, data)
  14257 		ClearMetadata(tls, hdr)
  14258 	} else {
  14259 		if decoded_data != libc.UintptrFromInt32(0) {
  14260 			**(**uintptr)(__ccgo_up(decoded_data)) = data
  14261 		} else {
  14262 			// We allocate image data in this function only for transforms. At level 0
  14263 			// (that is: not the transforms), we shouldn't have allocated anything.
  14264 		}
  14265 		(*VP8LDecoder)(unsafe.Pointer(dec)).Flast_pixel = 0 // Reset for future DECODE_DATA_FUNC() calls.
  14266 		if !(is_level0 != 0) {
  14267 			ClearMetadata(tls, hdr)
  14268 		} // Clean up temporary data behind.
  14269 	}
  14270 	return ok
  14271 }
  14272 
  14273 // C documentation
  14274 //
  14275 //	//------------------------------------------------------------------------------
  14276 //	// Allocate internal buffers dec->pixels and dec->argb_cache.
  14277 func AllocateInternalBuffers32b(tls *libc.TLS, dec uintptr, final_width int32) (r int32) {
  14278 	var cache_pixels, cache_top_pixels, num_pixels, total_num_pixels uint64_t
  14279 	_, _, _, _ = cache_pixels, cache_top_pixels, num_pixels, total_num_pixels
  14280 	num_pixels = uint64((*VP8LDecoder)(unsafe.Pointer(dec)).Fwidth) * uint64((*VP8LDecoder)(unsafe.Pointer(dec)).Fheight)
  14281 	// Scratch buffer corresponding to top-prediction row for transforming the
  14282 	// first row in the row-blocks. Not needed for paletted alpha.
  14283 	cache_top_pixels = uint64(uint16(final_width))
  14284 	// Scratch buffer for temporary BGRA storage. Not needed for paletted alpha.
  14285 	cache_pixels = uint64(final_width) * uint64(NUM_ARGB_CACHE_ROWS)
  14286 	total_num_pixels = num_pixels + cache_top_pixels + cache_pixels
  14287 	(*VP8LDecoder)(unsafe.Pointer(dec)).Fpixels = WebPSafeMalloc(tls, total_num_pixels, uint64(4))
  14288 	if (*VP8LDecoder)(unsafe.Pointer(dec)).Fpixels == libc.UintptrFromInt32(0) {
  14289 		(*VP8LDecoder)(unsafe.Pointer(dec)).Fargb_cache = libc.UintptrFromInt32(0) // for soundness
  14290 		return VP8LSetError(tls, dec, int32(VP8_STATUS_OUT_OF_MEMORY))
  14291 	}
  14292 	(*VP8LDecoder)(unsafe.Pointer(dec)).Fargb_cache = (*VP8LDecoder)(unsafe.Pointer(dec)).Fpixels + uintptr(num_pixels)*4 + uintptr(cache_top_pixels)*4
  14293 	return int32(1)
  14294 }
  14295 
  14296 func AllocateInternalBuffers8b(tls *libc.TLS, dec uintptr) (r int32) {
  14297 	var total_num_pixels uint64_t
  14298 	_ = total_num_pixels
  14299 	total_num_pixels = uint64((*VP8LDecoder)(unsafe.Pointer(dec)).Fwidth) * uint64((*VP8LDecoder)(unsafe.Pointer(dec)).Fheight)
  14300 	(*VP8LDecoder)(unsafe.Pointer(dec)).Fargb_cache = libc.UintptrFromInt32(0) // for soundness
  14301 	(*VP8LDecoder)(unsafe.Pointer(dec)).Fpixels = WebPSafeMalloc(tls, total_num_pixels, uint64(1))
  14302 	if (*VP8LDecoder)(unsafe.Pointer(dec)).Fpixels == libc.UintptrFromInt32(0) {
  14303 		return VP8LSetError(tls, dec, int32(VP8_STATUS_OUT_OF_MEMORY))
  14304 	}
  14305 	return int32(1)
  14306 }
  14307 
  14308 //------------------------------------------------------------------------------
  14309 
  14310 // C documentation
  14311 //
  14312 //	// Special row-processing that only stores the alpha data.
  14313 func ExtractAlphaRows(tls *libc.TLS, dec uintptr, last_row int32) {
  14314 	var alph_dec, dst, in, output, src uintptr
  14315 	var cache_pixs, cur_row, num_rows, num_rows_to_process, width, v1 int32
  14316 	_, _, _, _, _, _, _, _, _, _, _ = alph_dec, cache_pixs, cur_row, dst, in, num_rows, num_rows_to_process, output, src, width, v1
  14317 	cur_row = (*VP8LDecoder)(unsafe.Pointer(dec)).Flast_row
  14318 	num_rows = last_row - cur_row
  14319 	in = (*VP8LDecoder)(unsafe.Pointer(dec)).Fpixels + uintptr((*VP8LDecoder)(unsafe.Pointer(dec)).Fwidth*cur_row)*4
  14320 	for num_rows > 0 {
  14321 		if num_rows > int32(NUM_ARGB_CACHE_ROWS) {
  14322 			v1 = int32(NUM_ARGB_CACHE_ROWS)
  14323 		} else {
  14324 			v1 = num_rows
  14325 		}
  14326 		num_rows_to_process = v1
  14327 		// Extract alpha (which is stored in the green plane).
  14328 		alph_dec = (*VP8Io)(unsafe.Pointer((*VP8LDecoder)(unsafe.Pointer(dec)).Fio)).Fopaque
  14329 		output = (*ALPHDecoder)(unsafe.Pointer(alph_dec)).Foutput
  14330 		width = (*VP8Io)(unsafe.Pointer((*VP8LDecoder)(unsafe.Pointer(dec)).Fio)).Fwidth // the final width (!= dec->width)
  14331 		cache_pixs = width * num_rows_to_process
  14332 		dst = output + uintptr(width*cur_row)
  14333 		src = (*VP8LDecoder)(unsafe.Pointer(dec)).Fargb_cache
  14334 		ApplyInverseTransforms(tls, dec, cur_row, num_rows_to_process, in)
  14335 		(*(*func(*libc.TLS, uintptr, uintptr, int32))(unsafe.Pointer(&struct{ uintptr }{WebPExtractGreen})))(tls, src, dst, cache_pixs)
  14336 		AlphaApplyFilter(tls, alph_dec, cur_row, cur_row+num_rows_to_process, dst, width)
  14337 		num_rows = num_rows - num_rows_to_process
  14338 		in = in + uintptr(num_rows_to_process*(*VP8LDecoder)(unsafe.Pointer(dec)).Fwidth)*4
  14339 		cur_row = cur_row + num_rows_to_process
  14340 	}
  14341 	v1 = last_row
  14342 	(*VP8LDecoder)(unsafe.Pointer(dec)).Flast_out_row = v1
  14343 	(*VP8LDecoder)(unsafe.Pointer(dec)).Flast_row = v1
  14344 }
  14345 
  14346 func VP8LDecodeAlphaHeader(tls *libc.TLS, alph_dec uintptr, data uintptr, data_size size_t) (r int32) {
  14347 	var dec uintptr
  14348 	var ok int32
  14349 	_, _ = dec, ok
  14350 	ok = 0
  14351 	dec = VP8LNew(tls)
  14352 	if dec == libc.UintptrFromInt32(0) {
  14353 		return 0
  14354 	}
  14355 	(*VP8LDecoder)(unsafe.Pointer(dec)).Fwidth = (*ALPHDecoder)(unsafe.Pointer(alph_dec)).Fwidth
  14356 	(*VP8LDecoder)(unsafe.Pointer(dec)).Fheight = (*ALPHDecoder)(unsafe.Pointer(alph_dec)).Fheight
  14357 	(*VP8LDecoder)(unsafe.Pointer(dec)).Fio = alph_dec + 32
  14358 	(*VP8Io)(unsafe.Pointer((*VP8LDecoder)(unsafe.Pointer(dec)).Fio)).Fopaque = alph_dec
  14359 	(*VP8Io)(unsafe.Pointer((*VP8LDecoder)(unsafe.Pointer(dec)).Fio)).Fwidth = (*ALPHDecoder)(unsafe.Pointer(alph_dec)).Fwidth
  14360 	(*VP8Io)(unsafe.Pointer((*VP8LDecoder)(unsafe.Pointer(dec)).Fio)).Fheight = (*ALPHDecoder)(unsafe.Pointer(alph_dec)).Fheight
  14361 	(*VP8LDecoder)(unsafe.Pointer(dec)).Fstatus = int32(VP8_STATUS_OK)
  14362 	VP8LInitBitReader(tls, dec+40, data, data_size)
  14363 	if !(DecodeImageStream(tls, (*ALPHDecoder)(unsafe.Pointer(alph_dec)).Fwidth, (*ALPHDecoder)(unsafe.Pointer(alph_dec)).Fheight, int32(1), dec, libc.UintptrFromInt32(0)) != 0) {
  14364 		goto Err
  14365 	}
  14366 	// Special case: if alpha data uses only the color indexing transform and
  14367 	// doesn't use color cache (a frequent case), we will use DecodeAlphaData()
  14368 	// method that only needs allocation of 1 byte per pixel (alpha channel).
  14369 	if (*VP8LDecoder)(unsafe.Pointer(dec)).Fnext_transform == int32(1) && (**(**VP8LTransform)(__ccgo_up(dec + 280))).Ftype1 == int32(COLOR_INDEXING_TRANSFORM) && Is8bOptimizable(tls, dec+152) != 0 {
  14370 		(*ALPHDecoder)(unsafe.Pointer(alph_dec)).Fuse_8b_decode = int32(1)
  14371 		ok = AllocateInternalBuffers8b(tls, dec)
  14372 	} else {
  14373 		// Allocate internal buffers (note that dec->width may have changed here).
  14374 		(*ALPHDecoder)(unsafe.Pointer(alph_dec)).Fuse_8b_decode = 0
  14375 		ok = AllocateInternalBuffers32b(tls, dec, (*ALPHDecoder)(unsafe.Pointer(alph_dec)).Fwidth)
  14376 	}
  14377 	if !(ok != 0) {
  14378 		goto Err
  14379 	}
  14380 	// Only set here, once we are sure it is valid (to avoid thread races).
  14381 	(*ALPHDecoder)(unsafe.Pointer(alph_dec)).Fvp8l_dec = dec
  14382 	return int32(1)
  14383 	goto Err
  14384 Err:
  14385 	;
  14386 	VP8LDelete(tls, dec)
  14387 	return 0
  14388 }
  14389 
  14390 func VP8LDecodeAlphaImageStream(tls *libc.TLS, alph_dec uintptr, last_row int32) (r int32) {
  14391 	var dec uintptr
  14392 	var v1 int32
  14393 	_, _ = dec, v1
  14394 	dec = (*ALPHDecoder)(unsafe.Pointer(alph_dec)).Fvp8l_dec
  14395 	if (*VP8LDecoder)(unsafe.Pointer(dec)).Flast_row >= last_row {
  14396 		return int32(1) // done
  14397 	}
  14398 	if !((*ALPHDecoder)(unsafe.Pointer(alph_dec)).Fuse_8b_decode != 0) {
  14399 		WebPInitAlphaProcessing(tls)
  14400 	}
  14401 	// Decode (with special row processing).
  14402 	if (*ALPHDecoder)(unsafe.Pointer(alph_dec)).Fuse_8b_decode != 0 {
  14403 		v1 = DecodeAlphaData(tls, dec, (*VP8LDecoder)(unsafe.Pointer(dec)).Fpixels, (*VP8LDecoder)(unsafe.Pointer(dec)).Fwidth, (*VP8LDecoder)(unsafe.Pointer(dec)).Fheight, last_row)
  14404 	} else {
  14405 		v1 = DecodeImageData(tls, dec, (*VP8LDecoder)(unsafe.Pointer(dec)).Fpixels, (*VP8LDecoder)(unsafe.Pointer(dec)).Fwidth, (*VP8LDecoder)(unsafe.Pointer(dec)).Fheight, last_row, __ccgo_fp(ExtractAlphaRows))
  14406 	}
  14407 	return v1
  14408 }
  14409 
  14410 //------------------------------------------------------------------------------
  14411 
  14412 func VP8LDecodeHeader(tls *libc.TLS, dec uintptr, io uintptr) (r int32) {
  14413 	bp := tls.Alloc(16)
  14414 	defer tls.Free(16)
  14415 	var _ /* has_alpha at bp+8 */ int32
  14416 	var _ /* height at bp+4 */ int32
  14417 	var _ /* width at bp+0 */ int32
  14418 	if dec == libc.UintptrFromInt32(0) {
  14419 		return 0
  14420 	}
  14421 	if io == libc.UintptrFromInt32(0) {
  14422 		return VP8LSetError(tls, dec, int32(VP8_STATUS_INVALID_PARAM))
  14423 	}
  14424 	(*VP8LDecoder)(unsafe.Pointer(dec)).Fio = io
  14425 	(*VP8LDecoder)(unsafe.Pointer(dec)).Fstatus = int32(VP8_STATUS_OK)
  14426 	VP8LInitBitReader(tls, dec+40, (*VP8Io)(unsafe.Pointer(io)).Fdata, (*VP8Io)(unsafe.Pointer(io)).Fdata_size)
  14427 	if !(ReadImageInfo(tls, dec+40, bp, bp+4, bp+8) != 0) {
  14428 		VP8LSetError(tls, dec, int32(VP8_STATUS_BITSTREAM_ERROR))
  14429 		goto Error
  14430 	}
  14431 	(*VP8LDecoder)(unsafe.Pointer(dec)).Fstate = int32(READ_DIM)
  14432 	(*VP8Io)(unsafe.Pointer(io)).Fwidth = **(**int32)(__ccgo_up(bp))
  14433 	(*VP8Io)(unsafe.Pointer(io)).Fheight = **(**int32)(__ccgo_up(bp + 4))
  14434 	if !(DecodeImageStream(tls, **(**int32)(__ccgo_up(bp)), **(**int32)(__ccgo_up(bp + 4)), int32(1), dec, libc.UintptrFromInt32(0)) != 0) {
  14435 		goto Error
  14436 	}
  14437 	return int32(1)
  14438 	goto Error
  14439 Error:
  14440 	;
  14441 	VP8LClear(tls, dec)
  14442 	return 0
  14443 }
  14444 
  14445 func VP8LDecodeImage(tls *libc.TLS, dec uintptr) (r int32) {
  14446 	var io, params uintptr
  14447 	var v1 WEBP_CSP_MODE1
  14448 	var v2 int32
  14449 	var v4 bool
  14450 	_, _, _, _, _ = io, params, v1, v2, v4
  14451 	io = libc.UintptrFromInt32(0)
  14452 	params = libc.UintptrFromInt32(0)
  14453 	if dec == libc.UintptrFromInt32(0) {
  14454 		return 0
  14455 	}
  14456 	io = (*VP8LDecoder)(unsafe.Pointer(dec)).Fio
  14457 	params = (*VP8Io)(unsafe.Pointer(io)).Fopaque
  14458 	// Initialization.
  14459 	if (*VP8LDecoder)(unsafe.Pointer(dec)).Fstate != int32(READ_DATA) {
  14460 		(*VP8LDecoder)(unsafe.Pointer(dec)).Foutput = (*WebPDecParams)(unsafe.Pointer(params)).Foutput
  14461 		if !(WebPIoInitFromOptions(tls, (*WebPDecParams)(unsafe.Pointer(params)).Foptions, io, int32(MODE_BGRA)) != 0) {
  14462 			VP8LSetError(tls, dec, int32(VP8_STATUS_INVALID_PARAM))
  14463 			goto Err
  14464 		}
  14465 		if !(AllocateInternalBuffers32b(tls, dec, (*VP8Io)(unsafe.Pointer(io)).Fwidth) != 0) {
  14466 			goto Err
  14467 		}
  14468 		if (*VP8Io)(unsafe.Pointer(io)).Fuse_scaling != 0 && !(AllocateAndInitRescaler(tls, dec, io) != 0) {
  14469 			goto Err
  14470 		}
  14471 		if v4 = (*VP8Io)(unsafe.Pointer(io)).Fuse_scaling != 0; !v4 {
  14472 			v1 = (*WebPDecBuffer)(unsafe.Pointer((*VP8LDecoder)(unsafe.Pointer(dec)).Foutput)).Fcolorspace
  14473 			v2 = libc.BoolInt32(v1 == int32(MODE_rgbA) || v1 == int32(MODE_bgrA) || v1 == int32(MODE_Argb) || v1 == int32(MODE_rgbA_4444))
  14474 			goto _3
  14475 		_3:
  14476 		}
  14477 		if v4 || v2 != 0 {
  14478 			// need the alpha-multiply functions for premultiplied output or rescaling
  14479 			WebPInitAlphaProcessing(tls)
  14480 		}
  14481 		v2 = libc.BoolInt32((*WebPDecBuffer)(unsafe.Pointer((*VP8LDecoder)(unsafe.Pointer(dec)).Foutput)).Fcolorspace < int32(MODE_YUV))
  14482 		goto _6
  14483 	_6:
  14484 		if !(v2 != 0) {
  14485 			WebPInitConvertARGBToYUV(tls)
  14486 			if (*(*WebPYUVABuffer)(unsafe.Pointer((*VP8LDecoder)(unsafe.Pointer(dec)).Foutput + 16))).Fa != libc.UintptrFromInt32(0) {
  14487 				WebPInitAlphaProcessing(tls)
  14488 			}
  14489 		}
  14490 		if (*VP8LDecoder)(unsafe.Pointer(dec)).Fincremental != 0 {
  14491 			if (*VP8LDecoder)(unsafe.Pointer(dec)).Fhdr.Fcolor_cache_size > 0 && (*VP8LDecoder)(unsafe.Pointer(dec)).Fhdr.Fsaved_color_cache.Fcolors == libc.UintptrFromInt32(0) {
  14492 				if !(VP8LColorCacheInit(tls, dec+152+24, (*VP8LDecoder)(unsafe.Pointer(dec)).Fhdr.Fcolor_cache.Fhash_bits) != 0) {
  14493 					VP8LSetError(tls, dec, int32(VP8_STATUS_OUT_OF_MEMORY))
  14494 					goto Err
  14495 				}
  14496 			}
  14497 		}
  14498 		(*VP8LDecoder)(unsafe.Pointer(dec)).Fstate = int32(READ_DATA)
  14499 	}
  14500 	// Decode.
  14501 	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) {
  14502 		goto Err
  14503 	}
  14504 	(*WebPDecParams)(unsafe.Pointer(params)).Flast_y = (*VP8LDecoder)(unsafe.Pointer(dec)).Flast_out_row
  14505 	return int32(1)
  14506 	goto Err
  14507 Err:
  14508 	;
  14509 	VP8LClear(tls, dec)
  14510 	return 0
  14511 }
  14512 
  14513 const VP8L_MAGIC_BYTE2 = 0x2f
  14514 
  14515 var kHashMul9 = uint32(0x1e35a7bd)
  14516 
  14517 type WebPData = struct {
  14518 	Fbytes uintptr
  14519 	Fsize  size_t
  14520 }
  14521 
  14522 type WebPFeatureFlags1 = int32
  14523 
  14524 type WebPFeatureFlags = int32
  14525 
  14526 const ANIMATION_FLAG = 2
  14527 const XMP_FLAG = 4
  14528 const EXIF_FLAG = 8
  14529 const ALPHA_FLAG = 16
  14530 const ICCP_FLAG = 32
  14531 const ALL_VALID_FLAGS = 62
  14532 
  14533 type WebPMuxAnimDispose1 = int32
  14534 
  14535 type WebPMuxAnimDispose = int32
  14536 
  14537 const WEBP_MUX_DISPOSE_NONE = 0
  14538 const WEBP_MUX_DISPOSE_BACKGROUND = 1
  14539 
  14540 type WebPMuxAnimBlend1 = int32
  14541 
  14542 type WebPMuxAnimBlend = int32
  14543 
  14544 const WEBP_MUX_BLEND = 0
  14545 const WEBP_MUX_NO_BLEND = 1
  14546 
  14547 // Copyright 2010 Google Inc. All Rights Reserved.
  14548 //
  14549 // Use of this source code is governed by a BSD-style license
  14550 // that can be found in the COPYING file in the root of the source
  14551 // tree. An additional intellectual property rights grant can be found
  14552 // in the file PATENTS. All contributing project authors may
  14553 // be found in the AUTHORS file in the root of the source tree.
  14554 // -----------------------------------------------------------------------------
  14555 //
  14556 //  Common types + memory wrappers
  14557 //
  14558 // Author: Skal (pascal.massimino@gmail.com)
  14559 
  14560 //------------------------------------------------------------------------------
  14561 // RIFF layout is:
  14562 //   Offset  tag
  14563 //   0...3   "RIFF" 4-byte tag
  14564 //   4...7   size of image data (including metadata) starting at offset 8
  14565 //   8...11  "WEBP"   our form-type signature
  14566 // The RIFF container (12 bytes) is followed by appropriate chunks:
  14567 //   12..15  "VP8 ": 4-bytes tags, signaling the use of VP8 video format
  14568 //   16..19  size of the raw VP8 image data, starting at offset 20
  14569 //   20....  the VP8 bytes
  14570 // Or,
  14571 //   12..15  "VP8L": 4-bytes tags, signaling the use of VP8L lossless format
  14572 //   16..19  size of the raw VP8L image data, starting at offset 20
  14573 //   20....  the VP8L bytes
  14574 // Or,
  14575 //   12..15  "VP8X": 4-bytes tags, describing the extended-VP8 chunk.
  14576 //   16..19  size of the VP8X chunk starting at offset 20.
  14577 //   20..23  VP8X flags bit-map corresponding to the chunk-types present.
  14578 //   24..26  Width of the Canvas Image.
  14579 //   27..29  Height of the Canvas Image.
  14580 // There can be extra chunks after the "VP8X" chunk (ICCP, ANMF, VP8, VP8L,
  14581 // XMP, EXIF  ...)
  14582 // All sizes are in little-endian order.
  14583 // Note: chunk data size must be padded to multiple of 2 when written.
  14584 
  14585 // C documentation
  14586 //
  14587 //	// Validates the RIFF container (if detected) and skips over it.
  14588 //	// If a RIFF container is detected, returns:
  14589 //	//     VP8_STATUS_BITSTREAM_ERROR for invalid header,
  14590 //	//     VP8_STATUS_NOT_ENOUGH_DATA for truncated data if have_all_data is true,
  14591 //	// and VP8_STATUS_OK otherwise.
  14592 //	// In case there are not enough bytes (partial RIFF container), return 0 for
  14593 //	// *riff_size. Else return the RIFF size extracted from the header.
  14594 func ParseRIFF(tls *libc.TLS, data2 uintptr, data_size uintptr, have_all_data int32, riff_size uintptr) (r VP8StatusCode1) {
  14595 	var size, v2 uint32_t
  14596 	var v1, v4, v7 uintptr
  14597 	var v5, v8 int32
  14598 	_, _, _, _, _, _, _ = size, v1, v2, v4, v5, v7, v8
  14599 	**(**size_t)(__ccgo_up(riff_size)) = uint64(0) // Default: no RIFF present.
  14600 	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) {
  14601 		if libc.Xmemcmp(tls, **(**uintptr)(__ccgo_up(data2))+uintptr(8), __ccgo_ts+569, uint64(TAG_SIZE)) != 0 {
  14602 			return int32(VP8_STATUS_BITSTREAM_ERROR) // Wrong image file signature.
  14603 		} else {
  14604 			v1 = **(**uintptr)(__ccgo_up(data2)) + uintptr(TAG_SIZE)
  14605 			v4 = v1
  14606 			v5 = int32(**(**uint8_t)(__ccgo_up(v4)))<<libc.Int32FromInt32(0) | int32(**(**uint8_t)(__ccgo_up(v4 + 1)))<<int32(8)
  14607 			goto _6
  14608 		_6:
  14609 			v7 = v1 + uintptr(2)
  14610 			v8 = int32(**(**uint8_t)(__ccgo_up(v7)))<<libc.Int32FromInt32(0) | int32(**(**uint8_t)(__ccgo_up(v7 + 1)))<<int32(8)
  14611 			goto _9
  14612 		_9:
  14613 			v2 = uint32(v5) | uint32(v8)<<libc.Int32FromInt32(16)
  14614 			goto _3
  14615 		_3:
  14616 			size = v2
  14617 			// Check that we have at least one chunk (i.e "WEBP" + "VP8?nnnn").
  14618 			if size < uint32(libc.Int32FromInt32(TAG_SIZE)+libc.Int32FromInt32(CHUNK_HEADER_SIZE)) {
  14619 				return int32(VP8_STATUS_BITSTREAM_ERROR)
  14620 			}
  14621 			if size > ^libc.Uint32FromUint32(0)-libc.Uint32FromInt32(CHUNK_HEADER_SIZE)-libc.Uint32FromInt32(1) {
  14622 				return int32(VP8_STATUS_BITSTREAM_ERROR)
  14623 			}
  14624 			if have_all_data != 0 && uint64(size) > **(**size_t)(__ccgo_up(data_size))-uint64(CHUNK_HEADER_SIZE) {
  14625 				return int32(VP8_STATUS_NOT_ENOUGH_DATA) // Truncated bitstream.
  14626 			}
  14627 			// We have a RIFF container. Skip it.
  14628 			**(**size_t)(__ccgo_up(riff_size)) = uint64(size)
  14629 			**(**uintptr)(__ccgo_up(data2)) += uintptr(RIFF_HEADER_SIZE)
  14630 			**(**size_t)(__ccgo_up(data_size)) -= uint64(RIFF_HEADER_SIZE)
  14631 		}
  14632 	}
  14633 	return int32(VP8_STATUS_OK)
  14634 }
  14635 
  14636 // C documentation
  14637 //
  14638 //	// Validates the VP8X header and skips over it.
  14639 //	// Returns VP8_STATUS_BITSTREAM_ERROR for invalid VP8X header,
  14640 //	//         VP8_STATUS_NOT_ENOUGH_DATA in case of insufficient data, and
  14641 //	//         VP8_STATUS_OK otherwise.
  14642 //	// If a VP8X chunk is found, found_vp8x is set to true and *width_ptr,
  14643 //	// *height_ptr and *flags_ptr are set to the corresponding values extracted
  14644 //	// from the VP8X chunk.
  14645 func ParseVP8X(tls *libc.TLS, data3 uintptr, data_size uintptr, found_vp8x uintptr, width_ptr uintptr, height_ptr uintptr, flags_ptr uintptr) (r VP8StatusCode1) {
  14646 	var chunk_size, flags, vp8x_size, v2 uint32_t
  14647 	var height, width, v5, v8 int32
  14648 	var v1, v4, v7 uintptr
  14649 	_, _, _, _, _, _, _, _, _, _, _ = chunk_size, flags, height, vp8x_size, width, v1, v2, v4, v5, v7, v8
  14650 	vp8x_size = uint32(libc.Int32FromInt32(CHUNK_HEADER_SIZE) + libc.Int32FromInt32(VP8X_CHUNK_SIZE))
  14651 	**(**int32)(__ccgo_up(found_vp8x)) = 0
  14652 	if **(**size_t)(__ccgo_up(data_size)) < uint64(CHUNK_HEADER_SIZE) {
  14653 		return int32(VP8_STATUS_NOT_ENOUGH_DATA) // Insufficient data.
  14654 	}
  14655 	if !(libc.Xmemcmp(tls, **(**uintptr)(__ccgo_up(data3)), __ccgo_ts+574, uint64(TAG_SIZE)) != 0) {
  14656 		v1 = **(**uintptr)(__ccgo_up(data3)) + uintptr(TAG_SIZE)
  14657 		v4 = v1
  14658 		v5 = int32(**(**uint8_t)(__ccgo_up(v4)))<<libc.Int32FromInt32(0) | int32(**(**uint8_t)(__ccgo_up(v4 + 1)))<<int32(8)
  14659 		goto _6
  14660 	_6:
  14661 		v7 = v1 + uintptr(2)
  14662 		v8 = int32(**(**uint8_t)(__ccgo_up(v7)))<<libc.Int32FromInt32(0) | int32(**(**uint8_t)(__ccgo_up(v7 + 1)))<<int32(8)
  14663 		goto _9
  14664 	_9:
  14665 		v2 = uint32(v5) | uint32(v8)<<libc.Int32FromInt32(16)
  14666 		goto _3
  14667 	_3:
  14668 		chunk_size = v2
  14669 		if chunk_size != uint32(VP8X_CHUNK_SIZE) {
  14670 			return int32(VP8_STATUS_BITSTREAM_ERROR) // Wrong chunk size.
  14671 		}
  14672 		// Verify if enough data is available to validate the VP8X chunk.
  14673 		if **(**size_t)(__ccgo_up(data_size)) < uint64(vp8x_size) {
  14674 			return int32(VP8_STATUS_NOT_ENOUGH_DATA) // Insufficient data.
  14675 		}
  14676 		v1 = **(**uintptr)(__ccgo_up(data3)) + uintptr(8)
  14677 		v4 = v1
  14678 		v5 = int32(**(**uint8_t)(__ccgo_up(v4)))<<libc.Int32FromInt32(0) | int32(**(**uint8_t)(__ccgo_up(v4 + 1)))<<int32(8)
  14679 		goto _15
  14680 	_15:
  14681 		v7 = v1 + uintptr(2)
  14682 		v8 = int32(**(**uint8_t)(__ccgo_up(v7)))<<libc.Int32FromInt32(0) | int32(**(**uint8_t)(__ccgo_up(v7 + 1)))<<int32(8)
  14683 		goto _18
  14684 	_18:
  14685 		v2 = uint32(v5) | uint32(v8)<<libc.Int32FromInt32(16)
  14686 		goto _12
  14687 	_12:
  14688 		flags = v2
  14689 		v1 = **(**uintptr)(__ccgo_up(data3)) + uintptr(12)
  14690 		v4 = v1
  14691 		v8 = int32(**(**uint8_t)(__ccgo_up(v4)))<<libc.Int32FromInt32(0) | int32(**(**uint8_t)(__ccgo_up(v4 + 1)))<<int32(8)
  14692 		goto _24
  14693 	_24:
  14694 		v5 = v8 | int32(**(**uint8_t)(__ccgo_up(v1 + 2)))<<int32(16)
  14695 		goto _21
  14696 	_21:
  14697 		width = int32(1) + v5
  14698 		v1 = **(**uintptr)(__ccgo_up(data3)) + uintptr(15)
  14699 		v4 = v1
  14700 		v8 = int32(**(**uint8_t)(__ccgo_up(v4)))<<libc.Int32FromInt32(0) | int32(**(**uint8_t)(__ccgo_up(v4 + 1)))<<int32(8)
  14701 		goto _30
  14702 	_30:
  14703 		v5 = v8 | int32(**(**uint8_t)(__ccgo_up(v1 + 2)))<<int32(16)
  14704 		goto _27
  14705 	_27:
  14706 		height = int32(1) + v5
  14707 		if uint64(width)*uint64(height) >= libc.Uint64FromUint64(1)<<libc.Int32FromInt32(32) {
  14708 			return int32(VP8_STATUS_BITSTREAM_ERROR) // image is too large
  14709 		}
  14710 		if flags_ptr != libc.UintptrFromInt32(0) {
  14711 			**(**uint32_t)(__ccgo_up(flags_ptr)) = flags
  14712 		}
  14713 		if width_ptr != libc.UintptrFromInt32(0) {
  14714 			**(**int32)(__ccgo_up(width_ptr)) = width
  14715 		}
  14716 		if height_ptr != libc.UintptrFromInt32(0) {
  14717 			**(**int32)(__ccgo_up(height_ptr)) = height
  14718 		}
  14719 		// Skip over VP8X header bytes.
  14720 		**(**uintptr)(__ccgo_up(data3)) += uintptr(vp8x_size)
  14721 		**(**size_t)(__ccgo_up(data_size)) -= uint64(vp8x_size)
  14722 		**(**int32)(__ccgo_up(found_vp8x)) = int32(1)
  14723 	}
  14724 	return int32(VP8_STATUS_OK)
  14725 }
  14726 
  14727 // C documentation
  14728 //
  14729 //	// Skips to the next VP8/VP8L chunk header in the data given the size of the
  14730 //	// RIFF chunk 'riff_size'.
  14731 //	// Returns VP8_STATUS_BITSTREAM_ERROR if any invalid chunk size is encountered,
  14732 //	//         VP8_STATUS_NOT_ENOUGH_DATA in case of insufficient data, and
  14733 //	//         VP8_STATUS_OK otherwise.
  14734 //	// If an alpha chunk is found, *alpha_data and *alpha_size are set
  14735 //	// appropriately.
  14736 func ParseOptionalChunks(tls *libc.TLS, data2 uintptr, data_size uintptr, riff_size size_t, alpha_data uintptr, alpha_size uintptr) (r VP8StatusCode1) {
  14737 	var buf, v1, v4, v7 uintptr
  14738 	var buf_size size_t
  14739 	var chunk_size, disk_chunk_size, total_size, v2 uint32_t
  14740 	var v5, v8 int32
  14741 	_, _, _, _, _, _, _, _, _, _, _ = buf, buf_size, chunk_size, disk_chunk_size, total_size, v1, v2, v4, v5, v7, v8
  14742 	total_size = uint32(libc.Int32FromInt32(TAG_SIZE) + libc.Int32FromInt32(CHUNK_HEADER_SIZE) + libc.Int32FromInt32(VP8X_CHUNK_SIZE)) // data.
  14743 	buf = **(**uintptr)(__ccgo_up(data2))
  14744 	buf_size = **(**size_t)(__ccgo_up(data_size))
  14745 	**(**uintptr)(__ccgo_up(alpha_data)) = libc.UintptrFromInt32(0)
  14746 	**(**size_t)(__ccgo_up(alpha_size)) = uint64(0)
  14747 	for int32(1) != 0 { // chunk_size with padding
  14748 		**(**uintptr)(__ccgo_up(data2)) = buf
  14749 		**(**size_t)(__ccgo_up(data_size)) = buf_size
  14750 		if buf_size < uint64(CHUNK_HEADER_SIZE) { // Insufficient data.
  14751 			return int32(VP8_STATUS_NOT_ENOUGH_DATA)
  14752 		}
  14753 		v1 = buf + uintptr(TAG_SIZE)
  14754 		v4 = v1
  14755 		v5 = int32(**(**uint8_t)(__ccgo_up(v4)))<<libc.Int32FromInt32(0) | int32(**(**uint8_t)(__ccgo_up(v4 + 1)))<<int32(8)
  14756 		goto _6
  14757 	_6:
  14758 		v7 = v1 + uintptr(2)
  14759 		v8 = int32(**(**uint8_t)(__ccgo_up(v7)))<<libc.Int32FromInt32(0) | int32(**(**uint8_t)(__ccgo_up(v7 + 1)))<<int32(8)
  14760 		goto _9
  14761 	_9:
  14762 		v2 = uint32(v5) | uint32(v8)<<libc.Int32FromInt32(16)
  14763 		goto _3
  14764 	_3:
  14765 		chunk_size = v2
  14766 		if chunk_size > ^libc.Uint32FromUint32(0)-libc.Uint32FromInt32(CHUNK_HEADER_SIZE)-libc.Uint32FromInt32(1) {
  14767 			return int32(VP8_STATUS_BITSTREAM_ERROR) // Not a valid chunk size.
  14768 		}
  14769 		// For odd-sized chunk-payload, there's one byte padding at the end.
  14770 		disk_chunk_size = (uint32(CHUNK_HEADER_SIZE) + chunk_size + uint32(1)) & ^libc.Uint32FromUint32(1)
  14771 		total_size = total_size + disk_chunk_size
  14772 		// Check that total bytes skipped so far does not exceed riff_size.
  14773 		if riff_size > uint64(0) && uint64(total_size) > riff_size {
  14774 			return int32(VP8_STATUS_BITSTREAM_ERROR) // Not a valid chunk size.
  14775 		}
  14776 		// Start of a (possibly incomplete) VP8/VP8L chunk implies that we have
  14777 		// parsed all the optional chunks.
  14778 		// Note: This check must occur before the check 'buf_size < disk_chunk_size'
  14779 		// below to allow incomplete VP8/VP8L chunks.
  14780 		if !(libc.Xmemcmp(tls, buf, __ccgo_ts+579, uint64(TAG_SIZE)) != 0) || !(libc.Xmemcmp(tls, buf, __ccgo_ts+584, uint64(TAG_SIZE)) != 0) {
  14781 			return int32(VP8_STATUS_OK)
  14782 		}
  14783 		if buf_size < uint64(disk_chunk_size) { // Insufficient data.
  14784 			return int32(VP8_STATUS_NOT_ENOUGH_DATA)
  14785 		}
  14786 		if !(libc.Xmemcmp(tls, buf, __ccgo_ts+589, uint64(TAG_SIZE)) != 0) { // A valid ALPH header.
  14787 			**(**uintptr)(__ccgo_up(alpha_data)) = buf + uintptr(CHUNK_HEADER_SIZE)
  14788 			**(**size_t)(__ccgo_up(alpha_size)) = uint64(chunk_size)
  14789 		}
  14790 		// We have a full and valid chunk; skip it.
  14791 		buf = buf + uintptr(disk_chunk_size)
  14792 		buf_size = buf_size - uint64(disk_chunk_size)
  14793 	}
  14794 	return r
  14795 }
  14796 
  14797 // C documentation
  14798 //
  14799 //	// Validates the VP8/VP8L Header ("VP8 nnnn" or "VP8L nnnn") and skips over it.
  14800 //	// Returns VP8_STATUS_BITSTREAM_ERROR for invalid (chunk larger than
  14801 //	//         riff_size) VP8/VP8L header,
  14802 //	//         VP8_STATUS_NOT_ENOUGH_DATA in case of insufficient data, and
  14803 //	//         VP8_STATUS_OK otherwise.
  14804 //	// If a VP8/VP8L chunk is found, *chunk_size is set to the total number of bytes
  14805 //	// extracted from the VP8/VP8L chunk header.
  14806 //	// The flag '*is_lossless' is set to 1 in case of VP8L chunk / raw VP8L data.
  14807 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) {
  14808 	var data2, v1, v4, v7 uintptr
  14809 	var is_vp8, is_vp8l, v5, v8 int32
  14810 	var minimal_size, size, v2 uint32_t
  14811 	_, _, _, _, _, _, _, _, _, _, _ = data2, is_vp8, is_vp8l, minimal_size, size, v1, v2, v4, v5, v7, v8
  14812 	data2 = **(**uintptr)(__ccgo_up(data_ptr))
  14813 	is_vp8 = libc.BoolInt32(!(libc.Xmemcmp(tls, data2, __ccgo_ts+579, uint64(TAG_SIZE)) != 0))
  14814 	is_vp8l = libc.BoolInt32(!(libc.Xmemcmp(tls, data2, __ccgo_ts+584, uint64(TAG_SIZE)) != 0))
  14815 	minimal_size = uint32(libc.Int32FromInt32(TAG_SIZE) + libc.Int32FromInt32(CHUNK_HEADER_SIZE)) // "WEBP" + "VP8 nnnn" OR
  14816 	// "WEBP" + "VP8Lnnnn"
  14817 	if **(**size_t)(__ccgo_up(data_size)) < uint64(CHUNK_HEADER_SIZE) {
  14818 		return int32(VP8_STATUS_NOT_ENOUGH_DATA) // Insufficient data.
  14819 	}
  14820 	if is_vp8 != 0 || is_vp8l != 0 {
  14821 		v1 = data2 + uintptr(TAG_SIZE)
  14822 		v4 = v1
  14823 		v5 = int32(**(**uint8_t)(__ccgo_up(v4)))<<libc.Int32FromInt32(0) | int32(**(**uint8_t)(__ccgo_up(v4 + 1)))<<int32(8)
  14824 		goto _6
  14825 	_6:
  14826 		v7 = v1 + uintptr(2)
  14827 		v8 = int32(**(**uint8_t)(__ccgo_up(v7)))<<libc.Int32FromInt32(0) | int32(**(**uint8_t)(__ccgo_up(v7 + 1)))<<int32(8)
  14828 		goto _9
  14829 	_9:
  14830 		v2 = uint32(v5) | uint32(v8)<<libc.Int32FromInt32(16)
  14831 		goto _3
  14832 	_3:
  14833 		// Bitstream contains VP8/VP8L header.
  14834 		size = v2
  14835 		if riff_size >= uint64(minimal_size) && uint64(size) > riff_size-uint64(minimal_size) {
  14836 			return int32(VP8_STATUS_BITSTREAM_ERROR) // Inconsistent size information.
  14837 		}
  14838 		if have_all_data != 0 && uint64(size) > **(**size_t)(__ccgo_up(data_size))-uint64(CHUNK_HEADER_SIZE) {
  14839 			return int32(VP8_STATUS_NOT_ENOUGH_DATA) // Truncated bitstream.
  14840 		}
  14841 		// Skip over CHUNK_HEADER_SIZE bytes from VP8/VP8L Header.
  14842 		**(**size_t)(__ccgo_up(chunk_size)) = uint64(size)
  14843 		**(**uintptr)(__ccgo_up(data_ptr)) += uintptr(CHUNK_HEADER_SIZE)
  14844 		**(**size_t)(__ccgo_up(data_size)) -= uint64(CHUNK_HEADER_SIZE)
  14845 		**(**int32)(__ccgo_up(is_lossless)) = is_vp8l
  14846 	} else {
  14847 		// Raw VP8/VP8L bitstream (no header).
  14848 		**(**int32)(__ccgo_up(is_lossless)) = VP8LCheckSignature(tls, data2, **(**size_t)(__ccgo_up(data_size)))
  14849 		**(**size_t)(__ccgo_up(chunk_size)) = **(**size_t)(__ccgo_up(data_size))
  14850 	}
  14851 	return int32(VP8_STATUS_OK)
  14852 }
  14853 
  14854 //------------------------------------------------------------------------------
  14855 
  14856 // C documentation
  14857 //
  14858 //	// Fetch '*width', '*height', '*has_alpha' and fill out 'headers' based on
  14859 //	// 'data'. All the output parameters may be NULL. If 'headers' is NULL only the
  14860 //	// minimal amount will be read to fetch the remaining parameters.
  14861 //	// If 'headers' is non-NULL this function will attempt to locate both alpha
  14862 //	// data (with or without a VP8X chunk) and the bitstream chunk (VP8/VP8L).
  14863 //	// Note: The following chunk sequences (before the raw VP8/VP8L data) are
  14864 //	// considered valid by this function:
  14865 //	// RIFF + VP8(L)
  14866 //	// RIFF + VP8X + (optional chunks) + VP8(L)
  14867 //	// ALPH + VP8 <-- Not a valid WebP format: only allowed for internal purpose.
  14868 //	// VP8(L)     <-- Not a valid WebP format: only allowed for internal purpose.
  14869 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) {
  14870 	bp := tls.Alloc(128)
  14871 	defer tls.Free(128)
  14872 	*(*uintptr)(unsafe.Pointer(bp)) = _data
  14873 	*(*size_t)(unsafe.Pointer(bp + 8)) = _data_size
  14874 	var animation_present, found_riff, have_all_data, v1 int32
  14875 	var status VP8StatusCode1
  14876 	var _ /* canvas_height at bp+20 */ int32
  14877 	var _ /* canvas_width at bp+16 */ int32
  14878 	var _ /* flags at bp+112 */ uint32_t
  14879 	var _ /* found_vp8x at bp+32 */ int32
  14880 	var _ /* hdrs at bp+40 */ WebPHeaderStructure
  14881 	var _ /* image_height at bp+28 */ int32
  14882 	var _ /* image_width at bp+24 */ int32
  14883 	_, _, _, _, _ = animation_present, found_riff, have_all_data, status, v1
  14884 	**(**int32)(__ccgo_up(bp + 16)) = 0
  14885 	**(**int32)(__ccgo_up(bp + 20)) = 0
  14886 	**(**int32)(__ccgo_up(bp + 24)) = 0
  14887 	**(**int32)(__ccgo_up(bp + 28)) = 0
  14888 	found_riff = 0
  14889 	**(**int32)(__ccgo_up(bp + 32)) = 0
  14890 	animation_present = 0
  14891 	if headers != libc.UintptrFromInt32(0) {
  14892 		v1 = (*WebPHeaderStructure)(unsafe.Pointer(headers)).Fhave_all_data
  14893 	} else {
  14894 		v1 = 0
  14895 	}
  14896 	have_all_data = v1
  14897 	if **(**uintptr)(__ccgo_up(bp)) == libc.UintptrFromInt32(0) || **(**size_t)(__ccgo_up(bp + 8)) < uint64(RIFF_HEADER_SIZE) {
  14898 		return int32(VP8_STATUS_NOT_ENOUGH_DATA)
  14899 	}
  14900 	libc.Xmemset(tls, bp+40, 0, uint64(72))
  14901 	(**(**WebPHeaderStructure)(__ccgo_up(bp + 40))).Fdata = **(**uintptr)(__ccgo_up(bp))
  14902 	(**(**WebPHeaderStructure)(__ccgo_up(bp + 40))).Fdata_size = **(**size_t)(__ccgo_up(bp + 8))
  14903 	// Skip over RIFF header.
  14904 	status = ParseRIFF(tls, bp, bp+8, have_all_data, bp+40+56)
  14905 	if status != int32(VP8_STATUS_OK) {
  14906 		return status // Wrong RIFF header / insufficient data.
  14907 	}
  14908 	found_riff = libc.BoolInt32((**(**WebPHeaderStructure)(__ccgo_up(bp + 40))).Friff_size > uint64(0))
  14909 	// Skip over VP8X.
  14910 	**(**uint32_t)(__ccgo_up(bp + 112)) = uint32(0)
  14911 	status = ParseVP8X(tls, bp, bp+8, bp+32, bp+16, bp+20, bp+112)
  14912 	if status != int32(VP8_STATUS_OK) {
  14913 		return status // Wrong VP8X / insufficient data.
  14914 	}
  14915 	animation_present = libc.BoolInt32(!!(**(**uint32_t)(__ccgo_up(bp + 112))&uint32(ANIMATION_FLAG) != 0))
  14916 	if !(found_riff != 0) && **(**int32)(__ccgo_up(bp + 32)) != 0 {
  14917 		// Note: This restriction may be removed in the future, if it becomes
  14918 		// necessary to send VP8X chunk to the decoder.
  14919 		return int32(VP8_STATUS_BITSTREAM_ERROR)
  14920 	}
  14921 	if has_alpha != libc.UintptrFromInt32(0) {
  14922 		**(**int32)(__ccgo_up(has_alpha)) = libc.BoolInt32(!!(**(**uint32_t)(__ccgo_up(bp + 112))&uint32(ALPHA_FLAG) != 0))
  14923 	}
  14924 	if has_animation != libc.UintptrFromInt32(0) {
  14925 		**(**int32)(__ccgo_up(has_animation)) = animation_present
  14926 	}
  14927 	if format != libc.UintptrFromInt32(0) {
  14928 		**(**int32)(__ccgo_up(format)) = 0
  14929 	} // default = undefined
  14930 	**(**int32)(__ccgo_up(bp + 24)) = **(**int32)(__ccgo_up(bp + 16))
  14931 	**(**int32)(__ccgo_up(bp + 28)) = **(**int32)(__ccgo_up(bp + 20))
  14932 	if **(**int32)(__ccgo_up(bp + 32)) != 0 && animation_present != 0 && headers == libc.UintptrFromInt32(0) {
  14933 		status = int32(VP8_STATUS_OK)
  14934 		goto ReturnWidthHeight // Just return features from VP8X header.
  14935 	}
  14936 	if **(**size_t)(__ccgo_up(bp + 8)) < uint64(TAG_SIZE) {
  14937 		status = int32(VP8_STATUS_NOT_ENOUGH_DATA)
  14938 		goto ReturnWidthHeight
  14939 	}
  14940 	// Skip over optional chunks if data started with "RIFF + VP8X" or "ALPH".
  14941 	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) {
  14942 		status = ParseOptionalChunks(tls, bp, bp+8, (**(**WebPHeaderStructure)(__ccgo_up(bp + 40))).Friff_size, bp+40+32, bp+40+40)
  14943 		if status != int32(VP8_STATUS_OK) {
  14944 			goto ReturnWidthHeight // Invalid chunk size / insufficient data.
  14945 		}
  14946 	}
  14947 	// Skip over VP8/VP8L header.
  14948 	status = ParseVP8Header(tls, bp, bp+8, have_all_data, (**(**WebPHeaderStructure)(__ccgo_up(bp + 40))).Friff_size, bp+40+48, bp+40+64)
  14949 	if status != int32(VP8_STATUS_OK) {
  14950 		goto ReturnWidthHeight // Wrong VP8/VP8L chunk-header / insufficient data.
  14951 	}
  14952 	if (**(**WebPHeaderStructure)(__ccgo_up(bp + 40))).Fcompressed_size > uint64(^libc.Uint32FromUint32(0)-libc.Uint32FromInt32(CHUNK_HEADER_SIZE)-libc.Uint32FromInt32(1)) {
  14953 		return int32(VP8_STATUS_BITSTREAM_ERROR)
  14954 	}
  14955 	if format != libc.UintptrFromInt32(0) && !(animation_present != 0) {
  14956 		if (**(**WebPHeaderStructure)(__ccgo_up(bp + 40))).Fis_lossless != 0 {
  14957 			v1 = int32(2)
  14958 		} else {
  14959 			v1 = int32(1)
  14960 		}
  14961 		**(**int32)(__ccgo_up(format)) = v1
  14962 	}
  14963 	if !((**(**WebPHeaderStructure)(__ccgo_up(bp + 40))).Fis_lossless != 0) {
  14964 		if **(**size_t)(__ccgo_up(bp + 8)) < uint64(VP8_FRAME_HEADER_SIZE) {
  14965 			status = int32(VP8_STATUS_NOT_ENOUGH_DATA)
  14966 			goto ReturnWidthHeight
  14967 		}
  14968 		// Validates raw VP8 data.
  14969 		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) {
  14970 			return int32(VP8_STATUS_BITSTREAM_ERROR)
  14971 		}
  14972 	} else {
  14973 		if **(**size_t)(__ccgo_up(bp + 8)) < uint64(VP8L_FRAME_HEADER_SIZE) {
  14974 			status = int32(VP8_STATUS_NOT_ENOUGH_DATA)
  14975 			goto ReturnWidthHeight
  14976 		}
  14977 		// Validates raw VP8L data.
  14978 		if !(VP8LGetInfo(tls, **(**uintptr)(__ccgo_up(bp)), **(**size_t)(__ccgo_up(bp + 8)), bp+24, bp+28, has_alpha) != 0) {
  14979 			return int32(VP8_STATUS_BITSTREAM_ERROR)
  14980 		}
  14981 	}
  14982 	// Validates image size coherency.
  14983 	if **(**int32)(__ccgo_up(bp + 32)) != 0 {
  14984 		if **(**int32)(__ccgo_up(bp + 16)) != **(**int32)(__ccgo_up(bp + 24)) || **(**int32)(__ccgo_up(bp + 20)) != **(**int32)(__ccgo_up(bp + 28)) {
  14985 			return int32(VP8_STATUS_BITSTREAM_ERROR)
  14986 		}
  14987 	}
  14988 	if headers != libc.UintptrFromInt32(0) {
  14989 		**(**WebPHeaderStructure)(__ccgo_up(headers)) = **(**WebPHeaderStructure)(__ccgo_up(bp + 40))
  14990 		(*WebPHeaderStructure)(unsafe.Pointer(headers)).Foffset = uint64(int64(**(**uintptr)(__ccgo_up(bp))) - int64((*WebPHeaderStructure)(unsafe.Pointer(headers)).Fdata))
  14991 	}
  14992 	goto ReturnWidthHeight
  14993 ReturnWidthHeight:
  14994 	;
  14995 	if status == int32(VP8_STATUS_OK) || status == int32(VP8_STATUS_NOT_ENOUGH_DATA) && **(**int32)(__ccgo_up(bp + 32)) != 0 && headers == libc.UintptrFromInt32(0) {
  14996 		if has_alpha != libc.UintptrFromInt32(0) {
  14997 			// If the data did not contain a VP8X/VP8L chunk the only definitive way
  14998 			// to set this is by looking for alpha data (from an ALPH chunk).
  14999 			**(**int32)(__ccgo_up(has_alpha)) |= libc.BoolInt32((**(**WebPHeaderStructure)(__ccgo_up(bp + 40))).Falpha_data != libc.UintptrFromInt32(0))
  15000 		}
  15001 		if width != libc.UintptrFromInt32(0) {
  15002 			**(**int32)(__ccgo_up(width)) = **(**int32)(__ccgo_up(bp + 24))
  15003 		}
  15004 		if height != libc.UintptrFromInt32(0) {
  15005 			**(**int32)(__ccgo_up(height)) = **(**int32)(__ccgo_up(bp + 28))
  15006 		}
  15007 		return int32(VP8_STATUS_OK)
  15008 	} else {
  15009 		return status
  15010 	}
  15011 	return r
  15012 }
  15013 
  15014 func WebPParseHeaders(tls *libc.TLS, headers uintptr) (r VP8StatusCode1) {
  15015 	bp := tls.Alloc(16)
  15016 	defer tls.Free(16)
  15017 	var status VP8StatusCode1
  15018 	var _ /* has_animation at bp+0 */ int32
  15019 	_ = status
  15020 	**(**int32)(__ccgo_up(bp)) = 0
  15021 	// fill out headers, ignore width/height/has_alpha.
  15022 	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)
  15023 	if status == int32(VP8_STATUS_OK) || status == int32(VP8_STATUS_NOT_ENOUGH_DATA) {
  15024 		// The WebPDemux API + libwebp can be used to decode individual
  15025 		// uncomposited frames or the WebPAnimDecoder can be used to fully
  15026 		// reconstruct them (see webp/demux.h).
  15027 		if **(**int32)(__ccgo_up(bp)) != 0 {
  15028 			status = int32(VP8_STATUS_UNSUPPORTED_FEATURE)
  15029 		}
  15030 	}
  15031 	return status
  15032 }
  15033 
  15034 //------------------------------------------------------------------------------
  15035 // WebPDecParams
  15036 
  15037 func WebPResetDecParams(tls *libc.TLS, params uintptr) {
  15038 	if params != libc.UintptrFromInt32(0) {
  15039 		libc.Xmemset(tls, params, 0, uint64(112))
  15040 	}
  15041 }
  15042 
  15043 //------------------------------------------------------------------------------
  15044 // "Into" decoding variants
  15045 
  15046 // C documentation
  15047 //
  15048 //	// Main flow
  15049 func DecodeInto(tls *libc.TLS, data uintptr, data_size size_t, params uintptr) (r VP8StatusCode1) {
  15050 	bp := tls.Alloc(240)
  15051 	defer tls.Free(240)
  15052 	var dec, dec1 uintptr
  15053 	var status VP8StatusCode1
  15054 	var v1 int32
  15055 	var _ /* headers at bp+160 */ WebPHeaderStructure
  15056 	var _ /* io at bp+0 */ VP8Io
  15057 	_, _, _, _ = dec, dec1, status, v1
  15058 	(**(**WebPHeaderStructure)(__ccgo_up(bp + 160))).Fdata = data
  15059 	(**(**WebPHeaderStructure)(__ccgo_up(bp + 160))).Fdata_size = data_size
  15060 	(**(**WebPHeaderStructure)(__ccgo_up(bp + 160))).Fhave_all_data = int32(1)
  15061 	status = WebPParseHeaders(tls, bp+160) // Process Pre-VP8 chunks.
  15062 	if status != int32(VP8_STATUS_OK) {
  15063 		return status
  15064 	}
  15065 	v1 = VP8InitIoInternal(tls, bp, int32(WEBP_DECODER_ABI_VERSION))
  15066 	goto _2
  15067 _2:
  15068 	if !(v1 != 0) {
  15069 		return int32(VP8_STATUS_INVALID_PARAM)
  15070 	}
  15071 	(**(**VP8Io)(__ccgo_up(bp))).Fdata = (**(**WebPHeaderStructure)(__ccgo_up(bp + 160))).Fdata + uintptr((**(**WebPHeaderStructure)(__ccgo_up(bp + 160))).Foffset)
  15072 	(**(**VP8Io)(__ccgo_up(bp))).Fdata_size = (**(**WebPHeaderStructure)(__ccgo_up(bp + 160))).Fdata_size - (**(**WebPHeaderStructure)(__ccgo_up(bp + 160))).Foffset
  15073 	WebPInitCustomIo(tls, params, bp) // Plug the I/O functions.
  15074 	if !((**(**WebPHeaderStructure)(__ccgo_up(bp + 160))).Fis_lossless != 0) {
  15075 		dec = VP8New(tls)
  15076 		if dec == libc.UintptrFromInt32(0) {
  15077 			return int32(VP8_STATUS_OUT_OF_MEMORY)
  15078 		}
  15079 		(*VP8Decoder)(unsafe.Pointer(dec)).Falpha_data = (**(**WebPHeaderStructure)(__ccgo_up(bp + 160))).Falpha_data
  15080 		(*VP8Decoder)(unsafe.Pointer(dec)).Falpha_data_size = (**(**WebPHeaderStructure)(__ccgo_up(bp + 160))).Falpha_data_size
  15081 		// Decode bitstream header, update io->width/io->height.
  15082 		if !(VP8GetHeaders(tls, dec, bp) != 0) {
  15083 			status = (*VP8Decoder)(unsafe.Pointer(dec)).Fstatus // An error occurred. Grab error status.
  15084 		} else {
  15085 			// Allocate/check output buffers.
  15086 			status = WebPAllocateDecBuffer(tls, (**(**VP8Io)(__ccgo_up(bp))).Fwidth, (**(**VP8Io)(__ccgo_up(bp))).Fheight, (*WebPDecParams)(unsafe.Pointer(params)).Foptions, (*WebPDecParams)(unsafe.Pointer(params)).Foutput)
  15087 			if status == int32(VP8_STATUS_OK) { // Decode
  15088 				// This change must be done before calling VP8Decode()
  15089 				(*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)
  15090 				VP8InitDithering(tls, (*WebPDecParams)(unsafe.Pointer(params)).Foptions, dec)
  15091 				if !(VP8Decode(tls, dec, bp) != 0) {
  15092 					status = (*VP8Decoder)(unsafe.Pointer(dec)).Fstatus
  15093 				}
  15094 			}
  15095 		}
  15096 		VP8Delete(tls, dec)
  15097 	} else {
  15098 		dec1 = VP8LNew(tls)
  15099 		if dec1 == libc.UintptrFromInt32(0) {
  15100 			return int32(VP8_STATUS_OUT_OF_MEMORY)
  15101 		}
  15102 		if !(VP8LDecodeHeader(tls, dec1, bp) != 0) {
  15103 			status = (*VP8LDecoder)(unsafe.Pointer(dec1)).Fstatus // An error occurred. Grab error status.
  15104 		} else {
  15105 			// Allocate/check output buffers.
  15106 			status = WebPAllocateDecBuffer(tls, (**(**VP8Io)(__ccgo_up(bp))).Fwidth, (**(**VP8Io)(__ccgo_up(bp))).Fheight, (*WebPDecParams)(unsafe.Pointer(params)).Foptions, (*WebPDecParams)(unsafe.Pointer(params)).Foutput)
  15107 			if status == int32(VP8_STATUS_OK) { // Decode
  15108 				if !(VP8LDecodeImage(tls, dec1) != 0) {
  15109 					status = (*VP8LDecoder)(unsafe.Pointer(dec1)).Fstatus
  15110 				}
  15111 			}
  15112 		}
  15113 		VP8LDelete(tls, dec1)
  15114 	}
  15115 	if status != int32(VP8_STATUS_OK) {
  15116 		WebPFreeDecBuffer(tls, (*WebPDecParams)(unsafe.Pointer(params)).Foutput)
  15117 	} else {
  15118 		if (*WebPDecParams)(unsafe.Pointer(params)).Foptions != libc.UintptrFromInt32(0) && (*WebPDecoderOptions)(unsafe.Pointer((*WebPDecParams)(unsafe.Pointer(params)).Foptions)).Fflip != 0 {
  15119 			// This restores the original stride values if options->flip was used
  15120 			// during the call to WebPAllocateDecBuffer above.
  15121 			status = WebPFlipBuffer(tls, (*WebPDecParams)(unsafe.Pointer(params)).Foutput)
  15122 		}
  15123 	}
  15124 	return status
  15125 }
  15126 
  15127 // C documentation
  15128 //
  15129 //	// Helpers
  15130 func DecodeIntoRGBABuffer(tls *libc.TLS, colorspace WEBP_CSP_MODE1, data uintptr, data_size size_t, rgba uintptr, stride int32, size size_t) (r uintptr) {
  15131 	bp := tls.Alloc(240)
  15132 	defer tls.Free(240)
  15133 	var v1 int32
  15134 	var v3 bool
  15135 	var _ /* buf at bp+112 */ WebPDecBuffer
  15136 	var _ /* params at bp+0 */ WebPDecParams
  15137 	_, _ = v1, v3
  15138 	if v3 = rgba == libc.UintptrFromInt32(0); !v3 {
  15139 		v1 = WebPInitDecBufferInternal(tls, bp+112, int32(WEBP_DECODER_ABI_VERSION))
  15140 		goto _2
  15141 	_2:
  15142 	}
  15143 	if v3 || !(v1 != 0) {
  15144 		return libc.UintptrFromInt32(0)
  15145 	}
  15146 	WebPResetDecParams(tls, bp)
  15147 	(**(**WebPDecParams)(__ccgo_up(bp))).Foutput = bp + 112
  15148 	(**(**WebPDecBuffer)(__ccgo_up(bp + 112))).Fcolorspace = colorspace
  15149 	*(*uintptr)(unsafe.Pointer(bp + 112 + 16)) = rgba
  15150 	*(*int32)(unsafe.Pointer(bp + 112 + 16 + 8)) = stride
  15151 	*(*size_t)(unsafe.Pointer(bp + 112 + 16 + 16)) = size
  15152 	(**(**WebPDecBuffer)(__ccgo_up(bp + 112))).Fis_external_memory = int32(1)
  15153 	if DecodeInto(tls, data, data_size, bp) != int32(VP8_STATUS_OK) {
  15154 		return libc.UintptrFromInt32(0)
  15155 	}
  15156 	return rgba
  15157 }
  15158 
  15159 func WebPDecodeRGBInto(tls *libc.TLS, data uintptr, data_size size_t, output uintptr, size size_t, stride int32) (r uintptr) {
  15160 	return DecodeIntoRGBABuffer(tls, int32(MODE_RGB), data, data_size, output, stride, size)
  15161 }
  15162 
  15163 func WebPDecodeRGBAInto(tls *libc.TLS, data uintptr, data_size size_t, output uintptr, size size_t, stride int32) (r uintptr) {
  15164 	return DecodeIntoRGBABuffer(tls, int32(MODE_RGBA), data, data_size, output, stride, size)
  15165 }
  15166 
  15167 func WebPDecodeARGBInto(tls *libc.TLS, data uintptr, data_size size_t, output uintptr, size size_t, stride int32) (r uintptr) {
  15168 	return DecodeIntoRGBABuffer(tls, int32(MODE_ARGB), data, data_size, output, stride, size)
  15169 }
  15170 
  15171 func WebPDecodeBGRInto(tls *libc.TLS, data uintptr, data_size size_t, output uintptr, size size_t, stride int32) (r uintptr) {
  15172 	return DecodeIntoRGBABuffer(tls, int32(MODE_BGR), data, data_size, output, stride, size)
  15173 }
  15174 
  15175 func WebPDecodeBGRAInto(tls *libc.TLS, data uintptr, data_size size_t, output uintptr, size size_t, stride int32) (r uintptr) {
  15176 	return DecodeIntoRGBABuffer(tls, int32(MODE_BGRA), data, data_size, output, stride, size)
  15177 }
  15178 
  15179 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) {
  15180 	bp := tls.Alloc(240)
  15181 	defer tls.Free(240)
  15182 	var v1 int32
  15183 	var v3 bool
  15184 	var _ /* output at bp+112 */ WebPDecBuffer
  15185 	var _ /* params at bp+0 */ WebPDecParams
  15186 	_, _ = v1, v3
  15187 	if v3 = luma == libc.UintptrFromInt32(0); !v3 {
  15188 		v1 = WebPInitDecBufferInternal(tls, bp+112, int32(WEBP_DECODER_ABI_VERSION))
  15189 		goto _2
  15190 	_2:
  15191 	}
  15192 	if v3 || !(v1 != 0) {
  15193 		return libc.UintptrFromInt32(0)
  15194 	}
  15195 	WebPResetDecParams(tls, bp)
  15196 	(**(**WebPDecParams)(__ccgo_up(bp))).Foutput = bp + 112
  15197 	(**(**WebPDecBuffer)(__ccgo_up(bp + 112))).Fcolorspace = int32(MODE_YUV)
  15198 	*(*uintptr)(unsafe.Pointer(bp + 112 + 16)) = luma
  15199 	*(*int32)(unsafe.Pointer(bp + 112 + 16 + 32)) = luma_stride
  15200 	*(*size_t)(unsafe.Pointer(bp + 112 + 16 + 48)) = luma_size
  15201 	*(*uintptr)(unsafe.Pointer(bp + 112 + 16 + 8)) = u
  15202 	*(*int32)(unsafe.Pointer(bp + 112 + 16 + 36)) = u_stride
  15203 	*(*size_t)(unsafe.Pointer(bp + 112 + 16 + 56)) = u_size
  15204 	*(*uintptr)(unsafe.Pointer(bp + 112 + 16 + 16)) = v
  15205 	*(*int32)(unsafe.Pointer(bp + 112 + 16 + 40)) = v_stride
  15206 	*(*size_t)(unsafe.Pointer(bp + 112 + 16 + 64)) = v_size
  15207 	(**(**WebPDecBuffer)(__ccgo_up(bp + 112))).Fis_external_memory = int32(1)
  15208 	if DecodeInto(tls, data, data_size, bp) != int32(VP8_STATUS_OK) {
  15209 		return libc.UintptrFromInt32(0)
  15210 	}
  15211 	return luma
  15212 }
  15213 
  15214 // ------------------------------------------------------------------------------
  15215 func Decode(tls *libc.TLS, mode1 WEBP_CSP_MODE1, data uintptr, data_size size_t, width uintptr, height uintptr, keep_info uintptr) (r uintptr) {
  15216 	bp := tls.Alloc(240)
  15217 	defer tls.Free(240)
  15218 	var v1 int32
  15219 	var v3 uintptr
  15220 	var _ /* output at bp+112 */ WebPDecBuffer
  15221 	var _ /* params at bp+0 */ WebPDecParams
  15222 	_, _ = v1, v3
  15223 	v1 = WebPInitDecBufferInternal(tls, bp+112, int32(WEBP_DECODER_ABI_VERSION))
  15224 	goto _2
  15225 _2:
  15226 	if !(v1 != 0) {
  15227 		return libc.UintptrFromInt32(0)
  15228 	}
  15229 	WebPResetDecParams(tls, bp)
  15230 	(**(**WebPDecParams)(__ccgo_up(bp))).Foutput = bp + 112
  15231 	(**(**WebPDecBuffer)(__ccgo_up(bp + 112))).Fcolorspace = mode1
  15232 	// Retrieve (and report back) the required dimensions from bitstream.
  15233 	if !(WebPGetInfo(tls, data, data_size, bp+112+4, bp+112+8) != 0) {
  15234 		return libc.UintptrFromInt32(0)
  15235 	}
  15236 	if width != libc.UintptrFromInt32(0) {
  15237 		**(**int32)(__ccgo_up(width)) = (**(**WebPDecBuffer)(__ccgo_up(bp + 112))).Fwidth
  15238 	}
  15239 	if height != libc.UintptrFromInt32(0) {
  15240 		**(**int32)(__ccgo_up(height)) = (**(**WebPDecBuffer)(__ccgo_up(bp + 112))).Fheight
  15241 	}
  15242 	// Decode
  15243 	if DecodeInto(tls, data, data_size, bp) != int32(VP8_STATUS_OK) {
  15244 		return libc.UintptrFromInt32(0)
  15245 	}
  15246 	if keep_info != libc.UintptrFromInt32(0) { // keep track of the side-info
  15247 		WebPCopyDecBuffer(tls, bp+112, keep_info)
  15248 	}
  15249 	// return decoded samples (don't clear 'output'!)
  15250 	v1 = libc.BoolInt32(mode1 < int32(MODE_YUV))
  15251 	goto _5
  15252 _5:
  15253 	if v1 != 0 {
  15254 		v3 = *(*uintptr)(unsafe.Pointer(bp + 112 + 16))
  15255 	} else {
  15256 		v3 = *(*uintptr)(unsafe.Pointer(bp + 112 + 16))
  15257 	}
  15258 	return v3
  15259 }
  15260 
  15261 func WebPDecodeRGB(tls *libc.TLS, data uintptr, data_size size_t, width uintptr, height uintptr) (r uintptr) {
  15262 	return Decode(tls, int32(MODE_RGB), data, data_size, width, height, libc.UintptrFromInt32(0))
  15263 }
  15264 
  15265 func WebPDecodeRGBA(tls *libc.TLS, data uintptr, data_size size_t, width uintptr, height uintptr) (r uintptr) {
  15266 	return Decode(tls, int32(MODE_RGBA), data, data_size, width, height, libc.UintptrFromInt32(0))
  15267 }
  15268 
  15269 func WebPDecodeARGB(tls *libc.TLS, data uintptr, data_size size_t, width uintptr, height uintptr) (r uintptr) {
  15270 	return Decode(tls, int32(MODE_ARGB), data, data_size, width, height, libc.UintptrFromInt32(0))
  15271 }
  15272 
  15273 func WebPDecodeBGR(tls *libc.TLS, data uintptr, data_size size_t, width uintptr, height uintptr) (r uintptr) {
  15274 	return Decode(tls, int32(MODE_BGR), data, data_size, width, height, libc.UintptrFromInt32(0))
  15275 }
  15276 
  15277 func WebPDecodeBGRA(tls *libc.TLS, data uintptr, data_size size_t, width uintptr, height uintptr) (r uintptr) {
  15278 	return Decode(tls, int32(MODE_BGRA), data, data_size, width, height, libc.UintptrFromInt32(0))
  15279 }
  15280 
  15281 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) {
  15282 	bp := tls.Alloc(128)
  15283 	defer tls.Free(128)
  15284 	var buf, out uintptr
  15285 	var _ /* output at bp+0 */ WebPDecBuffer
  15286 	_, _ = buf, out
  15287 	// data, width and height are checked by Decode().
  15288 	if u == libc.UintptrFromInt32(0) || v == libc.UintptrFromInt32(0) || stride == libc.UintptrFromInt32(0) || uv_stride == libc.UintptrFromInt32(0) {
  15289 		return libc.UintptrFromInt32(0)
  15290 	}
  15291 	// only to preserve the side-infos
  15292 	out = Decode(tls, int32(MODE_YUV), data, data_size, width, height, bp)
  15293 	if out != libc.UintptrFromInt32(0) {
  15294 		buf = bp + 16
  15295 		**(**uintptr)(__ccgo_up(u)) = (*WebPYUVABuffer)(unsafe.Pointer(buf)).Fu
  15296 		**(**uintptr)(__ccgo_up(v)) = (*WebPYUVABuffer)(unsafe.Pointer(buf)).Fv
  15297 		**(**int32)(__ccgo_up(stride)) = (*WebPYUVABuffer)(unsafe.Pointer(buf)).Fy_stride
  15298 		**(**int32)(__ccgo_up(uv_stride)) = (*WebPYUVABuffer)(unsafe.Pointer(buf)).Fu_stride
  15299 	}
  15300 	return out
  15301 	return r
  15302 }
  15303 
  15304 func DefaultFeatures(tls *libc.TLS, features uintptr) {
  15305 	libc.Xmemset(tls, features, 0, uint64(40))
  15306 }
  15307 
  15308 func GetFeatures(tls *libc.TLS, data uintptr, data_size size_t, features uintptr) (r VP8StatusCode1) {
  15309 	if features == libc.UintptrFromInt32(0) || data == libc.UintptrFromInt32(0) {
  15310 		return int32(VP8_STATUS_INVALID_PARAM)
  15311 	}
  15312 	DefaultFeatures(tls, features)
  15313 	// Only parse enough of the data to retrieve the features.
  15314 	return ParseHeadersInternal(tls, data, data_size, features, features+4, features+8, features+12, features+16, libc.UintptrFromInt32(0))
  15315 }
  15316 
  15317 //------------------------------------------------------------------------------
  15318 // WebPGetInfo()
  15319 
  15320 func WebPGetInfo(tls *libc.TLS, data uintptr, data_size size_t, width uintptr, height uintptr) (r int32) {
  15321 	bp := tls.Alloc(48)
  15322 	defer tls.Free(48)
  15323 	var _ /* features at bp+0 */ WebPBitstreamFeatures
  15324 	if GetFeatures(tls, data, data_size, bp) != int32(VP8_STATUS_OK) {
  15325 		return 0
  15326 	}
  15327 	if width != libc.UintptrFromInt32(0) {
  15328 		**(**int32)(__ccgo_up(width)) = (**(**WebPBitstreamFeatures)(__ccgo_up(bp))).Fwidth
  15329 	}
  15330 	if height != libc.UintptrFromInt32(0) {
  15331 		**(**int32)(__ccgo_up(height)) = (**(**WebPBitstreamFeatures)(__ccgo_up(bp))).Fheight
  15332 	}
  15333 	return int32(1)
  15334 }
  15335 
  15336 //------------------------------------------------------------------------------
  15337 // Advance decoding API
  15338 
  15339 func WebPInitDecoderConfigInternal(tls *libc.TLS, config uintptr, version int32) (r int32) {
  15340 	var v1 int32
  15341 	_ = v1
  15342 	if version>>int32(8) != libc.Int32FromInt32(WEBP_DECODER_ABI_VERSION)>>libc.Int32FromInt32(8) {
  15343 		return 0 // version mismatch
  15344 	}
  15345 	if config == libc.UintptrFromInt32(0) {
  15346 		return 0
  15347 	}
  15348 	libc.Xmemset(tls, config, 0, uint64(240))
  15349 	DefaultFeatures(tls, config)
  15350 	v1 = WebPInitDecBufferInternal(tls, config+40, int32(WEBP_DECODER_ABI_VERSION))
  15351 	goto _2
  15352 _2:
  15353 	if !(v1 != 0) {
  15354 		return 0
  15355 	}
  15356 	return int32(1)
  15357 }
  15358 
  15359 func WebPCheckCropDimensionsBasic(tls *libc.TLS, x int32, y int32, w int32, h int32) (r int32) {
  15360 	return libc.BoolInt32(!(x < 0 || y < 0 || w <= 0 || h <= 0))
  15361 }
  15362 
  15363 func WebPValidateDecoderConfig(tls *libc.TLS, config uintptr) (r int32) {
  15364 	bp := tls.Alloc(16)
  15365 	defer tls.Free(16)
  15366 	var options uintptr
  15367 	var _ /* scaled_height at bp+4 */ int32
  15368 	var _ /* scaled_width at bp+0 */ int32
  15369 	_ = options
  15370 	if config == libc.UintptrFromInt32(0) {
  15371 		return 0
  15372 	}
  15373 	if !(IsValidColorspace(tls, (*WebPDecoderConfig)(unsafe.Pointer(config)).Foutput.Fcolorspace) != 0) {
  15374 		return 0
  15375 	}
  15376 	options = config + 160
  15377 	// bypass_filtering, no_fancy_upsampling, use_cropping, use_scaling,
  15378 	// use_threads, flip can be any integer and are interpreted as boolean.
  15379 	// Check for cropping.
  15380 	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) {
  15381 		return 0
  15382 	}
  15383 	// Check for scaling.
  15384 	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) {
  15385 		return 0
  15386 	}
  15387 	// In case the WebPBitstreamFeatures has been filled in, check further.
  15388 	if (*WebPDecoderConfig)(unsafe.Pointer(config)).Finput.Fwidth > 0 || (*WebPDecoderConfig)(unsafe.Pointer(config)).Finput.Fheight > 0 {
  15389 		**(**int32)(__ccgo_up(bp)) = (*WebPDecoderOptions)(unsafe.Pointer(options)).Fscaled_width
  15390 		**(**int32)(__ccgo_up(bp + 4)) = (*WebPDecoderOptions)(unsafe.Pointer(options)).Fscaled_height
  15391 		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) {
  15392 			return 0
  15393 		}
  15394 		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) {
  15395 			return 0
  15396 		}
  15397 	}
  15398 	// Check for dithering.
  15399 	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) {
  15400 		return 0
  15401 	}
  15402 	return int32(1)
  15403 }
  15404 
  15405 func WebPGetFeaturesInternal(tls *libc.TLS, data uintptr, data_size size_t, features uintptr, version int32) (r VP8StatusCode1) {
  15406 	if version>>int32(8) != libc.Int32FromInt32(WEBP_DECODER_ABI_VERSION)>>libc.Int32FromInt32(8) {
  15407 		return int32(VP8_STATUS_INVALID_PARAM) // version mismatch
  15408 	}
  15409 	if features == libc.UintptrFromInt32(0) {
  15410 		return int32(VP8_STATUS_INVALID_PARAM)
  15411 	}
  15412 	return GetFeatures(tls, data, data_size, features)
  15413 }
  15414 
  15415 func WebPDecode(tls *libc.TLS, data uintptr, data_size size_t, config uintptr) (r VP8StatusCode1) {
  15416 	bp := tls.Alloc(240)
  15417 	defer tls.Free(240)
  15418 	var status VP8StatusCode1
  15419 	var v1 int32
  15420 	var _ /* in_mem_buffer at bp+112 */ WebPDecBuffer
  15421 	var _ /* params at bp+0 */ WebPDecParams
  15422 	_, _ = status, v1
  15423 	if config == libc.UintptrFromInt32(0) {
  15424 		return int32(VP8_STATUS_INVALID_PARAM)
  15425 	}
  15426 	status = GetFeatures(tls, data, data_size, config)
  15427 	if status != int32(VP8_STATUS_OK) {
  15428 		if status == int32(VP8_STATUS_NOT_ENOUGH_DATA) {
  15429 			return int32(VP8_STATUS_BITSTREAM_ERROR) // Not-enough-data treated as error.
  15430 		}
  15431 		return status
  15432 	}
  15433 	WebPResetDecParams(tls, bp)
  15434 	(**(**WebPDecParams)(__ccgo_up(bp))).Foptions = config + 160
  15435 	(**(**WebPDecParams)(__ccgo_up(bp))).Foutput = config + 40
  15436 	if WebPAvoidSlowMemory(tls, (**(**WebPDecParams)(__ccgo_up(bp))).Foutput, config) != 0 {
  15437 		v1 = WebPInitDecBufferInternal(tls, bp+112, int32(WEBP_DECODER_ABI_VERSION))
  15438 		goto _2
  15439 	_2:
  15440 		if !(v1 != 0) {
  15441 			return int32(VP8_STATUS_INVALID_PARAM)
  15442 		}
  15443 		(**(**WebPDecBuffer)(__ccgo_up(bp + 112))).Fcolorspace = (*WebPDecoderConfig)(unsafe.Pointer(config)).Foutput.Fcolorspace
  15444 		(**(**WebPDecBuffer)(__ccgo_up(bp + 112))).Fwidth = (*WebPDecoderConfig)(unsafe.Pointer(config)).Finput.Fwidth
  15445 		(**(**WebPDecBuffer)(__ccgo_up(bp + 112))).Fheight = (*WebPDecoderConfig)(unsafe.Pointer(config)).Finput.Fheight
  15446 		(**(**WebPDecParams)(__ccgo_up(bp))).Foutput = bp + 112
  15447 		status = DecodeInto(tls, data, data_size, bp)
  15448 		if status == int32(VP8_STATUS_OK) { // do the slow-copy
  15449 			status = WebPCopyDecBufferPixels(tls, bp+112, config+40)
  15450 		}
  15451 		WebPFreeDecBuffer(tls, bp+112)
  15452 	} else {
  15453 		status = DecodeInto(tls, data, data_size, bp)
  15454 	}
  15455 	return status
  15456 }
  15457 
  15458 //------------------------------------------------------------------------------
  15459 // Cropping and rescaling.
  15460 
  15461 func WebPCheckCropDimensions(tls *libc.TLS, image_width int32, image_height int32, x int32, y int32, w int32, h int32) (r int32) {
  15462 	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))
  15463 }
  15464 
  15465 func WebPIoInitFromOptions(tls *libc.TLS, options uintptr, io uintptr, src_colorspace WEBP_CSP_MODE1) (r int32) {
  15466 	bp := tls.Alloc(16)
  15467 	defer tls.Free(16)
  15468 	var H, W, h, w, x, y, v1 int32
  15469 	var _ /* scaled_height at bp+4 */ int32
  15470 	var _ /* scaled_width at bp+0 */ int32
  15471 	_, _, _, _, _, _, _ = H, W, h, w, x, y, v1
  15472 	W = (*VP8Io)(unsafe.Pointer(io)).Fwidth
  15473 	H = (*VP8Io)(unsafe.Pointer(io)).Fheight
  15474 	x = 0
  15475 	y = 0
  15476 	w = W
  15477 	h = H
  15478 	// Cropping
  15479 	(*VP8Io)(unsafe.Pointer(io)).Fuse_cropping = libc.BoolInt32(options != libc.UintptrFromInt32(0) && (*WebPDecoderOptions)(unsafe.Pointer(options)).Fuse_cropping != 0)
  15480 	if (*VP8Io)(unsafe.Pointer(io)).Fuse_cropping != 0 {
  15481 		w = (*WebPDecoderOptions)(unsafe.Pointer(options)).Fcrop_width
  15482 		h = (*WebPDecoderOptions)(unsafe.Pointer(options)).Fcrop_height
  15483 		x = (*WebPDecoderOptions)(unsafe.Pointer(options)).Fcrop_left
  15484 		y = (*WebPDecoderOptions)(unsafe.Pointer(options)).Fcrop_top
  15485 		v1 = libc.BoolInt32(src_colorspace < int32(MODE_YUV))
  15486 		goto _2
  15487 	_2:
  15488 		if !(v1 != 0) { // only snap for YUV420
  15489 			x = x & ^libc.Int32FromInt32(1)
  15490 			y = y & ^libc.Int32FromInt32(1)
  15491 		}
  15492 		if !(WebPCheckCropDimensions(tls, W, H, x, y, w, h) != 0) {
  15493 			return 0 // out of frame boundary error
  15494 		}
  15495 	}
  15496 	(*VP8Io)(unsafe.Pointer(io)).Fcrop_left = x
  15497 	(*VP8Io)(unsafe.Pointer(io)).Fcrop_top = y
  15498 	(*VP8Io)(unsafe.Pointer(io)).Fcrop_right = x + w
  15499 	(*VP8Io)(unsafe.Pointer(io)).Fcrop_bottom = y + h
  15500 	(*VP8Io)(unsafe.Pointer(io)).Fmb_w = w
  15501 	(*VP8Io)(unsafe.Pointer(io)).Fmb_h = h
  15502 	// Scaling
  15503 	(*VP8Io)(unsafe.Pointer(io)).Fuse_scaling = libc.BoolInt32(options != libc.UintptrFromInt32(0) && (*WebPDecoderOptions)(unsafe.Pointer(options)).Fuse_scaling != 0)
  15504 	if (*VP8Io)(unsafe.Pointer(io)).Fuse_scaling != 0 {
  15505 		**(**int32)(__ccgo_up(bp)) = (*WebPDecoderOptions)(unsafe.Pointer(options)).Fscaled_width
  15506 		**(**int32)(__ccgo_up(bp + 4)) = (*WebPDecoderOptions)(unsafe.Pointer(options)).Fscaled_height
  15507 		if !(WebPRescalerGetScaledDimensions(tls, w, h, bp, bp+4) != 0) {
  15508 			return 0
  15509 		}
  15510 		(*VP8Io)(unsafe.Pointer(io)).Fscaled_width = **(**int32)(__ccgo_up(bp))
  15511 		(*VP8Io)(unsafe.Pointer(io)).Fscaled_height = **(**int32)(__ccgo_up(bp + 4))
  15512 	}
  15513 	// Filter
  15514 	(*VP8Io)(unsafe.Pointer(io)).Fbypass_filtering = libc.BoolInt32(options != libc.UintptrFromInt32(0) && (*WebPDecoderOptions)(unsafe.Pointer(options)).Fbypass_filtering != 0)
  15515 	// Fancy upsampler
  15516 	(*VP8Io)(unsafe.Pointer(io)).Ffancy_upsampling = libc.BoolInt32(options == libc.UintptrFromInt32(0) || !((*WebPDecoderOptions)(unsafe.Pointer(options)).Fno_fancy_upsampling != 0))
  15517 	if (*VP8Io)(unsafe.Pointer(io)).Fuse_scaling != 0 {
  15518 		// disable filter (only for large downscaling ratio).
  15519 		**(**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))
  15520 		(*VP8Io)(unsafe.Pointer(io)).Ffancy_upsampling = 0
  15521 	}
  15522 	return int32(1)
  15523 }
  15524 
  15525 const ENC_MAJ_VERSION = 1
  15526 const ENC_MIN_VERSION = 6
  15527 const ENC_REV_VERSION = 0
  15528 const ERROR_DIFFUSION_QUALITY = 98
  15529 const HASH_BITS = 18
  15530 const MAX_COLOR_CACHE_BITS = 10
  15531 const MAX_LENGTH_BITS = 12
  15532 const MAX_REFS_BLOCK_PER_IMAGE = 16
  15533 const QFIX = 17
  15534 const U_OFF_ENC = 16
  15535 const VP8L_WRITER_BITS = 32
  15536 const VP8L_WRITER_BYTES = 4
  15537 const VP8L_WRITER_MAX_BITS = 64
  15538 const WEBP_ENCODER_ABI_VERSION = 528
  15539 const WEBP_MAX_DIMENSION = 16383
  15540 const WEBP_NEAR_LOSSLESS = 1
  15541 const WINDOW_SIZE_BITS = 20
  15542 const WSWAP = "HToLE32"
  15543 const Y_OFF_ENC = 0
  15544 
  15545 type VP8Matrix = struct {
  15546 	Fq       [16]uint16_t
  15547 	Fiq      [16]uint16_t
  15548 	Fbias    [16]uint32_t
  15549 	Fzthresh [16]uint32_t
  15550 	Fsharpen [16]uint16_t
  15551 }
  15552 
  15553 type VP8BitWriter = struct {
  15554 	Frange1  int32_t
  15555 	Fvalue   int32_t
  15556 	Frun     int32
  15557 	Fnb_bits int32
  15558 	Fbuf     uintptr
  15559 	Fpos     size_t
  15560 	Fmax_pos size_t
  15561 	Ferror1  int32
  15562 }
  15563 
  15564 type vp8l_atype_t = uint64
  15565 
  15566 type vp8l_wtype_t = uint32
  15567 
  15568 type VP8LBitWriter = struct {
  15569 	Fbits   vp8l_atype_t
  15570 	Fused   int32
  15571 	Fbuf    uintptr
  15572 	Fcur    uintptr
  15573 	Fend    uintptr
  15574 	Ferror1 int32
  15575 }
  15576 
  15577 type WebPPicture = struct {
  15578 	Fuse_argb        int32
  15579 	Fcolorspace      WebPEncCSP1
  15580 	Fwidth           int32
  15581 	Fheight          int32
  15582 	Fy               uintptr
  15583 	Fu               uintptr
  15584 	Fv               uintptr
  15585 	Fy_stride        int32
  15586 	Fuv_stride       int32
  15587 	Fa               uintptr
  15588 	Fa_stride        int32
  15589 	Fpad1            [2]uint32_t
  15590 	Fargb            uintptr
  15591 	Fargb_stride     int32
  15592 	Fpad2            [3]uint32_t
  15593 	Fwriter          WebPWriterFunction
  15594 	Fcustom_ptr      uintptr
  15595 	Fextra_info_type int32
  15596 	Fextra_info      uintptr
  15597 	Fstats           uintptr
  15598 	Ferror_code      WebPEncodingError1
  15599 	Fprogress_hook   WebPProgressHook
  15600 	Fuser_data       uintptr
  15601 	Fpad3            [3]uint32_t
  15602 	Fpad4            uintptr
  15603 	Fpad5            uintptr
  15604 	Fpad6            [8]uint32_t
  15605 	Fmemory_         uintptr
  15606 	Fmemory_argb_    uintptr
  15607 	Fpad7            [2]uintptr
  15608 }
  15609 
  15610 type WebPEncCSP = int32
  15611 
  15612 const WEBP_YUV420 = 0
  15613 const WEBP_YUV420A = 4
  15614 const WEBP_CSP_UV_MASK = 3
  15615 const WEBP_CSP_ALPHA_BIT = 4
  15616 
  15617 type WebPEncodingError = int32
  15618 
  15619 const VP8_ENC_OK = 0
  15620 const VP8_ENC_ERROR_OUT_OF_MEMORY = 1
  15621 const VP8_ENC_ERROR_BITSTREAM_OUT_OF_MEMORY = 2
  15622 const VP8_ENC_ERROR_NULL_PARAMETER = 3
  15623 const VP8_ENC_ERROR_INVALID_CONFIGURATION = 4
  15624 const VP8_ENC_ERROR_BAD_DIMENSION = 5
  15625 const VP8_ENC_ERROR_PARTITION0_OVERFLOW = 6
  15626 const VP8_ENC_ERROR_PARTITION_OVERFLOW = 7
  15627 const VP8_ENC_ERROR_BAD_WRITE = 8
  15628 const VP8_ENC_ERROR_FILE_TOO_BIG = 9
  15629 const VP8_ENC_ERROR_USER_ABORT = 10
  15630 const VP8_ENC_ERROR_LAST = 11
  15631 
  15632 type WebPConfig = struct {
  15633 	Flossless          int32
  15634 	Fquality           float32
  15635 	Fmethod            int32
  15636 	Fimage_hint        WebPImageHint1
  15637 	Ftarget_size       int32
  15638 	Ftarget_PSNR       float32
  15639 	Fsegments          int32
  15640 	Fsns_strength      int32
  15641 	Ffilter_strength   int32
  15642 	Ffilter_sharpness  int32
  15643 	Ffilter_type       int32
  15644 	Fautofilter        int32
  15645 	Falpha_compression int32
  15646 	Falpha_filtering   int32
  15647 	Falpha_quality     int32
  15648 	Fpass              int32
  15649 	Fshow_compressed   int32
  15650 	Fpreprocessing     int32
  15651 	Fpartitions        int32
  15652 	Fpartition_limit   int32
  15653 	Femulate_jpeg_size int32
  15654 	Fthread_level      int32
  15655 	Flow_memory        int32
  15656 	Fnear_lossless     int32
  15657 	Fexact             int32
  15658 	Fuse_delta_palette int32
  15659 	Fuse_sharp_yuv     int32
  15660 	Fqmin              int32
  15661 	Fqmax              int32
  15662 }
  15663 
  15664 type WebPImageHint = int32
  15665 
  15666 const WEBP_HINT_DEFAULT = 0
  15667 const WEBP_HINT_PICTURE = 1
  15668 const WEBP_HINT_PHOTO = 2
  15669 const WEBP_HINT_GRAPH = 3
  15670 const WEBP_HINT_LAST = 4
  15671 
  15672 type WebPAuxStats = struct {
  15673 	Fcoded_size                 int32
  15674 	FPSNR                       [5]float32
  15675 	Fblock_count                [3]int32
  15676 	Fheader_bytes               [2]int32
  15677 	Fresidual_bytes             [3][4]int32
  15678 	Fsegment_size               [4]int32
  15679 	Fsegment_quant              [4]int32
  15680 	Fsegment_level              [4]int32
  15681 	Falpha_data_size            int32
  15682 	Flayer_data_size            int32
  15683 	Flossless_features          uint32_t
  15684 	Fhistogram_bits             int32
  15685 	Ftransform_bits             int32
  15686 	Fcache_bits                 int32
  15687 	Fpalette_size               int32
  15688 	Flossless_size              int32
  15689 	Flossless_hdr_size          int32
  15690 	Flossless_data_size         int32
  15691 	Fcross_color_transform_bits int32
  15692 	Fpad                        [1]uint32_t
  15693 }
  15694 
  15695 type WebPMemoryWriter = struct {
  15696 	Fmem      uintptr
  15697 	Fsize     size_t
  15698 	Fmax_size size_t
  15699 	Fpad      [1]uint32_t
  15700 }
  15701 
  15702 type WebPImageHint1 = int32
  15703 
  15704 type WebPPreset1 = int32
  15705 
  15706 type WebPPreset = int32
  15707 
  15708 const WEBP_PRESET_DEFAULT = 0
  15709 const WEBP_PRESET_PICTURE = 1
  15710 const WEBP_PRESET_PHOTO = 2
  15711 const WEBP_PRESET_DRAWING = 3
  15712 const WEBP_PRESET_ICON = 4
  15713 const WEBP_PRESET_TEXT = 5
  15714 
  15715 type WebPWriterFunction = uintptr
  15716 
  15717 type WebPProgressHook = uintptr
  15718 
  15719 type WebPEncCSP1 = int32
  15720 
  15721 type WebPEncodingError1 = int32
  15722 
  15723 const MAX_LF_LEVELS = 64
  15724 const MAX_VARIABLE_LEVEL = 67
  15725 const MAX_LEVEL = 2047
  15726 
  15727 type VP8RDLevel = int32
  15728 
  15729 const RD_OPT_NONE = 0
  15730 const RD_OPT_BASIC = 1
  15731 const RD_OPT_TRELLIS = 2
  15732 const RD_OPT_TRELLIS_ALL = 3
  15733 
  15734 type score_t = int64
  15735 
  15736 type proba_t = uint32
  15737 
  15738 type ProbaArray = [3][11]uint8_t
  15739 
  15740 type StatsArray = [3][11]proba_t
  15741 
  15742 type CostArray = [3][68]uint16_t
  15743 
  15744 type CostArrayPtr = uintptr
  15745 
  15746 type CostArrayMap = [16][3]uintptr
  15747 
  15748 type LFStats = [4][64]float64
  15749 
  15750 type VP8Encoder = struct {
  15751 	Fconfig             uintptr
  15752 	Fpic                uintptr
  15753 	Ffilter_hdr         VP8EncFilterHeader
  15754 	Fsegment_hdr        VP8EncSegmentHeader
  15755 	Fprofile            int32
  15756 	Fmb_w               int32
  15757 	Fmb_h               int32
  15758 	Fpreds_w            int32
  15759 	Fnum_parts          int32
  15760 	Fbw                 VP8BitWriter
  15761 	Fparts              [8]VP8BitWriter
  15762 	Ftokens             VP8TBuffer
  15763 	Fpercent            int32
  15764 	Fhas_alpha          int32
  15765 	Falpha_data         uintptr
  15766 	Falpha_data_size    uint32_t
  15767 	Falpha_worker       WebPWorker
  15768 	Fdqm                [4]VP8SegmentInfo
  15769 	Fbase_quant         int32
  15770 	Falpha              int32
  15771 	Fuv_alpha           int32
  15772 	Fdq_y1_dc           int32
  15773 	Fdq_y2_dc           int32
  15774 	Fdq_y2_ac           int32
  15775 	Fdq_uv_dc           int32
  15776 	Fdq_uv_ac           int32
  15777 	Fproba              VP8EncProba
  15778 	Fsse                [4]uint64_t
  15779 	Fsse_count          uint64_t
  15780 	Fcoded_size         int32
  15781 	Fresidual_bytes     [3][4]int32
  15782 	Fblock_count        [3]int32
  15783 	Fmethod             int32
  15784 	Frd_opt_level       VP8RDLevel
  15785 	Fmax_i4_header_bits int32
  15786 	Fmb_header_limit    int32
  15787 	Fthread_level       int32
  15788 	Fdo_search          int32
  15789 	Fuse_tokens         int32
  15790 	Fmb_info            uintptr
  15791 	Fpreds              uintptr
  15792 	Fnz                 uintptr
  15793 	Fy_top              uintptr
  15794 	Fuv_top             uintptr
  15795 	Flf_stats           uintptr
  15796 	Ftop_derr           uintptr
  15797 }
  15798 
  15799 type VP8EncSegmentHeader = struct {
  15800 	Fnum_segments int32
  15801 	Fupdate_map   int32
  15802 	Fsize         int32
  15803 }
  15804 
  15805 type VP8EncProba = struct {
  15806 	Fsegments       [3]uint8_t
  15807 	Fskip_proba     uint8_t
  15808 	Fcoeffs         [4][8]ProbaArray
  15809 	Fstats          [4][8]StatsArray
  15810 	Flevel_cost     [4][8]CostArray
  15811 	Fremapped_costs [4]CostArrayMap
  15812 	Fdirty          int32
  15813 	Fuse_skip_proba int32
  15814 	Fnb_skip        int32
  15815 }
  15816 
  15817 type VP8EncFilterHeader = struct {
  15818 	Fsimple        int32
  15819 	Flevel         int32
  15820 	Fsharpness     int32
  15821 	Fi4x4_lf_delta int32
  15822 }
  15823 
  15824 type VP8MBInfo = struct {
  15825 	F__ccgo_align [0]uint32
  15826 	F__ccgo0      uint8
  15827 	Falpha        uint8_t
  15828 }
  15829 
  15830 type VP8SegmentInfo = struct {
  15831 	Fy1                 VP8Matrix
  15832 	Fy2                 VP8Matrix
  15833 	Fuv                 VP8Matrix
  15834 	Falpha              int32
  15835 	Fbeta               int32
  15836 	Fquant              int32
  15837 	Ffstrength          int32
  15838 	Fmax_edge           int32
  15839 	Fmin_disto          int32
  15840 	Flambda_i16         int32
  15841 	Flambda_i4          int32
  15842 	Flambda_uv          int32
  15843 	Flambda_mode        int32
  15844 	Flambda_trellis     int32
  15845 	Ftlambda            int32
  15846 	Flambda_trellis_i16 int32
  15847 	Flambda_trellis_i4  int32
  15848 	Flambda_trellis_uv  int32
  15849 	Fi4_penalty         score_t
  15850 }
  15851 
  15852 type DError = [2][2]int8_t
  15853 
  15854 type VP8ModeScore = struct {
  15855 	FD           score_t
  15856 	FSD          score_t
  15857 	FH           score_t
  15858 	FR           score_t
  15859 	Fscore       score_t
  15860 	Fy_dc_levels [16]int16_t
  15861 	Fy_ac_levels [16][16]int16_t
  15862 	Fuv_levels   [8][16]int16_t
  15863 	Fmode_i16    int32
  15864 	Fmodes_i4    [16]uint8_t
  15865 	Fmode_uv     int32
  15866 	Fnz          uint32_t
  15867 	Fderr        [2][3]int8_t
  15868 }
  15869 
  15870 type VP8EncIterator = struct {
  15871 	Fx            int32
  15872 	Fy            int32
  15873 	Fyuv_in       uintptr
  15874 	Fyuv_out      uintptr
  15875 	Fyuv_out2     uintptr
  15876 	Fyuv_p        uintptr
  15877 	Fenc          uintptr
  15878 	Fmb           uintptr
  15879 	Fbw           uintptr
  15880 	Fpreds        uintptr
  15881 	Fnz           uintptr
  15882 	Fi4_boundary  [37]uint8_t
  15883 	Fi4_top       uintptr
  15884 	Fi4           int32
  15885 	Ftop_nz       [9]int32
  15886 	Fleft_nz      [9]int32
  15887 	Fbit_count    [4][3]uint64_t
  15888 	Fluma_bits    uint64_t
  15889 	Fuv_bits      uint64_t
  15890 	Flf_stats     uintptr
  15891 	Fdo_trellis   int32
  15892 	Fcount_down   int32
  15893 	Fcount_down0  int32
  15894 	Fpercent0     int32
  15895 	Fleft_derr    DError
  15896 	Ftop_derr     uintptr
  15897 	Fy_left       uintptr
  15898 	Fu_left       uintptr
  15899 	Fv_left       uintptr
  15900 	Fy_top        uintptr
  15901 	Fuv_top       uintptr
  15902 	Fyuv_left_mem [88]uint8_t
  15903 	Fyuv_mem      [3359]uint8_t
  15904 }
  15905 
  15906 type VP8TBuffer = struct {
  15907 	Fpages     uintptr
  15908 	Flast_page uintptr
  15909 	Ftokens    uintptr
  15910 	Fleft      int32
  15911 	Fpage_size int32
  15912 	Ferror1    int32
  15913 }
  15914 
  15915 type Mode = int32
  15916 
  15917 const kLiteral = 0
  15918 const kCacheIdx = 1
  15919 const kCopy = 2
  15920 const kNone = 3
  15921 
  15922 type PixOrCopy = struct {
  15923 	Fmode             uint8_t
  15924 	Flen1             uint16_t
  15925 	Fargb_or_distance uint32_t
  15926 }
  15927 
  15928 type VP8LHashChain = struct {
  15929 	Foffset_length uintptr
  15930 	Fsize          int32
  15931 }
  15932 
  15933 type VP8LBackwardRefs = struct {
  15934 	Fblock_size  int32
  15935 	Ferror1      int32
  15936 	Frefs        uintptr
  15937 	Ftail        uintptr
  15938 	Ffree_blocks uintptr
  15939 	Flast_block  uintptr
  15940 }
  15941 
  15942 type VP8LRefsCursor = struct {
  15943 	Fcur_pos   uintptr
  15944 	Fcur_block uintptr
  15945 	Flast_pos  uintptr
  15946 }
  15947 
  15948 type VP8LLZ77Type = int32
  15949 
  15950 const kLZ77Standard = 1
  15951 const kLZ77RLE = 2
  15952 const kLZ77Box = 4
  15953 
  15954 type VP8LHistogram = struct {
  15955 	Fliteral           uintptr
  15956 	Fred               [256]uint32_t
  15957 	Fblue              [256]uint32_t
  15958 	Falpha             [256]uint32_t
  15959 	Fdistance          [40]uint32_t
  15960 	Fpalette_code_bits int32
  15961 	Ftrivial_symbol    [5]uint16_t
  15962 	Fbit_cost          uint64_t
  15963 	Fcosts             [5]uint64_t
  15964 	Fis_used           [5]uint8_t
  15965 	Fbin_id            uint16_t
  15966 }
  15967 
  15968 type VP8LHistogramSet = struct {
  15969 	Fsize       int32
  15970 	Fmax_size   int32
  15971 	Fhistograms uintptr
  15972 }
  15973 
  15974 type VP8LEncoderARGBContent = int32
  15975 
  15976 const kEncoderNone = 0
  15977 const kEncoderARGB = 1
  15978 const kEncoderNearLossless = 2
  15979 const kEncoderPalette = 3
  15980 
  15981 type VP8LEncoder = struct {
  15982 	Fconfig                     uintptr
  15983 	Fpic                        uintptr
  15984 	Fargb                       uintptr
  15985 	Fargb_content               VP8LEncoderARGBContent
  15986 	Fargb_scratch               uintptr
  15987 	Ftransform_data             uintptr
  15988 	Ftransform_mem              uintptr
  15989 	Ftransform_mem_size         size_t
  15990 	Fcurrent_width              int32
  15991 	Fhisto_bits                 int32
  15992 	Fpredictor_transform_bits   int32
  15993 	Fcross_color_transform_bits int32
  15994 	Fcache_bits                 int32
  15995 	Fuse_cross_color            int32
  15996 	Fuse_subtract_green         int32
  15997 	Fuse_predict                int32
  15998 	Fuse_palette                int32
  15999 	Fpalette_size               int32
  16000 	Fpalette                    [256]uint32_t
  16001 	Fpalette_sorted             [256]uint32_t
  16002 	Frefs                       [4]VP8LBackwardRefs
  16003 	Fhash_chain                 VP8LHashChain
  16004 }
  16005 
  16006 //------------------------------------------------------------------------------
  16007 
  16008 func EncodeLossless(tls *libc.TLS, data uintptr, width int32, height int32, effort_level int32, use_quality_100 int32, bw uintptr, stats uintptr) (r int32) {
  16009 	bp := tls.Alloc(384)
  16010 	defer tls.Free(384)
  16011 	var ok, v1 int32
  16012 	var v5 float32
  16013 	var _ /* config at bp+0 */ WebPConfig
  16014 	var _ /* picture at bp+120 */ WebPPicture
  16015 	_, _, _ = ok, v1, v5
  16016 	ok = 0
  16017 	v1 = WebPPictureInitInternal(tls, bp+120, int32(WEBP_ENCODER_ABI_VERSION))
  16018 	goto _2
  16019 _2:
  16020 	if !(v1 != 0) {
  16021 		return 0
  16022 	}
  16023 	(**(**WebPPicture)(__ccgo_up(bp + 120))).Fwidth = width
  16024 	(**(**WebPPicture)(__ccgo_up(bp + 120))).Fheight = height
  16025 	(**(**WebPPicture)(__ccgo_up(bp + 120))).Fuse_argb = int32(1)
  16026 	(**(**WebPPicture)(__ccgo_up(bp + 120))).Fstats = stats
  16027 	if !(WebPPictureAlloc(tls, bp+120) != 0) {
  16028 		return 0
  16029 	}
  16030 	// Transfer the alpha values to the green channel.
  16031 	(*(*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)
  16032 	v1 = WebPConfigInitInternal(tls, bp, int32(WEBP_PRESET_DEFAULT), libc.Float32FromFloat32(75), int32(WEBP_ENCODER_ABI_VERSION))
  16033 	goto _4
  16034 _4:
  16035 	if !(v1 != 0) {
  16036 		return 0
  16037 	}
  16038 	(**(**WebPConfig)(__ccgo_up(bp))).Flossless = int32(1)
  16039 	// Enable exact, or it would alter RGB values of transparent alpha, which is
  16040 	// normally OK but not here since we are not encoding the input image but  an
  16041 	// internal encoding-related image containing necessary exact information in
  16042 	// RGB channels.
  16043 	(**(**WebPConfig)(__ccgo_up(bp))).Fexact = int32(1)
  16044 	(**(**WebPConfig)(__ccgo_up(bp))).Fmethod = effort_level // impact is very small
  16045 	// Set a low default quality for encoding alpha. Ensure that Alpha quality at
  16046 	// lower methods (3 and below) is less than the threshold for triggering
  16047 	// costly 'BackwardReferencesTraceBackwards'.
  16048 	// If the alpha quality is set to 100 and the method to 6, allow for a high
  16049 	// lossless quality to trigger the cruncher.
  16050 	if use_quality_100 != 0 && effort_level == int32(6) {
  16051 		v5 = libc.Float32FromInt32(100)
  16052 	} else {
  16053 		v5 = float32(libc.Float32FromFloat32(8) * float32(effort_level))
  16054 	}
  16055 	(**(**WebPConfig)(__ccgo_up(bp))).Fquality = v5
  16056 	ok = VP8LEncodeStream(tls, bp, bp+120, bw)
  16057 	WebPPictureFree(tls, bp+120)
  16058 	ok = libc.BoolInt32(ok != 0 && !((*VP8LBitWriter)(unsafe.Pointer(bw)).Ferror1 != 0))
  16059 	if !(ok != 0) {
  16060 		VP8LBitWriterWipeOut(tls, bw)
  16061 		return 0
  16062 	}
  16063 	return int32(1)
  16064 }
  16065 
  16066 // -----------------------------------------------------------------------------
  16067 
  16068 // C documentation
  16069 //
  16070 //	// Small struct to hold the result of a filter mode compression attempt.
  16071 type FilterTrial = struct {
  16072 	Fscore size_t
  16073 	Fbw    VP8BitWriter
  16074 	Fstats WebPAuxStats
  16075 }
  16076 
  16077 // C documentation
  16078 //
  16079 //	// This function always returns an initialized 'bw' object, even upon error.
  16080 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) {
  16081 	bp := tls.Alloc(64)
  16082 	defer tls.Free(64)
  16083 	var alpha_src, output, v1 uintptr
  16084 	var data_size, output_size, v2 size_t
  16085 	var filter_func WebPFilterFunc
  16086 	var ok int32
  16087 	var _ /* header at bp+0 */ uint8_t
  16088 	var _ /* tmp_bw at bp+8 */ VP8LBitWriter
  16089 	_, _, _, _, _, _, _, _ = alpha_src, data_size, filter_func, ok, output, output_size, v1, v2
  16090 	ok = 0
  16091 	data_size = uint64(width * height)
  16092 	output = libc.UintptrFromInt32(0)
  16093 	output_size = uint64(0)
  16094 	// as per spec
  16095 	filter_func = WebPFilters[filter]
  16096 	if filter_func != libc.UintptrFromInt32(0) {
  16097 		(*(*func(*libc.TLS, uintptr, int32, int32, int32, uintptr))(unsafe.Pointer(&struct{ uintptr }{filter_func})))(tls, data, width, height, width, tmp_alpha)
  16098 		alpha_src = tmp_alpha
  16099 	} else {
  16100 		alpha_src = data
  16101 	}
  16102 	if method != ALPHA_NO_COMPRESSION {
  16103 		ok = VP8LBitWriterInit(tls, bp+8, data_size>>int32(3))
  16104 		ok = libc.BoolInt32(ok != 0 && EncodeLossless(tls, alpha_src, width, height, effort_level, libc.BoolInt32(!(reduce_levels != 0)), bp+8, result+56) != 0)
  16105 		if ok != 0 {
  16106 			output = VP8LBitWriterFinish(tls, bp+8)
  16107 			if (**(**VP8LBitWriter)(__ccgo_up(bp + 8))).Ferror1 != 0 {
  16108 				VP8LBitWriterWipeOut(tls, bp+8)
  16109 				libc.Xmemset(tls, result+8, 0, uint64(48))
  16110 				return 0
  16111 			}
  16112 			v1 = bp + 8
  16113 			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)))
  16114 			goto _3
  16115 		_3:
  16116 			output_size = v2
  16117 			if output_size > data_size {
  16118 				// compressed size is larger than source! Revert to uncompressed mode.
  16119 				method = ALPHA_NO_COMPRESSION
  16120 				VP8LBitWriterWipeOut(tls, bp+8)
  16121 			}
  16122 		} else {
  16123 			VP8LBitWriterWipeOut(tls, bp+8)
  16124 			libc.Xmemset(tls, result+8, 0, uint64(48))
  16125 			return 0
  16126 		}
  16127 	}
  16128 	if method == ALPHA_NO_COMPRESSION {
  16129 		output = alpha_src
  16130 		output_size = data_size
  16131 		ok = int32(1)
  16132 	}
  16133 	// Emit final result.
  16134 	**(**uint8_t)(__ccgo_up(bp)) = uint8(method | filter<<int32(2))
  16135 	if reduce_levels != 0 {
  16136 		**(**uint8_t)(__ccgo_up(bp)) = uint8(int32(**(**uint8_t)(__ccgo_up(bp))) | libc.Int32FromInt32(ALPHA_PREPROCESSED_LEVELS)<<libc.Int32FromInt32(4))
  16137 	}
  16138 	if !(VP8BitWriterInit(tls, result+8, uint64(ALPHA_HEADER_LEN)+output_size) != 0) {
  16139 		ok = 0
  16140 	}
  16141 	ok = libc.BoolInt32(ok != 0 && VP8BitWriterAppend(tls, result+8, bp, uint64(ALPHA_HEADER_LEN)) != 0)
  16142 	ok = libc.BoolInt32(ok != 0 && VP8BitWriterAppend(tls, result+8, output, output_size) != 0)
  16143 	if method != ALPHA_NO_COMPRESSION {
  16144 		VP8LBitWriterWipeOut(tls, bp+8)
  16145 	}
  16146 	ok = libc.BoolInt32(ok != 0 && !((*FilterTrial)(unsafe.Pointer(result)).Fbw.Ferror1 != 0))
  16147 	v2 = (*VP8BitWriter)(unsafe.Pointer(result + 8)).Fpos
  16148 	goto _5
  16149 _5:
  16150 	(*FilterTrial)(unsafe.Pointer(result)).Fscore = v2
  16151 	return ok
  16152 }
  16153 
  16154 // -----------------------------------------------------------------------------
  16155 
  16156 func GetNumColors(tls *libc.TLS, data uintptr, width int32, height int32, stride int32) (r int32) {
  16157 	var color [256]uint8_t
  16158 	var colors, i, j int32
  16159 	var p uintptr
  16160 	_, _, _, _, _ = color, colors, i, j, p
  16161 	colors = 0
  16162 	color = [256]uint8_t{}
  16163 	j = 0
  16164 	for {
  16165 		if !(j < height) {
  16166 			break
  16167 		}
  16168 		p = data + uintptr(j*stride)
  16169 		i = 0
  16170 		for {
  16171 			if !(i < width) {
  16172 				break
  16173 			}
  16174 			color[**(**uint8_t)(__ccgo_up(p + uintptr(i)))] = uint8(1)
  16175 			goto _2
  16176 		_2:
  16177 			;
  16178 			i = i + 1
  16179 		}
  16180 		goto _1
  16181 	_1:
  16182 		;
  16183 		j = j + 1
  16184 	}
  16185 	j = 0
  16186 	for {
  16187 		if !(j < int32(256)) {
  16188 			break
  16189 		}
  16190 		if int32(color[j]) > 0 {
  16191 			colors = colors + 1
  16192 		}
  16193 		goto _3
  16194 	_3:
  16195 		;
  16196 		j = j + 1
  16197 	}
  16198 	return colors
  16199 }
  16200 
  16201 // C documentation
  16202 //
  16203 //	// Given the input 'filter' option, return an OR'd bit-set of filters to try.
  16204 func GetFilterMap(tls *libc.TLS, alpha uintptr, width int32, height int32, filter int32, effort_level int32) (r uint32_t) {
  16205 	var bit_map uint32_t
  16206 	var kMaxColorsForFilterNone, kMinColorsForFilterNone, num_colors, try_filter_none, v1 int32
  16207 	_, _, _, _, _, _ = bit_map, kMaxColorsForFilterNone, kMinColorsForFilterNone, num_colors, try_filter_none, v1
  16208 	bit_map = 0
  16209 	if filter == int32(WEBP_FILTER_FAST) {
  16210 		// Quick estimate of the best candidate.
  16211 		try_filter_none = libc.BoolInt32(effort_level > int32(3))
  16212 		kMinColorsForFilterNone = int32(16)
  16213 		kMaxColorsForFilterNone = int32(192)
  16214 		num_colors = GetNumColors(tls, alpha, width, height, width)
  16215 		// For low number of colors, NONE yields better compression.
  16216 		if num_colors <= kMinColorsForFilterNone {
  16217 			v1 = int32(WEBP_FILTER_NONE)
  16218 		} else {
  16219 			v1 = WebPEstimateBestFilter(tls, alpha, width, height, width)
  16220 		}
  16221 		filter = v1
  16222 		bit_map = bit_map | uint32(int32(1)<<filter)
  16223 		// For large number of colors, try FILTER_NONE in addition to the best
  16224 		// filter as well.
  16225 		if try_filter_none != 0 || num_colors > kMaxColorsForFilterNone {
  16226 			bit_map = bit_map | uint32(libc.Int32FromInt32(1)<<int32(WEBP_FILTER_NONE))
  16227 		}
  16228 	} else {
  16229 		if filter == int32(WEBP_FILTER_NONE) {
  16230 			bit_map = uint32(libc.Int32FromInt32(1) << int32(WEBP_FILTER_NONE))
  16231 		} else { // WEBP_FILTER_BEST -> try all
  16232 			bit_map = uint32(libc.Int32FromInt32(1)<<int32(WEBP_FILTER_LAST) - libc.Int32FromInt32(1))
  16233 		}
  16234 	}
  16235 	return bit_map
  16236 }
  16237 
  16238 func InitFilterTrial(tls *libc.TLS, score uintptr) {
  16239 	(*FilterTrial)(unsafe.Pointer(score)).Fscore = uint64(^libc.Uint32FromUint32(0))
  16240 	VP8BitWriterInit(tls, score+8, uint64(0))
  16241 }
  16242 
  16243 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) {
  16244 	bp := tls.Alloc(496)
  16245 	defer tls.Free(496)
  16246 	var filtered_alpha, v4 uintptr
  16247 	var ok int32
  16248 	var try_map uint32_t
  16249 	var v2 size_t
  16250 	var _ /* best at bp+0 */ FilterTrial
  16251 	var _ /* trial at bp+248 */ FilterTrial
  16252 	_, _, _, _, _ = filtered_alpha, ok, try_map, v2, v4
  16253 	ok = int32(1)
  16254 	try_map = GetFilterMap(tls, alpha, width, height, filter, effort_level)
  16255 	InitFilterTrial(tls, bp)
  16256 	if try_map != uint32(libc.Int32FromInt32(1)<<int32(WEBP_FILTER_NONE)) {
  16257 		filtered_alpha = WebPSafeMalloc(tls, uint64(1), data_size)
  16258 		if filtered_alpha == libc.UintptrFromInt32(0) {
  16259 			return 0
  16260 		}
  16261 		filter = int32(WEBP_FILTER_NONE)
  16262 		for {
  16263 			if !(ok != 0 && try_map != 0) {
  16264 				break
  16265 			}
  16266 			if try_map&uint32(1) != 0 {
  16267 				ok = EncodeAlphaInternal(tls, alpha, width, height, method, filter, reduce_levels, effort_level, filtered_alpha, bp+248)
  16268 				if ok != 0 && (**(**FilterTrial)(__ccgo_up(bp + 248))).Fscore < (**(**FilterTrial)(__ccgo_up(bp))).Fscore {
  16269 					VP8BitWriterWipeOut(tls, bp+8)
  16270 					**(**FilterTrial)(__ccgo_up(bp)) = **(**FilterTrial)(__ccgo_up(bp + 248))
  16271 				} else {
  16272 					VP8BitWriterWipeOut(tls, bp+248+8)
  16273 				}
  16274 			}
  16275 			goto _1
  16276 		_1:
  16277 			;
  16278 			filter = filter + 1
  16279 			try_map = try_map >> uint32(1)
  16280 		}
  16281 		WebPSafeFree(tls, filtered_alpha)
  16282 	} else {
  16283 		ok = EncodeAlphaInternal(tls, alpha, width, height, method, int32(WEBP_FILTER_NONE), reduce_levels, effort_level, libc.UintptrFromInt32(0), bp)
  16284 	}
  16285 	if ok != 0 {
  16286 		if stats != libc.UintptrFromInt32(0) {
  16287 			(*WebPAuxStats)(unsafe.Pointer(stats)).Flossless_features = (**(**FilterTrial)(__ccgo_up(bp))).Fstats.Flossless_features
  16288 			(*WebPAuxStats)(unsafe.Pointer(stats)).Fhistogram_bits = (**(**FilterTrial)(__ccgo_up(bp))).Fstats.Fhistogram_bits
  16289 			(*WebPAuxStats)(unsafe.Pointer(stats)).Ftransform_bits = (**(**FilterTrial)(__ccgo_up(bp))).Fstats.Ftransform_bits
  16290 			(*WebPAuxStats)(unsafe.Pointer(stats)).Fcross_color_transform_bits = (**(**FilterTrial)(__ccgo_up(bp))).Fstats.Fcross_color_transform_bits
  16291 			(*WebPAuxStats)(unsafe.Pointer(stats)).Fcache_bits = (**(**FilterTrial)(__ccgo_up(bp))).Fstats.Fcache_bits
  16292 			(*WebPAuxStats)(unsafe.Pointer(stats)).Fpalette_size = (**(**FilterTrial)(__ccgo_up(bp))).Fstats.Fpalette_size
  16293 			(*WebPAuxStats)(unsafe.Pointer(stats)).Flossless_size = (**(**FilterTrial)(__ccgo_up(bp))).Fstats.Flossless_size
  16294 			(*WebPAuxStats)(unsafe.Pointer(stats)).Flossless_hdr_size = (**(**FilterTrial)(__ccgo_up(bp))).Fstats.Flossless_hdr_size
  16295 			(*WebPAuxStats)(unsafe.Pointer(stats)).Flossless_data_size = (**(**FilterTrial)(__ccgo_up(bp))).Fstats.Flossless_data_size
  16296 		}
  16297 		v2 = (*VP8BitWriter)(unsafe.Pointer(bp + 8)).Fpos
  16298 		goto _3
  16299 	_3:
  16300 		**(**size_t)(__ccgo_up(output_size)) = v2
  16301 		v4 = (*VP8BitWriter)(unsafe.Pointer(bp + 8)).Fbuf
  16302 		goto _5
  16303 	_5:
  16304 		**(**uintptr)(__ccgo_up(output)) = v4
  16305 	} else {
  16306 		VP8BitWriterWipeOut(tls, bp+8)
  16307 	}
  16308 	return ok
  16309 }
  16310 
  16311 func EncodeAlpha(tls *libc.TLS, enc uintptr, quality int32, method int32, filter int32, effort_level int32, output uintptr, output_size uintptr) (r int32) {
  16312 	bp := tls.Alloc(16)
  16313 	defer tls.Free(16)
  16314 	var alpha_levels, height, ok, reduce_levels, width, v1 int32
  16315 	var data_size size_t
  16316 	var pic, quant_alpha uintptr
  16317 	var _ /* sse at bp+0 */ uint64_t
  16318 	_, _, _, _, _, _, _, _, _ = alpha_levels, data_size, height, ok, pic, quant_alpha, reduce_levels, width, v1
  16319 	pic = (*VP8Encoder)(unsafe.Pointer(enc)).Fpic
  16320 	width = (*WebPPicture)(unsafe.Pointer(pic)).Fwidth
  16321 	height = (*WebPPicture)(unsafe.Pointer(pic)).Fheight
  16322 	quant_alpha = libc.UintptrFromInt32(0)
  16323 	data_size = uint64(width * height)
  16324 	**(**uint64_t)(__ccgo_up(bp)) = uint64(0)
  16325 	ok = int32(1)
  16326 	reduce_levels = libc.BoolInt32(quality < libc.Int32FromInt32(100))
  16327 	// quick correctness checks
  16328 	// as per spec
  16329 	if quality < 0 || quality > int32(100) {
  16330 		return WebPEncodingSetError(tls, pic, int32(VP8_ENC_ERROR_INVALID_CONFIGURATION))
  16331 	}
  16332 	if method < ALPHA_NO_COMPRESSION || method > int32(ALPHA_LOSSLESS_COMPRESSION) {
  16333 		return WebPEncodingSetError(tls, pic, int32(VP8_ENC_ERROR_INVALID_CONFIGURATION))
  16334 	}
  16335 	if method == ALPHA_NO_COMPRESSION {
  16336 		// Don't filter, as filtering will make no impact on compressed size.
  16337 		filter = int32(WEBP_FILTER_NONE)
  16338 	}
  16339 	quant_alpha = WebPSafeMalloc(tls, uint64(1), data_size)
  16340 	if quant_alpha == libc.UintptrFromInt32(0) {
  16341 		return WebPEncodingSetError(tls, pic, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  16342 	}
  16343 	// Extract alpha data (width x height) from raw_data (stride x height).
  16344 	WebPCopyPlane(tls, (*WebPPicture)(unsafe.Pointer(pic)).Fa, (*WebPPicture)(unsafe.Pointer(pic)).Fa_stride, quant_alpha, width, width, height)
  16345 	if reduce_levels != 0 {
  16346 		if quality <= int32(70) {
  16347 			v1 = int32(2) + quality/int32(5)
  16348 		} else {
  16349 			v1 = int32(16) + (quality-int32(70))*int32(8)
  16350 		} // No Quantization required for 'quality = 100'.
  16351 		// 16 alpha levels gives quite a low MSE w.r.t original alpha plane hence
  16352 		// mapped to moderate quality 70. Hence Quality:[0, 70] -> Levels:[2, 16]
  16353 		// and Quality:]70, 100] -> Levels:]16, 256].
  16354 		alpha_levels = v1
  16355 		ok = QuantizeLevels(tls, quant_alpha, width, height, alpha_levels, bp)
  16356 	}
  16357 	if ok != 0 {
  16358 		VP8FiltersInit(tls)
  16359 		ok = ApplyFiltersAndEncode(tls, quant_alpha, width, height, data_size, method, filter, reduce_levels, effort_level, output, output_size, (*WebPPicture)(unsafe.Pointer(pic)).Fstats)
  16360 		if !(ok != 0) {
  16361 			WebPEncodingSetError(tls, pic, int32(VP8_ENC_ERROR_OUT_OF_MEMORY)) // imprecise
  16362 		}
  16363 		if (*WebPPicture)(unsafe.Pointer(pic)).Fstats != libc.UintptrFromInt32(0) { // need stats?
  16364 			**(**int32)(__ccgo_up((*WebPPicture)(unsafe.Pointer(pic)).Fstats)) += int32(**(**size_t)(__ccgo_up(output_size)))
  16365 			**(**uint64_t)(__ccgo_up(enc + 23512 + 3*8)) = **(**uint64_t)(__ccgo_up(bp))
  16366 		}
  16367 	}
  16368 	WebPSafeFree(tls, quant_alpha)
  16369 	return ok
  16370 }
  16371 
  16372 //------------------------------------------------------------------------------
  16373 // Main calls
  16374 
  16375 func CompressAlphaJob(tls *libc.TLS, arg1 uintptr, unused uintptr) (r int32) {
  16376 	bp := tls.Alloc(16)
  16377 	defer tls.Free(16)
  16378 	var config, enc uintptr
  16379 	var effort_level, v1, v2 int32
  16380 	var filter WEBP_FILTER_TYPE
  16381 	var _ /* alpha_data at bp+0 */ uintptr
  16382 	var _ /* alpha_size at bp+8 */ size_t
  16383 	_, _, _, _, _, _ = config, effort_level, enc, filter, v1, v2
  16384 	enc = arg1
  16385 	config = (*VP8Encoder)(unsafe.Pointer(enc)).Fconfig
  16386 	**(**uintptr)(__ccgo_up(bp)) = libc.UintptrFromInt32(0)
  16387 	**(**size_t)(__ccgo_up(bp + 8)) = uint64(0)
  16388 	effort_level = (*WebPConfig)(unsafe.Pointer(config)).Fmethod
  16389 	if (*WebPConfig)(unsafe.Pointer(config)).Falpha_filtering == 0 {
  16390 		v1 = int32(WEBP_FILTER_NONE)
  16391 	} else {
  16392 		if (*WebPConfig)(unsafe.Pointer(config)).Falpha_filtering == int32(1) {
  16393 			v2 = int32(WEBP_FILTER_FAST)
  16394 		} else {
  16395 			v2 = int32(WEBP_FILTER_BEST)
  16396 		}
  16397 		v1 = v2
  16398 	} // maps to [0..6]
  16399 	filter = v1
  16400 	if !(EncodeAlpha(tls, enc, (*WebPConfig)(unsafe.Pointer(config)).Falpha_quality, (*WebPConfig)(unsafe.Pointer(config)).Falpha_compression, filter, effort_level, bp, bp+8) != 0) {
  16401 		return 0
  16402 	}
  16403 	if **(**size_t)(__ccgo_up(bp + 8)) != uint64(uint32(**(**size_t)(__ccgo_up(bp + 8)))) { // Soundness check.
  16404 		WebPSafeFree(tls, **(**uintptr)(__ccgo_up(bp)))
  16405 		return 0
  16406 	}
  16407 	(*VP8Encoder)(unsafe.Pointer(enc)).Falpha_data_size = uint32(**(**size_t)(__ccgo_up(bp + 8)))
  16408 	(*VP8Encoder)(unsafe.Pointer(enc)).Falpha_data = **(**uintptr)(__ccgo_up(bp))
  16409 	_ = unused
  16410 	return int32(1)
  16411 }
  16412 
  16413 func VP8EncInitAlpha(tls *libc.TLS, enc uintptr) {
  16414 	var worker uintptr
  16415 	_ = worker
  16416 	WebPInitAlphaProcessing(tls)
  16417 	(*VP8Encoder)(unsafe.Pointer(enc)).Fhas_alpha = WebPPictureHasTransparency(tls, (*VP8Encoder)(unsafe.Pointer(enc)).Fpic)
  16418 	(*VP8Encoder)(unsafe.Pointer(enc)).Falpha_data = libc.UintptrFromInt32(0)
  16419 	(*VP8Encoder)(unsafe.Pointer(enc)).Falpha_data_size = uint32(0)
  16420 	if (*VP8Encoder)(unsafe.Pointer(enc)).Fthread_level > 0 {
  16421 		worker = enc + 560
  16422 		(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(&struct{ uintptr }{(*WebPWorkerInterface)(unsafe.Pointer(WebPGetWorkerInterface(tls))).FInit})))(tls, worker)
  16423 		(*WebPWorker)(unsafe.Pointer(worker)).Fdata1 = enc
  16424 		(*WebPWorker)(unsafe.Pointer(worker)).Fdata2 = libc.UintptrFromInt32(0)
  16425 		(*WebPWorker)(unsafe.Pointer(worker)).Fhook = __ccgo_fp(CompressAlphaJob)
  16426 	}
  16427 }
  16428 
  16429 func VP8EncStartAlpha(tls *libc.TLS, enc uintptr) (r int32) {
  16430 	var worker uintptr
  16431 	_ = worker
  16432 	if (*VP8Encoder)(unsafe.Pointer(enc)).Fhas_alpha != 0 {
  16433 		if (*VP8Encoder)(unsafe.Pointer(enc)).Fthread_level > 0 {
  16434 			worker = enc + 560
  16435 			// Makes sure worker is good to go.
  16436 			if !((*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*WebPWorkerInterface)(unsafe.Pointer(WebPGetWorkerInterface(tls))).FReset})))(tls, worker) != 0) {
  16437 				return WebPEncodingSetError(tls, (*VP8Encoder)(unsafe.Pointer(enc)).Fpic, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  16438 			}
  16439 			(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(&struct{ uintptr }{(*WebPWorkerInterface)(unsafe.Pointer(WebPGetWorkerInterface(tls))).FLaunch})))(tls, worker)
  16440 			return int32(1)
  16441 		} else {
  16442 			return CompressAlphaJob(tls, enc, libc.UintptrFromInt32(0)) // just do the job right away
  16443 		}
  16444 	}
  16445 	return int32(1)
  16446 }
  16447 
  16448 func VP8EncFinishAlpha(tls *libc.TLS, enc uintptr) (r int32) {
  16449 	var worker uintptr
  16450 	_ = worker
  16451 	if (*VP8Encoder)(unsafe.Pointer(enc)).Fhas_alpha != 0 {
  16452 		if (*VP8Encoder)(unsafe.Pointer(enc)).Fthread_level > 0 {
  16453 			worker = enc + 560
  16454 			if !((*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*WebPWorkerInterface)(unsafe.Pointer(WebPGetWorkerInterface(tls))).FSync})))(tls, worker) != 0) {
  16455 				return 0
  16456 			} // error
  16457 		}
  16458 	}
  16459 	return WebPReportProgress(tls, (*VP8Encoder)(unsafe.Pointer(enc)).Fpic, (*VP8Encoder)(unsafe.Pointer(enc)).Fpercent+int32(20), enc+536)
  16460 }
  16461 
  16462 func VP8EncDeleteAlpha(tls *libc.TLS, enc uintptr) (r int32) {
  16463 	var ok int32
  16464 	var worker uintptr
  16465 	_, _ = ok, worker
  16466 	ok = int32(1)
  16467 	if (*VP8Encoder)(unsafe.Pointer(enc)).Fthread_level > 0 {
  16468 		worker = enc + 560
  16469 		// finish anything left in flight
  16470 		ok = (*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*WebPWorkerInterface)(unsafe.Pointer(WebPGetWorkerInterface(tls))).FSync})))(tls, worker)
  16471 		// still need to end the worker, even if !ok
  16472 		(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(&struct{ uintptr }{(*WebPWorkerInterface)(unsafe.Pointer(WebPGetWorkerInterface(tls))).FEnd})))(tls, worker)
  16473 	}
  16474 	WebPSafeFree(tls, (*VP8Encoder)(unsafe.Pointer(enc)).Falpha_data)
  16475 	(*VP8Encoder)(unsafe.Pointer(enc)).Falpha_data = libc.UintptrFromInt32(0)
  16476 	(*VP8Encoder)(unsafe.Pointer(enc)).Falpha_data_size = uint32(0)
  16477 	(*VP8Encoder)(unsafe.Pointer(enc)).Fhas_alpha = 0
  16478 	return ok
  16479 }
  16480 
  16481 const MAX_ALPHA = 255
  16482 const MAX_INTRA16_MODE = 2
  16483 const MAX_INTRA4_MODE = 2
  16484 const MAX_ITERS_K_MEANS = 6
  16485 const MAX_UV_MODE = 2
  16486 
  16487 //------------------------------------------------------------------------------
  16488 
  16489 // Copyright 2011 Google Inc. All Rights Reserved.
  16490 //
  16491 // Use of this source code is governed by a BSD-style license
  16492 // that can be found in the COPYING file in the root of the source
  16493 // tree. An additional intellectual property rights grant can be found
  16494 // in the file PATENTS. All contributing project authors may
  16495 // be found in the AUTHORS file in the root of the source tree.
  16496 // -----------------------------------------------------------------------------
  16497 //
  16498 // Multi-threaded worker
  16499 //
  16500 // Author: Skal (pascal.massimino@gmail.com)
  16501 
  16502 // Copyright 2012 Google Inc. All Rights Reserved.
  16503 //
  16504 // Use of this source code is governed by a BSD-style license
  16505 // that can be found in the COPYING file in the root of the source
  16506 // tree. An additional intellectual property rights grant can be found
  16507 // in the file PATENTS. All contributing project authors may
  16508 // be found in the AUTHORS file in the root of the source tree.
  16509 // -----------------------------------------------------------------------------
  16510 //
  16511 // Misc. common utility functions
  16512 //
  16513 // Authors: Skal (pascal.massimino@gmail.com)
  16514 //          Urvang (urvang@google.com)
  16515 
  16516 // Copyright 2011 Google Inc. All Rights Reserved.
  16517 //
  16518 // Use of this source code is governed by a BSD-style license
  16519 // that can be found in the COPYING file in the root of the source
  16520 // tree. An additional intellectual property rights grant can be found
  16521 // in the file PATENTS. All contributing project authors may
  16522 // be found in the AUTHORS file in the root of the source tree.
  16523 // -----------------------------------------------------------------------------
  16524 //
  16525 //   WebP encoder: main interface
  16526 //
  16527 // Author: Skal (pascal.massimino@gmail.com)
  16528 
  16529 // Copyright 2010 Google Inc. All Rights Reserved.
  16530 //
  16531 // Use of this source code is governed by a BSD-style license
  16532 // that can be found in the COPYING file in the root of the source
  16533 // tree. An additional intellectual property rights grant can be found
  16534 // in the file PATENTS. All contributing project authors may
  16535 // be found in the AUTHORS file in the root of the source tree.
  16536 // -----------------------------------------------------------------------------
  16537 //
  16538 //  Common types + memory wrappers
  16539 //
  16540 // Author: Skal (pascal.massimino@gmail.com)
  16541 
  16542 //------------------------------------------------------------------------------
  16543 // Smooth the segment map by replacing isolated block by the majority of its
  16544 // neighbours.
  16545 
  16546 func SmoothSegmentMap(tls *libc.TLS, enc uintptr) {
  16547 	var cnt [4]int32
  16548 	var h, majority_cnt_3_x_3_grid, majority_seg, n, w, x, y int32
  16549 	var mb, mb1, tmp uintptr
  16550 	_, _, _, _, _, _, _, _, _, _, _ = cnt, h, majority_cnt_3_x_3_grid, majority_seg, mb, mb1, n, tmp, w, x, y
  16551 	w = (*VP8Encoder)(unsafe.Pointer(enc)).Fmb_w
  16552 	h = (*VP8Encoder)(unsafe.Pointer(enc)).Fmb_h
  16553 	majority_cnt_3_x_3_grid = int32(5)
  16554 	tmp = WebPSafeMalloc(tls, uint64(w*h), uint64(1))
  16555 	// no overflow, as per spec
  16556 	if tmp == libc.UintptrFromInt32(0) {
  16557 		return
  16558 	}
  16559 	y = int32(1)
  16560 	for {
  16561 		if !(y < h-int32(1)) {
  16562 			break
  16563 		}
  16564 		x = int32(1)
  16565 		for {
  16566 			if !(x < w-int32(1)) {
  16567 				break
  16568 			}
  16569 			cnt = [4]int32{}
  16570 			mb = (*VP8Encoder)(unsafe.Pointer(enc)).Fmb_info + uintptr(x+w*y)*4
  16571 			majority_seg = int32(uint32(*(*uint8)(unsafe.Pointer(mb + 0)) & 0x60 >> 5))
  16572 			// Check the 8 neighbouring segment values.
  16573 			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
  16574 			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
  16575 			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
  16576 			cnt[int32(uint32(*(*uint8)(unsafe.Pointer(mb + uintptr(-libc.Int32FromInt32(1))*4 + 0))&0x60>>5))] = cnt[int32(uint32(*(*uint8)(unsafe.Pointer(mb + uintptr(-libc.Int32FromInt32(1))*4 + 0))&0x60>>5))] + 1 // left
  16577 			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
  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                           // bottom-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                                         // bottom
  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                           // bottom-right
  16581 			n = 0
  16582 			for {
  16583 				if !(n < int32(NUM_MB_SEGMENTS)) {
  16584 					break
  16585 				}
  16586 				if cnt[n] >= majority_cnt_3_x_3_grid {
  16587 					majority_seg = n
  16588 					break
  16589 				}
  16590 				goto _3
  16591 			_3:
  16592 				;
  16593 				n = n + 1
  16594 			}
  16595 			**(**uint8_t)(__ccgo_up(tmp + uintptr(x+y*w))) = uint8(majority_seg)
  16596 			goto _2
  16597 		_2:
  16598 			;
  16599 			x = x + 1
  16600 		}
  16601 		goto _1
  16602 	_1:
  16603 		;
  16604 		y = y + 1
  16605 	}
  16606 	y = int32(1)
  16607 	for {
  16608 		if !(y < h-int32(1)) {
  16609 			break
  16610 		}
  16611 		x = int32(1)
  16612 		for {
  16613 			if !(x < w-int32(1)) {
  16614 				break
  16615 			}
  16616 			mb1 = (*VP8Encoder)(unsafe.Pointer(enc)).Fmb_info + uintptr(x+w*y)*4
  16617 			libc.SetBitFieldPtr8Uint32(mb1+0, uint32(**(**uint8_t)(__ccgo_up(tmp + uintptr(x+y*w)))), 5, 0x60)
  16618 			goto _5
  16619 		_5:
  16620 			;
  16621 			x = x + 1
  16622 		}
  16623 		goto _4
  16624 	_4:
  16625 		;
  16626 		y = y + 1
  16627 	}
  16628 	WebPSafeFree(tls, tmp)
  16629 }
  16630 
  16631 //------------------------------------------------------------------------------
  16632 // set segment susceptibility 'alpha' / 'beta'
  16633 
  16634 func clip1(tls *libc.TLS, v int32, m int32, M int32) (r int32) {
  16635 	var v1, v2 int32
  16636 	_, _ = v1, v2
  16637 	if v < m {
  16638 		v1 = m
  16639 	} else {
  16640 		if v > M {
  16641 			v2 = M
  16642 		} else {
  16643 			v2 = v
  16644 		}
  16645 		v1 = v2
  16646 	}
  16647 	return v1
  16648 }
  16649 
  16650 func SetSegmentAlphas(tls *libc.TLS, enc uintptr, centers uintptr, mid int32) {
  16651 	var alpha, beta, max, min, n, nb int32
  16652 	_, _, _, _, _, _ = alpha, beta, max, min, n, nb
  16653 	nb = (*VP8Encoder)(unsafe.Pointer(enc)).Fsegment_hdr.Fnum_segments
  16654 	min = **(**int32)(__ccgo_up(centers))
  16655 	max = **(**int32)(__ccgo_up(centers))
  16656 	if nb > int32(1) {
  16657 		n = 0
  16658 		for {
  16659 			if !(n < nb) {
  16660 				break
  16661 			}
  16662 			if min > **(**int32)(__ccgo_up(centers + uintptr(n)*4)) {
  16663 				min = **(**int32)(__ccgo_up(centers + uintptr(n)*4))
  16664 			}
  16665 			if max < **(**int32)(__ccgo_up(centers + uintptr(n)*4)) {
  16666 				max = **(**int32)(__ccgo_up(centers + uintptr(n)*4))
  16667 			}
  16668 			goto _1
  16669 		_1:
  16670 			;
  16671 			n = n + 1
  16672 		}
  16673 	}
  16674 	if max == min {
  16675 		max = min + int32(1)
  16676 	}
  16677 	n = 0
  16678 	for {
  16679 		if !(n < nb) {
  16680 			break
  16681 		}
  16682 		alpha = int32(255) * (**(**int32)(__ccgo_up(centers + uintptr(n)*4)) - mid) / (max - min)
  16683 		beta = int32(255) * (**(**int32)(__ccgo_up(centers + uintptr(n)*4)) - min) / (max - min)
  16684 		(**(**VP8SegmentInfo)(__ccgo_up(enc + 608 + uintptr(n)*744))).Falpha = clip1(tls, alpha, -int32(127), int32(127))
  16685 		(**(**VP8SegmentInfo)(__ccgo_up(enc + 608 + uintptr(n)*744))).Fbeta = clip1(tls, beta, 0, int32(255))
  16686 		goto _2
  16687 	_2:
  16688 		;
  16689 		n = n + 1
  16690 	}
  16691 }
  16692 
  16693 //------------------------------------------------------------------------------
  16694 // Compute susceptibility based on DCT-coeff histograms:
  16695 // the higher, the "easier" the macroblock is to compress.
  16696 
  16697 func FinalAlphaValue(tls *libc.TLS, alpha int32) (r int32) {
  16698 	alpha = int32(MAX_ALPHA) - alpha
  16699 	return clip1(tls, alpha, 0, int32(MAX_ALPHA))
  16700 }
  16701 
  16702 func GetAlpha(tls *libc.TLS, histo uintptr) (r int32) {
  16703 	var alpha, last_non_zero, max_value, v1 int32
  16704 	_, _, _, _ = alpha, last_non_zero, max_value, v1
  16705 	// 'alpha' will later be clipped to [0..MAX_ALPHA] range, clamping outer
  16706 	// values which happen to be mostly noise. This leaves the maximum precision
  16707 	// for handling the useful small values which contribute most.
  16708 	max_value = (*VP8Histogram)(unsafe.Pointer(histo)).Fmax_value
  16709 	last_non_zero = (*VP8Histogram)(unsafe.Pointer(histo)).Flast_non_zero
  16710 	if max_value > int32(1) {
  16711 		v1 = libc.Int32FromInt32(2) * libc.Int32FromInt32(MAX_ALPHA) * last_non_zero / max_value
  16712 	} else {
  16713 		v1 = 0
  16714 	}
  16715 	alpha = v1
  16716 	return alpha
  16717 }
  16718 
  16719 func InitHistogram(tls *libc.TLS, histo uintptr) {
  16720 	(*VP8Histogram)(unsafe.Pointer(histo)).Fmax_value = 0
  16721 	(*VP8Histogram)(unsafe.Pointer(histo)).Flast_non_zero = int32(1)
  16722 }
  16723 
  16724 //------------------------------------------------------------------------------
  16725 // Simplified k-Means, to assign Nb segments based on alpha-histogram
  16726 
  16727 func AssignSegments(tls *libc.TLS, enc uintptr, alphas uintptr) {
  16728 	bp := tls.Alloc(48)
  16729 	defer tls.Free(48)
  16730 	var a, alpha, displaced, k, max_a, min_a, n, nb, new_center, range_a, smooth, total_weight, weighted_average, v1 int32
  16731 	var map1 [256]int32
  16732 	var mb uintptr
  16733 	var _ /* accum at bp+16 */ [4]int32
  16734 	var _ /* centers at bp+0 */ [4]int32
  16735 	var _ /* dist_accum at bp+32 */ [4]int32
  16736 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = a, alpha, displaced, k, map1, max_a, mb, min_a, n, nb, new_center, range_a, smooth, total_weight, weighted_average, v1
  16737 	if (*VP8Encoder)(unsafe.Pointer(enc)).Fsegment_hdr.Fnum_segments < int32(NUM_MB_SEGMENTS) {
  16738 		v1 = (*VP8Encoder)(unsafe.Pointer(enc)).Fsegment_hdr.Fnum_segments
  16739 	} else {
  16740 		v1 = int32(NUM_MB_SEGMENTS)
  16741 	}
  16742 	// 'num_segments' is previously validated and <= NUM_MB_SEGMENTS, but an
  16743 	// explicit check is needed to avoid spurious warning about 'n + 1' exceeding
  16744 	// array bounds of 'centers' with some compilers (noticed with gcc-4.9).
  16745 	nb = v1
  16746 	weighted_average = 0
  16747 	min_a = 0
  16748 	max_a = int32(MAX_ALPHA)
  16749 	// bracket the input
  16750 	n = 0
  16751 	for {
  16752 		if !(n <= int32(MAX_ALPHA) && **(**int32)(__ccgo_up(alphas + uintptr(n)*4)) == 0) {
  16753 			break
  16754 		}
  16755 		goto _2
  16756 	_2:
  16757 		;
  16758 		n = n + 1
  16759 	}
  16760 	min_a = n
  16761 	n = int32(MAX_ALPHA)
  16762 	for {
  16763 		if !(n > min_a && **(**int32)(__ccgo_up(alphas + uintptr(n)*4)) == 0) {
  16764 			break
  16765 		}
  16766 		goto _3
  16767 	_3:
  16768 		;
  16769 		n = n - 1
  16770 	}
  16771 	max_a = n
  16772 	range_a = max_a - min_a
  16773 	// Spread initial centers evenly
  16774 	k = 0
  16775 	n = libc.Int32FromInt32(1)
  16776 	for {
  16777 		if !(k < nb) {
  16778 			break
  16779 		}
  16780 		(**(**[4]int32)(__ccgo_up(bp)))[k] = min_a + n*range_a/(int32(2)*nb)
  16781 		goto _4
  16782 	_4:
  16783 		;
  16784 		k = k + 1
  16785 		n = n + int32(2)
  16786 	}
  16787 	k = 0
  16788 	for {
  16789 		if !(k < int32(MAX_ITERS_K_MEANS)) {
  16790 			break
  16791 		}
  16792 		// Reset stats
  16793 		n = 0
  16794 		for {
  16795 			if !(n < nb) {
  16796 				break
  16797 			}
  16798 			(**(**[4]int32)(__ccgo_up(bp + 16)))[n] = 0
  16799 			(**(**[4]int32)(__ccgo_up(bp + 32)))[n] = 0
  16800 			goto _6
  16801 		_6:
  16802 			;
  16803 			n = n + 1
  16804 		}
  16805 		// Assign nearest center for each 'a'
  16806 		n = 0 // track the nearest center for current 'a'
  16807 		a = min_a
  16808 		for {
  16809 			if !(a <= max_a) {
  16810 				break
  16811 			}
  16812 			if **(**int32)(__ccgo_up(alphas + uintptr(a)*4)) != 0 {
  16813 				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]) {
  16814 					n = n + 1
  16815 				}
  16816 				map1[a] = n
  16817 				// accumulate contribution into best centroid
  16818 				**(**int32)(__ccgo_up(bp + 32 + uintptr(n)*4)) += a * **(**int32)(__ccgo_up(alphas + uintptr(a)*4))
  16819 				**(**int32)(__ccgo_up(bp + 16 + uintptr(n)*4)) += **(**int32)(__ccgo_up(alphas + uintptr(a)*4))
  16820 			}
  16821 			goto _7
  16822 		_7:
  16823 			;
  16824 			a = a + 1
  16825 		}
  16826 		// All point are classified. Move the centroids to the
  16827 		// center of their respective cloud.
  16828 		displaced = 0
  16829 		weighted_average = 0
  16830 		total_weight = 0
  16831 		n = 0
  16832 		for {
  16833 			if !(n < nb) {
  16834 				break
  16835 			}
  16836 			if (**(**[4]int32)(__ccgo_up(bp + 16)))[n] != 0 {
  16837 				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]
  16838 				displaced = displaced + libc.Xabs(tls, (**(**[4]int32)(__ccgo_up(bp)))[n]-new_center)
  16839 				(**(**[4]int32)(__ccgo_up(bp)))[n] = new_center
  16840 				weighted_average = weighted_average + new_center*(**(**[4]int32)(__ccgo_up(bp + 16)))[n]
  16841 				total_weight = total_weight + (**(**[4]int32)(__ccgo_up(bp + 16)))[n]
  16842 			}
  16843 			goto _8
  16844 		_8:
  16845 			;
  16846 			n = n + 1
  16847 		}
  16848 		weighted_average = (weighted_average + total_weight/int32(2)) / total_weight
  16849 		if displaced < int32(5) {
  16850 			break
  16851 		} // no need to keep on looping...
  16852 		goto _5
  16853 	_5:
  16854 		;
  16855 		k = k + 1
  16856 	}
  16857 	// Map each original value to the closest centroid
  16858 	n = 0
  16859 	for {
  16860 		if !(n < (*VP8Encoder)(unsafe.Pointer(enc)).Fmb_w*(*VP8Encoder)(unsafe.Pointer(enc)).Fmb_h) {
  16861 			break
  16862 		}
  16863 		mb = (*VP8Encoder)(unsafe.Pointer(enc)).Fmb_info + uintptr(n)*4
  16864 		alpha = int32((*VP8MBInfo)(unsafe.Pointer(mb)).Falpha)
  16865 		libc.SetBitFieldPtr8Uint32(mb+0, uint32(map1[alpha]), 5, 0x60)
  16866 		(*VP8MBInfo)(unsafe.Pointer(mb)).Falpha = uint8((**(**[4]int32)(__ccgo_up(bp)))[map1[alpha]]) // for the record.
  16867 		goto _9
  16868 	_9:
  16869 		;
  16870 		n = n + 1
  16871 	}
  16872 	if nb > int32(1) {
  16873 		smooth = (*WebPConfig)(unsafe.Pointer((*VP8Encoder)(unsafe.Pointer(enc)).Fconfig)).Fpreprocessing & libc.Int32FromInt32(1)
  16874 		if smooth != 0 {
  16875 			SmoothSegmentMap(tls, enc)
  16876 		}
  16877 	}
  16878 	SetSegmentAlphas(tls, enc, bp, weighted_average) // pick some alphas.
  16879 }
  16880 
  16881 //------------------------------------------------------------------------------
  16882 // Macroblock analysis: collect histogram for each mode, deduce the maximal
  16883 // susceptibility and set best modes for this macroblock.
  16884 // Segment assignment is done later.
  16885 
  16886 // Number of modes to inspect for 'alpha' evaluation. We don't need to test all
  16887 // the possible modes during the analysis phase: we risk falling into a local
  16888 // optimum, or be subject to boundary effect
  16889 
  16890 func MBAnalyzeBestIntra16Mode(tls *libc.TLS, it uintptr) (r int32) {
  16891 	bp := tls.Alloc(16)
  16892 	defer tls.Free(16)
  16893 	var alpha, best_alpha, best_mode, max_mode, mode int32
  16894 	var _ /* histo at bp+0 */ VP8Histogram
  16895 	_, _, _, _, _ = alpha, best_alpha, best_mode, max_mode, mode
  16896 	max_mode = int32(MAX_INTRA16_MODE)
  16897 	best_alpha = -int32(1)
  16898 	best_mode = 0
  16899 	VP8MakeLuma16Preds(tls, it)
  16900 	mode = 0
  16901 	for {
  16902 		if !(mode < max_mode) {
  16903 			break
  16904 		}
  16905 		InitHistogram(tls, bp)
  16906 		(*(*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)
  16907 		alpha = GetAlpha(tls, bp)
  16908 		if alpha > best_alpha {
  16909 			best_alpha = alpha
  16910 			best_mode = mode
  16911 		}
  16912 		goto _1
  16913 	_1:
  16914 		;
  16915 		mode = mode + 1
  16916 	}
  16917 	VP8SetIntra16Mode(tls, it, best_mode)
  16918 	return best_alpha
  16919 }
  16920 
  16921 func FastMBAnalyze(tls *libc.TLS, it uintptr) (r int32) {
  16922 	bp := tls.Alloc(80)
  16923 	defer tls.Free(80)
  16924 	var k, q int32
  16925 	var kThreshold, m, m2 uint32_t
  16926 	var _ /* dc at bp+0 */ [16]uint32_t
  16927 	var _ /* modes at bp+64 */ [16]uint8_t
  16928 	_, _, _, _, _ = k, kThreshold, m, m2, q
  16929 	// Empirical cut-off value, should be around 16 (~=block size). We use the
  16930 	// [8-17] range and favor intra4 at high quality, intra16 for low quality.
  16931 	q = int32((*WebPConfig)(unsafe.Pointer((*VP8Encoder)(unsafe.Pointer((*VP8EncIterator)(unsafe.Pointer(it)).Fenc)).Fconfig)).Fquality)
  16932 	kThreshold = uint32(int32(8) + (libc.Int32FromInt32(17)-libc.Int32FromInt32(8))*q/int32(100))
  16933 	k = 0
  16934 	for {
  16935 		if !(k < int32(16)) {
  16936 			break
  16937 		}
  16938 		(*(*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)
  16939 		goto _1
  16940 	_1:
  16941 		;
  16942 		k = k + int32(4)
  16943 	}
  16944 	m = uint32(0)
  16945 	m2 = uint32(0)
  16946 	k = libc.Int32FromInt32(0)
  16947 	for {
  16948 		if !(k < int32(16)) {
  16949 			break
  16950 		}
  16951 		m = m + (**(**[16]uint32_t)(__ccgo_up(bp)))[k]
  16952 		m2 = m2 + (**(**[16]uint32_t)(__ccgo_up(bp)))[k]*(**(**[16]uint32_t)(__ccgo_up(bp)))[k]
  16953 		goto _2
  16954 	_2:
  16955 		;
  16956 		k = k + 1
  16957 	}
  16958 	if kThreshold*m2 < m*m {
  16959 		VP8SetIntra16Mode(tls, it, 0) // DC16
  16960 	} else {
  16961 		**(**[16]uint8_t)(__ccgo_up(bp + 64)) = [16]uint8_t{} // DC4
  16962 		VP8SetIntra4Mode(tls, it, bp+64)
  16963 	}
  16964 	return 0
  16965 }
  16966 
  16967 func MBAnalyzeBestUVMode(tls *libc.TLS, it uintptr) (r int32) {
  16968 	bp := tls.Alloc(16)
  16969 	defer tls.Free(16)
  16970 	var alpha, best_alpha, best_mode, max_mode, mode, smallest_alpha int32
  16971 	var _ /* histo at bp+0 */ VP8Histogram
  16972 	_, _, _, _, _, _ = alpha, best_alpha, best_mode, max_mode, mode, smallest_alpha
  16973 	best_alpha = -int32(1)
  16974 	smallest_alpha = 0
  16975 	best_mode = 0
  16976 	max_mode = int32(MAX_UV_MODE)
  16977 	VP8MakeChroma8Preds(tls, it)
  16978 	mode = 0
  16979 	for {
  16980 		if !(mode < max_mode) {
  16981 			break
  16982 		}
  16983 		InitHistogram(tls, bp)
  16984 		(*(*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)
  16985 		alpha = GetAlpha(tls, bp)
  16986 		if alpha > best_alpha {
  16987 			best_alpha = alpha
  16988 		}
  16989 		// The best prediction mode tends to be the one with the smallest alpha.
  16990 		if mode == 0 || alpha < smallest_alpha {
  16991 			smallest_alpha = alpha
  16992 			best_mode = mode
  16993 		}
  16994 		goto _1
  16995 	_1:
  16996 		;
  16997 		mode = mode + 1
  16998 	}
  16999 	VP8SetIntraUVMode(tls, it, best_mode)
  17000 	return best_alpha
  17001 }
  17002 
  17003 func MBAnalyze(tls *libc.TLS, it uintptr, alphas uintptr, alpha uintptr, uv_alpha uintptr) {
  17004 	var best_alpha, best_uv_alpha int32
  17005 	var enc uintptr
  17006 	_, _, _ = best_alpha, best_uv_alpha, enc
  17007 	enc = (*VP8EncIterator)(unsafe.Pointer(it)).Fenc
  17008 	VP8SetIntra16Mode(tls, it, 0) // default: Intra16, DC_PRED
  17009 	VP8SetSkip(tls, it, 0)        // not skipped
  17010 	VP8SetSegment(tls, it, 0)     // default segment, spec-wise.
  17011 	if (*VP8Encoder)(unsafe.Pointer(enc)).Fmethod <= int32(1) {
  17012 		best_alpha = FastMBAnalyze(tls, it)
  17013 	} else {
  17014 		best_alpha = MBAnalyzeBestIntra16Mode(tls, it)
  17015 	}
  17016 	best_uv_alpha = MBAnalyzeBestUVMode(tls, it)
  17017 	// Final susceptibility mix
  17018 	best_alpha = (int32(3)*best_alpha + best_uv_alpha + int32(2)) >> int32(2)
  17019 	best_alpha = FinalAlphaValue(tls, best_alpha)
  17020 	**(**int32)(__ccgo_up(alphas + uintptr(best_alpha)*4)) = **(**int32)(__ccgo_up(alphas + uintptr(best_alpha)*4)) + 1
  17021 	(*VP8MBInfo)(unsafe.Pointer((*VP8EncIterator)(unsafe.Pointer(it)).Fmb)).Falpha = uint8(best_alpha) // for later remapping.
  17022 	// Accumulate for later complexity analysis.
  17023 	**(**int32)(__ccgo_up(alpha)) += best_alpha // mixed susceptibility (not just luma)
  17024 	**(**int32)(__ccgo_up(uv_alpha)) += best_uv_alpha
  17025 }
  17026 
  17027 func DefaultMBInfo(tls *libc.TLS, mb uintptr) {
  17028 	libc.SetBitFieldPtr8Uint32(mb+0, libc.Uint32FromInt32(1), 0, 0x3) // I16x16
  17029 	libc.SetBitFieldPtr8Uint32(mb+0, libc.Uint32FromInt32(0), 2, 0xc)
  17030 	libc.SetBitFieldPtr8Uint32(mb+0, libc.Uint32FromInt32(0), 4, 0x10) // not skipped
  17031 	libc.SetBitFieldPtr8Uint32(mb+0, libc.Uint32FromInt32(0), 5, 0x60) // default segment
  17032 	(*VP8MBInfo)(unsafe.Pointer(mb)).Falpha = uint8(0)
  17033 }
  17034 
  17035 //------------------------------------------------------------------------------
  17036 // Main analysis loop:
  17037 // Collect all susceptibilities for each macroblock and record their
  17038 // distribution in alphas[]. Segments is assigned a-posteriori, based on
  17039 // this histogram.
  17040 // We also pick an intra16 prediction mode, which shouldn't be considered
  17041 // final except for fast-encode settings. We can also pick some intra4 modes
  17042 // and decide intra4/intra16, but that's usually almost always a bad choice at
  17043 // this stage.
  17044 
  17045 func ResetAllMBInfo(tls *libc.TLS, enc uintptr) {
  17046 	var n int32
  17047 	_ = n
  17048 	n = 0
  17049 	for {
  17050 		if !(n < (*VP8Encoder)(unsafe.Pointer(enc)).Fmb_w*(*VP8Encoder)(unsafe.Pointer(enc)).Fmb_h) {
  17051 			break
  17052 		}
  17053 		DefaultMBInfo(tls, (*VP8Encoder)(unsafe.Pointer(enc)).Fmb_info+uintptr(n)*4)
  17054 		goto _1
  17055 	_1:
  17056 		;
  17057 		n = n + 1
  17058 	}
  17059 	// Default susceptibilities.
  17060 	(**(**VP8SegmentInfo)(__ccgo_up(enc + 608))).Falpha = 0
  17061 	(**(**VP8SegmentInfo)(__ccgo_up(enc + 608))).Fbeta = 0
  17062 	// Note: we can't compute this 'alpha' / 'uv_alpha' -> set to default value.
  17063 	(*VP8Encoder)(unsafe.Pointer(enc)).Falpha = 0
  17064 	(*VP8Encoder)(unsafe.Pointer(enc)).Fuv_alpha = 0
  17065 	WebPReportProgress(tls, (*VP8Encoder)(unsafe.Pointer(enc)).Fpic, (*VP8Encoder)(unsafe.Pointer(enc)).Fpercent+int32(20), enc+536)
  17066 }
  17067 
  17068 // C documentation
  17069 //
  17070 //	// struct used to collect job result
  17071 type SegmentJob = struct {
  17072 	Fworker         WebPWorker
  17073 	Falphas         [256]int32
  17074 	Falpha          int32
  17075 	Fuv_alpha       int32
  17076 	Fit             VP8EncIterator
  17077 	Fdelta_progress int32
  17078 }
  17079 
  17080 // C documentation
  17081 //
  17082 //	// main work call
  17083 func DoSegmentsJob(tls *libc.TLS, arg1 uintptr, arg2 uintptr) (r int32) {
  17084 	bp := tls.Alloc(64)
  17085 	defer tls.Free(64)
  17086 	var it, job, scratch uintptr
  17087 	var ok int32
  17088 	var _ /* tmp at bp+0 */ [63]uint8_t
  17089 	_, _, _, _ = it, job, ok, scratch
  17090 	job = arg1
  17091 	it = arg2
  17092 	ok = int32(1)
  17093 	if !(VP8IteratorIsDone(tls, it) != 0) {
  17094 		scratch = uintptr((uintptr_t(bp) + libc.Uint64FromInt32(WEBP_ALIGN_CST)) & ^libc.Uint64FromInt32(WEBP_ALIGN_CST))
  17095 		for cond := true; cond; cond = ok != 0 && VP8IteratorNext(tls, it) != 0 {
  17096 			// Let's pretend we have perfect lossless reconstruction.
  17097 			VP8IteratorImport(tls, it, scratch)
  17098 			MBAnalyze(tls, it, job+48, job+1072, job+1076)
  17099 			ok = VP8IteratorProgress(tls, it, (*SegmentJob)(unsafe.Pointer(job)).Fdelta_progress)
  17100 		}
  17101 	}
  17102 	return ok
  17103 }
  17104 
  17105 // C documentation
  17106 //
  17107 //	// initialize the job struct with some tasks to perform
  17108 func InitSegmentJob(tls *libc.TLS, enc uintptr, job uintptr, start_row int32, end_row int32) {
  17109 	var v1 int32
  17110 	_ = v1
  17111 	(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(&struct{ uintptr }{(*WebPWorkerInterface)(unsafe.Pointer(WebPGetWorkerInterface(tls))).FInit})))(tls, job)
  17112 	(*SegmentJob)(unsafe.Pointer(job)).Fworker.Fdata1 = job
  17113 	(*SegmentJob)(unsafe.Pointer(job)).Fworker.Fdata2 = job + 1080
  17114 	(*SegmentJob)(unsafe.Pointer(job)).Fworker.Fhook = __ccgo_fp(DoSegmentsJob)
  17115 	VP8IteratorInit(tls, enc, job+1080)
  17116 	VP8IteratorSetRow(tls, job+1080, start_row)
  17117 	VP8IteratorSetCountDown(tls, job+1080, (end_row-start_row)*(*VP8Encoder)(unsafe.Pointer(enc)).Fmb_w)
  17118 	libc.Xmemset(tls, job+48, 0, uint64(1024))
  17119 	(*SegmentJob)(unsafe.Pointer(job)).Falpha = 0
  17120 	(*SegmentJob)(unsafe.Pointer(job)).Fuv_alpha = 0
  17121 	// only one of both jobs can record the progress, since we don't
  17122 	// expect the user's hook to be multi-thread safe
  17123 	if start_row == 0 {
  17124 		v1 = int32(20)
  17125 	} else {
  17126 		v1 = 0
  17127 	}
  17128 	(*SegmentJob)(unsafe.Pointer(job)).Fdelta_progress = v1
  17129 }
  17130 
  17131 // C documentation
  17132 //
  17133 //	// main entry point
  17134 func VP8EncAnalyze(tls *libc.TLS, enc uintptr) (r int32) {
  17135 	bp := tls.Alloc(4944)
  17136 	defer tls.Free(4944)
  17137 	var do_mt, do_segments, last_row, ok, total_mb int32
  17138 	var worker_interface uintptr
  17139 	var _ /* main_job at bp+0 */ SegmentJob
  17140 	_, _, _, _, _, _ = do_mt, do_segments, last_row, ok, total_mb, worker_interface
  17141 	ok = int32(1)
  17142 	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.
  17143 	if do_segments != 0 {
  17144 		last_row = (*VP8Encoder)(unsafe.Pointer(enc)).Fmb_h
  17145 		total_mb = last_row * (*VP8Encoder)(unsafe.Pointer(enc)).Fmb_w
  17146 		do_mt = 0
  17147 		worker_interface = WebPGetWorkerInterface(tls)
  17148 		if do_mt != 0 {
  17149 		} else {
  17150 			// Even for single-thread case, we use the generic Worker tools.
  17151 			InitSegmentJob(tls, enc, bp, 0, last_row)
  17152 			(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(&struct{ uintptr }{(*WebPWorkerInterface)(unsafe.Pointer(worker_interface)).FExecute})))(tls, bp)
  17153 			ok = ok & (*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*WebPWorkerInterface)(unsafe.Pointer(worker_interface)).FSync})))(tls, bp)
  17154 		}
  17155 		(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(&struct{ uintptr }{(*WebPWorkerInterface)(unsafe.Pointer(worker_interface)).FEnd})))(tls, bp)
  17156 		if ok != 0 {
  17157 			(*VP8Encoder)(unsafe.Pointer(enc)).Falpha = (**(**SegmentJob)(__ccgo_up(bp))).Falpha / total_mb
  17158 			(*VP8Encoder)(unsafe.Pointer(enc)).Fuv_alpha = (**(**SegmentJob)(__ccgo_up(bp))).Fuv_alpha / total_mb
  17159 			AssignSegments(tls, enc, bp+48)
  17160 		}
  17161 	} else { // Use only one default segment.
  17162 		ResetAllMBInfo(tls, enc)
  17163 	}
  17164 	if !(ok != 0) {
  17165 		return WebPEncodingSetError(tls, (*VP8Encoder)(unsafe.Pointer(enc)).Fpic, int32(VP8_ENC_ERROR_OUT_OF_MEMORY)) // imprecise
  17166 	}
  17167 	return ok
  17168 }
  17169 
  17170 const COST_CACHE_INTERVAL_SIZE_MAX = 500
  17171 const COST_MANAGER_MAX_FREE_LIST = 10
  17172 const SIZE_MAX3 = "UINT64_MAX"
  17173 const VALUES_IN_BYTE = 256
  17174 
  17175 var kHashMul10 = uint32(0x1e35a7bd)
  17176 
  17177 type CostModel = struct {
  17178 	Falpha    [256]uint32_t
  17179 	Fred      [256]uint32_t
  17180 	Fblue     [256]uint32_t
  17181 	Fdistance [40]uint32_t
  17182 	Fliteral  uintptr
  17183 }
  17184 
  17185 func ConvertPopulationCountTableToBitEstimates(tls *libc.TLS, num_symbols int32, population_counts uintptr, output uintptr) {
  17186 	var i, nonzeros int32
  17187 	var logsum, sum, v2, v3, v7, v8 uint32_t
  17188 	var v10, v5 uint32
  17189 	_, _, _, _, _, _, _, _, _, _ = i, logsum, nonzeros, sum, v10, v2, v3, v5, v7, v8
  17190 	sum = uint32(0)
  17191 	nonzeros = 0
  17192 	i = 0
  17193 	for {
  17194 		if !(i < num_symbols) {
  17195 			break
  17196 		}
  17197 		sum = sum + **(**uint32_t)(__ccgo_up(population_counts + uintptr(i)*4))
  17198 		if **(**uint32_t)(__ccgo_up(population_counts + uintptr(i)*4)) > uint32(0) {
  17199 			nonzeros = nonzeros + 1
  17200 		}
  17201 		goto _1
  17202 	_1:
  17203 		;
  17204 		i = i + 1
  17205 	}
  17206 	if nonzeros <= int32(1) {
  17207 		libc.Xmemset(tls, output, 0, uint64(num_symbols)*uint64(4))
  17208 	} else {
  17209 		v2 = sum
  17210 		if v2 < uint32(LOG_LOOKUP_IDX_MAX) {
  17211 			v5 = kLog2Table[v2]
  17212 		} else {
  17213 			v5 = (*(*func(*libc.TLS, uint32_t) uint32_t)(unsafe.Pointer(&struct{ uintptr }{VP8LFastLog2Slow})))(tls, v2)
  17214 		}
  17215 		v3 = v5
  17216 		goto _4
  17217 	_4:
  17218 		logsum = v3
  17219 		i = 0
  17220 		for {
  17221 			if !(i < num_symbols) {
  17222 				break
  17223 			}
  17224 			v7 = **(**uint32_t)(__ccgo_up(population_counts + uintptr(i)*4))
  17225 			if v7 < uint32(LOG_LOOKUP_IDX_MAX) {
  17226 				v10 = kLog2Table[v7]
  17227 			} else {
  17228 				v10 = (*(*func(*libc.TLS, uint32_t) uint32_t)(unsafe.Pointer(&struct{ uintptr }{VP8LFastLog2Slow})))(tls, v7)
  17229 			}
  17230 			v8 = v10
  17231 			goto _9
  17232 		_9:
  17233 			**(**uint32_t)(__ccgo_up(output + uintptr(i)*4)) = logsum - v8
  17234 			goto _6
  17235 		_6:
  17236 			;
  17237 			i = i + 1
  17238 		}
  17239 	}
  17240 }
  17241 
  17242 func CostModelBuild(tls *libc.TLS, m uintptr, xsize int32, cache_bits int32, refs uintptr) (r int32) {
  17243 	var histo uintptr
  17244 	var ok, v1, v2, v4 int32
  17245 	_, _, _, _, _ = histo, ok, v1, v2, v4
  17246 	ok = 0
  17247 	histo = VP8LAllocateHistogram(tls, cache_bits)
  17248 	if histo == libc.UintptrFromInt32(0) {
  17249 		goto Error
  17250 	}
  17251 	// The following code is similar to VP8LHistogramCreate but converts the
  17252 	// distance to plane code.
  17253 	VP8LHistogramInit(tls, histo, cache_bits, int32(1))
  17254 	VP8LHistogramStoreRefs(tls, refs, __ccgo_fp(VP8LDistanceToPlaneCode), xsize, histo)
  17255 	v1 = (*VP8LHistogram)(unsafe.Pointer(histo)).Fpalette_code_bits
  17256 	if v1 > 0 {
  17257 		v4 = int32(1) << v1
  17258 	} else {
  17259 		v4 = 0
  17260 	}
  17261 	v2 = libc.Int32FromInt32(NUM_LITERAL_CODES) + libc.Int32FromInt32(NUM_LENGTH_CODES) + v4
  17262 	goto _3
  17263 _3:
  17264 	ConvertPopulationCountTableToBitEstimates(tls, v2, (*VP8LHistogram)(unsafe.Pointer(histo)).Fliteral, (*CostModel)(unsafe.Pointer(m)).Fliteral)
  17265 	ConvertPopulationCountTableToBitEstimates(tls, int32(VALUES_IN_BYTE), histo+8, m+1024)
  17266 	ConvertPopulationCountTableToBitEstimates(tls, int32(VALUES_IN_BYTE), histo+1032, m+2048)
  17267 	ConvertPopulationCountTableToBitEstimates(tls, int32(VALUES_IN_BYTE), histo+2056, m)
  17268 	ConvertPopulationCountTableToBitEstimates(tls, int32(NUM_DISTANCE_CODES), histo+3080, m+3072)
  17269 	ok = int32(1)
  17270 	goto Error
  17271 Error:
  17272 	;
  17273 	VP8LFreeHistogram(tls, histo)
  17274 	return ok
  17275 }
  17276 
  17277 func GetLiteralCost(tls *libc.TLS, m uintptr, v uint32_t) (r int64_t) {
  17278 	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)))
  17279 }
  17280 
  17281 func GetCacheCost(tls *libc.TLS, m uintptr, idx uint32_t) (r int64_t) {
  17282 	var literal_idx int32
  17283 	_ = literal_idx
  17284 	literal_idx = int32(uint32(libc.Int32FromInt32(VALUES_IN_BYTE)+libc.Int32FromInt32(NUM_LENGTH_CODES)) + idx)
  17285 	return int64(**(**uint32_t)(__ccgo_up((*CostModel)(unsafe.Pointer(m)).Fliteral + uintptr(literal_idx)*4)))
  17286 }
  17287 
  17288 func GetLengthCost(tls *libc.TLS, m uintptr, length uint32_t) (r int64_t) {
  17289 	bp := tls.Alloc(16)
  17290 	defer tls.Free(16)
  17291 	var highest_bit, second_highest_bit, v1, v4, v5, v6 int32
  17292 	var prefix_code VP8LPrefixCode
  17293 	var v2, v3 uintptr
  17294 	var _ /* code at bp+0 */ int32
  17295 	var _ /* extra_bits at bp+4 */ int32
  17296 	_, _, _, _, _, _, _, _, _ = highest_bit, prefix_code, second_highest_bit, v1, v2, v3, v4, v5, v6
  17297 	v1 = int32(length)
  17298 	v2 = bp
  17299 	v3 = bp + 4
  17300 	if v1 < libc.Int32FromInt32(PREFIX_LOOKUP_IDX_MAX) {
  17301 		prefix_code = kPrefixEncodeCode[v1]
  17302 		**(**int32)(__ccgo_up(v2)) = int32(prefix_code.Fcode)
  17303 		**(**int32)(__ccgo_up(v3)) = int32(prefix_code.Fextra_bits)
  17304 	} else {
  17305 		v4 = v1
  17306 		v4 = v4 - 1
  17307 		v5 = v4
  17308 		v6 = int32(31) ^ libc.X__builtin_clz(tls, uint32(v5))
  17309 		goto _7
  17310 	_7:
  17311 		highest_bit = v6
  17312 		second_highest_bit = v4 >> (highest_bit - int32(1)) & int32(1)
  17313 		**(**int32)(__ccgo_up(v3)) = highest_bit - int32(1)
  17314 		**(**int32)(__ccgo_up(v2)) = int32(2)*highest_bit + second_highest_bit
  17315 	}
  17316 	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)
  17317 }
  17318 
  17319 func GetDistanceCost(tls *libc.TLS, m uintptr, distance2 uint32_t) (r int64_t) {
  17320 	bp := tls.Alloc(16)
  17321 	defer tls.Free(16)
  17322 	var highest_bit, second_highest_bit, v1, v4, v5, v6 int32
  17323 	var prefix_code VP8LPrefixCode
  17324 	var v2, v3 uintptr
  17325 	var _ /* code at bp+0 */ int32
  17326 	var _ /* extra_bits at bp+4 */ int32
  17327 	_, _, _, _, _, _, _, _, _ = highest_bit, prefix_code, second_highest_bit, v1, v2, v3, v4, v5, v6
  17328 	v1 = int32(distance2)
  17329 	v2 = bp
  17330 	v3 = bp + 4
  17331 	if v1 < libc.Int32FromInt32(PREFIX_LOOKUP_IDX_MAX) {
  17332 		prefix_code = kPrefixEncodeCode[v1]
  17333 		**(**int32)(__ccgo_up(v2)) = int32(prefix_code.Fcode)
  17334 		**(**int32)(__ccgo_up(v3)) = int32(prefix_code.Fextra_bits)
  17335 	} else {
  17336 		v4 = v1
  17337 		v4 = v4 - 1
  17338 		v5 = v4
  17339 		v6 = int32(31) ^ libc.X__builtin_clz(tls, uint32(v5))
  17340 		goto _7
  17341 	_7:
  17342 		highest_bit = v6
  17343 		second_highest_bit = v4 >> (highest_bit - int32(1)) & int32(1)
  17344 		**(**int32)(__ccgo_up(v3)) = highest_bit - int32(1)
  17345 		**(**int32)(__ccgo_up(v2)) = int32(2)*highest_bit + second_highest_bit
  17346 	}
  17347 	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)
  17348 }
  17349 
  17350 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) {
  17351 	var color, v3 uint32_t
  17352 	var cost_val, v10, v11, v9 int64_t
  17353 	var ix, key, key1, v1, v4, v6, v8 int32
  17354 	var v13 int64
  17355 	var v2 uintptr
  17356 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = color, cost_val, ix, key, key1, v1, v10, v11, v13, v2, v3, v4, v6, v8, v9
  17357 	cost_val = prev_cost
  17358 	color = **(**uint32_t)(__ccgo_up(argb3 + uintptr(idx)*4))
  17359 	if use_color_cache != 0 {
  17360 		v2 = hashers
  17361 		v3 = color
  17362 		v4 = int32(v3 * kHashMul10 >> (*VP8LColorCache)(unsafe.Pointer(v2)).Fhash_shift)
  17363 		goto _5
  17364 	_5:
  17365 		key1 = v4
  17366 		if **(**uint32_t)(__ccgo_up((*VP8LColorCache)(unsafe.Pointer(v2)).Fcolors + uintptr(key1)*4)) == v3 {
  17367 			v8 = key1
  17368 		} else {
  17369 			v8 = -int32(1)
  17370 		}
  17371 		v6 = v8
  17372 		goto _7
  17373 	_7:
  17374 		v1 = v6
  17375 	} else {
  17376 		v1 = -int32(1)
  17377 	}
  17378 	ix = v1
  17379 	if ix >= 0 {
  17380 		// use_color_cache is true and hashers contains color
  17381 		v9 = GetCacheCost(tls, cost_model, uint32(ix)) * int64(68)
  17382 		v10 = int64(100)
  17383 		if libc.BoolInt32(v9 < 0) == libc.BoolInt32(v10 < 0) {
  17384 			v13 = (v9 + v10/int64(2)) / v10
  17385 		} else {
  17386 			v13 = (v9 - v10/int64(2)) / v10
  17387 		}
  17388 		v11 = v13
  17389 		goto _12
  17390 	_12:
  17391 		cost_val = cost_val + v11
  17392 	} else {
  17393 		if use_color_cache != 0 {
  17394 			v2 = hashers
  17395 			v3 = color
  17396 			v1 = int32(v3 * kHashMul10 >> (*VP8LColorCache)(unsafe.Pointer(v2)).Fhash_shift)
  17397 			goto _17
  17398 		_17:
  17399 			key = v1
  17400 			**(**uint32_t)(__ccgo_up((*VP8LColorCache)(unsafe.Pointer(v2)).Fcolors + uintptr(key)*4)) = v3
  17401 		}
  17402 		v9 = GetLiteralCost(tls, cost_model, color) * int64(82)
  17403 		v10 = int64(100)
  17404 		if libc.BoolInt32(v9 < 0) == libc.BoolInt32(v10 < 0) {
  17405 			v13 = (v9 + v10/int64(2)) / v10
  17406 		} else {
  17407 			v13 = (v9 - v10/int64(2)) / v10
  17408 		}
  17409 		v11 = v13
  17410 		goto _21
  17411 	_21:
  17412 		cost_val = cost_val + v11
  17413 	}
  17414 	if **(**int64_t)(__ccgo_up(cost + uintptr(idx)*8)) > cost_val {
  17415 		**(**int64_t)(__ccgo_up(cost + uintptr(idx)*8)) = cost_val
  17416 		**(**uint16_t)(__ccgo_up(dist_array + uintptr(idx)*2)) = uint16(1) // only one is inserted.
  17417 	}
  17418 }
  17419 
  17420 // -----------------------------------------------------------------------------
  17421 // CostManager and interval handling
  17422 
  17423 // Empirical value to avoid high memory consumption but good for performance.
  17424 
  17425 // C documentation
  17426 //
  17427 //	// To perform backward reference every pixel at index 'index' is considered and
  17428 //	// the cost for the MAX_LENGTH following pixels computed. Those following pixels
  17429 //	// at index 'index' + k (k from 0 to MAX_LENGTH) have a cost of:
  17430 //	//     cost = distance cost at index + GetLengthCost(cost_model, k)
  17431 //	// and the minimum value is kept. GetLengthCost(cost_model, k) is cached in an
  17432 //	// array of size MAX_LENGTH.
  17433 //	// Instead of performing MAX_LENGTH comparisons per pixel, we keep track of the
  17434 //	// minimal values using intervals of constant cost.
  17435 //	// An interval is defined by the 'index' of the pixel that generated it and
  17436 //	// is only useful in a range of indices from 'start' to 'end' (exclusive), i.e.
  17437 //	// it contains the minimum value for pixels between start and end.
  17438 //	// Intervals are stored in a linked list and ordered by 'start'. When a new
  17439 //	// interval has a better value, old intervals are split or removed. There are
  17440 //	// therefore no overlapping intervals.
  17441 type CostInterval = struct {
  17442 	Fcost     int64_t
  17443 	Fstart    int32
  17444 	Fend      int32
  17445 	Findex    int32
  17446 	Fprevious uintptr
  17447 	Fnext     uintptr
  17448 }
  17449 
  17450 // C documentation
  17451 //
  17452 //	// The GetLengthCost(cost_model, k) are cached in a CostCacheInterval.
  17453 type CostCacheInterval = struct {
  17454 	Fcost  int64_t
  17455 	Fstart int32
  17456 	Fend   int32
  17457 }
  17458 
  17459 // C documentation
  17460 //
  17461 //	// This structure is in charge of managing intervals and costs.
  17462 //	// It caches the different CostCacheInterval, caches the different
  17463 //	// GetLengthCost(cost_model, k) in cost_cache and the CostInterval's (whose
  17464 //	// 'count' is limited by COST_CACHE_INTERVAL_SIZE_MAX).
  17465 type CostManager = struct {
  17466 	Fhead                 uintptr
  17467 	Fcount                int32
  17468 	Fcache_intervals      uintptr
  17469 	Fcache_intervals_size size_t
  17470 	Fcost_cache           [4095]int64_t
  17471 	Fcosts                uintptr
  17472 	Fdist_array           uintptr
  17473 	Fintervals            [10]CostInterval
  17474 	Ffree_intervals       uintptr
  17475 	Frecycled_intervals   uintptr
  17476 }
  17477 
  17478 func CostIntervalAddToFreeList(tls *libc.TLS, manager uintptr, interval uintptr) {
  17479 	(*CostInterval)(unsafe.Pointer(interval)).Fnext = (*CostManager)(unsafe.Pointer(manager)).Ffree_intervals
  17480 	(*CostManager)(unsafe.Pointer(manager)).Ffree_intervals = interval
  17481 }
  17482 
  17483 func CostIntervalIsInFreeList(tls *libc.TLS, manager uintptr, interval uintptr) (r int32) {
  17484 	return libc.BoolInt32(interval >= manager+32808 && interval <= manager+32808+uintptr(libc.Int32FromInt32(COST_MANAGER_MAX_FREE_LIST)-libc.Int32FromInt32(1))*40)
  17485 }
  17486 
  17487 func CostManagerInitFreeList(tls *libc.TLS, manager uintptr) {
  17488 	var i int32
  17489 	_ = i
  17490 	(*CostManager)(unsafe.Pointer(manager)).Ffree_intervals = libc.UintptrFromInt32(0)
  17491 	i = 0
  17492 	for {
  17493 		if !(i < int32(COST_MANAGER_MAX_FREE_LIST)) {
  17494 			break
  17495 		}
  17496 		CostIntervalAddToFreeList(tls, manager, manager+32808+uintptr(i)*40)
  17497 		goto _1
  17498 	_1:
  17499 		;
  17500 		i = i + 1
  17501 	}
  17502 }
  17503 
  17504 func DeleteIntervalList(tls *libc.TLS, manager uintptr, interval uintptr) {
  17505 	var next uintptr
  17506 	_ = next
  17507 	for interval != libc.UintptrFromInt32(0) {
  17508 		next = (*CostInterval)(unsafe.Pointer(interval)).Fnext
  17509 		if !(CostIntervalIsInFreeList(tls, manager, interval) != 0) {
  17510 			WebPSafeFree(tls, interval)
  17511 		} // else: do nothing
  17512 		interval = next
  17513 	}
  17514 }
  17515 
  17516 func CostManagerClear(tls *libc.TLS, manager uintptr) {
  17517 	if manager == libc.UintptrFromInt32(0) {
  17518 		return
  17519 	}
  17520 	WebPSafeFree(tls, (*CostManager)(unsafe.Pointer(manager)).Fcosts)
  17521 	WebPSafeFree(tls, (*CostManager)(unsafe.Pointer(manager)).Fcache_intervals)
  17522 	// Clear the interval lists.
  17523 	DeleteIntervalList(tls, manager, (*CostManager)(unsafe.Pointer(manager)).Fhead)
  17524 	(*CostManager)(unsafe.Pointer(manager)).Fhead = libc.UintptrFromInt32(0)
  17525 	DeleteIntervalList(tls, manager, (*CostManager)(unsafe.Pointer(manager)).Frecycled_intervals)
  17526 	(*CostManager)(unsafe.Pointer(manager)).Frecycled_intervals = libc.UintptrFromInt32(0)
  17527 	// Reset pointers, 'count' and 'cache_intervals_size'.
  17528 	libc.Xmemset(tls, manager, 0, uint64(33224))
  17529 	CostManagerInitFreeList(tls, manager)
  17530 }
  17531 
  17532 func CostManagerInit(tls *libc.TLS, manager uintptr, dist_array uintptr, pix_count int32, cost_model uintptr) (r int32) {
  17533 	var cost_cache_size, i, v1 int32
  17534 	var cost_val int64_t
  17535 	var cur uintptr
  17536 	_, _, _, _, _ = cost_cache_size, cost_val, cur, i, v1
  17537 	if pix_count > libc.Int32FromInt32(1)<<libc.Int32FromInt32(MAX_LENGTH_BITS)-libc.Int32FromInt32(1) {
  17538 		v1 = libc.Int32FromInt32(1)<<libc.Int32FromInt32(MAX_LENGTH_BITS) - libc.Int32FromInt32(1)
  17539 	} else {
  17540 		v1 = pix_count
  17541 	}
  17542 	cost_cache_size = v1
  17543 	(*CostManager)(unsafe.Pointer(manager)).Fcosts = libc.UintptrFromInt32(0)
  17544 	(*CostManager)(unsafe.Pointer(manager)).Fcache_intervals = libc.UintptrFromInt32(0)
  17545 	(*CostManager)(unsafe.Pointer(manager)).Fhead = libc.UintptrFromInt32(0)
  17546 	(*CostManager)(unsafe.Pointer(manager)).Frecycled_intervals = libc.UintptrFromInt32(0)
  17547 	(*CostManager)(unsafe.Pointer(manager)).Fcount = 0
  17548 	(*CostManager)(unsafe.Pointer(manager)).Fdist_array = dist_array
  17549 	CostManagerInitFreeList(tls, manager)
  17550 	// Fill in the 'cost_cache'.
  17551 	// Has to be done in two passes due to a GCC bug on i686
  17552 	// related to https://gcc.gnu.org/bugzilla/show_bug.cgi?id=323
  17553 	i = 0
  17554 	for {
  17555 		if !(i < cost_cache_size) {
  17556 			break
  17557 		}
  17558 		**(**int64_t)(__ccgo_up(manager + 32 + uintptr(i)*8)) = GetLengthCost(tls, cost_model, uint32(i))
  17559 		goto _2
  17560 	_2:
  17561 		;
  17562 		i = i + 1
  17563 	}
  17564 	(*CostManager)(unsafe.Pointer(manager)).Fcache_intervals_size = uint64(1)
  17565 	i = int32(1)
  17566 	for {
  17567 		if !(i < cost_cache_size) {
  17568 			break
  17569 		}
  17570 		// Get the number of bound intervals.
  17571 		if **(**int64_t)(__ccgo_up(manager + 32 + uintptr(i)*8)) != **(**int64_t)(__ccgo_up(manager + 32 + uintptr(i-int32(1))*8)) {
  17572 			(*CostManager)(unsafe.Pointer(manager)).Fcache_intervals_size = (*CostManager)(unsafe.Pointer(manager)).Fcache_intervals_size + 1
  17573 		}
  17574 		goto _3
  17575 	_3:
  17576 		;
  17577 		i = i + 1
  17578 	}
  17579 	// With the current cost model, we usually have below 20 intervals.
  17580 	// The worst case scenario with a cost model would be if every length has a
  17581 	// different cost, hence MAX_LENGTH but that is impossible with the current
  17582 	// implementation that spirals around a pixel.
  17583 	(*CostManager)(unsafe.Pointer(manager)).Fcache_intervals = WebPSafeMalloc(tls, (*CostManager)(unsafe.Pointer(manager)).Fcache_intervals_size, uint64(16))
  17584 	if (*CostManager)(unsafe.Pointer(manager)).Fcache_intervals == libc.UintptrFromInt32(0) {
  17585 		CostManagerClear(tls, manager)
  17586 		return 0
  17587 	}
  17588 	// Fill in the 'cache_intervals'.
  17589 	cur = (*CostManager)(unsafe.Pointer(manager)).Fcache_intervals
  17590 	// Consecutive values in 'cost_cache' are compared and if a big enough
  17591 	// difference is found, a new interval is created and bounded.
  17592 	(*CostCacheInterval)(unsafe.Pointer(cur)).Fstart = 0
  17593 	(*CostCacheInterval)(unsafe.Pointer(cur)).Fend = int32(1)
  17594 	(*CostCacheInterval)(unsafe.Pointer(cur)).Fcost = **(**int64_t)(__ccgo_up(manager + 32))
  17595 	i = int32(1)
  17596 	for {
  17597 		if !(i < cost_cache_size) {
  17598 			break
  17599 		}
  17600 		cost_val = **(**int64_t)(__ccgo_up(manager + 32 + uintptr(i)*8))
  17601 		if cost_val != (*CostCacheInterval)(unsafe.Pointer(cur)).Fcost {
  17602 			cur += 16
  17603 			// Initialize an interval.
  17604 			(*CostCacheInterval)(unsafe.Pointer(cur)).Fstart = i
  17605 			(*CostCacheInterval)(unsafe.Pointer(cur)).Fcost = cost_val
  17606 		}
  17607 		(*CostCacheInterval)(unsafe.Pointer(cur)).Fend = i + int32(1)
  17608 		goto _4
  17609 	_4:
  17610 		;
  17611 		i = i + 1
  17612 	}
  17613 	(*CostManager)(unsafe.Pointer(manager)).Fcosts = WebPSafeMalloc(tls, uint64(pix_count), uint64(8))
  17614 	if (*CostManager)(unsafe.Pointer(manager)).Fcosts == libc.UintptrFromInt32(0) {
  17615 		CostManagerClear(tls, manager)
  17616 		return 0
  17617 	}
  17618 	// Set the initial 'costs' to INT64_MAX for every pixel as we will keep the
  17619 	// minimum.
  17620 	i = 0
  17621 	for {
  17622 		if !(i < pix_count) {
  17623 			break
  17624 		}
  17625 		**(**int64_t)(__ccgo_up((*CostManager)(unsafe.Pointer(manager)).Fcosts + uintptr(i)*8)) = int64(libc.Uint64FromUint64(1)<<libc.Int32FromInt32(63) - libc.Uint64FromInt32(1))
  17626 		goto _5
  17627 	_5:
  17628 		;
  17629 		i = i + 1
  17630 	}
  17631 	return int32(1)
  17632 }
  17633 
  17634 // C documentation
  17635 //
  17636 //	// Given the cost and the position that define an interval, update the cost at
  17637 //	// pixel 'i' if it is smaller than the previously computed value.
  17638 func UpdateCost(tls *libc.TLS, manager uintptr, i int32, position int32, cost int64_t) {
  17639 	var k int32
  17640 	_ = k
  17641 	k = i - position
  17642 	if **(**int64_t)(__ccgo_up((*CostManager)(unsafe.Pointer(manager)).Fcosts + uintptr(i)*8)) > cost {
  17643 		**(**int64_t)(__ccgo_up((*CostManager)(unsafe.Pointer(manager)).Fcosts + uintptr(i)*8)) = cost
  17644 		**(**uint16_t)(__ccgo_up((*CostManager)(unsafe.Pointer(manager)).Fdist_array + uintptr(i)*2)) = uint16(k + int32(1))
  17645 	}
  17646 }
  17647 
  17648 // C documentation
  17649 //
  17650 //	// Given the cost and the position that define an interval, update the cost for
  17651 //	// all the pixels between 'start' and 'end' excluded.
  17652 func UpdateCostPerInterval(tls *libc.TLS, manager uintptr, start int32, end int32, position int32, cost int64_t) {
  17653 	var i int32
  17654 	_ = i
  17655 	i = start
  17656 	for {
  17657 		if !(i < end) {
  17658 			break
  17659 		}
  17660 		UpdateCost(tls, manager, i, position, cost)
  17661 		goto _1
  17662 	_1:
  17663 		;
  17664 		i = i + 1
  17665 	}
  17666 }
  17667 
  17668 // C documentation
  17669 //
  17670 //	// Given two intervals, make 'prev' be the previous one of 'next' in 'manager'.
  17671 func ConnectIntervals(tls *libc.TLS, manager uintptr, prev uintptr, next uintptr) {
  17672 	if prev != libc.UintptrFromInt32(0) {
  17673 		(*CostInterval)(unsafe.Pointer(prev)).Fnext = next
  17674 	} else {
  17675 		(*CostManager)(unsafe.Pointer(manager)).Fhead = next
  17676 	}
  17677 	if next != libc.UintptrFromInt32(0) {
  17678 		(*CostInterval)(unsafe.Pointer(next)).Fprevious = prev
  17679 	}
  17680 }
  17681 
  17682 // C documentation
  17683 //
  17684 //	// Pop an interval in the manager.
  17685 func PopInterval(tls *libc.TLS, manager uintptr, interval uintptr) {
  17686 	if interval == libc.UintptrFromInt32(0) {
  17687 		return
  17688 	}
  17689 	ConnectIntervals(tls, manager, (*CostInterval)(unsafe.Pointer(interval)).Fprevious, (*CostInterval)(unsafe.Pointer(interval)).Fnext)
  17690 	if CostIntervalIsInFreeList(tls, manager, interval) != 0 {
  17691 		CostIntervalAddToFreeList(tls, manager, interval)
  17692 	} else { // recycle regularly malloc'd intervals too
  17693 		(*CostInterval)(unsafe.Pointer(interval)).Fnext = (*CostManager)(unsafe.Pointer(manager)).Frecycled_intervals
  17694 		(*CostManager)(unsafe.Pointer(manager)).Frecycled_intervals = interval
  17695 	}
  17696 	(*CostManager)(unsafe.Pointer(manager)).Fcount = (*CostManager)(unsafe.Pointer(manager)).Fcount - 1
  17697 }
  17698 
  17699 // C documentation
  17700 //
  17701 //	// Update the cost at index i by going over all the stored intervals that
  17702 //	// overlap with i.
  17703 //	// If 'do_clean_intervals' is set to something different than 0, intervals that
  17704 //	// end before 'i' will be popped.
  17705 func UpdateCostAtIndex(tls *libc.TLS, manager uintptr, i int32, do_clean_intervals int32) {
  17706 	var current, next uintptr
  17707 	_, _ = current, next
  17708 	current = (*CostManager)(unsafe.Pointer(manager)).Fhead
  17709 	for current != libc.UintptrFromInt32(0) && (*CostInterval)(unsafe.Pointer(current)).Fstart <= i {
  17710 		next = (*CostInterval)(unsafe.Pointer(current)).Fnext
  17711 		if (*CostInterval)(unsafe.Pointer(current)).Fend <= i {
  17712 			if do_clean_intervals != 0 {
  17713 				// We have an outdated interval, remove it.
  17714 				PopInterval(tls, manager, current)
  17715 			}
  17716 		} else {
  17717 			UpdateCost(tls, manager, i, (*CostInterval)(unsafe.Pointer(current)).Findex, (*CostInterval)(unsafe.Pointer(current)).Fcost)
  17718 		}
  17719 		current = next
  17720 	}
  17721 }
  17722 
  17723 // C documentation
  17724 //
  17725 //	// Given a current orphan interval and its previous interval, before
  17726 //	// it was orphaned (which can be NULL), set it at the right place in the list
  17727 //	// of intervals using the 'start' ordering and the previous interval as a hint.
  17728 func PositionOrphanInterval(tls *libc.TLS, manager uintptr, current uintptr, previous uintptr) {
  17729 	if previous == libc.UintptrFromInt32(0) {
  17730 		previous = (*CostManager)(unsafe.Pointer(manager)).Fhead
  17731 	}
  17732 	for previous != libc.UintptrFromInt32(0) && (*CostInterval)(unsafe.Pointer(current)).Fstart < (*CostInterval)(unsafe.Pointer(previous)).Fstart {
  17733 		previous = (*CostInterval)(unsafe.Pointer(previous)).Fprevious
  17734 	}
  17735 	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 {
  17736 		previous = (*CostInterval)(unsafe.Pointer(previous)).Fnext
  17737 	}
  17738 	if previous != libc.UintptrFromInt32(0) {
  17739 		ConnectIntervals(tls, manager, current, (*CostInterval)(unsafe.Pointer(previous)).Fnext)
  17740 	} else {
  17741 		ConnectIntervals(tls, manager, current, (*CostManager)(unsafe.Pointer(manager)).Fhead)
  17742 	}
  17743 	ConnectIntervals(tls, manager, previous, current)
  17744 }
  17745 
  17746 // C documentation
  17747 //
  17748 //	// Insert an interval in the list contained in the manager by starting at
  17749 //	// 'interval_in' as a hint. The intervals are sorted by 'start' value.
  17750 func InsertInterval(tls *libc.TLS, manager uintptr, interval_in uintptr, cost int64_t, position int32, start int32, end int32) {
  17751 	var interval_new uintptr
  17752 	_ = interval_new
  17753 	if start >= end {
  17754 		return
  17755 	}
  17756 	if (*CostManager)(unsafe.Pointer(manager)).Fcount >= int32(COST_CACHE_INTERVAL_SIZE_MAX) {
  17757 		// Serialize the interval if we cannot store it.
  17758 		UpdateCostPerInterval(tls, manager, start, end, position, cost)
  17759 		return
  17760 	}
  17761 	if (*CostManager)(unsafe.Pointer(manager)).Ffree_intervals != libc.UintptrFromInt32(0) {
  17762 		interval_new = (*CostManager)(unsafe.Pointer(manager)).Ffree_intervals
  17763 		(*CostManager)(unsafe.Pointer(manager)).Ffree_intervals = (*CostInterval)(unsafe.Pointer(interval_new)).Fnext
  17764 	} else {
  17765 		if (*CostManager)(unsafe.Pointer(manager)).Frecycled_intervals != libc.UintptrFromInt32(0) {
  17766 			interval_new = (*CostManager)(unsafe.Pointer(manager)).Frecycled_intervals
  17767 			(*CostManager)(unsafe.Pointer(manager)).Frecycled_intervals = (*CostInterval)(unsafe.Pointer(interval_new)).Fnext
  17768 		} else { // malloc for good
  17769 			interval_new = WebPSafeMalloc(tls, uint64(1), uint64(40))
  17770 			if interval_new == libc.UintptrFromInt32(0) {
  17771 				// Write down the interval if we cannot create it.
  17772 				UpdateCostPerInterval(tls, manager, start, end, position, cost)
  17773 				return
  17774 			}
  17775 		}
  17776 	}
  17777 	(*CostInterval)(unsafe.Pointer(interval_new)).Fcost = cost
  17778 	(*CostInterval)(unsafe.Pointer(interval_new)).Findex = position
  17779 	(*CostInterval)(unsafe.Pointer(interval_new)).Fstart = start
  17780 	(*CostInterval)(unsafe.Pointer(interval_new)).Fend = end
  17781 	PositionOrphanInterval(tls, manager, interval_new, interval_in)
  17782 	(*CostManager)(unsafe.Pointer(manager)).Fcount = (*CostManager)(unsafe.Pointer(manager)).Fcount + 1
  17783 }
  17784 
  17785 // C documentation
  17786 //
  17787 //	// Given a new cost interval defined by its start at position, its length value
  17788 //	// and distance_cost, add its contributions to the previous intervals and costs.
  17789 //	// If handling the interval or one of its subintervals becomes to heavy, its
  17790 //	// contribution is added to the costs right away.
  17791 func PushInterval(tls *libc.TLS, manager uintptr, distance_cost int64_t, position int32, len1 int32) {
  17792 	var cost, cost_tmp int64_t
  17793 	var cost_cache_intervals, interval, interval_next uintptr
  17794 	var end, end_original, j, k, kSkipDistance, start, start_new, v3 int32
  17795 	var i size_t
  17796 	_, _, _, _, _, _, _, _, _, _, _, _, _, _ = cost, cost_cache_intervals, cost_tmp, end, end_original, i, interval, interval_next, j, k, kSkipDistance, start, start_new, v3
  17797 	interval = (*CostManager)(unsafe.Pointer(manager)).Fhead
  17798 	cost_cache_intervals = (*CostManager)(unsafe.Pointer(manager)).Fcache_intervals
  17799 	// If the interval is small enough, no need to deal with the heavy
  17800 	// interval logic, just serialize it right away. This constant is empirical.
  17801 	kSkipDistance = int32(10)
  17802 	if len1 < kSkipDistance {
  17803 		j = position
  17804 		for {
  17805 			if !(j < position+len1) {
  17806 				break
  17807 			}
  17808 			k = j - position
  17809 			cost_tmp = distance_cost + **(**int64_t)(__ccgo_up(manager + 32 + uintptr(k)*8))
  17810 			if **(**int64_t)(__ccgo_up((*CostManager)(unsafe.Pointer(manager)).Fcosts + uintptr(j)*8)) > cost_tmp {
  17811 				**(**int64_t)(__ccgo_up((*CostManager)(unsafe.Pointer(manager)).Fcosts + uintptr(j)*8)) = cost_tmp
  17812 				**(**uint16_t)(__ccgo_up((*CostManager)(unsafe.Pointer(manager)).Fdist_array + uintptr(j)*2)) = uint16(k + int32(1))
  17813 			}
  17814 			goto _1
  17815 		_1:
  17816 			;
  17817 			j = j + 1
  17818 		}
  17819 		return
  17820 	}
  17821 	i = uint64(0)
  17822 	for {
  17823 		if !(i < (*CostManager)(unsafe.Pointer(manager)).Fcache_intervals_size && (**(**CostCacheInterval)(__ccgo_up(cost_cache_intervals + uintptr(i)*16))).Fstart < len1) {
  17824 			break
  17825 		}
  17826 		// Define the intersection of the ith interval with the new one.
  17827 		start = position + (**(**CostCacheInterval)(__ccgo_up(cost_cache_intervals + uintptr(i)*16))).Fstart
  17828 		if (**(**CostCacheInterval)(__ccgo_up(cost_cache_intervals + uintptr(i)*16))).Fend > len1 {
  17829 			v3 = len1
  17830 		} else {
  17831 			v3 = (**(**CostCacheInterval)(__ccgo_up(cost_cache_intervals + uintptr(i)*16))).Fend
  17832 		}
  17833 		end = position + v3
  17834 		cost = distance_cost + (**(**CostCacheInterval)(__ccgo_up(cost_cache_intervals + uintptr(i)*16))).Fcost
  17835 		for {
  17836 			if !(interval != libc.UintptrFromInt32(0) && (*CostInterval)(unsafe.Pointer(interval)).Fstart < end) {
  17837 				break
  17838 			}
  17839 			interval_next = (*CostInterval)(unsafe.Pointer(interval)).Fnext
  17840 			// Make sure we have some overlap
  17841 			if start >= (*CostInterval)(unsafe.Pointer(interval)).Fend {
  17842 				goto _4
  17843 			}
  17844 			if cost >= (*CostInterval)(unsafe.Pointer(interval)).Fcost {
  17845 				// When intervals are represented, the lower, the better.
  17846 				// [**********************************************************[
  17847 				// start                                                    end
  17848 				//                   [----------------------------------[
  17849 				//                   interval->start        interval->end
  17850 				// If we are worse than what we already have, add whatever we have so
  17851 				// far up to interval.
  17852 				start_new = (*CostInterval)(unsafe.Pointer(interval)).Fend
  17853 				InsertInterval(tls, manager, interval, cost, position, start, (*CostInterval)(unsafe.Pointer(interval)).Fstart)
  17854 				start = start_new
  17855 				if start >= end {
  17856 					break
  17857 				}
  17858 				goto _4
  17859 			}
  17860 			if start <= (*CostInterval)(unsafe.Pointer(interval)).Fstart {
  17861 				if (*CostInterval)(unsafe.Pointer(interval)).Fend <= end {
  17862 					//                   [----------------------------------[
  17863 					//                   interval->start        interval->end
  17864 					// [**************************************************************[
  17865 					// start                                                        end
  17866 					// We can safely remove the old interval as it is fully included.
  17867 					PopInterval(tls, manager, interval)
  17868 				} else {
  17869 					//              [------------------------------------[
  17870 					//              interval->start          interval->end
  17871 					// [*****************************[
  17872 					// start                       end
  17873 					(*CostInterval)(unsafe.Pointer(interval)).Fstart = end
  17874 					break
  17875 				}
  17876 			} else {
  17877 				if end < (*CostInterval)(unsafe.Pointer(interval)).Fend {
  17878 					// [--------------------------------------------------------------[
  17879 					// interval->start                                    interval->end
  17880 					//                     [*****************************[
  17881 					//                     start                       end
  17882 					// We have to split the old interval as it fully contains the new one.
  17883 					end_original = (*CostInterval)(unsafe.Pointer(interval)).Fend
  17884 					(*CostInterval)(unsafe.Pointer(interval)).Fend = start
  17885 					InsertInterval(tls, manager, interval, (*CostInterval)(unsafe.Pointer(interval)).Fcost, (*CostInterval)(unsafe.Pointer(interval)).Findex, end, end_original)
  17886 					interval = (*CostInterval)(unsafe.Pointer(interval)).Fnext
  17887 					break
  17888 				} else {
  17889 					// [------------------------------------[
  17890 					// interval->start          interval->end
  17891 					//                     [*****************************[
  17892 					//                     start                       end
  17893 					(*CostInterval)(unsafe.Pointer(interval)).Fend = start
  17894 				}
  17895 			}
  17896 			goto _4
  17897 		_4:
  17898 			;
  17899 			interval = interval_next
  17900 		}
  17901 		// Insert the remaining interval from start to end.
  17902 		InsertInterval(tls, manager, interval, cost, position, start, end)
  17903 		goto _2
  17904 	_2:
  17905 		;
  17906 		i = i + 1
  17907 	}
  17908 }
  17909 
  17910 func BackwardReferencesHashChainDistanceOnly(tls *libc.TLS, xsize int32, ysize int32, argb uintptr, cache_bits int32, hash_chain uintptr, refs uintptr, dist_array uintptr) (r int32) {
  17911 	bp := tls.Alloc(32)
  17912 	defer tls.Free(32)
  17913 	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
  17914 	var cost_manager, cost_model, v6 uintptr
  17915 	var cost_model_size, literal_array_size size_t
  17916 	var offset_cost, prev_cost int64_t
  17917 	var _ /* hashers at bp+0 */ VP8LColorCache
  17918 	var _ /* len at bp+20 */ int32
  17919 	var _ /* len_j at bp+28 */ int32
  17920 	var _ /* offset at bp+16 */ int32
  17921 	var _ /* offset_j at bp+24 */ int32
  17922 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  17923 	ok = 0
  17924 	cc_init = 0
  17925 	pix_count = xsize * ysize
  17926 	use_color_cache = libc.BoolInt32(cache_bits > libc.Int32FromInt32(0))
  17927 	v1 = cache_bits
  17928 	if v1 > 0 {
  17929 		v4 = int32(1) << v1
  17930 	} else {
  17931 		v4 = 0
  17932 	}
  17933 	v2 = libc.Int32FromInt32(NUM_LITERAL_CODES) + libc.Int32FromInt32(NUM_LENGTH_CODES) + v4
  17934 	goto _3
  17935 _3:
  17936 	literal_array_size = uint64(4) * uint64(v2)
  17937 	cost_model_size = uint64(3240) + literal_array_size
  17938 	cost_model = WebPSafeCalloc(tls, uint64(1), cost_model_size)
  17939 	cost_manager = WebPSafeCalloc(tls, uint64(1), uint64(33224))
  17940 	offset_prev = -int32(1)
  17941 	len_prev = -int32(1)
  17942 	offset_cost = int64(-int32(1))
  17943 	first_offset_is_constant = -int32(1) // initialized with 'impossible' value
  17944 	reach = 0
  17945 	if cost_model == libc.UintptrFromInt32(0) || cost_manager == libc.UintptrFromInt32(0) {
  17946 		goto Error
  17947 	}
  17948 	(*CostModel)(unsafe.Pointer(cost_model)).Fliteral = cost_model + libc.UintptrFromInt32(1)*3240
  17949 	if use_color_cache != 0 {
  17950 		cc_init = VP8LColorCacheInit(tls, bp, cache_bits)
  17951 		if !(cc_init != 0) {
  17952 			goto Error
  17953 		}
  17954 	}
  17955 	if !(CostModelBuild(tls, cost_model, xsize, cache_bits, refs) != 0) {
  17956 		goto Error
  17957 	}
  17958 	if !(CostManagerInit(tls, cost_manager, dist_array, pix_count, cost_model) != 0) {
  17959 		goto Error
  17960 	}
  17961 	// We loop one pixel at a time, but store all currently best points to
  17962 	// non-processed locations from this point.
  17963 	**(**uint16_t)(__ccgo_up(dist_array)) = uint16(0)
  17964 	// Add first pixel as literal.
  17965 	AddSingleLiteralWithCostModel(tls, argb, bp, cost_model, 0, use_color_cache, 0, (*CostManager)(unsafe.Pointer(cost_manager)).Fcosts, dist_array)
  17966 	i = int32(1)
  17967 	for {
  17968 		if !(i < pix_count) {
  17969 			break
  17970 		}
  17971 		prev_cost = **(**int64_t)(__ccgo_up((*CostManager)(unsafe.Pointer(cost_manager)).Fcosts + uintptr(i-int32(1))*8))
  17972 		v6 = hash_chain
  17973 		v1 = i
  17974 		v2 = int32(**(**uint32_t)(__ccgo_up((*VP8LHashChain)(unsafe.Pointer(v6)).Foffset_length + uintptr(v1)*4)) >> int32(MAX_LENGTH_BITS))
  17975 		goto _9
  17976 	_9:
  17977 		**(**int32)(__ccgo_up(bp + 16)) = v2
  17978 		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)))
  17979 		goto _11
  17980 	_11:
  17981 		**(**int32)(__ccgo_up(bp + 20)) = v4
  17982 		// Try adding the pixel as a literal.
  17983 		AddSingleLiteralWithCostModel(tls, argb, bp, cost_model, i, use_color_cache, prev_cost, (*CostManager)(unsafe.Pointer(cost_manager)).Fcosts, dist_array)
  17984 		// If we are dealing with a non-literal.
  17985 		if **(**int32)(__ccgo_up(bp + 20)) >= int32(2) {
  17986 			if **(**int32)(__ccgo_up(bp + 16)) != offset_prev {
  17987 				code = VP8LDistanceToPlaneCode(tls, xsize, **(**int32)(__ccgo_up(bp + 16)))
  17988 				offset_cost = GetDistanceCost(tls, cost_model, uint32(code))
  17989 				first_offset_is_constant = int32(1)
  17990 				PushInterval(tls, cost_manager, prev_cost+offset_cost, i, **(**int32)(__ccgo_up(bp + 20)))
  17991 			} else {
  17992 				// Instead of considering all contributions from a pixel i by calling:
  17993 				//         PushInterval(cost_manager, prev_cost + offset_cost, i, len);
  17994 				// we optimize these contributions in case offset_cost stays the same
  17995 				// for consecutive pixels. This describes a set of pixels similar to a
  17996 				// previous set (e.g. constant color regions).
  17997 				if first_offset_is_constant != 0 {
  17998 					reach = i - int32(1) + len_prev - int32(1)
  17999 					first_offset_is_constant = 0
  18000 				}
  18001 				if i+**(**int32)(__ccgo_up(bp + 20))-int32(1) > reach {
  18002 					**(**int32)(__ccgo_up(bp + 28)) = 0
  18003 					// Figure out the last consecutive pixel within [i, reach + 1] with
  18004 					// the same offset.
  18005 					j = i
  18006 					for {
  18007 						if !(j <= reach) {
  18008 							break
  18009 						}
  18010 						v6 = hash_chain
  18011 						v1 = j + int32(1)
  18012 						v2 = int32(**(**uint32_t)(__ccgo_up((*VP8LHashChain)(unsafe.Pointer(v6)).Foffset_length + uintptr(v1)*4)) >> int32(MAX_LENGTH_BITS))
  18013 						goto _16
  18014 					_16:
  18015 						**(**int32)(__ccgo_up(bp + 24)) = v2
  18016 						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)))
  18017 						goto _18
  18018 					_18:
  18019 						**(**int32)(__ccgo_up(bp + 28)) = v4
  18020 						if **(**int32)(__ccgo_up(bp + 24)) != **(**int32)(__ccgo_up(bp + 16)) {
  18021 							v6 = hash_chain
  18022 							v1 = j
  18023 							v2 = int32(**(**uint32_t)(__ccgo_up((*VP8LHashChain)(unsafe.Pointer(v6)).Foffset_length + uintptr(v1)*4)) >> int32(MAX_LENGTH_BITS))
  18024 							goto _22
  18025 						_22:
  18026 							**(**int32)(__ccgo_up(bp + 24)) = v2
  18027 							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)))
  18028 							goto _24
  18029 						_24:
  18030 							**(**int32)(__ccgo_up(bp + 28)) = v4
  18031 							break
  18032 						}
  18033 						goto _12
  18034 					_12:
  18035 						;
  18036 						j = j + 1
  18037 					}
  18038 					// Update the cost at j - 1 and j.
  18039 					UpdateCostAtIndex(tls, cost_manager, j-int32(1), 0)
  18040 					UpdateCostAtIndex(tls, cost_manager, j, 0)
  18041 					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)))
  18042 					reach = j + **(**int32)(__ccgo_up(bp + 28)) - int32(1)
  18043 				}
  18044 			}
  18045 		}
  18046 		UpdateCostAtIndex(tls, cost_manager, i, int32(1))
  18047 		offset_prev = **(**int32)(__ccgo_up(bp + 16))
  18048 		len_prev = **(**int32)(__ccgo_up(bp + 20))
  18049 		goto _5
  18050 	_5:
  18051 		;
  18052 		i = i + 1
  18053 	}
  18054 	ok = libc.BoolInt32(!((*VP8LBackwardRefs)(unsafe.Pointer(refs)).Ferror1 != 0))
  18055 	goto Error
  18056 Error:
  18057 	;
  18058 	if cc_init != 0 {
  18059 		VP8LColorCacheClear(tls, bp)
  18060 	}
  18061 	CostManagerClear(tls, cost_manager)
  18062 	WebPSafeFree(tls, cost_model)
  18063 	WebPSafeFree(tls, cost_manager)
  18064 	return ok
  18065 }
  18066 
  18067 // C documentation
  18068 //
  18069 //	// We pack the path at the end of *dist_array and return
  18070 //	// a pointer to this part of the array. Example:
  18071 //	// dist_array = [1x2xx3x2] => packed [1x2x1232], chosen_path = [1232]
  18072 func TraceBackwards(tls *libc.TLS, dist_array uintptr, dist_array_size int32, chosen_path uintptr, chosen_path_size uintptr) {
  18073 	var cur, path uintptr
  18074 	var k int32
  18075 	_, _, _ = cur, k, path
  18076 	path = dist_array + uintptr(dist_array_size)*2
  18077 	cur = dist_array + uintptr(dist_array_size)*2 - uintptr(1)*2
  18078 	for cur >= dist_array {
  18079 		k = int32(**(**uint16_t)(__ccgo_up(cur)))
  18080 		path -= 2
  18081 		**(**uint16_t)(__ccgo_up(path)) = uint16(k)
  18082 		cur = cur - uintptr(k)*2
  18083 	}
  18084 	**(**uintptr)(__ccgo_up(chosen_path)) = path
  18085 	**(**int32)(__ccgo_up(chosen_path_size)) = int32((int64(dist_array+uintptr(dist_array_size)*2) - int64(path)) / 2)
  18086 }
  18087 
  18088 func BackwardReferencesHashChainFollowChosenPath(tls *libc.TLS, argb4 uintptr, cache_bits int32, chosen_path uintptr, chosen_path_size int32, hash_chain uintptr, refs uintptr) (r int32) {
  18089 	bp := tls.Alloc(16)
  18090 	defer tls.Free(16)
  18091 	var cc_init, i, idx1, ix, k, key, key1, len1, offset, ok, use_color_cache, v11, v14, v2, v9 int32
  18092 	var retval, retval1, retval2, v, v4 PixOrCopy
  18093 	var v7 uintptr
  18094 	var v8 uint32_t
  18095 	var _ /* hashers at bp+0 */ VP8LColorCache
  18096 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  18097 	use_color_cache = libc.BoolInt32(cache_bits > libc.Int32FromInt32(0))
  18098 	i = 0
  18099 	ok = 0
  18100 	cc_init = 0
  18101 	if use_color_cache != 0 {
  18102 		cc_init = VP8LColorCacheInit(tls, bp, cache_bits)
  18103 		if !(cc_init != 0) {
  18104 			goto Error
  18105 		}
  18106 	}
  18107 	VP8LClearBackwardRefs(tls, refs)
  18108 	ix = 0
  18109 	for {
  18110 		if !(ix < chosen_path_size) {
  18111 			break
  18112 		}
  18113 		len1 = int32(**(**uint16_t)(__ccgo_up(chosen_path + uintptr(ix)*2)))
  18114 		if len1 != int32(1) {
  18115 			v2 = int32(**(**uint32_t)(__ccgo_up((*VP8LHashChain)(unsafe.Pointer(hash_chain)).Foffset_length + uintptr(i)*4)) >> int32(MAX_LENGTH_BITS))
  18116 			goto _3
  18117 		_3:
  18118 			offset = v2
  18119 			retval.Fmode = uint8(kCopy)
  18120 			retval.Fargb_or_distance = uint32(offset)
  18121 			retval.Flen1 = uint16(len1)
  18122 			v4 = retval
  18123 			goto _5
  18124 		_5:
  18125 			VP8LBackwardRefsCursorAdd(tls, refs, v4)
  18126 			if use_color_cache != 0 {
  18127 				k = 0
  18128 				for {
  18129 					if !(k < len1) {
  18130 						break
  18131 					}
  18132 					v7 = bp
  18133 					v8 = **(**uint32_t)(__ccgo_up(argb4 + uintptr(i+k)*4))
  18134 					v2 = int32(v8 * kHashMul10 >> (*VP8LColorCache)(unsafe.Pointer(v7)).Fhash_shift)
  18135 					goto _10
  18136 				_10:
  18137 					key = v2
  18138 					**(**uint32_t)(__ccgo_up((*VP8LColorCache)(unsafe.Pointer(v7)).Fcolors + uintptr(key)*4)) = v8
  18139 					goto _6
  18140 				_6:
  18141 					;
  18142 					k = k + 1
  18143 				}
  18144 			}
  18145 			i = i + len1
  18146 		} else {
  18147 			if use_color_cache != 0 {
  18148 				v7 = bp
  18149 				v8 = **(**uint32_t)(__ccgo_up(argb4 + uintptr(i)*4))
  18150 				v9 = int32(v8 * kHashMul10 >> (*VP8LColorCache)(unsafe.Pointer(v7)).Fhash_shift)
  18151 				goto _15
  18152 			_15:
  18153 				key1 = v9
  18154 				if **(**uint32_t)(__ccgo_up((*VP8LColorCache)(unsafe.Pointer(v7)).Fcolors + uintptr(key1)*4)) == v8 {
  18155 					v14 = key1
  18156 				} else {
  18157 					v14 = -int32(1)
  18158 				}
  18159 				v11 = v14
  18160 				goto _17
  18161 			_17:
  18162 				v2 = v11
  18163 			} else {
  18164 				v2 = -int32(1)
  18165 			}
  18166 			idx1 = v2
  18167 			if idx1 >= 0 {
  18168 				// use_color_cache is true and hashers contains argb[i]
  18169 				// push pixel as a color cache index
  18170 				retval1.Fmode = uint8(kCacheIdx)
  18171 				retval1.Fargb_or_distance = uint32(idx1)
  18172 				retval1.Flen1 = uint16(1)
  18173 				v4 = retval1
  18174 				goto _20
  18175 			_20:
  18176 				v = v4
  18177 			} else {
  18178 				if use_color_cache != 0 {
  18179 					v7 = bp
  18180 					v8 = **(**uint32_t)(__ccgo_up(argb4 + uintptr(i)*4))
  18181 					v2 = int32(v8 * kHashMul10 >> (*VP8LColorCache)(unsafe.Pointer(v7)).Fhash_shift)
  18182 					goto _24
  18183 				_24:
  18184 					key = v2
  18185 					**(**uint32_t)(__ccgo_up((*VP8LColorCache)(unsafe.Pointer(v7)).Fcolors + uintptr(key)*4)) = v8
  18186 				}
  18187 				retval2.Fmode = uint8(kLiteral)
  18188 				retval2.Fargb_or_distance = **(**uint32_t)(__ccgo_up(argb4 + uintptr(i)*4))
  18189 				retval2.Flen1 = uint16(1)
  18190 				v4 = retval2
  18191 				goto _26
  18192 			_26:
  18193 				v = v4
  18194 			}
  18195 			VP8LBackwardRefsCursorAdd(tls, refs, v)
  18196 			i = i + 1
  18197 		}
  18198 		goto _1
  18199 	_1:
  18200 		;
  18201 		ix = ix + 1
  18202 	}
  18203 	ok = libc.BoolInt32(!((*VP8LBackwardRefs)(unsafe.Pointer(refs)).Ferror1 != 0))
  18204 	goto Error
  18205 Error:
  18206 	;
  18207 	if cc_init != 0 {
  18208 		VP8LColorCacheClear(tls, bp)
  18209 	}
  18210 	return ok
  18211 }
  18212 
  18213 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) {
  18214 	bp := tls.Alloc(16)
  18215 	defer tls.Free(16)
  18216 	var dist_array uintptr
  18217 	var dist_array_size, ok int32
  18218 	var _ /* chosen_path at bp+0 */ uintptr
  18219 	var _ /* chosen_path_size at bp+8 */ int32
  18220 	_, _, _ = dist_array, dist_array_size, ok
  18221 	ok = 0
  18222 	dist_array_size = xsize * ysize
  18223 	**(**uintptr)(__ccgo_up(bp)) = libc.UintptrFromInt32(0)
  18224 	**(**int32)(__ccgo_up(bp + 8)) = 0
  18225 	dist_array = WebPSafeMalloc(tls, uint64(dist_array_size), uint64(2))
  18226 	if dist_array == libc.UintptrFromInt32(0) {
  18227 		goto Error
  18228 	}
  18229 	if !(BackwardReferencesHashChainDistanceOnly(tls, xsize, ysize, argb, cache_bits, hash_chain, refs_src, dist_array) != 0) {
  18230 		goto Error
  18231 	}
  18232 	TraceBackwards(tls, dist_array, dist_array_size, bp, bp+8)
  18233 	if !(BackwardReferencesHashChainFollowChosenPath(tls, argb, cache_bits, **(**uintptr)(__ccgo_up(bp)), **(**int32)(__ccgo_up(bp + 8)), hash_chain, refs_dst) != 0) {
  18234 		goto Error
  18235 	}
  18236 	ok = int32(1)
  18237 	goto Error
  18238 Error:
  18239 	;
  18240 	WebPSafeFree(tls, dist_array)
  18241 	return ok
  18242 }
  18243 
  18244 const MIN_BLOCK_SIZE = 256
  18245 const MIN_LENGTH = 4
  18246 const SIZE_MAX4 = "_UI64_MAX"
  18247 const WINDOW_OFFSETS_SIZE_MAX = 32
  18248 
  18249 type PixOrCopyBlock = struct {
  18250 	Fnext  uintptr
  18251 	Fstart uintptr
  18252 	Fsize  int32
  18253 }
  18254 
  18255 var kHashMul11 = uint32(0x1e35a7bd)
  18256 
  18257 //------------------------------------------------------------------------------
  18258 
  18259 // Copyright 2012 Google Inc. All Rights Reserved.
  18260 //
  18261 // Use of this source code is governed by a BSD-style license
  18262 // that can be found in the COPYING file in the root of the source
  18263 // tree. An additional intellectual property rights grant can be found
  18264 // in the file PATENTS. All contributing project authors may
  18265 // be found in the AUTHORS file in the root of the source tree.
  18266 // -----------------------------------------------------------------------------
  18267 //
  18268 // Misc. common utility functions
  18269 //
  18270 // Authors: Skal (pascal.massimino@gmail.com)
  18271 //          Urvang (urvang@google.com)
  18272 
  18273 // Copyright 2011 Google Inc. All Rights Reserved.
  18274 //
  18275 // Use of this source code is governed by a BSD-style license
  18276 // that can be found in the COPYING file in the root of the source
  18277 // tree. An additional intellectual property rights grant can be found
  18278 // in the file PATENTS. All contributing project authors may
  18279 // be found in the AUTHORS file in the root of the source tree.
  18280 // -----------------------------------------------------------------------------
  18281 //
  18282 //   WebP encoder: main interface
  18283 //
  18284 // Author: Skal (pascal.massimino@gmail.com)
  18285 
  18286 // Copyright 2012 Google Inc. All Rights Reserved.
  18287 //
  18288 // Use of this source code is governed by a BSD-style license
  18289 // that can be found in the COPYING file in the root of the source
  18290 // tree. An additional intellectual property rights grant can be found
  18291 // in the file PATENTS. All contributing project authors may
  18292 // be found in the AUTHORS file in the root of the source tree.
  18293 // -----------------------------------------------------------------------------
  18294 //
  18295 //  Internal header for constants related to WebP file format.
  18296 //
  18297 // Author: Urvang (urvang@google.com)
  18298 
  18299 // Copyright 2010 Google Inc. All Rights Reserved.
  18300 //
  18301 // Use of this source code is governed by a BSD-style license
  18302 // that can be found in the COPYING file in the root of the source
  18303 // tree. An additional intellectual property rights grant can be found
  18304 // in the file PATENTS. All contributing project authors may
  18305 // be found in the AUTHORS file in the root of the source tree.
  18306 // -----------------------------------------------------------------------------
  18307 //
  18308 //  Common types + memory wrappers
  18309 //
  18310 // Author: Skal (pascal.massimino@gmail.com)
  18311 
  18312 // 1M window (4M bytes) minus 120 special codes for short distances.
  18313 
  18314 // Minimum number of pixels for which it is cheaper to encode a
  18315 // distance + length instead of each pixel as a literal.
  18316 
  18317 // -----------------------------------------------------------------------------
  18318 
  18319 var plane_to_code_lut = [128]uint8_t{
  18320 	0:   uint8(96),
  18321 	1:   uint8(73),
  18322 	2:   uint8(55),
  18323 	3:   uint8(39),
  18324 	4:   uint8(23),
  18325 	5:   uint8(13),
  18326 	6:   uint8(5),
  18327 	7:   uint8(1),
  18328 	8:   uint8(255),
  18329 	9:   uint8(255),
  18330 	10:  uint8(255),
  18331 	11:  uint8(255),
  18332 	12:  uint8(255),
  18333 	13:  uint8(255),
  18334 	14:  uint8(255),
  18335 	15:  uint8(255),
  18336 	16:  uint8(101),
  18337 	17:  uint8(78),
  18338 	18:  uint8(58),
  18339 	19:  uint8(42),
  18340 	20:  uint8(26),
  18341 	21:  uint8(16),
  18342 	22:  uint8(8),
  18343 	23:  uint8(2),
  18344 	25:  uint8(3),
  18345 	26:  uint8(9),
  18346 	27:  uint8(17),
  18347 	28:  uint8(27),
  18348 	29:  uint8(43),
  18349 	30:  uint8(59),
  18350 	31:  uint8(79),
  18351 	32:  uint8(102),
  18352 	33:  uint8(86),
  18353 	34:  uint8(62),
  18354 	35:  uint8(46),
  18355 	36:  uint8(32),
  18356 	37:  uint8(20),
  18357 	38:  uint8(10),
  18358 	39:  uint8(6),
  18359 	40:  uint8(4),
  18360 	41:  uint8(7),
  18361 	42:  uint8(11),
  18362 	43:  uint8(21),
  18363 	44:  uint8(33),
  18364 	45:  uint8(47),
  18365 	46:  uint8(63),
  18366 	47:  uint8(87),
  18367 	48:  uint8(105),
  18368 	49:  uint8(90),
  18369 	50:  uint8(70),
  18370 	51:  uint8(52),
  18371 	52:  uint8(37),
  18372 	53:  uint8(28),
  18373 	54:  uint8(18),
  18374 	55:  uint8(14),
  18375 	56:  uint8(12),
  18376 	57:  uint8(15),
  18377 	58:  uint8(19),
  18378 	59:  uint8(29),
  18379 	60:  uint8(38),
  18380 	61:  uint8(53),
  18381 	62:  uint8(71),
  18382 	63:  uint8(91),
  18383 	64:  uint8(110),
  18384 	65:  uint8(99),
  18385 	66:  uint8(82),
  18386 	67:  uint8(66),
  18387 	68:  uint8(48),
  18388 	69:  uint8(35),
  18389 	70:  uint8(30),
  18390 	71:  uint8(24),
  18391 	72:  uint8(22),
  18392 	73:  uint8(25),
  18393 	74:  uint8(31),
  18394 	75:  uint8(36),
  18395 	76:  uint8(49),
  18396 	77:  uint8(67),
  18397 	78:  uint8(83),
  18398 	79:  uint8(100),
  18399 	80:  uint8(115),
  18400 	81:  uint8(108),
  18401 	82:  uint8(94),
  18402 	83:  uint8(76),
  18403 	84:  uint8(64),
  18404 	85:  uint8(50),
  18405 	86:  uint8(44),
  18406 	87:  uint8(40),
  18407 	88:  uint8(34),
  18408 	89:  uint8(41),
  18409 	90:  uint8(45),
  18410 	91:  uint8(51),
  18411 	92:  uint8(65),
  18412 	93:  uint8(77),
  18413 	94:  uint8(95),
  18414 	95:  uint8(109),
  18415 	96:  uint8(118),
  18416 	97:  uint8(113),
  18417 	98:  uint8(103),
  18418 	99:  uint8(92),
  18419 	100: uint8(80),
  18420 	101: uint8(68),
  18421 	102: uint8(60),
  18422 	103: uint8(56),
  18423 	104: uint8(54),
  18424 	105: uint8(57),
  18425 	106: uint8(61),
  18426 	107: uint8(69),
  18427 	108: uint8(81),
  18428 	109: uint8(93),
  18429 	110: uint8(104),
  18430 	111: uint8(114),
  18431 	112: uint8(119),
  18432 	113: uint8(116),
  18433 	114: uint8(111),
  18434 	115: uint8(106),
  18435 	116: uint8(97),
  18436 	117: uint8(88),
  18437 	118: uint8(84),
  18438 	119: uint8(74),
  18439 	120: uint8(72),
  18440 	121: uint8(75),
  18441 	122: uint8(85),
  18442 	123: uint8(89),
  18443 	124: uint8(98),
  18444 	125: uint8(107),
  18445 	126: uint8(112),
  18446 	127: uint8(117),
  18447 }
  18448 
  18449 func VP8LDistanceToPlaneCode(tls *libc.TLS, xsize int32, dist int32) (r int32) {
  18450 	var xoffset, yoffset int32
  18451 	_, _ = xoffset, yoffset
  18452 	yoffset = dist / xsize
  18453 	xoffset = dist - yoffset*xsize
  18454 	if xoffset <= int32(8) && yoffset < int32(8) {
  18455 		return int32(plane_to_code_lut[yoffset*int32(16)+int32(8)-xoffset]) + int32(1)
  18456 	} else {
  18457 		if xoffset > xsize-int32(8) && yoffset < int32(7) {
  18458 			return int32(plane_to_code_lut[(yoffset+int32(1))*int32(16)+int32(8)+(xsize-xoffset)]) + int32(1)
  18459 		}
  18460 	}
  18461 	return dist + int32(120)
  18462 }
  18463 
  18464 // C documentation
  18465 //
  18466 //	// Returns the exact index where array1 and array2 are different. For an index
  18467 //	// inferior or equal to best_len_match, the return value just has to be strictly
  18468 //	// inferior to best_len_match. The current behavior is to return 0 if this index
  18469 //	// is best_len_match, and the index itself otherwise.
  18470 //	// If no two elements are the same, it returns max_limit.
  18471 func FindMatchLength(tls *libc.TLS, array1 uintptr, array2 uintptr, best_len_match int32, max_limit int32) (r int32) {
  18472 	// Before 'expensive' linear match, check if the two arrays match at the
  18473 	// current best length index.
  18474 	if **(**uint32_t)(__ccgo_up(array1 + uintptr(best_len_match)*4)) != **(**uint32_t)(__ccgo_up(array2 + uintptr(best_len_match)*4)) {
  18475 		return 0
  18476 	}
  18477 	return (*(*func(*libc.TLS, uintptr, uintptr, int32) int32)(unsafe.Pointer(&struct{ uintptr }{VP8LVectorMismatch})))(tls, array1, array2, max_limit)
  18478 }
  18479 
  18480 func VP8LClearBackwardRefs(tls *libc.TLS, refs uintptr) {
  18481 	if (*VP8LBackwardRefs)(unsafe.Pointer(refs)).Ftail != libc.UintptrFromInt32(0) {
  18482 		**(**uintptr)(__ccgo_up((*VP8LBackwardRefs)(unsafe.Pointer(refs)).Ftail)) = (*VP8LBackwardRefs)(unsafe.Pointer(refs)).Ffree_blocks // recycle all blocks at once
  18483 	}
  18484 	(*VP8LBackwardRefs)(unsafe.Pointer(refs)).Ffree_blocks = (*VP8LBackwardRefs)(unsafe.Pointer(refs)).Frefs
  18485 	(*VP8LBackwardRefs)(unsafe.Pointer(refs)).Ftail = refs + 8
  18486 	(*VP8LBackwardRefs)(unsafe.Pointer(refs)).Flast_block = libc.UintptrFromInt32(0)
  18487 	(*VP8LBackwardRefs)(unsafe.Pointer(refs)).Frefs = libc.UintptrFromInt32(0)
  18488 }
  18489 
  18490 func VP8LBackwardRefsClear(tls *libc.TLS, refs uintptr) {
  18491 	var next uintptr
  18492 	_ = next
  18493 	VP8LClearBackwardRefs(tls, refs)
  18494 	for (*VP8LBackwardRefs)(unsafe.Pointer(refs)).Ffree_blocks != libc.UintptrFromInt32(0) {
  18495 		next = (*PixOrCopyBlock)(unsafe.Pointer((*VP8LBackwardRefs)(unsafe.Pointer(refs)).Ffree_blocks)).Fnext
  18496 		WebPSafeFree(tls, (*VP8LBackwardRefs)(unsafe.Pointer(refs)).Ffree_blocks)
  18497 		(*VP8LBackwardRefs)(unsafe.Pointer(refs)).Ffree_blocks = next
  18498 	}
  18499 }
  18500 
  18501 // C documentation
  18502 //
  18503 //	// Swaps the content of two VP8LBackwardRefs.
  18504 func BackwardRefsSwap(tls *libc.TLS, refs1 uintptr, refs2 uintptr) {
  18505 	var point_to_refs1, point_to_refs2 int32
  18506 	var tmp VP8LBackwardRefs
  18507 	_, _, _ = point_to_refs1, point_to_refs2, tmp
  18508 	point_to_refs1 = libc.BoolInt32((*VP8LBackwardRefs)(unsafe.Pointer(refs1)).Ftail != libc.UintptrFromInt32(0) && (*VP8LBackwardRefs)(unsafe.Pointer(refs1)).Ftail == refs1+8)
  18509 	point_to_refs2 = libc.BoolInt32((*VP8LBackwardRefs)(unsafe.Pointer(refs2)).Ftail != libc.UintptrFromInt32(0) && (*VP8LBackwardRefs)(unsafe.Pointer(refs2)).Ftail == refs2+8)
  18510 	tmp = **(**VP8LBackwardRefs)(__ccgo_up(refs1))
  18511 	**(**VP8LBackwardRefs)(__ccgo_up(refs1)) = **(**VP8LBackwardRefs)(__ccgo_up(refs2))
  18512 	**(**VP8LBackwardRefs)(__ccgo_up(refs2)) = tmp
  18513 	if point_to_refs2 != 0 {
  18514 		(*VP8LBackwardRefs)(unsafe.Pointer(refs1)).Ftail = refs1 + 8
  18515 	}
  18516 	if point_to_refs1 != 0 {
  18517 		(*VP8LBackwardRefs)(unsafe.Pointer(refs2)).Ftail = refs2 + 8
  18518 	}
  18519 }
  18520 
  18521 func VP8LBackwardRefsInit(tls *libc.TLS, refs uintptr, block_size int32) {
  18522 	var v1 int32
  18523 	_ = v1
  18524 	libc.Xmemset(tls, refs, 0, uint64(40))
  18525 	(*VP8LBackwardRefs)(unsafe.Pointer(refs)).Ftail = refs + 8
  18526 	if block_size < int32(MIN_BLOCK_SIZE) {
  18527 		v1 = int32(MIN_BLOCK_SIZE)
  18528 	} else {
  18529 		v1 = block_size
  18530 	}
  18531 	(*VP8LBackwardRefs)(unsafe.Pointer(refs)).Fblock_size = v1
  18532 }
  18533 
  18534 func VP8LRefsCursorInit(tls *libc.TLS, refs uintptr) (r VP8LRefsCursor) {
  18535 	var c VP8LRefsCursor
  18536 	_ = c
  18537 	c.Fcur_block = (*VP8LBackwardRefs)(unsafe.Pointer(refs)).Frefs
  18538 	if (*VP8LBackwardRefs)(unsafe.Pointer(refs)).Frefs != libc.UintptrFromInt32(0) {
  18539 		c.Fcur_pos = (*PixOrCopyBlock)(unsafe.Pointer(c.Fcur_block)).Fstart
  18540 		c.Flast_pos = c.Fcur_pos + uintptr((*PixOrCopyBlock)(unsafe.Pointer(c.Fcur_block)).Fsize)*8
  18541 	} else {
  18542 		c.Fcur_pos = libc.UintptrFromInt32(0)
  18543 		c.Flast_pos = libc.UintptrFromInt32(0)
  18544 	}
  18545 	return c
  18546 }
  18547 
  18548 func VP8LRefsCursorNextBlock(tls *libc.TLS, c uintptr) {
  18549 	var b, v1 uintptr
  18550 	_, _ = b, v1
  18551 	b = (*PixOrCopyBlock)(unsafe.Pointer((*VP8LRefsCursor)(unsafe.Pointer(c)).Fcur_block)).Fnext
  18552 	if b == libc.UintptrFromInt32(0) {
  18553 		v1 = libc.UintptrFromInt32(0)
  18554 	} else {
  18555 		v1 = (*PixOrCopyBlock)(unsafe.Pointer(b)).Fstart
  18556 	}
  18557 	(*VP8LRefsCursor)(unsafe.Pointer(c)).Fcur_pos = v1
  18558 	if b == libc.UintptrFromInt32(0) {
  18559 		v1 = libc.UintptrFromInt32(0)
  18560 	} else {
  18561 		v1 = (*PixOrCopyBlock)(unsafe.Pointer(b)).Fstart + uintptr((*PixOrCopyBlock)(unsafe.Pointer(b)).Fsize)*8
  18562 	}
  18563 	(*VP8LRefsCursor)(unsafe.Pointer(c)).Flast_pos = v1
  18564 	(*VP8LRefsCursor)(unsafe.Pointer(c)).Fcur_block = b
  18565 }
  18566 
  18567 // C documentation
  18568 //
  18569 //	// Create a new block, either from the free list or allocated
  18570 func BackwardRefsNewBlock(tls *libc.TLS, refs uintptr) (r uintptr) {
  18571 	var b uintptr
  18572 	var total_size size_t
  18573 	_, _ = b, total_size
  18574 	b = (*VP8LBackwardRefs)(unsafe.Pointer(refs)).Ffree_blocks
  18575 	if b == libc.UintptrFromInt32(0) { // allocate new memory chunk
  18576 		total_size = uint64(24) + uint64((*VP8LBackwardRefs)(unsafe.Pointer(refs)).Fblock_size)*uint64(8)
  18577 		b = WebPSafeMalloc(tls, uint64(1), total_size)
  18578 		if b == libc.UintptrFromInt32(0) {
  18579 			**(**int32)(__ccgo_up(refs + 4)) |= int32(1)
  18580 			return libc.UintptrFromInt32(0)
  18581 		}
  18582 		(*PixOrCopyBlock)(unsafe.Pointer(b)).Fstart = b + libc.UintptrFromInt64(24) // not always aligned
  18583 	} else { // recycle from free-list
  18584 		(*VP8LBackwardRefs)(unsafe.Pointer(refs)).Ffree_blocks = (*PixOrCopyBlock)(unsafe.Pointer(b)).Fnext
  18585 	}
  18586 	**(**uintptr)(__ccgo_up((*VP8LBackwardRefs)(unsafe.Pointer(refs)).Ftail)) = b
  18587 	(*VP8LBackwardRefs)(unsafe.Pointer(refs)).Ftail = b
  18588 	(*VP8LBackwardRefs)(unsafe.Pointer(refs)).Flast_block = b
  18589 	(*PixOrCopyBlock)(unsafe.Pointer(b)).Fnext = libc.UintptrFromInt32(0)
  18590 	(*PixOrCopyBlock)(unsafe.Pointer(b)).Fsize = 0
  18591 	return b
  18592 }
  18593 
  18594 // C documentation
  18595 //
  18596 //	// Return 1 on success, 0 on error.
  18597 func BackwardRefsClone(tls *libc.TLS, from uintptr, to uintptr) (r int32) {
  18598 	var block_from, block_to uintptr
  18599 	_, _ = block_from, block_to
  18600 	block_from = (*VP8LBackwardRefs)(unsafe.Pointer(from)).Frefs
  18601 	VP8LClearBackwardRefs(tls, to)
  18602 	for block_from != libc.UintptrFromInt32(0) {
  18603 		block_to = BackwardRefsNewBlock(tls, to)
  18604 		if block_to == libc.UintptrFromInt32(0) {
  18605 			return 0
  18606 		}
  18607 		libc.Xmemcpy(tls, (*PixOrCopyBlock)(unsafe.Pointer(block_to)).Fstart, (*PixOrCopyBlock)(unsafe.Pointer(block_from)).Fstart, uint64((*PixOrCopyBlock)(unsafe.Pointer(block_from)).Fsize)*uint64(8))
  18608 		(*PixOrCopyBlock)(unsafe.Pointer(block_to)).Fsize = (*PixOrCopyBlock)(unsafe.Pointer(block_from)).Fsize
  18609 		block_from = (*PixOrCopyBlock)(unsafe.Pointer(block_from)).Fnext
  18610 	}
  18611 	return int32(1)
  18612 }
  18613 
  18614 func VP8LBackwardRefsCursorAdd(tls *libc.TLS, refs uintptr, v PixOrCopy) {
  18615 	var b, v2 uintptr
  18616 	var v1 int32
  18617 	_, _, _ = b, v1, v2
  18618 	b = (*VP8LBackwardRefs)(unsafe.Pointer(refs)).Flast_block
  18619 	if b == libc.UintptrFromInt32(0) || (*PixOrCopyBlock)(unsafe.Pointer(b)).Fsize == (*VP8LBackwardRefs)(unsafe.Pointer(refs)).Fblock_size {
  18620 		b = BackwardRefsNewBlock(tls, refs)
  18621 		if b == libc.UintptrFromInt32(0) {
  18622 			return
  18623 		} // refs->error is set
  18624 	}
  18625 	v2 = b + 16
  18626 	v1 = *(*int32)(unsafe.Pointer(v2))
  18627 	*(*int32)(unsafe.Pointer(v2)) = *(*int32)(unsafe.Pointer(v2)) + 1
  18628 	**(**PixOrCopy)(__ccgo_up((*PixOrCopyBlock)(unsafe.Pointer(b)).Fstart + uintptr(v1)*8)) = v
  18629 }
  18630 
  18631 // -----------------------------------------------------------------------------
  18632 // Hash chains
  18633 
  18634 func VP8LHashChainInit(tls *libc.TLS, p uintptr, size int32) (r int32) {
  18635 	(*VP8LHashChain)(unsafe.Pointer(p)).Foffset_length = WebPSafeMalloc(tls, uint64(size), uint64(4))
  18636 	if (*VP8LHashChain)(unsafe.Pointer(p)).Foffset_length == libc.UintptrFromInt32(0) {
  18637 		return 0
  18638 	}
  18639 	(*VP8LHashChain)(unsafe.Pointer(p)).Fsize = size
  18640 	return int32(1)
  18641 }
  18642 
  18643 func VP8LHashChainClear(tls *libc.TLS, p uintptr) {
  18644 	WebPSafeFree(tls, (*VP8LHashChain)(unsafe.Pointer(p)).Foffset_length)
  18645 	(*VP8LHashChain)(unsafe.Pointer(p)).Fsize = 0
  18646 	(*VP8LHashChain)(unsafe.Pointer(p)).Foffset_length = libc.UintptrFromInt32(0)
  18647 }
  18648 
  18649 // -----------------------------------------------------------------------------
  18650 
  18651 var kHashMultiplierHi = uint32(0xc6a4a793)
  18652 var kHashMultiplierLo = uint32(0x5bd1e996)
  18653 
  18654 func GetPixPairHash64(tls *libc.TLS, argb uintptr) (r uint32_t) {
  18655 	var key uint32_t
  18656 	_ = key
  18657 	key = **(**uint32_t)(__ccgo_up(argb + 1*4)) * kHashMultiplierHi
  18658 	key = key + **(**uint32_t)(__ccgo_up(argb))*kHashMultiplierLo
  18659 	key = key >> (libc.Int32FromInt32(32) - libc.Int32FromInt32(HASH_BITS))
  18660 	return key
  18661 }
  18662 
  18663 // C documentation
  18664 //
  18665 //	// Returns the maximum number of hash chain lookups to do for a
  18666 //	// given compression quality. Return value in range [8, 86].
  18667 func GetMaxItersForQuality(tls *libc.TLS, quality int32) (r int32) {
  18668 	return int32(8) + quality*quality/int32(128)
  18669 }
  18670 
  18671 func GetWindowSizeForHashChain(tls *libc.TLS, quality int32, xsize int32) (r int32) {
  18672 	var max_window_size, v1, v2, v3 int32
  18673 	_, _, _, _ = max_window_size, v1, v2, v3
  18674 	if quality > int32(75) {
  18675 		v1 = libc.Int32FromInt32(1)<<libc.Int32FromInt32(WINDOW_SIZE_BITS) - libc.Int32FromInt32(120)
  18676 	} else {
  18677 		if quality > int32(50) {
  18678 			v2 = xsize << int32(8)
  18679 		} else {
  18680 			if quality > int32(25) {
  18681 				v3 = xsize << int32(6)
  18682 			} else {
  18683 				v3 = xsize << int32(4)
  18684 			}
  18685 			v2 = v3
  18686 		}
  18687 		v1 = v2
  18688 	}
  18689 	max_window_size = v1
  18690 	if max_window_size > libc.Int32FromInt32(1)<<libc.Int32FromInt32(WINDOW_SIZE_BITS)-libc.Int32FromInt32(120) {
  18691 		v1 = libc.Int32FromInt32(1)<<libc.Int32FromInt32(WINDOW_SIZE_BITS) - libc.Int32FromInt32(120)
  18692 	} else {
  18693 		v1 = max_window_size
  18694 	}
  18695 	return v1
  18696 }
  18697 
  18698 func MaxFindCopyLength(tls *libc.TLS, len1 int32) (r int32) {
  18699 	var v1 int32
  18700 	_ = v1
  18701 	if len1 < libc.Int32FromInt32(1)<<libc.Int32FromInt32(MAX_LENGTH_BITS)-libc.Int32FromInt32(1) {
  18702 		v1 = len1
  18703 	} else {
  18704 		v1 = libc.Int32FromInt32(1)<<libc.Int32FromInt32(MAX_LENGTH_BITS) - libc.Int32FromInt32(1)
  18705 	}
  18706 	return v1
  18707 }
  18708 
  18709 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) {
  18710 	bp := tls.Alloc(16)
  18711 	defer tls.Free(16)
  18712 	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
  18713 	var argb_start, chain, hash_to_first_index uintptr
  18714 	var base_position, best_argb, best_distance, hash_code, len1, max_base_position, window_size, v1 uint32_t
  18715 	var v12 bool
  18716 	var v8 uint32
  18717 	var _ /* tmp at bp+0 */ [2]uint32_t
  18718 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  18719 	size = xsize * ysize
  18720 	iter_max = GetMaxItersForQuality(tls, quality)
  18721 	window_size = uint32(GetWindowSizeForHashChain(tls, quality, xsize))
  18722 	remaining_percent = percent_range
  18723 	percent_start = **(**int32)(__ccgo_up(percent))
  18724 	// Temporarily use the p->offset_length as a hash chain.
  18725 	chain = (*VP8LHashChain)(unsafe.Pointer(p)).Foffset_length
  18726 	if size <= int32(2) {
  18727 		v1 = libc.Uint32FromInt32(0)
  18728 		**(**uint32_t)(__ccgo_up((*VP8LHashChain)(unsafe.Pointer(p)).Foffset_length + uintptr(size-int32(1))*4)) = v1
  18729 		**(**uint32_t)(__ccgo_up((*VP8LHashChain)(unsafe.Pointer(p)).Foffset_length)) = v1
  18730 		return int32(1)
  18731 	}
  18732 	hash_to_first_index = WebPSafeMalloc(tls, uint64(libc.Int32FromInt32(1)<<libc.Int32FromInt32(HASH_BITS)), uint64(4))
  18733 	if hash_to_first_index == libc.UintptrFromInt32(0) {
  18734 		return WebPEncodingSetError(tls, pic, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  18735 	}
  18736 	percent_range = remaining_percent / int32(2)
  18737 	remaining_percent = remaining_percent - percent_range
  18738 	// Set the int32_t array to -1.
  18739 	libc.Xmemset(tls, hash_to_first_index, int32(0xff), uint64(libc.Int32FromInt32(1)<<libc.Int32FromInt32(HASH_BITS))*libc.Uint64FromInt64(4))
  18740 	// Fill the chain linking pixels with the same hash.
  18741 	argb_comp = libc.BoolInt32(**(**uint32_t)(__ccgo_up(argb)) == **(**uint32_t)(__ccgo_up(argb + 1*4)))
  18742 	pos = 0
  18743 	for {
  18744 		if !(pos < size-int32(2)) {
  18745 			break
  18746 		}
  18747 		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)))
  18748 		if argb_comp != 0 && argb_comp_next != 0 {
  18749 			len1 = uint32(1)
  18750 			(**(**[2]uint32_t)(__ccgo_up(bp)))[0] = **(**uint32_t)(__ccgo_up(argb + uintptr(pos)*4))
  18751 			// Figure out how far the pixels are the same.
  18752 			// The last pixel has a different 64 bit hash, as its next pixel does
  18753 			// not have the same color, so we just need to get to the last pixel equal
  18754 			// to its follower.
  18755 			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)) {
  18756 				len1 = len1 + 1
  18757 			}
  18758 			if len1 > uint32(libc.Int32FromInt32(1)<<libc.Int32FromInt32(MAX_LENGTH_BITS)-libc.Int32FromInt32(1)) {
  18759 				// Skip the pixels that match for distance=1 and length>MAX_LENGTH
  18760 				// because they are linked to their predecessor and we automatically
  18761 				// check that in the main for loop below. Skipping means setting no
  18762 				// predecessor in the chain, hence -1.
  18763 				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))
  18764 				pos = int32(uint32(pos) + (len1 - uint32(libc.Int32FromInt32(1)<<libc.Int32FromInt32(MAX_LENGTH_BITS)-libc.Int32FromInt32(1))))
  18765 				len1 = uint32(libc.Int32FromInt32(1)<<libc.Int32FromInt32(MAX_LENGTH_BITS) - libc.Int32FromInt32(1))
  18766 			}
  18767 			// Process the rest of the hash chain.
  18768 			for len1 != 0 {
  18769 				v1 = len1
  18770 				len1 = len1 - 1
  18771 				(**(**[2]uint32_t)(__ccgo_up(bp)))[int32(1)] = v1
  18772 				hash_code = GetPixPairHash64(tls, bp)
  18773 				**(**int32_t)(__ccgo_up(chain + uintptr(pos)*4)) = **(**int32_t)(__ccgo_up(hash_to_first_index + uintptr(hash_code)*4))
  18774 				v4 = pos
  18775 				pos = pos + 1
  18776 				**(**int32_t)(__ccgo_up(hash_to_first_index + uintptr(hash_code)*4)) = v4
  18777 			}
  18778 			argb_comp = 0
  18779 		} else {
  18780 			// Just move one pixel forward.
  18781 			hash_code = GetPixPairHash64(tls, argb+uintptr(pos)*4)
  18782 			**(**int32_t)(__ccgo_up(chain + uintptr(pos)*4)) = **(**int32_t)(__ccgo_up(hash_to_first_index + uintptr(hash_code)*4))
  18783 			v4 = pos
  18784 			pos = pos + 1
  18785 			**(**int32_t)(__ccgo_up(hash_to_first_index + uintptr(hash_code)*4)) = v4
  18786 			argb_comp = argb_comp_next
  18787 		}
  18788 		if !(WebPReportProgress(tls, pic, percent_start+percent_range*pos/(size-int32(2)), percent) != 0) {
  18789 			WebPSafeFree(tls, hash_to_first_index)
  18790 			return 0
  18791 		}
  18792 		goto _2
  18793 	_2:
  18794 	}
  18795 	// Process the penultimate pixel.
  18796 	**(**int32_t)(__ccgo_up(chain + uintptr(pos)*4)) = **(**int32_t)(__ccgo_up(hash_to_first_index + uintptr(GetPixPairHash64(tls, argb+uintptr(pos)*4))*4))
  18797 	WebPSafeFree(tls, hash_to_first_index)
  18798 	percent_start = percent_start + percent_range
  18799 	if !(WebPReportProgress(tls, pic, percent_start, percent) != 0) {
  18800 		return 0
  18801 	}
  18802 	percent_range = remaining_percent
  18803 	// Find the best match interval at each pixel, defined by an offset to the
  18804 	// pixel and a length. The right-most pixel cannot match anything to the right
  18805 	// (hence a best length of 0) and the left-most pixel nothing to the left
  18806 	// (hence an offset of 0).
  18807 	v1 = libc.Uint32FromInt32(0)
  18808 	**(**uint32_t)(__ccgo_up((*VP8LHashChain)(unsafe.Pointer(p)).Foffset_length + uintptr(size-int32(1))*4)) = v1
  18809 	**(**uint32_t)(__ccgo_up((*VP8LHashChain)(unsafe.Pointer(p)).Foffset_length)) = v1
  18810 	base_position = uint32(size - int32(2))
  18811 	for {
  18812 		if !(base_position > uint32(0)) {
  18813 			break
  18814 		}
  18815 		max_len = MaxFindCopyLength(tls, int32(uint32(size-int32(1))-base_position))
  18816 		argb_start = argb + uintptr(base_position)*4
  18817 		iter = iter_max
  18818 		best_length = 0
  18819 		best_distance = uint32(0)
  18820 		if base_position > window_size {
  18821 			v8 = base_position - window_size
  18822 		} else {
  18823 			v8 = uint32(0)
  18824 		}
  18825 		min_pos = int32(v8)
  18826 		if max_len < int32(256) {
  18827 			v4 = max_len
  18828 		} else {
  18829 			v4 = int32(256)
  18830 		}
  18831 		length_max = v4
  18832 		pos = **(**int32_t)(__ccgo_up(chain + uintptr(base_position)*4))
  18833 		if !(low_effort != 0) {
  18834 			// Heuristic: use the comparison with the above line as an initialization.
  18835 			if base_position >= uint32(xsize) {
  18836 				curr_length = FindMatchLength(tls, argb_start-uintptr(xsize)*4, argb_start, best_length, max_len)
  18837 				if curr_length > best_length {
  18838 					best_length = curr_length
  18839 					best_distance = uint32(xsize)
  18840 				}
  18841 				iter = iter - 1
  18842 			}
  18843 			// Heuristic: compare to the previous pixel.
  18844 			curr_length = FindMatchLength(tls, argb_start-uintptr(1)*4, argb_start, best_length, max_len)
  18845 			if curr_length > best_length {
  18846 				best_length = curr_length
  18847 				best_distance = uint32(1)
  18848 			}
  18849 			iter = iter - 1
  18850 			// Skip the for loop if we already have the maximum.
  18851 			if best_length == libc.Int32FromInt32(1)<<libc.Int32FromInt32(MAX_LENGTH_BITS)-libc.Int32FromInt32(1) {
  18852 				pos = min_pos - int32(1)
  18853 			}
  18854 		}
  18855 		best_argb = **(**uint32_t)(__ccgo_up(argb_start + uintptr(best_length)*4))
  18856 		for {
  18857 			if v12 = pos >= min_pos; v12 {
  18858 				iter = iter - 1
  18859 				v4 = iter
  18860 			}
  18861 			if !(v12 && v4 != 0) {
  18862 				break
  18863 			}
  18864 			if **(**uint32_t)(__ccgo_up(argb + uintptr(pos+best_length)*4)) != best_argb {
  18865 				goto _10
  18866 			}
  18867 			curr_length1 = (*(*func(*libc.TLS, uintptr, uintptr, int32) int32)(unsafe.Pointer(&struct{ uintptr }{VP8LVectorMismatch})))(tls, argb+uintptr(pos)*4, argb_start, max_len)
  18868 			if best_length < curr_length1 {
  18869 				best_length = curr_length1
  18870 				best_distance = base_position - uint32(pos)
  18871 				best_argb = **(**uint32_t)(__ccgo_up(argb_start + uintptr(best_length)*4))
  18872 				// Stop if we have reached a good enough length.
  18873 				if best_length >= length_max {
  18874 					break
  18875 				}
  18876 			}
  18877 			goto _10
  18878 		_10:
  18879 			;
  18880 			pos = **(**int32_t)(__ccgo_up(chain + uintptr(pos)*4))
  18881 		}
  18882 		// We have the best match but in case the two intervals continue matching
  18883 		// to the left, we have the best matches for the left-extended pixels.
  18884 		max_base_position = base_position
  18885 		for int32(1) != 0 {
  18886 			**(**uint32_t)(__ccgo_up((*VP8LHashChain)(unsafe.Pointer(p)).Foffset_length + uintptr(base_position)*4)) = best_distance<<libc.Int32FromInt32(MAX_LENGTH_BITS) | uint32(best_length)
  18887 			base_position = base_position - 1
  18888 			// Stop if we don't have a match or if we are out of bounds.
  18889 			if best_distance == uint32(0) || base_position == uint32(0) {
  18890 				break
  18891 			}
  18892 			// Stop if we cannot extend the matching intervals to the left.
  18893 			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)) {
  18894 				break
  18895 			}
  18896 			// Stop if we are matching at its limit because there could be a closer
  18897 			// matching interval with the same maximum length. Then again, if the
  18898 			// matching interval is as close as possible (best_distance == 1), we will
  18899 			// never find anything better so let's continue.
  18900 			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 {
  18901 				break
  18902 			}
  18903 			if best_length < libc.Int32FromInt32(1)<<libc.Int32FromInt32(MAX_LENGTH_BITS)-libc.Int32FromInt32(1) {
  18904 				best_length = best_length + 1
  18905 				max_base_position = base_position
  18906 			}
  18907 		}
  18908 		if !(WebPReportProgress(tls, pic, int32(uint32(percent_start)+uint32(percent_range)*(uint32(size-int32(2))-base_position)/uint32(size-libc.Int32FromInt32(2))), percent) != 0) {
  18909 			return 0
  18910 		}
  18911 		goto _7
  18912 	_7:
  18913 	}
  18914 	return WebPReportProgress(tls, pic, percent_start+percent_range, percent)
  18915 }
  18916 
  18917 func AddSingleLiteral(tls *libc.TLS, pixel uint32_t, use_color_cache int32, hashers uintptr, refs uintptr) {
  18918 	var key2, v5 uint32_t
  18919 	var retval, retval1, v, v7 PixOrCopy
  18920 	var v1, v3 int32
  18921 	_, _, _, _, _, _, _, _ = key2, retval, retval1, v, v1, v3, v5, v7
  18922 	if use_color_cache != 0 {
  18923 		v3 = int32(pixel * kHashMul11 >> (*VP8LColorCache)(unsafe.Pointer(hashers)).Fhash_shift)
  18924 		goto _4
  18925 	_4:
  18926 		v1 = v3
  18927 		goto _2
  18928 	_2:
  18929 		key2 = uint32(v1)
  18930 		v5 = **(**uint32_t)(__ccgo_up((*VP8LColorCache)(unsafe.Pointer(hashers)).Fcolors + uintptr(key2)*4))
  18931 		goto _6
  18932 	_6:
  18933 		if v5 == pixel {
  18934 			retval.Fmode = uint8(kCacheIdx)
  18935 			retval.Fargb_or_distance = uint32(int32(key2))
  18936 			retval.Flen1 = uint16(1)
  18937 			v7 = retval
  18938 			goto _8
  18939 		_8:
  18940 			v = v7
  18941 		} else {
  18942 			retval1.Fmode = uint8(kLiteral)
  18943 			retval1.Fargb_or_distance = pixel
  18944 			retval1.Flen1 = uint16(1)
  18945 			v7 = retval1
  18946 			goto _10
  18947 		_10:
  18948 			v = v7
  18949 			**(**uint32_t)(__ccgo_up((*VP8LColorCache)(unsafe.Pointer(hashers)).Fcolors + uintptr(key2)*4)) = pixel
  18950 		}
  18951 	} else {
  18952 		retval1.Fmode = uint8(kLiteral)
  18953 		retval1.Fargb_or_distance = pixel
  18954 		retval1.Flen1 = uint16(1)
  18955 		v7 = retval1
  18956 		goto _12
  18957 	_12:
  18958 		v = v7
  18959 	}
  18960 	VP8LBackwardRefsCursorAdd(tls, refs, v)
  18961 }
  18962 
  18963 func BackwardReferencesRle(tls *libc.TLS, xsize int32, ysize int32, argb2 uintptr, cache_bits int32, refs uintptr) (r int32) {
  18964 	bp := tls.Alloc(16)
  18965 	defer tls.Free(16)
  18966 	var i, k, key, max_len, pix_count, prev_row_len, rle_len, use_color_cache, v1 int32
  18967 	var retval, v2 PixOrCopy
  18968 	var v7 uintptr
  18969 	var v8 uint32_t
  18970 	var _ /* hashers at bp+0 */ VP8LColorCache
  18971 	_, _, _, _, _, _, _, _, _, _, _, _, _ = i, k, key, max_len, pix_count, prev_row_len, retval, rle_len, use_color_cache, v1, v2, v7, v8
  18972 	pix_count = xsize * ysize
  18973 	use_color_cache = libc.BoolInt32(cache_bits > libc.Int32FromInt32(0))
  18974 	if use_color_cache != 0 && !(VP8LColorCacheInit(tls, bp, cache_bits) != 0) {
  18975 		return 0
  18976 	}
  18977 	VP8LClearBackwardRefs(tls, refs)
  18978 	// Add first pixel as literal.
  18979 	AddSingleLiteral(tls, **(**uint32_t)(__ccgo_up(argb2)), use_color_cache, bp, refs)
  18980 	i = int32(1)
  18981 	for i < pix_count {
  18982 		max_len = MaxFindCopyLength(tls, pix_count-i)
  18983 		rle_len = FindMatchLength(tls, argb2+uintptr(i)*4, argb2+uintptr(i)*4-uintptr(1)*4, 0, max_len)
  18984 		if i < xsize {
  18985 			v1 = 0
  18986 		} else {
  18987 			v1 = FindMatchLength(tls, argb2+uintptr(i)*4, argb2+uintptr(i)*4-uintptr(xsize)*4, 0, max_len)
  18988 		}
  18989 		prev_row_len = v1
  18990 		if rle_len >= prev_row_len && rle_len >= int32(MIN_LENGTH) {
  18991 			retval.Fmode = uint8(kCopy)
  18992 			retval.Fargb_or_distance = uint32(1)
  18993 			retval.Flen1 = uint16(rle_len)
  18994 			v2 = retval
  18995 			goto _3
  18996 		_3:
  18997 			VP8LBackwardRefsCursorAdd(tls, refs, v2)
  18998 			// We don't need to update the color cache here since it is always the
  18999 			// same pixel being copied, and that does not change the color cache
  19000 			// state.
  19001 			i = i + rle_len
  19002 		} else {
  19003 			if prev_row_len >= int32(MIN_LENGTH) {
  19004 				retval.Fmode = uint8(kCopy)
  19005 				retval.Fargb_or_distance = uint32(xsize)
  19006 				retval.Flen1 = uint16(prev_row_len)
  19007 				v2 = retval
  19008 				goto _5
  19009 			_5:
  19010 				VP8LBackwardRefsCursorAdd(tls, refs, v2)
  19011 				if use_color_cache != 0 {
  19012 					k = 0
  19013 					for {
  19014 						if !(k < prev_row_len) {
  19015 							break
  19016 						}
  19017 						v7 = bp
  19018 						v8 = **(**uint32_t)(__ccgo_up(argb2 + uintptr(i+k)*4))
  19019 						v1 = int32(v8 * kHashMul11 >> (*VP8LColorCache)(unsafe.Pointer(v7)).Fhash_shift)
  19020 						goto _10
  19021 					_10:
  19022 						key = v1
  19023 						**(**uint32_t)(__ccgo_up((*VP8LColorCache)(unsafe.Pointer(v7)).Fcolors + uintptr(key)*4)) = v8
  19024 						goto _6
  19025 					_6:
  19026 						;
  19027 						k = k + 1
  19028 					}
  19029 				}
  19030 				i = i + prev_row_len
  19031 			} else {
  19032 				AddSingleLiteral(tls, **(**uint32_t)(__ccgo_up(argb2 + uintptr(i)*4)), use_color_cache, bp, refs)
  19033 				i = i + 1
  19034 			}
  19035 		}
  19036 	}
  19037 	if use_color_cache != 0 {
  19038 		VP8LColorCacheClear(tls, bp)
  19039 	}
  19040 	return libc.BoolInt32(!((*VP8LBackwardRefs)(unsafe.Pointer(refs)).Ferror1 != 0))
  19041 }
  19042 
  19043 func BackwardReferencesLz77(tls *libc.TLS, xsize int32, ysize int32, argb2 uintptr, cache_bits int32, hash_chain uintptr, refs uintptr) (r int32) {
  19044 	bp := tls.Alloc(32)
  19045 	defer tls.Free(32)
  19046 	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
  19047 	var retval, v14 PixOrCopy
  19048 	var v2 uintptr
  19049 	var v18 uint32_t
  19050 	var _ /* hashers at bp+0 */ VP8LColorCache
  19051 	var _ /* len at bp+20 */ int32
  19052 	var _ /* offset at bp+16 */ int32
  19053 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  19054 	i_last_check = -int32(1)
  19055 	ok = 0
  19056 	cc_init = 0
  19057 	use_color_cache = libc.BoolInt32(cache_bits > libc.Int32FromInt32(0))
  19058 	pix_count = xsize * ysize
  19059 	if use_color_cache != 0 {
  19060 		cc_init = VP8LColorCacheInit(tls, bp, cache_bits)
  19061 		if !(cc_init != 0) {
  19062 			goto Error
  19063 		}
  19064 	}
  19065 	VP8LClearBackwardRefs(tls, refs)
  19066 	i = 0
  19067 	for {
  19068 		if !(i < pix_count) {
  19069 			break
  19070 		}
  19071 		// Alternative#1: Code the pixels starting at 'i' using backward reference.
  19072 		**(**int32)(__ccgo_up(bp + 16)) = 0
  19073 		**(**int32)(__ccgo_up(bp + 20)) = 0
  19074 		v2 = hash_chain
  19075 		v3 = i
  19076 		v4 = int32(**(**uint32_t)(__ccgo_up((*VP8LHashChain)(unsafe.Pointer(v2)).Foffset_length + uintptr(v3)*4)) >> int32(MAX_LENGTH_BITS))
  19077 		goto _5
  19078 	_5:
  19079 		**(**int32)(__ccgo_up(bp + 16)) = v4
  19080 		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)))
  19081 		goto _7
  19082 	_7:
  19083 		**(**int32)(__ccgo_up(bp + 20)) = v6
  19084 		if **(**int32)(__ccgo_up(bp + 20)) >= int32(MIN_LENGTH) {
  19085 			len_ini = **(**int32)(__ccgo_up(bp + 20))
  19086 			max_reach = 0
  19087 			if i+len_ini >= pix_count {
  19088 				v3 = pix_count - int32(1)
  19089 			} else {
  19090 				v3 = i + len_ini
  19091 			}
  19092 			j_max = v3
  19093 			// Only start from what we have not checked already.
  19094 			if i > i_last_check {
  19095 				v4 = i
  19096 			} else {
  19097 				v4 = i_last_check
  19098 			}
  19099 			i_last_check = v4
  19100 			// We know the best match for the current pixel but we try to find the
  19101 			// best matches for the current pixel AND the next one combined.
  19102 			// The naive method would use the intervals:
  19103 			// [i,i+len) + [i+len, length of best match at i+len)
  19104 			// while we check if we can use:
  19105 			// [i,j) (where j<=i+len) + [j, length of best match at j)
  19106 			j = i_last_check + int32(1)
  19107 			for {
  19108 				if !(j <= j_max) {
  19109 					break
  19110 				}
  19111 				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)))
  19112 				goto _12
  19113 			_12:
  19114 				len_j = v3
  19115 				if len_j >= int32(MIN_LENGTH) {
  19116 					v4 = len_j
  19117 				} else {
  19118 					v4 = int32(1)
  19119 				}
  19120 				reach = j + v4 // 1 for single literal.
  19121 				if reach > max_reach {
  19122 					**(**int32)(__ccgo_up(bp + 20)) = j - i
  19123 					max_reach = reach
  19124 					if max_reach >= pix_count {
  19125 						break
  19126 					}
  19127 				}
  19128 				goto _10
  19129 			_10:
  19130 				;
  19131 				j = j + 1
  19132 			}
  19133 		} else {
  19134 			**(**int32)(__ccgo_up(bp + 20)) = int32(1)
  19135 		}
  19136 		// Go with literal or backward reference.
  19137 		if **(**int32)(__ccgo_up(bp + 20)) == int32(1) {
  19138 			AddSingleLiteral(tls, **(**uint32_t)(__ccgo_up(argb2 + uintptr(i)*4)), use_color_cache, bp, refs)
  19139 		} else {
  19140 			retval.Fmode = uint8(kCopy)
  19141 			retval.Fargb_or_distance = uint32(**(**int32)(__ccgo_up(bp + 16)))
  19142 			retval.Flen1 = uint16(**(**int32)(__ccgo_up(bp + 20)))
  19143 			v14 = retval
  19144 			goto _15
  19145 		_15:
  19146 			VP8LBackwardRefsCursorAdd(tls, refs, v14)
  19147 			if use_color_cache != 0 {
  19148 				j = i
  19149 				for {
  19150 					if !(j < i+**(**int32)(__ccgo_up(bp + 20))) {
  19151 						break
  19152 					}
  19153 					v2 = bp
  19154 					v18 = **(**uint32_t)(__ccgo_up(argb2 + uintptr(j)*4))
  19155 					v3 = int32(v18 * kHashMul11 >> (*VP8LColorCache)(unsafe.Pointer(v2)).Fhash_shift)
  19156 					goto _20
  19157 				_20:
  19158 					key = v3
  19159 					**(**uint32_t)(__ccgo_up((*VP8LColorCache)(unsafe.Pointer(v2)).Fcolors + uintptr(key)*4)) = v18
  19160 					goto _16
  19161 				_16:
  19162 					;
  19163 					j = j + 1
  19164 				}
  19165 			}
  19166 		}
  19167 		i = i + **(**int32)(__ccgo_up(bp + 20))
  19168 		goto _1
  19169 	_1:
  19170 	}
  19171 	ok = libc.BoolInt32(!((*VP8LBackwardRefs)(unsafe.Pointer(refs)).Ferror1 != 0))
  19172 	goto Error
  19173 Error:
  19174 	;
  19175 	if cc_init != 0 {
  19176 		VP8LColorCacheClear(tls, bp)
  19177 	}
  19178 	return ok
  19179 }
  19180 
  19181 // C documentation
  19182 //
  19183 //	// Compute an LZ77 by forcing matches to happen within a given distance cost.
  19184 //	// We therefore limit the algorithm to the lowest 32 values in the PlaneCode
  19185 //	// definition.
  19186 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) {
  19187 	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
  19188 	var counts, counts_ini uintptr
  19189 	var window_offsets, window_offsets_new [32]int32
  19190 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  19191 	pix_count = xsize * ysize
  19192 	window_offsets = [32]int32{}
  19193 	window_offsets_new = [32]int32{}
  19194 	window_offsets_size = 0
  19195 	window_offsets_new_size = 0
  19196 	counts_ini = WebPSafeMalloc(tls, uint64(xsize*ysize), uint64(2))
  19197 	best_offset_prev = -int32(1)
  19198 	best_length_prev = -int32(1)
  19199 	if counts_ini == libc.UintptrFromInt32(0) {
  19200 		return 0
  19201 	}
  19202 	// counts[i] counts how many times a pixel is repeated starting at position i.
  19203 	i = pix_count - int32(2)
  19204 	counts = counts_ini + uintptr(i)*2
  19205 	**(**uint16_t)(__ccgo_up(counts + 1*2)) = uint16(1)
  19206 	for {
  19207 		if !(i >= 0) {
  19208 			break
  19209 		}
  19210 		if **(**uint32_t)(__ccgo_up(argb + uintptr(i)*4)) == **(**uint32_t)(__ccgo_up(argb + uintptr(i+int32(1))*4)) {
  19211 			// Max out the counts to MAX_LENGTH.
  19212 			**(**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)))
  19213 		} else {
  19214 			**(**uint16_t)(__ccgo_up(counts)) = uint16(1)
  19215 		}
  19216 		goto _1
  19217 	_1:
  19218 		;
  19219 		i = i - 1
  19220 		counts -= 2
  19221 	}
  19222 	// Figure out the window offsets around a pixel. They are stored in a
  19223 	// spiraling order around the pixel as defined by VP8LDistanceToPlaneCode.
  19224 	y = 0
  19225 	for {
  19226 		if !(y <= int32(6)) {
  19227 			break
  19228 		}
  19229 		x = -int32(6)
  19230 		for {
  19231 			if !(x <= int32(6)) {
  19232 				break
  19233 			}
  19234 			offset = y*xsize + x
  19235 			// Ignore offsets that bring us after the pixel.
  19236 			if offset <= 0 {
  19237 				goto _3
  19238 			}
  19239 			plane_code = VP8LDistanceToPlaneCode(tls, xsize, offset) - int32(1)
  19240 			if plane_code >= int32(WINDOW_OFFSETS_SIZE_MAX) {
  19241 				goto _3
  19242 			}
  19243 			window_offsets[plane_code] = offset
  19244 			goto _3
  19245 		_3:
  19246 			;
  19247 			x = x + 1
  19248 		}
  19249 		goto _2
  19250 	_2:
  19251 		;
  19252 		y = y + 1
  19253 	}
  19254 	// For narrow images, not all plane codes are reached, so remove those.
  19255 	i = 0
  19256 	for {
  19257 		if !(i < int32(WINDOW_OFFSETS_SIZE_MAX)) {
  19258 			break
  19259 		}
  19260 		if window_offsets[i] == 0 {
  19261 			goto _4
  19262 		}
  19263 		v5 = window_offsets_size
  19264 		window_offsets_size = window_offsets_size + 1
  19265 		window_offsets[v5] = window_offsets[i]
  19266 		goto _4
  19267 	_4:
  19268 		;
  19269 		i = i + 1
  19270 	}
  19271 	// Given a pixel P, find the offsets that reach pixels unreachable from P-1
  19272 	// with any of the offsets in window_offsets[].
  19273 	i = 0
  19274 	for {
  19275 		if !(i < window_offsets_size) {
  19276 			break
  19277 		}
  19278 		is_reachable = 0
  19279 		j = 0
  19280 		for {
  19281 			if !(j < window_offsets_size && !(is_reachable != 0)) {
  19282 				break
  19283 			}
  19284 			is_reachable = is_reachable | libc.BoolInt32(window_offsets[i] == window_offsets[j]+int32(1))
  19285 			goto _7
  19286 		_7:
  19287 			;
  19288 			j = j + 1
  19289 		}
  19290 		if !(is_reachable != 0) {
  19291 			window_offsets_new[window_offsets_new_size] = window_offsets[i]
  19292 			window_offsets_new_size = window_offsets_new_size + 1
  19293 		}
  19294 		goto _6
  19295 	_6:
  19296 		;
  19297 		i = i + 1
  19298 	}
  19299 	**(**uint32_t)(__ccgo_up((*VP8LHashChain)(unsafe.Pointer(hash_chain)).Foffset_length)) = uint32(0)
  19300 	i = int32(1)
  19301 	for {
  19302 		if !(i < pix_count) {
  19303 			break
  19304 		}
  19305 		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)))
  19306 		goto _10
  19307 	_10:
  19308 		best_length = v5
  19309 		do_compute = int32(1)
  19310 		if best_length >= libc.Int32FromInt32(1)<<libc.Int32FromInt32(MAX_LENGTH_BITS)-libc.Int32FromInt32(1) {
  19311 			// Do not recompute the best match if we already have a maximal one in the
  19312 			// window.
  19313 			v9 = int32(**(**uint32_t)(__ccgo_up((*VP8LHashChain)(unsafe.Pointer(hash_chain_best)).Foffset_length + uintptr(i)*4)) >> int32(MAX_LENGTH_BITS))
  19314 			goto _12
  19315 		_12:
  19316 			best_offset = v9
  19317 			ind = 0
  19318 			for {
  19319 				if !(ind < window_offsets_size) {
  19320 					break
  19321 				}
  19322 				if best_offset == window_offsets[ind] {
  19323 					do_compute = 0
  19324 					break
  19325 				}
  19326 				goto _13
  19327 			_13:
  19328 				;
  19329 				ind = ind + 1
  19330 			}
  19331 		}
  19332 		if do_compute != 0 {
  19333 			// Figure out if we should use the offset/length from the previous pixel
  19334 			// as an initial guess and therefore only inspect the offsets in
  19335 			// window_offsets_new[].
  19336 			use_prev = libc.BoolInt32(best_length_prev > int32(1) && best_length_prev < libc.Int32FromInt32(1)<<libc.Int32FromInt32(MAX_LENGTH_BITS)-libc.Int32FromInt32(1))
  19337 			if use_prev != 0 {
  19338 				v5 = window_offsets_new_size
  19339 			} else {
  19340 				v5 = window_offsets_size
  19341 			}
  19342 			num_ind = v5
  19343 			if use_prev != 0 {
  19344 				v9 = best_length_prev - int32(1)
  19345 			} else {
  19346 				v9 = 0
  19347 			}
  19348 			best_length = v9
  19349 			if use_prev != 0 {
  19350 				v5 = best_offset_prev
  19351 			} else {
  19352 				v5 = 0
  19353 			}
  19354 			best_offset = v5
  19355 			// Find the longest match in a window around the pixel.
  19356 			ind = 0
  19357 			for {
  19358 				if !(ind < num_ind) {
  19359 					break
  19360 				}
  19361 				curr_length = 0
  19362 				j1 = i
  19363 				if use_prev != 0 {
  19364 					v5 = i - window_offsets_new[ind]
  19365 				} else {
  19366 					v5 = i - window_offsets[ind]
  19367 				}
  19368 				j_offset = v5
  19369 				if j_offset < 0 || **(**uint32_t)(__ccgo_up(argb + uintptr(j_offset)*4)) != **(**uint32_t)(__ccgo_up(argb + uintptr(i)*4)) {
  19370 					goto _17
  19371 				}
  19372 				// The longest match is the sum of how many times each pixel is
  19373 				// repeated.
  19374 				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)) {
  19375 					counts_j_offset = int32(**(**uint16_t)(__ccgo_up(counts_ini + uintptr(j_offset)*2)))
  19376 					counts_j = int32(**(**uint16_t)(__ccgo_up(counts_ini + uintptr(j1)*2)))
  19377 					if counts_j_offset != counts_j {
  19378 						if counts_j_offset < counts_j {
  19379 							v5 = counts_j_offset
  19380 						} else {
  19381 							v5 = counts_j
  19382 						}
  19383 						curr_length = curr_length + v5
  19384 						break
  19385 					}
  19386 					// The same color is repeated counts_pos times at j_offset and j.
  19387 					curr_length = curr_length + counts_j_offset
  19388 					j_offset = j_offset + counts_j_offset
  19389 					j1 = j1 + counts_j_offset
  19390 				}
  19391 				if best_length < curr_length {
  19392 					if use_prev != 0 {
  19393 						v5 = window_offsets_new[ind]
  19394 					} else {
  19395 						v5 = window_offsets[ind]
  19396 					}
  19397 					best_offset = v5
  19398 					if curr_length >= libc.Int32FromInt32(1)<<libc.Int32FromInt32(MAX_LENGTH_BITS)-libc.Int32FromInt32(1) {
  19399 						best_length = libc.Int32FromInt32(1)<<libc.Int32FromInt32(MAX_LENGTH_BITS) - libc.Int32FromInt32(1)
  19400 						break
  19401 					} else {
  19402 						best_length = curr_length
  19403 					}
  19404 				}
  19405 				goto _17
  19406 			_17:
  19407 				;
  19408 				ind = ind + 1
  19409 			}
  19410 		}
  19411 		if best_length <= int32(MIN_LENGTH) {
  19412 			**(**uint32_t)(__ccgo_up((*VP8LHashChain)(unsafe.Pointer(hash_chain)).Foffset_length + uintptr(i)*4)) = uint32(0)
  19413 			best_offset_prev = 0
  19414 			best_length_prev = 0
  19415 		} else {
  19416 			**(**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)
  19417 			best_offset_prev = best_offset
  19418 			best_length_prev = best_length
  19419 		}
  19420 		goto _8
  19421 	_8:
  19422 		;
  19423 		i = i + 1
  19424 	}
  19425 	**(**uint32_t)(__ccgo_up((*VP8LHashChain)(unsafe.Pointer(hash_chain)).Foffset_length)) = uint32(0)
  19426 	WebPSafeFree(tls, counts_ini)
  19427 	return BackwardReferencesLz77(tls, xsize, ysize, argb, cache_bits, hash_chain, refs)
  19428 }
  19429 
  19430 // -----------------------------------------------------------------------------
  19431 
  19432 func BackwardReferences2DLocality(tls *libc.TLS, xsize int32, refs uintptr) {
  19433 	bp := tls.Alloc(32)
  19434 	defer tls.Free(32)
  19435 	var dist, transformed_dist, v1, v3 int32
  19436 	var v5, v6, v7 uintptr
  19437 	var _ /* c at bp+0 */ VP8LRefsCursor
  19438 	_, _, _, _, _, _, _ = dist, transformed_dist, v1, v3, v5, v6, v7
  19439 	**(**VP8LRefsCursor)(__ccgo_up(bp)) = VP8LRefsCursorInit(tls, refs)
  19440 	for {
  19441 		v1 = libc.BoolInt32((*VP8LRefsCursor)(unsafe.Pointer(bp)).Fcur_pos != libc.UintptrFromInt32(0))
  19442 		goto _2
  19443 	_2:
  19444 		if !(v1 != 0) {
  19445 			break
  19446 		}
  19447 		v3 = libc.BoolInt32(int32((*PixOrCopy)(unsafe.Pointer((**(**VP8LRefsCursor)(__ccgo_up(bp))).Fcur_pos)).Fmode) == int32(kCopy))
  19448 		goto _4
  19449 	_4:
  19450 		if v3 != 0 {
  19451 			dist = int32((*PixOrCopy)(unsafe.Pointer((**(**VP8LRefsCursor)(__ccgo_up(bp))).Fcur_pos)).Fargb_or_distance)
  19452 			transformed_dist = VP8LDistanceToPlaneCode(tls, xsize, dist)
  19453 			(*PixOrCopy)(unsafe.Pointer((**(**VP8LRefsCursor)(__ccgo_up(bp))).Fcur_pos)).Fargb_or_distance = uint32(transformed_dist)
  19454 		}
  19455 		v5 = bp
  19456 		v7 = v5
  19457 		*(*uintptr)(unsafe.Pointer(v7)) += 8
  19458 		v6 = *(*uintptr)(unsafe.Pointer(v7))
  19459 		if v6 == (*VP8LRefsCursor)(unsafe.Pointer(v5)).Flast_pos {
  19460 			VP8LRefsCursorNextBlock(tls, v5)
  19461 		}
  19462 	}
  19463 }
  19464 
  19465 // C documentation
  19466 //
  19467 //	// Evaluate optimal cache bits for the local color cache.
  19468 //	// The input *best_cache_bits sets the maximum cache bits to use (passing 0
  19469 //	// implies disabling the local color cache). The local color cache is also
  19470 //	// disabled for the lower (<= 25) quality.
  19471 //	// Returns 0 in case of memory error.
  19472 func CalculateBestCacheSize(tls *libc.TLS, argb2 uintptr, quality int32, refs uintptr, best_cache_bits uintptr) (r1 int32) {
  19473 	bp := tls.Alloc(224)
  19474 	defer tls.Free(224)
  19475 	var a, argb_prev, b, g, pix, r, v11 uint32_t
  19476 	var cache_bits_max, highest_bit, i, key2, key3, len1, ok, second_highest_bit, v1, v3, v5, v8 int32
  19477 	var cc_init [11]int32
  19478 	var entropy, entropy_min uint64_t
  19479 	var histos [11]uintptr
  19480 	var prefix_code VP8LPrefixCode
  19481 	var v, v16, v17, v18, v7 uintptr
  19482 	var _ /* c at bp+176 */ VP8LRefsCursor
  19483 	var _ /* code at bp+200 */ int32
  19484 	var _ /* extra_bits at bp+204 */ int32
  19485 	var _ /* extra_bits_value at bp+208 */ int32
  19486 	var _ /* hashers at bp+0 */ [11]VP8LColorCache
  19487 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  19488 	if quality <= int32(25) {
  19489 		v1 = 0
  19490 	} else {
  19491 		v1 = **(**int32)(__ccgo_up(best_cache_bits))
  19492 	}
  19493 	cache_bits_max = v1
  19494 	entropy_min = ^libc.Uint64FromUint64(0)
  19495 	cc_init = [11]int32{}
  19496 	**(**VP8LRefsCursor)(__ccgo_up(bp + 176)) = VP8LRefsCursorInit(tls, refs)
  19497 	histos = [11]uintptr{}
  19498 	ok = 0
  19499 	if cache_bits_max == 0 {
  19500 		**(**int32)(__ccgo_up(best_cache_bits)) = 0
  19501 		// Local color cache is disabled.
  19502 		return int32(1)
  19503 	}
  19504 	// Allocate data.
  19505 	i = 0
  19506 	for {
  19507 		if !(i <= cache_bits_max) {
  19508 			break
  19509 		}
  19510 		histos[i] = VP8LAllocateHistogram(tls, i)
  19511 		if histos[i] == libc.UintptrFromInt32(0) {
  19512 			goto Error
  19513 		}
  19514 		VP8LHistogramInit(tls, histos[i], i, int32(1))
  19515 		if i == 0 {
  19516 			goto _2
  19517 		}
  19518 		cc_init[i] = VP8LColorCacheInit(tls, bp+uintptr(i)*16, i)
  19519 		if !(cc_init[i] != 0) {
  19520 			goto Error
  19521 		}
  19522 		goto _2
  19523 	_2:
  19524 		;
  19525 		i = i + 1
  19526 	}
  19527 	// Find the cache_bits giving the lowest entropy. The search is done in a
  19528 	// brute-force way as the function (entropy w.r.t cache_bits) can be
  19529 	// anything in practice.
  19530 	for {
  19531 		v1 = libc.BoolInt32((*VP8LRefsCursor)(unsafe.Pointer(bp+176)).Fcur_pos != libc.UintptrFromInt32(0))
  19532 		goto _4
  19533 	_4:
  19534 		if !(v1 != 0) {
  19535 			break
  19536 		}
  19537 		v = (**(**VP8LRefsCursor)(__ccgo_up(bp + 176))).Fcur_pos
  19538 		v3 = libc.BoolInt32(int32((*PixOrCopy)(unsafe.Pointer(v)).Fmode) == int32(kLiteral))
  19539 		goto _6
  19540 	_6:
  19541 		if v3 != 0 {
  19542 			v7 = argb2
  19543 			argb2 += 4
  19544 			pix = **(**uint32_t)(__ccgo_up(v7))
  19545 			a = pix >> libc.Int32FromInt32(24) & uint32(0xff)
  19546 			r = pix >> libc.Int32FromInt32(16) & uint32(0xff)
  19547 			g = pix >> libc.Int32FromInt32(8) & uint32(0xff)
  19548 			b = pix >> libc.Int32FromInt32(0) & uint32(0xff)
  19549 			v5 = int32(pix * kHashMul11 >> (int32(32) - cache_bits_max))
  19550 			goto _9
  19551 		_9:
  19552 			// The keys of the caches can be derived from the longest one.
  19553 			key2 = v5
  19554 			// Do not use the color cache for cache_bits = 0.
  19555 			**(**uint32_t)(__ccgo_up(histos[0] + 1032 + uintptr(b)*4)) = **(**uint32_t)(__ccgo_up(histos[0] + 1032 + uintptr(b)*4)) + 1
  19556 			**(**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
  19557 			**(**uint32_t)(__ccgo_up(histos[0] + 8 + uintptr(r)*4)) = **(**uint32_t)(__ccgo_up(histos[0] + 8 + uintptr(r)*4)) + 1
  19558 			**(**uint32_t)(__ccgo_up(histos[0] + 2056 + uintptr(a)*4)) = **(**uint32_t)(__ccgo_up(histos[0] + 2056 + uintptr(a)*4)) + 1
  19559 			// Deal with cache_bits > 0.
  19560 			i = cache_bits_max
  19561 			for {
  19562 				if !(i >= int32(1)) {
  19563 					break
  19564 				}
  19565 				v11 = **(**uint32_t)(__ccgo_up((*VP8LColorCache)(unsafe.Pointer(bp+uintptr(i)*16)).Fcolors + uintptr(uint32(key2))*4))
  19566 				goto _12
  19567 			_12:
  19568 				if v11 == pix {
  19569 					**(**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
  19570 				} else {
  19571 					**(**uint32_t)(__ccgo_up((*VP8LColorCache)(unsafe.Pointer(bp+uintptr(i)*16)).Fcolors + uintptr(uint32(key2))*4)) = pix
  19572 					**(**uint32_t)(__ccgo_up(histos[i] + 1032 + uintptr(b)*4)) = **(**uint32_t)(__ccgo_up(histos[i] + 1032 + uintptr(b)*4)) + 1
  19573 					**(**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
  19574 					**(**uint32_t)(__ccgo_up(histos[i] + 8 + uintptr(r)*4)) = **(**uint32_t)(__ccgo_up(histos[i] + 8 + uintptr(r)*4)) + 1
  19575 					**(**uint32_t)(__ccgo_up(histos[i] + 2056 + uintptr(a)*4)) = **(**uint32_t)(__ccgo_up(histos[i] + 2056 + uintptr(a)*4)) + 1
  19576 				}
  19577 				goto _10
  19578 			_10:
  19579 				;
  19580 				i = i - 1
  19581 				key2 = key2 >> int32(1)
  19582 			}
  19583 		} else {
  19584 			v11 = uint32((*PixOrCopy)(unsafe.Pointer(v)).Flen1)
  19585 			goto _14
  19586 		_14:
  19587 			// We should compute the contribution of the (distance,length)
  19588 			// histograms but those are the same independently from the cache size.
  19589 			// As those constant contributions are in the end added to the other
  19590 			// histogram contributions, we can ignore them, except for the length
  19591 			// prefix that is part of the 'literal' histogram.
  19592 			len1 = int32(v11)
  19593 			argb_prev = **(**uint32_t)(__ccgo_up(argb2)) ^ uint32(0xffffffff)
  19594 			v1 = len1
  19595 			v7 = bp + 200
  19596 			v16 = bp + 204
  19597 			v17 = bp + 208
  19598 			if v1 < libc.Int32FromInt32(PREFIX_LOOKUP_IDX_MAX) {
  19599 				prefix_code = kPrefixEncodeCode[v1]
  19600 				**(**int32)(__ccgo_up(v7)) = int32(prefix_code.Fcode)
  19601 				**(**int32)(__ccgo_up(v16)) = int32(prefix_code.Fextra_bits)
  19602 				**(**int32)(__ccgo_up(v17)) = int32(kPrefixEncodeExtraBitsValue[v1])
  19603 			} else {
  19604 				v3 = v1
  19605 				v18 = v16
  19606 				v3 = v3 - 1
  19607 				v5 = v3
  19608 				v8 = int32(31) ^ libc.X__builtin_clz(tls, uint32(v5))
  19609 				goto _23
  19610 			_23:
  19611 				highest_bit = v8
  19612 				second_highest_bit = v3 >> (highest_bit - int32(1)) & int32(1)
  19613 				**(**int32)(__ccgo_up(v18)) = highest_bit - int32(1)
  19614 				**(**int32)(__ccgo_up(v17)) = v3 & (int32(1)<<**(**int32)(__ccgo_up(v18)) - int32(1))
  19615 				**(**int32)(__ccgo_up(v7)) = int32(2)*highest_bit + second_highest_bit
  19616 			}
  19617 			i = 0
  19618 			for {
  19619 				if !(i <= cache_bits_max) {
  19620 					break
  19621 				}
  19622 				**(**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
  19623 				goto _24
  19624 			_24:
  19625 				;
  19626 				i = i + 1
  19627 			}
  19628 			// Update the color caches.
  19629 			for {
  19630 				if **(**uint32_t)(__ccgo_up(argb2)) != argb_prev {
  19631 					v3 = int32(**(**uint32_t)(__ccgo_up(argb2)) * kHashMul11 >> (int32(32) - cache_bits_max))
  19632 					goto _28
  19633 				_28:
  19634 					// Efficiency: insert only if the color changes.
  19635 					key3 = v3
  19636 					i = cache_bits_max
  19637 					for {
  19638 						if !(i >= int32(1)) {
  19639 							break
  19640 						}
  19641 						**(**uint32_t)(__ccgo_up((**(**[11]VP8LColorCache)(__ccgo_up(bp)))[i].Fcolors + uintptr(key3)*4)) = **(**uint32_t)(__ccgo_up(argb2))
  19642 						goto _29
  19643 					_29:
  19644 						;
  19645 						i = i - 1
  19646 						key3 = key3 >> int32(1)
  19647 					}
  19648 					argb_prev = **(**uint32_t)(__ccgo_up(argb2))
  19649 				}
  19650 				argb2 += 4
  19651 				goto _26
  19652 			_26:
  19653 				;
  19654 				len1 = len1 - 1
  19655 				v1 = len1
  19656 				if !(v1 != 0) {
  19657 					break
  19658 				}
  19659 			}
  19660 		}
  19661 		v7 = bp + 176
  19662 		v17 = v7
  19663 		*(*uintptr)(unsafe.Pointer(v17)) += 8
  19664 		v16 = *(*uintptr)(unsafe.Pointer(v17))
  19665 		if v16 == (*VP8LRefsCursor)(unsafe.Pointer(v7)).Flast_pos {
  19666 			VP8LRefsCursorNextBlock(tls, v7)
  19667 		}
  19668 	}
  19669 	i = 0
  19670 	for {
  19671 		if !(i <= cache_bits_max) {
  19672 			break
  19673 		}
  19674 		entropy = VP8LHistogramEstimateBits(tls, histos[i])
  19675 		if i == 0 || entropy < entropy_min {
  19676 			entropy_min = entropy
  19677 			**(**int32)(__ccgo_up(best_cache_bits)) = i
  19678 		}
  19679 		goto _33
  19680 	_33:
  19681 		;
  19682 		i = i + 1
  19683 	}
  19684 	ok = int32(1)
  19685 	goto Error
  19686 Error:
  19687 	;
  19688 	i = 0
  19689 	for {
  19690 		if !(i <= cache_bits_max) {
  19691 			break
  19692 		}
  19693 		if cc_init[i] != 0 {
  19694 			VP8LColorCacheClear(tls, bp+uintptr(i)*16)
  19695 		}
  19696 		VP8LFreeHistogram(tls, histos[i])
  19697 		goto _34
  19698 	_34:
  19699 		;
  19700 		i = i + 1
  19701 	}
  19702 	return ok
  19703 }
  19704 
  19705 // C documentation
  19706 //
  19707 //	// Update (in-place) backward references for specified cache_bits.
  19708 func BackwardRefsWithLocalCache(tls *libc.TLS, argb3 uintptr, cache_bits int32, refs uintptr) (r int32) {
  19709 	bp := tls.Alloc(48)
  19710 	defer tls.Free(48)
  19711 	var argb_literal, v6 uint32_t
  19712 	var ix, k, key, key1, pixel_index, v1, v11, v3, v7, v9 int32
  19713 	var retval, v12 PixOrCopy
  19714 	var v, v14, v20, v5 uintptr
  19715 	var _ /* c at bp+16 */ VP8LRefsCursor
  19716 	var _ /* hashers at bp+0 */ VP8LColorCache
  19717 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = argb_literal, ix, k, key, key1, pixel_index, retval, v, v1, v11, v12, v14, v20, v3, v5, v6, v7, v9
  19718 	pixel_index = 0
  19719 	**(**VP8LRefsCursor)(__ccgo_up(bp + 16)) = VP8LRefsCursorInit(tls, refs)
  19720 	if !(VP8LColorCacheInit(tls, bp, cache_bits) != 0) {
  19721 		return 0
  19722 	}
  19723 	for {
  19724 		v1 = libc.BoolInt32((*VP8LRefsCursor)(unsafe.Pointer(bp+16)).Fcur_pos != libc.UintptrFromInt32(0))
  19725 		goto _2
  19726 	_2:
  19727 		if !(v1 != 0) {
  19728 			break
  19729 		}
  19730 		v = (**(**VP8LRefsCursor)(__ccgo_up(bp + 16))).Fcur_pos
  19731 		v3 = libc.BoolInt32(int32((*PixOrCopy)(unsafe.Pointer(v)).Fmode) == int32(kLiteral))
  19732 		goto _4
  19733 	_4:
  19734 		if v3 != 0 {
  19735 			argb_literal = (*PixOrCopy)(unsafe.Pointer(v)).Fargb_or_distance
  19736 			v5 = bp
  19737 			v6 = argb_literal
  19738 			v7 = int32(v6 * kHashMul11 >> (*VP8LColorCache)(unsafe.Pointer(v5)).Fhash_shift)
  19739 			goto _8
  19740 		_8:
  19741 			key1 = v7
  19742 			if **(**uint32_t)(__ccgo_up((*VP8LColorCache)(unsafe.Pointer(v5)).Fcolors + uintptr(key1)*4)) == v6 {
  19743 				v11 = key1
  19744 			} else {
  19745 				v11 = -int32(1)
  19746 			}
  19747 			v9 = v11
  19748 			goto _10
  19749 		_10:
  19750 			ix = v9
  19751 			if ix >= 0 {
  19752 				// hashers contains argb_literal
  19753 				retval.Fmode = uint8(kCacheIdx)
  19754 				retval.Fargb_or_distance = uint32(ix)
  19755 				retval.Flen1 = uint16(1)
  19756 				v12 = retval
  19757 				goto _13
  19758 			_13:
  19759 				**(**PixOrCopy)(__ccgo_up(v)) = v12
  19760 			} else {
  19761 				v5 = bp
  19762 				v6 = argb_literal
  19763 				v1 = int32(v6 * kHashMul11 >> (*VP8LColorCache)(unsafe.Pointer(v5)).Fhash_shift)
  19764 				goto _17
  19765 			_17:
  19766 				key = v1
  19767 				**(**uint32_t)(__ccgo_up((*VP8LColorCache)(unsafe.Pointer(v5)).Fcolors + uintptr(key)*4)) = v6
  19768 			}
  19769 			pixel_index = pixel_index + 1
  19770 		} else {
  19771 			k = 0
  19772 			for {
  19773 				if !(k < int32((*PixOrCopy)(unsafe.Pointer(v)).Flen1)) {
  19774 					break
  19775 				}
  19776 				v1 = pixel_index
  19777 				pixel_index = pixel_index + 1
  19778 				v5 = bp
  19779 				v6 = **(**uint32_t)(__ccgo_up(argb3 + uintptr(v1)*4))
  19780 				v3 = int32(v6 * kHashMul11 >> (*VP8LColorCache)(unsafe.Pointer(v5)).Fhash_shift)
  19781 				goto _23
  19782 			_23:
  19783 				key = v3
  19784 				**(**uint32_t)(__ccgo_up((*VP8LColorCache)(unsafe.Pointer(v5)).Fcolors + uintptr(key)*4)) = v6
  19785 				goto _18
  19786 			_18:
  19787 				;
  19788 				k = k + 1
  19789 			}
  19790 		}
  19791 		v5 = bp + 16
  19792 		v20 = v5
  19793 		*(*uintptr)(unsafe.Pointer(v20)) += 8
  19794 		v14 = *(*uintptr)(unsafe.Pointer(v20))
  19795 		if v14 == (*VP8LRefsCursor)(unsafe.Pointer(v5)).Flast_pos {
  19796 			VP8LRefsCursorNextBlock(tls, v5)
  19797 		}
  19798 	}
  19799 	VP8LColorCacheClear(tls, bp)
  19800 	return int32(1)
  19801 }
  19802 
  19803 func GetBackwardReferencesLowEffort(tls *libc.TLS, width int32, height int32, argb uintptr, cache_bits uintptr, hash_chain uintptr, refs_lz77 uintptr) (r uintptr) {
  19804 	**(**int32)(__ccgo_up(cache_bits)) = 0
  19805 	if !(BackwardReferencesLz77(tls, width, height, argb, 0, hash_chain, refs_lz77) != 0) {
  19806 		return libc.UintptrFromInt32(0)
  19807 	}
  19808 	BackwardReferences2DLocality(tls, width, refs_lz77)
  19809 	return refs_lz77
  19810 }
  19811 
  19812 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) {
  19813 	bp := tls.Alloc(32)
  19814 	defer tls.Free(32)
  19815 	var bit_cost, bit_cost_trace uint64_t
  19816 	var bit_costs_best [2]uint64_t
  19817 	var cache_bits1, i, lz77_type, res, status, v1 int32
  19818 	var hash_chain_tmp, histo, refs_tmp, v6 uintptr
  19819 	var lz77_types_best [2]int32
  19820 	var _ /* cache_bits at bp+16 */ int32
  19821 	var _ /* hash_chain_box at bp+0 */ VP8LHashChain
  19822 	_, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  19823 	histo = libc.UintptrFromInt32(0)
  19824 	// Index 0 is for a color cache, index 1 for no cache (if needed).
  19825 	lz77_types_best = [2]int32{}
  19826 	bit_costs_best = [2]uint64_t{
  19827 		0: ^libc.Uint64FromUint64(0),
  19828 		1: ^libc.Uint64FromUint64(0),
  19829 	}
  19830 	if do_no_cache != 0 {
  19831 		v1 = int32(2)
  19832 	} else {
  19833 		v1 = int32(1)
  19834 	}
  19835 	refs_tmp = refs + uintptr(v1)*40
  19836 	status = 0
  19837 	libc.Xmemset(tls, bp, 0, uint64(16))
  19838 	histo = VP8LAllocateHistogram(tls, int32(MAX_COLOR_CACHE_BITS))
  19839 	if histo == libc.UintptrFromInt32(0) {
  19840 		goto Error
  19841 	}
  19842 	lz77_type = int32(1)
  19843 	for {
  19844 		if !(lz77_types_to_try != 0) {
  19845 			break
  19846 		}
  19847 		res = 0
  19848 		bit_cost = 0
  19849 		if lz77_types_to_try&lz77_type == 0 {
  19850 			goto _2
  19851 		}
  19852 		switch lz77_type {
  19853 		case int32(kLZ77RLE):
  19854 			res = BackwardReferencesRle(tls, width, height, argb, 0, refs_tmp)
  19855 		case int32(kLZ77Standard):
  19856 			// Compute LZ77 with no cache (0 bits), as the ideal LZ77 with a color
  19857 			// cache is not that different in practice.
  19858 			res = BackwardReferencesLz77(tls, width, height, argb, 0, hash_chain, refs_tmp)
  19859 		case int32(kLZ77Box):
  19860 			if !(VP8LHashChainInit(tls, bp, width*height) != 0) {
  19861 				goto Error
  19862 			}
  19863 			res = BackwardReferencesLz77Box(tls, width, height, argb, 0, hash_chain, bp, refs_tmp)
  19864 		default:
  19865 		}
  19866 		if !(res != 0) {
  19867 			goto Error
  19868 		}
  19869 		// Start with the no color cache case.
  19870 		i = int32(1)
  19871 		for {
  19872 			if !(i >= 0) {
  19873 				break
  19874 			}
  19875 			if i == int32(1) {
  19876 				v1 = 0
  19877 			} else {
  19878 				v1 = cache_bits_max
  19879 			}
  19880 			**(**int32)(__ccgo_up(bp + 16)) = v1
  19881 			if i == int32(1) && !(do_no_cache != 0) {
  19882 				goto _3
  19883 			}
  19884 			if i == 0 {
  19885 				// Try with a color cache.
  19886 				if !(CalculateBestCacheSize(tls, argb, quality, refs_tmp, bp+16) != 0) {
  19887 					goto Error
  19888 				}
  19889 				if **(**int32)(__ccgo_up(bp + 16)) > 0 {
  19890 					if !(BackwardRefsWithLocalCache(tls, argb, **(**int32)(__ccgo_up(bp + 16)), refs_tmp) != 0) {
  19891 						goto Error
  19892 					}
  19893 				}
  19894 			}
  19895 			if i == 0 && do_no_cache != 0 && **(**int32)(__ccgo_up(bp + 16)) == 0 {
  19896 				// No need to re-compute bit_cost as it was computed at i == 1.
  19897 			} else {
  19898 				VP8LHistogramCreate(tls, histo, refs_tmp, **(**int32)(__ccgo_up(bp + 16)))
  19899 				bit_cost = VP8LHistogramEstimateBits(tls, histo)
  19900 			}
  19901 			if bit_cost < bit_costs_best[i] {
  19902 				if i == int32(1) {
  19903 					// Do not swap as the full cache analysis would have the wrong
  19904 					// VP8LBackwardRefs to start with.
  19905 					if !(BackwardRefsClone(tls, refs_tmp, refs+1*40) != 0) {
  19906 						goto Error
  19907 					}
  19908 				} else {
  19909 					BackwardRefsSwap(tls, refs_tmp, refs)
  19910 				}
  19911 				bit_costs_best[i] = bit_cost
  19912 				lz77_types_best[i] = lz77_type
  19913 				if i == 0 {
  19914 					**(**int32)(__ccgo_up(cache_bits_best)) = **(**int32)(__ccgo_up(bp + 16))
  19915 				}
  19916 			}
  19917 			goto _3
  19918 		_3:
  19919 			;
  19920 			i = i - 1
  19921 		}
  19922 		goto _2
  19923 	_2:
  19924 		;
  19925 		lz77_types_to_try = lz77_types_to_try & ^lz77_type
  19926 		lz77_type = lz77_type << int32(1)
  19927 	}
  19928 	// Improve on simple LZ77 but only for high quality (TraceBackwards is
  19929 	// costly).
  19930 	i = int32(1)
  19931 	for {
  19932 		if !(i >= 0) {
  19933 			break
  19934 		}
  19935 		if i == int32(1) && !(do_no_cache != 0) {
  19936 			goto _5
  19937 		}
  19938 		if (lz77_types_best[i] == int32(kLZ77Standard) || lz77_types_best[i] == int32(kLZ77Box)) && quality >= int32(25) {
  19939 			if lz77_types_best[i] == int32(kLZ77Standard) {
  19940 				v6 = hash_chain
  19941 			} else {
  19942 				v6 = bp
  19943 			}
  19944 			hash_chain_tmp = v6
  19945 			if i == int32(1) {
  19946 				v1 = 0
  19947 			} else {
  19948 				v1 = **(**int32)(__ccgo_up(cache_bits_best))
  19949 			}
  19950 			cache_bits1 = v1
  19951 			if !(VP8LBackwardReferencesTraceBackwards(tls, width, height, argb, cache_bits1, hash_chain_tmp, refs+uintptr(i)*40, refs_tmp) != 0) {
  19952 				goto Error
  19953 			}
  19954 			VP8LHistogramCreate(tls, histo, refs_tmp, cache_bits1)
  19955 			bit_cost_trace = VP8LHistogramEstimateBits(tls, histo)
  19956 			if bit_cost_trace < bit_costs_best[i] {
  19957 				BackwardRefsSwap(tls, refs_tmp, refs+uintptr(i)*40)
  19958 			}
  19959 		}
  19960 		BackwardReferences2DLocality(tls, width, refs+uintptr(i)*40)
  19961 		if i == int32(1) && lz77_types_best[0] == lz77_types_best[int32(1)] && **(**int32)(__ccgo_up(cache_bits_best)) == 0 {
  19962 			// If the best cache size is 0 and we have the same best LZ77, just copy
  19963 			// the data over and stop here.
  19964 			if !(BackwardRefsClone(tls, refs+1*40, refs) != 0) {
  19965 				goto Error
  19966 			}
  19967 			break
  19968 		}
  19969 		goto _5
  19970 	_5:
  19971 		;
  19972 		i = i - 1
  19973 	}
  19974 	status = int32(1)
  19975 	goto Error
  19976 Error:
  19977 	;
  19978 	VP8LHashChainClear(tls, bp)
  19979 	VP8LFreeHistogram(tls, histo)
  19980 	return status
  19981 }
  19982 
  19983 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) {
  19984 	var refs_best uintptr
  19985 	_ = refs_best
  19986 	if low_effort != 0 {
  19987 		**(**int32)(__ccgo_up(cache_bits_best)) = cache_bits_max
  19988 		refs_best = GetBackwardReferencesLowEffort(tls, width, height, argb, cache_bits_best, hash_chain, refs)
  19989 		if refs_best == libc.UintptrFromInt32(0) {
  19990 			return WebPEncodingSetError(tls, pic, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  19991 		}
  19992 		// Set it in first position.
  19993 		BackwardRefsSwap(tls, refs_best, refs)
  19994 	} else {
  19995 		if !(GetBackwardReferences(tls, width, height, argb, quality, lz77_types_to_try, cache_bits_max, do_no_cache, hash_chain, refs, cache_bits_best) != 0) {
  19996 			return WebPEncodingSetError(tls, pic, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  19997 		}
  19998 	}
  19999 	return WebPReportProgress(tls, pic, **(**int32)(__ccgo_up(percent))+percent_range, percent)
  20000 }
  20001 
  20002 const MAX_LEVEL1 = 9
  20003 const SIZE_MAX5 = "UINT64_MAX"
  20004 
  20005 //------------------------------------------------------------------------------
  20006 
  20007 // Copyright 2010 Google Inc. All Rights Reserved.
  20008 //
  20009 // Use of this source code is governed by a BSD-style license
  20010 // that can be found in the COPYING file in the root of the source
  20011 // tree. An additional intellectual property rights grant can be found
  20012 // in the file PATENTS. All contributing project authors may
  20013 // be found in the AUTHORS file in the root of the source tree.
  20014 // -----------------------------------------------------------------------------
  20015 //
  20016 //  Common types + memory wrappers
  20017 //
  20018 // Author: Skal (pascal.massimino@gmail.com)
  20019 
  20020 //------------------------------------------------------------------------------
  20021 // WebPConfig
  20022 //------------------------------------------------------------------------------
  20023 
  20024 func WebPConfigInitInternal(tls *libc.TLS, config uintptr, preset WebPPreset1, quality float32, version int32) (r int32) {
  20025 	if version>>int32(8) != libc.Int32FromInt32(WEBP_ENCODER_ABI_VERSION)>>libc.Int32FromInt32(8) {
  20026 		return 0 // caller/system version mismatch!
  20027 	}
  20028 	if config == libc.UintptrFromInt32(0) {
  20029 		return 0
  20030 	}
  20031 	(*WebPConfig)(unsafe.Pointer(config)).Fquality = quality
  20032 	(*WebPConfig)(unsafe.Pointer(config)).Ftarget_size = 0
  20033 	(*WebPConfig)(unsafe.Pointer(config)).Ftarget_PSNR = float32(0)
  20034 	(*WebPConfig)(unsafe.Pointer(config)).Fmethod = int32(4)
  20035 	(*WebPConfig)(unsafe.Pointer(config)).Fsns_strength = int32(50)
  20036 	(*WebPConfig)(unsafe.Pointer(config)).Ffilter_strength = int32(60) // mid-filtering
  20037 	(*WebPConfig)(unsafe.Pointer(config)).Ffilter_sharpness = 0
  20038 	(*WebPConfig)(unsafe.Pointer(config)).Ffilter_type = int32(1) // default: strong (so U/V is filtered too)
  20039 	(*WebPConfig)(unsafe.Pointer(config)).Fpartitions = 0
  20040 	(*WebPConfig)(unsafe.Pointer(config)).Fsegments = int32(4)
  20041 	(*WebPConfig)(unsafe.Pointer(config)).Fpass = int32(1)
  20042 	(*WebPConfig)(unsafe.Pointer(config)).Fqmin = 0
  20043 	(*WebPConfig)(unsafe.Pointer(config)).Fqmax = int32(100)
  20044 	(*WebPConfig)(unsafe.Pointer(config)).Fshow_compressed = 0
  20045 	(*WebPConfig)(unsafe.Pointer(config)).Fpreprocessing = 0
  20046 	(*WebPConfig)(unsafe.Pointer(config)).Fautofilter = 0
  20047 	(*WebPConfig)(unsafe.Pointer(config)).Fpartition_limit = 0
  20048 	(*WebPConfig)(unsafe.Pointer(config)).Falpha_compression = int32(1)
  20049 	(*WebPConfig)(unsafe.Pointer(config)).Falpha_filtering = int32(1)
  20050 	(*WebPConfig)(unsafe.Pointer(config)).Falpha_quality = int32(100)
  20051 	(*WebPConfig)(unsafe.Pointer(config)).Flossless = 0
  20052 	(*WebPConfig)(unsafe.Pointer(config)).Fexact = 0
  20053 	(*WebPConfig)(unsafe.Pointer(config)).Fimage_hint = int32(WEBP_HINT_DEFAULT)
  20054 	(*WebPConfig)(unsafe.Pointer(config)).Femulate_jpeg_size = 0
  20055 	(*WebPConfig)(unsafe.Pointer(config)).Fthread_level = 0
  20056 	(*WebPConfig)(unsafe.Pointer(config)).Flow_memory = 0
  20057 	(*WebPConfig)(unsafe.Pointer(config)).Fnear_lossless = int32(100)
  20058 	(*WebPConfig)(unsafe.Pointer(config)).Fuse_sharp_yuv = 0
  20059 	// TODO(skal): tune.
  20060 	switch preset {
  20061 	case int32(WEBP_PRESET_PICTURE):
  20062 		(*WebPConfig)(unsafe.Pointer(config)).Fsns_strength = int32(80)
  20063 		(*WebPConfig)(unsafe.Pointer(config)).Ffilter_sharpness = int32(4)
  20064 		(*WebPConfig)(unsafe.Pointer(config)).Ffilter_strength = int32(35)
  20065 		**(**int32)(__ccgo_up(config + 68)) &= ^libc.Int32FromInt32(2) // no dithering
  20066 	case int32(WEBP_PRESET_PHOTO):
  20067 		(*WebPConfig)(unsafe.Pointer(config)).Fsns_strength = int32(80)
  20068 		(*WebPConfig)(unsafe.Pointer(config)).Ffilter_sharpness = int32(3)
  20069 		(*WebPConfig)(unsafe.Pointer(config)).Ffilter_strength = int32(30)
  20070 		**(**int32)(__ccgo_up(config + 68)) |= int32(2)
  20071 	case int32(WEBP_PRESET_DRAWING):
  20072 		(*WebPConfig)(unsafe.Pointer(config)).Fsns_strength = int32(25)
  20073 		(*WebPConfig)(unsafe.Pointer(config)).Ffilter_sharpness = int32(6)
  20074 		(*WebPConfig)(unsafe.Pointer(config)).Ffilter_strength = int32(10)
  20075 	case int32(WEBP_PRESET_ICON):
  20076 		(*WebPConfig)(unsafe.Pointer(config)).Fsns_strength = 0
  20077 		(*WebPConfig)(unsafe.Pointer(config)).Ffilter_strength = 0     // disable filtering to retain sharpness
  20078 		**(**int32)(__ccgo_up(config + 68)) &= ^libc.Int32FromInt32(2) // no dithering
  20079 	case int32(WEBP_PRESET_TEXT):
  20080 		(*WebPConfig)(unsafe.Pointer(config)).Fsns_strength = 0
  20081 		(*WebPConfig)(unsafe.Pointer(config)).Ffilter_strength = 0     // disable filtering to retain sharpness
  20082 		**(**int32)(__ccgo_up(config + 68)) &= ^libc.Int32FromInt32(2) // no dithering
  20083 		(*WebPConfig)(unsafe.Pointer(config)).Fsegments = int32(2)
  20084 	case int32(WEBP_PRESET_DEFAULT):
  20085 		fallthrough
  20086 	default:
  20087 		break
  20088 	}
  20089 	return WebPValidateConfig(tls, config)
  20090 }
  20091 
  20092 func WebPValidateConfig(tls *libc.TLS, config uintptr) (r int32) {
  20093 	if config == libc.UintptrFromInt32(0) {
  20094 		return 0
  20095 	}
  20096 	if (*WebPConfig)(unsafe.Pointer(config)).Fquality < libc.Float32FromInt32(0) || (*WebPConfig)(unsafe.Pointer(config)).Fquality > libc.Float32FromInt32(100) {
  20097 		return 0
  20098 	}
  20099 	if (*WebPConfig)(unsafe.Pointer(config)).Ftarget_size < 0 {
  20100 		return 0
  20101 	}
  20102 	if (*WebPConfig)(unsafe.Pointer(config)).Ftarget_PSNR < libc.Float32FromInt32(0) {
  20103 		return 0
  20104 	}
  20105 	if (*WebPConfig)(unsafe.Pointer(config)).Fmethod < 0 || (*WebPConfig)(unsafe.Pointer(config)).Fmethod > int32(6) {
  20106 		return 0
  20107 	}
  20108 	if (*WebPConfig)(unsafe.Pointer(config)).Fsegments < int32(1) || (*WebPConfig)(unsafe.Pointer(config)).Fsegments > int32(4) {
  20109 		return 0
  20110 	}
  20111 	if (*WebPConfig)(unsafe.Pointer(config)).Fsns_strength < 0 || (*WebPConfig)(unsafe.Pointer(config)).Fsns_strength > int32(100) {
  20112 		return 0
  20113 	}
  20114 	if (*WebPConfig)(unsafe.Pointer(config)).Ffilter_strength < 0 || (*WebPConfig)(unsafe.Pointer(config)).Ffilter_strength > int32(100) {
  20115 		return 0
  20116 	}
  20117 	if (*WebPConfig)(unsafe.Pointer(config)).Ffilter_sharpness < 0 || (*WebPConfig)(unsafe.Pointer(config)).Ffilter_sharpness > int32(7) {
  20118 		return 0
  20119 	}
  20120 	if (*WebPConfig)(unsafe.Pointer(config)).Ffilter_type < 0 || (*WebPConfig)(unsafe.Pointer(config)).Ffilter_type > int32(1) {
  20121 		return 0
  20122 	}
  20123 	if (*WebPConfig)(unsafe.Pointer(config)).Fautofilter < 0 || (*WebPConfig)(unsafe.Pointer(config)).Fautofilter > int32(1) {
  20124 		return 0
  20125 	}
  20126 	if (*WebPConfig)(unsafe.Pointer(config)).Fpass < int32(1) || (*WebPConfig)(unsafe.Pointer(config)).Fpass > int32(10) {
  20127 		return 0
  20128 	}
  20129 	if (*WebPConfig)(unsafe.Pointer(config)).Fqmin < 0 || (*WebPConfig)(unsafe.Pointer(config)).Fqmax > int32(100) || (*WebPConfig)(unsafe.Pointer(config)).Fqmin > (*WebPConfig)(unsafe.Pointer(config)).Fqmax {
  20130 		return 0
  20131 	}
  20132 	if (*WebPConfig)(unsafe.Pointer(config)).Fshow_compressed < 0 || (*WebPConfig)(unsafe.Pointer(config)).Fshow_compressed > int32(1) {
  20133 		return 0
  20134 	}
  20135 	if (*WebPConfig)(unsafe.Pointer(config)).Fpreprocessing < 0 || (*WebPConfig)(unsafe.Pointer(config)).Fpreprocessing > int32(7) {
  20136 		return 0
  20137 	}
  20138 	if (*WebPConfig)(unsafe.Pointer(config)).Fpartitions < 0 || (*WebPConfig)(unsafe.Pointer(config)).Fpartitions > int32(3) {
  20139 		return 0
  20140 	}
  20141 	if (*WebPConfig)(unsafe.Pointer(config)).Fpartition_limit < 0 || (*WebPConfig)(unsafe.Pointer(config)).Fpartition_limit > int32(100) {
  20142 		return 0
  20143 	}
  20144 	if (*WebPConfig)(unsafe.Pointer(config)).Falpha_compression < 0 {
  20145 		return 0
  20146 	}
  20147 	if (*WebPConfig)(unsafe.Pointer(config)).Falpha_filtering < 0 {
  20148 		return 0
  20149 	}
  20150 	if (*WebPConfig)(unsafe.Pointer(config)).Falpha_quality < 0 || (*WebPConfig)(unsafe.Pointer(config)).Falpha_quality > int32(100) {
  20151 		return 0
  20152 	}
  20153 	if (*WebPConfig)(unsafe.Pointer(config)).Flossless < 0 || (*WebPConfig)(unsafe.Pointer(config)).Flossless > int32(1) {
  20154 		return 0
  20155 	}
  20156 	if (*WebPConfig)(unsafe.Pointer(config)).Fnear_lossless < 0 || (*WebPConfig)(unsafe.Pointer(config)).Fnear_lossless > int32(100) {
  20157 		return 0
  20158 	}
  20159 	if (*WebPConfig)(unsafe.Pointer(config)).Fimage_hint >= int32(WEBP_HINT_LAST) {
  20160 		return 0
  20161 	}
  20162 	if (*WebPConfig)(unsafe.Pointer(config)).Femulate_jpeg_size < 0 || (*WebPConfig)(unsafe.Pointer(config)).Femulate_jpeg_size > int32(1) {
  20163 		return 0
  20164 	}
  20165 	if (*WebPConfig)(unsafe.Pointer(config)).Fthread_level < 0 || (*WebPConfig)(unsafe.Pointer(config)).Fthread_level > int32(1) {
  20166 		return 0
  20167 	}
  20168 	if (*WebPConfig)(unsafe.Pointer(config)).Flow_memory < 0 || (*WebPConfig)(unsafe.Pointer(config)).Flow_memory > int32(1) {
  20169 		return 0
  20170 	}
  20171 	if (*WebPConfig)(unsafe.Pointer(config)).Fexact < 0 || (*WebPConfig)(unsafe.Pointer(config)).Fexact > int32(1) {
  20172 		return 0
  20173 	}
  20174 	if (*WebPConfig)(unsafe.Pointer(config)).Fuse_sharp_yuv < 0 || (*WebPConfig)(unsafe.Pointer(config)).Fuse_sharp_yuv > int32(1) {
  20175 		return 0
  20176 	}
  20177 	return int32(1)
  20178 }
  20179 
  20180 //------------------------------------------------------------------------------
  20181 
  20182 // C documentation
  20183 //
  20184 //	// Mapping between -z level and -m / -q parameter settings.
  20185 var kLosslessPresets = [10]struct {
  20186 	Fmethod  uint8_t
  20187 	Fquality uint8_t
  20188 }{
  20189 	0: {},
  20190 	1: {
  20191 		Fmethod:  uint8(1),
  20192 		Fquality: uint8(20),
  20193 	},
  20194 	2: {
  20195 		Fmethod:  uint8(2),
  20196 		Fquality: uint8(25),
  20197 	},
  20198 	3: {
  20199 		Fmethod:  uint8(3),
  20200 		Fquality: uint8(30),
  20201 	},
  20202 	4: {
  20203 		Fmethod:  uint8(3),
  20204 		Fquality: uint8(50),
  20205 	},
  20206 	5: {
  20207 		Fmethod:  uint8(4),
  20208 		Fquality: uint8(50),
  20209 	},
  20210 	6: {
  20211 		Fmethod:  uint8(4),
  20212 		Fquality: uint8(75),
  20213 	},
  20214 	7: {
  20215 		Fmethod:  uint8(4),
  20216 		Fquality: uint8(90),
  20217 	},
  20218 	8: {
  20219 		Fmethod:  uint8(5),
  20220 		Fquality: uint8(90),
  20221 	},
  20222 	9: {
  20223 		Fmethod:  uint8(6),
  20224 		Fquality: uint8(100),
  20225 	},
  20226 }
  20227 
  20228 func WebPConfigLosslessPreset(tls *libc.TLS, config uintptr, level int32) (r int32) {
  20229 	if config == libc.UintptrFromInt32(0) || level < 0 || level > int32(MAX_LEVEL1) {
  20230 		return 0
  20231 	}
  20232 	(*WebPConfig)(unsafe.Pointer(config)).Flossless = int32(1)
  20233 	(*WebPConfig)(unsafe.Pointer(config)).Fmethod = int32(kLosslessPresets[level].Fmethod)
  20234 	(*WebPConfig)(unsafe.Pointer(config)).Fquality = float32(kLosslessPresets[level].Fquality)
  20235 	return int32(1)
  20236 }
  20237 
  20238 const SIZE_MAX6 = "_UI64_MAX"
  20239 
  20240 type VP8Residual = struct {
  20241 	Ffirst      int32
  20242 	Flast       int32
  20243 	Fcoeffs     uintptr
  20244 	Fcoeff_type int32
  20245 	Fprob       uintptr
  20246 	Fstats      uintptr
  20247 	Fcosts      CostArrayPtr
  20248 }
  20249 
  20250 //------------------------------------------------------------------------------
  20251 
  20252 // Copyright 2011 Google Inc. All Rights Reserved.
  20253 //
  20254 // Use of this source code is governed by a BSD-style license
  20255 // that can be found in the COPYING file in the root of the source
  20256 // tree. An additional intellectual property rights grant can be found
  20257 // in the file PATENTS. All contributing project authors may
  20258 // be found in the AUTHORS file in the root of the source tree.
  20259 // -----------------------------------------------------------------------------
  20260 //
  20261 //   WebP encoder: internal header.
  20262 //
  20263 // Author: Skal (pascal.massimino@gmail.com)
  20264 
  20265 //------------------------------------------------------------------------------
  20266 // Level cost tables
  20267 
  20268 // C documentation
  20269 //
  20270 //	// For each given level, the following table gives the pattern of contexts to
  20271 //	// use for coding it (in [][0]) as well as the bit value to use for each
  20272 //	// context (in [][1]).
  20273 var VP8LevelCodes = [67][2]uint16_t{
  20274 	0: {
  20275 		0: uint16(0x001),
  20276 	},
  20277 	1: {
  20278 		0: uint16(0x007),
  20279 		1: uint16(0x001),
  20280 	},
  20281 	2: {
  20282 		0: uint16(0x00f),
  20283 		1: uint16(0x005),
  20284 	},
  20285 	3: {
  20286 		0: uint16(0x00f),
  20287 		1: uint16(0x00d),
  20288 	},
  20289 	4: {
  20290 		0: uint16(0x033),
  20291 		1: uint16(0x003),
  20292 	},
  20293 	5: {
  20294 		0: uint16(0x033),
  20295 		1: uint16(0x003),
  20296 	},
  20297 	6: {
  20298 		0: uint16(0x033),
  20299 		1: uint16(0x023),
  20300 	},
  20301 	7: {
  20302 		0: uint16(0x033),
  20303 		1: uint16(0x023),
  20304 	},
  20305 	8: {
  20306 		0: uint16(0x033),
  20307 		1: uint16(0x023),
  20308 	},
  20309 	9: {
  20310 		0: uint16(0x033),
  20311 		1: uint16(0x023),
  20312 	},
  20313 	10: {
  20314 		0: uint16(0x0d3),
  20315 		1: uint16(0x013),
  20316 	},
  20317 	11: {
  20318 		0: uint16(0x0d3),
  20319 		1: uint16(0x013),
  20320 	},
  20321 	12: {
  20322 		0: uint16(0x0d3),
  20323 		1: uint16(0x013),
  20324 	},
  20325 	13: {
  20326 		0: uint16(0x0d3),
  20327 		1: uint16(0x013),
  20328 	},
  20329 	14: {
  20330 		0: uint16(0x0d3),
  20331 		1: uint16(0x013),
  20332 	},
  20333 	15: {
  20334 		0: uint16(0x0d3),
  20335 		1: uint16(0x013),
  20336 	},
  20337 	16: {
  20338 		0: uint16(0x0d3),
  20339 		1: uint16(0x013),
  20340 	},
  20341 	17: {
  20342 		0: uint16(0x0d3),
  20343 		1: uint16(0x013),
  20344 	},
  20345 	18: {
  20346 		0: uint16(0x0d3),
  20347 		1: uint16(0x093),
  20348 	},
  20349 	19: {
  20350 		0: uint16(0x0d3),
  20351 		1: uint16(0x093),
  20352 	},
  20353 	20: {
  20354 		0: uint16(0x0d3),
  20355 		1: uint16(0x093),
  20356 	},
  20357 	21: {
  20358 		0: uint16(0x0d3),
  20359 		1: uint16(0x093),
  20360 	},
  20361 	22: {
  20362 		0: uint16(0x0d3),
  20363 		1: uint16(0x093),
  20364 	},
  20365 	23: {
  20366 		0: uint16(0x0d3),
  20367 		1: uint16(0x093),
  20368 	},
  20369 	24: {
  20370 		0: uint16(0x0d3),
  20371 		1: uint16(0x093),
  20372 	},
  20373 	25: {
  20374 		0: uint16(0x0d3),
  20375 		1: uint16(0x093),
  20376 	},
  20377 	26: {
  20378 		0: uint16(0x0d3),
  20379 		1: uint16(0x093),
  20380 	},
  20381 	27: {
  20382 		0: uint16(0x0d3),
  20383 		1: uint16(0x093),
  20384 	},
  20385 	28: {
  20386 		0: uint16(0x0d3),
  20387 		1: uint16(0x093),
  20388 	},
  20389 	29: {
  20390 		0: uint16(0x0d3),
  20391 		1: uint16(0x093),
  20392 	},
  20393 	30: {
  20394 		0: uint16(0x0d3),
  20395 		1: uint16(0x093),
  20396 	},
  20397 	31: {
  20398 		0: uint16(0x0d3),
  20399 		1: uint16(0x093),
  20400 	},
  20401 	32: {
  20402 		0: uint16(0x0d3),
  20403 		1: uint16(0x093),
  20404 	},
  20405 	33: {
  20406 		0: uint16(0x0d3),
  20407 		1: uint16(0x093),
  20408 	},
  20409 	34: {
  20410 		0: uint16(0x153),
  20411 		1: uint16(0x053),
  20412 	},
  20413 	35: {
  20414 		0: uint16(0x153),
  20415 		1: uint16(0x053),
  20416 	},
  20417 	36: {
  20418 		0: uint16(0x153),
  20419 		1: uint16(0x053),
  20420 	},
  20421 	37: {
  20422 		0: uint16(0x153),
  20423 		1: uint16(0x053),
  20424 	},
  20425 	38: {
  20426 		0: uint16(0x153),
  20427 		1: uint16(0x053),
  20428 	},
  20429 	39: {
  20430 		0: uint16(0x153),
  20431 		1: uint16(0x053),
  20432 	},
  20433 	40: {
  20434 		0: uint16(0x153),
  20435 		1: uint16(0x053),
  20436 	},
  20437 	41: {
  20438 		0: uint16(0x153),
  20439 		1: uint16(0x053),
  20440 	},
  20441 	42: {
  20442 		0: uint16(0x153),
  20443 		1: uint16(0x053),
  20444 	},
  20445 	43: {
  20446 		0: uint16(0x153),
  20447 		1: uint16(0x053),
  20448 	},
  20449 	44: {
  20450 		0: uint16(0x153),
  20451 		1: uint16(0x053),
  20452 	},
  20453 	45: {
  20454 		0: uint16(0x153),
  20455 		1: uint16(0x053),
  20456 	},
  20457 	46: {
  20458 		0: uint16(0x153),
  20459 		1: uint16(0x053),
  20460 	},
  20461 	47: {
  20462 		0: uint16(0x153),
  20463 		1: uint16(0x053),
  20464 	},
  20465 	48: {
  20466 		0: uint16(0x153),
  20467 		1: uint16(0x053),
  20468 	},
  20469 	49: {
  20470 		0: uint16(0x153),
  20471 		1: uint16(0x053),
  20472 	},
  20473 	50: {
  20474 		0: uint16(0x153),
  20475 		1: uint16(0x053),
  20476 	},
  20477 	51: {
  20478 		0: uint16(0x153),
  20479 		1: uint16(0x053),
  20480 	},
  20481 	52: {
  20482 		0: uint16(0x153),
  20483 		1: uint16(0x053),
  20484 	},
  20485 	53: {
  20486 		0: uint16(0x153),
  20487 		1: uint16(0x053),
  20488 	},
  20489 	54: {
  20490 		0: uint16(0x153),
  20491 		1: uint16(0x053),
  20492 	},
  20493 	55: {
  20494 		0: uint16(0x153),
  20495 		1: uint16(0x053),
  20496 	},
  20497 	56: {
  20498 		0: uint16(0x153),
  20499 		1: uint16(0x053),
  20500 	},
  20501 	57: {
  20502 		0: uint16(0x153),
  20503 		1: uint16(0x053),
  20504 	},
  20505 	58: {
  20506 		0: uint16(0x153),
  20507 		1: uint16(0x053),
  20508 	},
  20509 	59: {
  20510 		0: uint16(0x153),
  20511 		1: uint16(0x053),
  20512 	},
  20513 	60: {
  20514 		0: uint16(0x153),
  20515 		1: uint16(0x053),
  20516 	},
  20517 	61: {
  20518 		0: uint16(0x153),
  20519 		1: uint16(0x053),
  20520 	},
  20521 	62: {
  20522 		0: uint16(0x153),
  20523 		1: uint16(0x053),
  20524 	},
  20525 	63: {
  20526 		0: uint16(0x153),
  20527 		1: uint16(0x053),
  20528 	},
  20529 	64: {
  20530 		0: uint16(0x153),
  20531 		1: uint16(0x053),
  20532 	},
  20533 	65: {
  20534 		0: uint16(0x153),
  20535 		1: uint16(0x053),
  20536 	},
  20537 	66: {
  20538 		0: uint16(0x153),
  20539 		1: uint16(0x153),
  20540 	},
  20541 }
  20542 
  20543 func VariableLevelCost(tls *libc.TLS, level int32, probas uintptr) (r int32) {
  20544 	var bits, cost, i, pattern, v3, v5 int32
  20545 	var v2 uint8_t
  20546 	_, _, _, _, _, _, _ = bits, cost, i, pattern, v2, v3, v5
  20547 	pattern = int32(**(**uint16_t)(__ccgo_up(uintptr(unsafe.Pointer(&VP8LevelCodes)) + uintptr(level-int32(1))*4)))
  20548 	bits = int32(**(**uint16_t)(__ccgo_up(uintptr(unsafe.Pointer(&VP8LevelCodes)) + uintptr(level-int32(1))*4 + 1*2)))
  20549 	cost = 0
  20550 	i = int32(2)
  20551 	for {
  20552 		if !(pattern != 0) {
  20553 			break
  20554 		}
  20555 		if pattern&int32(1) != 0 {
  20556 			v2 = **(**uint8_t)(__ccgo_up(probas + uintptr(i)))
  20557 			if !(bits&int32(1) != 0) {
  20558 				v5 = int32(VP8EntropyCost[v2])
  20559 			} else {
  20560 				v5 = int32(VP8EntropyCost[int32(255)-int32(v2)])
  20561 			}
  20562 			v3 = v5
  20563 			goto _4
  20564 		_4:
  20565 			cost = cost + v3
  20566 		}
  20567 		bits = bits >> int32(1)
  20568 		pattern = pattern >> int32(1)
  20569 		goto _1
  20570 	_1:
  20571 		;
  20572 		i = i + 1
  20573 	}
  20574 	return cost
  20575 }
  20576 
  20577 //------------------------------------------------------------------------------
  20578 // Pre-calc level costs once for all
  20579 
  20580 func VP8CalculateLevelCosts(tls *libc.TLS, proba1 uintptr) {
  20581 	var band, cost0, cost_base, ctx, ctype, n, v, v10, v12, v14, v16, v4, v6, v8 int32
  20582 	var p, table uintptr
  20583 	var v13, v5, v9 uint8_t
  20584 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = band, cost0, cost_base, ctx, ctype, n, p, table, v, v10, v12, v13, v14, v16, v4, v5, v6, v8, v9
  20585 	if !((*VP8EncProba)(unsafe.Pointer(proba1)).Fdirty != 0) {
  20586 		return
  20587 	} // nothing to do.
  20588 	ctype = 0
  20589 	for {
  20590 		if !(ctype < int32(NUM_TYPES)) {
  20591 			break
  20592 		}
  20593 		band = 0
  20594 		for {
  20595 			if !(band < int32(NUM_BANDS)) {
  20596 				break
  20597 			}
  20598 			ctx = 0
  20599 			for {
  20600 				if !(ctx < int32(NUM_CTX)) {
  20601 					break
  20602 				}
  20603 				p = proba1 + 4 + uintptr(ctype)*264 + uintptr(band)*33 + uintptr(ctx)*11
  20604 				table = proba1 + 5284 + uintptr(ctype)*3264 + uintptr(band)*408 + uintptr(ctx)*136
  20605 				if ctx > 0 {
  20606 					v5 = **(**uint8_t)(__ccgo_up(p))
  20607 					if !(int32(1) != 0) {
  20608 						v8 = int32(VP8EntropyCost[v5])
  20609 					} else {
  20610 						v8 = int32(VP8EntropyCost[int32(255)-int32(v5)])
  20611 					}
  20612 					v6 = v8
  20613 					goto _7
  20614 				_7:
  20615 					v4 = v6
  20616 				} else {
  20617 					v4 = 0
  20618 				}
  20619 				cost0 = v4
  20620 				v9 = **(**uint8_t)(__ccgo_up(p + 1))
  20621 				if !(int32(1) != 0) {
  20622 					v12 = int32(VP8EntropyCost[v9])
  20623 				} else {
  20624 					v12 = int32(VP8EntropyCost[int32(255)-int32(v9)])
  20625 				}
  20626 				v10 = v12
  20627 				goto _11
  20628 			_11:
  20629 				cost_base = v10 + cost0
  20630 				v13 = **(**uint8_t)(__ccgo_up(p + 1))
  20631 				if !(0 != 0) {
  20632 					v16 = int32(VP8EntropyCost[v13])
  20633 				} else {
  20634 					v16 = int32(VP8EntropyCost[int32(255)-int32(v13)])
  20635 				}
  20636 				v14 = v16
  20637 				goto _15
  20638 			_15:
  20639 				**(**uint16_t)(__ccgo_up(table)) = uint16(v14 + cost0)
  20640 				v = int32(1)
  20641 				for {
  20642 					if !(v <= int32(MAX_VARIABLE_LEVEL)) {
  20643 						break
  20644 					}
  20645 					**(**uint16_t)(__ccgo_up(table + uintptr(v)*2)) = uint16(cost_base + VariableLevelCost(tls, v, p))
  20646 					goto _17
  20647 				_17:
  20648 					;
  20649 					v = v + 1
  20650 				}
  20651 				// Starting at level 67 and up, the variable part of the cost is
  20652 				// actually constant.
  20653 				goto _3
  20654 			_3:
  20655 				;
  20656 				ctx = ctx + 1
  20657 			}
  20658 			goto _2
  20659 		_2:
  20660 			;
  20661 			band = band + 1
  20662 		}
  20663 		n = 0
  20664 		for {
  20665 			if !(n < int32(16)) {
  20666 				break
  20667 			} // replicate bands. We don't need to sentinel.
  20668 			ctx = 0
  20669 			for {
  20670 				if !(ctx < int32(NUM_CTX)) {
  20671 					break
  20672 				}
  20673 				**(**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
  20674 				goto _19
  20675 			_19:
  20676 				;
  20677 				ctx = ctx + 1
  20678 			}
  20679 			goto _18
  20680 		_18:
  20681 			;
  20682 			n = n + 1
  20683 		}
  20684 		goto _1
  20685 	_1:
  20686 		;
  20687 		ctype = ctype + 1
  20688 	}
  20689 	(*VP8EncProba)(unsafe.Pointer(proba1)).Fdirty = 0
  20690 }
  20691 
  20692 //------------------------------------------------------------------------------
  20693 // helper functions for residuals struct VP8Residual.
  20694 
  20695 func VP8InitResidual(tls *libc.TLS, first int32, coeff_type int32, enc uintptr, res uintptr) {
  20696 	(*VP8Residual)(unsafe.Pointer(res)).Fcoeff_type = coeff_type
  20697 	(*VP8Residual)(unsafe.Pointer(res)).Fprob = enc + 3616 + 4 + uintptr(coeff_type)*264
  20698 	(*VP8Residual)(unsafe.Pointer(res)).Fstats = enc + 3616 + 1060 + uintptr(coeff_type)*1056
  20699 	(*VP8Residual)(unsafe.Pointer(res)).Fcosts = enc + 3616 + 18344 + uintptr(coeff_type)*384
  20700 	(*VP8Residual)(unsafe.Pointer(res)).Ffirst = first
  20701 }
  20702 
  20703 //------------------------------------------------------------------------------
  20704 // Mode costs
  20705 
  20706 func VP8GetCostLuma4(tls *libc.TLS, it uintptr, levels uintptr) (r int32) {
  20707 	bp := tls.Alloc(48)
  20708 	defer tls.Free(48)
  20709 	var R, ctx, x, y int32
  20710 	var enc uintptr
  20711 	var _ /* res at bp+0 */ VP8Residual
  20712 	_, _, _, _, _ = R, ctx, enc, x, y
  20713 	x = (*VP8EncIterator)(unsafe.Pointer(it)).Fi4 & libc.Int32FromInt32(3)
  20714 	y = (*VP8EncIterator)(unsafe.Pointer(it)).Fi4 >> libc.Int32FromInt32(2)
  20715 	enc = (*VP8EncIterator)(unsafe.Pointer(it)).Fenc
  20716 	R = 0
  20717 	VP8InitResidual(tls, 0, int32(3), enc, bp)
  20718 	ctx = **(**int32)(__ccgo_up(it + 132 + uintptr(x)*4)) + **(**int32)(__ccgo_up(it + 168 + uintptr(y)*4))
  20719 	(*(*func(*libc.TLS, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8SetResidualCoeffs})))(tls, levels, bp)
  20720 	R = R + (*(*func(*libc.TLS, int32, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{VP8GetResidualCost})))(tls, ctx, bp)
  20721 	return R
  20722 }
  20723 
  20724 func VP8GetCostLuma16(tls *libc.TLS, it uintptr, rd uintptr) (r int32) {
  20725 	bp := tls.Alloc(48)
  20726 	defer tls.Free(48)
  20727 	var R, ctx, x, y, v3 int32
  20728 	var enc uintptr
  20729 	var _ /* res at bp+0 */ VP8Residual
  20730 	_, _, _, _, _, _ = R, ctx, enc, x, y, v3
  20731 	enc = (*VP8EncIterator)(unsafe.Pointer(it)).Fenc
  20732 	R = 0
  20733 	VP8IteratorNzToBytes(tls, it) // re-import the non-zero context
  20734 	// DC
  20735 	VP8InitResidual(tls, 0, int32(1), enc, bp)
  20736 	(*(*func(*libc.TLS, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8SetResidualCoeffs})))(tls, rd+40, bp)
  20737 	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)
  20738 	// AC
  20739 	VP8InitResidual(tls, int32(1), 0, enc, bp)
  20740 	y = 0
  20741 	for {
  20742 		if !(y < int32(4)) {
  20743 			break
  20744 		}
  20745 		x = 0
  20746 		for {
  20747 			if !(x < int32(4)) {
  20748 				break
  20749 			}
  20750 			ctx = **(**int32)(__ccgo_up(it + 132 + uintptr(x)*4)) + **(**int32)(__ccgo_up(it + 168 + uintptr(y)*4))
  20751 			(*(*func(*libc.TLS, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8SetResidualCoeffs})))(tls, rd+72+uintptr(x+y*int32(4))*32, bp)
  20752 			R = R + (*(*func(*libc.TLS, int32, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{VP8GetResidualCost})))(tls, ctx, bp)
  20753 			v3 = libc.BoolInt32((**(**VP8Residual)(__ccgo_up(bp))).Flast >= libc.Int32FromInt32(0))
  20754 			**(**int32)(__ccgo_up(it + 168 + uintptr(y)*4)) = v3
  20755 			**(**int32)(__ccgo_up(it + 132 + uintptr(x)*4)) = v3
  20756 			goto _2
  20757 		_2:
  20758 			;
  20759 			x = x + 1
  20760 		}
  20761 		goto _1
  20762 	_1:
  20763 		;
  20764 		y = y + 1
  20765 	}
  20766 	return R
  20767 }
  20768 
  20769 func VP8GetCostUV(tls *libc.TLS, it uintptr, rd uintptr) (r int32) {
  20770 	bp := tls.Alloc(48)
  20771 	defer tls.Free(48)
  20772 	var R, ch, ctx, x, y, v4 int32
  20773 	var enc uintptr
  20774 	var _ /* res at bp+0 */ VP8Residual
  20775 	_, _, _, _, _, _, _ = R, ch, ctx, enc, x, y, v4
  20776 	enc = (*VP8EncIterator)(unsafe.Pointer(it)).Fenc
  20777 	R = 0
  20778 	VP8IteratorNzToBytes(tls, it) // re-import the non-zero context
  20779 	VP8InitResidual(tls, 0, int32(2), enc, bp)
  20780 	ch = 0
  20781 	for {
  20782 		if !(ch <= int32(2)) {
  20783 			break
  20784 		}
  20785 		y = 0
  20786 		for {
  20787 			if !(y < int32(2)) {
  20788 				break
  20789 			}
  20790 			x = 0
  20791 			for {
  20792 				if !(x < int32(2)) {
  20793 					break
  20794 				}
  20795 				ctx = **(**int32)(__ccgo_up(it + 132 + uintptr(int32(4)+ch+x)*4)) + **(**int32)(__ccgo_up(it + 168 + uintptr(int32(4)+ch+y)*4))
  20796 				(*(*func(*libc.TLS, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8SetResidualCoeffs})))(tls, rd+584+uintptr(ch*int32(2)+x+y*int32(2))*32, bp)
  20797 				R = R + (*(*func(*libc.TLS, int32, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{VP8GetResidualCost})))(tls, ctx, bp)
  20798 				v4 = libc.BoolInt32((**(**VP8Residual)(__ccgo_up(bp))).Flast >= libc.Int32FromInt32(0))
  20799 				**(**int32)(__ccgo_up(it + 168 + uintptr(int32(4)+ch+y)*4)) = v4
  20800 				**(**int32)(__ccgo_up(it + 132 + uintptr(int32(4)+ch+x)*4)) = v4
  20801 				goto _3
  20802 			_3:
  20803 				;
  20804 				x = x + 1
  20805 			}
  20806 			goto _2
  20807 		_2:
  20808 			;
  20809 			y = y + 1
  20810 		}
  20811 		goto _1
  20812 	_1:
  20813 		;
  20814 		ch = ch + int32(2)
  20815 	}
  20816 	return R
  20817 }
  20818 
  20819 //------------------------------------------------------------------------------
  20820 // Recording of token probabilities.
  20821 
  20822 // We keep the table-free variant around for reference, in case.
  20823 
  20824 // C documentation
  20825 //
  20826 //	// Simulate block coding, but only record statistics.
  20827 //	// Note: no need to record the fixed probas.
  20828 func VP8RecordCoeffs(tls *libc.TLS, ctx int32, res uintptr) (r int32) {
  20829 	var bits, i, mask, n, pattern, v, v1, v4, v7 int32
  20830 	var p proba_t
  20831 	var s, v2 uintptr
  20832 	_, _, _, _, _, _, _, _, _, _, _, _ = bits, i, mask, n, p, pattern, s, v, v1, v2, v4, v7
  20833 	n = (*VP8Residual)(unsafe.Pointer(res)).Ffirst
  20834 	// should be stats[VP8EncBands[n]], but it's equivalent for n=0 or 1
  20835 	s = (*VP8Residual)(unsafe.Pointer(res)).Fstats + uintptr(n)*132 + uintptr(ctx)*44
  20836 	if (*VP8Residual)(unsafe.Pointer(res)).Flast < 0 {
  20837 		v1 = 0
  20838 		v2 = s + uintptr(0)*4
  20839 		p = **(**proba_t)(__ccgo_up(v2))
  20840 		if p >= libc.Uint32FromUint32(0xfffe0000) {
  20841 			p = (p + uint32(1)) >> int32(1) & uint32(0x7fff7fff)
  20842 		}
  20843 		p = p + (uint32(0x00010000) + uint32(v1))
  20844 		**(**proba_t)(__ccgo_up(v2)) = p
  20845 		_ = v1
  20846 		goto _3
  20847 	_3:
  20848 		;
  20849 		return 0
  20850 	}
  20851 	for n <= (*VP8Residual)(unsafe.Pointer(res)).Flast {
  20852 		v1 = int32(1)
  20853 		v2 = s + uintptr(0)*4
  20854 		p = **(**proba_t)(__ccgo_up(v2))
  20855 		if p >= libc.Uint32FromUint32(0xfffe0000) {
  20856 			p = (p + uint32(1)) >> int32(1) & uint32(0x7fff7fff)
  20857 		}
  20858 		p = p + (uint32(0x00010000) + uint32(v1))
  20859 		**(**proba_t)(__ccgo_up(v2)) = p
  20860 		_ = v1
  20861 		goto _6
  20862 	_6:
  20863 		; // order of record doesn't matter
  20864 		for {
  20865 			v4 = n
  20866 			n = n + 1
  20867 			v1 = int32(**(**int16_t)(__ccgo_up((*VP8Residual)(unsafe.Pointer(res)).Fcoeffs + uintptr(v4)*2)))
  20868 			v = v1
  20869 			if !(v1 == 0) {
  20870 				break
  20871 			}
  20872 			v7 = 0
  20873 			v2 = s + uintptr(1)*4
  20874 			p = **(**proba_t)(__ccgo_up(v2))
  20875 			if p >= libc.Uint32FromUint32(0xfffe0000) {
  20876 				p = (p + uint32(1)) >> int32(1) & uint32(0x7fff7fff)
  20877 			}
  20878 			p = p + (uint32(0x00010000) + uint32(v7))
  20879 			**(**proba_t)(__ccgo_up(v2)) = p
  20880 			_ = v7
  20881 			goto _11
  20882 		_11:
  20883 			;
  20884 			s = (*VP8Residual)(unsafe.Pointer(res)).Fstats + uintptr(VP8EncBands[n])*132
  20885 		}
  20886 		v1 = int32(1)
  20887 		v2 = s + uintptr(1)*4
  20888 		p = **(**proba_t)(__ccgo_up(v2))
  20889 		if p >= libc.Uint32FromUint32(0xfffe0000) {
  20890 			p = (p + uint32(1)) >> int32(1) & uint32(0x7fff7fff)
  20891 		}
  20892 		p = p + (uint32(0x00010000) + uint32(v1))
  20893 		**(**proba_t)(__ccgo_up(v2)) = p
  20894 		_ = v1
  20895 		goto _14
  20896 	_14:
  20897 		;
  20898 		v1 = libc.BoolInt32(uint32(2) < uint32(v+libc.Int32FromInt32(1)))
  20899 		v2 = s + uintptr(2)*4
  20900 		p = **(**proba_t)(__ccgo_up(v2))
  20901 		if p >= libc.Uint32FromUint32(0xfffe0000) {
  20902 			p = (p + uint32(1)) >> int32(1) & uint32(0x7fff7fff)
  20903 		}
  20904 		p = p + (uint32(0x00010000) + uint32(v1))
  20905 		**(**proba_t)(__ccgo_up(v2)) = p
  20906 		v4 = v1
  20907 		goto _18
  20908 	_18:
  20909 		if !(v4 != 0) { // v = -1 or 1
  20910 			s = (*VP8Residual)(unsafe.Pointer(res)).Fstats + uintptr(VP8EncBands[n])*132 + 1*44
  20911 		} else {
  20912 			v = libc.Xabs(tls, v)
  20913 			if v > int32(MAX_VARIABLE_LEVEL) {
  20914 				v = int32(MAX_VARIABLE_LEVEL)
  20915 			}
  20916 			bits = int32(**(**uint16_t)(__ccgo_up(uintptr(unsafe.Pointer(&VP8LevelCodes)) + uintptr(v-int32(1))*4 + 1*2)))
  20917 			pattern = int32(**(**uint16_t)(__ccgo_up(uintptr(unsafe.Pointer(&VP8LevelCodes)) + uintptr(v-int32(1))*4)))
  20918 			i = 0
  20919 			for {
  20920 				pattern = pattern >> int32(1)
  20921 				if !(pattern != 0) {
  20922 					break
  20923 				}
  20924 				mask = int32(2) << i
  20925 				if pattern&int32(1) != 0 {
  20926 					v1 = libc.BoolInt32(!!(bits&mask != 0))
  20927 					v2 = s + uintptr(3)*4 + uintptr(i)*4
  20928 					p = **(**proba_t)(__ccgo_up(v2))
  20929 					if p >= libc.Uint32FromUint32(0xfffe0000) {
  20930 						p = (p + uint32(1)) >> int32(1) & uint32(0x7fff7fff)
  20931 					}
  20932 					p = p + (uint32(0x00010000) + uint32(v1))
  20933 					**(**proba_t)(__ccgo_up(v2)) = p
  20934 					_ = v1
  20935 					goto _22
  20936 				_22:
  20937 				}
  20938 				goto _19
  20939 			_19:
  20940 				;
  20941 				i = i + 1
  20942 			}
  20943 			s = (*VP8Residual)(unsafe.Pointer(res)).Fstats + uintptr(VP8EncBands[n])*132 + 2*44
  20944 		}
  20945 	}
  20946 	if n < int32(16) {
  20947 		v1 = 0
  20948 		v2 = s + uintptr(0)*4
  20949 		p = **(**proba_t)(__ccgo_up(v2))
  20950 		if p >= libc.Uint32FromUint32(0xfffe0000) {
  20951 			p = (p + uint32(1)) >> int32(1) & uint32(0x7fff7fff)
  20952 		}
  20953 		p = p + (uint32(0x00010000) + uint32(v1))
  20954 		**(**proba_t)(__ccgo_up(v2)) = p
  20955 		_ = v1
  20956 		goto _25
  20957 	_25:
  20958 	}
  20959 	return int32(1)
  20960 }
  20961 
  20962 const MAX_DELTA_SIZE = 64
  20963 const SIZE_MAX7 = "UINT64_MAX"
  20964 
  20965 //------------------------------------------------------------------------------
  20966 
  20967 // C documentation
  20968 //
  20969 //	// This table gives, for a given sharpness, the filtering strength to be
  20970 //	// used (at least) in order to filter a given edge step delta.
  20971 //	// This is constructed by brute force inspection: for all delta, we iterate
  20972 //	// over all possible filtering strength / thresh until needs_filter() returns
  20973 //	// true.
  20974 var kLevelsFromDelta = [8][64]uint8_t{
  20975 	0: {
  20976 		1:  uint8(1),
  20977 		2:  uint8(2),
  20978 		3:  uint8(3),
  20979 		4:  uint8(4),
  20980 		5:  uint8(5),
  20981 		6:  uint8(6),
  20982 		7:  uint8(7),
  20983 		8:  uint8(8),
  20984 		9:  uint8(9),
  20985 		10: uint8(10),
  20986 		11: uint8(11),
  20987 		12: uint8(12),
  20988 		13: uint8(13),
  20989 		14: uint8(14),
  20990 		15: uint8(15),
  20991 		16: uint8(16),
  20992 		17: uint8(17),
  20993 		18: uint8(18),
  20994 		19: uint8(19),
  20995 		20: uint8(20),
  20996 		21: uint8(21),
  20997 		22: uint8(22),
  20998 		23: uint8(23),
  20999 		24: uint8(24),
  21000 		25: uint8(25),
  21001 		26: uint8(26),
  21002 		27: uint8(27),
  21003 		28: uint8(28),
  21004 		29: uint8(29),
  21005 		30: uint8(30),
  21006 		31: uint8(31),
  21007 		32: uint8(32),
  21008 		33: uint8(33),
  21009 		34: uint8(34),
  21010 		35: uint8(35),
  21011 		36: uint8(36),
  21012 		37: uint8(37),
  21013 		38: uint8(38),
  21014 		39: uint8(39),
  21015 		40: uint8(40),
  21016 		41: uint8(41),
  21017 		42: uint8(42),
  21018 		43: uint8(43),
  21019 		44: uint8(44),
  21020 		45: uint8(45),
  21021 		46: uint8(46),
  21022 		47: uint8(47),
  21023 		48: uint8(48),
  21024 		49: uint8(49),
  21025 		50: uint8(50),
  21026 		51: uint8(51),
  21027 		52: uint8(52),
  21028 		53: uint8(53),
  21029 		54: uint8(54),
  21030 		55: uint8(55),
  21031 		56: uint8(56),
  21032 		57: uint8(57),
  21033 		58: uint8(58),
  21034 		59: uint8(59),
  21035 		60: uint8(60),
  21036 		61: uint8(61),
  21037 		62: uint8(62),
  21038 		63: uint8(63),
  21039 	},
  21040 	1: {
  21041 		1:  uint8(1),
  21042 		2:  uint8(2),
  21043 		3:  uint8(3),
  21044 		4:  uint8(5),
  21045 		5:  uint8(6),
  21046 		6:  uint8(7),
  21047 		7:  uint8(8),
  21048 		8:  uint8(9),
  21049 		9:  uint8(11),
  21050 		10: uint8(12),
  21051 		11: uint8(13),
  21052 		12: uint8(14),
  21053 		13: uint8(15),
  21054 		14: uint8(17),
  21055 		15: uint8(18),
  21056 		16: uint8(20),
  21057 		17: uint8(21),
  21058 		18: uint8(23),
  21059 		19: uint8(24),
  21060 		20: uint8(26),
  21061 		21: uint8(27),
  21062 		22: uint8(29),
  21063 		23: uint8(30),
  21064 		24: uint8(32),
  21065 		25: uint8(33),
  21066 		26: uint8(35),
  21067 		27: uint8(36),
  21068 		28: uint8(38),
  21069 		29: uint8(39),
  21070 		30: uint8(41),
  21071 		31: uint8(42),
  21072 		32: uint8(44),
  21073 		33: uint8(45),
  21074 		34: uint8(47),
  21075 		35: uint8(48),
  21076 		36: uint8(50),
  21077 		37: uint8(51),
  21078 		38: uint8(53),
  21079 		39: uint8(54),
  21080 		40: uint8(56),
  21081 		41: uint8(57),
  21082 		42: uint8(59),
  21083 		43: uint8(60),
  21084 		44: uint8(62),
  21085 		45: uint8(63),
  21086 		46: uint8(63),
  21087 		47: uint8(63),
  21088 		48: uint8(63),
  21089 		49: uint8(63),
  21090 		50: uint8(63),
  21091 		51: uint8(63),
  21092 		52: uint8(63),
  21093 		53: uint8(63),
  21094 		54: uint8(63),
  21095 		55: uint8(63),
  21096 		56: uint8(63),
  21097 		57: uint8(63),
  21098 		58: uint8(63),
  21099 		59: uint8(63),
  21100 		60: uint8(63),
  21101 		61: uint8(63),
  21102 		62: uint8(63),
  21103 		63: uint8(63),
  21104 	},
  21105 	2: {
  21106 		1:  uint8(1),
  21107 		2:  uint8(2),
  21108 		3:  uint8(3),
  21109 		4:  uint8(5),
  21110 		5:  uint8(6),
  21111 		6:  uint8(7),
  21112 		7:  uint8(8),
  21113 		8:  uint8(9),
  21114 		9:  uint8(11),
  21115 		10: uint8(12),
  21116 		11: uint8(13),
  21117 		12: uint8(14),
  21118 		13: uint8(16),
  21119 		14: uint8(17),
  21120 		15: uint8(19),
  21121 		16: uint8(20),
  21122 		17: uint8(22),
  21123 		18: uint8(23),
  21124 		19: uint8(25),
  21125 		20: uint8(26),
  21126 		21: uint8(28),
  21127 		22: uint8(29),
  21128 		23: uint8(31),
  21129 		24: uint8(32),
  21130 		25: uint8(34),
  21131 		26: uint8(35),
  21132 		27: uint8(37),
  21133 		28: uint8(38),
  21134 		29: uint8(40),
  21135 		30: uint8(41),
  21136 		31: uint8(43),
  21137 		32: uint8(44),
  21138 		33: uint8(46),
  21139 		34: uint8(47),
  21140 		35: uint8(49),
  21141 		36: uint8(50),
  21142 		37: uint8(52),
  21143 		38: uint8(53),
  21144 		39: uint8(55),
  21145 		40: uint8(56),
  21146 		41: uint8(58),
  21147 		42: uint8(59),
  21148 		43: uint8(61),
  21149 		44: uint8(62),
  21150 		45: uint8(63),
  21151 		46: uint8(63),
  21152 		47: uint8(63),
  21153 		48: uint8(63),
  21154 		49: uint8(63),
  21155 		50: uint8(63),
  21156 		51: uint8(63),
  21157 		52: uint8(63),
  21158 		53: uint8(63),
  21159 		54: uint8(63),
  21160 		55: uint8(63),
  21161 		56: uint8(63),
  21162 		57: uint8(63),
  21163 		58: uint8(63),
  21164 		59: uint8(63),
  21165 		60: uint8(63),
  21166 		61: uint8(63),
  21167 		62: uint8(63),
  21168 		63: uint8(63),
  21169 	},
  21170 	3: {
  21171 		1:  uint8(1),
  21172 		2:  uint8(2),
  21173 		3:  uint8(3),
  21174 		4:  uint8(5),
  21175 		5:  uint8(6),
  21176 		6:  uint8(7),
  21177 		7:  uint8(8),
  21178 		8:  uint8(9),
  21179 		9:  uint8(11),
  21180 		10: uint8(12),
  21181 		11: uint8(13),
  21182 		12: uint8(15),
  21183 		13: uint8(16),
  21184 		14: uint8(18),
  21185 		15: uint8(19),
  21186 		16: uint8(21),
  21187 		17: uint8(22),
  21188 		18: uint8(24),
  21189 		19: uint8(25),
  21190 		20: uint8(27),
  21191 		21: uint8(28),
  21192 		22: uint8(30),
  21193 		23: uint8(31),
  21194 		24: uint8(33),
  21195 		25: uint8(34),
  21196 		26: uint8(36),
  21197 		27: uint8(37),
  21198 		28: uint8(39),
  21199 		29: uint8(40),
  21200 		30: uint8(42),
  21201 		31: uint8(43),
  21202 		32: uint8(45),
  21203 		33: uint8(46),
  21204 		34: uint8(48),
  21205 		35: uint8(49),
  21206 		36: uint8(51),
  21207 		37: uint8(52),
  21208 		38: uint8(54),
  21209 		39: uint8(55),
  21210 		40: uint8(57),
  21211 		41: uint8(58),
  21212 		42: uint8(60),
  21213 		43: uint8(61),
  21214 		44: uint8(63),
  21215 		45: uint8(63),
  21216 		46: uint8(63),
  21217 		47: uint8(63),
  21218 		48: uint8(63),
  21219 		49: uint8(63),
  21220 		50: uint8(63),
  21221 		51: uint8(63),
  21222 		52: uint8(63),
  21223 		53: uint8(63),
  21224 		54: uint8(63),
  21225 		55: uint8(63),
  21226 		56: uint8(63),
  21227 		57: uint8(63),
  21228 		58: uint8(63),
  21229 		59: uint8(63),
  21230 		60: uint8(63),
  21231 		61: uint8(63),
  21232 		62: uint8(63),
  21233 		63: uint8(63),
  21234 	},
  21235 	4: {
  21236 		1:  uint8(1),
  21237 		2:  uint8(2),
  21238 		3:  uint8(3),
  21239 		4:  uint8(5),
  21240 		5:  uint8(6),
  21241 		6:  uint8(7),
  21242 		7:  uint8(8),
  21243 		8:  uint8(9),
  21244 		9:  uint8(11),
  21245 		10: uint8(12),
  21246 		11: uint8(14),
  21247 		12: uint8(15),
  21248 		13: uint8(17),
  21249 		14: uint8(18),
  21250 		15: uint8(20),
  21251 		16: uint8(21),
  21252 		17: uint8(23),
  21253 		18: uint8(24),
  21254 		19: uint8(26),
  21255 		20: uint8(27),
  21256 		21: uint8(29),
  21257 		22: uint8(30),
  21258 		23: uint8(32),
  21259 		24: uint8(33),
  21260 		25: uint8(35),
  21261 		26: uint8(36),
  21262 		27: uint8(38),
  21263 		28: uint8(39),
  21264 		29: uint8(41),
  21265 		30: uint8(42),
  21266 		31: uint8(44),
  21267 		32: uint8(45),
  21268 		33: uint8(47),
  21269 		34: uint8(48),
  21270 		35: uint8(50),
  21271 		36: uint8(51),
  21272 		37: uint8(53),
  21273 		38: uint8(54),
  21274 		39: uint8(56),
  21275 		40: uint8(57),
  21276 		41: uint8(59),
  21277 		42: uint8(60),
  21278 		43: uint8(62),
  21279 		44: uint8(63),
  21280 		45: uint8(63),
  21281 		46: uint8(63),
  21282 		47: uint8(63),
  21283 		48: uint8(63),
  21284 		49: uint8(63),
  21285 		50: uint8(63),
  21286 		51: uint8(63),
  21287 		52: uint8(63),
  21288 		53: uint8(63),
  21289 		54: uint8(63),
  21290 		55: uint8(63),
  21291 		56: uint8(63),
  21292 		57: uint8(63),
  21293 		58: uint8(63),
  21294 		59: uint8(63),
  21295 		60: uint8(63),
  21296 		61: uint8(63),
  21297 		62: uint8(63),
  21298 		63: uint8(63),
  21299 	},
  21300 	5: {
  21301 		1:  uint8(1),
  21302 		2:  uint8(2),
  21303 		3:  uint8(4),
  21304 		4:  uint8(5),
  21305 		5:  uint8(7),
  21306 		6:  uint8(8),
  21307 		7:  uint8(9),
  21308 		8:  uint8(11),
  21309 		9:  uint8(12),
  21310 		10: uint8(13),
  21311 		11: uint8(15),
  21312 		12: uint8(16),
  21313 		13: uint8(17),
  21314 		14: uint8(19),
  21315 		15: uint8(20),
  21316 		16: uint8(22),
  21317 		17: uint8(23),
  21318 		18: uint8(25),
  21319 		19: uint8(26),
  21320 		20: uint8(28),
  21321 		21: uint8(29),
  21322 		22: uint8(31),
  21323 		23: uint8(32),
  21324 		24: uint8(34),
  21325 		25: uint8(35),
  21326 		26: uint8(37),
  21327 		27: uint8(38),
  21328 		28: uint8(40),
  21329 		29: uint8(41),
  21330 		30: uint8(43),
  21331 		31: uint8(44),
  21332 		32: uint8(46),
  21333 		33: uint8(47),
  21334 		34: uint8(49),
  21335 		35: uint8(50),
  21336 		36: uint8(52),
  21337 		37: uint8(53),
  21338 		38: uint8(55),
  21339 		39: uint8(56),
  21340 		40: uint8(58),
  21341 		41: uint8(59),
  21342 		42: uint8(61),
  21343 		43: uint8(62),
  21344 		44: uint8(63),
  21345 		45: uint8(63),
  21346 		46: uint8(63),
  21347 		47: uint8(63),
  21348 		48: uint8(63),
  21349 		49: uint8(63),
  21350 		50: uint8(63),
  21351 		51: uint8(63),
  21352 		52: uint8(63),
  21353 		53: uint8(63),
  21354 		54: uint8(63),
  21355 		55: uint8(63),
  21356 		56: uint8(63),
  21357 		57: uint8(63),
  21358 		58: uint8(63),
  21359 		59: uint8(63),
  21360 		60: uint8(63),
  21361 		61: uint8(63),
  21362 		62: uint8(63),
  21363 		63: uint8(63),
  21364 	},
  21365 	6: {
  21366 		1:  uint8(1),
  21367 		2:  uint8(2),
  21368 		3:  uint8(4),
  21369 		4:  uint8(5),
  21370 		5:  uint8(7),
  21371 		6:  uint8(8),
  21372 		7:  uint8(9),
  21373 		8:  uint8(11),
  21374 		9:  uint8(12),
  21375 		10: uint8(13),
  21376 		11: uint8(15),
  21377 		12: uint8(16),
  21378 		13: uint8(18),
  21379 		14: uint8(19),
  21380 		15: uint8(21),
  21381 		16: uint8(22),
  21382 		17: uint8(24),
  21383 		18: uint8(25),
  21384 		19: uint8(27),
  21385 		20: uint8(28),
  21386 		21: uint8(30),
  21387 		22: uint8(31),
  21388 		23: uint8(33),
  21389 		24: uint8(34),
  21390 		25: uint8(36),
  21391 		26: uint8(37),
  21392 		27: uint8(39),
  21393 		28: uint8(40),
  21394 		29: uint8(42),
  21395 		30: uint8(43),
  21396 		31: uint8(45),
  21397 		32: uint8(46),
  21398 		33: uint8(48),
  21399 		34: uint8(49),
  21400 		35: uint8(51),
  21401 		36: uint8(52),
  21402 		37: uint8(54),
  21403 		38: uint8(55),
  21404 		39: uint8(57),
  21405 		40: uint8(58),
  21406 		41: uint8(60),
  21407 		42: uint8(61),
  21408 		43: uint8(63),
  21409 		44: uint8(63),
  21410 		45: uint8(63),
  21411 		46: uint8(63),
  21412 		47: uint8(63),
  21413 		48: uint8(63),
  21414 		49: uint8(63),
  21415 		50: uint8(63),
  21416 		51: uint8(63),
  21417 		52: uint8(63),
  21418 		53: uint8(63),
  21419 		54: uint8(63),
  21420 		55: uint8(63),
  21421 		56: uint8(63),
  21422 		57: uint8(63),
  21423 		58: uint8(63),
  21424 		59: uint8(63),
  21425 		60: uint8(63),
  21426 		61: uint8(63),
  21427 		62: uint8(63),
  21428 		63: uint8(63),
  21429 	},
  21430 	7: {
  21431 		1:  uint8(1),
  21432 		2:  uint8(2),
  21433 		3:  uint8(4),
  21434 		4:  uint8(5),
  21435 		5:  uint8(7),
  21436 		6:  uint8(8),
  21437 		7:  uint8(9),
  21438 		8:  uint8(11),
  21439 		9:  uint8(12),
  21440 		10: uint8(14),
  21441 		11: uint8(15),
  21442 		12: uint8(17),
  21443 		13: uint8(18),
  21444 		14: uint8(20),
  21445 		15: uint8(21),
  21446 		16: uint8(23),
  21447 		17: uint8(24),
  21448 		18: uint8(26),
  21449 		19: uint8(27),
  21450 		20: uint8(29),
  21451 		21: uint8(30),
  21452 		22: uint8(32),
  21453 		23: uint8(33),
  21454 		24: uint8(35),
  21455 		25: uint8(36),
  21456 		26: uint8(38),
  21457 		27: uint8(39),
  21458 		28: uint8(41),
  21459 		29: uint8(42),
  21460 		30: uint8(44),
  21461 		31: uint8(45),
  21462 		32: uint8(47),
  21463 		33: uint8(48),
  21464 		34: uint8(50),
  21465 		35: uint8(51),
  21466 		36: uint8(53),
  21467 		37: uint8(54),
  21468 		38: uint8(56),
  21469 		39: uint8(57),
  21470 		40: uint8(59),
  21471 		41: uint8(60),
  21472 		42: uint8(62),
  21473 		43: uint8(63),
  21474 		44: uint8(63),
  21475 		45: uint8(63),
  21476 		46: uint8(63),
  21477 		47: uint8(63),
  21478 		48: uint8(63),
  21479 		49: uint8(63),
  21480 		50: uint8(63),
  21481 		51: uint8(63),
  21482 		52: uint8(63),
  21483 		53: uint8(63),
  21484 		54: uint8(63),
  21485 		55: uint8(63),
  21486 		56: uint8(63),
  21487 		57: uint8(63),
  21488 		58: uint8(63),
  21489 		59: uint8(63),
  21490 		60: uint8(63),
  21491 		61: uint8(63),
  21492 		62: uint8(63),
  21493 		63: uint8(63),
  21494 	},
  21495 }
  21496 
  21497 func VP8FilterStrengthFromDelta(tls *libc.TLS, sharpness int32, delta int32) (r int32) {
  21498 	var pos, v1 int32
  21499 	_, _ = pos, v1
  21500 	if delta < int32(MAX_DELTA_SIZE) {
  21501 		v1 = delta
  21502 	} else {
  21503 		v1 = libc.Int32FromInt32(MAX_DELTA_SIZE) - libc.Int32FromInt32(1)
  21504 	}
  21505 	pos = v1
  21506 	return int32(**(**uint8_t)(__ccgo_up(uintptr(unsafe.Pointer(&kLevelsFromDelta)) + uintptr(sharpness)*64 + uintptr(pos))))
  21507 }
  21508 
  21509 //------------------------------------------------------------------------------
  21510 // Paragraph 15.4: compute the inner-edge filtering strength
  21511 
  21512 func GetILevel(tls *libc.TLS, sharpness int32, level int32) (r int32) {
  21513 	if sharpness > 0 {
  21514 		if sharpness > int32(4) {
  21515 			level = level >> int32(2)
  21516 		} else {
  21517 			level = level >> int32(1)
  21518 		}
  21519 		if level > int32(9)-sharpness {
  21520 			level = int32(9) - sharpness
  21521 		}
  21522 	}
  21523 	if level < int32(1) {
  21524 		level = int32(1)
  21525 	}
  21526 	return level
  21527 }
  21528 
  21529 func DoFilter1(tls *libc.TLS, it uintptr, level int32) {
  21530 	var enc, u_dst, v_dst, y_dst uintptr
  21531 	var hev_thresh, ilevel, limit, v1, v2 int32
  21532 	_, _, _, _, _, _, _, _, _ = enc, hev_thresh, ilevel, limit, u_dst, v_dst, y_dst, v1, v2
  21533 	enc = (*VP8EncIterator)(unsafe.Pointer(it)).Fenc
  21534 	ilevel = GetILevel(tls, (*WebPConfig)(unsafe.Pointer((*VP8Encoder)(unsafe.Pointer(enc)).Fconfig)).Ffilter_sharpness, level)
  21535 	limit = int32(2)*level + ilevel
  21536 	y_dst = (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_out2 + uintptr(libc.Int32FromInt32(Y_OFF_ENC))
  21537 	u_dst = (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_out2 + uintptr(libc.Int32FromInt32(U_OFF_ENC))
  21538 	v_dst = (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_out2 + uintptr(libc.Int32FromInt32(16)+libc.Int32FromInt32(8))
  21539 	// copy current block to yuv_out2
  21540 	libc.Xmemcpy(tls, y_dst, (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_out, uint64(libc.Int32FromInt32(BPS)*libc.Int32FromInt32(16))*libc.Uint64FromInt64(1))
  21541 	if (*VP8Encoder)(unsafe.Pointer(enc)).Ffilter_hdr.Fsimple == int32(1) { // simple
  21542 		(*(*func(*libc.TLS, uintptr, int32, int32))(unsafe.Pointer(&struct{ uintptr }{VP8SimpleHFilter16i})))(tls, y_dst, int32(BPS), limit)
  21543 		(*(*func(*libc.TLS, uintptr, int32, int32))(unsafe.Pointer(&struct{ uintptr }{VP8SimpleVFilter16i})))(tls, y_dst, int32(BPS), limit)
  21544 	} else {
  21545 		if level >= int32(40) {
  21546 			v1 = int32(2)
  21547 		} else {
  21548 			if level >= int32(15) {
  21549 				v2 = int32(1)
  21550 			} else {
  21551 				v2 = 0
  21552 			}
  21553 			v1 = v2
  21554 		} // complex
  21555 		hev_thresh = v1
  21556 		(*(*func(*libc.TLS, uintptr, int32, int32, int32, int32))(unsafe.Pointer(&struct{ uintptr }{VP8HFilter16i})))(tls, y_dst, int32(BPS), limit, ilevel, hev_thresh)
  21557 		(*(*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)
  21558 		(*(*func(*libc.TLS, uintptr, int32, int32, int32, int32))(unsafe.Pointer(&struct{ uintptr }{VP8VFilter16i})))(tls, y_dst, int32(BPS), limit, ilevel, hev_thresh)
  21559 		(*(*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)
  21560 	}
  21561 }
  21562 
  21563 //------------------------------------------------------------------------------
  21564 // SSIM metric for one macroblock
  21565 
  21566 func GetMBSSIM(tls *libc.TLS, yuv1 uintptr, yuv2 uintptr) (r float64) {
  21567 	var sum float64
  21568 	var x, y int32
  21569 	_, _, _ = sum, x, y
  21570 	sum = float64(0)
  21571 	// compute SSIM in a 10 x 10 window
  21572 	y = int32(VP8_SSIM_KERNEL)
  21573 	for {
  21574 		if !(y < libc.Int32FromInt32(16)-libc.Int32FromInt32(VP8_SSIM_KERNEL)) {
  21575 			break
  21576 		}
  21577 		x = int32(VP8_SSIM_KERNEL)
  21578 		for {
  21579 			if !(x < libc.Int32FromInt32(16)-libc.Int32FromInt32(VP8_SSIM_KERNEL)) {
  21580 				break
  21581 			}
  21582 			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))
  21583 			goto _2
  21584 		_2:
  21585 			;
  21586 			x = x + 1
  21587 		}
  21588 		goto _1
  21589 	_1:
  21590 		;
  21591 		y = y + 1
  21592 	}
  21593 	x = int32(1)
  21594 	for {
  21595 		if !(x < int32(7)) {
  21596 			break
  21597 		}
  21598 		y = int32(1)
  21599 		for {
  21600 			if !(y < int32(7)) {
  21601 				break
  21602 			}
  21603 			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))
  21604 			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))
  21605 			goto _4
  21606 		_4:
  21607 			;
  21608 			y = y + 1
  21609 		}
  21610 		goto _3
  21611 	_3:
  21612 		;
  21613 		x = x + 1
  21614 	}
  21615 	return sum
  21616 }
  21617 
  21618 //------------------------------------------------------------------------------
  21619 // Exposed APIs: Encoder should call the following 3 functions to adjust
  21620 // loop filter strength
  21621 
  21622 func VP8InitFilter(tls *libc.TLS, it uintptr) {
  21623 	var i, s int32
  21624 	_, _ = i, s
  21625 	if (*VP8EncIterator)(unsafe.Pointer(it)).Flf_stats != libc.UintptrFromInt32(0) {
  21626 		s = 0
  21627 		for {
  21628 			if !(s < int32(NUM_MB_SEGMENTS)) {
  21629 				break
  21630 			}
  21631 			i = 0
  21632 			for {
  21633 				if !(i < int32(MAX_LF_LEVELS)) {
  21634 					break
  21635 				}
  21636 				**(**float64)(__ccgo_up((*VP8EncIterator)(unsafe.Pointer(it)).Flf_stats + uintptr(s)*512 + uintptr(i)*8)) = libc.Float64FromInt32(0)
  21637 				goto _2
  21638 			_2:
  21639 				;
  21640 				i = i + 1
  21641 			}
  21642 			goto _1
  21643 		_1:
  21644 			;
  21645 			s = s + 1
  21646 		}
  21647 		VP8SSIMDspInit(tls)
  21648 	}
  21649 }
  21650 
  21651 func VP8StoreFilterStats(tls *libc.TLS, it uintptr) {
  21652 	var d, delta_max, delta_min, level, level0, s, step_size, v1 int32
  21653 	var enc uintptr
  21654 	_, _, _, _, _, _, _, _, _ = d, delta_max, delta_min, enc, level, level0, s, step_size, v1
  21655 	enc = (*VP8EncIterator)(unsafe.Pointer(it)).Fenc
  21656 	s = int32(uint32(*(*uint8)(unsafe.Pointer((*VP8EncIterator)(unsafe.Pointer(it)).Fmb + 0)) & 0x60 >> 5))
  21657 	level0 = (**(**VP8SegmentInfo)(__ccgo_up(enc + 608 + uintptr(s)*744))).Ffstrength
  21658 	// explore +/-quant range of values around level0
  21659 	delta_min = -(**(**VP8SegmentInfo)(__ccgo_up(enc + 608 + uintptr(s)*744))).Fquant
  21660 	delta_max = (**(**VP8SegmentInfo)(__ccgo_up(enc + 608 + uintptr(s)*744))).Fquant
  21661 	if delta_max-delta_min >= int32(4) {
  21662 		v1 = int32(4)
  21663 	} else {
  21664 		v1 = int32(1)
  21665 	}
  21666 	step_size = v1
  21667 	if (*VP8EncIterator)(unsafe.Pointer(it)).Flf_stats == libc.UintptrFromInt32(0) {
  21668 		return
  21669 	}
  21670 	// NOTE: Currently we are applying filter only across the sublock edges
  21671 	// There are two reasons for that.
  21672 	// 1. Applying filter on macro block edges will change the pixels in
  21673 	// the left and top macro blocks. That will be hard to restore
  21674 	// 2. Macro Blocks on the bottom and right are not yet compressed. So we
  21675 	// cannot apply filter on the right and bottom macro block edges.
  21676 	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 {
  21677 		return
  21678 	}
  21679 	// Always try filter level  zero
  21680 	**(**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)
  21681 	d = delta_min
  21682 	for {
  21683 		if !(d <= delta_max) {
  21684 			break
  21685 		}
  21686 		level = level0 + d
  21687 		if level <= 0 || level >= int32(MAX_LF_LEVELS) {
  21688 			goto _2
  21689 		}
  21690 		DoFilter1(tls, it, level)
  21691 		**(**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)
  21692 		goto _2
  21693 	_2:
  21694 		;
  21695 		d = d + step_size
  21696 	}
  21697 }
  21698 
  21699 func VP8AdjustFilterStrength(tls *libc.TLS, it uintptr) {
  21700 	var best_level, delta, i, level, max_level, s, s1 int32
  21701 	var best_v, v float64
  21702 	var dqm, enc uintptr
  21703 	_, _, _, _, _, _, _, _, _, _, _ = best_level, best_v, delta, dqm, enc, i, level, max_level, s, s1, v
  21704 	enc = (*VP8EncIterator)(unsafe.Pointer(it)).Fenc
  21705 	if (*VP8EncIterator)(unsafe.Pointer(it)).Flf_stats != libc.UintptrFromInt32(0) {
  21706 		s = 0
  21707 		for {
  21708 			if !(s < int32(NUM_MB_SEGMENTS)) {
  21709 				break
  21710 			}
  21711 			best_level = 0
  21712 			// Improvement over filter level 0 should be at least 1e-5 (relatively)
  21713 			best_v = float64(float64(1.00001) * **(**float64)(__ccgo_up((*VP8EncIterator)(unsafe.Pointer(it)).Flf_stats + uintptr(s)*512)))
  21714 			i = int32(1)
  21715 			for {
  21716 				if !(i < int32(MAX_LF_LEVELS)) {
  21717 					break
  21718 				}
  21719 				v = **(**float64)(__ccgo_up((*VP8EncIterator)(unsafe.Pointer(it)).Flf_stats + uintptr(s)*512 + uintptr(i)*8))
  21720 				if v > best_v {
  21721 					best_v = v
  21722 					best_level = i
  21723 				}
  21724 				goto _2
  21725 			_2:
  21726 				;
  21727 				i = i + 1
  21728 			}
  21729 			(**(**VP8SegmentInfo)(__ccgo_up(enc + 608 + uintptr(s)*744))).Ffstrength = best_level
  21730 			goto _1
  21731 		_1:
  21732 			;
  21733 			s = s + 1
  21734 		}
  21735 		return
  21736 	}
  21737 	if (*WebPConfig)(unsafe.Pointer((*VP8Encoder)(unsafe.Pointer(enc)).Fconfig)).Ffilter_strength > 0 {
  21738 		max_level = 0
  21739 		s1 = 0
  21740 		for {
  21741 			if !(s1 < int32(NUM_MB_SEGMENTS)) {
  21742 				break
  21743 			}
  21744 			dqm = enc + 608 + uintptr(s1)*744
  21745 			// this '>> 3' accounts for some inverse WHT scaling
  21746 			delta = (*VP8SegmentInfo)(unsafe.Pointer(dqm)).Fmax_edge * int32(**(**uint16_t)(__ccgo_up(dqm + 224 + 1*2))) >> int32(3)
  21747 			level = VP8FilterStrengthFromDelta(tls, (*VP8Encoder)(unsafe.Pointer(enc)).Ffilter_hdr.Fsharpness, delta)
  21748 			if level > (*VP8SegmentInfo)(unsafe.Pointer(dqm)).Ffstrength {
  21749 				(*VP8SegmentInfo)(unsafe.Pointer(dqm)).Ffstrength = level
  21750 			}
  21751 			if max_level < (*VP8SegmentInfo)(unsafe.Pointer(dqm)).Ffstrength {
  21752 				max_level = (*VP8SegmentInfo)(unsafe.Pointer(dqm)).Ffstrength
  21753 			}
  21754 			goto _3
  21755 		_3:
  21756 			;
  21757 			s1 = s1 + 1
  21758 		}
  21759 		(*VP8Encoder)(unsafe.Pointer(enc)).Ffilter_hdr.Flevel = max_level
  21760 	}
  21761 }
  21762 
  21763 const DEBUG_SEARCH = 0
  21764 const DOMAIN = "_DOMAIN"
  21765 const DQ_LIMIT = 0.4
  21766 const FP_NAN = 0x0100
  21767 const FP_NDENORM = "_FPCLASS_ND"
  21768 const FP_NINF = "_FPCLASS_NINF"
  21769 const FP_NNORM = "_FPCLASS_NN"
  21770 const FP_NORMAL = 0x0400
  21771 const FP_NZERO = "_FPCLASS_NZ"
  21772 const FP_PDENORM = "_FPCLASS_PD"
  21773 const FP_PINF = "_FPCLASS_PINF"
  21774 const FP_PNORM = "_FPCLASS_PN"
  21775 const FP_PZERO = "_FPCLASS_PZ"
  21776 const FP_QNAN = "_FPCLASS_QNAN"
  21777 const FP_SNAN = "_FPCLASS_SNAN"
  21778 const FP_ZERO = 0x4000
  21779 const HUGE = "_HUGE"
  21780 const MATH_ERREXCEPT = 2
  21781 const MATH_ERRNO = 1
  21782 const MIN_COUNT = 96
  21783 const M_1_PI = 0.31830988618379067154
  21784 const M_2_PI = 0.63661977236758134308
  21785 const M_2_SQRTPI = 1.12837916709551257390
  21786 const M_E = 2.7182818284590452354
  21787 const M_LN10 = 2.30258509299404568402
  21788 const M_LN2 = 0.69314718055994530942
  21789 const M_LOG10E = 0.43429448190325182765
  21790 const M_LOG2E = 1.4426950408889634074
  21791 const M_PI = 3.14159265358979323846
  21792 const M_PI_2 = 1.57079632679489661923
  21793 const M_PI_4 = 0.78539816339744830962
  21794 const M_SQRT1_2 = 0.70710678118654752440
  21795 const M_SQRT2 = 1.41421356237309504880
  21796 const OVERFLOW = "_OVERFLOW"
  21797 const PLOSS = "_PLOSS"
  21798 const SEGMENT_VISU = 0
  21799 const SING = "_SING"
  21800 const SKIP_PROBA_THRESHOLD = 250
  21801 const TLOSS = "_TLOSS"
  21802 const UNDERFLOW = "_UNDERFLOW"
  21803 const _DOMAIN = 1
  21804 const _FPCLASS_ND = 0x0010
  21805 const _FPCLASS_NINF = 0x0004
  21806 const _FPCLASS_NN = 0x0008
  21807 const _FPCLASS_NZ = 0x0020
  21808 const _FPCLASS_PD = 0x0080
  21809 const _FPCLASS_PINF = 0x0200
  21810 const _FPCLASS_PN = 0x0100
  21811 const _FPCLASS_PZ = 0x0040
  21812 const _FPCLASS_QNAN = 0x0002
  21813 const _FPCLASS_SNAN = 0x0001
  21814 const _OVERFLOW = 3
  21815 const _PLOSS = 6
  21816 const _SING = 2
  21817 const _TLOSS = 5
  21818 const _UNDERFLOW = 4
  21819 const __MINGW_FPCLASS_DEFINED = 1
  21820 const __mingw_choose_expr = "__builtin_choose_expr"
  21821 const __setusermatherr = "__mingw_setusermatherr"
  21822 const _copysignl = "copysignl"
  21823 const _hypotl = "hypotl"
  21824 const matherr = "_matherr"
  21825 
  21826 type _exception = struct {
  21827 	Ftype1  int32
  21828 	Fname   uintptr
  21829 	Farg1   float64
  21830 	Farg2   float64
  21831 	Fretval float64
  21832 }
  21833 
  21834 type __mingw_dbl_type_t = struct {
  21835 	Fval [0]uint64
  21836 	Flh  [0]struct {
  21837 		Flow  uint32
  21838 		Fhigh uint32
  21839 	}
  21840 	Fx float64
  21841 }
  21842 
  21843 type __mingw_flt_type_t = struct {
  21844 	Fval [0]uint32
  21845 	Fx   float32
  21846 }
  21847 
  21848 type __mingw_ldbl_type_t = struct {
  21849 	Flh [0]struct {
  21850 		Flow      uint32
  21851 		Fhigh     uint32
  21852 		F__ccgo8  uint32
  21853 		F__ccgo12 uint32
  21854 	}
  21855 	Fx           float64
  21856 	F__ccgo_pad2 [8]byte
  21857 }
  21858 
  21859 type _complex = struct {
  21860 	Fx float64
  21861 	Fy float64
  21862 }
  21863 
  21864 type float_t = float32
  21865 
  21866 type double_t = float64
  21867 
  21868 // Alpha related constants.
  21869 
  21870 // Mux related constants.
  21871 
  21872 // Maximum chunk payload is such that adding the header and padding won't
  21873 // overflow a uint32_t.
  21874 
  21875 //------------------------------------------------------------------------------
  21876 // multi-pass convergence
  21877 
  21878 // we allow 2k of extra head-room in PARTITION0 limit.
  21879 
  21880 func Clamp(tls *libc.TLS, v float32, min float32, max float32) (r float32) {
  21881 	var v1, v2 float32
  21882 	_, _ = v1, v2
  21883 	if v < min {
  21884 		v1 = min
  21885 	} else {
  21886 		if v > max {
  21887 			v2 = max
  21888 		} else {
  21889 			v2 = v
  21890 		}
  21891 		v1 = v2
  21892 	}
  21893 	return v1
  21894 }
  21895 
  21896 type PassStats = struct {
  21897 	Fis_first       int32
  21898 	Fdq             float32
  21899 	Fq              float32
  21900 	Flast_q         float32
  21901 	Fqmin           float32
  21902 	Fqmax           float32
  21903 	Fvalue          float64
  21904 	Flast_value     float64
  21905 	Ftarget         float64
  21906 	Fdo_size_search int32
  21907 }
  21908 
  21909 func InitPassStats(tls *libc.TLS, enc uintptr, s uintptr) (r int32) {
  21910 	var do_size_search int32
  21911 	var target_PSNR, v1 float32
  21912 	var target_size uint64_t
  21913 	var v2, v3 float64
  21914 	_, _, _, _, _, _ = do_size_search, target_PSNR, target_size, v1, v2, v3
  21915 	target_size = uint64((*WebPConfig)(unsafe.Pointer((*VP8Encoder)(unsafe.Pointer(enc)).Fconfig)).Ftarget_size)
  21916 	do_size_search = libc.BoolInt32(target_size != libc.Uint64FromInt32(0))
  21917 	target_PSNR = (*WebPConfig)(unsafe.Pointer((*VP8Encoder)(unsafe.Pointer(enc)).Fconfig)).Ftarget_PSNR
  21918 	(*PassStats)(unsafe.Pointer(s)).Fis_first = int32(1)
  21919 	(*PassStats)(unsafe.Pointer(s)).Fdq = libc.Float32FromFloat32(10)
  21920 	(*PassStats)(unsafe.Pointer(s)).Fqmin = float32(libc.Float32FromFloat32(1) * float32((*WebPConfig)(unsafe.Pointer((*VP8Encoder)(unsafe.Pointer(enc)).Fconfig)).Fqmin))
  21921 	(*PassStats)(unsafe.Pointer(s)).Fqmax = float32(libc.Float32FromFloat32(1) * float32((*WebPConfig)(unsafe.Pointer((*VP8Encoder)(unsafe.Pointer(enc)).Fconfig)).Fqmax))
  21922 	v1 = Clamp(tls, (*WebPConfig)(unsafe.Pointer((*VP8Encoder)(unsafe.Pointer(enc)).Fconfig)).Fquality, (*PassStats)(unsafe.Pointer(s)).Fqmin, (*PassStats)(unsafe.Pointer(s)).Fqmax)
  21923 	(*PassStats)(unsafe.Pointer(s)).Flast_q = v1
  21924 	(*PassStats)(unsafe.Pointer(s)).Fq = v1
  21925 	if do_size_search != 0 {
  21926 		v2 = float64(target_size)
  21927 	} else {
  21928 		if float64(target_PSNR) > float64(0) {
  21929 			v3 = float64(target_PSNR)
  21930 		} else {
  21931 			v3 = float64(40)
  21932 		}
  21933 		v2 = v3
  21934 	}
  21935 	(*PassStats)(unsafe.Pointer(s)).Ftarget = v2 // default, just in case
  21936 	v2 = libc.Float64FromFloat64(0)
  21937 	(*PassStats)(unsafe.Pointer(s)).Flast_value = v2
  21938 	(*PassStats)(unsafe.Pointer(s)).Fvalue = v2
  21939 	(*PassStats)(unsafe.Pointer(s)).Fdo_size_search = do_size_search
  21940 	return do_size_search
  21941 }
  21942 
  21943 func ComputeNextQ(tls *libc.TLS, s uintptr) (r float32) {
  21944 	var dq, v1 float32
  21945 	var slope float64
  21946 	_, _, _ = dq, slope, v1
  21947 	if (*PassStats)(unsafe.Pointer(s)).Fis_first != 0 {
  21948 		if (*PassStats)(unsafe.Pointer(s)).Fvalue > (*PassStats)(unsafe.Pointer(s)).Ftarget {
  21949 			v1 = -(*PassStats)(unsafe.Pointer(s)).Fdq
  21950 		} else {
  21951 			v1 = (*PassStats)(unsafe.Pointer(s)).Fdq
  21952 		}
  21953 		dq = v1
  21954 		(*PassStats)(unsafe.Pointer(s)).Fis_first = 0
  21955 	} else {
  21956 		if (*PassStats)(unsafe.Pointer(s)).Fvalue != (*PassStats)(unsafe.Pointer(s)).Flast_value {
  21957 			slope = ((*PassStats)(unsafe.Pointer(s)).Ftarget - (*PassStats)(unsafe.Pointer(s)).Fvalue) / ((*PassStats)(unsafe.Pointer(s)).Flast_value - (*PassStats)(unsafe.Pointer(s)).Fvalue)
  21958 			dq = float32(float64(slope * float64((*PassStats)(unsafe.Pointer(s)).Flast_q-(*PassStats)(unsafe.Pointer(s)).Fq)))
  21959 		} else {
  21960 			dq = float32(0) // we're done?!
  21961 		}
  21962 	}
  21963 	// Limit variable to avoid large swings.
  21964 	(*PassStats)(unsafe.Pointer(s)).Fdq = Clamp(tls, dq, -libc.Float32FromFloat32(30), libc.Float32FromFloat32(30))
  21965 	(*PassStats)(unsafe.Pointer(s)).Flast_q = (*PassStats)(unsafe.Pointer(s)).Fq
  21966 	(*PassStats)(unsafe.Pointer(s)).Flast_value = (*PassStats)(unsafe.Pointer(s)).Fvalue
  21967 	(*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)
  21968 	return (*PassStats)(unsafe.Pointer(s)).Fq
  21969 }
  21970 
  21971 //------------------------------------------------------------------------------
  21972 // Reset the statistics about: number of skips, token proba, level cost,...
  21973 
  21974 func ResetStats(tls *libc.TLS, enc uintptr) {
  21975 	var proba uintptr
  21976 	_ = proba
  21977 	proba = enc + 3616
  21978 	VP8CalculateLevelCosts(tls, proba)
  21979 	(*VP8EncProba)(unsafe.Pointer(proba)).Fnb_skip = 0
  21980 }
  21981 
  21982 //------------------------------------------------------------------------------
  21983 // Skip decision probability
  21984 
  21985 func CalcSkipProba(tls *libc.TLS, nb uint64_t, total uint64_t) (r int32) {
  21986 	var v1 uint64
  21987 	_ = v1
  21988 	if total != 0 {
  21989 		v1 = (total - nb) * uint64(255) / total
  21990 	} else {
  21991 		v1 = uint64(255)
  21992 	}
  21993 	return int32(v1)
  21994 }
  21995 
  21996 // C documentation
  21997 //
  21998 //	// Returns the bit-cost for coding the skip probability.
  21999 func FinalizeSkipProba(tls *libc.TLS, enc uintptr) (r int32) {
  22000 	var nb_events, nb_mbs, size, v2, v4, v6, v8 int32
  22001 	var proba1 uintptr
  22002 	var v1, v5 uint8_t
  22003 	_, _, _, _, _, _, _, _, _, _ = nb_events, nb_mbs, proba1, size, v1, v2, v4, v5, v6, v8
  22004 	proba1 = enc + 3616
  22005 	nb_mbs = (*VP8Encoder)(unsafe.Pointer(enc)).Fmb_w * (*VP8Encoder)(unsafe.Pointer(enc)).Fmb_h
  22006 	nb_events = (*VP8EncProba)(unsafe.Pointer(proba1)).Fnb_skip
  22007 	(*VP8EncProba)(unsafe.Pointer(proba1)).Fskip_proba = uint8(CalcSkipProba(tls, uint64(nb_events), uint64(nb_mbs)))
  22008 	(*VP8EncProba)(unsafe.Pointer(proba1)).Fuse_skip_proba = libc.BoolInt32(int32((*VP8EncProba)(unsafe.Pointer(proba1)).Fskip_proba) < int32(SKIP_PROBA_THRESHOLD))
  22009 	size = int32(256) // 'use_skip_proba' bit
  22010 	if (*VP8EncProba)(unsafe.Pointer(proba1)).Fuse_skip_proba != 0 {
  22011 		v1 = (*VP8EncProba)(unsafe.Pointer(proba1)).Fskip_proba
  22012 		if !(int32(1) != 0) {
  22013 			v4 = int32(VP8EntropyCost[v1])
  22014 		} else {
  22015 			v4 = int32(VP8EntropyCost[int32(255)-int32(v1)])
  22016 		}
  22017 		v2 = v4
  22018 		goto _3
  22019 	_3:
  22020 		v5 = (*VP8EncProba)(unsafe.Pointer(proba1)).Fskip_proba
  22021 		if !(0 != 0) {
  22022 			v8 = int32(VP8EntropyCost[v5])
  22023 		} else {
  22024 			v8 = int32(VP8EntropyCost[int32(255)-int32(v5)])
  22025 		}
  22026 		v6 = v8
  22027 		goto _7
  22028 	_7:
  22029 		size = size + (nb_events*v2 + (nb_mbs-nb_events)*v6)
  22030 		size = size + libc.Int32FromInt32(8)*libc.Int32FromInt32(256) // cost of signaling the 'skip_proba' itself.
  22031 	}
  22032 	return size
  22033 }
  22034 
  22035 // C documentation
  22036 //
  22037 //	// Collect statistics and deduce probabilities for next coding pass.
  22038 //	// Return the total bit-cost for coding the probability updates.
  22039 func CalcTokenProba(tls *libc.TLS, nb int32, total int32) (r int32) {
  22040 	var v1 int32
  22041 	_ = v1
  22042 	if nb != 0 {
  22043 		v1 = int32(255) - nb*int32(255)/total
  22044 	} else {
  22045 		v1 = int32(255)
  22046 	}
  22047 	return v1
  22048 }
  22049 
  22050 // C documentation
  22051 //
  22052 //	// Cost of coding 'nb' 1's and 'total-nb' 0's using 'proba' probability.
  22053 func BranchCost(tls *libc.TLS, nb int32, total int32, proba1 int32) (r int32) {
  22054 	var v1, v5 uint8_t
  22055 	var v2, v4, v6, v8 int32
  22056 	_, _, _, _, _, _ = v1, v2, v4, v5, v6, v8
  22057 	v1 = uint8(proba1)
  22058 	if !(int32(1) != 0) {
  22059 		v4 = int32(VP8EntropyCost[v1])
  22060 	} else {
  22061 		v4 = int32(VP8EntropyCost[int32(255)-int32(v1)])
  22062 	}
  22063 	v2 = v4
  22064 	goto _3
  22065 _3:
  22066 	v5 = uint8(proba1)
  22067 	if !(0 != 0) {
  22068 		v8 = int32(VP8EntropyCost[v5])
  22069 	} else {
  22070 		v8 = int32(VP8EntropyCost[int32(255)-int32(v5)])
  22071 	}
  22072 	v6 = v8
  22073 	goto _7
  22074 _7:
  22075 	return nb*v2 + (total-nb)*v6
  22076 }
  22077 
  22078 func ResetTokenStats(tls *libc.TLS, enc uintptr) {
  22079 	var proba uintptr
  22080 	_ = proba
  22081 	proba = enc + 3616
  22082 	libc.Xmemset(tls, proba+1060, 0, uint64(4224))
  22083 }
  22084 
  22085 func FinalizeTokenProbas(tls *libc.TLS, proba1 uintptr) (r int32) {
  22086 	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
  22087 	var stats proba_t
  22088 	var v13, v5, v9 uint8_t
  22089 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  22090 	has_changed = 0
  22091 	size = 0
  22092 	t = 0
  22093 	for {
  22094 		if !(t < int32(NUM_TYPES)) {
  22095 			break
  22096 		}
  22097 		b = 0
  22098 		for {
  22099 			if !(b < int32(NUM_BANDS)) {
  22100 				break
  22101 			}
  22102 			c = 0
  22103 			for {
  22104 				if !(c < int32(NUM_CTX)) {
  22105 					break
  22106 				}
  22107 				p = 0
  22108 				for {
  22109 					if !(p < int32(NUM_PROBAS)) {
  22110 						break
  22111 					}
  22112 					stats = **(**proba_t)(__ccgo_up(proba1 + 1060 + uintptr(t)*1056 + uintptr(b)*132 + uintptr(c)*44 + uintptr(p)*4))
  22113 					nb = int32(stats >> libc.Int32FromInt32(0) & uint32(0xffff))
  22114 					total = int32(stats >> libc.Int32FromInt32(16) & uint32(0xffff))
  22115 					update_proba = int32(**(**uint8_t)(__ccgo_up(uintptr(unsafe.Pointer(&VP8CoeffsUpdateProba)) + uintptr(t)*264 + uintptr(b)*33 + uintptr(c)*11 + uintptr(p))))
  22116 					old_p = int32(**(**uint8_t)(__ccgo_up(uintptr(unsafe.Pointer(&VP8CoeffsProba0)) + uintptr(t)*264 + uintptr(b)*33 + uintptr(c)*11 + uintptr(p))))
  22117 					new_p = CalcTokenProba(tls, nb, total)
  22118 					v5 = uint8(update_proba)
  22119 					if !(0 != 0) {
  22120 						v8 = int32(VP8EntropyCost[v5])
  22121 					} else {
  22122 						v8 = int32(VP8EntropyCost[int32(255)-int32(v5)])
  22123 					}
  22124 					v6 = v8
  22125 					goto _7
  22126 				_7:
  22127 					old_cost = BranchCost(tls, nb, total, old_p) + v6
  22128 					v9 = uint8(update_proba)
  22129 					if !(int32(1) != 0) {
  22130 						v12 = int32(VP8EntropyCost[v9])
  22131 					} else {
  22132 						v12 = int32(VP8EntropyCost[int32(255)-int32(v9)])
  22133 					}
  22134 					v10 = v12
  22135 					goto _11
  22136 				_11:
  22137 					new_cost = BranchCost(tls, nb, total, new_p) + v10 + libc.Int32FromInt32(8)*libc.Int32FromInt32(256)
  22138 					use_new_p = libc.BoolInt32(old_cost > new_cost)
  22139 					v13 = uint8(update_proba)
  22140 					if !(use_new_p != 0) {
  22141 						v16 = int32(VP8EntropyCost[v13])
  22142 					} else {
  22143 						v16 = int32(VP8EntropyCost[int32(255)-int32(v13)])
  22144 					}
  22145 					v14 = v16
  22146 					goto _15
  22147 				_15:
  22148 					size = size + v14
  22149 					if use_new_p != 0 { // only use proba that seem meaningful enough.
  22150 						**(**uint8_t)(__ccgo_up(proba1 + 4 + uintptr(t)*264 + uintptr(b)*33 + uintptr(c)*11 + uintptr(p))) = uint8(new_p)
  22151 						has_changed = has_changed | libc.BoolInt32(new_p != old_p)
  22152 						size = size + libc.Int32FromInt32(8)*libc.Int32FromInt32(256)
  22153 					} else {
  22154 						**(**uint8_t)(__ccgo_up(proba1 + 4 + uintptr(t)*264 + uintptr(b)*33 + uintptr(c)*11 + uintptr(p))) = uint8(old_p)
  22155 					}
  22156 					goto _4
  22157 				_4:
  22158 					;
  22159 					p = p + 1
  22160 				}
  22161 				goto _3
  22162 			_3:
  22163 				;
  22164 				c = c + 1
  22165 			}
  22166 			goto _2
  22167 		_2:
  22168 			;
  22169 			b = b + 1
  22170 		}
  22171 		goto _1
  22172 	_1:
  22173 		;
  22174 		t = t + 1
  22175 	}
  22176 	(*VP8EncProba)(unsafe.Pointer(proba1)).Fdirty = has_changed
  22177 	return size
  22178 }
  22179 
  22180 //------------------------------------------------------------------------------
  22181 // Finalize Segment probability based on the coding tree
  22182 
  22183 func GetProba(tls *libc.TLS, a int32, b int32) (r int32) {
  22184 	var total, v1 int32
  22185 	_, _ = total, v1
  22186 	total = a + b
  22187 	if total == 0 {
  22188 		v1 = int32(255)
  22189 	} else {
  22190 		v1 = (int32(255)*a + total/int32(2)) / total
  22191 	}
  22192 	return v1 // rounded proba
  22193 }
  22194 
  22195 func ResetSegments(tls *libc.TLS, enc uintptr) {
  22196 	var n int32
  22197 	_ = n
  22198 	n = 0
  22199 	for {
  22200 		if !(n < (*VP8Encoder)(unsafe.Pointer(enc)).Fmb_w*(*VP8Encoder)(unsafe.Pointer(enc)).Fmb_h) {
  22201 			break
  22202 		}
  22203 		libc.SetBitFieldPtr8Uint32((*VP8Encoder)(unsafe.Pointer(enc)).Fmb_info+uintptr(n)*4+0, libc.Uint32FromInt32(0), 5, 0x60)
  22204 		goto _1
  22205 	_1:
  22206 		;
  22207 		n = n + 1
  22208 	}
  22209 }
  22210 
  22211 func SetSegmentProbas(tls *libc.TLS, enc uintptr) {
  22212 	var mb, probas uintptr
  22213 	var n, v10, v12, v14, v16, v18, v20, v22, v24, v26, v28, v30, v32, v34, v4, v6, v8 int32
  22214 	var p [4]int32
  22215 	var v11, v15, v19, v23, v27, v3, v31, v7 uint8_t
  22216 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  22217 	p = [4]int32{}
  22218 	n = 0
  22219 	for {
  22220 		if !(n < (*VP8Encoder)(unsafe.Pointer(enc)).Fmb_w*(*VP8Encoder)(unsafe.Pointer(enc)).Fmb_h) {
  22221 			break
  22222 		}
  22223 		mb = (*VP8Encoder)(unsafe.Pointer(enc)).Fmb_info + uintptr(n)*4
  22224 		p[int32(uint32(*(*uint8)(unsafe.Pointer(mb + 0))&0x60>>5))] = p[int32(uint32(*(*uint8)(unsafe.Pointer(mb + 0))&0x60>>5))] + 1
  22225 		goto _1
  22226 	_1:
  22227 		;
  22228 		n = n + 1
  22229 	}
  22230 	if (*WebPPicture)(unsafe.Pointer((*VP8Encoder)(unsafe.Pointer(enc)).Fpic)).Fstats != libc.UintptrFromInt32(0) {
  22231 		n = 0
  22232 		for {
  22233 			if !(n < int32(NUM_MB_SEGMENTS)) {
  22234 				break
  22235 			}
  22236 			**(**int32)(__ccgo_up((*WebPPicture)(unsafe.Pointer((*VP8Encoder)(unsafe.Pointer(enc)).Fpic)).Fstats + 92 + uintptr(n)*4)) = p[n]
  22237 			goto _2
  22238 		_2:
  22239 			;
  22240 			n = n + 1
  22241 		}
  22242 	}
  22243 	if (*VP8Encoder)(unsafe.Pointer(enc)).Fsegment_hdr.Fnum_segments > int32(1) {
  22244 		probas = enc + 3616
  22245 		**(**uint8_t)(__ccgo_up(probas)) = uint8(GetProba(tls, p[0]+p[int32(1)], p[int32(2)]+p[int32(3)]))
  22246 		**(**uint8_t)(__ccgo_up(probas + 1)) = uint8(GetProba(tls, p[0], p[int32(1)]))
  22247 		**(**uint8_t)(__ccgo_up(probas + 2)) = uint8(GetProba(tls, p[int32(2)], p[int32(3)]))
  22248 		(*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))
  22249 		if !((*VP8Encoder)(unsafe.Pointer(enc)).Fsegment_hdr.Fupdate_map != 0) {
  22250 			ResetSegments(tls, enc)
  22251 		}
  22252 		v3 = **(**uint8_t)(__ccgo_up(probas))
  22253 		if !(0 != 0) {
  22254 			v6 = int32(VP8EntropyCost[v3])
  22255 		} else {
  22256 			v6 = int32(VP8EntropyCost[int32(255)-int32(v3)])
  22257 		}
  22258 		v4 = v6
  22259 		goto _5
  22260 	_5:
  22261 		v7 = **(**uint8_t)(__ccgo_up(probas + 1))
  22262 		if !(0 != 0) {
  22263 			v10 = int32(VP8EntropyCost[v7])
  22264 		} else {
  22265 			v10 = int32(VP8EntropyCost[int32(255)-int32(v7)])
  22266 		}
  22267 		v8 = v10
  22268 		goto _9
  22269 	_9:
  22270 		v11 = **(**uint8_t)(__ccgo_up(probas))
  22271 		if !(0 != 0) {
  22272 			v14 = int32(VP8EntropyCost[v11])
  22273 		} else {
  22274 			v14 = int32(VP8EntropyCost[int32(255)-int32(v11)])
  22275 		}
  22276 		v12 = v14
  22277 		goto _13
  22278 	_13:
  22279 		v15 = **(**uint8_t)(__ccgo_up(probas + 1))
  22280 		if !(int32(1) != 0) {
  22281 			v18 = int32(VP8EntropyCost[v15])
  22282 		} else {
  22283 			v18 = int32(VP8EntropyCost[int32(255)-int32(v15)])
  22284 		}
  22285 		v16 = v18
  22286 		goto _17
  22287 	_17:
  22288 		v19 = **(**uint8_t)(__ccgo_up(probas))
  22289 		if !(int32(1) != 0) {
  22290 			v22 = int32(VP8EntropyCost[v19])
  22291 		} else {
  22292 			v22 = int32(VP8EntropyCost[int32(255)-int32(v19)])
  22293 		}
  22294 		v20 = v22
  22295 		goto _21
  22296 	_21:
  22297 		v23 = **(**uint8_t)(__ccgo_up(probas + 2))
  22298 		if !(0 != 0) {
  22299 			v26 = int32(VP8EntropyCost[v23])
  22300 		} else {
  22301 			v26 = int32(VP8EntropyCost[int32(255)-int32(v23)])
  22302 		}
  22303 		v24 = v26
  22304 		goto _25
  22305 	_25:
  22306 		v27 = **(**uint8_t)(__ccgo_up(probas))
  22307 		if !(int32(1) != 0) {
  22308 			v30 = int32(VP8EntropyCost[v27])
  22309 		} else {
  22310 			v30 = int32(VP8EntropyCost[int32(255)-int32(v27)])
  22311 		}
  22312 		v28 = v30
  22313 		goto _29
  22314 	_29:
  22315 		v31 = **(**uint8_t)(__ccgo_up(probas + 2))
  22316 		if !(int32(1) != 0) {
  22317 			v34 = int32(VP8EntropyCost[v31])
  22318 		} else {
  22319 			v34 = int32(VP8EntropyCost[int32(255)-int32(v31)])
  22320 		}
  22321 		v32 = v34
  22322 		goto _33
  22323 	_33:
  22324 		(*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)
  22325 	} else {
  22326 		(*VP8Encoder)(unsafe.Pointer(enc)).Fsegment_hdr.Fupdate_map = 0
  22327 		(*VP8Encoder)(unsafe.Pointer(enc)).Fsegment_hdr.Fsize = 0
  22328 	}
  22329 }
  22330 
  22331 //------------------------------------------------------------------------------
  22332 // Coefficient coding
  22333 
  22334 func PutCoeffs(tls *libc.TLS, bw uintptr, ctx int32, res uintptr) (r int32) {
  22335 	var c, mask, n, sign, v, v1, v2 int32
  22336 	var p, tab, v3 uintptr
  22337 	_, _, _, _, _, _, _, _, _, _ = c, mask, n, p, sign, tab, v, v1, v2, v3
  22338 	n = (*VP8Residual)(unsafe.Pointer(res)).Ffirst
  22339 	// should be prob[VP8EncBands[n]], but it's equivalent for n=0 or 1
  22340 	p = (*VP8Residual)(unsafe.Pointer(res)).Fprob + uintptr(n)*33 + uintptr(ctx)*11
  22341 	if !(VP8PutBit(tls, bw, libc.BoolInt32((*VP8Residual)(unsafe.Pointer(res)).Flast >= 0), int32(**(**uint8_t)(__ccgo_up(p)))) != 0) {
  22342 		return 0
  22343 	}
  22344 	for n < int32(16) {
  22345 		v1 = n
  22346 		n = n + 1
  22347 		c = int32(**(**int16_t)(__ccgo_up((*VP8Residual)(unsafe.Pointer(res)).Fcoeffs + uintptr(v1)*2)))
  22348 		sign = libc.BoolInt32(c < 0)
  22349 		if sign != 0 {
  22350 			v2 = -c
  22351 		} else {
  22352 			v2 = c
  22353 		}
  22354 		v = v2
  22355 		if !(VP8PutBit(tls, bw, libc.BoolInt32(v != 0), int32(**(**uint8_t)(__ccgo_up(p + 1)))) != 0) {
  22356 			p = (*VP8Residual)(unsafe.Pointer(res)).Fprob + uintptr(VP8EncBands[n])*33
  22357 			continue
  22358 		}
  22359 		if !(VP8PutBit(tls, bw, libc.BoolInt32(v > int32(1)), int32(**(**uint8_t)(__ccgo_up(p + 2)))) != 0) {
  22360 			p = (*VP8Residual)(unsafe.Pointer(res)).Fprob + uintptr(VP8EncBands[n])*33 + 1*11
  22361 		} else {
  22362 			if !(VP8PutBit(tls, bw, libc.BoolInt32(v > int32(4)), int32(**(**uint8_t)(__ccgo_up(p + 3)))) != 0) {
  22363 				if VP8PutBit(tls, bw, libc.BoolInt32(v != int32(2)), int32(**(**uint8_t)(__ccgo_up(p + 4)))) != 0 {
  22364 					VP8PutBit(tls, bw, libc.BoolInt32(v == int32(4)), int32(**(**uint8_t)(__ccgo_up(p + 5))))
  22365 				}
  22366 			} else {
  22367 				if !(VP8PutBit(tls, bw, libc.BoolInt32(v > int32(10)), int32(**(**uint8_t)(__ccgo_up(p + 6)))) != 0) {
  22368 					if !(VP8PutBit(tls, bw, libc.BoolInt32(v > int32(6)), int32(**(**uint8_t)(__ccgo_up(p + 7)))) != 0) {
  22369 						VP8PutBit(tls, bw, libc.BoolInt32(v == int32(6)), int32(159))
  22370 					} else {
  22371 						VP8PutBit(tls, bw, libc.BoolInt32(v >= int32(9)), int32(165))
  22372 						VP8PutBit(tls, bw, libc.BoolInt32(!(v&libc.Int32FromInt32(1) != 0)), int32(145))
  22373 					}
  22374 				} else {
  22375 					if v < libc.Int32FromInt32(3)+libc.Int32FromInt32(8)<<libc.Int32FromInt32(1) { // VP8Cat3  (3b)
  22376 						VP8PutBit(tls, bw, 0, int32(**(**uint8_t)(__ccgo_up(p + 8))))
  22377 						VP8PutBit(tls, bw, 0, int32(**(**uint8_t)(__ccgo_up(p + 9))))
  22378 						v = v - (libc.Int32FromInt32(3) + libc.Int32FromInt32(8)<<libc.Int32FromInt32(0))
  22379 						mask = libc.Int32FromInt32(1) << libc.Int32FromInt32(2)
  22380 						tab = uintptr(unsafe.Pointer(&VP8Cat3))
  22381 					} else {
  22382 						if v < libc.Int32FromInt32(3)+libc.Int32FromInt32(8)<<libc.Int32FromInt32(2) { // VP8Cat4  (4b)
  22383 							VP8PutBit(tls, bw, 0, int32(**(**uint8_t)(__ccgo_up(p + 8))))
  22384 							VP8PutBit(tls, bw, int32(1), int32(**(**uint8_t)(__ccgo_up(p + 9))))
  22385 							v = v - (libc.Int32FromInt32(3) + libc.Int32FromInt32(8)<<libc.Int32FromInt32(1))
  22386 							mask = libc.Int32FromInt32(1) << libc.Int32FromInt32(3)
  22387 							tab = uintptr(unsafe.Pointer(&VP8Cat4))
  22388 						} else {
  22389 							if v < libc.Int32FromInt32(3)+libc.Int32FromInt32(8)<<libc.Int32FromInt32(3) { // VP8Cat5  (5b)
  22390 								VP8PutBit(tls, bw, int32(1), int32(**(**uint8_t)(__ccgo_up(p + 8))))
  22391 								VP8PutBit(tls, bw, 0, int32(**(**uint8_t)(__ccgo_up(p + 10))))
  22392 								v = v - (libc.Int32FromInt32(3) + libc.Int32FromInt32(8)<<libc.Int32FromInt32(2))
  22393 								mask = libc.Int32FromInt32(1) << libc.Int32FromInt32(4)
  22394 								tab = uintptr(unsafe.Pointer(&VP8Cat5))
  22395 							} else { // VP8Cat6 (11b)
  22396 								VP8PutBit(tls, bw, int32(1), int32(**(**uint8_t)(__ccgo_up(p + 8))))
  22397 								VP8PutBit(tls, bw, int32(1), int32(**(**uint8_t)(__ccgo_up(p + 10))))
  22398 								v = v - (libc.Int32FromInt32(3) + libc.Int32FromInt32(8)<<libc.Int32FromInt32(3))
  22399 								mask = libc.Int32FromInt32(1) << libc.Int32FromInt32(10)
  22400 								tab = uintptr(unsafe.Pointer(&VP8Cat6))
  22401 							}
  22402 						}
  22403 					}
  22404 					for mask != 0 {
  22405 						v3 = tab
  22406 						tab = tab + 1
  22407 						VP8PutBit(tls, bw, libc.BoolInt32(!!(v&mask != 0)), int32(**(**uint8_t)(__ccgo_up(v3))))
  22408 						mask = mask >> int32(1)
  22409 					}
  22410 				}
  22411 			}
  22412 			p = (*VP8Residual)(unsafe.Pointer(res)).Fprob + uintptr(VP8EncBands[n])*33 + 2*11
  22413 		}
  22414 		VP8PutBitUniform(tls, bw, sign)
  22415 		if n == int32(16) || !(VP8PutBit(tls, bw, libc.BoolInt32(n <= (*VP8Residual)(unsafe.Pointer(res)).Flast), int32(**(**uint8_t)(__ccgo_up(p)))) != 0) {
  22416 			return int32(1) // EOB
  22417 		}
  22418 	}
  22419 	return int32(1)
  22420 }
  22421 
  22422 func CodeResiduals(tls *libc.TLS, bw1 uintptr, it uintptr, rd uintptr) {
  22423 	bp := tls.Alloc(48)
  22424 	defer tls.Free(48)
  22425 	var ch, ctx, ctx1, i16, segment, x, y, v4 int32
  22426 	var enc, v1 uintptr
  22427 	var nb_bits, pos1, pos2, pos3, v2 uint64_t
  22428 	var _ /* res at bp+0 */ VP8Residual
  22429 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = ch, ctx, ctx1, enc, i16, nb_bits, pos1, pos2, pos3, segment, x, y, v1, v2, v4
  22430 	i16 = libc.BoolInt32(int32(uint32(*(*uint8)(unsafe.Pointer((*VP8EncIterator)(unsafe.Pointer(it)).Fmb + 0))&0x3>>0)) == libc.Int32FromInt32(1))
  22431 	segment = int32(uint32(*(*uint8)(unsafe.Pointer((*VP8EncIterator)(unsafe.Pointer(it)).Fmb + 0)) & 0x60 >> 5))
  22432 	enc = (*VP8EncIterator)(unsafe.Pointer(it)).Fenc
  22433 	VP8IteratorNzToBytes(tls, it)
  22434 	v1 = bw1
  22435 	nb_bits = uint64(int32(8) + (*VP8BitWriter)(unsafe.Pointer(v1)).Fnb_bits)
  22436 	v2 = ((*VP8BitWriter)(unsafe.Pointer(v1)).Fpos+uint64((*VP8BitWriter)(unsafe.Pointer(v1)).Frun))*uint64(8) + nb_bits
  22437 	goto _3
  22438 _3:
  22439 	pos1 = v2
  22440 	if i16 != 0 {
  22441 		VP8InitResidual(tls, 0, int32(1), enc, bp)
  22442 		(*(*func(*libc.TLS, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8SetResidualCoeffs})))(tls, rd+40, bp)
  22443 		v4 = PutCoeffs(tls, bw1, **(**int32)(__ccgo_up(it + 132 + 8*4))+**(**int32)(__ccgo_up(it + 168 + 8*4)), bp)
  22444 		**(**int32)(__ccgo_up(it + 168 + 8*4)) = v4
  22445 		**(**int32)(__ccgo_up(it + 132 + 8*4)) = v4
  22446 		VP8InitResidual(tls, int32(1), 0, enc, bp)
  22447 	} else {
  22448 		VP8InitResidual(tls, 0, int32(3), enc, bp)
  22449 	}
  22450 	// luma-AC
  22451 	y = 0
  22452 	for {
  22453 		if !(y < int32(4)) {
  22454 			break
  22455 		}
  22456 		x = 0
  22457 		for {
  22458 			if !(x < int32(4)) {
  22459 				break
  22460 			}
  22461 			ctx = **(**int32)(__ccgo_up(it + 132 + uintptr(x)*4)) + **(**int32)(__ccgo_up(it + 168 + uintptr(y)*4))
  22462 			(*(*func(*libc.TLS, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8SetResidualCoeffs})))(tls, rd+72+uintptr(x+y*int32(4))*32, bp)
  22463 			v4 = PutCoeffs(tls, bw1, ctx, bp)
  22464 			**(**int32)(__ccgo_up(it + 168 + uintptr(y)*4)) = v4
  22465 			**(**int32)(__ccgo_up(it + 132 + uintptr(x)*4)) = v4
  22466 			goto _6
  22467 		_6:
  22468 			;
  22469 			x = x + 1
  22470 		}
  22471 		goto _5
  22472 	_5:
  22473 		;
  22474 		y = y + 1
  22475 	}
  22476 	v1 = bw1
  22477 	nb_bits = uint64(int32(8) + (*VP8BitWriter)(unsafe.Pointer(v1)).Fnb_bits)
  22478 	v2 = ((*VP8BitWriter)(unsafe.Pointer(v1)).Fpos+uint64((*VP8BitWriter)(unsafe.Pointer(v1)).Frun))*uint64(8) + nb_bits
  22479 	goto _10
  22480 _10:
  22481 	pos2 = v2
  22482 	// U/V
  22483 	VP8InitResidual(tls, 0, int32(2), enc, bp)
  22484 	ch = 0
  22485 	for {
  22486 		if !(ch <= int32(2)) {
  22487 			break
  22488 		}
  22489 		y = 0
  22490 		for {
  22491 			if !(y < int32(2)) {
  22492 				break
  22493 			}
  22494 			x = 0
  22495 			for {
  22496 				if !(x < int32(2)) {
  22497 					break
  22498 				}
  22499 				ctx1 = **(**int32)(__ccgo_up(it + 132 + uintptr(int32(4)+ch+x)*4)) + **(**int32)(__ccgo_up(it + 168 + uintptr(int32(4)+ch+y)*4))
  22500 				(*(*func(*libc.TLS, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8SetResidualCoeffs})))(tls, rd+584+uintptr(ch*int32(2)+x+y*int32(2))*32, bp)
  22501 				v4 = PutCoeffs(tls, bw1, ctx1, bp)
  22502 				**(**int32)(__ccgo_up(it + 168 + uintptr(int32(4)+ch+y)*4)) = v4
  22503 				**(**int32)(__ccgo_up(it + 132 + uintptr(int32(4)+ch+x)*4)) = v4
  22504 				goto _13
  22505 			_13:
  22506 				;
  22507 				x = x + 1
  22508 			}
  22509 			goto _12
  22510 		_12:
  22511 			;
  22512 			y = y + 1
  22513 		}
  22514 		goto _11
  22515 	_11:
  22516 		;
  22517 		ch = ch + int32(2)
  22518 	}
  22519 	v1 = bw1
  22520 	nb_bits = uint64(int32(8) + (*VP8BitWriter)(unsafe.Pointer(v1)).Fnb_bits)
  22521 	v2 = ((*VP8BitWriter)(unsafe.Pointer(v1)).Fpos+uint64((*VP8BitWriter)(unsafe.Pointer(v1)).Frun))*uint64(8) + nb_bits
  22522 	goto _17
  22523 _17:
  22524 	pos3 = v2
  22525 	(*VP8EncIterator)(unsafe.Pointer(it)).Fluma_bits = pos2 - pos1
  22526 	(*VP8EncIterator)(unsafe.Pointer(it)).Fuv_bits = pos3 - pos2
  22527 	**(**uint64_t)(__ccgo_up(it + 208 + uintptr(segment)*24 + uintptr(i16)*8)) += (*VP8EncIterator)(unsafe.Pointer(it)).Fluma_bits
  22528 	**(**uint64_t)(__ccgo_up(it + 208 + uintptr(segment)*24 + 2*8)) += (*VP8EncIterator)(unsafe.Pointer(it)).Fuv_bits
  22529 	VP8IteratorBytesToNz(tls, it)
  22530 }
  22531 
  22532 // C documentation
  22533 //
  22534 //	// Same as CodeResiduals, but doesn't actually write anything.
  22535 //	// Instead, it just records the event distribution.
  22536 func RecordResiduals(tls *libc.TLS, it uintptr, rd uintptr) {
  22537 	bp := tls.Alloc(48)
  22538 	defer tls.Free(48)
  22539 	var ch, ctx, ctx1, x, y, v1 int32
  22540 	var enc uintptr
  22541 	var _ /* res at bp+0 */ VP8Residual
  22542 	_, _, _, _, _, _, _ = ch, ctx, ctx1, enc, x, y, v1
  22543 	enc = (*VP8EncIterator)(unsafe.Pointer(it)).Fenc
  22544 	VP8IteratorNzToBytes(tls, it)
  22545 	if int32(uint32(*(*uint8)(unsafe.Pointer((*VP8EncIterator)(unsafe.Pointer(it)).Fmb + 0))&0x3>>0)) == int32(1) { // i16x16
  22546 		VP8InitResidual(tls, 0, int32(1), enc, bp)
  22547 		(*(*func(*libc.TLS, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8SetResidualCoeffs})))(tls, rd+40, bp)
  22548 		v1 = VP8RecordCoeffs(tls, **(**int32)(__ccgo_up(it + 132 + 8*4))+**(**int32)(__ccgo_up(it + 168 + 8*4)), bp)
  22549 		**(**int32)(__ccgo_up(it + 168 + 8*4)) = v1
  22550 		**(**int32)(__ccgo_up(it + 132 + 8*4)) = v1
  22551 		VP8InitResidual(tls, int32(1), 0, enc, bp)
  22552 	} else {
  22553 		VP8InitResidual(tls, 0, int32(3), enc, bp)
  22554 	}
  22555 	// luma-AC
  22556 	y = 0
  22557 	for {
  22558 		if !(y < int32(4)) {
  22559 			break
  22560 		}
  22561 		x = 0
  22562 		for {
  22563 			if !(x < int32(4)) {
  22564 				break
  22565 			}
  22566 			ctx = **(**int32)(__ccgo_up(it + 132 + uintptr(x)*4)) + **(**int32)(__ccgo_up(it + 168 + uintptr(y)*4))
  22567 			(*(*func(*libc.TLS, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8SetResidualCoeffs})))(tls, rd+72+uintptr(x+y*int32(4))*32, bp)
  22568 			v1 = VP8RecordCoeffs(tls, ctx, bp)
  22569 			**(**int32)(__ccgo_up(it + 168 + uintptr(y)*4)) = v1
  22570 			**(**int32)(__ccgo_up(it + 132 + uintptr(x)*4)) = v1
  22571 			goto _3
  22572 		_3:
  22573 			;
  22574 			x = x + 1
  22575 		}
  22576 		goto _2
  22577 	_2:
  22578 		;
  22579 		y = y + 1
  22580 	}
  22581 	// U/V
  22582 	VP8InitResidual(tls, 0, int32(2), enc, bp)
  22583 	ch = 0
  22584 	for {
  22585 		if !(ch <= int32(2)) {
  22586 			break
  22587 		}
  22588 		y = 0
  22589 		for {
  22590 			if !(y < int32(2)) {
  22591 				break
  22592 			}
  22593 			x = 0
  22594 			for {
  22595 				if !(x < int32(2)) {
  22596 					break
  22597 				}
  22598 				ctx1 = **(**int32)(__ccgo_up(it + 132 + uintptr(int32(4)+ch+x)*4)) + **(**int32)(__ccgo_up(it + 168 + uintptr(int32(4)+ch+y)*4))
  22599 				(*(*func(*libc.TLS, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8SetResidualCoeffs})))(tls, rd+584+uintptr(ch*int32(2)+x+y*int32(2))*32, bp)
  22600 				v1 = VP8RecordCoeffs(tls, ctx1, bp)
  22601 				**(**int32)(__ccgo_up(it + 168 + uintptr(int32(4)+ch+y)*4)) = v1
  22602 				**(**int32)(__ccgo_up(it + 132 + uintptr(int32(4)+ch+x)*4)) = v1
  22603 				goto _7
  22604 			_7:
  22605 				;
  22606 				x = x + 1
  22607 			}
  22608 			goto _6
  22609 		_6:
  22610 			;
  22611 			y = y + 1
  22612 		}
  22613 		goto _5
  22614 	_5:
  22615 		;
  22616 		ch = ch + int32(2)
  22617 	}
  22618 	VP8IteratorBytesToNz(tls, it)
  22619 }
  22620 
  22621 //------------------------------------------------------------------------------
  22622 // Token buffer
  22623 
  22624 func RecordTokens(tls *libc.TLS, it uintptr, rd uintptr, tokens uintptr) (r int32) {
  22625 	bp := tls.Alloc(48)
  22626 	defer tls.Free(48)
  22627 	var ch, ctx, ctx1, ctx2, x, y, v1 int32
  22628 	var enc uintptr
  22629 	var _ /* res at bp+0 */ VP8Residual
  22630 	_, _, _, _, _, _, _, _ = ch, ctx, ctx1, ctx2, enc, x, y, v1
  22631 	enc = (*VP8EncIterator)(unsafe.Pointer(it)).Fenc
  22632 	VP8IteratorNzToBytes(tls, it)
  22633 	if int32(uint32(*(*uint8)(unsafe.Pointer((*VP8EncIterator)(unsafe.Pointer(it)).Fmb + 0))&0x3>>0)) == int32(1) { // i16x16
  22634 		ctx = **(**int32)(__ccgo_up(it + 132 + 8*4)) + **(**int32)(__ccgo_up(it + 168 + 8*4))
  22635 		VP8InitResidual(tls, 0, int32(1), enc, bp)
  22636 		(*(*func(*libc.TLS, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8SetResidualCoeffs})))(tls, rd+40, bp)
  22637 		v1 = VP8RecordCoeffTokens(tls, ctx, bp, tokens)
  22638 		**(**int32)(__ccgo_up(it + 168 + 8*4)) = v1
  22639 		**(**int32)(__ccgo_up(it + 132 + 8*4)) = v1
  22640 		VP8InitResidual(tls, int32(1), 0, enc, bp)
  22641 	} else {
  22642 		VP8InitResidual(tls, 0, int32(3), enc, bp)
  22643 	}
  22644 	// luma-AC
  22645 	y = 0
  22646 	for {
  22647 		if !(y < int32(4)) {
  22648 			break
  22649 		}
  22650 		x = 0
  22651 		for {
  22652 			if !(x < int32(4)) {
  22653 				break
  22654 			}
  22655 			ctx1 = **(**int32)(__ccgo_up(it + 132 + uintptr(x)*4)) + **(**int32)(__ccgo_up(it + 168 + uintptr(y)*4))
  22656 			(*(*func(*libc.TLS, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8SetResidualCoeffs})))(tls, rd+72+uintptr(x+y*int32(4))*32, bp)
  22657 			v1 = VP8RecordCoeffTokens(tls, ctx1, bp, tokens)
  22658 			**(**int32)(__ccgo_up(it + 168 + uintptr(y)*4)) = v1
  22659 			**(**int32)(__ccgo_up(it + 132 + uintptr(x)*4)) = v1
  22660 			goto _3
  22661 		_3:
  22662 			;
  22663 			x = x + 1
  22664 		}
  22665 		goto _2
  22666 	_2:
  22667 		;
  22668 		y = y + 1
  22669 	}
  22670 	// U/V
  22671 	VP8InitResidual(tls, 0, int32(2), enc, bp)
  22672 	ch = 0
  22673 	for {
  22674 		if !(ch <= int32(2)) {
  22675 			break
  22676 		}
  22677 		y = 0
  22678 		for {
  22679 			if !(y < int32(2)) {
  22680 				break
  22681 			}
  22682 			x = 0
  22683 			for {
  22684 				if !(x < int32(2)) {
  22685 					break
  22686 				}
  22687 				ctx2 = **(**int32)(__ccgo_up(it + 132 + uintptr(int32(4)+ch+x)*4)) + **(**int32)(__ccgo_up(it + 168 + uintptr(int32(4)+ch+y)*4))
  22688 				(*(*func(*libc.TLS, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8SetResidualCoeffs})))(tls, rd+584+uintptr(ch*int32(2)+x+y*int32(2))*32, bp)
  22689 				v1 = VP8RecordCoeffTokens(tls, ctx2, bp, tokens)
  22690 				**(**int32)(__ccgo_up(it + 168 + uintptr(int32(4)+ch+y)*4)) = v1
  22691 				**(**int32)(__ccgo_up(it + 132 + uintptr(int32(4)+ch+x)*4)) = v1
  22692 				goto _7
  22693 			_7:
  22694 				;
  22695 				x = x + 1
  22696 			}
  22697 			goto _6
  22698 		_6:
  22699 			;
  22700 			y = y + 1
  22701 		}
  22702 		goto _5
  22703 	_5:
  22704 		;
  22705 		ch = ch + int32(2)
  22706 	}
  22707 	VP8IteratorBytesToNz(tls, it)
  22708 	return libc.BoolInt32(!((*VP8TBuffer)(unsafe.Pointer(tokens)).Ferror1 != 0))
  22709 }
  22710 
  22711 //------------------------------------------------------------------------------
  22712 // ExtraInfo map / Debug function
  22713 
  22714 func ResetSSE(tls *libc.TLS, enc uintptr) {
  22715 	**(**uint64_t)(__ccgo_up(enc + 23512)) = uint64(0)
  22716 	**(**uint64_t)(__ccgo_up(enc + 23512 + 1*8)) = uint64(0)
  22717 	**(**uint64_t)(__ccgo_up(enc + 23512 + 2*8)) = uint64(0)
  22718 	// Note: enc->sse[3] is managed by alpha.c
  22719 	(*VP8Encoder)(unsafe.Pointer(enc)).Fsse_count = uint64(0)
  22720 }
  22721 
  22722 func StoreSSE(tls *libc.TLS, it uintptr) {
  22723 	var enc, in, out uintptr
  22724 	_, _, _ = enc, in, out
  22725 	enc = (*VP8EncIterator)(unsafe.Pointer(it)).Fenc
  22726 	in = (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_in
  22727 	out = (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_out
  22728 	// Note: not totally accurate at boundary. And doesn't include in-loop filter.
  22729 	**(**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))))
  22730 	**(**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))))
  22731 	**(**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))))
  22732 	**(**uint64_t)(__ccgo_up(enc + 23544)) += uint64(libc.Int32FromInt32(16) * libc.Int32FromInt32(16))
  22733 }
  22734 
  22735 func StoreSideInfo(tls *libc.TLS, it uintptr) {
  22736 	var b, v1 int32
  22737 	var enc, info, mb, pic uintptr
  22738 	_, _, _, _, _, _ = b, enc, info, mb, pic, v1
  22739 	enc = (*VP8EncIterator)(unsafe.Pointer(it)).Fenc
  22740 	mb = (*VP8EncIterator)(unsafe.Pointer(it)).Fmb
  22741 	pic = (*VP8Encoder)(unsafe.Pointer(enc)).Fpic
  22742 	if (*WebPPicture)(unsafe.Pointer(pic)).Fstats != libc.UintptrFromInt32(0) {
  22743 		StoreSSE(tls, it)
  22744 		**(**int32)(__ccgo_up(enc + 23604)) += libc.BoolInt32(int32(uint32(*(*uint8)(unsafe.Pointer(mb + 0))&0x3>>0)) == 0)
  22745 		**(**int32)(__ccgo_up(enc + 23604 + 1*4)) += libc.BoolInt32(int32(uint32(*(*uint8)(unsafe.Pointer(mb + 0))&0x3>>0)) == int32(1))
  22746 		**(**int32)(__ccgo_up(enc + 23604 + 2*4)) += libc.BoolInt32(int32(uint32(*(*uint8)(unsafe.Pointer(mb + 0))&0x10>>4)) != 0)
  22747 	}
  22748 	if (*WebPPicture)(unsafe.Pointer(pic)).Fextra_info != libc.UintptrFromInt32(0) {
  22749 		info = (*WebPPicture)(unsafe.Pointer(pic)).Fextra_info + uintptr((*VP8EncIterator)(unsafe.Pointer(it)).Fx+(*VP8EncIterator)(unsafe.Pointer(it)).Fy*(*VP8Encoder)(unsafe.Pointer(enc)).Fmb_w)
  22750 		switch (*WebPPicture)(unsafe.Pointer(pic)).Fextra_info_type {
  22751 		case int32(1):
  22752 			**(**uint8_t)(__ccgo_up(info)) = uint8(int32(uint32(*(*uint8)(unsafe.Pointer(mb + 0)) & 0x3 >> 0)))
  22753 		case int32(2):
  22754 			**(**uint8_t)(__ccgo_up(info)) = uint8(int32(uint32(*(*uint8)(unsafe.Pointer(mb + 0)) & 0x60 >> 5)))
  22755 		case int32(3):
  22756 			**(**uint8_t)(__ccgo_up(info)) = uint8((**(**VP8SegmentInfo)(__ccgo_up(enc + 608 + uintptr(int32(uint32(*(*uint8)(unsafe.Pointer(mb + 0))&0x60>>5)))*744))).Fquant)
  22757 		case int32(4):
  22758 			if int32(uint32(*(*uint8)(unsafe.Pointer(mb + 0))&0x3>>0)) == int32(1) {
  22759 				v1 = int32(**(**uint8_t)(__ccgo_up((*VP8EncIterator)(unsafe.Pointer(it)).Fpreds)))
  22760 			} else {
  22761 				v1 = int32(0xff)
  22762 			}
  22763 			**(**uint8_t)(__ccgo_up(info)) = uint8(v1)
  22764 		case int32(5):
  22765 			**(**uint8_t)(__ccgo_up(info)) = uint8(int32(uint32(*(*uint8)(unsafe.Pointer(mb + 0)) & 0xc >> 2)))
  22766 		case int32(6):
  22767 			b = int32(((*VP8EncIterator)(unsafe.Pointer(it)).Fluma_bits + (*VP8EncIterator)(unsafe.Pointer(it)).Fuv_bits + libc.Uint64FromInt32(7)) >> libc.Int32FromInt32(3))
  22768 			if b > int32(255) {
  22769 				v1 = int32(255)
  22770 			} else {
  22771 				v1 = b
  22772 			}
  22773 			**(**uint8_t)(__ccgo_up(info)) = uint8(v1)
  22774 		case int32(7):
  22775 			**(**uint8_t)(__ccgo_up(info)) = (*VP8MBInfo)(unsafe.Pointer(mb)).Falpha
  22776 		default:
  22777 			**(**uint8_t)(__ccgo_up(info)) = uint8(0)
  22778 			break
  22779 		}
  22780 	}
  22781 }
  22782 
  22783 func ResetSideInfo(tls *libc.TLS, it uintptr) {
  22784 	var enc, pic uintptr
  22785 	_, _ = enc, pic
  22786 	enc = (*VP8EncIterator)(unsafe.Pointer(it)).Fenc
  22787 	pic = (*VP8Encoder)(unsafe.Pointer(enc)).Fpic
  22788 	if (*WebPPicture)(unsafe.Pointer(pic)).Fstats != libc.UintptrFromInt32(0) {
  22789 		libc.Xmemset(tls, enc+23604, 0, uint64(12))
  22790 	}
  22791 	ResetSSE(tls, enc)
  22792 }
  22793 
  22794 func GetPSNR(tls *libc.TLS, mse uint64_t, size uint64_t) (r float64) {
  22795 	var v1 float64
  22796 	_ = v1
  22797 	if mse > uint64(0) && size > uint64(0) {
  22798 		v1 = float64(float64(10) * libc.Xlog10(tls, float64(float64(libc.Float64FromFloat64(255)*libc.Float64FromFloat64(255))*float64(size))/float64(mse)))
  22799 	} else {
  22800 		v1 = libc.Float64FromInt32(99)
  22801 	}
  22802 	return v1
  22803 }
  22804 
  22805 //------------------------------------------------------------------------------
  22806 //  StatLoop(): only collect statistics (number of skips, token usage, ...).
  22807 //  This is used for deciding optimal probabilities. It also modifies the
  22808 //  quantizer value if some target (size, PSNR) was specified.
  22809 
  22810 func SetLoopParams(tls *libc.TLS, enc uintptr, q float32) {
  22811 	// Make sure the quality parameter is inside valid bounds
  22812 	q = Clamp(tls, q, libc.Float32FromFloat32(0), libc.Float32FromFloat32(100))
  22813 	VP8SetSegmentParams(tls, enc, q) // setup segment quantizations and filters
  22814 	SetSegmentProbas(tls, enc)       // compute segment probabilities
  22815 	ResetStats(tls, enc)
  22816 	ResetSSE(tls, enc)
  22817 }
  22818 
  22819 func OneStatPass(tls *libc.TLS, enc uintptr, rd_opt VP8RDLevel, nb_mbs int32, percent_delta int32, s uintptr) (r uint64_t) {
  22820 	bp := tls.Alloc(4736)
  22821 	defer tls.Free(4736)
  22822 	var distortion, pixel_count, size, size_p0 uint64_t
  22823 	var v1 int32
  22824 	var v2 bool
  22825 	var _ /* info at bp+3848 */ VP8ModeScore
  22826 	var _ /* it at bp+0 */ VP8EncIterator
  22827 	_, _, _, _, _, _ = distortion, pixel_count, size, size_p0, v1, v2
  22828 	size = uint64(0)
  22829 	size_p0 = uint64(0)
  22830 	distortion = uint64(0)
  22831 	pixel_count = uint64(nb_mbs) * uint64(384)
  22832 	VP8IteratorInit(tls, enc, bp)
  22833 	SetLoopParams(tls, enc, (*PassStats)(unsafe.Pointer(s)).Fq)
  22834 	for {
  22835 		VP8IteratorImport(tls, bp, libc.UintptrFromInt32(0))
  22836 		if VP8Decimate(tls, bp, bp+3848, rd_opt) != 0 {
  22837 			// Just record the number of skips and act like skip_proba is not used.
  22838 			(*VP8Encoder)(unsafe.Pointer(enc)).Fproba.Fnb_skip = (*VP8Encoder)(unsafe.Pointer(enc)).Fproba.Fnb_skip + 1
  22839 		}
  22840 		RecordResiduals(tls, bp, bp+3848)
  22841 		size = size + uint64((**(**VP8ModeScore)(__ccgo_up(bp + 3848))).FR+(**(**VP8ModeScore)(__ccgo_up(bp + 3848))).FH)
  22842 		size_p0 = size_p0 + uint64((**(**VP8ModeScore)(__ccgo_up(bp + 3848))).FH)
  22843 		distortion = distortion + uint64((**(**VP8ModeScore)(__ccgo_up(bp + 3848))).FD)
  22844 		if percent_delta != 0 && !(VP8IteratorProgress(tls, bp, percent_delta) != 0) {
  22845 			return uint64(0)
  22846 		}
  22847 		VP8IteratorSaveBoundary(tls, bp)
  22848 		goto _3
  22849 	_3:
  22850 		;
  22851 		if v2 = VP8IteratorNext(tls, bp) != 0; v2 {
  22852 			nb_mbs = nb_mbs - 1
  22853 			v1 = nb_mbs
  22854 		}
  22855 		if !(v2 && v1 > 0) {
  22856 			break
  22857 		}
  22858 	}
  22859 	size_p0 = size_p0 + uint64((*VP8Encoder)(unsafe.Pointer(enc)).Fsegment_hdr.Fsize)
  22860 	if (*PassStats)(unsafe.Pointer(s)).Fdo_size_search != 0 {
  22861 		size = size + uint64(FinalizeSkipProba(tls, enc))
  22862 		size = size + uint64(FinalizeTokenProbas(tls, enc+3616))
  22863 		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))
  22864 		(*PassStats)(unsafe.Pointer(s)).Fvalue = float64(size)
  22865 	} else {
  22866 		(*PassStats)(unsafe.Pointer(s)).Fvalue = GetPSNR(tls, distortion, pixel_count)
  22867 	}
  22868 	return size_p0
  22869 }
  22870 
  22871 func StatLoop(tls *libc.TLS, enc uintptr) (r int32) {
  22872 	bp := tls.Alloc(64)
  22873 	defer tls.Free(64)
  22874 	var do_search, fast_probe, final_percent, is_last_pass, method, nb_mbs, num_pass_left, percent_per_pass, task_percent, v1 int32
  22875 	var rd_opt VP8RDLevel
  22876 	var size_p0 uint64_t
  22877 	var _ /* stats at bp+0 */ PassStats
  22878 	_, _, _, _, _, _, _, _, _, _, _, _ = 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
  22879 	method = (*VP8Encoder)(unsafe.Pointer(enc)).Fmethod
  22880 	do_search = (*VP8Encoder)(unsafe.Pointer(enc)).Fdo_search
  22881 	fast_probe = libc.BoolInt32((method == 0 || method == int32(3)) && !(do_search != 0))
  22882 	num_pass_left = (*WebPConfig)(unsafe.Pointer((*VP8Encoder)(unsafe.Pointer(enc)).Fconfig)).Fpass
  22883 	task_percent = int32(20)
  22884 	percent_per_pass = (task_percent + num_pass_left/int32(2)) / num_pass_left
  22885 	final_percent = (*VP8Encoder)(unsafe.Pointer(enc)).Fpercent + task_percent
  22886 	if method >= int32(3) || do_search != 0 {
  22887 		v1 = int32(RD_OPT_BASIC)
  22888 	} else {
  22889 		v1 = int32(RD_OPT_NONE)
  22890 	}
  22891 	rd_opt = v1
  22892 	nb_mbs = (*VP8Encoder)(unsafe.Pointer(enc)).Fmb_w * (*VP8Encoder)(unsafe.Pointer(enc)).Fmb_h
  22893 	InitPassStats(tls, enc, bp)
  22894 	ResetTokenStats(tls, enc)
  22895 	// Fast mode: quick analysis pass over few mbs. Better than nothing.
  22896 	if fast_probe != 0 {
  22897 		if method == int32(3) { // we need more stats for method 3 to be reliable.
  22898 			if nb_mbs > int32(200) {
  22899 				v1 = nb_mbs >> int32(1)
  22900 			} else {
  22901 				v1 = int32(100)
  22902 			}
  22903 			nb_mbs = v1
  22904 		} else {
  22905 			if nb_mbs > int32(200) {
  22906 				v1 = nb_mbs >> int32(2)
  22907 			} else {
  22908 				v1 = int32(50)
  22909 			}
  22910 			nb_mbs = v1
  22911 		}
  22912 	}
  22913 	for {
  22914 		v1 = num_pass_left
  22915 		num_pass_left = num_pass_left - 1
  22916 		if !(v1 > 0) {
  22917 			break
  22918 		}
  22919 		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)
  22920 		size_p0 = OneStatPass(tls, enc, rd_opt, nb_mbs, percent_per_pass, bp)
  22921 		if size_p0 == uint64(0) {
  22922 			return 0
  22923 		}
  22924 		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) {
  22925 			num_pass_left = num_pass_left + 1
  22926 			**(**int32)(__ccgo_up(enc + 23624)) >>= int32(1) // strengthen header bit limitation...
  22927 			continue                                         // ...and start over
  22928 		}
  22929 		if is_last_pass != 0 {
  22930 			break
  22931 		}
  22932 		// If no target size: just do several pass without changing 'q'
  22933 		if do_search != 0 {
  22934 			ComputeNextQ(tls, bp)
  22935 			if libc.Xfabs(tls, float64((**(**PassStats)(__ccgo_up(bp))).Fdq)) <= float64(DQ_LIMIT) {
  22936 				break
  22937 			}
  22938 		}
  22939 	}
  22940 	if !(do_search != 0) || !((**(**PassStats)(__ccgo_up(bp))).Fdo_size_search != 0) {
  22941 		// Need to finalize probas now, since it wasn't done during the search.
  22942 		FinalizeSkipProba(tls, enc)
  22943 		FinalizeTokenProbas(tls, enc+3616)
  22944 	}
  22945 	VP8CalculateLevelCosts(tls, enc+3616) // finalize costs
  22946 	return WebPReportProgress(tls, (*VP8Encoder)(unsafe.Pointer(enc)).Fpic, final_percent, enc+536)
  22947 }
  22948 
  22949 //------------------------------------------------------------------------------
  22950 // Main loops
  22951 //
  22952 
  22953 var kAverageBytesPerMB = [8]uint8_t{
  22954 	0: uint8(50),
  22955 	1: uint8(24),
  22956 	2: uint8(16),
  22957 	3: uint8(9),
  22958 	4: uint8(7),
  22959 	5: uint8(5),
  22960 	6: uint8(3),
  22961 	7: uint8(2),
  22962 }
  22963 
  22964 func PreLoopInitialize(tls *libc.TLS, enc uintptr) (r int32) {
  22965 	var average_bytes_per_MB, bytes_per_parts, ok, p int32
  22966 	_, _, _, _ = average_bytes_per_MB, bytes_per_parts, ok, p
  22967 	ok = int32(1)
  22968 	average_bytes_per_MB = int32(kAverageBytesPerMB[(*VP8Encoder)(unsafe.Pointer(enc)).Fbase_quant>>int32(4)])
  22969 	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
  22970 	// Initialize the bit-writers
  22971 	p = 0
  22972 	for {
  22973 		if !(ok != 0 && p < (*VP8Encoder)(unsafe.Pointer(enc)).Fnum_parts) {
  22974 			break
  22975 		}
  22976 		ok = VP8BitWriterInit(tls, enc+112+uintptr(p)*48, uint64(bytes_per_parts))
  22977 		goto _1
  22978 	_1:
  22979 		;
  22980 		p = p + 1
  22981 	}
  22982 	if !(ok != 0) {
  22983 		VP8EncFreeBitWriters(tls, enc) // malloc error occurred
  22984 		return WebPEncodingSetError(tls, (*VP8Encoder)(unsafe.Pointer(enc)).Fpic, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  22985 	}
  22986 	return ok
  22987 }
  22988 
  22989 func PostLoopFinalize(tls *libc.TLS, it uintptr, ok int32) (r int32) {
  22990 	var enc uintptr
  22991 	var i, p, s int32
  22992 	_, _, _, _ = enc, i, p, s
  22993 	enc = (*VP8EncIterator)(unsafe.Pointer(it)).Fenc
  22994 	if ok != 0 {
  22995 		p = 0
  22996 		for {
  22997 			if !(p < (*VP8Encoder)(unsafe.Pointer(enc)).Fnum_parts) {
  22998 				break
  22999 			}
  23000 			VP8BitWriterFinish(tls, enc+112+uintptr(p)*48)
  23001 			ok = ok & libc.BoolInt32(!((**(**VP8BitWriter)(__ccgo_up(enc + 112 + uintptr(p)*48))).Ferror1 != 0))
  23002 			goto _1
  23003 		_1:
  23004 			;
  23005 			p = p + 1
  23006 		}
  23007 	}
  23008 	if ok != 0 { // All good. Finish up.
  23009 		if (*WebPPicture)(unsafe.Pointer((*VP8Encoder)(unsafe.Pointer(enc)).Fpic)).Fstats != libc.UintptrFromInt32(0) {
  23010 			i = 0
  23011 			for {
  23012 				if !(i <= int32(2)) {
  23013 					break
  23014 				}
  23015 				s = 0
  23016 				for {
  23017 					if !(s < int32(NUM_MB_SEGMENTS)) {
  23018 						break
  23019 					}
  23020 					**(**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))
  23021 					goto _3
  23022 				_3:
  23023 					;
  23024 					s = s + 1
  23025 				}
  23026 				goto _2
  23027 			_2:
  23028 				;
  23029 				i = i + 1
  23030 			}
  23031 		}
  23032 		VP8AdjustFilterStrength(tls, it) // ...and store filter stats.
  23033 	} else {
  23034 		// Something bad happened -> need to do some memory cleanup.
  23035 		VP8EncFreeBitWriters(tls, enc)
  23036 		return WebPEncodingSetError(tls, (*VP8Encoder)(unsafe.Pointer(enc)).Fpic, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  23037 	}
  23038 	return ok
  23039 }
  23040 
  23041 //------------------------------------------------------------------------------
  23042 //  VP8EncLoop(): does the final bitstream coding.
  23043 
  23044 func ResetAfterSkip(tls *libc.TLS, it uintptr) {
  23045 	if int32(uint32(*(*uint8)(unsafe.Pointer((*VP8EncIterator)(unsafe.Pointer(it)).Fmb + 0))&0x3>>0)) == int32(1) {
  23046 		**(**uint32_t)(__ccgo_up((*VP8EncIterator)(unsafe.Pointer(it)).Fnz)) = uint32(0) // reset all predictors
  23047 		**(**int32)(__ccgo_up(it + 168 + 8*4)) = 0
  23048 	} else {
  23049 		**(**uint32_t)(__ccgo_up((*VP8EncIterator)(unsafe.Pointer(it)).Fnz)) &= uint32(libc.Int32FromInt32(1) << libc.Int32FromInt32(24)) // preserve the dc_nz bit
  23050 	}
  23051 }
  23052 
  23053 func VP8EncLoop(tls *libc.TLS, enc uintptr) (r int32) {
  23054 	bp := tls.Alloc(4736)
  23055 	defer tls.Free(4736)
  23056 	var dont_use_skip, ok int32
  23057 	var rd_opt VP8RDLevel
  23058 	var _ /* info at bp+3848 */ VP8ModeScore
  23059 	var _ /* it at bp+0 */ VP8EncIterator
  23060 	_, _, _ = dont_use_skip, ok, rd_opt
  23061 	ok = PreLoopInitialize(tls, enc)
  23062 	if !(ok != 0) {
  23063 		return 0
  23064 	}
  23065 	StatLoop(tls, enc) // stats-collection loop
  23066 	VP8IteratorInit(tls, enc, bp)
  23067 	VP8InitFilter(tls, bp)
  23068 	for cond := true; cond; cond = ok != 0 && VP8IteratorNext(tls, bp) != 0 {
  23069 		dont_use_skip = libc.BoolInt32(!((*VP8Encoder)(unsafe.Pointer(enc)).Fproba.Fuse_skip_proba != 0))
  23070 		rd_opt = (*VP8Encoder)(unsafe.Pointer(enc)).Frd_opt_level
  23071 		VP8IteratorImport(tls, bp, libc.UintptrFromInt32(0))
  23072 		// Warning! order is important: first call VP8Decimate() and
  23073 		// *then* decide how to code the skip decision if there's one.
  23074 		if !(VP8Decimate(tls, bp, bp+3848, rd_opt) != 0) || dont_use_skip != 0 {
  23075 			CodeResiduals(tls, (**(**VP8EncIterator)(__ccgo_up(bp))).Fbw, bp, bp+3848)
  23076 			if (*VP8BitWriter)(unsafe.Pointer((**(**VP8EncIterator)(__ccgo_up(bp))).Fbw)).Ferror1 != 0 {
  23077 				// enc->pic->error_code is set in PostLoopFinalize().
  23078 				ok = 0
  23079 				break
  23080 			}
  23081 		} else { // reset predictors after a skip
  23082 			ResetAfterSkip(tls, bp)
  23083 		}
  23084 		StoreSideInfo(tls, bp)
  23085 		VP8StoreFilterStats(tls, bp)
  23086 		VP8IteratorExport(tls, bp)
  23087 		ok = VP8IteratorProgress(tls, bp, int32(20))
  23088 		VP8IteratorSaveBoundary(tls, bp)
  23089 	}
  23090 	return PostLoopFinalize(tls, bp, ok)
  23091 }
  23092 
  23093 //------------------------------------------------------------------------------
  23094 // Single pass using Token Buffer.
  23095 
  23096 func VP8EncTokenLoop(tls *libc.TLS, enc uintptr) (r int32) {
  23097 	bp := tls.Alloc(4784)
  23098 	defer tls.Free(4784)
  23099 	var cnt, do_search, is_last_pass, max_count, num_pass_left, ok, pass_progress, remaining_progress, v1 int32
  23100 	var distortion, pixel_count, size, size_p0 uint64_t
  23101 	var proba uintptr
  23102 	var rd_opt VP8RDLevel
  23103 	var v2 bool
  23104 	var _ /* info at bp+3904 */ VP8ModeScore
  23105 	var _ /* it at bp+0 */ VP8EncIterator
  23106 	var _ /* stats at bp+3848 */ PassStats
  23107 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  23108 	// Roughly refresh the proba eight times per pass
  23109 	max_count = (*VP8Encoder)(unsafe.Pointer(enc)).Fmb_w * (*VP8Encoder)(unsafe.Pointer(enc)).Fmb_h >> int32(3)
  23110 	num_pass_left = (*WebPConfig)(unsafe.Pointer((*VP8Encoder)(unsafe.Pointer(enc)).Fconfig)).Fpass
  23111 	remaining_progress = int32(40) // percents
  23112 	do_search = (*VP8Encoder)(unsafe.Pointer(enc)).Fdo_search
  23113 	proba = enc + 3616
  23114 	rd_opt = (*VP8Encoder)(unsafe.Pointer(enc)).Frd_opt_level
  23115 	pixel_count = uint64((*VP8Encoder)(unsafe.Pointer(enc)).Fmb_w) * uint64((*VP8Encoder)(unsafe.Pointer(enc)).Fmb_h) * uint64(384)
  23116 	InitPassStats(tls, enc, bp+3848)
  23117 	ok = PreLoopInitialize(tls, enc)
  23118 	if !(ok != 0) {
  23119 		return 0
  23120 	}
  23121 	if max_count < int32(MIN_COUNT) {
  23122 		max_count = int32(MIN_COUNT)
  23123 	}
  23124 	// otherwise, token-buffer won't be useful
  23125 	for {
  23126 		if v2 = ok != 0; v2 {
  23127 			v1 = num_pass_left
  23128 			num_pass_left = num_pass_left - 1
  23129 		}
  23130 		if !(v2 && v1 > 0) {
  23131 			break
  23132 		}
  23133 		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)
  23134 		size_p0 = uint64(0)
  23135 		distortion = uint64(0)
  23136 		cnt = max_count
  23137 		// The final number of passes is not trivial to know in advance.
  23138 		pass_progress = remaining_progress / (int32(2) + num_pass_left)
  23139 		remaining_progress = remaining_progress - pass_progress
  23140 		VP8IteratorInit(tls, enc, bp)
  23141 		SetLoopParams(tls, enc, (**(**PassStats)(__ccgo_up(bp + 3848))).Fq)
  23142 		if is_last_pass != 0 {
  23143 			ResetTokenStats(tls, enc)
  23144 			VP8InitFilter(tls, bp) // don't collect stats until last pass (too costly)
  23145 		}
  23146 		VP8TBufferClear(tls, enc+496)
  23147 		for cond := true; cond; cond = ok != 0 && VP8IteratorNext(tls, bp) != 0 {
  23148 			VP8IteratorImport(tls, bp, libc.UintptrFromInt32(0))
  23149 			cnt = cnt - 1
  23150 			v1 = cnt
  23151 			if v1 < 0 {
  23152 				FinalizeTokenProbas(tls, proba)
  23153 				VP8CalculateLevelCosts(tls, proba) // refresh cost tables for rd-opt
  23154 				cnt = max_count
  23155 			}
  23156 			VP8Decimate(tls, bp, bp+3904, rd_opt)
  23157 			ok = RecordTokens(tls, bp, bp+3904, enc+496)
  23158 			if !(ok != 0) {
  23159 				WebPEncodingSetError(tls, (*VP8Encoder)(unsafe.Pointer(enc)).Fpic, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  23160 				break
  23161 			}
  23162 			size_p0 = size_p0 + uint64((**(**VP8ModeScore)(__ccgo_up(bp + 3904))).FH)
  23163 			distortion = distortion + uint64((**(**VP8ModeScore)(__ccgo_up(bp + 3904))).FD)
  23164 			if is_last_pass != 0 {
  23165 				StoreSideInfo(tls, bp)
  23166 				VP8StoreFilterStats(tls, bp)
  23167 				VP8IteratorExport(tls, bp)
  23168 				ok = VP8IteratorProgress(tls, bp, pass_progress)
  23169 			}
  23170 			VP8IteratorSaveBoundary(tls, bp)
  23171 		}
  23172 		if !(ok != 0) {
  23173 			break
  23174 		}
  23175 		size_p0 = size_p0 + uint64((*VP8Encoder)(unsafe.Pointer(enc)).Fsegment_hdr.Fsize)
  23176 		if (**(**PassStats)(__ccgo_up(bp + 3848))).Fdo_size_search != 0 {
  23177 			size = uint64(FinalizeTokenProbas(tls, enc+3616))
  23178 			size = size + VP8EstimateTokenSize(tls, enc+496, proba+4)
  23179 			size = (size + size_p0 + uint64(1024)) >> int32(11) // -> size in bytes
  23180 			size = size + uint64(libc.Int32FromInt32(RIFF_HEADER_SIZE)+libc.Int32FromInt32(CHUNK_HEADER_SIZE)+libc.Int32FromInt32(VP8_FRAME_HEADER_SIZE))
  23181 			(**(**PassStats)(__ccgo_up(bp + 3848))).Fvalue = float64(size)
  23182 		} else { // compute and store PSNR
  23183 			(**(**PassStats)(__ccgo_up(bp + 3848))).Fvalue = GetPSNR(tls, distortion, pixel_count)
  23184 		}
  23185 		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) {
  23186 			num_pass_left = num_pass_left + 1
  23187 			**(**int32)(__ccgo_up(enc + 23624)) >>= int32(1) // strengthen header bit limitation...
  23188 			if is_last_pass != 0 {
  23189 				ResetSideInfo(tls, bp)
  23190 			}
  23191 			continue // ...and start over
  23192 		}
  23193 		if is_last_pass != 0 {
  23194 			break // done
  23195 		}
  23196 		if do_search != 0 {
  23197 			ComputeNextQ(tls, bp+3848) // Adjust q
  23198 		}
  23199 	}
  23200 	if ok != 0 {
  23201 		if !((**(**PassStats)(__ccgo_up(bp + 3848))).Fdo_size_search != 0) {
  23202 			FinalizeTokenProbas(tls, enc+3616)
  23203 		}
  23204 		ok = VP8EmitTokens(tls, enc+496, enc+112+uintptr(0)*48, proba+4, int32(1))
  23205 	}
  23206 	ok = libc.BoolInt32(ok != 0 && WebPReportProgress(tls, (*VP8Encoder)(unsafe.Pointer(enc)).Fpic, (*VP8Encoder)(unsafe.Pointer(enc)).Fpercent+remaining_progress, enc+536) != 0)
  23207 	return PostLoopFinalize(tls, bp, ok)
  23208 }
  23209 
  23210 const MAX_HISTO_GREEDY = 100
  23211 const NUM_PARTITIONS = 4
  23212 const SIZE_MAX8 = "_UI64_MAX"
  23213 
  23214 //------------------------------------------------------------------------------
  23215 
  23216 // Copyright 2012 Google Inc. All Rights Reserved.
  23217 //
  23218 // Use of this source code is governed by a BSD-style license
  23219 // that can be found in the COPYING file in the root of the source
  23220 // tree. An additional intellectual property rights grant can be found
  23221 // in the file PATENTS. All contributing project authors may
  23222 // be found in the AUTHORS file in the root of the source tree.
  23223 // -----------------------------------------------------------------------------
  23224 //
  23225 // Misc. common utility functions
  23226 //
  23227 // Authors: Skal (pascal.massimino@gmail.com)
  23228 //          Urvang (urvang@google.com)
  23229 
  23230 // Copyright 2011 Google Inc. All Rights Reserved.
  23231 //
  23232 // Use of this source code is governed by a BSD-style license
  23233 // that can be found in the COPYING file in the root of the source
  23234 // tree. An additional intellectual property rights grant can be found
  23235 // in the file PATENTS. All contributing project authors may
  23236 // be found in the AUTHORS file in the root of the source tree.
  23237 // -----------------------------------------------------------------------------
  23238 //
  23239 //   WebP encoder: main interface
  23240 //
  23241 // Author: Skal (pascal.massimino@gmail.com)
  23242 
  23243 // Copyright 2012 Google Inc. All Rights Reserved.
  23244 //
  23245 // Use of this source code is governed by a BSD-style license
  23246 // that can be found in the COPYING file in the root of the source
  23247 // tree. An additional intellectual property rights grant can be found
  23248 // in the file PATENTS. All contributing project authors may
  23249 // be found in the AUTHORS file in the root of the source tree.
  23250 // -----------------------------------------------------------------------------
  23251 //
  23252 //  Internal header for constants related to WebP file format.
  23253 //
  23254 // Author: Urvang (urvang@google.com)
  23255 
  23256 // Copyright 2010 Google Inc. All Rights Reserved.
  23257 //
  23258 // Use of this source code is governed by a BSD-style license
  23259 // that can be found in the COPYING file in the root of the source
  23260 // tree. An additional intellectual property rights grant can be found
  23261 // in the file PATENTS. All contributing project authors may
  23262 // be found in the AUTHORS file in the root of the source tree.
  23263 // -----------------------------------------------------------------------------
  23264 //
  23265 //  Common types + memory wrappers
  23266 //
  23267 // Author: Skal (pascal.massimino@gmail.com)
  23268 
  23269 // Number of partitions for the three dominant (literal, red and blue) symbol
  23270 // costs.
  23271 // The size of the bin-hash corresponding to the three dominant costs.
  23272 // Maximum number of histograms allowed in greedy combining algorithm.
  23273 
  23274 // C documentation
  23275 //
  23276 //	// Enum to meaningfully access the elements of the Histogram arrays.
  23277 type HistogramIndex = int32
  23278 
  23279 const LITERAL = 0
  23280 const DISTANCE = 4
  23281 
  23282 // C documentation
  23283 //
  23284 //	// Return the size of the histogram for a given cache_bits.
  23285 func GetHistogramSize(tls *libc.TLS, cache_bits int32) (r int32) {
  23286 	var literal_size, v1, v2, v4 int32
  23287 	var total_size size_t
  23288 	_, _, _, _, _ = literal_size, total_size, v1, v2, v4
  23289 	v1 = cache_bits
  23290 	if v1 > 0 {
  23291 		v4 = int32(1) << v1
  23292 	} else {
  23293 		v4 = 0
  23294 	}
  23295 	v2 = libc.Int32FromInt32(NUM_LITERAL_CODES) + libc.Int32FromInt32(NUM_LENGTH_CODES) + v4
  23296 	goto _3
  23297 _3:
  23298 	literal_size = v2
  23299 	total_size = uint64(3312) + uint64(4)*uint64(literal_size)
  23300 	return int32(total_size)
  23301 }
  23302 
  23303 func HistogramStatsClear(tls *libc.TLS, h uintptr) {
  23304 	var i int32
  23305 	_ = i
  23306 	i = 0
  23307 	for {
  23308 		if !(i < int32(5)) {
  23309 			break
  23310 		}
  23311 		**(**uint16_t)(__ccgo_up(h + 3244 + uintptr(i)*2)) = uint16(libc.Int32FromInt32(0xffff))
  23312 		// By default, the histogram is assumed to be used.
  23313 		**(**uint8_t)(__ccgo_up(h + 3304 + uintptr(i))) = uint8(1)
  23314 		goto _1
  23315 	_1:
  23316 		;
  23317 		i = i + 1
  23318 	}
  23319 	(*VP8LHistogram)(unsafe.Pointer(h)).Fbit_cost = uint64(0)
  23320 	libc.Xmemset(tls, h+3264, 0, uint64(40))
  23321 }
  23322 
  23323 func HistogramClear(tls *libc.TLS, h uintptr) {
  23324 	var cache_bits, histo_size int32
  23325 	var literal uintptr
  23326 	_, _, _ = cache_bits, histo_size, literal
  23327 	literal = (*VP8LHistogram)(unsafe.Pointer(h)).Fliteral
  23328 	cache_bits = (*VP8LHistogram)(unsafe.Pointer(h)).Fpalette_code_bits
  23329 	histo_size = GetHistogramSize(tls, cache_bits)
  23330 	libc.Xmemset(tls, h, 0, uint64(histo_size))
  23331 	(*VP8LHistogram)(unsafe.Pointer(h)).Fpalette_code_bits = cache_bits
  23332 	(*VP8LHistogram)(unsafe.Pointer(h)).Fliteral = literal
  23333 	HistogramStatsClear(tls, h)
  23334 }
  23335 
  23336 // C documentation
  23337 //
  23338 //	// Swap two histogram pointers.
  23339 func HistogramSwap(tls *libc.TLS, h1 uintptr, h2 uintptr) {
  23340 	var tmp uintptr
  23341 	_ = tmp
  23342 	tmp = **(**uintptr)(__ccgo_up(h1))
  23343 	**(**uintptr)(__ccgo_up(h1)) = **(**uintptr)(__ccgo_up(h2))
  23344 	**(**uintptr)(__ccgo_up(h2)) = tmp
  23345 }
  23346 
  23347 func HistogramCopy(tls *libc.TLS, src uintptr, dst uintptr) {
  23348 	var dst_cache_bits, histo_size, literal_size, v1, v2, v4 int32
  23349 	var dst_literal uintptr
  23350 	_, _, _, _, _, _, _ = dst_cache_bits, dst_literal, histo_size, literal_size, v1, v2, v4
  23351 	dst_literal = (*VP8LHistogram)(unsafe.Pointer(dst)).Fliteral
  23352 	dst_cache_bits = (*VP8LHistogram)(unsafe.Pointer(dst)).Fpalette_code_bits
  23353 	v1 = dst_cache_bits
  23354 	if v1 > 0 {
  23355 		v4 = int32(1) << v1
  23356 	} else {
  23357 		v4 = 0
  23358 	}
  23359 	v2 = libc.Int32FromInt32(NUM_LITERAL_CODES) + libc.Int32FromInt32(NUM_LENGTH_CODES) + v4
  23360 	goto _3
  23361 _3:
  23362 	literal_size = v2
  23363 	histo_size = GetHistogramSize(tls, dst_cache_bits)
  23364 	libc.Xmemcpy(tls, dst, src, uint64(histo_size))
  23365 	(*VP8LHistogram)(unsafe.Pointer(dst)).Fliteral = dst_literal
  23366 	libc.Xmemcpy(tls, (*VP8LHistogram)(unsafe.Pointer(dst)).Fliteral, (*VP8LHistogram)(unsafe.Pointer(src)).Fliteral, uint64(literal_size)*uint64(4))
  23367 }
  23368 
  23369 func VP8LFreeHistogram(tls *libc.TLS, h uintptr) {
  23370 	WebPSafeFree(tls, h)
  23371 }
  23372 
  23373 func VP8LFreeHistogramSet(tls *libc.TLS, histograms uintptr) {
  23374 	WebPSafeFree(tls, histograms)
  23375 }
  23376 
  23377 func VP8LHistogramCreate(tls *libc.TLS, h uintptr, refs uintptr, palette_code_bits int32) {
  23378 	if palette_code_bits >= 0 {
  23379 		(*VP8LHistogram)(unsafe.Pointer(h)).Fpalette_code_bits = palette_code_bits
  23380 	}
  23381 	HistogramClear(tls, h)
  23382 	VP8LHistogramStoreRefs(tls, refs, libc.UintptrFromInt32(0), 0, h)
  23383 }
  23384 
  23385 func VP8LHistogramInit(tls *libc.TLS, h uintptr, palette_code_bits int32, init_arrays int32) {
  23386 	(*VP8LHistogram)(unsafe.Pointer(h)).Fpalette_code_bits = palette_code_bits
  23387 	if init_arrays != 0 {
  23388 		HistogramClear(tls, h)
  23389 	} else {
  23390 		HistogramStatsClear(tls, h)
  23391 	}
  23392 }
  23393 
  23394 func VP8LAllocateHistogram(tls *libc.TLS, cache_bits int32) (r uintptr) {
  23395 	var histo, memory uintptr
  23396 	var total_size int32
  23397 	_, _, _ = histo, memory, total_size
  23398 	histo = libc.UintptrFromInt32(0)
  23399 	total_size = GetHistogramSize(tls, cache_bits)
  23400 	memory = WebPSafeMalloc(tls, uint64(total_size), uint64(1))
  23401 	if memory == libc.UintptrFromInt32(0) {
  23402 		return libc.UintptrFromInt32(0)
  23403 	}
  23404 	histo = memory
  23405 	// 'literal' won't necessary be aligned.
  23406 	(*VP8LHistogram)(unsafe.Pointer(histo)).Fliteral = memory + libc.UintptrFromInt64(3312)
  23407 	VP8LHistogramInit(tls, histo, cache_bits, 0)
  23408 	return histo
  23409 }
  23410 
  23411 // C documentation
  23412 //
  23413 //	// Resets the pointers of the histograms to point to the bit buffer in the set.
  23414 func HistogramSetResetPointers(tls *libc.TLS, set uintptr, cache_bits int32) {
  23415 	var histo_size, i int32
  23416 	var memory uintptr
  23417 	_, _, _ = histo_size, i, memory
  23418 	histo_size = GetHistogramSize(tls, cache_bits)
  23419 	memory = (*VP8LHistogramSet)(unsafe.Pointer(set)).Fhistograms
  23420 	memory = memory + uintptr(uint64((*VP8LHistogramSet)(unsafe.Pointer(set)).Fmax_size)*uint64(8))
  23421 	i = 0
  23422 	for {
  23423 		if !(i < (*VP8LHistogramSet)(unsafe.Pointer(set)).Fmax_size) {
  23424 			break
  23425 		}
  23426 		memory = uintptr((uint64(memory) + libc.Uint64FromInt32(WEBP_ALIGN_CST)) & ^libc.Uint64FromInt32(WEBP_ALIGN_CST))
  23427 		**(**uintptr)(__ccgo_up((*VP8LHistogramSet)(unsafe.Pointer(set)).Fhistograms + uintptr(i)*8)) = memory
  23428 		// 'literal' won't necessary be aligned.
  23429 		(*VP8LHistogram)(unsafe.Pointer(**(**uintptr)(__ccgo_up((*VP8LHistogramSet)(unsafe.Pointer(set)).Fhistograms + uintptr(i)*8)))).Fliteral = memory + libc.UintptrFromInt64(3312)
  23430 		memory = memory + uintptr(histo_size)
  23431 		goto _1
  23432 	_1:
  23433 		;
  23434 		i = i + 1
  23435 	}
  23436 }
  23437 
  23438 // C documentation
  23439 //
  23440 //	// Returns the total size of the VP8LHistogramSet.
  23441 func HistogramSetTotalSize(tls *libc.TLS, size int32, cache_bits int32) (r size_t) {
  23442 	var histo_size int32
  23443 	_ = histo_size
  23444 	histo_size = GetHistogramSize(tls, cache_bits)
  23445 	return libc.Uint64FromInt64(16) + uint64(size)*(libc.Uint64FromInt64(8)+uint64(histo_size)+libc.Uint64FromInt32(WEBP_ALIGN_CST))
  23446 }
  23447 
  23448 func VP8LAllocateHistogramSet(tls *libc.TLS, size int32, cache_bits int32) (r uintptr) {
  23449 	var i int32
  23450 	var memory, set uintptr
  23451 	var total_size size_t
  23452 	_, _, _, _ = i, memory, set, total_size
  23453 	total_size = HistogramSetTotalSize(tls, size, cache_bits)
  23454 	memory = WebPSafeMalloc(tls, total_size, uint64(1))
  23455 	if memory == libc.UintptrFromInt32(0) {
  23456 		return libc.UintptrFromInt32(0)
  23457 	}
  23458 	set = memory
  23459 	memory = memory + uintptr(16)
  23460 	(*VP8LHistogramSet)(unsafe.Pointer(set)).Fhistograms = memory
  23461 	(*VP8LHistogramSet)(unsafe.Pointer(set)).Fmax_size = size
  23462 	(*VP8LHistogramSet)(unsafe.Pointer(set)).Fsize = size
  23463 	HistogramSetResetPointers(tls, set, cache_bits)
  23464 	i = 0
  23465 	for {
  23466 		if !(i < size) {
  23467 			break
  23468 		}
  23469 		VP8LHistogramInit(tls, **(**uintptr)(__ccgo_up((*VP8LHistogramSet)(unsafe.Pointer(set)).Fhistograms + uintptr(i)*8)), cache_bits, 0)
  23470 		goto _1
  23471 	_1:
  23472 		;
  23473 		i = i + 1
  23474 	}
  23475 	return set
  23476 }
  23477 
  23478 func VP8LHistogramSetClear(tls *libc.TLS, set uintptr) {
  23479 	var cache_bits, i, size int32
  23480 	var memory uintptr
  23481 	var total_size size_t
  23482 	_, _, _, _, _ = cache_bits, i, memory, size, total_size
  23483 	cache_bits = (*VP8LHistogram)(unsafe.Pointer(**(**uintptr)(__ccgo_up((*VP8LHistogramSet)(unsafe.Pointer(set)).Fhistograms)))).Fpalette_code_bits
  23484 	size = (*VP8LHistogramSet)(unsafe.Pointer(set)).Fmax_size
  23485 	total_size = HistogramSetTotalSize(tls, size, cache_bits)
  23486 	memory = set
  23487 	libc.Xmemset(tls, memory, 0, total_size)
  23488 	memory = memory + uintptr(16)
  23489 	(*VP8LHistogramSet)(unsafe.Pointer(set)).Fhistograms = memory
  23490 	(*VP8LHistogramSet)(unsafe.Pointer(set)).Fmax_size = size
  23491 	(*VP8LHistogramSet)(unsafe.Pointer(set)).Fsize = size
  23492 	HistogramSetResetPointers(tls, set, cache_bits)
  23493 	i = 0
  23494 	for {
  23495 		if !(i < size) {
  23496 			break
  23497 		}
  23498 		(*VP8LHistogram)(unsafe.Pointer(**(**uintptr)(__ccgo_up((*VP8LHistogramSet)(unsafe.Pointer(set)).Fhistograms + uintptr(i)*8)))).Fpalette_code_bits = cache_bits
  23499 		goto _1
  23500 	_1:
  23501 		;
  23502 		i = i + 1
  23503 	}
  23504 }
  23505 
  23506 // C documentation
  23507 //
  23508 //	// Removes the histogram 'i' from 'set'.
  23509 func HistogramSetRemoveHistogram(tls *libc.TLS, set uintptr, i int32) {
  23510 	**(**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))
  23511 	(*VP8LHistogramSet)(unsafe.Pointer(set)).Fsize = (*VP8LHistogramSet)(unsafe.Pointer(set)).Fsize - 1
  23512 }
  23513 
  23514 // -----------------------------------------------------------------------------
  23515 
  23516 func HistogramAddSinglePixOrCopy(tls *libc.TLS, histo uintptr, v uintptr, __ccgo_fp_distance_modifier uintptr, distance_modifier_arg0 int32) {
  23517 	bp := tls.Alloc(16)
  23518 	defer tls.Free(16)
  23519 	var highest_bit, literal_ix, second_highest_bit, v1, v11, v17, v20 int32
  23520 	var prefix_code VP8LPrefixCode
  23521 	var v3 uint32_t
  23522 	var v18, v19 uintptr
  23523 	var _ /* code at bp+0 */ int32
  23524 	var _ /* extra_bits at bp+4 */ int32
  23525 	_, _, _, _, _, _, _, _, _, _, _ = highest_bit, literal_ix, prefix_code, second_highest_bit, v1, v11, v17, v18, v19, v20, v3
  23526 	v1 = libc.BoolInt32(int32((*PixOrCopy)(unsafe.Pointer(v)).Fmode) == int32(kLiteral))
  23527 	goto _2
  23528 _2:
  23529 	if v1 != 0 {
  23530 		v3 = (*PixOrCopy)(unsafe.Pointer(v)).Fargb_or_distance >> (int32(3) * libc.Int32FromInt32(8)) & uint32(0xff)
  23531 		goto _4
  23532 	_4:
  23533 		**(**uint32_t)(__ccgo_up(histo + 2056 + uintptr(v3)*4)) = **(**uint32_t)(__ccgo_up(histo + 2056 + uintptr(v3)*4)) + 1
  23534 		v3 = (*PixOrCopy)(unsafe.Pointer(v)).Fargb_or_distance >> (int32(2) * libc.Int32FromInt32(8)) & uint32(0xff)
  23535 		goto _6
  23536 	_6:
  23537 		**(**uint32_t)(__ccgo_up(histo + 8 + uintptr(v3)*4)) = **(**uint32_t)(__ccgo_up(histo + 8 + uintptr(v3)*4)) + 1
  23538 		v3 = (*PixOrCopy)(unsafe.Pointer(v)).Fargb_or_distance >> (int32(1) * libc.Int32FromInt32(8)) & uint32(0xff)
  23539 		goto _8
  23540 	_8:
  23541 		**(**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
  23542 		v3 = (*PixOrCopy)(unsafe.Pointer(v)).Fargb_or_distance >> (0 * libc.Int32FromInt32(8)) & uint32(0xff)
  23543 		goto _10
  23544 	_10:
  23545 		**(**uint32_t)(__ccgo_up(histo + 1032 + uintptr(v3)*4)) = **(**uint32_t)(__ccgo_up(histo + 1032 + uintptr(v3)*4)) + 1
  23546 	} else {
  23547 		v1 = libc.BoolInt32(int32((*PixOrCopy)(unsafe.Pointer(v)).Fmode) == int32(kCacheIdx))
  23548 		goto _12
  23549 	_12:
  23550 		if v1 != 0 {
  23551 			v3 = (*PixOrCopy)(unsafe.Pointer(v)).Fargb_or_distance
  23552 			goto _14
  23553 		_14:
  23554 			literal_ix = int32(uint32(libc.Int32FromInt32(NUM_LITERAL_CODES)+libc.Int32FromInt32(NUM_LENGTH_CODES)) + v3)
  23555 			**(**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
  23556 		} else {
  23557 			v3 = uint32((*PixOrCopy)(unsafe.Pointer(v)).Flen1)
  23558 			goto _16
  23559 		_16:
  23560 			v1 = int32(v3)
  23561 			v18 = bp
  23562 			v19 = bp + 4
  23563 			if v1 < libc.Int32FromInt32(PREFIX_LOOKUP_IDX_MAX) {
  23564 				prefix_code = kPrefixEncodeCode[v1]
  23565 				**(**int32)(__ccgo_up(v18)) = int32(prefix_code.Fcode)
  23566 				**(**int32)(__ccgo_up(v19)) = int32(prefix_code.Fextra_bits)
  23567 			} else {
  23568 				v11 = v1
  23569 				v11 = v11 - 1
  23570 				v17 = v11
  23571 				v20 = int32(31) ^ libc.X__builtin_clz(tls, uint32(v17))
  23572 				goto _23
  23573 			_23:
  23574 				highest_bit = v20
  23575 				second_highest_bit = v11 >> (highest_bit - int32(1)) & int32(1)
  23576 				**(**int32)(__ccgo_up(v19)) = highest_bit - int32(1)
  23577 				**(**int32)(__ccgo_up(v18)) = int32(2)*highest_bit + second_highest_bit
  23578 			}
  23579 			**(**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
  23580 			if __ccgo_fp_distance_modifier == libc.UintptrFromInt32(0) {
  23581 				v3 = (*PixOrCopy)(unsafe.Pointer(v)).Fargb_or_distance
  23582 				goto _25
  23583 			_25:
  23584 				v1 = int32(v3)
  23585 				v18 = bp
  23586 				v19 = bp + 4
  23587 				if v1 < libc.Int32FromInt32(PREFIX_LOOKUP_IDX_MAX) {
  23588 					prefix_code = kPrefixEncodeCode[v1]
  23589 					**(**int32)(__ccgo_up(v18)) = int32(prefix_code.Fcode)
  23590 					**(**int32)(__ccgo_up(v19)) = int32(prefix_code.Fextra_bits)
  23591 				} else {
  23592 					v11 = v1
  23593 					v11 = v11 - 1
  23594 					v17 = v11
  23595 					v20 = int32(31) ^ libc.X__builtin_clz(tls, uint32(v17))
  23596 					goto _32
  23597 				_32:
  23598 					highest_bit = v20
  23599 					second_highest_bit = v11 >> (highest_bit - int32(1)) & int32(1)
  23600 					**(**int32)(__ccgo_up(v19)) = highest_bit - int32(1)
  23601 					**(**int32)(__ccgo_up(v18)) = int32(2)*highest_bit + second_highest_bit
  23602 				}
  23603 			} else {
  23604 				v3 = (*PixOrCopy)(unsafe.Pointer(v)).Fargb_or_distance
  23605 				goto _34
  23606 			_34:
  23607 				v1 = (*(*func(*libc.TLS, int32, int32) int32)(unsafe.Pointer(&struct{ uintptr }{__ccgo_fp_distance_modifier})))(tls, distance_modifier_arg0, int32(v3))
  23608 				v18 = bp
  23609 				v19 = bp + 4
  23610 				if v1 < libc.Int32FromInt32(PREFIX_LOOKUP_IDX_MAX) {
  23611 					prefix_code = kPrefixEncodeCode[v1]
  23612 					**(**int32)(__ccgo_up(v18)) = int32(prefix_code.Fcode)
  23613 					**(**int32)(__ccgo_up(v19)) = int32(prefix_code.Fextra_bits)
  23614 				} else {
  23615 					v11 = v1
  23616 					v11 = v11 - 1
  23617 					v17 = v11
  23618 					v20 = int32(31) ^ libc.X__builtin_clz(tls, uint32(v17))
  23619 					goto _41
  23620 				_41:
  23621 					highest_bit = v20
  23622 					second_highest_bit = v11 >> (highest_bit - int32(1)) & int32(1)
  23623 					**(**int32)(__ccgo_up(v19)) = highest_bit - int32(1)
  23624 					**(**int32)(__ccgo_up(v18)) = int32(2)*highest_bit + second_highest_bit
  23625 				}
  23626 			}
  23627 			**(**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
  23628 		}
  23629 	}
  23630 }
  23631 
  23632 type __ccgo_fp__XVP8LHistogramStoreRefs_1 = func(*libc.TLS, int32, int32) int32
  23633 
  23634 func VP8LHistogramStoreRefs(tls *libc.TLS, refs uintptr, __ccgo_fp_distance_modifier uintptr, distance_modifier_arg0 int32, histo uintptr) {
  23635 	bp := tls.Alloc(32)
  23636 	defer tls.Free(32)
  23637 	var v1 int32
  23638 	var v3, v4, v5 uintptr
  23639 	var _ /* c at bp+0 */ VP8LRefsCursor
  23640 	_, _, _, _ = v1, v3, v4, v5
  23641 	**(**VP8LRefsCursor)(__ccgo_up(bp)) = VP8LRefsCursorInit(tls, refs)
  23642 	for {
  23643 		v1 = libc.BoolInt32((*VP8LRefsCursor)(unsafe.Pointer(bp)).Fcur_pos != libc.UintptrFromInt32(0))
  23644 		goto _2
  23645 	_2:
  23646 		if !(v1 != 0) {
  23647 			break
  23648 		}
  23649 		HistogramAddSinglePixOrCopy(tls, histo, (**(**VP8LRefsCursor)(__ccgo_up(bp))).Fcur_pos, __ccgo_fp_distance_modifier, distance_modifier_arg0)
  23650 		v3 = bp
  23651 		v5 = v3
  23652 		*(*uintptr)(unsafe.Pointer(v5)) += 8
  23653 		v4 = *(*uintptr)(unsafe.Pointer(v5))
  23654 		if v4 == (*VP8LRefsCursor)(unsafe.Pointer(v3)).Flast_pos {
  23655 			VP8LRefsCursorNextBlock(tls, v3)
  23656 		}
  23657 	}
  23658 }
  23659 
  23660 // -----------------------------------------------------------------------------
  23661 // Entropy-related functions.
  23662 
  23663 func BitsEntropyRefine(tls *libc.TLS, entropy uintptr) (r uint64_t) {
  23664 	var min_limit, mix uint64_t
  23665 	var v1, v2, v3 int64_t
  23666 	var v5 int64
  23667 	var v11 uint64
  23668 	_, _, _, _, _, _, _ = min_limit, mix, v1, v11, v2, v3, v5
  23669 	if (*VP8LBitEntropy)(unsafe.Pointer(entropy)).Fnonzeros < int32(5) {
  23670 		if (*VP8LBitEntropy)(unsafe.Pointer(entropy)).Fnonzeros <= int32(1) {
  23671 			return uint64(0)
  23672 		}
  23673 		// Two symbols, they will be 0 and 1 in a Huffman code.
  23674 		// Let's mix in a bit of entropy to favor good clustering when
  23675 		// distributions of these are combined.
  23676 		if (*VP8LBitEntropy)(unsafe.Pointer(entropy)).Fnonzeros == int32(2) {
  23677 			v1 = int64(uint64(99)*(uint64((*VP8LBitEntropy)(unsafe.Pointer(entropy)).Fsum)<<libc.Int32FromInt32(LOG_2_PRECISION_BITS)) + (*VP8LBitEntropy)(unsafe.Pointer(entropy)).Fentropy)
  23678 			v2 = int64(100)
  23679 			if libc.BoolInt32(v1 < 0) == libc.BoolInt32(v2 < 0) {
  23680 				v5 = (v1 + v2/int64(2)) / v2
  23681 			} else {
  23682 				v5 = (v1 - v2/int64(2)) / v2
  23683 			}
  23684 			v3 = v5
  23685 			goto _4
  23686 		_4:
  23687 			return uint64(v3)
  23688 		}
  23689 		// No matter what the entropy says, we cannot be better than min_limit
  23690 		// with Huffman coding. I am mixing a bit of entropy into the
  23691 		// min_limit since it produces much better (~0.5 %) compression results
  23692 		// perhaps because of better entropy clustering.
  23693 		if (*VP8LBitEntropy)(unsafe.Pointer(entropy)).Fnonzeros == int32(3) {
  23694 			mix = uint64(950)
  23695 		} else {
  23696 			mix = uint64(700) // nonzeros == 4.
  23697 		}
  23698 	} else {
  23699 		mix = uint64(627)
  23700 	}
  23701 	min_limit = uint64(libc.Uint32FromInt32(2)*(*VP8LBitEntropy)(unsafe.Pointer(entropy)).Fsum-(*VP8LBitEntropy)(unsafe.Pointer(entropy)).Fmax_val) << int32(LOG_2_PRECISION_BITS)
  23702 	v1 = int64(mix*min_limit + (uint64(1000)-mix)*(*VP8LBitEntropy)(unsafe.Pointer(entropy)).Fentropy)
  23703 	v2 = int64(1000)
  23704 	if libc.BoolInt32(v1 < 0) == libc.BoolInt32(v2 < 0) {
  23705 		v5 = (v1 + v2/int64(2)) / v2
  23706 	} else {
  23707 		v5 = (v1 - v2/int64(2)) / v2
  23708 	}
  23709 	v3 = v5
  23710 	goto _9
  23711 _9:
  23712 	min_limit = uint64(v3)
  23713 	if (*VP8LBitEntropy)(unsafe.Pointer(entropy)).Fentropy < min_limit {
  23714 		v11 = min_limit
  23715 	} else {
  23716 		v11 = (*VP8LBitEntropy)(unsafe.Pointer(entropy)).Fentropy
  23717 	}
  23718 	return v11
  23719 	return r
  23720 }
  23721 
  23722 func VP8LBitsEntropy(tls *libc.TLS, array uintptr, n int32) (r uint64_t) {
  23723 	bp := tls.Alloc(32)
  23724 	defer tls.Free(32)
  23725 	var _ /* entropy at bp+0 */ VP8LBitEntropy
  23726 	VP8LBitsEntropyUnrefined(tls, array, n, bp)
  23727 	return BitsEntropyRefine(tls, bp)
  23728 }
  23729 
  23730 func InitialHuffmanCost(tls *libc.TLS) (r uint64_t) {
  23731 	var v1, v2, v3 int64_t
  23732 	var v5 int64
  23733 	_, _, _, _ = v1, v2, v3, v5
  23734 	// Subtract a bias of 9.1.
  23735 	v1 = libc.Int64FromInt64(91) << libc.Int32FromInt32(LOG_2_PRECISION_BITS)
  23736 	v2 = int64(10)
  23737 	if libc.BoolInt32(v1 < 0) == libc.BoolInt32(v2 < 0) {
  23738 		v5 = (v1 + v2/int64(2)) / v2
  23739 	} else {
  23740 		v5 = (v1 - v2/int64(2)) / v2
  23741 	}
  23742 	v3 = v5
  23743 	goto _4
  23744 _4:
  23745 	return kHuffmanCodeOfHuffmanCodeSize<<libc.Int32FromInt32(LOG_2_PRECISION_BITS) - uint64(v3)
  23746 }
  23747 
  23748 // Small bias because Huffman code length is typically not stored in
  23749 // full length.
  23750 var kHuffmanCodeOfHuffmanCodeSize = uint64(libc.Int32FromInt32(CODE_LENGTH_CODES) * libc.Int32FromInt32(3))
  23751 
  23752 // C documentation
  23753 //
  23754 //	// Finalize the Huffman cost based on streak numbers and length type (<3 or >=3)
  23755 func FinalHuffmanCost(tls *libc.TLS, stats uintptr) (r uint64_t) {
  23756 	var retval uint64_t
  23757 	var retval_extra uint32_t
  23758 	_, _ = retval, retval_extra
  23759 	// The constants in this function are empirical and got rounded from
  23760 	// their original values in 1/8 when switched to 1/1024.
  23761 	retval = InitialHuffmanCost(tls)
  23762 	// Second coefficient: Many zeros in the histogram are covered efficiently
  23763 	// by a run-length encode. Originally 2/8.
  23764 	retval_extra = uint32(**(**int32)(__ccgo_up(stats))*int32(1600) + int32(240)***(**int32)(__ccgo_up(stats + 8 + 1*4)))
  23765 	// Second coefficient: Constant values are encoded less efficiently, but still
  23766 	// RLE'ed. Originally 6/8.
  23767 	retval_extra = retval_extra + uint32(**(**int32)(__ccgo_up(stats + 1*4))*int32(2640)+int32(720)***(**int32)(__ccgo_up(stats + 8 + 1*8 + 1*4)))
  23768 	// 0s are usually encoded more efficiently than non-0s.
  23769 	// Originally 15/8.
  23770 	retval_extra = retval_extra + uint32(int32(1840)***(**int32)(__ccgo_up(stats + 8)))
  23771 	// Originally 26/8.
  23772 	retval_extra = retval_extra + uint32(int32(3360)***(**int32)(__ccgo_up(stats + 8 + 1*8)))
  23773 	return retval + uint64(retval_extra)<<(libc.Int32FromInt32(LOG_2_PRECISION_BITS)-libc.Int32FromInt32(10))
  23774 }
  23775 
  23776 // C documentation
  23777 //
  23778 //	// Get the symbol entropy for the distribution 'population'.
  23779 //	// Set 'trivial_sym', if there's only one symbol present in the distribution.
  23780 func PopulationCost(tls *libc.TLS, population uintptr, length int32, trivial_sym uintptr, is_used uintptr) (r uint64_t) {
  23781 	bp := tls.Alloc(48)
  23782 	defer tls.Free(48)
  23783 	var v1 uint32
  23784 	var _ /* bit_entropy at bp+0 */ VP8LBitEntropy
  23785 	var _ /* stats at bp+24 */ VP8LStreaks
  23786 	_ = v1
  23787 	(*(*func(*libc.TLS, uintptr, int32, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8LGetEntropyUnrefined})))(tls, population, length, bp, bp+24)
  23788 	if trivial_sym != libc.UintptrFromInt32(0) {
  23789 		if (**(**VP8LBitEntropy)(__ccgo_up(bp))).Fnonzeros == int32(1) {
  23790 			v1 = (**(**VP8LBitEntropy)(__ccgo_up(bp))).Fnonzero_code
  23791 		} else {
  23792 			v1 = uint32(uint16(libc.Int32FromInt32(0xffff)))
  23793 		}
  23794 		**(**uint16_t)(__ccgo_up(trivial_sym)) = uint16(v1)
  23795 	}
  23796 	if is_used != libc.UintptrFromInt32(0) {
  23797 		// The histogram is used if there is at least one non-zero streak.
  23798 		**(**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)
  23799 	}
  23800 	return BitsEntropyRefine(tls, bp) + FinalHuffmanCost(tls, bp+24)
  23801 }
  23802 
  23803 func GetPopulationInfo(tls *libc.TLS, histo uintptr, index HistogramIndex, population uintptr, length uintptr) {
  23804 	var v1, v2, v4 int32
  23805 	_, _, _ = v1, v2, v4
  23806 	switch index {
  23807 	case int32(LITERAL):
  23808 		**(**uintptr)(__ccgo_up(population)) = (*VP8LHistogram)(unsafe.Pointer(histo)).Fliteral
  23809 		v1 = (*VP8LHistogram)(unsafe.Pointer(histo)).Fpalette_code_bits
  23810 		if v1 > 0 {
  23811 			v4 = int32(1) << v1
  23812 		} else {
  23813 			v4 = 0
  23814 		}
  23815 		v2 = libc.Int32FromInt32(NUM_LITERAL_CODES) + libc.Int32FromInt32(NUM_LENGTH_CODES) + v4
  23816 		goto _3
  23817 	_3:
  23818 		**(**int32)(__ccgo_up(length)) = v2
  23819 	case int32(RED):
  23820 		**(**uintptr)(__ccgo_up(population)) = histo + 8
  23821 		**(**int32)(__ccgo_up(length)) = int32(NUM_LITERAL_CODES)
  23822 	case int32(BLUE):
  23823 		**(**uintptr)(__ccgo_up(population)) = histo + 1032
  23824 		**(**int32)(__ccgo_up(length)) = int32(NUM_LITERAL_CODES)
  23825 	case int32(ALPHA):
  23826 		**(**uintptr)(__ccgo_up(population)) = histo + 2056
  23827 		**(**int32)(__ccgo_up(length)) = int32(NUM_LITERAL_CODES)
  23828 	case int32(DISTANCE):
  23829 		**(**uintptr)(__ccgo_up(population)) = histo + 3080
  23830 		**(**int32)(__ccgo_up(length)) = int32(NUM_DISTANCE_CODES)
  23831 		break
  23832 	}
  23833 }
  23834 
  23835 // C documentation
  23836 //
  23837 //	// trivial_at_end is 1 if the two histograms only have one element that is
  23838 //	// non-zero: both the zero-th one, or both the last one.
  23839 //	// 'index' is the index of the symbol in the histogram (literal, red, blue,
  23840 //	// alpha, distance).
  23841 func GetCombinedEntropy(tls *libc.TLS, h1 uintptr, h2 uintptr, index HistogramIndex) (r uint64_t) {
  23842 	bp := tls.Alloc(80)
  23843 	defer tls.Free(80)
  23844 	var is_h1_used, is_h2_used, is_trivial int32
  23845 	var _ /* X at bp+0 */ uintptr
  23846 	var _ /* Y at bp+8 */ uintptr
  23847 	var _ /* bit_entropy at bp+48 */ VP8LBitEntropy
  23848 	var _ /* length at bp+16 */ int32
  23849 	var _ /* stats at bp+20 */ VP8LStreaks
  23850 	_, _, _ = is_h1_used, is_h2_used, is_trivial
  23851 	is_h1_used = int32(**(**uint8_t)(__ccgo_up(h1 + 3304 + uintptr(index))))
  23852 	is_h2_used = int32(**(**uint8_t)(__ccgo_up(h2 + 3304 + uintptr(index))))
  23853 	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))))
  23854 	if is_trivial != 0 || !(is_h1_used != 0) || !(is_h2_used != 0) {
  23855 		if is_h1_used != 0 {
  23856 			return **(**uint64_t)(__ccgo_up(h1 + 3264 + uintptr(index)*8))
  23857 		}
  23858 		return **(**uint64_t)(__ccgo_up(h2 + 3264 + uintptr(index)*8))
  23859 	}
  23860 	GetPopulationInfo(tls, h1, index, bp, bp+16)
  23861 	GetPopulationInfo(tls, h2, index, bp+8, bp+16)
  23862 	(*(*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)
  23863 	return BitsEntropyRefine(tls, bp+48) + FinalHuffmanCost(tls, bp+20)
  23864 }
  23865 
  23866 // C documentation
  23867 //
  23868 //	// Estimates the Entropy + Huffman + other block overhead size cost.
  23869 func VP8LHistogramEstimateBits(tls *libc.TLS, h uintptr) (r uint64_t) {
  23870 	bp := tls.Alloc(16)
  23871 	defer tls.Free(16)
  23872 	var cost uint64_t
  23873 	var i int32
  23874 	var _ /* length at bp+0 */ int32
  23875 	var _ /* population at bp+8 */ uintptr
  23876 	_, _ = cost, i
  23877 	cost = uint64(0)
  23878 	i = 0
  23879 	for {
  23880 		if !(i < int32(5)) {
  23881 			break
  23882 		}
  23883 		GetPopulationInfo(tls, h, i, bp+8, bp)
  23884 		cost = cost + PopulationCost(tls, **(**uintptr)(__ccgo_up(bp + 8)), **(**int32)(__ccgo_up(bp)), libc.UintptrFromInt32(0), libc.UintptrFromInt32(0))
  23885 		goto _1
  23886 	_1:
  23887 		;
  23888 		i = i + 1
  23889 	}
  23890 	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)
  23891 	return cost
  23892 }
  23893 
  23894 // -----------------------------------------------------------------------------
  23895 // Various histogram combine/cost-eval functions
  23896 
  23897 // C documentation
  23898 //
  23899 //	// Set a + b in b, saturating at WEBP_INT64_MAX.
  23900 func SaturateAdd(tls *libc.TLS, a uint64_t, b uintptr) {
  23901 	if **(**int64_t)(__ccgo_up(b)) < 0 || int64(a) <= int64(libc.Uint64FromUint64(1)<<libc.Int32FromInt32(63)-libc.Uint64FromInt32(1))-**(**int64_t)(__ccgo_up(b)) {
  23902 		**(**int64_t)(__ccgo_up(b)) += int64(a)
  23903 	} else {
  23904 		**(**int64_t)(__ccgo_up(b)) = int64(libc.Uint64FromUint64(1)<<libc.Int32FromInt32(63) - libc.Uint64FromInt32(1))
  23905 	}
  23906 }
  23907 
  23908 // C documentation
  23909 //
  23910 //	// Returns 1 if the cost of the combined histogram is less than the threshold.
  23911 //	// Otherwise returns 0 and the cost is invalid due to early bail-out.
  23912 func GetCombinedHistogramEntropy(tls *libc.TLS, a uintptr, b uintptr, cost_threshold_in int64_t, cost uintptr, costs uintptr) (r int32) {
  23913 	var cost_threshold uint64_t
  23914 	var i int32
  23915 	_, _ = cost_threshold, i
  23916 	cost_threshold = uint64(cost_threshold_in)
  23917 	if cost_threshold_in <= 0 {
  23918 		return 0
  23919 	}
  23920 	**(**uint64_t)(__ccgo_up(cost)) = uint64(0)
  23921 	// No need to add the extra cost for length and distance as it is a constant
  23922 	// that does not influence the histograms.
  23923 	i = 0
  23924 	for {
  23925 		if !(i < int32(5)) {
  23926 			break
  23927 		}
  23928 		**(**uint64_t)(__ccgo_up(costs + uintptr(i)*8)) = GetCombinedEntropy(tls, a, b, i)
  23929 		**(**uint64_t)(__ccgo_up(cost)) += **(**uint64_t)(__ccgo_up(costs + uintptr(i)*8))
  23930 		if **(**uint64_t)(__ccgo_up(cost)) >= cost_threshold {
  23931 			return 0
  23932 		}
  23933 		goto _1
  23934 	_1:
  23935 		;
  23936 		i = i + 1
  23937 	}
  23938 	return int32(1)
  23939 }
  23940 
  23941 func HistogramAdd(tls *libc.TLS, h1 uintptr, h2 uintptr, hout uintptr) {
  23942 	bp := tls.Alloc(32)
  23943 	defer tls.Free(32)
  23944 	var i, v3 int32
  23945 	var pout uintptr
  23946 	var _ /* length at bp+0 */ int32
  23947 	var _ /* p1 at bp+8 */ uintptr
  23948 	var _ /* p2 at bp+16 */ uintptr
  23949 	var _ /* pout_const at bp+24 */ uintptr
  23950 	_, _, _ = i, pout, v3
  23951 	i = 0
  23952 	for {
  23953 		if !(i < int32(5)) {
  23954 			break
  23955 		}
  23956 		GetPopulationInfo(tls, h1, i, bp+8, bp)
  23957 		GetPopulationInfo(tls, h2, i, bp+16, bp)
  23958 		GetPopulationInfo(tls, hout, i, bp+24, bp)
  23959 		pout = **(**uintptr)(__ccgo_up(bp + 24))
  23960 		if h2 == hout {
  23961 			if **(**uint8_t)(__ccgo_up(h1 + 3304 + uintptr(i))) != 0 {
  23962 				if **(**uint8_t)(__ccgo_up(hout + 3304 + uintptr(i))) != 0 {
  23963 					(*(*func(*libc.TLS, uintptr, uintptr, int32))(unsafe.Pointer(&struct{ uintptr }{VP8LAddVectorEq})))(tls, **(**uintptr)(__ccgo_up(bp + 8)), pout, **(**int32)(__ccgo_up(bp)))
  23964 				} else {
  23965 					libc.Xmemcpy(tls, pout, **(**uintptr)(__ccgo_up(bp + 8)), uint64(**(**int32)(__ccgo_up(bp)))*uint64(4))
  23966 				}
  23967 			}
  23968 		} else {
  23969 			if **(**uint8_t)(__ccgo_up(h1 + 3304 + uintptr(i))) != 0 {
  23970 				if **(**uint8_t)(__ccgo_up(h2 + 3304 + uintptr(i))) != 0 {
  23971 					(*(*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)))
  23972 				} else {
  23973 					libc.Xmemcpy(tls, pout, **(**uintptr)(__ccgo_up(bp + 8)), uint64(**(**int32)(__ccgo_up(bp)))*uint64(4))
  23974 				}
  23975 			} else {
  23976 				if **(**uint8_t)(__ccgo_up(h2 + 3304 + uintptr(i))) != 0 {
  23977 					libc.Xmemcpy(tls, pout, **(**uintptr)(__ccgo_up(bp + 16)), uint64(**(**int32)(__ccgo_up(bp)))*uint64(4))
  23978 				} else {
  23979 					libc.Xmemset(tls, pout, 0, uint64(**(**int32)(__ccgo_up(bp)))*uint64(4))
  23980 				}
  23981 			}
  23982 		}
  23983 		goto _1
  23984 	_1:
  23985 		;
  23986 		i = i + 1
  23987 	}
  23988 	i = 0
  23989 	for {
  23990 		if !(i < int32(5)) {
  23991 			break
  23992 		}
  23993 		if int32(**(**uint16_t)(__ccgo_up(h1 + 3244 + uintptr(i)*2))) == int32(**(**uint16_t)(__ccgo_up(h2 + 3244 + uintptr(i)*2))) {
  23994 			v3 = int32(**(**uint16_t)(__ccgo_up(h1 + 3244 + uintptr(i)*2)))
  23995 		} else {
  23996 			v3 = int32(uint16(libc.Int32FromInt32(0xffff)))
  23997 		}
  23998 		**(**uint16_t)(__ccgo_up(hout + 3244 + uintptr(i)*2)) = uint16(v3)
  23999 		**(**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)
  24000 		goto _2
  24001 	_2:
  24002 		;
  24003 		i = i + 1
  24004 	}
  24005 }
  24006 
  24007 func UpdateHistogramCost(tls *libc.TLS, bit_cost uint64_t, costs uintptr, h uintptr) {
  24008 	var i int32
  24009 	_ = i
  24010 	(*VP8LHistogram)(unsafe.Pointer(h)).Fbit_cost = bit_cost
  24011 	i = 0
  24012 	for {
  24013 		if !(i < int32(5)) {
  24014 			break
  24015 		}
  24016 		**(**uint64_t)(__ccgo_up(h + 3264 + uintptr(i)*8)) = **(**uint64_t)(__ccgo_up(costs + uintptr(i)*8))
  24017 		goto _1
  24018 	_1:
  24019 		;
  24020 		i = i + 1
  24021 	}
  24022 }
  24023 
  24024 // C documentation
  24025 //
  24026 //	// Performs out = a + b, computing the cost C(a+b) - C(a) - C(b) while comparing
  24027 //	// to the threshold value 'cost_threshold'. The score returned is
  24028 //	//  Score = C(a+b) - C(a) - C(b), where C(a) + C(b) is known and fixed.
  24029 //	// Since the previous score passed is 'cost_threshold', we only need to compare
  24030 //	// the partial cost against 'cost_threshold + C(a) + C(b)' to possibly bail-out
  24031 //	// early.
  24032 //	// Returns 1 if the cost is less than the threshold.
  24033 //	// Otherwise returns 0 and the cost is invalid due to early bail-out.
  24034 func HistogramAddEval(tls *libc.TLS, a uintptr, b uintptr, out uintptr, _cost_threshold int64_t) (r int32) {
  24035 	bp := tls.Alloc(64)
  24036 	defer tls.Free(64)
  24037 	*(*int64_t)(unsafe.Pointer(bp)) = _cost_threshold
  24038 	var sum_cost uint64_t
  24039 	var _ /* bit_cost at bp+8 */ uint64_t
  24040 	var _ /* costs at bp+16 */ [5]uint64_t
  24041 	_ = sum_cost
  24042 	sum_cost = (*VP8LHistogram)(unsafe.Pointer(a)).Fbit_cost + (*VP8LHistogram)(unsafe.Pointer(b)).Fbit_cost
  24043 	SaturateAdd(tls, sum_cost, bp)
  24044 	if !(GetCombinedHistogramEntropy(tls, a, b, **(**int64_t)(__ccgo_up(bp)), bp+8, bp+16) != 0) {
  24045 		return 0
  24046 	}
  24047 	HistogramAdd(tls, a, b, out)
  24048 	UpdateHistogramCost(tls, **(**uint64_t)(__ccgo_up(bp + 8)), bp+16, out)
  24049 	return int32(1)
  24050 }
  24051 
  24052 // C documentation
  24053 //
  24054 //	// Same as HistogramAddEval(), except that the resulting histogram
  24055 //	// is not stored. Only the cost C(a+b) - C(a) is evaluated. We omit
  24056 //	// the term C(b) which is constant over all the evaluations.
  24057 //	// Returns 1 if the cost is less than the threshold.
  24058 //	// Otherwise returns 0 and the cost is invalid due to early bail-out.
  24059 func HistogramAddThresh(tls *libc.TLS, a uintptr, b uintptr, _cost_threshold int64_t, cost_out uintptr) (r int32) {
  24060 	bp := tls.Alloc(64)
  24061 	defer tls.Free(64)
  24062 	*(*int64_t)(unsafe.Pointer(bp)) = _cost_threshold
  24063 	var _ /* cost at bp+8 */ uint64_t
  24064 	var _ /* costs at bp+16 */ [5]uint64_t
  24065 	SaturateAdd(tls, (*VP8LHistogram)(unsafe.Pointer(a)).Fbit_cost, bp)
  24066 	if !(GetCombinedHistogramEntropy(tls, a, b, **(**int64_t)(__ccgo_up(bp)), bp+8, bp+16) != 0) {
  24067 		return 0
  24068 	}
  24069 	**(**int64_t)(__ccgo_up(cost_out)) = int64(**(**uint64_t)(__ccgo_up(bp + 8))) - int64((*VP8LHistogram)(unsafe.Pointer(a)).Fbit_cost)
  24070 	return int32(1)
  24071 }
  24072 
  24073 // -----------------------------------------------------------------------------
  24074 
  24075 // C documentation
  24076 //
  24077 //	// The structure to keep track of cost range for the three dominant entropy
  24078 //	// symbols.
  24079 type DominantCostRange = struct {
  24080 	Fliteral_max uint64_t
  24081 	Fliteral_min uint64_t
  24082 	Fred_max     uint64_t
  24083 	Fred_min     uint64_t
  24084 	Fblue_max    uint64_t
  24085 	Fblue_min    uint64_t
  24086 }
  24087 
  24088 func DominantCostRangeInit(tls *libc.TLS, c uintptr) {
  24089 	(*DominantCostRange)(unsafe.Pointer(c)).Fliteral_max = uint64(0)
  24090 	(*DominantCostRange)(unsafe.Pointer(c)).Fliteral_min = ^libc.Uint64FromUint64(0)
  24091 	(*DominantCostRange)(unsafe.Pointer(c)).Fred_max = uint64(0)
  24092 	(*DominantCostRange)(unsafe.Pointer(c)).Fred_min = ^libc.Uint64FromUint64(0)
  24093 	(*DominantCostRange)(unsafe.Pointer(c)).Fblue_max = uint64(0)
  24094 	(*DominantCostRange)(unsafe.Pointer(c)).Fblue_min = ^libc.Uint64FromUint64(0)
  24095 }
  24096 
  24097 func UpdateDominantCostRange(tls *libc.TLS, h uintptr, c uintptr) {
  24098 	if (*DominantCostRange)(unsafe.Pointer(c)).Fliteral_max < **(**uint64_t)(__ccgo_up(h + 3264 + uintptr(LITERAL)*8)) {
  24099 		(*DominantCostRange)(unsafe.Pointer(c)).Fliteral_max = **(**uint64_t)(__ccgo_up(h + 3264 + uintptr(LITERAL)*8))
  24100 	}
  24101 	if (*DominantCostRange)(unsafe.Pointer(c)).Fliteral_min > **(**uint64_t)(__ccgo_up(h + 3264 + uintptr(LITERAL)*8)) {
  24102 		(*DominantCostRange)(unsafe.Pointer(c)).Fliteral_min = **(**uint64_t)(__ccgo_up(h + 3264 + uintptr(LITERAL)*8))
  24103 	}
  24104 	if (*DominantCostRange)(unsafe.Pointer(c)).Fred_max < **(**uint64_t)(__ccgo_up(h + 3264 + uintptr(RED)*8)) {
  24105 		(*DominantCostRange)(unsafe.Pointer(c)).Fred_max = **(**uint64_t)(__ccgo_up(h + 3264 + uintptr(RED)*8))
  24106 	}
  24107 	if (*DominantCostRange)(unsafe.Pointer(c)).Fred_min > **(**uint64_t)(__ccgo_up(h + 3264 + uintptr(RED)*8)) {
  24108 		(*DominantCostRange)(unsafe.Pointer(c)).Fred_min = **(**uint64_t)(__ccgo_up(h + 3264 + uintptr(RED)*8))
  24109 	}
  24110 	if (*DominantCostRange)(unsafe.Pointer(c)).Fblue_max < **(**uint64_t)(__ccgo_up(h + 3264 + uintptr(BLUE)*8)) {
  24111 		(*DominantCostRange)(unsafe.Pointer(c)).Fblue_max = **(**uint64_t)(__ccgo_up(h + 3264 + uintptr(BLUE)*8))
  24112 	}
  24113 	if (*DominantCostRange)(unsafe.Pointer(c)).Fblue_min > **(**uint64_t)(__ccgo_up(h + 3264 + uintptr(BLUE)*8)) {
  24114 		(*DominantCostRange)(unsafe.Pointer(c)).Fblue_min = **(**uint64_t)(__ccgo_up(h + 3264 + uintptr(BLUE)*8))
  24115 	}
  24116 }
  24117 
  24118 func ComputeHistogramCost(tls *libc.TLS, h uintptr) {
  24119 	bp := tls.Alloc(16)
  24120 	defer tls.Free(16)
  24121 	var i int32
  24122 	var _ /* length at bp+8 */ int32
  24123 	var _ /* population at bp+0 */ uintptr
  24124 	_ = i
  24125 	// No need to add the extra cost for length and distance as it is a constant
  24126 	// that does not influence the histograms.
  24127 	i = 0
  24128 	for {
  24129 		if !(i < int32(5)) {
  24130 			break
  24131 		}
  24132 		GetPopulationInfo(tls, h, i, bp, bp+8)
  24133 		**(**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))
  24134 		goto _1
  24135 	_1:
  24136 		;
  24137 		i = i + 1
  24138 	}
  24139 	(*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))
  24140 }
  24141 
  24142 func GetBinIdForEntropy(tls *libc.TLS, min uint64_t, max uint64_t, val uint64_t) (r int32) {
  24143 	var delta, range1 uint64_t
  24144 	_, _ = delta, range1
  24145 	range1 = max - min
  24146 	if range1 > uint64(0) {
  24147 		delta = val - min
  24148 		return int32(float64((libc.Float64FromInt32(NUM_PARTITIONS)-libc.Float64FromFloat64(1e-06))*float64(delta)) / float64(range1))
  24149 	} else {
  24150 		return 0
  24151 	}
  24152 	return r
  24153 }
  24154 
  24155 func GetHistoBinIndex(tls *libc.TLS, h uintptr, c uintptr, low_effort int32) (r int32) {
  24156 	var bin_id int32
  24157 	_ = bin_id
  24158 	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)))
  24159 	if !(low_effort != 0) {
  24160 		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)))
  24161 		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)))
  24162 	}
  24163 	return bin_id
  24164 }
  24165 
  24166 // C documentation
  24167 //
  24168 //	// Construct the histograms from backward references.
  24169 func HistogramBuild(tls *libc.TLS, xsize int32, histo_bits int32, backward_refs uintptr, image_histo uintptr) {
  24170 	bp := tls.Alloc(32)
  24171 	defer tls.Free(32)
  24172 	var histo_xsize, ix, x, y, v4 int32
  24173 	var histograms, v, v10, v8, v9 uintptr
  24174 	var v1, v2 uint32_t
  24175 	var _ /* c at bp+0 */ VP8LRefsCursor
  24176 	_, _, _, _, _, _, _, _, _, _, _, _ = histo_xsize, histograms, ix, v, x, y, v1, v10, v2, v4, v8, v9
  24177 	x = 0
  24178 	y = 0
  24179 	v1 = uint32(histo_bits)
  24180 	v2 = (uint32(xsize) + uint32(libc.Int32FromInt32(1)<<v1) - uint32(1)) >> v1
  24181 	goto _3
  24182 _3:
  24183 	histo_xsize = int32(v2)
  24184 	histograms = (*VP8LHistogramSet)(unsafe.Pointer(image_histo)).Fhistograms
  24185 	**(**VP8LRefsCursor)(__ccgo_up(bp)) = VP8LRefsCursorInit(tls, backward_refs)
  24186 	VP8LHistogramSetClear(tls, image_histo)
  24187 	for {
  24188 		v4 = libc.BoolInt32((*VP8LRefsCursor)(unsafe.Pointer(bp)).Fcur_pos != libc.UintptrFromInt32(0))
  24189 		goto _5
  24190 	_5:
  24191 		if !(v4 != 0) {
  24192 			break
  24193 		}
  24194 		v = (**(**VP8LRefsCursor)(__ccgo_up(bp))).Fcur_pos
  24195 		ix = y>>histo_bits*histo_xsize + x>>histo_bits
  24196 		HistogramAddSinglePixOrCopy(tls, **(**uintptr)(__ccgo_up(histograms + uintptr(ix)*8)), v, libc.UintptrFromInt32(0), 0)
  24197 		v1 = uint32((*PixOrCopy)(unsafe.Pointer(v)).Flen1)
  24198 		goto _7
  24199 	_7:
  24200 		x = int32(uint32(x) + v1)
  24201 		for x >= xsize {
  24202 			x = x - xsize
  24203 			y = y + 1
  24204 		}
  24205 		v8 = bp
  24206 		v10 = v8
  24207 		*(*uintptr)(unsafe.Pointer(v10)) += 8
  24208 		v9 = *(*uintptr)(unsafe.Pointer(v10))
  24209 		if v9 == (*VP8LRefsCursor)(unsafe.Pointer(v8)).Flast_pos {
  24210 			VP8LRefsCursorNextBlock(tls, v8)
  24211 		}
  24212 	}
  24213 }
  24214 
  24215 // C documentation
  24216 //
  24217 //	// Copies the histograms and computes its bit_cost.
  24218 func HistogramCopyAndAnalyze(tls *libc.TLS, orig_histo uintptr, image_histo uintptr) {
  24219 	var histo, histograms, orig_histograms uintptr
  24220 	var i int32
  24221 	_, _, _, _ = histo, histograms, i, orig_histograms
  24222 	orig_histograms = (*VP8LHistogramSet)(unsafe.Pointer(orig_histo)).Fhistograms
  24223 	histograms = (*VP8LHistogramSet)(unsafe.Pointer(image_histo)).Fhistograms
  24224 	(*VP8LHistogramSet)(unsafe.Pointer(image_histo)).Fsize = 0
  24225 	i = 0
  24226 	for {
  24227 		if !(i < (*VP8LHistogramSet)(unsafe.Pointer(orig_histo)).Fmax_size) {
  24228 			break
  24229 		}
  24230 		histo = **(**uintptr)(__ccgo_up(orig_histograms + uintptr(i)*8))
  24231 		ComputeHistogramCost(tls, histo)
  24232 		// Skip the histogram if it is completely empty, which can happen for tiles
  24233 		// with no information (when they are skipped because of LZ77).
  24234 		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) {
  24235 			// The first histogram is always used.
  24236 			**(**uintptr)(__ccgo_up(orig_histograms + uintptr(i)*8)) = libc.UintptrFromInt32(0)
  24237 		} else {
  24238 			// Copy histograms from orig_histo[] to image_histo[].
  24239 			HistogramCopy(tls, histo, **(**uintptr)(__ccgo_up(histograms + uintptr((*VP8LHistogramSet)(unsafe.Pointer(image_histo)).Fsize)*8)))
  24240 			(*VP8LHistogramSet)(unsafe.Pointer(image_histo)).Fsize = (*VP8LHistogramSet)(unsafe.Pointer(image_histo)).Fsize + 1
  24241 		}
  24242 		goto _1
  24243 	_1:
  24244 		;
  24245 		i = i + 1
  24246 	}
  24247 }
  24248 
  24249 // C documentation
  24250 //
  24251 //	// Partition histograms to different entropy bins for three dominant (literal,
  24252 //	// red and blue) symbol costs and compute the histogram aggregate bit_cost.
  24253 func HistogramAnalyzeEntropyBin(tls *libc.TLS, image_histo uintptr, low_effort int32) {
  24254 	bp := tls.Alloc(48)
  24255 	defer tls.Free(48)
  24256 	var histo_size, i int32
  24257 	var histograms uintptr
  24258 	var _ /* cost_range at bp+0 */ DominantCostRange
  24259 	_, _, _ = histo_size, histograms, i
  24260 	histograms = (*VP8LHistogramSet)(unsafe.Pointer(image_histo)).Fhistograms
  24261 	histo_size = (*VP8LHistogramSet)(unsafe.Pointer(image_histo)).Fsize
  24262 	DominantCostRangeInit(tls, bp)
  24263 	// Analyze the dominant (literal, red and blue) entropy costs.
  24264 	i = 0
  24265 	for {
  24266 		if !(i < histo_size) {
  24267 			break
  24268 		}
  24269 		UpdateDominantCostRange(tls, **(**uintptr)(__ccgo_up(histograms + uintptr(i)*8)), bp)
  24270 		goto _1
  24271 	_1:
  24272 		;
  24273 		i = i + 1
  24274 	}
  24275 	// bin-hash histograms on three of the dominant (literal, red and blue)
  24276 	// symbol costs and store the resulting bin_id for each histogram.
  24277 	i = 0
  24278 	for {
  24279 		if !(i < histo_size) {
  24280 			break
  24281 		}
  24282 		(*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))
  24283 		goto _2
  24284 	_2:
  24285 		;
  24286 		i = i + 1
  24287 	}
  24288 }
  24289 
  24290 // C documentation
  24291 //
  24292 //	// Merges some histograms with same bin_id together if it's advantageous.
  24293 //	// Sets the remaining histograms to NULL.
  24294 //	// 'combine_cost_factor' has to be divided by 100.
  24295 func HistogramCombineEntropyBin(tls *libc.TLS, image_histo uintptr, _cur_combo uintptr, num_bins int32, combine_cost_factor int32_t, low_effort int32) {
  24296 	bp := tls.Alloc(16)
  24297 	defer tls.Free(16)
  24298 	*(*uintptr)(unsafe.Pointer(bp)) = _cur_combo
  24299 	var bin_id, first, idx, max_combine_failures, try_combine int32
  24300 	var bin_info [64]struct {
  24301 		Ffirst                int16_t
  24302 		Fnum_combine_failures uint16_t
  24303 	}
  24304 	var bit_cost uint64_t
  24305 	var bit_cost_thresh, v3, v4, v5 int64_t
  24306 	var histograms uintptr
  24307 	var v7 int64
  24308 	_, _, _, _, _, _, _, _, _, _, _, _, _ = bin_id, bin_info, bit_cost, bit_cost_thresh, first, histograms, idx, max_combine_failures, try_combine, v3, v4, v5, v7
  24309 	histograms = (*VP8LHistogramSet)(unsafe.Pointer(image_histo)).Fhistograms
  24310 	idx = 0
  24311 	for {
  24312 		if !(idx < num_bins) {
  24313 			break
  24314 		}
  24315 		bin_info[idx].Ffirst = int16(-int32(1))
  24316 		bin_info[idx].Fnum_combine_failures = uint16(0)
  24317 		goto _1
  24318 	_1:
  24319 		;
  24320 		idx = idx + 1
  24321 	}
  24322 	idx = 0
  24323 	for {
  24324 		if !(idx < (*VP8LHistogramSet)(unsafe.Pointer(image_histo)).Fsize) {
  24325 			break
  24326 		}
  24327 		bin_id = int32((*VP8LHistogram)(unsafe.Pointer(**(**uintptr)(__ccgo_up(histograms + uintptr(idx)*8)))).Fbin_id)
  24328 		first = int32(bin_info[bin_id].Ffirst)
  24329 		if first == -int32(1) {
  24330 			bin_info[bin_id].Ffirst = int16(idx)
  24331 			idx = idx + 1
  24332 		} else {
  24333 			if low_effort != 0 {
  24334 				HistogramAdd(tls, **(**uintptr)(__ccgo_up(histograms + uintptr(idx)*8)), **(**uintptr)(__ccgo_up(histograms + uintptr(first)*8)), **(**uintptr)(__ccgo_up(histograms + uintptr(first)*8)))
  24335 				HistogramSetRemoveHistogram(tls, image_histo, idx)
  24336 			} else {
  24337 				// try to merge #idx into #first (both share the same bin_id)
  24338 				bit_cost = (*VP8LHistogram)(unsafe.Pointer(**(**uintptr)(__ccgo_up(histograms + uintptr(idx)*8)))).Fbit_cost
  24339 				v3 = int64(bit_cost) * int64(combine_cost_factor)
  24340 				v4 = int64(100)
  24341 				if libc.BoolInt32(v3 < 0) == libc.BoolInt32(v4 < 0) {
  24342 					v7 = (v3 + v4/int64(2)) / v4
  24343 				} else {
  24344 					v7 = (v3 - v4/int64(2)) / v4
  24345 				}
  24346 				v5 = v7
  24347 				goto _6
  24348 			_6:
  24349 				bit_cost_thresh = -v5
  24350 				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 {
  24351 					max_combine_failures = int32(32)
  24352 					// Try to merge two histograms only if the combo is a trivial one or
  24353 					// the two candidate histograms are already non-trivial.
  24354 					// For some images, 'try_combine' turns out to be false for a lot of
  24355 					// histogram pairs. In that case, we fallback to combining
  24356 					// histograms as usual to avoid increasing the header size.
  24357 					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))))
  24358 					if !(try_combine != 0) {
  24359 						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))))
  24360 						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))))
  24361 					}
  24362 					if try_combine != 0 || int32(bin_info[bin_id].Fnum_combine_failures) >= max_combine_failures {
  24363 						// move the (better) merged histogram to its final slot
  24364 						HistogramSwap(tls, bp, histograms+uintptr(first)*8)
  24365 						HistogramSetRemoveHistogram(tls, image_histo, idx)
  24366 					} else {
  24367 						bin_info[bin_id].Fnum_combine_failures = bin_info[bin_id].Fnum_combine_failures + 1
  24368 						idx = idx + 1
  24369 					}
  24370 				} else {
  24371 					idx = idx + 1
  24372 				}
  24373 			}
  24374 		}
  24375 		goto _2
  24376 	_2:
  24377 	}
  24378 	if low_effort != 0 {
  24379 		// for low_effort case, update the final cost when everything is merged
  24380 		idx = 0
  24381 		for {
  24382 			if !(idx < (*VP8LHistogramSet)(unsafe.Pointer(image_histo)).Fsize) {
  24383 				break
  24384 			}
  24385 			ComputeHistogramCost(tls, **(**uintptr)(__ccgo_up(histograms + uintptr(idx)*8)))
  24386 			goto _8
  24387 		_8:
  24388 			;
  24389 			idx = idx + 1
  24390 		}
  24391 	}
  24392 }
  24393 
  24394 // C documentation
  24395 //
  24396 //	// Implement a Lehmer random number generator with a multiplicative constant of
  24397 //	// 48271 and a modulo constant of 2^31 - 1.
  24398 func MyRand(tls *libc.TLS, seed uintptr) (r uint32_t) {
  24399 	**(**uint32_t)(__ccgo_up(seed)) = uint32(uint64(**(**uint32_t)(__ccgo_up(seed))) * libc.Uint64FromUint32(48271) % libc.Uint64FromUint32(2147483647))
  24400 	return **(**uint32_t)(__ccgo_up(seed))
  24401 }
  24402 
  24403 // -----------------------------------------------------------------------------
  24404 // Histogram pairs priority queue
  24405 
  24406 // C documentation
  24407 //
  24408 //	// Pair of histograms. Negative idx1 value means that pair is out-of-date.
  24409 type HistogramPair = struct {
  24410 	Fidx1       int32
  24411 	Fidx2       int32
  24412 	Fcost_diff  int64_t
  24413 	Fcost_combo uint64_t
  24414 	Fcosts      [5]uint64_t
  24415 }
  24416 
  24417 type HistoQueue = struct {
  24418 	Fqueue    uintptr
  24419 	Fsize     int32
  24420 	Fmax_size int32
  24421 }
  24422 
  24423 func HistoQueueInit(tls *libc.TLS, histo_queue uintptr, max_size int32) (r int32) {
  24424 	(*HistoQueue)(unsafe.Pointer(histo_queue)).Fsize = 0
  24425 	(*HistoQueue)(unsafe.Pointer(histo_queue)).Fmax_size = max_size
  24426 	// We allocate max_size + 1 because the last element at index "size" is
  24427 	// used as temporary data (and it could be up to max_size).
  24428 	(*HistoQueue)(unsafe.Pointer(histo_queue)).Fqueue = WebPSafeMalloc(tls, uint64((*HistoQueue)(unsafe.Pointer(histo_queue)).Fmax_size+int32(1)), uint64(64))
  24429 	return libc.BoolInt32((*HistoQueue)(unsafe.Pointer(histo_queue)).Fqueue != libc.UintptrFromInt32(0))
  24430 }
  24431 
  24432 func HistoQueueClear(tls *libc.TLS, histo_queue uintptr) {
  24433 	WebPSafeFree(tls, (*HistoQueue)(unsafe.Pointer(histo_queue)).Fqueue)
  24434 	(*HistoQueue)(unsafe.Pointer(histo_queue)).Fsize = 0
  24435 	(*HistoQueue)(unsafe.Pointer(histo_queue)).Fmax_size = 0
  24436 }
  24437 
  24438 // C documentation
  24439 //
  24440 //	// Pop a specific pair in the queue by replacing it with the last one
  24441 //	// and shrinking the queue.
  24442 func HistoQueuePopPair(tls *libc.TLS, histo_queue uintptr, pair uintptr) {
  24443 	**(**HistogramPair)(__ccgo_up(pair)) = **(**HistogramPair)(__ccgo_up((*HistoQueue)(unsafe.Pointer(histo_queue)).Fqueue + uintptr((*HistoQueue)(unsafe.Pointer(histo_queue)).Fsize-int32(1))*64))
  24444 	(*HistoQueue)(unsafe.Pointer(histo_queue)).Fsize = (*HistoQueue)(unsafe.Pointer(histo_queue)).Fsize - 1
  24445 }
  24446 
  24447 // C documentation
  24448 //
  24449 //	// Check whether a pair in the queue should be updated as head or not.
  24450 func HistoQueueUpdateHead(tls *libc.TLS, histo_queue uintptr, pair uintptr) {
  24451 	var tmp HistogramPair
  24452 	_ = tmp
  24453 	if (*HistogramPair)(unsafe.Pointer(pair)).Fcost_diff < (**(**HistogramPair)(__ccgo_up((*HistoQueue)(unsafe.Pointer(histo_queue)).Fqueue))).Fcost_diff {
  24454 		// Replace the best pair.
  24455 		tmp = **(**HistogramPair)(__ccgo_up((*HistoQueue)(unsafe.Pointer(histo_queue)).Fqueue))
  24456 		**(**HistogramPair)(__ccgo_up((*HistoQueue)(unsafe.Pointer(histo_queue)).Fqueue)) = **(**HistogramPair)(__ccgo_up(pair))
  24457 		**(**HistogramPair)(__ccgo_up(pair)) = tmp
  24458 	}
  24459 }
  24460 
  24461 // C documentation
  24462 //
  24463 //	// Replaces the bad_id with good_id in the pair.
  24464 func HistoQueueFixPair(tls *libc.TLS, bad_id int32, good_id int32, pair uintptr) {
  24465 	var tmp int32
  24466 	_ = tmp
  24467 	if (*HistogramPair)(unsafe.Pointer(pair)).Fidx1 == bad_id {
  24468 		(*HistogramPair)(unsafe.Pointer(pair)).Fidx1 = good_id
  24469 	}
  24470 	if (*HistogramPair)(unsafe.Pointer(pair)).Fidx2 == bad_id {
  24471 		(*HistogramPair)(unsafe.Pointer(pair)).Fidx2 = good_id
  24472 	}
  24473 	if (*HistogramPair)(unsafe.Pointer(pair)).Fidx1 > (*HistogramPair)(unsafe.Pointer(pair)).Fidx2 {
  24474 		tmp = (*HistogramPair)(unsafe.Pointer(pair)).Fidx1
  24475 		(*HistogramPair)(unsafe.Pointer(pair)).Fidx1 = (*HistogramPair)(unsafe.Pointer(pair)).Fidx2
  24476 		(*HistogramPair)(unsafe.Pointer(pair)).Fidx2 = tmp
  24477 	}
  24478 }
  24479 
  24480 // C documentation
  24481 //
  24482 //	// Update the cost diff and combo of a pair of histograms. This needs to be
  24483 //	// called when the histograms have been merged with a third one.
  24484 //	// Returns 1 if the cost diff is less than the threshold.
  24485 //	// Otherwise returns 0 and the cost is invalid due to early bail-out.
  24486 func HistoQueueUpdatePair(tls *libc.TLS, h1 uintptr, h2 uintptr, _cost_threshold int64_t, pair uintptr) (r int32) {
  24487 	bp := tls.Alloc(16)
  24488 	defer tls.Free(16)
  24489 	*(*int64_t)(unsafe.Pointer(bp)) = _cost_threshold
  24490 	var sum_cost int64_t
  24491 	_ = sum_cost
  24492 	sum_cost = int64((*VP8LHistogram)(unsafe.Pointer(h1)).Fbit_cost + (*VP8LHistogram)(unsafe.Pointer(h2)).Fbit_cost)
  24493 	SaturateAdd(tls, uint64(sum_cost), bp)
  24494 	if !(GetCombinedHistogramEntropy(tls, h1, h2, **(**int64_t)(__ccgo_up(bp)), pair+16, pair+24) != 0) {
  24495 		return 0
  24496 	}
  24497 	(*HistogramPair)(unsafe.Pointer(pair)).Fcost_diff = int64((*HistogramPair)(unsafe.Pointer(pair)).Fcost_combo) - sum_cost
  24498 	return int32(1)
  24499 }
  24500 
  24501 // C documentation
  24502 //
  24503 //	// Create a pair from indices "idx1" and "idx2" provided its cost
  24504 //	// is inferior to "threshold", a negative entropy.
  24505 //	// It returns the cost of the pair, or 0 if it superior to threshold.
  24506 func HistoQueuePush(tls *libc.TLS, histo_queue uintptr, histograms uintptr, idx1 int32, idx2 int32, threshold int64_t) (r int64_t) {
  24507 	bp := tls.Alloc(64)
  24508 	defer tls.Free(64)
  24509 	var h1, h2, v2 uintptr
  24510 	var tmp, v1 int32
  24511 	var _ /* pair at bp+0 */ HistogramPair
  24512 	_, _, _, _, _ = h1, h2, tmp, v1, v2
  24513 	// Stop here if the queue is full.
  24514 	if (*HistoQueue)(unsafe.Pointer(histo_queue)).Fsize == (*HistoQueue)(unsafe.Pointer(histo_queue)).Fmax_size {
  24515 		return 0
  24516 	}
  24517 	if idx1 > idx2 {
  24518 		tmp = idx2
  24519 		idx2 = idx1
  24520 		idx1 = tmp
  24521 	}
  24522 	(**(**HistogramPair)(__ccgo_up(bp))).Fidx1 = idx1
  24523 	(**(**HistogramPair)(__ccgo_up(bp))).Fidx2 = idx2
  24524 	h1 = **(**uintptr)(__ccgo_up(histograms + uintptr(idx1)*8))
  24525 	h2 = **(**uintptr)(__ccgo_up(histograms + uintptr(idx2)*8))
  24526 	// Do not even consider the pair if it does not improve the entropy.
  24527 	if !(HistoQueueUpdatePair(tls, h1, h2, threshold, bp) != 0) {
  24528 		return 0
  24529 	}
  24530 	v2 = histo_queue + 8
  24531 	v1 = *(*int32)(unsafe.Pointer(v2))
  24532 	*(*int32)(unsafe.Pointer(v2)) = *(*int32)(unsafe.Pointer(v2)) + 1
  24533 	**(**HistogramPair)(__ccgo_up((*HistoQueue)(unsafe.Pointer(histo_queue)).Fqueue + uintptr(v1)*64)) = **(**HistogramPair)(__ccgo_up(bp))
  24534 	HistoQueueUpdateHead(tls, histo_queue, (*HistoQueue)(unsafe.Pointer(histo_queue)).Fqueue+uintptr((*HistoQueue)(unsafe.Pointer(histo_queue)).Fsize-int32(1))*64)
  24535 	return (**(**HistogramPair)(__ccgo_up(bp))).Fcost_diff
  24536 }
  24537 
  24538 // -----------------------------------------------------------------------------
  24539 
  24540 // C documentation
  24541 //
  24542 //	// Combines histograms by continuously choosing the one with the highest cost
  24543 //	// reduction.
  24544 func HistogramCombineGreedy(tls *libc.TLS, image_histo uintptr) (r int32) {
  24545 	bp := tls.Alloc(16)
  24546 	defer tls.Free(16)
  24547 	var histograms, p uintptr
  24548 	var i, idx1, idx2, image_histo_size, j, ok int32
  24549 	var _ /* histo_queue at bp+0 */ HistoQueue
  24550 	_, _, _, _, _, _, _, _ = histograms, i, idx1, idx2, image_histo_size, j, ok, p
  24551 	ok = 0
  24552 	image_histo_size = (*VP8LHistogramSet)(unsafe.Pointer(image_histo)).Fsize
  24553 	histograms = (*VP8LHistogramSet)(unsafe.Pointer(image_histo)).Fhistograms
  24554 	// image_histo_size^2 for the queue size is safe. If you look at
  24555 	// HistogramCombineGreedy, and imagine that UpdateQueueFront always pushes
  24556 	// data to the queue, you insert at most:
  24557 	// - image_histo_size*(image_histo_size-1)/2 (the first two for loops)
  24558 	// - image_histo_size - 1 in the last for loop at the first iteration of
  24559 	//   the while loop, image_histo_size - 2 at the second iteration ...
  24560 	//   therefore image_histo_size*(image_histo_size-1)/2 overall too
  24561 	if !(HistoQueueInit(tls, bp, image_histo_size*image_histo_size) != 0) {
  24562 		goto End
  24563 	}
  24564 	// Initialize the queue.
  24565 	i = 0
  24566 	for {
  24567 		if !(i < image_histo_size) {
  24568 			break
  24569 		}
  24570 		j = i + int32(1)
  24571 		for {
  24572 			if !(j < image_histo_size) {
  24573 				break
  24574 			}
  24575 			HistoQueuePush(tls, bp, histograms, i, j, 0)
  24576 			goto _2
  24577 		_2:
  24578 			;
  24579 			j = j + 1
  24580 		}
  24581 		goto _1
  24582 	_1:
  24583 		;
  24584 		i = i + 1
  24585 	}
  24586 	for (**(**HistoQueue)(__ccgo_up(bp))).Fsize > 0 {
  24587 		idx1 = (**(**HistogramPair)(__ccgo_up((**(**HistoQueue)(__ccgo_up(bp))).Fqueue))).Fidx1
  24588 		idx2 = (**(**HistogramPair)(__ccgo_up((**(**HistoQueue)(__ccgo_up(bp))).Fqueue))).Fidx2
  24589 		HistogramAdd(tls, **(**uintptr)(__ccgo_up(histograms + uintptr(idx2)*8)), **(**uintptr)(__ccgo_up(histograms + uintptr(idx1)*8)), **(**uintptr)(__ccgo_up(histograms + uintptr(idx1)*8)))
  24590 		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)))
  24591 		// Remove merged histogram.
  24592 		HistogramSetRemoveHistogram(tls, image_histo, idx2)
  24593 		// Remove pairs intersecting the just combined best pair.
  24594 		i = 0
  24595 		for {
  24596 			if !(i < (**(**HistoQueue)(__ccgo_up(bp))).Fsize) {
  24597 				break
  24598 			}
  24599 			p = (**(**HistoQueue)(__ccgo_up(bp))).Fqueue + uintptr(i)*64
  24600 			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 {
  24601 				HistoQueuePopPair(tls, bp, p)
  24602 			} else {
  24603 				HistoQueueFixPair(tls, (*VP8LHistogramSet)(unsafe.Pointer(image_histo)).Fsize, idx2, p)
  24604 				HistoQueueUpdateHead(tls, bp, p)
  24605 				i = i + 1
  24606 			}
  24607 			goto _3
  24608 		_3:
  24609 		}
  24610 		// Push new pairs formed with combined histogram to the queue.
  24611 		i = 0
  24612 		for {
  24613 			if !(i < (*VP8LHistogramSet)(unsafe.Pointer(image_histo)).Fsize) {
  24614 				break
  24615 			}
  24616 			if i == idx1 {
  24617 				goto _4
  24618 			}
  24619 			HistoQueuePush(tls, bp, (*VP8LHistogramSet)(unsafe.Pointer(image_histo)).Fhistograms, idx1, i, 0)
  24620 			goto _4
  24621 		_4:
  24622 			;
  24623 			i = i + 1
  24624 		}
  24625 	}
  24626 	ok = int32(1)
  24627 	goto End
  24628 End:
  24629 	;
  24630 	HistoQueueClear(tls, bp)
  24631 	return ok
  24632 }
  24633 
  24634 // C documentation
  24635 //
  24636 //	// Perform histogram aggregation using a stochastic approach.
  24637 //	// 'do_greedy' is set to 1 if a greedy approach needs to be performed
  24638 //	// afterwards, 0 otherwise.
  24639 func HistogramCombineStochastic(tls *libc.TLS, image_histo uintptr, min_cluster_size int32, do_greedy uintptr) (r int32) {
  24640 	bp := tls.Alloc(32)
  24641 	defer tls.Free(32)
  24642 	var best_cost, curr_cost int64_t
  24643 	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
  24644 	var histograms, p uintptr
  24645 	var idx1, idx2, rand_range, tmp uint32_t
  24646 	var v3 bool
  24647 	var v4 int64
  24648 	var _ /* histo_queue at bp+8 */ HistoQueue
  24649 	var _ /* seed at bp+0 */ uint32_t
  24650 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  24651 	**(**uint32_t)(__ccgo_up(bp)) = uint32(1)
  24652 	tries_with_no_success = 0
  24653 	outer_iters = (*VP8LHistogramSet)(unsafe.Pointer(image_histo)).Fsize
  24654 	num_tries_no_success = outer_iters / int32(2)
  24655 	histograms = (*VP8LHistogramSet)(unsafe.Pointer(image_histo)).Fhistograms
  24656 	kHistoQueueSize = int32(9)
  24657 	ok = 0
  24658 	if (*VP8LHistogramSet)(unsafe.Pointer(image_histo)).Fsize < min_cluster_size {
  24659 		**(**int32)(__ccgo_up(do_greedy)) = int32(1)
  24660 		return int32(1)
  24661 	}
  24662 	if !(HistoQueueInit(tls, bp+8, kHistoQueueSize) != 0) {
  24663 		goto End
  24664 	}
  24665 	// Collapse similar histograms in 'image_histo'.
  24666 	iter = 0
  24667 	for {
  24668 		if v3 = iter < outer_iters && (*VP8LHistogramSet)(unsafe.Pointer(image_histo)).Fsize >= min_cluster_size; v3 {
  24669 			tries_with_no_success = tries_with_no_success + 1
  24670 			v2 = tries_with_no_success
  24671 		}
  24672 		if !(v3 && v2 < num_tries_no_success) {
  24673 			break
  24674 		}
  24675 		if (**(**HistoQueue)(__ccgo_up(bp + 8))).Fsize == 0 {
  24676 			v4 = 0
  24677 		} else {
  24678 			v4 = (**(**HistogramPair)(__ccgo_up((**(**HistoQueue)(__ccgo_up(bp + 8))).Fqueue))).Fcost_diff
  24679 		}
  24680 		best_cost = v4
  24681 		best_idx1 = -int32(1)
  24682 		best_idx2 = int32(1)
  24683 		rand_range = uint32(((*VP8LHistogramSet)(unsafe.Pointer(image_histo)).Fsize - int32(1)) * (*VP8LHistogramSet)(unsafe.Pointer(image_histo)).Fsize)
  24684 		// (image_histo->size) / 2 was chosen empirically. Less means faster but
  24685 		// worse compression.
  24686 		num_tries = (*VP8LHistogramSet)(unsafe.Pointer(image_histo)).Fsize / int32(2)
  24687 		// Pick random samples.
  24688 		j = 0
  24689 		for {
  24690 			if !((*VP8LHistogramSet)(unsafe.Pointer(image_histo)).Fsize >= int32(2) && j < num_tries) {
  24691 				break
  24692 			}
  24693 			// Choose two different histograms at random and try to combine them.
  24694 			tmp = MyRand(tls, bp) % rand_range
  24695 			idx1 = tmp / uint32((*VP8LHistogramSet)(unsafe.Pointer(image_histo)).Fsize-libc.Int32FromInt32(1))
  24696 			idx2 = tmp % uint32((*VP8LHistogramSet)(unsafe.Pointer(image_histo)).Fsize-libc.Int32FromInt32(1))
  24697 			if idx2 >= idx1 {
  24698 				idx2 = idx2 + 1
  24699 			}
  24700 			// Calculate cost reduction on combination.
  24701 			curr_cost = HistoQueuePush(tls, bp+8, histograms, int32(idx1), int32(idx2), best_cost)
  24702 			if curr_cost < 0 { // found a better pair?
  24703 				best_cost = curr_cost
  24704 				// Empty the queue if we reached full capacity.
  24705 				if (**(**HistoQueue)(__ccgo_up(bp + 8))).Fsize == (**(**HistoQueue)(__ccgo_up(bp + 8))).Fmax_size {
  24706 					break
  24707 				}
  24708 			}
  24709 			goto _5
  24710 		_5:
  24711 			;
  24712 			j = j + 1
  24713 		}
  24714 		if (**(**HistoQueue)(__ccgo_up(bp + 8))).Fsize == 0 {
  24715 			goto _1
  24716 		}
  24717 		// Get the best histograms.
  24718 		best_idx1 = (**(**HistogramPair)(__ccgo_up((**(**HistoQueue)(__ccgo_up(bp + 8))).Fqueue))).Fidx1
  24719 		best_idx2 = (**(**HistogramPair)(__ccgo_up((**(**HistoQueue)(__ccgo_up(bp + 8))).Fqueue))).Fidx2
  24720 		// Merge the histograms and remove best_idx2 from the queue.
  24721 		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)))
  24722 		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)))
  24723 		HistogramSetRemoveHistogram(tls, image_histo, best_idx2)
  24724 		// Parse the queue and update each pair that deals with best_idx1,
  24725 		// best_idx2 or image_histo_size.
  24726 		j = 0
  24727 		for {
  24728 			if !(j < (**(**HistoQueue)(__ccgo_up(bp + 8))).Fsize) {
  24729 				break
  24730 			}
  24731 			p = (**(**HistoQueue)(__ccgo_up(bp + 8))).Fqueue + uintptr(j)*64
  24732 			is_idx1_best = libc.BoolInt32((*HistogramPair)(unsafe.Pointer(p)).Fidx1 == best_idx1 || (*HistogramPair)(unsafe.Pointer(p)).Fidx1 == best_idx2)
  24733 			is_idx2_best = libc.BoolInt32((*HistogramPair)(unsafe.Pointer(p)).Fidx2 == best_idx1 || (*HistogramPair)(unsafe.Pointer(p)).Fidx2 == best_idx2)
  24734 			// The front pair could have been duplicated by a random pick so
  24735 			// check for it all the time nevertheless.
  24736 			if is_idx1_best != 0 && is_idx2_best != 0 {
  24737 				HistoQueuePopPair(tls, bp+8, p)
  24738 				goto _6
  24739 			}
  24740 			// Any pair containing one of the two best indices should only refer to
  24741 			// best_idx1. Its cost should also be updated.
  24742 			if is_idx1_best != 0 || is_idx2_best != 0 {
  24743 				HistoQueueFixPair(tls, best_idx2, best_idx1, p)
  24744 				// Re-evaluate the cost of an updated pair.
  24745 				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) {
  24746 					HistoQueuePopPair(tls, bp+8, p)
  24747 					goto _6
  24748 				}
  24749 			}
  24750 			HistoQueueFixPair(tls, (*VP8LHistogramSet)(unsafe.Pointer(image_histo)).Fsize, best_idx2, p)
  24751 			HistoQueueUpdateHead(tls, bp+8, p)
  24752 			j = j + 1
  24753 			goto _6
  24754 		_6:
  24755 		}
  24756 		tries_with_no_success = 0
  24757 		goto _1
  24758 	_1:
  24759 		;
  24760 		iter = iter + 1
  24761 	}
  24762 	**(**int32)(__ccgo_up(do_greedy)) = libc.BoolInt32((*VP8LHistogramSet)(unsafe.Pointer(image_histo)).Fsize <= min_cluster_size)
  24763 	ok = int32(1)
  24764 	goto End
  24765 End:
  24766 	;
  24767 	HistoQueueClear(tls, bp+8)
  24768 	return ok
  24769 }
  24770 
  24771 // -----------------------------------------------------------------------------
  24772 // Histogram refinement
  24773 
  24774 // C documentation
  24775 //
  24776 //	// Find the best 'out' histogram for each of the 'in' histograms.
  24777 //	// At call-time, 'out' contains the histograms of the clusters.
  24778 //	// Note: we assume that out[]->bit_cost is already up-to-date.
  24779 func HistogramRemap(tls *libc.TLS, in uintptr, out uintptr, symbols uintptr) {
  24780 	bp := tls.Alloc(16)
  24781 	defer tls.Free(16)
  24782 	var best_bits int64_t
  24783 	var best_out, i, idx, in_size, k, out_size int32
  24784 	var in_histo, out_histo uintptr
  24785 	var _ /* cur_bits at bp+0 */ int64_t
  24786 	_, _, _, _, _, _, _, _, _ = best_bits, best_out, i, idx, in_histo, in_size, k, out_histo, out_size
  24787 	in_histo = (*VP8LHistogramSet)(unsafe.Pointer(in)).Fhistograms
  24788 	out_histo = (*VP8LHistogramSet)(unsafe.Pointer(out)).Fhistograms
  24789 	in_size = (*VP8LHistogramSet)(unsafe.Pointer(out)).Fmax_size
  24790 	out_size = (*VP8LHistogramSet)(unsafe.Pointer(out)).Fsize
  24791 	if out_size > int32(1) {
  24792 		i = 0
  24793 		for {
  24794 			if !(i < in_size) {
  24795 				break
  24796 			}
  24797 			best_out = 0
  24798 			best_bits = int64(libc.Uint64FromUint64(1)<<libc.Int32FromInt32(63) - libc.Uint64FromInt32(1))
  24799 			if **(**uintptr)(__ccgo_up(in_histo + uintptr(i)*8)) == libc.UintptrFromInt32(0) {
  24800 				// Arbitrarily set to the previous value if unused to help future LZ77.
  24801 				**(**uint32_t)(__ccgo_up(symbols + uintptr(i)*4)) = **(**uint32_t)(__ccgo_up(symbols + uintptr(i-int32(1))*4))
  24802 				goto _1
  24803 			}
  24804 			k = 0
  24805 			for {
  24806 				if !(k < out_size) {
  24807 					break
  24808 				}
  24809 				if HistogramAddThresh(tls, **(**uintptr)(__ccgo_up(out_histo + uintptr(k)*8)), **(**uintptr)(__ccgo_up(in_histo + uintptr(i)*8)), best_bits, bp) != 0 {
  24810 					best_bits = **(**int64_t)(__ccgo_up(bp))
  24811 					best_out = k
  24812 				}
  24813 				goto _2
  24814 			_2:
  24815 				;
  24816 				k = k + 1
  24817 			}
  24818 			**(**uint32_t)(__ccgo_up(symbols + uintptr(i)*4)) = uint32(best_out)
  24819 			goto _1
  24820 		_1:
  24821 			;
  24822 			i = i + 1
  24823 		}
  24824 	} else {
  24825 		i = 0
  24826 		for {
  24827 			if !(i < in_size) {
  24828 				break
  24829 			}
  24830 			**(**uint32_t)(__ccgo_up(symbols + uintptr(i)*4)) = uint32(0)
  24831 			goto _3
  24832 		_3:
  24833 			;
  24834 			i = i + 1
  24835 		}
  24836 	}
  24837 	// Recompute each out based on raw and symbols.
  24838 	VP8LHistogramSetClear(tls, out)
  24839 	(*VP8LHistogramSet)(unsafe.Pointer(out)).Fsize = out_size
  24840 	i = 0
  24841 	for {
  24842 		if !(i < in_size) {
  24843 			break
  24844 		}
  24845 		if **(**uintptr)(__ccgo_up(in_histo + uintptr(i)*8)) == libc.UintptrFromInt32(0) {
  24846 			goto _4
  24847 		}
  24848 		idx = int32(**(**uint32_t)(__ccgo_up(symbols + uintptr(i)*4)))
  24849 		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)))
  24850 		goto _4
  24851 	_4:
  24852 		;
  24853 		i = i + 1
  24854 	}
  24855 }
  24856 
  24857 func GetCombineCostFactor(tls *libc.TLS, histo_size int32, quality int32) (r int32_t) {
  24858 	var combine_cost_factor int32_t
  24859 	_ = combine_cost_factor
  24860 	combine_cost_factor = int32(16)
  24861 	if quality < int32(90) {
  24862 		if histo_size > int32(256) {
  24863 			combine_cost_factor = combine_cost_factor / int32(2)
  24864 		}
  24865 		if histo_size > int32(512) {
  24866 			combine_cost_factor = combine_cost_factor / int32(2)
  24867 		}
  24868 		if histo_size > int32(1024) {
  24869 			combine_cost_factor = combine_cost_factor / int32(2)
  24870 		}
  24871 		if quality <= int32(50) {
  24872 			combine_cost_factor = combine_cost_factor / int32(2)
  24873 		}
  24874 	}
  24875 	return combine_cost_factor
  24876 }
  24877 
  24878 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) {
  24879 	bp := tls.Alloc(16)
  24880 	defer tls.Free(16)
  24881 	var combine_cost_factor int32_t
  24882 	var entropy_combine, entropy_combine_num_bins, histo_xsize, histo_ysize, image_histo_raw_size, threshold_size, v9 int32
  24883 	var orig_histo uintptr
  24884 	var v1, v5 uint32
  24885 	var v10, v11, v12 int64_t
  24886 	var v14 int64
  24887 	var v2, v3, v6, v7 uint32_t
  24888 	var _ /* do_greedy at bp+0 */ int32
  24889 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  24890 	if histogram_bits != 0 {
  24891 		v2 = uint32(histogram_bits)
  24892 		v3 = (uint32(xsize) + uint32(libc.Int32FromInt32(1)<<v2) - uint32(1)) >> v2
  24893 		goto _4
  24894 	_4:
  24895 		v1 = v3
  24896 	} else {
  24897 		v1 = uint32(1)
  24898 	}
  24899 	histo_xsize = int32(v1)
  24900 	if histogram_bits != 0 {
  24901 		v6 = uint32(histogram_bits)
  24902 		v7 = (uint32(ysize) + uint32(libc.Int32FromInt32(1)<<v6) - uint32(1)) >> v6
  24903 		goto _8
  24904 	_8:
  24905 		v5 = v7
  24906 	} else {
  24907 		v5 = uint32(1)
  24908 	}
  24909 	histo_ysize = int32(v5)
  24910 	image_histo_raw_size = histo_xsize * histo_ysize
  24911 	orig_histo = VP8LAllocateHistogramSet(tls, image_histo_raw_size, cache_bits)
  24912 	if low_effort != 0 {
  24913 		v9 = int32(NUM_PARTITIONS)
  24914 	} else {
  24915 		v9 = libc.Int32FromInt32(NUM_PARTITIONS) * libc.Int32FromInt32(NUM_PARTITIONS) * libc.Int32FromInt32(NUM_PARTITIONS)
  24916 	}
  24917 	// Don't attempt linear bin-partition heuristic for
  24918 	// histograms of small sizes (as bin_map will be very sparse) and
  24919 	// maximum quality q==100 (to preserve the compression gains at that level).
  24920 	entropy_combine_num_bins = v9
  24921 	if orig_histo == libc.UintptrFromInt32(0) {
  24922 		WebPEncodingSetError(tls, pic, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  24923 		goto Error
  24924 	}
  24925 	// Construct the histograms from backward references.
  24926 	HistogramBuild(tls, xsize, histogram_bits, refs, orig_histo)
  24927 	HistogramCopyAndAnalyze(tls, orig_histo, image_histo)
  24928 	entropy_combine = libc.BoolInt32((*VP8LHistogramSet)(unsafe.Pointer(image_histo)).Fsize > entropy_combine_num_bins*int32(2) && quality < int32(100))
  24929 	if entropy_combine != 0 {
  24930 		combine_cost_factor = GetCombineCostFactor(tls, image_histo_raw_size, quality)
  24931 		HistogramAnalyzeEntropyBin(tls, image_histo, low_effort)
  24932 		// Collapse histograms with similar entropy.
  24933 		HistogramCombineEntropyBin(tls, image_histo, tmp_histo, entropy_combine_num_bins, combine_cost_factor, low_effort)
  24934 	}
  24935 	// Don't combine the histograms using stochastic and greedy heuristics for
  24936 	// low-effort compression mode.
  24937 	if !(low_effort != 0) || !(entropy_combine != 0) {
  24938 		v10 = int64(quality * quality * quality * (libc.Int32FromInt32(MAX_HISTO_GREEDY) - libc.Int32FromInt32(1)))
  24939 		v11 = int64(libc.Int32FromInt32(100) * libc.Int32FromInt32(100) * libc.Int32FromInt32(100))
  24940 		if libc.BoolInt32(v10 < 0) == libc.BoolInt32(v11 < 0) {
  24941 			v14 = (v10 + v11/int64(2)) / v11
  24942 		} else {
  24943 			v14 = (v10 - v11/int64(2)) / v11
  24944 		}
  24945 		v12 = v14
  24946 		goto _13
  24947 	_13:
  24948 		// cubic ramp between 1 and MAX_HISTO_GREEDY:
  24949 		threshold_size = int32(libc.Int64FromInt32(1) + v12)
  24950 		if !(HistogramCombineStochastic(tls, image_histo, threshold_size, bp) != 0) {
  24951 			WebPEncodingSetError(tls, pic, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  24952 			goto Error
  24953 		}
  24954 		if **(**int32)(__ccgo_up(bp)) != 0 {
  24955 			if !(HistogramCombineGreedy(tls, image_histo) != 0) {
  24956 				WebPEncodingSetError(tls, pic, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  24957 				goto Error
  24958 			}
  24959 		}
  24960 	}
  24961 	// Find the optimal map from original histograms to the final ones.
  24962 	HistogramRemap(tls, orig_histo, image_histo, histogram_symbols)
  24963 	if !(WebPReportProgress(tls, pic, **(**int32)(__ccgo_up(percent))+percent_range, percent) != 0) {
  24964 		goto Error
  24965 	}
  24966 	goto Error
  24967 Error:
  24968 	;
  24969 	VP8LFreeHistogramSet(tls, orig_histo)
  24970 	return libc.BoolInt32((*WebPPicture)(unsafe.Pointer(pic)).Ferror_code == int32(VP8_ENC_OK))
  24971 }
  24972 
  24973 const SIZE_MAX9 = "UINT64_MAX"
  24974 
  24975 //------------------------------------------------------------------------------
  24976 
  24977 // Copyright 2012 Google Inc. All Rights Reserved.
  24978 //
  24979 // Use of this source code is governed by a BSD-style license
  24980 // that can be found in the COPYING file in the root of the source
  24981 // tree. An additional intellectual property rights grant can be found
  24982 // in the file PATENTS. All contributing project authors may
  24983 // be found in the AUTHORS file in the root of the source tree.
  24984 // -----------------------------------------------------------------------------
  24985 //
  24986 // Misc. common utility functions
  24987 //
  24988 // Authors: Skal (pascal.massimino@gmail.com)
  24989 //          Urvang (urvang@google.com)
  24990 
  24991 // Copyright 2010 Google Inc. All Rights Reserved.
  24992 //
  24993 // Use of this source code is governed by a BSD-style license
  24994 // that can be found in the COPYING file in the root of the source
  24995 // tree. An additional intellectual property rights grant can be found
  24996 // in the file PATENTS. All contributing project authors may
  24997 // be found in the AUTHORS file in the root of the source tree.
  24998 // -----------------------------------------------------------------------------
  24999 //
  25000 //  Common types + memory wrappers
  25001 //
  25002 // Author: Skal (pascal.massimino@gmail.com)
  25003 
  25004 //------------------------------------------------------------------------------
  25005 // VP8Iterator
  25006 //------------------------------------------------------------------------------
  25007 
  25008 func InitLeft(tls *libc.TLS, it uintptr) {
  25009 	var v1, v2 uint8_t
  25010 	var v3 int32
  25011 	_, _, _ = v1, v2, v3
  25012 	if (*VP8EncIterator)(unsafe.Pointer(it)).Fy > 0 {
  25013 		v3 = int32(129)
  25014 	} else {
  25015 		v3 = int32(127)
  25016 	}
  25017 	v2 = uint8(v3)
  25018 	**(**uint8_t)(__ccgo_up((*VP8EncIterator)(unsafe.Pointer(it)).Fv_left + uintptr(-libc.Int32FromInt32(1)))) = v2
  25019 	v1 = v2
  25020 	**(**uint8_t)(__ccgo_up((*VP8EncIterator)(unsafe.Pointer(it)).Fu_left + uintptr(-libc.Int32FromInt32(1)))) = v1
  25021 	**(**uint8_t)(__ccgo_up((*VP8EncIterator)(unsafe.Pointer(it)).Fy_left + uintptr(-libc.Int32FromInt32(1)))) = v1
  25022 	libc.Xmemset(tls, (*VP8EncIterator)(unsafe.Pointer(it)).Fy_left, int32(129), uint64(16))
  25023 	libc.Xmemset(tls, (*VP8EncIterator)(unsafe.Pointer(it)).Fu_left, int32(129), uint64(8))
  25024 	libc.Xmemset(tls, (*VP8EncIterator)(unsafe.Pointer(it)).Fv_left, int32(129), uint64(8))
  25025 	**(**int32)(__ccgo_up(it + 168 + 8*4)) = 0
  25026 	if (*VP8EncIterator)(unsafe.Pointer(it)).Ftop_derr != libc.UintptrFromInt32(0) {
  25027 		libc.Xmemset(tls, it+344, 0, uint64(4))
  25028 	}
  25029 }
  25030 
  25031 func InitTop(tls *libc.TLS, it uintptr) {
  25032 	var enc uintptr
  25033 	var top_size size_t
  25034 	_, _ = enc, top_size
  25035 	enc = (*VP8EncIterator)(unsafe.Pointer(it)).Fenc
  25036 	top_size = uint64((*VP8Encoder)(unsafe.Pointer(enc)).Fmb_w * int32(16))
  25037 	libc.Xmemset(tls, (*VP8Encoder)(unsafe.Pointer(enc)).Fy_top, int32(127), uint64(2)*top_size)
  25038 	libc.Xmemset(tls, (*VP8Encoder)(unsafe.Pointer(enc)).Fnz, 0, uint64((*VP8Encoder)(unsafe.Pointer(enc)).Fmb_w)*uint64(4))
  25039 	if (*VP8Encoder)(unsafe.Pointer(enc)).Ftop_derr != libc.UintptrFromInt32(0) {
  25040 		libc.Xmemset(tls, (*VP8Encoder)(unsafe.Pointer(enc)).Ftop_derr, 0, uint64((*VP8Encoder)(unsafe.Pointer(enc)).Fmb_w)*uint64(4))
  25041 	}
  25042 }
  25043 
  25044 func VP8IteratorSetRow(tls *libc.TLS, it uintptr, y int32) {
  25045 	var enc uintptr
  25046 	_ = enc
  25047 	enc = (*VP8EncIterator)(unsafe.Pointer(it)).Fenc
  25048 	(*VP8EncIterator)(unsafe.Pointer(it)).Fx = 0
  25049 	(*VP8EncIterator)(unsafe.Pointer(it)).Fy = y
  25050 	(*VP8EncIterator)(unsafe.Pointer(it)).Fbw = enc + 112 + uintptr(y&((*VP8Encoder)(unsafe.Pointer(enc)).Fnum_parts-int32(1)))*48
  25051 	(*VP8EncIterator)(unsafe.Pointer(it)).Fpreds = (*VP8Encoder)(unsafe.Pointer(enc)).Fpreds + uintptr(y*int32(4)*(*VP8Encoder)(unsafe.Pointer(enc)).Fpreds_w)
  25052 	(*VP8EncIterator)(unsafe.Pointer(it)).Fnz = (*VP8Encoder)(unsafe.Pointer(enc)).Fnz
  25053 	(*VP8EncIterator)(unsafe.Pointer(it)).Fmb = (*VP8Encoder)(unsafe.Pointer(enc)).Fmb_info + uintptr(y*(*VP8Encoder)(unsafe.Pointer(enc)).Fmb_w)*4
  25054 	(*VP8EncIterator)(unsafe.Pointer(it)).Fy_top = (*VP8Encoder)(unsafe.Pointer(enc)).Fy_top
  25055 	(*VP8EncIterator)(unsafe.Pointer(it)).Fuv_top = (*VP8Encoder)(unsafe.Pointer(enc)).Fuv_top
  25056 	InitLeft(tls, it)
  25057 }
  25058 
  25059 // C documentation
  25060 //
  25061 //	// restart a scan
  25062 func VP8IteratorReset(tls *libc.TLS, it uintptr) {
  25063 	var enc uintptr
  25064 	_ = enc
  25065 	enc = (*VP8EncIterator)(unsafe.Pointer(it)).Fenc
  25066 	VP8IteratorSetRow(tls, it, 0)
  25067 	VP8IteratorSetCountDown(tls, it, (*VP8Encoder)(unsafe.Pointer(enc)).Fmb_w*(*VP8Encoder)(unsafe.Pointer(enc)).Fmb_h) // default
  25068 	InitTop(tls, it)
  25069 	libc.Xmemset(tls, it+208, 0, uint64(96))
  25070 	(*VP8EncIterator)(unsafe.Pointer(it)).Fdo_trellis = 0
  25071 }
  25072 
  25073 func VP8IteratorSetCountDown(tls *libc.TLS, it uintptr, count_down int32) {
  25074 	var v1 int32
  25075 	_ = v1
  25076 	v1 = count_down
  25077 	(*VP8EncIterator)(unsafe.Pointer(it)).Fcount_down0 = v1
  25078 	(*VP8EncIterator)(unsafe.Pointer(it)).Fcount_down = v1
  25079 }
  25080 
  25081 func VP8IteratorIsDone(tls *libc.TLS, it uintptr) (r int32) {
  25082 	return libc.BoolInt32((*VP8EncIterator)(unsafe.Pointer(it)).Fcount_down <= 0)
  25083 }
  25084 
  25085 func VP8IteratorInit(tls *libc.TLS, enc uintptr, it uintptr) {
  25086 	(*VP8EncIterator)(unsafe.Pointer(it)).Fenc = enc
  25087 	(*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_in = uintptr((uintptr_t(it+488) + libc.Uint64FromInt32(WEBP_ALIGN_CST)) & ^libc.Uint64FromInt32(WEBP_ALIGN_CST))
  25088 	(*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_out = (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_in + uintptr(libc.Int32FromInt32(BPS)*libc.Int32FromInt32(16))
  25089 	(*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_out2 = (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_out + uintptr(libc.Int32FromInt32(BPS)*libc.Int32FromInt32(16))
  25090 	(*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_p = (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_out2 + uintptr(libc.Int32FromInt32(BPS)*libc.Int32FromInt32(16))
  25091 	(*VP8EncIterator)(unsafe.Pointer(it)).Flf_stats = (*VP8Encoder)(unsafe.Pointer(enc)).Flf_stats
  25092 	(*VP8EncIterator)(unsafe.Pointer(it)).Fpercent0 = (*VP8Encoder)(unsafe.Pointer(enc)).Fpercent
  25093 	(*VP8EncIterator)(unsafe.Pointer(it)).Fy_left = uintptr((uint64(it+400+libc.UintptrFromInt32(1)) + libc.Uint64FromInt32(WEBP_ALIGN_CST)) & ^libc.Uint64FromInt32(WEBP_ALIGN_CST))
  25094 	(*VP8EncIterator)(unsafe.Pointer(it)).Fu_left = (*VP8EncIterator)(unsafe.Pointer(it)).Fy_left + uintptr(16) + uintptr(16)
  25095 	(*VP8EncIterator)(unsafe.Pointer(it)).Fv_left = (*VP8EncIterator)(unsafe.Pointer(it)).Fu_left + uintptr(16)
  25096 	(*VP8EncIterator)(unsafe.Pointer(it)).Ftop_derr = (*VP8Encoder)(unsafe.Pointer(enc)).Ftop_derr
  25097 	VP8IteratorReset(tls, it)
  25098 }
  25099 
  25100 func VP8IteratorProgress(tls *libc.TLS, it uintptr, delta int32) (r int32) {
  25101 	var done, percent, v1 int32
  25102 	var enc uintptr
  25103 	_, _, _, _ = done, enc, percent, v1
  25104 	enc = (*VP8EncIterator)(unsafe.Pointer(it)).Fenc
  25105 	if delta != 0 && (*WebPPicture)(unsafe.Pointer((*VP8Encoder)(unsafe.Pointer(enc)).Fpic)).Fprogress_hook != libc.UintptrFromInt32(0) {
  25106 		done = (*VP8EncIterator)(unsafe.Pointer(it)).Fcount_down0 - (*VP8EncIterator)(unsafe.Pointer(it)).Fcount_down
  25107 		if (*VP8EncIterator)(unsafe.Pointer(it)).Fcount_down0 <= 0 {
  25108 			v1 = (*VP8EncIterator)(unsafe.Pointer(it)).Fpercent0
  25109 		} else {
  25110 			v1 = (*VP8EncIterator)(unsafe.Pointer(it)).Fpercent0 + delta*done/(*VP8EncIterator)(unsafe.Pointer(it)).Fcount_down0
  25111 		}
  25112 		percent = v1
  25113 		return WebPReportProgress(tls, (*VP8Encoder)(unsafe.Pointer(enc)).Fpic, percent, enc+536)
  25114 	}
  25115 	return int32(1)
  25116 }
  25117 
  25118 //------------------------------------------------------------------------------
  25119 // Import the source samples into the cache. Takes care of replicating
  25120 // boundary pixels if necessary.
  25121 
  25122 func MinSize(tls *libc.TLS, a int32, b int32) (r int32) {
  25123 	var v1 int32
  25124 	_ = v1
  25125 	if a < b {
  25126 		v1 = a
  25127 	} else {
  25128 		v1 = b
  25129 	}
  25130 	return v1
  25131 }
  25132 
  25133 func ImportBlock(tls *libc.TLS, src uintptr, src_stride int32, dst uintptr, w int32, h int32, size int32) {
  25134 	var i int32
  25135 	_ = i
  25136 	i = 0
  25137 	for {
  25138 		if !(i < h) {
  25139 			break
  25140 		}
  25141 		libc.Xmemcpy(tls, dst, src, uint64(w))
  25142 		if w < size {
  25143 			libc.Xmemset(tls, dst+uintptr(w), int32(**(**uint8_t)(__ccgo_up(dst + uintptr(w-int32(1))))), uint64(size-w))
  25144 		}
  25145 		dst = dst + uintptr(BPS)
  25146 		src = src + uintptr(src_stride)
  25147 		goto _1
  25148 	_1:
  25149 		;
  25150 		i = i + 1
  25151 	}
  25152 	i = h
  25153 	for {
  25154 		if !(i < size) {
  25155 			break
  25156 		}
  25157 		libc.Xmemcpy(tls, dst, dst-uintptr(BPS), uint64(size))
  25158 		dst = dst + uintptr(BPS)
  25159 		goto _2
  25160 	_2:
  25161 		;
  25162 		i = i + 1
  25163 	}
  25164 }
  25165 
  25166 func ImportLine(tls *libc.TLS, src uintptr, src_stride int32, dst uintptr, len1 int32, total_len int32) {
  25167 	var i int32
  25168 	_ = i
  25169 	i = 0
  25170 	for {
  25171 		if !(i < len1) {
  25172 			break
  25173 		}
  25174 		**(**uint8_t)(__ccgo_up(dst + uintptr(i))) = **(**uint8_t)(__ccgo_up(src))
  25175 		goto _1
  25176 	_1:
  25177 		;
  25178 		i = i + 1
  25179 		src = src + uintptr(src_stride)
  25180 	}
  25181 	for {
  25182 		if !(i < total_len) {
  25183 			break
  25184 		}
  25185 		**(**uint8_t)(__ccgo_up(dst + uintptr(i))) = **(**uint8_t)(__ccgo_up(dst + uintptr(len1-int32(1))))
  25186 		goto _2
  25187 	_2:
  25188 		;
  25189 		i = i + 1
  25190 	}
  25191 }
  25192 
  25193 func VP8IteratorImport(tls *libc.TLS, it uintptr, tmp_32 uintptr) {
  25194 	var enc, pic, usrc, vsrc, ysrc uintptr
  25195 	var h, uv_h, uv_w, w, x, y int32
  25196 	var v1, v2 uint8_t
  25197 	_, _, _, _, _, _, _, _, _, _, _, _, _ = enc, h, pic, usrc, uv_h, uv_w, vsrc, w, x, y, ysrc, v1, v2
  25198 	enc = (*VP8EncIterator)(unsafe.Pointer(it)).Fenc
  25199 	x = (*VP8EncIterator)(unsafe.Pointer(it)).Fx
  25200 	y = (*VP8EncIterator)(unsafe.Pointer(it)).Fy
  25201 	pic = (*VP8Encoder)(unsafe.Pointer(enc)).Fpic
  25202 	ysrc = (*WebPPicture)(unsafe.Pointer(pic)).Fy + uintptr((y*(*WebPPicture)(unsafe.Pointer(pic)).Fy_stride+x)*int32(16))
  25203 	usrc = (*WebPPicture)(unsafe.Pointer(pic)).Fu + uintptr((y*(*WebPPicture)(unsafe.Pointer(pic)).Fuv_stride+x)*int32(8))
  25204 	vsrc = (*WebPPicture)(unsafe.Pointer(pic)).Fv + uintptr((y*(*WebPPicture)(unsafe.Pointer(pic)).Fuv_stride+x)*int32(8))
  25205 	w = MinSize(tls, (*WebPPicture)(unsafe.Pointer(pic)).Fwidth-x*int32(16), int32(16))
  25206 	h = MinSize(tls, (*WebPPicture)(unsafe.Pointer(pic)).Fheight-y*int32(16), int32(16))
  25207 	uv_w = (w + int32(1)) >> int32(1)
  25208 	uv_h = (h + int32(1)) >> int32(1)
  25209 	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))
  25210 	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))
  25211 	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))
  25212 	if tmp_32 == libc.UintptrFromInt32(0) {
  25213 		return
  25214 	}
  25215 	// Import source (uncompressed) samples into boundary.
  25216 	if x == 0 {
  25217 		InitLeft(tls, it)
  25218 	} else {
  25219 		if y == 0 {
  25220 			v2 = libc.Uint8FromInt32(127)
  25221 			**(**uint8_t)(__ccgo_up((*VP8EncIterator)(unsafe.Pointer(it)).Fv_left + uintptr(-libc.Int32FromInt32(1)))) = v2
  25222 			v1 = v2
  25223 			**(**uint8_t)(__ccgo_up((*VP8EncIterator)(unsafe.Pointer(it)).Fu_left + uintptr(-libc.Int32FromInt32(1)))) = v1
  25224 			**(**uint8_t)(__ccgo_up((*VP8EncIterator)(unsafe.Pointer(it)).Fy_left + uintptr(-libc.Int32FromInt32(1)))) = v1
  25225 		} else {
  25226 			**(**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)))
  25227 			**(**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)))
  25228 			**(**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)))
  25229 		}
  25230 		ImportLine(tls, ysrc-uintptr(1), (*WebPPicture)(unsafe.Pointer(pic)).Fy_stride, (*VP8EncIterator)(unsafe.Pointer(it)).Fy_left, h, int32(16))
  25231 		ImportLine(tls, usrc-uintptr(1), (*WebPPicture)(unsafe.Pointer(pic)).Fuv_stride, (*VP8EncIterator)(unsafe.Pointer(it)).Fu_left, uv_h, int32(8))
  25232 		ImportLine(tls, vsrc-uintptr(1), (*WebPPicture)(unsafe.Pointer(pic)).Fuv_stride, (*VP8EncIterator)(unsafe.Pointer(it)).Fv_left, uv_h, int32(8))
  25233 	}
  25234 	(*VP8EncIterator)(unsafe.Pointer(it)).Fy_top = tmp_32 + uintptr(0)
  25235 	(*VP8EncIterator)(unsafe.Pointer(it)).Fuv_top = tmp_32 + uintptr(16)
  25236 	if y == 0 {
  25237 		libc.Xmemset(tls, tmp_32, int32(127), libc.Uint64FromInt32(32)*libc.Uint64FromInt64(1))
  25238 	} else {
  25239 		ImportLine(tls, ysrc-uintptr((*WebPPicture)(unsafe.Pointer(pic)).Fy_stride), int32(1), tmp_32, w, int32(16))
  25240 		ImportLine(tls, usrc-uintptr((*WebPPicture)(unsafe.Pointer(pic)).Fuv_stride), int32(1), tmp_32+uintptr(16), uv_w, int32(8))
  25241 		ImportLine(tls, vsrc-uintptr((*WebPPicture)(unsafe.Pointer(pic)).Fuv_stride), int32(1), tmp_32+uintptr(16)+uintptr(8), uv_w, int32(8))
  25242 	}
  25243 }
  25244 
  25245 //------------------------------------------------------------------------------
  25246 // Copy back the compressed samples into user space if requested.
  25247 
  25248 func ExportBlock(tls *libc.TLS, src uintptr, dst uintptr, dst_stride int32, w int32, h int32) {
  25249 	var v1 int32
  25250 	_ = v1
  25251 	for {
  25252 		v1 = h
  25253 		h = h - 1
  25254 		if !(v1 > 0) {
  25255 			break
  25256 		}
  25257 		libc.Xmemcpy(tls, dst, src, uint64(w))
  25258 		dst = dst + uintptr(dst_stride)
  25259 		src = src + uintptr(BPS)
  25260 	}
  25261 }
  25262 
  25263 func VP8IteratorExport(tls *libc.TLS, it uintptr) {
  25264 	var enc, pic, udst, usrc, vdst, vsrc, ydst, ysrc uintptr
  25265 	var h, uv_h, uv_w, w, x, y int32
  25266 	_, _, _, _, _, _, _, _, _, _, _, _, _, _ = enc, h, pic, udst, usrc, uv_h, uv_w, vdst, vsrc, w, x, y, ydst, ysrc
  25267 	enc = (*VP8EncIterator)(unsafe.Pointer(it)).Fenc
  25268 	if (*WebPConfig)(unsafe.Pointer((*VP8Encoder)(unsafe.Pointer(enc)).Fconfig)).Fshow_compressed != 0 {
  25269 		x = (*VP8EncIterator)(unsafe.Pointer(it)).Fx
  25270 		y = (*VP8EncIterator)(unsafe.Pointer(it)).Fy
  25271 		ysrc = (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_out + uintptr(libc.Int32FromInt32(Y_OFF_ENC))
  25272 		usrc = (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_out + uintptr(libc.Int32FromInt32(U_OFF_ENC))
  25273 		vsrc = (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_out + uintptr(libc.Int32FromInt32(16)+libc.Int32FromInt32(8))
  25274 		pic = (*VP8Encoder)(unsafe.Pointer(enc)).Fpic
  25275 		ydst = (*WebPPicture)(unsafe.Pointer(pic)).Fy + uintptr((y*(*WebPPicture)(unsafe.Pointer(pic)).Fy_stride+x)*int32(16))
  25276 		udst = (*WebPPicture)(unsafe.Pointer(pic)).Fu + uintptr((y*(*WebPPicture)(unsafe.Pointer(pic)).Fuv_stride+x)*int32(8))
  25277 		vdst = (*WebPPicture)(unsafe.Pointer(pic)).Fv + uintptr((y*(*WebPPicture)(unsafe.Pointer(pic)).Fuv_stride+x)*int32(8))
  25278 		w = (*WebPPicture)(unsafe.Pointer(pic)).Fwidth - x*int32(16)
  25279 		h = (*WebPPicture)(unsafe.Pointer(pic)).Fheight - y*int32(16)
  25280 		if w > int32(16) {
  25281 			w = int32(16)
  25282 		}
  25283 		if h > int32(16) {
  25284 			h = int32(16)
  25285 		}
  25286 		// Luma plane
  25287 		ExportBlock(tls, ysrc, ydst, (*WebPPicture)(unsafe.Pointer(pic)).Fy_stride, w, h)
  25288 		// U/V planes
  25289 		uv_w = (w + int32(1)) >> int32(1)
  25290 		uv_h = (h + int32(1)) >> int32(1)
  25291 		ExportBlock(tls, usrc, udst, (*WebPPicture)(unsafe.Pointer(pic)).Fuv_stride, uv_w, uv_h)
  25292 		ExportBlock(tls, vsrc, vdst, (*WebPPicture)(unsafe.Pointer(pic)).Fuv_stride, uv_w, uv_h)
  25293 	}
  25294 }
  25295 
  25296 //------------------------------------------------------------------------------
  25297 // Non-zero contexts setup/teardown
  25298 
  25299 // Nz bits:
  25300 //  0  1  2  3  Y
  25301 //  4  5  6  7
  25302 //  8  9 10 11
  25303 // 12 13 14 15
  25304 // 16 17        U
  25305 // 18 19
  25306 // 20 21        V
  25307 // 22 23
  25308 // 24           DC-intra16
  25309 
  25310 // Convert packed context to byte array
  25311 
  25312 func VP8IteratorNzToBytes(tls *libc.TLS, it uintptr) {
  25313 	var left_nz, top_nz uintptr
  25314 	var lnz, tnz int32
  25315 	_, _, _, _ = left_nz, lnz, tnz, top_nz
  25316 	tnz = int32(**(**uint32_t)(__ccgo_up((*VP8EncIterator)(unsafe.Pointer(it)).Fnz)))
  25317 	lnz = int32(**(**uint32_t)(__ccgo_up((*VP8EncIterator)(unsafe.Pointer(it)).Fnz + uintptr(-libc.Int32FromInt32(1))*4)))
  25318 	top_nz = it + 132
  25319 	left_nz = it + 168
  25320 	// Top-Y
  25321 	**(**int32)(__ccgo_up(top_nz)) = libc.BoolInt32(!!(tnz&(libc.Int32FromInt32(1)<<libc.Int32FromInt32(12)) != 0))
  25322 	**(**int32)(__ccgo_up(top_nz + 1*4)) = libc.BoolInt32(!!(tnz&(libc.Int32FromInt32(1)<<libc.Int32FromInt32(13)) != 0))
  25323 	**(**int32)(__ccgo_up(top_nz + 2*4)) = libc.BoolInt32(!!(tnz&(libc.Int32FromInt32(1)<<libc.Int32FromInt32(14)) != 0))
  25324 	**(**int32)(__ccgo_up(top_nz + 3*4)) = libc.BoolInt32(!!(tnz&(libc.Int32FromInt32(1)<<libc.Int32FromInt32(15)) != 0))
  25325 	// Top-U
  25326 	**(**int32)(__ccgo_up(top_nz + 4*4)) = libc.BoolInt32(!!(tnz&(libc.Int32FromInt32(1)<<libc.Int32FromInt32(18)) != 0))
  25327 	**(**int32)(__ccgo_up(top_nz + 5*4)) = libc.BoolInt32(!!(tnz&(libc.Int32FromInt32(1)<<libc.Int32FromInt32(19)) != 0))
  25328 	// Top-V
  25329 	**(**int32)(__ccgo_up(top_nz + 6*4)) = libc.BoolInt32(!!(tnz&(libc.Int32FromInt32(1)<<libc.Int32FromInt32(22)) != 0))
  25330 	**(**int32)(__ccgo_up(top_nz + 7*4)) = libc.BoolInt32(!!(tnz&(libc.Int32FromInt32(1)<<libc.Int32FromInt32(23)) != 0))
  25331 	// DC
  25332 	**(**int32)(__ccgo_up(top_nz + 8*4)) = libc.BoolInt32(!!(tnz&(libc.Int32FromInt32(1)<<libc.Int32FromInt32(24)) != 0))
  25333 	// left-Y
  25334 	**(**int32)(__ccgo_up(left_nz)) = libc.BoolInt32(!!(lnz&(libc.Int32FromInt32(1)<<libc.Int32FromInt32(3)) != 0))
  25335 	**(**int32)(__ccgo_up(left_nz + 1*4)) = libc.BoolInt32(!!(lnz&(libc.Int32FromInt32(1)<<libc.Int32FromInt32(7)) != 0))
  25336 	**(**int32)(__ccgo_up(left_nz + 2*4)) = libc.BoolInt32(!!(lnz&(libc.Int32FromInt32(1)<<libc.Int32FromInt32(11)) != 0))
  25337 	**(**int32)(__ccgo_up(left_nz + 3*4)) = libc.BoolInt32(!!(lnz&(libc.Int32FromInt32(1)<<libc.Int32FromInt32(15)) != 0))
  25338 	// left-U
  25339 	**(**int32)(__ccgo_up(left_nz + 4*4)) = libc.BoolInt32(!!(lnz&(libc.Int32FromInt32(1)<<libc.Int32FromInt32(17)) != 0))
  25340 	**(**int32)(__ccgo_up(left_nz + 5*4)) = libc.BoolInt32(!!(lnz&(libc.Int32FromInt32(1)<<libc.Int32FromInt32(19)) != 0))
  25341 	// left-V
  25342 	**(**int32)(__ccgo_up(left_nz + 6*4)) = libc.BoolInt32(!!(lnz&(libc.Int32FromInt32(1)<<libc.Int32FromInt32(21)) != 0))
  25343 	**(**int32)(__ccgo_up(left_nz + 7*4)) = libc.BoolInt32(!!(lnz&(libc.Int32FromInt32(1)<<libc.Int32FromInt32(23)) != 0))
  25344 	// left-DC is special, iterated separately
  25345 }
  25346 
  25347 func VP8IteratorBytesToNz(tls *libc.TLS, it uintptr) {
  25348 	var left_nz, top_nz uintptr
  25349 	var nz uint32_t
  25350 	_, _, _ = left_nz, nz, top_nz
  25351 	nz = uint32(0)
  25352 	top_nz = it + 132
  25353 	left_nz = it + 168
  25354 	// top
  25355 	nz = nz | uint32(**(**int32)(__ccgo_up(top_nz))<<libc.Int32FromInt32(12)|**(**int32)(__ccgo_up(top_nz + 1*4))<<libc.Int32FromInt32(13))
  25356 	nz = nz | uint32(**(**int32)(__ccgo_up(top_nz + 2*4))<<libc.Int32FromInt32(14)|**(**int32)(__ccgo_up(top_nz + 3*4))<<libc.Int32FromInt32(15))
  25357 	nz = nz | uint32(**(**int32)(__ccgo_up(top_nz + 4*4))<<libc.Int32FromInt32(18)|**(**int32)(__ccgo_up(top_nz + 5*4))<<libc.Int32FromInt32(19))
  25358 	nz = nz | uint32(**(**int32)(__ccgo_up(top_nz + 6*4))<<libc.Int32FromInt32(22)|**(**int32)(__ccgo_up(top_nz + 7*4))<<libc.Int32FromInt32(23))
  25359 	nz = nz | uint32(**(**int32)(__ccgo_up(top_nz + 8*4))<<libc.Int32FromInt32(24)) // we propagate the _top_ bit, esp. for intra4
  25360 	// left
  25361 	nz = nz | uint32(**(**int32)(__ccgo_up(left_nz))<<libc.Int32FromInt32(3)|**(**int32)(__ccgo_up(left_nz + 1*4))<<libc.Int32FromInt32(7))
  25362 	nz = nz | uint32(**(**int32)(__ccgo_up(left_nz + 2*4))<<libc.Int32FromInt32(11))
  25363 	nz = nz | uint32(**(**int32)(__ccgo_up(left_nz + 4*4))<<libc.Int32FromInt32(17)|**(**int32)(__ccgo_up(left_nz + 6*4))<<libc.Int32FromInt32(21))
  25364 	**(**uint32_t)(__ccgo_up((*VP8EncIterator)(unsafe.Pointer(it)).Fnz)) = nz
  25365 }
  25366 
  25367 //------------------------------------------------------------------------------
  25368 // Advance to the next position, doing the bookkeeping.
  25369 
  25370 func VP8IteratorSaveBoundary(tls *libc.TLS, it uintptr) {
  25371 	var enc, uvsrc, ysrc uintptr
  25372 	var i, x, y int32
  25373 	_, _, _, _, _, _ = enc, i, uvsrc, x, y, ysrc
  25374 	enc = (*VP8EncIterator)(unsafe.Pointer(it)).Fenc
  25375 	x = (*VP8EncIterator)(unsafe.Pointer(it)).Fx
  25376 	y = (*VP8EncIterator)(unsafe.Pointer(it)).Fy
  25377 	ysrc = (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_out + uintptr(libc.Int32FromInt32(Y_OFF_ENC))
  25378 	uvsrc = (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_out + uintptr(libc.Int32FromInt32(U_OFF_ENC))
  25379 	if x < (*VP8Encoder)(unsafe.Pointer(enc)).Fmb_w-int32(1) {
  25380 		i = 0
  25381 		for {
  25382 			if !(i < int32(16)) {
  25383 				break
  25384 			}
  25385 			**(**uint8_t)(__ccgo_up((*VP8EncIterator)(unsafe.Pointer(it)).Fy_left + uintptr(i))) = **(**uint8_t)(__ccgo_up(ysrc + uintptr(int32(15)+i*int32(BPS))))
  25386 			goto _1
  25387 		_1:
  25388 			;
  25389 			i = i + 1
  25390 		}
  25391 		i = 0
  25392 		for {
  25393 			if !(i < int32(8)) {
  25394 				break
  25395 			}
  25396 			**(**uint8_t)(__ccgo_up((*VP8EncIterator)(unsafe.Pointer(it)).Fu_left + uintptr(i))) = **(**uint8_t)(__ccgo_up(uvsrc + uintptr(int32(7)+i*int32(BPS))))
  25397 			**(**uint8_t)(__ccgo_up((*VP8EncIterator)(unsafe.Pointer(it)).Fv_left + uintptr(i))) = **(**uint8_t)(__ccgo_up(uvsrc + uintptr(int32(15)+i*int32(BPS))))
  25398 			goto _2
  25399 		_2:
  25400 			;
  25401 			i = i + 1
  25402 		}
  25403 		// top-left (before 'top'!)
  25404 		**(**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))
  25405 		**(**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))))
  25406 		**(**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))))
  25407 	}
  25408 	if y < (*VP8Encoder)(unsafe.Pointer(enc)).Fmb_h-int32(1) { // top
  25409 		libc.Xmemcpy(tls, (*VP8EncIterator)(unsafe.Pointer(it)).Fy_top, ysrc+uintptr(libc.Int32FromInt32(15)*libc.Int32FromInt32(BPS)), uint64(16))
  25410 		libc.Xmemcpy(tls, (*VP8EncIterator)(unsafe.Pointer(it)).Fuv_top, uvsrc+uintptr(libc.Int32FromInt32(7)*libc.Int32FromInt32(BPS)), uint64(libc.Int32FromInt32(8)+libc.Int32FromInt32(8)))
  25411 	}
  25412 }
  25413 
  25414 func VP8IteratorNext(tls *libc.TLS, it uintptr) (r int32) {
  25415 	var v1, v3 int32
  25416 	var v2, v4 uintptr
  25417 	_, _, _, _ = v1, v2, v3, v4
  25418 	v2 = it
  25419 	*(*int32)(unsafe.Pointer(v2)) = *(*int32)(unsafe.Pointer(v2)) + 1
  25420 	v1 = *(*int32)(unsafe.Pointer(v2))
  25421 	if v1 == (*VP8Encoder)(unsafe.Pointer((*VP8EncIterator)(unsafe.Pointer(it)).Fenc)).Fmb_w {
  25422 		v4 = it + 4
  25423 		*(*int32)(unsafe.Pointer(v4)) = *(*int32)(unsafe.Pointer(v4)) + 1
  25424 		v3 = *(*int32)(unsafe.Pointer(v4))
  25425 		VP8IteratorSetRow(tls, it, v3)
  25426 	} else {
  25427 		**(**uintptr)(__ccgo_up(it + 64)) += uintptr(4)
  25428 		**(**uintptr)(__ccgo_up(it + 48)) += uintptr(1) * 4
  25429 		**(**uintptr)(__ccgo_up(it + 72)) += uintptr(1) * 4
  25430 		**(**uintptr)(__ccgo_up(it + 384)) += uintptr(16)
  25431 		**(**uintptr)(__ccgo_up(it + 392)) += uintptr(16)
  25432 	}
  25433 	v2 = it + 332
  25434 	*(*int32)(unsafe.Pointer(v2)) = *(*int32)(unsafe.Pointer(v2)) - 1
  25435 	v1 = *(*int32)(unsafe.Pointer(v2))
  25436 	return libc.BoolInt32(0 < v1)
  25437 }
  25438 
  25439 //------------------------------------------------------------------------------
  25440 // Helper function to set mode properties
  25441 
  25442 func VP8SetIntra16Mode(tls *libc.TLS, it uintptr, mode int32) {
  25443 	var preds uintptr
  25444 	var y int32
  25445 	_, _ = preds, y
  25446 	preds = (*VP8EncIterator)(unsafe.Pointer(it)).Fpreds
  25447 	y = 0
  25448 	for {
  25449 		if !(y < int32(4)) {
  25450 			break
  25451 		}
  25452 		libc.Xmemset(tls, preds, mode, uint64(4))
  25453 		preds = preds + uintptr((*VP8Encoder)(unsafe.Pointer((*VP8EncIterator)(unsafe.Pointer(it)).Fenc)).Fpreds_w)
  25454 		goto _1
  25455 	_1:
  25456 		;
  25457 		y = y + 1
  25458 	}
  25459 	libc.SetBitFieldPtr8Uint32((*VP8EncIterator)(unsafe.Pointer(it)).Fmb+0, libc.Uint32FromInt32(1), 0, 0x3)
  25460 }
  25461 
  25462 func VP8SetIntra4Mode(tls *libc.TLS, it uintptr, modes uintptr) {
  25463 	var preds uintptr
  25464 	var y int32
  25465 	_, _ = preds, y
  25466 	preds = (*VP8EncIterator)(unsafe.Pointer(it)).Fpreds
  25467 	y = int32(4)
  25468 	for {
  25469 		if !(y > 0) {
  25470 			break
  25471 		}
  25472 		libc.Xmemcpy(tls, preds, modes, libc.Uint64FromInt32(4)*libc.Uint64FromInt64(1))
  25473 		preds = preds + uintptr((*VP8Encoder)(unsafe.Pointer((*VP8EncIterator)(unsafe.Pointer(it)).Fenc)).Fpreds_w)
  25474 		modes = modes + uintptr(4)
  25475 		goto _1
  25476 	_1:
  25477 		;
  25478 		y = y - 1
  25479 	}
  25480 	libc.SetBitFieldPtr8Uint32((*VP8EncIterator)(unsafe.Pointer(it)).Fmb+0, libc.Uint32FromInt32(0), 0, 0x3)
  25481 }
  25482 
  25483 func VP8SetIntraUVMode(tls *libc.TLS, it uintptr, mode int32) {
  25484 	libc.SetBitFieldPtr8Uint32((*VP8EncIterator)(unsafe.Pointer(it)).Fmb+0, uint32(mode), 2, 0xc)
  25485 }
  25486 
  25487 func VP8SetSkip(tls *libc.TLS, it uintptr, skip int32) {
  25488 	libc.SetBitFieldPtr8Uint32((*VP8EncIterator)(unsafe.Pointer(it)).Fmb+0, uint32(skip), 4, 0x10)
  25489 }
  25490 
  25491 func VP8SetSegment(tls *libc.TLS, it uintptr, segment int32) {
  25492 	libc.SetBitFieldPtr8Uint32((*VP8EncIterator)(unsafe.Pointer(it)).Fmb+0, uint32(segment), 5, 0x60)
  25493 }
  25494 
  25495 //------------------------------------------------------------------------------
  25496 // Intra4x4 sub-blocks iteration
  25497 //
  25498 //  We store and update the boundary samples into an array of 37 pixels. They
  25499 //  are updated as we iterate and reconstructs each intra4x4 blocks in turn.
  25500 //  The position of the samples has the following snake pattern:
  25501 //
  25502 // 16|17 18 19 20|21 22 23 24|25 26 27 28|29 30 31 32|33 34 35 36  <- Top-right
  25503 // --+-----------+-----------+-----------+-----------+
  25504 // 15|         19|         23|         27|         31|
  25505 // 14|         18|         22|         26|         30|
  25506 // 13|         17|         21|         25|         29|
  25507 // 12|13 14 15 16|17 18 19 20|21 22 23 24|25 26 27 28|
  25508 // --+-----------+-----------+-----------+-----------+
  25509 // 11|         15|         19|         23|         27|
  25510 // 10|         14|         18|         22|         26|
  25511 //  9|         13|         17|         21|         25|
  25512 //  8| 9 10 11 12|13 14 15 16|17 18 19 20|21 22 23 24|
  25513 // --+-----------+-----------+-----------+-----------+
  25514 //  7|         11|         15|         19|         23|
  25515 //  6|         10|         14|         18|         22|
  25516 //  5|          9|         13|         17|         21|
  25517 //  4| 5  6  7  8| 9 10 11 12|13 14 15 16|17 18 19 20|
  25518 // --+-----------+-----------+-----------+-----------+
  25519 //  3|          7|         11|         15|         19|
  25520 //  2|          6|         10|         14|         18|
  25521 //  1|          5|          9|         13|         17|
  25522 //  0| 1  2  3  4| 5  6  7  8| 9 10 11 12|13 14 15 16|
  25523 // --+-----------+-----------+-----------+-----------+
  25524 
  25525 // C documentation
  25526 //
  25527 //	// Array to record the position of the top sample to pass to the prediction
  25528 //	// functions in dsp.c.
  25529 var VP8TopLeftI4 = [16]uint8_t{
  25530 	0:  uint8(17),
  25531 	1:  uint8(21),
  25532 	2:  uint8(25),
  25533 	3:  uint8(29),
  25534 	4:  uint8(13),
  25535 	5:  uint8(17),
  25536 	6:  uint8(21),
  25537 	7:  uint8(25),
  25538 	8:  uint8(9),
  25539 	9:  uint8(13),
  25540 	10: uint8(17),
  25541 	11: uint8(21),
  25542 	12: uint8(5),
  25543 	13: uint8(9),
  25544 	14: uint8(13),
  25545 	15: uint8(17),
  25546 }
  25547 
  25548 func VP8IteratorStartI4(tls *libc.TLS, it uintptr) {
  25549 	var enc uintptr
  25550 	var i int32
  25551 	_, _ = enc, i
  25552 	enc = (*VP8EncIterator)(unsafe.Pointer(it)).Fenc
  25553 	(*VP8EncIterator)(unsafe.Pointer(it)).Fi4 = 0 // first 4x4 sub-block
  25554 	(*VP8EncIterator)(unsafe.Pointer(it)).Fi4_top = it + 80 + uintptr(VP8TopLeftI4[0])
  25555 	// Import the boundary samples
  25556 	i = 0
  25557 	for {
  25558 		if !(i < int32(17)) {
  25559 			break
  25560 		} // left
  25561 		**(**uint8_t)(__ccgo_up(it + 80 + uintptr(i))) = **(**uint8_t)(__ccgo_up((*VP8EncIterator)(unsafe.Pointer(it)).Fy_left + uintptr(int32(15)-i)))
  25562 		goto _1
  25563 	_1:
  25564 		;
  25565 		i = i + 1
  25566 	}
  25567 	i = 0
  25568 	for {
  25569 		if !(i < int32(16)) {
  25570 			break
  25571 		} // top
  25572 		**(**uint8_t)(__ccgo_up(it + 80 + uintptr(int32(17)+i))) = **(**uint8_t)(__ccgo_up((*VP8EncIterator)(unsafe.Pointer(it)).Fy_top + uintptr(i)))
  25573 		goto _2
  25574 	_2:
  25575 		;
  25576 		i = i + 1
  25577 	}
  25578 	// top-right samples have a special case on the far right of the picture
  25579 	if (*VP8EncIterator)(unsafe.Pointer(it)).Fx < (*VP8Encoder)(unsafe.Pointer(enc)).Fmb_w-int32(1) {
  25580 		i = int32(16)
  25581 		for {
  25582 			if !(i < libc.Int32FromInt32(16)+libc.Int32FromInt32(4)) {
  25583 				break
  25584 			}
  25585 			**(**uint8_t)(__ccgo_up(it + 80 + uintptr(int32(17)+i))) = **(**uint8_t)(__ccgo_up((*VP8EncIterator)(unsafe.Pointer(it)).Fy_top + uintptr(i)))
  25586 			goto _3
  25587 		_3:
  25588 			;
  25589 			i = i + 1
  25590 		}
  25591 	} else { // else, replicate the last valid pixel four times
  25592 		i = int32(16)
  25593 		for {
  25594 			if !(i < libc.Int32FromInt32(16)+libc.Int32FromInt32(4)) {
  25595 				break
  25596 			}
  25597 			**(**uint8_t)(__ccgo_up(it + 80 + uintptr(int32(17)+i))) = **(**uint8_t)(__ccgo_up(it + 80 + uintptr(libc.Int32FromInt32(17)+libc.Int32FromInt32(15))))
  25598 			goto _4
  25599 		_4:
  25600 			;
  25601 			i = i + 1
  25602 		}
  25603 	}
  25604 	VP8IteratorNzToBytes(tls, it) // import the non-zero context
  25605 }
  25606 
  25607 func VP8IteratorRotateI4(tls *libc.TLS, it uintptr, yuv_out uintptr) (r int32) {
  25608 	var blk, top uintptr
  25609 	var i int32
  25610 	_, _, _ = blk, i, top
  25611 	blk = yuv_out + uintptr(VP8Scan[(*VP8EncIterator)(unsafe.Pointer(it)).Fi4])
  25612 	top = (*VP8EncIterator)(unsafe.Pointer(it)).Fi4_top
  25613 	// Update the cache with 7 fresh samples
  25614 	i = 0
  25615 	for {
  25616 		if !(i <= int32(3)) {
  25617 			break
  25618 		}
  25619 		**(**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
  25620 		goto _1
  25621 	_1:
  25622 		;
  25623 		i = i + 1
  25624 	}
  25625 	if (*VP8EncIterator)(unsafe.Pointer(it)).Fi4&int32(3) != int32(3) { // if not on the right sub-blocks #3, #7, #11, #15
  25626 		i = 0
  25627 		for {
  25628 			if !(i <= int32(2)) {
  25629 				break
  25630 			} // store future left samples
  25631 			**(**uint8_t)(__ccgo_up(top + uintptr(i))) = **(**uint8_t)(__ccgo_up(blk + uintptr(int32(3)+(int32(2)-i)*int32(BPS))))
  25632 			goto _2
  25633 		_2:
  25634 			;
  25635 			i = i + 1
  25636 		}
  25637 	} else { // else replicate top-right samples, as says the specs.
  25638 		i = 0
  25639 		for {
  25640 			if !(i <= int32(3)) {
  25641 				break
  25642 			}
  25643 			**(**uint8_t)(__ccgo_up(top + uintptr(i))) = **(**uint8_t)(__ccgo_up(top + uintptr(i+int32(4))))
  25644 			goto _3
  25645 		_3:
  25646 			;
  25647 			i = i + 1
  25648 		}
  25649 	}
  25650 	// move pointers to next sub-block
  25651 	(*VP8EncIterator)(unsafe.Pointer(it)).Fi4 = (*VP8EncIterator)(unsafe.Pointer(it)).Fi4 + 1
  25652 	if (*VP8EncIterator)(unsafe.Pointer(it)).Fi4 == int32(16) { // we're done
  25653 		return 0
  25654 	}
  25655 	(*VP8EncIterator)(unsafe.Pointer(it)).Fi4_top = it + 80 + uintptr(VP8TopLeftI4[(*VP8EncIterator)(unsafe.Pointer(it)).Fi4])
  25656 	return int32(1)
  25657 }
  25658 
  25659 const MAX_LIMIT_BITS = 5
  25660 const MIN_DIM_FOR_NEAR_LOSSLESS = 64
  25661 const SIZE_MAX10 = "_UI64_MAX"
  25662 
  25663 //------------------------------------------------------------------------------
  25664 
  25665 // Copyright 2012 Google Inc. All Rights Reserved.
  25666 //
  25667 // Use of this source code is governed by a BSD-style license
  25668 // that can be found in the COPYING file in the root of the source
  25669 // tree. An additional intellectual property rights grant can be found
  25670 // in the file PATENTS. All contributing project authors may
  25671 // be found in the AUTHORS file in the root of the source tree.
  25672 // -----------------------------------------------------------------------------
  25673 //
  25674 // Misc. common utility functions
  25675 //
  25676 // Authors: Skal (pascal.massimino@gmail.com)
  25677 //          Urvang (urvang@google.com)
  25678 
  25679 // Copyright 2011 Google Inc. All Rights Reserved.
  25680 //
  25681 // Use of this source code is governed by a BSD-style license
  25682 // that can be found in the COPYING file in the root of the source
  25683 // tree. An additional intellectual property rights grant can be found
  25684 // in the file PATENTS. All contributing project authors may
  25685 // be found in the AUTHORS file in the root of the source tree.
  25686 // -----------------------------------------------------------------------------
  25687 //
  25688 //   WebP encoder: main interface
  25689 //
  25690 // Author: Skal (pascal.massimino@gmail.com)
  25691 
  25692 // C documentation
  25693 //
  25694 //	// Quantizes the value up or down to a multiple of 1<<bits (or to 255),
  25695 //	// choosing the closer one, resolving ties using bankers' rounding.
  25696 func FindClosestDiscretized(tls *libc.TLS, a uint32_t, bits int32) (r uint32_t) {
  25697 	var biased, mask uint32_t
  25698 	_, _ = biased, mask
  25699 	mask = uint32(1)<<bits - uint32(1)
  25700 	biased = a + mask>>libc.Int32FromInt32(1) + a>>bits&uint32(1)
  25701 	if biased > uint32(0xff) {
  25702 		return uint32(0xff)
  25703 	}
  25704 	return biased & ^mask
  25705 }
  25706 
  25707 // C documentation
  25708 //
  25709 //	// Applies FindClosestDiscretized to all channels of pixel.
  25710 func ClosestDiscretizedArgb(tls *libc.TLS, a uint32_t, bits int32) (r uint32_t) {
  25711 	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)
  25712 }
  25713 
  25714 // C documentation
  25715 //
  25716 //	// Checks if distance between corresponding channel values of pixels a and b
  25717 //	// is within the given limit.
  25718 func IsNear(tls *libc.TLS, a uint32_t, b uint32_t, limit int32) (r int32) {
  25719 	var delta, k int32
  25720 	_, _ = delta, k
  25721 	k = 0
  25722 	for {
  25723 		if !(k < int32(4)) {
  25724 			break
  25725 		}
  25726 		delta = int32(a>>(k*libc.Int32FromInt32(8))&libc.Uint32FromInt32(0xff)) - int32(b>>(k*libc.Int32FromInt32(8))&libc.Uint32FromInt32(0xff))
  25727 		if delta >= limit || delta <= -limit {
  25728 			return 0
  25729 		}
  25730 		goto _1
  25731 	_1:
  25732 		;
  25733 		k = k + 1
  25734 	}
  25735 	return int32(1)
  25736 }
  25737 
  25738 func IsSmooth(tls *libc.TLS, prev_row uintptr, curr_row uintptr, next_row uintptr, ix int32, limit int32) (r int32) {
  25739 	// Check that all pixels in 4-connected neighborhood are smooth.
  25740 	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)
  25741 }
  25742 
  25743 // C documentation
  25744 //
  25745 //	// Adjusts pixel values of image with given maximum error.
  25746 func NearLossless(tls *libc.TLS, xsize int32, ysize int32, argb_src uintptr, stride int32, limit_bits int32, copy_buffer uintptr, argb_dst uintptr) {
  25747 	var curr_row, next_row, prev_row, temp uintptr
  25748 	var limit, x, y int32
  25749 	_, _, _, _, _, _, _ = curr_row, limit, next_row, prev_row, temp, x, y
  25750 	limit = int32(1) << limit_bits
  25751 	prev_row = copy_buffer
  25752 	curr_row = prev_row + uintptr(xsize)*4
  25753 	next_row = curr_row + uintptr(xsize)*4
  25754 	libc.Xmemcpy(tls, curr_row, argb_src, uint64(xsize)*uint64(4))
  25755 	libc.Xmemcpy(tls, next_row, argb_src+uintptr(stride)*4, uint64(xsize)*uint64(4))
  25756 	y = 0
  25757 	for {
  25758 		if !(y < ysize) {
  25759 			break
  25760 		}
  25761 		if y == 0 || y == ysize-int32(1) {
  25762 			libc.Xmemcpy(tls, argb_dst, argb_src, uint64(xsize)*uint64(4))
  25763 		} else {
  25764 			libc.Xmemcpy(tls, next_row, argb_src+uintptr(stride)*4, uint64(xsize)*uint64(4))
  25765 			**(**uint32_t)(__ccgo_up(argb_dst)) = **(**uint32_t)(__ccgo_up(argb_src))
  25766 			**(**uint32_t)(__ccgo_up(argb_dst + uintptr(xsize-int32(1))*4)) = **(**uint32_t)(__ccgo_up(argb_src + uintptr(xsize-int32(1))*4))
  25767 			x = int32(1)
  25768 			for {
  25769 				if !(x < xsize-int32(1)) {
  25770 					break
  25771 				}
  25772 				if IsSmooth(tls, prev_row, curr_row, next_row, x, limit) != 0 {
  25773 					**(**uint32_t)(__ccgo_up(argb_dst + uintptr(x)*4)) = **(**uint32_t)(__ccgo_up(curr_row + uintptr(x)*4))
  25774 				} else {
  25775 					**(**uint32_t)(__ccgo_up(argb_dst + uintptr(x)*4)) = ClosestDiscretizedArgb(tls, **(**uint32_t)(__ccgo_up(curr_row + uintptr(x)*4)), limit_bits)
  25776 				}
  25777 				goto _2
  25778 			_2:
  25779 				;
  25780 				x = x + 1
  25781 			}
  25782 		}
  25783 		// Three-way swap.
  25784 		temp = prev_row
  25785 		prev_row = curr_row
  25786 		curr_row = next_row
  25787 		next_row = temp
  25788 		goto _1
  25789 	_1:
  25790 		;
  25791 		y = y + 1
  25792 		argb_src = argb_src + uintptr(stride)*4
  25793 		argb_dst = argb_dst + uintptr(xsize)*4
  25794 	}
  25795 }
  25796 
  25797 func VP8ApplyNearLossless(tls *libc.TLS, picture uintptr, quality int32, argb_dst uintptr) (r int32) {
  25798 	var copy_buffer uintptr
  25799 	var i, limit_bits, stride, xsize, ysize, v1 int32
  25800 	_, _, _, _, _, _, _ = copy_buffer, i, limit_bits, stride, xsize, ysize, v1
  25801 	xsize = (*WebPPicture)(unsafe.Pointer(picture)).Fwidth
  25802 	ysize = (*WebPPicture)(unsafe.Pointer(picture)).Fheight
  25803 	stride = (*WebPPicture)(unsafe.Pointer(picture)).Fargb_stride
  25804 	copy_buffer = WebPSafeMalloc(tls, uint64(xsize*int32(3)), uint64(4))
  25805 	v1 = int32(5) - quality/int32(20)
  25806 	goto _2
  25807 _2:
  25808 	limit_bits = v1
  25809 	if copy_buffer == libc.UintptrFromInt32(0) {
  25810 		return 0
  25811 	}
  25812 	// For small icon images, don't attempt to apply near-lossless compression.
  25813 	if xsize < int32(MIN_DIM_FOR_NEAR_LOSSLESS) && ysize < int32(MIN_DIM_FOR_NEAR_LOSSLESS) || ysize < int32(3) {
  25814 		i = 0
  25815 		for {
  25816 			if !(i < ysize) {
  25817 				break
  25818 			}
  25819 			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))
  25820 			goto _3
  25821 		_3:
  25822 			;
  25823 			i = i + 1
  25824 		}
  25825 		WebPSafeFree(tls, copy_buffer)
  25826 		return int32(1)
  25827 	}
  25828 	NearLossless(tls, xsize, ysize, (*WebPPicture)(unsafe.Pointer(picture)).Fargb, stride, limit_bits, copy_buffer, argb_dst)
  25829 	i = limit_bits - int32(1)
  25830 	for {
  25831 		if !(i != 0) {
  25832 			break
  25833 		}
  25834 		NearLossless(tls, xsize, ysize, argb_dst, xsize, i, copy_buffer, argb_dst)
  25835 		goto _4
  25836 	_4:
  25837 		;
  25838 		i = i - 1
  25839 	}
  25840 	WebPSafeFree(tls, copy_buffer)
  25841 	return int32(1)
  25842 }
  25843 
  25844 const GAMMA_FIX = 12
  25845 const GAMMA_TAB_FIX = 7
  25846 const SHARPYUV_INLINE = "inline"
  25847 const SHARPYUV_VERSION_MAJOR = 0
  25848 const SHARPYUV_VERSION_MINOR = 4
  25849 const SHARPYUV_VERSION_PATCH = 2
  25850 
  25851 type SharpYuvConversionMatrix = struct {
  25852 	Frgb_to_y [4]int32
  25853 	Frgb_to_u [4]int32
  25854 	Frgb_to_v [4]int32
  25855 }
  25856 
  25857 type SharpYuvOptions = struct {
  25858 	Fyuv_matrix    uintptr
  25859 	Ftransfer_type SharpYuvTransferFunctionType1
  25860 }
  25861 
  25862 type SharpYuvTransferFunctionType = int32
  25863 
  25864 const kSharpYuvTransferFunctionBt709 = 1
  25865 const kSharpYuvTransferFunctionBt470M = 4
  25866 const kSharpYuvTransferFunctionBt470Bg = 5
  25867 const kSharpYuvTransferFunctionBt601 = 6
  25868 const kSharpYuvTransferFunctionSmpte240 = 7
  25869 const kSharpYuvTransferFunctionLinear = 8
  25870 const kSharpYuvTransferFunctionLog100 = 9
  25871 const kSharpYuvTransferFunctionLog100_Sqrt10 = 10
  25872 const kSharpYuvTransferFunctionIec61966 = 11
  25873 const kSharpYuvTransferFunctionBt1361 = 12
  25874 const kSharpYuvTransferFunctionSrgb = 13
  25875 const kSharpYuvTransferFunctionBt2020_10Bit = 14
  25876 const kSharpYuvTransferFunctionBt2020_12Bit = 15
  25877 const kSharpYuvTransferFunctionSmpte2084 = 16
  25878 const kSharpYuvTransferFunctionSmpte428 = 17
  25879 const kSharpYuvTransferFunctionHlg = 18
  25880 const kSharpYuvTransferFunctionNum = 19
  25881 
  25882 type SharpYuvTransferFunctionType1 = int32
  25883 
  25884 type SharpYuvRange = int32
  25885 
  25886 const kSharpYuvRangeFull = 0
  25887 const kSharpYuvRangeLimited = 1
  25888 
  25889 type SharpYuvColorSpace = struct {
  25890 	Fkr        float32
  25891 	Fkb        float32
  25892 	Fbit_depth int32
  25893 	Frange1    SharpYuvRange
  25894 }
  25895 
  25896 type SharpYuvMatrixType = int32
  25897 
  25898 const kSharpYuvMatrixWebp = 0
  25899 const kSharpYuvMatrixRec601Limited = 1
  25900 const kSharpYuvMatrixRec601Full = 2
  25901 const kSharpYuvMatrixRec709Limited = 3
  25902 const kSharpYuvMatrixRec709Full = 4
  25903 const kSharpYuvMatrixNum = 5
  25904 
  25905 // Copyright 2012 Google Inc. All Rights Reserved.
  25906 //
  25907 // Use of this source code is governed by a BSD-style license
  25908 // that can be found in the COPYING file in the root of the source
  25909 // tree. An additional intellectual property rights grant can be found
  25910 // in the file PATENTS. All contributing project authors may
  25911 // be found in the AUTHORS file in the root of the source tree.
  25912 // -----------------------------------------------------------------------------
  25913 //
  25914 // Misc. common utility functions
  25915 //
  25916 // Authors: Skal (pascal.massimino@gmail.com)
  25917 //          Urvang (urvang@google.com)
  25918 
  25919 // Copyright 2011 Google Inc. All Rights Reserved.
  25920 //
  25921 // Use of this source code is governed by a BSD-style license
  25922 // that can be found in the COPYING file in the root of the source
  25923 // tree. An additional intellectual property rights grant can be found
  25924 // in the file PATENTS. All contributing project authors may
  25925 // be found in the AUTHORS file in the root of the source tree.
  25926 // -----------------------------------------------------------------------------
  25927 //
  25928 //   WebP encoder: main interface
  25929 //
  25930 // Author: Skal (pascal.massimino@gmail.com)
  25931 
  25932 // Copyright 2010 Google Inc. All Rights Reserved.
  25933 //
  25934 // Use of this source code is governed by a BSD-style license
  25935 // that can be found in the COPYING file in the root of the source
  25936 // tree. An additional intellectual property rights grant can be found
  25937 // in the file PATENTS. All contributing project authors may
  25938 // be found in the AUTHORS file in the root of the source tree.
  25939 // -----------------------------------------------------------------------------
  25940 //
  25941 //  Common types + memory wrappers
  25942 //
  25943 // Author: Skal (pascal.massimino@gmail.com)
  25944 
  25945 // Uncomment to disable gamma-compression during RGB->U/V averaging
  25946 
  25947 // If defined, use table to compute x / alpha.
  25948 
  25949 // uint32_t 0xff000000 is 0x00,00,00,ff in memory
  25950 
  25951 //------------------------------------------------------------------------------
  25952 // Detection of non-trivial transparency
  25953 
  25954 // C documentation
  25955 //
  25956 //	// Returns true if alpha[] has non-0xff values.
  25957 func CheckNonOpaque(tls *libc.TLS, alpha uintptr, width int32, height int32, x_step int32, y_step int32) (r int32) {
  25958 	var v2 int32
  25959 	_ = v2
  25960 	if alpha == libc.UintptrFromInt32(0) {
  25961 		return 0
  25962 	}
  25963 	WebPInitAlphaProcessing(tls)
  25964 	if x_step == int32(1) {
  25965 		for {
  25966 			v2 = height
  25967 			height = height - 1
  25968 			if !(v2 > 0) {
  25969 				break
  25970 			}
  25971 			if (*(*func(*libc.TLS, uintptr, int32) int32)(unsafe.Pointer(&struct{ uintptr }{WebPHasAlpha8b})))(tls, alpha, width) != 0 {
  25972 				return int32(1)
  25973 			}
  25974 			goto _1
  25975 		_1:
  25976 			;
  25977 			alpha = alpha + uintptr(y_step)
  25978 		}
  25979 	} else {
  25980 		for {
  25981 			v2 = height
  25982 			height = height - 1
  25983 			if !(v2 > 0) {
  25984 				break
  25985 			}
  25986 			if (*(*func(*libc.TLS, uintptr, int32) int32)(unsafe.Pointer(&struct{ uintptr }{WebPHasAlpha32b})))(tls, alpha, width) != 0 {
  25987 				return int32(1)
  25988 			}
  25989 			goto _3
  25990 		_3:
  25991 			;
  25992 			alpha = alpha + uintptr(y_step)
  25993 		}
  25994 	}
  25995 	return 0
  25996 }
  25997 
  25998 // C documentation
  25999 //
  26000 //	// Checking for the presence of non-opaque alpha.
  26001 func WebPPictureHasTransparency(tls *libc.TLS, picture uintptr) (r int32) {
  26002 	if picture == libc.UintptrFromInt32(0) {
  26003 		return 0
  26004 	}
  26005 	if (*WebPPicture)(unsafe.Pointer(picture)).Fuse_argb != 0 {
  26006 		if (*WebPPicture)(unsafe.Pointer(picture)).Fargb != libc.UintptrFromInt32(0) {
  26007 			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)))
  26008 		}
  26009 		return 0
  26010 	}
  26011 	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)
  26012 }
  26013 
  26014 //------------------------------------------------------------------------------
  26015 // Code for gamma correction
  26016 
  26017 // C documentation
  26018 //
  26019 //	// Gamma correction compensates loss of resolution during chroma subsampling.
  26020 var kGamma = float64(0.8)
  26021 var kGammaScale = libc.Int32FromInt32(1)<<libc.Int32FromInt32(GAMMA_FIX) - libc.Int32FromInt32(1)
  26022 var kGammaTabScale = libc.Int32FromInt32(1) << libc.Int32FromInt32(GAMMA_TAB_FIX)
  26023 var kGammaTabRounder = libc.Int32FromInt32(1) << libc.Int32FromInt32(GAMMA_TAB_FIX) >> libc.Int32FromInt32(1)
  26024 
  26025 var kLinearToGammaTab [33]int32
  26026 var kGammaToLinearTab [256]uint16_t
  26027 var kGammaTablesOk = int32(0)
  26028 
  26029 func InitGammaTables(tls *libc.TLS) {
  26030 	if libc.AtomicLoadPUintptr(uintptr(unsafe.Pointer(&InitGammaTables_body_last_cpuinfo_used))) == VP8GetCPUInfo {
  26031 		goto _1
  26032 	}
  26033 	InitGammaTables_body(tls)
  26034 	libc.AtomicStorePUintptr(uintptr(unsafe.Pointer(&InitGammaTables_body_last_cpuinfo_used)), VP8GetCPUInfo)
  26035 	goto _2
  26036 _2:
  26037 	;
  26038 	goto _1
  26039 _1: /**/ //
  26040 }
  26041 
  26042 var InitGammaTables_body_last_cpuinfo_used = uintptr(0)
  26043 
  26044 func init() {
  26045 	p := unsafe.Pointer(&InitGammaTables_body_last_cpuinfo_used)
  26046 	*(*uintptr)(unsafe.Add(p, 0)) = uintptr(unsafe.Pointer(&InitGammaTables_body_last_cpuinfo_used))
  26047 }
  26048 
  26049 func InitGammaTables_body(tls *libc.TLS) {
  26050 	var norm, scale float64
  26051 	var v int32
  26052 	_, _, _ = norm, scale, v
  26053 	if !(libc.AtomicLoadPInt32(uintptr(unsafe.Pointer(&kGammaTablesOk))) != 0) {
  26054 		scale = float64(libc.Int32FromInt32(1)<<libc.Int32FromInt32(GAMMA_TAB_FIX)) / float64(kGammaScale)
  26055 		norm = libc.Float64FromFloat64(1) / libc.Float64FromFloat64(255)
  26056 		v = 0
  26057 		for {
  26058 			if !(v <= int32(255)) {
  26059 				break
  26060 			}
  26061 			kGammaToLinearTab[v] = uint16(float64(libc.Xpow(tls, float64(norm*float64(v)), kGamma)*float64(kGammaScale)) + libc.Float64FromFloat64(0.5))
  26062 			goto _1
  26063 		_1:
  26064 			;
  26065 			v = v + 1
  26066 		}
  26067 		v = 0
  26068 		for {
  26069 			if !(v <= libc.Int32FromInt32(1)<<(libc.Int32FromInt32(GAMMA_FIX)-libc.Int32FromInt32(GAMMA_TAB_FIX))) {
  26070 				break
  26071 			}
  26072 			kLinearToGammaTab[v] = int32(float64(libc.Float64FromFloat64(255)*libc.Xpow(tls, float64(scale*float64(v)), float64(1)/kGamma)) + libc.Float64FromFloat64(0.5))
  26073 			goto _2
  26074 		_2:
  26075 			;
  26076 			v = v + 1
  26077 		}
  26078 		libc.AtomicStorePInt32(uintptr(unsafe.Pointer(&kGammaTablesOk)), int32(1))
  26079 	}
  26080 }
  26081 
  26082 func GammaToLinear(tls *libc.TLS, v uint8_t) (r uint32_t) {
  26083 	return uint32(kGammaToLinearTab[v])
  26084 }
  26085 
  26086 func Interpolate(tls *libc.TLS, v int32) (r int32) {
  26087 	var tab_pos, v0, v1, x, y int32
  26088 	_, _, _, _, _ = tab_pos, v0, v1, x, y
  26089 	tab_pos = v >> (libc.Int32FromInt32(GAMMA_TAB_FIX) + libc.Int32FromInt32(2)) // integer part
  26090 	x = v & (kGammaTabScale<<libc.Int32FromInt32(2) - int32(1))                  // fractional part
  26091 	v0 = kLinearToGammaTab[tab_pos]
  26092 	v1 = kLinearToGammaTab[tab_pos+int32(1)]
  26093 	y = v1*x + v0*(kGammaTabScale<<libc.Int32FromInt32(2)-x) // interpolate
  26094 	return y
  26095 }
  26096 
  26097 // C documentation
  26098 //
  26099 //	// Convert a linear value 'v' to YUV_FIX+2 fixed-point precision
  26100 //	// U/V value, suitable for RGBToU/V calls.
  26101 func LinearToGamma(tls *libc.TLS, base_value uint32_t, shift int32) (r int32) {
  26102 	var y int32
  26103 	_ = y
  26104 	y = Interpolate(tls, int32(base_value<<shift))        // final uplifted value
  26105 	return (y + kGammaTabRounder) >> int32(GAMMA_TAB_FIX) // descale
  26106 }
  26107 
  26108 //------------------------------------------------------------------------------
  26109 // RGB -> YUV conversion
  26110 
  26111 func RGBToY(tls *libc.TLS, r1 int32, g1 int32, b1 int32, rg2 uintptr) (r int32) {
  26112 	var diff, luma, v1, v11, v13, v15, v2, v5, v8, v9 int32
  26113 	var v10, v12, v4, v7 uintptr
  26114 	_, _, _, _, _, _, _, _, _, _, _, _, _, _ = diff, luma, v1, v10, v11, v12, v13, v15, v2, v4, v5, v7, v8, v9
  26115 	if rg2 == libc.UintptrFromInt32(0) {
  26116 		luma = int32(16839)*r1 + int32(33059)*g1 + int32(6420)*b1
  26117 		v2 = (luma + int32(YUV_HALF) + libc.Int32FromInt32(16)<<int32(YUV_FIX)) >> int32(YUV_FIX)
  26118 		goto _3
  26119 	_3:
  26120 		v1 = v2
  26121 	} else {
  26122 		v4 = rg2
  26123 		v7 = v4
  26124 		v8 = int32(YUV_FIX)
  26125 		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)))
  26126 		if diff < libc.Int32FromInt32(0) {
  26127 			diff = int32(uint32(diff) + libc.Uint32FromUint32(1)<<libc.Int32FromInt32(31))
  26128 		}
  26129 		**(**uint32_t)(__ccgo_up(v7 + 8 + uintptr((*VP8Random)(unsafe.Pointer(v7)).Findex1)*4)) = uint32(diff)
  26130 		v10 = v7
  26131 		*(*int32)(unsafe.Pointer(v10)) = *(*int32)(unsafe.Pointer(v10)) + 1
  26132 		v9 = *(*int32)(unsafe.Pointer(v10))
  26133 		if v9 == libc.Int32FromInt32(VP8_RANDOM_TABLE_SIZE) {
  26134 			(*VP8Random)(unsafe.Pointer(v7)).Findex1 = 0
  26135 		}
  26136 		v12 = v7 + 4
  26137 		*(*int32)(unsafe.Pointer(v12)) = *(*int32)(unsafe.Pointer(v12)) + 1
  26138 		v11 = *(*int32)(unsafe.Pointer(v12))
  26139 		if v11 == libc.Int32FromInt32(VP8_RANDOM_TABLE_SIZE) {
  26140 			(*VP8Random)(unsafe.Pointer(v7)).Findex2 = 0
  26141 		}
  26142 		diff = int32(uint32(diff)<<libc.Int32FromInt32(1)) >> (int32(32) - v8)
  26143 		diff = diff * (*VP8Random)(unsafe.Pointer(v4)).Famp >> int32(VP8_RANDOM_DITHER_FIX)
  26144 		diff = diff + int32(1)<<(v8-int32(1))
  26145 		v13 = diff
  26146 		goto _14
  26147 	_14:
  26148 		v5 = v13
  26149 		goto _6
  26150 	_6:
  26151 		luma = int32(16839)*r1 + int32(33059)*g1 + int32(6420)*b1
  26152 		v15 = (luma + v5 + libc.Int32FromInt32(16)<<int32(YUV_FIX)) >> int32(YUV_FIX)
  26153 		goto _16
  26154 	_16:
  26155 		v1 = v15
  26156 	}
  26157 	return v1
  26158 }
  26159 
  26160 func RGBToU(tls *libc.TLS, r1 int32, g1 int32, b1 int32, rg2 uintptr) (r int32) {
  26161 	var diff, u, v1, v10, v13, v14, v16, v18, v2, v20, v22, v23, v25, v26, v4, v5, v7, v8 int32
  26162 	var v12, v15, v17, v9 uintptr
  26163 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = diff, u, v1, v10, v12, v13, v14, v15, v16, v17, v18, v2, v20, v22, v23, v25, v26, v4, v5, v7, v8, v9
  26164 	if rg2 == libc.UintptrFromInt32(0) {
  26165 		u = -int32(9719)*r1 - int32(19081)*g1 + int32(28800)*b1
  26166 		v4 = u
  26167 		v4 = (v4 + int32(YUV_HALF)<<libc.Int32FromInt32(2) + libc.Int32FromInt32(128)<<(int32(YUV_FIX)+libc.Int32FromInt32(2))) >> (int32(YUV_FIX) + libc.Int32FromInt32(2))
  26168 		if v4 & ^libc.Int32FromInt32(0xff) == 0 {
  26169 			v7 = v4
  26170 		} else {
  26171 			if v4 < 0 {
  26172 				v8 = 0
  26173 			} else {
  26174 				v8 = int32(255)
  26175 			}
  26176 			v7 = v8
  26177 		}
  26178 		v5 = v7
  26179 		goto _6
  26180 	_6:
  26181 		v2 = v5
  26182 		goto _3
  26183 	_3:
  26184 		v1 = v2
  26185 	} else {
  26186 		v9 = rg2
  26187 		v12 = v9
  26188 		v13 = int32(YUV_FIX) + libc.Int32FromInt32(2)
  26189 		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)))
  26190 		if diff < libc.Int32FromInt32(0) {
  26191 			diff = int32(uint32(diff) + libc.Uint32FromUint32(1)<<libc.Int32FromInt32(31))
  26192 		}
  26193 		**(**uint32_t)(__ccgo_up(v12 + 8 + uintptr((*VP8Random)(unsafe.Pointer(v12)).Findex1)*4)) = uint32(diff)
  26194 		v15 = v12
  26195 		*(*int32)(unsafe.Pointer(v15)) = *(*int32)(unsafe.Pointer(v15)) + 1
  26196 		v14 = *(*int32)(unsafe.Pointer(v15))
  26197 		if v14 == libc.Int32FromInt32(VP8_RANDOM_TABLE_SIZE) {
  26198 			(*VP8Random)(unsafe.Pointer(v12)).Findex1 = 0
  26199 		}
  26200 		v17 = v12 + 4
  26201 		*(*int32)(unsafe.Pointer(v17)) = *(*int32)(unsafe.Pointer(v17)) + 1
  26202 		v16 = *(*int32)(unsafe.Pointer(v17))
  26203 		if v16 == libc.Int32FromInt32(VP8_RANDOM_TABLE_SIZE) {
  26204 			(*VP8Random)(unsafe.Pointer(v12)).Findex2 = 0
  26205 		}
  26206 		diff = int32(uint32(diff)<<libc.Int32FromInt32(1)) >> (int32(32) - v13)
  26207 		diff = diff * (*VP8Random)(unsafe.Pointer(v9)).Famp >> int32(VP8_RANDOM_DITHER_FIX)
  26208 		diff = diff + int32(1)<<(v13-int32(1))
  26209 		v18 = diff
  26210 		goto _19
  26211 	_19:
  26212 		v10 = v18
  26213 		goto _11
  26214 	_11:
  26215 		u = -int32(9719)*r1 - int32(19081)*g1 + int32(28800)*b1
  26216 		v22 = u
  26217 		v22 = (v22 + v10 + libc.Int32FromInt32(128)<<(int32(YUV_FIX)+libc.Int32FromInt32(2))) >> (int32(YUV_FIX) + libc.Int32FromInt32(2))
  26218 		if v22 & ^libc.Int32FromInt32(0xff) == 0 {
  26219 			v25 = v22
  26220 		} else {
  26221 			if v22 < 0 {
  26222 				v26 = 0
  26223 			} else {
  26224 				v26 = int32(255)
  26225 			}
  26226 			v25 = v26
  26227 		}
  26228 		v23 = v25
  26229 		goto _24
  26230 	_24:
  26231 		v20 = v23
  26232 		goto _21
  26233 	_21:
  26234 		v1 = v20
  26235 	}
  26236 	return v1
  26237 }
  26238 
  26239 func RGBToV(tls *libc.TLS, r1 int32, g1 int32, b1 int32, rg2 uintptr) (r int32) {
  26240 	var diff, v, v1, v10, v13, v14, v16, v18, v2, v20, v22, v23, v25, v26, v4, v5, v7, v8 int32
  26241 	var v12, v15, v17, v9 uintptr
  26242 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = diff, v, v1, v10, v12, v13, v14, v15, v16, v17, v18, v2, v20, v22, v23, v25, v26, v4, v5, v7, v8, v9
  26243 	if rg2 == libc.UintptrFromInt32(0) {
  26244 		v = +libc.Int32FromInt32(28800)*r1 - int32(24116)*g1 - int32(4684)*b1
  26245 		v4 = v
  26246 		v4 = (v4 + int32(YUV_HALF)<<libc.Int32FromInt32(2) + libc.Int32FromInt32(128)<<(int32(YUV_FIX)+libc.Int32FromInt32(2))) >> (int32(YUV_FIX) + libc.Int32FromInt32(2))
  26247 		if v4 & ^libc.Int32FromInt32(0xff) == 0 {
  26248 			v7 = v4
  26249 		} else {
  26250 			if v4 < 0 {
  26251 				v8 = 0
  26252 			} else {
  26253 				v8 = int32(255)
  26254 			}
  26255 			v7 = v8
  26256 		}
  26257 		v5 = v7
  26258 		goto _6
  26259 	_6:
  26260 		v2 = v5
  26261 		goto _3
  26262 	_3:
  26263 		v1 = v2
  26264 	} else {
  26265 		v9 = rg2
  26266 		v12 = v9
  26267 		v13 = int32(YUV_FIX) + libc.Int32FromInt32(2)
  26268 		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)))
  26269 		if diff < libc.Int32FromInt32(0) {
  26270 			diff = int32(uint32(diff) + libc.Uint32FromUint32(1)<<libc.Int32FromInt32(31))
  26271 		}
  26272 		**(**uint32_t)(__ccgo_up(v12 + 8 + uintptr((*VP8Random)(unsafe.Pointer(v12)).Findex1)*4)) = uint32(diff)
  26273 		v15 = v12
  26274 		*(*int32)(unsafe.Pointer(v15)) = *(*int32)(unsafe.Pointer(v15)) + 1
  26275 		v14 = *(*int32)(unsafe.Pointer(v15))
  26276 		if v14 == libc.Int32FromInt32(VP8_RANDOM_TABLE_SIZE) {
  26277 			(*VP8Random)(unsafe.Pointer(v12)).Findex1 = 0
  26278 		}
  26279 		v17 = v12 + 4
  26280 		*(*int32)(unsafe.Pointer(v17)) = *(*int32)(unsafe.Pointer(v17)) + 1
  26281 		v16 = *(*int32)(unsafe.Pointer(v17))
  26282 		if v16 == libc.Int32FromInt32(VP8_RANDOM_TABLE_SIZE) {
  26283 			(*VP8Random)(unsafe.Pointer(v12)).Findex2 = 0
  26284 		}
  26285 		diff = int32(uint32(diff)<<libc.Int32FromInt32(1)) >> (int32(32) - v13)
  26286 		diff = diff * (*VP8Random)(unsafe.Pointer(v9)).Famp >> int32(VP8_RANDOM_DITHER_FIX)
  26287 		diff = diff + int32(1)<<(v13-int32(1))
  26288 		v18 = diff
  26289 		goto _19
  26290 	_19:
  26291 		v10 = v18
  26292 		goto _11
  26293 	_11:
  26294 		v = +libc.Int32FromInt32(28800)*r1 - int32(24116)*g1 - int32(4684)*b1
  26295 		v22 = v
  26296 		v22 = (v22 + v10 + libc.Int32FromInt32(128)<<(int32(YUV_FIX)+libc.Int32FromInt32(2))) >> (int32(YUV_FIX) + libc.Int32FromInt32(2))
  26297 		if v22 & ^libc.Int32FromInt32(0xff) == 0 {
  26298 			v25 = v22
  26299 		} else {
  26300 			if v22 < 0 {
  26301 				v26 = 0
  26302 			} else {
  26303 				v26 = int32(255)
  26304 			}
  26305 			v25 = v26
  26306 		}
  26307 		v23 = v25
  26308 		goto _24
  26309 	_24:
  26310 		v20 = v23
  26311 		goto _21
  26312 	_21:
  26313 		v1 = v20
  26314 	}
  26315 	return v1
  26316 }
  26317 
  26318 //------------------------------------------------------------------------------
  26319 // Sharp RGB->YUV conversion
  26320 
  26321 var kMinDimensionIterativeConversion = int32(4)
  26322 
  26323 //------------------------------------------------------------------------------
  26324 // Main function
  26325 
  26326 func PreprocessARGB(tls *libc.TLS, r_ptr uintptr, g_ptr uintptr, b_ptr uintptr, step int32, rgb_stride int32, picture uintptr) (r int32) {
  26327 	var ok int32
  26328 	_ = ok
  26329 	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)))
  26330 	if !(ok != 0) {
  26331 		return WebPEncodingSetError(tls, picture, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  26332 	}
  26333 	return ok
  26334 }
  26335 
  26336 //------------------------------------------------------------------------------
  26337 // "Fast" regular RGB->YUV
  26338 
  26339 var kAlphaFix = int32(19)
  26340 
  26341 // C documentation
  26342 //
  26343 //	// Following table is (1 << kAlphaFix) / a. The (v * kInvAlpha[a]) >> kAlphaFix
  26344 //	// formula is then equal to v / a in most (99.6%) cases. Note that this table
  26345 //	// and constant are adjusted very tightly to fit 32b arithmetic.
  26346 //	// In particular, they use the fact that the operands for 'v / a' are actually
  26347 //	// derived as v = (a0.p0 + a1.p1 + a2.p2 + a3.p3) and a = a0 + a1 + a2 + a3
  26348 //	// with ai in [0..255] and pi in [0..1<<GAMMA_FIX). The constraint to avoid
  26349 //	// overflow is: GAMMA_FIX + kAlphaFix <= 31.
  26350 var kInvAlpha = [1021]uint32_t{
  26351 	1:    uint32(524288),
  26352 	2:    uint32(262144),
  26353 	3:    uint32(174762),
  26354 	4:    uint32(131072),
  26355 	5:    uint32(104857),
  26356 	6:    uint32(87381),
  26357 	7:    uint32(74898),
  26358 	8:    uint32(65536),
  26359 	9:    uint32(58254),
  26360 	10:   uint32(52428),
  26361 	11:   uint32(47662),
  26362 	12:   uint32(43690),
  26363 	13:   uint32(40329),
  26364 	14:   uint32(37449),
  26365 	15:   uint32(34952),
  26366 	16:   uint32(32768),
  26367 	17:   uint32(30840),
  26368 	18:   uint32(29127),
  26369 	19:   uint32(27594),
  26370 	20:   uint32(26214),
  26371 	21:   uint32(24966),
  26372 	22:   uint32(23831),
  26373 	23:   uint32(22795),
  26374 	24:   uint32(21845),
  26375 	25:   uint32(20971),
  26376 	26:   uint32(20164),
  26377 	27:   uint32(19418),
  26378 	28:   uint32(18724),
  26379 	29:   uint32(18078),
  26380 	30:   uint32(17476),
  26381 	31:   uint32(16912),
  26382 	32:   uint32(16384),
  26383 	33:   uint32(15887),
  26384 	34:   uint32(15420),
  26385 	35:   uint32(14979),
  26386 	36:   uint32(14563),
  26387 	37:   uint32(14169),
  26388 	38:   uint32(13797),
  26389 	39:   uint32(13443),
  26390 	40:   uint32(13107),
  26391 	41:   uint32(12787),
  26392 	42:   uint32(12483),
  26393 	43:   uint32(12192),
  26394 	44:   uint32(11915),
  26395 	45:   uint32(11650),
  26396 	46:   uint32(11397),
  26397 	47:   uint32(11155),
  26398 	48:   uint32(10922),
  26399 	49:   uint32(10699),
  26400 	50:   uint32(10485),
  26401 	51:   uint32(10280),
  26402 	52:   uint32(10082),
  26403 	53:   uint32(9892),
  26404 	54:   uint32(9709),
  26405 	55:   uint32(9532),
  26406 	56:   uint32(9362),
  26407 	57:   uint32(9198),
  26408 	58:   uint32(9039),
  26409 	59:   uint32(8886),
  26410 	60:   uint32(8738),
  26411 	61:   uint32(8594),
  26412 	62:   uint32(8456),
  26413 	63:   uint32(8322),
  26414 	64:   uint32(8192),
  26415 	65:   uint32(8065),
  26416 	66:   uint32(7943),
  26417 	67:   uint32(7825),
  26418 	68:   uint32(7710),
  26419 	69:   uint32(7598),
  26420 	70:   uint32(7489),
  26421 	71:   uint32(7384),
  26422 	72:   uint32(7281),
  26423 	73:   uint32(7182),
  26424 	74:   uint32(7084),
  26425 	75:   uint32(6990),
  26426 	76:   uint32(6898),
  26427 	77:   uint32(6808),
  26428 	78:   uint32(6721),
  26429 	79:   uint32(6636),
  26430 	80:   uint32(6553),
  26431 	81:   uint32(6472),
  26432 	82:   uint32(6393),
  26433 	83:   uint32(6316),
  26434 	84:   uint32(6241),
  26435 	85:   uint32(6168),
  26436 	86:   uint32(6096),
  26437 	87:   uint32(6026),
  26438 	88:   uint32(5957),
  26439 	89:   uint32(5890),
  26440 	90:   uint32(5825),
  26441 	91:   uint32(5761),
  26442 	92:   uint32(5698),
  26443 	93:   uint32(5637),
  26444 	94:   uint32(5577),
  26445 	95:   uint32(5518),
  26446 	96:   uint32(5461),
  26447 	97:   uint32(5405),
  26448 	98:   uint32(5349),
  26449 	99:   uint32(5295),
  26450 	100:  uint32(5242),
  26451 	101:  uint32(5190),
  26452 	102:  uint32(5140),
  26453 	103:  uint32(5090),
  26454 	104:  uint32(5041),
  26455 	105:  uint32(4993),
  26456 	106:  uint32(4946),
  26457 	107:  uint32(4899),
  26458 	108:  uint32(4854),
  26459 	109:  uint32(4809),
  26460 	110:  uint32(4766),
  26461 	111:  uint32(4723),
  26462 	112:  uint32(4681),
  26463 	113:  uint32(4639),
  26464 	114:  uint32(4599),
  26465 	115:  uint32(4559),
  26466 	116:  uint32(4519),
  26467 	117:  uint32(4481),
  26468 	118:  uint32(4443),
  26469 	119:  uint32(4405),
  26470 	120:  uint32(4369),
  26471 	121:  uint32(4332),
  26472 	122:  uint32(4297),
  26473 	123:  uint32(4262),
  26474 	124:  uint32(4228),
  26475 	125:  uint32(4194),
  26476 	126:  uint32(4161),
  26477 	127:  uint32(4128),
  26478 	128:  uint32(4096),
  26479 	129:  uint32(4064),
  26480 	130:  uint32(4032),
  26481 	131:  uint32(4002),
  26482 	132:  uint32(3971),
  26483 	133:  uint32(3942),
  26484 	134:  uint32(3912),
  26485 	135:  uint32(3883),
  26486 	136:  uint32(3855),
  26487 	137:  uint32(3826),
  26488 	138:  uint32(3799),
  26489 	139:  uint32(3771),
  26490 	140:  uint32(3744),
  26491 	141:  uint32(3718),
  26492 	142:  uint32(3692),
  26493 	143:  uint32(3666),
  26494 	144:  uint32(3640),
  26495 	145:  uint32(3615),
  26496 	146:  uint32(3591),
  26497 	147:  uint32(3566),
  26498 	148:  uint32(3542),
  26499 	149:  uint32(3518),
  26500 	150:  uint32(3495),
  26501 	151:  uint32(3472),
  26502 	152:  uint32(3449),
  26503 	153:  uint32(3426),
  26504 	154:  uint32(3404),
  26505 	155:  uint32(3382),
  26506 	156:  uint32(3360),
  26507 	157:  uint32(3339),
  26508 	158:  uint32(3318),
  26509 	159:  uint32(3297),
  26510 	160:  uint32(3276),
  26511 	161:  uint32(3256),
  26512 	162:  uint32(3236),
  26513 	163:  uint32(3216),
  26514 	164:  uint32(3196),
  26515 	165:  uint32(3177),
  26516 	166:  uint32(3158),
  26517 	167:  uint32(3139),
  26518 	168:  uint32(3120),
  26519 	169:  uint32(3102),
  26520 	170:  uint32(3084),
  26521 	171:  uint32(3066),
  26522 	172:  uint32(3048),
  26523 	173:  uint32(3030),
  26524 	174:  uint32(3013),
  26525 	175:  uint32(2995),
  26526 	176:  uint32(2978),
  26527 	177:  uint32(2962),
  26528 	178:  uint32(2945),
  26529 	179:  uint32(2928),
  26530 	180:  uint32(2912),
  26531 	181:  uint32(2896),
  26532 	182:  uint32(2880),
  26533 	183:  uint32(2864),
  26534 	184:  uint32(2849),
  26535 	185:  uint32(2833),
  26536 	186:  uint32(2818),
  26537 	187:  uint32(2803),
  26538 	188:  uint32(2788),
  26539 	189:  uint32(2774),
  26540 	190:  uint32(2759),
  26541 	191:  uint32(2744),
  26542 	192:  uint32(2730),
  26543 	193:  uint32(2716),
  26544 	194:  uint32(2702),
  26545 	195:  uint32(2688),
  26546 	196:  uint32(2674),
  26547 	197:  uint32(2661),
  26548 	198:  uint32(2647),
  26549 	199:  uint32(2634),
  26550 	200:  uint32(2621),
  26551 	201:  uint32(2608),
  26552 	202:  uint32(2595),
  26553 	203:  uint32(2582),
  26554 	204:  uint32(2570),
  26555 	205:  uint32(2557),
  26556 	206:  uint32(2545),
  26557 	207:  uint32(2532),
  26558 	208:  uint32(2520),
  26559 	209:  uint32(2508),
  26560 	210:  uint32(2496),
  26561 	211:  uint32(2484),
  26562 	212:  uint32(2473),
  26563 	213:  uint32(2461),
  26564 	214:  uint32(2449),
  26565 	215:  uint32(2438),
  26566 	216:  uint32(2427),
  26567 	217:  uint32(2416),
  26568 	218:  uint32(2404),
  26569 	219:  uint32(2394),
  26570 	220:  uint32(2383),
  26571 	221:  uint32(2372),
  26572 	222:  uint32(2361),
  26573 	223:  uint32(2351),
  26574 	224:  uint32(2340),
  26575 	225:  uint32(2330),
  26576 	226:  uint32(2319),
  26577 	227:  uint32(2309),
  26578 	228:  uint32(2299),
  26579 	229:  uint32(2289),
  26580 	230:  uint32(2279),
  26581 	231:  uint32(2269),
  26582 	232:  uint32(2259),
  26583 	233:  uint32(2250),
  26584 	234:  uint32(2240),
  26585 	235:  uint32(2231),
  26586 	236:  uint32(2221),
  26587 	237:  uint32(2212),
  26588 	238:  uint32(2202),
  26589 	239:  uint32(2193),
  26590 	240:  uint32(2184),
  26591 	241:  uint32(2175),
  26592 	242:  uint32(2166),
  26593 	243:  uint32(2157),
  26594 	244:  uint32(2148),
  26595 	245:  uint32(2139),
  26596 	246:  uint32(2131),
  26597 	247:  uint32(2122),
  26598 	248:  uint32(2114),
  26599 	249:  uint32(2105),
  26600 	250:  uint32(2097),
  26601 	251:  uint32(2088),
  26602 	252:  uint32(2080),
  26603 	253:  uint32(2072),
  26604 	254:  uint32(2064),
  26605 	255:  uint32(2056),
  26606 	256:  uint32(2048),
  26607 	257:  uint32(2040),
  26608 	258:  uint32(2032),
  26609 	259:  uint32(2024),
  26610 	260:  uint32(2016),
  26611 	261:  uint32(2008),
  26612 	262:  uint32(2001),
  26613 	263:  uint32(1993),
  26614 	264:  uint32(1985),
  26615 	265:  uint32(1978),
  26616 	266:  uint32(1971),
  26617 	267:  uint32(1963),
  26618 	268:  uint32(1956),
  26619 	269:  uint32(1949),
  26620 	270:  uint32(1941),
  26621 	271:  uint32(1934),
  26622 	272:  uint32(1927),
  26623 	273:  uint32(1920),
  26624 	274:  uint32(1913),
  26625 	275:  uint32(1906),
  26626 	276:  uint32(1899),
  26627 	277:  uint32(1892),
  26628 	278:  uint32(1885),
  26629 	279:  uint32(1879),
  26630 	280:  uint32(1872),
  26631 	281:  uint32(1865),
  26632 	282:  uint32(1859),
  26633 	283:  uint32(1852),
  26634 	284:  uint32(1846),
  26635 	285:  uint32(1839),
  26636 	286:  uint32(1833),
  26637 	287:  uint32(1826),
  26638 	288:  uint32(1820),
  26639 	289:  uint32(1814),
  26640 	290:  uint32(1807),
  26641 	291:  uint32(1801),
  26642 	292:  uint32(1795),
  26643 	293:  uint32(1789),
  26644 	294:  uint32(1783),
  26645 	295:  uint32(1777),
  26646 	296:  uint32(1771),
  26647 	297:  uint32(1765),
  26648 	298:  uint32(1759),
  26649 	299:  uint32(1753),
  26650 	300:  uint32(1747),
  26651 	301:  uint32(1741),
  26652 	302:  uint32(1736),
  26653 	303:  uint32(1730),
  26654 	304:  uint32(1724),
  26655 	305:  uint32(1718),
  26656 	306:  uint32(1713),
  26657 	307:  uint32(1707),
  26658 	308:  uint32(1702),
  26659 	309:  uint32(1696),
  26660 	310:  uint32(1691),
  26661 	311:  uint32(1685),
  26662 	312:  uint32(1680),
  26663 	313:  uint32(1675),
  26664 	314:  uint32(1669),
  26665 	315:  uint32(1664),
  26666 	316:  uint32(1659),
  26667 	317:  uint32(1653),
  26668 	318:  uint32(1648),
  26669 	319:  uint32(1643),
  26670 	320:  uint32(1638),
  26671 	321:  uint32(1633),
  26672 	322:  uint32(1628),
  26673 	323:  uint32(1623),
  26674 	324:  uint32(1618),
  26675 	325:  uint32(1613),
  26676 	326:  uint32(1608),
  26677 	327:  uint32(1603),
  26678 	328:  uint32(1598),
  26679 	329:  uint32(1593),
  26680 	330:  uint32(1588),
  26681 	331:  uint32(1583),
  26682 	332:  uint32(1579),
  26683 	333:  uint32(1574),
  26684 	334:  uint32(1569),
  26685 	335:  uint32(1565),
  26686 	336:  uint32(1560),
  26687 	337:  uint32(1555),
  26688 	338:  uint32(1551),
  26689 	339:  uint32(1546),
  26690 	340:  uint32(1542),
  26691 	341:  uint32(1537),
  26692 	342:  uint32(1533),
  26693 	343:  uint32(1528),
  26694 	344:  uint32(1524),
  26695 	345:  uint32(1519),
  26696 	346:  uint32(1515),
  26697 	347:  uint32(1510),
  26698 	348:  uint32(1506),
  26699 	349:  uint32(1502),
  26700 	350:  uint32(1497),
  26701 	351:  uint32(1493),
  26702 	352:  uint32(1489),
  26703 	353:  uint32(1485),
  26704 	354:  uint32(1481),
  26705 	355:  uint32(1476),
  26706 	356:  uint32(1472),
  26707 	357:  uint32(1468),
  26708 	358:  uint32(1464),
  26709 	359:  uint32(1460),
  26710 	360:  uint32(1456),
  26711 	361:  uint32(1452),
  26712 	362:  uint32(1448),
  26713 	363:  uint32(1444),
  26714 	364:  uint32(1440),
  26715 	365:  uint32(1436),
  26716 	366:  uint32(1432),
  26717 	367:  uint32(1428),
  26718 	368:  uint32(1424),
  26719 	369:  uint32(1420),
  26720 	370:  uint32(1416),
  26721 	371:  uint32(1413),
  26722 	372:  uint32(1409),
  26723 	373:  uint32(1405),
  26724 	374:  uint32(1401),
  26725 	375:  uint32(1398),
  26726 	376:  uint32(1394),
  26727 	377:  uint32(1390),
  26728 	378:  uint32(1387),
  26729 	379:  uint32(1383),
  26730 	380:  uint32(1379),
  26731 	381:  uint32(1376),
  26732 	382:  uint32(1372),
  26733 	383:  uint32(1368),
  26734 	384:  uint32(1365),
  26735 	385:  uint32(1361),
  26736 	386:  uint32(1358),
  26737 	387:  uint32(1354),
  26738 	388:  uint32(1351),
  26739 	389:  uint32(1347),
  26740 	390:  uint32(1344),
  26741 	391:  uint32(1340),
  26742 	392:  uint32(1337),
  26743 	393:  uint32(1334),
  26744 	394:  uint32(1330),
  26745 	395:  uint32(1327),
  26746 	396:  uint32(1323),
  26747 	397:  uint32(1320),
  26748 	398:  uint32(1317),
  26749 	399:  uint32(1314),
  26750 	400:  uint32(1310),
  26751 	401:  uint32(1307),
  26752 	402:  uint32(1304),
  26753 	403:  uint32(1300),
  26754 	404:  uint32(1297),
  26755 	405:  uint32(1294),
  26756 	406:  uint32(1291),
  26757 	407:  uint32(1288),
  26758 	408:  uint32(1285),
  26759 	409:  uint32(1281),
  26760 	410:  uint32(1278),
  26761 	411:  uint32(1275),
  26762 	412:  uint32(1272),
  26763 	413:  uint32(1269),
  26764 	414:  uint32(1266),
  26765 	415:  uint32(1263),
  26766 	416:  uint32(1260),
  26767 	417:  uint32(1257),
  26768 	418:  uint32(1254),
  26769 	419:  uint32(1251),
  26770 	420:  uint32(1248),
  26771 	421:  uint32(1245),
  26772 	422:  uint32(1242),
  26773 	423:  uint32(1239),
  26774 	424:  uint32(1236),
  26775 	425:  uint32(1233),
  26776 	426:  uint32(1230),
  26777 	427:  uint32(1227),
  26778 	428:  uint32(1224),
  26779 	429:  uint32(1222),
  26780 	430:  uint32(1219),
  26781 	431:  uint32(1216),
  26782 	432:  uint32(1213),
  26783 	433:  uint32(1210),
  26784 	434:  uint32(1208),
  26785 	435:  uint32(1205),
  26786 	436:  uint32(1202),
  26787 	437:  uint32(1199),
  26788 	438:  uint32(1197),
  26789 	439:  uint32(1194),
  26790 	440:  uint32(1191),
  26791 	441:  uint32(1188),
  26792 	442:  uint32(1186),
  26793 	443:  uint32(1183),
  26794 	444:  uint32(1180),
  26795 	445:  uint32(1178),
  26796 	446:  uint32(1175),
  26797 	447:  uint32(1172),
  26798 	448:  uint32(1170),
  26799 	449:  uint32(1167),
  26800 	450:  uint32(1165),
  26801 	451:  uint32(1162),
  26802 	452:  uint32(1159),
  26803 	453:  uint32(1157),
  26804 	454:  uint32(1154),
  26805 	455:  uint32(1152),
  26806 	456:  uint32(1149),
  26807 	457:  uint32(1147),
  26808 	458:  uint32(1144),
  26809 	459:  uint32(1142),
  26810 	460:  uint32(1139),
  26811 	461:  uint32(1137),
  26812 	462:  uint32(1134),
  26813 	463:  uint32(1132),
  26814 	464:  uint32(1129),
  26815 	465:  uint32(1127),
  26816 	466:  uint32(1125),
  26817 	467:  uint32(1122),
  26818 	468:  uint32(1120),
  26819 	469:  uint32(1117),
  26820 	470:  uint32(1115),
  26821 	471:  uint32(1113),
  26822 	472:  uint32(1110),
  26823 	473:  uint32(1108),
  26824 	474:  uint32(1106),
  26825 	475:  uint32(1103),
  26826 	476:  uint32(1101),
  26827 	477:  uint32(1099),
  26828 	478:  uint32(1096),
  26829 	479:  uint32(1094),
  26830 	480:  uint32(1092),
  26831 	481:  uint32(1089),
  26832 	482:  uint32(1087),
  26833 	483:  uint32(1085),
  26834 	484:  uint32(1083),
  26835 	485:  uint32(1081),
  26836 	486:  uint32(1078),
  26837 	487:  uint32(1076),
  26838 	488:  uint32(1074),
  26839 	489:  uint32(1072),
  26840 	490:  uint32(1069),
  26841 	491:  uint32(1067),
  26842 	492:  uint32(1065),
  26843 	493:  uint32(1063),
  26844 	494:  uint32(1061),
  26845 	495:  uint32(1059),
  26846 	496:  uint32(1057),
  26847 	497:  uint32(1054),
  26848 	498:  uint32(1052),
  26849 	499:  uint32(1050),
  26850 	500:  uint32(1048),
  26851 	501:  uint32(1046),
  26852 	502:  uint32(1044),
  26853 	503:  uint32(1042),
  26854 	504:  uint32(1040),
  26855 	505:  uint32(1038),
  26856 	506:  uint32(1036),
  26857 	507:  uint32(1034),
  26858 	508:  uint32(1032),
  26859 	509:  uint32(1030),
  26860 	510:  uint32(1028),
  26861 	511:  uint32(1026),
  26862 	512:  uint32(1024),
  26863 	513:  uint32(1022),
  26864 	514:  uint32(1020),
  26865 	515:  uint32(1018),
  26866 	516:  uint32(1016),
  26867 	517:  uint32(1014),
  26868 	518:  uint32(1012),
  26869 	519:  uint32(1010),
  26870 	520:  uint32(1008),
  26871 	521:  uint32(1006),
  26872 	522:  uint32(1004),
  26873 	523:  uint32(1002),
  26874 	524:  uint32(1000),
  26875 	525:  uint32(998),
  26876 	526:  uint32(996),
  26877 	527:  uint32(994),
  26878 	528:  uint32(992),
  26879 	529:  uint32(991),
  26880 	530:  uint32(989),
  26881 	531:  uint32(987),
  26882 	532:  uint32(985),
  26883 	533:  uint32(983),
  26884 	534:  uint32(981),
  26885 	535:  uint32(979),
  26886 	536:  uint32(978),
  26887 	537:  uint32(976),
  26888 	538:  uint32(974),
  26889 	539:  uint32(972),
  26890 	540:  uint32(970),
  26891 	541:  uint32(969),
  26892 	542:  uint32(967),
  26893 	543:  uint32(965),
  26894 	544:  uint32(963),
  26895 	545:  uint32(961),
  26896 	546:  uint32(960),
  26897 	547:  uint32(958),
  26898 	548:  uint32(956),
  26899 	549:  uint32(954),
  26900 	550:  uint32(953),
  26901 	551:  uint32(951),
  26902 	552:  uint32(949),
  26903 	553:  uint32(948),
  26904 	554:  uint32(946),
  26905 	555:  uint32(944),
  26906 	556:  uint32(942),
  26907 	557:  uint32(941),
  26908 	558:  uint32(939),
  26909 	559:  uint32(937),
  26910 	560:  uint32(936),
  26911 	561:  uint32(934),
  26912 	562:  uint32(932),
  26913 	563:  uint32(931),
  26914 	564:  uint32(929),
  26915 	565:  uint32(927),
  26916 	566:  uint32(926),
  26917 	567:  uint32(924),
  26918 	568:  uint32(923),
  26919 	569:  uint32(921),
  26920 	570:  uint32(919),
  26921 	571:  uint32(918),
  26922 	572:  uint32(916),
  26923 	573:  uint32(914),
  26924 	574:  uint32(913),
  26925 	575:  uint32(911),
  26926 	576:  uint32(910),
  26927 	577:  uint32(908),
  26928 	578:  uint32(907),
  26929 	579:  uint32(905),
  26930 	580:  uint32(903),
  26931 	581:  uint32(902),
  26932 	582:  uint32(900),
  26933 	583:  uint32(899),
  26934 	584:  uint32(897),
  26935 	585:  uint32(896),
  26936 	586:  uint32(894),
  26937 	587:  uint32(893),
  26938 	588:  uint32(891),
  26939 	589:  uint32(890),
  26940 	590:  uint32(888),
  26941 	591:  uint32(887),
  26942 	592:  uint32(885),
  26943 	593:  uint32(884),
  26944 	594:  uint32(882),
  26945 	595:  uint32(881),
  26946 	596:  uint32(879),
  26947 	597:  uint32(878),
  26948 	598:  uint32(876),
  26949 	599:  uint32(875),
  26950 	600:  uint32(873),
  26951 	601:  uint32(872),
  26952 	602:  uint32(870),
  26953 	603:  uint32(869),
  26954 	604:  uint32(868),
  26955 	605:  uint32(866),
  26956 	606:  uint32(865),
  26957 	607:  uint32(863),
  26958 	608:  uint32(862),
  26959 	609:  uint32(860),
  26960 	610:  uint32(859),
  26961 	611:  uint32(858),
  26962 	612:  uint32(856),
  26963 	613:  uint32(855),
  26964 	614:  uint32(853),
  26965 	615:  uint32(852),
  26966 	616:  uint32(851),
  26967 	617:  uint32(849),
  26968 	618:  uint32(848),
  26969 	619:  uint32(846),
  26970 	620:  uint32(845),
  26971 	621:  uint32(844),
  26972 	622:  uint32(842),
  26973 	623:  uint32(841),
  26974 	624:  uint32(840),
  26975 	625:  uint32(838),
  26976 	626:  uint32(837),
  26977 	627:  uint32(836),
  26978 	628:  uint32(834),
  26979 	629:  uint32(833),
  26980 	630:  uint32(832),
  26981 	631:  uint32(830),
  26982 	632:  uint32(829),
  26983 	633:  uint32(828),
  26984 	634:  uint32(826),
  26985 	635:  uint32(825),
  26986 	636:  uint32(824),
  26987 	637:  uint32(823),
  26988 	638:  uint32(821),
  26989 	639:  uint32(820),
  26990 	640:  uint32(819),
  26991 	641:  uint32(817),
  26992 	642:  uint32(816),
  26993 	643:  uint32(815),
  26994 	644:  uint32(814),
  26995 	645:  uint32(812),
  26996 	646:  uint32(811),
  26997 	647:  uint32(810),
  26998 	648:  uint32(809),
  26999 	649:  uint32(807),
  27000 	650:  uint32(806),
  27001 	651:  uint32(805),
  27002 	652:  uint32(804),
  27003 	653:  uint32(802),
  27004 	654:  uint32(801),
  27005 	655:  uint32(800),
  27006 	656:  uint32(799),
  27007 	657:  uint32(798),
  27008 	658:  uint32(796),
  27009 	659:  uint32(795),
  27010 	660:  uint32(794),
  27011 	661:  uint32(793),
  27012 	662:  uint32(791),
  27013 	663:  uint32(790),
  27014 	664:  uint32(789),
  27015 	665:  uint32(788),
  27016 	666:  uint32(787),
  27017 	667:  uint32(786),
  27018 	668:  uint32(784),
  27019 	669:  uint32(783),
  27020 	670:  uint32(782),
  27021 	671:  uint32(781),
  27022 	672:  uint32(780),
  27023 	673:  uint32(779),
  27024 	674:  uint32(777),
  27025 	675:  uint32(776),
  27026 	676:  uint32(775),
  27027 	677:  uint32(774),
  27028 	678:  uint32(773),
  27029 	679:  uint32(772),
  27030 	680:  uint32(771),
  27031 	681:  uint32(769),
  27032 	682:  uint32(768),
  27033 	683:  uint32(767),
  27034 	684:  uint32(766),
  27035 	685:  uint32(765),
  27036 	686:  uint32(764),
  27037 	687:  uint32(763),
  27038 	688:  uint32(762),
  27039 	689:  uint32(760),
  27040 	690:  uint32(759),
  27041 	691:  uint32(758),
  27042 	692:  uint32(757),
  27043 	693:  uint32(756),
  27044 	694:  uint32(755),
  27045 	695:  uint32(754),
  27046 	696:  uint32(753),
  27047 	697:  uint32(752),
  27048 	698:  uint32(751),
  27049 	699:  uint32(750),
  27050 	700:  uint32(748),
  27051 	701:  uint32(747),
  27052 	702:  uint32(746),
  27053 	703:  uint32(745),
  27054 	704:  uint32(744),
  27055 	705:  uint32(743),
  27056 	706:  uint32(742),
  27057 	707:  uint32(741),
  27058 	708:  uint32(740),
  27059 	709:  uint32(739),
  27060 	710:  uint32(738),
  27061 	711:  uint32(737),
  27062 	712:  uint32(736),
  27063 	713:  uint32(735),
  27064 	714:  uint32(734),
  27065 	715:  uint32(733),
  27066 	716:  uint32(732),
  27067 	717:  uint32(731),
  27068 	718:  uint32(730),
  27069 	719:  uint32(729),
  27070 	720:  uint32(728),
  27071 	721:  uint32(727),
  27072 	722:  uint32(726),
  27073 	723:  uint32(725),
  27074 	724:  uint32(724),
  27075 	725:  uint32(723),
  27076 	726:  uint32(722),
  27077 	727:  uint32(721),
  27078 	728:  uint32(720),
  27079 	729:  uint32(719),
  27080 	730:  uint32(718),
  27081 	731:  uint32(717),
  27082 	732:  uint32(716),
  27083 	733:  uint32(715),
  27084 	734:  uint32(714),
  27085 	735:  uint32(713),
  27086 	736:  uint32(712),
  27087 	737:  uint32(711),
  27088 	738:  uint32(710),
  27089 	739:  uint32(709),
  27090 	740:  uint32(708),
  27091 	741:  uint32(707),
  27092 	742:  uint32(706),
  27093 	743:  uint32(705),
  27094 	744:  uint32(704),
  27095 	745:  uint32(703),
  27096 	746:  uint32(702),
  27097 	747:  uint32(701),
  27098 	748:  uint32(700),
  27099 	749:  uint32(699),
  27100 	750:  uint32(699),
  27101 	751:  uint32(698),
  27102 	752:  uint32(697),
  27103 	753:  uint32(696),
  27104 	754:  uint32(695),
  27105 	755:  uint32(694),
  27106 	756:  uint32(693),
  27107 	757:  uint32(692),
  27108 	758:  uint32(691),
  27109 	759:  uint32(690),
  27110 	760:  uint32(689),
  27111 	761:  uint32(688),
  27112 	762:  uint32(688),
  27113 	763:  uint32(687),
  27114 	764:  uint32(686),
  27115 	765:  uint32(685),
  27116 	766:  uint32(684),
  27117 	767:  uint32(683),
  27118 	768:  uint32(682),
  27119 	769:  uint32(681),
  27120 	770:  uint32(680),
  27121 	771:  uint32(680),
  27122 	772:  uint32(679),
  27123 	773:  uint32(678),
  27124 	774:  uint32(677),
  27125 	775:  uint32(676),
  27126 	776:  uint32(675),
  27127 	777:  uint32(674),
  27128 	778:  uint32(673),
  27129 	779:  uint32(673),
  27130 	780:  uint32(672),
  27131 	781:  uint32(671),
  27132 	782:  uint32(670),
  27133 	783:  uint32(669),
  27134 	784:  uint32(668),
  27135 	785:  uint32(667),
  27136 	786:  uint32(667),
  27137 	787:  uint32(666),
  27138 	788:  uint32(665),
  27139 	789:  uint32(664),
  27140 	790:  uint32(663),
  27141 	791:  uint32(662),
  27142 	792:  uint32(661),
  27143 	793:  uint32(661),
  27144 	794:  uint32(660),
  27145 	795:  uint32(659),
  27146 	796:  uint32(658),
  27147 	797:  uint32(657),
  27148 	798:  uint32(657),
  27149 	799:  uint32(656),
  27150 	800:  uint32(655),
  27151 	801:  uint32(654),
  27152 	802:  uint32(653),
  27153 	803:  uint32(652),
  27154 	804:  uint32(652),
  27155 	805:  uint32(651),
  27156 	806:  uint32(650),
  27157 	807:  uint32(649),
  27158 	808:  uint32(648),
  27159 	809:  uint32(648),
  27160 	810:  uint32(647),
  27161 	811:  uint32(646),
  27162 	812:  uint32(645),
  27163 	813:  uint32(644),
  27164 	814:  uint32(644),
  27165 	815:  uint32(643),
  27166 	816:  uint32(642),
  27167 	817:  uint32(641),
  27168 	818:  uint32(640),
  27169 	819:  uint32(640),
  27170 	820:  uint32(639),
  27171 	821:  uint32(638),
  27172 	822:  uint32(637),
  27173 	823:  uint32(637),
  27174 	824:  uint32(636),
  27175 	825:  uint32(635),
  27176 	826:  uint32(634),
  27177 	827:  uint32(633),
  27178 	828:  uint32(633),
  27179 	829:  uint32(632),
  27180 	830:  uint32(631),
  27181 	831:  uint32(630),
  27182 	832:  uint32(630),
  27183 	833:  uint32(629),
  27184 	834:  uint32(628),
  27185 	835:  uint32(627),
  27186 	836:  uint32(627),
  27187 	837:  uint32(626),
  27188 	838:  uint32(625),
  27189 	839:  uint32(624),
  27190 	840:  uint32(624),
  27191 	841:  uint32(623),
  27192 	842:  uint32(622),
  27193 	843:  uint32(621),
  27194 	844:  uint32(621),
  27195 	845:  uint32(620),
  27196 	846:  uint32(619),
  27197 	847:  uint32(618),
  27198 	848:  uint32(618),
  27199 	849:  uint32(617),
  27200 	850:  uint32(616),
  27201 	851:  uint32(616),
  27202 	852:  uint32(615),
  27203 	853:  uint32(614),
  27204 	854:  uint32(613),
  27205 	855:  uint32(613),
  27206 	856:  uint32(612),
  27207 	857:  uint32(611),
  27208 	858:  uint32(611),
  27209 	859:  uint32(610),
  27210 	860:  uint32(609),
  27211 	861:  uint32(608),
  27212 	862:  uint32(608),
  27213 	863:  uint32(607),
  27214 	864:  uint32(606),
  27215 	865:  uint32(606),
  27216 	866:  uint32(605),
  27217 	867:  uint32(604),
  27218 	868:  uint32(604),
  27219 	869:  uint32(603),
  27220 	870:  uint32(602),
  27221 	871:  uint32(601),
  27222 	872:  uint32(601),
  27223 	873:  uint32(600),
  27224 	874:  uint32(599),
  27225 	875:  uint32(599),
  27226 	876:  uint32(598),
  27227 	877:  uint32(597),
  27228 	878:  uint32(597),
  27229 	879:  uint32(596),
  27230 	880:  uint32(595),
  27231 	881:  uint32(595),
  27232 	882:  uint32(594),
  27233 	883:  uint32(593),
  27234 	884:  uint32(593),
  27235 	885:  uint32(592),
  27236 	886:  uint32(591),
  27237 	887:  uint32(591),
  27238 	888:  uint32(590),
  27239 	889:  uint32(589),
  27240 	890:  uint32(589),
  27241 	891:  uint32(588),
  27242 	892:  uint32(587),
  27243 	893:  uint32(587),
  27244 	894:  uint32(586),
  27245 	895:  uint32(585),
  27246 	896:  uint32(585),
  27247 	897:  uint32(584),
  27248 	898:  uint32(583),
  27249 	899:  uint32(583),
  27250 	900:  uint32(582),
  27251 	901:  uint32(581),
  27252 	902:  uint32(581),
  27253 	903:  uint32(580),
  27254 	904:  uint32(579),
  27255 	905:  uint32(579),
  27256 	906:  uint32(578),
  27257 	907:  uint32(578),
  27258 	908:  uint32(577),
  27259 	909:  uint32(576),
  27260 	910:  uint32(576),
  27261 	911:  uint32(575),
  27262 	912:  uint32(574),
  27263 	913:  uint32(574),
  27264 	914:  uint32(573),
  27265 	915:  uint32(572),
  27266 	916:  uint32(572),
  27267 	917:  uint32(571),
  27268 	918:  uint32(571),
  27269 	919:  uint32(570),
  27270 	920:  uint32(569),
  27271 	921:  uint32(569),
  27272 	922:  uint32(568),
  27273 	923:  uint32(568),
  27274 	924:  uint32(567),
  27275 	925:  uint32(566),
  27276 	926:  uint32(566),
  27277 	927:  uint32(565),
  27278 	928:  uint32(564),
  27279 	929:  uint32(564),
  27280 	930:  uint32(563),
  27281 	931:  uint32(563),
  27282 	932:  uint32(562),
  27283 	933:  uint32(561),
  27284 	934:  uint32(561),
  27285 	935:  uint32(560),
  27286 	936:  uint32(560),
  27287 	937:  uint32(559),
  27288 	938:  uint32(558),
  27289 	939:  uint32(558),
  27290 	940:  uint32(557),
  27291 	941:  uint32(557),
  27292 	942:  uint32(556),
  27293 	943:  uint32(555),
  27294 	944:  uint32(555),
  27295 	945:  uint32(554),
  27296 	946:  uint32(554),
  27297 	947:  uint32(553),
  27298 	948:  uint32(553),
  27299 	949:  uint32(552),
  27300 	950:  uint32(551),
  27301 	951:  uint32(551),
  27302 	952:  uint32(550),
  27303 	953:  uint32(550),
  27304 	954:  uint32(549),
  27305 	955:  uint32(548),
  27306 	956:  uint32(548),
  27307 	957:  uint32(547),
  27308 	958:  uint32(547),
  27309 	959:  uint32(546),
  27310 	960:  uint32(546),
  27311 	961:  uint32(545),
  27312 	962:  uint32(544),
  27313 	963:  uint32(544),
  27314 	964:  uint32(543),
  27315 	965:  uint32(543),
  27316 	966:  uint32(542),
  27317 	967:  uint32(542),
  27318 	968:  uint32(541),
  27319 	969:  uint32(541),
  27320 	970:  uint32(540),
  27321 	971:  uint32(539),
  27322 	972:  uint32(539),
  27323 	973:  uint32(538),
  27324 	974:  uint32(538),
  27325 	975:  uint32(537),
  27326 	976:  uint32(537),
  27327 	977:  uint32(536),
  27328 	978:  uint32(536),
  27329 	979:  uint32(535),
  27330 	980:  uint32(534),
  27331 	981:  uint32(534),
  27332 	982:  uint32(533),
  27333 	983:  uint32(533),
  27334 	984:  uint32(532),
  27335 	985:  uint32(532),
  27336 	986:  uint32(531),
  27337 	987:  uint32(531),
  27338 	988:  uint32(530),
  27339 	989:  uint32(530),
  27340 	990:  uint32(529),
  27341 	991:  uint32(529),
  27342 	992:  uint32(528),
  27343 	993:  uint32(527),
  27344 	994:  uint32(527),
  27345 	995:  uint32(526),
  27346 	996:  uint32(526),
  27347 	997:  uint32(525),
  27348 	998:  uint32(525),
  27349 	999:  uint32(524),
  27350 	1000: uint32(524),
  27351 	1001: uint32(523),
  27352 	1002: uint32(523),
  27353 	1003: uint32(522),
  27354 	1004: uint32(522),
  27355 	1005: uint32(521),
  27356 	1006: uint32(521),
  27357 	1007: uint32(520),
  27358 	1008: uint32(520),
  27359 	1009: uint32(519),
  27360 	1010: uint32(519),
  27361 	1011: uint32(518),
  27362 	1012: uint32(518),
  27363 	1013: uint32(517),
  27364 	1014: uint32(517),
  27365 	1015: uint32(516),
  27366 	1016: uint32(516),
  27367 	1017: uint32(515),
  27368 	1018: uint32(515),
  27369 	1019: uint32(514),
  27370 	1020: uint32(514),
  27371 }
  27372 
  27373 // Note that LinearToGamma() expects the values to be premultiplied by 4,
  27374 // so we incorporate this factor 4 inside the DIVIDE_BY_ALPHA macro directly.
  27375 
  27376 func LinearToGammaWeighted(tls *libc.TLS, src uintptr, a_ptr uintptr, total_a uint32_t, step int32, rgb_stride int32) (r int32) {
  27377 	var sum uint32_t
  27378 	_ = sum
  27379 	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))))
  27380 	return LinearToGamma(tls, sum*kInvAlpha[total_a]>>(kAlphaFix-libc.Int32FromInt32(2)), 0)
  27381 }
  27382 
  27383 func ConvertRowToY(tls *libc.TLS, r_ptr uintptr, g_ptr uintptr, b_ptr uintptr, step int32, dst_y uintptr, width int32, rg uintptr) {
  27384 	var i, j int32
  27385 	_, _ = i, j
  27386 	i = 0
  27387 	j = libc.Int32FromInt32(0)
  27388 	for {
  27389 		if !(i < width) {
  27390 			break
  27391 		}
  27392 		**(**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))
  27393 		goto _1
  27394 	_1:
  27395 		;
  27396 		i = i + int32(1)
  27397 		j = j + step
  27398 	}
  27399 }
  27400 
  27401 func AccumulateRGBA(tls *libc.TLS, r_ptr uintptr, g_ptr uintptr, b_ptr uintptr, a_ptr uintptr, rgb_stride int32, dst uintptr, width int32) {
  27402 	var a, a1 uint32_t
  27403 	var b, b1, g, g1, i, j, r, r1 int32
  27404 	_, _, _, _, _, _, _, _, _, _ = a, a1, b, b1, g, g1, i, j, r, r1
  27405 	// we loop over 2x2 blocks and produce one R/G/B/A value for each.
  27406 	i = 0
  27407 	j = libc.Int32FromInt32(0)
  27408 	for {
  27409 		if !(i < width>>int32(1)) {
  27410 			break
  27411 		}
  27412 		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))))))
  27413 		if a == uint32(libc.Int32FromInt32(4)*libc.Int32FromInt32(0xff)) || a == uint32(0) {
  27414 			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)
  27415 			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)
  27416 			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)
  27417 		} else {
  27418 			r = LinearToGammaWeighted(tls, r_ptr+uintptr(j), a_ptr+uintptr(j), a, int32(4), rgb_stride)
  27419 			g = LinearToGammaWeighted(tls, g_ptr+uintptr(j), a_ptr+uintptr(j), a, int32(4), rgb_stride)
  27420 			b = LinearToGammaWeighted(tls, b_ptr+uintptr(j), a_ptr+uintptr(j), a, int32(4), rgb_stride)
  27421 		}
  27422 		**(**uint16_t)(__ccgo_up(dst)) = uint16(r)
  27423 		**(**uint16_t)(__ccgo_up(dst + 1*2)) = uint16(g)
  27424 		**(**uint16_t)(__ccgo_up(dst + 2*2)) = uint16(b)
  27425 		**(**uint16_t)(__ccgo_up(dst + 3*2)) = uint16(a)
  27426 		goto _1
  27427 	_1:
  27428 		;
  27429 		i = i + int32(1)
  27430 		j = j + libc.Int32FromInt32(2)*libc.Int32FromInt32(4)
  27431 		dst = dst + uintptr(4)*2
  27432 	}
  27433 	if width&int32(1) != 0 {
  27434 		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)))))
  27435 		if a1 == uint32(libc.Int32FromInt32(4)*libc.Int32FromInt32(0xff)) || a1 == uint32(0) {
  27436 			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))
  27437 			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))
  27438 			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))
  27439 		} else {
  27440 			r1 = LinearToGammaWeighted(tls, r_ptr+uintptr(j), a_ptr+uintptr(j), a1, 0, rgb_stride)
  27441 			g1 = LinearToGammaWeighted(tls, g_ptr+uintptr(j), a_ptr+uintptr(j), a1, 0, rgb_stride)
  27442 			b1 = LinearToGammaWeighted(tls, b_ptr+uintptr(j), a_ptr+uintptr(j), a1, 0, rgb_stride)
  27443 		}
  27444 		**(**uint16_t)(__ccgo_up(dst)) = uint16(r1)
  27445 		**(**uint16_t)(__ccgo_up(dst + 1*2)) = uint16(g1)
  27446 		**(**uint16_t)(__ccgo_up(dst + 2*2)) = uint16(b1)
  27447 		**(**uint16_t)(__ccgo_up(dst + 3*2)) = uint16(a1)
  27448 	}
  27449 }
  27450 
  27451 func AccumulateRGB(tls *libc.TLS, r_ptr uintptr, g_ptr uintptr, b_ptr uintptr, step int32, rgb_stride int32, dst uintptr, width int32) {
  27452 	var i, j int32
  27453 	_, _ = i, j
  27454 	i = 0
  27455 	j = libc.Int32FromInt32(0)
  27456 	for {
  27457 		if !(i < width>>int32(1)) {
  27458 			break
  27459 		}
  27460 		**(**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))
  27461 		**(**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))
  27462 		**(**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))
  27463 		// MemorySanitizer may raise false positives with data that passes through
  27464 		// RGBA32PackedToPlanar_16b_SSE41() due to incorrect modeling of shuffles.
  27465 		// See https://crbug.com/webp/573.
  27466 		goto _1
  27467 	_1:
  27468 		;
  27469 		i = i + int32(1)
  27470 		j = j + int32(2)*step
  27471 		dst = dst + uintptr(4)*2
  27472 	}
  27473 	if width&int32(1) != 0 {
  27474 		**(**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)))
  27475 		**(**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)))
  27476 		**(**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)))
  27477 	}
  27478 }
  27479 
  27480 func ConvertRowsToUV(tls *libc.TLS, rgb uintptr, dst_u uintptr, dst_v uintptr, width int32, rg uintptr) {
  27481 	var b, g, i, r int32
  27482 	_, _, _, _ = b, g, i, r
  27483 	i = 0
  27484 	for {
  27485 		if !(i < width) {
  27486 			break
  27487 		}
  27488 		r = int32(**(**uint16_t)(__ccgo_up(rgb)))
  27489 		g = int32(**(**uint16_t)(__ccgo_up(rgb + 1*2)))
  27490 		b = int32(**(**uint16_t)(__ccgo_up(rgb + 2*2)))
  27491 		**(**uint8_t)(__ccgo_up(dst_u + uintptr(i))) = uint8(RGBToU(tls, r, g, b, rg))
  27492 		**(**uint8_t)(__ccgo_up(dst_v + uintptr(i))) = uint8(RGBToV(tls, r, g, b, rg))
  27493 		goto _1
  27494 	_1:
  27495 		;
  27496 		i = i + int32(1)
  27497 		rgb = rgb + uintptr(4)*2
  27498 	}
  27499 }
  27500 
  27501 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) {
  27502 	bp := tls.Alloc(240)
  27503 	defer tls.Free(240)
  27504 	var dst_a, dst_u, dst_v, dst_y, rg, tmp_rgb uintptr
  27505 	var has_alpha, height, is_rgb, row_has_alpha, rows_have_alpha, use_dsp, uv_width, width, y, v1 int32
  27506 	var _ /* base_rg at bp+0 */ VP8Random
  27507 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  27508 	width = (*WebPPicture)(unsafe.Pointer(picture)).Fwidth
  27509 	height = (*WebPPicture)(unsafe.Pointer(picture)).Fheight
  27510 	has_alpha = CheckNonOpaque(tls, a_ptr, width, height, step, rgb_stride)
  27511 	is_rgb = libc.BoolInt32(r_ptr < b_ptr) // otherwise it's bgr
  27512 	if has_alpha != 0 {
  27513 		v1 = int32(WEBP_YUV420A)
  27514 	} else {
  27515 		v1 = int32(WEBP_YUV420)
  27516 	}
  27517 	(*WebPPicture)(unsafe.Pointer(picture)).Fcolorspace = v1
  27518 	(*WebPPicture)(unsafe.Pointer(picture)).Fuse_argb = 0
  27519 	// disable smart conversion if source is too small (overkill).
  27520 	if width < kMinDimensionIterativeConversion || height < kMinDimensionIterativeConversion {
  27521 		use_iterative_conversion = 0
  27522 	}
  27523 	if !(WebPPictureAllocYUVA(tls, picture) != 0) {
  27524 		return 0
  27525 	}
  27526 	if has_alpha != 0 {
  27527 	}
  27528 	if use_iterative_conversion != 0 {
  27529 		SharpYuvInit(tls, VP8GetCPUInfo)
  27530 		if !(PreprocessARGB(tls, r_ptr, g_ptr, b_ptr, step, rgb_stride, picture) != 0) {
  27531 			return 0
  27532 		}
  27533 		if has_alpha != 0 {
  27534 			(*(*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)
  27535 		}
  27536 	} else {
  27537 		uv_width = (width + int32(1)) >> int32(1)
  27538 		use_dsp = libc.BoolInt32(step == int32(3)) // use special function in this case
  27539 		// temporary storage for accumulated R/G/B values during conversion to U/V
  27540 		tmp_rgb = WebPSafeMalloc(tls, uint64(int32(4)*uv_width), uint64(2))
  27541 		dst_y = (*WebPPicture)(unsafe.Pointer(picture)).Fy
  27542 		dst_u = (*WebPPicture)(unsafe.Pointer(picture)).Fu
  27543 		dst_v = (*WebPPicture)(unsafe.Pointer(picture)).Fv
  27544 		dst_a = (*WebPPicture)(unsafe.Pointer(picture)).Fa
  27545 		rg = libc.UintptrFromInt32(0)
  27546 		if float64(dithering) > float64(0) {
  27547 			VP8InitRandom(tls, bp, dithering)
  27548 			rg = bp
  27549 			use_dsp = 0 // can't use dsp in this case
  27550 		}
  27551 		WebPInitConvertARGBToYUV(tls)
  27552 		InitGammaTables(tls)
  27553 		if tmp_rgb == libc.UintptrFromInt32(0) {
  27554 			return WebPEncodingSetError(tls, picture, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  27555 		}
  27556 		// Downsample Y/U/V planes, two rows at a time
  27557 		y = 0
  27558 		for {
  27559 			if !(y < height>>libc.Int32FromInt32(1)) {
  27560 				break
  27561 			}
  27562 			rows_have_alpha = has_alpha
  27563 			if use_dsp != 0 {
  27564 				if is_rgb != 0 {
  27565 					(*(*func(*libc.TLS, uintptr, uintptr, int32))(unsafe.Pointer(&struct{ uintptr }{WebPConvertRGB24ToY})))(tls, r_ptr, dst_y, width)
  27566 					(*(*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)
  27567 				} else {
  27568 					(*(*func(*libc.TLS, uintptr, uintptr, int32))(unsafe.Pointer(&struct{ uintptr }{WebPConvertBGR24ToY})))(tls, b_ptr, dst_y, width)
  27569 					(*(*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)
  27570 				}
  27571 			} else {
  27572 				ConvertRowToY(tls, r_ptr, g_ptr, b_ptr, step, dst_y, width, rg)
  27573 				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)
  27574 			}
  27575 			dst_y = dst_y + uintptr(int32(2)*(*WebPPicture)(unsafe.Pointer(picture)).Fy_stride)
  27576 			if has_alpha != 0 {
  27577 				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))
  27578 				dst_a = dst_a + uintptr(int32(2)*(*WebPPicture)(unsafe.Pointer(picture)).Fa_stride)
  27579 			}
  27580 			// Collect averaged R/G/B(/A)
  27581 			if !(rows_have_alpha != 0) {
  27582 				AccumulateRGB(tls, r_ptr, g_ptr, b_ptr, step, rgb_stride, tmp_rgb, width)
  27583 			} else {
  27584 				AccumulateRGBA(tls, r_ptr, g_ptr, b_ptr, a_ptr, rgb_stride, tmp_rgb, width)
  27585 			}
  27586 			// Convert to U/V
  27587 			if rg == libc.UintptrFromInt32(0) {
  27588 				(*(*func(*libc.TLS, uintptr, uintptr, uintptr, int32))(unsafe.Pointer(&struct{ uintptr }{WebPConvertRGBA32ToUV})))(tls, tmp_rgb, dst_u, dst_v, uv_width)
  27589 			} else {
  27590 				ConvertRowsToUV(tls, tmp_rgb, dst_u, dst_v, uv_width, rg)
  27591 			}
  27592 			dst_u = dst_u + uintptr((*WebPPicture)(unsafe.Pointer(picture)).Fuv_stride)
  27593 			dst_v = dst_v + uintptr((*WebPPicture)(unsafe.Pointer(picture)).Fuv_stride)
  27594 			r_ptr = r_ptr + uintptr(int32(2)*rgb_stride)
  27595 			b_ptr = b_ptr + uintptr(int32(2)*rgb_stride)
  27596 			g_ptr = g_ptr + uintptr(int32(2)*rgb_stride)
  27597 			if has_alpha != 0 {
  27598 				a_ptr = a_ptr + uintptr(int32(2)*rgb_stride)
  27599 			}
  27600 			goto _2
  27601 		_2:
  27602 			;
  27603 			y = y + 1
  27604 		}
  27605 		if height&int32(1) != 0 { // extra last row
  27606 			row_has_alpha = has_alpha
  27607 			if use_dsp != 0 {
  27608 				if r_ptr < b_ptr {
  27609 					(*(*func(*libc.TLS, uintptr, uintptr, int32))(unsafe.Pointer(&struct{ uintptr }{WebPConvertRGB24ToY})))(tls, r_ptr, dst_y, width)
  27610 				} else {
  27611 					(*(*func(*libc.TLS, uintptr, uintptr, int32))(unsafe.Pointer(&struct{ uintptr }{WebPConvertBGR24ToY})))(tls, b_ptr, dst_y, width)
  27612 				}
  27613 			} else {
  27614 				ConvertRowToY(tls, r_ptr, g_ptr, b_ptr, step, dst_y, width, rg)
  27615 			}
  27616 			if row_has_alpha != 0 {
  27617 				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))
  27618 			}
  27619 			// Collect averaged R/G/B(/A)
  27620 			if !(row_has_alpha != 0) {
  27621 				// Collect averaged R/G/B
  27622 				AccumulateRGB(tls, r_ptr, g_ptr, b_ptr, step, 0, tmp_rgb, width)
  27623 			} else {
  27624 				AccumulateRGBA(tls, r_ptr, g_ptr, b_ptr, a_ptr, 0, tmp_rgb, width)
  27625 			}
  27626 			if rg == libc.UintptrFromInt32(0) {
  27627 				(*(*func(*libc.TLS, uintptr, uintptr, uintptr, int32))(unsafe.Pointer(&struct{ uintptr }{WebPConvertRGBA32ToUV})))(tls, tmp_rgb, dst_u, dst_v, uv_width)
  27628 			} else {
  27629 				ConvertRowsToUV(tls, tmp_rgb, dst_u, dst_v, uv_width, rg)
  27630 			}
  27631 		}
  27632 		WebPSafeFree(tls, tmp_rgb)
  27633 	}
  27634 	return int32(1)
  27635 }
  27636 
  27637 //------------------------------------------------------------------------------
  27638 // call for ARGB->YUVA conversion
  27639 
  27640 func PictureARGBToYUVA(tls *libc.TLS, picture uintptr, colorspace WebPEncCSP1, dithering float32, use_iterative_conversion int32) (r1 int32) {
  27641 	var a, argb, b, g, r uintptr
  27642 	_, _, _, _, _ = a, argb, b, g, r
  27643 	if picture == libc.UintptrFromInt32(0) {
  27644 		return 0
  27645 	}
  27646 	if (*WebPPicture)(unsafe.Pointer(picture)).Fargb == libc.UintptrFromInt32(0) {
  27647 		return WebPEncodingSetError(tls, picture, int32(VP8_ENC_ERROR_NULL_PARAMETER))
  27648 	} else {
  27649 		if colorspace&int32(WEBP_CSP_UV_MASK) != int32(WEBP_YUV420) {
  27650 			return WebPEncodingSetError(tls, picture, int32(VP8_ENC_ERROR_INVALID_CONFIGURATION))
  27651 		} else {
  27652 			argb = (*WebPPicture)(unsafe.Pointer(picture)).Fargb
  27653 			a = argb + uintptr(libc.Int32FromInt32(3)-libc.Int32FromInt32(0))
  27654 			r = argb + uintptr(libc.Int32FromInt32(3)-libc.Int32FromInt32(1))
  27655 			g = argb + uintptr(libc.Int32FromInt32(3)-libc.Int32FromInt32(2))
  27656 			b = argb + uintptr(libc.Int32FromInt32(3)-libc.Int32FromInt32(3))
  27657 			(*WebPPicture)(unsafe.Pointer(picture)).Fcolorspace = int32(WEBP_YUV420)
  27658 			return ImportYUVAFromRGBA(tls, r, g, b, a, int32(4), int32(4)*(*WebPPicture)(unsafe.Pointer(picture)).Fargb_stride, dithering, use_iterative_conversion, picture)
  27659 		}
  27660 	}
  27661 	return r1
  27662 }
  27663 
  27664 func WebPPictureARGBToYUVADithered(tls *libc.TLS, picture uintptr, colorspace WebPEncCSP1, dithering float32) (r int32) {
  27665 	return PictureARGBToYUVA(tls, picture, colorspace, dithering, 0)
  27666 }
  27667 
  27668 func WebPPictureARGBToYUVA(tls *libc.TLS, picture uintptr, colorspace WebPEncCSP1) (r int32) {
  27669 	return PictureARGBToYUVA(tls, picture, colorspace, libc.Float32FromFloat32(0), 0)
  27670 }
  27671 
  27672 func WebPPictureSharpARGBToYUVA(tls *libc.TLS, picture uintptr) (r int32) {
  27673 	return PictureARGBToYUVA(tls, picture, int32(WEBP_YUV420), libc.Float32FromFloat32(0), int32(1))
  27674 }
  27675 
  27676 // C documentation
  27677 //
  27678 //	// for backward compatibility
  27679 func WebPPictureSmartARGBToYUVA(tls *libc.TLS, picture uintptr) (r int32) {
  27680 	return WebPPictureSharpARGBToYUVA(tls, picture)
  27681 }
  27682 
  27683 //------------------------------------------------------------------------------
  27684 // call for YUVA -> ARGB conversion
  27685 
  27686 func WebPPictureYUVAToARGB(tls *libc.TLS, picture uintptr) (r int32) {
  27687 	var argb_dst, cur_u, cur_v, cur_y, dst, src, top_u, top_v uintptr
  27688 	var argb_stride, height, width, x, y int32
  27689 	var upsample WebPUpsampleLinePairFunc
  27690 	_, _, _, _, _, _, _, _, _, _, _, _, _, _ = argb_dst, argb_stride, cur_u, cur_v, cur_y, dst, height, src, top_u, top_v, upsample, width, x, y
  27691 	if picture == libc.UintptrFromInt32(0) {
  27692 		return 0
  27693 	}
  27694 	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) {
  27695 		return WebPEncodingSetError(tls, picture, int32(VP8_ENC_ERROR_NULL_PARAMETER))
  27696 	}
  27697 	if (*WebPPicture)(unsafe.Pointer(picture)).Fcolorspace&int32(WEBP_CSP_ALPHA_BIT) != 0 && (*WebPPicture)(unsafe.Pointer(picture)).Fa == libc.UintptrFromInt32(0) {
  27698 		return WebPEncodingSetError(tls, picture, int32(VP8_ENC_ERROR_NULL_PARAMETER))
  27699 	}
  27700 	if (*WebPPicture)(unsafe.Pointer(picture)).Fcolorspace&int32(WEBP_CSP_UV_MASK) != int32(WEBP_YUV420) {
  27701 		return WebPEncodingSetError(tls, picture, int32(VP8_ENC_ERROR_INVALID_CONFIGURATION))
  27702 	}
  27703 	// Allocate a new argb buffer (discarding the previous one).
  27704 	if !(WebPPictureAllocARGB(tls, picture) != 0) {
  27705 		return 0
  27706 	}
  27707 	(*WebPPicture)(unsafe.Pointer(picture)).Fuse_argb = int32(1)
  27708 	// Convert
  27709 	width = (*WebPPicture)(unsafe.Pointer(picture)).Fwidth
  27710 	height = (*WebPPicture)(unsafe.Pointer(picture)).Fheight
  27711 	argb_stride = int32(4) * (*WebPPicture)(unsafe.Pointer(picture)).Fargb_stride
  27712 	dst = (*WebPPicture)(unsafe.Pointer(picture)).Fargb
  27713 	cur_u = (*WebPPicture)(unsafe.Pointer(picture)).Fu
  27714 	cur_v = (*WebPPicture)(unsafe.Pointer(picture)).Fv
  27715 	cur_y = (*WebPPicture)(unsafe.Pointer(picture)).Fy
  27716 	upsample = WebPGetLinePairConverter(tls, libc.BoolInt32(libc.Int32FromInt32(3)-libc.Int32FromInt32(0) > 0))
  27717 	// First row, with replicated top samples.
  27718 	(*(*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)
  27719 	cur_y = cur_y + uintptr((*WebPPicture)(unsafe.Pointer(picture)).Fy_stride)
  27720 	dst = dst + uintptr(argb_stride)
  27721 	// Center rows.
  27722 	y = int32(1)
  27723 	for {
  27724 		if !(y+int32(1) < height) {
  27725 			break
  27726 		}
  27727 		top_u = cur_u
  27728 		top_v = cur_v
  27729 		cur_u = cur_u + uintptr((*WebPPicture)(unsafe.Pointer(picture)).Fuv_stride)
  27730 		cur_v = cur_v + uintptr((*WebPPicture)(unsafe.Pointer(picture)).Fuv_stride)
  27731 		(*(*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)
  27732 		cur_y = cur_y + uintptr(int32(2)*(*WebPPicture)(unsafe.Pointer(picture)).Fy_stride)
  27733 		dst = dst + uintptr(int32(2)*argb_stride)
  27734 		goto _1
  27735 	_1:
  27736 		;
  27737 		y = y + int32(2)
  27738 	}
  27739 	// Last row (if needed), with replicated bottom samples.
  27740 	if height > int32(1) && !(height&libc.Int32FromInt32(1) != 0) {
  27741 		(*(*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)
  27742 	}
  27743 	// Insert alpha values if needed, in replacement for the default 0xff ones.
  27744 	if (*WebPPicture)(unsafe.Pointer(picture)).Fcolorspace&int32(WEBP_CSP_ALPHA_BIT) != 0 {
  27745 		y = 0
  27746 		for {
  27747 			if !(y < height) {
  27748 				break
  27749 			}
  27750 			argb_dst = (*WebPPicture)(unsafe.Pointer(picture)).Fargb + uintptr(y*(*WebPPicture)(unsafe.Pointer(picture)).Fargb_stride)*4
  27751 			src = (*WebPPicture)(unsafe.Pointer(picture)).Fa + uintptr(y*(*WebPPicture)(unsafe.Pointer(picture)).Fa_stride)
  27752 			x = 0
  27753 			for {
  27754 				if !(x < width) {
  27755 					break
  27756 				}
  27757 				**(**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)
  27758 				goto _3
  27759 			_3:
  27760 				;
  27761 				x = x + 1
  27762 			}
  27763 			goto _2
  27764 		_2:
  27765 			;
  27766 			y = y + 1
  27767 		}
  27768 	}
  27769 	return int32(1)
  27770 }
  27771 
  27772 //------------------------------------------------------------------------------
  27773 // automatic import / conversion
  27774 
  27775 func Import(tls *libc.TLS, picture uintptr, rgb uintptr, rgb_stride int32, step int32, swap_rb int32, import_alpha int32) (r int32) {
  27776 	var a_ptr, b_ptr, dst, dst1, g_ptr, r_ptr, v4 uintptr
  27777 	var do_copy, height, width, y, v1, v2, v3 int32
  27778 	_, _, _, _, _, _, _, _, _, _, _, _, _, _ = a_ptr, b_ptr, do_copy, dst, dst1, g_ptr, height, r_ptr, width, y, v1, v2, v3, v4
  27779 	if swap_rb != 0 {
  27780 		v1 = int32(2)
  27781 	} else {
  27782 		v1 = 0
  27783 	}
  27784 	// swap_rb -> b,g,r,a , !swap_rb -> r,g,b,a
  27785 	r_ptr = rgb + uintptr(v1)
  27786 	g_ptr = rgb + uintptr(1)
  27787 	if swap_rb != 0 {
  27788 		v2 = 0
  27789 	} else {
  27790 		v2 = int32(2)
  27791 	}
  27792 	b_ptr = rgb + uintptr(v2)
  27793 	width = (*WebPPicture)(unsafe.Pointer(picture)).Fwidth
  27794 	height = (*WebPPicture)(unsafe.Pointer(picture)).Fheight
  27795 	if import_alpha != 0 {
  27796 		v3 = int32(4)
  27797 	} else {
  27798 		v3 = int32(3)
  27799 	}
  27800 	if libc.Xabs(tls, rgb_stride) < v3*width {
  27801 		return 0
  27802 	}
  27803 	if !((*WebPPicture)(unsafe.Pointer(picture)).Fuse_argb != 0) {
  27804 		if import_alpha != 0 {
  27805 			v4 = rgb + uintptr(3)
  27806 		} else {
  27807 			v4 = libc.UintptrFromInt32(0)
  27808 		}
  27809 		a_ptr = v4
  27810 		return ImportYUVAFromRGBA(tls, r_ptr, g_ptr, b_ptr, a_ptr, step, rgb_stride, libc.Float32FromFloat32(0), 0, picture)
  27811 	}
  27812 	if !(WebPPictureAlloc(tls, picture) != 0) {
  27813 		return 0
  27814 	}
  27815 	VP8LDspInit(tls)
  27816 	WebPInitAlphaProcessing(tls)
  27817 	if import_alpha != 0 {
  27818 		// dst[] byte order is {a,r,g,b} for big-endian, {b,g,r,a} for little endian
  27819 		dst = (*WebPPicture)(unsafe.Pointer(picture)).Fargb
  27820 		do_copy = libc.BoolInt32(libc.Bool(libc.Int32FromInt32(3)-libc.Int32FromInt32(0) == int32(3)) && swap_rb != 0)
  27821 		if do_copy != 0 {
  27822 			y = 0
  27823 			for {
  27824 				if !(y < height) {
  27825 					break
  27826 				}
  27827 				libc.Xmemcpy(tls, dst, rgb, uint64(width*int32(4)))
  27828 				rgb = rgb + uintptr(rgb_stride)
  27829 				dst = dst + uintptr((*WebPPicture)(unsafe.Pointer(picture)).Fargb_stride)*4
  27830 				goto _5
  27831 			_5:
  27832 				;
  27833 				y = y + 1
  27834 			}
  27835 		} else {
  27836 			y = 0
  27837 			for {
  27838 				if !(y < height) {
  27839 					break
  27840 				}
  27841 				// RGBA input order. Need to swap R and B.
  27842 				(*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8LConvertBGRAToRGBA})))(tls, rgb, width, dst)
  27843 				rgb = rgb + uintptr(rgb_stride)
  27844 				dst = dst + uintptr((*WebPPicture)(unsafe.Pointer(picture)).Fargb_stride)*4
  27845 				goto _6
  27846 			_6:
  27847 				;
  27848 				y = y + 1
  27849 			}
  27850 		}
  27851 	} else {
  27852 		dst1 = (*WebPPicture)(unsafe.Pointer(picture)).Fargb
  27853 		y = 0
  27854 		for {
  27855 			if !(y < height) {
  27856 				break
  27857 			}
  27858 			(*(*func(*libc.TLS, uintptr, uintptr, uintptr, int32, int32, uintptr))(unsafe.Pointer(&struct{ uintptr }{WebPPackRGB})))(tls, r_ptr, g_ptr, b_ptr, width, step, dst1)
  27859 			r_ptr = r_ptr + uintptr(rgb_stride)
  27860 			g_ptr = g_ptr + uintptr(rgb_stride)
  27861 			b_ptr = b_ptr + uintptr(rgb_stride)
  27862 			dst1 = dst1 + uintptr((*WebPPicture)(unsafe.Pointer(picture)).Fargb_stride)*4
  27863 			goto _7
  27864 		_7:
  27865 			;
  27866 			y = y + 1
  27867 		}
  27868 	}
  27869 	return int32(1)
  27870 }
  27871 
  27872 // Public API
  27873 
  27874 func WebPPictureImportBGR(tls *libc.TLS, picture uintptr, bgr uintptr, bgr_stride int32) (r int32) {
  27875 	var v1 int32
  27876 	_ = v1
  27877 	if picture != libc.UintptrFromInt32(0) && bgr != libc.UintptrFromInt32(0) {
  27878 		v1 = Import(tls, picture, bgr, bgr_stride, int32(3), int32(1), 0)
  27879 	} else {
  27880 		v1 = 0
  27881 	}
  27882 	return v1
  27883 }
  27884 
  27885 func WebPPictureImportBGRA(tls *libc.TLS, picture uintptr, bgra uintptr, bgra_stride int32) (r int32) {
  27886 	var v1 int32
  27887 	_ = v1
  27888 	if picture != libc.UintptrFromInt32(0) && bgra != libc.UintptrFromInt32(0) {
  27889 		v1 = Import(tls, picture, bgra, bgra_stride, int32(4), int32(1), int32(1))
  27890 	} else {
  27891 		v1 = 0
  27892 	}
  27893 	return v1
  27894 }
  27895 
  27896 func WebPPictureImportBGRX(tls *libc.TLS, picture uintptr, bgrx uintptr, bgrx_stride int32) (r int32) {
  27897 	var v1 int32
  27898 	_ = v1
  27899 	if picture != libc.UintptrFromInt32(0) && bgrx != libc.UintptrFromInt32(0) {
  27900 		v1 = Import(tls, picture, bgrx, bgrx_stride, int32(4), int32(1), 0)
  27901 	} else {
  27902 		v1 = 0
  27903 	}
  27904 	return v1
  27905 }
  27906 
  27907 func WebPPictureImportRGB(tls *libc.TLS, picture uintptr, rgb uintptr, rgb_stride int32) (r int32) {
  27908 	var v1 int32
  27909 	_ = v1
  27910 	if picture != libc.UintptrFromInt32(0) && rgb != libc.UintptrFromInt32(0) {
  27911 		v1 = Import(tls, picture, rgb, rgb_stride, int32(3), 0, 0)
  27912 	} else {
  27913 		v1 = 0
  27914 	}
  27915 	return v1
  27916 }
  27917 
  27918 func WebPPictureImportRGBA(tls *libc.TLS, picture uintptr, rgba uintptr, rgba_stride int32) (r int32) {
  27919 	var v1 int32
  27920 	_ = v1
  27921 	if picture != libc.UintptrFromInt32(0) && rgba != libc.UintptrFromInt32(0) {
  27922 		v1 = Import(tls, picture, rgba, rgba_stride, int32(4), 0, int32(1))
  27923 	} else {
  27924 		v1 = 0
  27925 	}
  27926 	return v1
  27927 }
  27928 
  27929 func WebPPictureImportRGBX(tls *libc.TLS, picture uintptr, rgbx uintptr, rgbx_stride int32) (r int32) {
  27930 	var v1 int32
  27931 	_ = v1
  27932 	if picture != libc.UintptrFromInt32(0) && rgbx != libc.UintptrFromInt32(0) {
  27933 		v1 = Import(tls, picture, rgbx, rgbx_stride, int32(4), 0, 0)
  27934 	} else {
  27935 		v1 = 0
  27936 	}
  27937 	return v1
  27938 }
  27939 
  27940 const LOSSLESS_DEFAULT_QUALITY = 70
  27941 const __INT_MAX__1 = 2147483647
  27942 
  27943 //------------------------------------------------------------------------------
  27944 
  27945 // Copyright 2012 Google Inc. All Rights Reserved.
  27946 //
  27947 // Use of this source code is governed by a BSD-style license
  27948 // that can be found in the COPYING file in the root of the source
  27949 // tree. An additional intellectual property rights grant can be found
  27950 // in the file PATENTS. All contributing project authors may
  27951 // be found in the AUTHORS file in the root of the source tree.
  27952 // -----------------------------------------------------------------------------
  27953 //
  27954 // Misc. common utility functions
  27955 //
  27956 // Authors: Skal (pascal.massimino@gmail.com)
  27957 //          Urvang (urvang@google.com)
  27958 
  27959 // Copyright 2011 Google Inc. All Rights Reserved.
  27960 //
  27961 // Use of this source code is governed by a BSD-style license
  27962 // that can be found in the COPYING file in the root of the source
  27963 // tree. An additional intellectual property rights grant can be found
  27964 // in the file PATENTS. All contributing project authors may
  27965 // be found in the AUTHORS file in the root of the source tree.
  27966 // -----------------------------------------------------------------------------
  27967 //
  27968 //   WebP encoder: main interface
  27969 //
  27970 // Author: Skal (pascal.massimino@gmail.com)
  27971 
  27972 // Copyright 2010 Google Inc. All Rights Reserved.
  27973 //
  27974 // Use of this source code is governed by a BSD-style license
  27975 // that can be found in the COPYING file in the root of the source
  27976 // tree. An additional intellectual property rights grant can be found
  27977 // in the file PATENTS. All contributing project authors may
  27978 // be found in the AUTHORS file in the root of the source tree.
  27979 // -----------------------------------------------------------------------------
  27980 //
  27981 //  Common types + memory wrappers
  27982 //
  27983 // Author: Skal (pascal.massimino@gmail.com)
  27984 
  27985 //------------------------------------------------------------------------------
  27986 // WebPPicture
  27987 //------------------------------------------------------------------------------
  27988 
  27989 func DummyWriter(tls *libc.TLS, data uintptr, data_size size_t, picture uintptr) (r int32) {
  27990 	// The following are to prevent 'unused variable' error message.
  27991 	_ = data
  27992 	_ = data_size
  27993 	_ = picture
  27994 	return int32(1)
  27995 }
  27996 
  27997 func WebPPictureInitInternal(tls *libc.TLS, picture uintptr, version int32) (r int32) {
  27998 	if version>>int32(8) != libc.Int32FromInt32(WEBP_ENCODER_ABI_VERSION)>>libc.Int32FromInt32(8) {
  27999 		return 0 // caller/system version mismatch!
  28000 	}
  28001 	if picture != libc.UintptrFromInt32(0) {
  28002 		libc.Xmemset(tls, picture, 0, uint64(256))
  28003 		(*WebPPicture)(unsafe.Pointer(picture)).Fwriter = __ccgo_fp(DummyWriter)
  28004 		WebPEncodingSetError(tls, picture, int32(VP8_ENC_OK))
  28005 	}
  28006 	return int32(1)
  28007 }
  28008 
  28009 //------------------------------------------------------------------------------
  28010 
  28011 func WebPValidatePicture(tls *libc.TLS, picture uintptr) (r int32) {
  28012 	if picture == libc.UintptrFromInt32(0) {
  28013 		return 0
  28014 	}
  28015 	if (*WebPPicture)(unsafe.Pointer(picture)).Fwidth <= 0 || (*WebPPicture)(unsafe.Pointer(picture)).Fheight <= 0 {
  28016 		return WebPEncodingSetError(tls, picture, int32(VP8_ENC_ERROR_BAD_DIMENSION))
  28017 	}
  28018 	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) {
  28019 		return WebPEncodingSetError(tls, picture, int32(VP8_ENC_ERROR_BAD_DIMENSION))
  28020 	}
  28021 	if (*WebPPicture)(unsafe.Pointer(picture)).Fcolorspace != int32(WEBP_YUV420) && (*WebPPicture)(unsafe.Pointer(picture)).Fcolorspace != int32(WEBP_YUV420A) {
  28022 		return WebPEncodingSetError(tls, picture, int32(VP8_ENC_ERROR_INVALID_CONFIGURATION))
  28023 	}
  28024 	return int32(1)
  28025 }
  28026 
  28027 func WebPPictureResetBufferARGB(tls *libc.TLS, picture uintptr) {
  28028 	(*WebPPicture)(unsafe.Pointer(picture)).Fmemory_argb_ = libc.UintptrFromInt32(0)
  28029 	(*WebPPicture)(unsafe.Pointer(picture)).Fargb = libc.UintptrFromInt32(0)
  28030 	(*WebPPicture)(unsafe.Pointer(picture)).Fargb_stride = 0
  28031 }
  28032 
  28033 func WebPPictureResetBufferYUVA(tls *libc.TLS, picture uintptr) {
  28034 	var v1, v2, v3 uintptr
  28035 	var v4 int32
  28036 	_, _, _, _ = v1, v2, v3, v4
  28037 	(*WebPPicture)(unsafe.Pointer(picture)).Fmemory_ = libc.UintptrFromInt32(0)
  28038 	v3 = libc.UintptrFromInt32(0)
  28039 	(*WebPPicture)(unsafe.Pointer(picture)).Fa = v3
  28040 	v2 = v3
  28041 	(*WebPPicture)(unsafe.Pointer(picture)).Fv = v2
  28042 	v1 = v2
  28043 	(*WebPPicture)(unsafe.Pointer(picture)).Fu = v1
  28044 	(*WebPPicture)(unsafe.Pointer(picture)).Fy = v1
  28045 	v4 = libc.Int32FromInt32(0)
  28046 	(*WebPPicture)(unsafe.Pointer(picture)).Fuv_stride = v4
  28047 	(*WebPPicture)(unsafe.Pointer(picture)).Fy_stride = v4
  28048 	(*WebPPicture)(unsafe.Pointer(picture)).Fa_stride = 0
  28049 }
  28050 
  28051 func WebPPictureResetBuffers(tls *libc.TLS, picture uintptr) {
  28052 	WebPPictureResetBufferARGB(tls, picture)
  28053 	WebPPictureResetBufferYUVA(tls, picture)
  28054 }
  28055 
  28056 func WebPPictureAllocARGB(tls *libc.TLS, picture uintptr) (r int32) {
  28057 	var argb_size uint64_t
  28058 	var height, width int32
  28059 	var memory uintptr
  28060 	_, _, _, _ = argb_size, height, memory, width
  28061 	width = (*WebPPicture)(unsafe.Pointer(picture)).Fwidth
  28062 	height = (*WebPPicture)(unsafe.Pointer(picture)).Fheight
  28063 	argb_size = uint64(width) * uint64(height)
  28064 	if !(WebPValidatePicture(tls, picture) != 0) {
  28065 		return 0
  28066 	}
  28067 	WebPSafeFree(tls, (*WebPPicture)(unsafe.Pointer(picture)).Fmemory_argb_)
  28068 	WebPPictureResetBufferARGB(tls, picture)
  28069 	// allocate a new buffer.
  28070 	memory = WebPSafeMalloc(tls, argb_size+uint64(WEBP_ALIGN_CST), uint64(4))
  28071 	if memory == libc.UintptrFromInt32(0) {
  28072 		return WebPEncodingSetError(tls, picture, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  28073 	}
  28074 	(*WebPPicture)(unsafe.Pointer(picture)).Fmemory_argb_ = memory
  28075 	(*WebPPicture)(unsafe.Pointer(picture)).Fargb = uintptr((uint64(memory) + libc.Uint64FromInt32(WEBP_ALIGN_CST)) & ^libc.Uint64FromInt32(WEBP_ALIGN_CST))
  28076 	(*WebPPicture)(unsafe.Pointer(picture)).Fargb_stride = width
  28077 	return int32(1)
  28078 }
  28079 
  28080 func WebPPictureAllocYUVA(tls *libc.TLS, picture uintptr) (r int32) {
  28081 	var a_size, total_size, uv_size, y_size uint64_t
  28082 	var a_stride, a_width, has_alpha, height, uv_height, uv_stride, uv_width, width, y_stride, v1 int32
  28083 	var mem uintptr
  28084 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  28085 	has_alpha = (*WebPPicture)(unsafe.Pointer(picture)).Fcolorspace & int32(WEBP_CSP_ALPHA_BIT)
  28086 	width = (*WebPPicture)(unsafe.Pointer(picture)).Fwidth
  28087 	height = (*WebPPicture)(unsafe.Pointer(picture)).Fheight
  28088 	y_stride = width
  28089 	uv_width = int32((int64(width) + libc.Int64FromInt32(1)) >> libc.Int32FromInt32(1))
  28090 	uv_height = int32((int64(height) + libc.Int64FromInt32(1)) >> libc.Int32FromInt32(1))
  28091 	uv_stride = uv_width
  28092 	if !(WebPValidatePicture(tls, picture) != 0) {
  28093 		return 0
  28094 	}
  28095 	WebPSafeFree(tls, (*WebPPicture)(unsafe.Pointer(picture)).Fmemory_)
  28096 	WebPPictureResetBufferYUVA(tls, picture)
  28097 	// alpha
  28098 	if has_alpha != 0 {
  28099 		v1 = width
  28100 	} else {
  28101 		v1 = 0
  28102 	}
  28103 	a_width = v1
  28104 	a_stride = a_width
  28105 	y_size = uint64(y_stride) * uint64(height)
  28106 	uv_size = uint64(uv_stride) * uint64(uv_height)
  28107 	a_size = uint64(a_stride) * uint64(height)
  28108 	total_size = y_size + a_size + uint64(2)*uv_size
  28109 	// Security and validation checks
  28110 	if width <= 0 || height <= 0 || uv_width <= 0 || uv_height <= 0 { // u/v param error
  28111 		return WebPEncodingSetError(tls, picture, int32(VP8_ENC_ERROR_BAD_DIMENSION))
  28112 	}
  28113 	// allocate a new buffer.
  28114 	mem = WebPSafeMalloc(tls, total_size, uint64(1))
  28115 	if mem == libc.UintptrFromInt32(0) {
  28116 		return WebPEncodingSetError(tls, picture, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  28117 	}
  28118 	// From now on, we're in the clear, we can no longer fail...
  28119 	(*WebPPicture)(unsafe.Pointer(picture)).Fmemory_ = mem
  28120 	(*WebPPicture)(unsafe.Pointer(picture)).Fy_stride = y_stride
  28121 	(*WebPPicture)(unsafe.Pointer(picture)).Fuv_stride = uv_stride
  28122 	(*WebPPicture)(unsafe.Pointer(picture)).Fa_stride = a_stride
  28123 	// TODO(skal): we could align the y/u/v planes and adjust stride.
  28124 	(*WebPPicture)(unsafe.Pointer(picture)).Fy = mem
  28125 	mem = mem + uintptr(y_size)
  28126 	(*WebPPicture)(unsafe.Pointer(picture)).Fu = mem
  28127 	mem = mem + uintptr(uv_size)
  28128 	(*WebPPicture)(unsafe.Pointer(picture)).Fv = mem
  28129 	mem = mem + uintptr(uv_size)
  28130 	if a_size > uint64(0) {
  28131 		(*WebPPicture)(unsafe.Pointer(picture)).Fa = mem
  28132 		mem = mem + uintptr(a_size)
  28133 	}
  28134 	_ = mem // makes the static analyzer happy
  28135 	return int32(1)
  28136 }
  28137 
  28138 func WebPPictureAlloc(tls *libc.TLS, picture uintptr) (r int32) {
  28139 	if picture != libc.UintptrFromInt32(0) {
  28140 		WebPPictureFree(tls, picture) // erase previous buffer
  28141 		if !((*WebPPicture)(unsafe.Pointer(picture)).Fuse_argb != 0) {
  28142 			return WebPPictureAllocYUVA(tls, picture)
  28143 		} else {
  28144 			return WebPPictureAllocARGB(tls, picture)
  28145 		}
  28146 	}
  28147 	return int32(1)
  28148 }
  28149 
  28150 func WebPPictureFree(tls *libc.TLS, picture uintptr) {
  28151 	if picture != libc.UintptrFromInt32(0) {
  28152 		WebPSafeFree(tls, (*WebPPicture)(unsafe.Pointer(picture)).Fmemory_)
  28153 		WebPSafeFree(tls, (*WebPPicture)(unsafe.Pointer(picture)).Fmemory_argb_)
  28154 		WebPPictureResetBuffers(tls, picture)
  28155 	}
  28156 }
  28157 
  28158 //------------------------------------------------------------------------------
  28159 // WebPMemoryWriter: Write-to-memory
  28160 
  28161 func WebPMemoryWriterInit(tls *libc.TLS, writer uintptr) {
  28162 	(*WebPMemoryWriter)(unsafe.Pointer(writer)).Fmem = libc.UintptrFromInt32(0)
  28163 	(*WebPMemoryWriter)(unsafe.Pointer(writer)).Fsize = uint64(0)
  28164 	(*WebPMemoryWriter)(unsafe.Pointer(writer)).Fmax_size = uint64(0)
  28165 }
  28166 
  28167 func WebPMemoryWrite(tls *libc.TLS, data uintptr, data_size size_t, picture uintptr) (r int32) {
  28168 	var new_mem, w uintptr
  28169 	var next_max_size, next_size uint64_t
  28170 	_, _, _, _ = new_mem, next_max_size, next_size, w
  28171 	w = (*WebPPicture)(unsafe.Pointer(picture)).Fcustom_ptr
  28172 	if w == libc.UintptrFromInt32(0) {
  28173 		return int32(1)
  28174 	}
  28175 	next_size = (*WebPMemoryWriter)(unsafe.Pointer(w)).Fsize + data_size
  28176 	if next_size > (*WebPMemoryWriter)(unsafe.Pointer(w)).Fmax_size {
  28177 		next_max_size = uint64(2) * (*WebPMemoryWriter)(unsafe.Pointer(w)).Fmax_size
  28178 		if next_max_size < next_size {
  28179 			next_max_size = next_size
  28180 		}
  28181 		if next_max_size < uint64(8192) {
  28182 			next_max_size = uint64(8192)
  28183 		}
  28184 		new_mem = WebPSafeMalloc(tls, next_max_size, uint64(1))
  28185 		if new_mem == libc.UintptrFromInt32(0) {
  28186 			return 0
  28187 		}
  28188 		if (*WebPMemoryWriter)(unsafe.Pointer(w)).Fsize > uint64(0) {
  28189 			libc.Xmemcpy(tls, new_mem, (*WebPMemoryWriter)(unsafe.Pointer(w)).Fmem, (*WebPMemoryWriter)(unsafe.Pointer(w)).Fsize)
  28190 		}
  28191 		WebPSafeFree(tls, (*WebPMemoryWriter)(unsafe.Pointer(w)).Fmem)
  28192 		(*WebPMemoryWriter)(unsafe.Pointer(w)).Fmem = new_mem
  28193 		// down-cast is ok, thanks to WebPSafeMalloc
  28194 		(*WebPMemoryWriter)(unsafe.Pointer(w)).Fmax_size = next_max_size
  28195 	}
  28196 	if data_size > uint64(0) {
  28197 		libc.Xmemcpy(tls, (*WebPMemoryWriter)(unsafe.Pointer(w)).Fmem+uintptr((*WebPMemoryWriter)(unsafe.Pointer(w)).Fsize), data, data_size)
  28198 		**(**size_t)(__ccgo_up(w + 8)) += data_size
  28199 	}
  28200 	return int32(1)
  28201 }
  28202 
  28203 func WebPMemoryWriterClear(tls *libc.TLS, writer uintptr) {
  28204 	if writer != libc.UintptrFromInt32(0) {
  28205 		WebPSafeFree(tls, (*WebPMemoryWriter)(unsafe.Pointer(writer)).Fmem)
  28206 		WebPMemoryWriterInit(tls, writer)
  28207 	}
  28208 }
  28209 
  28210 //------------------------------------------------------------------------------
  28211 // Simplest high-level calls:
  28212 
  28213 type Importer = uintptr
  28214 
  28215 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) {
  28216 	bp := tls.Alloc(416)
  28217 	defer tls.Free(416)
  28218 	var ok, v1, v3 int32
  28219 	var v5 bool
  28220 	var _ /* config at bp+256 */ WebPConfig
  28221 	var _ /* pic at bp+0 */ WebPPicture
  28222 	var _ /* wrt at bp+376 */ WebPMemoryWriter
  28223 	_, _, _, _ = ok, v1, v3, v5
  28224 	if output == libc.UintptrFromInt32(0) {
  28225 		return uint64(0)
  28226 	}
  28227 	v1 = WebPConfigInitInternal(tls, bp+256, int32(WEBP_PRESET_DEFAULT), quality_factor, int32(WEBP_ENCODER_ABI_VERSION))
  28228 	goto _2
  28229 _2:
  28230 	;
  28231 	if v5 = !(v1 != 0); !v5 {
  28232 		v3 = WebPPictureInitInternal(tls, bp, int32(WEBP_ENCODER_ABI_VERSION))
  28233 		goto _4
  28234 	_4:
  28235 	}
  28236 	if v5 || !(v3 != 0) {
  28237 		return uint64(0) // shouldn't happen, except if system installation is broken
  28238 	}
  28239 	(**(**WebPConfig)(__ccgo_up(bp + 256))).Flossless = libc.BoolInt32(!!(lossless != 0))
  28240 	(**(**WebPPicture)(__ccgo_up(bp))).Fuse_argb = libc.BoolInt32(!!(lossless != 0))
  28241 	(**(**WebPPicture)(__ccgo_up(bp))).Fwidth = width
  28242 	(**(**WebPPicture)(__ccgo_up(bp))).Fheight = height
  28243 	(**(**WebPPicture)(__ccgo_up(bp))).Fwriter = __ccgo_fp(WebPMemoryWrite)
  28244 	(**(**WebPPicture)(__ccgo_up(bp))).Fcustom_ptr = bp + 376
  28245 	WebPMemoryWriterInit(tls, bp+376)
  28246 	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)
  28247 	WebPPictureFree(tls, bp)
  28248 	if !(ok != 0) {
  28249 		WebPMemoryWriterClear(tls, bp+376)
  28250 		**(**uintptr)(__ccgo_up(output)) = libc.UintptrFromInt32(0)
  28251 		return uint64(0)
  28252 	}
  28253 	**(**uintptr)(__ccgo_up(output)) = (**(**WebPMemoryWriter)(__ccgo_up(bp + 376))).Fmem
  28254 	return (**(**WebPMemoryWriter)(__ccgo_up(bp + 376))).Fsize
  28255 }
  28256 
  28257 func WebPEncodeRGB(tls *libc.TLS, in uintptr, w int32, h int32, bps int32, q float32, out uintptr) (r size_t) {
  28258 	return Encode(tls, in, w, h, bps, __ccgo_fp(WebPPictureImportRGB), q, 0, out)
  28259 }
  28260 
  28261 func WebPEncodeRGBA(tls *libc.TLS, in uintptr, w int32, h int32, bps int32, q float32, out uintptr) (r size_t) {
  28262 	return Encode(tls, in, w, h, bps, __ccgo_fp(WebPPictureImportRGBA), q, 0, out)
  28263 }
  28264 
  28265 func WebPEncodeBGR(tls *libc.TLS, in uintptr, w int32, h int32, bps int32, q float32, out uintptr) (r size_t) {
  28266 	return Encode(tls, in, w, h, bps, __ccgo_fp(WebPPictureImportBGR), q, 0, out)
  28267 }
  28268 
  28269 func WebPEncodeBGRA(tls *libc.TLS, in uintptr, w int32, h int32, bps int32, q float32, out uintptr) (r size_t) {
  28270 	return Encode(tls, in, w, h, bps, __ccgo_fp(WebPPictureImportBGRA), q, 0, out)
  28271 }
  28272 
  28273 func WebPEncodeLosslessRGB(tls *libc.TLS, in uintptr, w int32, h int32, bps int32, out uintptr) (r size_t) {
  28274 	return Encode(tls, in, w, h, bps, __ccgo_fp(WebPPictureImportRGB), float32(70), int32(1), out)
  28275 }
  28276 
  28277 func WebPEncodeLosslessRGBA(tls *libc.TLS, in uintptr, w int32, h int32, bps int32, out uintptr) (r size_t) {
  28278 	return Encode(tls, in, w, h, bps, __ccgo_fp(WebPPictureImportRGBA), float32(70), int32(1), out)
  28279 }
  28280 
  28281 func WebPEncodeLosslessBGR(tls *libc.TLS, in uintptr, w int32, h int32, bps int32, out uintptr) (r size_t) {
  28282 	return Encode(tls, in, w, h, bps, __ccgo_fp(WebPPictureImportBGR), float32(70), int32(1), out)
  28283 }
  28284 
  28285 func WebPEncodeLosslessBGRA(tls *libc.TLS, in uintptr, w int32, h int32, bps int32, out uintptr) (r size_t) {
  28286 	return Encode(tls, in, w, h, bps, __ccgo_fp(WebPPictureImportBGRA), float32(70), int32(1), out)
  28287 }
  28288 
  28289 const SIZE_MAX11 = "UINT64_MAX"
  28290 const __INT_MAX__2 = 0x7fffffff
  28291 
  28292 //------------------------------------------------------------------------------
  28293 
  28294 // Copyright 2012 Google Inc. All Rights Reserved.
  28295 //
  28296 // Use of this source code is governed by a BSD-style license
  28297 // that can be found in the COPYING file in the root of the source
  28298 // tree. An additional intellectual property rights grant can be found
  28299 // in the file PATENTS. All contributing project authors may
  28300 // be found in the AUTHORS file in the root of the source tree.
  28301 // -----------------------------------------------------------------------------
  28302 //
  28303 // Misc. common utility functions
  28304 //
  28305 // Authors: Skal (pascal.massimino@gmail.com)
  28306 //          Urvang (urvang@google.com)
  28307 
  28308 type AccumulateFunc = uintptr
  28309 
  28310 //------------------------------------------------------------------------------
  28311 // local-min distortion
  28312 //
  28313 // For every pixel in the *reference* picture, we search for the local best
  28314 // match in the compressed image. This is not a symmetrical measure.
  28315 
  28316 func AccumulateLSIM(tls *libc.TLS, src uintptr, src_stride int32, ref uintptr, ref_stride int32, w int32, h int32) (r float64) {
  28317 	var best_sse, diff, sse, total_sse, value float64
  28318 	var i, j, x, x_0, x_1, y, y_0, y_1, v2, v3, v5, v6 int32
  28319 	var s uintptr
  28320 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = best_sse, diff, i, j, s, sse, total_sse, value, x, x_0, x_1, y, y_0, y_1, v2, v3, v5, v6
  28321 	total_sse = float64(0)
  28322 	y = 0
  28323 	for {
  28324 		if !(y < h) {
  28325 			break
  28326 		}
  28327 		if y-int32(2) < 0 {
  28328 			v2 = 0
  28329 		} else {
  28330 			v2 = y - int32(2)
  28331 		}
  28332 		y_0 = v2
  28333 		if y+int32(2)+int32(1) >= h {
  28334 			v3 = h
  28335 		} else {
  28336 			v3 = y + int32(2) + int32(1)
  28337 		}
  28338 		y_1 = v3
  28339 		x = 0
  28340 		for {
  28341 			if !(x < w) {
  28342 				break
  28343 			}
  28344 			if x-int32(2) < 0 {
  28345 				v5 = 0
  28346 			} else {
  28347 				v5 = x - int32(2)
  28348 			}
  28349 			x_0 = v5
  28350 			if x+int32(2)+int32(1) >= w {
  28351 				v6 = w
  28352 			} else {
  28353 				v6 = x + int32(2) + int32(1)
  28354 			}
  28355 			x_1 = v6
  28356 			best_sse = float64(libc.Float64FromFloat64(255) * libc.Float64FromFloat64(255))
  28357 			value = float64(**(**uint8_t)(__ccgo_up(ref + uintptr(y*ref_stride+x))))
  28358 			j = y_0
  28359 			for {
  28360 				if !(j < y_1) {
  28361 					break
  28362 				}
  28363 				s = src + uintptr(j*src_stride)
  28364 				i = x_0
  28365 				for {
  28366 					if !(i < x_1) {
  28367 						break
  28368 					}
  28369 					diff = float64(**(**uint8_t)(__ccgo_up(s + uintptr(i)))) - value
  28370 					sse = float64(diff * diff)
  28371 					if sse < best_sse {
  28372 						best_sse = sse
  28373 					}
  28374 					goto _8
  28375 				_8:
  28376 					;
  28377 					i = i + 1
  28378 				}
  28379 				goto _7
  28380 			_7:
  28381 				;
  28382 				j = j + 1
  28383 			}
  28384 			total_sse = total_sse + best_sse
  28385 			goto _4
  28386 		_4:
  28387 			;
  28388 			x = x + 1
  28389 		}
  28390 		goto _1
  28391 	_1:
  28392 		;
  28393 		y = y + 1
  28394 	}
  28395 	return total_sse
  28396 }
  28397 
  28398 func AccumulateSSE(tls *libc.TLS, src uintptr, src_stride int32, ref uintptr, ref_stride int32, w int32, h int32) (r float64) {
  28399 	var total_sse float64
  28400 	var y int32
  28401 	_, _ = total_sse, y
  28402 	total_sse = float64(0)
  28403 	y = 0
  28404 	for {
  28405 		if !(y < h) {
  28406 			break
  28407 		}
  28408 		total_sse = total_sse + float64((*(*func(*libc.TLS, uintptr, uintptr, int32) uint32_t)(unsafe.Pointer(&struct{ uintptr }{VP8AccumulateSSE})))(tls, src, ref, w))
  28409 		src = src + uintptr(src_stride)
  28410 		ref = ref + uintptr(ref_stride)
  28411 		goto _1
  28412 	_1:
  28413 		;
  28414 		y = y + 1
  28415 	}
  28416 	return total_sse
  28417 }
  28418 
  28419 //------------------------------------------------------------------------------
  28420 
  28421 func AccumulateSSIM(tls *libc.TLS, src uintptr, src_stride int32, ref uintptr, ref_stride int32, w int32, h int32) (r float64) {
  28422 	var h0, h1, off1, off2, w0, w1, x, y, v1, v2 int32
  28423 	var sum float64
  28424 	_, _, _, _, _, _, _, _, _, _, _ = h0, h1, off1, off2, sum, w0, w1, x, y, v1, v2
  28425 	if w < int32(VP8_SSIM_KERNEL) {
  28426 		v1 = w
  28427 	} else {
  28428 		v1 = int32(VP8_SSIM_KERNEL)
  28429 	}
  28430 	w0 = v1
  28431 	w1 = w - int32(VP8_SSIM_KERNEL) - int32(1)
  28432 	if h < int32(VP8_SSIM_KERNEL) {
  28433 		v2 = h
  28434 	} else {
  28435 		v2 = int32(VP8_SSIM_KERNEL)
  28436 	}
  28437 	h0 = v2
  28438 	h1 = h - int32(VP8_SSIM_KERNEL) - int32(1)
  28439 	sum = float64(0)
  28440 	y = 0
  28441 	for {
  28442 		if !(y < h0) {
  28443 			break
  28444 		}
  28445 		x = 0
  28446 		for {
  28447 			if !(x < w) {
  28448 				break
  28449 			}
  28450 			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)
  28451 			goto _4
  28452 		_4:
  28453 			;
  28454 			x = x + 1
  28455 		}
  28456 		goto _3
  28457 	_3:
  28458 		;
  28459 		y = y + 1
  28460 	}
  28461 	for {
  28462 		if !(y < h1) {
  28463 			break
  28464 		}
  28465 		x = 0
  28466 		for {
  28467 			if !(x < w0) {
  28468 				break
  28469 			}
  28470 			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)
  28471 			goto _6
  28472 		_6:
  28473 			;
  28474 			x = x + 1
  28475 		}
  28476 		for {
  28477 			if !(x < w1) {
  28478 				break
  28479 			}
  28480 			off1 = x - int32(VP8_SSIM_KERNEL) + (y-int32(VP8_SSIM_KERNEL))*src_stride
  28481 			off2 = x - int32(VP8_SSIM_KERNEL) + (y-int32(VP8_SSIM_KERNEL))*ref_stride
  28482 			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)
  28483 			goto _7
  28484 		_7:
  28485 			;
  28486 			x = x + 1
  28487 		}
  28488 		for {
  28489 			if !(x < w) {
  28490 				break
  28491 			}
  28492 			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)
  28493 			goto _8
  28494 		_8:
  28495 			;
  28496 			x = x + 1
  28497 		}
  28498 		goto _5
  28499 	_5:
  28500 		;
  28501 		y = y + 1
  28502 	}
  28503 	for {
  28504 		if !(y < h) {
  28505 			break
  28506 		}
  28507 		x = 0
  28508 		for {
  28509 			if !(x < w) {
  28510 				break
  28511 			}
  28512 			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)
  28513 			goto _10
  28514 		_10:
  28515 			;
  28516 			x = x + 1
  28517 		}
  28518 		goto _9
  28519 	_9:
  28520 		;
  28521 		y = y + 1
  28522 	}
  28523 	return sum
  28524 }
  28525 
  28526 //------------------------------------------------------------------------------
  28527 // Distortion
  28528 
  28529 // C documentation
  28530 //
  28531 //	// Max value returned in case of exact similarity.
  28532 var kMinDistortion_dB = float64(99)
  28533 
  28534 func GetPSNR1(tls *libc.TLS, v float64, size float64) (r float64) {
  28535 	var v1 float64
  28536 	_ = v1
  28537 	if v > float64(0) && size > float64(0) {
  28538 		v1 = float64(-libc.Float64FromFloat64(4.3429448) * libc.Xlog(tls, v/float64(float64(size*libc.Float64FromInt32(255))*float64(255))))
  28539 	} else {
  28540 		v1 = kMinDistortion_dB
  28541 	}
  28542 	return v1
  28543 }
  28544 
  28545 func GetLogSSIM(tls *libc.TLS, v float64, size float64) (r float64) {
  28546 	var v1 float64
  28547 	_ = v1
  28548 	if size > float64(0) {
  28549 		v1 = v / size
  28550 	} else {
  28551 		v1 = float64(1)
  28552 	}
  28553 	v = v1
  28554 	if v < float64(1) {
  28555 		v1 = float64(-libc.Float64FromFloat64(10) * libc.Xlog10(tls, float64(1)-v))
  28556 	} else {
  28557 		v1 = kMinDistortion_dB
  28558 	}
  28559 	return v1
  28560 }
  28561 
  28562 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) {
  28563 	var allocated, tmp1, tmp2, v1, v2 uintptr
  28564 	var metric AccumulateFunc
  28565 	var x, y int32
  28566 	var v5 float32
  28567 	_, _, _, _, _, _, _, _, _ = allocated, metric, tmp1, tmp2, x, y, v1, v2, v5
  28568 	allocated = libc.UintptrFromInt32(0)
  28569 	if type1 == 0 {
  28570 		v1 = __ccgo_fp(AccumulateSSE)
  28571 	} else {
  28572 		if type1 == int32(1) {
  28573 			v2 = __ccgo_fp(AccumulateSSIM)
  28574 		} else {
  28575 			v2 = __ccgo_fp(AccumulateLSIM)
  28576 		}
  28577 		v1 = v2
  28578 	}
  28579 	metric = v1
  28580 	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) {
  28581 		return 0
  28582 	}
  28583 	VP8SSIMDspInit(tls)
  28584 	if x_step != uint64(1) {
  28585 		allocated = WebPSafeMalloc(tls, uint64(2)*uint64(width)*uint64(height), uint64(1))
  28586 		if allocated == libc.UintptrFromInt32(0) {
  28587 			return 0
  28588 		}
  28589 		tmp1 = allocated
  28590 		tmp2 = tmp1 + uintptr(uint64(width)*uint64(height))
  28591 		y = 0
  28592 		for {
  28593 			if !(y < height) {
  28594 				break
  28595 			}
  28596 			x = 0
  28597 			for {
  28598 				if !(x < width) {
  28599 					break
  28600 				}
  28601 				**(**uint8_t)(__ccgo_up(tmp1 + uintptr(x+y*width))) = **(**uint8_t)(__ccgo_up(src + uintptr(uint64(x)*x_step+uint64(y)*src_stride)))
  28602 				**(**uint8_t)(__ccgo_up(tmp2 + uintptr(x+y*width))) = **(**uint8_t)(__ccgo_up(ref + uintptr(uint64(x)*x_step+uint64(y)*ref_stride)))
  28603 				goto _4
  28604 			_4:
  28605 				;
  28606 				x = x + 1
  28607 			}
  28608 			goto _3
  28609 		_3:
  28610 			;
  28611 			y = y + 1
  28612 		}
  28613 		src = tmp1
  28614 		ref = tmp2
  28615 	}
  28616 	**(**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))
  28617 	WebPSafeFree(tls, allocated)
  28618 	if type1 == int32(1) {
  28619 		v5 = float32(GetLogSSIM(tls, float64(**(**float32)(__ccgo_up(distortion))), float64(float64(width)*float64(height))))
  28620 	} else {
  28621 		v5 = float32(GetPSNR1(tls, float64(**(**float32)(__ccgo_up(distortion))), float64(float64(width)*float64(height))))
  28622 	}
  28623 	**(**float32)(__ccgo_up(result)) = v5
  28624 	return int32(1)
  28625 }
  28626 
  28627 func WebPPictureDistortion(tls *libc.TLS, src uintptr, ref uintptr, type1 int32, results uintptr) (r int32) {
  28628 	bp := tls.Alloc(528)
  28629 	defer tls.Free(528)
  28630 	var c, h, offset, ok, w, v1, v3 int32
  28631 	var stride0, stride1 size_t
  28632 	var total_distortion, total_size float64
  28633 	var v5 bool
  28634 	var v7 float32
  28635 	var _ /* distortion at bp+512 */ float32
  28636 	var _ /* p0 at bp+0 */ WebPPicture
  28637 	var _ /* p1 at bp+256 */ WebPPicture
  28638 	_, _, _, _, _, _, _, _, _, _, _, _, _ = c, h, offset, ok, stride0, stride1, total_distortion, total_size, w, v1, v3, v5, v7
  28639 	ok = 0
  28640 	total_size = float64(0)
  28641 	total_distortion = float64(0)
  28642 	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) {
  28643 		return 0
  28644 	}
  28645 	VP8SSIMDspInit(tls)
  28646 	v1 = WebPPictureInitInternal(tls, bp, int32(WEBP_ENCODER_ABI_VERSION))
  28647 	goto _2
  28648 _2:
  28649 	;
  28650 	if v5 = !(v1 != 0); !v5 {
  28651 		v3 = WebPPictureInitInternal(tls, bp+256, int32(WEBP_ENCODER_ABI_VERSION))
  28652 		goto _4
  28653 	_4:
  28654 	}
  28655 	if v5 || !(v3 != 0) {
  28656 		return 0
  28657 	}
  28658 	w = (*WebPPicture)(unsafe.Pointer(src)).Fwidth
  28659 	h = (*WebPPicture)(unsafe.Pointer(src)).Fheight
  28660 	if !(WebPPictureView(tls, src, 0, 0, w, h, bp) != 0) {
  28661 		goto Error
  28662 	}
  28663 	if !(WebPPictureView(tls, ref, 0, 0, w, h, bp+256) != 0) {
  28664 		goto Error
  28665 	}
  28666 	// We always measure distortion in ARGB space.
  28667 	if (**(**WebPPicture)(__ccgo_up(bp))).Fuse_argb == 0 && !(WebPPictureYUVAToARGB(tls, bp) != 0) {
  28668 		goto Error
  28669 	}
  28670 	if (**(**WebPPicture)(__ccgo_up(bp + 256))).Fuse_argb == 0 && !(WebPPictureYUVAToARGB(tls, bp+256) != 0) {
  28671 		goto Error
  28672 	}
  28673 	c = 0
  28674 	for {
  28675 		if !(c < int32(4)) {
  28676 			break
  28677 		}
  28678 		stride0 = uint64(4) * uint64((**(**WebPPicture)(__ccgo_up(bp))).Fargb_stride)
  28679 		stride1 = uint64(4) * uint64((**(**WebPPicture)(__ccgo_up(bp + 256))).Fargb_stride)
  28680 		// results are reported as BGRA
  28681 		offset = c ^ 0
  28682 		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) {
  28683 			goto Error
  28684 		}
  28685 		total_distortion = total_distortion + float64(**(**float32)(__ccgo_up(bp + 512)))
  28686 		total_size = total_size + float64(w*h)
  28687 		goto _6
  28688 	_6:
  28689 		;
  28690 		c = c + 1
  28691 	}
  28692 	if type1 == int32(1) {
  28693 		v7 = float32(GetLogSSIM(tls, total_distortion, total_size))
  28694 	} else {
  28695 		v7 = float32(GetPSNR1(tls, total_distortion, total_size))
  28696 	}
  28697 	**(**float32)(__ccgo_up(results + 4*4)) = v7
  28698 	ok = int32(1)
  28699 	goto Error
  28700 Error:
  28701 	;
  28702 	WebPPictureFree(tls, bp)
  28703 	WebPPictureFree(tls, bp+256)
  28704 	return ok
  28705 }
  28706 
  28707 //------------------------------------------------------------------------------
  28708 
  28709 // Copyright 2012 Google Inc. All Rights Reserved.
  28710 //
  28711 // Use of this source code is governed by a BSD-style license
  28712 // that can be found in the COPYING file in the root of the source
  28713 // tree. An additional intellectual property rights grant can be found
  28714 // in the file PATENTS. All contributing project authors may
  28715 // be found in the AUTHORS file in the root of the source tree.
  28716 // -----------------------------------------------------------------------------
  28717 //
  28718 // Misc. common utility functions
  28719 //
  28720 // Authors: Skal (pascal.massimino@gmail.com)
  28721 //          Urvang (urvang@google.com)
  28722 
  28723 // C documentation
  28724 //
  28725 //	// Grab the 'specs' (writer, *opaque, width, height...) from 'src' and copy them
  28726 //	// into 'dst'. Mark 'dst' as not owning any memory.
  28727 func PictureGrabSpecs(tls *libc.TLS, src uintptr, dst uintptr) {
  28728 	**(**WebPPicture)(__ccgo_up(dst)) = **(**WebPPicture)(__ccgo_up(src))
  28729 	WebPPictureResetBuffers(tls, dst)
  28730 }
  28731 
  28732 //------------------------------------------------------------------------------
  28733 
  28734 // C documentation
  28735 //
  28736 //	// Adjust top-left corner to chroma sample position.
  28737 func SnapTopLeftPosition(tls *libc.TLS, pic uintptr, left uintptr, top uintptr) {
  28738 	if !((*WebPPicture)(unsafe.Pointer(pic)).Fuse_argb != 0) {
  28739 		**(**int32)(__ccgo_up(left)) &= ^libc.Int32FromInt32(1)
  28740 		**(**int32)(__ccgo_up(top)) &= ^libc.Int32FromInt32(1)
  28741 	}
  28742 }
  28743 
  28744 // C documentation
  28745 //
  28746 //	// Adjust top-left corner and verify that the sub-rectangle is valid.
  28747 func AdjustAndCheckRectangle(tls *libc.TLS, pic uintptr, left uintptr, top uintptr, width int32, height int32) (r int32) {
  28748 	SnapTopLeftPosition(tls, pic, left, top)
  28749 	if **(**int32)(__ccgo_up(left)) < 0 || **(**int32)(__ccgo_up(top)) < 0 {
  28750 		return 0
  28751 	}
  28752 	if width <= 0 || height <= 0 {
  28753 		return 0
  28754 	}
  28755 	if **(**int32)(__ccgo_up(left))+width > (*WebPPicture)(unsafe.Pointer(pic)).Fwidth {
  28756 		return 0
  28757 	}
  28758 	if **(**int32)(__ccgo_up(top))+height > (*WebPPicture)(unsafe.Pointer(pic)).Fheight {
  28759 		return 0
  28760 	}
  28761 	return int32(1)
  28762 }
  28763 
  28764 func WebPPictureCopy(tls *libc.TLS, src uintptr, dst uintptr) (r int32) {
  28765 	if src == libc.UintptrFromInt32(0) || dst == libc.UintptrFromInt32(0) {
  28766 		return 0
  28767 	}
  28768 	if src == dst {
  28769 		return int32(1)
  28770 	}
  28771 	PictureGrabSpecs(tls, src, dst)
  28772 	if !(WebPPictureAlloc(tls, dst) != 0) {
  28773 		return 0
  28774 	}
  28775 	if !((*WebPPicture)(unsafe.Pointer(src)).Fuse_argb != 0) {
  28776 		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)
  28777 		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))
  28778 		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))
  28779 		if (*WebPPicture)(unsafe.Pointer(dst)).Fa != libc.UintptrFromInt32(0) {
  28780 			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)
  28781 		}
  28782 	} else {
  28783 		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)
  28784 	}
  28785 	return int32(1)
  28786 }
  28787 
  28788 func WebPPictureIsView(tls *libc.TLS, picture uintptr) (r int32) {
  28789 	if picture == libc.UintptrFromInt32(0) {
  28790 		return 0
  28791 	}
  28792 	if (*WebPPicture)(unsafe.Pointer(picture)).Fuse_argb != 0 {
  28793 		return libc.BoolInt32((*WebPPicture)(unsafe.Pointer(picture)).Fmemory_argb_ == libc.UintptrFromInt32(0))
  28794 	}
  28795 	return libc.BoolInt32((*WebPPicture)(unsafe.Pointer(picture)).Fmemory_ == libc.UintptrFromInt32(0))
  28796 }
  28797 
  28798 func WebPPictureView(tls *libc.TLS, src uintptr, _left int32, _top int32, width int32, height int32, dst uintptr) (r int32) {
  28799 	bp := tls.Alloc(16)
  28800 	defer tls.Free(16)
  28801 	*(*int32)(unsafe.Pointer(bp)) = _left
  28802 	*(*int32)(unsafe.Pointer(bp + 4)) = _top
  28803 	if src == libc.UintptrFromInt32(0) || dst == libc.UintptrFromInt32(0) {
  28804 		return 0
  28805 	}
  28806 	// verify rectangle position.
  28807 	if !(AdjustAndCheckRectangle(tls, src, bp, bp+4, width, height) != 0) {
  28808 		return 0
  28809 	}
  28810 	if src != dst { // beware of aliasing! We don't want to leak 'memory_'.
  28811 		PictureGrabSpecs(tls, src, dst)
  28812 	}
  28813 	(*WebPPicture)(unsafe.Pointer(dst)).Fwidth = width
  28814 	(*WebPPicture)(unsafe.Pointer(dst)).Fheight = height
  28815 	if !((*WebPPicture)(unsafe.Pointer(src)).Fuse_argb != 0) {
  28816 		(*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)))
  28817 		(*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))
  28818 		(*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))
  28819 		(*WebPPicture)(unsafe.Pointer(dst)).Fy_stride = (*WebPPicture)(unsafe.Pointer(src)).Fy_stride
  28820 		(*WebPPicture)(unsafe.Pointer(dst)).Fuv_stride = (*WebPPicture)(unsafe.Pointer(src)).Fuv_stride
  28821 		if (*WebPPicture)(unsafe.Pointer(src)).Fa != libc.UintptrFromInt32(0) {
  28822 			(*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)))
  28823 			(*WebPPicture)(unsafe.Pointer(dst)).Fa_stride = (*WebPPicture)(unsafe.Pointer(src)).Fa_stride
  28824 		}
  28825 	} else {
  28826 		(*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
  28827 		(*WebPPicture)(unsafe.Pointer(dst)).Fargb_stride = (*WebPPicture)(unsafe.Pointer(src)).Fargb_stride
  28828 	}
  28829 	return int32(1)
  28830 }
  28831 
  28832 //------------------------------------------------------------------------------
  28833 // Picture cropping
  28834 
  28835 func WebPPictureCrop(tls *libc.TLS, pic uintptr, _left int32, _top int32, width int32, height int32) (r int32) {
  28836 	bp := tls.Alloc(272)
  28837 	defer tls.Free(272)
  28838 	*(*int32)(unsafe.Pointer(bp)) = _left
  28839 	*(*int32)(unsafe.Pointer(bp + 4)) = _top
  28840 	var a_offset, uv_offset, y_offset int32
  28841 	var src uintptr
  28842 	var _ /* tmp at bp+8 */ WebPPicture
  28843 	_, _, _, _ = a_offset, src, uv_offset, y_offset
  28844 	if pic == libc.UintptrFromInt32(0) {
  28845 		return 0
  28846 	}
  28847 	if !(AdjustAndCheckRectangle(tls, pic, bp, bp+4, width, height) != 0) {
  28848 		return 0
  28849 	}
  28850 	PictureGrabSpecs(tls, pic, bp+8)
  28851 	(**(**WebPPicture)(__ccgo_up(bp + 8))).Fwidth = width
  28852 	(**(**WebPPicture)(__ccgo_up(bp + 8))).Fheight = height
  28853 	if !(WebPPictureAlloc(tls, bp+8) != 0) {
  28854 		return WebPEncodingSetError(tls, pic, (**(**WebPPicture)(__ccgo_up(bp + 8))).Ferror_code)
  28855 	}
  28856 	if !((*WebPPicture)(unsafe.Pointer(pic)).Fuse_argb != 0) {
  28857 		y_offset = **(**int32)(__ccgo_up(bp + 4))*(*WebPPicture)(unsafe.Pointer(pic)).Fy_stride + **(**int32)(__ccgo_up(bp))
  28858 		uv_offset = **(**int32)(__ccgo_up(bp + 4))/int32(2)*(*WebPPicture)(unsafe.Pointer(pic)).Fuv_stride + **(**int32)(__ccgo_up(bp))/int32(2)
  28859 		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)
  28860 		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))
  28861 		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))
  28862 		if (**(**WebPPicture)(__ccgo_up(bp + 8))).Fa != libc.UintptrFromInt32(0) {
  28863 			a_offset = **(**int32)(__ccgo_up(bp + 4))*(*WebPPicture)(unsafe.Pointer(pic)).Fa_stride + **(**int32)(__ccgo_up(bp))
  28864 			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)
  28865 		}
  28866 	} else {
  28867 		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
  28868 		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)
  28869 	}
  28870 	WebPPictureFree(tls, pic)
  28871 	**(**WebPPicture)(__ccgo_up(pic)) = **(**WebPPicture)(__ccgo_up(bp + 8))
  28872 	return int32(1)
  28873 }
  28874 
  28875 //------------------------------------------------------------------------------
  28876 // Simple picture rescaler
  28877 
  28878 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) {
  28879 	bp := tls.Alloc(112)
  28880 	defer tls.Free(112)
  28881 	var y int32
  28882 	var _ /* rescaler at bp+0 */ WebPRescaler
  28883 	_ = y
  28884 	y = 0
  28885 	if !(WebPRescalerInit(tls, bp, src_width, src_height, dst, dst_width, dst_height, dst_stride, num_channels, work) != 0) {
  28886 		return 0
  28887 	}
  28888 	for y < src_height {
  28889 		y = y + WebPRescalerImport(tls, bp, src_height-y, src+uintptr(y*src_stride), src_stride)
  28890 		WebPRescalerExport(tls, bp)
  28891 	}
  28892 	return int32(1)
  28893 }
  28894 
  28895 func AlphaMultiplyARGB(tls *libc.TLS, pic uintptr, inverse int32) {
  28896 	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)
  28897 }
  28898 
  28899 func AlphaMultiplyY(tls *libc.TLS, pic uintptr, inverse int32) {
  28900 	if (*WebPPicture)(unsafe.Pointer(pic)).Fa != libc.UintptrFromInt32(0) {
  28901 		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)
  28902 	}
  28903 }
  28904 
  28905 func WebPPictureRescale(tls *libc.TLS, picture uintptr, _width int32, _height int32) (r int32) {
  28906 	bp := tls.Alloc(272)
  28907 	defer tls.Free(272)
  28908 	*(*int32)(unsafe.Pointer(bp)) = _width
  28909 	*(*int32)(unsafe.Pointer(bp + 4)) = _height
  28910 	var prev_height, prev_width int32
  28911 	var work uintptr
  28912 	var _ /* tmp at bp+8 */ WebPPicture
  28913 	_, _, _ = prev_height, prev_width, work
  28914 	if picture == libc.UintptrFromInt32(0) {
  28915 		return 0
  28916 	}
  28917 	prev_width = (*WebPPicture)(unsafe.Pointer(picture)).Fwidth
  28918 	prev_height = (*WebPPicture)(unsafe.Pointer(picture)).Fheight
  28919 	if !(WebPRescalerGetScaledDimensions(tls, prev_width, prev_height, bp, bp+4) != 0) {
  28920 		return WebPEncodingSetError(tls, picture, int32(VP8_ENC_ERROR_BAD_DIMENSION))
  28921 	}
  28922 	PictureGrabSpecs(tls, picture, bp+8)
  28923 	(**(**WebPPicture)(__ccgo_up(bp + 8))).Fwidth = **(**int32)(__ccgo_up(bp))
  28924 	(**(**WebPPicture)(__ccgo_up(bp + 8))).Fheight = **(**int32)(__ccgo_up(bp + 4))
  28925 	if !(WebPPictureAlloc(tls, bp+8) != 0) {
  28926 		return WebPEncodingSetError(tls, picture, (**(**WebPPicture)(__ccgo_up(bp + 8))).Ferror_code)
  28927 	}
  28928 	if !((*WebPPicture)(unsafe.Pointer(picture)).Fuse_argb != 0) {
  28929 		work = WebPSafeMalloc(tls, uint64(2)*uint64(**(**int32)(__ccgo_up(bp))), uint64(4))
  28930 		if work == libc.UintptrFromInt32(0) {
  28931 			WebPPictureFree(tls, bp+8)
  28932 			return WebPEncodingSetError(tls, picture, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  28933 		}
  28934 		// If present, we need to rescale alpha first (for AlphaMultiplyY).
  28935 		if (*WebPPicture)(unsafe.Pointer(picture)).Fa != libc.UintptrFromInt32(0) {
  28936 			WebPInitAlphaProcessing(tls)
  28937 			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) {
  28938 				return WebPEncodingSetError(tls, picture, int32(VP8_ENC_ERROR_BAD_DIMENSION))
  28939 			}
  28940 		}
  28941 		// We take transparency into account on the luma plane only. That's not
  28942 		// totally exact blending, but still is a good approximation.
  28943 		AlphaMultiplyY(tls, picture, 0)
  28944 		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) {
  28945 			return WebPEncodingSetError(tls, picture, int32(VP8_ENC_ERROR_BAD_DIMENSION))
  28946 		}
  28947 		AlphaMultiplyY(tls, bp+8, int32(1))
  28948 	} else {
  28949 		work = WebPSafeMalloc(tls, uint64(2)*uint64(**(**int32)(__ccgo_up(bp)))*uint64(4), uint64(4))
  28950 		if work == libc.UintptrFromInt32(0) {
  28951 			WebPPictureFree(tls, bp+8)
  28952 			return WebPEncodingSetError(tls, picture, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  28953 		}
  28954 		// In order to correctly interpolate colors, we need to apply the alpha
  28955 		// weighting first (black-matting), scale the RGB values, and remove
  28956 		// the premultiplication afterward (while preserving the alpha channel).
  28957 		WebPInitAlphaProcessing(tls)
  28958 		AlphaMultiplyARGB(tls, picture, 0)
  28959 		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) {
  28960 			return WebPEncodingSetError(tls, picture, int32(VP8_ENC_ERROR_BAD_DIMENSION))
  28961 		}
  28962 		AlphaMultiplyARGB(tls, bp+8, int32(1))
  28963 	}
  28964 	WebPPictureFree(tls, picture)
  28965 	WebPSafeFree(tls, work)
  28966 	**(**WebPPicture)(__ccgo_up(picture)) = **(**WebPPicture)(__ccgo_up(bp + 8))
  28967 	return int32(1)
  28968 }
  28969 
  28970 //------------------------------------------------------------------------------
  28971 
  28972 // Copyright 2011 Google Inc. All Rights Reserved.
  28973 //
  28974 // Use of this source code is governed by a BSD-style license
  28975 // that can be found in the COPYING file in the root of the source
  28976 // tree. An additional intellectual property rights grant can be found
  28977 // in the file PATENTS. All contributing project authors may
  28978 // be found in the AUTHORS file in the root of the source tree.
  28979 // -----------------------------------------------------------------------------
  28980 //
  28981 //   WebP encoder: main interface
  28982 //
  28983 // Author: Skal (pascal.massimino@gmail.com)
  28984 
  28985 // Copyright 2010 Google Inc. All Rights Reserved.
  28986 //
  28987 // Use of this source code is governed by a BSD-style license
  28988 // that can be found in the COPYING file in the root of the source
  28989 // tree. An additional intellectual property rights grant can be found
  28990 // in the file PATENTS. All contributing project authors may
  28991 // be found in the AUTHORS file in the root of the source tree.
  28992 // -----------------------------------------------------------------------------
  28993 //
  28994 //  Common types + memory wrappers
  28995 //
  28996 // Author: Skal (pascal.massimino@gmail.com)
  28997 
  28998 //------------------------------------------------------------------------------
  28999 // Helper: clean up fully transparent area to help compressibility.
  29000 
  29001 func IsTransparentARGBArea(tls *libc.TLS, ptr uintptr, stride int32, size int32) (r int32) {
  29002 	var x, y int32
  29003 	_, _ = x, y
  29004 	y = 0
  29005 	for {
  29006 		if !(y < size) {
  29007 			break
  29008 		}
  29009 		x = 0
  29010 		for {
  29011 			if !(x < size) {
  29012 				break
  29013 			}
  29014 			if **(**uint32_t)(__ccgo_up(ptr + uintptr(x)*4))&uint32(0xff000000) != 0 {
  29015 				return 0
  29016 			}
  29017 			goto _2
  29018 		_2:
  29019 			;
  29020 			x = x + 1
  29021 		}
  29022 		ptr = ptr + uintptr(stride)*4
  29023 		goto _1
  29024 	_1:
  29025 		;
  29026 		y = y + 1
  29027 	}
  29028 	return int32(1)
  29029 }
  29030 
  29031 func Flatten(tls *libc.TLS, ptr uintptr, v int32, stride int32, size int32) {
  29032 	var y int32
  29033 	_ = y
  29034 	y = 0
  29035 	for {
  29036 		if !(y < size) {
  29037 			break
  29038 		}
  29039 		libc.Xmemset(tls, ptr, v, uint64(size))
  29040 		ptr = ptr + uintptr(stride)
  29041 		goto _1
  29042 	_1:
  29043 		;
  29044 		y = y + 1
  29045 	}
  29046 }
  29047 
  29048 func FlattenARGB(tls *libc.TLS, ptr uintptr, v uint32_t, stride int32, size int32) {
  29049 	var x, y int32
  29050 	_, _ = x, y
  29051 	y = 0
  29052 	for {
  29053 		if !(y < size) {
  29054 			break
  29055 		}
  29056 		x = 0
  29057 		for {
  29058 			if !(x < size) {
  29059 				break
  29060 			}
  29061 			**(**uint32_t)(__ccgo_up(ptr + uintptr(x)*4)) = v
  29062 			goto _2
  29063 		_2:
  29064 			;
  29065 			x = x + 1
  29066 		}
  29067 		ptr = ptr + uintptr(stride)*4
  29068 		goto _1
  29069 	_1:
  29070 		;
  29071 		y = y + 1
  29072 	}
  29073 }
  29074 
  29075 // C documentation
  29076 //
  29077 //	// Smoothen the luma components of transparent pixels. Return true if the whole
  29078 //	// block is transparent.
  29079 func SmoothenBlock(tls *libc.TLS, a_ptr uintptr, a_stride int32, y_ptr uintptr, y_stride int32, width int32, height int32) (r int32) {
  29080 	var alpha_ptr, luma_ptr uintptr
  29081 	var avg_u8 uint8_t
  29082 	var count, sum, x, y int32
  29083 	_, _, _, _, _, _, _ = alpha_ptr, avg_u8, count, luma_ptr, sum, x, y
  29084 	sum = 0
  29085 	count = 0
  29086 	alpha_ptr = a_ptr
  29087 	luma_ptr = y_ptr
  29088 	y = 0
  29089 	for {
  29090 		if !(y < height) {
  29091 			break
  29092 		}
  29093 		x = 0
  29094 		for {
  29095 			if !(x < width) {
  29096 				break
  29097 			}
  29098 			if int32(**(**uint8_t)(__ccgo_up(alpha_ptr + uintptr(x)))) != 0 {
  29099 				count = count + 1
  29100 				sum = sum + int32(**(**uint8_t)(__ccgo_up(luma_ptr + uintptr(x))))
  29101 			}
  29102 			goto _2
  29103 		_2:
  29104 			;
  29105 			x = x + 1
  29106 		}
  29107 		alpha_ptr = alpha_ptr + uintptr(a_stride)
  29108 		luma_ptr = luma_ptr + uintptr(y_stride)
  29109 		goto _1
  29110 	_1:
  29111 		;
  29112 		y = y + 1
  29113 	}
  29114 	if count > 0 && count < width*height {
  29115 		avg_u8 = uint8(sum / count)
  29116 		alpha_ptr = a_ptr
  29117 		luma_ptr = y_ptr
  29118 		y = 0
  29119 		for {
  29120 			if !(y < height) {
  29121 				break
  29122 			}
  29123 			x = 0
  29124 			for {
  29125 				if !(x < width) {
  29126 					break
  29127 				}
  29128 				if int32(**(**uint8_t)(__ccgo_up(alpha_ptr + uintptr(x)))) == 0 {
  29129 					**(**uint8_t)(__ccgo_up(luma_ptr + uintptr(x))) = avg_u8
  29130 				}
  29131 				goto _4
  29132 			_4:
  29133 				;
  29134 				x = x + 1
  29135 			}
  29136 			alpha_ptr = alpha_ptr + uintptr(a_stride)
  29137 			luma_ptr = luma_ptr + uintptr(y_stride)
  29138 			goto _3
  29139 		_3:
  29140 			;
  29141 			y = y + 1
  29142 		}
  29143 	}
  29144 	return libc.BoolInt32(count == 0)
  29145 }
  29146 
  29147 func WebPReplaceTransparentPixels(tls *libc.TLS, pic uintptr, color uint32_t) {
  29148 	var argb uintptr
  29149 	var y, v1 int32
  29150 	_, _, _ = argb, y, v1
  29151 	if pic != libc.UintptrFromInt32(0) && (*WebPPicture)(unsafe.Pointer(pic)).Fuse_argb != 0 {
  29152 		y = (*WebPPicture)(unsafe.Pointer(pic)).Fheight
  29153 		argb = (*WebPPicture)(unsafe.Pointer(pic)).Fargb
  29154 		color = color & uint32(0xffffff) // force alpha=0
  29155 		WebPInitAlphaProcessing(tls)
  29156 		for {
  29157 			v1 = y
  29158 			y = y - 1
  29159 			if !(v1 > 0) {
  29160 				break
  29161 			}
  29162 			(*(*func(*libc.TLS, uintptr, int32, uint32_t))(unsafe.Pointer(&struct{ uintptr }{WebPAlphaReplace})))(tls, argb, (*WebPPicture)(unsafe.Pointer(pic)).Fwidth, color)
  29163 			argb = argb + uintptr((*WebPPicture)(unsafe.Pointer(pic)).Fargb_stride)*4
  29164 		}
  29165 	}
  29166 }
  29167 
  29168 func WebPCleanupTransparentArea(tls *libc.TLS, pic uintptr) {
  29169 	var a_ptr, u_ptr, v_ptr, y_ptr uintptr
  29170 	var a_stride, h, height, need_reset, need_reset1, off, sub_height, uv_stride, w, width, x, y, y_stride int32
  29171 	var argb_value uint32_t
  29172 	var values [3]int32
  29173 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  29174 	if pic == libc.UintptrFromInt32(0) {
  29175 		return
  29176 	}
  29177 	w = (*WebPPicture)(unsafe.Pointer(pic)).Fwidth / int32(8)
  29178 	h = (*WebPPicture)(unsafe.Pointer(pic)).Fheight / int32(8)
  29179 	// note: we ignore the left-overs on right/bottom, except for SmoothenBlock().
  29180 	if (*WebPPicture)(unsafe.Pointer(pic)).Fuse_argb != 0 {
  29181 		argb_value = uint32(0)
  29182 		y = 0
  29183 		for {
  29184 			if !(y < h) {
  29185 				break
  29186 			}
  29187 			need_reset = int32(1)
  29188 			x = 0
  29189 			for {
  29190 				if !(x < w) {
  29191 					break
  29192 				}
  29193 				off = (y*(*WebPPicture)(unsafe.Pointer(pic)).Fargb_stride + x) * int32(8)
  29194 				if IsTransparentARGBArea(tls, (*WebPPicture)(unsafe.Pointer(pic)).Fargb+uintptr(off)*4, (*WebPPicture)(unsafe.Pointer(pic)).Fargb_stride, int32(8)) != 0 {
  29195 					if need_reset != 0 {
  29196 						argb_value = **(**uint32_t)(__ccgo_up((*WebPPicture)(unsafe.Pointer(pic)).Fargb + uintptr(off)*4))
  29197 						need_reset = 0
  29198 					}
  29199 					FlattenARGB(tls, (*WebPPicture)(unsafe.Pointer(pic)).Fargb+uintptr(off)*4, argb_value, (*WebPPicture)(unsafe.Pointer(pic)).Fargb_stride, int32(8))
  29200 				} else {
  29201 					need_reset = int32(1)
  29202 				}
  29203 				goto _2
  29204 			_2:
  29205 				;
  29206 				x = x + 1
  29207 			}
  29208 			goto _1
  29209 		_1:
  29210 			;
  29211 			y = y + 1
  29212 		}
  29213 	} else {
  29214 		width = (*WebPPicture)(unsafe.Pointer(pic)).Fwidth
  29215 		height = (*WebPPicture)(unsafe.Pointer(pic)).Fheight
  29216 		y_stride = (*WebPPicture)(unsafe.Pointer(pic)).Fy_stride
  29217 		uv_stride = (*WebPPicture)(unsafe.Pointer(pic)).Fuv_stride
  29218 		a_stride = (*WebPPicture)(unsafe.Pointer(pic)).Fa_stride
  29219 		y_ptr = (*WebPPicture)(unsafe.Pointer(pic)).Fy
  29220 		u_ptr = (*WebPPicture)(unsafe.Pointer(pic)).Fu
  29221 		v_ptr = (*WebPPicture)(unsafe.Pointer(pic)).Fv
  29222 		a_ptr = (*WebPPicture)(unsafe.Pointer(pic)).Fa
  29223 		values = [3]int32{}
  29224 		if a_ptr == libc.UintptrFromInt32(0) || y_ptr == libc.UintptrFromInt32(0) || u_ptr == libc.UintptrFromInt32(0) || v_ptr == libc.UintptrFromInt32(0) {
  29225 			return
  29226 		}
  29227 		y = 0
  29228 		for {
  29229 			if !(y+int32(8) <= height) {
  29230 				break
  29231 			}
  29232 			need_reset1 = int32(1)
  29233 			x = 0
  29234 			for {
  29235 				if !(x+int32(8) <= width) {
  29236 					break
  29237 				}
  29238 				if SmoothenBlock(tls, a_ptr+uintptr(x), a_stride, y_ptr+uintptr(x), y_stride, int32(8), int32(8)) != 0 {
  29239 					if need_reset1 != 0 {
  29240 						values[0] = int32(**(**uint8_t)(__ccgo_up(y_ptr + uintptr(x))))
  29241 						values[int32(1)] = int32(**(**uint8_t)(__ccgo_up(u_ptr + uintptr(x>>int32(1)))))
  29242 						values[int32(2)] = int32(**(**uint8_t)(__ccgo_up(v_ptr + uintptr(x>>int32(1)))))
  29243 						need_reset1 = 0
  29244 					}
  29245 					Flatten(tls, y_ptr+uintptr(x), values[0], y_stride, int32(8))
  29246 					Flatten(tls, u_ptr+uintptr(x>>libc.Int32FromInt32(1)), values[int32(1)], uv_stride, libc.Int32FromInt32(8)/libc.Int32FromInt32(2))
  29247 					Flatten(tls, v_ptr+uintptr(x>>libc.Int32FromInt32(1)), values[int32(2)], uv_stride, libc.Int32FromInt32(8)/libc.Int32FromInt32(2))
  29248 				} else {
  29249 					need_reset1 = int32(1)
  29250 				}
  29251 				goto _4
  29252 			_4:
  29253 				;
  29254 				x = x + int32(8)
  29255 			}
  29256 			if x < width {
  29257 				SmoothenBlock(tls, a_ptr+uintptr(x), a_stride, y_ptr+uintptr(x), y_stride, width-x, int32(8))
  29258 			}
  29259 			a_ptr = a_ptr + uintptr(int32(8)*a_stride)
  29260 			y_ptr = y_ptr + uintptr(int32(8)*y_stride)
  29261 			u_ptr = u_ptr + uintptr(libc.Int32FromInt32(8)/libc.Int32FromInt32(2)*uv_stride)
  29262 			v_ptr = v_ptr + uintptr(libc.Int32FromInt32(8)/libc.Int32FromInt32(2)*uv_stride)
  29263 			goto _3
  29264 		_3:
  29265 			;
  29266 			y = y + int32(8)
  29267 		}
  29268 		if y < height {
  29269 			sub_height = height - y
  29270 			x = 0
  29271 			for {
  29272 				if !(x+int32(8) <= width) {
  29273 					break
  29274 				}
  29275 				SmoothenBlock(tls, a_ptr+uintptr(x), a_stride, y_ptr+uintptr(x), y_stride, int32(8), sub_height)
  29276 				goto _5
  29277 			_5:
  29278 				;
  29279 				x = x + int32(8)
  29280 			}
  29281 			if x < width {
  29282 				SmoothenBlock(tls, a_ptr+uintptr(x), a_stride, y_ptr+uintptr(x), y_stride, width-x, sub_height)
  29283 			}
  29284 		}
  29285 	}
  29286 }
  29287 
  29288 //------------------------------------------------------------------------------
  29289 // Blend color and remove transparency info
  29290 
  29291 func MakeARGB32(tls *libc.TLS, r int32, g int32, b int32) (r1 uint32_t) {
  29292 	return libc.Uint32FromUint32(0xff000000) | uint32(r<<libc.Int32FromInt32(16)) | uint32(g<<libc.Int32FromInt32(8)) | uint32(b)
  29293 }
  29294 
  29295 func WebPBlendAlpha(tls *libc.TLS, picture uintptr, background_rgb uint32_t) {
  29296 	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
  29297 	var a_ptr, a_ptr2, argb, u_ptr, v_ptr, y_ptr, v19 uintptr
  29298 	var alpha uint8_t
  29299 	var alpha1, alpha2, background uint32_t
  29300 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  29301 	red = int32(background_rgb >> libc.Int32FromInt32(16) & uint32(0xff))
  29302 	green = int32(background_rgb >> libc.Int32FromInt32(8) & uint32(0xff))
  29303 	blue = int32(background_rgb >> libc.Int32FromInt32(0) & uint32(0xff))
  29304 	if picture == libc.UintptrFromInt32(0) {
  29305 		return
  29306 	}
  29307 	if !((*WebPPicture)(unsafe.Pointer(picture)).Fuse_argb != 0) {
  29308 		// omit last pixel during u/v loop
  29309 		uv_width = (*WebPPicture)(unsafe.Pointer(picture)).Fwidth >> libc.Int32FromInt32(1)
  29310 		luma = int32(16839)*red + int32(33059)*green + int32(6420)*blue
  29311 		v1 = (luma + int32(YUV_HALF) + libc.Int32FromInt32(16)<<int32(YUV_FIX)) >> int32(YUV_FIX)
  29312 		goto _2
  29313 	_2:
  29314 		Y0 = v1
  29315 		u = -int32(9719)*(int32(4)*red) - int32(19081)*(int32(4)*green) + int32(28800)*(int32(4)*blue)
  29316 		v5 = u
  29317 		v5 = (v5 + libc.Int32FromInt32(4)*int32(YUV_HALF) + libc.Int32FromInt32(128)<<(int32(YUV_FIX)+libc.Int32FromInt32(2))) >> (int32(YUV_FIX) + libc.Int32FromInt32(2))
  29318 		if v5 & ^libc.Int32FromInt32(0xff) == 0 {
  29319 			v8 = v5
  29320 		} else {
  29321 			if v5 < 0 {
  29322 				v9 = 0
  29323 			} else {
  29324 				v9 = int32(255)
  29325 			}
  29326 			v8 = v9
  29327 		}
  29328 		v6 = v8
  29329 		goto _7
  29330 	_7:
  29331 		v3 = v6
  29332 		goto _4
  29333 	_4:
  29334 		// VP8RGBToU/V expects the u/v values summed over four pixels
  29335 		U0 = v3
  29336 		v = +libc.Int32FromInt32(28800)*(int32(4)*red) - int32(24116)*(int32(4)*green) - int32(4684)*(int32(4)*blue)
  29337 		v12 = v
  29338 		v12 = (v12 + libc.Int32FromInt32(4)*int32(YUV_HALF) + libc.Int32FromInt32(128)<<(int32(YUV_FIX)+libc.Int32FromInt32(2))) >> (int32(YUV_FIX) + libc.Int32FromInt32(2))
  29339 		if v12 & ^libc.Int32FromInt32(0xff) == 0 {
  29340 			v15 = v12
  29341 		} else {
  29342 			if v12 < 0 {
  29343 				v16 = 0
  29344 			} else {
  29345 				v16 = int32(255)
  29346 			}
  29347 			v15 = v16
  29348 		}
  29349 		v13 = v15
  29350 		goto _14
  29351 	_14:
  29352 		v10 = v13
  29353 		goto _11
  29354 	_11:
  29355 		V0 = v10
  29356 		has_alpha = (*WebPPicture)(unsafe.Pointer(picture)).Fcolorspace & int32(WEBP_CSP_ALPHA_BIT)
  29357 		y_ptr = (*WebPPicture)(unsafe.Pointer(picture)).Fy
  29358 		u_ptr = (*WebPPicture)(unsafe.Pointer(picture)).Fu
  29359 		v_ptr = (*WebPPicture)(unsafe.Pointer(picture)).Fv
  29360 		a_ptr = (*WebPPicture)(unsafe.Pointer(picture)).Fa
  29361 		if !(has_alpha != 0) || a_ptr == libc.UintptrFromInt32(0) {
  29362 			return
  29363 		} // nothing to do
  29364 		y = 0
  29365 		for {
  29366 			if !(y < (*WebPPicture)(unsafe.Pointer(picture)).Fheight) {
  29367 				break
  29368 			}
  29369 			// Luma blending
  29370 			x = 0
  29371 			for {
  29372 				if !(x < (*WebPPicture)(unsafe.Pointer(picture)).Fwidth) {
  29373 					break
  29374 				}
  29375 				alpha = **(**uint8_t)(__ccgo_up(a_ptr + uintptr(x)))
  29376 				if int32(alpha) < int32(0xff) {
  29377 					**(**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))
  29378 				}
  29379 				goto _18
  29380 			_18:
  29381 				;
  29382 				x = x + 1
  29383 			}
  29384 			// Chroma blending every even line
  29385 			if y&int32(1) == 0 {
  29386 				if y+int32(1) == (*WebPPicture)(unsafe.Pointer(picture)).Fheight {
  29387 					v19 = a_ptr
  29388 				} else {
  29389 					v19 = a_ptr + uintptr((*WebPPicture)(unsafe.Pointer(picture)).Fa_stride)
  29390 				}
  29391 				a_ptr2 = v19
  29392 				x = 0
  29393 				for {
  29394 					if !(x < uv_width) {
  29395 						break
  29396 					}
  29397 					// Average four alpha values into a single blending weight.
  29398 					// TODO(skal): might lead to visible contouring. Can we do better?
  29399 					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))))))
  29400 					**(**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))
  29401 					**(**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))
  29402 					goto _20
  29403 				_20:
  29404 					;
  29405 					x = x + 1
  29406 				}
  29407 				if (*WebPPicture)(unsafe.Pointer(picture)).Fwidth&int32(1) != 0 { // rightmost pixel
  29408 					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))))))
  29409 					**(**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))
  29410 					**(**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))
  29411 				}
  29412 			} else {
  29413 				u_ptr = u_ptr + uintptr((*WebPPicture)(unsafe.Pointer(picture)).Fuv_stride)
  29414 				v_ptr = v_ptr + uintptr((*WebPPicture)(unsafe.Pointer(picture)).Fuv_stride)
  29415 			}
  29416 			libc.Xmemset(tls, a_ptr, int32(0xff), uint64((*WebPPicture)(unsafe.Pointer(picture)).Fwidth)) // reset alpha value to opaque
  29417 			a_ptr = a_ptr + uintptr((*WebPPicture)(unsafe.Pointer(picture)).Fa_stride)
  29418 			y_ptr = y_ptr + uintptr((*WebPPicture)(unsafe.Pointer(picture)).Fy_stride)
  29419 			goto _17
  29420 		_17:
  29421 			;
  29422 			y = y + 1
  29423 		}
  29424 	} else {
  29425 		argb = (*WebPPicture)(unsafe.Pointer(picture)).Fargb
  29426 		background = MakeARGB32(tls, red, green, blue)
  29427 		y = 0
  29428 		for {
  29429 			if !(y < (*WebPPicture)(unsafe.Pointer(picture)).Fheight) {
  29430 				break
  29431 			}
  29432 			x = 0
  29433 			for {
  29434 				if !(x < (*WebPPicture)(unsafe.Pointer(picture)).Fwidth) {
  29435 					break
  29436 				}
  29437 				alpha3 = int32(**(**uint32_t)(__ccgo_up(argb + uintptr(x)*4)) >> libc.Int32FromInt32(24) & uint32(0xff))
  29438 				if alpha3 != int32(0xff) {
  29439 					if alpha3 > 0 {
  29440 						r3 = int32(**(**uint32_t)(__ccgo_up(argb + uintptr(x)*4)) >> libc.Int32FromInt32(16) & uint32(0xff))
  29441 						g3 = int32(**(**uint32_t)(__ccgo_up(argb + uintptr(x)*4)) >> libc.Int32FromInt32(8) & uint32(0xff))
  29442 						b3 = int32(**(**uint32_t)(__ccgo_up(argb + uintptr(x)*4)) >> libc.Int32FromInt32(0) & uint32(0xff))
  29443 						r3 = ((red*(int32(255)-alpha3)+r3*alpha3)*int32(0x101) + int32(256)) >> int32(16)
  29444 						g3 = ((green*(int32(255)-alpha3)+g3*alpha3)*int32(0x101) + int32(256)) >> int32(16)
  29445 						b3 = ((blue*(int32(255)-alpha3)+b3*alpha3)*int32(0x101) + int32(256)) >> int32(16)
  29446 						**(**uint32_t)(__ccgo_up(argb + uintptr(x)*4)) = MakeARGB32(tls, r3, g3, b3)
  29447 					} else {
  29448 						**(**uint32_t)(__ccgo_up(argb + uintptr(x)*4)) = background
  29449 					}
  29450 				}
  29451 				goto _22
  29452 			_22:
  29453 				;
  29454 				x = x + 1
  29455 			}
  29456 			argb = argb + uintptr((*WebPPicture)(unsafe.Pointer(picture)).Fargb_stride)*4
  29457 			goto _21
  29458 		_21:
  29459 			;
  29460 			y = y + 1
  29461 		}
  29462 	}
  29463 }
  29464 
  29465 const ARGB_BLACK1 = 4278190080
  29466 const SIZE_MAX12 = "_UI64_MAX"
  29467 
  29468 //------------------------------------------------------------------------------
  29469 
  29470 // Copyright 2012 Google Inc. All Rights Reserved.
  29471 //
  29472 // Use of this source code is governed by a BSD-style license
  29473 // that can be found in the COPYING file in the root of the source
  29474 // tree. An additional intellectual property rights grant can be found
  29475 // in the file PATENTS. All contributing project authors may
  29476 // be found in the AUTHORS file in the root of the source tree.
  29477 // -----------------------------------------------------------------------------
  29478 //
  29479 // Misc. common utility functions
  29480 //
  29481 // Authors: Skal (pascal.massimino@gmail.com)
  29482 //          Urvang (urvang@google.com)
  29483 
  29484 // Copyright 2011 Google Inc. All Rights Reserved.
  29485 //
  29486 // Use of this source code is governed by a BSD-style license
  29487 // that can be found in the COPYING file in the root of the source
  29488 // tree. An additional intellectual property rights grant can be found
  29489 // in the file PATENTS. All contributing project authors may
  29490 // be found in the AUTHORS file in the root of the source tree.
  29491 // -----------------------------------------------------------------------------
  29492 //
  29493 //   WebP encoder: main interface
  29494 //
  29495 // Author: Skal (pascal.massimino@gmail.com)
  29496 
  29497 // Copyright 2012 Google Inc. All Rights Reserved.
  29498 //
  29499 // Use of this source code is governed by a BSD-style license
  29500 // that can be found in the COPYING file in the root of the source
  29501 // tree. An additional intellectual property rights grant can be found
  29502 // in the file PATENTS. All contributing project authors may
  29503 // be found in the AUTHORS file in the root of the source tree.
  29504 // -----------------------------------------------------------------------------
  29505 //
  29506 //  Internal header for constants related to WebP file format.
  29507 //
  29508 // Author: Urvang (urvang@google.com)
  29509 
  29510 // Copyright 2010 Google Inc. All Rights Reserved.
  29511 //
  29512 // Use of this source code is governed by a BSD-style license
  29513 // that can be found in the COPYING file in the root of the source
  29514 // tree. An additional intellectual property rights grant can be found
  29515 // in the file PATENTS. All contributing project authors may
  29516 // be found in the AUTHORS file in the root of the source tree.
  29517 // -----------------------------------------------------------------------------
  29518 //
  29519 //  Common types + memory wrappers
  29520 //
  29521 // Author: Skal (pascal.massimino@gmail.com)
  29522 
  29523 var kSpatialPredictorBias = libc.Int64FromInt64(15) << libc.Int32FromInt32(LOG_2_PRECISION_BITS)
  29524 var kPredLowEffort = int32(11)
  29525 var kMaskAlpha = uint32(0xff000000)
  29526 var kNumPredModes = int32(14)
  29527 
  29528 // C documentation
  29529 //
  29530 //	// Mostly used to reduce code size + readability
  29531 func GetMin(tls *libc.TLS, a int32, b int32) (r int32) {
  29532 	var v1 int32
  29533 	_ = v1
  29534 	if a > b {
  29535 		v1 = b
  29536 	} else {
  29537 		v1 = a
  29538 	}
  29539 	return v1
  29540 }
  29541 
  29542 func GetMax(tls *libc.TLS, a int32, b int32) (r int32) {
  29543 	var v1 int32
  29544 	_ = v1
  29545 	if a < b {
  29546 		v1 = b
  29547 	} else {
  29548 		v1 = a
  29549 	}
  29550 	return v1
  29551 }
  29552 
  29553 //------------------------------------------------------------------------------
  29554 // Methods to calculate Entropy (Shannon).
  29555 
  29556 // C documentation
  29557 //
  29558 //	// Compute a bias for prediction entropy using a global heuristic to favor
  29559 //	// values closer to 0. Hence the final negative sign.
  29560 //	// 'exp_val' has a scaling factor of 1/100.
  29561 func PredictionCostBias(tls *libc.TLS, counts uintptr, weight_0 uint64_t, exp_val uint64_t) (r int64_t) {
  29562 	var bits, exp_decay_factor uint64_t
  29563 	var i, significant_symbols int32
  29564 	var v6 int64
  29565 	var v2, v3, v4 int64_t
  29566 	_, _, _, _, _, _, _, _ = bits, exp_decay_factor, i, significant_symbols, v2, v3, v4, v6
  29567 	significant_symbols = libc.Int32FromInt32(256) >> libc.Int32FromInt32(4)
  29568 	exp_decay_factor = uint64(6) // has a scaling factor of 1/10
  29569 	bits = weight_0 * uint64(**(**uint32_t)(__ccgo_up(counts))) << int32(LOG_2_PRECISION_BITS)
  29570 	exp_val = exp_val << uint64(LOG_2_PRECISION_BITS)
  29571 	i = int32(1)
  29572 	for {
  29573 		if !(i < significant_symbols) {
  29574 			break
  29575 		}
  29576 		v2 = int64(exp_val * uint64(**(**uint32_t)(__ccgo_up(counts + uintptr(i)*4))+**(**uint32_t)(__ccgo_up(counts + uintptr(int32(256)-i)*4))))
  29577 		v3 = int64(100)
  29578 		if libc.BoolInt32(v2 < 0) == libc.BoolInt32(v3 < 0) {
  29579 			v6 = (v2 + v3/int64(2)) / v3
  29580 		} else {
  29581 			v6 = (v2 - v3/int64(2)) / v3
  29582 		}
  29583 		v4 = v6
  29584 		goto _5
  29585 	_5:
  29586 		bits = bits + uint64(v4)
  29587 		v2 = int64(exp_decay_factor * exp_val)
  29588 		v3 = int64(10)
  29589 		if libc.BoolInt32(v2 < 0) == libc.BoolInt32(v3 < 0) {
  29590 			v6 = (v2 + v3/int64(2)) / v3
  29591 		} else {
  29592 			v6 = (v2 - v3/int64(2)) / v3
  29593 		}
  29594 		v4 = v6
  29595 		goto _10
  29596 	_10:
  29597 		exp_val = uint64(v4)
  29598 		goto _1
  29599 	_1:
  29600 		;
  29601 		i = i + 1
  29602 	}
  29603 	v2 = int64(bits)
  29604 	v3 = int64(10)
  29605 	if libc.BoolInt32(v2 < 0) == libc.BoolInt32(v3 < 0) {
  29606 		v6 = (v2 + v3/int64(2)) / v3
  29607 	} else {
  29608 		v6 = (v2 - v3/int64(2)) / v3
  29609 	}
  29610 	v4 = v6
  29611 	goto _15
  29612 _15:
  29613 	return -v4
  29614 }
  29615 
  29616 func PredictionCostSpatialHistogram(tls *libc.TLS, accumulated uintptr, tile uintptr, mode int32, left_mode int32, above_mode int32) (r int64_t) {
  29617 	var i int32
  29618 	var kExpValue uint64_t
  29619 	var retval int64_t
  29620 	_, _, _ = i, kExpValue, retval
  29621 	retval = 0
  29622 	i = 0
  29623 	for {
  29624 		if !(i < int32(4)) {
  29625 			break
  29626 		}
  29627 		kExpValue = uint64(94)
  29628 		retval = retval + PredictionCostBias(tls, tile+uintptr(i*int32(256))*4, uint64(1), kExpValue)
  29629 		// Compute the new cost if 'tile' is added to 'accumulate' but also add the
  29630 		// cost of the current histogram to guide the spatial predictor selection.
  29631 		// Basically, favor low entropy, locally and globally.
  29632 		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))
  29633 		goto _1
  29634 	_1:
  29635 		;
  29636 		i = i + 1
  29637 	}
  29638 	// Favor keeping the areas locally similar.
  29639 	if mode == left_mode {
  29640 		retval = retval - kSpatialPredictorBias
  29641 	}
  29642 	if mode == above_mode {
  29643 		retval = retval - kSpatialPredictorBias
  29644 	}
  29645 	return retval
  29646 }
  29647 
  29648 func UpdateHisto(tls *libc.TLS, histo_argb uintptr, argb uint32_t) {
  29649 	**(**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
  29650 	**(**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
  29651 	**(**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
  29652 	**(**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
  29653 }
  29654 
  29655 //------------------------------------------------------------------------------
  29656 // Spatial transform functions.
  29657 
  29658 func PredictBatch(tls *libc.TLS, mode int32, x_start int32, y int32, num_pixels int32, current uintptr, upper uintptr, out uintptr) {
  29659 	if x_start == 0 {
  29660 		if y == 0 {
  29661 			// ARGB_BLACK.
  29662 			(*(*func(*libc.TLS, uintptr, uintptr, int32, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8LPredictorsSub[libc.Int32FromInt32(0)]})))(tls, current, libc.UintptrFromInt32(0), int32(1), out)
  29663 		} else {
  29664 			// Top one.
  29665 			(*(*func(*libc.TLS, uintptr, uintptr, int32, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8LPredictorsSub[libc.Int32FromInt32(2)]})))(tls, current, upper, int32(1), out)
  29666 		}
  29667 		x_start = x_start + 1
  29668 		out += 4
  29669 		num_pixels = num_pixels - 1
  29670 	}
  29671 	if y == 0 {
  29672 		// Left one.
  29673 		(*(*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)
  29674 	} else {
  29675 		(*(*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)
  29676 	}
  29677 }
  29678 
  29679 func MaxDiffBetweenPixels(tls *libc.TLS, p1 uint32_t, p2 uint32_t) (r int32) {
  29680 	var diff_a, diff_b, diff_g, diff_r int32
  29681 	_, _, _, _ = diff_a, diff_b, diff_g, diff_r
  29682 	diff_a = libc.Xabs(tls, int32(p1>>libc.Int32FromInt32(24))-int32(p2>>libc.Int32FromInt32(24)))
  29683 	diff_r = libc.Xabs(tls, int32(p1>>libc.Int32FromInt32(16)&libc.Uint32FromInt32(0xff))-int32(p2>>libc.Int32FromInt32(16)&libc.Uint32FromInt32(0xff)))
  29684 	diff_g = libc.Xabs(tls, int32(p1>>libc.Int32FromInt32(8)&libc.Uint32FromInt32(0xff))-int32(p2>>libc.Int32FromInt32(8)&libc.Uint32FromInt32(0xff)))
  29685 	diff_b = libc.Xabs(tls, int32(p1&libc.Uint32FromInt32(0xff))-int32(p2&libc.Uint32FromInt32(0xff)))
  29686 	return GetMax(tls, GetMax(tls, diff_a, diff_r), GetMax(tls, diff_g, diff_b))
  29687 }
  29688 
  29689 func MaxDiffAroundPixel(tls *libc.TLS, current uint32_t, up uint32_t, down uint32_t, left uint32_t, right uint32_t) (r int32) {
  29690 	var diff_down, diff_left, diff_right, diff_up int32
  29691 	_, _, _, _ = diff_down, diff_left, diff_right, diff_up
  29692 	diff_up = MaxDiffBetweenPixels(tls, current, up)
  29693 	diff_down = MaxDiffBetweenPixels(tls, current, down)
  29694 	diff_left = MaxDiffBetweenPixels(tls, current, left)
  29695 	diff_right = MaxDiffBetweenPixels(tls, current, right)
  29696 	return GetMax(tls, GetMax(tls, diff_up, diff_down), GetMax(tls, diff_left, diff_right))
  29697 }
  29698 
  29699 func AddGreenToBlueAndRed(tls *libc.TLS, argb uint32_t) (r uint32_t) {
  29700 	var green, red_blue uint32_t
  29701 	_, _ = green, red_blue
  29702 	green = argb >> libc.Int32FromInt32(8) & uint32(0xff)
  29703 	red_blue = argb & uint32(0x00ff00ff)
  29704 	red_blue = red_blue + (green<<libc.Int32FromInt32(16) | green)
  29705 	red_blue = red_blue & uint32(0x00ff00ff)
  29706 	return argb&uint32(0xff00ff00) | red_blue
  29707 }
  29708 
  29709 func MaxDiffsForRow(tls *libc.TLS, width int32, stride int32, argb uintptr, max_diffs uintptr, used_subtract_green int32) {
  29710 	var current, down, left, right, up uint32_t
  29711 	var x int32
  29712 	_, _, _, _, _, _ = current, down, left, right, up, x
  29713 	if width <= int32(2) {
  29714 		return
  29715 	}
  29716 	current = **(**uint32_t)(__ccgo_up(argb))
  29717 	right = **(**uint32_t)(__ccgo_up(argb + 1*4))
  29718 	if used_subtract_green != 0 {
  29719 		current = AddGreenToBlueAndRed(tls, current)
  29720 		right = AddGreenToBlueAndRed(tls, right)
  29721 	}
  29722 	// max_diffs[0] and max_diffs[width - 1] are never used.
  29723 	x = int32(1)
  29724 	for {
  29725 		if !(x < width-int32(1)) {
  29726 			break
  29727 		}
  29728 		up = **(**uint32_t)(__ccgo_up(argb + uintptr(-stride+x)*4))
  29729 		down = **(**uint32_t)(__ccgo_up(argb + uintptr(stride+x)*4))
  29730 		left = current
  29731 		current = right
  29732 		right = **(**uint32_t)(__ccgo_up(argb + uintptr(x+int32(1))*4))
  29733 		if used_subtract_green != 0 {
  29734 			up = AddGreenToBlueAndRed(tls, up)
  29735 			down = AddGreenToBlueAndRed(tls, down)
  29736 			right = AddGreenToBlueAndRed(tls, right)
  29737 		}
  29738 		**(**uint8_t)(__ccgo_up(max_diffs + uintptr(x))) = uint8(MaxDiffAroundPixel(tls, current, up, down, left, right))
  29739 		goto _1
  29740 	_1:
  29741 		;
  29742 		x = x + 1
  29743 	}
  29744 }
  29745 
  29746 // C documentation
  29747 //
  29748 //	// Quantize the difference between the actual component value and its prediction
  29749 //	// to a multiple of quantization, working modulo 256, taking care not to cross
  29750 //	// a boundary (inclusive upper limit).
  29751 func NearLosslessComponent(tls *libc.TLS, value uint8_t, predict uint8_t, boundary uint8_t, quantization int32) (r uint8_t) {
  29752 	var bias, boundary_residual, lower, residual, upper int32
  29753 	_, _, _, _, _ = bias, boundary_residual, lower, residual, upper
  29754 	residual = (int32(value) - int32(predict)) & int32(0xff)
  29755 	boundary_residual = (int32(boundary) - int32(predict)) & int32(0xff)
  29756 	lower = residual & ^(quantization - libc.Int32FromInt32(1))
  29757 	upper = lower + quantization
  29758 	// Resolve ties towards a value closer to the prediction (i.e. towards lower
  29759 	// if value comes after prediction and towards upper otherwise).
  29760 	bias = libc.BoolInt32((int32(boundary)-int32(value))&int32(0xff) < boundary_residual)
  29761 	if residual-lower < upper-residual+bias {
  29762 		// lower is closer to residual than upper.
  29763 		if residual > boundary_residual && lower <= boundary_residual {
  29764 			// Halve quantization step to avoid crossing boundary. This midpoint is
  29765 			// on the same side of boundary as residual because midpoint >= residual
  29766 			// (since lower is closer than upper) and residual is above the boundary.
  29767 			return uint8(lower + quantization>>int32(1))
  29768 		}
  29769 		return uint8(lower)
  29770 	} else {
  29771 		// upper is closer to residual than lower.
  29772 		if residual <= boundary_residual && upper > boundary_residual {
  29773 			// Halve quantization step to avoid crossing boundary. This midpoint is
  29774 			// on the same side of boundary as residual because midpoint <= residual
  29775 			// (since upper is closer than lower) and residual is below the boundary.
  29776 			return uint8(lower + quantization>>int32(1))
  29777 		}
  29778 		return uint8(upper & int32(0xff))
  29779 	}
  29780 	return r
  29781 }
  29782 
  29783 func NearLosslessDiff(tls *libc.TLS, a uint8_t, b uint8_t) (r uint8_t) {
  29784 	return uint8((int32(a) - int32(b)) & libc.Int32FromInt32(0xff))
  29785 }
  29786 
  29787 // C documentation
  29788 //
  29789 //	// Quantize every component of the difference between the actual pixel value and
  29790 //	// its prediction to a multiple of a quantization (a power of 2, not larger than
  29791 //	// max_quantization which is a power of 2, smaller than max_diff). Take care if
  29792 //	// value and predict have undergone subtract green, which means that red and
  29793 //	// blue are represented as offsets from green.
  29794 func NearLossless1(tls *libc.TLS, value uint32_t, predict uint32_t, max_quantization int32, max_diff int32, used_subtract_green int32) (r1 uint32_t) {
  29795 	var a1, b1, g, green_diff, new_green, r uint8_t
  29796 	var alpha_and_green, red_and_blue, v1, v2, v3 uint32_t
  29797 	var quantization int32
  29798 	_, _, _, _, _, _, _, _, _, _, _, _ = a1, alpha_and_green, b1, g, green_diff, new_green, quantization, r, red_and_blue, v1, v2, v3
  29799 	new_green = uint8(0)
  29800 	green_diff = uint8(0)
  29801 	if max_diff <= int32(2) {
  29802 		v1 = value
  29803 		v2 = predict
  29804 		alpha_and_green = uint32(0x00ff00ff) + v1&uint32(0xff00ff00) - v2&uint32(0xff00ff00)
  29805 		red_and_blue = uint32(0xff00ff00) + v1&uint32(0x00ff00ff) - v2&uint32(0x00ff00ff)
  29806 		v3 = alpha_and_green&uint32(0xff00ff00) | red_and_blue&uint32(0x00ff00ff)
  29807 		goto _4
  29808 	_4:
  29809 		return v3
  29810 	}
  29811 	quantization = max_quantization
  29812 	for quantization >= max_diff {
  29813 		quantization = quantization >> int32(1)
  29814 	}
  29815 	if value>>libc.Int32FromInt32(24) == uint32(0) || value>>libc.Int32FromInt32(24) == uint32(0xff) {
  29816 		// Preserve transparency of fully transparent or fully opaque pixels.
  29817 		a1 = NearLosslessDiff(tls, uint8(value>>libc.Int32FromInt32(24)&uint32(0xff)), uint8(predict>>libc.Int32FromInt32(24)&uint32(0xff)))
  29818 	} else {
  29819 		a1 = NearLosslessComponent(tls, uint8(value>>int32(24)), uint8(predict>>int32(24)), uint8(0xff), quantization)
  29820 	}
  29821 	g = NearLosslessComponent(tls, uint8(value>>libc.Int32FromInt32(8)&uint32(0xff)), uint8(predict>>libc.Int32FromInt32(8)&uint32(0xff)), uint8(0xff), quantization)
  29822 	if used_subtract_green != 0 {
  29823 		// The green offset will be added to red and blue components during decoding
  29824 		// to obtain the actual red and blue values.
  29825 		new_green = uint8((predict>>libc.Int32FromInt32(8) + uint32(g)) & uint32(0xff))
  29826 		// The amount by which green has been adjusted during quantization. It is
  29827 		// subtracted from red and blue for compensation, to avoid accumulating two
  29828 		// quantization errors in them.
  29829 		green_diff = NearLosslessDiff(tls, new_green, uint8(value>>libc.Int32FromInt32(8)&uint32(0xff)))
  29830 	}
  29831 	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)
  29832 	b1 = NearLosslessComponent(tls, NearLosslessDiff(tls, uint8(value&uint32(0xff)), green_diff), uint8(predict&uint32(0xff)), uint8(int32(0xff)-int32(new_green)), quantization)
  29833 	return uint32(a1)<<libc.Int32FromInt32(24) | uint32(r)<<libc.Int32FromInt32(16) | uint32(g)<<libc.Int32FromInt32(8) | uint32(b1)
  29834 }
  29835 
  29836 // C documentation
  29837 //
  29838 //	// Stores the difference between the pixel and its prediction in "out".
  29839 //	// In case of a lossy encoding, updates the source image to avoid propagating
  29840 //	// the deviation further to pixels which depend on the current pixel for their
  29841 //	// predictions.
  29842 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) {
  29843 	var alpha_and_green, alpha_and_green1, predict, red_and_blue, red_and_blue1, residual, v3, v4, v5 uint32_t
  29844 	var pred_func VP8LPredictorFunc
  29845 	var x int32
  29846 	var v2 uint32
  29847 	_, _, _, _, _, _, _, _, _, _, _, _ = alpha_and_green, alpha_and_green1, pred_func, predict, red_and_blue, red_and_blue1, residual, x, v2, v3, v4, v5
  29848 	if exact != 0 {
  29849 		PredictBatch(tls, mode, x_start, y, x_end-x_start, current_row, upper_row, out)
  29850 	} else {
  29851 		pred_func = VP8LPredictors[mode]
  29852 		x = x_start
  29853 		for {
  29854 			if !(x < x_end) {
  29855 				break
  29856 			}
  29857 			if y == 0 {
  29858 				if x == 0 {
  29859 					v2 = uint32(ARGB_BLACK1)
  29860 				} else {
  29861 					v2 = **(**uint32_t)(__ccgo_up(current_row + uintptr(x-int32(1))*4))
  29862 				}
  29863 				predict = v2 // Left.
  29864 			} else {
  29865 				if x == 0 {
  29866 					predict = **(**uint32_t)(__ccgo_up(upper_row + uintptr(x)*4)) // Top.
  29867 				} else {
  29868 					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)
  29869 				}
  29870 			}
  29871 			if max_quantization == int32(1) || mode == 0 || y == 0 || y == height-int32(1) || x == 0 || x == width-int32(1) {
  29872 				v3 = **(**uint32_t)(__ccgo_up(current_row + uintptr(x)*4))
  29873 				v4 = predict
  29874 				alpha_and_green1 = uint32(0x00ff00ff) + v3&uint32(0xff00ff00) - v4&uint32(0xff00ff00)
  29875 				red_and_blue1 = uint32(0xff00ff00) + v3&uint32(0x00ff00ff) - v4&uint32(0x00ff00ff)
  29876 				v5 = alpha_and_green1&uint32(0xff00ff00) | red_and_blue1&uint32(0x00ff00ff)
  29877 				goto _6
  29878 			_6:
  29879 				residual = v5
  29880 			} else {
  29881 				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)
  29882 				// Update the source image.
  29883 				v3 = predict
  29884 				v4 = residual
  29885 				alpha_and_green = v3&uint32(0xff00ff00) + v4&uint32(0xff00ff00)
  29886 				red_and_blue = v3&uint32(0x00ff00ff) + v4&uint32(0x00ff00ff)
  29887 				v5 = alpha_and_green&uint32(0xff00ff00) | red_and_blue&uint32(0x00ff00ff)
  29888 				goto _10
  29889 			_10:
  29890 				**(**uint32_t)(__ccgo_up(current_row + uintptr(x)*4)) = v5
  29891 				// x is never 0 here so we do not need to update upper_row like below.
  29892 			}
  29893 			if **(**uint32_t)(__ccgo_up(current_row + uintptr(x)*4))&kMaskAlpha == uint32(0) {
  29894 				// If alpha is 0, cleanup RGB. We can choose the RGB values of the
  29895 				// residual for best compression. The prediction of alpha itself can be
  29896 				// non-zero and must be kept though. We choose RGB of the residual to be
  29897 				// 0.
  29898 				residual = residual & kMaskAlpha
  29899 				// Update the source image.
  29900 				**(**uint32_t)(__ccgo_up(current_row + uintptr(x)*4)) = predict & ^kMaskAlpha
  29901 				// The prediction for the rightmost pixel in a row uses the leftmost
  29902 				// pixel
  29903 				// in that row as its top-right context pixel. Hence if we change the
  29904 				// leftmost pixel of current_row, the corresponding change must be
  29905 				// applied
  29906 				// to upper_row as well where top-right context is being read from.
  29907 				if x == 0 && y != 0 {
  29908 					**(**uint32_t)(__ccgo_up(upper_row + uintptr(width)*4)) = **(**uint32_t)(__ccgo_up(current_row))
  29909 				}
  29910 			}
  29911 			**(**uint32_t)(__ccgo_up(out + uintptr(x-x_start)*4)) = residual
  29912 			goto _1
  29913 		_1:
  29914 			;
  29915 			x = x + 1
  29916 		}
  29917 	}
  29918 }
  29919 
  29920 // C documentation
  29921 //
  29922 //	// Accessors to residual histograms.
  29923 func GetHistoArgb(tls *libc.TLS, all_histos uintptr, subsampling_index int32, mode int32) (r uintptr) {
  29924 	return all_histos + uintptr((subsampling_index*kNumPredModes+mode)*(libc.Int32FromInt32(4)*libc.Int32FromInt32(256)))*4
  29925 }
  29926 
  29927 func GetHistoArgbConst(tls *libc.TLS, all_histos uintptr, subsampling_index int32, mode int32) (r uintptr) {
  29928 	return all_histos + uintptr(subsampling_index*kNumPredModes*(libc.Int32FromInt32(4)*libc.Int32FromInt32(256))+mode*(libc.Int32FromInt32(4)*libc.Int32FromInt32(256)))*4
  29929 }
  29930 
  29931 // C documentation
  29932 //
  29933 //	// Accessors to accumulated residual histogram.
  29934 func GetAccumulatedHisto(tls *libc.TLS, all_accumulated uintptr, subsampling_index int32) (r uintptr) {
  29935 	return all_accumulated + uintptr(subsampling_index*(libc.Int32FromInt32(4)*libc.Int32FromInt32(256)))*4
  29936 }
  29937 
  29938 // C documentation
  29939 //
  29940 //	// Find and store the best predictor for a tile at subsampling
  29941 //	// 'subsampling_index'.
  29942 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) {
  29943 	var above_mode, left_mode, mode int32
  29944 	var accumulated_argb, best_histo, histo_argb, modes, pred_histos uintptr
  29945 	var best_diff, cur_diff int64_t
  29946 	var best_mode uint32_t
  29947 	var v1, v2 uint32
  29948 	_, _, _, _, _, _, _, _, _, _, _, _, _ = above_mode, accumulated_argb, best_diff, best_histo, best_mode, cur_diff, histo_argb, left_mode, mode, modes, pred_histos, v1, v2
  29949 	accumulated_argb = GetAccumulatedHisto(tls, all_accumulated_argb, subsampling_index)
  29950 	modes = **(**uintptr)(__ccgo_up(all_modes + uintptr(subsampling_index)*8))
  29951 	pred_histos = all_pred_histos + uintptr(subsampling_index*kNumPredModes)*4
  29952 	if tile_x > 0 {
  29953 		v1 = **(**uint32_t)(__ccgo_up(modes + uintptr(tile_y*tiles_per_row+tile_x-int32(1))*4)) >> libc.Int32FromInt32(8) & uint32(0xff)
  29954 	} else {
  29955 		v1 = uint32(0xff)
  29956 	}
  29957 	// Prediction modes of the left and above neighbor tiles.
  29958 	left_mode = int32(v1)
  29959 	if tile_y > 0 {
  29960 		v2 = **(**uint32_t)(__ccgo_up(modes + uintptr((tile_y-int32(1))*tiles_per_row+tile_x)*4)) >> libc.Int32FromInt32(8) & uint32(0xff)
  29961 	} else {
  29962 		v2 = uint32(0xff)
  29963 	}
  29964 	above_mode = int32(v2)
  29965 	best_diff = int64(libc.Uint64FromUint64(1)<<libc.Int32FromInt32(63) - libc.Uint64FromInt32(1))
  29966 	best_mode = uint32(0)
  29967 	best_histo = GetHistoArgbConst(tls, all_argb, 0, int32(best_mode))
  29968 	mode = 0
  29969 	for {
  29970 		if !(mode < kNumPredModes) {
  29971 			break
  29972 		}
  29973 		histo_argb = GetHistoArgbConst(tls, all_argb, subsampling_index, mode)
  29974 		cur_diff = PredictionCostSpatialHistogram(tls, accumulated_argb, histo_argb, mode, left_mode, above_mode)
  29975 		if cur_diff < best_diff {
  29976 			best_histo = histo_argb
  29977 			best_diff = cur_diff
  29978 			best_mode = uint32(mode)
  29979 		}
  29980 		goto _3
  29981 	_3:
  29982 		;
  29983 		mode = mode + 1
  29984 	}
  29985 	// Update the accumulated histogram.
  29986 	(*(*func(*libc.TLS, uintptr, uintptr, int32))(unsafe.Pointer(&struct{ uintptr }{VP8LAddVectorEq})))(tls, best_histo, accumulated_argb, libc.Int32FromInt32(4)*libc.Int32FromInt32(256))
  29987 	**(**uint32_t)(__ccgo_up(modes + uintptr(tile_y*tiles_per_row+tile_x)*4)) = uint32(ARGB_BLACK1) | best_mode<<libc.Int32FromInt32(8)
  29988 	**(**uint32_t)(__ccgo_up(pred_histos + uintptr(best_mode)*4)) = **(**uint32_t)(__ccgo_up(pred_histos + uintptr(best_mode)*4)) + 1
  29989 }
  29990 
  29991 // C documentation
  29992 //
  29993 //	// Computes the residuals for the different predictors.
  29994 //	// If max_quantization > 1, assumes that near lossless processing will be
  29995 //	// applied, quantizing residuals to multiples of quantization levels up to
  29996 //	// max_quantization (the actual quantization level depends on smoothness near
  29997 //	// the given pixel).
  29998 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) {
  29999 	bp := tls.Alloc(2048)
  30000 	defer tls.Free(2048)
  30001 	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
  30002 	var current_row, histo_argb, max_diffs, super_histo, tmp, upper_row uintptr
  30003 	var subsampling_index uint32_t
  30004 	var _ /* residuals at bp+0 */ [512]uint32_t
  30005 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  30006 	start_x = tile_x << min_bits
  30007 	start_y = tile_y << min_bits
  30008 	tile_size = int32(1) << min_bits
  30009 	max_y = GetMin(tls, tile_size, height-start_y)
  30010 	max_x = GetMin(tls, tile_size, width-start_x)
  30011 	// Whether there exist columns just outside the tile.
  30012 	have_left = libc.BoolInt32(start_x > libc.Int32FromInt32(0))
  30013 	// Position and size of the strip covering the tile and adjacent columns if
  30014 	// they exist.
  30015 	context_start_x = start_x - have_left
  30016 	context_width = max_x + have_left + libc.BoolInt32(max_x < width-start_x)
  30017 	// The width of upper_row and current_row is one pixel larger than image width
  30018 	// to allow the top right pixel to point to the leftmost pixel of the next row
  30019 	// when at the right edge.
  30020 	upper_row = argb_scratch
  30021 	current_row = upper_row + uintptr(width)*4 + uintptr(1)*4
  30022 	max_diffs = current_row + uintptr(width)*4 + libc.UintptrFromInt32(1)*4
  30023 	mode = 0
  30024 	for {
  30025 		if !(mode < kNumPredModes) {
  30026 			break
  30027 		}
  30028 		histo_argb = GetHistoArgb(tls, all_argb, 0, mode)
  30029 		if start_y > 0 {
  30030 			// Read the row above the tile which will become the first upper_row.
  30031 			// Include a pixel to the left if it exists; include a pixel to the right
  30032 			// in all cases (wrapping to the leftmost pixel of the next row if it does
  30033 			// not exist).
  30034 			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)))
  30035 		}
  30036 		relative_y = 0
  30037 		for {
  30038 			if !(relative_y < max_y) {
  30039 				break
  30040 			}
  30041 			y = start_y + relative_y
  30042 			tmp = upper_row
  30043 			upper_row = current_row
  30044 			current_row = tmp
  30045 			// Read current_row. Include a pixel to the left if it exists; include a
  30046 			// pixel to the right in all cases except at the bottom right corner of
  30047 			// the image (wrapping to the leftmost pixel of the next row if it does
  30048 			// not exist in the current row).
  30049 			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)))
  30050 			if max_quantization > int32(1) && y >= int32(1) && y+int32(1) < height {
  30051 				MaxDiffsForRow(tls, context_width, width, argb+uintptr(y*width)*4+uintptr(context_start_x)*4, max_diffs+uintptr(context_start_x), used_subtract_green)
  30052 			}
  30053 			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)
  30054 			relative_x = 0
  30055 			for {
  30056 				if !(relative_x < max_x) {
  30057 					break
  30058 				}
  30059 				UpdateHisto(tls, histo_argb, (**(**[512]uint32_t)(__ccgo_up(bp)))[relative_x])
  30060 				goto _3
  30061 			_3:
  30062 				;
  30063 				relative_x = relative_x + 1
  30064 			}
  30065 			if update_up_to_index > uint32(0) {
  30066 				subsampling_index = uint32(1)
  30067 				for {
  30068 					if !(subsampling_index <= update_up_to_index) {
  30069 						break
  30070 					}
  30071 					super_histo = GetHistoArgb(tls, all_argb, int32(subsampling_index), mode)
  30072 					relative_x = 0
  30073 					for {
  30074 						if !(relative_x < max_x) {
  30075 							break
  30076 						}
  30077 						UpdateHisto(tls, super_histo, (**(**[512]uint32_t)(__ccgo_up(bp)))[relative_x])
  30078 						goto _5
  30079 					_5:
  30080 						;
  30081 						relative_x = relative_x + 1
  30082 					}
  30083 					goto _4
  30084 				_4:
  30085 					;
  30086 					subsampling_index = subsampling_index + 1
  30087 				}
  30088 			}
  30089 			goto _2
  30090 		_2:
  30091 			;
  30092 			relative_y = relative_y + 1
  30093 		}
  30094 		goto _1
  30095 	_1:
  30096 		;
  30097 		mode = mode + 1
  30098 	}
  30099 }
  30100 
  30101 // C documentation
  30102 //
  30103 //	// Converts pixels of the image to residuals with respect to predictions.
  30104 //	// If max_quantization > 1, applies near lossless processing, quantizing
  30105 //	// residuals to multiples of quantization levels up to max_quantization
  30106 //	// (the actual quantization level depends on smoothness near the given pixel).
  30107 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) {
  30108 	var current_max_diffs, current_row, lower_max_diffs, tmp32, tmp8, upper_row uintptr
  30109 	var mode, tiles_per_row, x, x_end, y int32
  30110 	var v1, v2 uint32_t
  30111 	_, _, _, _, _, _, _, _, _, _, _, _, _ = current_max_diffs, current_row, lower_max_diffs, mode, tiles_per_row, tmp32, tmp8, upper_row, x, x_end, y, v1, v2
  30112 	v1 = uint32(bits)
  30113 	v2 = (uint32(width) + uint32(libc.Int32FromInt32(1)<<v1) - uint32(1)) >> v1
  30114 	goto _3
  30115 _3:
  30116 	tiles_per_row = int32(v2)
  30117 	// The width of upper_row and current_row is one pixel larger than image width
  30118 	// to allow the top right pixel to point to the leftmost pixel of the next row
  30119 	// when at the right edge.
  30120 	upper_row = argb_scratch
  30121 	current_row = upper_row + uintptr(width)*4 + uintptr(1)*4
  30122 	current_max_diffs = current_row + uintptr(width)*4 + libc.UintptrFromInt32(1)*4
  30123 	lower_max_diffs = current_max_diffs + uintptr(width)
  30124 	y = 0
  30125 	for {
  30126 		if !(y < height) {
  30127 			break
  30128 		}
  30129 		tmp32 = upper_row
  30130 		upper_row = current_row
  30131 		current_row = tmp32
  30132 		libc.Xmemcpy(tls, current_row, argb+uintptr(y*width)*4, uint64(4)*uint64(width+libc.BoolInt32(y+libc.Int32FromInt32(1) < height)))
  30133 		if low_effort != 0 {
  30134 			PredictBatch(tls, kPredLowEffort, 0, y, width, current_row, upper_row, argb+uintptr(y*width)*4)
  30135 		} else {
  30136 			if max_quantization > int32(1) {
  30137 				// Compute max_diffs for the lower row now, because that needs the
  30138 				// contents of argb for the current row, which we will overwrite with
  30139 				// residuals before proceeding with the next row.
  30140 				tmp8 = current_max_diffs
  30141 				current_max_diffs = lower_max_diffs
  30142 				lower_max_diffs = tmp8
  30143 				if y+int32(2) < height {
  30144 					MaxDiffsForRow(tls, width, width, argb+uintptr((y+int32(1))*width)*4, lower_max_diffs, used_subtract_green)
  30145 				}
  30146 			}
  30147 			x = 0
  30148 			for {
  30149 				if !(x < width) {
  30150 					break
  30151 				}
  30152 				mode = int32(**(**uint32_t)(__ccgo_up(modes + uintptr(y>>bits*tiles_per_row+x>>bits)*4)) >> libc.Int32FromInt32(8) & uint32(0xff))
  30153 				x_end = x + int32(1)<<bits
  30154 				if x_end > width {
  30155 					x_end = width
  30156 				}
  30157 				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)
  30158 				x = x_end
  30159 				goto _5
  30160 			_5:
  30161 			}
  30162 		}
  30163 		goto _4
  30164 	_4:
  30165 		;
  30166 		y = y + 1
  30167 	}
  30168 }
  30169 
  30170 // C documentation
  30171 //
  30172 //	// Checks whether 'image' can be subsampled by finding the biggest power of 2
  30173 //	// squares (defined by 'best_bits') of uniform value it is made out of.
  30174 func VP8LOptimizeSampling(tls *libc.TLS, image uintptr, full_width int32, full_height int32, bits int32, max_bits int32, best_bits_out uintptr) {
  30175 	var best_bits, height, i, is_good, is_good1, new_square_size, old_width, square_size, width, x, y int32
  30176 	var v1, v2, v4, v5 uint32_t
  30177 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = best_bits, height, i, is_good, is_good1, new_square_size, old_width, square_size, width, x, y, v1, v2, v4, v5
  30178 	v1 = uint32(bits)
  30179 	v2 = (uint32(full_width) + uint32(libc.Int32FromInt32(1)<<v1) - uint32(1)) >> v1
  30180 	goto _3
  30181 _3:
  30182 	width = int32(v2)
  30183 	v4 = uint32(bits)
  30184 	v5 = (uint32(full_height) + uint32(libc.Int32FromInt32(1)<<v4) - uint32(1)) >> v4
  30185 	goto _6
  30186 _6:
  30187 	height = int32(v5)
  30188 	best_bits = bits
  30189 	**(**int32)(__ccgo_up(best_bits_out)) = bits
  30190 	// Check rows first.
  30191 	for best_bits < max_bits {
  30192 		new_square_size = int32(1) << (best_bits + int32(1) - bits)
  30193 		is_good = int32(1)
  30194 		square_size = int32(1) << (best_bits - bits)
  30195 		y = 0
  30196 		for {
  30197 			if !(y+square_size < height) {
  30198 				break
  30199 			}
  30200 			// Check the first lines of consecutive line groups.
  30201 			if libc.Xmemcmp(tls, image+uintptr(y*width)*4, image+uintptr((y+square_size)*width)*4, uint64(width)*uint64(4)) != 0 {
  30202 				is_good = 0
  30203 				break
  30204 			}
  30205 			goto _7
  30206 		_7:
  30207 			;
  30208 			y = y + new_square_size
  30209 		}
  30210 		if is_good != 0 {
  30211 			best_bits = best_bits + 1
  30212 		} else {
  30213 			break
  30214 		}
  30215 	}
  30216 	if best_bits == bits {
  30217 		return
  30218 	}
  30219 	// Check columns.
  30220 	for best_bits > bits {
  30221 		is_good1 = int32(1)
  30222 		square_size = int32(1) << (best_bits - bits)
  30223 		y = 0
  30224 		for {
  30225 			if !(is_good1 != 0 && y < height) {
  30226 				break
  30227 			}
  30228 			x = 0
  30229 			for {
  30230 				if !(is_good1 != 0 && x < width) {
  30231 					break
  30232 				}
  30233 				i = x + int32(1)
  30234 				for {
  30235 					if !(i < GetMin(tls, x+square_size, width)) {
  30236 						break
  30237 					}
  30238 					if **(**uint32_t)(__ccgo_up(image + uintptr(y*width+i)*4)) != **(**uint32_t)(__ccgo_up(image + uintptr(y*width+x)*4)) {
  30239 						is_good1 = 0
  30240 						break
  30241 					}
  30242 					goto _10
  30243 				_10:
  30244 					;
  30245 					i = i + 1
  30246 				}
  30247 				goto _9
  30248 			_9:
  30249 				;
  30250 				x = x + square_size
  30251 			}
  30252 			goto _8
  30253 		_8:
  30254 			;
  30255 			y = y + 1
  30256 		}
  30257 		if is_good1 != 0 {
  30258 			break
  30259 		}
  30260 		best_bits = best_bits - 1
  30261 	}
  30262 	if best_bits == bits {
  30263 		return
  30264 	}
  30265 	// Subsample the image.
  30266 	old_width = width
  30267 	square_size = int32(1) << (best_bits - bits)
  30268 	v1 = uint32(best_bits)
  30269 	v2 = (uint32(full_width) + uint32(libc.Int32FromInt32(1)<<v1) - uint32(1)) >> v1
  30270 	goto _13
  30271 _13:
  30272 	width = int32(v2)
  30273 	v1 = uint32(best_bits)
  30274 	v2 = (uint32(full_height) + uint32(libc.Int32FromInt32(1)<<v1) - uint32(1)) >> v1
  30275 	goto _16
  30276 _16:
  30277 	height = int32(v2)
  30278 	y = 0
  30279 	for {
  30280 		if !(y < height) {
  30281 			break
  30282 		}
  30283 		x = 0
  30284 		for {
  30285 			if !(x < width) {
  30286 				break
  30287 			}
  30288 			**(**uint32_t)(__ccgo_up(image + uintptr(y*width+x)*4)) = **(**uint32_t)(__ccgo_up(image + uintptr(square_size*(y*old_width+x))*4))
  30289 			goto _18
  30290 		_18:
  30291 			;
  30292 			x = x + 1
  30293 		}
  30294 		goto _17
  30295 	_17:
  30296 		;
  30297 		y = y + 1
  30298 	}
  30299 	**(**int32)(__ccgo_up(best_bits_out)) = best_bits
  30300 }
  30301 
  30302 // C documentation
  30303 //
  30304 //	// Computes the best predictor image.
  30305 //	// Finds the best predictors per tile. Once done, finds the best predictor image
  30306 //	// sampling.
  30307 //	// best_bits is set to 0 in case of error.
  30308 //	// The following requires some glossary:
  30309 //	// - a tile is a square of side 2^min_bits pixels.
  30310 //	// - a super-tile of a tile is a square of side 2^bits pixels with bits in
  30311 //	// [min_bits+1, max_bits].
  30312 //	// - the max-tile of a tile is the square of 2^max_bits pixels containing it.
  30313 //	//   If this max-tile crosses the border of an image, it is cropped.
  30314 //	// - tile, super-tiles and max_tile are aligned on powers of 2 in the original
  30315 //	//   image.
  30316 //	// - coordinates for tile, super-tile, max-tile are respectively named
  30317 //	//   tile_x, super_tile_x, max_tile_x at their bit scale.
  30318 //	// - in the max-tile, a tile has local coordinates (local_tile_x, local_tile_y).
  30319 //	// The tiles are processed in the following zigzag order to complete the
  30320 //	// super-tiles as soon as possible:
  30321 //	//   1  2|  5  6
  30322 //	//   3  4|  7  8
  30323 //	// --------------
  30324 //	//   9 10| 13 14
  30325 //	//  11 12| 15 16
  30326 //	// When computing the residuals for a tile, the histogram of the above
  30327 //	// super-tile is updated. If this super-tile is finished, its histogram is used
  30328 //	// to update the histogram of the next super-tile and so on up to the max-tile.
  30329 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) {
  30330 	var accumulated, all_accumulated_argb, all_argb, all_pred_histos, raw_data uintptr
  30331 	var best_cost, cost int64_t
  30332 	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
  30333 	var max_tile_size, num_accumulated_rgb, num_argb, num_predictors, percent_start, plane int32
  30334 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  30335 	v1 = uint32(min_bits)
  30336 	v2 = (uint32(width) + uint32(libc.Int32FromInt32(1)<<v1) - uint32(1)) >> v1
  30337 	goto _3
  30338 _3:
  30339 	tiles_per_row = v2
  30340 	v4 = uint32(min_bits)
  30341 	v5 = (uint32(height) + uint32(libc.Int32FromInt32(1)<<v4) - uint32(1)) >> v4
  30342 	goto _6
  30343 _6:
  30344 	tiles_per_col = v5
  30345 	max_subsampling_index = uint32(max_bits - min_bits)
  30346 	// Compute the needed memory size for residual histograms, accumulated
  30347 	// residual histograms and predictor histograms.
  30348 	num_argb = int32((max_subsampling_index + uint32(1)) * uint32(kNumPredModes) * uint32(libc.Int32FromInt32(4)*libc.Int32FromInt32(256)))
  30349 	num_accumulated_rgb = int32((max_subsampling_index + uint32(1)) * uint32(libc.Int32FromInt32(4)*libc.Int32FromInt32(256)))
  30350 	num_predictors = int32((max_subsampling_index + uint32(1)) * uint32(kNumPredModes))
  30351 	raw_data = WebPSafeCalloc(tls, uint64(num_argb+num_accumulated_rgb+num_predictors), uint64(4))
  30352 	all_argb = raw_data
  30353 	all_accumulated_argb = all_argb + uintptr(num_argb)*4
  30354 	all_pred_histos = all_accumulated_argb + uintptr(num_accumulated_rgb)*4
  30355 	max_tile_size = int32(1) << max_subsampling_index // in tile size
  30356 	percent_start = **(**int32)(__ccgo_up(percent))
  30357 	// When using the residuals of a tile for its super-tiles, you can either:
  30358 	// - use each residual to update the histogram of the super-tile, with a cost
  30359 	//   of 4 * (1<<n)^2 increment operations (4 for the number of channels, and
  30360 	//   (1<<n)^2 for the number of pixels in the tile)
  30361 	// - use the histogram of the tile to update the histogram of the super-tile,
  30362 	//   with a cost of HISTO_SIZE (1024)
  30363 	// The first method is therefore faster until n==4. 'update_up_to_index'
  30364 	// defines the maximum subsampling_index for which the residuals should be
  30365 	// individually added to the super-tile histogram.
  30366 	update_up_to_index = uint32(GetMax(tls, GetMin(tls, int32(4), max_bits), min_bits) - min_bits)
  30367 	// Coordinates in the max-tile in tile units.
  30368 	local_tile_x = uint32(0)
  30369 	local_tile_y = uint32(0)
  30370 	max_tile_x = uint32(0)
  30371 	max_tile_y = uint32(0)
  30372 	tile_x = uint32(0)
  30373 	tile_y = uint32(0)
  30374 	**(**int32)(__ccgo_up(best_bits)) = 0
  30375 	**(**uintptr)(__ccgo_up(best_mode)) = libc.UintptrFromInt32(0)
  30376 	if raw_data == libc.UintptrFromInt32(0) {
  30377 		return
  30378 	}
  30379 	for tile_y < tiles_per_col {
  30380 		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)
  30381 		// Update all the super-tiles that are complete.
  30382 		subsampling_index = uint32(0)
  30383 		for int32(1) != 0 {
  30384 			super_tile_x = tile_x >> subsampling_index
  30385 			super_tile_y = tile_y >> subsampling_index
  30386 			v1 = uint32(min_bits) + subsampling_index
  30387 			v2 = (uint32(width) + uint32(libc.Int32FromInt32(1)<<v1) - uint32(1)) >> v1
  30388 			goto _9
  30389 		_9:
  30390 			super_tiles_per_row = v2
  30391 			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)
  30392 			if subsampling_index == max_subsampling_index {
  30393 				break
  30394 			}
  30395 			// Update the following super-tile histogram if it has not been updated
  30396 			// yet.
  30397 			subsampling_index = subsampling_index + 1
  30398 			if subsampling_index > update_up_to_index && subsampling_index <= max_subsampling_index {
  30399 				(*(*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)
  30400 			}
  30401 			// Check whether the super-tile is not complete (if the smallest tile
  30402 			// is not at the end of a line/column or at the beginning of a super-tile
  30403 			// of size (1 << subsampling_index)).
  30404 			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))) {
  30405 				subsampling_index = subsampling_index - 1
  30406 				// subsampling_index now is the index of the last finished super-tile.
  30407 				break
  30408 			}
  30409 		}
  30410 		// Reset all the histograms belonging to finished tiles.
  30411 		libc.Xmemset(tls, all_argb, 0, uint64(uint32(libc.Int32FromInt32(4)*libc.Int32FromInt32(256)*kNumPredModes)*(subsampling_index+uint32(1)))*uint64(4))
  30412 		if subsampling_index == max_subsampling_index {
  30413 			// If a new max-tile is started.
  30414 			if tile_x == tiles_per_row-uint32(1) {
  30415 				max_tile_x = uint32(0)
  30416 				max_tile_y = max_tile_y + 1
  30417 			} else {
  30418 				max_tile_x = max_tile_x + 1
  30419 			}
  30420 			local_tile_x = uint32(0)
  30421 			local_tile_y = uint32(0)
  30422 		} else {
  30423 			// Proceed with the Z traversal.
  30424 			coord_x = local_tile_x >> subsampling_index
  30425 			coord_y = local_tile_y >> subsampling_index
  30426 			if tile_x == tiles_per_row-uint32(1) && coord_x%uint32(2) == uint32(0) {
  30427 				coord_y = coord_y + 1
  30428 			} else {
  30429 				if coord_x%uint32(2) == uint32(0) {
  30430 					coord_x = coord_x + 1
  30431 				} else {
  30432 					// Z traversal.
  30433 					coord_y = coord_y + 1
  30434 					coord_x = coord_x - 1
  30435 				}
  30436 			}
  30437 			local_tile_x = coord_x << subsampling_index
  30438 			local_tile_y = coord_y << subsampling_index
  30439 		}
  30440 		tile_x = max_tile_x*uint32(max_tile_size) + local_tile_x
  30441 		tile_y = max_tile_y*uint32(max_tile_size) + local_tile_y
  30442 		if tile_x == uint32(0) && !(WebPReportProgress(tls, pic, int32(uint32(percent_start)+uint32(percent_range)*tile_y/tiles_per_col), percent) != 0) {
  30443 			WebPSafeFree(tls, raw_data)
  30444 			return
  30445 		}
  30446 	}
  30447 	// Figure out the best sampling.
  30448 	best_cost = int64(libc.Uint64FromUint64(1)<<libc.Int32FromInt32(63) - libc.Uint64FromInt32(1))
  30449 	subsampling_index = uint32(0)
  30450 	for {
  30451 		if !(subsampling_index <= max_subsampling_index) {
  30452 			break
  30453 		}
  30454 		accumulated = GetAccumulatedHisto(tls, all_accumulated_argb, int32(subsampling_index))
  30455 		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))
  30456 		plane = 0
  30457 		for {
  30458 			if !(plane < int32(4)) {
  30459 				break
  30460 			}
  30461 			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)))
  30462 			goto _11
  30463 		_11:
  30464 			;
  30465 			plane = plane + 1
  30466 		}
  30467 		if cost < best_cost {
  30468 			best_cost = cost
  30469 			**(**int32)(__ccgo_up(best_bits)) = int32(uint32(min_bits) + subsampling_index)
  30470 			**(**uintptr)(__ccgo_up(best_mode)) = **(**uintptr)(__ccgo_up(all_modes + uintptr(subsampling_index)*8))
  30471 		}
  30472 		goto _10
  30473 	_10:
  30474 		;
  30475 		subsampling_index = subsampling_index + 1
  30476 	}
  30477 	WebPSafeFree(tls, raw_data)
  30478 	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)
  30479 }
  30480 
  30481 // C documentation
  30482 //
  30483 //	// Finds the best predictor for each tile, and converts the image to residuals
  30484 //	// with respect to predictions. If near_lossless_quality < 100, applies
  30485 //	// near lossless processing, shaving off more bits of residuals for lower
  30486 //	// qualities.
  30487 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) {
  30488 	bp := tls.Alloc(96)
  30489 	defer tls.Free(96)
  30490 	var bits, i, max_quantization, percent_start, tiles_per_col, tiles_per_col1, tiles_per_row, tiles_per_row1, v1 int32
  30491 	var modes_raw uintptr
  30492 	var num_pixels [10]uint32_t
  30493 	var sum_num_pixels, v3, v4, v6, v7 uint32_t
  30494 	var _ /* best_mode at bp+0 */ uintptr
  30495 	var _ /* modes at bp+8 */ [10]uintptr
  30496 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  30497 	percent_start = **(**int32)(__ccgo_up(percent))
  30498 	v1 = int32(5) - near_lossless_quality1/int32(20)
  30499 	goto _2
  30500 _2:
  30501 	max_quantization = int32(1) << v1
  30502 	if low_effort != 0 {
  30503 		v3 = uint32(max_bits)
  30504 		v4 = (uint32(width) + uint32(libc.Int32FromInt32(1)<<v3) - uint32(1)) >> v3
  30505 		goto _5
  30506 	_5:
  30507 		tiles_per_row = int32(v4)
  30508 		v6 = uint32(max_bits)
  30509 		v7 = (uint32(height) + uint32(libc.Int32FromInt32(1)<<v6) - uint32(1)) >> v6
  30510 		goto _8
  30511 	_8:
  30512 		tiles_per_col = int32(v7)
  30513 		i = 0
  30514 		for {
  30515 			if !(i < tiles_per_row*tiles_per_col) {
  30516 				break
  30517 			}
  30518 			**(**uint32_t)(__ccgo_up(image + uintptr(i)*4)) = uint32(ARGB_BLACK1) | uint32(kPredLowEffort<<libc.Int32FromInt32(8))
  30519 			goto _9
  30520 		_9:
  30521 			;
  30522 			i = i + 1
  30523 		}
  30524 		**(**int32)(__ccgo_up(best_bits)) = max_bits
  30525 	} else {
  30526 		sum_num_pixels = 0
  30527 		bits = min_bits
  30528 		for {
  30529 			if !(bits <= max_bits) {
  30530 				break
  30531 			}
  30532 			v3 = uint32(bits)
  30533 			v4 = (uint32(width) + uint32(libc.Int32FromInt32(1)<<v3) - uint32(1)) >> v3
  30534 			goto _13
  30535 		_13:
  30536 			tiles_per_row1 = int32(v4)
  30537 			v6 = uint32(bits)
  30538 			v7 = (uint32(height) + uint32(libc.Int32FromInt32(1)<<v6) - uint32(1)) >> v6
  30539 			goto _16
  30540 		_16:
  30541 			tiles_per_col1 = int32(v7)
  30542 			num_pixels[bits] = uint32(tiles_per_row1 * tiles_per_col1)
  30543 			sum_num_pixels = sum_num_pixels + num_pixels[bits]
  30544 			goto _10
  30545 		_10:
  30546 			;
  30547 			bits = bits + 1
  30548 		}
  30549 		modes_raw = WebPSafeMalloc(tls, uint64(sum_num_pixels), uint64(4))
  30550 		if modes_raw == libc.UintptrFromInt32(0) {
  30551 			return 0
  30552 		}
  30553 		// Have modes point to the right global memory modes_raw.
  30554 		(**(**[10]uintptr)(__ccgo_up(bp + 8)))[min_bits] = modes_raw
  30555 		bits = min_bits + int32(1)
  30556 		for {
  30557 			if !(bits <= max_bits) {
  30558 				break
  30559 			}
  30560 			(**(**[10]uintptr)(__ccgo_up(bp + 8)))[bits] = (**(**[10]uintptr)(__ccgo_up(bp + 8)))[bits-int32(1)] + uintptr(num_pixels[bits-int32(1)])*4
  30561 			goto _17
  30562 		_17:
  30563 			;
  30564 			bits = bits + 1
  30565 		}
  30566 		// Find the best sampling.
  30567 		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)
  30568 		if **(**int32)(__ccgo_up(best_bits)) == 0 {
  30569 			WebPSafeFree(tls, modes_raw)
  30570 			return 0
  30571 		}
  30572 		// Keep the best predictor image.
  30573 		v3 = uint32(**(**int32)(__ccgo_up(best_bits)))
  30574 		v4 = (uint32(width) + uint32(libc.Int32FromInt32(1)<<v3) - uint32(1)) >> v3
  30575 		goto _20
  30576 	_20:
  30577 		v6 = uint32(**(**int32)(__ccgo_up(best_bits)))
  30578 		v7 = (uint32(height) + uint32(libc.Int32FromInt32(1)<<v6) - uint32(1)) >> v6
  30579 		goto _23
  30580 	_23:
  30581 		libc.Xmemcpy(tls, image, **(**uintptr)(__ccgo_up(bp)), uint64(v4*v7)*uint64(4))
  30582 		WebPSafeFree(tls, modes_raw)
  30583 	}
  30584 	CopyImageWithPrediction(tls, width, height, **(**int32)(__ccgo_up(best_bits)), image, argb_scratch, argb, low_effort, max_quantization, exact, used_subtract_green)
  30585 	return WebPReportProgress(tls, pic, percent_start+percent_range, percent)
  30586 }
  30587 
  30588 //------------------------------------------------------------------------------
  30589 // Color transform functions.
  30590 
  30591 func MultipliersClear(tls *libc.TLS, m uintptr) {
  30592 	(*VP8LMultipliers)(unsafe.Pointer(m)).Fgreen_to_red = uint8(0)
  30593 	(*VP8LMultipliers)(unsafe.Pointer(m)).Fgreen_to_blue = uint8(0)
  30594 	(*VP8LMultipliers)(unsafe.Pointer(m)).Fred_to_blue = uint8(0)
  30595 }
  30596 
  30597 func ColorCodeToMultipliers(tls *libc.TLS, color_code uint32_t, m uintptr) {
  30598 	(*VP8LMultipliers)(unsafe.Pointer(m)).Fgreen_to_red = uint8(color_code >> libc.Int32FromInt32(0) & uint32(0xff))
  30599 	(*VP8LMultipliers)(unsafe.Pointer(m)).Fgreen_to_blue = uint8(color_code >> libc.Int32FromInt32(8) & uint32(0xff))
  30600 	(*VP8LMultipliers)(unsafe.Pointer(m)).Fred_to_blue = uint8(color_code >> libc.Int32FromInt32(16) & uint32(0xff))
  30601 }
  30602 
  30603 func MultipliersToColorCode(tls *libc.TLS, m uintptr) (r uint32_t) {
  30604 	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)
  30605 }
  30606 
  30607 func PredictionCostCrossColor(tls *libc.TLS, accumulated uintptr, counts uintptr) (r int64_t) {
  30608 	return int64((*(*func(*libc.TLS, uintptr, uintptr) uint64_t)(unsafe.Pointer(&struct{ uintptr }{VP8LCombinedShannonEntropy})))(tls, counts, accumulated)) + PredictionCostBias(tls, counts, uint64(3), kExpValue)
  30609 }
  30610 
  30611 // Favor low entropy, locally and globally.
  30612 // Favor small absolute values for PredictionCostSpatial
  30613 var kExpValue = uint64(240)
  30614 
  30615 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) {
  30616 	bp := tls.Alloc(1024)
  30617 	defer tls.Free(1024)
  30618 	var cur_diff int64_t
  30619 	var _ /* histo at bp+0 */ [256]uint32_t
  30620 	_ = cur_diff
  30621 	**(**[256]uint32_t)(__ccgo_up(bp)) = [256]uint32_t{}
  30622 	(*(*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)
  30623 	cur_diff = PredictionCostCrossColor(tls, accumulated_red_histo, bp)
  30624 	if int32(uint8(green_to_red)) == int32(prev_x.Fgreen_to_red) {
  30625 		// favor keeping the areas locally similar
  30626 		cur_diff = cur_diff - libc.Int64FromInt64(3)<<libc.Int32FromInt32(LOG_2_PRECISION_BITS)
  30627 	}
  30628 	if int32(uint8(green_to_red)) == int32(prev_y.Fgreen_to_red) {
  30629 		// favor keeping the areas locally similar
  30630 		cur_diff = cur_diff - libc.Int64FromInt64(3)<<libc.Int32FromInt32(LOG_2_PRECISION_BITS)
  30631 	}
  30632 	if green_to_red == 0 {
  30633 		cur_diff = cur_diff - libc.Int64FromInt64(3)<<libc.Int32FromInt32(LOG_2_PRECISION_BITS)
  30634 	}
  30635 	return cur_diff
  30636 }
  30637 
  30638 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) {
  30639 	var best_diff, cur_diff int64_t
  30640 	var delta, green_to_red_best, green_to_red_cur, iter, kMaxIters, offset int32
  30641 	_, _, _, _, _, _, _, _ = best_diff, cur_diff, delta, green_to_red_best, green_to_red_cur, iter, kMaxIters, offset
  30642 	kMaxIters = int32(4) + int32(7)*quality>>int32(8) // in range [4..6]
  30643 	green_to_red_best = 0
  30644 	best_diff = GetPredictionCostCrossColorRed(tls, argb, stride, tile_width, tile_height, prev_x, prev_y, green_to_red_best, accumulated_red_histo)
  30645 	iter = 0
  30646 	for {
  30647 		if !(iter < kMaxIters) {
  30648 			break
  30649 		}
  30650 		// ColorTransformDelta is a 3.5 bit fixed point, so 32 is equal to
  30651 		// one in color computation. Having initial delta here as 1 is sufficient
  30652 		// to explore the range of (-2, 2).
  30653 		delta = int32(32) >> iter
  30654 		// Try a negative and a positive delta from the best known value.
  30655 		offset = -delta
  30656 		for {
  30657 			if !(offset <= delta) {
  30658 				break
  30659 			}
  30660 			green_to_red_cur = offset + green_to_red_best
  30661 			cur_diff = GetPredictionCostCrossColorRed(tls, argb, stride, tile_width, tile_height, prev_x, prev_y, green_to_red_cur, accumulated_red_histo)
  30662 			if cur_diff < best_diff {
  30663 				best_diff = cur_diff
  30664 				green_to_red_best = green_to_red_cur
  30665 			}
  30666 			goto _2
  30667 		_2:
  30668 			;
  30669 			offset = offset + int32(2)*delta
  30670 		}
  30671 		goto _1
  30672 	_1:
  30673 		;
  30674 		iter = iter + 1
  30675 	}
  30676 	(*VP8LMultipliers)(unsafe.Pointer(best_tx)).Fgreen_to_red = uint8(green_to_red_best & libc.Int32FromInt32(0xff))
  30677 }
  30678 
  30679 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) {
  30680 	bp := tls.Alloc(1024)
  30681 	defer tls.Free(1024)
  30682 	var cur_diff int64_t
  30683 	var _ /* histo at bp+0 */ [256]uint32_t
  30684 	_ = cur_diff
  30685 	**(**[256]uint32_t)(__ccgo_up(bp)) = [256]uint32_t{}
  30686 	(*(*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)
  30687 	cur_diff = PredictionCostCrossColor(tls, accumulated_blue_histo, bp)
  30688 	if int32(uint8(green_to_blue)) == int32(prev_x.Fgreen_to_blue) {
  30689 		// favor keeping the areas locally similar
  30690 		cur_diff = cur_diff - libc.Int64FromInt64(3)<<libc.Int32FromInt32(LOG_2_PRECISION_BITS)
  30691 	}
  30692 	if int32(uint8(green_to_blue)) == int32(prev_y.Fgreen_to_blue) {
  30693 		// favor keeping the areas locally similar
  30694 		cur_diff = cur_diff - libc.Int64FromInt64(3)<<libc.Int32FromInt32(LOG_2_PRECISION_BITS)
  30695 	}
  30696 	if int32(uint8(red_to_blue)) == int32(prev_x.Fred_to_blue) {
  30697 		// favor keeping the areas locally similar
  30698 		cur_diff = cur_diff - libc.Int64FromInt64(3)<<libc.Int32FromInt32(LOG_2_PRECISION_BITS)
  30699 	}
  30700 	if int32(uint8(red_to_blue)) == int32(prev_y.Fred_to_blue) {
  30701 		// favor keeping the areas locally similar
  30702 		cur_diff = cur_diff - libc.Int64FromInt64(3)<<libc.Int32FromInt32(LOG_2_PRECISION_BITS)
  30703 	}
  30704 	if green_to_blue == 0 {
  30705 		cur_diff = cur_diff - libc.Int64FromInt64(3)<<libc.Int32FromInt32(LOG_2_PRECISION_BITS)
  30706 	}
  30707 	if red_to_blue == 0 {
  30708 		cur_diff = cur_diff - libc.Int64FromInt64(3)<<libc.Int32FromInt32(LOG_2_PRECISION_BITS)
  30709 	}
  30710 	return cur_diff
  30711 }
  30712 
  30713 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) {
  30714 	bp := tls.Alloc(16)
  30715 	defer tls.Free(16)
  30716 	var axis, delta, green_to_blue_best, green_to_blue_cur, iter, iters, red_to_blue_best, red_to_blue_cur, v1, v2 int32
  30717 	var best_diff, cur_diff int64_t
  30718 	var delta_lut [7]int8_t
  30719 	var _ /* offset at bp+0 */ [8][2]int8_t
  30720 	_, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  30721 	**(**[8][2]int8_t)(__ccgo_up(bp)) = [8][2]int8_t{
  30722 		0: {
  30723 			1: int8(-int32(1)),
  30724 		},
  30725 		1: {
  30726 			1: int8(1),
  30727 		},
  30728 		2: {
  30729 			0: int8(-int32(1)),
  30730 		},
  30731 		3: {
  30732 			0: int8(1),
  30733 		},
  30734 		4: {
  30735 			0: int8(-int32(1)),
  30736 			1: int8(-int32(1)),
  30737 		},
  30738 		5: {
  30739 			0: int8(-int32(1)),
  30740 			1: int8(1),
  30741 		},
  30742 		6: {
  30743 			0: int8(1),
  30744 			1: int8(-int32(1)),
  30745 		},
  30746 		7: {
  30747 			0: int8(1),
  30748 			1: int8(1),
  30749 		},
  30750 	}
  30751 	delta_lut = [7]int8_t{
  30752 		0: int8(16),
  30753 		1: int8(16),
  30754 		2: int8(8),
  30755 		3: int8(4),
  30756 		4: int8(2),
  30757 		5: int8(2),
  30758 		6: int8(2),
  30759 	}
  30760 	if quality < int32(25) {
  30761 		v1 = int32(1)
  30762 	} else {
  30763 		if quality > int32(50) {
  30764 			v2 = int32(7)
  30765 		} else {
  30766 			v2 = int32(4)
  30767 		}
  30768 		v1 = v2
  30769 	}
  30770 	iters = v1
  30771 	green_to_blue_best = 0
  30772 	red_to_blue_best = 0
  30773 	// Initial value at origin:
  30774 	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)
  30775 	iter = 0
  30776 	for {
  30777 		if !(iter < iters) {
  30778 			break
  30779 		}
  30780 		delta = int32(delta_lut[iter])
  30781 		axis = 0
  30782 		for {
  30783 			if !(axis < int32(8)) {
  30784 				break
  30785 			}
  30786 			green_to_blue_cur = int32(**(**int8_t)(__ccgo_up(bp + uintptr(axis)*2)))*delta + green_to_blue_best
  30787 			red_to_blue_cur = int32(**(**int8_t)(__ccgo_up(bp + uintptr(axis)*2 + 1)))*delta + red_to_blue_best
  30788 			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)
  30789 			if cur_diff < best_diff {
  30790 				best_diff = cur_diff
  30791 				green_to_blue_best = green_to_blue_cur
  30792 				red_to_blue_best = red_to_blue_cur
  30793 			}
  30794 			if quality < int32(25) && iter == int32(4) {
  30795 				// Only axis aligned diffs for lower quality.
  30796 				break // next iter.
  30797 			}
  30798 			goto _4
  30799 		_4:
  30800 			;
  30801 			axis = axis + 1
  30802 		}
  30803 		if delta == int32(2) && green_to_blue_best == 0 && red_to_blue_best == 0 {
  30804 			// Further iterations would not help.
  30805 			break // out of iter-loop.
  30806 		}
  30807 		goto _3
  30808 	_3:
  30809 		;
  30810 		iter = iter + 1
  30811 	}
  30812 	(*VP8LMultipliers)(unsafe.Pointer(best_tx)).Fgreen_to_blue = uint8(green_to_blue_best & int32(0xff))
  30813 	(*VP8LMultipliers)(unsafe.Pointer(best_tx)).Fred_to_blue = uint8(red_to_blue_best & int32(0xff))
  30814 }
  30815 
  30816 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) {
  30817 	bp := tls.Alloc(16)
  30818 	defer tls.Free(16)
  30819 	var all_x_max, all_y_max, max_tile_size, tile_height, tile_width, tile_x_offset, tile_y_offset int32
  30820 	var tile_argb uintptr
  30821 	var _ /* best_tx at bp+0 */ VP8LMultipliers
  30822 	_, _, _, _, _, _, _, _ = all_x_max, all_y_max, max_tile_size, tile_argb, tile_height, tile_width, tile_x_offset, tile_y_offset
  30823 	max_tile_size = int32(1) << bits
  30824 	tile_y_offset = tile_y * max_tile_size
  30825 	tile_x_offset = tile_x * max_tile_size
  30826 	all_x_max = GetMin(tls, tile_x_offset+max_tile_size, xsize)
  30827 	all_y_max = GetMin(tls, tile_y_offset+max_tile_size, ysize)
  30828 	tile_width = all_x_max - tile_x_offset
  30829 	tile_height = all_y_max - tile_y_offset
  30830 	tile_argb = argb + uintptr(tile_y_offset*xsize)*4 + uintptr(tile_x_offset)*4
  30831 	MultipliersClear(tls, bp)
  30832 	GetBestGreenToRed(tls, tile_argb, xsize, tile_width, tile_height, prev_x, prev_y, quality, accumulated_red_histo, bp)
  30833 	GetBestGreenRedToBlue(tls, tile_argb, xsize, tile_width, tile_height, prev_x, prev_y, quality, accumulated_blue_histo, bp)
  30834 	return **(**VP8LMultipliers)(__ccgo_up(bp))
  30835 }
  30836 
  30837 func CopyTileWithColorTransform(tls *libc.TLS, xsize int32, ysize int32, tile_x int32, tile_y int32, max_tile_size int32, _color_transform VP8LMultipliers, argb uintptr) {
  30838 	bp := tls.Alloc(16)
  30839 	defer tls.Free(16)
  30840 	*(*VP8LMultipliers)(unsafe.Pointer(bp)) = _color_transform
  30841 	var xscan, yscan, v1 int32
  30842 	_, _, _ = xscan, yscan, v1
  30843 	xscan = GetMin(tls, max_tile_size, xsize-tile_x)
  30844 	yscan = GetMin(tls, max_tile_size, ysize-tile_y)
  30845 	argb = argb + uintptr(tile_y*xsize+tile_x)*4
  30846 	for {
  30847 		v1 = yscan
  30848 		yscan = yscan - 1
  30849 		if !(v1 > 0) {
  30850 			break
  30851 		}
  30852 		(*(*func(*libc.TLS, uintptr, uintptr, int32))(unsafe.Pointer(&struct{ uintptr }{VP8LTransformColor})))(tls, bp, argb, xscan)
  30853 		argb = argb + uintptr(xsize)*4
  30854 	}
  30855 }
  30856 
  30857 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) {
  30858 	bp := tls.Alloc(2064)
  30859 	defer tls.Free(2064)
  30860 	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
  30861 	var pix, v1, v2, v4, v5 uint32_t
  30862 	var _ /* accumulated_blue_histo at bp+1024 */ [256]uint32_t
  30863 	var _ /* accumulated_red_histo at bp+0 */ [256]uint32_t
  30864 	var _ /* prev_x at bp+2049 */ VP8LMultipliers
  30865 	var _ /* prev_y at bp+2052 */ VP8LMultipliers
  30866 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  30867 	max_tile_size = int32(1) << bits
  30868 	v1 = uint32(bits)
  30869 	v2 = (uint32(width) + uint32(libc.Int32FromInt32(1)<<v1) - uint32(1)) >> v1
  30870 	goto _3
  30871 _3:
  30872 	tile_xsize = int32(v2)
  30873 	v4 = uint32(bits)
  30874 	v5 = (uint32(height) + uint32(libc.Int32FromInt32(1)<<v4) - uint32(1)) >> v4
  30875 	goto _6
  30876 _6:
  30877 	tile_ysize = int32(v5)
  30878 	percent_start = **(**int32)(__ccgo_up(percent))
  30879 	**(**[256]uint32_t)(__ccgo_up(bp)) = [256]uint32_t{}
  30880 	**(**[256]uint32_t)(__ccgo_up(bp + 1024)) = [256]uint32_t{}
  30881 	MultipliersClear(tls, bp+2052)
  30882 	MultipliersClear(tls, bp+2049)
  30883 	tile_y = 0
  30884 	for {
  30885 		if !(tile_y < tile_ysize) {
  30886 			break
  30887 		}
  30888 		tile_x = 0
  30889 		for {
  30890 			if !(tile_x < tile_xsize) {
  30891 				break
  30892 			}
  30893 			tile_x_offset = tile_x * max_tile_size
  30894 			tile_y_offset = tile_y * max_tile_size
  30895 			all_x_max = GetMin(tls, tile_x_offset+max_tile_size, width)
  30896 			all_y_max = GetMin(tls, tile_y_offset+max_tile_size, height)
  30897 			offset = tile_y*tile_xsize + tile_x
  30898 			if tile_y != 0 {
  30899 				ColorCodeToMultipliers(tls, **(**uint32_t)(__ccgo_up(image + uintptr(offset-tile_xsize)*4)), bp+2052)
  30900 			}
  30901 			**(**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)
  30902 			**(**uint32_t)(__ccgo_up(image + uintptr(offset)*4)) = MultipliersToColorCode(tls, bp+2049)
  30903 			CopyTileWithColorTransform(tls, width, height, tile_x_offset, tile_y_offset, max_tile_size, **(**VP8LMultipliers)(__ccgo_up(bp + 2049)), argb)
  30904 			// Gather accumulated histogram data.
  30905 			y = tile_y_offset
  30906 			for {
  30907 				if !(y < all_y_max) {
  30908 					break
  30909 				}
  30910 				ix = y*width + tile_x_offset
  30911 				ix_end = ix + all_x_max - tile_x_offset
  30912 				for {
  30913 					if !(ix < ix_end) {
  30914 						break
  30915 					}
  30916 					pix = **(**uint32_t)(__ccgo_up(argb + uintptr(ix)*4))
  30917 					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)) {
  30918 						goto _10 // repeated pixels are handled by backward references
  30919 					}
  30920 					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)) {
  30921 						goto _10 // repeated pixels are handled by backward references
  30922 					}
  30923 					(**(**[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
  30924 					(**(**[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
  30925 					goto _10
  30926 				_10:
  30927 					;
  30928 					ix = ix + 1
  30929 				}
  30930 				goto _9
  30931 			_9:
  30932 				;
  30933 				y = y + 1
  30934 			}
  30935 			goto _8
  30936 		_8:
  30937 			;
  30938 			tile_x = tile_x + 1
  30939 		}
  30940 		if !(WebPReportProgress(tls, pic, percent_start+percent_range*tile_y/tile_ysize, percent) != 0) {
  30941 			return 0
  30942 		}
  30943 		goto _7
  30944 	_7:
  30945 		;
  30946 		tile_y = tile_y + 1
  30947 	}
  30948 	VP8LOptimizeSampling(tls, image, width, height, bits, libc.Int32FromInt32(MIN_TRANSFORM_BITS)+libc.Int32FromInt32(1)<<libc.Int32FromInt32(NUM_TRANSFORM_BITS)-libc.Int32FromInt32(1), best_bits)
  30949 	return int32(1)
  30950 }
  30951 
  30952 const DO_TRELLIS_I16 = 1
  30953 const DO_TRELLIS_I4 = 1
  30954 const DO_TRELLIS_UV = 0
  30955 const FLATNESS_LIMIT_I16 = 0
  30956 const FLATNESS_LIMIT_I4 = 3
  30957 const FLATNESS_LIMIT_UV = 2
  30958 const FLATNESS_PENALTY = 140
  30959 const FSTRENGTH_CUTOFF = 2
  30960 const IsFlat = "IsFlat_C"
  30961 const MAX_ALPHA1 = 100
  30962 const MAX_DELTA = 1
  30963 const MAX_DQ_UV = 6
  30964 const MID_ALPHA = 64
  30965 const MIN_ALPHA = 30
  30966 const MIN_DELTA = 0
  30967 const RD_DISTO_MULT = 256
  30968 const SHARPEN_BITS = 11
  30969 const SNS_TO_DQ = 0.9
  30970 const USE_TDISTO = 1
  30971 
  30972 //------------------------------------------------------------------------------
  30973 
  30974 // Copyright 2011 Google Inc. All Rights Reserved.
  30975 //
  30976 // Use of this source code is governed by a BSD-style license
  30977 // that can be found in the COPYING file in the root of the source
  30978 // tree. An additional intellectual property rights grant can be found
  30979 // in the file PATENTS. All contributing project authors may
  30980 // be found in the AUTHORS file in the root of the source tree.
  30981 // -----------------------------------------------------------------------------
  30982 //
  30983 //   WebP encoder: internal header.
  30984 //
  30985 // Author: Skal (pascal.massimino@gmail.com)
  30986 
  30987 // Copyright 2010 Google Inc. All Rights Reserved.
  30988 //
  30989 // Use of this source code is governed by a BSD-style license
  30990 // that can be found in the COPYING file in the root of the source
  30991 // tree. An additional intellectual property rights grant can be found
  30992 // in the file PATENTS. All contributing project authors may
  30993 // be found in the AUTHORS file in the root of the source tree.
  30994 // -----------------------------------------------------------------------------
  30995 //
  30996 //  Common types + memory wrappers
  30997 //
  30998 // Author: Skal (pascal.massimino@gmail.com)
  30999 
  31000 // power-law modulation. Must be strictly less than 1.
  31001 
  31002 // number of non-zero coeffs below which we consider the block very flat
  31003 // (and apply a penalty to complex predictions)
  31004 
  31005 // #define DEBUG_BLOCK
  31006 
  31007 //------------------------------------------------------------------------------
  31008 
  31009 //------------------------------------------------------------------------------
  31010 
  31011 func clip2(tls *libc.TLS, v int32, m int32, M int32) (r int32) {
  31012 	var v1, v2 int32
  31013 	_, _ = v1, v2
  31014 	if v < m {
  31015 		v1 = m
  31016 	} else {
  31017 		if v > M {
  31018 			v2 = M
  31019 		} else {
  31020 			v2 = v
  31021 		}
  31022 		v1 = v2
  31023 	}
  31024 	return v1
  31025 }
  31026 
  31027 var kZigzag1 = [16]uint8_t{
  31028 	1:  uint8(1),
  31029 	2:  uint8(4),
  31030 	3:  uint8(8),
  31031 	4:  uint8(5),
  31032 	5:  uint8(2),
  31033 	6:  uint8(3),
  31034 	7:  uint8(6),
  31035 	8:  uint8(9),
  31036 	9:  uint8(12),
  31037 	10: uint8(13),
  31038 	11: uint8(10),
  31039 	12: uint8(7),
  31040 	13: uint8(11),
  31041 	14: uint8(14),
  31042 	15: uint8(15),
  31043 }
  31044 
  31045 var kDcTable1 = [128]uint8_t{
  31046 	0:   uint8(4),
  31047 	1:   uint8(5),
  31048 	2:   uint8(6),
  31049 	3:   uint8(7),
  31050 	4:   uint8(8),
  31051 	5:   uint8(9),
  31052 	6:   uint8(10),
  31053 	7:   uint8(10),
  31054 	8:   uint8(11),
  31055 	9:   uint8(12),
  31056 	10:  uint8(13),
  31057 	11:  uint8(14),
  31058 	12:  uint8(15),
  31059 	13:  uint8(16),
  31060 	14:  uint8(17),
  31061 	15:  uint8(17),
  31062 	16:  uint8(18),
  31063 	17:  uint8(19),
  31064 	18:  uint8(20),
  31065 	19:  uint8(20),
  31066 	20:  uint8(21),
  31067 	21:  uint8(21),
  31068 	22:  uint8(22),
  31069 	23:  uint8(22),
  31070 	24:  uint8(23),
  31071 	25:  uint8(23),
  31072 	26:  uint8(24),
  31073 	27:  uint8(25),
  31074 	28:  uint8(25),
  31075 	29:  uint8(26),
  31076 	30:  uint8(27),
  31077 	31:  uint8(28),
  31078 	32:  uint8(29),
  31079 	33:  uint8(30),
  31080 	34:  uint8(31),
  31081 	35:  uint8(32),
  31082 	36:  uint8(33),
  31083 	37:  uint8(34),
  31084 	38:  uint8(35),
  31085 	39:  uint8(36),
  31086 	40:  uint8(37),
  31087 	41:  uint8(37),
  31088 	42:  uint8(38),
  31089 	43:  uint8(39),
  31090 	44:  uint8(40),
  31091 	45:  uint8(41),
  31092 	46:  uint8(42),
  31093 	47:  uint8(43),
  31094 	48:  uint8(44),
  31095 	49:  uint8(45),
  31096 	50:  uint8(46),
  31097 	51:  uint8(46),
  31098 	52:  uint8(47),
  31099 	53:  uint8(48),
  31100 	54:  uint8(49),
  31101 	55:  uint8(50),
  31102 	56:  uint8(51),
  31103 	57:  uint8(52),
  31104 	58:  uint8(53),
  31105 	59:  uint8(54),
  31106 	60:  uint8(55),
  31107 	61:  uint8(56),
  31108 	62:  uint8(57),
  31109 	63:  uint8(58),
  31110 	64:  uint8(59),
  31111 	65:  uint8(60),
  31112 	66:  uint8(61),
  31113 	67:  uint8(62),
  31114 	68:  uint8(63),
  31115 	69:  uint8(64),
  31116 	70:  uint8(65),
  31117 	71:  uint8(66),
  31118 	72:  uint8(67),
  31119 	73:  uint8(68),
  31120 	74:  uint8(69),
  31121 	75:  uint8(70),
  31122 	76:  uint8(71),
  31123 	77:  uint8(72),
  31124 	78:  uint8(73),
  31125 	79:  uint8(74),
  31126 	80:  uint8(75),
  31127 	81:  uint8(76),
  31128 	82:  uint8(76),
  31129 	83:  uint8(77),
  31130 	84:  uint8(78),
  31131 	85:  uint8(79),
  31132 	86:  uint8(80),
  31133 	87:  uint8(81),
  31134 	88:  uint8(82),
  31135 	89:  uint8(83),
  31136 	90:  uint8(84),
  31137 	91:  uint8(85),
  31138 	92:  uint8(86),
  31139 	93:  uint8(87),
  31140 	94:  uint8(88),
  31141 	95:  uint8(89),
  31142 	96:  uint8(91),
  31143 	97:  uint8(93),
  31144 	98:  uint8(95),
  31145 	99:  uint8(96),
  31146 	100: uint8(98),
  31147 	101: uint8(100),
  31148 	102: uint8(101),
  31149 	103: uint8(102),
  31150 	104: uint8(104),
  31151 	105: uint8(106),
  31152 	106: uint8(108),
  31153 	107: uint8(110),
  31154 	108: uint8(112),
  31155 	109: uint8(114),
  31156 	110: uint8(116),
  31157 	111: uint8(118),
  31158 	112: uint8(122),
  31159 	113: uint8(124),
  31160 	114: uint8(126),
  31161 	115: uint8(128),
  31162 	116: uint8(130),
  31163 	117: uint8(132),
  31164 	118: uint8(134),
  31165 	119: uint8(136),
  31166 	120: uint8(138),
  31167 	121: uint8(140),
  31168 	122: uint8(143),
  31169 	123: uint8(145),
  31170 	124: uint8(148),
  31171 	125: uint8(151),
  31172 	126: uint8(154),
  31173 	127: uint8(157),
  31174 }
  31175 
  31176 var kAcTable1 = [128]uint16_t{
  31177 	0:   uint16(4),
  31178 	1:   uint16(5),
  31179 	2:   uint16(6),
  31180 	3:   uint16(7),
  31181 	4:   uint16(8),
  31182 	5:   uint16(9),
  31183 	6:   uint16(10),
  31184 	7:   uint16(11),
  31185 	8:   uint16(12),
  31186 	9:   uint16(13),
  31187 	10:  uint16(14),
  31188 	11:  uint16(15),
  31189 	12:  uint16(16),
  31190 	13:  uint16(17),
  31191 	14:  uint16(18),
  31192 	15:  uint16(19),
  31193 	16:  uint16(20),
  31194 	17:  uint16(21),
  31195 	18:  uint16(22),
  31196 	19:  uint16(23),
  31197 	20:  uint16(24),
  31198 	21:  uint16(25),
  31199 	22:  uint16(26),
  31200 	23:  uint16(27),
  31201 	24:  uint16(28),
  31202 	25:  uint16(29),
  31203 	26:  uint16(30),
  31204 	27:  uint16(31),
  31205 	28:  uint16(32),
  31206 	29:  uint16(33),
  31207 	30:  uint16(34),
  31208 	31:  uint16(35),
  31209 	32:  uint16(36),
  31210 	33:  uint16(37),
  31211 	34:  uint16(38),
  31212 	35:  uint16(39),
  31213 	36:  uint16(40),
  31214 	37:  uint16(41),
  31215 	38:  uint16(42),
  31216 	39:  uint16(43),
  31217 	40:  uint16(44),
  31218 	41:  uint16(45),
  31219 	42:  uint16(46),
  31220 	43:  uint16(47),
  31221 	44:  uint16(48),
  31222 	45:  uint16(49),
  31223 	46:  uint16(50),
  31224 	47:  uint16(51),
  31225 	48:  uint16(52),
  31226 	49:  uint16(53),
  31227 	50:  uint16(54),
  31228 	51:  uint16(55),
  31229 	52:  uint16(56),
  31230 	53:  uint16(57),
  31231 	54:  uint16(58),
  31232 	55:  uint16(60),
  31233 	56:  uint16(62),
  31234 	57:  uint16(64),
  31235 	58:  uint16(66),
  31236 	59:  uint16(68),
  31237 	60:  uint16(70),
  31238 	61:  uint16(72),
  31239 	62:  uint16(74),
  31240 	63:  uint16(76),
  31241 	64:  uint16(78),
  31242 	65:  uint16(80),
  31243 	66:  uint16(82),
  31244 	67:  uint16(84),
  31245 	68:  uint16(86),
  31246 	69:  uint16(88),
  31247 	70:  uint16(90),
  31248 	71:  uint16(92),
  31249 	72:  uint16(94),
  31250 	73:  uint16(96),
  31251 	74:  uint16(98),
  31252 	75:  uint16(100),
  31253 	76:  uint16(102),
  31254 	77:  uint16(104),
  31255 	78:  uint16(106),
  31256 	79:  uint16(108),
  31257 	80:  uint16(110),
  31258 	81:  uint16(112),
  31259 	82:  uint16(114),
  31260 	83:  uint16(116),
  31261 	84:  uint16(119),
  31262 	85:  uint16(122),
  31263 	86:  uint16(125),
  31264 	87:  uint16(128),
  31265 	88:  uint16(131),
  31266 	89:  uint16(134),
  31267 	90:  uint16(137),
  31268 	91:  uint16(140),
  31269 	92:  uint16(143),
  31270 	93:  uint16(146),
  31271 	94:  uint16(149),
  31272 	95:  uint16(152),
  31273 	96:  uint16(155),
  31274 	97:  uint16(158),
  31275 	98:  uint16(161),
  31276 	99:  uint16(164),
  31277 	100: uint16(167),
  31278 	101: uint16(170),
  31279 	102: uint16(173),
  31280 	103: uint16(177),
  31281 	104: uint16(181),
  31282 	105: uint16(185),
  31283 	106: uint16(189),
  31284 	107: uint16(193),
  31285 	108: uint16(197),
  31286 	109: uint16(201),
  31287 	110: uint16(205),
  31288 	111: uint16(209),
  31289 	112: uint16(213),
  31290 	113: uint16(217),
  31291 	114: uint16(221),
  31292 	115: uint16(225),
  31293 	116: uint16(229),
  31294 	117: uint16(234),
  31295 	118: uint16(239),
  31296 	119: uint16(245),
  31297 	120: uint16(249),
  31298 	121: uint16(254),
  31299 	122: uint16(259),
  31300 	123: uint16(264),
  31301 	124: uint16(269),
  31302 	125: uint16(274),
  31303 	126: uint16(279),
  31304 	127: uint16(284),
  31305 }
  31306 
  31307 var kAcTable2 = [128]uint16_t{
  31308 	0:   uint16(8),
  31309 	1:   uint16(8),
  31310 	2:   uint16(9),
  31311 	3:   uint16(10),
  31312 	4:   uint16(12),
  31313 	5:   uint16(13),
  31314 	6:   uint16(15),
  31315 	7:   uint16(17),
  31316 	8:   uint16(18),
  31317 	9:   uint16(20),
  31318 	10:  uint16(21),
  31319 	11:  uint16(23),
  31320 	12:  uint16(24),
  31321 	13:  uint16(26),
  31322 	14:  uint16(27),
  31323 	15:  uint16(29),
  31324 	16:  uint16(31),
  31325 	17:  uint16(32),
  31326 	18:  uint16(34),
  31327 	19:  uint16(35),
  31328 	20:  uint16(37),
  31329 	21:  uint16(38),
  31330 	22:  uint16(40),
  31331 	23:  uint16(41),
  31332 	24:  uint16(43),
  31333 	25:  uint16(44),
  31334 	26:  uint16(46),
  31335 	27:  uint16(48),
  31336 	28:  uint16(49),
  31337 	29:  uint16(51),
  31338 	30:  uint16(52),
  31339 	31:  uint16(54),
  31340 	32:  uint16(55),
  31341 	33:  uint16(57),
  31342 	34:  uint16(58),
  31343 	35:  uint16(60),
  31344 	36:  uint16(62),
  31345 	37:  uint16(63),
  31346 	38:  uint16(65),
  31347 	39:  uint16(66),
  31348 	40:  uint16(68),
  31349 	41:  uint16(69),
  31350 	42:  uint16(71),
  31351 	43:  uint16(72),
  31352 	44:  uint16(74),
  31353 	45:  uint16(75),
  31354 	46:  uint16(77),
  31355 	47:  uint16(79),
  31356 	48:  uint16(80),
  31357 	49:  uint16(82),
  31358 	50:  uint16(83),
  31359 	51:  uint16(85),
  31360 	52:  uint16(86),
  31361 	53:  uint16(88),
  31362 	54:  uint16(89),
  31363 	55:  uint16(93),
  31364 	56:  uint16(96),
  31365 	57:  uint16(99),
  31366 	58:  uint16(102),
  31367 	59:  uint16(105),
  31368 	60:  uint16(108),
  31369 	61:  uint16(111),
  31370 	62:  uint16(114),
  31371 	63:  uint16(117),
  31372 	64:  uint16(120),
  31373 	65:  uint16(124),
  31374 	66:  uint16(127),
  31375 	67:  uint16(130),
  31376 	68:  uint16(133),
  31377 	69:  uint16(136),
  31378 	70:  uint16(139),
  31379 	71:  uint16(142),
  31380 	72:  uint16(145),
  31381 	73:  uint16(148),
  31382 	74:  uint16(151),
  31383 	75:  uint16(155),
  31384 	76:  uint16(158),
  31385 	77:  uint16(161),
  31386 	78:  uint16(164),
  31387 	79:  uint16(167),
  31388 	80:  uint16(170),
  31389 	81:  uint16(173),
  31390 	82:  uint16(176),
  31391 	83:  uint16(179),
  31392 	84:  uint16(184),
  31393 	85:  uint16(189),
  31394 	86:  uint16(193),
  31395 	87:  uint16(198),
  31396 	88:  uint16(203),
  31397 	89:  uint16(207),
  31398 	90:  uint16(212),
  31399 	91:  uint16(217),
  31400 	92:  uint16(221),
  31401 	93:  uint16(226),
  31402 	94:  uint16(230),
  31403 	95:  uint16(235),
  31404 	96:  uint16(240),
  31405 	97:  uint16(244),
  31406 	98:  uint16(249),
  31407 	99:  uint16(254),
  31408 	100: uint16(258),
  31409 	101: uint16(263),
  31410 	102: uint16(268),
  31411 	103: uint16(274),
  31412 	104: uint16(280),
  31413 	105: uint16(286),
  31414 	106: uint16(292),
  31415 	107: uint16(299),
  31416 	108: uint16(305),
  31417 	109: uint16(311),
  31418 	110: uint16(317),
  31419 	111: uint16(323),
  31420 	112: uint16(330),
  31421 	113: uint16(336),
  31422 	114: uint16(342),
  31423 	115: uint16(348),
  31424 	116: uint16(354),
  31425 	117: uint16(362),
  31426 	118: uint16(370),
  31427 	119: uint16(379),
  31428 	120: uint16(385),
  31429 	121: uint16(393),
  31430 	122: uint16(401),
  31431 	123: uint16(409),
  31432 	124: uint16(416),
  31433 	125: uint16(424),
  31434 	126: uint16(432),
  31435 	127: uint16(440),
  31436 }
  31437 
  31438 var kBiasMatrices = [3][2]uint8_t{
  31439 	0: {
  31440 		0: uint8(96),
  31441 		1: uint8(110),
  31442 	},
  31443 	1: {
  31444 		0: uint8(96),
  31445 		1: uint8(108),
  31446 	},
  31447 	2: {
  31448 		0: uint8(110),
  31449 		1: uint8(115),
  31450 	},
  31451 }
  31452 
  31453 // C documentation
  31454 //
  31455 //	// Sharpening by (slightly) raising the hi-frequency coeffs.
  31456 //	// Hack-ish but helpful for mid-bitrate range. Use with care.
  31457 var kFreqSharpening = [16]uint8_t{
  31458 	1:  uint8(30),
  31459 	2:  uint8(60),
  31460 	3:  uint8(90),
  31461 	4:  uint8(30),
  31462 	5:  uint8(60),
  31463 	6:  uint8(90),
  31464 	7:  uint8(90),
  31465 	8:  uint8(60),
  31466 	9:  uint8(90),
  31467 	10: uint8(90),
  31468 	11: uint8(90),
  31469 	12: uint8(90),
  31470 	13: uint8(90),
  31471 	14: uint8(90),
  31472 	15: uint8(90),
  31473 }
  31474 
  31475 //------------------------------------------------------------------------------
  31476 // Initialize quantization parameters in VP8Matrix
  31477 
  31478 // C documentation
  31479 //
  31480 //	// Returns the average quantizer
  31481 func ExpandMatrix(tls *libc.TLS, m uintptr, type1 int32) (r int32) {
  31482 	var bias, i, is_ac_coeff, sum int32
  31483 	_, _, _, _ = bias, i, is_ac_coeff, sum
  31484 	i = 0
  31485 	for {
  31486 		if !(i < int32(2)) {
  31487 			break
  31488 		}
  31489 		is_ac_coeff = libc.BoolInt32(i > libc.Int32FromInt32(0))
  31490 		bias = int32(**(**uint8_t)(__ccgo_up(uintptr(unsafe.Pointer(&kBiasMatrices)) + uintptr(type1)*2 + uintptr(is_ac_coeff))))
  31491 		**(**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))))
  31492 		**(**uint32_t)(__ccgo_up(m + 64 + uintptr(i)*4)) = uint32(bias << (libc.Int32FromInt32(QFIX) - libc.Int32FromInt32(8)))
  31493 		// zthresh is the exact value such that QUANTDIV(coeff, iQ, B) is:
  31494 		//   * zero if coeff <= zthresh
  31495 		//   * non-zero if coeff > zthresh
  31496 		**(**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)))
  31497 		goto _1
  31498 	_1:
  31499 		;
  31500 		i = i + 1
  31501 	}
  31502 	i = int32(2)
  31503 	for {
  31504 		if !(i < int32(16)) {
  31505 			break
  31506 		}
  31507 		**(**uint16_t)(__ccgo_up(m + uintptr(i)*2)) = **(**uint16_t)(__ccgo_up(m + 1*2))
  31508 		**(**uint16_t)(__ccgo_up(m + 32 + uintptr(i)*2)) = **(**uint16_t)(__ccgo_up(m + 32 + 1*2))
  31509 		**(**uint32_t)(__ccgo_up(m + 64 + uintptr(i)*4)) = **(**uint32_t)(__ccgo_up(m + 64 + 1*4))
  31510 		**(**uint32_t)(__ccgo_up(m + 128 + uintptr(i)*4)) = **(**uint32_t)(__ccgo_up(m + 128 + 1*4))
  31511 		goto _2
  31512 	_2:
  31513 		;
  31514 		i = i + 1
  31515 	}
  31516 	sum = 0
  31517 	i = libc.Int32FromInt32(0)
  31518 	for {
  31519 		if !(i < int32(16)) {
  31520 			break
  31521 		}
  31522 		if type1 == 0 { // we only use sharpening for AC luma coeffs
  31523 			**(**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))
  31524 		} else {
  31525 			**(**uint16_t)(__ccgo_up(m + 192 + uintptr(i)*2)) = uint16(0)
  31526 		}
  31527 		sum = sum + int32(**(**uint16_t)(__ccgo_up(m + uintptr(i)*2)))
  31528 		goto _3
  31529 	_3:
  31530 		;
  31531 		i = i + 1
  31532 	}
  31533 	return (sum + int32(8)) >> int32(4)
  31534 }
  31535 
  31536 func CheckLambdaValue(tls *libc.TLS, v uintptr) {
  31537 	if **(**int32)(__ccgo_up(v)) < int32(1) {
  31538 		**(**int32)(__ccgo_up(v)) = int32(1)
  31539 	}
  31540 }
  31541 
  31542 func SetupMatrices(tls *libc.TLS, enc uintptr) {
  31543 	var i, num_segments, q, q_i16, q_i4, q_uv, tlambda_scale, v1 int32
  31544 	var m uintptr
  31545 	_, _, _, _, _, _, _, _, _ = i, m, num_segments, q, q_i16, q_i4, q_uv, tlambda_scale, v1
  31546 	if (*VP8Encoder)(unsafe.Pointer(enc)).Fmethod >= int32(4) {
  31547 		v1 = (*WebPConfig)(unsafe.Pointer((*VP8Encoder)(unsafe.Pointer(enc)).Fconfig)).Fsns_strength
  31548 	} else {
  31549 		v1 = 0
  31550 	}
  31551 	tlambda_scale = v1
  31552 	num_segments = (*VP8Encoder)(unsafe.Pointer(enc)).Fsegment_hdr.Fnum_segments
  31553 	i = 0
  31554 	for {
  31555 		if !(i < num_segments) {
  31556 			break
  31557 		}
  31558 		m = enc + 608 + uintptr(i)*744
  31559 		q = (*VP8SegmentInfo)(unsafe.Pointer(m)).Fquant
  31560 		**(**uint16_t)(__ccgo_up(m)) = uint16(kDcTable1[clip2(tls, q+(*VP8Encoder)(unsafe.Pointer(enc)).Fdq_y1_dc, 0, int32(127))])
  31561 		**(**uint16_t)(__ccgo_up(m + 1*2)) = kAcTable1[clip2(tls, q, 0, int32(127))]
  31562 		**(**uint16_t)(__ccgo_up(m + 224)) = uint16(int32(kDcTable1[clip2(tls, q+(*VP8Encoder)(unsafe.Pointer(enc)).Fdq_y2_dc, 0, int32(127))]) * int32(2))
  31563 		**(**uint16_t)(__ccgo_up(m + 224 + 1*2)) = kAcTable2[clip2(tls, q+(*VP8Encoder)(unsafe.Pointer(enc)).Fdq_y2_ac, 0, int32(127))]
  31564 		**(**uint16_t)(__ccgo_up(m + 448)) = uint16(kDcTable1[clip2(tls, q+(*VP8Encoder)(unsafe.Pointer(enc)).Fdq_uv_dc, 0, int32(117))])
  31565 		**(**uint16_t)(__ccgo_up(m + 448 + 1*2)) = kAcTable1[clip2(tls, q+(*VP8Encoder)(unsafe.Pointer(enc)).Fdq_uv_ac, 0, int32(127))]
  31566 		q_i4 = ExpandMatrix(tls, m, 0)
  31567 		q_i16 = ExpandMatrix(tls, m+224, int32(1))
  31568 		q_uv = ExpandMatrix(tls, m+448, int32(2))
  31569 		(*VP8SegmentInfo)(unsafe.Pointer(m)).Flambda_i4 = int32(3) * q_i4 * q_i4 >> int32(7)
  31570 		(*VP8SegmentInfo)(unsafe.Pointer(m)).Flambda_i16 = int32(3) * q_i16 * q_i16
  31571 		(*VP8SegmentInfo)(unsafe.Pointer(m)).Flambda_uv = int32(3) * q_uv * q_uv >> int32(6)
  31572 		(*VP8SegmentInfo)(unsafe.Pointer(m)).Flambda_mode = int32(1) * q_i4 * q_i4 >> int32(7)
  31573 		(*VP8SegmentInfo)(unsafe.Pointer(m)).Flambda_trellis_i4 = int32(7) * q_i4 * q_i4 >> int32(3)
  31574 		(*VP8SegmentInfo)(unsafe.Pointer(m)).Flambda_trellis_i16 = q_i16 * q_i16 >> int32(2)
  31575 		(*VP8SegmentInfo)(unsafe.Pointer(m)).Flambda_trellis_uv = q_uv * q_uv << int32(1)
  31576 		(*VP8SegmentInfo)(unsafe.Pointer(m)).Ftlambda = tlambda_scale * q_i4 >> int32(5)
  31577 		// none of these constants should be < 1
  31578 		CheckLambdaValue(tls, m+700)
  31579 		CheckLambdaValue(tls, m+696)
  31580 		CheckLambdaValue(tls, m+704)
  31581 		CheckLambdaValue(tls, m+708)
  31582 		CheckLambdaValue(tls, m+724)
  31583 		CheckLambdaValue(tls, m+720)
  31584 		CheckLambdaValue(tls, m+728)
  31585 		CheckLambdaValue(tls, m+716)
  31586 		(*VP8SegmentInfo)(unsafe.Pointer(m)).Fmin_disto = int32(20) * int32(**(**uint16_t)(__ccgo_up(m))) // quantization-aware min disto
  31587 		(*VP8SegmentInfo)(unsafe.Pointer(m)).Fmax_edge = 0
  31588 		(*VP8SegmentInfo)(unsafe.Pointer(m)).Fi4_penalty = int64(int32(1000) * q_i4 * q_i4)
  31589 		goto _2
  31590 	_2:
  31591 		;
  31592 		i = i + 1
  31593 	}
  31594 }
  31595 
  31596 //------------------------------------------------------------------------------
  31597 // Initialize filtering parameters
  31598 
  31599 // Very small filter-strength values have close to no visual effect. So we can
  31600 // save a little decoding-CPU by turning filtering off for these.
  31601 
  31602 func SetupFilterStrength(tls *libc.TLS, enc uintptr) {
  31603 	var base_strength, f, i, level0, qstep, v2, v3 int32
  31604 	var m uintptr
  31605 	_, _, _, _, _, _, _, _ = base_strength, f, i, level0, m, qstep, v2, v3
  31606 	// level0 is in [0..500]. Using '-f 50' as filter_strength is mid-filtering.
  31607 	level0 = int32(5) * (*WebPConfig)(unsafe.Pointer((*VP8Encoder)(unsafe.Pointer(enc)).Fconfig)).Ffilter_strength
  31608 	i = 0
  31609 	for {
  31610 		if !(i < int32(NUM_MB_SEGMENTS)) {
  31611 			break
  31612 		}
  31613 		m = enc + 608 + uintptr(i)*744
  31614 		// We focus on the quantization of AC coeffs.
  31615 		qstep = int32(kAcTable1[clip2(tls, (*VP8SegmentInfo)(unsafe.Pointer(m)).Fquant, 0, int32(127))]) >> int32(2)
  31616 		base_strength = VP8FilterStrengthFromDelta(tls, (*VP8Encoder)(unsafe.Pointer(enc)).Ffilter_hdr.Fsharpness, qstep)
  31617 		// Segments with lower complexity ('beta') will be less filtered.
  31618 		f = base_strength * level0 / (int32(256) + (*VP8SegmentInfo)(unsafe.Pointer(m)).Fbeta)
  31619 		if f < int32(FSTRENGTH_CUTOFF) {
  31620 			v2 = 0
  31621 		} else {
  31622 			if f > int32(63) {
  31623 				v3 = int32(63)
  31624 			} else {
  31625 				v3 = f
  31626 			}
  31627 			v2 = v3
  31628 		}
  31629 		(*VP8SegmentInfo)(unsafe.Pointer(m)).Ffstrength = v2
  31630 		goto _1
  31631 	_1:
  31632 		;
  31633 		i = i + 1
  31634 	}
  31635 	// We record the initial strength (mainly for the case of 1-segment only).
  31636 	(*VP8Encoder)(unsafe.Pointer(enc)).Ffilter_hdr.Flevel = (**(**VP8SegmentInfo)(__ccgo_up(enc + 608))).Ffstrength
  31637 	(*VP8Encoder)(unsafe.Pointer(enc)).Ffilter_hdr.Fsimple = libc.BoolInt32((*WebPConfig)(unsafe.Pointer((*VP8Encoder)(unsafe.Pointer(enc)).Fconfig)).Ffilter_type == 0)
  31638 	(*VP8Encoder)(unsafe.Pointer(enc)).Ffilter_hdr.Fsharpness = (*WebPConfig)(unsafe.Pointer((*VP8Encoder)(unsafe.Pointer(enc)).Fconfig)).Ffilter_sharpness
  31639 }
  31640 
  31641 //------------------------------------------------------------------------------
  31642 
  31643 // Note: if you change the values below, remember that the max range
  31644 // allowed by the syntax for DQ_UV is [-16,16].
  31645 
  31646 // C documentation
  31647 //
  31648 //	// We want to emulate jpeg-like behaviour where the expected "good" quality
  31649 //	// is around q=75. Internally, our "good" middle is around c=50. So we
  31650 //	// map accordingly using linear piece-wise function
  31651 func QualityToCompression(tls *libc.TLS, c float64) (r float64) {
  31652 	var linear_c, v, v1 float64
  31653 	_, _, _ = linear_c, v, v1
  31654 	if c < float64(0.75) {
  31655 		v1 = float64(c * (libc.Float64FromFloat64(2) / libc.Float64FromFloat64(3)))
  31656 	} else {
  31657 		v1 = float64(float64(2)*c) - float64(1)
  31658 	}
  31659 	linear_c = v1
  31660 	// The file size roughly scales as pow(quantizer, 3.). Actually, the
  31661 	// exponent is somewhere between 2.8 and 3.2, but we're mostly interested
  31662 	// in the mid-quant range. So we scale the compressibility inversely to
  31663 	// this power-law: quant ~= compression ^ 1/3. This law holds well for
  31664 	// low quant. Finer modeling for high-quant would make use of kAcTable[]
  31665 	// more explicitly.
  31666 	v = libc.Xpow(tls, linear_c, libc.Float64FromInt32(1)/libc.Float64FromFloat64(3))
  31667 	return v
  31668 }
  31669 
  31670 func QualityToJPEGCompression(tls *libc.TLS, c float64, alpha float64) (r float64) {
  31671 	var amax, amin, exp_max, exp_min, expn, slope, v, v1, v2 float64
  31672 	_, _, _, _, _, _, _, _, _ = amax, amin, exp_max, exp_min, expn, slope, v, v1, v2
  31673 	// We map the complexity 'alpha' and quality setting 'c' to a compression
  31674 	// exponent empirically matched to the compression curve of libjpeg6b.
  31675 	// On average, the WebP output size will be roughly similar to that of a
  31676 	// JPEG file compressed with same quality factor.
  31677 	amin = float64(0.3)
  31678 	amax = float64(0.85)
  31679 	exp_min = float64(0.4)
  31680 	exp_max = float64(0.9)
  31681 	slope = (exp_min - exp_max) / (amax - amin)
  31682 	if alpha > amax {
  31683 		v1 = exp_min
  31684 	} else {
  31685 		if alpha < amin {
  31686 			v2 = exp_max
  31687 		} else {
  31688 			v2 = exp_max + float64(slope*(alpha-amin))
  31689 		}
  31690 		v1 = v2
  31691 	}
  31692 	// Linearly interpolate 'expn' from exp_min to exp_max
  31693 	// in the [amin, amax] range.
  31694 	expn = v1
  31695 	v = libc.Xpow(tls, c, expn)
  31696 	return v
  31697 }
  31698 
  31699 func SegmentsAreEquivalent(tls *libc.TLS, S1 uintptr, S2 uintptr) (r int32) {
  31700 	return libc.BoolInt32((*VP8SegmentInfo)(unsafe.Pointer(S1)).Fquant == (*VP8SegmentInfo)(unsafe.Pointer(S2)).Fquant && (*VP8SegmentInfo)(unsafe.Pointer(S1)).Ffstrength == (*VP8SegmentInfo)(unsafe.Pointer(S2)).Ffstrength)
  31701 }
  31702 
  31703 func SimplifySegments(tls *libc.TLS, enc uintptr) {
  31704 	var S1, S2 uintptr
  31705 	var found, i, num_final_segments, num_segments, s1, s2, v1 int32
  31706 	var map1 [4]int32
  31707 	_, _, _, _, _, _, _, _, _, _ = S1, S2, found, i, map1, num_final_segments, num_segments, s1, s2, v1
  31708 	map1 = [4]int32{
  31709 		1: int32(1),
  31710 		2: int32(2),
  31711 		3: int32(3),
  31712 	}
  31713 	if (*VP8Encoder)(unsafe.Pointer(enc)).Fsegment_hdr.Fnum_segments < int32(NUM_MB_SEGMENTS) {
  31714 		v1 = (*VP8Encoder)(unsafe.Pointer(enc)).Fsegment_hdr.Fnum_segments
  31715 	} else {
  31716 		v1 = int32(NUM_MB_SEGMENTS)
  31717 	}
  31718 	// 'num_segments' is previously validated and <= NUM_MB_SEGMENTS, but an
  31719 	// explicit check is needed to avoid a spurious warning about 'i' exceeding
  31720 	// array bounds of 'dqm' with some compilers (noticed with gcc-4.9).
  31721 	num_segments = v1
  31722 	num_final_segments = int32(1)
  31723 	s1 = int32(1)
  31724 	for {
  31725 		if !(s1 < num_segments) {
  31726 			break
  31727 		} // find similar segments
  31728 		S1 = enc + 608 + uintptr(s1)*744
  31729 		found = 0
  31730 		// check if we already have similar segment
  31731 		s2 = 0
  31732 		for {
  31733 			if !(s2 < num_final_segments) {
  31734 				break
  31735 			}
  31736 			S2 = enc + 608 + uintptr(s2)*744
  31737 			if SegmentsAreEquivalent(tls, S1, S2) != 0 {
  31738 				found = int32(1)
  31739 				break
  31740 			}
  31741 			goto _3
  31742 		_3:
  31743 			;
  31744 			s2 = s2 + 1
  31745 		}
  31746 		map1[s1] = s2
  31747 		if !(found != 0) {
  31748 			if num_final_segments != s1 {
  31749 				**(**VP8SegmentInfo)(__ccgo_up(enc + 608 + uintptr(num_final_segments)*744)) = **(**VP8SegmentInfo)(__ccgo_up(enc + 608 + uintptr(s1)*744))
  31750 			}
  31751 			num_final_segments = num_final_segments + 1
  31752 		}
  31753 		goto _2
  31754 	_2:
  31755 		;
  31756 		s1 = s1 + 1
  31757 	}
  31758 	if num_final_segments < num_segments { // Remap
  31759 		i = (*VP8Encoder)(unsafe.Pointer(enc)).Fmb_w * (*VP8Encoder)(unsafe.Pointer(enc)).Fmb_h
  31760 		for {
  31761 			v1 = i
  31762 			i = i - 1
  31763 			if !(v1 > 0) {
  31764 				break
  31765 			}
  31766 			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)
  31767 		}
  31768 		(*VP8Encoder)(unsafe.Pointer(enc)).Fsegment_hdr.Fnum_segments = num_final_segments
  31769 		// Replicate the trailing segment infos (it's mostly cosmetics)
  31770 		i = num_final_segments
  31771 		for {
  31772 			if !(i < num_segments) {
  31773 				break
  31774 			}
  31775 			**(**VP8SegmentInfo)(__ccgo_up(enc + 608 + uintptr(i)*744)) = **(**VP8SegmentInfo)(__ccgo_up(enc + 608 + uintptr(num_final_segments-int32(1))*744))
  31776 			goto _5
  31777 		_5:
  31778 			;
  31779 			i = i + 1
  31780 		}
  31781 	}
  31782 }
  31783 
  31784 func VP8SetSegmentParams(tls *libc.TLS, enc uintptr, quality float32) {
  31785 	var Q, amp, c, c_base, expn, v1 float64
  31786 	var dq_uv_ac, dq_uv_dc, i, num_segments, q int32
  31787 	_, _, _, _, _, _, _, _, _, _, _ = Q, amp, c, c_base, dq_uv_ac, dq_uv_dc, expn, i, num_segments, q, v1
  31788 	num_segments = (*VP8Encoder)(unsafe.Pointer(enc)).Fsegment_hdr.Fnum_segments
  31789 	amp = float64(float64(SNS_TO_DQ)*float64((*WebPConfig)(unsafe.Pointer((*VP8Encoder)(unsafe.Pointer(enc)).Fconfig)).Fsns_strength)) / float64(100) / float64(128)
  31790 	Q = float64(quality) / float64(100)
  31791 	if (*WebPConfig)(unsafe.Pointer((*VP8Encoder)(unsafe.Pointer(enc)).Fconfig)).Femulate_jpeg_size != 0 {
  31792 		v1 = QualityToJPEGCompression(tls, Q, float64((*VP8Encoder)(unsafe.Pointer(enc)).Falpha)/float64(255))
  31793 	} else {
  31794 		v1 = QualityToCompression(tls, Q)
  31795 	}
  31796 	c_base = v1
  31797 	i = 0
  31798 	for {
  31799 		if !(i < num_segments) {
  31800 			break
  31801 		}
  31802 		// We modulate the base coefficient to accommodate for the quantization
  31803 		// susceptibility and allow denser segments to be quantized more.
  31804 		expn = float64(1) - float64(amp*float64((**(**VP8SegmentInfo)(__ccgo_up(enc + 608 + uintptr(i)*744))).Falpha))
  31805 		c = libc.Xpow(tls, c_base, expn)
  31806 		q = int32(float64(libc.Float64FromFloat64(127) * (libc.Float64FromFloat64(1) - c)))
  31807 		(**(**VP8SegmentInfo)(__ccgo_up(enc + 608 + uintptr(i)*744))).Fquant = clip2(tls, q, 0, int32(127))
  31808 		goto _2
  31809 	_2:
  31810 		;
  31811 		i = i + 1
  31812 	}
  31813 	// purely indicative in the bitstream (except for the 1-segment case)
  31814 	(*VP8Encoder)(unsafe.Pointer(enc)).Fbase_quant = (**(**VP8SegmentInfo)(__ccgo_up(enc + 608))).Fquant
  31815 	// fill-in values for the unused segments (required by the syntax)
  31816 	i = num_segments
  31817 	for {
  31818 		if !(i < int32(NUM_MB_SEGMENTS)) {
  31819 			break
  31820 		}
  31821 		(**(**VP8SegmentInfo)(__ccgo_up(enc + 608 + uintptr(i)*744))).Fquant = (*VP8Encoder)(unsafe.Pointer(enc)).Fbase_quant
  31822 		goto _3
  31823 	_3:
  31824 		;
  31825 		i = i + 1
  31826 	}
  31827 	// uv_alpha is normally spread around ~60. The useful range is
  31828 	// typically ~30 (quite bad) to ~100 (ok to decimate UV more).
  31829 	// We map it to the safe maximal range of MAX/MIN_DQ_UV for dq_uv.
  31830 	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))
  31831 	// we rescale by the user-defined strength of adaptation
  31832 	dq_uv_ac = dq_uv_ac * (*WebPConfig)(unsafe.Pointer((*VP8Encoder)(unsafe.Pointer(enc)).Fconfig)).Fsns_strength / int32(100)
  31833 	// and make it safe.
  31834 	dq_uv_ac = clip2(tls, dq_uv_ac, -int32(4), int32(MAX_DQ_UV))
  31835 	// We also boost the dc-uv-quant a little, based on sns-strength, since
  31836 	// U/V channels are quite more reactive to high quants (flat DC-blocks
  31837 	// tend to appear, and are unpleasant).
  31838 	dq_uv_dc = -int32(4) * (*WebPConfig)(unsafe.Pointer((*VP8Encoder)(unsafe.Pointer(enc)).Fconfig)).Fsns_strength / int32(100)
  31839 	dq_uv_dc = clip2(tls, dq_uv_dc, -int32(15), int32(15)) // 4bit-signed max allowed
  31840 	(*VP8Encoder)(unsafe.Pointer(enc)).Fdq_y1_dc = 0       // TODO(skal): dq-lum
  31841 	(*VP8Encoder)(unsafe.Pointer(enc)).Fdq_y2_dc = 0
  31842 	(*VP8Encoder)(unsafe.Pointer(enc)).Fdq_y2_ac = 0
  31843 	(*VP8Encoder)(unsafe.Pointer(enc)).Fdq_uv_dc = dq_uv_dc
  31844 	(*VP8Encoder)(unsafe.Pointer(enc)).Fdq_uv_ac = dq_uv_ac
  31845 	SetupFilterStrength(tls, enc) // initialize segments' filtering, eventually
  31846 	if num_segments > int32(1) {
  31847 		SimplifySegments(tls, enc)
  31848 	}
  31849 	SetupMatrices(tls, enc) // finalize quantization matrices
  31850 }
  31851 
  31852 // C documentation
  31853 //
  31854 //	// Must be indexed using {B_DC_PRED -> B_HU_PRED} as index
  31855 var VP8I4ModeOffsets = [10]uint16_t{
  31856 	0: uint16(libc.Int32FromInt32(3)*libc.Int32FromInt32(16)*libc.Int32FromInt32(BPS) + libc.Int32FromInt32(0)),
  31857 	1: uint16(libc.Int32FromInt32(3)*libc.Int32FromInt32(16)*libc.Int32FromInt32(BPS) + libc.Int32FromInt32(0) + libc.Int32FromInt32(4)),
  31858 	2: uint16(libc.Int32FromInt32(3)*libc.Int32FromInt32(16)*libc.Int32FromInt32(BPS) + libc.Int32FromInt32(0) + libc.Int32FromInt32(8)),
  31859 	3: uint16(libc.Int32FromInt32(3)*libc.Int32FromInt32(16)*libc.Int32FromInt32(BPS) + libc.Int32FromInt32(0) + libc.Int32FromInt32(12)),
  31860 	4: uint16(libc.Int32FromInt32(3)*libc.Int32FromInt32(16)*libc.Int32FromInt32(BPS) + libc.Int32FromInt32(0) + libc.Int32FromInt32(16)),
  31861 	5: uint16(libc.Int32FromInt32(3)*libc.Int32FromInt32(16)*libc.Int32FromInt32(BPS) + libc.Int32FromInt32(0) + libc.Int32FromInt32(20)),
  31862 	6: uint16(libc.Int32FromInt32(3)*libc.Int32FromInt32(16)*libc.Int32FromInt32(BPS) + libc.Int32FromInt32(0) + libc.Int32FromInt32(24)),
  31863 	7: uint16(libc.Int32FromInt32(3)*libc.Int32FromInt32(16)*libc.Int32FromInt32(BPS) + libc.Int32FromInt32(0) + libc.Int32FromInt32(28)),
  31864 	8: uint16(libc.Int32FromInt32(3)*libc.Int32FromInt32(16)*libc.Int32FromInt32(BPS) + libc.Int32FromInt32(4)*libc.Int32FromInt32(BPS)),
  31865 	9: uint16(libc.Int32FromInt32(3)*libc.Int32FromInt32(16)*libc.Int32FromInt32(BPS) + libc.Int32FromInt32(4)*libc.Int32FromInt32(BPS) + libc.Int32FromInt32(4)),
  31866 }
  31867 
  31868 func VP8MakeLuma16Preds(tls *libc.TLS, it uintptr) {
  31869 	var left, top, v1, v2 uintptr
  31870 	_, _, _, _ = left, top, v1, v2
  31871 	if (*VP8EncIterator)(unsafe.Pointer(it)).Fx != 0 {
  31872 		v1 = (*VP8EncIterator)(unsafe.Pointer(it)).Fy_left
  31873 	} else {
  31874 		v1 = libc.UintptrFromInt32(0)
  31875 	}
  31876 	left = v1
  31877 	if (*VP8EncIterator)(unsafe.Pointer(it)).Fy != 0 {
  31878 		v2 = (*VP8EncIterator)(unsafe.Pointer(it)).Fy_top
  31879 	} else {
  31880 		v2 = libc.UintptrFromInt32(0)
  31881 	}
  31882 	top = v2
  31883 	(*(*func(*libc.TLS, uintptr, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8EncPredLuma16})))(tls, (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_p, left, top)
  31884 }
  31885 
  31886 func VP8MakeChroma8Preds(tls *libc.TLS, it uintptr) {
  31887 	var left, top, v1, v2 uintptr
  31888 	_, _, _, _ = left, top, v1, v2
  31889 	if (*VP8EncIterator)(unsafe.Pointer(it)).Fx != 0 {
  31890 		v1 = (*VP8EncIterator)(unsafe.Pointer(it)).Fu_left
  31891 	} else {
  31892 		v1 = libc.UintptrFromInt32(0)
  31893 	}
  31894 	left = v1
  31895 	if (*VP8EncIterator)(unsafe.Pointer(it)).Fy != 0 {
  31896 		v2 = (*VP8EncIterator)(unsafe.Pointer(it)).Fuv_top
  31897 	} else {
  31898 		v2 = libc.UintptrFromInt32(0)
  31899 	}
  31900 	top = v2
  31901 	(*(*func(*libc.TLS, uintptr, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8EncPredChroma8})))(tls, (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_p, left, top)
  31902 }
  31903 
  31904 // C documentation
  31905 //
  31906 //	// Form all the ten Intra4x4 predictions in the 'yuv_p' cache
  31907 //	// for the 4x4 block it->i4
  31908 func MakeIntra4Preds(tls *libc.TLS, it uintptr) {
  31909 	(*(*func(*libc.TLS, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8EncPredLuma4})))(tls, (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_p, (*VP8EncIterator)(unsafe.Pointer(it)).Fi4_top)
  31910 }
  31911 
  31912 var VP8ScanUV = [8]uint16_t{
  31913 	1: uint16(libc.Int32FromInt32(4) + libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)),
  31914 	2: uint16(libc.Int32FromInt32(0) + libc.Int32FromInt32(4)*libc.Int32FromInt32(BPS)),
  31915 	3: uint16(libc.Int32FromInt32(4) + libc.Int32FromInt32(4)*libc.Int32FromInt32(BPS)),
  31916 	4: uint16(libc.Int32FromInt32(8) + libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)),
  31917 	5: uint16(libc.Int32FromInt32(12) + libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)),
  31918 	6: uint16(libc.Int32FromInt32(8) + libc.Int32FromInt32(4)*libc.Int32FromInt32(BPS)),
  31919 	7: uint16(libc.Int32FromInt32(12) + libc.Int32FromInt32(4)*libc.Int32FromInt32(BPS)),
  31920 }
  31921 
  31922 //------------------------------------------------------------------------------
  31923 // Distortion measurement
  31924 
  31925 var kWeightY = [16]uint16_t{
  31926 	0:  uint16(38),
  31927 	1:  uint16(32),
  31928 	2:  uint16(20),
  31929 	3:  uint16(9),
  31930 	4:  uint16(32),
  31931 	5:  uint16(28),
  31932 	6:  uint16(17),
  31933 	7:  uint16(7),
  31934 	8:  uint16(20),
  31935 	9:  uint16(17),
  31936 	10: uint16(10),
  31937 	11: uint16(4),
  31938 	12: uint16(9),
  31939 	13: uint16(7),
  31940 	14: uint16(4),
  31941 	15: uint16(2),
  31942 }
  31943 
  31944 var kWeightTrellis = [16]uint16_t{
  31945 	0:  uint16(30),
  31946 	1:  uint16(27),
  31947 	2:  uint16(19),
  31948 	3:  uint16(11),
  31949 	4:  uint16(27),
  31950 	5:  uint16(24),
  31951 	6:  uint16(17),
  31952 	7:  uint16(10),
  31953 	8:  uint16(19),
  31954 	9:  uint16(17),
  31955 	10: uint16(12),
  31956 	11: uint16(8),
  31957 	12: uint16(11),
  31958 	13: uint16(10),
  31959 	14: uint16(8),
  31960 	15: uint16(6),
  31961 }
  31962 
  31963 // C documentation
  31964 //
  31965 //	// Init/Copy the common fields in score.
  31966 func InitScore(tls *libc.TLS, rd uintptr) {
  31967 	(*VP8ModeScore)(unsafe.Pointer(rd)).FD = 0
  31968 	(*VP8ModeScore)(unsafe.Pointer(rd)).FSD = 0
  31969 	(*VP8ModeScore)(unsafe.Pointer(rd)).FR = 0
  31970 	(*VP8ModeScore)(unsafe.Pointer(rd)).FH = 0
  31971 	(*VP8ModeScore)(unsafe.Pointer(rd)).Fnz = uint32(0)
  31972 	(*VP8ModeScore)(unsafe.Pointer(rd)).Fscore = libc.Int64FromInt64(0x7fffffffffffff)
  31973 }
  31974 
  31975 func CopyScore(tls *libc.TLS, dst uintptr, src uintptr) {
  31976 	(*VP8ModeScore)(unsafe.Pointer(dst)).FD = (*VP8ModeScore)(unsafe.Pointer(src)).FD
  31977 	(*VP8ModeScore)(unsafe.Pointer(dst)).FSD = (*VP8ModeScore)(unsafe.Pointer(src)).FSD
  31978 	(*VP8ModeScore)(unsafe.Pointer(dst)).FR = (*VP8ModeScore)(unsafe.Pointer(src)).FR
  31979 	(*VP8ModeScore)(unsafe.Pointer(dst)).FH = (*VP8ModeScore)(unsafe.Pointer(src)).FH
  31980 	(*VP8ModeScore)(unsafe.Pointer(dst)).Fnz = (*VP8ModeScore)(unsafe.Pointer(src)).Fnz // note that nz is not accumulated, but just copied.
  31981 	(*VP8ModeScore)(unsafe.Pointer(dst)).Fscore = (*VP8ModeScore)(unsafe.Pointer(src)).Fscore
  31982 }
  31983 
  31984 func AddScore(tls *libc.TLS, dst uintptr, src uintptr) {
  31985 	**(**score_t)(__ccgo_up(dst)) += (*VP8ModeScore)(unsafe.Pointer(src)).FD
  31986 	**(**score_t)(__ccgo_up(dst + 8)) += (*VP8ModeScore)(unsafe.Pointer(src)).FSD
  31987 	**(**score_t)(__ccgo_up(dst + 24)) += (*VP8ModeScore)(unsafe.Pointer(src)).FR
  31988 	**(**score_t)(__ccgo_up(dst + 16)) += (*VP8ModeScore)(unsafe.Pointer(src)).FH
  31989 	**(**uint32_t)(__ccgo_up(dst + 864)) |= (*VP8ModeScore)(unsafe.Pointer(src)).Fnz // here, new nz bits are accumulated.
  31990 	**(**score_t)(__ccgo_up(dst + 32)) += (*VP8ModeScore)(unsafe.Pointer(src)).Fscore
  31991 }
  31992 
  31993 //------------------------------------------------------------------------------
  31994 // Performs trellis-optimized quantization.
  31995 
  31996 // C documentation
  31997 //
  31998 //	// Trellis node
  31999 type Node = struct {
  32000 	Fprev  int8_t
  32001 	Fsign  int8_t
  32002 	Flevel int16_t
  32003 }
  32004 
  32005 // C documentation
  32006 //
  32007 //	// Score state
  32008 type ScoreState = struct {
  32009 	Fscore score_t
  32010 	Fcosts uintptr
  32011 }
  32012 
  32013 // If a coefficient was quantized to a value Q (using a neutral bias),
  32014 // we test all alternate possibilities between [Q-MIN_DELTA, Q+MAX_DELTA]
  32015 // We don't test negative values though.
  32016 
  32017 func SetRDScore(tls *libc.TLS, lambda int32, rd uintptr) {
  32018 	(*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)
  32019 }
  32020 
  32021 func RDScoreTrellis(tls *libc.TLS, lambda int32, rate score_t, distortion score_t) (r score_t) {
  32022 	return rate*int64(lambda) + int64(RD_DISTO_MULT)*distortion
  32023 }
  32024 
  32025 const TYPE_I16_AC = 0
  32026 const TYPE_I16_DC = 1
  32027 const TYPE_CHROMA_A = 2
  32028 const TYPE_I4_AC = 3
  32029 
  32030 func TrellisQuantizeBlock(tls *libc.TLS, enc uintptr, in uintptr, out uintptr, ctx0 int32, coeff_type int32, mtx uintptr, lambda int32) (r int32) {
  32031 	bp := tls.Alloc(192)
  32032 	defer tls.Free(192)
  32033 	var B1, Q, coeff0, iQ1 uint32_t
  32034 	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
  32035 	var base_score, best_cur_score, best_score, cost, cost1, last_pos_cost, last_pos_score, rate, score score_t
  32036 	var best_path [3]int32
  32037 	var costs CostArrayPtr
  32038 	var cur, node, probas, ss_cur, ss_prev, tmp uintptr
  32039 	var v3 uint8_t
  32040 	var _ /* nodes at bp+0 */ [16][2]Node
  32041 	var _ /* score_states at bp+128 */ [2][2]ScoreState
  32042 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  32043 	probas = enc + 3616 + 4 + uintptr(coeff_type)*264
  32044 	costs = enc + 3616 + 18344 + uintptr(coeff_type)*384
  32045 	if coeff_type == int32(TYPE_I16_AC) {
  32046 		v1 = int32(1)
  32047 	} else {
  32048 		v1 = 0
  32049 	}
  32050 	first = v1
  32051 	ss_cur = bp + 128 + uintptr(libc.Int32FromInt32(MIN_DELTA)+libc.Int32FromInt32(MIN_DELTA))*16
  32052 	ss_prev = bp + 128 + 1*32 + uintptr(libc.Int32FromInt32(MIN_DELTA)+libc.Int32FromInt32(MIN_DELTA))*16
  32053 	best_path = [3]int32{
  32054 		0: -int32(1),
  32055 		1: -int32(1),
  32056 		2: -int32(1),
  32057 	}
  32058 	thresh = int32(**(**uint16_t)(__ccgo_up(mtx + 1*2))) * int32(**(**uint16_t)(__ccgo_up(mtx + 1*2))) / int32(4)
  32059 	last_proba = int32(**(**uint8_t)(__ccgo_up(probas + uintptr(VP8EncBands[first])*33 + uintptr(ctx0)*11)))
  32060 	// compute the position of the last interesting coefficient
  32061 	last = first - int32(1)
  32062 	n1 = int32(15)
  32063 	for {
  32064 		if !(n1 >= first) {
  32065 			break
  32066 		}
  32067 		j = int32(kZigzag1[n1])
  32068 		err = int32(**(**int16_t)(__ccgo_up(in + uintptr(j)*2))) * int32(**(**int16_t)(__ccgo_up(in + uintptr(j)*2)))
  32069 		if err > thresh {
  32070 			last = n1
  32071 			break
  32072 		}
  32073 		goto _2
  32074 	_2:
  32075 		;
  32076 		n1 = n1 - 1
  32077 	}
  32078 	// we don't need to go inspect up to n = 16 coeffs. We can just go up
  32079 	// to last + 1 (inclusive) without losing much.
  32080 	if last < int32(15) {
  32081 		last = last + 1
  32082 	}
  32083 	// compute 'skip' score. This is the max score one can do.
  32084 	v3 = uint8(last_proba)
  32085 	if !(0 != 0) {
  32086 		v4 = int32(VP8EntropyCost[v3])
  32087 	} else {
  32088 		v4 = int32(VP8EntropyCost[int32(255)-int32(v3)])
  32089 	}
  32090 	v1 = v4
  32091 	goto _5
  32092 _5:
  32093 	cost = int64(v1)
  32094 	best_score = RDScoreTrellis(tls, lambda, cost, 0)
  32095 	// initialize source node.
  32096 	m = -MIN_DELTA
  32097 	for {
  32098 		if !(m <= int32(MAX_DELTA)) {
  32099 			break
  32100 		}
  32101 		if ctx0 == 0 {
  32102 			v3 = uint8(last_proba)
  32103 			if !(int32(1) != 0) {
  32104 				v6 = int32(VP8EntropyCost[v3])
  32105 			} else {
  32106 				v6 = int32(VP8EntropyCost[int32(255)-int32(v3)])
  32107 			}
  32108 			v4 = v6
  32109 			goto _11
  32110 		_11:
  32111 			v1 = v4
  32112 		} else {
  32113 			v1 = 0
  32114 		}
  32115 		rate = int64(v1)
  32116 		(**(**ScoreState)(__ccgo_up(ss_cur + uintptr(m)*16))).Fscore = RDScoreTrellis(tls, lambda, rate, 0)
  32117 		(**(**ScoreState)(__ccgo_up(ss_cur + uintptr(m)*16))).Fcosts = **(**uintptr)(__ccgo_up(costs + uintptr(first)*24 + uintptr(ctx0)*8))
  32118 		goto _7
  32119 	_7:
  32120 		;
  32121 		m = m + 1
  32122 	}
  32123 	// traverse trellis.
  32124 	n1 = first
  32125 	for {
  32126 		if !(n1 <= last) {
  32127 			break
  32128 		}
  32129 		j1 = int32(kZigzag1[n1])
  32130 		Q = uint32(**(**uint16_t)(__ccgo_up(mtx + uintptr(j1)*2)))
  32131 		iQ1 = uint32(**(**uint16_t)(__ccgo_up(mtx + 32 + uintptr(j1)*2)))
  32132 		B1 = uint32(libc.Int32FromInt32(0x00) << (libc.Int32FromInt32(QFIX) - libc.Int32FromInt32(8))) // neutral bias
  32133 		// note: it's important to take sign of the _original_ coeff,
  32134 		// so we don't have to consider level < 0 afterward.
  32135 		sign = libc.BoolInt32(int32(**(**int16_t)(__ccgo_up(in + uintptr(j1)*2))) < libc.Int32FromInt32(0))
  32136 		if sign != 0 {
  32137 			v1 = -int32(**(**int16_t)(__ccgo_up(in + uintptr(j1)*2)))
  32138 		} else {
  32139 			v1 = int32(**(**int16_t)(__ccgo_up(in + uintptr(j1)*2)))
  32140 		}
  32141 		coeff0 = uint32(v1 + int32(**(**uint16_t)(__ccgo_up(mtx + 192 + uintptr(j1)*2))))
  32142 		v4 = int32((coeff0*iQ1 + B1) >> libc.Int32FromInt32(QFIX))
  32143 		goto _16
  32144 	_16:
  32145 		level0 = v4
  32146 		v6 = int32((coeff0*iQ1 + uint32(libc.Int32FromInt32(0x80)<<(libc.Int32FromInt32(QFIX)-libc.Int32FromInt32(8)))) >> libc.Int32FromInt32(QFIX))
  32147 		goto _18
  32148 	_18:
  32149 		thresh_level = v6
  32150 		if thresh_level > int32(MAX_LEVEL) {
  32151 			thresh_level = int32(MAX_LEVEL)
  32152 		}
  32153 		if level0 > int32(MAX_LEVEL) {
  32154 			level0 = int32(MAX_LEVEL)
  32155 		}
  32156 		// Swap current and previous score states
  32157 		tmp = ss_cur
  32158 		ss_cur = ss_prev
  32159 		ss_prev = tmp
  32160 		// test all alternate level values around level0.
  32161 		m = -MIN_DELTA
  32162 		for {
  32163 			if !(m <= int32(MAX_DELTA)) {
  32164 				break
  32165 			}
  32166 			cur = bp + uintptr(n1)*8 + uintptr(m+MIN_DELTA)*4
  32167 			level1 = level0 + m
  32168 			if level1 > int32(2) {
  32169 				v1 = int32(2)
  32170 			} else {
  32171 				v1 = level1
  32172 			}
  32173 			ctx = v1
  32174 			band = int32(VP8EncBands[n1+int32(1)])
  32175 			(**(**ScoreState)(__ccgo_up(ss_cur + uintptr(m)*16))).Fcosts = **(**uintptr)(__ccgo_up(costs + uintptr(n1+int32(1))*24 + uintptr(ctx)*8))
  32176 			if level1 < 0 || level1 > thresh_level {
  32177 				(**(**ScoreState)(__ccgo_up(ss_cur + uintptr(m)*16))).Fscore = libc.Int64FromInt64(0x7fffffffffffff)
  32178 				// Node is dead.
  32179 				goto _19
  32180 			}
  32181 			// Compute delta_error = how much coding this level will
  32182 			// subtract to max_error as distortion.
  32183 			// Here, distortion = sum of (|coeff_i| - level_i * Q_i)^2
  32184 			new_error = int32(coeff0 - uint32(level1)*Q)
  32185 			delta_error = int32(uint32(kWeightTrellis[j1]) * (uint32(new_error*new_error) - coeff0*coeff0))
  32186 			base_score = RDScoreTrellis(tls, lambda, 0, int64(delta_error))
  32187 			// Inspect all possible non-dead predecessors. Retain only the best one.
  32188 			// The base_score is added to all scores so it is only added for the final
  32189 			// value after the loop.
  32190 			v1 = level1
  32191 			if v1 > int32(MAX_VARIABLE_LEVEL) {
  32192 				v6 = int32(MAX_VARIABLE_LEVEL)
  32193 			} else {
  32194 				v6 = v1
  32195 			}
  32196 			v4 = int32(VP8LevelFixedCosts[v1]) + int32(**(**uint16_t)(__ccgo_up((**(**ScoreState)(__ccgo_up(ss_prev + uintptr(-libc.Int32FromInt32(MIN_DELTA))*16))).Fcosts + uintptr(v6)*2)))
  32197 			goto _23
  32198 		_23:
  32199 			cost1 = int64(v4)
  32200 			best_cur_score = (**(**ScoreState)(__ccgo_up(ss_prev + uintptr(-libc.Int32FromInt32(MIN_DELTA))*16))).Fscore + RDScoreTrellis(tls, lambda, cost1, 0)
  32201 			best_prev = -MIN_DELTA
  32202 			p = -libc.Int32FromInt32(MIN_DELTA) + libc.Int32FromInt32(1)
  32203 			for {
  32204 				if !(p <= int32(MAX_DELTA)) {
  32205 					break
  32206 				}
  32207 				// Dead nodes (with ss_prev[p].score >= MAX_COST) are automatically
  32208 				// eliminated since their score can't be better than the current best.
  32209 				v1 = level1
  32210 				if v1 > int32(MAX_VARIABLE_LEVEL) {
  32211 					v6 = int32(MAX_VARIABLE_LEVEL)
  32212 				} else {
  32213 					v6 = v1
  32214 				}
  32215 				v4 = int32(VP8LevelFixedCosts[v1]) + int32(**(**uint16_t)(__ccgo_up((**(**ScoreState)(__ccgo_up(ss_prev + uintptr(p)*16))).Fcosts + uintptr(v6)*2)))
  32216 				goto _28
  32217 			_28:
  32218 				cost1 = int64(v4)
  32219 				// Examine node assuming it's a non-terminal one.
  32220 				score = (**(**ScoreState)(__ccgo_up(ss_prev + uintptr(p)*16))).Fscore + RDScoreTrellis(tls, lambda, cost1, 0)
  32221 				if score < best_cur_score {
  32222 					best_cur_score = score
  32223 					best_prev = p
  32224 				}
  32225 				goto _25
  32226 			_25:
  32227 				;
  32228 				p = p + 1
  32229 			}
  32230 			best_cur_score = best_cur_score + base_score
  32231 			// Store best finding in current node.
  32232 			(*Node)(unsafe.Pointer(cur)).Fsign = int8(sign)
  32233 			(*Node)(unsafe.Pointer(cur)).Flevel = int16(level1)
  32234 			(*Node)(unsafe.Pointer(cur)).Fprev = int8(best_prev)
  32235 			(**(**ScoreState)(__ccgo_up(ss_cur + uintptr(m)*16))).Fscore = best_cur_score
  32236 			// Now, record best terminal node (and thus best entry in the graph).
  32237 			if level1 != 0 && best_cur_score < best_score {
  32238 				if n1 < int32(15) {
  32239 					v3 = **(**uint8_t)(__ccgo_up(probas + uintptr(band)*33 + uintptr(ctx)*11))
  32240 					if !(0 != 0) {
  32241 						v6 = int32(VP8EntropyCost[v3])
  32242 					} else {
  32243 						v6 = int32(VP8EntropyCost[int32(255)-int32(v3)])
  32244 					}
  32245 					v4 = v6
  32246 					goto _33
  32247 				_33:
  32248 					v1 = v4
  32249 				} else {
  32250 					v1 = 0
  32251 				}
  32252 				last_pos_cost = int64(v1)
  32253 				last_pos_score = RDScoreTrellis(tls, lambda, last_pos_cost, 0)
  32254 				score = best_cur_score + last_pos_score
  32255 				if score < best_score {
  32256 					best_score = score
  32257 					best_path[0] = n1               // best eob position
  32258 					best_path[int32(1)] = m         // best node index
  32259 					best_path[int32(2)] = best_prev // best predecessor
  32260 				}
  32261 			}
  32262 			goto _19
  32263 		_19:
  32264 			;
  32265 			m = m + 1
  32266 		}
  32267 		goto _13
  32268 	_13:
  32269 		;
  32270 		n1 = n1 + 1
  32271 	}
  32272 	// Fresh start
  32273 	// Beware! We must preserve in[0]/out[0] value for TYPE_I16_AC case.
  32274 	if coeff_type == int32(TYPE_I16_AC) {
  32275 		libc.Xmemset(tls, in+uintptr(1)*2, 0, libc.Uint64FromInt32(15)*libc.Uint64FromInt64(2))
  32276 		libc.Xmemset(tls, out+uintptr(1)*2, 0, libc.Uint64FromInt32(15)*libc.Uint64FromInt64(2))
  32277 	} else {
  32278 		libc.Xmemset(tls, in, 0, libc.Uint64FromInt32(16)*libc.Uint64FromInt64(2))
  32279 		libc.Xmemset(tls, out, 0, libc.Uint64FromInt32(16)*libc.Uint64FromInt64(2))
  32280 	}
  32281 	if best_path[0] == -int32(1) {
  32282 		return 0 // skip!
  32283 	}
  32284 	// Unwind the best path.
  32285 	// Note: best-prev on terminal node is not necessarily equal to the
  32286 	// best_prev for non-terminal. So we patch best_path[2] in.
  32287 	nz = 0
  32288 	best_node = best_path[int32(1)]
  32289 	n1 = best_path[0]
  32290 	(**(**Node)(__ccgo_up(bp + uintptr(n1)*8 + uintptr(best_node+MIN_DELTA)*4))).Fprev = int8(best_path[int32(2)]) // force best-prev for terminal
  32291 	for {
  32292 		if !(n1 >= first) {
  32293 			break
  32294 		}
  32295 		node = bp + uintptr(n1)*8 + uintptr(best_node+MIN_DELTA)*4
  32296 		j2 = int32(kZigzag1[n1])
  32297 		if (*Node)(unsafe.Pointer(node)).Fsign != 0 {
  32298 			v1 = -int32((*Node)(unsafe.Pointer(node)).Flevel)
  32299 		} else {
  32300 			v1 = int32((*Node)(unsafe.Pointer(node)).Flevel)
  32301 		}
  32302 		**(**int16_t)(__ccgo_up(out + uintptr(n1)*2)) = int16(v1)
  32303 		nz = nz | int32((*Node)(unsafe.Pointer(node)).Flevel)
  32304 		**(**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))))
  32305 		best_node = int32((*Node)(unsafe.Pointer(node)).Fprev)
  32306 		goto _35
  32307 	_35:
  32308 		;
  32309 		n1 = n1 - 1
  32310 	}
  32311 	return libc.BoolInt32(nz != 0)
  32312 	return r
  32313 }
  32314 
  32315 //------------------------------------------------------------------------------
  32316 // Performs: difference, transform, quantize, back-transform, add
  32317 // all at once. Output is the reconstructed block in *yuv_out, and the
  32318 // quantized levels in *levels.
  32319 
  32320 func ReconstructIntra16(tls *libc.TLS, it uintptr, rd uintptr, yuv_out uintptr, mode int32) (r int32) {
  32321 	bp := tls.Alloc(544)
  32322 	defer tls.Free(544)
  32323 	var ctx, n, non_zero, nz, x, y, v4 int32
  32324 	var dqm, enc, ref, src uintptr
  32325 	var v6 int16_t
  32326 	var _ /* dc_tmp at bp+512 */ [16]int16_t
  32327 	var _ /* tmp at bp+0 */ [16][16]int16_t
  32328 	_, _, _, _, _, _, _, _, _, _, _, _ = ctx, dqm, enc, n, non_zero, nz, ref, src, x, y, v4, v6
  32329 	enc = (*VP8EncIterator)(unsafe.Pointer(it)).Fenc
  32330 	ref = (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_p + uintptr(VP8I16ModeOffsets[mode])
  32331 	src = (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_in + uintptr(libc.Int32FromInt32(Y_OFF_ENC))
  32332 	dqm = enc + 608 + uintptr(int32(uint32(*(*uint8)(unsafe.Pointer((*VP8EncIterator)(unsafe.Pointer(it)).Fmb + 0))&0x60>>5)))*744
  32333 	nz = 0
  32334 	n = 0
  32335 	for {
  32336 		if !(n < int32(16)) {
  32337 			break
  32338 		}
  32339 		(*(*func(*libc.TLS, uintptr, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8FTransform2})))(tls, src+uintptr(VP8Scan[n]), ref+uintptr(VP8Scan[n]), bp+uintptr(n)*32)
  32340 		goto _1
  32341 	_1:
  32342 		;
  32343 		n = n + int32(2)
  32344 	}
  32345 	(*(*func(*libc.TLS, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8FTransformWHT})))(tls, bp, bp+512)
  32346 	nz = nz | (*(*func(*libc.TLS, uintptr, uintptr, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{VP8EncQuantizeBlockWHT})))(tls, bp+512, rd+40, dqm+224)<<int32(24)
  32347 	if libc.Bool(int32(DO_TRELLIS_I16) != 0) && (*VP8EncIterator)(unsafe.Pointer(it)).Fdo_trellis != 0 {
  32348 		VP8IteratorNzToBytes(tls, it)
  32349 		y = 0
  32350 		n = libc.Int32FromInt32(0)
  32351 		for {
  32352 			if !(y < int32(4)) {
  32353 				break
  32354 			}
  32355 			x = 0
  32356 			for {
  32357 				if !(x < int32(4)) {
  32358 					break
  32359 				}
  32360 				ctx = **(**int32)(__ccgo_up(it + 132 + uintptr(x)*4)) + **(**int32)(__ccgo_up(it + 168 + uintptr(y)*4))
  32361 				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)
  32362 				v4 = non_zero
  32363 				**(**int32)(__ccgo_up(it + 168 + uintptr(y)*4)) = v4
  32364 				**(**int32)(__ccgo_up(it + 132 + uintptr(x)*4)) = v4
  32365 				**(**int16_t)(__ccgo_up(rd + 72 + uintptr(n)*32)) = 0
  32366 				nz = nz | non_zero<<n
  32367 				goto _3
  32368 			_3:
  32369 				;
  32370 				x = x + 1
  32371 				n = n + 1
  32372 			}
  32373 			goto _2
  32374 		_2:
  32375 			;
  32376 			y = y + 1
  32377 		}
  32378 	} else {
  32379 		n = 0
  32380 		for {
  32381 			if !(n < int32(16)) {
  32382 				break
  32383 			}
  32384 			// Zero-out the first coeff, so that: a) nz is correct below, and
  32385 			// b) finding 'last' non-zero coeffs in SetResidualCoeffs() is simplified.
  32386 			v6 = libc.Int16FromInt32(0)
  32387 			**(**int16_t)(__ccgo_up(bp + uintptr(n+int32(1))*32)) = v6
  32388 			**(**int16_t)(__ccgo_up(bp + uintptr(n)*32)) = v6
  32389 			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
  32390 			goto _5
  32391 		_5:
  32392 			;
  32393 			n = n + int32(2)
  32394 		}
  32395 	}
  32396 	// Transform back
  32397 	(*(*func(*libc.TLS, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8TransformWHT})))(tls, bp+512, bp)
  32398 	n = 0
  32399 	for {
  32400 		if !(n < int32(16)) {
  32401 			break
  32402 		}
  32403 		(*(*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))
  32404 		goto _7
  32405 	_7:
  32406 		;
  32407 		n = n + int32(2)
  32408 	}
  32409 	return nz
  32410 }
  32411 
  32412 func ReconstructIntra4(tls *libc.TLS, it uintptr, levels uintptr, src uintptr, yuv_out uintptr, mode int32) (r int32) {
  32413 	bp := tls.Alloc(32)
  32414 	defer tls.Free(32)
  32415 	var ctx, nz, x, y int32
  32416 	var dqm, enc, ref uintptr
  32417 	var _ /* tmp at bp+0 */ [16]int16_t
  32418 	_, _, _, _, _, _, _ = ctx, dqm, enc, nz, ref, x, y
  32419 	enc = (*VP8EncIterator)(unsafe.Pointer(it)).Fenc
  32420 	ref = (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_p + uintptr(VP8I4ModeOffsets[mode])
  32421 	dqm = enc + 608 + uintptr(int32(uint32(*(*uint8)(unsafe.Pointer((*VP8EncIterator)(unsafe.Pointer(it)).Fmb + 0))&0x60>>5)))*744
  32422 	nz = 0
  32423 	(*(*func(*libc.TLS, uintptr, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8FTransform})))(tls, src, ref, bp)
  32424 	if libc.Bool(int32(DO_TRELLIS_I4) != 0) && (*VP8EncIterator)(unsafe.Pointer(it)).Fdo_trellis != 0 {
  32425 		x = (*VP8EncIterator)(unsafe.Pointer(it)).Fi4 & int32(3)
  32426 		y = (*VP8EncIterator)(unsafe.Pointer(it)).Fi4 >> int32(2)
  32427 		ctx = **(**int32)(__ccgo_up(it + 132 + uintptr(x)*4)) + **(**int32)(__ccgo_up(it + 168 + uintptr(y)*4))
  32428 		nz = TrellisQuantizeBlock(tls, enc, bp, levels, ctx, int32(TYPE_I4_AC), dqm, (*VP8SegmentInfo)(unsafe.Pointer(dqm)).Flambda_trellis_i4)
  32429 	} else {
  32430 		nz = (*(*func(*libc.TLS, uintptr, uintptr, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{VP8EncQuantizeBlock})))(tls, bp, levels, dqm)
  32431 	}
  32432 	(*(*func(*libc.TLS, uintptr, uintptr, uintptr, int32))(unsafe.Pointer(&struct{ uintptr }{VP8ITransform})))(tls, ref, bp, yuv_out, 0)
  32433 	return nz
  32434 }
  32435 
  32436 //------------------------------------------------------------------------------
  32437 // DC-error diffusion
  32438 
  32439 // Diffusion weights. We under-correct a bit (15/16th of the error is actually
  32440 // diffused) to avoid 'rainbow' chessboard pattern of blocks at q~=0.
  32441 
  32442 // C documentation
  32443 //
  32444 //	// Quantize as usual, but also compute and return the quantization error.
  32445 //	// Error is already divided by DSHIFT.
  32446 func QuantizeSingle(tls *libc.TLS, v uintptr, mtx uintptr) (r int32) {
  32447 	var V, err, qV, sign, v1, v3 int32
  32448 	_, _, _, _, _, _ = V, err, qV, sign, v1, v3
  32449 	V = int32(**(**int16_t)(__ccgo_up(v)))
  32450 	sign = libc.BoolInt32(V < libc.Int32FromInt32(0))
  32451 	if sign != 0 {
  32452 		V = -V
  32453 	}
  32454 	if V > int32(**(**uint32_t)(__ccgo_up(mtx + 128))) {
  32455 		v1 = int32((uint32(V)*uint32(**(**uint16_t)(__ccgo_up(mtx + 32))) + **(**uint32_t)(__ccgo_up(mtx + 64))) >> libc.Int32FromInt32(QFIX))
  32456 		goto _2
  32457 	_2:
  32458 		qV = v1 * int32(**(**uint16_t)(__ccgo_up(mtx)))
  32459 		err = V - qV
  32460 		if sign != 0 {
  32461 			v3 = -qV
  32462 		} else {
  32463 			v3 = qV
  32464 		}
  32465 		**(**int16_t)(__ccgo_up(v)) = int16(v3)
  32466 		if sign != 0 {
  32467 			v1 = -err
  32468 		} else {
  32469 			v1 = err
  32470 		}
  32471 		return v1 >> int32(1)
  32472 	}
  32473 	**(**int16_t)(__ccgo_up(v)) = 0
  32474 	if sign != 0 {
  32475 		v1 = -V
  32476 	} else {
  32477 		v1 = V
  32478 	}
  32479 	return v1 >> int32(1)
  32480 }
  32481 
  32482 func CorrectDCValues(tls *libc.TLS, it uintptr, mtx uintptr, tmp uintptr, rd uintptr) {
  32483 	var c, left, top, v2 uintptr
  32484 	var ch, err0, err1, err2, err3 int32
  32485 	_, _, _, _, _, _, _, _, _ = c, ch, err0, err1, err2, err3, left, top, v2
  32486 	ch = 0
  32487 	for {
  32488 		if !(ch <= int32(1)) {
  32489 			break
  32490 		}
  32491 		top = (*VP8EncIterator)(unsafe.Pointer(it)).Ftop_derr + uintptr((*VP8EncIterator)(unsafe.Pointer(it)).Fx)*4 + uintptr(ch)*2
  32492 		left = it + 344 + uintptr(ch)*2
  32493 		c = tmp + uintptr(ch*int32(4))*32
  32494 		v2 = c
  32495 		*(*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)))
  32496 		err0 = QuantizeSingle(tls, c, mtx)
  32497 		v2 = c + 1*32
  32498 		*(*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)))
  32499 		err1 = QuantizeSingle(tls, c+1*32, mtx)
  32500 		v2 = c + 2*32
  32501 		*(*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)))
  32502 		err2 = QuantizeSingle(tls, c+2*32, mtx)
  32503 		v2 = c + 3*32
  32504 		*(*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)))
  32505 		err3 = QuantizeSingle(tls, c+3*32, mtx)
  32506 		// error 'err' is bounded by mtx->q[0] which is 132 at max. Hence
  32507 		// err >> DSCALE will fit in an int8_t type if DSCALE>=1.
  32508 		**(**int8_t)(__ccgo_up(rd + 868 + uintptr(ch)*3)) = int8(err1)
  32509 		**(**int8_t)(__ccgo_up(rd + 868 + uintptr(ch)*3 + 1)) = int8(err2)
  32510 		**(**int8_t)(__ccgo_up(rd + 868 + uintptr(ch)*3 + 2)) = int8(err3)
  32511 		goto _1
  32512 	_1:
  32513 		;
  32514 		ch = ch + 1
  32515 	}
  32516 }
  32517 
  32518 func StoreDiffusionErrors(tls *libc.TLS, it uintptr, rd uintptr) {
  32519 	var ch int32
  32520 	var left, top uintptr
  32521 	_, _, _ = ch, left, top
  32522 	ch = 0
  32523 	for {
  32524 		if !(ch <= int32(1)) {
  32525 			break
  32526 		}
  32527 		top = (*VP8EncIterator)(unsafe.Pointer(it)).Ftop_derr + uintptr((*VP8EncIterator)(unsafe.Pointer(it)).Fx)*4 + uintptr(ch)*2
  32528 		left = it + 344 + uintptr(ch)*2
  32529 		**(**int8_t)(__ccgo_up(left)) = **(**int8_t)(__ccgo_up(rd + 868 + uintptr(ch)*3))                                                                // restore err1
  32530 		**(**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
  32531 		**(**int8_t)(__ccgo_up(top)) = **(**int8_t)(__ccgo_up(rd + 868 + uintptr(ch)*3 + 1))                                                             //     ... err2
  32532 		**(**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.
  32533 		goto _1
  32534 	_1:
  32535 		;
  32536 		ch = ch + 1
  32537 	}
  32538 }
  32539 
  32540 //------------------------------------------------------------------------------
  32541 
  32542 func ReconstructUV(tls *libc.TLS, it uintptr, rd uintptr, yuv_out uintptr, mode int32) (r int32) {
  32543 	bp := tls.Alloc(256)
  32544 	defer tls.Free(256)
  32545 	var ch, ctx, n, non_zero, nz, x, y, v5 int32
  32546 	var dqm, enc, ref, src uintptr
  32547 	var _ /* tmp at bp+0 */ [8][16]int16_t
  32548 	_, _, _, _, _, _, _, _, _, _, _, _ = ch, ctx, dqm, enc, n, non_zero, nz, ref, src, x, y, v5
  32549 	enc = (*VP8EncIterator)(unsafe.Pointer(it)).Fenc
  32550 	ref = (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_p + uintptr(VP8UVModeOffsets[mode])
  32551 	src = (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_in + uintptr(libc.Int32FromInt32(U_OFF_ENC))
  32552 	dqm = enc + 608 + uintptr(int32(uint32(*(*uint8)(unsafe.Pointer((*VP8EncIterator)(unsafe.Pointer(it)).Fmb + 0))&0x60>>5)))*744
  32553 	nz = 0
  32554 	n = 0
  32555 	for {
  32556 		if !(n < int32(8)) {
  32557 			break
  32558 		}
  32559 		(*(*func(*libc.TLS, uintptr, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8FTransform2})))(tls, src+uintptr(VP8ScanUV[n]), ref+uintptr(VP8ScanUV[n]), bp+uintptr(n)*32)
  32560 		goto _1
  32561 	_1:
  32562 		;
  32563 		n = n + int32(2)
  32564 	}
  32565 	if (*VP8EncIterator)(unsafe.Pointer(it)).Ftop_derr != libc.UintptrFromInt32(0) {
  32566 		CorrectDCValues(tls, it, dqm+448, bp, rd)
  32567 	}
  32568 	if libc.Bool(DO_TRELLIS_UV != 0) && (*VP8EncIterator)(unsafe.Pointer(it)).Fdo_trellis != 0 {
  32569 		ch = 0
  32570 		n = libc.Int32FromInt32(0)
  32571 		for {
  32572 			if !(ch <= int32(2)) {
  32573 				break
  32574 			}
  32575 			y = 0
  32576 			for {
  32577 				if !(y < int32(2)) {
  32578 					break
  32579 				}
  32580 				x = 0
  32581 				for {
  32582 					if !(x < int32(2)) {
  32583 						break
  32584 					}
  32585 					ctx = **(**int32)(__ccgo_up(it + 132 + uintptr(int32(4)+ch+x)*4)) + **(**int32)(__ccgo_up(it + 168 + uintptr(int32(4)+ch+y)*4))
  32586 					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)
  32587 					v5 = non_zero
  32588 					**(**int32)(__ccgo_up(it + 168 + uintptr(int32(4)+ch+y)*4)) = v5
  32589 					**(**int32)(__ccgo_up(it + 132 + uintptr(int32(4)+ch+x)*4)) = v5
  32590 					nz = nz | non_zero<<n
  32591 					goto _4
  32592 				_4:
  32593 					;
  32594 					x = x + 1
  32595 					n = n + 1
  32596 				}
  32597 				goto _3
  32598 			_3:
  32599 				;
  32600 				y = y + 1
  32601 			}
  32602 			goto _2
  32603 		_2:
  32604 			;
  32605 			ch = ch + int32(2)
  32606 		}
  32607 	} else {
  32608 		n = 0
  32609 		for {
  32610 			if !(n < int32(8)) {
  32611 				break
  32612 			}
  32613 			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
  32614 			goto _6
  32615 		_6:
  32616 			;
  32617 			n = n + int32(2)
  32618 		}
  32619 	}
  32620 	n = 0
  32621 	for {
  32622 		if !(n < int32(8)) {
  32623 			break
  32624 		}
  32625 		(*(*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))
  32626 		goto _7
  32627 	_7:
  32628 		;
  32629 		n = n + int32(2)
  32630 	}
  32631 	return nz << int32(16)
  32632 }
  32633 
  32634 //------------------------------------------------------------------------------
  32635 // RD-opt decision. Reconstruct each modes, evalue distortion and bit-cost.
  32636 // Pick the mode is lower RD-cost = Rate + lambda * Distortion.
  32637 
  32638 func StoreMaxDelta(tls *libc.TLS, dqm uintptr, DCs uintptr) {
  32639 	var max_v, v0, v1, v2, v11, v21 int32
  32640 	_, _, _, _, _, _ = max_v, v0, v1, v2, v11, v21
  32641 	// We look at the first three AC coefficients to determine what is the average
  32642 	// delta between each sub-4x4 block.
  32643 	v0 = libc.Xabs(tls, int32(**(**int16_t)(__ccgo_up(DCs + 1*2))))
  32644 	v1 = libc.Xabs(tls, int32(**(**int16_t)(__ccgo_up(DCs + 2*2))))
  32645 	v2 = libc.Xabs(tls, int32(**(**int16_t)(__ccgo_up(DCs + 4*2))))
  32646 	if v1 > v0 {
  32647 		v11 = v1
  32648 	} else {
  32649 		v11 = v0
  32650 	}
  32651 	max_v = v11
  32652 	if v2 > max_v {
  32653 		v21 = v2
  32654 	} else {
  32655 		v21 = max_v
  32656 	}
  32657 	max_v = v21
  32658 	if max_v > (*VP8SegmentInfo)(unsafe.Pointer(dqm)).Fmax_edge {
  32659 		(*VP8SegmentInfo)(unsafe.Pointer(dqm)).Fmax_edge = max_v
  32660 	}
  32661 }
  32662 
  32663 func SwapModeScore(tls *libc.TLS, a uintptr, b uintptr) {
  32664 	var tmp uintptr
  32665 	_ = tmp
  32666 	tmp = **(**uintptr)(__ccgo_up(a))
  32667 	**(**uintptr)(__ccgo_up(a)) = **(**uintptr)(__ccgo_up(b))
  32668 	**(**uintptr)(__ccgo_up(b)) = tmp
  32669 }
  32670 
  32671 func SwapPtr(tls *libc.TLS, a uintptr, b uintptr) {
  32672 	var tmp uintptr
  32673 	_ = tmp
  32674 	tmp = **(**uintptr)(__ccgo_up(a))
  32675 	**(**uintptr)(__ccgo_up(a)) = **(**uintptr)(__ccgo_up(b))
  32676 	**(**uintptr)(__ccgo_up(b)) = tmp
  32677 }
  32678 
  32679 func SwapOut(tls *libc.TLS, it uintptr) {
  32680 	SwapPtr(tls, it+16, it+24)
  32681 }
  32682 
  32683 func PickBestIntra16(tls *libc.TLS, it uintptr, rd uintptr) {
  32684 	bp := tls.Alloc(912)
  32685 	defer tls.Free(912)
  32686 	var dqm, src1, tmp_dst, v1 uintptr
  32687 	var i, i1, is_flat, kNumBlocks, lambda, mode, score, tlambda, v3, v6, v8 int32
  32688 	var _ /* rd_best at bp+896 */ uintptr
  32689 	var _ /* rd_cur at bp+888 */ uintptr
  32690 	var _ /* rd_tmp at bp+8 */ VP8ModeScore
  32691 	var _ /* v at bp+0 */ uint32_t
  32692 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = dqm, i, i1, is_flat, kNumBlocks, lambda, mode, score, src1, tlambda, tmp_dst, v1, v3, v6, v8
  32693 	kNumBlocks = int32(16)
  32694 	dqm = (*VP8EncIterator)(unsafe.Pointer(it)).Fenc + 608 + uintptr(int32(uint32(*(*uint8)(unsafe.Pointer((*VP8EncIterator)(unsafe.Pointer(it)).Fmb + 0))&0x60>>5)))*744
  32695 	lambda = (*VP8SegmentInfo)(unsafe.Pointer(dqm)).Flambda_i16
  32696 	tlambda = (*VP8SegmentInfo)(unsafe.Pointer(dqm)).Ftlambda
  32697 	src1 = (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_in + uintptr(libc.Int32FromInt32(Y_OFF_ENC))
  32698 	**(**uintptr)(__ccgo_up(bp + 888)) = bp + 8
  32699 	**(**uintptr)(__ccgo_up(bp + 896)) = rd
  32700 	v1 = (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_in + uintptr(libc.Int32FromInt32(Y_OFF_ENC))
  32701 	**(**uint32_t)(__ccgo_up(bp)) = uint32(**(**uint8_t)(__ccgo_up(v1))) * uint32(0x01010101)
  32702 	i1 = libc.Int32FromInt32(0)
  32703 	for {
  32704 		if !(i1 < libc.Int32FromInt32(16)) {
  32705 			break
  32706 		}
  32707 		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 {
  32708 			v3 = 0
  32709 			goto _4
  32710 		}
  32711 		v1 = v1 + uintptr(BPS)
  32712 		goto _2
  32713 	_2:
  32714 		;
  32715 		i1 = i1 + 1
  32716 	}
  32717 	v3 = int32(1)
  32718 	goto _4
  32719 _4:
  32720 	is_flat = v3
  32721 	(*VP8ModeScore)(unsafe.Pointer(rd)).Fmode_i16 = -int32(1)
  32722 	mode = 0
  32723 	for {
  32724 		if !(mode < int32(NUM_PRED_MODES)) {
  32725 			break
  32726 		}
  32727 		tmp_dst = (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_out2 + uintptr(libc.Int32FromInt32(Y_OFF_ENC)) // scratch buffer
  32728 		(*VP8ModeScore)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp + 888)))).Fmode_i16 = mode
  32729 		// Reconstruct
  32730 		(*VP8ModeScore)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp + 888)))).Fnz = uint32(ReconstructIntra16(tls, it, **(**uintptr)(__ccgo_up(bp + 888)), tmp_dst, mode))
  32731 		// Measure RD-score
  32732 		(*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))
  32733 		if tlambda != 0 {
  32734 			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)
  32735 		} else {
  32736 			v3 = 0
  32737 		}
  32738 		(*VP8ModeScore)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp + 888)))).FSD = int64(v3)
  32739 		(*VP8ModeScore)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp + 888)))).FH = int64(VP8FixedCostsI16[mode])
  32740 		(*VP8ModeScore)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp + 888)))).FR = int64(VP8GetCostLuma16(tls, it, **(**uintptr)(__ccgo_up(bp + 888))))
  32741 		if is_flat != 0 {
  32742 			// refine the first impression (which was in pixel space)
  32743 			v1 = **(**uintptr)(__ccgo_up(bp + 888)) + 72
  32744 			v3 = kNumBlocks
  32745 			score = 0
  32746 			for {
  32747 				v6 = v3
  32748 				v3 = v3 - 1
  32749 				if !(v6 > libc.Int32FromInt32(0)) {
  32750 					break
  32751 				}
  32752 				i = libc.Int32FromInt32(1)
  32753 				for {
  32754 					if !(i < libc.Int32FromInt32(16)) {
  32755 						break
  32756 					}
  32757 					score = score + libc.BoolInt32(int32(**(**int16_t)(__ccgo_up(v1 + uintptr(i)*2))) != 0)
  32758 					if score > FLATNESS_LIMIT_I16 {
  32759 						v8 = 0
  32760 						goto _12
  32761 					}
  32762 					goto _10
  32763 				_10:
  32764 					;
  32765 					i = i + 1
  32766 				}
  32767 				v1 = v1 + uintptr(16)*2
  32768 			}
  32769 			v8 = int32(1)
  32770 			goto _12
  32771 		_12:
  32772 			is_flat = v8
  32773 			if is_flat != 0 {
  32774 				// Block is very flat. We put emphasis on the distortion being very low!
  32775 				**(**score_t)(__ccgo_up(**(**uintptr)(__ccgo_up(bp + 888)))) *= int64(2)
  32776 				**(**score_t)(__ccgo_up(**(**uintptr)(__ccgo_up(bp + 888)) + 8)) *= int64(2)
  32777 			}
  32778 		}
  32779 		// Since we always examine Intra16 first, we can overwrite *rd directly.
  32780 		SetRDScore(tls, lambda, **(**uintptr)(__ccgo_up(bp + 888)))
  32781 		if mode == 0 || (*VP8ModeScore)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp + 888)))).Fscore < (*VP8ModeScore)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp + 896)))).Fscore {
  32782 			SwapModeScore(tls, bp+888, bp+896)
  32783 			SwapOut(tls, it)
  32784 		}
  32785 		goto _5
  32786 	_5:
  32787 		;
  32788 		mode = mode + 1
  32789 	}
  32790 	if **(**uintptr)(__ccgo_up(bp + 896)) != rd {
  32791 		libc.Xmemcpy(tls, rd, **(**uintptr)(__ccgo_up(bp + 896)), uint64(880))
  32792 	}
  32793 	SetRDScore(tls, (*VP8SegmentInfo)(unsafe.Pointer(dqm)).Flambda_mode, rd) // finalize score for mode decision.
  32794 	VP8SetIntra16Mode(tls, it, (*VP8ModeScore)(unsafe.Pointer(rd)).Fmode_i16)
  32795 	// we have a blocky macroblock (only DCs are non-zero) with fairly high
  32796 	// distortion, record max delta so we can later adjust the minimal filtering
  32797 	// strength needed to smooth these blocks out.
  32798 	if (*VP8ModeScore)(unsafe.Pointer(rd)).Fnz&uint32(0x100ffff) == uint32(0x1000000) && (*VP8ModeScore)(unsafe.Pointer(rd)).FD > int64((*VP8SegmentInfo)(unsafe.Pointer(dqm)).Fmin_disto) {
  32799 		StoreMaxDelta(tls, dqm, rd+40)
  32800 	}
  32801 }
  32802 
  32803 //------------------------------------------------------------------------------
  32804 
  32805 // C documentation
  32806 //
  32807 //	// return the cost array corresponding to the surrounding prediction modes.
  32808 func GetCostModeI4(tls *libc.TLS, it uintptr, modes uintptr) (r uintptr) {
  32809 	var left, preds_w, top, x, y, v1, v2 int32
  32810 	_, _, _, _, _, _, _ = left, preds_w, top, x, y, v1, v2
  32811 	preds_w = (*VP8Encoder)(unsafe.Pointer((*VP8EncIterator)(unsafe.Pointer(it)).Fenc)).Fpreds_w
  32812 	x = (*VP8EncIterator)(unsafe.Pointer(it)).Fi4 & libc.Int32FromInt32(3)
  32813 	y = (*VP8EncIterator)(unsafe.Pointer(it)).Fi4 >> int32(2)
  32814 	if x == 0 {
  32815 		v1 = int32(**(**uint8_t)(__ccgo_up((*VP8EncIterator)(unsafe.Pointer(it)).Fpreds + uintptr(y*preds_w-int32(1)))))
  32816 	} else {
  32817 		v1 = int32(**(**uint8_t)(__ccgo_up(modes + uintptr((*VP8EncIterator)(unsafe.Pointer(it)).Fi4-int32(1)))))
  32818 	}
  32819 	left = v1
  32820 	if y == 0 {
  32821 		v2 = int32(**(**uint8_t)(__ccgo_up((*VP8EncIterator)(unsafe.Pointer(it)).Fpreds + uintptr(-preds_w+x))))
  32822 	} else {
  32823 		v2 = int32(**(**uint8_t)(__ccgo_up(modes + uintptr((*VP8EncIterator)(unsafe.Pointer(it)).Fi4-int32(4)))))
  32824 	}
  32825 	top = v2
  32826 	return uintptr(unsafe.Pointer(&VP8FixedCostsI4)) + uintptr(top)*200 + uintptr(left)*20
  32827 }
  32828 
  32829 func PickBestIntra4(tls *libc.TLS, it uintptr, rd uintptr) (r int32) {
  32830 	bp := tls.Alloc(2688)
  32831 	defer tls.Free(2688)
  32832 	var best_blocks, dqm, enc, mode_costs, src, src0, v3 uintptr
  32833 	var best_mode, i, kNumBlocks, lambda, mode, score, tlambda, total_header_bits, v2, v4, v5 int32
  32834 	var v9 bool
  32835 	var _ /* best_block at bp+1760 */ uintptr
  32836 	var _ /* rd_best at bp+0 */ VP8ModeScore
  32837 	var _ /* rd_i4 at bp+880 */ VP8ModeScore
  32838 	var _ /* rd_tmp at bp+1776 */ VP8ModeScore
  32839 	var _ /* tmp_dst at bp+1768 */ uintptr
  32840 	var _ /* tmp_levels at bp+2656 */ [16]int16_t
  32841 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = best_blocks, best_mode, dqm, enc, i, kNumBlocks, lambda, mode, mode_costs, score, src, src0, tlambda, total_header_bits, v2, v3, v4, v5, v9
  32842 	enc = (*VP8EncIterator)(unsafe.Pointer(it)).Fenc
  32843 	dqm = enc + 608 + uintptr(int32(uint32(*(*uint8)(unsafe.Pointer((*VP8EncIterator)(unsafe.Pointer(it)).Fmb + 0))&0x60>>5)))*744
  32844 	lambda = (*VP8SegmentInfo)(unsafe.Pointer(dqm)).Flambda_i4
  32845 	tlambda = (*VP8SegmentInfo)(unsafe.Pointer(dqm)).Ftlambda
  32846 	src0 = (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_in + uintptr(libc.Int32FromInt32(Y_OFF_ENC))
  32847 	best_blocks = (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_out2 + uintptr(libc.Int32FromInt32(Y_OFF_ENC))
  32848 	total_header_bits = 0
  32849 	if (*VP8Encoder)(unsafe.Pointer(enc)).Fmax_i4_header_bits == 0 {
  32850 		return 0
  32851 	}
  32852 	InitScore(tls, bp)
  32853 	(**(**VP8ModeScore)(__ccgo_up(bp))).FH = int64(211) // '211' is the value of VP8BitCost(0, 145)
  32854 	SetRDScore(tls, (*VP8SegmentInfo)(unsafe.Pointer(dqm)).Flambda_mode, bp)
  32855 	VP8IteratorStartI4(tls, it)
  32856 	for cond := true; cond; cond = VP8IteratorRotateI4(tls, it, best_blocks) != 0 {
  32857 		kNumBlocks = int32(1)
  32858 		best_mode = -int32(1)
  32859 		src = src0 + uintptr(VP8Scan[(*VP8EncIterator)(unsafe.Pointer(it)).Fi4])
  32860 		mode_costs = GetCostModeI4(tls, it, rd+844)
  32861 		**(**uintptr)(__ccgo_up(bp + 1760)) = best_blocks + uintptr(VP8Scan[(*VP8EncIterator)(unsafe.Pointer(it)).Fi4])
  32862 		**(**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.
  32863 		InitScore(tls, bp+880)
  32864 		MakeIntra4Preds(tls, it)
  32865 		mode = 0
  32866 		for {
  32867 			if !(mode < int32(NUM_BMODES)) {
  32868 				break
  32869 			}
  32870 			// Reconstruct
  32871 			(**(**VP8ModeScore)(__ccgo_up(bp + 1776))).Fnz = uint32(ReconstructIntra4(tls, it, bp+2656, src, **(**uintptr)(__ccgo_up(bp + 1768)), mode) << (*VP8EncIterator)(unsafe.Pointer(it)).Fi4)
  32872 			// Compute RD-score
  32873 			(**(**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))))
  32874 			if tlambda != 0 {
  32875 				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)
  32876 			} else {
  32877 				v2 = 0
  32878 			}
  32879 			(**(**VP8ModeScore)(__ccgo_up(bp + 1776))).FSD = int64(v2)
  32880 			(**(**VP8ModeScore)(__ccgo_up(bp + 1776))).FH = int64(**(**uint16_t)(__ccgo_up(mode_costs + uintptr(mode)*2)))
  32881 			// Add flatness penalty, to avoid flat area to be mispredicted
  32882 			// by a complex mode.
  32883 			if v9 = mode > 0; v9 {
  32884 				v3 = bp + 2656
  32885 				v2 = kNumBlocks
  32886 				score = 0
  32887 				for {
  32888 					v4 = v2
  32889 					v2 = v2 - 1
  32890 					if !(v4 > libc.Int32FromInt32(0)) {
  32891 						break
  32892 					}
  32893 					i = libc.Int32FromInt32(1)
  32894 					for {
  32895 						if !(i < libc.Int32FromInt32(16)) {
  32896 							break
  32897 						}
  32898 						score = score + libc.BoolInt32(int32(**(**int16_t)(__ccgo_up(v3 + uintptr(i)*2))) != 0)
  32899 						if score > int32(FLATNESS_LIMIT_I4) {
  32900 							v5 = 0
  32901 							goto _8
  32902 						}
  32903 						goto _6
  32904 					_6:
  32905 						;
  32906 						i = i + 1
  32907 					}
  32908 					v3 = v3 + uintptr(16)*2
  32909 				}
  32910 				v5 = int32(1)
  32911 				goto _8
  32912 			_8:
  32913 			}
  32914 			if v9 && v5 != 0 {
  32915 				(**(**VP8ModeScore)(__ccgo_up(bp + 1776))).FR = int64(int32(FLATNESS_PENALTY) * kNumBlocks)
  32916 			} else {
  32917 				(**(**VP8ModeScore)(__ccgo_up(bp + 1776))).FR = 0
  32918 			}
  32919 			// early-out check
  32920 			SetRDScore(tls, lambda, bp+1776)
  32921 			if best_mode >= 0 && (**(**VP8ModeScore)(__ccgo_up(bp + 1776))).Fscore >= (**(**VP8ModeScore)(__ccgo_up(bp + 880))).Fscore {
  32922 				goto _1
  32923 			}
  32924 			// finish computing score
  32925 			(**(**VP8ModeScore)(__ccgo_up(bp + 1776))).FR += int64(VP8GetCostLuma4(tls, it, bp+2656))
  32926 			SetRDScore(tls, lambda, bp+1776)
  32927 			if best_mode < 0 || (**(**VP8ModeScore)(__ccgo_up(bp + 1776))).Fscore < (**(**VP8ModeScore)(__ccgo_up(bp + 880))).Fscore {
  32928 				CopyScore(tls, bp+880, bp+1776)
  32929 				best_mode = mode
  32930 				SwapPtr(tls, bp+1768, bp+1760)
  32931 				libc.Xmemcpy(tls, bp+72+uintptr((*VP8EncIterator)(unsafe.Pointer(it)).Fi4)*32, bp+2656, uint64(32))
  32932 			}
  32933 			goto _1
  32934 		_1:
  32935 			;
  32936 			mode = mode + 1
  32937 		}
  32938 		SetRDScore(tls, (*VP8SegmentInfo)(unsafe.Pointer(dqm)).Flambda_mode, bp+880)
  32939 		AddScore(tls, bp, bp+880)
  32940 		if (**(**VP8ModeScore)(__ccgo_up(bp))).Fscore >= (*VP8ModeScore)(unsafe.Pointer(rd)).Fscore {
  32941 			return 0
  32942 		}
  32943 		total_header_bits = total_header_bits + int32((**(**VP8ModeScore)(__ccgo_up(bp + 880))).FH) // <- equal to mode_costs[best_mode];
  32944 		if total_header_bits > (*VP8Encoder)(unsafe.Pointer(enc)).Fmax_i4_header_bits {
  32945 			return 0
  32946 		}
  32947 		// Copy selected samples if not in the right place already.
  32948 		if **(**uintptr)(__ccgo_up(bp + 1760)) != best_blocks+uintptr(VP8Scan[(*VP8EncIterator)(unsafe.Pointer(it)).Fi4]) {
  32949 			(*(*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]))
  32950 		}
  32951 		**(**uint8_t)(__ccgo_up(rd + 844 + uintptr((*VP8EncIterator)(unsafe.Pointer(it)).Fi4))) = uint8(best_mode)
  32952 		if (**(**VP8ModeScore)(__ccgo_up(bp + 880))).Fnz != 0 {
  32953 			v4 = int32(1)
  32954 		} else {
  32955 			v4 = 0
  32956 		}
  32957 		v2 = v4
  32958 		**(**int32)(__ccgo_up(it + 168 + uintptr((*VP8EncIterator)(unsafe.Pointer(it)).Fi4>>int32(2))*4)) = v2
  32959 		**(**int32)(__ccgo_up(it + 132 + uintptr((*VP8EncIterator)(unsafe.Pointer(it)).Fi4&int32(3))*4)) = v2
  32960 	}
  32961 	// finalize state
  32962 	CopyScore(tls, rd, bp)
  32963 	VP8SetIntra4Mode(tls, it, rd+844)
  32964 	SwapOut(tls, it)
  32965 	libc.Xmemcpy(tls, rd+72, bp+72, uint64(512))
  32966 	return int32(1) // select intra4x4 over intra16x16
  32967 }
  32968 
  32969 //------------------------------------------------------------------------------
  32970 
  32971 func PickBestUV(tls *libc.TLS, it uintptr, rd uintptr) {
  32972 	bp := tls.Alloc(1776)
  32973 	defer tls.Free(1776)
  32974 	var dqm, dst0, src, v2 uintptr
  32975 	var i, kNumBlocks, lambda, mode, score, v3, v4, v6 int32
  32976 	var v8 bool
  32977 	var _ /* dst at bp+8 */ uintptr
  32978 	var _ /* rd_best at bp+16 */ VP8ModeScore
  32979 	var _ /* rd_uv at bp+896 */ VP8ModeScore
  32980 	var _ /* tmp_dst at bp+0 */ uintptr
  32981 	_, _, _, _, _, _, _, _, _, _, _, _, _ = dqm, dst0, i, kNumBlocks, lambda, mode, score, src, v2, v3, v4, v6, v8
  32982 	kNumBlocks = int32(8)
  32983 	dqm = (*VP8EncIterator)(unsafe.Pointer(it)).Fenc + 608 + uintptr(int32(uint32(*(*uint8)(unsafe.Pointer((*VP8EncIterator)(unsafe.Pointer(it)).Fmb + 0))&0x60>>5)))*744
  32984 	lambda = (*VP8SegmentInfo)(unsafe.Pointer(dqm)).Flambda_uv
  32985 	src = (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_in + uintptr(libc.Int32FromInt32(U_OFF_ENC))
  32986 	**(**uintptr)(__ccgo_up(bp)) = (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_out2 + uintptr(libc.Int32FromInt32(U_OFF_ENC)) // scratch buffer
  32987 	dst0 = (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_out + uintptr(libc.Int32FromInt32(U_OFF_ENC))
  32988 	**(**uintptr)(__ccgo_up(bp + 8)) = dst0
  32989 	(*VP8ModeScore)(unsafe.Pointer(rd)).Fmode_uv = -int32(1)
  32990 	InitScore(tls, bp+16)
  32991 	mode = 0
  32992 	for {
  32993 		if !(mode < int32(NUM_PRED_MODES)) {
  32994 			break
  32995 		}
  32996 		// Reconstruct
  32997 		(**(**VP8ModeScore)(__ccgo_up(bp + 896))).Fnz = uint32(ReconstructUV(tls, it, bp+896, **(**uintptr)(__ccgo_up(bp)), mode))
  32998 		// Compute RD-score
  32999 		(**(**VP8ModeScore)(__ccgo_up(bp + 896))).FD = int64((*(*func(*libc.TLS, uintptr, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{VP8SSE16x8})))(tls, src, **(**uintptr)(__ccgo_up(bp))))
  33000 		(**(**VP8ModeScore)(__ccgo_up(bp + 896))).FSD = 0 // not calling TDisto here: it tends to flatten areas.
  33001 		(**(**VP8ModeScore)(__ccgo_up(bp + 896))).FH = int64(VP8FixedCostsUV[mode])
  33002 		(**(**VP8ModeScore)(__ccgo_up(bp + 896))).FR = int64(VP8GetCostUV(tls, it, bp+896))
  33003 		if v8 = mode > 0; v8 {
  33004 			v2 = bp + 896 + 584
  33005 			v3 = kNumBlocks
  33006 			score = 0
  33007 			for {
  33008 				v4 = v3
  33009 				v3 = v3 - 1
  33010 				if !(v4 > libc.Int32FromInt32(0)) {
  33011 					break
  33012 				}
  33013 				i = libc.Int32FromInt32(1)
  33014 				for {
  33015 					if !(i < libc.Int32FromInt32(16)) {
  33016 						break
  33017 					}
  33018 					score = score + libc.BoolInt32(int32(**(**int16_t)(__ccgo_up(v2 + uintptr(i)*2))) != 0)
  33019 					if score > int32(FLATNESS_LIMIT_UV) {
  33020 						v6 = 0
  33021 						goto _7
  33022 					}
  33023 					goto _5
  33024 				_5:
  33025 					;
  33026 					i = i + 1
  33027 				}
  33028 				v2 = v2 + uintptr(16)*2
  33029 			}
  33030 			v6 = int32(1)
  33031 			goto _7
  33032 		_7:
  33033 		}
  33034 		if v8 && v6 != 0 {
  33035 			(**(**VP8ModeScore)(__ccgo_up(bp + 896))).FR += int64(int32(FLATNESS_PENALTY) * kNumBlocks)
  33036 		}
  33037 		SetRDScore(tls, lambda, bp+896)
  33038 		if mode == 0 || (**(**VP8ModeScore)(__ccgo_up(bp + 896))).Fscore < (**(**VP8ModeScore)(__ccgo_up(bp + 16))).Fscore {
  33039 			CopyScore(tls, bp+16, bp+896)
  33040 			(*VP8ModeScore)(unsafe.Pointer(rd)).Fmode_uv = mode
  33041 			libc.Xmemcpy(tls, rd+584, bp+896+584, uint64(256))
  33042 			if (*VP8EncIterator)(unsafe.Pointer(it)).Ftop_derr != libc.UintptrFromInt32(0) {
  33043 				libc.Xmemcpy(tls, rd+868, bp+896+868, uint64(6))
  33044 			}
  33045 			SwapPtr(tls, bp+8, bp)
  33046 		}
  33047 		goto _1
  33048 	_1:
  33049 		;
  33050 		mode = mode + 1
  33051 	}
  33052 	VP8SetIntraUVMode(tls, it, (*VP8ModeScore)(unsafe.Pointer(rd)).Fmode_uv)
  33053 	AddScore(tls, rd, bp+16)
  33054 	if **(**uintptr)(__ccgo_up(bp + 8)) != dst0 { // copy 16x8 block if needed
  33055 		(*(*func(*libc.TLS, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8Copy16x8})))(tls, **(**uintptr)(__ccgo_up(bp + 8)), dst0)
  33056 	}
  33057 	if (*VP8EncIterator)(unsafe.Pointer(it)).Ftop_derr != libc.UintptrFromInt32(0) { // store diffusion errors for next block
  33058 		StoreDiffusionErrors(tls, it, rd)
  33059 	}
  33060 }
  33061 
  33062 //------------------------------------------------------------------------------
  33063 // Final reconstruction and quantization.
  33064 
  33065 func SimpleQuantize(tls *libc.TLS, it uintptr, rd uintptr) {
  33066 	var dst, enc, src uintptr
  33067 	var is_i16, mode, nz int32
  33068 	_, _, _, _, _, _ = dst, enc, is_i16, mode, nz, src
  33069 	enc = (*VP8EncIterator)(unsafe.Pointer(it)).Fenc
  33070 	is_i16 = libc.BoolInt32(int32(uint32(*(*uint8)(unsafe.Pointer((*VP8EncIterator)(unsafe.Pointer(it)).Fmb + 0))&0x3>>0)) == libc.Int32FromInt32(1))
  33071 	nz = 0
  33072 	if is_i16 != 0 {
  33073 		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))))
  33074 	} else {
  33075 		VP8IteratorStartI4(tls, it)
  33076 		for cond := true; cond; cond = VP8IteratorRotateI4(tls, it, (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_out+uintptr(libc.Int32FromInt32(Y_OFF_ENC))) != 0 {
  33077 			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))))
  33078 			src = (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_in + uintptr(libc.Int32FromInt32(Y_OFF_ENC)) + uintptr(VP8Scan[(*VP8EncIterator)(unsafe.Pointer(it)).Fi4])
  33079 			dst = (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_out + uintptr(libc.Int32FromInt32(Y_OFF_ENC)) + uintptr(VP8Scan[(*VP8EncIterator)(unsafe.Pointer(it)).Fi4])
  33080 			MakeIntra4Preds(tls, it)
  33081 			nz = nz | ReconstructIntra4(tls, it, rd+72+uintptr((*VP8EncIterator)(unsafe.Pointer(it)).Fi4)*32, src, dst, mode)<<(*VP8EncIterator)(unsafe.Pointer(it)).Fi4
  33082 		}
  33083 	}
  33084 	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)))
  33085 	(*VP8ModeScore)(unsafe.Pointer(rd)).Fnz = uint32(nz)
  33086 }
  33087 
  33088 // C documentation
  33089 //
  33090 //	// Refine intra16/intra4 sub-modes based on distortion only (not rate).
  33091 func RefineUsingDistortion(tls *libc.TLS, it uintptr, try_both_modes int32, refine_uv_mode int32, rd uintptr) {
  33092 	bp := tls.Alloc(16)
  33093 	defer tls.Free(16)
  33094 	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
  33095 	var best_i4_score, best_score, best_uv_score, bit_limit, i4_bit_sum, score, score1, score2, score_i4 score_t
  33096 	var dqm, mode_costs, ref, ref1, ref2, src1, src2, src3, tmp_dst, v3 uintptr
  33097 	var v1 int64
  33098 	var _ /* v at bp+0 */ uint32_t
  33099 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  33100 	best_score = libc.Int64FromInt64(0x7fffffffffffff)
  33101 	nz = 0
  33102 	is_i16 = libc.BoolInt32(try_both_modes != 0 || int32(uint32(*(*uint8)(unsafe.Pointer((*VP8EncIterator)(unsafe.Pointer(it)).Fmb + 0))&0x3>>0)) == int32(1))
  33103 	dqm = (*VP8EncIterator)(unsafe.Pointer(it)).Fenc + 608 + uintptr(int32(uint32(*(*uint8)(unsafe.Pointer((*VP8EncIterator)(unsafe.Pointer(it)).Fmb + 0))&0x60>>5)))*744
  33104 	// Some empiric constants, of approximate order of magnitude.
  33105 	lambda_d_i16 = int32(106)
  33106 	lambda_d_i4 = int32(11)
  33107 	lambda_d_uv = int32(120)
  33108 	score_i4 = (*VP8SegmentInfo)(unsafe.Pointer(dqm)).Fi4_penalty
  33109 	i4_bit_sum = 0
  33110 	if try_both_modes != 0 {
  33111 		v1 = int64((*VP8Encoder)(unsafe.Pointer((*VP8EncIterator)(unsafe.Pointer(it)).Fenc)).Fmb_header_limit)
  33112 	} else {
  33113 		v1 = libc.Int64FromInt64(0x7fffffffffffff)
  33114 	}
  33115 	bit_limit = v1   // no early-out allowed
  33116 	if is_i16 != 0 { // First, evaluate Intra16 distortion
  33117 		best_mode = -int32(1)
  33118 		src1 = (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_in + uintptr(libc.Int32FromInt32(Y_OFF_ENC))
  33119 		mode = 0
  33120 		for {
  33121 			if !(mode < int32(NUM_PRED_MODES)) {
  33122 				break
  33123 			}
  33124 			ref = (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_p + uintptr(VP8I16ModeOffsets[mode])
  33125 			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)
  33126 			if mode > 0 && int64(VP8FixedCostsI16[mode]) > bit_limit {
  33127 				goto _2
  33128 			}
  33129 			if score < best_score {
  33130 				best_mode = mode
  33131 				best_score = score
  33132 			}
  33133 			goto _2
  33134 		_2:
  33135 			;
  33136 			mode = mode + 1
  33137 		}
  33138 		if (*VP8EncIterator)(unsafe.Pointer(it)).Fx == 0 || (*VP8EncIterator)(unsafe.Pointer(it)).Fy == 0 {
  33139 			// avoid starting a checkerboard resonance from the border. See bug #432.
  33140 			v3 = src1
  33141 			**(**uint32_t)(__ccgo_up(bp)) = uint32(**(**uint8_t)(__ccgo_up(v3))) * uint32(0x01010101)
  33142 			i = libc.Int32FromInt32(0)
  33143 			for {
  33144 				if !(i < libc.Int32FromInt32(16)) {
  33145 					break
  33146 				}
  33147 				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 {
  33148 					v5 = 0
  33149 					goto _6
  33150 				}
  33151 				v3 = v3 + uintptr(BPS)
  33152 				goto _4
  33153 			_4:
  33154 				;
  33155 				i = i + 1
  33156 			}
  33157 			v5 = int32(1)
  33158 			goto _6
  33159 		_6:
  33160 			if v5 != 0 {
  33161 				if (*VP8EncIterator)(unsafe.Pointer(it)).Fx == 0 {
  33162 					v7 = 0
  33163 				} else {
  33164 					v7 = int32(2)
  33165 				}
  33166 				best_mode = v7
  33167 				try_both_modes = 0 // stick to i16
  33168 			}
  33169 		}
  33170 		VP8SetIntra16Mode(tls, it, best_mode)
  33171 		// we'll reconstruct later, if i16 mode actually gets selected
  33172 	}
  33173 	// Next, evaluate Intra4
  33174 	if try_both_modes != 0 || !(is_i16 != 0) {
  33175 		// We don't evaluate the rate here, but just account for it through a
  33176 		// constant penalty (i4 mode usually needs more bits compared to i16).
  33177 		is_i16 = 0
  33178 		VP8IteratorStartI4(tls, it)
  33179 		for cond := true; cond; cond = VP8IteratorRotateI4(tls, it, (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_out2+uintptr(libc.Int32FromInt32(Y_OFF_ENC))) != 0 {
  33180 			best_i4_mode = -int32(1)
  33181 			best_i4_score = libc.Int64FromInt64(0x7fffffffffffff)
  33182 			src2 = (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_in + uintptr(libc.Int32FromInt32(Y_OFF_ENC)) + uintptr(VP8Scan[(*VP8EncIterator)(unsafe.Pointer(it)).Fi4])
  33183 			mode_costs = GetCostModeI4(tls, it, rd+844)
  33184 			MakeIntra4Preds(tls, it)
  33185 			mode = 0
  33186 			for {
  33187 				if !(mode < int32(NUM_BMODES)) {
  33188 					break
  33189 				}
  33190 				ref1 = (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_p + uintptr(VP8I4ModeOffsets[mode])
  33191 				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)
  33192 				if score1 < best_i4_score {
  33193 					best_i4_mode = mode
  33194 					best_i4_score = score1
  33195 				}
  33196 				goto _8
  33197 			_8:
  33198 				;
  33199 				mode = mode + 1
  33200 			}
  33201 			i4_bit_sum = i4_bit_sum + int64(**(**uint16_t)(__ccgo_up(mode_costs + uintptr(best_i4_mode)*2)))
  33202 			**(**uint8_t)(__ccgo_up(rd + 844 + uintptr((*VP8EncIterator)(unsafe.Pointer(it)).Fi4))) = uint8(best_i4_mode)
  33203 			score_i4 = score_i4 + best_i4_score
  33204 			if score_i4 >= best_score || i4_bit_sum > bit_limit {
  33205 				// Intra4 won't be better than Intra16. Bail out and pick Intra16.
  33206 				is_i16 = int32(1)
  33207 				break
  33208 			} else { // reconstruct partial block inside yuv_out2 buffer
  33209 				tmp_dst = (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_out2 + uintptr(libc.Int32FromInt32(Y_OFF_ENC)) + uintptr(VP8Scan[(*VP8EncIterator)(unsafe.Pointer(it)).Fi4])
  33210 				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
  33211 			}
  33212 		}
  33213 	}
  33214 	// Final reconstruction, depending on which mode is selected.
  33215 	if !(is_i16 != 0) {
  33216 		VP8SetIntra4Mode(tls, it, rd+844)
  33217 		SwapOut(tls, it)
  33218 		best_score = score_i4
  33219 	} else {
  33220 		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))))
  33221 	}
  33222 	// ... and UV!
  33223 	if refine_uv_mode != 0 {
  33224 		best_mode1 = -int32(1)
  33225 		best_uv_score = libc.Int64FromInt64(0x7fffffffffffff)
  33226 		src3 = (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_in + uintptr(libc.Int32FromInt32(U_OFF_ENC))
  33227 		mode = 0
  33228 		for {
  33229 			if !(mode < int32(NUM_PRED_MODES)) {
  33230 				break
  33231 			}
  33232 			ref2 = (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_p + uintptr(VP8UVModeOffsets[mode])
  33233 			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)
  33234 			if score2 < best_uv_score {
  33235 				best_mode1 = mode
  33236 				best_uv_score = score2
  33237 			}
  33238 			goto _9
  33239 		_9:
  33240 			;
  33241 			mode = mode + 1
  33242 		}
  33243 		VP8SetIntraUVMode(tls, it, best_mode1)
  33244 	}
  33245 	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)))
  33246 	(*VP8ModeScore)(unsafe.Pointer(rd)).Fnz = uint32(nz)
  33247 	(*VP8ModeScore)(unsafe.Pointer(rd)).Fscore = best_score
  33248 }
  33249 
  33250 //------------------------------------------------------------------------------
  33251 // Entry point
  33252 
  33253 func VP8Decimate(tls *libc.TLS, it uintptr, rd uintptr, rd_opt VP8RDLevel) (r int32) {
  33254 	var is_skipped, method int32
  33255 	_, _ = is_skipped, method
  33256 	method = (*VP8Encoder)(unsafe.Pointer((*VP8EncIterator)(unsafe.Pointer(it)).Fenc)).Fmethod
  33257 	InitScore(tls, rd)
  33258 	// We can perform predictions for Luma16x16 and Chroma8x8 already.
  33259 	// Luma4x4 predictions needs to be done as-we-go.
  33260 	VP8MakeLuma16Preds(tls, it)
  33261 	VP8MakeChroma8Preds(tls, it)
  33262 	if rd_opt > int32(RD_OPT_NONE) {
  33263 		(*VP8EncIterator)(unsafe.Pointer(it)).Fdo_trellis = libc.BoolInt32(rd_opt >= int32(RD_OPT_TRELLIS_ALL))
  33264 		PickBestIntra16(tls, it, rd)
  33265 		if method >= int32(2) {
  33266 			PickBestIntra4(tls, it, rd)
  33267 		}
  33268 		PickBestUV(tls, it, rd)
  33269 		if rd_opt == int32(RD_OPT_TRELLIS) { // finish off with trellis-optim now
  33270 			(*VP8EncIterator)(unsafe.Pointer(it)).Fdo_trellis = int32(1)
  33271 			SimpleQuantize(tls, it, rd)
  33272 		}
  33273 	} else {
  33274 		// At this point we have heuristically decided intra16 / intra4.
  33275 		// For method >= 2, pick the best intra4/intra16 based on SSE (~tad slower).
  33276 		// For method <= 1, we don't re-examine the decision but just go ahead with
  33277 		// quantization/reconstruction.
  33278 		RefineUsingDistortion(tls, it, libc.BoolInt32(method >= int32(2)), libc.BoolInt32(method >= int32(1)), rd)
  33279 	}
  33280 	is_skipped = libc.BoolInt32((*VP8ModeScore)(unsafe.Pointer(rd)).Fnz == uint32(0))
  33281 	VP8SetSkip(tls, it, is_skipped)
  33282 	return is_skipped
  33283 }
  33284 
  33285 const ARGB_BLACK2 = 0xff000000
  33286 const SIZE_MAX13 = "UINT64_MAX"
  33287 const VP8_SIGNATURE1 = 10289450
  33288 
  33289 //------------------------------------------------------------------------------
  33290 // Helper functions
  33291 
  33292 func IsVP8XNeeded(tls *libc.TLS, enc uintptr) (r int32) {
  33293 	return libc.BoolInt32(!!((*VP8Encoder)(unsafe.Pointer(enc)).Fhas_alpha != 0)) // Currently the only case when VP8X is needed.
  33294 	// This could change in the future.
  33295 }
  33296 
  33297 func PutPaddingByte(tls *libc.TLS, pic uintptr) (r int32) {
  33298 	bp := tls.Alloc(16)
  33299 	defer tls.Free(16)
  33300 	var _ /* pad_byte at bp+0 */ [1]uint8_t
  33301 	**(**[1]uint8_t)(__ccgo_up(bp)) = [1]uint8_t{}
  33302 	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))
  33303 }
  33304 
  33305 //------------------------------------------------------------------------------
  33306 // Writers for header's various pieces (in order of appearance)
  33307 
  33308 func PutRIFFHeader(tls *libc.TLS, enc uintptr, riff_size size_t) (r WebPEncodingError1) {
  33309 	bp := tls.Alloc(16)
  33310 	defer tls.Free(16)
  33311 	var pic, v1, v3, v5 uintptr
  33312 	var v2 uint32_t
  33313 	var v4, v6 int32
  33314 	var _ /* riff at bp+0 */ [12]uint8_t
  33315 	_, _, _, _, _, _, _ = pic, v1, v2, v3, v4, v5, v6
  33316 	pic = (*VP8Encoder)(unsafe.Pointer(enc)).Fpic
  33317 	**(**[12]uint8_t)(__ccgo_up(bp)) = [12]uint8_t{
  33318 		0:  uint8('R'),
  33319 		1:  uint8('I'),
  33320 		2:  uint8('F'),
  33321 		3:  uint8('F'),
  33322 		8:  uint8('W'),
  33323 		9:  uint8('E'),
  33324 		10: uint8('B'),
  33325 		11: uint8('P'),
  33326 	}
  33327 	v1 = bp + uintptr(TAG_SIZE)
  33328 	v2 = uint32(riff_size)
  33329 	v3 = v1
  33330 	v4 = int32(v2 & libc.Uint32FromInt32(0xffff))
  33331 	**(**uint8_t)(__ccgo_up(v3)) = uint8(v4 >> 0 & int32(0xff))
  33332 	**(**uint8_t)(__ccgo_up(v3 + 1)) = uint8(v4 >> int32(8) & int32(0xff))
  33333 	v5 = v1 + uintptr(2)
  33334 	v6 = int32(v2 >> libc.Int32FromInt32(16))
  33335 	**(**uint8_t)(__ccgo_up(v5)) = uint8(v6 >> 0 & int32(0xff))
  33336 	**(**uint8_t)(__ccgo_up(v5 + 1)) = uint8(v6 >> int32(8) & int32(0xff))
  33337 	if !((*(*func(*libc.TLS, uintptr, size_t, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*WebPPicture)(unsafe.Pointer(pic)).Fwriter})))(tls, bp, uint64(12), pic) != 0) {
  33338 		return int32(VP8_ENC_ERROR_BAD_WRITE)
  33339 	}
  33340 	return int32(VP8_ENC_OK)
  33341 }
  33342 
  33343 func PutVP8XHeader(tls *libc.TLS, enc uintptr) (r WebPEncodingError1) {
  33344 	bp := tls.Alloc(32)
  33345 	defer tls.Free(32)
  33346 	var flags, v2 uint32_t
  33347 	var pic, v1, v3, v5 uintptr
  33348 	var v4, v6 int32
  33349 	var _ /* vp8x at bp+0 */ [18]uint8_t
  33350 	_, _, _, _, _, _, _, _ = flags, pic, v1, v2, v3, v4, v5, v6
  33351 	pic = (*VP8Encoder)(unsafe.Pointer(enc)).Fpic
  33352 	**(**[18]uint8_t)(__ccgo_up(bp)) = [18]uint8_t{
  33353 		0: uint8('V'),
  33354 		1: uint8('P'),
  33355 		2: uint8('8'),
  33356 		3: uint8('X'),
  33357 	}
  33358 	flags = uint32(0)
  33359 	if (*VP8Encoder)(unsafe.Pointer(enc)).Fhas_alpha != 0 {
  33360 		flags = flags | uint32(ALPHA_FLAG)
  33361 	}
  33362 	v1 = bp + uintptr(TAG_SIZE)
  33363 	v2 = uint32(VP8X_CHUNK_SIZE)
  33364 	v3 = v1
  33365 	v4 = int32(v2 & libc.Uint32FromInt32(0xffff))
  33366 	**(**uint8_t)(__ccgo_up(v3)) = uint8(v4 >> 0 & int32(0xff))
  33367 	**(**uint8_t)(__ccgo_up(v3 + 1)) = uint8(v4 >> int32(8) & int32(0xff))
  33368 	v5 = v1 + uintptr(2)
  33369 	v6 = int32(v2 >> libc.Int32FromInt32(16))
  33370 	**(**uint8_t)(__ccgo_up(v5)) = uint8(v6 >> 0 & int32(0xff))
  33371 	**(**uint8_t)(__ccgo_up(v5 + 1)) = uint8(v6 >> int32(8) & int32(0xff))
  33372 	v1 = bp + uintptr(CHUNK_HEADER_SIZE)
  33373 	v2 = flags
  33374 	v3 = v1
  33375 	v4 = int32(v2 & libc.Uint32FromInt32(0xffff))
  33376 	**(**uint8_t)(__ccgo_up(v3)) = uint8(v4 >> 0 & int32(0xff))
  33377 	**(**uint8_t)(__ccgo_up(v3 + 1)) = uint8(v4 >> int32(8) & int32(0xff))
  33378 	v5 = v1 + uintptr(2)
  33379 	v6 = int32(v2 >> libc.Int32FromInt32(16))
  33380 	**(**uint8_t)(__ccgo_up(v5)) = uint8(v6 >> 0 & int32(0xff))
  33381 	**(**uint8_t)(__ccgo_up(v5 + 1)) = uint8(v6 >> int32(8) & int32(0xff))
  33382 	v1 = bp + uintptr(CHUNK_HEADER_SIZE) + uintptr(4)
  33383 	v4 = (*WebPPicture)(unsafe.Pointer(pic)).Fwidth - int32(1)
  33384 	v3 = v1
  33385 	v6 = v4 & int32(0xffff)
  33386 	**(**uint8_t)(__ccgo_up(v3)) = uint8(v6 >> 0 & int32(0xff))
  33387 	**(**uint8_t)(__ccgo_up(v3 + 1)) = uint8(v6 >> int32(8) & int32(0xff))
  33388 	**(**uint8_t)(__ccgo_up(v1 + 2)) = uint8(v4 >> int32(16) & int32(0xff))
  33389 	v1 = bp + uintptr(CHUNK_HEADER_SIZE) + uintptr(7)
  33390 	v4 = (*WebPPicture)(unsafe.Pointer(pic)).Fheight - int32(1)
  33391 	v3 = v1
  33392 	v6 = v4 & int32(0xffff)
  33393 	**(**uint8_t)(__ccgo_up(v3)) = uint8(v6 >> 0 & int32(0xff))
  33394 	**(**uint8_t)(__ccgo_up(v3 + 1)) = uint8(v6 >> int32(8) & int32(0xff))
  33395 	**(**uint8_t)(__ccgo_up(v1 + 2)) = uint8(v4 >> int32(16) & int32(0xff))
  33396 	if !((*(*func(*libc.TLS, uintptr, size_t, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*WebPPicture)(unsafe.Pointer(pic)).Fwriter})))(tls, bp, uint64(18), pic) != 0) {
  33397 		return int32(VP8_ENC_ERROR_BAD_WRITE)
  33398 	}
  33399 	return int32(VP8_ENC_OK)
  33400 }
  33401 
  33402 func PutAlphaChunk(tls *libc.TLS, enc uintptr) (r WebPEncodingError1) {
  33403 	bp := tls.Alloc(16)
  33404 	defer tls.Free(16)
  33405 	var pic, v1, v3, v5 uintptr
  33406 	var v2 uint32_t
  33407 	var v4, v6 int32
  33408 	var _ /* alpha_chunk_hdr at bp+0 */ [8]uint8_t
  33409 	_, _, _, _, _, _, _ = pic, v1, v2, v3, v4, v5, v6
  33410 	pic = (*VP8Encoder)(unsafe.Pointer(enc)).Fpic
  33411 	**(**[8]uint8_t)(__ccgo_up(bp)) = [8]uint8_t{
  33412 		0: uint8('A'),
  33413 		1: uint8('L'),
  33414 		2: uint8('P'),
  33415 		3: uint8('H'),
  33416 	}
  33417 	// Alpha chunk header.
  33418 	v1 = bp + uintptr(TAG_SIZE)
  33419 	v2 = (*VP8Encoder)(unsafe.Pointer(enc)).Falpha_data_size
  33420 	v3 = v1
  33421 	v4 = int32(v2 & libc.Uint32FromInt32(0xffff))
  33422 	**(**uint8_t)(__ccgo_up(v3)) = uint8(v4 >> 0 & int32(0xff))
  33423 	**(**uint8_t)(__ccgo_up(v3 + 1)) = uint8(v4 >> int32(8) & int32(0xff))
  33424 	v5 = v1 + uintptr(2)
  33425 	v6 = int32(v2 >> libc.Int32FromInt32(16))
  33426 	**(**uint8_t)(__ccgo_up(v5)) = uint8(v6 >> 0 & int32(0xff))
  33427 	**(**uint8_t)(__ccgo_up(v5 + 1)) = uint8(v6 >> int32(8) & int32(0xff))
  33428 	if !((*(*func(*libc.TLS, uintptr, size_t, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*WebPPicture)(unsafe.Pointer(pic)).Fwriter})))(tls, bp, uint64(8), pic) != 0) {
  33429 		return int32(VP8_ENC_ERROR_BAD_WRITE)
  33430 	}
  33431 	// Alpha chunk data.
  33432 	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) {
  33433 		return int32(VP8_ENC_ERROR_BAD_WRITE)
  33434 	}
  33435 	// Padding.
  33436 	if (*VP8Encoder)(unsafe.Pointer(enc)).Falpha_data_size&uint32(1) != 0 && !(PutPaddingByte(tls, pic) != 0) {
  33437 		return int32(VP8_ENC_ERROR_BAD_WRITE)
  33438 	}
  33439 	return int32(VP8_ENC_OK)
  33440 }
  33441 
  33442 func PutVP8Header(tls *libc.TLS, pic uintptr, vp8_size size_t) (r WebPEncodingError1) {
  33443 	bp := tls.Alloc(16)
  33444 	defer tls.Free(16)
  33445 	var v1, v3, v5 uintptr
  33446 	var v2 uint32_t
  33447 	var v4, v6 int32
  33448 	var _ /* vp8_chunk_hdr at bp+0 */ [8]uint8_t
  33449 	_, _, _, _, _, _ = v1, v2, v3, v4, v5, v6
  33450 	**(**[8]uint8_t)(__ccgo_up(bp)) = [8]uint8_t{
  33451 		0: uint8('V'),
  33452 		1: uint8('P'),
  33453 		2: uint8('8'),
  33454 		3: uint8(' '),
  33455 	}
  33456 	v1 = bp + uintptr(TAG_SIZE)
  33457 	v2 = uint32(vp8_size)
  33458 	v3 = v1
  33459 	v4 = int32(v2 & libc.Uint32FromInt32(0xffff))
  33460 	**(**uint8_t)(__ccgo_up(v3)) = uint8(v4 >> 0 & int32(0xff))
  33461 	**(**uint8_t)(__ccgo_up(v3 + 1)) = uint8(v4 >> int32(8) & int32(0xff))
  33462 	v5 = v1 + uintptr(2)
  33463 	v6 = int32(v2 >> libc.Int32FromInt32(16))
  33464 	**(**uint8_t)(__ccgo_up(v5)) = uint8(v6 >> 0 & int32(0xff))
  33465 	**(**uint8_t)(__ccgo_up(v5 + 1)) = uint8(v6 >> int32(8) & int32(0xff))
  33466 	if !((*(*func(*libc.TLS, uintptr, size_t, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*WebPPicture)(unsafe.Pointer(pic)).Fwriter})))(tls, bp, uint64(8), pic) != 0) {
  33467 		return int32(VP8_ENC_ERROR_BAD_WRITE)
  33468 	}
  33469 	return int32(VP8_ENC_OK)
  33470 }
  33471 
  33472 func PutVP8FrameHeader(tls *libc.TLS, pic uintptr, profile int32, size0 size_t) (r WebPEncodingError1) {
  33473 	bp := tls.Alloc(16)
  33474 	defer tls.Free(16)
  33475 	var bits uint32_t
  33476 	var _ /* vp8_frm_hdr at bp+0 */ [10]uint8_t
  33477 	_ = bits
  33478 	if size0 >= uint64(libc.Int32FromInt32(1)<<libc.Int32FromInt32(19)) { // partition #0 is too big to fit
  33479 		return int32(VP8_ENC_ERROR_PARTITION0_OVERFLOW)
  33480 	}
  33481 	// Paragraph 9.1.
  33482 	bits = uint32(0|profile<<int32(1)|libc.Int32FromInt32(1)<<libc.Int32FromInt32(4)) | uint32(size0)<<libc.Int32FromInt32(5) // partition length (19b)
  33483 	(**(**[10]uint8_t)(__ccgo_up(bp)))[0] = uint8(bits >> libc.Int32FromInt32(0) & uint32(0xff))
  33484 	(**(**[10]uint8_t)(__ccgo_up(bp)))[int32(1)] = uint8(bits >> libc.Int32FromInt32(8) & uint32(0xff))
  33485 	(**(**[10]uint8_t)(__ccgo_up(bp)))[int32(2)] = uint8(bits >> libc.Int32FromInt32(16) & uint32(0xff))
  33486 	// signature
  33487 	(**(**[10]uint8_t)(__ccgo_up(bp)))[int32(3)] = uint8(libc.Int32FromInt32(VP8_SIGNATURE1) >> libc.Int32FromInt32(16) & libc.Int32FromInt32(0xff))
  33488 	(**(**[10]uint8_t)(__ccgo_up(bp)))[int32(4)] = uint8(libc.Int32FromInt32(VP8_SIGNATURE1) >> libc.Int32FromInt32(8) & libc.Int32FromInt32(0xff))
  33489 	(**(**[10]uint8_t)(__ccgo_up(bp)))[int32(5)] = uint8(libc.Int32FromInt32(VP8_SIGNATURE1) >> libc.Int32FromInt32(0) & libc.Int32FromInt32(0xff))
  33490 	// dimensions
  33491 	(**(**[10]uint8_t)(__ccgo_up(bp)))[int32(6)] = uint8((*WebPPicture)(unsafe.Pointer(pic)).Fwidth & int32(0xff))
  33492 	(**(**[10]uint8_t)(__ccgo_up(bp)))[int32(7)] = uint8((*WebPPicture)(unsafe.Pointer(pic)).Fwidth >> int32(8))
  33493 	(**(**[10]uint8_t)(__ccgo_up(bp)))[int32(8)] = uint8((*WebPPicture)(unsafe.Pointer(pic)).Fheight & int32(0xff))
  33494 	(**(**[10]uint8_t)(__ccgo_up(bp)))[int32(9)] = uint8((*WebPPicture)(unsafe.Pointer(pic)).Fheight >> int32(8))
  33495 	if !((*(*func(*libc.TLS, uintptr, size_t, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*WebPPicture)(unsafe.Pointer(pic)).Fwriter})))(tls, bp, uint64(10), pic) != 0) {
  33496 		return int32(VP8_ENC_ERROR_BAD_WRITE)
  33497 	}
  33498 	return int32(VP8_ENC_OK)
  33499 }
  33500 
  33501 // C documentation
  33502 //
  33503 //	// WebP Headers.
  33504 func PutWebPHeaders(tls *libc.TLS, enc uintptr, size0 size_t, vp8_size size_t, riff_size size_t) (r int32) {
  33505 	var err WebPEncodingError1
  33506 	var pic uintptr
  33507 	_, _ = err, pic
  33508 	pic = (*VP8Encoder)(unsafe.Pointer(enc)).Fpic
  33509 	err = int32(VP8_ENC_OK)
  33510 	// RIFF header.
  33511 	err = PutRIFFHeader(tls, enc, riff_size)
  33512 	if err != int32(VP8_ENC_OK) {
  33513 		goto Error
  33514 	}
  33515 	// VP8X.
  33516 	if IsVP8XNeeded(tls, enc) != 0 {
  33517 		err = PutVP8XHeader(tls, enc)
  33518 		if err != int32(VP8_ENC_OK) {
  33519 			goto Error
  33520 		}
  33521 	}
  33522 	// Alpha.
  33523 	if (*VP8Encoder)(unsafe.Pointer(enc)).Fhas_alpha != 0 {
  33524 		err = PutAlphaChunk(tls, enc)
  33525 		if err != int32(VP8_ENC_OK) {
  33526 			goto Error
  33527 		}
  33528 	}
  33529 	// VP8 header.
  33530 	err = PutVP8Header(tls, pic, vp8_size)
  33531 	if err != int32(VP8_ENC_OK) {
  33532 		goto Error
  33533 	}
  33534 	// VP8 frame header.
  33535 	err = PutVP8FrameHeader(tls, pic, (*VP8Encoder)(unsafe.Pointer(enc)).Fprofile, size0)
  33536 	if err != int32(VP8_ENC_OK) {
  33537 		goto Error
  33538 	}
  33539 	// All OK.
  33540 	return int32(1)
  33541 	// Error.
  33542 	goto Error
  33543 Error:
  33544 	;
  33545 	return WebPEncodingSetError(tls, pic, err)
  33546 	return r
  33547 }
  33548 
  33549 // C documentation
  33550 //
  33551 //	// Segmentation header
  33552 func PutSegmentHeader(tls *libc.TLS, bw uintptr, enc uintptr) {
  33553 	var hdr, proba uintptr
  33554 	var s, update_data int32
  33555 	_, _, _, _ = hdr, proba, s, update_data
  33556 	hdr = enc + 32
  33557 	proba = enc + 3616
  33558 	if VP8PutBitUniform(tls, bw, libc.BoolInt32((*VP8EncSegmentHeader)(unsafe.Pointer(hdr)).Fnum_segments > int32(1))) != 0 {
  33559 		// We always 'update' the quant and filter strength values
  33560 		update_data = int32(1)
  33561 		VP8PutBitUniform(tls, bw, (*VP8EncSegmentHeader)(unsafe.Pointer(hdr)).Fupdate_map)
  33562 		if VP8PutBitUniform(tls, bw, update_data) != 0 {
  33563 			// we always use absolute values, not relative ones
  33564 			VP8PutBitUniform(tls, bw, int32(1)) // (segment_feature_mode = 1. Paragraph 9.3.)
  33565 			s = 0
  33566 			for {
  33567 				if !(s < int32(NUM_MB_SEGMENTS)) {
  33568 					break
  33569 				}
  33570 				VP8PutSignedBits(tls, bw, (**(**VP8SegmentInfo)(__ccgo_up(enc + 608 + uintptr(s)*744))).Fquant, int32(7))
  33571 				goto _1
  33572 			_1:
  33573 				;
  33574 				s = s + 1
  33575 			}
  33576 			s = 0
  33577 			for {
  33578 				if !(s < int32(NUM_MB_SEGMENTS)) {
  33579 					break
  33580 				}
  33581 				VP8PutSignedBits(tls, bw, (**(**VP8SegmentInfo)(__ccgo_up(enc + 608 + uintptr(s)*744))).Ffstrength, int32(6))
  33582 				goto _2
  33583 			_2:
  33584 				;
  33585 				s = s + 1
  33586 			}
  33587 		}
  33588 		if (*VP8EncSegmentHeader)(unsafe.Pointer(hdr)).Fupdate_map != 0 {
  33589 			s = 0
  33590 			for {
  33591 				if !(s < int32(3)) {
  33592 					break
  33593 				}
  33594 				if VP8PutBitUniform(tls, bw, libc.BoolInt32(uint32(**(**uint8_t)(__ccgo_up(proba + uintptr(s)))) != uint32(255))) != 0 {
  33595 					VP8PutBits(tls, bw, uint32(**(**uint8_t)(__ccgo_up(proba + uintptr(s)))), int32(8))
  33596 				}
  33597 				goto _3
  33598 			_3:
  33599 				;
  33600 				s = s + 1
  33601 			}
  33602 		}
  33603 	}
  33604 }
  33605 
  33606 // C documentation
  33607 //
  33608 //	// Filtering parameters header
  33609 func PutFilterHeader(tls *libc.TLS, bw uintptr, hdr uintptr) {
  33610 	var need_update, use_lf_delta int32
  33611 	_, _ = need_update, use_lf_delta
  33612 	use_lf_delta = libc.BoolInt32((*VP8EncFilterHeader)(unsafe.Pointer(hdr)).Fi4x4_lf_delta != libc.Int32FromInt32(0))
  33613 	VP8PutBitUniform(tls, bw, (*VP8EncFilterHeader)(unsafe.Pointer(hdr)).Fsimple)
  33614 	VP8PutBits(tls, bw, uint32((*VP8EncFilterHeader)(unsafe.Pointer(hdr)).Flevel), int32(6))
  33615 	VP8PutBits(tls, bw, uint32((*VP8EncFilterHeader)(unsafe.Pointer(hdr)).Fsharpness), int32(3))
  33616 	if VP8PutBitUniform(tls, bw, use_lf_delta) != 0 {
  33617 		// '0' is the default value for i4x4_lf_delta at frame #0.
  33618 		need_update = libc.BoolInt32((*VP8EncFilterHeader)(unsafe.Pointer(hdr)).Fi4x4_lf_delta != libc.Int32FromInt32(0))
  33619 		if VP8PutBitUniform(tls, bw, need_update) != 0 {
  33620 			// we don't use ref_lf_delta => emit four 0 bits
  33621 			VP8PutBits(tls, bw, uint32(0), int32(4))
  33622 			// we use mode_lf_delta for i4x4
  33623 			VP8PutSignedBits(tls, bw, (*VP8EncFilterHeader)(unsafe.Pointer(hdr)).Fi4x4_lf_delta, int32(6))
  33624 			VP8PutBits(tls, bw, uint32(0), int32(3)) // all others unused
  33625 		}
  33626 	}
  33627 }
  33628 
  33629 // C documentation
  33630 //
  33631 //	// Nominal quantization parameters
  33632 func PutQuant(tls *libc.TLS, bw uintptr, enc uintptr) {
  33633 	VP8PutBits(tls, bw, uint32((*VP8Encoder)(unsafe.Pointer(enc)).Fbase_quant), int32(7))
  33634 	VP8PutSignedBits(tls, bw, (*VP8Encoder)(unsafe.Pointer(enc)).Fdq_y1_dc, int32(4))
  33635 	VP8PutSignedBits(tls, bw, (*VP8Encoder)(unsafe.Pointer(enc)).Fdq_y2_dc, int32(4))
  33636 	VP8PutSignedBits(tls, bw, (*VP8Encoder)(unsafe.Pointer(enc)).Fdq_y2_ac, int32(4))
  33637 	VP8PutSignedBits(tls, bw, (*VP8Encoder)(unsafe.Pointer(enc)).Fdq_uv_dc, int32(4))
  33638 	VP8PutSignedBits(tls, bw, (*VP8Encoder)(unsafe.Pointer(enc)).Fdq_uv_ac, int32(4))
  33639 }
  33640 
  33641 // C documentation
  33642 //
  33643 //	// Partition sizes
  33644 func EmitPartitionsSize(tls *libc.TLS, enc uintptr, pic uintptr) (r int32) {
  33645 	bp := tls.Alloc(32)
  33646 	defer tls.Free(32)
  33647 	var p int32
  33648 	var part_size, v2 size_t
  33649 	var _ /* buf at bp+0 */ [21]uint8_t
  33650 	_, _, _ = p, part_size, v2
  33651 	p = 0
  33652 	for {
  33653 		if !(p < (*VP8Encoder)(unsafe.Pointer(enc)).Fnum_parts-int32(1)) {
  33654 			break
  33655 		}
  33656 		v2 = (*VP8BitWriter)(unsafe.Pointer(enc + 112 + uintptr(p)*48)).Fpos
  33657 		goto _3
  33658 	_3:
  33659 		part_size = v2
  33660 		if part_size >= uint64(libc.Int32FromInt32(1)<<libc.Int32FromInt32(24)) {
  33661 			return WebPEncodingSetError(tls, pic, int32(VP8_ENC_ERROR_PARTITION_OVERFLOW))
  33662 		}
  33663 		(**(**[21]uint8_t)(__ccgo_up(bp)))[int32(3)*p+0] = uint8(part_size >> libc.Int32FromInt32(0) & uint64(0xff))
  33664 		(**(**[21]uint8_t)(__ccgo_up(bp)))[int32(3)*p+int32(1)] = uint8(part_size >> libc.Int32FromInt32(8) & uint64(0xff))
  33665 		(**(**[21]uint8_t)(__ccgo_up(bp)))[int32(3)*p+int32(2)] = uint8(part_size >> libc.Int32FromInt32(16) & uint64(0xff))
  33666 		goto _1
  33667 	_1:
  33668 		;
  33669 		p = p + 1
  33670 	}
  33671 	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) {
  33672 		return WebPEncodingSetError(tls, pic, int32(VP8_ENC_ERROR_BAD_WRITE))
  33673 	}
  33674 	return int32(1)
  33675 }
  33676 
  33677 //------------------------------------------------------------------------------
  33678 
  33679 func GeneratePartition0(tls *libc.TLS, enc uintptr) (r int32) {
  33680 	var bw1, v1 uintptr
  33681 	var mb_size, v4, v5, v6 int32
  33682 	var nb_bits, pos1, pos2, pos3, v2 uint64_t
  33683 	_, _, _, _, _, _, _, _, _, _, _ = bw1, mb_size, nb_bits, pos1, pos2, pos3, v1, v2, v4, v5, v6
  33684 	bw1 = enc + 64
  33685 	mb_size = (*VP8Encoder)(unsafe.Pointer(enc)).Fmb_w * (*VP8Encoder)(unsafe.Pointer(enc)).Fmb_h
  33686 	v1 = bw1
  33687 	nb_bits = uint64(int32(8) + (*VP8BitWriter)(unsafe.Pointer(v1)).Fnb_bits)
  33688 	v2 = ((*VP8BitWriter)(unsafe.Pointer(v1)).Fpos+uint64((*VP8BitWriter)(unsafe.Pointer(v1)).Frun))*uint64(8) + nb_bits
  33689 	goto _3
  33690 _3:
  33691 	pos1 = v2
  33692 	if !(VP8BitWriterInit(tls, bw1, uint64(mb_size*int32(7)/int32(8))) != 0) { // ~7 bits per macroblock
  33693 		return WebPEncodingSetError(tls, (*VP8Encoder)(unsafe.Pointer(enc)).Fpic, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  33694 	}
  33695 	VP8PutBitUniform(tls, bw1, 0) // colorspace
  33696 	VP8PutBitUniform(tls, bw1, 0) // clamp type
  33697 	PutSegmentHeader(tls, bw1, enc)
  33698 	PutFilterHeader(tls, bw1, enc+16)
  33699 	if (*VP8Encoder)(unsafe.Pointer(enc)).Fnum_parts == int32(8) {
  33700 		v4 = int32(3)
  33701 	} else {
  33702 		if (*VP8Encoder)(unsafe.Pointer(enc)).Fnum_parts == int32(4) {
  33703 			v5 = int32(2)
  33704 		} else {
  33705 			if (*VP8Encoder)(unsafe.Pointer(enc)).Fnum_parts == int32(2) {
  33706 				v6 = int32(1)
  33707 			} else {
  33708 				v6 = 0
  33709 			}
  33710 			v5 = v6
  33711 		}
  33712 		v4 = v5
  33713 	}
  33714 	VP8PutBits(tls, bw1, uint32(v4), int32(2))
  33715 	PutQuant(tls, bw1, enc)
  33716 	VP8PutBitUniform(tls, bw1, 0) // no proba update
  33717 	VP8WriteProbas(tls, bw1, enc+3616)
  33718 	v1 = bw1
  33719 	nb_bits = uint64(int32(8) + (*VP8BitWriter)(unsafe.Pointer(v1)).Fnb_bits)
  33720 	v2 = ((*VP8BitWriter)(unsafe.Pointer(v1)).Fpos+uint64((*VP8BitWriter)(unsafe.Pointer(v1)).Frun))*uint64(8) + nb_bits
  33721 	goto _9
  33722 _9:
  33723 	pos2 = v2
  33724 	VP8CodeIntraModes(tls, enc)
  33725 	VP8BitWriterFinish(tls, bw1)
  33726 	v1 = bw1
  33727 	nb_bits = uint64(int32(8) + (*VP8BitWriter)(unsafe.Pointer(v1)).Fnb_bits)
  33728 	v2 = ((*VP8BitWriter)(unsafe.Pointer(v1)).Fpos+uint64((*VP8BitWriter)(unsafe.Pointer(v1)).Frun))*uint64(8) + nb_bits
  33729 	goto _12
  33730 _12:
  33731 	pos3 = v2
  33732 	if (*WebPPicture)(unsafe.Pointer((*VP8Encoder)(unsafe.Pointer(enc)).Fpic)).Fstats != 0 {
  33733 		**(**int32)(__ccgo_up((*WebPPicture)(unsafe.Pointer((*VP8Encoder)(unsafe.Pointer(enc)).Fpic)).Fstats + 36)) = int32((pos2 - pos1 + libc.Uint64FromInt32(7)) >> libc.Int32FromInt32(3))
  33734 		**(**int32)(__ccgo_up((*WebPPicture)(unsafe.Pointer((*VP8Encoder)(unsafe.Pointer(enc)).Fpic)).Fstats + 36 + 1*4)) = int32((pos3 - pos2 + libc.Uint64FromInt32(7)) >> libc.Int32FromInt32(3))
  33735 		(*WebPAuxStats)(unsafe.Pointer((*WebPPicture)(unsafe.Pointer((*VP8Encoder)(unsafe.Pointer(enc)).Fpic)).Fstats)).Falpha_data_size = int32((*VP8Encoder)(unsafe.Pointer(enc)).Falpha_data_size)
  33736 	}
  33737 	if (*VP8BitWriter)(unsafe.Pointer(bw1)).Ferror1 != 0 {
  33738 		return WebPEncodingSetError(tls, (*VP8Encoder)(unsafe.Pointer(enc)).Fpic, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  33739 	}
  33740 	return int32(1)
  33741 }
  33742 
  33743 func VP8EncFreeBitWriters(tls *libc.TLS, enc uintptr) {
  33744 	var p int32
  33745 	_ = p
  33746 	VP8BitWriterWipeOut(tls, enc+64)
  33747 	p = 0
  33748 	for {
  33749 		if !(p < (*VP8Encoder)(unsafe.Pointer(enc)).Fnum_parts) {
  33750 			break
  33751 		}
  33752 		VP8BitWriterWipeOut(tls, enc+112+uintptr(p)*48)
  33753 		goto _1
  33754 	_1:
  33755 		;
  33756 		p = p + 1
  33757 	}
  33758 }
  33759 
  33760 func VP8EncWrite(tls *libc.TLS, enc uintptr) (r int32) {
  33761 	var buf, bw2, part0, pic, v6 uintptr
  33762 	var final_percent, ok, p, percent_per_part, task_percent int32
  33763 	var pad, riff_size, size, size0, vp8_size, v1 size_t
  33764 	var padded_alpha_size uint32_t
  33765 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  33766 	pic = (*VP8Encoder)(unsafe.Pointer(enc)).Fpic
  33767 	bw2 = enc + 64
  33768 	task_percent = int32(19)
  33769 	percent_per_part = task_percent / (*VP8Encoder)(unsafe.Pointer(enc)).Fnum_parts
  33770 	final_percent = (*VP8Encoder)(unsafe.Pointer(enc)).Fpercent + task_percent
  33771 	ok = 0
  33772 	// Partition #0 with header and partition sizes
  33773 	ok = GeneratePartition0(tls, enc)
  33774 	if !(ok != 0) {
  33775 		return 0
  33776 	}
  33777 	// Compute VP8 size
  33778 	v1 = (*VP8BitWriter)(unsafe.Pointer(bw2)).Fpos
  33779 	goto _2
  33780 _2:
  33781 	vp8_size = uint64(VP8_FRAME_HEADER_SIZE) + v1 + uint64(int32(3)*((*VP8Encoder)(unsafe.Pointer(enc)).Fnum_parts-int32(1)))
  33782 	p = 0
  33783 	for {
  33784 		if !(p < (*VP8Encoder)(unsafe.Pointer(enc)).Fnum_parts) {
  33785 			break
  33786 		}
  33787 		v1 = (*VP8BitWriter)(unsafe.Pointer(enc + 112 + uintptr(p)*48)).Fpos
  33788 		goto _5
  33789 	_5:
  33790 		vp8_size = vp8_size + v1
  33791 		goto _3
  33792 	_3:
  33793 		;
  33794 		p = p + 1
  33795 	}
  33796 	pad = vp8_size & uint64(1)
  33797 	vp8_size = vp8_size + pad
  33798 	// Compute RIFF size
  33799 	// At the minimum it is: "WEBPVP8 nnnn" + VP8 data size.
  33800 	riff_size = uint64(libc.Int32FromInt32(TAG_SIZE)+libc.Int32FromInt32(CHUNK_HEADER_SIZE)) + vp8_size
  33801 	if IsVP8XNeeded(tls, enc) != 0 { // Add size for: VP8X header + data.
  33802 		riff_size = riff_size + uint64(libc.Int32FromInt32(CHUNK_HEADER_SIZE)+libc.Int32FromInt32(VP8X_CHUNK_SIZE))
  33803 	}
  33804 	if (*VP8Encoder)(unsafe.Pointer(enc)).Fhas_alpha != 0 { // Add size for: ALPH header + data.
  33805 		padded_alpha_size = (*VP8Encoder)(unsafe.Pointer(enc)).Falpha_data_size + (*VP8Encoder)(unsafe.Pointer(enc)).Falpha_data_size&uint32(1)
  33806 		riff_size = riff_size + uint64(uint32(CHUNK_HEADER_SIZE)+padded_alpha_size)
  33807 	}
  33808 	// RIFF size should fit in 32-bits.
  33809 	if riff_size > uint64(0xfffffffe) {
  33810 		return WebPEncodingSetError(tls, pic, int32(VP8_ENC_ERROR_FILE_TOO_BIG))
  33811 	}
  33812 	// Emit headers and partition #0
  33813 	v6 = (*VP8BitWriter)(unsafe.Pointer(bw2)).Fbuf
  33814 	goto _7
  33815 _7:
  33816 	part0 = v6
  33817 	v1 = (*VP8BitWriter)(unsafe.Pointer(bw2)).Fpos
  33818 	goto _9
  33819 _9:
  33820 	size0 = v1
  33821 	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)
  33822 	VP8BitWriterWipeOut(tls, bw2) // will free the internal buffer.
  33823 	// Token partitions
  33824 	p = 0
  33825 	for {
  33826 		if !(p < (*VP8Encoder)(unsafe.Pointer(enc)).Fnum_parts) {
  33827 			break
  33828 		}
  33829 		v6 = (*VP8BitWriter)(unsafe.Pointer(enc + 112 + uintptr(p)*48)).Fbuf
  33830 		goto _12
  33831 	_12:
  33832 		buf = v6
  33833 		v1 = (*VP8BitWriter)(unsafe.Pointer(enc + 112 + uintptr(p)*48)).Fpos
  33834 		goto _14
  33835 	_14:
  33836 		size = v1
  33837 		if size != 0 {
  33838 			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)
  33839 		}
  33840 		VP8BitWriterWipeOut(tls, enc+112+uintptr(p)*48) // will free the internal buffer.
  33841 		ok = libc.BoolInt32(ok != 0 && WebPReportProgress(tls, pic, (*VP8Encoder)(unsafe.Pointer(enc)).Fpercent+percent_per_part, enc+536) != 0)
  33842 		goto _10
  33843 	_10:
  33844 		;
  33845 		p = p + 1
  33846 	}
  33847 	// Padding byte
  33848 	if ok != 0 && pad != 0 {
  33849 		ok = PutPaddingByte(tls, pic)
  33850 	}
  33851 	(*VP8Encoder)(unsafe.Pointer(enc)).Fcoded_size = int32(libc.Uint64FromInt32(CHUNK_HEADER_SIZE) + riff_size)
  33852 	ok = libc.BoolInt32(ok != 0 && WebPReportProgress(tls, pic, final_percent, enc+536) != 0)
  33853 	if !(ok != 0) {
  33854 		WebPEncodingSetError(tls, pic, int32(VP8_ENC_ERROR_BAD_WRITE))
  33855 	}
  33856 	return ok
  33857 }
  33858 
  33859 const MIN_PAGE_SIZE = 8192
  33860 const SIZE_MAX14 = "_UI64_MAX"
  33861 
  33862 type VP8Tokens = struct {
  33863 	Fnext uintptr
  33864 }
  33865 
  33866 //------------------------------------------------------------------------------
  33867 
  33868 // Copyright 2011 Google Inc. All Rights Reserved.
  33869 //
  33870 // Use of this source code is governed by a BSD-style license
  33871 // that can be found in the COPYING file in the root of the source
  33872 // tree. An additional intellectual property rights grant can be found
  33873 // in the file PATENTS. All contributing project authors may
  33874 // be found in the AUTHORS file in the root of the source tree.
  33875 // -----------------------------------------------------------------------------
  33876 //
  33877 //   WebP encoder: internal header.
  33878 //
  33879 // Author: Skal (pascal.massimino@gmail.com)
  33880 
  33881 // Copyright 2011 Google Inc. All Rights Reserved.
  33882 //
  33883 // Use of this source code is governed by a BSD-style license
  33884 // that can be found in the COPYING file in the root of the source
  33885 // tree. An additional intellectual property rights grant can be found
  33886 // in the file PATENTS. All contributing project authors may
  33887 // be found in the AUTHORS file in the root of the source tree.
  33888 // -----------------------------------------------------------------------------
  33889 //
  33890 // Bit writing and boolean coder
  33891 //
  33892 // Author: Skal (pascal.massimino@gmail.com)
  33893 
  33894 // Copyright 2012 Google Inc. All Rights Reserved.
  33895 //
  33896 // Use of this source code is governed by a BSD-style license
  33897 // that can be found in the COPYING file in the root of the source
  33898 // tree. An additional intellectual property rights grant can be found
  33899 // in the file PATENTS. All contributing project authors may
  33900 // be found in the AUTHORS file in the root of the source tree.
  33901 // -----------------------------------------------------------------------------
  33902 //
  33903 // Misc. common utility functions
  33904 //
  33905 // Authors: Skal (pascal.massimino@gmail.com)
  33906 //          Urvang (urvang@google.com)
  33907 
  33908 // Copyright 2010 Google Inc. All Rights Reserved.
  33909 //
  33910 // Use of this source code is governed by a BSD-style license
  33911 // that can be found in the COPYING file in the root of the source
  33912 // tree. An additional intellectual property rights grant can be found
  33913 // in the file PATENTS. All contributing project authors may
  33914 // be found in the AUTHORS file in the root of the source tree.
  33915 // -----------------------------------------------------------------------------
  33916 //
  33917 //  Common types + memory wrappers
  33918 //
  33919 // Author: Skal (pascal.massimino@gmail.com)
  33920 
  33921 // we use pages to reduce the number of memcpy()
  33922 
  33923 type token_t = uint16
  33924 
  33925 // Token data is located in memory just after the 'next' field.
  33926 // This macro is used to return their address and hide the trick.
  33927 
  33928 //------------------------------------------------------------------------------
  33929 
  33930 func VP8TBufferInit(tls *libc.TLS, b uintptr, page_size int32) {
  33931 	var v1 int32
  33932 	_ = v1
  33933 	(*VP8TBuffer)(unsafe.Pointer(b)).Ftokens = libc.UintptrFromInt32(0)
  33934 	(*VP8TBuffer)(unsafe.Pointer(b)).Fpages = libc.UintptrFromInt32(0)
  33935 	(*VP8TBuffer)(unsafe.Pointer(b)).Flast_page = b
  33936 	(*VP8TBuffer)(unsafe.Pointer(b)).Fleft = 0
  33937 	if page_size < int32(MIN_PAGE_SIZE) {
  33938 		v1 = int32(MIN_PAGE_SIZE)
  33939 	} else {
  33940 		v1 = page_size
  33941 	}
  33942 	(*VP8TBuffer)(unsafe.Pointer(b)).Fpage_size = v1
  33943 	(*VP8TBuffer)(unsafe.Pointer(b)).Ferror1 = 0
  33944 }
  33945 
  33946 func VP8TBufferClear(tls *libc.TLS, b uintptr) {
  33947 	var next, p uintptr
  33948 	_, _ = next, p
  33949 	if b != libc.UintptrFromInt32(0) {
  33950 		p = (*VP8TBuffer)(unsafe.Pointer(b)).Fpages
  33951 		for p != libc.UintptrFromInt32(0) {
  33952 			next = (*VP8Tokens)(unsafe.Pointer(p)).Fnext
  33953 			WebPSafeFree(tls, p)
  33954 			p = next
  33955 		}
  33956 		VP8TBufferInit(tls, b, (*VP8TBuffer)(unsafe.Pointer(b)).Fpage_size)
  33957 	}
  33958 }
  33959 
  33960 func TBufferNewPage(tls *libc.TLS, b uintptr) (r int32) {
  33961 	var page uintptr
  33962 	var size size_t
  33963 	_, _ = page, size
  33964 	page = libc.UintptrFromInt32(0)
  33965 	if !((*VP8TBuffer)(unsafe.Pointer(b)).Ferror1 != 0) {
  33966 		size = uint64(8) + uint64((*VP8TBuffer)(unsafe.Pointer(b)).Fpage_size)*uint64(2)
  33967 		page = WebPSafeMalloc(tls, uint64(1), size)
  33968 	}
  33969 	if page == libc.UintptrFromInt32(0) {
  33970 		(*VP8TBuffer)(unsafe.Pointer(b)).Ferror1 = int32(1)
  33971 		return 0
  33972 	}
  33973 	(*VP8Tokens)(unsafe.Pointer(page)).Fnext = libc.UintptrFromInt32(0)
  33974 	**(**uintptr)(__ccgo_up((*VP8TBuffer)(unsafe.Pointer(b)).Flast_page)) = page
  33975 	(*VP8TBuffer)(unsafe.Pointer(b)).Flast_page = page
  33976 	(*VP8TBuffer)(unsafe.Pointer(b)).Fleft = (*VP8TBuffer)(unsafe.Pointer(b)).Fpage_size
  33977 	(*VP8TBuffer)(unsafe.Pointer(b)).Ftokens = page + 1*8
  33978 	return int32(1)
  33979 }
  33980 
  33981 //------------------------------------------------------------------------------
  33982 
  33983 func AddToken(tls *libc.TLS, b uintptr, bit1 uint32_t, proba_idx uint32_t, stats1 uintptr) (r uint32_t) {
  33984 	var p proba_t
  33985 	var slot, v1 int32
  33986 	var v2 uintptr
  33987 	_, _, _, _ = p, slot, v1, v2
  33988 	if (*VP8TBuffer)(unsafe.Pointer(b)).Fleft > 0 || TBufferNewPage(tls, b) != 0 {
  33989 		v2 = b + 24
  33990 		*(*int32)(unsafe.Pointer(v2)) = *(*int32)(unsafe.Pointer(v2)) - 1
  33991 		v1 = *(*int32)(unsafe.Pointer(v2))
  33992 		slot = v1
  33993 		**(**uint16_t)(__ccgo_up((*VP8TBuffer)(unsafe.Pointer(b)).Ftokens + uintptr(slot)*2)) = uint16(bit1<<libc.Int32FromInt32(15) | proba_idx)
  33994 	}
  33995 	v1 = int32(bit1)
  33996 	v2 = stats1
  33997 	p = **(**proba_t)(__ccgo_up(v2))
  33998 	if p >= libc.Uint32FromUint32(0xfffe0000) {
  33999 		p = (p + uint32(1)) >> int32(1) & uint32(0x7fff7fff)
  34000 	}
  34001 	p = p + (uint32(0x00010000) + uint32(v1))
  34002 	**(**proba_t)(__ccgo_up(v2)) = p
  34003 	_ = v1
  34004 	goto _5
  34005 _5:
  34006 	;
  34007 	return bit1
  34008 }
  34009 
  34010 func AddConstantToken(tls *libc.TLS, b uintptr, bit uint32_t, proba uint32_t) {
  34011 	var slot, v1 int32
  34012 	var v2 uintptr
  34013 	_, _, _ = slot, v1, v2
  34014 	if (*VP8TBuffer)(unsafe.Pointer(b)).Fleft > 0 || TBufferNewPage(tls, b) != 0 {
  34015 		v2 = b + 24
  34016 		*(*int32)(unsafe.Pointer(v2)) = *(*int32)(unsafe.Pointer(v2)) - 1
  34017 		v1 = *(*int32)(unsafe.Pointer(v2))
  34018 		slot = v1
  34019 		**(**uint16_t)(__ccgo_up((*VP8TBuffer)(unsafe.Pointer(b)).Ftokens + uintptr(slot)*2)) = uint16(bit<<libc.Int32FromInt32(15) | libc.Uint32FromUint32(1)<<libc.Int32FromInt32(14) | proba)
  34020 	}
  34021 }
  34022 
  34023 func VP8RecordCoeffTokens(tls *libc.TLS, ctx int32, res uintptr, tokens uintptr) (r int32) {
  34024 	var base_id, residue, v uint32_t
  34025 	var c, coeff_type, last, mask, n, sign, v1, v2 int32
  34026 	var coeffs, s, tab, v3 uintptr
  34027 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = base_id, c, coeff_type, coeffs, last, mask, n, residue, s, sign, tab, v, v1, v2, v3
  34028 	coeffs = (*VP8Residual)(unsafe.Pointer(res)).Fcoeffs
  34029 	coeff_type = (*VP8Residual)(unsafe.Pointer(res)).Fcoeff_type
  34030 	last = (*VP8Residual)(unsafe.Pointer(res)).Flast
  34031 	n = (*VP8Residual)(unsafe.Pointer(res)).Ffirst
  34032 	base_id = uint32(int32(NUM_PROBAS) * (ctx + int32(NUM_CTX)*(n+int32(NUM_BANDS)*coeff_type)))
  34033 	// should be stats[VP8EncBands[n]], but it's equivalent for n=0 or 1
  34034 	s = (*VP8Residual)(unsafe.Pointer(res)).Fstats + uintptr(n)*132 + uintptr(ctx)*44
  34035 	if !(AddToken(tls, tokens, libc.BoolUint32(last >= 0), base_id+uint32(0), s+uintptr(0)*4) != 0) {
  34036 		return 0
  34037 	}
  34038 	for n < int32(16) {
  34039 		v1 = n
  34040 		n = n + 1
  34041 		c = int32(**(**int16_t)(__ccgo_up(coeffs + uintptr(v1)*2)))
  34042 		sign = libc.BoolInt32(c < 0)
  34043 		if sign != 0 {
  34044 			v2 = -c
  34045 		} else {
  34046 			v2 = c
  34047 		}
  34048 		v = uint32(v2)
  34049 		if !(AddToken(tls, tokens, libc.BoolUint32(v != uint32(0)), base_id+uint32(1), s+uintptr(1)*4) != 0) {
  34050 			base_id = uint32(int32(NUM_PROBAS) * (libc.Int32FromInt32(0) + int32(NUM_CTX)*(int32(VP8EncBands[n])+int32(NUM_BANDS)*coeff_type))) // ctx=0
  34051 			s = (*VP8Residual)(unsafe.Pointer(res)).Fstats + uintptr(VP8EncBands[n])*132
  34052 			continue
  34053 		}
  34054 		if !(AddToken(tls, tokens, libc.BoolUint32(v > uint32(1)), base_id+uint32(2), s+uintptr(2)*4) != 0) {
  34055 			base_id = uint32(int32(NUM_PROBAS) * (libc.Int32FromInt32(1) + int32(NUM_CTX)*(int32(VP8EncBands[n])+int32(NUM_BANDS)*coeff_type))) // ctx=1
  34056 			s = (*VP8Residual)(unsafe.Pointer(res)).Fstats + uintptr(VP8EncBands[n])*132 + 1*44
  34057 		} else {
  34058 			if !(AddToken(tls, tokens, libc.BoolUint32(v > uint32(4)), base_id+uint32(3), s+uintptr(3)*4) != 0) {
  34059 				if AddToken(tls, tokens, libc.BoolUint32(v != uint32(2)), base_id+uint32(4), s+uintptr(4)*4) != 0 {
  34060 					AddToken(tls, tokens, libc.BoolUint32(v == uint32(4)), base_id+uint32(5), s+uintptr(5)*4)
  34061 				}
  34062 			} else {
  34063 				if !(AddToken(tls, tokens, libc.BoolUint32(v > uint32(10)), base_id+uint32(6), s+uintptr(6)*4) != 0) {
  34064 					if !(AddToken(tls, tokens, libc.BoolUint32(v > uint32(6)), base_id+uint32(7), s+uintptr(7)*4) != 0) {
  34065 						AddConstantToken(tls, tokens, libc.BoolUint32(v == uint32(6)), uint32(159))
  34066 					} else {
  34067 						AddConstantToken(tls, tokens, libc.BoolUint32(v >= uint32(9)), uint32(165))
  34068 						AddConstantToken(tls, tokens, libc.BoolUint32(!(v&libc.Uint32FromInt32(1) != 0)), uint32(145))
  34069 					}
  34070 				} else {
  34071 					residue = v - uint32(3)
  34072 					if residue < uint32(libc.Int32FromInt32(8)<<libc.Int32FromInt32(1)) { // VP8Cat3  (3b)
  34073 						AddToken(tls, tokens, uint32(0), base_id+uint32(8), s+uintptr(8)*4)
  34074 						AddToken(tls, tokens, uint32(0), base_id+uint32(9), s+uintptr(9)*4)
  34075 						residue = residue - uint32(libc.Int32FromInt32(8)<<libc.Int32FromInt32(0))
  34076 						mask = libc.Int32FromInt32(1) << libc.Int32FromInt32(2)
  34077 						tab = uintptr(unsafe.Pointer(&VP8Cat3))
  34078 					} else {
  34079 						if residue < uint32(libc.Int32FromInt32(8)<<libc.Int32FromInt32(2)) { // VP8Cat4  (4b)
  34080 							AddToken(tls, tokens, uint32(0), base_id+uint32(8), s+uintptr(8)*4)
  34081 							AddToken(tls, tokens, uint32(1), base_id+uint32(9), s+uintptr(9)*4)
  34082 							residue = residue - uint32(libc.Int32FromInt32(8)<<libc.Int32FromInt32(1))
  34083 							mask = libc.Int32FromInt32(1) << libc.Int32FromInt32(3)
  34084 							tab = uintptr(unsafe.Pointer(&VP8Cat4))
  34085 						} else {
  34086 							if residue < uint32(libc.Int32FromInt32(8)<<libc.Int32FromInt32(3)) { // VP8Cat5  (5b)
  34087 								AddToken(tls, tokens, uint32(1), base_id+uint32(8), s+uintptr(8)*4)
  34088 								AddToken(tls, tokens, uint32(0), base_id+uint32(10), s+uintptr(9)*4)
  34089 								residue = residue - uint32(libc.Int32FromInt32(8)<<libc.Int32FromInt32(2))
  34090 								mask = libc.Int32FromInt32(1) << libc.Int32FromInt32(4)
  34091 								tab = uintptr(unsafe.Pointer(&VP8Cat5))
  34092 							} else { // VP8Cat6 (11b)
  34093 								AddToken(tls, tokens, uint32(1), base_id+uint32(8), s+uintptr(8)*4)
  34094 								AddToken(tls, tokens, uint32(1), base_id+uint32(10), s+uintptr(9)*4)
  34095 								residue = residue - uint32(libc.Int32FromInt32(8)<<libc.Int32FromInt32(3))
  34096 								mask = libc.Int32FromInt32(1) << libc.Int32FromInt32(10)
  34097 								tab = uintptr(unsafe.Pointer(&VP8Cat6))
  34098 							}
  34099 						}
  34100 					}
  34101 					for mask != 0 {
  34102 						v3 = tab
  34103 						tab = tab + 1
  34104 						AddConstantToken(tls, tokens, libc.BoolUint32(!!(residue&uint32(mask) != 0)), uint32(**(**uint8_t)(__ccgo_up(v3))))
  34105 						mask = mask >> int32(1)
  34106 					}
  34107 				}
  34108 			}
  34109 			base_id = uint32(int32(NUM_PROBAS) * (libc.Int32FromInt32(2) + int32(NUM_CTX)*(int32(VP8EncBands[n])+int32(NUM_BANDS)*coeff_type))) // ctx=2
  34110 			s = (*VP8Residual)(unsafe.Pointer(res)).Fstats + uintptr(VP8EncBands[n])*132 + 2*44
  34111 		}
  34112 		AddConstantToken(tls, tokens, uint32(sign), uint32(128))
  34113 		if n == int32(16) || !(AddToken(tls, tokens, libc.BoolUint32(n <= last), base_id+uint32(0), s+uintptr(0)*4) != 0) {
  34114 			return int32(1) // EOB
  34115 		}
  34116 	}
  34117 	return int32(1)
  34118 }
  34119 
  34120 //------------------------------------------------------------------------------
  34121 // Final coding pass, with known probabilities
  34122 
  34123 func VP8EmitTokens(tls *libc.TLS, b uintptr, bw uintptr, probas uintptr, final_pass int32) (r int32) {
  34124 	var N, bit, n, v1, v2 int32
  34125 	var next, p, tokens uintptr
  34126 	var token token_t
  34127 	_, _, _, _, _, _, _, _, _ = N, bit, n, next, p, token, tokens, v1, v2
  34128 	p = (*VP8TBuffer)(unsafe.Pointer(b)).Fpages
  34129 	for p != libc.UintptrFromInt32(0) {
  34130 		next = (*VP8Tokens)(unsafe.Pointer(p)).Fnext
  34131 		if next == libc.UintptrFromInt32(0) {
  34132 			v1 = (*VP8TBuffer)(unsafe.Pointer(b)).Fleft
  34133 		} else {
  34134 			v1 = 0
  34135 		}
  34136 		N = v1
  34137 		n = (*VP8TBuffer)(unsafe.Pointer(b)).Fpage_size
  34138 		tokens = p + 1*8
  34139 		for {
  34140 			v2 = n
  34141 			n = n - 1
  34142 			if !(v2 > N) {
  34143 				break
  34144 			}
  34145 			token = **(**token_t)(__ccgo_up(tokens + uintptr(n)*2))
  34146 			bit = int32(token) >> int32(15) & int32(1)
  34147 			if uint32(token)&(libc.Uint32FromUint32(1)<<libc.Int32FromInt32(14)) != 0 {
  34148 				VP8PutBit(tls, bw, bit, int32(uint32(token)&uint32(0xff))) // constant proba
  34149 			} else {
  34150 				VP8PutBit(tls, bw, bit, int32(**(**uint8_t)(__ccgo_up(probas + uintptr(uint32(token)&uint32(0x3fff))))))
  34151 			}
  34152 		}
  34153 		if final_pass != 0 {
  34154 			WebPSafeFree(tls, p)
  34155 		}
  34156 		p = next
  34157 	}
  34158 	if final_pass != 0 {
  34159 		(*VP8TBuffer)(unsafe.Pointer(b)).Fpages = libc.UintptrFromInt32(0)
  34160 	}
  34161 	return int32(1)
  34162 }
  34163 
  34164 // C documentation
  34165 //
  34166 //	// Size estimation
  34167 func VP8EstimateTokenSize(tls *libc.TLS, b uintptr, probas uintptr) (r size_t) {
  34168 	var N, bit1, n, v1, v2, v4, v6 int32
  34169 	var next, p, tokens uintptr
  34170 	var size size_t
  34171 	var token token_t
  34172 	var v3 uint8_t
  34173 	_, _, _, _, _, _, _, _, _, _, _, _, _ = N, bit1, n, next, p, size, token, tokens, v1, v2, v3, v4, v6
  34174 	size = uint64(0)
  34175 	p = (*VP8TBuffer)(unsafe.Pointer(b)).Fpages
  34176 	for p != libc.UintptrFromInt32(0) {
  34177 		next = (*VP8Tokens)(unsafe.Pointer(p)).Fnext
  34178 		if next == libc.UintptrFromInt32(0) {
  34179 			v1 = (*VP8TBuffer)(unsafe.Pointer(b)).Fleft
  34180 		} else {
  34181 			v1 = 0
  34182 		}
  34183 		N = v1
  34184 		n = (*VP8TBuffer)(unsafe.Pointer(b)).Fpage_size
  34185 		tokens = p + 1*8
  34186 		for {
  34187 			v2 = n
  34188 			n = n - 1
  34189 			if !(v2 > N) {
  34190 				break
  34191 			}
  34192 			token = **(**token_t)(__ccgo_up(tokens + uintptr(n)*2))
  34193 			bit1 = int32(token) & (libc.Int32FromInt32(1) << libc.Int32FromInt32(15))
  34194 			if uint32(token)&(libc.Uint32FromUint32(1)<<libc.Int32FromInt32(14)) != 0 {
  34195 				v3 = uint8(uint32(token) & uint32(0xff))
  34196 				if !(bit1 != 0) {
  34197 					v6 = int32(VP8EntropyCost[v3])
  34198 				} else {
  34199 					v6 = int32(VP8EntropyCost[int32(255)-int32(v3)])
  34200 				}
  34201 				v4 = v6
  34202 				goto _5
  34203 			_5:
  34204 				size = size + uint64(v4)
  34205 			} else {
  34206 				v3 = **(**uint8_t)(__ccgo_up(probas + uintptr(uint32(token)&uint32(0x3fff))))
  34207 				if !(bit1 != 0) {
  34208 					v2 = int32(VP8EntropyCost[v3])
  34209 				} else {
  34210 					v2 = int32(VP8EntropyCost[int32(255)-int32(v3)])
  34211 				}
  34212 				v1 = v2
  34213 				goto _9
  34214 			_9:
  34215 				size = size + uint64(v1)
  34216 			}
  34217 		}
  34218 		p = next
  34219 	}
  34220 	return size
  34221 }
  34222 
  34223 const SIZE_MAX15 = "UINT64_MAX"
  34224 
  34225 func VP8DefaultProbas(tls *libc.TLS, enc uintptr) {
  34226 	var probas uintptr
  34227 	_ = probas
  34228 	probas = enc + 3616
  34229 	(*VP8EncProba)(unsafe.Pointer(probas)).Fuse_skip_proba = 0
  34230 	libc.Xmemset(tls, probas, libc.Int32FromUint32(255), uint64(3))
  34231 	libc.Xmemcpy(tls, probas+4, uintptr(unsafe.Pointer(&VP8CoeffsProba0)), uint64(1056))
  34232 	// Note: we could hard-code the level_costs corresponding to VP8CoeffsProba0,
  34233 	// but that's ~11k of static data. Better call VP8CalculateLevelCosts() later.
  34234 	(*VP8EncProba)(unsafe.Pointer(probas)).Fdirty = int32(1)
  34235 }
  34236 
  34237 // C documentation
  34238 //
  34239 //	// Paragraph 11.5.  900bytes.
  34240 var kBModesProba1 = [10][10][9]uint8_t{
  34241 	0: {
  34242 		0: {
  34243 			0: uint8(231),
  34244 			1: uint8(120),
  34245 			2: uint8(48),
  34246 			3: uint8(89),
  34247 			4: uint8(115),
  34248 			5: uint8(113),
  34249 			6: uint8(120),
  34250 			7: uint8(152),
  34251 			8: uint8(112),
  34252 		},
  34253 		1: {
  34254 			0: uint8(152),
  34255 			1: uint8(179),
  34256 			2: uint8(64),
  34257 			3: uint8(126),
  34258 			4: uint8(170),
  34259 			5: uint8(118),
  34260 			6: uint8(46),
  34261 			7: uint8(70),
  34262 			8: uint8(95),
  34263 		},
  34264 		2: {
  34265 			0: uint8(175),
  34266 			1: uint8(69),
  34267 			2: uint8(143),
  34268 			3: uint8(80),
  34269 			4: uint8(85),
  34270 			5: uint8(82),
  34271 			6: uint8(72),
  34272 			7: uint8(155),
  34273 			8: uint8(103),
  34274 		},
  34275 		3: {
  34276 			0: uint8(56),
  34277 			1: uint8(58),
  34278 			2: uint8(10),
  34279 			3: uint8(171),
  34280 			4: uint8(218),
  34281 			5: uint8(189),
  34282 			6: uint8(17),
  34283 			7: uint8(13),
  34284 			8: uint8(152),
  34285 		},
  34286 		4: {
  34287 			0: uint8(114),
  34288 			1: uint8(26),
  34289 			2: uint8(17),
  34290 			3: uint8(163),
  34291 			4: uint8(44),
  34292 			5: uint8(195),
  34293 			6: uint8(21),
  34294 			7: uint8(10),
  34295 			8: uint8(173),
  34296 		},
  34297 		5: {
  34298 			0: uint8(121),
  34299 			1: uint8(24),
  34300 			2: uint8(80),
  34301 			3: uint8(195),
  34302 			4: uint8(26),
  34303 			5: uint8(62),
  34304 			6: uint8(44),
  34305 			7: uint8(64),
  34306 			8: uint8(85),
  34307 		},
  34308 		6: {
  34309 			0: uint8(144),
  34310 			1: uint8(71),
  34311 			2: uint8(10),
  34312 			3: uint8(38),
  34313 			4: uint8(171),
  34314 			5: uint8(213),
  34315 			6: uint8(144),
  34316 			7: uint8(34),
  34317 			8: uint8(26),
  34318 		},
  34319 		7: {
  34320 			0: uint8(170),
  34321 			1: uint8(46),
  34322 			2: uint8(55),
  34323 			3: uint8(19),
  34324 			4: uint8(136),
  34325 			5: uint8(160),
  34326 			6: uint8(33),
  34327 			7: uint8(206),
  34328 			8: uint8(71),
  34329 		},
  34330 		8: {
  34331 			0: uint8(63),
  34332 			1: uint8(20),
  34333 			2: uint8(8),
  34334 			3: uint8(114),
  34335 			4: uint8(114),
  34336 			5: uint8(208),
  34337 			6: uint8(12),
  34338 			7: uint8(9),
  34339 			8: uint8(226),
  34340 		},
  34341 		9: {
  34342 			0: uint8(81),
  34343 			1: uint8(40),
  34344 			2: uint8(11),
  34345 			3: uint8(96),
  34346 			4: uint8(182),
  34347 			5: uint8(84),
  34348 			6: uint8(29),
  34349 			7: uint8(16),
  34350 			8: uint8(36),
  34351 		},
  34352 	},
  34353 	1: {
  34354 		0: {
  34355 			0: uint8(134),
  34356 			1: uint8(183),
  34357 			2: uint8(89),
  34358 			3: uint8(137),
  34359 			4: uint8(98),
  34360 			5: uint8(101),
  34361 			6: uint8(106),
  34362 			7: uint8(165),
  34363 			8: uint8(148),
  34364 		},
  34365 		1: {
  34366 			0: uint8(72),
  34367 			1: uint8(187),
  34368 			2: uint8(100),
  34369 			3: uint8(130),
  34370 			4: uint8(157),
  34371 			5: uint8(111),
  34372 			6: uint8(32),
  34373 			7: uint8(75),
  34374 			8: uint8(80),
  34375 		},
  34376 		2: {
  34377 			0: uint8(66),
  34378 			1: uint8(102),
  34379 			2: uint8(167),
  34380 			3: uint8(99),
  34381 			4: uint8(74),
  34382 			5: uint8(62),
  34383 			6: uint8(40),
  34384 			7: uint8(234),
  34385 			8: uint8(128),
  34386 		},
  34387 		3: {
  34388 			0: uint8(41),
  34389 			1: uint8(53),
  34390 			2: uint8(9),
  34391 			3: uint8(178),
  34392 			4: uint8(241),
  34393 			5: uint8(141),
  34394 			6: uint8(26),
  34395 			7: uint8(8),
  34396 			8: uint8(107),
  34397 		},
  34398 		4: {
  34399 			0: uint8(74),
  34400 			1: uint8(43),
  34401 			2: uint8(26),
  34402 			3: uint8(146),
  34403 			4: uint8(73),
  34404 			5: uint8(166),
  34405 			6: uint8(49),
  34406 			7: uint8(23),
  34407 			8: uint8(157),
  34408 		},
  34409 		5: {
  34410 			0: uint8(65),
  34411 			1: uint8(38),
  34412 			2: uint8(105),
  34413 			3: uint8(160),
  34414 			4: uint8(51),
  34415 			5: uint8(52),
  34416 			6: uint8(31),
  34417 			7: uint8(115),
  34418 			8: uint8(128),
  34419 		},
  34420 		6: {
  34421 			0: uint8(104),
  34422 			1: uint8(79),
  34423 			2: uint8(12),
  34424 			3: uint8(27),
  34425 			4: uint8(217),
  34426 			5: uint8(255),
  34427 			6: uint8(87),
  34428 			7: uint8(17),
  34429 			8: uint8(7),
  34430 		},
  34431 		7: {
  34432 			0: uint8(87),
  34433 			1: uint8(68),
  34434 			2: uint8(71),
  34435 			3: uint8(44),
  34436 			4: uint8(114),
  34437 			5: uint8(51),
  34438 			6: uint8(15),
  34439 			7: uint8(186),
  34440 			8: uint8(23),
  34441 		},
  34442 		8: {
  34443 			0: uint8(47),
  34444 			1: uint8(41),
  34445 			2: uint8(14),
  34446 			3: uint8(110),
  34447 			4: uint8(182),
  34448 			5: uint8(183),
  34449 			6: uint8(21),
  34450 			7: uint8(17),
  34451 			8: uint8(194),
  34452 		},
  34453 		9: {
  34454 			0: uint8(66),
  34455 			1: uint8(45),
  34456 			2: uint8(25),
  34457 			3: uint8(102),
  34458 			4: uint8(197),
  34459 			5: uint8(189),
  34460 			6: uint8(23),
  34461 			7: uint8(18),
  34462 			8: uint8(22),
  34463 		},
  34464 	},
  34465 	2: {
  34466 		0: {
  34467 			0: uint8(88),
  34468 			1: uint8(88),
  34469 			2: uint8(147),
  34470 			3: uint8(150),
  34471 			4: uint8(42),
  34472 			5: uint8(46),
  34473 			6: uint8(45),
  34474 			7: uint8(196),
  34475 			8: uint8(205),
  34476 		},
  34477 		1: {
  34478 			0: uint8(43),
  34479 			1: uint8(97),
  34480 			2: uint8(183),
  34481 			3: uint8(117),
  34482 			4: uint8(85),
  34483 			5: uint8(38),
  34484 			6: uint8(35),
  34485 			7: uint8(179),
  34486 			8: uint8(61),
  34487 		},
  34488 		2: {
  34489 			0: uint8(39),
  34490 			1: uint8(53),
  34491 			2: uint8(200),
  34492 			3: uint8(87),
  34493 			4: uint8(26),
  34494 			5: uint8(21),
  34495 			6: uint8(43),
  34496 			7: uint8(232),
  34497 			8: uint8(171),
  34498 		},
  34499 		3: {
  34500 			0: uint8(56),
  34501 			1: uint8(34),
  34502 			2: uint8(51),
  34503 			3: uint8(104),
  34504 			4: uint8(114),
  34505 			5: uint8(102),
  34506 			6: uint8(29),
  34507 			7: uint8(93),
  34508 			8: uint8(77),
  34509 		},
  34510 		4: {
  34511 			0: uint8(39),
  34512 			1: uint8(28),
  34513 			2: uint8(85),
  34514 			3: uint8(171),
  34515 			4: uint8(58),
  34516 			5: uint8(165),
  34517 			6: uint8(90),
  34518 			7: uint8(98),
  34519 			8: uint8(64),
  34520 		},
  34521 		5: {
  34522 			0: uint8(34),
  34523 			1: uint8(22),
  34524 			2: uint8(116),
  34525 			3: uint8(206),
  34526 			4: uint8(23),
  34527 			5: uint8(34),
  34528 			6: uint8(43),
  34529 			7: uint8(166),
  34530 			8: uint8(73),
  34531 		},
  34532 		6: {
  34533 			0: uint8(107),
  34534 			1: uint8(54),
  34535 			2: uint8(32),
  34536 			3: uint8(26),
  34537 			4: uint8(51),
  34538 			5: uint8(1),
  34539 			6: uint8(81),
  34540 			7: uint8(43),
  34541 			8: uint8(31),
  34542 		},
  34543 		7: {
  34544 			0: uint8(68),
  34545 			1: uint8(25),
  34546 			2: uint8(106),
  34547 			3: uint8(22),
  34548 			4: uint8(64),
  34549 			5: uint8(171),
  34550 			6: uint8(36),
  34551 			7: uint8(225),
  34552 			8: uint8(114),
  34553 		},
  34554 		8: {
  34555 			0: uint8(34),
  34556 			1: uint8(19),
  34557 			2: uint8(21),
  34558 			3: uint8(102),
  34559 			4: uint8(132),
  34560 			5: uint8(188),
  34561 			6: uint8(16),
  34562 			7: uint8(76),
  34563 			8: uint8(124),
  34564 		},
  34565 		9: {
  34566 			0: uint8(62),
  34567 			1: uint8(18),
  34568 			2: uint8(78),
  34569 			3: uint8(95),
  34570 			4: uint8(85),
  34571 			5: uint8(57),
  34572 			6: uint8(50),
  34573 			7: uint8(48),
  34574 			8: uint8(51),
  34575 		},
  34576 	},
  34577 	3: {
  34578 		0: {
  34579 			0: uint8(193),
  34580 			1: uint8(101),
  34581 			2: uint8(35),
  34582 			3: uint8(159),
  34583 			4: uint8(215),
  34584 			5: uint8(111),
  34585 			6: uint8(89),
  34586 			7: uint8(46),
  34587 			8: uint8(111),
  34588 		},
  34589 		1: {
  34590 			0: uint8(60),
  34591 			1: uint8(148),
  34592 			2: uint8(31),
  34593 			3: uint8(172),
  34594 			4: uint8(219),
  34595 			5: uint8(228),
  34596 			6: uint8(21),
  34597 			7: uint8(18),
  34598 			8: uint8(111),
  34599 		},
  34600 		2: {
  34601 			0: uint8(112),
  34602 			1: uint8(113),
  34603 			2: uint8(77),
  34604 			3: uint8(85),
  34605 			4: uint8(179),
  34606 			5: uint8(255),
  34607 			6: uint8(38),
  34608 			7: uint8(120),
  34609 			8: uint8(114),
  34610 		},
  34611 		3: {
  34612 			0: uint8(40),
  34613 			1: uint8(42),
  34614 			2: uint8(1),
  34615 			3: uint8(196),
  34616 			4: uint8(245),
  34617 			5: uint8(209),
  34618 			6: uint8(10),
  34619 			7: uint8(25),
  34620 			8: uint8(109),
  34621 		},
  34622 		4: {
  34623 			0: uint8(88),
  34624 			1: uint8(43),
  34625 			2: uint8(29),
  34626 			3: uint8(140),
  34627 			4: uint8(166),
  34628 			5: uint8(213),
  34629 			6: uint8(37),
  34630 			7: uint8(43),
  34631 			8: uint8(154),
  34632 		},
  34633 		5: {
  34634 			0: uint8(61),
  34635 			1: uint8(63),
  34636 			2: uint8(30),
  34637 			3: uint8(155),
  34638 			4: uint8(67),
  34639 			5: uint8(45),
  34640 			6: uint8(68),
  34641 			7: uint8(1),
  34642 			8: uint8(209),
  34643 		},
  34644 		6: {
  34645 			0: uint8(100),
  34646 			1: uint8(80),
  34647 			2: uint8(8),
  34648 			3: uint8(43),
  34649 			4: uint8(154),
  34650 			5: uint8(1),
  34651 			6: uint8(51),
  34652 			7: uint8(26),
  34653 			8: uint8(71),
  34654 		},
  34655 		7: {
  34656 			0: uint8(142),
  34657 			1: uint8(78),
  34658 			2: uint8(78),
  34659 			3: uint8(16),
  34660 			4: uint8(255),
  34661 			5: uint8(128),
  34662 			6: uint8(34),
  34663 			7: uint8(197),
  34664 			8: uint8(171),
  34665 		},
  34666 		8: {
  34667 			0: uint8(41),
  34668 			1: uint8(40),
  34669 			2: uint8(5),
  34670 			3: uint8(102),
  34671 			4: uint8(211),
  34672 			5: uint8(183),
  34673 			6: uint8(4),
  34674 			7: uint8(1),
  34675 			8: uint8(221),
  34676 		},
  34677 		9: {
  34678 			0: uint8(51),
  34679 			1: uint8(50),
  34680 			2: uint8(17),
  34681 			3: uint8(168),
  34682 			4: uint8(209),
  34683 			5: uint8(192),
  34684 			6: uint8(23),
  34685 			7: uint8(25),
  34686 			8: uint8(82),
  34687 		},
  34688 	},
  34689 	4: {
  34690 		0: {
  34691 			0: uint8(138),
  34692 			1: uint8(31),
  34693 			2: uint8(36),
  34694 			3: uint8(171),
  34695 			4: uint8(27),
  34696 			5: uint8(166),
  34697 			6: uint8(38),
  34698 			7: uint8(44),
  34699 			8: uint8(229),
  34700 		},
  34701 		1: {
  34702 			0: uint8(67),
  34703 			1: uint8(87),
  34704 			2: uint8(58),
  34705 			3: uint8(169),
  34706 			4: uint8(82),
  34707 			5: uint8(115),
  34708 			6: uint8(26),
  34709 			7: uint8(59),
  34710 			8: uint8(179),
  34711 		},
  34712 		2: {
  34713 			0: uint8(63),
  34714 			1: uint8(59),
  34715 			2: uint8(90),
  34716 			3: uint8(180),
  34717 			4: uint8(59),
  34718 			5: uint8(166),
  34719 			6: uint8(93),
  34720 			7: uint8(73),
  34721 			8: uint8(154),
  34722 		},
  34723 		3: {
  34724 			0: uint8(40),
  34725 			1: uint8(40),
  34726 			2: uint8(21),
  34727 			3: uint8(116),
  34728 			4: uint8(143),
  34729 			5: uint8(209),
  34730 			6: uint8(34),
  34731 			7: uint8(39),
  34732 			8: uint8(175),
  34733 		},
  34734 		4: {
  34735 			0: uint8(47),
  34736 			1: uint8(15),
  34737 			2: uint8(16),
  34738 			3: uint8(183),
  34739 			4: uint8(34),
  34740 			5: uint8(223),
  34741 			6: uint8(49),
  34742 			7: uint8(45),
  34743 			8: uint8(183),
  34744 		},
  34745 		5: {
  34746 			0: uint8(46),
  34747 			1: uint8(17),
  34748 			2: uint8(33),
  34749 			3: uint8(183),
  34750 			4: uint8(6),
  34751 			5: uint8(98),
  34752 			6: uint8(15),
  34753 			7: uint8(32),
  34754 			8: uint8(183),
  34755 		},
  34756 		6: {
  34757 			0: uint8(57),
  34758 			1: uint8(46),
  34759 			2: uint8(22),
  34760 			3: uint8(24),
  34761 			4: uint8(128),
  34762 			5: uint8(1),
  34763 			6: uint8(54),
  34764 			7: uint8(17),
  34765 			8: uint8(37),
  34766 		},
  34767 		7: {
  34768 			0: uint8(65),
  34769 			1: uint8(32),
  34770 			2: uint8(73),
  34771 			3: uint8(115),
  34772 			4: uint8(28),
  34773 			5: uint8(128),
  34774 			6: uint8(23),
  34775 			7: uint8(128),
  34776 			8: uint8(205),
  34777 		},
  34778 		8: {
  34779 			0: uint8(40),
  34780 			1: uint8(3),
  34781 			2: uint8(9),
  34782 			3: uint8(115),
  34783 			4: uint8(51),
  34784 			5: uint8(192),
  34785 			6: uint8(18),
  34786 			7: uint8(6),
  34787 			8: uint8(223),
  34788 		},
  34789 		9: {
  34790 			0: uint8(87),
  34791 			1: uint8(37),
  34792 			2: uint8(9),
  34793 			3: uint8(115),
  34794 			4: uint8(59),
  34795 			5: uint8(77),
  34796 			6: uint8(64),
  34797 			7: uint8(21),
  34798 			8: uint8(47),
  34799 		},
  34800 	},
  34801 	5: {
  34802 		0: {
  34803 			0: uint8(104),
  34804 			1: uint8(55),
  34805 			2: uint8(44),
  34806 			3: uint8(218),
  34807 			4: uint8(9),
  34808 			5: uint8(54),
  34809 			6: uint8(53),
  34810 			7: uint8(130),
  34811 			8: uint8(226),
  34812 		},
  34813 		1: {
  34814 			0: uint8(64),
  34815 			1: uint8(90),
  34816 			2: uint8(70),
  34817 			3: uint8(205),
  34818 			4: uint8(40),
  34819 			5: uint8(41),
  34820 			6: uint8(23),
  34821 			7: uint8(26),
  34822 			8: uint8(57),
  34823 		},
  34824 		2: {
  34825 			0: uint8(54),
  34826 			1: uint8(57),
  34827 			2: uint8(112),
  34828 			3: uint8(184),
  34829 			4: uint8(5),
  34830 			5: uint8(41),
  34831 			6: uint8(38),
  34832 			7: uint8(166),
  34833 			8: uint8(213),
  34834 		},
  34835 		3: {
  34836 			0: uint8(30),
  34837 			1: uint8(34),
  34838 			2: uint8(26),
  34839 			3: uint8(133),
  34840 			4: uint8(152),
  34841 			5: uint8(116),
  34842 			6: uint8(10),
  34843 			7: uint8(32),
  34844 			8: uint8(134),
  34845 		},
  34846 		4: {
  34847 			0: uint8(39),
  34848 			1: uint8(19),
  34849 			2: uint8(53),
  34850 			3: uint8(221),
  34851 			4: uint8(26),
  34852 			5: uint8(114),
  34853 			6: uint8(32),
  34854 			7: uint8(73),
  34855 			8: uint8(255),
  34856 		},
  34857 		5: {
  34858 			0: uint8(31),
  34859 			1: uint8(9),
  34860 			2: uint8(65),
  34861 			3: uint8(234),
  34862 			4: uint8(2),
  34863 			5: uint8(15),
  34864 			6: uint8(1),
  34865 			7: uint8(118),
  34866 			8: uint8(73),
  34867 		},
  34868 		6: {
  34869 			0: uint8(75),
  34870 			1: uint8(32),
  34871 			2: uint8(12),
  34872 			3: uint8(51),
  34873 			4: uint8(192),
  34874 			5: uint8(255),
  34875 			6: uint8(160),
  34876 			7: uint8(43),
  34877 			8: uint8(51),
  34878 		},
  34879 		7: {
  34880 			0: uint8(88),
  34881 			1: uint8(31),
  34882 			2: uint8(35),
  34883 			3: uint8(67),
  34884 			4: uint8(102),
  34885 			5: uint8(85),
  34886 			6: uint8(55),
  34887 			7: uint8(186),
  34888 			8: uint8(85),
  34889 		},
  34890 		8: {
  34891 			0: uint8(56),
  34892 			1: uint8(21),
  34893 			2: uint8(23),
  34894 			3: uint8(111),
  34895 			4: uint8(59),
  34896 			5: uint8(205),
  34897 			6: uint8(45),
  34898 			7: uint8(37),
  34899 			8: uint8(192),
  34900 		},
  34901 		9: {
  34902 			0: uint8(55),
  34903 			1: uint8(38),
  34904 			2: uint8(70),
  34905 			3: uint8(124),
  34906 			4: uint8(73),
  34907 			5: uint8(102),
  34908 			6: uint8(1),
  34909 			7: uint8(34),
  34910 			8: uint8(98),
  34911 		},
  34912 	},
  34913 	6: {
  34914 		0: {
  34915 			0: uint8(125),
  34916 			1: uint8(98),
  34917 			2: uint8(42),
  34918 			3: uint8(88),
  34919 			4: uint8(104),
  34920 			5: uint8(85),
  34921 			6: uint8(117),
  34922 			7: uint8(175),
  34923 			8: uint8(82),
  34924 		},
  34925 		1: {
  34926 			0: uint8(95),
  34927 			1: uint8(84),
  34928 			2: uint8(53),
  34929 			3: uint8(89),
  34930 			4: uint8(128),
  34931 			5: uint8(100),
  34932 			6: uint8(113),
  34933 			7: uint8(101),
  34934 			8: uint8(45),
  34935 		},
  34936 		2: {
  34937 			0: uint8(75),
  34938 			1: uint8(79),
  34939 			2: uint8(123),
  34940 			3: uint8(47),
  34941 			4: uint8(51),
  34942 			5: uint8(128),
  34943 			6: uint8(81),
  34944 			7: uint8(171),
  34945 			8: uint8(1),
  34946 		},
  34947 		3: {
  34948 			0: uint8(57),
  34949 			1: uint8(17),
  34950 			2: uint8(5),
  34951 			3: uint8(71),
  34952 			4: uint8(102),
  34953 			5: uint8(57),
  34954 			6: uint8(53),
  34955 			7: uint8(41),
  34956 			8: uint8(49),
  34957 		},
  34958 		4: {
  34959 			0: uint8(38),
  34960 			1: uint8(33),
  34961 			2: uint8(13),
  34962 			3: uint8(121),
  34963 			4: uint8(57),
  34964 			5: uint8(73),
  34965 			6: uint8(26),
  34966 			7: uint8(1),
  34967 			8: uint8(85),
  34968 		},
  34969 		5: {
  34970 			0: uint8(41),
  34971 			1: uint8(10),
  34972 			2: uint8(67),
  34973 			3: uint8(138),
  34974 			4: uint8(77),
  34975 			5: uint8(110),
  34976 			6: uint8(90),
  34977 			7: uint8(47),
  34978 			8: uint8(114),
  34979 		},
  34980 		6: {
  34981 			0: uint8(115),
  34982 			1: uint8(21),
  34983 			2: uint8(2),
  34984 			3: uint8(10),
  34985 			4: uint8(102),
  34986 			5: uint8(255),
  34987 			6: uint8(166),
  34988 			7: uint8(23),
  34989 			8: uint8(6),
  34990 		},
  34991 		7: {
  34992 			0: uint8(101),
  34993 			1: uint8(29),
  34994 			2: uint8(16),
  34995 			3: uint8(10),
  34996 			4: uint8(85),
  34997 			5: uint8(128),
  34998 			6: uint8(101),
  34999 			7: uint8(196),
  35000 			8: uint8(26),
  35001 		},
  35002 		8: {
  35003 			0: uint8(57),
  35004 			1: uint8(18),
  35005 			2: uint8(10),
  35006 			3: uint8(102),
  35007 			4: uint8(102),
  35008 			5: uint8(213),
  35009 			6: uint8(34),
  35010 			7: uint8(20),
  35011 			8: uint8(43),
  35012 		},
  35013 		9: {
  35014 			0: uint8(117),
  35015 			1: uint8(20),
  35016 			2: uint8(15),
  35017 			3: uint8(36),
  35018 			4: uint8(163),
  35019 			5: uint8(128),
  35020 			6: uint8(68),
  35021 			7: uint8(1),
  35022 			8: uint8(26),
  35023 		},
  35024 	},
  35025 	7: {
  35026 		0: {
  35027 			0: uint8(102),
  35028 			1: uint8(61),
  35029 			2: uint8(71),
  35030 			3: uint8(37),
  35031 			4: uint8(34),
  35032 			5: uint8(53),
  35033 			6: uint8(31),
  35034 			7: uint8(243),
  35035 			8: uint8(192),
  35036 		},
  35037 		1: {
  35038 			0: uint8(69),
  35039 			1: uint8(60),
  35040 			2: uint8(71),
  35041 			3: uint8(38),
  35042 			4: uint8(73),
  35043 			5: uint8(119),
  35044 			6: uint8(28),
  35045 			7: uint8(222),
  35046 			8: uint8(37),
  35047 		},
  35048 		2: {
  35049 			0: uint8(68),
  35050 			1: uint8(45),
  35051 			2: uint8(128),
  35052 			3: uint8(34),
  35053 			4: uint8(1),
  35054 			5: uint8(47),
  35055 			6: uint8(11),
  35056 			7: uint8(245),
  35057 			8: uint8(171),
  35058 		},
  35059 		3: {
  35060 			0: uint8(62),
  35061 			1: uint8(17),
  35062 			2: uint8(19),
  35063 			3: uint8(70),
  35064 			4: uint8(146),
  35065 			5: uint8(85),
  35066 			6: uint8(55),
  35067 			7: uint8(62),
  35068 			8: uint8(70),
  35069 		},
  35070 		4: {
  35071 			0: uint8(37),
  35072 			1: uint8(43),
  35073 			2: uint8(37),
  35074 			3: uint8(154),
  35075 			4: uint8(100),
  35076 			5: uint8(163),
  35077 			6: uint8(85),
  35078 			7: uint8(160),
  35079 			8: uint8(1),
  35080 		},
  35081 		5: {
  35082 			0: uint8(63),
  35083 			1: uint8(9),
  35084 			2: uint8(92),
  35085 			3: uint8(136),
  35086 			4: uint8(28),
  35087 			5: uint8(64),
  35088 			6: uint8(32),
  35089 			7: uint8(201),
  35090 			8: uint8(85),
  35091 		},
  35092 		6: {
  35093 			0: uint8(75),
  35094 			1: uint8(15),
  35095 			2: uint8(9),
  35096 			3: uint8(9),
  35097 			4: uint8(64),
  35098 			5: uint8(255),
  35099 			6: uint8(184),
  35100 			7: uint8(119),
  35101 			8: uint8(16),
  35102 		},
  35103 		7: {
  35104 			0: uint8(86),
  35105 			1: uint8(6),
  35106 			2: uint8(28),
  35107 			3: uint8(5),
  35108 			4: uint8(64),
  35109 			5: uint8(255),
  35110 			6: uint8(25),
  35111 			7: uint8(248),
  35112 			8: uint8(1),
  35113 		},
  35114 		8: {
  35115 			0: uint8(56),
  35116 			1: uint8(8),
  35117 			2: uint8(17),
  35118 			3: uint8(132),
  35119 			4: uint8(137),
  35120 			5: uint8(255),
  35121 			6: uint8(55),
  35122 			7: uint8(116),
  35123 			8: uint8(128),
  35124 		},
  35125 		9: {
  35126 			0: uint8(58),
  35127 			1: uint8(15),
  35128 			2: uint8(20),
  35129 			3: uint8(82),
  35130 			4: uint8(135),
  35131 			5: uint8(57),
  35132 			6: uint8(26),
  35133 			7: uint8(121),
  35134 			8: uint8(40),
  35135 		},
  35136 	},
  35137 	8: {
  35138 		0: {
  35139 			0: uint8(164),
  35140 			1: uint8(50),
  35141 			2: uint8(31),
  35142 			3: uint8(137),
  35143 			4: uint8(154),
  35144 			5: uint8(133),
  35145 			6: uint8(25),
  35146 			7: uint8(35),
  35147 			8: uint8(218),
  35148 		},
  35149 		1: {
  35150 			0: uint8(51),
  35151 			1: uint8(103),
  35152 			2: uint8(44),
  35153 			3: uint8(131),
  35154 			4: uint8(131),
  35155 			5: uint8(123),
  35156 			6: uint8(31),
  35157 			7: uint8(6),
  35158 			8: uint8(158),
  35159 		},
  35160 		2: {
  35161 			0: uint8(86),
  35162 			1: uint8(40),
  35163 			2: uint8(64),
  35164 			3: uint8(135),
  35165 			4: uint8(148),
  35166 			5: uint8(224),
  35167 			6: uint8(45),
  35168 			7: uint8(183),
  35169 			8: uint8(128),
  35170 		},
  35171 		3: {
  35172 			0: uint8(22),
  35173 			1: uint8(26),
  35174 			2: uint8(17),
  35175 			3: uint8(131),
  35176 			4: uint8(240),
  35177 			5: uint8(154),
  35178 			6: uint8(14),
  35179 			7: uint8(1),
  35180 			8: uint8(209),
  35181 		},
  35182 		4: {
  35183 			0: uint8(45),
  35184 			1: uint8(16),
  35185 			2: uint8(21),
  35186 			3: uint8(91),
  35187 			4: uint8(64),
  35188 			5: uint8(222),
  35189 			6: uint8(7),
  35190 			7: uint8(1),
  35191 			8: uint8(197),
  35192 		},
  35193 		5: {
  35194 			0: uint8(56),
  35195 			1: uint8(21),
  35196 			2: uint8(39),
  35197 			3: uint8(155),
  35198 			4: uint8(60),
  35199 			5: uint8(138),
  35200 			6: uint8(23),
  35201 			7: uint8(102),
  35202 			8: uint8(213),
  35203 		},
  35204 		6: {
  35205 			0: uint8(83),
  35206 			1: uint8(12),
  35207 			2: uint8(13),
  35208 			3: uint8(54),
  35209 			4: uint8(192),
  35210 			5: uint8(255),
  35211 			6: uint8(68),
  35212 			7: uint8(47),
  35213 			8: uint8(28),
  35214 		},
  35215 		7: {
  35216 			0: uint8(85),
  35217 			1: uint8(26),
  35218 			2: uint8(85),
  35219 			3: uint8(85),
  35220 			4: uint8(128),
  35221 			5: uint8(128),
  35222 			6: uint8(32),
  35223 			7: uint8(146),
  35224 			8: uint8(171),
  35225 		},
  35226 		8: {
  35227 			0: uint8(18),
  35228 			1: uint8(11),
  35229 			2: uint8(7),
  35230 			3: uint8(63),
  35231 			4: uint8(144),
  35232 			5: uint8(171),
  35233 			6: uint8(4),
  35234 			7: uint8(4),
  35235 			8: uint8(246),
  35236 		},
  35237 		9: {
  35238 			0: uint8(35),
  35239 			1: uint8(27),
  35240 			2: uint8(10),
  35241 			3: uint8(146),
  35242 			4: uint8(174),
  35243 			5: uint8(171),
  35244 			6: uint8(12),
  35245 			7: uint8(26),
  35246 			8: uint8(128),
  35247 		},
  35248 	},
  35249 	9: {
  35250 		0: {
  35251 			0: uint8(190),
  35252 			1: uint8(80),
  35253 			2: uint8(35),
  35254 			3: uint8(99),
  35255 			4: uint8(180),
  35256 			5: uint8(80),
  35257 			6: uint8(126),
  35258 			7: uint8(54),
  35259 			8: uint8(45),
  35260 		},
  35261 		1: {
  35262 			0: uint8(85),
  35263 			1: uint8(126),
  35264 			2: uint8(47),
  35265 			3: uint8(87),
  35266 			4: uint8(176),
  35267 			5: uint8(51),
  35268 			6: uint8(41),
  35269 			7: uint8(20),
  35270 			8: uint8(32),
  35271 		},
  35272 		2: {
  35273 			0: uint8(101),
  35274 			1: uint8(75),
  35275 			2: uint8(128),
  35276 			3: uint8(139),
  35277 			4: uint8(118),
  35278 			5: uint8(146),
  35279 			6: uint8(116),
  35280 			7: uint8(128),
  35281 			8: uint8(85),
  35282 		},
  35283 		3: {
  35284 			0: uint8(56),
  35285 			1: uint8(41),
  35286 			2: uint8(15),
  35287 			3: uint8(176),
  35288 			4: uint8(236),
  35289 			5: uint8(85),
  35290 			6: uint8(37),
  35291 			7: uint8(9),
  35292 			8: uint8(62),
  35293 		},
  35294 		4: {
  35295 			0: uint8(71),
  35296 			1: uint8(30),
  35297 			2: uint8(17),
  35298 			3: uint8(119),
  35299 			4: uint8(118),
  35300 			5: uint8(255),
  35301 			6: uint8(17),
  35302 			7: uint8(18),
  35303 			8: uint8(138),
  35304 		},
  35305 		5: {
  35306 			0: uint8(101),
  35307 			1: uint8(38),
  35308 			2: uint8(60),
  35309 			3: uint8(138),
  35310 			4: uint8(55),
  35311 			5: uint8(70),
  35312 			6: uint8(43),
  35313 			7: uint8(26),
  35314 			8: uint8(142),
  35315 		},
  35316 		6: {
  35317 			0: uint8(146),
  35318 			1: uint8(36),
  35319 			2: uint8(19),
  35320 			3: uint8(30),
  35321 			4: uint8(171),
  35322 			5: uint8(255),
  35323 			6: uint8(97),
  35324 			7: uint8(27),
  35325 			8: uint8(20),
  35326 		},
  35327 		7: {
  35328 			0: uint8(138),
  35329 			1: uint8(45),
  35330 			2: uint8(61),
  35331 			3: uint8(62),
  35332 			4: uint8(219),
  35333 			5: uint8(1),
  35334 			6: uint8(81),
  35335 			7: uint8(188),
  35336 			8: uint8(64),
  35337 		},
  35338 		8: {
  35339 			0: uint8(32),
  35340 			1: uint8(41),
  35341 			2: uint8(20),
  35342 			3: uint8(117),
  35343 			4: uint8(151),
  35344 			5: uint8(142),
  35345 			6: uint8(20),
  35346 			7: uint8(21),
  35347 			8: uint8(163),
  35348 		},
  35349 		9: {
  35350 			0: uint8(112),
  35351 			1: uint8(19),
  35352 			2: uint8(12),
  35353 			3: uint8(61),
  35354 			4: uint8(195),
  35355 			5: uint8(128),
  35356 			6: uint8(48),
  35357 			7: uint8(4),
  35358 			8: uint8(24),
  35359 		},
  35360 	},
  35361 }
  35362 
  35363 func PutI4Mode(tls *libc.TLS, bw uintptr, mode int32, prob uintptr) (r int32) {
  35364 	if VP8PutBit(tls, bw, libc.BoolInt32(mode != int32(B_DC_PRED)), int32(**(**uint8_t)(__ccgo_up(prob)))) != 0 {
  35365 		if VP8PutBit(tls, bw, libc.BoolInt32(mode != int32(B_TM_PRED)), int32(**(**uint8_t)(__ccgo_up(prob + 1)))) != 0 {
  35366 			if VP8PutBit(tls, bw, libc.BoolInt32(mode != int32(B_VE_PRED)), int32(**(**uint8_t)(__ccgo_up(prob + 2)))) != 0 {
  35367 				if !(VP8PutBit(tls, bw, libc.BoolInt32(mode >= int32(B_LD_PRED)), int32(**(**uint8_t)(__ccgo_up(prob + 3)))) != 0) {
  35368 					if VP8PutBit(tls, bw, libc.BoolInt32(mode != int32(B_HE_PRED)), int32(**(**uint8_t)(__ccgo_up(prob + 4)))) != 0 {
  35369 						VP8PutBit(tls, bw, libc.BoolInt32(mode != int32(B_RD_PRED)), int32(**(**uint8_t)(__ccgo_up(prob + 5))))
  35370 					}
  35371 				} else {
  35372 					if VP8PutBit(tls, bw, libc.BoolInt32(mode != int32(B_LD_PRED)), int32(**(**uint8_t)(__ccgo_up(prob + 6)))) != 0 {
  35373 						if VP8PutBit(tls, bw, libc.BoolInt32(mode != int32(B_VL_PRED)), int32(**(**uint8_t)(__ccgo_up(prob + 7)))) != 0 {
  35374 							VP8PutBit(tls, bw, libc.BoolInt32(mode != int32(B_HD_PRED)), int32(**(**uint8_t)(__ccgo_up(prob + 8))))
  35375 						}
  35376 					}
  35377 				}
  35378 			}
  35379 		}
  35380 	}
  35381 	return mode
  35382 }
  35383 
  35384 func PutI16Mode(tls *libc.TLS, bw uintptr, mode int32) {
  35385 	if VP8PutBit(tls, bw, libc.BoolInt32(mode == int32(TM_PRED) || mode == int32(H_PRED)), int32(156)) != 0 {
  35386 		VP8PutBit(tls, bw, libc.BoolInt32(mode == int32(TM_PRED)), int32(128)) // TM or HE
  35387 	} else {
  35388 		VP8PutBit(tls, bw, libc.BoolInt32(mode == int32(V_PRED)), int32(163)) // VE or DC
  35389 	}
  35390 }
  35391 
  35392 func PutUVMode(tls *libc.TLS, bw uintptr, uv_mode int32) {
  35393 	if VP8PutBit(tls, bw, libc.BoolInt32(uv_mode != int32(DC_PRED)), int32(142)) != 0 {
  35394 		if VP8PutBit(tls, bw, libc.BoolInt32(uv_mode != int32(V_PRED)), int32(114)) != 0 {
  35395 			VP8PutBit(tls, bw, libc.BoolInt32(uv_mode != int32(H_PRED)), int32(183)) // else: TM_PRED
  35396 		}
  35397 	}
  35398 }
  35399 
  35400 func PutSegment(tls *libc.TLS, bw uintptr, s int32, p uintptr) {
  35401 	if VP8PutBit(tls, bw, libc.BoolInt32(s >= int32(2)), int32(**(**uint8_t)(__ccgo_up(p)))) != 0 {
  35402 		p = p + uintptr(1)
  35403 	}
  35404 	VP8PutBit(tls, bw, s&int32(1), int32(**(**uint8_t)(__ccgo_up(p + 1))))
  35405 }
  35406 
  35407 func VP8CodeIntraModes(tls *libc.TLS, enc uintptr) {
  35408 	bp := tls.Alloc(3856)
  35409 	defer tls.Free(3856)
  35410 	var bw, mb, preds, probas, top_pred uintptr
  35411 	var left, preds_w, x, y int32
  35412 	var _ /* it at bp+0 */ VP8EncIterator
  35413 	_, _, _, _, _, _, _, _, _ = bw, left, mb, preds, preds_w, probas, top_pred, x, y
  35414 	bw = enc + 64
  35415 	VP8IteratorInit(tls, enc, bp)
  35416 	for cond := true; cond; cond = VP8IteratorNext(tls, bp) != 0 {
  35417 		mb = (**(**VP8EncIterator)(__ccgo_up(bp))).Fmb
  35418 		preds = (**(**VP8EncIterator)(__ccgo_up(bp))).Fpreds
  35419 		if (*VP8Encoder)(unsafe.Pointer(enc)).Fsegment_hdr.Fupdate_map != 0 {
  35420 			PutSegment(tls, bw, int32(uint32(*(*uint8)(unsafe.Pointer(mb + 0))&0x60>>5)), enc+3616)
  35421 		}
  35422 		if (*VP8Encoder)(unsafe.Pointer(enc)).Fproba.Fuse_skip_proba != 0 {
  35423 			VP8PutBit(tls, bw, int32(uint32(*(*uint8)(unsafe.Pointer(mb + 0))&0x10>>4)), int32((*VP8Encoder)(unsafe.Pointer(enc)).Fproba.Fskip_proba))
  35424 		}
  35425 		if VP8PutBit(tls, bw, libc.BoolInt32(int32(uint32(*(*uint8)(unsafe.Pointer(mb + 0))&0x3>>0)) != 0), int32(145)) != 0 { // i16x16
  35426 			PutI16Mode(tls, bw, int32(**(**uint8_t)(__ccgo_up(preds))))
  35427 		} else {
  35428 			preds_w = (*VP8Encoder)(unsafe.Pointer(enc)).Fpreds_w
  35429 			top_pred = preds - uintptr(preds_w)
  35430 			y = 0
  35431 			for {
  35432 				if !(y < int32(4)) {
  35433 					break
  35434 				}
  35435 				left = int32(**(**uint8_t)(__ccgo_up(preds + uintptr(-libc.Int32FromInt32(1)))))
  35436 				x = 0
  35437 				for {
  35438 					if !(x < int32(4)) {
  35439 						break
  35440 					}
  35441 					probas = uintptr(unsafe.Pointer(&kBModesProba1)) + uintptr(**(**uint8_t)(__ccgo_up(top_pred + uintptr(x))))*90 + uintptr(left)*9
  35442 					left = PutI4Mode(tls, bw, int32(**(**uint8_t)(__ccgo_up(preds + uintptr(x)))), probas)
  35443 					goto _2
  35444 				_2:
  35445 					;
  35446 					x = x + 1
  35447 				}
  35448 				top_pred = preds
  35449 				preds = preds + uintptr(preds_w)
  35450 				goto _1
  35451 			_1:
  35452 				;
  35453 				y = y + 1
  35454 			}
  35455 		}
  35456 		PutUVMode(tls, bw, int32(uint32(*(*uint8)(unsafe.Pointer(mb + 0))&0xc>>2)))
  35457 	}
  35458 }
  35459 
  35460 func VP8WriteProbas(tls *libc.TLS, bw uintptr, probas uintptr) {
  35461 	var b, c, p, t, update int32
  35462 	var p0 uint8_t
  35463 	_, _, _, _, _, _ = b, c, p, p0, t, update
  35464 	t = 0
  35465 	for {
  35466 		if !(t < int32(NUM_TYPES)) {
  35467 			break
  35468 		}
  35469 		b = 0
  35470 		for {
  35471 			if !(b < int32(NUM_BANDS)) {
  35472 				break
  35473 			}
  35474 			c = 0
  35475 			for {
  35476 				if !(c < int32(NUM_CTX)) {
  35477 					break
  35478 				}
  35479 				p = 0
  35480 				for {
  35481 					if !(p < int32(NUM_PROBAS)) {
  35482 						break
  35483 					}
  35484 					p0 = **(**uint8_t)(__ccgo_up(probas + 4 + uintptr(t)*264 + uintptr(b)*33 + uintptr(c)*11 + uintptr(p)))
  35485 					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)))))
  35486 					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 {
  35487 						VP8PutBits(tls, bw, uint32(p0), int32(8))
  35488 					}
  35489 					goto _4
  35490 				_4:
  35491 					;
  35492 					p = p + 1
  35493 				}
  35494 				goto _3
  35495 			_3:
  35496 				;
  35497 				c = c + 1
  35498 			}
  35499 			goto _2
  35500 		_2:
  35501 			;
  35502 			b = b + 1
  35503 		}
  35504 		goto _1
  35505 	_1:
  35506 		;
  35507 		t = t + 1
  35508 	}
  35509 	if VP8PutBitUniform(tls, bw, (*VP8EncProba)(unsafe.Pointer(probas)).Fuse_skip_proba) != 0 {
  35510 		VP8PutBits(tls, bw, uint32((*VP8EncProba)(unsafe.Pointer(probas)).Fskip_proba), int32(8))
  35511 	}
  35512 }
  35513 
  35514 const MAX_HUFF_IMAGE_SIZE = 2600
  35515 const NUM_BUCKETS = 256
  35516 const SIZE_MAX16 = "_UI64_MAX"
  35517 const VP8L_MAGIC_BYTE3 = 47
  35518 const VP8_SIGNATURE2 = 0x9d012a
  35519 
  35520 type HuffmanTreeToken = struct {
  35521 	Fcode       uint8_t
  35522 	Fextra_bits uint8_t
  35523 }
  35524 
  35525 type HuffmanTreeCode = struct {
  35526 	Fnum_symbols  int32
  35527 	Fcode_lengths uintptr
  35528 	Fcodes        uintptr
  35529 }
  35530 
  35531 type HuffmanTree = struct {
  35532 	Ftotal_count      uint32_t
  35533 	Fvalue            int32
  35534 	Fpool_index_left  int32
  35535 	Fpool_index_right int32
  35536 }
  35537 
  35538 type PaletteSorting1 = int32
  35539 
  35540 type PaletteSorting = int32
  35541 
  35542 const kSortedDefault = 0
  35543 const kMinimizeDelta = 1
  35544 const kModifiedZeng = 2
  35545 const kUnusedPalette = 3
  35546 const kPaletteSortingNum = 4
  35547 
  35548 // Copyright 2011 Google Inc. All Rights Reserved.
  35549 //
  35550 // Use of this source code is governed by a BSD-style license
  35551 // that can be found in the COPYING file in the root of the source
  35552 // tree. An additional intellectual property rights grant can be found
  35553 // in the file PATENTS. All contributing project authors may
  35554 // be found in the AUTHORS file in the root of the source tree.
  35555 // -----------------------------------------------------------------------------
  35556 //
  35557 // Multi-threaded worker
  35558 //
  35559 // Author: Skal (pascal.massimino@gmail.com)
  35560 
  35561 // Copyright 2012 Google Inc. All Rights Reserved.
  35562 //
  35563 // Use of this source code is governed by a BSD-style license
  35564 // that can be found in the COPYING file in the root of the source
  35565 // tree. An additional intellectual property rights grant can be found
  35566 // in the file PATENTS. All contributing project authors may
  35567 // be found in the AUTHORS file in the root of the source tree.
  35568 // -----------------------------------------------------------------------------
  35569 //
  35570 // Misc. common utility functions
  35571 //
  35572 // Authors: Skal (pascal.massimino@gmail.com)
  35573 //          Urvang (urvang@google.com)
  35574 
  35575 // Copyright 2011 Google Inc. All Rights Reserved.
  35576 //
  35577 // Use of this source code is governed by a BSD-style license
  35578 // that can be found in the COPYING file in the root of the source
  35579 // tree. An additional intellectual property rights grant can be found
  35580 // in the file PATENTS. All contributing project authors may
  35581 // be found in the AUTHORS file in the root of the source tree.
  35582 // -----------------------------------------------------------------------------
  35583 //
  35584 //   WebP encoder: main interface
  35585 //
  35586 // Author: Skal (pascal.massimino@gmail.com)
  35587 
  35588 // Copyright 2012 Google Inc. All Rights Reserved.
  35589 //
  35590 // Use of this source code is governed by a BSD-style license
  35591 // that can be found in the COPYING file in the root of the source
  35592 // tree. An additional intellectual property rights grant can be found
  35593 // in the file PATENTS. All contributing project authors may
  35594 // be found in the AUTHORS file in the root of the source tree.
  35595 // -----------------------------------------------------------------------------
  35596 //
  35597 //  Internal header for constants related to WebP file format.
  35598 //
  35599 // Author: Urvang (urvang@google.com)
  35600 
  35601 // Copyright 2010 Google Inc. All Rights Reserved.
  35602 //
  35603 // Use of this source code is governed by a BSD-style license
  35604 // that can be found in the COPYING file in the root of the source
  35605 // tree. An additional intellectual property rights grant can be found
  35606 // in the file PATENTS. All contributing project authors may
  35607 // be found in the AUTHORS file in the root of the source tree.
  35608 // -----------------------------------------------------------------------------
  35609 //
  35610 //  Common types + memory wrappers
  35611 //
  35612 // Author: Skal (pascal.massimino@gmail.com)
  35613 
  35614 // Maximum number of histogram images (sub-blocks).
  35615 // Empirical value for which it becomes too computationally expensive to
  35616 // compute the best predictor image.
  35617 
  35618 // -----------------------------------------------------------------------------
  35619 // Palette
  35620 
  35621 // C documentation
  35622 //
  35623 //	// These five modes are evaluated and their respective entropy is computed.
  35624 type EntropyIx = int32
  35625 
  35626 const kDirect = 0
  35627 const kSpatial = 1
  35628 const kSubGreen = 2
  35629 const kSpatialSubGreen = 3
  35630 const kPalette = 4
  35631 const kPaletteAndSpatial = 5
  35632 const kNumEntropyIx = 6
  35633 
  35634 type HistoIx = int32
  35635 
  35636 const kHistoAlpha = 0
  35637 const kHistoAlphaPred = 1
  35638 const kHistoGreen = 2
  35639 const kHistoGreenPred = 3
  35640 const kHistoRed = 4
  35641 const kHistoRedPred = 5
  35642 const kHistoBlue = 6
  35643 const kHistoBluePred = 7
  35644 const kHistoRedSubGreen = 8
  35645 const kHistoRedPredSubGreen = 9
  35646 const kHistoBlueSubGreen = 10
  35647 const kHistoBluePredSubGreen = 11
  35648 const kHistoPalette = 12
  35649 const kHistoTotal = 13
  35650 
  35651 type HistogramBuckets = [256]uint32_t
  35652 
  35653 // C documentation
  35654 //
  35655 //	// Keeping track of histograms, indexed by HistoIx.
  35656 //	// Ideally, this would just be a struct with meaningful fields, but the
  35657 //	// calculation of `entropy_comp` uses the index. One refactoring at a time :)
  35658 type Histograms = struct {
  35659 	Fcategory [13]HistogramBuckets
  35660 }
  35661 
  35662 func AddSingleSubGreen(tls *libc.TLS, p uint32_t, r uintptr, b uintptr) {
  35663 	var green int32
  35664 	_ = green
  35665 	green = int32(p) >> int32(8) // The upper bits are masked away later.
  35666 	**(**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
  35667 	**(**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
  35668 }
  35669 
  35670 func AddSingle(tls *libc.TLS, p uint32_t, a uintptr, r uintptr, g uintptr, b uintptr) {
  35671 	**(**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
  35672 	**(**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
  35673 	**(**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
  35674 	**(**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
  35675 }
  35676 
  35677 func HashPix(tls *libc.TLS, pix uint32_t) (r uint8_t) {
  35678 	// Note that masking with 0xffffffffu is for preventing an
  35679 	// 'unsigned int overflow' warning. Doesn't impact the compiled code.
  35680 	return uint8((uint64(pix) + uint64(pix>>libc.Int32FromInt32(19))) * uint64(0x39c5fba7) & uint64(0xffffffff) >> int32(24))
  35681 }
  35682 
  35683 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) {
  35684 	bp := tls.Alloc(48)
  35685 	defer tls.Free(48)
  35686 	var alpha_and_green, pix, pix_diff, pix_prev, red_and_blue, v10, v12, v3, v4, v5, v9 uint32_t
  35687 	var blue_histo, curr_row, histo, prev_row, red_histo uintptr
  35688 	var entropy_comp [13]uint64_t
  35689 	var hash uint8_t
  35690 	var i, j, k, last_mode_to_analyze, x, y, v7 int32
  35691 	var v18 uint32
  35692 	var _ /* entropy at bp+0 */ [6]uint64_t
  35693 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  35694 	if use_palette != 0 && palette_size <= int32(16) {
  35695 		// In the case of small palettes, we pack 2, 4 or 8 pixels together. In
  35696 		// practice, small palettes are better than any other transform.
  35697 		**(**EntropyIx)(__ccgo_up(min_entropy_ix)) = int32(kPalette)
  35698 		**(**int32)(__ccgo_up(red_and_blue_always_zero)) = int32(1)
  35699 		return int32(1)
  35700 	}
  35701 	histo = WebPSafeCalloc(tls, uint64(1), uint64(13312))
  35702 	if histo != libc.UintptrFromInt32(0) {
  35703 		prev_row = libc.UintptrFromInt32(0)
  35704 		curr_row = argb
  35705 		pix_prev = **(**uint32_t)(__ccgo_up(argb)) // Skip the first pixel.
  35706 		y = 0
  35707 		for {
  35708 			if !(y < height) {
  35709 				break
  35710 			}
  35711 			x = 0
  35712 			for {
  35713 				if !(x < width) {
  35714 					break
  35715 				}
  35716 				pix = **(**uint32_t)(__ccgo_up(curr_row + uintptr(x)*4))
  35717 				v3 = pix
  35718 				v4 = pix_prev
  35719 				alpha_and_green = uint32(0x00ff00ff) + v3&uint32(0xff00ff00) - v4&uint32(0xff00ff00)
  35720 				red_and_blue = uint32(0xff00ff00) + v3&uint32(0x00ff00ff) - v4&uint32(0x00ff00ff)
  35721 				v5 = alpha_and_green&uint32(0xff00ff00) | red_and_blue&uint32(0x00ff00ff)
  35722 				goto _6
  35723 			_6:
  35724 				pix_diff = v5
  35725 				pix_prev = pix
  35726 				if pix_diff == uint32(0) || prev_row != libc.UintptrFromInt32(0) && pix == **(**uint32_t)(__ccgo_up(prev_row + uintptr(x)*4)) {
  35727 					goto _2
  35728 				}
  35729 				AddSingle(tls, pix, histo+uintptr(kHistoAlpha)*1024, histo+uintptr(kHistoRed)*1024, histo+uintptr(kHistoGreen)*1024, histo+uintptr(kHistoBlue)*1024)
  35730 				AddSingle(tls, pix_diff, histo+uintptr(kHistoAlphaPred)*1024, histo+uintptr(kHistoRedPred)*1024, histo+uintptr(kHistoGreenPred)*1024, histo+uintptr(kHistoBluePred)*1024)
  35731 				AddSingleSubGreen(tls, pix, histo+uintptr(kHistoRedSubGreen)*1024, histo+uintptr(kHistoBlueSubGreen)*1024)
  35732 				AddSingleSubGreen(tls, pix_diff, histo+uintptr(kHistoRedPredSubGreen)*1024, histo+uintptr(kHistoBluePredSubGreen)*1024)
  35733 				// Approximate the palette by the entropy of the multiplicative hash.
  35734 				hash = HashPix(tls, pix)
  35735 				**(**uint32_t)(__ccgo_up(histo + uintptr(kHistoPalette)*1024 + uintptr(hash)*4)) = **(**uint32_t)(__ccgo_up(histo + uintptr(kHistoPalette)*1024 + uintptr(hash)*4)) + 1
  35736 				goto _2
  35737 			_2:
  35738 				;
  35739 				x = x + 1
  35740 			}
  35741 			prev_row = curr_row
  35742 			curr_row = curr_row + uintptr(argb_stride)*4
  35743 			goto _1
  35744 		_1:
  35745 			;
  35746 			y = y + 1
  35747 		}
  35748 		if use_palette != 0 {
  35749 			v7 = int32(kPalette)
  35750 		} else {
  35751 			v7 = int32(kSpatialSubGreen)
  35752 		}
  35753 		last_mode_to_analyze = v7
  35754 		// Let's add one zero to the predicted histograms. The zeros are removed
  35755 		// too efficiently by the pix_diff == 0 comparison, at least one of the
  35756 		// zeros is likely to exist.
  35757 		**(**uint32_t)(__ccgo_up(histo + uintptr(kHistoRedPredSubGreen)*1024)) = **(**uint32_t)(__ccgo_up(histo + uintptr(kHistoRedPredSubGreen)*1024)) + 1
  35758 		**(**uint32_t)(__ccgo_up(histo + uintptr(kHistoBluePredSubGreen)*1024)) = **(**uint32_t)(__ccgo_up(histo + uintptr(kHistoBluePredSubGreen)*1024)) + 1
  35759 		**(**uint32_t)(__ccgo_up(histo + uintptr(kHistoRedPred)*1024)) = **(**uint32_t)(__ccgo_up(histo + uintptr(kHistoRedPred)*1024)) + 1
  35760 		**(**uint32_t)(__ccgo_up(histo + uintptr(kHistoGreenPred)*1024)) = **(**uint32_t)(__ccgo_up(histo + uintptr(kHistoGreenPred)*1024)) + 1
  35761 		**(**uint32_t)(__ccgo_up(histo + uintptr(kHistoBluePred)*1024)) = **(**uint32_t)(__ccgo_up(histo + uintptr(kHistoBluePred)*1024)) + 1
  35762 		**(**uint32_t)(__ccgo_up(histo + uintptr(kHistoAlphaPred)*1024)) = **(**uint32_t)(__ccgo_up(histo + uintptr(kHistoAlphaPred)*1024)) + 1
  35763 		j = 0
  35764 		for {
  35765 			if !(j < int32(kHistoTotal)) {
  35766 				break
  35767 			}
  35768 			entropy_comp[j] = VP8LBitsEntropy(tls, histo+uintptr(j)*1024, int32(NUM_BUCKETS))
  35769 			goto _8
  35770 		_8:
  35771 			;
  35772 			j = j + 1
  35773 		}
  35774 		(**(**[6]uint64_t)(__ccgo_up(bp)))[int32(kDirect)] = entropy_comp[int32(kHistoAlpha)] + entropy_comp[int32(kHistoRed)] + entropy_comp[int32(kHistoGreen)] + entropy_comp[int32(kHistoBlue)]
  35775 		(**(**[6]uint64_t)(__ccgo_up(bp)))[int32(kSpatial)] = entropy_comp[int32(kHistoAlphaPred)] + entropy_comp[int32(kHistoRedPred)] + entropy_comp[int32(kHistoGreenPred)] + entropy_comp[int32(kHistoBluePred)]
  35776 		(**(**[6]uint64_t)(__ccgo_up(bp)))[int32(kSubGreen)] = entropy_comp[int32(kHistoAlpha)] + entropy_comp[int32(kHistoRedSubGreen)] + entropy_comp[int32(kHistoGreen)] + entropy_comp[int32(kHistoBlueSubGreen)]
  35777 		(**(**[6]uint64_t)(__ccgo_up(bp)))[int32(kSpatialSubGreen)] = entropy_comp[int32(kHistoAlphaPred)] + entropy_comp[int32(kHistoRedPredSubGreen)] + entropy_comp[int32(kHistoGreenPred)] + entropy_comp[int32(kHistoBluePredSubGreen)]
  35778 		(**(**[6]uint64_t)(__ccgo_up(bp)))[int32(kPalette)] = entropy_comp[int32(kHistoPalette)]
  35779 		// When including transforms, there is an overhead in bits from
  35780 		// storing them. This overhead is small but matters for small images.
  35781 		// For spatial, there are 14 transformations.
  35782 		v3 = uint32(transform_bits)
  35783 		v4 = (uint32(width) + uint32(libc.Int32FromInt32(1)<<v3) - uint32(1)) >> v3
  35784 		goto _11
  35785 	_11:
  35786 		v5 = uint32(transform_bits)
  35787 		v9 = (uint32(height) + uint32(libc.Int32FromInt32(1)<<v5) - uint32(1)) >> v5
  35788 		goto _14
  35789 	_14:
  35790 		v10 = uint32(14)
  35791 		if v10 < uint32(LOG_LOOKUP_IDX_MAX) {
  35792 			v18 = kLog2Table[v10]
  35793 		} else {
  35794 			v18 = (*(*func(*libc.TLS, uint32_t) uint32_t)(unsafe.Pointer(&struct{ uintptr }{VP8LFastLog2Slow})))(tls, v10)
  35795 		}
  35796 		v12 = v18
  35797 		goto _17
  35798 	_17:
  35799 		**(**uint64_t)(__ccgo_up(bp + uintptr(kSpatial)*8)) += uint64(v4) * uint64(v9) * uint64(v12)
  35800 		// For color transforms: 24 as only 3 channels are considered in a
  35801 		// ColorTransformElement.
  35802 		v3 = uint32(transform_bits)
  35803 		v4 = (uint32(width) + uint32(libc.Int32FromInt32(1)<<v3) - uint32(1)) >> v3
  35804 		goto _21
  35805 	_21:
  35806 		v5 = uint32(transform_bits)
  35807 		v9 = (uint32(height) + uint32(libc.Int32FromInt32(1)<<v5) - uint32(1)) >> v5
  35808 		goto _24
  35809 	_24:
  35810 		v10 = uint32(24)
  35811 		if v10 < uint32(LOG_LOOKUP_IDX_MAX) {
  35812 			v18 = kLog2Table[v10]
  35813 		} else {
  35814 			v18 = (*(*func(*libc.TLS, uint32_t) uint32_t)(unsafe.Pointer(&struct{ uintptr }{VP8LFastLog2Slow})))(tls, v10)
  35815 		}
  35816 		v12 = v18
  35817 		goto _27
  35818 	_27:
  35819 		**(**uint64_t)(__ccgo_up(bp + uintptr(kSpatialSubGreen)*8)) += uint64(v4) * uint64(v9) * uint64(v12)
  35820 		// For palettes, add the cost of storing the palette.
  35821 		// We empirically estimate the cost of a compressed entry as 8 bits.
  35822 		// The palette is differential-coded when compressed hence a much
  35823 		// lower cost than sizeof(uint32_t)*8.
  35824 		**(**uint64_t)(__ccgo_up(bp + uintptr(kPalette)*8)) += uint64(palette_size) * uint64(8) << int32(LOG_2_PRECISION_BITS)
  35825 		**(**EntropyIx)(__ccgo_up(min_entropy_ix)) = int32(kDirect)
  35826 		k = int32(kDirect) + libc.Int32FromInt32(1)
  35827 		for {
  35828 			if !(k <= last_mode_to_analyze) {
  35829 				break
  35830 			}
  35831 			if (**(**[6]uint64_t)(__ccgo_up(bp)))[**(**EntropyIx)(__ccgo_up(min_entropy_ix))] > (**(**[6]uint64_t)(__ccgo_up(bp)))[k] {
  35832 				**(**EntropyIx)(__ccgo_up(min_entropy_ix)) = k
  35833 			}
  35834 			goto _29
  35835 		_29:
  35836 			;
  35837 			k = k + 1
  35838 		}
  35839 		**(**int32)(__ccgo_up(red_and_blue_always_zero)) = int32(1)
  35840 		red_histo = histo + uintptr(**(**uint8_t)(__ccgo_up(uintptr(unsafe.Pointer(&kHistoPairs)) + uintptr(**(**EntropyIx)(__ccgo_up(min_entropy_ix)))*2)))*1024
  35841 		blue_histo = histo + uintptr(**(**uint8_t)(__ccgo_up(uintptr(unsafe.Pointer(&kHistoPairs)) + uintptr(**(**EntropyIx)(__ccgo_up(min_entropy_ix)))*2 + 1)))*1024
  35842 		i = int32(1)
  35843 		for {
  35844 			if !(i < int32(NUM_BUCKETS)) {
  35845 				break
  35846 			}
  35847 			if **(**uint32_t)(__ccgo_up(red_histo + uintptr(i)*4))|**(**uint32_t)(__ccgo_up(blue_histo + uintptr(i)*4)) != uint32(0) {
  35848 				**(**int32)(__ccgo_up(red_and_blue_always_zero)) = 0
  35849 				break
  35850 			}
  35851 			goto _30
  35852 		_30:
  35853 			;
  35854 			i = i + 1
  35855 		}
  35856 		WebPSafeFree(tls, histo)
  35857 		return int32(1)
  35858 	} else {
  35859 		return 0
  35860 	}
  35861 	return r
  35862 }
  35863 
  35864 // Let's check if the histogram of the chosen entropy mode has
  35865 // non-zero red and blue values. If all are zero, we can later skip
  35866 // the cross color optimization.
  35867 
  35868 var kHistoPairs = [5][2]uint8_t{
  35869 	0: {
  35870 		0: uint8(kHistoRed),
  35871 		1: uint8(kHistoBlue),
  35872 	},
  35873 	1: {
  35874 		0: uint8(kHistoRedPred),
  35875 		1: uint8(kHistoBluePred),
  35876 	},
  35877 	2: {
  35878 		0: uint8(kHistoRedSubGreen),
  35879 		1: uint8(kHistoBlueSubGreen),
  35880 	},
  35881 	3: {
  35882 		0: uint8(kHistoRedPredSubGreen),
  35883 		1: uint8(kHistoBluePredSubGreen),
  35884 	},
  35885 	4: {
  35886 		0: uint8(kHistoRed),
  35887 		1: uint8(kHistoBlue),
  35888 	},
  35889 }
  35890 
  35891 // C documentation
  35892 //
  35893 //	// Clamp histogram and transform bits.
  35894 func ClampBits(tls *libc.TLS, width int32, height int32, bits int32, min_bits int32, max_bits int32, image_size_max int32) (r int32) {
  35895 	var image_size, v1, v2 int32
  35896 	var v3, v4, v6, v7 uint32_t
  35897 	_, _, _, _, _, _, _ = image_size, v1, v2, v3, v4, v6, v7
  35898 	if bits < min_bits {
  35899 		v1 = min_bits
  35900 	} else {
  35901 		if bits > max_bits {
  35902 			v2 = max_bits
  35903 		} else {
  35904 			v2 = bits
  35905 		}
  35906 		v1 = v2
  35907 	}
  35908 	bits = v1
  35909 	v3 = uint32(bits)
  35910 	v4 = (uint32(width) + uint32(libc.Int32FromInt32(1)<<v3) - uint32(1)) >> v3
  35911 	goto _5
  35912 _5:
  35913 	v6 = uint32(bits)
  35914 	v7 = (uint32(height) + uint32(libc.Int32FromInt32(1)<<v6) - uint32(1)) >> v6
  35915 	goto _8
  35916 _8:
  35917 	image_size = int32(v4 * v7)
  35918 	for bits < max_bits && image_size > image_size_max {
  35919 		bits = bits + 1
  35920 		v3 = uint32(bits)
  35921 		v4 = (uint32(width) + uint32(libc.Int32FromInt32(1)<<v3) - uint32(1)) >> v3
  35922 		goto _11
  35923 	_11:
  35924 		v6 = uint32(bits)
  35925 		v7 = (uint32(height) + uint32(libc.Int32FromInt32(1)<<v6) - uint32(1)) >> v6
  35926 		goto _14
  35927 	_14:
  35928 		image_size = int32(v4 * v7)
  35929 	}
  35930 	// In case the bits reduce the image too much, choose the smallest value
  35931 	// setting the histogram image size to 1.
  35932 	for bits > min_bits && image_size == int32(1) {
  35933 		v3 = uint32(bits - int32(1))
  35934 		v4 = (uint32(width) + uint32(libc.Int32FromInt32(1)<<v3) - uint32(1)) >> v3
  35935 		goto _17
  35936 	_17:
  35937 		v6 = uint32(bits - int32(1))
  35938 		v7 = (uint32(height) + uint32(libc.Int32FromInt32(1)<<v6) - uint32(1)) >> v6
  35939 		goto _20
  35940 	_20:
  35941 		image_size = int32(v4 * v7)
  35942 		if image_size != int32(1) {
  35943 			break
  35944 		}
  35945 		bits = bits - 1
  35946 	}
  35947 	return bits
  35948 }
  35949 
  35950 func GetHistoBits(tls *libc.TLS, method int32, use_palette int32, width int32, height int32) (r int32) {
  35951 	var histo_bits, v1 int32
  35952 	_, _ = histo_bits, v1
  35953 	if use_palette != 0 {
  35954 		v1 = int32(9)
  35955 	} else {
  35956 		v1 = int32(7)
  35957 	}
  35958 	// Make tile size a function of encoding method (Range: 0 to 6).
  35959 	histo_bits = v1 - method
  35960 	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))
  35961 }
  35962 
  35963 func GetTransformBits(tls *libc.TLS, method int32, histo_bits int32) (r int32) {
  35964 	var max_transform_bits, res, v1, v2, v3 int32
  35965 	_, _, _, _, _ = max_transform_bits, res, v1, v2, v3
  35966 	if method < int32(4) {
  35967 		v1 = int32(6)
  35968 	} else {
  35969 		if method > int32(4) {
  35970 			v2 = int32(4)
  35971 		} else {
  35972 			v2 = int32(5)
  35973 		}
  35974 		v1 = v2
  35975 	}
  35976 	max_transform_bits = v1
  35977 	if histo_bits > max_transform_bits {
  35978 		v3 = max_transform_bits
  35979 	} else {
  35980 		v3 = histo_bits
  35981 	}
  35982 	res = v3
  35983 	return res
  35984 }
  35985 
  35986 // C documentation
  35987 //
  35988 //	// Set of parameters to be used in each iteration of the cruncher.
  35989 type CrunchSubConfig = struct {
  35990 	Flz77        int32
  35991 	Fdo_no_cache int32
  35992 }
  35993 
  35994 type CrunchConfig = struct {
  35995 	Fentropy_idx          int32
  35996 	Fpalette_sorting_type PaletteSorting1
  35997 	Fsub_configs          [2]CrunchSubConfig
  35998 	Fsub_configs_size     int32
  35999 }
  36000 
  36001 // +2 because we add a palette sorting configuration for kPalette and
  36002 // kPaletteAndSpatial.
  36003 
  36004 func EncoderAnalyze(tls *libc.TLS, enc uintptr, crunch_configs uintptr, crunch_configs_size uintptr, red_and_blue_always_zero uintptr) (r int32) {
  36005 	bp := tls.Alloc(16)
  36006 	defer tls.Free(16)
  36007 	var config, pic uintptr
  36008 	var do_no_cache, height, i, j, low_effort, method, n_lz77s, sorting_method, transform_bits, use_palette, width, v1 int32
  36009 	var typed_sorting_method PaletteSorting1
  36010 	var _ /* min_entropy_ix at bp+0 */ EntropyIx
  36011 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = config, do_no_cache, height, i, j, low_effort, method, n_lz77s, pic, sorting_method, transform_bits, typed_sorting_method, use_palette, width, v1
  36012 	pic = (*VP8LEncoder)(unsafe.Pointer(enc)).Fpic
  36013 	width = (*WebPPicture)(unsafe.Pointer(pic)).Fwidth
  36014 	height = (*WebPPicture)(unsafe.Pointer(pic)).Fheight
  36015 	config = (*VP8LEncoder)(unsafe.Pointer(enc)).Fconfig
  36016 	method = (*WebPConfig)(unsafe.Pointer(config)).Fmethod
  36017 	low_effort = libc.BoolInt32((*WebPConfig)(unsafe.Pointer(config)).Fmethod == libc.Int32FromInt32(0))
  36018 	// If set to 0, analyze the cache with the computed cache value. If 1, also
  36019 	// analyze with no-cache.
  36020 	do_no_cache = 0
  36021 	// Check whether a palette is possible.
  36022 	(*VP8LEncoder)(unsafe.Pointer(enc)).Fpalette_size = GetColorPalette(tls, pic, enc+1128)
  36023 	use_palette = libc.BoolInt32((*VP8LEncoder)(unsafe.Pointer(enc)).Fpalette_size <= int32(MAX_PALETTE_SIZE))
  36024 	if !(use_palette != 0) {
  36025 		(*VP8LEncoder)(unsafe.Pointer(enc)).Fpalette_size = 0
  36026 	}
  36027 	// Empirical bit sizes.
  36028 	(*VP8LEncoder)(unsafe.Pointer(enc)).Fhisto_bits = GetHistoBits(tls, method, use_palette, (*WebPPicture)(unsafe.Pointer(pic)).Fwidth, (*WebPPicture)(unsafe.Pointer(pic)).Fheight)
  36029 	transform_bits = GetTransformBits(tls, method, (*VP8LEncoder)(unsafe.Pointer(enc)).Fhisto_bits)
  36030 	(*VP8LEncoder)(unsafe.Pointer(enc)).Fpredictor_transform_bits = transform_bits
  36031 	(*VP8LEncoder)(unsafe.Pointer(enc)).Fcross_color_transform_bits = transform_bits
  36032 	if low_effort != 0 {
  36033 		// AnalyzeEntropy is somewhat slow.
  36034 		if use_palette != 0 {
  36035 			v1 = int32(kPalette)
  36036 		} else {
  36037 			v1 = int32(kSpatialSubGreen)
  36038 		}
  36039 		(**(**CrunchConfig)(__ccgo_up(crunch_configs))).Fentropy_idx = v1
  36040 		if use_palette != 0 {
  36041 			v1 = int32(kSortedDefault)
  36042 		} else {
  36043 			v1 = int32(kUnusedPalette)
  36044 		}
  36045 		(**(**CrunchConfig)(__ccgo_up(crunch_configs))).Fpalette_sorting_type = v1
  36046 		n_lz77s = int32(1)
  36047 		**(**int32)(__ccgo_up(crunch_configs_size)) = int32(1)
  36048 	} else {
  36049 		// Try out multiple LZ77 on images with few colors.
  36050 		if (*VP8LEncoder)(unsafe.Pointer(enc)).Fpalette_size > 0 && (*VP8LEncoder)(unsafe.Pointer(enc)).Fpalette_size <= int32(16) {
  36051 			v1 = int32(2)
  36052 		} else {
  36053 			v1 = int32(1)
  36054 		}
  36055 		n_lz77s = v1
  36056 		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) {
  36057 			return 0
  36058 		}
  36059 		if method == int32(6) && (*WebPConfig)(unsafe.Pointer(config)).Fquality == libc.Float32FromInt32(100) {
  36060 			do_no_cache = int32(1)
  36061 			// Go brute force on all transforms.
  36062 			**(**int32)(__ccgo_up(crunch_configs_size)) = 0
  36063 			i = 0
  36064 			for {
  36065 				if !(i < int32(kNumEntropyIx)) {
  36066 					break
  36067 				}
  36068 				// We can only apply kPalette or kPaletteAndSpatial if we can indeed use
  36069 				// a palette.
  36070 				if i != int32(kPalette) && i != int32(kPaletteAndSpatial) || use_palette != 0 {
  36071 					if use_palette != 0 && (i == int32(kPalette) || i == int32(kPaletteAndSpatial)) {
  36072 						sorting_method = 0
  36073 						for {
  36074 							if !(sorting_method < int32(kPaletteSortingNum)) {
  36075 								break
  36076 							}
  36077 							typed_sorting_method = sorting_method
  36078 							// TODO(vrabaud) kSortedDefault should be tested. It is omitted
  36079 							// for now for backward compatibility.
  36080 							if typed_sorting_method == int32(kUnusedPalette) || typed_sorting_method == int32(kSortedDefault) {
  36081 								goto _5
  36082 							}
  36083 							(**(**CrunchConfig)(__ccgo_up(crunch_configs + uintptr(**(**int32)(__ccgo_up(crunch_configs_size)))*28))).Fentropy_idx = i
  36084 							(**(**CrunchConfig)(__ccgo_up(crunch_configs + uintptr(**(**int32)(__ccgo_up(crunch_configs_size)))*28))).Fpalette_sorting_type = typed_sorting_method
  36085 							**(**int32)(__ccgo_up(crunch_configs_size)) = **(**int32)(__ccgo_up(crunch_configs_size)) + 1
  36086 							goto _5
  36087 						_5:
  36088 							;
  36089 							sorting_method = sorting_method + 1
  36090 						}
  36091 					} else {
  36092 						(**(**CrunchConfig)(__ccgo_up(crunch_configs + uintptr(**(**int32)(__ccgo_up(crunch_configs_size)))*28))).Fentropy_idx = i
  36093 						(**(**CrunchConfig)(__ccgo_up(crunch_configs + uintptr(**(**int32)(__ccgo_up(crunch_configs_size)))*28))).Fpalette_sorting_type = int32(kUnusedPalette)
  36094 						**(**int32)(__ccgo_up(crunch_configs_size)) = **(**int32)(__ccgo_up(crunch_configs_size)) + 1
  36095 					}
  36096 				}
  36097 				goto _4
  36098 			_4:
  36099 				;
  36100 				i = i + 1
  36101 			}
  36102 		} else {
  36103 			// Only choose the guessed best transform.
  36104 			**(**int32)(__ccgo_up(crunch_configs_size)) = int32(1)
  36105 			(**(**CrunchConfig)(__ccgo_up(crunch_configs))).Fentropy_idx = **(**EntropyIx)(__ccgo_up(bp))
  36106 			if use_palette != 0 {
  36107 				v1 = int32(kMinimizeDelta)
  36108 			} else {
  36109 				v1 = int32(kUnusedPalette)
  36110 			}
  36111 			(**(**CrunchConfig)(__ccgo_up(crunch_configs))).Fpalette_sorting_type = v1
  36112 			if (*WebPConfig)(unsafe.Pointer(config)).Fquality >= libc.Float32FromInt32(75) && method == int32(5) {
  36113 				// Test with and without color cache.
  36114 				do_no_cache = int32(1)
  36115 				// If we have a palette, also check in combination with spatial.
  36116 				if **(**EntropyIx)(__ccgo_up(bp)) == int32(kPalette) {
  36117 					**(**int32)(__ccgo_up(crunch_configs_size)) = int32(2)
  36118 					(**(**CrunchConfig)(__ccgo_up(crunch_configs + 1*28))).Fentropy_idx = int32(kPaletteAndSpatial)
  36119 					(**(**CrunchConfig)(__ccgo_up(crunch_configs + 1*28))).Fpalette_sorting_type = int32(kMinimizeDelta)
  36120 				}
  36121 			}
  36122 		}
  36123 	}
  36124 	// Fill in the different LZ77s.
  36125 	i = 0
  36126 	for {
  36127 		if !(i < **(**int32)(__ccgo_up(crunch_configs_size))) {
  36128 			break
  36129 		}
  36130 		j = 0
  36131 		for {
  36132 			if !(j < n_lz77s) {
  36133 				break
  36134 			}
  36135 			if j == 0 {
  36136 				v1 = int32(kLZ77Standard) | int32(kLZ77RLE)
  36137 			} else {
  36138 				v1 = int32(kLZ77Box)
  36139 			}
  36140 			(**(**CrunchSubConfig)(__ccgo_up(crunch_configs + uintptr(i)*28 + 8 + uintptr(j)*8))).Flz77 = v1
  36141 			(**(**CrunchSubConfig)(__ccgo_up(crunch_configs + uintptr(i)*28 + 8 + uintptr(j)*8))).Fdo_no_cache = do_no_cache
  36142 			goto _8
  36143 		_8:
  36144 			;
  36145 			j = j + 1
  36146 		}
  36147 		(**(**CrunchConfig)(__ccgo_up(crunch_configs + uintptr(i)*28))).Fsub_configs_size = n_lz77s
  36148 		goto _7
  36149 	_7:
  36150 		;
  36151 		i = i + 1
  36152 	}
  36153 	return int32(1)
  36154 }
  36155 
  36156 func EncoderInit(tls *libc.TLS, enc uintptr) (r int32) {
  36157 	var height, i, pix_cnt, refs_block_size, width int32
  36158 	var pic uintptr
  36159 	_, _, _, _, _, _ = height, i, pic, pix_cnt, refs_block_size, width
  36160 	pic = (*VP8LEncoder)(unsafe.Pointer(enc)).Fpic
  36161 	width = (*WebPPicture)(unsafe.Pointer(pic)).Fwidth
  36162 	height = (*WebPPicture)(unsafe.Pointer(pic)).Fheight
  36163 	pix_cnt = width * height
  36164 	// we round the block size up, so we're guaranteed to have
  36165 	// at most MAX_REFS_BLOCK_PER_IMAGE blocks used:
  36166 	refs_block_size = (pix_cnt-int32(1))/int32(MAX_REFS_BLOCK_PER_IMAGE) + int32(1)
  36167 	if !(VP8LHashChainInit(tls, enc+2312, pix_cnt) != 0) {
  36168 		return 0
  36169 	}
  36170 	i = 0
  36171 	for {
  36172 		if !(i < int32(4)) {
  36173 			break
  36174 		}
  36175 		VP8LBackwardRefsInit(tls, enc+2152+uintptr(i)*40, refs_block_size)
  36176 		goto _1
  36177 	_1:
  36178 		;
  36179 		i = i + 1
  36180 	}
  36181 	return int32(1)
  36182 }
  36183 
  36184 // C documentation
  36185 //
  36186 //	// Returns false in case of memory error.
  36187 func GetHuffBitLengthsAndCodes(tls *libc.TLS, histogram_image uintptr, huffman_codes uintptr) (r int32) {
  36188 	var bit_length, histogram_image_size, i, k, max_num_symbols, num_symbols, ok, v3, v4, v5, v7, v8 int32
  36189 	var buf_rle, codes, codes1, codes2, histo, histo1, huff_tree, lengths, mem_buf uintptr
  36190 	var total_length_size uint64_t
  36191 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  36192 	ok = 0
  36193 	total_length_size = uint64(0)
  36194 	mem_buf = libc.UintptrFromInt32(0)
  36195 	histogram_image_size = (*VP8LHistogramSet)(unsafe.Pointer(histogram_image)).Fsize
  36196 	max_num_symbols = 0
  36197 	buf_rle = libc.UintptrFromInt32(0)
  36198 	huff_tree = libc.UintptrFromInt32(0)
  36199 	// Iterate over all histograms and get the aggregate number of codes used.
  36200 	i = 0
  36201 	for {
  36202 		if !(i < histogram_image_size) {
  36203 			break
  36204 		}
  36205 		histo = **(**uintptr)(__ccgo_up((*VP8LHistogramSet)(unsafe.Pointer(histogram_image)).Fhistograms + uintptr(i)*8))
  36206 		codes = huffman_codes + uintptr(int32(5)*i)*24
  36207 		k = 0
  36208 		for {
  36209 			if !(k < int32(5)) {
  36210 				break
  36211 			}
  36212 			if k == 0 {
  36213 				v4 = (*VP8LHistogram)(unsafe.Pointer(histo)).Fpalette_code_bits
  36214 				if v4 > 0 {
  36215 					v7 = int32(1) << v4
  36216 				} else {
  36217 					v7 = 0
  36218 				}
  36219 				v5 = libc.Int32FromInt32(NUM_LITERAL_CODES) + libc.Int32FromInt32(NUM_LENGTH_CODES) + v7
  36220 				goto _6
  36221 			_6:
  36222 				v3 = v5
  36223 			} else {
  36224 				if k == int32(4) {
  36225 					v8 = int32(NUM_DISTANCE_CODES)
  36226 				} else {
  36227 					v8 = int32(256)
  36228 				}
  36229 				v3 = v8
  36230 			}
  36231 			num_symbols = v3
  36232 			(**(**HuffmanTreeCode)(__ccgo_up(codes + uintptr(k)*24))).Fnum_symbols = num_symbols
  36233 			total_length_size = total_length_size + uint64(num_symbols)
  36234 			goto _2
  36235 		_2:
  36236 			;
  36237 			k = k + 1
  36238 		}
  36239 		goto _1
  36240 	_1:
  36241 		;
  36242 		i = i + 1
  36243 	}
  36244 	// Allocate and Set Huffman codes.
  36245 	mem_buf = WebPSafeCalloc(tls, total_length_size, libc.Uint64FromInt64(1)+libc.Uint64FromInt64(2))
  36246 	if mem_buf == libc.UintptrFromInt32(0) {
  36247 		goto End
  36248 	}
  36249 	codes1 = mem_buf
  36250 	lengths = codes1 + uintptr(total_length_size)*2
  36251 	i = 0
  36252 	for {
  36253 		if !(i < int32(5)*histogram_image_size) {
  36254 			break
  36255 		}
  36256 		bit_length = (**(**HuffmanTreeCode)(__ccgo_up(huffman_codes + uintptr(i)*24))).Fnum_symbols
  36257 		(**(**HuffmanTreeCode)(__ccgo_up(huffman_codes + uintptr(i)*24))).Fcodes = codes1
  36258 		(**(**HuffmanTreeCode)(__ccgo_up(huffman_codes + uintptr(i)*24))).Fcode_lengths = lengths
  36259 		codes1 = codes1 + uintptr(bit_length)*2
  36260 		lengths = lengths + uintptr(bit_length)
  36261 		if max_num_symbols < bit_length {
  36262 			max_num_symbols = bit_length
  36263 		}
  36264 		goto _9
  36265 	_9:
  36266 		;
  36267 		i = i + 1
  36268 	}
  36269 	buf_rle = WebPSafeMalloc(tls, uint64(1), uint64(max_num_symbols))
  36270 	huff_tree = WebPSafeMalloc(tls, uint64(3)*uint64(max_num_symbols), uint64(16))
  36271 	if buf_rle == libc.UintptrFromInt32(0) || huff_tree == libc.UintptrFromInt32(0) {
  36272 		goto End
  36273 	}
  36274 	// Create Huffman trees.
  36275 	i = 0
  36276 	for {
  36277 		if !(i < histogram_image_size) {
  36278 			break
  36279 		}
  36280 		codes2 = huffman_codes + uintptr(int32(5)*i)*24
  36281 		histo1 = **(**uintptr)(__ccgo_up((*VP8LHistogramSet)(unsafe.Pointer(histogram_image)).Fhistograms + uintptr(i)*8))
  36282 		VP8LCreateHuffmanTree(tls, (*VP8LHistogram)(unsafe.Pointer(histo1)).Fliteral, int32(15), buf_rle, huff_tree, codes2+uintptr(0)*24)
  36283 		VP8LCreateHuffmanTree(tls, histo1+8, int32(15), buf_rle, huff_tree, codes2+uintptr(1)*24)
  36284 		VP8LCreateHuffmanTree(tls, histo1+1032, int32(15), buf_rle, huff_tree, codes2+uintptr(2)*24)
  36285 		VP8LCreateHuffmanTree(tls, histo1+2056, int32(15), buf_rle, huff_tree, codes2+uintptr(3)*24)
  36286 		VP8LCreateHuffmanTree(tls, histo1+3080, int32(15), buf_rle, huff_tree, codes2+uintptr(4)*24)
  36287 		goto _10
  36288 	_10:
  36289 		;
  36290 		i = i + 1
  36291 	}
  36292 	ok = int32(1)
  36293 	goto End
  36294 End:
  36295 	;
  36296 	WebPSafeFree(tls, huff_tree)
  36297 	WebPSafeFree(tls, buf_rle)
  36298 	if !(ok != 0) {
  36299 		WebPSafeFree(tls, mem_buf)
  36300 		libc.Xmemset(tls, huffman_codes, 0, uint64(int32(5)*histogram_image_size)*uint64(24))
  36301 	}
  36302 	return ok
  36303 }
  36304 
  36305 func StoreHuffmanTreeOfHuffmanTreeToBitMask(tls *libc.TLS, bw1 uintptr, code_length_bitdepth uintptr) {
  36306 	var codes_to_store, i, v4 int32
  36307 	var v2 uintptr
  36308 	var v3 uint32_t
  36309 	_, _, _, _, _ = codes_to_store, i, v2, v3, v4
  36310 	// Throw away trailing zeros:
  36311 	codes_to_store = int32(CODE_LENGTH_CODES)
  36312 	for {
  36313 		if !(codes_to_store > int32(4)) {
  36314 			break
  36315 		}
  36316 		if int32(**(**uint8_t)(__ccgo_up(code_length_bitdepth + uintptr(kStorageOrder[codes_to_store-int32(1)])))) != 0 {
  36317 			break
  36318 		}
  36319 		goto _1
  36320 	_1:
  36321 		;
  36322 		codes_to_store = codes_to_store - 1
  36323 	}
  36324 	v2 = bw1
  36325 	v3 = uint32(codes_to_store - int32(4))
  36326 	v4 = int32(4)
  36327 	if libc.Uint64FromInt64(4) == libc.Uint64FromInt32(4) {
  36328 		if v4 > libc.Int32FromInt32(0) {
  36329 			if (*VP8LBitWriter)(unsafe.Pointer(v2)).Fused >= libc.Int32FromInt32(32) {
  36330 				VP8LPutBitsFlushBits(tls, v2)
  36331 			}
  36332 			**(**vp8l_atype_t)(__ccgo_up(v2)) |= uint64(v3) << (*VP8LBitWriter)(unsafe.Pointer(v2)).Fused
  36333 			**(**int32)(__ccgo_up(v2 + 8)) += v4
  36334 		}
  36335 	} else {
  36336 		VP8LPutBitsInternal(tls, v2, v3, v4)
  36337 	}
  36338 	i = 0
  36339 	for {
  36340 		if !(i < codes_to_store) {
  36341 			break
  36342 		}
  36343 		v2 = bw1
  36344 		v3 = uint32(**(**uint8_t)(__ccgo_up(code_length_bitdepth + uintptr(kStorageOrder[i]))))
  36345 		v4 = int32(3)
  36346 		if libc.Uint64FromInt64(4) == libc.Uint64FromInt32(4) {
  36347 			if v4 > libc.Int32FromInt32(0) {
  36348 				if (*VP8LBitWriter)(unsafe.Pointer(v2)).Fused >= libc.Int32FromInt32(32) {
  36349 					VP8LPutBitsFlushBits(tls, v2)
  36350 				}
  36351 				**(**vp8l_atype_t)(__ccgo_up(v2)) |= uint64(v3) << (*VP8LBitWriter)(unsafe.Pointer(v2)).Fused
  36352 				**(**int32)(__ccgo_up(v2 + 8)) += v4
  36353 			}
  36354 		} else {
  36355 			VP8LPutBitsInternal(tls, v2, v3, v4)
  36356 		}
  36357 		goto _5
  36358 	_5:
  36359 		;
  36360 		i = i + 1
  36361 	}
  36362 }
  36363 
  36364 // RFC 1951 will calm you down if you are worried about this funny sequence.
  36365 // This sequence is tuned from that, but more weighted for lower symbol count,
  36366 // and more spiking histograms.
  36367 var kStorageOrder = [19]uint8_t{
  36368 	0:  uint8(17),
  36369 	1:  uint8(18),
  36370 	3:  uint8(1),
  36371 	4:  uint8(2),
  36372 	5:  uint8(3),
  36373 	6:  uint8(4),
  36374 	7:  uint8(5),
  36375 	8:  uint8(16),
  36376 	9:  uint8(6),
  36377 	10: uint8(7),
  36378 	11: uint8(8),
  36379 	12: uint8(9),
  36380 	13: uint8(10),
  36381 	14: uint8(11),
  36382 	15: uint8(12),
  36383 	16: uint8(13),
  36384 	17: uint8(14),
  36385 	18: uint8(15),
  36386 }
  36387 
  36388 func ClearHuffmanTreeIfOnlyOneSymbol(tls *libc.TLS, huffman_code uintptr) {
  36389 	var count, k int32
  36390 	_, _ = count, k
  36391 	count = 0
  36392 	k = 0
  36393 	for {
  36394 		if !(k < (*HuffmanTreeCode)(unsafe.Pointer(huffman_code)).Fnum_symbols) {
  36395 			break
  36396 		}
  36397 		if int32(**(**uint8_t)(__ccgo_up((*HuffmanTreeCode)(unsafe.Pointer(huffman_code)).Fcode_lengths + uintptr(k)))) != 0 {
  36398 			count = count + 1
  36399 			if count > int32(1) {
  36400 				return
  36401 			}
  36402 		}
  36403 		goto _1
  36404 	_1:
  36405 		;
  36406 		k = k + 1
  36407 	}
  36408 	k = 0
  36409 	for {
  36410 		if !(k < (*HuffmanTreeCode)(unsafe.Pointer(huffman_code)).Fnum_symbols) {
  36411 			break
  36412 		}
  36413 		**(**uint8_t)(__ccgo_up((*HuffmanTreeCode)(unsafe.Pointer(huffman_code)).Fcode_lengths + uintptr(k))) = uint8(0)
  36414 		**(**uint16_t)(__ccgo_up((*HuffmanTreeCode)(unsafe.Pointer(huffman_code)).Fcodes + uintptr(k)*2)) = uint16(0)
  36415 		goto _2
  36416 	_2:
  36417 		;
  36418 		k = k + 1
  36419 	}
  36420 }
  36421 
  36422 func StoreHuffmanTreeToBitMask(tls *libc.TLS, bw1 uintptr, tokens uintptr, num_tokens int32, huffman_code uintptr) {
  36423 	var extra_bits, i, ix, v4 int32
  36424 	var v2 uintptr
  36425 	var v3 uint32_t
  36426 	_, _, _, _, _, _ = extra_bits, i, ix, v2, v3, v4
  36427 	i = 0
  36428 	for {
  36429 		if !(i < num_tokens) {
  36430 			break
  36431 		}
  36432 		ix = int32((**(**HuffmanTreeToken)(__ccgo_up(tokens + uintptr(i)*2))).Fcode)
  36433 		extra_bits = int32((**(**HuffmanTreeToken)(__ccgo_up(tokens + uintptr(i)*2))).Fextra_bits)
  36434 		v2 = bw1
  36435 		v3 = uint32(**(**uint16_t)(__ccgo_up((*HuffmanTreeCode)(unsafe.Pointer(huffman_code)).Fcodes + uintptr(ix)*2)))
  36436 		v4 = int32(**(**uint8_t)(__ccgo_up((*HuffmanTreeCode)(unsafe.Pointer(huffman_code)).Fcode_lengths + uintptr(ix))))
  36437 		if libc.Uint64FromInt64(4) == libc.Uint64FromInt32(4) {
  36438 			if v4 > libc.Int32FromInt32(0) {
  36439 				if (*VP8LBitWriter)(unsafe.Pointer(v2)).Fused >= libc.Int32FromInt32(32) {
  36440 					VP8LPutBitsFlushBits(tls, v2)
  36441 				}
  36442 				**(**vp8l_atype_t)(__ccgo_up(v2)) |= uint64(v3) << (*VP8LBitWriter)(unsafe.Pointer(v2)).Fused
  36443 				**(**int32)(__ccgo_up(v2 + 8)) += v4
  36444 			}
  36445 		} else {
  36446 			VP8LPutBitsInternal(tls, v2, v3, v4)
  36447 		}
  36448 		switch ix {
  36449 		case int32(16):
  36450 			v2 = bw1
  36451 			v3 = uint32(extra_bits)
  36452 			v4 = int32(2)
  36453 			if libc.Uint64FromInt64(4) == libc.Uint64FromInt32(4) {
  36454 				if v4 > libc.Int32FromInt32(0) {
  36455 					if (*VP8LBitWriter)(unsafe.Pointer(v2)).Fused >= libc.Int32FromInt32(32) {
  36456 						VP8LPutBitsFlushBits(tls, v2)
  36457 					}
  36458 					**(**vp8l_atype_t)(__ccgo_up(v2)) |= uint64(v3) << (*VP8LBitWriter)(unsafe.Pointer(v2)).Fused
  36459 					**(**int32)(__ccgo_up(v2 + 8)) += v4
  36460 				}
  36461 			} else {
  36462 				VP8LPutBitsInternal(tls, v2, v3, v4)
  36463 			}
  36464 		case int32(17):
  36465 			v2 = bw1
  36466 			v3 = uint32(extra_bits)
  36467 			v4 = int32(3)
  36468 			if libc.Uint64FromInt64(4) == libc.Uint64FromInt32(4) {
  36469 				if v4 > libc.Int32FromInt32(0) {
  36470 					if (*VP8LBitWriter)(unsafe.Pointer(v2)).Fused >= libc.Int32FromInt32(32) {
  36471 						VP8LPutBitsFlushBits(tls, v2)
  36472 					}
  36473 					**(**vp8l_atype_t)(__ccgo_up(v2)) |= uint64(v3) << (*VP8LBitWriter)(unsafe.Pointer(v2)).Fused
  36474 					**(**int32)(__ccgo_up(v2 + 8)) += v4
  36475 				}
  36476 			} else {
  36477 				VP8LPutBitsInternal(tls, v2, v3, v4)
  36478 			}
  36479 		case int32(18):
  36480 			v2 = bw1
  36481 			v3 = uint32(extra_bits)
  36482 			v4 = int32(7)
  36483 			if libc.Uint64FromInt64(4) == libc.Uint64FromInt32(4) {
  36484 				if v4 > libc.Int32FromInt32(0) {
  36485 					if (*VP8LBitWriter)(unsafe.Pointer(v2)).Fused >= libc.Int32FromInt32(32) {
  36486 						VP8LPutBitsFlushBits(tls, v2)
  36487 					}
  36488 					**(**vp8l_atype_t)(__ccgo_up(v2)) |= uint64(v3) << (*VP8LBitWriter)(unsafe.Pointer(v2)).Fused
  36489 					**(**int32)(__ccgo_up(v2 + 8)) += v4
  36490 				}
  36491 			} else {
  36492 				VP8LPutBitsInternal(tls, v2, v3, v4)
  36493 			}
  36494 			break
  36495 		}
  36496 		goto _1
  36497 	_1:
  36498 		;
  36499 		i = i + 1
  36500 	}
  36501 }
  36502 
  36503 // C documentation
  36504 //
  36505 //	// 'huff_tree' and 'tokens' are pre-alloacted buffers.
  36506 func StoreFullHuffmanCode(tls *libc.TLS, bw1 uintptr, huff_tree uintptr, tokens uintptr, tree uintptr) {
  36507 	bp := tls.Alloc(192)
  36508 	defer tls.Free(192)
  36509 	var i, i1, ix, length, max_tokens, nbitpairs, nbits, num_tokens, trailing_zero_bits, trimmed_length, write_trimmed_length, v3 int32
  36510 	var v1 uintptr
  36511 	var v2 uint32_t
  36512 	var _ /* buf_rle at bp+164 */ [19]uint8_t
  36513 	var _ /* code_length_bitdepth at bp+0 */ [19]uint8_t
  36514 	var _ /* code_length_bitdepth_symbols at bp+20 */ [19]uint16_t
  36515 	var _ /* histogram at bp+88 */ [19]uint32_t
  36516 	var _ /* huffman_code at bp+64 */ HuffmanTreeCode
  36517 	_, _, _, _, _, _, _, _, _, _, _, _, _, _ = i, i1, ix, length, max_tokens, nbitpairs, nbits, num_tokens, trailing_zero_bits, trimmed_length, write_trimmed_length, v1, v2, v3
  36518 	**(**[19]uint8_t)(__ccgo_up(bp)) = [19]uint8_t{}
  36519 	**(**[19]uint16_t)(__ccgo_up(bp + 20)) = [19]uint16_t{}
  36520 	max_tokens = (*HuffmanTreeCode)(unsafe.Pointer(tree)).Fnum_symbols
  36521 	(**(**HuffmanTreeCode)(__ccgo_up(bp + 64))).Fnum_symbols = int32(CODE_LENGTH_CODES)
  36522 	(**(**HuffmanTreeCode)(__ccgo_up(bp + 64))).Fcode_lengths = bp
  36523 	(**(**HuffmanTreeCode)(__ccgo_up(bp + 64))).Fcodes = bp + 20
  36524 	v1 = bw1
  36525 	v2 = uint32(0)
  36526 	v3 = int32(1)
  36527 	if libc.Uint64FromInt64(4) == libc.Uint64FromInt32(4) {
  36528 		if v3 > libc.Int32FromInt32(0) {
  36529 			if (*VP8LBitWriter)(unsafe.Pointer(v1)).Fused >= libc.Int32FromInt32(32) {
  36530 				VP8LPutBitsFlushBits(tls, v1)
  36531 			}
  36532 			**(**vp8l_atype_t)(__ccgo_up(v1)) |= uint64(v2) << (*VP8LBitWriter)(unsafe.Pointer(v1)).Fused
  36533 			**(**int32)(__ccgo_up(v1 + 8)) += v3
  36534 		}
  36535 	} else {
  36536 		VP8LPutBitsInternal(tls, v1, v2, v3)
  36537 	}
  36538 	num_tokens = VP8LCreateCompressedHuffmanTree(tls, tree, tokens, max_tokens)
  36539 	**(**[19]uint32_t)(__ccgo_up(bp + 88)) = [19]uint32_t{}
  36540 	**(**[19]uint8_t)(__ccgo_up(bp + 164)) = [19]uint8_t{}
  36541 	i = 0
  36542 	for {
  36543 		if !(i < num_tokens) {
  36544 			break
  36545 		}
  36546 		(**(**[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
  36547 		goto _4
  36548 	_4:
  36549 		;
  36550 		i = i + 1
  36551 	}
  36552 	VP8LCreateHuffmanTree(tls, bp+88, int32(7), bp+164, huff_tree, bp+64)
  36553 	StoreHuffmanTreeOfHuffmanTreeToBitMask(tls, bw1, bp)
  36554 	ClearHuffmanTreeIfOnlyOneSymbol(tls, bp+64)
  36555 	trailing_zero_bits = 0
  36556 	trimmed_length = num_tokens
  36557 	i1 = num_tokens
  36558 	for {
  36559 		v3 = i1
  36560 		i1 = i1 - 1
  36561 		if !(v3 > 0) {
  36562 			break
  36563 		}
  36564 		ix = int32((**(**HuffmanTreeToken)(__ccgo_up(tokens + uintptr(i1)*2))).Fcode)
  36565 		if ix == 0 || ix == int32(17) || ix == int32(18) {
  36566 			trimmed_length = trimmed_length - 1 // discount trailing zeros
  36567 			trailing_zero_bits = trailing_zero_bits + int32((**(**[19]uint8_t)(__ccgo_up(bp)))[ix])
  36568 			if ix == int32(17) {
  36569 				trailing_zero_bits = trailing_zero_bits + int32(3)
  36570 			} else {
  36571 				if ix == int32(18) {
  36572 					trailing_zero_bits = trailing_zero_bits + int32(7)
  36573 				}
  36574 			}
  36575 		} else {
  36576 			break
  36577 		}
  36578 	}
  36579 	write_trimmed_length = libc.BoolInt32(trimmed_length > int32(1) && trailing_zero_bits > int32(12))
  36580 	if write_trimmed_length != 0 {
  36581 		v3 = trimmed_length
  36582 	} else {
  36583 		v3 = num_tokens
  36584 	}
  36585 	length = v3
  36586 	v1 = bw1
  36587 	v2 = uint32(write_trimmed_length)
  36588 	v3 = int32(1)
  36589 	if libc.Uint64FromInt64(4) == libc.Uint64FromInt32(4) {
  36590 		if v3 > libc.Int32FromInt32(0) {
  36591 			if (*VP8LBitWriter)(unsafe.Pointer(v1)).Fused >= libc.Int32FromInt32(32) {
  36592 				VP8LPutBitsFlushBits(tls, v1)
  36593 			}
  36594 			**(**vp8l_atype_t)(__ccgo_up(v1)) |= uint64(v2) << (*VP8LBitWriter)(unsafe.Pointer(v1)).Fused
  36595 			**(**int32)(__ccgo_up(v1 + 8)) += v3
  36596 		}
  36597 	} else {
  36598 		VP8LPutBitsInternal(tls, v1, v2, v3)
  36599 	}
  36600 	if write_trimmed_length != 0 {
  36601 		if trimmed_length == int32(2) {
  36602 			v1 = bw1
  36603 			v2 = uint32(0)
  36604 			v3 = libc.Int32FromInt32(3) + libc.Int32FromInt32(2)
  36605 			if libc.Uint64FromInt64(4) == libc.Uint64FromInt32(4) {
  36606 				if v3 > libc.Int32FromInt32(0) {
  36607 					if (*VP8LBitWriter)(unsafe.Pointer(v1)).Fused >= libc.Int32FromInt32(32) {
  36608 						VP8LPutBitsFlushBits(tls, v1)
  36609 					}
  36610 					**(**vp8l_atype_t)(__ccgo_up(v1)) |= uint64(v2) << (*VP8LBitWriter)(unsafe.Pointer(v1)).Fused
  36611 					**(**int32)(__ccgo_up(v1 + 8)) += v3
  36612 				}
  36613 			} else {
  36614 				VP8LPutBitsInternal(tls, v1, v2, v3)
  36615 			} // nbitpairs=1, trimmed_length=2
  36616 		} else {
  36617 			v3 = int32(31) ^ libc.X__builtin_clz(tls, uint32(trimmed_length-int32(2)))
  36618 			goto _14
  36619 		_14:
  36620 			nbits = v3
  36621 			nbitpairs = nbits/int32(2) + int32(1)
  36622 			v1 = bw1
  36623 			v2 = uint32(nbitpairs - int32(1))
  36624 			v3 = int32(3)
  36625 			if libc.Uint64FromInt64(4) == libc.Uint64FromInt32(4) {
  36626 				if v3 > libc.Int32FromInt32(0) {
  36627 					if (*VP8LBitWriter)(unsafe.Pointer(v1)).Fused >= libc.Int32FromInt32(32) {
  36628 						VP8LPutBitsFlushBits(tls, v1)
  36629 					}
  36630 					**(**vp8l_atype_t)(__ccgo_up(v1)) |= uint64(v2) << (*VP8LBitWriter)(unsafe.Pointer(v1)).Fused
  36631 					**(**int32)(__ccgo_up(v1 + 8)) += v3
  36632 				}
  36633 			} else {
  36634 				VP8LPutBitsInternal(tls, v1, v2, v3)
  36635 			}
  36636 			v1 = bw1
  36637 			v2 = uint32(trimmed_length - int32(2))
  36638 			v3 = nbitpairs * int32(2)
  36639 			if libc.Uint64FromInt64(4) == libc.Uint64FromInt32(4) {
  36640 				if v3 > libc.Int32FromInt32(0) {
  36641 					if (*VP8LBitWriter)(unsafe.Pointer(v1)).Fused >= libc.Int32FromInt32(32) {
  36642 						VP8LPutBitsFlushBits(tls, v1)
  36643 					}
  36644 					**(**vp8l_atype_t)(__ccgo_up(v1)) |= uint64(v2) << (*VP8LBitWriter)(unsafe.Pointer(v1)).Fused
  36645 					**(**int32)(__ccgo_up(v1 + 8)) += v3
  36646 				}
  36647 			} else {
  36648 				VP8LPutBitsInternal(tls, v1, v2, v3)
  36649 			}
  36650 		}
  36651 	}
  36652 	StoreHuffmanTreeToBitMask(tls, bw1, tokens, length, bp+64)
  36653 }
  36654 
  36655 // C documentation
  36656 //
  36657 //	// 'huff_tree' and 'tokens' are pre-alloacted buffers.
  36658 func StoreHuffmanCode(tls *libc.TLS, bw1 uintptr, huff_tree uintptr, tokens uintptr, huffman_code uintptr) {
  36659 	var count, i, kMaxBits, kMaxSymbol, v4 int32
  36660 	var symbols [2]int32
  36661 	var v2 uintptr
  36662 	var v3 uint32_t
  36663 	_, _, _, _, _, _, _, _ = count, i, kMaxBits, kMaxSymbol, symbols, v2, v3, v4
  36664 	count = 0
  36665 	symbols = [2]int32{}
  36666 	kMaxBits = int32(8)
  36667 	kMaxSymbol = int32(1) << kMaxBits
  36668 	// Check whether it's a small tree.
  36669 	i = 0
  36670 	for {
  36671 		if !(i < (*HuffmanTreeCode)(unsafe.Pointer(huffman_code)).Fnum_symbols && count < int32(3)) {
  36672 			break
  36673 		}
  36674 		if int32(**(**uint8_t)(__ccgo_up((*HuffmanTreeCode)(unsafe.Pointer(huffman_code)).Fcode_lengths + uintptr(i)))) != 0 {
  36675 			if count < int32(2) {
  36676 				symbols[count] = i
  36677 			}
  36678 			count = count + 1
  36679 		}
  36680 		goto _1
  36681 	_1:
  36682 		;
  36683 		i = i + 1
  36684 	}
  36685 	if count == 0 { // emit minimal tree for empty cases
  36686 		// bits: small tree marker: 1, count-1: 0, large 8-bit code: 0, code: 0
  36687 		v2 = bw1
  36688 		v3 = uint32(0x01)
  36689 		v4 = int32(4)
  36690 		if libc.Uint64FromInt64(4) == libc.Uint64FromInt32(4) {
  36691 			if v4 > libc.Int32FromInt32(0) {
  36692 				if (*VP8LBitWriter)(unsafe.Pointer(v2)).Fused >= libc.Int32FromInt32(32) {
  36693 					VP8LPutBitsFlushBits(tls, v2)
  36694 				}
  36695 				**(**vp8l_atype_t)(__ccgo_up(v2)) |= uint64(v3) << (*VP8LBitWriter)(unsafe.Pointer(v2)).Fused
  36696 				**(**int32)(__ccgo_up(v2 + 8)) += v4
  36697 			}
  36698 		} else {
  36699 			VP8LPutBitsInternal(tls, v2, v3, v4)
  36700 		}
  36701 	} else {
  36702 		if count <= int32(2) && symbols[0] < kMaxSymbol && symbols[int32(1)] < kMaxSymbol {
  36703 			v2 = bw1
  36704 			v3 = uint32(1)
  36705 			v4 = int32(1)
  36706 			if libc.Uint64FromInt64(4) == libc.Uint64FromInt32(4) {
  36707 				if v4 > libc.Int32FromInt32(0) {
  36708 					if (*VP8LBitWriter)(unsafe.Pointer(v2)).Fused >= libc.Int32FromInt32(32) {
  36709 						VP8LPutBitsFlushBits(tls, v2)
  36710 					}
  36711 					**(**vp8l_atype_t)(__ccgo_up(v2)) |= uint64(v3) << (*VP8LBitWriter)(unsafe.Pointer(v2)).Fused
  36712 					**(**int32)(__ccgo_up(v2 + 8)) += v4
  36713 				}
  36714 			} else {
  36715 				VP8LPutBitsInternal(tls, v2, v3, v4)
  36716 			} // Small tree marker to encode 1 or 2 symbols.
  36717 			v2 = bw1
  36718 			v3 = uint32(count - int32(1))
  36719 			v4 = int32(1)
  36720 			if libc.Uint64FromInt64(4) == libc.Uint64FromInt32(4) {
  36721 				if v4 > libc.Int32FromInt32(0) {
  36722 					if (*VP8LBitWriter)(unsafe.Pointer(v2)).Fused >= libc.Int32FromInt32(32) {
  36723 						VP8LPutBitsFlushBits(tls, v2)
  36724 					}
  36725 					**(**vp8l_atype_t)(__ccgo_up(v2)) |= uint64(v3) << (*VP8LBitWriter)(unsafe.Pointer(v2)).Fused
  36726 					**(**int32)(__ccgo_up(v2 + 8)) += v4
  36727 				}
  36728 			} else {
  36729 				VP8LPutBitsInternal(tls, v2, v3, v4)
  36730 			}
  36731 			if symbols[0] <= int32(1) {
  36732 				v2 = bw1
  36733 				v3 = uint32(0)
  36734 				v4 = int32(1)
  36735 				if libc.Uint64FromInt64(4) == libc.Uint64FromInt32(4) {
  36736 					if v4 > libc.Int32FromInt32(0) {
  36737 						if (*VP8LBitWriter)(unsafe.Pointer(v2)).Fused >= libc.Int32FromInt32(32) {
  36738 							VP8LPutBitsFlushBits(tls, v2)
  36739 						}
  36740 						**(**vp8l_atype_t)(__ccgo_up(v2)) |= uint64(v3) << (*VP8LBitWriter)(unsafe.Pointer(v2)).Fused
  36741 						**(**int32)(__ccgo_up(v2 + 8)) += v4
  36742 					}
  36743 				} else {
  36744 					VP8LPutBitsInternal(tls, v2, v3, v4)
  36745 				} // Code bit for small (1 bit) symbol value.
  36746 				v2 = bw1
  36747 				v3 = uint32(symbols[0])
  36748 				v4 = int32(1)
  36749 				if libc.Uint64FromInt64(4) == libc.Uint64FromInt32(4) {
  36750 					if v4 > libc.Int32FromInt32(0) {
  36751 						if (*VP8LBitWriter)(unsafe.Pointer(v2)).Fused >= libc.Int32FromInt32(32) {
  36752 							VP8LPutBitsFlushBits(tls, v2)
  36753 						}
  36754 						**(**vp8l_atype_t)(__ccgo_up(v2)) |= uint64(v3) << (*VP8LBitWriter)(unsafe.Pointer(v2)).Fused
  36755 						**(**int32)(__ccgo_up(v2 + 8)) += v4
  36756 					}
  36757 				} else {
  36758 					VP8LPutBitsInternal(tls, v2, v3, v4)
  36759 				}
  36760 			} else {
  36761 				v2 = bw1
  36762 				v3 = uint32(1)
  36763 				v4 = int32(1)
  36764 				if libc.Uint64FromInt64(4) == libc.Uint64FromInt32(4) {
  36765 					if v4 > libc.Int32FromInt32(0) {
  36766 						if (*VP8LBitWriter)(unsafe.Pointer(v2)).Fused >= libc.Int32FromInt32(32) {
  36767 							VP8LPutBitsFlushBits(tls, v2)
  36768 						}
  36769 						**(**vp8l_atype_t)(__ccgo_up(v2)) |= uint64(v3) << (*VP8LBitWriter)(unsafe.Pointer(v2)).Fused
  36770 						**(**int32)(__ccgo_up(v2 + 8)) += v4
  36771 					}
  36772 				} else {
  36773 					VP8LPutBitsInternal(tls, v2, v3, v4)
  36774 				}
  36775 				v2 = bw1
  36776 				v3 = uint32(symbols[0])
  36777 				v4 = int32(8)
  36778 				if libc.Uint64FromInt64(4) == libc.Uint64FromInt32(4) {
  36779 					if v4 > libc.Int32FromInt32(0) {
  36780 						if (*VP8LBitWriter)(unsafe.Pointer(v2)).Fused >= libc.Int32FromInt32(32) {
  36781 							VP8LPutBitsFlushBits(tls, v2)
  36782 						}
  36783 						**(**vp8l_atype_t)(__ccgo_up(v2)) |= uint64(v3) << (*VP8LBitWriter)(unsafe.Pointer(v2)).Fused
  36784 						**(**int32)(__ccgo_up(v2 + 8)) += v4
  36785 					}
  36786 				} else {
  36787 					VP8LPutBitsInternal(tls, v2, v3, v4)
  36788 				}
  36789 			}
  36790 			if count == int32(2) {
  36791 				v2 = bw1
  36792 				v3 = uint32(symbols[int32(1)])
  36793 				v4 = int32(8)
  36794 				if libc.Uint64FromInt64(4) == libc.Uint64FromInt32(4) {
  36795 					if v4 > libc.Int32FromInt32(0) {
  36796 						if (*VP8LBitWriter)(unsafe.Pointer(v2)).Fused >= libc.Int32FromInt32(32) {
  36797 							VP8LPutBitsFlushBits(tls, v2)
  36798 						}
  36799 						**(**vp8l_atype_t)(__ccgo_up(v2)) |= uint64(v3) << (*VP8LBitWriter)(unsafe.Pointer(v2)).Fused
  36800 						**(**int32)(__ccgo_up(v2 + 8)) += v4
  36801 					}
  36802 				} else {
  36803 					VP8LPutBitsInternal(tls, v2, v3, v4)
  36804 				}
  36805 			}
  36806 		} else {
  36807 			StoreFullHuffmanCode(tls, bw1, huff_tree, tokens, huffman_code)
  36808 		}
  36809 	}
  36810 }
  36811 
  36812 func WriteHuffmanCode(tls *libc.TLS, bw1 uintptr, code uintptr, code_index int32) {
  36813 	var depth, symbol, v3 int32
  36814 	var v1 uintptr
  36815 	var v2 uint32_t
  36816 	_, _, _, _, _ = depth, symbol, v1, v2, v3
  36817 	depth = int32(**(**uint8_t)(__ccgo_up((*HuffmanTreeCode)(unsafe.Pointer(code)).Fcode_lengths + uintptr(code_index))))
  36818 	symbol = int32(**(**uint16_t)(__ccgo_up((*HuffmanTreeCode)(unsafe.Pointer(code)).Fcodes + uintptr(code_index)*2)))
  36819 	v1 = bw1
  36820 	v2 = uint32(symbol)
  36821 	v3 = depth
  36822 	if libc.Uint64FromInt64(4) == libc.Uint64FromInt32(4) {
  36823 		if v3 > libc.Int32FromInt32(0) {
  36824 			if (*VP8LBitWriter)(unsafe.Pointer(v1)).Fused >= libc.Int32FromInt32(32) {
  36825 				VP8LPutBitsFlushBits(tls, v1)
  36826 			}
  36827 			**(**vp8l_atype_t)(__ccgo_up(v1)) |= uint64(v2) << (*VP8LBitWriter)(unsafe.Pointer(v1)).Fused
  36828 			**(**int32)(__ccgo_up(v1 + 8)) += v3
  36829 		}
  36830 	} else {
  36831 		VP8LPutBitsInternal(tls, v1, v2, v3)
  36832 	}
  36833 }
  36834 
  36835 func WriteHuffmanCodeWithExtraBits(tls *libc.TLS, bw1 uintptr, code uintptr, code_index int32, bits1 int32, n_bits1 int32) {
  36836 	var depth, symbol, v3 int32
  36837 	var v1 uintptr
  36838 	var v2 uint32_t
  36839 	_, _, _, _, _ = depth, symbol, v1, v2, v3
  36840 	depth = int32(**(**uint8_t)(__ccgo_up((*HuffmanTreeCode)(unsafe.Pointer(code)).Fcode_lengths + uintptr(code_index))))
  36841 	symbol = int32(**(**uint16_t)(__ccgo_up((*HuffmanTreeCode)(unsafe.Pointer(code)).Fcodes + uintptr(code_index)*2)))
  36842 	v1 = bw1
  36843 	v2 = uint32(bits1<<depth | symbol)
  36844 	v3 = depth + n_bits1
  36845 	if libc.Uint64FromInt64(4) == libc.Uint64FromInt32(4) {
  36846 		if v3 > libc.Int32FromInt32(0) {
  36847 			if (*VP8LBitWriter)(unsafe.Pointer(v1)).Fused >= libc.Int32FromInt32(32) {
  36848 				VP8LPutBitsFlushBits(tls, v1)
  36849 			}
  36850 			**(**vp8l_atype_t)(__ccgo_up(v1)) |= uint64(v2) << (*VP8LBitWriter)(unsafe.Pointer(v1)).Fused
  36851 			**(**int32)(__ccgo_up(v1 + 8)) += v3
  36852 		}
  36853 	} else {
  36854 		VP8LPutBitsInternal(tls, v1, v2, v3)
  36855 	}
  36856 }
  36857 
  36858 func StoreImageToBitMask(tls *libc.TLS, bw1 uintptr, width int32, histo_bits int32, refs uintptr, histogram_symbols uintptr, huffman_codes uintptr, pic uintptr) (r int32) {
  36859 	bp := tls.Alloc(48)
  36860 	defer tls.Free(48)
  36861 	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
  36862 	var codes, v, v20, v21, v22, v24 uintptr
  36863 	var prefix_code VP8LPrefixCode
  36864 	var v1 uint32
  36865 	var v2, v3 uint32_t
  36866 	var _ /* bits at bp+24 */ int32
  36867 	var _ /* c at bp+0 */ VP8LRefsCursor
  36868 	var _ /* code at bp+32 */ int32
  36869 	var _ /* n_bits at bp+28 */ int32
  36870 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  36871 	if histo_bits != 0 {
  36872 		v2 = uint32(histo_bits)
  36873 		v3 = (uint32(width) + uint32(libc.Int32FromInt32(1)<<v2) - uint32(1)) >> v2
  36874 		goto _4
  36875 	_4:
  36876 		v1 = v3
  36877 	} else {
  36878 		v1 = uint32(1)
  36879 	}
  36880 	histo_xsize = int32(v1)
  36881 	if histo_bits == 0 {
  36882 		v5 = 0
  36883 	} else {
  36884 		v5 = -(int32(1) << histo_bits)
  36885 	}
  36886 	tile_mask = v5
  36887 	// x and y trace the position in the image.
  36888 	x = 0
  36889 	y = 0
  36890 	tile_x = x & tile_mask
  36891 	tile_y = y & tile_mask
  36892 	histogram_ix = int32(**(**uint32_t)(__ccgo_up(histogram_symbols)) >> libc.Int32FromInt32(8) & uint32(0xffff))
  36893 	codes = huffman_codes + uintptr(int32(5)*histogram_ix)*24
  36894 	**(**VP8LRefsCursor)(__ccgo_up(bp)) = VP8LRefsCursorInit(tls, refs)
  36895 	for {
  36896 		v6 = libc.BoolInt32((*VP8LRefsCursor)(unsafe.Pointer(bp)).Fcur_pos != libc.UintptrFromInt32(0))
  36897 		goto _7
  36898 	_7:
  36899 		if !(v6 != 0) {
  36900 			break
  36901 		}
  36902 		v = (**(**VP8LRefsCursor)(__ccgo_up(bp))).Fcur_pos
  36903 		if tile_x != x&tile_mask || tile_y != y&tile_mask {
  36904 			tile_x = x & tile_mask
  36905 			tile_y = y & tile_mask
  36906 			histogram_ix = int32(**(**uint32_t)(__ccgo_up(histogram_symbols + uintptr(y>>histo_bits*histo_xsize+x>>histo_bits)*4)) >> libc.Int32FromInt32(8) & uint32(0xffff))
  36907 			codes = huffman_codes + uintptr(int32(5)*histogram_ix)*24
  36908 		}
  36909 		v5 = libc.BoolInt32(int32((*PixOrCopy)(unsafe.Pointer(v)).Fmode) == int32(kLiteral))
  36910 		goto _9
  36911 	_9:
  36912 		if v5 != 0 {
  36913 			k = 0
  36914 			for {
  36915 				if !(k < int32(4)) {
  36916 					break
  36917 				}
  36918 				v2 = (*PixOrCopy)(unsafe.Pointer(v)).Fargb_or_distance >> (int32(order[k]) * libc.Int32FromInt32(8)) & uint32(0xff)
  36919 				goto _12
  36920 			_12:
  36921 				code2 = int32(v2)
  36922 				WriteHuffmanCode(tls, bw1, codes+uintptr(k)*24, code2)
  36923 				goto _10
  36924 			_10:
  36925 				;
  36926 				k = k + 1
  36927 			}
  36928 		} else {
  36929 			v5 = libc.BoolInt32(int32((*PixOrCopy)(unsafe.Pointer(v)).Fmode) == int32(kCacheIdx))
  36930 			goto _14
  36931 		_14:
  36932 			if v5 != 0 {
  36933 				v2 = (*PixOrCopy)(unsafe.Pointer(v)).Fargb_or_distance
  36934 				goto _16
  36935 			_16:
  36936 				code3 = int32(v2)
  36937 				literal_ix = libc.Int32FromInt32(256) + libc.Int32FromInt32(NUM_LENGTH_CODES) + code3
  36938 				WriteHuffmanCode(tls, bw1, codes, literal_ix)
  36939 			} else {
  36940 				v2 = (*PixOrCopy)(unsafe.Pointer(v)).Fargb_or_distance
  36941 				goto _18
  36942 			_18:
  36943 				distance2 = int32(v2)
  36944 				v5 = int32((*PixOrCopy)(unsafe.Pointer(v)).Flen1)
  36945 				v20 = bp + 32
  36946 				v21 = bp + 28
  36947 				v22 = bp + 24
  36948 				if v5 < libc.Int32FromInt32(PREFIX_LOOKUP_IDX_MAX) {
  36949 					prefix_code = kPrefixEncodeCode[v5]
  36950 					**(**int32)(__ccgo_up(v20)) = int32(prefix_code.Fcode)
  36951 					**(**int32)(__ccgo_up(v21)) = int32(prefix_code.Fextra_bits)
  36952 					**(**int32)(__ccgo_up(v22)) = int32(kPrefixEncodeExtraBitsValue[v5])
  36953 				} else {
  36954 					v6 = v5
  36955 					v24 = v21
  36956 					v6 = v6 - 1
  36957 					v8 = v6
  36958 					v13 = int32(31) ^ libc.X__builtin_clz(tls, uint32(v8))
  36959 					goto _27
  36960 				_27:
  36961 					highest_bit = v13
  36962 					second_highest_bit = v6 >> (highest_bit - int32(1)) & int32(1)
  36963 					**(**int32)(__ccgo_up(v24)) = highest_bit - int32(1)
  36964 					**(**int32)(__ccgo_up(v22)) = v6 & (int32(1)<<**(**int32)(__ccgo_up(v24)) - int32(1))
  36965 					**(**int32)(__ccgo_up(v20)) = int32(2)*highest_bit + second_highest_bit
  36966 				}
  36967 				WriteHuffmanCodeWithExtraBits(tls, bw1, codes, int32(256)+**(**int32)(__ccgo_up(bp + 32)), **(**int32)(__ccgo_up(bp + 24)), **(**int32)(__ccgo_up(bp + 28)))
  36968 				// Don't write the distance with the extra bits code since
  36969 				// the distance can be up to 18 bits of extra bits, and the prefix
  36970 				// 15 bits, totaling to 33, and our PutBits only supports up to 32 bits.
  36971 				v5 = distance2
  36972 				v20 = bp + 32
  36973 				v21 = bp + 28
  36974 				v22 = bp + 24
  36975 				if v5 < libc.Int32FromInt32(PREFIX_LOOKUP_IDX_MAX) {
  36976 					prefix_code = kPrefixEncodeCode[v5]
  36977 					**(**int32)(__ccgo_up(v20)) = int32(prefix_code.Fcode)
  36978 					**(**int32)(__ccgo_up(v21)) = int32(prefix_code.Fextra_bits)
  36979 					**(**int32)(__ccgo_up(v22)) = int32(kPrefixEncodeExtraBitsValue[v5])
  36980 				} else {
  36981 					v6 = v5
  36982 					v24 = v21
  36983 					v6 = v6 - 1
  36984 					v8 = v6
  36985 					v13 = int32(31) ^ libc.X__builtin_clz(tls, uint32(v8))
  36986 					goto _36
  36987 				_36:
  36988 					highest_bit = v13
  36989 					second_highest_bit = v6 >> (highest_bit - int32(1)) & int32(1)
  36990 					**(**int32)(__ccgo_up(v24)) = highest_bit - int32(1)
  36991 					**(**int32)(__ccgo_up(v22)) = v6 & (int32(1)<<**(**int32)(__ccgo_up(v24)) - int32(1))
  36992 					**(**int32)(__ccgo_up(v20)) = int32(2)*highest_bit + second_highest_bit
  36993 				}
  36994 				WriteHuffmanCode(tls, bw1, codes+uintptr(4)*24, **(**int32)(__ccgo_up(bp + 32)))
  36995 				v20 = bw1
  36996 				v2 = uint32(**(**int32)(__ccgo_up(bp + 24)))
  36997 				v5 = **(**int32)(__ccgo_up(bp + 28))
  36998 				if libc.Uint64FromInt64(4) == libc.Uint64FromInt32(4) {
  36999 					if v5 > libc.Int32FromInt32(0) {
  37000 						if (*VP8LBitWriter)(unsafe.Pointer(v20)).Fused >= libc.Int32FromInt32(32) {
  37001 							VP8LPutBitsFlushBits(tls, v20)
  37002 						}
  37003 						**(**vp8l_atype_t)(__ccgo_up(v20)) |= uint64(v2) << (*VP8LBitWriter)(unsafe.Pointer(v20)).Fused
  37004 						**(**int32)(__ccgo_up(v20 + 8)) += v5
  37005 					}
  37006 				} else {
  37007 					VP8LPutBitsInternal(tls, v20, v2, v5)
  37008 				}
  37009 			}
  37010 		}
  37011 		v2 = uint32((*PixOrCopy)(unsafe.Pointer(v)).Flen1)
  37012 		goto _41
  37013 	_41:
  37014 		x = int32(uint32(x) + v2)
  37015 		for x >= width {
  37016 			x = x - width
  37017 			y = y + 1
  37018 		}
  37019 		v20 = bp
  37020 		v22 = v20
  37021 		*(*uintptr)(unsafe.Pointer(v22)) += 8
  37022 		v21 = *(*uintptr)(unsafe.Pointer(v22))
  37023 		if v21 == (*VP8LRefsCursor)(unsafe.Pointer(v20)).Flast_pos {
  37024 			VP8LRefsCursorNextBlock(tls, v20)
  37025 		}
  37026 	}
  37027 	if (*VP8LBitWriter)(unsafe.Pointer(bw1)).Ferror1 != 0 {
  37028 		return WebPEncodingSetError(tls, pic, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  37029 	}
  37030 	return int32(1)
  37031 }
  37032 
  37033 var order = [4]uint8_t{
  37034 	0: uint8(1),
  37035 	1: uint8(2),
  37036 	3: uint8(3),
  37037 }
  37038 
  37039 // C documentation
  37040 //
  37041 //	// Special case of EncodeImageInternal() for cache-bits=0, histo_bits=31.
  37042 //	// pic and percent are for progress.
  37043 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) {
  37044 	bp := tls.Alloc(128)
  37045 	defer tls.Free(128)
  37046 	var codes, codes1, histogram_image, huff_tree, refs, tokens, v1 uintptr
  37047 	var i, max_tokens, v3 int32
  37048 	var v2 uint32_t
  37049 	var _ /* cache_bits at bp+124 */ int32
  37050 	var _ /* histogram_symbols at bp+120 */ [1]uint32_t
  37051 	var _ /* huffman_codes at bp+0 */ [5]HuffmanTreeCode
  37052 	_, _, _, _, _, _, _, _, _, _, _ = codes, codes1, histogram_image, huff_tree, i, max_tokens, refs, tokens, v1, v2, v3
  37053 	max_tokens = 0
  37054 	tokens = libc.UintptrFromInt32(0)
  37055 	**(**[5]HuffmanTreeCode)(__ccgo_up(bp)) = [5]HuffmanTreeCode{}
  37056 	**(**[1]uint32_t)(__ccgo_up(bp + 120)) = [1]uint32_t{} // only one tree, one symbol
  37057 	**(**int32)(__ccgo_up(bp + 124)) = 0
  37058 	histogram_image = libc.UintptrFromInt32(0)
  37059 	huff_tree = WebPSafeMalloc(tls, libc.Uint64FromUint64(3)*libc.Uint64FromInt32(CODE_LENGTH_CODES), uint64(16))
  37060 	if huff_tree == libc.UintptrFromInt32(0) {
  37061 		WebPEncodingSetError(tls, pic, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  37062 		goto Error
  37063 	}
  37064 	// Calculate backward references from ARGB image.
  37065 	if !(VP8LHashChainFill(tls, hash_chain, quality, argb, width, height, low_effort, pic, percent_range/int32(2), percent) != 0) {
  37066 		goto Error
  37067 	}
  37068 	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) {
  37069 		goto Error
  37070 	}
  37071 	refs = refs_array
  37072 	histogram_image = VP8LAllocateHistogramSet(tls, int32(1), **(**int32)(__ccgo_up(bp + 124)))
  37073 	if histogram_image == libc.UintptrFromInt32(0) {
  37074 		WebPEncodingSetError(tls, pic, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  37075 		goto Error
  37076 	}
  37077 	VP8LHistogramSetClear(tls, histogram_image)
  37078 	// Build histogram image and symbols from backward references.
  37079 	VP8LHistogramStoreRefs(tls, refs, libc.UintptrFromInt32(0), 0, **(**uintptr)(__ccgo_up((*VP8LHistogramSet)(unsafe.Pointer(histogram_image)).Fhistograms)))
  37080 	// Create Huffman bit lengths and codes for each histogram image.
  37081 	if !(GetHuffBitLengthsAndCodes(tls, histogram_image, bp) != 0) {
  37082 		WebPEncodingSetError(tls, pic, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  37083 		goto Error
  37084 	}
  37085 	// No color cache, no Huffman image.
  37086 	v1 = bw1
  37087 	v2 = uint32(0)
  37088 	v3 = int32(1)
  37089 	if libc.Uint64FromInt64(4) == libc.Uint64FromInt32(4) {
  37090 		if v3 > libc.Int32FromInt32(0) {
  37091 			if (*VP8LBitWriter)(unsafe.Pointer(v1)).Fused >= libc.Int32FromInt32(32) {
  37092 				VP8LPutBitsFlushBits(tls, v1)
  37093 			}
  37094 			**(**vp8l_atype_t)(__ccgo_up(v1)) |= uint64(v2) << (*VP8LBitWriter)(unsafe.Pointer(v1)).Fused
  37095 			**(**int32)(__ccgo_up(v1 + 8)) += v3
  37096 		}
  37097 	} else {
  37098 		VP8LPutBitsInternal(tls, v1, v2, v3)
  37099 	}
  37100 	// Find maximum number of symbols for the huffman tree-set.
  37101 	i = 0
  37102 	for {
  37103 		if !(i < int32(5)) {
  37104 			break
  37105 		}
  37106 		codes = bp + uintptr(i)*24
  37107 		if max_tokens < (*HuffmanTreeCode)(unsafe.Pointer(codes)).Fnum_symbols {
  37108 			max_tokens = (*HuffmanTreeCode)(unsafe.Pointer(codes)).Fnum_symbols
  37109 		}
  37110 		goto _4
  37111 	_4:
  37112 		;
  37113 		i = i + 1
  37114 	}
  37115 	tokens = WebPSafeMalloc(tls, uint64(max_tokens), uint64(2))
  37116 	if tokens == libc.UintptrFromInt32(0) {
  37117 		WebPEncodingSetError(tls, pic, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  37118 		goto Error
  37119 	}
  37120 	// Store Huffman codes.
  37121 	i = 0
  37122 	for {
  37123 		if !(i < int32(5)) {
  37124 			break
  37125 		}
  37126 		codes1 = bp + uintptr(i)*24
  37127 		StoreHuffmanCode(tls, bw1, huff_tree, tokens, codes1)
  37128 		ClearHuffmanTreeIfOnlyOneSymbol(tls, codes1)
  37129 		goto _5
  37130 	_5:
  37131 		;
  37132 		i = i + 1
  37133 	}
  37134 	// Store actual literals.
  37135 	if !(StoreImageToBitMask(tls, bw1, width, 0, refs, bp+120, bp, pic) != 0) {
  37136 		goto Error
  37137 	}
  37138 	goto Error
  37139 Error:
  37140 	;
  37141 	WebPSafeFree(tls, tokens)
  37142 	WebPSafeFree(tls, huff_tree)
  37143 	VP8LFreeHistogramSet(tls, histogram_image)
  37144 	WebPSafeFree(tls, (**(**[5]HuffmanTreeCode)(__ccgo_up(bp)))[0].Fcodes)
  37145 	return libc.BoolInt32((*WebPPicture)(unsafe.Pointer(pic)).Ferror_code == int32(VP8_ENC_OK))
  37146 }
  37147 
  37148 // C documentation
  37149 //
  37150 //	// pic and percent are for progress.
  37151 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) {
  37152 	bp := tls.Alloc(128)
  37153 	defer tls.Free(128)
  37154 	var bit_array_size, bw_size_best, v37, v40 size_t
  37155 	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
  37156 	var codes, codes1, histogram_argb, histogram_image, huff_tree, huffman_codes, sub_config, tmp_histo, tokens, v12, v15 uintptr
  37157 	var histogram_image_size, histogram_image_xysize, i, v1, v2, v4, v5 uint32_t
  37158 	var _ /* bw_best at bp+48 */ VP8LBitWriter
  37159 	var _ /* bw_init at bp+0 */ VP8LBitWriter
  37160 	var _ /* cache_bits_best at bp+112 */ int32
  37161 	var _ /* hash_chain_histogram at bp+96 */ VP8LHashChain
  37162 	var _ /* histogram_bits at bp+116 */ int32
  37163 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  37164 	v1 = uint32(histogram_bits_in)
  37165 	v2 = (uint32(width) + uint32(libc.Int32FromInt32(1)<<v1) - uint32(1)) >> v1
  37166 	goto _3
  37167 _3:
  37168 	v4 = uint32(histogram_bits_in)
  37169 	v5 = (uint32(height) + uint32(libc.Int32FromInt32(1)<<v4) - uint32(1)) >> v4
  37170 	goto _6
  37171 _6:
  37172 	histogram_image_xysize = v2 * v5
  37173 	remaining_percent = percent_range
  37174 	percent_start = **(**int32)(__ccgo_up(percent))
  37175 	histogram_image = libc.UintptrFromInt32(0)
  37176 	tmp_histo = libc.UintptrFromInt32(0)
  37177 	histogram_image_size = uint32(0)
  37178 	bit_array_size = uint64(0)
  37179 	huff_tree = WebPSafeMalloc(tls, libc.Uint64FromUint64(3)*libc.Uint64FromInt32(CODE_LENGTH_CODES), uint64(16))
  37180 	tokens = libc.UintptrFromInt32(0)
  37181 	huffman_codes = libc.UintptrFromInt32(0)
  37182 	histogram_argb = WebPSafeMalloc(tls, uint64(histogram_image_xysize), uint64(4))
  37183 	**(**VP8LBitWriter)(__ccgo_up(bp)) = **(**VP8LBitWriter)(__ccgo_up(bw2)) // histogram image hash chain
  37184 	bw_size_best = ^libc.Uint64FromInt32(0)
  37185 	libc.Xmemset(tls, bp+96, 0, uint64(16))
  37186 	if !(VP8LBitWriterInit(tls, bp+48, uint64(0)) != 0) {
  37187 		WebPEncodingSetError(tls, pic, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  37188 		goto Error
  37189 	}
  37190 	// Make sure we can allocate the different objects.
  37191 	if huff_tree == libc.UintptrFromInt32(0) || histogram_argb == libc.UintptrFromInt32(0) || !(VP8LHashChainInit(tls, bp+96, int32(histogram_image_xysize)) != 0) {
  37192 		WebPEncodingSetError(tls, pic, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  37193 		goto Error
  37194 	}
  37195 	percent_range = remaining_percent / int32(5)
  37196 	if !(VP8LHashChainFill(tls, hash_chain, quality, argb, width, height, low_effort, pic, percent_range, percent) != 0) {
  37197 		goto Error
  37198 	}
  37199 	percent_start = percent_start + percent_range
  37200 	remaining_percent = remaining_percent - percent_range
  37201 	// If the value is different from zero, it has been set during the palette
  37202 	// analysis.
  37203 	if **(**int32)(__ccgo_up(cache_bits)) == 0 {
  37204 		v7 = int32(MAX_COLOR_CACHE_BITS)
  37205 	} else {
  37206 		v7 = **(**int32)(__ccgo_up(cache_bits))
  37207 	}
  37208 	cache_bits_init = v7
  37209 	// If several iterations will happen, clone into bw_best.
  37210 	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) {
  37211 		WebPEncodingSetError(tls, pic, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  37212 		goto Error
  37213 	}
  37214 	sub_configs_idx = 0
  37215 	for {
  37216 		if !(sub_configs_idx < (*CrunchConfig)(unsafe.Pointer(config)).Fsub_configs_size) {
  37217 			break
  37218 		}
  37219 		sub_config = config + 8 + uintptr(sub_configs_idx)*8
  37220 		i_remaining_percent = remaining_percent / (*CrunchConfig)(unsafe.Pointer(config)).Fsub_configs_size
  37221 		i_percent_range = i_remaining_percent / int32(4)
  37222 		i_remaining_percent = i_remaining_percent - i_percent_range
  37223 		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) {
  37224 			goto Error
  37225 		}
  37226 		i_cache = 0
  37227 		for {
  37228 			if (*CrunchSubConfig)(unsafe.Pointer(sub_config)).Fdo_no_cache != 0 {
  37229 				v7 = int32(2)
  37230 			} else {
  37231 				v7 = int32(1)
  37232 			}
  37233 			if !(i_cache < v7) {
  37234 				break
  37235 			}
  37236 			if i_cache == 0 {
  37237 				v10 = **(**int32)(__ccgo_up(bp + 112))
  37238 			} else {
  37239 				v10 = 0
  37240 			}
  37241 			cache_bits_tmp = v10
  37242 			**(**int32)(__ccgo_up(bp + 116)) = histogram_bits_in
  37243 			// Speed-up: no need to study the no-cache case if it was already studied
  37244 			// in i_cache == 0.
  37245 			if i_cache == int32(1) && **(**int32)(__ccgo_up(bp + 112)) == 0 {
  37246 				break
  37247 			}
  37248 			// Reset the bit writer for this iteration.
  37249 			VP8LBitWriterReset(tls, bp, bw2)
  37250 			// Build histogram image and symbols from backward references.
  37251 			histogram_image = VP8LAllocateHistogramSet(tls, int32(histogram_image_xysize), cache_bits_tmp)
  37252 			tmp_histo = VP8LAllocateHistogram(tls, cache_bits_tmp)
  37253 			if histogram_image == libc.UintptrFromInt32(0) || tmp_histo == libc.UintptrFromInt32(0) {
  37254 				WebPEncodingSetError(tls, pic, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  37255 				goto Error
  37256 			}
  37257 			i_percent_range = i_remaining_percent / int32(3)
  37258 			i_remaining_percent = i_remaining_percent - i_percent_range
  37259 			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) {
  37260 				goto Error
  37261 			}
  37262 			// Create Huffman bit lengths and codes for each histogram image.
  37263 			histogram_image_size = uint32((*VP8LHistogramSet)(unsafe.Pointer(histogram_image)).Fsize)
  37264 			bit_array_size = uint64(uint32(5) * histogram_image_size)
  37265 			huffman_codes = WebPSafeCalloc(tls, bit_array_size, uint64(24))
  37266 			// Note: some histogram_image entries may point to tmp_histos[], so the
  37267 			// latter need to outlive the following call to
  37268 			// GetHuffBitLengthsAndCodes().
  37269 			if huffman_codes == libc.UintptrFromInt32(0) || !(GetHuffBitLengthsAndCodes(tls, histogram_image, huffman_codes) != 0) {
  37270 				WebPEncodingSetError(tls, pic, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  37271 				goto Error
  37272 			}
  37273 			// Free combined histograms.
  37274 			VP8LFreeHistogramSet(tls, histogram_image)
  37275 			histogram_image = libc.UintptrFromInt32(0)
  37276 			// Free scratch histograms.
  37277 			VP8LFreeHistogram(tls, tmp_histo)
  37278 			tmp_histo = libc.UintptrFromInt32(0)
  37279 			// Color Cache parameters.
  37280 			if cache_bits_tmp > 0 {
  37281 				v12 = bw2
  37282 				v1 = uint32(1)
  37283 				v7 = int32(1)
  37284 				if libc.Uint64FromInt64(4) == libc.Uint64FromInt32(4) {
  37285 					if v7 > libc.Int32FromInt32(0) {
  37286 						if (*VP8LBitWriter)(unsafe.Pointer(v12)).Fused >= libc.Int32FromInt32(32) {
  37287 							VP8LPutBitsFlushBits(tls, v12)
  37288 						}
  37289 						**(**vp8l_atype_t)(__ccgo_up(v12)) |= uint64(v1) << (*VP8LBitWriter)(unsafe.Pointer(v12)).Fused
  37290 						**(**int32)(__ccgo_up(v12 + 8)) += v7
  37291 					}
  37292 				} else {
  37293 					VP8LPutBitsInternal(tls, v12, v1, v7)
  37294 				}
  37295 				v12 = bw2
  37296 				v1 = uint32(cache_bits_tmp)
  37297 				v7 = int32(4)
  37298 				if libc.Uint64FromInt64(4) == libc.Uint64FromInt32(4) {
  37299 					if v7 > libc.Int32FromInt32(0) {
  37300 						if (*VP8LBitWriter)(unsafe.Pointer(v12)).Fused >= libc.Int32FromInt32(32) {
  37301 							VP8LPutBitsFlushBits(tls, v12)
  37302 						}
  37303 						**(**vp8l_atype_t)(__ccgo_up(v12)) |= uint64(v1) << (*VP8LBitWriter)(unsafe.Pointer(v12)).Fused
  37304 						**(**int32)(__ccgo_up(v12 + 8)) += v7
  37305 					}
  37306 				} else {
  37307 					VP8LPutBitsInternal(tls, v12, v1, v7)
  37308 				}
  37309 			} else {
  37310 				v12 = bw2
  37311 				v1 = uint32(0)
  37312 				v7 = int32(1)
  37313 				if libc.Uint64FromInt64(4) == libc.Uint64FromInt32(4) {
  37314 					if v7 > libc.Int32FromInt32(0) {
  37315 						if (*VP8LBitWriter)(unsafe.Pointer(v12)).Fused >= libc.Int32FromInt32(32) {
  37316 							VP8LPutBitsFlushBits(tls, v12)
  37317 						}
  37318 						**(**vp8l_atype_t)(__ccgo_up(v12)) |= uint64(v1) << (*VP8LBitWriter)(unsafe.Pointer(v12)).Fused
  37319 						**(**int32)(__ccgo_up(v12 + 8)) += v7
  37320 					}
  37321 				} else {
  37322 					VP8LPutBitsInternal(tls, v12, v1, v7)
  37323 				}
  37324 			}
  37325 			// Huffman image + meta huffman.
  37326 			histogram_image_size = uint32(0)
  37327 			i = uint32(0)
  37328 			for {
  37329 				if !(i < histogram_image_xysize) {
  37330 					break
  37331 				}
  37332 				if **(**uint32_t)(__ccgo_up(histogram_argb + uintptr(i)*4)) >= histogram_image_size {
  37333 					histogram_image_size = **(**uint32_t)(__ccgo_up(histogram_argb + uintptr(i)*4)) + uint32(1)
  37334 				}
  37335 				**(**uint32_t)(__ccgo_up(histogram_argb + uintptr(i)*4)) <<= uint32(8)
  37336 				goto _21
  37337 			_21:
  37338 				;
  37339 				i = i + 1
  37340 			}
  37341 			write_histogram_image = libc.BoolInt32(histogram_image_size > uint32(1))
  37342 			v12 = bw2
  37343 			v1 = uint32(write_histogram_image)
  37344 			v7 = int32(1)
  37345 			if libc.Uint64FromInt64(4) == libc.Uint64FromInt32(4) {
  37346 				if v7 > libc.Int32FromInt32(0) {
  37347 					if (*VP8LBitWriter)(unsafe.Pointer(v12)).Fused >= libc.Int32FromInt32(32) {
  37348 						VP8LPutBitsFlushBits(tls, v12)
  37349 					}
  37350 					**(**vp8l_atype_t)(__ccgo_up(v12)) |= uint64(v1) << (*VP8LBitWriter)(unsafe.Pointer(v12)).Fused
  37351 					**(**int32)(__ccgo_up(v12 + 8)) += v7
  37352 				}
  37353 			} else {
  37354 				VP8LPutBitsInternal(tls, v12, v1, v7)
  37355 			}
  37356 			if write_histogram_image != 0 {
  37357 				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)
  37358 				v12 = bw2
  37359 				v1 = uint32(**(**int32)(__ccgo_up(bp + 116)) - int32(2))
  37360 				v7 = int32(3)
  37361 				if libc.Uint64FromInt64(4) == libc.Uint64FromInt32(4) {
  37362 					if v7 > libc.Int32FromInt32(0) {
  37363 						if (*VP8LBitWriter)(unsafe.Pointer(v12)).Fused >= libc.Int32FromInt32(32) {
  37364 							VP8LPutBitsFlushBits(tls, v12)
  37365 						}
  37366 						**(**vp8l_atype_t)(__ccgo_up(v12)) |= uint64(v1) << (*VP8LBitWriter)(unsafe.Pointer(v12)).Fused
  37367 						**(**int32)(__ccgo_up(v12 + 8)) += v7
  37368 					}
  37369 				} else {
  37370 					VP8LPutBitsInternal(tls, v12, v1, v7)
  37371 				}
  37372 				i_percent_range = i_remaining_percent / int32(2)
  37373 				i_remaining_percent = i_remaining_percent - i_percent_range
  37374 				v1 = uint32(**(**int32)(__ccgo_up(bp + 116)))
  37375 				v2 = (uint32(width) + uint32(libc.Int32FromInt32(1)<<v1) - uint32(1)) >> v1
  37376 				goto _30
  37377 			_30:
  37378 				v4 = uint32(**(**int32)(__ccgo_up(bp + 116)))
  37379 				v5 = (uint32(height) + uint32(libc.Int32FromInt32(1)<<v4) - uint32(1)) >> v4
  37380 				goto _33
  37381 			_33:
  37382 				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) {
  37383 					goto Error
  37384 				}
  37385 			}
  37386 			// Store Huffman codes.
  37387 			max_tokens = 0
  37388 			// Find maximum number of symbols for the huffman tree-set.
  37389 			i = uint32(0)
  37390 			for {
  37391 				if !(i < uint32(5)*histogram_image_size) {
  37392 					break
  37393 				}
  37394 				codes = huffman_codes + uintptr(i)*24
  37395 				if max_tokens < (*HuffmanTreeCode)(unsafe.Pointer(codes)).Fnum_symbols {
  37396 					max_tokens = (*HuffmanTreeCode)(unsafe.Pointer(codes)).Fnum_symbols
  37397 				}
  37398 				goto _34
  37399 			_34:
  37400 				;
  37401 				i = i + 1
  37402 			}
  37403 			tokens = WebPSafeMalloc(tls, uint64(max_tokens), uint64(2))
  37404 			if tokens == libc.UintptrFromInt32(0) {
  37405 				WebPEncodingSetError(tls, pic, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  37406 				goto Error
  37407 			}
  37408 			i = uint32(0)
  37409 			for {
  37410 				if !(i < uint32(5)*histogram_image_size) {
  37411 					break
  37412 				}
  37413 				codes1 = huffman_codes + uintptr(i)*24
  37414 				StoreHuffmanCode(tls, bw2, huff_tree, tokens, codes1)
  37415 				ClearHuffmanTreeIfOnlyOneSymbol(tls, codes1)
  37416 				goto _35
  37417 			_35:
  37418 				;
  37419 				i = i + 1
  37420 			}
  37421 			// Store actual literals.
  37422 			v12 = bw2
  37423 			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)))
  37424 			goto _38
  37425 		_38:
  37426 			hdr_size_tmp = int32(v37 - init_byte_position)
  37427 			if !(StoreImageToBitMask(tls, bw2, width, **(**int32)(__ccgo_up(bp + 116)), refs_array+uintptr(i_cache)*40, histogram_argb, huffman_codes, pic) != 0) {
  37428 				goto Error
  37429 			}
  37430 			// Keep track of the smallest image so far.
  37431 			v12 = bw2
  37432 			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)))
  37433 			goto _41
  37434 		_41:
  37435 			if v37 < bw_size_best {
  37436 				v15 = bw2
  37437 				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)))
  37438 				goto _44
  37439 			_44:
  37440 				bw_size_best = v40
  37441 				**(**int32)(__ccgo_up(cache_bits)) = cache_bits_tmp
  37442 				**(**int32)(__ccgo_up(hdr_size)) = hdr_size_tmp
  37443 				v12 = bw2
  37444 				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)))
  37445 				goto _47
  37446 			_47:
  37447 				**(**int32)(__ccgo_up(data_size)) = int32(v37 - init_byte_position - uint64(**(**int32)(__ccgo_up(hdr_size))))
  37448 				VP8LBitWriterSwap(tls, bw2, bp+48)
  37449 			}
  37450 			WebPSafeFree(tls, tokens)
  37451 			tokens = libc.UintptrFromInt32(0)
  37452 			if huffman_codes != libc.UintptrFromInt32(0) {
  37453 				WebPSafeFree(tls, (*HuffmanTreeCode)(unsafe.Pointer(huffman_codes)).Fcodes)
  37454 				WebPSafeFree(tls, huffman_codes)
  37455 				huffman_codes = libc.UintptrFromInt32(0)
  37456 			}
  37457 			goto _9
  37458 		_9:
  37459 			;
  37460 			i_cache = i_cache + 1
  37461 		}
  37462 		goto _8
  37463 	_8:
  37464 		;
  37465 		sub_configs_idx = sub_configs_idx + 1
  37466 	}
  37467 	VP8LBitWriterSwap(tls, bw2, bp+48)
  37468 	if !(WebPReportProgress(tls, pic, percent_start+remaining_percent, percent) != 0) {
  37469 		goto Error
  37470 	}
  37471 	goto Error
  37472 Error:
  37473 	;
  37474 	WebPSafeFree(tls, tokens)
  37475 	WebPSafeFree(tls, huff_tree)
  37476 	VP8LFreeHistogramSet(tls, histogram_image)
  37477 	VP8LFreeHistogram(tls, tmp_histo)
  37478 	VP8LHashChainClear(tls, bp+96)
  37479 	if huffman_codes != libc.UintptrFromInt32(0) {
  37480 		WebPSafeFree(tls, (*HuffmanTreeCode)(unsafe.Pointer(huffman_codes)).Fcodes)
  37481 		WebPSafeFree(tls, huffman_codes)
  37482 	}
  37483 	WebPSafeFree(tls, histogram_argb)
  37484 	VP8LBitWriterWipeOut(tls, bp+48)
  37485 	return libc.BoolInt32((*WebPPicture)(unsafe.Pointer(pic)).Ferror_code == int32(VP8_ENC_OK))
  37486 }
  37487 
  37488 // -----------------------------------------------------------------------------
  37489 // Transforms
  37490 
  37491 func ApplySubtractGreen(tls *libc.TLS, enc uintptr, width int32, height int32, bw1 uintptr) {
  37492 	var v1 uintptr
  37493 	var v2 uint32_t
  37494 	var v3 int32
  37495 	_, _, _ = v1, v2, v3
  37496 	v1 = bw1
  37497 	v2 = uint32(TRANSFORM_PRESENT)
  37498 	v3 = int32(1)
  37499 	if libc.Uint64FromInt64(4) == libc.Uint64FromInt32(4) {
  37500 		if v3 > libc.Int32FromInt32(0) {
  37501 			if (*VP8LBitWriter)(unsafe.Pointer(v1)).Fused >= libc.Int32FromInt32(32) {
  37502 				VP8LPutBitsFlushBits(tls, v1)
  37503 			}
  37504 			**(**vp8l_atype_t)(__ccgo_up(v1)) |= uint64(v2) << (*VP8LBitWriter)(unsafe.Pointer(v1)).Fused
  37505 			**(**int32)(__ccgo_up(v1 + 8)) += v3
  37506 		}
  37507 	} else {
  37508 		VP8LPutBitsInternal(tls, v1, v2, v3)
  37509 	}
  37510 	v1 = bw1
  37511 	v2 = uint32(SUBTRACT_GREEN_TRANSFORM)
  37512 	v3 = int32(2)
  37513 	if libc.Uint64FromInt64(4) == libc.Uint64FromInt32(4) {
  37514 		if v3 > libc.Int32FromInt32(0) {
  37515 			if (*VP8LBitWriter)(unsafe.Pointer(v1)).Fused >= libc.Int32FromInt32(32) {
  37516 				VP8LPutBitsFlushBits(tls, v1)
  37517 			}
  37518 			**(**vp8l_atype_t)(__ccgo_up(v1)) |= uint64(v2) << (*VP8LBitWriter)(unsafe.Pointer(v1)).Fused
  37519 			**(**int32)(__ccgo_up(v1 + 8)) += v3
  37520 		}
  37521 	} else {
  37522 		VP8LPutBitsInternal(tls, v1, v2, v3)
  37523 	}
  37524 	(*(*func(*libc.TLS, uintptr, int32))(unsafe.Pointer(&struct{ uintptr }{VP8LSubtractGreenFromBlueAndRed})))(tls, (*VP8LEncoder)(unsafe.Pointer(enc)).Fargb, width*height)
  37525 }
  37526 
  37527 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) {
  37528 	var max_bits, min_bits, near_lossless_strength, v1, v2 int32
  37529 	var v10, v12, v4, v7 uint32_t
  37530 	var v3 uintptr
  37531 	_, _, _, _, _, _, _, _, _, _ = max_bits, min_bits, near_lossless_strength, v1, v10, v12, v2, v3, v4, v7
  37532 	if (*VP8LEncoder)(unsafe.Pointer(enc)).Fuse_palette != 0 {
  37533 		v1 = int32(100)
  37534 	} else {
  37535 		v1 = (*WebPConfig)(unsafe.Pointer((*VP8LEncoder)(unsafe.Pointer(enc)).Fconfig)).Fnear_lossless
  37536 	}
  37537 	near_lossless_strength = v1
  37538 	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))
  37539 	if (*WebPConfig)(unsafe.Pointer((*VP8LEncoder)(unsafe.Pointer(enc)).Fconfig)).Fmethod > int32(4) {
  37540 		v2 = (*WebPConfig)(unsafe.Pointer((*VP8LEncoder)(unsafe.Pointer(enc)).Fconfig)).Fmethod - int32(4)
  37541 	} else {
  37542 		v2 = 0
  37543 	}
  37544 	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))
  37545 	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) {
  37546 		return 0
  37547 	}
  37548 	v3 = bw1
  37549 	v4 = uint32(TRANSFORM_PRESENT)
  37550 	v1 = int32(1)
  37551 	if libc.Uint64FromInt64(4) == libc.Uint64FromInt32(4) {
  37552 		if v1 > libc.Int32FromInt32(0) {
  37553 			if (*VP8LBitWriter)(unsafe.Pointer(v3)).Fused >= libc.Int32FromInt32(32) {
  37554 				VP8LPutBitsFlushBits(tls, v3)
  37555 			}
  37556 			**(**vp8l_atype_t)(__ccgo_up(v3)) |= uint64(v4) << (*VP8LBitWriter)(unsafe.Pointer(v3)).Fused
  37557 			**(**int32)(__ccgo_up(v3 + 8)) += v1
  37558 		}
  37559 	} else {
  37560 		VP8LPutBitsInternal(tls, v3, v4, v1)
  37561 	}
  37562 	v3 = bw1
  37563 	v4 = uint32(PREDICTOR_TRANSFORM)
  37564 	v1 = int32(2)
  37565 	if libc.Uint64FromInt64(4) == libc.Uint64FromInt32(4) {
  37566 		if v1 > libc.Int32FromInt32(0) {
  37567 			if (*VP8LBitWriter)(unsafe.Pointer(v3)).Fused >= libc.Int32FromInt32(32) {
  37568 				VP8LPutBitsFlushBits(tls, v3)
  37569 			}
  37570 			**(**vp8l_atype_t)(__ccgo_up(v3)) |= uint64(v4) << (*VP8LBitWriter)(unsafe.Pointer(v3)).Fused
  37571 			**(**int32)(__ccgo_up(v3 + 8)) += v1
  37572 		}
  37573 	} else {
  37574 		VP8LPutBitsInternal(tls, v3, v4, v1)
  37575 	}
  37576 	v3 = bw1
  37577 	v4 = uint32(**(**int32)(__ccgo_up(best_bits)) - int32(MIN_TRANSFORM_BITS))
  37578 	v1 = int32(NUM_TRANSFORM_BITS)
  37579 	if libc.Uint64FromInt64(4) == libc.Uint64FromInt32(4) {
  37580 		if v1 > libc.Int32FromInt32(0) {
  37581 			if (*VP8LBitWriter)(unsafe.Pointer(v3)).Fused >= libc.Int32FromInt32(32) {
  37582 				VP8LPutBitsFlushBits(tls, v3)
  37583 			}
  37584 			**(**vp8l_atype_t)(__ccgo_up(v3)) |= uint64(v4) << (*VP8LBitWriter)(unsafe.Pointer(v3)).Fused
  37585 			**(**int32)(__ccgo_up(v3 + 8)) += v1
  37586 		}
  37587 	} else {
  37588 		VP8LPutBitsInternal(tls, v3, v4, v1)
  37589 	}
  37590 	v4 = uint32(**(**int32)(__ccgo_up(best_bits)))
  37591 	v7 = (uint32(width) + uint32(libc.Int32FromInt32(1)<<v4) - uint32(1)) >> v4
  37592 	goto _14
  37593 _14:
  37594 	v10 = uint32(**(**int32)(__ccgo_up(best_bits)))
  37595 	v12 = (uint32(height) + uint32(libc.Int32FromInt32(1)<<v10) - uint32(1)) >> v10
  37596 	goto _17
  37597 _17:
  37598 	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)
  37599 }
  37600 
  37601 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) {
  37602 	var min_bits, v3 int32
  37603 	var v1 uintptr
  37604 	var v10, v2, v5, v8 uint32_t
  37605 	_, _, _, _, _, _, _ = min_bits, v1, v10, v2, v3, v5, v8
  37606 	min_bits = (*VP8LEncoder)(unsafe.Pointer(enc)).Fcross_color_transform_bits
  37607 	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) {
  37608 		return 0
  37609 	}
  37610 	v1 = bw1
  37611 	v2 = uint32(TRANSFORM_PRESENT)
  37612 	v3 = int32(1)
  37613 	if libc.Uint64FromInt64(4) == libc.Uint64FromInt32(4) {
  37614 		if v3 > libc.Int32FromInt32(0) {
  37615 			if (*VP8LBitWriter)(unsafe.Pointer(v1)).Fused >= libc.Int32FromInt32(32) {
  37616 				VP8LPutBitsFlushBits(tls, v1)
  37617 			}
  37618 			**(**vp8l_atype_t)(__ccgo_up(v1)) |= uint64(v2) << (*VP8LBitWriter)(unsafe.Pointer(v1)).Fused
  37619 			**(**int32)(__ccgo_up(v1 + 8)) += v3
  37620 		}
  37621 	} else {
  37622 		VP8LPutBitsInternal(tls, v1, v2, v3)
  37623 	}
  37624 	v1 = bw1
  37625 	v2 = uint32(CROSS_COLOR_TRANSFORM)
  37626 	v3 = int32(2)
  37627 	if libc.Uint64FromInt64(4) == libc.Uint64FromInt32(4) {
  37628 		if v3 > libc.Int32FromInt32(0) {
  37629 			if (*VP8LBitWriter)(unsafe.Pointer(v1)).Fused >= libc.Int32FromInt32(32) {
  37630 				VP8LPutBitsFlushBits(tls, v1)
  37631 			}
  37632 			**(**vp8l_atype_t)(__ccgo_up(v1)) |= uint64(v2) << (*VP8LBitWriter)(unsafe.Pointer(v1)).Fused
  37633 			**(**int32)(__ccgo_up(v1 + 8)) += v3
  37634 		}
  37635 	} else {
  37636 		VP8LPutBitsInternal(tls, v1, v2, v3)
  37637 	}
  37638 	v1 = bw1
  37639 	v2 = uint32(**(**int32)(__ccgo_up(best_bits)) - int32(MIN_TRANSFORM_BITS))
  37640 	v3 = int32(NUM_TRANSFORM_BITS)
  37641 	if libc.Uint64FromInt64(4) == libc.Uint64FromInt32(4) {
  37642 		if v3 > libc.Int32FromInt32(0) {
  37643 			if (*VP8LBitWriter)(unsafe.Pointer(v1)).Fused >= libc.Int32FromInt32(32) {
  37644 				VP8LPutBitsFlushBits(tls, v1)
  37645 			}
  37646 			**(**vp8l_atype_t)(__ccgo_up(v1)) |= uint64(v2) << (*VP8LBitWriter)(unsafe.Pointer(v1)).Fused
  37647 			**(**int32)(__ccgo_up(v1 + 8)) += v3
  37648 		}
  37649 	} else {
  37650 		VP8LPutBitsInternal(tls, v1, v2, v3)
  37651 	}
  37652 	v2 = uint32(**(**int32)(__ccgo_up(best_bits)))
  37653 	v5 = (uint32(width) + uint32(libc.Int32FromInt32(1)<<v2) - uint32(1)) >> v2
  37654 	goto _12
  37655 _12:
  37656 	v8 = uint32(**(**int32)(__ccgo_up(best_bits)))
  37657 	v10 = (uint32(height) + uint32(libc.Int32FromInt32(1)<<v8) - uint32(1)) >> v8
  37658 	goto _15
  37659 _15:
  37660 	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)
  37661 }
  37662 
  37663 // -----------------------------------------------------------------------------
  37664 
  37665 func WriteRiffHeader(tls *libc.TLS, pic uintptr, riff_size size_t, vp8l_size size_t) (r int32) {
  37666 	bp := tls.Alloc(32)
  37667 	defer tls.Free(32)
  37668 	var v1, v3, v5 uintptr
  37669 	var v4, v6 int32
  37670 	var v2 uint32_t
  37671 	var _ /* riff at bp+0 */ [21]uint8_t
  37672 	_, _, _, _, _, _ = v1, v2, v3, v4, v5, v6
  37673 	**(**[21]uint8_t)(__ccgo_up(bp)) = [21]uint8_t{
  37674 		0:  uint8('R'),
  37675 		1:  uint8('I'),
  37676 		2:  uint8('F'),
  37677 		3:  uint8('F'),
  37678 		8:  uint8('W'),
  37679 		9:  uint8('E'),
  37680 		10: uint8('B'),
  37681 		11: uint8('P'),
  37682 		12: uint8('V'),
  37683 		13: uint8('P'),
  37684 		14: uint8('8'),
  37685 		15: uint8('L'),
  37686 		20: uint8(VP8L_MAGIC_BYTE3),
  37687 	}
  37688 	v1 = bp + uintptr(TAG_SIZE)
  37689 	v2 = uint32(riff_size)
  37690 	v3 = v1
  37691 	v4 = int32(v2 & libc.Uint32FromInt32(0xffff))
  37692 	**(**uint8_t)(__ccgo_up(v3)) = uint8(v4 >> 0 & int32(0xff))
  37693 	**(**uint8_t)(__ccgo_up(v3 + 1)) = uint8(v4 >> int32(8) & int32(0xff))
  37694 	v5 = v1 + uintptr(2)
  37695 	v6 = int32(v2 >> libc.Int32FromInt32(16))
  37696 	**(**uint8_t)(__ccgo_up(v5)) = uint8(v6 >> 0 & int32(0xff))
  37697 	**(**uint8_t)(__ccgo_up(v5 + 1)) = uint8(v6 >> int32(8) & int32(0xff))
  37698 	v1 = bp + uintptr(RIFF_HEADER_SIZE) + uintptr(TAG_SIZE)
  37699 	v2 = uint32(vp8l_size)
  37700 	v3 = v1
  37701 	v4 = int32(v2 & libc.Uint32FromInt32(0xffff))
  37702 	**(**uint8_t)(__ccgo_up(v3)) = uint8(v4 >> 0 & int32(0xff))
  37703 	**(**uint8_t)(__ccgo_up(v3 + 1)) = uint8(v4 >> int32(8) & int32(0xff))
  37704 	v5 = v1 + uintptr(2)
  37705 	v6 = int32(v2 >> libc.Int32FromInt32(16))
  37706 	**(**uint8_t)(__ccgo_up(v5)) = uint8(v6 >> 0 & int32(0xff))
  37707 	**(**uint8_t)(__ccgo_up(v5 + 1)) = uint8(v6 >> int32(8) & int32(0xff))
  37708 	return (*(*func(*libc.TLS, uintptr, size_t, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*WebPPicture)(unsafe.Pointer(pic)).Fwriter})))(tls, bp, uint64(21), pic)
  37709 }
  37710 
  37711 func WriteImageSize(tls *libc.TLS, pic uintptr, bw1 uintptr) (r int32) {
  37712 	var height, width, v3 int32
  37713 	var v1 uintptr
  37714 	var v2 uint32_t
  37715 	_, _, _, _, _ = height, width, v1, v2, v3
  37716 	width = (*WebPPicture)(unsafe.Pointer(pic)).Fwidth - int32(1)
  37717 	height = (*WebPPicture)(unsafe.Pointer(pic)).Fheight - int32(1)
  37718 	v1 = bw1
  37719 	v2 = uint32(width)
  37720 	v3 = int32(VP8L_IMAGE_SIZE_BITS)
  37721 	if libc.Uint64FromInt64(4) == libc.Uint64FromInt32(4) {
  37722 		if v3 > libc.Int32FromInt32(0) {
  37723 			if (*VP8LBitWriter)(unsafe.Pointer(v1)).Fused >= libc.Int32FromInt32(32) {
  37724 				VP8LPutBitsFlushBits(tls, v1)
  37725 			}
  37726 			**(**vp8l_atype_t)(__ccgo_up(v1)) |= uint64(v2) << (*VP8LBitWriter)(unsafe.Pointer(v1)).Fused
  37727 			**(**int32)(__ccgo_up(v1 + 8)) += v3
  37728 		}
  37729 	} else {
  37730 		VP8LPutBitsInternal(tls, v1, v2, v3)
  37731 	}
  37732 	v1 = bw1
  37733 	v2 = uint32(height)
  37734 	v3 = int32(VP8L_IMAGE_SIZE_BITS)
  37735 	if libc.Uint64FromInt64(4) == libc.Uint64FromInt32(4) {
  37736 		if v3 > libc.Int32FromInt32(0) {
  37737 			if (*VP8LBitWriter)(unsafe.Pointer(v1)).Fused >= libc.Int32FromInt32(32) {
  37738 				VP8LPutBitsFlushBits(tls, v1)
  37739 			}
  37740 			**(**vp8l_atype_t)(__ccgo_up(v1)) |= uint64(v2) << (*VP8LBitWriter)(unsafe.Pointer(v1)).Fused
  37741 			**(**int32)(__ccgo_up(v1 + 8)) += v3
  37742 		}
  37743 	} else {
  37744 		VP8LPutBitsInternal(tls, v1, v2, v3)
  37745 	}
  37746 	return libc.BoolInt32(!((*VP8LBitWriter)(unsafe.Pointer(bw1)).Ferror1 != 0))
  37747 }
  37748 
  37749 func WriteRealAlphaAndVersion(tls *libc.TLS, bw1 uintptr, has_alpha int32) (r int32) {
  37750 	var v1 uintptr
  37751 	var v2 uint32_t
  37752 	var v3 int32
  37753 	_, _, _ = v1, v2, v3
  37754 	v1 = bw1
  37755 	v2 = uint32(has_alpha)
  37756 	v3 = int32(1)
  37757 	if libc.Uint64FromInt64(4) == libc.Uint64FromInt32(4) {
  37758 		if v3 > libc.Int32FromInt32(0) {
  37759 			if (*VP8LBitWriter)(unsafe.Pointer(v1)).Fused >= libc.Int32FromInt32(32) {
  37760 				VP8LPutBitsFlushBits(tls, v1)
  37761 			}
  37762 			**(**vp8l_atype_t)(__ccgo_up(v1)) |= uint64(v2) << (*VP8LBitWriter)(unsafe.Pointer(v1)).Fused
  37763 			**(**int32)(__ccgo_up(v1 + 8)) += v3
  37764 		}
  37765 	} else {
  37766 		VP8LPutBitsInternal(tls, v1, v2, v3)
  37767 	}
  37768 	v1 = bw1
  37769 	v2 = uint32(VP8L_VERSION)
  37770 	v3 = int32(VP8L_VERSION_BITS)
  37771 	if libc.Uint64FromInt64(4) == libc.Uint64FromInt32(4) {
  37772 		if v3 > libc.Int32FromInt32(0) {
  37773 			if (*VP8LBitWriter)(unsafe.Pointer(v1)).Fused >= libc.Int32FromInt32(32) {
  37774 				VP8LPutBitsFlushBits(tls, v1)
  37775 			}
  37776 			**(**vp8l_atype_t)(__ccgo_up(v1)) |= uint64(v2) << (*VP8LBitWriter)(unsafe.Pointer(v1)).Fused
  37777 			**(**int32)(__ccgo_up(v1 + 8)) += v3
  37778 		}
  37779 	} else {
  37780 		VP8LPutBitsInternal(tls, v1, v2, v3)
  37781 	}
  37782 	return libc.BoolInt32(!((*VP8LBitWriter)(unsafe.Pointer(bw1)).Ferror1 != 0))
  37783 }
  37784 
  37785 func WriteImage(tls *libc.TLS, pic uintptr, bw1 uintptr, coded_size uintptr) (r int32) {
  37786 	bp := tls.Alloc(16)
  37787 	defer tls.Free(16)
  37788 	var pad, riff_size, vp8l_size, webpll_size, v2 size_t
  37789 	var webpll_data, v1 uintptr
  37790 	var _ /* pad_byte at bp+0 */ [1]uint8_t
  37791 	_, _, _, _, _, _, _ = pad, riff_size, vp8l_size, webpll_data, webpll_size, v1, v2
  37792 	webpll_data = VP8LBitWriterFinish(tls, bw1)
  37793 	v1 = bw1
  37794 	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)))
  37795 	goto _3
  37796 _3:
  37797 	webpll_size = v2
  37798 	vp8l_size = uint64(VP8L_SIGNATURE_SIZE) + webpll_size
  37799 	pad = vp8l_size & uint64(1)
  37800 	riff_size = uint64(libc.Int32FromInt32(TAG_SIZE)+libc.Int32FromInt32(CHUNK_HEADER_SIZE)) + vp8l_size + pad
  37801 	**(**size_t)(__ccgo_up(coded_size)) = uint64(0)
  37802 	if (*VP8LBitWriter)(unsafe.Pointer(bw1)).Ferror1 != 0 {
  37803 		return WebPEncodingSetError(tls, pic, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  37804 	}
  37805 	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) {
  37806 		return WebPEncodingSetError(tls, pic, int32(VP8_ENC_ERROR_BAD_WRITE))
  37807 	}
  37808 	if pad != 0 {
  37809 		**(**[1]uint8_t)(__ccgo_up(bp)) = [1]uint8_t{}
  37810 		if !((*(*func(*libc.TLS, uintptr, size_t, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*WebPPicture)(unsafe.Pointer(pic)).Fwriter})))(tls, bp, uint64(1), pic) != 0) {
  37811 			return WebPEncodingSetError(tls, pic, int32(VP8_ENC_ERROR_BAD_WRITE))
  37812 		}
  37813 	}
  37814 	**(**size_t)(__ccgo_up(coded_size)) = uint64(CHUNK_HEADER_SIZE) + riff_size
  37815 	return int32(1)
  37816 }
  37817 
  37818 // -----------------------------------------------------------------------------
  37819 
  37820 func ClearTransformBuffer(tls *libc.TLS, enc uintptr) {
  37821 	WebPSafeFree(tls, (*VP8LEncoder)(unsafe.Pointer(enc)).Ftransform_mem)
  37822 	(*VP8LEncoder)(unsafe.Pointer(enc)).Ftransform_mem = libc.UintptrFromInt32(0)
  37823 	(*VP8LEncoder)(unsafe.Pointer(enc)).Ftransform_mem_size = uint64(0)
  37824 }
  37825 
  37826 // C documentation
  37827 //
  37828 //	// Allocates the memory for argb (W x H) buffer, 2 rows of context for
  37829 //	// prediction and transform data.
  37830 //	// Flags influencing the memory allocated:
  37831 //	//  enc->transform_bits
  37832 //	//  enc->use_predict, enc->use_cross_color
  37833 func AllocateTransformBuffer(tls *libc.TLS, enc uintptr, width int32, height int32) (r int32) {
  37834 	var argb_scratch_size, image_size, max_alignment_in_words, mem_size, transform_data_size uint64_t
  37835 	var mem uintptr
  37836 	var v1, v2 uint64
  37837 	var v3, v4, v6, v7 uint32_t
  37838 	_, _, _, _, _, _, _, _, _, _, _, _ = argb_scratch_size, image_size, max_alignment_in_words, mem, mem_size, transform_data_size, v1, v2, v3, v4, v6, v7
  37839 	image_size = uint64(width) * uint64(height)
  37840 	if (*VP8LEncoder)(unsafe.Pointer(enc)).Fuse_predict != 0 {
  37841 		v1 = uint64((width+int32(1))*int32(2)) + (uint64(width*int32(2))+uint64(4)-uint64(1))/uint64(4)
  37842 	} else {
  37843 		v1 = uint64(0)
  37844 	}
  37845 	// VP8LResidualImage needs room for 2 scanlines of uint32 pixels with an extra
  37846 	// pixel in each, plus 2 regular scanlines of bytes.
  37847 	// TODO(skal): Clean up by using arithmetic in bytes instead of words.
  37848 	argb_scratch_size = v1
  37849 	if (*VP8LEncoder)(unsafe.Pointer(enc)).Fuse_predict != 0 || (*VP8LEncoder)(unsafe.Pointer(enc)).Fuse_cross_color != 0 {
  37850 		v3 = uint32(MIN_TRANSFORM_BITS)
  37851 		v4 = (uint32(width) + uint32(libc.Int32FromInt32(1)<<v3) - uint32(1)) >> v3
  37852 		goto _5
  37853 	_5:
  37854 		v6 = uint32(MIN_TRANSFORM_BITS)
  37855 		v7 = (uint32(height) + uint32(libc.Int32FromInt32(1)<<v6) - uint32(1)) >> v6
  37856 		goto _8
  37857 	_8:
  37858 		v2 = uint64(v4) * uint64(v7)
  37859 	} else {
  37860 		v2 = uint64(0)
  37861 	}
  37862 	transform_data_size = v2
  37863 	max_alignment_in_words = (libc.Uint64FromInt32(WEBP_ALIGN_CST) + libc.Uint64FromInt64(4) - libc.Uint64FromInt32(1)) / libc.Uint64FromInt64(4)
  37864 	mem_size = image_size + max_alignment_in_words + argb_scratch_size + max_alignment_in_words + transform_data_size
  37865 	mem = (*VP8LEncoder)(unsafe.Pointer(enc)).Ftransform_mem
  37866 	if mem == libc.UintptrFromInt32(0) || mem_size > (*VP8LEncoder)(unsafe.Pointer(enc)).Ftransform_mem_size {
  37867 		ClearTransformBuffer(tls, enc)
  37868 		mem = WebPSafeMalloc(tls, mem_size, uint64(4))
  37869 		if mem == libc.UintptrFromInt32(0) {
  37870 			return WebPEncodingSetError(tls, (*VP8LEncoder)(unsafe.Pointer(enc)).Fpic, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  37871 		}
  37872 		(*VP8LEncoder)(unsafe.Pointer(enc)).Ftransform_mem = mem
  37873 		(*VP8LEncoder)(unsafe.Pointer(enc)).Ftransform_mem_size = mem_size
  37874 		(*VP8LEncoder)(unsafe.Pointer(enc)).Fargb_content = int32(kEncoderNone)
  37875 	}
  37876 	(*VP8LEncoder)(unsafe.Pointer(enc)).Fargb = mem
  37877 	mem = uintptr((uint64(mem+uintptr(image_size)*4) + libc.Uint64FromInt32(WEBP_ALIGN_CST)) & ^libc.Uint64FromInt32(WEBP_ALIGN_CST))
  37878 	(*VP8LEncoder)(unsafe.Pointer(enc)).Fargb_scratch = mem
  37879 	mem = uintptr((uint64(mem+uintptr(argb_scratch_size)*4) + libc.Uint64FromInt32(WEBP_ALIGN_CST)) & ^libc.Uint64FromInt32(WEBP_ALIGN_CST))
  37880 	(*VP8LEncoder)(unsafe.Pointer(enc)).Ftransform_data = mem
  37881 	(*VP8LEncoder)(unsafe.Pointer(enc)).Fcurrent_width = width
  37882 	return int32(1)
  37883 }
  37884 
  37885 func MakeInputImageCopy(tls *libc.TLS, enc uintptr) (r int32) {
  37886 	var dst, picture, src uintptr
  37887 	var height, width, y int32
  37888 	_, _, _, _, _, _ = dst, height, picture, src, width, y
  37889 	picture = (*VP8LEncoder)(unsafe.Pointer(enc)).Fpic
  37890 	width = (*WebPPicture)(unsafe.Pointer(picture)).Fwidth
  37891 	height = (*WebPPicture)(unsafe.Pointer(picture)).Fheight
  37892 	if !(AllocateTransformBuffer(tls, enc, width, height) != 0) {
  37893 		return 0
  37894 	}
  37895 	if (*VP8LEncoder)(unsafe.Pointer(enc)).Fargb_content == int32(kEncoderARGB) {
  37896 		return int32(1)
  37897 	}
  37898 	dst = (*VP8LEncoder)(unsafe.Pointer(enc)).Fargb
  37899 	src = (*WebPPicture)(unsafe.Pointer(picture)).Fargb
  37900 	y = 0
  37901 	for {
  37902 		if !(y < height) {
  37903 			break
  37904 		}
  37905 		libc.Xmemcpy(tls, dst, src, uint64(width)*uint64(4))
  37906 		dst = dst + uintptr(width)*4
  37907 		src = src + uintptr((*WebPPicture)(unsafe.Pointer(picture)).Fargb_stride)*4
  37908 		goto _1
  37909 	_1:
  37910 		;
  37911 		y = y + 1
  37912 	}
  37913 	(*VP8LEncoder)(unsafe.Pointer(enc)).Fargb_content = int32(kEncoderARGB)
  37914 	return int32(1)
  37915 }
  37916 
  37917 // -----------------------------------------------------------------------------
  37918 
  37919 func SearchColorGreedy(tls *libc.TLS, palette uintptr, palette_size int32, color uint32_t) (r uint32_t) {
  37920 	_ = palette_size
  37921 	if color == **(**uint32_t)(__ccgo_up(palette)) {
  37922 		return uint32(0)
  37923 	}
  37924 	if color == **(**uint32_t)(__ccgo_up(palette + 1*4)) {
  37925 		return uint32(1)
  37926 	}
  37927 	if color == **(**uint32_t)(__ccgo_up(palette + 2*4)) {
  37928 		return uint32(2)
  37929 	}
  37930 	return uint32(3)
  37931 }
  37932 
  37933 func ApplyPaletteHash0(tls *libc.TLS, color uint32_t) (r uint32_t) {
  37934 	// Focus on the green color.
  37935 	return color >> libc.Int32FromInt32(8) & uint32(0xff)
  37936 }
  37937 
  37938 func ApplyPaletteHash1(tls *libc.TLS, color uint32_t) (r uint32_t) {
  37939 	// Forget about alpha.
  37940 	return uint32(uint64(color&libc.Uint32FromUint32(0x00ffffff))*libc.Uint64FromUint64(4222244071)) >> (libc.Int32FromInt32(32) - libc.Int32FromInt32(11))
  37941 }
  37942 
  37943 func ApplyPaletteHash2(tls *libc.TLS, color uint32_t) (r uint32_t) {
  37944 	// Forget about alpha.
  37945 	return uint32(uint64(color&libc.Uint32FromUint32(0x00ffffff))*(libc.Uint64FromUint64(1)<<libc.Int32FromInt32(31)-libc.Uint64FromInt32(1))) >> (libc.Int32FromInt32(32) - libc.Int32FromInt32(11))
  37946 }
  37947 
  37948 // Use 1 pixel cache for ARGB pixels.
  37949 
  37950 // C documentation
  37951 //
  37952 //	// Remap argb values in src[] to packed palettes entries in dst[]
  37953 //	// using 'row' as a temporary buffer of size 'width'.
  37954 //	// We assume that all src[] values have a corresponding entry in the palette.
  37955 //	// Note: src[] can be the same as dst[]
  37956 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) {
  37957 	bp := tls.Alloc(6144)
  37958 	defer tls.Free(6144)
  37959 	var hash_functions [3]uintptr
  37960 	var i, j, use_LUT, x, y int32
  37961 	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
  37962 	var tmp_row uintptr
  37963 	var _ /* buffer at bp+0 */ [2048]uint16_t
  37964 	var _ /* idx_map at bp+4096 */ [256]uint32_t
  37965 	var _ /* palette_sorted at bp+5120 */ [256]uint32_t
  37966 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  37967 	// TODO(skal): this tmp buffer is not needed if VP8LBundleColorMap() can be
  37968 	// made to work in-place.
  37969 	tmp_row = WebPSafeMalloc(tls, uint64(width), uint64(1))
  37970 	if tmp_row == libc.UintptrFromInt32(0) {
  37971 		return WebPEncodingSetError(tls, pic, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  37972 	}
  37973 	if palette_size < int32(4) {
  37974 		prev_pix = **(**uint32_t)(__ccgo_up(palette))
  37975 		prev_idx = uint32(0)
  37976 		y = 0
  37977 		for {
  37978 			if !(y < height) {
  37979 				break
  37980 			}
  37981 			x = 0
  37982 			for {
  37983 				if !(x < width) {
  37984 					break
  37985 				}
  37986 				pix = **(**uint32_t)(__ccgo_up(src + uintptr(x)*4))
  37987 				if pix != prev_pix {
  37988 					prev_idx = SearchColorGreedy(tls, palette, palette_size, pix)
  37989 					prev_pix = pix
  37990 				}
  37991 				**(**uint8_t)(__ccgo_up(tmp_row + uintptr(x))) = uint8(prev_idx)
  37992 				goto _2
  37993 			_2:
  37994 				;
  37995 				x = x + 1
  37996 			}
  37997 			(*(*func(*libc.TLS, uintptr, int32, int32, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8LBundleColorMap})))(tls, tmp_row, width, xbits, dst)
  37998 			src = src + uintptr(src_stride)*4
  37999 			dst = dst + uintptr(dst_stride)*4
  38000 			goto _1
  38001 		_1:
  38002 			;
  38003 			y = y + 1
  38004 		}
  38005 	} else {
  38006 		hash_functions = [3]uintptr{
  38007 			0: __ccgo_fp(ApplyPaletteHash0),
  38008 			1: __ccgo_fp(ApplyPaletteHash1),
  38009 			2: __ccgo_fp(ApplyPaletteHash2),
  38010 		}
  38011 		// Try to find a perfect hash function able to go from a color to an index
  38012 		// within 1 << PALETTE_INV_SIZE_BITS in order to build a hash map to go
  38013 		// from color to index in palette.
  38014 		i = 0
  38015 		for {
  38016 			if !(i < int32(3)) {
  38017 				break
  38018 			}
  38019 			use_LUT = int32(1)
  38020 			// Set each element in buffer to max uint16_t.
  38021 			libc.Xmemset(tls, bp, int32(0xff), uint64(4096))
  38022 			j = 0
  38023 			for {
  38024 				if !(j < palette_size) {
  38025 					break
  38026 				}
  38027 				ind = (*(*func(*libc.TLS, uint32_t) uint32_t)(unsafe.Pointer(&struct{ uintptr }{hash_functions[i]})))(tls, **(**uint32_t)(__ccgo_up(palette + uintptr(j)*4)))
  38028 				if uint32((**(**[2048]uint16_t)(__ccgo_up(bp)))[ind]) != uint32(0xffff) {
  38029 					use_LUT = 0
  38030 					break
  38031 				} else {
  38032 					(**(**[2048]uint16_t)(__ccgo_up(bp)))[ind] = uint16(j)
  38033 				}
  38034 				goto _4
  38035 			_4:
  38036 				;
  38037 				j = j + 1
  38038 			}
  38039 			if use_LUT != 0 {
  38040 				break
  38041 			}
  38042 			goto _3
  38043 		_3:
  38044 			;
  38045 			i = i + 1
  38046 		}
  38047 		if i == 0 {
  38048 			prev_pix1 = **(**uint32_t)(__ccgo_up(palette))
  38049 			prev_idx1 = uint32(0)
  38050 			y = 0
  38051 			for {
  38052 				if !(y < height) {
  38053 					break
  38054 				}
  38055 				x = 0
  38056 				for {
  38057 					if !(x < width) {
  38058 						break
  38059 					}
  38060 					pix1 = **(**uint32_t)(__ccgo_up(src + uintptr(x)*4))
  38061 					if pix1 != prev_pix1 {
  38062 						prev_idx1 = uint32((**(**[2048]uint16_t)(__ccgo_up(bp)))[ApplyPaletteHash0(tls, pix1)])
  38063 						prev_pix1 = pix1
  38064 					}
  38065 					**(**uint8_t)(__ccgo_up(tmp_row + uintptr(x))) = uint8(prev_idx1)
  38066 					goto _6
  38067 				_6:
  38068 					;
  38069 					x = x + 1
  38070 				}
  38071 				(*(*func(*libc.TLS, uintptr, int32, int32, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8LBundleColorMap})))(tls, tmp_row, width, xbits, dst)
  38072 				src = src + uintptr(src_stride)*4
  38073 				dst = dst + uintptr(dst_stride)*4
  38074 				goto _5
  38075 			_5:
  38076 				;
  38077 				y = y + 1
  38078 			}
  38079 		} else {
  38080 			if i == int32(1) {
  38081 				prev_pix2 = **(**uint32_t)(__ccgo_up(palette))
  38082 				prev_idx2 = uint32(0)
  38083 				y = 0
  38084 				for {
  38085 					if !(y < height) {
  38086 						break
  38087 					}
  38088 					x = 0
  38089 					for {
  38090 						if !(x < width) {
  38091 							break
  38092 						}
  38093 						pix2 = **(**uint32_t)(__ccgo_up(src + uintptr(x)*4))
  38094 						if pix2 != prev_pix2 {
  38095 							prev_idx2 = uint32((**(**[2048]uint16_t)(__ccgo_up(bp)))[ApplyPaletteHash1(tls, pix2)])
  38096 							prev_pix2 = pix2
  38097 						}
  38098 						**(**uint8_t)(__ccgo_up(tmp_row + uintptr(x))) = uint8(prev_idx2)
  38099 						goto _8
  38100 					_8:
  38101 						;
  38102 						x = x + 1
  38103 					}
  38104 					(*(*func(*libc.TLS, uintptr, int32, int32, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8LBundleColorMap})))(tls, tmp_row, width, xbits, dst)
  38105 					src = src + uintptr(src_stride)*4
  38106 					dst = dst + uintptr(dst_stride)*4
  38107 					goto _7
  38108 				_7:
  38109 					;
  38110 					y = y + 1
  38111 				}
  38112 			} else {
  38113 				if i == int32(2) {
  38114 					prev_pix3 = **(**uint32_t)(__ccgo_up(palette))
  38115 					prev_idx3 = uint32(0)
  38116 					y = 0
  38117 					for {
  38118 						if !(y < height) {
  38119 							break
  38120 						}
  38121 						x = 0
  38122 						for {
  38123 							if !(x < width) {
  38124 								break
  38125 							}
  38126 							pix3 = **(**uint32_t)(__ccgo_up(src + uintptr(x)*4))
  38127 							if pix3 != prev_pix3 {
  38128 								prev_idx3 = uint32((**(**[2048]uint16_t)(__ccgo_up(bp)))[ApplyPaletteHash2(tls, pix3)])
  38129 								prev_pix3 = pix3
  38130 							}
  38131 							**(**uint8_t)(__ccgo_up(tmp_row + uintptr(x))) = uint8(prev_idx3)
  38132 							goto _10
  38133 						_10:
  38134 							;
  38135 							x = x + 1
  38136 						}
  38137 						(*(*func(*libc.TLS, uintptr, int32, int32, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8LBundleColorMap})))(tls, tmp_row, width, xbits, dst)
  38138 						src = src + uintptr(src_stride)*4
  38139 						dst = dst + uintptr(dst_stride)*4
  38140 						goto _9
  38141 					_9:
  38142 						;
  38143 						y = y + 1
  38144 					}
  38145 				} else {
  38146 					PrepareMapToPalette(tls, palette, uint32(palette_size), bp+5120, bp+4096)
  38147 					prev_pix4 = **(**uint32_t)(__ccgo_up(palette))
  38148 					prev_idx4 = uint32(0)
  38149 					y = 0
  38150 					for {
  38151 						if !(y < height) {
  38152 							break
  38153 						}
  38154 						x = 0
  38155 						for {
  38156 							if !(x < width) {
  38157 								break
  38158 							}
  38159 							pix4 = **(**uint32_t)(__ccgo_up(src + uintptr(x)*4))
  38160 							if pix4 != prev_pix4 {
  38161 								prev_idx4 = (**(**[256]uint32_t)(__ccgo_up(bp + 4096)))[SearchColorNoIdx(tls, bp+5120, pix4, palette_size)]
  38162 								prev_pix4 = pix4
  38163 							}
  38164 							**(**uint8_t)(__ccgo_up(tmp_row + uintptr(x))) = uint8(prev_idx4)
  38165 							goto _12
  38166 						_12:
  38167 							;
  38168 							x = x + 1
  38169 						}
  38170 						(*(*func(*libc.TLS, uintptr, int32, int32, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8LBundleColorMap})))(tls, tmp_row, width, xbits, dst)
  38171 						src = src + uintptr(src_stride)*4
  38172 						dst = dst + uintptr(dst_stride)*4
  38173 						goto _11
  38174 					_11:
  38175 						;
  38176 						y = y + 1
  38177 					}
  38178 				}
  38179 			}
  38180 		}
  38181 	}
  38182 	WebPSafeFree(tls, tmp_row)
  38183 	return int32(1)
  38184 }
  38185 
  38186 // C documentation
  38187 //
  38188 //	// Note: Expects "enc->palette" to be set properly.
  38189 func MapImageFromPalette(tls *libc.TLS, enc uintptr) (r int32) {
  38190 	var height, palette_size, width, xbits, v1 int32
  38191 	var palette, pic uintptr
  38192 	var v3, v4 uint32_t
  38193 	_, _, _, _, _, _, _, _, _ = height, palette, palette_size, pic, width, xbits, v1, v3, v4
  38194 	pic = (*VP8LEncoder)(unsafe.Pointer(enc)).Fpic
  38195 	width = (*WebPPicture)(unsafe.Pointer(pic)).Fwidth
  38196 	height = (*WebPPicture)(unsafe.Pointer(pic)).Fheight
  38197 	palette = enc + 104
  38198 	palette_size = (*VP8LEncoder)(unsafe.Pointer(enc)).Fpalette_size
  38199 	// Replace each input pixel by corresponding palette index.
  38200 	// This is done line by line.
  38201 	if palette_size <= int32(4) {
  38202 		if palette_size <= int32(2) {
  38203 			v1 = int32(3)
  38204 		} else {
  38205 			v1 = int32(2)
  38206 		}
  38207 		xbits = v1
  38208 	} else {
  38209 		if palette_size <= int32(16) {
  38210 			v1 = int32(1)
  38211 		} else {
  38212 			v1 = 0
  38213 		}
  38214 		xbits = v1
  38215 	}
  38216 	v3 = uint32(xbits)
  38217 	v4 = (uint32(width) + uint32(libc.Int32FromInt32(1)<<v3) - uint32(1)) >> v3
  38218 	goto _5
  38219 _5:
  38220 	if !(AllocateTransformBuffer(tls, enc, int32(v4), height) != 0) {
  38221 		return 0
  38222 	}
  38223 	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) {
  38224 		return 0
  38225 	}
  38226 	(*VP8LEncoder)(unsafe.Pointer(enc)).Fargb_content = int32(kEncoderPalette)
  38227 	return int32(1)
  38228 }
  38229 
  38230 // C documentation
  38231 //
  38232 //	// Save palette[] to bitstream.
  38233 func EncodePalette(tls *libc.TLS, bw1 uintptr, low_effort int32, enc uintptr, percent_range int32, percent uintptr) (r int32) {
  38234 	bp := tls.Alloc(1024)
  38235 	defer tls.Free(1024)
  38236 	var alpha_and_green, encoded_palette_size, red_and_blue, v3, v6, v9 uint32_t
  38237 	var i, palette_size, v1, v4 int32
  38238 	var palette, v2 uintptr
  38239 	var _ /* tmp_palette at bp+0 */ [256]uint32_t
  38240 	_, _, _, _, _, _, _, _, _, _, _, _ = alpha_and_green, encoded_palette_size, i, palette, palette_size, red_and_blue, v1, v2, v3, v4, v6, v9
  38241 	palette_size = (*VP8LEncoder)(unsafe.Pointer(enc)).Fpalette_size
  38242 	palette = enc + 104
  38243 	if **(**uint32_t)(__ccgo_up(enc + 104 + uintptr(palette_size-int32(1))*4)) == uint32(0) && palette_size > int32(17) {
  38244 		v1 = palette_size - int32(1)
  38245 	} else {
  38246 		v1 = palette_size
  38247 	}
  38248 	// If the last element is 0, do not store it and count on automatic palette
  38249 	// 0-filling. This can only happen if there is no pixel packing, hence if
  38250 	// there are strictly more than 16 colors (after 0 is removed).
  38251 	encoded_palette_size = uint32(v1)
  38252 	v2 = bw1
  38253 	v3 = uint32(TRANSFORM_PRESENT)
  38254 	v4 = int32(1)
  38255 	if libc.Uint64FromInt64(4) == libc.Uint64FromInt32(4) {
  38256 		if v4 > libc.Int32FromInt32(0) {
  38257 			if (*VP8LBitWriter)(unsafe.Pointer(v2)).Fused >= libc.Int32FromInt32(32) {
  38258 				VP8LPutBitsFlushBits(tls, v2)
  38259 			}
  38260 			**(**vp8l_atype_t)(__ccgo_up(v2)) |= uint64(v3) << (*VP8LBitWriter)(unsafe.Pointer(v2)).Fused
  38261 			**(**int32)(__ccgo_up(v2 + 8)) += v4
  38262 		}
  38263 	} else {
  38264 		VP8LPutBitsInternal(tls, v2, v3, v4)
  38265 	}
  38266 	v2 = bw1
  38267 	v3 = uint32(COLOR_INDEXING_TRANSFORM)
  38268 	v1 = int32(2)
  38269 	if libc.Uint64FromInt64(4) == libc.Uint64FromInt32(4) {
  38270 		if v1 > libc.Int32FromInt32(0) {
  38271 			if (*VP8LBitWriter)(unsafe.Pointer(v2)).Fused >= libc.Int32FromInt32(32) {
  38272 				VP8LPutBitsFlushBits(tls, v2)
  38273 			}
  38274 			**(**vp8l_atype_t)(__ccgo_up(v2)) |= uint64(v3) << (*VP8LBitWriter)(unsafe.Pointer(v2)).Fused
  38275 			**(**int32)(__ccgo_up(v2 + 8)) += v1
  38276 		}
  38277 	} else {
  38278 		VP8LPutBitsInternal(tls, v2, v3, v1)
  38279 	}
  38280 	v2 = bw1
  38281 	v3 = encoded_palette_size - uint32(1)
  38282 	v1 = int32(8)
  38283 	if libc.Uint64FromInt64(4) == libc.Uint64FromInt32(4) {
  38284 		if v1 > libc.Int32FromInt32(0) {
  38285 			if (*VP8LBitWriter)(unsafe.Pointer(v2)).Fused >= libc.Int32FromInt32(32) {
  38286 				VP8LPutBitsFlushBits(tls, v2)
  38287 			}
  38288 			**(**vp8l_atype_t)(__ccgo_up(v2)) |= uint64(v3) << (*VP8LBitWriter)(unsafe.Pointer(v2)).Fused
  38289 			**(**int32)(__ccgo_up(v2 + 8)) += v1
  38290 		}
  38291 	} else {
  38292 		VP8LPutBitsInternal(tls, v2, v3, v1)
  38293 	}
  38294 	i = int32(encoded_palette_size - uint32(1))
  38295 	for {
  38296 		if !(i >= int32(1)) {
  38297 			break
  38298 		}
  38299 		v3 = **(**uint32_t)(__ccgo_up(palette + uintptr(i)*4))
  38300 		v6 = **(**uint32_t)(__ccgo_up(palette + uintptr(i-int32(1))*4))
  38301 		alpha_and_green = uint32(0x00ff00ff) + v3&uint32(0xff00ff00) - v6&uint32(0xff00ff00)
  38302 		red_and_blue = uint32(0xff00ff00) + v3&uint32(0x00ff00ff) - v6&uint32(0x00ff00ff)
  38303 		v9 = alpha_and_green&uint32(0xff00ff00) | red_and_blue&uint32(0x00ff00ff)
  38304 		goto _15
  38305 	_15:
  38306 		(**(**[256]uint32_t)(__ccgo_up(bp)))[i] = v9
  38307 		goto _11
  38308 	_11:
  38309 		;
  38310 		i = i - 1
  38311 	}
  38312 	(**(**[256]uint32_t)(__ccgo_up(bp)))[0] = **(**uint32_t)(__ccgo_up(palette))
  38313 	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)
  38314 }
  38315 
  38316 // -----------------------------------------------------------------------------
  38317 // VP8LEncoder
  38318 
  38319 func VP8LEncoderNew(tls *libc.TLS, config uintptr, picture uintptr) (r uintptr) {
  38320 	var enc uintptr
  38321 	_ = enc
  38322 	enc = WebPSafeCalloc(tls, uint64(1), uint64(2328))
  38323 	if enc == libc.UintptrFromInt32(0) {
  38324 		WebPEncodingSetError(tls, picture, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  38325 		return libc.UintptrFromInt32(0)
  38326 	}
  38327 	(*VP8LEncoder)(unsafe.Pointer(enc)).Fconfig = config
  38328 	(*VP8LEncoder)(unsafe.Pointer(enc)).Fpic = picture
  38329 	(*VP8LEncoder)(unsafe.Pointer(enc)).Fargb_content = int32(kEncoderNone)
  38330 	VP8LEncDspInit(tls)
  38331 	return enc
  38332 }
  38333 
  38334 func VP8LEncoderDelete(tls *libc.TLS, enc uintptr) {
  38335 	var i int32
  38336 	_ = i
  38337 	if enc != libc.UintptrFromInt32(0) {
  38338 		VP8LHashChainClear(tls, enc+2312)
  38339 		i = 0
  38340 		for {
  38341 			if !(i < int32(4)) {
  38342 				break
  38343 			}
  38344 			VP8LBackwardRefsClear(tls, enc+2152+uintptr(i)*40)
  38345 			goto _1
  38346 		_1:
  38347 			;
  38348 			i = i + 1
  38349 		}
  38350 		ClearTransformBuffer(tls, enc)
  38351 		WebPSafeFree(tls, enc)
  38352 	}
  38353 }
  38354 
  38355 // -----------------------------------------------------------------------------
  38356 // Main call
  38357 
  38358 type StreamEncodeContext = struct {
  38359 	Fconfig                   uintptr
  38360 	Fpicture                  uintptr
  38361 	Fbw                       uintptr
  38362 	Fenc                      uintptr
  38363 	Fcrunch_configs           [14]CrunchConfig
  38364 	Fnum_crunch_configs       int32
  38365 	Fred_and_blue_always_zero int32
  38366 	Fstats                    uintptr
  38367 }
  38368 
  38369 func EncodeStreamHook(tls *libc.TLS, input uintptr, data2 uintptr) (r int32) {
  38370 	bp := tls.Alloc(128)
  38371 	defer tls.Free(128)
  38372 	var best_size, byte_position, v12, v2 size_t
  38373 	var bw2, config, crunch_configs, enc, params, picture, stats, v1, v8 uintptr
  38374 	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
  38375 	var v9 uint32_t
  38376 	var _ /* bw_best at bp+64 */ VP8LBitWriter
  38377 	var _ /* bw_init at bp+16 */ VP8LBitWriter
  38378 	var _ /* cross_color_transform_bits at bp+116 */ int32
  38379 	var _ /* data_size at bp+8 */ int32
  38380 	var _ /* hdr_size at bp+4 */ int32
  38381 	var _ /* percent at bp+0 */ int32
  38382 	var _ /* predictor_transform_bits at bp+112 */ int32
  38383 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  38384 	params = input
  38385 	config = (*StreamEncodeContext)(unsafe.Pointer(params)).Fconfig
  38386 	picture = (*StreamEncodeContext)(unsafe.Pointer(params)).Fpicture
  38387 	bw2 = (*StreamEncodeContext)(unsafe.Pointer(params)).Fbw
  38388 	enc = (*StreamEncodeContext)(unsafe.Pointer(params)).Fenc
  38389 	crunch_configs = params + 32
  38390 	num_crunch_configs = (*StreamEncodeContext)(unsafe.Pointer(params)).Fnum_crunch_configs
  38391 	red_and_blue_always_zero = (*StreamEncodeContext)(unsafe.Pointer(params)).Fred_and_blue_always_zero
  38392 	stats = (*StreamEncodeContext)(unsafe.Pointer(params)).Fstats
  38393 	quality = int32((*WebPConfig)(unsafe.Pointer(config)).Fquality)
  38394 	low_effort = libc.BoolInt32((*WebPConfig)(unsafe.Pointer(config)).Fmethod == libc.Int32FromInt32(0))
  38395 	width = (*WebPPicture)(unsafe.Pointer(picture)).Fwidth
  38396 	height = (*WebPPicture)(unsafe.Pointer(picture)).Fheight
  38397 	v1 = bw2
  38398 	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)))
  38399 	goto _3
  38400 _3:
  38401 	byte_position = v2
  38402 	**(**int32)(__ccgo_up(bp)) = int32(2) // for WebPProgressHook
  38403 	use_near_lossless = 0
  38404 	**(**int32)(__ccgo_up(bp + 4)) = 0
  38405 	**(**int32)(__ccgo_up(bp + 8)) = 0
  38406 	best_size = ^libc.Uint64FromInt32(0)
  38407 	**(**VP8LBitWriter)(__ccgo_up(bp + 16)) = **(**VP8LBitWriter)(__ccgo_up(bw2))
  38408 	_ = data2
  38409 	if !(VP8LBitWriterInit(tls, bp+64, uint64(0)) != 0) || num_crunch_configs > int32(1) && !(VP8LBitWriterClone(tls, bw2, bp+64) != 0) {
  38410 		WebPEncodingSetError(tls, picture, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  38411 		goto Error
  38412 	}
  38413 	idx = 0
  38414 	for {
  38415 		if !(idx < num_crunch_configs) {
  38416 			break
  38417 		}
  38418 		entropy_idx = (**(**CrunchConfig)(__ccgo_up(crunch_configs + uintptr(idx)*28))).Fentropy_idx
  38419 		remaining_percent = int32(97) / num_crunch_configs
  38420 		**(**int32)(__ccgo_up(bp + 112)) = 0
  38421 		**(**int32)(__ccgo_up(bp + 116)) = 0
  38422 		(*VP8LEncoder)(unsafe.Pointer(enc)).Fuse_palette = libc.BoolInt32(entropy_idx == int32(kPalette) || entropy_idx == int32(kPaletteAndSpatial))
  38423 		(*VP8LEncoder)(unsafe.Pointer(enc)).Fuse_subtract_green = libc.BoolInt32(entropy_idx == int32(kSubGreen) || entropy_idx == int32(kSpatialSubGreen))
  38424 		(*VP8LEncoder)(unsafe.Pointer(enc)).Fuse_predict = libc.BoolInt32(entropy_idx == int32(kSpatial) || entropy_idx == int32(kSpatialSubGreen) || entropy_idx == int32(kPaletteAndSpatial))
  38425 		// When using a palette, R/B==0, hence no need to test for cross-color.
  38426 		if low_effort != 0 || (*VP8LEncoder)(unsafe.Pointer(enc)).Fuse_palette != 0 {
  38427 			(*VP8LEncoder)(unsafe.Pointer(enc)).Fuse_cross_color = 0
  38428 		} else {
  38429 			if red_and_blue_always_zero != 0 {
  38430 				v5 = 0
  38431 			} else {
  38432 				v5 = (*VP8LEncoder)(unsafe.Pointer(enc)).Fuse_predict
  38433 			}
  38434 			(*VP8LEncoder)(unsafe.Pointer(enc)).Fuse_cross_color = v5
  38435 		}
  38436 		// Reset any parameter in the encoder that is set in the previous iteration.
  38437 		(*VP8LEncoder)(unsafe.Pointer(enc)).Fcache_bits = 0
  38438 		VP8LBackwardRefsClear(tls, enc+2152)
  38439 		VP8LBackwardRefsClear(tls, enc+2152+1*40)
  38440 		// Apply near-lossless preprocessing.
  38441 		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))
  38442 		if use_near_lossless != 0 {
  38443 			if !(AllocateTransformBuffer(tls, enc, width, height) != 0) {
  38444 				goto Error
  38445 			}
  38446 			if (*VP8LEncoder)(unsafe.Pointer(enc)).Fargb_content != int32(kEncoderNearLossless) && !(VP8ApplyNearLossless(tls, picture, (*WebPConfig)(unsafe.Pointer(config)).Fnear_lossless, (*VP8LEncoder)(unsafe.Pointer(enc)).Fargb) != 0) {
  38447 				WebPEncodingSetError(tls, picture, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  38448 				goto Error
  38449 			}
  38450 			(*VP8LEncoder)(unsafe.Pointer(enc)).Fargb_content = int32(kEncoderNearLossless)
  38451 		} else {
  38452 			(*VP8LEncoder)(unsafe.Pointer(enc)).Fargb_content = int32(kEncoderNone)
  38453 		}
  38454 		// Encode palette
  38455 		if (*VP8LEncoder)(unsafe.Pointer(enc)).Fuse_palette != 0 {
  38456 			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) {
  38457 				WebPEncodingSetError(tls, (*VP8LEncoder)(unsafe.Pointer(enc)).Fpic, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  38458 				goto Error
  38459 			}
  38460 			percent_range = remaining_percent / int32(4)
  38461 			if !(EncodePalette(tls, bw2, low_effort, enc, percent_range, bp) != 0) {
  38462 				goto Error
  38463 			}
  38464 			remaining_percent = remaining_percent - percent_range
  38465 			if !(MapImageFromPalette(tls, enc) != 0) {
  38466 				goto Error
  38467 			}
  38468 			// If using a color cache, do not have it bigger than the number of
  38469 			// colors.
  38470 			if (*VP8LEncoder)(unsafe.Pointer(enc)).Fpalette_size < libc.Int32FromInt32(1)<<libc.Int32FromInt32(MAX_COLOR_CACHE_BITS) {
  38471 				v5 = int32(31) ^ libc.X__builtin_clz(tls, uint32((*VP8LEncoder)(unsafe.Pointer(enc)).Fpalette_size))
  38472 				goto _7
  38473 			_7:
  38474 				(*VP8LEncoder)(unsafe.Pointer(enc)).Fcache_bits = v5 + int32(1)
  38475 			}
  38476 		}
  38477 		// In case image is not packed.
  38478 		if (*VP8LEncoder)(unsafe.Pointer(enc)).Fargb_content != int32(kEncoderNearLossless) && (*VP8LEncoder)(unsafe.Pointer(enc)).Fargb_content != int32(kEncoderPalette) {
  38479 			if !(MakeInputImageCopy(tls, enc) != 0) {
  38480 				goto Error
  38481 			}
  38482 		}
  38483 		// -------------------------------------------------------------------------
  38484 		// Apply transforms and write transform data.
  38485 		if (*VP8LEncoder)(unsafe.Pointer(enc)).Fuse_subtract_green != 0 {
  38486 			ApplySubtractGreen(tls, enc, (*VP8LEncoder)(unsafe.Pointer(enc)).Fcurrent_width, height, bw2)
  38487 		}
  38488 		if (*VP8LEncoder)(unsafe.Pointer(enc)).Fuse_predict != 0 {
  38489 			percent_range = remaining_percent / int32(3)
  38490 			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) {
  38491 				goto Error
  38492 			}
  38493 			remaining_percent = remaining_percent - percent_range
  38494 		}
  38495 		if (*VP8LEncoder)(unsafe.Pointer(enc)).Fuse_cross_color != 0 {
  38496 			percent_range = remaining_percent / int32(2)
  38497 			if !(ApplyCrossColorFilter(tls, enc, (*VP8LEncoder)(unsafe.Pointer(enc)).Fcurrent_width, height, quality, low_effort, bw2, percent_range, bp, bp+116) != 0) {
  38498 				goto Error
  38499 			}
  38500 			remaining_percent = remaining_percent - percent_range
  38501 		}
  38502 		v1 = bw2
  38503 		v9 = libc.BoolUint32(!(libc.Int32FromInt32(TRANSFORM_PRESENT) != 0))
  38504 		v5 = int32(1)
  38505 		if libc.Uint64FromInt64(4) == libc.Uint64FromInt32(4) {
  38506 			if v5 > libc.Int32FromInt32(0) {
  38507 				if (*VP8LBitWriter)(unsafe.Pointer(v1)).Fused >= libc.Int32FromInt32(32) {
  38508 					VP8LPutBitsFlushBits(tls, v1)
  38509 				}
  38510 				**(**vp8l_atype_t)(__ccgo_up(v1)) |= uint64(v9) << (*VP8LBitWriter)(unsafe.Pointer(v1)).Fused
  38511 				**(**int32)(__ccgo_up(v1 + 8)) += v5
  38512 			}
  38513 		} else {
  38514 			VP8LPutBitsInternal(tls, v1, v9, v5)
  38515 		} // No more transforms.
  38516 		// -------------------------------------------------------------------------
  38517 		// Encode and write the transformed image.
  38518 		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) {
  38519 			goto Error
  38520 		}
  38521 		// If we are better than what we already have.
  38522 		v1 = bw2
  38523 		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)))
  38524 		goto _13
  38525 	_13:
  38526 		if v2 < best_size {
  38527 			v8 = bw2
  38528 			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)))
  38529 			goto _16
  38530 		_16:
  38531 			best_size = v12
  38532 			// Store the BitWriter.
  38533 			VP8LBitWriterSwap(tls, bw2, bp+64)
  38534 			// Update the stats.
  38535 			if stats != libc.UintptrFromInt32(0) {
  38536 				(*WebPAuxStats)(unsafe.Pointer(stats)).Flossless_features = uint32(0)
  38537 				if (*VP8LEncoder)(unsafe.Pointer(enc)).Fuse_predict != 0 {
  38538 					**(**uint32_t)(__ccgo_up(stats + 148)) |= uint32(1)
  38539 				}
  38540 				if (*VP8LEncoder)(unsafe.Pointer(enc)).Fuse_cross_color != 0 {
  38541 					**(**uint32_t)(__ccgo_up(stats + 148)) |= uint32(2)
  38542 				}
  38543 				if (*VP8LEncoder)(unsafe.Pointer(enc)).Fuse_subtract_green != 0 {
  38544 					**(**uint32_t)(__ccgo_up(stats + 148)) |= uint32(4)
  38545 				}
  38546 				if (*VP8LEncoder)(unsafe.Pointer(enc)).Fuse_palette != 0 {
  38547 					**(**uint32_t)(__ccgo_up(stats + 148)) |= uint32(8)
  38548 				}
  38549 				(*WebPAuxStats)(unsafe.Pointer(stats)).Fhistogram_bits = (*VP8LEncoder)(unsafe.Pointer(enc)).Fhisto_bits
  38550 				(*WebPAuxStats)(unsafe.Pointer(stats)).Ftransform_bits = **(**int32)(__ccgo_up(bp + 112))
  38551 				(*WebPAuxStats)(unsafe.Pointer(stats)).Fcross_color_transform_bits = **(**int32)(__ccgo_up(bp + 116))
  38552 				(*WebPAuxStats)(unsafe.Pointer(stats)).Fcache_bits = (*VP8LEncoder)(unsafe.Pointer(enc)).Fcache_bits
  38553 				(*WebPAuxStats)(unsafe.Pointer(stats)).Fpalette_size = (*VP8LEncoder)(unsafe.Pointer(enc)).Fpalette_size
  38554 				(*WebPAuxStats)(unsafe.Pointer(stats)).Flossless_size = int32(best_size - byte_position)
  38555 				(*WebPAuxStats)(unsafe.Pointer(stats)).Flossless_hdr_size = **(**int32)(__ccgo_up(bp + 4))
  38556 				(*WebPAuxStats)(unsafe.Pointer(stats)).Flossless_data_size = **(**int32)(__ccgo_up(bp + 8))
  38557 			}
  38558 		}
  38559 		// Reset the bit writer for the following iteration if any.
  38560 		if num_crunch_configs > int32(1) {
  38561 			VP8LBitWriterReset(tls, bp+16, bw2)
  38562 		}
  38563 		goto _4
  38564 	_4:
  38565 		;
  38566 		idx = idx + 1
  38567 	}
  38568 	VP8LBitWriterSwap(tls, bp+64, bw2)
  38569 	goto Error
  38570 Error:
  38571 	;
  38572 	VP8LBitWriterWipeOut(tls, bp+64)
  38573 	// The hook should return false in case of error.
  38574 	return libc.BoolInt32((*WebPPicture)(unsafe.Pointer((*StreamEncodeContext)(unsafe.Pointer(params)).Fpicture)).Ferror_code == int32(VP8_ENC_OK))
  38575 }
  38576 
  38577 func VP8LEncodeStream(tls *libc.TLS, config uintptr, picture1 uintptr, bw_main uintptr) (r int32) {
  38578 	bp := tls.Alloc(1872)
  38579 	defer tls.Free(1872)
  38580 	var enc_main, enc_side, param, worker, worker_interface, v7, v8 uintptr
  38581 	var idx, num_crunch_configs_side, ok_main, ok_side, params_size, v1 int32
  38582 	var v11, v14 size_t
  38583 	var _ /* bw_side at bp+1568 */ VP8LBitWriter
  38584 	var _ /* crunch_configs at bp+0 */ [14]CrunchConfig
  38585 	var _ /* num_crunch_configs_main at bp+392 */ int32
  38586 	var _ /* params_main at bp+496 */ StreamEncodeContext
  38587 	var _ /* params_side at bp+936 */ StreamEncodeContext
  38588 	var _ /* picture_side at bp+1616 */ WebPPicture
  38589 	var _ /* red_and_blue_always_zero at bp+396 */ int32
  38590 	var _ /* stats_side at bp+1376 */ WebPAuxStats
  38591 	var _ /* worker_main at bp+400 */ WebPWorker
  38592 	var _ /* worker_side at bp+448 */ WebPWorker
  38593 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = enc_main, enc_side, idx, num_crunch_configs_side, ok_main, ok_side, param, params_size, worker, worker_interface, v1, v11, v14, v7, v8
  38594 	enc_main = VP8LEncoderNew(tls, config, picture1)
  38595 	enc_side = libc.UintptrFromInt32(0)
  38596 	num_crunch_configs_side = 0
  38597 	**(**int32)(__ccgo_up(bp + 396)) = 0
  38598 	worker_interface = WebPGetWorkerInterface(tls)
  38599 	if enc_main == libc.UintptrFromInt32(0) || !(VP8LBitWriterInit(tls, bp+1568, uint64(0)) != 0) {
  38600 		VP8LEncoderDelete(tls, enc_main)
  38601 		return WebPEncodingSetError(tls, picture1, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  38602 	}
  38603 	// Avoid "garbage value" error from Clang's static analysis tool.
  38604 	v1 = WebPPictureInitInternal(tls, bp+1616, int32(WEBP_ENCODER_ABI_VERSION))
  38605 	goto _2
  38606 _2:
  38607 	if !(v1 != 0) {
  38608 		goto Error
  38609 	}
  38610 	// Analyze image (entropy, num_palettes etc)
  38611 	if !(EncoderAnalyze(tls, enc_main, bp, bp+392, bp+396) != 0) || !(EncoderInit(tls, enc_main) != 0) {
  38612 		WebPEncodingSetError(tls, picture1, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  38613 		goto Error
  38614 	}
  38615 	// Split the configs between the main and side threads (if any).
  38616 	if (*WebPConfig)(unsafe.Pointer(config)).Fthread_level > 0 {
  38617 		num_crunch_configs_side = **(**int32)(__ccgo_up(bp + 392)) / int32(2)
  38618 		idx = 0
  38619 		for {
  38620 			if !(idx < num_crunch_configs_side) {
  38621 				break
  38622 			}
  38623 			**(**CrunchConfig)(__ccgo_up(bp + 936 + 32 + uintptr(idx)*28)) = (**(**[14]CrunchConfig)(__ccgo_up(bp)))[**(**int32)(__ccgo_up(bp + 392))-num_crunch_configs_side+idx]
  38624 			goto _3
  38625 		_3:
  38626 			;
  38627 			idx = idx + 1
  38628 		}
  38629 		(**(**StreamEncodeContext)(__ccgo_up(bp + 936))).Fnum_crunch_configs = num_crunch_configs_side
  38630 	}
  38631 	**(**int32)(__ccgo_up(bp + 392)) = **(**int32)(__ccgo_up(bp + 392)) - num_crunch_configs_side
  38632 	idx = 0
  38633 	for {
  38634 		if !(idx < **(**int32)(__ccgo_up(bp + 392))) {
  38635 			break
  38636 		}
  38637 		**(**CrunchConfig)(__ccgo_up(bp + 496 + 32 + uintptr(idx)*28)) = (**(**[14]CrunchConfig)(__ccgo_up(bp)))[idx]
  38638 		goto _4
  38639 	_4:
  38640 		;
  38641 		idx = idx + 1
  38642 	}
  38643 	(**(**StreamEncodeContext)(__ccgo_up(bp + 496))).Fnum_crunch_configs = **(**int32)(__ccgo_up(bp + 392))
  38644 	// Fill in the parameters for the thread workers.
  38645 	if num_crunch_configs_side > 0 {
  38646 		v1 = int32(2)
  38647 	} else {
  38648 		v1 = int32(1)
  38649 	}
  38650 	params_size = v1
  38651 	idx = 0
  38652 	for {
  38653 		if !(idx < params_size) {
  38654 			break
  38655 		}
  38656 		if idx == 0 {
  38657 			v7 = bp + 400
  38658 		} else {
  38659 			v7 = bp + 448
  38660 		}
  38661 		// Create the parameters for each worker.
  38662 		worker = v7
  38663 		if idx == 0 {
  38664 			v8 = bp + 496
  38665 		} else {
  38666 			v8 = bp + 936
  38667 		}
  38668 		param = v8
  38669 		(*StreamEncodeContext)(unsafe.Pointer(param)).Fconfig = config
  38670 		(*StreamEncodeContext)(unsafe.Pointer(param)).Fred_and_blue_always_zero = **(**int32)(__ccgo_up(bp + 396))
  38671 		if idx == 0 {
  38672 			(*StreamEncodeContext)(unsafe.Pointer(param)).Fpicture = picture1
  38673 			(*StreamEncodeContext)(unsafe.Pointer(param)).Fstats = (*WebPPicture)(unsafe.Pointer(picture1)).Fstats
  38674 			(*StreamEncodeContext)(unsafe.Pointer(param)).Fbw = bw_main
  38675 			(*StreamEncodeContext)(unsafe.Pointer(param)).Fenc = enc_main
  38676 		} else {
  38677 			// Create a side picture (error_code is not thread-safe).
  38678 			if !(WebPPictureView(tls, picture1, 0, 0, (*WebPPicture)(unsafe.Pointer(picture1)).Fwidth, (*WebPPicture)(unsafe.Pointer(picture1)).Fheight, bp+1616) != 0) {
  38679 			}
  38680 			(**(**WebPPicture)(__ccgo_up(bp + 1616))).Fprogress_hook = libc.UintptrFromInt32(0) // Progress hook is not thread-safe.
  38681 			(*StreamEncodeContext)(unsafe.Pointer(param)).Fpicture = bp + 1616                  // No need to free a view afterwards.
  38682 			if (*WebPPicture)(unsafe.Pointer(picture1)).Fstats == libc.UintptrFromInt32(0) {
  38683 				v7 = libc.UintptrFromInt32(0)
  38684 			} else {
  38685 				v7 = bp + 1376
  38686 			}
  38687 			(*StreamEncodeContext)(unsafe.Pointer(param)).Fstats = v7
  38688 			// Create a side bit writer.
  38689 			if !(VP8LBitWriterClone(tls, bw_main, bp+1568) != 0) {
  38690 				WebPEncodingSetError(tls, picture1, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  38691 				goto Error
  38692 			}
  38693 			(*StreamEncodeContext)(unsafe.Pointer(param)).Fbw = bp + 1568
  38694 			// Create a side encoder.
  38695 			enc_side = VP8LEncoderNew(tls, config, bp+1616)
  38696 			if enc_side == libc.UintptrFromInt32(0) || !(EncoderInit(tls, enc_side) != 0) {
  38697 				WebPEncodingSetError(tls, picture1, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  38698 				goto Error
  38699 			}
  38700 			// Copy the values that were computed for the main encoder.
  38701 			(*VP8LEncoder)(unsafe.Pointer(enc_side)).Fhisto_bits = (*VP8LEncoder)(unsafe.Pointer(enc_main)).Fhisto_bits
  38702 			(*VP8LEncoder)(unsafe.Pointer(enc_side)).Fpredictor_transform_bits = (*VP8LEncoder)(unsafe.Pointer(enc_main)).Fpredictor_transform_bits
  38703 			(*VP8LEncoder)(unsafe.Pointer(enc_side)).Fcross_color_transform_bits = (*VP8LEncoder)(unsafe.Pointer(enc_main)).Fcross_color_transform_bits
  38704 			(*VP8LEncoder)(unsafe.Pointer(enc_side)).Fpalette_size = (*VP8LEncoder)(unsafe.Pointer(enc_main)).Fpalette_size
  38705 			libc.Xmemcpy(tls, enc_side+104, enc_main+104, uint64(1024))
  38706 			libc.Xmemcpy(tls, enc_side+1128, enc_main+1128, uint64(1024))
  38707 			(*StreamEncodeContext)(unsafe.Pointer(param)).Fenc = enc_side
  38708 		}
  38709 		// Create the workers.
  38710 		(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(&struct{ uintptr }{(*WebPWorkerInterface)(unsafe.Pointer(worker_interface)).FInit})))(tls, worker)
  38711 		(*WebPWorker)(unsafe.Pointer(worker)).Fdata1 = param
  38712 		(*WebPWorker)(unsafe.Pointer(worker)).Fdata2 = libc.UintptrFromInt32(0)
  38713 		(*WebPWorker)(unsafe.Pointer(worker)).Fhook = __ccgo_fp(EncodeStreamHook)
  38714 		goto _6
  38715 	_6:
  38716 		;
  38717 		idx = idx + 1
  38718 	}
  38719 	// Start the second thread if needed.
  38720 	if num_crunch_configs_side != 0 {
  38721 		if !((*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*WebPWorkerInterface)(unsafe.Pointer(worker_interface)).FReset})))(tls, bp+448) != 0) {
  38722 			WebPEncodingSetError(tls, picture1, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  38723 			goto Error
  38724 		}
  38725 		// This line is here and not in the param initialization above to remove a
  38726 		// Clang static analyzer warning.
  38727 		if (*WebPPicture)(unsafe.Pointer(picture1)).Fstats != libc.UintptrFromInt32(0) {
  38728 			libc.Xmemcpy(tls, bp+1376, (*WebPPicture)(unsafe.Pointer(picture1)).Fstats, uint64(188))
  38729 		}
  38730 		(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(&struct{ uintptr }{(*WebPWorkerInterface)(unsafe.Pointer(worker_interface)).FLaunch})))(tls, bp+448)
  38731 	}
  38732 	// Execute the main thread.
  38733 	(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(&struct{ uintptr }{(*WebPWorkerInterface)(unsafe.Pointer(worker_interface)).FExecute})))(tls, bp+400)
  38734 	ok_main = (*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*WebPWorkerInterface)(unsafe.Pointer(worker_interface)).FSync})))(tls, bp+400)
  38735 	(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(&struct{ uintptr }{(*WebPWorkerInterface)(unsafe.Pointer(worker_interface)).FEnd})))(tls, bp+400)
  38736 	if num_crunch_configs_side != 0 {
  38737 		// Wait for the second thread.
  38738 		ok_side = (*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*WebPWorkerInterface)(unsafe.Pointer(worker_interface)).FSync})))(tls, bp+448)
  38739 		(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(&struct{ uintptr }{(*WebPWorkerInterface)(unsafe.Pointer(worker_interface)).FEnd})))(tls, bp+448)
  38740 		if !(ok_main != 0) || !(ok_side != 0) {
  38741 			if (*WebPPicture)(unsafe.Pointer(picture1)).Ferror_code == int32(VP8_ENC_OK) {
  38742 				WebPEncodingSetError(tls, picture1, (**(**WebPPicture)(__ccgo_up(bp + 1616))).Ferror_code)
  38743 			}
  38744 			goto Error
  38745 		}
  38746 		v7 = bp + 1568
  38747 		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)))
  38748 		goto _12
  38749 	_12:
  38750 		v8 = bw_main
  38751 		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)))
  38752 		goto _15
  38753 	_15:
  38754 		if v11 < v14 {
  38755 			VP8LBitWriterSwap(tls, bw_main, bp+1568)
  38756 			if (*WebPPicture)(unsafe.Pointer(picture1)).Fstats != libc.UintptrFromInt32(0) {
  38757 				libc.Xmemcpy(tls, (*WebPPicture)(unsafe.Pointer(picture1)).Fstats, bp+1376, uint64(188))
  38758 			}
  38759 		}
  38760 	}
  38761 	goto Error
  38762 Error:
  38763 	;
  38764 	VP8LBitWriterWipeOut(tls, bp+1568)
  38765 	VP8LEncoderDelete(tls, enc_main)
  38766 	VP8LEncoderDelete(tls, enc_side)
  38767 	return libc.BoolInt32((*WebPPicture)(unsafe.Pointer(picture1)).Ferror_code == int32(VP8_ENC_OK))
  38768 }
  38769 
  38770 func VP8LEncodeImage(tls *libc.TLS, config uintptr, picture uintptr) (r int32) {
  38771 	bp := tls.Alloc(64)
  38772 	defer tls.Free(64)
  38773 	var has_alpha, height, initial_size, mb_h, mb_w, width, v1 int32
  38774 	var stats uintptr
  38775 	var _ /* bw at bp+16 */ VP8LBitWriter
  38776 	var _ /* coded_size at bp+0 */ size_t
  38777 	var _ /* percent at bp+8 */ int32
  38778 	_, _, _, _, _, _, _, _ = has_alpha, height, initial_size, mb_h, mb_w, stats, width, v1
  38779 	**(**int32)(__ccgo_up(bp + 8)) = 0
  38780 	if picture == libc.UintptrFromInt32(0) {
  38781 		return 0
  38782 	}
  38783 	if config == libc.UintptrFromInt32(0) || (*WebPPicture)(unsafe.Pointer(picture)).Fargb == libc.UintptrFromInt32(0) {
  38784 		return WebPEncodingSetError(tls, picture, int32(VP8_ENC_ERROR_NULL_PARAMETER))
  38785 	}
  38786 	width = (*WebPPicture)(unsafe.Pointer(picture)).Fwidth
  38787 	height = (*WebPPicture)(unsafe.Pointer(picture)).Fheight
  38788 	// Initialize BitWriter with size corresponding to 16 bpp to photo images and
  38789 	// 8 bpp for graphical images.
  38790 	if (*WebPConfig)(unsafe.Pointer(config)).Fimage_hint == int32(WEBP_HINT_GRAPH) {
  38791 		v1 = width * height
  38792 	} else {
  38793 		v1 = width * height * int32(2)
  38794 	}
  38795 	initial_size = v1
  38796 	if !(VP8LBitWriterInit(tls, bp+16, uint64(initial_size)) != 0) {
  38797 		WebPEncodingSetError(tls, picture, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  38798 		goto Error
  38799 	}
  38800 	if !!(WebPReportProgress(tls, picture, int32(1), bp+8) != 0) {
  38801 		goto _2
  38802 	}
  38803 	goto UserAbort
  38804 UserAbort:
  38805 	;
  38806 	WebPEncodingSetError(tls, picture, int32(VP8_ENC_ERROR_USER_ABORT))
  38807 	goto Error
  38808 _2:
  38809 	;
  38810 	// Reset stats (for pure lossless coding)
  38811 	if (*WebPPicture)(unsafe.Pointer(picture)).Fstats != libc.UintptrFromInt32(0) {
  38812 		stats = (*WebPPicture)(unsafe.Pointer(picture)).Fstats
  38813 		libc.Xmemset(tls, stats, 0, uint64(188))
  38814 		**(**float32)(__ccgo_up(stats + 4)) = libc.Float32FromFloat32(99)
  38815 		**(**float32)(__ccgo_up(stats + 4 + 1*4)) = libc.Float32FromFloat32(99)
  38816 		**(**float32)(__ccgo_up(stats + 4 + 2*4)) = libc.Float32FromFloat32(99)
  38817 		**(**float32)(__ccgo_up(stats + 4 + 3*4)) = libc.Float32FromFloat32(99)
  38818 		**(**float32)(__ccgo_up(stats + 4 + 4*4)) = libc.Float32FromFloat32(99)
  38819 	}
  38820 	// Write image size.
  38821 	if !(WriteImageSize(tls, picture, bp+16) != 0) {
  38822 		WebPEncodingSetError(tls, picture, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  38823 		goto Error
  38824 	}
  38825 	has_alpha = WebPPictureHasTransparency(tls, picture)
  38826 	// Write the non-trivial Alpha flag and lossless version.
  38827 	if !(WriteRealAlphaAndVersion(tls, bp+16, has_alpha) != 0) {
  38828 		WebPEncodingSetError(tls, picture, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  38829 		goto Error
  38830 	}
  38831 	if !(WebPReportProgress(tls, picture, int32(2), bp+8) != 0) {
  38832 		goto UserAbort
  38833 	}
  38834 	// Encode main image stream.
  38835 	if !(VP8LEncodeStream(tls, config, picture, bp+16) != 0) {
  38836 		goto Error
  38837 	}
  38838 	if !(WebPReportProgress(tls, picture, int32(99), bp+8) != 0) {
  38839 		goto UserAbort
  38840 	}
  38841 	// Finish the RIFF chunk.
  38842 	if !(WriteImage(tls, picture, bp+16, bp) != 0) {
  38843 		goto Error
  38844 	}
  38845 	if !(WebPReportProgress(tls, picture, int32(100), bp+8) != 0) {
  38846 		goto UserAbort
  38847 	}
  38848 	// Save size.
  38849 	if (*WebPPicture)(unsafe.Pointer(picture)).Fstats != libc.UintptrFromInt32(0) {
  38850 		**(**int32)(__ccgo_up((*WebPPicture)(unsafe.Pointer(picture)).Fstats)) += int32(**(**size_t)(__ccgo_up(bp)))
  38851 		(*WebPAuxStats)(unsafe.Pointer((*WebPPicture)(unsafe.Pointer(picture)).Fstats)).Flossless_size = int32(**(**size_t)(__ccgo_up(bp)))
  38852 	}
  38853 	if (*WebPPicture)(unsafe.Pointer(picture)).Fextra_info != libc.UintptrFromInt32(0) {
  38854 		mb_w = (width + int32(15)) >> int32(4)
  38855 		mb_h = (height + int32(15)) >> int32(4)
  38856 		libc.Xmemset(tls, (*WebPPicture)(unsafe.Pointer(picture)).Fextra_info, 0, uint64(mb_w*mb_h)*uint64(1))
  38857 	}
  38858 	goto Error
  38859 Error:
  38860 	;
  38861 	if (**(**VP8LBitWriter)(__ccgo_up(bp + 16))).Ferror1 != 0 {
  38862 		WebPEncodingSetError(tls, picture, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  38863 	}
  38864 	VP8LBitWriterWipeOut(tls, bp+16)
  38865 	return libc.BoolInt32((*WebPPicture)(unsafe.Pointer(picture)).Ferror_code == int32(VP8_ENC_OK))
  38866 }
  38867 
  38868 const VP8L_MAGIC_BYTE4 = 0x2f
  38869 
  38870 //------------------------------------------------------------------------------
  38871 
  38872 // Copyright 2012 Google Inc. All Rights Reserved.
  38873 //
  38874 // Use of this source code is governed by a BSD-style license
  38875 // that can be found in the COPYING file in the root of the source
  38876 // tree. An additional intellectual property rights grant can be found
  38877 // in the file PATENTS. All contributing project authors may
  38878 // be found in the AUTHORS file in the root of the source tree.
  38879 // -----------------------------------------------------------------------------
  38880 //
  38881 // Misc. common utility functions
  38882 //
  38883 // Authors: Skal (pascal.massimino@gmail.com)
  38884 //          Urvang (urvang@google.com)
  38885 
  38886 // Copyright 2011 Google Inc. All Rights Reserved.
  38887 //
  38888 // Use of this source code is governed by a BSD-style license
  38889 // that can be found in the COPYING file in the root of the source
  38890 // tree. An additional intellectual property rights grant can be found
  38891 // in the file PATENTS. All contributing project authors may
  38892 // be found in the AUTHORS file in the root of the source tree.
  38893 // -----------------------------------------------------------------------------
  38894 //
  38895 //   WebP encoder: main interface
  38896 //
  38897 // Author: Skal (pascal.massimino@gmail.com)
  38898 
  38899 // #define PRINT_MEMORY_INFO
  38900 
  38901 //------------------------------------------------------------------------------
  38902 
  38903 func WebPGetEncoderVersion(tls *libc.TLS) (r int32) {
  38904 	return libc.Int32FromInt32(ENC_MAJ_VERSION)<<libc.Int32FromInt32(16) | libc.Int32FromInt32(ENC_MIN_VERSION)<<libc.Int32FromInt32(8) | libc.Int32FromInt32(ENC_REV_VERSION)
  38905 }
  38906 
  38907 //------------------------------------------------------------------------------
  38908 // VP8Encoder
  38909 //------------------------------------------------------------------------------
  38910 
  38911 func ResetSegmentHeader1(tls *libc.TLS, enc uintptr) {
  38912 	var hdr uintptr
  38913 	_ = hdr
  38914 	hdr = enc + 32
  38915 	(*VP8EncSegmentHeader)(unsafe.Pointer(hdr)).Fnum_segments = (*WebPConfig)(unsafe.Pointer((*VP8Encoder)(unsafe.Pointer(enc)).Fconfig)).Fsegments
  38916 	(*VP8EncSegmentHeader)(unsafe.Pointer(hdr)).Fupdate_map = libc.BoolInt32((*VP8EncSegmentHeader)(unsafe.Pointer(hdr)).Fnum_segments > int32(1))
  38917 	(*VP8EncSegmentHeader)(unsafe.Pointer(hdr)).Fsize = 0
  38918 }
  38919 
  38920 func ResetFilterHeader(tls *libc.TLS, enc uintptr) {
  38921 	var hdr uintptr
  38922 	_ = hdr
  38923 	hdr = enc + 16
  38924 	(*VP8EncFilterHeader)(unsafe.Pointer(hdr)).Fsimple = int32(1)
  38925 	(*VP8EncFilterHeader)(unsafe.Pointer(hdr)).Flevel = 0
  38926 	(*VP8EncFilterHeader)(unsafe.Pointer(hdr)).Fsharpness = 0
  38927 	(*VP8EncFilterHeader)(unsafe.Pointer(hdr)).Fi4x4_lf_delta = 0
  38928 }
  38929 
  38930 func ResetBoundaryPredictions(tls *libc.TLS, enc uintptr) {
  38931 	var i int32
  38932 	var left, top uintptr
  38933 	_, _, _ = i, left, top
  38934 	top = (*VP8Encoder)(unsafe.Pointer(enc)).Fpreds - uintptr((*VP8Encoder)(unsafe.Pointer(enc)).Fpreds_w)
  38935 	left = (*VP8Encoder)(unsafe.Pointer(enc)).Fpreds - uintptr(1)
  38936 	i = -int32(1)
  38937 	for {
  38938 		if !(i < int32(4)*(*VP8Encoder)(unsafe.Pointer(enc)).Fmb_w) {
  38939 			break
  38940 		}
  38941 		**(**uint8_t)(__ccgo_up(top + uintptr(i))) = uint8(B_DC_PRED)
  38942 		goto _1
  38943 	_1:
  38944 		;
  38945 		i = i + 1
  38946 	}
  38947 	i = 0
  38948 	for {
  38949 		if !(i < int32(4)*(*VP8Encoder)(unsafe.Pointer(enc)).Fmb_h) {
  38950 			break
  38951 		}
  38952 		**(**uint8_t)(__ccgo_up(left + uintptr(i*(*VP8Encoder)(unsafe.Pointer(enc)).Fpreds_w))) = uint8(B_DC_PRED)
  38953 		goto _2
  38954 	_2:
  38955 		;
  38956 		i = i + 1
  38957 	}
  38958 	**(**uint32_t)(__ccgo_up((*VP8Encoder)(unsafe.Pointer(enc)).Fnz + uintptr(-libc.Int32FromInt32(1))*4)) = uint32(0) // constant
  38959 }
  38960 
  38961 // Mapping from config->method to coding tools used.
  38962 //-------------------+---+---+---+---+---+---+---+
  38963 //   Method          | 0 | 1 | 2 | 3 |(4)| 5 | 6 |
  38964 //-------------------+---+---+---+---+---+---+---+
  38965 // fast probe        | x |   |   | x |   |   |   |
  38966 //-------------------+---+---+---+---+---+---+---+
  38967 // dynamic proba     | ~ | x | x | x | x | x | x |
  38968 //-------------------+---+---+---+---+---+---+---+
  38969 // fast mode analysis|[x]|[x]|   |   | x | x | x |
  38970 //-------------------+---+---+---+---+---+---+---+
  38971 // basic rd-opt      |   |   |   | x | x | x | x |
  38972 //-------------------+---+---+---+---+---+---+---+
  38973 // disto-refine i4/16| x | x | x |   |   |   |   |
  38974 //-------------------+---+---+---+---+---+---+---+
  38975 // disto-refine uv   |   | x | x |   |   |   |   |
  38976 //-------------------+---+---+---+---+---+---+---+
  38977 // rd-opt i4/16      |   |   | ~ | x | x | x | x |
  38978 //-------------------+---+---+---+---+---+---+---+
  38979 // token buffer (opt)|   |   |   | x | x | x | x |
  38980 //-------------------+---+---+---+---+---+---+---+
  38981 // Trellis           |   |   |   |   |   | x |Ful|
  38982 //-------------------+---+---+---+---+---+---+---+
  38983 // full-SNS          |   |   |   |   | x | x | x |
  38984 //-------------------+---+---+---+---+---+---+---+
  38985 
  38986 func MapConfigToTools(tls *libc.TLS, enc uintptr) {
  38987 	var config uintptr
  38988 	var limit, method, v1, v2, v3 int32
  38989 	_, _, _, _, _, _ = config, limit, method, v1, v2, v3
  38990 	config = (*VP8Encoder)(unsafe.Pointer(enc)).Fconfig
  38991 	method = (*WebPConfig)(unsafe.Pointer(config)).Fmethod
  38992 	limit = int32(100) - (*WebPConfig)(unsafe.Pointer(config)).Fpartition_limit
  38993 	(*VP8Encoder)(unsafe.Pointer(enc)).Fmethod = method
  38994 	if method >= int32(6) {
  38995 		v1 = int32(RD_OPT_TRELLIS_ALL)
  38996 	} else {
  38997 		if method >= int32(5) {
  38998 			v2 = int32(RD_OPT_TRELLIS)
  38999 		} else {
  39000 			if method >= int32(3) {
  39001 				v3 = int32(RD_OPT_BASIC)
  39002 			} else {
  39003 				v3 = int32(RD_OPT_NONE)
  39004 			}
  39005 			v2 = v3
  39006 		}
  39007 		v1 = v2
  39008 	}
  39009 	(*VP8Encoder)(unsafe.Pointer(enc)).Frd_opt_level = v1
  39010 	(*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.
  39011 	// partition0 = 512k max.
  39012 	(*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))
  39013 	(*VP8Encoder)(unsafe.Pointer(enc)).Fthread_level = (*WebPConfig)(unsafe.Pointer(config)).Fthread_level
  39014 	(*VP8Encoder)(unsafe.Pointer(enc)).Fdo_search = libc.BoolInt32((*WebPConfig)(unsafe.Pointer(config)).Ftarget_size > 0 || (*WebPConfig)(unsafe.Pointer(config)).Ftarget_PSNR > libc.Float32FromInt32(0))
  39015 	if !((*WebPConfig)(unsafe.Pointer(config)).Flow_memory != 0) {
  39016 		(*VP8Encoder)(unsafe.Pointer(enc)).Fuse_tokens = libc.BoolInt32((*VP8Encoder)(unsafe.Pointer(enc)).Frd_opt_level >= int32(RD_OPT_BASIC)) // need rd stats
  39017 		if (*VP8Encoder)(unsafe.Pointer(enc)).Fuse_tokens != 0 {
  39018 			(*VP8Encoder)(unsafe.Pointer(enc)).Fnum_parts = int32(1) // doesn't work with multi-partition
  39019 		}
  39020 	}
  39021 }
  39022 
  39023 // Memory scaling with dimensions:
  39024 //  memory (bytes) ~= 2.25 * w + 0.0625 * w * h
  39025 //
  39026 // Typical memory footprint (614x440 picture)
  39027 //              encoder: 22111
  39028 //                 info: 4368
  39029 //                preds: 17741
  39030 //          top samples: 1263
  39031 //             non-zero: 175
  39032 //             lf-stats: 0
  39033 //                total: 45658
  39034 // Transient object sizes:
  39035 //       VP8EncIterator: 3360
  39036 //         VP8ModeScore: 872
  39037 //       VP8SegmentInfo: 732
  39038 //          VP8EncProba: 18352
  39039 //              LFStats: 2048
  39040 // Picture size (yuv): 419328
  39041 
  39042 func InitVP8Encoder(tls *libc.TLS, config uintptr, picture uintptr) (r uintptr) {
  39043 	var enc, mem, v3 uintptr
  39044 	var info_size, lf_stats_size, nz_size, preds_size, samples_size, top_derr_size size_t
  39045 	var mb_h, mb_w, preds_h, preds_w, top_stride, use_filter, v5, v6 int32
  39046 	var scale float32
  39047 	var size uint64_t
  39048 	var v1, v2 uint64
  39049 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  39050 	use_filter = libc.BoolInt32((*WebPConfig)(unsafe.Pointer(config)).Ffilter_strength > 0 || (*WebPConfig)(unsafe.Pointer(config)).Fautofilter > 0)
  39051 	mb_w = ((*WebPPicture)(unsafe.Pointer(picture)).Fwidth + int32(15)) >> int32(4)
  39052 	mb_h = ((*WebPPicture)(unsafe.Pointer(picture)).Fheight + int32(15)) >> int32(4)
  39053 	preds_w = int32(4)*mb_w + int32(1)
  39054 	preds_h = int32(4)*mb_h + int32(1)
  39055 	preds_size = uint64(preds_w*preds_h) * uint64(1)
  39056 	top_stride = mb_w * int32(16)
  39057 	nz_size = uint64(mb_w+libc.Int32FromInt32(1))*uint64(4) + uint64(WEBP_ALIGN_CST)
  39058 	info_size = uint64(mb_w*mb_h) * uint64(4)
  39059 	samples_size = uint64(int32(2)*top_stride)*uint64(1) + uint64(WEBP_ALIGN_CST)
  39060 	if (*WebPConfig)(unsafe.Pointer(config)).Fautofilter != 0 {
  39061 		v1 = libc.Uint64FromInt64(2048) + libc.Uint64FromInt32(WEBP_ALIGN_CST)
  39062 	} else {
  39063 		v1 = uint64(0)
  39064 	} // align all
  39065 	lf_stats_size = v1
  39066 	if (*WebPConfig)(unsafe.Pointer(config)).Fquality <= libc.Float32FromInt32(ERROR_DIFFUSION_QUALITY) || (*WebPConfig)(unsafe.Pointer(config)).Fpass > int32(1) {
  39067 		v2 = uint64(mb_w) * uint64(4)
  39068 	} else {
  39069 		v2 = uint64(0)
  39070 	}
  39071 	top_derr_size = v2
  39072 	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
  39073 	mem = WebPSafeMalloc(tls, size, uint64(1))
  39074 	if mem == libc.UintptrFromInt32(0) {
  39075 		WebPEncodingSetError(tls, picture, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  39076 		return libc.UintptrFromInt32(0)
  39077 	}
  39078 	enc = mem
  39079 	mem = uintptr((uint64(mem+libc.UintptrFromInt64(23704)) + libc.Uint64FromInt32(WEBP_ALIGN_CST)) & ^libc.Uint64FromInt32(WEBP_ALIGN_CST))
  39080 	libc.Xmemset(tls, enc, 0, uint64(23704))
  39081 	(*VP8Encoder)(unsafe.Pointer(enc)).Fnum_parts = int32(1) << (*WebPConfig)(unsafe.Pointer(config)).Fpartitions
  39082 	(*VP8Encoder)(unsafe.Pointer(enc)).Fmb_w = mb_w
  39083 	(*VP8Encoder)(unsafe.Pointer(enc)).Fmb_h = mb_h
  39084 	(*VP8Encoder)(unsafe.Pointer(enc)).Fpreds_w = preds_w
  39085 	(*VP8Encoder)(unsafe.Pointer(enc)).Fmb_info = mem
  39086 	mem = mem + uintptr(info_size)
  39087 	(*VP8Encoder)(unsafe.Pointer(enc)).Fpreds = mem + uintptr(1) + uintptr((*VP8Encoder)(unsafe.Pointer(enc)).Fpreds_w)
  39088 	mem = mem + uintptr(preds_size)
  39089 	(*VP8Encoder)(unsafe.Pointer(enc)).Fnz = uintptr(1)*4 + uintptr((uint64(mem)+libc.Uint64FromInt32(WEBP_ALIGN_CST)) & ^libc.Uint64FromInt32(WEBP_ALIGN_CST))
  39090 	mem = mem + uintptr(nz_size)
  39091 	if lf_stats_size != 0 {
  39092 		v3 = uintptr((uint64(mem) + libc.Uint64FromInt32(WEBP_ALIGN_CST)) & ^libc.Uint64FromInt32(WEBP_ALIGN_CST))
  39093 	} else {
  39094 		v3 = libc.UintptrFromInt32(0)
  39095 	}
  39096 	(*VP8Encoder)(unsafe.Pointer(enc)).Flf_stats = v3
  39097 	mem = mem + uintptr(lf_stats_size)
  39098 	// top samples (all 16-aligned)
  39099 	mem = uintptr((uint64(mem) + libc.Uint64FromInt32(WEBP_ALIGN_CST)) & ^libc.Uint64FromInt32(WEBP_ALIGN_CST))
  39100 	(*VP8Encoder)(unsafe.Pointer(enc)).Fy_top = mem
  39101 	(*VP8Encoder)(unsafe.Pointer(enc)).Fuv_top = (*VP8Encoder)(unsafe.Pointer(enc)).Fy_top + uintptr(top_stride)
  39102 	mem = mem + uintptr(int32(2)*top_stride)
  39103 	if top_derr_size != 0 {
  39104 		v3 = mem
  39105 	} else {
  39106 		v3 = libc.UintptrFromInt32(0)
  39107 	}
  39108 	(*VP8Encoder)(unsafe.Pointer(enc)).Ftop_derr = v3
  39109 	mem = mem + uintptr(top_derr_size)
  39110 	(*VP8Encoder)(unsafe.Pointer(enc)).Fconfig = config
  39111 	if use_filter != 0 {
  39112 		if (*WebPConfig)(unsafe.Pointer(config)).Ffilter_type == int32(1) {
  39113 			v6 = 0
  39114 		} else {
  39115 			v6 = int32(1)
  39116 		}
  39117 		v5 = v6
  39118 	} else {
  39119 		v5 = int32(2)
  39120 	}
  39121 	(*VP8Encoder)(unsafe.Pointer(enc)).Fprofile = v5
  39122 	(*VP8Encoder)(unsafe.Pointer(enc)).Fpic = picture
  39123 	(*VP8Encoder)(unsafe.Pointer(enc)).Fpercent = 0
  39124 	MapConfigToTools(tls, enc)
  39125 	VP8EncDspInit(tls)
  39126 	VP8DefaultProbas(tls, enc)
  39127 	ResetSegmentHeader1(tls, enc)
  39128 	ResetFilterHeader(tls, enc)
  39129 	ResetBoundaryPredictions(tls, enc)
  39130 	VP8EncDspCostInit(tls)
  39131 	VP8EncInitAlpha(tls, enc)
  39132 	// lower quality means smaller output -> we modulate a little the page
  39133 	// size based on quality. This is just a crude 1rst-order prediction.
  39134 	scale = libc.Float32FromFloat32(1) + float32((*WebPConfig)(unsafe.Pointer(config)).Fquality*libc.Float32FromFloat32(5))/libc.Float32FromFloat32(100) // in [1,6]
  39135 	VP8TBufferInit(tls, enc+496, int32(float32(float32(mb_w*mb_h*libc.Int32FromInt32(4))*scale)))
  39136 	return enc
  39137 }
  39138 
  39139 func DeleteVP8Encoder(tls *libc.TLS, enc uintptr) (r int32) {
  39140 	var ok int32
  39141 	_ = ok
  39142 	ok = int32(1)
  39143 	if enc != libc.UintptrFromInt32(0) {
  39144 		ok = VP8EncDeleteAlpha(tls, enc)
  39145 		VP8TBufferClear(tls, enc+496)
  39146 		WebPSafeFree(tls, enc)
  39147 	}
  39148 	return ok
  39149 }
  39150 
  39151 //------------------------------------------------------------------------------
  39152 
  39153 func GetPSNR2(tls *libc.TLS, err uint64_t, size uint64_t) (r float64) {
  39154 	var v1 float64
  39155 	_ = v1
  39156 	if err > uint64(0) && size > uint64(0) {
  39157 		v1 = float64(float64(10) * libc.Xlog10(tls, float64(float64(libc.Float64FromFloat64(255)*libc.Float64FromFloat64(255))*float64(size))/float64(err)))
  39158 	} else {
  39159 		v1 = float64(99)
  39160 	}
  39161 	return v1
  39162 }
  39163 
  39164 func FinalizePSNR(tls *libc.TLS, enc uintptr) {
  39165 	var size uint64_t
  39166 	var sse, stats uintptr
  39167 	_, _, _ = size, sse, stats
  39168 	stats = (*WebPPicture)(unsafe.Pointer((*VP8Encoder)(unsafe.Pointer(enc)).Fpic)).Fstats
  39169 	size = (*VP8Encoder)(unsafe.Pointer(enc)).Fsse_count
  39170 	sse = enc + 23512
  39171 	**(**float32)(__ccgo_up(stats + 4)) = float32(GetPSNR2(tls, **(**uint64_t)(__ccgo_up(sse)), size))
  39172 	**(**float32)(__ccgo_up(stats + 4 + 1*4)) = float32(GetPSNR2(tls, **(**uint64_t)(__ccgo_up(sse + 1*8)), size/uint64(4)))
  39173 	**(**float32)(__ccgo_up(stats + 4 + 2*4)) = float32(GetPSNR2(tls, **(**uint64_t)(__ccgo_up(sse + 2*8)), size/uint64(4)))
  39174 	**(**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)))
  39175 	**(**float32)(__ccgo_up(stats + 4 + 4*4)) = float32(GetPSNR2(tls, **(**uint64_t)(__ccgo_up(sse + 3*8)), size))
  39176 }
  39177 
  39178 func StoreStats(tls *libc.TLS, enc uintptr) {
  39179 	var i, s int32
  39180 	var stats uintptr
  39181 	_, _, _ = i, s, stats
  39182 	stats = (*WebPPicture)(unsafe.Pointer((*VP8Encoder)(unsafe.Pointer(enc)).Fpic)).Fstats
  39183 	if stats != libc.UintptrFromInt32(0) {
  39184 		i = 0
  39185 		for {
  39186 			if !(i < int32(NUM_MB_SEGMENTS)) {
  39187 				break
  39188 			}
  39189 			**(**int32)(__ccgo_up(stats + 124 + uintptr(i)*4)) = (**(**VP8SegmentInfo)(__ccgo_up(enc + 608 + uintptr(i)*744))).Ffstrength
  39190 			**(**int32)(__ccgo_up(stats + 108 + uintptr(i)*4)) = (**(**VP8SegmentInfo)(__ccgo_up(enc + 608 + uintptr(i)*744))).Fquant
  39191 			s = 0
  39192 			for {
  39193 				if !(s <= int32(2)) {
  39194 					break
  39195 				}
  39196 				**(**int32)(__ccgo_up(stats + 44 + uintptr(s)*16 + uintptr(i)*4)) = **(**int32)(__ccgo_up(enc + 23556 + uintptr(s)*16 + uintptr(i)*4))
  39197 				goto _2
  39198 			_2:
  39199 				;
  39200 				s = s + 1
  39201 			}
  39202 			goto _1
  39203 		_1:
  39204 			;
  39205 			i = i + 1
  39206 		}
  39207 		FinalizePSNR(tls, enc)
  39208 		(*WebPAuxStats)(unsafe.Pointer(stats)).Fcoded_size = (*VP8Encoder)(unsafe.Pointer(enc)).Fcoded_size
  39209 		i = 0
  39210 		for {
  39211 			if !(i < int32(3)) {
  39212 				break
  39213 			}
  39214 			**(**int32)(__ccgo_up(stats + 24 + uintptr(i)*4)) = **(**int32)(__ccgo_up(enc + 23604 + uintptr(i)*4))
  39215 			goto _3
  39216 		_3:
  39217 			;
  39218 			i = i + 1
  39219 		}
  39220 	}
  39221 }
  39222 
  39223 func WebPEncodingSetError(tls *libc.TLS, pic uintptr, error1 WebPEncodingError1) (r int32) {
  39224 	// The oldest error reported takes precedence over the new one.
  39225 	if (*WebPPicture)(unsafe.Pointer(pic)).Ferror_code == int32(VP8_ENC_OK) {
  39226 		(*WebPPicture)(unsafe.Pointer(pic)).Ferror_code = error1
  39227 	}
  39228 	return 0
  39229 }
  39230 
  39231 func WebPReportProgress(tls *libc.TLS, pic uintptr, percent int32, percent_store uintptr) (r int32) {
  39232 	if percent_store != libc.UintptrFromInt32(0) && percent != **(**int32)(__ccgo_up(percent_store)) {
  39233 		**(**int32)(__ccgo_up(percent_store)) = percent
  39234 		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) {
  39235 			// user abort requested
  39236 			return WebPEncodingSetError(tls, pic, int32(VP8_ENC_ERROR_USER_ABORT))
  39237 		}
  39238 	}
  39239 	return int32(1) // ok
  39240 }
  39241 
  39242 //------------------------------------------------------------------------------
  39243 
  39244 func WebPEncode(tls *libc.TLS, config uintptr, pic uintptr) (r int32) {
  39245 	var dithering, x, x2 float32
  39246 	var enc uintptr
  39247 	var ok int32
  39248 	_, _, _, _, _ = dithering, enc, ok, x, x2
  39249 	ok = 0
  39250 	if pic == libc.UintptrFromInt32(0) {
  39251 		return 0
  39252 	}
  39253 	(*WebPPicture)(unsafe.Pointer(pic)).Ferror_code = int32(VP8_ENC_OK) // all ok so far
  39254 	if config == libc.UintptrFromInt32(0) {                             // bad params
  39255 		return WebPEncodingSetError(tls, pic, int32(VP8_ENC_ERROR_NULL_PARAMETER))
  39256 	}
  39257 	if !(WebPValidateConfig(tls, config) != 0) {
  39258 		return WebPEncodingSetError(tls, pic, int32(VP8_ENC_ERROR_INVALID_CONFIGURATION))
  39259 	}
  39260 	if !(WebPValidatePicture(tls, pic) != 0) {
  39261 		return 0
  39262 	}
  39263 	if (*WebPPicture)(unsafe.Pointer(pic)).Fwidth > int32(WEBP_MAX_DIMENSION) || (*WebPPicture)(unsafe.Pointer(pic)).Fheight > int32(WEBP_MAX_DIMENSION) {
  39264 		return WebPEncodingSetError(tls, pic, int32(VP8_ENC_ERROR_BAD_DIMENSION))
  39265 	}
  39266 	if (*WebPPicture)(unsafe.Pointer(pic)).Fstats != libc.UintptrFromInt32(0) {
  39267 		libc.Xmemset(tls, (*WebPPicture)(unsafe.Pointer(pic)).Fstats, 0, uint64(188))
  39268 	}
  39269 	if !((*WebPConfig)(unsafe.Pointer(config)).Flossless != 0) {
  39270 		enc = libc.UintptrFromInt32(0)
  39271 		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) {
  39272 			// Make sure we have YUVA samples.
  39273 			if (*WebPConfig)(unsafe.Pointer(config)).Fuse_sharp_yuv != 0 || (*WebPConfig)(unsafe.Pointer(config)).Fpreprocessing&int32(4) != 0 {
  39274 				if !(WebPPictureSharpARGBToYUVA(tls, pic) != 0) {
  39275 					return 0
  39276 				}
  39277 			} else {
  39278 				dithering = libc.Float32FromFloat32(0)
  39279 				if (*WebPConfig)(unsafe.Pointer(config)).Fpreprocessing&int32(2) != 0 {
  39280 					x = (*WebPConfig)(unsafe.Pointer(config)).Fquality / libc.Float32FromFloat32(100)
  39281 					x2 = float32(x * x)
  39282 					// slowly decreasing from max dithering at low quality (q->0)
  39283 					// to 0.5 dithering amplitude at high quality (q->100)
  39284 					dithering = libc.Float32FromFloat32(1) + float32(float32((libc.Float32FromFloat32(0.5)-libc.Float32FromFloat32(1))*x2)*x2)
  39285 				}
  39286 				if !(WebPPictureARGBToYUVADithered(tls, pic, int32(WEBP_YUV420), dithering) != 0) {
  39287 					return 0
  39288 				}
  39289 			}
  39290 		}
  39291 		if !((*WebPConfig)(unsafe.Pointer(config)).Fexact != 0) {
  39292 			WebPCleanupTransparentArea(tls, pic)
  39293 		}
  39294 		enc = InitVP8Encoder(tls, config, pic)
  39295 		if enc == libc.UintptrFromInt32(0) {
  39296 			return 0
  39297 		} // pic->error is already set.
  39298 		// Note: each of the tasks below account for 20% in the progress report.
  39299 		ok = VP8EncAnalyze(tls, enc)
  39300 		// Analysis is done, proceed to actual coding.
  39301 		ok = libc.BoolInt32(ok != 0 && VP8EncStartAlpha(tls, enc) != 0) // possibly done in parallel
  39302 		if !((*VP8Encoder)(unsafe.Pointer(enc)).Fuse_tokens != 0) {
  39303 			ok = libc.BoolInt32(ok != 0 && VP8EncLoop(tls, enc) != 0)
  39304 		} else {
  39305 			ok = libc.BoolInt32(ok != 0 && VP8EncTokenLoop(tls, enc) != 0)
  39306 		}
  39307 		ok = libc.BoolInt32(ok != 0 && VP8EncFinishAlpha(tls, enc) != 0)
  39308 		ok = libc.BoolInt32(ok != 0 && VP8EncWrite(tls, enc) != 0)
  39309 		StoreStats(tls, enc)
  39310 		if !(ok != 0) {
  39311 			VP8EncFreeBitWriters(tls, enc)
  39312 		}
  39313 		ok = ok & DeleteVP8Encoder(tls, enc) // must always be called, even if !ok
  39314 	} else {
  39315 		// Make sure we have ARGB samples.
  39316 		if (*WebPPicture)(unsafe.Pointer(pic)).Fargb == libc.UintptrFromInt32(0) && !(WebPPictureYUVAToARGB(tls, pic) != 0) {
  39317 			return 0
  39318 		}
  39319 		if !((*WebPConfig)(unsafe.Pointer(config)).Fexact != 0) {
  39320 			WebPReplaceTransparentPixels(tls, pic, uint32(0x000000))
  39321 		}
  39322 		ok = VP8LEncodeImage(tls, config, pic) // Sets pic->error in case of problem.
  39323 	}
  39324 	return ok
  39325 }
  39326 
  39327 const SIZE_MAX17 = "UINT64_MAX"
  39328 const VP8L_LOG8_WBITS = 4
  39329 
  39330 // Copyright 2010 Google Inc. All Rights Reserved.
  39331 //
  39332 // Use of this source code is governed by a BSD-style license
  39333 // that can be found in the COPYING file in the root of the source
  39334 // tree. An additional intellectual property rights grant can be found
  39335 // in the file PATENTS. All contributing project authors may
  39336 // be found in the AUTHORS file in the root of the source tree.
  39337 // -----------------------------------------------------------------------------
  39338 //
  39339 // Boolean decoder
  39340 //
  39341 // Author: Skal (pascal.massimino@gmail.com)
  39342 //         Vikas Arora (vikaas.arora@gmail.com)
  39343 
  39344 // Copyright 2014 Google Inc. All Rights Reserved.
  39345 //
  39346 // Use of this source code is governed by a BSD-style license
  39347 // that can be found in the COPYING file in the root of the source
  39348 // tree. An additional intellectual property rights grant can be found
  39349 // in the file PATENTS. All contributing project authors may
  39350 // be found in the AUTHORS file in the root of the source tree.
  39351 // -----------------------------------------------------------------------------
  39352 //
  39353 // Endian related functions.
  39354 
  39355 // Copyright 2012 Google Inc. All Rights Reserved.
  39356 //
  39357 // Use of this source code is governed by a BSD-style license
  39358 // that can be found in the COPYING file in the root of the source
  39359 // tree. An additional intellectual property rights grant can be found
  39360 // in the file PATENTS. All contributing project authors may
  39361 // be found in the AUTHORS file in the root of the source tree.
  39362 // -----------------------------------------------------------------------------
  39363 //
  39364 // Misc. common utility functions
  39365 //
  39366 // Authors: Skal (pascal.massimino@gmail.com)
  39367 //          Urvang (urvang@google.com)
  39368 
  39369 //------------------------------------------------------------------------------
  39370 // VP8BitReader
  39371 
  39372 func VP8BitReaderSetBuffer(tls *libc.TLS, br uintptr, start uintptr, size size_t) {
  39373 	var v1 uintptr
  39374 	_ = v1
  39375 	(*VP8BitReader)(unsafe.Pointer(br)).Fbuf = start
  39376 	(*VP8BitReader)(unsafe.Pointer(br)).Fbuf_end = start + uintptr(size)
  39377 	if size >= uint64(8) {
  39378 		v1 = start + uintptr(size) - uintptr(8) + uintptr(1)
  39379 	} else {
  39380 		v1 = start
  39381 	}
  39382 	(*VP8BitReader)(unsafe.Pointer(br)).Fbuf_max = v1
  39383 }
  39384 
  39385 func VP8InitBitReader(tls *libc.TLS, br1 uintptr, start uintptr, size size_t) {
  39386 	bp := tls.Alloc(16)
  39387 	defer tls.Free(16)
  39388 	var bits bit_t
  39389 	var v1 uintptr
  39390 	var v2 uint64_t
  39391 	var _ /* in_bits at bp+0 */ lbit_t
  39392 	_, _, _ = bits, v1, v2
  39393 	// limit ensured by format and upstream checks
  39394 	(*VP8BitReader)(unsafe.Pointer(br1)).Frange1 = uint32(libc.Int32FromInt32(255) - libc.Int32FromInt32(1))
  39395 	(*VP8BitReader)(unsafe.Pointer(br1)).Fvalue = uint64(0)
  39396 	(*VP8BitReader)(unsafe.Pointer(br1)).Fbits = -int32(8) // to load the very first 8bits
  39397 	(*VP8BitReader)(unsafe.Pointer(br1)).Feof = 0
  39398 	VP8BitReaderSetBuffer(tls, br1, start, size)
  39399 	v1 = br1
  39400 	if (*VP8BitReader)(unsafe.Pointer(v1)).Fbuf < (*VP8BitReader)(unsafe.Pointer(v1)).Fbuf_max {
  39401 		libc.Xmemcpy(tls, bp, (*VP8BitReader)(unsafe.Pointer(v1)).Fbuf, uint64(8))
  39402 		**(**uintptr)(__ccgo_up(v1 + 16)) += uintptr(libc.Int32FromInt32(BITS) >> libc.Int32FromInt32(3))
  39403 		v2 = libc.X__builtin_bswap64(tls, **(**lbit_t)(__ccgo_up(bp)))
  39404 		goto _3
  39405 	_3:
  39406 		bits = v2
  39407 		bits = bits >> uint64(libc.Int32FromInt32(64)-libc.Int32FromInt32(BITS))
  39408 		(*VP8BitReader)(unsafe.Pointer(v1)).Fvalue = bits | (*VP8BitReader)(unsafe.Pointer(v1)).Fvalue<<libc.Int32FromInt32(BITS)
  39409 		**(**int32)(__ccgo_up(v1 + 12)) += int32(BITS)
  39410 	} else {
  39411 		VP8LoadFinalBytes(tls, v1)
  39412 	}
  39413 }
  39414 
  39415 func VP8RemapBitReader(tls *libc.TLS, br uintptr, offset ptrdiff_t) {
  39416 	if (*VP8BitReader)(unsafe.Pointer(br)).Fbuf != libc.UintptrFromInt32(0) {
  39417 		**(**uintptr)(__ccgo_up(br + 16)) += uintptr(offset)
  39418 		**(**uintptr)(__ccgo_up(br + 24)) += uintptr(offset)
  39419 		**(**uintptr)(__ccgo_up(br + 32)) += uintptr(offset)
  39420 	}
  39421 }
  39422 
  39423 func VP8LoadFinalBytes(tls *libc.TLS, br uintptr) {
  39424 	var v1, v2 uintptr
  39425 	_, _ = v1, v2
  39426 	// Only read 8bits at a time
  39427 	if (*VP8BitReader)(unsafe.Pointer(br)).Fbuf < (*VP8BitReader)(unsafe.Pointer(br)).Fbuf_end {
  39428 		**(**int32)(__ccgo_up(br + 12)) += int32(8)
  39429 		v2 = br + 16
  39430 		v1 = *(*uintptr)(unsafe.Pointer(v2))
  39431 		*(*uintptr)(unsafe.Pointer(v2)) = *(*uintptr)(unsafe.Pointer(v2)) + 1
  39432 		(*VP8BitReader)(unsafe.Pointer(br)).Fvalue = uint64(**(**uint8_t)(__ccgo_up(v1))) | (*VP8BitReader)(unsafe.Pointer(br)).Fvalue<<libc.Int32FromInt32(8)
  39433 	} else {
  39434 		if !((*VP8BitReader)(unsafe.Pointer(br)).Feof != 0) {
  39435 			**(**bit_t)(__ccgo_up(br)) <<= uint64(8)
  39436 			**(**int32)(__ccgo_up(br + 12)) += int32(8)
  39437 			(*VP8BitReader)(unsafe.Pointer(br)).Feof = int32(1)
  39438 		} else {
  39439 			(*VP8BitReader)(unsafe.Pointer(br)).Fbits = 0 // This is to avoid undefined behaviour with shifts.
  39440 		}
  39441 	}
  39442 }
  39443 
  39444 //------------------------------------------------------------------------------
  39445 // Higher-level calls
  39446 
  39447 func VP8GetValue(tls *libc.TLS, br2 uintptr, bits1 int32) (r uint32_t) {
  39448 	bp := tls.Alloc(16)
  39449 	defer tls.Free(16)
  39450 	var bit, pos, shift, v1, v6, v8 int32
  39451 	var bits bit_t
  39452 	var range1, split, value range_t
  39453 	var v uint32_t
  39454 	var v2, v3 uintptr
  39455 	var v4 uint64_t
  39456 	var _ /* in_bits at bp+0 */ lbit_t
  39457 	_, _, _, _, _, _, _, _, _, _, _, _, _, _ = bit, bits, pos, range1, shift, split, v, value, v1, v2, v3, v4, v6, v8
  39458 	v = uint32(0)
  39459 	for {
  39460 		v1 = bits1
  39461 		bits1 = bits1 - 1
  39462 		if !(v1 > 0) {
  39463 			break
  39464 		}
  39465 		v2 = br2
  39466 		range1 = (*VP8BitReader)(unsafe.Pointer(v2)).Frange1
  39467 		if (*VP8BitReader)(unsafe.Pointer(v2)).Fbits < libc.Int32FromInt32(0) {
  39468 			v3 = v2
  39469 			if (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf < (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf_max {
  39470 				libc.Xmemcpy(tls, bp, (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf, uint64(8))
  39471 				**(**uintptr)(__ccgo_up(v3 + 16)) += uintptr(libc.Int32FromInt32(BITS) >> libc.Int32FromInt32(3))
  39472 				v4 = libc.X__builtin_bswap64(tls, **(**lbit_t)(__ccgo_up(bp)))
  39473 				goto _5
  39474 			_5:
  39475 				bits = v4
  39476 				bits = bits >> uint64(libc.Int32FromInt32(64)-libc.Int32FromInt32(BITS))
  39477 				(*VP8BitReader)(unsafe.Pointer(v3)).Fvalue = bits | (*VP8BitReader)(unsafe.Pointer(v3)).Fvalue<<libc.Int32FromInt32(BITS)
  39478 				**(**int32)(__ccgo_up(v3 + 12)) += int32(BITS)
  39479 			} else {
  39480 				VP8LoadFinalBytes(tls, v3)
  39481 			}
  39482 		}
  39483 		pos = (*VP8BitReader)(unsafe.Pointer(v2)).Fbits
  39484 		split = range1 * uint32(int32(0x80)) >> int32(8)
  39485 		value = uint32((*VP8BitReader)(unsafe.Pointer(v2)).Fvalue >> pos)
  39486 		bit = libc.BoolInt32(value > split)
  39487 		if bit != 0 {
  39488 			range1 = range1 - split
  39489 			**(**bit_t)(__ccgo_up(v2)) -= uint64(split+libc.Uint32FromInt32(1)) << pos
  39490 		} else {
  39491 			range1 = split + uint32(1)
  39492 		}
  39493 		v6 = int32(31) ^ libc.X__builtin_clz(tls, range1)
  39494 		goto _7
  39495 	_7:
  39496 		shift = int32(7) ^ v6
  39497 		range1 = range1 << uint32(shift)
  39498 		**(**int32)(__ccgo_up(v2 + 12)) -= shift
  39499 		(*VP8BitReader)(unsafe.Pointer(v2)).Frange1 = range1 - uint32(1)
  39500 		v8 = bit
  39501 		goto _9
  39502 	_9:
  39503 		v = v | uint32(v8<<bits1)
  39504 	}
  39505 	return v
  39506 }
  39507 
  39508 func VP8GetSignedValue(tls *libc.TLS, br uintptr, bits int32) (r int32_t) {
  39509 	var value, v1 int32
  39510 	_, _ = value, v1
  39511 	value = int32(VP8GetValue(tls, br, bits))
  39512 	if VP8GetValue(tls, br, int32(1)) != 0 {
  39513 		v1 = -value
  39514 	} else {
  39515 		v1 = value
  39516 	}
  39517 	return v1
  39518 }
  39519 
  39520 //------------------------------------------------------------------------------
  39521 // VP8LBitReader
  39522 
  39523 var kBitMask = [25]uint32_t{
  39524 	1:  uint32(0x000001),
  39525 	2:  uint32(0x000003),
  39526 	3:  uint32(0x000007),
  39527 	4:  uint32(0x00000f),
  39528 	5:  uint32(0x00001f),
  39529 	6:  uint32(0x00003f),
  39530 	7:  uint32(0x00007f),
  39531 	8:  uint32(0x0000ff),
  39532 	9:  uint32(0x0001ff),
  39533 	10: uint32(0x0003ff),
  39534 	11: uint32(0x0007ff),
  39535 	12: uint32(0x000fff),
  39536 	13: uint32(0x001fff),
  39537 	14: uint32(0x003fff),
  39538 	15: uint32(0x007fff),
  39539 	16: uint32(0x00ffff),
  39540 	17: uint32(0x01ffff),
  39541 	18: uint32(0x03ffff),
  39542 	19: uint32(0x07ffff),
  39543 	20: uint32(0x0fffff),
  39544 	21: uint32(0x1fffff),
  39545 	22: uint32(0x3fffff),
  39546 	23: uint32(0x7fffff),
  39547 	24: uint32(0xffffff),
  39548 }
  39549 
  39550 func VP8LInitBitReader(tls *libc.TLS, br uintptr, start uintptr, length size_t) {
  39551 	var i size_t
  39552 	var value vp8l_val_t
  39553 	_, _ = i, value
  39554 	value = uint64(0)
  39555 	// can't happen with a RIFF chunk.
  39556 	(*VP8LBitReader)(unsafe.Pointer(br)).Flen1 = length
  39557 	(*VP8LBitReader)(unsafe.Pointer(br)).Fval = uint64(0)
  39558 	(*VP8LBitReader)(unsafe.Pointer(br)).Fbit_pos = 0
  39559 	(*VP8LBitReader)(unsafe.Pointer(br)).Feos = 0
  39560 	if length > uint64(8) {
  39561 		length = uint64(8)
  39562 	}
  39563 	i = uint64(0)
  39564 	for {
  39565 		if !(i < length) {
  39566 			break
  39567 		}
  39568 		value = value | uint64(**(**uint8_t)(__ccgo_up(start + uintptr(i))))<<(uint64(8)*i)
  39569 		goto _1
  39570 	_1:
  39571 		;
  39572 		i = i + 1
  39573 	}
  39574 	(*VP8LBitReader)(unsafe.Pointer(br)).Fval = value
  39575 	(*VP8LBitReader)(unsafe.Pointer(br)).Fpos = length
  39576 	(*VP8LBitReader)(unsafe.Pointer(br)).Fbuf = start
  39577 }
  39578 
  39579 func VP8LBitReaderSetBuffer(tls *libc.TLS, br1 uintptr, buf uintptr, len1 size_t) {
  39580 	var v1 uintptr
  39581 	var v2 int32
  39582 	var v4 bool
  39583 	_, _, _ = v1, v2, v4
  39584 	// can't happen with a RIFF chunk.
  39585 	(*VP8LBitReader)(unsafe.Pointer(br1)).Fbuf = buf
  39586 	(*VP8LBitReader)(unsafe.Pointer(br1)).Flen1 = len1
  39587 	// 'pos' > 'len' should be considered a param error.
  39588 	if v4 = (*VP8LBitReader)(unsafe.Pointer(br1)).Fpos > (*VP8LBitReader)(unsafe.Pointer(br1)).Flen1; !v4 {
  39589 		v1 = br1
  39590 		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))
  39591 		goto _3
  39592 	_3:
  39593 	}
  39594 	(*VP8LBitReader)(unsafe.Pointer(br1)).Feos = libc.BoolInt32(v4 || v2 != 0)
  39595 }
  39596 
  39597 func VP8LSetEndOfStream(tls *libc.TLS, br uintptr) {
  39598 	(*VP8LBitReader)(unsafe.Pointer(br)).Feos = int32(1)
  39599 	(*VP8LBitReader)(unsafe.Pointer(br)).Fbit_pos = 0 // To avoid undefined behaviour with shifts.
  39600 }
  39601 
  39602 // C documentation
  39603 //
  39604 //	// If not at EOS, reload up to VP8L_LBITS byte-by-byte
  39605 func ShiftBytes(tls *libc.TLS, br1 uintptr) {
  39606 	var v1 uintptr
  39607 	var v2 int32
  39608 	_, _ = v1, v2
  39609 	for (*VP8LBitReader)(unsafe.Pointer(br1)).Fbit_pos >= int32(8) && (*VP8LBitReader)(unsafe.Pointer(br1)).Fpos < (*VP8LBitReader)(unsafe.Pointer(br1)).Flen1 {
  39610 		**(**vp8l_val_t)(__ccgo_up(br1)) >>= uint64(8)
  39611 		**(**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))
  39612 		(*VP8LBitReader)(unsafe.Pointer(br1)).Fpos = (*VP8LBitReader)(unsafe.Pointer(br1)).Fpos + 1
  39613 		**(**int32)(__ccgo_up(br1 + 32)) -= int32(8)
  39614 	}
  39615 	v1 = br1
  39616 	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))
  39617 	goto _3
  39618 _3:
  39619 	if v2 != 0 {
  39620 		VP8LSetEndOfStream(tls, br1)
  39621 	}
  39622 }
  39623 
  39624 func VP8LDoFillBitWindow(tls *libc.TLS, br uintptr) {
  39625 	bp := tls.Alloc(16)
  39626 	defer tls.Free(16)
  39627 	var v1 uint32_t
  39628 	var _ /* A at bp+0 */ uint32_t
  39629 	_ = v1
  39630 	if (*VP8LBitReader)(unsafe.Pointer(br)).Fpos+uint64(8) < (*VP8LBitReader)(unsafe.Pointer(br)).Flen1 {
  39631 		**(**vp8l_val_t)(__ccgo_up(br)) >>= uint64(VP8L_WBITS)
  39632 		**(**int32)(__ccgo_up(br + 32)) -= int32(VP8L_WBITS)
  39633 		libc.Xmemcpy(tls, bp, (*VP8LBitReader)(unsafe.Pointer(br)).Fbuf+uintptr((*VP8LBitReader)(unsafe.Pointer(br)).Fpos), uint64(4))
  39634 		v1 = **(**uint32_t)(__ccgo_up(bp))
  39635 		goto _2
  39636 	_2:
  39637 		**(**vp8l_val_t)(__ccgo_up(br)) |= uint64(v1) << (libc.Int32FromInt32(VP8L_LBITS) - libc.Int32FromInt32(VP8L_WBITS))
  39638 		**(**size_t)(__ccgo_up(br + 24)) += uint64(VP8L_LOG8_WBITS)
  39639 		return
  39640 	}
  39641 	ShiftBytes(tls, br) // Slow path.
  39642 }
  39643 
  39644 func VP8LReadBits(tls *libc.TLS, br1 uintptr, n_bits int32) (r uint32_t) {
  39645 	var new_bits int32
  39646 	var val, v2 uint32_t
  39647 	var v1 uintptr
  39648 	_, _, _, _ = new_bits, val, v1, v2
  39649 	// Flag an error if end_of_stream or n_bits is more than allowed limit.
  39650 	if !((*VP8LBitReader)(unsafe.Pointer(br1)).Feos != 0) && n_bits <= int32(VP8L_MAX_NUM_BIT_READ) {
  39651 		v1 = br1
  39652 		v2 = uint32((*VP8LBitReader)(unsafe.Pointer(v1)).Fval >> ((*VP8LBitReader)(unsafe.Pointer(v1)).Fbit_pos & (libc.Int32FromInt32(VP8L_LBITS) - libc.Int32FromInt32(1))))
  39653 		goto _3
  39654 	_3:
  39655 		val = v2 & kBitMask[n_bits]
  39656 		new_bits = (*VP8LBitReader)(unsafe.Pointer(br1)).Fbit_pos + n_bits
  39657 		(*VP8LBitReader)(unsafe.Pointer(br1)).Fbit_pos = new_bits
  39658 		ShiftBytes(tls, br1)
  39659 		return val
  39660 	} else {
  39661 		VP8LSetEndOfStream(tls, br1)
  39662 		return uint32(0)
  39663 	}
  39664 	return r
  39665 }
  39666 
  39667 const MIN_EXTRA_SIZE = 32768
  39668 const SIZE_MAX18 = "_UI64_MAX"
  39669 
  39670 //------------------------------------------------------------------------------
  39671 
  39672 //------------------------------------------------------------------------------
  39673 // VP8BitWriter
  39674 
  39675 func BitWriterResize(tls *libc.TLS, bw uintptr, extra_size size_t) (r int32) {
  39676 	var needed_size, new_size size_t
  39677 	var needed_size_64b uint64_t
  39678 	var new_buf uintptr
  39679 	_, _, _, _ = needed_size, needed_size_64b, new_buf, new_size
  39680 	needed_size_64b = (*VP8BitWriter)(unsafe.Pointer(bw)).Fpos + extra_size
  39681 	needed_size = needed_size_64b
  39682 	if needed_size_64b != needed_size {
  39683 		(*VP8BitWriter)(unsafe.Pointer(bw)).Ferror1 = int32(1)
  39684 		return 0
  39685 	}
  39686 	if needed_size <= (*VP8BitWriter)(unsafe.Pointer(bw)).Fmax_pos {
  39687 		return int32(1)
  39688 	}
  39689 	// If the following line wraps over 32bit, the test just after will catch it.
  39690 	new_size = uint64(2) * (*VP8BitWriter)(unsafe.Pointer(bw)).Fmax_pos
  39691 	if new_size < needed_size {
  39692 		new_size = needed_size
  39693 	}
  39694 	if new_size < uint64(1024) {
  39695 		new_size = uint64(1024)
  39696 	}
  39697 	new_buf = WebPSafeMalloc(tls, uint64(1), new_size)
  39698 	if new_buf == libc.UintptrFromInt32(0) {
  39699 		(*VP8BitWriter)(unsafe.Pointer(bw)).Ferror1 = int32(1)
  39700 		return 0
  39701 	}
  39702 	if (*VP8BitWriter)(unsafe.Pointer(bw)).Fpos > uint64(0) {
  39703 		libc.Xmemcpy(tls, new_buf, (*VP8BitWriter)(unsafe.Pointer(bw)).Fbuf, (*VP8BitWriter)(unsafe.Pointer(bw)).Fpos)
  39704 	}
  39705 	WebPSafeFree(tls, (*VP8BitWriter)(unsafe.Pointer(bw)).Fbuf)
  39706 	(*VP8BitWriter)(unsafe.Pointer(bw)).Fbuf = new_buf
  39707 	(*VP8BitWriter)(unsafe.Pointer(bw)).Fmax_pos = new_size
  39708 	return int32(1)
  39709 }
  39710 
  39711 func Flush(tls *libc.TLS, bw uintptr) {
  39712 	var bits int32_t
  39713 	var pos, v3 size_t
  39714 	var s, value, v1 int32
  39715 	_, _, _, _, _, _ = bits, pos, s, value, v1, v3
  39716 	s = int32(8) + (*VP8BitWriter)(unsafe.Pointer(bw)).Fnb_bits
  39717 	bits = (*VP8BitWriter)(unsafe.Pointer(bw)).Fvalue >> s
  39718 	**(**int32_t)(__ccgo_up(bw + 4)) -= bits << s
  39719 	**(**int32)(__ccgo_up(bw + 12)) -= int32(8)
  39720 	if bits&int32(0xff) != int32(0xff) {
  39721 		pos = (*VP8BitWriter)(unsafe.Pointer(bw)).Fpos
  39722 		if !(BitWriterResize(tls, bw, uint64((*VP8BitWriter)(unsafe.Pointer(bw)).Frun+int32(1))) != 0) {
  39723 			return
  39724 		}
  39725 		if bits&int32(0x100) != 0 { // overflow -> propagate carry over pending 0xff's
  39726 			if pos > uint64(0) {
  39727 				**(**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
  39728 			}
  39729 		}
  39730 		if (*VP8BitWriter)(unsafe.Pointer(bw)).Frun > 0 {
  39731 			if bits&int32(0x100) != 0 {
  39732 				v1 = 0x00
  39733 			} else {
  39734 				v1 = int32(0xff)
  39735 			}
  39736 			value = v1
  39737 			for {
  39738 				if !((*VP8BitWriter)(unsafe.Pointer(bw)).Frun > 0) {
  39739 					break
  39740 				}
  39741 				v3 = pos
  39742 				pos = pos + 1
  39743 				**(**uint8_t)(__ccgo_up((*VP8BitWriter)(unsafe.Pointer(bw)).Fbuf + uintptr(v3))) = uint8(value)
  39744 				goto _2
  39745 			_2:
  39746 				;
  39747 				(*VP8BitWriter)(unsafe.Pointer(bw)).Frun = (*VP8BitWriter)(unsafe.Pointer(bw)).Frun - 1
  39748 			}
  39749 		}
  39750 		v3 = pos
  39751 		pos = pos + 1
  39752 		**(**uint8_t)(__ccgo_up((*VP8BitWriter)(unsafe.Pointer(bw)).Fbuf + uintptr(v3))) = uint8(bits & int32(0xff))
  39753 		(*VP8BitWriter)(unsafe.Pointer(bw)).Fpos = pos
  39754 	} else {
  39755 		(*VP8BitWriter)(unsafe.Pointer(bw)).Frun = (*VP8BitWriter)(unsafe.Pointer(bw)).Frun + 1 // delay writing of bytes 0xff, pending eventual carry.
  39756 	}
  39757 }
  39758 
  39759 //------------------------------------------------------------------------------
  39760 // renormalization
  39761 
  39762 var kNorm = [128]uint8_t{
  39763 	0:   uint8(7),
  39764 	1:   uint8(6),
  39765 	2:   uint8(6),
  39766 	3:   uint8(5),
  39767 	4:   uint8(5),
  39768 	5:   uint8(5),
  39769 	6:   uint8(5),
  39770 	7:   uint8(4),
  39771 	8:   uint8(4),
  39772 	9:   uint8(4),
  39773 	10:  uint8(4),
  39774 	11:  uint8(4),
  39775 	12:  uint8(4),
  39776 	13:  uint8(4),
  39777 	14:  uint8(4),
  39778 	15:  uint8(3),
  39779 	16:  uint8(3),
  39780 	17:  uint8(3),
  39781 	18:  uint8(3),
  39782 	19:  uint8(3),
  39783 	20:  uint8(3),
  39784 	21:  uint8(3),
  39785 	22:  uint8(3),
  39786 	23:  uint8(3),
  39787 	24:  uint8(3),
  39788 	25:  uint8(3),
  39789 	26:  uint8(3),
  39790 	27:  uint8(3),
  39791 	28:  uint8(3),
  39792 	29:  uint8(3),
  39793 	30:  uint8(3),
  39794 	31:  uint8(2),
  39795 	32:  uint8(2),
  39796 	33:  uint8(2),
  39797 	34:  uint8(2),
  39798 	35:  uint8(2),
  39799 	36:  uint8(2),
  39800 	37:  uint8(2),
  39801 	38:  uint8(2),
  39802 	39:  uint8(2),
  39803 	40:  uint8(2),
  39804 	41:  uint8(2),
  39805 	42:  uint8(2),
  39806 	43:  uint8(2),
  39807 	44:  uint8(2),
  39808 	45:  uint8(2),
  39809 	46:  uint8(2),
  39810 	47:  uint8(2),
  39811 	48:  uint8(2),
  39812 	49:  uint8(2),
  39813 	50:  uint8(2),
  39814 	51:  uint8(2),
  39815 	52:  uint8(2),
  39816 	53:  uint8(2),
  39817 	54:  uint8(2),
  39818 	55:  uint8(2),
  39819 	56:  uint8(2),
  39820 	57:  uint8(2),
  39821 	58:  uint8(2),
  39822 	59:  uint8(2),
  39823 	60:  uint8(2),
  39824 	61:  uint8(2),
  39825 	62:  uint8(2),
  39826 	63:  uint8(1),
  39827 	64:  uint8(1),
  39828 	65:  uint8(1),
  39829 	66:  uint8(1),
  39830 	67:  uint8(1),
  39831 	68:  uint8(1),
  39832 	69:  uint8(1),
  39833 	70:  uint8(1),
  39834 	71:  uint8(1),
  39835 	72:  uint8(1),
  39836 	73:  uint8(1),
  39837 	74:  uint8(1),
  39838 	75:  uint8(1),
  39839 	76:  uint8(1),
  39840 	77:  uint8(1),
  39841 	78:  uint8(1),
  39842 	79:  uint8(1),
  39843 	80:  uint8(1),
  39844 	81:  uint8(1),
  39845 	82:  uint8(1),
  39846 	83:  uint8(1),
  39847 	84:  uint8(1),
  39848 	85:  uint8(1),
  39849 	86:  uint8(1),
  39850 	87:  uint8(1),
  39851 	88:  uint8(1),
  39852 	89:  uint8(1),
  39853 	90:  uint8(1),
  39854 	91:  uint8(1),
  39855 	92:  uint8(1),
  39856 	93:  uint8(1),
  39857 	94:  uint8(1),
  39858 	95:  uint8(1),
  39859 	96:  uint8(1),
  39860 	97:  uint8(1),
  39861 	98:  uint8(1),
  39862 	99:  uint8(1),
  39863 	100: uint8(1),
  39864 	101: uint8(1),
  39865 	102: uint8(1),
  39866 	103: uint8(1),
  39867 	104: uint8(1),
  39868 	105: uint8(1),
  39869 	106: uint8(1),
  39870 	107: uint8(1),
  39871 	108: uint8(1),
  39872 	109: uint8(1),
  39873 	110: uint8(1),
  39874 	111: uint8(1),
  39875 	112: uint8(1),
  39876 	113: uint8(1),
  39877 	114: uint8(1),
  39878 	115: uint8(1),
  39879 	116: uint8(1),
  39880 	117: uint8(1),
  39881 	118: uint8(1),
  39882 	119: uint8(1),
  39883 	120: uint8(1),
  39884 	121: uint8(1),
  39885 	122: uint8(1),
  39886 	123: uint8(1),
  39887 	124: uint8(1),
  39888 	125: uint8(1),
  39889 	126: uint8(1),
  39890 }
  39891 
  39892 // C documentation
  39893 //
  39894 //	// range = ((range + 1) << kVP8Log2Range[range]) - 1
  39895 var kNewRange = [128]uint8_t{
  39896 	0:   uint8(127),
  39897 	1:   uint8(127),
  39898 	2:   uint8(191),
  39899 	3:   uint8(127),
  39900 	4:   uint8(159),
  39901 	5:   uint8(191),
  39902 	6:   uint8(223),
  39903 	7:   uint8(127),
  39904 	8:   uint8(143),
  39905 	9:   uint8(159),
  39906 	10:  uint8(175),
  39907 	11:  uint8(191),
  39908 	12:  uint8(207),
  39909 	13:  uint8(223),
  39910 	14:  uint8(239),
  39911 	15:  uint8(127),
  39912 	16:  uint8(135),
  39913 	17:  uint8(143),
  39914 	18:  uint8(151),
  39915 	19:  uint8(159),
  39916 	20:  uint8(167),
  39917 	21:  uint8(175),
  39918 	22:  uint8(183),
  39919 	23:  uint8(191),
  39920 	24:  uint8(199),
  39921 	25:  uint8(207),
  39922 	26:  uint8(215),
  39923 	27:  uint8(223),
  39924 	28:  uint8(231),
  39925 	29:  uint8(239),
  39926 	30:  uint8(247),
  39927 	31:  uint8(127),
  39928 	32:  uint8(131),
  39929 	33:  uint8(135),
  39930 	34:  uint8(139),
  39931 	35:  uint8(143),
  39932 	36:  uint8(147),
  39933 	37:  uint8(151),
  39934 	38:  uint8(155),
  39935 	39:  uint8(159),
  39936 	40:  uint8(163),
  39937 	41:  uint8(167),
  39938 	42:  uint8(171),
  39939 	43:  uint8(175),
  39940 	44:  uint8(179),
  39941 	45:  uint8(183),
  39942 	46:  uint8(187),
  39943 	47:  uint8(191),
  39944 	48:  uint8(195),
  39945 	49:  uint8(199),
  39946 	50:  uint8(203),
  39947 	51:  uint8(207),
  39948 	52:  uint8(211),
  39949 	53:  uint8(215),
  39950 	54:  uint8(219),
  39951 	55:  uint8(223),
  39952 	56:  uint8(227),
  39953 	57:  uint8(231),
  39954 	58:  uint8(235),
  39955 	59:  uint8(239),
  39956 	60:  uint8(243),
  39957 	61:  uint8(247),
  39958 	62:  uint8(251),
  39959 	63:  uint8(127),
  39960 	64:  uint8(129),
  39961 	65:  uint8(131),
  39962 	66:  uint8(133),
  39963 	67:  uint8(135),
  39964 	68:  uint8(137),
  39965 	69:  uint8(139),
  39966 	70:  uint8(141),
  39967 	71:  uint8(143),
  39968 	72:  uint8(145),
  39969 	73:  uint8(147),
  39970 	74:  uint8(149),
  39971 	75:  uint8(151),
  39972 	76:  uint8(153),
  39973 	77:  uint8(155),
  39974 	78:  uint8(157),
  39975 	79:  uint8(159),
  39976 	80:  uint8(161),
  39977 	81:  uint8(163),
  39978 	82:  uint8(165),
  39979 	83:  uint8(167),
  39980 	84:  uint8(169),
  39981 	85:  uint8(171),
  39982 	86:  uint8(173),
  39983 	87:  uint8(175),
  39984 	88:  uint8(177),
  39985 	89:  uint8(179),
  39986 	90:  uint8(181),
  39987 	91:  uint8(183),
  39988 	92:  uint8(185),
  39989 	93:  uint8(187),
  39990 	94:  uint8(189),
  39991 	95:  uint8(191),
  39992 	96:  uint8(193),
  39993 	97:  uint8(195),
  39994 	98:  uint8(197),
  39995 	99:  uint8(199),
  39996 	100: uint8(201),
  39997 	101: uint8(203),
  39998 	102: uint8(205),
  39999 	103: uint8(207),
  40000 	104: uint8(209),
  40001 	105: uint8(211),
  40002 	106: uint8(213),
  40003 	107: uint8(215),
  40004 	108: uint8(217),
  40005 	109: uint8(219),
  40006 	110: uint8(221),
  40007 	111: uint8(223),
  40008 	112: uint8(225),
  40009 	113: uint8(227),
  40010 	114: uint8(229),
  40011 	115: uint8(231),
  40012 	116: uint8(233),
  40013 	117: uint8(235),
  40014 	118: uint8(237),
  40015 	119: uint8(239),
  40016 	120: uint8(241),
  40017 	121: uint8(243),
  40018 	122: uint8(245),
  40019 	123: uint8(247),
  40020 	124: uint8(249),
  40021 	125: uint8(251),
  40022 	126: uint8(253),
  40023 	127: uint8(127),
  40024 }
  40025 
  40026 func VP8PutBit(tls *libc.TLS, bw uintptr, bit int32, prob int32) (r int32) {
  40027 	var shift, split int32
  40028 	_, _ = shift, split
  40029 	split = (*VP8BitWriter)(unsafe.Pointer(bw)).Frange1 * prob >> int32(8)
  40030 	if bit != 0 {
  40031 		**(**int32_t)(__ccgo_up(bw + 4)) += split + int32(1)
  40032 		**(**int32_t)(__ccgo_up(bw)) -= split + int32(1)
  40033 	} else {
  40034 		(*VP8BitWriter)(unsafe.Pointer(bw)).Frange1 = split
  40035 	}
  40036 	if (*VP8BitWriter)(unsafe.Pointer(bw)).Frange1 < int32(127) { // emit 'shift' bits out and renormalize
  40037 		shift = int32(kNorm[(*VP8BitWriter)(unsafe.Pointer(bw)).Frange1])
  40038 		(*VP8BitWriter)(unsafe.Pointer(bw)).Frange1 = int32(kNewRange[(*VP8BitWriter)(unsafe.Pointer(bw)).Frange1])
  40039 		**(**int32_t)(__ccgo_up(bw + 4)) <<= shift
  40040 		**(**int32)(__ccgo_up(bw + 12)) += shift
  40041 		if (*VP8BitWriter)(unsafe.Pointer(bw)).Fnb_bits > 0 {
  40042 			Flush(tls, bw)
  40043 		}
  40044 	}
  40045 	return bit
  40046 }
  40047 
  40048 func VP8PutBitUniform(tls *libc.TLS, bw uintptr, bit int32) (r int32) {
  40049 	var split int32
  40050 	_ = split
  40051 	split = (*VP8BitWriter)(unsafe.Pointer(bw)).Frange1 >> int32(1)
  40052 	if bit != 0 {
  40053 		**(**int32_t)(__ccgo_up(bw + 4)) += split + int32(1)
  40054 		**(**int32_t)(__ccgo_up(bw)) -= split + int32(1)
  40055 	} else {
  40056 		(*VP8BitWriter)(unsafe.Pointer(bw)).Frange1 = split
  40057 	}
  40058 	if (*VP8BitWriter)(unsafe.Pointer(bw)).Frange1 < int32(127) {
  40059 		(*VP8BitWriter)(unsafe.Pointer(bw)).Frange1 = int32(kNewRange[(*VP8BitWriter)(unsafe.Pointer(bw)).Frange1])
  40060 		**(**int32_t)(__ccgo_up(bw + 4)) <<= int32(1)
  40061 		**(**int32)(__ccgo_up(bw + 12)) += int32(1)
  40062 		if (*VP8BitWriter)(unsafe.Pointer(bw)).Fnb_bits > 0 {
  40063 			Flush(tls, bw)
  40064 		}
  40065 	}
  40066 	return bit
  40067 }
  40068 
  40069 func VP8PutBits(tls *libc.TLS, bw uintptr, value uint32_t, nb_bits int32) {
  40070 	var mask uint32_t
  40071 	_ = mask
  40072 	mask = uint32(1) << (nb_bits - int32(1))
  40073 	for {
  40074 		if !(mask != 0) {
  40075 			break
  40076 		}
  40077 		VP8PutBitUniform(tls, bw, int32(value&mask))
  40078 		goto _1
  40079 	_1:
  40080 		;
  40081 		mask = mask >> uint32(1)
  40082 	}
  40083 }
  40084 
  40085 func VP8PutSignedBits(tls *libc.TLS, bw uintptr, value int32, nb_bits int32) {
  40086 	if !(VP8PutBitUniform(tls, bw, libc.BoolInt32(value != 0)) != 0) {
  40087 		return
  40088 	}
  40089 	if value < 0 {
  40090 		VP8PutBits(tls, bw, uint32(-value<<int32(1)|int32(1)), nb_bits+int32(1))
  40091 	} else {
  40092 		VP8PutBits(tls, bw, uint32(value<<int32(1)), nb_bits+int32(1))
  40093 	}
  40094 }
  40095 
  40096 //------------------------------------------------------------------------------
  40097 
  40098 func VP8BitWriterInit(tls *libc.TLS, bw uintptr, expected_size size_t) (r int32) {
  40099 	var v1 int32
  40100 	_ = v1
  40101 	(*VP8BitWriter)(unsafe.Pointer(bw)).Frange1 = libc.Int32FromInt32(255) - libc.Int32FromInt32(1)
  40102 	(*VP8BitWriter)(unsafe.Pointer(bw)).Fvalue = 0
  40103 	(*VP8BitWriter)(unsafe.Pointer(bw)).Frun = 0
  40104 	(*VP8BitWriter)(unsafe.Pointer(bw)).Fnb_bits = -int32(8)
  40105 	(*VP8BitWriter)(unsafe.Pointer(bw)).Fpos = uint64(0)
  40106 	(*VP8BitWriter)(unsafe.Pointer(bw)).Fmax_pos = uint64(0)
  40107 	(*VP8BitWriter)(unsafe.Pointer(bw)).Ferror1 = 0
  40108 	(*VP8BitWriter)(unsafe.Pointer(bw)).Fbuf = libc.UintptrFromInt32(0)
  40109 	if expected_size > uint64(0) {
  40110 		v1 = BitWriterResize(tls, bw, expected_size)
  40111 	} else {
  40112 		v1 = int32(1)
  40113 	}
  40114 	return v1
  40115 }
  40116 
  40117 func VP8BitWriterFinish(tls *libc.TLS, bw uintptr) (r uintptr) {
  40118 	VP8PutBits(tls, bw, uint32(0), int32(9)-(*VP8BitWriter)(unsafe.Pointer(bw)).Fnb_bits)
  40119 	(*VP8BitWriter)(unsafe.Pointer(bw)).Fnb_bits = 0 // pad with zeroes
  40120 	Flush(tls, bw)
  40121 	return (*VP8BitWriter)(unsafe.Pointer(bw)).Fbuf
  40122 }
  40123 
  40124 func VP8BitWriterAppend(tls *libc.TLS, bw uintptr, data uintptr, size size_t) (r int32) {
  40125 	if (*VP8BitWriter)(unsafe.Pointer(bw)).Fnb_bits != -int32(8) {
  40126 		return 0
  40127 	} // Flush() must have been called
  40128 	if !(BitWriterResize(tls, bw, size) != 0) {
  40129 		return 0
  40130 	}
  40131 	libc.Xmemcpy(tls, (*VP8BitWriter)(unsafe.Pointer(bw)).Fbuf+uintptr((*VP8BitWriter)(unsafe.Pointer(bw)).Fpos), data, size)
  40132 	**(**size_t)(__ccgo_up(bw + 24)) += size
  40133 	return int32(1)
  40134 }
  40135 
  40136 func VP8BitWriterWipeOut(tls *libc.TLS, bw uintptr) {
  40137 	if bw != libc.UintptrFromInt32(0) {
  40138 		WebPSafeFree(tls, (*VP8BitWriter)(unsafe.Pointer(bw)).Fbuf)
  40139 		libc.Xmemset(tls, bw, 0, uint64(48))
  40140 	}
  40141 }
  40142 
  40143 //------------------------------------------------------------------------------
  40144 // VP8LBitWriter
  40145 
  40146 // This is the minimum amount of size the memory buffer is guaranteed to grow
  40147 // when extra space is needed.
  40148 
  40149 // C documentation
  40150 //
  40151 //	// Returns 1 on success.
  40152 func VP8LBitWriterResize(tls *libc.TLS, bw uintptr, extra_size size_t) (r int32) {
  40153 	var allocated_buf uintptr
  40154 	var allocated_size, current_size, max_bytes, size_required size_t
  40155 	var size_required_64b uint64_t
  40156 	_, _, _, _, _, _ = allocated_buf, allocated_size, current_size, max_bytes, size_required, size_required_64b
  40157 	max_bytes = uint64(int64((*VP8LBitWriter)(unsafe.Pointer(bw)).Fend) - int64((*VP8LBitWriter)(unsafe.Pointer(bw)).Fbuf))
  40158 	current_size = uint64(int64((*VP8LBitWriter)(unsafe.Pointer(bw)).Fcur) - int64((*VP8LBitWriter)(unsafe.Pointer(bw)).Fbuf))
  40159 	size_required_64b = current_size + extra_size
  40160 	size_required = size_required_64b
  40161 	if size_required != size_required_64b {
  40162 		(*VP8LBitWriter)(unsafe.Pointer(bw)).Ferror1 = int32(1)
  40163 		return 0
  40164 	}
  40165 	if max_bytes > uint64(0) && size_required <= max_bytes {
  40166 		return int32(1)
  40167 	}
  40168 	allocated_size = uint64(3) * max_bytes >> int32(1)
  40169 	if allocated_size < size_required {
  40170 		allocated_size = size_required
  40171 	}
  40172 	// make allocated size multiple of 1k
  40173 	allocated_size = (allocated_size>>libc.Int32FromInt32(10) + libc.Uint64FromInt32(1)) << libc.Int32FromInt32(10)
  40174 	allocated_buf = WebPSafeMalloc(tls, uint64(1), allocated_size)
  40175 	if allocated_buf == libc.UintptrFromInt32(0) {
  40176 		(*VP8LBitWriter)(unsafe.Pointer(bw)).Ferror1 = int32(1)
  40177 		return 0
  40178 	}
  40179 	if current_size > uint64(0) {
  40180 		libc.Xmemcpy(tls, allocated_buf, (*VP8LBitWriter)(unsafe.Pointer(bw)).Fbuf, current_size)
  40181 	}
  40182 	WebPSafeFree(tls, (*VP8LBitWriter)(unsafe.Pointer(bw)).Fbuf)
  40183 	(*VP8LBitWriter)(unsafe.Pointer(bw)).Fbuf = allocated_buf
  40184 	(*VP8LBitWriter)(unsafe.Pointer(bw)).Fcur = (*VP8LBitWriter)(unsafe.Pointer(bw)).Fbuf + uintptr(current_size)
  40185 	(*VP8LBitWriter)(unsafe.Pointer(bw)).Fend = (*VP8LBitWriter)(unsafe.Pointer(bw)).Fbuf + uintptr(allocated_size)
  40186 	return int32(1)
  40187 }
  40188 
  40189 func VP8LBitWriterInit(tls *libc.TLS, bw uintptr, expected_size size_t) (r int32) {
  40190 	libc.Xmemset(tls, bw, 0, uint64(48))
  40191 	return VP8LBitWriterResize(tls, bw, expected_size)
  40192 }
  40193 
  40194 func VP8LBitWriterClone(tls *libc.TLS, src uintptr, dst uintptr) (r int32) {
  40195 	var current_size size_t
  40196 	_ = current_size
  40197 	current_size = uint64(int64((*VP8LBitWriter)(unsafe.Pointer(src)).Fcur) - int64((*VP8LBitWriter)(unsafe.Pointer(src)).Fbuf))
  40198 	if !(VP8LBitWriterResize(tls, dst, current_size) != 0) {
  40199 		return 0
  40200 	}
  40201 	libc.Xmemcpy(tls, (*VP8LBitWriter)(unsafe.Pointer(dst)).Fbuf, (*VP8LBitWriter)(unsafe.Pointer(src)).Fbuf, current_size)
  40202 	(*VP8LBitWriter)(unsafe.Pointer(dst)).Fbits = (*VP8LBitWriter)(unsafe.Pointer(src)).Fbits
  40203 	(*VP8LBitWriter)(unsafe.Pointer(dst)).Fused = (*VP8LBitWriter)(unsafe.Pointer(src)).Fused
  40204 	(*VP8LBitWriter)(unsafe.Pointer(dst)).Ferror1 = (*VP8LBitWriter)(unsafe.Pointer(src)).Ferror1
  40205 	(*VP8LBitWriter)(unsafe.Pointer(dst)).Fcur = (*VP8LBitWriter)(unsafe.Pointer(dst)).Fbuf + uintptr(current_size)
  40206 	return int32(1)
  40207 }
  40208 
  40209 func VP8LBitWriterWipeOut(tls *libc.TLS, bw uintptr) {
  40210 	if bw != libc.UintptrFromInt32(0) {
  40211 		WebPSafeFree(tls, (*VP8LBitWriter)(unsafe.Pointer(bw)).Fbuf)
  40212 		libc.Xmemset(tls, bw, 0, uint64(48))
  40213 	}
  40214 }
  40215 
  40216 func VP8LBitWriterReset(tls *libc.TLS, bw_init uintptr, bw uintptr) {
  40217 	(*VP8LBitWriter)(unsafe.Pointer(bw)).Fbits = (*VP8LBitWriter)(unsafe.Pointer(bw_init)).Fbits
  40218 	(*VP8LBitWriter)(unsafe.Pointer(bw)).Fused = (*VP8LBitWriter)(unsafe.Pointer(bw_init)).Fused
  40219 	(*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))
  40220 	(*VP8LBitWriter)(unsafe.Pointer(bw)).Ferror1 = (*VP8LBitWriter)(unsafe.Pointer(bw_init)).Ferror1
  40221 }
  40222 
  40223 func VP8LBitWriterSwap(tls *libc.TLS, src uintptr, dst uintptr) {
  40224 	var tmp VP8LBitWriter
  40225 	_ = tmp
  40226 	tmp = **(**VP8LBitWriter)(__ccgo_up(src))
  40227 	**(**VP8LBitWriter)(__ccgo_up(src)) = **(**VP8LBitWriter)(__ccgo_up(dst))
  40228 	**(**VP8LBitWriter)(__ccgo_up(dst)) = tmp
  40229 }
  40230 
  40231 func VP8LPutBitsFlushBits(tls *libc.TLS, bw uintptr) {
  40232 	var extra_size, v1 uint64_t
  40233 	var v2 int32
  40234 	_, _, _ = extra_size, v1, v2
  40235 	// If needed, make some room by flushing some bits out.
  40236 	if (*VP8LBitWriter)(unsafe.Pointer(bw)).Fcur+uintptr(VP8L_WRITER_BYTES) > (*VP8LBitWriter)(unsafe.Pointer(bw)).Fend {
  40237 		extra_size = uint64(int64((*VP8LBitWriter)(unsafe.Pointer(bw)).Fend)-int64((*VP8LBitWriter)(unsafe.Pointer(bw)).Fbuf)) + uint64(32768)
  40238 		v1 = extra_size
  40239 		v2 = libc.BoolInt32(v1 == v1)
  40240 		goto _3
  40241 	_3:
  40242 		;
  40243 		if !(v2 != 0) || !(VP8LBitWriterResize(tls, bw, extra_size) != 0) {
  40244 			(*VP8LBitWriter)(unsafe.Pointer(bw)).Fcur = (*VP8LBitWriter)(unsafe.Pointer(bw)).Fbuf
  40245 			(*VP8LBitWriter)(unsafe.Pointer(bw)).Ferror1 = int32(1)
  40246 			return
  40247 		}
  40248 	}
  40249 	**(**vp8l_wtype_t)(__ccgo_up((*VP8LBitWriter)(unsafe.Pointer(bw)).Fcur)) = uint32((*VP8LBitWriter)(unsafe.Pointer(bw)).Fbits)
  40250 	**(**uintptr)(__ccgo_up(bw + 24)) += uintptr(VP8L_WRITER_BYTES)
  40251 	**(**vp8l_atype_t)(__ccgo_up(bw)) >>= uint64(VP8L_WRITER_BITS)
  40252 	**(**int32)(__ccgo_up(bw + 8)) -= int32(VP8L_WRITER_BITS)
  40253 }
  40254 
  40255 func VP8LPutBitsInternal(tls *libc.TLS, bw uintptr, bits uint32_t, n_bits int32) {
  40256 	var extra_size, v1 uint64_t
  40257 	var lbits vp8l_atype_t
  40258 	var used, v2 int32
  40259 	_, _, _, _, _ = extra_size, lbits, used, v1, v2
  40260 	// That's the max we can handle:
  40261 	if n_bits > 0 {
  40262 		lbits = (*VP8LBitWriter)(unsafe.Pointer(bw)).Fbits
  40263 		used = (*VP8LBitWriter)(unsafe.Pointer(bw)).Fused
  40264 		// Special case of overflow handling for 32bit accumulator (2-steps flush).
  40265 		// If needed, make some room by flushing some bits out.
  40266 		for used >= int32(VP8L_WRITER_BITS) {
  40267 			if (*VP8LBitWriter)(unsafe.Pointer(bw)).Fcur+uintptr(VP8L_WRITER_BYTES) > (*VP8LBitWriter)(unsafe.Pointer(bw)).Fend {
  40268 				extra_size = uint64(int64((*VP8LBitWriter)(unsafe.Pointer(bw)).Fend)-int64((*VP8LBitWriter)(unsafe.Pointer(bw)).Fbuf)) + uint64(32768)
  40269 				v1 = extra_size
  40270 				v2 = libc.BoolInt32(v1 == v1)
  40271 				goto _3
  40272 			_3:
  40273 				;
  40274 				if !(v2 != 0) || !(VP8LBitWriterResize(tls, bw, extra_size) != 0) {
  40275 					(*VP8LBitWriter)(unsafe.Pointer(bw)).Fcur = (*VP8LBitWriter)(unsafe.Pointer(bw)).Fbuf
  40276 					(*VP8LBitWriter)(unsafe.Pointer(bw)).Ferror1 = int32(1)
  40277 					return
  40278 				}
  40279 			}
  40280 			**(**vp8l_wtype_t)(__ccgo_up((*VP8LBitWriter)(unsafe.Pointer(bw)).Fcur)) = uint32(lbits)
  40281 			**(**uintptr)(__ccgo_up(bw + 24)) += uintptr(VP8L_WRITER_BYTES)
  40282 			lbits = lbits >> uint64(VP8L_WRITER_BITS)
  40283 			used = used - int32(VP8L_WRITER_BITS)
  40284 		}
  40285 		(*VP8LBitWriter)(unsafe.Pointer(bw)).Fbits = lbits | uint64(bits)<<used
  40286 		(*VP8LBitWriter)(unsafe.Pointer(bw)).Fused = used + n_bits
  40287 	}
  40288 }
  40289 
  40290 func VP8LBitWriterFinish(tls *libc.TLS, bw uintptr) (r uintptr) {
  40291 	var v1, v2 uintptr
  40292 	_, _ = v1, v2
  40293 	// flush leftover bits
  40294 	if VP8LBitWriterResize(tls, bw, uint64(((*VP8LBitWriter)(unsafe.Pointer(bw)).Fused+int32(7))>>int32(3))) != 0 {
  40295 		for (*VP8LBitWriter)(unsafe.Pointer(bw)).Fused > 0 {
  40296 			v2 = bw + 24
  40297 			v1 = *(*uintptr)(unsafe.Pointer(v2))
  40298 			*(*uintptr)(unsafe.Pointer(v2)) = *(*uintptr)(unsafe.Pointer(v2)) + 1
  40299 			**(**uint8_t)(__ccgo_up(v1)) = uint8((*VP8LBitWriter)(unsafe.Pointer(bw)).Fbits)
  40300 			**(**vp8l_atype_t)(__ccgo_up(bw)) >>= uint64(8)
  40301 			**(**int32)(__ccgo_up(bw + 8)) -= int32(8)
  40302 		}
  40303 		(*VP8LBitWriter)(unsafe.Pointer(bw)).Fused = 0
  40304 	}
  40305 	return (*VP8LBitWriter)(unsafe.Pointer(bw)).Fbuf
  40306 }
  40307 
  40308 var kHashMul12 = uint32(0x1e35a7bd)
  40309 
  40310 //------------------------------------------------------------------------------
  40311 
  40312 //------------------------------------------------------------------------------
  40313 // VP8LColorCache.
  40314 
  40315 func VP8LColorCacheInit(tls *libc.TLS, color_cache uintptr, hash_bits int32) (r int32) {
  40316 	var hash_size int32
  40317 	_ = hash_size
  40318 	hash_size = int32(1) << hash_bits
  40319 	(*VP8LColorCache)(unsafe.Pointer(color_cache)).Fcolors = WebPSafeCalloc(tls, uint64(hash_size), uint64(4))
  40320 	if (*VP8LColorCache)(unsafe.Pointer(color_cache)).Fcolors == libc.UintptrFromInt32(0) {
  40321 		return 0
  40322 	}
  40323 	(*VP8LColorCache)(unsafe.Pointer(color_cache)).Fhash_shift = int32(32) - hash_bits
  40324 	(*VP8LColorCache)(unsafe.Pointer(color_cache)).Fhash_bits = hash_bits
  40325 	return int32(1)
  40326 }
  40327 
  40328 func VP8LColorCacheClear(tls *libc.TLS, color_cache uintptr) {
  40329 	if color_cache != libc.UintptrFromInt32(0) {
  40330 		WebPSafeFree(tls, (*VP8LColorCache)(unsafe.Pointer(color_cache)).Fcolors)
  40331 		(*VP8LColorCache)(unsafe.Pointer(color_cache)).Fcolors = libc.UintptrFromInt32(0)
  40332 	}
  40333 }
  40334 
  40335 func VP8LColorCacheCopy(tls *libc.TLS, src uintptr, dst uintptr) {
  40336 	libc.Xmemcpy(tls, (*VP8LColorCache)(unsafe.Pointer(dst)).Fcolors, (*VP8LColorCache)(unsafe.Pointer(src)).Fcolors, libc.Uint64FromUint32(1)<<(*VP8LColorCache)(unsafe.Pointer(dst)).Fhash_bits*uint64(4))
  40337 }
  40338 
  40339 // -----------------------------------------------------------------------------
  40340 // Quick estimate of a potentially interesting filter mode to try.
  40341 
  40342 func GradientPredictor(tls *libc.TLS, a uint8_t, b uint8_t, c uint8_t) (r int32) {
  40343 	var g, v1, v2 int32
  40344 	_, _, _ = g, v1, v2
  40345 	g = int32(a) + int32(b) - int32(c)
  40346 	if g & ^libc.Int32FromInt32(0xff) == 0 {
  40347 		v1 = g
  40348 	} else {
  40349 		if g < 0 {
  40350 			v2 = 0
  40351 		} else {
  40352 			v2 = int32(255)
  40353 		}
  40354 		v1 = v2
  40355 	}
  40356 	return v1 // clip to 8bit
  40357 }
  40358 
  40359 func WebPEstimateBestFilter(tls *libc.TLS, data uintptr, width int32, height int32, stride int32) (r WEBP_FILTER_TYPE) {
  40360 	bp := tls.Alloc(256)
  40361 	defer tls.Free(256)
  40362 	var best_filter WEBP_FILTER_TYPE
  40363 	var best_score, diff0, diff1, diff2, diff3, filter, grad_pred, i, j, mean, score int32
  40364 	var p uintptr
  40365 	var _ /* bins at bp+0 */ [4][16]int32
  40366 	_, _, _, _, _, _, _, _, _, _, _, _, _ = best_filter, best_score, diff0, diff1, diff2, diff3, filter, grad_pred, i, j, mean, p, score
  40367 	libc.Xmemset(tls, bp, 0, uint64(256))
  40368 	// We only sample every other pixels. That's enough.
  40369 	j = int32(2)
  40370 	for {
  40371 		if !(j < height-int32(1)) {
  40372 			break
  40373 		}
  40374 		p = data + uintptr(j*stride)
  40375 		mean = int32(**(**uint8_t)(__ccgo_up(p)))
  40376 		i = int32(2)
  40377 		for {
  40378 			if !(i < width-int32(1)) {
  40379 				break
  40380 			}
  40381 			diff0 = libc.Xabs(tls, int32(**(**uint8_t)(__ccgo_up(p + uintptr(i))))-mean) >> libc.Int32FromInt32(4)
  40382 			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)
  40383 			diff2 = libc.Xabs(tls, int32(**(**uint8_t)(__ccgo_up(p + uintptr(i))))-int32(**(**uint8_t)(__ccgo_up(p + uintptr(i-width))))) >> libc.Int32FromInt32(4)
  40384 			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)))))
  40385 			diff3 = libc.Xabs(tls, int32(**(**uint8_t)(__ccgo_up(p + uintptr(i))))-grad_pred) >> libc.Int32FromInt32(4)
  40386 			**(**int32)(__ccgo_up(bp + uintptr(WEBP_FILTER_NONE)*64 + uintptr(diff0)*4)) = int32(1)
  40387 			**(**int32)(__ccgo_up(bp + uintptr(WEBP_FILTER_HORIZONTAL)*64 + uintptr(diff1)*4)) = int32(1)
  40388 			**(**int32)(__ccgo_up(bp + uintptr(WEBP_FILTER_VERTICAL)*64 + uintptr(diff2)*4)) = int32(1)
  40389 			**(**int32)(__ccgo_up(bp + uintptr(WEBP_FILTER_GRADIENT)*64 + uintptr(diff3)*4)) = int32(1)
  40390 			mean = (int32(3)*mean + int32(**(**uint8_t)(__ccgo_up(p + uintptr(i)))) + int32(2)) >> int32(2)
  40391 			goto _2
  40392 		_2:
  40393 			;
  40394 			i = i + int32(2)
  40395 		}
  40396 		goto _1
  40397 	_1:
  40398 		;
  40399 		j = j + int32(2)
  40400 	}
  40401 	best_filter = int32(WEBP_FILTER_NONE)
  40402 	best_score = int32(0x7fffffff)
  40403 	filter = int32(WEBP_FILTER_NONE)
  40404 	for {
  40405 		if !(filter < int32(WEBP_FILTER_LAST)) {
  40406 			break
  40407 		}
  40408 		score = 0
  40409 		i = 0
  40410 		for {
  40411 			if !(i < int32(16)) {
  40412 				break
  40413 			}
  40414 			if **(**int32)(__ccgo_up(bp + uintptr(filter)*64 + uintptr(i)*4)) > 0 {
  40415 				score = score + i
  40416 			}
  40417 			goto _4
  40418 		_4:
  40419 			;
  40420 			i = i + 1
  40421 		}
  40422 		if score < best_score {
  40423 			best_score = score
  40424 			best_filter = filter
  40425 		}
  40426 		goto _3
  40427 	_3:
  40428 		;
  40429 		filter = filter + 1
  40430 	}
  40431 	return best_filter
  40432 	return r
  40433 }
  40434 
  40435 // Alpha related constants.
  40436 
  40437 // Mux related constants.
  40438 
  40439 // Maximum chunk payload is such that adding the header and padding won't
  40440 // overflow a uint32_t.
  40441 
  40442 // -----------------------------------------------------------------------------
  40443 // Util function to optimize the symbol map for RLE coding
  40444 
  40445 // C documentation
  40446 //
  40447 //	// Heuristics for selecting the stride ranges to collapse.
  40448 func ValuesShouldBeCollapsedToStrideAverage(tls *libc.TLS, a int32, b int32) (r int32) {
  40449 	return libc.BoolInt32(libc.Xabs(tls, a-b) < int32(4))
  40450 }
  40451 
  40452 // C documentation
  40453 //
  40454 //	// Change the population counts in a way that the consequent
  40455 //	// Huffman tree compression, especially its RLE-part, give smaller output.
  40456 func OptimizeHuffmanForRle(tls *libc.TLS, length int32, good_for_rle uintptr, counts uintptr) {
  40457 	var count, k1, limit, stride1, sum, symbol uint32_t
  40458 	var i, k, stride int32
  40459 	_, _, _, _, _, _, _, _, _ = count, i, k, k1, limit, stride, stride1, sum, symbol
  40460 	for {
  40461 		if !(length >= 0) {
  40462 			break
  40463 		}
  40464 		if length == 0 {
  40465 			return // All zeros.
  40466 		}
  40467 		if **(**uint32_t)(__ccgo_up(counts + uintptr(length-int32(1))*4)) != uint32(0) {
  40468 			// Now counts[0..length - 1] does not have trailing zeros.
  40469 			break
  40470 		}
  40471 		goto _1
  40472 	_1:
  40473 		;
  40474 		length = length - 1
  40475 	}
  40476 	// 2) Let's mark all population counts that already can be encoded
  40477 	// with an rle code.
  40478 	// Let's not spoil any of the existing good rle codes.
  40479 	// Mark any seq of 0's that is longer as 5 as a good_for_rle.
  40480 	// Mark any seq of non-0's that is longer as 7 as a good_for_rle.
  40481 	symbol = **(**uint32_t)(__ccgo_up(counts))
  40482 	stride = 0
  40483 	i = 0
  40484 	for {
  40485 		if !(i < length+int32(1)) {
  40486 			break
  40487 		}
  40488 		if i == length || **(**uint32_t)(__ccgo_up(counts + uintptr(i)*4)) != symbol {
  40489 			if symbol == uint32(0) && stride >= int32(5) || symbol != uint32(0) && stride >= int32(7) {
  40490 				k = 0
  40491 				for {
  40492 					if !(k < stride) {
  40493 						break
  40494 					}
  40495 					**(**uint8_t)(__ccgo_up(good_for_rle + uintptr(i-k-int32(1)))) = uint8(1)
  40496 					goto _3
  40497 				_3:
  40498 					;
  40499 					k = k + 1
  40500 				}
  40501 			}
  40502 			stride = int32(1)
  40503 			if i != length {
  40504 				symbol = **(**uint32_t)(__ccgo_up(counts + uintptr(i)*4))
  40505 			}
  40506 		} else {
  40507 			stride = stride + 1
  40508 		}
  40509 		goto _2
  40510 	_2:
  40511 		;
  40512 		i = i + 1
  40513 	}
  40514 	// 3) Let's replace those population counts that lead to more rle codes.
  40515 	stride1 = uint32(0)
  40516 	limit = **(**uint32_t)(__ccgo_up(counts))
  40517 	sum = uint32(0)
  40518 	i = 0
  40519 	for {
  40520 		if !(i < length+int32(1)) {
  40521 			break
  40522 		}
  40523 		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) {
  40524 			if stride1 >= uint32(4) || stride1 >= uint32(3) && sum == uint32(0) {
  40525 				// The stride must end, collapse what we have, if we have enough (4).
  40526 				count = (sum + stride1/uint32(2)) / stride1
  40527 				if count < uint32(1) {
  40528 					count = uint32(1)
  40529 				}
  40530 				if sum == uint32(0) {
  40531 					// Don't make an all zeros stride to be upgraded to ones.
  40532 					count = uint32(0)
  40533 				}
  40534 				k1 = uint32(0)
  40535 				for {
  40536 					if !(k1 < stride1) {
  40537 						break
  40538 					}
  40539 					// We don't want to change value at counts[i],
  40540 					// that is already belonging to the next stride. Thus - 1.
  40541 					**(**uint32_t)(__ccgo_up(counts + uintptr(uint32(i)-k1-uint32(1))*4)) = count
  40542 					goto _5
  40543 				_5:
  40544 					;
  40545 					k1 = k1 + 1
  40546 				}
  40547 			}
  40548 			stride1 = uint32(0)
  40549 			sum = uint32(0)
  40550 			if i < length-int32(3) {
  40551 				// All interesting strides have a count of at least 4,
  40552 				// at least when non-zeros.
  40553 				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)
  40554 			} else {
  40555 				if i < length {
  40556 					limit = **(**uint32_t)(__ccgo_up(counts + uintptr(i)*4))
  40557 				} else {
  40558 					limit = uint32(0)
  40559 				}
  40560 			}
  40561 		}
  40562 		stride1 = stride1 + 1
  40563 		if i != length {
  40564 			sum = sum + **(**uint32_t)(__ccgo_up(counts + uintptr(i)*4))
  40565 			if stride1 >= uint32(4) {
  40566 				limit = (sum + stride1/uint32(2)) / stride1
  40567 			}
  40568 		}
  40569 		goto _4
  40570 	_4:
  40571 		;
  40572 		i = i + 1
  40573 	}
  40574 }
  40575 
  40576 // C documentation
  40577 //
  40578 //	// A comparer function for two Huffman trees: sorts first by 'total count'
  40579 //	// (more comes first), and then by 'value' (more comes first).
  40580 func CompareHuffmanTrees(tls *libc.TLS, ptr1 uintptr, ptr2 uintptr) (r int32) {
  40581 	var t1, t2 uintptr
  40582 	var v1 int32
  40583 	_, _, _ = t1, t2, v1
  40584 	t1 = ptr1
  40585 	t2 = ptr2
  40586 	if (*HuffmanTree)(unsafe.Pointer(t1)).Ftotal_count > (*HuffmanTree)(unsafe.Pointer(t2)).Ftotal_count {
  40587 		return -int32(1)
  40588 	} else {
  40589 		if (*HuffmanTree)(unsafe.Pointer(t1)).Ftotal_count < (*HuffmanTree)(unsafe.Pointer(t2)).Ftotal_count {
  40590 			return int32(1)
  40591 		} else {
  40592 			if (*HuffmanTree)(unsafe.Pointer(t1)).Fvalue < (*HuffmanTree)(unsafe.Pointer(t2)).Fvalue {
  40593 				v1 = -int32(1)
  40594 			} else {
  40595 				v1 = int32(1)
  40596 			}
  40597 			return v1
  40598 		}
  40599 	}
  40600 	return r
  40601 }
  40602 
  40603 func SetBitDepths(tls *libc.TLS, tree uintptr, pool uintptr, bit_depths uintptr, level int32) {
  40604 	if (*HuffmanTree)(unsafe.Pointer(tree)).Fpool_index_left >= 0 {
  40605 		SetBitDepths(tls, pool+uintptr((*HuffmanTree)(unsafe.Pointer(tree)).Fpool_index_left)*16, pool, bit_depths, level+int32(1))
  40606 		SetBitDepths(tls, pool+uintptr((*HuffmanTree)(unsafe.Pointer(tree)).Fpool_index_right)*16, pool, bit_depths, level+int32(1))
  40607 	} else {
  40608 		**(**uint8_t)(__ccgo_up(bit_depths + uintptr((*HuffmanTree)(unsafe.Pointer(tree)).Fvalue))) = uint8(level)
  40609 	}
  40610 }
  40611 
  40612 // C documentation
  40613 //
  40614 //	// Create an optimal Huffman tree.
  40615 //	//
  40616 //	// (data,length): population counts.
  40617 //	// tree_limit: maximum bit depth (inclusive) of the codes.
  40618 //	// bit_depths[]: how many bits are used for the symbol.
  40619 //	//
  40620 //	// Returns 0 when an error has occurred.
  40621 //	//
  40622 //	// The catch here is that the tree cannot be arbitrarily deep
  40623 //	//
  40624 //	// count_limit is the value that is to be faked as the minimum value
  40625 //	// and this minimum value is raised until the tree matches the
  40626 //	// maximum length requirement.
  40627 //	//
  40628 //	// This algorithm is not of excellent performance for very long data blocks,
  40629 //	// especially when population counts are longer than 2**tree_limit, but
  40630 //	// we are not planning to use this with extremely long blocks.
  40631 //	//
  40632 //	// See https://en.wikipedia.org/wiki/Huffman_coding
  40633 func GenerateOptimalTree(tls *libc.TLS, histogram uintptr, histogram_size int32, tree uintptr, tree_depth_limit int32, bit_depths uintptr) {
  40634 	var count, count1, count_min uint32_t
  40635 	var i, idx, j, k, max_depth, tree_pool_size, tree_size, tree_size_orig, v5 int32
  40636 	var tree_pool uintptr
  40637 	var v4 uint32
  40638 	_, _, _, _, _, _, _, _, _, _, _, _, _, _ = count, count1, count_min, i, idx, j, k, max_depth, tree_pool, tree_pool_size, tree_size, tree_size_orig, v4, v5
  40639 	tree_size_orig = 0
  40640 	i = 0
  40641 	for {
  40642 		if !(i < histogram_size) {
  40643 			break
  40644 		}
  40645 		if **(**uint32_t)(__ccgo_up(histogram + uintptr(i)*4)) != uint32(0) {
  40646 			tree_size_orig = tree_size_orig + 1
  40647 		}
  40648 		goto _1
  40649 	_1:
  40650 		;
  40651 		i = i + 1
  40652 	}
  40653 	if tree_size_orig == 0 { // pretty optimal already!
  40654 		return
  40655 	}
  40656 	tree_pool = tree + uintptr(tree_size_orig)*16
  40657 	// For block sizes with less than 64k symbols we never need to do a
  40658 	// second iteration of this loop.
  40659 	// If we actually start running inside this loop a lot, we would perhaps
  40660 	// be better off with the Katajainen algorithm.
  40661 	count_min = uint32(1)
  40662 	for {
  40663 		tree_size = tree_size_orig
  40664 		// We need to pack the Huffman tree in tree_depth_limit bits.
  40665 		// So, we try by faking histogram entries to be at least 'count_min'.
  40666 		idx = 0
  40667 		j = 0
  40668 		for {
  40669 			if !(j < histogram_size) {
  40670 				break
  40671 			}
  40672 			if **(**uint32_t)(__ccgo_up(histogram + uintptr(j)*4)) != uint32(0) {
  40673 				if **(**uint32_t)(__ccgo_up(histogram + uintptr(j)*4)) < count_min {
  40674 					v4 = count_min
  40675 				} else {
  40676 					v4 = **(**uint32_t)(__ccgo_up(histogram + uintptr(j)*4))
  40677 				}
  40678 				count = v4
  40679 				(**(**HuffmanTree)(__ccgo_up(tree + uintptr(idx)*16))).Ftotal_count = count
  40680 				(**(**HuffmanTree)(__ccgo_up(tree + uintptr(idx)*16))).Fvalue = j
  40681 				(**(**HuffmanTree)(__ccgo_up(tree + uintptr(idx)*16))).Fpool_index_left = -int32(1)
  40682 				(**(**HuffmanTree)(__ccgo_up(tree + uintptr(idx)*16))).Fpool_index_right = -int32(1)
  40683 				idx = idx + 1
  40684 			}
  40685 			goto _3
  40686 		_3:
  40687 			;
  40688 			j = j + 1
  40689 		}
  40690 		// Build the Huffman tree.
  40691 		libc.Xqsort(tls, tree, uint64(tree_size), uint64(16), __ccgo_fp(CompareHuffmanTrees))
  40692 		if tree_size > int32(1) { // Normal case.
  40693 			tree_pool_size = 0
  40694 			for tree_size > int32(1) {
  40695 				v5 = tree_pool_size
  40696 				tree_pool_size = tree_pool_size + 1
  40697 				**(**HuffmanTree)(__ccgo_up(tree_pool + uintptr(v5)*16)) = **(**HuffmanTree)(__ccgo_up(tree + uintptr(tree_size-int32(1))*16))
  40698 				v5 = tree_pool_size
  40699 				tree_pool_size = tree_pool_size + 1
  40700 				**(**HuffmanTree)(__ccgo_up(tree_pool + uintptr(v5)*16)) = **(**HuffmanTree)(__ccgo_up(tree + uintptr(tree_size-int32(2))*16))
  40701 				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
  40702 				tree_size = tree_size - int32(2)
  40703 				k = 0
  40704 				for {
  40705 					if !(k < tree_size) {
  40706 						break
  40707 					}
  40708 					if (**(**HuffmanTree)(__ccgo_up(tree + uintptr(k)*16))).Ftotal_count <= count1 {
  40709 						break
  40710 					}
  40711 					goto _7
  40712 				_7:
  40713 					;
  40714 					k = k + 1
  40715 				}
  40716 				libc.Xmemmove(tls, tree+uintptr(k+libc.Int32FromInt32(1))*16, tree+uintptr(k)*16, uint64(tree_size-k)*uint64(16))
  40717 				(**(**HuffmanTree)(__ccgo_up(tree + uintptr(k)*16))).Ftotal_count = count1
  40718 				(**(**HuffmanTree)(__ccgo_up(tree + uintptr(k)*16))).Fvalue = -int32(1)
  40719 				(**(**HuffmanTree)(__ccgo_up(tree + uintptr(k)*16))).Fpool_index_left = tree_pool_size - int32(1)
  40720 				(**(**HuffmanTree)(__ccgo_up(tree + uintptr(k)*16))).Fpool_index_right = tree_pool_size - int32(2)
  40721 				tree_size = tree_size + int32(1)
  40722 			}
  40723 			SetBitDepths(tls, tree, tree_pool, bit_depths, 0)
  40724 		} else {
  40725 			if tree_size == int32(1) { // Trivial case: only one element.
  40726 				**(**uint8_t)(__ccgo_up(bit_depths + uintptr((**(**HuffmanTree)(__ccgo_up(tree))).Fvalue))) = uint8(1)
  40727 			}
  40728 		}
  40729 		// Test if this Huffman tree satisfies our 'tree_depth_limit' criteria.
  40730 		max_depth = int32(**(**uint8_t)(__ccgo_up(bit_depths)))
  40731 		j = int32(1)
  40732 		for {
  40733 			if !(j < histogram_size) {
  40734 				break
  40735 			}
  40736 			if max_depth < int32(**(**uint8_t)(__ccgo_up(bit_depths + uintptr(j)))) {
  40737 				max_depth = int32(**(**uint8_t)(__ccgo_up(bit_depths + uintptr(j))))
  40738 			}
  40739 			goto _8
  40740 		_8:
  40741 			;
  40742 			j = j + 1
  40743 		}
  40744 		if max_depth <= tree_depth_limit {
  40745 			break
  40746 		}
  40747 		goto _2
  40748 	_2:
  40749 		;
  40750 		count_min = count_min * uint32(2)
  40751 	}
  40752 }
  40753 
  40754 // -----------------------------------------------------------------------------
  40755 // Coding of the Huffman tree values
  40756 
  40757 func CodeRepeatedValues(tls *libc.TLS, repetitions int32, tokens uintptr, value int32, prev_value int32) (r uintptr) {
  40758 	var i int32
  40759 	_ = i
  40760 	if value != prev_value {
  40761 		(*HuffmanTreeToken)(unsafe.Pointer(tokens)).Fcode = uint8(value)
  40762 		(*HuffmanTreeToken)(unsafe.Pointer(tokens)).Fextra_bits = uint8(0)
  40763 		tokens += 2
  40764 		repetitions = repetitions - 1
  40765 	}
  40766 	for repetitions >= int32(1) {
  40767 		if repetitions < int32(3) {
  40768 			i = 0
  40769 			for {
  40770 				if !(i < repetitions) {
  40771 					break
  40772 				}
  40773 				(*HuffmanTreeToken)(unsafe.Pointer(tokens)).Fcode = uint8(value)
  40774 				(*HuffmanTreeToken)(unsafe.Pointer(tokens)).Fextra_bits = uint8(0)
  40775 				tokens += 2
  40776 				goto _1
  40777 			_1:
  40778 				;
  40779 				i = i + 1
  40780 			}
  40781 			break
  40782 		} else {
  40783 			if repetitions < int32(7) {
  40784 				(*HuffmanTreeToken)(unsafe.Pointer(tokens)).Fcode = uint8(16)
  40785 				(*HuffmanTreeToken)(unsafe.Pointer(tokens)).Fextra_bits = uint8(repetitions - int32(3))
  40786 				tokens += 2
  40787 				break
  40788 			} else {
  40789 				(*HuffmanTreeToken)(unsafe.Pointer(tokens)).Fcode = uint8(16)
  40790 				(*HuffmanTreeToken)(unsafe.Pointer(tokens)).Fextra_bits = uint8(3)
  40791 				tokens += 2
  40792 				repetitions = repetitions - int32(6)
  40793 			}
  40794 		}
  40795 	}
  40796 	return tokens
  40797 }
  40798 
  40799 func CodeRepeatedZeros(tls *libc.TLS, repetitions int32, tokens uintptr) (r uintptr) {
  40800 	var i int32
  40801 	_ = i
  40802 	for repetitions >= int32(1) {
  40803 		if repetitions < int32(3) {
  40804 			i = 0
  40805 			for {
  40806 				if !(i < repetitions) {
  40807 					break
  40808 				}
  40809 				(*HuffmanTreeToken)(unsafe.Pointer(tokens)).Fcode = uint8(0) // 0-value
  40810 				(*HuffmanTreeToken)(unsafe.Pointer(tokens)).Fextra_bits = uint8(0)
  40811 				tokens += 2
  40812 				goto _1
  40813 			_1:
  40814 				;
  40815 				i = i + 1
  40816 			}
  40817 			break
  40818 		} else {
  40819 			if repetitions < int32(11) {
  40820 				(*HuffmanTreeToken)(unsafe.Pointer(tokens)).Fcode = uint8(17)
  40821 				(*HuffmanTreeToken)(unsafe.Pointer(tokens)).Fextra_bits = uint8(repetitions - int32(3))
  40822 				tokens += 2
  40823 				break
  40824 			} else {
  40825 				if repetitions < int32(139) {
  40826 					(*HuffmanTreeToken)(unsafe.Pointer(tokens)).Fcode = uint8(18)
  40827 					(*HuffmanTreeToken)(unsafe.Pointer(tokens)).Fextra_bits = uint8(repetitions - int32(11))
  40828 					tokens += 2
  40829 					break
  40830 				} else {
  40831 					(*HuffmanTreeToken)(unsafe.Pointer(tokens)).Fcode = uint8(18)
  40832 					(*HuffmanTreeToken)(unsafe.Pointer(tokens)).Fextra_bits = uint8(0x7f) // 138 repeated 0s
  40833 					tokens += 2
  40834 					repetitions = repetitions - int32(138)
  40835 				}
  40836 			}
  40837 		}
  40838 	}
  40839 	return tokens
  40840 }
  40841 
  40842 func VP8LCreateCompressedHuffmanTree(tls *libc.TLS, tree uintptr, tokens uintptr, max_tokens int32) (r int32) {
  40843 	var depth_size, i, k, prev_value, runs, value int32
  40844 	var ending_token, starting_token uintptr
  40845 	_, _, _, _, _, _, _, _ = depth_size, ending_token, i, k, prev_value, runs, starting_token, value
  40846 	starting_token = tokens
  40847 	ending_token = tokens + uintptr(max_tokens)*2
  40848 	depth_size = (*HuffmanTreeCode)(unsafe.Pointer(tree)).Fnum_symbols
  40849 	prev_value = int32(8) // 8 is the initial value for rle.
  40850 	i = 0
  40851 	for i < depth_size {
  40852 		value = int32(**(**uint8_t)(__ccgo_up((*HuffmanTreeCode)(unsafe.Pointer(tree)).Fcode_lengths + uintptr(i))))
  40853 		k = i + int32(1)
  40854 		for k < depth_size && int32(**(**uint8_t)(__ccgo_up((*HuffmanTreeCode)(unsafe.Pointer(tree)).Fcode_lengths + uintptr(k)))) == value {
  40855 			k = k + 1
  40856 		}
  40857 		runs = k - i
  40858 		if value == 0 {
  40859 			tokens = CodeRepeatedZeros(tls, runs, tokens)
  40860 		} else {
  40861 			tokens = CodeRepeatedValues(tls, runs, tokens, value, prev_value)
  40862 			prev_value = value
  40863 		}
  40864 		i = i + runs
  40865 	}
  40866 	_ = ending_token // suppress 'unused variable' warning
  40867 	return int32((int64(tokens) - int64(starting_token)) / 2)
  40868 }
  40869 
  40870 // -----------------------------------------------------------------------------
  40871 
  40872 // C documentation
  40873 //
  40874 //	// Pre-reversed 4-bit values.
  40875 var kReversedBits = [16]uint8_t{
  40876 	1:  uint8(0x8),
  40877 	2:  uint8(0x4),
  40878 	3:  uint8(0xc),
  40879 	4:  uint8(0x2),
  40880 	5:  uint8(0xa),
  40881 	6:  uint8(0x6),
  40882 	7:  uint8(0xe),
  40883 	8:  uint8(0x1),
  40884 	9:  uint8(0x9),
  40885 	10: uint8(0x5),
  40886 	11: uint8(0xd),
  40887 	12: uint8(0x3),
  40888 	13: uint8(0xb),
  40889 	14: uint8(0x7),
  40890 	15: uint8(0xf),
  40891 }
  40892 
  40893 func ReverseBits(tls *libc.TLS, num_bits int32, bits uint32_t) (r uint32_t) {
  40894 	var i int32
  40895 	var retval uint32_t
  40896 	_, _ = i, retval
  40897 	retval = uint32(0)
  40898 	i = 0
  40899 	for i < num_bits {
  40900 		i = i + int32(4)
  40901 		retval = retval | uint32(int32(kReversedBits[bits&uint32(0xf)])<<(libc.Int32FromInt32(MAX_ALLOWED_CODE_LENGTH)+libc.Int32FromInt32(1)-i))
  40902 		bits = bits >> uint32(4)
  40903 	}
  40904 	retval = retval >> uint32(libc.Int32FromInt32(MAX_ALLOWED_CODE_LENGTH)+libc.Int32FromInt32(1)-num_bits)
  40905 	return retval
  40906 }
  40907 
  40908 // C documentation
  40909 //
  40910 //	// Get the actual bit values for a tree of bit depths.
  40911 func ConvertBitDepthsToSymbols(tls *libc.TLS, tree uintptr) {
  40912 	bp := tls.Alloc(64)
  40913 	defer tls.Free(64)
  40914 	var code, v4 uint32_t
  40915 	var code_length, code_length1, i, len1 int32
  40916 	var depth_count [16]int32
  40917 	var v5 uintptr
  40918 	var _ /* next_code at bp+0 */ [16]uint32_t
  40919 	_, _, _, _, _, _, _, _ = code, code_length, code_length1, depth_count, i, len1, v4, v5
  40920 	depth_count = [16]int32{}
  40921 	len1 = (*HuffmanTreeCode)(unsafe.Pointer(tree)).Fnum_symbols
  40922 	i = 0
  40923 	for {
  40924 		if !(i < len1) {
  40925 			break
  40926 		}
  40927 		code_length = int32(**(**uint8_t)(__ccgo_up((*HuffmanTreeCode)(unsafe.Pointer(tree)).Fcode_lengths + uintptr(i))))
  40928 		depth_count[code_length] = depth_count[code_length] + 1
  40929 		goto _1
  40930 	_1:
  40931 		;
  40932 		i = i + 1
  40933 	}
  40934 	depth_count[0] = 0 // ignore unused symbol
  40935 	(**(**[16]uint32_t)(__ccgo_up(bp)))[0] = uint32(0)
  40936 	code = uint32(0)
  40937 	i = int32(1)
  40938 	for {
  40939 		if !(i <= int32(MAX_ALLOWED_CODE_LENGTH)) {
  40940 			break
  40941 		}
  40942 		code = (code + uint32(depth_count[i-int32(1)])) << int32(1)
  40943 		(**(**[16]uint32_t)(__ccgo_up(bp)))[i] = code
  40944 		goto _2
  40945 	_2:
  40946 		;
  40947 		i = i + 1
  40948 	}
  40949 	i = 0
  40950 	for {
  40951 		if !(i < len1) {
  40952 			break
  40953 		}
  40954 		code_length1 = int32(**(**uint8_t)(__ccgo_up((*HuffmanTreeCode)(unsafe.Pointer(tree)).Fcode_lengths + uintptr(i))))
  40955 		v5 = bp + uintptr(code_length1)*4
  40956 		v4 = *(*uint32_t)(unsafe.Pointer(v5))
  40957 		*(*uint32_t)(unsafe.Pointer(v5)) = *(*uint32_t)(unsafe.Pointer(v5)) + 1
  40958 		**(**uint16_t)(__ccgo_up((*HuffmanTreeCode)(unsafe.Pointer(tree)).Fcodes + uintptr(i)*2)) = uint16(ReverseBits(tls, code_length1, v4))
  40959 		goto _3
  40960 	_3:
  40961 		;
  40962 		i = i + 1
  40963 	}
  40964 }
  40965 
  40966 // -----------------------------------------------------------------------------
  40967 // Main entry point
  40968 
  40969 func VP8LCreateHuffmanTree(tls *libc.TLS, histogram uintptr, tree_depth_limit int32, buf_rle uintptr, huff_tree uintptr, huff_code uintptr) {
  40970 	var num_symbols int32
  40971 	_ = num_symbols
  40972 	num_symbols = (*HuffmanTreeCode)(unsafe.Pointer(huff_code)).Fnum_symbols
  40973 	libc.Xmemset(tls, buf_rle, 0, uint64(num_symbols)*uint64(1))
  40974 	OptimizeHuffmanForRle(tls, num_symbols, buf_rle, histogram)
  40975 	GenerateOptimalTree(tls, histogram, num_symbols, huff_tree, tree_depth_limit, (*HuffmanTreeCode)(unsafe.Pointer(huff_code)).Fcode_lengths)
  40976 	// Create the actual bit codes for the bit lengths.
  40977 	ConvertBitDepthsToSymbols(tls, huff_code)
  40978 }
  40979 
  40980 const MAX_HTREE_GROUPS = 0x10000
  40981 const SORTED_SIZE_CUTOFF = 512
  40982 
  40983 //------------------------------------------------------------------------------
  40984 
  40985 // Copyright 2012 Google Inc. All Rights Reserved.
  40986 //
  40987 // Use of this source code is governed by a BSD-style license
  40988 // that can be found in the COPYING file in the root of the source
  40989 // tree. An additional intellectual property rights grant can be found
  40990 // in the file PATENTS. All contributing project authors may
  40991 // be found in the AUTHORS file in the root of the source tree.
  40992 // -----------------------------------------------------------------------------
  40993 //
  40994 //  Internal header for constants related to WebP file format.
  40995 //
  40996 // Author: Urvang (urvang@google.com)
  40997 
  40998 // Copyright 2010 Google Inc. All Rights Reserved.
  40999 //
  41000 // Use of this source code is governed by a BSD-style license
  41001 // that can be found in the COPYING file in the root of the source
  41002 // tree. An additional intellectual property rights grant can be found
  41003 // in the file PATENTS. All contributing project authors may
  41004 // be found in the AUTHORS file in the root of the source tree.
  41005 // -----------------------------------------------------------------------------
  41006 //
  41007 //  Common types + memory wrappers
  41008 //
  41009 // Author: Skal (pascal.massimino@gmail.com)
  41010 
  41011 // Huffman data read via DecodeImageStream is represented in two (red and green)
  41012 // bytes.
  41013 
  41014 func VP8LHtreeGroupsNew(tls *libc.TLS, num_htree_groups int32) (r uintptr) {
  41015 	var htree_groups uintptr
  41016 	_ = htree_groups
  41017 	htree_groups = WebPSafeMalloc(tls, uint64(num_htree_groups), uint64(568))
  41018 	if htree_groups == libc.UintptrFromInt32(0) {
  41019 		return libc.UintptrFromInt32(0)
  41020 	}
  41021 	return htree_groups
  41022 }
  41023 
  41024 func VP8LHtreeGroupsFree(tls *libc.TLS, htree_groups uintptr) {
  41025 	if htree_groups != libc.UintptrFromInt32(0) {
  41026 		WebPSafeFree(tls, htree_groups)
  41027 	}
  41028 }
  41029 
  41030 // C documentation
  41031 //
  41032 //	// Returns reverse(reverse(key, len) + 1, len), where reverse(key, len) is the
  41033 //	// bit-wise reversal of the len least significant bits of key.
  41034 func GetNextKey(tls *libc.TLS, key uint32_t, len1 int32) (r uint32_t) {
  41035 	var step uint32_t
  41036 	var v1 uint32
  41037 	_, _ = step, v1
  41038 	step = uint32(int32(1) << (len1 - int32(1)))
  41039 	for key&step != 0 {
  41040 		step = step >> uint32(1)
  41041 	}
  41042 	if step != 0 {
  41043 		v1 = key&(step-uint32(1)) + step
  41044 	} else {
  41045 		v1 = key
  41046 	}
  41047 	return v1
  41048 }
  41049 
  41050 // C documentation
  41051 //
  41052 //	// Stores code in table[0], table[step], table[2*step], ..., table[end].
  41053 //	// Assumes that end is an integer multiple of step.
  41054 func ReplicateValue(tls *libc.TLS, table uintptr, step int32, end int32, code HuffmanCode) {
  41055 	for cond := true; cond; cond = end > 0 {
  41056 		end = end - step
  41057 		**(**HuffmanCode)(__ccgo_up(table + uintptr(end)*4)) = code
  41058 	}
  41059 }
  41060 
  41061 // C documentation
  41062 //
  41063 //	// Returns the table width of the next 2nd level table. count is the histogram
  41064 //	// of bit lengths for the remaining symbols, len is the code length of the next
  41065 //	// processed symbol
  41066 func NextTableBitSize(tls *libc.TLS, count uintptr, len1 int32, root_bits int32) (r int32) {
  41067 	var left int32
  41068 	_ = left
  41069 	left = int32(1) << (len1 - root_bits)
  41070 	for len1 < int32(MAX_ALLOWED_CODE_LENGTH) {
  41071 		left = left - **(**int32)(__ccgo_up(count + uintptr(len1)*4))
  41072 		if left <= 0 {
  41073 			break
  41074 		}
  41075 		len1 = len1 + 1
  41076 		left = left << int32(1)
  41077 	}
  41078 	return len1 - root_bits
  41079 }
  41080 
  41081 // C documentation
  41082 //
  41083 //	// sorted[code_lengths_size] is a pre-allocated array for sorting symbols
  41084 //	// by code length.
  41085 func BuildHuffmanTable(tls *libc.TLS, root_table uintptr, root_bits int32, code_lengths uintptr, code_lengths_size int32, sorted uintptr) (r int32) {
  41086 	bp := tls.Alloc(128)
  41087 	defer tls.Free(128)
  41088 	var code, code1, code2 HuffmanCode
  41089 	var key, low, mask uint32_t
  41090 	var len1, num_nodes, num_open, step, symbol, symbol_code_length, table_bits, table_size, total_size, v4 int32
  41091 	var table, v5 uintptr
  41092 	var _ /* count at bp+0 */ [16]int32
  41093 	var _ /* offset at bp+64 */ [16]int32
  41094 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  41095 	table = root_table                 // next available space in table
  41096 	total_size = int32(1) << root_bits // symbol index in original or sorted table
  41097 	// number of codes of each length:
  41098 	**(**[16]int32)(__ccgo_up(bp)) = [16]int32{}
  41099 	// Build histogram of code lengths.
  41100 	symbol = 0
  41101 	for {
  41102 		if !(symbol < code_lengths_size) {
  41103 			break
  41104 		}
  41105 		if **(**int32)(__ccgo_up(code_lengths + uintptr(symbol)*4)) > int32(MAX_ALLOWED_CODE_LENGTH) {
  41106 			return 0
  41107 		}
  41108 		(**(**[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
  41109 		goto _1
  41110 	_1:
  41111 		;
  41112 		symbol = symbol + 1
  41113 	}
  41114 	// Error, all code lengths are zeros.
  41115 	if (**(**[16]int32)(__ccgo_up(bp)))[0] == code_lengths_size {
  41116 		return 0
  41117 	}
  41118 	// Generate offsets into sorted symbol table by code length.
  41119 	(**(**[16]int32)(__ccgo_up(bp + 64)))[int32(1)] = 0
  41120 	len1 = int32(1)
  41121 	for {
  41122 		if !(len1 < int32(MAX_ALLOWED_CODE_LENGTH)) {
  41123 			break
  41124 		}
  41125 		if (**(**[16]int32)(__ccgo_up(bp)))[len1] > int32(1)<<len1 {
  41126 			return 0
  41127 		}
  41128 		(**(**[16]int32)(__ccgo_up(bp + 64)))[len1+int32(1)] = (**(**[16]int32)(__ccgo_up(bp + 64)))[len1] + (**(**[16]int32)(__ccgo_up(bp)))[len1]
  41129 		goto _2
  41130 	_2:
  41131 		;
  41132 		len1 = len1 + 1
  41133 	}
  41134 	// Sort symbols by length, by symbol order within each length.
  41135 	symbol = 0
  41136 	for {
  41137 		if !(symbol < code_lengths_size) {
  41138 			break
  41139 		}
  41140 		symbol_code_length = **(**int32)(__ccgo_up(code_lengths + uintptr(symbol)*4))
  41141 		if **(**int32)(__ccgo_up(code_lengths + uintptr(symbol)*4)) > 0 {
  41142 			if sorted != libc.UintptrFromInt32(0) {
  41143 				if (**(**[16]int32)(__ccgo_up(bp + 64)))[symbol_code_length] >= code_lengths_size {
  41144 					return 0
  41145 				}
  41146 				v5 = bp + 64 + uintptr(symbol_code_length)*4
  41147 				v4 = *(*int32)(unsafe.Pointer(v5))
  41148 				*(*int32)(unsafe.Pointer(v5)) = *(*int32)(unsafe.Pointer(v5)) + 1
  41149 				**(**uint16_t)(__ccgo_up(sorted + uintptr(v4)*2)) = uint16(symbol)
  41150 			} else {
  41151 				(**(**[16]int32)(__ccgo_up(bp + 64)))[symbol_code_length] = (**(**[16]int32)(__ccgo_up(bp + 64)))[symbol_code_length] + 1
  41152 			}
  41153 		}
  41154 		goto _3
  41155 	_3:
  41156 		;
  41157 		symbol = symbol + 1
  41158 	}
  41159 	// Special case code with only one value.
  41160 	if (**(**[16]int32)(__ccgo_up(bp + 64)))[int32(MAX_ALLOWED_CODE_LENGTH)] == int32(1) {
  41161 		if sorted != libc.UintptrFromInt32(0) {
  41162 			code.Fbits = uint8(0)
  41163 			code.Fvalue = **(**uint16_t)(__ccgo_up(sorted))
  41164 			ReplicateValue(tls, table, int32(1), total_size, code)
  41165 		}
  41166 		return total_size
  41167 	}
  41168 	// step size to replicate values in current table
  41169 	low = uint32(0xffffffff)             // low bits for current root entry
  41170 	mask = uint32(total_size - int32(1)) // mask for low bits
  41171 	key = uint32(0)                      // reversed prefix code
  41172 	num_nodes = int32(1)                 // number of Huffman tree nodes
  41173 	num_open = int32(1)                  // number of open branches in current tree level
  41174 	table_bits = root_bits               // key length of current table
  41175 	table_size = int32(1) << table_bits  // size of current table
  41176 	symbol = 0
  41177 	// Fill in root table.
  41178 	len1 = int32(1)
  41179 	step = libc.Int32FromInt32(2)
  41180 	for {
  41181 		if !(len1 <= root_bits) {
  41182 			break
  41183 		}
  41184 		num_open = num_open << int32(1)
  41185 		num_nodes = num_nodes + num_open
  41186 		num_open = num_open - (**(**[16]int32)(__ccgo_up(bp)))[len1]
  41187 		if num_open < 0 {
  41188 			return 0
  41189 		}
  41190 		if root_table == libc.UintptrFromInt32(0) {
  41191 			goto _6
  41192 		}
  41193 		for {
  41194 			if !((**(**[16]int32)(__ccgo_up(bp)))[len1] > 0) {
  41195 				break
  41196 			}
  41197 			code1.Fbits = uint8(len1)
  41198 			v4 = symbol
  41199 			symbol = symbol + 1
  41200 			code1.Fvalue = **(**uint16_t)(__ccgo_up(sorted + uintptr(v4)*2))
  41201 			ReplicateValue(tls, table+uintptr(key)*4, step, table_size, code1)
  41202 			key = GetNextKey(tls, key, len1)
  41203 			goto _7
  41204 		_7:
  41205 			;
  41206 			(**(**[16]int32)(__ccgo_up(bp)))[len1] = (**(**[16]int32)(__ccgo_up(bp)))[len1] - 1
  41207 		}
  41208 		goto _6
  41209 	_6:
  41210 		;
  41211 		len1 = len1 + 1
  41212 		step = step << int32(1)
  41213 	}
  41214 	// Fill in 2nd level tables and add pointers to root table.
  41215 	len1 = root_bits + int32(1)
  41216 	step = libc.Int32FromInt32(2)
  41217 	for {
  41218 		if !(len1 <= int32(MAX_ALLOWED_CODE_LENGTH)) {
  41219 			break
  41220 		}
  41221 		num_open = num_open << int32(1)
  41222 		num_nodes = num_nodes + num_open
  41223 		num_open = num_open - (**(**[16]int32)(__ccgo_up(bp)))[len1]
  41224 		if num_open < 0 {
  41225 			return 0
  41226 		}
  41227 		for {
  41228 			if !((**(**[16]int32)(__ccgo_up(bp)))[len1] > 0) {
  41229 				break
  41230 			}
  41231 			if key&mask != low {
  41232 				if root_table != libc.UintptrFromInt32(0) {
  41233 					table = table + uintptr(table_size)*4
  41234 				}
  41235 				table_bits = NextTableBitSize(tls, bp, len1, root_bits)
  41236 				table_size = int32(1) << table_bits
  41237 				total_size = total_size + table_size
  41238 				low = key & mask
  41239 				if root_table != libc.UintptrFromInt32(0) {
  41240 					(**(**HuffmanCode)(__ccgo_up(root_table + uintptr(low)*4))).Fbits = uint8(table_bits + root_bits)
  41241 					(**(**HuffmanCode)(__ccgo_up(root_table + uintptr(low)*4))).Fvalue = uint16((int64(table)-int64(root_table))/4 - int64(low))
  41242 				}
  41243 			}
  41244 			if root_table != libc.UintptrFromInt32(0) {
  41245 				code2.Fbits = uint8(len1 - root_bits)
  41246 				v4 = symbol
  41247 				symbol = symbol + 1
  41248 				code2.Fvalue = **(**uint16_t)(__ccgo_up(sorted + uintptr(v4)*2))
  41249 				ReplicateValue(tls, table+uintptr(key>>root_bits)*4, step, table_size, code2)
  41250 			}
  41251 			key = GetNextKey(tls, key, len1)
  41252 			goto _10
  41253 		_10:
  41254 			;
  41255 			(**(**[16]int32)(__ccgo_up(bp)))[len1] = (**(**[16]int32)(__ccgo_up(bp)))[len1] - 1
  41256 		}
  41257 		goto _9
  41258 	_9:
  41259 		;
  41260 		len1 = len1 + 1
  41261 		step = step << int32(1)
  41262 	}
  41263 	// Check if tree is full.
  41264 	if num_nodes != int32(2)*(**(**[16]int32)(__ccgo_up(bp + 64)))[int32(MAX_ALLOWED_CODE_LENGTH)]-int32(1) {
  41265 		return 0
  41266 	}
  41267 	return total_size
  41268 }
  41269 
  41270 // C documentation
  41271 //
  41272 //	// Maximum code_lengths_size is 2328 (reached for 11-bit color_cache_bits).
  41273 //	// More commonly, the value is around ~280.
  41274 //	// Cut-off value for switching between heap and stack allocation.
  41275 func VP8LBuildHuffmanTable(tls *libc.TLS, root_table uintptr, root_bits int32, code_lengths uintptr, code_lengths_size int32) (r int32) {
  41276 	bp := tls.Alloc(1024)
  41277 	defer tls.Free(1024)
  41278 	var next, sorted1 uintptr
  41279 	var segment_size, total_size, v1 int32
  41280 	var _ /* sorted at bp+0 */ [512]uint16_t
  41281 	_, _, _, _, _ = next, segment_size, sorted1, total_size, v1
  41282 	total_size = BuildHuffmanTable(tls, libc.UintptrFromInt32(0), root_bits, code_lengths, code_lengths_size, libc.UintptrFromInt32(0))
  41283 	if total_size == 0 || root_table == libc.UintptrFromInt32(0) {
  41284 		return total_size
  41285 	}
  41286 	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 {
  41287 		// If 'root_table' does not have enough memory, allocate a new segment.
  41288 		// The available part of root_table->curr_segment is left unused because we
  41289 		// need a contiguous buffer.
  41290 		segment_size = (*HuffmanTablesSegment)(unsafe.Pointer((*HuffmanTables)(unsafe.Pointer(root_table)).Fcurr_segment)).Fsize
  41291 		next = WebPSafeMalloc(tls, uint64(1), uint64(32))
  41292 		if next == libc.UintptrFromInt32(0) {
  41293 			return 0
  41294 		}
  41295 		// Fill the new segment.
  41296 		// We need at least 'total_size' but if that value is small, it is better to
  41297 		// allocate a big chunk to prevent more allocations later. 'segment_size' is
  41298 		// therefore chosen (any other arbitrary value could be chosen).
  41299 		if total_size > segment_size {
  41300 			v1 = total_size
  41301 		} else {
  41302 			v1 = segment_size
  41303 		}
  41304 		(*HuffmanTablesSegment)(unsafe.Pointer(next)).Fsize = v1
  41305 		(*HuffmanTablesSegment)(unsafe.Pointer(next)).Fstart = WebPSafeMalloc(tls, uint64((*HuffmanTablesSegment)(unsafe.Pointer(next)).Fsize), uint64(4))
  41306 		if (*HuffmanTablesSegment)(unsafe.Pointer(next)).Fstart == libc.UintptrFromInt32(0) {
  41307 			WebPSafeFree(tls, next)
  41308 			return 0
  41309 		}
  41310 		(*HuffmanTablesSegment)(unsafe.Pointer(next)).Fcurr_table = (*HuffmanTablesSegment)(unsafe.Pointer(next)).Fstart
  41311 		(*HuffmanTablesSegment)(unsafe.Pointer(next)).Fnext = libc.UintptrFromInt32(0)
  41312 		// Point to the new segment.
  41313 		(*HuffmanTablesSegment)(unsafe.Pointer((*HuffmanTables)(unsafe.Pointer(root_table)).Fcurr_segment)).Fnext = next
  41314 		(*HuffmanTables)(unsafe.Pointer(root_table)).Fcurr_segment = next
  41315 	}
  41316 	if code_lengths_size <= int32(SORTED_SIZE_CUTOFF) {
  41317 		BuildHuffmanTable(tls, (*HuffmanTablesSegment)(unsafe.Pointer((*HuffmanTables)(unsafe.Pointer(root_table)).Fcurr_segment)).Fcurr_table, root_bits, code_lengths, code_lengths_size, bp)
  41318 	} else { // rare case. Use heap allocation.
  41319 		sorted1 = WebPSafeMalloc(tls, uint64(code_lengths_size), uint64(2))
  41320 		if sorted1 == libc.UintptrFromInt32(0) {
  41321 			return 0
  41322 		}
  41323 		BuildHuffmanTable(tls, (*HuffmanTablesSegment)(unsafe.Pointer((*HuffmanTables)(unsafe.Pointer(root_table)).Fcurr_segment)).Fcurr_table, root_bits, code_lengths, code_lengths_size, sorted1)
  41324 		WebPSafeFree(tls, sorted1)
  41325 	}
  41326 	return total_size
  41327 }
  41328 
  41329 func VP8LHuffmanTablesAllocate(tls *libc.TLS, size int32, huffman_tables uintptr) (r int32) {
  41330 	var root uintptr
  41331 	_ = root
  41332 	// Have 'segment' point to the first segment for now, 'root'.
  41333 	root = huffman_tables
  41334 	(*HuffmanTables)(unsafe.Pointer(huffman_tables)).Fcurr_segment = root
  41335 	(*HuffmanTablesSegment)(unsafe.Pointer(root)).Fnext = libc.UintptrFromInt32(0)
  41336 	// Allocate root.
  41337 	(*HuffmanTablesSegment)(unsafe.Pointer(root)).Fstart = WebPSafeMalloc(tls, uint64(size), uint64(4))
  41338 	if (*HuffmanTablesSegment)(unsafe.Pointer(root)).Fstart == libc.UintptrFromInt32(0) {
  41339 		return 0
  41340 	}
  41341 	(*HuffmanTablesSegment)(unsafe.Pointer(root)).Fcurr_table = (*HuffmanTablesSegment)(unsafe.Pointer(root)).Fstart
  41342 	(*HuffmanTablesSegment)(unsafe.Pointer(root)).Fsize = size
  41343 	return int32(1)
  41344 }
  41345 
  41346 func VP8LHuffmanTablesDeallocate(tls *libc.TLS, huffman_tables uintptr) {
  41347 	var current, next uintptr
  41348 	_, _ = current, next
  41349 	if huffman_tables == libc.UintptrFromInt32(0) {
  41350 		return
  41351 	}
  41352 	// Free the root node.
  41353 	current = huffman_tables
  41354 	next = (*HuffmanTablesSegment)(unsafe.Pointer(current)).Fnext
  41355 	WebPSafeFree(tls, (*HuffmanTablesSegment)(unsafe.Pointer(current)).Fstart)
  41356 	(*HuffmanTablesSegment)(unsafe.Pointer(current)).Fstart = libc.UintptrFromInt32(0)
  41357 	(*HuffmanTablesSegment)(unsafe.Pointer(current)).Fnext = libc.UintptrFromInt32(0)
  41358 	current = next
  41359 	// Free the following nodes.
  41360 	for current != libc.UintptrFromInt32(0) {
  41361 		next = (*HuffmanTablesSegment)(unsafe.Pointer(current)).Fnext
  41362 		WebPSafeFree(tls, (*HuffmanTablesSegment)(unsafe.Pointer(current)).Fstart)
  41363 		WebPSafeFree(tls, current)
  41364 		current = next
  41365 	}
  41366 }
  41367 
  41368 const SIZE_MAX19 = "UINT64_MAX"
  41369 
  41370 var kHashMul13 = uint32(0x1e35a7bd)
  41371 
  41372 // Alpha related constants.
  41373 
  41374 // Mux related constants.
  41375 
  41376 // Maximum chunk payload is such that adding the header and padding won't
  41377 // overflow a uint32_t.
  41378 
  41379 // Copyright 2010 Google Inc. All Rights Reserved.
  41380 //
  41381 // Use of this source code is governed by a BSD-style license
  41382 // that can be found in the COPYING file in the root of the source
  41383 // tree. An additional intellectual property rights grant can be found
  41384 // in the file PATENTS. All contributing project authors may
  41385 // be found in the AUTHORS file in the root of the source tree.
  41386 // -----------------------------------------------------------------------------
  41387 //
  41388 //  Common types + memory wrappers
  41389 //
  41390 // Author: Skal (pascal.massimino@gmail.com)
  41391 
  41392 // -----------------------------------------------------------------------------
  41393 
  41394 // Palette reordering for smaller sum of deltas (and for smaller storage).
  41395 
  41396 func PaletteCompareColorsForQsort(tls *libc.TLS, p1 uintptr, p2 uintptr) (r int32) {
  41397 	bp := tls.Alloc(16)
  41398 	defer tls.Free(16)
  41399 	var a, b, v1, v3 uint32_t
  41400 	var v5 int32
  41401 	var _ /* A at bp+0 */ uint32_t
  41402 	_, _, _, _, _ = a, b, v1, v3, v5
  41403 	libc.Xmemcpy(tls, bp, p1, uint64(4))
  41404 	v1 = **(**uint32_t)(__ccgo_up(bp))
  41405 	goto _2
  41406 _2:
  41407 	a = v1
  41408 	libc.Xmemcpy(tls, bp, p2, uint64(4))
  41409 	v3 = **(**uint32_t)(__ccgo_up(bp))
  41410 	goto _4
  41411 _4:
  41412 	b = v3
  41413 	if a < b {
  41414 		v5 = -int32(1)
  41415 	} else {
  41416 		v5 = int32(1)
  41417 	}
  41418 	return v5
  41419 }
  41420 
  41421 func PaletteComponentDistance(tls *libc.TLS, v uint32_t) (r uint32_t) {
  41422 	var v1 uint32
  41423 	_ = v1
  41424 	if v <= uint32(128) {
  41425 		v1 = v
  41426 	} else {
  41427 		v1 = uint32(256) - v
  41428 	}
  41429 	return v1
  41430 }
  41431 
  41432 // C documentation
  41433 //
  41434 //	// Computes a value that is related to the entropy created by the
  41435 //	// palette entry diff.
  41436 //	//
  41437 //	// Note that the last & 0xff is a no-operation in the next statement, but
  41438 //	// removed by most compilers and is here only for regularity of the code.
  41439 func PaletteColorDistance(tls *libc.TLS, col1 uint32_t, col2 uint32_t) (r uint32_t) {
  41440 	var alpha_and_green, diff, red_and_blue, score, v1, v2, v3 uint32_t
  41441 	var kMoreWeightForRGBThanForAlpha int32
  41442 	_, _, _, _, _, _, _, _ = alpha_and_green, diff, kMoreWeightForRGBThanForAlpha, red_and_blue, score, v1, v2, v3
  41443 	v1 = col1
  41444 	v2 = col2
  41445 	alpha_and_green = uint32(0x00ff00ff) + v1&uint32(0xff00ff00) - v2&uint32(0xff00ff00)
  41446 	red_and_blue = uint32(0xff00ff00) + v1&uint32(0x00ff00ff) - v2&uint32(0x00ff00ff)
  41447 	v3 = alpha_and_green&uint32(0xff00ff00) | red_and_blue&uint32(0x00ff00ff)
  41448 	goto _4
  41449 _4:
  41450 	diff = v3
  41451 	kMoreWeightForRGBThanForAlpha = int32(9)
  41452 	score = PaletteComponentDistance(tls, diff>>libc.Int32FromInt32(0)&uint32(0xff))
  41453 	score = score + PaletteComponentDistance(tls, diff>>libc.Int32FromInt32(8)&uint32(0xff))
  41454 	score = score + PaletteComponentDistance(tls, diff>>libc.Int32FromInt32(16)&uint32(0xff))
  41455 	score = score * uint32(kMoreWeightForRGBThanForAlpha)
  41456 	score = score + PaletteComponentDistance(tls, diff>>libc.Int32FromInt32(24)&uint32(0xff))
  41457 	return score
  41458 }
  41459 
  41460 func SwapColor(tls *libc.TLS, col1 uintptr, col2 uintptr) {
  41461 	var tmp uint32_t
  41462 	_ = tmp
  41463 	tmp = **(**uint32_t)(__ccgo_up(col1))
  41464 	**(**uint32_t)(__ccgo_up(col1)) = **(**uint32_t)(__ccgo_up(col2))
  41465 	**(**uint32_t)(__ccgo_up(col2)) = tmp
  41466 }
  41467 
  41468 func SearchColorNoIdx(tls *libc.TLS, sorted uintptr, color uint32_t, num_colors int32) (r int32) {
  41469 	var hi, low, mid int32
  41470 	_, _, _ = hi, low, mid
  41471 	low = 0
  41472 	hi = num_colors
  41473 	if **(**uint32_t)(__ccgo_up(sorted + uintptr(low)*4)) == color {
  41474 		return low
  41475 	} // loop invariant: sorted[low] != color
  41476 	for int32(1) != 0 {
  41477 		mid = (low + hi) >> int32(1)
  41478 		if **(**uint32_t)(__ccgo_up(sorted + uintptr(mid)*4)) == color {
  41479 			return mid
  41480 		} else {
  41481 			if **(**uint32_t)(__ccgo_up(sorted + uintptr(mid)*4)) < color {
  41482 				low = mid
  41483 			} else {
  41484 				hi = mid
  41485 			}
  41486 		}
  41487 	}
  41488 	return 0
  41489 }
  41490 
  41491 func PrepareMapToPalette(tls *libc.TLS, palette uintptr, num_colors uint32_t, sorted uintptr, idx_map uintptr) {
  41492 	var i uint32_t
  41493 	_ = i
  41494 	libc.Xmemcpy(tls, sorted, palette, uint64(num_colors)*uint64(4))
  41495 	libc.Xqsort(tls, sorted, uint64(num_colors), uint64(4), __ccgo_fp(PaletteCompareColorsForQsort))
  41496 	i = uint32(0)
  41497 	for {
  41498 		if !(i < num_colors) {
  41499 			break
  41500 		}
  41501 		**(**uint32_t)(__ccgo_up(idx_map + uintptr(SearchColorNoIdx(tls, sorted, **(**uint32_t)(__ccgo_up(palette + uintptr(i)*4)), int32(num_colors)))*4)) = i
  41502 		goto _1
  41503 	_1:
  41504 		;
  41505 		i = i + 1
  41506 	}
  41507 }
  41508 
  41509 //------------------------------------------------------------------------------
  41510 
  41511 func GetColorPalette(tls *libc.TLS, pic uintptr, palette uintptr) (r int32) {
  41512 	var argb1 uintptr
  41513 	var colors [1024]uint32_t
  41514 	var height, i, key, num_colors, width, x, y, v3 int32
  41515 	var in_use [1024]uint8_t
  41516 	var last_pix uint32_t
  41517 	_, _, _, _, _, _, _, _, _, _, _, _ = argb1, colors, height, i, in_use, key, last_pix, num_colors, width, x, y, v3
  41518 	num_colors = 0
  41519 	in_use = [1024]uint8_t{}
  41520 	colors = [1024]uint32_t{}
  41521 	argb1 = (*WebPPicture)(unsafe.Pointer(pic)).Fargb
  41522 	width = (*WebPPicture)(unsafe.Pointer(pic)).Fwidth
  41523 	height = (*WebPPicture)(unsafe.Pointer(pic)).Fheight
  41524 	last_pix = ^**(**uint32_t)(__ccgo_up(argb1)) // so we're sure that last_pix != argb[0]
  41525 	y = 0
  41526 	for {
  41527 		if !(y < height) {
  41528 			break
  41529 		}
  41530 		x = 0
  41531 		for {
  41532 			if !(x < width) {
  41533 				break
  41534 			}
  41535 			if **(**uint32_t)(__ccgo_up(argb1 + uintptr(x)*4)) == last_pix {
  41536 				goto _2
  41537 			}
  41538 			last_pix = **(**uint32_t)(__ccgo_up(argb1 + uintptr(x)*4))
  41539 			v3 = int32(last_pix * kHashMul13 >> int32(22))
  41540 			goto _4
  41541 		_4:
  41542 			key = v3
  41543 			for int32(1) != 0 {
  41544 				if !(in_use[key] != 0) {
  41545 					colors[key] = last_pix
  41546 					in_use[key] = uint8(1)
  41547 					num_colors = num_colors + 1
  41548 					if num_colors > int32(MAX_PALETTE_SIZE) {
  41549 						return libc.Int32FromInt32(MAX_PALETTE_SIZE) + libc.Int32FromInt32(1) // Exact count not needed.
  41550 					}
  41551 					break
  41552 				} else {
  41553 					if colors[key] == last_pix {
  41554 						break // The color is already there.
  41555 					} else {
  41556 						// Some other color sits here, so do linear conflict resolution.
  41557 						key = key + 1
  41558 						key = key & (libc.Int32FromInt32(MAX_PALETTE_SIZE)*libc.Int32FromInt32(4) - libc.Int32FromInt32(1)) // Key mask.
  41559 					}
  41560 				}
  41561 			}
  41562 			goto _2
  41563 		_2:
  41564 			;
  41565 			x = x + 1
  41566 		}
  41567 		argb1 = argb1 + uintptr((*WebPPicture)(unsafe.Pointer(pic)).Fargb_stride)*4
  41568 		goto _1
  41569 	_1:
  41570 		;
  41571 		y = y + 1
  41572 	}
  41573 	if palette != libc.UintptrFromInt32(0) { // Fill the colors into palette.
  41574 		num_colors = 0
  41575 		i = 0
  41576 		for {
  41577 			if !(i < libc.Int32FromInt32(MAX_PALETTE_SIZE)*libc.Int32FromInt32(4)) {
  41578 				break
  41579 			}
  41580 			if in_use[i] != 0 {
  41581 				**(**uint32_t)(__ccgo_up(palette + uintptr(num_colors)*4)) = colors[i]
  41582 				num_colors = num_colors + 1
  41583 			}
  41584 			goto _5
  41585 		_5:
  41586 			;
  41587 			i = i + 1
  41588 		}
  41589 		libc.Xqsort(tls, palette, uint64(num_colors), uint64(4), __ccgo_fp(PaletteCompareColorsForQsort))
  41590 	}
  41591 	return num_colors
  41592 }
  41593 
  41594 // -----------------------------------------------------------------------------
  41595 
  41596 // C documentation
  41597 //
  41598 //	// The palette has been sorted by alpha. This function checks if the other
  41599 //	// components of the palette have a monotonic development with regards to
  41600 //	// position in the palette. If all have monotonic development, there is
  41601 //	// no benefit to re-organize them greedily. A monotonic development
  41602 //	// would be spotted in green-only situations (like lossy alpha) or gray-scale
  41603 //	// images.
  41604 func PaletteHasNonMonotonousDeltas(tls *libc.TLS, palette uintptr, num_colors int32) (r int32) {
  41605 	var alpha_and_green, diff, predict, red_and_blue, v2, v3, v4 uint32_t
  41606 	var bd, gd, rd, sign_found uint8_t
  41607 	var i, v6 int32
  41608 	_, _, _, _, _, _, _, _, _, _, _, _, _ = alpha_and_green, bd, diff, gd, i, predict, rd, red_and_blue, sign_found, v2, v3, v4, v6
  41609 	predict = uint32(0x000000)
  41610 	sign_found = uint8(0x00)
  41611 	i = 0
  41612 	for {
  41613 		if !(i < num_colors) {
  41614 			break
  41615 		}
  41616 		v2 = **(**uint32_t)(__ccgo_up(palette + uintptr(i)*4))
  41617 		v3 = predict
  41618 		alpha_and_green = uint32(0x00ff00ff) + v2&uint32(0xff00ff00) - v3&uint32(0xff00ff00)
  41619 		red_and_blue = uint32(0xff00ff00) + v2&uint32(0x00ff00ff) - v3&uint32(0x00ff00ff)
  41620 		v4 = alpha_and_green&uint32(0xff00ff00) | red_and_blue&uint32(0x00ff00ff)
  41621 		goto _5
  41622 	_5:
  41623 		diff = v4
  41624 		rd = uint8(diff >> libc.Int32FromInt32(16) & uint32(0xff))
  41625 		gd = uint8(diff >> libc.Int32FromInt32(8) & uint32(0xff))
  41626 		bd = uint8(diff >> libc.Int32FromInt32(0) & uint32(0xff))
  41627 		if int32(rd) != 0x00 {
  41628 			if int32(rd) < int32(0x80) {
  41629 				v6 = int32(1)
  41630 			} else {
  41631 				v6 = int32(2)
  41632 			}
  41633 			sign_found = uint8(int32(sign_found) | v6)
  41634 		}
  41635 		if int32(gd) != 0x00 {
  41636 			if int32(gd) < int32(0x80) {
  41637 				v6 = int32(8)
  41638 			} else {
  41639 				v6 = int32(16)
  41640 			}
  41641 			sign_found = uint8(int32(sign_found) | v6)
  41642 		}
  41643 		if int32(bd) != 0x00 {
  41644 			if int32(bd) < int32(0x80) {
  41645 				v6 = int32(64)
  41646 			} else {
  41647 				v6 = int32(128)
  41648 			}
  41649 			sign_found = uint8(int32(sign_found) | v6)
  41650 		}
  41651 		predict = **(**uint32_t)(__ccgo_up(palette + uintptr(i)*4))
  41652 		goto _1
  41653 	_1:
  41654 		;
  41655 		i = i + 1
  41656 	}
  41657 	return libc.BoolInt32(int32(sign_found)&(int32(sign_found)<<int32(1)) != 0) // two consequent signs.
  41658 }
  41659 
  41660 func PaletteSortMinimizeDeltas(tls *libc.TLS, palette_sorted uintptr, num_colors int32, palette uintptr) {
  41661 	var best_ix, i, k int32
  41662 	var best_score, cur_score, predict uint32_t
  41663 	_, _, _, _, _, _ = best_ix, best_score, cur_score, i, k, predict
  41664 	predict = uint32(0x00000000)
  41665 	libc.Xmemcpy(tls, palette, palette_sorted, uint64(num_colors)*uint64(4))
  41666 	if !(PaletteHasNonMonotonousDeltas(tls, palette_sorted, num_colors) != 0) {
  41667 		return
  41668 	}
  41669 	// Find greedily always the closest color of the predicted color to minimize
  41670 	// deltas in the palette. This reduces storage needs since the
  41671 	// palette is stored with delta encoding.
  41672 	if num_colors > int32(17) {
  41673 		if **(**uint32_t)(__ccgo_up(palette)) == uint32(0) {
  41674 			num_colors = num_colors - 1
  41675 			SwapColor(tls, palette+uintptr(num_colors)*4, palette)
  41676 		}
  41677 	}
  41678 	i = 0
  41679 	for {
  41680 		if !(i < num_colors) {
  41681 			break
  41682 		}
  41683 		best_ix = i
  41684 		best_score = ^libc.Uint32FromUint32(0)
  41685 		k = i
  41686 		for {
  41687 			if !(k < num_colors) {
  41688 				break
  41689 			}
  41690 			cur_score = PaletteColorDistance(tls, **(**uint32_t)(__ccgo_up(palette + uintptr(k)*4)), predict)
  41691 			if best_score > cur_score {
  41692 				best_score = cur_score
  41693 				best_ix = k
  41694 			}
  41695 			goto _2
  41696 		_2:
  41697 			;
  41698 			k = k + 1
  41699 		}
  41700 		SwapColor(tls, palette+uintptr(best_ix)*4, palette+uintptr(i)*4)
  41701 		predict = **(**uint32_t)(__ccgo_up(palette + uintptr(i)*4))
  41702 		goto _1
  41703 	_1:
  41704 		;
  41705 		i = i + 1
  41706 	}
  41707 }
  41708 
  41709 // -----------------------------------------------------------------------------
  41710 // Modified Zeng method from "A Survey on Palette Reordering
  41711 // Methods for Improving the Compression of Color-Indexed Images" by Armando J.
  41712 // Pinho and Antonio J. R. Neves.
  41713 
  41714 // C documentation
  41715 //
  41716 //	// Finds the biggest cooccurrence in the matrix.
  41717 func CoOccurrenceFindMax(tls *libc.TLS, cooccurrence uintptr, num_colors uint32_t, c1 uintptr, c2 uintptr) {
  41718 	var best_cooccurrence, best_sum, i, j, sum uint32_t
  41719 	_, _, _, _, _ = best_cooccurrence, best_sum, i, j, sum
  41720 	// Find the index that is most frequently located adjacent to other
  41721 	// (different) indexes.
  41722 	best_sum = 0
  41723 	**(**uint8_t)(__ccgo_up(c1)) = 0
  41724 	i = uint32(0)
  41725 	for {
  41726 		if !(i < num_colors) {
  41727 			break
  41728 		}
  41729 		sum = uint32(0)
  41730 		j = uint32(0)
  41731 		for {
  41732 			if !(j < num_colors) {
  41733 				break
  41734 			}
  41735 			sum = sum + **(**uint32_t)(__ccgo_up(cooccurrence + uintptr(i*num_colors+j)*4))
  41736 			goto _2
  41737 		_2:
  41738 			;
  41739 			j = j + 1
  41740 		}
  41741 		if sum > best_sum {
  41742 			best_sum = sum
  41743 			**(**uint8_t)(__ccgo_up(c1)) = uint8(i)
  41744 		}
  41745 		goto _1
  41746 	_1:
  41747 		;
  41748 		i = i + 1
  41749 	}
  41750 	// Find the index that is most frequently found adjacent to *c1.
  41751 	**(**uint8_t)(__ccgo_up(c2)) = 0
  41752 	best_cooccurrence = 0
  41753 	i = uint32(0)
  41754 	for {
  41755 		if !(i < num_colors) {
  41756 			break
  41757 		}
  41758 		if **(**uint32_t)(__ccgo_up(cooccurrence + uintptr(uint32(**(**uint8_t)(__ccgo_up(c1)))*num_colors+i)*4)) > best_cooccurrence {
  41759 			best_cooccurrence = **(**uint32_t)(__ccgo_up(cooccurrence + uintptr(uint32(**(**uint8_t)(__ccgo_up(c1)))*num_colors+i)*4))
  41760 			**(**uint8_t)(__ccgo_up(c2)) = uint8(i)
  41761 		}
  41762 		goto _3
  41763 	_3:
  41764 		;
  41765 		i = i + 1
  41766 	}
  41767 }
  41768 
  41769 // C documentation
  41770 //
  41771 //	// Builds the cooccurrence matrix
  41772 func CoOccurrenceBuild(tls *libc.TLS, pic uintptr, palette uintptr, num_colors uint32_t, cooccurrence uintptr) (r int32) {
  41773 	bp := tls.Alloc(2048)
  41774 	defer tls.Free(2048)
  41775 	var left_idx, pix, prev_idx, prev_pix, top_idx uint32_t
  41776 	var line_current, line_tmp, line_top, lines, src uintptr
  41777 	var x, y int32
  41778 	var _ /* idx_map at bp+0 */ [256]uint32_t
  41779 	var _ /* palette_sorted at bp+1024 */ [256]uint32_t
  41780 	_, _, _, _, _, _, _, _, _, _, _, _ = left_idx, line_current, line_tmp, line_top, lines, pix, prev_idx, prev_pix, src, top_idx, x, y
  41781 	src = (*WebPPicture)(unsafe.Pointer(pic)).Fargb
  41782 	prev_pix = ^**(**uint32_t)(__ccgo_up(src))
  41783 	prev_idx = 0
  41784 	**(**[256]uint32_t)(__ccgo_up(bp)) = [256]uint32_t{}
  41785 	lines = WebPSafeMalloc(tls, uint64(int32(2)*(*WebPPicture)(unsafe.Pointer(pic)).Fwidth), uint64(4))
  41786 	if lines == libc.UintptrFromInt32(0) {
  41787 		return 0
  41788 	}
  41789 	line_top = lines
  41790 	line_current = lines + uintptr((*WebPPicture)(unsafe.Pointer(pic)).Fwidth)*4
  41791 	PrepareMapToPalette(tls, palette, num_colors, bp+1024, bp)
  41792 	y = 0
  41793 	for {
  41794 		if !(y < (*WebPPicture)(unsafe.Pointer(pic)).Fheight) {
  41795 			break
  41796 		}
  41797 		x = 0
  41798 		for {
  41799 			if !(x < (*WebPPicture)(unsafe.Pointer(pic)).Fwidth) {
  41800 				break
  41801 			}
  41802 			pix = **(**uint32_t)(__ccgo_up(src + uintptr(x)*4))
  41803 			if pix != prev_pix {
  41804 				prev_idx = (**(**[256]uint32_t)(__ccgo_up(bp)))[SearchColorNoIdx(tls, bp+1024, pix, int32(num_colors))]
  41805 				prev_pix = pix
  41806 			}
  41807 			**(**uint32_t)(__ccgo_up(line_current + uintptr(x)*4)) = prev_idx
  41808 			// 4-connectivity is what works best as mentioned in "On the relation
  41809 			// between Memon's and the modified Zeng's palette reordering methods".
  41810 			if x > 0 && prev_idx != **(**uint32_t)(__ccgo_up(line_current + uintptr(x-int32(1))*4)) {
  41811 				left_idx = **(**uint32_t)(__ccgo_up(line_current + uintptr(x-int32(1))*4))
  41812 				**(**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
  41813 				**(**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
  41814 			}
  41815 			if y > 0 && prev_idx != **(**uint32_t)(__ccgo_up(line_top + uintptr(x)*4)) {
  41816 				top_idx = **(**uint32_t)(__ccgo_up(line_top + uintptr(x)*4))
  41817 				**(**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
  41818 				**(**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
  41819 			}
  41820 			goto _2
  41821 		_2:
  41822 			;
  41823 			x = x + 1
  41824 		}
  41825 		line_tmp = line_top
  41826 		line_top = line_current
  41827 		line_current = line_tmp
  41828 		src = src + uintptr((*WebPPicture)(unsafe.Pointer(pic)).Fargb_stride)*4
  41829 		goto _1
  41830 	_1:
  41831 		;
  41832 		y = y + 1
  41833 	}
  41834 	WebPSafeFree(tls, lines)
  41835 	return int32(1)
  41836 }
  41837 
  41838 type Sum = struct {
  41839 	Findex uint8_t
  41840 	Fsum   uint32_t
  41841 }
  41842 
  41843 func PaletteSortModifiedZeng(tls *libc.TLS, pic uintptr, palette_in uintptr, num_colors uint32_t, palette uintptr) (r int32) {
  41844 	bp := tls.Alloc(2304)
  41845 	defer tls.Free(2304)
  41846 	var best_index uint8_t
  41847 	var best_sum, cooccurrence uintptr
  41848 	var delta, n int32_t
  41849 	var first, i, ind, j, last, num_sums uint32_t
  41850 	var l_j uint16_t
  41851 	var v3 uint32
  41852 	var _ /* remapping at bp+0 */ [256]uint8_t
  41853 	var _ /* sums at bp+256 */ [256]Sum
  41854 	_, _, _, _, _, _, _, _, _, _, _, _, _ = best_index, best_sum, cooccurrence, delta, first, i, ind, j, l_j, last, n, num_sums, v3
  41855 	// TODO(vrabaud) check whether one color images should use palette or not.
  41856 	if num_colors <= uint32(1) {
  41857 		return int32(1)
  41858 	}
  41859 	// Build the co-occurrence matrix.
  41860 	cooccurrence = WebPSafeCalloc(tls, uint64(num_colors*num_colors), uint64(4))
  41861 	if cooccurrence == libc.UintptrFromInt32(0) {
  41862 		return 0
  41863 	}
  41864 	if !(CoOccurrenceBuild(tls, pic, palette_in, num_colors, cooccurrence) != 0) {
  41865 		WebPSafeFree(tls, cooccurrence)
  41866 		return 0
  41867 	}
  41868 	// Initialize the mapping list with the two best indices.
  41869 	CoOccurrenceFindMax(tls, cooccurrence, num_colors, bp, bp+1)
  41870 	// We need to append and prepend to the list of remapping. To this end, we
  41871 	// actually define the next start/end of the list as indices in a vector (with
  41872 	// a wrap around when the end is reached).
  41873 	first = uint32(0)
  41874 	last = uint32(1)
  41875 	num_sums = num_colors - uint32(2) // -2 because we know the first two values
  41876 	if num_sums > uint32(0) {
  41877 		// Initialize the sums with the first two remappings and find the best one
  41878 		best_sum = bp + 256
  41879 		(*Sum)(unsafe.Pointer(best_sum)).Findex = 0
  41880 		(*Sum)(unsafe.Pointer(best_sum)).Fsum = 0
  41881 		i = uint32(0)
  41882 		j = libc.Uint32FromInt32(0)
  41883 		for {
  41884 			if !(i < num_colors) {
  41885 				break
  41886 			}
  41887 			if i == uint32((**(**[256]uint8_t)(__ccgo_up(bp)))[0]) || i == uint32((**(**[256]uint8_t)(__ccgo_up(bp)))[int32(1)]) {
  41888 				goto _1
  41889 			}
  41890 			(**(**[256]Sum)(__ccgo_up(bp + 256)))[j].Findex = uint8(i)
  41891 			(**(**[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))
  41892 			if (**(**[256]Sum)(__ccgo_up(bp + 256)))[j].Fsum > (*Sum)(unsafe.Pointer(best_sum)).Fsum {
  41893 				best_sum = bp + 256 + uintptr(j)*8
  41894 			}
  41895 			j = j + 1
  41896 			goto _1
  41897 		_1:
  41898 			;
  41899 			i = i + 1
  41900 		}
  41901 		for num_sums > uint32(0) {
  41902 			best_index = (*Sum)(unsafe.Pointer(best_sum)).Findex
  41903 			// Compute delta to know if we need to prepend or append the best index.
  41904 			delta = 0
  41905 			n = int32(num_colors - num_sums)
  41906 			ind = first
  41907 			j = libc.Uint32FromInt32(0)
  41908 			for {
  41909 				if !((ind+j)%num_colors != last+uint32(1)) {
  41910 					break
  41911 				}
  41912 				l_j = uint16((**(**[256]uint8_t)(__ccgo_up(bp)))[(ind+j)%num_colors])
  41913 				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)))
  41914 				goto _2
  41915 			_2:
  41916 				;
  41917 				j = j + 1
  41918 			}
  41919 			if delta > 0 {
  41920 				if first == uint32(0) {
  41921 					v3 = num_colors - uint32(1)
  41922 				} else {
  41923 					v3 = first - uint32(1)
  41924 				}
  41925 				first = v3
  41926 				(**(**[256]uint8_t)(__ccgo_up(bp)))[first] = best_index
  41927 			} else {
  41928 				last = last + 1
  41929 				(**(**[256]uint8_t)(__ccgo_up(bp)))[last] = best_index
  41930 			}
  41931 			// Remove best_sum from sums.
  41932 			**(**Sum)(__ccgo_up(best_sum)) = (**(**[256]Sum)(__ccgo_up(bp + 256)))[num_sums-uint32(1)]
  41933 			num_sums = num_sums - 1
  41934 			// Update all the sums and find the best one.
  41935 			best_sum = bp + 256
  41936 			i = uint32(0)
  41937 			for {
  41938 				if !(i < num_sums) {
  41939 					break
  41940 				}
  41941 				(**(**[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))
  41942 				if (**(**[256]Sum)(__ccgo_up(bp + 256)))[i].Fsum > (*Sum)(unsafe.Pointer(best_sum)).Fsum {
  41943 					best_sum = bp + 256 + uintptr(i)*8
  41944 				}
  41945 				goto _4
  41946 			_4:
  41947 				;
  41948 				i = i + 1
  41949 			}
  41950 		}
  41951 	}
  41952 	WebPSafeFree(tls, cooccurrence)
  41953 	// Re-map the palette.
  41954 	i = uint32(0)
  41955 	for {
  41956 		if !(i < num_colors) {
  41957 			break
  41958 		}
  41959 		**(**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))
  41960 		goto _5
  41961 	_5:
  41962 		;
  41963 		i = i + 1
  41964 	}
  41965 	return int32(1)
  41966 }
  41967 
  41968 // -----------------------------------------------------------------------------
  41969 
  41970 func PaletteSort(tls *libc.TLS, method PaletteSorting1, pic uintptr, palette_sorted uintptr, num_colors uint32_t, palette uintptr) (r int32) {
  41971 	switch method {
  41972 	case int32(kSortedDefault):
  41973 		if **(**uint32_t)(__ccgo_up(palette_sorted)) == uint32(0) && num_colors > uint32(17) {
  41974 			libc.Xmemcpy(tls, palette, palette_sorted+uintptr(1)*4, uint64(num_colors-libc.Uint32FromInt32(1))*uint64(4))
  41975 			**(**uint32_t)(__ccgo_up(palette + uintptr(num_colors-uint32(1))*4)) = uint32(0)
  41976 		} else {
  41977 			libc.Xmemcpy(tls, palette, palette_sorted, uint64(num_colors)*uint64(4))
  41978 		}
  41979 		return int32(1)
  41980 	case int32(kMinimizeDelta):
  41981 		PaletteSortMinimizeDeltas(tls, palette_sorted, int32(num_colors), palette)
  41982 		return int32(1)
  41983 	case int32(kModifiedZeng):
  41984 		return PaletteSortModifiedZeng(tls, pic, palette_sorted, num_colors, palette)
  41985 	case int32(kUnusedPalette):
  41986 		fallthrough
  41987 	case int32(kPaletteSortingNum):
  41988 		break
  41989 	}
  41990 	return 0
  41991 }
  41992 
  41993 const DFIX = 0
  41994 const FIX = 16
  41995 const LFIX = 2
  41996 
  41997 //------------------------------------------------------------------------------
  41998 
  41999 // Copyright 2010 Google Inc. All Rights Reserved.
  42000 //
  42001 // Use of this source code is governed by a BSD-style license
  42002 // that can be found in the COPYING file in the root of the source
  42003 // tree. An additional intellectual property rights grant can be found
  42004 // in the file PATENTS. All contributing project authors may
  42005 // be found in the AUTHORS file in the root of the source tree.
  42006 // -----------------------------------------------------------------------------
  42007 //
  42008 //  Common types + memory wrappers
  42009 //
  42010 // Author: Skal (pascal.massimino@gmail.com)
  42011 
  42012 // #define USE_DITHERING   // uncomment to enable ordered dithering (not vital)
  42013 
  42014 type SmoothParams = struct {
  42015 	Fwidth          int32
  42016 	Fheight         int32
  42017 	Fstride         int32
  42018 	Frow            int32
  42019 	Fsrc            uintptr
  42020 	Fdst            uintptr
  42021 	Fradius         int32
  42022 	Fscale          int32
  42023 	Fmem            uintptr
  42024 	Fstart          uintptr
  42025 	Fcur            uintptr
  42026 	Fend            uintptr
  42027 	Ftop            uintptr
  42028 	Faverage        uintptr
  42029 	Fnum_levels     int32
  42030 	Fmin            int32
  42031 	Fmax            int32
  42032 	Fmin_level_dist int32
  42033 	Fcorrection     uintptr
  42034 }
  42035 
  42036 //------------------------------------------------------------------------------
  42037 
  42038 func clip_8b(tls *libc.TLS, v int32) (r uint8_t) {
  42039 	var v1, v2 uint32
  42040 	_, _ = v1, v2
  42041 	if !(v&int32(^libc.Uint32FromUint32(0)<<(libc.Int32FromInt32(8)+libc.Int32FromInt32(DFIX))) != 0) {
  42042 		v1 = uint32(uint8(v >> libc.Int32FromInt32(DFIX)))
  42043 	} else {
  42044 		if v < 0 {
  42045 			v2 = 0
  42046 		} else {
  42047 			v2 = uint32(255)
  42048 		}
  42049 		v1 = v2
  42050 	}
  42051 	return uint8(v1)
  42052 }
  42053 
  42054 // C documentation
  42055 //
  42056 //	// vertical accumulation
  42057 func VFilter(tls *libc.TLS, p uintptr) {
  42058 	var cur, out, src, top uintptr
  42059 	var new_value, sum uint16_t
  42060 	var w, x int32
  42061 	_, _, _, _, _, _, _, _ = cur, new_value, out, src, sum, top, w, x
  42062 	src = (*SmoothParams)(unsafe.Pointer(p)).Fsrc
  42063 	w = (*SmoothParams)(unsafe.Pointer(p)).Fwidth
  42064 	cur = (*SmoothParams)(unsafe.Pointer(p)).Fcur
  42065 	top = (*SmoothParams)(unsafe.Pointer(p)).Ftop
  42066 	out = (*SmoothParams)(unsafe.Pointer(p)).Fend
  42067 	sum = uint16(0)
  42068 	x = 0
  42069 	for {
  42070 		if !(x < w) {
  42071 			break
  42072 		}
  42073 		sum = uint16(int32(sum) + int32(**(**uint8_t)(__ccgo_up(src + uintptr(x)))))
  42074 		new_value = uint16(int32(**(**uint16_t)(__ccgo_up(top + uintptr(x)*2))) + int32(sum))
  42075 		**(**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.
  42076 		**(**uint16_t)(__ccgo_up(cur + uintptr(x)*2)) = new_value
  42077 		goto _1
  42078 	_1:
  42079 		;
  42080 		x = x + 1
  42081 	}
  42082 	// move input pointers one row down
  42083 	(*SmoothParams)(unsafe.Pointer(p)).Ftop = (*SmoothParams)(unsafe.Pointer(p)).Fcur
  42084 	**(**uintptr)(__ccgo_up(p + 56)) += uintptr(w) * 2
  42085 	if (*SmoothParams)(unsafe.Pointer(p)).Fcur == (*SmoothParams)(unsafe.Pointer(p)).Fend {
  42086 		(*SmoothParams)(unsafe.Pointer(p)).Fcur = (*SmoothParams)(unsafe.Pointer(p)).Fstart
  42087 	} // roll-over
  42088 	// We replicate edges, as it's somewhat easier as a boundary condition.
  42089 	// That's why we don't update the 'src' pointer on top/bottom area:
  42090 	if (*SmoothParams)(unsafe.Pointer(p)).Frow >= 0 && (*SmoothParams)(unsafe.Pointer(p)).Frow < (*SmoothParams)(unsafe.Pointer(p)).Fheight-int32(1) {
  42091 		**(**uintptr)(__ccgo_up(p + 16)) += uintptr((*SmoothParams)(unsafe.Pointer(p)).Fstride)
  42092 	}
  42093 }
  42094 
  42095 // C documentation
  42096 //
  42097 //	// horizontal accumulation. We use mirror replication of missing pixels, as it's
  42098 //	// a little easier to implement (surprisingly).
  42099 func HFilter(tls *libc.TLS, p uintptr) {
  42100 	var delta, delta1, delta2 uint16_t
  42101 	var in, out uintptr
  42102 	var r, w, x int32
  42103 	var scale uint32_t
  42104 	_, _, _, _, _, _, _, _, _ = delta, delta1, delta2, in, out, r, scale, w, x
  42105 	in = (*SmoothParams)(unsafe.Pointer(p)).Fend
  42106 	out = (*SmoothParams)(unsafe.Pointer(p)).Faverage
  42107 	scale = uint32((*SmoothParams)(unsafe.Pointer(p)).Fscale)
  42108 	w = (*SmoothParams)(unsafe.Pointer(p)).Fwidth
  42109 	r = (*SmoothParams)(unsafe.Pointer(p)).Fradius
  42110 	x = 0
  42111 	for {
  42112 		if !(x <= r) {
  42113 			break
  42114 		} // left mirroring
  42115 		delta = uint16(int32(**(**uint16_t)(__ccgo_up(in + uintptr(x+r-int32(1))*2))) + int32(**(**uint16_t)(__ccgo_up(in + uintptr(r-x)*2))))
  42116 		**(**uint16_t)(__ccgo_up(out + uintptr(x)*2)) = uint16(uint32(delta) * scale >> int32(FIX))
  42117 		goto _1
  42118 	_1:
  42119 		;
  42120 		x = x + 1
  42121 	}
  42122 	for {
  42123 		if !(x < w-r) {
  42124 			break
  42125 		} // bulk middle run
  42126 		delta1 = uint16(int32(**(**uint16_t)(__ccgo_up(in + uintptr(x+r)*2))) - int32(**(**uint16_t)(__ccgo_up(in + uintptr(x-r-int32(1))*2))))
  42127 		**(**uint16_t)(__ccgo_up(out + uintptr(x)*2)) = uint16(uint32(delta1) * scale >> int32(FIX))
  42128 		goto _2
  42129 	_2:
  42130 		;
  42131 		x = x + 1
  42132 	}
  42133 	for {
  42134 		if !(x < w) {
  42135 			break
  42136 		} // right mirroring
  42137 		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))))
  42138 		**(**uint16_t)(__ccgo_up(out + uintptr(x)*2)) = uint16(uint32(delta2) * scale >> int32(FIX))
  42139 		goto _3
  42140 	_3:
  42141 		;
  42142 		x = x + 1
  42143 	}
  42144 }
  42145 
  42146 // C documentation
  42147 //
  42148 //	// emit one filtered output row
  42149 func ApplyFilter(tls *libc.TLS, p uintptr) {
  42150 	var average, correction, dst uintptr
  42151 	var c, v, w, x int32
  42152 	_, _, _, _, _, _, _ = average, c, correction, dst, v, w, x
  42153 	average = (*SmoothParams)(unsafe.Pointer(p)).Faverage
  42154 	w = (*SmoothParams)(unsafe.Pointer(p)).Fwidth
  42155 	correction = (*SmoothParams)(unsafe.Pointer(p)).Fcorrection
  42156 	dst = (*SmoothParams)(unsafe.Pointer(p)).Fdst
  42157 	x = 0
  42158 	for {
  42159 		if !(x < w) {
  42160 			break
  42161 		}
  42162 		v = int32(**(**uint8_t)(__ccgo_up(dst + uintptr(x))))
  42163 		if v < (*SmoothParams)(unsafe.Pointer(p)).Fmax && v > (*SmoothParams)(unsafe.Pointer(p)).Fmin {
  42164 			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)))
  42165 			**(**uint8_t)(__ccgo_up(dst + uintptr(x))) = clip_8b(tls, c)
  42166 		}
  42167 		goto _1
  42168 	_1:
  42169 		;
  42170 		x = x + 1
  42171 	}
  42172 	**(**uintptr)(__ccgo_up(p + 24)) += uintptr((*SmoothParams)(unsafe.Pointer(p)).Fstride) // advance output pointer
  42173 }
  42174 
  42175 //------------------------------------------------------------------------------
  42176 // Initialize correction table
  42177 
  42178 func InitCorrectionLUT(tls *libc.TLS, lut uintptr, min_dist int32) {
  42179 	var c, delta, i, max_threshold, threshold1, threshold2, v2, v3 int32
  42180 	_, _, _, _, _, _, _, _ = c, delta, i, max_threshold, threshold1, threshold2, v2, v3
  42181 	// The correction curve is:
  42182 	//   f(x) = x for x <= threshold2
  42183 	//   f(x) = 0 for x >= threshold1
  42184 	// and a linear interpolation for range x=[threshold2, threshold1]
  42185 	// (along with f(-x) = -f(x) symmetry).
  42186 	// Note that: threshold2 = 3/4 * threshold1
  42187 	threshold1 = min_dist << int32(LFIX)
  42188 	threshold2 = int32(3) * threshold1 >> int32(2)
  42189 	max_threshold = threshold2 << DFIX
  42190 	delta = threshold1 - threshold2
  42191 	i = int32(1)
  42192 	for {
  42193 		if !(i <= libc.Int32FromInt32(1)<<(libc.Int32FromInt32(8)+libc.Int32FromInt32(LFIX))-libc.Int32FromInt32(1)) {
  42194 			break
  42195 		}
  42196 		if i <= threshold2 {
  42197 			v2 = i << DFIX
  42198 		} else {
  42199 			if i < threshold1 {
  42200 				v3 = max_threshold * (threshold1 - i) / delta
  42201 			} else {
  42202 				v3 = 0
  42203 			}
  42204 			v2 = v3
  42205 		}
  42206 		c = v2
  42207 		c = c >> int32(LFIX)
  42208 		**(**int16_t)(__ccgo_up(lut + uintptr(+i)*2)) = int16(+c)
  42209 		**(**int16_t)(__ccgo_up(lut + uintptr(-i)*2)) = int16(-c)
  42210 		goto _1
  42211 	_1:
  42212 		;
  42213 		i = i + 1
  42214 	}
  42215 	**(**int16_t)(__ccgo_up(lut)) = 0
  42216 }
  42217 
  42218 func CountLevels(tls *libc.TLS, p uintptr) {
  42219 	var data uintptr
  42220 	var i, j, last_level, level_dist, v int32
  42221 	var used_levels [256]uint8_t
  42222 	_, _, _, _, _, _, _ = data, i, j, last_level, level_dist, used_levels, v
  42223 	used_levels = [256]uint8_t{}
  42224 	data = (*SmoothParams)(unsafe.Pointer(p)).Fsrc
  42225 	(*SmoothParams)(unsafe.Pointer(p)).Fmin = int32(255)
  42226 	(*SmoothParams)(unsafe.Pointer(p)).Fmax = 0
  42227 	j = 0
  42228 	for {
  42229 		if !(j < (*SmoothParams)(unsafe.Pointer(p)).Fheight) {
  42230 			break
  42231 		}
  42232 		i = 0
  42233 		for {
  42234 			if !(i < (*SmoothParams)(unsafe.Pointer(p)).Fwidth) {
  42235 				break
  42236 			}
  42237 			v = int32(**(**uint8_t)(__ccgo_up(data + uintptr(i))))
  42238 			if v < (*SmoothParams)(unsafe.Pointer(p)).Fmin {
  42239 				(*SmoothParams)(unsafe.Pointer(p)).Fmin = v
  42240 			}
  42241 			if v > (*SmoothParams)(unsafe.Pointer(p)).Fmax {
  42242 				(*SmoothParams)(unsafe.Pointer(p)).Fmax = v
  42243 			}
  42244 			used_levels[v] = uint8(1)
  42245 			goto _2
  42246 		_2:
  42247 			;
  42248 			i = i + 1
  42249 		}
  42250 		data = data + uintptr((*SmoothParams)(unsafe.Pointer(p)).Fstride)
  42251 		goto _1
  42252 	_1:
  42253 		;
  42254 		j = j + 1
  42255 	}
  42256 	// Compute the mininum distance between two non-zero levels.
  42257 	(*SmoothParams)(unsafe.Pointer(p)).Fmin_level_dist = (*SmoothParams)(unsafe.Pointer(p)).Fmax - (*SmoothParams)(unsafe.Pointer(p)).Fmin
  42258 	last_level = -int32(1)
  42259 	i = 0
  42260 	for {
  42261 		if !(i < int32(256)) {
  42262 			break
  42263 		}
  42264 		if used_levels[i] != 0 {
  42265 			(*SmoothParams)(unsafe.Pointer(p)).Fnum_levels = (*SmoothParams)(unsafe.Pointer(p)).Fnum_levels + 1
  42266 			if last_level >= 0 {
  42267 				level_dist = i - last_level
  42268 				if level_dist < (*SmoothParams)(unsafe.Pointer(p)).Fmin_level_dist {
  42269 					(*SmoothParams)(unsafe.Pointer(p)).Fmin_level_dist = level_dist
  42270 				}
  42271 			}
  42272 			last_level = i
  42273 		}
  42274 		goto _3
  42275 	_3:
  42276 		;
  42277 		i = i + 1
  42278 	}
  42279 }
  42280 
  42281 // C documentation
  42282 //
  42283 //	// Initialize all params.
  42284 func InitParams(tls *libc.TLS, data uintptr, width int32, height int32, stride int32, radius int32, p uintptr) (r int32) {
  42285 	var R int32
  42286 	var mem uintptr
  42287 	var size_lut, size_m, size_scratch_m, total_size size_t
  42288 	_, _, _, _, _, _ = R, mem, size_lut, size_m, size_scratch_m, total_size
  42289 	R = int32(2)*radius + int32(1) // total size of the kernel
  42290 	size_scratch_m = uint64((R+int32(1))*width) * uint64(2)
  42291 	size_m = uint64(width) * uint64(2)
  42292 	size_lut = uint64(libc.Int32FromInt32(1)+libc.Int32FromInt32(2)*(libc.Int32FromInt32(1)<<(libc.Int32FromInt32(8)+libc.Int32FromInt32(LFIX))-libc.Int32FromInt32(1))) * libc.Uint64FromInt64(2)
  42293 	total_size = size_scratch_m + size_m + size_lut
  42294 	mem = WebPSafeMalloc(tls, uint64(1), total_size)
  42295 	if mem == libc.UintptrFromInt32(0) {
  42296 		return 0
  42297 	}
  42298 	(*SmoothParams)(unsafe.Pointer(p)).Fmem = mem
  42299 	(*SmoothParams)(unsafe.Pointer(p)).Fstart = mem
  42300 	(*SmoothParams)(unsafe.Pointer(p)).Fcur = (*SmoothParams)(unsafe.Pointer(p)).Fstart
  42301 	(*SmoothParams)(unsafe.Pointer(p)).Fend = (*SmoothParams)(unsafe.Pointer(p)).Fstart + uintptr(R*width)*2
  42302 	(*SmoothParams)(unsafe.Pointer(p)).Ftop = (*SmoothParams)(unsafe.Pointer(p)).Fend - uintptr(width)*2
  42303 	libc.Xmemset(tls, (*SmoothParams)(unsafe.Pointer(p)).Ftop, 0, uint64(width)*uint64(2))
  42304 	mem = mem + uintptr(size_scratch_m)
  42305 	(*SmoothParams)(unsafe.Pointer(p)).Faverage = mem
  42306 	mem = mem + uintptr(size_m)
  42307 	(*SmoothParams)(unsafe.Pointer(p)).Fwidth = width
  42308 	(*SmoothParams)(unsafe.Pointer(p)).Fheight = height
  42309 	(*SmoothParams)(unsafe.Pointer(p)).Fstride = stride
  42310 	(*SmoothParams)(unsafe.Pointer(p)).Fsrc = data
  42311 	(*SmoothParams)(unsafe.Pointer(p)).Fdst = data
  42312 	(*SmoothParams)(unsafe.Pointer(p)).Fradius = radius
  42313 	(*SmoothParams)(unsafe.Pointer(p)).Fscale = libc.Int32FromInt32(1) << (libc.Int32FromInt32(FIX) + libc.Int32FromInt32(LFIX)) / (R * R) // normalization constant
  42314 	(*SmoothParams)(unsafe.Pointer(p)).Frow = -radius
  42315 	// analyze the input distribution so we can best-fit the threshold
  42316 	CountLevels(tls, p)
  42317 	// correction table
  42318 	(*SmoothParams)(unsafe.Pointer(p)).Fcorrection = mem + uintptr(libc.Int32FromInt32(1)<<(libc.Int32FromInt32(8)+libc.Int32FromInt32(LFIX))-libc.Int32FromInt32(1))*2
  42319 	InitCorrectionLUT(tls, (*SmoothParams)(unsafe.Pointer(p)).Fcorrection, (*SmoothParams)(unsafe.Pointer(p)).Fmin_level_dist)
  42320 	return int32(1)
  42321 }
  42322 
  42323 func CleanupParams(tls *libc.TLS, p uintptr) {
  42324 	WebPSafeFree(tls, (*SmoothParams)(unsafe.Pointer(p)).Fmem)
  42325 }
  42326 
  42327 func WebPDequantizeLevels(tls *libc.TLS, data uintptr, width int32, height int32, stride int32, strength int32) (r int32) {
  42328 	bp := tls.Alloc(112)
  42329 	defer tls.Free(112)
  42330 	var radius int32
  42331 	var _ /* p at bp+0 */ SmoothParams
  42332 	_ = radius
  42333 	radius = int32(4) * strength / int32(100)
  42334 	if strength < 0 || strength > int32(100) {
  42335 		return 0
  42336 	}
  42337 	if data == libc.UintptrFromInt32(0) || width <= 0 || height <= 0 {
  42338 		return 0
  42339 	} // bad params
  42340 	// limit the filter size to not exceed the image dimensions
  42341 	if int32(2)*radius+int32(1) > width {
  42342 		radius = (width - int32(1)) >> int32(1)
  42343 	}
  42344 	if int32(2)*radius+int32(1) > height {
  42345 		radius = (height - int32(1)) >> int32(1)
  42346 	}
  42347 	if radius > 0 {
  42348 		libc.Xmemset(tls, bp, 0, uint64(112))
  42349 		if !(InitParams(tls, data, width, height, stride, radius, bp) != 0) {
  42350 			return 0
  42351 		}
  42352 		if (**(**SmoothParams)(__ccgo_up(bp))).Fnum_levels > int32(2) {
  42353 			for {
  42354 				if !((**(**SmoothParams)(__ccgo_up(bp))).Frow < (**(**SmoothParams)(__ccgo_up(bp))).Fheight) {
  42355 					break
  42356 				}
  42357 				VFilter(tls, bp) // accumulate average of input
  42358 				// Need to wait few rows in order to prime the filter,
  42359 				// before emitting some output.
  42360 				if (**(**SmoothParams)(__ccgo_up(bp))).Frow >= (**(**SmoothParams)(__ccgo_up(bp))).Fradius {
  42361 					HFilter(tls, bp)
  42362 					ApplyFilter(tls, bp)
  42363 				}
  42364 				goto _1
  42365 			_1:
  42366 				;
  42367 				(**(**SmoothParams)(__ccgo_up(bp))).Frow = (**(**SmoothParams)(__ccgo_up(bp))).Frow + 1
  42368 			}
  42369 		}
  42370 		CleanupParams(tls, bp)
  42371 	}
  42372 	return int32(1)
  42373 }
  42374 
  42375 const ERROR_THRESHOLD = 0.0001
  42376 const MAX_ITER = 6
  42377 const NUM_SYMBOLS = 256
  42378 
  42379 // -----------------------------------------------------------------------------
  42380 // Quantize levels.
  42381 
  42382 func QuantizeLevels(tls *libc.TLS, data uintptr, width int32, height int32, num_levels int32, sse uintptr) (r int32) {
  42383 	bp := tls.Alloc(4096)
  42384 	defer tls.Free(4096)
  42385 	var count, err, err_threshold, error1, last_err float64
  42386 	var data_size, n, n1 size_t
  42387 	var freq, q_level [256]int32
  42388 	var i, iter, max_s, min_s, num_levels_in, s, s1, slot, slot1 int32
  42389 	var inv_q_level [256]float64
  42390 	var map1 [256]uint8_t
  42391 	var _ /* q_count at bp+2048 */ [256]float64
  42392 	var _ /* q_sum at bp+0 */ [256]float64
  42393 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  42394 	freq = [256]int32{}
  42395 	q_level = [256]int32{}
  42396 	inv_q_level = [256]float64{}
  42397 	min_s = int32(255)
  42398 	max_s = 0
  42399 	data_size = uint64(height * width)
  42400 	last_err = float64(1e+38)
  42401 	err = float64(0)
  42402 	err_threshold = float64(float64(0.0001) * float64(data_size))
  42403 	if data == libc.UintptrFromInt32(0) {
  42404 		return 0
  42405 	}
  42406 	if width <= 0 || height <= 0 {
  42407 		return 0
  42408 	}
  42409 	if num_levels < int32(2) || num_levels > int32(256) {
  42410 		return 0
  42411 	}
  42412 	num_levels_in = 0
  42413 	n = uint64(0)
  42414 	for {
  42415 		if !(n < data_size) {
  42416 			break
  42417 		}
  42418 		num_levels_in = num_levels_in + libc.BoolInt32(freq[**(**uint8_t)(__ccgo_up(data + uintptr(n)))] == 0)
  42419 		if min_s > int32(**(**uint8_t)(__ccgo_up(data + uintptr(n)))) {
  42420 			min_s = int32(**(**uint8_t)(__ccgo_up(data + uintptr(n))))
  42421 		}
  42422 		if max_s < int32(**(**uint8_t)(__ccgo_up(data + uintptr(n)))) {
  42423 			max_s = int32(**(**uint8_t)(__ccgo_up(data + uintptr(n))))
  42424 		}
  42425 		freq[**(**uint8_t)(__ccgo_up(data + uintptr(n)))] = freq[**(**uint8_t)(__ccgo_up(data + uintptr(n)))] + 1
  42426 		goto _1
  42427 	_1:
  42428 		;
  42429 		n = n + 1
  42430 	}
  42431 	if num_levels_in <= num_levels {
  42432 		goto End
  42433 	} // nothing to do!
  42434 	// Start with uniformly spread centroids.
  42435 	i = 0
  42436 	for {
  42437 		if !(i < num_levels) {
  42438 			break
  42439 		}
  42440 		inv_q_level[i] = float64(min_s) + float64(float64(max_s-min_s)*float64(i))/float64(num_levels-libc.Int32FromInt32(1))
  42441 		goto _2
  42442 	_2:
  42443 		;
  42444 		i = i + 1
  42445 	}
  42446 	// Fixed values. Won't be changed.
  42447 	q_level[min_s] = 0
  42448 	q_level[max_s] = num_levels - int32(1)
  42449 	// k-Means iterations.
  42450 	iter = 0
  42451 	for {
  42452 		if !(iter < int32(MAX_ITER)) {
  42453 			break
  42454 		}
  42455 		**(**[256]float64)(__ccgo_up(bp)) = [256]float64{}
  42456 		**(**[256]float64)(__ccgo_up(bp + 2048)) = [256]float64{}
  42457 		slot = 0
  42458 		// Assign classes to representatives.
  42459 		s = min_s
  42460 		for {
  42461 			if !(s <= max_s) {
  42462 				break
  42463 			}
  42464 			// Keep track of the nearest neighbour 'slot'
  42465 			for slot < num_levels-int32(1) && float64(int32(2)*s) > inv_q_level[slot]+inv_q_level[slot+int32(1)] {
  42466 				slot = slot + 1
  42467 			}
  42468 			if freq[s] > 0 {
  42469 				**(**float64)(__ccgo_up(bp + uintptr(slot)*8)) += float64(s * freq[s])
  42470 				**(**float64)(__ccgo_up(bp + 2048 + uintptr(slot)*8)) += float64(freq[s])
  42471 			}
  42472 			q_level[s] = slot
  42473 			goto _4
  42474 		_4:
  42475 			;
  42476 			s = s + 1
  42477 		}
  42478 		// Assign new representatives to classes.
  42479 		if num_levels > int32(2) {
  42480 			slot = int32(1)
  42481 			for {
  42482 				if !(slot < num_levels-int32(1)) {
  42483 					break
  42484 				}
  42485 				count = (**(**[256]float64)(__ccgo_up(bp + 2048)))[slot]
  42486 				if count > float64(0) {
  42487 					inv_q_level[slot] = (**(**[256]float64)(__ccgo_up(bp)))[slot] / count
  42488 				}
  42489 				goto _5
  42490 			_5:
  42491 				;
  42492 				slot = slot + 1
  42493 			}
  42494 		}
  42495 		// Compute convergence error.
  42496 		err = float64(0)
  42497 		s = min_s
  42498 		for {
  42499 			if !(s <= max_s) {
  42500 				break
  42501 			}
  42502 			error1 = float64(s) - inv_q_level[q_level[s]]
  42503 			err = err + float64(float64(float64(freq[s])*error1)*error1)
  42504 			goto _6
  42505 		_6:
  42506 			;
  42507 			s = s + 1
  42508 		}
  42509 		// Check for convergence: we stop as soon as the error is no
  42510 		// longer improving.
  42511 		if last_err-err < err_threshold {
  42512 			break
  42513 		}
  42514 		last_err = err
  42515 		goto _3
  42516 	_3:
  42517 		;
  42518 		iter = iter + 1
  42519 	}
  42520 	// Remap the alpha plane to quantized values.
  42521 	s1 = min_s
  42522 	for {
  42523 		if !(s1 <= max_s) {
  42524 			break
  42525 		}
  42526 		slot1 = q_level[s1]
  42527 		map1[s1] = uint8(inv_q_level[slot1] + libc.Float64FromFloat64(0.5))
  42528 		goto _7
  42529 	_7:
  42530 		;
  42531 		s1 = s1 + 1
  42532 	}
  42533 	// Final pass.
  42534 	n1 = uint64(0)
  42535 	for {
  42536 		if !(n1 < data_size) {
  42537 			break
  42538 		}
  42539 		**(**uint8_t)(__ccgo_up(data + uintptr(n1))) = map1[**(**uint8_t)(__ccgo_up(data + uintptr(n1)))]
  42540 		goto _8
  42541 	_8:
  42542 		;
  42543 		n1 = n1 + 1
  42544 	}
  42545 	goto End
  42546 End:
  42547 	;
  42548 	// Store sum of squared error if needed.
  42549 	if sse != libc.UintptrFromInt32(0) {
  42550 		**(**uint64_t)(__ccgo_up(sse)) = uint64(err)
  42551 	}
  42552 	return int32(1)
  42553 }
  42554 
  42555 //------------------------------------------------------------------------------
  42556 
  42557 // C documentation
  42558 //
  42559 //	// 31b-range values
  42560 var kRandomTable = [55]uint32_t{
  42561 	0:  uint32(0x0de15230),
  42562 	1:  uint32(0x03b31886),
  42563 	2:  uint32(0x775faccb),
  42564 	3:  uint32(0x1c88626a),
  42565 	4:  uint32(0x68385c55),
  42566 	5:  uint32(0x14b3b828),
  42567 	6:  uint32(0x4a85fef8),
  42568 	7:  uint32(0x49ddb84b),
  42569 	8:  uint32(0x64fcf397),
  42570 	9:  uint32(0x5c550289),
  42571 	10: uint32(0x4a290000),
  42572 	11: uint32(0x0d7ec1da),
  42573 	12: uint32(0x5940b7ab),
  42574 	13: uint32(0x5492577d),
  42575 	14: uint32(0x4e19ca72),
  42576 	15: uint32(0x38d38c69),
  42577 	16: uint32(0x0c01ee65),
  42578 	17: uint32(0x32a1755f),
  42579 	18: uint32(0x5437f652),
  42580 	19: uint32(0x5abb2c32),
  42581 	20: uint32(0x0faa57b1),
  42582 	21: uint32(0x73f533e7),
  42583 	22: uint32(0x685feeda),
  42584 	23: uint32(0x7563cce2),
  42585 	24: uint32(0x6e990e83),
  42586 	25: uint32(0x4730a7ed),
  42587 	26: uint32(0x4fc0d9c6),
  42588 	27: uint32(0x496b153c),
  42589 	28: uint32(0x4f1403fa),
  42590 	29: uint32(0x541afb0c),
  42591 	30: uint32(0x73990b32),
  42592 	31: uint32(0x26d7cb1c),
  42593 	32: uint32(0x6fcc3706),
  42594 	33: uint32(0x2cbb77d8),
  42595 	34: uint32(0x75762f2a),
  42596 	35: uint32(0x6425ccdd),
  42597 	36: uint32(0x24b35461),
  42598 	37: uint32(0x0a7d8715),
  42599 	38: uint32(0x220414a8),
  42600 	39: uint32(0x141ebf67),
  42601 	40: uint32(0x56b41583),
  42602 	41: uint32(0x73e502e3),
  42603 	42: uint32(0x44cab16f),
  42604 	43: uint32(0x28264d42),
  42605 	44: uint32(0x73baaefb),
  42606 	45: uint32(0x0a50ebed),
  42607 	46: uint32(0x1d6ab6fb),
  42608 	47: uint32(0x0d3ad40b),
  42609 	48: uint32(0x35db3b68),
  42610 	49: uint32(0x2b081e83),
  42611 	50: uint32(0x77ce6b95),
  42612 	51: uint32(0x5181e5f0),
  42613 	52: uint32(0x78853bbc),
  42614 	53: uint32(0x009f9494),
  42615 	54: uint32(0x27e5ed3c),
  42616 }
  42617 
  42618 func VP8InitRandom(tls *libc.TLS, rg uintptr, dithering float32) {
  42619 	var v1, v2 uint32
  42620 	_, _ = v1, v2
  42621 	libc.Xmemcpy(tls, rg+8, uintptr(unsafe.Pointer(&kRandomTable)), uint64(220))
  42622 	(*VP8Random)(unsafe.Pointer(rg)).Findex1 = 0
  42623 	(*VP8Random)(unsafe.Pointer(rg)).Findex2 = int32(31)
  42624 	if float64(dithering) < float64(0) {
  42625 		v1 = uint32(0)
  42626 	} else {
  42627 		if float64(dithering) > float64(1) {
  42628 			v2 = uint32(libc.Int32FromInt32(1) << libc.Int32FromInt32(VP8_RANDOM_DITHER_FIX))
  42629 		} else {
  42630 			v2 = uint32(float32(float32(libc.Int32FromInt32(1)<<libc.Int32FromInt32(VP8_RANDOM_DITHER_FIX)) * dithering))
  42631 		}
  42632 		v1 = v2
  42633 	}
  42634 	(*VP8Random)(unsafe.Pointer(rg)).Famp = int32(v1)
  42635 }
  42636 
  42637 const SIZE_MAX20 = "_UI64_MAX"
  42638 const __INT_MAX__3 = 2147483647
  42639 
  42640 //------------------------------------------------------------------------------
  42641 
  42642 //------------------------------------------------------------------------------
  42643 
  42644 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) {
  42645 	var den, num, ratio, total_size, v1 uint64_t
  42646 	var x_add, x_sub, y_add, y_sub, v2 int32
  42647 	_, _, _, _, _, _, _, _, _, _ = den, num, ratio, total_size, x_add, x_sub, y_add, y_sub, v1, v2
  42648 	x_add = src_width
  42649 	x_sub = dst_width
  42650 	y_add = src_height
  42651 	y_sub = dst_height
  42652 	total_size = uint64(2) * uint64(dst_width) * uint64(num_channels) * uint64(4)
  42653 	v1 = total_size
  42654 	v2 = libc.BoolInt32(v1 == v1)
  42655 	goto _3
  42656 _3:
  42657 	if !(v2 != 0) {
  42658 		return 0
  42659 	}
  42660 	(*WebPRescaler)(unsafe.Pointer(rescaler)).Fx_expand = libc.BoolInt32(src_width < dst_width)
  42661 	(*WebPRescaler)(unsafe.Pointer(rescaler)).Fy_expand = libc.BoolInt32(src_height < dst_height)
  42662 	(*WebPRescaler)(unsafe.Pointer(rescaler)).Fsrc_width = src_width
  42663 	(*WebPRescaler)(unsafe.Pointer(rescaler)).Fsrc_height = src_height
  42664 	(*WebPRescaler)(unsafe.Pointer(rescaler)).Fdst_width = dst_width
  42665 	(*WebPRescaler)(unsafe.Pointer(rescaler)).Fdst_height = dst_height
  42666 	(*WebPRescaler)(unsafe.Pointer(rescaler)).Fsrc_y = 0
  42667 	(*WebPRescaler)(unsafe.Pointer(rescaler)).Fdst_y = 0
  42668 	(*WebPRescaler)(unsafe.Pointer(rescaler)).Fdst = dst
  42669 	(*WebPRescaler)(unsafe.Pointer(rescaler)).Fdst_stride = dst_stride
  42670 	(*WebPRescaler)(unsafe.Pointer(rescaler)).Fnum_channels = num_channels
  42671 	// for 'x_expand', we use bilinear interpolation
  42672 	if (*WebPRescaler)(unsafe.Pointer(rescaler)).Fx_expand != 0 {
  42673 		v2 = x_sub - int32(1)
  42674 	} else {
  42675 		v2 = x_add
  42676 	}
  42677 	(*WebPRescaler)(unsafe.Pointer(rescaler)).Fx_add = v2
  42678 	if (*WebPRescaler)(unsafe.Pointer(rescaler)).Fx_expand != 0 {
  42679 		v2 = x_add - int32(1)
  42680 	} else {
  42681 		v2 = x_sub
  42682 	}
  42683 	(*WebPRescaler)(unsafe.Pointer(rescaler)).Fx_sub = v2
  42684 	if !((*WebPRescaler)(unsafe.Pointer(rescaler)).Fx_expand != 0) { // fx_scale is not used otherwise
  42685 		(*WebPRescaler)(unsafe.Pointer(rescaler)).Ffx_scale = uint32(uint64(libc.Int32FromInt32(1)) << libc.Int32FromInt32(WEBP_RESCALER_RFIX) / uint64((*WebPRescaler)(unsafe.Pointer(rescaler)).Fx_sub))
  42686 	}
  42687 	// vertical scaling parameters
  42688 	if (*WebPRescaler)(unsafe.Pointer(rescaler)).Fy_expand != 0 {
  42689 		v2 = y_add - int32(1)
  42690 	} else {
  42691 		v2 = y_add
  42692 	}
  42693 	(*WebPRescaler)(unsafe.Pointer(rescaler)).Fy_add = v2
  42694 	if (*WebPRescaler)(unsafe.Pointer(rescaler)).Fy_expand != 0 {
  42695 		v2 = y_sub - int32(1)
  42696 	} else {
  42697 		v2 = y_sub
  42698 	}
  42699 	(*WebPRescaler)(unsafe.Pointer(rescaler)).Fy_sub = v2
  42700 	if (*WebPRescaler)(unsafe.Pointer(rescaler)).Fy_expand != 0 {
  42701 		v2 = (*WebPRescaler)(unsafe.Pointer(rescaler)).Fy_sub
  42702 	} else {
  42703 		v2 = (*WebPRescaler)(unsafe.Pointer(rescaler)).Fy_add
  42704 	}
  42705 	(*WebPRescaler)(unsafe.Pointer(rescaler)).Fy_accum = v2
  42706 	if !((*WebPRescaler)(unsafe.Pointer(rescaler)).Fy_expand != 0) {
  42707 		// This is WEBP_RESCALER_FRAC(dst_height, x_add * y_add) without the cast.
  42708 		// Its value is <= WEBP_RESCALER_ONE, because dst_height <= rescaler->y_add
  42709 		// and rescaler->x_add >= 1;
  42710 		num = uint64(dst_height) * (libc.Uint64FromUint64(1) << libc.Int32FromInt32(WEBP_RESCALER_RFIX))
  42711 		den = uint64((*WebPRescaler)(unsafe.Pointer(rescaler)).Fx_add) * uint64((*WebPRescaler)(unsafe.Pointer(rescaler)).Fy_add)
  42712 		ratio = num / den
  42713 		if ratio != uint64(uint32(ratio)) {
  42714 			// When ratio == WEBP_RESCALER_ONE, we can't represent the ratio with the
  42715 			// current fixed-point precision. This happens when src_height ==
  42716 			// rescaler->y_add (which == src_height), and rescaler->x_add == 1.
  42717 			// => We special-case fxy_scale = 0, in WebPRescalerExportRow().
  42718 			(*WebPRescaler)(unsafe.Pointer(rescaler)).Ffxy_scale = uint32(0)
  42719 		} else {
  42720 			(*WebPRescaler)(unsafe.Pointer(rescaler)).Ffxy_scale = uint32(ratio)
  42721 		}
  42722 		(*WebPRescaler)(unsafe.Pointer(rescaler)).Ffy_scale = uint32(uint64(libc.Int32FromInt32(1)) << libc.Int32FromInt32(WEBP_RESCALER_RFIX) / uint64((*WebPRescaler)(unsafe.Pointer(rescaler)).Fy_sub))
  42723 	} else {
  42724 		(*WebPRescaler)(unsafe.Pointer(rescaler)).Ffy_scale = uint32(uint64(libc.Int32FromInt32(1)) << libc.Int32FromInt32(WEBP_RESCALER_RFIX) / uint64((*WebPRescaler)(unsafe.Pointer(rescaler)).Fx_add))
  42725 		// rescaler->fxy_scale is unused here.
  42726 	}
  42727 	(*WebPRescaler)(unsafe.Pointer(rescaler)).Firow = work
  42728 	(*WebPRescaler)(unsafe.Pointer(rescaler)).Ffrow = work + uintptr(num_channels*dst_width)*4
  42729 	libc.Xmemset(tls, work, 0, total_size)
  42730 	WebPRescalerDspInit(tls)
  42731 	return int32(1)
  42732 }
  42733 
  42734 func WebPRescalerGetScaledDimensions(tls *libc.TLS, src_width int32, src_height int32, scaled_width uintptr, scaled_height uintptr) (r int32) {
  42735 	var height, max_size, width int32
  42736 	_, _, _ = height, max_size, width
  42737 	width = **(**int32)(__ccgo_up(scaled_width))
  42738 	height = **(**int32)(__ccgo_up(scaled_height))
  42739 	max_size = libc.Int32FromInt32(__INT_MAX__3) / libc.Int32FromInt32(2)
  42740 	// if width is unspecified, scale original proportionally to height ratio.
  42741 	if width == 0 && src_height > 0 {
  42742 		width = int32((uint64(src_width)*uint64(height) + uint64(src_height) - libc.Uint64FromInt32(1)) / uint64(src_height))
  42743 	}
  42744 	// if height is unspecified, scale original proportionally to width ratio.
  42745 	if height == 0 && src_width > 0 {
  42746 		height = int32((uint64(src_height)*uint64(width) + uint64(src_width) - libc.Uint64FromInt32(1)) / uint64(src_width))
  42747 	}
  42748 	// Check if the overall dimensions still make sense.
  42749 	if width <= 0 || height <= 0 || width > max_size || height > max_size {
  42750 		return 0
  42751 	}
  42752 	**(**int32)(__ccgo_up(scaled_width)) = width
  42753 	**(**int32)(__ccgo_up(scaled_height)) = height
  42754 	return int32(1)
  42755 	return r
  42756 }
  42757 
  42758 //------------------------------------------------------------------------------
  42759 // all-in-one calls
  42760 
  42761 func WebPRescaleNeededLines(tls *libc.TLS, rescaler uintptr, max_num_lines int32) (r int32) {
  42762 	var num_lines, v1 int32
  42763 	_, _ = num_lines, v1
  42764 	num_lines = ((*WebPRescaler)(unsafe.Pointer(rescaler)).Fy_accum + (*WebPRescaler)(unsafe.Pointer(rescaler)).Fy_sub - int32(1)) / (*WebPRescaler)(unsafe.Pointer(rescaler)).Fy_sub
  42765 	if num_lines > max_num_lines {
  42766 		v1 = max_num_lines
  42767 	} else {
  42768 		v1 = num_lines
  42769 	}
  42770 	return v1
  42771 }
  42772 
  42773 func WebPRescalerImport(tls *libc.TLS, rescaler2 uintptr, num_lines int32, src uintptr, src_stride int32) (r int32) {
  42774 	var tmp, v1, v4 uintptr
  42775 	var total_imported, x, v2, v5 int32
  42776 	var v7 bool
  42777 	_, _, _, _, _, _, _, _ = tmp, total_imported, x, v1, v2, v4, v5, v7
  42778 	total_imported = 0
  42779 	for {
  42780 		if v7 = total_imported < num_lines; v7 {
  42781 			v1 = rescaler2
  42782 			v4 = v1
  42783 			v5 = libc.BoolInt32((*WebPRescaler)(unsafe.Pointer(v4)).Fdst_y >= (*WebPRescaler)(unsafe.Pointer(v4)).Fdst_height)
  42784 			goto _6
  42785 		_6:
  42786 			;
  42787 			v2 = libc.BoolInt32(!(v5 != 0) && (*WebPRescaler)(unsafe.Pointer(v1)).Fy_accum <= 0)
  42788 			goto _3
  42789 		_3:
  42790 		}
  42791 		if !(v7 && !(v2 != 0)) {
  42792 			break
  42793 		}
  42794 		if (*WebPRescaler)(unsafe.Pointer(rescaler2)).Fy_expand != 0 {
  42795 			tmp = (*WebPRescaler)(unsafe.Pointer(rescaler2)).Firow
  42796 			(*WebPRescaler)(unsafe.Pointer(rescaler2)).Firow = (*WebPRescaler)(unsafe.Pointer(rescaler2)).Ffrow
  42797 			(*WebPRescaler)(unsafe.Pointer(rescaler2)).Ffrow = tmp
  42798 		}
  42799 		WebPRescalerImportRow(tls, rescaler2, src)
  42800 		if !((*WebPRescaler)(unsafe.Pointer(rescaler2)).Fy_expand != 0) {
  42801 			x = 0
  42802 			for {
  42803 				if !(x < (*WebPRescaler)(unsafe.Pointer(rescaler2)).Fnum_channels*(*WebPRescaler)(unsafe.Pointer(rescaler2)).Fdst_width) {
  42804 					break
  42805 				}
  42806 				**(**rescaler_t)(__ccgo_up((*WebPRescaler)(unsafe.Pointer(rescaler2)).Firow + uintptr(x)*4)) += **(**rescaler_t)(__ccgo_up((*WebPRescaler)(unsafe.Pointer(rescaler2)).Ffrow + uintptr(x)*4))
  42807 				goto _8
  42808 			_8:
  42809 				;
  42810 				x = x + 1
  42811 			}
  42812 		}
  42813 		(*WebPRescaler)(unsafe.Pointer(rescaler2)).Fsrc_y = (*WebPRescaler)(unsafe.Pointer(rescaler2)).Fsrc_y + 1
  42814 		src = src + uintptr(src_stride)
  42815 		total_imported = total_imported + 1
  42816 		**(**int32)(__ccgo_up(rescaler2 + 24)) -= (*WebPRescaler)(unsafe.Pointer(rescaler2)).Fy_sub
  42817 	}
  42818 	return total_imported
  42819 }
  42820 
  42821 func WebPRescalerExport(tls *libc.TLS, rescaler2 uintptr) (r int32) {
  42822 	var total_exported, v2, v5 int32
  42823 	var v1, v4 uintptr
  42824 	_, _, _, _, _ = total_exported, v1, v2, v4, v5
  42825 	total_exported = 0
  42826 	for {
  42827 		v1 = rescaler2
  42828 		v4 = v1
  42829 		v5 = libc.BoolInt32((*WebPRescaler)(unsafe.Pointer(v4)).Fdst_y >= (*WebPRescaler)(unsafe.Pointer(v4)).Fdst_height)
  42830 		goto _6
  42831 	_6:
  42832 		;
  42833 		v2 = libc.BoolInt32(!(v5 != 0) && (*WebPRescaler)(unsafe.Pointer(v1)).Fy_accum <= 0)
  42834 		goto _3
  42835 	_3:
  42836 		if !(v2 != 0) {
  42837 			break
  42838 		}
  42839 		WebPRescalerExportRow(tls, rescaler2)
  42840 		total_exported = total_exported + 1
  42841 	}
  42842 	return total_exported
  42843 }
  42844 
  42845 const SIZE_MAX21 = "UINT64_MAX"
  42846 const __INT_MAX__4 = 0x7fffffff
  42847 
  42848 //------------------------------------------------------------------------------
  42849 
  42850 //------------------------------------------------------------------------------
  42851 
  42852 func Init(tls *libc.TLS, worker uintptr) {
  42853 	libc.Xmemset(tls, worker, 0, uint64(48))
  42854 	(*WebPWorker)(unsafe.Pointer(worker)).Fstatus = int32(NOT_OK)
  42855 }
  42856 
  42857 func Sync(tls *libc.TLS, worker uintptr) (r int32) {
  42858 	return libc.BoolInt32(!((*WebPWorker)(unsafe.Pointer(worker)).Fhad_error != 0))
  42859 }
  42860 
  42861 func Reset(tls *libc.TLS, worker uintptr) (r int32) {
  42862 	var ok int32
  42863 	_ = ok
  42864 	ok = int32(1)
  42865 	(*WebPWorker)(unsafe.Pointer(worker)).Fhad_error = 0
  42866 	if (*WebPWorker)(unsafe.Pointer(worker)).Fstatus < int32(OK) {
  42867 		(*WebPWorker)(unsafe.Pointer(worker)).Fstatus = int32(OK)
  42868 	} else {
  42869 		if (*WebPWorker)(unsafe.Pointer(worker)).Fstatus > int32(OK) {
  42870 			ok = Sync(tls, worker)
  42871 		}
  42872 	}
  42873 	return ok
  42874 }
  42875 
  42876 func Execute(tls *libc.TLS, worker uintptr) {
  42877 	if (*WebPWorker)(unsafe.Pointer(worker)).Fhook != libc.UintptrFromInt32(0) {
  42878 		**(**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))
  42879 	}
  42880 }
  42881 
  42882 func Launch(tls *libc.TLS, worker uintptr) {
  42883 	Execute(tls, worker)
  42884 }
  42885 
  42886 func End(tls *libc.TLS, worker uintptr) {
  42887 	(*WebPWorker)(unsafe.Pointer(worker)).Fstatus = int32(NOT_OK)
  42888 }
  42889 
  42890 //------------------------------------------------------------------------------
  42891 
  42892 var g_worker_interface = WebPWorkerInterface{}
  42893 
  42894 func init() {
  42895 	p := unsafe.Pointer(&g_worker_interface)
  42896 	*(*uintptr)(unsafe.Add(p, 0)) = __ccgo_fp(Init)
  42897 	*(*uintptr)(unsafe.Add(p, 8)) = __ccgo_fp(Reset)
  42898 	*(*uintptr)(unsafe.Add(p, 16)) = __ccgo_fp(Sync)
  42899 	*(*uintptr)(unsafe.Add(p, 24)) = __ccgo_fp(Launch)
  42900 	*(*uintptr)(unsafe.Add(p, 32)) = __ccgo_fp(Execute)
  42901 	*(*uintptr)(unsafe.Add(p, 40)) = __ccgo_fp(End)
  42902 }
  42903 
  42904 func WebPSetWorkerInterface(tls *libc.TLS, winterface uintptr) (r int32) {
  42905 	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) {
  42906 		return 0
  42907 	}
  42908 	g_worker_interface = **(**WebPWorkerInterface)(__ccgo_up(winterface))
  42909 	return int32(1)
  42910 }
  42911 
  42912 func WebPGetWorkerInterface(tls *libc.TLS) (r uintptr) {
  42913 	return uintptr(unsafe.Pointer(&g_worker_interface))
  42914 }
  42915 
  42916 //------------------------------------------------------------------------------
  42917 
  42918 // If PRINT_MEM_INFO is defined, extra info (like total memory used, number of
  42919 // alloc/free etc) is printed. For debugging/tuning purpose only (it's slow,
  42920 // and not multi-thread safe!).
  42921 // An interesting alternative is valgrind's 'massif' tool:
  42922 //    https://valgrind.org/docs/manual/ms-manual.html
  42923 // Here is an example command line:
  42924 /*    valgrind --tool=massif --massif-out-file=massif.out                --stacks=yes --alloc-fn=WebPSafeMalloc --alloc-fn=WebPSafeCalloc
  42925       ms_print massif.out
  42926 */
  42927 // In addition:
  42928 // * if PRINT_MEM_TRAFFIC is defined, all the details of the malloc/free cycles
  42929 //   are printed.
  42930 // * if MALLOC_FAIL_AT is defined, the global environment variable
  42931 //   $MALLOC_FAIL_AT is used to simulate a memory error when calloc or malloc
  42932 //   is called for the nth time. Example usage:
  42933 //   export MALLOC_FAIL_AT=50 && ./examples/cwebp input.png
  42934 // * if MALLOC_LIMIT is defined, the global environment variable $MALLOC_LIMIT
  42935 //   sets the maximum amount of memory (in bytes) made available to libwebp.
  42936 //   This can be used to emulate environment with very limited memory.
  42937 //   Example: export MALLOC_LIMIT=64000000 && ./examples/dwebp picture.webp
  42938 
  42939 // #define PRINT_MEM_INFO
  42940 // #define PRINT_MEM_TRAFFIC
  42941 // #define MALLOC_FAIL_AT
  42942 // #define MALLOC_LIMIT
  42943 
  42944 //------------------------------------------------------------------------------
  42945 // Checked memory allocation
  42946 
  42947 // C documentation
  42948 //
  42949 //	// Returns 0 in case of overflow of nmemb * size.
  42950 func CheckSizeArgumentsOverflow(tls *libc.TLS, nmemb uint64_t, size1 size_t) (r int32) {
  42951 	var total_size, v1 uint64_t
  42952 	var v2 int32
  42953 	_, _, _ = total_size, v1, v2
  42954 	total_size = nmemb * size1
  42955 	if nmemb == uint64(0) {
  42956 		return int32(1)
  42957 	}
  42958 	if size1 > libc.Uint64FromUint64(1)<<libc.Int32FromInt32(34)/nmemb {
  42959 		return 0
  42960 	}
  42961 	v1 = total_size
  42962 	v2 = libc.BoolInt32(v1 == v1)
  42963 	goto _3
  42964 _3:
  42965 	if !(v2 != 0) {
  42966 		return 0
  42967 	}
  42968 	return int32(1)
  42969 }
  42970 
  42971 func WebPSafeMalloc(tls *libc.TLS, nmemb uint64_t, size size_t) (r uintptr) {
  42972 	var ptr uintptr
  42973 	_ = ptr
  42974 	if !(CheckSizeArgumentsOverflow(tls, nmemb, size) != 0) {
  42975 		return libc.UintptrFromInt32(0)
  42976 	}
  42977 	ptr = libc.Xmalloc(tls, nmemb*size)
  42978 	return ptr
  42979 }
  42980 
  42981 func WebPSafeCalloc(tls *libc.TLS, nmemb uint64_t, size size_t) (r uintptr) {
  42982 	var ptr uintptr
  42983 	_ = ptr
  42984 	if !(CheckSizeArgumentsOverflow(tls, nmemb, size) != 0) {
  42985 		return libc.UintptrFromInt32(0)
  42986 	}
  42987 	ptr = libc.Xcalloc(tls, nmemb, size)
  42988 	return ptr
  42989 }
  42990 
  42991 func WebPSafeFree(tls *libc.TLS, ptr uintptr) {
  42992 	if ptr != libc.UintptrFromInt32(0) {
  42993 	}
  42994 	libc.Xfree(tls, ptr)
  42995 }
  42996 
  42997 // Public API functions.
  42998 
  42999 func WebPMalloc(tls *libc.TLS, size size_t) (r uintptr) {
  43000 	return WebPSafeMalloc(tls, uint64(1), size)
  43001 }
  43002 
  43003 func WebPFree(tls *libc.TLS, ptr uintptr) {
  43004 	WebPSafeFree(tls, ptr)
  43005 }
  43006 
  43007 //------------------------------------------------------------------------------
  43008 
  43009 func WebPCopyPlane(tls *libc.TLS, src uintptr, src_stride int32, dst uintptr, dst_stride int32, width int32, height int32) {
  43010 	var v1 int32
  43011 	_ = v1
  43012 	for {
  43013 		v1 = height
  43014 		height = height - 1
  43015 		if !(v1 > 0) {
  43016 			break
  43017 		}
  43018 		libc.Xmemcpy(tls, dst, src, uint64(width))
  43019 		src = src + uintptr(src_stride)
  43020 		dst = dst + uintptr(dst_stride)
  43021 	}
  43022 }
  43023 
  43024 func WebPCopyPixels(tls *libc.TLS, src uintptr, dst uintptr) {
  43025 	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)
  43026 }
  43027 
  43028 //------------------------------------------------------------------------------
  43029 
  43030 func WebPGetColorPalette(tls *libc.TLS, pic uintptr, palette uintptr) (r int32) {
  43031 	return GetColorPalette(tls, pic, palette)
  43032 }
  43033 
  43034 const USE_TABLES_FOR_ALPHA_MULT = 0
  43035 
  43036 // Copyright 2010 Google Inc. All Rights Reserved.
  43037 //
  43038 // Use of this source code is governed by a BSD-style license
  43039 // that can be found in the COPYING file in the root of the source
  43040 // tree. An additional intellectual property rights grant can be found
  43041 // in the file PATENTS. All contributing project authors may
  43042 // be found in the AUTHORS file in the root of the source tree.
  43043 // -----------------------------------------------------------------------------
  43044 //
  43045 //  Common types + memory wrappers
  43046 //
  43047 // Author: Skal (pascal.massimino@gmail.com)
  43048 
  43049 // Tables can be faster on some platform but incur some extra binary size (~2k).
  43050 
  43051 // -----------------------------------------------------------------------------
  43052 
  43053 func Mult(tls *libc.TLS, x uint8_t, mult uint32_t) (r uint32_t) {
  43054 	var v uint32_t
  43055 	_ = v
  43056 	v = (uint32(x)*mult + libc.Uint32FromUint32(1)<<libc.Int32FromInt32(24)>>libc.Int32FromInt32(1)) >> int32(24)
  43057 	// <- 24bit precision is enough to ensure that.
  43058 	return v
  43059 }
  43060 
  43061 func GetScale(tls *libc.TLS, a uint32_t, inverse int32) (r uint32_t) {
  43062 	var v1 uint32
  43063 	_ = v1
  43064 	if inverse != 0 {
  43065 		v1 = libc.Uint32FromUint32(255) << libc.Int32FromInt32(24) / a
  43066 	} else {
  43067 		v1 = a * (libc.Uint32FromUint32(1) << libc.Int32FromInt32(24) / libc.Uint32FromUint32(255))
  43068 	}
  43069 	return v1
  43070 }
  43071 
  43072 func WebPMultARGBRow_C(tls *libc.TLS, ptr uintptr, width int32, inverse int32) {
  43073 	var alpha, argb, out, scale uint32_t
  43074 	var x int32
  43075 	_, _, _, _, _ = alpha, argb, out, scale, x
  43076 	x = 0
  43077 	for {
  43078 		if !(x < width) {
  43079 			break
  43080 		}
  43081 		argb = **(**uint32_t)(__ccgo_up(ptr + uintptr(x)*4))
  43082 		if argb < uint32(0xff000000) { // alpha < 255
  43083 			if argb <= uint32(0x00ffffff) { // alpha == 0
  43084 				**(**uint32_t)(__ccgo_up(ptr + uintptr(x)*4)) = uint32(0)
  43085 			} else {
  43086 				alpha = argb >> libc.Int32FromInt32(24) & uint32(0xff)
  43087 				scale = GetScale(tls, alpha, inverse)
  43088 				out = argb & uint32(0xff000000)
  43089 				out = out | Mult(tls, uint8(argb>>0), scale)<<0
  43090 				out = out | Mult(tls, uint8(argb>>int32(8)), scale)<<int32(8)
  43091 				out = out | Mult(tls, uint8(argb>>int32(16)), scale)<<int32(16)
  43092 				**(**uint32_t)(__ccgo_up(ptr + uintptr(x)*4)) = out
  43093 			}
  43094 		}
  43095 		goto _1
  43096 	_1:
  43097 		;
  43098 		x = x + 1
  43099 	}
  43100 }
  43101 
  43102 func WebPMultRow_C(tls *libc.TLS, ptr uintptr, alpha uintptr, width int32, inverse int32) {
  43103 	var a, scale uint32_t
  43104 	var x int32
  43105 	_, _, _ = a, scale, x
  43106 	x = 0
  43107 	for {
  43108 		if !(x < width) {
  43109 			break
  43110 		}
  43111 		a = uint32(**(**uint8_t)(__ccgo_up(alpha + uintptr(x))))
  43112 		if a != uint32(255) {
  43113 			if a == uint32(0) {
  43114 				**(**uint8_t)(__ccgo_up(ptr + uintptr(x))) = uint8(0)
  43115 			} else {
  43116 				scale = GetScale(tls, a, inverse)
  43117 				**(**uint8_t)(__ccgo_up(ptr + uintptr(x))) = uint8(Mult(tls, **(**uint8_t)(__ccgo_up(ptr + uintptr(x))), scale))
  43118 			}
  43119 		}
  43120 		goto _1
  43121 	_1:
  43122 		;
  43123 		x = x + 1
  43124 	}
  43125 }
  43126 
  43127 //------------------------------------------------------------------------------
  43128 // Generic per-plane calls
  43129 
  43130 func WebPMultARGBRows(tls *libc.TLS, ptr uintptr, stride int32, width int32, num_rows int32, inverse int32) {
  43131 	var n int32
  43132 	_ = n
  43133 	n = 0
  43134 	for {
  43135 		if !(n < num_rows) {
  43136 			break
  43137 		}
  43138 		(*(*func(*libc.TLS, uintptr, int32, int32))(unsafe.Pointer(&struct{ uintptr }{WebPMultARGBRow})))(tls, ptr, width, inverse)
  43139 		ptr = ptr + uintptr(stride)
  43140 		goto _1
  43141 	_1:
  43142 		;
  43143 		n = n + 1
  43144 	}
  43145 }
  43146 
  43147 func WebPMultRows(tls *libc.TLS, ptr uintptr, stride int32, alpha uintptr, alpha_stride int32, width int32, num_rows int32, inverse int32) {
  43148 	var n int32
  43149 	_ = n
  43150 	n = 0
  43151 	for {
  43152 		if !(n < num_rows) {
  43153 			break
  43154 		}
  43155 		(*(*func(*libc.TLS, uintptr, uintptr, int32, int32))(unsafe.Pointer(&struct{ uintptr }{WebPMultRow})))(tls, ptr, alpha, width, inverse)
  43156 		ptr = ptr + uintptr(stride)
  43157 		alpha = alpha + uintptr(alpha_stride)
  43158 		goto _1
  43159 	_1:
  43160 		;
  43161 		n = n + 1
  43162 	}
  43163 }
  43164 
  43165 //------------------------------------------------------------------------------
  43166 // Premultiplied modes
  43167 
  43168 // non dithered-modes
  43169 
  43170 // (x * a * 32897) >> 23 is bit-wise equivalent to (int)(x * a / 255.)
  43171 // for all 8bit x or a. For bit-wise equivalence to (int)(x * a / 255. + .5),
  43172 // one can use instead: (x * a * 65793 + (1 << 23)) >> 24
  43173 
  43174 func ApplyAlphaMultiply_C(tls *libc.TLS, rgba uintptr, alpha_first int32, w int32, h int32, stride int32) {
  43175 	var a, mult uint32_t
  43176 	var alpha, rgb uintptr
  43177 	var i, v1, v2, v3 int32
  43178 	_, _, _, _, _, _, _, _ = a, alpha, i, mult, rgb, v1, v2, v3
  43179 	for {
  43180 		v1 = h
  43181 		h = h - 1
  43182 		if !(v1 > 0) {
  43183 			break
  43184 		}
  43185 		if alpha_first != 0 {
  43186 			v2 = int32(1)
  43187 		} else {
  43188 			v2 = 0
  43189 		}
  43190 		rgb = rgba + uintptr(v2)
  43191 		if alpha_first != 0 {
  43192 			v3 = 0
  43193 		} else {
  43194 			v3 = int32(3)
  43195 		}
  43196 		alpha = rgba + uintptr(v3)
  43197 		i = 0
  43198 		for {
  43199 			if !(i < w) {
  43200 				break
  43201 			}
  43202 			a = uint32(**(**uint8_t)(__ccgo_up(alpha + uintptr(int32(4)*i))))
  43203 			if a != uint32(0xff) {
  43204 				mult = a * libc.Uint32FromUint32(32897)
  43205 				**(**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))
  43206 				**(**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))
  43207 				**(**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))
  43208 			}
  43209 			goto _4
  43210 		_4:
  43211 			;
  43212 			i = i + 1
  43213 		}
  43214 		rgba = rgba + uintptr(stride)
  43215 	}
  43216 }
  43217 
  43218 // rgbA4444
  43219 
  43220 func dither_hi(tls *libc.TLS, x uint8_t) (r uint8_t) {
  43221 	return uint8(int32(x)&int32(0xf0) | int32(x)>>int32(4))
  43222 }
  43223 
  43224 func dither_lo(tls *libc.TLS, x uint8_t) (r uint8_t) {
  43225 	return uint8(int32(x)&int32(0x0f) | int32(x)<<int32(4))
  43226 }
  43227 
  43228 func multiply(tls *libc.TLS, x uint8_t, m uint32_t) (r uint8_t) {
  43229 	return uint8(uint32(x) * m >> int32(16))
  43230 }
  43231 
  43232 func ApplyAlphaMultiply4444_C(tls *libc.TLS, rgba4444 uintptr, w int32, h int32, stride int32, rg_byte_pos int32) {
  43233 	var a, b, g, r uint8_t
  43234 	var ba, mult, rg uint32_t
  43235 	var i, v1 int32
  43236 	_, _, _, _, _, _, _, _, _ = a, b, ba, g, i, mult, r, rg, v1
  43237 	for {
  43238 		v1 = h
  43239 		h = h - 1
  43240 		if !(v1 > 0) {
  43241 			break
  43242 		}
  43243 		i = 0
  43244 		for {
  43245 			if !(i < w) {
  43246 				break
  43247 			}
  43248 			rg = uint32(**(**uint8_t)(__ccgo_up(rgba4444 + uintptr(int32(2)*i+rg_byte_pos))))
  43249 			ba = uint32(**(**uint8_t)(__ccgo_up(rgba4444 + uintptr(int32(2)*i+(rg_byte_pos^int32(1))))))
  43250 			a = uint8(ba & uint32(0x0f))
  43251 			mult = uint32(int32(a) * libc.Int32FromInt32(0x1111))
  43252 			r = multiply(tls, dither_hi(tls, uint8(rg)), mult)
  43253 			g = multiply(tls, dither_lo(tls, uint8(rg)), mult)
  43254 			b = multiply(tls, dither_hi(tls, uint8(ba)), mult)
  43255 			**(**uint8_t)(__ccgo_up(rgba4444 + uintptr(int32(2)*i+rg_byte_pos))) = uint8(int32(r)&int32(0xf0) | int32(g)>>int32(4)&int32(0x0f))
  43256 			**(**uint8_t)(__ccgo_up(rgba4444 + uintptr(int32(2)*i+(rg_byte_pos^int32(1))))) = uint8(int32(b)&int32(0xf0) | int32(a))
  43257 			goto _2
  43258 		_2:
  43259 			;
  43260 			i = i + 1
  43261 		}
  43262 		rgba4444 = rgba4444 + uintptr(stride)
  43263 	}
  43264 }
  43265 
  43266 func ApplyAlphaMultiply_16b_C(tls *libc.TLS, rgba4444 uintptr, w int32, h int32, stride int32) {
  43267 	ApplyAlphaMultiply4444_C(tls, rgba4444, w, h, stride, 0)
  43268 }
  43269 
  43270 func DispatchAlpha_C(tls *libc.TLS, alpha uintptr, alpha_stride int32, width int32, height int32, dst uintptr, dst_stride int32) (r int32) {
  43271 	var alpha_mask, alpha_value uint32_t
  43272 	var i, j int32
  43273 	_, _, _, _ = alpha_mask, alpha_value, i, j
  43274 	alpha_mask = uint32(0xff)
  43275 	j = 0
  43276 	for {
  43277 		if !(j < height) {
  43278 			break
  43279 		}
  43280 		i = 0
  43281 		for {
  43282 			if !(i < width) {
  43283 				break
  43284 			}
  43285 			alpha_value = uint32(**(**uint8_t)(__ccgo_up(alpha + uintptr(i))))
  43286 			**(**uint8_t)(__ccgo_up(dst + uintptr(int32(4)*i))) = uint8(alpha_value)
  43287 			alpha_mask = alpha_mask & alpha_value
  43288 			goto _2
  43289 		_2:
  43290 			;
  43291 			i = i + 1
  43292 		}
  43293 		alpha = alpha + uintptr(alpha_stride)
  43294 		dst = dst + uintptr(dst_stride)
  43295 		goto _1
  43296 	_1:
  43297 		;
  43298 		j = j + 1
  43299 	}
  43300 	return libc.BoolInt32(alpha_mask != uint32(0xff))
  43301 }
  43302 
  43303 func DispatchAlphaToGreen_C(tls *libc.TLS, alpha uintptr, alpha_stride int32, width int32, height int32, dst uintptr, dst_stride int32) {
  43304 	var i, j int32
  43305 	_, _ = i, j
  43306 	j = 0
  43307 	for {
  43308 		if !(j < height) {
  43309 			break
  43310 		}
  43311 		i = 0
  43312 		for {
  43313 			if !(i < width) {
  43314 				break
  43315 			}
  43316 			**(**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.
  43317 			goto _2
  43318 		_2:
  43319 			;
  43320 			i = i + 1
  43321 		}
  43322 		alpha = alpha + uintptr(alpha_stride)
  43323 		dst = dst + uintptr(dst_stride)*4
  43324 		goto _1
  43325 	_1:
  43326 		;
  43327 		j = j + 1
  43328 	}
  43329 }
  43330 
  43331 func ExtractAlpha_C(tls *libc.TLS, argb uintptr, argb_stride int32, width int32, height int32, alpha uintptr, alpha_stride int32) (r int32) {
  43332 	var alpha_mask, alpha_value uint8_t
  43333 	var i, j int32
  43334 	_, _, _, _ = alpha_mask, alpha_value, i, j
  43335 	alpha_mask = uint8(0xff)
  43336 	j = 0
  43337 	for {
  43338 		if !(j < height) {
  43339 			break
  43340 		}
  43341 		i = 0
  43342 		for {
  43343 			if !(i < width) {
  43344 				break
  43345 			}
  43346 			alpha_value = **(**uint8_t)(__ccgo_up(argb + uintptr(int32(4)*i)))
  43347 			**(**uint8_t)(__ccgo_up(alpha + uintptr(i))) = alpha_value
  43348 			alpha_mask = uint8(int32(alpha_mask) & int32(alpha_value))
  43349 			goto _2
  43350 		_2:
  43351 			;
  43352 			i = i + 1
  43353 		}
  43354 		argb = argb + uintptr(argb_stride)
  43355 		alpha = alpha + uintptr(alpha_stride)
  43356 		goto _1
  43357 	_1:
  43358 		;
  43359 		j = j + 1
  43360 	}
  43361 	return libc.BoolInt32(int32(alpha_mask) == int32(0xff))
  43362 }
  43363 
  43364 func ExtractGreen_C(tls *libc.TLS, argb uintptr, alpha uintptr, size int32) {
  43365 	var i int32
  43366 	_ = i
  43367 	i = 0
  43368 	for {
  43369 		if !(i < size) {
  43370 			break
  43371 		}
  43372 		**(**uint8_t)(__ccgo_up(alpha + uintptr(i))) = uint8(**(**uint32_t)(__ccgo_up(argb + uintptr(i)*4)) >> int32(8))
  43373 		goto _1
  43374 	_1:
  43375 		;
  43376 		i = i + 1
  43377 	}
  43378 }
  43379 
  43380 //------------------------------------------------------------------------------
  43381 
  43382 func HasAlpha8b_C(tls *libc.TLS, src uintptr, length int32) (r int32) {
  43383 	var v1 int32
  43384 	var v2 uintptr
  43385 	_, _ = v1, v2
  43386 	for {
  43387 		v1 = length
  43388 		length = length - 1
  43389 		if !(v1 > 0) {
  43390 			break
  43391 		}
  43392 		v2 = src
  43393 		src = src + 1
  43394 		if int32(**(**uint8_t)(__ccgo_up(v2))) != int32(0xff) {
  43395 			return int32(1)
  43396 		}
  43397 	}
  43398 	return 0
  43399 }
  43400 
  43401 func HasAlpha32b_C(tls *libc.TLS, src uintptr, length int32) (r int32) {
  43402 	var x, v2 int32
  43403 	_, _ = x, v2
  43404 	x = 0
  43405 	for {
  43406 		v2 = length
  43407 		length = length - 1
  43408 		if !(v2 > 0) {
  43409 			break
  43410 		}
  43411 		if int32(**(**uint8_t)(__ccgo_up(src + uintptr(x)))) != int32(0xff) {
  43412 			return int32(1)
  43413 		}
  43414 		goto _1
  43415 	_1:
  43416 		;
  43417 		x = x + int32(4)
  43418 	}
  43419 	return 0
  43420 }
  43421 
  43422 func AlphaReplace_C(tls *libc.TLS, src uintptr, length int32, color uint32_t) {
  43423 	var x int32
  43424 	_ = x
  43425 	x = 0
  43426 	for {
  43427 		if !(x < length) {
  43428 			break
  43429 		}
  43430 		if **(**uint32_t)(__ccgo_up(src + uintptr(x)*4))>>libc.Int32FromInt32(24) == uint32(0) {
  43431 			**(**uint32_t)(__ccgo_up(src + uintptr(x)*4)) = color
  43432 		}
  43433 		goto _1
  43434 	_1:
  43435 		;
  43436 		x = x + 1
  43437 	}
  43438 }
  43439 
  43440 //------------------------------------------------------------------------------
  43441 // Simple channel manipulations.
  43442 
  43443 func MakeARGB321(tls *libc.TLS, a int32, r int32, g int32, b int32) (r1 uint32_t) {
  43444 	return uint32(a)<<libc.Int32FromInt32(24) | uint32(r<<libc.Int32FromInt32(16)) | uint32(g<<libc.Int32FromInt32(8)) | uint32(b)
  43445 }
  43446 
  43447 func PackRGB_C(tls *libc.TLS, r uintptr, g uintptr, b uintptr, len1 int32, step int32, out uintptr) {
  43448 	var i, offset int32
  43449 	_, _ = i, offset
  43450 	offset = 0
  43451 	i = 0
  43452 	for {
  43453 		if !(i < len1) {
  43454 			break
  43455 		}
  43456 		**(**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)))))
  43457 		offset = offset + step
  43458 		goto _1
  43459 	_1:
  43460 		;
  43461 		i = i + 1
  43462 	}
  43463 }
  43464 
  43465 func WebPInitAlphaProcessing(tls *libc.TLS) {
  43466 	if libc.AtomicLoadPUintptr(uintptr(unsafe.Pointer(&WebPInitAlphaProcessing_body_last_cpuinfo_used))) == VP8GetCPUInfo {
  43467 		goto _1
  43468 	}
  43469 	WebPInitAlphaProcessing_body(tls)
  43470 	libc.AtomicStorePUintptr(uintptr(unsafe.Pointer(&WebPInitAlphaProcessing_body_last_cpuinfo_used)), VP8GetCPUInfo)
  43471 	goto _2
  43472 _2:
  43473 	;
  43474 	goto _1
  43475 _1: /**/ //
  43476 }
  43477 
  43478 var WebPInitAlphaProcessing_body_last_cpuinfo_used = uintptr(0)
  43479 
  43480 func init() {
  43481 	p := unsafe.Pointer(&WebPInitAlphaProcessing_body_last_cpuinfo_used)
  43482 	*(*uintptr)(unsafe.Add(p, 0)) = uintptr(unsafe.Pointer(&WebPInitAlphaProcessing_body_last_cpuinfo_used))
  43483 }
  43484 
  43485 func WebPInitAlphaProcessing_body(tls *libc.TLS) {
  43486 	WebPMultARGBRow = __ccgo_fp(WebPMultARGBRow_C)
  43487 	WebPMultRow = __ccgo_fp(WebPMultRow_C)
  43488 	WebPApplyAlphaMultiply4444 = __ccgo_fp(ApplyAlphaMultiply_16b_C)
  43489 	WebPPackRGB = __ccgo_fp(PackRGB_C)
  43490 	WebPApplyAlphaMultiply = __ccgo_fp(ApplyAlphaMultiply_C)
  43491 	WebPDispatchAlpha = __ccgo_fp(DispatchAlpha_C)
  43492 	WebPDispatchAlphaToGreen = __ccgo_fp(DispatchAlphaToGreen_C)
  43493 	WebPExtractAlpha = __ccgo_fp(ExtractAlpha_C)
  43494 	WebPExtractGreen = __ccgo_fp(ExtractGreen_C)
  43495 	WebPHasAlpha8b = __ccgo_fp(HasAlpha8b_C)
  43496 	WebPHasAlpha32b = __ccgo_fp(HasAlpha32b_C)
  43497 	WebPAlphaReplace = __ccgo_fp(AlphaReplace_C)
  43498 	// If defined, use CPUInfo() to overwrite some pointers with faster versions.
  43499 	if VP8GetCPUInfo != libc.UintptrFromInt32(0) {
  43500 	}
  43501 }
  43502 
  43503 func WebPInitAlphaProcessingMIPSdspR2(tls *libc.TLS) {
  43504 }
  43505 
  43506 func WebPInitAlphaProcessingNEON(tls *libc.TLS) {
  43507 }
  43508 
  43509 func WebPInitAlphaProcessingSSE2(tls *libc.TLS) {
  43510 }
  43511 
  43512 func WebPInitAlphaProcessingSSE41(tls *libc.TLS) {
  43513 }
  43514 
  43515 const SIZE_MAX22 = "_UI64_MAX"
  43516 
  43517 //------------------------------------------------------------------------------
  43518 // Mode costs
  43519 
  43520 func GetResidualCost_C(tls *libc.TLS, ctx0 int32, res uintptr) (r int32) {
  43521 	var b, cost, ctx, ctx1, last_p0, n, p0, v, v1, v11, v3, v5, v7, v9 int32
  43522 	var costs CostArrayPtr
  43523 	var t uintptr
  43524 	var v2, v6 uint8_t
  43525 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = b, cost, costs, ctx, ctx1, last_p0, n, p0, t, v, v1, v11, v2, v3, v5, v6, v7, v9
  43526 	n = (*VP8Residual)(unsafe.Pointer(res)).Ffirst
  43527 	// should be prob[VP8EncBands[n]], but it's equivalent for n=0 or 1
  43528 	p0 = int32(**(**uint8_t)(__ccgo_up((*VP8Residual)(unsafe.Pointer(res)).Fprob + uintptr(n)*33 + uintptr(ctx0)*11)))
  43529 	costs = (*VP8Residual)(unsafe.Pointer(res)).Fcosts
  43530 	t = **(**uintptr)(__ccgo_up(costs + uintptr(n)*24 + uintptr(ctx0)*8))
  43531 	if ctx0 == 0 {
  43532 		v2 = uint8(p0)
  43533 		if !(int32(1) != 0) {
  43534 			v5 = int32(VP8EntropyCost[v2])
  43535 		} else {
  43536 			v5 = int32(VP8EntropyCost[int32(255)-int32(v2)])
  43537 		}
  43538 		v3 = v5
  43539 		goto _4
  43540 	_4:
  43541 		v11 = v3
  43542 	} else {
  43543 		v11 = 0
  43544 	}
  43545 	// bit_cost(1, p0) is already incorporated in t[] tables, but only if ctx != 0
  43546 	// (as required by the syntax). For ctx0 == 0, we need to add it here or it'll
  43547 	// be missing during the loop.
  43548 	cost = v11
  43549 	if (*VP8Residual)(unsafe.Pointer(res)).Flast < 0 {
  43550 		v6 = uint8(p0)
  43551 		if !(0 != 0) {
  43552 			v9 = int32(VP8EntropyCost[v6])
  43553 		} else {
  43554 			v9 = int32(VP8EntropyCost[int32(255)-int32(v6)])
  43555 		}
  43556 		v7 = v9
  43557 		goto _8
  43558 	_8:
  43559 		return v7
  43560 	}
  43561 	for {
  43562 		if !(n < (*VP8Residual)(unsafe.Pointer(res)).Flast) {
  43563 			break
  43564 		}
  43565 		v = libc.Xabs(tls, int32(**(**int16_t)(__ccgo_up((*VP8Residual)(unsafe.Pointer(res)).Fcoeffs + uintptr(n)*2))))
  43566 		if v >= int32(2) {
  43567 			v11 = int32(2)
  43568 		} else {
  43569 			v11 = v
  43570 		}
  43571 		ctx = v11
  43572 		v3 = v
  43573 		if v3 > int32(MAX_VARIABLE_LEVEL) {
  43574 			v7 = int32(MAX_VARIABLE_LEVEL)
  43575 		} else {
  43576 			v7 = v3
  43577 		}
  43578 		v5 = int32(VP8LevelFixedCosts[v3]) + int32(**(**uint16_t)(__ccgo_up(t + uintptr(v7)*2)))
  43579 		goto _14
  43580 	_14:
  43581 		cost = cost + v5
  43582 		t = **(**uintptr)(__ccgo_up(costs + uintptr(n+int32(1))*24 + uintptr(ctx)*8))
  43583 		goto _10
  43584 	_10:
  43585 		;
  43586 		n = n + 1
  43587 	}
  43588 	// Last coefficient is always non-zero
  43589 	v1 = libc.Xabs(tls, int32(**(**int16_t)(__ccgo_up((*VP8Residual)(unsafe.Pointer(res)).Fcoeffs + uintptr(n)*2))))
  43590 	v11 = v1
  43591 	if v11 > int32(MAX_VARIABLE_LEVEL) {
  43592 		v5 = int32(MAX_VARIABLE_LEVEL)
  43593 	} else {
  43594 		v5 = v11
  43595 	}
  43596 	v3 = int32(VP8LevelFixedCosts[v11]) + int32(**(**uint16_t)(__ccgo_up(t + uintptr(v5)*2)))
  43597 	goto _18
  43598 _18:
  43599 	cost = cost + v3
  43600 	if n < int32(15) {
  43601 		b = int32(VP8EncBands[n+int32(1)])
  43602 		if v1 == int32(1) {
  43603 			v11 = int32(1)
  43604 		} else {
  43605 			v11 = int32(2)
  43606 		}
  43607 		ctx1 = v11
  43608 		last_p0 = int32(**(**uint8_t)(__ccgo_up((*VP8Residual)(unsafe.Pointer(res)).Fprob + uintptr(b)*33 + uintptr(ctx1)*11)))
  43609 		v2 = uint8(last_p0)
  43610 		if !(0 != 0) {
  43611 			v5 = int32(VP8EntropyCost[v2])
  43612 		} else {
  43613 			v5 = int32(VP8EntropyCost[int32(255)-int32(v2)])
  43614 		}
  43615 		v3 = v5
  43616 		goto _23
  43617 	_23:
  43618 		cost = cost + v3
  43619 	}
  43620 	return cost
  43621 }
  43622 
  43623 func SetResidualCoeffs_C(tls *libc.TLS, coeffs uintptr, res uintptr) {
  43624 	var n int32
  43625 	_ = n
  43626 	(*VP8Residual)(unsafe.Pointer(res)).Flast = -int32(1)
  43627 	n = int32(15)
  43628 	for {
  43629 		if !(n >= 0) {
  43630 			break
  43631 		}
  43632 		if **(**int16_t)(__ccgo_up(coeffs + uintptr(n)*2)) != 0 {
  43633 			(*VP8Residual)(unsafe.Pointer(res)).Flast = n
  43634 			break
  43635 		}
  43636 		goto _1
  43637 	_1:
  43638 		;
  43639 		n = n - 1
  43640 	}
  43641 	(*VP8Residual)(unsafe.Pointer(res)).Fcoeffs = coeffs
  43642 }
  43643 
  43644 func VP8EncDspCostInit(tls *libc.TLS) {
  43645 	if libc.AtomicLoadPUintptr(uintptr(unsafe.Pointer(&VP8EncDspCostInit_body_last_cpuinfo_used))) == VP8GetCPUInfo {
  43646 		goto _1
  43647 	}
  43648 	VP8EncDspCostInit_body(tls)
  43649 	libc.AtomicStorePUintptr(uintptr(unsafe.Pointer(&VP8EncDspCostInit_body_last_cpuinfo_used)), VP8GetCPUInfo)
  43650 	goto _2
  43651 _2:
  43652 	;
  43653 	goto _1
  43654 _1: /**/ //
  43655 }
  43656 
  43657 var VP8EncDspCostInit_body_last_cpuinfo_used = uintptr(0)
  43658 
  43659 func init() {
  43660 	p := unsafe.Pointer(&VP8EncDspCostInit_body_last_cpuinfo_used)
  43661 	*(*uintptr)(unsafe.Add(p, 0)) = uintptr(unsafe.Pointer(&VP8EncDspCostInit_body_last_cpuinfo_used))
  43662 }
  43663 
  43664 func VP8EncDspCostInit_body(tls *libc.TLS) {
  43665 	VP8GetResidualCost = __ccgo_fp(GetResidualCost_C)
  43666 	VP8SetResidualCoeffs = __ccgo_fp(SetResidualCoeffs_C)
  43667 	// If defined, use CPUInfo() to overwrite some pointers with faster versions.
  43668 	if VP8GetCPUInfo != libc.UintptrFromInt32(0) {
  43669 	}
  43670 }
  43671 
  43672 const SIZE_MAX23 = "UINT64_MAX"
  43673 
  43674 func VP8EncDspCostInitMIPS32(tls *libc.TLS) {
  43675 }
  43676 
  43677 func VP8EncDspCostInitMIPSdspR2(tls *libc.TLS) {
  43678 }
  43679 
  43680 func VP8EncDspCostInitNEON(tls *libc.TLS) {
  43681 }
  43682 
  43683 func VP8EncDspCostInitSSE2(tls *libc.TLS) {
  43684 }
  43685 
  43686 /**
  43687  * This file has no copyright assigned and is placed in the Public Domain.
  43688  * This file is part of the mingw-w64 runtime package.
  43689  * No warranty is given; refer to the file DISCLAIMER.PD within this package.
  43690  */
  43691 
  43692 /**
  43693  * This file has no copyright assigned and is placed in the Public Domain.
  43694  * This file is part of the mingw-w64 runtime package.
  43695  * No warranty is given; refer to the file DISCLAIMER.PD within this package.
  43696  */
  43697 
  43698 /*
  43699  * ISO C Standard:  7.17  Common definitions  <stddef.h>
  43700  */
  43701 
  43702 /* Copyright (C) 1989-2026 Free Software Foundation, Inc.
  43703 
  43704 This file is part of GCC.
  43705 
  43706 GCC is free software; you can redistribute it and/or modify
  43707 it under the terms of the GNU General Public License as published by
  43708 the Free Software Foundation; either version 3, or (at your option)
  43709 any later version.
  43710 
  43711 GCC is distributed in the hope that it will be useful,
  43712 but WITHOUT ANY WARRANTY; without even the implied warranty of
  43713 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  43714 GNU General Public License for more details.
  43715 
  43716 Under Section 7 of GPL version 3, you are granted additional
  43717 permissions described in the GCC Runtime Library Exception, version
  43718 3.1, as published by the Free Software Foundation.
  43719 
  43720 You should have received a copy of the GNU General Public License and
  43721 a copy of the GCC Runtime Library Exception along with this program;
  43722 see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
  43723 <http://www.gnu.org/licenses/>.  */
  43724 
  43725 /*
  43726  * ISO C Standard:  7.17  Common definitions  <stddef.h>
  43727  */
  43728 
  43729 // Copyright 2010 Google Inc. All Rights Reserved.
  43730 //
  43731 // Use of this source code is governed by a BSD-style license
  43732 // that can be found in the COPYING file in the root of the source
  43733 // tree. An additional intellectual property rights grant can be found
  43734 // in the file PATENTS. All contributing project authors may
  43735 // be found in the AUTHORS file in the root of the source tree.
  43736 // -----------------------------------------------------------------------------
  43737 //
  43738 //  Common types + memory wrappers
  43739 //
  43740 // Author: Skal (pascal.massimino@gmail.com)
  43741 
  43742 //------------------------------------------------------------------------------
  43743 // SSE2 detection.
  43744 //
  43745 
  43746 // C documentation
  43747 //
  43748 //	// apple/darwin gcc-4.0.1 defines __PIC__, but not __pic__ with -fPIC.
  43749 func GetCPUInfo(tls *libc.TLS, cpu_info uintptr, info_type int32) {
  43750 	//   __asm__ volatile (
  43751 	//     "cpuid\n"
  43752 	//     : "=a"(cpu_info[0]), "=b"(cpu_info[1]), "=c"(cpu_info[2]), "=d"(cpu_info[3])
  43753 	//     : "a"(info_type), "c"(0));
  43754 	libc.X__assert_fail(tls, __ccgo_ts+594, __ccgo_ts+629, 45, __ccgo_ts+635)
  43755 }
  43756 
  43757 // C documentation
  43758 //
  43759 //	// NaCl has no support for xgetbv or the raw opcode.
  43760 func xgetbv(tls *libc.TLS) (r uint64_t) {
  43761 	var eax, ecx, edx uint32_t
  43762 	_, _, _ = eax, ecx, edx
  43763 	ecx = uint32(0)
  43764 	// Use the raw opcode for xgetbv for compatibility with older toolchains.
  43765 	//   // Use the raw opcode for xgetbv for compatibility with older toolchains.
  43766 	//   __asm__ volatile (
  43767 	//     ".byte 0x0f, 0x01, 0xd0\n"
  43768 	//     : "=a"(eax), "=d"(edx) : "c" (ecx));
  43769 	libc.X__assert_fail(tls, __ccgo_ts+594, __ccgo_ts+629, 70, __ccgo_ts+646)
  43770 	return uint64(edx)<<libc.Int32FromInt32(32) | uint64(eax)
  43771 }
  43772 
  43773 // C documentation
  43774 //
  43775 //	// helper function for run-time detection of slow SSSE3 platforms
  43776 func CheckSlowModel(tls *libc.TLS, info int32) (r int32) {
  43777 	var family, model uint32_t
  43778 	var i size_t
  43779 	_, _, _ = family, i, model
  43780 	model = uint32(info&int32(0xf0000)>>int32(12) | info>>int32(4)&int32(0xf))
  43781 	family = uint32(info >> int32(8) & int32(0xf))
  43782 	if family == uint32(0x06) {
  43783 		i = uint64(0)
  43784 		for {
  43785 			if !(i < libc.Uint64FromInt64(6)/libc.Uint64FromInt64(1)) {
  43786 				break
  43787 			}
  43788 			if model == uint32(kSlowModels[i]) {
  43789 				return int32(1)
  43790 			}
  43791 			goto _1
  43792 		_1:
  43793 			;
  43794 			i = i + 1
  43795 		}
  43796 	}
  43797 	return 0
  43798 }
  43799 
  43800 // Table listing display models with longer latencies for the bsr instruction
  43801 // (ie 2 cycles vs 10/16 cycles) and some SSSE3 instructions like pshufb.
  43802 // Refer to Intel 64 and IA-32 Architectures Optimization Reference Manual.
  43803 var kSlowModels = [6]uint8_t{
  43804 	0: uint8(0x37),
  43805 	1: uint8(0x4a),
  43806 	2: uint8(0x4d),
  43807 	3: uint8(0x1c),
  43808 	4: uint8(0x26),
  43809 	5: uint8(0x27),
  43810 }
  43811 
  43812 func x86CPUInfo(tls *libc.TLS, feature CPUFeature) (r int32) {
  43813 	bp := tls.Alloc(16)
  43814 	defer tls.Free(16)
  43815 	var VENDOR_ID_INTEL_EBX, VENDOR_ID_INTEL_ECX, VENDOR_ID_INTEL_EDX, is_intel, max_cpuid_value int32
  43816 	var _ /* cpu_info at bp+0 */ [4]int32
  43817 	_, _, _, _, _ = VENDOR_ID_INTEL_EBX, VENDOR_ID_INTEL_ECX, VENDOR_ID_INTEL_EDX, is_intel, max_cpuid_value
  43818 	is_intel = 0
  43819 	// get the highest feature value cpuid supports
  43820 	GetCPUInfo(tls, bp, 0)
  43821 	max_cpuid_value = (**(**[4]int32)(__ccgo_up(bp)))[0]
  43822 	if max_cpuid_value < int32(1) {
  43823 		return 0
  43824 	} else {
  43825 		VENDOR_ID_INTEL_EBX = int32(0x756e6547)                                                                                                                                                                                             // uneG
  43826 		VENDOR_ID_INTEL_EDX = int32(0x49656e69)                                                                                                                                                                                             // Ieni
  43827 		VENDOR_ID_INTEL_ECX = int32(0x6c65746e)                                                                                                                                                                                             // letn
  43828 		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?
  43829 	}
  43830 	GetCPUInfo(tls, bp, int32(1))
  43831 	if feature == int32(kSSE2) {
  43832 		return libc.BoolInt32(!!((**(**[4]int32)(__ccgo_up(bp)))[int32(3)]&(libc.Int32FromInt32(1)<<libc.Int32FromInt32(26)) != 0))
  43833 	}
  43834 	if feature == int32(kSSE3) {
  43835 		return libc.BoolInt32(!!((**(**[4]int32)(__ccgo_up(bp)))[int32(2)]&(libc.Int32FromInt32(1)<<libc.Int32FromInt32(0)) != 0))
  43836 	}
  43837 	if feature == int32(kSlowSSSE3) {
  43838 		if is_intel != 0 && (**(**[4]int32)(__ccgo_up(bp)))[int32(2)]&(libc.Int32FromInt32(1)<<libc.Int32FromInt32(9)) != 0 { // SSSE3?
  43839 			return CheckSlowModel(tls, (**(**[4]int32)(__ccgo_up(bp)))[0])
  43840 		}
  43841 		return 0
  43842 	}
  43843 	if feature == int32(kSSE4_1) {
  43844 		return libc.BoolInt32(!!((**(**[4]int32)(__ccgo_up(bp)))[int32(2)]&(libc.Int32FromInt32(1)<<libc.Int32FromInt32(19)) != 0))
  43845 	}
  43846 	if feature == int32(kAVX) {
  43847 		// bits 27 (OSXSAVE) & 28 (256-bit AVX)
  43848 		if (**(**[4]int32)(__ccgo_up(bp)))[int32(2)]&int32(0x18000000) == int32(0x18000000) {
  43849 			// XMM state and YMM state enabled by the OS.
  43850 			return libc.BoolInt32(xgetbv(tls)&uint64(0x6) == uint64(0x6))
  43851 		}
  43852 	}
  43853 	if feature == int32(kAVX2) {
  43854 		if x86CPUInfo(tls, int32(kAVX)) != 0 && max_cpuid_value >= int32(7) {
  43855 			GetCPUInfo(tls, bp, int32(7))
  43856 			return libc.BoolInt32(!!((**(**[4]int32)(__ccgo_up(bp)))[int32(1)]&(libc.Int32FromInt32(1)<<libc.Int32FromInt32(5)) != 0))
  43857 		}
  43858 	}
  43859 	return 0
  43860 }
  43861 
  43862 func init() {
  43863 	p := unsafe.Pointer(&VP8GetCPUInfo)
  43864 	*(*uintptr)(unsafe.Add(p, 0)) = __ccgo_fp(x86CPUInfo)
  43865 }
  43866 
  43867 var kHashMul14 = uint32(0x1e35a7bd)
  43868 
  43869 //------------------------------------------------------------------------------
  43870 
  43871 // Copyright 2010 Google Inc. All Rights Reserved.
  43872 //
  43873 // Use of this source code is governed by a BSD-style license
  43874 // that can be found in the COPYING file in the root of the source
  43875 // tree. An additional intellectual property rights grant can be found
  43876 // in the file PATENTS. All contributing project authors may
  43877 // be found in the AUTHORS file in the root of the source tree.
  43878 // -----------------------------------------------------------------------------
  43879 //
  43880 //  Common types + memory wrappers
  43881 //
  43882 // Author: Skal (pascal.massimino@gmail.com)
  43883 
  43884 //------------------------------------------------------------------------------
  43885 
  43886 func clip_8b1(tls *libc.TLS, v int32) (r uint8_t) {
  43887 	var v1, v2 int32
  43888 	_, _ = v1, v2
  43889 	if !(v & ^libc.Int32FromInt32(0xff) != 0) {
  43890 		v1 = v
  43891 	} else {
  43892 		if v < 0 {
  43893 			v2 = 0
  43894 		} else {
  43895 			v2 = int32(255)
  43896 		}
  43897 		v1 = v2
  43898 	}
  43899 	return uint8(v1)
  43900 }
  43901 
  43902 //------------------------------------------------------------------------------
  43903 // Transforms (Paragraph 14.4)
  43904 
  43905 func TransformOne_C(tls *libc.TLS, in uintptr, dst uintptr) {
  43906 	bp := tls.Alloc(64)
  43907 	defer tls.Free(64)
  43908 	var a, a1, b, b1, c, c1, d, d1, dc, i int32
  43909 	var tmp uintptr
  43910 	var _ /* C at bp+0 */ [16]int32
  43911 	_, _, _, _, _, _, _, _, _, _, _ = a, a1, b, b1, c, c1, d, d1, dc, i, tmp
  43912 	tmp = bp
  43913 	i = 0
  43914 	for {
  43915 		if !(i < int32(4)) {
  43916 			break
  43917 		} // vertical pass
  43918 		a = int32(**(**int16_t)(__ccgo_up(in))) + int32(**(**int16_t)(__ccgo_up(in + 8*2)))                                                                                                                                       // [-4096, 4094]
  43919 		b = int32(**(**int16_t)(__ccgo_up(in))) - int32(**(**int16_t)(__ccgo_up(in + 8*2)))                                                                                                                                       // [-4095, 4095]
  43920 		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]
  43921 		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]
  43922 		**(**int32)(__ccgo_up(tmp)) = a + d                                                                                                                                                                                       // [-7881, 7875]
  43923 		**(**int32)(__ccgo_up(tmp + 1*4)) = b + c                                                                                                                                                                                 // [-7878, 7878]
  43924 		**(**int32)(__ccgo_up(tmp + 2*4)) = b - c                                                                                                                                                                                 // [-7878, 7878]
  43925 		**(**int32)(__ccgo_up(tmp + 3*4)) = a - d                                                                                                                                                                                 // [-7877, 7879]
  43926 		tmp = tmp + uintptr(4)*4
  43927 		in += 2
  43928 		goto _1
  43929 	_1:
  43930 		;
  43931 		i = i + 1
  43932 	}
  43933 	// Each pass is expanding the dynamic range by ~3.85 (upper bound).
  43934 	// The exact value is (2. + (20091 + 35468) / 65536).
  43935 	// After the second pass, maximum interval is [-3794, 3794], assuming
  43936 	// an input in [-2048, 2047] interval. We then need to add a dst value
  43937 	// in the [0, 255] range.
  43938 	// In the worst case scenario, the input to clip_8b() can be as large as
  43939 	// [-60713, 60968].
  43940 	tmp = bp
  43941 	i = 0
  43942 	for {
  43943 		if !(i < int32(4)) {
  43944 			break
  43945 		} // horizontal pass
  43946 		dc = **(**int32)(__ccgo_up(tmp)) + int32(4)
  43947 		a1 = dc + **(**int32)(__ccgo_up(tmp + 8*4))
  43948 		b1 = dc - **(**int32)(__ccgo_up(tmp + 8*4))
  43949 		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)))
  43950 		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)
  43951 		**(**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))
  43952 		**(**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))
  43953 		**(**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))
  43954 		**(**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))
  43955 		tmp += 4
  43956 		dst = dst + uintptr(BPS)
  43957 		goto _2
  43958 	_2:
  43959 		;
  43960 		i = i + 1
  43961 	}
  43962 }
  43963 
  43964 // C documentation
  43965 //
  43966 //	// Simplified transform when only in[0], in[1] and in[4] are non-zero
  43967 func TransformAC3_C(tls *libc.TLS, in uintptr, dst uintptr) {
  43968 	var DC, DC1, DC2, DC3, a, c1, c4, d1, d4 int32
  43969 	_, _, _, _, _, _, _, _, _ = DC, DC1, DC2, DC3, a, c1, c4, d1, d4
  43970 	a = int32(**(**int16_t)(__ccgo_up(in))) + int32(4)
  43971 	c4 = int32(**(**int16_t)(__ccgo_up(in + 4*2))) * libc.Int32FromInt32(WEBP_TRANSFORM_AC3_C2) >> libc.Int32FromInt32(16)
  43972 	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)))
  43973 	c1 = int32(**(**int16_t)(__ccgo_up(in + 1*2))) * libc.Int32FromInt32(WEBP_TRANSFORM_AC3_C2) >> libc.Int32FromInt32(16)
  43974 	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)))
  43975 	DC = a + d4
  43976 	**(**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))
  43977 	**(**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))
  43978 	**(**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))
  43979 	**(**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))
  43980 	DC1 = a + c4
  43981 	**(**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))
  43982 	**(**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))
  43983 	**(**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))
  43984 	**(**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))
  43985 	DC2 = a - c4
  43986 	**(**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))
  43987 	**(**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))
  43988 	**(**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))
  43989 	**(**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))
  43990 	DC3 = a - d4
  43991 	**(**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))
  43992 	**(**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))
  43993 	**(**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))
  43994 	**(**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))
  43995 }
  43996 
  43997 func TransformTwo_C(tls *libc.TLS, in uintptr, dst uintptr, do_two int32) {
  43998 	TransformOne_C(tls, in, dst)
  43999 	if do_two != 0 {
  44000 		TransformOne_C(tls, in+uintptr(16)*2, dst+uintptr(4))
  44001 	}
  44002 }
  44003 
  44004 func TransformUV_C(tls *libc.TLS, in uintptr, dst uintptr) {
  44005 	(*(*func(*libc.TLS, uintptr, uintptr, int32))(unsafe.Pointer(&struct{ uintptr }{VP8Transform})))(tls, in+uintptr(libc.Int32FromInt32(0)*libc.Int32FromInt32(16))*2, dst, int32(1))
  44006 	(*(*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))
  44007 }
  44008 
  44009 func TransformDC_C(tls *libc.TLS, in uintptr, dst uintptr) {
  44010 	var DC, i, j int32
  44011 	_, _, _ = DC, i, j
  44012 	DC = int32(**(**int16_t)(__ccgo_up(in))) + int32(4)
  44013 	j = 0
  44014 	for {
  44015 		if !(j < int32(4)) {
  44016 			break
  44017 		}
  44018 		i = 0
  44019 		for {
  44020 			if !(i < int32(4)) {
  44021 				break
  44022 			}
  44023 			**(**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))
  44024 			goto _2
  44025 		_2:
  44026 			;
  44027 			i = i + 1
  44028 		}
  44029 		goto _1
  44030 	_1:
  44031 		;
  44032 		j = j + 1
  44033 	}
  44034 }
  44035 
  44036 func TransformDCUV_C(tls *libc.TLS, in uintptr, dst uintptr) {
  44037 	if **(**int16_t)(__ccgo_up(in + uintptr(libc.Int32FromInt32(0)*libc.Int32FromInt32(16))*2)) != 0 {
  44038 		(*(*func(*libc.TLS, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8TransformDC})))(tls, in+uintptr(libc.Int32FromInt32(0)*libc.Int32FromInt32(16))*2, dst)
  44039 	}
  44040 	if **(**int16_t)(__ccgo_up(in + uintptr(libc.Int32FromInt32(1)*libc.Int32FromInt32(16))*2)) != 0 {
  44041 		(*(*func(*libc.TLS, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8TransformDC})))(tls, in+uintptr(libc.Int32FromInt32(1)*libc.Int32FromInt32(16))*2, dst+uintptr(4))
  44042 	}
  44043 	if **(**int16_t)(__ccgo_up(in + uintptr(libc.Int32FromInt32(2)*libc.Int32FromInt32(16))*2)) != 0 {
  44044 		(*(*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)))
  44045 	}
  44046 	if **(**int16_t)(__ccgo_up(in + uintptr(libc.Int32FromInt32(3)*libc.Int32FromInt32(16))*2)) != 0 {
  44047 		(*(*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))
  44048 	}
  44049 }
  44050 
  44051 //------------------------------------------------------------------------------
  44052 // Paragraph 14.3
  44053 
  44054 func TransformWHT_C(tls *libc.TLS, in uintptr, out uintptr) {
  44055 	var a0, a01, a1, a11, a2, a21, a3, a31, dc, i int32
  44056 	var tmp [16]int32
  44057 	_, _, _, _, _, _, _, _, _, _, _ = a0, a01, a1, a11, a2, a21, a3, a31, dc, i, tmp
  44058 	i = 0
  44059 	for {
  44060 		if !(i < int32(4)) {
  44061 			break
  44062 		}
  44063 		a0 = int32(**(**int16_t)(__ccgo_up(in + uintptr(0+i)*2))) + int32(**(**int16_t)(__ccgo_up(in + uintptr(int32(12)+i)*2)))
  44064 		a1 = int32(**(**int16_t)(__ccgo_up(in + uintptr(int32(4)+i)*2))) + int32(**(**int16_t)(__ccgo_up(in + uintptr(int32(8)+i)*2)))
  44065 		a2 = int32(**(**int16_t)(__ccgo_up(in + uintptr(int32(4)+i)*2))) - int32(**(**int16_t)(__ccgo_up(in + uintptr(int32(8)+i)*2)))
  44066 		a3 = int32(**(**int16_t)(__ccgo_up(in + uintptr(0+i)*2))) - int32(**(**int16_t)(__ccgo_up(in + uintptr(int32(12)+i)*2)))
  44067 		tmp[0+i] = a0 + a1
  44068 		tmp[int32(8)+i] = a0 - a1
  44069 		tmp[int32(4)+i] = a3 + a2
  44070 		tmp[int32(12)+i] = a3 - a2
  44071 		goto _1
  44072 	_1:
  44073 		;
  44074 		i = i + 1
  44075 	}
  44076 	i = 0
  44077 	for {
  44078 		if !(i < int32(4)) {
  44079 			break
  44080 		}
  44081 		dc = tmp[0+i*int32(4)] + int32(3) // w/ rounder
  44082 		a01 = dc + tmp[int32(3)+i*int32(4)]
  44083 		a11 = tmp[int32(1)+i*int32(4)] + tmp[int32(2)+i*int32(4)]
  44084 		a21 = tmp[int32(1)+i*int32(4)] - tmp[int32(2)+i*int32(4)]
  44085 		a31 = dc - tmp[int32(3)+i*int32(4)]
  44086 		**(**int16_t)(__ccgo_up(out)) = int16((a01 + a11) >> int32(3))
  44087 		**(**int16_t)(__ccgo_up(out + 16*2)) = int16((a31 + a21) >> int32(3))
  44088 		**(**int16_t)(__ccgo_up(out + 32*2)) = int16((a01 - a11) >> int32(3))
  44089 		**(**int16_t)(__ccgo_up(out + 48*2)) = int16((a31 - a21) >> int32(3))
  44090 		out = out + uintptr(64)*2
  44091 		goto _2
  44092 	_2:
  44093 		;
  44094 		i = i + 1
  44095 	}
  44096 }
  44097 
  44098 //------------------------------------------------------------------------------
  44099 // Intra predictions
  44100 
  44101 func TrueMotion(tls *libc.TLS, dst uintptr, size int32) {
  44102 	var clip, clip0, top uintptr
  44103 	var x, y int32
  44104 	_, _, _, _, _ = clip, clip0, top, x, y
  44105 	top = dst - uintptr(BPS)
  44106 	clip0 = VP8kclip1 - uintptr(**(**uint8_t)(__ccgo_up(top + uintptr(-libc.Int32FromInt32(1)))))
  44107 	y = 0
  44108 	for {
  44109 		if !(y < size) {
  44110 			break
  44111 		}
  44112 		clip = clip0 + uintptr(**(**uint8_t)(__ccgo_up(dst + uintptr(-libc.Int32FromInt32(1)))))
  44113 		x = 0
  44114 		for {
  44115 			if !(x < size) {
  44116 				break
  44117 			}
  44118 			**(**uint8_t)(__ccgo_up(dst + uintptr(x))) = **(**uint8_t)(__ccgo_up(clip + uintptr(**(**uint8_t)(__ccgo_up(top + uintptr(x))))))
  44119 			goto _2
  44120 		_2:
  44121 			;
  44122 			x = x + 1
  44123 		}
  44124 		dst = dst + uintptr(BPS)
  44125 		goto _1
  44126 	_1:
  44127 		;
  44128 		y = y + 1
  44129 	}
  44130 }
  44131 
  44132 func TM4_C(tls *libc.TLS, dst uintptr) {
  44133 	TrueMotion(tls, dst, int32(4))
  44134 }
  44135 
  44136 func TM8uv_C(tls *libc.TLS, dst uintptr) {
  44137 	TrueMotion(tls, dst, int32(8))
  44138 }
  44139 
  44140 func TM16_C(tls *libc.TLS, dst uintptr) {
  44141 	TrueMotion(tls, dst, int32(16))
  44142 }
  44143 
  44144 //------------------------------------------------------------------------------
  44145 // 16x16
  44146 
  44147 func VE16_C(tls *libc.TLS, dst uintptr) {
  44148 	var j int32
  44149 	_ = j
  44150 	j = 0
  44151 	for {
  44152 		if !(j < int32(16)) {
  44153 			break
  44154 		}
  44155 		libc.Xmemcpy(tls, dst+uintptr(j*int32(BPS)), dst-uintptr(BPS), uint64(16))
  44156 		goto _1
  44157 	_1:
  44158 		;
  44159 		j = j + 1
  44160 	}
  44161 }
  44162 
  44163 func HE16_C(tls *libc.TLS, dst uintptr) {
  44164 	var j int32
  44165 	_ = j
  44166 	j = int32(16)
  44167 	for {
  44168 		if !(j > 0) {
  44169 			break
  44170 		}
  44171 		libc.Xmemset(tls, dst, int32(**(**uint8_t)(__ccgo_up(dst + uintptr(-libc.Int32FromInt32(1))))), uint64(16))
  44172 		dst = dst + uintptr(BPS)
  44173 		goto _1
  44174 	_1:
  44175 		;
  44176 		j = j - 1
  44177 	}
  44178 }
  44179 
  44180 func Put16(tls *libc.TLS, v int32, dst uintptr) {
  44181 	var j int32
  44182 	_ = j
  44183 	j = 0
  44184 	for {
  44185 		if !(j < int32(16)) {
  44186 			break
  44187 		}
  44188 		libc.Xmemset(tls, dst+uintptr(j*int32(BPS)), v, uint64(16))
  44189 		goto _1
  44190 	_1:
  44191 		;
  44192 		j = j + 1
  44193 	}
  44194 }
  44195 
  44196 func DC16_C(tls *libc.TLS, dst uintptr) {
  44197 	var DC, j int32
  44198 	_, _ = DC, j // DC
  44199 	DC = int32(16)
  44200 	j = 0
  44201 	for {
  44202 		if !(j < int32(16)) {
  44203 			break
  44204 		}
  44205 		DC = DC + (int32(**(**uint8_t)(__ccgo_up(dst + uintptr(-int32(1)+j*int32(BPS))))) + int32(**(**uint8_t)(__ccgo_up(dst + uintptr(j-int32(BPS))))))
  44206 		goto _1
  44207 	_1:
  44208 		;
  44209 		j = j + 1
  44210 	}
  44211 	Put16(tls, DC>>int32(5), dst)
  44212 }
  44213 
  44214 func DC16NoTop_C(tls *libc.TLS, dst uintptr) {
  44215 	var DC, j int32
  44216 	_, _ = DC, j // DC with top samples not available
  44217 	DC = int32(8)
  44218 	j = 0
  44219 	for {
  44220 		if !(j < int32(16)) {
  44221 			break
  44222 		}
  44223 		DC = DC + int32(**(**uint8_t)(__ccgo_up(dst + uintptr(-int32(1)+j*int32(BPS)))))
  44224 		goto _1
  44225 	_1:
  44226 		;
  44227 		j = j + 1
  44228 	}
  44229 	Put16(tls, DC>>int32(4), dst)
  44230 }
  44231 
  44232 func DC16NoLeft_C(tls *libc.TLS, dst uintptr) {
  44233 	var DC, i int32
  44234 	_, _ = DC, i // DC with left samples not available
  44235 	DC = int32(8)
  44236 	i = 0
  44237 	for {
  44238 		if !(i < int32(16)) {
  44239 			break
  44240 		}
  44241 		DC = DC + int32(**(**uint8_t)(__ccgo_up(dst + uintptr(i-int32(BPS)))))
  44242 		goto _1
  44243 	_1:
  44244 		;
  44245 		i = i + 1
  44246 	}
  44247 	Put16(tls, DC>>int32(4), dst)
  44248 }
  44249 
  44250 func DC16NoTopLeft_C(tls *libc.TLS, dst uintptr) {
  44251 	// DC with no top and left samples
  44252 	Put16(tls, int32(0x80), dst)
  44253 }
  44254 
  44255 //------------------------------------------------------------------------------
  44256 // 4x4
  44257 
  44258 func VE4_C(tls *libc.TLS, dst uintptr) {
  44259 	bp := tls.Alloc(16)
  44260 	defer tls.Free(16)
  44261 	var i int32
  44262 	var top uintptr
  44263 	var _ /* vals at bp+0 */ [4]uint8_t
  44264 	_, _ = i, top // vertical
  44265 	top = dst - uintptr(BPS)
  44266 	**(**[4]uint8_t)(__ccgo_up(bp)) = [4]uint8_t{
  44267 		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)),
  44268 		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)),
  44269 		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)),
  44270 		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)),
  44271 	}
  44272 	i = 0
  44273 	for {
  44274 		if !(i < int32(4)) {
  44275 			break
  44276 		}
  44277 		libc.Xmemcpy(tls, dst+uintptr(i*int32(BPS)), bp, uint64(4))
  44278 		goto _1
  44279 	_1:
  44280 		;
  44281 		i = i + 1
  44282 	}
  44283 }
  44284 
  44285 func HE4_C(tls *libc.TLS, dst uintptr) {
  44286 	bp := tls.Alloc(16)
  44287 	defer tls.Free(16)
  44288 	var A, B, C, D, E int32
  44289 	var v1 uint32_t
  44290 	_, _, _, _, _, _ = A, B, C, D, E, v1 // horizontal
  44291 	A = int32(**(**uint8_t)(__ccgo_up(dst + uintptr(-libc.Int32FromInt32(1)-libc.Int32FromInt32(BPS)))))
  44292 	B = int32(**(**uint8_t)(__ccgo_up(dst + uintptr(-libc.Int32FromInt32(1)))))
  44293 	C = int32(**(**uint8_t)(__ccgo_up(dst + uintptr(-libc.Int32FromInt32(1)+libc.Int32FromInt32(BPS)))))
  44294 	D = int32(**(**uint8_t)(__ccgo_up(dst + uintptr(-libc.Int32FromInt32(1)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))))
  44295 	E = int32(**(**uint8_t)(__ccgo_up(dst + uintptr(-libc.Int32FromInt32(1)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))))
  44296 	v1 = uint32(0x01010101) * uint32(uint8((A+libc.Int32FromInt32(2)*B+C+libc.Int32FromInt32(2))>>libc.Int32FromInt32(2)))
  44297 	*(*uint32_t)(unsafe.Pointer(bp)) = v1
  44298 	libc.Xmemcpy(tls, dst+uintptr(libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)), bp, uint64(4))
  44299 	v1 = uint32(0x01010101) * uint32(uint8((B+libc.Int32FromInt32(2)*C+D+libc.Int32FromInt32(2))>>libc.Int32FromInt32(2)))
  44300 	*(*uint32_t)(unsafe.Pointer(bp)) = v1
  44301 	libc.Xmemcpy(tls, dst+uintptr(libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)), bp, uint64(4))
  44302 	v1 = uint32(0x01010101) * uint32(uint8((C+libc.Int32FromInt32(2)*D+E+libc.Int32FromInt32(2))>>libc.Int32FromInt32(2)))
  44303 	*(*uint32_t)(unsafe.Pointer(bp)) = v1
  44304 	libc.Xmemcpy(tls, dst+uintptr(libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)), bp, uint64(4))
  44305 	v1 = uint32(0x01010101) * uint32(uint8((D+libc.Int32FromInt32(2)*E+E+libc.Int32FromInt32(2))>>libc.Int32FromInt32(2)))
  44306 	*(*uint32_t)(unsafe.Pointer(bp)) = v1
  44307 	libc.Xmemcpy(tls, dst+uintptr(libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)), bp, uint64(4))
  44308 }
  44309 
  44310 func DC4_C(tls *libc.TLS, dst uintptr) {
  44311 	var dc uint32_t
  44312 	var i int32
  44313 	_, _ = dc, i // DC
  44314 	dc = uint32(4)
  44315 	i = 0
  44316 	for {
  44317 		if !(i < int32(4)) {
  44318 			break
  44319 		}
  44320 		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))))))
  44321 		goto _1
  44322 	_1:
  44323 		;
  44324 		i = i + 1
  44325 	}
  44326 	dc = dc >> uint32(3)
  44327 	i = 0
  44328 	for {
  44329 		if !(i < int32(4)) {
  44330 			break
  44331 		}
  44332 		libc.Xmemset(tls, dst+uintptr(i*int32(BPS)), int32(dc), uint64(4))
  44333 		goto _2
  44334 	_2:
  44335 		;
  44336 		i = i + 1
  44337 	}
  44338 }
  44339 
  44340 func RD4_C(tls *libc.TLS, dst uintptr) {
  44341 	var A, B, C, D, I, J, K, L, X int32
  44342 	var v1, v2, v3 uint8_t
  44343 	_, _, _, _, _, _, _, _, _, _, _, _ = A, B, C, D, I, J, K, L, X, v1, v2, v3 // Down-right
  44344 	I = int32(**(**uint8_t)(__ccgo_up(dst + uintptr(-libc.Int32FromInt32(1)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))))
  44345 	J = int32(**(**uint8_t)(__ccgo_up(dst + uintptr(-libc.Int32FromInt32(1)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))))
  44346 	K = int32(**(**uint8_t)(__ccgo_up(dst + uintptr(-libc.Int32FromInt32(1)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))))
  44347 	L = int32(**(**uint8_t)(__ccgo_up(dst + uintptr(-libc.Int32FromInt32(1)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))))
  44348 	X = int32(**(**uint8_t)(__ccgo_up(dst + uintptr(-libc.Int32FromInt32(1)-libc.Int32FromInt32(BPS)))))
  44349 	A = int32(**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)-libc.Int32FromInt32(BPS)))))
  44350 	B = int32(**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)-libc.Int32FromInt32(BPS)))))
  44351 	C = int32(**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)-libc.Int32FromInt32(BPS)))))
  44352 	D = int32(**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)-libc.Int32FromInt32(BPS)))))
  44353 	**(**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))
  44354 	v1 = uint8((I + libc.Int32FromInt32(2)*J + K + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  44355 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = v1
  44356 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = v1
  44357 	v2 = uint8((X + libc.Int32FromInt32(2)*I + J + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  44358 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = v2
  44359 	v1 = v2
  44360 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = v1
  44361 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = v1
  44362 	v3 = uint8((A + libc.Int32FromInt32(2)*X + I + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  44363 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = v3
  44364 	v2 = v3
  44365 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = v2
  44366 	v1 = v2
  44367 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = v1
  44368 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = v1
  44369 	v2 = uint8((B + libc.Int32FromInt32(2)*A + X + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  44370 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = v2
  44371 	v1 = v2
  44372 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = v1
  44373 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = v1
  44374 	v1 = uint8((C + libc.Int32FromInt32(2)*B + A + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  44375 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = v1
  44376 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = v1
  44377 	**(**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))
  44378 }
  44379 
  44380 func LD4_C(tls *libc.TLS, dst uintptr) {
  44381 	var A, B, C, D, E, F, G, H int32
  44382 	var v1, v2, v3 uint8_t
  44383 	_, _, _, _, _, _, _, _, _, _, _ = A, B, C, D, E, F, G, H, v1, v2, v3 // Down-Left
  44384 	A = int32(**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)-libc.Int32FromInt32(BPS)))))
  44385 	B = int32(**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)-libc.Int32FromInt32(BPS)))))
  44386 	C = int32(**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)-libc.Int32FromInt32(BPS)))))
  44387 	D = int32(**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)-libc.Int32FromInt32(BPS)))))
  44388 	E = int32(**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(4)-libc.Int32FromInt32(BPS)))))
  44389 	F = int32(**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(5)-libc.Int32FromInt32(BPS)))))
  44390 	G = int32(**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(6)-libc.Int32FromInt32(BPS)))))
  44391 	H = int32(**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(7)-libc.Int32FromInt32(BPS)))))
  44392 	**(**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))
  44393 	v1 = uint8((B + libc.Int32FromInt32(2)*C + D + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  44394 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = v1
  44395 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = v1
  44396 	v2 = uint8((C + libc.Int32FromInt32(2)*D + E + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  44397 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = v2
  44398 	v1 = v2
  44399 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = v1
  44400 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = v1
  44401 	v3 = uint8((D + libc.Int32FromInt32(2)*E + F + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  44402 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = v3
  44403 	v2 = v3
  44404 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = v2
  44405 	v1 = v2
  44406 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = v1
  44407 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = v1
  44408 	v2 = uint8((E + libc.Int32FromInt32(2)*F + G + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  44409 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = v2
  44410 	v1 = v2
  44411 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = v1
  44412 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = v1
  44413 	v1 = uint8((F + libc.Int32FromInt32(2)*G + H + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  44414 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = v1
  44415 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = v1
  44416 	**(**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))
  44417 }
  44418 
  44419 func VR4_C(tls *libc.TLS, dst uintptr) {
  44420 	var A, B, C, D, I, J, K, X int32
  44421 	var v1 uint8_t
  44422 	_, _, _, _, _, _, _, _, _ = A, B, C, D, I, J, K, X, v1 // Vertical-Right
  44423 	I = int32(**(**uint8_t)(__ccgo_up(dst + uintptr(-libc.Int32FromInt32(1)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))))
  44424 	J = int32(**(**uint8_t)(__ccgo_up(dst + uintptr(-libc.Int32FromInt32(1)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))))
  44425 	K = int32(**(**uint8_t)(__ccgo_up(dst + uintptr(-libc.Int32FromInt32(1)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))))
  44426 	X = int32(**(**uint8_t)(__ccgo_up(dst + uintptr(-libc.Int32FromInt32(1)-libc.Int32FromInt32(BPS)))))
  44427 	A = int32(**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)-libc.Int32FromInt32(BPS)))))
  44428 	B = int32(**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)-libc.Int32FromInt32(BPS)))))
  44429 	C = int32(**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)-libc.Int32FromInt32(BPS)))))
  44430 	D = int32(**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)-libc.Int32FromInt32(BPS)))))
  44431 	v1 = uint8((X + A + libc.Int32FromInt32(1)) >> libc.Int32FromInt32(1))
  44432 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = v1
  44433 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = v1
  44434 	v1 = uint8((A + B + libc.Int32FromInt32(1)) >> libc.Int32FromInt32(1))
  44435 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = v1
  44436 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = v1
  44437 	v1 = uint8((B + C + libc.Int32FromInt32(1)) >> libc.Int32FromInt32(1))
  44438 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = v1
  44439 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = v1
  44440 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = uint8((C + D + libc.Int32FromInt32(1)) >> libc.Int32FromInt32(1))
  44441 	**(**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))
  44442 	**(**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))
  44443 	v1 = uint8((I + libc.Int32FromInt32(2)*X + A + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  44444 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = v1
  44445 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = v1
  44446 	v1 = uint8((X + libc.Int32FromInt32(2)*A + B + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  44447 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = v1
  44448 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = v1
  44449 	v1 = uint8((A + libc.Int32FromInt32(2)*B + C + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  44450 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = v1
  44451 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = v1
  44452 	**(**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))
  44453 }
  44454 
  44455 func VL4_C(tls *libc.TLS, dst uintptr) {
  44456 	var A, B, C, D, E, F, G, H int32
  44457 	var v1 uint8_t
  44458 	_, _, _, _, _, _, _, _, _ = A, B, C, D, E, F, G, H, v1 // Vertical-Left
  44459 	A = int32(**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)-libc.Int32FromInt32(BPS)))))
  44460 	B = int32(**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)-libc.Int32FromInt32(BPS)))))
  44461 	C = int32(**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)-libc.Int32FromInt32(BPS)))))
  44462 	D = int32(**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)-libc.Int32FromInt32(BPS)))))
  44463 	E = int32(**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(4)-libc.Int32FromInt32(BPS)))))
  44464 	F = int32(**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(5)-libc.Int32FromInt32(BPS)))))
  44465 	G = int32(**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(6)-libc.Int32FromInt32(BPS)))))
  44466 	H = int32(**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(7)-libc.Int32FromInt32(BPS)))))
  44467 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = uint8((A + B + libc.Int32FromInt32(1)) >> libc.Int32FromInt32(1))
  44468 	v1 = uint8((B + C + libc.Int32FromInt32(1)) >> libc.Int32FromInt32(1))
  44469 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = v1
  44470 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = v1
  44471 	v1 = uint8((C + D + libc.Int32FromInt32(1)) >> libc.Int32FromInt32(1))
  44472 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = v1
  44473 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = v1
  44474 	v1 = uint8((D + E + libc.Int32FromInt32(1)) >> libc.Int32FromInt32(1))
  44475 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = v1
  44476 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = v1
  44477 	**(**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))
  44478 	v1 = uint8((B + libc.Int32FromInt32(2)*C + D + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  44479 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = v1
  44480 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = v1
  44481 	v1 = uint8((C + libc.Int32FromInt32(2)*D + E + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  44482 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = v1
  44483 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = v1
  44484 	v1 = uint8((D + libc.Int32FromInt32(2)*E + F + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  44485 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = v1
  44486 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = v1
  44487 	**(**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))
  44488 	**(**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))
  44489 }
  44490 
  44491 func HU4_C(tls *libc.TLS, dst uintptr) {
  44492 	var I, J, K, L int32
  44493 	var v1, v2, v3, v4, v5 uint8_t
  44494 	_, _, _, _, _, _, _, _, _ = I, J, K, L, v1, v2, v3, v4, v5 // Horizontal-Up
  44495 	I = int32(**(**uint8_t)(__ccgo_up(dst + uintptr(-libc.Int32FromInt32(1)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))))
  44496 	J = int32(**(**uint8_t)(__ccgo_up(dst + uintptr(-libc.Int32FromInt32(1)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))))
  44497 	K = int32(**(**uint8_t)(__ccgo_up(dst + uintptr(-libc.Int32FromInt32(1)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))))
  44498 	L = int32(**(**uint8_t)(__ccgo_up(dst + uintptr(-libc.Int32FromInt32(1)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))))
  44499 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = uint8((I + J + libc.Int32FromInt32(1)) >> libc.Int32FromInt32(1))
  44500 	v1 = uint8((J + K + libc.Int32FromInt32(1)) >> libc.Int32FromInt32(1))
  44501 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = v1
  44502 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = v1
  44503 	v1 = uint8((K + L + libc.Int32FromInt32(1)) >> libc.Int32FromInt32(1))
  44504 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = v1
  44505 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = v1
  44506 	**(**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))
  44507 	v1 = uint8((J + libc.Int32FromInt32(2)*K + L + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  44508 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = v1
  44509 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = v1
  44510 	v1 = uint8((K + libc.Int32FromInt32(2)*L + L + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  44511 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = v1
  44512 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = v1
  44513 	v5 = uint8(L)
  44514 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = v5
  44515 	v4 = v5
  44516 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = v4
  44517 	v3 = v4
  44518 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = v3
  44519 	v2 = v3
  44520 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = v2
  44521 	v1 = v2
  44522 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = v1
  44523 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = v1
  44524 }
  44525 
  44526 func HD4_C(tls *libc.TLS, dst uintptr) {
  44527 	var A, B, C, I, J, K, L, X int32
  44528 	var v1 uint8_t
  44529 	_, _, _, _, _, _, _, _, _ = A, B, C, I, J, K, L, X, v1 // Horizontal-Down
  44530 	I = int32(**(**uint8_t)(__ccgo_up(dst + uintptr(-libc.Int32FromInt32(1)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))))
  44531 	J = int32(**(**uint8_t)(__ccgo_up(dst + uintptr(-libc.Int32FromInt32(1)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))))
  44532 	K = int32(**(**uint8_t)(__ccgo_up(dst + uintptr(-libc.Int32FromInt32(1)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))))
  44533 	L = int32(**(**uint8_t)(__ccgo_up(dst + uintptr(-libc.Int32FromInt32(1)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))))
  44534 	X = int32(**(**uint8_t)(__ccgo_up(dst + uintptr(-libc.Int32FromInt32(1)-libc.Int32FromInt32(BPS)))))
  44535 	A = int32(**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)-libc.Int32FromInt32(BPS)))))
  44536 	B = int32(**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)-libc.Int32FromInt32(BPS)))))
  44537 	C = int32(**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)-libc.Int32FromInt32(BPS)))))
  44538 	v1 = uint8((I + X + libc.Int32FromInt32(1)) >> libc.Int32FromInt32(1))
  44539 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = v1
  44540 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = v1
  44541 	v1 = uint8((J + I + libc.Int32FromInt32(1)) >> libc.Int32FromInt32(1))
  44542 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = v1
  44543 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = v1
  44544 	v1 = uint8((K + J + libc.Int32FromInt32(1)) >> libc.Int32FromInt32(1))
  44545 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = v1
  44546 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = v1
  44547 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = uint8((L + K + libc.Int32FromInt32(1)) >> libc.Int32FromInt32(1))
  44548 	**(**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))
  44549 	**(**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))
  44550 	v1 = uint8((I + libc.Int32FromInt32(2)*X + A + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  44551 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = v1
  44552 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = v1
  44553 	v1 = uint8((J + libc.Int32FromInt32(2)*I + X + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  44554 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = v1
  44555 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = v1
  44556 	v1 = uint8((K + libc.Int32FromInt32(2)*J + I + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  44557 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = v1
  44558 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = v1
  44559 	**(**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))
  44560 }
  44561 
  44562 //------------------------------------------------------------------------------
  44563 // Chroma
  44564 
  44565 func VE8uv_C(tls *libc.TLS, dst uintptr) {
  44566 	var j int32
  44567 	_ = j
  44568 	j = 0
  44569 	for {
  44570 		if !(j < int32(8)) {
  44571 			break
  44572 		}
  44573 		libc.Xmemcpy(tls, dst+uintptr(j*int32(BPS)), dst-uintptr(BPS), uint64(8))
  44574 		goto _1
  44575 	_1:
  44576 		;
  44577 		j = j + 1
  44578 	}
  44579 }
  44580 
  44581 func HE8uv_C(tls *libc.TLS, dst uintptr) {
  44582 	var j int32
  44583 	_ = j
  44584 	j = 0
  44585 	for {
  44586 		if !(j < int32(8)) {
  44587 			break
  44588 		}
  44589 		libc.Xmemset(tls, dst, int32(**(**uint8_t)(__ccgo_up(dst + uintptr(-libc.Int32FromInt32(1))))), uint64(8))
  44590 		dst = dst + uintptr(BPS)
  44591 		goto _1
  44592 	_1:
  44593 		;
  44594 		j = j + 1
  44595 	}
  44596 }
  44597 
  44598 // C documentation
  44599 //
  44600 //	// helper for chroma-DC predictions
  44601 func Put8x8uv(tls *libc.TLS, value uint8_t, dst uintptr) {
  44602 	var j int32
  44603 	_ = j
  44604 	j = 0
  44605 	for {
  44606 		if !(j < int32(8)) {
  44607 			break
  44608 		}
  44609 		libc.Xmemset(tls, dst+uintptr(j*int32(BPS)), int32(value), uint64(8))
  44610 		goto _1
  44611 	_1:
  44612 		;
  44613 		j = j + 1
  44614 	}
  44615 }
  44616 
  44617 func DC8uv_C(tls *libc.TLS, dst uintptr) {
  44618 	var dc0, i int32
  44619 	_, _ = dc0, i // DC
  44620 	dc0 = int32(8)
  44621 	i = 0
  44622 	for {
  44623 		if !(i < int32(8)) {
  44624 			break
  44625 		}
  44626 		dc0 = dc0 + (int32(**(**uint8_t)(__ccgo_up(dst + uintptr(i-int32(BPS))))) + int32(**(**uint8_t)(__ccgo_up(dst + uintptr(-int32(1)+i*int32(BPS))))))
  44627 		goto _1
  44628 	_1:
  44629 		;
  44630 		i = i + 1
  44631 	}
  44632 	Put8x8uv(tls, uint8(dc0>>int32(4)), dst)
  44633 }
  44634 
  44635 func DC8uvNoLeft_C(tls *libc.TLS, dst uintptr) {
  44636 	var dc0, i int32
  44637 	_, _ = dc0, i // DC with no left samples
  44638 	dc0 = int32(4)
  44639 	i = 0
  44640 	for {
  44641 		if !(i < int32(8)) {
  44642 			break
  44643 		}
  44644 		dc0 = dc0 + int32(**(**uint8_t)(__ccgo_up(dst + uintptr(i-int32(BPS)))))
  44645 		goto _1
  44646 	_1:
  44647 		;
  44648 		i = i + 1
  44649 	}
  44650 	Put8x8uv(tls, uint8(dc0>>int32(3)), dst)
  44651 }
  44652 
  44653 func DC8uvNoTop_C(tls *libc.TLS, dst uintptr) {
  44654 	var dc0, i int32
  44655 	_, _ = dc0, i // DC with no top samples
  44656 	dc0 = int32(4)
  44657 	i = 0
  44658 	for {
  44659 		if !(i < int32(8)) {
  44660 			break
  44661 		}
  44662 		dc0 = dc0 + int32(**(**uint8_t)(__ccgo_up(dst + uintptr(-int32(1)+i*int32(BPS)))))
  44663 		goto _1
  44664 	_1:
  44665 		;
  44666 		i = i + 1
  44667 	}
  44668 	Put8x8uv(tls, uint8(dc0>>int32(3)), dst)
  44669 }
  44670 
  44671 func DC8uvNoTopLeft_C(tls *libc.TLS, dst uintptr) {
  44672 	// DC with nothing
  44673 	Put8x8uv(tls, uint8(0x80), dst)
  44674 }
  44675 
  44676 //------------------------------------------------------------------------------
  44677 // Edge filtering functions
  44678 
  44679 // C documentation
  44680 //
  44681 //	// 4 pixels in, 2 pixels out
  44682 func DoFilter2_C(tls *libc.TLS, p uintptr, step int32) {
  44683 	var a, a1, a2, p0, p1, q0, q1 int32
  44684 	_, _, _, _, _, _, _ = a, a1, a2, p0, p1, q0, q1
  44685 	p1 = int32(**(**uint8_t)(__ccgo_up(p + uintptr(-int32(2)*step))))
  44686 	p0 = int32(**(**uint8_t)(__ccgo_up(p + uintptr(-step))))
  44687 	q0 = int32(**(**uint8_t)(__ccgo_up(p)))
  44688 	q1 = int32(**(**uint8_t)(__ccgo_up(p + uintptr(step))))
  44689 	a = int32(3)*(q0-p0) + int32(**(**int8_t)(__ccgo_up(VP8ksclip1 + uintptr(p1-q1)))) // in [-893,892]
  44690 	a1 = int32(**(**int8_t)(__ccgo_up(VP8ksclip2 + uintptr((a+int32(4))>>int32(3)))))  // in [-16,15]
  44691 	a2 = int32(**(**int8_t)(__ccgo_up(VP8ksclip2 + uintptr((a+int32(3))>>int32(3)))))
  44692 	**(**uint8_t)(__ccgo_up(p + uintptr(-step))) = **(**uint8_t)(__ccgo_up(VP8kclip1 + uintptr(p0+a2)))
  44693 	**(**uint8_t)(__ccgo_up(p)) = **(**uint8_t)(__ccgo_up(VP8kclip1 + uintptr(q0-a1)))
  44694 }
  44695 
  44696 // C documentation
  44697 //
  44698 //	// 4 pixels in, 4 pixels out
  44699 func DoFilter4_C(tls *libc.TLS, p uintptr, step int32) {
  44700 	var a, a1, a2, a3, p0, p1, q0, q1 int32
  44701 	_, _, _, _, _, _, _, _ = a, a1, a2, a3, p0, p1, q0, q1
  44702 	p1 = int32(**(**uint8_t)(__ccgo_up(p + uintptr(-int32(2)*step))))
  44703 	p0 = int32(**(**uint8_t)(__ccgo_up(p + uintptr(-step))))
  44704 	q0 = int32(**(**uint8_t)(__ccgo_up(p)))
  44705 	q1 = int32(**(**uint8_t)(__ccgo_up(p + uintptr(step))))
  44706 	a = int32(3) * (q0 - p0)
  44707 	a1 = int32(**(**int8_t)(__ccgo_up(VP8ksclip2 + uintptr((a+int32(4))>>int32(3)))))
  44708 	a2 = int32(**(**int8_t)(__ccgo_up(VP8ksclip2 + uintptr((a+int32(3))>>int32(3)))))
  44709 	a3 = (a1 + int32(1)) >> int32(1)
  44710 	**(**uint8_t)(__ccgo_up(p + uintptr(-int32(2)*step))) = **(**uint8_t)(__ccgo_up(VP8kclip1 + uintptr(p1+a3)))
  44711 	**(**uint8_t)(__ccgo_up(p + uintptr(-step))) = **(**uint8_t)(__ccgo_up(VP8kclip1 + uintptr(p0+a2)))
  44712 	**(**uint8_t)(__ccgo_up(p)) = **(**uint8_t)(__ccgo_up(VP8kclip1 + uintptr(q0-a1)))
  44713 	**(**uint8_t)(__ccgo_up(p + uintptr(step))) = **(**uint8_t)(__ccgo_up(VP8kclip1 + uintptr(q1-a3)))
  44714 }
  44715 
  44716 // C documentation
  44717 //
  44718 //	// 6 pixels in, 6 pixels out
  44719 func DoFilter6_C(tls *libc.TLS, p uintptr, step int32) {
  44720 	var a, a1, a2, a3, p0, p1, p2, q0, q1, q2 int32
  44721 	_, _, _, _, _, _, _, _, _, _ = a, a1, a2, a3, p0, p1, p2, q0, q1, q2
  44722 	p2 = int32(**(**uint8_t)(__ccgo_up(p + uintptr(-int32(3)*step))))
  44723 	p1 = int32(**(**uint8_t)(__ccgo_up(p + uintptr(-int32(2)*step))))
  44724 	p0 = int32(**(**uint8_t)(__ccgo_up(p + uintptr(-step))))
  44725 	q0 = int32(**(**uint8_t)(__ccgo_up(p)))
  44726 	q1 = int32(**(**uint8_t)(__ccgo_up(p + uintptr(step))))
  44727 	q2 = int32(**(**uint8_t)(__ccgo_up(p + uintptr(int32(2)*step))))
  44728 	a = int32(**(**int8_t)(__ccgo_up(VP8ksclip1 + uintptr(int32(3)*(q0-p0)+int32(**(**int8_t)(__ccgo_up(VP8ksclip1 + uintptr(p1-q1))))))))
  44729 	// a is in [-128,127], a1 in [-27,27], a2 in [-18,18] and a3 in [-9,9]
  44730 	a1 = (int32(27)*a + int32(63)) >> int32(7) // eq. to ((3 * a + 7) * 9) >> 7
  44731 	a2 = (int32(18)*a + int32(63)) >> int32(7) // eq. to ((2 * a + 7) * 9) >> 7
  44732 	a3 = (int32(9)*a + int32(63)) >> int32(7)  // eq. to ((1 * a + 7) * 9) >> 7
  44733 	**(**uint8_t)(__ccgo_up(p + uintptr(-int32(3)*step))) = **(**uint8_t)(__ccgo_up(VP8kclip1 + uintptr(p2+a3)))
  44734 	**(**uint8_t)(__ccgo_up(p + uintptr(-int32(2)*step))) = **(**uint8_t)(__ccgo_up(VP8kclip1 + uintptr(p1+a2)))
  44735 	**(**uint8_t)(__ccgo_up(p + uintptr(-step))) = **(**uint8_t)(__ccgo_up(VP8kclip1 + uintptr(p0+a1)))
  44736 	**(**uint8_t)(__ccgo_up(p)) = **(**uint8_t)(__ccgo_up(VP8kclip1 + uintptr(q0-a1)))
  44737 	**(**uint8_t)(__ccgo_up(p + uintptr(step))) = **(**uint8_t)(__ccgo_up(VP8kclip1 + uintptr(q1-a2)))
  44738 	**(**uint8_t)(__ccgo_up(p + uintptr(int32(2)*step))) = **(**uint8_t)(__ccgo_up(VP8kclip1 + uintptr(q2-a3)))
  44739 }
  44740 
  44741 func Hev(tls *libc.TLS, p uintptr, step int32, thresh int32) (r int32) {
  44742 	var p0, p1, q0, q1 int32
  44743 	_, _, _, _ = p0, p1, q0, q1
  44744 	p1 = int32(**(**uint8_t)(__ccgo_up(p + uintptr(-int32(2)*step))))
  44745 	p0 = int32(**(**uint8_t)(__ccgo_up(p + uintptr(-step))))
  44746 	q0 = int32(**(**uint8_t)(__ccgo_up(p)))
  44747 	q1 = int32(**(**uint8_t)(__ccgo_up(p + uintptr(step))))
  44748 	return libc.BoolInt32(int32(**(**uint8_t)(__ccgo_up(VP8kabs0 + uintptr(p1-p0)))) > thresh || int32(**(**uint8_t)(__ccgo_up(VP8kabs0 + uintptr(q1-q0)))) > thresh)
  44749 }
  44750 
  44751 func NeedsFilter_C(tls *libc.TLS, p uintptr, step int32, t int32) (r int32) {
  44752 	var p0, p1, q0, q1 int32
  44753 	_, _, _, _ = p0, p1, q0, q1
  44754 	p1 = int32(**(**uint8_t)(__ccgo_up(p + uintptr(-int32(2)*step))))
  44755 	p0 = int32(**(**uint8_t)(__ccgo_up(p + uintptr(-step))))
  44756 	q0 = int32(**(**uint8_t)(__ccgo_up(p)))
  44757 	q1 = int32(**(**uint8_t)(__ccgo_up(p + uintptr(step))))
  44758 	return libc.BoolInt32(int32(4)*int32(**(**uint8_t)(__ccgo_up(VP8kabs0 + uintptr(p0-q0))))+int32(**(**uint8_t)(__ccgo_up(VP8kabs0 + uintptr(p1-q1)))) <= t)
  44759 }
  44760 
  44761 func NeedsFilter2_C(tls *libc.TLS, p uintptr, step int32, t int32, it int32) (r int32) {
  44762 	var p0, p1, p2, p3, q0, q1, q2, q3 int32
  44763 	_, _, _, _, _, _, _, _ = p0, p1, p2, p3, q0, q1, q2, q3
  44764 	p3 = int32(**(**uint8_t)(__ccgo_up(p + uintptr(-int32(4)*step))))
  44765 	p2 = int32(**(**uint8_t)(__ccgo_up(p + uintptr(-int32(3)*step))))
  44766 	p1 = int32(**(**uint8_t)(__ccgo_up(p + uintptr(-int32(2)*step))))
  44767 	p0 = int32(**(**uint8_t)(__ccgo_up(p + uintptr(-step))))
  44768 	q0 = int32(**(**uint8_t)(__ccgo_up(p)))
  44769 	q1 = int32(**(**uint8_t)(__ccgo_up(p + uintptr(step))))
  44770 	q2 = int32(**(**uint8_t)(__ccgo_up(p + uintptr(int32(2)*step))))
  44771 	q3 = int32(**(**uint8_t)(__ccgo_up(p + uintptr(int32(3)*step))))
  44772 	if int32(4)*int32(**(**uint8_t)(__ccgo_up(VP8kabs0 + uintptr(p0-q0))))+int32(**(**uint8_t)(__ccgo_up(VP8kabs0 + uintptr(p1-q1)))) > t {
  44773 		return 0
  44774 	}
  44775 	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)
  44776 }
  44777 
  44778 //------------------------------------------------------------------------------
  44779 // Simple In-loop filtering (Paragraph 15.2)
  44780 
  44781 func SimpleVFilter16_C(tls *libc.TLS, p uintptr, stride int32, thresh int32) {
  44782 	var i, thresh2 int32
  44783 	_, _ = i, thresh2
  44784 	thresh2 = int32(2)*thresh + int32(1)
  44785 	i = 0
  44786 	for {
  44787 		if !(i < int32(16)) {
  44788 			break
  44789 		}
  44790 		if NeedsFilter_C(tls, p+uintptr(i), stride, thresh2) != 0 {
  44791 			DoFilter2_C(tls, p+uintptr(i), stride)
  44792 		}
  44793 		goto _1
  44794 	_1:
  44795 		;
  44796 		i = i + 1
  44797 	}
  44798 }
  44799 
  44800 func SimpleHFilter16_C(tls *libc.TLS, p uintptr, stride int32, thresh int32) {
  44801 	var i, thresh2 int32
  44802 	_, _ = i, thresh2
  44803 	thresh2 = int32(2)*thresh + int32(1)
  44804 	i = 0
  44805 	for {
  44806 		if !(i < int32(16)) {
  44807 			break
  44808 		}
  44809 		if NeedsFilter_C(tls, p+uintptr(i*stride), int32(1), thresh2) != 0 {
  44810 			DoFilter2_C(tls, p+uintptr(i*stride), int32(1))
  44811 		}
  44812 		goto _1
  44813 	_1:
  44814 		;
  44815 		i = i + 1
  44816 	}
  44817 }
  44818 
  44819 func SimpleVFilter16i_C(tls *libc.TLS, p uintptr, stride int32, thresh int32) {
  44820 	var k int32
  44821 	_ = k
  44822 	k = int32(3)
  44823 	for {
  44824 		if !(k > 0) {
  44825 			break
  44826 		}
  44827 		p = p + uintptr(int32(4)*stride)
  44828 		SimpleVFilter16_C(tls, p, stride, thresh)
  44829 		goto _1
  44830 	_1:
  44831 		;
  44832 		k = k - 1
  44833 	}
  44834 }
  44835 
  44836 func SimpleHFilter16i_C(tls *libc.TLS, p uintptr, stride int32, thresh int32) {
  44837 	var k int32
  44838 	_ = k
  44839 	k = int32(3)
  44840 	for {
  44841 		if !(k > 0) {
  44842 			break
  44843 		}
  44844 		p = p + uintptr(4)
  44845 		SimpleHFilter16_C(tls, p, stride, thresh)
  44846 		goto _1
  44847 	_1:
  44848 		;
  44849 		k = k - 1
  44850 	}
  44851 }
  44852 
  44853 //------------------------------------------------------------------------------
  44854 // Complex In-loop filtering (Paragraph 15.3)
  44855 
  44856 func FilterLoop26_C(tls *libc.TLS, p uintptr, hstride int32, vstride int32, size int32, thresh int32, ithresh int32, hev_thresh int32) {
  44857 	var thresh2, v1 int32
  44858 	_, _ = thresh2, v1
  44859 	thresh2 = int32(2)*thresh + int32(1)
  44860 	for {
  44861 		v1 = size
  44862 		size = size - 1
  44863 		if !(v1 > 0) {
  44864 			break
  44865 		}
  44866 		if NeedsFilter2_C(tls, p, hstride, thresh2, ithresh) != 0 {
  44867 			if Hev(tls, p, hstride, hev_thresh) != 0 {
  44868 				DoFilter2_C(tls, p, hstride)
  44869 			} else {
  44870 				DoFilter6_C(tls, p, hstride)
  44871 			}
  44872 		}
  44873 		p = p + uintptr(vstride)
  44874 	}
  44875 }
  44876 
  44877 func FilterLoop24_C(tls *libc.TLS, p uintptr, hstride int32, vstride int32, size int32, thresh int32, ithresh int32, hev_thresh int32) {
  44878 	var thresh2, v1 int32
  44879 	_, _ = thresh2, v1
  44880 	thresh2 = int32(2)*thresh + int32(1)
  44881 	for {
  44882 		v1 = size
  44883 		size = size - 1
  44884 		if !(v1 > 0) {
  44885 			break
  44886 		}
  44887 		if NeedsFilter2_C(tls, p, hstride, thresh2, ithresh) != 0 {
  44888 			if Hev(tls, p, hstride, hev_thresh) != 0 {
  44889 				DoFilter2_C(tls, p, hstride)
  44890 			} else {
  44891 				DoFilter4_C(tls, p, hstride)
  44892 			}
  44893 		}
  44894 		p = p + uintptr(vstride)
  44895 	}
  44896 }
  44897 
  44898 // C documentation
  44899 //
  44900 //	// on macroblock edges
  44901 func VFilter16_C(tls *libc.TLS, p uintptr, stride int32, thresh int32, ithresh int32, hev_thresh int32) {
  44902 	FilterLoop26_C(tls, p, stride, int32(1), int32(16), thresh, ithresh, hev_thresh)
  44903 }
  44904 
  44905 func HFilter16_C(tls *libc.TLS, p uintptr, stride int32, thresh int32, ithresh int32, hev_thresh int32) {
  44906 	FilterLoop26_C(tls, p, int32(1), stride, int32(16), thresh, ithresh, hev_thresh)
  44907 }
  44908 
  44909 // C documentation
  44910 //
  44911 //	// on three inner edges
  44912 func VFilter16i_C(tls *libc.TLS, p uintptr, stride int32, thresh int32, ithresh int32, hev_thresh int32) {
  44913 	var k int32
  44914 	_ = k
  44915 	k = int32(3)
  44916 	for {
  44917 		if !(k > 0) {
  44918 			break
  44919 		}
  44920 		p = p + uintptr(int32(4)*stride)
  44921 		FilterLoop24_C(tls, p, stride, int32(1), int32(16), thresh, ithresh, hev_thresh)
  44922 		goto _1
  44923 	_1:
  44924 		;
  44925 		k = k - 1
  44926 	}
  44927 }
  44928 
  44929 func HFilter16i_C(tls *libc.TLS, p uintptr, stride int32, thresh int32, ithresh int32, hev_thresh int32) {
  44930 	var k int32
  44931 	_ = k
  44932 	k = int32(3)
  44933 	for {
  44934 		if !(k > 0) {
  44935 			break
  44936 		}
  44937 		p = p + uintptr(4)
  44938 		FilterLoop24_C(tls, p, int32(1), stride, int32(16), thresh, ithresh, hev_thresh)
  44939 		goto _1
  44940 	_1:
  44941 		;
  44942 		k = k - 1
  44943 	}
  44944 }
  44945 
  44946 // C documentation
  44947 //
  44948 //	// 8-pixels wide variant, for chroma filtering
  44949 func VFilter8_C(tls *libc.TLS, u uintptr, v uintptr, stride int32, thresh int32, ithresh int32, hev_thresh int32) {
  44950 	FilterLoop26_C(tls, u, stride, int32(1), int32(8), thresh, ithresh, hev_thresh)
  44951 	FilterLoop26_C(tls, v, stride, int32(1), int32(8), thresh, ithresh, hev_thresh)
  44952 }
  44953 
  44954 func HFilter8_C(tls *libc.TLS, u uintptr, v uintptr, stride int32, thresh int32, ithresh int32, hev_thresh int32) {
  44955 	FilterLoop26_C(tls, u, int32(1), stride, int32(8), thresh, ithresh, hev_thresh)
  44956 	FilterLoop26_C(tls, v, int32(1), stride, int32(8), thresh, ithresh, hev_thresh)
  44957 }
  44958 
  44959 func VFilter8i_C(tls *libc.TLS, u uintptr, v uintptr, stride int32, thresh int32, ithresh int32, hev_thresh int32) {
  44960 	FilterLoop24_C(tls, u+uintptr(int32(4)*stride), stride, int32(1), int32(8), thresh, ithresh, hev_thresh)
  44961 	FilterLoop24_C(tls, v+uintptr(int32(4)*stride), stride, int32(1), int32(8), thresh, ithresh, hev_thresh)
  44962 }
  44963 
  44964 func HFilter8i_C(tls *libc.TLS, u uintptr, v uintptr, stride int32, thresh int32, ithresh int32, hev_thresh int32) {
  44965 	FilterLoop24_C(tls, u+uintptr(4), int32(1), stride, int32(8), thresh, ithresh, hev_thresh)
  44966 	FilterLoop24_C(tls, v+uintptr(4), int32(1), stride, int32(8), thresh, ithresh, hev_thresh)
  44967 }
  44968 
  44969 //------------------------------------------------------------------------------
  44970 
  44971 func DitherCombine8x8_C(tls *libc.TLS, dither uintptr, dst uintptr, dst_stride int32) {
  44972 	var delta0, delta1, i, j int32
  44973 	_, _, _, _ = delta0, delta1, i, j
  44974 	j = 0
  44975 	for {
  44976 		if !(j < int32(8)) {
  44977 			break
  44978 		}
  44979 		i = 0
  44980 		for {
  44981 			if !(i < int32(8)) {
  44982 				break
  44983 			}
  44984 			delta0 = int32(**(**uint8_t)(__ccgo_up(dither + uintptr(i)))) - libc.Int32FromInt32(1)<<libc.Int32FromInt32(VP8_DITHER_AMP_BITS)
  44985 			delta1 = (delta0 + libc.Int32FromInt32(1)<<(libc.Int32FromInt32(VP8_DITHER_DESCALE)-libc.Int32FromInt32(1))) >> int32(VP8_DITHER_DESCALE)
  44986 			**(**uint8_t)(__ccgo_up(dst + uintptr(i))) = clip_8b1(tls, int32(**(**uint8_t)(__ccgo_up(dst + uintptr(i))))+delta1)
  44987 			goto _2
  44988 		_2:
  44989 			;
  44990 			i = i + 1
  44991 		}
  44992 		dst = dst + uintptr(dst_stride)
  44993 		dither = dither + uintptr(8)
  44994 		goto _1
  44995 	_1:
  44996 		;
  44997 		j = j + 1
  44998 	}
  44999 }
  45000 
  45001 func VP8DspInit(tls *libc.TLS) {
  45002 	if libc.AtomicLoadPUintptr(uintptr(unsafe.Pointer(&VP8DspInit_body_last_cpuinfo_used))) == VP8GetCPUInfo {
  45003 		goto _1
  45004 	}
  45005 	VP8DspInit_body(tls)
  45006 	libc.AtomicStorePUintptr(uintptr(unsafe.Pointer(&VP8DspInit_body_last_cpuinfo_used)), VP8GetCPUInfo)
  45007 	goto _2
  45008 _2:
  45009 	;
  45010 	goto _1
  45011 _1: /**/ //
  45012 }
  45013 
  45014 var VP8DspInit_body_last_cpuinfo_used = uintptr(0)
  45015 
  45016 func init() {
  45017 	p := unsafe.Pointer(&VP8DspInit_body_last_cpuinfo_used)
  45018 	*(*uintptr)(unsafe.Add(p, 0)) = uintptr(unsafe.Pointer(&VP8DspInit_body_last_cpuinfo_used))
  45019 }
  45020 
  45021 func VP8DspInit_body(tls *libc.TLS) {
  45022 	VP8InitClipTables(tls)
  45023 	VP8TransformWHT = __ccgo_fp(TransformWHT_C)
  45024 	VP8Transform = __ccgo_fp(TransformTwo_C)
  45025 	VP8TransformDC = __ccgo_fp(TransformDC_C)
  45026 	VP8TransformAC3 = __ccgo_fp(TransformAC3_C)
  45027 	VP8TransformUV = __ccgo_fp(TransformUV_C)
  45028 	VP8TransformDCUV = __ccgo_fp(TransformDCUV_C)
  45029 	VP8VFilter16 = __ccgo_fp(VFilter16_C)
  45030 	VP8VFilter16i = __ccgo_fp(VFilter16i_C)
  45031 	VP8HFilter16 = __ccgo_fp(HFilter16_C)
  45032 	VP8VFilter8 = __ccgo_fp(VFilter8_C)
  45033 	VP8VFilter8i = __ccgo_fp(VFilter8i_C)
  45034 	VP8SimpleVFilter16 = __ccgo_fp(SimpleVFilter16_C)
  45035 	VP8SimpleHFilter16 = __ccgo_fp(SimpleHFilter16_C)
  45036 	VP8SimpleVFilter16i = __ccgo_fp(SimpleVFilter16i_C)
  45037 	VP8SimpleHFilter16i = __ccgo_fp(SimpleHFilter16i_C)
  45038 	VP8HFilter16i = __ccgo_fp(HFilter16i_C)
  45039 	VP8HFilter8 = __ccgo_fp(HFilter8_C)
  45040 	VP8HFilter8i = __ccgo_fp(HFilter8i_C)
  45041 	VP8PredLuma4[0] = __ccgo_fp(DC4_C)
  45042 	VP8PredLuma4[int32(1)] = __ccgo_fp(TM4_C)
  45043 	VP8PredLuma4[int32(2)] = __ccgo_fp(VE4_C)
  45044 	VP8PredLuma4[int32(4)] = __ccgo_fp(RD4_C)
  45045 	VP8PredLuma4[int32(6)] = __ccgo_fp(LD4_C)
  45046 	VP8PredLuma4[int32(3)] = __ccgo_fp(HE4_C)
  45047 	VP8PredLuma4[int32(5)] = __ccgo_fp(VR4_C)
  45048 	VP8PredLuma4[int32(7)] = __ccgo_fp(VL4_C)
  45049 	VP8PredLuma4[int32(8)] = __ccgo_fp(HD4_C)
  45050 	VP8PredLuma4[int32(9)] = __ccgo_fp(HU4_C)
  45051 	VP8PredLuma16[0] = __ccgo_fp(DC16_C)
  45052 	VP8PredLuma16[int32(1)] = __ccgo_fp(TM16_C)
  45053 	VP8PredLuma16[int32(2)] = __ccgo_fp(VE16_C)
  45054 	VP8PredLuma16[int32(3)] = __ccgo_fp(HE16_C)
  45055 	VP8PredLuma16[int32(4)] = __ccgo_fp(DC16NoTop_C)
  45056 	VP8PredLuma16[int32(5)] = __ccgo_fp(DC16NoLeft_C)
  45057 	VP8PredLuma16[int32(6)] = __ccgo_fp(DC16NoTopLeft_C)
  45058 	VP8PredChroma8[0] = __ccgo_fp(DC8uv_C)
  45059 	VP8PredChroma8[int32(1)] = __ccgo_fp(TM8uv_C)
  45060 	VP8PredChroma8[int32(2)] = __ccgo_fp(VE8uv_C)
  45061 	VP8PredChroma8[int32(3)] = __ccgo_fp(HE8uv_C)
  45062 	VP8PredChroma8[int32(4)] = __ccgo_fp(DC8uvNoTop_C)
  45063 	VP8PredChroma8[int32(5)] = __ccgo_fp(DC8uvNoLeft_C)
  45064 	VP8PredChroma8[int32(6)] = __ccgo_fp(DC8uvNoTopLeft_C)
  45065 	VP8DitherCombine8x8 = __ccgo_fp(DitherCombine8x8_C)
  45066 	// If defined, use CPUInfo() to overwrite some pointers with faster versions.
  45067 	if VP8GetCPUInfo != libc.UintptrFromInt32(0) {
  45068 	}
  45069 }
  45070 
  45071 const USE_STATIC_TABLES = 1
  45072 
  45073 // define to 0 to have run-time table initialization
  45074 
  45075 var abs0 = [511]uint8_t{
  45076 	0:   uint8(0xff),
  45077 	1:   uint8(0xfe),
  45078 	2:   uint8(0xfd),
  45079 	3:   uint8(0xfc),
  45080 	4:   uint8(0xfb),
  45081 	5:   uint8(0xfa),
  45082 	6:   uint8(0xf9),
  45083 	7:   uint8(0xf8),
  45084 	8:   uint8(0xf7),
  45085 	9:   uint8(0xf6),
  45086 	10:  uint8(0xf5),
  45087 	11:  uint8(0xf4),
  45088 	12:  uint8(0xf3),
  45089 	13:  uint8(0xf2),
  45090 	14:  uint8(0xf1),
  45091 	15:  uint8(0xf0),
  45092 	16:  uint8(0xef),
  45093 	17:  uint8(0xee),
  45094 	18:  uint8(0xed),
  45095 	19:  uint8(0xec),
  45096 	20:  uint8(0xeb),
  45097 	21:  uint8(0xea),
  45098 	22:  uint8(0xe9),
  45099 	23:  uint8(0xe8),
  45100 	24:  uint8(0xe7),
  45101 	25:  uint8(0xe6),
  45102 	26:  uint8(0xe5),
  45103 	27:  uint8(0xe4),
  45104 	28:  uint8(0xe3),
  45105 	29:  uint8(0xe2),
  45106 	30:  uint8(0xe1),
  45107 	31:  uint8(0xe0),
  45108 	32:  uint8(0xdf),
  45109 	33:  uint8(0xde),
  45110 	34:  uint8(0xdd),
  45111 	35:  uint8(0xdc),
  45112 	36:  uint8(0xdb),
  45113 	37:  uint8(0xda),
  45114 	38:  uint8(0xd9),
  45115 	39:  uint8(0xd8),
  45116 	40:  uint8(0xd7),
  45117 	41:  uint8(0xd6),
  45118 	42:  uint8(0xd5),
  45119 	43:  uint8(0xd4),
  45120 	44:  uint8(0xd3),
  45121 	45:  uint8(0xd2),
  45122 	46:  uint8(0xd1),
  45123 	47:  uint8(0xd0),
  45124 	48:  uint8(0xcf),
  45125 	49:  uint8(0xce),
  45126 	50:  uint8(0xcd),
  45127 	51:  uint8(0xcc),
  45128 	52:  uint8(0xcb),
  45129 	53:  uint8(0xca),
  45130 	54:  uint8(0xc9),
  45131 	55:  uint8(0xc8),
  45132 	56:  uint8(0xc7),
  45133 	57:  uint8(0xc6),
  45134 	58:  uint8(0xc5),
  45135 	59:  uint8(0xc4),
  45136 	60:  uint8(0xc3),
  45137 	61:  uint8(0xc2),
  45138 	62:  uint8(0xc1),
  45139 	63:  uint8(0xc0),
  45140 	64:  uint8(0xbf),
  45141 	65:  uint8(0xbe),
  45142 	66:  uint8(0xbd),
  45143 	67:  uint8(0xbc),
  45144 	68:  uint8(0xbb),
  45145 	69:  uint8(0xba),
  45146 	70:  uint8(0xb9),
  45147 	71:  uint8(0xb8),
  45148 	72:  uint8(0xb7),
  45149 	73:  uint8(0xb6),
  45150 	74:  uint8(0xb5),
  45151 	75:  uint8(0xb4),
  45152 	76:  uint8(0xb3),
  45153 	77:  uint8(0xb2),
  45154 	78:  uint8(0xb1),
  45155 	79:  uint8(0xb0),
  45156 	80:  uint8(0xaf),
  45157 	81:  uint8(0xae),
  45158 	82:  uint8(0xad),
  45159 	83:  uint8(0xac),
  45160 	84:  uint8(0xab),
  45161 	85:  uint8(0xaa),
  45162 	86:  uint8(0xa9),
  45163 	87:  uint8(0xa8),
  45164 	88:  uint8(0xa7),
  45165 	89:  uint8(0xa6),
  45166 	90:  uint8(0xa5),
  45167 	91:  uint8(0xa4),
  45168 	92:  uint8(0xa3),
  45169 	93:  uint8(0xa2),
  45170 	94:  uint8(0xa1),
  45171 	95:  uint8(0xa0),
  45172 	96:  uint8(0x9f),
  45173 	97:  uint8(0x9e),
  45174 	98:  uint8(0x9d),
  45175 	99:  uint8(0x9c),
  45176 	100: uint8(0x9b),
  45177 	101: uint8(0x9a),
  45178 	102: uint8(0x99),
  45179 	103: uint8(0x98),
  45180 	104: uint8(0x97),
  45181 	105: uint8(0x96),
  45182 	106: uint8(0x95),
  45183 	107: uint8(0x94),
  45184 	108: uint8(0x93),
  45185 	109: uint8(0x92),
  45186 	110: uint8(0x91),
  45187 	111: uint8(0x90),
  45188 	112: uint8(0x8f),
  45189 	113: uint8(0x8e),
  45190 	114: uint8(0x8d),
  45191 	115: uint8(0x8c),
  45192 	116: uint8(0x8b),
  45193 	117: uint8(0x8a),
  45194 	118: uint8(0x89),
  45195 	119: uint8(0x88),
  45196 	120: uint8(0x87),
  45197 	121: uint8(0x86),
  45198 	122: uint8(0x85),
  45199 	123: uint8(0x84),
  45200 	124: uint8(0x83),
  45201 	125: uint8(0x82),
  45202 	126: uint8(0x81),
  45203 	127: uint8(0x80),
  45204 	128: uint8(0x7f),
  45205 	129: uint8(0x7e),
  45206 	130: uint8(0x7d),
  45207 	131: uint8(0x7c),
  45208 	132: uint8(0x7b),
  45209 	133: uint8(0x7a),
  45210 	134: uint8(0x79),
  45211 	135: uint8(0x78),
  45212 	136: uint8(0x77),
  45213 	137: uint8(0x76),
  45214 	138: uint8(0x75),
  45215 	139: uint8(0x74),
  45216 	140: uint8(0x73),
  45217 	141: uint8(0x72),
  45218 	142: uint8(0x71),
  45219 	143: uint8(0x70),
  45220 	144: uint8(0x6f),
  45221 	145: uint8(0x6e),
  45222 	146: uint8(0x6d),
  45223 	147: uint8(0x6c),
  45224 	148: uint8(0x6b),
  45225 	149: uint8(0x6a),
  45226 	150: uint8(0x69),
  45227 	151: uint8(0x68),
  45228 	152: uint8(0x67),
  45229 	153: uint8(0x66),
  45230 	154: uint8(0x65),
  45231 	155: uint8(0x64),
  45232 	156: uint8(0x63),
  45233 	157: uint8(0x62),
  45234 	158: uint8(0x61),
  45235 	159: uint8(0x60),
  45236 	160: uint8(0x5f),
  45237 	161: uint8(0x5e),
  45238 	162: uint8(0x5d),
  45239 	163: uint8(0x5c),
  45240 	164: uint8(0x5b),
  45241 	165: uint8(0x5a),
  45242 	166: uint8(0x59),
  45243 	167: uint8(0x58),
  45244 	168: uint8(0x57),
  45245 	169: uint8(0x56),
  45246 	170: uint8(0x55),
  45247 	171: uint8(0x54),
  45248 	172: uint8(0x53),
  45249 	173: uint8(0x52),
  45250 	174: uint8(0x51),
  45251 	175: uint8(0x50),
  45252 	176: uint8(0x4f),
  45253 	177: uint8(0x4e),
  45254 	178: uint8(0x4d),
  45255 	179: uint8(0x4c),
  45256 	180: uint8(0x4b),
  45257 	181: uint8(0x4a),
  45258 	182: uint8(0x49),
  45259 	183: uint8(0x48),
  45260 	184: uint8(0x47),
  45261 	185: uint8(0x46),
  45262 	186: uint8(0x45),
  45263 	187: uint8(0x44),
  45264 	188: uint8(0x43),
  45265 	189: uint8(0x42),
  45266 	190: uint8(0x41),
  45267 	191: uint8(0x40),
  45268 	192: uint8(0x3f),
  45269 	193: uint8(0x3e),
  45270 	194: uint8(0x3d),
  45271 	195: uint8(0x3c),
  45272 	196: uint8(0x3b),
  45273 	197: uint8(0x3a),
  45274 	198: uint8(0x39),
  45275 	199: uint8(0x38),
  45276 	200: uint8(0x37),
  45277 	201: uint8(0x36),
  45278 	202: uint8(0x35),
  45279 	203: uint8(0x34),
  45280 	204: uint8(0x33),
  45281 	205: uint8(0x32),
  45282 	206: uint8(0x31),
  45283 	207: uint8(0x30),
  45284 	208: uint8(0x2f),
  45285 	209: uint8(0x2e),
  45286 	210: uint8(0x2d),
  45287 	211: uint8(0x2c),
  45288 	212: uint8(0x2b),
  45289 	213: uint8(0x2a),
  45290 	214: uint8(0x29),
  45291 	215: uint8(0x28),
  45292 	216: uint8(0x27),
  45293 	217: uint8(0x26),
  45294 	218: uint8(0x25),
  45295 	219: uint8(0x24),
  45296 	220: uint8(0x23),
  45297 	221: uint8(0x22),
  45298 	222: uint8(0x21),
  45299 	223: uint8(0x20),
  45300 	224: uint8(0x1f),
  45301 	225: uint8(0x1e),
  45302 	226: uint8(0x1d),
  45303 	227: uint8(0x1c),
  45304 	228: uint8(0x1b),
  45305 	229: uint8(0x1a),
  45306 	230: uint8(0x19),
  45307 	231: uint8(0x18),
  45308 	232: uint8(0x17),
  45309 	233: uint8(0x16),
  45310 	234: uint8(0x15),
  45311 	235: uint8(0x14),
  45312 	236: uint8(0x13),
  45313 	237: uint8(0x12),
  45314 	238: uint8(0x11),
  45315 	239: uint8(0x10),
  45316 	240: uint8(0x0f),
  45317 	241: uint8(0x0e),
  45318 	242: uint8(0x0d),
  45319 	243: uint8(0x0c),
  45320 	244: uint8(0x0b),
  45321 	245: uint8(0x0a),
  45322 	246: uint8(0x09),
  45323 	247: uint8(0x08),
  45324 	248: uint8(0x07),
  45325 	249: uint8(0x06),
  45326 	250: uint8(0x05),
  45327 	251: uint8(0x04),
  45328 	252: uint8(0x03),
  45329 	253: uint8(0x02),
  45330 	254: uint8(0x01),
  45331 	256: uint8(0x01),
  45332 	257: uint8(0x02),
  45333 	258: uint8(0x03),
  45334 	259: uint8(0x04),
  45335 	260: uint8(0x05),
  45336 	261: uint8(0x06),
  45337 	262: uint8(0x07),
  45338 	263: uint8(0x08),
  45339 	264: uint8(0x09),
  45340 	265: uint8(0x0a),
  45341 	266: uint8(0x0b),
  45342 	267: uint8(0x0c),
  45343 	268: uint8(0x0d),
  45344 	269: uint8(0x0e),
  45345 	270: uint8(0x0f),
  45346 	271: uint8(0x10),
  45347 	272: uint8(0x11),
  45348 	273: uint8(0x12),
  45349 	274: uint8(0x13),
  45350 	275: uint8(0x14),
  45351 	276: uint8(0x15),
  45352 	277: uint8(0x16),
  45353 	278: uint8(0x17),
  45354 	279: uint8(0x18),
  45355 	280: uint8(0x19),
  45356 	281: uint8(0x1a),
  45357 	282: uint8(0x1b),
  45358 	283: uint8(0x1c),
  45359 	284: uint8(0x1d),
  45360 	285: uint8(0x1e),
  45361 	286: uint8(0x1f),
  45362 	287: uint8(0x20),
  45363 	288: uint8(0x21),
  45364 	289: uint8(0x22),
  45365 	290: uint8(0x23),
  45366 	291: uint8(0x24),
  45367 	292: uint8(0x25),
  45368 	293: uint8(0x26),
  45369 	294: uint8(0x27),
  45370 	295: uint8(0x28),
  45371 	296: uint8(0x29),
  45372 	297: uint8(0x2a),
  45373 	298: uint8(0x2b),
  45374 	299: uint8(0x2c),
  45375 	300: uint8(0x2d),
  45376 	301: uint8(0x2e),
  45377 	302: uint8(0x2f),
  45378 	303: uint8(0x30),
  45379 	304: uint8(0x31),
  45380 	305: uint8(0x32),
  45381 	306: uint8(0x33),
  45382 	307: uint8(0x34),
  45383 	308: uint8(0x35),
  45384 	309: uint8(0x36),
  45385 	310: uint8(0x37),
  45386 	311: uint8(0x38),
  45387 	312: uint8(0x39),
  45388 	313: uint8(0x3a),
  45389 	314: uint8(0x3b),
  45390 	315: uint8(0x3c),
  45391 	316: uint8(0x3d),
  45392 	317: uint8(0x3e),
  45393 	318: uint8(0x3f),
  45394 	319: uint8(0x40),
  45395 	320: uint8(0x41),
  45396 	321: uint8(0x42),
  45397 	322: uint8(0x43),
  45398 	323: uint8(0x44),
  45399 	324: uint8(0x45),
  45400 	325: uint8(0x46),
  45401 	326: uint8(0x47),
  45402 	327: uint8(0x48),
  45403 	328: uint8(0x49),
  45404 	329: uint8(0x4a),
  45405 	330: uint8(0x4b),
  45406 	331: uint8(0x4c),
  45407 	332: uint8(0x4d),
  45408 	333: uint8(0x4e),
  45409 	334: uint8(0x4f),
  45410 	335: uint8(0x50),
  45411 	336: uint8(0x51),
  45412 	337: uint8(0x52),
  45413 	338: uint8(0x53),
  45414 	339: uint8(0x54),
  45415 	340: uint8(0x55),
  45416 	341: uint8(0x56),
  45417 	342: uint8(0x57),
  45418 	343: uint8(0x58),
  45419 	344: uint8(0x59),
  45420 	345: uint8(0x5a),
  45421 	346: uint8(0x5b),
  45422 	347: uint8(0x5c),
  45423 	348: uint8(0x5d),
  45424 	349: uint8(0x5e),
  45425 	350: uint8(0x5f),
  45426 	351: uint8(0x60),
  45427 	352: uint8(0x61),
  45428 	353: uint8(0x62),
  45429 	354: uint8(0x63),
  45430 	355: uint8(0x64),
  45431 	356: uint8(0x65),
  45432 	357: uint8(0x66),
  45433 	358: uint8(0x67),
  45434 	359: uint8(0x68),
  45435 	360: uint8(0x69),
  45436 	361: uint8(0x6a),
  45437 	362: uint8(0x6b),
  45438 	363: uint8(0x6c),
  45439 	364: uint8(0x6d),
  45440 	365: uint8(0x6e),
  45441 	366: uint8(0x6f),
  45442 	367: uint8(0x70),
  45443 	368: uint8(0x71),
  45444 	369: uint8(0x72),
  45445 	370: uint8(0x73),
  45446 	371: uint8(0x74),
  45447 	372: uint8(0x75),
  45448 	373: uint8(0x76),
  45449 	374: uint8(0x77),
  45450 	375: uint8(0x78),
  45451 	376: uint8(0x79),
  45452 	377: uint8(0x7a),
  45453 	378: uint8(0x7b),
  45454 	379: uint8(0x7c),
  45455 	380: uint8(0x7d),
  45456 	381: uint8(0x7e),
  45457 	382: uint8(0x7f),
  45458 	383: uint8(0x80),
  45459 	384: uint8(0x81),
  45460 	385: uint8(0x82),
  45461 	386: uint8(0x83),
  45462 	387: uint8(0x84),
  45463 	388: uint8(0x85),
  45464 	389: uint8(0x86),
  45465 	390: uint8(0x87),
  45466 	391: uint8(0x88),
  45467 	392: uint8(0x89),
  45468 	393: uint8(0x8a),
  45469 	394: uint8(0x8b),
  45470 	395: uint8(0x8c),
  45471 	396: uint8(0x8d),
  45472 	397: uint8(0x8e),
  45473 	398: uint8(0x8f),
  45474 	399: uint8(0x90),
  45475 	400: uint8(0x91),
  45476 	401: uint8(0x92),
  45477 	402: uint8(0x93),
  45478 	403: uint8(0x94),
  45479 	404: uint8(0x95),
  45480 	405: uint8(0x96),
  45481 	406: uint8(0x97),
  45482 	407: uint8(0x98),
  45483 	408: uint8(0x99),
  45484 	409: uint8(0x9a),
  45485 	410: uint8(0x9b),
  45486 	411: uint8(0x9c),
  45487 	412: uint8(0x9d),
  45488 	413: uint8(0x9e),
  45489 	414: uint8(0x9f),
  45490 	415: uint8(0xa0),
  45491 	416: uint8(0xa1),
  45492 	417: uint8(0xa2),
  45493 	418: uint8(0xa3),
  45494 	419: uint8(0xa4),
  45495 	420: uint8(0xa5),
  45496 	421: uint8(0xa6),
  45497 	422: uint8(0xa7),
  45498 	423: uint8(0xa8),
  45499 	424: uint8(0xa9),
  45500 	425: uint8(0xaa),
  45501 	426: uint8(0xab),
  45502 	427: uint8(0xac),
  45503 	428: uint8(0xad),
  45504 	429: uint8(0xae),
  45505 	430: uint8(0xaf),
  45506 	431: uint8(0xb0),
  45507 	432: uint8(0xb1),
  45508 	433: uint8(0xb2),
  45509 	434: uint8(0xb3),
  45510 	435: uint8(0xb4),
  45511 	436: uint8(0xb5),
  45512 	437: uint8(0xb6),
  45513 	438: uint8(0xb7),
  45514 	439: uint8(0xb8),
  45515 	440: uint8(0xb9),
  45516 	441: uint8(0xba),
  45517 	442: uint8(0xbb),
  45518 	443: uint8(0xbc),
  45519 	444: uint8(0xbd),
  45520 	445: uint8(0xbe),
  45521 	446: uint8(0xbf),
  45522 	447: uint8(0xc0),
  45523 	448: uint8(0xc1),
  45524 	449: uint8(0xc2),
  45525 	450: uint8(0xc3),
  45526 	451: uint8(0xc4),
  45527 	452: uint8(0xc5),
  45528 	453: uint8(0xc6),
  45529 	454: uint8(0xc7),
  45530 	455: uint8(0xc8),
  45531 	456: uint8(0xc9),
  45532 	457: uint8(0xca),
  45533 	458: uint8(0xcb),
  45534 	459: uint8(0xcc),
  45535 	460: uint8(0xcd),
  45536 	461: uint8(0xce),
  45537 	462: uint8(0xcf),
  45538 	463: uint8(0xd0),
  45539 	464: uint8(0xd1),
  45540 	465: uint8(0xd2),
  45541 	466: uint8(0xd3),
  45542 	467: uint8(0xd4),
  45543 	468: uint8(0xd5),
  45544 	469: uint8(0xd6),
  45545 	470: uint8(0xd7),
  45546 	471: uint8(0xd8),
  45547 	472: uint8(0xd9),
  45548 	473: uint8(0xda),
  45549 	474: uint8(0xdb),
  45550 	475: uint8(0xdc),
  45551 	476: uint8(0xdd),
  45552 	477: uint8(0xde),
  45553 	478: uint8(0xdf),
  45554 	479: uint8(0xe0),
  45555 	480: uint8(0xe1),
  45556 	481: uint8(0xe2),
  45557 	482: uint8(0xe3),
  45558 	483: uint8(0xe4),
  45559 	484: uint8(0xe5),
  45560 	485: uint8(0xe6),
  45561 	486: uint8(0xe7),
  45562 	487: uint8(0xe8),
  45563 	488: uint8(0xe9),
  45564 	489: uint8(0xea),
  45565 	490: uint8(0xeb),
  45566 	491: uint8(0xec),
  45567 	492: uint8(0xed),
  45568 	493: uint8(0xee),
  45569 	494: uint8(0xef),
  45570 	495: uint8(0xf0),
  45571 	496: uint8(0xf1),
  45572 	497: uint8(0xf2),
  45573 	498: uint8(0xf3),
  45574 	499: uint8(0xf4),
  45575 	500: uint8(0xf5),
  45576 	501: uint8(0xf6),
  45577 	502: uint8(0xf7),
  45578 	503: uint8(0xf8),
  45579 	504: uint8(0xf9),
  45580 	505: uint8(0xfa),
  45581 	506: uint8(0xfb),
  45582 	507: uint8(0xfc),
  45583 	508: uint8(0xfd),
  45584 	509: uint8(0xfe),
  45585 	510: uint8(0xff),
  45586 }
  45587 
  45588 var sclip1 = [2041]uint8_t{
  45589 	0:    uint8(0x80),
  45590 	1:    uint8(0x80),
  45591 	2:    uint8(0x80),
  45592 	3:    uint8(0x80),
  45593 	4:    uint8(0x80),
  45594 	5:    uint8(0x80),
  45595 	6:    uint8(0x80),
  45596 	7:    uint8(0x80),
  45597 	8:    uint8(0x80),
  45598 	9:    uint8(0x80),
  45599 	10:   uint8(0x80),
  45600 	11:   uint8(0x80),
  45601 	12:   uint8(0x80),
  45602 	13:   uint8(0x80),
  45603 	14:   uint8(0x80),
  45604 	15:   uint8(0x80),
  45605 	16:   uint8(0x80),
  45606 	17:   uint8(0x80),
  45607 	18:   uint8(0x80),
  45608 	19:   uint8(0x80),
  45609 	20:   uint8(0x80),
  45610 	21:   uint8(0x80),
  45611 	22:   uint8(0x80),
  45612 	23:   uint8(0x80),
  45613 	24:   uint8(0x80),
  45614 	25:   uint8(0x80),
  45615 	26:   uint8(0x80),
  45616 	27:   uint8(0x80),
  45617 	28:   uint8(0x80),
  45618 	29:   uint8(0x80),
  45619 	30:   uint8(0x80),
  45620 	31:   uint8(0x80),
  45621 	32:   uint8(0x80),
  45622 	33:   uint8(0x80),
  45623 	34:   uint8(0x80),
  45624 	35:   uint8(0x80),
  45625 	36:   uint8(0x80),
  45626 	37:   uint8(0x80),
  45627 	38:   uint8(0x80),
  45628 	39:   uint8(0x80),
  45629 	40:   uint8(0x80),
  45630 	41:   uint8(0x80),
  45631 	42:   uint8(0x80),
  45632 	43:   uint8(0x80),
  45633 	44:   uint8(0x80),
  45634 	45:   uint8(0x80),
  45635 	46:   uint8(0x80),
  45636 	47:   uint8(0x80),
  45637 	48:   uint8(0x80),
  45638 	49:   uint8(0x80),
  45639 	50:   uint8(0x80),
  45640 	51:   uint8(0x80),
  45641 	52:   uint8(0x80),
  45642 	53:   uint8(0x80),
  45643 	54:   uint8(0x80),
  45644 	55:   uint8(0x80),
  45645 	56:   uint8(0x80),
  45646 	57:   uint8(0x80),
  45647 	58:   uint8(0x80),
  45648 	59:   uint8(0x80),
  45649 	60:   uint8(0x80),
  45650 	61:   uint8(0x80),
  45651 	62:   uint8(0x80),
  45652 	63:   uint8(0x80),
  45653 	64:   uint8(0x80),
  45654 	65:   uint8(0x80),
  45655 	66:   uint8(0x80),
  45656 	67:   uint8(0x80),
  45657 	68:   uint8(0x80),
  45658 	69:   uint8(0x80),
  45659 	70:   uint8(0x80),
  45660 	71:   uint8(0x80),
  45661 	72:   uint8(0x80),
  45662 	73:   uint8(0x80),
  45663 	74:   uint8(0x80),
  45664 	75:   uint8(0x80),
  45665 	76:   uint8(0x80),
  45666 	77:   uint8(0x80),
  45667 	78:   uint8(0x80),
  45668 	79:   uint8(0x80),
  45669 	80:   uint8(0x80),
  45670 	81:   uint8(0x80),
  45671 	82:   uint8(0x80),
  45672 	83:   uint8(0x80),
  45673 	84:   uint8(0x80),
  45674 	85:   uint8(0x80),
  45675 	86:   uint8(0x80),
  45676 	87:   uint8(0x80),
  45677 	88:   uint8(0x80),
  45678 	89:   uint8(0x80),
  45679 	90:   uint8(0x80),
  45680 	91:   uint8(0x80),
  45681 	92:   uint8(0x80),
  45682 	93:   uint8(0x80),
  45683 	94:   uint8(0x80),
  45684 	95:   uint8(0x80),
  45685 	96:   uint8(0x80),
  45686 	97:   uint8(0x80),
  45687 	98:   uint8(0x80),
  45688 	99:   uint8(0x80),
  45689 	100:  uint8(0x80),
  45690 	101:  uint8(0x80),
  45691 	102:  uint8(0x80),
  45692 	103:  uint8(0x80),
  45693 	104:  uint8(0x80),
  45694 	105:  uint8(0x80),
  45695 	106:  uint8(0x80),
  45696 	107:  uint8(0x80),
  45697 	108:  uint8(0x80),
  45698 	109:  uint8(0x80),
  45699 	110:  uint8(0x80),
  45700 	111:  uint8(0x80),
  45701 	112:  uint8(0x80),
  45702 	113:  uint8(0x80),
  45703 	114:  uint8(0x80),
  45704 	115:  uint8(0x80),
  45705 	116:  uint8(0x80),
  45706 	117:  uint8(0x80),
  45707 	118:  uint8(0x80),
  45708 	119:  uint8(0x80),
  45709 	120:  uint8(0x80),
  45710 	121:  uint8(0x80),
  45711 	122:  uint8(0x80),
  45712 	123:  uint8(0x80),
  45713 	124:  uint8(0x80),
  45714 	125:  uint8(0x80),
  45715 	126:  uint8(0x80),
  45716 	127:  uint8(0x80),
  45717 	128:  uint8(0x80),
  45718 	129:  uint8(0x80),
  45719 	130:  uint8(0x80),
  45720 	131:  uint8(0x80),
  45721 	132:  uint8(0x80),
  45722 	133:  uint8(0x80),
  45723 	134:  uint8(0x80),
  45724 	135:  uint8(0x80),
  45725 	136:  uint8(0x80),
  45726 	137:  uint8(0x80),
  45727 	138:  uint8(0x80),
  45728 	139:  uint8(0x80),
  45729 	140:  uint8(0x80),
  45730 	141:  uint8(0x80),
  45731 	142:  uint8(0x80),
  45732 	143:  uint8(0x80),
  45733 	144:  uint8(0x80),
  45734 	145:  uint8(0x80),
  45735 	146:  uint8(0x80),
  45736 	147:  uint8(0x80),
  45737 	148:  uint8(0x80),
  45738 	149:  uint8(0x80),
  45739 	150:  uint8(0x80),
  45740 	151:  uint8(0x80),
  45741 	152:  uint8(0x80),
  45742 	153:  uint8(0x80),
  45743 	154:  uint8(0x80),
  45744 	155:  uint8(0x80),
  45745 	156:  uint8(0x80),
  45746 	157:  uint8(0x80),
  45747 	158:  uint8(0x80),
  45748 	159:  uint8(0x80),
  45749 	160:  uint8(0x80),
  45750 	161:  uint8(0x80),
  45751 	162:  uint8(0x80),
  45752 	163:  uint8(0x80),
  45753 	164:  uint8(0x80),
  45754 	165:  uint8(0x80),
  45755 	166:  uint8(0x80),
  45756 	167:  uint8(0x80),
  45757 	168:  uint8(0x80),
  45758 	169:  uint8(0x80),
  45759 	170:  uint8(0x80),
  45760 	171:  uint8(0x80),
  45761 	172:  uint8(0x80),
  45762 	173:  uint8(0x80),
  45763 	174:  uint8(0x80),
  45764 	175:  uint8(0x80),
  45765 	176:  uint8(0x80),
  45766 	177:  uint8(0x80),
  45767 	178:  uint8(0x80),
  45768 	179:  uint8(0x80),
  45769 	180:  uint8(0x80),
  45770 	181:  uint8(0x80),
  45771 	182:  uint8(0x80),
  45772 	183:  uint8(0x80),
  45773 	184:  uint8(0x80),
  45774 	185:  uint8(0x80),
  45775 	186:  uint8(0x80),
  45776 	187:  uint8(0x80),
  45777 	188:  uint8(0x80),
  45778 	189:  uint8(0x80),
  45779 	190:  uint8(0x80),
  45780 	191:  uint8(0x80),
  45781 	192:  uint8(0x80),
  45782 	193:  uint8(0x80),
  45783 	194:  uint8(0x80),
  45784 	195:  uint8(0x80),
  45785 	196:  uint8(0x80),
  45786 	197:  uint8(0x80),
  45787 	198:  uint8(0x80),
  45788 	199:  uint8(0x80),
  45789 	200:  uint8(0x80),
  45790 	201:  uint8(0x80),
  45791 	202:  uint8(0x80),
  45792 	203:  uint8(0x80),
  45793 	204:  uint8(0x80),
  45794 	205:  uint8(0x80),
  45795 	206:  uint8(0x80),
  45796 	207:  uint8(0x80),
  45797 	208:  uint8(0x80),
  45798 	209:  uint8(0x80),
  45799 	210:  uint8(0x80),
  45800 	211:  uint8(0x80),
  45801 	212:  uint8(0x80),
  45802 	213:  uint8(0x80),
  45803 	214:  uint8(0x80),
  45804 	215:  uint8(0x80),
  45805 	216:  uint8(0x80),
  45806 	217:  uint8(0x80),
  45807 	218:  uint8(0x80),
  45808 	219:  uint8(0x80),
  45809 	220:  uint8(0x80),
  45810 	221:  uint8(0x80),
  45811 	222:  uint8(0x80),
  45812 	223:  uint8(0x80),
  45813 	224:  uint8(0x80),
  45814 	225:  uint8(0x80),
  45815 	226:  uint8(0x80),
  45816 	227:  uint8(0x80),
  45817 	228:  uint8(0x80),
  45818 	229:  uint8(0x80),
  45819 	230:  uint8(0x80),
  45820 	231:  uint8(0x80),
  45821 	232:  uint8(0x80),
  45822 	233:  uint8(0x80),
  45823 	234:  uint8(0x80),
  45824 	235:  uint8(0x80),
  45825 	236:  uint8(0x80),
  45826 	237:  uint8(0x80),
  45827 	238:  uint8(0x80),
  45828 	239:  uint8(0x80),
  45829 	240:  uint8(0x80),
  45830 	241:  uint8(0x80),
  45831 	242:  uint8(0x80),
  45832 	243:  uint8(0x80),
  45833 	244:  uint8(0x80),
  45834 	245:  uint8(0x80),
  45835 	246:  uint8(0x80),
  45836 	247:  uint8(0x80),
  45837 	248:  uint8(0x80),
  45838 	249:  uint8(0x80),
  45839 	250:  uint8(0x80),
  45840 	251:  uint8(0x80),
  45841 	252:  uint8(0x80),
  45842 	253:  uint8(0x80),
  45843 	254:  uint8(0x80),
  45844 	255:  uint8(0x80),
  45845 	256:  uint8(0x80),
  45846 	257:  uint8(0x80),
  45847 	258:  uint8(0x80),
  45848 	259:  uint8(0x80),
  45849 	260:  uint8(0x80),
  45850 	261:  uint8(0x80),
  45851 	262:  uint8(0x80),
  45852 	263:  uint8(0x80),
  45853 	264:  uint8(0x80),
  45854 	265:  uint8(0x80),
  45855 	266:  uint8(0x80),
  45856 	267:  uint8(0x80),
  45857 	268:  uint8(0x80),
  45858 	269:  uint8(0x80),
  45859 	270:  uint8(0x80),
  45860 	271:  uint8(0x80),
  45861 	272:  uint8(0x80),
  45862 	273:  uint8(0x80),
  45863 	274:  uint8(0x80),
  45864 	275:  uint8(0x80),
  45865 	276:  uint8(0x80),
  45866 	277:  uint8(0x80),
  45867 	278:  uint8(0x80),
  45868 	279:  uint8(0x80),
  45869 	280:  uint8(0x80),
  45870 	281:  uint8(0x80),
  45871 	282:  uint8(0x80),
  45872 	283:  uint8(0x80),
  45873 	284:  uint8(0x80),
  45874 	285:  uint8(0x80),
  45875 	286:  uint8(0x80),
  45876 	287:  uint8(0x80),
  45877 	288:  uint8(0x80),
  45878 	289:  uint8(0x80),
  45879 	290:  uint8(0x80),
  45880 	291:  uint8(0x80),
  45881 	292:  uint8(0x80),
  45882 	293:  uint8(0x80),
  45883 	294:  uint8(0x80),
  45884 	295:  uint8(0x80),
  45885 	296:  uint8(0x80),
  45886 	297:  uint8(0x80),
  45887 	298:  uint8(0x80),
  45888 	299:  uint8(0x80),
  45889 	300:  uint8(0x80),
  45890 	301:  uint8(0x80),
  45891 	302:  uint8(0x80),
  45892 	303:  uint8(0x80),
  45893 	304:  uint8(0x80),
  45894 	305:  uint8(0x80),
  45895 	306:  uint8(0x80),
  45896 	307:  uint8(0x80),
  45897 	308:  uint8(0x80),
  45898 	309:  uint8(0x80),
  45899 	310:  uint8(0x80),
  45900 	311:  uint8(0x80),
  45901 	312:  uint8(0x80),
  45902 	313:  uint8(0x80),
  45903 	314:  uint8(0x80),
  45904 	315:  uint8(0x80),
  45905 	316:  uint8(0x80),
  45906 	317:  uint8(0x80),
  45907 	318:  uint8(0x80),
  45908 	319:  uint8(0x80),
  45909 	320:  uint8(0x80),
  45910 	321:  uint8(0x80),
  45911 	322:  uint8(0x80),
  45912 	323:  uint8(0x80),
  45913 	324:  uint8(0x80),
  45914 	325:  uint8(0x80),
  45915 	326:  uint8(0x80),
  45916 	327:  uint8(0x80),
  45917 	328:  uint8(0x80),
  45918 	329:  uint8(0x80),
  45919 	330:  uint8(0x80),
  45920 	331:  uint8(0x80),
  45921 	332:  uint8(0x80),
  45922 	333:  uint8(0x80),
  45923 	334:  uint8(0x80),
  45924 	335:  uint8(0x80),
  45925 	336:  uint8(0x80),
  45926 	337:  uint8(0x80),
  45927 	338:  uint8(0x80),
  45928 	339:  uint8(0x80),
  45929 	340:  uint8(0x80),
  45930 	341:  uint8(0x80),
  45931 	342:  uint8(0x80),
  45932 	343:  uint8(0x80),
  45933 	344:  uint8(0x80),
  45934 	345:  uint8(0x80),
  45935 	346:  uint8(0x80),
  45936 	347:  uint8(0x80),
  45937 	348:  uint8(0x80),
  45938 	349:  uint8(0x80),
  45939 	350:  uint8(0x80),
  45940 	351:  uint8(0x80),
  45941 	352:  uint8(0x80),
  45942 	353:  uint8(0x80),
  45943 	354:  uint8(0x80),
  45944 	355:  uint8(0x80),
  45945 	356:  uint8(0x80),
  45946 	357:  uint8(0x80),
  45947 	358:  uint8(0x80),
  45948 	359:  uint8(0x80),
  45949 	360:  uint8(0x80),
  45950 	361:  uint8(0x80),
  45951 	362:  uint8(0x80),
  45952 	363:  uint8(0x80),
  45953 	364:  uint8(0x80),
  45954 	365:  uint8(0x80),
  45955 	366:  uint8(0x80),
  45956 	367:  uint8(0x80),
  45957 	368:  uint8(0x80),
  45958 	369:  uint8(0x80),
  45959 	370:  uint8(0x80),
  45960 	371:  uint8(0x80),
  45961 	372:  uint8(0x80),
  45962 	373:  uint8(0x80),
  45963 	374:  uint8(0x80),
  45964 	375:  uint8(0x80),
  45965 	376:  uint8(0x80),
  45966 	377:  uint8(0x80),
  45967 	378:  uint8(0x80),
  45968 	379:  uint8(0x80),
  45969 	380:  uint8(0x80),
  45970 	381:  uint8(0x80),
  45971 	382:  uint8(0x80),
  45972 	383:  uint8(0x80),
  45973 	384:  uint8(0x80),
  45974 	385:  uint8(0x80),
  45975 	386:  uint8(0x80),
  45976 	387:  uint8(0x80),
  45977 	388:  uint8(0x80),
  45978 	389:  uint8(0x80),
  45979 	390:  uint8(0x80),
  45980 	391:  uint8(0x80),
  45981 	392:  uint8(0x80),
  45982 	393:  uint8(0x80),
  45983 	394:  uint8(0x80),
  45984 	395:  uint8(0x80),
  45985 	396:  uint8(0x80),
  45986 	397:  uint8(0x80),
  45987 	398:  uint8(0x80),
  45988 	399:  uint8(0x80),
  45989 	400:  uint8(0x80),
  45990 	401:  uint8(0x80),
  45991 	402:  uint8(0x80),
  45992 	403:  uint8(0x80),
  45993 	404:  uint8(0x80),
  45994 	405:  uint8(0x80),
  45995 	406:  uint8(0x80),
  45996 	407:  uint8(0x80),
  45997 	408:  uint8(0x80),
  45998 	409:  uint8(0x80),
  45999 	410:  uint8(0x80),
  46000 	411:  uint8(0x80),
  46001 	412:  uint8(0x80),
  46002 	413:  uint8(0x80),
  46003 	414:  uint8(0x80),
  46004 	415:  uint8(0x80),
  46005 	416:  uint8(0x80),
  46006 	417:  uint8(0x80),
  46007 	418:  uint8(0x80),
  46008 	419:  uint8(0x80),
  46009 	420:  uint8(0x80),
  46010 	421:  uint8(0x80),
  46011 	422:  uint8(0x80),
  46012 	423:  uint8(0x80),
  46013 	424:  uint8(0x80),
  46014 	425:  uint8(0x80),
  46015 	426:  uint8(0x80),
  46016 	427:  uint8(0x80),
  46017 	428:  uint8(0x80),
  46018 	429:  uint8(0x80),
  46019 	430:  uint8(0x80),
  46020 	431:  uint8(0x80),
  46021 	432:  uint8(0x80),
  46022 	433:  uint8(0x80),
  46023 	434:  uint8(0x80),
  46024 	435:  uint8(0x80),
  46025 	436:  uint8(0x80),
  46026 	437:  uint8(0x80),
  46027 	438:  uint8(0x80),
  46028 	439:  uint8(0x80),
  46029 	440:  uint8(0x80),
  46030 	441:  uint8(0x80),
  46031 	442:  uint8(0x80),
  46032 	443:  uint8(0x80),
  46033 	444:  uint8(0x80),
  46034 	445:  uint8(0x80),
  46035 	446:  uint8(0x80),
  46036 	447:  uint8(0x80),
  46037 	448:  uint8(0x80),
  46038 	449:  uint8(0x80),
  46039 	450:  uint8(0x80),
  46040 	451:  uint8(0x80),
  46041 	452:  uint8(0x80),
  46042 	453:  uint8(0x80),
  46043 	454:  uint8(0x80),
  46044 	455:  uint8(0x80),
  46045 	456:  uint8(0x80),
  46046 	457:  uint8(0x80),
  46047 	458:  uint8(0x80),
  46048 	459:  uint8(0x80),
  46049 	460:  uint8(0x80),
  46050 	461:  uint8(0x80),
  46051 	462:  uint8(0x80),
  46052 	463:  uint8(0x80),
  46053 	464:  uint8(0x80),
  46054 	465:  uint8(0x80),
  46055 	466:  uint8(0x80),
  46056 	467:  uint8(0x80),
  46057 	468:  uint8(0x80),
  46058 	469:  uint8(0x80),
  46059 	470:  uint8(0x80),
  46060 	471:  uint8(0x80),
  46061 	472:  uint8(0x80),
  46062 	473:  uint8(0x80),
  46063 	474:  uint8(0x80),
  46064 	475:  uint8(0x80),
  46065 	476:  uint8(0x80),
  46066 	477:  uint8(0x80),
  46067 	478:  uint8(0x80),
  46068 	479:  uint8(0x80),
  46069 	480:  uint8(0x80),
  46070 	481:  uint8(0x80),
  46071 	482:  uint8(0x80),
  46072 	483:  uint8(0x80),
  46073 	484:  uint8(0x80),
  46074 	485:  uint8(0x80),
  46075 	486:  uint8(0x80),
  46076 	487:  uint8(0x80),
  46077 	488:  uint8(0x80),
  46078 	489:  uint8(0x80),
  46079 	490:  uint8(0x80),
  46080 	491:  uint8(0x80),
  46081 	492:  uint8(0x80),
  46082 	493:  uint8(0x80),
  46083 	494:  uint8(0x80),
  46084 	495:  uint8(0x80),
  46085 	496:  uint8(0x80),
  46086 	497:  uint8(0x80),
  46087 	498:  uint8(0x80),
  46088 	499:  uint8(0x80),
  46089 	500:  uint8(0x80),
  46090 	501:  uint8(0x80),
  46091 	502:  uint8(0x80),
  46092 	503:  uint8(0x80),
  46093 	504:  uint8(0x80),
  46094 	505:  uint8(0x80),
  46095 	506:  uint8(0x80),
  46096 	507:  uint8(0x80),
  46097 	508:  uint8(0x80),
  46098 	509:  uint8(0x80),
  46099 	510:  uint8(0x80),
  46100 	511:  uint8(0x80),
  46101 	512:  uint8(0x80),
  46102 	513:  uint8(0x80),
  46103 	514:  uint8(0x80),
  46104 	515:  uint8(0x80),
  46105 	516:  uint8(0x80),
  46106 	517:  uint8(0x80),
  46107 	518:  uint8(0x80),
  46108 	519:  uint8(0x80),
  46109 	520:  uint8(0x80),
  46110 	521:  uint8(0x80),
  46111 	522:  uint8(0x80),
  46112 	523:  uint8(0x80),
  46113 	524:  uint8(0x80),
  46114 	525:  uint8(0x80),
  46115 	526:  uint8(0x80),
  46116 	527:  uint8(0x80),
  46117 	528:  uint8(0x80),
  46118 	529:  uint8(0x80),
  46119 	530:  uint8(0x80),
  46120 	531:  uint8(0x80),
  46121 	532:  uint8(0x80),
  46122 	533:  uint8(0x80),
  46123 	534:  uint8(0x80),
  46124 	535:  uint8(0x80),
  46125 	536:  uint8(0x80),
  46126 	537:  uint8(0x80),
  46127 	538:  uint8(0x80),
  46128 	539:  uint8(0x80),
  46129 	540:  uint8(0x80),
  46130 	541:  uint8(0x80),
  46131 	542:  uint8(0x80),
  46132 	543:  uint8(0x80),
  46133 	544:  uint8(0x80),
  46134 	545:  uint8(0x80),
  46135 	546:  uint8(0x80),
  46136 	547:  uint8(0x80),
  46137 	548:  uint8(0x80),
  46138 	549:  uint8(0x80),
  46139 	550:  uint8(0x80),
  46140 	551:  uint8(0x80),
  46141 	552:  uint8(0x80),
  46142 	553:  uint8(0x80),
  46143 	554:  uint8(0x80),
  46144 	555:  uint8(0x80),
  46145 	556:  uint8(0x80),
  46146 	557:  uint8(0x80),
  46147 	558:  uint8(0x80),
  46148 	559:  uint8(0x80),
  46149 	560:  uint8(0x80),
  46150 	561:  uint8(0x80),
  46151 	562:  uint8(0x80),
  46152 	563:  uint8(0x80),
  46153 	564:  uint8(0x80),
  46154 	565:  uint8(0x80),
  46155 	566:  uint8(0x80),
  46156 	567:  uint8(0x80),
  46157 	568:  uint8(0x80),
  46158 	569:  uint8(0x80),
  46159 	570:  uint8(0x80),
  46160 	571:  uint8(0x80),
  46161 	572:  uint8(0x80),
  46162 	573:  uint8(0x80),
  46163 	574:  uint8(0x80),
  46164 	575:  uint8(0x80),
  46165 	576:  uint8(0x80),
  46166 	577:  uint8(0x80),
  46167 	578:  uint8(0x80),
  46168 	579:  uint8(0x80),
  46169 	580:  uint8(0x80),
  46170 	581:  uint8(0x80),
  46171 	582:  uint8(0x80),
  46172 	583:  uint8(0x80),
  46173 	584:  uint8(0x80),
  46174 	585:  uint8(0x80),
  46175 	586:  uint8(0x80),
  46176 	587:  uint8(0x80),
  46177 	588:  uint8(0x80),
  46178 	589:  uint8(0x80),
  46179 	590:  uint8(0x80),
  46180 	591:  uint8(0x80),
  46181 	592:  uint8(0x80),
  46182 	593:  uint8(0x80),
  46183 	594:  uint8(0x80),
  46184 	595:  uint8(0x80),
  46185 	596:  uint8(0x80),
  46186 	597:  uint8(0x80),
  46187 	598:  uint8(0x80),
  46188 	599:  uint8(0x80),
  46189 	600:  uint8(0x80),
  46190 	601:  uint8(0x80),
  46191 	602:  uint8(0x80),
  46192 	603:  uint8(0x80),
  46193 	604:  uint8(0x80),
  46194 	605:  uint8(0x80),
  46195 	606:  uint8(0x80),
  46196 	607:  uint8(0x80),
  46197 	608:  uint8(0x80),
  46198 	609:  uint8(0x80),
  46199 	610:  uint8(0x80),
  46200 	611:  uint8(0x80),
  46201 	612:  uint8(0x80),
  46202 	613:  uint8(0x80),
  46203 	614:  uint8(0x80),
  46204 	615:  uint8(0x80),
  46205 	616:  uint8(0x80),
  46206 	617:  uint8(0x80),
  46207 	618:  uint8(0x80),
  46208 	619:  uint8(0x80),
  46209 	620:  uint8(0x80),
  46210 	621:  uint8(0x80),
  46211 	622:  uint8(0x80),
  46212 	623:  uint8(0x80),
  46213 	624:  uint8(0x80),
  46214 	625:  uint8(0x80),
  46215 	626:  uint8(0x80),
  46216 	627:  uint8(0x80),
  46217 	628:  uint8(0x80),
  46218 	629:  uint8(0x80),
  46219 	630:  uint8(0x80),
  46220 	631:  uint8(0x80),
  46221 	632:  uint8(0x80),
  46222 	633:  uint8(0x80),
  46223 	634:  uint8(0x80),
  46224 	635:  uint8(0x80),
  46225 	636:  uint8(0x80),
  46226 	637:  uint8(0x80),
  46227 	638:  uint8(0x80),
  46228 	639:  uint8(0x80),
  46229 	640:  uint8(0x80),
  46230 	641:  uint8(0x80),
  46231 	642:  uint8(0x80),
  46232 	643:  uint8(0x80),
  46233 	644:  uint8(0x80),
  46234 	645:  uint8(0x80),
  46235 	646:  uint8(0x80),
  46236 	647:  uint8(0x80),
  46237 	648:  uint8(0x80),
  46238 	649:  uint8(0x80),
  46239 	650:  uint8(0x80),
  46240 	651:  uint8(0x80),
  46241 	652:  uint8(0x80),
  46242 	653:  uint8(0x80),
  46243 	654:  uint8(0x80),
  46244 	655:  uint8(0x80),
  46245 	656:  uint8(0x80),
  46246 	657:  uint8(0x80),
  46247 	658:  uint8(0x80),
  46248 	659:  uint8(0x80),
  46249 	660:  uint8(0x80),
  46250 	661:  uint8(0x80),
  46251 	662:  uint8(0x80),
  46252 	663:  uint8(0x80),
  46253 	664:  uint8(0x80),
  46254 	665:  uint8(0x80),
  46255 	666:  uint8(0x80),
  46256 	667:  uint8(0x80),
  46257 	668:  uint8(0x80),
  46258 	669:  uint8(0x80),
  46259 	670:  uint8(0x80),
  46260 	671:  uint8(0x80),
  46261 	672:  uint8(0x80),
  46262 	673:  uint8(0x80),
  46263 	674:  uint8(0x80),
  46264 	675:  uint8(0x80),
  46265 	676:  uint8(0x80),
  46266 	677:  uint8(0x80),
  46267 	678:  uint8(0x80),
  46268 	679:  uint8(0x80),
  46269 	680:  uint8(0x80),
  46270 	681:  uint8(0x80),
  46271 	682:  uint8(0x80),
  46272 	683:  uint8(0x80),
  46273 	684:  uint8(0x80),
  46274 	685:  uint8(0x80),
  46275 	686:  uint8(0x80),
  46276 	687:  uint8(0x80),
  46277 	688:  uint8(0x80),
  46278 	689:  uint8(0x80),
  46279 	690:  uint8(0x80),
  46280 	691:  uint8(0x80),
  46281 	692:  uint8(0x80),
  46282 	693:  uint8(0x80),
  46283 	694:  uint8(0x80),
  46284 	695:  uint8(0x80),
  46285 	696:  uint8(0x80),
  46286 	697:  uint8(0x80),
  46287 	698:  uint8(0x80),
  46288 	699:  uint8(0x80),
  46289 	700:  uint8(0x80),
  46290 	701:  uint8(0x80),
  46291 	702:  uint8(0x80),
  46292 	703:  uint8(0x80),
  46293 	704:  uint8(0x80),
  46294 	705:  uint8(0x80),
  46295 	706:  uint8(0x80),
  46296 	707:  uint8(0x80),
  46297 	708:  uint8(0x80),
  46298 	709:  uint8(0x80),
  46299 	710:  uint8(0x80),
  46300 	711:  uint8(0x80),
  46301 	712:  uint8(0x80),
  46302 	713:  uint8(0x80),
  46303 	714:  uint8(0x80),
  46304 	715:  uint8(0x80),
  46305 	716:  uint8(0x80),
  46306 	717:  uint8(0x80),
  46307 	718:  uint8(0x80),
  46308 	719:  uint8(0x80),
  46309 	720:  uint8(0x80),
  46310 	721:  uint8(0x80),
  46311 	722:  uint8(0x80),
  46312 	723:  uint8(0x80),
  46313 	724:  uint8(0x80),
  46314 	725:  uint8(0x80),
  46315 	726:  uint8(0x80),
  46316 	727:  uint8(0x80),
  46317 	728:  uint8(0x80),
  46318 	729:  uint8(0x80),
  46319 	730:  uint8(0x80),
  46320 	731:  uint8(0x80),
  46321 	732:  uint8(0x80),
  46322 	733:  uint8(0x80),
  46323 	734:  uint8(0x80),
  46324 	735:  uint8(0x80),
  46325 	736:  uint8(0x80),
  46326 	737:  uint8(0x80),
  46327 	738:  uint8(0x80),
  46328 	739:  uint8(0x80),
  46329 	740:  uint8(0x80),
  46330 	741:  uint8(0x80),
  46331 	742:  uint8(0x80),
  46332 	743:  uint8(0x80),
  46333 	744:  uint8(0x80),
  46334 	745:  uint8(0x80),
  46335 	746:  uint8(0x80),
  46336 	747:  uint8(0x80),
  46337 	748:  uint8(0x80),
  46338 	749:  uint8(0x80),
  46339 	750:  uint8(0x80),
  46340 	751:  uint8(0x80),
  46341 	752:  uint8(0x80),
  46342 	753:  uint8(0x80),
  46343 	754:  uint8(0x80),
  46344 	755:  uint8(0x80),
  46345 	756:  uint8(0x80),
  46346 	757:  uint8(0x80),
  46347 	758:  uint8(0x80),
  46348 	759:  uint8(0x80),
  46349 	760:  uint8(0x80),
  46350 	761:  uint8(0x80),
  46351 	762:  uint8(0x80),
  46352 	763:  uint8(0x80),
  46353 	764:  uint8(0x80),
  46354 	765:  uint8(0x80),
  46355 	766:  uint8(0x80),
  46356 	767:  uint8(0x80),
  46357 	768:  uint8(0x80),
  46358 	769:  uint8(0x80),
  46359 	770:  uint8(0x80),
  46360 	771:  uint8(0x80),
  46361 	772:  uint8(0x80),
  46362 	773:  uint8(0x80),
  46363 	774:  uint8(0x80),
  46364 	775:  uint8(0x80),
  46365 	776:  uint8(0x80),
  46366 	777:  uint8(0x80),
  46367 	778:  uint8(0x80),
  46368 	779:  uint8(0x80),
  46369 	780:  uint8(0x80),
  46370 	781:  uint8(0x80),
  46371 	782:  uint8(0x80),
  46372 	783:  uint8(0x80),
  46373 	784:  uint8(0x80),
  46374 	785:  uint8(0x80),
  46375 	786:  uint8(0x80),
  46376 	787:  uint8(0x80),
  46377 	788:  uint8(0x80),
  46378 	789:  uint8(0x80),
  46379 	790:  uint8(0x80),
  46380 	791:  uint8(0x80),
  46381 	792:  uint8(0x80),
  46382 	793:  uint8(0x80),
  46383 	794:  uint8(0x80),
  46384 	795:  uint8(0x80),
  46385 	796:  uint8(0x80),
  46386 	797:  uint8(0x80),
  46387 	798:  uint8(0x80),
  46388 	799:  uint8(0x80),
  46389 	800:  uint8(0x80),
  46390 	801:  uint8(0x80),
  46391 	802:  uint8(0x80),
  46392 	803:  uint8(0x80),
  46393 	804:  uint8(0x80),
  46394 	805:  uint8(0x80),
  46395 	806:  uint8(0x80),
  46396 	807:  uint8(0x80),
  46397 	808:  uint8(0x80),
  46398 	809:  uint8(0x80),
  46399 	810:  uint8(0x80),
  46400 	811:  uint8(0x80),
  46401 	812:  uint8(0x80),
  46402 	813:  uint8(0x80),
  46403 	814:  uint8(0x80),
  46404 	815:  uint8(0x80),
  46405 	816:  uint8(0x80),
  46406 	817:  uint8(0x80),
  46407 	818:  uint8(0x80),
  46408 	819:  uint8(0x80),
  46409 	820:  uint8(0x80),
  46410 	821:  uint8(0x80),
  46411 	822:  uint8(0x80),
  46412 	823:  uint8(0x80),
  46413 	824:  uint8(0x80),
  46414 	825:  uint8(0x80),
  46415 	826:  uint8(0x80),
  46416 	827:  uint8(0x80),
  46417 	828:  uint8(0x80),
  46418 	829:  uint8(0x80),
  46419 	830:  uint8(0x80),
  46420 	831:  uint8(0x80),
  46421 	832:  uint8(0x80),
  46422 	833:  uint8(0x80),
  46423 	834:  uint8(0x80),
  46424 	835:  uint8(0x80),
  46425 	836:  uint8(0x80),
  46426 	837:  uint8(0x80),
  46427 	838:  uint8(0x80),
  46428 	839:  uint8(0x80),
  46429 	840:  uint8(0x80),
  46430 	841:  uint8(0x80),
  46431 	842:  uint8(0x80),
  46432 	843:  uint8(0x80),
  46433 	844:  uint8(0x80),
  46434 	845:  uint8(0x80),
  46435 	846:  uint8(0x80),
  46436 	847:  uint8(0x80),
  46437 	848:  uint8(0x80),
  46438 	849:  uint8(0x80),
  46439 	850:  uint8(0x80),
  46440 	851:  uint8(0x80),
  46441 	852:  uint8(0x80),
  46442 	853:  uint8(0x80),
  46443 	854:  uint8(0x80),
  46444 	855:  uint8(0x80),
  46445 	856:  uint8(0x80),
  46446 	857:  uint8(0x80),
  46447 	858:  uint8(0x80),
  46448 	859:  uint8(0x80),
  46449 	860:  uint8(0x80),
  46450 	861:  uint8(0x80),
  46451 	862:  uint8(0x80),
  46452 	863:  uint8(0x80),
  46453 	864:  uint8(0x80),
  46454 	865:  uint8(0x80),
  46455 	866:  uint8(0x80),
  46456 	867:  uint8(0x80),
  46457 	868:  uint8(0x80),
  46458 	869:  uint8(0x80),
  46459 	870:  uint8(0x80),
  46460 	871:  uint8(0x80),
  46461 	872:  uint8(0x80),
  46462 	873:  uint8(0x80),
  46463 	874:  uint8(0x80),
  46464 	875:  uint8(0x80),
  46465 	876:  uint8(0x80),
  46466 	877:  uint8(0x80),
  46467 	878:  uint8(0x80),
  46468 	879:  uint8(0x80),
  46469 	880:  uint8(0x80),
  46470 	881:  uint8(0x80),
  46471 	882:  uint8(0x80),
  46472 	883:  uint8(0x80),
  46473 	884:  uint8(0x80),
  46474 	885:  uint8(0x80),
  46475 	886:  uint8(0x80),
  46476 	887:  uint8(0x80),
  46477 	888:  uint8(0x80),
  46478 	889:  uint8(0x80),
  46479 	890:  uint8(0x80),
  46480 	891:  uint8(0x80),
  46481 	892:  uint8(0x80),
  46482 	893:  uint8(0x81),
  46483 	894:  uint8(0x82),
  46484 	895:  uint8(0x83),
  46485 	896:  uint8(0x84),
  46486 	897:  uint8(0x85),
  46487 	898:  uint8(0x86),
  46488 	899:  uint8(0x87),
  46489 	900:  uint8(0x88),
  46490 	901:  uint8(0x89),
  46491 	902:  uint8(0x8a),
  46492 	903:  uint8(0x8b),
  46493 	904:  uint8(0x8c),
  46494 	905:  uint8(0x8d),
  46495 	906:  uint8(0x8e),
  46496 	907:  uint8(0x8f),
  46497 	908:  uint8(0x90),
  46498 	909:  uint8(0x91),
  46499 	910:  uint8(0x92),
  46500 	911:  uint8(0x93),
  46501 	912:  uint8(0x94),
  46502 	913:  uint8(0x95),
  46503 	914:  uint8(0x96),
  46504 	915:  uint8(0x97),
  46505 	916:  uint8(0x98),
  46506 	917:  uint8(0x99),
  46507 	918:  uint8(0x9a),
  46508 	919:  uint8(0x9b),
  46509 	920:  uint8(0x9c),
  46510 	921:  uint8(0x9d),
  46511 	922:  uint8(0x9e),
  46512 	923:  uint8(0x9f),
  46513 	924:  uint8(0xa0),
  46514 	925:  uint8(0xa1),
  46515 	926:  uint8(0xa2),
  46516 	927:  uint8(0xa3),
  46517 	928:  uint8(0xa4),
  46518 	929:  uint8(0xa5),
  46519 	930:  uint8(0xa6),
  46520 	931:  uint8(0xa7),
  46521 	932:  uint8(0xa8),
  46522 	933:  uint8(0xa9),
  46523 	934:  uint8(0xaa),
  46524 	935:  uint8(0xab),
  46525 	936:  uint8(0xac),
  46526 	937:  uint8(0xad),
  46527 	938:  uint8(0xae),
  46528 	939:  uint8(0xaf),
  46529 	940:  uint8(0xb0),
  46530 	941:  uint8(0xb1),
  46531 	942:  uint8(0xb2),
  46532 	943:  uint8(0xb3),
  46533 	944:  uint8(0xb4),
  46534 	945:  uint8(0xb5),
  46535 	946:  uint8(0xb6),
  46536 	947:  uint8(0xb7),
  46537 	948:  uint8(0xb8),
  46538 	949:  uint8(0xb9),
  46539 	950:  uint8(0xba),
  46540 	951:  uint8(0xbb),
  46541 	952:  uint8(0xbc),
  46542 	953:  uint8(0xbd),
  46543 	954:  uint8(0xbe),
  46544 	955:  uint8(0xbf),
  46545 	956:  uint8(0xc0),
  46546 	957:  uint8(0xc1),
  46547 	958:  uint8(0xc2),
  46548 	959:  uint8(0xc3),
  46549 	960:  uint8(0xc4),
  46550 	961:  uint8(0xc5),
  46551 	962:  uint8(0xc6),
  46552 	963:  uint8(0xc7),
  46553 	964:  uint8(0xc8),
  46554 	965:  uint8(0xc9),
  46555 	966:  uint8(0xca),
  46556 	967:  uint8(0xcb),
  46557 	968:  uint8(0xcc),
  46558 	969:  uint8(0xcd),
  46559 	970:  uint8(0xce),
  46560 	971:  uint8(0xcf),
  46561 	972:  uint8(0xd0),
  46562 	973:  uint8(0xd1),
  46563 	974:  uint8(0xd2),
  46564 	975:  uint8(0xd3),
  46565 	976:  uint8(0xd4),
  46566 	977:  uint8(0xd5),
  46567 	978:  uint8(0xd6),
  46568 	979:  uint8(0xd7),
  46569 	980:  uint8(0xd8),
  46570 	981:  uint8(0xd9),
  46571 	982:  uint8(0xda),
  46572 	983:  uint8(0xdb),
  46573 	984:  uint8(0xdc),
  46574 	985:  uint8(0xdd),
  46575 	986:  uint8(0xde),
  46576 	987:  uint8(0xdf),
  46577 	988:  uint8(0xe0),
  46578 	989:  uint8(0xe1),
  46579 	990:  uint8(0xe2),
  46580 	991:  uint8(0xe3),
  46581 	992:  uint8(0xe4),
  46582 	993:  uint8(0xe5),
  46583 	994:  uint8(0xe6),
  46584 	995:  uint8(0xe7),
  46585 	996:  uint8(0xe8),
  46586 	997:  uint8(0xe9),
  46587 	998:  uint8(0xea),
  46588 	999:  uint8(0xeb),
  46589 	1000: uint8(0xec),
  46590 	1001: uint8(0xed),
  46591 	1002: uint8(0xee),
  46592 	1003: uint8(0xef),
  46593 	1004: uint8(0xf0),
  46594 	1005: uint8(0xf1),
  46595 	1006: uint8(0xf2),
  46596 	1007: uint8(0xf3),
  46597 	1008: uint8(0xf4),
  46598 	1009: uint8(0xf5),
  46599 	1010: uint8(0xf6),
  46600 	1011: uint8(0xf7),
  46601 	1012: uint8(0xf8),
  46602 	1013: uint8(0xf9),
  46603 	1014: uint8(0xfa),
  46604 	1015: uint8(0xfb),
  46605 	1016: uint8(0xfc),
  46606 	1017: uint8(0xfd),
  46607 	1018: uint8(0xfe),
  46608 	1019: uint8(0xff),
  46609 	1021: uint8(0x01),
  46610 	1022: uint8(0x02),
  46611 	1023: uint8(0x03),
  46612 	1024: uint8(0x04),
  46613 	1025: uint8(0x05),
  46614 	1026: uint8(0x06),
  46615 	1027: uint8(0x07),
  46616 	1028: uint8(0x08),
  46617 	1029: uint8(0x09),
  46618 	1030: uint8(0x0a),
  46619 	1031: uint8(0x0b),
  46620 	1032: uint8(0x0c),
  46621 	1033: uint8(0x0d),
  46622 	1034: uint8(0x0e),
  46623 	1035: uint8(0x0f),
  46624 	1036: uint8(0x10),
  46625 	1037: uint8(0x11),
  46626 	1038: uint8(0x12),
  46627 	1039: uint8(0x13),
  46628 	1040: uint8(0x14),
  46629 	1041: uint8(0x15),
  46630 	1042: uint8(0x16),
  46631 	1043: uint8(0x17),
  46632 	1044: uint8(0x18),
  46633 	1045: uint8(0x19),
  46634 	1046: uint8(0x1a),
  46635 	1047: uint8(0x1b),
  46636 	1048: uint8(0x1c),
  46637 	1049: uint8(0x1d),
  46638 	1050: uint8(0x1e),
  46639 	1051: uint8(0x1f),
  46640 	1052: uint8(0x20),
  46641 	1053: uint8(0x21),
  46642 	1054: uint8(0x22),
  46643 	1055: uint8(0x23),
  46644 	1056: uint8(0x24),
  46645 	1057: uint8(0x25),
  46646 	1058: uint8(0x26),
  46647 	1059: uint8(0x27),
  46648 	1060: uint8(0x28),
  46649 	1061: uint8(0x29),
  46650 	1062: uint8(0x2a),
  46651 	1063: uint8(0x2b),
  46652 	1064: uint8(0x2c),
  46653 	1065: uint8(0x2d),
  46654 	1066: uint8(0x2e),
  46655 	1067: uint8(0x2f),
  46656 	1068: uint8(0x30),
  46657 	1069: uint8(0x31),
  46658 	1070: uint8(0x32),
  46659 	1071: uint8(0x33),
  46660 	1072: uint8(0x34),
  46661 	1073: uint8(0x35),
  46662 	1074: uint8(0x36),
  46663 	1075: uint8(0x37),
  46664 	1076: uint8(0x38),
  46665 	1077: uint8(0x39),
  46666 	1078: uint8(0x3a),
  46667 	1079: uint8(0x3b),
  46668 	1080: uint8(0x3c),
  46669 	1081: uint8(0x3d),
  46670 	1082: uint8(0x3e),
  46671 	1083: uint8(0x3f),
  46672 	1084: uint8(0x40),
  46673 	1085: uint8(0x41),
  46674 	1086: uint8(0x42),
  46675 	1087: uint8(0x43),
  46676 	1088: uint8(0x44),
  46677 	1089: uint8(0x45),
  46678 	1090: uint8(0x46),
  46679 	1091: uint8(0x47),
  46680 	1092: uint8(0x48),
  46681 	1093: uint8(0x49),
  46682 	1094: uint8(0x4a),
  46683 	1095: uint8(0x4b),
  46684 	1096: uint8(0x4c),
  46685 	1097: uint8(0x4d),
  46686 	1098: uint8(0x4e),
  46687 	1099: uint8(0x4f),
  46688 	1100: uint8(0x50),
  46689 	1101: uint8(0x51),
  46690 	1102: uint8(0x52),
  46691 	1103: uint8(0x53),
  46692 	1104: uint8(0x54),
  46693 	1105: uint8(0x55),
  46694 	1106: uint8(0x56),
  46695 	1107: uint8(0x57),
  46696 	1108: uint8(0x58),
  46697 	1109: uint8(0x59),
  46698 	1110: uint8(0x5a),
  46699 	1111: uint8(0x5b),
  46700 	1112: uint8(0x5c),
  46701 	1113: uint8(0x5d),
  46702 	1114: uint8(0x5e),
  46703 	1115: uint8(0x5f),
  46704 	1116: uint8(0x60),
  46705 	1117: uint8(0x61),
  46706 	1118: uint8(0x62),
  46707 	1119: uint8(0x63),
  46708 	1120: uint8(0x64),
  46709 	1121: uint8(0x65),
  46710 	1122: uint8(0x66),
  46711 	1123: uint8(0x67),
  46712 	1124: uint8(0x68),
  46713 	1125: uint8(0x69),
  46714 	1126: uint8(0x6a),
  46715 	1127: uint8(0x6b),
  46716 	1128: uint8(0x6c),
  46717 	1129: uint8(0x6d),
  46718 	1130: uint8(0x6e),
  46719 	1131: uint8(0x6f),
  46720 	1132: uint8(0x70),
  46721 	1133: uint8(0x71),
  46722 	1134: uint8(0x72),
  46723 	1135: uint8(0x73),
  46724 	1136: uint8(0x74),
  46725 	1137: uint8(0x75),
  46726 	1138: uint8(0x76),
  46727 	1139: uint8(0x77),
  46728 	1140: uint8(0x78),
  46729 	1141: uint8(0x79),
  46730 	1142: uint8(0x7a),
  46731 	1143: uint8(0x7b),
  46732 	1144: uint8(0x7c),
  46733 	1145: uint8(0x7d),
  46734 	1146: uint8(0x7e),
  46735 	1147: uint8(0x7f),
  46736 	1148: uint8(0x7f),
  46737 	1149: uint8(0x7f),
  46738 	1150: uint8(0x7f),
  46739 	1151: uint8(0x7f),
  46740 	1152: uint8(0x7f),
  46741 	1153: uint8(0x7f),
  46742 	1154: uint8(0x7f),
  46743 	1155: uint8(0x7f),
  46744 	1156: uint8(0x7f),
  46745 	1157: uint8(0x7f),
  46746 	1158: uint8(0x7f),
  46747 	1159: uint8(0x7f),
  46748 	1160: uint8(0x7f),
  46749 	1161: uint8(0x7f),
  46750 	1162: uint8(0x7f),
  46751 	1163: uint8(0x7f),
  46752 	1164: uint8(0x7f),
  46753 	1165: uint8(0x7f),
  46754 	1166: uint8(0x7f),
  46755 	1167: uint8(0x7f),
  46756 	1168: uint8(0x7f),
  46757 	1169: uint8(0x7f),
  46758 	1170: uint8(0x7f),
  46759 	1171: uint8(0x7f),
  46760 	1172: uint8(0x7f),
  46761 	1173: uint8(0x7f),
  46762 	1174: uint8(0x7f),
  46763 	1175: uint8(0x7f),
  46764 	1176: uint8(0x7f),
  46765 	1177: uint8(0x7f),
  46766 	1178: uint8(0x7f),
  46767 	1179: uint8(0x7f),
  46768 	1180: uint8(0x7f),
  46769 	1181: uint8(0x7f),
  46770 	1182: uint8(0x7f),
  46771 	1183: uint8(0x7f),
  46772 	1184: uint8(0x7f),
  46773 	1185: uint8(0x7f),
  46774 	1186: uint8(0x7f),
  46775 	1187: uint8(0x7f),
  46776 	1188: uint8(0x7f),
  46777 	1189: uint8(0x7f),
  46778 	1190: uint8(0x7f),
  46779 	1191: uint8(0x7f),
  46780 	1192: uint8(0x7f),
  46781 	1193: uint8(0x7f),
  46782 	1194: uint8(0x7f),
  46783 	1195: uint8(0x7f),
  46784 	1196: uint8(0x7f),
  46785 	1197: uint8(0x7f),
  46786 	1198: uint8(0x7f),
  46787 	1199: uint8(0x7f),
  46788 	1200: uint8(0x7f),
  46789 	1201: uint8(0x7f),
  46790 	1202: uint8(0x7f),
  46791 	1203: uint8(0x7f),
  46792 	1204: uint8(0x7f),
  46793 	1205: uint8(0x7f),
  46794 	1206: uint8(0x7f),
  46795 	1207: uint8(0x7f),
  46796 	1208: uint8(0x7f),
  46797 	1209: uint8(0x7f),
  46798 	1210: uint8(0x7f),
  46799 	1211: uint8(0x7f),
  46800 	1212: uint8(0x7f),
  46801 	1213: uint8(0x7f),
  46802 	1214: uint8(0x7f),
  46803 	1215: uint8(0x7f),
  46804 	1216: uint8(0x7f),
  46805 	1217: uint8(0x7f),
  46806 	1218: uint8(0x7f),
  46807 	1219: uint8(0x7f),
  46808 	1220: uint8(0x7f),
  46809 	1221: uint8(0x7f),
  46810 	1222: uint8(0x7f),
  46811 	1223: uint8(0x7f),
  46812 	1224: uint8(0x7f),
  46813 	1225: uint8(0x7f),
  46814 	1226: uint8(0x7f),
  46815 	1227: uint8(0x7f),
  46816 	1228: uint8(0x7f),
  46817 	1229: uint8(0x7f),
  46818 	1230: uint8(0x7f),
  46819 	1231: uint8(0x7f),
  46820 	1232: uint8(0x7f),
  46821 	1233: uint8(0x7f),
  46822 	1234: uint8(0x7f),
  46823 	1235: uint8(0x7f),
  46824 	1236: uint8(0x7f),
  46825 	1237: uint8(0x7f),
  46826 	1238: uint8(0x7f),
  46827 	1239: uint8(0x7f),
  46828 	1240: uint8(0x7f),
  46829 	1241: uint8(0x7f),
  46830 	1242: uint8(0x7f),
  46831 	1243: uint8(0x7f),
  46832 	1244: uint8(0x7f),
  46833 	1245: uint8(0x7f),
  46834 	1246: uint8(0x7f),
  46835 	1247: uint8(0x7f),
  46836 	1248: uint8(0x7f),
  46837 	1249: uint8(0x7f),
  46838 	1250: uint8(0x7f),
  46839 	1251: uint8(0x7f),
  46840 	1252: uint8(0x7f),
  46841 	1253: uint8(0x7f),
  46842 	1254: uint8(0x7f),
  46843 	1255: uint8(0x7f),
  46844 	1256: uint8(0x7f),
  46845 	1257: uint8(0x7f),
  46846 	1258: uint8(0x7f),
  46847 	1259: uint8(0x7f),
  46848 	1260: uint8(0x7f),
  46849 	1261: uint8(0x7f),
  46850 	1262: uint8(0x7f),
  46851 	1263: uint8(0x7f),
  46852 	1264: uint8(0x7f),
  46853 	1265: uint8(0x7f),
  46854 	1266: uint8(0x7f),
  46855 	1267: uint8(0x7f),
  46856 	1268: uint8(0x7f),
  46857 	1269: uint8(0x7f),
  46858 	1270: uint8(0x7f),
  46859 	1271: uint8(0x7f),
  46860 	1272: uint8(0x7f),
  46861 	1273: uint8(0x7f),
  46862 	1274: uint8(0x7f),
  46863 	1275: uint8(0x7f),
  46864 	1276: uint8(0x7f),
  46865 	1277: uint8(0x7f),
  46866 	1278: uint8(0x7f),
  46867 	1279: uint8(0x7f),
  46868 	1280: uint8(0x7f),
  46869 	1281: uint8(0x7f),
  46870 	1282: uint8(0x7f),
  46871 	1283: uint8(0x7f),
  46872 	1284: uint8(0x7f),
  46873 	1285: uint8(0x7f),
  46874 	1286: uint8(0x7f),
  46875 	1287: uint8(0x7f),
  46876 	1288: uint8(0x7f),
  46877 	1289: uint8(0x7f),
  46878 	1290: uint8(0x7f),
  46879 	1291: uint8(0x7f),
  46880 	1292: uint8(0x7f),
  46881 	1293: uint8(0x7f),
  46882 	1294: uint8(0x7f),
  46883 	1295: uint8(0x7f),
  46884 	1296: uint8(0x7f),
  46885 	1297: uint8(0x7f),
  46886 	1298: uint8(0x7f),
  46887 	1299: uint8(0x7f),
  46888 	1300: uint8(0x7f),
  46889 	1301: uint8(0x7f),
  46890 	1302: uint8(0x7f),
  46891 	1303: uint8(0x7f),
  46892 	1304: uint8(0x7f),
  46893 	1305: uint8(0x7f),
  46894 	1306: uint8(0x7f),
  46895 	1307: uint8(0x7f),
  46896 	1308: uint8(0x7f),
  46897 	1309: uint8(0x7f),
  46898 	1310: uint8(0x7f),
  46899 	1311: uint8(0x7f),
  46900 	1312: uint8(0x7f),
  46901 	1313: uint8(0x7f),
  46902 	1314: uint8(0x7f),
  46903 	1315: uint8(0x7f),
  46904 	1316: uint8(0x7f),
  46905 	1317: uint8(0x7f),
  46906 	1318: uint8(0x7f),
  46907 	1319: uint8(0x7f),
  46908 	1320: uint8(0x7f),
  46909 	1321: uint8(0x7f),
  46910 	1322: uint8(0x7f),
  46911 	1323: uint8(0x7f),
  46912 	1324: uint8(0x7f),
  46913 	1325: uint8(0x7f),
  46914 	1326: uint8(0x7f),
  46915 	1327: uint8(0x7f),
  46916 	1328: uint8(0x7f),
  46917 	1329: uint8(0x7f),
  46918 	1330: uint8(0x7f),
  46919 	1331: uint8(0x7f),
  46920 	1332: uint8(0x7f),
  46921 	1333: uint8(0x7f),
  46922 	1334: uint8(0x7f),
  46923 	1335: uint8(0x7f),
  46924 	1336: uint8(0x7f),
  46925 	1337: uint8(0x7f),
  46926 	1338: uint8(0x7f),
  46927 	1339: uint8(0x7f),
  46928 	1340: uint8(0x7f),
  46929 	1341: uint8(0x7f),
  46930 	1342: uint8(0x7f),
  46931 	1343: uint8(0x7f),
  46932 	1344: uint8(0x7f),
  46933 	1345: uint8(0x7f),
  46934 	1346: uint8(0x7f),
  46935 	1347: uint8(0x7f),
  46936 	1348: uint8(0x7f),
  46937 	1349: uint8(0x7f),
  46938 	1350: uint8(0x7f),
  46939 	1351: uint8(0x7f),
  46940 	1352: uint8(0x7f),
  46941 	1353: uint8(0x7f),
  46942 	1354: uint8(0x7f),
  46943 	1355: uint8(0x7f),
  46944 	1356: uint8(0x7f),
  46945 	1357: uint8(0x7f),
  46946 	1358: uint8(0x7f),
  46947 	1359: uint8(0x7f),
  46948 	1360: uint8(0x7f),
  46949 	1361: uint8(0x7f),
  46950 	1362: uint8(0x7f),
  46951 	1363: uint8(0x7f),
  46952 	1364: uint8(0x7f),
  46953 	1365: uint8(0x7f),
  46954 	1366: uint8(0x7f),
  46955 	1367: uint8(0x7f),
  46956 	1368: uint8(0x7f),
  46957 	1369: uint8(0x7f),
  46958 	1370: uint8(0x7f),
  46959 	1371: uint8(0x7f),
  46960 	1372: uint8(0x7f),
  46961 	1373: uint8(0x7f),
  46962 	1374: uint8(0x7f),
  46963 	1375: uint8(0x7f),
  46964 	1376: uint8(0x7f),
  46965 	1377: uint8(0x7f),
  46966 	1378: uint8(0x7f),
  46967 	1379: uint8(0x7f),
  46968 	1380: uint8(0x7f),
  46969 	1381: uint8(0x7f),
  46970 	1382: uint8(0x7f),
  46971 	1383: uint8(0x7f),
  46972 	1384: uint8(0x7f),
  46973 	1385: uint8(0x7f),
  46974 	1386: uint8(0x7f),
  46975 	1387: uint8(0x7f),
  46976 	1388: uint8(0x7f),
  46977 	1389: uint8(0x7f),
  46978 	1390: uint8(0x7f),
  46979 	1391: uint8(0x7f),
  46980 	1392: uint8(0x7f),
  46981 	1393: uint8(0x7f),
  46982 	1394: uint8(0x7f),
  46983 	1395: uint8(0x7f),
  46984 	1396: uint8(0x7f),
  46985 	1397: uint8(0x7f),
  46986 	1398: uint8(0x7f),
  46987 	1399: uint8(0x7f),
  46988 	1400: uint8(0x7f),
  46989 	1401: uint8(0x7f),
  46990 	1402: uint8(0x7f),
  46991 	1403: uint8(0x7f),
  46992 	1404: uint8(0x7f),
  46993 	1405: uint8(0x7f),
  46994 	1406: uint8(0x7f),
  46995 	1407: uint8(0x7f),
  46996 	1408: uint8(0x7f),
  46997 	1409: uint8(0x7f),
  46998 	1410: uint8(0x7f),
  46999 	1411: uint8(0x7f),
  47000 	1412: uint8(0x7f),
  47001 	1413: uint8(0x7f),
  47002 	1414: uint8(0x7f),
  47003 	1415: uint8(0x7f),
  47004 	1416: uint8(0x7f),
  47005 	1417: uint8(0x7f),
  47006 	1418: uint8(0x7f),
  47007 	1419: uint8(0x7f),
  47008 	1420: uint8(0x7f),
  47009 	1421: uint8(0x7f),
  47010 	1422: uint8(0x7f),
  47011 	1423: uint8(0x7f),
  47012 	1424: uint8(0x7f),
  47013 	1425: uint8(0x7f),
  47014 	1426: uint8(0x7f),
  47015 	1427: uint8(0x7f),
  47016 	1428: uint8(0x7f),
  47017 	1429: uint8(0x7f),
  47018 	1430: uint8(0x7f),
  47019 	1431: uint8(0x7f),
  47020 	1432: uint8(0x7f),
  47021 	1433: uint8(0x7f),
  47022 	1434: uint8(0x7f),
  47023 	1435: uint8(0x7f),
  47024 	1436: uint8(0x7f),
  47025 	1437: uint8(0x7f),
  47026 	1438: uint8(0x7f),
  47027 	1439: uint8(0x7f),
  47028 	1440: uint8(0x7f),
  47029 	1441: uint8(0x7f),
  47030 	1442: uint8(0x7f),
  47031 	1443: uint8(0x7f),
  47032 	1444: uint8(0x7f),
  47033 	1445: uint8(0x7f),
  47034 	1446: uint8(0x7f),
  47035 	1447: uint8(0x7f),
  47036 	1448: uint8(0x7f),
  47037 	1449: uint8(0x7f),
  47038 	1450: uint8(0x7f),
  47039 	1451: uint8(0x7f),
  47040 	1452: uint8(0x7f),
  47041 	1453: uint8(0x7f),
  47042 	1454: uint8(0x7f),
  47043 	1455: uint8(0x7f),
  47044 	1456: uint8(0x7f),
  47045 	1457: uint8(0x7f),
  47046 	1458: uint8(0x7f),
  47047 	1459: uint8(0x7f),
  47048 	1460: uint8(0x7f),
  47049 	1461: uint8(0x7f),
  47050 	1462: uint8(0x7f),
  47051 	1463: uint8(0x7f),
  47052 	1464: uint8(0x7f),
  47053 	1465: uint8(0x7f),
  47054 	1466: uint8(0x7f),
  47055 	1467: uint8(0x7f),
  47056 	1468: uint8(0x7f),
  47057 	1469: uint8(0x7f),
  47058 	1470: uint8(0x7f),
  47059 	1471: uint8(0x7f),
  47060 	1472: uint8(0x7f),
  47061 	1473: uint8(0x7f),
  47062 	1474: uint8(0x7f),
  47063 	1475: uint8(0x7f),
  47064 	1476: uint8(0x7f),
  47065 	1477: uint8(0x7f),
  47066 	1478: uint8(0x7f),
  47067 	1479: uint8(0x7f),
  47068 	1480: uint8(0x7f),
  47069 	1481: uint8(0x7f),
  47070 	1482: uint8(0x7f),
  47071 	1483: uint8(0x7f),
  47072 	1484: uint8(0x7f),
  47073 	1485: uint8(0x7f),
  47074 	1486: uint8(0x7f),
  47075 	1487: uint8(0x7f),
  47076 	1488: uint8(0x7f),
  47077 	1489: uint8(0x7f),
  47078 	1490: uint8(0x7f),
  47079 	1491: uint8(0x7f),
  47080 	1492: uint8(0x7f),
  47081 	1493: uint8(0x7f),
  47082 	1494: uint8(0x7f),
  47083 	1495: uint8(0x7f),
  47084 	1496: uint8(0x7f),
  47085 	1497: uint8(0x7f),
  47086 	1498: uint8(0x7f),
  47087 	1499: uint8(0x7f),
  47088 	1500: uint8(0x7f),
  47089 	1501: uint8(0x7f),
  47090 	1502: uint8(0x7f),
  47091 	1503: uint8(0x7f),
  47092 	1504: uint8(0x7f),
  47093 	1505: uint8(0x7f),
  47094 	1506: uint8(0x7f),
  47095 	1507: uint8(0x7f),
  47096 	1508: uint8(0x7f),
  47097 	1509: uint8(0x7f),
  47098 	1510: uint8(0x7f),
  47099 	1511: uint8(0x7f),
  47100 	1512: uint8(0x7f),
  47101 	1513: uint8(0x7f),
  47102 	1514: uint8(0x7f),
  47103 	1515: uint8(0x7f),
  47104 	1516: uint8(0x7f),
  47105 	1517: uint8(0x7f),
  47106 	1518: uint8(0x7f),
  47107 	1519: uint8(0x7f),
  47108 	1520: uint8(0x7f),
  47109 	1521: uint8(0x7f),
  47110 	1522: uint8(0x7f),
  47111 	1523: uint8(0x7f),
  47112 	1524: uint8(0x7f),
  47113 	1525: uint8(0x7f),
  47114 	1526: uint8(0x7f),
  47115 	1527: uint8(0x7f),
  47116 	1528: uint8(0x7f),
  47117 	1529: uint8(0x7f),
  47118 	1530: uint8(0x7f),
  47119 	1531: uint8(0x7f),
  47120 	1532: uint8(0x7f),
  47121 	1533: uint8(0x7f),
  47122 	1534: uint8(0x7f),
  47123 	1535: uint8(0x7f),
  47124 	1536: uint8(0x7f),
  47125 	1537: uint8(0x7f),
  47126 	1538: uint8(0x7f),
  47127 	1539: uint8(0x7f),
  47128 	1540: uint8(0x7f),
  47129 	1541: uint8(0x7f),
  47130 	1542: uint8(0x7f),
  47131 	1543: uint8(0x7f),
  47132 	1544: uint8(0x7f),
  47133 	1545: uint8(0x7f),
  47134 	1546: uint8(0x7f),
  47135 	1547: uint8(0x7f),
  47136 	1548: uint8(0x7f),
  47137 	1549: uint8(0x7f),
  47138 	1550: uint8(0x7f),
  47139 	1551: uint8(0x7f),
  47140 	1552: uint8(0x7f),
  47141 	1553: uint8(0x7f),
  47142 	1554: uint8(0x7f),
  47143 	1555: uint8(0x7f),
  47144 	1556: uint8(0x7f),
  47145 	1557: uint8(0x7f),
  47146 	1558: uint8(0x7f),
  47147 	1559: uint8(0x7f),
  47148 	1560: uint8(0x7f),
  47149 	1561: uint8(0x7f),
  47150 	1562: uint8(0x7f),
  47151 	1563: uint8(0x7f),
  47152 	1564: uint8(0x7f),
  47153 	1565: uint8(0x7f),
  47154 	1566: uint8(0x7f),
  47155 	1567: uint8(0x7f),
  47156 	1568: uint8(0x7f),
  47157 	1569: uint8(0x7f),
  47158 	1570: uint8(0x7f),
  47159 	1571: uint8(0x7f),
  47160 	1572: uint8(0x7f),
  47161 	1573: uint8(0x7f),
  47162 	1574: uint8(0x7f),
  47163 	1575: uint8(0x7f),
  47164 	1576: uint8(0x7f),
  47165 	1577: uint8(0x7f),
  47166 	1578: uint8(0x7f),
  47167 	1579: uint8(0x7f),
  47168 	1580: uint8(0x7f),
  47169 	1581: uint8(0x7f),
  47170 	1582: uint8(0x7f),
  47171 	1583: uint8(0x7f),
  47172 	1584: uint8(0x7f),
  47173 	1585: uint8(0x7f),
  47174 	1586: uint8(0x7f),
  47175 	1587: uint8(0x7f),
  47176 	1588: uint8(0x7f),
  47177 	1589: uint8(0x7f),
  47178 	1590: uint8(0x7f),
  47179 	1591: uint8(0x7f),
  47180 	1592: uint8(0x7f),
  47181 	1593: uint8(0x7f),
  47182 	1594: uint8(0x7f),
  47183 	1595: uint8(0x7f),
  47184 	1596: uint8(0x7f),
  47185 	1597: uint8(0x7f),
  47186 	1598: uint8(0x7f),
  47187 	1599: uint8(0x7f),
  47188 	1600: uint8(0x7f),
  47189 	1601: uint8(0x7f),
  47190 	1602: uint8(0x7f),
  47191 	1603: uint8(0x7f),
  47192 	1604: uint8(0x7f),
  47193 	1605: uint8(0x7f),
  47194 	1606: uint8(0x7f),
  47195 	1607: uint8(0x7f),
  47196 	1608: uint8(0x7f),
  47197 	1609: uint8(0x7f),
  47198 	1610: uint8(0x7f),
  47199 	1611: uint8(0x7f),
  47200 	1612: uint8(0x7f),
  47201 	1613: uint8(0x7f),
  47202 	1614: uint8(0x7f),
  47203 	1615: uint8(0x7f),
  47204 	1616: uint8(0x7f),
  47205 	1617: uint8(0x7f),
  47206 	1618: uint8(0x7f),
  47207 	1619: uint8(0x7f),
  47208 	1620: uint8(0x7f),
  47209 	1621: uint8(0x7f),
  47210 	1622: uint8(0x7f),
  47211 	1623: uint8(0x7f),
  47212 	1624: uint8(0x7f),
  47213 	1625: uint8(0x7f),
  47214 	1626: uint8(0x7f),
  47215 	1627: uint8(0x7f),
  47216 	1628: uint8(0x7f),
  47217 	1629: uint8(0x7f),
  47218 	1630: uint8(0x7f),
  47219 	1631: uint8(0x7f),
  47220 	1632: uint8(0x7f),
  47221 	1633: uint8(0x7f),
  47222 	1634: uint8(0x7f),
  47223 	1635: uint8(0x7f),
  47224 	1636: uint8(0x7f),
  47225 	1637: uint8(0x7f),
  47226 	1638: uint8(0x7f),
  47227 	1639: uint8(0x7f),
  47228 	1640: uint8(0x7f),
  47229 	1641: uint8(0x7f),
  47230 	1642: uint8(0x7f),
  47231 	1643: uint8(0x7f),
  47232 	1644: uint8(0x7f),
  47233 	1645: uint8(0x7f),
  47234 	1646: uint8(0x7f),
  47235 	1647: uint8(0x7f),
  47236 	1648: uint8(0x7f),
  47237 	1649: uint8(0x7f),
  47238 	1650: uint8(0x7f),
  47239 	1651: uint8(0x7f),
  47240 	1652: uint8(0x7f),
  47241 	1653: uint8(0x7f),
  47242 	1654: uint8(0x7f),
  47243 	1655: uint8(0x7f),
  47244 	1656: uint8(0x7f),
  47245 	1657: uint8(0x7f),
  47246 	1658: uint8(0x7f),
  47247 	1659: uint8(0x7f),
  47248 	1660: uint8(0x7f),
  47249 	1661: uint8(0x7f),
  47250 	1662: uint8(0x7f),
  47251 	1663: uint8(0x7f),
  47252 	1664: uint8(0x7f),
  47253 	1665: uint8(0x7f),
  47254 	1666: uint8(0x7f),
  47255 	1667: uint8(0x7f),
  47256 	1668: uint8(0x7f),
  47257 	1669: uint8(0x7f),
  47258 	1670: uint8(0x7f),
  47259 	1671: uint8(0x7f),
  47260 	1672: uint8(0x7f),
  47261 	1673: uint8(0x7f),
  47262 	1674: uint8(0x7f),
  47263 	1675: uint8(0x7f),
  47264 	1676: uint8(0x7f),
  47265 	1677: uint8(0x7f),
  47266 	1678: uint8(0x7f),
  47267 	1679: uint8(0x7f),
  47268 	1680: uint8(0x7f),
  47269 	1681: uint8(0x7f),
  47270 	1682: uint8(0x7f),
  47271 	1683: uint8(0x7f),
  47272 	1684: uint8(0x7f),
  47273 	1685: uint8(0x7f),
  47274 	1686: uint8(0x7f),
  47275 	1687: uint8(0x7f),
  47276 	1688: uint8(0x7f),
  47277 	1689: uint8(0x7f),
  47278 	1690: uint8(0x7f),
  47279 	1691: uint8(0x7f),
  47280 	1692: uint8(0x7f),
  47281 	1693: uint8(0x7f),
  47282 	1694: uint8(0x7f),
  47283 	1695: uint8(0x7f),
  47284 	1696: uint8(0x7f),
  47285 	1697: uint8(0x7f),
  47286 	1698: uint8(0x7f),
  47287 	1699: uint8(0x7f),
  47288 	1700: uint8(0x7f),
  47289 	1701: uint8(0x7f),
  47290 	1702: uint8(0x7f),
  47291 	1703: uint8(0x7f),
  47292 	1704: uint8(0x7f),
  47293 	1705: uint8(0x7f),
  47294 	1706: uint8(0x7f),
  47295 	1707: uint8(0x7f),
  47296 	1708: uint8(0x7f),
  47297 	1709: uint8(0x7f),
  47298 	1710: uint8(0x7f),
  47299 	1711: uint8(0x7f),
  47300 	1712: uint8(0x7f),
  47301 	1713: uint8(0x7f),
  47302 	1714: uint8(0x7f),
  47303 	1715: uint8(0x7f),
  47304 	1716: uint8(0x7f),
  47305 	1717: uint8(0x7f),
  47306 	1718: uint8(0x7f),
  47307 	1719: uint8(0x7f),
  47308 	1720: uint8(0x7f),
  47309 	1721: uint8(0x7f),
  47310 	1722: uint8(0x7f),
  47311 	1723: uint8(0x7f),
  47312 	1724: uint8(0x7f),
  47313 	1725: uint8(0x7f),
  47314 	1726: uint8(0x7f),
  47315 	1727: uint8(0x7f),
  47316 	1728: uint8(0x7f),
  47317 	1729: uint8(0x7f),
  47318 	1730: uint8(0x7f),
  47319 	1731: uint8(0x7f),
  47320 	1732: uint8(0x7f),
  47321 	1733: uint8(0x7f),
  47322 	1734: uint8(0x7f),
  47323 	1735: uint8(0x7f),
  47324 	1736: uint8(0x7f),
  47325 	1737: uint8(0x7f),
  47326 	1738: uint8(0x7f),
  47327 	1739: uint8(0x7f),
  47328 	1740: uint8(0x7f),
  47329 	1741: uint8(0x7f),
  47330 	1742: uint8(0x7f),
  47331 	1743: uint8(0x7f),
  47332 	1744: uint8(0x7f),
  47333 	1745: uint8(0x7f),
  47334 	1746: uint8(0x7f),
  47335 	1747: uint8(0x7f),
  47336 	1748: uint8(0x7f),
  47337 	1749: uint8(0x7f),
  47338 	1750: uint8(0x7f),
  47339 	1751: uint8(0x7f),
  47340 	1752: uint8(0x7f),
  47341 	1753: uint8(0x7f),
  47342 	1754: uint8(0x7f),
  47343 	1755: uint8(0x7f),
  47344 	1756: uint8(0x7f),
  47345 	1757: uint8(0x7f),
  47346 	1758: uint8(0x7f),
  47347 	1759: uint8(0x7f),
  47348 	1760: uint8(0x7f),
  47349 	1761: uint8(0x7f),
  47350 	1762: uint8(0x7f),
  47351 	1763: uint8(0x7f),
  47352 	1764: uint8(0x7f),
  47353 	1765: uint8(0x7f),
  47354 	1766: uint8(0x7f),
  47355 	1767: uint8(0x7f),
  47356 	1768: uint8(0x7f),
  47357 	1769: uint8(0x7f),
  47358 	1770: uint8(0x7f),
  47359 	1771: uint8(0x7f),
  47360 	1772: uint8(0x7f),
  47361 	1773: uint8(0x7f),
  47362 	1774: uint8(0x7f),
  47363 	1775: uint8(0x7f),
  47364 	1776: uint8(0x7f),
  47365 	1777: uint8(0x7f),
  47366 	1778: uint8(0x7f),
  47367 	1779: uint8(0x7f),
  47368 	1780: uint8(0x7f),
  47369 	1781: uint8(0x7f),
  47370 	1782: uint8(0x7f),
  47371 	1783: uint8(0x7f),
  47372 	1784: uint8(0x7f),
  47373 	1785: uint8(0x7f),
  47374 	1786: uint8(0x7f),
  47375 	1787: uint8(0x7f),
  47376 	1788: uint8(0x7f),
  47377 	1789: uint8(0x7f),
  47378 	1790: uint8(0x7f),
  47379 	1791: uint8(0x7f),
  47380 	1792: uint8(0x7f),
  47381 	1793: uint8(0x7f),
  47382 	1794: uint8(0x7f),
  47383 	1795: uint8(0x7f),
  47384 	1796: uint8(0x7f),
  47385 	1797: uint8(0x7f),
  47386 	1798: uint8(0x7f),
  47387 	1799: uint8(0x7f),
  47388 	1800: uint8(0x7f),
  47389 	1801: uint8(0x7f),
  47390 	1802: uint8(0x7f),
  47391 	1803: uint8(0x7f),
  47392 	1804: uint8(0x7f),
  47393 	1805: uint8(0x7f),
  47394 	1806: uint8(0x7f),
  47395 	1807: uint8(0x7f),
  47396 	1808: uint8(0x7f),
  47397 	1809: uint8(0x7f),
  47398 	1810: uint8(0x7f),
  47399 	1811: uint8(0x7f),
  47400 	1812: uint8(0x7f),
  47401 	1813: uint8(0x7f),
  47402 	1814: uint8(0x7f),
  47403 	1815: uint8(0x7f),
  47404 	1816: uint8(0x7f),
  47405 	1817: uint8(0x7f),
  47406 	1818: uint8(0x7f),
  47407 	1819: uint8(0x7f),
  47408 	1820: uint8(0x7f),
  47409 	1821: uint8(0x7f),
  47410 	1822: uint8(0x7f),
  47411 	1823: uint8(0x7f),
  47412 	1824: uint8(0x7f),
  47413 	1825: uint8(0x7f),
  47414 	1826: uint8(0x7f),
  47415 	1827: uint8(0x7f),
  47416 	1828: uint8(0x7f),
  47417 	1829: uint8(0x7f),
  47418 	1830: uint8(0x7f),
  47419 	1831: uint8(0x7f),
  47420 	1832: uint8(0x7f),
  47421 	1833: uint8(0x7f),
  47422 	1834: uint8(0x7f),
  47423 	1835: uint8(0x7f),
  47424 	1836: uint8(0x7f),
  47425 	1837: uint8(0x7f),
  47426 	1838: uint8(0x7f),
  47427 	1839: uint8(0x7f),
  47428 	1840: uint8(0x7f),
  47429 	1841: uint8(0x7f),
  47430 	1842: uint8(0x7f),
  47431 	1843: uint8(0x7f),
  47432 	1844: uint8(0x7f),
  47433 	1845: uint8(0x7f),
  47434 	1846: uint8(0x7f),
  47435 	1847: uint8(0x7f),
  47436 	1848: uint8(0x7f),
  47437 	1849: uint8(0x7f),
  47438 	1850: uint8(0x7f),
  47439 	1851: uint8(0x7f),
  47440 	1852: uint8(0x7f),
  47441 	1853: uint8(0x7f),
  47442 	1854: uint8(0x7f),
  47443 	1855: uint8(0x7f),
  47444 	1856: uint8(0x7f),
  47445 	1857: uint8(0x7f),
  47446 	1858: uint8(0x7f),
  47447 	1859: uint8(0x7f),
  47448 	1860: uint8(0x7f),
  47449 	1861: uint8(0x7f),
  47450 	1862: uint8(0x7f),
  47451 	1863: uint8(0x7f),
  47452 	1864: uint8(0x7f),
  47453 	1865: uint8(0x7f),
  47454 	1866: uint8(0x7f),
  47455 	1867: uint8(0x7f),
  47456 	1868: uint8(0x7f),
  47457 	1869: uint8(0x7f),
  47458 	1870: uint8(0x7f),
  47459 	1871: uint8(0x7f),
  47460 	1872: uint8(0x7f),
  47461 	1873: uint8(0x7f),
  47462 	1874: uint8(0x7f),
  47463 	1875: uint8(0x7f),
  47464 	1876: uint8(0x7f),
  47465 	1877: uint8(0x7f),
  47466 	1878: uint8(0x7f),
  47467 	1879: uint8(0x7f),
  47468 	1880: uint8(0x7f),
  47469 	1881: uint8(0x7f),
  47470 	1882: uint8(0x7f),
  47471 	1883: uint8(0x7f),
  47472 	1884: uint8(0x7f),
  47473 	1885: uint8(0x7f),
  47474 	1886: uint8(0x7f),
  47475 	1887: uint8(0x7f),
  47476 	1888: uint8(0x7f),
  47477 	1889: uint8(0x7f),
  47478 	1890: uint8(0x7f),
  47479 	1891: uint8(0x7f),
  47480 	1892: uint8(0x7f),
  47481 	1893: uint8(0x7f),
  47482 	1894: uint8(0x7f),
  47483 	1895: uint8(0x7f),
  47484 	1896: uint8(0x7f),
  47485 	1897: uint8(0x7f),
  47486 	1898: uint8(0x7f),
  47487 	1899: uint8(0x7f),
  47488 	1900: uint8(0x7f),
  47489 	1901: uint8(0x7f),
  47490 	1902: uint8(0x7f),
  47491 	1903: uint8(0x7f),
  47492 	1904: uint8(0x7f),
  47493 	1905: uint8(0x7f),
  47494 	1906: uint8(0x7f),
  47495 	1907: uint8(0x7f),
  47496 	1908: uint8(0x7f),
  47497 	1909: uint8(0x7f),
  47498 	1910: uint8(0x7f),
  47499 	1911: uint8(0x7f),
  47500 	1912: uint8(0x7f),
  47501 	1913: uint8(0x7f),
  47502 	1914: uint8(0x7f),
  47503 	1915: uint8(0x7f),
  47504 	1916: uint8(0x7f),
  47505 	1917: uint8(0x7f),
  47506 	1918: uint8(0x7f),
  47507 	1919: uint8(0x7f),
  47508 	1920: uint8(0x7f),
  47509 	1921: uint8(0x7f),
  47510 	1922: uint8(0x7f),
  47511 	1923: uint8(0x7f),
  47512 	1924: uint8(0x7f),
  47513 	1925: uint8(0x7f),
  47514 	1926: uint8(0x7f),
  47515 	1927: uint8(0x7f),
  47516 	1928: uint8(0x7f),
  47517 	1929: uint8(0x7f),
  47518 	1930: uint8(0x7f),
  47519 	1931: uint8(0x7f),
  47520 	1932: uint8(0x7f),
  47521 	1933: uint8(0x7f),
  47522 	1934: uint8(0x7f),
  47523 	1935: uint8(0x7f),
  47524 	1936: uint8(0x7f),
  47525 	1937: uint8(0x7f),
  47526 	1938: uint8(0x7f),
  47527 	1939: uint8(0x7f),
  47528 	1940: uint8(0x7f),
  47529 	1941: uint8(0x7f),
  47530 	1942: uint8(0x7f),
  47531 	1943: uint8(0x7f),
  47532 	1944: uint8(0x7f),
  47533 	1945: uint8(0x7f),
  47534 	1946: uint8(0x7f),
  47535 	1947: uint8(0x7f),
  47536 	1948: uint8(0x7f),
  47537 	1949: uint8(0x7f),
  47538 	1950: uint8(0x7f),
  47539 	1951: uint8(0x7f),
  47540 	1952: uint8(0x7f),
  47541 	1953: uint8(0x7f),
  47542 	1954: uint8(0x7f),
  47543 	1955: uint8(0x7f),
  47544 	1956: uint8(0x7f),
  47545 	1957: uint8(0x7f),
  47546 	1958: uint8(0x7f),
  47547 	1959: uint8(0x7f),
  47548 	1960: uint8(0x7f),
  47549 	1961: uint8(0x7f),
  47550 	1962: uint8(0x7f),
  47551 	1963: uint8(0x7f),
  47552 	1964: uint8(0x7f),
  47553 	1965: uint8(0x7f),
  47554 	1966: uint8(0x7f),
  47555 	1967: uint8(0x7f),
  47556 	1968: uint8(0x7f),
  47557 	1969: uint8(0x7f),
  47558 	1970: uint8(0x7f),
  47559 	1971: uint8(0x7f),
  47560 	1972: uint8(0x7f),
  47561 	1973: uint8(0x7f),
  47562 	1974: uint8(0x7f),
  47563 	1975: uint8(0x7f),
  47564 	1976: uint8(0x7f),
  47565 	1977: uint8(0x7f),
  47566 	1978: uint8(0x7f),
  47567 	1979: uint8(0x7f),
  47568 	1980: uint8(0x7f),
  47569 	1981: uint8(0x7f),
  47570 	1982: uint8(0x7f),
  47571 	1983: uint8(0x7f),
  47572 	1984: uint8(0x7f),
  47573 	1985: uint8(0x7f),
  47574 	1986: uint8(0x7f),
  47575 	1987: uint8(0x7f),
  47576 	1988: uint8(0x7f),
  47577 	1989: uint8(0x7f),
  47578 	1990: uint8(0x7f),
  47579 	1991: uint8(0x7f),
  47580 	1992: uint8(0x7f),
  47581 	1993: uint8(0x7f),
  47582 	1994: uint8(0x7f),
  47583 	1995: uint8(0x7f),
  47584 	1996: uint8(0x7f),
  47585 	1997: uint8(0x7f),
  47586 	1998: uint8(0x7f),
  47587 	1999: uint8(0x7f),
  47588 	2000: uint8(0x7f),
  47589 	2001: uint8(0x7f),
  47590 	2002: uint8(0x7f),
  47591 	2003: uint8(0x7f),
  47592 	2004: uint8(0x7f),
  47593 	2005: uint8(0x7f),
  47594 	2006: uint8(0x7f),
  47595 	2007: uint8(0x7f),
  47596 	2008: uint8(0x7f),
  47597 	2009: uint8(0x7f),
  47598 	2010: uint8(0x7f),
  47599 	2011: uint8(0x7f),
  47600 	2012: uint8(0x7f),
  47601 	2013: uint8(0x7f),
  47602 	2014: uint8(0x7f),
  47603 	2015: uint8(0x7f),
  47604 	2016: uint8(0x7f),
  47605 	2017: uint8(0x7f),
  47606 	2018: uint8(0x7f),
  47607 	2019: uint8(0x7f),
  47608 	2020: uint8(0x7f),
  47609 	2021: uint8(0x7f),
  47610 	2022: uint8(0x7f),
  47611 	2023: uint8(0x7f),
  47612 	2024: uint8(0x7f),
  47613 	2025: uint8(0x7f),
  47614 	2026: uint8(0x7f),
  47615 	2027: uint8(0x7f),
  47616 	2028: uint8(0x7f),
  47617 	2029: uint8(0x7f),
  47618 	2030: uint8(0x7f),
  47619 	2031: uint8(0x7f),
  47620 	2032: uint8(0x7f),
  47621 	2033: uint8(0x7f),
  47622 	2034: uint8(0x7f),
  47623 	2035: uint8(0x7f),
  47624 	2036: uint8(0x7f),
  47625 	2037: uint8(0x7f),
  47626 	2038: uint8(0x7f),
  47627 	2039: uint8(0x7f),
  47628 }
  47629 
  47630 var sclip2 = [225]uint8_t{
  47631 	0:   uint8(0xf0),
  47632 	1:   uint8(0xf0),
  47633 	2:   uint8(0xf0),
  47634 	3:   uint8(0xf0),
  47635 	4:   uint8(0xf0),
  47636 	5:   uint8(0xf0),
  47637 	6:   uint8(0xf0),
  47638 	7:   uint8(0xf0),
  47639 	8:   uint8(0xf0),
  47640 	9:   uint8(0xf0),
  47641 	10:  uint8(0xf0),
  47642 	11:  uint8(0xf0),
  47643 	12:  uint8(0xf0),
  47644 	13:  uint8(0xf0),
  47645 	14:  uint8(0xf0),
  47646 	15:  uint8(0xf0),
  47647 	16:  uint8(0xf0),
  47648 	17:  uint8(0xf0),
  47649 	18:  uint8(0xf0),
  47650 	19:  uint8(0xf0),
  47651 	20:  uint8(0xf0),
  47652 	21:  uint8(0xf0),
  47653 	22:  uint8(0xf0),
  47654 	23:  uint8(0xf0),
  47655 	24:  uint8(0xf0),
  47656 	25:  uint8(0xf0),
  47657 	26:  uint8(0xf0),
  47658 	27:  uint8(0xf0),
  47659 	28:  uint8(0xf0),
  47660 	29:  uint8(0xf0),
  47661 	30:  uint8(0xf0),
  47662 	31:  uint8(0xf0),
  47663 	32:  uint8(0xf0),
  47664 	33:  uint8(0xf0),
  47665 	34:  uint8(0xf0),
  47666 	35:  uint8(0xf0),
  47667 	36:  uint8(0xf0),
  47668 	37:  uint8(0xf0),
  47669 	38:  uint8(0xf0),
  47670 	39:  uint8(0xf0),
  47671 	40:  uint8(0xf0),
  47672 	41:  uint8(0xf0),
  47673 	42:  uint8(0xf0),
  47674 	43:  uint8(0xf0),
  47675 	44:  uint8(0xf0),
  47676 	45:  uint8(0xf0),
  47677 	46:  uint8(0xf0),
  47678 	47:  uint8(0xf0),
  47679 	48:  uint8(0xf0),
  47680 	49:  uint8(0xf0),
  47681 	50:  uint8(0xf0),
  47682 	51:  uint8(0xf0),
  47683 	52:  uint8(0xf0),
  47684 	53:  uint8(0xf0),
  47685 	54:  uint8(0xf0),
  47686 	55:  uint8(0xf0),
  47687 	56:  uint8(0xf0),
  47688 	57:  uint8(0xf0),
  47689 	58:  uint8(0xf0),
  47690 	59:  uint8(0xf0),
  47691 	60:  uint8(0xf0),
  47692 	61:  uint8(0xf0),
  47693 	62:  uint8(0xf0),
  47694 	63:  uint8(0xf0),
  47695 	64:  uint8(0xf0),
  47696 	65:  uint8(0xf0),
  47697 	66:  uint8(0xf0),
  47698 	67:  uint8(0xf0),
  47699 	68:  uint8(0xf0),
  47700 	69:  uint8(0xf0),
  47701 	70:  uint8(0xf0),
  47702 	71:  uint8(0xf0),
  47703 	72:  uint8(0xf0),
  47704 	73:  uint8(0xf0),
  47705 	74:  uint8(0xf0),
  47706 	75:  uint8(0xf0),
  47707 	76:  uint8(0xf0),
  47708 	77:  uint8(0xf0),
  47709 	78:  uint8(0xf0),
  47710 	79:  uint8(0xf0),
  47711 	80:  uint8(0xf0),
  47712 	81:  uint8(0xf0),
  47713 	82:  uint8(0xf0),
  47714 	83:  uint8(0xf0),
  47715 	84:  uint8(0xf0),
  47716 	85:  uint8(0xf0),
  47717 	86:  uint8(0xf0),
  47718 	87:  uint8(0xf0),
  47719 	88:  uint8(0xf0),
  47720 	89:  uint8(0xf0),
  47721 	90:  uint8(0xf0),
  47722 	91:  uint8(0xf0),
  47723 	92:  uint8(0xf0),
  47724 	93:  uint8(0xf0),
  47725 	94:  uint8(0xf0),
  47726 	95:  uint8(0xf0),
  47727 	96:  uint8(0xf0),
  47728 	97:  uint8(0xf1),
  47729 	98:  uint8(0xf2),
  47730 	99:  uint8(0xf3),
  47731 	100: uint8(0xf4),
  47732 	101: uint8(0xf5),
  47733 	102: uint8(0xf6),
  47734 	103: uint8(0xf7),
  47735 	104: uint8(0xf8),
  47736 	105: uint8(0xf9),
  47737 	106: uint8(0xfa),
  47738 	107: uint8(0xfb),
  47739 	108: uint8(0xfc),
  47740 	109: uint8(0xfd),
  47741 	110: uint8(0xfe),
  47742 	111: uint8(0xff),
  47743 	113: uint8(0x01),
  47744 	114: uint8(0x02),
  47745 	115: uint8(0x03),
  47746 	116: uint8(0x04),
  47747 	117: uint8(0x05),
  47748 	118: uint8(0x06),
  47749 	119: uint8(0x07),
  47750 	120: uint8(0x08),
  47751 	121: uint8(0x09),
  47752 	122: uint8(0x0a),
  47753 	123: uint8(0x0b),
  47754 	124: uint8(0x0c),
  47755 	125: uint8(0x0d),
  47756 	126: uint8(0x0e),
  47757 	127: uint8(0x0f),
  47758 	128: uint8(0x0f),
  47759 	129: uint8(0x0f),
  47760 	130: uint8(0x0f),
  47761 	131: uint8(0x0f),
  47762 	132: uint8(0x0f),
  47763 	133: uint8(0x0f),
  47764 	134: uint8(0x0f),
  47765 	135: uint8(0x0f),
  47766 	136: uint8(0x0f),
  47767 	137: uint8(0x0f),
  47768 	138: uint8(0x0f),
  47769 	139: uint8(0x0f),
  47770 	140: uint8(0x0f),
  47771 	141: uint8(0x0f),
  47772 	142: uint8(0x0f),
  47773 	143: uint8(0x0f),
  47774 	144: uint8(0x0f),
  47775 	145: uint8(0x0f),
  47776 	146: uint8(0x0f),
  47777 	147: uint8(0x0f),
  47778 	148: uint8(0x0f),
  47779 	149: uint8(0x0f),
  47780 	150: uint8(0x0f),
  47781 	151: uint8(0x0f),
  47782 	152: uint8(0x0f),
  47783 	153: uint8(0x0f),
  47784 	154: uint8(0x0f),
  47785 	155: uint8(0x0f),
  47786 	156: uint8(0x0f),
  47787 	157: uint8(0x0f),
  47788 	158: uint8(0x0f),
  47789 	159: uint8(0x0f),
  47790 	160: uint8(0x0f),
  47791 	161: uint8(0x0f),
  47792 	162: uint8(0x0f),
  47793 	163: uint8(0x0f),
  47794 	164: uint8(0x0f),
  47795 	165: uint8(0x0f),
  47796 	166: uint8(0x0f),
  47797 	167: uint8(0x0f),
  47798 	168: uint8(0x0f),
  47799 	169: uint8(0x0f),
  47800 	170: uint8(0x0f),
  47801 	171: uint8(0x0f),
  47802 	172: uint8(0x0f),
  47803 	173: uint8(0x0f),
  47804 	174: uint8(0x0f),
  47805 	175: uint8(0x0f),
  47806 	176: uint8(0x0f),
  47807 	177: uint8(0x0f),
  47808 	178: uint8(0x0f),
  47809 	179: uint8(0x0f),
  47810 	180: uint8(0x0f),
  47811 	181: uint8(0x0f),
  47812 	182: uint8(0x0f),
  47813 	183: uint8(0x0f),
  47814 	184: uint8(0x0f),
  47815 	185: uint8(0x0f),
  47816 	186: uint8(0x0f),
  47817 	187: uint8(0x0f),
  47818 	188: uint8(0x0f),
  47819 	189: uint8(0x0f),
  47820 	190: uint8(0x0f),
  47821 	191: uint8(0x0f),
  47822 	192: uint8(0x0f),
  47823 	193: uint8(0x0f),
  47824 	194: uint8(0x0f),
  47825 	195: uint8(0x0f),
  47826 	196: uint8(0x0f),
  47827 	197: uint8(0x0f),
  47828 	198: uint8(0x0f),
  47829 	199: uint8(0x0f),
  47830 	200: uint8(0x0f),
  47831 	201: uint8(0x0f),
  47832 	202: uint8(0x0f),
  47833 	203: uint8(0x0f),
  47834 	204: uint8(0x0f),
  47835 	205: uint8(0x0f),
  47836 	206: uint8(0x0f),
  47837 	207: uint8(0x0f),
  47838 	208: uint8(0x0f),
  47839 	209: uint8(0x0f),
  47840 	210: uint8(0x0f),
  47841 	211: uint8(0x0f),
  47842 	212: uint8(0x0f),
  47843 	213: uint8(0x0f),
  47844 	214: uint8(0x0f),
  47845 	215: uint8(0x0f),
  47846 	216: uint8(0x0f),
  47847 	217: uint8(0x0f),
  47848 	218: uint8(0x0f),
  47849 	219: uint8(0x0f),
  47850 	220: uint8(0x0f),
  47851 	221: uint8(0x0f),
  47852 	222: uint8(0x0f),
  47853 	223: uint8(0x0f),
  47854 }
  47855 
  47856 var clip11 = [767]uint8_t{
  47857 	256: uint8(0x01),
  47858 	257: uint8(0x02),
  47859 	258: uint8(0x03),
  47860 	259: uint8(0x04),
  47861 	260: uint8(0x05),
  47862 	261: uint8(0x06),
  47863 	262: uint8(0x07),
  47864 	263: uint8(0x08),
  47865 	264: uint8(0x09),
  47866 	265: uint8(0x0a),
  47867 	266: uint8(0x0b),
  47868 	267: uint8(0x0c),
  47869 	268: uint8(0x0d),
  47870 	269: uint8(0x0e),
  47871 	270: uint8(0x0f),
  47872 	271: uint8(0x10),
  47873 	272: uint8(0x11),
  47874 	273: uint8(0x12),
  47875 	274: uint8(0x13),
  47876 	275: uint8(0x14),
  47877 	276: uint8(0x15),
  47878 	277: uint8(0x16),
  47879 	278: uint8(0x17),
  47880 	279: uint8(0x18),
  47881 	280: uint8(0x19),
  47882 	281: uint8(0x1a),
  47883 	282: uint8(0x1b),
  47884 	283: uint8(0x1c),
  47885 	284: uint8(0x1d),
  47886 	285: uint8(0x1e),
  47887 	286: uint8(0x1f),
  47888 	287: uint8(0x20),
  47889 	288: uint8(0x21),
  47890 	289: uint8(0x22),
  47891 	290: uint8(0x23),
  47892 	291: uint8(0x24),
  47893 	292: uint8(0x25),
  47894 	293: uint8(0x26),
  47895 	294: uint8(0x27),
  47896 	295: uint8(0x28),
  47897 	296: uint8(0x29),
  47898 	297: uint8(0x2a),
  47899 	298: uint8(0x2b),
  47900 	299: uint8(0x2c),
  47901 	300: uint8(0x2d),
  47902 	301: uint8(0x2e),
  47903 	302: uint8(0x2f),
  47904 	303: uint8(0x30),
  47905 	304: uint8(0x31),
  47906 	305: uint8(0x32),
  47907 	306: uint8(0x33),
  47908 	307: uint8(0x34),
  47909 	308: uint8(0x35),
  47910 	309: uint8(0x36),
  47911 	310: uint8(0x37),
  47912 	311: uint8(0x38),
  47913 	312: uint8(0x39),
  47914 	313: uint8(0x3a),
  47915 	314: uint8(0x3b),
  47916 	315: uint8(0x3c),
  47917 	316: uint8(0x3d),
  47918 	317: uint8(0x3e),
  47919 	318: uint8(0x3f),
  47920 	319: uint8(0x40),
  47921 	320: uint8(0x41),
  47922 	321: uint8(0x42),
  47923 	322: uint8(0x43),
  47924 	323: uint8(0x44),
  47925 	324: uint8(0x45),
  47926 	325: uint8(0x46),
  47927 	326: uint8(0x47),
  47928 	327: uint8(0x48),
  47929 	328: uint8(0x49),
  47930 	329: uint8(0x4a),
  47931 	330: uint8(0x4b),
  47932 	331: uint8(0x4c),
  47933 	332: uint8(0x4d),
  47934 	333: uint8(0x4e),
  47935 	334: uint8(0x4f),
  47936 	335: uint8(0x50),
  47937 	336: uint8(0x51),
  47938 	337: uint8(0x52),
  47939 	338: uint8(0x53),
  47940 	339: uint8(0x54),
  47941 	340: uint8(0x55),
  47942 	341: uint8(0x56),
  47943 	342: uint8(0x57),
  47944 	343: uint8(0x58),
  47945 	344: uint8(0x59),
  47946 	345: uint8(0x5a),
  47947 	346: uint8(0x5b),
  47948 	347: uint8(0x5c),
  47949 	348: uint8(0x5d),
  47950 	349: uint8(0x5e),
  47951 	350: uint8(0x5f),
  47952 	351: uint8(0x60),
  47953 	352: uint8(0x61),
  47954 	353: uint8(0x62),
  47955 	354: uint8(0x63),
  47956 	355: uint8(0x64),
  47957 	356: uint8(0x65),
  47958 	357: uint8(0x66),
  47959 	358: uint8(0x67),
  47960 	359: uint8(0x68),
  47961 	360: uint8(0x69),
  47962 	361: uint8(0x6a),
  47963 	362: uint8(0x6b),
  47964 	363: uint8(0x6c),
  47965 	364: uint8(0x6d),
  47966 	365: uint8(0x6e),
  47967 	366: uint8(0x6f),
  47968 	367: uint8(0x70),
  47969 	368: uint8(0x71),
  47970 	369: uint8(0x72),
  47971 	370: uint8(0x73),
  47972 	371: uint8(0x74),
  47973 	372: uint8(0x75),
  47974 	373: uint8(0x76),
  47975 	374: uint8(0x77),
  47976 	375: uint8(0x78),
  47977 	376: uint8(0x79),
  47978 	377: uint8(0x7a),
  47979 	378: uint8(0x7b),
  47980 	379: uint8(0x7c),
  47981 	380: uint8(0x7d),
  47982 	381: uint8(0x7e),
  47983 	382: uint8(0x7f),
  47984 	383: uint8(0x80),
  47985 	384: uint8(0x81),
  47986 	385: uint8(0x82),
  47987 	386: uint8(0x83),
  47988 	387: uint8(0x84),
  47989 	388: uint8(0x85),
  47990 	389: uint8(0x86),
  47991 	390: uint8(0x87),
  47992 	391: uint8(0x88),
  47993 	392: uint8(0x89),
  47994 	393: uint8(0x8a),
  47995 	394: uint8(0x8b),
  47996 	395: uint8(0x8c),
  47997 	396: uint8(0x8d),
  47998 	397: uint8(0x8e),
  47999 	398: uint8(0x8f),
  48000 	399: uint8(0x90),
  48001 	400: uint8(0x91),
  48002 	401: uint8(0x92),
  48003 	402: uint8(0x93),
  48004 	403: uint8(0x94),
  48005 	404: uint8(0x95),
  48006 	405: uint8(0x96),
  48007 	406: uint8(0x97),
  48008 	407: uint8(0x98),
  48009 	408: uint8(0x99),
  48010 	409: uint8(0x9a),
  48011 	410: uint8(0x9b),
  48012 	411: uint8(0x9c),
  48013 	412: uint8(0x9d),
  48014 	413: uint8(0x9e),
  48015 	414: uint8(0x9f),
  48016 	415: uint8(0xa0),
  48017 	416: uint8(0xa1),
  48018 	417: uint8(0xa2),
  48019 	418: uint8(0xa3),
  48020 	419: uint8(0xa4),
  48021 	420: uint8(0xa5),
  48022 	421: uint8(0xa6),
  48023 	422: uint8(0xa7),
  48024 	423: uint8(0xa8),
  48025 	424: uint8(0xa9),
  48026 	425: uint8(0xaa),
  48027 	426: uint8(0xab),
  48028 	427: uint8(0xac),
  48029 	428: uint8(0xad),
  48030 	429: uint8(0xae),
  48031 	430: uint8(0xaf),
  48032 	431: uint8(0xb0),
  48033 	432: uint8(0xb1),
  48034 	433: uint8(0xb2),
  48035 	434: uint8(0xb3),
  48036 	435: uint8(0xb4),
  48037 	436: uint8(0xb5),
  48038 	437: uint8(0xb6),
  48039 	438: uint8(0xb7),
  48040 	439: uint8(0xb8),
  48041 	440: uint8(0xb9),
  48042 	441: uint8(0xba),
  48043 	442: uint8(0xbb),
  48044 	443: uint8(0xbc),
  48045 	444: uint8(0xbd),
  48046 	445: uint8(0xbe),
  48047 	446: uint8(0xbf),
  48048 	447: uint8(0xc0),
  48049 	448: uint8(0xc1),
  48050 	449: uint8(0xc2),
  48051 	450: uint8(0xc3),
  48052 	451: uint8(0xc4),
  48053 	452: uint8(0xc5),
  48054 	453: uint8(0xc6),
  48055 	454: uint8(0xc7),
  48056 	455: uint8(0xc8),
  48057 	456: uint8(0xc9),
  48058 	457: uint8(0xca),
  48059 	458: uint8(0xcb),
  48060 	459: uint8(0xcc),
  48061 	460: uint8(0xcd),
  48062 	461: uint8(0xce),
  48063 	462: uint8(0xcf),
  48064 	463: uint8(0xd0),
  48065 	464: uint8(0xd1),
  48066 	465: uint8(0xd2),
  48067 	466: uint8(0xd3),
  48068 	467: uint8(0xd4),
  48069 	468: uint8(0xd5),
  48070 	469: uint8(0xd6),
  48071 	470: uint8(0xd7),
  48072 	471: uint8(0xd8),
  48073 	472: uint8(0xd9),
  48074 	473: uint8(0xda),
  48075 	474: uint8(0xdb),
  48076 	475: uint8(0xdc),
  48077 	476: uint8(0xdd),
  48078 	477: uint8(0xde),
  48079 	478: uint8(0xdf),
  48080 	479: uint8(0xe0),
  48081 	480: uint8(0xe1),
  48082 	481: uint8(0xe2),
  48083 	482: uint8(0xe3),
  48084 	483: uint8(0xe4),
  48085 	484: uint8(0xe5),
  48086 	485: uint8(0xe6),
  48087 	486: uint8(0xe7),
  48088 	487: uint8(0xe8),
  48089 	488: uint8(0xe9),
  48090 	489: uint8(0xea),
  48091 	490: uint8(0xeb),
  48092 	491: uint8(0xec),
  48093 	492: uint8(0xed),
  48094 	493: uint8(0xee),
  48095 	494: uint8(0xef),
  48096 	495: uint8(0xf0),
  48097 	496: uint8(0xf1),
  48098 	497: uint8(0xf2),
  48099 	498: uint8(0xf3),
  48100 	499: uint8(0xf4),
  48101 	500: uint8(0xf5),
  48102 	501: uint8(0xf6),
  48103 	502: uint8(0xf7),
  48104 	503: uint8(0xf8),
  48105 	504: uint8(0xf9),
  48106 	505: uint8(0xfa),
  48107 	506: uint8(0xfb),
  48108 	507: uint8(0xfc),
  48109 	508: uint8(0xfd),
  48110 	509: uint8(0xfe),
  48111 	510: uint8(0xff),
  48112 	511: uint8(0xff),
  48113 	512: uint8(0xff),
  48114 	513: uint8(0xff),
  48115 	514: uint8(0xff),
  48116 	515: uint8(0xff),
  48117 	516: uint8(0xff),
  48118 	517: uint8(0xff),
  48119 	518: uint8(0xff),
  48120 	519: uint8(0xff),
  48121 	520: uint8(0xff),
  48122 	521: uint8(0xff),
  48123 	522: uint8(0xff),
  48124 	523: uint8(0xff),
  48125 	524: uint8(0xff),
  48126 	525: uint8(0xff),
  48127 	526: uint8(0xff),
  48128 	527: uint8(0xff),
  48129 	528: uint8(0xff),
  48130 	529: uint8(0xff),
  48131 	530: uint8(0xff),
  48132 	531: uint8(0xff),
  48133 	532: uint8(0xff),
  48134 	533: uint8(0xff),
  48135 	534: uint8(0xff),
  48136 	535: uint8(0xff),
  48137 	536: uint8(0xff),
  48138 	537: uint8(0xff),
  48139 	538: uint8(0xff),
  48140 	539: uint8(0xff),
  48141 	540: uint8(0xff),
  48142 	541: uint8(0xff),
  48143 	542: uint8(0xff),
  48144 	543: uint8(0xff),
  48145 	544: uint8(0xff),
  48146 	545: uint8(0xff),
  48147 	546: uint8(0xff),
  48148 	547: uint8(0xff),
  48149 	548: uint8(0xff),
  48150 	549: uint8(0xff),
  48151 	550: uint8(0xff),
  48152 	551: uint8(0xff),
  48153 	552: uint8(0xff),
  48154 	553: uint8(0xff),
  48155 	554: uint8(0xff),
  48156 	555: uint8(0xff),
  48157 	556: uint8(0xff),
  48158 	557: uint8(0xff),
  48159 	558: uint8(0xff),
  48160 	559: uint8(0xff),
  48161 	560: uint8(0xff),
  48162 	561: uint8(0xff),
  48163 	562: uint8(0xff),
  48164 	563: uint8(0xff),
  48165 	564: uint8(0xff),
  48166 	565: uint8(0xff),
  48167 	566: uint8(0xff),
  48168 	567: uint8(0xff),
  48169 	568: uint8(0xff),
  48170 	569: uint8(0xff),
  48171 	570: uint8(0xff),
  48172 	571: uint8(0xff),
  48173 	572: uint8(0xff),
  48174 	573: uint8(0xff),
  48175 	574: uint8(0xff),
  48176 	575: uint8(0xff),
  48177 	576: uint8(0xff),
  48178 	577: uint8(0xff),
  48179 	578: uint8(0xff),
  48180 	579: uint8(0xff),
  48181 	580: uint8(0xff),
  48182 	581: uint8(0xff),
  48183 	582: uint8(0xff),
  48184 	583: uint8(0xff),
  48185 	584: uint8(0xff),
  48186 	585: uint8(0xff),
  48187 	586: uint8(0xff),
  48188 	587: uint8(0xff),
  48189 	588: uint8(0xff),
  48190 	589: uint8(0xff),
  48191 	590: uint8(0xff),
  48192 	591: uint8(0xff),
  48193 	592: uint8(0xff),
  48194 	593: uint8(0xff),
  48195 	594: uint8(0xff),
  48196 	595: uint8(0xff),
  48197 	596: uint8(0xff),
  48198 	597: uint8(0xff),
  48199 	598: uint8(0xff),
  48200 	599: uint8(0xff),
  48201 	600: uint8(0xff),
  48202 	601: uint8(0xff),
  48203 	602: uint8(0xff),
  48204 	603: uint8(0xff),
  48205 	604: uint8(0xff),
  48206 	605: uint8(0xff),
  48207 	606: uint8(0xff),
  48208 	607: uint8(0xff),
  48209 	608: uint8(0xff),
  48210 	609: uint8(0xff),
  48211 	610: uint8(0xff),
  48212 	611: uint8(0xff),
  48213 	612: uint8(0xff),
  48214 	613: uint8(0xff),
  48215 	614: uint8(0xff),
  48216 	615: uint8(0xff),
  48217 	616: uint8(0xff),
  48218 	617: uint8(0xff),
  48219 	618: uint8(0xff),
  48220 	619: uint8(0xff),
  48221 	620: uint8(0xff),
  48222 	621: uint8(0xff),
  48223 	622: uint8(0xff),
  48224 	623: uint8(0xff),
  48225 	624: uint8(0xff),
  48226 	625: uint8(0xff),
  48227 	626: uint8(0xff),
  48228 	627: uint8(0xff),
  48229 	628: uint8(0xff),
  48230 	629: uint8(0xff),
  48231 	630: uint8(0xff),
  48232 	631: uint8(0xff),
  48233 	632: uint8(0xff),
  48234 	633: uint8(0xff),
  48235 	634: uint8(0xff),
  48236 	635: uint8(0xff),
  48237 	636: uint8(0xff),
  48238 	637: uint8(0xff),
  48239 	638: uint8(0xff),
  48240 	639: uint8(0xff),
  48241 	640: uint8(0xff),
  48242 	641: uint8(0xff),
  48243 	642: uint8(0xff),
  48244 	643: uint8(0xff),
  48245 	644: uint8(0xff),
  48246 	645: uint8(0xff),
  48247 	646: uint8(0xff),
  48248 	647: uint8(0xff),
  48249 	648: uint8(0xff),
  48250 	649: uint8(0xff),
  48251 	650: uint8(0xff),
  48252 	651: uint8(0xff),
  48253 	652: uint8(0xff),
  48254 	653: uint8(0xff),
  48255 	654: uint8(0xff),
  48256 	655: uint8(0xff),
  48257 	656: uint8(0xff),
  48258 	657: uint8(0xff),
  48259 	658: uint8(0xff),
  48260 	659: uint8(0xff),
  48261 	660: uint8(0xff),
  48262 	661: uint8(0xff),
  48263 	662: uint8(0xff),
  48264 	663: uint8(0xff),
  48265 	664: uint8(0xff),
  48266 	665: uint8(0xff),
  48267 	666: uint8(0xff),
  48268 	667: uint8(0xff),
  48269 	668: uint8(0xff),
  48270 	669: uint8(0xff),
  48271 	670: uint8(0xff),
  48272 	671: uint8(0xff),
  48273 	672: uint8(0xff),
  48274 	673: uint8(0xff),
  48275 	674: uint8(0xff),
  48276 	675: uint8(0xff),
  48277 	676: uint8(0xff),
  48278 	677: uint8(0xff),
  48279 	678: uint8(0xff),
  48280 	679: uint8(0xff),
  48281 	680: uint8(0xff),
  48282 	681: uint8(0xff),
  48283 	682: uint8(0xff),
  48284 	683: uint8(0xff),
  48285 	684: uint8(0xff),
  48286 	685: uint8(0xff),
  48287 	686: uint8(0xff),
  48288 	687: uint8(0xff),
  48289 	688: uint8(0xff),
  48290 	689: uint8(0xff),
  48291 	690: uint8(0xff),
  48292 	691: uint8(0xff),
  48293 	692: uint8(0xff),
  48294 	693: uint8(0xff),
  48295 	694: uint8(0xff),
  48296 	695: uint8(0xff),
  48297 	696: uint8(0xff),
  48298 	697: uint8(0xff),
  48299 	698: uint8(0xff),
  48300 	699: uint8(0xff),
  48301 	700: uint8(0xff),
  48302 	701: uint8(0xff),
  48303 	702: uint8(0xff),
  48304 	703: uint8(0xff),
  48305 	704: uint8(0xff),
  48306 	705: uint8(0xff),
  48307 	706: uint8(0xff),
  48308 	707: uint8(0xff),
  48309 	708: uint8(0xff),
  48310 	709: uint8(0xff),
  48311 	710: uint8(0xff),
  48312 	711: uint8(0xff),
  48313 	712: uint8(0xff),
  48314 	713: uint8(0xff),
  48315 	714: uint8(0xff),
  48316 	715: uint8(0xff),
  48317 	716: uint8(0xff),
  48318 	717: uint8(0xff),
  48319 	718: uint8(0xff),
  48320 	719: uint8(0xff),
  48321 	720: uint8(0xff),
  48322 	721: uint8(0xff),
  48323 	722: uint8(0xff),
  48324 	723: uint8(0xff),
  48325 	724: uint8(0xff),
  48326 	725: uint8(0xff),
  48327 	726: uint8(0xff),
  48328 	727: uint8(0xff),
  48329 	728: uint8(0xff),
  48330 	729: uint8(0xff),
  48331 	730: uint8(0xff),
  48332 	731: uint8(0xff),
  48333 	732: uint8(0xff),
  48334 	733: uint8(0xff),
  48335 	734: uint8(0xff),
  48336 	735: uint8(0xff),
  48337 	736: uint8(0xff),
  48338 	737: uint8(0xff),
  48339 	738: uint8(0xff),
  48340 	739: uint8(0xff),
  48341 	740: uint8(0xff),
  48342 	741: uint8(0xff),
  48343 	742: uint8(0xff),
  48344 	743: uint8(0xff),
  48345 	744: uint8(0xff),
  48346 	745: uint8(0xff),
  48347 	746: uint8(0xff),
  48348 	747: uint8(0xff),
  48349 	748: uint8(0xff),
  48350 	749: uint8(0xff),
  48351 	750: uint8(0xff),
  48352 	751: uint8(0xff),
  48353 	752: uint8(0xff),
  48354 	753: uint8(0xff),
  48355 	754: uint8(0xff),
  48356 	755: uint8(0xff),
  48357 	756: uint8(0xff),
  48358 	757: uint8(0xff),
  48359 	758: uint8(0xff),
  48360 	759: uint8(0xff),
  48361 	760: uint8(0xff),
  48362 	761: uint8(0xff),
  48363 	762: uint8(0xff),
  48364 	763: uint8(0xff),
  48365 	764: uint8(0xff),
  48366 	765: uint8(0xff),
  48367 }
  48368 
  48369 func VP8InitClipTables(tls *libc.TLS) {
  48370 }
  48371 
  48372 func VP8DspInitMIPS32(tls *libc.TLS) {
  48373 }
  48374 
  48375 func VP8DspInitMIPSdspR2(tls *libc.TLS) {
  48376 }
  48377 
  48378 func VP8DspInitMSA(tls *libc.TLS) {
  48379 }
  48380 
  48381 func VP8DspInitNEON(tls *libc.TLS) {
  48382 }
  48383 
  48384 func VP8DspInitSSE2(tls *libc.TLS) {
  48385 }
  48386 
  48387 func VP8DspInitSSE41(tls *libc.TLS) {
  48388 }
  48389 
  48390 const SIZE_MAX24 = "_UI64_MAX"
  48391 
  48392 //------------------------------------------------------------------------------
  48393 
  48394 // Copyright 2012 Google Inc. All Rights Reserved.
  48395 //
  48396 // Use of this source code is governed by a BSD-style license
  48397 // that can be found in the COPYING file in the root of the source
  48398 // tree. An additional intellectual property rights grant can be found
  48399 // in the file PATENTS. All contributing project authors may
  48400 // be found in the AUTHORS file in the root of the source tree.
  48401 // -----------------------------------------------------------------------------
  48402 //
  48403 // Misc. common utility functions
  48404 //
  48405 // Authors: Skal (pascal.massimino@gmail.com)
  48406 //          Urvang (urvang@google.com)
  48407 
  48408 // Copyright 2010 Google Inc. All Rights Reserved.
  48409 //
  48410 // Use of this source code is governed by a BSD-style license
  48411 // that can be found in the COPYING file in the root of the source
  48412 // tree. An additional intellectual property rights grant can be found
  48413 // in the file PATENTS. All contributing project authors may
  48414 // be found in the AUTHORS file in the root of the source tree.
  48415 // -----------------------------------------------------------------------------
  48416 //
  48417 //  Common types + memory wrappers
  48418 //
  48419 // Author: Skal (pascal.massimino@gmail.com)
  48420 
  48421 func clip_8b2(tls *libc.TLS, v int32) (r uint8_t) {
  48422 	var v1, v2 int32
  48423 	_, _ = v1, v2
  48424 	if !(v & ^libc.Int32FromInt32(0xff) != 0) {
  48425 		v1 = v
  48426 	} else {
  48427 		if v < 0 {
  48428 			v2 = 0
  48429 		} else {
  48430 			v2 = int32(255)
  48431 		}
  48432 		v1 = v2
  48433 	}
  48434 	return uint8(v1)
  48435 }
  48436 
  48437 func clip_max(tls *libc.TLS, v int32, max int32) (r int32) {
  48438 	var v1 int32
  48439 	_ = v1
  48440 	if v > max {
  48441 		v1 = max
  48442 	} else {
  48443 		v1 = v
  48444 	}
  48445 	return v1
  48446 }
  48447 
  48448 // C documentation
  48449 //
  48450 //	// general-purpose util function
  48451 func VP8SetHistogramData(tls *libc.TLS, distribution uintptr, histo uintptr) {
  48452 	var k, last_non_zero, max_value, value int32
  48453 	_, _, _, _ = k, last_non_zero, max_value, value
  48454 	max_value = 0
  48455 	last_non_zero = int32(1)
  48456 	k = 0
  48457 	for {
  48458 		if !(k <= int32(MAX_COEFF_THRESH)) {
  48459 			break
  48460 		}
  48461 		value = **(**int32)(__ccgo_up(distribution + uintptr(k)*4))
  48462 		if value > 0 {
  48463 			if value > max_value {
  48464 				max_value = value
  48465 			}
  48466 			last_non_zero = k
  48467 		}
  48468 		goto _1
  48469 	_1:
  48470 		;
  48471 		k = k + 1
  48472 	}
  48473 	(*VP8Histogram)(unsafe.Pointer(histo)).Fmax_value = max_value
  48474 	(*VP8Histogram)(unsafe.Pointer(histo)).Flast_non_zero = last_non_zero
  48475 }
  48476 
  48477 func CollectHistogram_C(tls *libc.TLS, ref uintptr, pred uintptr, start_block int32, end_block int32, histo uintptr) {
  48478 	bp := tls.Alloc(160)
  48479 	defer tls.Free(160)
  48480 	var clipped_value, j, k, v int32
  48481 	var _ /* distribution at bp+0 */ [32]int32
  48482 	var _ /* out at bp+128 */ [16]int16_t
  48483 	_, _, _, _ = clipped_value, j, k, v
  48484 	**(**[32]int32)(__ccgo_up(bp)) = [32]int32{}
  48485 	j = start_block
  48486 	for {
  48487 		if !(j < end_block) {
  48488 			break
  48489 		}
  48490 		(*(*func(*libc.TLS, uintptr, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8FTransform})))(tls, ref+uintptr(VP8DspScan[j]), pred+uintptr(VP8DspScan[j]), bp+128)
  48491 		// Convert coefficients to bin.
  48492 		k = 0
  48493 		for {
  48494 			if !(k < int32(16)) {
  48495 				break
  48496 			}
  48497 			v = libc.Xabs(tls, int32((**(**[16]int16_t)(__ccgo_up(bp + 128)))[k])) >> int32(3)
  48498 			clipped_value = clip_max(tls, v, int32(MAX_COEFF_THRESH))
  48499 			(**(**[32]int32)(__ccgo_up(bp)))[clipped_value] = (**(**[32]int32)(__ccgo_up(bp)))[clipped_value] + 1
  48500 			goto _2
  48501 		_2:
  48502 			;
  48503 			k = k + 1
  48504 		}
  48505 		goto _1
  48506 	_1:
  48507 		;
  48508 		j = j + 1
  48509 	}
  48510 	VP8SetHistogramData(tls, bp, histo)
  48511 }
  48512 
  48513 //------------------------------------------------------------------------------
  48514 // run-time tables (~4k)
  48515 
  48516 var clip12 [766]uint8_t // clips [-255,510] to [0,255]
  48517 
  48518 // C documentation
  48519 //
  48520 //	// We declare this variable 'volatile' to prevent instruction reordering
  48521 //	// and make sure it's set to true _last_ (so as to be thread-safe)
  48522 var tables_ok = int32(0)
  48523 
  48524 func InitTables(tls *libc.TLS) {
  48525 	var i int32
  48526 	_ = i
  48527 	if !(libc.AtomicLoadPInt32(uintptr(unsafe.Pointer(&tables_ok))) != 0) {
  48528 		i = -int32(255)
  48529 		for {
  48530 			if !(i <= libc.Int32FromInt32(255)+libc.Int32FromInt32(255)) {
  48531 				break
  48532 			}
  48533 			clip12[int32(255)+i] = clip_8b2(tls, i)
  48534 			goto _1
  48535 		_1:
  48536 			;
  48537 			i = i + 1
  48538 		}
  48539 		libc.AtomicStorePInt32(uintptr(unsafe.Pointer(&tables_ok)), int32(1))
  48540 	}
  48541 }
  48542 
  48543 //------------------------------------------------------------------------------
  48544 // Transforms (Paragraph 14.4)
  48545 
  48546 func ITransformOne(tls *libc.TLS, ref uintptr, in uintptr, dst uintptr) {
  48547 	bp := tls.Alloc(64)
  48548 	defer tls.Free(64)
  48549 	var a, a1, b, b1, c, c1, d, d1, dc, i int32
  48550 	var tmp uintptr
  48551 	var _ /* C at bp+0 */ [16]int32
  48552 	_, _, _, _, _, _, _, _, _, _, _ = a, a1, b, b1, c, c1, d, d1, dc, i, tmp
  48553 	tmp = bp
  48554 	i = 0
  48555 	for {
  48556 		if !(i < int32(4)) {
  48557 			break
  48558 		} // vertical pass
  48559 		a = int32(**(**int16_t)(__ccgo_up(in))) + int32(**(**int16_t)(__ccgo_up(in + 8*2)))
  48560 		b = int32(**(**int16_t)(__ccgo_up(in))) - int32(**(**int16_t)(__ccgo_up(in + 8*2)))
  48561 		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))))
  48562 		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)
  48563 		**(**int32)(__ccgo_up(tmp)) = a + d
  48564 		**(**int32)(__ccgo_up(tmp + 1*4)) = b + c
  48565 		**(**int32)(__ccgo_up(tmp + 2*4)) = b - c
  48566 		**(**int32)(__ccgo_up(tmp + 3*4)) = a - d
  48567 		tmp = tmp + uintptr(4)*4
  48568 		in += 2
  48569 		goto _1
  48570 	_1:
  48571 		;
  48572 		i = i + 1
  48573 	}
  48574 	tmp = bp
  48575 	i = 0
  48576 	for {
  48577 		if !(i < int32(4)) {
  48578 			break
  48579 		} // horizontal pass
  48580 		dc = **(**int32)(__ccgo_up(tmp)) + int32(4)
  48581 		a1 = dc + **(**int32)(__ccgo_up(tmp + 8*4))
  48582 		b1 = dc - **(**int32)(__ccgo_up(tmp + 8*4))
  48583 		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)))
  48584 		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)
  48585 		**(**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))
  48586 		**(**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))
  48587 		**(**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))
  48588 		**(**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))
  48589 		tmp += 4
  48590 		goto _2
  48591 	_2:
  48592 		;
  48593 		i = i + 1
  48594 	}
  48595 }
  48596 
  48597 func ITransform_C(tls *libc.TLS, ref uintptr, in uintptr, dst uintptr, do_two int32) {
  48598 	ITransformOne(tls, ref, in, dst)
  48599 	if do_two != 0 {
  48600 		ITransformOne(tls, ref+uintptr(4), in+uintptr(16)*2, dst+uintptr(4))
  48601 	}
  48602 }
  48603 
  48604 func FTransform_C(tls *libc.TLS, src uintptr, ref uintptr, out uintptr) {
  48605 	var a0, a01, a1, a11, a2, a21, a3, a31, d0, d1, d2, d3, i int32
  48606 	var tmp [16]int32
  48607 	_, _, _, _, _, _, _, _, _, _, _, _, _, _ = a0, a01, a1, a11, a2, a21, a3, a31, d0, d1, d2, d3, i, tmp
  48608 	i = 0
  48609 	for {
  48610 		if !(i < int32(4)) {
  48611 			break
  48612 		}
  48613 		d0 = int32(**(**uint8_t)(__ccgo_up(src))) - int32(**(**uint8_t)(__ccgo_up(ref))) // 9bit dynamic range ([-255,255])
  48614 		d1 = int32(**(**uint8_t)(__ccgo_up(src + 1))) - int32(**(**uint8_t)(__ccgo_up(ref + 1)))
  48615 		d2 = int32(**(**uint8_t)(__ccgo_up(src + 2))) - int32(**(**uint8_t)(__ccgo_up(ref + 2)))
  48616 		d3 = int32(**(**uint8_t)(__ccgo_up(src + 3))) - int32(**(**uint8_t)(__ccgo_up(ref + 3)))
  48617 		a0 = d0 + d3 // 10b                      [-510,510]
  48618 		a1 = d1 + d2
  48619 		a2 = d1 - d2
  48620 		a3 = d0 - d3
  48621 		tmp[0+i*int32(4)] = (a0 + a1) * int32(8)                                               // 14b                      [-8160,8160]
  48622 		tmp[int32(1)+i*int32(4)] = (a2*int32(2217) + a3*int32(5352) + int32(1812)) >> int32(9) // [-7536,7542]
  48623 		tmp[int32(2)+i*int32(4)] = (a0 - a1) * int32(8)
  48624 		tmp[int32(3)+i*int32(4)] = (a3*int32(2217) - a2*int32(5352) + int32(937)) >> int32(9)
  48625 		goto _1
  48626 	_1:
  48627 		;
  48628 		i = i + 1
  48629 		src = src + uintptr(BPS)
  48630 		ref = ref + uintptr(BPS)
  48631 	}
  48632 	i = 0
  48633 	for {
  48634 		if !(i < int32(4)) {
  48635 			break
  48636 		}
  48637 		a01 = tmp[0+i] + tmp[int32(12)+i] // 15b
  48638 		a11 = tmp[int32(4)+i] + tmp[int32(8)+i]
  48639 		a21 = tmp[int32(4)+i] - tmp[int32(8)+i]
  48640 		a31 = tmp[0+i] - tmp[int32(12)+i]
  48641 		**(**int16_t)(__ccgo_up(out + uintptr(0+i)*2)) = int16((a01 + a11 + int32(7)) >> int32(4)) // 12b
  48642 		**(**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))
  48643 		**(**int16_t)(__ccgo_up(out + uintptr(int32(8)+i)*2)) = int16((a01 - a11 + int32(7)) >> int32(4))
  48644 		**(**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))
  48645 		goto _2
  48646 	_2:
  48647 		;
  48648 		i = i + 1
  48649 	}
  48650 }
  48651 
  48652 func FTransform2_C(tls *libc.TLS, src uintptr, ref uintptr, out uintptr) {
  48653 	(*(*func(*libc.TLS, uintptr, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8FTransform})))(tls, src, ref, out)
  48654 	(*(*func(*libc.TLS, uintptr, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8FTransform})))(tls, src+uintptr(4), ref+uintptr(4), out+uintptr(16)*2)
  48655 }
  48656 
  48657 func FTransformWHT_C(tls *libc.TLS, in uintptr, out uintptr) {
  48658 	var a0, a01, a1, a11, a2, a21, a3, a31, b0, b1, b2, b3, i int32
  48659 	var tmp [16]int32_t
  48660 	_, _, _, _, _, _, _, _, _, _, _, _, _, _ = a0, a01, a1, a11, a2, a21, a3, a31, b0, b1, b2, b3, i, tmp
  48661 	i = 0
  48662 	for {
  48663 		if !(i < int32(4)) {
  48664 			break
  48665 		}
  48666 		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
  48667 		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)))
  48668 		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)))
  48669 		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)))
  48670 		tmp[0+i*int32(4)] = a0 + a1 // 14b
  48671 		tmp[int32(1)+i*int32(4)] = a3 + a2
  48672 		tmp[int32(2)+i*int32(4)] = a3 - a2
  48673 		tmp[int32(3)+i*int32(4)] = a0 - a1
  48674 		goto _1
  48675 	_1:
  48676 		;
  48677 		i = i + 1
  48678 		in = in + uintptr(64)*2
  48679 	}
  48680 	i = 0
  48681 	for {
  48682 		if !(i < int32(4)) {
  48683 			break
  48684 		}
  48685 		a01 = tmp[0+i] + tmp[int32(8)+i] // 15b
  48686 		a11 = tmp[int32(4)+i] + tmp[int32(12)+i]
  48687 		a21 = tmp[int32(4)+i] - tmp[int32(12)+i]
  48688 		a31 = tmp[0+i] - tmp[int32(8)+i]
  48689 		b0 = a01 + a11 // 16b
  48690 		b1 = a31 + a21
  48691 		b2 = a31 - a21
  48692 		b3 = a01 - a11
  48693 		**(**int16_t)(__ccgo_up(out + uintptr(0+i)*2)) = int16(b0 >> int32(1)) // 15b
  48694 		**(**int16_t)(__ccgo_up(out + uintptr(int32(4)+i)*2)) = int16(b1 >> int32(1))
  48695 		**(**int16_t)(__ccgo_up(out + uintptr(int32(8)+i)*2)) = int16(b2 >> int32(1))
  48696 		**(**int16_t)(__ccgo_up(out + uintptr(int32(12)+i)*2)) = int16(b3 >> int32(1))
  48697 		goto _2
  48698 	_2:
  48699 		;
  48700 		i = i + 1
  48701 	}
  48702 }
  48703 
  48704 //------------------------------------------------------------------------------
  48705 // Intra predictions
  48706 
  48707 func Fill(tls *libc.TLS, dst uintptr, value int32, size int32) {
  48708 	var j int32
  48709 	_ = j
  48710 	j = 0
  48711 	for {
  48712 		if !(j < size) {
  48713 			break
  48714 		}
  48715 		libc.Xmemset(tls, dst+uintptr(j*int32(BPS)), value, uint64(size))
  48716 		goto _1
  48717 	_1:
  48718 		;
  48719 		j = j + 1
  48720 	}
  48721 }
  48722 
  48723 func VerticalPred(tls *libc.TLS, dst uintptr, top uintptr, size int32) {
  48724 	var j int32
  48725 	_ = j
  48726 	if top != libc.UintptrFromInt32(0) {
  48727 		j = 0
  48728 		for {
  48729 			if !(j < size) {
  48730 				break
  48731 			}
  48732 			libc.Xmemcpy(tls, dst+uintptr(j*int32(BPS)), top, uint64(size))
  48733 			goto _1
  48734 		_1:
  48735 			;
  48736 			j = j + 1
  48737 		}
  48738 	} else {
  48739 		Fill(tls, dst, int32(127), size)
  48740 	}
  48741 }
  48742 
  48743 func HorizontalPred(tls *libc.TLS, dst uintptr, left uintptr, size int32) {
  48744 	var j int32
  48745 	_ = j
  48746 	if left != libc.UintptrFromInt32(0) {
  48747 		j = 0
  48748 		for {
  48749 			if !(j < size) {
  48750 				break
  48751 			}
  48752 			libc.Xmemset(tls, dst+uintptr(j*int32(BPS)), int32(**(**uint8_t)(__ccgo_up(left + uintptr(j)))), uint64(size))
  48753 			goto _1
  48754 		_1:
  48755 			;
  48756 			j = j + 1
  48757 		}
  48758 	} else {
  48759 		Fill(tls, dst, int32(129), size)
  48760 	}
  48761 }
  48762 
  48763 func TrueMotion1(tls *libc.TLS, dst uintptr, left uintptr, top uintptr, size int32) {
  48764 	var clip, clip_table uintptr
  48765 	var x, y int32
  48766 	_, _, _, _ = clip, clip_table, x, y
  48767 	if left != libc.UintptrFromInt32(0) {
  48768 		if top != libc.UintptrFromInt32(0) {
  48769 			clip = uintptr(unsafe.Pointer(&clip12)) + uintptr(255) - uintptr(**(**uint8_t)(__ccgo_up(left + uintptr(-libc.Int32FromInt32(1)))))
  48770 			y = 0
  48771 			for {
  48772 				if !(y < size) {
  48773 					break
  48774 				}
  48775 				clip_table = clip + uintptr(**(**uint8_t)(__ccgo_up(left + uintptr(y))))
  48776 				x = 0
  48777 				for {
  48778 					if !(x < size) {
  48779 						break
  48780 					}
  48781 					**(**uint8_t)(__ccgo_up(dst + uintptr(x))) = **(**uint8_t)(__ccgo_up(clip_table + uintptr(**(**uint8_t)(__ccgo_up(top + uintptr(x))))))
  48782 					goto _2
  48783 				_2:
  48784 					;
  48785 					x = x + 1
  48786 				}
  48787 				dst = dst + uintptr(BPS)
  48788 				goto _1
  48789 			_1:
  48790 				;
  48791 				y = y + 1
  48792 			}
  48793 		} else {
  48794 			HorizontalPred(tls, dst, left, size)
  48795 		}
  48796 	} else {
  48797 		// true motion without left samples (hence: with default 129 value)
  48798 		// is equivalent to VE prediction where you just copy the top samples.
  48799 		// Note that if top samples are not available, the default value is
  48800 		// then 129, and not 127 as in the VerticalPred case.
  48801 		if top != libc.UintptrFromInt32(0) {
  48802 			VerticalPred(tls, dst, top, size)
  48803 		} else {
  48804 			Fill(tls, dst, int32(129), size)
  48805 		}
  48806 	}
  48807 }
  48808 
  48809 func DCMode(tls *libc.TLS, dst uintptr, left uintptr, top uintptr, size int32, round int32, shift int32) {
  48810 	var DC, j int32
  48811 	_, _ = DC, j
  48812 	DC = 0
  48813 	if top != libc.UintptrFromInt32(0) {
  48814 		j = 0
  48815 		for {
  48816 			if !(j < size) {
  48817 				break
  48818 			}
  48819 			DC = DC + int32(**(**uint8_t)(__ccgo_up(top + uintptr(j))))
  48820 			goto _1
  48821 		_1:
  48822 			;
  48823 			j = j + 1
  48824 		}
  48825 		if left != libc.UintptrFromInt32(0) { // top and left present
  48826 			j = 0
  48827 			for {
  48828 				if !(j < size) {
  48829 					break
  48830 				}
  48831 				DC = DC + int32(**(**uint8_t)(__ccgo_up(left + uintptr(j))))
  48832 				goto _2
  48833 			_2:
  48834 				;
  48835 				j = j + 1
  48836 			}
  48837 		} else { // top, but no left
  48838 			DC = DC + DC
  48839 		}
  48840 		DC = (DC + round) >> shift
  48841 	} else {
  48842 		if left != libc.UintptrFromInt32(0) { // left but no top
  48843 			j = 0
  48844 			for {
  48845 				if !(j < size) {
  48846 					break
  48847 				}
  48848 				DC = DC + int32(**(**uint8_t)(__ccgo_up(left + uintptr(j))))
  48849 				goto _3
  48850 			_3:
  48851 				;
  48852 				j = j + 1
  48853 			}
  48854 			DC = DC + DC
  48855 			DC = (DC + round) >> shift
  48856 		} else { // no top, no left, nothing.
  48857 			DC = int32(0x80)
  48858 		}
  48859 	}
  48860 	Fill(tls, dst, DC, size)
  48861 }
  48862 
  48863 //------------------------------------------------------------------------------
  48864 // Chroma 8x8 prediction (paragraph 12.2)
  48865 
  48866 func IntraChromaPreds_C(tls *libc.TLS, dst uintptr, left uintptr, top uintptr) {
  48867 	// U block
  48868 	DCMode(tls, uintptr(libc.Int32FromInt32(2)*libc.Int32FromInt32(16)*libc.Int32FromInt32(BPS))+dst, left, top, int32(8), int32(8), int32(4))
  48869 	VerticalPred(tls, uintptr(libc.Int32FromInt32(2)*libc.Int32FromInt32(16)*libc.Int32FromInt32(BPS)+libc.Int32FromInt32(8)*libc.Int32FromInt32(BPS))+dst, top, int32(8))
  48870 	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))
  48871 	TrueMotion1(tls, uintptr(libc.Int32FromInt32(2)*libc.Int32FromInt32(16)*libc.Int32FromInt32(BPS)+libc.Int32FromInt32(1)*libc.Int32FromInt32(16))+dst, left, top, int32(8))
  48872 	// V block
  48873 	dst = dst + uintptr(8)
  48874 	if top != libc.UintptrFromInt32(0) {
  48875 		top = top + uintptr(8)
  48876 	}
  48877 	if left != libc.UintptrFromInt32(0) {
  48878 		left = left + uintptr(16)
  48879 	}
  48880 	DCMode(tls, uintptr(libc.Int32FromInt32(2)*libc.Int32FromInt32(16)*libc.Int32FromInt32(BPS))+dst, left, top, int32(8), int32(8), int32(4))
  48881 	VerticalPred(tls, uintptr(libc.Int32FromInt32(2)*libc.Int32FromInt32(16)*libc.Int32FromInt32(BPS)+libc.Int32FromInt32(8)*libc.Int32FromInt32(BPS))+dst, top, int32(8))
  48882 	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))
  48883 	TrueMotion1(tls, uintptr(libc.Int32FromInt32(2)*libc.Int32FromInt32(16)*libc.Int32FromInt32(BPS)+libc.Int32FromInt32(1)*libc.Int32FromInt32(16))+dst, left, top, int32(8))
  48884 }
  48885 
  48886 //------------------------------------------------------------------------------
  48887 // luma 16x16 prediction (paragraph 12.3)
  48888 
  48889 func Intra16Preds_C(tls *libc.TLS, dst uintptr, left uintptr, top uintptr) {
  48890 	DCMode(tls, uintptr(libc.Int32FromInt32(0)*libc.Int32FromInt32(16)*libc.Int32FromInt32(BPS))+dst, left, top, int32(16), int32(16), int32(5))
  48891 	VerticalPred(tls, uintptr(libc.Int32FromInt32(1)*libc.Int32FromInt32(16)*libc.Int32FromInt32(BPS))+dst, top, int32(16))
  48892 	HorizontalPred(tls, uintptr(libc.Int32FromInt32(1)*libc.Int32FromInt32(16)*libc.Int32FromInt32(BPS)+libc.Int32FromInt32(16))+dst, left, int32(16))
  48893 	TrueMotion1(tls, uintptr(libc.Int32FromInt32(0)*libc.Int32FromInt32(16)*libc.Int32FromInt32(BPS)+libc.Int32FromInt32(16))+dst, left, top, int32(16))
  48894 }
  48895 
  48896 //------------------------------------------------------------------------------
  48897 // luma 4x4 prediction
  48898 
  48899 // C documentation
  48900 //
  48901 //	// vertical
  48902 func VE4(tls *libc.TLS, dst uintptr, top uintptr) {
  48903 	bp := tls.Alloc(16)
  48904 	defer tls.Free(16)
  48905 	var i int32
  48906 	var _ /* vals at bp+0 */ [4]uint8_t
  48907 	_ = i
  48908 	**(**[4]uint8_t)(__ccgo_up(bp)) = [4]uint8_t{
  48909 		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)),
  48910 		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)),
  48911 		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)),
  48912 		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)),
  48913 	}
  48914 	i = 0
  48915 	for {
  48916 		if !(i < int32(4)) {
  48917 			break
  48918 		}
  48919 		libc.Xmemcpy(tls, dst+uintptr(i*int32(BPS)), bp, uint64(4))
  48920 		goto _1
  48921 	_1:
  48922 		;
  48923 		i = i + 1
  48924 	}
  48925 }
  48926 
  48927 // C documentation
  48928 //
  48929 //	// horizontal
  48930 func HE4(tls *libc.TLS, dst uintptr, top uintptr) {
  48931 	bp := tls.Alloc(16)
  48932 	defer tls.Free(16)
  48933 	var I, J, K, L, X int32
  48934 	var v1 uint32_t
  48935 	_, _, _, _, _, _ = I, J, K, L, X, v1
  48936 	X = int32(**(**uint8_t)(__ccgo_up(top + uintptr(-libc.Int32FromInt32(1)))))
  48937 	I = int32(**(**uint8_t)(__ccgo_up(top + uintptr(-libc.Int32FromInt32(2)))))
  48938 	J = int32(**(**uint8_t)(__ccgo_up(top + uintptr(-libc.Int32FromInt32(3)))))
  48939 	K = int32(**(**uint8_t)(__ccgo_up(top + uintptr(-libc.Int32FromInt32(4)))))
  48940 	L = int32(**(**uint8_t)(__ccgo_up(top + uintptr(-libc.Int32FromInt32(5)))))
  48941 	v1 = uint32(0x01010101) * uint32(uint8((X+libc.Int32FromInt32(2)*I+J+libc.Int32FromInt32(2))>>libc.Int32FromInt32(2)))
  48942 	*(*uint32_t)(unsafe.Pointer(bp)) = v1
  48943 	libc.Xmemcpy(tls, dst+uintptr(libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)), bp, uint64(4))
  48944 	v1 = uint32(0x01010101) * uint32(uint8((I+libc.Int32FromInt32(2)*J+K+libc.Int32FromInt32(2))>>libc.Int32FromInt32(2)))
  48945 	*(*uint32_t)(unsafe.Pointer(bp)) = v1
  48946 	libc.Xmemcpy(tls, dst+uintptr(libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)), bp, uint64(4))
  48947 	v1 = uint32(0x01010101) * uint32(uint8((J+libc.Int32FromInt32(2)*K+L+libc.Int32FromInt32(2))>>libc.Int32FromInt32(2)))
  48948 	*(*uint32_t)(unsafe.Pointer(bp)) = v1
  48949 	libc.Xmemcpy(tls, dst+uintptr(libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)), bp, uint64(4))
  48950 	v1 = uint32(0x01010101) * uint32(uint8((K+libc.Int32FromInt32(2)*L+L+libc.Int32FromInt32(2))>>libc.Int32FromInt32(2)))
  48951 	*(*uint32_t)(unsafe.Pointer(bp)) = v1
  48952 	libc.Xmemcpy(tls, dst+uintptr(libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)), bp, uint64(4))
  48953 }
  48954 
  48955 func DC4(tls *libc.TLS, dst uintptr, top uintptr) {
  48956 	var dc uint32_t
  48957 	var i int32
  48958 	_, _ = dc, i
  48959 	dc = uint32(4)
  48960 	i = 0
  48961 	for {
  48962 		if !(i < int32(4)) {
  48963 			break
  48964 		}
  48965 		dc = dc + uint32(int32(**(**uint8_t)(__ccgo_up(top + uintptr(i))))+int32(**(**uint8_t)(__ccgo_up(top + uintptr(-int32(5)+i)))))
  48966 		goto _1
  48967 	_1:
  48968 		;
  48969 		i = i + 1
  48970 	}
  48971 	Fill(tls, dst, int32(dc>>int32(3)), int32(4))
  48972 }
  48973 
  48974 func RD4(tls *libc.TLS, dst uintptr, top uintptr) {
  48975 	var A, B, C, D, I, J, K, L, X int32
  48976 	var v1, v2, v3 uint8_t
  48977 	_, _, _, _, _, _, _, _, _, _, _, _ = A, B, C, D, I, J, K, L, X, v1, v2, v3
  48978 	X = int32(**(**uint8_t)(__ccgo_up(top + uintptr(-libc.Int32FromInt32(1)))))
  48979 	I = int32(**(**uint8_t)(__ccgo_up(top + uintptr(-libc.Int32FromInt32(2)))))
  48980 	J = int32(**(**uint8_t)(__ccgo_up(top + uintptr(-libc.Int32FromInt32(3)))))
  48981 	K = int32(**(**uint8_t)(__ccgo_up(top + uintptr(-libc.Int32FromInt32(4)))))
  48982 	L = int32(**(**uint8_t)(__ccgo_up(top + uintptr(-libc.Int32FromInt32(5)))))
  48983 	A = int32(**(**uint8_t)(__ccgo_up(top)))
  48984 	B = int32(**(**uint8_t)(__ccgo_up(top + 1)))
  48985 	C = int32(**(**uint8_t)(__ccgo_up(top + 2)))
  48986 	D = int32(**(**uint8_t)(__ccgo_up(top + 3)))
  48987 	**(**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))
  48988 	v1 = uint8((I + libc.Int32FromInt32(2)*J + K + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  48989 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = v1
  48990 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = v1
  48991 	v2 = uint8((X + libc.Int32FromInt32(2)*I + J + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  48992 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = v2
  48993 	v1 = v2
  48994 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = v1
  48995 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = v1
  48996 	v3 = uint8((A + libc.Int32FromInt32(2)*X + I + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  48997 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = v3
  48998 	v2 = v3
  48999 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = v2
  49000 	v1 = v2
  49001 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = v1
  49002 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = v1
  49003 	v2 = uint8((B + libc.Int32FromInt32(2)*A + X + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  49004 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = v2
  49005 	v1 = v2
  49006 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = v1
  49007 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = v1
  49008 	v1 = uint8((C + libc.Int32FromInt32(2)*B + A + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  49009 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = v1
  49010 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = v1
  49011 	**(**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))
  49012 }
  49013 
  49014 func LD4(tls *libc.TLS, dst uintptr, top uintptr) {
  49015 	var A, B, C, D, E, F, G, H int32
  49016 	var v1, v2, v3 uint8_t
  49017 	_, _, _, _, _, _, _, _, _, _, _ = A, B, C, D, E, F, G, H, v1, v2, v3
  49018 	A = int32(**(**uint8_t)(__ccgo_up(top)))
  49019 	B = int32(**(**uint8_t)(__ccgo_up(top + 1)))
  49020 	C = int32(**(**uint8_t)(__ccgo_up(top + 2)))
  49021 	D = int32(**(**uint8_t)(__ccgo_up(top + 3)))
  49022 	E = int32(**(**uint8_t)(__ccgo_up(top + 4)))
  49023 	F = int32(**(**uint8_t)(__ccgo_up(top + 5)))
  49024 	G = int32(**(**uint8_t)(__ccgo_up(top + 6)))
  49025 	H = int32(**(**uint8_t)(__ccgo_up(top + 7)))
  49026 	**(**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))
  49027 	v1 = uint8((B + libc.Int32FromInt32(2)*C + D + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  49028 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = v1
  49029 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = v1
  49030 	v2 = uint8((C + libc.Int32FromInt32(2)*D + E + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  49031 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = v2
  49032 	v1 = v2
  49033 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = v1
  49034 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = v1
  49035 	v3 = uint8((D + libc.Int32FromInt32(2)*E + F + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  49036 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = v3
  49037 	v2 = v3
  49038 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = v2
  49039 	v1 = v2
  49040 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = v1
  49041 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = v1
  49042 	v2 = uint8((E + libc.Int32FromInt32(2)*F + G + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  49043 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = v2
  49044 	v1 = v2
  49045 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = v1
  49046 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = v1
  49047 	v1 = uint8((F + libc.Int32FromInt32(2)*G + H + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  49048 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = v1
  49049 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = v1
  49050 	**(**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))
  49051 }
  49052 
  49053 func VR4(tls *libc.TLS, dst uintptr, top uintptr) {
  49054 	var A, B, C, D, I, J, K, X int32
  49055 	var v1 uint8_t
  49056 	_, _, _, _, _, _, _, _, _ = A, B, C, D, I, J, K, X, v1
  49057 	X = int32(**(**uint8_t)(__ccgo_up(top + uintptr(-libc.Int32FromInt32(1)))))
  49058 	I = int32(**(**uint8_t)(__ccgo_up(top + uintptr(-libc.Int32FromInt32(2)))))
  49059 	J = int32(**(**uint8_t)(__ccgo_up(top + uintptr(-libc.Int32FromInt32(3)))))
  49060 	K = int32(**(**uint8_t)(__ccgo_up(top + uintptr(-libc.Int32FromInt32(4)))))
  49061 	A = int32(**(**uint8_t)(__ccgo_up(top)))
  49062 	B = int32(**(**uint8_t)(__ccgo_up(top + 1)))
  49063 	C = int32(**(**uint8_t)(__ccgo_up(top + 2)))
  49064 	D = int32(**(**uint8_t)(__ccgo_up(top + 3)))
  49065 	v1 = uint8((X + A + libc.Int32FromInt32(1)) >> libc.Int32FromInt32(1))
  49066 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = v1
  49067 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = v1
  49068 	v1 = uint8((A + B + libc.Int32FromInt32(1)) >> libc.Int32FromInt32(1))
  49069 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = v1
  49070 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = v1
  49071 	v1 = uint8((B + C + libc.Int32FromInt32(1)) >> libc.Int32FromInt32(1))
  49072 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = v1
  49073 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = v1
  49074 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = uint8((C + D + libc.Int32FromInt32(1)) >> libc.Int32FromInt32(1))
  49075 	**(**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))
  49076 	**(**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))
  49077 	v1 = uint8((I + libc.Int32FromInt32(2)*X + A + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  49078 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = v1
  49079 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = v1
  49080 	v1 = uint8((X + libc.Int32FromInt32(2)*A + B + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  49081 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = v1
  49082 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = v1
  49083 	v1 = uint8((A + libc.Int32FromInt32(2)*B + C + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  49084 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = v1
  49085 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = v1
  49086 	**(**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))
  49087 }
  49088 
  49089 func VL4(tls *libc.TLS, dst uintptr, top uintptr) {
  49090 	var A, B, C, D, E, F, G, H int32
  49091 	var v1 uint8_t
  49092 	_, _, _, _, _, _, _, _, _ = A, B, C, D, E, F, G, H, v1
  49093 	A = int32(**(**uint8_t)(__ccgo_up(top)))
  49094 	B = int32(**(**uint8_t)(__ccgo_up(top + 1)))
  49095 	C = int32(**(**uint8_t)(__ccgo_up(top + 2)))
  49096 	D = int32(**(**uint8_t)(__ccgo_up(top + 3)))
  49097 	E = int32(**(**uint8_t)(__ccgo_up(top + 4)))
  49098 	F = int32(**(**uint8_t)(__ccgo_up(top + 5)))
  49099 	G = int32(**(**uint8_t)(__ccgo_up(top + 6)))
  49100 	H = int32(**(**uint8_t)(__ccgo_up(top + 7)))
  49101 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = uint8((A + B + libc.Int32FromInt32(1)) >> libc.Int32FromInt32(1))
  49102 	v1 = uint8((B + C + libc.Int32FromInt32(1)) >> libc.Int32FromInt32(1))
  49103 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = v1
  49104 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = v1
  49105 	v1 = uint8((C + D + libc.Int32FromInt32(1)) >> libc.Int32FromInt32(1))
  49106 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = v1
  49107 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = v1
  49108 	v1 = uint8((D + E + libc.Int32FromInt32(1)) >> libc.Int32FromInt32(1))
  49109 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = v1
  49110 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = v1
  49111 	**(**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))
  49112 	v1 = uint8((B + libc.Int32FromInt32(2)*C + D + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  49113 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = v1
  49114 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = v1
  49115 	v1 = uint8((C + libc.Int32FromInt32(2)*D + E + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  49116 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = v1
  49117 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = v1
  49118 	v1 = uint8((D + libc.Int32FromInt32(2)*E + F + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  49119 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = v1
  49120 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = v1
  49121 	**(**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))
  49122 	**(**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))
  49123 }
  49124 
  49125 func HU4(tls *libc.TLS, dst uintptr, top uintptr) {
  49126 	var I, J, K, L int32
  49127 	var v1, v2, v3, v4, v5 uint8_t
  49128 	_, _, _, _, _, _, _, _, _ = I, J, K, L, v1, v2, v3, v4, v5
  49129 	I = int32(**(**uint8_t)(__ccgo_up(top + uintptr(-libc.Int32FromInt32(2)))))
  49130 	J = int32(**(**uint8_t)(__ccgo_up(top + uintptr(-libc.Int32FromInt32(3)))))
  49131 	K = int32(**(**uint8_t)(__ccgo_up(top + uintptr(-libc.Int32FromInt32(4)))))
  49132 	L = int32(**(**uint8_t)(__ccgo_up(top + uintptr(-libc.Int32FromInt32(5)))))
  49133 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = uint8((I + J + libc.Int32FromInt32(1)) >> libc.Int32FromInt32(1))
  49134 	v1 = uint8((J + K + libc.Int32FromInt32(1)) >> libc.Int32FromInt32(1))
  49135 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = v1
  49136 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = v1
  49137 	v1 = uint8((K + L + libc.Int32FromInt32(1)) >> libc.Int32FromInt32(1))
  49138 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = v1
  49139 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = v1
  49140 	**(**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))
  49141 	v1 = uint8((J + libc.Int32FromInt32(2)*K + L + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  49142 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = v1
  49143 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = v1
  49144 	v1 = uint8((K + libc.Int32FromInt32(2)*L + L + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  49145 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = v1
  49146 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = v1
  49147 	v5 = uint8(L)
  49148 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = v5
  49149 	v4 = v5
  49150 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = v4
  49151 	v3 = v4
  49152 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = v3
  49153 	v2 = v3
  49154 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = v2
  49155 	v1 = v2
  49156 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = v1
  49157 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = v1
  49158 }
  49159 
  49160 func HD4(tls *libc.TLS, dst uintptr, top uintptr) {
  49161 	var A, B, C, I, J, K, L, X int32
  49162 	var v1 uint8_t
  49163 	_, _, _, _, _, _, _, _, _ = A, B, C, I, J, K, L, X, v1
  49164 	X = int32(**(**uint8_t)(__ccgo_up(top + uintptr(-libc.Int32FromInt32(1)))))
  49165 	I = int32(**(**uint8_t)(__ccgo_up(top + uintptr(-libc.Int32FromInt32(2)))))
  49166 	J = int32(**(**uint8_t)(__ccgo_up(top + uintptr(-libc.Int32FromInt32(3)))))
  49167 	K = int32(**(**uint8_t)(__ccgo_up(top + uintptr(-libc.Int32FromInt32(4)))))
  49168 	L = int32(**(**uint8_t)(__ccgo_up(top + uintptr(-libc.Int32FromInt32(5)))))
  49169 	A = int32(**(**uint8_t)(__ccgo_up(top)))
  49170 	B = int32(**(**uint8_t)(__ccgo_up(top + 1)))
  49171 	C = int32(**(**uint8_t)(__ccgo_up(top + 2)))
  49172 	v1 = uint8((I + X + libc.Int32FromInt32(1)) >> libc.Int32FromInt32(1))
  49173 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = v1
  49174 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = v1
  49175 	v1 = uint8((J + I + libc.Int32FromInt32(1)) >> libc.Int32FromInt32(1))
  49176 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = v1
  49177 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = v1
  49178 	v1 = uint8((K + J + libc.Int32FromInt32(1)) >> libc.Int32FromInt32(1))
  49179 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = v1
  49180 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = v1
  49181 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = uint8((L + K + libc.Int32FromInt32(1)) >> libc.Int32FromInt32(1))
  49182 	**(**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))
  49183 	**(**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))
  49184 	v1 = uint8((I + libc.Int32FromInt32(2)*X + A + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  49185 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = v1
  49186 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = v1
  49187 	v1 = uint8((J + libc.Int32FromInt32(2)*I + X + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  49188 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = v1
  49189 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = v1
  49190 	v1 = uint8((K + libc.Int32FromInt32(2)*J + I + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  49191 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = v1
  49192 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = v1
  49193 	**(**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))
  49194 }
  49195 
  49196 func TM4(tls *libc.TLS, dst uintptr, top uintptr) {
  49197 	var clip, clip_table uintptr
  49198 	var x, y int32
  49199 	_, _, _, _ = clip, clip_table, x, y
  49200 	clip = uintptr(unsafe.Pointer(&clip12)) + uintptr(255) - uintptr(**(**uint8_t)(__ccgo_up(top + uintptr(-libc.Int32FromInt32(1)))))
  49201 	y = 0
  49202 	for {
  49203 		if !(y < int32(4)) {
  49204 			break
  49205 		}
  49206 		clip_table = clip + uintptr(**(**uint8_t)(__ccgo_up(top + uintptr(-int32(2)-y))))
  49207 		x = 0
  49208 		for {
  49209 			if !(x < int32(4)) {
  49210 				break
  49211 			}
  49212 			**(**uint8_t)(__ccgo_up(dst + uintptr(x))) = **(**uint8_t)(__ccgo_up(clip_table + uintptr(**(**uint8_t)(__ccgo_up(top + uintptr(x))))))
  49213 			goto _2
  49214 		_2:
  49215 			;
  49216 			x = x + 1
  49217 		}
  49218 		dst = dst + uintptr(BPS)
  49219 		goto _1
  49220 	_1:
  49221 		;
  49222 		y = y + 1
  49223 	}
  49224 }
  49225 
  49226 // C documentation
  49227 //
  49228 //	// Left samples are top[-5 .. -2], top_left is top[-1], top are
  49229 //	// located at top[0..3], and top right is top[4..7]
  49230 func Intra4Preds_C(tls *libc.TLS, dst uintptr, top uintptr) {
  49231 	DC4(tls, uintptr(libc.Int32FromInt32(3)*libc.Int32FromInt32(16)*libc.Int32FromInt32(BPS)+libc.Int32FromInt32(0))+dst, top)
  49232 	TM4(tls, uintptr(libc.Int32FromInt32(3)*libc.Int32FromInt32(16)*libc.Int32FromInt32(BPS)+libc.Int32FromInt32(0)+libc.Int32FromInt32(4))+dst, top)
  49233 	VE4(tls, uintptr(libc.Int32FromInt32(3)*libc.Int32FromInt32(16)*libc.Int32FromInt32(BPS)+libc.Int32FromInt32(0)+libc.Int32FromInt32(8))+dst, top)
  49234 	HE4(tls, uintptr(libc.Int32FromInt32(3)*libc.Int32FromInt32(16)*libc.Int32FromInt32(BPS)+libc.Int32FromInt32(0)+libc.Int32FromInt32(12))+dst, top)
  49235 	RD4(tls, uintptr(libc.Int32FromInt32(3)*libc.Int32FromInt32(16)*libc.Int32FromInt32(BPS)+libc.Int32FromInt32(0)+libc.Int32FromInt32(16))+dst, top)
  49236 	VR4(tls, uintptr(libc.Int32FromInt32(3)*libc.Int32FromInt32(16)*libc.Int32FromInt32(BPS)+libc.Int32FromInt32(0)+libc.Int32FromInt32(20))+dst, top)
  49237 	LD4(tls, uintptr(libc.Int32FromInt32(3)*libc.Int32FromInt32(16)*libc.Int32FromInt32(BPS)+libc.Int32FromInt32(0)+libc.Int32FromInt32(24))+dst, top)
  49238 	VL4(tls, uintptr(libc.Int32FromInt32(3)*libc.Int32FromInt32(16)*libc.Int32FromInt32(BPS)+libc.Int32FromInt32(0)+libc.Int32FromInt32(28))+dst, top)
  49239 	HD4(tls, uintptr(libc.Int32FromInt32(3)*libc.Int32FromInt32(16)*libc.Int32FromInt32(BPS)+libc.Int32FromInt32(4)*libc.Int32FromInt32(BPS))+dst, top)
  49240 	HU4(tls, uintptr(libc.Int32FromInt32(3)*libc.Int32FromInt32(16)*libc.Int32FromInt32(BPS)+libc.Int32FromInt32(4)*libc.Int32FromInt32(BPS)+libc.Int32FromInt32(4))+dst, top)
  49241 }
  49242 
  49243 //------------------------------------------------------------------------------
  49244 // Metric
  49245 
  49246 func GetSSE(tls *libc.TLS, a uintptr, b uintptr, w int32, h int32) (r int32) {
  49247 	var count, diff, x, y int32
  49248 	_, _, _, _ = count, diff, x, y
  49249 	count = 0
  49250 	y = 0
  49251 	for {
  49252 		if !(y < h) {
  49253 			break
  49254 		}
  49255 		x = 0
  49256 		for {
  49257 			if !(x < w) {
  49258 				break
  49259 			}
  49260 			diff = int32(**(**uint8_t)(__ccgo_up(a + uintptr(x)))) - int32(**(**uint8_t)(__ccgo_up(b + uintptr(x))))
  49261 			count = count + diff*diff
  49262 			goto _2
  49263 		_2:
  49264 			;
  49265 			x = x + 1
  49266 		}
  49267 		a = a + uintptr(BPS)
  49268 		b = b + uintptr(BPS)
  49269 		goto _1
  49270 	_1:
  49271 		;
  49272 		y = y + 1
  49273 	}
  49274 	return count
  49275 }
  49276 
  49277 func SSE16x16_C(tls *libc.TLS, a uintptr, b uintptr) (r int32) {
  49278 	return GetSSE(tls, a, b, int32(16), int32(16))
  49279 }
  49280 
  49281 func SSE16x8_C(tls *libc.TLS, a uintptr, b uintptr) (r int32) {
  49282 	return GetSSE(tls, a, b, int32(16), int32(8))
  49283 }
  49284 
  49285 func SSE8x8_C(tls *libc.TLS, a uintptr, b uintptr) (r int32) {
  49286 	return GetSSE(tls, a, b, int32(8), int32(8))
  49287 }
  49288 
  49289 func SSE4x4_C(tls *libc.TLS, a uintptr, b uintptr) (r int32) {
  49290 	return GetSSE(tls, a, b, int32(4), int32(4))
  49291 }
  49292 
  49293 func Mean16x4_C(tls *libc.TLS, ref uintptr, dc uintptr) {
  49294 	var avg uint32_t
  49295 	var k, x, y int32
  49296 	_, _, _, _ = avg, k, x, y
  49297 	k = 0
  49298 	for {
  49299 		if !(k < int32(4)) {
  49300 			break
  49301 		}
  49302 		avg = uint32(0)
  49303 		y = 0
  49304 		for {
  49305 			if !(y < int32(4)) {
  49306 				break
  49307 			}
  49308 			x = 0
  49309 			for {
  49310 				if !(x < int32(4)) {
  49311 					break
  49312 				}
  49313 				avg = avg + uint32(**(**uint8_t)(__ccgo_up(ref + uintptr(x+y*int32(BPS)))))
  49314 				goto _3
  49315 			_3:
  49316 				;
  49317 				x = x + 1
  49318 			}
  49319 			goto _2
  49320 		_2:
  49321 			;
  49322 			y = y + 1
  49323 		}
  49324 		**(**uint32_t)(__ccgo_up(dc + uintptr(k)*4)) = avg
  49325 		ref = ref + uintptr(4) // go to next 4x4 block.
  49326 		goto _1
  49327 	_1:
  49328 		;
  49329 		k = k + 1
  49330 	}
  49331 }
  49332 
  49333 //------------------------------------------------------------------------------
  49334 // Texture distortion
  49335 //
  49336 // We try to match the spectral content (weighted) between source and
  49337 // reconstructed samples.
  49338 
  49339 // C documentation
  49340 //
  49341 //	// Hadamard transform
  49342 //	// Returns the weighted sum of the absolute value of transformed coefficients.
  49343 //	// w[] contains a row-major 4 by 4 symmetric matrix.
  49344 func TTransform(tls *libc.TLS, in uintptr, w uintptr) (r int32) {
  49345 	var a0, a01, a1, a11, a2, a21, a3, a31, b0, b1, b2, b3, i, sum int32
  49346 	var tmp [16]int32
  49347 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = a0, a01, a1, a11, a2, a21, a3, a31, b0, b1, b2, b3, i, sum, tmp
  49348 	sum = 0
  49349 	// horizontal pass
  49350 	i = 0
  49351 	for {
  49352 		if !(i < int32(4)) {
  49353 			break
  49354 		}
  49355 		a0 = int32(**(**uint8_t)(__ccgo_up(in))) + int32(**(**uint8_t)(__ccgo_up(in + 2)))
  49356 		a1 = int32(**(**uint8_t)(__ccgo_up(in + 1))) + int32(**(**uint8_t)(__ccgo_up(in + 3)))
  49357 		a2 = int32(**(**uint8_t)(__ccgo_up(in + 1))) - int32(**(**uint8_t)(__ccgo_up(in + 3)))
  49358 		a3 = int32(**(**uint8_t)(__ccgo_up(in))) - int32(**(**uint8_t)(__ccgo_up(in + 2)))
  49359 		tmp[0+i*int32(4)] = a0 + a1
  49360 		tmp[int32(1)+i*int32(4)] = a3 + a2
  49361 		tmp[int32(2)+i*int32(4)] = a3 - a2
  49362 		tmp[int32(3)+i*int32(4)] = a0 - a1
  49363 		goto _1
  49364 	_1:
  49365 		;
  49366 		i = i + 1
  49367 		in = in + uintptr(BPS)
  49368 	}
  49369 	// vertical pass
  49370 	i = 0
  49371 	for {
  49372 		if !(i < int32(4)) {
  49373 			break
  49374 		}
  49375 		a01 = tmp[0+i] + tmp[int32(8)+i]
  49376 		a11 = tmp[int32(4)+i] + tmp[int32(12)+i]
  49377 		a21 = tmp[int32(4)+i] - tmp[int32(12)+i]
  49378 		a31 = tmp[0+i] - tmp[int32(8)+i]
  49379 		b0 = a01 + a11
  49380 		b1 = a31 + a21
  49381 		b2 = a31 - a21
  49382 		b3 = a01 - a11
  49383 		sum = sum + int32(**(**uint16_t)(__ccgo_up(w)))*libc.Xabs(tls, b0)
  49384 		sum = sum + int32(**(**uint16_t)(__ccgo_up(w + 4*2)))*libc.Xabs(tls, b1)
  49385 		sum = sum + int32(**(**uint16_t)(__ccgo_up(w + 8*2)))*libc.Xabs(tls, b2)
  49386 		sum = sum + int32(**(**uint16_t)(__ccgo_up(w + 12*2)))*libc.Xabs(tls, b3)
  49387 		goto _2
  49388 	_2:
  49389 		;
  49390 		i = i + 1
  49391 		w += 2
  49392 	}
  49393 	return sum
  49394 }
  49395 
  49396 func Disto4x4_C(tls *libc.TLS, a uintptr, b uintptr, w uintptr) (r int32) {
  49397 	var sum1, sum2 int32
  49398 	_, _ = sum1, sum2
  49399 	sum1 = TTransform(tls, a, w)
  49400 	sum2 = TTransform(tls, b, w)
  49401 	return libc.Xabs(tls, sum2-sum1) >> int32(5)
  49402 }
  49403 
  49404 func Disto16x16_C(tls *libc.TLS, a uintptr, b uintptr, w uintptr) (r int32) {
  49405 	var D, x, y int32
  49406 	_, _, _ = D, x, y
  49407 	D = 0
  49408 	y = 0
  49409 	for {
  49410 		if !(y < libc.Int32FromInt32(16)*libc.Int32FromInt32(BPS)) {
  49411 			break
  49412 		}
  49413 		x = 0
  49414 		for {
  49415 			if !(x < int32(16)) {
  49416 				break
  49417 			}
  49418 			D = D + Disto4x4_C(tls, a+uintptr(x)+uintptr(y), b+uintptr(x)+uintptr(y), w)
  49419 			goto _2
  49420 		_2:
  49421 			;
  49422 			x = x + int32(4)
  49423 		}
  49424 		goto _1
  49425 	_1:
  49426 		;
  49427 		y = y + libc.Int32FromInt32(4)*libc.Int32FromInt32(BPS)
  49428 	}
  49429 	return D
  49430 }
  49431 
  49432 //------------------------------------------------------------------------------
  49433 // Quantization
  49434 //
  49435 
  49436 var kZigzag2 = [16]uint8_t{
  49437 	1:  uint8(1),
  49438 	2:  uint8(4),
  49439 	3:  uint8(8),
  49440 	4:  uint8(5),
  49441 	5:  uint8(2),
  49442 	6:  uint8(3),
  49443 	7:  uint8(6),
  49444 	8:  uint8(9),
  49445 	9:  uint8(12),
  49446 	10: uint8(13),
  49447 	11: uint8(10),
  49448 	12: uint8(7),
  49449 	13: uint8(11),
  49450 	14: uint8(14),
  49451 	15: uint8(15),
  49452 }
  49453 
  49454 // C documentation
  49455 //
  49456 //	// Simple quantization
  49457 func QuantizeBlock_C(tls *libc.TLS, in uintptr, out uintptr, mtx uintptr) (r int32) {
  49458 	var B1, Q, coeff, iQ1 uint32_t
  49459 	var j, last, level, n1, sign, v2, v3 int32
  49460 	_, _, _, _, _, _, _, _, _, _, _ = B1, Q, coeff, iQ1, j, last, level, n1, sign, v2, v3
  49461 	last = -int32(1)
  49462 	n1 = 0
  49463 	for {
  49464 		if !(n1 < int32(16)) {
  49465 			break
  49466 		}
  49467 		j = int32(kZigzag2[n1])
  49468 		sign = libc.BoolInt32(int32(**(**int16_t)(__ccgo_up(in + uintptr(j)*2))) < libc.Int32FromInt32(0))
  49469 		if sign != 0 {
  49470 			v2 = -int32(**(**int16_t)(__ccgo_up(in + uintptr(j)*2)))
  49471 		} else {
  49472 			v2 = int32(**(**int16_t)(__ccgo_up(in + uintptr(j)*2)))
  49473 		}
  49474 		coeff = uint32(v2 + int32(**(**uint16_t)(__ccgo_up(mtx + 192 + uintptr(j)*2))))
  49475 		if coeff > **(**uint32_t)(__ccgo_up(mtx + 128 + uintptr(j)*4)) {
  49476 			Q = uint32(**(**uint16_t)(__ccgo_up(mtx + uintptr(j)*2)))
  49477 			iQ1 = uint32(**(**uint16_t)(__ccgo_up(mtx + 32 + uintptr(j)*2)))
  49478 			B1 = **(**uint32_t)(__ccgo_up(mtx + 64 + uintptr(j)*4))
  49479 			v3 = int32((coeff*iQ1 + B1) >> libc.Int32FromInt32(QFIX))
  49480 			goto _4
  49481 		_4:
  49482 			level = v3
  49483 			if level > int32(MAX_LEVEL) {
  49484 				level = int32(MAX_LEVEL)
  49485 			}
  49486 			if sign != 0 {
  49487 				level = -level
  49488 			}
  49489 			**(**int16_t)(__ccgo_up(in + uintptr(j)*2)) = int16(level * int32(Q))
  49490 			**(**int16_t)(__ccgo_up(out + uintptr(n1)*2)) = int16(level)
  49491 			if level != 0 {
  49492 				last = n1
  49493 			}
  49494 		} else {
  49495 			**(**int16_t)(__ccgo_up(out + uintptr(n1)*2)) = 0
  49496 			**(**int16_t)(__ccgo_up(in + uintptr(j)*2)) = 0
  49497 		}
  49498 		goto _1
  49499 	_1:
  49500 		;
  49501 		n1 = n1 + 1
  49502 	}
  49503 	return libc.BoolInt32(last >= 0)
  49504 }
  49505 
  49506 func Quantize2Blocks_C(tls *libc.TLS, in uintptr, out uintptr, mtx uintptr) (r int32) {
  49507 	var nz int32
  49508 	_ = nz
  49509 	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
  49510 	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)
  49511 	return nz
  49512 }
  49513 
  49514 //------------------------------------------------------------------------------
  49515 // Block copy
  49516 
  49517 func Copy(tls *libc.TLS, src uintptr, dst uintptr, w int32, h int32) {
  49518 	var y int32
  49519 	_ = y
  49520 	y = 0
  49521 	for {
  49522 		if !(y < h) {
  49523 			break
  49524 		}
  49525 		libc.Xmemcpy(tls, dst, src, uint64(w))
  49526 		src = src + uintptr(BPS)
  49527 		dst = dst + uintptr(BPS)
  49528 		goto _1
  49529 	_1:
  49530 		;
  49531 		y = y + 1
  49532 	}
  49533 }
  49534 
  49535 func Copy4x4_C(tls *libc.TLS, src uintptr, dst uintptr) {
  49536 	Copy(tls, src, dst, int32(4), int32(4))
  49537 }
  49538 
  49539 func Copy16x8_C(tls *libc.TLS, src uintptr, dst uintptr) {
  49540 	Copy(tls, src, dst, int32(16), int32(8))
  49541 }
  49542 
  49543 func VP8EncDspInit(tls *libc.TLS) {
  49544 	if libc.AtomicLoadPUintptr(uintptr(unsafe.Pointer(&VP8EncDspInit_body_last_cpuinfo_used))) == VP8GetCPUInfo {
  49545 		goto _1
  49546 	}
  49547 	VP8EncDspInit_body(tls)
  49548 	libc.AtomicStorePUintptr(uintptr(unsafe.Pointer(&VP8EncDspInit_body_last_cpuinfo_used)), VP8GetCPUInfo)
  49549 	goto _2
  49550 _2:
  49551 	;
  49552 	goto _1
  49553 _1: /**/ //
  49554 }
  49555 
  49556 var VP8EncDspInit_body_last_cpuinfo_used = uintptr(0)
  49557 
  49558 func init() {
  49559 	p := unsafe.Pointer(&VP8EncDspInit_body_last_cpuinfo_used)
  49560 	*(*uintptr)(unsafe.Add(p, 0)) = uintptr(unsafe.Pointer(&VP8EncDspInit_body_last_cpuinfo_used))
  49561 }
  49562 
  49563 func VP8EncDspInit_body(tls *libc.TLS) {
  49564 	VP8DspInit(tls) // common inverse transforms
  49565 	InitTables(tls)
  49566 	// default C implementations
  49567 	VP8ITransform = __ccgo_fp(ITransform_C)
  49568 	VP8FTransform = __ccgo_fp(FTransform_C)
  49569 	VP8FTransformWHT = __ccgo_fp(FTransformWHT_C)
  49570 	VP8TDisto4x4 = __ccgo_fp(Disto4x4_C)
  49571 	VP8TDisto16x16 = __ccgo_fp(Disto16x16_C)
  49572 	VP8CollectHistogram = __ccgo_fp(CollectHistogram_C)
  49573 	VP8SSE16x16 = __ccgo_fp(SSE16x16_C)
  49574 	VP8SSE16x8 = __ccgo_fp(SSE16x8_C)
  49575 	VP8SSE8x8 = __ccgo_fp(SSE8x8_C)
  49576 	VP8SSE4x4 = __ccgo_fp(SSE4x4_C)
  49577 	VP8EncQuantizeBlock = __ccgo_fp(QuantizeBlock_C)
  49578 	VP8EncQuantize2Blocks = __ccgo_fp(Quantize2Blocks_C)
  49579 	VP8EncQuantizeBlockWHT = __ccgo_fp(QuantizeBlock_C)
  49580 	VP8EncPredLuma4 = __ccgo_fp(Intra4Preds_C)
  49581 	VP8EncPredLuma16 = __ccgo_fp(Intra16Preds_C)
  49582 	VP8FTransform2 = __ccgo_fp(FTransform2_C)
  49583 	VP8EncPredChroma8 = __ccgo_fp(IntraChromaPreds_C)
  49584 	VP8Mean16x4 = __ccgo_fp(Mean16x4_C)
  49585 	VP8Copy4x4 = __ccgo_fp(Copy4x4_C)
  49586 	VP8Copy16x8 = __ccgo_fp(Copy16x8_C)
  49587 	// If defined, use CPUInfo() to overwrite some pointers with faster versions.
  49588 	if VP8GetCPUInfo != libc.UintptrFromInt32(0) {
  49589 	}
  49590 }
  49591 
  49592 const SIZE_MAX25 = "UINT64_MAX"
  49593 
  49594 func VP8EncDspInitMIPS32(tls *libc.TLS) {
  49595 }
  49596 
  49597 func VP8EncDspInitMIPSdspR2(tls *libc.TLS) {
  49598 }
  49599 
  49600 func VP8EncDspInitMSA(tls *libc.TLS) {
  49601 }
  49602 
  49603 func VP8EncDspInitNEON(tls *libc.TLS) {
  49604 }
  49605 
  49606 func VP8EncDspInitSSE2(tls *libc.TLS) {
  49607 }
  49608 
  49609 func VP8EncDspInitSSE41(tls *libc.TLS) {
  49610 }
  49611 
  49612 const SIZE_MAX26 = "_UI64_MAX"
  49613 
  49614 // Copyright 2010 Google Inc. All Rights Reserved.
  49615 //
  49616 // Use of this source code is governed by a BSD-style license
  49617 // that can be found in the COPYING file in the root of the source
  49618 // tree. An additional intellectual property rights grant can be found
  49619 // in the file PATENTS. All contributing project authors may
  49620 // be found in the AUTHORS file in the root of the source tree.
  49621 // -----------------------------------------------------------------------------
  49622 //
  49623 //  Common types + memory wrappers
  49624 //
  49625 // Author: Skal (pascal.massimino@gmail.com)
  49626 
  49627 //------------------------------------------------------------------------------
  49628 // Helpful macro.
  49629 
  49630 func PredictLine_C(tls *libc.TLS, src uintptr, pred uintptr, dst uintptr, length int32) {
  49631 	var i int32
  49632 	_ = i
  49633 	i = 0
  49634 	for {
  49635 		if !(i < length) {
  49636 			break
  49637 		}
  49638 		**(**uint8_t)(__ccgo_up(dst + uintptr(i))) = uint8(int32(**(**uint8_t)(__ccgo_up(src + uintptr(i)))) - int32(**(**uint8_t)(__ccgo_up(pred + uintptr(i)))))
  49639 		goto _1
  49640 	_1:
  49641 		;
  49642 		i = i + 1
  49643 	}
  49644 }
  49645 
  49646 //------------------------------------------------------------------------------
  49647 // Horizontal filter.
  49648 
  49649 func DoHorizontalFilter_C(tls *libc.TLS, in uintptr, width int32, height int32, stride int32, out uintptr) {
  49650 	var preds uintptr
  49651 	var row int32
  49652 	_, _ = preds, row
  49653 	preds = in
  49654 	// Leftmost pixel is the same as input for topmost scanline.
  49655 	**(**uint8_t)(__ccgo_up(out)) = **(**uint8_t)(__ccgo_up(in))
  49656 	PredictLine_C(tls, in+uintptr(1), preds, out+uintptr(1), width-int32(1))
  49657 	preds = preds + uintptr(stride)
  49658 	in = in + uintptr(stride)
  49659 	out = out + uintptr(stride)
  49660 	// Filter line-by-line.
  49661 	row = int32(1)
  49662 	for {
  49663 		if !(row < height) {
  49664 			break
  49665 		}
  49666 		// Leftmost pixel is predicted from above.
  49667 		PredictLine_C(tls, in, preds-uintptr(stride), out, int32(1))
  49668 		PredictLine_C(tls, in+uintptr(1), preds, out+uintptr(1), width-int32(1))
  49669 		preds = preds + uintptr(stride)
  49670 		in = in + uintptr(stride)
  49671 		out = out + uintptr(stride)
  49672 		goto _1
  49673 	_1:
  49674 		;
  49675 		row = row + 1
  49676 	}
  49677 }
  49678 
  49679 //------------------------------------------------------------------------------
  49680 // Vertical filter.
  49681 
  49682 func DoVerticalFilter_C(tls *libc.TLS, in uintptr, width int32, height int32, stride int32, out uintptr) {
  49683 	var preds uintptr
  49684 	var row int32
  49685 	_, _ = preds, row
  49686 	preds = in
  49687 	// Very first top-left pixel is copied.
  49688 	**(**uint8_t)(__ccgo_up(out)) = **(**uint8_t)(__ccgo_up(in))
  49689 	// Rest of top scan-line is left-predicted.
  49690 	PredictLine_C(tls, in+uintptr(1), preds, out+uintptr(1), width-int32(1))
  49691 	in = in + uintptr(stride)
  49692 	out = out + uintptr(stride)
  49693 	// Filter line-by-line.
  49694 	row = int32(1)
  49695 	for {
  49696 		if !(row < height) {
  49697 			break
  49698 		}
  49699 		PredictLine_C(tls, in, preds, out, width)
  49700 		preds = preds + uintptr(stride)
  49701 		in = in + uintptr(stride)
  49702 		out = out + uintptr(stride)
  49703 		goto _1
  49704 	_1:
  49705 		;
  49706 		row = row + 1
  49707 	}
  49708 }
  49709 
  49710 //------------------------------------------------------------------------------
  49711 // Gradient filter.
  49712 
  49713 func GradientPredictor_C(tls *libc.TLS, a uint8_t, b uint8_t, c uint8_t) (r int32) {
  49714 	var g, v1, v2 int32
  49715 	_, _, _ = g, v1, v2
  49716 	g = int32(a) + int32(b) - int32(c)
  49717 	if g & ^libc.Int32FromInt32(0xff) == 0 {
  49718 		v1 = g
  49719 	} else {
  49720 		if g < 0 {
  49721 			v2 = 0
  49722 		} else {
  49723 			v2 = int32(255)
  49724 		}
  49725 		v1 = v2
  49726 	}
  49727 	return v1 // clip to 8bit
  49728 }
  49729 
  49730 func DoGradientFilter_C(tls *libc.TLS, in uintptr, width int32, height int32, stride int32, out uintptr) {
  49731 	var pred, row, w int32
  49732 	var preds uintptr
  49733 	_, _, _, _ = pred, preds, row, w
  49734 	preds = in
  49735 	// left prediction for top scan-line
  49736 	**(**uint8_t)(__ccgo_up(out)) = **(**uint8_t)(__ccgo_up(in))
  49737 	PredictLine_C(tls, in+uintptr(1), preds, out+uintptr(1), width-int32(1))
  49738 	preds = preds + uintptr(stride)
  49739 	in = in + uintptr(stride)
  49740 	out = out + uintptr(stride)
  49741 	// Filter line-by-line.
  49742 	row = int32(1)
  49743 	for {
  49744 		if !(row < height) {
  49745 			break
  49746 		}
  49747 		// leftmost pixel: predict from above.
  49748 		PredictLine_C(tls, in, preds-uintptr(stride), out, int32(1))
  49749 		w = int32(1)
  49750 		for {
  49751 			if !(w < width) {
  49752 				break
  49753 			}
  49754 			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)))))
  49755 			**(**uint8_t)(__ccgo_up(out + uintptr(w))) = uint8(int32(**(**uint8_t)(__ccgo_up(in + uintptr(w)))) - pred)
  49756 			goto _2
  49757 		_2:
  49758 			;
  49759 			w = w + 1
  49760 		}
  49761 		preds = preds + uintptr(stride)
  49762 		in = in + uintptr(stride)
  49763 		out = out + uintptr(stride)
  49764 		goto _1
  49765 	_1:
  49766 		;
  49767 		row = row + 1
  49768 	}
  49769 }
  49770 
  49771 //------------------------------------------------------------------------------
  49772 
  49773 func HorizontalFilter_C(tls *libc.TLS, data uintptr, width int32, height int32, stride int32, filtered_data uintptr) {
  49774 	DoHorizontalFilter_C(tls, data, width, height, stride, filtered_data)
  49775 }
  49776 
  49777 func VerticalFilter_C(tls *libc.TLS, data uintptr, width int32, height int32, stride int32, filtered_data uintptr) {
  49778 	DoVerticalFilter_C(tls, data, width, height, stride, filtered_data)
  49779 }
  49780 
  49781 func GradientFilter_C(tls *libc.TLS, data uintptr, width int32, height int32, stride int32, filtered_data uintptr) {
  49782 	DoGradientFilter_C(tls, data, width, height, stride, filtered_data)
  49783 }
  49784 
  49785 //------------------------------------------------------------------------------
  49786 
  49787 func NoneUnfilter_C(tls *libc.TLS, prev uintptr, in uintptr, out uintptr, width int32) {
  49788 	_ = prev
  49789 	if out != in {
  49790 		libc.Xmemcpy(tls, out, in, uint64(width)*uint64(1))
  49791 	}
  49792 }
  49793 
  49794 func HorizontalUnfilter_C(tls *libc.TLS, prev uintptr, in uintptr, out uintptr, width int32) {
  49795 	var i, v1 int32
  49796 	var pred uint8_t
  49797 	_, _, _ = i, pred, v1
  49798 	if prev == libc.UintptrFromInt32(0) {
  49799 		v1 = 0
  49800 	} else {
  49801 		v1 = int32(**(**uint8_t)(__ccgo_up(prev)))
  49802 	}
  49803 	pred = uint8(v1)
  49804 	i = 0
  49805 	for {
  49806 		if !(i < width) {
  49807 			break
  49808 		}
  49809 		**(**uint8_t)(__ccgo_up(out + uintptr(i))) = uint8(int32(pred) + int32(**(**uint8_t)(__ccgo_up(in + uintptr(i)))))
  49810 		pred = **(**uint8_t)(__ccgo_up(out + uintptr(i)))
  49811 		goto _2
  49812 	_2:
  49813 		;
  49814 		i = i + 1
  49815 	}
  49816 }
  49817 
  49818 func VerticalUnfilter_C(tls *libc.TLS, prev uintptr, in uintptr, out uintptr, width int32) {
  49819 	var i int32
  49820 	_ = i
  49821 	if prev == libc.UintptrFromInt32(0) {
  49822 		HorizontalUnfilter_C(tls, libc.UintptrFromInt32(0), in, out, width)
  49823 	} else {
  49824 		i = 0
  49825 		for {
  49826 			if !(i < width) {
  49827 				break
  49828 			}
  49829 			**(**uint8_t)(__ccgo_up(out + uintptr(i))) = uint8(int32(**(**uint8_t)(__ccgo_up(prev + uintptr(i)))) + int32(**(**uint8_t)(__ccgo_up(in + uintptr(i)))))
  49830 			goto _1
  49831 		_1:
  49832 			;
  49833 			i = i + 1
  49834 		}
  49835 	}
  49836 }
  49837 
  49838 func GradientUnfilter_C(tls *libc.TLS, prev uintptr, in uintptr, out uintptr, width int32) {
  49839 	var i int32
  49840 	var left, top, top_left uint8_t
  49841 	_, _, _, _ = i, left, top, top_left
  49842 	if prev == libc.UintptrFromInt32(0) {
  49843 		HorizontalUnfilter_C(tls, libc.UintptrFromInt32(0), in, out, width)
  49844 	} else {
  49845 		top = **(**uint8_t)(__ccgo_up(prev))
  49846 		top_left = top
  49847 		left = top
  49848 		i = 0
  49849 		for {
  49850 			if !(i < width) {
  49851 				break
  49852 			}
  49853 			top = **(**uint8_t)(__ccgo_up(prev + uintptr(i))) // need to read this first, in case prev==out
  49854 			left = uint8(int32(**(**uint8_t)(__ccgo_up(in + uintptr(i)))) + GradientPredictor_C(tls, left, top, top_left))
  49855 			top_left = top
  49856 			**(**uint8_t)(__ccgo_up(out + uintptr(i))) = left
  49857 			goto _1
  49858 		_1:
  49859 			;
  49860 			i = i + 1
  49861 		}
  49862 	}
  49863 }
  49864 
  49865 func VP8FiltersInit(tls *libc.TLS) {
  49866 	if libc.AtomicLoadPUintptr(uintptr(unsafe.Pointer(&VP8FiltersInit_body_last_cpuinfo_used))) == VP8GetCPUInfo {
  49867 		goto _1
  49868 	}
  49869 	VP8FiltersInit_body(tls)
  49870 	libc.AtomicStorePUintptr(uintptr(unsafe.Pointer(&VP8FiltersInit_body_last_cpuinfo_used)), VP8GetCPUInfo)
  49871 	goto _2
  49872 _2:
  49873 	;
  49874 	goto _1
  49875 _1: /**/ //
  49876 }
  49877 
  49878 var VP8FiltersInit_body_last_cpuinfo_used = uintptr(0)
  49879 
  49880 func init() {
  49881 	p := unsafe.Pointer(&VP8FiltersInit_body_last_cpuinfo_used)
  49882 	*(*uintptr)(unsafe.Add(p, 0)) = uintptr(unsafe.Pointer(&VP8FiltersInit_body_last_cpuinfo_used))
  49883 }
  49884 
  49885 func VP8FiltersInit_body(tls *libc.TLS) {
  49886 	WebPUnfilters[int32(WEBP_FILTER_NONE)] = __ccgo_fp(NoneUnfilter_C)
  49887 	WebPUnfilters[int32(WEBP_FILTER_HORIZONTAL)] = __ccgo_fp(HorizontalUnfilter_C)
  49888 	WebPUnfilters[int32(WEBP_FILTER_VERTICAL)] = __ccgo_fp(VerticalUnfilter_C)
  49889 	WebPUnfilters[int32(WEBP_FILTER_GRADIENT)] = __ccgo_fp(GradientUnfilter_C)
  49890 	WebPFilters[int32(WEBP_FILTER_NONE)] = libc.UintptrFromInt32(0)
  49891 	WebPFilters[int32(WEBP_FILTER_HORIZONTAL)] = __ccgo_fp(HorizontalFilter_C)
  49892 	WebPFilters[int32(WEBP_FILTER_VERTICAL)] = __ccgo_fp(VerticalFilter_C)
  49893 	WebPFilters[int32(WEBP_FILTER_GRADIENT)] = __ccgo_fp(GradientFilter_C)
  49894 	if VP8GetCPUInfo != libc.UintptrFromInt32(0) {
  49895 	}
  49896 }
  49897 
  49898 const SIZE_MAX27 = "UINT64_MAX"
  49899 
  49900 func VP8FiltersInitMIPSdspR2(tls *libc.TLS) {
  49901 }
  49902 
  49903 func VP8FiltersInitMSA(tls *libc.TLS) {
  49904 }
  49905 
  49906 func VP8FiltersInitNEON(tls *libc.TLS) {
  49907 }
  49908 
  49909 func VP8FiltersInitSSE2(tls *libc.TLS) {
  49910 }
  49911 
  49912 func VP8LDspInitAVX2(tls *libc.TLS) {
  49913 }
  49914 
  49915 const ARGB_BLACK3 = 4278190080
  49916 
  49917 var kHashMul15 = uint32(0x1e35a7bd)
  49918 
  49919 // Copyright 2012 Google Inc. All Rights Reserved.
  49920 //
  49921 // Use of this source code is governed by a BSD-style license
  49922 // that can be found in the COPYING file in the root of the source
  49923 // tree. An additional intellectual property rights grant can be found
  49924 // in the file PATENTS. All contributing project authors may
  49925 // be found in the AUTHORS file in the root of the source tree.
  49926 // -----------------------------------------------------------------------------
  49927 //
  49928 // Misc. common utility functions
  49929 //
  49930 // Authors: Skal (pascal.massimino@gmail.com)
  49931 //          Urvang (urvang@google.com)
  49932 
  49933 // Copyright 2010 Google Inc. All Rights Reserved.
  49934 //
  49935 // Use of this source code is governed by a BSD-style license
  49936 // that can be found in the COPYING file in the root of the source
  49937 // tree. An additional intellectual property rights grant can be found
  49938 // in the file PATENTS. All contributing project authors may
  49939 // be found in the AUTHORS file in the root of the source tree.
  49940 // -----------------------------------------------------------------------------
  49941 //
  49942 //  Main decoding functions for WebP images.
  49943 //
  49944 // Author: Skal (pascal.massimino@gmail.com)
  49945 
  49946 // Copyright 2012 Google Inc. All Rights Reserved.
  49947 //
  49948 // Use of this source code is governed by a BSD-style license
  49949 // that can be found in the COPYING file in the root of the source
  49950 // tree. An additional intellectual property rights grant can be found
  49951 // in the file PATENTS. All contributing project authors may
  49952 // be found in the AUTHORS file in the root of the source tree.
  49953 // -----------------------------------------------------------------------------
  49954 //
  49955 //  Internal header for constants related to WebP file format.
  49956 //
  49957 // Author: Urvang (urvang@google.com)
  49958 
  49959 // Copyright 2010 Google Inc. All Rights Reserved.
  49960 //
  49961 // Use of this source code is governed by a BSD-style license
  49962 // that can be found in the COPYING file in the root of the source
  49963 // tree. An additional intellectual property rights grant can be found
  49964 // in the file PATENTS. All contributing project authors may
  49965 // be found in the AUTHORS file in the root of the source tree.
  49966 // -----------------------------------------------------------------------------
  49967 //
  49968 //  Common types + memory wrappers
  49969 //
  49970 // Author: Skal (pascal.massimino@gmail.com)
  49971 
  49972 //------------------------------------------------------------------------------
  49973 // Image transforms.
  49974 
  49975 func Average2(tls *libc.TLS, a0 uint32_t, a1 uint32_t) (r uint32_t) {
  49976 	return (a0^a1)&uint32(0xfefefefe)>>int32(1) + a0&a1
  49977 }
  49978 
  49979 func Average3(tls *libc.TLS, a0 uint32_t, a1 uint32_t, a2 uint32_t) (r uint32_t) {
  49980 	return Average2(tls, Average2(tls, a0, a2), a1)
  49981 }
  49982 
  49983 func Average4(tls *libc.TLS, a0 uint32_t, a1 uint32_t, a2 uint32_t, a3 uint32_t) (r uint32_t) {
  49984 	return Average2(tls, Average2(tls, a0, a1), Average2(tls, a2, a3))
  49985 }
  49986 
  49987 func Clip255(tls *libc.TLS, a uint32_t) (r uint32_t) {
  49988 	if a < uint32(256) {
  49989 		return a
  49990 	}
  49991 	// return 0, when a is a negative integer.
  49992 	// return 255, when a is positive.
  49993 	return ^a >> int32(24)
  49994 }
  49995 
  49996 func AddSubtractComponentFull(tls *libc.TLS, a int32, b int32, c int32) (r int32) {
  49997 	return int32(Clip255(tls, uint32(a+b-c)))
  49998 }
  49999 
  50000 func ClampedAddSubtractFull(tls *libc.TLS, c0 uint32_t, c1 uint32_t, c2 uint32_t) (r1 uint32_t) {
  50001 	var a, b, g, r int32
  50002 	_, _, _, _ = a, b, g, r
  50003 	a = AddSubtractComponentFull(tls, int32(c0>>int32(24)), int32(c1>>int32(24)), int32(c2>>int32(24)))
  50004 	r = AddSubtractComponentFull(tls, int32(c0>>libc.Int32FromInt32(16)&uint32(0xff)), int32(c1>>libc.Int32FromInt32(16)&uint32(0xff)), int32(c2>>libc.Int32FromInt32(16)&uint32(0xff)))
  50005 	g = AddSubtractComponentFull(tls, int32(c0>>libc.Int32FromInt32(8)&uint32(0xff)), int32(c1>>libc.Int32FromInt32(8)&uint32(0xff)), int32(c2>>libc.Int32FromInt32(8)&uint32(0xff)))
  50006 	b = AddSubtractComponentFull(tls, int32(c0&uint32(0xff)), int32(c1&uint32(0xff)), int32(c2&uint32(0xff)))
  50007 	return uint32(a)<<libc.Int32FromInt32(24) | uint32(r<<libc.Int32FromInt32(16)) | uint32(g<<libc.Int32FromInt32(8)) | uint32(b)
  50008 }
  50009 
  50010 func AddSubtractComponentHalf(tls *libc.TLS, a int32, b int32) (r int32) {
  50011 	return int32(Clip255(tls, uint32(a+(a-b)/libc.Int32FromInt32(2))))
  50012 }
  50013 
  50014 func ClampedAddSubtractHalf(tls *libc.TLS, c0 uint32_t, c1 uint32_t, c2 uint32_t) (r1 uint32_t) {
  50015 	var a, b, g, r int32
  50016 	var ave uint32_t
  50017 	_, _, _, _, _ = a, ave, b, g, r
  50018 	ave = Average2(tls, c0, c1)
  50019 	a = AddSubtractComponentHalf(tls, int32(ave>>int32(24)), int32(c2>>int32(24)))
  50020 	r = AddSubtractComponentHalf(tls, int32(ave>>libc.Int32FromInt32(16)&uint32(0xff)), int32(c2>>libc.Int32FromInt32(16)&uint32(0xff)))
  50021 	g = AddSubtractComponentHalf(tls, int32(ave>>libc.Int32FromInt32(8)&uint32(0xff)), int32(c2>>libc.Int32FromInt32(8)&uint32(0xff)))
  50022 	b = AddSubtractComponentHalf(tls, int32(ave>>libc.Int32FromInt32(0)&uint32(0xff)), int32(c2>>libc.Int32FromInt32(0)&uint32(0xff)))
  50023 	return uint32(a)<<libc.Int32FromInt32(24) | uint32(r<<libc.Int32FromInt32(16)) | uint32(g<<libc.Int32FromInt32(8)) | uint32(b)
  50024 }
  50025 
  50026 // gcc <= 4.9 on ARM generates incorrect code in Select() when Sub3() is
  50027 // inlined.
  50028 
  50029 func Sub3(tls *libc.TLS, a int32, b int32, c int32) (r int32) {
  50030 	var pa, pb int32
  50031 	_, _ = pa, pb
  50032 	pb = b - c
  50033 	pa = a - c
  50034 	return libc.Xabs(tls, pb) - libc.Xabs(tls, pa)
  50035 }
  50036 
  50037 func Select(tls *libc.TLS, a uint32_t, b uint32_t, c uint32_t) (r uint32_t) {
  50038 	var pa_minus_pb int32
  50039 	var v1 uint32
  50040 	_, _ = pa_minus_pb, v1
  50041 	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)))
  50042 	if pa_minus_pb <= 0 {
  50043 		v1 = a
  50044 	} else {
  50045 		v1 = b
  50046 	}
  50047 	return v1
  50048 }
  50049 
  50050 //------------------------------------------------------------------------------
  50051 // Predictors
  50052 
  50053 func VP8LPredictor0_C(tls *libc.TLS, left uintptr, top uintptr) (r uint32_t) {
  50054 	_ = top
  50055 	_ = left
  50056 	return uint32(ARGB_BLACK3)
  50057 }
  50058 
  50059 func VP8LPredictor1_C(tls *libc.TLS, left uintptr, top uintptr) (r uint32_t) {
  50060 	_ = top
  50061 	return **(**uint32_t)(__ccgo_up(left))
  50062 }
  50063 
  50064 func VP8LPredictor2_C(tls *libc.TLS, left uintptr, top uintptr) (r uint32_t) {
  50065 	_ = left
  50066 	return **(**uint32_t)(__ccgo_up(top))
  50067 }
  50068 
  50069 func VP8LPredictor3_C(tls *libc.TLS, left uintptr, top uintptr) (r uint32_t) {
  50070 	_ = left
  50071 	return **(**uint32_t)(__ccgo_up(top + 1*4))
  50072 }
  50073 
  50074 func VP8LPredictor4_C(tls *libc.TLS, left uintptr, top uintptr) (r uint32_t) {
  50075 	_ = left
  50076 	return **(**uint32_t)(__ccgo_up(top + uintptr(-libc.Int32FromInt32(1))*4))
  50077 }
  50078 
  50079 func VP8LPredictor5_C(tls *libc.TLS, left uintptr, top uintptr) (r uint32_t) {
  50080 	var pred uint32_t
  50081 	_ = pred
  50082 	pred = Average3(tls, **(**uint32_t)(__ccgo_up(left)), **(**uint32_t)(__ccgo_up(top)), **(**uint32_t)(__ccgo_up(top + 1*4)))
  50083 	return pred
  50084 }
  50085 
  50086 func VP8LPredictor6_C(tls *libc.TLS, left uintptr, top uintptr) (r uint32_t) {
  50087 	var pred uint32_t
  50088 	_ = pred
  50089 	pred = Average2(tls, **(**uint32_t)(__ccgo_up(left)), **(**uint32_t)(__ccgo_up(top + uintptr(-libc.Int32FromInt32(1))*4)))
  50090 	return pred
  50091 }
  50092 
  50093 func VP8LPredictor7_C(tls *libc.TLS, left uintptr, top uintptr) (r uint32_t) {
  50094 	var pred uint32_t
  50095 	_ = pred
  50096 	pred = Average2(tls, **(**uint32_t)(__ccgo_up(left)), **(**uint32_t)(__ccgo_up(top)))
  50097 	return pred
  50098 }
  50099 
  50100 func VP8LPredictor8_C(tls *libc.TLS, left uintptr, top uintptr) (r uint32_t) {
  50101 	var pred uint32_t
  50102 	_ = pred
  50103 	pred = Average2(tls, **(**uint32_t)(__ccgo_up(top + uintptr(-libc.Int32FromInt32(1))*4)), **(**uint32_t)(__ccgo_up(top)))
  50104 	_ = left
  50105 	return pred
  50106 }
  50107 
  50108 func VP8LPredictor9_C(tls *libc.TLS, left uintptr, top uintptr) (r uint32_t) {
  50109 	var pred uint32_t
  50110 	_ = pred
  50111 	pred = Average2(tls, **(**uint32_t)(__ccgo_up(top)), **(**uint32_t)(__ccgo_up(top + 1*4)))
  50112 	_ = left
  50113 	return pred
  50114 }
  50115 
  50116 func VP8LPredictor10_C(tls *libc.TLS, left uintptr, top uintptr) (r uint32_t) {
  50117 	var pred uint32_t
  50118 	_ = pred
  50119 	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)))
  50120 	return pred
  50121 }
  50122 
  50123 func VP8LPredictor11_C(tls *libc.TLS, left uintptr, top uintptr) (r uint32_t) {
  50124 	var pred uint32_t
  50125 	_ = pred
  50126 	pred = Select(tls, **(**uint32_t)(__ccgo_up(top)), **(**uint32_t)(__ccgo_up(left)), **(**uint32_t)(__ccgo_up(top + uintptr(-libc.Int32FromInt32(1))*4)))
  50127 	return pred
  50128 }
  50129 
  50130 func VP8LPredictor12_C(tls *libc.TLS, left uintptr, top uintptr) (r uint32_t) {
  50131 	var pred uint32_t
  50132 	_ = pred
  50133 	pred = ClampedAddSubtractFull(tls, **(**uint32_t)(__ccgo_up(left)), **(**uint32_t)(__ccgo_up(top)), **(**uint32_t)(__ccgo_up(top + uintptr(-libc.Int32FromInt32(1))*4)))
  50134 	return pred
  50135 }
  50136 
  50137 func VP8LPredictor13_C(tls *libc.TLS, left uintptr, top uintptr) (r uint32_t) {
  50138 	var pred uint32_t
  50139 	_ = pred
  50140 	pred = ClampedAddSubtractHalf(tls, **(**uint32_t)(__ccgo_up(left)), **(**uint32_t)(__ccgo_up(top)), **(**uint32_t)(__ccgo_up(top + uintptr(-libc.Int32FromInt32(1))*4)))
  50141 	return pred
  50142 }
  50143 
  50144 func PredictorAdd0_C(tls *libc.TLS, in uintptr, upper uintptr, num_pixels int32, out uintptr) {
  50145 	var alpha_and_green, red_and_blue, v2, v3, v4 uint32_t
  50146 	var x int32
  50147 	_, _, _, _, _, _ = alpha_and_green, red_and_blue, x, v2, v3, v4
  50148 	_ = upper
  50149 	x = 0
  50150 	for {
  50151 		if !(x < num_pixels) {
  50152 			break
  50153 		}
  50154 		v2 = **(**uint32_t)(__ccgo_up(in + uintptr(x)*4))
  50155 		v3 = uint32(ARGB_BLACK3)
  50156 		alpha_and_green = v2&uint32(0xff00ff00) + v3&uint32(0xff00ff00)
  50157 		red_and_blue = v2&uint32(0x00ff00ff) + v3&uint32(0x00ff00ff)
  50158 		v4 = alpha_and_green&uint32(0xff00ff00) | red_and_blue&uint32(0x00ff00ff)
  50159 		goto _5
  50160 	_5:
  50161 		**(**uint32_t)(__ccgo_up(out + uintptr(x)*4)) = v4
  50162 		goto _1
  50163 	_1:
  50164 		;
  50165 		x = x + 1
  50166 	}
  50167 }
  50168 
  50169 func PredictorAdd1_C(tls *libc.TLS, in uintptr, upper uintptr, num_pixels int32, out uintptr) {
  50170 	var alpha_and_green, left, red_and_blue, v2, v3, v4, v5 uint32_t
  50171 	var i int32
  50172 	_, _, _, _, _, _, _, _ = alpha_and_green, i, left, red_and_blue, v2, v3, v4, v5
  50173 	left = **(**uint32_t)(__ccgo_up(out + uintptr(-libc.Int32FromInt32(1))*4))
  50174 	_ = upper
  50175 	i = 0
  50176 	for {
  50177 		if !(i < num_pixels) {
  50178 			break
  50179 		}
  50180 		v3 = **(**uint32_t)(__ccgo_up(in + uintptr(i)*4))
  50181 		v4 = left
  50182 		alpha_and_green = v3&uint32(0xff00ff00) + v4&uint32(0xff00ff00)
  50183 		red_and_blue = v3&uint32(0x00ff00ff) + v4&uint32(0x00ff00ff)
  50184 		v5 = alpha_and_green&uint32(0xff00ff00) | red_and_blue&uint32(0x00ff00ff)
  50185 		goto _6
  50186 	_6:
  50187 		v2 = v5
  50188 		left = v2
  50189 		**(**uint32_t)(__ccgo_up(out + uintptr(i)*4)) = v2
  50190 		goto _1
  50191 	_1:
  50192 		;
  50193 		i = i + 1
  50194 	}
  50195 }
  50196 
  50197 func PredictorAdd2_C(tls *libc.TLS, in uintptr, upper uintptr, num_pixels int32, out uintptr) {
  50198 	var alpha_and_green, pred, red_and_blue, v2, v3, v4 uint32_t
  50199 	var x int32
  50200 	_, _, _, _, _, _, _ = alpha_and_green, pred, red_and_blue, x, v2, v3, v4
  50201 	x = 0
  50202 	for {
  50203 		if !(x < num_pixels) {
  50204 			break
  50205 		}
  50206 		pred = VP8LPredictor2_C(tls, out+uintptr(x-int32(1))*4, upper+uintptr(x)*4)
  50207 		v2 = **(**uint32_t)(__ccgo_up(in + uintptr(x)*4))
  50208 		v3 = pred
  50209 		alpha_and_green = v2&uint32(0xff00ff00) + v3&uint32(0xff00ff00)
  50210 		red_and_blue = v2&uint32(0x00ff00ff) + v3&uint32(0x00ff00ff)
  50211 		v4 = alpha_and_green&uint32(0xff00ff00) | red_and_blue&uint32(0x00ff00ff)
  50212 		goto _5
  50213 	_5:
  50214 		**(**uint32_t)(__ccgo_up(out + uintptr(x)*4)) = v4
  50215 		goto _1
  50216 	_1:
  50217 		;
  50218 		x = x + 1
  50219 	}
  50220 }
  50221 
  50222 func PredictorAdd3_C(tls *libc.TLS, in uintptr, upper uintptr, num_pixels int32, out uintptr) {
  50223 	var alpha_and_green, pred, red_and_blue, v2, v3, v4 uint32_t
  50224 	var x int32
  50225 	_, _, _, _, _, _, _ = alpha_and_green, pred, red_and_blue, x, v2, v3, v4
  50226 	x = 0
  50227 	for {
  50228 		if !(x < num_pixels) {
  50229 			break
  50230 		}
  50231 		pred = VP8LPredictor3_C(tls, out+uintptr(x-int32(1))*4, upper+uintptr(x)*4)
  50232 		v2 = **(**uint32_t)(__ccgo_up(in + uintptr(x)*4))
  50233 		v3 = pred
  50234 		alpha_and_green = v2&uint32(0xff00ff00) + v3&uint32(0xff00ff00)
  50235 		red_and_blue = v2&uint32(0x00ff00ff) + v3&uint32(0x00ff00ff)
  50236 		v4 = alpha_and_green&uint32(0xff00ff00) | red_and_blue&uint32(0x00ff00ff)
  50237 		goto _5
  50238 	_5:
  50239 		**(**uint32_t)(__ccgo_up(out + uintptr(x)*4)) = v4
  50240 		goto _1
  50241 	_1:
  50242 		;
  50243 		x = x + 1
  50244 	}
  50245 }
  50246 
  50247 func PredictorAdd4_C(tls *libc.TLS, in uintptr, upper uintptr, num_pixels int32, out uintptr) {
  50248 	var alpha_and_green, pred, red_and_blue, v2, v3, v4 uint32_t
  50249 	var x int32
  50250 	_, _, _, _, _, _, _ = alpha_and_green, pred, red_and_blue, x, v2, v3, v4
  50251 	x = 0
  50252 	for {
  50253 		if !(x < num_pixels) {
  50254 			break
  50255 		}
  50256 		pred = VP8LPredictor4_C(tls, out+uintptr(x-int32(1))*4, upper+uintptr(x)*4)
  50257 		v2 = **(**uint32_t)(__ccgo_up(in + uintptr(x)*4))
  50258 		v3 = pred
  50259 		alpha_and_green = v2&uint32(0xff00ff00) + v3&uint32(0xff00ff00)
  50260 		red_and_blue = v2&uint32(0x00ff00ff) + v3&uint32(0x00ff00ff)
  50261 		v4 = alpha_and_green&uint32(0xff00ff00) | red_and_blue&uint32(0x00ff00ff)
  50262 		goto _5
  50263 	_5:
  50264 		**(**uint32_t)(__ccgo_up(out + uintptr(x)*4)) = v4
  50265 		goto _1
  50266 	_1:
  50267 		;
  50268 		x = x + 1
  50269 	}
  50270 }
  50271 
  50272 func PredictorAdd5_C(tls *libc.TLS, in uintptr, upper uintptr, num_pixels int32, out uintptr) {
  50273 	var alpha_and_green, pred, red_and_blue, v2, v3, v4 uint32_t
  50274 	var x int32
  50275 	_, _, _, _, _, _, _ = alpha_and_green, pred, red_and_blue, x, v2, v3, v4
  50276 	x = 0
  50277 	for {
  50278 		if !(x < num_pixels) {
  50279 			break
  50280 		}
  50281 		pred = VP8LPredictor5_C(tls, out+uintptr(x-int32(1))*4, upper+uintptr(x)*4)
  50282 		v2 = **(**uint32_t)(__ccgo_up(in + uintptr(x)*4))
  50283 		v3 = pred
  50284 		alpha_and_green = v2&uint32(0xff00ff00) + v3&uint32(0xff00ff00)
  50285 		red_and_blue = v2&uint32(0x00ff00ff) + v3&uint32(0x00ff00ff)
  50286 		v4 = alpha_and_green&uint32(0xff00ff00) | red_and_blue&uint32(0x00ff00ff)
  50287 		goto _5
  50288 	_5:
  50289 		**(**uint32_t)(__ccgo_up(out + uintptr(x)*4)) = v4
  50290 		goto _1
  50291 	_1:
  50292 		;
  50293 		x = x + 1
  50294 	}
  50295 }
  50296 
  50297 func PredictorAdd6_C(tls *libc.TLS, in uintptr, upper uintptr, num_pixels int32, out uintptr) {
  50298 	var alpha_and_green, pred, red_and_blue, v2, v3, v4 uint32_t
  50299 	var x int32
  50300 	_, _, _, _, _, _, _ = alpha_and_green, pred, red_and_blue, x, v2, v3, v4
  50301 	x = 0
  50302 	for {
  50303 		if !(x < num_pixels) {
  50304 			break
  50305 		}
  50306 		pred = VP8LPredictor6_C(tls, out+uintptr(x-int32(1))*4, upper+uintptr(x)*4)
  50307 		v2 = **(**uint32_t)(__ccgo_up(in + uintptr(x)*4))
  50308 		v3 = pred
  50309 		alpha_and_green = v2&uint32(0xff00ff00) + v3&uint32(0xff00ff00)
  50310 		red_and_blue = v2&uint32(0x00ff00ff) + v3&uint32(0x00ff00ff)
  50311 		v4 = alpha_and_green&uint32(0xff00ff00) | red_and_blue&uint32(0x00ff00ff)
  50312 		goto _5
  50313 	_5:
  50314 		**(**uint32_t)(__ccgo_up(out + uintptr(x)*4)) = v4
  50315 		goto _1
  50316 	_1:
  50317 		;
  50318 		x = x + 1
  50319 	}
  50320 }
  50321 
  50322 func PredictorAdd7_C(tls *libc.TLS, in uintptr, upper uintptr, num_pixels int32, out uintptr) {
  50323 	var alpha_and_green, pred, red_and_blue, v2, v3, v4 uint32_t
  50324 	var x int32
  50325 	_, _, _, _, _, _, _ = alpha_and_green, pred, red_and_blue, x, v2, v3, v4
  50326 	x = 0
  50327 	for {
  50328 		if !(x < num_pixels) {
  50329 			break
  50330 		}
  50331 		pred = VP8LPredictor7_C(tls, out+uintptr(x-int32(1))*4, upper+uintptr(x)*4)
  50332 		v2 = **(**uint32_t)(__ccgo_up(in + uintptr(x)*4))
  50333 		v3 = pred
  50334 		alpha_and_green = v2&uint32(0xff00ff00) + v3&uint32(0xff00ff00)
  50335 		red_and_blue = v2&uint32(0x00ff00ff) + v3&uint32(0x00ff00ff)
  50336 		v4 = alpha_and_green&uint32(0xff00ff00) | red_and_blue&uint32(0x00ff00ff)
  50337 		goto _5
  50338 	_5:
  50339 		**(**uint32_t)(__ccgo_up(out + uintptr(x)*4)) = v4
  50340 		goto _1
  50341 	_1:
  50342 		;
  50343 		x = x + 1
  50344 	}
  50345 }
  50346 
  50347 func PredictorAdd8_C(tls *libc.TLS, in uintptr, upper uintptr, num_pixels int32, out uintptr) {
  50348 	var alpha_and_green, pred, red_and_blue, v2, v3, v4 uint32_t
  50349 	var x int32
  50350 	_, _, _, _, _, _, _ = alpha_and_green, pred, red_and_blue, x, v2, v3, v4
  50351 	x = 0
  50352 	for {
  50353 		if !(x < num_pixels) {
  50354 			break
  50355 		}
  50356 		pred = VP8LPredictor8_C(tls, out+uintptr(x-int32(1))*4, upper+uintptr(x)*4)
  50357 		v2 = **(**uint32_t)(__ccgo_up(in + uintptr(x)*4))
  50358 		v3 = pred
  50359 		alpha_and_green = v2&uint32(0xff00ff00) + v3&uint32(0xff00ff00)
  50360 		red_and_blue = v2&uint32(0x00ff00ff) + v3&uint32(0x00ff00ff)
  50361 		v4 = alpha_and_green&uint32(0xff00ff00) | red_and_blue&uint32(0x00ff00ff)
  50362 		goto _5
  50363 	_5:
  50364 		**(**uint32_t)(__ccgo_up(out + uintptr(x)*4)) = v4
  50365 		goto _1
  50366 	_1:
  50367 		;
  50368 		x = x + 1
  50369 	}
  50370 }
  50371 
  50372 func PredictorAdd9_C(tls *libc.TLS, in uintptr, upper uintptr, num_pixels int32, out uintptr) {
  50373 	var alpha_and_green, pred, red_and_blue, v2, v3, v4 uint32_t
  50374 	var x int32
  50375 	_, _, _, _, _, _, _ = alpha_and_green, pred, red_and_blue, x, v2, v3, v4
  50376 	x = 0
  50377 	for {
  50378 		if !(x < num_pixels) {
  50379 			break
  50380 		}
  50381 		pred = VP8LPredictor9_C(tls, out+uintptr(x-int32(1))*4, upper+uintptr(x)*4)
  50382 		v2 = **(**uint32_t)(__ccgo_up(in + uintptr(x)*4))
  50383 		v3 = pred
  50384 		alpha_and_green = v2&uint32(0xff00ff00) + v3&uint32(0xff00ff00)
  50385 		red_and_blue = v2&uint32(0x00ff00ff) + v3&uint32(0x00ff00ff)
  50386 		v4 = alpha_and_green&uint32(0xff00ff00) | red_and_blue&uint32(0x00ff00ff)
  50387 		goto _5
  50388 	_5:
  50389 		**(**uint32_t)(__ccgo_up(out + uintptr(x)*4)) = v4
  50390 		goto _1
  50391 	_1:
  50392 		;
  50393 		x = x + 1
  50394 	}
  50395 }
  50396 
  50397 func PredictorAdd10_C(tls *libc.TLS, in uintptr, upper uintptr, num_pixels int32, out uintptr) {
  50398 	var alpha_and_green, pred, red_and_blue, v2, v3, v4 uint32_t
  50399 	var x int32
  50400 	_, _, _, _, _, _, _ = alpha_and_green, pred, red_and_blue, x, v2, v3, v4
  50401 	x = 0
  50402 	for {
  50403 		if !(x < num_pixels) {
  50404 			break
  50405 		}
  50406 		pred = VP8LPredictor10_C(tls, out+uintptr(x-int32(1))*4, upper+uintptr(x)*4)
  50407 		v2 = **(**uint32_t)(__ccgo_up(in + uintptr(x)*4))
  50408 		v3 = pred
  50409 		alpha_and_green = v2&uint32(0xff00ff00) + v3&uint32(0xff00ff00)
  50410 		red_and_blue = v2&uint32(0x00ff00ff) + v3&uint32(0x00ff00ff)
  50411 		v4 = alpha_and_green&uint32(0xff00ff00) | red_and_blue&uint32(0x00ff00ff)
  50412 		goto _5
  50413 	_5:
  50414 		**(**uint32_t)(__ccgo_up(out + uintptr(x)*4)) = v4
  50415 		goto _1
  50416 	_1:
  50417 		;
  50418 		x = x + 1
  50419 	}
  50420 }
  50421 
  50422 func PredictorAdd11_C(tls *libc.TLS, in uintptr, upper uintptr, num_pixels int32, out uintptr) {
  50423 	var alpha_and_green, pred, red_and_blue, v2, v3, v4 uint32_t
  50424 	var x int32
  50425 	_, _, _, _, _, _, _ = alpha_and_green, pred, red_and_blue, x, v2, v3, v4
  50426 	x = 0
  50427 	for {
  50428 		if !(x < num_pixels) {
  50429 			break
  50430 		}
  50431 		pred = VP8LPredictor11_C(tls, out+uintptr(x-int32(1))*4, upper+uintptr(x)*4)
  50432 		v2 = **(**uint32_t)(__ccgo_up(in + uintptr(x)*4))
  50433 		v3 = pred
  50434 		alpha_and_green = v2&uint32(0xff00ff00) + v3&uint32(0xff00ff00)
  50435 		red_and_blue = v2&uint32(0x00ff00ff) + v3&uint32(0x00ff00ff)
  50436 		v4 = alpha_and_green&uint32(0xff00ff00) | red_and_blue&uint32(0x00ff00ff)
  50437 		goto _5
  50438 	_5:
  50439 		**(**uint32_t)(__ccgo_up(out + uintptr(x)*4)) = v4
  50440 		goto _1
  50441 	_1:
  50442 		;
  50443 		x = x + 1
  50444 	}
  50445 }
  50446 
  50447 func PredictorAdd12_C(tls *libc.TLS, in uintptr, upper uintptr, num_pixels int32, out uintptr) {
  50448 	var alpha_and_green, pred, red_and_blue, v2, v3, v4 uint32_t
  50449 	var x int32
  50450 	_, _, _, _, _, _, _ = alpha_and_green, pred, red_and_blue, x, v2, v3, v4
  50451 	x = 0
  50452 	for {
  50453 		if !(x < num_pixels) {
  50454 			break
  50455 		}
  50456 		pred = VP8LPredictor12_C(tls, out+uintptr(x-int32(1))*4, upper+uintptr(x)*4)
  50457 		v2 = **(**uint32_t)(__ccgo_up(in + uintptr(x)*4))
  50458 		v3 = pred
  50459 		alpha_and_green = v2&uint32(0xff00ff00) + v3&uint32(0xff00ff00)
  50460 		red_and_blue = v2&uint32(0x00ff00ff) + v3&uint32(0x00ff00ff)
  50461 		v4 = alpha_and_green&uint32(0xff00ff00) | red_and_blue&uint32(0x00ff00ff)
  50462 		goto _5
  50463 	_5:
  50464 		**(**uint32_t)(__ccgo_up(out + uintptr(x)*4)) = v4
  50465 		goto _1
  50466 	_1:
  50467 		;
  50468 		x = x + 1
  50469 	}
  50470 }
  50471 
  50472 func PredictorAdd13_C(tls *libc.TLS, in uintptr, upper uintptr, num_pixels int32, out uintptr) {
  50473 	var alpha_and_green, pred, red_and_blue, v2, v3, v4 uint32_t
  50474 	var x int32
  50475 	_, _, _, _, _, _, _ = alpha_and_green, pred, red_and_blue, x, v2, v3, v4
  50476 	x = 0
  50477 	for {
  50478 		if !(x < num_pixels) {
  50479 			break
  50480 		}
  50481 		pred = VP8LPredictor13_C(tls, out+uintptr(x-int32(1))*4, upper+uintptr(x)*4)
  50482 		v2 = **(**uint32_t)(__ccgo_up(in + uintptr(x)*4))
  50483 		v3 = pred
  50484 		alpha_and_green = v2&uint32(0xff00ff00) + v3&uint32(0xff00ff00)
  50485 		red_and_blue = v2&uint32(0x00ff00ff) + v3&uint32(0x00ff00ff)
  50486 		v4 = alpha_and_green&uint32(0xff00ff00) | red_and_blue&uint32(0x00ff00ff)
  50487 		goto _5
  50488 	_5:
  50489 		**(**uint32_t)(__ccgo_up(out + uintptr(x)*4)) = v4
  50490 		goto _1
  50491 	_1:
  50492 		;
  50493 		x = x + 1
  50494 	}
  50495 }
  50496 
  50497 //------------------------------------------------------------------------------
  50498 
  50499 // C documentation
  50500 //
  50501 //	// Inverse prediction.
  50502 func PredictorInverseTransform_C(tls *libc.TLS, transform uintptr, y_start int32, y_end int32, in uintptr, out uintptr) {
  50503 	var mask, tile_width, tiles_per_row, width, x, x_end, y int32
  50504 	var pred_func VP8LPredictorAddSubFunc
  50505 	var pred_mode_base, pred_mode_src, v4 uintptr
  50506 	var v1, v2 uint32_t
  50507 	_, _, _, _, _, _, _, _, _, _, _, _, _ = mask, pred_func, pred_mode_base, pred_mode_src, tile_width, tiles_per_row, width, x, x_end, y, v1, v2, v4
  50508 	width = (*VP8LTransform)(unsafe.Pointer(transform)).Fxsize
  50509 	if y_start == 0 { // First Row follows the L (mode=1) mode.
  50510 		PredictorAdd0_C(tls, in, libc.UintptrFromInt32(0), int32(1), out)
  50511 		PredictorAdd1_C(tls, in+uintptr(1)*4, libc.UintptrFromInt32(0), width-int32(1), out+uintptr(1)*4)
  50512 		in = in + uintptr(width)*4
  50513 		out = out + uintptr(width)*4
  50514 		y_start = y_start + 1
  50515 	}
  50516 	y = y_start
  50517 	tile_width = int32(1) << (*VP8LTransform)(unsafe.Pointer(transform)).Fbits
  50518 	mask = tile_width - int32(1)
  50519 	v1 = uint32((*VP8LTransform)(unsafe.Pointer(transform)).Fbits)
  50520 	v2 = (uint32(width) + uint32(libc.Int32FromInt32(1)<<v1) - uint32(1)) >> v1
  50521 	goto _3
  50522 _3:
  50523 	tiles_per_row = int32(v2)
  50524 	pred_mode_base = (*VP8LTransform)(unsafe.Pointer(transform)).Fdata + uintptr(y>>(*VP8LTransform)(unsafe.Pointer(transform)).Fbits*tiles_per_row)*4
  50525 	for y < y_end {
  50526 		pred_mode_src = pred_mode_base
  50527 		x = int32(1)
  50528 		// First pixel follows the T (mode=2) mode.
  50529 		PredictorAdd2_C(tls, in, out-uintptr(width)*4, int32(1), out)
  50530 		// .. the rest:
  50531 		for x < width {
  50532 			v4 = pred_mode_src
  50533 			pred_mode_src += 4
  50534 			pred_func = VP8LPredictorsAdd[**(**uint32_t)(__ccgo_up(v4))>>libc.Int32FromInt32(8)&uint32(0xf)]
  50535 			x_end = x & ^mask + tile_width
  50536 			if x_end > width {
  50537 				x_end = width
  50538 			}
  50539 			(*(*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)
  50540 			x = x_end
  50541 		}
  50542 		in = in + uintptr(width)*4
  50543 		out = out + uintptr(width)*4
  50544 		y = y + 1
  50545 		if y&mask == 0 { // Use the same mask, since tiles are squares.
  50546 			pred_mode_base = pred_mode_base + uintptr(tiles_per_row)*4
  50547 		}
  50548 	}
  50549 }
  50550 
  50551 // C documentation
  50552 //
  50553 //	// Add green to blue and red channels (i.e. perform the inverse transform of
  50554 //	// 'subtract green').
  50555 func VP8LAddGreenToBlueAndRed_C(tls *libc.TLS, src uintptr, num_pixels int32, dst uintptr) {
  50556 	var argb, green, red_blue uint32_t
  50557 	var i int32
  50558 	_, _, _, _ = argb, green, i, red_blue
  50559 	i = 0
  50560 	for {
  50561 		if !(i < num_pixels) {
  50562 			break
  50563 		}
  50564 		argb = **(**uint32_t)(__ccgo_up(src + uintptr(i)*4))
  50565 		green = argb >> libc.Int32FromInt32(8) & libc.Uint32FromInt32(0xff)
  50566 		red_blue = argb & libc.Uint32FromUint32(0x00ff00ff)
  50567 		red_blue = red_blue + (green<<libc.Int32FromInt32(16) | green)
  50568 		red_blue = red_blue & uint32(0x00ff00ff)
  50569 		**(**uint32_t)(__ccgo_up(dst + uintptr(i)*4)) = argb&uint32(0xff00ff00) | red_blue
  50570 		goto _1
  50571 	_1:
  50572 		;
  50573 		i = i + 1
  50574 	}
  50575 }
  50576 
  50577 func ColorTransformDelta(tls *libc.TLS, color_pred int8_t, color int8_t) (r int32) {
  50578 	return int32(color_pred) * int32(color) >> int32(5)
  50579 }
  50580 
  50581 func ColorCodeToMultipliers1(tls *libc.TLS, color_code uint32_t, m uintptr) {
  50582 	(*VP8LMultipliers)(unsafe.Pointer(m)).Fgreen_to_red = uint8(color_code >> libc.Int32FromInt32(0) & uint32(0xff))
  50583 	(*VP8LMultipliers)(unsafe.Pointer(m)).Fgreen_to_blue = uint8(color_code >> libc.Int32FromInt32(8) & uint32(0xff))
  50584 	(*VP8LMultipliers)(unsafe.Pointer(m)).Fred_to_blue = uint8(color_code >> libc.Int32FromInt32(16) & uint32(0xff))
  50585 }
  50586 
  50587 func VP8LTransformColorInverse_C(tls *libc.TLS, m uintptr, src uintptr, num_pixels int32, dst uintptr) {
  50588 	var argb, red uint32_t
  50589 	var green int8_t
  50590 	var i, new_blue, new_red int32
  50591 	_, _, _, _, _, _ = argb, green, i, new_blue, new_red, red
  50592 	i = 0
  50593 	for {
  50594 		if !(i < num_pixels) {
  50595 			break
  50596 		}
  50597 		argb = **(**uint32_t)(__ccgo_up(src + uintptr(i)*4))
  50598 		green = int8(argb >> libc.Int32FromInt32(8))
  50599 		red = argb >> int32(16)
  50600 		new_red = int32(red & uint32(0xff))
  50601 		new_blue = int32(argb & uint32(0xff))
  50602 		new_red = new_red + ColorTransformDelta(tls, int8((*VP8LMultipliers)(unsafe.Pointer(m)).Fgreen_to_red), green)
  50603 		new_red = new_red & int32(0xff)
  50604 		new_blue = new_blue + ColorTransformDelta(tls, int8((*VP8LMultipliers)(unsafe.Pointer(m)).Fgreen_to_blue), green)
  50605 		new_blue = new_blue + ColorTransformDelta(tls, int8((*VP8LMultipliers)(unsafe.Pointer(m)).Fred_to_blue), int8(new_red))
  50606 		new_blue = new_blue & int32(0xff)
  50607 		**(**uint32_t)(__ccgo_up(dst + uintptr(i)*4)) = argb&uint32(0xff00ff00) | uint32(new_red<<libc.Int32FromInt32(16)) | uint32(new_blue)
  50608 		goto _1
  50609 	_1:
  50610 		;
  50611 		i = i + 1
  50612 	}
  50613 }
  50614 
  50615 // C documentation
  50616 //
  50617 //	// Color space inverse transform.
  50618 func ColorSpaceInverseTransform_C(tls *libc.TLS, transform uintptr, y_start int32, y_end int32, src uintptr, dst uintptr) {
  50619 	bp := tls.Alloc(16)
  50620 	defer tls.Free(16)
  50621 	var mask, remaining_width, safe_width, tile_width, tiles_per_row, width, y int32
  50622 	var pred, pred_row, src_end, src_safe_end, v4 uintptr
  50623 	var v1, v2 uint32_t
  50624 	var _ /* m at bp+0 */ VP8LMultipliers
  50625 	_, _, _, _, _, _, _, _, _, _, _, _, _, _ = mask, pred, pred_row, remaining_width, safe_width, src_end, src_safe_end, tile_width, tiles_per_row, width, y, v1, v2, v4
  50626 	width = (*VP8LTransform)(unsafe.Pointer(transform)).Fxsize
  50627 	tile_width = int32(1) << (*VP8LTransform)(unsafe.Pointer(transform)).Fbits
  50628 	mask = tile_width - int32(1)
  50629 	safe_width = width & ^mask
  50630 	remaining_width = width - safe_width
  50631 	v1 = uint32((*VP8LTransform)(unsafe.Pointer(transform)).Fbits)
  50632 	v2 = (uint32(width) + uint32(libc.Int32FromInt32(1)<<v1) - uint32(1)) >> v1
  50633 	goto _3
  50634 _3:
  50635 	tiles_per_row = int32(v2)
  50636 	y = y_start
  50637 	pred_row = (*VP8LTransform)(unsafe.Pointer(transform)).Fdata + uintptr(y>>(*VP8LTransform)(unsafe.Pointer(transform)).Fbits*tiles_per_row)*4
  50638 	for y < y_end {
  50639 		pred = pred_row
  50640 		**(**VP8LMultipliers)(__ccgo_up(bp)) = VP8LMultipliers{}
  50641 		src_safe_end = src + uintptr(safe_width)*4
  50642 		src_end = src + uintptr(width)*4
  50643 		for src < src_safe_end {
  50644 			v4 = pred
  50645 			pred += 4
  50646 			ColorCodeToMultipliers1(tls, **(**uint32_t)(__ccgo_up(v4)), bp)
  50647 			(*(*func(*libc.TLS, uintptr, uintptr, int32, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8LTransformColorInverse})))(tls, bp, src, tile_width, dst)
  50648 			src = src + uintptr(tile_width)*4
  50649 			dst = dst + uintptr(tile_width)*4
  50650 		}
  50651 		if src < src_end { // Left-overs using C-version.
  50652 			v4 = pred
  50653 			pred += 4
  50654 			ColorCodeToMultipliers1(tls, **(**uint32_t)(__ccgo_up(v4)), bp)
  50655 			(*(*func(*libc.TLS, uintptr, uintptr, int32, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8LTransformColorInverse})))(tls, bp, src, remaining_width, dst)
  50656 			src = src + uintptr(remaining_width)*4
  50657 			dst = dst + uintptr(remaining_width)*4
  50658 		}
  50659 		y = y + 1
  50660 		if y&mask == 0 {
  50661 			pred_row = pred_row + uintptr(tiles_per_row)*4
  50662 		}
  50663 	}
  50664 }
  50665 
  50666 // Separate out pixels packed together using pixel-bundling.
  50667 // We define two methods for ARGB data (uint32_t) and alpha-only data (uint8_t).
  50668 func MapARGB_C(tls *libc.TLS, src uintptr, color_map uintptr, dst uintptr, y_start int32, y_end int32, width int32) {
  50669 	var x, y int32
  50670 	var v3, v4 uintptr
  50671 	var v5, v7 uint32_t
  50672 	_, _, _, _, _, _ = x, y, v3, v4, v5, v7
  50673 	y = y_start
  50674 	for {
  50675 		if !(y < y_end) {
  50676 			break
  50677 		}
  50678 		x = 0
  50679 		for {
  50680 			if !(x < width) {
  50681 				break
  50682 			}
  50683 			v3 = dst
  50684 			dst += 4
  50685 			v4 = src
  50686 			src += 4
  50687 			v5 = **(**uint32_t)(__ccgo_up(v4)) >> libc.Int32FromInt32(8) & uint32(0xff)
  50688 			goto _6
  50689 		_6:
  50690 			v7 = **(**uint32_t)(__ccgo_up(color_map + uintptr(v5)*4))
  50691 			goto _8
  50692 		_8:
  50693 			**(**uint32_t)(__ccgo_up(v3)) = v7
  50694 			goto _2
  50695 		_2:
  50696 			;
  50697 			x = x + 1
  50698 		}
  50699 		goto _1
  50700 	_1:
  50701 		;
  50702 		y = y + 1
  50703 	}
  50704 }
  50705 
  50706 func ColorIndexInverseTransform_C(tls *libc.TLS, transform uintptr, y_start int32, y_end int32, src uintptr, dst uintptr) {
  50707 	var bit_mask, packed_pixels, v4 uint32_t
  50708 	var bits_per_pixel, count_mask, pixels_per_byte, width, x, y int32
  50709 	var color_map, v3 uintptr
  50710 	_, _, _, _, _, _, _, _, _, _, _ = bit_mask, bits_per_pixel, color_map, count_mask, packed_pixels, pixels_per_byte, width, x, y, v3, v4
  50711 	bits_per_pixel = int32(8) >> (*VP8LTransform)(unsafe.Pointer(transform)).Fbits
  50712 	width = (*VP8LTransform)(unsafe.Pointer(transform)).Fxsize
  50713 	color_map = (*VP8LTransform)(unsafe.Pointer(transform)).Fdata
  50714 	if bits_per_pixel < int32(8) {
  50715 		pixels_per_byte = int32(1) << (*VP8LTransform)(unsafe.Pointer(transform)).Fbits
  50716 		count_mask = pixels_per_byte - int32(1)
  50717 		bit_mask = uint32(int32(1)<<bits_per_pixel - int32(1))
  50718 		y = y_start
  50719 		for {
  50720 			if !(y < y_end) {
  50721 				break
  50722 			}
  50723 			packed_pixels = uint32(0)
  50724 			x = 0
  50725 			for {
  50726 				if !(x < width) {
  50727 					break
  50728 				} /* 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.                                         */
  50729 				if x&count_mask == 0 {
  50730 					v3 = src
  50731 					src += 4
  50732 					v4 = **(**uint32_t)(__ccgo_up(v3)) >> libc.Int32FromInt32(8) & uint32(0xff)
  50733 					goto _5
  50734 				_5:
  50735 					packed_pixels = v4
  50736 				}
  50737 				v3 = dst
  50738 				dst += 4
  50739 				v4 = **(**uint32_t)(__ccgo_up(color_map + uintptr(packed_pixels&bit_mask)*4))
  50740 				goto _8
  50741 			_8:
  50742 				**(**uint32_t)(__ccgo_up(v3)) = v4
  50743 				packed_pixels = packed_pixels >> uint32(bits_per_pixel)
  50744 				goto _2
  50745 			_2:
  50746 				;
  50747 				x = x + 1
  50748 			}
  50749 			goto _1
  50750 		_1:
  50751 			;
  50752 			y = y + 1
  50753 		}
  50754 	} else {
  50755 		(*(*func(*libc.TLS, uintptr, uintptr, uintptr, int32, int32, int32))(unsafe.Pointer(&struct{ uintptr }{VP8LMapColor32b})))(tls, src, color_map, dst, y_start, y_end, width)
  50756 	}
  50757 }
  50758 
  50759 func MapAlpha_C(tls *libc.TLS, src uintptr, color_map uintptr, dst uintptr, y_start int32, y_end int32, width int32) {
  50760 	var x, y int32
  50761 	var v3, v4 uintptr
  50762 	var v5, v7 uint8_t
  50763 	_, _, _, _, _, _ = x, y, v3, v4, v5, v7
  50764 	y = y_start
  50765 	for {
  50766 		if !(y < y_end) {
  50767 			break
  50768 		}
  50769 		x = 0
  50770 		for {
  50771 			if !(x < width) {
  50772 				break
  50773 			}
  50774 			v3 = dst
  50775 			dst = dst + 1
  50776 			v4 = src
  50777 			src = src + 1
  50778 			v5 = **(**uint8_t)(__ccgo_up(v4))
  50779 			goto _6
  50780 		_6:
  50781 			v7 = uint8(**(**uint32_t)(__ccgo_up(color_map + uintptr(v5)*4)) >> libc.Int32FromInt32(8) & uint32(0xff))
  50782 			goto _8
  50783 		_8:
  50784 			**(**uint8_t)(__ccgo_up(v3)) = v7
  50785 			goto _2
  50786 		_2:
  50787 			;
  50788 			x = x + 1
  50789 		}
  50790 		goto _1
  50791 	_1:
  50792 		;
  50793 		y = y + 1
  50794 	}
  50795 }
  50796 
  50797 func VP8LColorIndexInverseTransformAlpha(tls *libc.TLS, transform uintptr, y_start int32, y_end int32, src uintptr, dst uintptr) {
  50798 	var bit_mask, packed_pixels uint32_t
  50799 	var bits_per_pixel, count_mask, pixels_per_byte, width, x, y int32
  50800 	var color_map, v3 uintptr
  50801 	var v4 uint8_t
  50802 	_, _, _, _, _, _, _, _, _, _, _ = bit_mask, bits_per_pixel, color_map, count_mask, packed_pixels, pixels_per_byte, width, x, y, v3, v4
  50803 	bits_per_pixel = int32(8) >> (*VP8LTransform)(unsafe.Pointer(transform)).Fbits
  50804 	width = (*VP8LTransform)(unsafe.Pointer(transform)).Fxsize
  50805 	color_map = (*VP8LTransform)(unsafe.Pointer(transform)).Fdata
  50806 	if bits_per_pixel < int32(8) {
  50807 		pixels_per_byte = int32(1) << (*VP8LTransform)(unsafe.Pointer(transform)).Fbits
  50808 		count_mask = pixels_per_byte - int32(1)
  50809 		bit_mask = uint32(int32(1)<<bits_per_pixel - int32(1))
  50810 		y = y_start
  50811 		for {
  50812 			if !(y < y_end) {
  50813 				break
  50814 			}
  50815 			packed_pixels = uint32(0)
  50816 			x = 0
  50817 			for {
  50818 				if !(x < width) {
  50819 					break
  50820 				} /* 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.                                         */
  50821 				if x&count_mask == 0 {
  50822 					v3 = src
  50823 					src = src + 1
  50824 					v4 = **(**uint8_t)(__ccgo_up(v3))
  50825 					goto _5
  50826 				_5:
  50827 					packed_pixels = uint32(v4)
  50828 				}
  50829 				v3 = dst
  50830 				dst = dst + 1
  50831 				v4 = uint8(**(**uint32_t)(__ccgo_up(color_map + uintptr(packed_pixels&bit_mask)*4)) >> libc.Int32FromInt32(8) & uint32(0xff))
  50832 				goto _8
  50833 			_8:
  50834 				**(**uint8_t)(__ccgo_up(v3)) = v4
  50835 				packed_pixels = packed_pixels >> uint32(bits_per_pixel)
  50836 				goto _2
  50837 			_2:
  50838 				;
  50839 				x = x + 1
  50840 			}
  50841 			goto _1
  50842 		_1:
  50843 			;
  50844 			y = y + 1
  50845 		}
  50846 	} else {
  50847 		(*(*func(*libc.TLS, uintptr, uintptr, uintptr, int32, int32, int32))(unsafe.Pointer(&struct{ uintptr }{VP8LMapColor8b})))(tls, src, color_map, dst, y_start, y_end, width)
  50848 	}
  50849 }
  50850 
  50851 func VP8LInverseTransform(tls *libc.TLS, transform uintptr, row_start int32, row_end int32, in uintptr, out uintptr) {
  50852 	var in_stride, out_stride, width int32
  50853 	var src uintptr
  50854 	var v1, v2 uint32_t
  50855 	_, _, _, _, _, _ = in_stride, out_stride, src, width, v1, v2
  50856 	width = (*VP8LTransform)(unsafe.Pointer(transform)).Fxsize
  50857 	switch (*VP8LTransform)(unsafe.Pointer(transform)).Ftype1 {
  50858 	case int32(SUBTRACT_GREEN_TRANSFORM):
  50859 		(*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8LAddGreenToBlueAndRed})))(tls, in, (row_end-row_start)*width, out)
  50860 	case int32(PREDICTOR_TRANSFORM):
  50861 		PredictorInverseTransform_C(tls, transform, row_start, row_end, in, out)
  50862 		if row_end != (*VP8LTransform)(unsafe.Pointer(transform)).Fysize {
  50863 			// The last predicted row in this iteration will be the top-pred row
  50864 			// for the first row in next iteration.
  50865 			libc.Xmemcpy(tls, out-uintptr(width)*4, out+uintptr((row_end-row_start-int32(1))*width)*4, uint64(width)*uint64(4))
  50866 		}
  50867 	case int32(CROSS_COLOR_TRANSFORM):
  50868 		ColorSpaceInverseTransform_C(tls, transform, row_start, row_end, in, out)
  50869 	case int32(COLOR_INDEXING_TRANSFORM):
  50870 		if in == out && (*VP8LTransform)(unsafe.Pointer(transform)).Fbits > 0 {
  50871 			// Move packed pixels to the end of unpacked region, so that unpacking
  50872 			// can occur seamlessly.
  50873 			// Also, note that this is the only transform that applies on
  50874 			// the effective width of VP8LSubSampleSize(xsize, bits). All other
  50875 			// transforms work on effective width of 'xsize'.
  50876 			out_stride = (row_end - row_start) * width
  50877 			v1 = uint32((*VP8LTransform)(unsafe.Pointer(transform)).Fbits)
  50878 			v2 = (uint32((*VP8LTransform)(unsafe.Pointer(transform)).Fxsize) + uint32(libc.Int32FromInt32(1)<<v1) - uint32(1)) >> v1
  50879 			goto _3
  50880 		_3:
  50881 			in_stride = int32(uint32(row_end-row_start) * v2)
  50882 			src = out + uintptr(out_stride)*4 - uintptr(in_stride)*4
  50883 			libc.Xmemmove(tls, src, out, uint64(in_stride)*uint64(4))
  50884 			ColorIndexInverseTransform_C(tls, transform, row_start, row_end, src, out)
  50885 		} else {
  50886 			ColorIndexInverseTransform_C(tls, transform, row_start, row_end, in, out)
  50887 		}
  50888 		break
  50889 	}
  50890 }
  50891 
  50892 //------------------------------------------------------------------------------
  50893 // Color space conversion.
  50894 
  50895 func is_big_endian(tls *libc.TLS) (r int32) {
  50896 	return libc.BoolInt32(int32(**(**uint8_t)(__ccgo_up(uintptr(unsafe.Pointer(&tmp))))) != int32(1))
  50897 }
  50898 
  50899 var tmp = *(*struct {
  50900 	Fb [0][2]uint8_t
  50901 	Fw uint16_t
  50902 })(unsafe.Pointer(&[1]uint16{0x1}))
  50903 
  50904 func VP8LConvertBGRAToRGB_C(tls *libc.TLS, src uintptr, num_pixels int32, dst uintptr) {
  50905 	var argb uint32_t
  50906 	var src_end, v1, v2 uintptr
  50907 	_, _, _, _ = argb, src_end, v1, v2
  50908 	src_end = src + uintptr(num_pixels)*4
  50909 	for src < src_end {
  50910 		v1 = src
  50911 		src += 4
  50912 		argb = **(**uint32_t)(__ccgo_up(v1))
  50913 		v2 = dst
  50914 		dst = dst + 1
  50915 		**(**uint8_t)(__ccgo_up(v2)) = uint8(argb >> libc.Int32FromInt32(16) & uint32(0xff))
  50916 		v1 = dst
  50917 		dst = dst + 1
  50918 		**(**uint8_t)(__ccgo_up(v1)) = uint8(argb >> libc.Int32FromInt32(8) & uint32(0xff))
  50919 		v1 = dst
  50920 		dst = dst + 1
  50921 		**(**uint8_t)(__ccgo_up(v1)) = uint8(argb >> libc.Int32FromInt32(0) & uint32(0xff))
  50922 	}
  50923 }
  50924 
  50925 func VP8LConvertBGRAToRGBA_C(tls *libc.TLS, src uintptr, num_pixels int32, dst uintptr) {
  50926 	var argb uint32_t
  50927 	var src_end, v1, v2 uintptr
  50928 	_, _, _, _ = argb, src_end, v1, v2
  50929 	src_end = src + uintptr(num_pixels)*4
  50930 	for src < src_end {
  50931 		v1 = src
  50932 		src += 4
  50933 		argb = **(**uint32_t)(__ccgo_up(v1))
  50934 		v2 = dst
  50935 		dst = dst + 1
  50936 		**(**uint8_t)(__ccgo_up(v2)) = uint8(argb >> libc.Int32FromInt32(16) & uint32(0xff))
  50937 		v1 = dst
  50938 		dst = dst + 1
  50939 		**(**uint8_t)(__ccgo_up(v1)) = uint8(argb >> libc.Int32FromInt32(8) & uint32(0xff))
  50940 		v1 = dst
  50941 		dst = dst + 1
  50942 		**(**uint8_t)(__ccgo_up(v1)) = uint8(argb >> libc.Int32FromInt32(0) & uint32(0xff))
  50943 		v1 = dst
  50944 		dst = dst + 1
  50945 		**(**uint8_t)(__ccgo_up(v1)) = uint8(argb >> libc.Int32FromInt32(24) & uint32(0xff))
  50946 	}
  50947 }
  50948 
  50949 func VP8LConvertBGRAToRGBA4444_C(tls *libc.TLS, src uintptr, num_pixels int32, dst uintptr) {
  50950 	var argb uint32_t
  50951 	var ba, rg uint8_t
  50952 	var src_end, v1, v2 uintptr
  50953 	_, _, _, _, _, _ = argb, ba, rg, src_end, v1, v2
  50954 	src_end = src + uintptr(num_pixels)*4
  50955 	for src < src_end {
  50956 		v1 = src
  50957 		src += 4
  50958 		argb = **(**uint32_t)(__ccgo_up(v1))
  50959 		rg = uint8(argb>>libc.Int32FromInt32(16)&uint32(0xf0) | argb>>libc.Int32FromInt32(12)&uint32(0xf))
  50960 		ba = uint8(argb>>libc.Int32FromInt32(0)&uint32(0xf0) | argb>>libc.Int32FromInt32(28)&uint32(0xf))
  50961 		v2 = dst
  50962 		dst = dst + 1
  50963 		**(**uint8_t)(__ccgo_up(v2)) = rg
  50964 		v1 = dst
  50965 		dst = dst + 1
  50966 		**(**uint8_t)(__ccgo_up(v1)) = ba
  50967 	}
  50968 }
  50969 
  50970 func VP8LConvertBGRAToRGB565_C(tls *libc.TLS, src uintptr, num_pixels int32, dst uintptr) {
  50971 	var argb uint32_t
  50972 	var gb, rg uint8_t
  50973 	var src_end, v1, v2 uintptr
  50974 	_, _, _, _, _, _ = argb, gb, rg, src_end, v1, v2
  50975 	src_end = src + uintptr(num_pixels)*4
  50976 	for src < src_end {
  50977 		v1 = src
  50978 		src += 4
  50979 		argb = **(**uint32_t)(__ccgo_up(v1))
  50980 		rg = uint8(argb>>libc.Int32FromInt32(16)&uint32(0xf8) | argb>>libc.Int32FromInt32(13)&uint32(0x7))
  50981 		gb = uint8(argb>>libc.Int32FromInt32(5)&uint32(0xe0) | argb>>libc.Int32FromInt32(3)&uint32(0x1f))
  50982 		v2 = dst
  50983 		dst = dst + 1
  50984 		**(**uint8_t)(__ccgo_up(v2)) = rg
  50985 		v1 = dst
  50986 		dst = dst + 1
  50987 		**(**uint8_t)(__ccgo_up(v1)) = gb
  50988 	}
  50989 }
  50990 
  50991 func VP8LConvertBGRAToBGR_C(tls *libc.TLS, src uintptr, num_pixels int32, dst uintptr) {
  50992 	var argb uint32_t
  50993 	var src_end, v1, v2 uintptr
  50994 	_, _, _, _ = argb, src_end, v1, v2
  50995 	src_end = src + uintptr(num_pixels)*4
  50996 	for src < src_end {
  50997 		v1 = src
  50998 		src += 4
  50999 		argb = **(**uint32_t)(__ccgo_up(v1))
  51000 		v2 = dst
  51001 		dst = dst + 1
  51002 		**(**uint8_t)(__ccgo_up(v2)) = uint8(argb >> libc.Int32FromInt32(0) & uint32(0xff))
  51003 		v1 = dst
  51004 		dst = dst + 1
  51005 		**(**uint8_t)(__ccgo_up(v1)) = uint8(argb >> libc.Int32FromInt32(8) & uint32(0xff))
  51006 		v1 = dst
  51007 		dst = dst + 1
  51008 		**(**uint8_t)(__ccgo_up(v1)) = uint8(argb >> libc.Int32FromInt32(16) & uint32(0xff))
  51009 	}
  51010 }
  51011 
  51012 func CopyOrSwap(tls *libc.TLS, src uintptr, num_pixels int32, dst uintptr, swap_on_big_endian int32) {
  51013 	bp := tls.Alloc(16)
  51014 	defer tls.Free(16)
  51015 	var argb, v2, v4 uint32_t
  51016 	var src_end, v1 uintptr
  51017 	_, _, _, _, _ = argb, src_end, v1, v2, v4
  51018 	if is_big_endian(tls) == swap_on_big_endian {
  51019 		src_end = src + uintptr(num_pixels)*4
  51020 		for src < src_end {
  51021 			v1 = src
  51022 			src += 4
  51023 			argb = **(**uint32_t)(__ccgo_up(v1))
  51024 			v2 = libc.X__builtin_bswap32(tls, argb)
  51025 			goto _3
  51026 		_3:
  51027 			v4 = v2
  51028 			*(*uint32_t)(unsafe.Pointer(bp)) = v4
  51029 			libc.Xmemcpy(tls, dst, bp, uint64(4))
  51030 			dst = dst + uintptr(4)
  51031 		}
  51032 	} else {
  51033 		libc.Xmemcpy(tls, dst, src, uint64(num_pixels)*uint64(4))
  51034 	}
  51035 }
  51036 
  51037 func VP8LConvertFromBGRA(tls *libc.TLS, in_data uintptr, num_pixels int32, out_colorspace WEBP_CSP_MODE1, rgba uintptr) {
  51038 	switch out_colorspace {
  51039 	case int32(MODE_RGB):
  51040 		(*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8LConvertBGRAToRGB})))(tls, in_data, num_pixels, rgba)
  51041 	case int32(MODE_RGBA):
  51042 		(*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8LConvertBGRAToRGBA})))(tls, in_data, num_pixels, rgba)
  51043 	case int32(MODE_rgbA):
  51044 		(*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8LConvertBGRAToRGBA})))(tls, in_data, num_pixels, rgba)
  51045 		(*(*func(*libc.TLS, uintptr, int32, int32, int32, int32))(unsafe.Pointer(&struct{ uintptr }{WebPApplyAlphaMultiply})))(tls, rgba, 0, num_pixels, int32(1), 0)
  51046 	case int32(MODE_BGR):
  51047 		(*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8LConvertBGRAToBGR})))(tls, in_data, num_pixels, rgba)
  51048 	case int32(MODE_BGRA):
  51049 		CopyOrSwap(tls, in_data, num_pixels, rgba, int32(1))
  51050 	case int32(MODE_bgrA):
  51051 		CopyOrSwap(tls, in_data, num_pixels, rgba, int32(1))
  51052 		(*(*func(*libc.TLS, uintptr, int32, int32, int32, int32))(unsafe.Pointer(&struct{ uintptr }{WebPApplyAlphaMultiply})))(tls, rgba, 0, num_pixels, int32(1), 0)
  51053 	case int32(MODE_ARGB):
  51054 		CopyOrSwap(tls, in_data, num_pixels, rgba, 0)
  51055 	case int32(MODE_Argb):
  51056 		CopyOrSwap(tls, in_data, num_pixels, rgba, 0)
  51057 		(*(*func(*libc.TLS, uintptr, int32, int32, int32, int32))(unsafe.Pointer(&struct{ uintptr }{WebPApplyAlphaMultiply})))(tls, rgba, int32(1), num_pixels, int32(1), 0)
  51058 	case int32(MODE_RGBA_4444):
  51059 		(*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8LConvertBGRAToRGBA4444})))(tls, in_data, num_pixels, rgba)
  51060 	case int32(MODE_rgbA_4444):
  51061 		(*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8LConvertBGRAToRGBA4444})))(tls, in_data, num_pixels, rgba)
  51062 		(*(*func(*libc.TLS, uintptr, int32, int32, int32))(unsafe.Pointer(&struct{ uintptr }{WebPApplyAlphaMultiply4444})))(tls, rgba, num_pixels, int32(1), 0)
  51063 	case int32(MODE_RGB_565):
  51064 		(*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8LConvertBGRAToRGB565})))(tls, in_data, num_pixels, rgba)
  51065 	default:
  51066 		// Code flow should not reach here.
  51067 	}
  51068 }
  51069 
  51070 func VP8LDspInit(tls *libc.TLS) {
  51071 	if libc.AtomicLoadPUintptr(uintptr(unsafe.Pointer(&VP8LDspInit_body_last_cpuinfo_used))) == VP8GetCPUInfo {
  51072 		goto _1
  51073 	}
  51074 	VP8LDspInit_body(tls)
  51075 	libc.AtomicStorePUintptr(uintptr(unsafe.Pointer(&VP8LDspInit_body_last_cpuinfo_used)), VP8GetCPUInfo)
  51076 	goto _2
  51077 _2:
  51078 	;
  51079 	goto _1
  51080 _1: /**/ //
  51081 }
  51082 
  51083 var VP8LDspInit_body_last_cpuinfo_used = uintptr(0)
  51084 
  51085 func init() {
  51086 	p := unsafe.Pointer(&VP8LDspInit_body_last_cpuinfo_used)
  51087 	*(*uintptr)(unsafe.Add(p, 0)) = uintptr(unsafe.Pointer(&VP8LDspInit_body_last_cpuinfo_used))
  51088 }
  51089 
  51090 func VP8LDspInit_body(tls *libc.TLS) {
  51091 	VP8LPredictors[0] = __ccgo_fp(VP8LPredictor0_C)
  51092 	VP8LPredictors[int32(1)] = __ccgo_fp(VP8LPredictor1_C)
  51093 	VP8LPredictors[int32(2)] = __ccgo_fp(VP8LPredictor2_C)
  51094 	VP8LPredictors[int32(3)] = __ccgo_fp(VP8LPredictor3_C)
  51095 	VP8LPredictors[int32(4)] = __ccgo_fp(VP8LPredictor4_C)
  51096 	VP8LPredictors[int32(5)] = __ccgo_fp(VP8LPredictor5_C)
  51097 	VP8LPredictors[int32(6)] = __ccgo_fp(VP8LPredictor6_C)
  51098 	VP8LPredictors[int32(7)] = __ccgo_fp(VP8LPredictor7_C)
  51099 	VP8LPredictors[int32(8)] = __ccgo_fp(VP8LPredictor8_C)
  51100 	VP8LPredictors[int32(9)] = __ccgo_fp(VP8LPredictor9_C)
  51101 	VP8LPredictors[int32(10)] = __ccgo_fp(VP8LPredictor10_C)
  51102 	VP8LPredictors[int32(11)] = __ccgo_fp(VP8LPredictor11_C)
  51103 	VP8LPredictors[int32(12)] = __ccgo_fp(VP8LPredictor12_C)
  51104 	VP8LPredictors[int32(13)] = __ccgo_fp(VP8LPredictor13_C)
  51105 	VP8LPredictors[int32(14)] = __ccgo_fp(VP8LPredictor0_C) /* <- padding security sentinels*/
  51106 	VP8LPredictors[int32(15)] = __ccgo_fp(VP8LPredictor0_C)
  51107 	VP8LPredictorsAdd[0] = __ccgo_fp(PredictorAdd0_C)
  51108 	VP8LPredictorsAdd[int32(1)] = __ccgo_fp(PredictorAdd1_C)
  51109 	VP8LPredictorsAdd[int32(2)] = __ccgo_fp(PredictorAdd2_C)
  51110 	VP8LPredictorsAdd[int32(3)] = __ccgo_fp(PredictorAdd3_C)
  51111 	VP8LPredictorsAdd[int32(4)] = __ccgo_fp(PredictorAdd4_C)
  51112 	VP8LPredictorsAdd[int32(5)] = __ccgo_fp(PredictorAdd5_C)
  51113 	VP8LPredictorsAdd[int32(6)] = __ccgo_fp(PredictorAdd6_C)
  51114 	VP8LPredictorsAdd[int32(7)] = __ccgo_fp(PredictorAdd7_C)
  51115 	VP8LPredictorsAdd[int32(8)] = __ccgo_fp(PredictorAdd8_C)
  51116 	VP8LPredictorsAdd[int32(9)] = __ccgo_fp(PredictorAdd9_C)
  51117 	VP8LPredictorsAdd[int32(10)] = __ccgo_fp(PredictorAdd10_C)
  51118 	VP8LPredictorsAdd[int32(11)] = __ccgo_fp(PredictorAdd11_C)
  51119 	VP8LPredictorsAdd[int32(12)] = __ccgo_fp(PredictorAdd12_C)
  51120 	VP8LPredictorsAdd[int32(13)] = __ccgo_fp(PredictorAdd13_C)
  51121 	VP8LPredictorsAdd[int32(14)] = __ccgo_fp(PredictorAdd0_C) /* <- padding security sentinels*/
  51122 	VP8LPredictorsAdd[int32(15)] = __ccgo_fp(PredictorAdd0_C)
  51123 	VP8LPredictorsAdd_C[0] = __ccgo_fp(PredictorAdd0_C)
  51124 	VP8LPredictorsAdd_C[int32(1)] = __ccgo_fp(PredictorAdd1_C)
  51125 	VP8LPredictorsAdd_C[int32(2)] = __ccgo_fp(PredictorAdd2_C)
  51126 	VP8LPredictorsAdd_C[int32(3)] = __ccgo_fp(PredictorAdd3_C)
  51127 	VP8LPredictorsAdd_C[int32(4)] = __ccgo_fp(PredictorAdd4_C)
  51128 	VP8LPredictorsAdd_C[int32(5)] = __ccgo_fp(PredictorAdd5_C)
  51129 	VP8LPredictorsAdd_C[int32(6)] = __ccgo_fp(PredictorAdd6_C)
  51130 	VP8LPredictorsAdd_C[int32(7)] = __ccgo_fp(PredictorAdd7_C)
  51131 	VP8LPredictorsAdd_C[int32(8)] = __ccgo_fp(PredictorAdd8_C)
  51132 	VP8LPredictorsAdd_C[int32(9)] = __ccgo_fp(PredictorAdd9_C)
  51133 	VP8LPredictorsAdd_C[int32(10)] = __ccgo_fp(PredictorAdd10_C)
  51134 	VP8LPredictorsAdd_C[int32(11)] = __ccgo_fp(PredictorAdd11_C)
  51135 	VP8LPredictorsAdd_C[int32(12)] = __ccgo_fp(PredictorAdd12_C)
  51136 	VP8LPredictorsAdd_C[int32(13)] = __ccgo_fp(PredictorAdd13_C)
  51137 	VP8LPredictorsAdd_C[int32(14)] = __ccgo_fp(PredictorAdd0_C) /* <- padding security sentinels*/
  51138 	VP8LPredictorsAdd_C[int32(15)] = __ccgo_fp(PredictorAdd0_C)
  51139 	VP8LAddGreenToBlueAndRed = __ccgo_fp(VP8LAddGreenToBlueAndRed_C)
  51140 	VP8LTransformColorInverse = __ccgo_fp(VP8LTransformColorInverse_C)
  51141 	VP8LConvertBGRAToRGBA = __ccgo_fp(VP8LConvertBGRAToRGBA_C)
  51142 	VP8LConvertBGRAToRGB = __ccgo_fp(VP8LConvertBGRAToRGB_C)
  51143 	VP8LConvertBGRAToBGR = __ccgo_fp(VP8LConvertBGRAToBGR_C)
  51144 	VP8LConvertBGRAToRGBA4444 = __ccgo_fp(VP8LConvertBGRAToRGBA4444_C)
  51145 	VP8LConvertBGRAToRGB565 = __ccgo_fp(VP8LConvertBGRAToRGB565_C)
  51146 	VP8LMapColor32b = __ccgo_fp(MapARGB_C)
  51147 	VP8LMapColor8b = __ccgo_fp(MapAlpha_C)
  51148 	// If defined, use CPUInfo() to overwrite some pointers with faster versions.
  51149 	if VP8GetCPUInfo != libc.UintptrFromInt32(0) {
  51150 	}
  51151 }
  51152 
  51153 func VP8LEncDspInitAVX2(tls *libc.TLS) {
  51154 }
  51155 
  51156 const LOG_2_RECIPROCAL_FIXED_DOUBLE1 = 1.2102203161561485e+07
  51157 const SIZE_MAX28 = "_UI64_MAX"
  51158 
  51159 func FastSLog2Slow_C(tls *libc.TLS, v uint32_t) (r uint64_t) {
  51160 	var correction, log_cnt, orig_v uint64_t
  51161 	var y uint32_t
  51162 	var v1 int32
  51163 	_, _, _, _, _ = correction, log_cnt, orig_v, y, v1
  51164 	if v < uint32(APPROX_LOG_WITH_CORRECTION_MAX) {
  51165 		orig_v = uint64(v)
  51166 		v1 = int32(31) ^ libc.X__builtin_clz(tls, v)
  51167 		goto _2
  51168 	_2:
  51169 		// use clz if available
  51170 		log_cnt = uint64(v1 - int32(7))
  51171 		y = uint32(int32(1) << log_cnt)
  51172 		v = uint32(uint64(v) >> log_cnt)
  51173 		// vf = (2^log_cnt) * Xf; where y = 2^log_cnt and Xf < 256
  51174 		// Xf = floor(Xf) * (1 + (v % y) / v)
  51175 		// log2(Xf) = log2(floor(Xf)) + log2(1 + (v % y) / v)
  51176 		// The correction factor: log(1 + d) ~ d; for very small d values, so
  51177 		// log2(1 + (v % y) / v) ~ LOG_2_RECIPROCAL * (v % y)/v
  51178 		correction = libc.Uint64FromInt32(12102203) * (orig_v & uint64(y-libc.Uint32FromInt32(1)))
  51179 		return orig_v*(uint64(kLog2Table[v])+log_cnt<<libc.Int32FromInt32(LOG_2_PRECISION_BITS)) + correction
  51180 	} else {
  51181 		return uint64(float64(float64(libc.Float64FromFloat64(1.2102203161561485e+07)*float64(v))*libc.Xlog(tls, float64(v))) + libc.Float64FromFloat64(0.5))
  51182 	}
  51183 	return r
  51184 }
  51185 
  51186 func FastLog2Slow_C(tls *libc.TLS, v uint32_t) (r uint32_t) {
  51187 	var correction uint64_t
  51188 	var log_2, log_cnt, orig_v, y uint32_t
  51189 	var v1 int32
  51190 	var v3, v4, v5 int64_t
  51191 	var v7 int64
  51192 	_, _, _, _, _, _, _, _, _, _ = correction, log_2, log_cnt, orig_v, y, v1, v3, v4, v5, v7
  51193 	if v < uint32(APPROX_LOG_WITH_CORRECTION_MAX) {
  51194 		orig_v = v
  51195 		v1 = int32(31) ^ libc.X__builtin_clz(tls, v)
  51196 		goto _2
  51197 	_2:
  51198 		// use clz if available
  51199 		log_cnt = uint32(v1 - int32(7))
  51200 		y = uint32(int32(1) << log_cnt)
  51201 		v = v >> log_cnt
  51202 		log_2 = kLog2Table[v] + log_cnt<<libc.Int32FromInt32(LOG_2_PRECISION_BITS)
  51203 		if orig_v >= uint32(APPROX_LOG_MAX) {
  51204 			// Since the division is still expensive, add this correction factor only
  51205 			// for large values of 'v'.
  51206 			correction = libc.Uint64FromInt32(12102203) * uint64(orig_v&(y-libc.Uint32FromInt32(1)))
  51207 			v3 = int64(correction)
  51208 			v4 = int64(orig_v)
  51209 			if libc.BoolInt32(v3 < 0) == libc.BoolInt32(v4 < 0) {
  51210 				v7 = (v3 + v4/int64(2)) / v4
  51211 			} else {
  51212 				v7 = (v3 - v4/int64(2)) / v4
  51213 			}
  51214 			v5 = v7
  51215 			goto _6
  51216 		_6:
  51217 			log_2 = log_2 + uint32(v5)
  51218 		}
  51219 		return log_2
  51220 	} else {
  51221 		return uint32(float64(libc.Float64FromFloat64(1.2102203161561485e+07)*libc.Xlog(tls, float64(v))) + libc.Float64FromFloat64(0.5))
  51222 	}
  51223 	return r
  51224 }
  51225 
  51226 //------------------------------------------------------------------------------
  51227 // Methods to calculate Entropy (Shannon).
  51228 
  51229 // C documentation
  51230 //
  51231 //	// Compute the combined Shanon's entropy for distribution {X} and {X+Y}
  51232 func CombinedShannonEntropy_C(tls *libc.TLS, X uintptr, Y uintptr) (r uint64_t) {
  51233 	var i int32
  51234 	var retval, v3, v7 uint64_t
  51235 	var sumX, sumXY, x, xy, v2, v6 uint32_t
  51236 	var v5, v9 uint64
  51237 	_, _, _, _, _, _, _, _, _, _, _, _ = i, retval, sumX, sumXY, x, xy, v2, v3, v5, v6, v7, v9
  51238 	retval = uint64(0)
  51239 	sumX = uint32(0)
  51240 	sumXY = uint32(0)
  51241 	i = 0
  51242 	for {
  51243 		if !(i < int32(256)) {
  51244 			break
  51245 		}
  51246 		x = **(**uint32_t)(__ccgo_up(X + uintptr(i)*4))
  51247 		if x != uint32(0) {
  51248 			xy = x + **(**uint32_t)(__ccgo_up(Y + uintptr(i)*4))
  51249 			sumX = sumX + x
  51250 			v2 = x
  51251 			if v2 < uint32(LOG_LOOKUP_IDX_MAX) {
  51252 				v5 = kSLog2Table[v2]
  51253 			} else {
  51254 				v5 = (*(*func(*libc.TLS, uint32_t) uint64_t)(unsafe.Pointer(&struct{ uintptr }{VP8LFastSLog2Slow})))(tls, v2)
  51255 			}
  51256 			v3 = v5
  51257 			goto _4
  51258 		_4:
  51259 			retval = retval + v3
  51260 			sumXY = sumXY + xy
  51261 			v2 = xy
  51262 			if v2 < uint32(LOG_LOOKUP_IDX_MAX) {
  51263 				v5 = kSLog2Table[v2]
  51264 			} else {
  51265 				v5 = (*(*func(*libc.TLS, uint32_t) uint64_t)(unsafe.Pointer(&struct{ uintptr }{VP8LFastSLog2Slow})))(tls, v2)
  51266 			}
  51267 			v3 = v5
  51268 			goto _8
  51269 		_8:
  51270 			retval = retval + v3
  51271 		} else {
  51272 			if **(**uint32_t)(__ccgo_up(Y + uintptr(i)*4)) != uint32(0) {
  51273 				sumXY = sumXY + **(**uint32_t)(__ccgo_up(Y + uintptr(i)*4))
  51274 				v2 = **(**uint32_t)(__ccgo_up(Y + uintptr(i)*4))
  51275 				if v2 < uint32(LOG_LOOKUP_IDX_MAX) {
  51276 					v5 = kSLog2Table[v2]
  51277 				} else {
  51278 					v5 = (*(*func(*libc.TLS, uint32_t) uint64_t)(unsafe.Pointer(&struct{ uintptr }{VP8LFastSLog2Slow})))(tls, v2)
  51279 				}
  51280 				v3 = v5
  51281 				goto _12
  51282 			_12:
  51283 				retval = retval + v3
  51284 			}
  51285 		}
  51286 		goto _1
  51287 	_1:
  51288 		;
  51289 		i = i + 1
  51290 	}
  51291 	v2 = sumX
  51292 	if v2 < uint32(LOG_LOOKUP_IDX_MAX) {
  51293 		v5 = kSLog2Table[v2]
  51294 	} else {
  51295 		v5 = (*(*func(*libc.TLS, uint32_t) uint64_t)(unsafe.Pointer(&struct{ uintptr }{VP8LFastSLog2Slow})))(tls, v2)
  51296 	}
  51297 	v3 = v5
  51298 	goto _16
  51299 _16:
  51300 	v6 = sumXY
  51301 	if v6 < uint32(LOG_LOOKUP_IDX_MAX) {
  51302 		v9 = kSLog2Table[v6]
  51303 	} else {
  51304 		v9 = (*(*func(*libc.TLS, uint32_t) uint64_t)(unsafe.Pointer(&struct{ uintptr }{VP8LFastSLog2Slow})))(tls, v6)
  51305 	}
  51306 	v7 = v9
  51307 	goto _20
  51308 _20:
  51309 	retval = v3 + v7 - retval
  51310 	return retval
  51311 }
  51312 
  51313 func ShannonEntropy_C(tls *libc.TLS, X uintptr, n int32) (r uint64_t) {
  51314 	var i, x int32
  51315 	var retval, v3 uint64_t
  51316 	var sumX, v2 uint32_t
  51317 	var v5 uint64
  51318 	_, _, _, _, _, _, _ = i, retval, sumX, x, v2, v3, v5
  51319 	retval = uint64(0)
  51320 	sumX = uint32(0)
  51321 	i = 0
  51322 	for {
  51323 		if !(i < n) {
  51324 			break
  51325 		}
  51326 		x = int32(**(**uint32_t)(__ccgo_up(X + uintptr(i)*4)))
  51327 		if x != 0 {
  51328 			sumX = sumX + uint32(x)
  51329 			v2 = uint32(x)
  51330 			if v2 < uint32(LOG_LOOKUP_IDX_MAX) {
  51331 				v5 = kSLog2Table[v2]
  51332 			} else {
  51333 				v5 = (*(*func(*libc.TLS, uint32_t) uint64_t)(unsafe.Pointer(&struct{ uintptr }{VP8LFastSLog2Slow})))(tls, v2)
  51334 			}
  51335 			v3 = v5
  51336 			goto _4
  51337 		_4:
  51338 			retval = retval + v3
  51339 		}
  51340 		goto _1
  51341 	_1:
  51342 		;
  51343 		i = i + 1
  51344 	}
  51345 	v2 = sumX
  51346 	if v2 < uint32(LOG_LOOKUP_IDX_MAX) {
  51347 		v5 = kSLog2Table[v2]
  51348 	} else {
  51349 		v5 = (*(*func(*libc.TLS, uint32_t) uint64_t)(unsafe.Pointer(&struct{ uintptr }{VP8LFastSLog2Slow})))(tls, v2)
  51350 	}
  51351 	v3 = v5
  51352 	goto _8
  51353 _8:
  51354 	retval = v3 - retval
  51355 	return retval
  51356 }
  51357 
  51358 func VP8LBitEntropyInit(tls *libc.TLS, entropy uintptr) {
  51359 	(*VP8LBitEntropy)(unsafe.Pointer(entropy)).Fentropy = uint64(0)
  51360 	(*VP8LBitEntropy)(unsafe.Pointer(entropy)).Fsum = uint32(0)
  51361 	(*VP8LBitEntropy)(unsafe.Pointer(entropy)).Fnonzeros = 0
  51362 	(*VP8LBitEntropy)(unsafe.Pointer(entropy)).Fmax_val = uint32(0)
  51363 	(*VP8LBitEntropy)(unsafe.Pointer(entropy)).Fnonzero_code = uint32(uint16(libc.Int32FromInt32(0xffff)))
  51364 }
  51365 
  51366 func VP8LBitsEntropyUnrefined(tls *libc.TLS, array uintptr, n int32, entropy uintptr) {
  51367 	var i int32
  51368 	var v2 uint32_t
  51369 	var v3 uint64_t
  51370 	var v5 uint64
  51371 	_, _, _, _ = i, v2, v3, v5
  51372 	VP8LBitEntropyInit(tls, entropy)
  51373 	i = 0
  51374 	for {
  51375 		if !(i < n) {
  51376 			break
  51377 		}
  51378 		if **(**uint32_t)(__ccgo_up(array + uintptr(i)*4)) != uint32(0) {
  51379 			**(**uint32_t)(__ccgo_up(entropy + 8)) += **(**uint32_t)(__ccgo_up(array + uintptr(i)*4))
  51380 			(*VP8LBitEntropy)(unsafe.Pointer(entropy)).Fnonzero_code = uint32(i)
  51381 			(*VP8LBitEntropy)(unsafe.Pointer(entropy)).Fnonzeros = (*VP8LBitEntropy)(unsafe.Pointer(entropy)).Fnonzeros + 1
  51382 			v2 = **(**uint32_t)(__ccgo_up(array + uintptr(i)*4))
  51383 			if v2 < uint32(LOG_LOOKUP_IDX_MAX) {
  51384 				v5 = kSLog2Table[v2]
  51385 			} else {
  51386 				v5 = (*(*func(*libc.TLS, uint32_t) uint64_t)(unsafe.Pointer(&struct{ uintptr }{VP8LFastSLog2Slow})))(tls, v2)
  51387 			}
  51388 			v3 = v5
  51389 			goto _4
  51390 		_4:
  51391 			**(**uint64_t)(__ccgo_up(entropy)) += v3
  51392 			if (*VP8LBitEntropy)(unsafe.Pointer(entropy)).Fmax_val < **(**uint32_t)(__ccgo_up(array + uintptr(i)*4)) {
  51393 				(*VP8LBitEntropy)(unsafe.Pointer(entropy)).Fmax_val = **(**uint32_t)(__ccgo_up(array + uintptr(i)*4))
  51394 			}
  51395 		}
  51396 		goto _1
  51397 	_1:
  51398 		;
  51399 		i = i + 1
  51400 	}
  51401 	v2 = (*VP8LBitEntropy)(unsafe.Pointer(entropy)).Fsum
  51402 	if v2 < uint32(LOG_LOOKUP_IDX_MAX) {
  51403 		v5 = kSLog2Table[v2]
  51404 	} else {
  51405 		v5 = (*(*func(*libc.TLS, uint32_t) uint64_t)(unsafe.Pointer(&struct{ uintptr }{VP8LFastSLog2Slow})))(tls, v2)
  51406 	}
  51407 	v3 = v5
  51408 	goto _8
  51409 _8:
  51410 	(*VP8LBitEntropy)(unsafe.Pointer(entropy)).Fentropy = v3 - (*VP8LBitEntropy)(unsafe.Pointer(entropy)).Fentropy
  51411 }
  51412 
  51413 func GetEntropyUnrefinedHelper(tls *libc.TLS, val uint32_t, i int32, val_prev uintptr, i_prev uintptr, bit_entropy uintptr, stats uintptr) {
  51414 	var streak int32
  51415 	var v1 uint32_t
  51416 	var v2 uint64_t
  51417 	var v4 uint64
  51418 	_, _, _, _ = streak, v1, v2, v4
  51419 	streak = i - **(**int32)(__ccgo_up(i_prev))
  51420 	// Gather info for the bit entropy.
  51421 	if **(**uint32_t)(__ccgo_up(val_prev)) != uint32(0) {
  51422 		**(**uint32_t)(__ccgo_up(bit_entropy + 8)) += **(**uint32_t)(__ccgo_up(val_prev)) * uint32(streak)
  51423 		**(**int32)(__ccgo_up(bit_entropy + 12)) += streak
  51424 		(*VP8LBitEntropy)(unsafe.Pointer(bit_entropy)).Fnonzero_code = uint32(**(**int32)(__ccgo_up(i_prev)))
  51425 		v1 = **(**uint32_t)(__ccgo_up(val_prev))
  51426 		if v1 < uint32(LOG_LOOKUP_IDX_MAX) {
  51427 			v4 = kSLog2Table[v1]
  51428 		} else {
  51429 			v4 = (*(*func(*libc.TLS, uint32_t) uint64_t)(unsafe.Pointer(&struct{ uintptr }{VP8LFastSLog2Slow})))(tls, v1)
  51430 		}
  51431 		v2 = v4
  51432 		goto _3
  51433 	_3:
  51434 		**(**uint64_t)(__ccgo_up(bit_entropy)) += v2 * uint64(streak)
  51435 		if (*VP8LBitEntropy)(unsafe.Pointer(bit_entropy)).Fmax_val < **(**uint32_t)(__ccgo_up(val_prev)) {
  51436 			(*VP8LBitEntropy)(unsafe.Pointer(bit_entropy)).Fmax_val = **(**uint32_t)(__ccgo_up(val_prev))
  51437 		}
  51438 	}
  51439 	// Gather info for the Huffman cost.
  51440 	**(**int32)(__ccgo_up(stats + libc.BoolUintptr(**(**uint32_t)(__ccgo_up(val_prev)) != uint32(0))*4)) += libc.BoolInt32(streak > int32(3))
  51441 	**(**int32)(__ccgo_up(stats + 8 + libc.BoolUintptr(**(**uint32_t)(__ccgo_up(val_prev)) != uint32(0))*8 + libc.BoolUintptr(streak > libc.Int32FromInt32(3))*4)) += streak
  51442 	**(**uint32_t)(__ccgo_up(val_prev)) = val
  51443 	**(**int32)(__ccgo_up(i_prev)) = i
  51444 }
  51445 
  51446 func GetEntropyUnrefined_C(tls *libc.TLS, X uintptr, length int32, bit_entropy uintptr, stats uintptr) {
  51447 	bp := tls.Alloc(16)
  51448 	defer tls.Free(16)
  51449 	var i int32
  51450 	var x, v2 uint32_t
  51451 	var v3 uint64_t
  51452 	var v5 uint64
  51453 	var _ /* i_prev at bp+0 */ int32
  51454 	var _ /* x_prev at bp+4 */ uint32_t
  51455 	_, _, _, _, _ = i, x, v2, v3, v5
  51456 	**(**int32)(__ccgo_up(bp)) = 0
  51457 	**(**uint32_t)(__ccgo_up(bp + 4)) = **(**uint32_t)(__ccgo_up(X))
  51458 	libc.Xmemset(tls, stats, 0, uint64(24))
  51459 	VP8LBitEntropyInit(tls, bit_entropy)
  51460 	i = int32(1)
  51461 	for {
  51462 		if !(i < length) {
  51463 			break
  51464 		}
  51465 		x = **(**uint32_t)(__ccgo_up(X + uintptr(i)*4))
  51466 		if x != **(**uint32_t)(__ccgo_up(bp + 4)) {
  51467 			GetEntropyUnrefinedHelper(tls, x, i, bp+4, bp, bit_entropy, stats)
  51468 		}
  51469 		goto _1
  51470 	_1:
  51471 		;
  51472 		i = i + 1
  51473 	}
  51474 	GetEntropyUnrefinedHelper(tls, uint32(0), i, bp+4, bp, bit_entropy, stats)
  51475 	v2 = (*VP8LBitEntropy)(unsafe.Pointer(bit_entropy)).Fsum
  51476 	if v2 < uint32(LOG_LOOKUP_IDX_MAX) {
  51477 		v5 = kSLog2Table[v2]
  51478 	} else {
  51479 		v5 = (*(*func(*libc.TLS, uint32_t) uint64_t)(unsafe.Pointer(&struct{ uintptr }{VP8LFastSLog2Slow})))(tls, v2)
  51480 	}
  51481 	v3 = v5
  51482 	goto _4
  51483 _4:
  51484 	(*VP8LBitEntropy)(unsafe.Pointer(bit_entropy)).Fentropy = v3 - (*VP8LBitEntropy)(unsafe.Pointer(bit_entropy)).Fentropy
  51485 }
  51486 
  51487 func GetCombinedEntropyUnrefined_C(tls *libc.TLS, X uintptr, Y uintptr, length int32, bit_entropy uintptr, stats uintptr) {
  51488 	bp := tls.Alloc(16)
  51489 	defer tls.Free(16)
  51490 	var i int32
  51491 	var xy, v2 uint32_t
  51492 	var v3 uint64_t
  51493 	var v5 uint64
  51494 	var _ /* i_prev at bp+0 */ int32
  51495 	var _ /* xy_prev at bp+4 */ uint32_t
  51496 	_, _, _, _, _ = i, xy, v2, v3, v5
  51497 	i = int32(1)
  51498 	**(**int32)(__ccgo_up(bp)) = 0
  51499 	**(**uint32_t)(__ccgo_up(bp + 4)) = **(**uint32_t)(__ccgo_up(X)) + **(**uint32_t)(__ccgo_up(Y))
  51500 	libc.Xmemset(tls, stats, 0, uint64(24))
  51501 	VP8LBitEntropyInit(tls, bit_entropy)
  51502 	i = int32(1)
  51503 	for {
  51504 		if !(i < length) {
  51505 			break
  51506 		}
  51507 		xy = **(**uint32_t)(__ccgo_up(X + uintptr(i)*4)) + **(**uint32_t)(__ccgo_up(Y + uintptr(i)*4))
  51508 		if xy != **(**uint32_t)(__ccgo_up(bp + 4)) {
  51509 			GetEntropyUnrefinedHelper(tls, xy, i, bp+4, bp, bit_entropy, stats)
  51510 		}
  51511 		goto _1
  51512 	_1:
  51513 		;
  51514 		i = i + 1
  51515 	}
  51516 	GetEntropyUnrefinedHelper(tls, uint32(0), i, bp+4, bp, bit_entropy, stats)
  51517 	v2 = (*VP8LBitEntropy)(unsafe.Pointer(bit_entropy)).Fsum
  51518 	if v2 < uint32(LOG_LOOKUP_IDX_MAX) {
  51519 		v5 = kSLog2Table[v2]
  51520 	} else {
  51521 		v5 = (*(*func(*libc.TLS, uint32_t) uint64_t)(unsafe.Pointer(&struct{ uintptr }{VP8LFastSLog2Slow})))(tls, v2)
  51522 	}
  51523 	v3 = v5
  51524 	goto _4
  51525 _4:
  51526 	(*VP8LBitEntropy)(unsafe.Pointer(bit_entropy)).Fentropy = v3 - (*VP8LBitEntropy)(unsafe.Pointer(bit_entropy)).Fentropy
  51527 }
  51528 
  51529 //------------------------------------------------------------------------------
  51530 
  51531 func VP8LSubtractGreenFromBlueAndRed_C(tls *libc.TLS, argb_data uintptr, num_pixels int32) {
  51532 	var argb, green, i int32
  51533 	var new_b, new_r uint32_t
  51534 	_, _, _, _, _ = argb, green, i, new_b, new_r
  51535 	i = 0
  51536 	for {
  51537 		if !(i < num_pixels) {
  51538 			break
  51539 		}
  51540 		argb = int32(**(**uint32_t)(__ccgo_up(argb_data + uintptr(i)*4)))
  51541 		green = argb >> libc.Int32FromInt32(8) & int32(0xff)
  51542 		new_r = uint32((argb>>libc.Int32FromInt32(16)&int32(0xff) - green) & int32(0xff))
  51543 		new_b = uint32((argb>>libc.Int32FromInt32(0)&int32(0xff) - green) & int32(0xff))
  51544 		**(**uint32_t)(__ccgo_up(argb_data + uintptr(i)*4)) = uint32(argb)&uint32(0xff00ff00) | new_r<<libc.Int32FromInt32(16) | new_b
  51545 		goto _1
  51546 	_1:
  51547 		;
  51548 		i = i + 1
  51549 	}
  51550 }
  51551 
  51552 func ColorTransformDelta1(tls *libc.TLS, color_pred int8_t, color int8_t) (r int32) {
  51553 	return int32(color_pred) * int32(color) >> int32(5)
  51554 }
  51555 
  51556 func U32ToS8(tls *libc.TLS, v uint32_t) (r int8_t) {
  51557 	return int8(v & libc.Uint32FromInt32(0xff))
  51558 }
  51559 
  51560 func VP8LTransformColor_C(tls *libc.TLS, m uintptr, data uintptr, num_pixels int32) {
  51561 	var argb uint32_t
  51562 	var green, red int8_t
  51563 	var i, new_blue, new_red int32
  51564 	_, _, _, _, _, _ = argb, green, i, new_blue, new_red, red
  51565 	i = 0
  51566 	for {
  51567 		if !(i < num_pixels) {
  51568 			break
  51569 		}
  51570 		argb = **(**uint32_t)(__ccgo_up(data + uintptr(i)*4))
  51571 		green = U32ToS8(tls, argb>>int32(8))
  51572 		red = U32ToS8(tls, argb>>int32(16))
  51573 		new_red = int32(red) & int32(0xff)
  51574 		new_blue = int32(argb & uint32(0xff))
  51575 		new_red = new_red - ColorTransformDelta1(tls, int8((*VP8LMultipliers)(unsafe.Pointer(m)).Fgreen_to_red), green)
  51576 		new_red = new_red & int32(0xff)
  51577 		new_blue = new_blue - ColorTransformDelta1(tls, int8((*VP8LMultipliers)(unsafe.Pointer(m)).Fgreen_to_blue), green)
  51578 		new_blue = new_blue - ColorTransformDelta1(tls, int8((*VP8LMultipliers)(unsafe.Pointer(m)).Fred_to_blue), red)
  51579 		new_blue = new_blue & int32(0xff)
  51580 		**(**uint32_t)(__ccgo_up(data + uintptr(i)*4)) = argb&uint32(0xff00ff00) | uint32(new_red<<libc.Int32FromInt32(16)) | uint32(new_blue)
  51581 		goto _1
  51582 	_1:
  51583 		;
  51584 		i = i + 1
  51585 	}
  51586 }
  51587 
  51588 func TransformColorRed(tls *libc.TLS, green_to_red uint8_t, argb uint32_t) (r uint8_t) {
  51589 	var green int8_t
  51590 	var new_red int32
  51591 	_, _ = green, new_red
  51592 	green = U32ToS8(tls, argb>>int32(8))
  51593 	new_red = int32(argb >> int32(16))
  51594 	new_red = new_red - ColorTransformDelta1(tls, int8(green_to_red), green)
  51595 	return uint8(new_red & libc.Int32FromInt32(0xff))
  51596 }
  51597 
  51598 func TransformColorBlue(tls *libc.TLS, green_to_blue uint8_t, red_to_blue uint8_t, argb uint32_t) (r uint8_t) {
  51599 	var green, red int8_t
  51600 	var new_blue int32
  51601 	_, _, _ = green, new_blue, red
  51602 	green = U32ToS8(tls, argb>>int32(8))
  51603 	red = U32ToS8(tls, argb>>int32(16))
  51604 	new_blue = int32(argb & uint32(0xff))
  51605 	new_blue = new_blue - ColorTransformDelta1(tls, int8(green_to_blue), green)
  51606 	new_blue = new_blue - ColorTransformDelta1(tls, int8(red_to_blue), red)
  51607 	return uint8(new_blue & libc.Int32FromInt32(0xff))
  51608 }
  51609 
  51610 func VP8LCollectColorRedTransforms_C(tls *libc.TLS, argb uintptr, stride int32, tile_width int32, tile_height int32, green_to_red int32, histo uintptr) {
  51611 	var x, v1 int32
  51612 	_, _ = x, v1
  51613 	for {
  51614 		v1 = tile_height
  51615 		tile_height = tile_height - 1
  51616 		if !(v1 > 0) {
  51617 			break
  51618 		}
  51619 		x = 0
  51620 		for {
  51621 			if !(x < tile_width) {
  51622 				break
  51623 			}
  51624 			**(**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
  51625 			goto _2
  51626 		_2:
  51627 			;
  51628 			x = x + 1
  51629 		}
  51630 		argb = argb + uintptr(stride)*4
  51631 	}
  51632 }
  51633 
  51634 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) {
  51635 	var x, v1 int32
  51636 	_, _ = x, v1
  51637 	for {
  51638 		v1 = tile_height
  51639 		tile_height = tile_height - 1
  51640 		if !(v1 > 0) {
  51641 			break
  51642 		}
  51643 		x = 0
  51644 		for {
  51645 			if !(x < tile_width) {
  51646 				break
  51647 			}
  51648 			**(**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
  51649 			goto _2
  51650 		_2:
  51651 			;
  51652 			x = x + 1
  51653 		}
  51654 		argb = argb + uintptr(stride)*4
  51655 	}
  51656 }
  51657 
  51658 //------------------------------------------------------------------------------
  51659 
  51660 func VectorMismatch_C(tls *libc.TLS, array1 uintptr, array2 uintptr, length int32) (r int32) {
  51661 	var match_len int32
  51662 	_ = match_len
  51663 	match_len = 0
  51664 	for match_len < length && **(**uint32_t)(__ccgo_up(array1 + uintptr(match_len)*4)) == **(**uint32_t)(__ccgo_up(array2 + uintptr(match_len)*4)) {
  51665 		match_len = match_len + 1
  51666 	}
  51667 	return match_len
  51668 }
  51669 
  51670 // C documentation
  51671 //
  51672 //	// Bundles multiple (1, 2, 4 or 8) pixels into a single pixel.
  51673 func VP8LBundleColorMap_C(tls *libc.TLS, row uintptr, width int32, xbits int32, dst uintptr) {
  51674 	var bit_depth, mask, x, xsub int32
  51675 	var code uint32_t
  51676 	_, _, _, _, _ = bit_depth, code, mask, x, xsub
  51677 	if xbits > 0 {
  51678 		bit_depth = int32(1) << (int32(3) - xbits)
  51679 		mask = int32(1)<<xbits - int32(1)
  51680 		code = uint32(0xff000000)
  51681 		x = 0
  51682 		for {
  51683 			if !(x < width) {
  51684 				break
  51685 			}
  51686 			xsub = x & mask
  51687 			if xsub == 0 {
  51688 				code = uint32(0xff000000)
  51689 			}
  51690 			code = code | uint32(int32(**(**uint8_t)(__ccgo_up(row + uintptr(x))))<<(int32(8)+bit_depth*xsub))
  51691 			**(**uint32_t)(__ccgo_up(dst + uintptr(x>>xbits)*4)) = code
  51692 			goto _1
  51693 		_1:
  51694 			;
  51695 			x = x + 1
  51696 		}
  51697 	} else {
  51698 		x = 0
  51699 		for {
  51700 			if !(x < width) {
  51701 				break
  51702 			}
  51703 			**(**uint32_t)(__ccgo_up(dst + uintptr(x)*4)) = uint32(0xff000000) | uint32(int32(**(**uint8_t)(__ccgo_up(row + uintptr(x))))<<libc.Int32FromInt32(8))
  51704 			goto _2
  51705 		_2:
  51706 			;
  51707 			x = x + 1
  51708 		}
  51709 	}
  51710 }
  51711 
  51712 //------------------------------------------------------------------------------
  51713 
  51714 func ExtraCost_C(tls *libc.TLS, population uintptr, length int32) (r uint32_t) {
  51715 	var cost uint32_t
  51716 	var i int32
  51717 	_, _ = cost, i
  51718 	cost = **(**uint32_t)(__ccgo_up(population + 4*4)) + **(**uint32_t)(__ccgo_up(population + 5*4))
  51719 	i = int32(2)
  51720 	for {
  51721 		if !(i < length/int32(2)-int32(1)) {
  51722 			break
  51723 		}
  51724 		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)))
  51725 		goto _1
  51726 	_1:
  51727 		;
  51728 		i = i + 1
  51729 	}
  51730 	return cost
  51731 }
  51732 
  51733 //------------------------------------------------------------------------------
  51734 
  51735 func AddVector_C(tls *libc.TLS, a uintptr, b uintptr, out uintptr, size int32) {
  51736 	var i int32
  51737 	_ = i
  51738 	i = 0
  51739 	for {
  51740 		if !(i < size) {
  51741 			break
  51742 		}
  51743 		**(**uint32_t)(__ccgo_up(out + uintptr(i)*4)) = **(**uint32_t)(__ccgo_up(a + uintptr(i)*4)) + **(**uint32_t)(__ccgo_up(b + uintptr(i)*4))
  51744 		goto _1
  51745 	_1:
  51746 		;
  51747 		i = i + 1
  51748 	}
  51749 }
  51750 
  51751 func AddVectorEq_C(tls *libc.TLS, a uintptr, out uintptr, size int32) {
  51752 	var i int32
  51753 	_ = i
  51754 	i = 0
  51755 	for {
  51756 		if !(i < size) {
  51757 			break
  51758 		}
  51759 		**(**uint32_t)(__ccgo_up(out + uintptr(i)*4)) += **(**uint32_t)(__ccgo_up(a + uintptr(i)*4))
  51760 		goto _1
  51761 	_1:
  51762 		;
  51763 		i = i + 1
  51764 	}
  51765 }
  51766 
  51767 //------------------------------------------------------------------------------
  51768 // Image transforms.
  51769 
  51770 func PredictorSub0_C(tls *libc.TLS, in uintptr, upper uintptr, num_pixels int32, out uintptr) {
  51771 	var alpha_and_green, red_and_blue, v2, v3, v4 uint32_t
  51772 	var i int32
  51773 	_, _, _, _, _, _ = alpha_and_green, i, red_and_blue, v2, v3, v4
  51774 	i = 0
  51775 	for {
  51776 		if !(i < num_pixels) {
  51777 			break
  51778 		}
  51779 		v2 = **(**uint32_t)(__ccgo_up(in + uintptr(i)*4))
  51780 		v3 = uint32(ARGB_BLACK3)
  51781 		alpha_and_green = uint32(0x00ff00ff) + v2&uint32(0xff00ff00) - v3&uint32(0xff00ff00)
  51782 		red_and_blue = uint32(0xff00ff00) + v2&uint32(0x00ff00ff) - v3&uint32(0x00ff00ff)
  51783 		v4 = alpha_and_green&uint32(0xff00ff00) | red_and_blue&uint32(0x00ff00ff)
  51784 		goto _5
  51785 	_5:
  51786 		**(**uint32_t)(__ccgo_up(out + uintptr(i)*4)) = v4
  51787 		goto _1
  51788 	_1:
  51789 		;
  51790 		i = i + 1
  51791 	}
  51792 	_ = upper
  51793 }
  51794 
  51795 func PredictorSub1_C(tls *libc.TLS, in uintptr, upper uintptr, num_pixels int32, out uintptr) {
  51796 	var alpha_and_green, red_and_blue, v2, v3, v4 uint32_t
  51797 	var i int32
  51798 	_, _, _, _, _, _ = alpha_and_green, i, red_and_blue, v2, v3, v4
  51799 	i = 0
  51800 	for {
  51801 		if !(i < num_pixels) {
  51802 			break
  51803 		}
  51804 		v2 = **(**uint32_t)(__ccgo_up(in + uintptr(i)*4))
  51805 		v3 = **(**uint32_t)(__ccgo_up(in + uintptr(i-int32(1))*4))
  51806 		alpha_and_green = uint32(0x00ff00ff) + v2&uint32(0xff00ff00) - v3&uint32(0xff00ff00)
  51807 		red_and_blue = uint32(0xff00ff00) + v2&uint32(0x00ff00ff) - v3&uint32(0x00ff00ff)
  51808 		v4 = alpha_and_green&uint32(0xff00ff00) | red_and_blue&uint32(0x00ff00ff)
  51809 		goto _5
  51810 	_5:
  51811 		**(**uint32_t)(__ccgo_up(out + uintptr(i)*4)) = v4
  51812 		goto _1
  51813 	_1:
  51814 		;
  51815 		i = i + 1
  51816 	}
  51817 	_ = upper
  51818 }
  51819 
  51820 // It subtracts the prediction from the input pixel and stores the residual
  51821 // in the output pixel.
  51822 func PredictorSub2_C(tls *libc.TLS, in uintptr, upper uintptr, num_pixels int32, out uintptr) {
  51823 	var alpha_and_green, pred, red_and_blue, v2, v3, v4 uint32_t
  51824 	var x int32
  51825 	_, _, _, _, _, _, _ = alpha_and_green, pred, red_and_blue, x, v2, v3, v4
  51826 	x = 0
  51827 	for {
  51828 		if !(x < num_pixels) {
  51829 			break
  51830 		}
  51831 		pred = VP8LPredictor2_C(tls, in+uintptr(x-int32(1))*4, upper+uintptr(x)*4)
  51832 		v2 = **(**uint32_t)(__ccgo_up(in + uintptr(x)*4))
  51833 		v3 = pred
  51834 		alpha_and_green = uint32(0x00ff00ff) + v2&uint32(0xff00ff00) - v3&uint32(0xff00ff00)
  51835 		red_and_blue = uint32(0xff00ff00) + v2&uint32(0x00ff00ff) - v3&uint32(0x00ff00ff)
  51836 		v4 = alpha_and_green&uint32(0xff00ff00) | red_and_blue&uint32(0x00ff00ff)
  51837 		goto _5
  51838 	_5:
  51839 		**(**uint32_t)(__ccgo_up(out + uintptr(x)*4)) = v4
  51840 		goto _1
  51841 	_1:
  51842 		;
  51843 		x = x + 1
  51844 	}
  51845 }
  51846 
  51847 func PredictorSub3_C(tls *libc.TLS, in uintptr, upper uintptr, num_pixels int32, out uintptr) {
  51848 	var alpha_and_green, pred, red_and_blue, v2, v3, v4 uint32_t
  51849 	var x int32
  51850 	_, _, _, _, _, _, _ = alpha_and_green, pred, red_and_blue, x, v2, v3, v4
  51851 	x = 0
  51852 	for {
  51853 		if !(x < num_pixels) {
  51854 			break
  51855 		}
  51856 		pred = VP8LPredictor3_C(tls, in+uintptr(x-int32(1))*4, upper+uintptr(x)*4)
  51857 		v2 = **(**uint32_t)(__ccgo_up(in + uintptr(x)*4))
  51858 		v3 = pred
  51859 		alpha_and_green = uint32(0x00ff00ff) + v2&uint32(0xff00ff00) - v3&uint32(0xff00ff00)
  51860 		red_and_blue = uint32(0xff00ff00) + v2&uint32(0x00ff00ff) - v3&uint32(0x00ff00ff)
  51861 		v4 = alpha_and_green&uint32(0xff00ff00) | red_and_blue&uint32(0x00ff00ff)
  51862 		goto _5
  51863 	_5:
  51864 		**(**uint32_t)(__ccgo_up(out + uintptr(x)*4)) = v4
  51865 		goto _1
  51866 	_1:
  51867 		;
  51868 		x = x + 1
  51869 	}
  51870 }
  51871 
  51872 func PredictorSub4_C(tls *libc.TLS, in uintptr, upper uintptr, num_pixels int32, out uintptr) {
  51873 	var alpha_and_green, pred, red_and_blue, v2, v3, v4 uint32_t
  51874 	var x int32
  51875 	_, _, _, _, _, _, _ = alpha_and_green, pred, red_and_blue, x, v2, v3, v4
  51876 	x = 0
  51877 	for {
  51878 		if !(x < num_pixels) {
  51879 			break
  51880 		}
  51881 		pred = VP8LPredictor4_C(tls, in+uintptr(x-int32(1))*4, upper+uintptr(x)*4)
  51882 		v2 = **(**uint32_t)(__ccgo_up(in + uintptr(x)*4))
  51883 		v3 = pred
  51884 		alpha_and_green = uint32(0x00ff00ff) + v2&uint32(0xff00ff00) - v3&uint32(0xff00ff00)
  51885 		red_and_blue = uint32(0xff00ff00) + v2&uint32(0x00ff00ff) - v3&uint32(0x00ff00ff)
  51886 		v4 = alpha_and_green&uint32(0xff00ff00) | red_and_blue&uint32(0x00ff00ff)
  51887 		goto _5
  51888 	_5:
  51889 		**(**uint32_t)(__ccgo_up(out + uintptr(x)*4)) = v4
  51890 		goto _1
  51891 	_1:
  51892 		;
  51893 		x = x + 1
  51894 	}
  51895 }
  51896 
  51897 func PredictorSub5_C(tls *libc.TLS, in uintptr, upper uintptr, num_pixels int32, out uintptr) {
  51898 	var alpha_and_green, pred, red_and_blue, v2, v3, v4 uint32_t
  51899 	var x int32
  51900 	_, _, _, _, _, _, _ = alpha_and_green, pred, red_and_blue, x, v2, v3, v4
  51901 	x = 0
  51902 	for {
  51903 		if !(x < num_pixels) {
  51904 			break
  51905 		}
  51906 		pred = VP8LPredictor5_C(tls, in+uintptr(x-int32(1))*4, upper+uintptr(x)*4)
  51907 		v2 = **(**uint32_t)(__ccgo_up(in + uintptr(x)*4))
  51908 		v3 = pred
  51909 		alpha_and_green = uint32(0x00ff00ff) + v2&uint32(0xff00ff00) - v3&uint32(0xff00ff00)
  51910 		red_and_blue = uint32(0xff00ff00) + v2&uint32(0x00ff00ff) - v3&uint32(0x00ff00ff)
  51911 		v4 = alpha_and_green&uint32(0xff00ff00) | red_and_blue&uint32(0x00ff00ff)
  51912 		goto _5
  51913 	_5:
  51914 		**(**uint32_t)(__ccgo_up(out + uintptr(x)*4)) = v4
  51915 		goto _1
  51916 	_1:
  51917 		;
  51918 		x = x + 1
  51919 	}
  51920 }
  51921 
  51922 func PredictorSub6_C(tls *libc.TLS, in uintptr, upper uintptr, num_pixels int32, out uintptr) {
  51923 	var alpha_and_green, pred, red_and_blue, v2, v3, v4 uint32_t
  51924 	var x int32
  51925 	_, _, _, _, _, _, _ = alpha_and_green, pred, red_and_blue, x, v2, v3, v4
  51926 	x = 0
  51927 	for {
  51928 		if !(x < num_pixels) {
  51929 			break
  51930 		}
  51931 		pred = VP8LPredictor6_C(tls, in+uintptr(x-int32(1))*4, upper+uintptr(x)*4)
  51932 		v2 = **(**uint32_t)(__ccgo_up(in + uintptr(x)*4))
  51933 		v3 = pred
  51934 		alpha_and_green = uint32(0x00ff00ff) + v2&uint32(0xff00ff00) - v3&uint32(0xff00ff00)
  51935 		red_and_blue = uint32(0xff00ff00) + v2&uint32(0x00ff00ff) - v3&uint32(0x00ff00ff)
  51936 		v4 = alpha_and_green&uint32(0xff00ff00) | red_and_blue&uint32(0x00ff00ff)
  51937 		goto _5
  51938 	_5:
  51939 		**(**uint32_t)(__ccgo_up(out + uintptr(x)*4)) = v4
  51940 		goto _1
  51941 	_1:
  51942 		;
  51943 		x = x + 1
  51944 	}
  51945 }
  51946 
  51947 func PredictorSub7_C(tls *libc.TLS, in uintptr, upper uintptr, num_pixels int32, out uintptr) {
  51948 	var alpha_and_green, pred, red_and_blue, v2, v3, v4 uint32_t
  51949 	var x int32
  51950 	_, _, _, _, _, _, _ = alpha_and_green, pred, red_and_blue, x, v2, v3, v4
  51951 	x = 0
  51952 	for {
  51953 		if !(x < num_pixels) {
  51954 			break
  51955 		}
  51956 		pred = VP8LPredictor7_C(tls, in+uintptr(x-int32(1))*4, upper+uintptr(x)*4)
  51957 		v2 = **(**uint32_t)(__ccgo_up(in + uintptr(x)*4))
  51958 		v3 = pred
  51959 		alpha_and_green = uint32(0x00ff00ff) + v2&uint32(0xff00ff00) - v3&uint32(0xff00ff00)
  51960 		red_and_blue = uint32(0xff00ff00) + v2&uint32(0x00ff00ff) - v3&uint32(0x00ff00ff)
  51961 		v4 = alpha_and_green&uint32(0xff00ff00) | red_and_blue&uint32(0x00ff00ff)
  51962 		goto _5
  51963 	_5:
  51964 		**(**uint32_t)(__ccgo_up(out + uintptr(x)*4)) = v4
  51965 		goto _1
  51966 	_1:
  51967 		;
  51968 		x = x + 1
  51969 	}
  51970 }
  51971 
  51972 func PredictorSub8_C(tls *libc.TLS, in uintptr, upper uintptr, num_pixels int32, out uintptr) {
  51973 	var alpha_and_green, pred, red_and_blue, v2, v3, v4 uint32_t
  51974 	var x int32
  51975 	_, _, _, _, _, _, _ = alpha_and_green, pred, red_and_blue, x, v2, v3, v4
  51976 	x = 0
  51977 	for {
  51978 		if !(x < num_pixels) {
  51979 			break
  51980 		}
  51981 		pred = VP8LPredictor8_C(tls, in+uintptr(x-int32(1))*4, upper+uintptr(x)*4)
  51982 		v2 = **(**uint32_t)(__ccgo_up(in + uintptr(x)*4))
  51983 		v3 = pred
  51984 		alpha_and_green = uint32(0x00ff00ff) + v2&uint32(0xff00ff00) - v3&uint32(0xff00ff00)
  51985 		red_and_blue = uint32(0xff00ff00) + v2&uint32(0x00ff00ff) - v3&uint32(0x00ff00ff)
  51986 		v4 = alpha_and_green&uint32(0xff00ff00) | red_and_blue&uint32(0x00ff00ff)
  51987 		goto _5
  51988 	_5:
  51989 		**(**uint32_t)(__ccgo_up(out + uintptr(x)*4)) = v4
  51990 		goto _1
  51991 	_1:
  51992 		;
  51993 		x = x + 1
  51994 	}
  51995 }
  51996 
  51997 func PredictorSub9_C(tls *libc.TLS, in uintptr, upper uintptr, num_pixels int32, out uintptr) {
  51998 	var alpha_and_green, pred, red_and_blue, v2, v3, v4 uint32_t
  51999 	var x int32
  52000 	_, _, _, _, _, _, _ = alpha_and_green, pred, red_and_blue, x, v2, v3, v4
  52001 	x = 0
  52002 	for {
  52003 		if !(x < num_pixels) {
  52004 			break
  52005 		}
  52006 		pred = VP8LPredictor9_C(tls, in+uintptr(x-int32(1))*4, upper+uintptr(x)*4)
  52007 		v2 = **(**uint32_t)(__ccgo_up(in + uintptr(x)*4))
  52008 		v3 = pred
  52009 		alpha_and_green = uint32(0x00ff00ff) + v2&uint32(0xff00ff00) - v3&uint32(0xff00ff00)
  52010 		red_and_blue = uint32(0xff00ff00) + v2&uint32(0x00ff00ff) - v3&uint32(0x00ff00ff)
  52011 		v4 = alpha_and_green&uint32(0xff00ff00) | red_and_blue&uint32(0x00ff00ff)
  52012 		goto _5
  52013 	_5:
  52014 		**(**uint32_t)(__ccgo_up(out + uintptr(x)*4)) = v4
  52015 		goto _1
  52016 	_1:
  52017 		;
  52018 		x = x + 1
  52019 	}
  52020 }
  52021 
  52022 func PredictorSub10_C(tls *libc.TLS, in uintptr, upper uintptr, num_pixels int32, out uintptr) {
  52023 	var alpha_and_green, pred, red_and_blue, v2, v3, v4 uint32_t
  52024 	var x int32
  52025 	_, _, _, _, _, _, _ = alpha_and_green, pred, red_and_blue, x, v2, v3, v4
  52026 	x = 0
  52027 	for {
  52028 		if !(x < num_pixels) {
  52029 			break
  52030 		}
  52031 		pred = VP8LPredictor10_C(tls, in+uintptr(x-int32(1))*4, upper+uintptr(x)*4)
  52032 		v2 = **(**uint32_t)(__ccgo_up(in + uintptr(x)*4))
  52033 		v3 = pred
  52034 		alpha_and_green = uint32(0x00ff00ff) + v2&uint32(0xff00ff00) - v3&uint32(0xff00ff00)
  52035 		red_and_blue = uint32(0xff00ff00) + v2&uint32(0x00ff00ff) - v3&uint32(0x00ff00ff)
  52036 		v4 = alpha_and_green&uint32(0xff00ff00) | red_and_blue&uint32(0x00ff00ff)
  52037 		goto _5
  52038 	_5:
  52039 		**(**uint32_t)(__ccgo_up(out + uintptr(x)*4)) = v4
  52040 		goto _1
  52041 	_1:
  52042 		;
  52043 		x = x + 1
  52044 	}
  52045 }
  52046 
  52047 func PredictorSub11_C(tls *libc.TLS, in uintptr, upper uintptr, num_pixels int32, out uintptr) {
  52048 	var alpha_and_green, pred, red_and_blue, v2, v3, v4 uint32_t
  52049 	var x int32
  52050 	_, _, _, _, _, _, _ = alpha_and_green, pred, red_and_blue, x, v2, v3, v4
  52051 	x = 0
  52052 	for {
  52053 		if !(x < num_pixels) {
  52054 			break
  52055 		}
  52056 		pred = VP8LPredictor11_C(tls, in+uintptr(x-int32(1))*4, upper+uintptr(x)*4)
  52057 		v2 = **(**uint32_t)(__ccgo_up(in + uintptr(x)*4))
  52058 		v3 = pred
  52059 		alpha_and_green = uint32(0x00ff00ff) + v2&uint32(0xff00ff00) - v3&uint32(0xff00ff00)
  52060 		red_and_blue = uint32(0xff00ff00) + v2&uint32(0x00ff00ff) - v3&uint32(0x00ff00ff)
  52061 		v4 = alpha_and_green&uint32(0xff00ff00) | red_and_blue&uint32(0x00ff00ff)
  52062 		goto _5
  52063 	_5:
  52064 		**(**uint32_t)(__ccgo_up(out + uintptr(x)*4)) = v4
  52065 		goto _1
  52066 	_1:
  52067 		;
  52068 		x = x + 1
  52069 	}
  52070 }
  52071 
  52072 func PredictorSub12_C(tls *libc.TLS, in uintptr, upper uintptr, num_pixels int32, out uintptr) {
  52073 	var alpha_and_green, pred, red_and_blue, v2, v3, v4 uint32_t
  52074 	var x int32
  52075 	_, _, _, _, _, _, _ = alpha_and_green, pred, red_and_blue, x, v2, v3, v4
  52076 	x = 0
  52077 	for {
  52078 		if !(x < num_pixels) {
  52079 			break
  52080 		}
  52081 		pred = VP8LPredictor12_C(tls, in+uintptr(x-int32(1))*4, upper+uintptr(x)*4)
  52082 		v2 = **(**uint32_t)(__ccgo_up(in + uintptr(x)*4))
  52083 		v3 = pred
  52084 		alpha_and_green = uint32(0x00ff00ff) + v2&uint32(0xff00ff00) - v3&uint32(0xff00ff00)
  52085 		red_and_blue = uint32(0xff00ff00) + v2&uint32(0x00ff00ff) - v3&uint32(0x00ff00ff)
  52086 		v4 = alpha_and_green&uint32(0xff00ff00) | red_and_blue&uint32(0x00ff00ff)
  52087 		goto _5
  52088 	_5:
  52089 		**(**uint32_t)(__ccgo_up(out + uintptr(x)*4)) = v4
  52090 		goto _1
  52091 	_1:
  52092 		;
  52093 		x = x + 1
  52094 	}
  52095 }
  52096 
  52097 func PredictorSub13_C(tls *libc.TLS, in uintptr, upper uintptr, num_pixels int32, out uintptr) {
  52098 	var alpha_and_green, pred, red_and_blue, v2, v3, v4 uint32_t
  52099 	var x int32
  52100 	_, _, _, _, _, _, _ = alpha_and_green, pred, red_and_blue, x, v2, v3, v4
  52101 	x = 0
  52102 	for {
  52103 		if !(x < num_pixels) {
  52104 			break
  52105 		}
  52106 		pred = VP8LPredictor13_C(tls, in+uintptr(x-int32(1))*4, upper+uintptr(x)*4)
  52107 		v2 = **(**uint32_t)(__ccgo_up(in + uintptr(x)*4))
  52108 		v3 = pred
  52109 		alpha_and_green = uint32(0x00ff00ff) + v2&uint32(0xff00ff00) - v3&uint32(0xff00ff00)
  52110 		red_and_blue = uint32(0xff00ff00) + v2&uint32(0x00ff00ff) - v3&uint32(0x00ff00ff)
  52111 		v4 = alpha_and_green&uint32(0xff00ff00) | red_and_blue&uint32(0x00ff00ff)
  52112 		goto _5
  52113 	_5:
  52114 		**(**uint32_t)(__ccgo_up(out + uintptr(x)*4)) = v4
  52115 		goto _1
  52116 	_1:
  52117 		;
  52118 		x = x + 1
  52119 	}
  52120 }
  52121 
  52122 func VP8LEncDspInit(tls *libc.TLS) {
  52123 	if libc.AtomicLoadPUintptr(uintptr(unsafe.Pointer(&VP8LEncDspInit_body_last_cpuinfo_used))) == VP8GetCPUInfo {
  52124 		goto _1
  52125 	}
  52126 	VP8LEncDspInit_body(tls)
  52127 	libc.AtomicStorePUintptr(uintptr(unsafe.Pointer(&VP8LEncDspInit_body_last_cpuinfo_used)), VP8GetCPUInfo)
  52128 	goto _2
  52129 _2:
  52130 	;
  52131 	goto _1
  52132 _1: /**/ //
  52133 }
  52134 
  52135 var VP8LEncDspInit_body_last_cpuinfo_used = uintptr(0)
  52136 
  52137 func init() {
  52138 	p := unsafe.Pointer(&VP8LEncDspInit_body_last_cpuinfo_used)
  52139 	*(*uintptr)(unsafe.Add(p, 0)) = uintptr(unsafe.Pointer(&VP8LEncDspInit_body_last_cpuinfo_used))
  52140 }
  52141 
  52142 func VP8LEncDspInit_body(tls *libc.TLS) {
  52143 	VP8LDspInit(tls)
  52144 	VP8LSubtractGreenFromBlueAndRed = __ccgo_fp(VP8LSubtractGreenFromBlueAndRed_C)
  52145 	VP8LTransformColor = __ccgo_fp(VP8LTransformColor_C)
  52146 	VP8LCollectColorBlueTransforms = __ccgo_fp(VP8LCollectColorBlueTransforms_C)
  52147 	VP8LCollectColorRedTransforms = __ccgo_fp(VP8LCollectColorRedTransforms_C)
  52148 	VP8LFastLog2Slow = __ccgo_fp(FastLog2Slow_C)
  52149 	VP8LFastSLog2Slow = __ccgo_fp(FastSLog2Slow_C)
  52150 	VP8LExtraCost = __ccgo_fp(ExtraCost_C)
  52151 	VP8LCombinedShannonEntropy = __ccgo_fp(CombinedShannonEntropy_C)
  52152 	VP8LShannonEntropy = __ccgo_fp(ShannonEntropy_C)
  52153 	VP8LGetEntropyUnrefined = __ccgo_fp(GetEntropyUnrefined_C)
  52154 	VP8LGetCombinedEntropyUnrefined = __ccgo_fp(GetCombinedEntropyUnrefined_C)
  52155 	VP8LAddVector = __ccgo_fp(AddVector_C)
  52156 	VP8LAddVectorEq = __ccgo_fp(AddVectorEq_C)
  52157 	VP8LVectorMismatch = __ccgo_fp(VectorMismatch_C)
  52158 	VP8LBundleColorMap = __ccgo_fp(VP8LBundleColorMap_C)
  52159 	VP8LPredictorsSub[0] = __ccgo_fp(PredictorSub0_C)
  52160 	VP8LPredictorsSub[int32(1)] = __ccgo_fp(PredictorSub1_C)
  52161 	VP8LPredictorsSub[int32(2)] = __ccgo_fp(PredictorSub2_C)
  52162 	VP8LPredictorsSub[int32(3)] = __ccgo_fp(PredictorSub3_C)
  52163 	VP8LPredictorsSub[int32(4)] = __ccgo_fp(PredictorSub4_C)
  52164 	VP8LPredictorsSub[int32(5)] = __ccgo_fp(PredictorSub5_C)
  52165 	VP8LPredictorsSub[int32(6)] = __ccgo_fp(PredictorSub6_C)
  52166 	VP8LPredictorsSub[int32(7)] = __ccgo_fp(PredictorSub7_C)
  52167 	VP8LPredictorsSub[int32(8)] = __ccgo_fp(PredictorSub8_C)
  52168 	VP8LPredictorsSub[int32(9)] = __ccgo_fp(PredictorSub9_C)
  52169 	VP8LPredictorsSub[int32(10)] = __ccgo_fp(PredictorSub10_C)
  52170 	VP8LPredictorsSub[int32(11)] = __ccgo_fp(PredictorSub11_C)
  52171 	VP8LPredictorsSub[int32(12)] = __ccgo_fp(PredictorSub12_C)
  52172 	VP8LPredictorsSub[int32(13)] = __ccgo_fp(PredictorSub13_C)
  52173 	VP8LPredictorsSub[int32(14)] = __ccgo_fp(PredictorSub0_C) // <- padding security sentinels
  52174 	VP8LPredictorsSub[int32(15)] = __ccgo_fp(PredictorSub0_C)
  52175 	VP8LPredictorsSub_C[0] = __ccgo_fp(PredictorSub0_C)
  52176 	VP8LPredictorsSub_C[int32(1)] = __ccgo_fp(PredictorSub1_C)
  52177 	VP8LPredictorsSub_C[int32(2)] = __ccgo_fp(PredictorSub2_C)
  52178 	VP8LPredictorsSub_C[int32(3)] = __ccgo_fp(PredictorSub3_C)
  52179 	VP8LPredictorsSub_C[int32(4)] = __ccgo_fp(PredictorSub4_C)
  52180 	VP8LPredictorsSub_C[int32(5)] = __ccgo_fp(PredictorSub5_C)
  52181 	VP8LPredictorsSub_C[int32(6)] = __ccgo_fp(PredictorSub6_C)
  52182 	VP8LPredictorsSub_C[int32(7)] = __ccgo_fp(PredictorSub7_C)
  52183 	VP8LPredictorsSub_C[int32(8)] = __ccgo_fp(PredictorSub8_C)
  52184 	VP8LPredictorsSub_C[int32(9)] = __ccgo_fp(PredictorSub9_C)
  52185 	VP8LPredictorsSub_C[int32(10)] = __ccgo_fp(PredictorSub10_C)
  52186 	VP8LPredictorsSub_C[int32(11)] = __ccgo_fp(PredictorSub11_C)
  52187 	VP8LPredictorsSub_C[int32(12)] = __ccgo_fp(PredictorSub12_C)
  52188 	VP8LPredictorsSub_C[int32(13)] = __ccgo_fp(PredictorSub13_C)
  52189 	VP8LPredictorsSub_C[int32(14)] = __ccgo_fp(PredictorSub0_C) // <- padding security sentinels
  52190 	VP8LPredictorsSub_C[int32(15)] = __ccgo_fp(PredictorSub0_C)
  52191 	// If defined, use CPUInfo() to overwrite some pointers with faster versions.
  52192 	if VP8GetCPUInfo != libc.UintptrFromInt32(0) {
  52193 	}
  52194 }
  52195 
  52196 const LOG_2_RECIPROCAL_FIXED_DOUBLE2 = 12102203.161561485379934310913085937500
  52197 const SIZE_MAX29 = "UINT64_MAX"
  52198 
  52199 func VP8LEncDspInitMIPS32(tls *libc.TLS) {
  52200 }
  52201 
  52202 func VP8LEncDspInitMIPSdspR2(tls *libc.TLS) {
  52203 }
  52204 
  52205 func VP8LEncDspInitMSA(tls *libc.TLS) {
  52206 }
  52207 
  52208 func VP8LEncDspInitNEON(tls *libc.TLS) {
  52209 }
  52210 
  52211 func VP8LEncDspInitSSE2(tls *libc.TLS) {
  52212 }
  52213 
  52214 func VP8LEncDspInitSSE41(tls *libc.TLS) {
  52215 }
  52216 
  52217 func VP8LDspInitMIPSdspR2(tls *libc.TLS) {
  52218 }
  52219 
  52220 func VP8LDspInitMSA(tls *libc.TLS) {
  52221 }
  52222 
  52223 func VP8LDspInitNEON(tls *libc.TLS) {
  52224 }
  52225 
  52226 func VP8LDspInitSSE2(tls *libc.TLS) {
  52227 }
  52228 
  52229 func VP8LDspInitSSE41(tls *libc.TLS) {
  52230 }
  52231 
  52232 //------------------------------------------------------------------------------
  52233 
  52234 //------------------------------------------------------------------------------
  52235 // Implementations of critical functions ImportRow / ExportRow
  52236 
  52237 //------------------------------------------------------------------------------
  52238 // Row import
  52239 
  52240 func WebPRescalerImportRowExpand_C(tls *libc.TLS, wrk uintptr, src uintptr) {
  52241 	var accum, channel, x_in, x_out, x_out_max, x_stride int32
  52242 	var left, right rescaler_t
  52243 	var v2 uint32
  52244 	_, _, _, _, _, _, _, _, _ = accum, channel, left, right, x_in, x_out, x_out_max, x_stride, v2
  52245 	x_stride = (*WebPRescaler)(unsafe.Pointer(wrk)).Fnum_channels
  52246 	x_out_max = (*WebPRescaler)(unsafe.Pointer(wrk)).Fdst_width * (*WebPRescaler)(unsafe.Pointer(wrk)).Fnum_channels
  52247 	channel = 0
  52248 	for {
  52249 		if !(channel < x_stride) {
  52250 			break
  52251 		}
  52252 		x_in = channel
  52253 		x_out = channel
  52254 		// simple bilinear interpolation
  52255 		accum = (*WebPRescaler)(unsafe.Pointer(wrk)).Fx_add
  52256 		left = uint32(**(**uint8_t)(__ccgo_up(src + uintptr(x_in))))
  52257 		if (*WebPRescaler)(unsafe.Pointer(wrk)).Fsrc_width > int32(1) {
  52258 			v2 = uint32(**(**uint8_t)(__ccgo_up(src + uintptr(x_in+x_stride))))
  52259 		} else {
  52260 			v2 = left
  52261 		}
  52262 		right = v2
  52263 		x_in = x_in + x_stride
  52264 		for int32(1) != 0 {
  52265 			**(**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)
  52266 			x_out = x_out + x_stride
  52267 			if x_out >= x_out_max {
  52268 				break
  52269 			}
  52270 			accum = accum - (*WebPRescaler)(unsafe.Pointer(wrk)).Fx_sub
  52271 			if accum < 0 {
  52272 				left = right
  52273 				x_in = x_in + x_stride
  52274 				right = uint32(**(**uint8_t)(__ccgo_up(src + uintptr(x_in))))
  52275 				accum = accum + (*WebPRescaler)(unsafe.Pointer(wrk)).Fx_add
  52276 			}
  52277 		}
  52278 		goto _1
  52279 	_1:
  52280 		;
  52281 		channel = channel + 1
  52282 	}
  52283 }
  52284 
  52285 func WebPRescalerImportRowShrink_C(tls *libc.TLS, wrk uintptr, src uintptr) {
  52286 	var accum, channel, x_in, x_out, x_out_max, x_stride int32
  52287 	var base, sum uint32_t
  52288 	var frac rescaler_t
  52289 	_, _, _, _, _, _, _, _, _ = accum, base, channel, frac, sum, x_in, x_out, x_out_max, x_stride
  52290 	x_stride = (*WebPRescaler)(unsafe.Pointer(wrk)).Fnum_channels
  52291 	x_out_max = (*WebPRescaler)(unsafe.Pointer(wrk)).Fdst_width * (*WebPRescaler)(unsafe.Pointer(wrk)).Fnum_channels
  52292 	channel = 0
  52293 	for {
  52294 		if !(channel < x_stride) {
  52295 			break
  52296 		}
  52297 		x_in = channel
  52298 		x_out = channel
  52299 		sum = uint32(0)
  52300 		accum = 0
  52301 		for x_out < x_out_max {
  52302 			base = uint32(0)
  52303 			accum = accum + (*WebPRescaler)(unsafe.Pointer(wrk)).Fx_add
  52304 			for accum > 0 {
  52305 				accum = accum - (*WebPRescaler)(unsafe.Pointer(wrk)).Fx_sub
  52306 				base = uint32(**(**uint8_t)(__ccgo_up(src + uintptr(x_in))))
  52307 				sum = sum + base
  52308 				x_in = x_in + x_stride
  52309 			}
  52310 			// Emit next horizontal pixel.
  52311 			frac = base * uint32(-accum)
  52312 			**(**rescaler_t)(__ccgo_up((*WebPRescaler)(unsafe.Pointer(wrk)).Ffrow + uintptr(x_out)*4)) = sum*uint32((*WebPRescaler)(unsafe.Pointer(wrk)).Fx_sub) - frac
  52313 			// fresh fractional start for next pixel
  52314 			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)))
  52315 			x_out = x_out + x_stride
  52316 		}
  52317 		goto _1
  52318 	_1:
  52319 		;
  52320 		channel = channel + 1
  52321 	}
  52322 }
  52323 
  52324 //------------------------------------------------------------------------------
  52325 // Row export
  52326 
  52327 func WebPRescalerExportRowExpand_C(tls *libc.TLS, wrk uintptr) {
  52328 	var A, B, J, J1 uint32_t
  52329 	var I uint64_t
  52330 	var dst, frow, irow uintptr
  52331 	var v, v1, x_out, x_out_max int32
  52332 	var v2 uint32
  52333 	_, _, _, _, _, _, _, _, _, _, _, _, _ = A, B, I, J, J1, dst, frow, irow, v, v1, x_out, x_out_max, v2
  52334 	dst = (*WebPRescaler)(unsafe.Pointer(wrk)).Fdst
  52335 	irow = (*WebPRescaler)(unsafe.Pointer(wrk)).Firow
  52336 	x_out_max = (*WebPRescaler)(unsafe.Pointer(wrk)).Fdst_width * (*WebPRescaler)(unsafe.Pointer(wrk)).Fnum_channels
  52337 	frow = (*WebPRescaler)(unsafe.Pointer(wrk)).Ffrow
  52338 	if (*WebPRescaler)(unsafe.Pointer(wrk)).Fy_accum == 0 {
  52339 		x_out = 0
  52340 		for {
  52341 			if !(x_out < x_out_max) {
  52342 				break
  52343 			}
  52344 			J = **(**rescaler_t)(__ccgo_up(frow + uintptr(x_out)*4))
  52345 			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))
  52346 			if v > int32(255) {
  52347 				v2 = uint32(255)
  52348 			} else {
  52349 				v2 = uint32(uint8(v))
  52350 			}
  52351 			**(**uint8_t)(__ccgo_up(dst + uintptr(x_out))) = uint8(v2)
  52352 			goto _1
  52353 		_1:
  52354 			;
  52355 			x_out = x_out + 1
  52356 		}
  52357 	} else {
  52358 		B = uint32(uint64(-(*WebPRescaler)(unsafe.Pointer(wrk)).Fy_accum) << libc.Int32FromInt32(WEBP_RESCALER_RFIX) / uint64((*WebPRescaler)(unsafe.Pointer(wrk)).Fy_sub))
  52359 		A = uint32(libc.Uint64FromUint64(1)<<libc.Int32FromInt32(WEBP_RESCALER_RFIX) - uint64(B))
  52360 		x_out = 0
  52361 		for {
  52362 			if !(x_out < x_out_max) {
  52363 				break
  52364 			}
  52365 			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)))
  52366 			J1 = uint32((I + libc.Uint64FromUint64(1)<<libc.Int32FromInt32(WEBP_RESCALER_RFIX)>>libc.Int32FromInt32(1)) >> libc.Int32FromInt32(WEBP_RESCALER_RFIX))
  52367 			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))
  52368 			if v1 > int32(255) {
  52369 				v2 = uint32(255)
  52370 			} else {
  52371 				v2 = uint32(uint8(v1))
  52372 			}
  52373 			**(**uint8_t)(__ccgo_up(dst + uintptr(x_out))) = uint8(v2)
  52374 			goto _3
  52375 		_3:
  52376 			;
  52377 			x_out = x_out + 1
  52378 		}
  52379 	}
  52380 }
  52381 
  52382 func WebPRescalerExportRowShrink_C(tls *libc.TLS, wrk uintptr) {
  52383 	var dst, frow, irow uintptr
  52384 	var frac, yscale uint32_t
  52385 	var v, v1, x_out, x_out_max int32
  52386 	var v2 uint32
  52387 	_, _, _, _, _, _, _, _, _, _ = dst, frac, frow, irow, v, v1, x_out, x_out_max, yscale, v2
  52388 	dst = (*WebPRescaler)(unsafe.Pointer(wrk)).Fdst
  52389 	irow = (*WebPRescaler)(unsafe.Pointer(wrk)).Firow
  52390 	x_out_max = (*WebPRescaler)(unsafe.Pointer(wrk)).Fdst_width * (*WebPRescaler)(unsafe.Pointer(wrk)).Fnum_channels
  52391 	frow = (*WebPRescaler)(unsafe.Pointer(wrk)).Ffrow
  52392 	yscale = (*WebPRescaler)(unsafe.Pointer(wrk)).Ffy_scale * uint32(-(*WebPRescaler)(unsafe.Pointer(wrk)).Fy_accum)
  52393 	if yscale != 0 {
  52394 		x_out = 0
  52395 		for {
  52396 			if !(x_out < x_out_max) {
  52397 				break
  52398 			}
  52399 			frac = uint32(uint64(**(**rescaler_t)(__ccgo_up(frow + uintptr(x_out)*4))) * uint64(yscale) >> libc.Int32FromInt32(WEBP_RESCALER_RFIX))
  52400 			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))
  52401 			if v > int32(255) {
  52402 				v2 = uint32(255)
  52403 			} else {
  52404 				v2 = uint32(uint8(v))
  52405 			}
  52406 			**(**uint8_t)(__ccgo_up(dst + uintptr(x_out))) = uint8(v2)
  52407 			**(**rescaler_t)(__ccgo_up(irow + uintptr(x_out)*4)) = frac // new fractional start
  52408 			goto _1
  52409 		_1:
  52410 			;
  52411 			x_out = x_out + 1
  52412 		}
  52413 	} else {
  52414 		x_out = 0
  52415 		for {
  52416 			if !(x_out < x_out_max) {
  52417 				break
  52418 			}
  52419 			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))
  52420 			if v1 > int32(255) {
  52421 				v2 = uint32(255)
  52422 			} else {
  52423 				v2 = uint32(uint8(v1))
  52424 			}
  52425 			**(**uint8_t)(__ccgo_up(dst + uintptr(x_out))) = uint8(v2)
  52426 			**(**rescaler_t)(__ccgo_up(irow + uintptr(x_out)*4)) = uint32(0)
  52427 			goto _3
  52428 		_3:
  52429 			;
  52430 			x_out = x_out + 1
  52431 		}
  52432 	}
  52433 }
  52434 
  52435 //------------------------------------------------------------------------------
  52436 // Main entry calls
  52437 
  52438 func WebPRescalerImportRow(tls *libc.TLS, wrk uintptr, src uintptr) {
  52439 	if !((*WebPRescaler)(unsafe.Pointer(wrk)).Fx_expand != 0) {
  52440 		(*(*func(*libc.TLS, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{WebPRescalerImportRowShrink})))(tls, wrk, src)
  52441 	} else {
  52442 		(*(*func(*libc.TLS, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{WebPRescalerImportRowExpand})))(tls, wrk, src)
  52443 	}
  52444 }
  52445 
  52446 func WebPRescalerExportRow(tls *libc.TLS, wrk uintptr) {
  52447 	var i int32
  52448 	_ = i
  52449 	if (*WebPRescaler)(unsafe.Pointer(wrk)).Fy_accum <= 0 {
  52450 		if (*WebPRescaler)(unsafe.Pointer(wrk)).Fy_expand != 0 {
  52451 			(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(&struct{ uintptr }{WebPRescalerExportRowExpand})))(tls, wrk)
  52452 		} else {
  52453 			if (*WebPRescaler)(unsafe.Pointer(wrk)).Ffxy_scale != 0 {
  52454 				(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(&struct{ uintptr }{WebPRescalerExportRowShrink})))(tls, wrk)
  52455 			} else {
  52456 				i = 0
  52457 				for {
  52458 					if !(i < (*WebPRescaler)(unsafe.Pointer(wrk)).Fnum_channels*(*WebPRescaler)(unsafe.Pointer(wrk)).Fdst_width) {
  52459 						break
  52460 					}
  52461 					**(**uint8_t)(__ccgo_up((*WebPRescaler)(unsafe.Pointer(wrk)).Fdst + uintptr(i))) = uint8(**(**rescaler_t)(__ccgo_up((*WebPRescaler)(unsafe.Pointer(wrk)).Firow + uintptr(i)*4)))
  52462 					**(**rescaler_t)(__ccgo_up((*WebPRescaler)(unsafe.Pointer(wrk)).Firow + uintptr(i)*4)) = uint32(0)
  52463 					goto _1
  52464 				_1:
  52465 					;
  52466 					i = i + 1
  52467 				}
  52468 			}
  52469 		}
  52470 		**(**int32)(__ccgo_up(wrk + 24)) += (*WebPRescaler)(unsafe.Pointer(wrk)).Fy_add
  52471 		**(**uintptr)(__ccgo_up(wrk + 72)) += uintptr((*WebPRescaler)(unsafe.Pointer(wrk)).Fdst_stride)
  52472 		(*WebPRescaler)(unsafe.Pointer(wrk)).Fdst_y = (*WebPRescaler)(unsafe.Pointer(wrk)).Fdst_y + 1
  52473 	}
  52474 }
  52475 
  52476 func WebPRescalerDspInit(tls *libc.TLS) {
  52477 	if libc.AtomicLoadPUintptr(uintptr(unsafe.Pointer(&WebPRescalerDspInit_body_last_cpuinfo_used))) == VP8GetCPUInfo {
  52478 		goto _1
  52479 	}
  52480 	WebPRescalerDspInit_body(tls)
  52481 	libc.AtomicStorePUintptr(uintptr(unsafe.Pointer(&WebPRescalerDspInit_body_last_cpuinfo_used)), VP8GetCPUInfo)
  52482 	goto _2
  52483 _2:
  52484 	;
  52485 	goto _1
  52486 _1: /**/ //
  52487 }
  52488 
  52489 var WebPRescalerDspInit_body_last_cpuinfo_used = uintptr(0)
  52490 
  52491 func init() {
  52492 	p := unsafe.Pointer(&WebPRescalerDspInit_body_last_cpuinfo_used)
  52493 	*(*uintptr)(unsafe.Add(p, 0)) = uintptr(unsafe.Pointer(&WebPRescalerDspInit_body_last_cpuinfo_used))
  52494 }
  52495 
  52496 func WebPRescalerDspInit_body(tls *libc.TLS) {
  52497 	WebPRescalerExportRowExpand = __ccgo_fp(WebPRescalerExportRowExpand_C)
  52498 	WebPRescalerExportRowShrink = __ccgo_fp(WebPRescalerExportRowShrink_C)
  52499 	WebPRescalerImportRowExpand = __ccgo_fp(WebPRescalerImportRowExpand_C)
  52500 	WebPRescalerImportRowShrink = __ccgo_fp(WebPRescalerImportRowShrink_C)
  52501 	if VP8GetCPUInfo != libc.UintptrFromInt32(0) {
  52502 	}
  52503 }
  52504 
  52505 func WebPRescalerDspInitMIPS32(tls *libc.TLS) {
  52506 }
  52507 
  52508 func WebPRescalerDspInitMIPSdspR2(tls *libc.TLS) {
  52509 }
  52510 
  52511 func WebPRescalerDspInitMSA(tls *libc.TLS) {
  52512 }
  52513 
  52514 func WebPRescalerDspInitNEON(tls *libc.TLS) {
  52515 }
  52516 
  52517 func WebPRescalerDspInitSSE2(tls *libc.TLS) {
  52518 }
  52519 
  52520 const SIZE_MAX30 = "_UI64_MAX"
  52521 
  52522 // Copyright 2010 Google Inc. All Rights Reserved.
  52523 //
  52524 // Use of this source code is governed by a BSD-style license
  52525 // that can be found in the COPYING file in the root of the source
  52526 // tree. An additional intellectual property rights grant can be found
  52527 // in the file PATENTS. All contributing project authors may
  52528 // be found in the AUTHORS file in the root of the source tree.
  52529 // -----------------------------------------------------------------------------
  52530 //
  52531 //  Common types + memory wrappers
  52532 //
  52533 // Author: Skal (pascal.massimino@gmail.com)
  52534 
  52535 //------------------------------------------------------------------------------
  52536 // SSIM / PSNR
  52537 
  52538 // C documentation
  52539 //
  52540 //	// hat-shaped filter. Sum of coefficients is equal to 16.
  52541 var kWeight = [7]uint32_t{
  52542 	0: uint32(1),
  52543 	1: uint32(2),
  52544 	2: uint32(3),
  52545 	3: uint32(4),
  52546 	4: uint32(3),
  52547 	5: uint32(2),
  52548 	6: uint32(1),
  52549 }
  52550 var kWeightSum = uint32(libc.Int32FromInt32(16) * libc.Int32FromInt32(16)) // sum{kWeight}^2
  52551 
  52552 func SSIMCalculation(tls *libc.TLS, stats uintptr, N uint32_t) (r1 float64) {
  52553 	var C1, C2, C3, w2 uint32_t
  52554 	var den_S, fden, fnum, num_S, sxx, syy, xmxm, ymym uint64_t
  52555 	var r float64
  52556 	var sxy, xmym int64_t
  52557 	var v1 int64
  52558 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = C1, C2, C3, den_S, fden, fnum, num_S, r, sxx, sxy, syy, w2, xmxm, xmym, ymym, v1
  52559 	w2 = N * N
  52560 	C1 = uint32(20) * w2
  52561 	C2 = uint32(60) * w2
  52562 	C3 = uint32(libc.Int32FromInt32(8)*libc.Int32FromInt32(8)) * w2 // 'dark' limit ~= 6
  52563 	xmxm = uint64((*VP8DistoStats)(unsafe.Pointer(stats)).Fxm) * uint64((*VP8DistoStats)(unsafe.Pointer(stats)).Fxm)
  52564 	ymym = uint64((*VP8DistoStats)(unsafe.Pointer(stats)).Fym) * uint64((*VP8DistoStats)(unsafe.Pointer(stats)).Fym)
  52565 	if xmxm+ymym >= uint64(C3) {
  52566 		xmym = int64((*VP8DistoStats)(unsafe.Pointer(stats)).Fxm) * int64((*VP8DistoStats)(unsafe.Pointer(stats)).Fym)
  52567 		sxy = int64((*VP8DistoStats)(unsafe.Pointer(stats)).Fxym)*int64(N) - xmym // can be negative
  52568 		sxx = uint64((*VP8DistoStats)(unsafe.Pointer(stats)).Fxxm)*uint64(N) - xmxm
  52569 		syy = uint64((*VP8DistoStats)(unsafe.Pointer(stats)).Fyym)*uint64(N) - ymym
  52570 		if sxy < 0 {
  52571 			v1 = 0
  52572 		} else {
  52573 			v1 = sxy
  52574 		}
  52575 		// we descale by 8 to prevent overflow during the fnum/fden multiply.
  52576 		num_S = (uint64(2)*uint64(v1) + uint64(C2)) >> int32(8)
  52577 		den_S = (sxx + syy + uint64(C2)) >> int32(8)
  52578 		fnum = uint64(libc.Int64FromInt32(2)*xmym+int64(C1)) * num_S
  52579 		fden = (xmxm + ymym + uint64(C1)) * den_S
  52580 		r = float64(fnum) / float64(fden)
  52581 		return r
  52582 	}
  52583 	return float64(1) // area is too dark to contribute meaningfully
  52584 }
  52585 
  52586 func VP8SSIMFromStats(tls *libc.TLS, stats uintptr) (r float64) {
  52587 	return SSIMCalculation(tls, stats, kWeightSum)
  52588 }
  52589 
  52590 func VP8SSIMFromStatsClipped(tls *libc.TLS, stats uintptr) (r float64) {
  52591 	return SSIMCalculation(tls, stats, (*VP8DistoStats)(unsafe.Pointer(stats)).Fw)
  52592 }
  52593 
  52594 func SSIMGetClipped_C(tls *libc.TLS, src1 uintptr, stride1 int32, src2 uintptr, stride2 int32, xo int32, yo int32, W int32, H int32) (r float64) {
  52595 	bp := tls.Alloc(32)
  52596 	defer tls.Free(32)
  52597 	var s1, s2, w uint32_t
  52598 	var x, xmax, xmin, y, ymax, ymin, v1, v2, v3, v4 int32
  52599 	var _ /* stats at bp+0 */ VP8DistoStats
  52600 	_, _, _, _, _, _, _, _, _, _, _, _, _ = s1, s2, w, x, xmax, xmin, y, ymax, ymin, v1, v2, v3, v4
  52601 	**(**VP8DistoStats)(__ccgo_up(bp)) = VP8DistoStats{}
  52602 	if yo-int32(VP8_SSIM_KERNEL) < 0 {
  52603 		v1 = 0
  52604 	} else {
  52605 		v1 = yo - int32(VP8_SSIM_KERNEL)
  52606 	}
  52607 	ymin = v1
  52608 	if yo+int32(VP8_SSIM_KERNEL) > H-int32(1) {
  52609 		v2 = H - int32(1)
  52610 	} else {
  52611 		v2 = yo + int32(VP8_SSIM_KERNEL)
  52612 	}
  52613 	ymax = v2
  52614 	if xo-int32(VP8_SSIM_KERNEL) < 0 {
  52615 		v3 = 0
  52616 	} else {
  52617 		v3 = xo - int32(VP8_SSIM_KERNEL)
  52618 	}
  52619 	xmin = v3
  52620 	if xo+int32(VP8_SSIM_KERNEL) > W-int32(1) {
  52621 		v4 = W - int32(1)
  52622 	} else {
  52623 		v4 = xo + int32(VP8_SSIM_KERNEL)
  52624 	}
  52625 	xmax = v4
  52626 	src1 = src1 + uintptr(ymin*stride1)
  52627 	src2 = src2 + uintptr(ymin*stride2)
  52628 	y = ymin
  52629 	for {
  52630 		if !(y <= ymax) {
  52631 			break
  52632 		}
  52633 		x = xmin
  52634 		for {
  52635 			if !(x <= xmax) {
  52636 				break
  52637 			}
  52638 			w = kWeight[int32(VP8_SSIM_KERNEL)+x-xo] * kWeight[int32(VP8_SSIM_KERNEL)+y-yo]
  52639 			s1 = uint32(**(**uint8_t)(__ccgo_up(src1 + uintptr(x))))
  52640 			s2 = uint32(**(**uint8_t)(__ccgo_up(src2 + uintptr(x))))
  52641 			(**(**VP8DistoStats)(__ccgo_up(bp))).Fw += w
  52642 			(**(**VP8DistoStats)(__ccgo_up(bp))).Fxm += w * s1
  52643 			(**(**VP8DistoStats)(__ccgo_up(bp))).Fym += w * s2
  52644 			(**(**VP8DistoStats)(__ccgo_up(bp))).Fxxm += w * s1 * s1
  52645 			(**(**VP8DistoStats)(__ccgo_up(bp))).Fxym += w * s1 * s2
  52646 			(**(**VP8DistoStats)(__ccgo_up(bp))).Fyym += w * s2 * s2
  52647 			goto _6
  52648 		_6:
  52649 			;
  52650 			x = x + 1
  52651 		}
  52652 		goto _5
  52653 	_5:
  52654 		;
  52655 		y = y + 1
  52656 		src1 = src1 + uintptr(stride1)
  52657 		src2 = src2 + uintptr(stride2)
  52658 	}
  52659 	return VP8SSIMFromStatsClipped(tls, bp)
  52660 }
  52661 
  52662 func SSIMGet_C(tls *libc.TLS, src1 uintptr, stride1 int32, src2 uintptr, stride2 int32) (r float64) {
  52663 	bp := tls.Alloc(32)
  52664 	defer tls.Free(32)
  52665 	var s1, s2, w uint32_t
  52666 	var x, y int32
  52667 	var _ /* stats at bp+0 */ VP8DistoStats
  52668 	_, _, _, _, _ = s1, s2, w, x, y
  52669 	**(**VP8DistoStats)(__ccgo_up(bp)) = VP8DistoStats{}
  52670 	y = 0
  52671 	for {
  52672 		if !(y <= libc.Int32FromInt32(2)*libc.Int32FromInt32(VP8_SSIM_KERNEL)) {
  52673 			break
  52674 		}
  52675 		x = 0
  52676 		for {
  52677 			if !(x <= libc.Int32FromInt32(2)*libc.Int32FromInt32(VP8_SSIM_KERNEL)) {
  52678 				break
  52679 			}
  52680 			w = kWeight[x] * kWeight[y]
  52681 			s1 = uint32(**(**uint8_t)(__ccgo_up(src1 + uintptr(x))))
  52682 			s2 = uint32(**(**uint8_t)(__ccgo_up(src2 + uintptr(x))))
  52683 			(**(**VP8DistoStats)(__ccgo_up(bp))).Fxm += w * s1
  52684 			(**(**VP8DistoStats)(__ccgo_up(bp))).Fym += w * s2
  52685 			(**(**VP8DistoStats)(__ccgo_up(bp))).Fxxm += w * s1 * s1
  52686 			(**(**VP8DistoStats)(__ccgo_up(bp))).Fxym += w * s1 * s2
  52687 			(**(**VP8DistoStats)(__ccgo_up(bp))).Fyym += w * s2 * s2
  52688 			goto _2
  52689 		_2:
  52690 			;
  52691 			x = x + 1
  52692 		}
  52693 		goto _1
  52694 	_1:
  52695 		;
  52696 		y = y + 1
  52697 		src1 = src1 + uintptr(stride1)
  52698 		src2 = src2 + uintptr(stride2)
  52699 	}
  52700 	return VP8SSIMFromStats(tls, bp)
  52701 }
  52702 
  52703 //------------------------------------------------------------------------------
  52704 
  52705 func AccumulateSSE_C(tls *libc.TLS, src1 uintptr, src2 uintptr, len1 int32) (r uint32_t) {
  52706 	var diff int32_t
  52707 	var i int32
  52708 	var sse2 uint32_t
  52709 	_, _, _ = diff, i, sse2
  52710 	sse2 = uint32(0)
  52711 	// to ensure that accumulation fits within uint32_t
  52712 	i = 0
  52713 	for {
  52714 		if !(i < len1) {
  52715 			break
  52716 		}
  52717 		diff = int32(**(**uint8_t)(__ccgo_up(src1 + uintptr(i)))) - int32(**(**uint8_t)(__ccgo_up(src2 + uintptr(i))))
  52718 		sse2 = sse2 + uint32(diff*diff)
  52719 		goto _1
  52720 	_1:
  52721 		;
  52722 		i = i + 1
  52723 	}
  52724 	return sse2
  52725 }
  52726 
  52727 func VP8SSIMDspInit(tls *libc.TLS) {
  52728 	if libc.AtomicLoadPUintptr(uintptr(unsafe.Pointer(&VP8SSIMDspInit_body_last_cpuinfo_used))) == VP8GetCPUInfo {
  52729 		goto _1
  52730 	}
  52731 	VP8SSIMDspInit_body(tls)
  52732 	libc.AtomicStorePUintptr(uintptr(unsafe.Pointer(&VP8SSIMDspInit_body_last_cpuinfo_used)), VP8GetCPUInfo)
  52733 	goto _2
  52734 _2:
  52735 	;
  52736 	goto _1
  52737 _1: /**/ //
  52738 }
  52739 
  52740 var VP8SSIMDspInit_body_last_cpuinfo_used = uintptr(0)
  52741 
  52742 func init() {
  52743 	p := unsafe.Pointer(&VP8SSIMDspInit_body_last_cpuinfo_used)
  52744 	*(*uintptr)(unsafe.Add(p, 0)) = uintptr(unsafe.Pointer(&VP8SSIMDspInit_body_last_cpuinfo_used))
  52745 }
  52746 
  52747 func VP8SSIMDspInit_body(tls *libc.TLS) {
  52748 	VP8SSIMGetClipped = __ccgo_fp(SSIMGetClipped_C)
  52749 	VP8SSIMGet = __ccgo_fp(SSIMGet_C)
  52750 	VP8AccumulateSSE = __ccgo_fp(AccumulateSSE_C)
  52751 	if VP8GetCPUInfo != libc.UintptrFromInt32(0) {
  52752 	}
  52753 }
  52754 
  52755 const SIZE_MAX31 = "UINT64_MAX"
  52756 
  52757 func VP8SSIMDspInitSSE2(tls *libc.TLS) {
  52758 }
  52759 
  52760 // Given samples laid out in a square as:
  52761 //  [a b]
  52762 //  [c d]
  52763 // we interpolate u/v as:
  52764 //  ([9*a + 3*b + 3*c +   d    3*a + 9*b + 3*c +   d] + [8 8]) / 16
  52765 //  ([3*a +   b + 9*c + 3*d      a + 3*b + 3*c + 9*d]   [8 8]) / 16
  52766 
  52767 // We process u and v together stashed into 32bit (16bit each).
  52768 
  52769 // C documentation
  52770 //
  52771 //	// All variants implemented.
  52772 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) {
  52773 	var avg, diag_03, diag_12, l_uv, t_uv, tl_uv, uv, uv0, uv01, uv02, uv03, uv04, uv05, uv1, uv11 uint32_t
  52774 	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
  52775 	var v1, v5 uintptr
  52776 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  52777 	last_pixel_pair = (len1 - int32(1)) >> int32(1)
  52778 	tl_uv = uint32(int32(**(**uint8_t)(__ccgo_up(top_u))) | int32(**(**uint8_t)(__ccgo_up(top_v)))<<libc.Int32FromInt32(16)) /* top-left sample */
  52779 	l_uv = uint32(int32(**(**uint8_t)(__ccgo_up(cur_u))) | int32(**(**uint8_t)(__ccgo_up(cur_v)))<<libc.Int32FromInt32(16))
  52780 	uv0 = (uint32(3)*tl_uv + l_uv + uint32(0x00020002)) >> int32(2)
  52781 	v1 = top_dst
  52782 	v2 = int32(**(**uint8_t)(__ccgo_up(top_y)))
  52783 	v3 = int32(uint8(uv0 & uint32(0xff)))
  52784 	v4 = int32(uint8(uv0 >> libc.Int32FromInt32(16)))
  52785 	v5 = v1
  52786 	v8 = v2 * int32(19077) >> int32(8)
  52787 	goto _9
  52788 _9:
  52789 	v10 = v4 * int32(26149) >> int32(8)
  52790 	goto _11
  52791 _11:
  52792 	v12 = v8 + v10 - int32(14234)
  52793 	if v12 & ^int32(YUV_MASK2) == 0 {
  52794 		v15 = v12 >> int32(YUV_FIX2)
  52795 	} else {
  52796 		if v12 < 0 {
  52797 			v16 = 0
  52798 		} else {
  52799 			v16 = int32(255)
  52800 		}
  52801 		v15 = v16
  52802 	}
  52803 	v13 = v15
  52804 	goto _14
  52805 _14:
  52806 	v6 = v13
  52807 	goto _7
  52808 _7:
  52809 	**(**uint8_t)(__ccgo_up(v5)) = uint8(v6)
  52810 	v19 = v2 * int32(19077) >> int32(8)
  52811 	goto _20
  52812 _20:
  52813 	v21 = v3 * int32(6419) >> int32(8)
  52814 	goto _22
  52815 _22:
  52816 	v23 = v4 * int32(13320) >> int32(8)
  52817 	goto _24
  52818 _24:
  52819 	v25 = v19 - v21 - v23 + int32(8708)
  52820 	if v25 & ^int32(YUV_MASK2) == 0 {
  52821 		v28 = v25 >> int32(YUV_FIX2)
  52822 	} else {
  52823 		if v25 < 0 {
  52824 			v29 = 0
  52825 		} else {
  52826 			v29 = int32(255)
  52827 		}
  52828 		v28 = v29
  52829 	}
  52830 	v26 = v28
  52831 	goto _27
  52832 _27:
  52833 	v17 = v26
  52834 	goto _18
  52835 _18:
  52836 	**(**uint8_t)(__ccgo_up(v5 + 1)) = uint8(v17)
  52837 	v32 = v2 * int32(19077) >> int32(8)
  52838 	goto _33
  52839 _33:
  52840 	v34 = v3 * int32(33050) >> int32(8)
  52841 	goto _35
  52842 _35:
  52843 	v36 = v32 + v34 - int32(17685)
  52844 	if v36 & ^int32(YUV_MASK2) == 0 {
  52845 		v39 = v36 >> int32(YUV_FIX2)
  52846 	} else {
  52847 		if v36 < 0 {
  52848 			v40 = 0
  52849 		} else {
  52850 			v40 = int32(255)
  52851 		}
  52852 		v39 = v40
  52853 	}
  52854 	v37 = v39
  52855 	goto _38
  52856 _38:
  52857 	v30 = v37
  52858 	goto _31
  52859 _31:
  52860 	**(**uint8_t)(__ccgo_up(v5 + 2)) = uint8(v30)
  52861 	**(**uint8_t)(__ccgo_up(v1 + 3)) = uint8(0xff)
  52862 	if bottom_y != libc.UintptrFromInt32(0) {
  52863 		uv01 = (uint32(3)*l_uv + tl_uv + uint32(0x00020002)) >> int32(2)
  52864 		v1 = bottom_dst
  52865 		v2 = int32(**(**uint8_t)(__ccgo_up(bottom_y)))
  52866 		v3 = int32(uint8(uv01 & uint32(0xff)))
  52867 		v4 = int32(uint8(uv01 >> libc.Int32FromInt32(16)))
  52868 		v5 = v1
  52869 		v8 = v2 * int32(19077) >> int32(8)
  52870 		goto _49
  52871 	_49:
  52872 		v10 = v4 * int32(26149) >> int32(8)
  52873 		goto _51
  52874 	_51:
  52875 		v12 = v8 + v10 - int32(14234)
  52876 		if v12 & ^int32(YUV_MASK2) == 0 {
  52877 			v15 = v12 >> int32(YUV_FIX2)
  52878 		} else {
  52879 			if v12 < 0 {
  52880 				v16 = 0
  52881 			} else {
  52882 				v16 = int32(255)
  52883 			}
  52884 			v15 = v16
  52885 		}
  52886 		v13 = v15
  52887 		goto _54
  52888 	_54:
  52889 		v6 = v13
  52890 		goto _47
  52891 	_47:
  52892 		**(**uint8_t)(__ccgo_up(v5)) = uint8(v6)
  52893 		v19 = v2 * int32(19077) >> int32(8)
  52894 		goto _60
  52895 	_60:
  52896 		v21 = v3 * int32(6419) >> int32(8)
  52897 		goto _62
  52898 	_62:
  52899 		v23 = v4 * int32(13320) >> int32(8)
  52900 		goto _64
  52901 	_64:
  52902 		v25 = v19 - v21 - v23 + int32(8708)
  52903 		if v25 & ^int32(YUV_MASK2) == 0 {
  52904 			v28 = v25 >> int32(YUV_FIX2)
  52905 		} else {
  52906 			if v25 < 0 {
  52907 				v29 = 0
  52908 			} else {
  52909 				v29 = int32(255)
  52910 			}
  52911 			v28 = v29
  52912 		}
  52913 		v26 = v28
  52914 		goto _67
  52915 	_67:
  52916 		v17 = v26
  52917 		goto _58
  52918 	_58:
  52919 		**(**uint8_t)(__ccgo_up(v5 + 1)) = uint8(v17)
  52920 		v32 = v2 * int32(19077) >> int32(8)
  52921 		goto _73
  52922 	_73:
  52923 		v34 = v3 * int32(33050) >> int32(8)
  52924 		goto _75
  52925 	_75:
  52926 		v36 = v32 + v34 - int32(17685)
  52927 		if v36 & ^int32(YUV_MASK2) == 0 {
  52928 			v39 = v36 >> int32(YUV_FIX2)
  52929 		} else {
  52930 			if v36 < 0 {
  52931 				v40 = 0
  52932 			} else {
  52933 				v40 = int32(255)
  52934 			}
  52935 			v39 = v40
  52936 		}
  52937 		v37 = v39
  52938 		goto _78
  52939 	_78:
  52940 		v30 = v37
  52941 		goto _71
  52942 	_71:
  52943 		**(**uint8_t)(__ccgo_up(v5 + 2)) = uint8(v30)
  52944 		**(**uint8_t)(__ccgo_up(v1 + 3)) = uint8(0xff)
  52945 	}
  52946 	x = int32(1)
  52947 	for {
  52948 		if !(x <= last_pixel_pair) {
  52949 			break
  52950 		}
  52951 		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 */
  52952 		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*/
  52953 		avg = tl_uv + t_uv + l_uv + uv + uint32(0x00080008)
  52954 		diag_12 = (avg + uint32(2)*(t_uv+l_uv)) >> int32(3)
  52955 		diag_03 = (avg + uint32(2)*(tl_uv+uv)) >> int32(3)
  52956 		uv02 = (diag_12 + tl_uv) >> int32(1)
  52957 		uv1 = (diag_03 + t_uv) >> int32(1)
  52958 		v1 = top_dst + uintptr((int32(2)*x-int32(1))*int32(4))
  52959 		v2 = int32(**(**uint8_t)(__ccgo_up(top_y + uintptr(int32(2)*x-int32(1)))))
  52960 		v3 = int32(uint8(uv02 & uint32(0xff)))
  52961 		v4 = int32(uint8(uv02 >> libc.Int32FromInt32(16)))
  52962 		v5 = v1
  52963 		v8 = v2 * int32(19077) >> int32(8)
  52964 		goto _90
  52965 	_90:
  52966 		v10 = v4 * int32(26149) >> int32(8)
  52967 		goto _92
  52968 	_92:
  52969 		v12 = v8 + v10 - int32(14234)
  52970 		if v12 & ^int32(YUV_MASK2) == 0 {
  52971 			v15 = v12 >> int32(YUV_FIX2)
  52972 		} else {
  52973 			if v12 < 0 {
  52974 				v16 = 0
  52975 			} else {
  52976 				v16 = int32(255)
  52977 			}
  52978 			v15 = v16
  52979 		}
  52980 		v13 = v15
  52981 		goto _95
  52982 	_95:
  52983 		v6 = v13
  52984 		goto _88
  52985 	_88:
  52986 		**(**uint8_t)(__ccgo_up(v5)) = uint8(v6)
  52987 		v19 = v2 * int32(19077) >> int32(8)
  52988 		goto _101
  52989 	_101:
  52990 		v21 = v3 * int32(6419) >> int32(8)
  52991 		goto _103
  52992 	_103:
  52993 		v23 = v4 * int32(13320) >> int32(8)
  52994 		goto _105
  52995 	_105:
  52996 		v25 = v19 - v21 - v23 + int32(8708)
  52997 		if v25 & ^int32(YUV_MASK2) == 0 {
  52998 			v28 = v25 >> int32(YUV_FIX2)
  52999 		} else {
  53000 			if v25 < 0 {
  53001 				v29 = 0
  53002 			} else {
  53003 				v29 = int32(255)
  53004 			}
  53005 			v28 = v29
  53006 		}
  53007 		v26 = v28
  53008 		goto _108
  53009 	_108:
  53010 		v17 = v26
  53011 		goto _99
  53012 	_99:
  53013 		**(**uint8_t)(__ccgo_up(v5 + 1)) = uint8(v17)
  53014 		v32 = v2 * int32(19077) >> int32(8)
  53015 		goto _114
  53016 	_114:
  53017 		v34 = v3 * int32(33050) >> int32(8)
  53018 		goto _116
  53019 	_116:
  53020 		v36 = v32 + v34 - int32(17685)
  53021 		if v36 & ^int32(YUV_MASK2) == 0 {
  53022 			v39 = v36 >> int32(YUV_FIX2)
  53023 		} else {
  53024 			if v36 < 0 {
  53025 				v40 = 0
  53026 			} else {
  53027 				v40 = int32(255)
  53028 			}
  53029 			v39 = v40
  53030 		}
  53031 		v37 = v39
  53032 		goto _119
  53033 	_119:
  53034 		v30 = v37
  53035 		goto _112
  53036 	_112:
  53037 		**(**uint8_t)(__ccgo_up(v5 + 2)) = uint8(v30)
  53038 		**(**uint8_t)(__ccgo_up(v1 + 3)) = uint8(0xff)
  53039 		v1 = top_dst + uintptr((int32(2)*x-0)*int32(4))
  53040 		v2 = int32(**(**uint8_t)(__ccgo_up(top_y + uintptr(int32(2)*x-0))))
  53041 		v3 = int32(uint8(uv1 & uint32(0xff)))
  53042 		v4 = int32(uint8(uv1 >> libc.Int32FromInt32(16)))
  53043 		v5 = v1
  53044 		v8 = v2 * int32(19077) >> int32(8)
  53045 		goto _130
  53046 	_130:
  53047 		v10 = v4 * int32(26149) >> int32(8)
  53048 		goto _132
  53049 	_132:
  53050 		v12 = v8 + v10 - int32(14234)
  53051 		if v12 & ^int32(YUV_MASK2) == 0 {
  53052 			v15 = v12 >> int32(YUV_FIX2)
  53053 		} else {
  53054 			if v12 < 0 {
  53055 				v16 = 0
  53056 			} else {
  53057 				v16 = int32(255)
  53058 			}
  53059 			v15 = v16
  53060 		}
  53061 		v13 = v15
  53062 		goto _135
  53063 	_135:
  53064 		v6 = v13
  53065 		goto _128
  53066 	_128:
  53067 		**(**uint8_t)(__ccgo_up(v5)) = uint8(v6)
  53068 		v19 = v2 * int32(19077) >> int32(8)
  53069 		goto _141
  53070 	_141:
  53071 		v21 = v3 * int32(6419) >> int32(8)
  53072 		goto _143
  53073 	_143:
  53074 		v23 = v4 * int32(13320) >> int32(8)
  53075 		goto _145
  53076 	_145:
  53077 		v25 = v19 - v21 - v23 + int32(8708)
  53078 		if v25 & ^int32(YUV_MASK2) == 0 {
  53079 			v28 = v25 >> int32(YUV_FIX2)
  53080 		} else {
  53081 			if v25 < 0 {
  53082 				v29 = 0
  53083 			} else {
  53084 				v29 = int32(255)
  53085 			}
  53086 			v28 = v29
  53087 		}
  53088 		v26 = v28
  53089 		goto _148
  53090 	_148:
  53091 		v17 = v26
  53092 		goto _139
  53093 	_139:
  53094 		**(**uint8_t)(__ccgo_up(v5 + 1)) = uint8(v17)
  53095 		v32 = v2 * int32(19077) >> int32(8)
  53096 		goto _154
  53097 	_154:
  53098 		v34 = v3 * int32(33050) >> int32(8)
  53099 		goto _156
  53100 	_156:
  53101 		v36 = v32 + v34 - int32(17685)
  53102 		if v36 & ^int32(YUV_MASK2) == 0 {
  53103 			v39 = v36 >> int32(YUV_FIX2)
  53104 		} else {
  53105 			if v36 < 0 {
  53106 				v40 = 0
  53107 			} else {
  53108 				v40 = int32(255)
  53109 			}
  53110 			v39 = v40
  53111 		}
  53112 		v37 = v39
  53113 		goto _159
  53114 	_159:
  53115 		v30 = v37
  53116 		goto _152
  53117 	_152:
  53118 		**(**uint8_t)(__ccgo_up(v5 + 2)) = uint8(v30)
  53119 		**(**uint8_t)(__ccgo_up(v1 + 3)) = uint8(0xff)
  53120 		if bottom_y != libc.UintptrFromInt32(0) {
  53121 			uv03 = (diag_03 + l_uv) >> int32(1)
  53122 			uv11 = (diag_12 + uv) >> int32(1)
  53123 			v1 = bottom_dst + uintptr((int32(2)*x-int32(1))*int32(4))
  53124 			v2 = int32(**(**uint8_t)(__ccgo_up(bottom_y + uintptr(int32(2)*x-int32(1)))))
  53125 			v3 = int32(uint8(uv03 & uint32(0xff)))
  53126 			v4 = int32(uint8(uv03 >> libc.Int32FromInt32(16)))
  53127 			v5 = v1
  53128 			v8 = v2 * int32(19077) >> int32(8)
  53129 			goto _170
  53130 		_170:
  53131 			v10 = v4 * int32(26149) >> int32(8)
  53132 			goto _172
  53133 		_172:
  53134 			v12 = v8 + v10 - int32(14234)
  53135 			if v12 & ^int32(YUV_MASK2) == 0 {
  53136 				v15 = v12 >> int32(YUV_FIX2)
  53137 			} else {
  53138 				if v12 < 0 {
  53139 					v16 = 0
  53140 				} else {
  53141 					v16 = int32(255)
  53142 				}
  53143 				v15 = v16
  53144 			}
  53145 			v13 = v15
  53146 			goto _175
  53147 		_175:
  53148 			v6 = v13
  53149 			goto _168
  53150 		_168:
  53151 			**(**uint8_t)(__ccgo_up(v5)) = uint8(v6)
  53152 			v19 = v2 * int32(19077) >> int32(8)
  53153 			goto _181
  53154 		_181:
  53155 			v21 = v3 * int32(6419) >> int32(8)
  53156 			goto _183
  53157 		_183:
  53158 			v23 = v4 * int32(13320) >> int32(8)
  53159 			goto _185
  53160 		_185:
  53161 			v25 = v19 - v21 - v23 + int32(8708)
  53162 			if v25 & ^int32(YUV_MASK2) == 0 {
  53163 				v28 = v25 >> int32(YUV_FIX2)
  53164 			} else {
  53165 				if v25 < 0 {
  53166 					v29 = 0
  53167 				} else {
  53168 					v29 = int32(255)
  53169 				}
  53170 				v28 = v29
  53171 			}
  53172 			v26 = v28
  53173 			goto _188
  53174 		_188:
  53175 			v17 = v26
  53176 			goto _179
  53177 		_179:
  53178 			**(**uint8_t)(__ccgo_up(v5 + 1)) = uint8(v17)
  53179 			v32 = v2 * int32(19077) >> int32(8)
  53180 			goto _194
  53181 		_194:
  53182 			v34 = v3 * int32(33050) >> int32(8)
  53183 			goto _196
  53184 		_196:
  53185 			v36 = v32 + v34 - int32(17685)
  53186 			if v36 & ^int32(YUV_MASK2) == 0 {
  53187 				v39 = v36 >> int32(YUV_FIX2)
  53188 			} else {
  53189 				if v36 < 0 {
  53190 					v40 = 0
  53191 				} else {
  53192 					v40 = int32(255)
  53193 				}
  53194 				v39 = v40
  53195 			}
  53196 			v37 = v39
  53197 			goto _199
  53198 		_199:
  53199 			v30 = v37
  53200 			goto _192
  53201 		_192:
  53202 			**(**uint8_t)(__ccgo_up(v5 + 2)) = uint8(v30)
  53203 			**(**uint8_t)(__ccgo_up(v1 + 3)) = uint8(0xff)
  53204 			v1 = bottom_dst + uintptr((int32(2)*x+0)*int32(4))
  53205 			v2 = int32(**(**uint8_t)(__ccgo_up(bottom_y + uintptr(int32(2)*x+0))))
  53206 			v3 = int32(uint8(uv11 & uint32(0xff)))
  53207 			v4 = int32(uint8(uv11 >> libc.Int32FromInt32(16)))
  53208 			v5 = v1
  53209 			v8 = v2 * int32(19077) >> int32(8)
  53210 			goto _210
  53211 		_210:
  53212 			v10 = v4 * int32(26149) >> int32(8)
  53213 			goto _212
  53214 		_212:
  53215 			v12 = v8 + v10 - int32(14234)
  53216 			if v12 & ^int32(YUV_MASK2) == 0 {
  53217 				v15 = v12 >> int32(YUV_FIX2)
  53218 			} else {
  53219 				if v12 < 0 {
  53220 					v16 = 0
  53221 				} else {
  53222 					v16 = int32(255)
  53223 				}
  53224 				v15 = v16
  53225 			}
  53226 			v13 = v15
  53227 			goto _215
  53228 		_215:
  53229 			v6 = v13
  53230 			goto _208
  53231 		_208:
  53232 			**(**uint8_t)(__ccgo_up(v5)) = uint8(v6)
  53233 			v19 = v2 * int32(19077) >> int32(8)
  53234 			goto _221
  53235 		_221:
  53236 			v21 = v3 * int32(6419) >> int32(8)
  53237 			goto _223
  53238 		_223:
  53239 			v23 = v4 * int32(13320) >> int32(8)
  53240 			goto _225
  53241 		_225:
  53242 			v25 = v19 - v21 - v23 + int32(8708)
  53243 			if v25 & ^int32(YUV_MASK2) == 0 {
  53244 				v28 = v25 >> int32(YUV_FIX2)
  53245 			} else {
  53246 				if v25 < 0 {
  53247 					v29 = 0
  53248 				} else {
  53249 					v29 = int32(255)
  53250 				}
  53251 				v28 = v29
  53252 			}
  53253 			v26 = v28
  53254 			goto _228
  53255 		_228:
  53256 			v17 = v26
  53257 			goto _219
  53258 		_219:
  53259 			**(**uint8_t)(__ccgo_up(v5 + 1)) = uint8(v17)
  53260 			v32 = v2 * int32(19077) >> int32(8)
  53261 			goto _234
  53262 		_234:
  53263 			v34 = v3 * int32(33050) >> int32(8)
  53264 			goto _236
  53265 		_236:
  53266 			v36 = v32 + v34 - int32(17685)
  53267 			if v36 & ^int32(YUV_MASK2) == 0 {
  53268 				v39 = v36 >> int32(YUV_FIX2)
  53269 			} else {
  53270 				if v36 < 0 {
  53271 					v40 = 0
  53272 				} else {
  53273 					v40 = int32(255)
  53274 				}
  53275 				v39 = v40
  53276 			}
  53277 			v37 = v39
  53278 			goto _239
  53279 		_239:
  53280 			v30 = v37
  53281 			goto _232
  53282 		_232:
  53283 			**(**uint8_t)(__ccgo_up(v5 + 2)) = uint8(v30)
  53284 			**(**uint8_t)(__ccgo_up(v1 + 3)) = uint8(0xff)
  53285 		}
  53286 		tl_uv = t_uv
  53287 		l_uv = uv
  53288 		goto _81
  53289 	_81:
  53290 		;
  53291 		x = x + 1
  53292 	}
  53293 	if !(len1&libc.Int32FromInt32(1) != 0) {
  53294 		uv04 = (uint32(3)*tl_uv + l_uv + uint32(0x00020002)) >> int32(2)
  53295 		v1 = top_dst + uintptr((len1-int32(1))*int32(4))
  53296 		v2 = int32(**(**uint8_t)(__ccgo_up(top_y + uintptr(len1-int32(1)))))
  53297 		v3 = int32(uint8(uv04 & uint32(0xff)))
  53298 		v4 = int32(uint8(uv04 >> libc.Int32FromInt32(16)))
  53299 		v5 = v1
  53300 		v8 = v2 * int32(19077) >> int32(8)
  53301 		goto _250
  53302 	_250:
  53303 		v10 = v4 * int32(26149) >> int32(8)
  53304 		goto _252
  53305 	_252:
  53306 		v12 = v8 + v10 - int32(14234)
  53307 		if v12 & ^int32(YUV_MASK2) == 0 {
  53308 			v15 = v12 >> int32(YUV_FIX2)
  53309 		} else {
  53310 			if v12 < 0 {
  53311 				v16 = 0
  53312 			} else {
  53313 				v16 = int32(255)
  53314 			}
  53315 			v15 = v16
  53316 		}
  53317 		v13 = v15
  53318 		goto _255
  53319 	_255:
  53320 		v6 = v13
  53321 		goto _248
  53322 	_248:
  53323 		**(**uint8_t)(__ccgo_up(v5)) = uint8(v6)
  53324 		v19 = v2 * int32(19077) >> int32(8)
  53325 		goto _261
  53326 	_261:
  53327 		v21 = v3 * int32(6419) >> int32(8)
  53328 		goto _263
  53329 	_263:
  53330 		v23 = v4 * int32(13320) >> int32(8)
  53331 		goto _265
  53332 	_265:
  53333 		v25 = v19 - v21 - v23 + int32(8708)
  53334 		if v25 & ^int32(YUV_MASK2) == 0 {
  53335 			v28 = v25 >> int32(YUV_FIX2)
  53336 		} else {
  53337 			if v25 < 0 {
  53338 				v29 = 0
  53339 			} else {
  53340 				v29 = int32(255)
  53341 			}
  53342 			v28 = v29
  53343 		}
  53344 		v26 = v28
  53345 		goto _268
  53346 	_268:
  53347 		v17 = v26
  53348 		goto _259
  53349 	_259:
  53350 		**(**uint8_t)(__ccgo_up(v5 + 1)) = uint8(v17)
  53351 		v32 = v2 * int32(19077) >> int32(8)
  53352 		goto _274
  53353 	_274:
  53354 		v34 = v3 * int32(33050) >> int32(8)
  53355 		goto _276
  53356 	_276:
  53357 		v36 = v32 + v34 - int32(17685)
  53358 		if v36 & ^int32(YUV_MASK2) == 0 {
  53359 			v39 = v36 >> int32(YUV_FIX2)
  53360 		} else {
  53361 			if v36 < 0 {
  53362 				v40 = 0
  53363 			} else {
  53364 				v40 = int32(255)
  53365 			}
  53366 			v39 = v40
  53367 		}
  53368 		v37 = v39
  53369 		goto _279
  53370 	_279:
  53371 		v30 = v37
  53372 		goto _272
  53373 	_272:
  53374 		**(**uint8_t)(__ccgo_up(v5 + 2)) = uint8(v30)
  53375 		**(**uint8_t)(__ccgo_up(v1 + 3)) = uint8(0xff)
  53376 		if bottom_y != libc.UintptrFromInt32(0) {
  53377 			uv05 = (uint32(3)*l_uv + tl_uv + uint32(0x00020002)) >> int32(2)
  53378 			v1 = bottom_dst + uintptr((len1-int32(1))*int32(4))
  53379 			v2 = int32(**(**uint8_t)(__ccgo_up(bottom_y + uintptr(len1-int32(1)))))
  53380 			v3 = int32(uint8(uv05 & uint32(0xff)))
  53381 			v4 = int32(uint8(uv05 >> libc.Int32FromInt32(16)))
  53382 			v5 = v1
  53383 			v8 = v2 * int32(19077) >> int32(8)
  53384 			goto _290
  53385 		_290:
  53386 			v10 = v4 * int32(26149) >> int32(8)
  53387 			goto _292
  53388 		_292:
  53389 			v12 = v8 + v10 - int32(14234)
  53390 			if v12 & ^int32(YUV_MASK2) == 0 {
  53391 				v15 = v12 >> int32(YUV_FIX2)
  53392 			} else {
  53393 				if v12 < 0 {
  53394 					v16 = 0
  53395 				} else {
  53396 					v16 = int32(255)
  53397 				}
  53398 				v15 = v16
  53399 			}
  53400 			v13 = v15
  53401 			goto _295
  53402 		_295:
  53403 			v6 = v13
  53404 			goto _288
  53405 		_288:
  53406 			**(**uint8_t)(__ccgo_up(v5)) = uint8(v6)
  53407 			v19 = v2 * int32(19077) >> int32(8)
  53408 			goto _301
  53409 		_301:
  53410 			v21 = v3 * int32(6419) >> int32(8)
  53411 			goto _303
  53412 		_303:
  53413 			v23 = v4 * int32(13320) >> int32(8)
  53414 			goto _305
  53415 		_305:
  53416 			v25 = v19 - v21 - v23 + int32(8708)
  53417 			if v25 & ^int32(YUV_MASK2) == 0 {
  53418 				v28 = v25 >> int32(YUV_FIX2)
  53419 			} else {
  53420 				if v25 < 0 {
  53421 					v29 = 0
  53422 				} else {
  53423 					v29 = int32(255)
  53424 				}
  53425 				v28 = v29
  53426 			}
  53427 			v26 = v28
  53428 			goto _308
  53429 		_308:
  53430 			v17 = v26
  53431 			goto _299
  53432 		_299:
  53433 			**(**uint8_t)(__ccgo_up(v5 + 1)) = uint8(v17)
  53434 			v32 = v2 * int32(19077) >> int32(8)
  53435 			goto _314
  53436 		_314:
  53437 			v34 = v3 * int32(33050) >> int32(8)
  53438 			goto _316
  53439 		_316:
  53440 			v36 = v32 + v34 - int32(17685)
  53441 			if v36 & ^int32(YUV_MASK2) == 0 {
  53442 				v39 = v36 >> int32(YUV_FIX2)
  53443 			} else {
  53444 				if v36 < 0 {
  53445 					v40 = 0
  53446 				} else {
  53447 					v40 = int32(255)
  53448 				}
  53449 				v39 = v40
  53450 			}
  53451 			v37 = v39
  53452 			goto _319
  53453 		_319:
  53454 			v30 = v37
  53455 			goto _312
  53456 		_312:
  53457 			**(**uint8_t)(__ccgo_up(v5 + 2)) = uint8(v30)
  53458 			**(**uint8_t)(__ccgo_up(v1 + 3)) = uint8(0xff)
  53459 		}
  53460 	}
  53461 }
  53462 
  53463 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) {
  53464 	var avg, diag_03, diag_12, l_uv, t_uv, tl_uv, uv, uv0, uv01, uv02, uv03, uv04, uv05, uv1, uv11 uint32_t
  53465 	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
  53466 	var v1, v5 uintptr
  53467 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  53468 	last_pixel_pair = (len1 - int32(1)) >> int32(1)
  53469 	tl_uv = uint32(int32(**(**uint8_t)(__ccgo_up(top_u))) | int32(**(**uint8_t)(__ccgo_up(top_v)))<<libc.Int32FromInt32(16)) /* top-left sample */
  53470 	l_uv = uint32(int32(**(**uint8_t)(__ccgo_up(cur_u))) | int32(**(**uint8_t)(__ccgo_up(cur_v)))<<libc.Int32FromInt32(16))
  53471 	uv0 = (uint32(3)*tl_uv + l_uv + uint32(0x00020002)) >> int32(2)
  53472 	v1 = top_dst
  53473 	v2 = int32(**(**uint8_t)(__ccgo_up(top_y)))
  53474 	v3 = int32(uint8(uv0 & uint32(0xff)))
  53475 	v4 = int32(uint8(uv0 >> libc.Int32FromInt32(16)))
  53476 	v5 = v1
  53477 	v8 = v2 * int32(19077) >> int32(8)
  53478 	goto _9
  53479 _9:
  53480 	v10 = v3 * int32(33050) >> int32(8)
  53481 	goto _11
  53482 _11:
  53483 	v12 = v8 + v10 - int32(17685)
  53484 	if v12 & ^int32(YUV_MASK2) == 0 {
  53485 		v15 = v12 >> int32(YUV_FIX2)
  53486 	} else {
  53487 		if v12 < 0 {
  53488 			v16 = 0
  53489 		} else {
  53490 			v16 = int32(255)
  53491 		}
  53492 		v15 = v16
  53493 	}
  53494 	v13 = v15
  53495 	goto _14
  53496 _14:
  53497 	v6 = v13
  53498 	goto _7
  53499 _7:
  53500 	**(**uint8_t)(__ccgo_up(v5)) = uint8(v6)
  53501 	v19 = v2 * int32(19077) >> int32(8)
  53502 	goto _20
  53503 _20:
  53504 	v21 = v3 * int32(6419) >> int32(8)
  53505 	goto _22
  53506 _22:
  53507 	v23 = v4 * int32(13320) >> int32(8)
  53508 	goto _24
  53509 _24:
  53510 	v25 = v19 - v21 - v23 + int32(8708)
  53511 	if v25 & ^int32(YUV_MASK2) == 0 {
  53512 		v28 = v25 >> int32(YUV_FIX2)
  53513 	} else {
  53514 		if v25 < 0 {
  53515 			v29 = 0
  53516 		} else {
  53517 			v29 = int32(255)
  53518 		}
  53519 		v28 = v29
  53520 	}
  53521 	v26 = v28
  53522 	goto _27
  53523 _27:
  53524 	v17 = v26
  53525 	goto _18
  53526 _18:
  53527 	**(**uint8_t)(__ccgo_up(v5 + 1)) = uint8(v17)
  53528 	v32 = v2 * int32(19077) >> int32(8)
  53529 	goto _33
  53530 _33:
  53531 	v34 = v4 * int32(26149) >> int32(8)
  53532 	goto _35
  53533 _35:
  53534 	v36 = v32 + v34 - int32(14234)
  53535 	if v36 & ^int32(YUV_MASK2) == 0 {
  53536 		v39 = v36 >> int32(YUV_FIX2)
  53537 	} else {
  53538 		if v36 < 0 {
  53539 			v40 = 0
  53540 		} else {
  53541 			v40 = int32(255)
  53542 		}
  53543 		v39 = v40
  53544 	}
  53545 	v37 = v39
  53546 	goto _38
  53547 _38:
  53548 	v30 = v37
  53549 	goto _31
  53550 _31:
  53551 	**(**uint8_t)(__ccgo_up(v5 + 2)) = uint8(v30)
  53552 	**(**uint8_t)(__ccgo_up(v1 + 3)) = uint8(0xff)
  53553 	if bottom_y != libc.UintptrFromInt32(0) {
  53554 		uv01 = (uint32(3)*l_uv + tl_uv + uint32(0x00020002)) >> int32(2)
  53555 		v1 = bottom_dst
  53556 		v2 = int32(**(**uint8_t)(__ccgo_up(bottom_y)))
  53557 		v3 = int32(uint8(uv01 & uint32(0xff)))
  53558 		v4 = int32(uint8(uv01 >> libc.Int32FromInt32(16)))
  53559 		v5 = v1
  53560 		v8 = v2 * int32(19077) >> int32(8)
  53561 		goto _49
  53562 	_49:
  53563 		v10 = v3 * int32(33050) >> int32(8)
  53564 		goto _51
  53565 	_51:
  53566 		v12 = v8 + v10 - int32(17685)
  53567 		if v12 & ^int32(YUV_MASK2) == 0 {
  53568 			v15 = v12 >> int32(YUV_FIX2)
  53569 		} else {
  53570 			if v12 < 0 {
  53571 				v16 = 0
  53572 			} else {
  53573 				v16 = int32(255)
  53574 			}
  53575 			v15 = v16
  53576 		}
  53577 		v13 = v15
  53578 		goto _54
  53579 	_54:
  53580 		v6 = v13
  53581 		goto _47
  53582 	_47:
  53583 		**(**uint8_t)(__ccgo_up(v5)) = uint8(v6)
  53584 		v19 = v2 * int32(19077) >> int32(8)
  53585 		goto _60
  53586 	_60:
  53587 		v21 = v3 * int32(6419) >> int32(8)
  53588 		goto _62
  53589 	_62:
  53590 		v23 = v4 * int32(13320) >> int32(8)
  53591 		goto _64
  53592 	_64:
  53593 		v25 = v19 - v21 - v23 + int32(8708)
  53594 		if v25 & ^int32(YUV_MASK2) == 0 {
  53595 			v28 = v25 >> int32(YUV_FIX2)
  53596 		} else {
  53597 			if v25 < 0 {
  53598 				v29 = 0
  53599 			} else {
  53600 				v29 = int32(255)
  53601 			}
  53602 			v28 = v29
  53603 		}
  53604 		v26 = v28
  53605 		goto _67
  53606 	_67:
  53607 		v17 = v26
  53608 		goto _58
  53609 	_58:
  53610 		**(**uint8_t)(__ccgo_up(v5 + 1)) = uint8(v17)
  53611 		v32 = v2 * int32(19077) >> int32(8)
  53612 		goto _73
  53613 	_73:
  53614 		v34 = v4 * int32(26149) >> int32(8)
  53615 		goto _75
  53616 	_75:
  53617 		v36 = v32 + v34 - int32(14234)
  53618 		if v36 & ^int32(YUV_MASK2) == 0 {
  53619 			v39 = v36 >> int32(YUV_FIX2)
  53620 		} else {
  53621 			if v36 < 0 {
  53622 				v40 = 0
  53623 			} else {
  53624 				v40 = int32(255)
  53625 			}
  53626 			v39 = v40
  53627 		}
  53628 		v37 = v39
  53629 		goto _78
  53630 	_78:
  53631 		v30 = v37
  53632 		goto _71
  53633 	_71:
  53634 		**(**uint8_t)(__ccgo_up(v5 + 2)) = uint8(v30)
  53635 		**(**uint8_t)(__ccgo_up(v1 + 3)) = uint8(0xff)
  53636 	}
  53637 	x = int32(1)
  53638 	for {
  53639 		if !(x <= last_pixel_pair) {
  53640 			break
  53641 		}
  53642 		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 */
  53643 		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*/
  53644 		avg = tl_uv + t_uv + l_uv + uv + uint32(0x00080008)
  53645 		diag_12 = (avg + uint32(2)*(t_uv+l_uv)) >> int32(3)
  53646 		diag_03 = (avg + uint32(2)*(tl_uv+uv)) >> int32(3)
  53647 		uv02 = (diag_12 + tl_uv) >> int32(1)
  53648 		uv1 = (diag_03 + t_uv) >> int32(1)
  53649 		v1 = top_dst + uintptr((int32(2)*x-int32(1))*int32(4))
  53650 		v2 = int32(**(**uint8_t)(__ccgo_up(top_y + uintptr(int32(2)*x-int32(1)))))
  53651 		v3 = int32(uint8(uv02 & uint32(0xff)))
  53652 		v4 = int32(uint8(uv02 >> libc.Int32FromInt32(16)))
  53653 		v5 = v1
  53654 		v8 = v2 * int32(19077) >> int32(8)
  53655 		goto _90
  53656 	_90:
  53657 		v10 = v3 * int32(33050) >> int32(8)
  53658 		goto _92
  53659 	_92:
  53660 		v12 = v8 + v10 - int32(17685)
  53661 		if v12 & ^int32(YUV_MASK2) == 0 {
  53662 			v15 = v12 >> int32(YUV_FIX2)
  53663 		} else {
  53664 			if v12 < 0 {
  53665 				v16 = 0
  53666 			} else {
  53667 				v16 = int32(255)
  53668 			}
  53669 			v15 = v16
  53670 		}
  53671 		v13 = v15
  53672 		goto _95
  53673 	_95:
  53674 		v6 = v13
  53675 		goto _88
  53676 	_88:
  53677 		**(**uint8_t)(__ccgo_up(v5)) = uint8(v6)
  53678 		v19 = v2 * int32(19077) >> int32(8)
  53679 		goto _101
  53680 	_101:
  53681 		v21 = v3 * int32(6419) >> int32(8)
  53682 		goto _103
  53683 	_103:
  53684 		v23 = v4 * int32(13320) >> int32(8)
  53685 		goto _105
  53686 	_105:
  53687 		v25 = v19 - v21 - v23 + int32(8708)
  53688 		if v25 & ^int32(YUV_MASK2) == 0 {
  53689 			v28 = v25 >> int32(YUV_FIX2)
  53690 		} else {
  53691 			if v25 < 0 {
  53692 				v29 = 0
  53693 			} else {
  53694 				v29 = int32(255)
  53695 			}
  53696 			v28 = v29
  53697 		}
  53698 		v26 = v28
  53699 		goto _108
  53700 	_108:
  53701 		v17 = v26
  53702 		goto _99
  53703 	_99:
  53704 		**(**uint8_t)(__ccgo_up(v5 + 1)) = uint8(v17)
  53705 		v32 = v2 * int32(19077) >> int32(8)
  53706 		goto _114
  53707 	_114:
  53708 		v34 = v4 * int32(26149) >> int32(8)
  53709 		goto _116
  53710 	_116:
  53711 		v36 = v32 + v34 - int32(14234)
  53712 		if v36 & ^int32(YUV_MASK2) == 0 {
  53713 			v39 = v36 >> int32(YUV_FIX2)
  53714 		} else {
  53715 			if v36 < 0 {
  53716 				v40 = 0
  53717 			} else {
  53718 				v40 = int32(255)
  53719 			}
  53720 			v39 = v40
  53721 		}
  53722 		v37 = v39
  53723 		goto _119
  53724 	_119:
  53725 		v30 = v37
  53726 		goto _112
  53727 	_112:
  53728 		**(**uint8_t)(__ccgo_up(v5 + 2)) = uint8(v30)
  53729 		**(**uint8_t)(__ccgo_up(v1 + 3)) = uint8(0xff)
  53730 		v1 = top_dst + uintptr((int32(2)*x-0)*int32(4))
  53731 		v2 = int32(**(**uint8_t)(__ccgo_up(top_y + uintptr(int32(2)*x-0))))
  53732 		v3 = int32(uint8(uv1 & uint32(0xff)))
  53733 		v4 = int32(uint8(uv1 >> libc.Int32FromInt32(16)))
  53734 		v5 = v1
  53735 		v8 = v2 * int32(19077) >> int32(8)
  53736 		goto _130
  53737 	_130:
  53738 		v10 = v3 * int32(33050) >> int32(8)
  53739 		goto _132
  53740 	_132:
  53741 		v12 = v8 + v10 - int32(17685)
  53742 		if v12 & ^int32(YUV_MASK2) == 0 {
  53743 			v15 = v12 >> int32(YUV_FIX2)
  53744 		} else {
  53745 			if v12 < 0 {
  53746 				v16 = 0
  53747 			} else {
  53748 				v16 = int32(255)
  53749 			}
  53750 			v15 = v16
  53751 		}
  53752 		v13 = v15
  53753 		goto _135
  53754 	_135:
  53755 		v6 = v13
  53756 		goto _128
  53757 	_128:
  53758 		**(**uint8_t)(__ccgo_up(v5)) = uint8(v6)
  53759 		v19 = v2 * int32(19077) >> int32(8)
  53760 		goto _141
  53761 	_141:
  53762 		v21 = v3 * int32(6419) >> int32(8)
  53763 		goto _143
  53764 	_143:
  53765 		v23 = v4 * int32(13320) >> int32(8)
  53766 		goto _145
  53767 	_145:
  53768 		v25 = v19 - v21 - v23 + int32(8708)
  53769 		if v25 & ^int32(YUV_MASK2) == 0 {
  53770 			v28 = v25 >> int32(YUV_FIX2)
  53771 		} else {
  53772 			if v25 < 0 {
  53773 				v29 = 0
  53774 			} else {
  53775 				v29 = int32(255)
  53776 			}
  53777 			v28 = v29
  53778 		}
  53779 		v26 = v28
  53780 		goto _148
  53781 	_148:
  53782 		v17 = v26
  53783 		goto _139
  53784 	_139:
  53785 		**(**uint8_t)(__ccgo_up(v5 + 1)) = uint8(v17)
  53786 		v32 = v2 * int32(19077) >> int32(8)
  53787 		goto _154
  53788 	_154:
  53789 		v34 = v4 * int32(26149) >> int32(8)
  53790 		goto _156
  53791 	_156:
  53792 		v36 = v32 + v34 - int32(14234)
  53793 		if v36 & ^int32(YUV_MASK2) == 0 {
  53794 			v39 = v36 >> int32(YUV_FIX2)
  53795 		} else {
  53796 			if v36 < 0 {
  53797 				v40 = 0
  53798 			} else {
  53799 				v40 = int32(255)
  53800 			}
  53801 			v39 = v40
  53802 		}
  53803 		v37 = v39
  53804 		goto _159
  53805 	_159:
  53806 		v30 = v37
  53807 		goto _152
  53808 	_152:
  53809 		**(**uint8_t)(__ccgo_up(v5 + 2)) = uint8(v30)
  53810 		**(**uint8_t)(__ccgo_up(v1 + 3)) = uint8(0xff)
  53811 		if bottom_y != libc.UintptrFromInt32(0) {
  53812 			uv03 = (diag_03 + l_uv) >> int32(1)
  53813 			uv11 = (diag_12 + uv) >> int32(1)
  53814 			v1 = bottom_dst + uintptr((int32(2)*x-int32(1))*int32(4))
  53815 			v2 = int32(**(**uint8_t)(__ccgo_up(bottom_y + uintptr(int32(2)*x-int32(1)))))
  53816 			v3 = int32(uint8(uv03 & uint32(0xff)))
  53817 			v4 = int32(uint8(uv03 >> libc.Int32FromInt32(16)))
  53818 			v5 = v1
  53819 			v8 = v2 * int32(19077) >> int32(8)
  53820 			goto _170
  53821 		_170:
  53822 			v10 = v3 * int32(33050) >> int32(8)
  53823 			goto _172
  53824 		_172:
  53825 			v12 = v8 + v10 - int32(17685)
  53826 			if v12 & ^int32(YUV_MASK2) == 0 {
  53827 				v15 = v12 >> int32(YUV_FIX2)
  53828 			} else {
  53829 				if v12 < 0 {
  53830 					v16 = 0
  53831 				} else {
  53832 					v16 = int32(255)
  53833 				}
  53834 				v15 = v16
  53835 			}
  53836 			v13 = v15
  53837 			goto _175
  53838 		_175:
  53839 			v6 = v13
  53840 			goto _168
  53841 		_168:
  53842 			**(**uint8_t)(__ccgo_up(v5)) = uint8(v6)
  53843 			v19 = v2 * int32(19077) >> int32(8)
  53844 			goto _181
  53845 		_181:
  53846 			v21 = v3 * int32(6419) >> int32(8)
  53847 			goto _183
  53848 		_183:
  53849 			v23 = v4 * int32(13320) >> int32(8)
  53850 			goto _185
  53851 		_185:
  53852 			v25 = v19 - v21 - v23 + int32(8708)
  53853 			if v25 & ^int32(YUV_MASK2) == 0 {
  53854 				v28 = v25 >> int32(YUV_FIX2)
  53855 			} else {
  53856 				if v25 < 0 {
  53857 					v29 = 0
  53858 				} else {
  53859 					v29 = int32(255)
  53860 				}
  53861 				v28 = v29
  53862 			}
  53863 			v26 = v28
  53864 			goto _188
  53865 		_188:
  53866 			v17 = v26
  53867 			goto _179
  53868 		_179:
  53869 			**(**uint8_t)(__ccgo_up(v5 + 1)) = uint8(v17)
  53870 			v32 = v2 * int32(19077) >> int32(8)
  53871 			goto _194
  53872 		_194:
  53873 			v34 = v4 * int32(26149) >> int32(8)
  53874 			goto _196
  53875 		_196:
  53876 			v36 = v32 + v34 - int32(14234)
  53877 			if v36 & ^int32(YUV_MASK2) == 0 {
  53878 				v39 = v36 >> int32(YUV_FIX2)
  53879 			} else {
  53880 				if v36 < 0 {
  53881 					v40 = 0
  53882 				} else {
  53883 					v40 = int32(255)
  53884 				}
  53885 				v39 = v40
  53886 			}
  53887 			v37 = v39
  53888 			goto _199
  53889 		_199:
  53890 			v30 = v37
  53891 			goto _192
  53892 		_192:
  53893 			**(**uint8_t)(__ccgo_up(v5 + 2)) = uint8(v30)
  53894 			**(**uint8_t)(__ccgo_up(v1 + 3)) = uint8(0xff)
  53895 			v1 = bottom_dst + uintptr((int32(2)*x+0)*int32(4))
  53896 			v2 = int32(**(**uint8_t)(__ccgo_up(bottom_y + uintptr(int32(2)*x+0))))
  53897 			v3 = int32(uint8(uv11 & uint32(0xff)))
  53898 			v4 = int32(uint8(uv11 >> libc.Int32FromInt32(16)))
  53899 			v5 = v1
  53900 			v8 = v2 * int32(19077) >> int32(8)
  53901 			goto _210
  53902 		_210:
  53903 			v10 = v3 * int32(33050) >> int32(8)
  53904 			goto _212
  53905 		_212:
  53906 			v12 = v8 + v10 - int32(17685)
  53907 			if v12 & ^int32(YUV_MASK2) == 0 {
  53908 				v15 = v12 >> int32(YUV_FIX2)
  53909 			} else {
  53910 				if v12 < 0 {
  53911 					v16 = 0
  53912 				} else {
  53913 					v16 = int32(255)
  53914 				}
  53915 				v15 = v16
  53916 			}
  53917 			v13 = v15
  53918 			goto _215
  53919 		_215:
  53920 			v6 = v13
  53921 			goto _208
  53922 		_208:
  53923 			**(**uint8_t)(__ccgo_up(v5)) = uint8(v6)
  53924 			v19 = v2 * int32(19077) >> int32(8)
  53925 			goto _221
  53926 		_221:
  53927 			v21 = v3 * int32(6419) >> int32(8)
  53928 			goto _223
  53929 		_223:
  53930 			v23 = v4 * int32(13320) >> int32(8)
  53931 			goto _225
  53932 		_225:
  53933 			v25 = v19 - v21 - v23 + int32(8708)
  53934 			if v25 & ^int32(YUV_MASK2) == 0 {
  53935 				v28 = v25 >> int32(YUV_FIX2)
  53936 			} else {
  53937 				if v25 < 0 {
  53938 					v29 = 0
  53939 				} else {
  53940 					v29 = int32(255)
  53941 				}
  53942 				v28 = v29
  53943 			}
  53944 			v26 = v28
  53945 			goto _228
  53946 		_228:
  53947 			v17 = v26
  53948 			goto _219
  53949 		_219:
  53950 			**(**uint8_t)(__ccgo_up(v5 + 1)) = uint8(v17)
  53951 			v32 = v2 * int32(19077) >> int32(8)
  53952 			goto _234
  53953 		_234:
  53954 			v34 = v4 * int32(26149) >> int32(8)
  53955 			goto _236
  53956 		_236:
  53957 			v36 = v32 + v34 - int32(14234)
  53958 			if v36 & ^int32(YUV_MASK2) == 0 {
  53959 				v39 = v36 >> int32(YUV_FIX2)
  53960 			} else {
  53961 				if v36 < 0 {
  53962 					v40 = 0
  53963 				} else {
  53964 					v40 = int32(255)
  53965 				}
  53966 				v39 = v40
  53967 			}
  53968 			v37 = v39
  53969 			goto _239
  53970 		_239:
  53971 			v30 = v37
  53972 			goto _232
  53973 		_232:
  53974 			**(**uint8_t)(__ccgo_up(v5 + 2)) = uint8(v30)
  53975 			**(**uint8_t)(__ccgo_up(v1 + 3)) = uint8(0xff)
  53976 		}
  53977 		tl_uv = t_uv
  53978 		l_uv = uv
  53979 		goto _81
  53980 	_81:
  53981 		;
  53982 		x = x + 1
  53983 	}
  53984 	if !(len1&libc.Int32FromInt32(1) != 0) {
  53985 		uv04 = (uint32(3)*tl_uv + l_uv + uint32(0x00020002)) >> int32(2)
  53986 		v1 = top_dst + uintptr((len1-int32(1))*int32(4))
  53987 		v2 = int32(**(**uint8_t)(__ccgo_up(top_y + uintptr(len1-int32(1)))))
  53988 		v3 = int32(uint8(uv04 & uint32(0xff)))
  53989 		v4 = int32(uint8(uv04 >> libc.Int32FromInt32(16)))
  53990 		v5 = v1
  53991 		v8 = v2 * int32(19077) >> int32(8)
  53992 		goto _250
  53993 	_250:
  53994 		v10 = v3 * int32(33050) >> int32(8)
  53995 		goto _252
  53996 	_252:
  53997 		v12 = v8 + v10 - int32(17685)
  53998 		if v12 & ^int32(YUV_MASK2) == 0 {
  53999 			v15 = v12 >> int32(YUV_FIX2)
  54000 		} else {
  54001 			if v12 < 0 {
  54002 				v16 = 0
  54003 			} else {
  54004 				v16 = int32(255)
  54005 			}
  54006 			v15 = v16
  54007 		}
  54008 		v13 = v15
  54009 		goto _255
  54010 	_255:
  54011 		v6 = v13
  54012 		goto _248
  54013 	_248:
  54014 		**(**uint8_t)(__ccgo_up(v5)) = uint8(v6)
  54015 		v19 = v2 * int32(19077) >> int32(8)
  54016 		goto _261
  54017 	_261:
  54018 		v21 = v3 * int32(6419) >> int32(8)
  54019 		goto _263
  54020 	_263:
  54021 		v23 = v4 * int32(13320) >> int32(8)
  54022 		goto _265
  54023 	_265:
  54024 		v25 = v19 - v21 - v23 + int32(8708)
  54025 		if v25 & ^int32(YUV_MASK2) == 0 {
  54026 			v28 = v25 >> int32(YUV_FIX2)
  54027 		} else {
  54028 			if v25 < 0 {
  54029 				v29 = 0
  54030 			} else {
  54031 				v29 = int32(255)
  54032 			}
  54033 			v28 = v29
  54034 		}
  54035 		v26 = v28
  54036 		goto _268
  54037 	_268:
  54038 		v17 = v26
  54039 		goto _259
  54040 	_259:
  54041 		**(**uint8_t)(__ccgo_up(v5 + 1)) = uint8(v17)
  54042 		v32 = v2 * int32(19077) >> int32(8)
  54043 		goto _274
  54044 	_274:
  54045 		v34 = v4 * int32(26149) >> int32(8)
  54046 		goto _276
  54047 	_276:
  54048 		v36 = v32 + v34 - int32(14234)
  54049 		if v36 & ^int32(YUV_MASK2) == 0 {
  54050 			v39 = v36 >> int32(YUV_FIX2)
  54051 		} else {
  54052 			if v36 < 0 {
  54053 				v40 = 0
  54054 			} else {
  54055 				v40 = int32(255)
  54056 			}
  54057 			v39 = v40
  54058 		}
  54059 		v37 = v39
  54060 		goto _279
  54061 	_279:
  54062 		v30 = v37
  54063 		goto _272
  54064 	_272:
  54065 		**(**uint8_t)(__ccgo_up(v5 + 2)) = uint8(v30)
  54066 		**(**uint8_t)(__ccgo_up(v1 + 3)) = uint8(0xff)
  54067 		if bottom_y != libc.UintptrFromInt32(0) {
  54068 			uv05 = (uint32(3)*l_uv + tl_uv + uint32(0x00020002)) >> int32(2)
  54069 			v1 = bottom_dst + uintptr((len1-int32(1))*int32(4))
  54070 			v2 = int32(**(**uint8_t)(__ccgo_up(bottom_y + uintptr(len1-int32(1)))))
  54071 			v3 = int32(uint8(uv05 & uint32(0xff)))
  54072 			v4 = int32(uint8(uv05 >> libc.Int32FromInt32(16)))
  54073 			v5 = v1
  54074 			v8 = v2 * int32(19077) >> int32(8)
  54075 			goto _290
  54076 		_290:
  54077 			v10 = v3 * int32(33050) >> int32(8)
  54078 			goto _292
  54079 		_292:
  54080 			v12 = v8 + v10 - int32(17685)
  54081 			if v12 & ^int32(YUV_MASK2) == 0 {
  54082 				v15 = v12 >> int32(YUV_FIX2)
  54083 			} else {
  54084 				if v12 < 0 {
  54085 					v16 = 0
  54086 				} else {
  54087 					v16 = int32(255)
  54088 				}
  54089 				v15 = v16
  54090 			}
  54091 			v13 = v15
  54092 			goto _295
  54093 		_295:
  54094 			v6 = v13
  54095 			goto _288
  54096 		_288:
  54097 			**(**uint8_t)(__ccgo_up(v5)) = uint8(v6)
  54098 			v19 = v2 * int32(19077) >> int32(8)
  54099 			goto _301
  54100 		_301:
  54101 			v21 = v3 * int32(6419) >> int32(8)
  54102 			goto _303
  54103 		_303:
  54104 			v23 = v4 * int32(13320) >> int32(8)
  54105 			goto _305
  54106 		_305:
  54107 			v25 = v19 - v21 - v23 + int32(8708)
  54108 			if v25 & ^int32(YUV_MASK2) == 0 {
  54109 				v28 = v25 >> int32(YUV_FIX2)
  54110 			} else {
  54111 				if v25 < 0 {
  54112 					v29 = 0
  54113 				} else {
  54114 					v29 = int32(255)
  54115 				}
  54116 				v28 = v29
  54117 			}
  54118 			v26 = v28
  54119 			goto _308
  54120 		_308:
  54121 			v17 = v26
  54122 			goto _299
  54123 		_299:
  54124 			**(**uint8_t)(__ccgo_up(v5 + 1)) = uint8(v17)
  54125 			v32 = v2 * int32(19077) >> int32(8)
  54126 			goto _314
  54127 		_314:
  54128 			v34 = v4 * int32(26149) >> int32(8)
  54129 			goto _316
  54130 		_316:
  54131 			v36 = v32 + v34 - int32(14234)
  54132 			if v36 & ^int32(YUV_MASK2) == 0 {
  54133 				v39 = v36 >> int32(YUV_FIX2)
  54134 			} else {
  54135 				if v36 < 0 {
  54136 					v40 = 0
  54137 				} else {
  54138 					v40 = int32(255)
  54139 				}
  54140 				v39 = v40
  54141 			}
  54142 			v37 = v39
  54143 			goto _319
  54144 		_319:
  54145 			v30 = v37
  54146 			goto _312
  54147 		_312:
  54148 			**(**uint8_t)(__ccgo_up(v5 + 2)) = uint8(v30)
  54149 			**(**uint8_t)(__ccgo_up(v1 + 3)) = uint8(0xff)
  54150 		}
  54151 	}
  54152 }
  54153 
  54154 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) {
  54155 	var avg, diag_03, diag_12, l_uv, t_uv, tl_uv, uv, uv0, uv01, uv02, uv03, uv04, uv05, uv1, uv11 uint32_t
  54156 	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
  54157 	var v1, v5 uintptr
  54158 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  54159 	last_pixel_pair = (len1 - int32(1)) >> int32(1)
  54160 	tl_uv = uint32(int32(**(**uint8_t)(__ccgo_up(top_u))) | int32(**(**uint8_t)(__ccgo_up(top_v)))<<libc.Int32FromInt32(16)) /* top-left sample */
  54161 	l_uv = uint32(int32(**(**uint8_t)(__ccgo_up(cur_u))) | int32(**(**uint8_t)(__ccgo_up(cur_v)))<<libc.Int32FromInt32(16))
  54162 	uv0 = (uint32(3)*tl_uv + l_uv + uint32(0x00020002)) >> int32(2)
  54163 	v1 = top_dst
  54164 	**(**uint8_t)(__ccgo_up(v1)) = uint8(0xff)
  54165 	v2 = int32(**(**uint8_t)(__ccgo_up(top_y)))
  54166 	v3 = int32(uint8(uv0 & uint32(0xff)))
  54167 	v4 = int32(uint8(uv0 >> libc.Int32FromInt32(16)))
  54168 	v5 = v1 + uintptr(1)
  54169 	v8 = v2 * int32(19077) >> int32(8)
  54170 	goto _9
  54171 _9:
  54172 	v10 = v4 * int32(26149) >> int32(8)
  54173 	goto _11
  54174 _11:
  54175 	v12 = v8 + v10 - int32(14234)
  54176 	if v12 & ^int32(YUV_MASK2) == 0 {
  54177 		v15 = v12 >> int32(YUV_FIX2)
  54178 	} else {
  54179 		if v12 < 0 {
  54180 			v16 = 0
  54181 		} else {
  54182 			v16 = int32(255)
  54183 		}
  54184 		v15 = v16
  54185 	}
  54186 	v13 = v15
  54187 	goto _14
  54188 _14:
  54189 	v6 = v13
  54190 	goto _7
  54191 _7:
  54192 	**(**uint8_t)(__ccgo_up(v5)) = uint8(v6)
  54193 	v19 = v2 * int32(19077) >> int32(8)
  54194 	goto _20
  54195 _20:
  54196 	v21 = v3 * int32(6419) >> int32(8)
  54197 	goto _22
  54198 _22:
  54199 	v23 = v4 * int32(13320) >> int32(8)
  54200 	goto _24
  54201 _24:
  54202 	v25 = v19 - v21 - v23 + int32(8708)
  54203 	if v25 & ^int32(YUV_MASK2) == 0 {
  54204 		v28 = v25 >> int32(YUV_FIX2)
  54205 	} else {
  54206 		if v25 < 0 {
  54207 			v29 = 0
  54208 		} else {
  54209 			v29 = int32(255)
  54210 		}
  54211 		v28 = v29
  54212 	}
  54213 	v26 = v28
  54214 	goto _27
  54215 _27:
  54216 	v17 = v26
  54217 	goto _18
  54218 _18:
  54219 	**(**uint8_t)(__ccgo_up(v5 + 1)) = uint8(v17)
  54220 	v32 = v2 * int32(19077) >> int32(8)
  54221 	goto _33
  54222 _33:
  54223 	v34 = v3 * int32(33050) >> int32(8)
  54224 	goto _35
  54225 _35:
  54226 	v36 = v32 + v34 - int32(17685)
  54227 	if v36 & ^int32(YUV_MASK2) == 0 {
  54228 		v39 = v36 >> int32(YUV_FIX2)
  54229 	} else {
  54230 		if v36 < 0 {
  54231 			v40 = 0
  54232 		} else {
  54233 			v40 = int32(255)
  54234 		}
  54235 		v39 = v40
  54236 	}
  54237 	v37 = v39
  54238 	goto _38
  54239 _38:
  54240 	v30 = v37
  54241 	goto _31
  54242 _31:
  54243 	**(**uint8_t)(__ccgo_up(v5 + 2)) = uint8(v30)
  54244 	if bottom_y != libc.UintptrFromInt32(0) {
  54245 		uv01 = (uint32(3)*l_uv + tl_uv + uint32(0x00020002)) >> int32(2)
  54246 		v1 = bottom_dst
  54247 		**(**uint8_t)(__ccgo_up(v1)) = uint8(0xff)
  54248 		v2 = int32(**(**uint8_t)(__ccgo_up(bottom_y)))
  54249 		v3 = int32(uint8(uv01 & uint32(0xff)))
  54250 		v4 = int32(uint8(uv01 >> libc.Int32FromInt32(16)))
  54251 		v5 = v1 + uintptr(1)
  54252 		v8 = v2 * int32(19077) >> int32(8)
  54253 		goto _49
  54254 	_49:
  54255 		v10 = v4 * int32(26149) >> int32(8)
  54256 		goto _51
  54257 	_51:
  54258 		v12 = v8 + v10 - int32(14234)
  54259 		if v12 & ^int32(YUV_MASK2) == 0 {
  54260 			v15 = v12 >> int32(YUV_FIX2)
  54261 		} else {
  54262 			if v12 < 0 {
  54263 				v16 = 0
  54264 			} else {
  54265 				v16 = int32(255)
  54266 			}
  54267 			v15 = v16
  54268 		}
  54269 		v13 = v15
  54270 		goto _54
  54271 	_54:
  54272 		v6 = v13
  54273 		goto _47
  54274 	_47:
  54275 		**(**uint8_t)(__ccgo_up(v5)) = uint8(v6)
  54276 		v19 = v2 * int32(19077) >> int32(8)
  54277 		goto _60
  54278 	_60:
  54279 		v21 = v3 * int32(6419) >> int32(8)
  54280 		goto _62
  54281 	_62:
  54282 		v23 = v4 * int32(13320) >> int32(8)
  54283 		goto _64
  54284 	_64:
  54285 		v25 = v19 - v21 - v23 + int32(8708)
  54286 		if v25 & ^int32(YUV_MASK2) == 0 {
  54287 			v28 = v25 >> int32(YUV_FIX2)
  54288 		} else {
  54289 			if v25 < 0 {
  54290 				v29 = 0
  54291 			} else {
  54292 				v29 = int32(255)
  54293 			}
  54294 			v28 = v29
  54295 		}
  54296 		v26 = v28
  54297 		goto _67
  54298 	_67:
  54299 		v17 = v26
  54300 		goto _58
  54301 	_58:
  54302 		**(**uint8_t)(__ccgo_up(v5 + 1)) = uint8(v17)
  54303 		v32 = v2 * int32(19077) >> int32(8)
  54304 		goto _73
  54305 	_73:
  54306 		v34 = v3 * int32(33050) >> int32(8)
  54307 		goto _75
  54308 	_75:
  54309 		v36 = v32 + v34 - int32(17685)
  54310 		if v36 & ^int32(YUV_MASK2) == 0 {
  54311 			v39 = v36 >> int32(YUV_FIX2)
  54312 		} else {
  54313 			if v36 < 0 {
  54314 				v40 = 0
  54315 			} else {
  54316 				v40 = int32(255)
  54317 			}
  54318 			v39 = v40
  54319 		}
  54320 		v37 = v39
  54321 		goto _78
  54322 	_78:
  54323 		v30 = v37
  54324 		goto _71
  54325 	_71:
  54326 		**(**uint8_t)(__ccgo_up(v5 + 2)) = uint8(v30)
  54327 	}
  54328 	x = int32(1)
  54329 	for {
  54330 		if !(x <= last_pixel_pair) {
  54331 			break
  54332 		}
  54333 		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 */
  54334 		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*/
  54335 		avg = tl_uv + t_uv + l_uv + uv + uint32(0x00080008)
  54336 		diag_12 = (avg + uint32(2)*(t_uv+l_uv)) >> int32(3)
  54337 		diag_03 = (avg + uint32(2)*(tl_uv+uv)) >> int32(3)
  54338 		uv02 = (diag_12 + tl_uv) >> int32(1)
  54339 		uv1 = (diag_03 + t_uv) >> int32(1)
  54340 		v1 = top_dst + uintptr((int32(2)*x-int32(1))*int32(4))
  54341 		**(**uint8_t)(__ccgo_up(v1)) = uint8(0xff)
  54342 		v2 = int32(**(**uint8_t)(__ccgo_up(top_y + uintptr(int32(2)*x-int32(1)))))
  54343 		v3 = int32(uint8(uv02 & uint32(0xff)))
  54344 		v4 = int32(uint8(uv02 >> libc.Int32FromInt32(16)))
  54345 		v5 = v1 + uintptr(1)
  54346 		v8 = v2 * int32(19077) >> int32(8)
  54347 		goto _90
  54348 	_90:
  54349 		v10 = v4 * int32(26149) >> int32(8)
  54350 		goto _92
  54351 	_92:
  54352 		v12 = v8 + v10 - int32(14234)
  54353 		if v12 & ^int32(YUV_MASK2) == 0 {
  54354 			v15 = v12 >> int32(YUV_FIX2)
  54355 		} else {
  54356 			if v12 < 0 {
  54357 				v16 = 0
  54358 			} else {
  54359 				v16 = int32(255)
  54360 			}
  54361 			v15 = v16
  54362 		}
  54363 		v13 = v15
  54364 		goto _95
  54365 	_95:
  54366 		v6 = v13
  54367 		goto _88
  54368 	_88:
  54369 		**(**uint8_t)(__ccgo_up(v5)) = uint8(v6)
  54370 		v19 = v2 * int32(19077) >> int32(8)
  54371 		goto _101
  54372 	_101:
  54373 		v21 = v3 * int32(6419) >> int32(8)
  54374 		goto _103
  54375 	_103:
  54376 		v23 = v4 * int32(13320) >> int32(8)
  54377 		goto _105
  54378 	_105:
  54379 		v25 = v19 - v21 - v23 + int32(8708)
  54380 		if v25 & ^int32(YUV_MASK2) == 0 {
  54381 			v28 = v25 >> int32(YUV_FIX2)
  54382 		} else {
  54383 			if v25 < 0 {
  54384 				v29 = 0
  54385 			} else {
  54386 				v29 = int32(255)
  54387 			}
  54388 			v28 = v29
  54389 		}
  54390 		v26 = v28
  54391 		goto _108
  54392 	_108:
  54393 		v17 = v26
  54394 		goto _99
  54395 	_99:
  54396 		**(**uint8_t)(__ccgo_up(v5 + 1)) = uint8(v17)
  54397 		v32 = v2 * int32(19077) >> int32(8)
  54398 		goto _114
  54399 	_114:
  54400 		v34 = v3 * int32(33050) >> int32(8)
  54401 		goto _116
  54402 	_116:
  54403 		v36 = v32 + v34 - int32(17685)
  54404 		if v36 & ^int32(YUV_MASK2) == 0 {
  54405 			v39 = v36 >> int32(YUV_FIX2)
  54406 		} else {
  54407 			if v36 < 0 {
  54408 				v40 = 0
  54409 			} else {
  54410 				v40 = int32(255)
  54411 			}
  54412 			v39 = v40
  54413 		}
  54414 		v37 = v39
  54415 		goto _119
  54416 	_119:
  54417 		v30 = v37
  54418 		goto _112
  54419 	_112:
  54420 		**(**uint8_t)(__ccgo_up(v5 + 2)) = uint8(v30)
  54421 		v1 = top_dst + uintptr((int32(2)*x-0)*int32(4))
  54422 		**(**uint8_t)(__ccgo_up(v1)) = uint8(0xff)
  54423 		v2 = int32(**(**uint8_t)(__ccgo_up(top_y + uintptr(int32(2)*x-0))))
  54424 		v3 = int32(uint8(uv1 & uint32(0xff)))
  54425 		v4 = int32(uint8(uv1 >> libc.Int32FromInt32(16)))
  54426 		v5 = v1 + uintptr(1)
  54427 		v8 = v2 * int32(19077) >> int32(8)
  54428 		goto _130
  54429 	_130:
  54430 		v10 = v4 * int32(26149) >> int32(8)
  54431 		goto _132
  54432 	_132:
  54433 		v12 = v8 + v10 - int32(14234)
  54434 		if v12 & ^int32(YUV_MASK2) == 0 {
  54435 			v15 = v12 >> int32(YUV_FIX2)
  54436 		} else {
  54437 			if v12 < 0 {
  54438 				v16 = 0
  54439 			} else {
  54440 				v16 = int32(255)
  54441 			}
  54442 			v15 = v16
  54443 		}
  54444 		v13 = v15
  54445 		goto _135
  54446 	_135:
  54447 		v6 = v13
  54448 		goto _128
  54449 	_128:
  54450 		**(**uint8_t)(__ccgo_up(v5)) = uint8(v6)
  54451 		v19 = v2 * int32(19077) >> int32(8)
  54452 		goto _141
  54453 	_141:
  54454 		v21 = v3 * int32(6419) >> int32(8)
  54455 		goto _143
  54456 	_143:
  54457 		v23 = v4 * int32(13320) >> int32(8)
  54458 		goto _145
  54459 	_145:
  54460 		v25 = v19 - v21 - v23 + int32(8708)
  54461 		if v25 & ^int32(YUV_MASK2) == 0 {
  54462 			v28 = v25 >> int32(YUV_FIX2)
  54463 		} else {
  54464 			if v25 < 0 {
  54465 				v29 = 0
  54466 			} else {
  54467 				v29 = int32(255)
  54468 			}
  54469 			v28 = v29
  54470 		}
  54471 		v26 = v28
  54472 		goto _148
  54473 	_148:
  54474 		v17 = v26
  54475 		goto _139
  54476 	_139:
  54477 		**(**uint8_t)(__ccgo_up(v5 + 1)) = uint8(v17)
  54478 		v32 = v2 * int32(19077) >> int32(8)
  54479 		goto _154
  54480 	_154:
  54481 		v34 = v3 * int32(33050) >> int32(8)
  54482 		goto _156
  54483 	_156:
  54484 		v36 = v32 + v34 - int32(17685)
  54485 		if v36 & ^int32(YUV_MASK2) == 0 {
  54486 			v39 = v36 >> int32(YUV_FIX2)
  54487 		} else {
  54488 			if v36 < 0 {
  54489 				v40 = 0
  54490 			} else {
  54491 				v40 = int32(255)
  54492 			}
  54493 			v39 = v40
  54494 		}
  54495 		v37 = v39
  54496 		goto _159
  54497 	_159:
  54498 		v30 = v37
  54499 		goto _152
  54500 	_152:
  54501 		**(**uint8_t)(__ccgo_up(v5 + 2)) = uint8(v30)
  54502 		if bottom_y != libc.UintptrFromInt32(0) {
  54503 			uv03 = (diag_03 + l_uv) >> int32(1)
  54504 			uv11 = (diag_12 + uv) >> int32(1)
  54505 			v1 = bottom_dst + uintptr((int32(2)*x-int32(1))*int32(4))
  54506 			**(**uint8_t)(__ccgo_up(v1)) = uint8(0xff)
  54507 			v2 = int32(**(**uint8_t)(__ccgo_up(bottom_y + uintptr(int32(2)*x-int32(1)))))
  54508 			v3 = int32(uint8(uv03 & uint32(0xff)))
  54509 			v4 = int32(uint8(uv03 >> libc.Int32FromInt32(16)))
  54510 			v5 = v1 + uintptr(1)
  54511 			v8 = v2 * int32(19077) >> int32(8)
  54512 			goto _170
  54513 		_170:
  54514 			v10 = v4 * int32(26149) >> int32(8)
  54515 			goto _172
  54516 		_172:
  54517 			v12 = v8 + v10 - int32(14234)
  54518 			if v12 & ^int32(YUV_MASK2) == 0 {
  54519 				v15 = v12 >> int32(YUV_FIX2)
  54520 			} else {
  54521 				if v12 < 0 {
  54522 					v16 = 0
  54523 				} else {
  54524 					v16 = int32(255)
  54525 				}
  54526 				v15 = v16
  54527 			}
  54528 			v13 = v15
  54529 			goto _175
  54530 		_175:
  54531 			v6 = v13
  54532 			goto _168
  54533 		_168:
  54534 			**(**uint8_t)(__ccgo_up(v5)) = uint8(v6)
  54535 			v19 = v2 * int32(19077) >> int32(8)
  54536 			goto _181
  54537 		_181:
  54538 			v21 = v3 * int32(6419) >> int32(8)
  54539 			goto _183
  54540 		_183:
  54541 			v23 = v4 * int32(13320) >> int32(8)
  54542 			goto _185
  54543 		_185:
  54544 			v25 = v19 - v21 - v23 + int32(8708)
  54545 			if v25 & ^int32(YUV_MASK2) == 0 {
  54546 				v28 = v25 >> int32(YUV_FIX2)
  54547 			} else {
  54548 				if v25 < 0 {
  54549 					v29 = 0
  54550 				} else {
  54551 					v29 = int32(255)
  54552 				}
  54553 				v28 = v29
  54554 			}
  54555 			v26 = v28
  54556 			goto _188
  54557 		_188:
  54558 			v17 = v26
  54559 			goto _179
  54560 		_179:
  54561 			**(**uint8_t)(__ccgo_up(v5 + 1)) = uint8(v17)
  54562 			v32 = v2 * int32(19077) >> int32(8)
  54563 			goto _194
  54564 		_194:
  54565 			v34 = v3 * int32(33050) >> int32(8)
  54566 			goto _196
  54567 		_196:
  54568 			v36 = v32 + v34 - int32(17685)
  54569 			if v36 & ^int32(YUV_MASK2) == 0 {
  54570 				v39 = v36 >> int32(YUV_FIX2)
  54571 			} else {
  54572 				if v36 < 0 {
  54573 					v40 = 0
  54574 				} else {
  54575 					v40 = int32(255)
  54576 				}
  54577 				v39 = v40
  54578 			}
  54579 			v37 = v39
  54580 			goto _199
  54581 		_199:
  54582 			v30 = v37
  54583 			goto _192
  54584 		_192:
  54585 			**(**uint8_t)(__ccgo_up(v5 + 2)) = uint8(v30)
  54586 			v1 = bottom_dst + uintptr((int32(2)*x+0)*int32(4))
  54587 			**(**uint8_t)(__ccgo_up(v1)) = uint8(0xff)
  54588 			v2 = int32(**(**uint8_t)(__ccgo_up(bottom_y + uintptr(int32(2)*x+0))))
  54589 			v3 = int32(uint8(uv11 & uint32(0xff)))
  54590 			v4 = int32(uint8(uv11 >> libc.Int32FromInt32(16)))
  54591 			v5 = v1 + uintptr(1)
  54592 			v8 = v2 * int32(19077) >> int32(8)
  54593 			goto _210
  54594 		_210:
  54595 			v10 = v4 * int32(26149) >> int32(8)
  54596 			goto _212
  54597 		_212:
  54598 			v12 = v8 + v10 - int32(14234)
  54599 			if v12 & ^int32(YUV_MASK2) == 0 {
  54600 				v15 = v12 >> int32(YUV_FIX2)
  54601 			} else {
  54602 				if v12 < 0 {
  54603 					v16 = 0
  54604 				} else {
  54605 					v16 = int32(255)
  54606 				}
  54607 				v15 = v16
  54608 			}
  54609 			v13 = v15
  54610 			goto _215
  54611 		_215:
  54612 			v6 = v13
  54613 			goto _208
  54614 		_208:
  54615 			**(**uint8_t)(__ccgo_up(v5)) = uint8(v6)
  54616 			v19 = v2 * int32(19077) >> int32(8)
  54617 			goto _221
  54618 		_221:
  54619 			v21 = v3 * int32(6419) >> int32(8)
  54620 			goto _223
  54621 		_223:
  54622 			v23 = v4 * int32(13320) >> int32(8)
  54623 			goto _225
  54624 		_225:
  54625 			v25 = v19 - v21 - v23 + int32(8708)
  54626 			if v25 & ^int32(YUV_MASK2) == 0 {
  54627 				v28 = v25 >> int32(YUV_FIX2)
  54628 			} else {
  54629 				if v25 < 0 {
  54630 					v29 = 0
  54631 				} else {
  54632 					v29 = int32(255)
  54633 				}
  54634 				v28 = v29
  54635 			}
  54636 			v26 = v28
  54637 			goto _228
  54638 		_228:
  54639 			v17 = v26
  54640 			goto _219
  54641 		_219:
  54642 			**(**uint8_t)(__ccgo_up(v5 + 1)) = uint8(v17)
  54643 			v32 = v2 * int32(19077) >> int32(8)
  54644 			goto _234
  54645 		_234:
  54646 			v34 = v3 * int32(33050) >> int32(8)
  54647 			goto _236
  54648 		_236:
  54649 			v36 = v32 + v34 - int32(17685)
  54650 			if v36 & ^int32(YUV_MASK2) == 0 {
  54651 				v39 = v36 >> int32(YUV_FIX2)
  54652 			} else {
  54653 				if v36 < 0 {
  54654 					v40 = 0
  54655 				} else {
  54656 					v40 = int32(255)
  54657 				}
  54658 				v39 = v40
  54659 			}
  54660 			v37 = v39
  54661 			goto _239
  54662 		_239:
  54663 			v30 = v37
  54664 			goto _232
  54665 		_232:
  54666 			**(**uint8_t)(__ccgo_up(v5 + 2)) = uint8(v30)
  54667 		}
  54668 		tl_uv = t_uv
  54669 		l_uv = uv
  54670 		goto _81
  54671 	_81:
  54672 		;
  54673 		x = x + 1
  54674 	}
  54675 	if !(len1&libc.Int32FromInt32(1) != 0) {
  54676 		uv04 = (uint32(3)*tl_uv + l_uv + uint32(0x00020002)) >> int32(2)
  54677 		v1 = top_dst + uintptr((len1-int32(1))*int32(4))
  54678 		**(**uint8_t)(__ccgo_up(v1)) = uint8(0xff)
  54679 		v2 = int32(**(**uint8_t)(__ccgo_up(top_y + uintptr(len1-int32(1)))))
  54680 		v3 = int32(uint8(uv04 & uint32(0xff)))
  54681 		v4 = int32(uint8(uv04 >> libc.Int32FromInt32(16)))
  54682 		v5 = v1 + uintptr(1)
  54683 		v8 = v2 * int32(19077) >> int32(8)
  54684 		goto _250
  54685 	_250:
  54686 		v10 = v4 * int32(26149) >> int32(8)
  54687 		goto _252
  54688 	_252:
  54689 		v12 = v8 + v10 - int32(14234)
  54690 		if v12 & ^int32(YUV_MASK2) == 0 {
  54691 			v15 = v12 >> int32(YUV_FIX2)
  54692 		} else {
  54693 			if v12 < 0 {
  54694 				v16 = 0
  54695 			} else {
  54696 				v16 = int32(255)
  54697 			}
  54698 			v15 = v16
  54699 		}
  54700 		v13 = v15
  54701 		goto _255
  54702 	_255:
  54703 		v6 = v13
  54704 		goto _248
  54705 	_248:
  54706 		**(**uint8_t)(__ccgo_up(v5)) = uint8(v6)
  54707 		v19 = v2 * int32(19077) >> int32(8)
  54708 		goto _261
  54709 	_261:
  54710 		v21 = v3 * int32(6419) >> int32(8)
  54711 		goto _263
  54712 	_263:
  54713 		v23 = v4 * int32(13320) >> int32(8)
  54714 		goto _265
  54715 	_265:
  54716 		v25 = v19 - v21 - v23 + int32(8708)
  54717 		if v25 & ^int32(YUV_MASK2) == 0 {
  54718 			v28 = v25 >> int32(YUV_FIX2)
  54719 		} else {
  54720 			if v25 < 0 {
  54721 				v29 = 0
  54722 			} else {
  54723 				v29 = int32(255)
  54724 			}
  54725 			v28 = v29
  54726 		}
  54727 		v26 = v28
  54728 		goto _268
  54729 	_268:
  54730 		v17 = v26
  54731 		goto _259
  54732 	_259:
  54733 		**(**uint8_t)(__ccgo_up(v5 + 1)) = uint8(v17)
  54734 		v32 = v2 * int32(19077) >> int32(8)
  54735 		goto _274
  54736 	_274:
  54737 		v34 = v3 * int32(33050) >> int32(8)
  54738 		goto _276
  54739 	_276:
  54740 		v36 = v32 + v34 - int32(17685)
  54741 		if v36 & ^int32(YUV_MASK2) == 0 {
  54742 			v39 = v36 >> int32(YUV_FIX2)
  54743 		} else {
  54744 			if v36 < 0 {
  54745 				v40 = 0
  54746 			} else {
  54747 				v40 = int32(255)
  54748 			}
  54749 			v39 = v40
  54750 		}
  54751 		v37 = v39
  54752 		goto _279
  54753 	_279:
  54754 		v30 = v37
  54755 		goto _272
  54756 	_272:
  54757 		**(**uint8_t)(__ccgo_up(v5 + 2)) = uint8(v30)
  54758 		if bottom_y != libc.UintptrFromInt32(0) {
  54759 			uv05 = (uint32(3)*l_uv + tl_uv + uint32(0x00020002)) >> int32(2)
  54760 			v1 = bottom_dst + uintptr((len1-int32(1))*int32(4))
  54761 			**(**uint8_t)(__ccgo_up(v1)) = uint8(0xff)
  54762 			v2 = int32(**(**uint8_t)(__ccgo_up(bottom_y + uintptr(len1-int32(1)))))
  54763 			v3 = int32(uint8(uv05 & uint32(0xff)))
  54764 			v4 = int32(uint8(uv05 >> libc.Int32FromInt32(16)))
  54765 			v5 = v1 + uintptr(1)
  54766 			v8 = v2 * int32(19077) >> int32(8)
  54767 			goto _290
  54768 		_290:
  54769 			v10 = v4 * int32(26149) >> int32(8)
  54770 			goto _292
  54771 		_292:
  54772 			v12 = v8 + v10 - int32(14234)
  54773 			if v12 & ^int32(YUV_MASK2) == 0 {
  54774 				v15 = v12 >> int32(YUV_FIX2)
  54775 			} else {
  54776 				if v12 < 0 {
  54777 					v16 = 0
  54778 				} else {
  54779 					v16 = int32(255)
  54780 				}
  54781 				v15 = v16
  54782 			}
  54783 			v13 = v15
  54784 			goto _295
  54785 		_295:
  54786 			v6 = v13
  54787 			goto _288
  54788 		_288:
  54789 			**(**uint8_t)(__ccgo_up(v5)) = uint8(v6)
  54790 			v19 = v2 * int32(19077) >> int32(8)
  54791 			goto _301
  54792 		_301:
  54793 			v21 = v3 * int32(6419) >> int32(8)
  54794 			goto _303
  54795 		_303:
  54796 			v23 = v4 * int32(13320) >> int32(8)
  54797 			goto _305
  54798 		_305:
  54799 			v25 = v19 - v21 - v23 + int32(8708)
  54800 			if v25 & ^int32(YUV_MASK2) == 0 {
  54801 				v28 = v25 >> int32(YUV_FIX2)
  54802 			} else {
  54803 				if v25 < 0 {
  54804 					v29 = 0
  54805 				} else {
  54806 					v29 = int32(255)
  54807 				}
  54808 				v28 = v29
  54809 			}
  54810 			v26 = v28
  54811 			goto _308
  54812 		_308:
  54813 			v17 = v26
  54814 			goto _299
  54815 		_299:
  54816 			**(**uint8_t)(__ccgo_up(v5 + 1)) = uint8(v17)
  54817 			v32 = v2 * int32(19077) >> int32(8)
  54818 			goto _314
  54819 		_314:
  54820 			v34 = v3 * int32(33050) >> int32(8)
  54821 			goto _316
  54822 		_316:
  54823 			v36 = v32 + v34 - int32(17685)
  54824 			if v36 & ^int32(YUV_MASK2) == 0 {
  54825 				v39 = v36 >> int32(YUV_FIX2)
  54826 			} else {
  54827 				if v36 < 0 {
  54828 					v40 = 0
  54829 				} else {
  54830 					v40 = int32(255)
  54831 				}
  54832 				v39 = v40
  54833 			}
  54834 			v37 = v39
  54835 			goto _319
  54836 		_319:
  54837 			v30 = v37
  54838 			goto _312
  54839 		_312:
  54840 			**(**uint8_t)(__ccgo_up(v5 + 2)) = uint8(v30)
  54841 		}
  54842 	}
  54843 }
  54844 
  54845 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) {
  54846 	var avg, diag_03, diag_12, l_uv, t_uv, tl_uv, uv, uv0, uv01, uv02, uv03, uv04, uv05, uv1, uv11 uint32_t
  54847 	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
  54848 	var v4 uintptr
  54849 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  54850 	last_pixel_pair = (len1 - int32(1)) >> int32(1)
  54851 	tl_uv = uint32(int32(**(**uint8_t)(__ccgo_up(top_u))) | int32(**(**uint8_t)(__ccgo_up(top_v)))<<libc.Int32FromInt32(16)) /* top-left sample */
  54852 	l_uv = uint32(int32(**(**uint8_t)(__ccgo_up(cur_u))) | int32(**(**uint8_t)(__ccgo_up(cur_v)))<<libc.Int32FromInt32(16))
  54853 	uv0 = (uint32(3)*tl_uv + l_uv + uint32(0x00020002)) >> int32(2)
  54854 	v1 = int32(**(**uint8_t)(__ccgo_up(top_y)))
  54855 	v2 = int32(uv0 & uint32(0xff))
  54856 	v3 = int32(uv0 >> libc.Int32FromInt32(16))
  54857 	v4 = top_dst
  54858 	v7 = v1 * int32(19077) >> int32(8)
  54859 	goto _8
  54860 _8:
  54861 	v9 = v3 * int32(26149) >> int32(8)
  54862 	goto _10
  54863 _10:
  54864 	v11 = v7 + v9 - int32(14234)
  54865 	if v11 & ^int32(YUV_MASK2) == 0 {
  54866 		v14 = v11 >> int32(YUV_FIX2)
  54867 	} else {
  54868 		if v11 < 0 {
  54869 			v15 = 0
  54870 		} else {
  54871 			v15 = int32(255)
  54872 		}
  54873 		v14 = v15
  54874 	}
  54875 	v12 = v14
  54876 	goto _13
  54877 _13:
  54878 	v5 = v12
  54879 	goto _6
  54880 _6:
  54881 	**(**uint8_t)(__ccgo_up(v4)) = uint8(v5)
  54882 	v18 = v1 * int32(19077) >> int32(8)
  54883 	goto _19
  54884 _19:
  54885 	v20 = v2 * int32(6419) >> int32(8)
  54886 	goto _21
  54887 _21:
  54888 	v22 = v3 * int32(13320) >> int32(8)
  54889 	goto _23
  54890 _23:
  54891 	v24 = v18 - v20 - v22 + int32(8708)
  54892 	if v24 & ^int32(YUV_MASK2) == 0 {
  54893 		v27 = v24 >> int32(YUV_FIX2)
  54894 	} else {
  54895 		if v24 < 0 {
  54896 			v28 = 0
  54897 		} else {
  54898 			v28 = int32(255)
  54899 		}
  54900 		v27 = v28
  54901 	}
  54902 	v25 = v27
  54903 	goto _26
  54904 _26:
  54905 	v16 = v25
  54906 	goto _17
  54907 _17:
  54908 	**(**uint8_t)(__ccgo_up(v4 + 1)) = uint8(v16)
  54909 	v31 = v1 * int32(19077) >> int32(8)
  54910 	goto _32
  54911 _32:
  54912 	v33 = v2 * int32(33050) >> int32(8)
  54913 	goto _34
  54914 _34:
  54915 	v35 = v31 + v33 - int32(17685)
  54916 	if v35 & ^int32(YUV_MASK2) == 0 {
  54917 		v38 = v35 >> int32(YUV_FIX2)
  54918 	} else {
  54919 		if v35 < 0 {
  54920 			v39 = 0
  54921 		} else {
  54922 			v39 = int32(255)
  54923 		}
  54924 		v38 = v39
  54925 	}
  54926 	v36 = v38
  54927 	goto _37
  54928 _37:
  54929 	v29 = v36
  54930 	goto _30
  54931 _30:
  54932 	**(**uint8_t)(__ccgo_up(v4 + 2)) = uint8(v29)
  54933 	if bottom_y != libc.UintptrFromInt32(0) {
  54934 		uv01 = (uint32(3)*l_uv + tl_uv + uint32(0x00020002)) >> int32(2)
  54935 		v1 = int32(**(**uint8_t)(__ccgo_up(bottom_y)))
  54936 		v2 = int32(uv01 & uint32(0xff))
  54937 		v3 = int32(uv01 >> libc.Int32FromInt32(16))
  54938 		v4 = bottom_dst
  54939 		v7 = v1 * int32(19077) >> int32(8)
  54940 		goto _47
  54941 	_47:
  54942 		v9 = v3 * int32(26149) >> int32(8)
  54943 		goto _49
  54944 	_49:
  54945 		v11 = v7 + v9 - int32(14234)
  54946 		if v11 & ^int32(YUV_MASK2) == 0 {
  54947 			v14 = v11 >> int32(YUV_FIX2)
  54948 		} else {
  54949 			if v11 < 0 {
  54950 				v15 = 0
  54951 			} else {
  54952 				v15 = int32(255)
  54953 			}
  54954 			v14 = v15
  54955 		}
  54956 		v12 = v14
  54957 		goto _52
  54958 	_52:
  54959 		v5 = v12
  54960 		goto _45
  54961 	_45:
  54962 		**(**uint8_t)(__ccgo_up(v4)) = uint8(v5)
  54963 		v18 = v1 * int32(19077) >> int32(8)
  54964 		goto _58
  54965 	_58:
  54966 		v20 = v2 * int32(6419) >> int32(8)
  54967 		goto _60
  54968 	_60:
  54969 		v22 = v3 * int32(13320) >> int32(8)
  54970 		goto _62
  54971 	_62:
  54972 		v24 = v18 - v20 - v22 + int32(8708)
  54973 		if v24 & ^int32(YUV_MASK2) == 0 {
  54974 			v27 = v24 >> int32(YUV_FIX2)
  54975 		} else {
  54976 			if v24 < 0 {
  54977 				v28 = 0
  54978 			} else {
  54979 				v28 = int32(255)
  54980 			}
  54981 			v27 = v28
  54982 		}
  54983 		v25 = v27
  54984 		goto _65
  54985 	_65:
  54986 		v16 = v25
  54987 		goto _56
  54988 	_56:
  54989 		**(**uint8_t)(__ccgo_up(v4 + 1)) = uint8(v16)
  54990 		v31 = v1 * int32(19077) >> int32(8)
  54991 		goto _71
  54992 	_71:
  54993 		v33 = v2 * int32(33050) >> int32(8)
  54994 		goto _73
  54995 	_73:
  54996 		v35 = v31 + v33 - int32(17685)
  54997 		if v35 & ^int32(YUV_MASK2) == 0 {
  54998 			v38 = v35 >> int32(YUV_FIX2)
  54999 		} else {
  55000 			if v35 < 0 {
  55001 				v39 = 0
  55002 			} else {
  55003 				v39 = int32(255)
  55004 			}
  55005 			v38 = v39
  55006 		}
  55007 		v36 = v38
  55008 		goto _76
  55009 	_76:
  55010 		v29 = v36
  55011 		goto _69
  55012 	_69:
  55013 		**(**uint8_t)(__ccgo_up(v4 + 2)) = uint8(v29)
  55014 	}
  55015 	x = int32(1)
  55016 	for {
  55017 		if !(x <= last_pixel_pair) {
  55018 			break
  55019 		}
  55020 		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 */
  55021 		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*/
  55022 		avg = tl_uv + t_uv + l_uv + uv + uint32(0x00080008)
  55023 		diag_12 = (avg + uint32(2)*(t_uv+l_uv)) >> int32(3)
  55024 		diag_03 = (avg + uint32(2)*(tl_uv+uv)) >> int32(3)
  55025 		uv02 = (diag_12 + tl_uv) >> int32(1)
  55026 		uv1 = (diag_03 + t_uv) >> int32(1)
  55027 		v1 = int32(**(**uint8_t)(__ccgo_up(top_y + uintptr(int32(2)*x-int32(1)))))
  55028 		v2 = int32(uv02 & uint32(0xff))
  55029 		v3 = int32(uv02 >> libc.Int32FromInt32(16))
  55030 		v4 = top_dst + uintptr((int32(2)*x-int32(1))*int32(3))
  55031 		v7 = v1 * int32(19077) >> int32(8)
  55032 		goto _87
  55033 	_87:
  55034 		v9 = v3 * int32(26149) >> int32(8)
  55035 		goto _89
  55036 	_89:
  55037 		v11 = v7 + v9 - int32(14234)
  55038 		if v11 & ^int32(YUV_MASK2) == 0 {
  55039 			v14 = v11 >> int32(YUV_FIX2)
  55040 		} else {
  55041 			if v11 < 0 {
  55042 				v15 = 0
  55043 			} else {
  55044 				v15 = int32(255)
  55045 			}
  55046 			v14 = v15
  55047 		}
  55048 		v12 = v14
  55049 		goto _92
  55050 	_92:
  55051 		v5 = v12
  55052 		goto _85
  55053 	_85:
  55054 		**(**uint8_t)(__ccgo_up(v4)) = uint8(v5)
  55055 		v18 = v1 * int32(19077) >> int32(8)
  55056 		goto _98
  55057 	_98:
  55058 		v20 = v2 * int32(6419) >> int32(8)
  55059 		goto _100
  55060 	_100:
  55061 		v22 = v3 * int32(13320) >> int32(8)
  55062 		goto _102
  55063 	_102:
  55064 		v24 = v18 - v20 - v22 + int32(8708)
  55065 		if v24 & ^int32(YUV_MASK2) == 0 {
  55066 			v27 = v24 >> int32(YUV_FIX2)
  55067 		} else {
  55068 			if v24 < 0 {
  55069 				v28 = 0
  55070 			} else {
  55071 				v28 = int32(255)
  55072 			}
  55073 			v27 = v28
  55074 		}
  55075 		v25 = v27
  55076 		goto _105
  55077 	_105:
  55078 		v16 = v25
  55079 		goto _96
  55080 	_96:
  55081 		**(**uint8_t)(__ccgo_up(v4 + 1)) = uint8(v16)
  55082 		v31 = v1 * int32(19077) >> int32(8)
  55083 		goto _111
  55084 	_111:
  55085 		v33 = v2 * int32(33050) >> int32(8)
  55086 		goto _113
  55087 	_113:
  55088 		v35 = v31 + v33 - int32(17685)
  55089 		if v35 & ^int32(YUV_MASK2) == 0 {
  55090 			v38 = v35 >> int32(YUV_FIX2)
  55091 		} else {
  55092 			if v35 < 0 {
  55093 				v39 = 0
  55094 			} else {
  55095 				v39 = int32(255)
  55096 			}
  55097 			v38 = v39
  55098 		}
  55099 		v36 = v38
  55100 		goto _116
  55101 	_116:
  55102 		v29 = v36
  55103 		goto _109
  55104 	_109:
  55105 		**(**uint8_t)(__ccgo_up(v4 + 2)) = uint8(v29)
  55106 		v1 = int32(**(**uint8_t)(__ccgo_up(top_y + uintptr(int32(2)*x-0))))
  55107 		v2 = int32(uv1 & uint32(0xff))
  55108 		v3 = int32(uv1 >> libc.Int32FromInt32(16))
  55109 		v4 = top_dst + uintptr((int32(2)*x-0)*int32(3))
  55110 		v7 = v1 * int32(19077) >> int32(8)
  55111 		goto _126
  55112 	_126:
  55113 		v9 = v3 * int32(26149) >> int32(8)
  55114 		goto _128
  55115 	_128:
  55116 		v11 = v7 + v9 - int32(14234)
  55117 		if v11 & ^int32(YUV_MASK2) == 0 {
  55118 			v14 = v11 >> int32(YUV_FIX2)
  55119 		} else {
  55120 			if v11 < 0 {
  55121 				v15 = 0
  55122 			} else {
  55123 				v15 = int32(255)
  55124 			}
  55125 			v14 = v15
  55126 		}
  55127 		v12 = v14
  55128 		goto _131
  55129 	_131:
  55130 		v5 = v12
  55131 		goto _124
  55132 	_124:
  55133 		**(**uint8_t)(__ccgo_up(v4)) = uint8(v5)
  55134 		v18 = v1 * int32(19077) >> int32(8)
  55135 		goto _137
  55136 	_137:
  55137 		v20 = v2 * int32(6419) >> int32(8)
  55138 		goto _139
  55139 	_139:
  55140 		v22 = v3 * int32(13320) >> int32(8)
  55141 		goto _141
  55142 	_141:
  55143 		v24 = v18 - v20 - v22 + int32(8708)
  55144 		if v24 & ^int32(YUV_MASK2) == 0 {
  55145 			v27 = v24 >> int32(YUV_FIX2)
  55146 		} else {
  55147 			if v24 < 0 {
  55148 				v28 = 0
  55149 			} else {
  55150 				v28 = int32(255)
  55151 			}
  55152 			v27 = v28
  55153 		}
  55154 		v25 = v27
  55155 		goto _144
  55156 	_144:
  55157 		v16 = v25
  55158 		goto _135
  55159 	_135:
  55160 		**(**uint8_t)(__ccgo_up(v4 + 1)) = uint8(v16)
  55161 		v31 = v1 * int32(19077) >> int32(8)
  55162 		goto _150
  55163 	_150:
  55164 		v33 = v2 * int32(33050) >> int32(8)
  55165 		goto _152
  55166 	_152:
  55167 		v35 = v31 + v33 - int32(17685)
  55168 		if v35 & ^int32(YUV_MASK2) == 0 {
  55169 			v38 = v35 >> int32(YUV_FIX2)
  55170 		} else {
  55171 			if v35 < 0 {
  55172 				v39 = 0
  55173 			} else {
  55174 				v39 = int32(255)
  55175 			}
  55176 			v38 = v39
  55177 		}
  55178 		v36 = v38
  55179 		goto _155
  55180 	_155:
  55181 		v29 = v36
  55182 		goto _148
  55183 	_148:
  55184 		**(**uint8_t)(__ccgo_up(v4 + 2)) = uint8(v29)
  55185 		if bottom_y != libc.UintptrFromInt32(0) {
  55186 			uv03 = (diag_03 + l_uv) >> int32(1)
  55187 			uv11 = (diag_12 + uv) >> int32(1)
  55188 			v1 = int32(**(**uint8_t)(__ccgo_up(bottom_y + uintptr(int32(2)*x-int32(1)))))
  55189 			v2 = int32(uv03 & uint32(0xff))
  55190 			v3 = int32(uv03 >> libc.Int32FromInt32(16))
  55191 			v4 = bottom_dst + uintptr((int32(2)*x-int32(1))*int32(3))
  55192 			v7 = v1 * int32(19077) >> int32(8)
  55193 			goto _165
  55194 		_165:
  55195 			v9 = v3 * int32(26149) >> int32(8)
  55196 			goto _167
  55197 		_167:
  55198 			v11 = v7 + v9 - int32(14234)
  55199 			if v11 & ^int32(YUV_MASK2) == 0 {
  55200 				v14 = v11 >> int32(YUV_FIX2)
  55201 			} else {
  55202 				if v11 < 0 {
  55203 					v15 = 0
  55204 				} else {
  55205 					v15 = int32(255)
  55206 				}
  55207 				v14 = v15
  55208 			}
  55209 			v12 = v14
  55210 			goto _170
  55211 		_170:
  55212 			v5 = v12
  55213 			goto _163
  55214 		_163:
  55215 			**(**uint8_t)(__ccgo_up(v4)) = uint8(v5)
  55216 			v18 = v1 * int32(19077) >> int32(8)
  55217 			goto _176
  55218 		_176:
  55219 			v20 = v2 * int32(6419) >> int32(8)
  55220 			goto _178
  55221 		_178:
  55222 			v22 = v3 * int32(13320) >> int32(8)
  55223 			goto _180
  55224 		_180:
  55225 			v24 = v18 - v20 - v22 + int32(8708)
  55226 			if v24 & ^int32(YUV_MASK2) == 0 {
  55227 				v27 = v24 >> int32(YUV_FIX2)
  55228 			} else {
  55229 				if v24 < 0 {
  55230 					v28 = 0
  55231 				} else {
  55232 					v28 = int32(255)
  55233 				}
  55234 				v27 = v28
  55235 			}
  55236 			v25 = v27
  55237 			goto _183
  55238 		_183:
  55239 			v16 = v25
  55240 			goto _174
  55241 		_174:
  55242 			**(**uint8_t)(__ccgo_up(v4 + 1)) = uint8(v16)
  55243 			v31 = v1 * int32(19077) >> int32(8)
  55244 			goto _189
  55245 		_189:
  55246 			v33 = v2 * int32(33050) >> int32(8)
  55247 			goto _191
  55248 		_191:
  55249 			v35 = v31 + v33 - int32(17685)
  55250 			if v35 & ^int32(YUV_MASK2) == 0 {
  55251 				v38 = v35 >> int32(YUV_FIX2)
  55252 			} else {
  55253 				if v35 < 0 {
  55254 					v39 = 0
  55255 				} else {
  55256 					v39 = int32(255)
  55257 				}
  55258 				v38 = v39
  55259 			}
  55260 			v36 = v38
  55261 			goto _194
  55262 		_194:
  55263 			v29 = v36
  55264 			goto _187
  55265 		_187:
  55266 			**(**uint8_t)(__ccgo_up(v4 + 2)) = uint8(v29)
  55267 			v1 = int32(**(**uint8_t)(__ccgo_up(bottom_y + uintptr(int32(2)*x+0))))
  55268 			v2 = int32(uv11 & uint32(0xff))
  55269 			v3 = int32(uv11 >> libc.Int32FromInt32(16))
  55270 			v4 = bottom_dst + uintptr((int32(2)*x+0)*int32(3))
  55271 			v7 = v1 * int32(19077) >> int32(8)
  55272 			goto _204
  55273 		_204:
  55274 			v9 = v3 * int32(26149) >> int32(8)
  55275 			goto _206
  55276 		_206:
  55277 			v11 = v7 + v9 - int32(14234)
  55278 			if v11 & ^int32(YUV_MASK2) == 0 {
  55279 				v14 = v11 >> int32(YUV_FIX2)
  55280 			} else {
  55281 				if v11 < 0 {
  55282 					v15 = 0
  55283 				} else {
  55284 					v15 = int32(255)
  55285 				}
  55286 				v14 = v15
  55287 			}
  55288 			v12 = v14
  55289 			goto _209
  55290 		_209:
  55291 			v5 = v12
  55292 			goto _202
  55293 		_202:
  55294 			**(**uint8_t)(__ccgo_up(v4)) = uint8(v5)
  55295 			v18 = v1 * int32(19077) >> int32(8)
  55296 			goto _215
  55297 		_215:
  55298 			v20 = v2 * int32(6419) >> int32(8)
  55299 			goto _217
  55300 		_217:
  55301 			v22 = v3 * int32(13320) >> int32(8)
  55302 			goto _219
  55303 		_219:
  55304 			v24 = v18 - v20 - v22 + int32(8708)
  55305 			if v24 & ^int32(YUV_MASK2) == 0 {
  55306 				v27 = v24 >> int32(YUV_FIX2)
  55307 			} else {
  55308 				if v24 < 0 {
  55309 					v28 = 0
  55310 				} else {
  55311 					v28 = int32(255)
  55312 				}
  55313 				v27 = v28
  55314 			}
  55315 			v25 = v27
  55316 			goto _222
  55317 		_222:
  55318 			v16 = v25
  55319 			goto _213
  55320 		_213:
  55321 			**(**uint8_t)(__ccgo_up(v4 + 1)) = uint8(v16)
  55322 			v31 = v1 * int32(19077) >> int32(8)
  55323 			goto _228
  55324 		_228:
  55325 			v33 = v2 * int32(33050) >> int32(8)
  55326 			goto _230
  55327 		_230:
  55328 			v35 = v31 + v33 - int32(17685)
  55329 			if v35 & ^int32(YUV_MASK2) == 0 {
  55330 				v38 = v35 >> int32(YUV_FIX2)
  55331 			} else {
  55332 				if v35 < 0 {
  55333 					v39 = 0
  55334 				} else {
  55335 					v39 = int32(255)
  55336 				}
  55337 				v38 = v39
  55338 			}
  55339 			v36 = v38
  55340 			goto _233
  55341 		_233:
  55342 			v29 = v36
  55343 			goto _226
  55344 		_226:
  55345 			**(**uint8_t)(__ccgo_up(v4 + 2)) = uint8(v29)
  55346 		}
  55347 		tl_uv = t_uv
  55348 		l_uv = uv
  55349 		goto _79
  55350 	_79:
  55351 		;
  55352 		x = x + 1
  55353 	}
  55354 	if !(len1&libc.Int32FromInt32(1) != 0) {
  55355 		uv04 = (uint32(3)*tl_uv + l_uv + uint32(0x00020002)) >> int32(2)
  55356 		v1 = int32(**(**uint8_t)(__ccgo_up(top_y + uintptr(len1-int32(1)))))
  55357 		v2 = int32(uv04 & uint32(0xff))
  55358 		v3 = int32(uv04 >> libc.Int32FromInt32(16))
  55359 		v4 = top_dst + uintptr((len1-int32(1))*int32(3))
  55360 		v7 = v1 * int32(19077) >> int32(8)
  55361 		goto _243
  55362 	_243:
  55363 		v9 = v3 * int32(26149) >> int32(8)
  55364 		goto _245
  55365 	_245:
  55366 		v11 = v7 + v9 - int32(14234)
  55367 		if v11 & ^int32(YUV_MASK2) == 0 {
  55368 			v14 = v11 >> int32(YUV_FIX2)
  55369 		} else {
  55370 			if v11 < 0 {
  55371 				v15 = 0
  55372 			} else {
  55373 				v15 = int32(255)
  55374 			}
  55375 			v14 = v15
  55376 		}
  55377 		v12 = v14
  55378 		goto _248
  55379 	_248:
  55380 		v5 = v12
  55381 		goto _241
  55382 	_241:
  55383 		**(**uint8_t)(__ccgo_up(v4)) = uint8(v5)
  55384 		v18 = v1 * int32(19077) >> int32(8)
  55385 		goto _254
  55386 	_254:
  55387 		v20 = v2 * int32(6419) >> int32(8)
  55388 		goto _256
  55389 	_256:
  55390 		v22 = v3 * int32(13320) >> int32(8)
  55391 		goto _258
  55392 	_258:
  55393 		v24 = v18 - v20 - v22 + int32(8708)
  55394 		if v24 & ^int32(YUV_MASK2) == 0 {
  55395 			v27 = v24 >> int32(YUV_FIX2)
  55396 		} else {
  55397 			if v24 < 0 {
  55398 				v28 = 0
  55399 			} else {
  55400 				v28 = int32(255)
  55401 			}
  55402 			v27 = v28
  55403 		}
  55404 		v25 = v27
  55405 		goto _261
  55406 	_261:
  55407 		v16 = v25
  55408 		goto _252
  55409 	_252:
  55410 		**(**uint8_t)(__ccgo_up(v4 + 1)) = uint8(v16)
  55411 		v31 = v1 * int32(19077) >> int32(8)
  55412 		goto _267
  55413 	_267:
  55414 		v33 = v2 * int32(33050) >> int32(8)
  55415 		goto _269
  55416 	_269:
  55417 		v35 = v31 + v33 - int32(17685)
  55418 		if v35 & ^int32(YUV_MASK2) == 0 {
  55419 			v38 = v35 >> int32(YUV_FIX2)
  55420 		} else {
  55421 			if v35 < 0 {
  55422 				v39 = 0
  55423 			} else {
  55424 				v39 = int32(255)
  55425 			}
  55426 			v38 = v39
  55427 		}
  55428 		v36 = v38
  55429 		goto _272
  55430 	_272:
  55431 		v29 = v36
  55432 		goto _265
  55433 	_265:
  55434 		**(**uint8_t)(__ccgo_up(v4 + 2)) = uint8(v29)
  55435 		if bottom_y != libc.UintptrFromInt32(0) {
  55436 			uv05 = (uint32(3)*l_uv + tl_uv + uint32(0x00020002)) >> int32(2)
  55437 			v1 = int32(**(**uint8_t)(__ccgo_up(bottom_y + uintptr(len1-int32(1)))))
  55438 			v2 = int32(uv05 & uint32(0xff))
  55439 			v3 = int32(uv05 >> libc.Int32FromInt32(16))
  55440 			v4 = bottom_dst + uintptr((len1-int32(1))*int32(3))
  55441 			v7 = v1 * int32(19077) >> int32(8)
  55442 			goto _282
  55443 		_282:
  55444 			v9 = v3 * int32(26149) >> int32(8)
  55445 			goto _284
  55446 		_284:
  55447 			v11 = v7 + v9 - int32(14234)
  55448 			if v11 & ^int32(YUV_MASK2) == 0 {
  55449 				v14 = v11 >> int32(YUV_FIX2)
  55450 			} else {
  55451 				if v11 < 0 {
  55452 					v15 = 0
  55453 				} else {
  55454 					v15 = int32(255)
  55455 				}
  55456 				v14 = v15
  55457 			}
  55458 			v12 = v14
  55459 			goto _287
  55460 		_287:
  55461 			v5 = v12
  55462 			goto _280
  55463 		_280:
  55464 			**(**uint8_t)(__ccgo_up(v4)) = uint8(v5)
  55465 			v18 = v1 * int32(19077) >> int32(8)
  55466 			goto _293
  55467 		_293:
  55468 			v20 = v2 * int32(6419) >> int32(8)
  55469 			goto _295
  55470 		_295:
  55471 			v22 = v3 * int32(13320) >> int32(8)
  55472 			goto _297
  55473 		_297:
  55474 			v24 = v18 - v20 - v22 + int32(8708)
  55475 			if v24 & ^int32(YUV_MASK2) == 0 {
  55476 				v27 = v24 >> int32(YUV_FIX2)
  55477 			} else {
  55478 				if v24 < 0 {
  55479 					v28 = 0
  55480 				} else {
  55481 					v28 = int32(255)
  55482 				}
  55483 				v27 = v28
  55484 			}
  55485 			v25 = v27
  55486 			goto _300
  55487 		_300:
  55488 			v16 = v25
  55489 			goto _291
  55490 		_291:
  55491 			**(**uint8_t)(__ccgo_up(v4 + 1)) = uint8(v16)
  55492 			v31 = v1 * int32(19077) >> int32(8)
  55493 			goto _306
  55494 		_306:
  55495 			v33 = v2 * int32(33050) >> int32(8)
  55496 			goto _308
  55497 		_308:
  55498 			v35 = v31 + v33 - int32(17685)
  55499 			if v35 & ^int32(YUV_MASK2) == 0 {
  55500 				v38 = v35 >> int32(YUV_FIX2)
  55501 			} else {
  55502 				if v35 < 0 {
  55503 					v39 = 0
  55504 				} else {
  55505 					v39 = int32(255)
  55506 				}
  55507 				v38 = v39
  55508 			}
  55509 			v36 = v38
  55510 			goto _311
  55511 		_311:
  55512 			v29 = v36
  55513 			goto _304
  55514 		_304:
  55515 			**(**uint8_t)(__ccgo_up(v4 + 2)) = uint8(v29)
  55516 		}
  55517 	}
  55518 }
  55519 
  55520 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) {
  55521 	var avg, diag_03, diag_12, l_uv, t_uv, tl_uv, uv, uv0, uv01, uv02, uv03, uv04, uv05, uv1, uv11 uint32_t
  55522 	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
  55523 	var v4 uintptr
  55524 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  55525 	last_pixel_pair = (len1 - int32(1)) >> int32(1)
  55526 	tl_uv = uint32(int32(**(**uint8_t)(__ccgo_up(top_u))) | int32(**(**uint8_t)(__ccgo_up(top_v)))<<libc.Int32FromInt32(16)) /* top-left sample */
  55527 	l_uv = uint32(int32(**(**uint8_t)(__ccgo_up(cur_u))) | int32(**(**uint8_t)(__ccgo_up(cur_v)))<<libc.Int32FromInt32(16))
  55528 	uv0 = (uint32(3)*tl_uv + l_uv + uint32(0x00020002)) >> int32(2)
  55529 	v1 = int32(**(**uint8_t)(__ccgo_up(top_y)))
  55530 	v2 = int32(uv0 & uint32(0xff))
  55531 	v3 = int32(uv0 >> libc.Int32FromInt32(16))
  55532 	v4 = top_dst
  55533 	v7 = v1 * int32(19077) >> int32(8)
  55534 	goto _8
  55535 _8:
  55536 	v9 = v2 * int32(33050) >> int32(8)
  55537 	goto _10
  55538 _10:
  55539 	v11 = v7 + v9 - int32(17685)
  55540 	if v11 & ^int32(YUV_MASK2) == 0 {
  55541 		v14 = v11 >> int32(YUV_FIX2)
  55542 	} else {
  55543 		if v11 < 0 {
  55544 			v15 = 0
  55545 		} else {
  55546 			v15 = int32(255)
  55547 		}
  55548 		v14 = v15
  55549 	}
  55550 	v12 = v14
  55551 	goto _13
  55552 _13:
  55553 	v5 = v12
  55554 	goto _6
  55555 _6:
  55556 	**(**uint8_t)(__ccgo_up(v4)) = uint8(v5)
  55557 	v18 = v1 * int32(19077) >> int32(8)
  55558 	goto _19
  55559 _19:
  55560 	v20 = v2 * int32(6419) >> int32(8)
  55561 	goto _21
  55562 _21:
  55563 	v22 = v3 * int32(13320) >> int32(8)
  55564 	goto _23
  55565 _23:
  55566 	v24 = v18 - v20 - v22 + int32(8708)
  55567 	if v24 & ^int32(YUV_MASK2) == 0 {
  55568 		v27 = v24 >> int32(YUV_FIX2)
  55569 	} else {
  55570 		if v24 < 0 {
  55571 			v28 = 0
  55572 		} else {
  55573 			v28 = int32(255)
  55574 		}
  55575 		v27 = v28
  55576 	}
  55577 	v25 = v27
  55578 	goto _26
  55579 _26:
  55580 	v16 = v25
  55581 	goto _17
  55582 _17:
  55583 	**(**uint8_t)(__ccgo_up(v4 + 1)) = uint8(v16)
  55584 	v31 = v1 * int32(19077) >> int32(8)
  55585 	goto _32
  55586 _32:
  55587 	v33 = v3 * int32(26149) >> int32(8)
  55588 	goto _34
  55589 _34:
  55590 	v35 = v31 + v33 - int32(14234)
  55591 	if v35 & ^int32(YUV_MASK2) == 0 {
  55592 		v38 = v35 >> int32(YUV_FIX2)
  55593 	} else {
  55594 		if v35 < 0 {
  55595 			v39 = 0
  55596 		} else {
  55597 			v39 = int32(255)
  55598 		}
  55599 		v38 = v39
  55600 	}
  55601 	v36 = v38
  55602 	goto _37
  55603 _37:
  55604 	v29 = v36
  55605 	goto _30
  55606 _30:
  55607 	**(**uint8_t)(__ccgo_up(v4 + 2)) = uint8(v29)
  55608 	if bottom_y != libc.UintptrFromInt32(0) {
  55609 		uv01 = (uint32(3)*l_uv + tl_uv + uint32(0x00020002)) >> int32(2)
  55610 		v1 = int32(**(**uint8_t)(__ccgo_up(bottom_y)))
  55611 		v2 = int32(uv01 & uint32(0xff))
  55612 		v3 = int32(uv01 >> libc.Int32FromInt32(16))
  55613 		v4 = bottom_dst
  55614 		v7 = v1 * int32(19077) >> int32(8)
  55615 		goto _47
  55616 	_47:
  55617 		v9 = v2 * int32(33050) >> int32(8)
  55618 		goto _49
  55619 	_49:
  55620 		v11 = v7 + v9 - int32(17685)
  55621 		if v11 & ^int32(YUV_MASK2) == 0 {
  55622 			v14 = v11 >> int32(YUV_FIX2)
  55623 		} else {
  55624 			if v11 < 0 {
  55625 				v15 = 0
  55626 			} else {
  55627 				v15 = int32(255)
  55628 			}
  55629 			v14 = v15
  55630 		}
  55631 		v12 = v14
  55632 		goto _52
  55633 	_52:
  55634 		v5 = v12
  55635 		goto _45
  55636 	_45:
  55637 		**(**uint8_t)(__ccgo_up(v4)) = uint8(v5)
  55638 		v18 = v1 * int32(19077) >> int32(8)
  55639 		goto _58
  55640 	_58:
  55641 		v20 = v2 * int32(6419) >> int32(8)
  55642 		goto _60
  55643 	_60:
  55644 		v22 = v3 * int32(13320) >> int32(8)
  55645 		goto _62
  55646 	_62:
  55647 		v24 = v18 - v20 - v22 + int32(8708)
  55648 		if v24 & ^int32(YUV_MASK2) == 0 {
  55649 			v27 = v24 >> int32(YUV_FIX2)
  55650 		} else {
  55651 			if v24 < 0 {
  55652 				v28 = 0
  55653 			} else {
  55654 				v28 = int32(255)
  55655 			}
  55656 			v27 = v28
  55657 		}
  55658 		v25 = v27
  55659 		goto _65
  55660 	_65:
  55661 		v16 = v25
  55662 		goto _56
  55663 	_56:
  55664 		**(**uint8_t)(__ccgo_up(v4 + 1)) = uint8(v16)
  55665 		v31 = v1 * int32(19077) >> int32(8)
  55666 		goto _71
  55667 	_71:
  55668 		v33 = v3 * int32(26149) >> int32(8)
  55669 		goto _73
  55670 	_73:
  55671 		v35 = v31 + v33 - int32(14234)
  55672 		if v35 & ^int32(YUV_MASK2) == 0 {
  55673 			v38 = v35 >> int32(YUV_FIX2)
  55674 		} else {
  55675 			if v35 < 0 {
  55676 				v39 = 0
  55677 			} else {
  55678 				v39 = int32(255)
  55679 			}
  55680 			v38 = v39
  55681 		}
  55682 		v36 = v38
  55683 		goto _76
  55684 	_76:
  55685 		v29 = v36
  55686 		goto _69
  55687 	_69:
  55688 		**(**uint8_t)(__ccgo_up(v4 + 2)) = uint8(v29)
  55689 	}
  55690 	x = int32(1)
  55691 	for {
  55692 		if !(x <= last_pixel_pair) {
  55693 			break
  55694 		}
  55695 		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 */
  55696 		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*/
  55697 		avg = tl_uv + t_uv + l_uv + uv + uint32(0x00080008)
  55698 		diag_12 = (avg + uint32(2)*(t_uv+l_uv)) >> int32(3)
  55699 		diag_03 = (avg + uint32(2)*(tl_uv+uv)) >> int32(3)
  55700 		uv02 = (diag_12 + tl_uv) >> int32(1)
  55701 		uv1 = (diag_03 + t_uv) >> int32(1)
  55702 		v1 = int32(**(**uint8_t)(__ccgo_up(top_y + uintptr(int32(2)*x-int32(1)))))
  55703 		v2 = int32(uv02 & uint32(0xff))
  55704 		v3 = int32(uv02 >> libc.Int32FromInt32(16))
  55705 		v4 = top_dst + uintptr((int32(2)*x-int32(1))*int32(3))
  55706 		v7 = v1 * int32(19077) >> int32(8)
  55707 		goto _87
  55708 	_87:
  55709 		v9 = v2 * int32(33050) >> int32(8)
  55710 		goto _89
  55711 	_89:
  55712 		v11 = v7 + v9 - int32(17685)
  55713 		if v11 & ^int32(YUV_MASK2) == 0 {
  55714 			v14 = v11 >> int32(YUV_FIX2)
  55715 		} else {
  55716 			if v11 < 0 {
  55717 				v15 = 0
  55718 			} else {
  55719 				v15 = int32(255)
  55720 			}
  55721 			v14 = v15
  55722 		}
  55723 		v12 = v14
  55724 		goto _92
  55725 	_92:
  55726 		v5 = v12
  55727 		goto _85
  55728 	_85:
  55729 		**(**uint8_t)(__ccgo_up(v4)) = uint8(v5)
  55730 		v18 = v1 * int32(19077) >> int32(8)
  55731 		goto _98
  55732 	_98:
  55733 		v20 = v2 * int32(6419) >> int32(8)
  55734 		goto _100
  55735 	_100:
  55736 		v22 = v3 * int32(13320) >> int32(8)
  55737 		goto _102
  55738 	_102:
  55739 		v24 = v18 - v20 - v22 + int32(8708)
  55740 		if v24 & ^int32(YUV_MASK2) == 0 {
  55741 			v27 = v24 >> int32(YUV_FIX2)
  55742 		} else {
  55743 			if v24 < 0 {
  55744 				v28 = 0
  55745 			} else {
  55746 				v28 = int32(255)
  55747 			}
  55748 			v27 = v28
  55749 		}
  55750 		v25 = v27
  55751 		goto _105
  55752 	_105:
  55753 		v16 = v25
  55754 		goto _96
  55755 	_96:
  55756 		**(**uint8_t)(__ccgo_up(v4 + 1)) = uint8(v16)
  55757 		v31 = v1 * int32(19077) >> int32(8)
  55758 		goto _111
  55759 	_111:
  55760 		v33 = v3 * int32(26149) >> int32(8)
  55761 		goto _113
  55762 	_113:
  55763 		v35 = v31 + v33 - int32(14234)
  55764 		if v35 & ^int32(YUV_MASK2) == 0 {
  55765 			v38 = v35 >> int32(YUV_FIX2)
  55766 		} else {
  55767 			if v35 < 0 {
  55768 				v39 = 0
  55769 			} else {
  55770 				v39 = int32(255)
  55771 			}
  55772 			v38 = v39
  55773 		}
  55774 		v36 = v38
  55775 		goto _116
  55776 	_116:
  55777 		v29 = v36
  55778 		goto _109
  55779 	_109:
  55780 		**(**uint8_t)(__ccgo_up(v4 + 2)) = uint8(v29)
  55781 		v1 = int32(**(**uint8_t)(__ccgo_up(top_y + uintptr(int32(2)*x-0))))
  55782 		v2 = int32(uv1 & uint32(0xff))
  55783 		v3 = int32(uv1 >> libc.Int32FromInt32(16))
  55784 		v4 = top_dst + uintptr((int32(2)*x-0)*int32(3))
  55785 		v7 = v1 * int32(19077) >> int32(8)
  55786 		goto _126
  55787 	_126:
  55788 		v9 = v2 * int32(33050) >> int32(8)
  55789 		goto _128
  55790 	_128:
  55791 		v11 = v7 + v9 - int32(17685)
  55792 		if v11 & ^int32(YUV_MASK2) == 0 {
  55793 			v14 = v11 >> int32(YUV_FIX2)
  55794 		} else {
  55795 			if v11 < 0 {
  55796 				v15 = 0
  55797 			} else {
  55798 				v15 = int32(255)
  55799 			}
  55800 			v14 = v15
  55801 		}
  55802 		v12 = v14
  55803 		goto _131
  55804 	_131:
  55805 		v5 = v12
  55806 		goto _124
  55807 	_124:
  55808 		**(**uint8_t)(__ccgo_up(v4)) = uint8(v5)
  55809 		v18 = v1 * int32(19077) >> int32(8)
  55810 		goto _137
  55811 	_137:
  55812 		v20 = v2 * int32(6419) >> int32(8)
  55813 		goto _139
  55814 	_139:
  55815 		v22 = v3 * int32(13320) >> int32(8)
  55816 		goto _141
  55817 	_141:
  55818 		v24 = v18 - v20 - v22 + int32(8708)
  55819 		if v24 & ^int32(YUV_MASK2) == 0 {
  55820 			v27 = v24 >> int32(YUV_FIX2)
  55821 		} else {
  55822 			if v24 < 0 {
  55823 				v28 = 0
  55824 			} else {
  55825 				v28 = int32(255)
  55826 			}
  55827 			v27 = v28
  55828 		}
  55829 		v25 = v27
  55830 		goto _144
  55831 	_144:
  55832 		v16 = v25
  55833 		goto _135
  55834 	_135:
  55835 		**(**uint8_t)(__ccgo_up(v4 + 1)) = uint8(v16)
  55836 		v31 = v1 * int32(19077) >> int32(8)
  55837 		goto _150
  55838 	_150:
  55839 		v33 = v3 * int32(26149) >> int32(8)
  55840 		goto _152
  55841 	_152:
  55842 		v35 = v31 + v33 - int32(14234)
  55843 		if v35 & ^int32(YUV_MASK2) == 0 {
  55844 			v38 = v35 >> int32(YUV_FIX2)
  55845 		} else {
  55846 			if v35 < 0 {
  55847 				v39 = 0
  55848 			} else {
  55849 				v39 = int32(255)
  55850 			}
  55851 			v38 = v39
  55852 		}
  55853 		v36 = v38
  55854 		goto _155
  55855 	_155:
  55856 		v29 = v36
  55857 		goto _148
  55858 	_148:
  55859 		**(**uint8_t)(__ccgo_up(v4 + 2)) = uint8(v29)
  55860 		if bottom_y != libc.UintptrFromInt32(0) {
  55861 			uv03 = (diag_03 + l_uv) >> int32(1)
  55862 			uv11 = (diag_12 + uv) >> int32(1)
  55863 			v1 = int32(**(**uint8_t)(__ccgo_up(bottom_y + uintptr(int32(2)*x-int32(1)))))
  55864 			v2 = int32(uv03 & uint32(0xff))
  55865 			v3 = int32(uv03 >> libc.Int32FromInt32(16))
  55866 			v4 = bottom_dst + uintptr((int32(2)*x-int32(1))*int32(3))
  55867 			v7 = v1 * int32(19077) >> int32(8)
  55868 			goto _165
  55869 		_165:
  55870 			v9 = v2 * int32(33050) >> int32(8)
  55871 			goto _167
  55872 		_167:
  55873 			v11 = v7 + v9 - int32(17685)
  55874 			if v11 & ^int32(YUV_MASK2) == 0 {
  55875 				v14 = v11 >> int32(YUV_FIX2)
  55876 			} else {
  55877 				if v11 < 0 {
  55878 					v15 = 0
  55879 				} else {
  55880 					v15 = int32(255)
  55881 				}
  55882 				v14 = v15
  55883 			}
  55884 			v12 = v14
  55885 			goto _170
  55886 		_170:
  55887 			v5 = v12
  55888 			goto _163
  55889 		_163:
  55890 			**(**uint8_t)(__ccgo_up(v4)) = uint8(v5)
  55891 			v18 = v1 * int32(19077) >> int32(8)
  55892 			goto _176
  55893 		_176:
  55894 			v20 = v2 * int32(6419) >> int32(8)
  55895 			goto _178
  55896 		_178:
  55897 			v22 = v3 * int32(13320) >> int32(8)
  55898 			goto _180
  55899 		_180:
  55900 			v24 = v18 - v20 - v22 + int32(8708)
  55901 			if v24 & ^int32(YUV_MASK2) == 0 {
  55902 				v27 = v24 >> int32(YUV_FIX2)
  55903 			} else {
  55904 				if v24 < 0 {
  55905 					v28 = 0
  55906 				} else {
  55907 					v28 = int32(255)
  55908 				}
  55909 				v27 = v28
  55910 			}
  55911 			v25 = v27
  55912 			goto _183
  55913 		_183:
  55914 			v16 = v25
  55915 			goto _174
  55916 		_174:
  55917 			**(**uint8_t)(__ccgo_up(v4 + 1)) = uint8(v16)
  55918 			v31 = v1 * int32(19077) >> int32(8)
  55919 			goto _189
  55920 		_189:
  55921 			v33 = v3 * int32(26149) >> int32(8)
  55922 			goto _191
  55923 		_191:
  55924 			v35 = v31 + v33 - int32(14234)
  55925 			if v35 & ^int32(YUV_MASK2) == 0 {
  55926 				v38 = v35 >> int32(YUV_FIX2)
  55927 			} else {
  55928 				if v35 < 0 {
  55929 					v39 = 0
  55930 				} else {
  55931 					v39 = int32(255)
  55932 				}
  55933 				v38 = v39
  55934 			}
  55935 			v36 = v38
  55936 			goto _194
  55937 		_194:
  55938 			v29 = v36
  55939 			goto _187
  55940 		_187:
  55941 			**(**uint8_t)(__ccgo_up(v4 + 2)) = uint8(v29)
  55942 			v1 = int32(**(**uint8_t)(__ccgo_up(bottom_y + uintptr(int32(2)*x+0))))
  55943 			v2 = int32(uv11 & uint32(0xff))
  55944 			v3 = int32(uv11 >> libc.Int32FromInt32(16))
  55945 			v4 = bottom_dst + uintptr((int32(2)*x+0)*int32(3))
  55946 			v7 = v1 * int32(19077) >> int32(8)
  55947 			goto _204
  55948 		_204:
  55949 			v9 = v2 * int32(33050) >> int32(8)
  55950 			goto _206
  55951 		_206:
  55952 			v11 = v7 + v9 - int32(17685)
  55953 			if v11 & ^int32(YUV_MASK2) == 0 {
  55954 				v14 = v11 >> int32(YUV_FIX2)
  55955 			} else {
  55956 				if v11 < 0 {
  55957 					v15 = 0
  55958 				} else {
  55959 					v15 = int32(255)
  55960 				}
  55961 				v14 = v15
  55962 			}
  55963 			v12 = v14
  55964 			goto _209
  55965 		_209:
  55966 			v5 = v12
  55967 			goto _202
  55968 		_202:
  55969 			**(**uint8_t)(__ccgo_up(v4)) = uint8(v5)
  55970 			v18 = v1 * int32(19077) >> int32(8)
  55971 			goto _215
  55972 		_215:
  55973 			v20 = v2 * int32(6419) >> int32(8)
  55974 			goto _217
  55975 		_217:
  55976 			v22 = v3 * int32(13320) >> int32(8)
  55977 			goto _219
  55978 		_219:
  55979 			v24 = v18 - v20 - v22 + int32(8708)
  55980 			if v24 & ^int32(YUV_MASK2) == 0 {
  55981 				v27 = v24 >> int32(YUV_FIX2)
  55982 			} else {
  55983 				if v24 < 0 {
  55984 					v28 = 0
  55985 				} else {
  55986 					v28 = int32(255)
  55987 				}
  55988 				v27 = v28
  55989 			}
  55990 			v25 = v27
  55991 			goto _222
  55992 		_222:
  55993 			v16 = v25
  55994 			goto _213
  55995 		_213:
  55996 			**(**uint8_t)(__ccgo_up(v4 + 1)) = uint8(v16)
  55997 			v31 = v1 * int32(19077) >> int32(8)
  55998 			goto _228
  55999 		_228:
  56000 			v33 = v3 * int32(26149) >> int32(8)
  56001 			goto _230
  56002 		_230:
  56003 			v35 = v31 + v33 - int32(14234)
  56004 			if v35 & ^int32(YUV_MASK2) == 0 {
  56005 				v38 = v35 >> int32(YUV_FIX2)
  56006 			} else {
  56007 				if v35 < 0 {
  56008 					v39 = 0
  56009 				} else {
  56010 					v39 = int32(255)
  56011 				}
  56012 				v38 = v39
  56013 			}
  56014 			v36 = v38
  56015 			goto _233
  56016 		_233:
  56017 			v29 = v36
  56018 			goto _226
  56019 		_226:
  56020 			**(**uint8_t)(__ccgo_up(v4 + 2)) = uint8(v29)
  56021 		}
  56022 		tl_uv = t_uv
  56023 		l_uv = uv
  56024 		goto _79
  56025 	_79:
  56026 		;
  56027 		x = x + 1
  56028 	}
  56029 	if !(len1&libc.Int32FromInt32(1) != 0) {
  56030 		uv04 = (uint32(3)*tl_uv + l_uv + uint32(0x00020002)) >> int32(2)
  56031 		v1 = int32(**(**uint8_t)(__ccgo_up(top_y + uintptr(len1-int32(1)))))
  56032 		v2 = int32(uv04 & uint32(0xff))
  56033 		v3 = int32(uv04 >> libc.Int32FromInt32(16))
  56034 		v4 = top_dst + uintptr((len1-int32(1))*int32(3))
  56035 		v7 = v1 * int32(19077) >> int32(8)
  56036 		goto _243
  56037 	_243:
  56038 		v9 = v2 * int32(33050) >> int32(8)
  56039 		goto _245
  56040 	_245:
  56041 		v11 = v7 + v9 - int32(17685)
  56042 		if v11 & ^int32(YUV_MASK2) == 0 {
  56043 			v14 = v11 >> int32(YUV_FIX2)
  56044 		} else {
  56045 			if v11 < 0 {
  56046 				v15 = 0
  56047 			} else {
  56048 				v15 = int32(255)
  56049 			}
  56050 			v14 = v15
  56051 		}
  56052 		v12 = v14
  56053 		goto _248
  56054 	_248:
  56055 		v5 = v12
  56056 		goto _241
  56057 	_241:
  56058 		**(**uint8_t)(__ccgo_up(v4)) = uint8(v5)
  56059 		v18 = v1 * int32(19077) >> int32(8)
  56060 		goto _254
  56061 	_254:
  56062 		v20 = v2 * int32(6419) >> int32(8)
  56063 		goto _256
  56064 	_256:
  56065 		v22 = v3 * int32(13320) >> int32(8)
  56066 		goto _258
  56067 	_258:
  56068 		v24 = v18 - v20 - v22 + int32(8708)
  56069 		if v24 & ^int32(YUV_MASK2) == 0 {
  56070 			v27 = v24 >> int32(YUV_FIX2)
  56071 		} else {
  56072 			if v24 < 0 {
  56073 				v28 = 0
  56074 			} else {
  56075 				v28 = int32(255)
  56076 			}
  56077 			v27 = v28
  56078 		}
  56079 		v25 = v27
  56080 		goto _261
  56081 	_261:
  56082 		v16 = v25
  56083 		goto _252
  56084 	_252:
  56085 		**(**uint8_t)(__ccgo_up(v4 + 1)) = uint8(v16)
  56086 		v31 = v1 * int32(19077) >> int32(8)
  56087 		goto _267
  56088 	_267:
  56089 		v33 = v3 * int32(26149) >> int32(8)
  56090 		goto _269
  56091 	_269:
  56092 		v35 = v31 + v33 - int32(14234)
  56093 		if v35 & ^int32(YUV_MASK2) == 0 {
  56094 			v38 = v35 >> int32(YUV_FIX2)
  56095 		} else {
  56096 			if v35 < 0 {
  56097 				v39 = 0
  56098 			} else {
  56099 				v39 = int32(255)
  56100 			}
  56101 			v38 = v39
  56102 		}
  56103 		v36 = v38
  56104 		goto _272
  56105 	_272:
  56106 		v29 = v36
  56107 		goto _265
  56108 	_265:
  56109 		**(**uint8_t)(__ccgo_up(v4 + 2)) = uint8(v29)
  56110 		if bottom_y != libc.UintptrFromInt32(0) {
  56111 			uv05 = (uint32(3)*l_uv + tl_uv + uint32(0x00020002)) >> int32(2)
  56112 			v1 = int32(**(**uint8_t)(__ccgo_up(bottom_y + uintptr(len1-int32(1)))))
  56113 			v2 = int32(uv05 & uint32(0xff))
  56114 			v3 = int32(uv05 >> libc.Int32FromInt32(16))
  56115 			v4 = bottom_dst + uintptr((len1-int32(1))*int32(3))
  56116 			v7 = v1 * int32(19077) >> int32(8)
  56117 			goto _282
  56118 		_282:
  56119 			v9 = v2 * int32(33050) >> int32(8)
  56120 			goto _284
  56121 		_284:
  56122 			v11 = v7 + v9 - int32(17685)
  56123 			if v11 & ^int32(YUV_MASK2) == 0 {
  56124 				v14 = v11 >> int32(YUV_FIX2)
  56125 			} else {
  56126 				if v11 < 0 {
  56127 					v15 = 0
  56128 				} else {
  56129 					v15 = int32(255)
  56130 				}
  56131 				v14 = v15
  56132 			}
  56133 			v12 = v14
  56134 			goto _287
  56135 		_287:
  56136 			v5 = v12
  56137 			goto _280
  56138 		_280:
  56139 			**(**uint8_t)(__ccgo_up(v4)) = uint8(v5)
  56140 			v18 = v1 * int32(19077) >> int32(8)
  56141 			goto _293
  56142 		_293:
  56143 			v20 = v2 * int32(6419) >> int32(8)
  56144 			goto _295
  56145 		_295:
  56146 			v22 = v3 * int32(13320) >> int32(8)
  56147 			goto _297
  56148 		_297:
  56149 			v24 = v18 - v20 - v22 + int32(8708)
  56150 			if v24 & ^int32(YUV_MASK2) == 0 {
  56151 				v27 = v24 >> int32(YUV_FIX2)
  56152 			} else {
  56153 				if v24 < 0 {
  56154 					v28 = 0
  56155 				} else {
  56156 					v28 = int32(255)
  56157 				}
  56158 				v27 = v28
  56159 			}
  56160 			v25 = v27
  56161 			goto _300
  56162 		_300:
  56163 			v16 = v25
  56164 			goto _291
  56165 		_291:
  56166 			**(**uint8_t)(__ccgo_up(v4 + 1)) = uint8(v16)
  56167 			v31 = v1 * int32(19077) >> int32(8)
  56168 			goto _306
  56169 		_306:
  56170 			v33 = v3 * int32(26149) >> int32(8)
  56171 			goto _308
  56172 		_308:
  56173 			v35 = v31 + v33 - int32(14234)
  56174 			if v35 & ^int32(YUV_MASK2) == 0 {
  56175 				v38 = v35 >> int32(YUV_FIX2)
  56176 			} else {
  56177 				if v35 < 0 {
  56178 					v39 = 0
  56179 				} else {
  56180 					v39 = int32(255)
  56181 				}
  56182 				v38 = v39
  56183 			}
  56184 			v36 = v38
  56185 			goto _311
  56186 		_311:
  56187 			v29 = v36
  56188 			goto _304
  56189 		_304:
  56190 			**(**uint8_t)(__ccgo_up(v4 + 2)) = uint8(v29)
  56191 		}
  56192 	}
  56193 }
  56194 
  56195 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) {
  56196 	var avg, diag_03, diag_12, l_uv, t_uv, tl_uv, uv, uv0, uv01, uv02, uv03, uv04, uv05, uv1, uv11 uint32_t
  56197 	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
  56198 	var v4 uintptr
  56199 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  56200 	last_pixel_pair = (len1 - int32(1)) >> int32(1)
  56201 	tl_uv = uint32(int32(**(**uint8_t)(__ccgo_up(top_u))) | int32(**(**uint8_t)(__ccgo_up(top_v)))<<libc.Int32FromInt32(16)) /* top-left sample */
  56202 	l_uv = uint32(int32(**(**uint8_t)(__ccgo_up(cur_u))) | int32(**(**uint8_t)(__ccgo_up(cur_v)))<<libc.Int32FromInt32(16))
  56203 	uv0 = (uint32(3)*tl_uv + l_uv + uint32(0x00020002)) >> int32(2)
  56204 	v1 = int32(**(**uint8_t)(__ccgo_up(top_y)))
  56205 	v2 = int32(uv0 & uint32(0xff))
  56206 	v3 = int32(uv0 >> libc.Int32FromInt32(16))
  56207 	v4 = top_dst
  56208 	v7 = v1 * int32(19077) >> int32(8)
  56209 	goto _8
  56210 _8:
  56211 	v9 = v3 * int32(26149) >> int32(8)
  56212 	goto _10
  56213 _10:
  56214 	v11 = v7 + v9 - int32(14234)
  56215 	if v11 & ^int32(YUV_MASK2) == 0 {
  56216 		v14 = v11 >> int32(YUV_FIX2)
  56217 	} else {
  56218 		if v11 < 0 {
  56219 			v15 = 0
  56220 		} else {
  56221 			v15 = int32(255)
  56222 		}
  56223 		v14 = v15
  56224 	}
  56225 	v12 = v14
  56226 	goto _13
  56227 _13:
  56228 	v5 = v12
  56229 	goto _6
  56230 _6:
  56231 	r = v5
  56232 	v18 = v1 * int32(19077) >> int32(8)
  56233 	goto _19
  56234 _19:
  56235 	v20 = v2 * int32(6419) >> int32(8)
  56236 	goto _21
  56237 _21:
  56238 	v22 = v3 * int32(13320) >> int32(8)
  56239 	goto _23
  56240 _23:
  56241 	v24 = v18 - v20 - v22 + int32(8708)
  56242 	if v24 & ^int32(YUV_MASK2) == 0 {
  56243 		v27 = v24 >> int32(YUV_FIX2)
  56244 	} else {
  56245 		if v24 < 0 {
  56246 			v28 = 0
  56247 		} else {
  56248 			v28 = int32(255)
  56249 		}
  56250 		v27 = v28
  56251 	}
  56252 	v25 = v27
  56253 	goto _26
  56254 _26:
  56255 	v16 = v25
  56256 	goto _17
  56257 _17:
  56258 	g = v16
  56259 	v31 = v1 * int32(19077) >> int32(8)
  56260 	goto _32
  56261 _32:
  56262 	v33 = v2 * int32(33050) >> int32(8)
  56263 	goto _34
  56264 _34:
  56265 	v35 = v31 + v33 - int32(17685)
  56266 	if v35 & ^int32(YUV_MASK2) == 0 {
  56267 		v38 = v35 >> int32(YUV_FIX2)
  56268 	} else {
  56269 		if v35 < 0 {
  56270 			v39 = 0
  56271 		} else {
  56272 			v39 = int32(255)
  56273 		}
  56274 		v38 = v39
  56275 	}
  56276 	v36 = v38
  56277 	goto _37
  56278 _37:
  56279 	v29 = v36
  56280 	goto _30
  56281 _30:
  56282 	b = v29
  56283 	rg = r&int32(0xf0) | g>>libc.Int32FromInt32(4)
  56284 	ba = b&int32(0xf0) | int32(0x0f)
  56285 	**(**uint8_t)(__ccgo_up(v4)) = uint8(rg)
  56286 	**(**uint8_t)(__ccgo_up(v4 + 1)) = uint8(ba)
  56287 	if bottom_y != libc.UintptrFromInt32(0) {
  56288 		uv01 = (uint32(3)*l_uv + tl_uv + uint32(0x00020002)) >> int32(2)
  56289 		v1 = int32(**(**uint8_t)(__ccgo_up(bottom_y)))
  56290 		v2 = int32(uv01 & uint32(0xff))
  56291 		v3 = int32(uv01 >> libc.Int32FromInt32(16))
  56292 		v4 = bottom_dst
  56293 		v7 = v1 * int32(19077) >> int32(8)
  56294 		goto _47
  56295 	_47:
  56296 		v9 = v3 * int32(26149) >> int32(8)
  56297 		goto _49
  56298 	_49:
  56299 		v11 = v7 + v9 - int32(14234)
  56300 		if v11 & ^int32(YUV_MASK2) == 0 {
  56301 			v14 = v11 >> int32(YUV_FIX2)
  56302 		} else {
  56303 			if v11 < 0 {
  56304 				v15 = 0
  56305 			} else {
  56306 				v15 = int32(255)
  56307 			}
  56308 			v14 = v15
  56309 		}
  56310 		v12 = v14
  56311 		goto _52
  56312 	_52:
  56313 		v5 = v12
  56314 		goto _45
  56315 	_45:
  56316 		r = v5
  56317 		v18 = v1 * int32(19077) >> int32(8)
  56318 		goto _58
  56319 	_58:
  56320 		v20 = v2 * int32(6419) >> int32(8)
  56321 		goto _60
  56322 	_60:
  56323 		v22 = v3 * int32(13320) >> int32(8)
  56324 		goto _62
  56325 	_62:
  56326 		v24 = v18 - v20 - v22 + int32(8708)
  56327 		if v24 & ^int32(YUV_MASK2) == 0 {
  56328 			v27 = v24 >> int32(YUV_FIX2)
  56329 		} else {
  56330 			if v24 < 0 {
  56331 				v28 = 0
  56332 			} else {
  56333 				v28 = int32(255)
  56334 			}
  56335 			v27 = v28
  56336 		}
  56337 		v25 = v27
  56338 		goto _65
  56339 	_65:
  56340 		v16 = v25
  56341 		goto _56
  56342 	_56:
  56343 		g = v16
  56344 		v31 = v1 * int32(19077) >> int32(8)
  56345 		goto _71
  56346 	_71:
  56347 		v33 = v2 * int32(33050) >> int32(8)
  56348 		goto _73
  56349 	_73:
  56350 		v35 = v31 + v33 - int32(17685)
  56351 		if v35 & ^int32(YUV_MASK2) == 0 {
  56352 			v38 = v35 >> int32(YUV_FIX2)
  56353 		} else {
  56354 			if v35 < 0 {
  56355 				v39 = 0
  56356 			} else {
  56357 				v39 = int32(255)
  56358 			}
  56359 			v38 = v39
  56360 		}
  56361 		v36 = v38
  56362 		goto _76
  56363 	_76:
  56364 		v29 = v36
  56365 		goto _69
  56366 	_69:
  56367 		b = v29
  56368 		rg = r&int32(0xf0) | g>>libc.Int32FromInt32(4)
  56369 		ba = b&int32(0xf0) | int32(0x0f)
  56370 		**(**uint8_t)(__ccgo_up(v4)) = uint8(rg)
  56371 		**(**uint8_t)(__ccgo_up(v4 + 1)) = uint8(ba)
  56372 	}
  56373 	x = int32(1)
  56374 	for {
  56375 		if !(x <= last_pixel_pair) {
  56376 			break
  56377 		}
  56378 		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 */
  56379 		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*/
  56380 		avg = tl_uv + t_uv + l_uv + uv + uint32(0x00080008)
  56381 		diag_12 = (avg + uint32(2)*(t_uv+l_uv)) >> int32(3)
  56382 		diag_03 = (avg + uint32(2)*(tl_uv+uv)) >> int32(3)
  56383 		uv02 = (diag_12 + tl_uv) >> int32(1)
  56384 		uv1 = (diag_03 + t_uv) >> int32(1)
  56385 		v1 = int32(**(**uint8_t)(__ccgo_up(top_y + uintptr(int32(2)*x-int32(1)))))
  56386 		v2 = int32(uv02 & uint32(0xff))
  56387 		v3 = int32(uv02 >> libc.Int32FromInt32(16))
  56388 		v4 = top_dst + uintptr((int32(2)*x-int32(1))*int32(2))
  56389 		v7 = v1 * int32(19077) >> int32(8)
  56390 		goto _87
  56391 	_87:
  56392 		v9 = v3 * int32(26149) >> int32(8)
  56393 		goto _89
  56394 	_89:
  56395 		v11 = v7 + v9 - int32(14234)
  56396 		if v11 & ^int32(YUV_MASK2) == 0 {
  56397 			v14 = v11 >> int32(YUV_FIX2)
  56398 		} else {
  56399 			if v11 < 0 {
  56400 				v15 = 0
  56401 			} else {
  56402 				v15 = int32(255)
  56403 			}
  56404 			v14 = v15
  56405 		}
  56406 		v12 = v14
  56407 		goto _92
  56408 	_92:
  56409 		v5 = v12
  56410 		goto _85
  56411 	_85:
  56412 		r = v5
  56413 		v18 = v1 * int32(19077) >> int32(8)
  56414 		goto _98
  56415 	_98:
  56416 		v20 = v2 * int32(6419) >> int32(8)
  56417 		goto _100
  56418 	_100:
  56419 		v22 = v3 * int32(13320) >> int32(8)
  56420 		goto _102
  56421 	_102:
  56422 		v24 = v18 - v20 - v22 + int32(8708)
  56423 		if v24 & ^int32(YUV_MASK2) == 0 {
  56424 			v27 = v24 >> int32(YUV_FIX2)
  56425 		} else {
  56426 			if v24 < 0 {
  56427 				v28 = 0
  56428 			} else {
  56429 				v28 = int32(255)
  56430 			}
  56431 			v27 = v28
  56432 		}
  56433 		v25 = v27
  56434 		goto _105
  56435 	_105:
  56436 		v16 = v25
  56437 		goto _96
  56438 	_96:
  56439 		g = v16
  56440 		v31 = v1 * int32(19077) >> int32(8)
  56441 		goto _111
  56442 	_111:
  56443 		v33 = v2 * int32(33050) >> int32(8)
  56444 		goto _113
  56445 	_113:
  56446 		v35 = v31 + v33 - int32(17685)
  56447 		if v35 & ^int32(YUV_MASK2) == 0 {
  56448 			v38 = v35 >> int32(YUV_FIX2)
  56449 		} else {
  56450 			if v35 < 0 {
  56451 				v39 = 0
  56452 			} else {
  56453 				v39 = int32(255)
  56454 			}
  56455 			v38 = v39
  56456 		}
  56457 		v36 = v38
  56458 		goto _116
  56459 	_116:
  56460 		v29 = v36
  56461 		goto _109
  56462 	_109:
  56463 		b = v29
  56464 		rg = r&int32(0xf0) | g>>libc.Int32FromInt32(4)
  56465 		ba = b&int32(0xf0) | int32(0x0f)
  56466 		**(**uint8_t)(__ccgo_up(v4)) = uint8(rg)
  56467 		**(**uint8_t)(__ccgo_up(v4 + 1)) = uint8(ba)
  56468 		v1 = int32(**(**uint8_t)(__ccgo_up(top_y + uintptr(int32(2)*x-0))))
  56469 		v2 = int32(uv1 & uint32(0xff))
  56470 		v3 = int32(uv1 >> libc.Int32FromInt32(16))
  56471 		v4 = top_dst + uintptr((int32(2)*x-0)*int32(2))
  56472 		v7 = v1 * int32(19077) >> int32(8)
  56473 		goto _126
  56474 	_126:
  56475 		v9 = v3 * int32(26149) >> int32(8)
  56476 		goto _128
  56477 	_128:
  56478 		v11 = v7 + v9 - int32(14234)
  56479 		if v11 & ^int32(YUV_MASK2) == 0 {
  56480 			v14 = v11 >> int32(YUV_FIX2)
  56481 		} else {
  56482 			if v11 < 0 {
  56483 				v15 = 0
  56484 			} else {
  56485 				v15 = int32(255)
  56486 			}
  56487 			v14 = v15
  56488 		}
  56489 		v12 = v14
  56490 		goto _131
  56491 	_131:
  56492 		v5 = v12
  56493 		goto _124
  56494 	_124:
  56495 		r = v5
  56496 		v18 = v1 * int32(19077) >> int32(8)
  56497 		goto _137
  56498 	_137:
  56499 		v20 = v2 * int32(6419) >> int32(8)
  56500 		goto _139
  56501 	_139:
  56502 		v22 = v3 * int32(13320) >> int32(8)
  56503 		goto _141
  56504 	_141:
  56505 		v24 = v18 - v20 - v22 + int32(8708)
  56506 		if v24 & ^int32(YUV_MASK2) == 0 {
  56507 			v27 = v24 >> int32(YUV_FIX2)
  56508 		} else {
  56509 			if v24 < 0 {
  56510 				v28 = 0
  56511 			} else {
  56512 				v28 = int32(255)
  56513 			}
  56514 			v27 = v28
  56515 		}
  56516 		v25 = v27
  56517 		goto _144
  56518 	_144:
  56519 		v16 = v25
  56520 		goto _135
  56521 	_135:
  56522 		g = v16
  56523 		v31 = v1 * int32(19077) >> int32(8)
  56524 		goto _150
  56525 	_150:
  56526 		v33 = v2 * int32(33050) >> int32(8)
  56527 		goto _152
  56528 	_152:
  56529 		v35 = v31 + v33 - int32(17685)
  56530 		if v35 & ^int32(YUV_MASK2) == 0 {
  56531 			v38 = v35 >> int32(YUV_FIX2)
  56532 		} else {
  56533 			if v35 < 0 {
  56534 				v39 = 0
  56535 			} else {
  56536 				v39 = int32(255)
  56537 			}
  56538 			v38 = v39
  56539 		}
  56540 		v36 = v38
  56541 		goto _155
  56542 	_155:
  56543 		v29 = v36
  56544 		goto _148
  56545 	_148:
  56546 		b = v29
  56547 		rg = r&int32(0xf0) | g>>libc.Int32FromInt32(4)
  56548 		ba = b&int32(0xf0) | int32(0x0f)
  56549 		**(**uint8_t)(__ccgo_up(v4)) = uint8(rg)
  56550 		**(**uint8_t)(__ccgo_up(v4 + 1)) = uint8(ba)
  56551 		if bottom_y != libc.UintptrFromInt32(0) {
  56552 			uv03 = (diag_03 + l_uv) >> int32(1)
  56553 			uv11 = (diag_12 + uv) >> int32(1)
  56554 			v1 = int32(**(**uint8_t)(__ccgo_up(bottom_y + uintptr(int32(2)*x-int32(1)))))
  56555 			v2 = int32(uv03 & uint32(0xff))
  56556 			v3 = int32(uv03 >> libc.Int32FromInt32(16))
  56557 			v4 = bottom_dst + uintptr((int32(2)*x-int32(1))*int32(2))
  56558 			v7 = v1 * int32(19077) >> int32(8)
  56559 			goto _165
  56560 		_165:
  56561 			v9 = v3 * int32(26149) >> int32(8)
  56562 			goto _167
  56563 		_167:
  56564 			v11 = v7 + v9 - int32(14234)
  56565 			if v11 & ^int32(YUV_MASK2) == 0 {
  56566 				v14 = v11 >> int32(YUV_FIX2)
  56567 			} else {
  56568 				if v11 < 0 {
  56569 					v15 = 0
  56570 				} else {
  56571 					v15 = int32(255)
  56572 				}
  56573 				v14 = v15
  56574 			}
  56575 			v12 = v14
  56576 			goto _170
  56577 		_170:
  56578 			v5 = v12
  56579 			goto _163
  56580 		_163:
  56581 			r = v5
  56582 			v18 = v1 * int32(19077) >> int32(8)
  56583 			goto _176
  56584 		_176:
  56585 			v20 = v2 * int32(6419) >> int32(8)
  56586 			goto _178
  56587 		_178:
  56588 			v22 = v3 * int32(13320) >> int32(8)
  56589 			goto _180
  56590 		_180:
  56591 			v24 = v18 - v20 - v22 + int32(8708)
  56592 			if v24 & ^int32(YUV_MASK2) == 0 {
  56593 				v27 = v24 >> int32(YUV_FIX2)
  56594 			} else {
  56595 				if v24 < 0 {
  56596 					v28 = 0
  56597 				} else {
  56598 					v28 = int32(255)
  56599 				}
  56600 				v27 = v28
  56601 			}
  56602 			v25 = v27
  56603 			goto _183
  56604 		_183:
  56605 			v16 = v25
  56606 			goto _174
  56607 		_174:
  56608 			g = v16
  56609 			v31 = v1 * int32(19077) >> int32(8)
  56610 			goto _189
  56611 		_189:
  56612 			v33 = v2 * int32(33050) >> int32(8)
  56613 			goto _191
  56614 		_191:
  56615 			v35 = v31 + v33 - int32(17685)
  56616 			if v35 & ^int32(YUV_MASK2) == 0 {
  56617 				v38 = v35 >> int32(YUV_FIX2)
  56618 			} else {
  56619 				if v35 < 0 {
  56620 					v39 = 0
  56621 				} else {
  56622 					v39 = int32(255)
  56623 				}
  56624 				v38 = v39
  56625 			}
  56626 			v36 = v38
  56627 			goto _194
  56628 		_194:
  56629 			v29 = v36
  56630 			goto _187
  56631 		_187:
  56632 			b = v29
  56633 			rg = r&int32(0xf0) | g>>libc.Int32FromInt32(4)
  56634 			ba = b&int32(0xf0) | int32(0x0f)
  56635 			**(**uint8_t)(__ccgo_up(v4)) = uint8(rg)
  56636 			**(**uint8_t)(__ccgo_up(v4 + 1)) = uint8(ba)
  56637 			v1 = int32(**(**uint8_t)(__ccgo_up(bottom_y + uintptr(int32(2)*x+0))))
  56638 			v2 = int32(uv11 & uint32(0xff))
  56639 			v3 = int32(uv11 >> libc.Int32FromInt32(16))
  56640 			v4 = bottom_dst + uintptr((int32(2)*x+0)*int32(2))
  56641 			v7 = v1 * int32(19077) >> int32(8)
  56642 			goto _204
  56643 		_204:
  56644 			v9 = v3 * int32(26149) >> int32(8)
  56645 			goto _206
  56646 		_206:
  56647 			v11 = v7 + v9 - int32(14234)
  56648 			if v11 & ^int32(YUV_MASK2) == 0 {
  56649 				v14 = v11 >> int32(YUV_FIX2)
  56650 			} else {
  56651 				if v11 < 0 {
  56652 					v15 = 0
  56653 				} else {
  56654 					v15 = int32(255)
  56655 				}
  56656 				v14 = v15
  56657 			}
  56658 			v12 = v14
  56659 			goto _209
  56660 		_209:
  56661 			v5 = v12
  56662 			goto _202
  56663 		_202:
  56664 			r = v5
  56665 			v18 = v1 * int32(19077) >> int32(8)
  56666 			goto _215
  56667 		_215:
  56668 			v20 = v2 * int32(6419) >> int32(8)
  56669 			goto _217
  56670 		_217:
  56671 			v22 = v3 * int32(13320) >> int32(8)
  56672 			goto _219
  56673 		_219:
  56674 			v24 = v18 - v20 - v22 + int32(8708)
  56675 			if v24 & ^int32(YUV_MASK2) == 0 {
  56676 				v27 = v24 >> int32(YUV_FIX2)
  56677 			} else {
  56678 				if v24 < 0 {
  56679 					v28 = 0
  56680 				} else {
  56681 					v28 = int32(255)
  56682 				}
  56683 				v27 = v28
  56684 			}
  56685 			v25 = v27
  56686 			goto _222
  56687 		_222:
  56688 			v16 = v25
  56689 			goto _213
  56690 		_213:
  56691 			g = v16
  56692 			v31 = v1 * int32(19077) >> int32(8)
  56693 			goto _228
  56694 		_228:
  56695 			v33 = v2 * int32(33050) >> int32(8)
  56696 			goto _230
  56697 		_230:
  56698 			v35 = v31 + v33 - int32(17685)
  56699 			if v35 & ^int32(YUV_MASK2) == 0 {
  56700 				v38 = v35 >> int32(YUV_FIX2)
  56701 			} else {
  56702 				if v35 < 0 {
  56703 					v39 = 0
  56704 				} else {
  56705 					v39 = int32(255)
  56706 				}
  56707 				v38 = v39
  56708 			}
  56709 			v36 = v38
  56710 			goto _233
  56711 		_233:
  56712 			v29 = v36
  56713 			goto _226
  56714 		_226:
  56715 			b = v29
  56716 			rg = r&int32(0xf0) | g>>libc.Int32FromInt32(4)
  56717 			ba = b&int32(0xf0) | int32(0x0f)
  56718 			**(**uint8_t)(__ccgo_up(v4)) = uint8(rg)
  56719 			**(**uint8_t)(__ccgo_up(v4 + 1)) = uint8(ba)
  56720 		}
  56721 		tl_uv = t_uv
  56722 		l_uv = uv
  56723 		goto _79
  56724 	_79:
  56725 		;
  56726 		x = x + 1
  56727 	}
  56728 	if !(len1&libc.Int32FromInt32(1) != 0) {
  56729 		uv04 = (uint32(3)*tl_uv + l_uv + uint32(0x00020002)) >> int32(2)
  56730 		v1 = int32(**(**uint8_t)(__ccgo_up(top_y + uintptr(len1-int32(1)))))
  56731 		v2 = int32(uv04 & uint32(0xff))
  56732 		v3 = int32(uv04 >> libc.Int32FromInt32(16))
  56733 		v4 = top_dst + uintptr((len1-int32(1))*int32(2))
  56734 		v7 = v1 * int32(19077) >> int32(8)
  56735 		goto _243
  56736 	_243:
  56737 		v9 = v3 * int32(26149) >> int32(8)
  56738 		goto _245
  56739 	_245:
  56740 		v11 = v7 + v9 - int32(14234)
  56741 		if v11 & ^int32(YUV_MASK2) == 0 {
  56742 			v14 = v11 >> int32(YUV_FIX2)
  56743 		} else {
  56744 			if v11 < 0 {
  56745 				v15 = 0
  56746 			} else {
  56747 				v15 = int32(255)
  56748 			}
  56749 			v14 = v15
  56750 		}
  56751 		v12 = v14
  56752 		goto _248
  56753 	_248:
  56754 		v5 = v12
  56755 		goto _241
  56756 	_241:
  56757 		r = v5
  56758 		v18 = v1 * int32(19077) >> int32(8)
  56759 		goto _254
  56760 	_254:
  56761 		v20 = v2 * int32(6419) >> int32(8)
  56762 		goto _256
  56763 	_256:
  56764 		v22 = v3 * int32(13320) >> int32(8)
  56765 		goto _258
  56766 	_258:
  56767 		v24 = v18 - v20 - v22 + int32(8708)
  56768 		if v24 & ^int32(YUV_MASK2) == 0 {
  56769 			v27 = v24 >> int32(YUV_FIX2)
  56770 		} else {
  56771 			if v24 < 0 {
  56772 				v28 = 0
  56773 			} else {
  56774 				v28 = int32(255)
  56775 			}
  56776 			v27 = v28
  56777 		}
  56778 		v25 = v27
  56779 		goto _261
  56780 	_261:
  56781 		v16 = v25
  56782 		goto _252
  56783 	_252:
  56784 		g = v16
  56785 		v31 = v1 * int32(19077) >> int32(8)
  56786 		goto _267
  56787 	_267:
  56788 		v33 = v2 * int32(33050) >> int32(8)
  56789 		goto _269
  56790 	_269:
  56791 		v35 = v31 + v33 - int32(17685)
  56792 		if v35 & ^int32(YUV_MASK2) == 0 {
  56793 			v38 = v35 >> int32(YUV_FIX2)
  56794 		} else {
  56795 			if v35 < 0 {
  56796 				v39 = 0
  56797 			} else {
  56798 				v39 = int32(255)
  56799 			}
  56800 			v38 = v39
  56801 		}
  56802 		v36 = v38
  56803 		goto _272
  56804 	_272:
  56805 		v29 = v36
  56806 		goto _265
  56807 	_265:
  56808 		b = v29
  56809 		rg = r&int32(0xf0) | g>>libc.Int32FromInt32(4)
  56810 		ba = b&int32(0xf0) | int32(0x0f)
  56811 		**(**uint8_t)(__ccgo_up(v4)) = uint8(rg)
  56812 		**(**uint8_t)(__ccgo_up(v4 + 1)) = uint8(ba)
  56813 		if bottom_y != libc.UintptrFromInt32(0) {
  56814 			uv05 = (uint32(3)*l_uv + tl_uv + uint32(0x00020002)) >> int32(2)
  56815 			v1 = int32(**(**uint8_t)(__ccgo_up(bottom_y + uintptr(len1-int32(1)))))
  56816 			v2 = int32(uv05 & uint32(0xff))
  56817 			v3 = int32(uv05 >> libc.Int32FromInt32(16))
  56818 			v4 = bottom_dst + uintptr((len1-int32(1))*int32(2))
  56819 			v7 = v1 * int32(19077) >> int32(8)
  56820 			goto _282
  56821 		_282:
  56822 			v9 = v3 * int32(26149) >> int32(8)
  56823 			goto _284
  56824 		_284:
  56825 			v11 = v7 + v9 - int32(14234)
  56826 			if v11 & ^int32(YUV_MASK2) == 0 {
  56827 				v14 = v11 >> int32(YUV_FIX2)
  56828 			} else {
  56829 				if v11 < 0 {
  56830 					v15 = 0
  56831 				} else {
  56832 					v15 = int32(255)
  56833 				}
  56834 				v14 = v15
  56835 			}
  56836 			v12 = v14
  56837 			goto _287
  56838 		_287:
  56839 			v5 = v12
  56840 			goto _280
  56841 		_280:
  56842 			r = v5
  56843 			v18 = v1 * int32(19077) >> int32(8)
  56844 			goto _293
  56845 		_293:
  56846 			v20 = v2 * int32(6419) >> int32(8)
  56847 			goto _295
  56848 		_295:
  56849 			v22 = v3 * int32(13320) >> int32(8)
  56850 			goto _297
  56851 		_297:
  56852 			v24 = v18 - v20 - v22 + int32(8708)
  56853 			if v24 & ^int32(YUV_MASK2) == 0 {
  56854 				v27 = v24 >> int32(YUV_FIX2)
  56855 			} else {
  56856 				if v24 < 0 {
  56857 					v28 = 0
  56858 				} else {
  56859 					v28 = int32(255)
  56860 				}
  56861 				v27 = v28
  56862 			}
  56863 			v25 = v27
  56864 			goto _300
  56865 		_300:
  56866 			v16 = v25
  56867 			goto _291
  56868 		_291:
  56869 			g = v16
  56870 			v31 = v1 * int32(19077) >> int32(8)
  56871 			goto _306
  56872 		_306:
  56873 			v33 = v2 * int32(33050) >> int32(8)
  56874 			goto _308
  56875 		_308:
  56876 			v35 = v31 + v33 - int32(17685)
  56877 			if v35 & ^int32(YUV_MASK2) == 0 {
  56878 				v38 = v35 >> int32(YUV_FIX2)
  56879 			} else {
  56880 				if v35 < 0 {
  56881 					v39 = 0
  56882 				} else {
  56883 					v39 = int32(255)
  56884 				}
  56885 				v38 = v39
  56886 			}
  56887 			v36 = v38
  56888 			goto _311
  56889 		_311:
  56890 			v29 = v36
  56891 			goto _304
  56892 		_304:
  56893 			b = v29
  56894 			rg = r&int32(0xf0) | g>>libc.Int32FromInt32(4)
  56895 			ba = b&int32(0xf0) | int32(0x0f)
  56896 			**(**uint8_t)(__ccgo_up(v4)) = uint8(rg)
  56897 			**(**uint8_t)(__ccgo_up(v4 + 1)) = uint8(ba)
  56898 		}
  56899 	}
  56900 }
  56901 
  56902 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) {
  56903 	var avg, diag_03, diag_12, l_uv, t_uv, tl_uv, uv, uv0, uv01, uv02, uv03, uv04, uv05, uv1, uv11 uint32_t
  56904 	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
  56905 	var v4 uintptr
  56906 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  56907 	last_pixel_pair = (len1 - int32(1)) >> int32(1)
  56908 	tl_uv = uint32(int32(**(**uint8_t)(__ccgo_up(top_u))) | int32(**(**uint8_t)(__ccgo_up(top_v)))<<libc.Int32FromInt32(16)) /* top-left sample */
  56909 	l_uv = uint32(int32(**(**uint8_t)(__ccgo_up(cur_u))) | int32(**(**uint8_t)(__ccgo_up(cur_v)))<<libc.Int32FromInt32(16))
  56910 	uv0 = (uint32(3)*tl_uv + l_uv + uint32(0x00020002)) >> int32(2)
  56911 	v1 = int32(**(**uint8_t)(__ccgo_up(top_y)))
  56912 	v2 = int32(uv0 & uint32(0xff))
  56913 	v3 = int32(uv0 >> libc.Int32FromInt32(16))
  56914 	v4 = top_dst
  56915 	v7 = v1 * int32(19077) >> int32(8)
  56916 	goto _8
  56917 _8:
  56918 	v9 = v3 * int32(26149) >> int32(8)
  56919 	goto _10
  56920 _10:
  56921 	v11 = v7 + v9 - int32(14234)
  56922 	if v11 & ^int32(YUV_MASK2) == 0 {
  56923 		v14 = v11 >> int32(YUV_FIX2)
  56924 	} else {
  56925 		if v11 < 0 {
  56926 			v15 = 0
  56927 		} else {
  56928 			v15 = int32(255)
  56929 		}
  56930 		v14 = v15
  56931 	}
  56932 	v12 = v14
  56933 	goto _13
  56934 _13:
  56935 	v5 = v12
  56936 	goto _6
  56937 _6:
  56938 	r = v5
  56939 	v18 = v1 * int32(19077) >> int32(8)
  56940 	goto _19
  56941 _19:
  56942 	v20 = v2 * int32(6419) >> int32(8)
  56943 	goto _21
  56944 _21:
  56945 	v22 = v3 * int32(13320) >> int32(8)
  56946 	goto _23
  56947 _23:
  56948 	v24 = v18 - v20 - v22 + int32(8708)
  56949 	if v24 & ^int32(YUV_MASK2) == 0 {
  56950 		v27 = v24 >> int32(YUV_FIX2)
  56951 	} else {
  56952 		if v24 < 0 {
  56953 			v28 = 0
  56954 		} else {
  56955 			v28 = int32(255)
  56956 		}
  56957 		v27 = v28
  56958 	}
  56959 	v25 = v27
  56960 	goto _26
  56961 _26:
  56962 	v16 = v25
  56963 	goto _17
  56964 _17:
  56965 	g = v16
  56966 	v31 = v1 * int32(19077) >> int32(8)
  56967 	goto _32
  56968 _32:
  56969 	v33 = v2 * int32(33050) >> int32(8)
  56970 	goto _34
  56971 _34:
  56972 	v35 = v31 + v33 - int32(17685)
  56973 	if v35 & ^int32(YUV_MASK2) == 0 {
  56974 		v38 = v35 >> int32(YUV_FIX2)
  56975 	} else {
  56976 		if v35 < 0 {
  56977 			v39 = 0
  56978 		} else {
  56979 			v39 = int32(255)
  56980 		}
  56981 		v38 = v39
  56982 	}
  56983 	v36 = v38
  56984 	goto _37
  56985 _37:
  56986 	v29 = v36
  56987 	goto _30
  56988 _30:
  56989 	b = v29
  56990 	rg = r&int32(0xf8) | g>>libc.Int32FromInt32(5)
  56991 	gb = g<<libc.Int32FromInt32(3)&int32(0xe0) | b>>libc.Int32FromInt32(3)
  56992 	**(**uint8_t)(__ccgo_up(v4)) = uint8(rg)
  56993 	**(**uint8_t)(__ccgo_up(v4 + 1)) = uint8(gb)
  56994 	if bottom_y != libc.UintptrFromInt32(0) {
  56995 		uv01 = (uint32(3)*l_uv + tl_uv + uint32(0x00020002)) >> int32(2)
  56996 		v1 = int32(**(**uint8_t)(__ccgo_up(bottom_y)))
  56997 		v2 = int32(uv01 & uint32(0xff))
  56998 		v3 = int32(uv01 >> libc.Int32FromInt32(16))
  56999 		v4 = bottom_dst
  57000 		v7 = v1 * int32(19077) >> int32(8)
  57001 		goto _47
  57002 	_47:
  57003 		v9 = v3 * int32(26149) >> int32(8)
  57004 		goto _49
  57005 	_49:
  57006 		v11 = v7 + v9 - int32(14234)
  57007 		if v11 & ^int32(YUV_MASK2) == 0 {
  57008 			v14 = v11 >> int32(YUV_FIX2)
  57009 		} else {
  57010 			if v11 < 0 {
  57011 				v15 = 0
  57012 			} else {
  57013 				v15 = int32(255)
  57014 			}
  57015 			v14 = v15
  57016 		}
  57017 		v12 = v14
  57018 		goto _52
  57019 	_52:
  57020 		v5 = v12
  57021 		goto _45
  57022 	_45:
  57023 		r = v5
  57024 		v18 = v1 * int32(19077) >> int32(8)
  57025 		goto _58
  57026 	_58:
  57027 		v20 = v2 * int32(6419) >> int32(8)
  57028 		goto _60
  57029 	_60:
  57030 		v22 = v3 * int32(13320) >> int32(8)
  57031 		goto _62
  57032 	_62:
  57033 		v24 = v18 - v20 - v22 + int32(8708)
  57034 		if v24 & ^int32(YUV_MASK2) == 0 {
  57035 			v27 = v24 >> int32(YUV_FIX2)
  57036 		} else {
  57037 			if v24 < 0 {
  57038 				v28 = 0
  57039 			} else {
  57040 				v28 = int32(255)
  57041 			}
  57042 			v27 = v28
  57043 		}
  57044 		v25 = v27
  57045 		goto _65
  57046 	_65:
  57047 		v16 = v25
  57048 		goto _56
  57049 	_56:
  57050 		g = v16
  57051 		v31 = v1 * int32(19077) >> int32(8)
  57052 		goto _71
  57053 	_71:
  57054 		v33 = v2 * int32(33050) >> int32(8)
  57055 		goto _73
  57056 	_73:
  57057 		v35 = v31 + v33 - int32(17685)
  57058 		if v35 & ^int32(YUV_MASK2) == 0 {
  57059 			v38 = v35 >> int32(YUV_FIX2)
  57060 		} else {
  57061 			if v35 < 0 {
  57062 				v39 = 0
  57063 			} else {
  57064 				v39 = int32(255)
  57065 			}
  57066 			v38 = v39
  57067 		}
  57068 		v36 = v38
  57069 		goto _76
  57070 	_76:
  57071 		v29 = v36
  57072 		goto _69
  57073 	_69:
  57074 		b = v29
  57075 		rg = r&int32(0xf8) | g>>libc.Int32FromInt32(5)
  57076 		gb = g<<libc.Int32FromInt32(3)&int32(0xe0) | b>>libc.Int32FromInt32(3)
  57077 		**(**uint8_t)(__ccgo_up(v4)) = uint8(rg)
  57078 		**(**uint8_t)(__ccgo_up(v4 + 1)) = uint8(gb)
  57079 	}
  57080 	x = int32(1)
  57081 	for {
  57082 		if !(x <= last_pixel_pair) {
  57083 			break
  57084 		}
  57085 		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 */
  57086 		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*/
  57087 		avg = tl_uv + t_uv + l_uv + uv + uint32(0x00080008)
  57088 		diag_12 = (avg + uint32(2)*(t_uv+l_uv)) >> int32(3)
  57089 		diag_03 = (avg + uint32(2)*(tl_uv+uv)) >> int32(3)
  57090 		uv02 = (diag_12 + tl_uv) >> int32(1)
  57091 		uv1 = (diag_03 + t_uv) >> int32(1)
  57092 		v1 = int32(**(**uint8_t)(__ccgo_up(top_y + uintptr(int32(2)*x-int32(1)))))
  57093 		v2 = int32(uv02 & uint32(0xff))
  57094 		v3 = int32(uv02 >> libc.Int32FromInt32(16))
  57095 		v4 = top_dst + uintptr((int32(2)*x-int32(1))*int32(2))
  57096 		v7 = v1 * int32(19077) >> int32(8)
  57097 		goto _87
  57098 	_87:
  57099 		v9 = v3 * int32(26149) >> int32(8)
  57100 		goto _89
  57101 	_89:
  57102 		v11 = v7 + v9 - int32(14234)
  57103 		if v11 & ^int32(YUV_MASK2) == 0 {
  57104 			v14 = v11 >> int32(YUV_FIX2)
  57105 		} else {
  57106 			if v11 < 0 {
  57107 				v15 = 0
  57108 			} else {
  57109 				v15 = int32(255)
  57110 			}
  57111 			v14 = v15
  57112 		}
  57113 		v12 = v14
  57114 		goto _92
  57115 	_92:
  57116 		v5 = v12
  57117 		goto _85
  57118 	_85:
  57119 		r = v5
  57120 		v18 = v1 * int32(19077) >> int32(8)
  57121 		goto _98
  57122 	_98:
  57123 		v20 = v2 * int32(6419) >> int32(8)
  57124 		goto _100
  57125 	_100:
  57126 		v22 = v3 * int32(13320) >> int32(8)
  57127 		goto _102
  57128 	_102:
  57129 		v24 = v18 - v20 - v22 + int32(8708)
  57130 		if v24 & ^int32(YUV_MASK2) == 0 {
  57131 			v27 = v24 >> int32(YUV_FIX2)
  57132 		} else {
  57133 			if v24 < 0 {
  57134 				v28 = 0
  57135 			} else {
  57136 				v28 = int32(255)
  57137 			}
  57138 			v27 = v28
  57139 		}
  57140 		v25 = v27
  57141 		goto _105
  57142 	_105:
  57143 		v16 = v25
  57144 		goto _96
  57145 	_96:
  57146 		g = v16
  57147 		v31 = v1 * int32(19077) >> int32(8)
  57148 		goto _111
  57149 	_111:
  57150 		v33 = v2 * int32(33050) >> int32(8)
  57151 		goto _113
  57152 	_113:
  57153 		v35 = v31 + v33 - int32(17685)
  57154 		if v35 & ^int32(YUV_MASK2) == 0 {
  57155 			v38 = v35 >> int32(YUV_FIX2)
  57156 		} else {
  57157 			if v35 < 0 {
  57158 				v39 = 0
  57159 			} else {
  57160 				v39 = int32(255)
  57161 			}
  57162 			v38 = v39
  57163 		}
  57164 		v36 = v38
  57165 		goto _116
  57166 	_116:
  57167 		v29 = v36
  57168 		goto _109
  57169 	_109:
  57170 		b = v29
  57171 		rg = r&int32(0xf8) | g>>libc.Int32FromInt32(5)
  57172 		gb = g<<libc.Int32FromInt32(3)&int32(0xe0) | b>>libc.Int32FromInt32(3)
  57173 		**(**uint8_t)(__ccgo_up(v4)) = uint8(rg)
  57174 		**(**uint8_t)(__ccgo_up(v4 + 1)) = uint8(gb)
  57175 		v1 = int32(**(**uint8_t)(__ccgo_up(top_y + uintptr(int32(2)*x-0))))
  57176 		v2 = int32(uv1 & uint32(0xff))
  57177 		v3 = int32(uv1 >> libc.Int32FromInt32(16))
  57178 		v4 = top_dst + uintptr((int32(2)*x-0)*int32(2))
  57179 		v7 = v1 * int32(19077) >> int32(8)
  57180 		goto _126
  57181 	_126:
  57182 		v9 = v3 * int32(26149) >> int32(8)
  57183 		goto _128
  57184 	_128:
  57185 		v11 = v7 + v9 - int32(14234)
  57186 		if v11 & ^int32(YUV_MASK2) == 0 {
  57187 			v14 = v11 >> int32(YUV_FIX2)
  57188 		} else {
  57189 			if v11 < 0 {
  57190 				v15 = 0
  57191 			} else {
  57192 				v15 = int32(255)
  57193 			}
  57194 			v14 = v15
  57195 		}
  57196 		v12 = v14
  57197 		goto _131
  57198 	_131:
  57199 		v5 = v12
  57200 		goto _124
  57201 	_124:
  57202 		r = v5
  57203 		v18 = v1 * int32(19077) >> int32(8)
  57204 		goto _137
  57205 	_137:
  57206 		v20 = v2 * int32(6419) >> int32(8)
  57207 		goto _139
  57208 	_139:
  57209 		v22 = v3 * int32(13320) >> int32(8)
  57210 		goto _141
  57211 	_141:
  57212 		v24 = v18 - v20 - v22 + int32(8708)
  57213 		if v24 & ^int32(YUV_MASK2) == 0 {
  57214 			v27 = v24 >> int32(YUV_FIX2)
  57215 		} else {
  57216 			if v24 < 0 {
  57217 				v28 = 0
  57218 			} else {
  57219 				v28 = int32(255)
  57220 			}
  57221 			v27 = v28
  57222 		}
  57223 		v25 = v27
  57224 		goto _144
  57225 	_144:
  57226 		v16 = v25
  57227 		goto _135
  57228 	_135:
  57229 		g = v16
  57230 		v31 = v1 * int32(19077) >> int32(8)
  57231 		goto _150
  57232 	_150:
  57233 		v33 = v2 * int32(33050) >> int32(8)
  57234 		goto _152
  57235 	_152:
  57236 		v35 = v31 + v33 - int32(17685)
  57237 		if v35 & ^int32(YUV_MASK2) == 0 {
  57238 			v38 = v35 >> int32(YUV_FIX2)
  57239 		} else {
  57240 			if v35 < 0 {
  57241 				v39 = 0
  57242 			} else {
  57243 				v39 = int32(255)
  57244 			}
  57245 			v38 = v39
  57246 		}
  57247 		v36 = v38
  57248 		goto _155
  57249 	_155:
  57250 		v29 = v36
  57251 		goto _148
  57252 	_148:
  57253 		b = v29
  57254 		rg = r&int32(0xf8) | g>>libc.Int32FromInt32(5)
  57255 		gb = g<<libc.Int32FromInt32(3)&int32(0xe0) | b>>libc.Int32FromInt32(3)
  57256 		**(**uint8_t)(__ccgo_up(v4)) = uint8(rg)
  57257 		**(**uint8_t)(__ccgo_up(v4 + 1)) = uint8(gb)
  57258 		if bottom_y != libc.UintptrFromInt32(0) {
  57259 			uv03 = (diag_03 + l_uv) >> int32(1)
  57260 			uv11 = (diag_12 + uv) >> int32(1)
  57261 			v1 = int32(**(**uint8_t)(__ccgo_up(bottom_y + uintptr(int32(2)*x-int32(1)))))
  57262 			v2 = int32(uv03 & uint32(0xff))
  57263 			v3 = int32(uv03 >> libc.Int32FromInt32(16))
  57264 			v4 = bottom_dst + uintptr((int32(2)*x-int32(1))*int32(2))
  57265 			v7 = v1 * int32(19077) >> int32(8)
  57266 			goto _165
  57267 		_165:
  57268 			v9 = v3 * int32(26149) >> int32(8)
  57269 			goto _167
  57270 		_167:
  57271 			v11 = v7 + v9 - int32(14234)
  57272 			if v11 & ^int32(YUV_MASK2) == 0 {
  57273 				v14 = v11 >> int32(YUV_FIX2)
  57274 			} else {
  57275 				if v11 < 0 {
  57276 					v15 = 0
  57277 				} else {
  57278 					v15 = int32(255)
  57279 				}
  57280 				v14 = v15
  57281 			}
  57282 			v12 = v14
  57283 			goto _170
  57284 		_170:
  57285 			v5 = v12
  57286 			goto _163
  57287 		_163:
  57288 			r = v5
  57289 			v18 = v1 * int32(19077) >> int32(8)
  57290 			goto _176
  57291 		_176:
  57292 			v20 = v2 * int32(6419) >> int32(8)
  57293 			goto _178
  57294 		_178:
  57295 			v22 = v3 * int32(13320) >> int32(8)
  57296 			goto _180
  57297 		_180:
  57298 			v24 = v18 - v20 - v22 + int32(8708)
  57299 			if v24 & ^int32(YUV_MASK2) == 0 {
  57300 				v27 = v24 >> int32(YUV_FIX2)
  57301 			} else {
  57302 				if v24 < 0 {
  57303 					v28 = 0
  57304 				} else {
  57305 					v28 = int32(255)
  57306 				}
  57307 				v27 = v28
  57308 			}
  57309 			v25 = v27
  57310 			goto _183
  57311 		_183:
  57312 			v16 = v25
  57313 			goto _174
  57314 		_174:
  57315 			g = v16
  57316 			v31 = v1 * int32(19077) >> int32(8)
  57317 			goto _189
  57318 		_189:
  57319 			v33 = v2 * int32(33050) >> int32(8)
  57320 			goto _191
  57321 		_191:
  57322 			v35 = v31 + v33 - int32(17685)
  57323 			if v35 & ^int32(YUV_MASK2) == 0 {
  57324 				v38 = v35 >> int32(YUV_FIX2)
  57325 			} else {
  57326 				if v35 < 0 {
  57327 					v39 = 0
  57328 				} else {
  57329 					v39 = int32(255)
  57330 				}
  57331 				v38 = v39
  57332 			}
  57333 			v36 = v38
  57334 			goto _194
  57335 		_194:
  57336 			v29 = v36
  57337 			goto _187
  57338 		_187:
  57339 			b = v29
  57340 			rg = r&int32(0xf8) | g>>libc.Int32FromInt32(5)
  57341 			gb = g<<libc.Int32FromInt32(3)&int32(0xe0) | b>>libc.Int32FromInt32(3)
  57342 			**(**uint8_t)(__ccgo_up(v4)) = uint8(rg)
  57343 			**(**uint8_t)(__ccgo_up(v4 + 1)) = uint8(gb)
  57344 			v1 = int32(**(**uint8_t)(__ccgo_up(bottom_y + uintptr(int32(2)*x+0))))
  57345 			v2 = int32(uv11 & uint32(0xff))
  57346 			v3 = int32(uv11 >> libc.Int32FromInt32(16))
  57347 			v4 = bottom_dst + uintptr((int32(2)*x+0)*int32(2))
  57348 			v7 = v1 * int32(19077) >> int32(8)
  57349 			goto _204
  57350 		_204:
  57351 			v9 = v3 * int32(26149) >> int32(8)
  57352 			goto _206
  57353 		_206:
  57354 			v11 = v7 + v9 - int32(14234)
  57355 			if v11 & ^int32(YUV_MASK2) == 0 {
  57356 				v14 = v11 >> int32(YUV_FIX2)
  57357 			} else {
  57358 				if v11 < 0 {
  57359 					v15 = 0
  57360 				} else {
  57361 					v15 = int32(255)
  57362 				}
  57363 				v14 = v15
  57364 			}
  57365 			v12 = v14
  57366 			goto _209
  57367 		_209:
  57368 			v5 = v12
  57369 			goto _202
  57370 		_202:
  57371 			r = v5
  57372 			v18 = v1 * int32(19077) >> int32(8)
  57373 			goto _215
  57374 		_215:
  57375 			v20 = v2 * int32(6419) >> int32(8)
  57376 			goto _217
  57377 		_217:
  57378 			v22 = v3 * int32(13320) >> int32(8)
  57379 			goto _219
  57380 		_219:
  57381 			v24 = v18 - v20 - v22 + int32(8708)
  57382 			if v24 & ^int32(YUV_MASK2) == 0 {
  57383 				v27 = v24 >> int32(YUV_FIX2)
  57384 			} else {
  57385 				if v24 < 0 {
  57386 					v28 = 0
  57387 				} else {
  57388 					v28 = int32(255)
  57389 				}
  57390 				v27 = v28
  57391 			}
  57392 			v25 = v27
  57393 			goto _222
  57394 		_222:
  57395 			v16 = v25
  57396 			goto _213
  57397 		_213:
  57398 			g = v16
  57399 			v31 = v1 * int32(19077) >> int32(8)
  57400 			goto _228
  57401 		_228:
  57402 			v33 = v2 * int32(33050) >> int32(8)
  57403 			goto _230
  57404 		_230:
  57405 			v35 = v31 + v33 - int32(17685)
  57406 			if v35 & ^int32(YUV_MASK2) == 0 {
  57407 				v38 = v35 >> int32(YUV_FIX2)
  57408 			} else {
  57409 				if v35 < 0 {
  57410 					v39 = 0
  57411 				} else {
  57412 					v39 = int32(255)
  57413 				}
  57414 				v38 = v39
  57415 			}
  57416 			v36 = v38
  57417 			goto _233
  57418 		_233:
  57419 			v29 = v36
  57420 			goto _226
  57421 		_226:
  57422 			b = v29
  57423 			rg = r&int32(0xf8) | g>>libc.Int32FromInt32(5)
  57424 			gb = g<<libc.Int32FromInt32(3)&int32(0xe0) | b>>libc.Int32FromInt32(3)
  57425 			**(**uint8_t)(__ccgo_up(v4)) = uint8(rg)
  57426 			**(**uint8_t)(__ccgo_up(v4 + 1)) = uint8(gb)
  57427 		}
  57428 		tl_uv = t_uv
  57429 		l_uv = uv
  57430 		goto _79
  57431 	_79:
  57432 		;
  57433 		x = x + 1
  57434 	}
  57435 	if !(len1&libc.Int32FromInt32(1) != 0) {
  57436 		uv04 = (uint32(3)*tl_uv + l_uv + uint32(0x00020002)) >> int32(2)
  57437 		v1 = int32(**(**uint8_t)(__ccgo_up(top_y + uintptr(len1-int32(1)))))
  57438 		v2 = int32(uv04 & uint32(0xff))
  57439 		v3 = int32(uv04 >> libc.Int32FromInt32(16))
  57440 		v4 = top_dst + uintptr((len1-int32(1))*int32(2))
  57441 		v7 = v1 * int32(19077) >> int32(8)
  57442 		goto _243
  57443 	_243:
  57444 		v9 = v3 * int32(26149) >> int32(8)
  57445 		goto _245
  57446 	_245:
  57447 		v11 = v7 + v9 - int32(14234)
  57448 		if v11 & ^int32(YUV_MASK2) == 0 {
  57449 			v14 = v11 >> int32(YUV_FIX2)
  57450 		} else {
  57451 			if v11 < 0 {
  57452 				v15 = 0
  57453 			} else {
  57454 				v15 = int32(255)
  57455 			}
  57456 			v14 = v15
  57457 		}
  57458 		v12 = v14
  57459 		goto _248
  57460 	_248:
  57461 		v5 = v12
  57462 		goto _241
  57463 	_241:
  57464 		r = v5
  57465 		v18 = v1 * int32(19077) >> int32(8)
  57466 		goto _254
  57467 	_254:
  57468 		v20 = v2 * int32(6419) >> int32(8)
  57469 		goto _256
  57470 	_256:
  57471 		v22 = v3 * int32(13320) >> int32(8)
  57472 		goto _258
  57473 	_258:
  57474 		v24 = v18 - v20 - v22 + int32(8708)
  57475 		if v24 & ^int32(YUV_MASK2) == 0 {
  57476 			v27 = v24 >> int32(YUV_FIX2)
  57477 		} else {
  57478 			if v24 < 0 {
  57479 				v28 = 0
  57480 			} else {
  57481 				v28 = int32(255)
  57482 			}
  57483 			v27 = v28
  57484 		}
  57485 		v25 = v27
  57486 		goto _261
  57487 	_261:
  57488 		v16 = v25
  57489 		goto _252
  57490 	_252:
  57491 		g = v16
  57492 		v31 = v1 * int32(19077) >> int32(8)
  57493 		goto _267
  57494 	_267:
  57495 		v33 = v2 * int32(33050) >> int32(8)
  57496 		goto _269
  57497 	_269:
  57498 		v35 = v31 + v33 - int32(17685)
  57499 		if v35 & ^int32(YUV_MASK2) == 0 {
  57500 			v38 = v35 >> int32(YUV_FIX2)
  57501 		} else {
  57502 			if v35 < 0 {
  57503 				v39 = 0
  57504 			} else {
  57505 				v39 = int32(255)
  57506 			}
  57507 			v38 = v39
  57508 		}
  57509 		v36 = v38
  57510 		goto _272
  57511 	_272:
  57512 		v29 = v36
  57513 		goto _265
  57514 	_265:
  57515 		b = v29
  57516 		rg = r&int32(0xf8) | g>>libc.Int32FromInt32(5)
  57517 		gb = g<<libc.Int32FromInt32(3)&int32(0xe0) | b>>libc.Int32FromInt32(3)
  57518 		**(**uint8_t)(__ccgo_up(v4)) = uint8(rg)
  57519 		**(**uint8_t)(__ccgo_up(v4 + 1)) = uint8(gb)
  57520 		if bottom_y != libc.UintptrFromInt32(0) {
  57521 			uv05 = (uint32(3)*l_uv + tl_uv + uint32(0x00020002)) >> int32(2)
  57522 			v1 = int32(**(**uint8_t)(__ccgo_up(bottom_y + uintptr(len1-int32(1)))))
  57523 			v2 = int32(uv05 & uint32(0xff))
  57524 			v3 = int32(uv05 >> libc.Int32FromInt32(16))
  57525 			v4 = bottom_dst + uintptr((len1-int32(1))*int32(2))
  57526 			v7 = v1 * int32(19077) >> int32(8)
  57527 			goto _282
  57528 		_282:
  57529 			v9 = v3 * int32(26149) >> int32(8)
  57530 			goto _284
  57531 		_284:
  57532 			v11 = v7 + v9 - int32(14234)
  57533 			if v11 & ^int32(YUV_MASK2) == 0 {
  57534 				v14 = v11 >> int32(YUV_FIX2)
  57535 			} else {
  57536 				if v11 < 0 {
  57537 					v15 = 0
  57538 				} else {
  57539 					v15 = int32(255)
  57540 				}
  57541 				v14 = v15
  57542 			}
  57543 			v12 = v14
  57544 			goto _287
  57545 		_287:
  57546 			v5 = v12
  57547 			goto _280
  57548 		_280:
  57549 			r = v5
  57550 			v18 = v1 * int32(19077) >> int32(8)
  57551 			goto _293
  57552 		_293:
  57553 			v20 = v2 * int32(6419) >> int32(8)
  57554 			goto _295
  57555 		_295:
  57556 			v22 = v3 * int32(13320) >> int32(8)
  57557 			goto _297
  57558 		_297:
  57559 			v24 = v18 - v20 - v22 + int32(8708)
  57560 			if v24 & ^int32(YUV_MASK2) == 0 {
  57561 				v27 = v24 >> int32(YUV_FIX2)
  57562 			} else {
  57563 				if v24 < 0 {
  57564 					v28 = 0
  57565 				} else {
  57566 					v28 = int32(255)
  57567 				}
  57568 				v27 = v28
  57569 			}
  57570 			v25 = v27
  57571 			goto _300
  57572 		_300:
  57573 			v16 = v25
  57574 			goto _291
  57575 		_291:
  57576 			g = v16
  57577 			v31 = v1 * int32(19077) >> int32(8)
  57578 			goto _306
  57579 		_306:
  57580 			v33 = v2 * int32(33050) >> int32(8)
  57581 			goto _308
  57582 		_308:
  57583 			v35 = v31 + v33 - int32(17685)
  57584 			if v35 & ^int32(YUV_MASK2) == 0 {
  57585 				v38 = v35 >> int32(YUV_FIX2)
  57586 			} else {
  57587 				if v35 < 0 {
  57588 					v39 = 0
  57589 				} else {
  57590 					v39 = int32(255)
  57591 				}
  57592 				v38 = v39
  57593 			}
  57594 			v36 = v38
  57595 			goto _311
  57596 		_311:
  57597 			v29 = v36
  57598 			goto _304
  57599 		_304:
  57600 			b = v29
  57601 			rg = r&int32(0xf8) | g>>libc.Int32FromInt32(5)
  57602 			gb = g<<libc.Int32FromInt32(3)&int32(0xe0) | b>>libc.Int32FromInt32(3)
  57603 			**(**uint8_t)(__ccgo_up(v4)) = uint8(rg)
  57604 			**(**uint8_t)(__ccgo_up(v4 + 1)) = uint8(gb)
  57605 		}
  57606 	}
  57607 }
  57608 
  57609 //------------------------------------------------------------------------------
  57610 
  57611 func WebPGetLinePairConverter(tls *libc.TLS, alpha_is_last int32) (r WebPUpsampleLinePairFunc) {
  57612 	var v1 int32
  57613 	_ = v1
  57614 	WebPInitUpsamplers(tls)
  57615 	if alpha_is_last != 0 {
  57616 		v1 = int32(MODE_BGRA)
  57617 	} else {
  57618 		v1 = int32(MODE_ARGB)
  57619 	}
  57620 	return WebPUpsamplers[v1]
  57621 }
  57622 
  57623 func WebPYuv444ToRgba_C(tls *libc.TLS, y5 uintptr, u4 uintptr, v6 uintptr, dst uintptr, len1 int32) {
  57624 	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
  57625 	var v2, v61 uintptr
  57626 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  57627 	i = 0
  57628 	for {
  57629 		if !(i < len1) {
  57630 			break
  57631 		}
  57632 		v2 = dst + uintptr(i*int32(4))
  57633 		v3 = int32(**(**uint8_t)(__ccgo_up(y5 + uintptr(i))))
  57634 		v4 = int32(**(**uint8_t)(__ccgo_up(u4 + uintptr(i))))
  57635 		v5 = int32(**(**uint8_t)(__ccgo_up(v6 + uintptr(i))))
  57636 		v61 = v2
  57637 		v9 = v3 * int32(19077) >> int32(8)
  57638 		goto _10
  57639 	_10:
  57640 		v11 = v5 * int32(26149) >> int32(8)
  57641 		goto _12
  57642 	_12:
  57643 		v13 = v9 + v11 - int32(14234)
  57644 		if v13 & ^int32(YUV_MASK2) == 0 {
  57645 			v16 = v13 >> int32(YUV_FIX2)
  57646 		} else {
  57647 			if v13 < 0 {
  57648 				v17 = 0
  57649 			} else {
  57650 				v17 = int32(255)
  57651 			}
  57652 			v16 = v17
  57653 		}
  57654 		v14 = v16
  57655 		goto _15
  57656 	_15:
  57657 		v7 = v14
  57658 		goto _8
  57659 	_8:
  57660 		**(**uint8_t)(__ccgo_up(v61)) = uint8(v7)
  57661 		v20 = v3 * int32(19077) >> int32(8)
  57662 		goto _21
  57663 	_21:
  57664 		v22 = v4 * int32(6419) >> int32(8)
  57665 		goto _23
  57666 	_23:
  57667 		v24 = v5 * int32(13320) >> int32(8)
  57668 		goto _25
  57669 	_25:
  57670 		v26 = v20 - v22 - v24 + int32(8708)
  57671 		if v26 & ^int32(YUV_MASK2) == 0 {
  57672 			v29 = v26 >> int32(YUV_FIX2)
  57673 		} else {
  57674 			if v26 < 0 {
  57675 				v30 = 0
  57676 			} else {
  57677 				v30 = int32(255)
  57678 			}
  57679 			v29 = v30
  57680 		}
  57681 		v27 = v29
  57682 		goto _28
  57683 	_28:
  57684 		v18 = v27
  57685 		goto _19
  57686 	_19:
  57687 		**(**uint8_t)(__ccgo_up(v61 + 1)) = uint8(v18)
  57688 		v33 = v3 * int32(19077) >> int32(8)
  57689 		goto _34
  57690 	_34:
  57691 		v35 = v4 * int32(33050) >> int32(8)
  57692 		goto _36
  57693 	_36:
  57694 		v37 = v33 + v35 - int32(17685)
  57695 		if v37 & ^int32(YUV_MASK2) == 0 {
  57696 			v40 = v37 >> int32(YUV_FIX2)
  57697 		} else {
  57698 			if v37 < 0 {
  57699 				v41 = 0
  57700 			} else {
  57701 				v41 = int32(255)
  57702 			}
  57703 			v40 = v41
  57704 		}
  57705 		v38 = v40
  57706 		goto _39
  57707 	_39:
  57708 		v31 = v38
  57709 		goto _32
  57710 	_32:
  57711 		**(**uint8_t)(__ccgo_up(v61 + 2)) = uint8(v31)
  57712 		**(**uint8_t)(__ccgo_up(v2 + 3)) = uint8(0xff)
  57713 		goto _1
  57714 	_1:
  57715 		;
  57716 		i = i + 1
  57717 	}
  57718 }
  57719 
  57720 func WebPYuv444ToBgra_C(tls *libc.TLS, y5 uintptr, u4 uintptr, v6 uintptr, dst uintptr, len1 int32) {
  57721 	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
  57722 	var v2, v61 uintptr
  57723 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  57724 	i = 0
  57725 	for {
  57726 		if !(i < len1) {
  57727 			break
  57728 		}
  57729 		v2 = dst + uintptr(i*int32(4))
  57730 		v3 = int32(**(**uint8_t)(__ccgo_up(y5 + uintptr(i))))
  57731 		v4 = int32(**(**uint8_t)(__ccgo_up(u4 + uintptr(i))))
  57732 		v5 = int32(**(**uint8_t)(__ccgo_up(v6 + uintptr(i))))
  57733 		v61 = v2
  57734 		v9 = v3 * int32(19077) >> int32(8)
  57735 		goto _10
  57736 	_10:
  57737 		v11 = v4 * int32(33050) >> int32(8)
  57738 		goto _12
  57739 	_12:
  57740 		v13 = v9 + v11 - int32(17685)
  57741 		if v13 & ^int32(YUV_MASK2) == 0 {
  57742 			v16 = v13 >> int32(YUV_FIX2)
  57743 		} else {
  57744 			if v13 < 0 {
  57745 				v17 = 0
  57746 			} else {
  57747 				v17 = int32(255)
  57748 			}
  57749 			v16 = v17
  57750 		}
  57751 		v14 = v16
  57752 		goto _15
  57753 	_15:
  57754 		v7 = v14
  57755 		goto _8
  57756 	_8:
  57757 		**(**uint8_t)(__ccgo_up(v61)) = uint8(v7)
  57758 		v20 = v3 * int32(19077) >> int32(8)
  57759 		goto _21
  57760 	_21:
  57761 		v22 = v4 * int32(6419) >> int32(8)
  57762 		goto _23
  57763 	_23:
  57764 		v24 = v5 * int32(13320) >> int32(8)
  57765 		goto _25
  57766 	_25:
  57767 		v26 = v20 - v22 - v24 + int32(8708)
  57768 		if v26 & ^int32(YUV_MASK2) == 0 {
  57769 			v29 = v26 >> int32(YUV_FIX2)
  57770 		} else {
  57771 			if v26 < 0 {
  57772 				v30 = 0
  57773 			} else {
  57774 				v30 = int32(255)
  57775 			}
  57776 			v29 = v30
  57777 		}
  57778 		v27 = v29
  57779 		goto _28
  57780 	_28:
  57781 		v18 = v27
  57782 		goto _19
  57783 	_19:
  57784 		**(**uint8_t)(__ccgo_up(v61 + 1)) = uint8(v18)
  57785 		v33 = v3 * int32(19077) >> int32(8)
  57786 		goto _34
  57787 	_34:
  57788 		v35 = v5 * int32(26149) >> int32(8)
  57789 		goto _36
  57790 	_36:
  57791 		v37 = v33 + v35 - int32(14234)
  57792 		if v37 & ^int32(YUV_MASK2) == 0 {
  57793 			v40 = v37 >> int32(YUV_FIX2)
  57794 		} else {
  57795 			if v37 < 0 {
  57796 				v41 = 0
  57797 			} else {
  57798 				v41 = int32(255)
  57799 			}
  57800 			v40 = v41
  57801 		}
  57802 		v38 = v40
  57803 		goto _39
  57804 	_39:
  57805 		v31 = v38
  57806 		goto _32
  57807 	_32:
  57808 		**(**uint8_t)(__ccgo_up(v61 + 2)) = uint8(v31)
  57809 		**(**uint8_t)(__ccgo_up(v2 + 3)) = uint8(0xff)
  57810 		goto _1
  57811 	_1:
  57812 		;
  57813 		i = i + 1
  57814 	}
  57815 }
  57816 
  57817 func WebPYuv444ToRgb_C(tls *libc.TLS, y4 uintptr, u3 uintptr, v5 uintptr, dst uintptr, len1 int32) {
  57818 	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
  57819 	var v51 uintptr
  57820 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  57821 	i = 0
  57822 	for {
  57823 		if !(i < len1) {
  57824 			break
  57825 		}
  57826 		v2 = int32(**(**uint8_t)(__ccgo_up(y4 + uintptr(i))))
  57827 		v3 = int32(**(**uint8_t)(__ccgo_up(u3 + uintptr(i))))
  57828 		v4 = int32(**(**uint8_t)(__ccgo_up(v5 + uintptr(i))))
  57829 		v51 = dst + uintptr(i*int32(3))
  57830 		v8 = v2 * int32(19077) >> int32(8)
  57831 		goto _9
  57832 	_9:
  57833 		v10 = v4 * int32(26149) >> int32(8)
  57834 		goto _11
  57835 	_11:
  57836 		v12 = v8 + v10 - int32(14234)
  57837 		if v12 & ^int32(YUV_MASK2) == 0 {
  57838 			v15 = v12 >> int32(YUV_FIX2)
  57839 		} else {
  57840 			if v12 < 0 {
  57841 				v16 = 0
  57842 			} else {
  57843 				v16 = int32(255)
  57844 			}
  57845 			v15 = v16
  57846 		}
  57847 		v13 = v15
  57848 		goto _14
  57849 	_14:
  57850 		v6 = v13
  57851 		goto _7
  57852 	_7:
  57853 		**(**uint8_t)(__ccgo_up(v51)) = uint8(v6)
  57854 		v19 = v2 * int32(19077) >> int32(8)
  57855 		goto _20
  57856 	_20:
  57857 		v21 = v3 * int32(6419) >> int32(8)
  57858 		goto _22
  57859 	_22:
  57860 		v23 = v4 * int32(13320) >> int32(8)
  57861 		goto _24
  57862 	_24:
  57863 		v25 = v19 - v21 - v23 + int32(8708)
  57864 		if v25 & ^int32(YUV_MASK2) == 0 {
  57865 			v28 = v25 >> int32(YUV_FIX2)
  57866 		} else {
  57867 			if v25 < 0 {
  57868 				v29 = 0
  57869 			} else {
  57870 				v29 = int32(255)
  57871 			}
  57872 			v28 = v29
  57873 		}
  57874 		v26 = v28
  57875 		goto _27
  57876 	_27:
  57877 		v17 = v26
  57878 		goto _18
  57879 	_18:
  57880 		**(**uint8_t)(__ccgo_up(v51 + 1)) = uint8(v17)
  57881 		v32 = v2 * int32(19077) >> int32(8)
  57882 		goto _33
  57883 	_33:
  57884 		v34 = v3 * int32(33050) >> int32(8)
  57885 		goto _35
  57886 	_35:
  57887 		v36 = v32 + v34 - int32(17685)
  57888 		if v36 & ^int32(YUV_MASK2) == 0 {
  57889 			v39 = v36 >> int32(YUV_FIX2)
  57890 		} else {
  57891 			if v36 < 0 {
  57892 				v40 = 0
  57893 			} else {
  57894 				v40 = int32(255)
  57895 			}
  57896 			v39 = v40
  57897 		}
  57898 		v37 = v39
  57899 		goto _38
  57900 	_38:
  57901 		v30 = v37
  57902 		goto _31
  57903 	_31:
  57904 		**(**uint8_t)(__ccgo_up(v51 + 2)) = uint8(v30)
  57905 		goto _1
  57906 	_1:
  57907 		;
  57908 		i = i + 1
  57909 	}
  57910 }
  57911 
  57912 func WebPYuv444ToBgr_C(tls *libc.TLS, y4 uintptr, u3 uintptr, v5 uintptr, dst uintptr, len1 int32) {
  57913 	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
  57914 	var v51 uintptr
  57915 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  57916 	i = 0
  57917 	for {
  57918 		if !(i < len1) {
  57919 			break
  57920 		}
  57921 		v2 = int32(**(**uint8_t)(__ccgo_up(y4 + uintptr(i))))
  57922 		v3 = int32(**(**uint8_t)(__ccgo_up(u3 + uintptr(i))))
  57923 		v4 = int32(**(**uint8_t)(__ccgo_up(v5 + uintptr(i))))
  57924 		v51 = dst + uintptr(i*int32(3))
  57925 		v8 = v2 * int32(19077) >> int32(8)
  57926 		goto _9
  57927 	_9:
  57928 		v10 = v3 * int32(33050) >> int32(8)
  57929 		goto _11
  57930 	_11:
  57931 		v12 = v8 + v10 - int32(17685)
  57932 		if v12 & ^int32(YUV_MASK2) == 0 {
  57933 			v15 = v12 >> int32(YUV_FIX2)
  57934 		} else {
  57935 			if v12 < 0 {
  57936 				v16 = 0
  57937 			} else {
  57938 				v16 = int32(255)
  57939 			}
  57940 			v15 = v16
  57941 		}
  57942 		v13 = v15
  57943 		goto _14
  57944 	_14:
  57945 		v6 = v13
  57946 		goto _7
  57947 	_7:
  57948 		**(**uint8_t)(__ccgo_up(v51)) = uint8(v6)
  57949 		v19 = v2 * int32(19077) >> int32(8)
  57950 		goto _20
  57951 	_20:
  57952 		v21 = v3 * int32(6419) >> int32(8)
  57953 		goto _22
  57954 	_22:
  57955 		v23 = v4 * int32(13320) >> int32(8)
  57956 		goto _24
  57957 	_24:
  57958 		v25 = v19 - v21 - v23 + int32(8708)
  57959 		if v25 & ^int32(YUV_MASK2) == 0 {
  57960 			v28 = v25 >> int32(YUV_FIX2)
  57961 		} else {
  57962 			if v25 < 0 {
  57963 				v29 = 0
  57964 			} else {
  57965 				v29 = int32(255)
  57966 			}
  57967 			v28 = v29
  57968 		}
  57969 		v26 = v28
  57970 		goto _27
  57971 	_27:
  57972 		v17 = v26
  57973 		goto _18
  57974 	_18:
  57975 		**(**uint8_t)(__ccgo_up(v51 + 1)) = uint8(v17)
  57976 		v32 = v2 * int32(19077) >> int32(8)
  57977 		goto _33
  57978 	_33:
  57979 		v34 = v4 * int32(26149) >> int32(8)
  57980 		goto _35
  57981 	_35:
  57982 		v36 = v32 + v34 - int32(14234)
  57983 		if v36 & ^int32(YUV_MASK2) == 0 {
  57984 			v39 = v36 >> int32(YUV_FIX2)
  57985 		} else {
  57986 			if v36 < 0 {
  57987 				v40 = 0
  57988 			} else {
  57989 				v40 = int32(255)
  57990 			}
  57991 			v39 = v40
  57992 		}
  57993 		v37 = v39
  57994 		goto _38
  57995 	_38:
  57996 		v30 = v37
  57997 		goto _31
  57998 	_31:
  57999 		**(**uint8_t)(__ccgo_up(v51 + 2)) = uint8(v30)
  58000 		goto _1
  58001 	_1:
  58002 		;
  58003 		i = i + 1
  58004 	}
  58005 }
  58006 
  58007 func WebPYuv444ToArgb_C(tls *libc.TLS, y5 uintptr, u4 uintptr, v6 uintptr, dst uintptr, len1 int32) {
  58008 	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
  58009 	var v2, v61 uintptr
  58010 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  58011 	i = 0
  58012 	for {
  58013 		if !(i < len1) {
  58014 			break
  58015 		}
  58016 		v2 = dst + uintptr(i*int32(4))
  58017 		**(**uint8_t)(__ccgo_up(v2)) = uint8(0xff)
  58018 		v3 = int32(**(**uint8_t)(__ccgo_up(y5 + uintptr(i))))
  58019 		v4 = int32(**(**uint8_t)(__ccgo_up(u4 + uintptr(i))))
  58020 		v5 = int32(**(**uint8_t)(__ccgo_up(v6 + uintptr(i))))
  58021 		v61 = v2 + uintptr(1)
  58022 		v9 = v3 * int32(19077) >> int32(8)
  58023 		goto _10
  58024 	_10:
  58025 		v11 = v5 * int32(26149) >> int32(8)
  58026 		goto _12
  58027 	_12:
  58028 		v13 = v9 + v11 - int32(14234)
  58029 		if v13 & ^int32(YUV_MASK2) == 0 {
  58030 			v16 = v13 >> int32(YUV_FIX2)
  58031 		} else {
  58032 			if v13 < 0 {
  58033 				v17 = 0
  58034 			} else {
  58035 				v17 = int32(255)
  58036 			}
  58037 			v16 = v17
  58038 		}
  58039 		v14 = v16
  58040 		goto _15
  58041 	_15:
  58042 		v7 = v14
  58043 		goto _8
  58044 	_8:
  58045 		**(**uint8_t)(__ccgo_up(v61)) = uint8(v7)
  58046 		v20 = v3 * int32(19077) >> int32(8)
  58047 		goto _21
  58048 	_21:
  58049 		v22 = v4 * int32(6419) >> int32(8)
  58050 		goto _23
  58051 	_23:
  58052 		v24 = v5 * int32(13320) >> int32(8)
  58053 		goto _25
  58054 	_25:
  58055 		v26 = v20 - v22 - v24 + int32(8708)
  58056 		if v26 & ^int32(YUV_MASK2) == 0 {
  58057 			v29 = v26 >> int32(YUV_FIX2)
  58058 		} else {
  58059 			if v26 < 0 {
  58060 				v30 = 0
  58061 			} else {
  58062 				v30 = int32(255)
  58063 			}
  58064 			v29 = v30
  58065 		}
  58066 		v27 = v29
  58067 		goto _28
  58068 	_28:
  58069 		v18 = v27
  58070 		goto _19
  58071 	_19:
  58072 		**(**uint8_t)(__ccgo_up(v61 + 1)) = uint8(v18)
  58073 		v33 = v3 * int32(19077) >> int32(8)
  58074 		goto _34
  58075 	_34:
  58076 		v35 = v4 * int32(33050) >> int32(8)
  58077 		goto _36
  58078 	_36:
  58079 		v37 = v33 + v35 - int32(17685)
  58080 		if v37 & ^int32(YUV_MASK2) == 0 {
  58081 			v40 = v37 >> int32(YUV_FIX2)
  58082 		} else {
  58083 			if v37 < 0 {
  58084 				v41 = 0
  58085 			} else {
  58086 				v41 = int32(255)
  58087 			}
  58088 			v40 = v41
  58089 		}
  58090 		v38 = v40
  58091 		goto _39
  58092 	_39:
  58093 		v31 = v38
  58094 		goto _32
  58095 	_32:
  58096 		**(**uint8_t)(__ccgo_up(v61 + 2)) = uint8(v31)
  58097 		goto _1
  58098 	_1:
  58099 		;
  58100 		i = i + 1
  58101 	}
  58102 }
  58103 
  58104 func WebPYuv444ToRgba4444_C(tls *libc.TLS, y4 uintptr, u3 uintptr, v5 uintptr, dst uintptr, len1 int32) {
  58105 	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
  58106 	var v51 uintptr
  58107 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  58108 	i = 0
  58109 	for {
  58110 		if !(i < len1) {
  58111 			break
  58112 		}
  58113 		v2 = int32(**(**uint8_t)(__ccgo_up(y4 + uintptr(i))))
  58114 		v3 = int32(**(**uint8_t)(__ccgo_up(u3 + uintptr(i))))
  58115 		v4 = int32(**(**uint8_t)(__ccgo_up(v5 + uintptr(i))))
  58116 		v51 = dst + uintptr(i*int32(2))
  58117 		v8 = v2 * int32(19077) >> int32(8)
  58118 		goto _9
  58119 	_9:
  58120 		v10 = v4 * int32(26149) >> int32(8)
  58121 		goto _11
  58122 	_11:
  58123 		v12 = v8 + v10 - int32(14234)
  58124 		if v12 & ^int32(YUV_MASK2) == 0 {
  58125 			v15 = v12 >> int32(YUV_FIX2)
  58126 		} else {
  58127 			if v12 < 0 {
  58128 				v16 = 0
  58129 			} else {
  58130 				v16 = int32(255)
  58131 			}
  58132 			v15 = v16
  58133 		}
  58134 		v13 = v15
  58135 		goto _14
  58136 	_14:
  58137 		v6 = v13
  58138 		goto _7
  58139 	_7:
  58140 		r = v6
  58141 		v19 = v2 * int32(19077) >> int32(8)
  58142 		goto _20
  58143 	_20:
  58144 		v21 = v3 * int32(6419) >> int32(8)
  58145 		goto _22
  58146 	_22:
  58147 		v23 = v4 * int32(13320) >> int32(8)
  58148 		goto _24
  58149 	_24:
  58150 		v25 = v19 - v21 - v23 + int32(8708)
  58151 		if v25 & ^int32(YUV_MASK2) == 0 {
  58152 			v28 = v25 >> int32(YUV_FIX2)
  58153 		} else {
  58154 			if v25 < 0 {
  58155 				v29 = 0
  58156 			} else {
  58157 				v29 = int32(255)
  58158 			}
  58159 			v28 = v29
  58160 		}
  58161 		v26 = v28
  58162 		goto _27
  58163 	_27:
  58164 		v17 = v26
  58165 		goto _18
  58166 	_18:
  58167 		g = v17
  58168 		v32 = v2 * int32(19077) >> int32(8)
  58169 		goto _33
  58170 	_33:
  58171 		v34 = v3 * int32(33050) >> int32(8)
  58172 		goto _35
  58173 	_35:
  58174 		v36 = v32 + v34 - int32(17685)
  58175 		if v36 & ^int32(YUV_MASK2) == 0 {
  58176 			v39 = v36 >> int32(YUV_FIX2)
  58177 		} else {
  58178 			if v36 < 0 {
  58179 				v40 = 0
  58180 			} else {
  58181 				v40 = int32(255)
  58182 			}
  58183 			v39 = v40
  58184 		}
  58185 		v37 = v39
  58186 		goto _38
  58187 	_38:
  58188 		v30 = v37
  58189 		goto _31
  58190 	_31:
  58191 		b = v30
  58192 		rg = r&int32(0xf0) | g>>libc.Int32FromInt32(4)
  58193 		ba = b&int32(0xf0) | int32(0x0f)
  58194 		**(**uint8_t)(__ccgo_up(v51)) = uint8(rg)
  58195 		**(**uint8_t)(__ccgo_up(v51 + 1)) = uint8(ba)
  58196 		goto _1
  58197 	_1:
  58198 		;
  58199 		i = i + 1
  58200 	}
  58201 }
  58202 
  58203 func WebPYuv444ToRgb565_C(tls *libc.TLS, y4 uintptr, u3 uintptr, v5 uintptr, dst uintptr, len1 int32) {
  58204 	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
  58205 	var v51 uintptr
  58206 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  58207 	i = 0
  58208 	for {
  58209 		if !(i < len1) {
  58210 			break
  58211 		}
  58212 		v2 = int32(**(**uint8_t)(__ccgo_up(y4 + uintptr(i))))
  58213 		v3 = int32(**(**uint8_t)(__ccgo_up(u3 + uintptr(i))))
  58214 		v4 = int32(**(**uint8_t)(__ccgo_up(v5 + uintptr(i))))
  58215 		v51 = dst + uintptr(i*int32(2))
  58216 		v8 = v2 * int32(19077) >> int32(8)
  58217 		goto _9
  58218 	_9:
  58219 		v10 = v4 * int32(26149) >> int32(8)
  58220 		goto _11
  58221 	_11:
  58222 		v12 = v8 + v10 - int32(14234)
  58223 		if v12 & ^int32(YUV_MASK2) == 0 {
  58224 			v15 = v12 >> int32(YUV_FIX2)
  58225 		} else {
  58226 			if v12 < 0 {
  58227 				v16 = 0
  58228 			} else {
  58229 				v16 = int32(255)
  58230 			}
  58231 			v15 = v16
  58232 		}
  58233 		v13 = v15
  58234 		goto _14
  58235 	_14:
  58236 		v6 = v13
  58237 		goto _7
  58238 	_7:
  58239 		r = v6
  58240 		v19 = v2 * int32(19077) >> int32(8)
  58241 		goto _20
  58242 	_20:
  58243 		v21 = v3 * int32(6419) >> int32(8)
  58244 		goto _22
  58245 	_22:
  58246 		v23 = v4 * int32(13320) >> int32(8)
  58247 		goto _24
  58248 	_24:
  58249 		v25 = v19 - v21 - v23 + int32(8708)
  58250 		if v25 & ^int32(YUV_MASK2) == 0 {
  58251 			v28 = v25 >> int32(YUV_FIX2)
  58252 		} else {
  58253 			if v25 < 0 {
  58254 				v29 = 0
  58255 			} else {
  58256 				v29 = int32(255)
  58257 			}
  58258 			v28 = v29
  58259 		}
  58260 		v26 = v28
  58261 		goto _27
  58262 	_27:
  58263 		v17 = v26
  58264 		goto _18
  58265 	_18:
  58266 		g = v17
  58267 		v32 = v2 * int32(19077) >> int32(8)
  58268 		goto _33
  58269 	_33:
  58270 		v34 = v3 * int32(33050) >> int32(8)
  58271 		goto _35
  58272 	_35:
  58273 		v36 = v32 + v34 - int32(17685)
  58274 		if v36 & ^int32(YUV_MASK2) == 0 {
  58275 			v39 = v36 >> int32(YUV_FIX2)
  58276 		} else {
  58277 			if v36 < 0 {
  58278 				v40 = 0
  58279 			} else {
  58280 				v40 = int32(255)
  58281 			}
  58282 			v39 = v40
  58283 		}
  58284 		v37 = v39
  58285 		goto _38
  58286 	_38:
  58287 		v30 = v37
  58288 		goto _31
  58289 	_31:
  58290 		b = v30
  58291 		rg = r&int32(0xf8) | g>>libc.Int32FromInt32(5)
  58292 		gb = g<<libc.Int32FromInt32(3)&int32(0xe0) | b>>libc.Int32FromInt32(3)
  58293 		**(**uint8_t)(__ccgo_up(v51)) = uint8(rg)
  58294 		**(**uint8_t)(__ccgo_up(v51 + 1)) = uint8(gb)
  58295 		goto _1
  58296 	_1:
  58297 		;
  58298 		i = i + 1
  58299 	}
  58300 }
  58301 
  58302 func WebPInitYUV444Converters(tls *libc.TLS) {
  58303 	if libc.AtomicLoadPUintptr(uintptr(unsafe.Pointer(&WebPInitYUV444Converters_body_last_cpuinfo_used))) == VP8GetCPUInfo {
  58304 		goto _1
  58305 	}
  58306 	WebPInitYUV444Converters_body(tls)
  58307 	libc.AtomicStorePUintptr(uintptr(unsafe.Pointer(&WebPInitYUV444Converters_body_last_cpuinfo_used)), VP8GetCPUInfo)
  58308 	goto _2
  58309 _2:
  58310 	;
  58311 	goto _1
  58312 _1: /**/ //
  58313 }
  58314 
  58315 var WebPInitYUV444Converters_body_last_cpuinfo_used = uintptr(0)
  58316 
  58317 func init() {
  58318 	p := unsafe.Pointer(&WebPInitYUV444Converters_body_last_cpuinfo_used)
  58319 	*(*uintptr)(unsafe.Add(p, 0)) = uintptr(unsafe.Pointer(&WebPInitYUV444Converters_body_last_cpuinfo_used))
  58320 }
  58321 
  58322 func WebPInitYUV444Converters_body(tls *libc.TLS) {
  58323 	WebPYUV444Converters[int32(MODE_RGBA)] = __ccgo_fp(WebPYuv444ToRgba_C)
  58324 	WebPYUV444Converters[int32(MODE_BGRA)] = __ccgo_fp(WebPYuv444ToBgra_C)
  58325 	WebPYUV444Converters[int32(MODE_RGB)] = __ccgo_fp(WebPYuv444ToRgb_C)
  58326 	WebPYUV444Converters[int32(MODE_BGR)] = __ccgo_fp(WebPYuv444ToBgr_C)
  58327 	WebPYUV444Converters[int32(MODE_ARGB)] = __ccgo_fp(WebPYuv444ToArgb_C)
  58328 	WebPYUV444Converters[int32(MODE_RGBA_4444)] = __ccgo_fp(WebPYuv444ToRgba4444_C)
  58329 	WebPYUV444Converters[int32(MODE_RGB_565)] = __ccgo_fp(WebPYuv444ToRgb565_C)
  58330 	WebPYUV444Converters[int32(MODE_rgbA)] = __ccgo_fp(WebPYuv444ToRgba_C)
  58331 	WebPYUV444Converters[int32(MODE_bgrA)] = __ccgo_fp(WebPYuv444ToBgra_C)
  58332 	WebPYUV444Converters[int32(MODE_Argb)] = __ccgo_fp(WebPYuv444ToArgb_C)
  58333 	WebPYUV444Converters[int32(MODE_rgbA_4444)] = __ccgo_fp(WebPYuv444ToRgba4444_C)
  58334 	if VP8GetCPUInfo != libc.UintptrFromInt32(0) {
  58335 	}
  58336 }
  58337 
  58338 func WebPInitUpsamplers(tls *libc.TLS) {
  58339 	if libc.AtomicLoadPUintptr(uintptr(unsafe.Pointer(&WebPInitUpsamplers_body_last_cpuinfo_used))) == VP8GetCPUInfo {
  58340 		goto _1
  58341 	}
  58342 	WebPInitUpsamplers_body(tls)
  58343 	libc.AtomicStorePUintptr(uintptr(unsafe.Pointer(&WebPInitUpsamplers_body_last_cpuinfo_used)), VP8GetCPUInfo)
  58344 	goto _2
  58345 _2:
  58346 	;
  58347 	goto _1
  58348 _1: /**/ //
  58349 }
  58350 
  58351 var WebPInitUpsamplers_body_last_cpuinfo_used = uintptr(0)
  58352 
  58353 func init() {
  58354 	p := unsafe.Pointer(&WebPInitUpsamplers_body_last_cpuinfo_used)
  58355 	*(*uintptr)(unsafe.Add(p, 0)) = uintptr(unsafe.Pointer(&WebPInitUpsamplers_body_last_cpuinfo_used))
  58356 }
  58357 
  58358 func WebPInitUpsamplers_body(tls *libc.TLS) {
  58359 	WebPUpsamplers[int32(MODE_RGBA)] = __ccgo_fp(UpsampleRgbaLinePair_C)
  58360 	WebPUpsamplers[int32(MODE_BGRA)] = __ccgo_fp(UpsampleBgraLinePair_C)
  58361 	WebPUpsamplers[int32(MODE_rgbA)] = __ccgo_fp(UpsampleRgbaLinePair_C)
  58362 	WebPUpsamplers[int32(MODE_bgrA)] = __ccgo_fp(UpsampleBgraLinePair_C)
  58363 	WebPUpsamplers[int32(MODE_RGB)] = __ccgo_fp(UpsampleRgbLinePair_C)
  58364 	WebPUpsamplers[int32(MODE_BGR)] = __ccgo_fp(UpsampleBgrLinePair_C)
  58365 	WebPUpsamplers[int32(MODE_ARGB)] = __ccgo_fp(UpsampleArgbLinePair_C)
  58366 	WebPUpsamplers[int32(MODE_RGBA_4444)] = __ccgo_fp(UpsampleRgba4444LinePair_C)
  58367 	WebPUpsamplers[int32(MODE_RGB_565)] = __ccgo_fp(UpsampleRgb565LinePair_C)
  58368 	WebPUpsamplers[int32(MODE_Argb)] = __ccgo_fp(UpsampleArgbLinePair_C)
  58369 	WebPUpsamplers[int32(MODE_rgbA_4444)] = __ccgo_fp(UpsampleRgba4444LinePair_C)
  58370 	// If defined, use CPUInfo() to overwrite some pointers with faster versions.
  58371 	if VP8GetCPUInfo != libc.UintptrFromInt32(0) {
  58372 	}
  58373 }
  58374 
  58375 func WebPInitYUV444ConvertersMIPSdspR2(tls *libc.TLS) {
  58376 }
  58377 
  58378 func WebPInitUpsamplersMIPSdspR2(tls *libc.TLS) {
  58379 }
  58380 
  58381 func WebPInitUpsamplersMSA(tls *libc.TLS) {
  58382 }
  58383 
  58384 func WebPInitUpsamplersNEON(tls *libc.TLS) {
  58385 }
  58386 
  58387 func WebPInitYUV444ConvertersSSE2(tls *libc.TLS) {
  58388 }
  58389 
  58390 func WebPInitUpsamplersSSE2(tls *libc.TLS) {
  58391 }
  58392 
  58393 func WebPInitYUV444ConvertersSSE41(tls *libc.TLS) {
  58394 }
  58395 
  58396 func WebPInitUpsamplersSSE41(tls *libc.TLS) {
  58397 }
  58398 
  58399 const SIZE_MAX32 = "_UI64_MAX"
  58400 
  58401 // Copyright 2010 Google Inc. All Rights Reserved.
  58402 //
  58403 // Use of this source code is governed by a BSD-style license
  58404 // that can be found in the COPYING file in the root of the source
  58405 // tree. An additional intellectual property rights grant can be found
  58406 // in the file PATENTS. All contributing project authors may
  58407 // be found in the AUTHORS file in the root of the source tree.
  58408 // -----------------------------------------------------------------------------
  58409 //
  58410 //  Main decoding functions for WebP images.
  58411 //
  58412 // Author: Skal (pascal.massimino@gmail.com)
  58413 
  58414 //-----------------------------------------------------------------------------
  58415 // Plain-C version
  58416 
  58417 // C documentation
  58418 //
  58419 //	// All variants implemented.
  58420 func YuvToRgbRow(tls *libc.TLS, y4 uintptr, u3 uintptr, v5 uintptr, dst uintptr, len1 int32) {
  58421 	var end, v4 uintptr
  58422 	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
  58423 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  58424 	end = dst + uintptr(len1 & ^libc.Int32FromInt32(1) * int32(3))
  58425 	for dst != end {
  58426 		v1 = int32(**(**uint8_t)(__ccgo_up(y4)))
  58427 		v2 = int32(**(**uint8_t)(__ccgo_up(u3)))
  58428 		v3 = int32(**(**uint8_t)(__ccgo_up(v5)))
  58429 		v4 = dst
  58430 		v7 = v1 * int32(19077) >> int32(8)
  58431 		goto _8
  58432 	_8:
  58433 		v9 = v3 * int32(26149) >> int32(8)
  58434 		goto _10
  58435 	_10:
  58436 		v11 = v7 + v9 - int32(14234)
  58437 		if v11 & ^int32(YUV_MASK2) == 0 {
  58438 			v14 = v11 >> int32(YUV_FIX2)
  58439 		} else {
  58440 			if v11 < 0 {
  58441 				v15 = 0
  58442 			} else {
  58443 				v15 = int32(255)
  58444 			}
  58445 			v14 = v15
  58446 		}
  58447 		v12 = v14
  58448 		goto _13
  58449 	_13:
  58450 		v51 = v12
  58451 		goto _6
  58452 	_6:
  58453 		**(**uint8_t)(__ccgo_up(v4)) = uint8(v51)
  58454 		v18 = v1 * int32(19077) >> int32(8)
  58455 		goto _19
  58456 	_19:
  58457 		v20 = v2 * int32(6419) >> int32(8)
  58458 		goto _21
  58459 	_21:
  58460 		v22 = v3 * int32(13320) >> int32(8)
  58461 		goto _23
  58462 	_23:
  58463 		v24 = v18 - v20 - v22 + int32(8708)
  58464 		if v24 & ^int32(YUV_MASK2) == 0 {
  58465 			v27 = v24 >> int32(YUV_FIX2)
  58466 		} else {
  58467 			if v24 < 0 {
  58468 				v28 = 0
  58469 			} else {
  58470 				v28 = int32(255)
  58471 			}
  58472 			v27 = v28
  58473 		}
  58474 		v25 = v27
  58475 		goto _26
  58476 	_26:
  58477 		v16 = v25
  58478 		goto _17
  58479 	_17:
  58480 		**(**uint8_t)(__ccgo_up(v4 + 1)) = uint8(v16)
  58481 		v31 = v1 * int32(19077) >> int32(8)
  58482 		goto _32
  58483 	_32:
  58484 		v33 = v2 * int32(33050) >> int32(8)
  58485 		goto _34
  58486 	_34:
  58487 		v35 = v31 + v33 - int32(17685)
  58488 		if v35 & ^int32(YUV_MASK2) == 0 {
  58489 			v38 = v35 >> int32(YUV_FIX2)
  58490 		} else {
  58491 			if v35 < 0 {
  58492 				v39 = 0
  58493 			} else {
  58494 				v39 = int32(255)
  58495 			}
  58496 			v38 = v39
  58497 		}
  58498 		v36 = v38
  58499 		goto _37
  58500 	_37:
  58501 		v29 = v36
  58502 		goto _30
  58503 	_30:
  58504 		**(**uint8_t)(__ccgo_up(v4 + 2)) = uint8(v29)
  58505 		v1 = int32(**(**uint8_t)(__ccgo_up(y4 + 1)))
  58506 		v2 = int32(**(**uint8_t)(__ccgo_up(u3)))
  58507 		v3 = int32(**(**uint8_t)(__ccgo_up(v5)))
  58508 		v4 = dst + uintptr(libc.Int32FromInt32(3))
  58509 		v7 = v1 * int32(19077) >> int32(8)
  58510 		goto _47
  58511 	_47:
  58512 		v9 = v3 * int32(26149) >> int32(8)
  58513 		goto _49
  58514 	_49:
  58515 		v11 = v7 + v9 - int32(14234)
  58516 		if v11 & ^int32(YUV_MASK2) == 0 {
  58517 			v14 = v11 >> int32(YUV_FIX2)
  58518 		} else {
  58519 			if v11 < 0 {
  58520 				v15 = 0
  58521 			} else {
  58522 				v15 = int32(255)
  58523 			}
  58524 			v14 = v15
  58525 		}
  58526 		v12 = v14
  58527 		goto _52
  58528 	_52:
  58529 		v51 = v12
  58530 		goto _45
  58531 	_45:
  58532 		**(**uint8_t)(__ccgo_up(v4)) = uint8(v51)
  58533 		v18 = v1 * int32(19077) >> int32(8)
  58534 		goto _58
  58535 	_58:
  58536 		v20 = v2 * int32(6419) >> int32(8)
  58537 		goto _60
  58538 	_60:
  58539 		v22 = v3 * int32(13320) >> int32(8)
  58540 		goto _62
  58541 	_62:
  58542 		v24 = v18 - v20 - v22 + int32(8708)
  58543 		if v24 & ^int32(YUV_MASK2) == 0 {
  58544 			v27 = v24 >> int32(YUV_FIX2)
  58545 		} else {
  58546 			if v24 < 0 {
  58547 				v28 = 0
  58548 			} else {
  58549 				v28 = int32(255)
  58550 			}
  58551 			v27 = v28
  58552 		}
  58553 		v25 = v27
  58554 		goto _65
  58555 	_65:
  58556 		v16 = v25
  58557 		goto _56
  58558 	_56:
  58559 		**(**uint8_t)(__ccgo_up(v4 + 1)) = uint8(v16)
  58560 		v31 = v1 * int32(19077) >> int32(8)
  58561 		goto _71
  58562 	_71:
  58563 		v33 = v2 * int32(33050) >> int32(8)
  58564 		goto _73
  58565 	_73:
  58566 		v35 = v31 + v33 - int32(17685)
  58567 		if v35 & ^int32(YUV_MASK2) == 0 {
  58568 			v38 = v35 >> int32(YUV_FIX2)
  58569 		} else {
  58570 			if v35 < 0 {
  58571 				v39 = 0
  58572 			} else {
  58573 				v39 = int32(255)
  58574 			}
  58575 			v38 = v39
  58576 		}
  58577 		v36 = v38
  58578 		goto _76
  58579 	_76:
  58580 		v29 = v36
  58581 		goto _69
  58582 	_69:
  58583 		**(**uint8_t)(__ccgo_up(v4 + 2)) = uint8(v29)
  58584 		y4 = y4 + uintptr(2)
  58585 		u3 = u3 + 1
  58586 		v5 = v5 + 1
  58587 		dst = dst + uintptr(libc.Int32FromInt32(2)*libc.Int32FromInt32(3))
  58588 	}
  58589 	if len1&int32(1) != 0 {
  58590 		v1 = int32(**(**uint8_t)(__ccgo_up(y4)))
  58591 		v2 = int32(**(**uint8_t)(__ccgo_up(u3)))
  58592 		v3 = int32(**(**uint8_t)(__ccgo_up(v5)))
  58593 		v4 = dst
  58594 		v7 = v1 * int32(19077) >> int32(8)
  58595 		goto _86
  58596 	_86:
  58597 		v9 = v3 * int32(26149) >> int32(8)
  58598 		goto _88
  58599 	_88:
  58600 		v11 = v7 + v9 - int32(14234)
  58601 		if v11 & ^int32(YUV_MASK2) == 0 {
  58602 			v14 = v11 >> int32(YUV_FIX2)
  58603 		} else {
  58604 			if v11 < 0 {
  58605 				v15 = 0
  58606 			} else {
  58607 				v15 = int32(255)
  58608 			}
  58609 			v14 = v15
  58610 		}
  58611 		v12 = v14
  58612 		goto _91
  58613 	_91:
  58614 		v51 = v12
  58615 		goto _84
  58616 	_84:
  58617 		**(**uint8_t)(__ccgo_up(v4)) = uint8(v51)
  58618 		v18 = v1 * int32(19077) >> int32(8)
  58619 		goto _97
  58620 	_97:
  58621 		v20 = v2 * int32(6419) >> int32(8)
  58622 		goto _99
  58623 	_99:
  58624 		v22 = v3 * int32(13320) >> int32(8)
  58625 		goto _101
  58626 	_101:
  58627 		v24 = v18 - v20 - v22 + int32(8708)
  58628 		if v24 & ^int32(YUV_MASK2) == 0 {
  58629 			v27 = v24 >> int32(YUV_FIX2)
  58630 		} else {
  58631 			if v24 < 0 {
  58632 				v28 = 0
  58633 			} else {
  58634 				v28 = int32(255)
  58635 			}
  58636 			v27 = v28
  58637 		}
  58638 		v25 = v27
  58639 		goto _104
  58640 	_104:
  58641 		v16 = v25
  58642 		goto _95
  58643 	_95:
  58644 		**(**uint8_t)(__ccgo_up(v4 + 1)) = uint8(v16)
  58645 		v31 = v1 * int32(19077) >> int32(8)
  58646 		goto _110
  58647 	_110:
  58648 		v33 = v2 * int32(33050) >> int32(8)
  58649 		goto _112
  58650 	_112:
  58651 		v35 = v31 + v33 - int32(17685)
  58652 		if v35 & ^int32(YUV_MASK2) == 0 {
  58653 			v38 = v35 >> int32(YUV_FIX2)
  58654 		} else {
  58655 			if v35 < 0 {
  58656 				v39 = 0
  58657 			} else {
  58658 				v39 = int32(255)
  58659 			}
  58660 			v38 = v39
  58661 		}
  58662 		v36 = v38
  58663 		goto _115
  58664 	_115:
  58665 		v29 = v36
  58666 		goto _108
  58667 	_108:
  58668 		**(**uint8_t)(__ccgo_up(v4 + 2)) = uint8(v29)
  58669 	}
  58670 }
  58671 
  58672 func YuvToBgrRow(tls *libc.TLS, y4 uintptr, u3 uintptr, v5 uintptr, dst uintptr, len1 int32) {
  58673 	var end, v4 uintptr
  58674 	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
  58675 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  58676 	end = dst + uintptr(len1 & ^libc.Int32FromInt32(1) * int32(3))
  58677 	for dst != end {
  58678 		v1 = int32(**(**uint8_t)(__ccgo_up(y4)))
  58679 		v2 = int32(**(**uint8_t)(__ccgo_up(u3)))
  58680 		v3 = int32(**(**uint8_t)(__ccgo_up(v5)))
  58681 		v4 = dst
  58682 		v7 = v1 * int32(19077) >> int32(8)
  58683 		goto _8
  58684 	_8:
  58685 		v9 = v2 * int32(33050) >> int32(8)
  58686 		goto _10
  58687 	_10:
  58688 		v11 = v7 + v9 - int32(17685)
  58689 		if v11 & ^int32(YUV_MASK2) == 0 {
  58690 			v14 = v11 >> int32(YUV_FIX2)
  58691 		} else {
  58692 			if v11 < 0 {
  58693 				v15 = 0
  58694 			} else {
  58695 				v15 = int32(255)
  58696 			}
  58697 			v14 = v15
  58698 		}
  58699 		v12 = v14
  58700 		goto _13
  58701 	_13:
  58702 		v51 = v12
  58703 		goto _6
  58704 	_6:
  58705 		**(**uint8_t)(__ccgo_up(v4)) = uint8(v51)
  58706 		v18 = v1 * int32(19077) >> int32(8)
  58707 		goto _19
  58708 	_19:
  58709 		v20 = v2 * int32(6419) >> int32(8)
  58710 		goto _21
  58711 	_21:
  58712 		v22 = v3 * int32(13320) >> int32(8)
  58713 		goto _23
  58714 	_23:
  58715 		v24 = v18 - v20 - v22 + int32(8708)
  58716 		if v24 & ^int32(YUV_MASK2) == 0 {
  58717 			v27 = v24 >> int32(YUV_FIX2)
  58718 		} else {
  58719 			if v24 < 0 {
  58720 				v28 = 0
  58721 			} else {
  58722 				v28 = int32(255)
  58723 			}
  58724 			v27 = v28
  58725 		}
  58726 		v25 = v27
  58727 		goto _26
  58728 	_26:
  58729 		v16 = v25
  58730 		goto _17
  58731 	_17:
  58732 		**(**uint8_t)(__ccgo_up(v4 + 1)) = uint8(v16)
  58733 		v31 = v1 * int32(19077) >> int32(8)
  58734 		goto _32
  58735 	_32:
  58736 		v33 = v3 * int32(26149) >> int32(8)
  58737 		goto _34
  58738 	_34:
  58739 		v35 = v31 + v33 - int32(14234)
  58740 		if v35 & ^int32(YUV_MASK2) == 0 {
  58741 			v38 = v35 >> int32(YUV_FIX2)
  58742 		} else {
  58743 			if v35 < 0 {
  58744 				v39 = 0
  58745 			} else {
  58746 				v39 = int32(255)
  58747 			}
  58748 			v38 = v39
  58749 		}
  58750 		v36 = v38
  58751 		goto _37
  58752 	_37:
  58753 		v29 = v36
  58754 		goto _30
  58755 	_30:
  58756 		**(**uint8_t)(__ccgo_up(v4 + 2)) = uint8(v29)
  58757 		v1 = int32(**(**uint8_t)(__ccgo_up(y4 + 1)))
  58758 		v2 = int32(**(**uint8_t)(__ccgo_up(u3)))
  58759 		v3 = int32(**(**uint8_t)(__ccgo_up(v5)))
  58760 		v4 = dst + uintptr(libc.Int32FromInt32(3))
  58761 		v7 = v1 * int32(19077) >> int32(8)
  58762 		goto _47
  58763 	_47:
  58764 		v9 = v2 * int32(33050) >> int32(8)
  58765 		goto _49
  58766 	_49:
  58767 		v11 = v7 + v9 - int32(17685)
  58768 		if v11 & ^int32(YUV_MASK2) == 0 {
  58769 			v14 = v11 >> int32(YUV_FIX2)
  58770 		} else {
  58771 			if v11 < 0 {
  58772 				v15 = 0
  58773 			} else {
  58774 				v15 = int32(255)
  58775 			}
  58776 			v14 = v15
  58777 		}
  58778 		v12 = v14
  58779 		goto _52
  58780 	_52:
  58781 		v51 = v12
  58782 		goto _45
  58783 	_45:
  58784 		**(**uint8_t)(__ccgo_up(v4)) = uint8(v51)
  58785 		v18 = v1 * int32(19077) >> int32(8)
  58786 		goto _58
  58787 	_58:
  58788 		v20 = v2 * int32(6419) >> int32(8)
  58789 		goto _60
  58790 	_60:
  58791 		v22 = v3 * int32(13320) >> int32(8)
  58792 		goto _62
  58793 	_62:
  58794 		v24 = v18 - v20 - v22 + int32(8708)
  58795 		if v24 & ^int32(YUV_MASK2) == 0 {
  58796 			v27 = v24 >> int32(YUV_FIX2)
  58797 		} else {
  58798 			if v24 < 0 {
  58799 				v28 = 0
  58800 			} else {
  58801 				v28 = int32(255)
  58802 			}
  58803 			v27 = v28
  58804 		}
  58805 		v25 = v27
  58806 		goto _65
  58807 	_65:
  58808 		v16 = v25
  58809 		goto _56
  58810 	_56:
  58811 		**(**uint8_t)(__ccgo_up(v4 + 1)) = uint8(v16)
  58812 		v31 = v1 * int32(19077) >> int32(8)
  58813 		goto _71
  58814 	_71:
  58815 		v33 = v3 * int32(26149) >> int32(8)
  58816 		goto _73
  58817 	_73:
  58818 		v35 = v31 + v33 - int32(14234)
  58819 		if v35 & ^int32(YUV_MASK2) == 0 {
  58820 			v38 = v35 >> int32(YUV_FIX2)
  58821 		} else {
  58822 			if v35 < 0 {
  58823 				v39 = 0
  58824 			} else {
  58825 				v39 = int32(255)
  58826 			}
  58827 			v38 = v39
  58828 		}
  58829 		v36 = v38
  58830 		goto _76
  58831 	_76:
  58832 		v29 = v36
  58833 		goto _69
  58834 	_69:
  58835 		**(**uint8_t)(__ccgo_up(v4 + 2)) = uint8(v29)
  58836 		y4 = y4 + uintptr(2)
  58837 		u3 = u3 + 1
  58838 		v5 = v5 + 1
  58839 		dst = dst + uintptr(libc.Int32FromInt32(2)*libc.Int32FromInt32(3))
  58840 	}
  58841 	if len1&int32(1) != 0 {
  58842 		v1 = int32(**(**uint8_t)(__ccgo_up(y4)))
  58843 		v2 = int32(**(**uint8_t)(__ccgo_up(u3)))
  58844 		v3 = int32(**(**uint8_t)(__ccgo_up(v5)))
  58845 		v4 = dst
  58846 		v7 = v1 * int32(19077) >> int32(8)
  58847 		goto _86
  58848 	_86:
  58849 		v9 = v2 * int32(33050) >> int32(8)
  58850 		goto _88
  58851 	_88:
  58852 		v11 = v7 + v9 - int32(17685)
  58853 		if v11 & ^int32(YUV_MASK2) == 0 {
  58854 			v14 = v11 >> int32(YUV_FIX2)
  58855 		} else {
  58856 			if v11 < 0 {
  58857 				v15 = 0
  58858 			} else {
  58859 				v15 = int32(255)
  58860 			}
  58861 			v14 = v15
  58862 		}
  58863 		v12 = v14
  58864 		goto _91
  58865 	_91:
  58866 		v51 = v12
  58867 		goto _84
  58868 	_84:
  58869 		**(**uint8_t)(__ccgo_up(v4)) = uint8(v51)
  58870 		v18 = v1 * int32(19077) >> int32(8)
  58871 		goto _97
  58872 	_97:
  58873 		v20 = v2 * int32(6419) >> int32(8)
  58874 		goto _99
  58875 	_99:
  58876 		v22 = v3 * int32(13320) >> int32(8)
  58877 		goto _101
  58878 	_101:
  58879 		v24 = v18 - v20 - v22 + int32(8708)
  58880 		if v24 & ^int32(YUV_MASK2) == 0 {
  58881 			v27 = v24 >> int32(YUV_FIX2)
  58882 		} else {
  58883 			if v24 < 0 {
  58884 				v28 = 0
  58885 			} else {
  58886 				v28 = int32(255)
  58887 			}
  58888 			v27 = v28
  58889 		}
  58890 		v25 = v27
  58891 		goto _104
  58892 	_104:
  58893 		v16 = v25
  58894 		goto _95
  58895 	_95:
  58896 		**(**uint8_t)(__ccgo_up(v4 + 1)) = uint8(v16)
  58897 		v31 = v1 * int32(19077) >> int32(8)
  58898 		goto _110
  58899 	_110:
  58900 		v33 = v3 * int32(26149) >> int32(8)
  58901 		goto _112
  58902 	_112:
  58903 		v35 = v31 + v33 - int32(14234)
  58904 		if v35 & ^int32(YUV_MASK2) == 0 {
  58905 			v38 = v35 >> int32(YUV_FIX2)
  58906 		} else {
  58907 			if v35 < 0 {
  58908 				v39 = 0
  58909 			} else {
  58910 				v39 = int32(255)
  58911 			}
  58912 			v38 = v39
  58913 		}
  58914 		v36 = v38
  58915 		goto _115
  58916 	_115:
  58917 		v29 = v36
  58918 		goto _108
  58919 	_108:
  58920 		**(**uint8_t)(__ccgo_up(v4 + 2)) = uint8(v29)
  58921 	}
  58922 }
  58923 
  58924 func YuvToRgbaRow(tls *libc.TLS, y5 uintptr, u4 uintptr, v6 uintptr, dst uintptr, len1 int32) {
  58925 	var end, v1, v5 uintptr
  58926 	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
  58927 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  58928 	end = dst + uintptr(len1 & ^libc.Int32FromInt32(1) * int32(4))
  58929 	for dst != end {
  58930 		v1 = dst
  58931 		v2 = int32(**(**uint8_t)(__ccgo_up(y5)))
  58932 		v3 = int32(**(**uint8_t)(__ccgo_up(u4)))
  58933 		v4 = int32(**(**uint8_t)(__ccgo_up(v6)))
  58934 		v5 = v1
  58935 		v8 = v2 * int32(19077) >> int32(8)
  58936 		goto _9
  58937 	_9:
  58938 		v10 = v4 * int32(26149) >> int32(8)
  58939 		goto _11
  58940 	_11:
  58941 		v12 = v8 + v10 - int32(14234)
  58942 		if v12 & ^int32(YUV_MASK2) == 0 {
  58943 			v15 = v12 >> int32(YUV_FIX2)
  58944 		} else {
  58945 			if v12 < 0 {
  58946 				v16 = 0
  58947 			} else {
  58948 				v16 = int32(255)
  58949 			}
  58950 			v15 = v16
  58951 		}
  58952 		v13 = v15
  58953 		goto _14
  58954 	_14:
  58955 		v61 = v13
  58956 		goto _7
  58957 	_7:
  58958 		**(**uint8_t)(__ccgo_up(v5)) = uint8(v61)
  58959 		v19 = v2 * int32(19077) >> int32(8)
  58960 		goto _20
  58961 	_20:
  58962 		v21 = v3 * int32(6419) >> int32(8)
  58963 		goto _22
  58964 	_22:
  58965 		v23 = v4 * int32(13320) >> int32(8)
  58966 		goto _24
  58967 	_24:
  58968 		v25 = v19 - v21 - v23 + int32(8708)
  58969 		if v25 & ^int32(YUV_MASK2) == 0 {
  58970 			v28 = v25 >> int32(YUV_FIX2)
  58971 		} else {
  58972 			if v25 < 0 {
  58973 				v29 = 0
  58974 			} else {
  58975 				v29 = int32(255)
  58976 			}
  58977 			v28 = v29
  58978 		}
  58979 		v26 = v28
  58980 		goto _27
  58981 	_27:
  58982 		v17 = v26
  58983 		goto _18
  58984 	_18:
  58985 		**(**uint8_t)(__ccgo_up(v5 + 1)) = uint8(v17)
  58986 		v32 = v2 * int32(19077) >> int32(8)
  58987 		goto _33
  58988 	_33:
  58989 		v34 = v3 * int32(33050) >> int32(8)
  58990 		goto _35
  58991 	_35:
  58992 		v36 = v32 + v34 - int32(17685)
  58993 		if v36 & ^int32(YUV_MASK2) == 0 {
  58994 			v39 = v36 >> int32(YUV_FIX2)
  58995 		} else {
  58996 			if v36 < 0 {
  58997 				v40 = 0
  58998 			} else {
  58999 				v40 = int32(255)
  59000 			}
  59001 			v39 = v40
  59002 		}
  59003 		v37 = v39
  59004 		goto _38
  59005 	_38:
  59006 		v30 = v37
  59007 		goto _31
  59008 	_31:
  59009 		**(**uint8_t)(__ccgo_up(v5 + 2)) = uint8(v30)
  59010 		**(**uint8_t)(__ccgo_up(v1 + 3)) = uint8(0xff)
  59011 		v1 = dst + uintptr(libc.Int32FromInt32(4))
  59012 		v2 = int32(**(**uint8_t)(__ccgo_up(y5 + 1)))
  59013 		v3 = int32(**(**uint8_t)(__ccgo_up(u4)))
  59014 		v4 = int32(**(**uint8_t)(__ccgo_up(v6)))
  59015 		v5 = v1
  59016 		v8 = v2 * int32(19077) >> int32(8)
  59017 		goto _49
  59018 	_49:
  59019 		v10 = v4 * int32(26149) >> int32(8)
  59020 		goto _51
  59021 	_51:
  59022 		v12 = v8 + v10 - int32(14234)
  59023 		if v12 & ^int32(YUV_MASK2) == 0 {
  59024 			v15 = v12 >> int32(YUV_FIX2)
  59025 		} else {
  59026 			if v12 < 0 {
  59027 				v16 = 0
  59028 			} else {
  59029 				v16 = int32(255)
  59030 			}
  59031 			v15 = v16
  59032 		}
  59033 		v13 = v15
  59034 		goto _54
  59035 	_54:
  59036 		v61 = v13
  59037 		goto _47
  59038 	_47:
  59039 		**(**uint8_t)(__ccgo_up(v5)) = uint8(v61)
  59040 		v19 = v2 * int32(19077) >> int32(8)
  59041 		goto _60
  59042 	_60:
  59043 		v21 = v3 * int32(6419) >> int32(8)
  59044 		goto _62
  59045 	_62:
  59046 		v23 = v4 * int32(13320) >> int32(8)
  59047 		goto _64
  59048 	_64:
  59049 		v25 = v19 - v21 - v23 + int32(8708)
  59050 		if v25 & ^int32(YUV_MASK2) == 0 {
  59051 			v28 = v25 >> int32(YUV_FIX2)
  59052 		} else {
  59053 			if v25 < 0 {
  59054 				v29 = 0
  59055 			} else {
  59056 				v29 = int32(255)
  59057 			}
  59058 			v28 = v29
  59059 		}
  59060 		v26 = v28
  59061 		goto _67
  59062 	_67:
  59063 		v17 = v26
  59064 		goto _58
  59065 	_58:
  59066 		**(**uint8_t)(__ccgo_up(v5 + 1)) = uint8(v17)
  59067 		v32 = v2 * int32(19077) >> int32(8)
  59068 		goto _73
  59069 	_73:
  59070 		v34 = v3 * int32(33050) >> int32(8)
  59071 		goto _75
  59072 	_75:
  59073 		v36 = v32 + v34 - int32(17685)
  59074 		if v36 & ^int32(YUV_MASK2) == 0 {
  59075 			v39 = v36 >> int32(YUV_FIX2)
  59076 		} else {
  59077 			if v36 < 0 {
  59078 				v40 = 0
  59079 			} else {
  59080 				v40 = int32(255)
  59081 			}
  59082 			v39 = v40
  59083 		}
  59084 		v37 = v39
  59085 		goto _78
  59086 	_78:
  59087 		v30 = v37
  59088 		goto _71
  59089 	_71:
  59090 		**(**uint8_t)(__ccgo_up(v5 + 2)) = uint8(v30)
  59091 		**(**uint8_t)(__ccgo_up(v1 + 3)) = uint8(0xff)
  59092 		y5 = y5 + uintptr(2)
  59093 		u4 = u4 + 1
  59094 		v6 = v6 + 1
  59095 		dst = dst + uintptr(libc.Int32FromInt32(2)*libc.Int32FromInt32(4))
  59096 	}
  59097 	if len1&int32(1) != 0 {
  59098 		v1 = dst
  59099 		v2 = int32(**(**uint8_t)(__ccgo_up(y5)))
  59100 		v3 = int32(**(**uint8_t)(__ccgo_up(u4)))
  59101 		v4 = int32(**(**uint8_t)(__ccgo_up(v6)))
  59102 		v5 = v1
  59103 		v8 = v2 * int32(19077) >> int32(8)
  59104 		goto _89
  59105 	_89:
  59106 		v10 = v4 * int32(26149) >> int32(8)
  59107 		goto _91
  59108 	_91:
  59109 		v12 = v8 + v10 - int32(14234)
  59110 		if v12 & ^int32(YUV_MASK2) == 0 {
  59111 			v15 = v12 >> int32(YUV_FIX2)
  59112 		} else {
  59113 			if v12 < 0 {
  59114 				v16 = 0
  59115 			} else {
  59116 				v16 = int32(255)
  59117 			}
  59118 			v15 = v16
  59119 		}
  59120 		v13 = v15
  59121 		goto _94
  59122 	_94:
  59123 		v61 = v13
  59124 		goto _87
  59125 	_87:
  59126 		**(**uint8_t)(__ccgo_up(v5)) = uint8(v61)
  59127 		v19 = v2 * int32(19077) >> int32(8)
  59128 		goto _100
  59129 	_100:
  59130 		v21 = v3 * int32(6419) >> int32(8)
  59131 		goto _102
  59132 	_102:
  59133 		v23 = v4 * int32(13320) >> int32(8)
  59134 		goto _104
  59135 	_104:
  59136 		v25 = v19 - v21 - v23 + int32(8708)
  59137 		if v25 & ^int32(YUV_MASK2) == 0 {
  59138 			v28 = v25 >> int32(YUV_FIX2)
  59139 		} else {
  59140 			if v25 < 0 {
  59141 				v29 = 0
  59142 			} else {
  59143 				v29 = int32(255)
  59144 			}
  59145 			v28 = v29
  59146 		}
  59147 		v26 = v28
  59148 		goto _107
  59149 	_107:
  59150 		v17 = v26
  59151 		goto _98
  59152 	_98:
  59153 		**(**uint8_t)(__ccgo_up(v5 + 1)) = uint8(v17)
  59154 		v32 = v2 * int32(19077) >> int32(8)
  59155 		goto _113
  59156 	_113:
  59157 		v34 = v3 * int32(33050) >> int32(8)
  59158 		goto _115
  59159 	_115:
  59160 		v36 = v32 + v34 - int32(17685)
  59161 		if v36 & ^int32(YUV_MASK2) == 0 {
  59162 			v39 = v36 >> int32(YUV_FIX2)
  59163 		} else {
  59164 			if v36 < 0 {
  59165 				v40 = 0
  59166 			} else {
  59167 				v40 = int32(255)
  59168 			}
  59169 			v39 = v40
  59170 		}
  59171 		v37 = v39
  59172 		goto _118
  59173 	_118:
  59174 		v30 = v37
  59175 		goto _111
  59176 	_111:
  59177 		**(**uint8_t)(__ccgo_up(v5 + 2)) = uint8(v30)
  59178 		**(**uint8_t)(__ccgo_up(v1 + 3)) = uint8(0xff)
  59179 	}
  59180 }
  59181 
  59182 func YuvToBgraRow(tls *libc.TLS, y5 uintptr, u4 uintptr, v6 uintptr, dst uintptr, len1 int32) {
  59183 	var end, v1, v5 uintptr
  59184 	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
  59185 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  59186 	end = dst + uintptr(len1 & ^libc.Int32FromInt32(1) * int32(4))
  59187 	for dst != end {
  59188 		v1 = dst
  59189 		v2 = int32(**(**uint8_t)(__ccgo_up(y5)))
  59190 		v3 = int32(**(**uint8_t)(__ccgo_up(u4)))
  59191 		v4 = int32(**(**uint8_t)(__ccgo_up(v6)))
  59192 		v5 = v1
  59193 		v8 = v2 * int32(19077) >> int32(8)
  59194 		goto _9
  59195 	_9:
  59196 		v10 = v3 * int32(33050) >> int32(8)
  59197 		goto _11
  59198 	_11:
  59199 		v12 = v8 + v10 - int32(17685)
  59200 		if v12 & ^int32(YUV_MASK2) == 0 {
  59201 			v15 = v12 >> int32(YUV_FIX2)
  59202 		} else {
  59203 			if v12 < 0 {
  59204 				v16 = 0
  59205 			} else {
  59206 				v16 = int32(255)
  59207 			}
  59208 			v15 = v16
  59209 		}
  59210 		v13 = v15
  59211 		goto _14
  59212 	_14:
  59213 		v61 = v13
  59214 		goto _7
  59215 	_7:
  59216 		**(**uint8_t)(__ccgo_up(v5)) = uint8(v61)
  59217 		v19 = v2 * int32(19077) >> int32(8)
  59218 		goto _20
  59219 	_20:
  59220 		v21 = v3 * int32(6419) >> int32(8)
  59221 		goto _22
  59222 	_22:
  59223 		v23 = v4 * int32(13320) >> int32(8)
  59224 		goto _24
  59225 	_24:
  59226 		v25 = v19 - v21 - v23 + int32(8708)
  59227 		if v25 & ^int32(YUV_MASK2) == 0 {
  59228 			v28 = v25 >> int32(YUV_FIX2)
  59229 		} else {
  59230 			if v25 < 0 {
  59231 				v29 = 0
  59232 			} else {
  59233 				v29 = int32(255)
  59234 			}
  59235 			v28 = v29
  59236 		}
  59237 		v26 = v28
  59238 		goto _27
  59239 	_27:
  59240 		v17 = v26
  59241 		goto _18
  59242 	_18:
  59243 		**(**uint8_t)(__ccgo_up(v5 + 1)) = uint8(v17)
  59244 		v32 = v2 * int32(19077) >> int32(8)
  59245 		goto _33
  59246 	_33:
  59247 		v34 = v4 * int32(26149) >> int32(8)
  59248 		goto _35
  59249 	_35:
  59250 		v36 = v32 + v34 - int32(14234)
  59251 		if v36 & ^int32(YUV_MASK2) == 0 {
  59252 			v39 = v36 >> int32(YUV_FIX2)
  59253 		} else {
  59254 			if v36 < 0 {
  59255 				v40 = 0
  59256 			} else {
  59257 				v40 = int32(255)
  59258 			}
  59259 			v39 = v40
  59260 		}
  59261 		v37 = v39
  59262 		goto _38
  59263 	_38:
  59264 		v30 = v37
  59265 		goto _31
  59266 	_31:
  59267 		**(**uint8_t)(__ccgo_up(v5 + 2)) = uint8(v30)
  59268 		**(**uint8_t)(__ccgo_up(v1 + 3)) = uint8(0xff)
  59269 		v1 = dst + uintptr(libc.Int32FromInt32(4))
  59270 		v2 = int32(**(**uint8_t)(__ccgo_up(y5 + 1)))
  59271 		v3 = int32(**(**uint8_t)(__ccgo_up(u4)))
  59272 		v4 = int32(**(**uint8_t)(__ccgo_up(v6)))
  59273 		v5 = v1
  59274 		v8 = v2 * int32(19077) >> int32(8)
  59275 		goto _49
  59276 	_49:
  59277 		v10 = v3 * int32(33050) >> int32(8)
  59278 		goto _51
  59279 	_51:
  59280 		v12 = v8 + v10 - int32(17685)
  59281 		if v12 & ^int32(YUV_MASK2) == 0 {
  59282 			v15 = v12 >> int32(YUV_FIX2)
  59283 		} else {
  59284 			if v12 < 0 {
  59285 				v16 = 0
  59286 			} else {
  59287 				v16 = int32(255)
  59288 			}
  59289 			v15 = v16
  59290 		}
  59291 		v13 = v15
  59292 		goto _54
  59293 	_54:
  59294 		v61 = v13
  59295 		goto _47
  59296 	_47:
  59297 		**(**uint8_t)(__ccgo_up(v5)) = uint8(v61)
  59298 		v19 = v2 * int32(19077) >> int32(8)
  59299 		goto _60
  59300 	_60:
  59301 		v21 = v3 * int32(6419) >> int32(8)
  59302 		goto _62
  59303 	_62:
  59304 		v23 = v4 * int32(13320) >> int32(8)
  59305 		goto _64
  59306 	_64:
  59307 		v25 = v19 - v21 - v23 + int32(8708)
  59308 		if v25 & ^int32(YUV_MASK2) == 0 {
  59309 			v28 = v25 >> int32(YUV_FIX2)
  59310 		} else {
  59311 			if v25 < 0 {
  59312 				v29 = 0
  59313 			} else {
  59314 				v29 = int32(255)
  59315 			}
  59316 			v28 = v29
  59317 		}
  59318 		v26 = v28
  59319 		goto _67
  59320 	_67:
  59321 		v17 = v26
  59322 		goto _58
  59323 	_58:
  59324 		**(**uint8_t)(__ccgo_up(v5 + 1)) = uint8(v17)
  59325 		v32 = v2 * int32(19077) >> int32(8)
  59326 		goto _73
  59327 	_73:
  59328 		v34 = v4 * int32(26149) >> int32(8)
  59329 		goto _75
  59330 	_75:
  59331 		v36 = v32 + v34 - int32(14234)
  59332 		if v36 & ^int32(YUV_MASK2) == 0 {
  59333 			v39 = v36 >> int32(YUV_FIX2)
  59334 		} else {
  59335 			if v36 < 0 {
  59336 				v40 = 0
  59337 			} else {
  59338 				v40 = int32(255)
  59339 			}
  59340 			v39 = v40
  59341 		}
  59342 		v37 = v39
  59343 		goto _78
  59344 	_78:
  59345 		v30 = v37
  59346 		goto _71
  59347 	_71:
  59348 		**(**uint8_t)(__ccgo_up(v5 + 2)) = uint8(v30)
  59349 		**(**uint8_t)(__ccgo_up(v1 + 3)) = uint8(0xff)
  59350 		y5 = y5 + uintptr(2)
  59351 		u4 = u4 + 1
  59352 		v6 = v6 + 1
  59353 		dst = dst + uintptr(libc.Int32FromInt32(2)*libc.Int32FromInt32(4))
  59354 	}
  59355 	if len1&int32(1) != 0 {
  59356 		v1 = dst
  59357 		v2 = int32(**(**uint8_t)(__ccgo_up(y5)))
  59358 		v3 = int32(**(**uint8_t)(__ccgo_up(u4)))
  59359 		v4 = int32(**(**uint8_t)(__ccgo_up(v6)))
  59360 		v5 = v1
  59361 		v8 = v2 * int32(19077) >> int32(8)
  59362 		goto _89
  59363 	_89:
  59364 		v10 = v3 * int32(33050) >> int32(8)
  59365 		goto _91
  59366 	_91:
  59367 		v12 = v8 + v10 - int32(17685)
  59368 		if v12 & ^int32(YUV_MASK2) == 0 {
  59369 			v15 = v12 >> int32(YUV_FIX2)
  59370 		} else {
  59371 			if v12 < 0 {
  59372 				v16 = 0
  59373 			} else {
  59374 				v16 = int32(255)
  59375 			}
  59376 			v15 = v16
  59377 		}
  59378 		v13 = v15
  59379 		goto _94
  59380 	_94:
  59381 		v61 = v13
  59382 		goto _87
  59383 	_87:
  59384 		**(**uint8_t)(__ccgo_up(v5)) = uint8(v61)
  59385 		v19 = v2 * int32(19077) >> int32(8)
  59386 		goto _100
  59387 	_100:
  59388 		v21 = v3 * int32(6419) >> int32(8)
  59389 		goto _102
  59390 	_102:
  59391 		v23 = v4 * int32(13320) >> int32(8)
  59392 		goto _104
  59393 	_104:
  59394 		v25 = v19 - v21 - v23 + int32(8708)
  59395 		if v25 & ^int32(YUV_MASK2) == 0 {
  59396 			v28 = v25 >> int32(YUV_FIX2)
  59397 		} else {
  59398 			if v25 < 0 {
  59399 				v29 = 0
  59400 			} else {
  59401 				v29 = int32(255)
  59402 			}
  59403 			v28 = v29
  59404 		}
  59405 		v26 = v28
  59406 		goto _107
  59407 	_107:
  59408 		v17 = v26
  59409 		goto _98
  59410 	_98:
  59411 		**(**uint8_t)(__ccgo_up(v5 + 1)) = uint8(v17)
  59412 		v32 = v2 * int32(19077) >> int32(8)
  59413 		goto _113
  59414 	_113:
  59415 		v34 = v4 * int32(26149) >> int32(8)
  59416 		goto _115
  59417 	_115:
  59418 		v36 = v32 + v34 - int32(14234)
  59419 		if v36 & ^int32(YUV_MASK2) == 0 {
  59420 			v39 = v36 >> int32(YUV_FIX2)
  59421 		} else {
  59422 			if v36 < 0 {
  59423 				v40 = 0
  59424 			} else {
  59425 				v40 = int32(255)
  59426 			}
  59427 			v39 = v40
  59428 		}
  59429 		v37 = v39
  59430 		goto _118
  59431 	_118:
  59432 		v30 = v37
  59433 		goto _111
  59434 	_111:
  59435 		**(**uint8_t)(__ccgo_up(v5 + 2)) = uint8(v30)
  59436 		**(**uint8_t)(__ccgo_up(v1 + 3)) = uint8(0xff)
  59437 	}
  59438 }
  59439 
  59440 func YuvToArgbRow(tls *libc.TLS, y5 uintptr, u4 uintptr, v6 uintptr, dst uintptr, len1 int32) {
  59441 	var end, v1, v5 uintptr
  59442 	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
  59443 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  59444 	end = dst + uintptr(len1 & ^libc.Int32FromInt32(1) * int32(4))
  59445 	for dst != end {
  59446 		v1 = dst
  59447 		**(**uint8_t)(__ccgo_up(v1)) = uint8(0xff)
  59448 		v2 = int32(**(**uint8_t)(__ccgo_up(y5)))
  59449 		v3 = int32(**(**uint8_t)(__ccgo_up(u4)))
  59450 		v4 = int32(**(**uint8_t)(__ccgo_up(v6)))
  59451 		v5 = v1 + uintptr(1)
  59452 		v8 = v2 * int32(19077) >> int32(8)
  59453 		goto _9
  59454 	_9:
  59455 		v10 = v4 * int32(26149) >> int32(8)
  59456 		goto _11
  59457 	_11:
  59458 		v12 = v8 + v10 - int32(14234)
  59459 		if v12 & ^int32(YUV_MASK2) == 0 {
  59460 			v15 = v12 >> int32(YUV_FIX2)
  59461 		} else {
  59462 			if v12 < 0 {
  59463 				v16 = 0
  59464 			} else {
  59465 				v16 = int32(255)
  59466 			}
  59467 			v15 = v16
  59468 		}
  59469 		v13 = v15
  59470 		goto _14
  59471 	_14:
  59472 		v61 = v13
  59473 		goto _7
  59474 	_7:
  59475 		**(**uint8_t)(__ccgo_up(v5)) = uint8(v61)
  59476 		v19 = v2 * int32(19077) >> int32(8)
  59477 		goto _20
  59478 	_20:
  59479 		v21 = v3 * int32(6419) >> int32(8)
  59480 		goto _22
  59481 	_22:
  59482 		v23 = v4 * int32(13320) >> int32(8)
  59483 		goto _24
  59484 	_24:
  59485 		v25 = v19 - v21 - v23 + int32(8708)
  59486 		if v25 & ^int32(YUV_MASK2) == 0 {
  59487 			v28 = v25 >> int32(YUV_FIX2)
  59488 		} else {
  59489 			if v25 < 0 {
  59490 				v29 = 0
  59491 			} else {
  59492 				v29 = int32(255)
  59493 			}
  59494 			v28 = v29
  59495 		}
  59496 		v26 = v28
  59497 		goto _27
  59498 	_27:
  59499 		v17 = v26
  59500 		goto _18
  59501 	_18:
  59502 		**(**uint8_t)(__ccgo_up(v5 + 1)) = uint8(v17)
  59503 		v32 = v2 * int32(19077) >> int32(8)
  59504 		goto _33
  59505 	_33:
  59506 		v34 = v3 * int32(33050) >> int32(8)
  59507 		goto _35
  59508 	_35:
  59509 		v36 = v32 + v34 - int32(17685)
  59510 		if v36 & ^int32(YUV_MASK2) == 0 {
  59511 			v39 = v36 >> int32(YUV_FIX2)
  59512 		} else {
  59513 			if v36 < 0 {
  59514 				v40 = 0
  59515 			} else {
  59516 				v40 = int32(255)
  59517 			}
  59518 			v39 = v40
  59519 		}
  59520 		v37 = v39
  59521 		goto _38
  59522 	_38:
  59523 		v30 = v37
  59524 		goto _31
  59525 	_31:
  59526 		**(**uint8_t)(__ccgo_up(v5 + 2)) = uint8(v30)
  59527 		v1 = dst + uintptr(libc.Int32FromInt32(4))
  59528 		**(**uint8_t)(__ccgo_up(v1)) = uint8(0xff)
  59529 		v2 = int32(**(**uint8_t)(__ccgo_up(y5 + 1)))
  59530 		v3 = int32(**(**uint8_t)(__ccgo_up(u4)))
  59531 		v4 = int32(**(**uint8_t)(__ccgo_up(v6)))
  59532 		v5 = v1 + uintptr(1)
  59533 		v8 = v2 * int32(19077) >> int32(8)
  59534 		goto _49
  59535 	_49:
  59536 		v10 = v4 * int32(26149) >> int32(8)
  59537 		goto _51
  59538 	_51:
  59539 		v12 = v8 + v10 - int32(14234)
  59540 		if v12 & ^int32(YUV_MASK2) == 0 {
  59541 			v15 = v12 >> int32(YUV_FIX2)
  59542 		} else {
  59543 			if v12 < 0 {
  59544 				v16 = 0
  59545 			} else {
  59546 				v16 = int32(255)
  59547 			}
  59548 			v15 = v16
  59549 		}
  59550 		v13 = v15
  59551 		goto _54
  59552 	_54:
  59553 		v61 = v13
  59554 		goto _47
  59555 	_47:
  59556 		**(**uint8_t)(__ccgo_up(v5)) = uint8(v61)
  59557 		v19 = v2 * int32(19077) >> int32(8)
  59558 		goto _60
  59559 	_60:
  59560 		v21 = v3 * int32(6419) >> int32(8)
  59561 		goto _62
  59562 	_62:
  59563 		v23 = v4 * int32(13320) >> int32(8)
  59564 		goto _64
  59565 	_64:
  59566 		v25 = v19 - v21 - v23 + int32(8708)
  59567 		if v25 & ^int32(YUV_MASK2) == 0 {
  59568 			v28 = v25 >> int32(YUV_FIX2)
  59569 		} else {
  59570 			if v25 < 0 {
  59571 				v29 = 0
  59572 			} else {
  59573 				v29 = int32(255)
  59574 			}
  59575 			v28 = v29
  59576 		}
  59577 		v26 = v28
  59578 		goto _67
  59579 	_67:
  59580 		v17 = v26
  59581 		goto _58
  59582 	_58:
  59583 		**(**uint8_t)(__ccgo_up(v5 + 1)) = uint8(v17)
  59584 		v32 = v2 * int32(19077) >> int32(8)
  59585 		goto _73
  59586 	_73:
  59587 		v34 = v3 * int32(33050) >> int32(8)
  59588 		goto _75
  59589 	_75:
  59590 		v36 = v32 + v34 - int32(17685)
  59591 		if v36 & ^int32(YUV_MASK2) == 0 {
  59592 			v39 = v36 >> int32(YUV_FIX2)
  59593 		} else {
  59594 			if v36 < 0 {
  59595 				v40 = 0
  59596 			} else {
  59597 				v40 = int32(255)
  59598 			}
  59599 			v39 = v40
  59600 		}
  59601 		v37 = v39
  59602 		goto _78
  59603 	_78:
  59604 		v30 = v37
  59605 		goto _71
  59606 	_71:
  59607 		**(**uint8_t)(__ccgo_up(v5 + 2)) = uint8(v30)
  59608 		y5 = y5 + uintptr(2)
  59609 		u4 = u4 + 1
  59610 		v6 = v6 + 1
  59611 		dst = dst + uintptr(libc.Int32FromInt32(2)*libc.Int32FromInt32(4))
  59612 	}
  59613 	if len1&int32(1) != 0 {
  59614 		v1 = dst
  59615 		**(**uint8_t)(__ccgo_up(v1)) = uint8(0xff)
  59616 		v2 = int32(**(**uint8_t)(__ccgo_up(y5)))
  59617 		v3 = int32(**(**uint8_t)(__ccgo_up(u4)))
  59618 		v4 = int32(**(**uint8_t)(__ccgo_up(v6)))
  59619 		v5 = v1 + uintptr(1)
  59620 		v8 = v2 * int32(19077) >> int32(8)
  59621 		goto _89
  59622 	_89:
  59623 		v10 = v4 * int32(26149) >> int32(8)
  59624 		goto _91
  59625 	_91:
  59626 		v12 = v8 + v10 - int32(14234)
  59627 		if v12 & ^int32(YUV_MASK2) == 0 {
  59628 			v15 = v12 >> int32(YUV_FIX2)
  59629 		} else {
  59630 			if v12 < 0 {
  59631 				v16 = 0
  59632 			} else {
  59633 				v16 = int32(255)
  59634 			}
  59635 			v15 = v16
  59636 		}
  59637 		v13 = v15
  59638 		goto _94
  59639 	_94:
  59640 		v61 = v13
  59641 		goto _87
  59642 	_87:
  59643 		**(**uint8_t)(__ccgo_up(v5)) = uint8(v61)
  59644 		v19 = v2 * int32(19077) >> int32(8)
  59645 		goto _100
  59646 	_100:
  59647 		v21 = v3 * int32(6419) >> int32(8)
  59648 		goto _102
  59649 	_102:
  59650 		v23 = v4 * int32(13320) >> int32(8)
  59651 		goto _104
  59652 	_104:
  59653 		v25 = v19 - v21 - v23 + int32(8708)
  59654 		if v25 & ^int32(YUV_MASK2) == 0 {
  59655 			v28 = v25 >> int32(YUV_FIX2)
  59656 		} else {
  59657 			if v25 < 0 {
  59658 				v29 = 0
  59659 			} else {
  59660 				v29 = int32(255)
  59661 			}
  59662 			v28 = v29
  59663 		}
  59664 		v26 = v28
  59665 		goto _107
  59666 	_107:
  59667 		v17 = v26
  59668 		goto _98
  59669 	_98:
  59670 		**(**uint8_t)(__ccgo_up(v5 + 1)) = uint8(v17)
  59671 		v32 = v2 * int32(19077) >> int32(8)
  59672 		goto _113
  59673 	_113:
  59674 		v34 = v3 * int32(33050) >> int32(8)
  59675 		goto _115
  59676 	_115:
  59677 		v36 = v32 + v34 - int32(17685)
  59678 		if v36 & ^int32(YUV_MASK2) == 0 {
  59679 			v39 = v36 >> int32(YUV_FIX2)
  59680 		} else {
  59681 			if v36 < 0 {
  59682 				v40 = 0
  59683 			} else {
  59684 				v40 = int32(255)
  59685 			}
  59686 			v39 = v40
  59687 		}
  59688 		v37 = v39
  59689 		goto _118
  59690 	_118:
  59691 		v30 = v37
  59692 		goto _111
  59693 	_111:
  59694 		**(**uint8_t)(__ccgo_up(v5 + 2)) = uint8(v30)
  59695 	}
  59696 }
  59697 
  59698 func YuvToRgba4444Row(tls *libc.TLS, y4 uintptr, u3 uintptr, v5 uintptr, dst uintptr, len1 int32) {
  59699 	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
  59700 	var end, v4 uintptr
  59701 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  59702 	end = dst + uintptr(len1 & ^libc.Int32FromInt32(1) * int32(2))
  59703 	for dst != end {
  59704 		v1 = int32(**(**uint8_t)(__ccgo_up(y4)))
  59705 		v2 = int32(**(**uint8_t)(__ccgo_up(u3)))
  59706 		v3 = int32(**(**uint8_t)(__ccgo_up(v5)))
  59707 		v4 = dst
  59708 		v7 = v1 * int32(19077) >> int32(8)
  59709 		goto _8
  59710 	_8:
  59711 		v9 = v3 * int32(26149) >> int32(8)
  59712 		goto _10
  59713 	_10:
  59714 		v11 = v7 + v9 - int32(14234)
  59715 		if v11 & ^int32(YUV_MASK2) == 0 {
  59716 			v14 = v11 >> int32(YUV_FIX2)
  59717 		} else {
  59718 			if v11 < 0 {
  59719 				v15 = 0
  59720 			} else {
  59721 				v15 = int32(255)
  59722 			}
  59723 			v14 = v15
  59724 		}
  59725 		v12 = v14
  59726 		goto _13
  59727 	_13:
  59728 		v51 = v12
  59729 		goto _6
  59730 	_6:
  59731 		r = v51
  59732 		v18 = v1 * int32(19077) >> int32(8)
  59733 		goto _19
  59734 	_19:
  59735 		v20 = v2 * int32(6419) >> int32(8)
  59736 		goto _21
  59737 	_21:
  59738 		v22 = v3 * int32(13320) >> int32(8)
  59739 		goto _23
  59740 	_23:
  59741 		v24 = v18 - v20 - v22 + int32(8708)
  59742 		if v24 & ^int32(YUV_MASK2) == 0 {
  59743 			v27 = v24 >> int32(YUV_FIX2)
  59744 		} else {
  59745 			if v24 < 0 {
  59746 				v28 = 0
  59747 			} else {
  59748 				v28 = int32(255)
  59749 			}
  59750 			v27 = v28
  59751 		}
  59752 		v25 = v27
  59753 		goto _26
  59754 	_26:
  59755 		v16 = v25
  59756 		goto _17
  59757 	_17:
  59758 		g = v16
  59759 		v31 = v1 * int32(19077) >> int32(8)
  59760 		goto _32
  59761 	_32:
  59762 		v33 = v2 * int32(33050) >> int32(8)
  59763 		goto _34
  59764 	_34:
  59765 		v35 = v31 + v33 - int32(17685)
  59766 		if v35 & ^int32(YUV_MASK2) == 0 {
  59767 			v38 = v35 >> int32(YUV_FIX2)
  59768 		} else {
  59769 			if v35 < 0 {
  59770 				v39 = 0
  59771 			} else {
  59772 				v39 = int32(255)
  59773 			}
  59774 			v38 = v39
  59775 		}
  59776 		v36 = v38
  59777 		goto _37
  59778 	_37:
  59779 		v29 = v36
  59780 		goto _30
  59781 	_30:
  59782 		b = v29
  59783 		rg = r&int32(0xf0) | g>>libc.Int32FromInt32(4)
  59784 		ba = b&int32(0xf0) | int32(0x0f)
  59785 		**(**uint8_t)(__ccgo_up(v4)) = uint8(rg)
  59786 		**(**uint8_t)(__ccgo_up(v4 + 1)) = uint8(ba)
  59787 		v1 = int32(**(**uint8_t)(__ccgo_up(y4 + 1)))
  59788 		v2 = int32(**(**uint8_t)(__ccgo_up(u3)))
  59789 		v3 = int32(**(**uint8_t)(__ccgo_up(v5)))
  59790 		v4 = dst + uintptr(libc.Int32FromInt32(2))
  59791 		v7 = v1 * int32(19077) >> int32(8)
  59792 		goto _47
  59793 	_47:
  59794 		v9 = v3 * int32(26149) >> int32(8)
  59795 		goto _49
  59796 	_49:
  59797 		v11 = v7 + v9 - int32(14234)
  59798 		if v11 & ^int32(YUV_MASK2) == 0 {
  59799 			v14 = v11 >> int32(YUV_FIX2)
  59800 		} else {
  59801 			if v11 < 0 {
  59802 				v15 = 0
  59803 			} else {
  59804 				v15 = int32(255)
  59805 			}
  59806 			v14 = v15
  59807 		}
  59808 		v12 = v14
  59809 		goto _52
  59810 	_52:
  59811 		v51 = v12
  59812 		goto _45
  59813 	_45:
  59814 		r = v51
  59815 		v18 = v1 * int32(19077) >> int32(8)
  59816 		goto _58
  59817 	_58:
  59818 		v20 = v2 * int32(6419) >> int32(8)
  59819 		goto _60
  59820 	_60:
  59821 		v22 = v3 * int32(13320) >> int32(8)
  59822 		goto _62
  59823 	_62:
  59824 		v24 = v18 - v20 - v22 + int32(8708)
  59825 		if v24 & ^int32(YUV_MASK2) == 0 {
  59826 			v27 = v24 >> int32(YUV_FIX2)
  59827 		} else {
  59828 			if v24 < 0 {
  59829 				v28 = 0
  59830 			} else {
  59831 				v28 = int32(255)
  59832 			}
  59833 			v27 = v28
  59834 		}
  59835 		v25 = v27
  59836 		goto _65
  59837 	_65:
  59838 		v16 = v25
  59839 		goto _56
  59840 	_56:
  59841 		g = v16
  59842 		v31 = v1 * int32(19077) >> int32(8)
  59843 		goto _71
  59844 	_71:
  59845 		v33 = v2 * int32(33050) >> int32(8)
  59846 		goto _73
  59847 	_73:
  59848 		v35 = v31 + v33 - int32(17685)
  59849 		if v35 & ^int32(YUV_MASK2) == 0 {
  59850 			v38 = v35 >> int32(YUV_FIX2)
  59851 		} else {
  59852 			if v35 < 0 {
  59853 				v39 = 0
  59854 			} else {
  59855 				v39 = int32(255)
  59856 			}
  59857 			v38 = v39
  59858 		}
  59859 		v36 = v38
  59860 		goto _76
  59861 	_76:
  59862 		v29 = v36
  59863 		goto _69
  59864 	_69:
  59865 		b = v29
  59866 		rg = r&int32(0xf0) | g>>libc.Int32FromInt32(4)
  59867 		ba = b&int32(0xf0) | int32(0x0f)
  59868 		**(**uint8_t)(__ccgo_up(v4)) = uint8(rg)
  59869 		**(**uint8_t)(__ccgo_up(v4 + 1)) = uint8(ba)
  59870 		y4 = y4 + uintptr(2)
  59871 		u3 = u3 + 1
  59872 		v5 = v5 + 1
  59873 		dst = dst + uintptr(libc.Int32FromInt32(2)*libc.Int32FromInt32(2))
  59874 	}
  59875 	if len1&int32(1) != 0 {
  59876 		v1 = int32(**(**uint8_t)(__ccgo_up(y4)))
  59877 		v2 = int32(**(**uint8_t)(__ccgo_up(u3)))
  59878 		v3 = int32(**(**uint8_t)(__ccgo_up(v5)))
  59879 		v4 = dst
  59880 		v7 = v1 * int32(19077) >> int32(8)
  59881 		goto _86
  59882 	_86:
  59883 		v9 = v3 * int32(26149) >> int32(8)
  59884 		goto _88
  59885 	_88:
  59886 		v11 = v7 + v9 - int32(14234)
  59887 		if v11 & ^int32(YUV_MASK2) == 0 {
  59888 			v14 = v11 >> int32(YUV_FIX2)
  59889 		} else {
  59890 			if v11 < 0 {
  59891 				v15 = 0
  59892 			} else {
  59893 				v15 = int32(255)
  59894 			}
  59895 			v14 = v15
  59896 		}
  59897 		v12 = v14
  59898 		goto _91
  59899 	_91:
  59900 		v51 = v12
  59901 		goto _84
  59902 	_84:
  59903 		r = v51
  59904 		v18 = v1 * int32(19077) >> int32(8)
  59905 		goto _97
  59906 	_97:
  59907 		v20 = v2 * int32(6419) >> int32(8)
  59908 		goto _99
  59909 	_99:
  59910 		v22 = v3 * int32(13320) >> int32(8)
  59911 		goto _101
  59912 	_101:
  59913 		v24 = v18 - v20 - v22 + int32(8708)
  59914 		if v24 & ^int32(YUV_MASK2) == 0 {
  59915 			v27 = v24 >> int32(YUV_FIX2)
  59916 		} else {
  59917 			if v24 < 0 {
  59918 				v28 = 0
  59919 			} else {
  59920 				v28 = int32(255)
  59921 			}
  59922 			v27 = v28
  59923 		}
  59924 		v25 = v27
  59925 		goto _104
  59926 	_104:
  59927 		v16 = v25
  59928 		goto _95
  59929 	_95:
  59930 		g = v16
  59931 		v31 = v1 * int32(19077) >> int32(8)
  59932 		goto _110
  59933 	_110:
  59934 		v33 = v2 * int32(33050) >> int32(8)
  59935 		goto _112
  59936 	_112:
  59937 		v35 = v31 + v33 - int32(17685)
  59938 		if v35 & ^int32(YUV_MASK2) == 0 {
  59939 			v38 = v35 >> int32(YUV_FIX2)
  59940 		} else {
  59941 			if v35 < 0 {
  59942 				v39 = 0
  59943 			} else {
  59944 				v39 = int32(255)
  59945 			}
  59946 			v38 = v39
  59947 		}
  59948 		v36 = v38
  59949 		goto _115
  59950 	_115:
  59951 		v29 = v36
  59952 		goto _108
  59953 	_108:
  59954 		b = v29
  59955 		rg = r&int32(0xf0) | g>>libc.Int32FromInt32(4)
  59956 		ba = b&int32(0xf0) | int32(0x0f)
  59957 		**(**uint8_t)(__ccgo_up(v4)) = uint8(rg)
  59958 		**(**uint8_t)(__ccgo_up(v4 + 1)) = uint8(ba)
  59959 	}
  59960 }
  59961 
  59962 func YuvToRgb565Row(tls *libc.TLS, y4 uintptr, u3 uintptr, v5 uintptr, dst uintptr, len1 int32) {
  59963 	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
  59964 	var end, v4 uintptr
  59965 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  59966 	end = dst + uintptr(len1 & ^libc.Int32FromInt32(1) * int32(2))
  59967 	for dst != end {
  59968 		v1 = int32(**(**uint8_t)(__ccgo_up(y4)))
  59969 		v2 = int32(**(**uint8_t)(__ccgo_up(u3)))
  59970 		v3 = int32(**(**uint8_t)(__ccgo_up(v5)))
  59971 		v4 = dst
  59972 		v7 = v1 * int32(19077) >> int32(8)
  59973 		goto _8
  59974 	_8:
  59975 		v9 = v3 * int32(26149) >> int32(8)
  59976 		goto _10
  59977 	_10:
  59978 		v11 = v7 + v9 - int32(14234)
  59979 		if v11 & ^int32(YUV_MASK2) == 0 {
  59980 			v14 = v11 >> int32(YUV_FIX2)
  59981 		} else {
  59982 			if v11 < 0 {
  59983 				v15 = 0
  59984 			} else {
  59985 				v15 = int32(255)
  59986 			}
  59987 			v14 = v15
  59988 		}
  59989 		v12 = v14
  59990 		goto _13
  59991 	_13:
  59992 		v51 = v12
  59993 		goto _6
  59994 	_6:
  59995 		r = v51
  59996 		v18 = v1 * int32(19077) >> int32(8)
  59997 		goto _19
  59998 	_19:
  59999 		v20 = v2 * int32(6419) >> int32(8)
  60000 		goto _21
  60001 	_21:
  60002 		v22 = v3 * int32(13320) >> int32(8)
  60003 		goto _23
  60004 	_23:
  60005 		v24 = v18 - v20 - v22 + int32(8708)
  60006 		if v24 & ^int32(YUV_MASK2) == 0 {
  60007 			v27 = v24 >> int32(YUV_FIX2)
  60008 		} else {
  60009 			if v24 < 0 {
  60010 				v28 = 0
  60011 			} else {
  60012 				v28 = int32(255)
  60013 			}
  60014 			v27 = v28
  60015 		}
  60016 		v25 = v27
  60017 		goto _26
  60018 	_26:
  60019 		v16 = v25
  60020 		goto _17
  60021 	_17:
  60022 		g = v16
  60023 		v31 = v1 * int32(19077) >> int32(8)
  60024 		goto _32
  60025 	_32:
  60026 		v33 = v2 * int32(33050) >> int32(8)
  60027 		goto _34
  60028 	_34:
  60029 		v35 = v31 + v33 - int32(17685)
  60030 		if v35 & ^int32(YUV_MASK2) == 0 {
  60031 			v38 = v35 >> int32(YUV_FIX2)
  60032 		} else {
  60033 			if v35 < 0 {
  60034 				v39 = 0
  60035 			} else {
  60036 				v39 = int32(255)
  60037 			}
  60038 			v38 = v39
  60039 		}
  60040 		v36 = v38
  60041 		goto _37
  60042 	_37:
  60043 		v29 = v36
  60044 		goto _30
  60045 	_30:
  60046 		b = v29
  60047 		rg = r&int32(0xf8) | g>>libc.Int32FromInt32(5)
  60048 		gb = g<<libc.Int32FromInt32(3)&int32(0xe0) | b>>libc.Int32FromInt32(3)
  60049 		**(**uint8_t)(__ccgo_up(v4)) = uint8(rg)
  60050 		**(**uint8_t)(__ccgo_up(v4 + 1)) = uint8(gb)
  60051 		v1 = int32(**(**uint8_t)(__ccgo_up(y4 + 1)))
  60052 		v2 = int32(**(**uint8_t)(__ccgo_up(u3)))
  60053 		v3 = int32(**(**uint8_t)(__ccgo_up(v5)))
  60054 		v4 = dst + uintptr(libc.Int32FromInt32(2))
  60055 		v7 = v1 * int32(19077) >> int32(8)
  60056 		goto _47
  60057 	_47:
  60058 		v9 = v3 * int32(26149) >> int32(8)
  60059 		goto _49
  60060 	_49:
  60061 		v11 = v7 + v9 - int32(14234)
  60062 		if v11 & ^int32(YUV_MASK2) == 0 {
  60063 			v14 = v11 >> int32(YUV_FIX2)
  60064 		} else {
  60065 			if v11 < 0 {
  60066 				v15 = 0
  60067 			} else {
  60068 				v15 = int32(255)
  60069 			}
  60070 			v14 = v15
  60071 		}
  60072 		v12 = v14
  60073 		goto _52
  60074 	_52:
  60075 		v51 = v12
  60076 		goto _45
  60077 	_45:
  60078 		r = v51
  60079 		v18 = v1 * int32(19077) >> int32(8)
  60080 		goto _58
  60081 	_58:
  60082 		v20 = v2 * int32(6419) >> int32(8)
  60083 		goto _60
  60084 	_60:
  60085 		v22 = v3 * int32(13320) >> int32(8)
  60086 		goto _62
  60087 	_62:
  60088 		v24 = v18 - v20 - v22 + int32(8708)
  60089 		if v24 & ^int32(YUV_MASK2) == 0 {
  60090 			v27 = v24 >> int32(YUV_FIX2)
  60091 		} else {
  60092 			if v24 < 0 {
  60093 				v28 = 0
  60094 			} else {
  60095 				v28 = int32(255)
  60096 			}
  60097 			v27 = v28
  60098 		}
  60099 		v25 = v27
  60100 		goto _65
  60101 	_65:
  60102 		v16 = v25
  60103 		goto _56
  60104 	_56:
  60105 		g = v16
  60106 		v31 = v1 * int32(19077) >> int32(8)
  60107 		goto _71
  60108 	_71:
  60109 		v33 = v2 * int32(33050) >> int32(8)
  60110 		goto _73
  60111 	_73:
  60112 		v35 = v31 + v33 - int32(17685)
  60113 		if v35 & ^int32(YUV_MASK2) == 0 {
  60114 			v38 = v35 >> int32(YUV_FIX2)
  60115 		} else {
  60116 			if v35 < 0 {
  60117 				v39 = 0
  60118 			} else {
  60119 				v39 = int32(255)
  60120 			}
  60121 			v38 = v39
  60122 		}
  60123 		v36 = v38
  60124 		goto _76
  60125 	_76:
  60126 		v29 = v36
  60127 		goto _69
  60128 	_69:
  60129 		b = v29
  60130 		rg = r&int32(0xf8) | g>>libc.Int32FromInt32(5)
  60131 		gb = g<<libc.Int32FromInt32(3)&int32(0xe0) | b>>libc.Int32FromInt32(3)
  60132 		**(**uint8_t)(__ccgo_up(v4)) = uint8(rg)
  60133 		**(**uint8_t)(__ccgo_up(v4 + 1)) = uint8(gb)
  60134 		y4 = y4 + uintptr(2)
  60135 		u3 = u3 + 1
  60136 		v5 = v5 + 1
  60137 		dst = dst + uintptr(libc.Int32FromInt32(2)*libc.Int32FromInt32(2))
  60138 	}
  60139 	if len1&int32(1) != 0 {
  60140 		v1 = int32(**(**uint8_t)(__ccgo_up(y4)))
  60141 		v2 = int32(**(**uint8_t)(__ccgo_up(u3)))
  60142 		v3 = int32(**(**uint8_t)(__ccgo_up(v5)))
  60143 		v4 = dst
  60144 		v7 = v1 * int32(19077) >> int32(8)
  60145 		goto _86
  60146 	_86:
  60147 		v9 = v3 * int32(26149) >> int32(8)
  60148 		goto _88
  60149 	_88:
  60150 		v11 = v7 + v9 - int32(14234)
  60151 		if v11 & ^int32(YUV_MASK2) == 0 {
  60152 			v14 = v11 >> int32(YUV_FIX2)
  60153 		} else {
  60154 			if v11 < 0 {
  60155 				v15 = 0
  60156 			} else {
  60157 				v15 = int32(255)
  60158 			}
  60159 			v14 = v15
  60160 		}
  60161 		v12 = v14
  60162 		goto _91
  60163 	_91:
  60164 		v51 = v12
  60165 		goto _84
  60166 	_84:
  60167 		r = v51
  60168 		v18 = v1 * int32(19077) >> int32(8)
  60169 		goto _97
  60170 	_97:
  60171 		v20 = v2 * int32(6419) >> int32(8)
  60172 		goto _99
  60173 	_99:
  60174 		v22 = v3 * int32(13320) >> int32(8)
  60175 		goto _101
  60176 	_101:
  60177 		v24 = v18 - v20 - v22 + int32(8708)
  60178 		if v24 & ^int32(YUV_MASK2) == 0 {
  60179 			v27 = v24 >> int32(YUV_FIX2)
  60180 		} else {
  60181 			if v24 < 0 {
  60182 				v28 = 0
  60183 			} else {
  60184 				v28 = int32(255)
  60185 			}
  60186 			v27 = v28
  60187 		}
  60188 		v25 = v27
  60189 		goto _104
  60190 	_104:
  60191 		v16 = v25
  60192 		goto _95
  60193 	_95:
  60194 		g = v16
  60195 		v31 = v1 * int32(19077) >> int32(8)
  60196 		goto _110
  60197 	_110:
  60198 		v33 = v2 * int32(33050) >> int32(8)
  60199 		goto _112
  60200 	_112:
  60201 		v35 = v31 + v33 - int32(17685)
  60202 		if v35 & ^int32(YUV_MASK2) == 0 {
  60203 			v38 = v35 >> int32(YUV_FIX2)
  60204 		} else {
  60205 			if v35 < 0 {
  60206 				v39 = 0
  60207 			} else {
  60208 				v39 = int32(255)
  60209 			}
  60210 			v38 = v39
  60211 		}
  60212 		v36 = v38
  60213 		goto _115
  60214 	_115:
  60215 		v29 = v36
  60216 		goto _108
  60217 	_108:
  60218 		b = v29
  60219 		rg = r&int32(0xf8) | g>>libc.Int32FromInt32(5)
  60220 		gb = g<<libc.Int32FromInt32(3)&int32(0xe0) | b>>libc.Int32FromInt32(3)
  60221 		**(**uint8_t)(__ccgo_up(v4)) = uint8(rg)
  60222 		**(**uint8_t)(__ccgo_up(v4 + 1)) = uint8(gb)
  60223 	}
  60224 }
  60225 
  60226 type __ccgo_fp__XWebPSamplerProcessPlane_9 = func(*libc.TLS, uintptr, uintptr, uintptr, uintptr, int32)
  60227 
  60228 // C documentation
  60229 //
  60230 //	// Main call for processing a plane with a WebPSamplerRowFunc function:
  60231 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) {
  60232 	var j int32
  60233 	_ = j
  60234 	j = 0
  60235 	for {
  60236 		if !(j < height) {
  60237 			break
  60238 		}
  60239 		(*(*func(*libc.TLS, uintptr, uintptr, uintptr, uintptr, int32))(unsafe.Pointer(&struct{ uintptr }{__ccgo_fp_func})))(tls, y, u, v, dst, width)
  60240 		y = y + uintptr(y_stride)
  60241 		if j&int32(1) != 0 {
  60242 			u = u + uintptr(uv_stride)
  60243 			v = v + uintptr(uv_stride)
  60244 		}
  60245 		dst = dst + uintptr(dst_stride)
  60246 		goto _1
  60247 	_1:
  60248 		;
  60249 		j = j + 1
  60250 	}
  60251 }
  60252 
  60253 func WebPInitSamplers(tls *libc.TLS) {
  60254 	if libc.AtomicLoadPUintptr(uintptr(unsafe.Pointer(&WebPInitSamplers_body_last_cpuinfo_used))) == VP8GetCPUInfo {
  60255 		goto _1
  60256 	}
  60257 	WebPInitSamplers_body(tls)
  60258 	libc.AtomicStorePUintptr(uintptr(unsafe.Pointer(&WebPInitSamplers_body_last_cpuinfo_used)), VP8GetCPUInfo)
  60259 	goto _2
  60260 _2:
  60261 	;
  60262 	goto _1
  60263 _1: /**/ //
  60264 }
  60265 
  60266 var WebPInitSamplers_body_last_cpuinfo_used = uintptr(0)
  60267 
  60268 func init() {
  60269 	p := unsafe.Pointer(&WebPInitSamplers_body_last_cpuinfo_used)
  60270 	*(*uintptr)(unsafe.Add(p, 0)) = uintptr(unsafe.Pointer(&WebPInitSamplers_body_last_cpuinfo_used))
  60271 }
  60272 
  60273 func WebPInitSamplers_body(tls *libc.TLS) {
  60274 	WebPSamplers[int32(MODE_RGB)] = __ccgo_fp(YuvToRgbRow)
  60275 	WebPSamplers[int32(MODE_RGBA)] = __ccgo_fp(YuvToRgbaRow)
  60276 	WebPSamplers[int32(MODE_BGR)] = __ccgo_fp(YuvToBgrRow)
  60277 	WebPSamplers[int32(MODE_BGRA)] = __ccgo_fp(YuvToBgraRow)
  60278 	WebPSamplers[int32(MODE_ARGB)] = __ccgo_fp(YuvToArgbRow)
  60279 	WebPSamplers[int32(MODE_RGBA_4444)] = __ccgo_fp(YuvToRgba4444Row)
  60280 	WebPSamplers[int32(MODE_RGB_565)] = __ccgo_fp(YuvToRgb565Row)
  60281 	WebPSamplers[int32(MODE_rgbA)] = __ccgo_fp(YuvToRgbaRow)
  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 	// If defined, use CPUInfo() to overwrite some pointers with faster versions.
  60286 	if VP8GetCPUInfo != libc.UintptrFromInt32(0) {
  60287 	}
  60288 }
  60289 
  60290 //-----------------------------------------------------------------------------
  60291 // ARGB -> YUV converters
  60292 
  60293 func ConvertARGBToY_C(tls *libc.TLS, argb uintptr, y uintptr, width int32) {
  60294 	var i, luma, v2 int32
  60295 	var p uint32_t
  60296 	_, _, _, _ = i, luma, p, v2
  60297 	i = 0
  60298 	for {
  60299 		if !(i < width) {
  60300 			break
  60301 		}
  60302 		p = **(**uint32_t)(__ccgo_up(argb + uintptr(i)*4))
  60303 		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))
  60304 		v2 = (luma + int32(YUV_HALF) + libc.Int32FromInt32(16)<<int32(YUV_FIX)) >> int32(YUV_FIX)
  60305 		goto _3
  60306 	_3:
  60307 		**(**uint8_t)(__ccgo_up(y + uintptr(i))) = uint8(v2)
  60308 		goto _1
  60309 	_1:
  60310 		;
  60311 		i = i + 1
  60312 	}
  60313 }
  60314 
  60315 func WebPConvertARGBToUV_C(tls *libc.TLS, argb uintptr, u1 uintptr, v1 uintptr, src_width int32, do_store int32) {
  60316 	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
  60317 	var v0, v01, v11 uint32_t
  60318 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  60319 	// No rounding. Last pixel is dealt with separately.
  60320 	uv_width = src_width >> int32(1)
  60321 	i = 0
  60322 	for {
  60323 		if !(i < uv_width) {
  60324 			break
  60325 		}
  60326 		v0 = **(**uint32_t)(__ccgo_up(argb + uintptr(int32(2)*i+0)*4))
  60327 		v11 = **(**uint32_t)(__ccgo_up(argb + uintptr(int32(2)*i+int32(1))*4))
  60328 		// VP8RGBToU/V expects four accumulated pixels. Hence we need to
  60329 		// scale r/g/b value by a factor 2. We just shift v0/v1 one bit less.
  60330 		r2 = int32(v0>>libc.Int32FromInt32(15)&uint32(0x1fe) + v11>>libc.Int32FromInt32(15)&uint32(0x1fe))
  60331 		g2 = int32(v0>>libc.Int32FromInt32(7)&uint32(0x1fe) + v11>>libc.Int32FromInt32(7)&uint32(0x1fe))
  60332 		b2 = int32(v0<<libc.Int32FromInt32(1)&uint32(0x1fe) + v11<<libc.Int32FromInt32(1)&uint32(0x1fe))
  60333 		u = -int32(9719)*r2 - int32(19081)*g2 + int32(28800)*b2
  60334 		v4 = u
  60335 		v4 = (v4 + int32(YUV_HALF)<<libc.Int32FromInt32(2) + libc.Int32FromInt32(128)<<(int32(YUV_FIX)+libc.Int32FromInt32(2))) >> (int32(YUV_FIX) + libc.Int32FromInt32(2))
  60336 		if v4 & ^libc.Int32FromInt32(0xff) == 0 {
  60337 			v7 = v4
  60338 		} else {
  60339 			if v4 < 0 {
  60340 				v8 = 0
  60341 			} else {
  60342 				v8 = int32(255)
  60343 			}
  60344 			v7 = v8
  60345 		}
  60346 		v5 = v7
  60347 		goto _6
  60348 	_6:
  60349 		v2 = v5
  60350 		goto _3
  60351 	_3:
  60352 		tmp_u = v2
  60353 		v = +libc.Int32FromInt32(28800)*r2 - int32(24116)*g2 - int32(4684)*b2
  60354 		v111 = v
  60355 		v111 = (v111 + int32(YUV_HALF)<<libc.Int32FromInt32(2) + libc.Int32FromInt32(128)<<(int32(YUV_FIX)+libc.Int32FromInt32(2))) >> (int32(YUV_FIX) + libc.Int32FromInt32(2))
  60356 		if v111 & ^libc.Int32FromInt32(0xff) == 0 {
  60357 			v14 = v111
  60358 		} else {
  60359 			if v111 < 0 {
  60360 				v15 = 0
  60361 			} else {
  60362 				v15 = int32(255)
  60363 			}
  60364 			v14 = v15
  60365 		}
  60366 		v12 = v14
  60367 		goto _13
  60368 	_13:
  60369 		v9 = v12
  60370 		goto _10
  60371 	_10:
  60372 		tmp_v = v9
  60373 		if do_store != 0 {
  60374 			**(**uint8_t)(__ccgo_up(u1 + uintptr(i))) = uint8(tmp_u)
  60375 			**(**uint8_t)(__ccgo_up(v1 + uintptr(i))) = uint8(tmp_v)
  60376 		} else {
  60377 			// Approximated average-of-four. But it's an acceptable diff.
  60378 			**(**uint8_t)(__ccgo_up(u1 + uintptr(i))) = uint8((int32(**(**uint8_t)(__ccgo_up(u1 + uintptr(i)))) + tmp_u + int32(1)) >> int32(1))
  60379 			**(**uint8_t)(__ccgo_up(v1 + uintptr(i))) = uint8((int32(**(**uint8_t)(__ccgo_up(v1 + uintptr(i)))) + tmp_v + int32(1)) >> int32(1))
  60380 		}
  60381 		goto _1
  60382 	_1:
  60383 		;
  60384 		i = i + 1
  60385 	}
  60386 	if src_width&int32(1) != 0 { // last pixel
  60387 		v01 = **(**uint32_t)(__ccgo_up(argb + uintptr(int32(2)*i+0)*4))
  60388 		r3 = int32(v01 >> libc.Int32FromInt32(14) & uint32(0x3fc))
  60389 		g3 = int32(v01 >> libc.Int32FromInt32(6) & uint32(0x3fc))
  60390 		b3 = int32(v01 << libc.Int32FromInt32(2) & uint32(0x3fc))
  60391 		u = -int32(9719)*r3 - int32(19081)*g3 + int32(28800)*b3
  60392 		v4 = u
  60393 		v4 = (v4 + int32(YUV_HALF)<<libc.Int32FromInt32(2) + libc.Int32FromInt32(128)<<(int32(YUV_FIX)+libc.Int32FromInt32(2))) >> (int32(YUV_FIX) + libc.Int32FromInt32(2))
  60394 		if v4 & ^libc.Int32FromInt32(0xff) == 0 {
  60395 			v7 = v4
  60396 		} else {
  60397 			if v4 < 0 {
  60398 				v8 = 0
  60399 			} else {
  60400 				v8 = int32(255)
  60401 			}
  60402 			v7 = v8
  60403 		}
  60404 		v5 = v7
  60405 		goto _20
  60406 	_20:
  60407 		v2 = v5
  60408 		goto _17
  60409 	_17:
  60410 		tmp_u1 = v2
  60411 		v = +libc.Int32FromInt32(28800)*r3 - int32(24116)*g3 - int32(4684)*b3
  60412 		v111 = v
  60413 		v111 = (v111 + int32(YUV_HALF)<<libc.Int32FromInt32(2) + libc.Int32FromInt32(128)<<(int32(YUV_FIX)+libc.Int32FromInt32(2))) >> (int32(YUV_FIX) + libc.Int32FromInt32(2))
  60414 		if v111 & ^libc.Int32FromInt32(0xff) == 0 {
  60415 			v14 = v111
  60416 		} else {
  60417 			if v111 < 0 {
  60418 				v15 = 0
  60419 			} else {
  60420 				v15 = int32(255)
  60421 			}
  60422 			v14 = v15
  60423 		}
  60424 		v12 = v14
  60425 		goto _27
  60426 	_27:
  60427 		v9 = v12
  60428 		goto _24
  60429 	_24:
  60430 		tmp_v1 = v9
  60431 		if do_store != 0 {
  60432 			**(**uint8_t)(__ccgo_up(u1 + uintptr(i))) = uint8(tmp_u1)
  60433 			**(**uint8_t)(__ccgo_up(v1 + uintptr(i))) = uint8(tmp_v1)
  60434 		} else {
  60435 			**(**uint8_t)(__ccgo_up(u1 + uintptr(i))) = uint8((int32(**(**uint8_t)(__ccgo_up(u1 + uintptr(i)))) + tmp_u1 + int32(1)) >> int32(1))
  60436 			**(**uint8_t)(__ccgo_up(v1 + uintptr(i))) = uint8((int32(**(**uint8_t)(__ccgo_up(v1 + uintptr(i)))) + tmp_v1 + int32(1)) >> int32(1))
  60437 		}
  60438 	}
  60439 }
  60440 
  60441 //-----------------------------------------------------------------------------
  60442 
  60443 func ConvertRGB24ToY_C(tls *libc.TLS, rgb uintptr, y uintptr, width int32) {
  60444 	var i, luma, v2 int32
  60445 	_, _, _ = i, luma, v2
  60446 	i = 0
  60447 	for {
  60448 		if !(i < width) {
  60449 			break
  60450 		}
  60451 		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)))
  60452 		v2 = (luma + int32(YUV_HALF) + libc.Int32FromInt32(16)<<int32(YUV_FIX)) >> int32(YUV_FIX)
  60453 		goto _3
  60454 	_3:
  60455 		**(**uint8_t)(__ccgo_up(y + uintptr(i))) = uint8(v2)
  60456 		goto _1
  60457 	_1:
  60458 		;
  60459 		i = i + 1
  60460 		rgb = rgb + uintptr(3)
  60461 	}
  60462 }
  60463 
  60464 func ConvertBGR24ToY_C(tls *libc.TLS, bgr uintptr, y uintptr, width int32) {
  60465 	var i, luma, v2 int32
  60466 	_, _, _ = i, luma, v2
  60467 	i = 0
  60468 	for {
  60469 		if !(i < width) {
  60470 			break
  60471 		}
  60472 		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)))
  60473 		v2 = (luma + int32(YUV_HALF) + libc.Int32FromInt32(16)<<int32(YUV_FIX)) >> int32(YUV_FIX)
  60474 		goto _3
  60475 	_3:
  60476 		**(**uint8_t)(__ccgo_up(y + uintptr(i))) = uint8(v2)
  60477 		goto _1
  60478 	_1:
  60479 		;
  60480 		i = i + 1
  60481 		bgr = bgr + uintptr(3)
  60482 	}
  60483 }
  60484 
  60485 func WebPConvertRGBA32ToUV_C(tls *libc.TLS, rgb uintptr, u1 uintptr, v1 uintptr, width int32) {
  60486 	var b2, g2, i, r2, u, v, v2, v4, v5, v7, v8 int32
  60487 	_, _, _, _, _, _, _, _, _, _, _ = b2, g2, i, r2, u, v, v2, v4, v5, v7, v8
  60488 	i = 0
  60489 	for {
  60490 		if !(i < width) {
  60491 			break
  60492 		}
  60493 		r2 = int32(**(**uint16_t)(__ccgo_up(rgb)))
  60494 		g2 = int32(**(**uint16_t)(__ccgo_up(rgb + 1*2)))
  60495 		b2 = int32(**(**uint16_t)(__ccgo_up(rgb + 2*2)))
  60496 		u = -int32(9719)*r2 - int32(19081)*g2 + int32(28800)*b2
  60497 		v4 = u
  60498 		v4 = (v4 + int32(YUV_HALF)<<libc.Int32FromInt32(2) + libc.Int32FromInt32(128)<<(int32(YUV_FIX)+libc.Int32FromInt32(2))) >> (int32(YUV_FIX) + libc.Int32FromInt32(2))
  60499 		if v4 & ^libc.Int32FromInt32(0xff) == 0 {
  60500 			v7 = v4
  60501 		} else {
  60502 			if v4 < 0 {
  60503 				v8 = 0
  60504 			} else {
  60505 				v8 = int32(255)
  60506 			}
  60507 			v7 = v8
  60508 		}
  60509 		v5 = v7
  60510 		goto _6
  60511 	_6:
  60512 		v2 = v5
  60513 		goto _3
  60514 	_3:
  60515 		**(**uint8_t)(__ccgo_up(u1 + uintptr(i))) = uint8(v2)
  60516 		v = +libc.Int32FromInt32(28800)*r2 - int32(24116)*g2 - int32(4684)*b2
  60517 		v4 = v
  60518 		v4 = (v4 + int32(YUV_HALF)<<libc.Int32FromInt32(2) + libc.Int32FromInt32(128)<<(int32(YUV_FIX)+libc.Int32FromInt32(2))) >> (int32(YUV_FIX) + libc.Int32FromInt32(2))
  60519 		if v4 & ^libc.Int32FromInt32(0xff) == 0 {
  60520 			v7 = v4
  60521 		} else {
  60522 			if v4 < 0 {
  60523 				v8 = 0
  60524 			} else {
  60525 				v8 = int32(255)
  60526 			}
  60527 			v7 = v8
  60528 		}
  60529 		v5 = v7
  60530 		goto _13
  60531 	_13:
  60532 		v2 = v5
  60533 		goto _10
  60534 	_10:
  60535 		**(**uint8_t)(__ccgo_up(v1 + uintptr(i))) = uint8(v2)
  60536 		goto _1
  60537 	_1:
  60538 		;
  60539 		i = i + int32(1)
  60540 		rgb = rgb + uintptr(4)*2
  60541 	}
  60542 }
  60543 
  60544 func WebPInitConvertARGBToYUV(tls *libc.TLS) {
  60545 	if libc.AtomicLoadPUintptr(uintptr(unsafe.Pointer(&WebPInitConvertARGBToYUV_body_last_cpuinfo_used))) == VP8GetCPUInfo {
  60546 		goto _1
  60547 	}
  60548 	WebPInitConvertARGBToYUV_body(tls)
  60549 	libc.AtomicStorePUintptr(uintptr(unsafe.Pointer(&WebPInitConvertARGBToYUV_body_last_cpuinfo_used)), VP8GetCPUInfo)
  60550 	goto _2
  60551 _2:
  60552 	;
  60553 	goto _1
  60554 _1: /**/ //
  60555 }
  60556 
  60557 var WebPInitConvertARGBToYUV_body_last_cpuinfo_used = uintptr(0)
  60558 
  60559 func init() {
  60560 	p := unsafe.Pointer(&WebPInitConvertARGBToYUV_body_last_cpuinfo_used)
  60561 	*(*uintptr)(unsafe.Add(p, 0)) = uintptr(unsafe.Pointer(&WebPInitConvertARGBToYUV_body_last_cpuinfo_used))
  60562 }
  60563 
  60564 func WebPInitConvertARGBToYUV_body(tls *libc.TLS) {
  60565 	WebPConvertARGBToY = __ccgo_fp(ConvertARGBToY_C)
  60566 	WebPConvertARGBToUV = __ccgo_fp(WebPConvertARGBToUV_C)
  60567 	WebPConvertRGB24ToY = __ccgo_fp(ConvertRGB24ToY_C)
  60568 	WebPConvertBGR24ToY = __ccgo_fp(ConvertBGR24ToY_C)
  60569 	WebPConvertRGBA32ToUV = __ccgo_fp(WebPConvertRGBA32ToUV_C)
  60570 	if VP8GetCPUInfo != libc.UintptrFromInt32(0) {
  60571 	}
  60572 }
  60573 
  60574 const SIZE_MAX33 = "UINT64_MAX"
  60575 
  60576 func WebPInitSamplersMIPS32(tls *libc.TLS) {
  60577 }
  60578 
  60579 func WebPInitSamplersMIPSdspR2(tls *libc.TLS) {
  60580 }
  60581 
  60582 func WebPInitConvertARGBToYUVNEON(tls *libc.TLS) {
  60583 }
  60584 
  60585 func WebPInitSamplersSSE2(tls *libc.TLS) {
  60586 }
  60587 
  60588 func WebPInitConvertARGBToYUVSSE2(tls *libc.TLS) {
  60589 }
  60590 
  60591 func WebPInitSamplersSSE41(tls *libc.TLS) {
  60592 }
  60593 
  60594 func WebPInitConvertARGBToYUVSSE41(tls *libc.TLS) {
  60595 }
  60596 
  60597 type __ccgo_fp__XSharpYuvInit_0 = func(*libc.TLS, int32) int32
  60598 
  60599 func SharpYuvInit(tls *libc.TLS, __ccgo_fp_cpu_info_func VP8CPUInfo) {
  60600 	_ = __ccgo_fp_cpu_info_func
  60601 }
  60602 
  60603 func SharpYuvGetConversionMatrix(tls *libc.TLS, matrix_type SharpYuvMatrixType) (r uintptr) {
  60604 	_ = matrix_type
  60605 	return libc.UintptrFromInt32(0)
  60606 }
  60607 
  60608 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) {
  60609 	_ = r_ptr
  60610 	_ = g_ptr
  60611 	_ = b_ptr
  60612 	_ = rgb_step
  60613 	_ = rgb_stride
  60614 	_ = rgb_bit_depth
  60615 	_ = y_ptr
  60616 	_ = y_stride
  60617 	_ = u_ptr
  60618 	_ = u_stride
  60619 	_ = v_ptr
  60620 	_ = v_stride
  60621 	_ = yuv_bit_depth
  60622 	_ = width
  60623 	_ = height
  60624 	_ = yuv_matrix
  60625 	return 0
  60626 }
  60627 
  60628 func __ccgo_fp(f interface{}) uintptr {
  60629 	type iface [2]uintptr
  60630 	return (*iface)(unsafe.Pointer(&f))[1]
  60631 }
  60632 
  60633 func __ccgo_up(n uintptr) unsafe.Pointer {
  60634 	return unsafe.Pointer(&n)
  60635 }
  60636 
  60637 var VP8AccumulateSSE VP8AccumulateSSEFunc
  60638 
  60639 //------------------------------------------------------------------------------
  60640 // Tables for level coding
  60641 
  60642 var VP8Cat3 = [3]uint8_t{
  60643 	0: uint8(173),
  60644 	1: uint8(148),
  60645 	2: uint8(140),
  60646 }
  60647 
  60648 var VP8Cat4 = [4]uint8_t{
  60649 	0: uint8(176),
  60650 	1: uint8(155),
  60651 	2: uint8(140),
  60652 	3: uint8(135),
  60653 }
  60654 
  60655 var VP8Cat5 = [5]uint8_t{
  60656 	0: uint8(180),
  60657 	1: uint8(157),
  60658 	2: uint8(141),
  60659 	3: uint8(134),
  60660 	4: uint8(130),
  60661 }
  60662 
  60663 var VP8Cat6 = [11]uint8_t{
  60664 	0:  uint8(254),
  60665 	1:  uint8(254),
  60666 	2:  uint8(243),
  60667 	3:  uint8(230),
  60668 	4:  uint8(196),
  60669 	5:  uint8(177),
  60670 	6:  uint8(153),
  60671 	7:  uint8(140),
  60672 	8:  uint8(133),
  60673 	9:  uint8(130),
  60674 	10: uint8(129),
  60675 }
  60676 
  60677 //------------------------------------------------------------------------------
  60678 
  60679 // Copyright 2011 Google Inc. All Rights Reserved.
  60680 //
  60681 // Use of this source code is governed by a BSD-style license
  60682 // that can be found in the COPYING file in the root of the source
  60683 // tree. An additional intellectual property rights grant can be found
  60684 // in the file PATENTS. All contributing project authors may
  60685 // be found in the AUTHORS file in the root of the source tree.
  60686 // -----------------------------------------------------------------------------
  60687 //
  60688 // Bit writing and boolean coder
  60689 //
  60690 // Author: Skal (pascal.massimino@gmail.com)
  60691 
  60692 //------------------------------------------------------------------------------
  60693 // Default probabilities
  60694 
  60695 // C documentation
  60696 //
  60697 //	// Paragraph 13.5
  60698 
  60699 var VP8CoeffsProba0 = [4][8][3][11]uint8_t{
  60700 	0: {
  60701 		0: {
  60702 			0: {
  60703 				0:  uint8(128),
  60704 				1:  uint8(128),
  60705 				2:  uint8(128),
  60706 				3:  uint8(128),
  60707 				4:  uint8(128),
  60708 				5:  uint8(128),
  60709 				6:  uint8(128),
  60710 				7:  uint8(128),
  60711 				8:  uint8(128),
  60712 				9:  uint8(128),
  60713 				10: uint8(128),
  60714 			},
  60715 			1: {
  60716 				0:  uint8(128),
  60717 				1:  uint8(128),
  60718 				2:  uint8(128),
  60719 				3:  uint8(128),
  60720 				4:  uint8(128),
  60721 				5:  uint8(128),
  60722 				6:  uint8(128),
  60723 				7:  uint8(128),
  60724 				8:  uint8(128),
  60725 				9:  uint8(128),
  60726 				10: uint8(128),
  60727 			},
  60728 			2: {
  60729 				0:  uint8(128),
  60730 				1:  uint8(128),
  60731 				2:  uint8(128),
  60732 				3:  uint8(128),
  60733 				4:  uint8(128),
  60734 				5:  uint8(128),
  60735 				6:  uint8(128),
  60736 				7:  uint8(128),
  60737 				8:  uint8(128),
  60738 				9:  uint8(128),
  60739 				10: uint8(128),
  60740 			},
  60741 		},
  60742 		1: {
  60743 			0: {
  60744 				0:  uint8(253),
  60745 				1:  uint8(136),
  60746 				2:  uint8(254),
  60747 				3:  uint8(255),
  60748 				4:  uint8(228),
  60749 				5:  uint8(219),
  60750 				6:  uint8(128),
  60751 				7:  uint8(128),
  60752 				8:  uint8(128),
  60753 				9:  uint8(128),
  60754 				10: uint8(128),
  60755 			},
  60756 			1: {
  60757 				0:  uint8(189),
  60758 				1:  uint8(129),
  60759 				2:  uint8(242),
  60760 				3:  uint8(255),
  60761 				4:  uint8(227),
  60762 				5:  uint8(213),
  60763 				6:  uint8(255),
  60764 				7:  uint8(219),
  60765 				8:  uint8(128),
  60766 				9:  uint8(128),
  60767 				10: uint8(128),
  60768 			},
  60769 			2: {
  60770 				0:  uint8(106),
  60771 				1:  uint8(126),
  60772 				2:  uint8(227),
  60773 				3:  uint8(252),
  60774 				4:  uint8(214),
  60775 				5:  uint8(209),
  60776 				6:  uint8(255),
  60777 				7:  uint8(255),
  60778 				8:  uint8(128),
  60779 				9:  uint8(128),
  60780 				10: uint8(128),
  60781 			},
  60782 		},
  60783 		2: {
  60784 			0: {
  60785 				0:  uint8(1),
  60786 				1:  uint8(98),
  60787 				2:  uint8(248),
  60788 				3:  uint8(255),
  60789 				4:  uint8(236),
  60790 				5:  uint8(226),
  60791 				6:  uint8(255),
  60792 				7:  uint8(255),
  60793 				8:  uint8(128),
  60794 				9:  uint8(128),
  60795 				10: uint8(128),
  60796 			},
  60797 			1: {
  60798 				0:  uint8(181),
  60799 				1:  uint8(133),
  60800 				2:  uint8(238),
  60801 				3:  uint8(254),
  60802 				4:  uint8(221),
  60803 				5:  uint8(234),
  60804 				6:  uint8(255),
  60805 				7:  uint8(154),
  60806 				8:  uint8(128),
  60807 				9:  uint8(128),
  60808 				10: uint8(128),
  60809 			},
  60810 			2: {
  60811 				0:  uint8(78),
  60812 				1:  uint8(134),
  60813 				2:  uint8(202),
  60814 				3:  uint8(247),
  60815 				4:  uint8(198),
  60816 				5:  uint8(180),
  60817 				6:  uint8(255),
  60818 				7:  uint8(219),
  60819 				8:  uint8(128),
  60820 				9:  uint8(128),
  60821 				10: uint8(128),
  60822 			},
  60823 		},
  60824 		3: {
  60825 			0: {
  60826 				0:  uint8(1),
  60827 				1:  uint8(185),
  60828 				2:  uint8(249),
  60829 				3:  uint8(255),
  60830 				4:  uint8(243),
  60831 				5:  uint8(255),
  60832 				6:  uint8(128),
  60833 				7:  uint8(128),
  60834 				8:  uint8(128),
  60835 				9:  uint8(128),
  60836 				10: uint8(128),
  60837 			},
  60838 			1: {
  60839 				0:  uint8(184),
  60840 				1:  uint8(150),
  60841 				2:  uint8(247),
  60842 				3:  uint8(255),
  60843 				4:  uint8(236),
  60844 				5:  uint8(224),
  60845 				6:  uint8(128),
  60846 				7:  uint8(128),
  60847 				8:  uint8(128),
  60848 				9:  uint8(128),
  60849 				10: uint8(128),
  60850 			},
  60851 			2: {
  60852 				0:  uint8(77),
  60853 				1:  uint8(110),
  60854 				2:  uint8(216),
  60855 				3:  uint8(255),
  60856 				4:  uint8(236),
  60857 				5:  uint8(230),
  60858 				6:  uint8(128),
  60859 				7:  uint8(128),
  60860 				8:  uint8(128),
  60861 				9:  uint8(128),
  60862 				10: uint8(128),
  60863 			},
  60864 		},
  60865 		4: {
  60866 			0: {
  60867 				0:  uint8(1),
  60868 				1:  uint8(101),
  60869 				2:  uint8(251),
  60870 				3:  uint8(255),
  60871 				4:  uint8(241),
  60872 				5:  uint8(255),
  60873 				6:  uint8(128),
  60874 				7:  uint8(128),
  60875 				8:  uint8(128),
  60876 				9:  uint8(128),
  60877 				10: uint8(128),
  60878 			},
  60879 			1: {
  60880 				0:  uint8(170),
  60881 				1:  uint8(139),
  60882 				2:  uint8(241),
  60883 				3:  uint8(252),
  60884 				4:  uint8(236),
  60885 				5:  uint8(209),
  60886 				6:  uint8(255),
  60887 				7:  uint8(255),
  60888 				8:  uint8(128),
  60889 				9:  uint8(128),
  60890 				10: uint8(128),
  60891 			},
  60892 			2: {
  60893 				0:  uint8(37),
  60894 				1:  uint8(116),
  60895 				2:  uint8(196),
  60896 				3:  uint8(243),
  60897 				4:  uint8(228),
  60898 				5:  uint8(255),
  60899 				6:  uint8(255),
  60900 				7:  uint8(255),
  60901 				8:  uint8(128),
  60902 				9:  uint8(128),
  60903 				10: uint8(128),
  60904 			},
  60905 		},
  60906 		5: {
  60907 			0: {
  60908 				0:  uint8(1),
  60909 				1:  uint8(204),
  60910 				2:  uint8(254),
  60911 				3:  uint8(255),
  60912 				4:  uint8(245),
  60913 				5:  uint8(255),
  60914 				6:  uint8(128),
  60915 				7:  uint8(128),
  60916 				8:  uint8(128),
  60917 				9:  uint8(128),
  60918 				10: uint8(128),
  60919 			},
  60920 			1: {
  60921 				0:  uint8(207),
  60922 				1:  uint8(160),
  60923 				2:  uint8(250),
  60924 				3:  uint8(255),
  60925 				4:  uint8(238),
  60926 				5:  uint8(128),
  60927 				6:  uint8(128),
  60928 				7:  uint8(128),
  60929 				8:  uint8(128),
  60930 				9:  uint8(128),
  60931 				10: uint8(128),
  60932 			},
  60933 			2: {
  60934 				0:  uint8(102),
  60935 				1:  uint8(103),
  60936 				2:  uint8(231),
  60937 				3:  uint8(255),
  60938 				4:  uint8(211),
  60939 				5:  uint8(171),
  60940 				6:  uint8(128),
  60941 				7:  uint8(128),
  60942 				8:  uint8(128),
  60943 				9:  uint8(128),
  60944 				10: uint8(128),
  60945 			},
  60946 		},
  60947 		6: {
  60948 			0: {
  60949 				0:  uint8(1),
  60950 				1:  uint8(152),
  60951 				2:  uint8(252),
  60952 				3:  uint8(255),
  60953 				4:  uint8(240),
  60954 				5:  uint8(255),
  60955 				6:  uint8(128),
  60956 				7:  uint8(128),
  60957 				8:  uint8(128),
  60958 				9:  uint8(128),
  60959 				10: uint8(128),
  60960 			},
  60961 			1: {
  60962 				0:  uint8(177),
  60963 				1:  uint8(135),
  60964 				2:  uint8(243),
  60965 				3:  uint8(255),
  60966 				4:  uint8(234),
  60967 				5:  uint8(225),
  60968 				6:  uint8(128),
  60969 				7:  uint8(128),
  60970 				8:  uint8(128),
  60971 				9:  uint8(128),
  60972 				10: uint8(128),
  60973 			},
  60974 			2: {
  60975 				0:  uint8(80),
  60976 				1:  uint8(129),
  60977 				2:  uint8(211),
  60978 				3:  uint8(255),
  60979 				4:  uint8(194),
  60980 				5:  uint8(224),
  60981 				6:  uint8(128),
  60982 				7:  uint8(128),
  60983 				8:  uint8(128),
  60984 				9:  uint8(128),
  60985 				10: uint8(128),
  60986 			},
  60987 		},
  60988 		7: {
  60989 			0: {
  60990 				0:  uint8(1),
  60991 				1:  uint8(1),
  60992 				2:  uint8(255),
  60993 				3:  uint8(128),
  60994 				4:  uint8(128),
  60995 				5:  uint8(128),
  60996 				6:  uint8(128),
  60997 				7:  uint8(128),
  60998 				8:  uint8(128),
  60999 				9:  uint8(128),
  61000 				10: uint8(128),
  61001 			},
  61002 			1: {
  61003 				0:  uint8(246),
  61004 				1:  uint8(1),
  61005 				2:  uint8(255),
  61006 				3:  uint8(128),
  61007 				4:  uint8(128),
  61008 				5:  uint8(128),
  61009 				6:  uint8(128),
  61010 				7:  uint8(128),
  61011 				8:  uint8(128),
  61012 				9:  uint8(128),
  61013 				10: uint8(128),
  61014 			},
  61015 			2: {
  61016 				0:  uint8(255),
  61017 				1:  uint8(128),
  61018 				2:  uint8(128),
  61019 				3:  uint8(128),
  61020 				4:  uint8(128),
  61021 				5:  uint8(128),
  61022 				6:  uint8(128),
  61023 				7:  uint8(128),
  61024 				8:  uint8(128),
  61025 				9:  uint8(128),
  61026 				10: uint8(128),
  61027 			},
  61028 		},
  61029 	},
  61030 	1: {
  61031 		0: {
  61032 			0: {
  61033 				0:  uint8(198),
  61034 				1:  uint8(35),
  61035 				2:  uint8(237),
  61036 				3:  uint8(223),
  61037 				4:  uint8(193),
  61038 				5:  uint8(187),
  61039 				6:  uint8(162),
  61040 				7:  uint8(160),
  61041 				8:  uint8(145),
  61042 				9:  uint8(155),
  61043 				10: uint8(62),
  61044 			},
  61045 			1: {
  61046 				0:  uint8(131),
  61047 				1:  uint8(45),
  61048 				2:  uint8(198),
  61049 				3:  uint8(221),
  61050 				4:  uint8(172),
  61051 				5:  uint8(176),
  61052 				6:  uint8(220),
  61053 				7:  uint8(157),
  61054 				8:  uint8(252),
  61055 				9:  uint8(221),
  61056 				10: uint8(1),
  61057 			},
  61058 			2: {
  61059 				0:  uint8(68),
  61060 				1:  uint8(47),
  61061 				2:  uint8(146),
  61062 				3:  uint8(208),
  61063 				4:  uint8(149),
  61064 				5:  uint8(167),
  61065 				6:  uint8(221),
  61066 				7:  uint8(162),
  61067 				8:  uint8(255),
  61068 				9:  uint8(223),
  61069 				10: uint8(128),
  61070 			},
  61071 		},
  61072 		1: {
  61073 			0: {
  61074 				0:  uint8(1),
  61075 				1:  uint8(149),
  61076 				2:  uint8(241),
  61077 				3:  uint8(255),
  61078 				4:  uint8(221),
  61079 				5:  uint8(224),
  61080 				6:  uint8(255),
  61081 				7:  uint8(255),
  61082 				8:  uint8(128),
  61083 				9:  uint8(128),
  61084 				10: uint8(128),
  61085 			},
  61086 			1: {
  61087 				0:  uint8(184),
  61088 				1:  uint8(141),
  61089 				2:  uint8(234),
  61090 				3:  uint8(253),
  61091 				4:  uint8(222),
  61092 				5:  uint8(220),
  61093 				6:  uint8(255),
  61094 				7:  uint8(199),
  61095 				8:  uint8(128),
  61096 				9:  uint8(128),
  61097 				10: uint8(128),
  61098 			},
  61099 			2: {
  61100 				0:  uint8(81),
  61101 				1:  uint8(99),
  61102 				2:  uint8(181),
  61103 				3:  uint8(242),
  61104 				4:  uint8(176),
  61105 				5:  uint8(190),
  61106 				6:  uint8(249),
  61107 				7:  uint8(202),
  61108 				8:  uint8(255),
  61109 				9:  uint8(255),
  61110 				10: uint8(128),
  61111 			},
  61112 		},
  61113 		2: {
  61114 			0: {
  61115 				0:  uint8(1),
  61116 				1:  uint8(129),
  61117 				2:  uint8(232),
  61118 				3:  uint8(253),
  61119 				4:  uint8(214),
  61120 				5:  uint8(197),
  61121 				6:  uint8(242),
  61122 				7:  uint8(196),
  61123 				8:  uint8(255),
  61124 				9:  uint8(255),
  61125 				10: uint8(128),
  61126 			},
  61127 			1: {
  61128 				0:  uint8(99),
  61129 				1:  uint8(121),
  61130 				2:  uint8(210),
  61131 				3:  uint8(250),
  61132 				4:  uint8(201),
  61133 				5:  uint8(198),
  61134 				6:  uint8(255),
  61135 				7:  uint8(202),
  61136 				8:  uint8(128),
  61137 				9:  uint8(128),
  61138 				10: uint8(128),
  61139 			},
  61140 			2: {
  61141 				0:  uint8(23),
  61142 				1:  uint8(91),
  61143 				2:  uint8(163),
  61144 				3:  uint8(242),
  61145 				4:  uint8(170),
  61146 				5:  uint8(187),
  61147 				6:  uint8(247),
  61148 				7:  uint8(210),
  61149 				8:  uint8(255),
  61150 				9:  uint8(255),
  61151 				10: uint8(128),
  61152 			},
  61153 		},
  61154 		3: {
  61155 			0: {
  61156 				0:  uint8(1),
  61157 				1:  uint8(200),
  61158 				2:  uint8(246),
  61159 				3:  uint8(255),
  61160 				4:  uint8(234),
  61161 				5:  uint8(255),
  61162 				6:  uint8(128),
  61163 				7:  uint8(128),
  61164 				8:  uint8(128),
  61165 				9:  uint8(128),
  61166 				10: uint8(128),
  61167 			},
  61168 			1: {
  61169 				0:  uint8(109),
  61170 				1:  uint8(178),
  61171 				2:  uint8(241),
  61172 				3:  uint8(255),
  61173 				4:  uint8(231),
  61174 				5:  uint8(245),
  61175 				6:  uint8(255),
  61176 				7:  uint8(255),
  61177 				8:  uint8(128),
  61178 				9:  uint8(128),
  61179 				10: uint8(128),
  61180 			},
  61181 			2: {
  61182 				0:  uint8(44),
  61183 				1:  uint8(130),
  61184 				2:  uint8(201),
  61185 				3:  uint8(253),
  61186 				4:  uint8(205),
  61187 				5:  uint8(192),
  61188 				6:  uint8(255),
  61189 				7:  uint8(255),
  61190 				8:  uint8(128),
  61191 				9:  uint8(128),
  61192 				10: uint8(128),
  61193 			},
  61194 		},
  61195 		4: {
  61196 			0: {
  61197 				0:  uint8(1),
  61198 				1:  uint8(132),
  61199 				2:  uint8(239),
  61200 				3:  uint8(251),
  61201 				4:  uint8(219),
  61202 				5:  uint8(209),
  61203 				6:  uint8(255),
  61204 				7:  uint8(165),
  61205 				8:  uint8(128),
  61206 				9:  uint8(128),
  61207 				10: uint8(128),
  61208 			},
  61209 			1: {
  61210 				0:  uint8(94),
  61211 				1:  uint8(136),
  61212 				2:  uint8(225),
  61213 				3:  uint8(251),
  61214 				4:  uint8(218),
  61215 				5:  uint8(190),
  61216 				6:  uint8(255),
  61217 				7:  uint8(255),
  61218 				8:  uint8(128),
  61219 				9:  uint8(128),
  61220 				10: uint8(128),
  61221 			},
  61222 			2: {
  61223 				0:  uint8(22),
  61224 				1:  uint8(100),
  61225 				2:  uint8(174),
  61226 				3:  uint8(245),
  61227 				4:  uint8(186),
  61228 				5:  uint8(161),
  61229 				6:  uint8(255),
  61230 				7:  uint8(199),
  61231 				8:  uint8(128),
  61232 				9:  uint8(128),
  61233 				10: uint8(128),
  61234 			},
  61235 		},
  61236 		5: {
  61237 			0: {
  61238 				0:  uint8(1),
  61239 				1:  uint8(182),
  61240 				2:  uint8(249),
  61241 				3:  uint8(255),
  61242 				4:  uint8(232),
  61243 				5:  uint8(235),
  61244 				6:  uint8(128),
  61245 				7:  uint8(128),
  61246 				8:  uint8(128),
  61247 				9:  uint8(128),
  61248 				10: uint8(128),
  61249 			},
  61250 			1: {
  61251 				0:  uint8(124),
  61252 				1:  uint8(143),
  61253 				2:  uint8(241),
  61254 				3:  uint8(255),
  61255 				4:  uint8(227),
  61256 				5:  uint8(234),
  61257 				6:  uint8(128),
  61258 				7:  uint8(128),
  61259 				8:  uint8(128),
  61260 				9:  uint8(128),
  61261 				10: uint8(128),
  61262 			},
  61263 			2: {
  61264 				0:  uint8(35),
  61265 				1:  uint8(77),
  61266 				2:  uint8(181),
  61267 				3:  uint8(251),
  61268 				4:  uint8(193),
  61269 				5:  uint8(211),
  61270 				6:  uint8(255),
  61271 				7:  uint8(205),
  61272 				8:  uint8(128),
  61273 				9:  uint8(128),
  61274 				10: uint8(128),
  61275 			},
  61276 		},
  61277 		6: {
  61278 			0: {
  61279 				0:  uint8(1),
  61280 				1:  uint8(157),
  61281 				2:  uint8(247),
  61282 				3:  uint8(255),
  61283 				4:  uint8(236),
  61284 				5:  uint8(231),
  61285 				6:  uint8(255),
  61286 				7:  uint8(255),
  61287 				8:  uint8(128),
  61288 				9:  uint8(128),
  61289 				10: uint8(128),
  61290 			},
  61291 			1: {
  61292 				0:  uint8(121),
  61293 				1:  uint8(141),
  61294 				2:  uint8(235),
  61295 				3:  uint8(255),
  61296 				4:  uint8(225),
  61297 				5:  uint8(227),
  61298 				6:  uint8(255),
  61299 				7:  uint8(255),
  61300 				8:  uint8(128),
  61301 				9:  uint8(128),
  61302 				10: uint8(128),
  61303 			},
  61304 			2: {
  61305 				0:  uint8(45),
  61306 				1:  uint8(99),
  61307 				2:  uint8(188),
  61308 				3:  uint8(251),
  61309 				4:  uint8(195),
  61310 				5:  uint8(217),
  61311 				6:  uint8(255),
  61312 				7:  uint8(224),
  61313 				8:  uint8(128),
  61314 				9:  uint8(128),
  61315 				10: uint8(128),
  61316 			},
  61317 		},
  61318 		7: {
  61319 			0: {
  61320 				0:  uint8(1),
  61321 				1:  uint8(1),
  61322 				2:  uint8(251),
  61323 				3:  uint8(255),
  61324 				4:  uint8(213),
  61325 				5:  uint8(255),
  61326 				6:  uint8(128),
  61327 				7:  uint8(128),
  61328 				8:  uint8(128),
  61329 				9:  uint8(128),
  61330 				10: uint8(128),
  61331 			},
  61332 			1: {
  61333 				0:  uint8(203),
  61334 				1:  uint8(1),
  61335 				2:  uint8(248),
  61336 				3:  uint8(255),
  61337 				4:  uint8(255),
  61338 				5:  uint8(128),
  61339 				6:  uint8(128),
  61340 				7:  uint8(128),
  61341 				8:  uint8(128),
  61342 				9:  uint8(128),
  61343 				10: uint8(128),
  61344 			},
  61345 			2: {
  61346 				0:  uint8(137),
  61347 				1:  uint8(1),
  61348 				2:  uint8(177),
  61349 				3:  uint8(255),
  61350 				4:  uint8(224),
  61351 				5:  uint8(255),
  61352 				6:  uint8(128),
  61353 				7:  uint8(128),
  61354 				8:  uint8(128),
  61355 				9:  uint8(128),
  61356 				10: uint8(128),
  61357 			},
  61358 		},
  61359 	},
  61360 	2: {
  61361 		0: {
  61362 			0: {
  61363 				0:  uint8(253),
  61364 				1:  uint8(9),
  61365 				2:  uint8(248),
  61366 				3:  uint8(251),
  61367 				4:  uint8(207),
  61368 				5:  uint8(208),
  61369 				6:  uint8(255),
  61370 				7:  uint8(192),
  61371 				8:  uint8(128),
  61372 				9:  uint8(128),
  61373 				10: uint8(128),
  61374 			},
  61375 			1: {
  61376 				0:  uint8(175),
  61377 				1:  uint8(13),
  61378 				2:  uint8(224),
  61379 				3:  uint8(243),
  61380 				4:  uint8(193),
  61381 				5:  uint8(185),
  61382 				6:  uint8(249),
  61383 				7:  uint8(198),
  61384 				8:  uint8(255),
  61385 				9:  uint8(255),
  61386 				10: uint8(128),
  61387 			},
  61388 			2: {
  61389 				0:  uint8(73),
  61390 				1:  uint8(17),
  61391 				2:  uint8(171),
  61392 				3:  uint8(221),
  61393 				4:  uint8(161),
  61394 				5:  uint8(179),
  61395 				6:  uint8(236),
  61396 				7:  uint8(167),
  61397 				8:  uint8(255),
  61398 				9:  uint8(234),
  61399 				10: uint8(128),
  61400 			},
  61401 		},
  61402 		1: {
  61403 			0: {
  61404 				0:  uint8(1),
  61405 				1:  uint8(95),
  61406 				2:  uint8(247),
  61407 				3:  uint8(253),
  61408 				4:  uint8(212),
  61409 				5:  uint8(183),
  61410 				6:  uint8(255),
  61411 				7:  uint8(255),
  61412 				8:  uint8(128),
  61413 				9:  uint8(128),
  61414 				10: uint8(128),
  61415 			},
  61416 			1: {
  61417 				0:  uint8(239),
  61418 				1:  uint8(90),
  61419 				2:  uint8(244),
  61420 				3:  uint8(250),
  61421 				4:  uint8(211),
  61422 				5:  uint8(209),
  61423 				6:  uint8(255),
  61424 				7:  uint8(255),
  61425 				8:  uint8(128),
  61426 				9:  uint8(128),
  61427 				10: uint8(128),
  61428 			},
  61429 			2: {
  61430 				0:  uint8(155),
  61431 				1:  uint8(77),
  61432 				2:  uint8(195),
  61433 				3:  uint8(248),
  61434 				4:  uint8(188),
  61435 				5:  uint8(195),
  61436 				6:  uint8(255),
  61437 				7:  uint8(255),
  61438 				8:  uint8(128),
  61439 				9:  uint8(128),
  61440 				10: uint8(128),
  61441 			},
  61442 		},
  61443 		2: {
  61444 			0: {
  61445 				0:  uint8(1),
  61446 				1:  uint8(24),
  61447 				2:  uint8(239),
  61448 				3:  uint8(251),
  61449 				4:  uint8(218),
  61450 				5:  uint8(219),
  61451 				6:  uint8(255),
  61452 				7:  uint8(205),
  61453 				8:  uint8(128),
  61454 				9:  uint8(128),
  61455 				10: uint8(128),
  61456 			},
  61457 			1: {
  61458 				0:  uint8(201),
  61459 				1:  uint8(51),
  61460 				2:  uint8(219),
  61461 				3:  uint8(255),
  61462 				4:  uint8(196),
  61463 				5:  uint8(186),
  61464 				6:  uint8(128),
  61465 				7:  uint8(128),
  61466 				8:  uint8(128),
  61467 				9:  uint8(128),
  61468 				10: uint8(128),
  61469 			},
  61470 			2: {
  61471 				0:  uint8(69),
  61472 				1:  uint8(46),
  61473 				2:  uint8(190),
  61474 				3:  uint8(239),
  61475 				4:  uint8(201),
  61476 				5:  uint8(218),
  61477 				6:  uint8(255),
  61478 				7:  uint8(228),
  61479 				8:  uint8(128),
  61480 				9:  uint8(128),
  61481 				10: uint8(128),
  61482 			},
  61483 		},
  61484 		3: {
  61485 			0: {
  61486 				0:  uint8(1),
  61487 				1:  uint8(191),
  61488 				2:  uint8(251),
  61489 				3:  uint8(255),
  61490 				4:  uint8(255),
  61491 				5:  uint8(128),
  61492 				6:  uint8(128),
  61493 				7:  uint8(128),
  61494 				8:  uint8(128),
  61495 				9:  uint8(128),
  61496 				10: uint8(128),
  61497 			},
  61498 			1: {
  61499 				0:  uint8(223),
  61500 				1:  uint8(165),
  61501 				2:  uint8(249),
  61502 				3:  uint8(255),
  61503 				4:  uint8(213),
  61504 				5:  uint8(255),
  61505 				6:  uint8(128),
  61506 				7:  uint8(128),
  61507 				8:  uint8(128),
  61508 				9:  uint8(128),
  61509 				10: uint8(128),
  61510 			},
  61511 			2: {
  61512 				0:  uint8(141),
  61513 				1:  uint8(124),
  61514 				2:  uint8(248),
  61515 				3:  uint8(255),
  61516 				4:  uint8(255),
  61517 				5:  uint8(128),
  61518 				6:  uint8(128),
  61519 				7:  uint8(128),
  61520 				8:  uint8(128),
  61521 				9:  uint8(128),
  61522 				10: uint8(128),
  61523 			},
  61524 		},
  61525 		4: {
  61526 			0: {
  61527 				0:  uint8(1),
  61528 				1:  uint8(16),
  61529 				2:  uint8(248),
  61530 				3:  uint8(255),
  61531 				4:  uint8(255),
  61532 				5:  uint8(128),
  61533 				6:  uint8(128),
  61534 				7:  uint8(128),
  61535 				8:  uint8(128),
  61536 				9:  uint8(128),
  61537 				10: uint8(128),
  61538 			},
  61539 			1: {
  61540 				0:  uint8(190),
  61541 				1:  uint8(36),
  61542 				2:  uint8(230),
  61543 				3:  uint8(255),
  61544 				4:  uint8(236),
  61545 				5:  uint8(255),
  61546 				6:  uint8(128),
  61547 				7:  uint8(128),
  61548 				8:  uint8(128),
  61549 				9:  uint8(128),
  61550 				10: uint8(128),
  61551 			},
  61552 			2: {
  61553 				0:  uint8(149),
  61554 				1:  uint8(1),
  61555 				2:  uint8(255),
  61556 				3:  uint8(128),
  61557 				4:  uint8(128),
  61558 				5:  uint8(128),
  61559 				6:  uint8(128),
  61560 				7:  uint8(128),
  61561 				8:  uint8(128),
  61562 				9:  uint8(128),
  61563 				10: uint8(128),
  61564 			},
  61565 		},
  61566 		5: {
  61567 			0: {
  61568 				0:  uint8(1),
  61569 				1:  uint8(226),
  61570 				2:  uint8(255),
  61571 				3:  uint8(128),
  61572 				4:  uint8(128),
  61573 				5:  uint8(128),
  61574 				6:  uint8(128),
  61575 				7:  uint8(128),
  61576 				8:  uint8(128),
  61577 				9:  uint8(128),
  61578 				10: uint8(128),
  61579 			},
  61580 			1: {
  61581 				0:  uint8(247),
  61582 				1:  uint8(192),
  61583 				2:  uint8(255),
  61584 				3:  uint8(128),
  61585 				4:  uint8(128),
  61586 				5:  uint8(128),
  61587 				6:  uint8(128),
  61588 				7:  uint8(128),
  61589 				8:  uint8(128),
  61590 				9:  uint8(128),
  61591 				10: uint8(128),
  61592 			},
  61593 			2: {
  61594 				0:  uint8(240),
  61595 				1:  uint8(128),
  61596 				2:  uint8(255),
  61597 				3:  uint8(128),
  61598 				4:  uint8(128),
  61599 				5:  uint8(128),
  61600 				6:  uint8(128),
  61601 				7:  uint8(128),
  61602 				8:  uint8(128),
  61603 				9:  uint8(128),
  61604 				10: uint8(128),
  61605 			},
  61606 		},
  61607 		6: {
  61608 			0: {
  61609 				0:  uint8(1),
  61610 				1:  uint8(134),
  61611 				2:  uint8(252),
  61612 				3:  uint8(255),
  61613 				4:  uint8(255),
  61614 				5:  uint8(128),
  61615 				6:  uint8(128),
  61616 				7:  uint8(128),
  61617 				8:  uint8(128),
  61618 				9:  uint8(128),
  61619 				10: uint8(128),
  61620 			},
  61621 			1: {
  61622 				0:  uint8(213),
  61623 				1:  uint8(62),
  61624 				2:  uint8(250),
  61625 				3:  uint8(255),
  61626 				4:  uint8(255),
  61627 				5:  uint8(128),
  61628 				6:  uint8(128),
  61629 				7:  uint8(128),
  61630 				8:  uint8(128),
  61631 				9:  uint8(128),
  61632 				10: uint8(128),
  61633 			},
  61634 			2: {
  61635 				0:  uint8(55),
  61636 				1:  uint8(93),
  61637 				2:  uint8(255),
  61638 				3:  uint8(128),
  61639 				4:  uint8(128),
  61640 				5:  uint8(128),
  61641 				6:  uint8(128),
  61642 				7:  uint8(128),
  61643 				8:  uint8(128),
  61644 				9:  uint8(128),
  61645 				10: uint8(128),
  61646 			},
  61647 		},
  61648 		7: {
  61649 			0: {
  61650 				0:  uint8(128),
  61651 				1:  uint8(128),
  61652 				2:  uint8(128),
  61653 				3:  uint8(128),
  61654 				4:  uint8(128),
  61655 				5:  uint8(128),
  61656 				6:  uint8(128),
  61657 				7:  uint8(128),
  61658 				8:  uint8(128),
  61659 				9:  uint8(128),
  61660 				10: uint8(128),
  61661 			},
  61662 			1: {
  61663 				0:  uint8(128),
  61664 				1:  uint8(128),
  61665 				2:  uint8(128),
  61666 				3:  uint8(128),
  61667 				4:  uint8(128),
  61668 				5:  uint8(128),
  61669 				6:  uint8(128),
  61670 				7:  uint8(128),
  61671 				8:  uint8(128),
  61672 				9:  uint8(128),
  61673 				10: uint8(128),
  61674 			},
  61675 			2: {
  61676 				0:  uint8(128),
  61677 				1:  uint8(128),
  61678 				2:  uint8(128),
  61679 				3:  uint8(128),
  61680 				4:  uint8(128),
  61681 				5:  uint8(128),
  61682 				6:  uint8(128),
  61683 				7:  uint8(128),
  61684 				8:  uint8(128),
  61685 				9:  uint8(128),
  61686 				10: uint8(128),
  61687 			},
  61688 		},
  61689 	},
  61690 	3: {
  61691 		0: {
  61692 			0: {
  61693 				0:  uint8(202),
  61694 				1:  uint8(24),
  61695 				2:  uint8(213),
  61696 				3:  uint8(235),
  61697 				4:  uint8(186),
  61698 				5:  uint8(191),
  61699 				6:  uint8(220),
  61700 				7:  uint8(160),
  61701 				8:  uint8(240),
  61702 				9:  uint8(175),
  61703 				10: uint8(255),
  61704 			},
  61705 			1: {
  61706 				0:  uint8(126),
  61707 				1:  uint8(38),
  61708 				2:  uint8(182),
  61709 				3:  uint8(232),
  61710 				4:  uint8(169),
  61711 				5:  uint8(184),
  61712 				6:  uint8(228),
  61713 				7:  uint8(174),
  61714 				8:  uint8(255),
  61715 				9:  uint8(187),
  61716 				10: uint8(128),
  61717 			},
  61718 			2: {
  61719 				0:  uint8(61),
  61720 				1:  uint8(46),
  61721 				2:  uint8(138),
  61722 				3:  uint8(219),
  61723 				4:  uint8(151),
  61724 				5:  uint8(178),
  61725 				6:  uint8(240),
  61726 				7:  uint8(170),
  61727 				8:  uint8(255),
  61728 				9:  uint8(216),
  61729 				10: uint8(128),
  61730 			},
  61731 		},
  61732 		1: {
  61733 			0: {
  61734 				0:  uint8(1),
  61735 				1:  uint8(112),
  61736 				2:  uint8(230),
  61737 				3:  uint8(250),
  61738 				4:  uint8(199),
  61739 				5:  uint8(191),
  61740 				6:  uint8(247),
  61741 				7:  uint8(159),
  61742 				8:  uint8(255),
  61743 				9:  uint8(255),
  61744 				10: uint8(128),
  61745 			},
  61746 			1: {
  61747 				0:  uint8(166),
  61748 				1:  uint8(109),
  61749 				2:  uint8(228),
  61750 				3:  uint8(252),
  61751 				4:  uint8(211),
  61752 				5:  uint8(215),
  61753 				6:  uint8(255),
  61754 				7:  uint8(174),
  61755 				8:  uint8(128),
  61756 				9:  uint8(128),
  61757 				10: uint8(128),
  61758 			},
  61759 			2: {
  61760 				0:  uint8(39),
  61761 				1:  uint8(77),
  61762 				2:  uint8(162),
  61763 				3:  uint8(232),
  61764 				4:  uint8(172),
  61765 				5:  uint8(180),
  61766 				6:  uint8(245),
  61767 				7:  uint8(178),
  61768 				8:  uint8(255),
  61769 				9:  uint8(255),
  61770 				10: uint8(128),
  61771 			},
  61772 		},
  61773 		2: {
  61774 			0: {
  61775 				0:  uint8(1),
  61776 				1:  uint8(52),
  61777 				2:  uint8(220),
  61778 				3:  uint8(246),
  61779 				4:  uint8(198),
  61780 				5:  uint8(199),
  61781 				6:  uint8(249),
  61782 				7:  uint8(220),
  61783 				8:  uint8(255),
  61784 				9:  uint8(255),
  61785 				10: uint8(128),
  61786 			},
  61787 			1: {
  61788 				0:  uint8(124),
  61789 				1:  uint8(74),
  61790 				2:  uint8(191),
  61791 				3:  uint8(243),
  61792 				4:  uint8(183),
  61793 				5:  uint8(193),
  61794 				6:  uint8(250),
  61795 				7:  uint8(221),
  61796 				8:  uint8(255),
  61797 				9:  uint8(255),
  61798 				10: uint8(128),
  61799 			},
  61800 			2: {
  61801 				0:  uint8(24),
  61802 				1:  uint8(71),
  61803 				2:  uint8(130),
  61804 				3:  uint8(219),
  61805 				4:  uint8(154),
  61806 				5:  uint8(170),
  61807 				6:  uint8(243),
  61808 				7:  uint8(182),
  61809 				8:  uint8(255),
  61810 				9:  uint8(255),
  61811 				10: uint8(128),
  61812 			},
  61813 		},
  61814 		3: {
  61815 			0: {
  61816 				0:  uint8(1),
  61817 				1:  uint8(182),
  61818 				2:  uint8(225),
  61819 				3:  uint8(249),
  61820 				4:  uint8(219),
  61821 				5:  uint8(240),
  61822 				6:  uint8(255),
  61823 				7:  uint8(224),
  61824 				8:  uint8(128),
  61825 				9:  uint8(128),
  61826 				10: uint8(128),
  61827 			},
  61828 			1: {
  61829 				0:  uint8(149),
  61830 				1:  uint8(150),
  61831 				2:  uint8(226),
  61832 				3:  uint8(252),
  61833 				4:  uint8(216),
  61834 				5:  uint8(205),
  61835 				6:  uint8(255),
  61836 				7:  uint8(171),
  61837 				8:  uint8(128),
  61838 				9:  uint8(128),
  61839 				10: uint8(128),
  61840 			},
  61841 			2: {
  61842 				0:  uint8(28),
  61843 				1:  uint8(108),
  61844 				2:  uint8(170),
  61845 				3:  uint8(242),
  61846 				4:  uint8(183),
  61847 				5:  uint8(194),
  61848 				6:  uint8(254),
  61849 				7:  uint8(223),
  61850 				8:  uint8(255),
  61851 				9:  uint8(255),
  61852 				10: uint8(128),
  61853 			},
  61854 		},
  61855 		4: {
  61856 			0: {
  61857 				0:  uint8(1),
  61858 				1:  uint8(81),
  61859 				2:  uint8(230),
  61860 				3:  uint8(252),
  61861 				4:  uint8(204),
  61862 				5:  uint8(203),
  61863 				6:  uint8(255),
  61864 				7:  uint8(192),
  61865 				8:  uint8(128),
  61866 				9:  uint8(128),
  61867 				10: uint8(128),
  61868 			},
  61869 			1: {
  61870 				0:  uint8(123),
  61871 				1:  uint8(102),
  61872 				2:  uint8(209),
  61873 				3:  uint8(247),
  61874 				4:  uint8(188),
  61875 				5:  uint8(196),
  61876 				6:  uint8(255),
  61877 				7:  uint8(233),
  61878 				8:  uint8(128),
  61879 				9:  uint8(128),
  61880 				10: uint8(128),
  61881 			},
  61882 			2: {
  61883 				0:  uint8(20),
  61884 				1:  uint8(95),
  61885 				2:  uint8(153),
  61886 				3:  uint8(243),
  61887 				4:  uint8(164),
  61888 				5:  uint8(173),
  61889 				6:  uint8(255),
  61890 				7:  uint8(203),
  61891 				8:  uint8(128),
  61892 				9:  uint8(128),
  61893 				10: uint8(128),
  61894 			},
  61895 		},
  61896 		5: {
  61897 			0: {
  61898 				0:  uint8(1),
  61899 				1:  uint8(222),
  61900 				2:  uint8(248),
  61901 				3:  uint8(255),
  61902 				4:  uint8(216),
  61903 				5:  uint8(213),
  61904 				6:  uint8(128),
  61905 				7:  uint8(128),
  61906 				8:  uint8(128),
  61907 				9:  uint8(128),
  61908 				10: uint8(128),
  61909 			},
  61910 			1: {
  61911 				0:  uint8(168),
  61912 				1:  uint8(175),
  61913 				2:  uint8(246),
  61914 				3:  uint8(252),
  61915 				4:  uint8(235),
  61916 				5:  uint8(205),
  61917 				6:  uint8(255),
  61918 				7:  uint8(255),
  61919 				8:  uint8(128),
  61920 				9:  uint8(128),
  61921 				10: uint8(128),
  61922 			},
  61923 			2: {
  61924 				0:  uint8(47),
  61925 				1:  uint8(116),
  61926 				2:  uint8(215),
  61927 				3:  uint8(255),
  61928 				4:  uint8(211),
  61929 				5:  uint8(212),
  61930 				6:  uint8(255),
  61931 				7:  uint8(255),
  61932 				8:  uint8(128),
  61933 				9:  uint8(128),
  61934 				10: uint8(128),
  61935 			},
  61936 		},
  61937 		6: {
  61938 			0: {
  61939 				0:  uint8(1),
  61940 				1:  uint8(121),
  61941 				2:  uint8(236),
  61942 				3:  uint8(253),
  61943 				4:  uint8(212),
  61944 				5:  uint8(214),
  61945 				6:  uint8(255),
  61946 				7:  uint8(255),
  61947 				8:  uint8(128),
  61948 				9:  uint8(128),
  61949 				10: uint8(128),
  61950 			},
  61951 			1: {
  61952 				0:  uint8(141),
  61953 				1:  uint8(84),
  61954 				2:  uint8(213),
  61955 				3:  uint8(252),
  61956 				4:  uint8(201),
  61957 				5:  uint8(202),
  61958 				6:  uint8(255),
  61959 				7:  uint8(219),
  61960 				8:  uint8(128),
  61961 				9:  uint8(128),
  61962 				10: uint8(128),
  61963 			},
  61964 			2: {
  61965 				0:  uint8(42),
  61966 				1:  uint8(80),
  61967 				2:  uint8(160),
  61968 				3:  uint8(240),
  61969 				4:  uint8(162),
  61970 				5:  uint8(185),
  61971 				6:  uint8(255),
  61972 				7:  uint8(205),
  61973 				8:  uint8(128),
  61974 				9:  uint8(128),
  61975 				10: uint8(128),
  61976 			},
  61977 		},
  61978 		7: {
  61979 			0: {
  61980 				0:  uint8(1),
  61981 				1:  uint8(1),
  61982 				2:  uint8(255),
  61983 				3:  uint8(128),
  61984 				4:  uint8(128),
  61985 				5:  uint8(128),
  61986 				6:  uint8(128),
  61987 				7:  uint8(128),
  61988 				8:  uint8(128),
  61989 				9:  uint8(128),
  61990 				10: uint8(128),
  61991 			},
  61992 			1: {
  61993 				0:  uint8(244),
  61994 				1:  uint8(1),
  61995 				2:  uint8(255),
  61996 				3:  uint8(128),
  61997 				4:  uint8(128),
  61998 				5:  uint8(128),
  61999 				6:  uint8(128),
  62000 				7:  uint8(128),
  62001 				8:  uint8(128),
  62002 				9:  uint8(128),
  62003 				10: uint8(128),
  62004 			},
  62005 			2: {
  62006 				0:  uint8(238),
  62007 				1:  uint8(1),
  62008 				2:  uint8(255),
  62009 				3:  uint8(128),
  62010 				4:  uint8(128),
  62011 				5:  uint8(128),
  62012 				6:  uint8(128),
  62013 				7:  uint8(128),
  62014 				8:  uint8(128),
  62015 				9:  uint8(128),
  62016 				10: uint8(128),
  62017 			},
  62018 		},
  62019 	},
  62020 }
  62021 
  62022 //------------------------------------------------------------------------------
  62023 // Paragraph 13
  62024 
  62025 var VP8CoeffsUpdateProba = [4][8][3][11]uint8_t{
  62026 	0: {
  62027 		0: {
  62028 			0: {
  62029 				0:  uint8(255),
  62030 				1:  uint8(255),
  62031 				2:  uint8(255),
  62032 				3:  uint8(255),
  62033 				4:  uint8(255),
  62034 				5:  uint8(255),
  62035 				6:  uint8(255),
  62036 				7:  uint8(255),
  62037 				8:  uint8(255),
  62038 				9:  uint8(255),
  62039 				10: uint8(255),
  62040 			},
  62041 			1: {
  62042 				0:  uint8(255),
  62043 				1:  uint8(255),
  62044 				2:  uint8(255),
  62045 				3:  uint8(255),
  62046 				4:  uint8(255),
  62047 				5:  uint8(255),
  62048 				6:  uint8(255),
  62049 				7:  uint8(255),
  62050 				8:  uint8(255),
  62051 				9:  uint8(255),
  62052 				10: uint8(255),
  62053 			},
  62054 			2: {
  62055 				0:  uint8(255),
  62056 				1:  uint8(255),
  62057 				2:  uint8(255),
  62058 				3:  uint8(255),
  62059 				4:  uint8(255),
  62060 				5:  uint8(255),
  62061 				6:  uint8(255),
  62062 				7:  uint8(255),
  62063 				8:  uint8(255),
  62064 				9:  uint8(255),
  62065 				10: uint8(255),
  62066 			},
  62067 		},
  62068 		1: {
  62069 			0: {
  62070 				0:  uint8(176),
  62071 				1:  uint8(246),
  62072 				2:  uint8(255),
  62073 				3:  uint8(255),
  62074 				4:  uint8(255),
  62075 				5:  uint8(255),
  62076 				6:  uint8(255),
  62077 				7:  uint8(255),
  62078 				8:  uint8(255),
  62079 				9:  uint8(255),
  62080 				10: uint8(255),
  62081 			},
  62082 			1: {
  62083 				0:  uint8(223),
  62084 				1:  uint8(241),
  62085 				2:  uint8(252),
  62086 				3:  uint8(255),
  62087 				4:  uint8(255),
  62088 				5:  uint8(255),
  62089 				6:  uint8(255),
  62090 				7:  uint8(255),
  62091 				8:  uint8(255),
  62092 				9:  uint8(255),
  62093 				10: uint8(255),
  62094 			},
  62095 			2: {
  62096 				0:  uint8(249),
  62097 				1:  uint8(253),
  62098 				2:  uint8(253),
  62099 				3:  uint8(255),
  62100 				4:  uint8(255),
  62101 				5:  uint8(255),
  62102 				6:  uint8(255),
  62103 				7:  uint8(255),
  62104 				8:  uint8(255),
  62105 				9:  uint8(255),
  62106 				10: uint8(255),
  62107 			},
  62108 		},
  62109 		2: {
  62110 			0: {
  62111 				0:  uint8(255),
  62112 				1:  uint8(244),
  62113 				2:  uint8(252),
  62114 				3:  uint8(255),
  62115 				4:  uint8(255),
  62116 				5:  uint8(255),
  62117 				6:  uint8(255),
  62118 				7:  uint8(255),
  62119 				8:  uint8(255),
  62120 				9:  uint8(255),
  62121 				10: uint8(255),
  62122 			},
  62123 			1: {
  62124 				0:  uint8(234),
  62125 				1:  uint8(254),
  62126 				2:  uint8(254),
  62127 				3:  uint8(255),
  62128 				4:  uint8(255),
  62129 				5:  uint8(255),
  62130 				6:  uint8(255),
  62131 				7:  uint8(255),
  62132 				8:  uint8(255),
  62133 				9:  uint8(255),
  62134 				10: uint8(255),
  62135 			},
  62136 			2: {
  62137 				0:  uint8(253),
  62138 				1:  uint8(255),
  62139 				2:  uint8(255),
  62140 				3:  uint8(255),
  62141 				4:  uint8(255),
  62142 				5:  uint8(255),
  62143 				6:  uint8(255),
  62144 				7:  uint8(255),
  62145 				8:  uint8(255),
  62146 				9:  uint8(255),
  62147 				10: uint8(255),
  62148 			},
  62149 		},
  62150 		3: {
  62151 			0: {
  62152 				0:  uint8(255),
  62153 				1:  uint8(246),
  62154 				2:  uint8(254),
  62155 				3:  uint8(255),
  62156 				4:  uint8(255),
  62157 				5:  uint8(255),
  62158 				6:  uint8(255),
  62159 				7:  uint8(255),
  62160 				8:  uint8(255),
  62161 				9:  uint8(255),
  62162 				10: uint8(255),
  62163 			},
  62164 			1: {
  62165 				0:  uint8(239),
  62166 				1:  uint8(253),
  62167 				2:  uint8(254),
  62168 				3:  uint8(255),
  62169 				4:  uint8(255),
  62170 				5:  uint8(255),
  62171 				6:  uint8(255),
  62172 				7:  uint8(255),
  62173 				8:  uint8(255),
  62174 				9:  uint8(255),
  62175 				10: uint8(255),
  62176 			},
  62177 			2: {
  62178 				0:  uint8(254),
  62179 				1:  uint8(255),
  62180 				2:  uint8(254),
  62181 				3:  uint8(255),
  62182 				4:  uint8(255),
  62183 				5:  uint8(255),
  62184 				6:  uint8(255),
  62185 				7:  uint8(255),
  62186 				8:  uint8(255),
  62187 				9:  uint8(255),
  62188 				10: uint8(255),
  62189 			},
  62190 		},
  62191 		4: {
  62192 			0: {
  62193 				0:  uint8(255),
  62194 				1:  uint8(248),
  62195 				2:  uint8(254),
  62196 				3:  uint8(255),
  62197 				4:  uint8(255),
  62198 				5:  uint8(255),
  62199 				6:  uint8(255),
  62200 				7:  uint8(255),
  62201 				8:  uint8(255),
  62202 				9:  uint8(255),
  62203 				10: uint8(255),
  62204 			},
  62205 			1: {
  62206 				0:  uint8(251),
  62207 				1:  uint8(255),
  62208 				2:  uint8(254),
  62209 				3:  uint8(255),
  62210 				4:  uint8(255),
  62211 				5:  uint8(255),
  62212 				6:  uint8(255),
  62213 				7:  uint8(255),
  62214 				8:  uint8(255),
  62215 				9:  uint8(255),
  62216 				10: uint8(255),
  62217 			},
  62218 			2: {
  62219 				0:  uint8(255),
  62220 				1:  uint8(255),
  62221 				2:  uint8(255),
  62222 				3:  uint8(255),
  62223 				4:  uint8(255),
  62224 				5:  uint8(255),
  62225 				6:  uint8(255),
  62226 				7:  uint8(255),
  62227 				8:  uint8(255),
  62228 				9:  uint8(255),
  62229 				10: uint8(255),
  62230 			},
  62231 		},
  62232 		5: {
  62233 			0: {
  62234 				0:  uint8(255),
  62235 				1:  uint8(253),
  62236 				2:  uint8(254),
  62237 				3:  uint8(255),
  62238 				4:  uint8(255),
  62239 				5:  uint8(255),
  62240 				6:  uint8(255),
  62241 				7:  uint8(255),
  62242 				8:  uint8(255),
  62243 				9:  uint8(255),
  62244 				10: uint8(255),
  62245 			},
  62246 			1: {
  62247 				0:  uint8(251),
  62248 				1:  uint8(254),
  62249 				2:  uint8(254),
  62250 				3:  uint8(255),
  62251 				4:  uint8(255),
  62252 				5:  uint8(255),
  62253 				6:  uint8(255),
  62254 				7:  uint8(255),
  62255 				8:  uint8(255),
  62256 				9:  uint8(255),
  62257 				10: uint8(255),
  62258 			},
  62259 			2: {
  62260 				0:  uint8(254),
  62261 				1:  uint8(255),
  62262 				2:  uint8(254),
  62263 				3:  uint8(255),
  62264 				4:  uint8(255),
  62265 				5:  uint8(255),
  62266 				6:  uint8(255),
  62267 				7:  uint8(255),
  62268 				8:  uint8(255),
  62269 				9:  uint8(255),
  62270 				10: uint8(255),
  62271 			},
  62272 		},
  62273 		6: {
  62274 			0: {
  62275 				0:  uint8(255),
  62276 				1:  uint8(254),
  62277 				2:  uint8(253),
  62278 				3:  uint8(255),
  62279 				4:  uint8(254),
  62280 				5:  uint8(255),
  62281 				6:  uint8(255),
  62282 				7:  uint8(255),
  62283 				8:  uint8(255),
  62284 				9:  uint8(255),
  62285 				10: uint8(255),
  62286 			},
  62287 			1: {
  62288 				0:  uint8(250),
  62289 				1:  uint8(255),
  62290 				2:  uint8(254),
  62291 				3:  uint8(255),
  62292 				4:  uint8(254),
  62293 				5:  uint8(255),
  62294 				6:  uint8(255),
  62295 				7:  uint8(255),
  62296 				8:  uint8(255),
  62297 				9:  uint8(255),
  62298 				10: uint8(255),
  62299 			},
  62300 			2: {
  62301 				0:  uint8(254),
  62302 				1:  uint8(255),
  62303 				2:  uint8(255),
  62304 				3:  uint8(255),
  62305 				4:  uint8(255),
  62306 				5:  uint8(255),
  62307 				6:  uint8(255),
  62308 				7:  uint8(255),
  62309 				8:  uint8(255),
  62310 				9:  uint8(255),
  62311 				10: uint8(255),
  62312 			},
  62313 		},
  62314 		7: {
  62315 			0: {
  62316 				0:  uint8(255),
  62317 				1:  uint8(255),
  62318 				2:  uint8(255),
  62319 				3:  uint8(255),
  62320 				4:  uint8(255),
  62321 				5:  uint8(255),
  62322 				6:  uint8(255),
  62323 				7:  uint8(255),
  62324 				8:  uint8(255),
  62325 				9:  uint8(255),
  62326 				10: uint8(255),
  62327 			},
  62328 			1: {
  62329 				0:  uint8(255),
  62330 				1:  uint8(255),
  62331 				2:  uint8(255),
  62332 				3:  uint8(255),
  62333 				4:  uint8(255),
  62334 				5:  uint8(255),
  62335 				6:  uint8(255),
  62336 				7:  uint8(255),
  62337 				8:  uint8(255),
  62338 				9:  uint8(255),
  62339 				10: uint8(255),
  62340 			},
  62341 			2: {
  62342 				0:  uint8(255),
  62343 				1:  uint8(255),
  62344 				2:  uint8(255),
  62345 				3:  uint8(255),
  62346 				4:  uint8(255),
  62347 				5:  uint8(255),
  62348 				6:  uint8(255),
  62349 				7:  uint8(255),
  62350 				8:  uint8(255),
  62351 				9:  uint8(255),
  62352 				10: uint8(255),
  62353 			},
  62354 		},
  62355 	},
  62356 	1: {
  62357 		0: {
  62358 			0: {
  62359 				0:  uint8(217),
  62360 				1:  uint8(255),
  62361 				2:  uint8(255),
  62362 				3:  uint8(255),
  62363 				4:  uint8(255),
  62364 				5:  uint8(255),
  62365 				6:  uint8(255),
  62366 				7:  uint8(255),
  62367 				8:  uint8(255),
  62368 				9:  uint8(255),
  62369 				10: uint8(255),
  62370 			},
  62371 			1: {
  62372 				0:  uint8(225),
  62373 				1:  uint8(252),
  62374 				2:  uint8(241),
  62375 				3:  uint8(253),
  62376 				4:  uint8(255),
  62377 				5:  uint8(255),
  62378 				6:  uint8(254),
  62379 				7:  uint8(255),
  62380 				8:  uint8(255),
  62381 				9:  uint8(255),
  62382 				10: uint8(255),
  62383 			},
  62384 			2: {
  62385 				0:  uint8(234),
  62386 				1:  uint8(250),
  62387 				2:  uint8(241),
  62388 				3:  uint8(250),
  62389 				4:  uint8(253),
  62390 				5:  uint8(255),
  62391 				6:  uint8(253),
  62392 				7:  uint8(254),
  62393 				8:  uint8(255),
  62394 				9:  uint8(255),
  62395 				10: uint8(255),
  62396 			},
  62397 		},
  62398 		1: {
  62399 			0: {
  62400 				0:  uint8(255),
  62401 				1:  uint8(254),
  62402 				2:  uint8(255),
  62403 				3:  uint8(255),
  62404 				4:  uint8(255),
  62405 				5:  uint8(255),
  62406 				6:  uint8(255),
  62407 				7:  uint8(255),
  62408 				8:  uint8(255),
  62409 				9:  uint8(255),
  62410 				10: uint8(255),
  62411 			},
  62412 			1: {
  62413 				0:  uint8(223),
  62414 				1:  uint8(254),
  62415 				2:  uint8(254),
  62416 				3:  uint8(255),
  62417 				4:  uint8(255),
  62418 				5:  uint8(255),
  62419 				6:  uint8(255),
  62420 				7:  uint8(255),
  62421 				8:  uint8(255),
  62422 				9:  uint8(255),
  62423 				10: uint8(255),
  62424 			},
  62425 			2: {
  62426 				0:  uint8(238),
  62427 				1:  uint8(253),
  62428 				2:  uint8(254),
  62429 				3:  uint8(254),
  62430 				4:  uint8(255),
  62431 				5:  uint8(255),
  62432 				6:  uint8(255),
  62433 				7:  uint8(255),
  62434 				8:  uint8(255),
  62435 				9:  uint8(255),
  62436 				10: uint8(255),
  62437 			},
  62438 		},
  62439 		2: {
  62440 			0: {
  62441 				0:  uint8(255),
  62442 				1:  uint8(248),
  62443 				2:  uint8(254),
  62444 				3:  uint8(255),
  62445 				4:  uint8(255),
  62446 				5:  uint8(255),
  62447 				6:  uint8(255),
  62448 				7:  uint8(255),
  62449 				8:  uint8(255),
  62450 				9:  uint8(255),
  62451 				10: uint8(255),
  62452 			},
  62453 			1: {
  62454 				0:  uint8(249),
  62455 				1:  uint8(254),
  62456 				2:  uint8(255),
  62457 				3:  uint8(255),
  62458 				4:  uint8(255),
  62459 				5:  uint8(255),
  62460 				6:  uint8(255),
  62461 				7:  uint8(255),
  62462 				8:  uint8(255),
  62463 				9:  uint8(255),
  62464 				10: uint8(255),
  62465 			},
  62466 			2: {
  62467 				0:  uint8(255),
  62468 				1:  uint8(255),
  62469 				2:  uint8(255),
  62470 				3:  uint8(255),
  62471 				4:  uint8(255),
  62472 				5:  uint8(255),
  62473 				6:  uint8(255),
  62474 				7:  uint8(255),
  62475 				8:  uint8(255),
  62476 				9:  uint8(255),
  62477 				10: uint8(255),
  62478 			},
  62479 		},
  62480 		3: {
  62481 			0: {
  62482 				0:  uint8(255),
  62483 				1:  uint8(253),
  62484 				2:  uint8(255),
  62485 				3:  uint8(255),
  62486 				4:  uint8(255),
  62487 				5:  uint8(255),
  62488 				6:  uint8(255),
  62489 				7:  uint8(255),
  62490 				8:  uint8(255),
  62491 				9:  uint8(255),
  62492 				10: uint8(255),
  62493 			},
  62494 			1: {
  62495 				0:  uint8(247),
  62496 				1:  uint8(254),
  62497 				2:  uint8(255),
  62498 				3:  uint8(255),
  62499 				4:  uint8(255),
  62500 				5:  uint8(255),
  62501 				6:  uint8(255),
  62502 				7:  uint8(255),
  62503 				8:  uint8(255),
  62504 				9:  uint8(255),
  62505 				10: uint8(255),
  62506 			},
  62507 			2: {
  62508 				0:  uint8(255),
  62509 				1:  uint8(255),
  62510 				2:  uint8(255),
  62511 				3:  uint8(255),
  62512 				4:  uint8(255),
  62513 				5:  uint8(255),
  62514 				6:  uint8(255),
  62515 				7:  uint8(255),
  62516 				8:  uint8(255),
  62517 				9:  uint8(255),
  62518 				10: uint8(255),
  62519 			},
  62520 		},
  62521 		4: {
  62522 			0: {
  62523 				0:  uint8(255),
  62524 				1:  uint8(253),
  62525 				2:  uint8(254),
  62526 				3:  uint8(255),
  62527 				4:  uint8(255),
  62528 				5:  uint8(255),
  62529 				6:  uint8(255),
  62530 				7:  uint8(255),
  62531 				8:  uint8(255),
  62532 				9:  uint8(255),
  62533 				10: uint8(255),
  62534 			},
  62535 			1: {
  62536 				0:  uint8(252),
  62537 				1:  uint8(255),
  62538 				2:  uint8(255),
  62539 				3:  uint8(255),
  62540 				4:  uint8(255),
  62541 				5:  uint8(255),
  62542 				6:  uint8(255),
  62543 				7:  uint8(255),
  62544 				8:  uint8(255),
  62545 				9:  uint8(255),
  62546 				10: uint8(255),
  62547 			},
  62548 			2: {
  62549 				0:  uint8(255),
  62550 				1:  uint8(255),
  62551 				2:  uint8(255),
  62552 				3:  uint8(255),
  62553 				4:  uint8(255),
  62554 				5:  uint8(255),
  62555 				6:  uint8(255),
  62556 				7:  uint8(255),
  62557 				8:  uint8(255),
  62558 				9:  uint8(255),
  62559 				10: uint8(255),
  62560 			},
  62561 		},
  62562 		5: {
  62563 			0: {
  62564 				0:  uint8(255),
  62565 				1:  uint8(254),
  62566 				2:  uint8(254),
  62567 				3:  uint8(255),
  62568 				4:  uint8(255),
  62569 				5:  uint8(255),
  62570 				6:  uint8(255),
  62571 				7:  uint8(255),
  62572 				8:  uint8(255),
  62573 				9:  uint8(255),
  62574 				10: uint8(255),
  62575 			},
  62576 			1: {
  62577 				0:  uint8(253),
  62578 				1:  uint8(255),
  62579 				2:  uint8(255),
  62580 				3:  uint8(255),
  62581 				4:  uint8(255),
  62582 				5:  uint8(255),
  62583 				6:  uint8(255),
  62584 				7:  uint8(255),
  62585 				8:  uint8(255),
  62586 				9:  uint8(255),
  62587 				10: uint8(255),
  62588 			},
  62589 			2: {
  62590 				0:  uint8(255),
  62591 				1:  uint8(255),
  62592 				2:  uint8(255),
  62593 				3:  uint8(255),
  62594 				4:  uint8(255),
  62595 				5:  uint8(255),
  62596 				6:  uint8(255),
  62597 				7:  uint8(255),
  62598 				8:  uint8(255),
  62599 				9:  uint8(255),
  62600 				10: uint8(255),
  62601 			},
  62602 		},
  62603 		6: {
  62604 			0: {
  62605 				0:  uint8(255),
  62606 				1:  uint8(254),
  62607 				2:  uint8(253),
  62608 				3:  uint8(255),
  62609 				4:  uint8(255),
  62610 				5:  uint8(255),
  62611 				6:  uint8(255),
  62612 				7:  uint8(255),
  62613 				8:  uint8(255),
  62614 				9:  uint8(255),
  62615 				10: uint8(255),
  62616 			},
  62617 			1: {
  62618 				0:  uint8(250),
  62619 				1:  uint8(255),
  62620 				2:  uint8(255),
  62621 				3:  uint8(255),
  62622 				4:  uint8(255),
  62623 				5:  uint8(255),
  62624 				6:  uint8(255),
  62625 				7:  uint8(255),
  62626 				8:  uint8(255),
  62627 				9:  uint8(255),
  62628 				10: uint8(255),
  62629 			},
  62630 			2: {
  62631 				0:  uint8(254),
  62632 				1:  uint8(255),
  62633 				2:  uint8(255),
  62634 				3:  uint8(255),
  62635 				4:  uint8(255),
  62636 				5:  uint8(255),
  62637 				6:  uint8(255),
  62638 				7:  uint8(255),
  62639 				8:  uint8(255),
  62640 				9:  uint8(255),
  62641 				10: uint8(255),
  62642 			},
  62643 		},
  62644 		7: {
  62645 			0: {
  62646 				0:  uint8(255),
  62647 				1:  uint8(255),
  62648 				2:  uint8(255),
  62649 				3:  uint8(255),
  62650 				4:  uint8(255),
  62651 				5:  uint8(255),
  62652 				6:  uint8(255),
  62653 				7:  uint8(255),
  62654 				8:  uint8(255),
  62655 				9:  uint8(255),
  62656 				10: uint8(255),
  62657 			},
  62658 			1: {
  62659 				0:  uint8(255),
  62660 				1:  uint8(255),
  62661 				2:  uint8(255),
  62662 				3:  uint8(255),
  62663 				4:  uint8(255),
  62664 				5:  uint8(255),
  62665 				6:  uint8(255),
  62666 				7:  uint8(255),
  62667 				8:  uint8(255),
  62668 				9:  uint8(255),
  62669 				10: uint8(255),
  62670 			},
  62671 			2: {
  62672 				0:  uint8(255),
  62673 				1:  uint8(255),
  62674 				2:  uint8(255),
  62675 				3:  uint8(255),
  62676 				4:  uint8(255),
  62677 				5:  uint8(255),
  62678 				6:  uint8(255),
  62679 				7:  uint8(255),
  62680 				8:  uint8(255),
  62681 				9:  uint8(255),
  62682 				10: uint8(255),
  62683 			},
  62684 		},
  62685 	},
  62686 	2: {
  62687 		0: {
  62688 			0: {
  62689 				0:  uint8(186),
  62690 				1:  uint8(251),
  62691 				2:  uint8(250),
  62692 				3:  uint8(255),
  62693 				4:  uint8(255),
  62694 				5:  uint8(255),
  62695 				6:  uint8(255),
  62696 				7:  uint8(255),
  62697 				8:  uint8(255),
  62698 				9:  uint8(255),
  62699 				10: uint8(255),
  62700 			},
  62701 			1: {
  62702 				0:  uint8(234),
  62703 				1:  uint8(251),
  62704 				2:  uint8(244),
  62705 				3:  uint8(254),
  62706 				4:  uint8(255),
  62707 				5:  uint8(255),
  62708 				6:  uint8(255),
  62709 				7:  uint8(255),
  62710 				8:  uint8(255),
  62711 				9:  uint8(255),
  62712 				10: uint8(255),
  62713 			},
  62714 			2: {
  62715 				0:  uint8(251),
  62716 				1:  uint8(251),
  62717 				2:  uint8(243),
  62718 				3:  uint8(253),
  62719 				4:  uint8(254),
  62720 				5:  uint8(255),
  62721 				6:  uint8(254),
  62722 				7:  uint8(255),
  62723 				8:  uint8(255),
  62724 				9:  uint8(255),
  62725 				10: uint8(255),
  62726 			},
  62727 		},
  62728 		1: {
  62729 			0: {
  62730 				0:  uint8(255),
  62731 				1:  uint8(253),
  62732 				2:  uint8(254),
  62733 				3:  uint8(255),
  62734 				4:  uint8(255),
  62735 				5:  uint8(255),
  62736 				6:  uint8(255),
  62737 				7:  uint8(255),
  62738 				8:  uint8(255),
  62739 				9:  uint8(255),
  62740 				10: uint8(255),
  62741 			},
  62742 			1: {
  62743 				0:  uint8(236),
  62744 				1:  uint8(253),
  62745 				2:  uint8(254),
  62746 				3:  uint8(255),
  62747 				4:  uint8(255),
  62748 				5:  uint8(255),
  62749 				6:  uint8(255),
  62750 				7:  uint8(255),
  62751 				8:  uint8(255),
  62752 				9:  uint8(255),
  62753 				10: uint8(255),
  62754 			},
  62755 			2: {
  62756 				0:  uint8(251),
  62757 				1:  uint8(253),
  62758 				2:  uint8(253),
  62759 				3:  uint8(254),
  62760 				4:  uint8(254),
  62761 				5:  uint8(255),
  62762 				6:  uint8(255),
  62763 				7:  uint8(255),
  62764 				8:  uint8(255),
  62765 				9:  uint8(255),
  62766 				10: uint8(255),
  62767 			},
  62768 		},
  62769 		2: {
  62770 			0: {
  62771 				0:  uint8(255),
  62772 				1:  uint8(254),
  62773 				2:  uint8(254),
  62774 				3:  uint8(255),
  62775 				4:  uint8(255),
  62776 				5:  uint8(255),
  62777 				6:  uint8(255),
  62778 				7:  uint8(255),
  62779 				8:  uint8(255),
  62780 				9:  uint8(255),
  62781 				10: uint8(255),
  62782 			},
  62783 			1: {
  62784 				0:  uint8(254),
  62785 				1:  uint8(254),
  62786 				2:  uint8(254),
  62787 				3:  uint8(255),
  62788 				4:  uint8(255),
  62789 				5:  uint8(255),
  62790 				6:  uint8(255),
  62791 				7:  uint8(255),
  62792 				8:  uint8(255),
  62793 				9:  uint8(255),
  62794 				10: uint8(255),
  62795 			},
  62796 			2: {
  62797 				0:  uint8(255),
  62798 				1:  uint8(255),
  62799 				2:  uint8(255),
  62800 				3:  uint8(255),
  62801 				4:  uint8(255),
  62802 				5:  uint8(255),
  62803 				6:  uint8(255),
  62804 				7:  uint8(255),
  62805 				8:  uint8(255),
  62806 				9:  uint8(255),
  62807 				10: uint8(255),
  62808 			},
  62809 		},
  62810 		3: {
  62811 			0: {
  62812 				0:  uint8(255),
  62813 				1:  uint8(254),
  62814 				2:  uint8(255),
  62815 				3:  uint8(255),
  62816 				4:  uint8(255),
  62817 				5:  uint8(255),
  62818 				6:  uint8(255),
  62819 				7:  uint8(255),
  62820 				8:  uint8(255),
  62821 				9:  uint8(255),
  62822 				10: uint8(255),
  62823 			},
  62824 			1: {
  62825 				0:  uint8(254),
  62826 				1:  uint8(254),
  62827 				2:  uint8(255),
  62828 				3:  uint8(255),
  62829 				4:  uint8(255),
  62830 				5:  uint8(255),
  62831 				6:  uint8(255),
  62832 				7:  uint8(255),
  62833 				8:  uint8(255),
  62834 				9:  uint8(255),
  62835 				10: uint8(255),
  62836 			},
  62837 			2: {
  62838 				0:  uint8(254),
  62839 				1:  uint8(255),
  62840 				2:  uint8(255),
  62841 				3:  uint8(255),
  62842 				4:  uint8(255),
  62843 				5:  uint8(255),
  62844 				6:  uint8(255),
  62845 				7:  uint8(255),
  62846 				8:  uint8(255),
  62847 				9:  uint8(255),
  62848 				10: uint8(255),
  62849 			},
  62850 		},
  62851 		4: {
  62852 			0: {
  62853 				0:  uint8(255),
  62854 				1:  uint8(255),
  62855 				2:  uint8(255),
  62856 				3:  uint8(255),
  62857 				4:  uint8(255),
  62858 				5:  uint8(255),
  62859 				6:  uint8(255),
  62860 				7:  uint8(255),
  62861 				8:  uint8(255),
  62862 				9:  uint8(255),
  62863 				10: uint8(255),
  62864 			},
  62865 			1: {
  62866 				0:  uint8(254),
  62867 				1:  uint8(255),
  62868 				2:  uint8(255),
  62869 				3:  uint8(255),
  62870 				4:  uint8(255),
  62871 				5:  uint8(255),
  62872 				6:  uint8(255),
  62873 				7:  uint8(255),
  62874 				8:  uint8(255),
  62875 				9:  uint8(255),
  62876 				10: uint8(255),
  62877 			},
  62878 			2: {
  62879 				0:  uint8(255),
  62880 				1:  uint8(255),
  62881 				2:  uint8(255),
  62882 				3:  uint8(255),
  62883 				4:  uint8(255),
  62884 				5:  uint8(255),
  62885 				6:  uint8(255),
  62886 				7:  uint8(255),
  62887 				8:  uint8(255),
  62888 				9:  uint8(255),
  62889 				10: uint8(255),
  62890 			},
  62891 		},
  62892 		5: {
  62893 			0: {
  62894 				0:  uint8(255),
  62895 				1:  uint8(255),
  62896 				2:  uint8(255),
  62897 				3:  uint8(255),
  62898 				4:  uint8(255),
  62899 				5:  uint8(255),
  62900 				6:  uint8(255),
  62901 				7:  uint8(255),
  62902 				8:  uint8(255),
  62903 				9:  uint8(255),
  62904 				10: uint8(255),
  62905 			},
  62906 			1: {
  62907 				0:  uint8(255),
  62908 				1:  uint8(255),
  62909 				2:  uint8(255),
  62910 				3:  uint8(255),
  62911 				4:  uint8(255),
  62912 				5:  uint8(255),
  62913 				6:  uint8(255),
  62914 				7:  uint8(255),
  62915 				8:  uint8(255),
  62916 				9:  uint8(255),
  62917 				10: uint8(255),
  62918 			},
  62919 			2: {
  62920 				0:  uint8(255),
  62921 				1:  uint8(255),
  62922 				2:  uint8(255),
  62923 				3:  uint8(255),
  62924 				4:  uint8(255),
  62925 				5:  uint8(255),
  62926 				6:  uint8(255),
  62927 				7:  uint8(255),
  62928 				8:  uint8(255),
  62929 				9:  uint8(255),
  62930 				10: uint8(255),
  62931 			},
  62932 		},
  62933 		6: {
  62934 			0: {
  62935 				0:  uint8(255),
  62936 				1:  uint8(255),
  62937 				2:  uint8(255),
  62938 				3:  uint8(255),
  62939 				4:  uint8(255),
  62940 				5:  uint8(255),
  62941 				6:  uint8(255),
  62942 				7:  uint8(255),
  62943 				8:  uint8(255),
  62944 				9:  uint8(255),
  62945 				10: uint8(255),
  62946 			},
  62947 			1: {
  62948 				0:  uint8(255),
  62949 				1:  uint8(255),
  62950 				2:  uint8(255),
  62951 				3:  uint8(255),
  62952 				4:  uint8(255),
  62953 				5:  uint8(255),
  62954 				6:  uint8(255),
  62955 				7:  uint8(255),
  62956 				8:  uint8(255),
  62957 				9:  uint8(255),
  62958 				10: uint8(255),
  62959 			},
  62960 			2: {
  62961 				0:  uint8(255),
  62962 				1:  uint8(255),
  62963 				2:  uint8(255),
  62964 				3:  uint8(255),
  62965 				4:  uint8(255),
  62966 				5:  uint8(255),
  62967 				6:  uint8(255),
  62968 				7:  uint8(255),
  62969 				8:  uint8(255),
  62970 				9:  uint8(255),
  62971 				10: uint8(255),
  62972 			},
  62973 		},
  62974 		7: {
  62975 			0: {
  62976 				0:  uint8(255),
  62977 				1:  uint8(255),
  62978 				2:  uint8(255),
  62979 				3:  uint8(255),
  62980 				4:  uint8(255),
  62981 				5:  uint8(255),
  62982 				6:  uint8(255),
  62983 				7:  uint8(255),
  62984 				8:  uint8(255),
  62985 				9:  uint8(255),
  62986 				10: uint8(255),
  62987 			},
  62988 			1: {
  62989 				0:  uint8(255),
  62990 				1:  uint8(255),
  62991 				2:  uint8(255),
  62992 				3:  uint8(255),
  62993 				4:  uint8(255),
  62994 				5:  uint8(255),
  62995 				6:  uint8(255),
  62996 				7:  uint8(255),
  62997 				8:  uint8(255),
  62998 				9:  uint8(255),
  62999 				10: uint8(255),
  63000 			},
  63001 			2: {
  63002 				0:  uint8(255),
  63003 				1:  uint8(255),
  63004 				2:  uint8(255),
  63005 				3:  uint8(255),
  63006 				4:  uint8(255),
  63007 				5:  uint8(255),
  63008 				6:  uint8(255),
  63009 				7:  uint8(255),
  63010 				8:  uint8(255),
  63011 				9:  uint8(255),
  63012 				10: uint8(255),
  63013 			},
  63014 		},
  63015 	},
  63016 	3: {
  63017 		0: {
  63018 			0: {
  63019 				0:  uint8(248),
  63020 				1:  uint8(255),
  63021 				2:  uint8(255),
  63022 				3:  uint8(255),
  63023 				4:  uint8(255),
  63024 				5:  uint8(255),
  63025 				6:  uint8(255),
  63026 				7:  uint8(255),
  63027 				8:  uint8(255),
  63028 				9:  uint8(255),
  63029 				10: uint8(255),
  63030 			},
  63031 			1: {
  63032 				0:  uint8(250),
  63033 				1:  uint8(254),
  63034 				2:  uint8(252),
  63035 				3:  uint8(254),
  63036 				4:  uint8(255),
  63037 				5:  uint8(255),
  63038 				6:  uint8(255),
  63039 				7:  uint8(255),
  63040 				8:  uint8(255),
  63041 				9:  uint8(255),
  63042 				10: uint8(255),
  63043 			},
  63044 			2: {
  63045 				0:  uint8(248),
  63046 				1:  uint8(254),
  63047 				2:  uint8(249),
  63048 				3:  uint8(253),
  63049 				4:  uint8(255),
  63050 				5:  uint8(255),
  63051 				6:  uint8(255),
  63052 				7:  uint8(255),
  63053 				8:  uint8(255),
  63054 				9:  uint8(255),
  63055 				10: uint8(255),
  63056 			},
  63057 		},
  63058 		1: {
  63059 			0: {
  63060 				0:  uint8(255),
  63061 				1:  uint8(253),
  63062 				2:  uint8(253),
  63063 				3:  uint8(255),
  63064 				4:  uint8(255),
  63065 				5:  uint8(255),
  63066 				6:  uint8(255),
  63067 				7:  uint8(255),
  63068 				8:  uint8(255),
  63069 				9:  uint8(255),
  63070 				10: uint8(255),
  63071 			},
  63072 			1: {
  63073 				0:  uint8(246),
  63074 				1:  uint8(253),
  63075 				2:  uint8(253),
  63076 				3:  uint8(255),
  63077 				4:  uint8(255),
  63078 				5:  uint8(255),
  63079 				6:  uint8(255),
  63080 				7:  uint8(255),
  63081 				8:  uint8(255),
  63082 				9:  uint8(255),
  63083 				10: uint8(255),
  63084 			},
  63085 			2: {
  63086 				0:  uint8(252),
  63087 				1:  uint8(254),
  63088 				2:  uint8(251),
  63089 				3:  uint8(254),
  63090 				4:  uint8(254),
  63091 				5:  uint8(255),
  63092 				6:  uint8(255),
  63093 				7:  uint8(255),
  63094 				8:  uint8(255),
  63095 				9:  uint8(255),
  63096 				10: uint8(255),
  63097 			},
  63098 		},
  63099 		2: {
  63100 			0: {
  63101 				0:  uint8(255),
  63102 				1:  uint8(254),
  63103 				2:  uint8(252),
  63104 				3:  uint8(255),
  63105 				4:  uint8(255),
  63106 				5:  uint8(255),
  63107 				6:  uint8(255),
  63108 				7:  uint8(255),
  63109 				8:  uint8(255),
  63110 				9:  uint8(255),
  63111 				10: uint8(255),
  63112 			},
  63113 			1: {
  63114 				0:  uint8(248),
  63115 				1:  uint8(254),
  63116 				2:  uint8(253),
  63117 				3:  uint8(255),
  63118 				4:  uint8(255),
  63119 				5:  uint8(255),
  63120 				6:  uint8(255),
  63121 				7:  uint8(255),
  63122 				8:  uint8(255),
  63123 				9:  uint8(255),
  63124 				10: uint8(255),
  63125 			},
  63126 			2: {
  63127 				0:  uint8(253),
  63128 				1:  uint8(255),
  63129 				2:  uint8(254),
  63130 				3:  uint8(254),
  63131 				4:  uint8(255),
  63132 				5:  uint8(255),
  63133 				6:  uint8(255),
  63134 				7:  uint8(255),
  63135 				8:  uint8(255),
  63136 				9:  uint8(255),
  63137 				10: uint8(255),
  63138 			},
  63139 		},
  63140 		3: {
  63141 			0: {
  63142 				0:  uint8(255),
  63143 				1:  uint8(251),
  63144 				2:  uint8(254),
  63145 				3:  uint8(255),
  63146 				4:  uint8(255),
  63147 				5:  uint8(255),
  63148 				6:  uint8(255),
  63149 				7:  uint8(255),
  63150 				8:  uint8(255),
  63151 				9:  uint8(255),
  63152 				10: uint8(255),
  63153 			},
  63154 			1: {
  63155 				0:  uint8(245),
  63156 				1:  uint8(251),
  63157 				2:  uint8(254),
  63158 				3:  uint8(255),
  63159 				4:  uint8(255),
  63160 				5:  uint8(255),
  63161 				6:  uint8(255),
  63162 				7:  uint8(255),
  63163 				8:  uint8(255),
  63164 				9:  uint8(255),
  63165 				10: uint8(255),
  63166 			},
  63167 			2: {
  63168 				0:  uint8(253),
  63169 				1:  uint8(253),
  63170 				2:  uint8(254),
  63171 				3:  uint8(255),
  63172 				4:  uint8(255),
  63173 				5:  uint8(255),
  63174 				6:  uint8(255),
  63175 				7:  uint8(255),
  63176 				8:  uint8(255),
  63177 				9:  uint8(255),
  63178 				10: uint8(255),
  63179 			},
  63180 		},
  63181 		4: {
  63182 			0: {
  63183 				0:  uint8(255),
  63184 				1:  uint8(251),
  63185 				2:  uint8(253),
  63186 				3:  uint8(255),
  63187 				4:  uint8(255),
  63188 				5:  uint8(255),
  63189 				6:  uint8(255),
  63190 				7:  uint8(255),
  63191 				8:  uint8(255),
  63192 				9:  uint8(255),
  63193 				10: uint8(255),
  63194 			},
  63195 			1: {
  63196 				0:  uint8(252),
  63197 				1:  uint8(253),
  63198 				2:  uint8(254),
  63199 				3:  uint8(255),
  63200 				4:  uint8(255),
  63201 				5:  uint8(255),
  63202 				6:  uint8(255),
  63203 				7:  uint8(255),
  63204 				8:  uint8(255),
  63205 				9:  uint8(255),
  63206 				10: uint8(255),
  63207 			},
  63208 			2: {
  63209 				0:  uint8(255),
  63210 				1:  uint8(254),
  63211 				2:  uint8(255),
  63212 				3:  uint8(255),
  63213 				4:  uint8(255),
  63214 				5:  uint8(255),
  63215 				6:  uint8(255),
  63216 				7:  uint8(255),
  63217 				8:  uint8(255),
  63218 				9:  uint8(255),
  63219 				10: uint8(255),
  63220 			},
  63221 		},
  63222 		5: {
  63223 			0: {
  63224 				0:  uint8(255),
  63225 				1:  uint8(252),
  63226 				2:  uint8(255),
  63227 				3:  uint8(255),
  63228 				4:  uint8(255),
  63229 				5:  uint8(255),
  63230 				6:  uint8(255),
  63231 				7:  uint8(255),
  63232 				8:  uint8(255),
  63233 				9:  uint8(255),
  63234 				10: uint8(255),
  63235 			},
  63236 			1: {
  63237 				0:  uint8(249),
  63238 				1:  uint8(255),
  63239 				2:  uint8(254),
  63240 				3:  uint8(255),
  63241 				4:  uint8(255),
  63242 				5:  uint8(255),
  63243 				6:  uint8(255),
  63244 				7:  uint8(255),
  63245 				8:  uint8(255),
  63246 				9:  uint8(255),
  63247 				10: uint8(255),
  63248 			},
  63249 			2: {
  63250 				0:  uint8(255),
  63251 				1:  uint8(255),
  63252 				2:  uint8(254),
  63253 				3:  uint8(255),
  63254 				4:  uint8(255),
  63255 				5:  uint8(255),
  63256 				6:  uint8(255),
  63257 				7:  uint8(255),
  63258 				8:  uint8(255),
  63259 				9:  uint8(255),
  63260 				10: uint8(255),
  63261 			},
  63262 		},
  63263 		6: {
  63264 			0: {
  63265 				0:  uint8(255),
  63266 				1:  uint8(255),
  63267 				2:  uint8(253),
  63268 				3:  uint8(255),
  63269 				4:  uint8(255),
  63270 				5:  uint8(255),
  63271 				6:  uint8(255),
  63272 				7:  uint8(255),
  63273 				8:  uint8(255),
  63274 				9:  uint8(255),
  63275 				10: uint8(255),
  63276 			},
  63277 			1: {
  63278 				0:  uint8(250),
  63279 				1:  uint8(255),
  63280 				2:  uint8(255),
  63281 				3:  uint8(255),
  63282 				4:  uint8(255),
  63283 				5:  uint8(255),
  63284 				6:  uint8(255),
  63285 				7:  uint8(255),
  63286 				8:  uint8(255),
  63287 				9:  uint8(255),
  63288 				10: uint8(255),
  63289 			},
  63290 			2: {
  63291 				0:  uint8(255),
  63292 				1:  uint8(255),
  63293 				2:  uint8(255),
  63294 				3:  uint8(255),
  63295 				4:  uint8(255),
  63296 				5:  uint8(255),
  63297 				6:  uint8(255),
  63298 				7:  uint8(255),
  63299 				8:  uint8(255),
  63300 				9:  uint8(255),
  63301 				10: uint8(255),
  63302 			},
  63303 		},
  63304 		7: {
  63305 			0: {
  63306 				0:  uint8(255),
  63307 				1:  uint8(255),
  63308 				2:  uint8(255),
  63309 				3:  uint8(255),
  63310 				4:  uint8(255),
  63311 				5:  uint8(255),
  63312 				6:  uint8(255),
  63313 				7:  uint8(255),
  63314 				8:  uint8(255),
  63315 				9:  uint8(255),
  63316 				10: uint8(255),
  63317 			},
  63318 			1: {
  63319 				0:  uint8(254),
  63320 				1:  uint8(255),
  63321 				2:  uint8(255),
  63322 				3:  uint8(255),
  63323 				4:  uint8(255),
  63324 				5:  uint8(255),
  63325 				6:  uint8(255),
  63326 				7:  uint8(255),
  63327 				8:  uint8(255),
  63328 				9:  uint8(255),
  63329 				10: uint8(255),
  63330 			},
  63331 			2: {
  63332 				0:  uint8(255),
  63333 				1:  uint8(255),
  63334 				2:  uint8(255),
  63335 				3:  uint8(255),
  63336 				4:  uint8(255),
  63337 				5:  uint8(255),
  63338 				6:  uint8(255),
  63339 				7:  uint8(255),
  63340 				8:  uint8(255),
  63341 				9:  uint8(255),
  63342 				10: uint8(255),
  63343 			},
  63344 		},
  63345 	},
  63346 }
  63347 
  63348 //------------------------------------------------------------------------------
  63349 // Initialization
  63350 
  63351 // C documentation
  63352 //
  63353 //	// Speed-critical function pointers. We have to initialize them to the default
  63354 //	// implementations within VP8EncDspInit().
  63355 var VP8CollectHistogram VP8CHisto
  63356 
  63357 var VP8Copy16x8 VP8BlockCopy
  63358 
  63359 var VP8Copy4x4 VP8BlockCopy
  63360 
  63361 var VP8DitherCombine8x8 uintptr
  63362 
  63363 //------------------------------------------------------------------------------
  63364 // Compute susceptibility based on DCT-coeff histograms:
  63365 // the higher, the "easier" the macroblock is to compress.
  63366 
  63367 var VP8DspScan = [24]int32{
  63368 	1:  libc.Int32FromInt32(4) + libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS),
  63369 	2:  libc.Int32FromInt32(8) + libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS),
  63370 	3:  libc.Int32FromInt32(12) + libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS),
  63371 	4:  libc.Int32FromInt32(0) + libc.Int32FromInt32(4)*libc.Int32FromInt32(BPS),
  63372 	5:  libc.Int32FromInt32(4) + libc.Int32FromInt32(4)*libc.Int32FromInt32(BPS),
  63373 	6:  libc.Int32FromInt32(8) + libc.Int32FromInt32(4)*libc.Int32FromInt32(BPS),
  63374 	7:  libc.Int32FromInt32(12) + libc.Int32FromInt32(4)*libc.Int32FromInt32(BPS),
  63375 	8:  libc.Int32FromInt32(0) + libc.Int32FromInt32(8)*libc.Int32FromInt32(BPS),
  63376 	9:  libc.Int32FromInt32(4) + libc.Int32FromInt32(8)*libc.Int32FromInt32(BPS),
  63377 	10: libc.Int32FromInt32(8) + libc.Int32FromInt32(8)*libc.Int32FromInt32(BPS),
  63378 	11: libc.Int32FromInt32(12) + libc.Int32FromInt32(8)*libc.Int32FromInt32(BPS),
  63379 	12: libc.Int32FromInt32(0) + libc.Int32FromInt32(12)*libc.Int32FromInt32(BPS),
  63380 	13: libc.Int32FromInt32(4) + libc.Int32FromInt32(12)*libc.Int32FromInt32(BPS),
  63381 	14: libc.Int32FromInt32(8) + libc.Int32FromInt32(12)*libc.Int32FromInt32(BPS),
  63382 	15: libc.Int32FromInt32(12) + libc.Int32FromInt32(12)*libc.Int32FromInt32(BPS),
  63383 	17: libc.Int32FromInt32(4) + libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS),
  63384 	18: libc.Int32FromInt32(0) + libc.Int32FromInt32(4)*libc.Int32FromInt32(BPS),
  63385 	19: libc.Int32FromInt32(4) + libc.Int32FromInt32(4)*libc.Int32FromInt32(BPS),
  63386 	20: libc.Int32FromInt32(8) + libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS),
  63387 	21: libc.Int32FromInt32(12) + libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS),
  63388 	22: libc.Int32FromInt32(8) + libc.Int32FromInt32(4)*libc.Int32FromInt32(BPS),
  63389 	23: libc.Int32FromInt32(12) + libc.Int32FromInt32(4)*libc.Int32FromInt32(BPS),
  63390 }
  63391 
  63392 //------------------------------------------------------------------------------
  63393 // Tables for level coding
  63394 
  63395 var VP8EncBands = [17]uint8_t{
  63396 	1:  uint8(1),
  63397 	2:  uint8(2),
  63398 	3:  uint8(3),
  63399 	4:  uint8(6),
  63400 	5:  uint8(4),
  63401 	6:  uint8(5),
  63402 	7:  uint8(6),
  63403 	8:  uint8(6),
  63404 	9:  uint8(6),
  63405 	10: uint8(6),
  63406 	11: uint8(6),
  63407 	12: uint8(6),
  63408 	13: uint8(6),
  63409 	14: uint8(6),
  63410 	15: uint8(7),
  63411 }
  63412 
  63413 var VP8EncPredChroma8 VP8IntraPreds
  63414 
  63415 var VP8EncPredLuma16 VP8IntraPreds
  63416 
  63417 var VP8EncPredLuma4 VP8Intra4Preds
  63418 
  63419 var VP8EncQuantize2Blocks VP8Quantize2Blocks
  63420 
  63421 var VP8EncQuantizeBlock VP8QuantizeBlock
  63422 
  63423 var VP8EncQuantizeBlockWHT VP8QuantizeBlockWHT
  63424 
  63425 //------------------------------------------------------------------------------
  63426 
  63427 // Copyright 2011 Google Inc. All Rights Reserved.
  63428 //
  63429 // Use of this source code is governed by a BSD-style license
  63430 // that can be found in the COPYING file in the root of the source
  63431 // tree. An additional intellectual property rights grant can be found
  63432 // in the file PATENTS. All contributing project authors may
  63433 // be found in the AUTHORS file in the root of the source tree.
  63434 // -----------------------------------------------------------------------------
  63435 //
  63436 //   WebP encoder: internal header.
  63437 //
  63438 // Author: Skal (pascal.massimino@gmail.com)
  63439 
  63440 //------------------------------------------------------------------------------
  63441 // Boolean-cost cost table
  63442 
  63443 var VP8EntropyCost = [256]uint16_t{
  63444 	0:   uint16(1792),
  63445 	1:   uint16(1792),
  63446 	2:   uint16(1792),
  63447 	3:   uint16(1536),
  63448 	4:   uint16(1536),
  63449 	5:   uint16(1408),
  63450 	6:   uint16(1366),
  63451 	7:   uint16(1280),
  63452 	8:   uint16(1280),
  63453 	9:   uint16(1216),
  63454 	10:  uint16(1178),
  63455 	11:  uint16(1152),
  63456 	12:  uint16(1110),
  63457 	13:  uint16(1076),
  63458 	14:  uint16(1061),
  63459 	15:  uint16(1024),
  63460 	16:  uint16(1024),
  63461 	17:  uint16(992),
  63462 	18:  uint16(968),
  63463 	19:  uint16(951),
  63464 	20:  uint16(939),
  63465 	21:  uint16(911),
  63466 	22:  uint16(896),
  63467 	23:  uint16(878),
  63468 	24:  uint16(871),
  63469 	25:  uint16(854),
  63470 	26:  uint16(838),
  63471 	27:  uint16(820),
  63472 	28:  uint16(811),
  63473 	29:  uint16(794),
  63474 	30:  uint16(786),
  63475 	31:  uint16(768),
  63476 	32:  uint16(768),
  63477 	33:  uint16(752),
  63478 	34:  uint16(740),
  63479 	35:  uint16(732),
  63480 	36:  uint16(720),
  63481 	37:  uint16(709),
  63482 	38:  uint16(704),
  63483 	39:  uint16(690),
  63484 	40:  uint16(683),
  63485 	41:  uint16(672),
  63486 	42:  uint16(666),
  63487 	43:  uint16(655),
  63488 	44:  uint16(647),
  63489 	45:  uint16(640),
  63490 	46:  uint16(631),
  63491 	47:  uint16(622),
  63492 	48:  uint16(615),
  63493 	49:  uint16(607),
  63494 	50:  uint16(598),
  63495 	51:  uint16(592),
  63496 	52:  uint16(586),
  63497 	53:  uint16(576),
  63498 	54:  uint16(572),
  63499 	55:  uint16(564),
  63500 	56:  uint16(559),
  63501 	57:  uint16(555),
  63502 	58:  uint16(547),
  63503 	59:  uint16(541),
  63504 	60:  uint16(534),
  63505 	61:  uint16(528),
  63506 	62:  uint16(522),
  63507 	63:  uint16(512),
  63508 	64:  uint16(512),
  63509 	65:  uint16(504),
  63510 	66:  uint16(500),
  63511 	67:  uint16(494),
  63512 	68:  uint16(488),
  63513 	69:  uint16(483),
  63514 	70:  uint16(477),
  63515 	71:  uint16(473),
  63516 	72:  uint16(467),
  63517 	73:  uint16(461),
  63518 	74:  uint16(458),
  63519 	75:  uint16(452),
  63520 	76:  uint16(448),
  63521 	77:  uint16(443),
  63522 	78:  uint16(438),
  63523 	79:  uint16(434),
  63524 	80:  uint16(427),
  63525 	81:  uint16(424),
  63526 	82:  uint16(419),
  63527 	83:  uint16(415),
  63528 	84:  uint16(410),
  63529 	85:  uint16(406),
  63530 	86:  uint16(403),
  63531 	87:  uint16(399),
  63532 	88:  uint16(394),
  63533 	89:  uint16(390),
  63534 	90:  uint16(384),
  63535 	91:  uint16(384),
  63536 	92:  uint16(377),
  63537 	93:  uint16(374),
  63538 	94:  uint16(370),
  63539 	95:  uint16(366),
  63540 	96:  uint16(362),
  63541 	97:  uint16(359),
  63542 	98:  uint16(355),
  63543 	99:  uint16(351),
  63544 	100: uint16(347),
  63545 	101: uint16(342),
  63546 	102: uint16(342),
  63547 	103: uint16(336),
  63548 	104: uint16(333),
  63549 	105: uint16(330),
  63550 	106: uint16(326),
  63551 	107: uint16(323),
  63552 	108: uint16(320),
  63553 	109: uint16(316),
  63554 	110: uint16(312),
  63555 	111: uint16(308),
  63556 	112: uint16(305),
  63557 	113: uint16(302),
  63558 	114: uint16(299),
  63559 	115: uint16(296),
  63560 	116: uint16(293),
  63561 	117: uint16(288),
  63562 	118: uint16(287),
  63563 	119: uint16(283),
  63564 	120: uint16(280),
  63565 	121: uint16(277),
  63566 	122: uint16(274),
  63567 	123: uint16(272),
  63568 	124: uint16(268),
  63569 	125: uint16(266),
  63570 	126: uint16(262),
  63571 	127: uint16(256),
  63572 	128: uint16(256),
  63573 	129: uint16(256),
  63574 	130: uint16(251),
  63575 	131: uint16(248),
  63576 	132: uint16(245),
  63577 	133: uint16(242),
  63578 	134: uint16(240),
  63579 	135: uint16(237),
  63580 	136: uint16(234),
  63581 	137: uint16(232),
  63582 	138: uint16(228),
  63583 	139: uint16(226),
  63584 	140: uint16(223),
  63585 	141: uint16(221),
  63586 	142: uint16(218),
  63587 	143: uint16(216),
  63588 	144: uint16(214),
  63589 	145: uint16(211),
  63590 	146: uint16(208),
  63591 	147: uint16(205),
  63592 	148: uint16(203),
  63593 	149: uint16(201),
  63594 	150: uint16(198),
  63595 	151: uint16(196),
  63596 	152: uint16(192),
  63597 	153: uint16(191),
  63598 	154: uint16(188),
  63599 	155: uint16(187),
  63600 	156: uint16(183),
  63601 	157: uint16(181),
  63602 	158: uint16(179),
  63603 	159: uint16(176),
  63604 	160: uint16(175),
  63605 	161: uint16(171),
  63606 	162: uint16(171),
  63607 	163: uint16(168),
  63608 	164: uint16(165),
  63609 	165: uint16(163),
  63610 	166: uint16(160),
  63611 	167: uint16(159),
  63612 	168: uint16(156),
  63613 	169: uint16(154),
  63614 	170: uint16(152),
  63615 	171: uint16(150),
  63616 	172: uint16(148),
  63617 	173: uint16(146),
  63618 	174: uint16(144),
  63619 	175: uint16(142),
  63620 	176: uint16(139),
  63621 	177: uint16(138),
  63622 	178: uint16(135),
  63623 	179: uint16(133),
  63624 	180: uint16(131),
  63625 	181: uint16(128),
  63626 	182: uint16(128),
  63627 	183: uint16(125),
  63628 	184: uint16(123),
  63629 	185: uint16(121),
  63630 	186: uint16(119),
  63631 	187: uint16(117),
  63632 	188: uint16(115),
  63633 	189: uint16(113),
  63634 	190: uint16(111),
  63635 	191: uint16(110),
  63636 	192: uint16(107),
  63637 	193: uint16(105),
  63638 	194: uint16(103),
  63639 	195: uint16(102),
  63640 	196: uint16(100),
  63641 	197: uint16(98),
  63642 	198: uint16(96),
  63643 	199: uint16(94),
  63644 	200: uint16(92),
  63645 	201: uint16(91),
  63646 	202: uint16(89),
  63647 	203: uint16(86),
  63648 	204: uint16(86),
  63649 	205: uint16(83),
  63650 	206: uint16(82),
  63651 	207: uint16(80),
  63652 	208: uint16(77),
  63653 	209: uint16(76),
  63654 	210: uint16(74),
  63655 	211: uint16(73),
  63656 	212: uint16(71),
  63657 	213: uint16(69),
  63658 	214: uint16(67),
  63659 	215: uint16(66),
  63660 	216: uint16(64),
  63661 	217: uint16(63),
  63662 	218: uint16(61),
  63663 	219: uint16(59),
  63664 	220: uint16(57),
  63665 	221: uint16(55),
  63666 	222: uint16(54),
  63667 	223: uint16(52),
  63668 	224: uint16(51),
  63669 	225: uint16(49),
  63670 	226: uint16(47),
  63671 	227: uint16(46),
  63672 	228: uint16(44),
  63673 	229: uint16(43),
  63674 	230: uint16(41),
  63675 	231: uint16(40),
  63676 	232: uint16(38),
  63677 	233: uint16(36),
  63678 	234: uint16(35),
  63679 	235: uint16(33),
  63680 	236: uint16(32),
  63681 	237: uint16(30),
  63682 	238: uint16(29),
  63683 	239: uint16(27),
  63684 	240: uint16(25),
  63685 	241: uint16(24),
  63686 	242: uint16(22),
  63687 	243: uint16(21),
  63688 	244: uint16(19),
  63689 	245: uint16(18),
  63690 	246: uint16(16),
  63691 	247: uint16(15),
  63692 	248: uint16(13),
  63693 	249: uint16(12),
  63694 	250: uint16(10),
  63695 	251: uint16(9),
  63696 	252: uint16(7),
  63697 	253: uint16(6),
  63698 	254: uint16(4),
  63699 	255: uint16(3),
  63700 }
  63701 
  63702 var VP8FTransform VP8Fdct
  63703 
  63704 var VP8FTransform2 VP8Fdct
  63705 
  63706 var VP8FTransformWHT VP8WHT
  63707 
  63708 // C documentation
  63709 //
  63710 //	// note: these values include the fixed VP8BitCost(1, 145) mode selection cost.
  63711 var VP8FixedCostsI16 = [4]uint16_t{
  63712 	0: uint16(663),
  63713 	1: uint16(919),
  63714 	2: uint16(872),
  63715 	3: uint16(919),
  63716 }
  63717 
  63718 var VP8FixedCostsI4 = [10][10][10]uint16_t{
  63719 	0: {
  63720 		0: {
  63721 			0: uint16(40),
  63722 			1: uint16(1151),
  63723 			2: uint16(1723),
  63724 			3: uint16(1874),
  63725 			4: uint16(2103),
  63726 			5: uint16(2019),
  63727 			6: uint16(1628),
  63728 			7: uint16(1777),
  63729 			8: uint16(2226),
  63730 			9: uint16(2137),
  63731 		},
  63732 		1: {
  63733 			0: uint16(192),
  63734 			1: uint16(469),
  63735 			2: uint16(1296),
  63736 			3: uint16(1308),
  63737 			4: uint16(1849),
  63738 			5: uint16(1794),
  63739 			6: uint16(1781),
  63740 			7: uint16(1703),
  63741 			8: uint16(1713),
  63742 			9: uint16(1522),
  63743 		},
  63744 		2: {
  63745 			0: uint16(142),
  63746 			1: uint16(910),
  63747 			2: uint16(762),
  63748 			3: uint16(1684),
  63749 			4: uint16(1849),
  63750 			5: uint16(1576),
  63751 			6: uint16(1460),
  63752 			7: uint16(1305),
  63753 			8: uint16(1801),
  63754 			9: uint16(1657),
  63755 		},
  63756 		3: {
  63757 			0: uint16(559),
  63758 			1: uint16(641),
  63759 			2: uint16(1370),
  63760 			3: uint16(421),
  63761 			4: uint16(1182),
  63762 			5: uint16(1569),
  63763 			6: uint16(1612),
  63764 			7: uint16(1725),
  63765 			8: uint16(863),
  63766 			9: uint16(1007),
  63767 		},
  63768 		4: {
  63769 			0: uint16(299),
  63770 			1: uint16(1059),
  63771 			2: uint16(1256),
  63772 			3: uint16(1108),
  63773 			4: uint16(636),
  63774 			5: uint16(1068),
  63775 			6: uint16(1581),
  63776 			7: uint16(1883),
  63777 			8: uint16(869),
  63778 			9: uint16(1142),
  63779 		},
  63780 		5: {
  63781 			0: uint16(277),
  63782 			1: uint16(1111),
  63783 			2: uint16(707),
  63784 			3: uint16(1362),
  63785 			4: uint16(1089),
  63786 			5: uint16(672),
  63787 			6: uint16(1603),
  63788 			7: uint16(1541),
  63789 			8: uint16(1545),
  63790 			9: uint16(1291),
  63791 		},
  63792 		6: {
  63793 			0: uint16(214),
  63794 			1: uint16(781),
  63795 			2: uint16(1609),
  63796 			3: uint16(1303),
  63797 			4: uint16(1632),
  63798 			5: uint16(2229),
  63799 			6: uint16(726),
  63800 			7: uint16(1560),
  63801 			8: uint16(1713),
  63802 			9: uint16(918),
  63803 		},
  63804 		7: {
  63805 			0: uint16(152),
  63806 			1: uint16(1037),
  63807 			2: uint16(1046),
  63808 			3: uint16(1759),
  63809 			4: uint16(1983),
  63810 			5: uint16(2174),
  63811 			6: uint16(1358),
  63812 			7: uint16(742),
  63813 			8: uint16(1740),
  63814 			9: uint16(1390),
  63815 		},
  63816 		8: {
  63817 			0: uint16(512),
  63818 			1: uint16(1046),
  63819 			2: uint16(1420),
  63820 			3: uint16(753),
  63821 			4: uint16(752),
  63822 			5: uint16(1297),
  63823 			6: uint16(1486),
  63824 			7: uint16(1613),
  63825 			8: uint16(460),
  63826 			9: uint16(1207),
  63827 		},
  63828 		9: {
  63829 			0: uint16(424),
  63830 			1: uint16(827),
  63831 			2: uint16(1362),
  63832 			3: uint16(719),
  63833 			4: uint16(1462),
  63834 			5: uint16(1202),
  63835 			6: uint16(1199),
  63836 			7: uint16(1476),
  63837 			8: uint16(1199),
  63838 			9: uint16(538),
  63839 		},
  63840 	},
  63841 	1: {
  63842 		0: {
  63843 			0: uint16(240),
  63844 			1: uint16(402),
  63845 			2: uint16(1134),
  63846 			3: uint16(1491),
  63847 			4: uint16(1659),
  63848 			5: uint16(1505),
  63849 			6: uint16(1517),
  63850 			7: uint16(1555),
  63851 			8: uint16(1979),
  63852 			9: uint16(2099),
  63853 		},
  63854 		1: {
  63855 			0: uint16(467),
  63856 			1: uint16(242),
  63857 			2: uint16(960),
  63858 			3: uint16(1232),
  63859 			4: uint16(1714),
  63860 			5: uint16(1620),
  63861 			6: uint16(1834),
  63862 			7: uint16(1570),
  63863 			8: uint16(1676),
  63864 			9: uint16(1391),
  63865 		},
  63866 		2: {
  63867 			0: uint16(500),
  63868 			1: uint16(455),
  63869 			2: uint16(463),
  63870 			3: uint16(1507),
  63871 			4: uint16(1699),
  63872 			5: uint16(1282),
  63873 			6: uint16(1564),
  63874 			7: uint16(982),
  63875 			8: uint16(2114),
  63876 			9: uint16(2114),
  63877 		},
  63878 		3: {
  63879 			0: uint16(672),
  63880 			1: uint16(643),
  63881 			2: uint16(1372),
  63882 			3: uint16(331),
  63883 			4: uint16(1589),
  63884 			5: uint16(1667),
  63885 			6: uint16(1453),
  63886 			7: uint16(1938),
  63887 			8: uint16(996),
  63888 			9: uint16(876),
  63889 		},
  63890 		4: {
  63891 			0: uint16(458),
  63892 			1: uint16(783),
  63893 			2: uint16(1037),
  63894 			3: uint16(911),
  63895 			4: uint16(738),
  63896 			5: uint16(968),
  63897 			6: uint16(1165),
  63898 			7: uint16(1518),
  63899 			8: uint16(859),
  63900 			9: uint16(1033),
  63901 		},
  63902 		5: {
  63903 			0: uint16(504),
  63904 			1: uint16(815),
  63905 			2: uint16(504),
  63906 			3: uint16(1139),
  63907 			4: uint16(1219),
  63908 			5: uint16(719),
  63909 			6: uint16(1506),
  63910 			7: uint16(1085),
  63911 			8: uint16(1268),
  63912 			9: uint16(1268),
  63913 		},
  63914 		6: {
  63915 			0: uint16(333),
  63916 			1: uint16(630),
  63917 			2: uint16(1445),
  63918 			3: uint16(1239),
  63919 			4: uint16(1883),
  63920 			5: uint16(3672),
  63921 			6: uint16(799),
  63922 			7: uint16(1548),
  63923 			8: uint16(1865),
  63924 			9: uint16(598),
  63925 		},
  63926 		7: {
  63927 			0: uint16(399),
  63928 			1: uint16(644),
  63929 			2: uint16(746),
  63930 			3: uint16(1342),
  63931 			4: uint16(1856),
  63932 			5: uint16(1350),
  63933 			6: uint16(1493),
  63934 			7: uint16(613),
  63935 			8: uint16(1855),
  63936 			9: uint16(1015),
  63937 		},
  63938 		8: {
  63939 			0: uint16(622),
  63940 			1: uint16(749),
  63941 			2: uint16(1205),
  63942 			3: uint16(608),
  63943 			4: uint16(1066),
  63944 			5: uint16(1408),
  63945 			6: uint16(1290),
  63946 			7: uint16(1406),
  63947 			8: uint16(546),
  63948 			9: uint16(971),
  63949 		},
  63950 		9: {
  63951 			0: uint16(500),
  63952 			1: uint16(753),
  63953 			2: uint16(1041),
  63954 			3: uint16(668),
  63955 			4: uint16(1230),
  63956 			5: uint16(1617),
  63957 			6: uint16(1297),
  63958 			7: uint16(1425),
  63959 			8: uint16(1383),
  63960 			9: uint16(523),
  63961 		},
  63962 	},
  63963 	2: {
  63964 		0: {
  63965 			0: uint16(394),
  63966 			1: uint16(553),
  63967 			2: uint16(523),
  63968 			3: uint16(1502),
  63969 			4: uint16(1536),
  63970 			5: uint16(981),
  63971 			6: uint16(1608),
  63972 			7: uint16(1142),
  63973 			8: uint16(1666),
  63974 			9: uint16(2181),
  63975 		},
  63976 		1: {
  63977 			0: uint16(655),
  63978 			1: uint16(430),
  63979 			2: uint16(375),
  63980 			3: uint16(1411),
  63981 			4: uint16(1861),
  63982 			5: uint16(1220),
  63983 			6: uint16(1677),
  63984 			7: uint16(1135),
  63985 			8: uint16(1978),
  63986 			9: uint16(1553),
  63987 		},
  63988 		2: {
  63989 			0: uint16(690),
  63990 			1: uint16(640),
  63991 			2: uint16(245),
  63992 			3: uint16(1954),
  63993 			4: uint16(2070),
  63994 			5: uint16(1194),
  63995 			6: uint16(1528),
  63996 			7: uint16(982),
  63997 			8: uint16(1972),
  63998 			9: uint16(2232),
  63999 		},
  64000 		3: {
  64001 			0: uint16(559),
  64002 			1: uint16(834),
  64003 			2: uint16(741),
  64004 			3: uint16(867),
  64005 			4: uint16(1131),
  64006 			5: uint16(980),
  64007 			6: uint16(1225),
  64008 			7: uint16(852),
  64009 			8: uint16(1092),
  64010 			9: uint16(784),
  64011 		},
  64012 		4: {
  64013 			0: uint16(690),
  64014 			1: uint16(875),
  64015 			2: uint16(516),
  64016 			3: uint16(959),
  64017 			4: uint16(673),
  64018 			5: uint16(894),
  64019 			6: uint16(1056),
  64020 			7: uint16(1190),
  64021 			8: uint16(1528),
  64022 			9: uint16(1126),
  64023 		},
  64024 		5: {
  64025 			0: uint16(740),
  64026 			1: uint16(951),
  64027 			2: uint16(384),
  64028 			3: uint16(1277),
  64029 			4: uint16(1177),
  64030 			5: uint16(492),
  64031 			6: uint16(1579),
  64032 			7: uint16(1155),
  64033 			8: uint16(1846),
  64034 			9: uint16(1513),
  64035 		},
  64036 		6: {
  64037 			0: uint16(323),
  64038 			1: uint16(775),
  64039 			2: uint16(1062),
  64040 			3: uint16(1776),
  64041 			4: uint16(3062),
  64042 			5: uint16(1274),
  64043 			6: uint16(813),
  64044 			7: uint16(1188),
  64045 			8: uint16(1372),
  64046 			9: uint16(655),
  64047 		},
  64048 		7: {
  64049 			0: uint16(488),
  64050 			1: uint16(971),
  64051 			2: uint16(484),
  64052 			3: uint16(1767),
  64053 			4: uint16(1515),
  64054 			5: uint16(1775),
  64055 			6: uint16(1115),
  64056 			7: uint16(503),
  64057 			8: uint16(1539),
  64058 			9: uint16(1461),
  64059 		},
  64060 		8: {
  64061 			0: uint16(740),
  64062 			1: uint16(1006),
  64063 			2: uint16(998),
  64064 			3: uint16(709),
  64065 			4: uint16(851),
  64066 			5: uint16(1230),
  64067 			6: uint16(1337),
  64068 			7: uint16(788),
  64069 			8: uint16(741),
  64070 			9: uint16(721),
  64071 		},
  64072 		9: {
  64073 			0: uint16(522),
  64074 			1: uint16(1073),
  64075 			2: uint16(573),
  64076 			3: uint16(1045),
  64077 			4: uint16(1346),
  64078 			5: uint16(887),
  64079 			6: uint16(1046),
  64080 			7: uint16(1146),
  64081 			8: uint16(1203),
  64082 			9: uint16(697),
  64083 		},
  64084 	},
  64085 	3: {
  64086 		0: {
  64087 			0: uint16(105),
  64088 			1: uint16(864),
  64089 			2: uint16(1442),
  64090 			3: uint16(1009),
  64091 			4: uint16(1934),
  64092 			5: uint16(1840),
  64093 			6: uint16(1519),
  64094 			7: uint16(1920),
  64095 			8: uint16(1673),
  64096 			9: uint16(1579),
  64097 		},
  64098 		1: {
  64099 			0: uint16(534),
  64100 			1: uint16(305),
  64101 			2: uint16(1193),
  64102 			3: uint16(683),
  64103 			4: uint16(1388),
  64104 			5: uint16(2164),
  64105 			6: uint16(1802),
  64106 			7: uint16(1894),
  64107 			8: uint16(1264),
  64108 			9: uint16(1170),
  64109 		},
  64110 		2: {
  64111 			0: uint16(305),
  64112 			1: uint16(518),
  64113 			2: uint16(877),
  64114 			3: uint16(1108),
  64115 			4: uint16(1426),
  64116 			5: uint16(3215),
  64117 			6: uint16(1425),
  64118 			7: uint16(1064),
  64119 			8: uint16(1320),
  64120 			9: uint16(1242),
  64121 		},
  64122 		3: {
  64123 			0: uint16(683),
  64124 			1: uint16(732),
  64125 			2: uint16(1927),
  64126 			3: uint16(257),
  64127 			4: uint16(1493),
  64128 			5: uint16(2048),
  64129 			6: uint16(1858),
  64130 			7: uint16(1552),
  64131 			8: uint16(1055),
  64132 			9: uint16(947),
  64133 		},
  64134 		4: {
  64135 			0: uint16(394),
  64136 			1: uint16(814),
  64137 			2: uint16(1024),
  64138 			3: uint16(660),
  64139 			4: uint16(959),
  64140 			5: uint16(1556),
  64141 			6: uint16(1282),
  64142 			7: uint16(1289),
  64143 			8: uint16(893),
  64144 			9: uint16(1047),
  64145 		},
  64146 		5: {
  64147 			0: uint16(528),
  64148 			1: uint16(615),
  64149 			2: uint16(996),
  64150 			3: uint16(940),
  64151 			4: uint16(1201),
  64152 			5: uint16(635),
  64153 			6: uint16(1094),
  64154 			7: uint16(2515),
  64155 			8: uint16(803),
  64156 			9: uint16(1358),
  64157 		},
  64158 		6: {
  64159 			0: uint16(347),
  64160 			1: uint16(614),
  64161 			2: uint16(1609),
  64162 			3: uint16(1187),
  64163 			4: uint16(3133),
  64164 			5: uint16(1345),
  64165 			6: uint16(1007),
  64166 			7: uint16(1339),
  64167 			8: uint16(1017),
  64168 			9: uint16(667),
  64169 		},
  64170 		7: {
  64171 			0: uint16(218),
  64172 			1: uint16(740),
  64173 			2: uint16(878),
  64174 			3: uint16(1605),
  64175 			4: uint16(3650),
  64176 			5: uint16(3650),
  64177 			6: uint16(1345),
  64178 			7: uint16(758),
  64179 			8: uint16(1357),
  64180 			9: uint16(1617),
  64181 		},
  64182 		8: {
  64183 			0: uint16(672),
  64184 			1: uint16(750),
  64185 			2: uint16(1541),
  64186 			3: uint16(558),
  64187 			4: uint16(1257),
  64188 			5: uint16(1599),
  64189 			6: uint16(1870),
  64190 			7: uint16(2135),
  64191 			8: uint16(402),
  64192 			9: uint16(1087),
  64193 		},
  64194 		9: {
  64195 			0: uint16(592),
  64196 			1: uint16(684),
  64197 			2: uint16(1161),
  64198 			3: uint16(430),
  64199 			4: uint16(1092),
  64200 			5: uint16(1497),
  64201 			6: uint16(1475),
  64202 			7: uint16(1489),
  64203 			8: uint16(1095),
  64204 			9: uint16(822),
  64205 		},
  64206 	},
  64207 	4: {
  64208 		0: {
  64209 			0: uint16(228),
  64210 			1: uint16(1056),
  64211 			2: uint16(1059),
  64212 			3: uint16(1368),
  64213 			4: uint16(752),
  64214 			5: uint16(982),
  64215 			6: uint16(1512),
  64216 			7: uint16(1518),
  64217 			8: uint16(987),
  64218 			9: uint16(1782),
  64219 		},
  64220 		1: {
  64221 			0: uint16(494),
  64222 			1: uint16(514),
  64223 			2: uint16(818),
  64224 			3: uint16(942),
  64225 			4: uint16(965),
  64226 			5: uint16(892),
  64227 			6: uint16(1610),
  64228 			7: uint16(1356),
  64229 			8: uint16(1048),
  64230 			9: uint16(1363),
  64231 		},
  64232 		2: {
  64233 			0: uint16(512),
  64234 			1: uint16(648),
  64235 			2: uint16(591),
  64236 			3: uint16(1042),
  64237 			4: uint16(761),
  64238 			5: uint16(991),
  64239 			6: uint16(1196),
  64240 			7: uint16(1454),
  64241 			8: uint16(1309),
  64242 			9: uint16(1463),
  64243 		},
  64244 		3: {
  64245 			0: uint16(683),
  64246 			1: uint16(749),
  64247 			2: uint16(1043),
  64248 			3: uint16(676),
  64249 			4: uint16(841),
  64250 			5: uint16(1396),
  64251 			6: uint16(1133),
  64252 			7: uint16(1138),
  64253 			8: uint16(654),
  64254 			9: uint16(939),
  64255 		},
  64256 		4: {
  64257 			0: uint16(622),
  64258 			1: uint16(1101),
  64259 			2: uint16(1126),
  64260 			3: uint16(994),
  64261 			4: uint16(361),
  64262 			5: uint16(1077),
  64263 			6: uint16(1203),
  64264 			7: uint16(1318),
  64265 			8: uint16(877),
  64266 			9: uint16(1219),
  64267 		},
  64268 		5: {
  64269 			0: uint16(631),
  64270 			1: uint16(1068),
  64271 			2: uint16(857),
  64272 			3: uint16(1650),
  64273 			4: uint16(651),
  64274 			5: uint16(477),
  64275 			6: uint16(1650),
  64276 			7: uint16(1419),
  64277 			8: uint16(828),
  64278 			9: uint16(1170),
  64279 		},
  64280 		6: {
  64281 			0: uint16(555),
  64282 			1: uint16(727),
  64283 			2: uint16(1068),
  64284 			3: uint16(1335),
  64285 			4: uint16(3127),
  64286 			5: uint16(1339),
  64287 			6: uint16(820),
  64288 			7: uint16(1331),
  64289 			8: uint16(1077),
  64290 			9: uint16(429),
  64291 		},
  64292 		7: {
  64293 			0: uint16(504),
  64294 			1: uint16(879),
  64295 			2: uint16(624),
  64296 			3: uint16(1398),
  64297 			4: uint16(889),
  64298 			5: uint16(889),
  64299 			6: uint16(1392),
  64300 			7: uint16(808),
  64301 			8: uint16(891),
  64302 			9: uint16(1406),
  64303 		},
  64304 		8: {
  64305 			0: uint16(683),
  64306 			1: uint16(1602),
  64307 			2: uint16(1289),
  64308 			3: uint16(977),
  64309 			4: uint16(578),
  64310 			5: uint16(983),
  64311 			6: uint16(1280),
  64312 			7: uint16(1708),
  64313 			8: uint16(406),
  64314 			9: uint16(1122),
  64315 		},
  64316 		9: {
  64317 			0: uint16(399),
  64318 			1: uint16(865),
  64319 			2: uint16(1433),
  64320 			3: uint16(1070),
  64321 			4: uint16(1072),
  64322 			5: uint16(764),
  64323 			6: uint16(968),
  64324 			7: uint16(1477),
  64325 			8: uint16(1223),
  64326 			9: uint16(678),
  64327 		},
  64328 	},
  64329 	5: {
  64330 		0: {
  64331 			0: uint16(333),
  64332 			1: uint16(760),
  64333 			2: uint16(935),
  64334 			3: uint16(1638),
  64335 			4: uint16(1010),
  64336 			5: uint16(529),
  64337 			6: uint16(1646),
  64338 			7: uint16(1410),
  64339 			8: uint16(1472),
  64340 			9: uint16(2219),
  64341 		},
  64342 		1: {
  64343 			0: uint16(512),
  64344 			1: uint16(494),
  64345 			2: uint16(750),
  64346 			3: uint16(1160),
  64347 			4: uint16(1215),
  64348 			5: uint16(610),
  64349 			6: uint16(1870),
  64350 			7: uint16(1868),
  64351 			8: uint16(1628),
  64352 			9: uint16(1169),
  64353 		},
  64354 		2: {
  64355 			0: uint16(572),
  64356 			1: uint16(646),
  64357 			2: uint16(492),
  64358 			3: uint16(1934),
  64359 			4: uint16(1208),
  64360 			5: uint16(603),
  64361 			6: uint16(1580),
  64362 			7: uint16(1099),
  64363 			8: uint16(1398),
  64364 			9: uint16(1995),
  64365 		},
  64366 		3: {
  64367 			0: uint16(786),
  64368 			1: uint16(789),
  64369 			2: uint16(942),
  64370 			3: uint16(581),
  64371 			4: uint16(1018),
  64372 			5: uint16(951),
  64373 			6: uint16(1599),
  64374 			7: uint16(1207),
  64375 			8: uint16(731),
  64376 			9: uint16(768),
  64377 		},
  64378 		4: {
  64379 			0: uint16(690),
  64380 			1: uint16(1015),
  64381 			2: uint16(672),
  64382 			3: uint16(1078),
  64383 			4: uint16(582),
  64384 			5: uint16(504),
  64385 			6: uint16(1693),
  64386 			7: uint16(1438),
  64387 			8: uint16(1108),
  64388 			9: uint16(2897),
  64389 		},
  64390 		5: {
  64391 			0: uint16(768),
  64392 			1: uint16(1267),
  64393 			2: uint16(571),
  64394 			3: uint16(2005),
  64395 			4: uint16(1243),
  64396 			5: uint16(244),
  64397 			6: uint16(2881),
  64398 			7: uint16(1380),
  64399 			8: uint16(1786),
  64400 			9: uint16(1453),
  64401 		},
  64402 		6: {
  64403 			0: uint16(452),
  64404 			1: uint16(899),
  64405 			2: uint16(1293),
  64406 			3: uint16(903),
  64407 			4: uint16(1311),
  64408 			5: uint16(3100),
  64409 			6: uint16(465),
  64410 			7: uint16(1311),
  64411 			8: uint16(1319),
  64412 			9: uint16(813),
  64413 		},
  64414 		7: {
  64415 			0: uint16(394),
  64416 			1: uint16(927),
  64417 			2: uint16(942),
  64418 			3: uint16(1103),
  64419 			4: uint16(1358),
  64420 			5: uint16(1104),
  64421 			6: uint16(946),
  64422 			7: uint16(593),
  64423 			8: uint16(1363),
  64424 			9: uint16(1109),
  64425 		},
  64426 		8: {
  64427 			0: uint16(559),
  64428 			1: uint16(1005),
  64429 			2: uint16(1007),
  64430 			3: uint16(1016),
  64431 			4: uint16(658),
  64432 			5: uint16(1173),
  64433 			6: uint16(1021),
  64434 			7: uint16(1164),
  64435 			8: uint16(623),
  64436 			9: uint16(1028),
  64437 		},
  64438 		9: {
  64439 			0: uint16(564),
  64440 			1: uint16(796),
  64441 			2: uint16(632),
  64442 			3: uint16(1005),
  64443 			4: uint16(1014),
  64444 			5: uint16(863),
  64445 			6: uint16(2316),
  64446 			7: uint16(1268),
  64447 			8: uint16(938),
  64448 			9: uint16(764),
  64449 		},
  64450 	},
  64451 	6: {
  64452 		0: {
  64453 			0: uint16(266),
  64454 			1: uint16(606),
  64455 			2: uint16(1098),
  64456 			3: uint16(1228),
  64457 			4: uint16(1497),
  64458 			5: uint16(1243),
  64459 			6: uint16(948),
  64460 			7: uint16(1030),
  64461 			8: uint16(1734),
  64462 			9: uint16(1461),
  64463 		},
  64464 		1: {
  64465 			0: uint16(366),
  64466 			1: uint16(585),
  64467 			2: uint16(901),
  64468 			3: uint16(1060),
  64469 			4: uint16(1407),
  64470 			5: uint16(1247),
  64471 			6: uint16(876),
  64472 			7: uint16(1134),
  64473 			8: uint16(1620),
  64474 			9: uint16(1054),
  64475 		},
  64476 		2: {
  64477 			0: uint16(452),
  64478 			1: uint16(565),
  64479 			2: uint16(542),
  64480 			3: uint16(1729),
  64481 			4: uint16(1479),
  64482 			5: uint16(1479),
  64483 			6: uint16(1016),
  64484 			7: uint16(886),
  64485 			8: uint16(2938),
  64486 			9: uint16(1150),
  64487 		},
  64488 		3: {
  64489 			0: uint16(555),
  64490 			1: uint16(1088),
  64491 			2: uint16(1533),
  64492 			3: uint16(950),
  64493 			4: uint16(1354),
  64494 			5: uint16(895),
  64495 			6: uint16(834),
  64496 			7: uint16(1019),
  64497 			8: uint16(1021),
  64498 			9: uint16(496),
  64499 		},
  64500 		4: {
  64501 			0: uint16(704),
  64502 			1: uint16(815),
  64503 			2: uint16(1193),
  64504 			3: uint16(971),
  64505 			4: uint16(973),
  64506 			5: uint16(640),
  64507 			6: uint16(1217),
  64508 			7: uint16(2214),
  64509 			8: uint16(832),
  64510 			9: uint16(578),
  64511 		},
  64512 		5: {
  64513 			0: uint16(672),
  64514 			1: uint16(1245),
  64515 			2: uint16(579),
  64516 			3: uint16(871),
  64517 			4: uint16(875),
  64518 			5: uint16(774),
  64519 			6: uint16(872),
  64520 			7: uint16(1273),
  64521 			8: uint16(1027),
  64522 			9: uint16(949),
  64523 		},
  64524 		6: {
  64525 			0: uint16(296),
  64526 			1: uint16(1134),
  64527 			2: uint16(2050),
  64528 			3: uint16(1784),
  64529 			4: uint16(1636),
  64530 			5: uint16(3425),
  64531 			6: uint16(442),
  64532 			7: uint16(1550),
  64533 			8: uint16(2076),
  64534 			9: uint16(722),
  64535 		},
  64536 		7: {
  64537 			0: uint16(342),
  64538 			1: uint16(982),
  64539 			2: uint16(1259),
  64540 			3: uint16(1846),
  64541 			4: uint16(1848),
  64542 			5: uint16(1848),
  64543 			6: uint16(622),
  64544 			7: uint16(568),
  64545 			8: uint16(1847),
  64546 			9: uint16(1052),
  64547 		},
  64548 		8: {
  64549 			0: uint16(555),
  64550 			1: uint16(1064),
  64551 			2: uint16(1304),
  64552 			3: uint16(828),
  64553 			4: uint16(746),
  64554 			5: uint16(1343),
  64555 			6: uint16(1075),
  64556 			7: uint16(1329),
  64557 			8: uint16(1078),
  64558 			9: uint16(494),
  64559 		},
  64560 		9: {
  64561 			0: uint16(288),
  64562 			1: uint16(1167),
  64563 			2: uint16(1285),
  64564 			3: uint16(1174),
  64565 			4: uint16(1639),
  64566 			5: uint16(1639),
  64567 			6: uint16(833),
  64568 			7: uint16(2254),
  64569 			8: uint16(1304),
  64570 			9: uint16(509),
  64571 		},
  64572 	},
  64573 	7: {
  64574 		0: {
  64575 			0: uint16(342),
  64576 			1: uint16(719),
  64577 			2: uint16(767),
  64578 			3: uint16(1866),
  64579 			4: uint16(1757),
  64580 			5: uint16(1270),
  64581 			6: uint16(1246),
  64582 			7: uint16(550),
  64583 			8: uint16(1746),
  64584 			9: uint16(2151),
  64585 		},
  64586 		1: {
  64587 			0: uint16(483),
  64588 			1: uint16(653),
  64589 			2: uint16(694),
  64590 			3: uint16(1509),
  64591 			4: uint16(1459),
  64592 			5: uint16(1410),
  64593 			6: uint16(1218),
  64594 			7: uint16(507),
  64595 			8: uint16(1914),
  64596 			9: uint16(1266),
  64597 		},
  64598 		2: {
  64599 			0: uint16(488),
  64600 			1: uint16(757),
  64601 			2: uint16(447),
  64602 			3: uint16(2979),
  64603 			4: uint16(1813),
  64604 			5: uint16(1268),
  64605 			6: uint16(1654),
  64606 			7: uint16(539),
  64607 			8: uint16(1849),
  64608 			9: uint16(2109),
  64609 		},
  64610 		3: {
  64611 			0: uint16(522),
  64612 			1: uint16(1097),
  64613 			2: uint16(1085),
  64614 			3: uint16(851),
  64615 			4: uint16(1365),
  64616 			5: uint16(1111),
  64617 			6: uint16(851),
  64618 			7: uint16(901),
  64619 			8: uint16(961),
  64620 			9: uint16(605),
  64621 		},
  64622 		4: {
  64623 			0: uint16(709),
  64624 			1: uint16(716),
  64625 			2: uint16(841),
  64626 			3: uint16(728),
  64627 			4: uint16(736),
  64628 			5: uint16(945),
  64629 			6: uint16(941),
  64630 			7: uint16(862),
  64631 			8: uint16(2845),
  64632 			9: uint16(1057),
  64633 		},
  64634 		5: {
  64635 			0: uint16(512),
  64636 			1: uint16(1323),
  64637 			2: uint16(500),
  64638 			3: uint16(1336),
  64639 			4: uint16(1083),
  64640 			5: uint16(681),
  64641 			6: uint16(1342),
  64642 			7: uint16(717),
  64643 			8: uint16(1604),
  64644 			9: uint16(1350),
  64645 		},
  64646 		6: {
  64647 			0: uint16(452),
  64648 			1: uint16(1155),
  64649 			2: uint16(1372),
  64650 			3: uint16(1900),
  64651 			4: uint16(1501),
  64652 			5: uint16(3290),
  64653 			6: uint16(311),
  64654 			7: uint16(944),
  64655 			8: uint16(1919),
  64656 			9: uint16(922),
  64657 		},
  64658 		7: {
  64659 			0: uint16(403),
  64660 			1: uint16(1520),
  64661 			2: uint16(977),
  64662 			3: uint16(2132),
  64663 			4: uint16(1733),
  64664 			5: uint16(3522),
  64665 			6: uint16(1076),
  64666 			7: uint16(276),
  64667 			8: uint16(3335),
  64668 			9: uint16(1547),
  64669 		},
  64670 		8: {
  64671 			0: uint16(559),
  64672 			1: uint16(1374),
  64673 			2: uint16(1101),
  64674 			3: uint16(615),
  64675 			4: uint16(673),
  64676 			5: uint16(2462),
  64677 			6: uint16(974),
  64678 			7: uint16(795),
  64679 			8: uint16(984),
  64680 			9: uint16(984),
  64681 		},
  64682 		9: {
  64683 			0: uint16(547),
  64684 			1: uint16(1122),
  64685 			2: uint16(1062),
  64686 			3: uint16(812),
  64687 			4: uint16(1410),
  64688 			5: uint16(951),
  64689 			6: uint16(1140),
  64690 			7: uint16(622),
  64691 			8: uint16(1268),
  64692 			9: uint16(651),
  64693 		},
  64694 	},
  64695 	8: {
  64696 		0: {
  64697 			0: uint16(165),
  64698 			1: uint16(982),
  64699 			2: uint16(1235),
  64700 			3: uint16(938),
  64701 			4: uint16(1334),
  64702 			5: uint16(1366),
  64703 			6: uint16(1659),
  64704 			7: uint16(1578),
  64705 			8: uint16(964),
  64706 			9: uint16(1612),
  64707 		},
  64708 		1: {
  64709 			0: uint16(592),
  64710 			1: uint16(422),
  64711 			2: uint16(925),
  64712 			3: uint16(847),
  64713 			4: uint16(1139),
  64714 			5: uint16(1112),
  64715 			6: uint16(1387),
  64716 			7: uint16(2036),
  64717 			8: uint16(861),
  64718 			9: uint16(1041),
  64719 		},
  64720 		2: {
  64721 			0: uint16(403),
  64722 			1: uint16(837),
  64723 			2: uint16(732),
  64724 			3: uint16(770),
  64725 			4: uint16(941),
  64726 			5: uint16(1658),
  64727 			6: uint16(1250),
  64728 			7: uint16(809),
  64729 			8: uint16(1407),
  64730 			9: uint16(1407),
  64731 		},
  64732 		3: {
  64733 			0: uint16(896),
  64734 			1: uint16(874),
  64735 			2: uint16(1071),
  64736 			3: uint16(381),
  64737 			4: uint16(1568),
  64738 			5: uint16(1722),
  64739 			6: uint16(1437),
  64740 			7: uint16(2192),
  64741 			8: uint16(480),
  64742 			9: uint16(1035),
  64743 		},
  64744 		4: {
  64745 			0: uint16(640),
  64746 			1: uint16(1098),
  64747 			2: uint16(1012),
  64748 			3: uint16(1032),
  64749 			4: uint16(684),
  64750 			5: uint16(1382),
  64751 			6: uint16(1581),
  64752 			7: uint16(2106),
  64753 			8: uint16(416),
  64754 			9: uint16(865),
  64755 		},
  64756 		5: {
  64757 			0: uint16(559),
  64758 			1: uint16(1005),
  64759 			2: uint16(819),
  64760 			3: uint16(914),
  64761 			4: uint16(710),
  64762 			5: uint16(770),
  64763 			6: uint16(1418),
  64764 			7: uint16(920),
  64765 			8: uint16(838),
  64766 			9: uint16(1435),
  64767 		},
  64768 		6: {
  64769 			0: uint16(415),
  64770 			1: uint16(1258),
  64771 			2: uint16(1245),
  64772 			3: uint16(870),
  64773 			4: uint16(1278),
  64774 			5: uint16(3067),
  64775 			6: uint16(770),
  64776 			7: uint16(1021),
  64777 			8: uint16(1287),
  64778 			9: uint16(522),
  64779 		},
  64780 		7: {
  64781 			0: uint16(406),
  64782 			1: uint16(990),
  64783 			2: uint16(601),
  64784 			3: uint16(1009),
  64785 			4: uint16(1265),
  64786 			5: uint16(1265),
  64787 			6: uint16(1267),
  64788 			7: uint16(759),
  64789 			8: uint16(1017),
  64790 			9: uint16(1277),
  64791 		},
  64792 		8: {
  64793 			0: uint16(968),
  64794 			1: uint16(1182),
  64795 			2: uint16(1329),
  64796 			3: uint16(788),
  64797 			4: uint16(1032),
  64798 			5: uint16(1292),
  64799 			6: uint16(1705),
  64800 			7: uint16(1714),
  64801 			8: uint16(203),
  64802 			9: uint16(1403),
  64803 		},
  64804 		9: {
  64805 			0: uint16(732),
  64806 			1: uint16(877),
  64807 			2: uint16(1279),
  64808 			3: uint16(471),
  64809 			4: uint16(901),
  64810 			5: uint16(1161),
  64811 			6: uint16(1545),
  64812 			7: uint16(1294),
  64813 			8: uint16(755),
  64814 			9: uint16(755),
  64815 		},
  64816 	},
  64817 	9: {
  64818 		0: {
  64819 			0: uint16(111),
  64820 			1: uint16(931),
  64821 			2: uint16(1378),
  64822 			3: uint16(1185),
  64823 			4: uint16(1933),
  64824 			5: uint16(1648),
  64825 			6: uint16(1148),
  64826 			7: uint16(1714),
  64827 			8: uint16(1873),
  64828 			9: uint16(1307),
  64829 		},
  64830 		1: {
  64831 			0: uint16(406),
  64832 			1: uint16(414),
  64833 			2: uint16(1030),
  64834 			3: uint16(1023),
  64835 			4: uint16(1910),
  64836 			5: uint16(1404),
  64837 			6: uint16(1313),
  64838 			7: uint16(1647),
  64839 			8: uint16(1509),
  64840 			9: uint16(793),
  64841 		},
  64842 		2: {
  64843 			0: uint16(342),
  64844 			1: uint16(640),
  64845 			2: uint16(575),
  64846 			3: uint16(1088),
  64847 			4: uint16(1241),
  64848 			5: uint16(1349),
  64849 			6: uint16(1161),
  64850 			7: uint16(1350),
  64851 			8: uint16(1756),
  64852 			9: uint16(1502),
  64853 		},
  64854 		3: {
  64855 			0: uint16(559),
  64856 			1: uint16(766),
  64857 			2: uint16(1185),
  64858 			3: uint16(357),
  64859 			4: uint16(1682),
  64860 			5: uint16(1428),
  64861 			6: uint16(1329),
  64862 			7: uint16(1897),
  64863 			8: uint16(1219),
  64864 			9: uint16(802),
  64865 		},
  64866 		4: {
  64867 			0: uint16(473),
  64868 			1: uint16(909),
  64869 			2: uint16(1164),
  64870 			3: uint16(771),
  64871 			4: uint16(719),
  64872 			5: uint16(2508),
  64873 			6: uint16(1427),
  64874 			7: uint16(1432),
  64875 			8: uint16(722),
  64876 			9: uint16(782),
  64877 		},
  64878 		5: {
  64879 			0: uint16(342),
  64880 			1: uint16(892),
  64881 			2: uint16(785),
  64882 			3: uint16(1145),
  64883 			4: uint16(1150),
  64884 			5: uint16(794),
  64885 			6: uint16(1296),
  64886 			7: uint16(1550),
  64887 			8: uint16(973),
  64888 			9: uint16(1057),
  64889 		},
  64890 		6: {
  64891 			0: uint16(208),
  64892 			1: uint16(1036),
  64893 			2: uint16(1326),
  64894 			3: uint16(1343),
  64895 			4: uint16(1606),
  64896 			5: uint16(3395),
  64897 			6: uint16(815),
  64898 			7: uint16(1455),
  64899 			8: uint16(1618),
  64900 			9: uint16(712),
  64901 		},
  64902 		7: {
  64903 			0: uint16(228),
  64904 			1: uint16(928),
  64905 			2: uint16(890),
  64906 			3: uint16(1046),
  64907 			4: uint16(3499),
  64908 			5: uint16(1711),
  64909 			6: uint16(994),
  64910 			7: uint16(829),
  64911 			8: uint16(1720),
  64912 			9: uint16(1318),
  64913 		},
  64914 		8: {
  64915 			0: uint16(768),
  64916 			1: uint16(724),
  64917 			2: uint16(1058),
  64918 			3: uint16(636),
  64919 			4: uint16(991),
  64920 			5: uint16(1075),
  64921 			6: uint16(1319),
  64922 			7: uint16(1324),
  64923 			8: uint16(616),
  64924 			9: uint16(825),
  64925 		},
  64926 		9: {
  64927 			0: uint16(305),
  64928 			1: uint16(1167),
  64929 			2: uint16(1358),
  64930 			3: uint16(899),
  64931 			4: uint16(1587),
  64932 			5: uint16(1587),
  64933 			6: uint16(987),
  64934 			7: uint16(1988),
  64935 			8: uint16(1332),
  64936 			9: uint16(501),
  64937 		},
  64938 	},
  64939 }
  64940 
  64941 //------------------------------------------------------------------------------
  64942 // Mode cost tables.
  64943 
  64944 // C documentation
  64945 //
  64946 //	// These are the fixed probabilities (in the coding trees) turned into bit-cost
  64947 //	// by calling VP8BitCost().
  64948 var VP8FixedCostsUV = [4]uint16_t{
  64949 	0: uint16(302),
  64950 	1: uint16(984),
  64951 	2: uint16(439),
  64952 	3: uint16(642),
  64953 }
  64954 
  64955 var VP8GetCPUInfo = uintptr(0)
  64956 
  64957 //------------------------------------------------------------------------------
  64958 // init function
  64959 
  64960 var VP8GetResidualCost VP8GetResidualCostFunc
  64961 
  64962 var VP8HFilter16 VP8LumaFilterFunc
  64963 
  64964 var VP8HFilter16i VP8LumaFilterFunc
  64965 
  64966 var VP8HFilter8 VP8ChromaFilterFunc
  64967 
  64968 var VP8HFilter8i VP8ChromaFilterFunc
  64969 
  64970 //------------------------------------------------------------------------------
  64971 // Form the predictions in cache
  64972 
  64973 // C documentation
  64974 //
  64975 //	// Must be ordered using {DC_PRED, TM_PRED, V_PRED, H_PRED} as index
  64976 var VP8I16ModeOffsets = [4]uint16_t{
  64977 	1: uint16(libc.Int32FromInt32(0)*libc.Int32FromInt32(16)*libc.Int32FromInt32(BPS) + libc.Int32FromInt32(16)),
  64978 	2: uint16(libc.Int32FromInt32(1) * libc.Int32FromInt32(16) * libc.Int32FromInt32(BPS)),
  64979 	3: uint16(libc.Int32FromInt32(1)*libc.Int32FromInt32(16)*libc.Int32FromInt32(BPS) + libc.Int32FromInt32(16)),
  64980 }
  64981 
  64982 var VP8ITransform VP8Idct
  64983 
  64984 //------------------------------------------------------------------------------
  64985 
  64986 var VP8LAddGreenToBlueAndRed VP8LProcessDecBlueAndRedFunc
  64987 
  64988 var VP8LAddGreenToBlueAndRed_SSE VP8LProcessDecBlueAndRedFunc
  64989 
  64990 var VP8LAddVector VP8LAddVectorFunc
  64991 
  64992 var VP8LAddVectorEq VP8LAddVectorEqFunc
  64993 
  64994 var VP8LBundleColorMap VP8LBundleColorMapFunc
  64995 
  64996 var VP8LBundleColorMap_SSE VP8LBundleColorMapFunc
  64997 
  64998 var VP8LCollectColorBlueTransforms VP8LCollectColorBlueTransformsFunc
  64999 
  65000 var VP8LCollectColorBlueTransforms_SSE VP8LCollectColorBlueTransformsFunc
  65001 
  65002 var VP8LCollectColorRedTransforms VP8LCollectColorRedTransformsFunc
  65003 
  65004 var VP8LCollectColorRedTransforms_SSE VP8LCollectColorRedTransformsFunc
  65005 
  65006 var VP8LCombinedShannonEntropy VP8LCombinedShannonEntropyFunc
  65007 
  65008 var VP8LConvertBGRAToBGR VP8LConvertFunc
  65009 
  65010 var VP8LConvertBGRAToRGB VP8LConvertFunc
  65011 
  65012 var VP8LConvertBGRAToRGB565 VP8LConvertFunc
  65013 
  65014 var VP8LConvertBGRAToRGBA VP8LConvertFunc
  65015 
  65016 var VP8LConvertBGRAToRGBA4444 VP8LConvertFunc
  65017 
  65018 var VP8LConvertBGRAToRGBA_SSE VP8LConvertFunc
  65019 
  65020 var VP8LConvertBGRAToRGB_SSE VP8LConvertFunc
  65021 
  65022 var VP8LExtraCost VP8LCostFunc
  65023 
  65024 var VP8LFastLog2Slow VP8LFastLog2SlowFunc
  65025 
  65026 var VP8LFastSLog2Slow VP8LFastSLog2SlowFunc
  65027 
  65028 var VP8LGetCombinedEntropyUnrefined VP8LGetCombinedEntropyUnrefinedFunc
  65029 
  65030 var VP8LGetEntropyUnrefined VP8LGetEntropyUnrefinedFunc
  65031 
  65032 var VP8LMapColor32b VP8LMapARGBFunc
  65033 
  65034 var VP8LMapColor8b VP8LMapAlphaFunc
  65035 
  65036 var VP8LPredictors [16]VP8LPredictorFunc
  65037 
  65038 var VP8LPredictorsAdd [16]VP8LPredictorAddSubFunc
  65039 
  65040 // C documentation
  65041 //
  65042 //	// exposed plain-C implementations
  65043 var VP8LPredictorsAdd_C [16]VP8LPredictorAddSubFunc
  65044 
  65045 var VP8LPredictorsAdd_SSE [16]VP8LPredictorAddSubFunc
  65046 
  65047 var VP8LPredictorsSub [16]VP8LPredictorAddSubFunc
  65048 
  65049 var VP8LPredictorsSub_C [16]VP8LPredictorAddSubFunc
  65050 
  65051 var VP8LPredictorsSub_SSE [16]VP8LPredictorAddSubFunc
  65052 
  65053 var VP8LShannonEntropy VP8LShannonEntropyFunc
  65054 
  65055 //------------------------------------------------------------------------------
  65056 
  65057 var VP8LSubtractGreenFromBlueAndRed VP8LProcessEncBlueAndRedFunc
  65058 
  65059 var VP8LSubtractGreenFromBlueAndRed_SSE VP8LProcessEncBlueAndRedFunc
  65060 
  65061 var VP8LTransformColor VP8LTransformColorFunc
  65062 
  65063 var VP8LTransformColorInverse VP8LTransformColorInverseFunc
  65064 
  65065 var VP8LTransformColorInverse_SSE VP8LTransformColorInverseFunc
  65066 
  65067 var VP8LTransformColor_SSE VP8LTransformColorFunc
  65068 
  65069 var VP8LVectorMismatch VP8LVectorMismatchFunc
  65070 
  65071 //------------------------------------------------------------------------------
  65072 // Level cost tables
  65073 
  65074 // C documentation
  65075 //
  65076 //	// fixed costs for coding levels, deduce from the coding tree.
  65077 //	// This is only the part that doesn't depend on the probability state.
  65078 var VP8LevelFixedCosts = [2048]uint16_t{
  65079 	1:    uint16(256),
  65080 	2:    uint16(256),
  65081 	3:    uint16(256),
  65082 	4:    uint16(256),
  65083 	5:    uint16(432),
  65084 	6:    uint16(618),
  65085 	7:    uint16(630),
  65086 	8:    uint16(731),
  65087 	9:    uint16(640),
  65088 	10:   uint16(640),
  65089 	11:   uint16(828),
  65090 	12:   uint16(901),
  65091 	13:   uint16(948),
  65092 	14:   uint16(1021),
  65093 	15:   uint16(1101),
  65094 	16:   uint16(1174),
  65095 	17:   uint16(1221),
  65096 	18:   uint16(1294),
  65097 	19:   uint16(1042),
  65098 	20:   uint16(1085),
  65099 	21:   uint16(1115),
  65100 	22:   uint16(1158),
  65101 	23:   uint16(1202),
  65102 	24:   uint16(1245),
  65103 	25:   uint16(1275),
  65104 	26:   uint16(1318),
  65105 	27:   uint16(1337),
  65106 	28:   uint16(1380),
  65107 	29:   uint16(1410),
  65108 	30:   uint16(1453),
  65109 	31:   uint16(1497),
  65110 	32:   uint16(1540),
  65111 	33:   uint16(1570),
  65112 	34:   uint16(1613),
  65113 	35:   uint16(1280),
  65114 	36:   uint16(1295),
  65115 	37:   uint16(1317),
  65116 	38:   uint16(1332),
  65117 	39:   uint16(1358),
  65118 	40:   uint16(1373),
  65119 	41:   uint16(1395),
  65120 	42:   uint16(1410),
  65121 	43:   uint16(1454),
  65122 	44:   uint16(1469),
  65123 	45:   uint16(1491),
  65124 	46:   uint16(1506),
  65125 	47:   uint16(1532),
  65126 	48:   uint16(1547),
  65127 	49:   uint16(1569),
  65128 	50:   uint16(1584),
  65129 	51:   uint16(1601),
  65130 	52:   uint16(1616),
  65131 	53:   uint16(1638),
  65132 	54:   uint16(1653),
  65133 	55:   uint16(1679),
  65134 	56:   uint16(1694),
  65135 	57:   uint16(1716),
  65136 	58:   uint16(1731),
  65137 	59:   uint16(1775),
  65138 	60:   uint16(1790),
  65139 	61:   uint16(1812),
  65140 	62:   uint16(1827),
  65141 	63:   uint16(1853),
  65142 	64:   uint16(1868),
  65143 	65:   uint16(1890),
  65144 	66:   uint16(1905),
  65145 	67:   uint16(1727),
  65146 	68:   uint16(1733),
  65147 	69:   uint16(1742),
  65148 	70:   uint16(1748),
  65149 	71:   uint16(1759),
  65150 	72:   uint16(1765),
  65151 	73:   uint16(1774),
  65152 	74:   uint16(1780),
  65153 	75:   uint16(1800),
  65154 	76:   uint16(1806),
  65155 	77:   uint16(1815),
  65156 	78:   uint16(1821),
  65157 	79:   uint16(1832),
  65158 	80:   uint16(1838),
  65159 	81:   uint16(1847),
  65160 	82:   uint16(1853),
  65161 	83:   uint16(1878),
  65162 	84:   uint16(1884),
  65163 	85:   uint16(1893),
  65164 	86:   uint16(1899),
  65165 	87:   uint16(1910),
  65166 	88:   uint16(1916),
  65167 	89:   uint16(1925),
  65168 	90:   uint16(1931),
  65169 	91:   uint16(1951),
  65170 	92:   uint16(1957),
  65171 	93:   uint16(1966),
  65172 	94:   uint16(1972),
  65173 	95:   uint16(1983),
  65174 	96:   uint16(1989),
  65175 	97:   uint16(1998),
  65176 	98:   uint16(2004),
  65177 	99:   uint16(2027),
  65178 	100:  uint16(2033),
  65179 	101:  uint16(2042),
  65180 	102:  uint16(2048),
  65181 	103:  uint16(2059),
  65182 	104:  uint16(2065),
  65183 	105:  uint16(2074),
  65184 	106:  uint16(2080),
  65185 	107:  uint16(2100),
  65186 	108:  uint16(2106),
  65187 	109:  uint16(2115),
  65188 	110:  uint16(2121),
  65189 	111:  uint16(2132),
  65190 	112:  uint16(2138),
  65191 	113:  uint16(2147),
  65192 	114:  uint16(2153),
  65193 	115:  uint16(2178),
  65194 	116:  uint16(2184),
  65195 	117:  uint16(2193),
  65196 	118:  uint16(2199),
  65197 	119:  uint16(2210),
  65198 	120:  uint16(2216),
  65199 	121:  uint16(2225),
  65200 	122:  uint16(2231),
  65201 	123:  uint16(2251),
  65202 	124:  uint16(2257),
  65203 	125:  uint16(2266),
  65204 	126:  uint16(2272),
  65205 	127:  uint16(2283),
  65206 	128:  uint16(2289),
  65207 	129:  uint16(2298),
  65208 	130:  uint16(2304),
  65209 	131:  uint16(2168),
  65210 	132:  uint16(2174),
  65211 	133:  uint16(2183),
  65212 	134:  uint16(2189),
  65213 	135:  uint16(2200),
  65214 	136:  uint16(2206),
  65215 	137:  uint16(2215),
  65216 	138:  uint16(2221),
  65217 	139:  uint16(2241),
  65218 	140:  uint16(2247),
  65219 	141:  uint16(2256),
  65220 	142:  uint16(2262),
  65221 	143:  uint16(2273),
  65222 	144:  uint16(2279),
  65223 	145:  uint16(2288),
  65224 	146:  uint16(2294),
  65225 	147:  uint16(2319),
  65226 	148:  uint16(2325),
  65227 	149:  uint16(2334),
  65228 	150:  uint16(2340),
  65229 	151:  uint16(2351),
  65230 	152:  uint16(2357),
  65231 	153:  uint16(2366),
  65232 	154:  uint16(2372),
  65233 	155:  uint16(2392),
  65234 	156:  uint16(2398),
  65235 	157:  uint16(2407),
  65236 	158:  uint16(2413),
  65237 	159:  uint16(2424),
  65238 	160:  uint16(2430),
  65239 	161:  uint16(2439),
  65240 	162:  uint16(2445),
  65241 	163:  uint16(2468),
  65242 	164:  uint16(2474),
  65243 	165:  uint16(2483),
  65244 	166:  uint16(2489),
  65245 	167:  uint16(2500),
  65246 	168:  uint16(2506),
  65247 	169:  uint16(2515),
  65248 	170:  uint16(2521),
  65249 	171:  uint16(2541),
  65250 	172:  uint16(2547),
  65251 	173:  uint16(2556),
  65252 	174:  uint16(2562),
  65253 	175:  uint16(2573),
  65254 	176:  uint16(2579),
  65255 	177:  uint16(2588),
  65256 	178:  uint16(2594),
  65257 	179:  uint16(2619),
  65258 	180:  uint16(2625),
  65259 	181:  uint16(2634),
  65260 	182:  uint16(2640),
  65261 	183:  uint16(2651),
  65262 	184:  uint16(2657),
  65263 	185:  uint16(2666),
  65264 	186:  uint16(2672),
  65265 	187:  uint16(2692),
  65266 	188:  uint16(2698),
  65267 	189:  uint16(2707),
  65268 	190:  uint16(2713),
  65269 	191:  uint16(2724),
  65270 	192:  uint16(2730),
  65271 	193:  uint16(2739),
  65272 	194:  uint16(2745),
  65273 	195:  uint16(2540),
  65274 	196:  uint16(2546),
  65275 	197:  uint16(2555),
  65276 	198:  uint16(2561),
  65277 	199:  uint16(2572),
  65278 	200:  uint16(2578),
  65279 	201:  uint16(2587),
  65280 	202:  uint16(2593),
  65281 	203:  uint16(2613),
  65282 	204:  uint16(2619),
  65283 	205:  uint16(2628),
  65284 	206:  uint16(2634),
  65285 	207:  uint16(2645),
  65286 	208:  uint16(2651),
  65287 	209:  uint16(2660),
  65288 	210:  uint16(2666),
  65289 	211:  uint16(2691),
  65290 	212:  uint16(2697),
  65291 	213:  uint16(2706),
  65292 	214:  uint16(2712),
  65293 	215:  uint16(2723),
  65294 	216:  uint16(2729),
  65295 	217:  uint16(2738),
  65296 	218:  uint16(2744),
  65297 	219:  uint16(2764),
  65298 	220:  uint16(2770),
  65299 	221:  uint16(2779),
  65300 	222:  uint16(2785),
  65301 	223:  uint16(2796),
  65302 	224:  uint16(2802),
  65303 	225:  uint16(2811),
  65304 	226:  uint16(2817),
  65305 	227:  uint16(2840),
  65306 	228:  uint16(2846),
  65307 	229:  uint16(2855),
  65308 	230:  uint16(2861),
  65309 	231:  uint16(2872),
  65310 	232:  uint16(2878),
  65311 	233:  uint16(2887),
  65312 	234:  uint16(2893),
  65313 	235:  uint16(2913),
  65314 	236:  uint16(2919),
  65315 	237:  uint16(2928),
  65316 	238:  uint16(2934),
  65317 	239:  uint16(2945),
  65318 	240:  uint16(2951),
  65319 	241:  uint16(2960),
  65320 	242:  uint16(2966),
  65321 	243:  uint16(2991),
  65322 	244:  uint16(2997),
  65323 	245:  uint16(3006),
  65324 	246:  uint16(3012),
  65325 	247:  uint16(3023),
  65326 	248:  uint16(3029),
  65327 	249:  uint16(3038),
  65328 	250:  uint16(3044),
  65329 	251:  uint16(3064),
  65330 	252:  uint16(3070),
  65331 	253:  uint16(3079),
  65332 	254:  uint16(3085),
  65333 	255:  uint16(3096),
  65334 	256:  uint16(3102),
  65335 	257:  uint16(3111),
  65336 	258:  uint16(3117),
  65337 	259:  uint16(2981),
  65338 	260:  uint16(2987),
  65339 	261:  uint16(2996),
  65340 	262:  uint16(3002),
  65341 	263:  uint16(3013),
  65342 	264:  uint16(3019),
  65343 	265:  uint16(3028),
  65344 	266:  uint16(3034),
  65345 	267:  uint16(3054),
  65346 	268:  uint16(3060),
  65347 	269:  uint16(3069),
  65348 	270:  uint16(3075),
  65349 	271:  uint16(3086),
  65350 	272:  uint16(3092),
  65351 	273:  uint16(3101),
  65352 	274:  uint16(3107),
  65353 	275:  uint16(3132),
  65354 	276:  uint16(3138),
  65355 	277:  uint16(3147),
  65356 	278:  uint16(3153),
  65357 	279:  uint16(3164),
  65358 	280:  uint16(3170),
  65359 	281:  uint16(3179),
  65360 	282:  uint16(3185),
  65361 	283:  uint16(3205),
  65362 	284:  uint16(3211),
  65363 	285:  uint16(3220),
  65364 	286:  uint16(3226),
  65365 	287:  uint16(3237),
  65366 	288:  uint16(3243),
  65367 	289:  uint16(3252),
  65368 	290:  uint16(3258),
  65369 	291:  uint16(3281),
  65370 	292:  uint16(3287),
  65371 	293:  uint16(3296),
  65372 	294:  uint16(3302),
  65373 	295:  uint16(3313),
  65374 	296:  uint16(3319),
  65375 	297:  uint16(3328),
  65376 	298:  uint16(3334),
  65377 	299:  uint16(3354),
  65378 	300:  uint16(3360),
  65379 	301:  uint16(3369),
  65380 	302:  uint16(3375),
  65381 	303:  uint16(3386),
  65382 	304:  uint16(3392),
  65383 	305:  uint16(3401),
  65384 	306:  uint16(3407),
  65385 	307:  uint16(3432),
  65386 	308:  uint16(3438),
  65387 	309:  uint16(3447),
  65388 	310:  uint16(3453),
  65389 	311:  uint16(3464),
  65390 	312:  uint16(3470),
  65391 	313:  uint16(3479),
  65392 	314:  uint16(3485),
  65393 	315:  uint16(3505),
  65394 	316:  uint16(3511),
  65395 	317:  uint16(3520),
  65396 	318:  uint16(3526),
  65397 	319:  uint16(3537),
  65398 	320:  uint16(3543),
  65399 	321:  uint16(3552),
  65400 	322:  uint16(3558),
  65401 	323:  uint16(2816),
  65402 	324:  uint16(2822),
  65403 	325:  uint16(2831),
  65404 	326:  uint16(2837),
  65405 	327:  uint16(2848),
  65406 	328:  uint16(2854),
  65407 	329:  uint16(2863),
  65408 	330:  uint16(2869),
  65409 	331:  uint16(2889),
  65410 	332:  uint16(2895),
  65411 	333:  uint16(2904),
  65412 	334:  uint16(2910),
  65413 	335:  uint16(2921),
  65414 	336:  uint16(2927),
  65415 	337:  uint16(2936),
  65416 	338:  uint16(2942),
  65417 	339:  uint16(2967),
  65418 	340:  uint16(2973),
  65419 	341:  uint16(2982),
  65420 	342:  uint16(2988),
  65421 	343:  uint16(2999),
  65422 	344:  uint16(3005),
  65423 	345:  uint16(3014),
  65424 	346:  uint16(3020),
  65425 	347:  uint16(3040),
  65426 	348:  uint16(3046),
  65427 	349:  uint16(3055),
  65428 	350:  uint16(3061),
  65429 	351:  uint16(3072),
  65430 	352:  uint16(3078),
  65431 	353:  uint16(3087),
  65432 	354:  uint16(3093),
  65433 	355:  uint16(3116),
  65434 	356:  uint16(3122),
  65435 	357:  uint16(3131),
  65436 	358:  uint16(3137),
  65437 	359:  uint16(3148),
  65438 	360:  uint16(3154),
  65439 	361:  uint16(3163),
  65440 	362:  uint16(3169),
  65441 	363:  uint16(3189),
  65442 	364:  uint16(3195),
  65443 	365:  uint16(3204),
  65444 	366:  uint16(3210),
  65445 	367:  uint16(3221),
  65446 	368:  uint16(3227),
  65447 	369:  uint16(3236),
  65448 	370:  uint16(3242),
  65449 	371:  uint16(3267),
  65450 	372:  uint16(3273),
  65451 	373:  uint16(3282),
  65452 	374:  uint16(3288),
  65453 	375:  uint16(3299),
  65454 	376:  uint16(3305),
  65455 	377:  uint16(3314),
  65456 	378:  uint16(3320),
  65457 	379:  uint16(3340),
  65458 	380:  uint16(3346),
  65459 	381:  uint16(3355),
  65460 	382:  uint16(3361),
  65461 	383:  uint16(3372),
  65462 	384:  uint16(3378),
  65463 	385:  uint16(3387),
  65464 	386:  uint16(3393),
  65465 	387:  uint16(3257),
  65466 	388:  uint16(3263),
  65467 	389:  uint16(3272),
  65468 	390:  uint16(3278),
  65469 	391:  uint16(3289),
  65470 	392:  uint16(3295),
  65471 	393:  uint16(3304),
  65472 	394:  uint16(3310),
  65473 	395:  uint16(3330),
  65474 	396:  uint16(3336),
  65475 	397:  uint16(3345),
  65476 	398:  uint16(3351),
  65477 	399:  uint16(3362),
  65478 	400:  uint16(3368),
  65479 	401:  uint16(3377),
  65480 	402:  uint16(3383),
  65481 	403:  uint16(3408),
  65482 	404:  uint16(3414),
  65483 	405:  uint16(3423),
  65484 	406:  uint16(3429),
  65485 	407:  uint16(3440),
  65486 	408:  uint16(3446),
  65487 	409:  uint16(3455),
  65488 	410:  uint16(3461),
  65489 	411:  uint16(3481),
  65490 	412:  uint16(3487),
  65491 	413:  uint16(3496),
  65492 	414:  uint16(3502),
  65493 	415:  uint16(3513),
  65494 	416:  uint16(3519),
  65495 	417:  uint16(3528),
  65496 	418:  uint16(3534),
  65497 	419:  uint16(3557),
  65498 	420:  uint16(3563),
  65499 	421:  uint16(3572),
  65500 	422:  uint16(3578),
  65501 	423:  uint16(3589),
  65502 	424:  uint16(3595),
  65503 	425:  uint16(3604),
  65504 	426:  uint16(3610),
  65505 	427:  uint16(3630),
  65506 	428:  uint16(3636),
  65507 	429:  uint16(3645),
  65508 	430:  uint16(3651),
  65509 	431:  uint16(3662),
  65510 	432:  uint16(3668),
  65511 	433:  uint16(3677),
  65512 	434:  uint16(3683),
  65513 	435:  uint16(3708),
  65514 	436:  uint16(3714),
  65515 	437:  uint16(3723),
  65516 	438:  uint16(3729),
  65517 	439:  uint16(3740),
  65518 	440:  uint16(3746),
  65519 	441:  uint16(3755),
  65520 	442:  uint16(3761),
  65521 	443:  uint16(3781),
  65522 	444:  uint16(3787),
  65523 	445:  uint16(3796),
  65524 	446:  uint16(3802),
  65525 	447:  uint16(3813),
  65526 	448:  uint16(3819),
  65527 	449:  uint16(3828),
  65528 	450:  uint16(3834),
  65529 	451:  uint16(3629),
  65530 	452:  uint16(3635),
  65531 	453:  uint16(3644),
  65532 	454:  uint16(3650),
  65533 	455:  uint16(3661),
  65534 	456:  uint16(3667),
  65535 	457:  uint16(3676),
  65536 	458:  uint16(3682),
  65537 	459:  uint16(3702),
  65538 	460:  uint16(3708),
  65539 	461:  uint16(3717),
  65540 	462:  uint16(3723),
  65541 	463:  uint16(3734),
  65542 	464:  uint16(3740),
  65543 	465:  uint16(3749),
  65544 	466:  uint16(3755),
  65545 	467:  uint16(3780),
  65546 	468:  uint16(3786),
  65547 	469:  uint16(3795),
  65548 	470:  uint16(3801),
  65549 	471:  uint16(3812),
  65550 	472:  uint16(3818),
  65551 	473:  uint16(3827),
  65552 	474:  uint16(3833),
  65553 	475:  uint16(3853),
  65554 	476:  uint16(3859),
  65555 	477:  uint16(3868),
  65556 	478:  uint16(3874),
  65557 	479:  uint16(3885),
  65558 	480:  uint16(3891),
  65559 	481:  uint16(3900),
  65560 	482:  uint16(3906),
  65561 	483:  uint16(3929),
  65562 	484:  uint16(3935),
  65563 	485:  uint16(3944),
  65564 	486:  uint16(3950),
  65565 	487:  uint16(3961),
  65566 	488:  uint16(3967),
  65567 	489:  uint16(3976),
  65568 	490:  uint16(3982),
  65569 	491:  uint16(4002),
  65570 	492:  uint16(4008),
  65571 	493:  uint16(4017),
  65572 	494:  uint16(4023),
  65573 	495:  uint16(4034),
  65574 	496:  uint16(4040),
  65575 	497:  uint16(4049),
  65576 	498:  uint16(4055),
  65577 	499:  uint16(4080),
  65578 	500:  uint16(4086),
  65579 	501:  uint16(4095),
  65580 	502:  uint16(4101),
  65581 	503:  uint16(4112),
  65582 	504:  uint16(4118),
  65583 	505:  uint16(4127),
  65584 	506:  uint16(4133),
  65585 	507:  uint16(4153),
  65586 	508:  uint16(4159),
  65587 	509:  uint16(4168),
  65588 	510:  uint16(4174),
  65589 	511:  uint16(4185),
  65590 	512:  uint16(4191),
  65591 	513:  uint16(4200),
  65592 	514:  uint16(4206),
  65593 	515:  uint16(4070),
  65594 	516:  uint16(4076),
  65595 	517:  uint16(4085),
  65596 	518:  uint16(4091),
  65597 	519:  uint16(4102),
  65598 	520:  uint16(4108),
  65599 	521:  uint16(4117),
  65600 	522:  uint16(4123),
  65601 	523:  uint16(4143),
  65602 	524:  uint16(4149),
  65603 	525:  uint16(4158),
  65604 	526:  uint16(4164),
  65605 	527:  uint16(4175),
  65606 	528:  uint16(4181),
  65607 	529:  uint16(4190),
  65608 	530:  uint16(4196),
  65609 	531:  uint16(4221),
  65610 	532:  uint16(4227),
  65611 	533:  uint16(4236),
  65612 	534:  uint16(4242),
  65613 	535:  uint16(4253),
  65614 	536:  uint16(4259),
  65615 	537:  uint16(4268),
  65616 	538:  uint16(4274),
  65617 	539:  uint16(4294),
  65618 	540:  uint16(4300),
  65619 	541:  uint16(4309),
  65620 	542:  uint16(4315),
  65621 	543:  uint16(4326),
  65622 	544:  uint16(4332),
  65623 	545:  uint16(4341),
  65624 	546:  uint16(4347),
  65625 	547:  uint16(4370),
  65626 	548:  uint16(4376),
  65627 	549:  uint16(4385),
  65628 	550:  uint16(4391),
  65629 	551:  uint16(4402),
  65630 	552:  uint16(4408),
  65631 	553:  uint16(4417),
  65632 	554:  uint16(4423),
  65633 	555:  uint16(4443),
  65634 	556:  uint16(4449),
  65635 	557:  uint16(4458),
  65636 	558:  uint16(4464),
  65637 	559:  uint16(4475),
  65638 	560:  uint16(4481),
  65639 	561:  uint16(4490),
  65640 	562:  uint16(4496),
  65641 	563:  uint16(4521),
  65642 	564:  uint16(4527),
  65643 	565:  uint16(4536),
  65644 	566:  uint16(4542),
  65645 	567:  uint16(4553),
  65646 	568:  uint16(4559),
  65647 	569:  uint16(4568),
  65648 	570:  uint16(4574),
  65649 	571:  uint16(4594),
  65650 	572:  uint16(4600),
  65651 	573:  uint16(4609),
  65652 	574:  uint16(4615),
  65653 	575:  uint16(4626),
  65654 	576:  uint16(4632),
  65655 	577:  uint16(4641),
  65656 	578:  uint16(4647),
  65657 	579:  uint16(3515),
  65658 	580:  uint16(3521),
  65659 	581:  uint16(3530),
  65660 	582:  uint16(3536),
  65661 	583:  uint16(3547),
  65662 	584:  uint16(3553),
  65663 	585:  uint16(3562),
  65664 	586:  uint16(3568),
  65665 	587:  uint16(3588),
  65666 	588:  uint16(3594),
  65667 	589:  uint16(3603),
  65668 	590:  uint16(3609),
  65669 	591:  uint16(3620),
  65670 	592:  uint16(3626),
  65671 	593:  uint16(3635),
  65672 	594:  uint16(3641),
  65673 	595:  uint16(3666),
  65674 	596:  uint16(3672),
  65675 	597:  uint16(3681),
  65676 	598:  uint16(3687),
  65677 	599:  uint16(3698),
  65678 	600:  uint16(3704),
  65679 	601:  uint16(3713),
  65680 	602:  uint16(3719),
  65681 	603:  uint16(3739),
  65682 	604:  uint16(3745),
  65683 	605:  uint16(3754),
  65684 	606:  uint16(3760),
  65685 	607:  uint16(3771),
  65686 	608:  uint16(3777),
  65687 	609:  uint16(3786),
  65688 	610:  uint16(3792),
  65689 	611:  uint16(3815),
  65690 	612:  uint16(3821),
  65691 	613:  uint16(3830),
  65692 	614:  uint16(3836),
  65693 	615:  uint16(3847),
  65694 	616:  uint16(3853),
  65695 	617:  uint16(3862),
  65696 	618:  uint16(3868),
  65697 	619:  uint16(3888),
  65698 	620:  uint16(3894),
  65699 	621:  uint16(3903),
  65700 	622:  uint16(3909),
  65701 	623:  uint16(3920),
  65702 	624:  uint16(3926),
  65703 	625:  uint16(3935),
  65704 	626:  uint16(3941),
  65705 	627:  uint16(3966),
  65706 	628:  uint16(3972),
  65707 	629:  uint16(3981),
  65708 	630:  uint16(3987),
  65709 	631:  uint16(3998),
  65710 	632:  uint16(4004),
  65711 	633:  uint16(4013),
  65712 	634:  uint16(4019),
  65713 	635:  uint16(4039),
  65714 	636:  uint16(4045),
  65715 	637:  uint16(4054),
  65716 	638:  uint16(4060),
  65717 	639:  uint16(4071),
  65718 	640:  uint16(4077),
  65719 	641:  uint16(4086),
  65720 	642:  uint16(4092),
  65721 	643:  uint16(3956),
  65722 	644:  uint16(3962),
  65723 	645:  uint16(3971),
  65724 	646:  uint16(3977),
  65725 	647:  uint16(3988),
  65726 	648:  uint16(3994),
  65727 	649:  uint16(4003),
  65728 	650:  uint16(4009),
  65729 	651:  uint16(4029),
  65730 	652:  uint16(4035),
  65731 	653:  uint16(4044),
  65732 	654:  uint16(4050),
  65733 	655:  uint16(4061),
  65734 	656:  uint16(4067),
  65735 	657:  uint16(4076),
  65736 	658:  uint16(4082),
  65737 	659:  uint16(4107),
  65738 	660:  uint16(4113),
  65739 	661:  uint16(4122),
  65740 	662:  uint16(4128),
  65741 	663:  uint16(4139),
  65742 	664:  uint16(4145),
  65743 	665:  uint16(4154),
  65744 	666:  uint16(4160),
  65745 	667:  uint16(4180),
  65746 	668:  uint16(4186),
  65747 	669:  uint16(4195),
  65748 	670:  uint16(4201),
  65749 	671:  uint16(4212),
  65750 	672:  uint16(4218),
  65751 	673:  uint16(4227),
  65752 	674:  uint16(4233),
  65753 	675:  uint16(4256),
  65754 	676:  uint16(4262),
  65755 	677:  uint16(4271),
  65756 	678:  uint16(4277),
  65757 	679:  uint16(4288),
  65758 	680:  uint16(4294),
  65759 	681:  uint16(4303),
  65760 	682:  uint16(4309),
  65761 	683:  uint16(4329),
  65762 	684:  uint16(4335),
  65763 	685:  uint16(4344),
  65764 	686:  uint16(4350),
  65765 	687:  uint16(4361),
  65766 	688:  uint16(4367),
  65767 	689:  uint16(4376),
  65768 	690:  uint16(4382),
  65769 	691:  uint16(4407),
  65770 	692:  uint16(4413),
  65771 	693:  uint16(4422),
  65772 	694:  uint16(4428),
  65773 	695:  uint16(4439),
  65774 	696:  uint16(4445),
  65775 	697:  uint16(4454),
  65776 	698:  uint16(4460),
  65777 	699:  uint16(4480),
  65778 	700:  uint16(4486),
  65779 	701:  uint16(4495),
  65780 	702:  uint16(4501),
  65781 	703:  uint16(4512),
  65782 	704:  uint16(4518),
  65783 	705:  uint16(4527),
  65784 	706:  uint16(4533),
  65785 	707:  uint16(4328),
  65786 	708:  uint16(4334),
  65787 	709:  uint16(4343),
  65788 	710:  uint16(4349),
  65789 	711:  uint16(4360),
  65790 	712:  uint16(4366),
  65791 	713:  uint16(4375),
  65792 	714:  uint16(4381),
  65793 	715:  uint16(4401),
  65794 	716:  uint16(4407),
  65795 	717:  uint16(4416),
  65796 	718:  uint16(4422),
  65797 	719:  uint16(4433),
  65798 	720:  uint16(4439),
  65799 	721:  uint16(4448),
  65800 	722:  uint16(4454),
  65801 	723:  uint16(4479),
  65802 	724:  uint16(4485),
  65803 	725:  uint16(4494),
  65804 	726:  uint16(4500),
  65805 	727:  uint16(4511),
  65806 	728:  uint16(4517),
  65807 	729:  uint16(4526),
  65808 	730:  uint16(4532),
  65809 	731:  uint16(4552),
  65810 	732:  uint16(4558),
  65811 	733:  uint16(4567),
  65812 	734:  uint16(4573),
  65813 	735:  uint16(4584),
  65814 	736:  uint16(4590),
  65815 	737:  uint16(4599),
  65816 	738:  uint16(4605),
  65817 	739:  uint16(4628),
  65818 	740:  uint16(4634),
  65819 	741:  uint16(4643),
  65820 	742:  uint16(4649),
  65821 	743:  uint16(4660),
  65822 	744:  uint16(4666),
  65823 	745:  uint16(4675),
  65824 	746:  uint16(4681),
  65825 	747:  uint16(4701),
  65826 	748:  uint16(4707),
  65827 	749:  uint16(4716),
  65828 	750:  uint16(4722),
  65829 	751:  uint16(4733),
  65830 	752:  uint16(4739),
  65831 	753:  uint16(4748),
  65832 	754:  uint16(4754),
  65833 	755:  uint16(4779),
  65834 	756:  uint16(4785),
  65835 	757:  uint16(4794),
  65836 	758:  uint16(4800),
  65837 	759:  uint16(4811),
  65838 	760:  uint16(4817),
  65839 	761:  uint16(4826),
  65840 	762:  uint16(4832),
  65841 	763:  uint16(4852),
  65842 	764:  uint16(4858),
  65843 	765:  uint16(4867),
  65844 	766:  uint16(4873),
  65845 	767:  uint16(4884),
  65846 	768:  uint16(4890),
  65847 	769:  uint16(4899),
  65848 	770:  uint16(4905),
  65849 	771:  uint16(4769),
  65850 	772:  uint16(4775),
  65851 	773:  uint16(4784),
  65852 	774:  uint16(4790),
  65853 	775:  uint16(4801),
  65854 	776:  uint16(4807),
  65855 	777:  uint16(4816),
  65856 	778:  uint16(4822),
  65857 	779:  uint16(4842),
  65858 	780:  uint16(4848),
  65859 	781:  uint16(4857),
  65860 	782:  uint16(4863),
  65861 	783:  uint16(4874),
  65862 	784:  uint16(4880),
  65863 	785:  uint16(4889),
  65864 	786:  uint16(4895),
  65865 	787:  uint16(4920),
  65866 	788:  uint16(4926),
  65867 	789:  uint16(4935),
  65868 	790:  uint16(4941),
  65869 	791:  uint16(4952),
  65870 	792:  uint16(4958),
  65871 	793:  uint16(4967),
  65872 	794:  uint16(4973),
  65873 	795:  uint16(4993),
  65874 	796:  uint16(4999),
  65875 	797:  uint16(5008),
  65876 	798:  uint16(5014),
  65877 	799:  uint16(5025),
  65878 	800:  uint16(5031),
  65879 	801:  uint16(5040),
  65880 	802:  uint16(5046),
  65881 	803:  uint16(5069),
  65882 	804:  uint16(5075),
  65883 	805:  uint16(5084),
  65884 	806:  uint16(5090),
  65885 	807:  uint16(5101),
  65886 	808:  uint16(5107),
  65887 	809:  uint16(5116),
  65888 	810:  uint16(5122),
  65889 	811:  uint16(5142),
  65890 	812:  uint16(5148),
  65891 	813:  uint16(5157),
  65892 	814:  uint16(5163),
  65893 	815:  uint16(5174),
  65894 	816:  uint16(5180),
  65895 	817:  uint16(5189),
  65896 	818:  uint16(5195),
  65897 	819:  uint16(5220),
  65898 	820:  uint16(5226),
  65899 	821:  uint16(5235),
  65900 	822:  uint16(5241),
  65901 	823:  uint16(5252),
  65902 	824:  uint16(5258),
  65903 	825:  uint16(5267),
  65904 	826:  uint16(5273),
  65905 	827:  uint16(5293),
  65906 	828:  uint16(5299),
  65907 	829:  uint16(5308),
  65908 	830:  uint16(5314),
  65909 	831:  uint16(5325),
  65910 	832:  uint16(5331),
  65911 	833:  uint16(5340),
  65912 	834:  uint16(5346),
  65913 	835:  uint16(4604),
  65914 	836:  uint16(4610),
  65915 	837:  uint16(4619),
  65916 	838:  uint16(4625),
  65917 	839:  uint16(4636),
  65918 	840:  uint16(4642),
  65919 	841:  uint16(4651),
  65920 	842:  uint16(4657),
  65921 	843:  uint16(4677),
  65922 	844:  uint16(4683),
  65923 	845:  uint16(4692),
  65924 	846:  uint16(4698),
  65925 	847:  uint16(4709),
  65926 	848:  uint16(4715),
  65927 	849:  uint16(4724),
  65928 	850:  uint16(4730),
  65929 	851:  uint16(4755),
  65930 	852:  uint16(4761),
  65931 	853:  uint16(4770),
  65932 	854:  uint16(4776),
  65933 	855:  uint16(4787),
  65934 	856:  uint16(4793),
  65935 	857:  uint16(4802),
  65936 	858:  uint16(4808),
  65937 	859:  uint16(4828),
  65938 	860:  uint16(4834),
  65939 	861:  uint16(4843),
  65940 	862:  uint16(4849),
  65941 	863:  uint16(4860),
  65942 	864:  uint16(4866),
  65943 	865:  uint16(4875),
  65944 	866:  uint16(4881),
  65945 	867:  uint16(4904),
  65946 	868:  uint16(4910),
  65947 	869:  uint16(4919),
  65948 	870:  uint16(4925),
  65949 	871:  uint16(4936),
  65950 	872:  uint16(4942),
  65951 	873:  uint16(4951),
  65952 	874:  uint16(4957),
  65953 	875:  uint16(4977),
  65954 	876:  uint16(4983),
  65955 	877:  uint16(4992),
  65956 	878:  uint16(4998),
  65957 	879:  uint16(5009),
  65958 	880:  uint16(5015),
  65959 	881:  uint16(5024),
  65960 	882:  uint16(5030),
  65961 	883:  uint16(5055),
  65962 	884:  uint16(5061),
  65963 	885:  uint16(5070),
  65964 	886:  uint16(5076),
  65965 	887:  uint16(5087),
  65966 	888:  uint16(5093),
  65967 	889:  uint16(5102),
  65968 	890:  uint16(5108),
  65969 	891:  uint16(5128),
  65970 	892:  uint16(5134),
  65971 	893:  uint16(5143),
  65972 	894:  uint16(5149),
  65973 	895:  uint16(5160),
  65974 	896:  uint16(5166),
  65975 	897:  uint16(5175),
  65976 	898:  uint16(5181),
  65977 	899:  uint16(5045),
  65978 	900:  uint16(5051),
  65979 	901:  uint16(5060),
  65980 	902:  uint16(5066),
  65981 	903:  uint16(5077),
  65982 	904:  uint16(5083),
  65983 	905:  uint16(5092),
  65984 	906:  uint16(5098),
  65985 	907:  uint16(5118),
  65986 	908:  uint16(5124),
  65987 	909:  uint16(5133),
  65988 	910:  uint16(5139),
  65989 	911:  uint16(5150),
  65990 	912:  uint16(5156),
  65991 	913:  uint16(5165),
  65992 	914:  uint16(5171),
  65993 	915:  uint16(5196),
  65994 	916:  uint16(5202),
  65995 	917:  uint16(5211),
  65996 	918:  uint16(5217),
  65997 	919:  uint16(5228),
  65998 	920:  uint16(5234),
  65999 	921:  uint16(5243),
  66000 	922:  uint16(5249),
  66001 	923:  uint16(5269),
  66002 	924:  uint16(5275),
  66003 	925:  uint16(5284),
  66004 	926:  uint16(5290),
  66005 	927:  uint16(5301),
  66006 	928:  uint16(5307),
  66007 	929:  uint16(5316),
  66008 	930:  uint16(5322),
  66009 	931:  uint16(5345),
  66010 	932:  uint16(5351),
  66011 	933:  uint16(5360),
  66012 	934:  uint16(5366),
  66013 	935:  uint16(5377),
  66014 	936:  uint16(5383),
  66015 	937:  uint16(5392),
  66016 	938:  uint16(5398),
  66017 	939:  uint16(5418),
  66018 	940:  uint16(5424),
  66019 	941:  uint16(5433),
  66020 	942:  uint16(5439),
  66021 	943:  uint16(5450),
  66022 	944:  uint16(5456),
  66023 	945:  uint16(5465),
  66024 	946:  uint16(5471),
  66025 	947:  uint16(5496),
  66026 	948:  uint16(5502),
  66027 	949:  uint16(5511),
  66028 	950:  uint16(5517),
  66029 	951:  uint16(5528),
  66030 	952:  uint16(5534),
  66031 	953:  uint16(5543),
  66032 	954:  uint16(5549),
  66033 	955:  uint16(5569),
  66034 	956:  uint16(5575),
  66035 	957:  uint16(5584),
  66036 	958:  uint16(5590),
  66037 	959:  uint16(5601),
  66038 	960:  uint16(5607),
  66039 	961:  uint16(5616),
  66040 	962:  uint16(5622),
  66041 	963:  uint16(5417),
  66042 	964:  uint16(5423),
  66043 	965:  uint16(5432),
  66044 	966:  uint16(5438),
  66045 	967:  uint16(5449),
  66046 	968:  uint16(5455),
  66047 	969:  uint16(5464),
  66048 	970:  uint16(5470),
  66049 	971:  uint16(5490),
  66050 	972:  uint16(5496),
  66051 	973:  uint16(5505),
  66052 	974:  uint16(5511),
  66053 	975:  uint16(5522),
  66054 	976:  uint16(5528),
  66055 	977:  uint16(5537),
  66056 	978:  uint16(5543),
  66057 	979:  uint16(5568),
  66058 	980:  uint16(5574),
  66059 	981:  uint16(5583),
  66060 	982:  uint16(5589),
  66061 	983:  uint16(5600),
  66062 	984:  uint16(5606),
  66063 	985:  uint16(5615),
  66064 	986:  uint16(5621),
  66065 	987:  uint16(5641),
  66066 	988:  uint16(5647),
  66067 	989:  uint16(5656),
  66068 	990:  uint16(5662),
  66069 	991:  uint16(5673),
  66070 	992:  uint16(5679),
  66071 	993:  uint16(5688),
  66072 	994:  uint16(5694),
  66073 	995:  uint16(5717),
  66074 	996:  uint16(5723),
  66075 	997:  uint16(5732),
  66076 	998:  uint16(5738),
  66077 	999:  uint16(5749),
  66078 	1000: uint16(5755),
  66079 	1001: uint16(5764),
  66080 	1002: uint16(5770),
  66081 	1003: uint16(5790),
  66082 	1004: uint16(5796),
  66083 	1005: uint16(5805),
  66084 	1006: uint16(5811),
  66085 	1007: uint16(5822),
  66086 	1008: uint16(5828),
  66087 	1009: uint16(5837),
  66088 	1010: uint16(5843),
  66089 	1011: uint16(5868),
  66090 	1012: uint16(5874),
  66091 	1013: uint16(5883),
  66092 	1014: uint16(5889),
  66093 	1015: uint16(5900),
  66094 	1016: uint16(5906),
  66095 	1017: uint16(5915),
  66096 	1018: uint16(5921),
  66097 	1019: uint16(5941),
  66098 	1020: uint16(5947),
  66099 	1021: uint16(5956),
  66100 	1022: uint16(5962),
  66101 	1023: uint16(5973),
  66102 	1024: uint16(5979),
  66103 	1025: uint16(5988),
  66104 	1026: uint16(5994),
  66105 	1027: uint16(5858),
  66106 	1028: uint16(5864),
  66107 	1029: uint16(5873),
  66108 	1030: uint16(5879),
  66109 	1031: uint16(5890),
  66110 	1032: uint16(5896),
  66111 	1033: uint16(5905),
  66112 	1034: uint16(5911),
  66113 	1035: uint16(5931),
  66114 	1036: uint16(5937),
  66115 	1037: uint16(5946),
  66116 	1038: uint16(5952),
  66117 	1039: uint16(5963),
  66118 	1040: uint16(5969),
  66119 	1041: uint16(5978),
  66120 	1042: uint16(5984),
  66121 	1043: uint16(6009),
  66122 	1044: uint16(6015),
  66123 	1045: uint16(6024),
  66124 	1046: uint16(6030),
  66125 	1047: uint16(6041),
  66126 	1048: uint16(6047),
  66127 	1049: uint16(6056),
  66128 	1050: uint16(6062),
  66129 	1051: uint16(6082),
  66130 	1052: uint16(6088),
  66131 	1053: uint16(6097),
  66132 	1054: uint16(6103),
  66133 	1055: uint16(6114),
  66134 	1056: uint16(6120),
  66135 	1057: uint16(6129),
  66136 	1058: uint16(6135),
  66137 	1059: uint16(6158),
  66138 	1060: uint16(6164),
  66139 	1061: uint16(6173),
  66140 	1062: uint16(6179),
  66141 	1063: uint16(6190),
  66142 	1064: uint16(6196),
  66143 	1065: uint16(6205),
  66144 	1066: uint16(6211),
  66145 	1067: uint16(6231),
  66146 	1068: uint16(6237),
  66147 	1069: uint16(6246),
  66148 	1070: uint16(6252),
  66149 	1071: uint16(6263),
  66150 	1072: uint16(6269),
  66151 	1073: uint16(6278),
  66152 	1074: uint16(6284),
  66153 	1075: uint16(6309),
  66154 	1076: uint16(6315),
  66155 	1077: uint16(6324),
  66156 	1078: uint16(6330),
  66157 	1079: uint16(6341),
  66158 	1080: uint16(6347),
  66159 	1081: uint16(6356),
  66160 	1082: uint16(6362),
  66161 	1083: uint16(6382),
  66162 	1084: uint16(6388),
  66163 	1085: uint16(6397),
  66164 	1086: uint16(6403),
  66165 	1087: uint16(6414),
  66166 	1088: uint16(6420),
  66167 	1089: uint16(6429),
  66168 	1090: uint16(6435),
  66169 	1091: uint16(3515),
  66170 	1092: uint16(3521),
  66171 	1093: uint16(3530),
  66172 	1094: uint16(3536),
  66173 	1095: uint16(3547),
  66174 	1096: uint16(3553),
  66175 	1097: uint16(3562),
  66176 	1098: uint16(3568),
  66177 	1099: uint16(3588),
  66178 	1100: uint16(3594),
  66179 	1101: uint16(3603),
  66180 	1102: uint16(3609),
  66181 	1103: uint16(3620),
  66182 	1104: uint16(3626),
  66183 	1105: uint16(3635),
  66184 	1106: uint16(3641),
  66185 	1107: uint16(3666),
  66186 	1108: uint16(3672),
  66187 	1109: uint16(3681),
  66188 	1110: uint16(3687),
  66189 	1111: uint16(3698),
  66190 	1112: uint16(3704),
  66191 	1113: uint16(3713),
  66192 	1114: uint16(3719),
  66193 	1115: uint16(3739),
  66194 	1116: uint16(3745),
  66195 	1117: uint16(3754),
  66196 	1118: uint16(3760),
  66197 	1119: uint16(3771),
  66198 	1120: uint16(3777),
  66199 	1121: uint16(3786),
  66200 	1122: uint16(3792),
  66201 	1123: uint16(3815),
  66202 	1124: uint16(3821),
  66203 	1125: uint16(3830),
  66204 	1126: uint16(3836),
  66205 	1127: uint16(3847),
  66206 	1128: uint16(3853),
  66207 	1129: uint16(3862),
  66208 	1130: uint16(3868),
  66209 	1131: uint16(3888),
  66210 	1132: uint16(3894),
  66211 	1133: uint16(3903),
  66212 	1134: uint16(3909),
  66213 	1135: uint16(3920),
  66214 	1136: uint16(3926),
  66215 	1137: uint16(3935),
  66216 	1138: uint16(3941),
  66217 	1139: uint16(3966),
  66218 	1140: uint16(3972),
  66219 	1141: uint16(3981),
  66220 	1142: uint16(3987),
  66221 	1143: uint16(3998),
  66222 	1144: uint16(4004),
  66223 	1145: uint16(4013),
  66224 	1146: uint16(4019),
  66225 	1147: uint16(4039),
  66226 	1148: uint16(4045),
  66227 	1149: uint16(4054),
  66228 	1150: uint16(4060),
  66229 	1151: uint16(4071),
  66230 	1152: uint16(4077),
  66231 	1153: uint16(4086),
  66232 	1154: uint16(4092),
  66233 	1155: uint16(3956),
  66234 	1156: uint16(3962),
  66235 	1157: uint16(3971),
  66236 	1158: uint16(3977),
  66237 	1159: uint16(3988),
  66238 	1160: uint16(3994),
  66239 	1161: uint16(4003),
  66240 	1162: uint16(4009),
  66241 	1163: uint16(4029),
  66242 	1164: uint16(4035),
  66243 	1165: uint16(4044),
  66244 	1166: uint16(4050),
  66245 	1167: uint16(4061),
  66246 	1168: uint16(4067),
  66247 	1169: uint16(4076),
  66248 	1170: uint16(4082),
  66249 	1171: uint16(4107),
  66250 	1172: uint16(4113),
  66251 	1173: uint16(4122),
  66252 	1174: uint16(4128),
  66253 	1175: uint16(4139),
  66254 	1176: uint16(4145),
  66255 	1177: uint16(4154),
  66256 	1178: uint16(4160),
  66257 	1179: uint16(4180),
  66258 	1180: uint16(4186),
  66259 	1181: uint16(4195),
  66260 	1182: uint16(4201),
  66261 	1183: uint16(4212),
  66262 	1184: uint16(4218),
  66263 	1185: uint16(4227),
  66264 	1186: uint16(4233),
  66265 	1187: uint16(4256),
  66266 	1188: uint16(4262),
  66267 	1189: uint16(4271),
  66268 	1190: uint16(4277),
  66269 	1191: uint16(4288),
  66270 	1192: uint16(4294),
  66271 	1193: uint16(4303),
  66272 	1194: uint16(4309),
  66273 	1195: uint16(4329),
  66274 	1196: uint16(4335),
  66275 	1197: uint16(4344),
  66276 	1198: uint16(4350),
  66277 	1199: uint16(4361),
  66278 	1200: uint16(4367),
  66279 	1201: uint16(4376),
  66280 	1202: uint16(4382),
  66281 	1203: uint16(4407),
  66282 	1204: uint16(4413),
  66283 	1205: uint16(4422),
  66284 	1206: uint16(4428),
  66285 	1207: uint16(4439),
  66286 	1208: uint16(4445),
  66287 	1209: uint16(4454),
  66288 	1210: uint16(4460),
  66289 	1211: uint16(4480),
  66290 	1212: uint16(4486),
  66291 	1213: uint16(4495),
  66292 	1214: uint16(4501),
  66293 	1215: uint16(4512),
  66294 	1216: uint16(4518),
  66295 	1217: uint16(4527),
  66296 	1218: uint16(4533),
  66297 	1219: uint16(4328),
  66298 	1220: uint16(4334),
  66299 	1221: uint16(4343),
  66300 	1222: uint16(4349),
  66301 	1223: uint16(4360),
  66302 	1224: uint16(4366),
  66303 	1225: uint16(4375),
  66304 	1226: uint16(4381),
  66305 	1227: uint16(4401),
  66306 	1228: uint16(4407),
  66307 	1229: uint16(4416),
  66308 	1230: uint16(4422),
  66309 	1231: uint16(4433),
  66310 	1232: uint16(4439),
  66311 	1233: uint16(4448),
  66312 	1234: uint16(4454),
  66313 	1235: uint16(4479),
  66314 	1236: uint16(4485),
  66315 	1237: uint16(4494),
  66316 	1238: uint16(4500),
  66317 	1239: uint16(4511),
  66318 	1240: uint16(4517),
  66319 	1241: uint16(4526),
  66320 	1242: uint16(4532),
  66321 	1243: uint16(4552),
  66322 	1244: uint16(4558),
  66323 	1245: uint16(4567),
  66324 	1246: uint16(4573),
  66325 	1247: uint16(4584),
  66326 	1248: uint16(4590),
  66327 	1249: uint16(4599),
  66328 	1250: uint16(4605),
  66329 	1251: uint16(4628),
  66330 	1252: uint16(4634),
  66331 	1253: uint16(4643),
  66332 	1254: uint16(4649),
  66333 	1255: uint16(4660),
  66334 	1256: uint16(4666),
  66335 	1257: uint16(4675),
  66336 	1258: uint16(4681),
  66337 	1259: uint16(4701),
  66338 	1260: uint16(4707),
  66339 	1261: uint16(4716),
  66340 	1262: uint16(4722),
  66341 	1263: uint16(4733),
  66342 	1264: uint16(4739),
  66343 	1265: uint16(4748),
  66344 	1266: uint16(4754),
  66345 	1267: uint16(4779),
  66346 	1268: uint16(4785),
  66347 	1269: uint16(4794),
  66348 	1270: uint16(4800),
  66349 	1271: uint16(4811),
  66350 	1272: uint16(4817),
  66351 	1273: uint16(4826),
  66352 	1274: uint16(4832),
  66353 	1275: uint16(4852),
  66354 	1276: uint16(4858),
  66355 	1277: uint16(4867),
  66356 	1278: uint16(4873),
  66357 	1279: uint16(4884),
  66358 	1280: uint16(4890),
  66359 	1281: uint16(4899),
  66360 	1282: uint16(4905),
  66361 	1283: uint16(4769),
  66362 	1284: uint16(4775),
  66363 	1285: uint16(4784),
  66364 	1286: uint16(4790),
  66365 	1287: uint16(4801),
  66366 	1288: uint16(4807),
  66367 	1289: uint16(4816),
  66368 	1290: uint16(4822),
  66369 	1291: uint16(4842),
  66370 	1292: uint16(4848),
  66371 	1293: uint16(4857),
  66372 	1294: uint16(4863),
  66373 	1295: uint16(4874),
  66374 	1296: uint16(4880),
  66375 	1297: uint16(4889),
  66376 	1298: uint16(4895),
  66377 	1299: uint16(4920),
  66378 	1300: uint16(4926),
  66379 	1301: uint16(4935),
  66380 	1302: uint16(4941),
  66381 	1303: uint16(4952),
  66382 	1304: uint16(4958),
  66383 	1305: uint16(4967),
  66384 	1306: uint16(4973),
  66385 	1307: uint16(4993),
  66386 	1308: uint16(4999),
  66387 	1309: uint16(5008),
  66388 	1310: uint16(5014),
  66389 	1311: uint16(5025),
  66390 	1312: uint16(5031),
  66391 	1313: uint16(5040),
  66392 	1314: uint16(5046),
  66393 	1315: uint16(5069),
  66394 	1316: uint16(5075),
  66395 	1317: uint16(5084),
  66396 	1318: uint16(5090),
  66397 	1319: uint16(5101),
  66398 	1320: uint16(5107),
  66399 	1321: uint16(5116),
  66400 	1322: uint16(5122),
  66401 	1323: uint16(5142),
  66402 	1324: uint16(5148),
  66403 	1325: uint16(5157),
  66404 	1326: uint16(5163),
  66405 	1327: uint16(5174),
  66406 	1328: uint16(5180),
  66407 	1329: uint16(5189),
  66408 	1330: uint16(5195),
  66409 	1331: uint16(5220),
  66410 	1332: uint16(5226),
  66411 	1333: uint16(5235),
  66412 	1334: uint16(5241),
  66413 	1335: uint16(5252),
  66414 	1336: uint16(5258),
  66415 	1337: uint16(5267),
  66416 	1338: uint16(5273),
  66417 	1339: uint16(5293),
  66418 	1340: uint16(5299),
  66419 	1341: uint16(5308),
  66420 	1342: uint16(5314),
  66421 	1343: uint16(5325),
  66422 	1344: uint16(5331),
  66423 	1345: uint16(5340),
  66424 	1346: uint16(5346),
  66425 	1347: uint16(4604),
  66426 	1348: uint16(4610),
  66427 	1349: uint16(4619),
  66428 	1350: uint16(4625),
  66429 	1351: uint16(4636),
  66430 	1352: uint16(4642),
  66431 	1353: uint16(4651),
  66432 	1354: uint16(4657),
  66433 	1355: uint16(4677),
  66434 	1356: uint16(4683),
  66435 	1357: uint16(4692),
  66436 	1358: uint16(4698),
  66437 	1359: uint16(4709),
  66438 	1360: uint16(4715),
  66439 	1361: uint16(4724),
  66440 	1362: uint16(4730),
  66441 	1363: uint16(4755),
  66442 	1364: uint16(4761),
  66443 	1365: uint16(4770),
  66444 	1366: uint16(4776),
  66445 	1367: uint16(4787),
  66446 	1368: uint16(4793),
  66447 	1369: uint16(4802),
  66448 	1370: uint16(4808),
  66449 	1371: uint16(4828),
  66450 	1372: uint16(4834),
  66451 	1373: uint16(4843),
  66452 	1374: uint16(4849),
  66453 	1375: uint16(4860),
  66454 	1376: uint16(4866),
  66455 	1377: uint16(4875),
  66456 	1378: uint16(4881),
  66457 	1379: uint16(4904),
  66458 	1380: uint16(4910),
  66459 	1381: uint16(4919),
  66460 	1382: uint16(4925),
  66461 	1383: uint16(4936),
  66462 	1384: uint16(4942),
  66463 	1385: uint16(4951),
  66464 	1386: uint16(4957),
  66465 	1387: uint16(4977),
  66466 	1388: uint16(4983),
  66467 	1389: uint16(4992),
  66468 	1390: uint16(4998),
  66469 	1391: uint16(5009),
  66470 	1392: uint16(5015),
  66471 	1393: uint16(5024),
  66472 	1394: uint16(5030),
  66473 	1395: uint16(5055),
  66474 	1396: uint16(5061),
  66475 	1397: uint16(5070),
  66476 	1398: uint16(5076),
  66477 	1399: uint16(5087),
  66478 	1400: uint16(5093),
  66479 	1401: uint16(5102),
  66480 	1402: uint16(5108),
  66481 	1403: uint16(5128),
  66482 	1404: uint16(5134),
  66483 	1405: uint16(5143),
  66484 	1406: uint16(5149),
  66485 	1407: uint16(5160),
  66486 	1408: uint16(5166),
  66487 	1409: uint16(5175),
  66488 	1410: uint16(5181),
  66489 	1411: uint16(5045),
  66490 	1412: uint16(5051),
  66491 	1413: uint16(5060),
  66492 	1414: uint16(5066),
  66493 	1415: uint16(5077),
  66494 	1416: uint16(5083),
  66495 	1417: uint16(5092),
  66496 	1418: uint16(5098),
  66497 	1419: uint16(5118),
  66498 	1420: uint16(5124),
  66499 	1421: uint16(5133),
  66500 	1422: uint16(5139),
  66501 	1423: uint16(5150),
  66502 	1424: uint16(5156),
  66503 	1425: uint16(5165),
  66504 	1426: uint16(5171),
  66505 	1427: uint16(5196),
  66506 	1428: uint16(5202),
  66507 	1429: uint16(5211),
  66508 	1430: uint16(5217),
  66509 	1431: uint16(5228),
  66510 	1432: uint16(5234),
  66511 	1433: uint16(5243),
  66512 	1434: uint16(5249),
  66513 	1435: uint16(5269),
  66514 	1436: uint16(5275),
  66515 	1437: uint16(5284),
  66516 	1438: uint16(5290),
  66517 	1439: uint16(5301),
  66518 	1440: uint16(5307),
  66519 	1441: uint16(5316),
  66520 	1442: uint16(5322),
  66521 	1443: uint16(5345),
  66522 	1444: uint16(5351),
  66523 	1445: uint16(5360),
  66524 	1446: uint16(5366),
  66525 	1447: uint16(5377),
  66526 	1448: uint16(5383),
  66527 	1449: uint16(5392),
  66528 	1450: uint16(5398),
  66529 	1451: uint16(5418),
  66530 	1452: uint16(5424),
  66531 	1453: uint16(5433),
  66532 	1454: uint16(5439),
  66533 	1455: uint16(5450),
  66534 	1456: uint16(5456),
  66535 	1457: uint16(5465),
  66536 	1458: uint16(5471),
  66537 	1459: uint16(5496),
  66538 	1460: uint16(5502),
  66539 	1461: uint16(5511),
  66540 	1462: uint16(5517),
  66541 	1463: uint16(5528),
  66542 	1464: uint16(5534),
  66543 	1465: uint16(5543),
  66544 	1466: uint16(5549),
  66545 	1467: uint16(5569),
  66546 	1468: uint16(5575),
  66547 	1469: uint16(5584),
  66548 	1470: uint16(5590),
  66549 	1471: uint16(5601),
  66550 	1472: uint16(5607),
  66551 	1473: uint16(5616),
  66552 	1474: uint16(5622),
  66553 	1475: uint16(5417),
  66554 	1476: uint16(5423),
  66555 	1477: uint16(5432),
  66556 	1478: uint16(5438),
  66557 	1479: uint16(5449),
  66558 	1480: uint16(5455),
  66559 	1481: uint16(5464),
  66560 	1482: uint16(5470),
  66561 	1483: uint16(5490),
  66562 	1484: uint16(5496),
  66563 	1485: uint16(5505),
  66564 	1486: uint16(5511),
  66565 	1487: uint16(5522),
  66566 	1488: uint16(5528),
  66567 	1489: uint16(5537),
  66568 	1490: uint16(5543),
  66569 	1491: uint16(5568),
  66570 	1492: uint16(5574),
  66571 	1493: uint16(5583),
  66572 	1494: uint16(5589),
  66573 	1495: uint16(5600),
  66574 	1496: uint16(5606),
  66575 	1497: uint16(5615),
  66576 	1498: uint16(5621),
  66577 	1499: uint16(5641),
  66578 	1500: uint16(5647),
  66579 	1501: uint16(5656),
  66580 	1502: uint16(5662),
  66581 	1503: uint16(5673),
  66582 	1504: uint16(5679),
  66583 	1505: uint16(5688),
  66584 	1506: uint16(5694),
  66585 	1507: uint16(5717),
  66586 	1508: uint16(5723),
  66587 	1509: uint16(5732),
  66588 	1510: uint16(5738),
  66589 	1511: uint16(5749),
  66590 	1512: uint16(5755),
  66591 	1513: uint16(5764),
  66592 	1514: uint16(5770),
  66593 	1515: uint16(5790),
  66594 	1516: uint16(5796),
  66595 	1517: uint16(5805),
  66596 	1518: uint16(5811),
  66597 	1519: uint16(5822),
  66598 	1520: uint16(5828),
  66599 	1521: uint16(5837),
  66600 	1522: uint16(5843),
  66601 	1523: uint16(5868),
  66602 	1524: uint16(5874),
  66603 	1525: uint16(5883),
  66604 	1526: uint16(5889),
  66605 	1527: uint16(5900),
  66606 	1528: uint16(5906),
  66607 	1529: uint16(5915),
  66608 	1530: uint16(5921),
  66609 	1531: uint16(5941),
  66610 	1532: uint16(5947),
  66611 	1533: uint16(5956),
  66612 	1534: uint16(5962),
  66613 	1535: uint16(5973),
  66614 	1536: uint16(5979),
  66615 	1537: uint16(5988),
  66616 	1538: uint16(5994),
  66617 	1539: uint16(5858),
  66618 	1540: uint16(5864),
  66619 	1541: uint16(5873),
  66620 	1542: uint16(5879),
  66621 	1543: uint16(5890),
  66622 	1544: uint16(5896),
  66623 	1545: uint16(5905),
  66624 	1546: uint16(5911),
  66625 	1547: uint16(5931),
  66626 	1548: uint16(5937),
  66627 	1549: uint16(5946),
  66628 	1550: uint16(5952),
  66629 	1551: uint16(5963),
  66630 	1552: uint16(5969),
  66631 	1553: uint16(5978),
  66632 	1554: uint16(5984),
  66633 	1555: uint16(6009),
  66634 	1556: uint16(6015),
  66635 	1557: uint16(6024),
  66636 	1558: uint16(6030),
  66637 	1559: uint16(6041),
  66638 	1560: uint16(6047),
  66639 	1561: uint16(6056),
  66640 	1562: uint16(6062),
  66641 	1563: uint16(6082),
  66642 	1564: uint16(6088),
  66643 	1565: uint16(6097),
  66644 	1566: uint16(6103),
  66645 	1567: uint16(6114),
  66646 	1568: uint16(6120),
  66647 	1569: uint16(6129),
  66648 	1570: uint16(6135),
  66649 	1571: uint16(6158),
  66650 	1572: uint16(6164),
  66651 	1573: uint16(6173),
  66652 	1574: uint16(6179),
  66653 	1575: uint16(6190),
  66654 	1576: uint16(6196),
  66655 	1577: uint16(6205),
  66656 	1578: uint16(6211),
  66657 	1579: uint16(6231),
  66658 	1580: uint16(6237),
  66659 	1581: uint16(6246),
  66660 	1582: uint16(6252),
  66661 	1583: uint16(6263),
  66662 	1584: uint16(6269),
  66663 	1585: uint16(6278),
  66664 	1586: uint16(6284),
  66665 	1587: uint16(6309),
  66666 	1588: uint16(6315),
  66667 	1589: uint16(6324),
  66668 	1590: uint16(6330),
  66669 	1591: uint16(6341),
  66670 	1592: uint16(6347),
  66671 	1593: uint16(6356),
  66672 	1594: uint16(6362),
  66673 	1595: uint16(6382),
  66674 	1596: uint16(6388),
  66675 	1597: uint16(6397),
  66676 	1598: uint16(6403),
  66677 	1599: uint16(6414),
  66678 	1600: uint16(6420),
  66679 	1601: uint16(6429),
  66680 	1602: uint16(6435),
  66681 	1603: uint16(5303),
  66682 	1604: uint16(5309),
  66683 	1605: uint16(5318),
  66684 	1606: uint16(5324),
  66685 	1607: uint16(5335),
  66686 	1608: uint16(5341),
  66687 	1609: uint16(5350),
  66688 	1610: uint16(5356),
  66689 	1611: uint16(5376),
  66690 	1612: uint16(5382),
  66691 	1613: uint16(5391),
  66692 	1614: uint16(5397),
  66693 	1615: uint16(5408),
  66694 	1616: uint16(5414),
  66695 	1617: uint16(5423),
  66696 	1618: uint16(5429),
  66697 	1619: uint16(5454),
  66698 	1620: uint16(5460),
  66699 	1621: uint16(5469),
  66700 	1622: uint16(5475),
  66701 	1623: uint16(5486),
  66702 	1624: uint16(5492),
  66703 	1625: uint16(5501),
  66704 	1626: uint16(5507),
  66705 	1627: uint16(5527),
  66706 	1628: uint16(5533),
  66707 	1629: uint16(5542),
  66708 	1630: uint16(5548),
  66709 	1631: uint16(5559),
  66710 	1632: uint16(5565),
  66711 	1633: uint16(5574),
  66712 	1634: uint16(5580),
  66713 	1635: uint16(5603),
  66714 	1636: uint16(5609),
  66715 	1637: uint16(5618),
  66716 	1638: uint16(5624),
  66717 	1639: uint16(5635),
  66718 	1640: uint16(5641),
  66719 	1641: uint16(5650),
  66720 	1642: uint16(5656),
  66721 	1643: uint16(5676),
  66722 	1644: uint16(5682),
  66723 	1645: uint16(5691),
  66724 	1646: uint16(5697),
  66725 	1647: uint16(5708),
  66726 	1648: uint16(5714),
  66727 	1649: uint16(5723),
  66728 	1650: uint16(5729),
  66729 	1651: uint16(5754),
  66730 	1652: uint16(5760),
  66731 	1653: uint16(5769),
  66732 	1654: uint16(5775),
  66733 	1655: uint16(5786),
  66734 	1656: uint16(5792),
  66735 	1657: uint16(5801),
  66736 	1658: uint16(5807),
  66737 	1659: uint16(5827),
  66738 	1660: uint16(5833),
  66739 	1661: uint16(5842),
  66740 	1662: uint16(5848),
  66741 	1663: uint16(5859),
  66742 	1664: uint16(5865),
  66743 	1665: uint16(5874),
  66744 	1666: uint16(5880),
  66745 	1667: uint16(5744),
  66746 	1668: uint16(5750),
  66747 	1669: uint16(5759),
  66748 	1670: uint16(5765),
  66749 	1671: uint16(5776),
  66750 	1672: uint16(5782),
  66751 	1673: uint16(5791),
  66752 	1674: uint16(5797),
  66753 	1675: uint16(5817),
  66754 	1676: uint16(5823),
  66755 	1677: uint16(5832),
  66756 	1678: uint16(5838),
  66757 	1679: uint16(5849),
  66758 	1680: uint16(5855),
  66759 	1681: uint16(5864),
  66760 	1682: uint16(5870),
  66761 	1683: uint16(5895),
  66762 	1684: uint16(5901),
  66763 	1685: uint16(5910),
  66764 	1686: uint16(5916),
  66765 	1687: uint16(5927),
  66766 	1688: uint16(5933),
  66767 	1689: uint16(5942),
  66768 	1690: uint16(5948),
  66769 	1691: uint16(5968),
  66770 	1692: uint16(5974),
  66771 	1693: uint16(5983),
  66772 	1694: uint16(5989),
  66773 	1695: uint16(6000),
  66774 	1696: uint16(6006),
  66775 	1697: uint16(6015),
  66776 	1698: uint16(6021),
  66777 	1699: uint16(6044),
  66778 	1700: uint16(6050),
  66779 	1701: uint16(6059),
  66780 	1702: uint16(6065),
  66781 	1703: uint16(6076),
  66782 	1704: uint16(6082),
  66783 	1705: uint16(6091),
  66784 	1706: uint16(6097),
  66785 	1707: uint16(6117),
  66786 	1708: uint16(6123),
  66787 	1709: uint16(6132),
  66788 	1710: uint16(6138),
  66789 	1711: uint16(6149),
  66790 	1712: uint16(6155),
  66791 	1713: uint16(6164),
  66792 	1714: uint16(6170),
  66793 	1715: uint16(6195),
  66794 	1716: uint16(6201),
  66795 	1717: uint16(6210),
  66796 	1718: uint16(6216),
  66797 	1719: uint16(6227),
  66798 	1720: uint16(6233),
  66799 	1721: uint16(6242),
  66800 	1722: uint16(6248),
  66801 	1723: uint16(6268),
  66802 	1724: uint16(6274),
  66803 	1725: uint16(6283),
  66804 	1726: uint16(6289),
  66805 	1727: uint16(6300),
  66806 	1728: uint16(6306),
  66807 	1729: uint16(6315),
  66808 	1730: uint16(6321),
  66809 	1731: uint16(6116),
  66810 	1732: uint16(6122),
  66811 	1733: uint16(6131),
  66812 	1734: uint16(6137),
  66813 	1735: uint16(6148),
  66814 	1736: uint16(6154),
  66815 	1737: uint16(6163),
  66816 	1738: uint16(6169),
  66817 	1739: uint16(6189),
  66818 	1740: uint16(6195),
  66819 	1741: uint16(6204),
  66820 	1742: uint16(6210),
  66821 	1743: uint16(6221),
  66822 	1744: uint16(6227),
  66823 	1745: uint16(6236),
  66824 	1746: uint16(6242),
  66825 	1747: uint16(6267),
  66826 	1748: uint16(6273),
  66827 	1749: uint16(6282),
  66828 	1750: uint16(6288),
  66829 	1751: uint16(6299),
  66830 	1752: uint16(6305),
  66831 	1753: uint16(6314),
  66832 	1754: uint16(6320),
  66833 	1755: uint16(6340),
  66834 	1756: uint16(6346),
  66835 	1757: uint16(6355),
  66836 	1758: uint16(6361),
  66837 	1759: uint16(6372),
  66838 	1760: uint16(6378),
  66839 	1761: uint16(6387),
  66840 	1762: uint16(6393),
  66841 	1763: uint16(6416),
  66842 	1764: uint16(6422),
  66843 	1765: uint16(6431),
  66844 	1766: uint16(6437),
  66845 	1767: uint16(6448),
  66846 	1768: uint16(6454),
  66847 	1769: uint16(6463),
  66848 	1770: uint16(6469),
  66849 	1771: uint16(6489),
  66850 	1772: uint16(6495),
  66851 	1773: uint16(6504),
  66852 	1774: uint16(6510),
  66853 	1775: uint16(6521),
  66854 	1776: uint16(6527),
  66855 	1777: uint16(6536),
  66856 	1778: uint16(6542),
  66857 	1779: uint16(6567),
  66858 	1780: uint16(6573),
  66859 	1781: uint16(6582),
  66860 	1782: uint16(6588),
  66861 	1783: uint16(6599),
  66862 	1784: uint16(6605),
  66863 	1785: uint16(6614),
  66864 	1786: uint16(6620),
  66865 	1787: uint16(6640),
  66866 	1788: uint16(6646),
  66867 	1789: uint16(6655),
  66868 	1790: uint16(6661),
  66869 	1791: uint16(6672),
  66870 	1792: uint16(6678),
  66871 	1793: uint16(6687),
  66872 	1794: uint16(6693),
  66873 	1795: uint16(6557),
  66874 	1796: uint16(6563),
  66875 	1797: uint16(6572),
  66876 	1798: uint16(6578),
  66877 	1799: uint16(6589),
  66878 	1800: uint16(6595),
  66879 	1801: uint16(6604),
  66880 	1802: uint16(6610),
  66881 	1803: uint16(6630),
  66882 	1804: uint16(6636),
  66883 	1805: uint16(6645),
  66884 	1806: uint16(6651),
  66885 	1807: uint16(6662),
  66886 	1808: uint16(6668),
  66887 	1809: uint16(6677),
  66888 	1810: uint16(6683),
  66889 	1811: uint16(6708),
  66890 	1812: uint16(6714),
  66891 	1813: uint16(6723),
  66892 	1814: uint16(6729),
  66893 	1815: uint16(6740),
  66894 	1816: uint16(6746),
  66895 	1817: uint16(6755),
  66896 	1818: uint16(6761),
  66897 	1819: uint16(6781),
  66898 	1820: uint16(6787),
  66899 	1821: uint16(6796),
  66900 	1822: uint16(6802),
  66901 	1823: uint16(6813),
  66902 	1824: uint16(6819),
  66903 	1825: uint16(6828),
  66904 	1826: uint16(6834),
  66905 	1827: uint16(6857),
  66906 	1828: uint16(6863),
  66907 	1829: uint16(6872),
  66908 	1830: uint16(6878),
  66909 	1831: uint16(6889),
  66910 	1832: uint16(6895),
  66911 	1833: uint16(6904),
  66912 	1834: uint16(6910),
  66913 	1835: uint16(6930),
  66914 	1836: uint16(6936),
  66915 	1837: uint16(6945),
  66916 	1838: uint16(6951),
  66917 	1839: uint16(6962),
  66918 	1840: uint16(6968),
  66919 	1841: uint16(6977),
  66920 	1842: uint16(6983),
  66921 	1843: uint16(7008),
  66922 	1844: uint16(7014),
  66923 	1845: uint16(7023),
  66924 	1846: uint16(7029),
  66925 	1847: uint16(7040),
  66926 	1848: uint16(7046),
  66927 	1849: uint16(7055),
  66928 	1850: uint16(7061),
  66929 	1851: uint16(7081),
  66930 	1852: uint16(7087),
  66931 	1853: uint16(7096),
  66932 	1854: uint16(7102),
  66933 	1855: uint16(7113),
  66934 	1856: uint16(7119),
  66935 	1857: uint16(7128),
  66936 	1858: uint16(7134),
  66937 	1859: uint16(6392),
  66938 	1860: uint16(6398),
  66939 	1861: uint16(6407),
  66940 	1862: uint16(6413),
  66941 	1863: uint16(6424),
  66942 	1864: uint16(6430),
  66943 	1865: uint16(6439),
  66944 	1866: uint16(6445),
  66945 	1867: uint16(6465),
  66946 	1868: uint16(6471),
  66947 	1869: uint16(6480),
  66948 	1870: uint16(6486),
  66949 	1871: uint16(6497),
  66950 	1872: uint16(6503),
  66951 	1873: uint16(6512),
  66952 	1874: uint16(6518),
  66953 	1875: uint16(6543),
  66954 	1876: uint16(6549),
  66955 	1877: uint16(6558),
  66956 	1878: uint16(6564),
  66957 	1879: uint16(6575),
  66958 	1880: uint16(6581),
  66959 	1881: uint16(6590),
  66960 	1882: uint16(6596),
  66961 	1883: uint16(6616),
  66962 	1884: uint16(6622),
  66963 	1885: uint16(6631),
  66964 	1886: uint16(6637),
  66965 	1887: uint16(6648),
  66966 	1888: uint16(6654),
  66967 	1889: uint16(6663),
  66968 	1890: uint16(6669),
  66969 	1891: uint16(6692),
  66970 	1892: uint16(6698),
  66971 	1893: uint16(6707),
  66972 	1894: uint16(6713),
  66973 	1895: uint16(6724),
  66974 	1896: uint16(6730),
  66975 	1897: uint16(6739),
  66976 	1898: uint16(6745),
  66977 	1899: uint16(6765),
  66978 	1900: uint16(6771),
  66979 	1901: uint16(6780),
  66980 	1902: uint16(6786),
  66981 	1903: uint16(6797),
  66982 	1904: uint16(6803),
  66983 	1905: uint16(6812),
  66984 	1906: uint16(6818),
  66985 	1907: uint16(6843),
  66986 	1908: uint16(6849),
  66987 	1909: uint16(6858),
  66988 	1910: uint16(6864),
  66989 	1911: uint16(6875),
  66990 	1912: uint16(6881),
  66991 	1913: uint16(6890),
  66992 	1914: uint16(6896),
  66993 	1915: uint16(6916),
  66994 	1916: uint16(6922),
  66995 	1917: uint16(6931),
  66996 	1918: uint16(6937),
  66997 	1919: uint16(6948),
  66998 	1920: uint16(6954),
  66999 	1921: uint16(6963),
  67000 	1922: uint16(6969),
  67001 	1923: uint16(6833),
  67002 	1924: uint16(6839),
  67003 	1925: uint16(6848),
  67004 	1926: uint16(6854),
  67005 	1927: uint16(6865),
  67006 	1928: uint16(6871),
  67007 	1929: uint16(6880),
  67008 	1930: uint16(6886),
  67009 	1931: uint16(6906),
  67010 	1932: uint16(6912),
  67011 	1933: uint16(6921),
  67012 	1934: uint16(6927),
  67013 	1935: uint16(6938),
  67014 	1936: uint16(6944),
  67015 	1937: uint16(6953),
  67016 	1938: uint16(6959),
  67017 	1939: uint16(6984),
  67018 	1940: uint16(6990),
  67019 	1941: uint16(6999),
  67020 	1942: uint16(7005),
  67021 	1943: uint16(7016),
  67022 	1944: uint16(7022),
  67023 	1945: uint16(7031),
  67024 	1946: uint16(7037),
  67025 	1947: uint16(7057),
  67026 	1948: uint16(7063),
  67027 	1949: uint16(7072),
  67028 	1950: uint16(7078),
  67029 	1951: uint16(7089),
  67030 	1952: uint16(7095),
  67031 	1953: uint16(7104),
  67032 	1954: uint16(7110),
  67033 	1955: uint16(7133),
  67034 	1956: uint16(7139),
  67035 	1957: uint16(7148),
  67036 	1958: uint16(7154),
  67037 	1959: uint16(7165),
  67038 	1960: uint16(7171),
  67039 	1961: uint16(7180),
  67040 	1962: uint16(7186),
  67041 	1963: uint16(7206),
  67042 	1964: uint16(7212),
  67043 	1965: uint16(7221),
  67044 	1966: uint16(7227),
  67045 	1967: uint16(7238),
  67046 	1968: uint16(7244),
  67047 	1969: uint16(7253),
  67048 	1970: uint16(7259),
  67049 	1971: uint16(7284),
  67050 	1972: uint16(7290),
  67051 	1973: uint16(7299),
  67052 	1974: uint16(7305),
  67053 	1975: uint16(7316),
  67054 	1976: uint16(7322),
  67055 	1977: uint16(7331),
  67056 	1978: uint16(7337),
  67057 	1979: uint16(7357),
  67058 	1980: uint16(7363),
  67059 	1981: uint16(7372),
  67060 	1982: uint16(7378),
  67061 	1983: uint16(7389),
  67062 	1984: uint16(7395),
  67063 	1985: uint16(7404),
  67064 	1986: uint16(7410),
  67065 	1987: uint16(7205),
  67066 	1988: uint16(7211),
  67067 	1989: uint16(7220),
  67068 	1990: uint16(7226),
  67069 	1991: uint16(7237),
  67070 	1992: uint16(7243),
  67071 	1993: uint16(7252),
  67072 	1994: uint16(7258),
  67073 	1995: uint16(7278),
  67074 	1996: uint16(7284),
  67075 	1997: uint16(7293),
  67076 	1998: uint16(7299),
  67077 	1999: uint16(7310),
  67078 	2000: uint16(7316),
  67079 	2001: uint16(7325),
  67080 	2002: uint16(7331),
  67081 	2003: uint16(7356),
  67082 	2004: uint16(7362),
  67083 	2005: uint16(7371),
  67084 	2006: uint16(7377),
  67085 	2007: uint16(7388),
  67086 	2008: uint16(7394),
  67087 	2009: uint16(7403),
  67088 	2010: uint16(7409),
  67089 	2011: uint16(7429),
  67090 	2012: uint16(7435),
  67091 	2013: uint16(7444),
  67092 	2014: uint16(7450),
  67093 	2015: uint16(7461),
  67094 	2016: uint16(7467),
  67095 	2017: uint16(7476),
  67096 	2018: uint16(7482),
  67097 	2019: uint16(7505),
  67098 	2020: uint16(7511),
  67099 	2021: uint16(7520),
  67100 	2022: uint16(7526),
  67101 	2023: uint16(7537),
  67102 	2024: uint16(7543),
  67103 	2025: uint16(7552),
  67104 	2026: uint16(7558),
  67105 	2027: uint16(7578),
  67106 	2028: uint16(7584),
  67107 	2029: uint16(7593),
  67108 	2030: uint16(7599),
  67109 	2031: uint16(7610),
  67110 	2032: uint16(7616),
  67111 	2033: uint16(7625),
  67112 	2034: uint16(7631),
  67113 	2035: uint16(7656),
  67114 	2036: uint16(7662),
  67115 	2037: uint16(7671),
  67116 	2038: uint16(7677),
  67117 	2039: uint16(7688),
  67118 	2040: uint16(7694),
  67119 	2041: uint16(7703),
  67120 	2042: uint16(7709),
  67121 	2043: uint16(7729),
  67122 	2044: uint16(7735),
  67123 	2045: uint16(7744),
  67124 	2046: uint16(7750),
  67125 	2047: uint16(7761),
  67126 }
  67127 
  67128 var VP8Mean16x4 VP8MeanMetric
  67129 
  67130 var VP8PredChroma8 [7]VP8PredFunc
  67131 
  67132 var VP8PredLuma16 [7]VP8PredFunc
  67133 
  67134 var VP8PredLuma4 [10]VP8PredFunc
  67135 
  67136 var VP8SSE16x16 VP8Metric
  67137 
  67138 var VP8SSE16x8 VP8Metric
  67139 
  67140 var VP8SSE4x4 VP8Metric
  67141 
  67142 var VP8SSE8x8 VP8Metric
  67143 
  67144 //------------------------------------------------------------------------------
  67145 
  67146 var VP8SSIMGet VP8SSIMGetFunc
  67147 
  67148 var VP8SSIMGetClipped VP8SSIMGetClippedFunc
  67149 
  67150 //------------------------------------------------------------------------------
  67151 // Quantize
  67152 
  67153 // Layout:
  67154 // +----+----+
  67155 // |YYYY|UUVV| 0
  67156 // |YYYY|UUVV| 4
  67157 // |YYYY|....| 8
  67158 // |YYYY|....| 12
  67159 // +----+----+
  67160 
  67161 var VP8Scan = [16]uint16_t{
  67162 	1:  uint16(libc.Int32FromInt32(4) + libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)),
  67163 	2:  uint16(libc.Int32FromInt32(8) + libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)),
  67164 	3:  uint16(libc.Int32FromInt32(12) + libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)),
  67165 	4:  uint16(libc.Int32FromInt32(0) + libc.Int32FromInt32(4)*libc.Int32FromInt32(BPS)),
  67166 	5:  uint16(libc.Int32FromInt32(4) + libc.Int32FromInt32(4)*libc.Int32FromInt32(BPS)),
  67167 	6:  uint16(libc.Int32FromInt32(8) + libc.Int32FromInt32(4)*libc.Int32FromInt32(BPS)),
  67168 	7:  uint16(libc.Int32FromInt32(12) + libc.Int32FromInt32(4)*libc.Int32FromInt32(BPS)),
  67169 	8:  uint16(libc.Int32FromInt32(0) + libc.Int32FromInt32(8)*libc.Int32FromInt32(BPS)),
  67170 	9:  uint16(libc.Int32FromInt32(4) + libc.Int32FromInt32(8)*libc.Int32FromInt32(BPS)),
  67171 	10: uint16(libc.Int32FromInt32(8) + libc.Int32FromInt32(8)*libc.Int32FromInt32(BPS)),
  67172 	11: uint16(libc.Int32FromInt32(12) + libc.Int32FromInt32(8)*libc.Int32FromInt32(BPS)),
  67173 	12: uint16(libc.Int32FromInt32(0) + libc.Int32FromInt32(12)*libc.Int32FromInt32(BPS)),
  67174 	13: uint16(libc.Int32FromInt32(4) + libc.Int32FromInt32(12)*libc.Int32FromInt32(BPS)),
  67175 	14: uint16(libc.Int32FromInt32(8) + libc.Int32FromInt32(12)*libc.Int32FromInt32(BPS)),
  67176 	15: uint16(libc.Int32FromInt32(12) + libc.Int32FromInt32(12)*libc.Int32FromInt32(BPS)),
  67177 }
  67178 
  67179 var VP8SetResidualCoeffs VP8SetResidualCoeffsFunc
  67180 
  67181 var VP8SimpleHFilter16 VP8SimpleFilterFunc
  67182 
  67183 var VP8SimpleHFilter16i VP8SimpleFilterFunc
  67184 
  67185 var VP8SimpleVFilter16 VP8SimpleFilterFunc
  67186 
  67187 var VP8SimpleVFilter16i VP8SimpleFilterFunc
  67188 
  67189 var VP8TDisto16x16 VP8WMetric
  67190 
  67191 var VP8TDisto4x4 VP8WMetric
  67192 
  67193 //------------------------------------------------------------------------------
  67194 
  67195 var VP8Transform VP8DecIdct2
  67196 
  67197 var VP8TransformAC3 VP8DecIdct
  67198 
  67199 var VP8TransformDC VP8DecIdct
  67200 
  67201 var VP8TransformDCUV VP8DecIdct
  67202 
  67203 var VP8TransformUV VP8DecIdct
  67204 
  67205 var VP8TransformWHT VP8WHT
  67206 
  67207 var VP8UVModeOffsets = [4]uint16_t{
  67208 	0: uint16(libc.Int32FromInt32(2) * libc.Int32FromInt32(16) * libc.Int32FromInt32(BPS)),
  67209 	1: uint16(libc.Int32FromInt32(2)*libc.Int32FromInt32(16)*libc.Int32FromInt32(BPS) + libc.Int32FromInt32(1)*libc.Int32FromInt32(16)),
  67210 	2: uint16(libc.Int32FromInt32(2)*libc.Int32FromInt32(16)*libc.Int32FromInt32(BPS) + libc.Int32FromInt32(8)*libc.Int32FromInt32(BPS)),
  67211 	3: uint16(libc.Int32FromInt32(2)*libc.Int32FromInt32(16)*libc.Int32FromInt32(BPS) + libc.Int32FromInt32(8)*libc.Int32FromInt32(BPS) + libc.Int32FromInt32(1)*libc.Int32FromInt32(16)),
  67212 }
  67213 
  67214 var VP8VFilter16 VP8LumaFilterFunc
  67215 
  67216 var VP8VFilter16i VP8LumaFilterFunc
  67217 
  67218 var VP8VFilter8 VP8ChromaFilterFunc
  67219 
  67220 var VP8VFilter8i VP8ChromaFilterFunc
  67221 
  67222 var VP8kabs0 = uintptr(unsafe.Pointer(&abs0)) + 255
  67223 
  67224 var VP8kclip1 = uintptr(unsafe.Pointer(&clip11)) + 255
  67225 
  67226 var VP8ksclip1 = uintptr(unsafe.Pointer(&sclip1)) + 1020
  67227 
  67228 var VP8ksclip2 = uintptr(unsafe.Pointer(&sclip2)) + 112
  67229 
  67230 var WebPAlphaReplace uintptr
  67231 
  67232 var WebPApplyAlphaMultiply uintptr
  67233 
  67234 var WebPApplyAlphaMultiply4444 uintptr
  67235 
  67236 var WebPConvertARGBToUV uintptr
  67237 
  67238 var WebPConvertARGBToY uintptr
  67239 
  67240 var WebPConvertBGR24ToY uintptr
  67241 
  67242 //-----------------------------------------------------------------------------
  67243 
  67244 var WebPConvertRGB24ToY uintptr
  67245 
  67246 var WebPConvertRGBA32ToUV uintptr
  67247 
  67248 var WebPDispatchAlpha uintptr
  67249 
  67250 var WebPDispatchAlphaToGreen uintptr
  67251 
  67252 var WebPExtractAlpha uintptr
  67253 
  67254 var WebPExtractGreen uintptr
  67255 
  67256 //------------------------------------------------------------------------------
  67257 // Init function
  67258 
  67259 var WebPFilters [4]WebPFilterFunc
  67260 
  67261 var WebPHasAlpha32b uintptr
  67262 
  67263 var WebPHasAlpha8b uintptr
  67264 
  67265 var WebPMultARGBRow uintptr
  67266 
  67267 var WebPMultRow uintptr
  67268 
  67269 var WebPPackRGB uintptr
  67270 
  67271 var WebPRescalerExportRowExpand WebPRescalerExportRowFunc
  67272 
  67273 var WebPRescalerExportRowShrink WebPRescalerExportRowFunc
  67274 
  67275 //------------------------------------------------------------------------------
  67276 
  67277 var WebPRescalerImportRowExpand WebPRescalerImportRowFunc
  67278 
  67279 var WebPRescalerImportRowShrink WebPRescalerImportRowFunc
  67280 
  67281 //-----------------------------------------------------------------------------
  67282 // Main call
  67283 
  67284 var WebPSamplers [13]WebPSamplerRowFunc
  67285 
  67286 var WebPUnfilters [4]WebPUnfilterFunc
  67287 
  67288 // Copyright 2010 Google Inc. All Rights Reserved.
  67289 //
  67290 // Use of this source code is governed by a BSD-style license
  67291 // that can be found in the COPYING file in the root of the source
  67292 // tree. An additional intellectual property rights grant can be found
  67293 // in the file PATENTS. All contributing project authors may
  67294 // be found in the AUTHORS file in the root of the source tree.
  67295 // -----------------------------------------------------------------------------
  67296 //
  67297 //  Main decoding functions for WebP images.
  67298 //
  67299 // Author: Skal (pascal.massimino@gmail.com)
  67300 
  67301 //------------------------------------------------------------------------------
  67302 // Fancy upsampler
  67303 
  67304 // C documentation
  67305 //
  67306 //	// Fancy upsampling functions to convert YUV to RGB
  67307 var WebPUpsamplers [13]WebPUpsampleLinePairFunc
  67308 
  67309 var WebPYUV444Converters [13]WebPYUV444Converter
  67310 
  67311 // Copyright 2012 Google Inc. All Rights Reserved.
  67312 //
  67313 // Use of this source code is governed by a BSD-style license
  67314 // that can be found in the COPYING file in the root of the source
  67315 // tree. An additional intellectual property rights grant can be found
  67316 // in the file PATENTS. All contributing project authors may
  67317 // be found in the AUTHORS file in the root of the source tree.
  67318 // -----------------------------------------------------------------------------
  67319 //
  67320 // Misc. common utility functions
  67321 //
  67322 // Authors: Skal (pascal.massimino@gmail.com)
  67323 //          Urvang (urvang@google.com)
  67324 
  67325 // Copyright 2012 Google Inc. All Rights Reserved.
  67326 //
  67327 // Use of this source code is governed by a BSD-style license
  67328 // that can be found in the COPYING file in the root of the source
  67329 // tree. An additional intellectual property rights grant can be found
  67330 // in the file PATENTS. All contributing project authors may
  67331 // be found in the AUTHORS file in the root of the source tree.
  67332 // -----------------------------------------------------------------------------
  67333 //
  67334 //  Internal header for constants related to WebP file format.
  67335 //
  67336 // Author: Urvang (urvang@google.com)
  67337 
  67338 // Copyright 2010 Google Inc. All Rights Reserved.
  67339 //
  67340 // Use of this source code is governed by a BSD-style license
  67341 // that can be found in the COPYING file in the root of the source
  67342 // tree. An additional intellectual property rights grant can be found
  67343 // in the file PATENTS. All contributing project authors may
  67344 // be found in the AUTHORS file in the root of the source tree.
  67345 // -----------------------------------------------------------------------------
  67346 //
  67347 //  Common types + memory wrappers
  67348 //
  67349 // Author: Skal (pascal.massimino@gmail.com)
  67350 
  67351 // C documentation
  67352 //
  67353 //	// lookup table for small values of log2(int) * (1 << LOG_2_PRECISION_BITS).
  67354 //	// Obtained in Python with:
  67355 //	// a = [ str(round((1<<23)*math.log2(i))) if i else "0" for i in range(256)]
  67356 //	// print(',\n'.join(['  '+','.join(v)
  67357 //	//       for v in batched([i.rjust(9) for i in a],7)]))
  67358 var kLog2Table = [256]uint32_t{
  67359 	2:   uint32(8388608),
  67360 	3:   uint32(13295629),
  67361 	4:   uint32(16777216),
  67362 	5:   uint32(19477745),
  67363 	6:   uint32(21684237),
  67364 	7:   uint32(23549800),
  67365 	8:   uint32(25165824),
  67366 	9:   uint32(26591258),
  67367 	10:  uint32(27866353),
  67368 	11:  uint32(29019816),
  67369 	12:  uint32(30072845),
  67370 	13:  uint32(31041538),
  67371 	14:  uint32(31938408),
  67372 	15:  uint32(32773374),
  67373 	16:  uint32(33554432),
  67374 	17:  uint32(34288123),
  67375 	18:  uint32(34979866),
  67376 	19:  uint32(35634199),
  67377 	20:  uint32(36254961),
  67378 	21:  uint32(36845429),
  67379 	22:  uint32(37408424),
  67380 	23:  uint32(37946388),
  67381 	24:  uint32(38461453),
  67382 	25:  uint32(38955489),
  67383 	26:  uint32(39430146),
  67384 	27:  uint32(39886887),
  67385 	28:  uint32(40327016),
  67386 	29:  uint32(40751698),
  67387 	30:  uint32(41161982),
  67388 	31:  uint32(41558811),
  67389 	32:  uint32(41943040),
  67390 	33:  uint32(42315445),
  67391 	34:  uint32(42676731),
  67392 	35:  uint32(43027545),
  67393 	36:  uint32(43368474),
  67394 	37:  uint32(43700062),
  67395 	38:  uint32(44022807),
  67396 	39:  uint32(44337167),
  67397 	40:  uint32(44643569),
  67398 	41:  uint32(44942404),
  67399 	42:  uint32(45234037),
  67400 	43:  uint32(45518808),
  67401 	44:  uint32(45797032),
  67402 	45:  uint32(46069003),
  67403 	46:  uint32(46334996),
  67404 	47:  uint32(46595268),
  67405 	48:  uint32(46850061),
  67406 	49:  uint32(47099600),
  67407 	50:  uint32(47344097),
  67408 	51:  uint32(47583753),
  67409 	52:  uint32(47818754),
  67410 	53:  uint32(48049279),
  67411 	54:  uint32(48275495),
  67412 	55:  uint32(48497560),
  67413 	56:  uint32(48715624),
  67414 	57:  uint32(48929828),
  67415 	58:  uint32(49140306),
  67416 	59:  uint32(49347187),
  67417 	60:  uint32(49550590),
  67418 	61:  uint32(49750631),
  67419 	62:  uint32(49947419),
  67420 	63:  uint32(50141058),
  67421 	64:  uint32(50331648),
  67422 	65:  uint32(50519283),
  67423 	66:  uint32(50704053),
  67424 	67:  uint32(50886044),
  67425 	68:  uint32(51065339),
  67426 	69:  uint32(51242017),
  67427 	70:  uint32(51416153),
  67428 	71:  uint32(51587818),
  67429 	72:  uint32(51757082),
  67430 	73:  uint32(51924012),
  67431 	74:  uint32(52088670),
  67432 	75:  uint32(52251118),
  67433 	76:  uint32(52411415),
  67434 	77:  uint32(52569616),
  67435 	78:  uint32(52725775),
  67436 	79:  uint32(52879946),
  67437 	80:  uint32(53032177),
  67438 	81:  uint32(53182516),
  67439 	82:  uint32(53331012),
  67440 	83:  uint32(53477707),
  67441 	84:  uint32(53622645),
  67442 	85:  uint32(53765868),
  67443 	86:  uint32(53907416),
  67444 	87:  uint32(54047327),
  67445 	88:  uint32(54185640),
  67446 	89:  uint32(54322389),
  67447 	90:  uint32(54457611),
  67448 	91:  uint32(54591338),
  67449 	92:  uint32(54723604),
  67450 	93:  uint32(54854440),
  67451 	94:  uint32(54983876),
  67452 	95:  uint32(55111943),
  67453 	96:  uint32(55238669),
  67454 	97:  uint32(55364082),
  67455 	98:  uint32(55488208),
  67456 	99:  uint32(55611074),
  67457 	100: uint32(55732705),
  67458 	101: uint32(55853126),
  67459 	102: uint32(55972361),
  67460 	103: uint32(56090432),
  67461 	104: uint32(56207362),
  67462 	105: uint32(56323174),
  67463 	106: uint32(56437887),
  67464 	107: uint32(56551524),
  67465 	108: uint32(56664103),
  67466 	109: uint32(56775645),
  67467 	110: uint32(56886168),
  67468 	111: uint32(56995691),
  67469 	112: uint32(57104232),
  67470 	113: uint32(57211808),
  67471 	114: uint32(57318436),
  67472 	115: uint32(57424133),
  67473 	116: uint32(57528914),
  67474 	117: uint32(57632796),
  67475 	118: uint32(57735795),
  67476 	119: uint32(57837923),
  67477 	120: uint32(57939198),
  67478 	121: uint32(58039632),
  67479 	122: uint32(58139239),
  67480 	123: uint32(58238033),
  67481 	124: uint32(58336027),
  67482 	125: uint32(58433234),
  67483 	126: uint32(58529666),
  67484 	127: uint32(58625336),
  67485 	128: uint32(58720256),
  67486 	129: uint32(58814437),
  67487 	130: uint32(58907891),
  67488 	131: uint32(59000628),
  67489 	132: uint32(59092661),
  67490 	133: uint32(59183999),
  67491 	134: uint32(59274652),
  67492 	135: uint32(59364632),
  67493 	136: uint32(59453947),
  67494 	137: uint32(59542609),
  67495 	138: uint32(59630625),
  67496 	139: uint32(59718006),
  67497 	140: uint32(59804761),
  67498 	141: uint32(59890898),
  67499 	142: uint32(59976426),
  67500 	143: uint32(60061354),
  67501 	144: uint32(60145690),
  67502 	145: uint32(60229443),
  67503 	146: uint32(60312620),
  67504 	147: uint32(60395229),
  67505 	148: uint32(60477278),
  67506 	149: uint32(60558775),
  67507 	150: uint32(60639726),
  67508 	151: uint32(60720140),
  67509 	152: uint32(60800023),
  67510 	153: uint32(60879382),
  67511 	154: uint32(60958224),
  67512 	155: uint32(61036555),
  67513 	156: uint32(61114383),
  67514 	157: uint32(61191714),
  67515 	158: uint32(61268554),
  67516 	159: uint32(61344908),
  67517 	160: uint32(61420785),
  67518 	161: uint32(61496188),
  67519 	162: uint32(61571124),
  67520 	163: uint32(61645600),
  67521 	164: uint32(61719620),
  67522 	165: uint32(61793189),
  67523 	166: uint32(61866315),
  67524 	167: uint32(61939001),
  67525 	168: uint32(62011253),
  67526 	169: uint32(62083076),
  67527 	170: uint32(62154476),
  67528 	171: uint32(62225457),
  67529 	172: uint32(62296024),
  67530 	173: uint32(62366182),
  67531 	174: uint32(62435935),
  67532 	175: uint32(62505289),
  67533 	176: uint32(62574248),
  67534 	177: uint32(62642816),
  67535 	178: uint32(62710997),
  67536 	179: uint32(62778797),
  67537 	180: uint32(62846219),
  67538 	181: uint32(62913267),
  67539 	182: uint32(62979946),
  67540 	183: uint32(63046260),
  67541 	184: uint32(63112212),
  67542 	185: uint32(63177807),
  67543 	186: uint32(63243048),
  67544 	187: uint32(63307939),
  67545 	188: uint32(63372484),
  67546 	189: uint32(63436687),
  67547 	190: uint32(63500551),
  67548 	191: uint32(63564080),
  67549 	192: uint32(63627277),
  67550 	193: uint32(63690146),
  67551 	194: uint32(63752690),
  67552 	195: uint32(63814912),
  67553 	196: uint32(63876816),
  67554 	197: uint32(63938405),
  67555 	198: uint32(63999682),
  67556 	199: uint32(64060650),
  67557 	200: uint32(64121313),
  67558 	201: uint32(64181673),
  67559 	202: uint32(64241734),
  67560 	203: uint32(64301498),
  67561 	204: uint32(64360969),
  67562 	205: uint32(64420148),
  67563 	206: uint32(64479040),
  67564 	207: uint32(64537646),
  67565 	208: uint32(64595970),
  67566 	209: uint32(64654014),
  67567 	210: uint32(64711782),
  67568 	211: uint32(64769274),
  67569 	212: uint32(64826495),
  67570 	213: uint32(64883447),
  67571 	214: uint32(64940132),
  67572 	215: uint32(64996553),
  67573 	216: uint32(65052711),
  67574 	217: uint32(65108611),
  67575 	218: uint32(65164253),
  67576 	219: uint32(65219641),
  67577 	220: uint32(65274776),
  67578 	221: uint32(65329662),
  67579 	222: uint32(65384299),
  67580 	223: uint32(65438691),
  67581 	224: uint32(65492840),
  67582 	225: uint32(65546747),
  67583 	226: uint32(65600416),
  67584 	227: uint32(65653847),
  67585 	228: uint32(65707044),
  67586 	229: uint32(65760008),
  67587 	230: uint32(65812741),
  67588 	231: uint32(65865245),
  67589 	232: uint32(65917522),
  67590 	233: uint32(65969575),
  67591 	234: uint32(66021404),
  67592 	235: uint32(66073013),
  67593 	236: uint32(66124403),
  67594 	237: uint32(66175575),
  67595 	238: uint32(66226531),
  67596 	239: uint32(66277275),
  67597 	240: uint32(66327806),
  67598 	241: uint32(66378127),
  67599 	242: uint32(66428240),
  67600 	243: uint32(66478146),
  67601 	244: uint32(66527847),
  67602 	245: uint32(66577345),
  67603 	246: uint32(66626641),
  67604 	247: uint32(66675737),
  67605 	248: uint32(66724635),
  67606 	249: uint32(66773336),
  67607 	250: uint32(66821842),
  67608 	251: uint32(66870154),
  67609 	252: uint32(66918274),
  67610 	253: uint32(66966204),
  67611 	254: uint32(67013944),
  67612 	255: uint32(67061497),
  67613 }
  67614 
  67615 var kPrefixEncodeCode = [512]VP8LPrefixCode{
  67616 	0: {},
  67617 	1: {},
  67618 	2: {
  67619 		Fcode: int8(1),
  67620 	},
  67621 	3: {
  67622 		Fcode: int8(2),
  67623 	},
  67624 	4: {
  67625 		Fcode: int8(3),
  67626 	},
  67627 	5: {
  67628 		Fcode:       int8(4),
  67629 		Fextra_bits: int8(1),
  67630 	},
  67631 	6: {
  67632 		Fcode:       int8(4),
  67633 		Fextra_bits: int8(1),
  67634 	},
  67635 	7: {
  67636 		Fcode:       int8(5),
  67637 		Fextra_bits: int8(1),
  67638 	},
  67639 	8: {
  67640 		Fcode:       int8(5),
  67641 		Fextra_bits: int8(1),
  67642 	},
  67643 	9: {
  67644 		Fcode:       int8(6),
  67645 		Fextra_bits: int8(2),
  67646 	},
  67647 	10: {
  67648 		Fcode:       int8(6),
  67649 		Fextra_bits: int8(2),
  67650 	},
  67651 	11: {
  67652 		Fcode:       int8(6),
  67653 		Fextra_bits: int8(2),
  67654 	},
  67655 	12: {
  67656 		Fcode:       int8(6),
  67657 		Fextra_bits: int8(2),
  67658 	},
  67659 	13: {
  67660 		Fcode:       int8(7),
  67661 		Fextra_bits: int8(2),
  67662 	},
  67663 	14: {
  67664 		Fcode:       int8(7),
  67665 		Fextra_bits: int8(2),
  67666 	},
  67667 	15: {
  67668 		Fcode:       int8(7),
  67669 		Fextra_bits: int8(2),
  67670 	},
  67671 	16: {
  67672 		Fcode:       int8(7),
  67673 		Fextra_bits: int8(2),
  67674 	},
  67675 	17: {
  67676 		Fcode:       int8(8),
  67677 		Fextra_bits: int8(3),
  67678 	},
  67679 	18: {
  67680 		Fcode:       int8(8),
  67681 		Fextra_bits: int8(3),
  67682 	},
  67683 	19: {
  67684 		Fcode:       int8(8),
  67685 		Fextra_bits: int8(3),
  67686 	},
  67687 	20: {
  67688 		Fcode:       int8(8),
  67689 		Fextra_bits: int8(3),
  67690 	},
  67691 	21: {
  67692 		Fcode:       int8(8),
  67693 		Fextra_bits: int8(3),
  67694 	},
  67695 	22: {
  67696 		Fcode:       int8(8),
  67697 		Fextra_bits: int8(3),
  67698 	},
  67699 	23: {
  67700 		Fcode:       int8(8),
  67701 		Fextra_bits: int8(3),
  67702 	},
  67703 	24: {
  67704 		Fcode:       int8(8),
  67705 		Fextra_bits: int8(3),
  67706 	},
  67707 	25: {
  67708 		Fcode:       int8(9),
  67709 		Fextra_bits: int8(3),
  67710 	},
  67711 	26: {
  67712 		Fcode:       int8(9),
  67713 		Fextra_bits: int8(3),
  67714 	},
  67715 	27: {
  67716 		Fcode:       int8(9),
  67717 		Fextra_bits: int8(3),
  67718 	},
  67719 	28: {
  67720 		Fcode:       int8(9),
  67721 		Fextra_bits: int8(3),
  67722 	},
  67723 	29: {
  67724 		Fcode:       int8(9),
  67725 		Fextra_bits: int8(3),
  67726 	},
  67727 	30: {
  67728 		Fcode:       int8(9),
  67729 		Fextra_bits: int8(3),
  67730 	},
  67731 	31: {
  67732 		Fcode:       int8(9),
  67733 		Fextra_bits: int8(3),
  67734 	},
  67735 	32: {
  67736 		Fcode:       int8(9),
  67737 		Fextra_bits: int8(3),
  67738 	},
  67739 	33: {
  67740 		Fcode:       int8(10),
  67741 		Fextra_bits: int8(4),
  67742 	},
  67743 	34: {
  67744 		Fcode:       int8(10),
  67745 		Fextra_bits: int8(4),
  67746 	},
  67747 	35: {
  67748 		Fcode:       int8(10),
  67749 		Fextra_bits: int8(4),
  67750 	},
  67751 	36: {
  67752 		Fcode:       int8(10),
  67753 		Fextra_bits: int8(4),
  67754 	},
  67755 	37: {
  67756 		Fcode:       int8(10),
  67757 		Fextra_bits: int8(4),
  67758 	},
  67759 	38: {
  67760 		Fcode:       int8(10),
  67761 		Fextra_bits: int8(4),
  67762 	},
  67763 	39: {
  67764 		Fcode:       int8(10),
  67765 		Fextra_bits: int8(4),
  67766 	},
  67767 	40: {
  67768 		Fcode:       int8(10),
  67769 		Fextra_bits: int8(4),
  67770 	},
  67771 	41: {
  67772 		Fcode:       int8(10),
  67773 		Fextra_bits: int8(4),
  67774 	},
  67775 	42: {
  67776 		Fcode:       int8(10),
  67777 		Fextra_bits: int8(4),
  67778 	},
  67779 	43: {
  67780 		Fcode:       int8(10),
  67781 		Fextra_bits: int8(4),
  67782 	},
  67783 	44: {
  67784 		Fcode:       int8(10),
  67785 		Fextra_bits: int8(4),
  67786 	},
  67787 	45: {
  67788 		Fcode:       int8(10),
  67789 		Fextra_bits: int8(4),
  67790 	},
  67791 	46: {
  67792 		Fcode:       int8(10),
  67793 		Fextra_bits: int8(4),
  67794 	},
  67795 	47: {
  67796 		Fcode:       int8(10),
  67797 		Fextra_bits: int8(4),
  67798 	},
  67799 	48: {
  67800 		Fcode:       int8(10),
  67801 		Fextra_bits: int8(4),
  67802 	},
  67803 	49: {
  67804 		Fcode:       int8(11),
  67805 		Fextra_bits: int8(4),
  67806 	},
  67807 	50: {
  67808 		Fcode:       int8(11),
  67809 		Fextra_bits: int8(4),
  67810 	},
  67811 	51: {
  67812 		Fcode:       int8(11),
  67813 		Fextra_bits: int8(4),
  67814 	},
  67815 	52: {
  67816 		Fcode:       int8(11),
  67817 		Fextra_bits: int8(4),
  67818 	},
  67819 	53: {
  67820 		Fcode:       int8(11),
  67821 		Fextra_bits: int8(4),
  67822 	},
  67823 	54: {
  67824 		Fcode:       int8(11),
  67825 		Fextra_bits: int8(4),
  67826 	},
  67827 	55: {
  67828 		Fcode:       int8(11),
  67829 		Fextra_bits: int8(4),
  67830 	},
  67831 	56: {
  67832 		Fcode:       int8(11),
  67833 		Fextra_bits: int8(4),
  67834 	},
  67835 	57: {
  67836 		Fcode:       int8(11),
  67837 		Fextra_bits: int8(4),
  67838 	},
  67839 	58: {
  67840 		Fcode:       int8(11),
  67841 		Fextra_bits: int8(4),
  67842 	},
  67843 	59: {
  67844 		Fcode:       int8(11),
  67845 		Fextra_bits: int8(4),
  67846 	},
  67847 	60: {
  67848 		Fcode:       int8(11),
  67849 		Fextra_bits: int8(4),
  67850 	},
  67851 	61: {
  67852 		Fcode:       int8(11),
  67853 		Fextra_bits: int8(4),
  67854 	},
  67855 	62: {
  67856 		Fcode:       int8(11),
  67857 		Fextra_bits: int8(4),
  67858 	},
  67859 	63: {
  67860 		Fcode:       int8(11),
  67861 		Fextra_bits: int8(4),
  67862 	},
  67863 	64: {
  67864 		Fcode:       int8(11),
  67865 		Fextra_bits: int8(4),
  67866 	},
  67867 	65: {
  67868 		Fcode:       int8(12),
  67869 		Fextra_bits: int8(5),
  67870 	},
  67871 	66: {
  67872 		Fcode:       int8(12),
  67873 		Fextra_bits: int8(5),
  67874 	},
  67875 	67: {
  67876 		Fcode:       int8(12),
  67877 		Fextra_bits: int8(5),
  67878 	},
  67879 	68: {
  67880 		Fcode:       int8(12),
  67881 		Fextra_bits: int8(5),
  67882 	},
  67883 	69: {
  67884 		Fcode:       int8(12),
  67885 		Fextra_bits: int8(5),
  67886 	},
  67887 	70: {
  67888 		Fcode:       int8(12),
  67889 		Fextra_bits: int8(5),
  67890 	},
  67891 	71: {
  67892 		Fcode:       int8(12),
  67893 		Fextra_bits: int8(5),
  67894 	},
  67895 	72: {
  67896 		Fcode:       int8(12),
  67897 		Fextra_bits: int8(5),
  67898 	},
  67899 	73: {
  67900 		Fcode:       int8(12),
  67901 		Fextra_bits: int8(5),
  67902 	},
  67903 	74: {
  67904 		Fcode:       int8(12),
  67905 		Fextra_bits: int8(5),
  67906 	},
  67907 	75: {
  67908 		Fcode:       int8(12),
  67909 		Fextra_bits: int8(5),
  67910 	},
  67911 	76: {
  67912 		Fcode:       int8(12),
  67913 		Fextra_bits: int8(5),
  67914 	},
  67915 	77: {
  67916 		Fcode:       int8(12),
  67917 		Fextra_bits: int8(5),
  67918 	},
  67919 	78: {
  67920 		Fcode:       int8(12),
  67921 		Fextra_bits: int8(5),
  67922 	},
  67923 	79: {
  67924 		Fcode:       int8(12),
  67925 		Fextra_bits: int8(5),
  67926 	},
  67927 	80: {
  67928 		Fcode:       int8(12),
  67929 		Fextra_bits: int8(5),
  67930 	},
  67931 	81: {
  67932 		Fcode:       int8(12),
  67933 		Fextra_bits: int8(5),
  67934 	},
  67935 	82: {
  67936 		Fcode:       int8(12),
  67937 		Fextra_bits: int8(5),
  67938 	},
  67939 	83: {
  67940 		Fcode:       int8(12),
  67941 		Fextra_bits: int8(5),
  67942 	},
  67943 	84: {
  67944 		Fcode:       int8(12),
  67945 		Fextra_bits: int8(5),
  67946 	},
  67947 	85: {
  67948 		Fcode:       int8(12),
  67949 		Fextra_bits: int8(5),
  67950 	},
  67951 	86: {
  67952 		Fcode:       int8(12),
  67953 		Fextra_bits: int8(5),
  67954 	},
  67955 	87: {
  67956 		Fcode:       int8(12),
  67957 		Fextra_bits: int8(5),
  67958 	},
  67959 	88: {
  67960 		Fcode:       int8(12),
  67961 		Fextra_bits: int8(5),
  67962 	},
  67963 	89: {
  67964 		Fcode:       int8(12),
  67965 		Fextra_bits: int8(5),
  67966 	},
  67967 	90: {
  67968 		Fcode:       int8(12),
  67969 		Fextra_bits: int8(5),
  67970 	},
  67971 	91: {
  67972 		Fcode:       int8(12),
  67973 		Fextra_bits: int8(5),
  67974 	},
  67975 	92: {
  67976 		Fcode:       int8(12),
  67977 		Fextra_bits: int8(5),
  67978 	},
  67979 	93: {
  67980 		Fcode:       int8(12),
  67981 		Fextra_bits: int8(5),
  67982 	},
  67983 	94: {
  67984 		Fcode:       int8(12),
  67985 		Fextra_bits: int8(5),
  67986 	},
  67987 	95: {
  67988 		Fcode:       int8(12),
  67989 		Fextra_bits: int8(5),
  67990 	},
  67991 	96: {
  67992 		Fcode:       int8(12),
  67993 		Fextra_bits: int8(5),
  67994 	},
  67995 	97: {
  67996 		Fcode:       int8(13),
  67997 		Fextra_bits: int8(5),
  67998 	},
  67999 	98: {
  68000 		Fcode:       int8(13),
  68001 		Fextra_bits: int8(5),
  68002 	},
  68003 	99: {
  68004 		Fcode:       int8(13),
  68005 		Fextra_bits: int8(5),
  68006 	},
  68007 	100: {
  68008 		Fcode:       int8(13),
  68009 		Fextra_bits: int8(5),
  68010 	},
  68011 	101: {
  68012 		Fcode:       int8(13),
  68013 		Fextra_bits: int8(5),
  68014 	},
  68015 	102: {
  68016 		Fcode:       int8(13),
  68017 		Fextra_bits: int8(5),
  68018 	},
  68019 	103: {
  68020 		Fcode:       int8(13),
  68021 		Fextra_bits: int8(5),
  68022 	},
  68023 	104: {
  68024 		Fcode:       int8(13),
  68025 		Fextra_bits: int8(5),
  68026 	},
  68027 	105: {
  68028 		Fcode:       int8(13),
  68029 		Fextra_bits: int8(5),
  68030 	},
  68031 	106: {
  68032 		Fcode:       int8(13),
  68033 		Fextra_bits: int8(5),
  68034 	},
  68035 	107: {
  68036 		Fcode:       int8(13),
  68037 		Fextra_bits: int8(5),
  68038 	},
  68039 	108: {
  68040 		Fcode:       int8(13),
  68041 		Fextra_bits: int8(5),
  68042 	},
  68043 	109: {
  68044 		Fcode:       int8(13),
  68045 		Fextra_bits: int8(5),
  68046 	},
  68047 	110: {
  68048 		Fcode:       int8(13),
  68049 		Fextra_bits: int8(5),
  68050 	},
  68051 	111: {
  68052 		Fcode:       int8(13),
  68053 		Fextra_bits: int8(5),
  68054 	},
  68055 	112: {
  68056 		Fcode:       int8(13),
  68057 		Fextra_bits: int8(5),
  68058 	},
  68059 	113: {
  68060 		Fcode:       int8(13),
  68061 		Fextra_bits: int8(5),
  68062 	},
  68063 	114: {
  68064 		Fcode:       int8(13),
  68065 		Fextra_bits: int8(5),
  68066 	},
  68067 	115: {
  68068 		Fcode:       int8(13),
  68069 		Fextra_bits: int8(5),
  68070 	},
  68071 	116: {
  68072 		Fcode:       int8(13),
  68073 		Fextra_bits: int8(5),
  68074 	},
  68075 	117: {
  68076 		Fcode:       int8(13),
  68077 		Fextra_bits: int8(5),
  68078 	},
  68079 	118: {
  68080 		Fcode:       int8(13),
  68081 		Fextra_bits: int8(5),
  68082 	},
  68083 	119: {
  68084 		Fcode:       int8(13),
  68085 		Fextra_bits: int8(5),
  68086 	},
  68087 	120: {
  68088 		Fcode:       int8(13),
  68089 		Fextra_bits: int8(5),
  68090 	},
  68091 	121: {
  68092 		Fcode:       int8(13),
  68093 		Fextra_bits: int8(5),
  68094 	},
  68095 	122: {
  68096 		Fcode:       int8(13),
  68097 		Fextra_bits: int8(5),
  68098 	},
  68099 	123: {
  68100 		Fcode:       int8(13),
  68101 		Fextra_bits: int8(5),
  68102 	},
  68103 	124: {
  68104 		Fcode:       int8(13),
  68105 		Fextra_bits: int8(5),
  68106 	},
  68107 	125: {
  68108 		Fcode:       int8(13),
  68109 		Fextra_bits: int8(5),
  68110 	},
  68111 	126: {
  68112 		Fcode:       int8(13),
  68113 		Fextra_bits: int8(5),
  68114 	},
  68115 	127: {
  68116 		Fcode:       int8(13),
  68117 		Fextra_bits: int8(5),
  68118 	},
  68119 	128: {
  68120 		Fcode:       int8(13),
  68121 		Fextra_bits: int8(5),
  68122 	},
  68123 	129: {
  68124 		Fcode:       int8(14),
  68125 		Fextra_bits: int8(6),
  68126 	},
  68127 	130: {
  68128 		Fcode:       int8(14),
  68129 		Fextra_bits: int8(6),
  68130 	},
  68131 	131: {
  68132 		Fcode:       int8(14),
  68133 		Fextra_bits: int8(6),
  68134 	},
  68135 	132: {
  68136 		Fcode:       int8(14),
  68137 		Fextra_bits: int8(6),
  68138 	},
  68139 	133: {
  68140 		Fcode:       int8(14),
  68141 		Fextra_bits: int8(6),
  68142 	},
  68143 	134: {
  68144 		Fcode:       int8(14),
  68145 		Fextra_bits: int8(6),
  68146 	},
  68147 	135: {
  68148 		Fcode:       int8(14),
  68149 		Fextra_bits: int8(6),
  68150 	},
  68151 	136: {
  68152 		Fcode:       int8(14),
  68153 		Fextra_bits: int8(6),
  68154 	},
  68155 	137: {
  68156 		Fcode:       int8(14),
  68157 		Fextra_bits: int8(6),
  68158 	},
  68159 	138: {
  68160 		Fcode:       int8(14),
  68161 		Fextra_bits: int8(6),
  68162 	},
  68163 	139: {
  68164 		Fcode:       int8(14),
  68165 		Fextra_bits: int8(6),
  68166 	},
  68167 	140: {
  68168 		Fcode:       int8(14),
  68169 		Fextra_bits: int8(6),
  68170 	},
  68171 	141: {
  68172 		Fcode:       int8(14),
  68173 		Fextra_bits: int8(6),
  68174 	},
  68175 	142: {
  68176 		Fcode:       int8(14),
  68177 		Fextra_bits: int8(6),
  68178 	},
  68179 	143: {
  68180 		Fcode:       int8(14),
  68181 		Fextra_bits: int8(6),
  68182 	},
  68183 	144: {
  68184 		Fcode:       int8(14),
  68185 		Fextra_bits: int8(6),
  68186 	},
  68187 	145: {
  68188 		Fcode:       int8(14),
  68189 		Fextra_bits: int8(6),
  68190 	},
  68191 	146: {
  68192 		Fcode:       int8(14),
  68193 		Fextra_bits: int8(6),
  68194 	},
  68195 	147: {
  68196 		Fcode:       int8(14),
  68197 		Fextra_bits: int8(6),
  68198 	},
  68199 	148: {
  68200 		Fcode:       int8(14),
  68201 		Fextra_bits: int8(6),
  68202 	},
  68203 	149: {
  68204 		Fcode:       int8(14),
  68205 		Fextra_bits: int8(6),
  68206 	},
  68207 	150: {
  68208 		Fcode:       int8(14),
  68209 		Fextra_bits: int8(6),
  68210 	},
  68211 	151: {
  68212 		Fcode:       int8(14),
  68213 		Fextra_bits: int8(6),
  68214 	},
  68215 	152: {
  68216 		Fcode:       int8(14),
  68217 		Fextra_bits: int8(6),
  68218 	},
  68219 	153: {
  68220 		Fcode:       int8(14),
  68221 		Fextra_bits: int8(6),
  68222 	},
  68223 	154: {
  68224 		Fcode:       int8(14),
  68225 		Fextra_bits: int8(6),
  68226 	},
  68227 	155: {
  68228 		Fcode:       int8(14),
  68229 		Fextra_bits: int8(6),
  68230 	},
  68231 	156: {
  68232 		Fcode:       int8(14),
  68233 		Fextra_bits: int8(6),
  68234 	},
  68235 	157: {
  68236 		Fcode:       int8(14),
  68237 		Fextra_bits: int8(6),
  68238 	},
  68239 	158: {
  68240 		Fcode:       int8(14),
  68241 		Fextra_bits: int8(6),
  68242 	},
  68243 	159: {
  68244 		Fcode:       int8(14),
  68245 		Fextra_bits: int8(6),
  68246 	},
  68247 	160: {
  68248 		Fcode:       int8(14),
  68249 		Fextra_bits: int8(6),
  68250 	},
  68251 	161: {
  68252 		Fcode:       int8(14),
  68253 		Fextra_bits: int8(6),
  68254 	},
  68255 	162: {
  68256 		Fcode:       int8(14),
  68257 		Fextra_bits: int8(6),
  68258 	},
  68259 	163: {
  68260 		Fcode:       int8(14),
  68261 		Fextra_bits: int8(6),
  68262 	},
  68263 	164: {
  68264 		Fcode:       int8(14),
  68265 		Fextra_bits: int8(6),
  68266 	},
  68267 	165: {
  68268 		Fcode:       int8(14),
  68269 		Fextra_bits: int8(6),
  68270 	},
  68271 	166: {
  68272 		Fcode:       int8(14),
  68273 		Fextra_bits: int8(6),
  68274 	},
  68275 	167: {
  68276 		Fcode:       int8(14),
  68277 		Fextra_bits: int8(6),
  68278 	},
  68279 	168: {
  68280 		Fcode:       int8(14),
  68281 		Fextra_bits: int8(6),
  68282 	},
  68283 	169: {
  68284 		Fcode:       int8(14),
  68285 		Fextra_bits: int8(6),
  68286 	},
  68287 	170: {
  68288 		Fcode:       int8(14),
  68289 		Fextra_bits: int8(6),
  68290 	},
  68291 	171: {
  68292 		Fcode:       int8(14),
  68293 		Fextra_bits: int8(6),
  68294 	},
  68295 	172: {
  68296 		Fcode:       int8(14),
  68297 		Fextra_bits: int8(6),
  68298 	},
  68299 	173: {
  68300 		Fcode:       int8(14),
  68301 		Fextra_bits: int8(6),
  68302 	},
  68303 	174: {
  68304 		Fcode:       int8(14),
  68305 		Fextra_bits: int8(6),
  68306 	},
  68307 	175: {
  68308 		Fcode:       int8(14),
  68309 		Fextra_bits: int8(6),
  68310 	},
  68311 	176: {
  68312 		Fcode:       int8(14),
  68313 		Fextra_bits: int8(6),
  68314 	},
  68315 	177: {
  68316 		Fcode:       int8(14),
  68317 		Fextra_bits: int8(6),
  68318 	},
  68319 	178: {
  68320 		Fcode:       int8(14),
  68321 		Fextra_bits: int8(6),
  68322 	},
  68323 	179: {
  68324 		Fcode:       int8(14),
  68325 		Fextra_bits: int8(6),
  68326 	},
  68327 	180: {
  68328 		Fcode:       int8(14),
  68329 		Fextra_bits: int8(6),
  68330 	},
  68331 	181: {
  68332 		Fcode:       int8(14),
  68333 		Fextra_bits: int8(6),
  68334 	},
  68335 	182: {
  68336 		Fcode:       int8(14),
  68337 		Fextra_bits: int8(6),
  68338 	},
  68339 	183: {
  68340 		Fcode:       int8(14),
  68341 		Fextra_bits: int8(6),
  68342 	},
  68343 	184: {
  68344 		Fcode:       int8(14),
  68345 		Fextra_bits: int8(6),
  68346 	},
  68347 	185: {
  68348 		Fcode:       int8(14),
  68349 		Fextra_bits: int8(6),
  68350 	},
  68351 	186: {
  68352 		Fcode:       int8(14),
  68353 		Fextra_bits: int8(6),
  68354 	},
  68355 	187: {
  68356 		Fcode:       int8(14),
  68357 		Fextra_bits: int8(6),
  68358 	},
  68359 	188: {
  68360 		Fcode:       int8(14),
  68361 		Fextra_bits: int8(6),
  68362 	},
  68363 	189: {
  68364 		Fcode:       int8(14),
  68365 		Fextra_bits: int8(6),
  68366 	},
  68367 	190: {
  68368 		Fcode:       int8(14),
  68369 		Fextra_bits: int8(6),
  68370 	},
  68371 	191: {
  68372 		Fcode:       int8(14),
  68373 		Fextra_bits: int8(6),
  68374 	},
  68375 	192: {
  68376 		Fcode:       int8(14),
  68377 		Fextra_bits: int8(6),
  68378 	},
  68379 	193: {
  68380 		Fcode:       int8(15),
  68381 		Fextra_bits: int8(6),
  68382 	},
  68383 	194: {
  68384 		Fcode:       int8(15),
  68385 		Fextra_bits: int8(6),
  68386 	},
  68387 	195: {
  68388 		Fcode:       int8(15),
  68389 		Fextra_bits: int8(6),
  68390 	},
  68391 	196: {
  68392 		Fcode:       int8(15),
  68393 		Fextra_bits: int8(6),
  68394 	},
  68395 	197: {
  68396 		Fcode:       int8(15),
  68397 		Fextra_bits: int8(6),
  68398 	},
  68399 	198: {
  68400 		Fcode:       int8(15),
  68401 		Fextra_bits: int8(6),
  68402 	},
  68403 	199: {
  68404 		Fcode:       int8(15),
  68405 		Fextra_bits: int8(6),
  68406 	},
  68407 	200: {
  68408 		Fcode:       int8(15),
  68409 		Fextra_bits: int8(6),
  68410 	},
  68411 	201: {
  68412 		Fcode:       int8(15),
  68413 		Fextra_bits: int8(6),
  68414 	},
  68415 	202: {
  68416 		Fcode:       int8(15),
  68417 		Fextra_bits: int8(6),
  68418 	},
  68419 	203: {
  68420 		Fcode:       int8(15),
  68421 		Fextra_bits: int8(6),
  68422 	},
  68423 	204: {
  68424 		Fcode:       int8(15),
  68425 		Fextra_bits: int8(6),
  68426 	},
  68427 	205: {
  68428 		Fcode:       int8(15),
  68429 		Fextra_bits: int8(6),
  68430 	},
  68431 	206: {
  68432 		Fcode:       int8(15),
  68433 		Fextra_bits: int8(6),
  68434 	},
  68435 	207: {
  68436 		Fcode:       int8(15),
  68437 		Fextra_bits: int8(6),
  68438 	},
  68439 	208: {
  68440 		Fcode:       int8(15),
  68441 		Fextra_bits: int8(6),
  68442 	},
  68443 	209: {
  68444 		Fcode:       int8(15),
  68445 		Fextra_bits: int8(6),
  68446 	},
  68447 	210: {
  68448 		Fcode:       int8(15),
  68449 		Fextra_bits: int8(6),
  68450 	},
  68451 	211: {
  68452 		Fcode:       int8(15),
  68453 		Fextra_bits: int8(6),
  68454 	},
  68455 	212: {
  68456 		Fcode:       int8(15),
  68457 		Fextra_bits: int8(6),
  68458 	},
  68459 	213: {
  68460 		Fcode:       int8(15),
  68461 		Fextra_bits: int8(6),
  68462 	},
  68463 	214: {
  68464 		Fcode:       int8(15),
  68465 		Fextra_bits: int8(6),
  68466 	},
  68467 	215: {
  68468 		Fcode:       int8(15),
  68469 		Fextra_bits: int8(6),
  68470 	},
  68471 	216: {
  68472 		Fcode:       int8(15),
  68473 		Fextra_bits: int8(6),
  68474 	},
  68475 	217: {
  68476 		Fcode:       int8(15),
  68477 		Fextra_bits: int8(6),
  68478 	},
  68479 	218: {
  68480 		Fcode:       int8(15),
  68481 		Fextra_bits: int8(6),
  68482 	},
  68483 	219: {
  68484 		Fcode:       int8(15),
  68485 		Fextra_bits: int8(6),
  68486 	},
  68487 	220: {
  68488 		Fcode:       int8(15),
  68489 		Fextra_bits: int8(6),
  68490 	},
  68491 	221: {
  68492 		Fcode:       int8(15),
  68493 		Fextra_bits: int8(6),
  68494 	},
  68495 	222: {
  68496 		Fcode:       int8(15),
  68497 		Fextra_bits: int8(6),
  68498 	},
  68499 	223: {
  68500 		Fcode:       int8(15),
  68501 		Fextra_bits: int8(6),
  68502 	},
  68503 	224: {
  68504 		Fcode:       int8(15),
  68505 		Fextra_bits: int8(6),
  68506 	},
  68507 	225: {
  68508 		Fcode:       int8(15),
  68509 		Fextra_bits: int8(6),
  68510 	},
  68511 	226: {
  68512 		Fcode:       int8(15),
  68513 		Fextra_bits: int8(6),
  68514 	},
  68515 	227: {
  68516 		Fcode:       int8(15),
  68517 		Fextra_bits: int8(6),
  68518 	},
  68519 	228: {
  68520 		Fcode:       int8(15),
  68521 		Fextra_bits: int8(6),
  68522 	},
  68523 	229: {
  68524 		Fcode:       int8(15),
  68525 		Fextra_bits: int8(6),
  68526 	},
  68527 	230: {
  68528 		Fcode:       int8(15),
  68529 		Fextra_bits: int8(6),
  68530 	},
  68531 	231: {
  68532 		Fcode:       int8(15),
  68533 		Fextra_bits: int8(6),
  68534 	},
  68535 	232: {
  68536 		Fcode:       int8(15),
  68537 		Fextra_bits: int8(6),
  68538 	},
  68539 	233: {
  68540 		Fcode:       int8(15),
  68541 		Fextra_bits: int8(6),
  68542 	},
  68543 	234: {
  68544 		Fcode:       int8(15),
  68545 		Fextra_bits: int8(6),
  68546 	},
  68547 	235: {
  68548 		Fcode:       int8(15),
  68549 		Fextra_bits: int8(6),
  68550 	},
  68551 	236: {
  68552 		Fcode:       int8(15),
  68553 		Fextra_bits: int8(6),
  68554 	},
  68555 	237: {
  68556 		Fcode:       int8(15),
  68557 		Fextra_bits: int8(6),
  68558 	},
  68559 	238: {
  68560 		Fcode:       int8(15),
  68561 		Fextra_bits: int8(6),
  68562 	},
  68563 	239: {
  68564 		Fcode:       int8(15),
  68565 		Fextra_bits: int8(6),
  68566 	},
  68567 	240: {
  68568 		Fcode:       int8(15),
  68569 		Fextra_bits: int8(6),
  68570 	},
  68571 	241: {
  68572 		Fcode:       int8(15),
  68573 		Fextra_bits: int8(6),
  68574 	},
  68575 	242: {
  68576 		Fcode:       int8(15),
  68577 		Fextra_bits: int8(6),
  68578 	},
  68579 	243: {
  68580 		Fcode:       int8(15),
  68581 		Fextra_bits: int8(6),
  68582 	},
  68583 	244: {
  68584 		Fcode:       int8(15),
  68585 		Fextra_bits: int8(6),
  68586 	},
  68587 	245: {
  68588 		Fcode:       int8(15),
  68589 		Fextra_bits: int8(6),
  68590 	},
  68591 	246: {
  68592 		Fcode:       int8(15),
  68593 		Fextra_bits: int8(6),
  68594 	},
  68595 	247: {
  68596 		Fcode:       int8(15),
  68597 		Fextra_bits: int8(6),
  68598 	},
  68599 	248: {
  68600 		Fcode:       int8(15),
  68601 		Fextra_bits: int8(6),
  68602 	},
  68603 	249: {
  68604 		Fcode:       int8(15),
  68605 		Fextra_bits: int8(6),
  68606 	},
  68607 	250: {
  68608 		Fcode:       int8(15),
  68609 		Fextra_bits: int8(6),
  68610 	},
  68611 	251: {
  68612 		Fcode:       int8(15),
  68613 		Fextra_bits: int8(6),
  68614 	},
  68615 	252: {
  68616 		Fcode:       int8(15),
  68617 		Fextra_bits: int8(6),
  68618 	},
  68619 	253: {
  68620 		Fcode:       int8(15),
  68621 		Fextra_bits: int8(6),
  68622 	},
  68623 	254: {
  68624 		Fcode:       int8(15),
  68625 		Fextra_bits: int8(6),
  68626 	},
  68627 	255: {
  68628 		Fcode:       int8(15),
  68629 		Fextra_bits: int8(6),
  68630 	},
  68631 	256: {
  68632 		Fcode:       int8(15),
  68633 		Fextra_bits: int8(6),
  68634 	},
  68635 	257: {
  68636 		Fcode:       int8(16),
  68637 		Fextra_bits: int8(7),
  68638 	},
  68639 	258: {
  68640 		Fcode:       int8(16),
  68641 		Fextra_bits: int8(7),
  68642 	},
  68643 	259: {
  68644 		Fcode:       int8(16),
  68645 		Fextra_bits: int8(7),
  68646 	},
  68647 	260: {
  68648 		Fcode:       int8(16),
  68649 		Fextra_bits: int8(7),
  68650 	},
  68651 	261: {
  68652 		Fcode:       int8(16),
  68653 		Fextra_bits: int8(7),
  68654 	},
  68655 	262: {
  68656 		Fcode:       int8(16),
  68657 		Fextra_bits: int8(7),
  68658 	},
  68659 	263: {
  68660 		Fcode:       int8(16),
  68661 		Fextra_bits: int8(7),
  68662 	},
  68663 	264: {
  68664 		Fcode:       int8(16),
  68665 		Fextra_bits: int8(7),
  68666 	},
  68667 	265: {
  68668 		Fcode:       int8(16),
  68669 		Fextra_bits: int8(7),
  68670 	},
  68671 	266: {
  68672 		Fcode:       int8(16),
  68673 		Fextra_bits: int8(7),
  68674 	},
  68675 	267: {
  68676 		Fcode:       int8(16),
  68677 		Fextra_bits: int8(7),
  68678 	},
  68679 	268: {
  68680 		Fcode:       int8(16),
  68681 		Fextra_bits: int8(7),
  68682 	},
  68683 	269: {
  68684 		Fcode:       int8(16),
  68685 		Fextra_bits: int8(7),
  68686 	},
  68687 	270: {
  68688 		Fcode:       int8(16),
  68689 		Fextra_bits: int8(7),
  68690 	},
  68691 	271: {
  68692 		Fcode:       int8(16),
  68693 		Fextra_bits: int8(7),
  68694 	},
  68695 	272: {
  68696 		Fcode:       int8(16),
  68697 		Fextra_bits: int8(7),
  68698 	},
  68699 	273: {
  68700 		Fcode:       int8(16),
  68701 		Fextra_bits: int8(7),
  68702 	},
  68703 	274: {
  68704 		Fcode:       int8(16),
  68705 		Fextra_bits: int8(7),
  68706 	},
  68707 	275: {
  68708 		Fcode:       int8(16),
  68709 		Fextra_bits: int8(7),
  68710 	},
  68711 	276: {
  68712 		Fcode:       int8(16),
  68713 		Fextra_bits: int8(7),
  68714 	},
  68715 	277: {
  68716 		Fcode:       int8(16),
  68717 		Fextra_bits: int8(7),
  68718 	},
  68719 	278: {
  68720 		Fcode:       int8(16),
  68721 		Fextra_bits: int8(7),
  68722 	},
  68723 	279: {
  68724 		Fcode:       int8(16),
  68725 		Fextra_bits: int8(7),
  68726 	},
  68727 	280: {
  68728 		Fcode:       int8(16),
  68729 		Fextra_bits: int8(7),
  68730 	},
  68731 	281: {
  68732 		Fcode:       int8(16),
  68733 		Fextra_bits: int8(7),
  68734 	},
  68735 	282: {
  68736 		Fcode:       int8(16),
  68737 		Fextra_bits: int8(7),
  68738 	},
  68739 	283: {
  68740 		Fcode:       int8(16),
  68741 		Fextra_bits: int8(7),
  68742 	},
  68743 	284: {
  68744 		Fcode:       int8(16),
  68745 		Fextra_bits: int8(7),
  68746 	},
  68747 	285: {
  68748 		Fcode:       int8(16),
  68749 		Fextra_bits: int8(7),
  68750 	},
  68751 	286: {
  68752 		Fcode:       int8(16),
  68753 		Fextra_bits: int8(7),
  68754 	},
  68755 	287: {
  68756 		Fcode:       int8(16),
  68757 		Fextra_bits: int8(7),
  68758 	},
  68759 	288: {
  68760 		Fcode:       int8(16),
  68761 		Fextra_bits: int8(7),
  68762 	},
  68763 	289: {
  68764 		Fcode:       int8(16),
  68765 		Fextra_bits: int8(7),
  68766 	},
  68767 	290: {
  68768 		Fcode:       int8(16),
  68769 		Fextra_bits: int8(7),
  68770 	},
  68771 	291: {
  68772 		Fcode:       int8(16),
  68773 		Fextra_bits: int8(7),
  68774 	},
  68775 	292: {
  68776 		Fcode:       int8(16),
  68777 		Fextra_bits: int8(7),
  68778 	},
  68779 	293: {
  68780 		Fcode:       int8(16),
  68781 		Fextra_bits: int8(7),
  68782 	},
  68783 	294: {
  68784 		Fcode:       int8(16),
  68785 		Fextra_bits: int8(7),
  68786 	},
  68787 	295: {
  68788 		Fcode:       int8(16),
  68789 		Fextra_bits: int8(7),
  68790 	},
  68791 	296: {
  68792 		Fcode:       int8(16),
  68793 		Fextra_bits: int8(7),
  68794 	},
  68795 	297: {
  68796 		Fcode:       int8(16),
  68797 		Fextra_bits: int8(7),
  68798 	},
  68799 	298: {
  68800 		Fcode:       int8(16),
  68801 		Fextra_bits: int8(7),
  68802 	},
  68803 	299: {
  68804 		Fcode:       int8(16),
  68805 		Fextra_bits: int8(7),
  68806 	},
  68807 	300: {
  68808 		Fcode:       int8(16),
  68809 		Fextra_bits: int8(7),
  68810 	},
  68811 	301: {
  68812 		Fcode:       int8(16),
  68813 		Fextra_bits: int8(7),
  68814 	},
  68815 	302: {
  68816 		Fcode:       int8(16),
  68817 		Fextra_bits: int8(7),
  68818 	},
  68819 	303: {
  68820 		Fcode:       int8(16),
  68821 		Fextra_bits: int8(7),
  68822 	},
  68823 	304: {
  68824 		Fcode:       int8(16),
  68825 		Fextra_bits: int8(7),
  68826 	},
  68827 	305: {
  68828 		Fcode:       int8(16),
  68829 		Fextra_bits: int8(7),
  68830 	},
  68831 	306: {
  68832 		Fcode:       int8(16),
  68833 		Fextra_bits: int8(7),
  68834 	},
  68835 	307: {
  68836 		Fcode:       int8(16),
  68837 		Fextra_bits: int8(7),
  68838 	},
  68839 	308: {
  68840 		Fcode:       int8(16),
  68841 		Fextra_bits: int8(7),
  68842 	},
  68843 	309: {
  68844 		Fcode:       int8(16),
  68845 		Fextra_bits: int8(7),
  68846 	},
  68847 	310: {
  68848 		Fcode:       int8(16),
  68849 		Fextra_bits: int8(7),
  68850 	},
  68851 	311: {
  68852 		Fcode:       int8(16),
  68853 		Fextra_bits: int8(7),
  68854 	},
  68855 	312: {
  68856 		Fcode:       int8(16),
  68857 		Fextra_bits: int8(7),
  68858 	},
  68859 	313: {
  68860 		Fcode:       int8(16),
  68861 		Fextra_bits: int8(7),
  68862 	},
  68863 	314: {
  68864 		Fcode:       int8(16),
  68865 		Fextra_bits: int8(7),
  68866 	},
  68867 	315: {
  68868 		Fcode:       int8(16),
  68869 		Fextra_bits: int8(7),
  68870 	},
  68871 	316: {
  68872 		Fcode:       int8(16),
  68873 		Fextra_bits: int8(7),
  68874 	},
  68875 	317: {
  68876 		Fcode:       int8(16),
  68877 		Fextra_bits: int8(7),
  68878 	},
  68879 	318: {
  68880 		Fcode:       int8(16),
  68881 		Fextra_bits: int8(7),
  68882 	},
  68883 	319: {
  68884 		Fcode:       int8(16),
  68885 		Fextra_bits: int8(7),
  68886 	},
  68887 	320: {
  68888 		Fcode:       int8(16),
  68889 		Fextra_bits: int8(7),
  68890 	},
  68891 	321: {
  68892 		Fcode:       int8(16),
  68893 		Fextra_bits: int8(7),
  68894 	},
  68895 	322: {
  68896 		Fcode:       int8(16),
  68897 		Fextra_bits: int8(7),
  68898 	},
  68899 	323: {
  68900 		Fcode:       int8(16),
  68901 		Fextra_bits: int8(7),
  68902 	},
  68903 	324: {
  68904 		Fcode:       int8(16),
  68905 		Fextra_bits: int8(7),
  68906 	},
  68907 	325: {
  68908 		Fcode:       int8(16),
  68909 		Fextra_bits: int8(7),
  68910 	},
  68911 	326: {
  68912 		Fcode:       int8(16),
  68913 		Fextra_bits: int8(7),
  68914 	},
  68915 	327: {
  68916 		Fcode:       int8(16),
  68917 		Fextra_bits: int8(7),
  68918 	},
  68919 	328: {
  68920 		Fcode:       int8(16),
  68921 		Fextra_bits: int8(7),
  68922 	},
  68923 	329: {
  68924 		Fcode:       int8(16),
  68925 		Fextra_bits: int8(7),
  68926 	},
  68927 	330: {
  68928 		Fcode:       int8(16),
  68929 		Fextra_bits: int8(7),
  68930 	},
  68931 	331: {
  68932 		Fcode:       int8(16),
  68933 		Fextra_bits: int8(7),
  68934 	},
  68935 	332: {
  68936 		Fcode:       int8(16),
  68937 		Fextra_bits: int8(7),
  68938 	},
  68939 	333: {
  68940 		Fcode:       int8(16),
  68941 		Fextra_bits: int8(7),
  68942 	},
  68943 	334: {
  68944 		Fcode:       int8(16),
  68945 		Fextra_bits: int8(7),
  68946 	},
  68947 	335: {
  68948 		Fcode:       int8(16),
  68949 		Fextra_bits: int8(7),
  68950 	},
  68951 	336: {
  68952 		Fcode:       int8(16),
  68953 		Fextra_bits: int8(7),
  68954 	},
  68955 	337: {
  68956 		Fcode:       int8(16),
  68957 		Fextra_bits: int8(7),
  68958 	},
  68959 	338: {
  68960 		Fcode:       int8(16),
  68961 		Fextra_bits: int8(7),
  68962 	},
  68963 	339: {
  68964 		Fcode:       int8(16),
  68965 		Fextra_bits: int8(7),
  68966 	},
  68967 	340: {
  68968 		Fcode:       int8(16),
  68969 		Fextra_bits: int8(7),
  68970 	},
  68971 	341: {
  68972 		Fcode:       int8(16),
  68973 		Fextra_bits: int8(7),
  68974 	},
  68975 	342: {
  68976 		Fcode:       int8(16),
  68977 		Fextra_bits: int8(7),
  68978 	},
  68979 	343: {
  68980 		Fcode:       int8(16),
  68981 		Fextra_bits: int8(7),
  68982 	},
  68983 	344: {
  68984 		Fcode:       int8(16),
  68985 		Fextra_bits: int8(7),
  68986 	},
  68987 	345: {
  68988 		Fcode:       int8(16),
  68989 		Fextra_bits: int8(7),
  68990 	},
  68991 	346: {
  68992 		Fcode:       int8(16),
  68993 		Fextra_bits: int8(7),
  68994 	},
  68995 	347: {
  68996 		Fcode:       int8(16),
  68997 		Fextra_bits: int8(7),
  68998 	},
  68999 	348: {
  69000 		Fcode:       int8(16),
  69001 		Fextra_bits: int8(7),
  69002 	},
  69003 	349: {
  69004 		Fcode:       int8(16),
  69005 		Fextra_bits: int8(7),
  69006 	},
  69007 	350: {
  69008 		Fcode:       int8(16),
  69009 		Fextra_bits: int8(7),
  69010 	},
  69011 	351: {
  69012 		Fcode:       int8(16),
  69013 		Fextra_bits: int8(7),
  69014 	},
  69015 	352: {
  69016 		Fcode:       int8(16),
  69017 		Fextra_bits: int8(7),
  69018 	},
  69019 	353: {
  69020 		Fcode:       int8(16),
  69021 		Fextra_bits: int8(7),
  69022 	},
  69023 	354: {
  69024 		Fcode:       int8(16),
  69025 		Fextra_bits: int8(7),
  69026 	},
  69027 	355: {
  69028 		Fcode:       int8(16),
  69029 		Fextra_bits: int8(7),
  69030 	},
  69031 	356: {
  69032 		Fcode:       int8(16),
  69033 		Fextra_bits: int8(7),
  69034 	},
  69035 	357: {
  69036 		Fcode:       int8(16),
  69037 		Fextra_bits: int8(7),
  69038 	},
  69039 	358: {
  69040 		Fcode:       int8(16),
  69041 		Fextra_bits: int8(7),
  69042 	},
  69043 	359: {
  69044 		Fcode:       int8(16),
  69045 		Fextra_bits: int8(7),
  69046 	},
  69047 	360: {
  69048 		Fcode:       int8(16),
  69049 		Fextra_bits: int8(7),
  69050 	},
  69051 	361: {
  69052 		Fcode:       int8(16),
  69053 		Fextra_bits: int8(7),
  69054 	},
  69055 	362: {
  69056 		Fcode:       int8(16),
  69057 		Fextra_bits: int8(7),
  69058 	},
  69059 	363: {
  69060 		Fcode:       int8(16),
  69061 		Fextra_bits: int8(7),
  69062 	},
  69063 	364: {
  69064 		Fcode:       int8(16),
  69065 		Fextra_bits: int8(7),
  69066 	},
  69067 	365: {
  69068 		Fcode:       int8(16),
  69069 		Fextra_bits: int8(7),
  69070 	},
  69071 	366: {
  69072 		Fcode:       int8(16),
  69073 		Fextra_bits: int8(7),
  69074 	},
  69075 	367: {
  69076 		Fcode:       int8(16),
  69077 		Fextra_bits: int8(7),
  69078 	},
  69079 	368: {
  69080 		Fcode:       int8(16),
  69081 		Fextra_bits: int8(7),
  69082 	},
  69083 	369: {
  69084 		Fcode:       int8(16),
  69085 		Fextra_bits: int8(7),
  69086 	},
  69087 	370: {
  69088 		Fcode:       int8(16),
  69089 		Fextra_bits: int8(7),
  69090 	},
  69091 	371: {
  69092 		Fcode:       int8(16),
  69093 		Fextra_bits: int8(7),
  69094 	},
  69095 	372: {
  69096 		Fcode:       int8(16),
  69097 		Fextra_bits: int8(7),
  69098 	},
  69099 	373: {
  69100 		Fcode:       int8(16),
  69101 		Fextra_bits: int8(7),
  69102 	},
  69103 	374: {
  69104 		Fcode:       int8(16),
  69105 		Fextra_bits: int8(7),
  69106 	},
  69107 	375: {
  69108 		Fcode:       int8(16),
  69109 		Fextra_bits: int8(7),
  69110 	},
  69111 	376: {
  69112 		Fcode:       int8(16),
  69113 		Fextra_bits: int8(7),
  69114 	},
  69115 	377: {
  69116 		Fcode:       int8(16),
  69117 		Fextra_bits: int8(7),
  69118 	},
  69119 	378: {
  69120 		Fcode:       int8(16),
  69121 		Fextra_bits: int8(7),
  69122 	},
  69123 	379: {
  69124 		Fcode:       int8(16),
  69125 		Fextra_bits: int8(7),
  69126 	},
  69127 	380: {
  69128 		Fcode:       int8(16),
  69129 		Fextra_bits: int8(7),
  69130 	},
  69131 	381: {
  69132 		Fcode:       int8(16),
  69133 		Fextra_bits: int8(7),
  69134 	},
  69135 	382: {
  69136 		Fcode:       int8(16),
  69137 		Fextra_bits: int8(7),
  69138 	},
  69139 	383: {
  69140 		Fcode:       int8(16),
  69141 		Fextra_bits: int8(7),
  69142 	},
  69143 	384: {
  69144 		Fcode:       int8(16),
  69145 		Fextra_bits: int8(7),
  69146 	},
  69147 	385: {
  69148 		Fcode:       int8(17),
  69149 		Fextra_bits: int8(7),
  69150 	},
  69151 	386: {
  69152 		Fcode:       int8(17),
  69153 		Fextra_bits: int8(7),
  69154 	},
  69155 	387: {
  69156 		Fcode:       int8(17),
  69157 		Fextra_bits: int8(7),
  69158 	},
  69159 	388: {
  69160 		Fcode:       int8(17),
  69161 		Fextra_bits: int8(7),
  69162 	},
  69163 	389: {
  69164 		Fcode:       int8(17),
  69165 		Fextra_bits: int8(7),
  69166 	},
  69167 	390: {
  69168 		Fcode:       int8(17),
  69169 		Fextra_bits: int8(7),
  69170 	},
  69171 	391: {
  69172 		Fcode:       int8(17),
  69173 		Fextra_bits: int8(7),
  69174 	},
  69175 	392: {
  69176 		Fcode:       int8(17),
  69177 		Fextra_bits: int8(7),
  69178 	},
  69179 	393: {
  69180 		Fcode:       int8(17),
  69181 		Fextra_bits: int8(7),
  69182 	},
  69183 	394: {
  69184 		Fcode:       int8(17),
  69185 		Fextra_bits: int8(7),
  69186 	},
  69187 	395: {
  69188 		Fcode:       int8(17),
  69189 		Fextra_bits: int8(7),
  69190 	},
  69191 	396: {
  69192 		Fcode:       int8(17),
  69193 		Fextra_bits: int8(7),
  69194 	},
  69195 	397: {
  69196 		Fcode:       int8(17),
  69197 		Fextra_bits: int8(7),
  69198 	},
  69199 	398: {
  69200 		Fcode:       int8(17),
  69201 		Fextra_bits: int8(7),
  69202 	},
  69203 	399: {
  69204 		Fcode:       int8(17),
  69205 		Fextra_bits: int8(7),
  69206 	},
  69207 	400: {
  69208 		Fcode:       int8(17),
  69209 		Fextra_bits: int8(7),
  69210 	},
  69211 	401: {
  69212 		Fcode:       int8(17),
  69213 		Fextra_bits: int8(7),
  69214 	},
  69215 	402: {
  69216 		Fcode:       int8(17),
  69217 		Fextra_bits: int8(7),
  69218 	},
  69219 	403: {
  69220 		Fcode:       int8(17),
  69221 		Fextra_bits: int8(7),
  69222 	},
  69223 	404: {
  69224 		Fcode:       int8(17),
  69225 		Fextra_bits: int8(7),
  69226 	},
  69227 	405: {
  69228 		Fcode:       int8(17),
  69229 		Fextra_bits: int8(7),
  69230 	},
  69231 	406: {
  69232 		Fcode:       int8(17),
  69233 		Fextra_bits: int8(7),
  69234 	},
  69235 	407: {
  69236 		Fcode:       int8(17),
  69237 		Fextra_bits: int8(7),
  69238 	},
  69239 	408: {
  69240 		Fcode:       int8(17),
  69241 		Fextra_bits: int8(7),
  69242 	},
  69243 	409: {
  69244 		Fcode:       int8(17),
  69245 		Fextra_bits: int8(7),
  69246 	},
  69247 	410: {
  69248 		Fcode:       int8(17),
  69249 		Fextra_bits: int8(7),
  69250 	},
  69251 	411: {
  69252 		Fcode:       int8(17),
  69253 		Fextra_bits: int8(7),
  69254 	},
  69255 	412: {
  69256 		Fcode:       int8(17),
  69257 		Fextra_bits: int8(7),
  69258 	},
  69259 	413: {
  69260 		Fcode:       int8(17),
  69261 		Fextra_bits: int8(7),
  69262 	},
  69263 	414: {
  69264 		Fcode:       int8(17),
  69265 		Fextra_bits: int8(7),
  69266 	},
  69267 	415: {
  69268 		Fcode:       int8(17),
  69269 		Fextra_bits: int8(7),
  69270 	},
  69271 	416: {
  69272 		Fcode:       int8(17),
  69273 		Fextra_bits: int8(7),
  69274 	},
  69275 	417: {
  69276 		Fcode:       int8(17),
  69277 		Fextra_bits: int8(7),
  69278 	},
  69279 	418: {
  69280 		Fcode:       int8(17),
  69281 		Fextra_bits: int8(7),
  69282 	},
  69283 	419: {
  69284 		Fcode:       int8(17),
  69285 		Fextra_bits: int8(7),
  69286 	},
  69287 	420: {
  69288 		Fcode:       int8(17),
  69289 		Fextra_bits: int8(7),
  69290 	},
  69291 	421: {
  69292 		Fcode:       int8(17),
  69293 		Fextra_bits: int8(7),
  69294 	},
  69295 	422: {
  69296 		Fcode:       int8(17),
  69297 		Fextra_bits: int8(7),
  69298 	},
  69299 	423: {
  69300 		Fcode:       int8(17),
  69301 		Fextra_bits: int8(7),
  69302 	},
  69303 	424: {
  69304 		Fcode:       int8(17),
  69305 		Fextra_bits: int8(7),
  69306 	},
  69307 	425: {
  69308 		Fcode:       int8(17),
  69309 		Fextra_bits: int8(7),
  69310 	},
  69311 	426: {
  69312 		Fcode:       int8(17),
  69313 		Fextra_bits: int8(7),
  69314 	},
  69315 	427: {
  69316 		Fcode:       int8(17),
  69317 		Fextra_bits: int8(7),
  69318 	},
  69319 	428: {
  69320 		Fcode:       int8(17),
  69321 		Fextra_bits: int8(7),
  69322 	},
  69323 	429: {
  69324 		Fcode:       int8(17),
  69325 		Fextra_bits: int8(7),
  69326 	},
  69327 	430: {
  69328 		Fcode:       int8(17),
  69329 		Fextra_bits: int8(7),
  69330 	},
  69331 	431: {
  69332 		Fcode:       int8(17),
  69333 		Fextra_bits: int8(7),
  69334 	},
  69335 	432: {
  69336 		Fcode:       int8(17),
  69337 		Fextra_bits: int8(7),
  69338 	},
  69339 	433: {
  69340 		Fcode:       int8(17),
  69341 		Fextra_bits: int8(7),
  69342 	},
  69343 	434: {
  69344 		Fcode:       int8(17),
  69345 		Fextra_bits: int8(7),
  69346 	},
  69347 	435: {
  69348 		Fcode:       int8(17),
  69349 		Fextra_bits: int8(7),
  69350 	},
  69351 	436: {
  69352 		Fcode:       int8(17),
  69353 		Fextra_bits: int8(7),
  69354 	},
  69355 	437: {
  69356 		Fcode:       int8(17),
  69357 		Fextra_bits: int8(7),
  69358 	},
  69359 	438: {
  69360 		Fcode:       int8(17),
  69361 		Fextra_bits: int8(7),
  69362 	},
  69363 	439: {
  69364 		Fcode:       int8(17),
  69365 		Fextra_bits: int8(7),
  69366 	},
  69367 	440: {
  69368 		Fcode:       int8(17),
  69369 		Fextra_bits: int8(7),
  69370 	},
  69371 	441: {
  69372 		Fcode:       int8(17),
  69373 		Fextra_bits: int8(7),
  69374 	},
  69375 	442: {
  69376 		Fcode:       int8(17),
  69377 		Fextra_bits: int8(7),
  69378 	},
  69379 	443: {
  69380 		Fcode:       int8(17),
  69381 		Fextra_bits: int8(7),
  69382 	},
  69383 	444: {
  69384 		Fcode:       int8(17),
  69385 		Fextra_bits: int8(7),
  69386 	},
  69387 	445: {
  69388 		Fcode:       int8(17),
  69389 		Fextra_bits: int8(7),
  69390 	},
  69391 	446: {
  69392 		Fcode:       int8(17),
  69393 		Fextra_bits: int8(7),
  69394 	},
  69395 	447: {
  69396 		Fcode:       int8(17),
  69397 		Fextra_bits: int8(7),
  69398 	},
  69399 	448: {
  69400 		Fcode:       int8(17),
  69401 		Fextra_bits: int8(7),
  69402 	},
  69403 	449: {
  69404 		Fcode:       int8(17),
  69405 		Fextra_bits: int8(7),
  69406 	},
  69407 	450: {
  69408 		Fcode:       int8(17),
  69409 		Fextra_bits: int8(7),
  69410 	},
  69411 	451: {
  69412 		Fcode:       int8(17),
  69413 		Fextra_bits: int8(7),
  69414 	},
  69415 	452: {
  69416 		Fcode:       int8(17),
  69417 		Fextra_bits: int8(7),
  69418 	},
  69419 	453: {
  69420 		Fcode:       int8(17),
  69421 		Fextra_bits: int8(7),
  69422 	},
  69423 	454: {
  69424 		Fcode:       int8(17),
  69425 		Fextra_bits: int8(7),
  69426 	},
  69427 	455: {
  69428 		Fcode:       int8(17),
  69429 		Fextra_bits: int8(7),
  69430 	},
  69431 	456: {
  69432 		Fcode:       int8(17),
  69433 		Fextra_bits: int8(7),
  69434 	},
  69435 	457: {
  69436 		Fcode:       int8(17),
  69437 		Fextra_bits: int8(7),
  69438 	},
  69439 	458: {
  69440 		Fcode:       int8(17),
  69441 		Fextra_bits: int8(7),
  69442 	},
  69443 	459: {
  69444 		Fcode:       int8(17),
  69445 		Fextra_bits: int8(7),
  69446 	},
  69447 	460: {
  69448 		Fcode:       int8(17),
  69449 		Fextra_bits: int8(7),
  69450 	},
  69451 	461: {
  69452 		Fcode:       int8(17),
  69453 		Fextra_bits: int8(7),
  69454 	},
  69455 	462: {
  69456 		Fcode:       int8(17),
  69457 		Fextra_bits: int8(7),
  69458 	},
  69459 	463: {
  69460 		Fcode:       int8(17),
  69461 		Fextra_bits: int8(7),
  69462 	},
  69463 	464: {
  69464 		Fcode:       int8(17),
  69465 		Fextra_bits: int8(7),
  69466 	},
  69467 	465: {
  69468 		Fcode:       int8(17),
  69469 		Fextra_bits: int8(7),
  69470 	},
  69471 	466: {
  69472 		Fcode:       int8(17),
  69473 		Fextra_bits: int8(7),
  69474 	},
  69475 	467: {
  69476 		Fcode:       int8(17),
  69477 		Fextra_bits: int8(7),
  69478 	},
  69479 	468: {
  69480 		Fcode:       int8(17),
  69481 		Fextra_bits: int8(7),
  69482 	},
  69483 	469: {
  69484 		Fcode:       int8(17),
  69485 		Fextra_bits: int8(7),
  69486 	},
  69487 	470: {
  69488 		Fcode:       int8(17),
  69489 		Fextra_bits: int8(7),
  69490 	},
  69491 	471: {
  69492 		Fcode:       int8(17),
  69493 		Fextra_bits: int8(7),
  69494 	},
  69495 	472: {
  69496 		Fcode:       int8(17),
  69497 		Fextra_bits: int8(7),
  69498 	},
  69499 	473: {
  69500 		Fcode:       int8(17),
  69501 		Fextra_bits: int8(7),
  69502 	},
  69503 	474: {
  69504 		Fcode:       int8(17),
  69505 		Fextra_bits: int8(7),
  69506 	},
  69507 	475: {
  69508 		Fcode:       int8(17),
  69509 		Fextra_bits: int8(7),
  69510 	},
  69511 	476: {
  69512 		Fcode:       int8(17),
  69513 		Fextra_bits: int8(7),
  69514 	},
  69515 	477: {
  69516 		Fcode:       int8(17),
  69517 		Fextra_bits: int8(7),
  69518 	},
  69519 	478: {
  69520 		Fcode:       int8(17),
  69521 		Fextra_bits: int8(7),
  69522 	},
  69523 	479: {
  69524 		Fcode:       int8(17),
  69525 		Fextra_bits: int8(7),
  69526 	},
  69527 	480: {
  69528 		Fcode:       int8(17),
  69529 		Fextra_bits: int8(7),
  69530 	},
  69531 	481: {
  69532 		Fcode:       int8(17),
  69533 		Fextra_bits: int8(7),
  69534 	},
  69535 	482: {
  69536 		Fcode:       int8(17),
  69537 		Fextra_bits: int8(7),
  69538 	},
  69539 	483: {
  69540 		Fcode:       int8(17),
  69541 		Fextra_bits: int8(7),
  69542 	},
  69543 	484: {
  69544 		Fcode:       int8(17),
  69545 		Fextra_bits: int8(7),
  69546 	},
  69547 	485: {
  69548 		Fcode:       int8(17),
  69549 		Fextra_bits: int8(7),
  69550 	},
  69551 	486: {
  69552 		Fcode:       int8(17),
  69553 		Fextra_bits: int8(7),
  69554 	},
  69555 	487: {
  69556 		Fcode:       int8(17),
  69557 		Fextra_bits: int8(7),
  69558 	},
  69559 	488: {
  69560 		Fcode:       int8(17),
  69561 		Fextra_bits: int8(7),
  69562 	},
  69563 	489: {
  69564 		Fcode:       int8(17),
  69565 		Fextra_bits: int8(7),
  69566 	},
  69567 	490: {
  69568 		Fcode:       int8(17),
  69569 		Fextra_bits: int8(7),
  69570 	},
  69571 	491: {
  69572 		Fcode:       int8(17),
  69573 		Fextra_bits: int8(7),
  69574 	},
  69575 	492: {
  69576 		Fcode:       int8(17),
  69577 		Fextra_bits: int8(7),
  69578 	},
  69579 	493: {
  69580 		Fcode:       int8(17),
  69581 		Fextra_bits: int8(7),
  69582 	},
  69583 	494: {
  69584 		Fcode:       int8(17),
  69585 		Fextra_bits: int8(7),
  69586 	},
  69587 	495: {
  69588 		Fcode:       int8(17),
  69589 		Fextra_bits: int8(7),
  69590 	},
  69591 	496: {
  69592 		Fcode:       int8(17),
  69593 		Fextra_bits: int8(7),
  69594 	},
  69595 	497: {
  69596 		Fcode:       int8(17),
  69597 		Fextra_bits: int8(7),
  69598 	},
  69599 	498: {
  69600 		Fcode:       int8(17),
  69601 		Fextra_bits: int8(7),
  69602 	},
  69603 	499: {
  69604 		Fcode:       int8(17),
  69605 		Fextra_bits: int8(7),
  69606 	},
  69607 	500: {
  69608 		Fcode:       int8(17),
  69609 		Fextra_bits: int8(7),
  69610 	},
  69611 	501: {
  69612 		Fcode:       int8(17),
  69613 		Fextra_bits: int8(7),
  69614 	},
  69615 	502: {
  69616 		Fcode:       int8(17),
  69617 		Fextra_bits: int8(7),
  69618 	},
  69619 	503: {
  69620 		Fcode:       int8(17),
  69621 		Fextra_bits: int8(7),
  69622 	},
  69623 	504: {
  69624 		Fcode:       int8(17),
  69625 		Fextra_bits: int8(7),
  69626 	},
  69627 	505: {
  69628 		Fcode:       int8(17),
  69629 		Fextra_bits: int8(7),
  69630 	},
  69631 	506: {
  69632 		Fcode:       int8(17),
  69633 		Fextra_bits: int8(7),
  69634 	},
  69635 	507: {
  69636 		Fcode:       int8(17),
  69637 		Fextra_bits: int8(7),
  69638 	},
  69639 	508: {
  69640 		Fcode:       int8(17),
  69641 		Fextra_bits: int8(7),
  69642 	},
  69643 	509: {
  69644 		Fcode:       int8(17),
  69645 		Fextra_bits: int8(7),
  69646 	},
  69647 	510: {
  69648 		Fcode:       int8(17),
  69649 		Fextra_bits: int8(7),
  69650 	},
  69651 	511: {
  69652 		Fcode:       int8(17),
  69653 		Fextra_bits: int8(7),
  69654 	},
  69655 }
  69656 
  69657 var kPrefixEncodeExtraBitsValue = [512]uint8_t{
  69658 	6:   uint8(1),
  69659 	8:   uint8(1),
  69660 	10:  uint8(1),
  69661 	11:  uint8(2),
  69662 	12:  uint8(3),
  69663 	14:  uint8(1),
  69664 	15:  uint8(2),
  69665 	16:  uint8(3),
  69666 	18:  uint8(1),
  69667 	19:  uint8(2),
  69668 	20:  uint8(3),
  69669 	21:  uint8(4),
  69670 	22:  uint8(5),
  69671 	23:  uint8(6),
  69672 	24:  uint8(7),
  69673 	26:  uint8(1),
  69674 	27:  uint8(2),
  69675 	28:  uint8(3),
  69676 	29:  uint8(4),
  69677 	30:  uint8(5),
  69678 	31:  uint8(6),
  69679 	32:  uint8(7),
  69680 	34:  uint8(1),
  69681 	35:  uint8(2),
  69682 	36:  uint8(3),
  69683 	37:  uint8(4),
  69684 	38:  uint8(5),
  69685 	39:  uint8(6),
  69686 	40:  uint8(7),
  69687 	41:  uint8(8),
  69688 	42:  uint8(9),
  69689 	43:  uint8(10),
  69690 	44:  uint8(11),
  69691 	45:  uint8(12),
  69692 	46:  uint8(13),
  69693 	47:  uint8(14),
  69694 	48:  uint8(15),
  69695 	50:  uint8(1),
  69696 	51:  uint8(2),
  69697 	52:  uint8(3),
  69698 	53:  uint8(4),
  69699 	54:  uint8(5),
  69700 	55:  uint8(6),
  69701 	56:  uint8(7),
  69702 	57:  uint8(8),
  69703 	58:  uint8(9),
  69704 	59:  uint8(10),
  69705 	60:  uint8(11),
  69706 	61:  uint8(12),
  69707 	62:  uint8(13),
  69708 	63:  uint8(14),
  69709 	64:  uint8(15),
  69710 	66:  uint8(1),
  69711 	67:  uint8(2),
  69712 	68:  uint8(3),
  69713 	69:  uint8(4),
  69714 	70:  uint8(5),
  69715 	71:  uint8(6),
  69716 	72:  uint8(7),
  69717 	73:  uint8(8),
  69718 	74:  uint8(9),
  69719 	75:  uint8(10),
  69720 	76:  uint8(11),
  69721 	77:  uint8(12),
  69722 	78:  uint8(13),
  69723 	79:  uint8(14),
  69724 	80:  uint8(15),
  69725 	81:  uint8(16),
  69726 	82:  uint8(17),
  69727 	83:  uint8(18),
  69728 	84:  uint8(19),
  69729 	85:  uint8(20),
  69730 	86:  uint8(21),
  69731 	87:  uint8(22),
  69732 	88:  uint8(23),
  69733 	89:  uint8(24),
  69734 	90:  uint8(25),
  69735 	91:  uint8(26),
  69736 	92:  uint8(27),
  69737 	93:  uint8(28),
  69738 	94:  uint8(29),
  69739 	95:  uint8(30),
  69740 	96:  uint8(31),
  69741 	98:  uint8(1),
  69742 	99:  uint8(2),
  69743 	100: uint8(3),
  69744 	101: uint8(4),
  69745 	102: uint8(5),
  69746 	103: uint8(6),
  69747 	104: uint8(7),
  69748 	105: uint8(8),
  69749 	106: uint8(9),
  69750 	107: uint8(10),
  69751 	108: uint8(11),
  69752 	109: uint8(12),
  69753 	110: uint8(13),
  69754 	111: uint8(14),
  69755 	112: uint8(15),
  69756 	113: uint8(16),
  69757 	114: uint8(17),
  69758 	115: uint8(18),
  69759 	116: uint8(19),
  69760 	117: uint8(20),
  69761 	118: uint8(21),
  69762 	119: uint8(22),
  69763 	120: uint8(23),
  69764 	121: uint8(24),
  69765 	122: uint8(25),
  69766 	123: uint8(26),
  69767 	124: uint8(27),
  69768 	125: uint8(28),
  69769 	126: uint8(29),
  69770 	127: uint8(30),
  69771 	128: uint8(31),
  69772 	130: uint8(1),
  69773 	131: uint8(2),
  69774 	132: uint8(3),
  69775 	133: uint8(4),
  69776 	134: uint8(5),
  69777 	135: uint8(6),
  69778 	136: uint8(7),
  69779 	137: uint8(8),
  69780 	138: uint8(9),
  69781 	139: uint8(10),
  69782 	140: uint8(11),
  69783 	141: uint8(12),
  69784 	142: uint8(13),
  69785 	143: uint8(14),
  69786 	144: uint8(15),
  69787 	145: uint8(16),
  69788 	146: uint8(17),
  69789 	147: uint8(18),
  69790 	148: uint8(19),
  69791 	149: uint8(20),
  69792 	150: uint8(21),
  69793 	151: uint8(22),
  69794 	152: uint8(23),
  69795 	153: uint8(24),
  69796 	154: uint8(25),
  69797 	155: uint8(26),
  69798 	156: uint8(27),
  69799 	157: uint8(28),
  69800 	158: uint8(29),
  69801 	159: uint8(30),
  69802 	160: uint8(31),
  69803 	161: uint8(32),
  69804 	162: uint8(33),
  69805 	163: uint8(34),
  69806 	164: uint8(35),
  69807 	165: uint8(36),
  69808 	166: uint8(37),
  69809 	167: uint8(38),
  69810 	168: uint8(39),
  69811 	169: uint8(40),
  69812 	170: uint8(41),
  69813 	171: uint8(42),
  69814 	172: uint8(43),
  69815 	173: uint8(44),
  69816 	174: uint8(45),
  69817 	175: uint8(46),
  69818 	176: uint8(47),
  69819 	177: uint8(48),
  69820 	178: uint8(49),
  69821 	179: uint8(50),
  69822 	180: uint8(51),
  69823 	181: uint8(52),
  69824 	182: uint8(53),
  69825 	183: uint8(54),
  69826 	184: uint8(55),
  69827 	185: uint8(56),
  69828 	186: uint8(57),
  69829 	187: uint8(58),
  69830 	188: uint8(59),
  69831 	189: uint8(60),
  69832 	190: uint8(61),
  69833 	191: uint8(62),
  69834 	192: uint8(63),
  69835 	194: uint8(1),
  69836 	195: uint8(2),
  69837 	196: uint8(3),
  69838 	197: uint8(4),
  69839 	198: uint8(5),
  69840 	199: uint8(6),
  69841 	200: uint8(7),
  69842 	201: uint8(8),
  69843 	202: uint8(9),
  69844 	203: uint8(10),
  69845 	204: uint8(11),
  69846 	205: uint8(12),
  69847 	206: uint8(13),
  69848 	207: uint8(14),
  69849 	208: uint8(15),
  69850 	209: uint8(16),
  69851 	210: uint8(17),
  69852 	211: uint8(18),
  69853 	212: uint8(19),
  69854 	213: uint8(20),
  69855 	214: uint8(21),
  69856 	215: uint8(22),
  69857 	216: uint8(23),
  69858 	217: uint8(24),
  69859 	218: uint8(25),
  69860 	219: uint8(26),
  69861 	220: uint8(27),
  69862 	221: uint8(28),
  69863 	222: uint8(29),
  69864 	223: uint8(30),
  69865 	224: uint8(31),
  69866 	225: uint8(32),
  69867 	226: uint8(33),
  69868 	227: uint8(34),
  69869 	228: uint8(35),
  69870 	229: uint8(36),
  69871 	230: uint8(37),
  69872 	231: uint8(38),
  69873 	232: uint8(39),
  69874 	233: uint8(40),
  69875 	234: uint8(41),
  69876 	235: uint8(42),
  69877 	236: uint8(43),
  69878 	237: uint8(44),
  69879 	238: uint8(45),
  69880 	239: uint8(46),
  69881 	240: uint8(47),
  69882 	241: uint8(48),
  69883 	242: uint8(49),
  69884 	243: uint8(50),
  69885 	244: uint8(51),
  69886 	245: uint8(52),
  69887 	246: uint8(53),
  69888 	247: uint8(54),
  69889 	248: uint8(55),
  69890 	249: uint8(56),
  69891 	250: uint8(57),
  69892 	251: uint8(58),
  69893 	252: uint8(59),
  69894 	253: uint8(60),
  69895 	254: uint8(61),
  69896 	255: uint8(62),
  69897 	256: uint8(63),
  69898 	258: uint8(1),
  69899 	259: uint8(2),
  69900 	260: uint8(3),
  69901 	261: uint8(4),
  69902 	262: uint8(5),
  69903 	263: uint8(6),
  69904 	264: uint8(7),
  69905 	265: uint8(8),
  69906 	266: uint8(9),
  69907 	267: uint8(10),
  69908 	268: uint8(11),
  69909 	269: uint8(12),
  69910 	270: uint8(13),
  69911 	271: uint8(14),
  69912 	272: uint8(15),
  69913 	273: uint8(16),
  69914 	274: uint8(17),
  69915 	275: uint8(18),
  69916 	276: uint8(19),
  69917 	277: uint8(20),
  69918 	278: uint8(21),
  69919 	279: uint8(22),
  69920 	280: uint8(23),
  69921 	281: uint8(24),
  69922 	282: uint8(25),
  69923 	283: uint8(26),
  69924 	284: uint8(27),
  69925 	285: uint8(28),
  69926 	286: uint8(29),
  69927 	287: uint8(30),
  69928 	288: uint8(31),
  69929 	289: uint8(32),
  69930 	290: uint8(33),
  69931 	291: uint8(34),
  69932 	292: uint8(35),
  69933 	293: uint8(36),
  69934 	294: uint8(37),
  69935 	295: uint8(38),
  69936 	296: uint8(39),
  69937 	297: uint8(40),
  69938 	298: uint8(41),
  69939 	299: uint8(42),
  69940 	300: uint8(43),
  69941 	301: uint8(44),
  69942 	302: uint8(45),
  69943 	303: uint8(46),
  69944 	304: uint8(47),
  69945 	305: uint8(48),
  69946 	306: uint8(49),
  69947 	307: uint8(50),
  69948 	308: uint8(51),
  69949 	309: uint8(52),
  69950 	310: uint8(53),
  69951 	311: uint8(54),
  69952 	312: uint8(55),
  69953 	313: uint8(56),
  69954 	314: uint8(57),
  69955 	315: uint8(58),
  69956 	316: uint8(59),
  69957 	317: uint8(60),
  69958 	318: uint8(61),
  69959 	319: uint8(62),
  69960 	320: uint8(63),
  69961 	321: uint8(64),
  69962 	322: uint8(65),
  69963 	323: uint8(66),
  69964 	324: uint8(67),
  69965 	325: uint8(68),
  69966 	326: uint8(69),
  69967 	327: uint8(70),
  69968 	328: uint8(71),
  69969 	329: uint8(72),
  69970 	330: uint8(73),
  69971 	331: uint8(74),
  69972 	332: uint8(75),
  69973 	333: uint8(76),
  69974 	334: uint8(77),
  69975 	335: uint8(78),
  69976 	336: uint8(79),
  69977 	337: uint8(80),
  69978 	338: uint8(81),
  69979 	339: uint8(82),
  69980 	340: uint8(83),
  69981 	341: uint8(84),
  69982 	342: uint8(85),
  69983 	343: uint8(86),
  69984 	344: uint8(87),
  69985 	345: uint8(88),
  69986 	346: uint8(89),
  69987 	347: uint8(90),
  69988 	348: uint8(91),
  69989 	349: uint8(92),
  69990 	350: uint8(93),
  69991 	351: uint8(94),
  69992 	352: uint8(95),
  69993 	353: uint8(96),
  69994 	354: uint8(97),
  69995 	355: uint8(98),
  69996 	356: uint8(99),
  69997 	357: uint8(100),
  69998 	358: uint8(101),
  69999 	359: uint8(102),
  70000 	360: uint8(103),
  70001 	361: uint8(104),
  70002 	362: uint8(105),
  70003 	363: uint8(106),
  70004 	364: uint8(107),
  70005 	365: uint8(108),
  70006 	366: uint8(109),
  70007 	367: uint8(110),
  70008 	368: uint8(111),
  70009 	369: uint8(112),
  70010 	370: uint8(113),
  70011 	371: uint8(114),
  70012 	372: uint8(115),
  70013 	373: uint8(116),
  70014 	374: uint8(117),
  70015 	375: uint8(118),
  70016 	376: uint8(119),
  70017 	377: uint8(120),
  70018 	378: uint8(121),
  70019 	379: uint8(122),
  70020 	380: uint8(123),
  70021 	381: uint8(124),
  70022 	382: uint8(125),
  70023 	383: uint8(126),
  70024 	384: uint8(127),
  70025 	386: uint8(1),
  70026 	387: uint8(2),
  70027 	388: uint8(3),
  70028 	389: uint8(4),
  70029 	390: uint8(5),
  70030 	391: uint8(6),
  70031 	392: uint8(7),
  70032 	393: uint8(8),
  70033 	394: uint8(9),
  70034 	395: uint8(10),
  70035 	396: uint8(11),
  70036 	397: uint8(12),
  70037 	398: uint8(13),
  70038 	399: uint8(14),
  70039 	400: uint8(15),
  70040 	401: uint8(16),
  70041 	402: uint8(17),
  70042 	403: uint8(18),
  70043 	404: uint8(19),
  70044 	405: uint8(20),
  70045 	406: uint8(21),
  70046 	407: uint8(22),
  70047 	408: uint8(23),
  70048 	409: uint8(24),
  70049 	410: uint8(25),
  70050 	411: uint8(26),
  70051 	412: uint8(27),
  70052 	413: uint8(28),
  70053 	414: uint8(29),
  70054 	415: uint8(30),
  70055 	416: uint8(31),
  70056 	417: uint8(32),
  70057 	418: uint8(33),
  70058 	419: uint8(34),
  70059 	420: uint8(35),
  70060 	421: uint8(36),
  70061 	422: uint8(37),
  70062 	423: uint8(38),
  70063 	424: uint8(39),
  70064 	425: uint8(40),
  70065 	426: uint8(41),
  70066 	427: uint8(42),
  70067 	428: uint8(43),
  70068 	429: uint8(44),
  70069 	430: uint8(45),
  70070 	431: uint8(46),
  70071 	432: uint8(47),
  70072 	433: uint8(48),
  70073 	434: uint8(49),
  70074 	435: uint8(50),
  70075 	436: uint8(51),
  70076 	437: uint8(52),
  70077 	438: uint8(53),
  70078 	439: uint8(54),
  70079 	440: uint8(55),
  70080 	441: uint8(56),
  70081 	442: uint8(57),
  70082 	443: uint8(58),
  70083 	444: uint8(59),
  70084 	445: uint8(60),
  70085 	446: uint8(61),
  70086 	447: uint8(62),
  70087 	448: uint8(63),
  70088 	449: uint8(64),
  70089 	450: uint8(65),
  70090 	451: uint8(66),
  70091 	452: uint8(67),
  70092 	453: uint8(68),
  70093 	454: uint8(69),
  70094 	455: uint8(70),
  70095 	456: uint8(71),
  70096 	457: uint8(72),
  70097 	458: uint8(73),
  70098 	459: uint8(74),
  70099 	460: uint8(75),
  70100 	461: uint8(76),
  70101 	462: uint8(77),
  70102 	463: uint8(78),
  70103 	464: uint8(79),
  70104 	465: uint8(80),
  70105 	466: uint8(81),
  70106 	467: uint8(82),
  70107 	468: uint8(83),
  70108 	469: uint8(84),
  70109 	470: uint8(85),
  70110 	471: uint8(86),
  70111 	472: uint8(87),
  70112 	473: uint8(88),
  70113 	474: uint8(89),
  70114 	475: uint8(90),
  70115 	476: uint8(91),
  70116 	477: uint8(92),
  70117 	478: uint8(93),
  70118 	479: uint8(94),
  70119 	480: uint8(95),
  70120 	481: uint8(96),
  70121 	482: uint8(97),
  70122 	483: uint8(98),
  70123 	484: uint8(99),
  70124 	485: uint8(100),
  70125 	486: uint8(101),
  70126 	487: uint8(102),
  70127 	488: uint8(103),
  70128 	489: uint8(104),
  70129 	490: uint8(105),
  70130 	491: uint8(106),
  70131 	492: uint8(107),
  70132 	493: uint8(108),
  70133 	494: uint8(109),
  70134 	495: uint8(110),
  70135 	496: uint8(111),
  70136 	497: uint8(112),
  70137 	498: uint8(113),
  70138 	499: uint8(114),
  70139 	500: uint8(115),
  70140 	501: uint8(116),
  70141 	502: uint8(117),
  70142 	503: uint8(118),
  70143 	504: uint8(119),
  70144 	505: uint8(120),
  70145 	506: uint8(121),
  70146 	507: uint8(122),
  70147 	508: uint8(123),
  70148 	509: uint8(124),
  70149 	510: uint8(125),
  70150 	511: uint8(126),
  70151 }
  70152 
  70153 // C documentation
  70154 //
  70155 //	// lookup table for small values of int*log2(int) * (1 << LOG_2_PRECISION_BITS).
  70156 //	// Obtained in Python with:
  70157 //	// a=[ "%d"%i if i<(1<<32) else "%dull"%i
  70158 //	//     for i in [ round((1<<LOG_2_PRECISION_BITS)*math.log2(i)*i) if i
  70159 //	//     else 0 for i in range(256)]]
  70160 //	// print(',\n '.join([','.join(v) for v in batched([i.rjust(15)
  70161 //	//                      for i in a],4)]))
  70162 var kSLog2Table = [256]uint64_t{
  70163 	2:   uint64(16777216),
  70164 	3:   uint64(39886887),
  70165 	4:   uint64(67108864),
  70166 	5:   uint64(97388723),
  70167 	6:   uint64(130105423),
  70168 	7:   uint64(164848600),
  70169 	8:   uint64(201326592),
  70170 	9:   uint64(239321324),
  70171 	10:  uint64(278663526),
  70172 	11:  uint64(319217973),
  70173 	12:  uint64(360874141),
  70174 	13:  uint64(403539997),
  70175 	14:  uint64(447137711),
  70176 	15:  uint64(491600606),
  70177 	16:  uint64(536870912),
  70178 	17:  uint64(582898099),
  70179 	18:  uint64(629637592),
  70180 	19:  uint64(677049776),
  70181 	20:  uint64(725099212),
  70182 	21:  uint64(773754010),
  70183 	22:  uint64(822985323),
  70184 	23:  uint64(872766924),
  70185 	24:  uint64(923074875),
  70186 	25:  uint64(973887230),
  70187 	26:  uint64(1025183802),
  70188 	27:  uint64(1076945958),
  70189 	28:  uint64(1129156447),
  70190 	29:  uint64(1181799249),
  70191 	30:  uint64(1234859451),
  70192 	31:  uint64(1288323135),
  70193 	32:  uint64(1342177280),
  70194 	33:  uint64(1396409681),
  70195 	34:  uint64(1451008871),
  70196 	35:  uint64(1505964059),
  70197 	36:  uint64(1561265072),
  70198 	37:  uint64(1616902301),
  70199 	38:  uint64(1672866655),
  70200 	39:  uint64(1729149526),
  70201 	40:  uint64(1785742744),
  70202 	41:  uint64(1842638548),
  70203 	42:  uint64(1899829557),
  70204 	43:  uint64(1957308741),
  70205 	44:  uint64(2015069397),
  70206 	45:  uint64(2073105127),
  70207 	46:  uint64(2131409817),
  70208 	47:  uint64(2189977618),
  70209 	48:  uint64(2248802933),
  70210 	49:  uint64(2307880396),
  70211 	50:  uint64(2367204859),
  70212 	51:  uint64(2426771383),
  70213 	52:  uint64(2486575220),
  70214 	53:  uint64(2546611805),
  70215 	54:  uint64(2606876748),
  70216 	55:  uint64(2667365819),
  70217 	56:  uint64(2728074942),
  70218 	57:  uint64(2789000187),
  70219 	58:  uint64(2850137762),
  70220 	59:  uint64(2911484006),
  70221 	60:  uint64(2973035382),
  70222 	61:  uint64(3034788471),
  70223 	62:  uint64(3096739966),
  70224 	63:  uint64(3158886666),
  70225 	64:  uint64(3221225472),
  70226 	65:  uint64(3283753383),
  70227 	66:  uint64(3346467489),
  70228 	67:  uint64(3409364969),
  70229 	68:  uint64(3472443085),
  70230 	69:  uint64(3535699182),
  70231 	70:  uint64(3599130679),
  70232 	71:  uint64(3662735070),
  70233 	72:  uint64(3726509920),
  70234 	73:  uint64(3790452862),
  70235 	74:  uint64(3854561593),
  70236 	75:  uint64(3918833872),
  70237 	76:  uint64(3983267519),
  70238 	77:  uint64(4047860410),
  70239 	78:  uint64(4112610476),
  70240 	79:  uint64(4177515704),
  70241 	80:  uint64(4242574127),
  70242 	81:  uint64(4307783833),
  70243 	82:  uint64(4373142952),
  70244 	83:  uint64(4438649662),
  70245 	84:  uint64(4504302186),
  70246 	85:  uint64(4570098787),
  70247 	86:  uint64(4636037770),
  70248 	87:  uint64(4702117480),
  70249 	88:  uint64(4768336298),
  70250 	89:  uint64(4834692645),
  70251 	90:  uint64(4901184974),
  70252 	91:  uint64(4967811774),
  70253 	92:  uint64(5034571569),
  70254 	93:  uint64(5101462912),
  70255 	94:  uint64(5168484389),
  70256 	95:  uint64(5235634615),
  70257 	96:  uint64(5302912235),
  70258 	97:  uint64(5370315922),
  70259 	98:  uint64(5437844376),
  70260 	99:  uint64(5505496324),
  70261 	100: uint64(5573270518),
  70262 	101: uint64(5641165737),
  70263 	102: uint64(5709180782),
  70264 	103: uint64(5777314477),
  70265 	104: uint64(5845565671),
  70266 	105: uint64(5913933235),
  70267 	106: uint64(5982416059),
  70268 	107: uint64(6051013057),
  70269 	108: uint64(6119723161),
  70270 	109: uint64(6188545324),
  70271 	110: uint64(6257478518),
  70272 	111: uint64(6326521733),
  70273 	112: uint64(6395673979),
  70274 	113: uint64(6464934282),
  70275 	114: uint64(6534301685),
  70276 	115: uint64(6603775250),
  70277 	116: uint64(6673354052),
  70278 	117: uint64(6743037185),
  70279 	118: uint64(6812823756),
  70280 	119: uint64(6882712890),
  70281 	120: uint64(6952703725),
  70282 	121: uint64(7022795412),
  70283 	122: uint64(7092987118),
  70284 	123: uint64(7163278025),
  70285 	124: uint64(7233667324),
  70286 	125: uint64(7304154222),
  70287 	126: uint64(7374737939),
  70288 	127: uint64(7445417707),
  70289 	128: uint64(7516192768),
  70290 	129: uint64(7587062379),
  70291 	130: uint64(7658025806),
  70292 	131: uint64(7729082328),
  70293 	132: uint64(7800231234),
  70294 	133: uint64(7871471825),
  70295 	134: uint64(7942803410),
  70296 	135: uint64(8014225311),
  70297 	136: uint64(8085736859),
  70298 	137: uint64(8157337394),
  70299 	138: uint64(8229026267),
  70300 	139: uint64(8300802839),
  70301 	140: uint64(8372666477),
  70302 	141: uint64(8444616560),
  70303 	142: uint64(8516652476),
  70304 	143: uint64(8588773618),
  70305 	144: uint64(8660979393),
  70306 	145: uint64(8733269211),
  70307 	146: uint64(8805642493),
  70308 	147: uint64(8878098667),
  70309 	148: uint64(8950637170),
  70310 	149: uint64(9023257446),
  70311 	150: uint64(9095958945),
  70312 	151: uint64(9168741125),
  70313 	152: uint64(9241603454),
  70314 	153: uint64(9314545403),
  70315 	154: uint64(9387566451),
  70316 	155: uint64(9460666086),
  70317 	156: uint64(9533843800),
  70318 	157: uint64(9607099093),
  70319 	158: uint64(9680431471),
  70320 	159: uint64(9753840445),
  70321 	160: uint64(9827325535),
  70322 	161: uint64(9900886263),
  70323 	162: uint64(9974522161),
  70324 	163: uint64(10048232765),
  70325 	164: uint64(10122017615),
  70326 	165: uint64(10195876260),
  70327 	166: uint64(10269808253),
  70328 	167: uint64(10343813150),
  70329 	168: uint64(10417890516),
  70330 	169: uint64(10492039919),
  70331 	170: uint64(10566260934),
  70332 	171: uint64(10640553138),
  70333 	172: uint64(10714916116),
  70334 	173: uint64(10789349456),
  70335 	174: uint64(10863852751),
  70336 	175: uint64(10938425600),
  70337 	176: uint64(11013067604),
  70338 	177: uint64(11087778372),
  70339 	178: uint64(11162557513),
  70340 	179: uint64(11237404645),
  70341 	180: uint64(11312319387),
  70342 	181: uint64(11387301364),
  70343 	182: uint64(11462350205),
  70344 	183: uint64(11537465541),
  70345 	184: uint64(11612647010),
  70346 	185: uint64(11687894253),
  70347 	186: uint64(11763206912),
  70348 	187: uint64(11838584638),
  70349 	188: uint64(11914027082),
  70350 	189: uint64(11989533899),
  70351 	190: uint64(12065104750),
  70352 	191: uint64(12140739296),
  70353 	192: uint64(12216437206),
  70354 	193: uint64(12292198148),
  70355 	194: uint64(12368021795),
  70356 	195: uint64(12443907826),
  70357 	196: uint64(12519855920),
  70358 	197: uint64(12595865759),
  70359 	198: uint64(12671937032),
  70360 	199: uint64(12748069427),
  70361 	200: uint64(12824262637),
  70362 	201: uint64(12900516358),
  70363 	202: uint64(12976830290),
  70364 	203: uint64(13053204134),
  70365 	204: uint64(13129637595),
  70366 	205: uint64(13206130381),
  70367 	206: uint64(13282682202),
  70368 	207: uint64(13359292772),
  70369 	208: uint64(13435961806),
  70370 	209: uint64(13512689025),
  70371 	210: uint64(13589474149),
  70372 	211: uint64(13666316903),
  70373 	212: uint64(13743217014),
  70374 	213: uint64(13820174211),
  70375 	214: uint64(13897188225),
  70376 	215: uint64(13974258793),
  70377 	216: uint64(14051385649),
  70378 	217: uint64(14128568535),
  70379 	218: uint64(14205807192),
  70380 	219: uint64(14283101363),
  70381 	220: uint64(14360450796),
  70382 	221: uint64(14437855239),
  70383 	222: uint64(14515314443),
  70384 	223: uint64(14592828162),
  70385 	224: uint64(14670396151),
  70386 	225: uint64(14748018167),
  70387 	226: uint64(14825693972),
  70388 	227: uint64(14903423326),
  70389 	228: uint64(14981205995),
  70390 	229: uint64(15059041743),
  70391 	230: uint64(15136930339),
  70392 	231: uint64(15214871554),
  70393 	232: uint64(15292865160),
  70394 	233: uint64(15370910930),
  70395 	234: uint64(15449008641),
  70396 	235: uint64(15527158071),
  70397 	236: uint64(15605359001),
  70398 	237: uint64(15683611210),
  70399 	238: uint64(15761914485),
  70400 	239: uint64(15840268608),
  70401 	240: uint64(15918673369),
  70402 	241: uint64(15997128556),
  70403 	242: uint64(16075633960),
  70404 	243: uint64(16154189373),
  70405 	244: uint64(16232794589),
  70406 	245: uint64(16311449405),
  70407 	246: uint64(16390153617),
  70408 	247: uint64(16468907026),
  70409 	248: uint64(16547709431),
  70410 	249: uint64(16626560636),
  70411 	250: uint64(16705460444),
  70412 	251: uint64(16784408661),
  70413 	252: uint64(16863405094),
  70414 	253: uint64(16942449552),
  70415 	254: uint64(17021541845),
  70416 	255: uint64(17100681785),
  70417 }
  70418 
  70419 var kVP8Log2Range = [128]uint8_t{
  70420 	0:   uint8(7),
  70421 	1:   uint8(6),
  70422 	2:   uint8(6),
  70423 	3:   uint8(5),
  70424 	4:   uint8(5),
  70425 	5:   uint8(5),
  70426 	6:   uint8(5),
  70427 	7:   uint8(4),
  70428 	8:   uint8(4),
  70429 	9:   uint8(4),
  70430 	10:  uint8(4),
  70431 	11:  uint8(4),
  70432 	12:  uint8(4),
  70433 	13:  uint8(4),
  70434 	14:  uint8(4),
  70435 	15:  uint8(3),
  70436 	16:  uint8(3),
  70437 	17:  uint8(3),
  70438 	18:  uint8(3),
  70439 	19:  uint8(3),
  70440 	20:  uint8(3),
  70441 	21:  uint8(3),
  70442 	22:  uint8(3),
  70443 	23:  uint8(3),
  70444 	24:  uint8(3),
  70445 	25:  uint8(3),
  70446 	26:  uint8(3),
  70447 	27:  uint8(3),
  70448 	28:  uint8(3),
  70449 	29:  uint8(3),
  70450 	30:  uint8(3),
  70451 	31:  uint8(2),
  70452 	32:  uint8(2),
  70453 	33:  uint8(2),
  70454 	34:  uint8(2),
  70455 	35:  uint8(2),
  70456 	36:  uint8(2),
  70457 	37:  uint8(2),
  70458 	38:  uint8(2),
  70459 	39:  uint8(2),
  70460 	40:  uint8(2),
  70461 	41:  uint8(2),
  70462 	42:  uint8(2),
  70463 	43:  uint8(2),
  70464 	44:  uint8(2),
  70465 	45:  uint8(2),
  70466 	46:  uint8(2),
  70467 	47:  uint8(2),
  70468 	48:  uint8(2),
  70469 	49:  uint8(2),
  70470 	50:  uint8(2),
  70471 	51:  uint8(2),
  70472 	52:  uint8(2),
  70473 	53:  uint8(2),
  70474 	54:  uint8(2),
  70475 	55:  uint8(2),
  70476 	56:  uint8(2),
  70477 	57:  uint8(2),
  70478 	58:  uint8(2),
  70479 	59:  uint8(2),
  70480 	60:  uint8(2),
  70481 	61:  uint8(2),
  70482 	62:  uint8(2),
  70483 	63:  uint8(1),
  70484 	64:  uint8(1),
  70485 	65:  uint8(1),
  70486 	66:  uint8(1),
  70487 	67:  uint8(1),
  70488 	68:  uint8(1),
  70489 	69:  uint8(1),
  70490 	70:  uint8(1),
  70491 	71:  uint8(1),
  70492 	72:  uint8(1),
  70493 	73:  uint8(1),
  70494 	74:  uint8(1),
  70495 	75:  uint8(1),
  70496 	76:  uint8(1),
  70497 	77:  uint8(1),
  70498 	78:  uint8(1),
  70499 	79:  uint8(1),
  70500 	80:  uint8(1),
  70501 	81:  uint8(1),
  70502 	82:  uint8(1),
  70503 	83:  uint8(1),
  70504 	84:  uint8(1),
  70505 	85:  uint8(1),
  70506 	86:  uint8(1),
  70507 	87:  uint8(1),
  70508 	88:  uint8(1),
  70509 	89:  uint8(1),
  70510 	90:  uint8(1),
  70511 	91:  uint8(1),
  70512 	92:  uint8(1),
  70513 	93:  uint8(1),
  70514 	94:  uint8(1),
  70515 	95:  uint8(1),
  70516 	96:  uint8(1),
  70517 	97:  uint8(1),
  70518 	98:  uint8(1),
  70519 	99:  uint8(1),
  70520 	100: uint8(1),
  70521 	101: uint8(1),
  70522 	102: uint8(1),
  70523 	103: uint8(1),
  70524 	104: uint8(1),
  70525 	105: uint8(1),
  70526 	106: uint8(1),
  70527 	107: uint8(1),
  70528 	108: uint8(1),
  70529 	109: uint8(1),
  70530 	110: uint8(1),
  70531 	111: uint8(1),
  70532 	112: uint8(1),
  70533 	113: uint8(1),
  70534 	114: uint8(1),
  70535 	115: uint8(1),
  70536 	116: uint8(1),
  70537 	117: uint8(1),
  70538 	118: uint8(1),
  70539 	119: uint8(1),
  70540 	120: uint8(1),
  70541 	121: uint8(1),
  70542 	122: uint8(1),
  70543 	123: uint8(1),
  70544 	124: uint8(1),
  70545 	125: uint8(1),
  70546 	126: uint8(1),
  70547 }
  70548 
  70549 // C documentation
  70550 //
  70551 //	// range = ((range - 1) << kVP8Log2Range[range]) + 1
  70552 var kVP8NewRange = [128]uint8_t{
  70553 	0:   uint8(127),
  70554 	1:   uint8(127),
  70555 	2:   uint8(191),
  70556 	3:   uint8(127),
  70557 	4:   uint8(159),
  70558 	5:   uint8(191),
  70559 	6:   uint8(223),
  70560 	7:   uint8(127),
  70561 	8:   uint8(143),
  70562 	9:   uint8(159),
  70563 	10:  uint8(175),
  70564 	11:  uint8(191),
  70565 	12:  uint8(207),
  70566 	13:  uint8(223),
  70567 	14:  uint8(239),
  70568 	15:  uint8(127),
  70569 	16:  uint8(135),
  70570 	17:  uint8(143),
  70571 	18:  uint8(151),
  70572 	19:  uint8(159),
  70573 	20:  uint8(167),
  70574 	21:  uint8(175),
  70575 	22:  uint8(183),
  70576 	23:  uint8(191),
  70577 	24:  uint8(199),
  70578 	25:  uint8(207),
  70579 	26:  uint8(215),
  70580 	27:  uint8(223),
  70581 	28:  uint8(231),
  70582 	29:  uint8(239),
  70583 	30:  uint8(247),
  70584 	31:  uint8(127),
  70585 	32:  uint8(131),
  70586 	33:  uint8(135),
  70587 	34:  uint8(139),
  70588 	35:  uint8(143),
  70589 	36:  uint8(147),
  70590 	37:  uint8(151),
  70591 	38:  uint8(155),
  70592 	39:  uint8(159),
  70593 	40:  uint8(163),
  70594 	41:  uint8(167),
  70595 	42:  uint8(171),
  70596 	43:  uint8(175),
  70597 	44:  uint8(179),
  70598 	45:  uint8(183),
  70599 	46:  uint8(187),
  70600 	47:  uint8(191),
  70601 	48:  uint8(195),
  70602 	49:  uint8(199),
  70603 	50:  uint8(203),
  70604 	51:  uint8(207),
  70605 	52:  uint8(211),
  70606 	53:  uint8(215),
  70607 	54:  uint8(219),
  70608 	55:  uint8(223),
  70609 	56:  uint8(227),
  70610 	57:  uint8(231),
  70611 	58:  uint8(235),
  70612 	59:  uint8(239),
  70613 	60:  uint8(243),
  70614 	61:  uint8(247),
  70615 	62:  uint8(251),
  70616 	63:  uint8(127),
  70617 	64:  uint8(129),
  70618 	65:  uint8(131),
  70619 	66:  uint8(133),
  70620 	67:  uint8(135),
  70621 	68:  uint8(137),
  70622 	69:  uint8(139),
  70623 	70:  uint8(141),
  70624 	71:  uint8(143),
  70625 	72:  uint8(145),
  70626 	73:  uint8(147),
  70627 	74:  uint8(149),
  70628 	75:  uint8(151),
  70629 	76:  uint8(153),
  70630 	77:  uint8(155),
  70631 	78:  uint8(157),
  70632 	79:  uint8(159),
  70633 	80:  uint8(161),
  70634 	81:  uint8(163),
  70635 	82:  uint8(165),
  70636 	83:  uint8(167),
  70637 	84:  uint8(169),
  70638 	85:  uint8(171),
  70639 	86:  uint8(173),
  70640 	87:  uint8(175),
  70641 	88:  uint8(177),
  70642 	89:  uint8(179),
  70643 	90:  uint8(181),
  70644 	91:  uint8(183),
  70645 	92:  uint8(185),
  70646 	93:  uint8(187),
  70647 	94:  uint8(189),
  70648 	95:  uint8(191),
  70649 	96:  uint8(193),
  70650 	97:  uint8(195),
  70651 	98:  uint8(197),
  70652 	99:  uint8(199),
  70653 	100: uint8(201),
  70654 	101: uint8(203),
  70655 	102: uint8(205),
  70656 	103: uint8(207),
  70657 	104: uint8(209),
  70658 	105: uint8(211),
  70659 	106: uint8(213),
  70660 	107: uint8(215),
  70661 	108: uint8(217),
  70662 	109: uint8(219),
  70663 	110: uint8(221),
  70664 	111: uint8(223),
  70665 	112: uint8(225),
  70666 	113: uint8(227),
  70667 	114: uint8(229),
  70668 	115: uint8(231),
  70669 	116: uint8(233),
  70670 	117: uint8(235),
  70671 	118: uint8(237),
  70672 	119: uint8(239),
  70673 	120: uint8(241),
  70674 	121: uint8(243),
  70675 	122: uint8(245),
  70676 	123: uint8(247),
  70677 	124: uint8(249),
  70678 	125: uint8(251),
  70679 	126: uint8(253),
  70680 	127: uint8(127),
  70681 }
  70682 
  70683 var __ccgo_ts = (*reflect.StringHeader)(unsafe.Pointer(&__ccgo_ts1)).Data
  70684 
  70685 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"