I need to write a little tool that gives a list (x,y) of pixels in a png file that are not white. I did this in java, but because of the high footprint, I'd like to redo it in C/C++. I have a little experience with this languages, but none with libpng (I assumed this was the way to go).
So what I basically want to do is loop through each pixel in a PNG file and check the color. What would be the best way to do that with libpng?
a list (x,y) of pixels in a png file that are not white.
You'll get no help from us on this blatant apartheid policy.
Take your racism elsewhere.
Name:
Anonymous2011-09-10 14:38
>>1
Use libpng to decompress the PNG image into a 32-bit RGBA buffer with a given stride, and then iterate through every pixel such that you compute the x and y coordinate at every iteration:
struct coord2
{
int x;
int y;
coord2() { }
coord2(int a, int b) : x(a), y(b) { }
};
std::vector<coord2> results;
uint32_t* buffer = ...; // initialize with data from libpng
for (int y = 0; y < height; ++y) {
for (int x = 0; x < width; ++x) {
uint32_t pixel = buffer[(y * stride) + x];
if (is_match(pixel)) {
results.push_back(coord2(x, y));
}
}
}
Name:
Anonymous2011-09-10 14:45
>>4
I am so sorry. I'd like to loop through all pixels and treat them equally.
Hell, even I could figure out how it worked! Much better than the crappy C API!
Name:
Anonymous2011-09-10 18:54
>>12
The C++ bindings are shitty because they use global operator new/delete, which makes them useless for serious software development. libpng lets you provide your own malloc/free functions via hooks.
"cout" with "endl" is the silliest shit.
operator overloading is stupid except for linear algebra.
exceptions needin a class seems silly.
Bone-headed shit.
I guess "new" is useful. In LoseThos is haven't implemented it and just use malloc in an initialization routine. That's pretty-much just as good.
God says...
Line: 8562
36:2 And Moses called Bezaleel and Aholiab, and every wise hearted
man, in whose heart the LORD had put wisdom, even every one whose
heart stirred him up to come unto the work to do it: 36:3 And they
received of Moses all the offering, which the children of Israel had
brought for the work of the service of the sanctuary, to make it
withal. And they brought yet unto him free offerings every morning.
36:4 And all the wise men, that wrought all the work of the sanctuary,
came every man from his work which they made; 36:5 And they spake unto
Moses, saying, The people bring much more than enough for the service
of the work, which the LORD commanded to make.
pngtest.c, which is part of the libpng distribution, has example call-back functions, one of which counts black pixels -- you could easily modify it to count pixels of another color.