本文整理汇总了C++中BMP::SetBitDepth方法的典型用法代码示例。如果您正苦于以下问题:C++ BMP::SetBitDepth方法的具体用法?C++ BMP::SetBitDepth怎么用?C++ BMP::SetBitDepth使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BMP
的用法示例。
在下文中一共展示了BMP::SetBitDepth方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: PadBMP
void PadBMP( BMP& Input , int NewWidth , int NewHeight )
{
// if the NewWidth and NewHight are unchanged, exit
if( NewWidth == Input.TellWidth() &&
NewHeight == Input.TellHeight() )
{
return;
}
// find max range for the copy, so that cropping occurs
// if necessary
int MaxWidth = Input.TellWidth();
if( MaxWidth > NewWidth )
{
MaxWidth = NewWidth;
}
int MaxHeight = Input.TellHeight();
if( MaxHeight > NewHeight )
{
MaxHeight = NewHeight;
}
// create a temporary image to hold the original pixels
BMP Temp;
Temp.SetSize(NewWidth,NewHeight);
Temp.SetBitDepth( Input.TellBitDepth() );
int i,j;
int Difference = Temp.TellHeight() - MaxHeight;
for( i=0 ; i < MaxWidth ; i++ )
{
for( j=0 ; j < MaxHeight ; j++ )
{
*Temp(i,j+Difference) = *Input(i,j);
}
}
// resize the original image, and recopy the pixels
Input.SetSize(NewWidth,NewHeight);
for( i=0 ; i < Input.TellWidth() ; i++ )
{
for( j=0 ; j < Input.TellHeight() ; j++ )
{
*Input(i,j) = *Temp(i,j);
}
}
Temp.SetSize(1,1);
Temp.SetBitDepth(24);
return;
}
示例2: BMP
// creates a BMP from a CImage
// assumes all float values have already been scaled to [0.0, 255.0]
BMP * CImage::toBmp()
{
BMP * bmp = new BMP();
bmp->SetSize(m_width, m_height);
// for smaller output file size
bmp->SetBitDepth(8);
// 8-bit bitmaps need a color table
CreateGrayscaleColorTable(*bmp);
for (int col = 0; col < m_width; col++)
{
for (int row = 0; row < m_height; row++)
{
// Output is grayscale, so R, G, and B components are equal.
// ScaleAndDisplayDisparityValues() et. al. in stereo.cpp have already
// scaled all float pixel values to [0, 255].
ebmpBYTE byteVal = (ebmpBYTE) getValue(row, col, 0);
(* bmp)(col, row)->Red = byteVal;
(* bmp)(col, row)->Green = byteVal;
(* bmp)(col, row)->Blue = byteVal;
}
}
return bmp;
}
示例3: array2bmp
//数组转图像
void array2bmp()
{
int i,j;
BMP bmp;
RGBApixel pix_black={0};//R=0 G=0 B=0为黑色
RGBApixel pix_white={255,255,255,0};//白色
bmp.SetSize(3,3);
bmp.SetBitDepth(1);
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
if(array[i][j]==1)
{
bmp.SetPixel( i, j,pix_black);
}
else
{
bmp.SetPixel( i, j,pix_white);
}
}
}
bmp.WriteToFile("examp_array2bmp.bmp");
printf("array2bmp suc...\n");
}
示例4: raytrace
void Camera::raytrace(Node *node, const std::vector<Light*>& lights) {
BMP output;
output.SetSize(width,height);
output.SetBitDepth(24);
for(int i = 0; i < width; i++) {
for(int j = 0; j < height; j++) {
output(i,j)->Red = 0;
output(i,j)->Green = 0;
output(i,j)->Blue = 0;
}
}
float aRatio = (float)width/height;
glm::vec3 xAxis = glm::cross(fwd, up);
glm::vec3 yAxis = glm::cross(xAxis, fwd);
float xFov = std::atan(std::tan(yFov) * aRatio);
xAxis *= std::tan(xFov/2) * glm::length(fwd) / glm::length(xAxis);
yAxis *= std::tan(yFov/2) * glm::length(fwd) / glm::length(yAxis);
for(unsigned int j = 0; j < height; j++) {
std::cout << "\rline " << j << std::flush;
#pragma omp parallel for
for(unsigned int i = 0; i < width; i++) {
// indirect illumination
glm::vec3 color(0);
for(int d = 0; d < density; d++) {
float x = (float(i) + float(rand())/RAND_MAX) / width;
float y = (float(j) + float(rand())/RAND_MAX) / height;
std::cout << "dbg " << fwd << " " << xAxis << " " << yAxis << "\n";
glm::vec3 dir = glm::normalize(fwd + (2*x-1)*xAxis + (1-2*y)*yAxis);
Ray ray(pos, dir, rayCount, true);
glm::vec4 dirCol = rayIter(ray, node, lights);
glm::vec3 mcCol;
if(dirCol[3] < 1 && mcIter > 0) {
for(int w = 0; w < mcIter; w++)
mcCol += rayIter(ray,node);
mcCol /= float(mcIter);
} else {
dirCol[3] = 1;
}
color += (1.f - dirCol[3])*mcCol + dirCol[3]*glm::vec3(dirCol);
}
color /= float(density);
output(i,j)->Red = 255.0*glm::clamp(color[0],0.f,1.f);
output(i,j)->Green = 255.0*glm::clamp(color[1],0.f,1.f);
output(i,j)->Blue = 255.0*glm::clamp(color[2],0.f,1.f);
}
}
output.WriteToFile(outFile.c_str());
exit(0);
}
示例5: writeToBMPFile
bool Image::writeToBMPFile(const std::string & outputFileName)
{
bool success = true;
if( m_pixels != NULL )
{
// create bitmap image
BMP outputImage;
outputImage.SetSize(m_numCols, m_numRows);
outputImage.SetBitDepth( 24 );
double maxVal = m_pixels[0];
double minVal = m_pixels[0];
// Maximum and minimum values
for( int i = 1; i < m_numRows * m_numCols; ++i )
{
if( m_pixels[i] > maxVal )
{
maxVal = m_pixels[i];
}
if( m_pixels[i] <= minVal )
{
minVal = m_pixels[i];
}
}
for( int r = 0; r < m_numRows; ++r )
{
for( int c = 0; c < m_numCols; ++c )
{
// get pixel value and clamp between 0 and 255
double val = 255.0 * (m_pixels[r * m_numCols + c] - minVal) / (maxVal - minVal);
if( val < 0 )
{
val = 0;
}
if( val > 255 )
{
val = 255;
}
// set output color based on mapping
RGBApixel pixelVal;
pixelVal.Blue = (int)val; pixelVal.Green = (int)val; pixelVal.Red = (int)val;
outputImage.SetPixel(c, r, pixelVal);
}
}
// write to file
success = outputImage.WriteToFile( outputFileName.c_str() );
}
else
{
success = false;
}
return success;
}
示例6: HBITMAPtoBMP
bool HBITMAPtoBMP(HDC hDC,HBITMAP hBitmap,BMP& OutputImage)
{
using namespace std;
bool output = false;
BITMAPINFO BitInfo;
ZeroMemory(&BitInfo, sizeof(BITMAPINFO));
BitInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
// get all manner of information from the incoming bitmap
if(!::GetDIBits(hDC, hBitmap, 0, 0, NULL, &BitInfo, DIB_RGB_COLORS))
{ return false; }
// Set the size and bit depth of the BMP object
OutputImage.SetSize( BitInfo.bmiHeader.biWidth ,BitInfo.bmiHeader.biHeight );
OutputImage.SetBitDepth(32);
// reconfigure BitInfo.bmiHeader such that the resulting bitmap will be
// 32 bits per pixel. This is _MUCH_ simpler
BitInfo.bmiHeader.biBitCount = 32;
BitInfo.bmiHeader.biCompression = 0;
BitInfo.bmiHeader.biSizeImage = OutputImage.TellHeight()*OutputImage.TellWidth()*4;
// I don't understand the +5 part here. -- Paul
// BYTE *pData = new BYTE[BitInfo.bmiHeader.biSizeImage + 5];
// BYTE *pData = new BYTE[Output.TellHeight()*Output.TellWidth()*4+5];
BYTE *pData = new BYTE [BitInfo.bmiHeader.biSizeImage];
// now get the actual data
if(!::GetDIBits(hDC, hBitmap, 0, BitInfo.bmiHeader.biHeight, pData, &BitInfo, DIB_RGB_COLORS))
{ return false; }
// transfer that data into the BMP object
int i,j;
int k=0;
for( j=OutputImage.TellHeight()-1 ; j >= 0 ; j-- )
{
for( i=0; i < OutputImage.TellWidth() ; i++ )
{
OutputImage(i,j)->Blue = *(pData+k); k++;
OutputImage(i,j)->Green = *(pData+k); k++;
OutputImage(i,j)->Red = *(pData+k); k++;
OutputImage(i,j)->Alpha = *(pData+k); k++;
}
}
delete (pData);
return true;
}
示例7: main
int main( int argc, char *argv[] )
{
cout << endl
<< "Using EasyBMP Version " << _EasyBMP_Version_ << endl << endl
<< "Copyright (c) by the EasyBMP Project 2005-6" << endl
<< "WWW: http://easybmp.sourceforge.net" << endl << endl;
BMP Text;
Text.ReadFromFile("EasyBMPtext.bmp");
BMP Background;
Background.ReadFromFile("EasyBMPbackground.bmp");
BMP Output;
Output.SetSize( Background.TellWidth() , Background.TellHeight() );
Output.SetBitDepth( 24 );
RangedPixelToPixelCopy( Background, 0, Output.TellWidth() - 1,
Output.TellHeight() - 1 , 0,
Output, 0, 0 );
RangedPixelToPixelCopyTransparent( Text, 0, 380,
43, 0,
Output, 110, 5,
*Text(0, 0) );
RangedPixelToPixelCopyTransparent( Text, 0, Text.TellWidth() - 1,
Text.TellWidth() - 1, 50,
Output, 100, 442,
*Text(0, 49) );
Output.SetBitDepth( 32 );
cout << "writing 32bpp ... " << endl;
Output.WriteToFile( "EasyBMPoutput32bpp.bmp" );
Output.SetBitDepth( 24 );
cout << "writing 24bpp ... " << endl;
Output.WriteToFile( "EasyBMPoutput24bpp.bmp" );
Output.SetBitDepth( 8 );
cout << "writing 8bpp ... " << endl;
Output.WriteToFile( "EasyBMPoutput8bpp.bmp" );
Output.SetBitDepth( 4 );
cout << "writing 4bpp ... " << endl;
Output.WriteToFile( "EasyBMPoutput4bpp.bmp" );
Output.SetBitDepth( 1 );
cout << "writing 1bpp ... " << endl;
Output.WriteToFile( "EasyBMPoutput1bpp.bmp" );
Output.SetBitDepth( 24 );
Rescale( Output, 'p' , 50 );
cout << "writing 24bpp scaled image ..." << endl;
Output.WriteToFile( "EasyBMPoutput24bpp_rescaled.bmp" );
return 0;
}
示例8: w2f
void w2f(GlobalMap &globalMap, int i, int j, int size=1025)
{
char fileName[6] = {'0','0','.','b','m','p'};
fileName[0]=i+48;
fileName[1]=j+48;
short z;
RGBApixel color;
BMP image;
image.SetSize(size,size);
image.SetBitDepth(16);
for(int y=0; y<size; y++)
{
for(int x=0; x<size; x++)
{
z= globalMap.getLocalMap(i,j)->getHeight(x,y);
if(z<0)
{
color.Red=0;
color.Green=0;
color.Blue=(z+32768)/129;
color.Alpha=0;
}
if(z>=0 && z<20000)
{
color.Red=0;
color.Green=z/134+100;
color.Blue=0;
color.Alpha=0;
}
if(z>=20000 && z<25000)
{
color.Red=(z-20000)/500+200;
color.Green=(z-20000)/500+200;
color.Blue=(z-20000)/500+200;
color.Alpha=0;
}
if(z>=25000)
{
color.Red=255;
color.Green=255;
color.Blue=255;
color.Alpha=0;
}
image.SetPixel(x,y, color);
}
}
image.WriteToFile(fileName);
}
示例9: pixelsToBitmap
void BitmapRawConverter::pixelsToBitmap(char *outFilename) {
BMP out;
out.SetSize(width, height);
out.SetBitDepth(24);
for (int i = 0; i < width; i++) {
for (int j = 0; j < height; j++) {
out.SetPixel(i, j, getPixel(i,j));
}
}
out.WriteToFile(outFilename);
}
示例10: main
int main(int argc, char** argv) {
if (argc != 2) {
cout << "Incorrect input. Please enter the name of the configuration file." << endl;
return -1;
}
Reader * config = new Reader(argv[1]);
int width = config->getWIDTH();
int height = config->getHEIGHT();
int x = config->getX();
int y = config->getY();
int z = config->getZ();
Camera * rayGenerator = new Camera(config->getEYEP(), config->getVDIR(),
config->getUVEC(), config->getFOVY(), width, height);
BMP output;
output.SetSize(width, height);
output.SetBitDepth(24);
Raymarch * raymarch = new Raymarch(config->getVB(), rayGenerator, config->getEYEP(),
config->getMRGB(), config->getBRGB(),
config->getLCOL(), config->getLPOS(), config->getOFST());
for (int w = 0; w < width; w++) {
cout << "Rendering: " << (float) w/width << endl;
for (int h = 0; h < height; h++) {
/*
// Ray direction color test
output(w,h)->Red = abs(rayGenerator->getRayDirection(w,h).x) *255;
output(w,h)->Green = abs(rayGenerator->getRayDirection(w,h).y) *255;
output(w,h)->Blue = abs(rayGenerator->getRayDirection(w,h).z) *255;
*/
glm::vec3 colors = raymarch->getColor(w,h, config->getSTEP(), glm::vec3(x, y, z));
colors*=255.0;
if (colors.x > 255)
colors.x = 255;
if (colors.y > 255)
colors.y = 255;
if (colors.z > 255)
colors.z = 255;
output(w,h)->Red =colors.x;
output(w,h)->Green = colors.y;
output(w,h)->Blue = colors.z;
}
}
output.WriteToFile(config->getFILE());
cout << "File has been finished rendering." <<endl;
return 0;
}
示例11: printImage
void Camera::printImage(char* outputName) {
BMP output;
output.SetSize(imgWidth, imgHeight);
output.SetBitDepth(24);
glm::vec3 outR;
for (int i = 0; i < imgWidth; i++) {
for (int j = 0; j < imgHeight; j++) {
outR = glm::abs(glm::normalize(getDirectionFromCoordinate(i,j)-eye));
output(i,j)->Red = outR.x * 255;
output(i,j)->Green = outR.y * 255;
output(i,j)->Blue = outR.z * 255;
}
}
output.WriteToFile(outputName);
}
示例12:
static cell AMX_NATIVE_CALL n_FSetPixelRGBA( AMX* amx, cell* params ){
posx = params[1];
posy = params[2];
RGBApixel value;
value.Red = (ebmpBYTE)params[4];
value.Green = (ebmpBYTE)params[5];
value.Blue = (ebmpBYTE)params[6];
value.Alpha = (ebmpBYTE)params[7];
GlobalImage.SetBitDepth(24);
GlobalImage.GetPixel(posx,posy);
GlobalImage.SetPixel(posx,posy,value);
return 1;
}
示例13: ExportBMP
bool ExportBMP( const _TImg_t & in_indexed,
const std::string & filepath )
{
//shorten this static constant
typedef utils::do_exponent_of_2_<_TImg_t::pixel_t::mypixeltrait_t::BITS_PER_PIXEL> NbColorsPP_t;
BMP output;
output.SetBitDepth(_TImg_t::pixel_t::GetBitsPerPixel());
if( in_indexed.getNbColors() != NbColorsPP_t::value )
{
#ifdef _DEBUG
assert(false);
#endif
throw std::runtime_error( "ERROR: The tiled image to write to a bitmap image file has an invalid amount of color in its palette!" );
}
//copy palette
for( int i = 0; i < NbColorsPP_t::value; ++i )
output.SetColor( i, colorRGB24ToRGBApixel( in_indexed.getPalette()[i] ) );
//Copy image
output.SetSize( in_indexed.getNbPixelWidth(), in_indexed.getNbPixelHeight() );
for( int i = 0; i < output.TellWidth(); ++i )
{
for( int j = 0; j < output.TellHeight(); ++j )
{
auto & refpixel = in_indexed.getPixel( i, j );
uint8_t temp = static_cast<uint8_t>( refpixel.getWholePixelData() );
output.SetPixel( i,j, colorRGB24ToRGBApixel( in_indexed.getPalette()[temp] ) ); //We need to input the color directly thnaks to EasyBMP
}
}
bool bsuccess = false;
try
{
bsuccess = output.WriteToFile( filepath.c_str() );
}
catch( std::exception e )
{
cerr << "<!>- Error outputing image : " << filepath <<"\n"
<< " Exception details : \n"
<< " " <<e.what() <<"\n";
assert(false);
bsuccess = false;
}
return bsuccess;
}
示例14: _surf_save_bmp
bool _surf_save_bmp(const d_surf * srf, const char * filename) {
if (!filename)
return false;
if (!srf) {
writelog(LOG_ERROR,"surf_save_png : no surf loaded");
return false;
}
writelog(LOG_MESSAGE,"Saving surf %s to file %s (BMP)", srf->getName(), filename);
size_t NN = srf->getCountX();
size_t MM = srf->getCountY();
BMP res;
res.SetSize(NN,MM);
res.SetBitDepth(24);
REAL minz, maxz;
srf->getMinMaxZ(minz, maxz);
size_t i, j;
double gray_color;
for (j = 0; j < MM; j++) {
for (i = 0; i < NN; i++) {
REAL value = srf->getValueIJ(i,MM-j-1);
if (value == srf->undef_value) {
res(i,j)->Red = 0;
res(i,j)->Green = 0;
res(i,j)->Blue = 0;
res(i,j)->Alpha = 0;
} else {
gray_color = MAX(0,MIN(255,floor((value - minz)/(maxz-minz)*255 + 0.5)));
res(i,j)->Red = (ebmpBYTE)gray_color;
res(i,j)->Green = (ebmpBYTE)gray_color;
res(i,j)->Blue = (ebmpBYTE)gray_color;
res(i,j)->Alpha = 255;
}
}
}
res.WriteToFile(filename);
return true;
};
示例15: debugRender
void Camera::debugRender(unsigned int width, unsigned int height, std::string& outputFile)
{
BMP file;
file.SetSize(width,height);
file.SetBitDepth(24);
double d = m_direction.length(); //Distance from Eye to Middle point of the image
Vector myVectorEyetoMiddle(m_direction);
myVectorEyetoMiddle *= d; //C in full length
double tanfovx = tan(m_fovRad)*double(width)/height ;
Vector myEyeVectorX = myVectorEyetoMiddle.crossProduct(m_up) ; //A
Vector myEyeVectorY = myEyeVectorX.crossProduct(myVectorEyetoMiddle) ; //B
Vector myMiddlePoint = myVectorEyetoMiddle + m_position;
Vector myImageVectorX = myEyeVectorX * ( myVectorEyetoMiddle.normalize().length() * tanfovx / myEyeVectorX.length() ); //H
Vector myImageVectorY = myEyeVectorY * ( myVectorEyetoMiddle.normalize().length() * tan(m_fovRad) / myEyeVectorY.length() ); //V
for(unsigned int i=0;i<width;i++){
for(unsigned int j=0;j<height;j++){
double sx,sy;
sx = double(i)/width;
sy = double(j)/height;
Vector P = myImageVectorX*(2*sx-1) + myImageVectorY*(2*sy-1) + myMiddlePoint ;
Vector myRayCasting = (P - m_position)*(1.0 / (P - m_position).normalize().length()); //RayDirection = (P - E)/normalize(P - E);
Vector normalizedRay = myRayCasting.normalize();
RGBApixel NewColor;
NewColor.Red = (ebmpBYTE) abs(normalizedRay[0])*255;
NewColor.Green = (ebmpBYTE) abs(normalizedRay[1])*255;
NewColor.Blue = (ebmpBYTE) abs(normalizedRay[2])*255;
NewColor.Alpha = 0;
file.SetPixel(i, height-j-1, NewColor);
}
}
file.WriteToFile(outputFile.c_str());
}