9 #include <QImageReader>
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 return image.mirrored(
true,
false);
108 transform.rotate(180);
109 return image.transformed(transform);
111 return image.mirrored(
false,
true);
113 transform.rotate(270);
114 return image.mirrored(
true,
false).transformed(transform);
116 transform.rotate(90);
117 return image.transformed(transform);
119 transform.rotate(90);
120 return image.mirrored(
true,
false).transformed(transform);
122 transform.rotate(270);
123 return image.transformed(transform);
145 if ((size() == newSize) && !isNull())
150 *(
static_cast<QImage *
> (
this)) = QImage(newSize, QImage::Format_ARGB32);
157 Qt::AspectRatioMode mode = Qt::IgnoreAspectRatio;
159 mode = Qt::KeepAspectRatio;
161 Assign(scaled(newSize, mode, Qt::SmoothTransformation));
175 mirrorImage = mirrored(
false,
true);
178 int height = (int)((
float)mirrorImage.height() * (float)length/100);
179 mirrorImage = mirrorImage.copy(0,0,mirrorImage.width(),height);
185 mirrorImage = mirrored(
true,
false);
188 int width = (int)((
float)mirrorImage.width() * (float)length/100);
189 mirrorImage = mirrorImage.copy(0,0,width,mirrorImage.height());
194 QImage alphaChannel(mirrorImage.size(), QImage::Format_ARGB32);
195 MakeGradient(alphaChannel, QColor(0xAA, 0xAA, 0xAA), QColor(0x00, 0x00, 0x00), 255,
197 mirrorImage.setAlphaChannel(alphaChannel);
199 QTransform shearTransform;
202 shearTransform.scale(1,(
float)scale/100);
203 shearTransform.shear((
float)shear/100,0);
207 shearTransform.scale((
float)scale/100,1);
208 shearTransform.shear(0,(
float)shear/100);
211 mirrorImage = mirrorImage.transformed(shearTransform, Qt::SmoothTransformation);
215 newsize = QSize(mirrorImage.width(), height()+spacing+mirrorImage.height());
217 newsize = QSize(width()+spacing+mirrorImage.width(), mirrorImage.height());
219 QImage temp(newsize, QImage::Format_ARGB32);
220 temp.fill(Qt::transparent);
222 QPainter newpainter(&temp);
223 newpainter.setCompositionMode(QPainter::CompositionMode_SourceOver);
228 newpainter.drawImage(mirrorImage.width()-width(), 0,
229 *(
static_cast<QImage*
>(
this)));
233 newpainter.drawImage(0, 0, *(
static_cast<QImage*
>(
this)));
236 newpainter.drawImage(0, height()+spacing, mirrorImage);
242 newpainter.drawImage(0, mirrorImage.height()-height(),
243 *(
static_cast<QImage*
>(
this)));
247 newpainter.drawImage(0, 0, *(
static_cast<QImage*
>(
this)));
250 newpainter.drawImage(width()+spacing, 0, mirrorImage);
265 for (
int y = 0; y < height(); ++y)
267 for (
int x = 0; x < width(); ++x)
269 QRgb oldPixel =
pixel(x, y);
270 int greyVal = qGray(oldPixel);
271 setPixel(x, y, qRgba(greyVal, greyVal, greyVal, qAlpha(oldPixel)));
278 if (!reader || !reader->canRead())
281 auto *im =
new QImage;
283 if (im && reader->read(im))
299 QImage *im =
nullptr;
306 QString fname = url.path();
308 if (url.hasFragment())
309 fname +=
'#' + url.fragment();
312 if (!mythUrl.isEmpty())
314 auto *rf =
new RemoteFile(mythUrl,
false,
false, 0ms);
317 bool ret = rf->SaveAs(data);
324 im->loadFromData(data);
329 LOG(VB_GENERAL, LOG_ERR,
330 QString(
"MythImage::Load failed to load remote image %1")
335 else if ((
filename.startsWith(
"http://")) ||
336 (
filename.startsWith(
"https://")) ||
343 im->loadFromData(data);
349 if (path.startsWith(
'/') ||
351 im =
new QImage(path);
354 if (im && im->isNull())
367 LOG(VB_GUI, LOG_WARNING, QString(
"MythImage::Load(%1) failed").arg(
filename));
373 const QColor &end,
int alpha,
378 QColor startColor = begin;
379 QColor endColor = end;
380 startColor.setAlpha(alpha);
381 endColor.setAlpha(alpha);
388 pointB = QPoint(0,image.height());
392 pointB = QPoint(image.width(),0);
395 QLinearGradient gradient(pointA, pointB);
396 gradient.setColorAt(0, startColor);
397 gradient.setColorAt(1, endColor);
400 QPainter painter(&image);
401 painter.setCompositionMode(QPainter::CompositionMode_Source);
402 painter.fillRect(0, 0, image.width(), image.height(), gradient);
407 QColor black(0, 0, 0, alpha);
408 painter.setPen(black);
409 QPen pen = painter.pen();
411 painter.drawRect(image.rect());
417 QSize size,
const QColor &begin,
418 const QColor &end,
uint alpha,
421 QImage img(size.width(), size.height(), QImage::Format_ARGB32);
436 : m_fileName(std::move(fileName))