tight_detect_smooth_image24(VncState *vs, int w, int h)

{

    int off;

    int x, y, d, dx;

    uint c;

    uint stats[256];

    int pixels = 0;

    int pix, left[3];

    uint errors;

    unsigned char *buf = vs->tight.buffer;



    /*

     * If client is big-endian, color samples begin from the second

     * byte (offset 1) of a 32-bit pixel value.

     */

    off = !!(vs->clientds.flags & QEMU_BIG_ENDIAN_FLAG);



    memset(stats, 0, sizeof (stats));



    for (y = 0, x = 0; y < h && x < w;) {

        for (d = 0; d < h - y && d < w - x - VNC_TIGHT_DETECT_SUBROW_WIDTH;

             d++) {

            for (c = 0; c < 3; c++) {

                left[c] = buf[((y+d)*w+x+d)*4+off+c] & 0xFF;

            }

            for (dx = 1; dx <= VNC_TIGHT_DETECT_SUBROW_WIDTH; dx++) {

                for (c = 0; c < 3; c++) {

                    pix = buf[((y+d)*w+x+d+dx)*4+off+c] & 0xFF;

                    stats[abs(pix - left[c])]++;

                    left[c] = pix;

                }

                pixels++;

            }

        }

        if (w > h) {

            x += h;

            y = 0;

        } else {

            x = 0;

            y += w;

        }

    }



    /* 95% smooth or more ... */

    if (stats[0] * 33 / pixels >= 95) {

        return 0;

    }



    errors = 0;

    for (c = 1; c < 8; c++) {

        errors += stats[c] * (c * c);

        if (stats[c] == 0 || stats[c] > stats[c-1] * 2) {

            return 0;

        }

    }

    for (; c < 256; c++) {

        errors += stats[c] * (c * c);

    }

    errors /= (pixels * 3 - stats[0]);



    return errors;

}

tight_detect_smooth_image24(VncState *vs, int w, int h)

{

    int off;

    int x, y, d, dx;

    uint c;

    uint stats[256];

    int pixels = 0;

    int pix, left[3];

    uint errors;

    unsigned char *buf = vs->tight.buffer;



    







    off = !!(vs->clientds.flags & QEMU_BIG_ENDIAN_FLAG);



    memset(stats, 0, sizeof (stats));



    for (y = 0, x = 0; y < h && x < w;) {

        for (d = 0; d < h - y && d < w - x - VNC_TIGHT_DETECT_SUBROW_WIDTH;

             d++) {

            for (c = 0; c < 3; c++) {

                left[c] = buf[((y+d)*w+x+d)*4+off+c] & 0xFF;

            }

            for (dx = 1; dx <= VNC_TIGHT_DETECT_SUBROW_WIDTH; dx++) {

                for (c = 0; c < 3; c++) {

                    pix = buf[((y+d)*w+x+d+dx)*4+off+c] & 0xFF;

                    stats[abs(pix - left[c])]++;

                    left[c] = pix;

                }

                pixels++;

            }

        }

        if (w > h) {

            x += h;

            y = 0;

        } else {

            x = 0;

            y += w;

        }

    }



    

    if (stats[0] * 33 / pixels >= 95) {

        return 0;

    }



    errors = 0;

    for (c = 1; c < 8; c++) {

        errors += stats[c] * (c * c);

        if (stats[c] == 0 || stats[c] > stats[c-1] * 2) {

            return 0;

        }

    }

    for (; c < 256; c++) {

        errors += stats[c] * (c * c);

    }

    errors /= (pixels * 3 - stats[0]);



    return errors;

}

FUNC_0(VncState *VAR_0, int VAR_1, int VAR_2)

{

    int VAR_3;

    int VAR_4, VAR_5, VAR_6, VAR_7;

    uint c;

    uint stats[256];

    int VAR_8 = 0;

    int VAR_9, VAR_10[3];

    uint errors;

    unsigned char *VAR_11 = VAR_0->tight.buffer;



    







    VAR_3 = !!(VAR_0->clientds.flags & QEMU_BIG_ENDIAN_FLAG);



    memset(stats, 0, sizeof (stats));



    for (VAR_5 = 0, VAR_4 = 0; VAR_5 < VAR_2 && VAR_4 < VAR_1;) {

        for (VAR_6 = 0; VAR_6 < VAR_2 - VAR_5 && VAR_6 < VAR_1 - VAR_4 - VNC_TIGHT_DETECT_SUBROW_WIDTH;

             VAR_6++) {

            for (c = 0; c < 3; c++) {

                VAR_10[c] = VAR_11[((VAR_5+VAR_6)*VAR_1+VAR_4+VAR_6)*4+VAR_3+c] & 0xFF;

            }

            for (VAR_7 = 1; VAR_7 <= VNC_TIGHT_DETECT_SUBROW_WIDTH; VAR_7++) {

                for (c = 0; c < 3; c++) {

                    VAR_9 = VAR_11[((VAR_5+VAR_6)*VAR_1+VAR_4+VAR_6+VAR_7)*4+VAR_3+c] & 0xFF;

                    stats[abs(VAR_9 - VAR_10[c])]++;

                    VAR_10[c] = VAR_9;

                }

                VAR_8++;

            }

        }

        if (VAR_1 > VAR_2) {

            VAR_4 += VAR_2;

            VAR_5 = 0;

        } else {

            VAR_4 = 0;

            VAR_5 += VAR_1;

        }

    }



    

    if (stats[0] * 33 / VAR_8 >= 95) {

        return 0;

    }



    errors = 0;

    for (c = 1; c < 8; c++) {

        errors += stats[c] * (c * c);

        if (stats[c] == 0 || stats[c] > stats[c-1] * 2) {

            return 0;

        }

    }

    for (; c < 256; c++) {

        errors += stats[c] * (c * c);

    }

    errors /= (VAR_8 * 3 - stats[0]);



    return errors;

}

FUNC_0(VncState *VAR_0, int VAR_1, int VAR_2)
{ int VAR_3; int VAR_4, VAR_5, VAR_6, VAR_7; uint c; uint stats[256]; int VAR_8 = 0; int VAR_9, VAR_10[3]; uint errors; unsigned char *VAR_11 = VAR_0->tight.buffer; VAR_3 = !!(VAR_0->clientds.flags & QEMU_BIG_ENDIAN_FLAG); memset(stats, 0, sizeof (stats)); for (VAR_5 = 0, VAR_4 = 0; VAR_5 < VAR_2 && VAR_4 < VAR_1;) { for (VAR_6 = 0; VAR_6 < VAR_2 - VAR_5 && VAR_6 < VAR_1 - VAR_4 - VNC_TIGHT_DETECT_SUBROW_WIDTH; VAR_6++) { for (c = 0; c < 3; c++) { VAR_10[c] = VAR_11[((VAR_5+VAR_6)*VAR_1+VAR_4+VAR_6)*4+VAR_3+c] & 0xFF; } for (VAR_7 = 1; VAR_7 <= VNC_TIGHT_DETECT_SUBROW_WIDTH; VAR_7++) { for (c = 0; c < 3; c++) { VAR_9 = VAR_11[((VAR_5+VAR_6)*VAR_1+VAR_4+VAR_6+VAR_7)*4+VAR_3+c] & 0xFF; stats[abs(VAR_9 - VAR_10[c])]++; VAR_10[c] = VAR_9; } VAR_8++; } } if (VAR_1 > VAR_2) { VAR_4 += VAR_2; VAR_5 = 0; } else { VAR_4 = 0; VAR_5 += VAR_1; } } if (stats[0] * 33 / VAR_8 >= 95) { return 0; } errors = 0; for (c = 1; c < 8; c++) { errors += stats[c] * (c * c); if (stats[c] == 0 || stats[c] > stats[c-1] * 2) { return 0; } } for (; c < 256; c++) { errors += stats[c] * (c * c); } errors /= (VAR_8 * 3 - stats[0]); return errors; }