Bug 122693 - improvement proposals for the "add border" tool
Summary: improvement proposals for the "add border" tool
Status: RESOLVED FIXED
Alias: None
Product: digikam
Classification: Applications
Component: Plugin-Editor-Border (show other bugs)
Version: unspecified
Platform: Gentoo Packages Linux
: NOR wishlist
Target Milestone: ---
Assignee: Digikam Developers
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-02-25 13:51 UTC by sero4linux
Modified: 2018-02-05 11:31 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In: 0.9.0
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description sero4linux 2006-02-25 13:51:01 UTC
Version:           0.9.0 (using KDE KDE 3.5.1)
Installed from:    Gentoo Packages
OS:                Linux

This should be a comment to
Bug 118535: Add Border: use percent to designate border size. However I was not able to comment to this bug cause bko complaint about invalid version the report was assignt to (0.8.8). So here is the text of the wish again:

It would be nice to be able to add a border to an image (or group of images in batch mode) with the size specified as a percentage of the image size.  This would provide a consistent looking border to a set of images which are different sizes. 
 


I second this wish, cause in this way one could realy get a consistent look.

However from my understanding, the border size should only be a percentage value in relation to ONE (e.g. the longer) side of a picture - and this value should be applied to both the long and the short side of the image, so that on both sides the borders have the same width.

Related is a second improvement for the plugin. I used the plugin to add a white border to some photos that I have trimmed to an aspect ratio 2:3 before. Unfortuntaly the borders were slightly cut when the images were print. The reason: the plugin puts the borders "around" the images, thus increasing its size slightly and producing an slight aspect ratio missmatch (if you put a 10px border around every edge, then the aspect ratio of a 2:3 landscape format photo gets slightly more in direction to a 2:3.1 format).

To fix this, please put the border "inside" the picture, not extending it but "overwriting" the content of the picture in the border area.

I hope I found the right English words for the problem - maybe this wishes can be taken into consideration when the border plugin is adjusted for digikam 0.9.x 16bit color space.

Thanks in advance!
Comment 1 caulier.gilles 2006-08-18 11:09:51 UTC
SVN commit 574137 by cgilles:

digikam from trunk: now, "Add Border" image editor tool use percent ratio of image to compute border 
size to add around the image. A new default keyboard shortcut have been add to this tool: Shift+B

CCMAIL: digikam-devel@kde.org
BUG: 118535
CCBUGS:122693
 


 M  +19 -21    border.cpp  
 M  +14 -16    border.h  
 M  +2 -2      digikamimageplugin_border_ui.rc  
 M  +40 -50    imageeffect_border.cpp  
 M  +1 -2      imageeffect_border.h  
 M  +0 -1      imageplugin_border.cpp  
 M  +0 -1      imageplugin_border.h  
Comment 2 caulier.gilles 2006-08-18 11:18:04 UTC
>It would be nice to be able to add a border to an image (or group of images >in batch mode) with the size specified as a percentage of the image size.  >This would provide a consistent looking border to a set of images which are >different sizes.

==> About _Batch mode_ this is releavant of another plugin from kipi-plugins not digiKam. Please make a new file in the right B.K.O area. Thanks in advance

Gilles Caulier
Comment 3 caulier.gilles 2006-08-18 11:30:36 UTC
Ok, now about aspect ratio preservation, this is my proposal:

1/ I'm not agree to put the border inside the image to preserve original aspect ratio. Typicaly, the workflow of a picture correction is following :

 1=> Aspect Ratio Crop tool using composition rule guide.
 2=> Add border around the cropped image.

If you add the border into the image without change the size, the composition rule used to crop the image will be destroyed.

2/ I'm agree to add a "preserve aspect ratio" checkbox option to tool settings. This is my proposal :

  1=> Continue to add the border using the current implementation (around the original image)
  2=> Adapt the target image size to respect the original aspect ratio.
  3=> Using a white color to fill the background.

Gilles Caulier
Comment 4 caulier.gilles 2006-08-19 15:31:38 UTC
SVN commit 574581 by cgilles:

digikam from trunk : "Add Border" image editor tool now respect aspect ratio of original image to render the decorative border. There is no new option in tool settings.
BUG: 122693

 M  +84 -60    border.cpp  
 M  +2 -0      border.h  


--- trunk/extragear/graphics/digikamimageplugins/border/border.cpp #574580:574581
@@ -27,10 +27,9 @@
 
 // Qt includes.
 
-#include <qpixmap.h>
-#include <qpainter.h>
-#include <qbrush.h>
-#include <qpen.h>
+#include <qpoint.h>
+#include <qregion.h>
+#include <qpointarray.h>
 
 // KDE includes.
 
@@ -56,6 +55,7 @@
 { 
     m_orgWidth        = orgWidth;
     m_orgHeight       = orgHeight;
+    m_orgRatio        = (float)m_orgWidth / (float)m_orgHeight;
     m_borderType      = borderType;
     m_borderPath      = borderPath;
     int size          = (image->width() > image->height()) ? image->height() : image->width();
@@ -119,13 +119,24 @@
 
 void Border::solid(Digikam::DImg &src, Digikam::DImg &dest, const Digikam::DColor &fg, int borderWidth)
 {
-    dest = Digikam::DImg(src.width() + borderWidth*2, src.height() + borderWidth*2, src.sixteenBit(), src.hasAlpha());
-    dest.fill(fg);
-    dest.bitBltImage(&src, borderWidth, borderWidth);
+    if (m_orgWidth > m_orgHeight)
+    {
+        int height = src.height() + borderWidth*2;
+        dest = Digikam::DImg((int)(height*m_orgRatio), height, src.sixteenBit(), src.hasAlpha());
+        dest.fill(fg);
+        dest.bitBltImage(&src, (dest.width()-src.width())/2, borderWidth);
+    }
+    else
+    {
+        int width = src.width() + borderWidth*2;
+        dest = Digikam::DImg(width, (int)(width/m_orgRatio), src.sixteenBit(), src.hasAlpha());
+        dest.fill(fg);
+        dest.bitBltImage(&src, borderWidth, (dest.height()-src.height())/2);
+    }
 }
 
-void Border::niepce(Digikam::DImg &src, Digikam::DImg &dest, const Digikam::DColor &fg, int borderWidth, 
-                                const Digikam::DColor &bg, int lineWidth)
+void Border::niepce(Digikam::DImg &src, Digikam::DImg &dest, const Digikam::DColor &fg, 
+                    int borderWidth, const Digikam::DColor &bg, int lineWidth)
 {
     Digikam::DImg tmp;
     solid(src, tmp, bg, lineWidth);
@@ -133,81 +144,94 @@
 }
 
 void Border::bevel(Digikam::DImg &src, Digikam::DImg &dest, const Digikam::DColor &topColor, 
-                               const Digikam::DColor &btmColor, int borderWidth)
+                   const Digikam::DColor &btmColor, int borderWidth)
 {
-    int x, y;
-    int wc;
+    int width, height;
 
-    dest = Digikam::DImg(src.width() + borderWidth*2, src.height() + borderWidth*2, src.sixteenBit(), src.hasAlpha());
-
-    // top
-
-    for(y=0, wc = (int)dest.width()-1; y < borderWidth; ++y, --wc)
+    if (m_orgWidth > m_orgHeight)
     {
-        for(x=0; x < wc; ++x)
-            dest.setPixelColor(x, y, topColor);
-
-        for(;x < (int)dest.width(); ++x)
-            dest.setPixelColor(x, y, btmColor);
+        height = src.height() + borderWidth*2;
+        width  = (int)(height*m_orgRatio);
     }
+    else
+    {
+        width  = src.width() + borderWidth*2;
+        height = (int)(width/m_orgRatio);
+    }
 
-    // left and right
+    dest = Digikam::DImg(width, height, src.sixteenBit(), src.hasAlpha());
+    dest.fill(topColor);
 
-    for(; y < (int)dest.height()-borderWidth; ++y)
+    QPointArray btTriangle(3);
+    btTriangle.setPoint(0, width, 0);
+    btTriangle.setPoint(1, 0, height);
+    btTriangle.setPoint(2, width, height);
+    QRegion btRegion(btTriangle);
+
+    for(int x=0 ; x < width ; x++)
     {
-       for(x=0; x < borderWidth; ++x)
-           dest.setPixelColor(x, y, topColor);
-
-       for(x = (int)dest.width()-1; x > (int)dest.width()-borderWidth-1; --x)
-           dest.setPixelColor(x, y, btmColor);
+        for(int y=0 ; y < height ; y++)
+        {
+            if (btRegion.contains(QPoint(x, y)))
+                dest.setPixelColor(x, y, btmColor);
+        }
     }
 
-    // bottom
-
-    for(wc = borderWidth; y < (int)dest.height(); ++y, --wc)
+    if (m_orgWidth > m_orgHeight)
     {
-       for(x=0; x < wc; ++x)
-           dest.setPixelColor(x, y, topColor);
-
-       for(; x < (int)dest.width(); ++x)
-           dest.setPixelColor(x, y, btmColor);
+        dest.bitBltImage(&src, (dest.width()-src.width())/2, borderWidth);
     }
-
-    dest.bitBltImage(&src, borderWidth, borderWidth);
+    else
+    {
+        dest.bitBltImage(&src, borderWidth, (dest.height()-src.height())/2);
+    }
 }
 
 void Border::pattern(Digikam::DImg &src, Digikam::DImg &dest, int borderWidth,
                      const Digikam::DColor &firstColor, const Digikam::DColor &secondColor, 
                      int firstWidth, int secondWidth)
 {
-    // Border tile.
+    // Original image with the first solid border around.
+    Digikam::DImg tmp; 
+    solid(src, tmp, firstColor, firstWidth);
+  
+    // Border tiled image using pattern with second solid border around.
+    int width, height;
 
-    int w = m_orgWidth + borderWidth*2;
-    int h = m_orgHeight + borderWidth*2;
+    if (m_orgWidth > m_orgHeight)
+    {
+        height = tmp.height() + borderWidth*2;
+        width  = (int)(height*m_orgRatio);
+    }
+    else
+    {
+        width  = tmp.width() + borderWidth*2;
+        height = (int)(width/m_orgRatio);
+    }
+
+    Digikam::DImg tmp2(width, height, tmp.sixteenBit(), tmp.hasAlpha());
     kdDebug() << "Border File:" << m_borderPath << endl;
     Digikam::DImg border(m_borderPath);
     if ( border.isNull() )
         return;
+    
+    border.convertToDepthOfImage(&tmp2);
 
-    Digikam::DImg borderImg(w, h, src.sixteenBit(), src.hasAlpha());
-    border.convertToDepthOfImage(&borderImg);
+    for (int x = 0 ; x < width ; x+=border.width())
+        for (int y = 0 ; y < height ; y+=border.height())
+            tmp2.bitBltImage(&border, x, y);
+      
+    solid(tmp2, dest, secondColor, secondWidth);
 
-    for (int x = 0 ; x < w ; x+=border.width())
-        for (int y = 0 ; y < h ; y+=border.height())
-            borderImg.bitBltImage(&border, x, y);
-
-    // First line around the pattern tile.
-    Digikam::DImg tmp = borderImg.smoothScale( src.width() + borderWidth*2,
-                                                src.height() + borderWidth*2 );
-
-    solid(tmp, dest, firstColor, firstWidth);
-
-    // Second line around original image.
-    tmp.reset();
-    solid(src, tmp, secondColor, secondWidth);
-
-    // Copy original image.
-    dest.bitBltImage(&tmp, borderWidth, borderWidth);
+    // Merge both images to one.
+    if (m_orgWidth > m_orgHeight)
+    {
+        dest.bitBltImage(&tmp, (dest.width()-tmp.width())/2, borderWidth);
+    }
+    else
+    {
+        dest.bitBltImage(&tmp, borderWidth, (dest.height()-tmp.height())/2);
+    }
 }
 
 }  // NameSpace DigikamBorderImagesPlugin
--- trunk/extragear/graphics/digikamimageplugins/border/border.h #574580:574581
@@ -87,6 +87,8 @@
     int     m_borderMainWidth;
     int     m_border2ndWidth;
 
+    float   m_orgRatio;
+
     QString m_borderPath;
     
     Digikam::DColor m_solidColor;