Skip to content
This repository
Browse code

Merge pull request #2549 from popcornmix/avoid_resize

[rbp] Ensure GPU does resize when caching thumbnails
  • Loading branch information...
commit 67dc2a99fa828fc77cdf5870b1adaaa185203a0b 2 parents 39876d1 + 5f5b6df
authored April 06, 2013
76  xbmc/cores/omxplayer/OMXImage.cpp
@@ -487,30 +487,47 @@ bool COMXImage::ClampLimits(unsigned int &width, unsigned int &height)
487 487
 {
488 488
   RESOLUTION_INFO& res_info =  CDisplaySettings::Get().GetResolutionInfo(g_graphicsContext.GetVideoResolution());
489 489
   const bool transposed = m_orientation & 4;
490  
-  const int gui_width  = transposed ? res_info.iHeight:res_info.iWidth;
491  
-  const int gui_height = transposed ? res_info.iWidth:res_info.iHeight;
492  
-  const unsigned int max_width  = min(gui_width, 2048);
493  
-  const unsigned int max_height = min(gui_height, 2048);
  490
+  unsigned int max_width = width;
  491
+  unsigned int max_height = height;
  492
+  const unsigned int gui_width  = transposed ? res_info.iHeight:res_info.iWidth;
  493
+  const unsigned int gui_height = transposed ? res_info.iWidth:res_info.iHeight;
  494
+  const float aspect = (float)m_width / m_height;
494 495
 
495  
-  if(!max_width || !max_height)
496  
-    return false;
  496
+  if (max_width == 0 || max_height == 0)
  497
+  {
  498
+    max_height = g_advancedSettings.m_imageRes;
497 499
 
498  
-  const float ar = (float)width/(float)height;
499  
-  // bigger than maximum, so need to clamp
500  
-  if (width > max_width || height > max_height) {
501  
-    // wider than max, so clamp width first
502  
-    if (ar > (float)max_width/(float)max_height)
503  
-    {
504  
-      width = max_width;
505  
-      height = (float)max_width / ar + 0.5f;
506  
-    // taller than max, so clamp height first
507  
-    } else {
508  
-      height = max_height;
509  
-      width = (float)max_height * ar + 0.5f;
  500
+    if (g_advancedSettings.m_fanartRes > g_advancedSettings.m_imageRes)
  501
+    { // 16x9 images larger than the fanart res use that rather than the image res
  502
+      if (fabsf(aspect / (16.0f/9.0f) - 1.0f) <= 0.01f && m_height >= g_advancedSettings.m_fanartRes)
  503
+      {
  504
+        max_height = g_advancedSettings.m_fanartRes;
  505
+      }
510 506
     }
511  
-    return true;
  507
+    max_width = max_height * 16/9;
512 508
   }
513 509
 
  510
+  if (gui_width)
  511
+    max_width = min(max_width, gui_width);
  512
+  if (gui_height)
  513
+    max_height = min(max_height, gui_height);
  514
+
  515
+  max_width  = min(max_width, 2048U);
  516
+  max_height = min(max_height, 2048U);
  517
+
  518
+
  519
+  width = m_width;
  520
+  height = m_height;
  521
+  if (width > max_width || height > max_height)
  522
+  {
  523
+    if ((unsigned int)(max_width / aspect + 0.5f) > max_height)
  524
+      max_width = (unsigned int)(max_height * aspect + 0.5f);
  525
+    else
  526
+      max_height = (unsigned int)(max_width / aspect + 0.5f);
  527
+    width = max_width;
  528
+    height = max_height;
  529
+    return true;
  530
+  }
514 531
   return false;
515 532
 }
516 533
 
@@ -549,7 +566,6 @@ bool COMXImage::ReadFile(const CStdString& inputFile)
549 566
     CLog::Log(LOGERROR, "%s::%s %s m_width=%d m_height=%d\n", CLASSNAME, __func__, inputFile.c_str(), m_width, m_height);
550 567
     return false;
551 568
   }
552  
-  ClampLimits(m_width, m_height);
553 569
 
554 570
   m_is_open = true;
555 571
 
@@ -718,26 +734,6 @@ bool COMXImage::Decode(unsigned width, unsigned height)
718 734
   }
719 735
 
720 736
   m_decoder_open = true;
721  
-
722  
-  if(width == 0 || height == 0)
723  
-  {
724  
-    height = g_advancedSettings.m_imageRes;
725  
-    if (g_advancedSettings.m_fanartRes > g_advancedSettings.m_imageRes)
726  
-    { // a separate fanart resolution is specified - check if the image is exactly equal to this res
727  
-      if (m_width == (unsigned int)g_advancedSettings.m_fanartRes * 16/9 &&
728  
-          m_height == (unsigned int)g_advancedSettings.m_fanartRes)
729  
-      { // special case for fanart res
730  
-        height = g_advancedSettings.m_fanartRes;
731  
-      }
732  
-    }
733  
-    width = height * 16/9;
734  
-    if(!width || !height)
735  
-    {
736  
-      width = CDisplaySettings::Get().GetCurrentResolutionInfo().iWidth;
737  
-      height = CDisplaySettings::Get().GetCurrentResolutionInfo().iHeight;
738  
-    }
739  
-  }
740  
-
741 737
   ClampLimits(width, height);
742 738
 
743 739
   // set input format
2  xbmc/guilib/Texture.cpp
@@ -223,7 +223,7 @@ bool CBaseTexture::LoadFromFileInternal(const CStdString& texturePath, unsigned
223 223
 
224 224
     if(omx_image.ReadFile(texturePath))
225 225
     {
226  
-      if(omx_image.Decode(omx_image.GetWidth(), omx_image.GetHeight()))
  226
+      if(omx_image.Decode(maxWidth, maxHeight))
227 227
       {
228 228
         Allocate(omx_image.GetDecodedWidth(), omx_image.GetDecodedHeight(), XB_FMT_A8R8G8B8);
229 229
 
6  xbmc/pictures/Picture.cpp
@@ -119,9 +119,9 @@ bool CPicture::CacheTexture(uint8_t *pixels, uint32_t width, uint32_t height, ui
119 119
 
120 120
   uint32_t max_height = g_advancedSettings.m_imageRes;
121 121
   if (g_advancedSettings.m_fanartRes > g_advancedSettings.m_imageRes)
122  
-  { // a separate fanart resolution is specified - check if the image is exactly equal to this res
123  
-    if (width * 9 == height * 16 && height >= g_advancedSettings.m_fanartRes)
124  
-    { // special case for 16x9 images larger than the fanart res
  122
+  { // 16x9 images larger than the fanart res use that rather than the image res
  123
+    if (fabsf((float)width / (float)height / (16.0f/9.0f) - 1.0f) <= 0.01f && height >= g_advancedSettings.m_fanartRes)
  124
+    {
125 125
       max_height = g_advancedSettings.m_fanartRes;
126 126
     }
127 127
   }

0 notes on commit 67dc2a9

Please sign in to comment.
Something went wrong with that request. Please try again.