Logo Search packages:      
Sourcecode: inkscape version File versions

void nr_pixblock_setup_fast ( NRPixBlock pb,
NR_PIXBLOCK_MODE  mode,
int  x0,
int  y0,
int  x1,
int  y1,
bool  clear 
) [inline]

Returns number of bytes per pixel (1, 3, or 4).

Pixbuf initialisation using homegrown memory handling ("pixelstore").

Pixbuf sizes are differentiated into tiny, <4K, <16K, <64K, and more, with each type having its own method of memory handling. After allocating memory, the buffer is cleared if the clear flag is set. Intended to reduce memory fragmentation.

Parameters:
pb Pointer to the pixbuf struct.
mode Indicates grayscale/RGB/RGBA.
clear True if buffer should be cleared.
Precondition:
x1>=x0 && y1>=y0 && pb!=NULL

Definition at line 35 of file nr-pixblock.cpp.

Referenced by nr_pixblock_new_fast(), and sp_canvas_paint_single_buffer().

{
      int w, h, bpp;
      size_t size;

      w = x1 - x0;
      h = y1 - y0;
      bpp = (mode == NR_PIXBLOCK_MODE_A8) ? 1 : (mode == NR_PIXBLOCK_MODE_R8G8B8) ? 3 : 4;

      size = bpp * w * h;

      if (size <= NR_TINY_MAX) {
            pb->size = NR_PIXBLOCK_SIZE_TINY;
            if (clear) memset (pb->data.p, 0x0, size);
      } else if (size <= 4096) {
            pb->size = NR_PIXBLOCK_SIZE_4K;
            pb->data.px = nr_pixelstore_4K_new (clear, 0x0);
      } else if (size <= 16384) {
            pb->size = NR_PIXBLOCK_SIZE_16K;
            pb->data.px = nr_pixelstore_16K_new (clear, 0x0);
      } else if (size <= 65536) {
            pb->size = NR_PIXBLOCK_SIZE_64K;
            pb->data.px = nr_pixelstore_64K_new (clear, 0x0);
      } else if (size <= 262144) {
            pb->size = NR_PIXBLOCK_SIZE_256K;
            pb->data.px = nr_pixelstore_256K_new (clear, 0x0);
      } else if (size <= 1048576) {
            pb->size = NR_PIXBLOCK_SIZE_1M;
            pb->data.px = nr_pixelstore_1M_new (clear, 0x0);
      } else {
            pb->size = NR_PIXBLOCK_SIZE_BIG;
             pb->data.px = NULL;
            if (size > 100000000) { // Don't even try to allocate more than 100Mb (5000x5000 RGBA
                            // pixels). It'll just bog the system down even if successful. FIXME:
                            // Can anyone suggest something better than the magic number?
                g_warning ("%lu bytes requested for pixel buffer, I won't try to allocate that.", (long unsigned) size);
                return;
             }
            pb->data.px = g_try_new (unsigned char, size);
            if (pb->data.px == NULL) { // memory allocation failed
                g_warning ("Could not allocate %lu bytes for pixel buffer!", (long unsigned) size);
                return;
             }
            if (clear) memset (pb->data.px, 0x0, size);
      }

      pb->mode = mode;
      pb->empty = 1;
    pb->visible_area.x0 = pb->area.x0 = x0;
    pb->visible_area.y0 = pb->area.y0 = y0;
    pb->visible_area.x1 = pb->area.x1 = x1;
    pb->visible_area.y1 = pb->area.y1 = y1;
      pb->rs = bpp * w;
}


Generated by  Doxygen 1.6.0   Back to index