mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-05-16 14:16:09 -06:00
reference: RescaleFilter
git-svn-id: svn://ultimatepp.org/upp/trunk@5985 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
parent
8c3c7c6de4
commit
9dccade252
6 changed files with 8372 additions and 0 deletions
4
reference/ColumnList/init
Normal file
4
reference/ColumnList/init
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
#ifndef _ColumnList_icpp_init_stub
|
||||
#define _ColumnList_icpp_init_stub
|
||||
#include "CtrlLib/init"
|
||||
#endif
|
||||
15
reference/RescaleFilter/RescaleFilter.upp
Normal file
15
reference/RescaleFilter/RescaleFilter.upp
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
optimize_speed;
|
||||
|
||||
uses
|
||||
CtrlLib,
|
||||
Painter,
|
||||
plugin/jpg,
|
||||
plugin/gif;
|
||||
|
||||
file
|
||||
main.cpp,
|
||||
image.iml;
|
||||
|
||||
mainconfig
|
||||
"" = "GUI SSE2";
|
||||
|
||||
91
reference/RescaleFilter/c.cpp
Normal file
91
reference/RescaleFilter/c.cpp
Normal file
|
|
@ -0,0 +1,91 @@
|
|||
#include "bicubic.h"
|
||||
|
||||
#if 1
|
||||
|
||||
#define LDUMP(x)
|
||||
|
||||
#define up(x) ((x) << 8)
|
||||
#define dn(x) ((x + (1 << 7)) >> 8)
|
||||
#define dn2(x) ((x + (1 << 15)) >> 16)
|
||||
|
||||
double BiCubicKernel3Imp(double x)
|
||||
{
|
||||
double r = 0;
|
||||
|
||||
double xp2 = x + 2;
|
||||
double xp1 = x + 1;
|
||||
double xm1 = x - 1;
|
||||
|
||||
if(xp2 > 0)
|
||||
r += xp2 * xp2 * xp2;
|
||||
if(xp1 > 0)
|
||||
r -= 4 * xp1 * xp1 * xp1;
|
||||
if(x > 0)
|
||||
r += 6 * x * x * x;
|
||||
if(xm1 > 0)
|
||||
r -= 4 * xm1 * xm1 * xm1;
|
||||
|
||||
return(r / 6.0);
|
||||
}
|
||||
|
||||
static int kernel[up(4)];
|
||||
|
||||
force_inline
|
||||
int BiCubicKernel3(int x)
|
||||
{
|
||||
x += up(2);
|
||||
ASSERT(x >= 0 && x <= up(4) + 1);
|
||||
return kernel[x];
|
||||
}
|
||||
|
||||
Image RescaleBicubic3(Image& img, int cx, int cy)
|
||||
{
|
||||
ONCELOCK {
|
||||
for(int i = 0; i < up(4); i++) {
|
||||
kernel[i] = int(up(1) * BiCubicKernel3Imp((double)i / up(1) - 2));
|
||||
}
|
||||
}
|
||||
Size isz = img.GetSize();
|
||||
ImageBuffer ib(cx, cy);
|
||||
RGBA *t = ~ib;
|
||||
for(int y = 0; y < cy; y++) {
|
||||
int sy = y * isz.cy / cy;
|
||||
int dy = up(y * isz.cy) / cy - up(sy);
|
||||
for(int x = 0; x < cx; x++) {
|
||||
int sx = x * isz.cx / cx;
|
||||
int dx = up(x * isz.cx) / cx - up(sx);
|
||||
int red = 0;
|
||||
int green = 0;
|
||||
int blue = 0;
|
||||
int alpha = 0;
|
||||
int w = 0;
|
||||
for(int yy = -1; yy <= 2; yy++) {
|
||||
int ky = BiCubicKernel3(up(yy) - dy);
|
||||
const RGBA *l = img[minmax(sy + yy, 0, isz.cy - 1)];
|
||||
for(int xx = -1; xx <= 2; xx++) {
|
||||
const RGBA& s = l[minmax(sx + xx, 0, isz.cx - 1)];
|
||||
int weight = ky * BiCubicKernel3(up(xx) - dx);
|
||||
LDUMP(weight);
|
||||
red += weight * s.r;
|
||||
green += weight * s.g;
|
||||
blue += weight * s.b;
|
||||
LDUMP((int)s.a);
|
||||
alpha += weight * s.a;
|
||||
LDUMP(alpha);
|
||||
w += weight;
|
||||
}
|
||||
}
|
||||
t->r = dn2(red);
|
||||
t->g = dn2(green);
|
||||
t->b = dn2(blue);
|
||||
t->a = dn2(alpha);
|
||||
LDUMP((int)t->a);
|
||||
LDUMP(w);
|
||||
// return ib;
|
||||
t++;
|
||||
}
|
||||
}
|
||||
return ib;
|
||||
}
|
||||
|
||||
#endif
|
||||
8181
reference/RescaleFilter/image.iml
Normal file
8181
reference/RescaleFilter/image.iml
Normal file
File diff suppressed because it is too large
Load diff
7
reference/RescaleFilter/init
Normal file
7
reference/RescaleFilter/init
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
#ifndef _RescaleFilter_icpp_init_stub
|
||||
#define _RescaleFilter_icpp_init_stub
|
||||
#include "CtrlLib/init"
|
||||
#include "Painter/init"
|
||||
#include "plugin/jpg/init"
|
||||
#include "plugin/gif/init"
|
||||
#endif
|
||||
74
reference/RescaleFilter/main.cpp
Normal file
74
reference/RescaleFilter/main.cpp
Normal file
|
|
@ -0,0 +1,74 @@
|
|||
#include <CtrlLib/CtrlLib.h>
|
||||
|
||||
using namespace Upp;
|
||||
|
||||
#define IMAGECLASS TestImg
|
||||
#define IMAGEFILE <RescaleFilter/image.iml>
|
||||
#include <Draw/iml_header.h>
|
||||
|
||||
#define IMAGECLASS TestImg
|
||||
#define IMAGEFILE <RescaleFilter/image.iml>
|
||||
#include <Draw/iml_source.h>
|
||||
|
||||
struct MyApp : TopWindow {
|
||||
typedef MyApp CLASSNAME;
|
||||
|
||||
DropList method;
|
||||
|
||||
void Paint(Draw& w) {
|
||||
w.DrawRect(GetSize(), LtGray());
|
||||
|
||||
int m = ~method;
|
||||
|
||||
TimeStop tm;
|
||||
|
||||
for(int i = 0; i < TestImg().GetCount(); i++) {
|
||||
Image img = TestImg().Get(i);
|
||||
int x = 260 * i;
|
||||
w.DrawImage(x, 0, img);
|
||||
w.DrawImage(x, 200, RescaleFilter(img, 84, 84, m));
|
||||
w.DrawImage(x + 94, 200, RescaleFilter(img, 42, 42, m));
|
||||
w.DrawImage(x + 94 + 52, 200, RescaleFilter(img, 21, 21, m));
|
||||
w.DrawImage(x + 94 + 52 + 31, 200, RescaleFilter(img, 10, 10, m));
|
||||
w.DrawImage(x + 94 + 52 + 31 + 20, 200, RescaleFilter(img, 5, 5, m));
|
||||
w.DrawImage(x + 94 + 52 + 31 + 20 + 15, 200, RescaleFilter(img, 2, 2, m));
|
||||
w.DrawImage(x + 94 + 52 + 31 + 20 + 15 + 12, 200, RescaleFilter(img, 1, 1, m));
|
||||
w.DrawImage(x, 300, RescaleFilter(img, 250, 250, m));
|
||||
w.DrawImage(x, 600, RescaleFilter(img, Size(250, 250), RectC(40, 40, 100, 100), m));
|
||||
}
|
||||
|
||||
w.DrawText(GetSize().cx - 200, 40, String().Cat() << "Elapsed " << tm << "s");
|
||||
}
|
||||
|
||||
void Sync()
|
||||
{
|
||||
Refresh();
|
||||
}
|
||||
|
||||
MyApp() {
|
||||
SetRect(0, 0, 600, 800);
|
||||
Sizeable();
|
||||
|
||||
method.Add(FILTER_NEAREST, "Nearest");
|
||||
method.Add(FILTER_BILINEAR, "Bilinear");
|
||||
method.Add(FILTER_BSPLINE, "Bspline");
|
||||
method.Add(FILTER_COSTELLO, "Costello");
|
||||
method.Add(FILTER_BICUBIC_MITCHELL, "Bicubic Mitchell");
|
||||
method.Add(FILTER_BICUBIC_CATMULLROM, "Bicubic Catmull Rom");
|
||||
method.Add(FILTER_LANCZOS2, "Lanczos 2");
|
||||
method.Add(FILTER_LANCZOS3, "Lanczos 3");
|
||||
method.Add(FILTER_LANCZOS4, "Lanczos 4");
|
||||
method.Add(FILTER_LANCZOS5, "Lanczos 5");
|
||||
method <<= THISBACK(Sync);
|
||||
Add(method.TopPos(0, STDSIZE).RightPos(0, 200));
|
||||
method <<= FILTER_NEAREST;;
|
||||
|
||||
Zoomable();
|
||||
Maximize();
|
||||
}
|
||||
};
|
||||
|
||||
GUI_APP_MAIN
|
||||
{
|
||||
MyApp().Run();
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue