git-svn-id: svn://ultimatepp.org/upp/trunk@5979 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
cxl 2013-04-13 07:41:06 +00:00
parent 49673b4a7b
commit 0fc604309b
11 changed files with 3906 additions and 577 deletions

File diff suppressed because it is too large Load diff

2400
uppdev/AccessKey/h.iml.$tmp Normal file

File diff suppressed because it is too large Load diff

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.8 KiB

After

Width:  |  Height:  |  Size: 2.8 KiB

Before After
Before After

View file

@ -0,0 +1,18 @@
optimize_speed;
uses
CtrlLib,
Painter,
plugin/jpg;
file
bicubic.h,
a.cpp,
b.cpp,
c.cpp,
d.cpp,
main.cpp;
mainconfig
"" = "GUI SSE2";

79
uppdev/BiCubic/a.cpp Normal file
View file

@ -0,0 +1,79 @@
#include "bicubic.h"
#if 0
double BiCubicR(double x)
{
double xp2,xp1,xm1;
double r = 0;
xp2 = x + 2;
xp1 = x + 1;
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);
}
void BiCubicScale(const RGBA *bm_in, int nx, int ny,
RGBA *bm_out, int nnx, int nny)
{
int i_out,j_out,i_in,j_in,ii,jj;
int n,m;
long index;
double cx,cy,dx,dy,weight;
double red,green,blue,alpha;
RGBA col;
for (i_out=0;i_out<nnx;i_out++) {
for (j_out=0;j_out<nny;j_out++) {
i_in = (i_out * nx) / nnx;
j_in = (j_out * ny) / nny;
cx = i_out * nx / (double)nnx;
cy = j_out * ny / (double)nny;
dx = cx - i_in;
dy = cy - j_in;
red = 0;
green = 0;
blue = 0;
alpha = 0;
for (m=-1;m<=2;m++) {
for (n=-1;n<=2;n++) {
ii = i_in + m;
jj = j_in + n;
if (ii < 0) ii = 0;
if (ii >= nx) ii = nx-1;
if (jj < 0) jj = 0;
if (jj >= ny) jj = ny-1;
index = jj * nx + ii;
weight = BiCubicR(m-dx) * BiCubicR(n-dy);
red += weight * bm_in[index].r;
green += weight * bm_in[index].g;
blue += weight * bm_in[index].b;
alpha += weight * bm_in[index].a;
}
}
col.r = (int)red;
col.g = (int)green;
col.b = (int)blue;
col.a = (int)alpha;
bm_out[j_out * nnx + i_out] = col;
}
}
}
Image RescaleBicubic(Image& img, int cx, int cy)
{
ImageBuffer ib(cx, cy);
BiCubicScale(~img, img.GetWidth(), img.GetHeight(), ~ib, cx, cy);
return ib;
}
#endif

75
uppdev/BiCubic/b.cpp Normal file
View file

@ -0,0 +1,75 @@
#include "bicubic.h"
#if 1
double BiCubicKernel2(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 (1 / 6.0) * r;
}
double MagicKernel(double x)
{
x = abs(x);
return x > 1.3 ? 0 : 1.5 - x;
}
double Kernel(double x)
{
return MagicKernel(x);
}
Image RescaleBicubic2(Image& img, int cx, int cy)
{
Size isz = img.GetSize();
ImageBuffer ib(cx, cy);
RGBA *t = ~ib;
double inv_cx = 1.0 / cx;
for(int y = 0; y < cy; y++) {
int sy = (y * isz.cy) / cy;
double dy = y * isz.cy / (double)cy - sy;
for(int x = 0; x < cx; x++) {
int sx = (x * isz.cx) / cx;
double dx = x * isz.cx * inv_cx - sx;
double red = 0;
double green = 0;
double blue = 0;
double alpha = 0;
double w = 0;
for(int yy = -2; yy <= 2; yy++) {
double ky = Kernel(yy - dy);
const RGBA *l = img[minmax(sy + yy, 0, isz.cy - 1)];
for(int xx = -2; xx <= 2; xx++) {
const RGBA& s = l[minmax(sx + xx, 0, isz.cx - 1)];
// double weight = ky * BiCubicKernel2(xx - dx);
double weight = ky * Kernel(xx - dx);
red += weight * s.r;
green += weight * s.g;
blue += weight * s.b;
alpha += weight * s.a;
w += weight;
}
}
t->r = (int)(red / w);
t->g = (int)(green / w);
t->b = (int)(blue / w);
t->a = (int)(alpha / w);
t++;
}
}
return ib;
}
#endif

8
uppdev/BiCubic/bicubic.h Normal file
View file

@ -0,0 +1,8 @@
#include <CtrlLib/CtrlLib.h>
#include <Painter/Painter.h>
using namespace Upp;
Image RescaleBicubic2(Image& img, int cx, int cy);
Image RescaleBicubic3(Image& img, int cx, int cy);
Image RescaleBicubic4(Image& img, int cx, int cy);

91
uppdev/BiCubic/c.cpp Normal file
View 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

91
uppdev/BiCubic/d.cpp Normal file
View file

@ -0,0 +1,91 @@
#include "bicubic.h"
#if 1
#define LDUMP(x) DUMP(x)
#define up(x) ((x) << 8)
#define dn(x) ((x + (1 << 7)) >> 8)
#define dn2(x) ((x + (1 << 15)) >> 16)
double BiCubicKernel4Imp(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 BiCubicKernel4(int x)
{
x += up(2);
ASSERT(x >= 0 && x <= up(4) + 1);
return kernel[x];
}
Image RescaleBicubic4(Image& img, int cx, int cy)
{
ONCELOCK {
for(int i = 0; i < up(4); i++) {
kernel[i] = int(up(1) * BiCubicKernel4Imp((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 = BiCubicKernel4(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 * BiCubicKernel4(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 = red / w;
t->g = green / w;
t->b = blue / w;
t->a = alpha / w;
LDUMP((int)t->a);
LDUMP(w);
return ib;
t++;
}
}
return ib;
}
#endif

6
uppdev/BiCubic/init Normal file
View file

@ -0,0 +1,6 @@
#ifndef _BiCubic_icpp_init_stub
#define _BiCubic_icpp_init_stub
#include "CtrlLib/init"
#include "Painter/init"
#include "plugin/jpg/init"
#endif

73
uppdev/BiCubic/main.cpp Normal file
View file

@ -0,0 +1,73 @@
#include "bicubic.h"
Image img;
Image Rescale2(const Image& m, int cx, int cy)
{
ImagePainter iw(cx, cy);
iw.RectPath(0, 0, cx, cy);
double sw = (double)cx / m.GetWidth();
double sh = (double)cy / m.GetHeight();
iw.Fill(m, Xform2D::Scale(sw, sh)/* * Xform2D::Translation(x - sw * src.left, y - sh * src.top)*/,
FILL_EXACT);
return iw;
}
struct MyApp : TopWindow {
typedef MyApp CLASSNAME;
void Paint(Draw& w) {
w.DrawRect(GetSize(), LtGray());
// w.DrawImage(0, 0, Rescale(img, GetSize()));
w.DrawImage(0, 0, Rescale(img, 480, 84));
w.DrawImage(0, 100, Rescale2(img, 480, 84));
w.DrawImage(0, 200, RescaleBicubic2(img, 480, 84));
// w.DrawImage(0, 300, RescaleBicubic(img, Size(480, 84), Rect(img.GetSize()).Deflated(20)));
w.DrawImage(0, 300, RescaleBicubic3(img, 480, 84));
w.DrawImage(0, 400, RescaleBicubic4(img, 480, 84));
// for(int i = 1; i < 5; i++)
// w.DrawImage(0, 200 + 100 * i, RescaleBicubic(img, 480 / (i + 3), 84 / (i + 3)));
// w.DrawImage(0, 400, RescaleBicubic3(img, 480, 84));
}
MyApp() {
SetRect(0, 0, 600, 800);
Sizeable();
}
};
GUI_APP_MAIN
{
img = StreamRaster::LoadFileAny("c:/xxx/202728.jpg");
MyApp().Run();
#ifndef _DEBUG
for(int i = 0; i < 10; i++) {
{
RTIMING("Rescale");
Rescale(img, 480, 84);
}
{
RTIMING("Rescale2");
Rescale2(img, 480, 84);
}
{
RTIMING("RescaleBicubic");
RescaleBicubic(img, 480, 84);
}
{
RTIMING("RescaleBicubic2");
RescaleBicubic2(img, 480, 84);
}
{
RTIMING("RescaleBicubic3");
RescaleBicubic3(img, 480, 84);
}
{
RTIMING("RescaleBicubic4");
RescaleBicubic3(img, 480, 84);
}
}
#endif
}