本文整理汇总了C++中Image32::setSize方法的典型用法代码示例。如果您正苦于以下问题:C++ Image32::setSize方法的具体用法?C++ Image32::setSize怎么用?C++ Image32::setSize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Image32
的用法示例。
在下文中一共展示了Image32::setSize方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: sqrt
int Image32::RotateGaussian(const float& angle,Image32& outputImage) const
{
int height = this->height();
int width = this->width();
double rad = -1.0 * angle * (M_PI/180.0);
double midHeight = (height/2.0);
double midWidth = (width/2.0);
double diagonal = sqrt(midHeight*midHeight + midWidth*midWidth);
int offset = ceil(diagonal - min(midWidth, midHeight));
Image32 interImage;
interImage.setSize(width+(2*offset), height+(2*offset));
outputImage.setSize(width+(2*offset), height+(2*offset));
float variance = 2;
float radius = 2;
for(int y=0; y < height; ++y){
for(int x=0; x < width; ++x){
int xOffset = x + offset;
int yOffset = y + offset;
interImage.pixel(xOffset, yOffset).r = this->pixel(x,y).r;
interImage.pixel(xOffset, yOffset).g = this->pixel(x,y).g;
interImage.pixel(xOffset, yOffset).b = this->pixel(x,y).b;
}
}
for(int y=-1*offset; y < height + offset; ++y){
for(int x=-1*offset; x < width + offset; ++x){
int xOffset = x + offset;
int yOffset = y + offset;
float u = cos(rad)*(x - midWidth) - sin(rad)*(y - midHeight) + offset + midWidth;
float v = sin(rad)*(x - midWidth) + cos(rad)*(y - midHeight) + offset + midHeight;
Pixel32 pix = interImage.GaussianSample(u,v, variance, radius);
outputImage.pixel(xOffset,yOffset).r = pix.r;
outputImage.pixel(xOffset,yOffset).g = pix.g;
outputImage.pixel(xOffset,yOffset).b = pix.b;
outputImage.pixel(xOffset,yOffset).a = pix.a;
// useful for debugging
// outputImage.pixel(xOffset,yOffset).r = interImage.pixel(xOffset, yOffset).r;
// outputImage.pixel(xOffset,yOffset).g = interImage.pixel(xOffset, yOffset).g;
// outputImage.pixel(xOffset,yOffset).b = interImage.pixel(xOffset, yOffset).b;
}
}
return 1;
}
示例2: TakeSnapshot
/** This function reads the current frame buffer and sets the pixels of the image accordingly. */
int RayWindow::TakeSnapshot(Image32& img){
GLfloat *pixels;
int i,j,temp;
Pixel p;
GLint vp[4];
glGetIntegerv(GL_VIEWPORT,vp);
if(!img.setSize(vp[2],vp[3])){return 0;}
pixels=new GLfloat[vp[2]*vp[3]*3];
if(!pixels){return 0;}
glReadBuffer(GL_FRONT);
glReadPixels(vp[0],vp[1],vp[2],vp[3],GL_RGB,GL_FLOAT,pixels);
for(i=0;i<vp[3];i++){
for(j=0;j<vp[2];j++){
temp=0+j*3+(vp[3]-i-1)*(vp[2])*3;
p.r=255*pixels[temp];
temp=1+j*3+(vp[3]-i-1)*(vp[2])*3;
p.g=255*pixels[temp];
temp=2+j*3+(vp[3]-i-1)*(vp[2])*3;
p.b=255*pixels[temp];
img(j,i)=p;
}
}
delete[] pixels;
return 1;
}
示例3:
int Image32::Warp(const OrientedLineSegmentPairs& olsp,Image32& outputImage) const
{
int height = this->height();
int width = this->width();
outputImage.setSize(width,height);
int numOfLineSegments = olsp.count;
float dSumX, dSumY, weight, weightSum;
cout << "warp" << "\n";
for(int y=0; y<height; ++y){
for(int x=0; x<width; ++x){
for(int i=0; i<numOfLineSegments; ++i){
dSumX = 0, dSumY = 0, weightSum = 0;
weight = olsp.segments2[i].getWeight(x,y);
weightSum += weight;
float sourceX, sourceY;
olsp.segments1[i].GetSourcePosition(olsp.segments1[i], olsp.segments2[i], x, y, sourceX, sourceY);
dSumX += (sourceX - x) * weight;
dSumY += (sourceY - y) * weight;
}
outputImage.pixel(x,y).r = this->pixel(x + (dSumX/weightSum), y + (dSumY/weightSum)).r;
outputImage.pixel(x,y).g = this->pixel(x + (dSumX/weightSum), y + (dSumY/weightSum)).g;
outputImage.pixel(x,y).b = this->pixel(x + (dSumX/weightSum), y + (dSumY/weightSum)).b;
}
}
return 1;
}
示例4: int
int Image32::Brighten(const float& brightness,Image32& outputImage) const
{
int height = this->height();
int width = this->width();
outputImage.setSize(width, height);
for(int y=0; y<height; ++y){
for(int x=0; x<width; ++x){
int r = this->pixel(x,y).r;
int g = this->pixel(x,y).g;
int b = this->pixel(x,y).b;
int rBright = int(r * brightness);
int gBright = int(g * brightness);
int bBright = int(b * brightness);
if(rBright <= 255 && gBright <= 255 && bBright <= 255 ){
outputImage.pixel(x,y).r = rBright;
outputImage.pixel(x,y).g = gBright;
outputImage.pixel(x,y).b = bBright;
outputImage.pixel(x,y).a = this->pixel(x,y).a;
}
else{
// must clamp if any r,g,b values are over 255
int maxBrightness = 255 / max(r,max(g,b));
outputImage.pixel(x,y).r = int(r * maxBrightness);
outputImage.pixel(x,y).g = int(g * maxBrightness);
outputImage.pixel(x,y).b = int(b * maxBrightness);
outputImage.pixel(x,y).a = this->pixel(x,y).a;
}
}
}
return 1;
}
示例5: float
int Image32::OrderedDither2X2(const int& bits,Image32& outputImage) const
{
int height = this->height();
int width = this->width();
int i;
int j;
float D[2][2];
D[0][0] = 1.0;
D[0][1] = 3.0;
D[1][0] = 4.0;
D[1][1] = 2.0;
Image32 interImage;
interImage.setSize(width,height);
float scaler255 = (255.0/pow(2,bits-1));
this->Quantize(bits,interImage);
for(int y=0; y<height; ++y){
for (int x = 0; x<width; ++x){
i = x % 2;
j = y % 2;
float r = float(this->pixel(x,y).r) / 255.0;
float g = float(this->pixel(x,y).g) / 255.0;
float b = float(this->pixel(x,y).b) / 255.0;
float cR = r*pow(2,bits-1);
float cG = g*pow(2,bits-1);
float cB = b*pow(2,bits-1);
float eR = cR - floor(cR);
float eG = cG - floor(cG);
float eB = cB - floor(cB);
if(eR > (D[i][j] / 8)) {outputImage.pixel(x,y).r = int(ceil(cR)*scaler255);}
else{outputImage.pixel(x,y).r = int(floor(cR) * scaler255);}
if(eG > (D[i][j] / 8)) {outputImage.pixel(x,y).g = int(ceil(cG)*scaler255);}
else{outputImage.pixel(x,y).g = int(floor(cG) * scaler255);}
if(eB > (D[i][j] / 8)) {outputImage.pixel(x,y).b = int(ceil(cB)*scaler255);}
else{outputImage.pixel(x,y).b = int(floor(cB) * scaler255);}
outputImage.pixel(x,y).a = this->pixel(x,y).a;
}
}
return 1;
}
示例6: fabs
int Image32::Contrast(const float& contrast,Image32& outputImage) const
{
int height = this->height();
int width = this->width();
outputImage.setSize(width, height);
float totalLum = 0.0;
int numPixels = 0;
for(int y=0; y<height; ++y){
for(int x=0; x<width; ++x){
int r = this->pixel(x,y).r;
int g = this->pixel(x,y).g;
int b = this->pixel(x,y).b;
float l = 0.30*r + 0.59*g + 0.11*b;
totalLum += l;
numPixels += 1;
}
}
float meanLum = totalLum / numPixels;
for(int y=0; y<height; ++y){
for(int x=0; x<width; ++x){
int r = this->pixel(x,y).r;
int g = this->pixel(x,y).g;
int b = this->pixel(x,y).b;
int a = this->pixel(x,y).a;
float l = 0.30*r + 0.59*g + 0.11*b;
float lDiff = l - meanLum;
float maxContrast;
if(lDiff >= 0){
maxContrast = (255 - (max(r,max(g,b)) - lDiff)) / lDiff;
}
else{
maxContrast = fabs(((min(r,min(g,b))) - lDiff) / lDiff); // lDiff is negative, so adding to minimum of r,g,b
}
float contrastClamped = min(maxContrast,contrast);
outputImage.pixel(x,y).r = contrastClamped*lDiff + (r-lDiff);
outputImage.pixel(x,y).g = contrastClamped*lDiff + (g-lDiff);
outputImage.pixel(x,y).b = contrastClamped*lDiff + (b-lDiff);
outputImage.pixel(x,y).a = a;
}
}
return 1;
}
示例7: max
int Image32::AddRandomNoise(const float& noise,Image32& outputImage) const
{
int height = this->height();
int width = this->width();
outputImage.setSize(width, height);
int noiseRange = (noise * 256) * 2;
for(int y=0; y<height; ++y){
for(int x=0; x<width; ++x){
int randNum;
if(noiseRange != 0) randNum = (rand() % noiseRange) - (.5*noiseRange);
else{ randNum = 0; }
outputImage.pixel(x,y).r = max(0,min(255,randNum + this->pixel(x,y).r));
outputImage.pixel(x,y).g = max(0,min(255,randNum + this->pixel(x,y).g));
outputImage.pixel(x,y).b = max(0,min(255,randNum + this->pixel(x,y).b));
outputImage.pixel(x,y).a = this->pixel(x,y).a;
}
}
return 1;
}
示例8: min
int Image32::Saturate(const float& saturation,Image32& outputImage) const
{
int height = this->height();
int width = this->width();
outputImage.setSize(width, height);
for(int y=0; y<height; ++y){
for(int x=0; x<width; ++x){
int r = this->pixel(x,y).r;
int g = this->pixel(x,y).g;
int b = this->pixel(x,y).b;
float l = 0.30*r + 0.59*g + 0.11*b;
float rDiff = r-l;
float gDiff = g-l;
float bDiff = b-l;
bool rOverflow = (r-rDiff) + rDiff*saturation > 255 || (r-rDiff) + rDiff*saturation < 0;
bool gOverflow = (g-gDiff) + gDiff*saturation > 255 || (g-gDiff) + gDiff*saturation < 0;
bool bOverflow = (b-bDiff) + bDiff*saturation > 255 || (b-bDiff) + bDiff*saturation < 0;
float satClamped = saturation; // if no overflows, satClamped is saturation
if(rOverflow){ // if r overflows, clamp sat to max so r doesn't overflow
satClamped = min((r-rDiff), 255-(r-rDiff)) / rDiff;
}
if(gOverflow){ // if g overflows, clamp sat to max so g doesn't overflow (or satClamped if less)
satClamped = min(min((g-gDiff), 255-(g-gDiff)) / gDiff, satClamped);
}
if(bOverflow){ // if b overflows, clamp sat to max so b doesn't overflow (or satClamped if less)
satClamped = min(min((b-bDiff), 255-(b-bDiff)) / bDiff, satClamped);
}
outputImage.pixel(x,y).r = satClamped*rDiff + (r-rDiff);
outputImage.pixel(x,y).g = satClamped*gDiff + (g-gDiff);
outputImage.pixel(x,y).b = satClamped*bDiff + (b-bDiff);
outputImage.pixel(x,y).a = this->pixel(x,y).a;
}
}
return 1;
}
示例9: RayTrace
int RayScene::RayTrace(const int& width,const int& height,const int& rLimit,const double& cLimit,Image32& img){
int i,j;
Ray3D ray;
Point3D c;
Pixel32 p;
int rayCount=0;
if(!img.setSize(width,height)){return 0;}
ray.position=camera->position;
for(i=0;i<width;i++){
printf(" \r");
printf("%3.1f\r",(float)i/width*100);
for(j=0;j<height;j++){
ray=GetRay(camera,i,height-j-1,width,height);
c=GetColor(ray,rLimit,Point3D(cLimit,cLimit,cLimit));
p.r=(int)(c[0]*255);
p.g=(int)(c[1]*255);
p.b=(int)(c[2]*255);
img(i,j)=p;
}
}
return 1;
}