Crate geometrize_sys

source ·

Structs§

Constants§

Statics§

  • @brief allShapes is a convenient array of all of the members of ShapeTypes.
  • @brief shapeTypeNames provides a convenient mapping to names of types of shape (all lower case, underscores instead of spaces e.g. rotated_ellipse).

Functions§

  • @brief Bitmap Creates a new bitmap. @param width The width of the bitmap. @param height The height of the bitmap. @param color The starting color of the bitmap (RGBA format).
  • @brief Bitmap Creates a new bitmap from the supplied byte data. @param width The width of the bitmap. @param height The height of the bitmap. @param data The byte data to fill the bitmap with, must be width * height * depth (4) long.
  • @brief fill Fills the bitmap with the given color. @param color The color to fill the bitmap with.
  • @brief getHeight Gets the height of the bitmap.
  • @brief getPixel Gets a pixel color value. @param x The x-coordinate of the pixel. @param y The y-coordinate of the pixel. @return The pixel RGBA color value.
  • @brief getWidth Gets the width of the bitmap.
  • @brief setPixel Sets a pixel color value. @param x The x-coordinate of the pixel. @param y The y-coordinate of the pixel. @param color The pixel RGBA color value.
  • @brief ImageRunner Creates an new image runner with the given target bitmap. Uses the average color of the target as the starting image. @param targetBitmap The target bitmap to replicate with shapes.
  • @brief ImageRunner Creates an image runner with the given target bitmap, starting from the given initial bitmap. The target bitmap and initial bitmap must be the same size (width and height). @param targetBitmap The target bitmap to replicate with shapes. @param initialBitmap The starting bitmap.
  • @brief getCurrent Gets the current bitmap with the primitives drawn on it. @return The current bitmap.
  • @brief getCurrent Gets the current bitmap with the primitives drawn on it, const-edition. @return The current bitmap.
  • @brief getModel Gets the underlying model. @return The model.
  • @brief getTarget Gets the target bitmap. @return The target bitmap.
  • @brief getTarget Gets the target bitmap, const-edition. @return The target bitmap.
  • @brief step Updates the internal model once. @param options Various configurable settings for doing the step e.g. the shape types to consider. @param shapeCreator An optional function for creating and mutating shapes @param energyFunction An optional function to calculate the energy (if unspecified a default implementation is used). @param addShapePrecondition An optional function to determine whether to accept a shape (if unspecified a default implementation is used). @return A vector containing data about the shapes just added to the internal model.
  • @brief Model Creates a model that will aim to replicate the target bitmap with shapes. @param target The target bitmap to replicate with shapes.
  • @brief Model Creates a model that will optimize for the given target bitmap, starting from the given initial bitmap. The target bitmap and initial bitmap must be the same size (width and height). @param target The target bitmap to replicate with shapes. @param initial The starting bitmap.
  • @brief drawShape Draws a shape on the model. Typically used when to manually add a shape to the image (e.g. when setting an initial background). NOTE this unconditionally draws the shape, even if it increases the difference between the source and target image. @param shape The shape to draw. @param color The color (including alpha) of the shape. @return Data about the shape drawn on the model.
  • @brief getCurrent Gets the current bitmap. @return The current bitmap.
  • @brief getCurrent Gets the current bitmap, const-edition. @return The current bitmap.
  • @brief getHeight Gets the height of the target bitmap. @return The height of the target bitmap.
  • @brief getTarget Gets the target bitmap. @return The target bitmap.
  • @brief getTarget Gets the target bitmap, const-edition. @return The target bitmap.
  • @brief getWidth Gets the width of the target bitmap. @return The width of the target bitmap.
  • @brief reset Resets the model back to the state it was in when it was created. @param backgroundColor The starting background color to use.
  • @brief setSeed Sets the seed that the random number generators of this model use. Note that the model also uses an internal seed offset which is incremented when the model is stepped. @param seed The random number generator seed.
  • @brief step Steps the primitive optimization/fitting algorithm. @param shapeCreator A function that will produce the shapes. @param alpha The alpha of the shape. @param shapeCount The number of random shapes to generate (only 1 is chosen in the end). @param maxShapeMutations The maximum number of times to mutate each random shape. @param maxThreads The maximum number of threads to use during this step. @param energyFunction An optional function to calculate the energy (if unspecified a default implementation is used). @param addShapePrecondition An optional function to determine whether to accept a shape (if unspecified a default implementation is used). @return A vector containing data about the shapes added to the model in this step. This may be empty if no shape that improved the image could be found.
  • @brief Scanline Creates a new scanline. @param y The y-coordinate. @param x1 The leftmost x-coordinate. @param x2 The rightmost x-coordinate.
  • @brief Creates a new state. @param shape The shape. @param alpha The color alpha of the geometric shape.
  • @brief mutate Modifies the current state in a random fashion. @return The old state, useful for undoing the mutation or keeping track of previous states.
  • @brief getAverageImageColor Computes the average RGB color of the pixels in the bitmap. @param image The image whose average color will be calculated. @return The average RGB color of the image, RGBA8888 format. Alpha is set to opaque (255).
  • @brief mapShapeBoundsToImage Maps the given shape bound percentages to the given image, returning a bounding rectangle, or the whole image if the bounds were invalid @param The options to map to the image @param The image to map the options around @return The mapped shape bounds (xMin, yMin, xMax, yMax)
  • @brief randomRange Returns a random integer in the range, inclusive. Uses thread-local random number generators under the hood. To ensure deterministic shape generation that can be repeated for different seeds, this should be used for shape mutation, but nothing else. @param min The lower bound. @param max The upper bound. @return The random integer in the range.
  • @brief seedRandomGenerator Seeds the (thread-local) random number generators. @param seed The random seed.
  • @brief bestHillClimbState Gets the best state using a hill climbing algorithm. @param shapeCreator A function that will create the shapes that will be chosen from. @param alpha The opacity of the shape. @param n The number of random states to generate. @param age The number of hillclimbing steps. @param target The target bitmap. @param current The current bitmap. @param buffer The buffer bitmap. @param lastScore The last score. @param customEnergyFunction An optional function to calculate the energy (if unspecified a default implementation is used). @return The best state acquired from hill climbing i.e. the one with the lowest energy.
  • @brief computeColor Calculates the color of the scanlines. @param target The target image. @param current The current image. @param lines The scanlines. @param alpha The alpha of the scanline. @return The color of the scanlines.
  • @brief defaultEnergyFunction The default/built-in energy function that calculates a measure of the improvement adding the scanlines of a shape provides - lower energy is better. @param lines The scanlines of the shape. @param alpha The alpha of the scanlines. @param target The target bitmap. @param current The current bitmap. @param buffer The buffer bitmap. @param score The score. @return The energy measure.
  • @brief differenceFull Calculates the root-mean-square error between two bitmaps. @param first The first bitmap. @param second The second bitmap. @return The difference/error measure between the two bitmaps.
  • @brief differencePartial Calculates the root-mean-square error between the parts of the two bitmaps within the scanline mask. This is for optimization purposes, it lets us calculate new error values only for parts of the image we know have changed. @param target The target bitmap. @param before The bitmap before the change. @param after The bitmap after the change. @param score The score. @param lines The scanlines. @return The difference/error between the two bitmaps, masked by the scanlines.
  • @brief create Creates a new shape of the specified type. @param t The type of shape to create. @return The new shape.
  • @brief createDefaultShapeCreator Creates an instance of the default shape creator object. The setup, mutate and rasterize methods are bound with default methods. @param types The types of shapes to create. @param xMin The minimum x coordinate of the shapes created. @param yMin The minimum y coordinate of the shapes created. @param xMax The maximum x coordinate of the shapes created. @param yMax The maximum y coordinate of the shapes created. @return The default shape creator.
  • @brief randomShape Creates a random shape. @return The new shape.
  • @brief randomShapeOf Creates a random shape from the types supplied. @param t The types of shape to possibly create. @return The new shape.
  • @brief trimScanlines Crops the scanning width of an array of scanlines so they do not scan outside of the given area. @param scanlines The scanlines to crop. @param minX The minimum x value to crop to. @param minY The minimum y value to crop to. @param maxX The maximum x value to crop to. @param maxY The maximum y value to crop to. @return A new vector of cropped scanlines.

Type Aliases§

  • @brief ShapeAcceptancePreconditionFunction Type alias for a function that is used to decide whether or not to finally add a shape to the image @param lastScore The image similarity score prior to adding the shape @param newScore What the image similarity score would be after adding the shape @param shape The shape that this function shall decide whether to add @param lines The scanlines for the pixels in the shape @param color The colour of the shape @param before The image prior to adding the shape @param after The image as it would be after adding the shape @param target The image that we are trying to replicate @return True to add the shape to the image, false not to
  • @brief The ShapeTypes enum specifies the types of shapes that can be used. These can be combined to produce images composed of multiple primitive types. @author Sam Twidale (https://samcodes.co.uk/)
  • @brief EnergyFunction Type alias for a function that calculates a measure of the improvement adding the scanlines of a shape provides - lower energy is better. @param lines The scanlines of the shape. @param alpha The alpha of the scanlines. @param target The target bitmap. @param current The current bitmap. @param buffer The buffer bitmap. @param score The score. @return The energy measure.