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; }
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); } }
bool EasyBMP_Screenshot( const char* FileName ) { BMP Output; GLsizei viewport[4]; glGetIntegerv( GL_VIEWPORT , viewport ); int width = viewport[2] - viewport[0]; int height = viewport[3] - viewport[1]; Output.SetSize(width,height); GLint swapbytes, lsbfirst, rowlength, skiprows, skippixels, alignment; /* Save current pixel store state. */ glGetIntegerv(GL_UNPACK_SWAP_BYTES, &swapbytes); glGetIntegerv(GL_UNPACK_LSB_FIRST, &lsbfirst); glGetIntegerv(GL_UNPACK_ROW_LENGTH, &rowlength); glGetIntegerv(GL_UNPACK_SKIP_ROWS, &skiprows); glGetIntegerv(GL_UNPACK_SKIP_PIXELS, &skippixels); glGetIntegerv(GL_UNPACK_ALIGNMENT, &alignment); /* Set desired pixel store state. */ glPixelStorei(GL_UNPACK_SWAP_BYTES, GL_FALSE); glPixelStorei(GL_UNPACK_LSB_FIRST, GL_FALSE); glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); glPixelStorei(GL_UNPACK_SKIP_ROWS, 0); glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0); glPixelStorei(GL_UNPACK_ALIGNMENT, 1); RGBApixel* pixels; pixels = new RGBApixel [ Output.TellWidth() * Output.TellHeight() ]; glReadPixels( viewport[0],viewport[1], width,height, GL_RGBA, GL_UNSIGNED_BYTE, pixels); int n=0; for( int j=Output.TellHeight()-1 ; j >= 0 ; j-- ) { for( int i=0; i < Output.TellWidth() ; i++ ) { Output(i,j)->Red = (pixels[n]).Blue; Output(i,j)->Green = (pixels[n]).Green; Output(i,j)->Blue = (pixels[n]).Red; n++; } } /* Restore current pixel store state. */ glPixelStorei(GL_UNPACK_SWAP_BYTES, swapbytes); glPixelStorei(GL_UNPACK_LSB_FIRST, lsbfirst); glPixelStorei(GL_UNPACK_ROW_LENGTH, rowlength); glPixelStorei(GL_UNPACK_SKIP_ROWS, skiprows); glPixelStorei(GL_UNPACK_SKIP_PIXELS, skippixels); glPixelStorei(GL_UNPACK_ALIGNMENT, alignment); Output.WriteToFile( FileName ); return true; }
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; }
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; }
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; }
void CopyBMP( BMP& Input , BMP& Output ) { Output.SetSize( Input.TellWidth() , Input.TellHeight() ); for( int j=0 ; j < Input.TellHeight() ; j++ ) { for( int i=0 ; i < Input.TellWidth() ; i++ ) { *Output(i,j) = *Input(i,j); } } return; }
void pacmanTests() { cout << "Testing PacMan" << endl; // PAC MAN BFS BMP img; img.ReadFromFile("pacMan.bmp"); rainbowColorPicker BFSfiller(1.0/1000.0); animation pacManBFS = BFSfill(img, img.TellWidth()/2, img.TellHeight()/2, BFSfiller, 8000, INT_MAX); img.WriteToFile("pacManBFS.bmp"); cout << "\tWrote pacManBFS.bmp" << endl; //blueManBFS.write("pacManBFS.gif"); // PAC MAN DFS img.ReadFromFile("pacMan.bmp"); rainbowColorPicker DFSfiller(1.0/1000.0); animation pacManDFS = DFSfill(img, img.TellWidth()/2, img.TellHeight()/2, DFSfiller, 8000, INT_MAX); img.WriteToFile("pacManDFS.bmp"); cout << "\tWrote pacManDFS.bmp" << endl; // Make ANTI image BMP antiImg; antiImg.ReadFromFile("pacMan.bmp"); RGBApixel black; black.Red = black.Green = black.Blue = 0; RGBApixel grey; grey.Red = grey.Green = grey.Blue = 1; BFSfillSolid(antiImg, 10, 10, grey, 8000, INT_MAX); BFSfillSolid(antiImg, antiImg.TellWidth()/2, antiImg.TellHeight()/2, black, 8000, INT_MAX); // ANTI PAC MAN BFS img = antiImg; rainbowColorPicker aBFSfiller(1.0/1000.0); animation aManBFS = BFSfill(img, 20, 20, aBFSfiller, 0, 2000); //img.WriteToFile("antiPacManBFS.bmp"); aManBFS.write("antiPacManBFS.gif"); cout << "\tWrote antiPacManBFS.gif" << endl; // ANTI PAC MAN DFS img = antiImg; rainbowColorPicker aDFSfiller(1.0/1000.0); animation aManDFS = DFSfill(img, 20, 20, aDFSfiller, 0, 2000); //img.WriteToFile("antiPacManDFS.bmp"); aManDFS.write("antiPacManDFS.gif"); cout << "\tWrote antiPacManDFS.gif" << endl; }
// filename is a BMP file CImage::CImage(const char * filename, int colors) { BMP bmp; bmp.ReadFromFile(filename); init(bmp.TellWidth(), bmp.TellHeight(), colors); // convert pixels to float values for (int col = 0; col < m_width; col++) { for (int row = 0; row < m_height; row++) { RGBApixel* pixel = bmp(col, row); // m_color == 1 means grayscale... so all components should be equal // (i.e. Red = Green = Blue) if (m_color == 1) setValue(row, col, 0, (float) pixel->Red); else if (m_color == 3) { setValue(row, col, 0, (float) pixel->Red); setValue(row, col, 1, (float) pixel->Green); setValue(row, col, 2, (float) pixel->Blue); } } } }
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; }
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; }
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; }
inline float CubicFilter(int x, int y, const int Radius) { const int DatSize = POW2((Radius << 1) + 1); float *Dat = new float[DatSize]; Cint2 Offset = {x-Radius, y-Radius}; float Accum = 0.0f; int Denom = 0; int w = Bmp.TellWidth(); int h = Bmp.TellHeight(); for(int Cpt = 0; Cpt < DatSize; Cpt++){ if(Offset.x >= 0 && Offset.x < w && Offset.y >= 0 && Offset.y < h){ Accum += RGBMIXER(Offset.x, Offset.y); Denom++; } Offset.x++; if(Offset.x - x > Radius){ Offset.x = x-Radius; Offset.y++; } } SAFE_DELETE_ARRAY(Dat); return Accum / (float)Denom; }
int main() { BMP srcBMP; srcBMP.ReadFromFile("../../../../input/lena.bmp"); BMP dstBMP(srcBMP); int width =srcBMP.TellWidth(); int height=srcBMP.TellHeight(); int size =width*height; unsigned char* srcData= new unsigned char[width*height]; unsigned char* dstData= new unsigned char[width*height]; BMP2graydata(srcBMP, srcData); //sobel( srcData, dstData, width, height); //------- run sobel on nmc -------------- // Access and loading program to nm-board C_PC_Connector_mc5103 Connector(PROGRAM); if (!Connector.isConnected()){ printf("Connection to mc5103 error!"); return -1; } int handshake= Connector.Sync(0xC0DE0086); if (handshake!=0xC0DE6406){ printf("Handshake with mc5103 error!"); return -1; } int ok; ok=Connector.Sync(width); // Send width to nmc ok=Connector.Sync(height); // Send height to nmc ok=Connector.Sync(0); // Get status of memory allocation from nm if (ok!=0x600DB00F){ printf("Memory allocation error!"); return -1; } unsigned srcAddr=Connector.Sync(0); unsigned dstAddr=Connector.Sync(0); Connector.WriteMemBlock((unsigned*)srcData, srcAddr, size/4); // Send data to NMC Connector.Sync(0); // Barrier sync before call of Sobel filter on NMC //... wait while sobel is runing on board unsigned t=Connector.Sync(0); // Barrier sync. Wait until Sobel filter is finished Connector.ReadMemBlock ((unsigned*)dstData, dstAddr, size/4); // Recieve result data from NMC //---------------------- graydata2BMP(dstData, dstBMP); dstBMP.WriteToFile("dst.bmp"); delete srcData; delete dstData; return 0; }
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(); }
HBITMAP BMPtoHBITMAP(HDC hDC,BMP& Input) { HBITMAP Output = CreateCompatibleBitmap( hDC , Input.TellWidth(), Input.TellHeight() ); // create an array of bytes from the BMP pixels BYTE* pData; pData = new BYTE [Input.TellWidth()*Input.TellHeight()*4]; int i,j; int k=0; for( j= Input.TellHeight()-1 ; j >= 0 ; j-- ) { for( i=0 ; i < Input.TellWidth() ; i++ ) { *(pData+k) = Input(i,j)->Blue; k++; *(pData+k) = Input(i,j)->Green; k++; *(pData+k) = Input(i,j)->Red; k++; *(pData+k) = Input(i,j)->Alpha; k++; } } // create the BITMAPINFO data structure BITMAPINFO BitInfo; ZeroMemory(&BitInfo, sizeof(BITMAPINFO)); BitInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); BitInfo.bmiHeader.biWidth = Input.TellWidth(); BitInfo.bmiHeader.biHeight = Input.TellHeight(); BitInfo.bmiHeader.biPlanes = 1; BitInfo.bmiHeader.biBitCount = 32; BitInfo.bmiHeader.biCompression = 0; BitInfo.bmiHeader.biSizeImage = Input.TellWidth()*Input.TellHeight()*4; BitInfo.bmiHeader.biXPelsPerMeter = 0; BitInfo.bmiHeader.biYPelsPerMeter = 0; BitInfo.bmiHeader.biClrUsed = 0; BitInfo.bmiHeader.biClrImportant = 0; SetDIBits( hDC, Output, 0, Input.TellHeight() , pData , &BitInfo , DIB_RGB_COLORS ); return Output; }
//more specific default ctor for Quadtree // parameters: &BMP img - image passed that will be the foundation // for the tree // d - variable that tells the dimensions of the Quadtree::Quadtree(BMP & img, int d){ //check if d is in proper range if ((d>img.TellWidth())||(d>img.TellHeight())||(d<=0)) root=NULL; //when d is in proper range then make root point to a node and //do the BuildTree function else{ root=new QuadtreeNode(d); buildTree(img, d); } }
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; }
void main () { BMP picture; picture.ReadFromFile("a.bmp"); std::vector<std::vector<rect> > r = get_char_rects(picture); std::vector<std::vector<rect> >::iterator it = r.begin(); for (; it != r.end(); it++) { std::vector<rect>::iterator itt = (*it).begin(); for (; itt != (*it).end(); itt++) { // std::cout << "((" << itt->first.first << ", " << itt->first.second << "), (" << itt->second.first << ", " << itt->second.second << "))" << std::endl; std::cout << (double)itt->first.first / picture.TellWidth() << ", " << 1.0 - ((double)itt->first.second / picture.TellHeight()) << ", " << (double)itt->second.first / picture.TellWidth() << ", " << 1.0 - ((double)itt->second.second / picture.TellHeight()) << ", " << std::endl; } } system("PAUSE"); }
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); } } }
d_surf * _surf_load_bmp(const char * filename, const char * surfname, REAL minz, REAL maxz, REAL startX, REAL startY, REAL stepX, REAL stepY) { writelog(LOG_MESSAGE, "loading surface from BMP file %s",filename); BMP bmp; if (bmp.ReadFromFile(filename) == false) { writelog(LOG_ERROR,"Error loading surface from bitmap!"); return NULL; } size_t NN = bmp.TellWidth(); size_t MM = bmp.TellHeight(); extvec * coeff = create_extvec( NN*MM, 0, 0, 0); size_t i,j; double gray_color; double alpha; for (j = 0; j < MM; j++) { for (i = 0; i < NN; i++) { gray_color = bmp(i,j)->Red * 0.299 + bmp(i,j)->Green * 0.587 + bmp(i,j)->Blue * 0.114; alpha = bmp(i,j)->Alpha; if (alpha == 255) (*coeff)(i + (MM-1-j)*NN) = undef_value; else { if (minz != maxz) (*coeff)(i + (MM-1-j)*NN) = (maxz-minz)*gray_color/REAL(255) + minz; else (*coeff)(i + (MM-1-j)*NN) = gray_color; } } } d_grid * grd = create_grid(startX, startX + stepX*(NN-1), stepX, startY, startY + stepY*(MM-1), stepY); d_surf * res = create_surf(coeff, grd); if (surfname) res->setName(surfname); else { char * name = get_name(filename); res->setName(name); sstuff_free_char(name); } return res; };
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; } } }
//negatyw z obrazu void negatyw(BMP& obraz) { for( int j=0 ; j < obraz.TellHeight() ; j++) { for( int i=0 ; i < obraz.TellWidth() ; i++) { obraz(i,j)->Red = 255 - obraz(i,j)->Red; obraz(i,j)->Green = 255 - obraz(i,j)->Green; obraz(i,j)->Blue = 255 - obraz(i,j)->Blue; } } //return 0; }
void EasyBMP_Texture::ImportBMP( BMP& InputImage ) { OriginalWidth = InputImage.TellWidth(); OriginalHeight = InputImage.TellHeight(); MaxX = (GLfloat) InputImage.TellWidth(); MaxY = (GLfloat) InputImage.TellHeight(); OpenGLpadBMP( InputImage ); MaxX /= (GLfloat) InputImage.TellWidth(); MaxY /= (GLfloat) InputImage.TellHeight(); SetSize( InputImage.TellWidth() , InputImage.TellHeight() ); if( Texture != NULL ) { delete [] Texture; } Texture = BMPtoTexture( InputImage ); return; }
void setup(string const & filename, List<RGBApixel> & pixelList, int & width, int & height) { BMP imgIn; imgIn.ReadFromFile(filename.c_str()); width = imgIn.TellWidth(); height = imgIn.TellHeight(); // fill list with pixels pixelList.clear(); for (int y = 0; y < height; y++) for(int x = 0; x < width; x++) pixelList.insertAfter(*imgIn(x,y)); }
int main (){ // initializing variables bool sucess; BMP in; BMP out; int width,height,i,j,new_j,new_i; // Set Classes to contain image sucess=in.ReadFromFile("in.bmp"); //cout<<sucess<<endl; sucess=out.ReadFromFile("in.bmp"); //cout<<sucess<<endl; // Find height and width // starting from 0 not 1 so decrement width=(in.TellWidth()); width--; height=in.TellHeight(); height--; //cout<<in.TellWidth()<<endl; //cout<<in.TellHeight()<<endl; // runs horizontally across the image for (i=0;i<=width;i++){ // runs vertically across image for (j=0;j<=height;j++){ // code for finding pixel to change new_i=width-i; new_j=height-j; // code for changing output image out(new_i,new_j)->Red =in(i,j)->Red; out(new_i,new_j)->Green =in(i,j)->Green; out(new_i,new_j)->Blue =in(i,j)->Blue; } } //cout<<"Exiting For loops"<<endl; // write output image to disk out.WriteToFile("out.bmp"); //cout<<"Finished writing out.bmp"<<endl; return 0; }
int main( int argc, char* argv[] ) { const int width = 3, thresh = 5; BMFH bmfh = GetBMFH(argv[1]); if (bmfh.bfType != BMP::BMP_FILE_TYPE) { return -1; } BMP inImage; inImage.ReadFromFile(argv[1]); BMP outImage; outImage.SetSize(inImage.TellWidth(), inImage.TellHeight()); outImage.SetBitDepth(24); const int numNbr = (2 * width + 1) * (2 * width + 1) - 1; for( int i=width ; i < inImage.TellWidth()-width ; i++) { for( int j=width ; j < inImage.TellHeight()-width ; j++) { // find average of neighboring input pixels int rPij = 0, gPij = 0, bPij = 0; for (int di = -width; di <= width; ++di) { for (int dj = -width; dj <= width; ++dj) { if (di == 0 && dj == 0) continue; rPij += inImage.redPixel(i+di, j+dj); gPij += inImage.greenPixel(i+di, j+dj); bPij += inImage.bluePixel(i+di, j+dj); } } outImage.redPixel(i,j) = filter(inImage.redPixel(i,j), rPij / numNbr, thresh); outImage.greenPixel(i,j) = filter(inImage.greenPixel(i,j), gPij / numNbr, thresh); outImage.bluePixel(i,j) = filter(inImage.bluePixel(i,j), bPij / numNbr, thresh); } } outImage.WriteToFile(argv[2]); return 0; }
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; }
void graydata2BMP(unsigned char* data, BMP& bmp ){ 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; pix.Blue =data[k]; pix.Red =data[k]; pix.Green=data[k]; bmp.SetPixel(j,i,pix); k++; } } }
// Compares the top edge of UseTop to the bottom edge of UseBottom. // Assumes both inputs are squares of same size // score obtained by adding the difference between color components // squaring not used so that the numbers don't become too large int rowMatch (BMP& UseTop, BMP& UseBottom) { int height = UseTop.TellHeight(); int width = UseBottom.TellWidth(); int RowScore = 0; int Red = 0; int Green = 0; int Blue = 0; for (int i = 0; i < height-1; i++) { Red = abs(UseTop(i, 0)->Red - UseBottom(i, height-1)->Red); Green = abs(UseTop(i, 0)->Green - UseBottom(i, height-1)->Green); Blue = abs(UseTop(i, 0)->Blue - UseBottom(i, height-1)->Blue); RowScore += Red + Green + Blue; } return RowScore; }