Geometrize  1.0
An application for geometrizing images into geometric primitives
Functions
geometrize::image Namespace Reference

Functions

Bitmap createBitmap (const QImage &image)
 createBitmap Creates a bitmap data object from the given image. More...
 
geometrize::Bitmap convertImageToBitmapWithDownscaling (const QImage &image)
 imageToBitmapWithDownscaling Creates a bitmap data object from the given image, downscaling in the process based on global preferences for image resizing More...
 
QImage createImage (const Bitmap &data)
 createImage Creates an image from the bitmap data object. Assumes RGBA8888 format. More...
 
QPixmap createPixmap (const Bitmap &data)
 createPixmap Creates a pixmap from the bitmap data object. Assumes RGBA8888 format. More...
 
QImage loadImage (const std::string &filePath)
 loadImage Loads an image from the image at the file path. Converts to RGBA8888 format. More...
 
QImage convertImageToRgba8888 (const QImage &image)
 convertImageToRgba8888 Returns a copy of the image in the RGBA8888 format. More...
 

Function Documentation

◆ convertImageToBitmapWithDownscaling()

geometrize::Bitmap geometrize::image::convertImageToBitmapWithDownscaling ( const QImage &  image)

imageToBitmapWithDownscaling Creates a bitmap data object from the given image, downscaling in the process based on global preferences for image resizing

Parameters
imageThe image to create the bitmap data from.
Returns
The new bitmap data.
33 {
34  QImage im{image.copy()};
35 
37  if(prefs.isImageTaskImageResizeEnabled()) {
38  const std::pair<std::uint32_t, std::uint32_t> sizeThreshold{prefs.getImageTaskResizeThreshold()};
39  const QSize imageSize{im.size()};
40 
41  if(sizeThreshold.first < static_cast<unsigned int>(imageSize.width())
42  || sizeThreshold.second < static_cast<unsigned int>(imageSize.height())) {
43  im = image.scaled(sizeThreshold.first, sizeThreshold.second, Qt::KeepAspectRatio, Qt::SmoothTransformation).convertToFormat(QImage::Format_RGBA8888);
44  }
45  }
46  return geometrize::image::createBitmap(im.convertToFormat(QImage::Format_RGBA8888));
47 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ convertImageToRgba8888()

QImage geometrize::image::convertImageToRgba8888 ( const QImage &  image)

convertImageToRgba8888 Returns a copy of the image in the RGBA8888 format.

Parameters
imageThe image to convert.
Returns
A copy of the given image in RGBA8888 format.
83 {
84  return image.convertToFormat(QImage::Format_RGBA8888);
85 }
Here is the caller graph for this function:

◆ createBitmap()

Bitmap geometrize::image::createBitmap ( const QImage &  image)

createBitmap Creates a bitmap data object from the given image.

Parameters
imageThe image to create the bitmap data from.
Returns
The new bitmap data.
23 {
24  assert(!image.isNull() && "Image is null, will fail to create bitmap data");
25  assert((image.width() != 0 && image.height() != 0) && "Image has zero width or height");
26  assert((image.format() == QImage::Format_RGBA8888) && "Cannot create bitmap data from a non-RGBA8888 image");
27 
28  const std::vector<uchar> data(image.bits(), image.bits() + image.sizeInBytes());
29  return Bitmap(image.width(), image.height(), data);
30 }
Here is the caller graph for this function:

◆ createImage()

QImage geometrize::image::createImage ( const Bitmap &  data)

createImage Creates an image from the bitmap data object. Assumes RGBA8888 format.

Parameters
dataThe bitmap data, RGBA8888 bytes (must be a multiple of 4).
Returns
The pixmap created from the bytes data.
49 {
50  if(data.getWidth() == 0 || data.getHeight() == 0) {
51  assert(0 && "Bad bitmap data");
52  return QImage();
53  }
54 
55  // Note! This takes a shallow copy of the data, and so depends on the bitmap itself continuing to live on
56  return QImage(data.getDataRef().data(), data.getWidth(), data.getHeight(), QImage::Format_RGBA8888);
57 }
Here is the caller graph for this function:

◆ createPixmap()

QPixmap geometrize::image::createPixmap ( const Bitmap &  data)

createPixmap Creates a pixmap from the bitmap data object. Assumes RGBA8888 format.

Parameters
dataThe bitmap data, RGBA8888 bytes (must be a multiple of 4).
Returns
The pixmap created from the bytes data.
60 {
61  return QPixmap::fromImage(createImage(data));
62 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ loadImage()

QImage geometrize::image::loadImage ( const std::string &  filePath)

loadImage Loads an image from the image at the file path. Converts to RGBA8888 format.

Parameters
filePathThe file path to the image.
Returns
The image loaded from the image file.
65 {
66  const QString path = QString::fromStdString(filePath);
67  QImage image;
68  if(QFile(path).exists()) {
69  image = QImage(path);
70  } else {
71  image = QImage(QUrl(path).toLocalFile());
72  }
73 
74  if(image.isNull()) {
75  assert(0 && "Bad image data");
76  return image;
77  }
78 
79  return image.convertToFormat(QImage::Format_RGBA8888);
80 }
Here is the caller graph for this function:
geometrize::image::createImage
QImage createImage(const Bitmap &data)
createImage Creates an image from the bitmap data object. Assumes RGBA8888 format.
Definition: imageloader.cpp:48
geometrize::preferences::GlobalPreferences::getImageTaskResizeThreshold
std::pair< std::uint32_t, std::uint32_t > getImageTaskResizeThreshold() const
getImageTaskResizeThreshold Gets the maximum dimensions of an image that can be used in an image task...
Definition: globalpreferences.cpp:618
geometrize::image::createBitmap
Bitmap createBitmap(const QImage &image)
createBitmap Creates a bitmap data object from the given image.
Definition: imageloader.cpp:22
geometrize::preferences::GlobalPreferences
The GlobalPreferences class models the preferences associated with the application as a whole....
Definition: globalpreferences.h:44
geometrize::preferences::getGlobalPreferences
geometrize::preferences::GlobalPreferences & getGlobalPreferences()
getGlobalPreferences Shorthand function that gets a reference to the shared global preferences object...
Definition: globalpreferences.cpp:32