bool ImageBuffer::setImageToStart(void) { reader.set(CV_CAP_PROP_POS_AVI_RATIO, 0); // skip 3 frames to match with smoothGps imageInfo_t image; getCurrentImage(&image); getCurrentImage(&image); getCurrentImage(&image); fseek(readFp,0,SEEK_SET); readIdx = 0; return true; }
bool ImageBuffer::setImageToStart(void) { WaitForSingleObject(_hMutex,INFINITE); reader.set(CV_CAP_PROP_POS_AVI_RATIO, 0); // skip 3 frames to match with smoothGps imageInfo_t image; getCurrentImage(&image); getCurrentImage(&image); getCurrentImage(&image); fseek(readFp,0,SEEK_SET); readIdx = 0; ReleaseMutex(_hMutex); return true; }
void insertNode(QTnode* qt, int* dim, char *name) { //Alocating space in the heap for the node ListNode* temp = (ListNode*) malloc(sizeof(ListNode)); temp->image = qt; temp->size = *dim; temp->next = NULL; temp->current = 1; //Copies the name to the array, since the value of *name will change with time strncpy (temp->name, name, MAXLENGTH); int index = 0; if(first != NULL) { ListNode* currentImage = getCurrentImage(first); currentImage->current = FALSE; currentImage->next = temp; temp->previous = currentImage; index = (currentImage->index)+1; } else { first = temp; index=1; temp->previous = NULL; } temp->index = index; }
void OpenNIDevice::ImageDataThreadFunction () throw (OpenNIException) { while (running_) { // lock before checking running flag unique_lock<mutex> image_lock (image_mutex_); if (!running_) return; image_condition_.wait (image_lock); if (!running_) return; image_generator_.WaitAndUpdateData (); xn::ImageMetaData image_data; image_generator_.GetMetaData (image_data); image_lock.unlock (); Image* image = getCurrentImage (image_data); for (map< OpenNIDevice::CallbackHandle, ActualImageCallbackFunction >::iterator callbackIt = image_callback_.begin (); callbackIt != image_callback_.end (); ++callbackIt) { callbackIt->second.operator()(*image); } delete image; } }
void ofxSprite::draw(float x, float y) { if (!visible) return; ofPushMatrix(); ofTranslate(x, y); ofRotate(rotation); getCurrentImage().draw(-anchorPoint); ofPopMatrix(); }
F32 LLSnapshotLivePreview::getImageAspect() { if (!getCurrentImage()) { return 0.f; } return getAspect() ; }
void ContextMenuGraphicsComponent::update(GameObject*) { DrawParamsMenuGraphics* dp = new DrawParamsMenuGraphics(); dp->scale = scaleFactor_; dp->degrees = 0; dp->pos = menuPos_; dp->animate = animate_; dp->pixmapIdx = getCurrentImage(); emit signalDraw(dp,this, LAYER_MENU); }
bool ImageButton::hitTest (int x, int y) { if (alphaThreshold == 0) return true; Image im (getCurrentImage()); return im.isNull() || ((! imageBounds.isEmpty()) && alphaThreshold < im.getPixelAt (((x - imageBounds.getX()) * im.getWidth()) / imageBounds.getWidth(), ((y - imageBounds.getY()) * im.getHeight()) / imageBounds.getHeight()).getAlpha()); }
bool ImageButton::hitTest (int x, int y) { if (alphaThreshold == 0) return true; Image im (getCurrentImage()); return im.isNull() || (imageW > 0 && imageH > 0 && alphaThreshold < im.getPixelAt (((x - imageX) * im.getWidth()) / imageW, ((y - imageY) * im.getHeight()) / imageH).getAlpha()); }
QImage GCModule::setCorrectionsPoints(const QVector<QPoint> &points, CorrectionType type) { qDebug() << "GCModule::setCorrectionsPoints(" << points << ");"; static const int radius = 1; static const int thickness = -1; uchar value = type == BackgroundSelect ? cv::GC_BGD : cv::GC_FGD; for (auto & point : points) cv::circle( mMasks[mIdx], cast(point), radius, value, thickness); cv::grabCut(mInputImage, mMasks[mIdx], cv::Rect(), mBgdModel, mFgdModel, 5, cv::GC_INIT_WITH_MASK); return getCurrentImage(); }
bool ImageButton::hitTest (int x, int y) { if (! Component::hitTest (x, y)) // handle setInterceptsMouseClicks return false; if (alphaThreshold == 0) return true; Image im (getCurrentImage()); return im.isNull() || ((! imageBounds.isEmpty()) && alphaThreshold < im.getPixelAt (((x - imageBounds.getX()) * im.getWidth()) / imageBounds.getWidth(), ((y - imageBounds.getY()) * im.getHeight()) / imageBounds.getHeight()).getAlpha()); }
QImage GCModule::setRects(const QVector<QRect> &rects) { qDebug() << "GCModule::setRects(" << rects << ");"; for (auto & rect : rects) { cv::Mat mask; cv::grabCut(mInputImage, mask, cast(rect), mBgdModel, mFgdModel, 5, cv::GC_INIT_WITH_RECT); mMasks[mIdx] |= mask; } for (int i = mIdx - 1; i >= 0; --i) { cv::Mat mask = mMasks[i] == cv::GC_FGD | mMasks[i] == cv::GC_PR_FGD; mMasks[mIdx].setTo(cv::GC_BGD, mask); } return getCurrentImage(); }
void DrawableButton::buttonStateChanged() { repaint(); Drawable* imageToDraw = nullptr; float opacity = 1.0f; if (isEnabled()) { imageToDraw = getCurrentImage(); } else { imageToDraw = getToggleState() ? disabledImageOn : disabledImage; if (imageToDraw == nullptr) { opacity = 0.4f; imageToDraw = getNormalImage(); } } if (imageToDraw != currentImage) { removeChildComponent (currentImage); currentImage = imageToDraw; if (currentImage != nullptr) { currentImage->setInterceptsMouseClicks (false, false); addAndMakeVisible (currentImage); resized(); } } if (currentImage != nullptr) currentImage->setAlpha (opacity); }
void mapWidget::mousePressEvent(QMouseEvent *e) { if (e -> button() == Qt::LeftButton) { if (p_wantZoom) { p_initial = e -> pos(); p_prev = e -> pos(); p_zooming = true; } else if (p_wantMove) { p_initial = e -> pos(); setCursor(Qt::SizeAllCursor); p_moving = true; } else { QRgb rgb; QImage *currentImage; currentImage = getCurrentImage(); rgb = currentImage -> pixel(e -> x(), e -> y()); emit clicked(rgb, e -> pos()); } } else { if (p_wantZoom) { setOriginalImage(); } else e->ignore(); // that makes the event go to mapasker and clear the popup } }
void AppsPageComponent::buttonStateChanged(Button* btn) { auto appBtn = (AppIconButton*)btn; auto appIcon = (DrawableImage*)appBtn->getCurrentImage(); auto buttonPopup = launcherComponent->focusButtonPopup.get(); constexpr auto scale = 1.3; // show floating button popup if we're holding downstate and not showing the popup if (btn->isMouseButtonDown() && btn->isMouseOver() && !buttonPopup->isVisible()) { // copy application icon bounds in screen space auto boundsNext = appIcon->getScreenBounds(); auto boundsCentre = boundsNext.getCentre(); // scale and recenter boundsNext.setSize(boundsNext.getWidth()*scale, boundsNext.getHeight()*scale); boundsNext.setCentre(boundsCentre); // translate back to space local to popup parent (local bounds) auto parentPos = launcherComponent->getScreenPosition(); boundsNext.setPosition(boundsNext.getPosition() - parentPos); // show popup icon, hide real button beneath buttonPopup->setImage(appIcon->getImage()); buttonPopup->setBounds(boundsNext); buttonPopup->setVisible(true); appIcon->setVisible(false); appBtn->setColour(DrawableButton::textColourId, Colours::transparentWhite); } // set UI back to default if we can see the popup, but aren't holding the button down else if (btn->isVisible()) { appIcon->setVisible(true); appBtn->setColour(DrawableButton::textColourId, getLookAndFeel().findColour(DrawableButton::textColourId)); buttonPopup->setVisible(false); } }
void MidiPad::paintButton (Graphics& g, bool isMouseOverButton, bool isButtonDown) { Rectangle<float> imageSpace; const float insetX = getWidth()*(1.f-imageSize)*0.5f; const float insetY = getHeight()*(1.f-imageSize)*0.5f; imageSpace.setBounds (insetX, insetY, getWidth() - insetX * 2, getHeight() - insetY * 2); MidiPad::drawButtonBackground (g, *this, getBackgroundColour(), isMouseOverButton, isButtonDown); g.setImageResamplingQuality (Graphics::highResamplingQuality); g.setOpacity (1.0f); const Drawable* imageToDraw = 0; imageToDraw = getCurrentImage(); if (imageToDraw != 0) { imageToDraw->drawWithin (g, imageSpace, RectanglePlacement::centred, 1.f); } }
bool ImageBuffer::openReadFiles() { //printf("Open video: %s\n",saveFileName[0]); { std::stringstream msgStr; msgStr << "Open video "<< saveFileName[0]; logPrintf(logLevelInfo_e,"ImageBuffer", msgStr.str().c_str()); } if(!readFileFlag) { reader.open(saveFileName[0]); if(!reader.isOpened()) { //printf("cannot open reader %s file\n",saveFileName[0]); std::stringstream msgStr; msgStr << "cannot open reader "<< saveFileName[0] << "file"; logPrintf(logLevelError_e,"ImageBuffer", msgStr.str().c_str()); return false; } bufferSize = reader.get(CV_CAP_PROP_FRAME_COUNT); _imageWidth = reader.get(CV_CAP_PROP_FRAME_WIDTH); _imageHeight = reader.get(CV_CAP_PROP_FRAME_HEIGHT); readFp = fopen(saveFileName[1],"r"); if(readFp == NULL) { //printf("cannot open the reader %s file\n",saveFileName[1]); std::stringstream msgStr; msgStr << "cannot open reader "<< saveFileName[1] << "file"; logPrintf(logLevelError_e,"ImageBuffer", msgStr.str().c_str()); return false; } // Distance compensation to minimize systematic error //if (0) { // read existing location from file std::vector<point3D_t> locVec, locSmoothed,locVecAhead; for(int idx = 0; idx < bufferSize; idx++) { point3D_t locPoint; fscanf(readFp,"%lf,%lf\n",&locPoint.lat, &locPoint.lon); locVec.push_back(locPoint); } // smooth the gps by 7-order average filter ns_database::smoothGps(7,locVec,locSmoothed); // skip 3 frames imageInfo_t image; getCurrentImage(&image); getCurrentImage(&image); getCurrentImage(&image); fclose(readFp); // look ahead ns_database::lookAheadOnTrack(locSmoothed, inParamVec[0].offsetDist, locVecAhead); char compensationFileName[50] = "c.txt"; // write new location to file readFp = fopen(compensationFileName, "wt"); if(readFp == NULL) { printf("cannot open the reader %s file\n", compensationFileName); return false; } for(int idx = 0; idx < locVecAhead.size(); idx++) { point3D_t locPoint; fprintf(readFp, "%.14lf,%.14lf\n",locVecAhead[idx].lat, locVecAhead[idx].lon); } fclose(readFp); readFp = fopen(compensationFileName, "rt"); if(readFp == NULL) { printf("cannot open the reader %s file\n", compensationFileName); return false; } bufferSize = locVecAhead.size(); if(0 >= bufferSize) { readFileFlag = true; // read file already open, set the flag to true before return return false; } // reset read index to 0 readIdx = 0; } readFileFlag = true; return true; } return false; }
//Gotta find out how to move these methods out of this file and into // listOperations.c void removeNode() { if(first == NULL) { return; } ListNode* currentImage = getCurrentImage(first); //first and only image if(currentImage->previous == NULL && (currentImage->next == NULL)) { first = NULL; free(currentImage); } //Last node of the list else if(currentImage->next == NULL) { ListNode* temp = currentImage; currentImage = currentImage->previous; currentImage->next = NULL; currentImage->current = TRUE; free(temp); } else { ListNode* temp = currentImage; //Fixes the index numbers for all the following nodes while(temp->next != NULL) { temp = temp->next; temp->index = (temp->index - 1); } temp = currentImage; //Setting the next node link to the node before the one being deleted currentImage->next->previous = currentImage->previous; //first image has to be treated if(currentImage->previous != NULL) { currentImage->previous->next = currentImage->next; } else { first = currentImage->next; } //Setting the current image if(currentImage->next != NULL) { currentImage = currentImage->next; } else { currentImage = currentImage->previous; } currentImage->current = TRUE; free(temp); } }
void DrawableButton::paintButton (Graphics& g, bool isMouseOverButton, bool isButtonDown) { Rectangle imageSpace; if (style == ImageOnButtonBackground) { const int insetX = getWidth() / 4; const int insetY = getHeight() / 4; imageSpace.setBounds (insetX, insetY, getWidth() - insetX * 2, getHeight() - insetY * 2); getLookAndFeel().drawButtonBackground (g, *this, getBackgroundColour(), isMouseOverButton, isButtonDown); } else { g.fillAll (getBackgroundColour()); const int textH = (style == ImageAboveTextLabel) ? jmin (16, proportionOfHeight (0.25f)) : 0; const int indentX = jmin (edgeIndent, proportionOfWidth (0.3f)); const int indentY = jmin (edgeIndent, proportionOfHeight (0.3f)); imageSpace.setBounds (indentX, indentY, getWidth() - indentX * 2, getHeight() - indentY * 2 - textH); if (textH > 0) { g.setFont ((float) textH); g.setColour (Colours::black.withAlpha (isEnabled() ? 1.0f : 0.4f)); g.drawFittedText (getButtonText(), 2, getHeight() - textH - 1, getWidth() - 4, textH, Justification::centred, 1); } } g.setImageResamplingQuality (Graphics::mediumResamplingQuality); g.setOpacity (1.0f); const Drawable* imageToDraw = 0; if (isEnabled()) { imageToDraw = getCurrentImage(); } else { imageToDraw = getToggleState() ? disabledImageOn : disabledImage; if (imageToDraw == 0) { g.setOpacity (0.4f); imageToDraw = getNormalImage(); } } if (imageToDraw != 0) { if (style == ImageRaw) { imageToDraw->draw (g, 1.0f); } else { imageToDraw->drawWithin (g, imageSpace.getX(), imageSpace.getY(), imageSpace.getWidth(), imageSpace.getHeight(), RectanglePlacement::centred, 1.0f); } } }
void ImageExample::touchDown( ofTouchEventArgs & touch ) { TUIO::TuioCursor* cursor1 = nullptr; TUIO::TuioCursor* cursor2 = nullptr; TUIO::TuioCursor* cursor3 = nullptr; TUIO::TuioCursor* cursor4 = nullptr; unsigned long long currentTime = ofGetElapsedTimeMillis(); if(currentTime - m_elapsedTime <= 500) { m_Mode = M_DOUBLETAP; } else { m_Mode = M_TAP; } int cursorNum = MyClient.client->getTuioCursors().size(); switch (cursorNum) { case 1: //앨범이고 더블클릭일 경우 사진들 숨기기 for ( auto *iter : MyClient.client->getTuioCursors() ) { switch ( iter->getCursorID() ) { case 0: cursor1 = iter; break; default: break; } } if(cursor1 == nullptr) return; m_currentElement = getCurrentImage(cursor1); if(m_currentElement == nullptr) { break; } if(m_currentElement->m_isCover && m_Mode == M_DOUBLETAP) { hideImages(m_currentElement); } //앨범이고 탭일 경우 사진들 보이기 else if(m_currentElement->m_isCover && m_Mode == M_TAP) { showImages(m_currentElement); } //사진일 경우 단순 선택 else if(m_currentElement->m_isCover == false && m_Mode == M_TAP) { m_currentElement->m_Mode = M_TAP; } break; case 2: for ( auto *iter : MyClient.client->getTuioCursors() ) { switch ( iter->getCursorID() ) { case 0: cursor1 = iter; break; case 1: cursor2 = iter; break; break; default: break; } } if (cursor1 == nullptr || cursor2 == nullptr) { return; } if(getCurrentImage(cursor1) ==nullptr && getCurrentImage(cursor2)==nullptr) break; if(getCurrentImage(cursor1)==getCurrentImage(cursor2)) m_currentElement = getCurrentImage(cursor1); else if(getCurrentImage(cursor1)!= nullptr && getCurrentImage(cursor2)==nullptr) m_currentElement = getCurrentImage(cursor1); else if(getCurrentImage(cursor1)== nullptr && getCurrentImage(cursor2)!=nullptr) m_currentElement = getCurrentImage(cursor2); else break; if(m_currentElement->m_isCover == true) return; m_currentElement->m_Distance =sqrt(pow(cursor1->getX()-cursor2->getX(),2)+pow(cursor1->getY()-cursor2->getY(),2)); m_backOriginX = (cursor1->getX()-cursor2->getX())/2; m_backOriginY = (cursor1->getY()-cursor2->getY())/2; m_currentAngle = 180.0 * atan( ( cursor1->getY() - cursor2->getY() ) / ( cursor1->getX() - cursor2->getX() )) * PI; m_Mode = M_SCALE; break; case 3: for ( auto *iter : MyClient.client->getTuioCursors() ) { switch ( iter->getCursorID() ) { case 0: cursor1 = iter; break; case 1: cursor2 = iter; break; case 2: cursor3 = iter; break; default: break; } } if (cursor1 == nullptr || cursor2 == nullptr|| cursor3 == nullptr) { return; } m_Mode = M_ZOOM; m_currentElement = getZoomingImage(cursor1,cursor2,cursor3); break; case 4: for ( auto *iter : MyClient.client->getTuioCursors() ) { switch ( iter->getCursorID() ) { case 0: cursor1 = iter; break; case 1: cursor2 = iter; break; case 2: cursor3 = iter; break; case 3: cursor4 = iter; break; default: break; } } if (cursor1 == nullptr || cursor2 == nullptr|| cursor3 == nullptr|| cursor4 == nullptr) { return; } m_Mode = M_NAVIGATION; m_backOriginX = WINDOW_WIDTH*(cursor1->getX()+cursor2->getX() + cursor3->getX()+cursor4->getX())/4; m_backOriginY = WINDOW_HEIGHT*(cursor1->getY()+cursor2->getY() + cursor3->getY()+cursor4->getY())/4; break; default: break; } m_elapsedTime = currentTime; }
void ofxSprite::customDraw() { if (!visible) return; getCurrentImage().draw(-anchorPoint); }
float ofxSprite::getHeight() { return getCurrentImage().getHeight(); }
float ofxSprite::getWidth() { return getCurrentImage().getWidth(); }
void ofxSprite::draw(float x, float y) { //or should this one call setPosition and then draw()? getCurrentImage().draw(ofPoint(x,y)-anchorPoint); }
void ImageButton::paintButton (Graphics& g, bool isMouseOverButton, bool isButtonDown) { if (! isEnabled()) { isMouseOverButton = false; isButtonDown = false; } Image im (getCurrentImage()); if (im.isValid()) { const int iw = im.getWidth(); const int ih = im.getHeight(); imageW = getWidth(); imageH = getHeight(); imageX = (imageW - iw) >> 1; imageY = (imageH - ih) >> 1; if (scaleImageToFit) { if (preserveProportions) { int newW, newH; const float imRatio = ih / (float)iw; const float destRatio = imageH / (float)imageW; if (imRatio > destRatio) { newW = roundToInt (imageH / imRatio); newH = imageH; } else { newW = imageW; newH = roundToInt (imageW * imRatio); } imageX = (imageW - newW) / 2; imageY = (imageH - newH) / 2; imageW = newW; imageH = newH; } else { imageX = 0; imageY = 0; } } if (! scaleImageToFit) { imageW = iw; imageH = ih; } getLookAndFeel().drawImageButton (g, &im, imageX, imageY, imageW, imageH, isButtonDown ? downOverlay : (isMouseOverButton ? overOverlay : normalOverlay), isButtonDown ? downOpacity : (isMouseOverButton ? overOpacity : normalOpacity), *this); } }
void ImageButton::paintButton (Graphics& g, bool isMouseOverButton, bool isButtonDown) { if (! isEnabled()) { isMouseOverButton = false; isButtonDown = false; } Image im (getCurrentImage()); if (im.isValid()) { const int iw = im.getWidth(); const int ih = im.getHeight(); int w = getWidth(); int h = getHeight(); int x = (w - iw) / 2; int y = (h - ih) / 2; if (scaleImageToFit) { if (preserveProportions) { int newW, newH; const float imRatio = ih / (float) iw; const float destRatio = h / (float) w; if (imRatio > destRatio) { newW = roundToInt (h / imRatio); newH = h; } else { newW = w; newH = roundToInt (w * imRatio); } x = (w - newW) / 2; y = (h - newH) / 2; w = newW; h = newH; } else { x = 0; y = 0; } } if (! scaleImageToFit) { w = iw; h = ih; } imageBounds.setBounds (x, y, w, h); const bool useDownImage = isButtonDown || getToggleState(); getLookAndFeel().drawImageButton (g, &im, x, y, w, h, useDownImage ? downOverlay : (isMouseOverButton ? overOverlay : normalOverlay), useDownImage ? downOpacity : (isMouseOverButton ? overOpacity : normalOpacity), *this); } }
//============================================================================== void DrawablePad::paintButton (Graphics& g, bool isMouseOverButton, bool isButtonDown) { const int insetX = getWidth() / 4; const int insetY = getHeight() / 4; Rectangle imageSpace; imageSpace.setBounds (insetX, insetY, getWidth() - insetX * 2, getHeight() - insetY * 2); drawButtonBackground (g, *this, getBackgroundColour(), isMouseOverButton, isButtonDown); g.setOpacity (1.0f); const Drawable* imageToDraw = 0; if (isEnabled()) { imageToDraw = getCurrentImage(); } else { imageToDraw = getToggleState() ? disabledImageOn : disabledImage; if (imageToDraw == 0) { g.setOpacity (0.4f); imageToDraw = getNormalImage(); } } if (imageToDraw != 0) { g.setImageResamplingQuality (Graphics::highResamplingQuality); imageToDraw->drawWithin (g, imageSpace.getX(), imageSpace.getY(), imageSpace.getWidth(), imageSpace.getHeight(), RectanglePlacement::centred, 1.0f); } float fontsize = jmin ((float)(proportionOfWidth(0.2f)),(float)(proportionOfHeight(0.15f))); if (fontsize < 5.0) fontsize=5.0; g.setFont (Font (fontsize, Font::bold)); g.setColour (getBackgroundColour().contrasting(0.8f)); g.drawText (Label, proportionOfWidth (0.0447f), proportionOfHeight (0.0499f), proportionOfWidth (0.9137f), proportionOfHeight (0.1355f), Justification::centred, true); if (showdot && ! hex) { g.setFont (Font (fontsize*0.9f, Font::plain)); String xy; if (showx && showy) xy = T("x:") + String((int)(x*127.1)) + T(" y:") + String((int)(y*127.1)); else if (showx) xy = T("x:") + String((int)(x*127.1)); else if (showy) xy = T("y:") + String((int)(y*127.1)); g.drawText (xy, proportionOfWidth (0.0447f), proportionOfHeight (0.8057f), proportionOfWidth (0.9137f), proportionOfHeight (0.1355f), Justification::centred, true); float diameter = jmin ((float)(proportionOfHeight(0.125f)), (float)(proportionOfWidth(0.5f))); g.setColour (Colour (0x88faa52a)); g.fillEllipse ((float)(proportionOfWidth(x)) - diameter*0.5f, (float)(proportionOfHeight(1.0f-y)) - diameter*0.5f, diameter, diameter); g.setColour (Colour (0x99a52a88)); g.drawEllipse ((float)(proportionOfWidth(x)) - diameter*0.5f, (float)(proportionOfHeight(1.0f-y)) - diameter*0.5f, diameter, diameter, diameter*0.1f); } }
// Main function int main( void ) { char command[MAXLENGTH]; char c; /******************************************************************** * YOU WILL NEED TO COMPLETE THE FOLLOWING SECTION FOR STAGES 2 - 5 * *******************************************************************/ printPrompt(); while( fgets( command, MAXLENGTH, stdin ) != NULL ) { int imgNum; char *p; if(( p=strrchr( command, '\n')) != NULL ) { *p = '\0'; // remove '\n' at end of line } // find the first non-space character in the command p = command; while(isspace(*p)) { p++; } c = tolower(*p); if( isdigit(c)) // Command k { if( sscanf( command, "%d", &imgNum ) == 1 ) { //Checks to see if there's images in the album. if(first != NULL) { //Retrieves the image. found = getCurrentImage(first); found2 = selectImage(found, imgNum); //Checks to see if the requested image exist in the album. if(found2 != NULL) { found->current = FALSE; found2->current = TRUE; printNodeInfos(found2); last_action = 'k'; location = found->index; //Index of the previous image found = NULL; found2 = NULL; } } } } else switch( c ) { case 'h': // help printf(" A - Add image\n" ); printf(" I - Index\n" ); printf(" P - Print image\n" ); printf(" F - Forward\n" ); printf(" B - Back\n" ); printf("<k>- make image number k the current image\n"); printf(" D - Delete image\n" ); printf(" L - Look for image\n" ); printf(" R - Rotate image counterclockwise\n" ); printf(" M - Mirror image (reflect vertically)\n" ); printf("NE - zoom into North East corner\n" ); printf("NW - zoom into North West corner\n" ); printf("SW - zoom into South West corner\n" ); printf("SE - zoom into South East corner\n" ); printf(" O - zoom Out\n" ); printf(" U - Undo\n" ); printf(" H - Help\n" ); printf(" Q - Quit\n" ); break; // INSERT CODE FOR OTHER COMMANDS case 'a': p++; //Moves cursor away from 'a' while(isspace(*p)) { p++; } int *dim; QTnode* qt = getImage(p, dim); if(qt != NULL) { insertNode(qt, dim, p); printNodeInfos(getCurrentImage(first)); //Whenever a node is added, it becomes the selected node } last_action = 'a'; break; case 'i': if(first != NULL) { printIndex(first); } break; case 'p': { ListNode* currentImage = getCurrentImage(first); if(currentImage != NULL) { printImage(currentImage->image, currentImage->size); } break; } case 'f': { ListNode* currentImage = getCurrentImage(first); if(currentImage != NULL && (currentImage->next != NULL)) { currentImage->current = FALSE; currentImage = currentImage->next; currentImage->current = TRUE; printNodeInfos(currentImage); last_action = 'f'; } break; } case 'b': { ListNode* currentImage = getCurrentImage(first); if(currentImage != NULL && (currentImage->previous != NULL)) { currentImage->current = FALSE; currentImage = currentImage->previous; currentImage->current = TRUE; printNodeInfos(currentImage); last_action = 'b'; } break; } //'K' command is treated in the upper portion of the code case 'd': removeNode(); if(first != NULL) { printNodeInfos(getCurrentImage(first)); } last_action = 'd'; break; case 'l': if(first != NULL) { p++; //Moves cursor away from 'a' while(isspace(*p)) { p++; } ListNode* foundImage = findBySubString(first, p); //Image with the substring was found if(foundImage != NULL) { ListNode* currentImage = getCurrentImage(first); currentImage->current = FALSE; foundImage->current = TRUE; printNodeInfos(getCurrentImage(first)); last_action = 'l'; location = currentImage->index; } } break; case 'r': { ListNode* currentImage = getCurrentImage(first); if(currentImage != NULL) { rotateImage(currentImage->image); printImage(currentImage->image, currentImage->size); } last_action = 'r'; break; } case 'm': { ListNode* currentImage = getCurrentImage(first); if(currentImage != NULL) { mirrorImage(currentImage->image); printImage(currentImage->image, currentImage->size); } last_action = 'm'; break; } case 'n': { ListNode* currentImage = getCurrentImage(first); if(currentImage == NULL) { break; } //This line gets the next character of the command, so it can be //treated accordingly. char c2 = *(++p); //Dereferencing the pointer and moving it to the next char of the string if(c2 == 'e') { if(currentImage->image->ne == NULL) { break; } currentImage->image = currentImage->image->ne; printImage(currentImage->image, currentImage->size); last_action = 'w'; //because "ne" does not work, find a letter that is not used location = 'w'; } else if(c2 == 'w') { if(currentImage->image->nw == NULL) { break; } currentImage->image = currentImage->image->nw; printImage(currentImage->image, currentImage->size); last_action = 'x'; location = 'x'; } break; } case 's': { ListNode* currentImage = getCurrentImage(first); if(currentImage == NULL) { break; } //This line gets the next character of the command, so it can be //treated accordingly. char c2 = *(++p); //Dereferencing the pointer and moving it to the next char of the string if(c2 == 'e') { if(currentImage->image->se == NULL) { break; } currentImage->image = currentImage->image->se; printImage(currentImage->image, currentImage->size); last_action = 'y'; location = 'y'; } else if(c2 == 'w') { if(currentImage->image->sw == NULL) { break; } currentImage->image = currentImage->image->sw; printImage(currentImage->image, currentImage->size); last_action = 'z'; location = 'z'; } break; } case 'o': { ListNode* currentImage = getCurrentImage(first); if(currentImage == NULL || (currentImage->image->out == NULL)) { break; } currentImage->image = currentImage->image->out; printImage(currentImage->image, currentImage->size); last_action = 'o'; break; } case 'u': if(last_action == 'm'){ ListNode* currentImage = getCurrentImage(first); if(currentImage != NULL) { mirrorImage(currentImage->image); printImage(currentImage->image, currentImage->size); } break; } else if(last_action == 'r'){ ListNode* currentImage = getCurrentImage(first); if(currentImage != NULL) { rotateImage(currentImage->image); rotateImage(currentImage->image); rotateImage(currentImage->image); printImage(currentImage->image, currentImage->size); break; } } else if(last_action == 'a'){ removeNode(); if(first != NULL) { printNodeInfos(getCurrentImage(first)); } break; } else if(last_action == 'd'){ //todo me no smart break; } else if(last_action == 'w' || (last_action == 'x') || (last_action == 'y') || (last_action == 'z')){ ListNode* currentImage = getCurrentImage(first); if(currentImage == NULL || (currentImage->image->out == NULL)) { break; } currentImage->image = currentImage->image->out; printImage(currentImage->image, currentImage->size); break; } else if(last_action == 'o'){ ListNode* currentImage = getCurrentImage(first); if(location == 'w') { if(currentImage->image->ne == NULL) { break; } currentImage->image = currentImage->image->ne; printImage(currentImage->image, currentImage->size); break; } else if(location == 'x') { if(currentImage->image->nw == NULL) { break; } currentImage->image = currentImage->image->nw; printImage(currentImage->image, currentImage->size); break; } else if(location == 'y') { if(currentImage->image->se == NULL) { break; } currentImage->image = currentImage->image->se; printImage(currentImage->image, currentImage->size); break; } else if(location == 'z') { if(currentImage->image->sw == NULL) { break; } currentImage->image = currentImage->image->sw; printImage(currentImage->image, currentImage->size); break; } } else if(last_action == 'b'){ ListNode* currentImage = getCurrentImage(first); if(currentImage != NULL && (currentImage->next != NULL)) { currentImage->current = FALSE; currentImage = currentImage->next; currentImage->current = TRUE; printNodeInfos(currentImage); } break; } else if(last_action == 'f'){ ListNode* currentImage = getCurrentImage(first); if(currentImage != NULL && (currentImage->previous != NULL)) { currentImage->current = FALSE; currentImage = currentImage->previous; currentImage->current = TRUE; printNodeInfos(currentImage); } break; } else if(last_action == 'k' || (last_action == 'l')){ //Retrieves the image. found = getCurrentImage(first); found2 = selectImage(found, location); //Checks to see if the requested image exist in the album. if(found2 != NULL) { found->current = FALSE; found2->current = TRUE; printNodeInfos(found2); found = NULL; found2 = NULL; } break; } case 'q': // quit program printf("Bye!\n"); return 0; break; default: printf("Unrecognized command: %s\n", command ); break; } printPrompt(); } return 0; }