r3wp [groups: 83 posts: 189283]
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

World: r3wp

[View] discuss view related issues

Anton
21-Apr-2008
[7677]
The above update also cleans up loose words in the auto-crop-bitmap-text.r 
file.
Graham
21-Apr-2008
[7678x2]
I added a /pad option to mine so that it returns the text with a 
white space border.
which is needed for some ocr engines
Anton
21-Apr-2008
[7680x5]
/border
 makes more sense, doesn't it ?
maybe not...
updated 
	auto-crop-bitmap-text.r
removed old code and comments (file is 3.5k smaller)
updated again
	auto-crop-bitmap-text.r
replaced old comments with new ones.
Hmm.. I think the image padding might be outside the responsibility 
of an auto-crop function. Its job is to remove stuff, not add. It's 
probably better to write a small generalised function to do the padding 
(which could be useful elsewhere) and just feed the result of the 
auto-crop to it.
Graham
21-Apr-2008
[7685x2]
you're probably right
though it could be auto-crop to  as it were.
Anton
21-Apr-2008
[7687]
I think if you're going to make an "all-in-one" function, then its 
name should reflect that. eg. 
	crop-and-pad-ready-for-ocr: func [image][
		pad-image auto-crop-bitmap-text image 1x1
	]

(where pad-image is adding a 1x1 white border around the cropped 
image.)
Graham
21-Apr-2008
[7688x2]
auto-crop-bitmap-text: func ["Returns a cropped image, or none if 
the input image was blank"
	image [image!] 
	/local region
][
	if region: find-bitmap-text-crop-region image [ 

  copy/part skip image region/1 region/2  ; return a cropped image
	]
]

Looking at this, it appears to return unset! if region is none!
How about this 

	

auto-crop-bitmap-text: func ["Returns a cropped image, or none if 
the input image was blank"
	image [image!] 
	/local region
][
	all [
	 	region: find-bitmap-text-crop-region image  
		region: copy/part skip image region/1 region/2 
	]
	region
]
Anton
21-Apr-2008
[7690x2]
IF returns none when given false.
And your code redefines the meaning of 'region (which by itself is 
bad because it can cause confusion later) unnecessarily.
I could rewrite it more simply:
	all [
		region: find-bitmap-text-crop-region image
		copy/part skip image region/1 region/2
	]
but that's just equivalent to my IF above.
Graham
21-Apr-2008
[7692x3]
Ah ... ok.
I think it would be nice now to have the crop work on the sides as 
well.
Would it be hard to write a deskewing function?  basically I guess 
one finds a best fit horizontal line for the base of the text one 
finds, and then returns the angle needed to deskew it.
Anton
22-Apr-2008
[7695]
Is it really skew or do you mean rotate ?
Graham
22-Apr-2008
[7696x2]
It's normally called skew but it's the same.
To crop the right and left edges I think we can just rotate the image 
90 deg, crop it with the existing routines and then rotate it back 
again
Reichart
22-Apr-2008
[7698]
Smart...
Anton
22-Apr-2008
[7699x2]
I was going to say that modifying the code to support horizontal 
cropping should be pretty easy. But that method is even easier !
(if a bit hackish.)
Graham
22-Apr-2008
[7701]
Seems to work ... but I have to rotate 270 deg and not -90 to get 
the original orientation back.  Does effect not take a negative rotation?
Geomol
22-Apr-2008
[7702]
Seems to only do 0, 90, 180 and 270:
http://www.rebol.com/docs/view-system.html#section-9.5
Graham
22-Apr-2008
[7703]
Ahh.. that's no fun.  So, I can't use this to deskew.
Geomol
22-Apr-2008
[7704]
Do you know, how to use DRAW to do image transformations?
Graham
22-Apr-2008
[7705x2]
nope
I usually learn enough about view to do something I need and then 
promptly forget it :(
Geomol
22-Apr-2008
[7707]
You can rotate an image in DRAW like this:


view layout [box effect [draw [translate 40x0 rotate 60 image logo.gif]]]
Graham
22-Apr-2008
[7708x3]
that's how I'm doing the rotation now.
uhmm.. maybe not.
I'll try that out :)
Anton
23-Apr-2008
[7711]
( yes,  effect [draw [rotate]]  is different than  effect [rotate] 
)
Pekr
3-May-2008
[7712x2]
Here's small challenge. I created following script which is surely 
full of junk. I am not good View coder :-) Now who helps me to simplify 
it and to get the movement smoother? :-)
screen-size: system/view/screen-face/size
news-bottom-offset: 0x100
news-height: 0x100

message: "This is short news scroller. Who makes me smooth? ..."

;--- style for draw dialect
bold64: make face/font [style: 'bold size: 64 color: white]


;--- But how to calculate text size for draw? Here's a workaround 
...
txt: make face compose [size: 2000X200 text: (message)]
txt/font: make face/font [style: 'bold size: 64 color: white]
text-size: size-text txt


view/offset/options layout/size [
  backcolor green

  ;--- we start behind the screen ....
  at (to-pair reduce [screen-size/x 10])

  t: box (to-pair reduce [2000 news-height/y]) ;--- box size ...
       effect compose/deep [
         draw [
           font bold64
           text (message)
         ]
        ] 
       rate 50
       feel [
         engage: func [f a e][
           if a = 'time [
             ;--- zde nastavujeme rychlost posuvu
             f/offset: f/offset - 3x0

             if (f/offset/x + (first text-size)) < 0 [f/offset/x: screen-size/x]
             show f  
         ]
        ]
      ]

] (to-pair reduce [screen-size/x news-height/y])(to-pair reduce [0 
(screen-size/y - news-bottom-offset/y - news-height/y)])[no-border 
no-title]
Anton
3-May-2008
[7714]
I don't think you can make it 100% smooth without knowing when the 
screen refreshes.

You have two faces (which you might need long term), but you could 
probably achieve the same text scrolling effect with just one face 
by modifying its para/offset.
Anton
4-May-2008
[7715x5]
No, you can't :) Of course, the window/text goes to the title-bar.
(so to get text in a window you always need at least one subface.)
Yes, you can :) but it's using Draw dialect text.
view/new window: make face [
	size: 800x150
	font: make face/font [size: 40]

 effect: compose/deep [draw [font (font) text 100x50 "Hello there"]]
	rate: 50
]
window/feel: make window/feel [
	engage: func [face action event][
		if action = 'time [
			window/effect/draw/text/x: window/effect/draw/text/x - 1
			show window
		]
	]
]
do-events
i
Anyway, it doesn't fix the basic problem.
Brock
4-May-2008
[7720]
Is it possible that 'jitter' that occures in Pekrs nice example sharing 
the same root cause as the 'heart-beat' that Geomol mentioned in 
a previous post?
Pekr
4-May-2008
[7721x2]
not sure. HeartBeat might be TCP related. On my Core 2 duo I am not 
observing jitter, just not smooth animation. Now remember that Amiga 
with 7MHz CPU was able to provide us with absolutly smooth scrolling. 
But Win32API lacks vertical blanking period synchronisation, so I 
wonder if without DirectX or OpenGL we are able to actually make 
our situation better ...
Some time ago Carl told us, that View uses double buffering, but 
apparently it is not enough ....
TimW
8-May-2008
[7723]
Is there a way to have a face receive mouse input that is recieved 
via layouts in the faces pane?  This sounds weird, but when building 
components, if there is a generic face object that they all share, 
then on top of that face you add a layout with certain styles.  Is 
there a way(without adding a handler in the layout) to have the face 
receive the message as well?
Gregg
8-May-2008
[7724x2]
Have you tried DETECT? http://www.rebol.com/how-to/feel.html#sect6.
I rarely use detect, but use insert-event-func quite often.
TimW
11-May-2008
[7726]
That might be what I need.  Messing with it seemed to overwrite some 
other handlers.  Suppose you have this:  my-face: make face [
			offset: offs
			size: sz
			color: 0.0.0

   text: win-title ;rejoin[window-counter ":" name] ;should this be 
   copy name?
			plugid: plug-id
			id: window-counter
			pane: copy []]