// implement your functions here fillerImage::fillerImage() // constructor { timesUsed = 0; int R = 0; int G = 0; int B = 0; int Height = getHeight(); int Width = getWidth(); int pix = Width * Height; //pixel object[Height][Width]; for (int i = 0; i < Height; i++) { for (int j = 0; j < Width; j++) { R = 0; G = 0; B = 0; for(int H=0;H<Height;H++) { for(int W=0;W<Width;W++) { R += static_cast<int>(getPixels()[i+H][j+W].red); G += static_cast<int>(getPixels()[i+H][j+W].green); B += static_cast<int>(getPixels()[i+H][j+W].blue); } } //assign pixel average to created new image avgPixel.red = static_cast<unsigned char>(R/pix); avgPixel.green = static_cast<unsigned char>(G/pix); avgPixel.blue = static_cast<unsigned char>(B/pix); } } }
//------------------------------------------------------------------------------ // loadTexture() -- load the texture //------------------------------------------------------------------------------ void BmpTexture::loadTexture() { // If needed, read the BMP file if (getPixels() == 0) readFile(); // Load the texture if (getPixels() != 0) BaseClass::loadTexture(); }
screen_buffer_t ConfigWindow::draw(TCOContext *emuContext) { screen_buffer_t buffer; unsigned char *pixels; int stride; if (!getPixels(&buffer, &pixels, &stride)) { return 0; } int y=0,x=0; unsigned char c; const int cell_size = 16; for (y=0; y<m_size[1]; y++) { int t = y & cell_size; int h = y * stride; for (x=0; x < m_size[0]; x++) { int p = x * 4; c = ((x & cell_size) ^ t) ? 0xa0 : 0x80; pixels[h + p + 0] = c; pixels[h + p + 1] = c; pixels[h + p + 2] = c; pixels[h + p + 3] = 0xa0; } } emuContext->drawControls(buffer); return buffer; }
SpriteFrame::SpriteFrame(AccessEngine *vm, Common::SeekableReadStream *stream, int frameSize) { int xSize = stream->readUint16LE(); int ySize = stream->readUint16LE(); if (vm->getGameID() == GType_MartianMemorandum) { int size = stream->readUint16LE(); if (size != frameSize) warning("Unexpected file difference: framesize %d - size %d %d - unknown %d", frameSize, xSize, ySize, size); } create(xSize, ySize); // Empty surface byte *data = (byte *)getPixels(); Common::fill(data, data + w * h, TRANSPARENCY); // Decode the data for (int y = 0; y < h; ++y) { int offset = stream->readByte(); int len = stream->readByte(); assert((offset + len) <= w); byte *destP = (byte *)getBasePtr(offset, y); stream->read(destP, len); } }
/**************************************************************** * Fills Maze Image with pixels determined by the mazeGen algo ****************************************************************/ void PhotoMaze :: fillImage(){ int _w = mazeImage.width; int _h = mazeImage.height; int type = mazeImage.type; int bpp = images[0].bpp / 8; int cellW = w/rw, cellH = h/rh; unsigned char *pixels = mazeImage.getPixels(); for (int i = 0; i < rw; i++){ for (int j = 0; j < rh; j++){ int x1 = i*cellW, y1 = j*cellH; PhotoMazeCell cell = cells[INDEX(i, j)]; unsigned char *tempPixels = getPixels(cell.photoIndex, cell.position.x*cellW, cell.position.y*cellH, cellW, cellH); for (int x0 = x1; x0 < x1+cellW; x0++) for (int y0 = y1; y0 < y1+cellH; y0++){ pixels[(x0+y0*_w)*3 ] = tempPixels[(x0-x1+(y0-y1)*cellW)*3 ]; pixels[(x0+y0*_w)*3+1 ] = tempPixels[(x0-x1+(y0-y1)*cellW)*3+1 ]; pixels[(x0+y0*_w)*3+2 ] = tempPixels[(x0-x1+(y0-y1)*cellW)*3+2 ]; } delete tempPixels; } } mazeImage.reloadTexture(); }
void ofxThreadedImage::resizeIfNeeded(){ if (resizeAfterLoad){ int w = getWidth(); int h = getHeight(); int largestSide = MAX(w, h); if(largestSide > maxSideSize){ //we need resize! float scale = maxSideSize / (float)largestSide; //float t1 = ofGetElapsedTimef(); int newW = w * scale; int newH = h * scale; #if USE_OPENCV_TO_RESIZE if (type == OF_IMAGE_COLOR){ ofxCvColorImage cvImg; cvImg.setUseTexture(false); cvImg.allocate(w, h); cvImg.setFromPixels(getPixels(), w, h); ofxCvColorImage cvImgsmall; cvImgsmall.setUseTexture(false); cvImgsmall.allocate(newW, newH); cvImgsmall.scaleIntoMe(cvImg, CV_INTER_AREA); setFromPixels(cvImgsmall.getPixels(), newW, newH, OF_IMAGE_COLOR); }else{ resize(newW, newH); //TODO opencv resizing is much faster! } #else resize(newW, newH); //TODO opencv resizing is much faster! #endif //ofLog() << "time resize: " + ofToString( ofGetElapsedTimef() - t1 ); } } }
const vector<short> & ofxDepthCompressedFrame::compressedData(){ if(compressedDirty){ compressed.resize(getPixels().size()*2+5); if(!isKeyFrame()){ uncompressedDiff.clear(); int lastPos = 0; for(int i=0;i<pixels.size();i++){ int pos = i-lastPos; if(pixels[i]==0 && pos < std::numeric_limits<unsigned short>::max()) continue; DiffPixel diffPixel={(unsigned short)pos,pixels[i]}; uncompressedDiff.push_back(diffPixel); lastPos = i; } if(uncompressedDiff.empty()){ compressedBytes = 0; }else{ compressedBytes = ofx_compress((unsigned char*)&uncompressedDiff[0],uncompressedDiff.size()*sizeof(DiffPixel),(unsigned char*)&compressed[5]); } }else{ compressedBytes = ofx_compress((unsigned char*)pixels.getPixels(),pixels.size()*sizeof(short),(unsigned char*)&compressed[5]); } compressedDirty = false; compressed.resize(compressedBytes/2+5); } return compressed; }
/* rotate image by 90° */ IplImage * rotate ( IplImage * img, uchar *** pixels ) { int width = img->width, height = img->height, depth = img->depth, channels = img->nChannels; IplImage *out = NULL; out = cvCreateImage( cvSize(height,width), depth, channels ); uchar *** nPixels = NULL; nPixels = getPixels( out ); int nY, nX, // temp x, y, c; // iterator // set values for ( y = 0; y < height; y++ ) { for ( x = 0; x < width; x++ ) { nY = width - 1 - x; nX = y; for ( c = 0; c < channels; c++ ) nPixels[nY][nX][c] = pixels[y][x][c]; } } /* using cv */ // cvTranspose( img, out ); // cvFlip( out, NULL, 0 ); return out; }
void Screen::randomTransition() { Events &events = *_vm->_events; const int TRANSITION_MULTIPLIER = 0x15a4e35; clearDirtyRects(); assert(IS_SERRATED_SCALPEL); for (int idx = 0; idx <= 65535 && !_vm->shouldQuit(); ++idx) { _transitionSeed = _transitionSeed * TRANSITION_MULTIPLIER + 1; int offset = _transitionSeed & 0xFFFF; if (offset < (this->width() * this->height())) *((byte *)getPixels() + offset) = *((const byte *)_backBuffer.getPixels() + offset); if (idx != 0 && (idx % 300) == 0) { // Ensure there's a full screen dirty rect for the next frame update if (!isDirty()) addDirtyRect(Common::Rect(0, 0, this->w, this->h)); events.pollEvents(); events.delay(1); } } // Make sure everything has been transferred SHblitFrom(_backBuffer); }
///-------------------------------------------------------------- void PMMotionExtractor::draw(bool drawImage, bool drawHands) { if (hasKinect && drawImage) { auto infraredImage = kinect.getInfraredSource(); auto infraredPixels = infraredImage->getPixels(); for (auto & pixel : infraredPixels) { pixel += pixel * 2; } ofTexture drawTexture; drawTexture.allocate(512, 424, GL_LUMINANCE); drawTexture.loadData(infraredPixels); drawTexture.draw(0, 0, ofGetWidth(), ofGetHeight()); } if(drawHands){ ofPushStyle(); ofNoFill(); ofSetLineWidth(3); ofSetColor(ofColor::red); ofDrawEllipse(handsInfo.rightHand.pos.x * ofGetWidth(), handsInfo.rightHand.pos.y * ofGetHeight(), 20+20*(handsInfo.rightHand.v.x), 20+20*(handsInfo.rightHand.v.y)); ofDrawEllipse(handsInfo.leftHand.pos.x * ofGetWidth(), handsInfo.leftHand.pos.y * ofGetHeight(), 20+20*(handsInfo.leftHand.v.x),20+20*(handsInfo.leftHand.v.y)); //ofDrawBitmapString(handsInfo.rightHand.pos.z, handsInfo.rightHand.pos.x * ofGetWidth() + 10, handsInfo.rightHand.pos.y * ofGetHeight() + 10); //ofDrawBitmapString(handsInfo.leftHand.pos.z, handsInfo.leftHand.pos.x * ofGetWidth() + 10, handsInfo.leftHand.pos.y * ofGetHeight() + 10); ofPopStyle(); } ofDrawBitmapString(positionDetectedCounter, 0, 0); }
//-------------------------------------------------------- void Pixelgroup::paint(PixelWriterInterface& writer) { // safeties if (!isDirty() && !m_isFlickering) return; if (getPixels() == 0 || getSize() == 0) return; bool strobeState = !Strobe::isStrobing() || Strobe::getStrobeState(); bool flickeringDone = false; // mark as clean setDirty(false); for (uint8_t i=0; i<getSize(); i++) { uint8_t pixelIndex = getPixels()[i]; if (m_isFlickering > 0 && !flickeringDone) { #ifdef ESP8266 if ((rand() % 100) > 80) { #else if ((random() % 100) > 80) { #endif strobeState &= 0; flickeringDone = true; m_isFlickering--; // mark as dirty to redraw on next cycle setDirty(true); } } // set pixel color (or black) // sets color in pixelWriter // sets pixelwriter to dirty if (!strobeState || flickeringDone) { writer.setPixelColor(pixelIndex, 0, 0, 0); } else { writer.setPixelColor((uint8_t)pixelIndex, getR(), getG(), getB()); } } }
void ScreenSurface::init() { // Set the size for the screen setSize(MADS_SCREEN_WIDTH, MADS_SCREEN_HEIGHT); // Store a copy of the raw pixels pointer for the screen, since the surface // itself may be later changed to only a subset of the screen _surfacePixels = (byte *)getPixels(); _freeFlag = false; }
int main ( int argc, char * argv[] ) { if ( argc < 2 ) errorMessage( 1, "Missing Arguments" ); if ( argc > 3 ) errorMessage( 2, "Too many Arguments" ); IplImage *img = NULL; img = cvLoadImage( argv[1], 1 ); // pixels [y][x][c] uchar *** pixels = NULL; pixels = getPixels( img ); char key; do { key = (char) cvWaitKey(1); if ( key == 'n' ) normalize( img, pixels ); if ( key == 'i' ) invert( img, pixels ); if ( key == 'h' ) cvFlip( img, img, 1 ); if ( key == 'l' ) { IplImage *tmp = NULL; tmp = rotate( img, pixels ); freePixels( img->height, pixels ); cvReleaseImage( &img ); img = tmp; pixels = getPixels( img ); } cvShowImage("rgbviewer", img ); } while ( key != 'q' ); // quit // release the image & reference ( tmp ) freePixels( img->height, pixels ); cvReleaseImage( &img ); return 0; }
//---------- shared_ptr<Frame> NullDevice::getFrame() { ofSleepMillis(1e3 / this->settings.frameRate); auto frame = FramePool::X().getAvailableAllocatedFrame(this->settings.width, this->settings.height, OF_PIXELS_MONO); frame->getPixels().set(0, 0); frame->setFrameIndex(this->frameIndex++); frame->setTimestamp(chrono::high_resolution_clock::now() - this->startTime); return frame; }
const int Text::width(char character) { int character_width = 0; uint32_t pixels = getPixels(character); while (pixels > 1) { character_width += 1; pixels >>= CHARACTER_HEIGHT; } return character_width; }
//-------------------------------------------------------------------------------- void ofxCvImage::updateTexture(){ if(!bAllocated) { ofLogWarning("ofxCvImage") << "updateTexture(): image not allocated"; } else if(bUseTexture ) { if( bTextureDirty ) { tex.loadData( getPixels() ); bTextureDirty = false; } } }
void Scalpel3DOScreen::blitFrom3DOcolorLimit(uint16 limitColor) { uint16 *currentScreenPtr = (uint16 *)getPixels(); uint16 *targetScreenPtr = (uint16 *)_backBuffer.getPixels(); uint16 currentScreenPixel = 0; uint16 screenWidth = SHERLOCK_SCREEN_WIDTH; uint16 screenHeight = SHERLOCK_SCREEN_HEIGHT; uint16 screenX = 0; uint16 screenY = 0; uint16 currentScreenPixelRed = 0; uint16 currentScreenPixelGreen = 0; uint16 currentScreenPixelBlue = 0; uint16 limitPixelRed = limitColor & 0xF800; uint16 limitPixelGreen = limitColor & 0x07E0; uint16 limitPixelBlue = limitColor & 0x001F; for (screenY = 0; screenY < screenHeight; screenY++) { for (screenX = 0; screenX < screenWidth; screenX++) { currentScreenPixel = *targetScreenPtr; currentScreenPixelRed = currentScreenPixel & 0xF800; currentScreenPixelGreen = currentScreenPixel & 0x07E0; currentScreenPixelBlue = currentScreenPixel & 0x001F; if (currentScreenPixelRed < limitPixelRed) currentScreenPixelRed = limitPixelRed; if (currentScreenPixelGreen < limitPixelGreen) currentScreenPixelGreen = limitPixelGreen; if (currentScreenPixelBlue < limitPixelBlue) currentScreenPixelBlue = limitPixelBlue; uint16 v = currentScreenPixelRed | currentScreenPixelGreen | currentScreenPixelBlue; *currentScreenPtr = v; if (_vm->_isScreenDoubled) { *(currentScreenPtr + 1) = v; *(currentScreenPtr + 640) = v; *(currentScreenPtr + 640 + 1) = v; } currentScreenPtr += _vm->_isScreenDoubled ? 2 : 1; targetScreenPtr++; } if (_vm->_isScreenDoubled) currentScreenPtr += 640; } // Too much considered dirty at the moment if (_vm->_isScreenDoubled) addDirtyRect(Common::Rect(0, 0, screenWidth * 2, screenHeight * 2)); else addDirtyRect(Common::Rect(0, 0, screenWidth, screenHeight)); }
void P6::Monochrome(const char* filename) { if (isGrayMonochrome() == true) { cout << "The image is already monochrome \n"; return; } else { char* newName = ChangeFileName(filename, "_monochrome.ppm"); ofstream outFile(newName, ios::out); if (!outFile) { cerr << "Cannot write P6 file \n"; return; } char magic_pbm[3] = "P6"; outFile << magic_pbm << endl << getWidth() << " " << getHeight() << endl << getMaxNum() << endl; int r = 0, g = 0, b = 0; for (int i = 0; i < getHeight(); i++) { for (int j = 0; j < getWidth(); j++) { r = getPixels()[i][j].getRed(); g = getPixels()[i][j].getGreen(); b = getPixels()[i][j].getBlue(); int gray = grayscale(r, g, b); int m = monochrome(gray); outFile.write((const char*)&m, sizeof(char)); outFile.write((const char*)&m, sizeof(char)); outFile.write((const char*)&m, sizeof(char)); } } outFile.flush(); outFile.close(); delete[] newName; } }
//--------- shared_ptr<Frame> VideoInput::getFrame() { auto frame = FramePool::X().getAvailableAllocatedFrame(this->device->getWidth(this->deviceIndex) , this->device->getHeight(this->deviceIndex) , ofPixelFormat::OF_PIXELS_RGB); this->device->getPixels(this->deviceIndex, frame->getPixels().getData(), true, true); frame->setTimestamp(chrono::high_resolution_clock::now() - this->timerStart); frame->setFrameIndex(this->frameIndex); return frame; }
//-------------------------------------------------------------------------------- void ofxCvFloatImage::drawWithScale( float x, float y, float w, float h, float scaleMin, float scaleMax){ if( bUseTexture ) { // note, this is a bit ineficient, as we have to // copy the data out of the cvImage into the pixel array // and then upload to texture. We should add // to the texture class an override for pixelstorei // that allows stepped-width image upload: tex.loadData(getPixels(scaleMin, scaleMax), width, height, GL_LUMINANCE); tex.draw(x,y,w,h); } }
void ofxCvImage::updateTexture(){ if( bTextureDirty ) { if(tex.getWidth() != width || tex.getHeight() != height) { //ROI was changed // reallocating texture - this could be faster with ROI support tex.clear(); tex.allocate( width, height, glchannels ); } tex.loadData( getPixels(), width, height, glchannels ); bTextureDirty = false; } }
void HippoImageBuffer::tile(BITMAPINFO *bitmapInfo, void *bits, int x0, int y0, int x1, int y1) { // The way we combine images is that where we have alpha == 0xff in the source // image, we leave the destination image untouched, otherwise we replace the // destination pixel with the source pixel; basically we are "fixing up" the // image we drew with IE, which can't handle partial alpha on the background // of a web page, by replacing just the partially alpha pixels int destWidth = bitmapInfo->bmiHeader.biWidth; int destHeight = - bitmapInfo->bmiHeader.biHeight; if (x0 < 0) x0 = 0; if (y0 < 0) y0 = 0; if (x1 > destWidth) x1 = destWidth; if (y1 > destHeight) y1 = destHeight; const UINT *srcRow = buffer_; UINT *destRow = (UINT *)bits + y0 * destWidth + x0; int j = 0; for (int y = y0; y < y1; y++, j++) { if (j == getHeight()) { j = 0; srcRow = getPixels(); } const UINT *src = srcRow; UINT *dest = destRow; int i = 0; for (int x = x0; x < x1; x++, i++) { if (i == getWidth()) { i = 0; src = srcRow; } UINT srcPixel = *src; if ((srcPixel & 0xFF000000) != 0xFF000000) *dest = srcPixel; src++; dest++; } srcRow += getWidth(); destRow += destWidth; } }
const RawImage::Pixel * RawImage::getSurfacePixels(const unsigned int surfaceIndex) const { assert(isValid()); const Pixel * pixelsStart = getPixels(); for (unsigned int s = 0; s < surfaceIndex; ++s) { pixelsStart += getSurfacePixelCount(s); } return pixelsStart; }
//Grab frame from GPU void ofxKCoreVision::grabFrameToGPU(GLuint target){ //grab the frame to a raw openGL texture getPixels(); glEnable(GL_TEXTURE_2D); //glPixelStorei(1); glBindTexture(GL_TEXTURE_2D, target); glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, camWidth, camHeight, GL_RGB, GL_UNSIGNED_BYTE, sourceImg.getPixels()); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glBindTexture(GL_TEXTURE_2D,0); }
bool ImageRAW::load(std::string filename) { m_bLoaded = 0; if (!sofa::helper::system::DataRepository.findFile(filename)) { std::cerr << "File " << filename << " not found " << std::endl; return false; } FILE *file; /* make sure the file is there and open it read-only (binary) */ if ((file = fopen(filename.c_str(), "rb")) == NULL) { std::cerr << "File not found : " << filename << std::endl; return false; } // read header and ignore it as we don't know how to interpret it for ( unsigned i=0; i<headerSize; ++i ) { int c = getc ( file ); if ( c == EOF ) { fclose ( file ); return false; } else header[i] = ( unsigned char ) c; } const unsigned int numVoxels = getImageSize(); // get the voxels from the file unsigned char *data = getPixels(); for ( unsigned int i=0; i<numVoxels; ++i ) { int c = getc ( file ); if ( c == EOF ) { fclose ( file ); return false; } else data[i] = ( unsigned char ) c; } fclose(file); m_bLoaded = 1; return true; }
//----------------------------------------------------------------------------------- void ofxCairoTexture::update(){ if( surface == NULL ) { printf("Error: ofxCairoTexture not allocated\n"); return; } int w = getWidth(); int h = getHeight(); unsigned char * pix = getPixels(); tex.setFromPixels(pix, w, h, OF_IMAGE_COLOR_ALPHA, false); }
void P6::Grayscale(const char* filename) { if (isGrayMonochrome() == true) { cout << "The image is already grayscale \n"; return; } else { char* newName = ChangeFileName(filename, "_grayscale.ppm"); ofstream outFile(newName, ios::out | ios::binary); if (!outFile) { cerr << "Cannot write P6 file \n"; return; } char magic_pgm[3] = "P6"; outFile << magic_pgm << endl << width << " " << height << endl << max_num << endl; for (int i = 0; i < getHeight(); i++) { for (int j = 0; j < getWidth(); j++) { r = getPixels()[i][j].getRed(); g = getPixels()[i][j].getGreen(); b = getPixels()[i][j].getBlue(); int gray = grayscale(r, g, b); outFile.write((const char*)&gray, sizeof(Color) / 3); outFile.write((const char*)&gray, sizeof(Color) / 3); outFile.write((const char*)&gray, sizeof(Color) / 3); } } outFile.flush(); outFile.close(); delete[] newName; } }
//-------------------------------------------------------------------------------- void ofxCvImage::draw( float x, float y, float w, float h ) { if( bUseTexture ) { if( bTextureDirty ) { if(tex.getWidth() != width || tex.getHeight() != height) { //ROI was changed // reallocating texture - this could be faster with ROI support tex.clear(); tex.allocate( width, height, glchannels ); } tex.loadData( getPixels(), width, height, glchannels ); bTextureDirty = false; } tex.draw(x,y, w,h); } else { #ifdef TARGET_OPENGLES ofLog(OF_LOG_ERROR, "texture-less drawing not supported in OpenGL ES"); #else // this is slower than the typical draw method based on textures // but useful when dealing with threads GL textures often don't work ofLog(OF_LOG_NOTICE, "in draw, using slow texture-less drawing"); ofLog(OF_LOG_NOTICE, "texture-less drawing - be aware, unlike texture drawing, \ this always draws window aligned, rotation not supported"); if( x == 0) { x += 0.01; ofLog(OF_LOG_NOTICE, "BUG: can't draw at x==0 in texture-less mode."); } if(bAnchorIsPct){ x -= anchor.x * w; y -= anchor.y * h; }else{ x -= anchor.x; y -= anchor.y; } glRasterPos2f( x, y+h ); IplImage* tempImg; tempImg = cvCreateImage( cvSize((int)w, (int)h), ipldepth, iplchannels ); cvResize( cvImage, tempImg, CV_INTER_NN ); cvFlip( tempImg, tempImg, 0 ); glDrawPixels( tempImg->width, tempImg->height , glchannels, gldepth, tempImg->imageData ); cvReleaseImage( &tempImg ); #endif } }
void ASurface::transBlitFrom(ASurface *src, const Common::Point &destPos) { if (getPixels() == nullptr) create(w, h); for (int yp = 0; yp < src->h; ++yp) { const byte *srcP = (const byte *)src->getBasePtr(0, yp); byte *destP = (byte *)getBasePtr(destPos.x, destPos.y + yp); for (int xp = 0; xp < this->w; ++xp, ++srcP, ++destP) { if (*srcP != TRANSPARENCY) *destP = *srcP; } } }
bool Image::crop(const Rect& region) { std::vector<Color> pixels; if(!getPixels(pixels, region)) { return false; } _width = (int)region.width; _height = (int)region.height; _pixels.resize(pixels.size()); std::copy(pixels.begin(), pixels.end(), _pixels.begin()); return true; }