本文整理汇总了C++中BMP::GetPixel方法的典型用法代码示例。如果您正苦于以下问题:C++ BMP::GetPixel方法的具体用法?C++ BMP::GetPixel怎么用?C++ BMP::GetPixel使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BMP
的用法示例。
在下文中一共展示了BMP::GetPixel方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
/**
@function Get4Pixels16Bit
reads four consecutive pixels of the specified row started from given column and writes they to the
two registers out_BG and out_RA. Uses 16 bit per channel
@param in_img is a input image
@param in_row_idx is an index of a row to read pixels
@param in_col_idx ia an index of a column with a first pixel
@param out_BG is a pointer to a 128bit register to store blue and green channels for the pixels four
consecutive pixels in format BBBB GGGG. Order of pixels is [0, 1, 2, 3]
@param out_RA is a pointer to a 128bit register to store red and alpha channels for the pixels four
consecutive pixels in format RRRR AAAA. Order of pixels is [0, 1, 2, 3]
*/
inline void Get4Pixels16Bit(BMP &in_img, int in_row_idx, int in_col_idx,
__m128i *out_BG, __m128i *out_RA)
{
// read four consecutive pixels
RGBApixel pixel0 = in_img.GetPixel(in_col_idx, in_row_idx);
RGBApixel pixel1 = in_img.GetPixel(in_col_idx + 1, in_row_idx);
RGBApixel pixel2 = in_img.GetPixel(in_col_idx + 2, in_row_idx);
RGBApixel pixel3 = in_img.GetPixel(in_col_idx + 3, in_row_idx);
// write two pixel0 and pixel2 to the p02 and other to the p13
__m128i p02 = _mm_setr_epi32(*(reinterpret_cast<int*>(&pixel0)), *(reinterpret_cast<int*>(&pixel2)), 0, 0);
__m128i p13 = _mm_setr_epi32(*(reinterpret_cast<int*>(&pixel1)), *(reinterpret_cast<int*>(&pixel3)), 0, 0);
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* convert BGRA BGRA BGRA BGRA
* to BBBB GGGG RRRR AAAA
* order of pixels corresponds to the digits in the name of variables
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
// BGRA BGRA 0000 0000 + BGRA BGRA 0000 0000 -> BBGG RRAA BBGG RRAA
__m128i p0123 = _mm_unpacklo_epi8(p02, p13);
// extract BBGG RRAA 0000 0000 of pixel2 and pixel3
__m128i p23xx = _mm_unpackhi_epi64(p0123, _mm_setzero_si128());
// BBGG RRAA XXXX XXXX + BBGG RRAA 0000 0000 -> BBBB GGGG RRRR AAAA
// X denotes unused characters
__m128i p0123_8bit = _mm_unpacklo_epi16(p0123, p23xx);
// extend to 16bit
*out_BG = _mm_unpacklo_epi8(p0123_8bit, _mm_setzero_si128());
*out_RA = _mm_unpackhi_epi8(p0123_8bit, _mm_setzero_si128());
}
示例2: calculateTextureFromMaterial
Color Sphere::calculateTextureFromMaterial(Point intercept, bool diagnosticEnabled) {
BMP* texture;
texture = &this->texture;
int height = texture->TellHeight();
int width = texture->TellWidth();
Vector vectorToIntercept = intercept - origin;
vectorToIntercept.normalize();
double u = 0.5 + atan2(vectorToIntercept.z,vectorToIntercept.x) / 2 / 3.1415;
double v = 0.5 - asin(vectorToIntercept.y) / 3.1415;
int pixelX = abs((int)(u * width));
int pixelY = abs((int)(v * height));
pixelX %= width;
pixelY %= height;
Color matColor;
if(diagnosticEnabled) {
matColor = Color(v,0,sin(u * 3.1415));
}
else {
matColor.r = texture->GetPixel(pixelX,pixelY).Red/255.f;
matColor.g = texture->GetPixel(pixelX,pixelY).Green/255.f;
matColor.b = texture->GetPixel(pixelX,pixelY).Blue/255.f;
}
return matColor;
}
示例3: encode
void encode(string infile, string outfile, string payload)
{
BMP input;
if(!input.ReadFromFile(infile.c_str()))
{
cout << "The Bitmap doesn\'t exist!" << endl;
return;
}
int msglength = payload.length() * 2;
if(msglength > input.TellWidth() * input.TellHeight())
{
cout << "That message is too large for that image! (" << msglength << " as opposed to " << input.TellWidth() * input.TellHeight() << "; " << input.TellWidth() << " * " << input.TellHeight() << ")"<<endl;
return;
}
stringstream msglength_ss;
msglength_ss << setfill('0') << setw(8) << hex << msglength;
string msglength_str = msglength_ss.str();
uchar msgLength_split[8];
for(uint i = 0; i < msglength_str.length(); i++)
{
msgLength_split[i] = (uchar)single_char_to_int(msglength_str[i]);
}
char* payload_split = new char[payload.length() * 2];
for(uint i = 0; i < payload.length() * 2 - 1; i+=2)
{
payload_split[i] = payload[i / 2] >> 4;
payload_split[i + 1] = payload[i/ 2] & 0x0F;
}
RGBApixel pix;
for(int x = 0; x < 8; x++)
{
pix = input.GetPixel(x, 0);
pix.Blue &= 0xF0;
pix.Blue += msgLength_split[x];
input.SetPixel(x, 0, pix);
}
for(int y = 0; y < input.TellHeight(); y++)
{
for(int x = 0; x < input.TellWidth(); x++)
{
if(y == 0 && x < 8)
continue;
pix = input.GetPixel(x, y);
if(payload.length() * 2 > (uint)input.TellWidth() * y + x - 8)
{
pix.Blue &= 0xF0;
pix.Blue += payload_split[input.TellWidth() * y + x - 8];
}
input.SetPixel(x, y, pix);
}
}
fclose(fopen(outfile.c_str(),"w"));
input.WriteToFile(outfile.c_str());
delete[] payload_split;
}
示例4: tile
void tile(BMP& Input, BMP& Output) {
if (Input.TellHeight() == 1) {
Output.SetPixel(Output.TellWidth() - 1, 0, Input.GetPixel(0, 0));
}
else {
BMP* ScaledInput = new BMP(Input);
Rescale(*ScaledInput, 'p', 50);
// SW quadrant
RangedPixelToPixelCopy(*ScaledInput, 0, ScaledInput -> TellWidth(), 0, ScaledInput -> TellHeight(),
Output, Output.TellWidth() - 2 * ScaledInput -> TellWidth(), ScaledInput -> TellHeight());
// NE quadrant
tile(*ScaledInput, Output);
// NW quadrant
RangedPixelToPixelCopy(Output, Output.TellWidth() - ScaledInput -> TellWidth(), Output.TellWidth() - ScaledInput -> TellWidth() / 2 - 1,
0, ScaledInput -> TellHeight() - 1, Output, Output.TellWidth() - 2 * ScaledInput -> TellWidth(), 0);
RangedPixelToPixelCopy(Output, Output.TellWidth() - ScaledInput -> TellWidth(), Output.TellWidth() - ScaledInput -> TellWidth() / 2 - 1,
0, ScaledInput -> TellHeight() - 1, Output, Output.TellWidth() - 3 * ScaledInput -> TellWidth() / 2, 0);
// SE quadrant
RangedPixelToPixelCopy(Output, Output.TellWidth() - ScaledInput -> TellWidth(), Output.TellWidth() - 1, ScaledInput -> TellHeight() / 2,
ScaledInput -> TellHeight() - 1, Output, Output.TellWidth() - ScaledInput -> TellWidth(), ScaledInput -> TellHeight());
RangedPixelToPixelCopy(Output, Output.TellWidth() - ScaledInput -> TellWidth(), Output.TellWidth() - 1, ScaledInput -> TellHeight() / 2,
ScaledInput -> TellHeight() - 1, Output, Output.TellWidth() - ScaledInput -> TellWidth(), 3 * ScaledInput -> TellHeight() / 2);
}
}
示例5: readFromBMPFile
bool Image::readFromBMPFile(const std::string & inputFileName)
{
bool success = true;
// use BMP object to read image
BMP inputImage;
success = inputImage.ReadFromFile(inputFileName.c_str() );
if( success )
{
// allocate memory for image (deleting old, if exists)
m_numRows = inputImage.TellHeight();
m_numCols = inputImage.TellWidth();
if( m_pixels != NULL ) // deallocate old memory
{
delete [] m_pixels;
}
m_pixels = new double[m_numRows * m_numCols];
// copy pixels
for( int r = 0; r < m_numRows; ++r )
{
for( int c = 0; c < m_numCols; ++c )
{
RGBApixel pixelVal = inputImage.GetPixel(c, r);
double val = (double) pixelVal.Blue + (double) pixelVal.Green + (double) pixelVal.Red;
val = (val / 3.0 + 0.5);
m_pixels[r * m_numCols + c] = val;
}
}
}
return success;
}
示例6: loadImage
unsigned int loadImage(const char * fname)
{
if ( ! fname )
{
return 0;
}
BMP bmp;
if ( ! bmp.ReadFromFile(fname) )
{
printf( "not loaded : %s\n",fname );
return 0;
}
int w = bmp.TellWidth();
int h = bmp.TellHeight();
int d = bmp.TellBitDepth() / 8;
RGBApixel* pix = bmp(0,0);
char bytes[0x7ffff], *b=bytes;
for ( int j=0; j<h; j++ )
{
for ( int i=0; i<w; i++ )
{
RGBApixel pix = bmp.GetPixel(i, j);
*b++ = pix.Red;
*b++ = pix.Green;
*b++ = pix.Blue;
if ( d == 4 )
*b++ = pix.Alpha;
}
}
size_t i = RGL::texCreate( w, h, d, bytes, true );;
printf( "created : %d [%d %d %d] %s\n", i, w,h,d,fname );
return i;
}
示例7: decode
string decode(string infile)
{
BMP input;
if(!input.ReadFromFile(infile.c_str()))
{
cout << "The input file didn't exist!" << endl;
return "";
}
stringstream ret;
int count = 0;
char currentChar;
RGBApixel pix;
int msgLength = 0;
stringstream msglength_ss;
for(int x = 0; x < 8; x++)
{
pix = input.GetPixel(x, 0);
msglength_ss << hex << (ushort)(pix.Blue & 0x0F);
}
msgLength = strtol(msglength_ss.str().c_str(), NULL, 16);
for(int y = 0; y < input.TellHeight(); y++)
{
for(int x = 0; x < input.TellWidth(); x++)
{
if(input.TellWidth() * y + x - 8 > msgLength) goto end;
if(y == 0 && x < 8)
continue;
pix = input.GetPixel(x, y);
if(count % 2 == 0)
{
// Begin new Char
currentChar = pix.Blue & 0x0F;
}
else
{
// Add to current char
currentChar <<= 4;
currentChar += pix.Blue & 0x0F;
ret << currentChar;
}
count++;
}
}
end:
return ret.str();
}
示例8: rowMatch
int rowMatch (BMP& UseTop, BMP& UseBottom )
{ // Compares the top edge of UseTop to the bottom edge of UseBottom.
// Assumes UseTop and UseBottom are squares of same size
// score obtained by adding the difference between color components
int rowSize = UseTop.TellWidth();
int total = 0;
RGBApixel pixelTop;
RGBApixel pixelBottom;
for (int i = 0; i < rowSize; i++) {
pixelTop = UseTop.GetPixel(i, 0);
pixelBottom = UseBottom.GetPixel(i, rowSize - 1);
total += abs(pixelTop.Red - pixelBottom.Red) +
abs(pixelTop.Green - pixelBottom.Green) +
abs(pixelTop.Blue - pixelBottom.Blue);
}
return total;
}
示例9: copy
void copy(BMP & InImg, BMP & OutImg, int xPos, int yPos) {
// copy image to larger final picture so that the InImg is placed in row i, column j of OutImg
int width = InImg.TellWidth();
RGBApixel curPixel;
for (int i = 0; i < width; i++) {
for (int j = 0; j < width; j++) {
curPixel = InImg.GetPixel(i, j);
OutImg.SetPixel(xPos * width + i, yPos * width + j, curPixel);
}
}
}
示例10: columnMatch
int columnMatch ( BMP& UseLeft, BMP& UseRight )
{
// Compares the left edge of UseLeft to the right edge of UseRight.
// Assumes UseRight and UseLeft are squares of same size
// score obtained by adding the difference between color components
// similar to the rowMatch
int columnSize = UseLeft.TellWidth();
int total = 0;
RGBApixel pixelLeft;
RGBApixel pixelRight;
for (int i = 0; i < columnSize; i++) {
pixelLeft = UseLeft.GetPixel(0,i);
pixelRight = UseRight.GetPixel(columnSize - 1, i);
total += abs(pixelLeft.Red - pixelRight.Red) +
abs(pixelLeft.Green - pixelRight.Green) +
abs(pixelLeft.Blue - pixelRight.Blue);
}
return total;
}
示例11: BMP2graydata
void BMP2graydata(BMP& bmp, unsigned char* data){
int k=0;
int width =bmp.TellWidth();
int height=bmp.TellHeight();
for (int i=0; i<height; i++){
for (int j=0; j<width; j++){
RGBApixel pix=bmp.GetPixel(j,i );
data[k++]=pix.Blue;
//src[k++]= 0.2126 * pix.Red + 0.7152 * pix.Green + 0.0722 * pix.Blue;
}
}
}
示例12: LoadFont
void CBarBitmapWin32::DrawDigit(int left, int top,
char num)
{
BMP eBmp;
LoadFont(IDB_FONT_NUM, eBmp);
int leftMargin=8*(num-'0');
for (int i=0; i<8; i++)
for (int j=0; j<12; j++)
m_bmp->SetPixel(left+i,
top+j,
eBmp.GetPixel(leftMargin+i, j));
}
示例13:
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;
}
示例14: fromBMP
QImage fromBMP(QString &file)
{
QImage errImg;
BMP tarBMP;
if(!tarBMP.ReadFromFile( file.toLocal8Bit().data() )){
//WriteToLog(QtCriticalMsg, QString("Error: File does not exsist"));
return errImg; //Check if empty with errImg.isNull();
}
QImage bmpImg(tarBMP.TellWidth(),tarBMP.TellHeight(),QImage::Format_RGB666);
for(int x = 0; x < tarBMP.TellWidth(); x++){
for(int y = 0; y < tarBMP.TellHeight(); y++){
RGBApixel pixAt = tarBMP.GetPixel(x,y);
bmpImg.setPixel(x,y,qRgb(pixAt.Red, pixAt.Green, pixAt.Blue));
}
}
return bmpImg;
}
示例15: main
int main(int argc, char** argv){
#ifdef __APPLE__
// Needed in OSX to force use of OpenGL3.2
glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, 3);
glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 2);
glfwOpenWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
glfwOpenWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
#endif
// Set up pathtracer stuff
bool loadedScene = false;
finishedRender = false;
targetFrame = 0;
singleFrameMode = false;
// Load scene file
for(int i=1; i<argc; i++){
string header; string data;
istringstream liness(argv[i]);
getline(liness, header, '='); getline(liness, data, '=');
if(strcmp(header.c_str(), "scene")==0){
renderScene = new scene(data);
loadedScene = true;
}else if(strcmp(header.c_str(), "frame")==0){
targetFrame = atoi(data.c_str());
singleFrameMode = true;
}
}
if(!loadedScene){
cout << "Error: scene file needed!" << endl;
return 0;
}
// Set up camera stuff from loaded pathtracer settings
iterations = 0;
renderCam = &renderScene->renderCam;
parameterSet = &renderScene->parameterSet;
width = renderCam->resolution[0];
height = renderCam->resolution[1];
textures=new m_BMP[renderScene->bmps.size()];
int i,j,k;
for(i=0;i<renderScene->bmps.size();i++)
{
//int w=renderScene->bmps[i]->Width;
//int h=renderScene->bmps[i]->Height;
BMP now;
now.ReadFromFile(renderScene->bmps[i].c_str());
int h=now.TellHeight();int w=now.TellWidth();
textures[i].resolution=glm::vec2(w,h);
textures[i].colors=new glm::vec3[w*h];
for(j=0;j<w;j++)for(k=0;k<h;k++)
{
RGBApixel current=now.GetPixel(j,k);
textures[i].colors[j*h+k]=glm::vec3(current.Red,current.Green,current.Blue)*(1.0f/255.0f);
}
}
if(targetFrame>=renderCam->frames){
cout << "Warning: Specified target frame is out of range, defaulting to frame 0." << endl;
targetFrame = 0;
}
// Launch CUDA/GL
#ifdef __APPLE__
init();
#else
init(argc, argv);
#endif
initCuda();
initVAO();
initTextures();
GLuint passthroughProgram;
passthroughProgram = initShader("shaders/passthroughVS.glsl", "shaders/passthroughFS.glsl");
glUseProgram(passthroughProgram);
glActiveTexture(GL_TEXTURE0);
starttime=clock();
#ifdef __APPLE__
// send into GLFW main loop
while(1){
display();
if (glfwGetKey(GLFW_KEY_ESC) == GLFW_PRESS || !glfwGetWindowParam( GLFW_OPENED )){
exit(0);
}
}
glfwTerminate();
#else
glutDisplayFunc(display);
glutKeyboardFunc(keyboard);
glutMainLoop();
//.........这里部分代码省略.........