Debian Codegraph @

xbmc/pictures/SlideShowPicture.cpp

raw
1 /*
2 * Copyright (C) 2005-2018 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
4 *
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
7 */
8
9 #include "SlideShowPicture.h"
10
11 #include "ServiceBroker.h"
12 #include "guilib/Texture.h"
13 #include "settings/AdvancedSettings.h"
14 #include "settings/Settings.h"
15 #include "settings/SettingsComponent.h"
16 #include "windowing/GraphicContext.h"
17 #include "windowing/WinSystem.h"
18
19 #include <mutex>
20
21 #ifndef _USE_MATH_DEFINES
22 #define _USE_MATH_DEFINES
23 #endif
24 #include <cstddef>
25 #include <math.h>
26
27 #define IMMEDIATE_TRANSITION_TIME 20
28
29 #define PICTURE_MOVE_AMOUNT 0.02f
30 #define PICTURE_MOVE_AMOUNT_ANALOG 0.01f
31 #define PICTURE_VIEW_BOX_COLOR 0xffffff00 // YELLOW
32 #define PICTURE_VIEW_BOX_BACKGROUND 0xff000000 // BLACK
33
34 #define FPS 25
35
36 static float zoomamount[10] = { 1.0f, 1.2f, 1.5f, 2.0f, 2.8f, 4.0f, 6.0f, 9.0f, 13.5f, 20.0f };
37
38 CSlideShowPic::CSlideShowPic() : m_pImage(nullptr)
39 {
40 m_bIsLoaded = false;
41 m_bIsFinished = false;
42 m_bDrawNextImage = false;
43 m_bTransitionImmediately = false;
44
45 m_bCanMoveHorizontally = false;
46 m_bCanMoveVertically = false;
47 }
48
49 CSlideShowPic::~CSlideShowPic()
50 {
51 Close();
52 }
53
54 void CSlideShowPic::Close()
55 {
56 std::unique_lock<CCriticalSection> lock(m_textureAccess);
57 m_pImage.reset();
58 m_bIsLoaded = false;
59 m_bIsFinished = false;
60 m_bDrawNextImage = false;
61 m_bTransitionImmediately = false;
62 m_bIsDirty = true;
63 m_alpha = 0;
64 }
65
66 void CSlideShowPic::Reset(DISPLAY_EFFECT dispEffect, TRANSITION_EFFECT transEffect)
67 {
68 std::unique_lock<CCriticalSection> lock(m_textureAccess);
69 if (m_pImage)
70 SetTexture_Internal(m_iSlideNumber, std::move(m_pImage), dispEffect, transEffect);
71 else
72 Close();
73 }
74
75 bool CSlideShowPic::DisplayEffectNeedChange(DISPLAY_EFFECT newDispEffect) const
76 {
77 if (m_displayEffect == newDispEffect)
78 return false;
79 if (newDispEffect == EFFECT_RANDOM && m_displayEffect != EFFECT_NONE && m_displayEffect != EFFECT_NO_TIMEOUT)
80 return false;
81 return true;
82 }
83
84 void CSlideShowPic::SetTexture(int iSlideNumber,
85 std::unique_ptr<CTexture> pTexture,
86 DISPLAY_EFFECT dispEffect,
87 TRANSITION_EFFECT transEffect)
88 {
89 std::unique_lock<CCriticalSection> lock(m_textureAccess);
90 Close();
91 SetTexture_Internal(iSlideNumber, std::move(pTexture), dispEffect, transEffect);
92 }
93
94 void CSlideShowPic::SetTexture_Internal(int iSlideNumber,
95 std::unique_ptr<CTexture> pTexture,
96 DISPLAY_EFFECT dispEffect,
97 TRANSITION_EFFECT transEffect)
98 {
99 std::unique_lock<CCriticalSection> lock(m_textureAccess);
100 m_bPause = false;
101 m_bNoEffect = false;
102 m_bTransitionImmediately = false;
103 m_iSlideNumber = iSlideNumber;
104
105 m_bIsDirty = true;
106 m_pImage = std::move(pTexture);
107 m_fWidth = static_cast<float>(m_pImage->GetWidth());
108 m_fHeight = static_cast<float>(m_pImage->GetHeight());
109 if (CServiceBroker::GetSettingsComponent()->GetSettings()->GetBool(CSettings::SETTING_SLIDESHOW_HIGHQUALITYDOWNSCALING))
110 { // activate mipmapping when high quality downscaling is 'on'
111 m_pImage->SetMipmapping();
112 }
113 // reset our counter
114 m_iCounter = 0;
115 // initialize our transition effect
116 m_transitionStart.type = transEffect;
117 m_transitionStart.start = 0;
118
119 // initialize our display effect
120 if (dispEffect == EFFECT_RANDOM)
121 {
122 if (((m_fWidth / m_fHeight) > 1.9f) || ((m_fHeight / m_fWidth) > 1.9f))
123 m_displayEffect = EFFECT_PANORAMA;
124 else
125 m_displayEffect = (DISPLAY_EFFECT)((rand() % (EFFECT_RANDOM - 1)) + 1);
126 }
127 else
128 m_displayEffect = dispEffect;
129
130 // the +1's make sure it actually occurs
131 float fadeTime = 0.2f;
132 if (m_displayEffect != EFFECT_NO_TIMEOUT)
133 fadeTime = std::min(0.2f*CServiceBroker::GetSettingsComponent()->GetSettings()->GetInt(CSettings::SETTING_SLIDESHOW_STAYTIME), 3.0f);
134 m_transitionStart.length = (int)(CServiceBroker::GetWinSystem()->GetGfxContext().GetFPS() * fadeTime); // transition time in frames
135 m_transitionEnd.type = transEffect;
136 m_transitionEnd.length = m_transitionStart.length;
137 m_transitionTemp.type = TRANSITION_NONE;
138 m_fTransitionAngle = 0;
139 m_fTransitionZoom = 0;
140 m_fAngle = 0.0f;
141 if (m_pImage->GetOrientation() == 7)
142 { // rotate to 270 degrees
143 m_fAngle = 270.0f;
144 }
145 if (m_pImage->GetOrientation() == 2)
146 { // rotate to 180 degrees
147 m_fAngle = 180.0f;
148 }
149 if (m_pImage->GetOrientation() == 5)
150 { // rotate to 90 degrees
151 m_fAngle = 90.0f;
152 }
153 m_fZoomAmount = 1;
154 m_fZoomLeft = 0;
155 m_fZoomTop = 0;
156 m_fPosX = m_fPosY = 0.0f;
157 m_fPosZ = 1.0f;
158 m_fVelocityX = m_fVelocityY = m_fVelocityZ = 0.0f;
159 int iFrames = std::max((int)(CServiceBroker::GetWinSystem()->GetGfxContext().GetFPS() * CServiceBroker::GetSettingsComponent()->GetSettings()->GetInt(CSettings::SETTING_SLIDESHOW_STAYTIME)), 1);
160 if (m_displayEffect == EFFECT_PANORAMA)
161 {
162 RESOLUTION_INFO res = CServiceBroker::GetWinSystem()->GetGfxContext().GetResInfo();
163 float fScreenWidth = (float)res.Overscan.right - res.Overscan.left;
164 float fScreenHeight = (float)res.Overscan.bottom - res.Overscan.top;
165
166 if (m_fWidth > m_fHeight)
167 {
168 iFrames = (int)(iFrames * (m_fWidth - m_fHeight) / m_fHeight);
169 m_iTotalFrames = m_transitionStart.length + m_transitionEnd.length + iFrames;
170
171 m_fPosX = 0.5f - (fScreenWidth / fScreenHeight) * (m_fHeight / m_fWidth) * 0.5f;
172 if (rand() % 2)
173 m_fPosX = -m_fPosX;
174 m_fVelocityX = -m_fPosX * 2.0f / m_iTotalFrames;
175 }
176 else
177 {
178 iFrames = (int)(iFrames * (m_fHeight - (0.5f * m_fWidth)) / m_fWidth);
179 m_iTotalFrames = m_transitionStart.length + m_transitionEnd.length + iFrames;
180
181 m_fPosY = 0.5f - (fScreenHeight / fScreenWidth) * (m_fWidth / m_fHeight) * 0.5f;
182 if (rand() % 2)
183 m_fPosY = -m_fPosY;
184 m_fVelocityY = -m_fPosY * 2.0f / m_iTotalFrames;
185 }
186 }
187 else
188 {
189 m_iTotalFrames = m_transitionStart.length + m_transitionEnd.length + iFrames;
190
191 if (m_displayEffect == EFFECT_FLOAT)
192 {
193 // Calculate start and end positions
194 // choose a random direction
195 float angle = (rand() % 1000) / 1000.0f * 2 * (float)M_PI;
196 m_fPosX = cos(angle) * CServiceBroker::GetSettingsComponent()->GetAdvancedSettings()->m_slideshowPanAmount * m_iTotalFrames * 0.00005f;
197 m_fPosY = sin(angle) * CServiceBroker::GetSettingsComponent()->GetAdvancedSettings()->m_slideshowPanAmount * m_iTotalFrames * 0.00005f;
198 m_fVelocityX = -m_fPosX * 2.0f / m_iTotalFrames;
199 m_fVelocityY = -m_fPosY * 2.0f / m_iTotalFrames;
200 }
201 else if (m_displayEffect == EFFECT_ZOOM)
202 {
203 m_fPosZ = 1.0f;
204 m_fVelocityZ = 0.0001f * CServiceBroker::GetSettingsComponent()->GetAdvancedSettings()->m_slideshowZoomAmount;
205 }
206 }
207
208 m_transitionEnd.start = m_transitionStart.length + iFrames;
209
210 m_bIsFinished = false;
211 m_bDrawNextImage = false;
212 m_bIsLoaded = true;
213 }
214
215 void CSlideShowPic::SetOriginalSize(int iOriginalWidth, int iOriginalHeight, bool bFullSize)
216 {
217 m_iOriginalWidth = iOriginalWidth;
218 m_iOriginalHeight = iOriginalHeight;
219 m_bFullSize = bFullSize;
220 }
221
222 int CSlideShowPic::GetOriginalWidth()
223 {
224 int iAngle = (int)(m_fAngle / 90.0f + 0.4f);
225 if (iAngle % 2)
226 return m_iOriginalHeight;
227 else
228 return m_iOriginalWidth;
229 }
230
231 int CSlideShowPic::GetOriginalHeight()
232 {
233 int iAngle = (int)(m_fAngle / 90.0f + 0.4f);
234 if (iAngle % 2)
235 return m_iOriginalWidth;
236 else
237 return m_iOriginalHeight;
238 }
239
240 void CSlideShowPic::UpdateTexture(std::unique_ptr<CTexture> pTexture)
241 {
242 std::unique_lock<CCriticalSection> lock(m_textureAccess);
243 m_pImage = std::move(pTexture);
244 m_fWidth = static_cast<float>(m_pImage->GetWidth());
245 m_fHeight = static_cast<float>(m_pImage->GetHeight());
246 m_bIsDirty = true;
247 }
248
249 static CRect GetRectangle(const float x[4], const float y[4])
250 {
251 CRect rect;
252 rect.x1 = *std::min_element(x, x+4);
253 rect.y1 = *std::min_element(y, y+4);
254 rect.x2 = *std::max_element(x, x+4);
255 rect.y2 = *std::max_element(y, y+4);
256 return rect;
257 }
258
259 void CSlideShowPic::UpdateVertices(float cur_x[4], float cur_y[4], const float new_x[4], const float new_y[4], CDirtyRegionList &dirtyregions)
260 {
261 const size_t count = sizeof(float)*4;
262 if(memcmp(cur_x, new_x, count)
263 || memcmp(cur_y, new_y, count)
264 || m_bIsDirty)
265 {
266 dirtyregions.emplace_back(GetRectangle(cur_x, cur_y));
267 dirtyregions.emplace_back(GetRectangle(new_x, new_y));
268 memcpy(cur_x, new_x, count);
269 memcpy(cur_y, new_y, count);
270 }
271 }
272
273 void CSlideShowPic::Process(unsigned int currentTime, CDirtyRegionList &dirtyregions)
274 {
275 if (!m_pImage || !m_bIsLoaded || m_bIsFinished) return ;
276 UTILS::COLOR::Color alpha = m_alpha;
277 if (m_iCounter <= m_transitionStart.length)
278 { // do start transition
279 if (m_transitionStart.type == CROSSFADE)
280 { // fade in at 1x speed
281 alpha = (UTILS::COLOR::Color)((float)m_iCounter / (float)m_transitionStart.length * 255.0f);
282 }
283 else if (m_transitionStart.type == FADEIN_FADEOUT)
284 { // fade in at 2x speed, then keep solid
285 alpha =
286 (UTILS::COLOR::Color)((float)m_iCounter / (float)m_transitionStart.length * 255.0f * 2);
287 if (alpha > 255) alpha = 255;
288 }
289 else // m_transitionEffect == TRANSITION_NONE
290 {
291 alpha = 0xFF; // opaque
292 }
293 }
294 bool bPaused = m_bPause | (m_fZoomAmount != 1.0f);
295 // check if we're doing a temporary effect (such as rotate + zoom)
296 if (m_transitionTemp.type != TRANSITION_NONE)
297 {
298 bPaused = true;
299 if (m_iCounter >= m_transitionTemp.start)
300 {
301 if (m_iCounter >= m_transitionTemp.start + m_transitionTemp.length)
302 { // we're finished this transition
303 if (m_transitionTemp.type == TRANSITION_ZOOM)
304 { // correct for any introduced inaccuracies.
305 int i;
306 for (i = 0; i < 10; i++)
307 {
308 if (fabs(m_fZoomAmount - zoomamount[i]) < 0.01f * zoomamount[i])
309 {
310 m_fZoomAmount = zoomamount[i];
311 break;
312 }
313 }
314 m_bNoEffect = (m_fZoomAmount != 1.0f); // turn effect rendering back on.
315 }
316 m_transitionTemp.type = TRANSITION_NONE;
317 }
318 else
319 {
320 if (m_transitionTemp.type == TRANSITION_ROTATE)
321 m_fAngle += m_fTransitionAngle;
322 if (m_transitionTemp.type == TRANSITION_ZOOM)
323 m_fZoomAmount += m_fTransitionZoom;
324 }
325 }
326 }
327 // now just display
328 if (!m_bNoEffect && !bPaused)
329 {
330 if (m_displayEffect == EFFECT_PANORAMA)
331 {
332 m_fPosX += m_fVelocityX;
333 m_fPosY += m_fVelocityY;
334 }
335 else if (m_displayEffect == EFFECT_FLOAT)
336 {
337 m_fPosX += m_fVelocityX;
338 m_fPosY += m_fVelocityY;
339 float fMoveAmount = CServiceBroker::GetSettingsComponent()->GetAdvancedSettings()->m_slideshowPanAmount * m_iTotalFrames * 0.0001f;
340 if (m_fPosX > fMoveAmount)
341 {
342 m_fPosX = fMoveAmount;
343 m_fVelocityX = -m_fVelocityX;
344 }
345 if (m_fPosX < -fMoveAmount)
346 {
347 m_fPosX = -fMoveAmount;
348 m_fVelocityX = -m_fVelocityX;
349 }
350 if (m_fPosY > fMoveAmount)
351 {
352 m_fPosY = fMoveAmount;
353 m_fVelocityY = -m_fVelocityY;
354 }
355 if (m_fPosY < -fMoveAmount)
356 {
357 m_fPosY = -fMoveAmount;
358 m_fVelocityY = -m_fVelocityY;
359 }
360 }
361 else if (m_displayEffect == EFFECT_ZOOM)
362 {
363 m_fPosZ += m_fVelocityZ;
364 /* if (m_fPosZ > 1.0f + 0.01f*CServiceBroker::GetSettingsComponent()->GetSettings()->GetInt("Slideshow.ZoomAmount"))
365 {
366 m_fPosZ = 1.0f + 0.01f * CServiceBroker::GetSettingsComponent()->GetSettings()->GetInt("Slideshow.ZoomAmount");
367 m_fVelocityZ = -m_fVelocityZ;
368 }
369 if (m_fPosZ < 1.0f)
370 {
371 m_fPosZ = 1.0f;
372 m_fVelocityZ = -m_fVelocityZ;
373 }*/
374 }
375 }
376 if (m_displayEffect != EFFECT_NO_TIMEOUT && bPaused && !m_bTransitionImmediately)
377 { // paused - increment the last transition start time
378 m_transitionEnd.start++;
379 }
380 if (m_iCounter >= m_transitionEnd.start)
381 { // do end transition
382 // CLog::Log(LOGDEBUG,"Transitioning");
383 m_bDrawNextImage = true;
384 if (m_transitionEnd.type == CROSSFADE)
385 { // fade out at 1x speed
386 alpha = 255 - (UTILS::COLOR::Color)((float)(m_iCounter - m_transitionEnd.start) /
387 (float)m_transitionEnd.length * 255.0f);
388 }
389 else if (m_transitionEnd.type == FADEIN_FADEOUT)
390 { // keep solid, then fade out at 2x speed
391 alpha = (UTILS::COLOR::Color)(
392 (float)(m_transitionEnd.length - m_iCounter + m_transitionEnd.start) /
393 (float)m_transitionEnd.length * 255.0f * 2);
394 if (alpha > 255) alpha = 255;
395 }
396 else // m_transitionEffect == TRANSITION_NONE
397 {
398 alpha = 0xFF; // opaque
399 }
400 }
401 if (alpha != m_alpha)
402 {
403 m_alpha = alpha;
404 m_bIsDirty = true;
405 }
406 if (m_displayEffect != EFFECT_NO_TIMEOUT || m_iCounter < m_transitionStart.length || m_iCounter >= m_transitionEnd.start || (m_iCounter >= m_transitionTemp.start && m_iCounter < m_transitionTemp.start + m_transitionTemp.length))
407 {
408 /* this really annoying. there's non-stop logging when viewing a pic outside of the slideshow
409 if (m_displayEffect == EFFECT_NO_TIMEOUT)
410 CLog::Log(LOGDEBUG, "Incrementing counter ({}) while not in slideshow (startlength={},endstart={},endlength={})", m_iCounter, m_transitionStart.length, m_transitionEnd.start, m_transitionEnd.length);
411 */
412 m_iCounter++;
413 }
414 if (m_iCounter > m_transitionEnd.start + m_transitionEnd.length)
415 m_bIsFinished = true;
416
417 RESOLUTION_INFO info = CServiceBroker::GetWinSystem()->GetGfxContext().GetResInfo();
418
419 // calculate where we should render (and how large it should be)
420 // calculate aspect ratio correction factor
421 float fOffsetX = (float)info.Overscan.left;
422 float fOffsetY = (float)info.Overscan.top;
423 float fScreenWidth = (float)info.Overscan.right - info.Overscan.left;
424 float fScreenHeight = (float)info.Overscan.bottom - info.Overscan.top;
425 float fPixelRatio = info.fPixelRatio;
426
427 // Rotate the image as needed
428 float x[4];
429 float y[4];
430 float si = sin(m_fAngle / 180.0f * static_cast<float>(M_PI));
431 float co = cos(m_fAngle / 180.0f * static_cast<float>(M_PI));
432 x[0] = -m_fWidth * co + m_fHeight * si;
433 y[0] = -m_fWidth * si - m_fHeight * co;
434 x[1] = m_fWidth * co + m_fHeight * si;
435 y[1] = m_fWidth * si - m_fHeight * co;
436 x[2] = m_fWidth * co - m_fHeight * si;
437 y[2] = m_fWidth * si + m_fHeight * co;
438 x[3] = -m_fWidth * co - m_fHeight * si;
439 y[3] = -m_fWidth * si + m_fHeight * co;
440
441 // calculate our scale amounts
442 float fSourceAR = m_fWidth / m_fHeight;
443 float fSourceInvAR = 1 / fSourceAR;
444 float fAR = si * si * (fSourceInvAR - fSourceAR) + fSourceAR;
445
446 //float fOutputFrameAR = fAR / fPixelRatio;
447
448 float fScaleNorm = fScreenWidth / m_fWidth;
449 float fScaleInv = fScreenWidth / m_fHeight;
450
451 bool bFillScreen = false;
452 float fComp = 1.0f + 0.01f * CServiceBroker::GetSettingsComponent()->GetAdvancedSettings()->m_slideshowBlackBarCompensation;
453 float fScreenRatio = fScreenWidth / fScreenHeight * fPixelRatio;
454 // work out if we should be compensating the zoom to minimize blackbars
455 // we should compute this based on the % of black bars on screen perhaps??
456 //! @todo change m_displayEffect != EFFECT_NO_TIMEOUT to whether we're running the slideshow
457 if (m_displayEffect != EFFECT_NO_TIMEOUT && m_displayEffect != EFFECT_NONE && fScreenRatio < fSourceAR * fComp && fSourceAR < fScreenRatio * fComp)
458 bFillScreen = true;
459 if ((!bFillScreen && fScreenWidth*fPixelRatio > fScreenHeight*fSourceAR) || (bFillScreen && fScreenWidth*fPixelRatio < fScreenHeight*fSourceAR))
460 fScaleNorm = fScreenHeight / (m_fHeight * fPixelRatio);
461 bFillScreen = false;
462 if (m_displayEffect != EFFECT_NO_TIMEOUT && m_displayEffect != EFFECT_NONE && fScreenRatio < fSourceInvAR * fComp && fSourceInvAR < fScreenRatio * fComp)
463 bFillScreen = true;
464 if ((!bFillScreen && fScreenWidth*fPixelRatio > fScreenHeight*fSourceInvAR) || (bFillScreen && fScreenWidth*fPixelRatio < fScreenHeight*fSourceInvAR))
465 fScaleInv = fScreenHeight / (m_fWidth * fPixelRatio);
466
467 float fScale = si * si * (fScaleInv - fScaleNorm) + fScaleNorm;
468 // scale if we need to due to the effect we're using
469 if (m_displayEffect == EFFECT_PANORAMA)
470 {
471 if (m_fWidth > m_fHeight)
472 fScale *= m_fWidth / fScreenWidth * fScreenHeight / m_fHeight;
473 else
474 fScale *= m_fHeight / fScreenHeight * fScreenWidth / m_fWidth;
475 }
476 if (m_displayEffect == EFFECT_FLOAT)
477 fScale *= (1.0f + CServiceBroker::GetSettingsComponent()->GetAdvancedSettings()->m_slideshowPanAmount * m_iTotalFrames * 0.0001f);
478 if (m_displayEffect == EFFECT_ZOOM)
479 fScale *= m_fPosZ;
480 // zoom image
481 fScale *= m_fZoomAmount;
482
483 // calculate the resultant coordinates
484 for (int i = 0; i < 4; i++)
485 {
486 x[i] *= fScale * 0.5f; // as the offsets x[] and y[] are from center
487 y[i] *= fScale * fPixelRatio * 0.5f;
488 // center it
489 x[i] += 0.5f * fScreenWidth + fOffsetX;
490 y[i] += 0.5f * fScreenHeight + fOffsetY;
491 }
492 // shift if we're zooming
493 if (m_fZoomAmount > 1)
494 {
495 float minx = x[0];
496 float maxx = x[0];
497 float miny = y[0];
498 float maxy = y[0];
499 for (int i = 1; i < 4; i++)
500 {
501 if (x[i] < minx) minx = x[i];
502 if (x[i] > maxx) maxx = x[i];
503 if (y[i] < miny) miny = y[i];
504 if (y[i] > maxy) maxy = y[i];
505 }
506 float w = maxx - minx;
507 float h = maxy - miny;
508 m_bCanMoveHorizontally = (w >= fScreenWidth);
509 m_bCanMoveVertically = (h >= fScreenHeight);
510 if (w >= fScreenWidth)
511 { // must have no black bars
512 if (minx + m_fZoomLeft*w > fOffsetX)
513 m_fZoomLeft = (fOffsetX - minx) / w;
514 if (maxx + m_fZoomLeft*w < fOffsetX + fScreenWidth)
515 m_fZoomLeft = (fScreenWidth + fOffsetX - maxx) / w;
516 for (float& i : x)
517 i += w * m_fZoomLeft;
518 }
519 if (h >= fScreenHeight)
520 { // must have no black bars
521 if (miny + m_fZoomTop*h > fOffsetY)
522 m_fZoomTop = (fOffsetY - miny) / h;
523 if (maxy + m_fZoomTop*h < fOffsetY + fScreenHeight)
524 m_fZoomTop = (fScreenHeight + fOffsetY - maxy) / h;
525 for (float& i : y)
526 i += m_fZoomTop * h;
527 }
528 }
529 // add offset from display effects
530 for (int i = 0; i < 4; i++)
531 {
532 x[i] += m_fPosX * m_fWidth * fScale;
533 y[i] += m_fPosY * m_fHeight * fScale;
534 }
535
536 UpdateVertices(m_ax, m_ay, x, y, dirtyregions);
537
538 // now render the image in the top right corner if we're zooming
539 if (m_fZoomAmount == 1 || m_bIsComic)
540 {
541 const float empty[4] = {};
542 UpdateVertices(m_bx, m_by, empty, empty, dirtyregions);
543 UpdateVertices(m_sx, m_sy, empty, empty, dirtyregions);
544 UpdateVertices(m_ox, m_oy, empty, empty, dirtyregions);
545 m_bIsDirty = false;
546 return;
547 }
548
549 float sx[4], sy[4];
550 sx[0] = -m_fWidth * co + m_fHeight * si;
551 sy[0] = -m_fWidth * si - m_fHeight * co;
552 sx[1] = m_fWidth * co + m_fHeight * si;
553 sy[1] = m_fWidth * si - m_fHeight * co;
554 sx[2] = m_fWidth * co - m_fHeight * si;
555 sy[2] = m_fWidth * si + m_fHeight * co;
556 sx[3] = -m_fWidth * co - m_fHeight * si;
557 sy[3] = -m_fWidth * si + m_fHeight * co;
558 // convert to the appropriate scale
559 float fSmallArea = fScreenWidth * fScreenHeight / 50;
560 float fSmallWidth = sqrt(fSmallArea * fAR / fPixelRatio); // fAR*height = width, so total area*far = width*width
561 float fSmallHeight = fSmallArea / fSmallWidth;
562 float fSmallX = fOffsetX + fScreenWidth * 0.95f - fSmallWidth * 0.5f;
563 float fSmallY = fOffsetY + fScreenHeight * 0.05f + fSmallHeight * 0.5f;
564 fScaleNorm = fSmallWidth / m_fWidth;
565 fScaleInv = fSmallWidth / m_fHeight;
566 fScale = si * si * (fScaleInv - fScaleNorm) + fScaleNorm;
567 for (int i = 0; i < 4; i++)
568 {
569 sx[i] *= fScale * 0.5f;
570 sy[i] *= fScale * fPixelRatio * 0.5f;
571 }
572 // calculate a black border
573 float bx[4];
574 float by[4];
575 for (int i = 0; i < 4; i++)
576 {
577 if (sx[i] > 0)
578 bx[i] = sx[i] + 1;
579 else
580 bx[i] = sx[i] - 1;
581 if (sy[i] > 0)
582 by[i] = sy[i] + 1;
583 else
584 by[i] = sy[i] - 1;
585 sx[i] += fSmallX;
586 sy[i] += fSmallY;
587 bx[i] += fSmallX;
588 by[i] += fSmallY;
589 }
590
591 fSmallX -= fSmallWidth * 0.5f;
592 fSmallY -= fSmallHeight * 0.5f;
593
594 UpdateVertices(m_bx, m_by, bx, by, dirtyregions);
595 UpdateVertices(m_sx, m_sy, sx, sy, dirtyregions);
596
597 // now we must render the wireframe image of the view window
598 // work out the direction of the top of pic vector
599 float scale;
600 if (fabs(x[1] - x[0]) > fabs(x[3] - x[0]))
601 scale = (sx[1] - sx[0]) / (x[1] - x[0]);
602 else
603 scale = (sx[3] - sx[0]) / (x[3] - x[0]);
604 float ox[4];
605 float oy[4];
606 ox[0] = (fOffsetX - x[0]) * scale + sx[0];
607 oy[0] = (fOffsetY - y[0]) * scale + sy[0];
608 ox[1] = (fOffsetX + fScreenWidth - x[0]) * scale + sx[0];
609 oy[1] = (fOffsetY - y[0]) * scale + sy[0];
610 ox[2] = (fOffsetX + fScreenWidth - x[0]) * scale + sx[0];
611 oy[2] = (fOffsetY + fScreenHeight - y[0]) * scale + sy[0];
612 ox[3] = (fOffsetX - x[0]) * scale + sx[0];
613 oy[3] = (fOffsetY + fScreenHeight - y[0]) * scale + sy[0];
614 // crop to within the range of our piccy
615 for (int i = 0; i < 4; i++)
616 {
617 if (ox[i] < fSmallX) ox[i] = fSmallX;
618 if (ox[i] > fSmallX + fSmallWidth) ox[i] = fSmallX + fSmallWidth;
619 if (oy[i] < fSmallY) oy[i] = fSmallY;
620 if (oy[i] > fSmallY + fSmallHeight) oy[i] = fSmallY + fSmallHeight;
621 }
622
623 UpdateVertices(m_ox, m_oy, ox, oy, dirtyregions);
624 m_bIsDirty = false;
625 }
626
627 void CSlideShowPic::Keep()
628 {
629 // this is called if we need to keep the current pic on screen
630 // to wait for the next pic to load
631 if (!m_bDrawNextImage) return ; // don't need to keep pic
632 // hold off the start of the next frame
633 m_transitionEnd.start = m_iCounter;
634 }
635
636 bool CSlideShowPic::StartTransition()
637 {
638 // this is called if we need to start transitioning immediately to the new picture
639 if (m_bDrawNextImage) return false; // don't need to do anything as we are already transitioning
640 // decrease the number of display frame
641 m_transitionEnd.start = m_iCounter;
642 m_bTransitionImmediately = true;
643 return true;
644 }
645
646 void CSlideShowPic::Pause(bool bPause)
647 {
648 if (!m_bDrawNextImage)
649 m_bPause = bPause;
650 }
651
652 void CSlideShowPic::SetInSlideshow(bool slideshow)
653 {
654 if (slideshow && m_displayEffect == EFFECT_NO_TIMEOUT)
655 m_displayEffect = EFFECT_NONE;
656 }
657
658 int CSlideShowPic::GetTransitionTime(int iType) const
659 {
660 if (iType == 0) // start transition
661 return m_transitionStart.length;
662 else // iType == 1 // end transition
663 return m_transitionEnd.length;
664 }
665
666 void CSlideShowPic::SetTransitionTime(int iType, int iTime)
667 {
668 if (iType == 0) // start transition
669 m_transitionStart.length = iTime;
670 else // iType == 1 // end transition
671 m_transitionEnd.length = iTime;
672 }
673
674 void CSlideShowPic::Rotate(float fRotateAngle, bool immediate /* = false */)
675 {
676 if (m_bDrawNextImage) return;
677 if (m_transitionTemp.type == TRANSITION_ZOOM) return;
678 if (immediate)
679 {
680 m_fAngle += fRotateAngle;
681 return;
682 }
683
684 // if there is a rotation ongoing already
685 // add the new angle to the old destination angle
686 if (m_transitionTemp.type == TRANSITION_ROTATE &&
687 m_transitionTemp.start + m_transitionTemp.length > m_iCounter)
688 {
689 int remainder = m_transitionTemp.start + m_transitionTemp.length - m_iCounter;
690 fRotateAngle += m_fTransitionAngle * remainder;
691 }
692
693 m_transitionTemp.type = TRANSITION_ROTATE;
694 m_transitionTemp.start = m_iCounter;
695 m_transitionTemp.length = IMMEDIATE_TRANSITION_TIME;
696 m_fTransitionAngle = fRotateAngle / (float)m_transitionTemp.length;
697 // reset the timer
698 m_transitionEnd.start = m_iCounter + m_transitionStart.length + (int)(CServiceBroker::GetWinSystem()->GetGfxContext().GetFPS() * CServiceBroker::GetSettingsComponent()->GetSettings()->GetInt(CSettings::SETTING_SLIDESHOW_STAYTIME));
699 }
700
701 void CSlideShowPic::Zoom(float fZoom, bool immediate /* = false */)
702 {
703 if (m_bDrawNextImage) return;
704 if (m_transitionTemp.type == TRANSITION_ROTATE) return;
705 if (immediate)
706 {
707 m_fZoomAmount = fZoom;
708 return;
709 }
710 m_transitionTemp.type = TRANSITION_ZOOM;
711 m_transitionTemp.start = m_iCounter;
712 m_transitionTemp.length = IMMEDIATE_TRANSITION_TIME;
713 m_fTransitionZoom = (fZoom - m_fZoomAmount) / (float)m_transitionTemp.length;
714 // reset the timer
715 m_transitionEnd.start = m_iCounter + m_transitionStart.length + (int)(CServiceBroker::GetWinSystem()->GetGfxContext().GetFPS() * CServiceBroker::GetSettingsComponent()->GetSettings()->GetInt(CSettings::SETTING_SLIDESHOW_STAYTIME));
716 // turn off the render effects until we're back down to normal zoom
717 m_bNoEffect = true;
718 }
719
720 void CSlideShowPic::Move(float fDeltaX, float fDeltaY)
721 {
722 m_fZoomLeft += fDeltaX;
723 m_fZoomTop += fDeltaY;
724 // reset the timer
725 // m_transitionEnd.start = m_iCounter + m_transitionStart.length + (int)(CServiceBroker::GetWinSystem()->GetGfxContext().GetFPS() * CServiceBroker::GetSettingsComponent()->GetSettings()->GetInt(CSettings::SETTING_SLIDESHOW_STAYTIME));
726 }
727
728 void CSlideShowPic::Render()
729 {
730 std::unique_lock<CCriticalSection> lock(m_textureAccess);
731
732 Render(m_ax, m_ay, m_pImage.get(), (m_alpha << 24) | 0xFFFFFF);
733
734 // now render the image in the top right corner if we're zooming
735 if (m_fZoomAmount == 1.0f || m_bIsComic) return ;
736
737 Render(m_bx, m_by, NULL, PICTURE_VIEW_BOX_BACKGROUND);
738 Render(m_sx, m_sy, m_pImage.get(), 0xFFFFFFFF);
739 Render(m_ox, m_oy, NULL, PICTURE_VIEW_BOX_COLOR);
740 }