|
Post by tenochtitlanuk on Dec 14, 2020 16:29:56 GMT -5
LB's 'set' is slow, because of all the background work in updating and displaying an image, and getpixel is indeed much faster with dll or the pixel-file-save methods. Don't really understand your program and context. For me I've had a lot of fun saving pixel data in a 2D array and saving it as a BMP when needed, so it can be used on-screen via 'loadbmp'. This image shows an initial image, and versions where I swapped all R and B components; where I grey-scaled all pixels; and where I vignetted all within a circle. Takes a second or two with my method- but ages using getting and setting pixels.
|
|
|
Post by tenochtitlanuk on Dec 10, 2020 10:20:25 GMT -5
This is code to produce a 24 bit BMP programmatically at your choice of size. I'll add the line drawing/circles/fill/etc soon- they all write to the bmp-file as an array in memory, so it just needs dumping to file after any operations you do. Here I use a calculated fill as an excuse to put up a colourful output! Impressively fast in LB- once I realised the first version was taking ridiculously long. I was assembling the string of triad pixels as a data$ to send to file in one go. Too much claiming and releasing memory really hung things up. Memo to self- send calculated bytes to file as they are calculated! It also pointed out that LB5 regards ' data' as a reserved word, unlike LB4. And is a bit picky on whether you use ' #file,' or just ' #file' or ' print #file' to send data to a file. . nomainwin ' NB data is stored 'little-endian', ie lsb first, as unsigned integers of 16 or 32 bits
open "test6.bmp" for output as #bmp
filetype$ ="BM" reserved$ =FourByteString$( 0) offset$ =FourByteString$( 54) bmpheader$ =FourByteString$( 40) width = 512 height = 512 width$ =FourByteString$( width) height$ =FourByteString$( height) last =( width *3) mod 4 ' find how many of the last 4 bytes are already used pad =4 -last ' and thus how many to add filesize =54 +( width +pad) *3 *height ' ie header ( 54 bytes) +bitmapdata ( calculated). filesize$ =FourByteString$( filesize)
#bmp filetype$ +filesize$ +reserved$ +offset$; ' <<<<<<
planes$ =chr$( 1) +chr$( 0) bits$ =chr$( 24) +chr$( 0) ' data stored in triple-bytes, 8 bits per colour. compression$=FourByteString$( 0) ignore$ =FourByteString$( 0) +FourByteString$( 0) +FourByteString$( 0) +FourByteString$( 0)
bmpsize$ =FourByteString$( filesize)
o$ = bmpheader$ +width$ +height$ +planes$ +bits$ +compression$ +bmpsize$ +ignore$ +datt$ ' <<<<<< #bmp o$;
for count =1 to height N =int( count /height *255) bytes =0
for count2 =1 to width ' data is R B G pixels. O =int( 255 *count2 /width) ' colour order is BGR. #bmp chr$( O) +chr$( 255 -O) +chr$( N); ' <<<<<< bytes =bytes +3 next count2
' however each row has to be represented by multiples of four bytes, so add as necessary. if ( bytes mod 4) <>0 then b =4 -( bytes mod 4) for k =1 to b #bmp chr$( 0); ' could be any byte as padding.... ' <<<<<<
bytes =bytes +1 next k
next count
|
|
|
Post by tenochtitlanuk on Dec 7, 2020 16:57:47 GMT -5
It indicates you need to allocate TWO character positions before the decimal point, so change to
mean$ = using("##.#######", mean)
|
|
|
Post by tenochtitlanuk on Nov 28, 2020 9:13:27 GMT -5
For interest, JB was slightly faster than LB4, but LB5 wins hands down....
Sorry I didn't correct for the faultyLB5 time$( "seconds") reporting in milliseconds!
|
|
|
Post by tenochtitlanuk on Nov 27, 2020 17:06:26 GMT -5
The Linux LB ( at least- haven't tried MS version) gets confused over CR and LF conventions. Took me ages to see what was happening here.
I read a text section at the beginning of a long file. It uses x0A as separator. I save it back to a new file. The x0A are changed to x0D!
The next 750000 bytes are pixel triads. Not sure if any that happen to have values of 10 or 13 also get changed!
It's also a nuisance not having a working lof() or word$(). Lof() I can bypass since I know section lengths. Word$() I wrote a function to do.
|
|
|
Post by tenochtitlanuk on Nov 27, 2020 14:32:34 GMT -5
A poster on JB forum was interested in changing bmp files, pixel by pixel. Something I've done a lot.
In the words of the Irishman asked how to get to Dublin and replying 'Well I wouldn't start from here'. Gonna be slow....
The method I've showed recently, of working on ppm images at file level, produces the two transforms of a 500x500 image seen below in about 2.5 seconds each in LB5 on Linux on an old laptop. First image read as triplets of RGB. Re-written with RGB interchanged or rotated.
Slower on LB4, and problems in JB for some reason. Will post the points or problems that came up on the appropriate forum section. For example, he unfinished time$() always giving times in ms was worrying when it implied I must have gone to sleep for an hour or so!!
I'd hoped to have the same code run on all three platforms for comparison, but have yet to achieve it. Page on my site soon with code...
|
|
|
Post by tenochtitlanuk on Nov 27, 2020 14:18:20 GMT -5
Agree about UBW/UBW32. Use mine regularly for stepper motor projects etc, as shown on my site. So simple to make x/y motion, run servos, etc.
Have programmed microcontrollers in the past, but am not into the Arduino world. Play too much on LB and Raspberry Pi projects.. and I also am getting to grips with LB5 idiosyncracies!
My first computer was a hard-wired set up of an RCA1802. Lovely way to get bits and bytes in and out- but so slow and weak compared with modern microcontrollers, let alone computers-on-a-chip.
I had the ADC ready and unused. Took only minutes to run it on LB on MS. Took rather longer to sort out why it was not working on LB under Wine, when the device was recognised!
Your help was very good and encouraging. What I missed seems to be I had to do the regedit to remove the existing link of com port to allow the new one to be recognised. Will try on a virgin installation again and document exactly what I changed!
Thanks again
|
|
|
Post by tenochtitlanuk on Nov 26, 2020 4:38:19 GMT -5
LB5 on Linux Mint When I print long strings, there is a line feed inserted at the present width of mainwin- for the first line only. Visible when you resize the displayed string window... further lines correctly carry on to the ( large) required length.
for i =1 to 1000 o$ =o$ +right$( "...." +str$( i), 4) next i
print o$
|
|
|
Post by tenochtitlanuk on Nov 24, 2020 14:54:16 GMT -5
A cheap ADC card plugs in your USB port and streams ten data channels. What's not to like!
I bought this board some months ago, and needed to check out some old LiPo batteries. A page on my site gives more details. And I finally got LB/Wine/Linux to work with USB serial devices! An earlier correspondence with gidiom2 got me NEARLY there. And the code may give useful ideas to johnking and others.
|
|
|
Post by tenochtitlanuk on Nov 20, 2020 4:45:36 GMT -5
Yup- that's why I changed my nested if/thens to expanded forms...
|
|
|
Post by tenochtitlanuk on Nov 19, 2020 17:25:15 GMT -5
The following code works for your sample files. May give you some ideas. I get first a list of the first fields for each cow and assemble in a string, then do the same for the second file. Then I check systematically for ones in one file which are also in the second. Without genuine long one I've no idea how long it would take to list the ones in both files...
I've no idea how to automate sending a sms message...
open "inlees.csv" for input as #readFile i$ =input$( #readFile, lof( #readFile)) close #readFile
open "server.txt" for input as #server j$ =input$( #server, lof( #server)) close #server
' chr$( 10) separates rows in Linux data files; ',' separates fieldss
pos =1 numbersOfCowsInInleesFile$ ="_"
[here1] row$ =word$( i$, pos, chr$( 10)) if row$ ="" then goto [continue1] numbersOfCowsInInleesFile$ =numbersOfCowsInInleesFile$ +word$( row$, 1, ",") +"_" pos =pos +1 scan goto [here1]
[continue1] print "Cow numbers in first file "; numbersOfCowsInInleesFile$ pos =1 numbersOfCowsInServerFile$ ="_"
[here2] row$ =word$( j$, pos, chr$( 10)) if row$ ="" then goto [continue2] numbersOfCowsInServerFile$ =numbersOfCowsInServerFile$ +word$( row$, 1, ",") +"_" pos =pos +1 scan goto [here2]
[continue2] print "Cow numbers in second file "; numbersOfCowsInServerFile$
k =1
do f1$ =word$( numbersOfCowsInInleesFile$, k, "_") if instr( numbersOfCowsInServerFile$, "_" +f1$ +"_") then print f1$; " "; k =k +1 scan loop until f1$ =""
print " are in both files."
Cow numbers in first file _1_2_3_4_5_6_7_8_9_10_ Cow numbers in second file _113_8_83_4_7_9_100_120_37_ 4 7 8 9 are in both files.
|
|
|
Post by tenochtitlanuk on Nov 14, 2020 9:52:21 GMT -5
Unary minus has long been a request. Using '0 -a' is the work-round
OR
Use the alpha releases of LB5 which handle unary minus.
a =-1 print a print -1 gives
-1 -1
|
|
|
Post by tenochtitlanuk on Nov 13, 2020 10:28:17 GMT -5
Works OK if I keep sub parameters to 9 or less.. nomainwin global Width, Height, CR$, pi Width =400 Height =400 CR$ =chr$( 10) pi =4 *atn( 1) dim Pix$( Width, Height) ' set up local pixel arrays Pix$( x, y) holding 'RGB' as 3 bytes) dim Pix( 1000), Piy( 1000) ' to hold values in subs
' colour gradient background for y =0 to Height for x =0 to Width Pix$( x, y) =chr$( min( (x *y) mod 255, 255)) +chr$( 120) +chr$( min( (x *y /100) mod 255, 255)) next x next y call saveP6 "P0"
call fill 180, 189, 80 for K =250 to 100 step -5 call bresenham 100, 100, 400, K, 0, 0, 160 next K call saveP6 "Pa"
call fill 180, 189, 80 for RR =10 to 150 step 10 call circle 200, 200, RR, 0, 0, 255 next RR call saveP6 "Pb"
call fill 255, 255, 255 radius =100 Ra = 60 for theta =0 to 4 *pi step 0.0003 Xc =int( radius *sin( theta) +300.5) Yc =int( radius *cos( theta) +150.5) radius =Ra *( 2 +sin( theta *5.1)) Ra =Ra *0.999999 call setpixel Xc, Yc, 0, 0, 0 scan next theta call saveP6 "Pc" ' fails
call fill 10, 89, 80 call bezierquad 10,100,250,270,150,320,40 call saveP6 "Pd"
call fill 10, 189, 80 call beziercubic 160, 350, 300, 250, 230, 0, 250, 100, 60 call saveP6 "Pe"
call fill 180, 189, 80 'call histogramAndBandW ' N/A 'call saveP6 "Pf" notice "Done!" wait ' ________________________________________________________________________
sub fill r, g, b for y =0 to Height for x =0 to Width Pix$( x, y) =chr$( r ) +chr$( g) +chr$( b) next x next y end sub
sub setpixel x, y, r, g, b if x >=0 and x <=Width and y >=0 and y <=Height then Pix$( x, y) =chr$( r) +chr$( g) +chr$( b) end sub
sub saveP6 n$ open n$ for output as #fOut print #fOut, "P6" +CR$; print #fOut, "# Created by Liberty BASIC" +CR$; print #fOut, str$( Width +1) +" " +str$( Height +1) +CR$; print #fOut, "255" +CR$; for y =Height to 0 step -1 for x =0 to Width print #fOut, Pix$( x, y); next x next y close #fOut end sub function sgn( x) if x>=0 then sgn =1 else sgn =0 -1 end function ' ________________________________________________________________________ sub circle cx, cy, rd, r, g, b 'LOCAL f, x, y, ddx, ddy f =1 -rd y =rd ddy =0 -2 *rd call setpixel cx, cy +rd, r, g, b call setpixel cx, cy -rd, r, g, b call setpixel cx +rd, cy, r, g, b call setpixel cx -rd, cy, r, g, b while x <y if f >=0 then y = y -1 ddy =ddy +2 f =f +ddy end if x =x +1 ddx =ddx +2 f =f + ddx +1 call setpixel cx +x, cy +y, r, g, b call setpixel cx -x, cy +y, r, g, b call setpixel cx +x, cy -y, r, g, b call setpixel cx -x, cy -y, r, g, b call setpixel cx +y, cy +x, r, g, b call setpixel cx -y, cy +x, r, g, b call setpixel cx +y, cy -x, r, g, b call setpixel cx -y, cy -x, r, g, b wend end sub sub bresenham x1, y1, x2, y2, r, g, b dx =abs( x2 -x1): sx =sgn( x2 -x1) dy =abs( y2 -y1): sy =sgn( y2 -y1) if dx <dy then e =dx /2 else e =dy /2 do call setpixel x1, y1, r, g, b if x1 =x2 then if y1 =y2 then exit do end if end if if dx >dy then x1 =x1 +sx: e =e -dy: if e <0 then e =e +dx: y1 =y1 +sy else y1 =y1 +sy: e =e -dx: if e <0 then e =e +dy: x1 =x1 +sx end if loop until 0 end sub ' _________________________________________________________ sub bezierquad x1,y1,x2,y2,x3,y3,n for i = 0 to n t =i /n t1 =1 -t a =t1^2 b =2 *t *t1 c =t^2 Pix( i) =int( a *x1 +b *x2 +c *x3 +0.5) Piy( i) =int( a *y1 +b *y2 +c *y3 +0.5) next i for i =0 to n -1 call bresenham Pix( i), Piy( i), Pix( i +1), Piy( i +1), r, g, b next i end sub ' ________ sub beziercubic x1, y1, x2, y2, x3, y3, x4, y4, n for i = 0 to n t =i /n t1 =1 -t a =t1^3 b =3 *t *t1^2 c =3 *t^2 *t1 d =t^3 Pix( i) =int( a *x1 +b *x2 +c *x3 +d *x4 +0.5) Piy( i) =int( a *y1 +b *y2 +c *y3 +d *y4 +0.5) next i for i =0 to n -1 call bresenham Pix( i), Piy( i), Pix( i +1), Piy( i +1), r, g, b next i end sub ' ________________________________________________________________________
|
|
|
Post by tenochtitlanuk on Nov 13, 2020 9:43:33 GMT -5
Doesn't like large numberw of parameters ( 10 or more?). Try this minimal demo. Then knock off the last one in the call and definition...
call bezierquad 10,100,250,270,150,320,40,0,0,1 wait sub bezierquad x1,y1,x2,y2,x3,y3,n,r,g,b end sub
|
|