std::shared_ptr<Image> Visualizer::CaptureScreenFloatBuffer( bool do_render/* = true*/) { Image screen_image; screen_image.PrepareImage(view_control_ptr_->GetWindowWidth(), view_control_ptr_->GetWindowHeight(), 3, 4); if (do_render) { Render(); is_redraw_required_ = false; } glFinish(); glReadPixels(0, 0, view_control_ptr_->GetWindowWidth(), view_control_ptr_->GetWindowHeight(), GL_RGB, GL_FLOAT, screen_image.data_.data()); // glReadPixels get the screen in a vertically flipped manner // Thus we should flip it back. auto image_ptr = std::make_shared<Image>(); image_ptr->PrepareImage(view_control_ptr_->GetWindowWidth(), view_control_ptr_->GetWindowHeight(), 3, 4); int bytes_per_line = screen_image.BytesPerLine(); for (int i = 0; i < screen_image.height_; i++) { memcpy(image_ptr->data_.data() + bytes_per_line * i, screen_image.data_.data() + bytes_per_line * (screen_image.height_ - i - 1), bytes_per_line); } return image_ptr; }
void cScreenMovieMaker::update_image() { if((selected_girl)) //&& !IsMultiSelected(girllist_id)) { PrepareImage(girlimage_id, selected_girl, IMGTYPE_PROFILE, true, ImageNum); HideImage(girlimage_id, false); } else { HideImage(girlimage_id, true); } }
BOOL CAvatarProfilePage::OnInitDialog() { CSettingsPage::OnInitDialog(); if ( CXMLElement* pAvatar = MyProfile.GetXML( _T("avatar") ) ) { m_sAvatar = pAvatar->GetAttributeValue( _T("path") ); PrepareImage(); } return TRUE; }
void CAvatarProfilePage::OnAvatarBrowse() { CFileDialog dlg( TRUE, _T("png"), m_sAvatar, OFN_HIDEREADONLY, _T("Image Files|*.jpg;*.jpeg;*.png;*.bmp|All Files|*.*||"), this ); if ( dlg.DoModal() == IDOK ) { m_sAvatar = dlg.GetPathName(); PrepareImage(); Invalidate(); } }
void wgt_QVideoPlayer::s_TimerEvent() { if (IsSliderProcess) return; // No re-entrance if (!(PlayerPlayMode && !PlayerPauseMode)) return; // Only if play mode TimerTick=!TimerTick; #ifdef Q_OS_WIN // Trylock is always true on Windows instead of unix/linux system if (TimerTick) { #else if (!PlayerMutex.tryLock()) { if (!TimerTick) return; else { #endif /* // specific case for windows because never a timer event can happens if a previous timer event was not ended // so next trylock is always true int Elapsed=0,Wanted=int(double(1000)/ApplicationConfig->PreviewFPS); if (!PreviousTimerEvent.isValid()) PreviousTimerEvent.start(); else Elapsed=PreviousTimerEvent.restart(); if (Elapsed>Wanted) { TimerDelta+=Elapsed-Wanted; if (TimerDelta>=Wanted) { ToLog(LOGMSG_DEBUGTRACE,"FPS preview is too high: One image lost"); if (FrameList.List.count()>0) delete (cDiaporamaObjectInfo *)FrameList.DetachFirstFrame(); // Remove first image if we loose one tick else Diaporama->CurrentPosition+=Wanted; // Increase next position to one frame TimerDelta-=Wanted; } } */ } #ifdef Q_OS_WIN PlayerMutex.lock(); #else return;} #endif if (ThreadPrepareVideo.isRunning()) ThreadPrepareVideo.waitForFinished(); if (ThreadPrepareImage.isRunning()) ThreadPrepareImage.waitForFinished(); if (ThreadAssembly.isRunning()) ThreadAssembly.waitForFinished(); int64_t LastPosition=0,NextPosition=0; if (ResetPositionWanted) { Mutex.lock(); MixedMusic.ClearList(); // Free sound buffers Music.ClearList(); // Free sound buffers FrameList.ClearList(); // Free FrameList ResetPositionWanted=false; Mutex.unlock(); } if (ThreadAssembly.isRunning()) ThreadAssembly.waitForFinished(); // If no image in the list then create the first if (FrameList.List.count()==0) { LastPosition=Diaporama->CurrentPosition; NextPosition=LastPosition+int(double(1000)/ApplicationConfig->PreviewFPS); // If no image in the list then prepare a first frame cDiaporamaObjectInfo *Frame=new cDiaporamaObjectInfo(NULL,NextPosition,Diaporama,double(1000)/ApplicationConfig->PreviewFPS,true); // Ensure MusicTracks are ready if ((Frame->CurrentObject)&&(Frame->CurrentObject_MusicTrack==NULL)) { Frame->CurrentObject_MusicTrack=new cSoundBlockList(); Frame->CurrentObject_MusicTrack->SetFPS(double(1000)/double(ApplicationConfig->PreviewFPS),2,Diaporama->ApplicationConfig->PreviewSamplingRate,AV_SAMPLE_FMT_S16); } if ((Frame->TransitObject)&&(Frame->TransitObject_MusicTrack==NULL)&&(Frame->TransitObject_MusicObject!=NULL)&&(Frame->TransitObject_MusicObject!=Frame->CurrentObject_MusicObject)) { Frame->TransitObject_MusicTrack=new cSoundBlockList(); Frame->TransitObject_MusicTrack->SetFPS(double(1000)/double(ApplicationConfig->PreviewFPS),2,Diaporama->ApplicationConfig->PreviewSamplingRate,AV_SAMPLE_FMT_S16); } // Ensure SoundTracks are ready if ((Frame->CurrentObject)&&(Frame->CurrentObject_SoundTrackMontage==NULL)) { Frame->CurrentObject_SoundTrackMontage=new cSoundBlockList(); Frame->CurrentObject_SoundTrackMontage->SetFPS(double(1000)/double(ApplicationConfig->PreviewFPS),2,Diaporama->ApplicationConfig->PreviewSamplingRate,AV_SAMPLE_FMT_S16); } if ((Frame->TransitObject)&&(Frame->TransitObject_SoundTrackMontage==NULL)) { Frame->TransitObject_SoundTrackMontage=new cSoundBlockList(); Frame->TransitObject_SoundTrackMontage->SetFPS(double(1000)/double(ApplicationConfig->PreviewFPS),2,Diaporama->ApplicationConfig->PreviewSamplingRate,AV_SAMPLE_FMT_S16); } // Ensure background, image and soundtrack is ready int H=ui->MovieFrame->height(); int W=Diaporama->GetWidthForHeight(H); if (W>ui->MovieFrame->width()) { W=ui->MovieFrame->width(); H=Diaporama->GetHeightForWidth(W); } if ((Frame->IsTransition)&&(Frame->TransitObject)) Diaporama->CreateObjectContextList(Frame,W,H,false,true,true,PreparedTransitBrushList,Diaporama); Diaporama->CreateObjectContextList(Frame,W,H,true,true,true,PreparedBrushList,Diaporama); if (audio_outputStream->state()==QAudio::IdleState) { int len=audio_outputStream->bytesFree(); if (len==audio_outputStream->bufferSize()) { memset(AudioBuf,0,AUDIOBUFSIZE); AudioBufSize=len-MixedMusic.NbrPacketForFPS*MixedMusic.SoundPacketSize; } } PrepareImage(true,true,Frame,W,H); if (ThreadAssembly.isRunning()) ThreadAssembly.waitForFinished(); } // Add image to the list if it's not full if (((Diaporama)&&(FrameList.List.count()<BUFFERING_NBR_FRAME))&&(!ThreadPrepareImage.isRunning())) { cDiaporamaObjectInfo *PreviousFrame=(cDiaporamaObjectInfo *)FrameList.GetLastFrame(); if (Diaporama) LastPosition=PreviousFrame->CurrentObject_StartTime+PreviousFrame->CurrentObject_InObjectTime; NextPosition=LastPosition+int(double(1000)/ApplicationConfig->PreviewFPS); cDiaporamaObjectInfo *Frame=new cDiaporamaObjectInfo(PreviousFrame,NextPosition,Diaporama,double(1000)/ApplicationConfig->PreviewFPS,true); // Ensure MusicTracks are ready if ((Frame->CurrentObject)&&(Frame->CurrentObject_MusicTrack==NULL)) { Frame->CurrentObject_MusicTrack=new cSoundBlockList(); Frame->CurrentObject_MusicTrack->SetFPS(double(1000)/double(ApplicationConfig->PreviewFPS),2,Diaporama->ApplicationConfig->PreviewSamplingRate,AV_SAMPLE_FMT_S16); } if ((Frame->TransitObject)&&(Frame->TransitObject_MusicTrack==NULL)&&(Frame->TransitObject_MusicObject!=NULL)&&(Frame->TransitObject_MusicObject!=Frame->CurrentObject_MusicObject)) { Frame->TransitObject_MusicTrack=new cSoundBlockList(); Frame->TransitObject_MusicTrack->SetFPS(double(1000)/double(ApplicationConfig->PreviewFPS),2,Diaporama->ApplicationConfig->PreviewSamplingRate,AV_SAMPLE_FMT_S16); } // Ensure SoundTracks are ready if ((Frame->CurrentObject)&&(Frame->CurrentObject_SoundTrackMontage==NULL)) { Frame->CurrentObject_SoundTrackMontage=new cSoundBlockList(); Frame->CurrentObject_SoundTrackMontage->SetFPS(double(1000)/double(ApplicationConfig->PreviewFPS),2,Diaporama->ApplicationConfig->PreviewSamplingRate,AV_SAMPLE_FMT_S16); } if ((Frame->TransitObject)&&(Frame->TransitObject_SoundTrackMontage==NULL)) { Frame->TransitObject_SoundTrackMontage=new cSoundBlockList(); Frame->TransitObject_SoundTrackMontage->SetFPS(double(1000)/double(ApplicationConfig->PreviewFPS),2,Diaporama->ApplicationConfig->PreviewSamplingRate,AV_SAMPLE_FMT_S16); } // Ensure background, image and soundtrack is ready int H=ui->MovieFrame->height(); int W=Diaporama->GetWidthForHeight(H); if (W>ui->MovieFrame->width()) { W=ui->MovieFrame->width(); H=Diaporama->GetHeightForWidth(W); } if ((Frame->IsTransition)&&(Frame->TransitObject)) Diaporama->CreateObjectContextList(Frame,W,H,false,true,true,PreparedTransitBrushList,Diaporama); Diaporama->CreateObjectContextList(Frame,W,H,true,true,true,PreparedBrushList,Diaporama); ThreadPrepareImage.setFuture(QtConcurrent::run(this,&wgt_QVideoPlayer::PrepareImage,true,true,Frame,W,H)); } PlayerMutex.unlock(); // Audio if ((audio_outputStream->state()==QAudio::ActiveState)||(audio_outputStream->state()==QAudio::IdleState)) { int len=audio_outputStream->bytesFree(); if (len>0) { Mutex.lock(); while ((AudioBufSize<len)&&(MixedMusic.ListCount()>0)) { int16_t *Packet=MixedMusic.DetachFirstPacket(true); if (Packet!=NULL) { memcpy(AudioBuf+AudioBufSize,Packet,MixedMusic.SoundPacketSize); AudioBufSize+=MixedMusic.SoundPacketSize; } else { memset(AudioBuf+AudioBufSize,0,MixedMusic.SoundPacketSize); AudioBufSize+=MixedMusic.SoundPacketSize; } } if (len>AudioBufSize) len=AudioBufSize; if (len) { int RealLen=audio_outputDevice->write((char *)AudioBuf,len); if (RealLen<=AudioBufSize) { memcpy(AudioBuf,AudioBuf+RealLen,AudioBufSize-RealLen); AudioBufSize-=RealLen; } AudioPlayed+=RealLen; } Mutex.unlock(); // Preview is updated is sound played correspond to 1 FPS if (AudioPlayed>=MixedMusic.NbrPacketForFPS*MixedMusic.SoundPacketSize) { s_SliderMoved(((cDiaporamaObjectInfo *)FrameList.GetFirstFrame())->CurrentObject_StartTime+((cDiaporamaObjectInfo *)FrameList.GetFirstFrame())->CurrentObject_InObjectTime); AudioPlayed-=MixedMusic.NbrPacketForFPS*MixedMusic.SoundPacketSize; } } } ui->BufferState->setValue(FrameList.List.count()); if (FrameList.List.count()<2) ui->BufferState->setStyleSheet("QProgressBar:horizontal {\nborder: 0px;\nborder-radius: 0px;\nbackground: black;\npadding-top: 1px;\npadding-bottom: 2px;\npadding-left: 1px;\npadding-right: 1px;\n}\nQProgressBar::chunk:horizontal {\nbackground: red;\n}"); else if (FrameList.List.count()<4) ui->BufferState->setStyleSheet("QProgressBar:horizontal {\nborder: 0px;\nborder-radius: 0px;\nbackground: black;\npadding-top: 1px;\npadding-bottom: 2px;\npadding-left: 1px;\npadding-right: 1px;\n}\nQProgressBar::chunk:horizontal {\nbackground: yellow;\n}"); else if (FrameList.List.count()<=BUFFERING_NBR_FRAME) ui->BufferState->setStyleSheet("QProgressBar:horizontal {\nborder: 0px;\nborder-radius: 0px;\nbackground: black;\npadding-top: 1px;\npadding-bottom: 2px;\npadding-left: 1px;\npadding-right: 1px;\n}\nQProgressBar::chunk:horizontal {\nbackground: green;\n}"); } //============================================================================================ // Function use directly or with thread to prepare an image number Column at given position //============================================================================================ void wgt_QVideoPlayer::PrepareImage(bool SoundWanted,bool AddStartPos,cDiaporamaObjectInfo *Frame,int W,int H) { Diaporama->LoadSources(Frame,W,H,true,AddStartPos,PreparedTransitBrushList,PreparedBrushList); // Do Assembly ThreadAssembly.setFuture(QtConcurrent::run(this,&wgt_QVideoPlayer::StartThreadAssembly,ComputePCT(Frame->CurrentObject?Frame->CurrentObject->GetSpeedWave():0,Frame->TransitionPCTDone),Frame,W,H,SoundWanted)); }
void wgt_QVideoPlayer::s_SliderMoved(int Value) { if (InPlayerUpdate) return; InPlayerUpdate=true; if ((ResetPositionWanted)||(Value>ui->CustomRuler->maximum())) SetPlayerToPause(); // Update display in controls ui->CustomRuler->setValue(Value); ActualPosition=Value; ui->Position->setText(GetCurrentPos().toString(DisplayMSec?"hh:mm:ss.zzz":"hh:mm:ss")); ui->Duration->setText(tDuration.toString(DisplayMSec?"hh:mm:ss.zzz":"hh:mm:ss")); //*********************************************************************** // If playing //*********************************************************************** if (PlayerPlayMode && !PlayerPauseMode) { if (FrameList.List.count()>1) { // Process // Retrieve frame information cDiaporamaObjectInfo *Frame=(cDiaporamaObjectInfo *)FrameList.DetachFirstFrame(); // Display frame if (!Frame->RenderedImage.isNull()) ui->MovieFrame->SetImage(Frame->RenderedImage.scaledToHeight(ui->MovieFrame->height())); // If Diaporama mode and needed, set Diaporama to another object if (Diaporama) { if (Diaporama->CurrentCol!=Frame->CurrentObject_Number) { Diaporama->CurrentCol=Frame->CurrentObject_Number; ((MainWindow *)ApplicationConfig->TopLevelWindow)->SetTimelineCurrentCell(Frame->CurrentObject_Number); // Update slider mark if (Diaporama->List.count()>0) SetStartEndPos( Diaporama->GetObjectStartPosition(Diaporama->CurrentCol), // Current slide Diaporama->List[Diaporama->CurrentCol]->GetDuration(), (Diaporama->CurrentCol>0)?Diaporama->GetObjectStartPosition(Diaporama->CurrentCol-1):((Diaporama->CurrentCol==0)?0:-1), // Previous slide (Diaporama->CurrentCol>0)?Diaporama->List[Diaporama->CurrentCol-1]->GetDuration():((Diaporama->CurrentCol==0)?Diaporama->GetTransitionDuration(Diaporama->CurrentCol):0), Diaporama->CurrentCol<(Diaporama->List.count()-1)?Diaporama->GetObjectStartPosition(Diaporama->CurrentCol+1):-1, // Next slide Diaporama->CurrentCol<(Diaporama->List.count()-1)?Diaporama->List[Diaporama->CurrentCol+1]->GetDuration():0); else SetStartEndPos(0,0,-1,0,-1,0); } Diaporama->CurrentPosition=Value; } // Free frame delete Frame; } //*********************************************************************** // If moving by user //*********************************************************************** } else if (Diaporama) { QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); if (ThreadPrepareVideo.isRunning()) ThreadPrepareVideo.waitForFinished(); if (ThreadPrepareImage.isRunning()) ThreadPrepareImage.waitForFinished(); if (ThreadAssembly.isRunning()) ThreadAssembly.waitForFinished(); // Create a frame from actual position cDiaporamaObjectInfo *Frame=new cDiaporamaObjectInfo(NULL,ActualPosition,Diaporama,double(1000)/ApplicationConfig->PreviewFPS,false); int H=ui->MovieFrame->height(); int W=Diaporama->GetWidthForHeight(H); if (W>ui->MovieFrame->width()) { W=ui->MovieFrame->width(); H=Diaporama->GetHeightForWidth(W); } if ((Frame->IsTransition)&&(Frame->TransitObject)) Diaporama->CreateObjectContextList(Frame,W,H,false,true,true,PreparedTransitBrushList,Diaporama); Diaporama->CreateObjectContextList(Frame,W,H,true,true,true,PreparedBrushList,Diaporama); PrepareImage(false,true,Frame,W,H); // This will add frame to the FrameList if (ThreadAssembly.isRunning()) ThreadAssembly.waitForFinished(); Frame=(cDiaporamaObjectInfo *)FrameList.DetachFirstFrame(); // Then detach frame from the FrameList // Display frame ui->MovieFrame->SetImage(Frame->RenderedImage.scaledToHeight(ui->MovieFrame->height())); // If needed, set Diaporama to another object if ((Diaporama->CurrentCol!=Frame->CurrentObject_Number)&&((!Frame->IsTransition)||(Diaporama->CurrentCol!=Frame->TransitObject_Number))) { if (FLAGSTOPITEMSELECTION!=NULL) *FLAGSTOPITEMSELECTION=true; // Ensure mainwindow no modify player widget position Diaporama->CurrentCol=Frame->CurrentObject_Number; if (FLAGSTOPITEMSELECTION!=NULL) *FLAGSTOPITEMSELECTION=false; ((MainWindow *)ApplicationConfig->TopLevelWindow)->SetTimelineCurrentCell(Frame->CurrentObject_Number); // Update slider mark if (Diaporama->List.count()>0) SetStartEndPos( Diaporama->GetObjectStartPosition(Diaporama->CurrentCol), // Current slide Diaporama->List[Diaporama->CurrentCol]->GetDuration(), (Diaporama->CurrentCol>0)?Diaporama->GetObjectStartPosition(Diaporama->CurrentCol-1):((Diaporama->CurrentCol==0)?0:-1), // Previous slide (Diaporama->CurrentCol>0)?Diaporama->List[Diaporama->CurrentCol-1]->GetDuration():((Diaporama->CurrentCol==0)?Diaporama->GetTransitionDuration(Diaporama->CurrentCol):0), Diaporama->CurrentCol<(Diaporama->List.count()-1)?Diaporama->GetObjectStartPosition(Diaporama->CurrentCol+1):-1, // Next slide Diaporama->CurrentCol<(Diaporama->List.count()-1)?Diaporama->List[Diaporama->CurrentCol+1]->GetDuration():0); } Diaporama->CurrentPosition=Value; // Free frame delete Frame; QApplication::restoreOverrideCursor(); } InPlayerUpdate=false; }
bool IrisFinderHough::Find(IplImage* image, CvRect eyeROI) { if (!ParametersValid()) return false; if (m_sizeData.SizeChanged(eyeROI)) PrepareImage(eyeROI); // some helper imgs IplImage* imgSobelH = cvCreateImage(cvSize(eyeROI.width, eyeROI.height), IPL_DEPTH_16S, 1); IplImage* imgSobelV = cvCreateImage(cvSize(eyeROI.width, eyeROI.height), IPL_DEPTH_16S, 1); // copy roi to internal image ImgLib::CopyRect(image, m_eyeImg, eyeROI, cvPoint(0, 0)); cvSobel(m_eyeImg, imgSobelH, 1, 0, 3); cvSobel(m_eyeImg, imgSobelV, 0, 1, 3); double angle; double dx, dy; double thetaRad; double xPrim, yPrim; double xsi; double max_e = 2.2; HoughAccumulator acc(m_accPrecision); acc.AddParam(0, m_eyeImg->width); // x0 acc.AddParam(0, m_eyeImg->height); // x1 acc.AddParam(m_thetaMin, m_thetaMax); // theta acc.AddParam(m_aMin, m_aMax); // a acc.AddParam(m_bMin, m_bMax); // b acc.Init(); DOUBLEVECT indices; indices.resize(5); cvSmooth(m_eyeImg, m_eyeImg); cvCanny(m_eyeImg, m_eyeImg, 250, 100); for(int y = 0; y < m_eyeImg->height; y++) { short* sh_row = (short*)(imgSobelH->imageData + y * imgSobelH->widthStep); short* sv_row = (short*)(imgSobelV->imageData + y * imgSobelV->widthStep); uchar* canny_row = (uchar *)(m_eyeImg->imageData + y * m_eyeImg->widthStep); double x0, y0; double a, b, theta=0; for (int x = 0; x < m_eyeImg->width; x++) { if (canny_row[x] == 0) continue; short dX = sh_row[x]; short dY = sv_row[x]; if ( (abs(dX) + abs(dY)) < m_minGradStrength) { cvLine(m_eyeImg, cvPoint(x,y),cvPoint(x,y),CV_RGB(0,0,0)); continue; } for (a = m_aMin; a < m_aMax; a+= (1 / m_accPrecision)) for (b = m_bMin; b < m_bMax; b+= (1 / m_accPrecision)) { double e = a / b; if (e < 1) e = b / a; if (e > max_e) continue; for (theta = m_thetaMin; theta < m_thetaMax; theta += (1 / m_accPrecision)) { angle = atan2((float)dY, (float)dX); thetaRad = 2 * CV_PI * theta / 360.0; angle -= (thetaRad + CV_PI / 2.0); xsi = tan(angle); //xsi = (float) dY / (float) dX; dx = -SignX(dX, dY) * a / sqrt(1 + (b * b) / (a * a * xsi * xsi)); dy = -SignY(dX, dY) * b / sqrt(1 + (a * a * xsi * xsi) / (b * b)); // rotate by theta xPrim = cos(thetaRad) * dx - sin(thetaRad) * dy; yPrim = sin(thetaRad) * dx + cos(thetaRad) * dy; dx = xPrim; dy = yPrim; x0 = x + dx; y0 = y + dy; indices[0] = x0; indices[1] = y0; indices[2] = theta; indices[3] = a; indices[4] = b; acc.Increment(indices); } } } } indices = acc.FindBest(); if (indices.size() > 0) { cvEllipse(image, cvPoint(indices[0] + eyeROI.x, indices[1] + eyeROI.y), cvSize(indices[3], indices[4]), -indices[2], // 90, 0, 360, CV_RGB(255, 0, 0)); m_irisCentre.x = indices[0] + eyeROI.x; m_irisCentre.y = indices[1] + eyeROI.y; return true; } return false; }
void cScreenGirlDetails::init() { if (selected_girl == 0) { g_WinManager.Pop(); g_InitWin = true; g_LogFile.write("ERROR - girl details screen, selected_girl is null"); /* * adding this because the game will crash if we * go past this point with a null girl * * Now as to why it was null in the first place ... * -- doc */ return; } g_CurrentScreen = SCREEN_GIRLDETAILS; if (!g_InitWin) return; Focused(); g_InitWin = false; //////////////////// if (selected_girl->health() <= 0) { // `J` instead of removing dead girls from the list which breaks the game, just skip past her in the list. NextGirl(); // `J` currently this prevents scrolling backwards past her - need to fix that. // selected_girl = remove_selected_girl(); if (selected_girl == 0) { g_WinManager.Pop(); g_InitWin = true; return; } } u_int job = (Day0Night1 ? selected_girl->m_NightJob : selected_girl->m_DayJob); SetJob = true; EditTextItem(selected_girl->m_Realname, girlname_id); string detail; if (DetailLevel == 0) detail = g_Girls.GetDetailsString(selected_girl); else if (DetailLevel == 1) detail = g_Girls.GetMoreDetailsString(selected_girl); else detail = g_Girls.GetThirdDetailsString(selected_girl); EditTextItem(detail, girldesc_id); if (selected_girl) { if (lastsexact != -1) { PrepareImage(girlimage_id, selected_girl, lastsexact, true, ImageNum); lastsexact = -1; } else { if (selected_girl->m_newRandomFixed >= 0) { PrepareImage(girlimage_id, selected_girl, IMGTYPE_PROFILE, false, selected_girl->m_newRandomFixed); } else { PrepareImage(girlimage_id, selected_girl, IMGTYPE_PROFILE, true, ImageNum); } } } SliderRange(houseperc_id, 0, 100, g_Girls.GetStat(selected_girl, STAT_HOUSE), 10); ss.str(""); ss << gettext("House Percentage: ") << SliderValue(houseperc_id) << gettext("%"); EditTextItem(ss.str(), housepercval_id); ClearListBox(jobtypelist_id); // `J` Replacing accom buttons with slider if (accomdown_id != -1) DisableButton(accomdown_id, selected_girl->m_AccLevel < 1); if (accomup_id != -1) DisableButton(accomup_id, selected_girl->m_AccLevel > 9); if (accom_id != -1) { SliderRange(accom_id, 0, 9, selected_girl->m_AccLevel, 1); SliderMarker(accom_id, g_Girls.PreferredAccom(selected_girl)); } if (accomval_id != -1) { stringstream acc; acc << "Accommodation: " << g_Girls.Accommodation(SliderValue(accom_id)); if (cfg.debug.log_extradetails()) { int val = SliderValue(accom_id) - g_Girls.PreferredAccom(selected_girl); if (val != 0) acc << " ( " << (val > 0 ? "+" : "") << val << " )"; } EditTextItem(acc.str(), accomval_id); } DisableButton(interact_id, (g_TalkCount <= 0)); DisableButton(takegold_id, (selected_girl->m_Money <= 0)); SetCheckBox(antipreg_id, (selected_girl->m_UseAntiPreg)); bool InMovieStudio = (selected_girl->m_InStudio); bool InArena = (selected_girl->m_InArena); bool InCentre = (selected_girl->m_InCentre); bool InClinic = (selected_girl->m_InClinic); bool InHouse = (selected_girl->m_InHouse); bool InFarm = (selected_girl->m_InFarm); bool InDungeon = (selected_girl->m_DayJob == JOB_INDUNGEON); DisableButton(reldungeon_id, !InDungeon); DisableButton(senddungeon_id, InDungeon); // Disable dungeon if selected girl is in a non-brothel building // if (InMovieStudio || InArena || InCentre || InClinic || InFarm || InHouse) // { // DisableButton(senddungeon_id, true); // } if (InArena) { ClearListBox(joblist_id); AddToListBox(jobtypelist_id, JOBFILTER_ARENASTAFF, g_Arena.m_JobManager.JobFilterName[JOBFILTER_ARENASTAFF]); AddToListBox(jobtypelist_id, JOBFILTER_ARENA, g_Arena.m_JobManager.JobFilterName[JOBFILTER_ARENA]); RefreshJobList(); if (job >= g_Arena.m_JobManager.JobFilterIndex[JOBFILTER_ARENA] && job < g_Arena.m_JobManager.JobFilterIndex[JOBFILTER_ARENA + 1]) SetSelectedItemInList(jobtypelist_id, JOBFILTER_ARENA); else // if (job >= g_Arena.m_JobManager.JobFilterIndex[JOBFILTER_ARENASTAFF] && job < g_Arena.m_JobManager.JobFilterIndex[JOBFILTER_ARENASTAFF + 1]) SetSelectedItemInList(jobtypelist_id, JOBFILTER_ARENASTAFF); HideButton(day_id, false); HideButton(night_id, false); DisableButton(day_id, (Day0Night1 == SHIFT_DAY)); DisableButton(night_id, (Day0Night1 == SHIFT_NIGHT)); } else if (InClinic) { ClearListBox(joblist_id); AddToListBox(jobtypelist_id, JOBFILTER_CLINIC, g_Clinic.m_JobManager.JobFilterName[JOBFILTER_CLINIC]); AddToListBox(jobtypelist_id, JOBFILTER_CLINICSTAFF, g_Clinic.m_JobManager.JobFilterName[JOBFILTER_CLINICSTAFF]); RefreshJobList(); if (job >= g_Clinic.m_JobManager.JobFilterIndex[JOBFILTER_CLINIC] && job < g_Clinic.m_JobManager.JobFilterIndex[JOBFILTER_CLINIC + 1]) SetSelectedItemInList(jobtypelist_id, JOBFILTER_CLINIC); else SetSelectedItemInList(jobtypelist_id, JOBFILTER_CLINICSTAFF); HideButton(day_id, false); HideButton(night_id, false); DisableButton(day_id, (Day0Night1 == SHIFT_DAY)); DisableButton(night_id, (Day0Night1 == SHIFT_NIGHT)); } else if (InCentre) { ClearListBox(joblist_id); AddToListBox(jobtypelist_id, JOBFILTER_COMMUNITYCENTRE, g_Centre.m_JobManager.JobFilterName[JOBFILTER_COMMUNITYCENTRE]); AddToListBox(jobtypelist_id, JOBFILTER_COUNSELINGCENTRE, g_Centre.m_JobManager.JobFilterName[JOBFILTER_COUNSELINGCENTRE]); RefreshJobList(); if (job >= g_Centre.m_JobManager.JobFilterIndex[JOBFILTER_COUNSELINGCENTRE] && job < g_Centre.m_JobManager.JobFilterIndex[JOBFILTER_COUNSELINGCENTRE + 1]) SetSelectedItemInList(jobtypelist_id, JOBFILTER_COUNSELINGCENTRE); else SetSelectedItemInList(jobtypelist_id, JOBFILTER_COMMUNITYCENTRE); HideButton(day_id, false); HideButton(night_id, false); DisableButton(day_id, (Day0Night1 == SHIFT_DAY)); DisableButton(night_id, (Day0Night1 == SHIFT_NIGHT)); } else if (InHouse) { ClearListBox(joblist_id); AddToListBox(jobtypelist_id, JOBFILTER_HOUSE, g_House.m_JobManager.JobFilterName[JOBFILTER_HOUSE]); SetSelectedItemInList(jobtypelist_id, JOBFILTER_HOUSE); RefreshJobList(); HideButton(day_id, false); HideButton(night_id, false); DisableButton(day_id, (Day0Night1 == SHIFT_DAY)); DisableButton(night_id, (Day0Night1 == SHIFT_NIGHT)); } else if (InMovieStudio) { Day0Night1 = SHIFT_NIGHT; ClearListBox(joblist_id); AddToListBox(jobtypelist_id, JOBFILTER_STUDIOCREW, g_Studios.m_JobManager.JobFilterName[JOBFILTER_STUDIOCREW]); AddToListBox(jobtypelist_id, JOBFILTER_MOVIESTUDIO, g_Studios.m_JobManager.JobFilterName[JOBFILTER_MOVIESTUDIO]); RefreshJobList(); if (job >= g_Studios.m_JobManager.JobFilterIndex[JOBFILTER_MOVIESTUDIO] && job < g_Studios.m_JobManager.JobFilterIndex[JOBFILTER_MOVIESTUDIO + 1]) SetSelectedItemInList(jobtypelist_id, JOBFILTER_MOVIESTUDIO); else SetSelectedItemInList(jobtypelist_id, JOBFILTER_STUDIOCREW); HideButton(day_id, true); HideButton(night_id, true); } else if (InFarm) { ClearListBox(joblist_id); AddToListBox(jobtypelist_id, JOBFILTER_FARMSTAFF, g_Farm.m_JobManager.JobFilterName[JOBFILTER_FARMSTAFF]); AddToListBox(jobtypelist_id, JOBFILTER_LABORERS, g_Farm.m_JobManager.JobFilterName[JOBFILTER_LABORERS]); AddToListBox(jobtypelist_id, JOBFILTER_PRODUCERS, g_Farm.m_JobManager.JobFilterName[JOBFILTER_PRODUCERS]); RefreshJobList(); if (job >= g_Farm.m_JobManager.JobFilterIndex[JOBFILTER_LABORERS] && job < g_Farm.m_JobManager.JobFilterIndex[JOBFILTER_LABORERS + 1]) SetSelectedItemInList(jobtypelist_id, JOBFILTER_LABORERS); else if (job >= g_Farm.m_JobManager.JobFilterIndex[JOBFILTER_PRODUCERS] && job < g_Farm.m_JobManager.JobFilterIndex[JOBFILTER_PRODUCERS + 1]) SetSelectedItemInList(jobtypelist_id, JOBFILTER_PRODUCERS); else SetSelectedItemInList(jobtypelist_id, JOBFILTER_FARMSTAFF); HideButton(day_id, false); HideButton(night_id, false); DisableButton(day_id, (Day0Night1 == SHIFT_DAY)); DisableButton(night_id, (Day0Night1 == SHIFT_NIGHT)); } else if (!InDungeon) { // if not in dungeon, set up job lists // add the job filters // for(int i=0; i<NUMJOBTYPES; i++) // loop through all job types for (unsigned int i = 0; i <= JOBFILTER_BROTHEL; i++) // temporary limit to job types shown { AddToListBox(jobtypelist_id, i, g_Brothels.m_JobManager.JobFilterName[i]); } // set the job filter int jobtype = 0; for (unsigned int i = 0; i < NUMJOBTYPES; i++) { if (job >= g_Brothels.m_JobManager.JobFilterIndex[i] && job < g_Brothels.m_JobManager.JobFilterIndex[i + 1]) { jobtype = i; break; } } SetSelectedItemInList(jobtypelist_id, jobtype); RefreshJobList(); HideButton(day_id, false); HideButton(night_id, false); DisableButton(day_id, (Day0Night1 == SHIFT_DAY)); DisableButton(night_id, (Day0Night1 == SHIFT_NIGHT)); } else { // if in dungeon, effectively disable job lists ClearListBox(joblist_id); AddToListBox(jobtypelist_id, -1, gettext("Languish in dungeon")); HideButton(day_id, true); HideButton(night_id, true); } ClearListBox(traitlist_id); for (int i = 0; i < MAXNUM_TRAITS; i++) { if (selected_girl->m_Traits[i]) { stringstream st; st << selected_girl->m_Traits[i]->m_Name; if (selected_girl->m_TempTrait[i] > 0) st << " (" << selected_girl->m_TempTrait[i] << ")"; AddToListBox(traitlist_id, i, g_Traits.GetTranslateName(st.str())); } } EditTextItem("", traitdesc_id); }
void Interpreter::InterpretUsingAverageImages(string FilePath) { /* * FilePath: The absolute path of the input file to be interpreted */ IplImage* InputImage = cvLoadImage( FilePath.c_str() ); InputImage = PrepareImage(InputImage); InputImage = Threshold(InputImage); AllSymbols = ExtractAllSymbolBlobs(InputImage); path SymbolFilePath("./symbols/"); map<string, IplImage* > AllReferenceSymbols; directory_iterator EndIt; // default constructor is an end iterator // Load all the reference symbols for (directory_iterator FileIterator(SymbolFilePath); FileIterator != EndIt; ++FileIterator) { string Key = FileIterator->path().stem().c_str(); AllReferenceSymbols[ Key ] = cvLoadImage( FileIterator->path().c_str() ); IplImage* Destination = cvCreateImage(cvSize(AllReferenceSymbols[ Key ]->width, AllReferenceSymbols[ Key ]->height), IPL_DEPTH_8U, 1); cvCvtColor(AllReferenceSymbols[ Key ], Destination, CV_RGB2GRAY); AllReferenceSymbols[ Key ] = Destination; cout << "Symbol \"" << FileIterator->path().stem().c_str() << "\" loaded." << endl; } // Compare for (vector<IplImage*>::iterator SymbolIter = AllSymbols.begin(); SymbolIter != AllSymbols.end(); ++SymbolIter) { uchar* PixelData = (uchar*)(*SymbolIter)->imageData; const int Width = (*SymbolIter)->width; const int Height = (*SymbolIter)->height; const int Step = (*SymbolIter)->widthStep; const int Depth = (*SymbolIter)->depth; const int Channels = (*SymbolIter)->nChannels; if (Width <= 10 || Height <= 10) { // If it's this small, just discard it as useless - this is a hack, we'll come up with a better way later // We may have to base this on the region size relative to the image size - so we don't discard decimals, // multiplication signs, etc continue; } map<string, double> ConfidenceMap; for (map<string, IplImage*>::iterator RefSymbolIter = AllReferenceSymbols.begin(); RefSymbolIter != AllReferenceSymbols.end(); ++RefSymbolIter) { IplImage* ResizedReference = cvCreateImage(cvSize(Width, Height), Depth, Channels); cvResize(RefSymbolIter->second, ResizedReference, CV_INTER_AREA); double TotalPixelsAnalyzed = 0.0; double MatchingPixels = 0.0; const uchar* ReferencePixelData = (uchar*)ResizedReference->imageData; for (int i = 0; i < Height; i++) { for (int j = 0; j < Width; j++) { if (PixelData[i * Step + j] == 255) { // Found a white pixel in the original image TotalPixelsAnalyzed += 1.0; // If the same pixel on the resized reference image is white if (ReferencePixelData[i * Step + j] == 255) { MatchingPixels += 1.0; } } } } ConfidenceMap[ RefSymbolIter->first ] = MatchingPixels / TotalPixelsAnalyzed * 100; cout << ConfidenceMap[ RefSymbolIter->first ] << "% chance." << endl; //cvRelease(&ResizedReference); } } SaveAllSymbols(); }
void Interpreter::Interpret(string FilePath) { /* * FilePath: the absolute path of the input file to be interpreted */ IplImage* InputImage = cvLoadImage(FilePath.c_str()); InputImage = PrepareImage(InputImage); InputImage = Threshold(InputImage); AllSymbols = ExtractAllSymbolBlobs(InputImage); path SymbolFilePath("./symbols"); map<string, vector<Point> > AllPointLists; directory_iterator endIt; // default constructor is an end iterator // Iterate through all the symbol point cloud files for (directory_iterator FileIterator(SymbolFilePath); FileIterator != endIt; ++FileIterator) { // Load the point file ifstream PointFileStream(FileIterator->path().c_str()); string SymbolName = FileIterator->path().stem().c_str(); // Load in and break up the point file into a usable format stringstream Buffer; Buffer << PointFileStream.rdbuf(); vector<string> PointPairs; vector<Point> Points; MethodsThatShouldBeStandard::StringExplode(Buffer.str(), "\n", &PointPairs); for (vector<string>::iterator PointIterator = PointPairs.begin(); PointIterator != PointPairs.end(); ++PointIterator) { string XValue = PointIterator->substr(0, PointIterator->find_first_of(",")); string YValue = PointIterator->substr(PointIterator->find_first_of(",") + 1, PointIterator->length()); //cout << "(" << XValue << "," << YValue << ")" << endl; Point point; point.x = atoi(XValue.c_str()); point.y = atoi(YValue.c_str()); Points.push_back(point); } AllPointLists[SymbolName] = Points; cout << "Symbol '" << SymbolName << "' loaded." << endl; } // Let's compare the stored symbol to the input region for (vector<IplImage*>::iterator SymbolIterator = AllSymbols.begin(); SymbolIterator != AllSymbols.end(); ++SymbolIterator) { // Let's interpret all these images uchar* PixelData = (uchar*)(*SymbolIterator)->imageData; const int Width = (*SymbolIterator)->width; const int Height = (*SymbolIterator)->height; const int Step = (*SymbolIterator)->widthStep; map<string, int> ConfidenceMap; for (map<string, vector<Point> >::iterator PointListIterator = AllPointLists.begin(); PointListIterator != AllPointLists.end(); ++PointListIterator) { double TotalPoints = PointListIterator->second.size(); double PointsMatched = 0; for (vector<Point>::iterator PointIterator = PointListIterator->second.begin(); PointIterator != PointListIterator->second.end(); ++PointIterator) { // I got so wrapped up in writing the outer iterators that I can't remember what the hell goes here // wait I figured it out // PointsMatched += (PixelData[PointIterator->x * Step + PointIterator->y] == 255 ? 1 : 0); // PixelData[PointIterator->x * Step + PointIterator->y] = (PixelData[PointIterator->x * Step + PointIterator->y] == 255 ? 100 : 0); } ConfidenceMap[PointListIterator->first] = static_cast<int>(PointsMatched / TotalPoints * 100); cout << ConfidenceMap[PointListIterator->first] << "% chance of " << PointListIterator->first << endl; } } SaveAllSymbols(); }
std::shared_ptr<Image> Visualizer::CaptureDepthFloatBuffer( bool do_render/* = true*/) { Image depth_image; depth_image.PrepareImage(view_control_ptr_->GetWindowWidth(), view_control_ptr_->GetWindowHeight(), 1, 4); if (do_render) { Render(); is_redraw_required_ = false; } glFinish(); #if __APPLE__ // On OSX with Retina display and glfw3, there is a bug with glReadPixels(). // When using glReadPixels() to read a block of depth data. The data is // horizontally stretched (vertically it is fine). This issue is related // to GLFW_SAMPLES hint. When it is set to 0 (anti-aliasing disabled), // glReadPixels() works fine. See this post for details: // http://stackoverflow.com/questions/30608121/glreadpixel-one-pass-vs-looping-through-points // The reason of this bug is unknown. The current workaround is to read // depth buffer column by column. This is 15~30 times slower than one block // reading glReadPixels(). std::vector<float> float_buffer(depth_image.height_); float *p = (float *)depth_image.data_.data(); for (int j = 0; j < depth_image.width_; j++) { glReadPixels(j, 0, 1, depth_image.width_, GL_DEPTH_COMPONENT, GL_FLOAT, float_buffer.data()); for (int i = 0; i < depth_image.height_; i++) { p[i * depth_image.width_ + j] = float_buffer[i]; } } #else //__APPLE__ // By default, glReadPixels read a block of depth buffer. glReadPixels(0, 0, depth_image.width_, depth_image.height_, GL_DEPTH_COMPONENT, GL_FLOAT, depth_image.data_.data()); #endif //__APPLE__ // glReadPixels get the screen in a vertically flipped manner // We should flip it back, and convert it to the correct depth value auto image_ptr = std::make_shared<Image>(); double z_near = view_control_ptr_->GetZNear(); double z_far = view_control_ptr_->GetZFar(); image_ptr->PrepareImage(view_control_ptr_->GetWindowWidth(), view_control_ptr_->GetWindowHeight(), 1, 4); for (int i = 0; i < depth_image.height_; i++) { float *p_depth = (float *)(depth_image.data_.data() + depth_image.BytesPerLine() * (depth_image.height_ - i - 1)); float *p_image = (float *)(image_ptr->data_.data() + image_ptr->BytesPerLine() * i); for (int j = 0; j < depth_image.width_; j++) { if (p_depth[j] == 1.0) { continue; } double z_depth = 2.0 * z_near * z_far / (z_far + z_near - (2.0 * (double)p_depth[j] - 1.0) * (z_far - z_near)); p_image[j] = (float)z_depth; } } return image_ptr; }
void cScreenTown::do_walk() { if (g_WalkAround) { g_MessageQue.AddToQue("You can only do this once per week.", COLOR_RED); return; } sGirl *girl = g_Girls.GetRandomGirl(); // let's get a girl for the player to meet if (girl == 0) // if there's no girl, no meeting { g_MessageQue.AddToQue(walk_no_luck(), COLOR_RED); return; } // most of the time, you're not going to find anyone unless you're cheating, of course. if (!g_Dice.percent(cfg.initial.girl_meet()) && !g_Cheats) { g_MessageQue.AddToQue(walk_no_luck(), COLOR_BLUE); return; } if (girlimage_id != -1) { if (girl) { PrepareImage(girlimage_id, girl, IMGTYPE_PROFILE, true, ImageNum); HideImage(girlimage_id, false); } else HideImage(girlimage_id, true); } int v[2] = { 0, -1 }; cTrigger* trig = 0; DirPath dp; DirPath intro; string introfile = ""; string message = ""; cScriptManager sm; // is there a girl specific talk script? if (!(trig = girl->m_Triggers.CheckForScript(TRIGGER_MEET, false, v))) { // no, so trigger the default one introfile = "MeetTownDefault.script.intro"; intro = DirPath() << "Resources" << "Scripts"; dp = DirPath() << "Resources" << "Scripts" << "MeetTownDefault.script"; // no, so trigger the default one } else { // trigger the girl-specific one introfile = trig->m_Script + ".intro"; intro = DirPath(cfg.folders.characters().c_str()) << girl->m_Name; dp = DirPath(cfg.folders.characters().c_str()) << girl->m_Name << trig->m_Script; } FileList abstest(intro, introfile.c_str()); if (abstest.size() == 0) { message = "You go out searching around town for any new girls. You notice a potential new girl and walk up to her."; } else { message = ""; ifstream in; in.open(abstest[0].full()); in >> message; in.close(); } if (message.size() > 0) g_MessageQue.AddToQue(message, COLOR_BLUE); eventrunning = true; sm.Load(dp, girl); return; }