예제 #1
0
/* Read from the file header dimensions as well as max
 * int value used
 */
static int read_ppm_init_rest(int fd, struct ppm_info *ppm)
{
    /* Read size. */
    ppm->x = ppm_getuint(fd);
    ppm->y = ppm_getuint(fd);

#ifdef HAVE_LCD_COLOR
    ppm->native_img_size = ppm->x * ppm->y * FB_DATA_SZ;
#endif

    if (ppm->native_img_size > ppm->buf_size) {
        return PLUGIN_OUTOFMEM;
    }

    /* Read maxval. */
    ppm->maxval = ppm_getuint(fd);

    if (ppm->maxval > PPM_OVERALLMAXVAL) {
        ppm_error("maxval of input image (%u) is too large. "\
                  "The maximum allowed by the PPM is %u.",
                  ppm->maxval, PPM_OVERALLMAXVAL);
        return PLUGIN_ERROR;
    }
    if (ppm->maxval == 0) {
        ppm_error("maxval of input image is zero.");
        return PLUGIN_ERROR;
    }
    return PLUGIN_OK;
}
예제 #2
0
int read_ppm_init_rest(int fd, 
                       int * const cols, 
                       int * const rows, 
                       int * const maxval)
{
    /* Read size. */
    *cols = ppm_getuint(fd);
    *rows = ppm_getuint(fd);

    if ((long unsigned int)(*cols * *rows) > PPM_MAXSIZE) {
        ppm_error("Imagesize (%ld pixels) is too large. "\
                  "The maximum allowed is %ld.",
                  (long unsigned int)(*cols * *rows), 
                  (long unsigned int)PPM_MAXSIZE);
        return PLUGIN_ERROR;
    }

    /* Read maxval. */
    *maxval = ppm_getuint(fd);
    
    if (*maxval > PPM_OVERALLMAXVAL) {
        ppm_error("maxval of input image (%u) is too large. "\
                  "The maximum allowed by the PPM is %u.",
                  *maxval, PPM_OVERALLMAXVAL);
        return PLUGIN_ERROR;
    }
    if (*maxval == 0) {
        ppm_error("maxval of input image is zero.");
        return PLUGIN_ERROR;
    }
    return 1;
}
예제 #3
0
static int read_ppm_row(int fd, struct ppm_info *ppm, int row)
{
    int col;
    int r, g, b;
#ifdef HAVE_LCD_COLOR
#if   defined(LCD_STRIDEFORMAT) && LCD_STRIDEFORMAT == VERTICAL_STRIDE
    fb_data *dst = (fb_data *) ppm->buf + row;
    const int stride = ppm->x;
#else
    fb_data *dst = (fb_data *) ppm->buf + ppm->x*row;
    const int stride = 1;
#endif
#endif /* HAVE_LCD_COLOR */
    switch (ppm->format) {
        case PPM_FORMAT:
            for (col = 0; col < ppm->x; ++col) {
                r = ppm_getuint(fd);
                g = ppm_getuint(fd);
                b = ppm_getuint(fd);

                if (r == PLUGIN_ERROR || g == PLUGIN_ERROR ||
                    b == PLUGIN_ERROR)
                {
                    return PLUGIN_ERROR;
                }
                *dst = FB_RGBPACK(
                    (255 * r)/ppm->maxval,
                    (255 * g)/ppm->maxval,
                    (255 * b)/ppm->maxval);
                dst += stride;
            }
            break;

        case RPPM_FORMAT:
            for (col = 0; col < ppm->x; ++col) {
                r = ppm_getrawsample(fd, ppm->maxval);
                g = ppm_getrawsample(fd, ppm->maxval);
                b = ppm_getrawsample(fd, ppm->maxval);

                if (r == PLUGIN_ERROR || g == PLUGIN_ERROR ||
                    b == PLUGIN_ERROR)
                {
                    return PLUGIN_ERROR;
                }
                *dst = FB_RGBPACK(
                    (255 * r)/ppm->maxval,
                    (255 * g)/ppm->maxval,
                    (255 * b)/ppm->maxval);
                dst += stride;
            }
            break;

        default:
            ppm_error("What?!");
            return PLUGIN_ERROR;
    }
    return PLUGIN_OK;
}
예제 #4
0
int read_ppm_row(int fd, 
                 int const row, 
                 int const cols, 
                 int const rows,
                 int const maxval, 
                 int const format)
{
#if   !(defined(LCD_STRIDEFORMAT) && LCD_STRIDEFORMAT == VERTICAL_STRIDE)
    (void) rows;
#endif

    int col;
    int r, g, b;
    switch (format) {
        case PPM_FORMAT:
            for (col = 0; col < cols; ++col) {
                r = ppm_getuint(fd);
                g = ppm_getuint(fd);
                b = ppm_getuint(fd);

                if (r == PLUGIN_ERROR || g == PLUGIN_ERROR ||
                    b == PLUGIN_ERROR)
                {
                    return PLUGIN_ERROR;
                } 
                *BUFADDR(col, row, cols, rows) = LCD_RGBPACK(
                    (255 / maxval) * r,
                    (255 / maxval) * g,
                    (255 / maxval) * b);
            }
            break;

        case RPPM_FORMAT:
            for (col = 0; col < cols; ++col) {
                r = ppm_getrawsample(fd, maxval);
                g = ppm_getrawsample(fd, maxval);
                b = ppm_getrawsample(fd, maxval);

                if (r == PLUGIN_ERROR || g == PLUGIN_ERROR ||
                    b == PLUGIN_ERROR)
                {
                    return PLUGIN_ERROR;
                } 
                *BUFADDR(col, row, cols, rows) = LCD_RGBPACK(
                    (255 / maxval) * r,
                    (255 / maxval) * g,
                    (255 / maxval) * b);
            }
            break;

        default:
            ppm_error("What?!");
            return PLUGIN_ERROR;
    }
    return 1;
}