rspfRefPtr<rspfImageData> rspfPixelFlipper::getTile( const rspfIrect& tile_rect, rspf_uint32 resLevel) { if(!theInputConnection) { return 0; } // Fetch tile from pointer from the input source. rspfRefPtr<rspfImageData> inputTile = theInputConnection->getTile(tile_rect, resLevel); if (!inputTile.valid() || !isSourceEnabled()) return inputTile; if (!inputTile->getBuf()) return inputTile; // Lock for the length of this method. OpenThreads::ScopedLock<OpenThreads::Mutex> scopeLock(theMutex); // Call the appropriate load method. switch (inputTile->getScalarType()) { case RSPF_UCHAR: { flipPixels(rspf_uint8(0), inputTile.get(), resLevel); break; } case RSPF_UINT16: case RSPF_USHORT11: { flipPixels(rspf_uint16(0), inputTile.get(), resLevel); break; } case RSPF_SSHORT16: { flipPixels(rspf_sint16(0), inputTile.get(), resLevel); break; } case RSPF_UINT32: { flipPixels(rspf_uint32(0), inputTile.get(), resLevel); break; } case RSPF_SINT32: { flipPixels(rspf_sint32(0), inputTile.get(), resLevel); break; } case RSPF_FLOAT32: case RSPF_NORMALIZED_FLOAT: { flipPixels(float(0), inputTile.get(), resLevel); break; } case RSPF_NORMALIZED_DOUBLE: case RSPF_FLOAT64: { flipPixels(rspf_float64(0), inputTile.get(), resLevel); break; } case RSPF_SCALAR_UNKNOWN: default: { rspfNotify(rspfNotifyLevel_WARN) << "rspfPixelFlipper::getTile Unsupported scalar type!" << endl; break; } } inputTile->validate(); return inputTile; }
bool loadTextures() { SDL_Surface *bitmap = loadBitmap("data/nehe.bmp"); if (!bitmap) return false; if (!isPowerOf2(bitmap->w)) { fprintf(stderr, "image width is not power of 2"); return false; } if (!isPowerOf2(bitmap->h)) { fprintf(stderr, "image height is not power of 2"); return false; } int numColours = bitmap->format->BytesPerPixel; GLenum texture_format; if (numColours == 4) { // Contains alpha channel. if (bitmap->format->Rmask == 0x000000ff) { texture_format = GL_RGBA; } else { texture_format = GL_BGRA; } } else if (numColours == 3) { // No alpha channel. if (bitmap->format->Rmask == 0x000000ff) { texture_format = GL_RGB; } else { texture_format = GL_BGR; } } else { fprintf(stderr, "Image is not true colour"); return false; } printf("texture format is '%s'\n", textureFormatToString(texture_format)); // Create the texture. glGenTextures(1, &texture[1]); // Typical texture generation using data from the bitmap. glBindTexture(GL_TEXTURE_2D, texture[0]); // Linear Filtering. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); bool withMipMap = false; if (withMipMap) { gluBuild2DMipmaps(GL_TEXTURE_2D, 3, bitmap->w, bitmap->h, GL_BGR, GL_UNSIGNED_BYTE, bitmap->pixels); } else { RGB bmp[bitmap->w * bitmap->h]; flipPixels(bmp, bitmap); bool flip = false; glTexImage2D(GL_TEXTURE_2D, 0, numColours, bitmap->w, bitmap->h, 0, texture_format, GL_UNSIGNED_BYTE, flip? bmp : bitmap->pixels); } SDL_FreeSurface(bitmap); printf("texture \"name\" is %d\n", texture[0]); return true; }
//------------------------------------ void ofxImage::mirror(bool horizontal, bool vertical){ flipPixels(myPixels, horizontal, vertical); update(); }