r/programmingquestions • u/Plane_Assignment9080 • Jun 15 '23
Am I missing something?
I am writing code in C++ to fill a region to a certain color in an Image. For some unknown reason the color value that I give to memset doesn't give expected results. I gave the function the color, 0xff000000 and it sets the memory to 0x00000000. I have no idea why memset just gets rid of the alpha value. Any help will be appreciated:
void Image::FillQuadrant(Quadrant quad, u32 color)
{
const size_t bytes = sizeof(u32) * quad.Width;
const u32 yEnd = quad.y + quad.Height;
printf("Quadrant{ %hu, %hu, %hu, %hu }\n", quad.x, quad.y, quad.Width, quad.Height);
printf("Size: %lu bytes\n", bytes);
printf("Color: 0x%x\n", color);
u32* offset = &m_Data[quad.x];
for (u32 y = quad.y; y < yEnd; y++)
{
memset(offset + y * m_Width, color, bytes);
}
}
View all comments
Show parent comment
1
u/Plane_Assignment9080 Jun 16 '23
The Quadrant struct is more so to define the region. So I don't really want to modify the quadrant, but rather the area of the image defined by the quadrant