Exemple #1
0
        private unsafe void     UpdateBitmap()
        {
            if (m_sourceImage == null)
            {
                return;
            }

            // Fill pixel per pixel
            uint W = m_sourceImage.Width;
            uint H = m_sourceImage.Height;

            if (m_Bitmap != null && (m_Bitmap.Width != W || m_Bitmap.Height != H))
            {
                m_Bitmap.Dispose();
                m_Bitmap = null;
            }
            if (m_Bitmap == null)
            {
                m_Bitmap = new Bitmap((int)W, (int)H, PixelFormat.Format32bppArgb);
            }

            switch (m_ViewMode)
            {
            case VIEW_MODE.RGB:
                m_sourceImage.AsCustomBitmap(m_Bitmap, ( ref float4 _color ) => {
                    if (!m_viewLinear)
                    {
                        _color.x = ImageUtility.ColorProfile.Linear2sRGB(_color.x);
                        _color.y = ImageUtility.ColorProfile.Linear2sRGB(_color.y);
                        _color.z = ImageUtility.ColorProfile.Linear2sRGB(_color.z);
                    }
                    _color.w = 1.0f;
                });
                break;

            case VIEW_MODE.R:
                m_sourceImage.AsCustomBitmap(m_Bitmap, ( ref float4 _color ) => {
                    _color.x = m_viewLinear ? _color.x : ImageUtility.ColorProfile.Linear2sRGB(_color.x);
                    _color.y = _color.z = _color.x;
                    _color.w = 1.0f;
                });
                break;

            case VIEW_MODE.G:
                m_sourceImage.AsCustomBitmap(m_Bitmap, ( ref float4 _color ) => {
                    _color.y = m_viewLinear ? _color.y : ImageUtility.ColorProfile.Linear2sRGB(_color.y);
                    _color.x = _color.z = _color.y;
                    _color.w = 1.0f;
                });
                break;

            case VIEW_MODE.B:
                m_sourceImage.AsCustomBitmap(m_Bitmap, ( ref float4 _color ) => {
                    _color.z = m_viewLinear ? _color.z : ImageUtility.ColorProfile.Linear2sRGB(_color.z);
                    _color.x = _color.y = _color.z;
                    _color.w = 1.0f;
                });
                break;

            case VIEW_MODE.AO:
                m_sourceImage.AsCustomBitmap(m_Bitmap, ( ref float4 _color ) => {
                    _color.x = _color.y = _color.z = m_viewLinear ? _color.w : ImageUtility.ColorProfile.Linear2sRGB(_color.w);
                    _color.w = 1.0f;
                });
                break;

            case VIEW_MODE.AO_FROM_RGB:
                m_sourceImage.AsCustomBitmap(m_Bitmap, ( ref float4 _color ) => {
                    float LinR  = ImageUtility.ColorProfile.sRGB2Linear(_color.x);
                    float LinG  = ImageUtility.ColorProfile.sRGB2Linear(_color.y);
                    float LinB  = ImageUtility.ColorProfile.sRGB2Linear(_color.z);
                    float LinAO = (float)Math.Sqrt(LinR * LinR + LinG * LinG + LinB * LinB) * 0.57735026918962576450914878050196f;                              // divided by sqrt(3)
                    _color.x    = _color.y = _color.z = ImageUtility.ColorProfile.Linear2sRGB(LinAO);
                    _color.w    = 1.0f;
                });
                break;

            case VIEW_MODE.RGB_TIMES_AO:
                m_sourceImage.AsCustomBitmap(m_Bitmap, ( ref float4 _color ) => {
                    float LinR = ImageUtility.ColorProfile.sRGB2Linear(_color.x);
                    float LinG = ImageUtility.ColorProfile.sRGB2Linear(_color.y);
                    float LinB = ImageUtility.ColorProfile.sRGB2Linear(_color.z);
                    _color.x   = ImageUtility.ColorProfile.Linear2sRGB(_color.w * LinR);
                    _color.y   = ImageUtility.ColorProfile.Linear2sRGB(_color.w * LinG);
                    _color.z   = ImageUtility.ColorProfile.Linear2sRGB(_color.w * LinB);
                    _color.w   = 1.0f;
                });
                break;
            }

            Refresh();
        }
Exemple #2
0
        private unsafe void     UpdateBitmap()
        {
            if (m_sourceImage == null)
            {
                return;
            }

            // Fill pixel per pixel
            int W = (int)m_sourceImage.Width;
            int H = (int)m_sourceImage.Height;

            if (m_Bitmap != null && (m_Bitmap.Width != W || m_Bitmap.Height != H))
            {
                m_Bitmap.Dispose();
                m_Bitmap = null;
            }
            if (m_Bitmap == null)
            {
                m_Bitmap = new Bitmap(W, H, PixelFormat.Format32bppArgb);
            }

            switch (m_ViewMode)
            {
            case VIEW_MODE.RGB:
                m_sourceImage.AsCustomBitmap(m_Bitmap, ( ref float4 _color ) => {
                    _color.w = 1.0f;
                });
                break;

            case VIEW_MODE.R:
                m_sourceImage.AsCustomBitmap(m_Bitmap, ( ref float4 _color ) => {
                    _color.y = _color.z = _color.x;
                    _color.w = 1.0f;
                });
                break;

            case VIEW_MODE.G:
                m_sourceImage.AsCustomBitmap(m_Bitmap, ( ref float4 _color ) => {
                    _color.x = _color.z = _color.y;
                    _color.w = 1.0f;
                });
                break;

            case VIEW_MODE.B:
                m_sourceImage.AsCustomBitmap(m_Bitmap, ( ref float4 _color ) => {
                    _color.x = _color.y = _color.z;
                    _color.w = 1.0f;
                });
                break;

            case VIEW_MODE.AO:
                m_sourceImage.AsCustomBitmap(m_Bitmap, ( ref float4 _color ) => {
                    float AO = m_viewLinear ? _color.w : ImageUtility.ColorProfile.Linear2sRGB(_color.w);
                    _color.x = _color.y = _color.z = AO;
                    _color.w = 1.0f;
                });
                break;

            case VIEW_MODE.AO_FROM_RGB:
                m_sourceImage.AsCustomBitmap(m_Bitmap, ( ref float4 _color ) => {
                    float LinR  = ImageUtility.ColorProfile.sRGB2Linear(_color.x);
                    float LinG  = ImageUtility.ColorProfile.sRGB2Linear(_color.y);
                    float LinB  = ImageUtility.ColorProfile.sRGB2Linear(_color.z);
                    float LinAO = (float)Math.Sqrt(LinR * LinR + LinG * LinG + LinB * LinB) * 0.57735026918962576450914878050196f;                              // divided by sqrt(3)
                    _color.x    = _color.y = _color.z = ImageUtility.ColorProfile.Linear2sRGB(LinAO);
                    _color.w    = 1.0f;
                });
                break;

            case VIEW_MODE.RGB_TIMES_AO:
                m_sourceImage.AsCustomBitmap(m_Bitmap, ( ref float4 _color ) => {
                    float LinR = ImageUtility.ColorProfile.sRGB2Linear(_color.x);
                    float LinG = ImageUtility.ColorProfile.sRGB2Linear(_color.y);
                    float LinB = ImageUtility.ColorProfile.sRGB2Linear(_color.z);
                    _color.x   = ImageUtility.ColorProfile.Linear2sRGB(_color.w * LinR);
                    _color.y   = ImageUtility.ColorProfile.Linear2sRGB(_color.w * LinG);
                    _color.z   = ImageUtility.ColorProfile.Linear2sRGB(_color.w * LinB);
                    _color.w   = 1.0f;
                });
                break;
            }

//          float4[,]	ContentRGB = new float4[W,H];
//          float4[]	scanline = new float4[W];
//          if ( m_viewLinear ) {
//              for ( int Y=0; Y < H; Y++ ) {
//                  m_Image.ReadScanline( (uint) Y, scanline );
//                  for ( int X=0; X < W; X++ )
//                      ContentRGB[X,Y] = scanline[X];
//              }
//          } else {
//              for ( int Y=0; Y < H; Y++ ) {
//                  m_Image.ReadScanline( (uint) Y, scanline );
//                  for ( int X=0; X < W; X++ ) {
//                      m_ProfilesRGB.GammaRGB2LinearRGB( scanline[X], ref ContentRGB[X,Y] );
//                  }
//              }
//          }
//
//          BitmapData	LockedBitmap = m_Bitmap.LockBits( new Rectangle( 0, 0, W, H ), ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb );
//          for ( int Y=0; Y < H; Y++ )
//          {
//              byte*	pScanline = (byte*) LockedBitmap.Scan0.ToPointer() + LockedBitmap.Stride * Y;
//              for ( int X=0; X < W; X++ )
//              {
//                  byte	R = (byte) Math.Max( 0, Math.Min( 255, 255 * ContentRGB[X,Y].x ) );
//                  byte	G = (byte) Math.Max( 0, Math.Min( 255, 255 * ContentRGB[X,Y].y ) );
//                  byte	B = (byte) Math.Max( 0, Math.Min( 255, 255 * ContentRGB[X,Y].z ) );
//                  byte	A = (byte) Math.Max( 0, Math.Min( 255, 255 * (m_viewLinear ? ContentRGB[X,Y].w : ImageUtility.ColorProfile.Linear2sRGB( ContentRGB[X,Y].w )) ) );
//
//                  switch ( m_ViewMode )
//                  {
//                      case VIEW_MODE.RGB:
//                          *pScanline++ = B;
//                          *pScanline++ = G;
//                          *pScanline++ = R;
//                          *pScanline++ = 0xFF;
//                          break;
//                      case VIEW_MODE.R:
//                          *pScanline++ = R;
//                          *pScanline++ = R;
//                          *pScanline++ = R;
//                          *pScanline++ = 0xFF;
//                          break;
//                      case VIEW_MODE.G:
//                          *pScanline++ = G;
//                          *pScanline++ = G;
//                          *pScanline++ = G;
//                          *pScanline++ = 0xFF;
//                          break;
//                      case VIEW_MODE.B:
//                          *pScanline++ = B;
//                          *pScanline++ = B;
//                          *pScanline++ = B;
//                          *pScanline++ = 0xFF;
//                          break;
//                      case VIEW_MODE.AO:
//                          *pScanline++ = A;
//                          *pScanline++ = A;
//                          *pScanline++ = A;
//                          *pScanline++ = 0xFF;
//                          break;
//                      case VIEW_MODE.AO_FROM_RGB:
//                          {
//                              float	LinR = ImageUtility.ColorProfile.sRGB2Linear( ContentRGB[X,Y].x );
//                              float	LinG = ImageUtility.ColorProfile.sRGB2Linear( ContentRGB[X,Y].y );
//                              float	LinB = ImageUtility.ColorProfile.sRGB2Linear( ContentRGB[X,Y].z );
//                              float	LinAO = (float) Math.Sqrt( LinR*LinR + LinG*LinG + LinB*LinB ) * 0.57735026918962576450914878050196f;	// divided by sqrt(3)
//                              A = (byte) Math.Max( 0, Math.Min( 255, 255 * ImageUtility.ColorProfile.Linear2sRGB( LinAO ) ) );
//                              *pScanline++ = A;
//                              *pScanline++ = A;
//                              *pScanline++ = A;
//                              *pScanline++ = 0xFF;
//                          }
//                          break;
//                      case VIEW_MODE.RGB_TIMES_AO:
//                          {
//                              float	LinR = ImageUtility.ColorProfile.sRGB2Linear( ContentRGB[X,Y].x );
//                              float	LinG = ImageUtility.ColorProfile.sRGB2Linear( ContentRGB[X,Y].y );
//                              float	LinB = ImageUtility.ColorProfile.sRGB2Linear( ContentRGB[X,Y].z );
//                              float	LinAO = ContentRGB[X,Y].w;
//                              LinR *= LinAO;
//                              LinG *= LinAO;
//                              LinB *= LinAO;
//                              R = (byte) Math.Max( 0, Math.Min( 255, 255 * ImageUtility.ColorProfile.Linear2sRGB( LinR ) ) );
//                              G = (byte) Math.Max( 0, Math.Min( 255, 255 * ImageUtility.ColorProfile.Linear2sRGB( LinG ) ) );
//                              B = (byte) Math.Max( 0, Math.Min( 255, 255 * ImageUtility.ColorProfile.Linear2sRGB( LinB ) ) );
//                              *pScanline++ = B;
//                              *pScanline++ = G;
//                              *pScanline++ = R;
//                              *pScanline++ = 0xFF;
//                          }
//                          break;
//                  }
//              }
//          }
//          m_Bitmap.UnlockBits( LockedBitmap );

            Refresh();
        }
Exemple #3
0
        private void buttonTestBilateral_Click( object sender, EventArgs e )
        {
            try {
                panelParameters.Enabled = false;

                //////////////////////////////////////////////////////////////////////////
                // 1] Apply bilateral filtering to the input texture as a pre-process
                ApplyBilateralFiltering( m_textureSourceHeightMap, m_textureTarget0, floatTrackbarControlBilateralRadius.Value, floatTrackbarControlBilateralTolerance.Value, checkBoxWrap.Checked, 100 );

                progressBar.Value = progressBar.Maximum;

                //////////////////////////////////////////////////////////////////////////
                // 2] Copy target to staging for CPU readback and update the resulting bitmap
                m_textureTarget_CPU.CopyFrom( m_textureTarget0 );

                ImageUtility.Bitmap		tempBitmap = new ImageUtility.Bitmap( W, H );
                Renderer.PixelsBuffer	Pixels = m_textureTarget_CPU.Map( 0, 0 );
                using ( System.IO.BinaryReader R = Pixels.OpenStreamRead() )
                    for ( uint Y=0; Y < H; Y++ ) {
                        R.BaseStream.Position = Y * Pixels.RowPitch;
                        for ( uint X=0; X < W; X++ ) {
                            float	AO = R.ReadSingle();
                            tempBitmap[X,Y] = new float4( AO, AO, AO, 1 );
                        }
                    }

                Pixels.Dispose();
                m_textureTarget_CPU.UnMap( 0, 0 );

                // Convert to RGB
            //				ImageUtility.ColorProfile	Profile = m_ProfilesRGB;	// AO maps are sRGB! (although strange, that's certainly to have more range in dark values)
                ImageUtility.ColorProfile	Profile = m_profilesRGB;	// AO maps are sRGB! (although strange, that's certainly to have more range in dark values)

                if ( m_imageResult != null )
                    m_imageResult.Dispose();
                m_imageResult = new ImageUtility.ImageFile();
                tempBitmap.ToImageFile( m_imageResult, Profile );

                // Assign result
                viewportPanelResult.Bitmap = m_imageResult.AsCustomBitmap( ( ref float4 _color ) => {} );

            } catch ( Exception _e ) {
                MessageBox( "An error occurred during generation!\r\n\r\nDetails: ", _e );
            } finally {
                panelParameters.Enabled = true;
            }
        }