Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.
Posted 03 August 2005 - 09:36 PM
Posted 03 August 2005 - 10:01 PM
dx = 32 / 256;
dy = 32 / 128;
for(int y=0; y < 128; y++)
{
for(int x=0; x < 256; x++)
{
float ix = x*dx;
float iy = y*dy;
float s = ix - (float)((int)(ix+.5));
float t = iy - (float)((int)(iy+.5));
int ox = (int)ix;
int oy = (int)oy;
new_pic[y*256+x] = orig_pic[oy*32+ox]*(1-s)*(1-t)
+ orig_pic[(oy+1)*32+ox]*(1-s)*t
+ orig_pic[oy*32+ox+1]*s*(1-t)
+ orig_pic[(oy+1)*32+ox+1]*s*t;
}
}
Posted 03 August 2005 - 10:09 PM
Posted 04 August 2005 - 11:32 PM
[source lang ="cpp"]
//sample image up( powers of 2)
template<class U, class W> void samplebicubic(const U& s, W& d)
{
uint32 i,j;
int32 is,js,m,n;
float x,y,fact,dx,dy;
float test;
fact = U::MAP_SIZE/ W::MAP_SIZE;
for(i=0;i<W::MAP_SIZE;i++)
{
//calculate source coordinates
x = i * fact;
is = static_cast<int32>(x);
dx = x - is;
is = (is + W::MAP_SIZE)%W::MAP_SIZE;
for(j=0;j<W::MAP_SIZE;j++)
{
//calculate source coordinates
y = j * fact;
js = static_cast<int32>(y);
dy = y - js;
js = (js + W::MAP_SIZE)%W::MAP_SIZE;
d.m_Map[i][j] = 0.0f;
for(m=-1;m<3;m++)
{
for(n=-1;n<3;n++)
{
test = cubicweight(m-dx) * cubicweight(n-dy);
d.m_Map[i][j] += s.m_Map[(is + m + U::MAP_SIZE)%U::MAP_SIZE][(js + n + U::MAP_SIZE)%U::MAP_SIZE]
*test;
}
}
}
}
};
//cubic weight function
float cubicweight(float x)
{
float result;
float tmp;
//P(x+2)^3
tmp = (x+2)>0?x+2:0;
result = tmp*tmp*tmp;
//-4*P(x+1)^3
tmp = (x+1)>0?x+1:0;
result += -4*tmp*tmp*tmp;
//6*P(x)^3
tmp = x>0?x:0;
result += 6*tmp*tmp*tmp;
//-4P(x-1)^3
tmp = (x-1)>0?x-1:0;
result += -4*tmp*tmp*tmp;
result*=0.1666666f;
return result;
};
Posted 05 August 2005 - 04:59 PM
Posted 05 August 2005 - 05:54 PM
Posted 06 August 2005 - 08:58 AM
//sample image up( powers of 2)
template<class U, class W> void sample_bicubic2(const U& s, W& d)
{
uint32 i,j;
int32 is,js;
float x,y,fact,dx,dy;
int32 XCoords[4];
int32 YCoords[4];
float weights[4];
fact = static_cast<float>(U::MAP_SIZE)/ static_cast<float>(W::MAP_SIZE);
for(i=0;i<W::MAP_SIZE;i++)
{
//calculate source coordinates
x = i * fact;
is = static_cast<int32>(x);
dx = x - is;
XCoords[0] = is-1;
XCoords[1] = is;
XCoords[2] = is+1;
XCoords[3] = is+2;
for(j=0;j<W::MAP_SIZE;j++)
{
//calculate source coordinates
y = j * fact;
js = static_cast<int32>(y);
dy = y - js;
YCoords[0] = js-1;
YCoords[1] = js;
YCoords[2] = js+1;
YCoords[3] = js+2;
weights[0] = cubicweight2(
s.m_Map[(XCoords[0] + U::MAP_SIZE)%U::MAP_SIZE][(YCoords[0] + U::MAP_SIZE)%U::MAP_SIZE],
s.m_Map[(XCoords[0] + U::MAP_SIZE)%U::MAP_SIZE][(YCoords[1] + U::MAP_SIZE)%U::MAP_SIZE],
s.m_Map[(XCoords[0] + U::MAP_SIZE)%U::MAP_SIZE][(YCoords[2] + U::MAP_SIZE)%U::MAP_SIZE],
s.m_Map[(XCoords[0] + U::MAP_SIZE)%U::MAP_SIZE][(YCoords[3] + U::MAP_SIZE)%U::MAP_SIZE],
0.5f);
weights[1] = cubicweight2(
s.m_Map[(XCoords[1] + U::MAP_SIZE)%U::MAP_SIZE][(YCoords[0] + U::MAP_SIZE)%U::MAP_SIZE],
s.m_Map[(XCoords[1] + U::MAP_SIZE)%U::MAP_SIZE][(YCoords[1] + U::MAP_SIZE)%U::MAP_SIZE],
s.m_Map[(XCoords[1] + U::MAP_SIZE)%U::MAP_SIZE][(YCoords[2] + U::MAP_SIZE)%U::MAP_SIZE],
s.m_Map[(XCoords[1] + U::MAP_SIZE)%U::MAP_SIZE][(YCoords[3] + U::MAP_SIZE)%U::MAP_SIZE],
0.5f);
weights[2] = cubicweight2(
s.m_Map[(XCoords[2] + U::MAP_SIZE)%U::MAP_SIZE][(YCoords[0] + U::MAP_SIZE)%U::MAP_SIZE],
s.m_Map[(XCoords[2] + U::MAP_SIZE)%U::MAP_SIZE][(YCoords[1] + U::MAP_SIZE)%U::MAP_SIZE],
s.m_Map[(XCoords[2] + U::MAP_SIZE)%U::MAP_SIZE][(YCoords[2] + U::MAP_SIZE)%U::MAP_SIZE],
s.m_Map[(XCoords[2] + U::MAP_SIZE)%U::MAP_SIZE][(YCoords[3] + U::MAP_SIZE)%U::MAP_SIZE],
0.5f);
weights[3] = cubicweight2(
s.m_Map[(XCoords[3] + U::MAP_SIZE)%U::MAP_SIZE][(YCoords[0] + U::MAP_SIZE)%U::MAP_SIZE],
s.m_Map[(XCoords[3] + U::MAP_SIZE)%U::MAP_SIZE][(YCoords[1] + U::MAP_SIZE)%U::MAP_SIZE],
s.m_Map[(XCoords[3] + U::MAP_SIZE)%U::MAP_SIZE][(YCoords[2] + U::MAP_SIZE)%U::MAP_SIZE],
s.m_Map[(XCoords[3] + U::MAP_SIZE)%U::MAP_SIZE][(YCoords[3] + U::MAP_SIZE)%U::MAP_SIZE],
0.5f);
d.m_Map[i][j] = cubicweight2(weights[0],weights[1],weights[2],weights[3],0.5f);
}
}
};
//sample image up( powers of 2)
template<class U, class W> void sample_bicubic(const U& s, W& d)
{
uint32 i,j;
int32 is,js,m,n;
float x,y,fact,dx,dy;
float test;
fact = static_cast<float>(U::MAP_SIZE)/ static_cast<float>(W::MAP_SIZE);
for(i=0;i<W::MAP_SIZE;i++)
{
//calculate source coordinates
x = i * fact;
is = static_cast<int32>(x);
dx = x - is;
//is = (is + W::MAP_SIZE)%W::MAP_SIZE;
for(j=0;j<W::MAP_SIZE;j++)
{
//calculate source coordinates
y = j * fact;
js = static_cast<int32>(y);
dy = y - js;
//js = (js + W::MAP_SIZE)%W::MAP_SIZE;
d.m_Map[i][j] = 0.0f;
for(m=-1;m<3;m++)
{
test = cubicweight(dx-m);
for(n=-1;n<3;n++)
{
d.m_Map[i][j] += s.m_Map[(is + m + U::MAP_SIZE)%U::MAP_SIZE][(js + n + U::MAP_SIZE)%U::MAP_SIZE]
*test* cubicweight(dy-n);;
//std::cout<<std::endl;
}
}
}
}
};
//cubic weight function
float cubicweight(float x)
{
float result;
float tmp;
//P(x+2)^3
tmp = (x+2)>0?x+2:0;
result = tmp*tmp*tmp;
//-4*P(x+1)^3
tmp = (x+1)>0?x+1:0;
result += -4*tmp*tmp*tmp;
//6*P(x)^3
tmp = x>0?x:0;
result += 6*tmp*tmp*tmp;
//-4P(x-1)^3
tmp = (x-1)>0?x-1:0;
result += -4*tmp*tmp*tmp;
result*=0.1666666f;
return result;
};
Posted 06 August 2005 - 02:03 PM
Posted 06 August 2005 - 09:44 PM
Posted 07 August 2005 - 04:43 PM
// x,y coords for pixels in old and new images
float ox,oy;
int nx,ny;
// temp
pixel t[4];
dx = oldwidth / newwidth;
dy = oldheight / newheight;
for (ny = 0; ny < newheight; ++ny)
{
oy = ny * dy;
for (nx = 0; nx < newwidth; ++nx)
{
ox = nx * dx;
// ox.frac, oy.frac represent fractional portions of ox,oy
// i.e. for ox=4.15, ox.frac=0.15
// oimg, nimg are image buffers
t[0] = interpolate(oimg[ox - 1,oy - 1], oimg[ox,oy - 1], oimg[ox + 1,oy - 1], oimg[ox + 2,oy - 1], ox.frac);
t[1] = interpolate(oimg[ox - 1,oy], oimg[ox,oy], oimg[ox + 1,oy], oimg[ox + 2,oy], ox.frac);
t[2] = interpolate(oimg[ox - 1,oy + 1], oimg[ox,oy + 1], oimg[ox + 1,oy + 1], oimg[ox + 2,oy + 1], ox.frac);
t[3] = interpolate(oimg[ox - 1,oy + 2], oimg[ox,oy + 2], oimg[ox + 1,oy + 2], oimg[ox + 2,oy + 2], ox.frac);
nimg[nx,ny] = interpolate(t[0],t[1],t[2],[3], oy.frac);
[Edit]// Sorry, should have been interpolate() not cubic(), in case anyone else is looking at this.
}
}
pixel interpolate(pixel a,b,c,d, t)
{
return pixel(
cubic(a.r, b.r, c.r, d.r, t),
cubic(a.g, b.g, c.g, d.g, t),
cubic(a.b, b.b, c.b, d.b, t),
);
}
cubic(v0,v1,v2,v3, t)
{
int p = (v3 - v2) - (v0 - v1);
int q = (v0 - v1) - p;
int r = v2 - v0;
int s = v1;
float tSqrd = t * t;
return (p * (tSqrd * t)) + (q * tSqrd) + (r * t) + s;
}
Posted 07 August 2005 - 07:45 PM
Posted 08 August 2005 - 05:22 AM
Posted 12 October 2012 - 03:39 PM
---visit my game site http://www.boardspace.net - free online strategy games
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.
GameDev.net™, the GameDev.net logo, and GDNet™ are trademarks of GameDev.net, LLC.