Welcome, Guest. Please login or register.

Author Topic: Pen Independent Images.  (Read 4607 times)

Description:

0 Members and 1 Guest are viewing this topic.

Offline Piru

  • \' union select name,pwd--
  • Hero Member
  • *****
  • Join Date: Aug 2002
  • Posts: 6946
    • Show all replies
    • http://www.iki.fi/sintonen/
Re: Pen Independent Images.
« on: August 06, 2007, 07:02:37 PM »
Look into the autodoc?

Code: [Select]
cybergraphics.library/WritePixelArray   cybergraphics.library/WritePixelArray

   NAME
        WritePixelArray -- write the color value of a rectangular array of
        pixels starting at a specified x,y location and continuing through
        to another x,y location within a certain RastPort

   SYNOPSIS
        count = WritePixelArray(srcRect,SrcX ,SrcY ,SrcMod,RastPort,DestX,
        D0                         A0   D0:16 D1:16 D2:16     A1    D3:16
                                DestY,SizeX,SizeY,SrcFormat)
                                D4:16 D5:16 D6:16    D7

        LONG WritePixelArray(APTR,UWORD,UWORD,UWORD,struct RastPort *,UWORD,
                             UWORD,UWORD,UWORD,UBYTE)

   FUNCTION
        For each pixel in a rectangular region, write the color value from a
        linear array of color values into the bitmap used to describe a
        particular rastport.

   INPUTS
        srcRect - pointer to an array of pixels from which to fetch the
                  pixel data. The pixel format is specified in SrcFormat
        (SrcX,SrcY) - starting point in the source rectangle
        SrcMod - The number of bytes per row in the source rectangle.
        RastPort -  pointer to a RastPort structure
        (DestX,DestY) - starting point in the RastPort
        (SizeX,SizeY) - size of the rectangle that should be transfered
        SrcFormat - pixel format in the source rectangle
                    Currently supported formats are:

                    RECTFMT_RGB   3 bytes per pixel, one byte red, one blue
                                  and one byte green component

                    RECTFMT_RGBA  4 bytes per pixel, one byte red, one
                                  blue, one byte green component and the
                                  last byte is alpha channel information.
                                  If you do not use alpha channel set this
                                  byte to 0!!!

                    RECTFMT_ARGB  4 bytes per pixel, one byte red, one
                                  blue, one byte green component and the
                                  first byte is alpha channel information.
                                  If you do not use alpha channel set this
                                  byte to 0!!!

                    RECTFMT_LUT8  1 byte per pixel, specifying the pen
                                  number. On screen depths > 8 bits the
                                  data is converted using the actual color
                                  lookup table.

                    RECTFMT_GREY8 1 byte per pixel, specifying grey scale
                                  value.

   RESULT
        count will be set to the number of pixels plotted

   NOTES
        Only RECTFMT_LUT8 can be used on screen depths <= 8 bits.
        For > 8 bit rastport RECTFMT_LUT8 uses the actual colormap &quot;attached&quot;
        to the bitmap. If the bitmap is a friend bitmap of a screen bitmap
        or the screen bitmap itself, it uses the screen's viewport colormap.
       
   BUGS
        The count value returned is totally wrong.

   SEE ALSO
        ReadPixelArray(), WriteLUTPixelArray(),
        graphics.library/WritePixelArray()

 

Offline Piru

  • \' union select name,pwd--
  • Hero Member
  • *****
  • Join Date: Aug 2002
  • Posts: 6946
    • Show all replies
    • http://www.iki.fi/sintonen/
Re: Pen Independent Images.
« Reply #1 on: August 06, 2007, 07:31:53 PM »
Code: [Select]
#include <cybergraphx/cybergraphics.h>
#include <intuition/intuition.h>
#include <intuition/intuitionbase.h>

#include <proto/exec.h>
#include <proto/intuition.h>
#include <proto/cybergraphics.h>

#define WIDTH  320
#define HEIGHT 240

int main(int argc, char **argv)
{
  struct ExecBase *SysBase = *(struct ExecBase **) 4;
  struct IntuitionBase *IntuitionBase;
  struct Library *CyberGfxBase;

  IntuitionBase = (APTR) OpenLibrary(&quot;intuition.library&quot;, 37);
  CyberGfxBase = OpenLibrary(CYBERGFXNAME, 40);
  if (IntuitionBase && CyberGfxBase)
  {
    ULONG *array;

    array = AllocMem(WIDTH * HEIGHT * 4, MEMF_ANY);
    if (array)
    {
      struct Window *win;
      int x, y;

      for (y = 0; y < HEIGHT; y++)
      {
        for (x = 0; x < WIDTH; x++)
        {
          UBYTE r = 255 * x / WIDTH;
          UBYTE g = 255 * y / HEIGHT;
          UBYTE b = 255 * (x + y) / HEIGHT;
          array[y * WIDTH + x] = (r << 16) | (g << 8) | b;
        }
      }

      win =  OpenWindowTags(NULL,
                            WA_Left,         0,
                            WA_Top,          0,
                            WA_Width,        WIDTH,
                            WA_Height,       HEIGHT,
                            WA_DragBar,      TRUE,
                            WA_Borderless,   TRUE,
                            WA_SmartRefresh, TRUE,
                            WA_Activate,     TRUE,
                            WA_CloseGadget,  TRUE,
                            WA_IDCMP,        IDCMP_CLOSEWINDOW | IDCMP_RAWKEY,
                            TAG_DONE);
      if (win)
      {
        BOOL running = TRUE;

        WritePixelArray(array, 0, 0, WIDTH * 4,
                        win->RPort, 0, 0, WIDTH, HEIGHT, RECTFMT_ARGB);

        while (running)
        {
          struct IntuiMessage *imsg;

          Wait(1 << win->UserPort->mp_SigBit);

          while ((imsg = (APTR) GetMsg(win->UserPort)))
          {
            switch (imsg->Class)
            {
              case IDCMP_CLOSEWINDOW:
                running = FALSE;
                break;

              case IDCMP_RAWKEY:
                if (imsg->Code == (0x45 | IECODE_UP_PREFIX))
                {
                  running = FALSE;
                }
                break;
            }
            ReplyMsg(&imsg->ExecMessage);
          }
        }

        CloseWindow(win);
      }

      FreeMem(array, WIDTH * HEIGHT * 4);
    }
  }

  if (CyberGfxBase)
  {
    CloseLibrary(CyberGfxBase);
  }
  if (IntuitionBase)
  {
    CloseLibrary(&IntuitionBase->LibNode);
  }

  return 0;
}
 

Offline Piru

  • \' union select name,pwd--
  • Hero Member
  • *****
  • Join Date: Aug 2002
  • Posts: 6946
    • Show all replies
    • http://www.iki.fi/sintonen/
Re: Pen Independent Images.
« Reply #2 on: August 06, 2007, 07:38:50 PM »
@EDanall

Quote
If I use this, what are the compatibility issues with other Amigas

If you want to stay compatible do not use Picasso96 API.

CyberGraphX is the universally supported API, Picasso96 emulates it.
 

Offline Piru

  • \' union select name,pwd--
  • Hero Member
  • *****
  • Join Date: Aug 2002
  • Posts: 6946
    • Show all replies
    • http://www.iki.fi/sintonen/
Re: Pen Independent Images.
« Reply #3 on: August 06, 2007, 08:27:52 PM »
Bah, AmiDevCpp doesn't appear to have have libauto then... that sucks donkey round-objects...

I'll workaround the src in a moment.

[EDIT] done [/EDIT]
 

Offline Piru

  • \' union select name,pwd--
  • Hero Member
  • *****
  • Join Date: Aug 2002
  • Posts: 6946
    • Show all replies
    • http://www.iki.fi/sintonen/
Re: Pen Independent Images.
« Reply #4 on: August 07, 2007, 09:40:21 AM »
@EDanaII
Quote
May I upload your example to UtilityBase so that there actually is an example there?

I guess.

Quote
Do you know if there are there similar routines for BOBS and Sprites?

BOBs or Blitter OBjects are just rectangular gfx drawn by the system. With gfxcard you can use BltBitMap family routines (see graphics.doc). Note that you'll need to handle background restoration yourself (if you need any).

Graphics cards typically support only one sprite, the mouse pointer, so sprites are out I'm afraid.

Quote
Now I need to figure out how to load a PNG or an IFF into the array you provided.

You should look into datatype.library examples. Note however that stock AmigaOS install doesn't include png datatype. You could always use libpng, though.
 

Offline Piru

  • \' union select name,pwd--
  • Hero Member
  • *****
  • Join Date: Aug 2002
  • Posts: 6946
    • Show all replies
    • http://www.iki.fi/sintonen/
Re: Pen Independent Images.
« Reply #5 on: August 07, 2007, 11:11:11 PM »
@EDanaII

Quote
If I read a raw image straight into an array, should it work?

Assuming the raw file is ARGB and has the correct dimensions, sure.

The current code just fills the array with test-pattern.