static void omap_ppm_save(const char *filename, uint8_t *data,

                    int w, int h, int linesize, Error **errp)

{

    FILE *f;

    uint8_t *d, *d1;

    unsigned int v;

    int ret, y, x, bpp;



    f = fopen(filename, "wb");

    if (!f) {

        error_setg(errp, "failed to open file '%s': %s", filename,

                   strerror(errno));

        return;

    }

    ret = fprintf(f, "P6\n%d %d\n%d\n", w, h, 255);

    if (ret < 0) {

        goto write_err;

    }

    d1 = data;

    bpp = linesize / w;

    for (y = 0; y < h; y ++) {

        d = d1;

        for (x = 0; x < w; x ++) {

            v = *(uint32_t *) d;

            switch (bpp) {

            case 2:

                ret = fputc((v >> 8) & 0xf8, f);

                if (ret == EOF) {

                    goto write_err;

                }

                ret = fputc((v >> 3) & 0xfc, f);

                if (ret == EOF) {

                    goto write_err;

                }

                ret = fputc((v << 3) & 0xf8, f);

                if (ret == EOF) {

                    goto write_err;

                }

                break;

            case 3:

            case 4:

            default:

                ret = fputc((v >> 16) & 0xff, f);

                if (ret == EOF) {

                    goto write_err;

                }

                ret = fputc((v >> 8) & 0xff, f);

                if (ret == EOF) {

                    goto write_err;

                }

                ret = fputc((v) & 0xff, f);

                if (ret == EOF) {

                    goto write_err;

                }

                break;

            }

            d += bpp;

        }

        d1 += linesize;

    }

out:

    fclose(f);

    return;



write_err:

    error_setg(errp, "failed to write to file '%s': %s", filename,

               strerror(errno));

    unlink(filename);

    goto out;

}

static void omap_ppm_save(const char *filename, uint8_t *data,

                    int w, int h, int linesize, Error **errp)

{

    FILE *f;

    uint8_t *d, *d1;

    unsigned int v;

    int ret, y, x, bpp;



    f = fopen(filename, "wb");

    if (!f) {

        error_setg(errp, "failed to open file '%s': %s", filename,

                   strerror(errno));

        return;

    }

    ret = fprintf(f, "P6\n%d %d\n%d\n", w, h, 255);

    if (ret < 0) {

        goto write_err;

    }

    d1 = data;

    bpp = linesize / w;

    for (y = 0; y < h; y ++) {

        d = d1;

        for (x = 0; x < w; x ++) {

            v = *(uint32_t *) d;

            switch (bpp) {

            case 2:

                ret = fputc((v >> 8) & 0xf8, f);

                if (ret == EOF) {

                    goto write_err;

                }

                ret = fputc((v >> 3) & 0xfc, f);

                if (ret == EOF) {

                    goto write_err;

                }

                ret = fputc((v << 3) & 0xf8, f);

                if (ret == EOF) {

                    goto write_err;

                }

                break;

            case 3:

            case 4:

            default:

                ret = fputc((v >> 16) & 0xff, f);

                if (ret == EOF) {

                    goto write_err;

                }

                ret = fputc((v >> 8) & 0xff, f);

                if (ret == EOF) {

                    goto write_err;

                }

                ret = fputc((v) & 0xff, f);

                if (ret == EOF) {

                    goto write_err;

                }

                break;

            }

            d += bpp;

        }

        d1 += linesize;

    }

out:

    fclose(f);

    return;



write_err:

    error_setg(errp, "failed to write to file '%s': %s", filename,

               strerror(errno));

    unlink(filename);

    goto out;

}

static void FUNC_0(const char *VAR_0, uint8_t *VAR_1,

                    int VAR_2, int VAR_3, int VAR_4, Error **VAR_5)

{

    FILE *f;

    uint8_t *d, *d1;

    unsigned int VAR_6;

    int VAR_7, VAR_8, VAR_9, VAR_10;



    f = fopen(VAR_0, "wb");

    if (!f) {

        error_setg(VAR_5, "failed to open file '%s': %s", VAR_0,

                   strerror(errno));

        return;

    }

    VAR_7 = fprintf(f, "P6\n%d %d\n%d\n", VAR_2, VAR_3, 255);

    if (VAR_7 < 0) {

        goto write_err;

    }

    d1 = VAR_1;

    VAR_10 = VAR_4 / VAR_2;

    for (VAR_8 = 0; VAR_8 < VAR_3; VAR_8 ++) {

        d = d1;

        for (VAR_9 = 0; VAR_9 < VAR_2; VAR_9 ++) {

            VAR_6 = *(uint32_t *) d;

            switch (VAR_10) {

            case 2:

                VAR_7 = fputc((VAR_6 >> 8) & 0xf8, f);

                if (VAR_7 == EOF) {

                    goto write_err;

                }

                VAR_7 = fputc((VAR_6 >> 3) & 0xfc, f);

                if (VAR_7 == EOF) {

                    goto write_err;

                }

                VAR_7 = fputc((VAR_6 << 3) & 0xf8, f);

                if (VAR_7 == EOF) {

                    goto write_err;

                }

                break;

            case 3:

            case 4:

            default:

                VAR_7 = fputc((VAR_6 >> 16) & 0xff, f);

                if (VAR_7 == EOF) {

                    goto write_err;

                }

                VAR_7 = fputc((VAR_6 >> 8) & 0xff, f);

                if (VAR_7 == EOF) {

                    goto write_err;

                }

                VAR_7 = fputc((VAR_6) & 0xff, f);

                if (VAR_7 == EOF) {

                    goto write_err;

                }

                break;

            }

            d += VAR_10;

        }

        d1 += VAR_4;

    }

out:

    fclose(f);

    return;



write_err:

    error_setg(VAR_5, "failed to write to file '%s': %s", VAR_0,

               strerror(errno));

    unlink(VAR_0);

    goto out;

}

static void FUNC_0(const char *VAR_0, uint8_t *VAR_1,
int VAR_2, int VAR_3, int VAR_4, Error **VAR_5)
{ FILE *f; uint8_t *d, *d1; unsigned int VAR_6; int VAR_7, VAR_8, VAR_9, VAR_10; f = fopen(VAR_0, "wb"); if (!f) { error_setg(VAR_5, "failed to open file '%s': %s", VAR_0,
strerror(errno)); return; } VAR_7 = fprintf(f, "P6\n%d %d\n%d\n", VAR_2, VAR_3, 255); if (VAR_7 < 0) { goto write_err; } d1 = VAR_1; VAR_10 = VAR_4 / VAR_2; for (VAR_8 = 0; VAR_8 < VAR_3; VAR_8 ++) { d = d1; for (VAR_9 = 0; VAR_9 < VAR_2; VAR_9 ++) { VAR_6 = *(uint32_t *) d; switch (VAR_10) { case 2:
VAR_7 = fputc((VAR_6 >> 8) & 0xf8, f); if (VAR_7 == EOF) { goto write_err; } VAR_7 = fputc((VAR_6 >> 3) & 0xfc, f); if (VAR_7 == EOF) { goto write_err; } VAR_7 = fputc((VAR_6 << 3) & 0xf8, f); if (VAR_7 == EOF) { goto write_err; } break; case 3:
case 4:
default:
VAR_7 = fputc((VAR_6 >> 16) & 0xff, f); if (VAR_7 == EOF) { goto write_err; } VAR_7 = fputc((VAR_6 >> 8) & 0xff, f); if (VAR_7 == EOF) { goto write_err; } VAR_7 = fputc((VAR_6) & 0xff, f); if (VAR_7 == EOF) { goto write_err; } break; } d += VAR_10; } d1 += VAR_4; } out:
fclose(f); return; write_err:
error_setg(VAR_5, "failed to write to file '%s': %s", VAR_0,
strerror(errno)); unlink(VAR_0); goto out; }