Beispiel #1
0
void InitImage(int minX, int maxX, int minY, int maxY, int mpiRank, 
               Image &img, bool randomSizedImage)
{
  int dimsX = maxX - minX;
  int dimsY = maxY - minY;
  // random image dimension
  int rminX = minX + rand() % (dimsX-1);
  int rminY = minY + rand() % (dimsY-1);
  int rmaxX = rminX + 1 + rand() % (maxX - (rminX+1));
  int rmaxY = rminY + 1 + rand() % (maxY - (rminY+1));
  // random image 
  float depth = (rand() % 100)/100.0;
  // random color
  Color color;
  color.r = (rand() % 256)/256.0;
  color.g = (rand() % 256)/256.0;
  color.b = (rand() % 256)/256.0;
  color.a = (rand() % 256)/256.0;
  // create image
  Timer clock;
  clock.Start();
  if (randomSizedImage) { // random sized images    
    img.CreateImage(rminX, rmaxX, rminY, rmaxY);
    img.ColorImage(color);
  }
  else { // full sized images with bounding box    
    img.CreateImage(maxX, maxY, rminX, rmaxX, rminY, rmaxY);
    img.ColorImage(color, rminX, rmaxX, rminY, rmaxY);
  }
  img.SetDepth(depth);
  clock.Stop();
}
Beispiel #2
0
	//------------------------------------------------------------------------------------
	// Building the mipmap for a tile based image
	//------------------------------------------------------------------------------------
	bool Image::BuildTileMipMap( int NumCols, int NumRows )
	{
		BuildMipMaps();

		int tW			= m_iWidth  / NumCols;
		int tH			= m_iHeight / NumRows;
		int mipmapLevel = 1;
		int maxmipmaplevel = 0;
		u8* pTempData	= KGE_NEW_ARRAY(u8, tW * tH * 4);
		int t = 1, tth, ttw;

		Image* imgTemp = KGE_NEW(Image)("Temp");
		imgTemp->CreateImage(tW, tH, 1, 4, EIF_RGBA, 0);

		int wi = m_iWidth;
		while (wi > NumCols)
		{
			wi /= 2;
			maxmipmaplevel++;
		}

		io::Logger::Log(io::ELM_Warning, "mmm = %d", maxmipmaplevel);

		for ( int j = 0; j < maxmipmaplevel - 1; j++)
		{
			for (int y = 0; y < NumRows; y++)
			{
				for (int x = 0; x < NumCols; x++)
				{
					GetPixels(x * tW , y * tH, 1, tW, tH, 1, EIF_BGRA, pTempData);
					imgTemp->SetData(pTempData);
					t = math::pow(2, mipmapLevel);
					ttw = tW / t;
					tth = tH / t;
					imgTemp->Scale(ttw, tth, 1);
					SetPixels(x * ttw, y * tth, 1, ttw, tth, 1, EIF_BGRA,
						imgTemp->GetData(), mipmapLevel);

				} // for x

			} // for y

			mipmapLevel++;

		} // for j

		// TODO: Not tested
		KGE_DELETE_ARRAY(pTempData);
		KGE_DELETE(imgTemp, Image);

		return true;

	} // BuildTileMipMap
Beispiel #3
0
int main(int argc, char **argv) 
{
    Image image;
    
    if(image.Load("calculon640.jpg"))
    {
        /*
        for(unsigned int i = 0; i < image.mDataSize; i+= 3)
        {
            image.mpImage[i+1] = 0;
            image.mpImage[i+2] = 0;
        }
        */
        /*
        unsigned char* buffer = new unsigned char[6000];
        unsigned int len = 6000;
        unsigned int clen = 6000;
        double startTimeS = CxUtils::Timer::GetTimeSeconds();
        for(unsigned int i = 0; i < 100; i++)
        {
            image.Compress(&buffer, &len, &clen, Image::JPEG);
        }
        double finishTimeS = CxUtils::Timer::GetTimeSeconds();
        std::cout << "FPS: " << 100/(finishTimeS - startTimeS) << std::endl;
        */
        //unsigned char* buffer = NULL;
        //unsigned int bufferSize = 0;
        //unsigned int compressSize = 0;
        //image.Compress(&buffer, &bufferSize, &compressSize, Image::JPEG);
        //image.Decompress(buffer, compressSize, Image::JPEG);
        if(image.Save("calculon640_copy.jpg") && image.Save("calculon640_copy.png"))
        {
            cout << "Saved a copy of the image as a JPEG and PNG!\n";
        }

        Image tile;
        tile.CreateImage(image.mWidth, image.mHeight, image.mChannels, image.mpImage, 320, 240, true, true);
        image.ApplyTile(tile);
        image.Save("tile.jpg");
    }

    return 0;
}