else *sg_output_plane++ = P1;
static int ipvideo_decode_block_opcode_0x8(void){    int x, y;    unsigned char P[8];    unsigned char B[8];    unsigned int flags = 0;    unsigned int bitmask = 0;    unsigned char P0 = 0, P1 = 0;    int lower_half = 0;    /* 2-color encoding for each 4x4 quadrant, or 2-color encoding on     * either top and bottom or left and right halves */    CHECK_STREAM_PTR(2);    P[0] = *sg_stream_ptr++;    P[1] = *sg_stream_ptr++;    if (P[0] <= P[1]) {        /* need 12 more bytes */        CHECK_STREAM_PTR(12);        B[0] = *sg_stream_ptr++;  B[1] = *sg_stream_ptr++;        P[2] = *sg_stream_ptr++;  P[3] = *sg_stream_ptr++;        B[2] = *sg_stream_ptr++;  B[3] = *sg_stream_ptr++;        P[4] = *sg_stream_ptr++;  P[5] = *sg_stream_ptr++;        B[4] = *sg_stream_ptr++;  B[5] = *sg_stream_ptr++;        P[6] = *sg_stream_ptr++;  P[7] = *sg_stream_ptr++;        B[6] = *sg_stream_ptr++;  B[7] = *sg_stream_ptr++;        for (y = 0; y < 8; y++) {            /* time to reload flags? */            if (y == 0) {                flags =                    ((B[0] & 0xF0) <<  4) | ((B[4] & 0xF0) <<  8) |                    ((B[0] & 0x0F)      ) | ((B[4] & 0x0F) <<  4) |                    ((B[1] & 0xF0) << 20) | ((B[5] & 0xF0) << 24) |                    ((B[1] & 0x0F) << 16) | ((B[5] & 0x0F) << 20);                bitmask = 0x00000001;                lower_half = 0;  /* still on top half */            } else if (y == 4) {                flags =                    ((B[2] & 0xF0) <<  4) | ((B[6] & 0xF0) <<  8) |                    ((B[2] & 0x0F)      ) | ((B[6] & 0x0F) <<  4) |                    ((B[3] & 0xF0) << 20) | ((B[7] & 0xF0) << 24) |                    ((B[3] & 0x0F) << 16) | ((B[7] & 0x0F) << 20);                bitmask = 0x00000001;                lower_half = 4;            }            for (x = 0; x < 8; x++, bitmask <<= 1) {                /* get the pixel values ready for this quadrant */                if (x == 0) {                    P0 = P[lower_half + 0];                    P1 = P[lower_half + 1];                } else if (x == 4) {                    P0 = P[lower_half + 2];                    P1 = P[lower_half + 3];                }                if (flags & bitmask)                    *sg_output_plane++ = P1;                else                    *sg_output_plane++ = P0;            }            sg_output_plane += sg_line_inc;        }    } else {        /* need 10 more bytes */        CHECK_STREAM_PTR(10);        B[0] = *sg_stream_ptr++;  B[1] = *sg_stream_ptr++;        B[2] = *sg_stream_ptr++;  B[3] = *sg_stream_ptr++;        P[2] = *sg_stream_ptr++;  P[3] = *sg_stream_ptr++;        B[4] = *sg_stream_ptr++;  B[5] = *sg_stream_ptr++;        B[6] = *sg_stream_ptr++;  B[7] = *sg_stream_ptr++;        if (P[2] <= P[3]) {            /* vertical split; left & right halves are 2-color encoded */            for (y = 0; y < 8; y++) {                /* time to reload flags? */                if (y == 0) {                    flags =                        ((B[0] & 0xF0) <<  4) | ((B[4] & 0xF0) <<  8) |                        ((B[0] & 0x0F)      ) | ((B[4] & 0x0F) <<  4) |                        ((B[1] & 0xF0) << 20) | ((B[5] & 0xF0) << 24) |                        ((B[1] & 0x0F) << 16) | ((B[5] & 0x0F) << 20);                    bitmask = 0x00000001;                } else if (y == 4) {                    flags =                        ((B[2] & 0xF0) <<  4) | ((B[6] & 0xF0) <<  8) |                        ((B[2] & 0x0F)      ) | ((B[6] & 0x0F) <<  4) |                        ((B[3] & 0xF0) << 20) | ((B[7] & 0xF0) << 24) |                        ((B[3] & 0x0F) << 16) | ((B[7] & 0x0F) << 20);                    bitmask = 0x00000001;                }                for (x = 0; x < 8; x++, bitmask <<= 1) {                    /* get the pixel values ready for this half */                    if (x == 0) {                        P0 = P[0];                        P1 = P[1];                    } else if (x == 4) {                        P0 = P[2];                        P1 = P[3];                    }                    if (flags & bitmask)                        *sg_output_plane++ = P0;                    else                        *sg_output_plane++ = P1;                }                sg_output_plane += sg_line_inc;            }        } else {            /* horizontal split; top & bottom halves are 2-color encoded */            for (y = 0; y < 8; y++) {                flags = B[y];                if (y == 0) {                    P0 = P[0];                    P1 = P[1];                } else if (y == 4) {                    P0 = P[2];                    P1 = P[3];                }                for (bitmask = 0x01; bitmask <= 0x80; bitmask <<= 1) {                    if (flags & bitmask)                        *sg_output_plane++ = P0;                    else                        *sg_output_plane++ = P1;                }                sg_output_plane += sg_line_inc;            }        }    }    /* report success */    return 0;}