jargon

Advanced freeBASIC Composite Layer Video Routines 0x003

Jun 17th, 2013
388
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. 'clv003.bas
  2. 'Advanced freeBASIC Composite Layer Video Routines 0x003
  3. 'Created August 15th - May 6th 2010 by Timothy Robert Keal alias jargon
  4. 'Released under the Gnu Public License 2.0
  5. '
  6. 'http://retromachineshop.com/
  7. 'irc://chat.freenode.net/puzzlum
  8. '
  9. 'Please review the Gnu Public License, Thank you.
  10. 'The GPL can be located online at http://www.gnu.org/copyleft/gpl.html
  11. #include once "fbgfx.bi"
  12. #include once "inc\fbpng.bi"
  13. #include once "inc\png_image.bi"
  14.     declare sub clv_buffer_ini(clv_buffer() as fb.image ptr, Screen_Width as integer, Screen_Height as integer)
  15.     declare sub clv_font_load (clv_font() as fb.image ptr, FontIndex as integer, Switch as integer, Filename as string)
  16.     declare sub clv_draw_text (clv_buffer() as fb.image ptr, clv_font() as fb.image ptr, PageIndex as integer, clv_glyph() as integer, X as integer, Y as integer, Value as string)
  17.     declare sub clv_buffer_cls(clv_buffer() as fb.image ptr, PageIndex as integer)
  18.     declare sub clv_buffer_copy(clv_buffer() as fb.image ptr, SrcIndex as integer, DestIndex as integer)
  19.     declare sub clv_buffer_overlay(clv_buffer() as fb.image ptr, SrcIndex as integer, DestIndex as integer)
  20.     declare sub clv_buffer_flip(clv_buffer() as fb.image ptr, PageIndex as integer, Display_Width as integer, Display_Height as integer)
  21.     declare sub clv_draw_line(clv_buffer() as fb.image ptr, PageIndex as integer, X1 as integer, Y1 as integer, X2 as integer, Y2 as integer, ColorMask as uinteger, TransparencyMask as uinteger, Gfx_Method as integer)
  22.     declare sub clv_draw_pixel(clv_buffer() as fb.image ptr, PageIndex as integer, X as integer, Y as integer, ColorMask as uinteger, TransparencyMask as uinteger)
  23.     declare sub clv_draw_image(clv_buffer() as fb.image ptr, PageIndex as integer, X as integer, Y as integer, ColorGraphic as fb.image ptr, TransparencyGraphic as fb.image ptr)
  24.     declare function clv_filter_mask (SRC as uinteger, DST as uinteger, PARM as any ptr) as uinteger  
  25.     declare sub clv_draw_primitive_circle(Buffer as fb.image ptr, X1 as double, Y1 as double, X2 as double, Y2 as double, A1 as double, A2 as double, R1 as double, R2 as double, argb32_inner as uinteger, argb32_outer as uinteger, argb32_clockwise as uinteger, argb32_counterclockwise as uinteger)
  26.     declare sub clv_draw_primitive_triangle(clv_buffer() as fb.image ptr, PageIndex as integer, X1 as double, Y1 as double, X2 as double, Y2 as double, X3 as double, Y3 as double, ColorMask as uinteger, TransparencyMask as uinteger, Center_X as double, Center_Y as double)
  27.     declare function clv_math_vector2decimal (X1 as double, Y1 as double, X2 as double, Y2 as double) as double
  28.     declare function clv_argb32_mix(argb32() as uinteger, weight() as double) as uinteger
  29.     redim shared as integer clv_glyph(&H00 to &HFF, 0 to 1)
  30.     redim shared as fb.image ptr clv_font(&H00 to &HFF), clv_buffer(0 to 15, 0 to 1)
  31.     dim shared as integer clv_buffer_focus
  32.     const clv_math_Pi = 3.141592653589793#
  33.     const clv_flag_and=&HFFFFFFFF, clv_flag_or=&H00000000
  34.     const clv_buffer_visible=0, clv_buffer_draw=1
  35.     const clv_flag_default=0, clv_flag_b=1, clv_flag_bf=2
  36.     const clv_font_default=0
  37.     const clv_font_flag_load=1, clv_font_flag_destroy=2
  38. sub clv_buffer_ini(clv_buffer() as fb.image ptr, Screen_Width as integer, Screen_Height as integer)
  39.     dim as integer PageIndex
  40.     for PageIndex = lbound(clv_buffer, 1) to ubound(clv_buffer, 1)
  41.         clv_buffer(PageIndex, 0) = imagecreate(Screen_Width, Screen_Height)
  42.         clv_buffer(PageIndex, 1) = imagecreate(Screen_Width, Screen_Height)
  43.         clv_buffer_cls clv_buffer(), PageIndex
  44.     next
  45. end sub
  46. sub clv_font_load (clv_font() as fb.image ptr, FontIndex as integer, Switch as integer, Filename as string)
  47.     if Switch and clv_font_flag_destroy then
  48.         png_destroy clv_font(FontIndex)
  49.     end if
  50.     if Switch and clv_font_flag_load then
  51.         clv_font(FontIndex) = png_load(Filename)
  52.     end if
  53. end sub
  54. sub clv_draw_text (clv_buffer() as fb.image ptr, clv_font() as fb.image ptr, PageIndex as integer, clv_glyph() as integer, X as integer, Y as integer, Value as string)
  55.     dim as integer Glyph, Px, Py, Offset, Glyph_X, Glyph_Y
  56.     dim as fb.image ptr ColorGraphic, TransparencyGraphic
  57.     dim as uinteger Pc
  58.     ColorGraphic = imagecreate(8, 8)
  59.     TransparencyGraphic = imagecreate(8, 8)
  60.     line ColorGraphic, (0, 0) - (7, 7), rgb(0, 0, 0), bf
  61.     line TransparencyGraphic, (0, 0) - (7, 7), rgb(255, 255, 255), bf
  62.     for Offset = 0 to len(Value)-1
  63.         Glyph = clv_glyph(asc(mid(Value, Offset + 1, 1)), 1)
  64.         Glyph_X = (Glyph and 15) shl 3
  65.         Glyph_Y = (Glyph shr 4) shl 3
  66.         put ColorGraphic, (0, 0), clv_font(clv_glyph(Glyph, 0)), (Glyph_X, Glyph_Y)-(Glyph_X + 7,Glyph_Y + 7), pset
  67.         for Py = 0 to 7
  68.             for Px = 0 to 7
  69.                 Pc = point(Px, Py, ColorGraphic)
  70.                 if (Pc and &HFFFFFF)=0 then
  71.                     pset TransparencyGraphic, (Px, Py), rgb(255, 255, 255)
  72.                 else
  73.                     pset TransparencyGraphic, (Px, Py), rgb(0, 0, 0)
  74.                 end if                
  75.             next
  76.         next
  77.         Px=X+(Offset shl 3)
  78.         Py=Y
  79.         clv_draw_image clv_buffer(), PageIndex, Px, Py, ColorGraphic, TransparencyGraphic
  80.     next
  81.     imagedestroy ColorGraphic
  82.     imagedestroy TransparencyGraphic
  83. end sub
  84. sub clv_buffer_cls(clv_buffer() as fb.image ptr, PageIndex as integer)
  85.     line clv_buffer(PageIndex, 0), (0, 0) - (clv_buffer(PageIndex, 0) -> width - 1, clv_buffer(PageIndex, 0) -> height - 1), rgb(255, 255, 255), bf
  86.     line clv_buffer(PageIndex, 1), (0, 0) - (clv_buffer(PageIndex, 1) -> width - 1, clv_buffer(PageIndex, 1) -> height - 1), rgb(0, 0, 0), bf
  87. end sub
  88. sub clv_buffer_copy(clv_buffer() as fb.image ptr, SrcIndex as integer, DestIndex as integer)
  89.     put clv_buffer(DestIndex, 0), (0, 0), clv_buffer(SrcIndex, 0), pset
  90.     put clv_buffer(DestIndex, 1), (0, 0), clv_buffer(SrcIndex, 1), pset
  91. end sub
  92. sub clv_buffer_overlay(clv_buffer() as fb.image ptr, SrcIndex as integer, DestIndex as integer)
  93.     'transparency layer
  94.     put clv_buffer(DestIndex, 0), (0, 0), clv_buffer(SrcIndex, 0), custom, @clv_filter_mask, clv_flag_and
  95.     'color layer
  96.     put clv_buffer(DestIndex, 1), (0, 0), clv_buffer(SrcIndex, 0), custom, @clv_filter_mask, clv_flag_and
  97.     put clv_buffer(DestIndex, 1), (0, 0), clv_buffer(SrcIndex, 1), custom, @clv_filter_mask, clv_flag_or
  98. end sub
  99. sub clv_buffer_flip(clv_buffer() as fb.image ptr, PageIndex as integer, Display_Width as integer, Display_Height as integer)
  100.     dim as integer X, Y, Px, Py
  101.     dim as fb.image ptr Buffer
  102.     Buffer = imagecreate(Display_Width, clv_buffer(PageIndex, 1) -> height)
  103.     for Px = 0 to Buffer -> width - 1
  104.         X = fix(Px * clv_buffer(PageIndex, 0) -> width / Buffer -> width)
  105.         put Buffer, (Px, 0), clv_buffer(PageIndex, 1), (X, 0) - (X, clv_buffer(PageIndex, 1) -> height - 1), pset
  106.     next
  107.     for Py = 0 to Display_height - 1
  108.         Y = fix(Py * clv_buffer(PageIndex, 0) -> height / Display_Height)
  109.         put (0, Py), Buffer, (0,Y) - (Buffer -> width - 1, Y), pset
  110.     next
  111.     imagedestroy Buffer
  112. end sub
  113. sub clv_draw_line_thick(clv_buffer() as fb.image ptr, PageIndex as integer, X1 as integer, Y1 as integer, X2 as integer, Y2 as integer, W as double, TransparencyMask as uinteger, clv_flag_method as integer)
  114.     dim as double X1d=X1, Y1d=Y1, X2d=X2, Y2d=Y2
  115.     dim as double Angle=clv_math_vector2decimal(X1d, Y1d, X2d, Y2d)    
  116.     dim as double Xa=-W*cos(2*Pi*(Angle-.5)), Ya=W*sin(2*Pi*(Angle-.5))
  117.     dim as double Xb=-W*cos(2*Pi*(Angle+.5)), Yb=W*sin(2*Pi*(Angle+.5))
  118.     clv_draw_primitive_triangle clv_buffer(), PageIndex, X1d-Xa, Y1d-Ya, X1d+Xa, Y1d+Ya, X2d+Xa, Y2d+Ya, ColorMask, TransparencyMask, Center_X, Center_Y
  119.     clv_draw_primitive_triangle clv_buffer(), PageIndex, X1d-Xa, Y1d-Ya, X2d+Xa, Y2d+Ya, X2d-Xa, Y2d-Ya, ColorMask, TransparencyMask, Center_X, Center_Y
  120. end sub
  121. sub clv_draw_line(clv_buffer() as fb.image ptr, PageIndex as integer, X1 as integer, Y1 as integer, X2 as integer, Y2 as integer, ColorMask as uinteger, TransparencyMask as uinteger, clv_flag_method as integer)
  122.     select case clv_flag_method
  123.     case clv_flag_default
  124.         line clv_buffer(PageIndex, 0), (X1, Y1) - (X2, Y2), TransparencyMask
  125.         line clv_buffer(PageIndex, 1), (X1, Y1) - (X2, Y2), ColorMask
  126.     case clv_flag_b
  127.         line clv_buffer(PageIndex, 0), (X1, Y1) - (X2, Y2), TransparencyMask, b
  128.         line clv_buffer(PageIndex, 1), (X1, Y1) - (X2, Y2), ColorMask, b
  129.     case clv_flag_bf
  130.         line clv_buffer(PageIndex, 0), (X1, Y1) - (X2, Y2), TransparencyMask, bf
  131.         line clv_buffer(PageIndex, 1), (X1, Y1) - (X2, Y2), ColorMask, bf
  132.     end select
  133. end sub
  134. sub clv_draw_circle(clv_buffer() as fb.image ptr, PageIndex as integer, X1 as double, Y1 as double, X2 as double, Y2 as double, A1 as double, A2 as double, R1 as double, R2 as double, ColorMask_inner as uinteger, ColorMask_outer as uinteger, ColorMask_clockwise as uinteger, ColorMask_counterclockwise as uinteger, TransparencyMask as uinteger)
  135.     dim as fb.image ptr ColorGraphic, TransparencyGraphic
  136.     ColorGraphic = imagecreate(clv_buffer(PageIndex, 0) -> width, clv_buffer(PageIndex, 0) -> height)
  137.     TransparencyGraphic = imagecreate(clv_buffer(PageIndex, 1) -> width, clv_buffer(PageIndex, 1) -> height)
  138.     clv_draw_primitive_circle ColorGraphic, X1, Y1, X2, Y2, A1, A2, R1, R2, ColorMask_inner, ColorMask_outer, ColorMask_clockwise, ColorMask_counterclockwise
  139.     clv_draw_primitive_circle TransparencyGraphic, X1, Y1, X2, Y2, A1, A2, R1, R2, TransparencyMask, TransparencyMask, TransparencyMask, TransparencyMask
  140.     clv_draw_image clv_buffer(), PageIndex, X1, Y1, ColorGraphic, TransparencyGraphic
  141.     imagedestroy(ColorGraphic)
  142.     imagedestroy(TransparencyGraphic)
  143. end sub
  144. sub clv_draw_pixel(clv_buffer() as fb.image ptr, PageIndex as integer, X as integer, Y as integer, ColorMask as uinteger, TransparencyMask as uinteger)
  145.     pset clv_buffer(PageIndex, 0), (X, Y), TransparencyMask
  146.     pset clv_buffer(PageIndex, 1), (X, Y), ColorMask
  147. end sub
  148. sub clv_draw_image(clv_buffer() as fb.image ptr, PageIndex as integer, X as integer, Y as integer, ColorGraphic as fb.image ptr, TransparencyGraphic as fb.image ptr)
  149.     'transparency layer
  150.     put clv_buffer(PageIndex, 0), (X, Y), TransparencyGraphic, custom, @clv_filter_mask, clv_flag_and
  151.     'color layer
  152.     put clv_buffer(PageIndex, 1), (X, Y), TransparencyGraphic, custom, @clv_filter_mask, clv_flag_and
  153.     put clv_buffer(PageIndex, 1), (X, Y), ColorGraphic, custom, @clv_filter_mask, clv_flag_or
  154. end sub
  155. function clv_filter_mask (SRC as uinteger, DST as uinteger, PARM as any ptr) as uinteger  
  156.     dim as uinteger parm32 = cast(uinteger, PARM)
  157.     return ((SRC and DST) and not(parm32 xor clv_flag_and)) or ((SRC or DST) and not(parm32 xor clv_flag_or))
  158. end function
  159. sub clv_draw_primitive_circle(Buffer as fb.image ptr, X1 as double, Y1 as double, X2 as double, Y2 as double, A1 as double, A2 as double, R1 as double, R2 as double, argb32_inner as uinteger, argb32_outer as uinteger, argb32_clockwise as uinteger, argb32_counterclockwise as uinteger)
  160.     dim as uinteger argb32(0 to 7), argb32mix(0 to 1)
  161.     dim as double weight(0 to 7), weightmix(0 to 1)    
  162.     dim as double X, Y, RX, RY, CX, CY, X0, Y0, R, A
  163.     argb32(0) = argb32_inner
  164.     argb32(1) = argb32_outer
  165.     argb32(2) = argb32_clockwise
  166.     argb32(3) = argb32_counterclockwise
  167.     if X1 > X2 then swap X1, X2
  168.     if Y1 > Y2 then swap Y1, Y2
  169.     CX = (X2 + X1) / 2
  170.     CY = (Y2 + Y1) / 2
  171.     RX = (X2 - X1) / 2
  172.     RY = (Y2 - Y1) / 2
  173.     X1 = fix(CX - RX) - 1
  174.     X2 = fix(CX + RX) + 1
  175.     Y1 = fix(CX - RY) - 1
  176.     Y2 = fix(CX + RY) + 1
  177.     if X1 < 0 then
  178.         X1 = 0
  179.     elseif X1 > Buffer -> width then
  180.         X1 = Buffer -> width
  181.     endif
  182.     if X2 < 0 then
  183.         X2 = -1
  184.     elseif X2 > Buffer -> width then
  185.         X2 = Buffer -> width - 1
  186.     endif
  187.     if Y1 < 0 then
  188.         Y1 = 0
  189.     elseif Y1 > Buffer -> height then
  190.         Y1 = Buffer -> height
  191.     endif
  192.     if Y2<0 then
  193.         Y2 = -1
  194.     elseif Y2 > Buffer -> height then
  195.         Y2 = Buffer -> height - 1
  196.     endif
  197.     for Y = Y1 to Y2
  198.         for X = X1 to X2
  199.             X0 = (X - CX) / RX
  200.             Y0 = (Y - CY) / RY
  201.             A = clv_math_vector2decimal(0, 0, X0, Y0)
  202.             if (A1 < A2 and A >= A1 and A <= A2) or (A1 >= A2 and (A >= A1 or A <= A2)) then
  203.                 if abs(A2 - A1) > 0 then
  204.                     if (A1 < A2 and A >= A1 and A <= A2) then
  205.                         weight(0) = abs(A2 - A) / abs(A2 - A1)
  206.                         weight(1) = abs(A - A1) / abs(A2 - A1)
  207.                     elseif(A1 >= A2 and (A >= A1 or A <= A2)) then
  208.                         weight(0) = abs(A1 - A) / abs(A1 - A2)
  209.                         weight(1) = abs(A - A2) / abs(A1 - A2)
  210.                     endif
  211.                 else
  212.                     weight(0) = 1
  213.                     weight(1) = 1
  214.                 endif
  215.                 R = X0 * X0 + Y0 * Y0
  216.                 if R > 0 then R = sqr(R)
  217.                 if (R1 < R2 and R >= R1 and R <= R2) or (R1 >= R2 and (R >= R1 or R <= R2)) then
  218.                     if abs(R2 - R1) > 0 then
  219.                         if (R1 < R2 and R >= R1 and R <= R2) then
  220.                             weight(2) = abs(R2 - R) / abs(R2 - R1)
  221.                             weight(3) = abs(R - R1) / abs(R2 - R1)
  222.                         elseif(R1 >= R2 and (R >= R1 or R <= R2)) then
  223.                             weight(2) = abs(R1 - R) / abs(R1 - R2)
  224.                             weight(3) = abs(R - R2) / abs(R1 - R2)
  225.                         endif
  226.                     else
  227.                         weight(2) = 1
  228.                         weight(3) = 1
  229.                     endif
  230.                     argb32mix(0)=argb32(0)
  231.                     argb32mix(1)=argb32(1)
  232.                     weightmix(0)=weight(0)
  233.                     weightmix(1)=weight(1)
  234.                     argb32(4)=clv_argb32_mix(argb32mix(), weightmix())
  235.                     argb32mix(0)=argb32(2)
  236.                     argb32mix(1)=argb32(3)
  237.                     weightmix(0)=weight(2)
  238.                     weightmix(1)=weight(3)
  239.                     argb32(5)=clv_argb32_mix(argb32mix(), weightmix())
  240.                     argb32mix(0)=argb32(4)
  241.                     argb32mix(1)=argb32(5)
  242.                     weightmix(0)=.5
  243.                     weightmix(1)=.5
  244.                     argb32(6)=clv_argb32_mix(argb32mix(), weightmix())
  245.                     pset Buffer, (X, Y), argb32(6)
  246.                 endif
  247.             endif
  248.         next
  249.     next
  250. end sub
  251. sub clv_draw_primitive_triangle(clv_buffer() as fb.image ptr, PageIndex as integer, X1 as double, Y1 as double, X2 as double, Y2 as double, X3 as double, Y3 as double, ColorMask as uinteger, TransparencyMask as uinteger, Center_X as double, Center_Y as double)
  252.     dim as double Triv(0 to 3,0 to 1)
  253.     Triv(0,0)=X1
  254.     Triv(0,1)=Y1
  255.     Triv(1,0)=X2
  256.     Triv(1,1)=Y2
  257.     Triv(2,0)=X3
  258.     Triv(2,1)=Y3    
  259.     dim as uinteger temp=0
  260.     dim as uinteger TrivCt=0
  261.     dim as uinteger Triv1=0
  262.     dim as uinteger Triv2=0
  263.     dim as uinteger Triv3=0
  264.     dim as double TrivX1=0.0
  265.     dim as double TrivY1=0.0
  266.     dim as double TrivX2=0.0
  267.     dim as double TrivY2=0.0
  268.     dim as double TriX=0.0
  269.     dim as double TriY=0.0
  270.     dim as double TrivX=0.0
  271.     dim as double TrivY=0.0
  272.     dim as double TriX1=0.0
  273.     dim as double TriY1=0.0
  274.     dim as double TriX2=0.0
  275.     dim as double TriY2=0.0
  276.     for TrivCt=0 to 2
  277.         Triv1=TrivCt
  278.         Triv2=(Triv1+1) mod 3
  279.         Triv3=(Triv2+1) mod 3
  280.         if((Triv(Triv1,1)<=Triv(Triv2,1)) and (Triv(Triv1,1)<=Triv(Triv3,1))) then
  281.             if(Triv(Triv2,1)>Triv(Triv3,1)) then
  282.                 swap Triv2,Triv3
  283.             endif
  284.             if(Triv(Triv2,1)>Triv(Triv1,1)) then
  285.                 TrivX1=Triv(Triv2,1)-Triv(Triv1,1)
  286.                 TrivY1=Triv(Triv2,0)-Triv(Triv1,0)
  287.                 TrivX2=Triv(Triv3,1)-Triv(Triv1,1)
  288.                 TrivY2=Triv(Triv3,0)-Triv(Triv1,0)
  289.                 for TriY=Triv(Triv1,1) to Triv(Triv2,1)
  290.                     TriX1=TrivY1/TrivX1*(TriY-Triv(Triv1,1))+Triv(Triv1,0)
  291.                     TriX2=TrivY2/Trivx2*(TriY-Triv(Triv1,1))+Triv(Triv1,0)
  292.                     clv_draw_line clv_buffer(), PageIndex,Center_X+TriX1,Center_Y+TriY,Center_X+Trix2,Center_Y+TriY, ColorMask, TransparencyMask, clv_flag_bf
  293.                 next
  294.             endif
  295.             if(Triv(Triv3,1)>Triv(Triv2,1)) then
  296.                 TrivX1=Triv(Triv2,1)-Triv(Triv3,1)
  297.                 TrivY1=Triv(Triv2,0)-Triv(Triv3,0)
  298.                 TrivX2=Triv(Triv3,1)-Triv(Triv1,1)
  299.                 TrivY2=Triv(Triv3,0)-Triv(Triv1,0)
  300.                 for TriY=Triv(Triv2,1) to Triv(Triv3,1)
  301.                     TriX1=TrivY1/TrivX1*(TriY-Triv(Triv2,1))+Triv(Triv2,0)
  302.                     TriX2=TrivY2/Trivx2*(TriY-Triv(Triv1,1))+Triv(Triv1,0)
  303.                     clv_draw_line clv_buffer(), PageIndex,Center_X+TriX1,Center_Y+TriY,Center_X+Trix2,Center_Y+TriY, ColorMask, TransparencyMask, clv_flag_bf
  304.                 next
  305.             endif
  306.         endif
  307.     next
  308. end sub
  309. function clv_math_vector2decimal (X1 as double, Y1 as double, X2 as double, Y2 as double) as double
  310.     dim as double X3, Y3, R1a, R1b, R2a, R2b
  311.     X3 = X2 - X1
  312.     Y3 = Y2 - Y1
  313.     if Y3 <> 0 then
  314.         R1a = (X3 / Y3)
  315.         if R1a > 0 then R1a = R1a ^ (-1)
  316.         R1b = atn(R1a) / (clv_math_Pi / 2) * .25
  317.         if R1b < 0 then R1b = abs(R1b) + .25
  318.         if Y3 > 0 then R1b = R1b + .5
  319.     endif
  320.     select case X3
  321.     case is < 0
  322.         if Y3 = 0 then R1b = 0
  323.     case 0
  324.         select case Y3
  325.         case is < 0
  326.             R1b = .25
  327.         case is > 0
  328.             R1b = .75
  329.         end select
  330.     case is > 0
  331.         if Y3 = 0 then R1b = .5
  332.     end select
  333.     if X3 <> 0 then
  334.         R2a = (Y3 / X3)
  335.         if R2a > 0 then R2a = R2a ^ (-1)
  336.         R2b = atn(R2a) / (clv_math_Pi / 2) * .25
  337.         select case Y3
  338.         case is <0
  339.             select case R2b
  340.             case is < 0
  341.                 R2b = ABS(R2b)
  342.             case is > 0
  343.                 R2b = R2b + .75
  344.             end select
  345.         case is > 0
  346.             select case R2b
  347.             case is < 0
  348.                 R2b = ABS(R2b) + .5
  349.             case is > 0
  350.                 R2b = ABS(R2b) + .25
  351.             end select
  352.         end select
  353.     endif
  354.     select case X3
  355.     case is < 0
  356.         if Y3 = 0 then R2b = 1
  357.     case 0
  358.         select case Y3
  359.         case is < 0
  360.             R2b = .75
  361.         case is > 0
  362.             R2b = .25
  363.         end select
  364.     case is > 0
  365.         if Y3 = 0 then R2b = .5
  366.     end select
  367.     R2b = 1 - R2b
  368.     return (R1b + R2b) / 2
  369. end function
  370. function clv_argb32_mix(argb32() as uinteger, weight() as double) as uinteger
  371.     dim as uinteger ret
  372.     dim as double channel(0 to 1, 0 to 7)
  373.     dim as integer n=0, c=0
  374.     for n = lbound(argb32, 1) to ubound(argb32, 1)
  375.         if n >= lbound(weight, 1) and n <= ubound(weight, 1) then
  376.             channel(0, 4) = abs(weight(n))
  377.             channel(1, 4) = channel(1, 4) + abs(weight(n))
  378.         endif
  379.         for c = 1 to 3
  380.             channel(0, c) = (channel(0, c) + (argb32(n) shr (c shl 3)) and &hff) * channel(0, 4)
  381.         next
  382.     next    
  383.     if channel(1, 4) > 0 then
  384.         for c = 1 to 3
  385.             channel(1, c) = channel(0, c) / channel(1, 4)
  386.         next
  387.     endif
  388.     for c = 1 to 3
  389.         ret = ret or ((channel(1, c) and &hff) shl (c shl 3))
  390.     next
  391.     return ret
  392. end function
Add Comment
Please, Sign In to add comment