Project Dogwaffle - code snippets
for Delphi, PowerBasic, C and other programming languages
back
Information from Developers, for Developers - if you don't use VB
 Not using VB? Do you use Delphi, or other tools to code? 
For C Programmers:
Here's a wrapper by Dan Ritchie to help C programmers connect to Dogwaffle. This should help getting you started with MS developer studio 6 (msc++), perhaps also Bloodshed Dev-C++ and possibly other integrated development environments including MSVC++

C_Wrapper.zip
For PowerBasic Programmers:
Marco at mark0.net is creating a Lua scripting interface for Dogwaffle, called DogLua. He uses PowerBasic. He sent us a small source code example and executable which connects to Dogwaffle using PowerBasic, and inverses the image.
PBsample.zip
[6.77 KB (6,936 bytes)]
For Delphi (Pascal) Programmers :   NEW!
An Example - from Artweaver's Boris Eyrich:

Project Dogwaffle runs as an ActiveX server and is registered as such upon installation. This makes it very easy for programmers with Delphi to connect from their own applications such as standalone executable programs to the Dogwaffle through OLE. Delphi provides great and easy functions for OLE connectivity. Here are the most important functions needed:

      // we'll use COM objects
  
uses   ComObj;  

  
// some types of variables typically used
   var  
      Dogwaffle: Variant;
      DogHeight,DogWidth: Integer;
      rbuf,gbuf,bbuf,abuf: OleVariant;
      r,g,b,a: pByte;
      h,w: integer;


   // Connect to dogwaffle (slightly different for PD Particles)
   Dogwaffle := CreateOleObject('Dogwaffle.Dogwaffle_Class');

   // Get red color channel from main image buffer
   rbuf := Dogwaffle.Dog_GetRBuffer;

   // Get image size
   DogHeight := Dogwaffle.Dog_BufferHeight;
   DogWidth := Dogwaffle.Dog_BufferWidth;
 
   // Repaint image shown in Dogwaffle,
   Dogwaffle.Dog_Refresh;


Other methods of the Dogwaffle object are described  here. You can access the swap buffer too, and brush images, frames of an animation and much more.

Note that we didn't use any function or method so far to send images or pixels back to Dogwaffle. In this example below it's done by directly accessing the image buffers, which is why they're locked down for the duration of the operation.

OLE essentially lets you share the address base between Dogwaffle's image buffer and your pointers to it. Good programming habits will probably have you disconnect or close OLE and do perhaps one or two more housekeeping things, but for beginning your journey with programming for Dogwaffle, this`is pretty much all it takes. Below is a more detailed code sample. It inverts the image's red, green and blue values.


_____________________________________________________________

uses   ComObj;

procedure Sample;
var
   Dogwaffle: Variant;
   DogHeight,DogWidth: Integer;
   rbuf,gbuf,bbuf,abuf: OleVariant;
   r,g,b,a: pByte;
   h,w: integer;
begin
   // Connect to dogwaffle
   Dogwaffle := CreateOleObject('Dogwaffle.Dogwaffle_Class');
   // Get data
   rbuf := Dogwaffle.Dog_GetRBuffer;
   gbuf := Dogwaffle.Dog_GetGBuffer;
   bbuf := Dogwaffle.Dog_GetBBuffer;
   abuf := Dogwaffle.Dog_GetABuffer;
   // Get image size
   DogHeight := Dogwaffle.Dog_BufferHeight;
   DogWidth := Dogwaffle.Dog_BufferWidth;
   // Lock data
   r := VarArrayLock(rbuf);
   g := VarArrayLock(gbuf);
   b := VarArrayLock(bbuf);
   a := VarArrayLock(abuf);
   // Do something with the image data
   for h := 0 to DogHeight-1 do
   begin
     for w := 0 to DogWidth-1 do
     begin
       if a^ > 0 then
       begin
         // Invert the channels
         r^ := not r^;
         g^ := not g^;
         b^ := not b^;
       end;
       inc(r);
       inc(g);
       inc(b);
       inc(a);
     end;
     // Skip last bytes
     inc(r);
     inc(g);
     inc(b);
     inc(a);
   end;
   // Unlock data
   VarArrayUnLock(rbuf);
   VarArrayUnLock(gbuf);
   VarArrayUnLock(bbuf);
   VarArrayUnLock(abuf);
   // Repaint image
   Dogwaffle.Dog_Refresh;
end;


_____________________________________________________________

Another Delphi Example - from Gertrudis's Enrique Nieloud:

Does this look familiar to you?

DogwaffleConex := CreateOleObject('Dogwaffle.Dogwaffle_Class');
RedChannel   := DogwaffleConex.Dog_GetRBuffer;
GreenChannel := DogwaffleConex.Dog_GetGBuffer;
BlueChannel  := DogwaffleConex.Dog_GetBBuffer;
DogWidth     := DogwaffleConex.Dog_BufferWidth;
DogHeight    := DogwaffleConex.Dog_BufferHeight;
pRed         := VarArrayLock(RedChannel);
pGreen       := VarArrayLock(GreenChannel);
etc...

Enrique Nieloud, author of the Gertrudis for Dogwaffle plugin, used Delphi for his porting effort. Here's what he tells us:

I've no problem to publish the source files that read/write bitmaps with Dogwaffle. In this code you will see references to a unit named "G32". This library was developed by Alex Denisov and can be found at: www.g32.org.



Code sample #1:

gertrudis_dogwaffle.pas

Code sample #2
gertrudis_dibutils.pas











Information and code on this page is provided without warranty of any kind. Use at your own risk. Trademarks and registered trademarks are the property of their respective owners and only used for identification purpoases. No endorsement or other affiliation whatsoever is implied.