Page 1 of 1
NumToChar in LCB?
Posted: Fri Mar 29, 2019 5:30 pm
by trevix
Trying to work on images...
I understand that "the cod of tChar" give me the numeric code of the character.
What is the reverse of it? (on LCS would be NumToChar()
Trevix
Re: NumToChar in LCB?
Posted: Fri Mar 29, 2019 6:10 pm
by bn
Does this help?
ByteWithCode
Type operator
Syntax
the byte with code Value
Summary
Create a 1-byte data value from a number
Edition
Community
Associations
com.livecode.byte
Parameters
Name: Value
Description:
The value for the new data value
Description
Returns a byte of binary data, created using the given value. The
Value must be between 0 and 255 (inclusive).
Kind regards
Bernd
Re: NumToChar in LCB?
Posted: Sat Mar 30, 2019 9:47 pm
by trevix
Mmmmh...
this compile OK but returns me and error at line 12, given AdditionTest("abcd"), while should return "abc":
Code: Select all
library community.livecode.trevix.testmathuno
metadata version is "1.0.0"
metadata author is "trevix"
metadata title is "TestMathUno Library"
public handler AdditionTest(in pText as String) returns String
variable tNumText as String
variable tResult as String
variable tNum as Number
variable tCounter as Number
repeat with tCounter from 1 up to 3
put the code of (char tCounter of pText) into tNum --IS A Number 0-255
put the byte with code tNum into tNumText
put tNumText after tResult
end repeat
log[tResult]
return tResult
end handler
end library
Re: NumToChar in LCB?
Posted: Sat Mar 30, 2019 9:56 pm
by trevix
Also, since you seem to be knowledgable, what speed gain can I expect form LCB?
In LCS, a inverse conversion of an image area (make it negative) takes me roughly 7 seconds.
What do you think could be the time for the same routine in LCB?
Re: NumToChar in LCB?
Posted: Sun Mar 31, 2019 12:49 pm
by bn
Hi Trevix,
this works for me
Code: Select all
library community.livecode.trevix.testmathuno
metadata version is "1.0.0"
metadata author is "trevix"
metadata title is "TestMathUno Library"
public handler AdditionTest(in pText as String) returns String
variable tNumData as Data
variable tResult as String
variable tNum as Number
variable tCounter as Number
variable tDataToNum as Number
repeat with tCounter from 1 up to 3
put the code of (char tCounter of pText) into tNum --IS A Number 0-255
put tNum formatted as string & newline after tResult
put the byte with code tNum into tNumData -- tNumData is binary
put the code of tNumData into tDataToNum -- convert to Number
put tDataToNum formatted as string & newline after tResult
end repeat
--log[tResult]
return tResult
end handler
end library
You were trying to put binary data into a string-type variable. That did not work.
put the byte with code tNum into tNumText
As far as speed is concerned it all depends. But don't expect LCB to be considerably faster than LCS.
Look at the extensive and excellent examples from Hermann regarding LCB and imageData. Good stuff to learn from.
Kind regards
Bernd
Re: NumToChar in LCB?
Posted: Sun Mar 31, 2019 2:32 pm
by [-hh]
trevix wrote:What speed gain can I expect from LCB?
In LCS, a inverse conversion of an image area (make it negative) takes me roughly 7 seconds.
What do you think could be the time for the same routine in LCB?
The best way to know this is to walk through the bytes of imageData (= the pixels in LCB), without doing anything with them: It is muuuuch slower. Even using Java via FFI is not faster than LCS.
But LCB is very fast with canvas methods you don't have available in LCS, like transforms (I use these with widget imagewidget).
By far the fastest (directly available) way to handle raw imageData is JavaScript via a browser widget (because JS uses your GPU).
Re: NumToChar in LCB?
Posted: Sun Mar 31, 2019 6:47 pm
by bwmilby
A while back I did some speed comparisons for finding primes and LCS was much faster than LCB. The speed gains in LCB will currently come when it is leveraging compiled code (like the transforms that were mentioned).