pixblock-scaler.cpp revision b4b6e9c6f7dca6891f586984f1b26f81c61174ba
#define __NR_PIXBLOCK_SCALER_CPP__
/*
* Functions for blitting pixblocks using scaling
*
* Author:
* Niko Kiirala <niko@kiirala.com>
*
* Copyright (C) 2006,2009 Niko Kiirala
*
* Released under GNU GPL, read the file 'COPYING' for more information
*/
#include <glib.h>
#include <cmath>
#include "round.h"
#endif
#include "display/nr-filter-utils.h"
#include "libnr/nr-pixblock.h"
namespace NR {
struct RGBA {
double r, g, b, a;
};
/** Calculates cubically interpolated value of the four given pixel values.
* The pixel values should be from four adjacent pixels in source image or
* four adjacent interpolated values. len should be the x- or y-coordinate
* (depending on interpolation direction) of the center of the target pixel
* in source image coordinates.
*/
__attribute__ ((const))
inline static double sample(double const a, double const b,
double const c, double const d,
double const len)
{
double const f = -0.5; // corresponds to cubic Hermite spline
double sum = 0;
return sum;
}
/**
* Sanity check function for indexing pixblocks.
* Catches reading and writing outside the pixblock area.
* When enabled, decreases filter rendering speed massively.
*/
{
if(false) {
}
}
{
g_warning("A non-32-bpp image passed to scale_bicubic_rgba: scaling aborted.");
return;
}
bool free_from_on_exit = false;
from = new NRPixBlock;
nr_pixblock_setup_fast(from, to->mode, o_from->area.x0, o_from->area.y0, o_from->area.x1, o_from->area.y1, false);
free_from_on_exit = true;
}
// Precalculate sizes of source and destination pixblocks
// from_step: when advancing one pixel in destination image,
// how much we should advance in source image
// Loop through every pixel of destination image, a line at a time
// Pre-calculate beginning of the four horizontal lines, from
// which we should read
int from_line[4];
for (int i = 0 ; i < 4 ; i++) {
if (fy_line >= 0) {
if (fy_line < from_height) {
} else {
}
} else {
from_line[i] = 0;
}
}
// Loop through this horizontal line in destination image
// For every pixel, calculate the color of pixel with
// bicubic interpolation and set the pixel value in destination image
for (int i = 0 ; i < 4 ; i++) {
if (k < 0) k = 0;
k *= 4;
from_y);
from_y);
from_y);
from_y);
}
from_x));
from_x));
from_x));
from_x));
/* Clamp the colour channels to range from 0 to result.a to
* make sure, we don't exceed 100% per colour channel with
* images that have premultiplied alpha */
} else {
}
}
}
if (free_from_on_exit) {
delete from;
}
}
{
g_warning("A non-8-bpp image passed to scale_bicubic_alpha: scaling aborted.");
return;
}
// Precalculate sizes of source and destination pixblocks
// from_step: when advancing one pixel in destination image,
// how much we should advance in source image
// Loop through every pixel of destination image, a line at a time
// Pre-calculate beginning of the four horizontal lines, from
// which we should read
int from_line[4];
for (int i = 0 ; i < 4 ; i++) {
if (fy_line >= 0) {
if (fy_line < from_height) {
} else {
}
} else {
from_line[i] = 0;
}
}
// Loop through this horizontal line in destination image
// For every pixel, calculate the color of pixel with
// bicubic interpolation and set the pixel value in destination image
double line[4];
for (int i = 0 ; i < 4 ; i++) {
if (k < 0) k = 0;
from_y);
}
int result;
from_x));
}
}
}
{
} else {
g_warning("NR::scale_bicubic: unsupported bitdepths for scaling: to %d, from %d", NR_PIXBLOCK_BPP(to), NR_PIXBLOCK_BPP(from));
}
}
} /* namespace NR */
/*
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 :