当前位置: 首页>>代码示例>>C++>>正文


C++ BMP类代码示例

本文整理汇总了C++中BMP的典型用法代码示例。如果您正苦于以下问题:C++ BMP类的具体用法?C++ BMP怎么用?C++ BMP使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了BMP类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: main

/**
* function main starts here
**/
int main()
{
/**
* define test1 and output as BMP image
**/
  BMP test1;
  BMP output;
/**
* loads "in.bmp" into test1.
**/
  test1.readFromFile("in.bmp");
//test1.readFromFile("in.bmp");
/**
* loads "in.bmp" into output.
**/
  output.readFromFile("in.bmp");
/**
* call function reverse to rotate the test1 by 180 degree.and
* load the reversed image to image output
**/
  output = reverse(test1, test1.tellWidth(),
                test1.tellHeight(), output);
/**writes the image output to the disk
**/
  output.writeToFile("out.bmp");
return 0;

}
开发者ID:minyin2,项目名称:cloudDocs,代码行数:31,代码来源:main.cpp

示例2: Get4Pixels16Bit

/**
@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());
}
开发者ID:alisakhatipova,项目名称:ObjectClassification-SSEacceleration,代码行数:43,代码来源:task2.cpp

示例3: 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;
}
开发者ID:zachary-williamson,项目名称:robotics-bosscode,代码行数:33,代码来源:Image.cpp

示例4: writeFile

//store output data to disk
void writeFile(BMP img, int id, int iter){
	string name;
	stringstream sstm;
	if(id==1){
		for (short i =0; i<HEIGHT; i++){
			for (short j = 0; j<WIDTH; j++){
				img(i,j)->Red = (label[i][j] +3)*42; //normalize to [0, 255]
				img(i,j)->Green = (label[i][j] +3)*42;
				img(i,j)->Blue = (label[i][j] +3)*42;
			}
		}
		
		sstm << iter << "label" <<".bmp";
		name = sstm.str();
		img.WriteToFile(name.c_str());
		printf("\nlabel image stored");
	}
	else{ //zeroLevelSet
		for (short i =0; i<HEIGHT; i++){
			for (short j = 0; j<WIDTH; j++){
				img(i,j)->Red = zeroLevelSet[i][j]; 
				img(i,j)->Green = zeroLevelSet[i][j]; 
				img(i,j)->Blue = zeroLevelSet[i][j]; 
			}
		}
		sstm << iter << "zero" <<".bmp";
		name = sstm.str();
		img.WriteToFile(name.c_str());
		printf("\nzero image stored\n");
	}
}
开发者ID:N4TT,项目名称:LevelSet,代码行数:32,代码来源:main.cpp

示例5: if

// 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);
            }
        }
    }

}
开发者ID:ibrahim-amer,项目名称:StereoVision,代码行数:28,代码来源:cimage.cpp

示例6: 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;
}
开发者ID:ibrahim-amer,项目名称:StereoVision,代码行数:29,代码来源:cimage.cpp

示例7: 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;
}
开发者ID:khutchins,项目名称:Naive-Raytracer,代码行数:28,代码来源:ObjSphere.cpp

示例8: writeFile

void writeFile(BMP img, int id){
	if(id == 1){ //label
		for (int i =0; i<HEIGHT; i++){
			for (int j = 0; j<WIDTH; j++){
				img(i,j)->Red = (label[i][j] +3)*42; //normalize to [0, 255]
				img(i,j)->Green = (label[i][j] +3)*42;
				img(i,j)->Blue = (label[i][j] +3)*42;
			}
		}
		img.WriteToFile("output label.bmp");
		printf("\nlabel image stored");
	}
	else{ //zeroLevelSet
		for (int i =0; i<HEIGHT; i++){
			for (int j = 0; j<WIDTH; j++){
				//printf(" (%i,%i) ", i, j);
				img(i,j)->Red = zeroLevelSet[i][j]; 
				img(i,j)->Green = zeroLevelSet[i][j]; 
				img(i,j)->Blue = zeroLevelSet[i][j]; 
			}
		}
		img.WriteToFile("output zero.bmp");
		printf("\nzero image stored\n");
	}
}
开发者ID:N4TT,项目名称:LevelSet,代码行数:25,代码来源:IO.cpp

示例9: main

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;
}
开发者ID:RC-MODULE,项目名称:sobel-steps,代码行数:59,代码来源:main.cpp

示例10: n_GetImageBAtPos

static cell AMX_NATIVE_CALL n_GetImageBAtPos( AMX* amx, cell* params ){
	amx_StrParam(amx,params[1],tmp);
	BMP Image;
	Image.ReadFromFile(tmp);
	posx = params[2];
	posy = params[3];
	return Image(posx,posy)->Blue;
}
开发者ID:berke123123,项目名称:GPB,代码行数:8,代码来源:pwncurl.cpp

示例11: 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);
}
开发者ID:krupkad,项目名称:Krender,代码行数:58,代码来源:camera.cpp

示例12: 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;
}
开发者ID:zachary-williamson,项目名称:robotics-bosscode,代码行数:58,代码来源:Image.cpp

示例13: main

int main(int argc, char * argv[])
{
    if (argc < 3)
    {
        std::cerr << "Usage: " << argv[0] << " <font name> <font image>...\n";
        return 1;
    }

    // Average symbol information
    std::map<char, OCR::Font::Symbol> average;

    // Image
    BMP img;

    // Load a non-existent font
    OCR::Font bogus("BOGUS");

    // Open file for output
    std::string outFileName = argv[1];
    outFileName = "font/" + outFileName + ".font";
    std::ofstream outFile(outFileName.c_str());

    // Load each line and read its statistics
    for (int fileNum = 2; fileNum < argc; ++fileNum)
    {
        // Create line
        img.ReadFromFile(argv[fileNum]);
        OCR::Line line(img, bogus);

        // Create vector for symbol info
        std::vector<OCR::Font::Symbol> symbols;
        symbols.reserve(ALPHABET.size());

        // Do the reading
        line.Read(&symbols);

        // Loop through and add to the "average"
        std::vector<OCR::Font::Symbol>::iterator itr = symbols.begin();
        for (unsigned charIndex = 0; itr != symbols.end() && charIndex
                < ALPHABET .size(); ++itr, ++charIndex)
        {
            average[ALPHABET[charIndex]] += *itr;
        }
    }

    for (std::map<char, OCR::Font::Symbol>::iterator itr = average.begin(); itr
            != average.end(); ++itr)
    {
        // Divide all statistics by number of lines read
        itr->second /= (argc - 2);
        // Print the character and its statistics to the file
        outFile << itr->first << ' ' << itr->second << std::endl;
    }

    outFile.close();
    return 0;
}
开发者ID:ArumugamG,项目名称:OCR,代码行数:57,代码来源:learn.cpp

示例14: n_SetImageSize

static cell AMX_NATIVE_CALL n_SetImageSize( AMX* amx, cell* params ){
	amx_StrParam(amx,params[1],tmp);
	posx = params[2];
	posy = params[3];
	BMP Image;
	Image.ReadFromFile(tmp);
	Image.CreateStandardColorTable();
	Image.SetSize(posx,posy);
	return Image.WriteToFile(tmp);
}
开发者ID:berke123123,项目名称:GPB,代码行数:10,代码来源:pwncurl.cpp

示例15: LoadImages

/**Load images by list of files 'file_list' and store them in 'data_set'

*/
void LoadImages(const TFileList& file_list, TDataSet* data_set) {
    for (size_t img_idx = 0; img_idx < file_list.size(); ++img_idx) {
            // Create image
        BMP* image = new BMP();
            // Read image from file
        image->ReadFromFile(file_list[img_idx].first.c_str());
            // Add image and it's label to dataset
        data_set->push_back(make_pair(image, file_list[img_idx].second));
    }
}
开发者ID:alisakhatipova,项目名称:ObjectClassification-SSEacceleration,代码行数:13,代码来源:task2.cpp


注:本文中的BMP类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。