agent/browser/ie/pagetest/PagetestReporting.cpp
/*-----------------------------------------------------------------------------
  Save the image histogram as a json data structure
-----------------------------------------------------------------------------*/
Save the image histogram as a json data structure
Save the image histogram as a json data structure
void CPagetestReporting::SaveHistogram(CxImage& image, CString file) {
  if (image.IsValid()) {
    DWORD r[256], g[256], b[256];
    for (int i = 0; i < 256; i++) {
      r[i] = g[i] = b[i] = 0;
    }
    DWORD width = __max(image.GetWidth() - RIGHT_MARGIN, 0);
    DWORD height = image.GetHeight();
    for (DWORD y = BOTTOM_MARGIN; y < height; y++) {
      for (DWORD x = 0; x < width; x++) {
        RGBQUAD pixel = image.GetPixelColor(x,y);
        if (pixel.rgbRed != 255 || 
            pixel.rgbGreen != 255 || 
            pixel.rgbBlue != 255) {
          r[pixel.rgbRed]++;
          g[pixel.rgbGreen]++;
          b[pixel.rgbBlue]++;
        }
      }
    }
    CStringA red = "\"r\":[";
    CStringA green = "\"g\":[";
    CStringA blue = "\"b\":[";
    CStringA buff;
    for (int i = 0; i < 256; i++) {
      if (i) {
        red += ",";
        green += ",";
        blue += ",";
      }
      buff.Format("%d", r[i]);
      red += buff;
      buff.Format("%d", g[i]);
      green += buff;
      buff.Format("%d", b[i]);
      blue += buff;
    }
    red += "]";
    green += "]";
    blue += "]";
    CStringA histogram = CStringA("{") + red + 
                         CStringA(",") + green + 
                         CStringA(",") + blue + CStringA("}");
    HANDLE file_handle = CreateFile(file, GENERIC_WRITE, 0, 0, 
                                    CREATE_ALWAYS, 0, 0);
    if (file_handle != INVALID_HANDLE_VALUE) {
      DWORD bytes;
      WriteFile(file_handle, (LPCSTR)histogram, histogram.GetLength(), &bytes, 0);
      CloseHandle(file_handle);
    }
  }
}
void CPagetestReporting :: SaveHistogram ( CxImage & image , CString file ) { if ( image . IsValid ( ) ) { DWORD r [ 256 ] , g [ 256 ] , b [ 256 ] ; for ( int i = 0 ; i < 256 ; i ++ ) { r [ i ] = g [ i ] = b [ i ] = 0 ; } DWORD width = __max ( image . GetWidth ( ) - RIGHT_MARGIN , 0 ) ; DWORD height = image . GetHeight ( ) ; for ( DWORD y = BOTTOM_MARGIN ; y < height ; y ++ ) { for ( DWORD x = 0 ; x < width ; x ++ ) { RGBQUAD pixel = image . GetPixelColor ( x , y ) ; if ( pixel . rgbRed != 255 || pixel . rgbGreen != 255 || pixel . rgbBlue != 255 ) { r [ pixel . rgbRed ] ++ ; g [ pixel . rgbGreen ] ++ ; b [ pixel . rgbBlue ] ++ ; } } } CStringA red = " \" \" " ; CStringA green = " \" \" " ; CStringA blue = " \" \" " ; CStringA buff ; for ( int i = 0 ; i < 256 ; i ++ ) { if ( i ) { red += " " ; green += " " ; blue += " " ; } buff . Format ( " " , r [ i ] ) ; red += buff ; buff . Format ( " " , g [ i ] ) ; green += buff ; buff . Format ( " " , b [ i ] ) ; blue += buff ; } red += " " ; green += " " ; blue += " " ; CStringA histogram = CStringA ( " " ) + red + CStringA ( " " ) + green + CStringA ( " " ) + blue + CStringA ( " " ) ; HANDLE file_handle = CreateFile ( file , GENERIC_WRITE , 0 , 0 , CREATE_ALWAYS , 0 , 0 ) ; if ( file_handle != INVALID_HANDLE_VALUE ) { DWORD bytes ; WriteFile ( file_handle , ( LPCSTR ) histogram , histogram . GetLength ( ) , & bytes , 0 ) ; CloseHandle ( file_handle ) ; } } }
Save the image histogram as a json data structure
Save the image histogram as a json data structure