function create_64_and_32_from_128(&$t128) { $t32_i = 0; # 32x32 tile pixel index $t64_i = 0; # 64x64 tile pixel index $t128_i = 0; # 128x128 tile pixel index $t32 = str_repeat("", 32 * 32 / 8); $t64 = str_repeat("", 64 * 64 / 8); for ($y = 0; $y < 32; ++$y) { for ($x = 0; $x < 4; ++$x) { # pull values from t128 $p00 = ord($t128[$t128_i]); $p01 = ord($t128[$t128_i + T128_RB]); $p02 = ord($t128[$t128_i + T128_RB2]); $p03 = ord($t128[$t128_i + T128_RB3]); ++$t128_i; $p10 = ord($t128[$t128_i]); $p11 = ord($t128[$t128_i + T128_RB]); $p12 = ord($t128[$t128_i + T128_RB2]); $p13 = ord($t128[$t128_i + T128_RB3]); ++$t128_i; $p20 = ord($t128[$t128_i]); $p21 = ord($t128[$t128_i + T128_RB]); $p22 = ord($t128[$t128_i + T128_RB2]); $p23 = ord($t128[$t128_i + T128_RB3]); ++$t128_i; $p30 = ord($t128[$t128_i]); $p31 = ord($t128[$t128_i + T128_RB]); $p32 = ord($t128[$t128_i + T128_RB2]); $p33 = ord($t128[$t128_i + T128_RB3]); ++$t128_i; # downsample to 64x64 $d64_00 = downsample($p00, $p10, $p01, $p11); $t64[$t64_i] = chr($d64_00); $d64_01 = downsample($p02, $p12, $p03, $p13); $t64[$t64_i + T64_RB] = chr($d64_01); ++$t64_i; $d64_10 = downsample($p20, $p30, $p21, $p31); $t64[$t64_i] = chr($d64_10); $d64_11 = downsample($p22, $p32, $p23, $p33); $t64[$t64_i + T64_RB] = chr($d64_11); ++$t64_i; # downsample to 32x32 $t32[$t32_i] = chr(downsample($d64_00, $d64_10, $d64_01, $d64_11)); ++$t32_i; } # finished a row. move pixel pointers to next row $t128_i += T128_RB3; # skip three row (we wrote 4 rows at once, advancing one) $t64_i += T64_RB; # skip a row (we wrote two rows at once, advancing one) } return array($t64, $t32); }
function create_tile_from_quadrant($quad) { # set the pixel index we're copying from $pi = $quad % 2 * 16; $pi += floor($quad / 2) * 4096; $t32_i = 0; # 32x32 tile pixel index $t64_i = 0; # 64x64 tile pixel index $t128_i = 0; # 128x128 tile pixel index $t32 = str_repeat("", 32 * 32 / 8); $t64 = str_repeat("", 64 * 64 / 8); $t128 = str_repeat("", 128 * 128 / 8); for ($y = 0; $y < 32; ++$y) { for ($x = 0; $x < 4; ++$x) { # xy $p00 = $GLOBALS['pixels'][$pi]; $p01 = $GLOBALS['pixels'][$pi + PIXELS_RB]; $p02 = $GLOBALS['pixels'][$pi + PIXELS_RB2]; $p03 = $GLOBALS['pixels'][$pi + PIXELS_RB3]; ++$pi; $p10 = $GLOBALS['pixels'][$pi]; $p11 = $GLOBALS['pixels'][$pi + PIXELS_RB]; $p12 = $GLOBALS['pixels'][$pi + PIXELS_RB2]; $p13 = $GLOBALS['pixels'][$pi + PIXELS_RB3]; ++$pi; $p20 = $GLOBALS['pixels'][$pi]; $p21 = $GLOBALS['pixels'][$pi + PIXELS_RB]; $p23 = $GLOBALS['pixels'][$pi + PIXELS_RB3]; $p22 = $GLOBALS['pixels'][$pi + PIXELS_RB2]; ++$pi; $p30 = $GLOBALS['pixels'][$pi]; $p31 = $GLOBALS['pixels'][$pi + PIXELS_RB]; $p32 = $GLOBALS['pixels'][$pi + PIXELS_RB2]; $p33 = $GLOBALS['pixels'][$pi + PIXELS_RB3]; ++$pi; # save directly into t128 $t128[$t128_i] = chr($p00); $t128[$t128_i + T128_RB] = chr($p01); $t128[$t128_i + T128_RB2] = chr($p02); $t128[$t128_i + T128_RB3] = chr($p03); ++$t128_i; $t128[$t128_i] = chr($p10); $t128[$t128_i + T128_RB] = chr($p11); $t128[$t128_i + T128_RB2] = chr($p12); $t128[$t128_i + T128_RB3] = chr($p13); ++$t128_i; $t128[$t128_i] = chr($p20); $t128[$t128_i + T128_RB] = chr($p21); $t128[$t128_i + T128_RB2] = chr($p22); $t128[$t128_i + T128_RB3] = chr($p23); ++$t128_i; $t128[$t128_i] = chr($p30); $t128[$t128_i + T128_RB] = chr($p31); $t128[$t128_i + T128_RB2] = chr($p32); $t128[$t128_i + T128_RB3] = chr($p33); ++$t128_i; # downsample to 64x64 $d64_00 = downsample($p00, $p10, $p01, $p11); $t64[$t64_i] = chr($d64_00); $d64_01 = downsample($p02, $p12, $p03, $p13); $t64[$t64_i + T64_RB] = chr($d64_01); ++$t64_i; $d64_10 = downsample($p20, $p30, $p21, $p31); $t64[$t64_i] = chr($d64_10); $d64_11 = downsample($p22, $p32, $p23, $p33); $t64[$t64_i + T64_RB] = chr($d64_11); ++$t64_i; # downsample to 32x32 $t32[$t32_i] = chr(downsample($d64_00, $d64_10, $d64_01, $d64_11)); ++$t32_i; } # finished a row. move pixels pointer to next row $pi += T128_RB + PIXELS_RB3; # go forwards the other half of this row, and the 3 rows we finished $t128_i += T128_RB3; # skip three row (we wrote 4 rows at once, advancing one) $t64_i += T64_RB; # skip a row (we wrote two rows at once, advancing one) } /* print("quad: $quad\n"); print("first pixel from pixels: " . $GLOBALS['pixels'][0] . "\n"); print("Pixels:\n"); print_table($GLOBALS['pixels'], 64, PIXELS_RB); print("t128:\n"); print_table($t128, 64, T128_RB); print("t64:\n"); print_table($t64, 32, T64_RB); print("t32:\n"); print_table($t32, 16, T32_RB); exit(); */ #print_full_table($t32, 32, T32_RB); #exit(); return array($t128, $t64, $t32); }