Re: [Factor-talk] Transparent background texts and Windows Factor

2019-06-08 Thread Doug Coleman
Merged. Thank you all for working on this!

On Sat, Jun 8, 2019 at 8:24 AM Alexander Ilin  wrote:

>
> 08.06.2019, 16:11, "Alexander Ilin" :
> > I have also pushed an experimental commit to support transparency in the
> foreground text color.
> > It seems there is still an issue with the correct handling of foreground
> color. For example, instead of light blue I get a yellow.
>
>   Found the reason. It was the extra "swap rot" from John's suggested code.
>
>   I have removed the color mix-up and pushed the branch again.
>
>   https://github.com/AlexIljin/factor/tree/win-transparent-text-background
>
>   I consider this code to be complete, unless someone wants to comment on
> some unconventional formatting.
>   Also, I didn't actually test the text output with transparent foreground
> color. If you do some testing, let me know if it works as expected. I've
> removed transparent foreground handling into a separate if branch to reduce
> the performance impact on the most usual code path.
>
> ---=---
>  Александр
>
>
>
> ___
> Factor-talk mailing list
> Factor-talk@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/factor-talk
>
___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk


Re: [Factor-talk] Transparent background texts and Windows Factor

2019-06-08 Thread Alexander Ilin

08.06.2019, 16:11, "Alexander Ilin" :
> I have also pushed an experimental commit to support transparency in the 
> foreground text color.
> It seems there is still an issue with the correct handling of foreground 
> color. For example, instead of light blue I get a yellow.

  Found the reason. It was the extra "swap rot" from John's suggested code.

  I have removed the color mix-up and pushed the branch again.

  https://github.com/AlexIljin/factor/tree/win-transparent-text-background

  I consider this code to be complete, unless someone wants to comment on some 
unconventional formatting.
  Also, I didn't actually test the text output with transparent foreground 
color. If you do some testing, let me know if it works as expected. I've 
removed transparent foreground handling into a separate if branch to reduce the 
performance impact on the most usual code path.

---=--- 
 Александр



___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk


Re: [Factor-talk] Transparent background texts and Windows Factor

2019-06-08 Thread Alexander Ilin
I have also pushed an experimental commit to support transparency in the 
foreground text color.
It seems there is still an issue with the correct handling of foreground color. 
For example, instead of light blue I get a yellow.

08.06.2019, 15:12, "KUSUMOTO Norio" :
>>  2019/06/08 20:04、Alexander Ilin のメール:
>>
>>   Then I incorporated the optimizations suggested by Jonh Benediktsson, and 
>> here are the new results from commit fa57d052:
>>   Opaque background: 143 ms
>>   Transparent background: 150 ms
>>
>>   In general, the Transparent test runs about 6-7 ms longer than the Opaque 
>> test, i.e. about 4.6% slower, which is a much better performance 
>> characteristic compared to the previous approaches.
>>
>>   The updated code is posted here: 
>> https://github.com/AlexIljin/factor/tree/win-transparent-text-background
>
> How wonderful!
>
> If it's this fast, it shouldn't be a problem in terms of speed to implement 
> imperfectly
> transparent foreground text.

---=--- 
 Александр



___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk


Re: [Factor-talk] Transparent background texts and Windows Factor

2019-06-08 Thread Alexander Ilin
I have updated the code. There was the "24 bits" missing after "3byte-array 
uint32_t deref", so the random top byte used to mix in with the transparency 
via "bitor".

08.06.2019, 15:03, "Alexander Ilin" :
> Unfortunately, the posted code doesn't work as expected: the text labels 
> randomly have colored background. I'm looking for a reason.
>
> 08.06.2019, 14:04, "Alexander Ilin" :
>>  Hello, Norio, and thank you for the benchmark code!
>>
>>    I was able to use it, and here are results from my tests. I took the 
>> typical output values.
>>
>>    Your code from commit a16eb2f6:
>>    Opaque background: 146 ms
>>    Transparent background: 1083 ms
>>
>>    My code from commit 26516f97:
>>    Opaque background: 142 ms
>>    Transparent background: 1800 ms
>>
>>    Then I incorporated the optimizations suggested by Jonh Benediktsson, and 
>> here are the new results from commit fa57d052:
>>    Opaque background: 143 ms
>>    Transparent background: 150 ms
>>
>>    In general, the Transparent test runs about 6-7 ms longer than the Opaque 
>> test, i.e. about 4.6% slower, which is a much better performance 
>> characteristic compared to the previous approaches.
>>
>>    The updated code is posted here: 
>> https://github.com/AlexIljin/factor/tree/win-transparent-text-background
>>
>>  08.06.2019, 10:11, "KUSUMOTO Norio" :
>>>   Ouch, an e-mail wasn't sent to the mailing list because I sent it direct.
>>>   I rewrite the wrong part and send it again.
>>>
>>>   On 2019/06/05 22:24, John Benediktsson wrote:
    Or clear the cache each time, so you don’t have to be lower level 
 code...
>    On Jun 5, 2019, at 4:24 AM, Alexander Ilin wrote: I 
> think the pairs of {font, string} are cached and only drawn once by the 
> GUI framework. I think you need to call the drawing code more directly to 
> get real performance data.
>>>
>>>   Thank you, Alexander and John.
>>>   I decided to measure only internal processing time.
>>
>>  ---=---
>>   Александр
>>
>>  ___
>>  Factor-talk mailing list
>>  Factor-talk@lists.sourceforge.net
>>  https://lists.sourceforge.net/lists/listinfo/factor-talk
>
> ---=---
>  Александр
>
> ___
> Factor-talk mailing list
> Factor-talk@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/factor-talk

---=--- 
 Александр



___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk


Re: [Factor-talk] Transparent background texts and Windows Factor

2019-06-08 Thread KUSUMOTO Norio

> 2019/06/08 20:04、Alexander Ilin のメール:
> 
>  Then I incorporated the optimizations suggested by Jonh Benediktsson, and 
> here are the new results from commit fa57d052:
>  Opaque background: 143 ms
>  Transparent background: 150 ms
> 
>  In general, the Transparent test runs about 6-7 ms longer than the Opaque 
> test, i.e. about 4.6% slower, which is a much better performance 
> characteristic compared to the previous approaches.
> 
>  The updated code is posted here: 
> https://github.com/AlexIljin/factor/tree/win-transparent-text-background


How wonderful!

If it's this fast, it shouldn't be a problem in terms of speed to implement 
imperfectly 
transparent foreground text.

--
KUSUMOTO Norio





___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk


Re: [Factor-talk] Transparent background texts and Windows Factor

2019-06-08 Thread Alexander Ilin
Unfortunately, the posted code doesn't work as expected: the text labels 
randomly have colored background. I'm looking for a reason.

08.06.2019, 14:04, "Alexander Ilin" :
> Hello, Norio, and thank you for the benchmark code!
>
>   I was able to use it, and here are results from my tests. I took the 
> typical output values.
>
>   Your code from commit a16eb2f6:
>   Opaque background: 146 ms
>   Transparent background: 1083 ms
>
>   My code from commit 26516f97:
>   Opaque background: 142 ms
>   Transparent background: 1800 ms
>
>   Then I incorporated the optimizations suggested by Jonh Benediktsson, and 
> here are the new results from commit fa57d052:
>   Opaque background: 143 ms
>   Transparent background: 150 ms
>
>   In general, the Transparent test runs about 6-7 ms longer than the Opaque 
> test, i.e. about 4.6% slower, which is a much better performance 
> characteristic compared to the previous approaches.
>
>   The updated code is posted here: 
> https://github.com/AlexIljin/factor/tree/win-transparent-text-background
>
> 08.06.2019, 10:11, "KUSUMOTO Norio" :
>>  Ouch, an e-mail wasn't sent to the mailing list because I sent it direct.
>>  I rewrite the wrong part and send it again.
>>
>>  On 2019/06/05 22:24, John Benediktsson wrote:
>>>   Or clear the cache each time, so you don’t have to be lower level code...
   On Jun 5, 2019, at 4:24 AM, Alexander Ilin wrote: I 
 think the pairs of {font, string} are cached and only drawn once by the 
 GUI framework. I think you need to call the drawing code more directly to 
 get real performance data.
>>
>>  Thank you, Alexander and John.
>>  I decided to measure only internal processing time.
>
> ---=---
>  Александр
>
> ___
> Factor-talk mailing list
> Factor-talk@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/factor-talk

---=--- 
 Александр



___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk


Re: [Factor-talk] Transparent background texts and Windows Factor

2019-06-08 Thread Alexander Ilin
Hello, Norio, and thank you for the benchmark code!

  I was able to use it, and here are results from my tests. I took the typical 
output values.

  Your code from commit a16eb2f6:
  Opaque background: 146 ms
  Transparent background: 1083 ms

  My code from commit 26516f97:
  Opaque background: 142 ms
  Transparent background: 1800 ms

  Then I incorporated the optimizations suggested by Jonh Benediktsson, and 
here are the new results from commit fa57d052:
  Opaque background: 143 ms
  Transparent background: 150 ms

  In general, the Transparent test runs about 6-7 ms longer than the Opaque 
test, i.e. about 4.6% slower, which is a much better performance characteristic 
compared to the previous approaches.

  The updated code is posted here: 
https://github.com/AlexIljin/factor/tree/win-transparent-text-background

08.06.2019, 10:11, "KUSUMOTO Norio" :
> Ouch, an e-mail wasn't sent to the mailing list because I sent it direct.
> I rewrite the wrong part and send it again.
>
> On 2019/06/05 22:24, John Benediktsson wrote:
>>  Or clear the cache each time, so you don’t have to be lower level code...
>>>  On Jun 5, 2019, at 4:24 AM, Alexander Ilin wrote: I 
>>> think the pairs of {font, string} are cached and only drawn once by the GUI 
>>> framework. I think you need to call the drawing code more directly to get 
>>> real performance data.
>
> Thank you, Alexander and John.
> I decided to measure only internal processing time.

---=--- 
 Александр



___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk


Re: [Factor-talk] Transparent background texts and Windows Factor

2019-06-08 Thread KUSUMOTO Norio
Ouch, an e-mail wasn't sent to the mailing list because I sent it direct.
I rewrite the wrong part and send it again.

On 2019/06/05 22:24, John Benediktsson wrote:
> Or clear the cache each time, so you don’t have to be lower level code...
>> On Jun 5, 2019, at 4:24 AM, Alexander Ilin wrote: I think 
>> the pairs of {font, string} are cached and only drawn once by the GUI 
>> framework. I think you need to call the drawing code more directly to get 
>> real performance data.

Thank you, Alexander and John.
I decided to measure only internal processing time.

On my machine, my code took 9 to 10 times longer to make a text image with a 
transparent background
than it did with an opaque background.


! Copyright (C) 2019 KUSUMOTO Norio.
! See http://factorcode.org/license.txt for BSD license.
USING: kernel accessors locals math formatting ui ui.gadgets.labels
ui.commands ui.gadgets ui.gadgets.toolbar ui.gadgets.tracks ui.gestures
fonts colors tools.time memory math.ranges namespaces arrays sequences
windows.uniscribe windows.uniscribe.private ;
IN: uni-bench

TUPLE: uni-bench-gadget < track
opaque-font
transparent-font
opaque-time
transparent-time ;

:  ( -- gadget )
vertical uni-bench-gadget new-track

"monospace" >>name
T{ rgba f 0.0 0.0 0.0 1.0 } >>foreground
T{ rgba f 0.0 0.0 1.0 1.0 } >>background
36 >>size
>>opaque-font

"monospace" >>name
T{ rgba f 0.0 0.0 0.0 1.0 } >>foreground
T{ rgba f 0.0 0.0 1.0 0.0 } >>background
36 >>size
>>transparent-font
{
"  script-string>image "
""
"  Press any of the keys listed below"
""
"1: Opaque background \"\" (1000 times)"
"2: Transparent background \"\" (1000 times)  "
""
}  f track-add
""  >>opaque-time
""  >>transparent-time
dup opaque-time>> " Opaque background:" label-on-left f track-add
dup transparent-time>> " Transparent:background" label-on-left f track-add ;

:: com-benchmark-opaque-script-string>image ( gadget -- )
gadget opaque-font>> :> test-font
gc
[
1000 [
test-font ""  script-string>image drop
] times
] benchmark
gadget opaque-time>>
swap 100 / "%d ms" sprintf >>text relayout-1 ;

:: com-benchmark-transparent-script-string>image ( gadget -- )
gadget transparent-font>> :> test-font
gc
[
1000 [
test-font ""  script-string>image drop
] times
] benchmark
gadget transparent-time>>
swap 100 / "%d ms" sprintf >>text relayout-1 ;

uni-bench-gadget "gestures" f {
{ T{ key-down { sym "1" } } com-benchmark-opaque-script-string>image }
{ T{ key-down { sym "2" } } com-benchmark-transparent-script-string>image }
} define-command-map

MAIN-WINDOW: uni-bench { { title "Uniscribe benchmark" } }
 >>gadgets ;
--
KUSUMOTO Norio





> 2019/06/05 22:24、John Benediktsson  のメール:
> 
> Or clear the cache each time, so you don’t have to be lower level code...
> 
> 
>> On Jun 5, 2019, at 4:24 AM, Alexander Ilin  wrote:
>> 
>> I think the pairs of {font, string} are cached and only drawn once by the 
>> GUI framework.
>> I think you need to call the drawing code more directly to get real 
>> performance data.
>> 
>> 04.06.2019, 07:39, "KUSUMOTO, Norio" :
>>> My code was uploaded.
>>> 
>>> https://github.com/kusumotonorio/factor/blob/win-transparent-background-text/basis/windows/uniscribe/uniscribe.factor
>>> 
>>> I want to know how slow the code when it draws transparent background
>>> texts. So I am writing
>>> a test app to know it. But it has an issue.
>>> I try to measure time by actually drawing a label with a transparent
>>> background over and over again, and that happens very quickly.
>>> Creating an image from text takes a long time (3: and 4:) , so it should
>>> actually take longer.
>>> What's wrong with my code?
>>> 
>>> ! Copyright (C) 2019 KUSUMOTO Norio.
>>> ! See http://factorcode.org/license.txt for BSD license.
>>> USING: kernel accessors locals math formatting ui ui.gadgets.labels
>>> ui.commands ui.gadgets ui.gadgets.toolbar ui.gadgets.tracks ui.gestures
>>> fonts colors tools.time memory math.ranges namespaces arrays sequences
>>> windows.uniscribe windows.uniscribe.private ;
>>> IN: uni-bench
>>> 
>>> TUPLE: uni-bench-gadget < track
>>> opaque-label
>>> transparent-label
>>> opaque-time
>>> transparent-time ;
>>> 
>>> SYMBOL: test-strings
>>> V{ } clone test-strings set-global
>>> 1 5000 [a,b]  [
>>> "%04d" sprintf test-strings get push
>>> ] each
>>> test-strings get >array test-strings set-global
>>> 
>>> :  ( -- gadget )
>>> vertical uni-bench-gadget new-track
>>>  {
>>>  "  Press any of the keys listed below"
>>>  ""
>>>  "1: Opaque background label (5000 times)"
>>>  "2: Transparent background label (5000 times)"
>>>  "3: Opaque script-string>image (5000 times)"
>>>  "  

Re: [Factor-talk] Transparent background texts and Windows Factor

2019-06-05 Thread John Benediktsson
Or clear the cache each time, so you don’t have to be lower level code...


> On Jun 5, 2019, at 4:24 AM, Alexander Ilin  wrote:
> 
> I think the pairs of {font, string} are cached and only drawn once by the GUI 
> framework.
> I think you need to call the drawing code more directly to get real 
> performance data.
> 
> 04.06.2019, 07:39, "KUSUMOTO, Norio" :
>> My code was uploaded.
>> 
>> https://github.com/kusumotonorio/factor/blob/win-transparent-background-text/basis/windows/uniscribe/uniscribe.factor
>> 
>> I want to know how slow the code when it draws transparent background
>> texts. So I am writing
>> a test app to know it. But it has an issue.
>> I try to measure time by actually drawing a label with a transparent
>> background over and over again, and that happens very quickly.
>> Creating an image from text takes a long time (3: and 4:) , so it should
>> actually take longer.
>> What's wrong with my code?
>> 
>> ! Copyright (C) 2019 KUSUMOTO Norio.
>> ! See http://factorcode.org/license.txt for BSD license.
>> USING: kernel accessors locals math formatting ui ui.gadgets.labels
>> ui.commands ui.gadgets ui.gadgets.toolbar ui.gadgets.tracks ui.gestures
>> fonts colors tools.time memory math.ranges namespaces arrays sequences
>> windows.uniscribe windows.uniscribe.private ;
>> IN: uni-bench
>> 
>> TUPLE: uni-bench-gadget < track
>>  opaque-label
>>  transparent-label
>>  opaque-time
>>  transparent-time ;
>> 
>> SYMBOL: test-strings
>> V{ } clone test-strings set-global
>> 1 5000 [a,b]  [
>>  "%04d" sprintf test-strings get push
>> ] each
>> test-strings get >array test-strings set-global
>> 
>> :  ( -- gadget )
>>  vertical uni-bench-gadget new-track
>>   {
>>   "  Press any of the keys listed below"
>>   ""
>>   "1: Opaque background label (5000 times)"
>>   "2: Transparent background label (5000 times)"
>>   "3: Opaque script-string>image (5000 times)"
>>   "4: Transparent script-string>image (5000 times)"
>>   ""
>>  }  f track-add
>> 
>>  ""  >>opaque-label
>>  ""  >>transparent-label
>>  ""  >>opaque-time
>>  ""  >>transparent-time
>> 
>>  dup opaque-label>>
>>  
>>  "monospace" >>name
>>  T{ rgba f 0.0 0.0 0.0 1.0 } >>foreground
>>  T{ rgba f 0.0 0.0 1.0 1.0 } >>background
>>  36 >>size
>>  >>font f track-add
>> 
>>  dup transparent-label>>
>>  
>>  "monospace" >>name
>>  T{ rgba f 0.0 0.0 0.0 1.0 } >>foreground
>>  T{ rgba f 0.0 0.0 1.0 0.0 } >>background
>>  36 >>size
>>  >>font f track-add
>> 
>>  dup opaque-time>> " Opaque:" label-on-left f track-add
>>  dup transparent-time>> " Transparent:" label-on-left f track-add ;
>> 
>> :: com-benchmark-opaque ( gadget -- )
>>  gadget opaque-label>> :> test-label
>>  gc
>>  [
>>  test-strings get-global [
>>  test-label swap >>text relayout-1
>>  ] each
>>  ] benchmark
>>  gadget opaque-time>>
>>  swap 100 / "%d ms" sprintf >>text relayout-1 ;
>> 
>> :: com-benchmark-transparent ( gadget -- )
>>  gadget transparent-label>> :> test-label
>>  gc
>>  [
>>  test-strings get-global [
>>  test-label swap >>text relayout-1
>>  ] each
>>  ] benchmark
>>  gadget transparent-time>>
>>  swap 100 / "%d ms" sprintf >>text relayout-1 ;
>> 
>> :: com-benchmark-opaque-script-string>image ( gadget -- )
>>  gadget opaque-label>> font>> :> test-font
>>  gc
>>  [
>>  test-strings get-global [
>>  test-font swap  script-string>image drop
>>  ] each
>>  ] benchmark
>>  gadget opaque-time>>
>>  swap 100 / "%d ms" sprintf >>text relayout-1 ;
>> 
>> :: com-benchmark-transparent-script-string>image ( gadget -- )
>>  gadget transparent-label>> font>> :> test-font
>>  gc
>>  [
>>  test-strings get-global [
>>  test-font swap  script-string>image drop
>>  ] each
>>  ] benchmark
>>  gadget transparent-time>>
>>  swap 100 / "%d ms" sprintf >>text relayout-1 ;
>> 
>> uni-bench-gadget "gestures" f {
>>  { T{ key-down { sym "1" } } com-benchmark-opaque }
>>  { T{ key-down { sym "2" } } com-benchmark-transparent }
>>  { T{ key-down { sym "3" } } com-benchmark-opaque-script-string>image }
>>  { T{ key-down { sym "4" } }
>> com-benchmark-transparent-script-string>image }
>> } define-command-map
>> 
>> M: uni-bench-gadget pref-dim* drop { 300 250 } ;
>> 
>> MAIN-WINDOW: uni-bench { { title "Uniscribe benchmark" } }
>>   >>gadgets ;
>> 
>>> On 2019/05/30 21:17, KUSUMOTO Norio wrote:
>>>  Thank you, Alexander! I will read it and study. I tried the idea I
>>>  wrote earlier. I've only tried a little, but it seems to work well.
>>>  Yay!  -- KUSUMOTO Norio
  2019/05/30 20:19、Alexander Ilin のメール: Hello! I

Re: [Factor-talk] Transparent background texts and Windows Factor

2019-06-05 Thread Alexander Ilin
I think the pairs of {font, string} are cached and only drawn once by the GUI 
framework.
I think you need to call the drawing code more directly to get real performance 
data.

04.06.2019, 07:39, "KUSUMOTO, Norio" :
> My code was uploaded.
>
> https://github.com/kusumotonorio/factor/blob/win-transparent-background-text/basis/windows/uniscribe/uniscribe.factor
>
> I want to know how slow the code when it draws transparent background
> texts. So I am writing
> a test app to know it. But it has an issue.
> I try to measure time by actually drawing a label with a transparent
> background over and over again, and that happens very quickly.
> Creating an image from text takes a long time (3: and 4:) , so it should
> actually take longer.
> What's wrong with my code?
>
> ! Copyright (C) 2019 KUSUMOTO Norio.
> ! See http://factorcode.org/license.txt for BSD license.
> USING: kernel accessors locals math formatting ui ui.gadgets.labels
> ui.commands ui.gadgets ui.gadgets.toolbar ui.gadgets.tracks ui.gestures
> fonts colors tools.time memory math.ranges namespaces arrays sequences
> windows.uniscribe windows.uniscribe.private ;
> IN: uni-bench
>
> TUPLE: uni-bench-gadget < track
>  opaque-label
>  transparent-label
>  opaque-time
>  transparent-time ;
>
> SYMBOL: test-strings
> V{ } clone test-strings set-global
> 1 5000 [a,b]  [
>  "%04d" sprintf test-strings get push
> ] each
> test-strings get >array test-strings set-global
>
> :  ( -- gadget )
>  vertical uni-bench-gadget new-track
>   {
>   "  Press any of the keys listed below"
>   ""
>   "    1: Opaque background label (5000 times)"
>   "    2: Transparent background label (5000 times)"
>   "    3: Opaque script-string>image (5000 times)"
>   "    4: Transparent script-string>image (5000 times)"
>   ""
>  }  f track-add
>
>  ""  >>opaque-label
>  ""  >>transparent-label
>  ""  >>opaque-time
>  ""  >>transparent-time
>
>  dup opaque-label>>
>  
>  "monospace" >>name
>  T{ rgba f 0.0 0.0 0.0 1.0 } >>foreground
>  T{ rgba f 0.0 0.0 1.0 1.0 } >>background
>  36 >>size
>  >>font f track-add
>
>  dup transparent-label>>
>  
>  "monospace" >>name
>  T{ rgba f 0.0 0.0 0.0 1.0 } >>foreground
>  T{ rgba f 0.0 0.0 1.0 0.0 } >>background
>  36 >>size
>  >>font f track-add
>
>  dup opaque-time>> " Opaque:" label-on-left f track-add
>  dup transparent-time>> " Transparent:" label-on-left f track-add ;
>
> :: com-benchmark-opaque ( gadget -- )
>  gadget opaque-label>> :> test-label
>  gc
>  [
>  test-strings get-global [
>  test-label swap >>text relayout-1
>  ] each
>  ] benchmark
>  gadget opaque-time>>
>  swap 100 / "%d ms" sprintf >>text relayout-1 ;
>
> :: com-benchmark-transparent ( gadget -- )
>  gadget transparent-label>> :> test-label
>  gc
>  [
>  test-strings get-global [
>  test-label swap >>text relayout-1
>  ] each
>  ] benchmark
>  gadget transparent-time>>
>  swap 100 / "%d ms" sprintf >>text relayout-1 ;
>
> :: com-benchmark-opaque-script-string>image ( gadget -- )
>  gadget opaque-label>> font>> :> test-font
>  gc
>  [
>  test-strings get-global [
>  test-font swap  script-string>image drop
>  ] each
>  ] benchmark
>  gadget opaque-time>>
>  swap 100 / "%d ms" sprintf >>text relayout-1 ;
>
> :: com-benchmark-transparent-script-string>image ( gadget -- )
>  gadget transparent-label>> font>> :> test-font
>  gc
>  [
>  test-strings get-global [
>  test-font swap  script-string>image drop
>  ] each
>  ] benchmark
>  gadget transparent-time>>
>  swap 100 / "%d ms" sprintf >>text relayout-1 ;
>
> uni-bench-gadget "gestures" f {
>  { T{ key-down { sym "1" } } com-benchmark-opaque }
>  { T{ key-down { sym "2" } } com-benchmark-transparent }
>  { T{ key-down { sym "3" } } com-benchmark-opaque-script-string>image }
>  { T{ key-down { sym "4" } }
> com-benchmark-transparent-script-string>image }
> } define-command-map
>
> M: uni-bench-gadget pref-dim* drop { 300 250 } ;
>
> MAIN-WINDOW: uni-bench { { title "Uniscribe benchmark" } }
>   >>gadgets ;
>
> On 2019/05/30 21:17, KUSUMOTO Norio wrote:
>>  Thank you, Alexander! I will read it and study. I tried the idea I
>>  wrote earlier. I've only tried a little, but it seems to work well.
>>  Yay!  -- KUSUMOTO Norio
>>>  2019/05/30 20:19、Alexander Ilin のメール: Hello! I
>>>  think I have figured out the algorithm for the image processing. I'm
>>>  not sure if it's the same one that you came up with.
>>>  https://github.com/factor/factor/issues/152#issuecomment-497292323
>>>  Also, I don't know if there are standard WinApi functions to perform
>>>  the necessary op

Re: [Factor-talk] Transparent background texts and Windows Factor

2019-06-03 Thread KUSUMOTO, Norio

My code was uploaded.

https://github.com/kusumotonorio/factor/blob/win-transparent-background-text/basis/windows/uniscribe/uniscribe.factor


I want to know how slow the code when it draws transparent background 
texts. So I am writing

a test app to know it. But it has an issue.
I try to measure time by actually drawing a label with a transparent 
background over and over again, and that happens very quickly.
Creating an image from text takes a long time (3: and 4:) , so it should 
actually take longer.

What's wrong with my code?


! Copyright (C) 2019 KUSUMOTO Norio.
! See http://factorcode.org/license.txt for BSD license.
USING: kernel accessors locals math formatting ui ui.gadgets.labels
ui.commands ui.gadgets ui.gadgets.toolbar ui.gadgets.tracks ui.gestures
fonts colors tools.time memory math.ranges namespaces arrays sequences
windows.uniscribe windows.uniscribe.private ;
IN: uni-bench

TUPLE: uni-bench-gadget < track
    opaque-label
    transparent-label
    opaque-time
    transparent-time ;

SYMBOL: test-strings
V{ } clone test-strings set-global
1 5000 [a,b]  [
    "%04d" sprintf test-strings get push
] each
test-strings get >array test-strings set-global

:  ( -- gadget )
    vertical uni-bench-gadget new-track
 {
 "  Press any of the keys listed below"
 ""
 "    1: Opaque background label (5000 times)"
 "    2: Transparent background label (5000 times)"
 "    3: Opaque script-string>image (5000 times)"
 "    4: Transparent script-string>image (5000 times)"
 ""
    }  f track-add

    ""  >>opaque-label
    ""  >>transparent-label
    ""  >>opaque-time
    ""  >>transparent-time

    dup opaque-label>>
    
    "monospace" >>name
    T{ rgba f 0.0 0.0 0.0 1.0 } >>foreground
    T{ rgba f 0.0 0.0 1.0 1.0 } >>background
    36 >>size
    >>font f track-add

    dup transparent-label>>
    
    "monospace" >>name
    T{ rgba f 0.0 0.0 0.0 1.0 } >>foreground
    T{ rgba f 0.0 0.0 1.0 0.0 } >>background
    36 >>size
    >>font f track-add

    dup opaque-time>> " Opaque:" label-on-left f track-add
    dup transparent-time>> " Transparent:" label-on-left f track-add ;

:: com-benchmark-opaque ( gadget -- )
    gadget opaque-label>> :> test-label
    gc
    [
    test-strings get-global [
    test-label swap >>text relayout-1
    ] each
    ] benchmark
    gadget opaque-time>>
    swap 100 / "%d ms" sprintf >>text relayout-1 ;

:: com-benchmark-transparent ( gadget -- )
    gadget transparent-label>> :> test-label
    gc
    [
    test-strings get-global [
    test-label swap >>text relayout-1
    ] each
    ] benchmark
    gadget transparent-time>>
    swap 100 / "%d ms" sprintf >>text relayout-1 ;


:: com-benchmark-opaque-script-string>image ( gadget -- )
    gadget opaque-label>> font>> :> test-font
    gc
    [
    test-strings get-global [
    test-font swap  script-string>image drop
    ] each
    ] benchmark
    gadget opaque-time>>
    swap 100 / "%d ms" sprintf >>text relayout-1 ;

:: com-benchmark-transparent-script-string>image ( gadget -- )
    gadget transparent-label>> font>> :> test-font
    gc
    [
    test-strings get-global [
    test-font swap  script-string>image drop
    ] each
    ] benchmark
    gadget transparent-time>>
    swap 100 / "%d ms" sprintf >>text relayout-1 ;


uni-bench-gadget "gestures" f {
    { T{ key-down { sym "1" } } com-benchmark-opaque }
    { T{ key-down { sym "2" } } com-benchmark-transparent }
    { T{ key-down { sym "3" } } com-benchmark-opaque-script-string>image }
    { T{ key-down { sym "4" } } 
com-benchmark-transparent-script-string>image }

} define-command-map

M: uni-bench-gadget pref-dim* drop { 300 250 } ;

MAIN-WINDOW: uni-bench { { title "Uniscribe benchmark" } }
     >>gadgets ;



On 2019/05/30 21:17, KUSUMOTO Norio wrote:
Thank you, Alexander! I will read it and study. I tried the idea I 
wrote earlier. I've only tried a little, but it seems to work well. 
Yay!  -- KUSUMOTO Norio
2019/05/30 20:19、Alexander Ilin のメール: Hello! I 
think I have figured out the algorithm for the image processing. I'm 
not sure if it's the same one that you came up with. 
https://github.com/factor/factor/issues/152#issuecomment-497292323 
Also, I don't know if there are standard WinApi functions to perform 
the necessary operation, namely copying a color channel into the 
alpha channel, but I suspect there might be, in which case we won't 
lose performance there. 30.05.2019, 03:50, "KUSUMOTO Norio" 
:
Although it seems that to transfer the appropriate data to the 
device context is the 'right' solution, I have a hunch that it will 
be a difficult task. So I am beginning to think that we should take 
another, a cheat, approach. It's like a chroma key. Uniscribe draws 
text with a color background instead of transparency, and a word 
replaces the color with transpare

Re: [Factor-talk] Transparent background texts and Windows Factor

2019-05-30 Thread KUSUMOTO Norio
Thank you, Alexander!
I will read it and study.

I tried the idea I wrote earlier. I've only tried a little, but it seems to 
work well.
Yay!





--
KUSUMOTO Norio



> 2019/05/30 20:19、Alexander Ilin のメール:
> 
> Hello!
> 
>  I think I have figured out the algorithm for the image processing. I'm not 
> sure
>  if it's the same one that you came up with.
> 
>  https://github.com/factor/factor/issues/152#issuecomment-497292323
> 
>  Also, I don't know if there are standard WinApi functions to perform the
>  necessary operation, namely copying a color channel into the alpha
>  channel, but I suspect there might be, in which case we won't lose
>  performance there.
> 
> 30.05.2019, 03:50, "KUSUMOTO Norio" :
>> Although it seems that to transfer the appropriate data to the device 
>> context is
>> the 'right' solution, I have a hunch that it will be a difficult task.
>> So I am beginning to think that we should take another, a cheat, approach.
>> 
>> It's like a chroma key. Uniscribe draws text with a color background instead 
>> of
>> transparency, and a word replaces the color with transparency when converting
>> from the bitmap to an Factor's image.
>> 
>> It may be slow, but we don't have many chances to draw characters on a 
>> transparent
>> background. And for example, on a button label, once Factor creates an image 
>> with
>> such characters, Factor use the image again, so I think there are few 
>> problems.
>> 
>> This approach can localize changes. I can't define the word for image 
>> conversion to do
>> such a special action, but I think that it's not a difficult task for 
>> someone familiar with
>> image processing words.
> 
> 
> ---=--- 
> Александр
> 
> 
> 
> ___
> Factor-talk mailing list
> Factor-talk@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/factor-talk



___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk


Re: [Factor-talk] Transparent background texts and Windows Factor

2019-05-30 Thread Alexander Ilin
Hello!

  I think I have figured out the algorithm for the image processing. I'm not 
sure
  if it's the same one that you came up with.

  https://github.com/factor/factor/issues/152#issuecomment-497292323

  Also, I don't know if there are standard WinApi functions to perform the
  necessary operation, namely copying a color channel into the alpha
  channel, but I suspect there might be, in which case we won't lose
  performance there.

30.05.2019, 03:50, "KUSUMOTO Norio" :
> Although it seems that to transfer the appropriate data to the device context 
> is
> the 'right' solution, I have a hunch that it will be a difficult task.
> So I am beginning to think that we should take another, a cheat, approach.
>
> It's like a chroma key. Uniscribe draws text with a color background instead 
> of
> transparency, and a word replaces the color with transparency when converting
> from the bitmap to an Factor's image.
>
> It may be slow, but we don't have many chances to draw characters on a 
> transparent
> background. And for example, on a button label, once Factor creates an image 
> with
> such characters, Factor use the image again, so I think there are few 
> problems.
>
> This approach can localize changes. I can't define the word for image 
> conversion to do
> such a special action, but I think that it's not a difficult task for someone 
> familiar with
> image processing words.


---=--- 
 Александр



___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk


Re: [Factor-talk] Transparent background texts and Windows Factor

2019-05-29 Thread KUSUMOTO Norio
Although it seems that to transfer the appropriate data to the device context 
is 
the 'right' solution, I have a hunch that it will be a difficult task.
So I am beginning to think that we should take another, a cheat, approach.

It's like a chroma key. Uniscribe draws text with a color background instead of 
transparency, and a word replaces the color with transparency when converting 
from the bitmap to an Factor's image. 

It may be slow, but we don't have many chances to draw characters on a 
transparent 
background. And for example, on a button label, once Factor creates an image 
with 
such characters, Factor use the image again, so I think there are few problems.
 
This approach can localize changes. I can't define the word for image 
conversion to do 
such a special action, but I think that it's not a difficult task for someone 
familiar with 
image processing words.


> 2019/05/30 1:59、Alexander Ilin  のメール:
> 
> Wow, you are making a very valuable contribution!
> Thank you very much for the effort you are making!
> 
> It would be really great to have a solution for this issue.
> 
> 29.05.2019, 05:39, "KUSUMOTO Norio" :
>> It seems that the direction to solve the problem is not wrong.
>> But, we will need to transfer the appropriate data with the appropriate 
>> offset to the device context
>> where Uniscribe writes a text.
>> 
>> 


--
KUSUMOTO Norio



___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk


Re: [Factor-talk] Transparent background texts and Windows Factor

2019-05-29 Thread Alexander Ilin
Wow, you are making a very valuable contribution!
Thank you very much for the effort you are making!

It would be really great to have a solution for this issue.

29.05.2019, 05:39, "KUSUMOTO Norio" :
> It seems that the direction to solve the problem is not wrong.
> But, we will need to transfer the appropriate data with the appropriate 
> offset to the device context
> where Uniscribe writes a text.
>
> 
>

---=--- 
 Александр



___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk


Re: [Factor-talk] Transparent background texts and Windows Factor

2019-05-28 Thread KUSUMOTO Norio
It seems that the direction to solve the problem is not wrong.
But, we will need to transfer the appropriate data  with the appropriate offset 
to the device context 
where Uniscribe writes a text.



--
KUSUMOTO Norio



___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk


Re: [Factor-talk] Transparent background texts and Windows Factor

2019-05-28 Thread KUSUMOTO Norio
I seem to be a little too upset. I trusted machine translation too much. I'll 
fix it.


My guess seems to be correct. Uniscribe seems to be able to draw characters 
which have a transparent background on top of images transferred by BitBlt.

--
KUSUMOTO Norio



> 2019/05/28 22:27、KUSUMOTO Norio のメール:
> 
> My guess seems to be correct. Uniscribe seems to draw transparent characters 
> on top of images
> transferred via BitBlt.
> 



___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk


Re: [Factor-talk] Transparent background texts and Windows Factor

2019-05-28 Thread KUSUMOTO Norio
I did it. 

My guess seems to be correct. Uniscribe seems to draw transparent characters on 
top of images
transferred via BitBlt.


USING: accessors alien.c-types alien.data colors images.viewer
io io.encodings.string io.encodings.utf16n io.styles kernel
literals math sequences ui ui.commands ui.gadgets
ui.gadgets.borders ui.gadgets.panes ui.gadgets.tracks
ui.gestures windows.gdi32 windows.offscreen windows.ole32
windows.types windows.usp10 locals fonts windows.fonts
windows.errors ;
IN: hello-uniscribe


! NOTE:  The following declarations are required in gdi32.factor
!
!FUNCTION: int SetBkMode ( HDC hdc, int iBkMode )
!FUNCTION: BOOL BitBlt ( HDC hdc, int x, int y, int cx, int cy, HDC 
hdcSrc, int x1, int y1, DWORD rop )


TUPLE: hello-gadget < track ;

:  ( -- gadget )
horizontal hello-gadget new-track
[
{ { font-size 24 } } [
"Hello" print
"Grüß dich" print
"здравствуйте" print
"こんにちは" print
"안녕하세요" print
"שָׁלוֹם " print
] with-style
] make-pane { 10 10 } 
f track-add ;

:: com-screen-shot ( gadget -- )
[ :> dc
  gadget dim>> dc
  [
  dc 0 0 gadget dim>> first2 gadget parent>> handle>> hDC>> 0 0 SRCCOPY 
BitBlt drop
  ] make-bitmap-image image-window
] with-memory-dc ;

CONSTANT: ssa-dwFlags flags{ SSA_GLYPHS SSA_FALLBACK SSA_TAB }

:: (com-screen-shot-with-text) ( gadget dim bkMode uOptions -- )
[ :> dc
  dim dc [ 
  dc sans-serif-font cache-font SelectObject win32-error=0/f
  dc T{ rgba f 0.0 1.0 1.0 0.0 } color>RGB SetBkColor drop
  dc T{ rgba f 0.0 0.0 1.0 1.0 } color>RGB SetTextColor drop
  dc bkMode SetBkMode drop

  dc 0 0 dim first2 gadget parent>> handle>> hDC>> 0 0 SRCCOPY BitBlt 
drop

  dc
  "Hello!"
  [ utf16n encode ] ! pString
  [ length ] bi ! cString
  dup 1.5 * 16 + >integer ! cGlyphs -- MSDN says this is "recommended 
size"
  -1 ! iCharset -- Unicode
  ssa-dwFlags
  0 ! iReqWidth
  f ! psControl
  f ! psState
  f ! piDx
  f ! pTabdef
  f ! pbInClass
  f void*  ! pssa
  [ ScriptStringAnalyse ] keep
  [ check-ole32-error ] [ |ScriptStringFree void* deref ] bi*
  
  0 ! iX
  0 ! iY
  uOptions
  { 0 0 } dim 
  0 ! iMinSel
  0 ! iMaxSel
  FALSE ! fDisabled
  ScriptStringOut check-ole32-error
  ] make-bitmap-image image-window
] with-memory-dc ;

: com-screen-shot-with-text-opaque ( gadget -- )
dup dim>> OPAQUE ETO_OPAQUE (com-screen-shot-with-text) ;

: com-screen-shot-with-text-transparent-1 ( gadget -- )
dup dim>> OPAQUE 0 (com-screen-shot-with-text) ;

: com-screen-shot-with-text-transparent-2 ( gadget -- )
dup dim>> TRANSPARENT ETO_OPAQUE (com-screen-shot-with-text) ;

: com-screen-shot-with-text-transparent-3 ( gadget -- )
dup dim>> TRANSPARENT 0 (com-screen-shot-with-text) ;

hello-gadget "gestures" f {
{ T{ key-down { sym "1" } } com-screen-shot }
{ T{ key-down { sym "2" } } com-screen-shot-with-text-opaque }
{ T{ key-down { sym "3" } } com-screen-shot-with-text-transparent-1 }
{ T{ key-down { sym "4" } } com-screen-shot-with-text-transparent-2 }
{ T{ key-down { sym "5" } } com-screen-shot-with-text-transparent-3 }
} define-command-map

MAIN-WINDOW: hello-uniscribe { { title "გამარჯობა, uniscribe" } }
 >>gadgets ;




> 2019/05/28 19:07、KUSUMOTO Norio のメール:
> 
> Hi Alexander,
> 
> 
>> 2019/05/28 15:20、Alexander Ilin のメール:
>> 
>> Is it possible to tell Uniscribe to render the text in white color?
>> If such text shows up on the black background, that would confirm part of 
>> the theory.
> 
> Nice Idea.
> I modified the code to whiten the device context given by with-memory-dc 
> using PatBlt.
> Uniscribe works well with transparent background text.
> The next step should be to use BitBlt.

--
KUSUMOTO Norio




___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk


Re: [Factor-talk] Transparent background texts and Windows Factor

2019-05-28 Thread KUSUMOTO Norio
Hi Alexander,


> 2019/05/28 15:20、Alexander Ilin のメール:
> 
>  Is it possible to tell Uniscribe to render the text in white color?
>  If such text shows up on the black background, that would confirm part of 
> the theory.

Nice Idea.
I modified the code to whiten the device context given by with-memory-dc using 
PatBlt.
Uniscribe works well with transparent background text.
The next step should be to use BitBlt.




USING: accessors alien.c-types alien.data colors images.viewer
io io.encodings.string io.encodings.utf16n io.styles kernel
literals math sequences ui ui.commands ui.gadgets
ui.gadgets.borders ui.gadgets.panes ui.gadgets.tracks
ui.gestures windows.gdi32 windows.offscreen windows.ole32
windows.types windows.usp10 locals fonts windows.fonts
windows.errors ;
IN: hello-uniscribe


! NOTE:  The following declarations are required in gdi32.factor
!
!FUNCTION: int SetBkMode ( HDC hdc, int iBkMode )
!FUNCTION: BOOL PatBlt ( HDC hdc, int x, int y, int width, int height, 
DWORD rop )


TUPLE: hello-gadget < track ;

:  ( -- gadget )
horizontal hello-gadget new-track
[
{ { font-size 24 } } [
"Hello" print
"Grüß dich" print
"здравствуйте" print
"こんにちは" print
"안녕하세요" print
"שָׁלוֹם " print
] with-style
] make-pane { 10 10 } 
f track-add ;

:: com-screen-shot ( gadget -- )
[ :> dc
  gadget dim>> dc
  [
  dc 0 0 gadget dim>> first2  WHITENESS PatBlt drop
  ] make-bitmap-image image-window
] with-memory-dc ;

CONSTANT: ssa-dwFlags flags{ SSA_GLYPHS SSA_FALLBACK SSA_TAB }

:: (com-screen-shot-with-text) ( dim bkMode uOptions -- )
[ :> dc
  dim dc [ 
  dc sans-serif-font cache-font SelectObject win32-error=0/f
  dc T{ rgba f 0.0 1.0 1.0 0.0 } color>RGB SetBkColor drop
  dc T{ rgba f 0.0 0.0 1.0 1.0 } color>RGB SetTextColor drop
  dc bkMode SetBkMode drop

  dc 0 0 dim first2 WHITENESS PatBlt drop
  
  dc
  "Hello!"
  [ utf16n encode ] ! pString
  [ length ] bi ! cString
  dup 1.5 * 16 + >integer ! cGlyphs -- MSDN says this is "recommended 
size"
  -1 ! iCharset -- Unicode
  ssa-dwFlags
  0 ! iReqWidth
  f ! psControl
  f ! psState
  f ! piDx
  f ! pTabdef
  f ! pbInClass
  f void*  ! pssa
  [ ScriptStringAnalyse ] keep
  [ check-ole32-error ] [ |ScriptStringFree void* deref ] bi*
  
  0 ! iX
  0 ! iY
  uOptions
  { 0 0 } dim 
  0 ! iMinSel
  0 ! iMaxSel
  FALSE ! fDisabled
  ScriptStringOut check-ole32-error
  ] make-bitmap-image image-window
] with-memory-dc ;

: com-screen-shot-with-text-opaque ( gadget -- )
dim>> OPAQUE ETO_OPAQUE (com-screen-shot-with-text) ;

: com-screen-shot-with-text-transparent-1 ( gadget -- )
dim>> OPAQUE 0 (com-screen-shot-with-text) ;

: com-screen-shot-with-text-transparent-2 ( gadget -- )
dim>> TRANSPARENT ETO_OPAQUE (com-screen-shot-with-text) ;

: com-screen-shot-with-text-transparent-3 ( gadget -- )
dim>> TRANSPARENT 0 (com-screen-shot-with-text) ;

hello-gadget "gestures" f {
{ T{ key-down { sym "1" } } com-screen-shot }
{ T{ key-down { sym "2" } } com-screen-shot-with-text-opaque }
{ T{ key-down { sym "3" } } com-screen-shot-with-text-transparent-1 }
{ T{ key-down { sym "4" } } com-screen-shot-with-text-transparent-2 }
{ T{ key-down { sym "5" } } com-screen-shot-with-text-transparent-3 }
} define-command-map

MAIN-WINDOW: hello-uniscribe { { title "გამარჯობა, uniscribe" } }
 >>gadgets ;



--
KUSUMOTO Norio



> 2019/05/28 15:20、Alexander Ilin のメール:
> 
>  Is it possible to tell Uniscribe to render the text in white color?
>  If such text shows up on the black background, that would confirm part of 
> the theory.



___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk


Re: [Factor-talk] Transparent background texts and Windows Factor

2019-05-27 Thread Alexander Ilin
Hello!

28.05.2019, 08:37, "KUSUMOTO Norio" :
> Hello all,
>
> I've been researching for a while about Windows Factor's inability to 
> correctly render texts on
> transparent backgrounds. I haven't solved the problem yet, but I've just come 
> to an idea.
> I'd be happy to hear your opinions on that.
>
> For example, labels for button widgets are tentatively drawn with gray 
> background text because
> they cannot draw labels with a transparent background. I disabled this 
> behavior and tried to make
> transparent drawing work correctly, but only on a black background. I kept 
> trying to figure
> out what was behind the black background, but I couldn't find the widget.
>
> That's why I came up with the idea that Uniscribe works to make the 
> background transparent,
> but where the characters are written is black. At first it seemed like a 
> silly idea, but I wrote
> the code to confirm it.

  Is it possible to tell Uniscribe to render the text in white color?
  If such text shows up on the black background, that would confirm part of the 
theory.

---=--- 
 Александр



___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk


Re: [Factor-talk] Transparent background texts and Windows Factor

2019-05-27 Thread KUSUMOTO Norio
Sorry, the last sentences are wrong, so I will correct them.

What I found when I read uniscribe-factor is that a bitmap is created with the 
device context 
given by with-memory-dc. However, if you simply use that dc, the bitmap has a 
black background.

My guess is that you won't be able to create an image of a string with a 
transparent background 
unless you transfer the original window bitmap to the device context created by 
with-memory-dc.

--
KUSUMOTO Norio





> 2019/05/28 14:36、KUSUMOTO Norio  のメール:
> 
> Hello all, 
> 
> I've been researching for a while about Windows Factor's inability to 
> correctly render texts on 
> transparent backgrounds. I haven't solved the problem yet, but I've just come 
> to an idea. 
> I'd be happy to hear your opinions on that.
> 
> For example, labels for button widgets are tentatively drawn with gray 
> background text because 
> they cannot draw labels with a transparent background. I disabled this 
> behavior and tried to make 
> transparent drawing work correctly, but only on a black background. I kept 
> trying to figure 
> out what was behind the black background, but I couldn't find the widget.
> 
> That's why I came up with the idea that Uniscribe works to make the 
> background transparent, 
> but where the characters are written is black. At first it seemed like a 
> silly idea, but I wrote 
> the code to confirm it.
> 
> 
> USING: accessors alien.c-types alien.data colors images.viewer
> io io.encodings.string io.encodings.utf16n io.styles kernel
> literals math sequences ui ui.commands ui.gadgets
> ui.gadgets.borders ui.gadgets.panes ui.gadgets.tracks
> ui.gestures windows.gdi32 windows.offscreen windows.ole32
> windows.types windows.usp10 locals fonts windows.fonts
> windows.errors ;
> IN: hello-uniscribe
> 
> 
> ! NOTE:  The following declaration is required in gdi32.factor
> !
> !FUNCTION: int SetBkMode ( HDC hdc, int iBkMode )
> 
> TUPLE: hello-gadget < track ;
> 
> :  ( -- gadget )
>horizontal hello-gadget new-track
>[
>{ { font-size 24 } } [
>"Hello" print
>"Grüß dich" print
>"здравствуйте" print
>"こんにちは" print
>"안녕하세요" print
>"שָׁלוֹם " print
>] with-style
>] make-pane { 10 10 } 
>f track-add ;
> 
> :: com-screen-shot ( gadget -- )
>[ :> dc
> gadget dim>> dc [ ] make-bitmap-image image-window
>] with-memory-dc ;
> 
> CONSTANT: ssa-dwFlags flags{ SSA_GLYPHS SSA_FALLBACK SSA_TAB }
> 
> :: (com-screen-shot-with-text) ( dim bkMode uOptions -- )
>[ :> dc
>  dim dc [ 
>  dc sans-serif-font cache-font SelectObject win32-error=0/f
>  dc T{ rgba f 0.0 0.0 1.0 0.0 } color>RGB SetBkColor drop
>  dc T{ rgba f 1.0 1.0 1.0 1.0 } color>RGB SetTextColor drop
>  dc bkMode SetBkMode drop
> 
>  dc
>  "Hello!"
>  [ utf16n encode ] ! pString
>  [ length ] bi ! cString
>  dup 1.5 * 16 + >integer ! cGlyphs -- MSDN says this is "recommended 
> size"
>  -1 ! iCharset -- Unicode
>  ssa-dwFlags
>  0 ! iReqWidth
>  f ! psControl
>  f ! psState
>  f ! piDx
>  f ! pTabdef
>  f ! pbInClass
>  f void*  ! pssa
>  [ ScriptStringAnalyse ] keep
>  [ check-ole32-error ] [ |ScriptStringFree void* deref ] bi*
> 
>  0 ! iX
>  0 ! iY
>  uOptions
>  { 0 0 } dim 
>  0 ! iMinSel
>  0 ! iMaxSel
>  FALSE ! fDisabled
>  ScriptStringOut check-ole32-error
>  ] make-bitmap-image image-window
>] with-memory-dc ;
> 
> : com-screen-shot-with-text-opaque ( gadget -- )
>dim>> OPAQUE ETO_OPAQUE (com-screen-shot-with-text) ;
> 
> : com-screen-shot-with-text-transparent-1 ( gadget -- )
>dim>> OPAQUE 0 (com-screen-shot-with-text) ;
> 
> : com-screen-shot-with-text-transparent-2 ( gadget -- )
>dim>> TRANSPARENT ETO_OPAQUE (com-screen-shot-with-text) ;
> 
> : com-screen-shot-with-text-transparent-3 ( gadget -- )
>dim>> TRANSPARENT 0 (com-screen-shot-with-text) ;
> 
> hello-gadget "gestures" f {
>{ T{ key-down { sym "1" } } com-screen-shot }
>{ T{ key-down { sym "2" } } com-screen-shot-with-text-opaque }
>{ T{ key-down { sym "3" } } com-screen-shot-with-text-transparent-1 }
>{ T{ key-down { sym "4" } } com-screen-shot-with-text-transparent-2 }
>{ T{ key-down { sym "5" } } com-screen-shot-with-text-transparent-3 }
> } define-command-map
> 
> MAIN-WINDOW: hello-uniscribe { { title "გამარჯობა, uniscribe" } }
> >>gadgets ;
> 
> 
> My understanding from reading Uniscribe.factor is that it renders characters 
> in the device context 
> given by with-memory-dc. However, if you create a bitmap from that dc, its 
> background is black, 
> regardless of the drawing on the current window.
> 
> My guess is that you won't be able to create an image of a string with a 
> transparent background 
>

[Factor-talk] Transparent background texts and Windows Factor

2019-05-27 Thread KUSUMOTO Norio
Hello all, 

I've been researching for a while about Windows Factor's inability to correctly 
render texts on 
transparent backgrounds. I haven't solved the problem yet, but I've just come 
to an idea. 
I'd be happy to hear your opinions on that.

For example, labels for button widgets are tentatively drawn with gray 
background text because 
they cannot draw labels with a transparent background. I disabled this behavior 
and tried to make 
transparent drawing work correctly, but only on a black background. I kept 
trying to figure 
out what was behind the black background, but I couldn't find the widget.

That's why I came up with the idea that Uniscribe works to make the background 
transparent, 
but where the characters are written is black. At first it seemed like a silly 
idea, but I wrote 
the code to confirm it.


USING: accessors alien.c-types alien.data colors images.viewer
io io.encodings.string io.encodings.utf16n io.styles kernel
literals math sequences ui ui.commands ui.gadgets
ui.gadgets.borders ui.gadgets.panes ui.gadgets.tracks
ui.gestures windows.gdi32 windows.offscreen windows.ole32
windows.types windows.usp10 locals fonts windows.fonts
windows.errors ;
IN: hello-uniscribe


! NOTE:  The following declaration is required in gdi32.factor
!
!FUNCTION: int SetBkMode ( HDC hdc, int iBkMode )

TUPLE: hello-gadget < track ;

:  ( -- gadget )
horizontal hello-gadget new-track
[
{ { font-size 24 } } [
"Hello" print
"Grüß dich" print
"здравствуйте" print
"こんにちは" print
"안녕하세요" print
"שָׁלוֹם " print
] with-style
] make-pane { 10 10 } 
f track-add ;

:: com-screen-shot ( gadget -- )
[ :> dc
 gadget dim>> dc [ ] make-bitmap-image image-window
] with-memory-dc ;

CONSTANT: ssa-dwFlags flags{ SSA_GLYPHS SSA_FALLBACK SSA_TAB }

:: (com-screen-shot-with-text) ( dim bkMode uOptions -- )
[ :> dc
  dim dc [ 
  dc sans-serif-font cache-font SelectObject win32-error=0/f
  dc T{ rgba f 0.0 0.0 1.0 0.0 } color>RGB SetBkColor drop
  dc T{ rgba f 1.0 1.0 1.0 1.0 } color>RGB SetTextColor drop
  dc bkMode SetBkMode drop

  dc
  "Hello!"
  [ utf16n encode ] ! pString
  [ length ] bi ! cString
  dup 1.5 * 16 + >integer ! cGlyphs -- MSDN says this is "recommended 
size"
  -1 ! iCharset -- Unicode
  ssa-dwFlags
  0 ! iReqWidth
  f ! psControl
  f ! psState
  f ! piDx
  f ! pTabdef
  f ! pbInClass
  f void*  ! pssa
  [ ScriptStringAnalyse ] keep
  [ check-ole32-error ] [ |ScriptStringFree void* deref ] bi*
  
  0 ! iX
  0 ! iY
  uOptions
  { 0 0 } dim 
  0 ! iMinSel
  0 ! iMaxSel
  FALSE ! fDisabled
  ScriptStringOut check-ole32-error
  ] make-bitmap-image image-window
] with-memory-dc ;

: com-screen-shot-with-text-opaque ( gadget -- )
dim>> OPAQUE ETO_OPAQUE (com-screen-shot-with-text) ;

: com-screen-shot-with-text-transparent-1 ( gadget -- )
dim>> OPAQUE 0 (com-screen-shot-with-text) ;

: com-screen-shot-with-text-transparent-2 ( gadget -- )
dim>> TRANSPARENT ETO_OPAQUE (com-screen-shot-with-text) ;

: com-screen-shot-with-text-transparent-3 ( gadget -- )
dim>> TRANSPARENT 0 (com-screen-shot-with-text) ;

hello-gadget "gestures" f {
{ T{ key-down { sym "1" } } com-screen-shot }
{ T{ key-down { sym "2" } } com-screen-shot-with-text-opaque }
{ T{ key-down { sym "3" } } com-screen-shot-with-text-transparent-1 }
{ T{ key-down { sym "4" } } com-screen-shot-with-text-transparent-2 }
{ T{ key-down { sym "5" } } com-screen-shot-with-text-transparent-3 }
} define-command-map

MAIN-WINDOW: hello-uniscribe { { title "გამარჯობა, uniscribe" } }
 >>gadgets ;


My understanding from reading Uniscribe.factor is that it renders characters in 
the device context 
given by with-memory-dc. However, if you create a bitmap from that dc, its 
background is black, 
regardless of the drawing on the current window.

My guess is that you won't be able to create an image of a string with a 
transparent background 
unless you transfer the original window bitmap to the device context created by 
with-memory-dc.

--
KUSUMOTO Norio







___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk