private Bitmap BuildBitmap(T[][] buffers, LevelDef level, TileIdentify tile) { using (IBitmapBuilder <T> builder = GetBitmapBuilder()) { Bitmap bitmap = null; if (buffers.Length == 1) { bitmap = new Bitmap(_tileSize, _tileSize, PixelFormat.Format8bppIndexed); bitmap.Palette = BitmapBuilderFactory.GetDefaultGrayColorPalette(); if (st1 == null && _stretcher == null) { builder.Build(tile.Width, tile.Height, tile.OffsetX, tile.OffsetY, buffers[0], ref bitmap); } else { if (_stretcher != null) { builder.Build(tile.Width, tile.Height, tile.OffsetX, tile.OffsetY, buffers[0], _stretcher, ref bitmap); } else { builder.Build(tile.Width, tile.Height, tile.OffsetX, tile.OffsetY, buffers[0], st1.Stretcher, ref bitmap); } } // if (_colorMapTable != null) { ColorPalette plt = BitmapBuilderFactory.GetDefaultGrayColorPalette(); for (int i = 0; i < 256; i++) { plt.Entries[i] = Color.Black; } int idx = 1; foreach (ColorMapItem <int> item in _colorMapTable.Items) { for (int v = item.MinValue; v < item.MaxValue; v++) { plt.Entries[idx] = item.Color; } idx++; } bitmap.Palette = plt; } } else if (buffers.Length == 3) { bitmap = new Bitmap(_tileSize, _tileSize, PixelFormat.Format24bppRgb); if (st1 == null || st2 == null || st3 == null) { builder.Build(tile.Width, tile.Height, tile.OffsetX, tile.OffsetY, buffers[0], buffers[1], buffers[2], ref bitmap); } else { builder.Build(tile.Width, tile.Height, tile.OffsetX, tile.OffsetY, buffers[0], buffers[1], buffers[2], st1.Stretcher, st2.Stretcher, st3.Stretcher, ref bitmap); } } return(bitmap); } }
public Bitmap GetOverview(IRasterDataProvider dataProvider, int width, int height, int[] bands, Action <int> progress) { T[][] buffers = new T[bands.Length][]; T[] rowBuffer = new T[width]; GCHandle handle = GCHandle.Alloc(rowBuffer, GCHandleType.Pinned); try { IntPtr rowPtr = handle.AddrOfPinnedObject(); int offset = 0; for (int b = 0; b < bands.Length; b++, offset += height) { buffers[b] = ReadBandBuffer(dataProvider, rowPtr, bands[b], width, height, offset, progress); } // using (IBitmapBuilder <T> builder = GetBitmapBuilder()) { Bitmap bitmap = null; if (buffers.Length == 1) { bitmap = new Bitmap(width, height, PixelFormat.Format8bppIndexed); bitmap.Palette = BitmapBuilderFactory.GetDefaultGrayColorPalette(); if (st1 == null) { builder.Build(width, height, 0, 0, buffers[0], ref bitmap); } else { builder.Build(width, height, 0, 0, buffers[0], st1.Stretcher, ref bitmap); } } else if (buffers.Length == 3) { bitmap = new Bitmap(width, height, PixelFormat.Format24bppRgb); if (st1 == null || st2 == null || st3 == null) { builder.Build(width, height, 0, 0, buffers[0], buffers[1], buffers[2], ref bitmap); } else { builder.Build(width, height, 0, 0, buffers[0], buffers[1], buffers[2], st1.Stretcher, st2.Stretcher, st3.Stretcher, ref bitmap); } } return(bitmap); } } finally { handle.Free(); } }
private void btnGetVisibleTiles_Click(object sender, EventArgs e) { Console.WriteLine("////////////"); Console.WriteLine("///Visible Tiles:"); TileData[][] tiles = _tileMemeoryCacheManager.GetVisibleTileDatas(); for (int b = 0; b < tiles.Length; b++) { TileData[] bandTiles = tiles[b]; Console.WriteLine("/// Band " + b.ToString()); foreach (TileData t in bandTiles) { Console.WriteLine(" " + t.Tile.ToString()); using (IBitmapBuilder <byte> builder = BitmapBuilderFactory.CreateBitmapBuilderByte()) { Bitmap bm = new Bitmap(t.Tile.Width, t.Tile.Height, PixelFormat.Format8bppIndexed); bm.Palette = BitmapBuilderFactory.GetDefaultGrayColorPalette(); builder.Build(t.Tile.Width, t.Tile.Height, t.Data as Byte[], ref bm); bm.Save("d:\\B" + t.BandNo.ToString() + "_L" + t.Tile.LevelNo.ToString() + "_R" + t.Tile.Row.ToString() + "_C" + t.Tile.Col.ToString() + ".bmp", ImageFormat.Bmp); } } } // BuildBitmap(tiles); }
public void DefaultRGB() { string fname = "f:\\Penguins.jpg"; //fname = "f:\\4_大昭寺_IMG_GE.tif"; UInt16[] rBuffer = null, gBuffer = null, bBuffer = null; int width = 0, height = 0; ReadRasterFile(fname, out width, out height, out rBuffer, out gBuffer, out bBuffer); Console.WriteLine("Width:" + width.ToString() + ",Height:" + height.ToString()); Stopwatch sw = new Stopwatch(); sw.Start(); using (IBitmapBuilder <UInt16> builder = BitmapBuilderFactory.CreateBitmapBuilderUInt16()) { Bitmap bitmap = new Bitmap(width, height, PixelFormat.Format24bppRgb); //bitmap.Palette = _colorPalette; builder.Build(width, height, rBuffer, gBuffer, bBuffer, ref bitmap); //builder.Build(width, height, gBuffer, ref bitmap); bitmap.Save(fname + ".bmp", ImageFormat.Bmp); bitmap.Dispose(); } sw.Stop(); Console.WriteLine("Lost Time:" + sw.ElapsedMilliseconds.ToString()); //MessageBox.Show(sw.ElapsedMilliseconds.ToString()); }
public void StretchRGB() { string fname = "f:\\FY3A_Mersi_2010_06_24_10_00_1000M_L1B_PRJ_Whole.LDF"; UInt16[] rBuffer = null, gBuffer = null, bBuffer = null; int width = 0, height = 0; //BitmapToArray(fname, 3, 4, 2, out width, out height, out rBuffer, out gBuffer, out bBuffer); ReadRasterFile(fname, 6, 4, 3, out width, out height, out rBuffer, out gBuffer, out bBuffer); Console.WriteLine("Width:" + width.ToString() + ",Height:" + height.ToString()); IRgbStretcher <UInt16> rgbs = new LinearRgbStretcherUInt16(0, 1000, true); Func <UInt16, byte> stretcher = (rgbs).Stretcher; using (IBitmapBuilder <UInt16> builder = BitmapBuilderFactory.CreateBitmapBuilderUInt16()) { Bitmap bitmap = new Bitmap(width, height, PixelFormat.Format24bppRgb); // Stopwatch sw = new Stopwatch(); sw.Start(); // builder.Build(width, height, rBuffer, gBuffer, bBuffer, stretcher, stretcher, stretcher, ref bitmap); sw.Stop(); Console.WriteLine("Lost Time:" + sw.ElapsedMilliseconds.ToString()); MessageBox.Show(sw.ElapsedMilliseconds.ToString()); bitmap.Save(fname + ".bmp", ImageFormat.Bmp); bitmap.Dispose(); } }
public static Bitmap ToBitmap <T>(T[] buffer, int width, int height, string colorTableName) { //string colorTableName = string.Format("Cloudsat.{0}", "2B-GEOPROF.Radar_Reflectivity"); ProductColorTable productColorTable = ProductColorTableFactory.GetColorTable(colorTableName); if (productColorTable == null) { return(null); } RgbStretcherProvider stretcherProvier = new RgbStretcherProvider(); ColorMapTable <int> colorMapTable = null; Func <T, byte> stretcher = null; IBitmapBuilder <T> builder = null; TypeCode t = Type.GetTypeCode(default(T).GetType()); if (t == TypeCode.Single) { stretcher = stretcherProvier.GetStretcher(enumDataType.Float, productColorTable, out colorMapTable) as Func <T, byte>; builder = BitmapBuilderFactory.CreateBitmapBuilderFloat() as IBitmapBuilder <T>; } else if (t == TypeCode.Int16) { stretcher = stretcherProvier.GetStretcher(enumDataType.Int16, productColorTable, out colorMapTable) as Func <T, byte>; builder = BitmapBuilderFactory.CreateBitmapBuilderInt16() as IBitmapBuilder <T>; } Bitmap bitmap = null; bitmap = new Bitmap(width, height, PixelFormat.Format8bppIndexed); bitmap.Palette = BitmapBuilderFactory.GetDefaultGrayColorPalette(); try { builder.Build(width, height, buffer, stretcher, ref bitmap); if (colorMapTable != null) { ColorPalette plt = BitmapBuilderFactory.GetDefaultGrayColorPalette(); for (int i = 0; i < 256; i++) { plt.Entries[i] = Color.Black; } int idx = 1; foreach (ColorMapItem <int> item in colorMapTable.Items) { for (int v = item.MinValue; v < item.MaxValue; v++) { plt.Entries[idx] = item.Color; } idx++; } bitmap.Palette = plt; } return(bitmap); } finally { } }
private void BuildOneTile(TileData redData, TileData greenData, TileData blueData, int x, int y, Rectangle rasterWindowEnvelope, Graphics g) { LevelId lv = _tileComputer.Levels[redData.Tile.LevelNo]; int w = redData.Tile.Width; int h = redData.Tile.Height; Bitmap tBitmap = new Bitmap(w, h, PixelFormat.Format24bppRgb); using (IBitmapBuilder <byte> builder = BitmapBuilderFactory.CreateBitmapBuilderByte()) { builder.Build(w, h, redData.Data as byte[], greenData.Data as byte[], blueData.Data as byte[], ref tBitmap); } g.DrawImage(tBitmap, x, y); tBitmap.Dispose(); }
public Bitmap Decompress(CompressedImage compressedImage) { var unHuf = HuffmanCodec.Decode(compressedImage.DataBytes, compressedImage.DecodeTable, compressedImage.BitsCount); var unRle = Rle <byte> .Decode(unHuf).ToArray(); var yDct = new List <double>(); var cbDct = new List <double>(); var crDct = new List <double>(); var countYBlocks = compressedImage.ThinIndex * compressedImage.ThinIndex; var cellsToBlock = compressedImage.CompressionLevel; for (var i = 0; i < unRle.Length;) { for (var j = 0; j < countYBlocks * cellsToBlock; j++) { yDct.Add(unRle[i++]); } for (var j = 0; j < cellsToBlock; j++) { cbDct.Add(unRle[i++]); } for (var j = 0; j < cellsToBlock; j++) { crDct.Add(unRle[i++]); } } var yDctBlocks = DevideIntoPiece(yDct, compressedImage.CompressionLevel); var cbDctBlocks = DevideIntoPiece(cbDct, compressedImage.CompressionLevel); var crDctBlocks = DevideIntoPiece(crDct, compressedImage.CompressionLevel); var yChannel = _dctDecompressor.Decompress(yDctBlocks, _dctSize, compressedImage.Height, compressedImage.Width, _lumiaMatrixProvider.GetMatrix()); var thinnedCbChannel = _dctDecompressor.Decompress(cbDctBlocks, _dctSize, compressedImage.Height / compressedImage.ThinIndex, compressedImage.Width / compressedImage.ThinIndex, _colorMatrixProvider.GetMatrix()); var thinnedCrChannel = _dctDecompressor.Decompress(crDctBlocks, _dctSize, compressedImage.Height / compressedImage.ThinIndex, compressedImage.Width / compressedImage.ThinIndex, _colorMatrixProvider.GetMatrix()); var cbChannel = _pieceMatrixExtender.Extend(thinnedCbChannel, compressedImage.ThinIndex); var crChannel = _pieceMatrixExtender.Extend(thinnedCrChannel, compressedImage.ThinIndex); var yCbCrChannels = new YCbCrChannels(yChannel, cbChannel, crChannel); var yCbCrPixels = _iChannelsPacker.Pack(yCbCrChannels, compressedImage.Height, compressedImage.Width); var matrixRgbPixels = MatrixYCbCrToRgbConverter.Convert(yCbCrPixels); var bmp = _bitmapBuilder.Build(matrixRgbPixels); return(bmp); }