This project is read-only.

Disscuss of CreatePyramids function

Oct 9, 2011 at 5:51 PM

Something about my Implementation of the CreatePyramids function.

The original CreatePyramids function load the level 0 image  like that

 int w = _header.ImageHeaders[0].NumColumns;
            int h = _header.ImageHeaders[0].NumRows;
            int blockHeight = 32000000 / w;
            if (blockHeight > h) blockHeight = h;
            int numBlocks = (int)Math.Ceiling(h / (double)blockHeight);
            ProgressMeter pm = new ProgressMeter(ProgressHandler, "Generating Pyramids",
                _header.ImageHeaders.Length * numBlocks);
            for (int block = 0; block < numBlocks; block++)
            {
                // Normally block height except for the lowest block which is usually smaller
                int bh = blockHeight;
                if (block == numBlocks - 1) bh = h - block * blockHeight;

                // Read a block of bytes into a bitmap
                byte[] vals = ReadWindow(block * blockHeight, 0, bh, w, 0);

                Bitmap bmp = new Bitmap(w, bh);
                BitmapData bd = bmp.LockBits(new Rectangle(0, 0, w, bh), ImageLockMode.WriteOnly,
                                              PixelFormat.Format32bppArgb);
                Marshal.Copy(vals, 0, bd.Scan0, vals.Length);
                bmp.UnlockBits(bd);

	
When w> 10000 , new Bitmap(w, bh) alway failed

I change the loading method with fixed size.The beginning part of the function is like that

 
	int w = _header.ImageHeaders[0].NumColumns;           
        int h = _header.ImageHeaders[0].NumRows;    
        //fix size to 5k     
       int blockHeight = 4096;       
       int blockWidth = 4096;            //           
       if (blockHeight > h) blockHeight = h;            if (blockWidth > w) blockWidth = w;            int numHBlocks = (int)Math.Ceiling(h / (double)blockHeight);            int numWBlocks = (int)Math.Ceiling(w / (double)blockWidth);
            ProgressMeter pm = new ProgressMeter(ProgressHandler, "Generating Pyramids", _header.ImageHeaders.Length * numHBlocks * numWBlocks);
            for (int blockw = 0; blockw < numWBlocks; blockw++)               
              for (int blockh = 0; blockh < numHBlocks; blockh++)                
			int bh = blockHeight;
			if (blockh == numHBlocks - 1) bh = h - blockh * blockHeight;
			int bw = blockWidth;                   
                         if (blockw == numWBlocks - 1) bw = w - blockw * blockWidth;
			byte[] vals = ReadWindow(blockh * blockHeight, blockw * blockWidth, bh, bw, 0);
                    	Bitmap bmp = new Bitmap(bw, bh); 
	                   BitmapData bd = bmp.LockBits(new Rectangle(0, 0, bw, bh), ImageLockMode.WriteOnly,PixelFormat.Format32bppArgb);
	                    Marshal.Copy(vals, 0, bd.Scan0, vals.Length); 
                   bmp.UnlockBits(bd);

bw and bh will not be too large for Bitmap
By fixing the level0 Bitmap size, I got a workable pyramidsimage class, but I don't think it's a good method to build pyramids
Does anyone have any suggestion?