pixblock-scaler.cpp revision c6843f4373787d9ec7987e26edaaea04a0996cbf
#define __NR_PIXBLOCK_SCALER_CPP__
/*
* Functions for blitting pixblocks using scaling
*
* Author:
* Niko Kiirala <niko@kiirala.com>
*
* Copyright (C) 2006 Niko Kiirala
*
* Released under GNU GPL, read the file 'COPYING' for more information
*/
#include <glib.h>
#include <cmath>
#include "display/nr-filter-utils.h"
#include "libnr/nr-pixblock.h"
namespace NR {
struct RGBA {
int r, g, b, a;
};
/** Calculates cubically interpolated value of the four given pixel values.
* The pixel values should be from four vertically adjacent pixels.
* If we are calculating a pixel, whose y-coordinate in source image is
* i, these pixel values a, b, c and d should come from lines
* floor(i) - 1, floor(i), floor(i) + 1, floor(i) + 2, respectively.
* Parameter len should be set to i.
* Returns the interpolated value in fixed point format with 8 bit
* decimal part. (24.8 assuming 32-bit int)
*/
__attribute__ ((const))
inline static int sampley(unsigned const char a, unsigned const char b,
unsigned const char c, unsigned const char d,
const double len)
{
int sum = 0;
* lenf * 256 * a);
* 256 * b);
return sum;
}
/** Calculates cubically interpolated value of the four given pixel values.
* The pixel values should be interpolated values from sampley, from four
* horizontally adjacent vertical lines. The parameters a, b, c and d
* should be in fixed point format with 8-bit decimal part.
* If we are calculating a pixel, whose x-coordinate in source image is
* i, these vertical lines from where a, b, c and d are calculated, should be
* floor(i) - 1, floor(i), floor(i) + 1, floor(i) + 2, respectively.
* Parameter len should be set to i.
* Returns the interpolated value in 8-bit format, ready to be written
* to output buffer.
*/
int sum = 0;
//if (sum < 0) sum = 0;
//if (sum > 255 * 256) sum = 255 * 256;
return sum / 256;
}
/**
* 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++) {
} 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++) {
} 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
int 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 :