Files
libimg/include/image/filters.h
T

152 lines
5.5 KiB
C

#ifndef FILTERS_H
#define FILTERS_H
#include "utils.h"
/**
* @brief Packs new alpha channel
* @details Takes a value from 0 - 255 for levels of opacity in image and packs
* it into the first byte. 0 is transparent and 255 is fully opaque.
* @param[in] clr Takes in a packed pixel
* @param[in] alpha One byte value to be packed for image
* @return unsigned int Packed color with new alpha channel.
*/
unsigned int
u32_put_alpha(const unsigned int clr, const unsigned char alpha);
/**
* @brief Inverts bits for color channels
* @details Takes a packed color and inverts the RGB channel bits from 0 to 1
* and vice versa. Then saves the alpha channel back to new packed image.
* @param[in] clr Takes in a packed pixel
* @return unsigned int Packed color with inverted RGB channels.
*/
unsigned int
u32_invert(const unsigned int clr);
/**
* @brief Inverts RED and BLUE channels
* @details Takes a packed color and isolates the A and G channels, then shifts
* the clr Red channel 16 Bits right and B channel 16 Bits left.
* @param[in] clr Takes in a packed pixel
* @return unsigned int Packed color with inverted RB channels.
*/
unsigned int
u32_swap_rb(const unsigned int clr);
/**
* @brief Grays pixels from RGB channels
* @details Takes a packed color and merges RGB channels and sets all RGB
* channels to new gray.
* @param[in] clr Takes in a packed pixel
* @return unsigned int Packed color with gray RGB channels.
*/
unsigned int
u32_grayscale(const unsigned int clr);
/**
* @brief Grays pixels from RGB channels
* @details If greyscale value is less than Max then set color to transparent
* and black. If greater, set color to opaque white. channels to new gray.
* @param[in] clr Takes in a packed pixel
* @param[in] max Max gray value for split
* @return unsigned int Packed color with white or black RGB channels.
*/
unsigned int
u32_step(const unsigned int clr, const unsigned char max);
/**
* @brief Brightens Color
* @details Uses a factor to multiply RGB channels to increase values closer to
* 255 to raise brightness. Use x > 1 for a brighter pixel and x < 1 for a
* darker pixel
* @param[in] clr Takes in a packed pixel
* @param[in] factor Used to multiply against RGB channels. Can be 0 < x > 1 but
* NOT negative.
* @return unsigned int Packed color with brighter or darker pixel
*/
unsigned int
u32_brighten(const unsigned int clr, const float factor);
/**
* @brief Combines RGB values between 2 packed colors
* @details Takes and adds the respective RGB values between 2 colors and
* divides by 2 to make sure each channel is below 255. So, even if 2 pixels are
* white, the max values will stay 255.
* @param[in] clr_a Packed Pixel A
* @param[in] clr_b Packed Pixel B
* @return unsigned int Packed ARGB pixel.
*/
unsigned int
u32_mix(const unsigned int clr_a, const unsigned int clr_b);
/**
* @brief Combines RGB values between 2 packed colors
* @details Takes and adds the respective RGB values between 2 colors and
* divides by 2 to make sure each channel is below 255. So, even if 2 pixels are
* white, the max values will stay 255.
* @param[in] clr_a Packed Pixel A
* @param[in] clr_b Packed Pixel B
* @return unsigned int Packed ARGB pixel.
*/
unsigned int
u32_lerp(const unsigned clr_a, const unsigned int clr_b, const float ratio);
/**
* @brief Returns a Packed Pixel of one Channel
* @param[in] clr Packed Pixel
* @param[in] keep Character of 'r', 'g', 'b', keeping the channel respectively.
* @return unsigned int Packed Pixel with one channel kept, includes alpha auto
*/
unsigned int
u32_mask(const unsigned int clr, const char keep);
/**
* @brief Rotates the bits of each channel by n
* @details Moves bits of channels left by n with the max being 8 and
* recommended to use 0 < x < 8 instead of 8; 8 just returns the same pixel as
* it is just rotated back to original position. Cannot be greater than 8
* because the calculations would result in a negative.
* @param[in] clr Packed Pixel
* @param[in] n Amount of times to move bits to left.
* @return unsigned int Packed Pixel with newly moved bits
*/
unsigned int
u32_rotl(const unsigned int clr, const int n);
/**
* @brief Raises Color Vibrance
* @details Raises the vibrance by essentially raising specific channels higher
* and lowering others.
* @param[in] clr Packed Pixel
* @param[in] factor Floating point to raise or lower vibrance by.
* @return unsigned int Packed Pixel with one channel kept, includes alpha auto
*/
unsigned int
u32_contrast(const unsigned int clr, const float factor);
/**
* @brief Averages Red and Blue Channels for Green Channel
* @param[in] clr Packed Pixel
* @return unsigned int Packed Pixel with green pixel averaged
*/
unsigned int
u32_avg_gb(const unsigned int clr);
/**
* @brief Blurs image in a radiance with a box
* @details Uses 2 loops to scan from left to right; selecting a pixel and
* mixing all of the pixels from "radius" left to "radius" right and averaging
* them. Then it moves to the next pixel doing the same. Then it does the second
* loop from top to bottom doing the same principle. This can take some time
* depending on hardware, image size, radius, etc.
* @param[in] src_buf The image buffer to be blurred
* @param[in] img the PPM image container
* @param[in] radius The amount of pixels around the left and right, then top
* and bottom to mix with the currently selected pixel
* @return unsigned int Pointer to new created image buffer.
*/
unsigned int*
box_blur(const unsigned int* src_buf, const PPM* img, const int radius);
#endif