예제 #1
0
파일: gif.c 프로젝트: cortex/magick
INLINE int
aprox_image_pixels(const Image *image, GifColorType *colors, int color_count, PixelCache *cache, GifPixelType *out)
{
    int width = image->columns;
    int height = image->rows;
    ExceptionInfo ex;
    int ii;
    int jj;
    register const PixelPacket *p = ACQUIRE_IMAGE_PIXELS(image, 0, 0, width, height, &ex);
    if (!p) {
        return 0;
    }
    int end = width * height;
    for (ii = 0; ii < end; ii++, p++) {
        GifByteType r = ScaleQuantumToChar(p->red);
        GifByteType g = ScaleQuantumToChar(p->green);
        GifByteType b = ScaleQuantumToChar(p->blue);
        uint32_t key = (r << 16) + (g << 8) + b;
        if (!pixel_cache_get(cache, key, &out[ii])) {
            int min_delta = 3 * (NCOLORS * NCOLORS);
            int min_pos = 0;
            GifColorType *c = colors;
            for (jj = 0; jj < color_count; jj++, c++) {
                int rd = c->Red - r;
                int gd = c->Green - g;
                int bd = c->Blue - b;
                int delta = (rd * rd) + (gd * gd) + (bd * bd);
                if (delta < min_delta) {
                    min_delta = delta;
                    min_pos = jj;
                    if (min_delta == 0) {
                        break;
                    }
                }
            }
            out[ii] = min_pos;
            pixel_cache_set(cache, key, min_pos);
        }
    }
    return 1;
}
예제 #2
0
파일: transform.c 프로젝트: kilnyy/magick
void
calculate_image_histogram_in_rect(const Image *image, const RectangleInfo *rect, unsigned int histogram[], int o)
{
    register long y;
    register long x;
    register const PixelPacket *p;
    ExceptionInfo ex;
    long sx;
    long sy;
    unsigned int width;
    unsigned int height;
    if (o > 0) {
        memset(histogram, 0, sizeof(unsigned int) * HISTOGRAM_SIZE);
    }
    if (rect && rect->width > 0 && rect->height > 0) {
        sx = rect->x;
        sy = rect->y;
        width = rect->width;
        height = rect->height;
    } else {
        sx = 0;
        sy = 0;
        width = image->columns;
        height = image->rows;
    }
    unsigned int ey = sy + height;
    int total = 0;
    for(y = sy; y < ey; ++y) {
        p = ACQUIRE_IMAGE_PIXELS(image, sx, y, width, 1, &ex);
        if (!p) {
            continue;
        }
        total += width;
        for (x=0; x < width; x++, p++) {
            histogram[ScaleQuantumToChar(p->red)] += o;
            histogram[ScaleQuantumToChar(p->green) + 256] += o;
            histogram[ScaleQuantumToChar(p->blue) + 512] += o;
        }
    }
}
예제 #3
0
파일: gif.c 프로젝트: cortex/magick
INLINE int
acquire_image_pixels(const Image *image, GifByteType *red, GifByteType *green, GifByteType *blue)
{
    register long y;
    register long x;
    register const PixelPacket *p;
    ExceptionInfo ex;
    int width = image->columns;
    int height = image->rows;
    int ii = 0;
    for(y = 0; y < height; ++y) {
        p = ACQUIRE_IMAGE_PIXELS(image, 0, y, width, 1, &ex);
        if (!p) {
            return 0;
        }
        for (x = 0; x < width; x++, ii++, p++) {
            red[ii] = ScaleQuantumToChar(p->red);
            green[ii] = ScaleQuantumToChar(p->green);
            blue[ii] = ScaleQuantumToChar(p->blue);
        }
    }
    return 1;
}