-
Notifications
You must be signed in to change notification settings - Fork 0
Image
This section contains all functions relating to CP_Image.
- CP_Image_Load
- CP_Image_Free
- CP_Image_GetWidth
- CP_Image_GetHeight
- CP_Image_Draw
- CP_Image_DrawAdvanced
- CP_Image_DrawSubImage
- CP_Image_CreateFromData
- CP_Image_Screenshot
- CP_Image_GetPixelData
- CP_Image_UpdatePixelData
Load a CP_Image by inputting the file path of the image file as a string (const char*). When finished, the image should be released using CP_Image_Free.
CP_Image CP_Image_Load(const char* filepath);
- filepath (const char*) - The path to the image file that you want to load.
- CP_Image - The new image created from the specified file. Will be NULL if the image could not be created.
CP_Image justinFace = NULL;
void init()
{
justinFace = CP_Image_Load("./Assets/Justins_face.png");
}
void update()
{
CP_Graphics_ClearBackground(CP_Color_Create(255, 255, 255, 255));
int width = CP_System_GetWindowWidth();
int height = CP_System_GetWindowHeight();
CP_Image_Draw(justinFace, width / 2, height / 2, width / 2, width / 2, 255);
}
void shutdown()
{
CP_Image_Free(&justinFace);
}
- CP_Image
- CP_Image_Draw
- CP_Image_Free
- CP_Graphics_ClearBackground
- CP_Color_Create
- CP_System_GetWindowWidth
- CP_System_GetWindowHeight
Free a CP_Image by giving the image that you want to free.
void CP_Image_Free(CP_Image* img);
- image (CP_Image) - The image that you want to free.
This function does not return anything.
CP_Image justinFace = NULL;
void init()
{
justinFace = CP_Image_Load("./Assets/Justins_face.png");
}
void update()
{
CP_Graphics_ClearBackground(CP_Color_Create(255, 255, 255, 255));
int width = CP_System_GetWindowWidth();
int height = CP_System_GetWindowHeight();
CP_Image_Draw(justinFace, width / 2, height / 2, width / 2, width / 2, 255);
}
void shutdown()
{
CP_Image_Free(&justinFace);
}
- CP_Image
- CP_Image_Draw
- CP_Image_Load
- CP_Graphics_ClearBackground
- CP_Color_Create
- CP_System_GetWindowWidth
- CP_System_GetWindowHeight
Get the width in pixels of a given CP_Image.
int CP_Image_GetWidth(CP_Image img);
- image (CP_Image) - The image that you want to know the width of.
- int - The width of the image in pixels.
CP_Image justinFace = NULL;
void init()
{
justinFace = CP_Image_Load("./Assets/Justins_face.png");
}
void update()
{
CP_Graphics_ClearBackground(CP_Color_Create(255, 255, 255, 255));
int width = CP_Image_GetWidth(justinFace);
int windowWidth = CP_System_GetWindowWidth();
int windowHeight = CP_System_GetWindowHeight();
CP_Image_Draw(justinFace, windowWidth / 2, windowHeight / 2, windowWidth / 2, windowHeight / 2, 255);
}
void shutdown()
{
CP_Image_Free(&justinFace);
}
- CP_Image
- CP_Image_Load
- CP_Image_Draw
- CP_Image_Free
- CP_Graphics_ClearBackground
- CP_Color_Create
- CP_System_GetWindowWidth
- CP_System_GetWindowHeight
Get the height in pixels of a given CP_Image.
int CP_Image_GetHeight(CP_Image img);
- image (CP_Image) - The image that you want to know the height of.
- int - The height of the image in pixels.
CP_Image justinFace = NULL;
void init()
{
justinFace = CP_Image_Load("./Assets/Justins_face.png");
}
void update()
{
CP_Graphics_ClearBackground(CP_Color_Create(255, 255, 255, 255));
int height = CP_Image_GetHeight(justinFace);
int windowWidth = CP_System_GetWindowWidth();
int windowHeight = CP_System_GetWindowHeight();
CP_Image_Draw(justinFace, windowWidth / 2, windowHeight / 2, windowWidth / 2, windowHeight / 2, 255);
}
void shutdown()
{
CP_Image_Free(&justinFace);
}
- CP_Image
- CP_Image_Load
- CP_Image_Draw
- CP_Image_Free
- CP_Graphics_ClearBackground
- CP_Color_Create
- CP_System_GetWindowWidth
- CP_System_GetWindowHeight
Draws a given CP_Image to the screen using the given size and coordinates.
void CP_Image_Draw(CP_Image img, float x, float y, float w, float h, int alpha);
- image (CP_Image) - The image that you want to draw to the screen.
- x (float) - The x coordinate of the image in screen coordinates.
- y (float) - The y coordinate of the image in screen coordinates.
- w (float) - The width to draw the image in pixels.
- h (float) - The height to draw the image in pixels.
- alpha (float) - The alpha value to draw the image with (0-255).
This function does not return anything.
CP_Image justinFace = NULL;
void init()
{
justinFace = CP_Image_Load("./Assets/Justins_face.png");
}
void update()
{
CP_Graphics_ClearBackground(CP_Color_Create(255, 255, 255, 255));
int width = CP_System_GetWindowWidth();
int height = CP_System_GetWindowHeight();
CP_Image_Draw(justinFace, width / 2, height / 2, width / 2, width / 2, 255);
}
void shutdown()
{
CP_Image_Free(&justinFace);
}
- CP_Image
- CP_Image_Load
- CP_Image_Free
- CP_Graphics_ClearBackground
- CP_Color_Create
- CP_System_GetWindowWidth
- CP_System_GetWindowHeight
Draws a given CP_Image to the screen using the given position, size, alpha, and rotation.
void CP_Image_DrawAdvanced(CP_Image img, float x, float y, float w, float h, int alpha, float degrees);
- image (CP_Image) - The image that you want to draw to the screen.
- x (float) - The x coordinate of the image in screen coordinates.
- y (float) - The y coordinate of the image in screen coordinates.
- w (float) - The width to draw the image in pixels.
- h (float) - The height to draw the image in pixels.
- alpha (float) - The alpha value to draw the image with (0-255).
- degrees (float) - The degrees to rotate the image.
This function does not return anything.
CP_Image justinFace = NULL;
void init()
{
justinFace = CP_Image_Load("./Assets/Justins_face.png");
}
void update()
{
CP_Graphics_ClearBackground(CP_Color_Create(255, 255, 255, 255));
int width = CP_System_GetWindowWidth();
int height = CP_System_GetWindowHeight();
CP_Image_DrawAdvanced(justinFace, width / 2, height / 2, width / 2, width / 2, 255, 180);
}
void shutdown()
{
CP_Image_Free(&justinFace);
}
- CP_Image
- CP_Image_Load
- CP_Image_Free
- CP_Graphics_ClearBackground
- CP_Color_Create
- CP_System_GetWindowWidth
- CP_System_GetWindowHeight
Draws a given CP_Image to the screen using the given position, size, texture coordinates, and alpha.
void CP_Image_DrawSubImage(CP_Image img, float x, float y, float w, float h, float u0, float v0, float u1, float v1, int alpha);
- image (CP_Image) - The image that you want to draw to the screen.
- x (float) - The x coordinate of the image in screen coordinates.
- y (float) - The y coordinate of the image in screen coordinates.
- w (float) - The width to draw the image in pixels.
- h (float) - The height to draw the image in pixels.
- s0 (float) - The left most pixel of the sub-image(far left = 0).
- t0 (float) - The top most pixel of the sub-image (top = 0).
- s1 (float) - The right most pixel for the sub-image (far right = image width).
- t0 (float) - The bottom most pixel for the sub-image (bottom = image height).
- alpha (float) - The alpha value to draw the image with (0-255).
This function does not return anything.
CP_Image justinFace = NULL;
void init()
{
justinFace = CP_Image_Load("./Assets/Justins_face.png");
}
void update()
{
CP_Graphics_ClearBackground(CP_Color_Create(255, 255, 255, 255));
int width = CP_System_GetWindowWidth();
int height = CP_System_GetWindowHeight();
int imageWidth = CP_Image_GetWidth(justinFace);
int imageHeight = CP_Image_GetHeight(justinFace);
// draws the top left quarter of the image
CP_Image_DrawSubImage(justinFace, (width / 2), (height / 2), width, height, 0, 0, imageWidth / 2, imageHeight / 2, 255);
}
void shutdown()
{
CP_Image_Free(&justinFace);
}
- CP_Image
- CP_Image_GetWidth
- CP_Image_GetHeight
- CP_Image_Load
- CP_Image_Free
- CP_Graphics_ClearBackground
- CP_Color_Create
- CP_System_GetWindowWidth
- CP_System_GetWindowHeight
Creates a CP_Image from the given data.
CP_Image CP_Image_CreateFromData(int w, int h, unsigned char* pixelDataInput);
- w (int) - The width you want the created image to be (must correspond to the size of the data given).
- h (int) - The height you want the created image to be (must correspond to the size of the data given).
- pixelDataInput (unsigned char*) - The data to use to create the new image.
CP_Image justinFace = NULL;
void init()
{
unsigned char pixelData[] = {
255, 0, 0, 255, 255, 0, 0, 255, // 2 red pixels
0, 0, 255, 255, 0, 0, 255, 255 // 2 blue pixels
};
justinFace = CP_Image_CreateFromData(2, 2, pixelData);
}
void update()
{
CP_Graphics_ClearBackground(CP_Color_Create(255, 255, 255, 255));
int width = CP_System_GetWindowWidth();
int height = CP_System_GetWindowHeight();
// draws the top left quarter of the image
CP_Image_Draw(justinFace, width / 2, height / 2, width, height, 255);
}
void shutdown()
{
CP_Image_Free(&justinFace);
}
- CP_Image_Draw
- CP_Image_Free
- CP_Graphics_ClearBackground
- CP_Color_Create
- CP_System_GetWindowWidth
- CP_System_GetWindowHeight
This function will capture an area of the screen and return it as a CP_Image.
CP_Image CP_Image_Screenshot(int x, int y, int w, int h);
- x (int) - The X coordinate of the top left corner of the screen area to be captured.
- y (int) - The Y coordinate of the top left corner of the screen area to be captured.
- w (int) - The width of the screen area to be captured.
- h (int) - The height of the screen area to be captured.
void update()
{
if (CP_Input_KeyTriggered(KEY_S))
{
int windowWidth = CP_System_GetWindowWidth();
int windowHeight = CP_System_GetWindowHeight();
// Take a screenshot of the entire window
CP_Image screenshot = CP_Image_Screenshot(0, 0, windowWidth, windowHeight);
}
}
This function allows you to get an array of CP_Color variables that correspond to the pixels in a CP_Image. You must create and delete the array yourself, and its length must be the same as the number of pixels in the image (in other words, the image width times the image height).
void CP_Image_GetPixelData(CP_Image img, CP_Color* pixelDataOutput);
- img (CP_Image) - The image to get the pixel data from.
- pixelDataOutput (CP_Color*) - This CP_Color array will be filled with the color data from the image.
This function does not return anything.
CP_Image myImage;
void init()
{
// Load an image
myImage = CP_Image_Load("./Assets/Tree.png");
// Get the size of the array using the image width and height
int arraySize = CP_Image_GetWidth(myImage) * CP_Image_GetHeight(myImage);
// Create the array using the image size and the size of a CP_Color
CP_Color* colorArray = malloc(arraySize * sizeof(CP_Color));
// Get the array of pixel colors from the image
CP_Image_GetPixelData(myImage, colorArray);
// If any pixel is not transparent, set it to red
CP_Color red = CP_Color_Create(255, 0, 0, 255);
for (int i = 0; i < arraySize; ++i)
{
if (colorArray[i].a > 0)
{
colorArray[i] = red;
}
}
// Update the image with the altered pixels
CP_Image_UpdatePixelData(myImage, colorArray);
// Free the array memory
free(colorArray);
}
void update()
{
CP_Image_Draw(myImage, 50, 100, 100, 200, 255);
}
- CP_Image
- CP_Color
- CP_Image_Load
- CP_Image_GetWidth
- CP_Image_GetHeight
- CP_Image_UpdatePixelData
- CP_Image_Draw
This function will replace the current pixel data in the image with the data in the array which is passed into the function. Make sure the array is at least as big as the number of pixels in the image!
void CP_Image_UpdatePixelData(CP_Image img, CP_Color* pixelDataInput);
- img (CP_Image) - The image to copy the pixel data into.
- pixelDataInput (CP_Color*) - A CP_Color array that will be used to change the image pixels.
This function does not return anything.
CP_Image myImage;
void init()
{
// Load an image
myImage = CP_Image_Load("./Assets/Tree.png");
// Get the size of the array using the image width and height
int arraySize = CP_Image_GetWidth(myImage) * CP_Image_GetHeight(myImage);
// Create the array using the image size and the size of a CP_Color
CP_Color* colorArray = malloc(arraySize * sizeof(CP_Color));
// Get the array of pixel colors from the image
CP_Image_GetPixelData(myImage, colorArray);
// If any pixel is not transparent, set it to red
CP_Color red = CP_Color_Create(255, 0, 0, 255);
for (int i = 0; i < arraySize; ++i)
{
if (colorArray[i].a > 0)
{
colorArray[i] = red;
}
}
// Update the image with the altered pixels
CP_Image_UpdatePixelData(myImage, colorArray);
// Free the array memory
free(colorArray);
}
void update()
{
CP_Image_Draw(myImage, 50, 100, 100, 200, 255);
}