[futurebasic] Re: [FB3]pixels & pictures

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : February 2001 : Group Archive : Group : All Groups

From: "Peter Dempsey" <theviron@...>
Date: Sat, 10 Feb 2001 15:35:11 -0600
Amazingly enough, I think a little light bulb is starting to glow dully in 
the dark recesses of my unenlightened mind...

I think I understand the code, and how it SHOULD work.  However, I can't 
seem to get it to work.  It crashes in one of two ways (with my 
modifications, before it brought up all sorts of erros): quitting almost 
imediatly, or freezing the comp (eek).

It's probably something thats obvious (to most)... some memory mishandling.. 
I dunno... but its nasty..

Below is what I changed:


>From: Robert Covington <artlythere@...>
>Reply-To: futurebasic@...
>To: futurebasic@...
>Subject: [FB] Re:[FB3]pixels & pictures
>Date: Sat, 10 Feb 2001 01:56:00 -0400
>
>
I asked:
> >	So, could anyone point me to either information about how to look at a
> >picture (cough cough... pixel by pixel) or (if already done) some code?
> >
> >As always, thanks to everyone!
> >
> >-Peter Dempsey
>
RC responded:
>Graphic Converter may be of use. My own program Compositor may be of use.
>Photoshop would definitely be of use.
>If you want, I could probably write a batch processor to change your colors
>for you in not too much time. The price is your firstborn, and all money
>you earn until then.
That could take a while (c below) ;)
>
>Egads.
>
>You don't want to change the mask colors most likely. They reflect
>luminosity values, and copy amount/blend is based on that (usually). You
>can import your images into a GWorld, grab the pixels, change them, and
>stick them back.
>
>How many team colors do you need to have?
Well.. UMM ::cough cough:: whats 65536^3? I have every team color editable, 
with each color (rgb) up to 65536. I COULD do the blizzardesk thing and make 
only like 8 teams, preset colors, and units.  Then, the game would both be 
massively bigger, and much more restrictive (as opposed to 65536 teams 
possible ;).  My scenario editor would be in vain...


>
>Here is a basic tutorial... in fb3. You will need to alter for 8 bit images
>like you probably are using.  I think you know how, via FN JN rotation code
>of recent long post.
>;)
I think I missed something here... never assume anything about my knowledge. 
  For all intents and purposes, treat me like I am a lil kid who just got 
FB3 and knows didly squat. ;)

If you mean when I foolishly posted the function junction code on the entire 
list (WOOPS), then no, I never figured it out...

>
>// Change a Pixel, Change a Channel
>
>Resources "DempseyLand.rsrc" // Add yours here.
>
I put BEGIN GLOBALS here.. I'm just assuming...
>DIM myGWorld as Long
>_safeExtraMem = 64*1024
>DIM gRect as Rect
>End Globals
>
>// RP Special Old Edition
>LOCAL FN CopyGW2GW(sPort as long,dPort as long,sRect as ptr,dRect as ptr)
>CALL COPYBITS(#sPort+2,#dPort+2,#sRect,#dRect,_srcCopy,0)
>END FN
>
>LOCAL FN MakeAndLockGWorld(theRect as pointer to rect, depth)
>dim qdErr
>DIM @ myGWorld as long

Error: Variable 'MYGWORLD' Re-Defined here!
in file Temp Project at line 37 in MAKEANDLOCKGWORLD
�DIM @ myGWorld �as long

So, I deleted that line (myGWorld was meant to be global, right???)

>qdErr = FN NEWGWORLD(myGWorld, depth, #theRect, 0,0,0)
>LONG IF (qdErr != _noErr) OR (MEM(_maxAvail) < _safeExtraMem)
>Print "Dempsey is in Trouble"
>END IF
>long if (FN LOCKPIXELS(FN GETGWORLDPIXMAP(myGWorld)) == _false)
>stop "LockPixels error"
>end if
>
>END FN = myGWorld
>
>Local FN Clamp(value as long)    // keep values in Range
>If value< 0 Then value = 0
>If value > 255 Then Value = 255
>ENd FN = value
>
>
>Local FN Change_De_Colors // By Hannibal Lecter, or Lector, or Lectern. or
>Lecher. Some Lec' sound.
>DIM as long r,g,b
>DIM Pixel as PTR
>DIM myBaseAddress as Long
>DIM myRowBytes as Long
>DIM pmHandle as handle to pixMap
>
>DIM rTmp as long
>DIM gTmp as long
>DIM bTmp as long
>
>DIM @tmpWorld as long, @tmpDevice as long
>
>DIM yy as int
>DIM xx as int
>
>pmHandle  = FN GETGWORLDPIXMAP(myGWorld) // See the almighty global of your
>GWorld.
>myRowBytes = pmHandle..RowBytes AND 0x3FFF
>myBaseAddr = FN GETPIXBASEADDR(pmHandle)
>
>Cursor _watchCursor
>
>FOR yy=0 TO gRect.bottom-1
>FOR xx=0 TO gRect.right-1
>
>Pixel = myBaseAddr + (yy * myRowBytes) + (xx*4) // Yep, that is a pixel.
>
>r = Pixel.1`` // Red component
>g = Pixel.2`` // Green component
>b = Pixel.3`` // Blue component
>
>rTmp = b  // 0 to 255 in 32 bit GWorld

Error: End of Statement expected here...
in file Temp Project at line 86 in CHANGE_DE_COLORS
�rTmp = b�� // 0 to 255 in 32 bit GWorld

UMM.. it brought up this error for all three.  I haven't a clue whats 
wrong.. so I deleted these:
>gTmp = r  // 0 to 255 in 32 bit GWorld
>bTmp = r  // 0 to 255 in 32 bit GWorld
and (see below) I put em straight back in.  I hope this is OK??
>
>// Values in 16 bit gworld, 0-31 // 8 Bit gworld, 0-7
>
>// Sets Green channel to red, red to blue, blue to red...
>// Going to look funky. But you get the idea from here...
>// Pretend you worked on it some more...might be greater than 255
>// or less than 0 now... so FN Clamp
>
>// Stick the pixel information back...
Original:
>Pixel.1`` = FN Clamp(rTmp)
>Pixel.2`` = FN Clamp(gTmp)
>Pixel.3`` = FN Clamp(bTmp)
new:

Pixel.1`` = FN Clamp(b)
Pixel.2`` = FN Clamp(r)
Pixel.3`` = FN Clamp(r)
>
>NEXT xx
>NEXT yy
>Cursor _arrowCursor
>End FN
>
>"Main" // Sort of
>DIM pictH
>DIM @tmpWorld as Long
>DIM @tmpDevice as Long
>// Can Make a Loop Here...
>// For Pete's Start ID to End ID
>pictH = FN GetPicture(YourResID)// Set your Resources!
>Long if pictH
>gRect;8 = [pictH] +_PicFrame
>myGWorld = FN MakeAndLockGWorld(gRect, 32)//  8, I bet you use 8... Well..
>you have to use 24 this time.
>Long if myGWorld
>Call GetGWorld(tmpWorld,tmpDevice)
>Call SetGWorld(myGWorld,0)
>CLS
>Call Drawpicture (PictH,gRect)
>Call SetGWorld(tmpWorld,tmpDevice)
>if myGWorld then FN Change_De_Colors
>Picture ON
>FN CopyGW2GW(myGWorld, myGWorld,gRect,gRect)
>Picture OFF , pictH

Error: VARPTR does not work for register variables...
in file Temp Project at line 126 in Main
��Picture OFF , pictH

My knowledge if very fuzzy here.  I don't know quite what its talking about, 
(even after looking up VARPTR again... yeah I don't know much) so I dimmed 
pictH as a global.

NOTE: another thing that I think was a problem was that it was dimmed as a 
regular var, not a handle.  I quickly changed that, but the problem 
persisted so I made it a global.

>//FN PGPROCHANGESOMERESOURCEBACKTHINGHERE(pictH,YourResID)

Ok, this is not a PG project, and I don't know where the replace res. thingy 
is, so I decided just to SHOW the picture. SHOULD be easy enough... 
right...?

WINDOW 1,"Show me thy PICTURE!",(0,0)-(300,300)
CALL DRAWPICTURE(pictH,gRect)

DO
HANDLEEVENTS
UNTIL MOUSE(_DOWN) //not the most elegant.. but hey....


>if pictH then  KILL PICTURE pictH // if Save routine does not dispose of
>handle?
>
>if myGWorld then Call DisposeGWorld(myGWorld) // Ditch GWorld now.
>End If
>Xelse
>// Bogus
>End If
>// Next Loop (ID value?)
>
>// Don't forget to submit firstborn.
>
>// RC
>
>// PS Don't forget a possible CLUT approach.
>
>
>
>--
>To unsubscribe, send ANY message to <futurebasic-unsubscribe@...>
>


As for your RC's second response:

As I've said, I don't want a RESOURCE pre-rendered picture (although, I 
might render it in game and put it in memory).

However, thats an incredibly program!  I hadn't downloaded it before, and I 
wish I had.  All the functions are incredible for the price.  Now this is 
starting to sound like an ad, so I'll stop by saying that my next game (dum 
deeeee dum dum!) could make real use of them (most of the "graphics" are 
already done for starships, however).

>From: Robert Covington <artlythere@...>
>Reply-To: futurebasic@...
>To: futurebasic@...
>Subject: [FB] Re: [FB3]pixels & pictures
>Date: Sat, 10 Feb 2001 03:58:30 -0400
>
>Vironica,
???? name of the feature???? me is confused
>
>I forgot about my own feature. It may be of help to you with this.
>
>Download Compositor v1.6 at <
>http://www.artlythere.com/macsoft/compositor.hqx > if you haven't already
>and try Replace Color feature in the Image menu.
>
>You can copy a PICT in ResEdit, choose New With Clipboard to bring it to
>Compositor. Choose Image Menu/Replace Color. Click on the  cursor button to
>the left, pick the color you want to change, and then click the replacement
>rectangle color on the right to set the new color you want.
>
>Adjust the Fuzz factor to your satisfaction (it blends near colors to a
>similar shade, don't use much beyond 128 if that much), then apply. Undo if
>you don't like the result, and then start again. Copy (Command -C ) and
>paste back into ResEdit when done.
>
>The Replace Color settings will stay the same between images as long as you
>don't quit the application, you can do each "team" that way. You
could also
Thats just what I was looking for when I made Starships the original (a 
complete mess not even worth downloading.. but it was a learning 
experience).  It had 4 teams (colors) for each ship.  It was anoying finding 
all the spots on every ship for every angle and changing them.
>just save the actions and reload them, though with only one step, not much
>help other than to save your colors per team for future reference.
>
>May be an option you may wish to explore, if the approach I recently posted
>is too involved. Get to keep your firstborn this way too. :) I still get
>your woman though. (Make sure you send the air pump along with her. <g>)

Gimme a couple milleni... years to find one ;)
>
>Robert Covington
>
>
>
>
>--
>To unsubscribe, send ANY message to <futurebasic-unsubscribe@...>
>

So... I've got the basic idea... but the mechanics (code) are still hazy...

_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com