//-------------------------------------------------------------- void testApp::setup(){ screenWidth = 1024; screenHeight = 768; kernelSize = screenWidth / 2; currentLut = 0; currentTrial = 0; bNoiseState = true; bFirstTrial = true; // static const float sigmas[] = {1.5, 1.25, 1.0, 0.75, 0.5, 0.25, 0.125, 0.0625}; // static const float thetas[] = {0, 45, 90, 135, 180, 225, 270, 315}; // static const float freqs[] = {0.0625, 0.125, 0.25, 0.375, 0.5, 0.625, 0.75, 1.0}; static const float sigmas[] = {1.25, 0.125, 0.25, 1.5, 1.0, 0.5, 0.0625, 0.75}; static const float thetas[] = {0, 45, 225, 270, 135, 180, 315, 90}; static const float freqs[] = {0.375, 0.0625, 0.625, 0.5, 1.0, 0.125, 0.75, 0.25}; this->sigmas = vector<float>(sigmas, sigmas + sizeof(sigmas) / sizeof(sigmas[0]) ); this->thetas = vector<float>(thetas, thetas + sizeof(thetas) / sizeof(thetas[0]) ); this->freqs = vector<float>(freqs, freqs + sizeof(freqs) / sizeof(freqs[0]) ); for (int i = 0; i < this->sigmas.size(); i++) { for (int j = 0; j < this->thetas.size(); j++) { for (int k = 0; k < this->freqs.size(); k++) { int lut[] = {i, j, k}; vector<int> clut(lut, lut + sizeof(lut) / sizeof(lut[0])); this->lut.push_back(clut); } } } ////////////////////////////////////////////////////// // now create the file so that we can start adding frames to it: string filename = getNextFilename("eeg-record-trial-" + ofToString(currentTrial), "txt"); outfile.open( ofToDataPath(filename).c_str() ); oscReceiver.setup(RECEIVE_PORT); atom.allocate(max(screenWidth, screenHeight)); noiseShader.load(ofToDataPath("noise")); ofSetVerticalSync(true); ofSetWindowShape(screenWidth, screenHeight); ofResetElapsedTimeCounter(); }
uint8_t *decode_bitmap(const uint8_t *src, bool alpha, int colorKey, int *w, int *h) { if (memcmp(src, "BM", 2) != 0) { return 0; } const uint32_t imageOffset = READ_LE_UINT32(src + 0xA); const int width = READ_LE_UINT32(src + 0x12); const int height = READ_LE_UINT32(src + 0x16); const int depth = READ_LE_UINT16(src + 0x1C); const int compression = READ_LE_UINT32(src + 0x1E); if ((depth != 8 && depth != 32) || compression != 0) { warning("Unhandled bitmap depth %d compression %d", depth, compression); return 0; } const int bpp = (!alpha && colorKey < 0) ? 3 : 4; uint8_t *dst = (uint8_t *)malloc(width * height * bpp); if (!dst) { warning("Failed to allocate bitmap buffer, width %d height %d bpp %d", width, height, bpp); return 0; } if (depth == 8) { const uint8_t *palette = src + 14 /* BITMAPFILEHEADER */ + 40 /* BITMAPINFOHEADER */; const bool flipY = true; clut(src + imageOffset, palette, (width + 3) & ~3, width, height, bpp, flipY, colorKey, dst); } else { assert(depth == 32 && bpp == 3); const uint8_t *p = src + imageOffset; for (int y = height - 1; y >= 0; --y) { uint8_t *q = dst + y * width * bpp; for (int x = 0; x < width; ++x) { const uint32_t color = READ_LE_UINT32(p); p += 4; *q++ = (color >> 16) & 255; *q++ = (color >> 8) & 255; *q++ = color & 255; } } } *w = width; *h = height; return dst; }
QImage QPatchedPixmap::convertToImage() const { QImage image; if ( isNull() ) { #if defined(CHECK_NULL) qWarning( "QPixmap::convertToImage: Cannot convert a null pixmap" ); #if defined(NASTY) abort(); #endif #endif return image; } int w = qt_screen->mapToDevice( QSize(width(), height()) ).width(); int h = qt_screen->mapToDevice( QSize(width(), height()) ).height(); int d = depth(); bool mono = d == 1; if( d == 15 || d == 16 ) { #ifndef QT_NO_QWS_DEPTH_16 d = 32; // Convert here because we may not have a 32bpp gfx image.create( w,h,d,0, QImage::IgnoreEndian ); for ( int y=h-1; y>=0; y-- ) { // for each scan line... register uint *p = (uint *)image.scanLine(y); ushort *s = (ushort*)scanLine(y); for (int i=w;i>0;i--) *p++ = qt_conv16ToRgb( *s++ ); } const QBitmap *mymask = mask(); if(mymask!=NULL) { QImage maskedimage(width(), height(), 32); maskedimage.fill(0); QGfx * mygfx=maskedimage.graphicsContext(); if(mygfx) { mygfx->setAlphaSource(mymask->scanLine(0), mymask->bytesPerLine()); mygfx->setSource(&image); mygfx->setAlphaType(QGfx::LittleEndianMask); mygfx->setLineStep(maskedimage.bytesPerLine()); mygfx->blt(0,0,width(),height(),0,0); } else { qWarning("No image gfx for convertToImage!"); } delete mygfx; maskedimage.setAlphaBuffer(TRUE); image.reset(); image=maskedimage; } #endif } else { // We can only create little-endian pixmaps if ( d == 4 ) image.create(w,h,8,0, QImage::IgnoreEndian ); else if ( d == 24 ) image.create(w,h,32,0, QImage::IgnoreEndian ); else image.create(w,h,d,0, mono ? QImage::LittleEndian : QImage::IgnoreEndian );//####### endianness QGfx * mygfx=image.graphicsContext(); const QBitmap *mymask = mask(); if(mygfx) { QGfx::AlphaType at = QGfx::IgnoreAlpha; if(mymask!=NULL) { at = QGfx::LittleEndianMask; mygfx->setAlphaSource(mymask->scanLine(0), mymask->bytesPerLine()); image.fill(0); } mygfx->setSource(this); mygfx->setAlphaType(at); mygfx->setLineStep(image.bytesPerLine()); mygfx->blt(0,0,width(),height(),0,0); } else { qWarning("No image gfx for convertToImage!"); } delete mygfx; image.setAlphaBuffer(mymask==NULL?data->hasAlpha:TRUE); } if ( mono ) { // bitmap image.setNumColors( 2 ); image.setColor( 0, qRgb(255,255,255) ); image.setColor( 1, qRgb(0,0,0) ); } else if ( d <= 8 ) { image.setNumColors( numCols() ); for ( int i = 0; i < numCols(); i++ ) image.setColor( i, clut()[i] ); } image = qt_screen->mapFromDevice( image ); return image; }