Amiga.org
Amiga computer related discussion => Amiga/MorphOS/AROS Programmers Forum => Topic started by: nyteschayde on January 30, 2015, 05:36:44 AM
-
I have been trying to find place that describes how to load an image and present it with code. Things that would be nice to understand:
- How to load an image pre-datatypes
- How to load an image with datatypes
- How to display an image in a regular window
- How to display an image directly to a screen
- Examples on how to do this with <=3.1 would be great
- Examples on how to do this with >3.1 would also be enlightening
- Examples on how to do this with 24-bit images would be welcomed
- What types of images are supported without datatypes? ILBM? Anything else?
- Any info on tools you might use to convert PNGs, JPGs and more to ILBM
- Anything else along these lines
Thanks in advance.
-
What types of images are supported without datatypes?
None, not even ILBM. You have to write all loading/unpacking code yourself.
-
Thomas, do you have any quick examples on how to do what I asked in C or C++? Clearly with datatypes since it would seem that coming up with your own bitmap format or writing a parser for a bitmap would be a waste of time unless you were limited to OS1.3 or (when did they add datatypes? 2.x?)
-
Datatypes appeared in 3.0.
Here is an example which tells datatypes to dither the loaded image into the screen's pixel format and/or palette:
/* compile with vc +aos68k dtview.c -o dtview -lauto -lamiga */
#include <proto/exec.h>
#include <proto/dos.h>
#include <proto/graphics.h>
#include <proto/intuition.h>
#include <proto/datatypes.h>
#include <datatypes/pictureclass.h>
#include <clib/alib_protos.h>
int main (void)
{
int rc = RETURN_FAIL;
static struct {
char *file;
char *pubscreen;
} args = {NULL};
struct RDArgs *rdargs = ReadArgs ("FILE/A,PUBSCREEN/K", (APTR)&args, NULL);
if (rdargs)
{
struct Screen *scr = LockPubScreen (args.pubscreen);
if (scr)
{
Object *dto = NewDTObject (args.file,
DTA_GroupID, GID_PICTURE,
PDTA_Remap, TRUE,
PDTA_Screen, scr,
PDTA_DestMode, PMODE_V43,
TAG_END);
if (dto)
{
struct BitMapHeader *bmhd = NULL;
struct BitMap *bm = NULL;
DoMethod (dto, DTM_PROCLAYOUT, NULL, TRUE);
GetDTAttrs (dto,
PDTA_BitMapHeader, &bmhd,
PDTA_DestBitMap, &bm,
TAG_END);
if (bmhd && bm)
{
struct Window *win = OpenWindowTags (NULL,
WA_Title, FilePart(args.file),
WA_InnerWidth, bmhd->bmh_Width,
WA_InnerHeight, bmhd->bmh_Height,
WA_Flags, WFLG_CLOSEGADGET | WFLG_DRAGBAR | WFLG_DEPTHGADGET | WFLG_ACTIVATE | WFLG_NOCAREREFRESH,
WA_IDCMP, IDCMP_CLOSEWINDOW | IDCMP_VANILLAKEY,
TAG_END);
if (win)
{
BOOL cont = TRUE;
BltBitMapRastPort (bm, 0, 0, win->RPort,
win->BorderLeft, win->BorderTop,
win->GZZWidth, win->GZZHeight,
ABC | ABNC);
do {
struct IntuiMessage *imsg;
if (Wait ((1L << win->UserPort->mp_SigBit) | SIGBREAKF_CTRL_C) & SIGBREAKF_CTRL_C)
cont = FALSE;
while ((imsg = (struct IntuiMessage *) GetMsg (win->UserPort)))
{
switch (imsg->Class)
{
case IDCMP_VANILLAKEY:
if (imsg->Code == 0x1b) /* Esc */
cont = FALSE;
break;
case IDCMP_CLOSEWINDOW:
cont = FALSE;
break;
}
ReplyMsg ((struct Message *) imsg);
}
}
while (cont);
CloseWindow (win);
rc = RETURN_OK;
}
}
DisposeDTObject (dto);
}
UnlockPubScreen (NULL, scr);
}
FreeArgs (rdargs);
}
if (rc != RETURN_OK)
PrintFault (IoErr(), NULL);
return (rc);
}