My take on this type issue:
'draw a few boxes
'Now do a screen grab
ShortByte = 0
'open a file for saving
count = 1 'count is the count of repetitive times a color appears in a row
_MEMGET m
, m.OFFSET
+ p
* 4, c
'p is the current point finished = -1
IF (p
+ count
) * 4 >= m.SIZE
THEN finished = -1
count = count + 1
IF (p
+ count
) * 4 >= m.SIZE
THEN finished
= -1: count
= count
- 1:
EXIT DO p = p + count
PRINT #1, "DATA "; r;
","; g;
","; b;
",";
LongData = count
PRINT #1, ShortByte;
","; LongData
ShortByte = count
ShortByte = 0 'reset the default count to 0
'free resources
Run the above and it creates a crude screen of just a few different colored boxes for us. It then scans the screen for color values and prints them to the drive as so:
DATA 44 , 246 , 203 , 0 , 18141
DATA 221 , 149 , 67 , 228
DATA 44 , 246 , 203 , 0 , 412
DATA 221 , 149 , 67 , 228
DATA 44 , 246 , 203 , 0 , 412
DATA 221 , 149 , 67 , 228
DATA 44 , 246 , 203 , 0 , 412
DATA 221 , 149 , 67 , 228
DATA 44 , 246 , 203 , 0 , 412
(and so on...)
Now, to decipher that data and reconstruct our image, all we have to do is read it in and plot point by point, following the instructions it contains.
The first line is: DATA 44 , 246 , 203 , 0 , 18141 -- This tells us we have the color _RGB32(44, 246, 203) and that it's repeated 18,141 times, going left to right, top to bottom. (The 0 tells us to expect an extended value beyond a single byte.)
The second line is: DATA 221 , 149 , 67 , 228 -- This tells us the next color we're processing is _RGB32(221, 149, 67), and that it's going to be the same for the next 228 pixels, going left to right, top to bottom...
Now, using print like this, we really don't need to worry about the 0 being in there. We could just print the number of repetitions directly...
The only reason why I do it this way, is because I usually use PUT instead of PRINT to place values like this sequentially into a file. In that case, we'd be dealing with 4 bytes for a short record (red, green, blue, count if less than 256), and 8 bytes for a long record (red, green, blue, 0 as code the next chunk is our count, then 4 bytes for count size). We could basically just read our data one _UNSIGNED LONG at a time, and then process it from there!
:)