#Buffer overrun issues when tinting image

6 messages · Page 1 of 1 (latest)

alpine latch
#

in this code I am using a custom engine with its own image and color data types. I am trying to loop through an images pixel data and adjust each pixel like a tint. My current code gives errors and won't compile

CP_Image tintImage(CP_Image image, int red, int green, int blue) {
    // the color we will be tinting the image with
    CP_Color colorToApplyTint = CP_Color_Create(red, green, blue, 127);
    // the array of pixel data spots
    int arraySize = CP_Image_GetWidth(image) * CP_Image_GetHeight(image);
    // allocate the array memory
    CP_Color* colorArray = malloc(arraySize * sizeof(CP_Color));
    // get image pixel data and put it into the address of the color array
    CP_Image_GetPixelData(image, colorArray);
    // iterate through each pixel
    for (int i = 0; i < arraySize; ++i) {
        // if pixel is not transparent, overlay the tinted color
        if (colorArray[i].a > 0) { // error
            colorArray[i] = colorToApplyTint; // error
        }
    }
    // Put the altered pixel data into a new CP_Image we will return
    CP_Image img = image;
    CP_Image_UpdatePixelData(img, colorArray);
    // Free the array memory
    free(colorArray);
    // finally return the altered image
    return img;
}
acoustic bloomBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.

alpine latch
#
dereferencing null pointer from colorArray
reading invalid data from colorArray
butter over run while writing to colorArray
alpine latch
#

I made this code change to fix the error, but it still isn't tinting the image

acoustic bloomBOT
#

This question thread is being automatically closed. If your question is not answered feel free to bump the post or re-ask. Take a look at !howto ask for tips on improving your question.