nr-gradient.cpp revision a4030d5ca449e7e384bc699cd249ee704faaeab0
#define __NR_GRADIENT_C__
/*
* Pixel buffer rendering library
*
* Authors:
* Lauris Kaplinski <lauris@kaplinski.com>
* MenTaLguY <mental@rydia.net>
*...Jasper van de Gronde <th.v.d.gronde@hccnet.nl>
*
* Copyright (C) 2009 Jasper van de Gronde
* Copyright (C) 2007 MenTaLguY
* Copyright (C) 2001-2002 Lauris Kaplinski
* Copyright (C) 2001-2002 Ximian, Inc.
*
* Released under GNU GPL, read the file 'COPYING' for more information
*/
/*
* Derived in part from public domain code by Lauris Kaplinski
*/
#include <cstring>
#include <libnr/nr-pixops.h>
#include <libnr/nr-pixblock-pixel.h>
#include <libnr/nr-gradient.h>
#include <libnr/nr-matrix-ops.h>
#include <stdio.h>
/* Common */
namespace {
inline unsigned char const *vector_index(int idx,
unsigned char const *vector)
{
}
template <>
struct Spread<NR_GRADIENT_SPREAD_PAD> {
}
unsigned char const *vector)
{
//return vector_index((int)CLAMP(r, 0, (double)(NR_GRADIENT_VECTOR_LENGTH - 1)), vector);
}
};
template <>
struct Spread<NR_GRADIENT_SPREAD_REPEAT> {
}
unsigned char const *vector)
{
//return vector_index((int)((long long)r & NRG_MASK), vector);
}
};
template <>
struct Spread<NR_GRADIENT_SPREAD_REFLECT> {
return r;
}
unsigned char const *vector)
{
//int idx = (int) ((long long)r & NRG_2MASK);
//if (idx > NRG_MASK) idx = NRG_2MASK - idx;
//return vector_index(idx, vector);
}
};
template <>
struct ModeTraits<NR_PIXBLOCK_MODE_R8G8B8A8N> {
static const unsigned bpp=4;
};
template <>
struct ModeTraits<NR_PIXBLOCK_MODE_R8G8B8A8P> {
static const unsigned bpp=4;
};
template <>
struct ModeTraits<NR_PIXBLOCK_MODE_R8G8B8> {
static const unsigned bpp=3;
};
template <>
struct ModeTraits<NR_PIXBLOCK_MODE_A8> {
static const unsigned bpp=1;
};
struct Compose {
{
}
};
template <>
struct Compose<NR_PIXBLOCK_MODE_R8G8B8A8N, true> {
static const unsigned bpp=4;
{
}
};
template <>
struct Compose<NR_PIXBLOCK_MODE_R8G8B8A8P, true> {
static const unsigned bpp=4;
{
}
};
template <>
struct Compose<NR_PIXBLOCK_MODE_R8G8B8, true> {
static const unsigned bpp=3;
{
}
};
template <>
struct Compose<NR_PIXBLOCK_MODE_A8, true> {
static const unsigned bpp=1;
{
}
};
template <>
struct Compose<NR_PIXBLOCK_MODE_R8G8B8A8N, false> {
static const unsigned bpp=4;
{
unsigned int ca;
}
};
template <>
struct Compose<NR_PIXBLOCK_MODE_R8G8B8A8P, false> {
static const unsigned bpp=4;
{
}
};
template <>
struct Compose<NR_PIXBLOCK_MODE_R8G8B8, false> {
static const unsigned bpp=3;
{
}
};
static void
{
} else {
}
break;
} else {
}
break;
case NR_PIXBLOCK_MODE_R8G8B8:
} else {
}
break;
case NR_PIXBLOCK_MODE_A8:
} else {
}
break;
}
}
template <typename Subtype>
static void
{
break;
break;
case NR_GRADIENT_SPREAD_PAD:
default:
}
}
}
/* Linear */
namespace {
struct Linear {
int x, y;
unsigned char *d;
double pos;
0, 0, NR_GRADIENT_VECTOR_LENGTH, 1,
4 * NR_GRADIENT_VECTOR_LENGTH, 0, 0);
for (y = 0; y < height; y++) {
for (x = 0; x < width; x++) {
}
}
}
};
}
const unsigned char *cv,
unsigned int spread,
{
lgr->x0 = n2px[4] - 0.5; // These -0.5 offsets make sure that the gradient is sampled in the MIDDLE of each pixel.
return (NRRenderer *) lgr;
}
/* Radial */
/*
* The archetype is following
*
* gx gy - pixel coordinates
* Px Py - coordinates, where Fx Fy - gx gy line intersects with circle
*
* (1) (gx - fx) * (Py - fy) = (gy - fy) * (Px - fx)
* (2) (Px - cx) * (Px - cx) + (Py - cy) * (Py - cy) = r * r
*
* (3) Py = (Px - fx) * (gy - fy) / (gx - fx) + fy
* (4) (gy - fy) / (gx - fx) = D
* (5) Py = D * Px - D * fx + fy
*
* (6) D * fx - fy + cy = N
* (7) Px * Px - 2 * Px * cx + cx * cx + (D * Px) * (D * Px) - 2 * (D * Px) * N + N * N = r * r
* (8) (D * D + 1) * (Px * Px) - 2 * (cx + D * N) * Px + cx * cx + N * N = r * r
*
* (9) A = D * D + 1
* (10) B = -2 * (cx + D * N)
* (11) C = cx * cx + N * N - r * r
*
* (12) Px = (-B +- SQRT(B * B - 4 * A * C)) / 2 * A
*/
namespace {
struct SymmetricRadial {
{
0, 0, NR_GRADIENT_VECTOR_LENGTH, 1,
0, 0);
}
}
}
};
struct Radial {
{
0, 0, NR_GRADIENT_VECTOR_LENGTH, 1,
0, 0);
/* INVARIANT: qgx2_4 >= 0.0 */
/* qgx2_4 = MAX(qgx2_4, 0.0); */
/* We can safely divide by 0 here */
/* If we are sure pxgx cannot be -0 */
unsigned char const *s;
} else {
}
}
}
}
};
}
unsigned char const *cv,
unsigned spread,
float r)
{
if (r < NR_EPSILON) {
rgr->px2gs[4] += 0.5*(rgr->px2gs[0]+rgr->px2gs[2]); // These offsets make sure the gradient is sampled in the MIDDLE of each pixel
rgr->r = 1.0;
} else {
if (df >= r) {
}
rgr->px2gs[4] += 0.5*(rgr->px2gs[0]+rgr->px2gs[2]); // These offsets make sure the gradient is sampled in the MIDDLE of each pixel
/* INVARIANT: C < 0 */
}
return (NRRenderer *) rgr;
}
static void
{
}
/*
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:fileencoding=utf-8:textwidth=99 :