10#include <QNetworkReply>
29 LOG(VB_GENERAL, LOG_ERR,
"Image created without parent!");
58 if (
s_ui && (1 == cnt))
63 LOG(VB_GENERAL, LOG_INFO,
64 "Image should be removed from cache prior to deletion.");
82 *(
static_cast<QImage*
>(
this)) = img;
87 *(
static_cast<QImage*
>(
this)) = img;
106#if QT_VERSION < QT_VERSION_CHECK(6,9,0)
107 return image.mirrored(
true,
false);
109 return image.flipped(Qt::Horizontal);
112 transform.rotate(180);
113 return image.transformed(transform);
115#if QT_VERSION < QT_VERSION_CHECK(6,9,0)
116 return image.mirrored(
false,
true);
118 return image.flipped(Qt::Vertical);
121 transform.rotate(270);
122#if QT_VERSION < QT_VERSION_CHECK(6,9,0)
123 return image.mirrored(
true,
false).transformed(transform);
125 return image.flipped(Qt::Horizontal).transformed(transform);
128 transform.rotate(90);
129 return image.transformed(transform);
131 transform.rotate(90);
132#if QT_VERSION < QT_VERSION_CHECK(6,9,0)
133 return image.mirrored(
true,
false).transformed(transform);
135 return image.flipped(Qt::Horizontal).transformed(transform);
138 transform.rotate(270);
139 return image.transformed(transform);
161 if ((size() == newSize) && !isNull())
166 *(
static_cast<QImage *
> (
this)) = QImage(newSize, QImage::Format_ARGB32);
173 Qt::AspectRatioMode mode = Qt::IgnoreAspectRatio;
175 mode = Qt::KeepAspectRatio;
177 Assign(scaled(newSize, mode, Qt::SmoothTransformation));
191#if QT_VERSION < QT_VERSION_CHECK(6,9,0)
192 mirrorImage = mirrored(
false,
true);
194 mirrorImage = flipped(Qt::Vertical);
198 int height = (int)((
float)mirrorImage.height() * (float)length/100);
199 mirrorImage = mirrorImage.copy(0,0,mirrorImage.width(),height);
205#if QT_VERSION < QT_VERSION_CHECK(6,9,0)
206 mirrorImage = mirrored(
true,
false);
208 mirrorImage = flipped(Qt::Horizontal);
212 int width = (int)((
float)mirrorImage.width() * (float)length/100);
213 mirrorImage = mirrorImage.copy(0,0,width,mirrorImage.height());
218 QImage alphaChannel(mirrorImage.size(), QImage::Format_ARGB32);
219 MakeGradient(alphaChannel, QColor(0xAA, 0xAA, 0xAA), QColor(0x00, 0x00, 0x00), 255,
221 mirrorImage.setAlphaChannel(alphaChannel);
223 QTransform shearTransform;
226 shearTransform.scale(1,
static_cast<qreal
>(scale)/100);
227 shearTransform.shear(
static_cast<qreal
>(shear)/100,0);
231 shearTransform.scale(
static_cast<qreal
>(scale)/100,1);
232 shearTransform.shear(0,
static_cast<qreal
>(shear)/100);
235 mirrorImage = mirrorImage.transformed(shearTransform, Qt::SmoothTransformation);
239 newsize = QSize(mirrorImage.width(), height()+spacing+mirrorImage.height());
241 newsize = QSize(width()+spacing+mirrorImage.width(), mirrorImage.height());
243 QImage temp(newsize, QImage::Format_ARGB32);
244 temp.fill(Qt::transparent);
246 QPainter newpainter(&temp);
247 newpainter.setCompositionMode(QPainter::CompositionMode_SourceOver);
252 newpainter.drawImage(mirrorImage.width()-width(), 0,
253 *(
static_cast<QImage*
>(
this)));
257 newpainter.drawImage(0, 0, *(
static_cast<QImage*
>(
this)));
260 newpainter.drawImage(0, height()+spacing, mirrorImage);
266 newpainter.drawImage(0, mirrorImage.height()-height(),
267 *(
static_cast<QImage*
>(
this)));
271 newpainter.drawImage(0, 0, *(
static_cast<QImage*
>(
this)));
274 newpainter.drawImage(width()+spacing, 0, mirrorImage);
289 for (
int y = 0; y < height(); ++y)
291 for (
int x = 0; x < width(); ++x)
293 QRgb oldPixel =
pixel(x, y);
294 int greyVal = qGray(oldPixel);
295 setPixel(x, y, qRgba(greyVal, greyVal, greyVal, qAlpha(oldPixel)));
302 if (!reader || !reader->canRead())
305 auto *im =
new QImage;
307 if (im && reader->read(im))
323 QImage *im =
nullptr;
330 QString fname = url.path();
332 if (url.hasFragment())
333 fname +=
'#' + url.fragment();
336 if (!mythUrl.isEmpty())
338 auto *rf =
new RemoteFile(mythUrl,
false,
false, 0ms);
341 bool ret = rf->SaveAs(data);
348 im->loadFromData(data);
353 LOG(VB_GENERAL, LOG_ERR,
354 QString(
"MythImage::Load failed to load remote image %1")
359 else if ((
filename.startsWith(
"http://")) ||
360 (
filename.startsWith(
"https://")) ||
367 im->loadFromData(data);
373 if (path.startsWith(
'/') ||
375 im =
new QImage(path);
378 if (im && im->isNull())
391 LOG(VB_GUI, LOG_WARNING, QString(
"MythImage::Load(%1) failed").arg(
filename));
397 const QColor &end,
int alpha,
402 QColor startColor = begin;
403 QColor endColor = end;
404 startColor.setAlpha(alpha);
405 endColor.setAlpha(alpha);
412 pointB = QPoint(0,image.height());
416 pointB = QPoint(image.width(),0);
419 QLinearGradient gradient(pointA, pointB);
420 gradient.setColorAt(0, startColor);
421 gradient.setColorAt(1, endColor);
424 QPainter painter(&image);
425 painter.setCompositionMode(QPainter::CompositionMode_Source);
426 painter.fillRect(0, 0, image.width(), image.height(), gradient);
431 QColor black(0, 0, 0, alpha);
432 painter.setPen(black);
433 QPen pen = painter.pen();
435 painter.drawRect(image.rect());
441 QSize size,
const QColor &begin,
442 const QColor &end,
uint alpha,
445 QImage img(size.width(), size.height(), QImage::Format_ARGB32);
460 : m_fileName(
std::move(fileName))
bool download(const QString &url, const QString &dest, bool reload=false)
Downloads a URL to a file in blocking mode.
MythImageReader(QString fileName)
QNetworkReply * m_networkReply
FillDirection m_gradDirection
bool Load(MythImageReader *reader)
void SetIsInCache(bool bCached)
virtual void SetChanged(bool change=true)
static void MakeGradient(QImage &image, const QColor &begin, const QColor &end, int alpha, BoundaryWanted drawBoundary=BoundaryWanted::Yes, FillDirection direction=FillDirection::TopToBottom)
void SetFileName(QString fname)
static MythUIHelper * s_ui
void Orientation(int orientation)
Changes the orientation angle of the image according to the exif rotation values.
void Assign(const QImage &img)
void Reflect(ReflectAxis axis, int shear, int scale, int length, int spacing=0)
MythImage(MythPainter *parent, const char *name="MythImage")
Creates a reference counted image, call DecrRef() to delete.
static MythImage * Gradient(MythPainter *painter, QSize size, const QColor &begin, const QColor &end, uint alpha, FillDirection direction=FillDirection::TopToBottom)
Create a gradient image.
void Resize(QSize newSize, bool preserveAspect=false)
int DecrRef(void) override
Decrements reference count and deletes on 0.
int IncrRef(void) override
Increments reference count.
static QImage ApplyExifOrientation(QImage &image, int orientation)
void DeleteFormatImage(MythImage *im)
MythImage * GetFormatImage()
Returns a blank reference counted image in the format required for the Draw functions for this painte...
void ExcludeFromCacheSize(MythImage *Image)
void IncludeInCacheSize(MythImage *Image)
General purpose reference counter.
virtual int DecrRef(void)
Decrements reference count and deletes on 0.
virtual int IncrRef(void)
Increments reference count.
static QString FindFile(const QString &filename, const QString &host, const QString &storageGroup, bool useRegex=false, bool allowFallback=false)
Search all BE's for a file in the give storage group.
static guint32 * pixel
--------------------------------------------------—**
MythDownloadManager * GetMythDownloadManager(void)
Gets the pointer to the MythDownloadManager singleton.
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
MythUIHelper * GetMythUI()