Exemplo n.º 1
0
QImage DetailWindow::imageFromChromagram(const KeyFinder::Chromagram& ch){
  // 64 colours (plus black at index 0)
  // don't draw individual pixels; draw blocks of chromaScaleV*chromaScaleH. Sharpens image.
  QImage img = QImage(ch.getHops()*chromaScaleH,ch.getBins()*chromaScaleV,QImage::Format_Indexed8);
  prefs.setImageColours(img,ui->chromaColourCombo->currentIndex());
  // get max to normalise
  float max = 0;
  for(unsigned int h = 0; h < ch.getHops(); h++){
    for(unsigned int b = 0; b < ch.getBins(); b++){
      float mag = ch.getMagnitude(h,b);
      if(mag>max) max = mag;
    }
  }
  // set pixels
  for(unsigned int h = 0; h < ch.getHops(); h++){
    for(unsigned int b = 0; b < ch.getBins(); b++){
      int pixVal = ch.getMagnitude(h,b) / max * img.colorCount() - 1;
      if(pixVal<1)
        pixVal = 1;
      for(int x=0; x<chromaScaleH; x++)
        for(int y=0; y<chromaScaleV; y++)
          img.setPixel(h*chromaScaleH+x, (ch.getBins()-1-b)*chromaScaleV+y, pixVal);
    }
  }
  return img;
}
Exemplo n.º 2
0
TEST (ChromagramTest, ConstructorDefaultsWork) {
  KeyFinder::Chromagram c;
  ASSERT_EQ(0, c.getHops());
}