BRL-CAD

Implement a small utility in C/C++ that counts the colors in an image

The goal of this task is to implement an application that reads in an image file and reports back a count for all unique RGB colors. In fact, there's a tool in BRL-CAD that does exactly this already. If you have BRL-CAD compiled, you can run pixcount from the build directory:

bin/pixcount share/pix/moss.pix
  0   0   1  149586
  0   1   0  1
  1   1   0  2
  1   2   1  4
  1   3   1  3
  ...

The first three numbers are the R G B values, the fourth number is the count. You can find the source code to that tool in a BRL-CAD's source checkout at src/util/pixcount.cpp and that's what we want you to implement in C/C++. I'm sure you're wondering, why??

It's because that small 200-line tool's implementation uses a red-black tree container that we'd like to get rid of. Before we can get rid of it, we need to rewrite tools like pixcount to not use it.

In terms of re-writing pixcount, the easiest possibility if you know C++ is probably to use a std::map with an RGBA value as an int32_t index. You're welcome to use the existing code as a base, particularly for argument handling and reading .pix file data into memory. If you edit the file directly, you'll be able to run "svn diff > yourfile.patch" to create a file that we can easily review and test (see https://brlcad.org/wiki/Patches).

SUBMIT a rewrite of pixcount in C or C++ that preserves the same usage and output behavior without using the bu_rb interface.

Task tags

  • pixel data
  • computer graphics
  • image processing
  • c/c++

Students who completed this task

Jebbly

Task type

  • code Code
close

2019