boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - 我最近写的一个屏保程序
相关主题
recurvion真的很难懂~~
C++里有没有实现interpolation的函数?
问个overloading new operator的问题
缩小图象的程序
问个小问题
一个关于assignment constructor和expection的问题
Extrapolation in Python?
请教 一个matlab画图的问题
[合集] 我也花了一小时读了一下python
如何用’sed‘ comment out 某一行。
相关话题的讨论汇总
话题: mpcubic话题: double话题: unsigned话题: set
进入Programming版参与讨论
1 (共1页)
O*******d
发帖数: 20343
1
基本上是一个slide show。 把计算机产生的图像一幅一幅显示。 图像的产生用当时的
时间做seed,基本上永远不会有重复的图像。 图像做了antialiase处理,效果很好。
图像是Perlin Noise, 计算时充分利用多核处理器平行处理。我自己做的antialiase
和颜色混合。 对显卡没有严格要求,只要能显示24bit的颜色即可。 启动时有一个5
秒的busy动画。 按空格键就可以把图像存成一个jpg文件。 下边是存的一部分图像。
下载网址
http://www.mediafire.com/?6b016jn01ku27b1
o****e
发帖数: 916
2
cool! i really wish i have this kind of skill on graphic design. there is a
big step between making a software useful and a software user wants/like to
use
z****e
发帖数: 2024
3
师傅们越来越精进了!
b******n
发帖数: 592
4
Looks very nice. reminds the old good time of programming. If you love this
kind of stuff, try to google demo.


antialiase
5

【在 O*******d 的大作中提到】
: 基本上是一个slide show。 把计算机产生的图像一幅一幅显示。 图像的产生用当时的
: 时间做seed,基本上永远不会有重复的图像。 图像做了antialiase处理,效果很好。
: 图像是Perlin Noise, 计算时充分利用多核处理器平行处理。我自己做的antialiase
: 和颜色混合。 对显卡没有严格要求,只要能显示24bit的颜色即可。 启动时有一个5
: 秒的busy动画。 按空格键就可以把图像存成一个jpg文件。 下边是存的一部分图像。
: 下载网址
: http://www.mediafire.com/?6b016jn01ku27b1

O*******d
发帖数: 20343
5
说一下我怎么做的antialiase。 先把图形计算好,比最后的图像多出宽三列高三行。
图形是一个浮点数的点阵。 两个相邻的点之间的距离是一个单位。 然后用三次方程插
值。每个插值要用图形中4X4的值来计算。 在四个点组成的方格中均匀插入5X5=25个点
(单核机)或7X7=49个点(多核机),给每个插值赋予颜色,最后把一个方格中所有的
颜色平均,就是一个像素的颜色。
由于一组插值用的是同一套三次方程系数,所以写了一个class来做。 其实是一个
template。 做插值时,有两个套着的循环,分别在X方向移动和Y方向移动。 内循环是
在Y方向从上往下移动,这样每次移动一步,只需要计算最后一列的三次方程系数。下
边是我写的Cubic Interpolator. 是一个recursive template。For bicubic
interpolation, N = 2. 所有的重复计算都尽可能的避免了。 这个templete的计算
速度,在N==2时,是单独bicubic interpolation的速度的三倍。
template
class CubicInterpolator
{
public:
CubicInterpolator();
CubicInterpolator(const double *p);
void Set(const double *p);
void MoveDown(const double *p);

double Interpolate(const double * coordinates);

private:
double mPath[N - 1]; // Path is like {x, y, z}
double mArr[4]; // Working buffer
CubicInterpolator<1U> mCubic; // Object which holds coefficients of
a cubic function.
CubicInterpolator * mpCubic[4]; // Array of pointer for
rearranging sub objects
// SKIPs are for distance between first dimension elements in a
4x4x4... array.
// For N == 2, the distance is 4 in a 4x4 array. For N == 3, the
distance is 16 in a 4x4x4 array
// All these settings are based on assumption that row major multi
dimensional array is used.
enum
{
SKIP1 = 1 << (N - 1) * 2,
SKIP2 = SKIP1 * 2,
SKIP3 = SKIP1 * 3,
};
// Recursive template. Should have a terminal to end it, or
compiler will stop in a recursive build.
// The terminal template is CubicInterpolator<1U> in this
implementation.
CubicInterpolator m0;
CubicInterpolator m1;
CubicInterpolator m2;
CubicInterpolator m3;
};
/***************************************************************************
**
* Description: Parameterless Constructor
*
***************************************************************************
*/
template
CubicInterpolator::CubicInterpolator()
{
// coordinates are usually between 0.0 and 1.0. Set to a very large
// number so it will not match any practical number.
mPath[0] = 1.0E100;
mpCubic[0] = &m0;
mpCubic[1] = &m1;
mpCubic[2] = &m2;
mpCubic[3] = &m3;
}
/***************************************************************************
**
* Description: Constructor
*
* Parameters: p, Address of the first element of an N dimensional array
containing original data. Each dimension has 4 elements.
For example a[4][4] for N = 2. The elements in each
dimension
has range -1, 0, 1, 2.
*
****************************************************************************
**/
template
CubicInterpolator::CubicInterpolator(const double *p)
: m0(p), m1(p + SKIP1), m2(p + SKIP2), m3(p + SKIP3) //
Decompose the first dimension into 4 parts and then recursive construct.
{
// coordinates are usually between 0.0 and 1.0.
// Set to a very large number so it will not match any practical number.
mPath[0] = 1.0E100;
mpCubic[0] = &m0;
mpCubic[1] = &m1;
mpCubic[2] = &m2;
mpCubic[3] = &m3;
}
/***************************************************************************
**
* Description: Set parameters
*
* Parameters: p, Address of the first element of an N dimensional array
containing original data. Each dimension has 4 elements.
For example a[4][4] for N = 2. The elements in each
dimension
has coordinates -1, 0, 1, 2. For N == 1, this is x0 = -1,
x1 = 0, x2 = 1, x3 = 2.
*
****************************************************************************
**/
template
void CubicInterpolator::Set(const double *p)
{
mpCubic[0]->Set(p);
mpCubic[1]->Set(p + SKIP1);
mpCubic[2]->Set(p + SKIP2);
mpCubic[3]->Set(p + SKIP3);
}
/***************************************************************************
**
* Description: Move down by one row.
* This method is good only for interpolation on large grid,
moving
* down in column first fashion, not normal row first way. It
is like moving a window
* down the grid, one row a time. All rows move up with
bottom row replaced with the new row.
* The bottom row is recalculated using new data. Only the
last row needs update.
* Using this method will avoid repeated calculation of same
points.
*
* Parameters: p, addresss of the first element of the last block of an
4x4x4... array.
* For N == 2, this is the address of the last row of a 4x4
array. &arr[3][0] which has 4 elements to the end of arr.
* For N == 3, this is the address of the last layer of a
4x4x4 array, &arr[3][0][0] which has 16 elements to the end of arr.
*
****************************************************************************
**/
template
void CubicInterpolator::MoveDown(const double *p)
{
CubicInterpolator * pTemp = mpCubic[0];
mpCubic[0] = mpCubic[1];
mpCubic[1] = mpCubic[2];
mpCubic[2] = mpCubic[3];
mpCubic[3] = pTemp;
pTemp->Set(p);
}
/***************************************************************************
**
* Description: Perform N cubic interpolation
*
* Parameters: coordinates, Address of the first element of an array of N
elements of x, y, z,... For example c[2] for N = 2 which
contains x and y.
*
* Returns An interpolation value
****************************************************************************
**/
template
double CubicInterpolator::Interpolate(const double * coordinates)
{
const double *p = coordinates + 1;
// If path has changed, recalculate cubic function. Otherwise, reuse
the previous cubic function.
// This is for avoiding repeated calculation for grid data, many of them
share same path.
// This approach will save a lot of calculations if a large grid data is
used.
// For example: for N == 2, grid data is a m by n grid. Y path will
be recalculated only for the first
// element of each row because all data on the same row have same y
value. The logic is recursively expanded for higher N.
if(memcmp(mPath, p, sizeof(mPath)) != 0)
{
memcpy(mPath, p, sizeof(mPath)); // Save new path for comparison
next time.
mArr[0] = mpCubic[0]->Interpolate(p);
mArr[1] = mpCubic[1]->Interpolate(p);
mArr[2] = mpCubic[2]->Interpolate(p);
mArr[3] = mpCubic[3]->Interpolate(p);
mCubic.Set(mArr);
}
return mCubic.Interpolate(coordinates);
}
// Template specialization to terminate recursive build.
// This template also has implementation different from other templates of
higher N.
template <>
class CubicInterpolator<1U>
{
public:
CubicInterpolator();
CubicInterpolator(const double *p);
void Set(const double *p);
double Interpolate(const double * coordinates);

private:
// Cubic function coefficients
double A;
double B;
double C;
double D;
};
template <>
class CubicInterpolator<0U>
{
// No implementation. Should not use this class with 0 dimension.
};
/***************************************************************************
**
* Description: Constructor
*
*
****************************************************************************
**/
inline CubicInterpolator<1U>::CubicInterpolator() : A(0.0), B(0.0), C(0.0),
D(0.0)
{
}
/***************************************************************************
**
* Description: Constructor
*
* Parameters: p, Address of the first element of an array of 4 elements.
* The element has coordinates of -1, 0, 1, 2 for
interpolation
* between 0 and 1.
* Refer http://www.paulinternet.nl/?page=bicubic for more details.
*
****************************************************************************
**/
inline CubicInterpolator<1U>::CubicInterpolator(const double *p)
{
Set(p);
}
/***************************************************************************
**
* Description: Set cubic coefficients
*
* Parameters: p, Address of the first element of an array of 4 elements.
* The element has coordinates of -1, 0, 1, 2 for
interpolation
* between 0 and 1.
* Refer http://www.paulinternet.nl/?page=bicubic for more details.
*
****************************************************************************
**/
inline void CubicInterpolator<1U>::Set(const double *p)
{
// The following calculation is only good for p[n] = f(x) where x0 == -1
, x1 == 0, x2 == 1 and x3 == 2.
// See http://www.paulinternet.nl/?page=bicubic
A = -0.5 * p[0] + 1.5 * p[1] - 1.5 * p[2] + 0.5 * p[3];
B = p[0] - 2.5 * p[1] + 2.0 * p[2] - 0.5 * p[3];
C = -0.5 * p[0] + 0.5 * p[2];
D = p[1];
}
/***************************************************************************
**
* Description: Perform cubic interpolation
*
* Parameters: coordinates, Address of an x value.
*
* Returns An interpolation value
****************************************************************************
**/
inline double CubicInterpolator<1U>::Interpolate(const double *coordinates)
{
// *coordinates should be between 0.0 and 1.0, because the cubic
function is calculated for x0 == -1, x1 == 0, x2 == 1 and x3 == 2.
// This is where all interpolations are calculated.
double x1 = *coordinates;
double x2 = x1 * x1;
double x3 = x2 * x1;
return D + C * x1 + B * x2 + A * x3;
}
O*******d
发帖数: 20343
6
两幅图像在切换时,我用了颜色混合。 Windows的GDI没有比较好的混合颜色的方法。
我写这个屏保时不打算用OpenGL来做。于是自己写了一个混合颜色的class。 主要想法
是用空间换时间,。颜色混合用查表法。 两个颜色,不管红绿蓝,就是一个2维数组的
index,那个位置的颜色就是事先计算好的混合色。
#include
class ColorBlender
{
public:

ColorBlender(double alpha) { mAlpha = alpha;mLookupTable = NULL;
CreateTable(); }
~ColorBlender() {delete [] mLookupTable ;}
unsigned char Blend(unsigned char firstColor, unsigned char
secondColor);
void Blend(const unsigned char * pFirstColor, const unsigned char *
pSecondColor, unsigned char *pDestColor, int len);

private:
double mAlpha;
unsigned char *mLookupTable;
void CreateTable();
// Hide this constructor
ColorBlender();

};
/***************************************************************************
**/
inline void ColorBlender::CreateTable()
{
if(mAlpha > 1.0)
mAlpha = 1.0;
else if(mAlpha < 0.0)
mAlpha = 0.0;
if(mLookupTable == NULL)
{
mLookupTable = new unsigned char[256 * 256];
}
double oneMinusAlpha = 1.0 - mAlpha;
double blendedColor;
int i, j;
unsigned char byte;
unsigned char *p = mLookupTable;
for(i = 0; i < 256; ++i)
{
for(j = 0; j < 256; ++j)
{
blendedColor = (double)i * mAlpha + (double)j * oneMinusAlpha;
byte = (unsigned char)blendedColor;
if((blendedColor - byte) >= 0.5)
++byte; // correct round off error
*p++ = byte;
}
}
}
/***************************************************************************
**/
inline unsigned char ColorBlender::Blend(unsigned char souceColor, unsigned
char destColor)
{
return *(mLookupTable + ((unsigned int)souceColor << 8) + destColor);
}
/***************************************************************************
**/
inline void ColorBlender::Blend(const unsigned char * pFirstColor, // first
color buffer.
const unsigned char *pSecondColor, // second
color buffer.
unsigned char *pDestColor, // third
color buffer the content of which will be changed to blended color
int len) // length
of the buffer.
{
int i;
int remainder = len % 4;
int end = len - remainder;
// Use multi CPUs, if exist, to process this time consuming task.
#pragma omp parallel if (len > 10000)
{
// All parameters and values in this code block are private for each
thread.
const unsigned char * pColor1;
const unsigned char * pColor2;
unsigned char * pColor3;
#pragma omp for nowait
for(i = 0; i < end; i += 4) // unroll loop for faster speed
{
pColor1 = pFirstColor + i;
pColor2 = pSecondColor + i;
pColor3 = pDestColor + i;
*(pColor3 ) = Blend(*(pColor1 ), *(pColor2 ));
*(pColor3 + 1) = Blend(*(pColor1 + 1), *(pColor2 + 1));
*(pColor3 + 2) = Blend(*(pColor1 + 2), *(pColor2 + 2));
*(pColor3 + 3) = Blend(*(pColor1 + 3), *(pColor2 + 3));
}
}
for(i = end; i < len; ++i)
*(pDestColor + i) = Blend(*(pFirstColor + i), *(pSecondColor + i));
}
T*******x
发帖数: 8565
7
很好。
我下载了,安装发生如下的错误:


antialiase
5

【在 O*******d 的大作中提到】
: 基本上是一个slide show。 把计算机产生的图像一幅一幅显示。 图像的产生用当时的
: 时间做seed,基本上永远不会有重复的图像。 图像做了antialiase处理,效果很好。
: 图像是Perlin Noise, 计算时充分利用多核处理器平行处理。我自己做的antialiase
: 和颜色混合。 对显卡没有严格要求,只要能显示24bit的颜色即可。 启动时有一个5
: 秒的busy动画。 按空格键就可以把图像存成一个jpg文件。 下边是存的一部分图像。
: 下载网址
: http://www.mediafire.com/?6b016jn01ku27b1

T*******x
发帖数: 8565
8

就是最下面的几行字。在附件中的。

【在 T*******x 的大作中提到】
: 很好。
: 我下载了,安装发生如下的错误:
:
: 。
: antialiase
: 5

O*******d
发帖数: 20343
9
我在windows XP,Vista, Win7上都试过,可以安装啊。 你的是什么windows? 正式
安装需要先把文件copy到C:\Windows\System32里,然后右击,install,那个control
panel的display窗户就跳出。
如果你没有administrator权限,就无法copy到C:\Windows\System32里,只能右击test
或右击Config。

【在 T*******x 的大作中提到】
: 很好。
: 我下载了,安装发生如下的错误:
:
: 。
: antialiase
: 5

T*******x
发帖数: 8565
10
按照你的说法,现在可以安装了。但是不运行啊。用preview也不行。
我是win7。

control
test

【在 O*******d 的大作中提到】
: 我在windows XP,Vista, Win7上都试过,可以安装啊。 你的是什么windows? 正式
: 安装需要先把文件copy到C:\Windows\System32里,然后右击,install,那个control
: panel的display窗户就跳出。
: 如果你没有administrator权限,就无法copy到C:\Windows\System32里,只能右击test
: 或右击Config。

O*******d
发帖数: 20343
11
最简单的试验就是右击,Test。 屏幕立即变黑,中间有一个阴阳动画。 5秒以后显示
图形。 在Win7上的一个试验方法就是在control panel-》personalization-》
screensaver, 选Swirl,然后Preview.

【在 T*******x 的大作中提到】
: 按照你的说法,现在可以安装了。但是不运行啊。用preview也不行。
: 我是win7。
:
: control
: test

T*******x
发帖数: 8565
12
右击test,提示如下的错误:
The application has failed to start because its side-by-side
configuration is incorrect. Please see the application event
log or use the command-line sxstrace.exe tool for more detail.
control panel->personalization->screensaver->swirl->preview
没有反应,什么也没出来。

【在 O*******d 的大作中提到】
: 最简单的试验就是右击,Test。 屏幕立即变黑,中间有一个阴阳动画。 5秒以后显示
: 图形。 在Win7上的一个试验方法就是在control panel-》personalization-》
: screensaver, 选Swirl,然后Preview.

O*******d
发帖数: 20343
13
我在一些laptop上见过这种错误。不知道什么原因。google了一下The application
has failed to start because its side-by-side : configuration is incorrect,
网上有讨论
http://forums.techguy.org/windows-vista/613262-solved-failed-be
http://forums.techarena.in/vista-help/975947.htm

【在 T*******x 的大作中提到】
: 右击test,提示如下的错误:
: The application has failed to start because its side-by-side
: configuration is incorrect. Please see the application event
: log or use the command-line sxstrace.exe tool for more detail.
: control panel->personalization->screensaver->swirl->preview
: 没有反应,什么也没出来。

1 (共1页)
进入Programming版参与讨论
相关主题
如何用’sed‘ comment out 某一行。
matlab编程问题求助
c++ floating point calculation problem (revised)
[合集] 常数指针的问题
现在哪些script最流行?
什么算法可以比较2段曲线的相似度?
C++在linux下读一次系统时间要多少时间
从马航这事来看,big data还只是传说
How to find the best fit dimension of Polynomial interpolation/curve fitting ?
python simple question
相关话题的讨论汇总
话题: mpcubic话题: double话题: unsigned话题: set