Permalink
Browse files

Services/WebFrontend: Use JPG for preview images instead of PNG, at t…

…hese resolutions JPG looks no worse than PNG and smaller file sizes mean faster page loads over a slow network connection.
  • Loading branch information...
1 parent 5603d56 commit d2a14f2366e362e40c8a98bd1b0bcd9f0fd3d56a @stuartm stuartm committed Nov 17, 2013
@@ -59,7 +59,7 @@
month_names[program.StartTime.getMonth()],
program.StartTime.getDate(), startTime);
%>
- <img title="<%= title %>" alt="<%= desc %>" height="300" src="/Content/GetPreviewImage?ChanId=<%=program.Channel.ChanId %>&Height=300&StartTime=<%=UTCDateString( program.Recording.StartTs ) %>"/>
+ <img title="<%= title %>" alt="<%= desc %>" height="300" src="/Content/GetPreviewImage?ChanId=<%=program.Channel.ChanId %>&Height=300&StartTime=<%=UTCDateString( program.Recording.StartTs ) %>&Format=JPG"/>
<%
}
%>
@@ -21,7 +21,7 @@
<tr>
<!-- These image loads are slow when you have a lot of recordings, so comment
them out, but leave them in for reference for users.
- <td><img src="/Content/GetPreviewImage?ChanId=<%= program.Channel.ChanId%>&StartTime=<%= UTCDateString( program.StartTime ) %>" ></img></td>
+ <td><img src="/Content/GetPreviewImage?ChanId=<%= program.Channel.ChanId%>&StartTime=<%= UTCDateString( program.StartTime ) %>&Format=JPG" ></img></td>
-->
<td><%= program.Title %><% if (program.SubTitle.length) os.write(" - " + program.SubTitle); %></td>
@@ -40,7 +40,7 @@ import "/tv/js/constants.js"
if (displayGroupList.indexOf(displayGroup) === -1)
displayGroup = "";
- var recordings = dvr.GetRecordedList( sortDescending, 0, 50, displayGroup, recGroup, "" );
+ var recordings = dvr.GetRecordedList( sortDescending, 0, 0, displayGroup, recGroup, "" );
var programs = recordings.Programs;
%>
@@ -189,7 +189,7 @@ for (var progIdx = 0; progIdx < programs.length; progIdx++)
<div class="recordingRow" id="<%=programIdentifier%>_row">
<div class="previewBox">
<div class="previewImageBackground">
- <img alt="Preview Image" height="67" class="previewImage" src="/Content/GetPreviewImage?ChanId=<%=program.Channel.ChanId%>&amp;StartTime=<%=program.Recording.StartTs.toISOString()%>&amp;height=67" />
+ <img alt="Preview Image" height="67" class="previewImage" src="/Content/GetPreviewImage?ChanId=<%=program.Channel.ChanId%>&amp;StartTime=<%=program.Recording.StartTs.toISOString()%>&amp;height=67&amp;format=JPG" />
</div>
<span class="watchRecordingLink"><%=qsTr("Watch")%></span>
</div>
@@ -92,7 +92,8 @@ class SERVICE_PUBLIC ContentServices : public Service //, public QScriptable ??
const QDateTime &StartTime,
int Width,
int Height,
- int SecsIn ) = 0;
+ int SecsIn,
+ const QString &Format) = 0;
virtual QFileInfo GetRecording ( int ChanId,
const QDateTime &StartTime ) = 0;
@@ -27,8 +27,9 @@
#include <QDir>
#include <QImage>
-#include <math.h>
+#include <QImageWriter>
+#include <math.h>
#include <compat.h>
#include "mythcorecontext.h"
@@ -465,7 +466,8 @@ QFileInfo Content::GetPreviewImage( int nChanId,
const QDateTime &recstarttsRaw,
int nWidth,
int nHeight,
- int nSecsIn )
+ int nSecsIn,
+ const QString &sFormat )
{
if (!recstarttsRaw.isValid())
{
@@ -477,6 +479,16 @@ QFileInfo Content::GetPreviewImage( int nChanId,
throw sMsg;
}
+ if (!sFormat.isEmpty() &&
+ !QImageWriter::supportedImageFormats().contains(sFormat.toAscii()))
+ {
+ throw "GetPreviewImage: Specified 'Format' is not supported.";
+ }
+
+ QString sImageFormat = sFormat;
+ if (sImageFormat.isEmpty())
+ sImageFormat = "PNG";
+
QDateTime recstartts = recstarttsRaw.toUTC();
// ----------------------------------------------------------------------
@@ -516,11 +528,11 @@ QFileInfo Content::GetPreviewImage( int nChanId,
if (nSecsIn <= 0)
{
nSecsIn = -1;
- sPreviewFileName = sFileName + ".png";
+ sPreviewFileName = QString("%1.%2").arg(sFileName).arg(sImageFormat.toLower());
}
else
{
- sPreviewFileName = QString("%1.%2.png").arg(sFileName).arg(nSecsIn);
+ sPreviewFileName = QString("%1.%2.%3").arg(sFileName).arg(nSecsIn).arg(sImageFormat.toLower());
}
if (!QFile::exists( sPreviewFileName ))
@@ -577,11 +589,12 @@ QFileInfo Content::GetPreviewImage( int nChanId,
if (bDefaultPixmap)
sNewFileName = sPreviewFileName;
else
- sNewFileName = QString( "%1.%2.%3x%4.png" )
+ sNewFileName = QString( "%1.%2.%3x%4.%5" )
.arg( sFileName )
.arg( nSecsIn )
.arg( nWidth )
- .arg( nHeight );
+ .arg( nHeight )
+ .arg( sImageFormat.toLower() );
// ----------------------------------------------------------------------
// check to see if scaled preview image is already created.
@@ -73,7 +73,8 @@ class Content : public ContentServices
const QDateTime &StartTime,
int Width,
int Height,
- int SecsIn );
+ int SecsIn,
+ const QString &Format);
QFileInfo GetRecording ( int ChanId,
const QDateTime &StartTime );

0 comments on commit d2a14f2

Please sign in to comment.