So I'm using the median cut algorithm (sample found here) which reads a .raw image into Points. The actual reading in is done here: Median Cut Algorithm
medianCutPoints = new QList< QList<int>* >();
FILE * raw_in;
int numPoints = 617*800;
Point* points = (Point*)malloc(sizeof(Point) * numPoints);
raw_in = fopen("C:\\Users\\David\\Desktop\\image.raw", "rb");
for(int i = 0; i < numPoints; i++)
{
fread(&points[i], 3, 1, raw_in);
}
fclose(raw_in);
Then, the palette is generated via the algorithm..
std::list<Point> palette =
medianCut(points, numPoints, 15);
and finally, I store the points into a list.
for (iter = palette.begin() ; iter != palette.end(); iter++)
{
medianCutPoints->append(new QList<int>());
medianCutPoints->last()->append((int)iter->x[0]);
medianCutPoints->last()->append((int)iter->x[1]);
medianCutPoints->last()->append((int)iter->x[2]);
}
However, this only seems to work for a .raw, as there's no compressing going on as in a jpeg or png. If I feed in a jpg/png, the colors are greatly off from what they should be. This essentially is leaving me to only two options I can think of - use jpg and png libraries to decode the image into a .raw, or somehow read in each pixel of a compressed image into Points.
I'm having trouble understanding how the first loop works. I'm used to C#.NET, so how exactly is fread working, and how is Point* points setup? If I print out points[width*height].x[0], I get a number from the RGB code. But if I also do points[0].x[width*height], I still get a number. I figured this would be points[numberOfpoints].x[0-2], x being 3 spots for RGB.
Is there a way I can set Point* points to each pixel from a jpg/png as fread is doing with a .raw? With Qt being my first real venture into c++, this is a bit more complex than what I can comprehend, and I haven't had much luck searching for how exactly this is working.