X-Git-Url: https://www.fi.muni.cz/~kas/git//home/kas/public_html/git/?a=blobdiff_plain;ds=sidebyside;f=dvi%2Fmdvi-lib%2Fbitmap.c;h=9014dba6000d821cf7e3f4ca42061fa76c19cdcf;hb=07ae50430dd7dda3d9304f3836d2a58f011b9d4d;hp=b30369f42637cbed5a5caba03c477944513cf216;hpb=c3e1500a4815225f08e1b20dd066559e8c92c280;p=evince.git diff --git a/dvi/mdvi-lib/bitmap.c b/dvi/mdvi-lib/bitmap.c index b30369f4..9014dba6 100644 --- a/dvi/mdvi-lib/bitmap.c +++ b/dvi/mdvi-lib/bitmap.c @@ -21,6 +21,7 @@ #include #include "mdvi.h" +#include "color.h" /* bit_masks[n] contains a BmUnit with `n' contiguous bits */ @@ -46,17 +47,6 @@ static BmUnit bit_masks[] = { #define SHOW_OP_DATA (DEBUGGING(BITMAP_OPS) && DEBUGGING(BITMAP_DATA)) #endif -/* cache for color tables, to avoid creating them for every glyph */ -typedef struct { - Ulong fg; - Ulong bg; - Uint nlevels; - Ulong *pixels; - int density; - double gamma; - Uint hits; -} ColorCache; - /* * Some useful macros to manipulate bitmap data * SEGMENT(m,n) = bit mask for a segment of `m' contiguous bits @@ -126,70 +116,6 @@ static Uchar bit_swap[] = { 0x1f, 0x9f, 0x5f, 0xdf, 0x3f, 0xbf, 0x7f, 0xff }; -#define CCSIZE 256 -static ColorCache color_cache[CCSIZE]; -static int cc_entries; - -#define GAMMA_DIFF 0.005 - -static Ulong *get_color_table(DviDevice *dev, - int nlevels, Ulong fg, Ulong bg, double gamma, int density); - - -/* create a color table */ -static Ulong *get_color_table(DviDevice *dev, - int nlevels, Ulong fg, Ulong bg, double gamma, int density) -{ - ColorCache *cc, *tofree; - int lohits; - Ulong *pixels; - int status; - - lohits = color_cache[0].hits; - tofree = &color_cache[0]; - /* look in the cache and see if we have one that matches this request */ - for(cc = &color_cache[0]; cc < &color_cache[cc_entries]; cc++) { - if(cc->hits < lohits) { - lohits = cc->hits; - tofree = cc; - } - if(cc->fg == fg && cc->bg == bg && cc->density == density && - cc->nlevels == nlevels && fabs(cc->gamma - gamma) <= GAMMA_DIFF) - break; - } - - if(cc < &color_cache[cc_entries]) { - cc->hits++; - return cc->pixels; - } - - DEBUG((DBG_DEVICE, "Adding color table to cache (fg=%lu, bg=%lu, n=%d)\n", - fg, bg, nlevels)); - - /* no entry was found in the cache, create a new one */ - if(cc_entries < CCSIZE) { - cc = &color_cache[cc_entries++]; - cc->pixels = NULL; - } else { - cc = tofree; - xfree(cc->pixels); - } - pixels = xnalloc(Ulong, nlevels); - status = dev->alloc_colors(dev->device_data, - pixels, nlevels, fg, bg, gamma, density); - if(status < 0) { - xfree(pixels); - return NULL; - } - cc->fg = fg; - cc->bg = bg; - cc->gamma = gamma; - cc->density = density; - cc->nlevels = nlevels; - cc->pixels = pixels; - cc->hits = 1; - return pixels; -} /* * next we have three bitmap functions to convert bitmaps in LSB bit order @@ -284,7 +210,7 @@ BITMAP *bitmap_alloc(int w, int h) bm->height = h; bm->stride = BM_BYTES_PER_LINE(bm); if(h && bm->stride) - bm->data = (BmUnit *)xcalloc(h, bm->stride); + bm->data = (BmUnit *)mdvi_calloc(h, bm->stride); else bm->data = NULL; @@ -300,7 +226,7 @@ BITMAP *bitmap_alloc_raw(int w, int h) bm->height = h; bm->stride = BM_BYTES_PER_LINE(bm); if(h && bm->stride) - bm->data = (BmUnit *)xmalloc(h * bm->stride); + bm->data = (BmUnit *)mdvi_malloc(h * bm->stride); else bm->data = NULL; @@ -460,7 +386,7 @@ void bitmap_flip_horizontally(BITMAP *bm) nb.width = bm->width; nb.height = bm->height; nb.stride = bm->stride; - nb.data = xcalloc(bm->height, bm->stride); + nb.data = mdvi_calloc(bm->height, bm->stride); fptr = bm->data; tptr = __bm_unit_ptr(&nb, nb.width-1, 0); @@ -490,7 +416,7 @@ void bitmap_flip_horizontally(BITMAP *bm) } DEBUG((DBG_BITMAP_OPS, "flip_horizontally (%d,%d) -> (%d,%d)\n", bm->width, bm->height, nb.width, nb.height)); - xfree(bm->data); + mdvi_free(bm->data); bm->data = nb.data; if(SHOW_OP_DATA) bitmap_print(stderr, bm); @@ -506,7 +432,7 @@ void bitmap_flip_vertically(BITMAP *bm) nb.width = bm->width; nb.height = bm->height; nb.stride = bm->stride; - nb.data = xcalloc(bm->height, bm->stride); + nb.data = mdvi_calloc(bm->height, bm->stride); fptr = bm->data; tptr = __bm_unit_ptr(&nb, 0, nb.height-1); @@ -531,7 +457,7 @@ void bitmap_flip_vertically(BITMAP *bm) } DEBUG((DBG_BITMAP_OPS, "flip_vertically (%d,%d) -> (%d,%d)\n", bm->width, bm->height, nb.width, nb.height)); - xfree(bm->data); + mdvi_free(bm->data); bm->data = nb.data; if(SHOW_OP_DATA) bitmap_print(stderr, bm); @@ -547,7 +473,7 @@ void bitmap_flip_diagonally(BITMAP *bm) nb.width = bm->width; nb.height = bm->height; nb.stride = bm->stride; - nb.data = xcalloc(bm->height, bm->stride); + nb.data = mdvi_calloc(bm->height, bm->stride); fptr = bm->data; tptr = __bm_unit_ptr(&nb, nb.width-1, nb.height-1); @@ -577,7 +503,7 @@ void bitmap_flip_diagonally(BITMAP *bm) } DEBUG((DBG_BITMAP_OPS, "flip_diagonally (%d,%d) -> (%d,%d)\n", bm->width, bm->height, nb.width, nb.height)); - xfree(bm->data); + mdvi_free(bm->data); bm->data = nb.data; if(SHOW_OP_DATA) bitmap_print(stderr, bm); @@ -593,7 +519,7 @@ void bitmap_rotate_clockwise(BITMAP *bm) nb.width = bm->height; nb.height = bm->width; nb.stride = BM_BYTES_PER_LINE(&nb); - nb.data = xcalloc(nb.height, nb.stride); + nb.data = mdvi_calloc(nb.height, nb.stride); fptr = bm->data; tptr = __bm_unit_ptr(&nb, nb.width - 1, 0); @@ -626,7 +552,7 @@ void bitmap_rotate_clockwise(BITMAP *bm) DEBUG((DBG_BITMAP_OPS, "rotate_clockwise (%d,%d) -> (%d,%d)\n", bm->width, bm->height, nb.width, nb.height)); - xfree(bm->data); + mdvi_free(bm->data); bm->data = nb.data; bm->width = nb.width; bm->height = nb.height; @@ -645,7 +571,7 @@ void bitmap_rotate_counter_clockwise(BITMAP *bm) nb.width = bm->height; nb.height = bm->width; nb.stride = BM_BYTES_PER_LINE(&nb); - nb.data = xcalloc(nb.height, nb.stride); + nb.data = mdvi_calloc(nb.height, nb.stride); fptr = bm->data; tptr = __bm_unit_ptr(&nb, 0, nb.height - 1); @@ -678,7 +604,7 @@ void bitmap_rotate_counter_clockwise(BITMAP *bm) DEBUG((DBG_BITMAP_OPS, "rotate_counter_clockwise (%d,%d) -> (%d,%d)\n", bm->width, bm->height, nb.width, nb.height)); - xfree(bm->data); + mdvi_free(bm->data); bm->data = nb.data; bm->width = nb.width; bm->height = nb.height; @@ -697,7 +623,7 @@ void bitmap_flip_rotate_clockwise(BITMAP *bm) nb.width = bm->height; nb.height = bm->width; nb.stride = BM_BYTES_PER_LINE(&nb); - nb.data = xcalloc(nb.height, nb.stride); + nb.data = mdvi_calloc(nb.height, nb.stride); fptr = bm->data; tptr = __bm_unit_ptr(&nb, nb.width-1, nb.height-1); @@ -729,7 +655,7 @@ void bitmap_flip_rotate_clockwise(BITMAP *bm) } DEBUG((DBG_BITMAP_OPS, "flip_rotate_clockwise (%d,%d) -> (%d,%d)\n", bm->width, bm->height, nb.width, nb.height)); - xfree(bm->data); + mdvi_free(bm->data); bm->data = nb.data; bm->width = nb.width; bm->height = nb.height; @@ -748,7 +674,7 @@ void bitmap_flip_rotate_counter_clockwise(BITMAP *bm) nb.width = bm->height; nb.height = bm->width; nb.stride = BM_BYTES_PER_LINE(&nb); - nb.data = xcalloc(nb.height, nb.stride); + nb.data = mdvi_calloc(nb.height, nb.stride); fptr = bm->data; tptr = nb.data; @@ -781,7 +707,7 @@ void bitmap_flip_rotate_counter_clockwise(BITMAP *bm) DEBUG((DBG_BITMAP_OPS, "flip_rotate_counter_clockwise (%d,%d) -> (%d,%d)\n", bm->width, bm->height, nb.width, nb.height)); - xfree(bm->data); + mdvi_free(bm->data); bm->data = nb.data; bm->width = nb.width; bm->height = nb.height;