NumToChar in LCB?
NumToChar in LCB?
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
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
Trevix
OSX 14.3.1 xCode 15 LC 10 DP7 iOS 15> Android 7>
OSX 14.3.1 xCode 15 LC 10 DP7 iOS 15> Android 7>
-
- VIP Livecode Opensource Backer
- Posts: 4000
- Joined: Sun Jan 07, 2007 9:12 pm
- Location: Bochum, Germany
Re: NumToChar in LCB?
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
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?
Mmmmh...
this compile OK but returns me and error at line 12, given AdditionTest("abcd"), while should return "abc":
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
Trevix
OSX 14.3.1 xCode 15 LC 10 DP7 iOS 15> Android 7>
OSX 14.3.1 xCode 15 LC 10 DP7 iOS 15> Android 7>
Re: NumToChar in LCB?
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?
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?
Trevix
OSX 14.3.1 xCode 15 LC 10 DP7 iOS 15> Android 7>
OSX 14.3.1 xCode 15 LC 10 DP7 iOS 15> Android 7>
-
- VIP Livecode Opensource Backer
- Posts: 4000
- Joined: Sun Jan 07, 2007 9:12 pm
- Location: Bochum, Germany
Re: NumToChar in LCB?
Hi Trevix,
this works for me
You were trying to put binary data into a string-type variable. That did not work.
Look at the extensive and excellent examples from Hermann regarding LCB and imageData. Good stuff to learn from.
Kind regards
Bernd
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
As far as speed is concerned it all depends. But don't expect LCB to be considerably faster than LCS.put the byte with code tNum into tNumText
Look at the extensive and excellent examples from Hermann regarding LCB and imageData. Good stuff to learn from.
Kind regards
Bernd
-
- VIP Livecode Opensource Backer
- Posts: 2262
- Joined: Thu Feb 28, 2013 11:52 pm
- Location: Göttingen, DE
Re: NumToChar 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.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?
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).
shiftLock happens
Re: NumToChar in LCB?
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).
Brian Milby
Script Tracker https://github.com/bwmilby/scriptTracker
Script Tracker https://github.com/bwmilby/scriptTracker