nr-pixblock.cpp revision b8346b59f65f93ecaece3be77f5faae8c642810b
#define __NR_PIXBLOCK_C__
/** \file
* \brief Allocation/Setup of NRPixBlock objects. Pixel store functions.
*
* Authors:
* (C) 1999-2002 Lauris Kaplinski <lauris@kaplinski.com>
* 2008, Jasper van de Gronde <th.v.d.gonde@hccnet.nl>
*
* This code is in the Public Domain
*/
#include <cstring>
#include <string>
#include <string.h>
#include "nr-pixblock.h"
/// Size of buffer that needs no allocation (default 4).
#define NR_TINY_MAX sizeof (unsigned char *)
/**
* 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.
* \param pb Pointer to the pixbuf struct.
* \param clear True if buffer should be cleared.
* \pre x1>=x0 && y1>=y0 && pb!=NULL
*/
void
nr_pixblock_setup_fast (NRPixBlock *pb, NR_PIXBLOCK_MODE mode, int x0, int y0, int x1, int y1, bool clear)
{
int w, h, bpp;
if (size <= NR_TINY_MAX) {
} else if (size <= 4096) {
} else if (size <= 16384) {
} else if (size <= 65536) {
} else if (size <= 262144) {
} else if (size <= 1048576) {
} else {
// 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;
}
return;
}
}
}
/**
* Pixbuf initialisation using g_new.
*
* After allocating memory, the buffer is cleared if the clear flag is set.
* \param pb Pointer to the pixbuf struct.
* \param clear True if buffer should be cleared.
* \pre x1>=x0 && y1>=y0 && pb!=NULL
FIXME: currently unused except for nr_pixblock_new and pattern tiles, replace with _fast and delete?
*/
void
nr_pixblock_setup (NRPixBlock *pb, NR_PIXBLOCK_MODE mode, int x0, int y0, int x1, int y1, bool clear)
{
int w, h, bpp;
if (size <= NR_TINY_MAX) {
} else {
}
}
/**
* Pixbuf initialisation with preset values.
*
* After copying all parameters into the NRPixBlock struct, the pixel buffer is cleared if the clear flag is set.
* \param pb Pointer to the pixbuf struct.
* \param clear True if buffer should be cleared.
* \pre x1>=x0 && y1>=y0 && pb!=NULL
*/
void
nr_pixblock_setup_extern (NRPixBlock *pb, NR_PIXBLOCK_MODE mode, int x0, int y0, int x1, int y1, unsigned char *px, int rs, bool empty, bool clear)
{
int w, bpp;
if (clear) {
/// \todo How do you recognise if
/// px was an uncleared tiny buffer?
} else {
int y;
}
}
}
}
/**
* Frees memory taken by pixel data in NRPixBlock.
* \param pb Pointer to pixblock.
* \pre pb and pb->data.px point to valid addresses.
*
* According to pb->size, one of the functions for freeing the pixelstore
* is called. May be called regardless of how pixbuf was set up.
*/
void
{
case NR_PIXBLOCK_SIZE_TINY:
break;
case NR_PIXBLOCK_SIZE_4K:
break;
case NR_PIXBLOCK_SIZE_16K:
break;
case NR_PIXBLOCK_SIZE_64K:
break;
case NR_PIXBLOCK_SIZE_256K:
break;
case NR_PIXBLOCK_SIZE_1M:
break;
case NR_PIXBLOCK_SIZE_BIG:
break;
case NR_PIXBLOCK_SIZE_STATIC:
break;
default:
break;
}
}
/**
* Allocates NRPixBlock and sets it up.
*
* \return Pointer to fresh pixblock.
* Calls g_new() and nr_pixblock_setup().
FIXME: currently unused, delete? JG: Should be used more often! (To simplify memory management.)
*/
{
NRPixBlock *pb;
if (!pb) return 0;
return 0;
}
return pb;
}
/**
* Allocates NRPixBlock and sets it up.
*
* \return Pointer to fresh pixblock.
* Calls g_new() and nr_pixblock_setup().
*/
{
NRPixBlock *pb;
if (!pb) return 0;
return 0;
}
return pb;
}
/**
* Frees all memory taken by pixblock.
*
* \return NULL
*/
{
return NULL;
}
/* PixelStore operations */
#define NR_4K_BLOCK 32
static unsigned int nr_4K_len = 0;
static unsigned int nr_4K_size = 0;
unsigned char *
{
unsigned char *px;
if (nr_4K_len != 0) {
nr_4K_len -= 1;
} else {
}
return px;
}
void
nr_pixelstore_4K_free (unsigned char *px)
{
if (nr_4K_len == nr_4K_size) {
}
nr_4K_len += 1;
}
#define NR_16K_BLOCK 32
static unsigned int nr_16K_len = 0;
static unsigned int nr_16K_size = 0;
unsigned char *
{
unsigned char *px;
if (nr_16K_len != 0) {
nr_16K_len -= 1;
} else {
}
return px;
}
void
nr_pixelstore_16K_free (unsigned char *px)
{
if (nr_16K_len == nr_16K_size) {
}
nr_16K_len += 1;
}
#define NR_64K_BLOCK 32
static unsigned int nr_64K_len = 0;
static unsigned int nr_64K_size = 0;
unsigned char *
{
unsigned char *px;
if (nr_64K_len != 0) {
nr_64K_len -= 1;
} else {
}
return px;
}
void
nr_pixelstore_64K_free (unsigned char *px)
{
if (nr_64K_len == nr_64K_size) {
}
nr_64K_len += 1;
}
#define NR_256K_BLOCK 32
#define NR_256K 262144
static unsigned char **nr_256K_px = NULL;
static unsigned int nr_256K_len = 0;
static unsigned int nr_256K_size = 0;
unsigned char *
{
unsigned char *px;
if (nr_256K_len != 0) {
nr_256K_len -= 1;
} else {
}
return px;
}
void
nr_pixelstore_256K_free (unsigned char *px)
{
if (nr_256K_len == nr_256K_size) {
}
nr_256K_len += 1;
}
#define NR_1M_BLOCK 32
#define NR_1M 1048576
static unsigned int nr_1M_len = 0;
static unsigned int nr_1M_size = 0;
unsigned char *
{
unsigned char *px;
if (nr_1M_len != 0) {
nr_1M_len -= 1;
} else {
}
return px;
}
void
nr_pixelstore_1M_free (unsigned char *px)
{
if (nr_1M_len == nr_1M_size) {
}
nr_1M_len += 1;
}
/*
Local Variables:
mode:c++
c-file-style:"stroustrup"
c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
indent-tabs-mode:nil
fill-column:99
End:
*/
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :