[KimDaBa] Red-eye removal

Jesper K. Pedersen blackie at blackie.dk
Mon Jan 10 20:36:24 CET 2005


Looks interesting, I'll have a look - eventually.
On Monday 10 January 2005 18:38, Martin Ehmsen wrote:
| * Franck COLLINEAU <franck-collineau at wanadoo.fr> [Jan 05. 2005 07:55]:
| > I think kimdaba developper team should meet digikam developper team
| > because digikam offers this feature.
| > Is it possible ?
|
| I had a look at the digikam code, and their red-eye removal is quiet
| easy, and could probably easily be implemented in Kimdaba (if Jesper
| think is should).
| The only thing that stops me from implementing it in Kimdaba is my
| lacking C++ and KDE programming skills.
|
| Here is the actual red-eye removal code from digikam (the file is called
| imageeffect_redeye.cpp):
| CODE_BEGIN:
| ...
| uint* data = iface.getSelectedData();
| int   w    = iface.selectedWidth();
| int   h    = iface.selectedHeight();
| ...
| uint* newData = new uint[w*h];
| memcpy(newData, data, w*h*sizeof(unsigned int));
|
| int   r,g,b,a;
|
| struct channel {
|     float red_gain;
|     float green_gain;
|     float blue_gain;
| };
| channel red_chan, green_chan, blue_chan;
|
| red_chan.red_gain   = 0.1;
| red_chan.green_gain = 0.6;
| red_chan.blue_gain  = 0.3;
|
| green_chan.red_gain   = 0.0;
| green_chan.green_gain = 1.0;
| green_chan.blue_gain  = 0.0;
|
| blue_chan.red_gain   = 0.0;
| blue_chan.green_gain = 0.0;
| blue_chan.blue_gain  = 1.0;
|
| float red_norm, green_norm, blue_norm;
|
| red_norm = 1.0/(red_chan.red_gain + red_chan.green_gain +
| red_chan.blue_gain); green_norm = 1.0/(green_chan.red_gain +
| green_chan.green_gain + green_chan.blue_gain); blue_norm =
| 1.0/(blue_chan.red_gain + blue_chan.green_gain + blue_chan.blue_gain);
|
| uint* ptr  = data;
| uint* nptr = newData;
|
| int r1, g1, b1;
|
| for (int i=0; i<w*h; i++) {
|     a = (*ptr >> 24) & 0xff;
|     r = (*ptr >> 16) & 0xff;
|     g = (*ptr >> 8)  & 0xff;
|     b = (*ptr)       & 0xff;
|
|     if ( r >= ( 2 * g) ) {
|         r1 = (int) QMIN(255, red_norm * (red_chan.red_gain   * r +
|                                    red_chan.green_gain * g +
|                                    red_chan.blue_gain  * b));
|         b1 = (int) QMIN(255, green_norm * (green_chan.red_gain   * r +
|                                      green_chan.green_gain * g +
|                                      green_chan.blue_gain  * b));
|         g1 = (int) QMIN(255, blue_norm * (blue_chan.red_gain   * r +
|                                     blue_chan.green_gain * g +
|                                     blue_chan.blue_gain  * b));
|         *nptr = QMIN(int((r-g)/150.0*255.0),255) << 24 | r1 << 16 | g1 << 8
| | b1; }
|     ptr++;
|     nptr++;
| }
| CODE_END.
|
| then newData contains the selected part of the orig. image without the
| red-eye.
|
| So what I would like is:
| 1. I open an image for viewing and zooms in on a red-eye.
| 2. I right-click on the image and from the menu chooses "Remove red-eye"
| 3. The above code is run on the zoomed in portion of the image, and the
|    result is displayed.
| 4. A dialog-box appears and asks: "Save", "Save to new", "Cancel"
| 5. The appropriate code is run depending on the users choice.
|
| I think it should be fairly straight forward for anyone knowing Kimdaba
| internals and QT/KDE to implement.
|
| Anyone have any thought about this? Jesper??
| Is this code too close to making Kimdaba an image manipulation
| software?!?
|
| Martin
|
| P.S. Sorry Franck.

-- 
Having trouble finding a given image in your collection containing
thousands of images?

http://ktown.kde.org/kimdaba might be the answer.



More information about the KimDaBa mailing list