Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | Download | RSS feed

  1. --BRUSH Remap: Apply PenColor
  2. --by Richard Fhager
  3. --http://hem.fyristorg.com/dawnbringer/
  4.  
  5. -- Copyright 2010 Richard Fhager
  6. --
  7. -- This program is free software; you can redistribute it and/or
  8. -- modify it under the terms of the GNU General Public License
  9. -- as published by the Free Software Foundation; version 2
  10. -- of the License. See <http://www.gnu.org/licenses/>
  11.  
  12. run("../libs/dawnbringer_lib.lua")
  13.  
  14. OK,tin,clz,fade,amt,brikeep,falloff,nobg,nopen,briweight   = inputbox("Apply PenColor 2 Brush",
  15.                        
  16.                            "1. Tint",               1,  0,1,-1,
  17.                            "2. Colorize",           0,  0,1,-1,
  18.                            "BG->FG color Fade", 0,  0,1,0,
  19.                            "AMOUNT % (0-100)", 100,  0,100,0,  
  20.                            "Preserve Brightness", 1,  0,1,0,
  21.                            "Bri/Dark FallOff", 1,  0,1,0,
  22.                            "Exclude Background",     1,0,1,0,
  23.                            "Exclude PenColor",       0,0,1,0,
  24.                            "ColMatch Bri-Weight %", 25,  0,100,0                                                    
  25. );
  26.  
  27.  
  28. if OK == true then
  29.  
  30.  function cap(v) return math.min(255,math.max(v,0)); end
  31.  
  32.  w, h = getbrushsize()
  33.  
  34.  
  35.  fg = getforecolor()
  36.  bg = getbackcolor()
  37.  fR,fG,fB = getcolor(fg)
  38.  bR,bG,bB = getcolor(bg)
  39.  
  40.  pal = db.fixPalette(db.makePalList(256))
  41.  if nobg == 1 then
  42.   pal = db.stripIndexFromPalList(pal,bg) -- Remove background color from pallist
  43.  end
  44.  if nopen == 1 then
  45.   pal = db.stripIndexFromPalList(pal,fg) -- Remove  Pencolor from pallist
  46.  end
  47.  
  48.  
  49.  amtA = amt / 100
  50.  amtR = 1 - amtA
  51.  
  52.   -- Normalize Pen Color
  53.   lev = (fR+fG+fB)/3
  54.   fR = fR - lev
  55.   fG = fG - lev
  56.   fB = fB - lev
  57.  
  58.  ---------------------------------------------------
  59.  -- Colorize (Colourant) (just apply colorbalance)
  60.  -- Tint (make grayscale and apply colorbalance)
  61.  --
  62.  -- I think it should be the other way around since colorize is the process of adding color to B&W film...
  63.  -- But this is the what Brilliance and others call it
  64.  --
  65.  if clz == 1 or tin == 1 then
  66.   cols = {}
  67.   for n = 0, 255, 1 do
  68.  
  69.   r,g,b = getcolor(n)
  70.   a = db.getBrightness(r,g,b)
  71.  
  72.    
  73.   mR,mG,mB = fR,fG,fB
  74.  
  75.   -- Fade between bg & fg pencolor across dark-bright
  76.   if fade == 1 then
  77.     lf = a / 255
  78.     lr = 1 - lf
  79.     mR = bR*lr + fR*lf
  80.     mG = bG*lr + fG*lf
  81.     mB = bB*lr + fB*lf
  82.     lev = (mR+mG+mB)/3
  83.     mR = mR - lev
  84.     mG = mG - lev
  85.     mB = mB - lev
  86.   end  
  87.  
  88.   fr,fg,fb = mR,mG,mB
  89.  
  90.  
  91.      if brikeep == 1 then
  92.        -- Loose Brightness preservation (ex: applying full red to dark colors)
  93.        brin = db.getBrightness(cap(r+mR),cap(g+mG),cap(b+mB))
  94.        itot = brin - a
  95.        fr = mR - itot
  96.        fg = mG - itot
  97.        fb = mB - itot
  98.      end
  99.  
  100.      -- Falloff (Effect weakens at dark and bright colors)
  101.      if falloff == 1 then
  102.       fo =  1 - math.abs((a - 127.5)/127.5)^2
  103.       fr = fr * fo
  104.       fg = fg * fo
  105.       fb = fb * fo
  106.      end
  107.  
  108.      if tin == 1 then
  109.       --cols[n+1] = matchcolor((a+fr)*amtA + r*amtR, (a+fg)*amtA + g*amtR, (a+fb)*amtA + b*amtR)
  110.       cols[n+1] = db.getBestPalMatchHYBRID({(a+fr)*amtA+r*amtR, (a+fg)*amtA + g*amtR, (a+fb)*amtA + b*amtR},pal,briweight / 100,true)
  111.      end
  112.      if clz == 1 then
  113.       --cols[n+1] = matchcolor((r+fr)*amtA + r*amtR, (g+fg)*amtA + g*amtR, (b+fb)*amtA + b*amtR)
  114.       cols[n+1] = db.getBestPalMatchHYBRID({(r+fr)*amtA+r*amtR, (g+fg)*amtA + g*amtR, (b+fb)*amtA + b*amtR},pal,briweight / 100,true)
  115.      end
  116.   end
  117.  
  118.   if nobg == 1 then cols[getbackcolor()+1] = getbackcolor(); end
  119.  
  120.   for x = 0, w - 1, 1 do
  121.    for y = 0, h - 1, 1 do
  122.     putbrushpixel(x, y, cols[getbrushpixel(x,y) + 1]);
  123.   end
  124.  end
  125. end;
  126. -- eof Colorize & Tint
  127. --------------------------------------------------------
  128.  
  129. end -- OK
  130.