English Amiga Board


Go Back   English Amiga Board > Coders > Coders. General

 
 
Thread Tools
Old 04 January 2012, 10:58   #1
Morbane
Sub-Dimensional Array
 
Morbane's Avatar
 
Join Date: Nov 2011
Location: Australia
Posts: 123
How to load an image in C into a window/screen?

I would like to learn how to load or program a picture into a window. ANyone have the necessary C code examples or tutorial for that?
Morbane is offline  
Old 04 January 2012, 17:42   #2
Ed Cruse
Registered User
 
Join Date: Sep 2007
Location: Las Cruces, USA
Age: 71
Posts: 351
Quote:
Originally Posted by Morbane View Post
I would like to learn how to load or program a picture into a window. ANyone have the necessary C code examples or tutorial for that?
I have the C code for a movie player that I wrote, it uses double buffering so one is being loaded while the other one is being displayed. The movie that is fed to it is not compressed, it's 8 bit and the file contains a bitmap and a color map for each frame. Each color map is different for each frame because each frame uses the best 256 colors out of a 16meg palette.

If you are interested I can upload the source code, it's fairly complicated because it's a program with various options, the main one being it's controllable from Arexx, and you can display any one frame like in a slide show. If you really study the code you can see how to setup the color map and the bit map and then display it.
Ed Cruse is offline  
Old 04 January 2012, 18:20   #3
thomas
Registered User
 
thomas's Avatar
 
Join Date: Jan 2002
Location: Germany
Posts: 7,030
http://thomas-rapp.homepage.t-online...amples/dtwin.c
thomas is offline  
Old 04 January 2012, 22:29   #4
Morbane
Sub-Dimensional Array
 
Morbane's Avatar
 
Join Date: Nov 2011
Location: Australia
Posts: 123
Thanks thomas but I think your code was written in OS4 - no? A lot of declarations and such are nor found in my C library as it is now.



I would like to try and get this code to compile and then examine its parts. Is it suposed to run alone? If not I will simply read what I can to squeeze the good parts out.

PDTA_DestMode & PMODE_V43 are the culprits

Last edited by Morbane; 04 January 2012 at 22:39.
Morbane is offline  
Old 04 January 2012, 22:43   #5
thomas
Registered User
 
thomas's Avatar
 
Join Date: Jan 2002
Location: Germany
Posts: 7,030
You need the OS 3.9 include files or the picture.datatype V43 include files. Or just remove PDTA_DestMode,PMODE_V43 from the statement. Without it the picture will always be dithered to 8 bits or less. V43 mode allows true color bitmaps (16 or 24 bits).

The initialization warnings seem to be specific to GCC. You might need to cast each complained pointer to (ULONG).


I don't know what MUIPictureClass ist but I suppose that it certainly needs MUI include files.
thomas is offline  
Old 04 January 2012, 23:31   #6
Raislin77it
Zone Friend
 
Raislin77it's Avatar
 
Join Date: Jan 2005
Location: italy
Age: 46
Posts: 244
@thomas

i've watched your sources, but i have a problem......

my function is this :

struct Bitmap *bm_load_(char* name) {

struct Bitmap *TEMPbitmap = NULL;
Object *dtype = NULL;
struct BitMapHeader *bmh = NULL;
int result;

dtype = NewDTObject(name,
DTA_GroupID,GID_PICTURE,
PDTA_DestMode, PMODE_V43,
PDTA_Remap, FALSE,
TAG_END);

if (dtype == NULL) printf("immagine non caricata\n");

result = GetDTAttrs(dtype, PDTA_BitMapHeader, (ULONG)&bmh, TAG_END);

if (result != 1) printf("impossibile ottenere info sull'immagine\n");

TEMPbitmap = calloc(1,sizeof(Bitmap));


TEMPbitmap->width = bmh->bmh_Width;
TEMPbitmap->height = bmh->bmh_Height;
TEMPbitmap->depth = bmh->bmh_Depth; // per ora non viene usato


if(DoDTMethod (dtype,NULL,NULL,DTM_PROCLAYOUT,NULL,TRUE)){

result = GetDTAttrs(dtype,
PDTA_DestBitMap, (ULONG)&TEMPbitmap->bitmap,
PDTA_NumColors, (ULONG)&TEMPbitmap->colorNumber,
PDTA_CRegs, (ULONG)&TEMPbitmap->colorRegisters,
TAG_DONE);

if (result <3 ) printf("caricamento immagine non riuscita\n");
}

TEMPbitmap->palette = adaptCmap(TEMPbitmap->colorNumber, TEMPbitmap->colorRegisters);

TEMPbitmap->rastPort = (struct RastPort*) malloc(sizeof(struct RastPort));
InitRastPort(TEMPbitmap->rastPort);
TEMPbitmap->rastPort->BitMap = TEMPbitmap->bitmap;

// DisposeDTObject (dtype);
return TEMPbitmap;
}

in another function i display the bitmap and all goes good so far

but if before the :

return TEMPbitmap;
}

i don't comment off // DisposeDTObject (dtype);

the display of the image is garbled. Why?

with my function i obtain from the datatype the bitmap+colormap, why i can't dispose the datatype before the visualization?
Raislin77it is offline  
Old 05 January 2012, 10:20   #7
thomas
Registered User
 
thomas's Avatar
 
Join Date: Jan 2002
Location: Germany
Posts: 7,030
DisposeDTObject releases all memory which was allocated by NewDTObject. This includes the bitmap header, the palette and especially the dest bitmap.

If you want to keep the bitmap data after DisposeDTObject you need to copy the entire bitmap and not only the pointer.

Here is an example function to create a copy of a bitmap:

Code:
struct BitMap *copy_bitmap (struct BitMap *oldbm)

{
struct BitMap *newbm;
long w,h;

if (newbm = AllocBitMap (
		w = GetBitMapAttr(oldbm,BMA_WIDTH),
		h = GetBitMapAttr(oldbm,BMA_HEIGHT),
		GetBitMapAttr(oldbm,BMA_DEPTH),
		GetBitMapAttr(oldbm,BMA_FLAGS),
		oldbm))
	{
	BltBitMap (oldbm,0,0,newbm,0,0,w,h,0x0c0,0xff,NULL);
	}

return (newbm);
}
thomas is offline  
Old 05 January 2012, 11:21   #8
Raislin77it
Zone Friend
 
Raislin77it's Avatar
 
Join Date: Jan 2005
Location: italy
Age: 46
Posts: 244
Quote:
Originally Posted by thomas View Post
DisposeDTObject releases all memory which was allocated by NewDTObject. This includes the bitmap header, the palette and especially the dest bitmap.

If you want to keep the bitmap data after DisposeDTObject you need to copy the entire bitmap and not only the pointer.

Here is an example function to create a copy of a bitmap:

Code:
struct BitMap *copy_bitmap (struct BitMap *oldbm)

{
struct BitMap *newbm;
long w,h;

if (newbm = AllocBitMap (
        w = GetBitMapAttr(oldbm,BMA_WIDTH),
        h = GetBitMapAttr(oldbm,BMA_HEIGHT),
        GetBitMapAttr(oldbm,BMA_DEPTH),
        GetBitMapAttr(oldbm,BMA_FLAGS),
        oldbm))
    {
    BltBitMap (oldbm,0,0,newbm,0,0,w,h,0x0c0,0xff,NULL);
    }

return (newbm);
}
thanks a lot
Raislin77it is offline  
Old 05 January 2012, 14:44   #9
Morbane
Sub-Dimensional Array
 
Morbane's Avatar
 
Join Date: Nov 2011
Location: Australia
Posts: 123
Quote:
Originally Posted by thomas View Post
You need the OS 3.9 include files or the picture.datatype V43 include files. Or just remove PDTA_DestMode,PMODE_V43 from the statement. Without it the picture will always be dithered to 8 bits or less. V43 mode allows true color bitmaps (16 or 24 bits).

The initialization warnings seem to be specific to GCC. You might need to cast each complained pointer to (ULONG).


I don't know what MUIPictureClass ist but I suppose that it certainly needs MUI include files.
The MUIPictureClass was another example - and is not really part of this question anymore

How do I find said OS 3.9 and install it? Did a google search but no info of use came up - at least not in an obvious way.

Thanks.
Morbane is offline  
Old 05 January 2012, 15:28   #10
thomas
Registered User
 
thomas's Avatar
 
Join Date: Jan 2002
Location: Germany
Posts: 7,030
http://www.haage-partner.de/download/AmigaOS/NDK39.lha

http://aminet.net/package/util/dtype/PictDT43
thomas is offline  
Old 05 January 2012, 16:03   #11
Morbane
Sub-Dimensional Array
 
Morbane's Avatar
 
Join Date: Nov 2011
Location: Australia
Posts: 123
Anyone have an idea that works? Also I have no idea what to do with PictDT43?? I want to think that all I need to do is copy the folder and files to the right place - but where that place is , I have no idea.

SO now I have NDK39.lha - but what to do with it - once it is unpacked???

Last edited by Morbane; 06 January 2012 at 08:39.
Morbane is offline  
Old 06 January 2012, 10:27   #12
thomas
Registered User
 
thomas's Avatar
 
Join Date: Jan 2002
Location: Germany
Posts: 7,030
I told you that you need either the include files from OS 3.9 or the include files from picture.datatype version 43. The former is the Native Developer Kit for AmigaOS 3.9 which contains all include files and documentation for this version of the operating system and the latter is the official picture.datatype V43 archive which contains the include file with the V43 extensions.

The OS 3.9 include files are located in drawer NDK_3.9/Includes/includes_h. I would suspose that it's as easy as to copy them to the os-includes directory of your ADE (Amiga Development Environment). But I cannot tell, I never used GCC.
thomas is offline  
Old 06 January 2012, 13:12   #13
Morbane
Sub-Dimensional Array
 
Morbane's Avatar
 
Join Date: Nov 2011
Location: Australia
Posts: 123
OK I copied all the librarys - I am pretty sure thewy are in the right place as all the other libraries are there as well. I got this message:


How do I debug all that garbled stuff???
Morbane is offline  
Old 06 January 2012, 13:15   #14
thomas
Registered User
 
thomas's Avatar
 
Join Date: Jan 2002
Location: Germany
Posts: 7,030
Try to compile with -lauto.
thomas is offline  
Old 06 January 2012, 13:38   #15
Morbane
Sub-Dimensional Array
 
Morbane's Avatar
 
Join Date: Nov 2011
Location: Australia
Posts: 123


no dice - i think i messed up the .h directory copy or something
Morbane is offline  
Old 06 January 2012, 14:18   #16
thomas
Registered User
 
thomas's Avatar
 
Join Date: Jan 2002
Location: Germany
Posts: 7,030
I think there exists a libtoa utility which can make a libauto.a file from the auto.lib file which is contained in the NDK. Most Amiga compilers can deal with .lib files directly. Only GCC needs .a type files (and no, it is not just a matter of renaming the files).

You should learn to distinguish between compiler and linker errors and you should know that .h files are for the compiler while unresolved references are thrown by the linker.

And as an Amiga programmer you should know what xxxBase variables are for and how to use them. You can either define them explicitely in your code and then need to OpenLiberary() each one or you can define them as unresolved external references like it is done in the proto/xxx.h files and need then to link with the auto library.

If there is no auto library for your compiler, you need to revert to the OpenLibrary method. Don't expect help with this. Read the libraries section of the RKRM (Rom Kernel Reference Manual).
thomas is offline  
Old 07 January 2012, 12:01   #17
Morbane
Sub-Dimensional Array
 
Morbane's Avatar
 
Join Date: Nov 2011
Location: Australia
Posts: 123
Quote:
Originally Posted by thomas View Post
I think there exists a libtoa utility which can make a libauto.a file from the auto.lib file which is contained in the NDK. Most Amiga compilers can deal with .lib files directly. Only GCC needs .a type files (and no, it is not just a matter of renaming the files).

You should learn to distinguish between compiler and linker errors and you should know that .h files are for the compiler while unresolved references are thrown by the linker.

And as an Amiga programmer you should know what xxxBase variables are for and how to use them. You can either define them explicitely in your code and then need to OpenLiberary() each one or you can define them as unresolved external references like it is done in the proto/xxx.h files and need then to link with the auto library.

If there is no auto library for your compiler, you need to revert to the OpenLibrary method. Don't expect help with this. Read the libraries section of the RKRM (Rom Kernel Reference Manual).
No Help? But that is what these forums are for - no? Anyway I hope someone will happen by that will offer some help or solutions to my problem Besides all that I have been learning Amiga C programming for a week - how much am I supposed to know in that time, aye?
Morbane is offline  
Old 07 January 2012, 12:45   #18
thomas
Registered User
 
thomas's Avatar
 
Join Date: Jan 2002
Location: Germany
Posts: 7,030
If you don't invest any work into learning, then I do not feel good in helping you.

If you told me that you read this and that section of a manual and then put together some piece of code and need a little help in compiling it or something, then I am happy to help you.

But if you come here saying "I know nothing, please tell me everything", then you let me work for you and you do nothing. That's not what I understand of helping you to learn, because you learn nothing from it. Then you just put together toy blocks and never understand why they fit together or don't fit.
thomas is offline  
Old 07 January 2012, 23:01   #19
Morbane
Sub-Dimensional Array
 
Morbane's Avatar
 
Join Date: Nov 2011
Location: Australia
Posts: 123
Fair enough - would you happen to have a link to a copy of the Rom Kernel Reference Manual?? I looked around and could not find one - but I am beginning to think it is too recent of a publication that it be free on pdf - I just thought I would ask.
Morbane is offline  
Old 07 January 2012, 23:14   #20
thomas
Registered User
 
thomas's Avatar
 
Join Date: Jan 2002
Location: Germany
Posts: 7,030
I don't think there are PDF versions available. You can either buy the books or the developer CD which contains the RKRMs as AmigaGuide documents. http://www.vesalia.de/e_developer2.htm
thomas is offline  
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Similar Threads
Thread Thread Starter Forum Replies Last Post
Black screen in full screen but not full window Winuae all versions Mixter support.WinUAE 18 30 June 2013 00:45
[Bug] Screen doesn't update in 32-bit window RealNC support.WinUAE 2 25 August 2007 10:43
Window doesnt fit the screen??? richeyjh support.WinFellow 4 04 July 2005 20:17
Winuae 0.8.26 Hangs when load disk image Unregistered support.WinUAE 10 04 June 2004 00:36
Window to Full Screen Nyarlathotep support.WinUAE 4 14 January 2003 23:09

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 01:25.

Top

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Page generated in 0.09800 seconds with 14 queries