Cairo development

This forum is for general developer support questions.
User avatar
YesCop
Posts: 44
Joined: Tue Oct 25, 2011 11:45 pm
Location: Caen, France

Cairo development

Post by YesCop »

Hi everybody,
as I promised (in sdk forum), here is my thread about cairo.

For a week, I am testing cairo functions with some success. Here I will discuss about failures of course.

First, I tried to declare an image surface to save to png file (cairo_surface_write_to_png (surface, "stroke.png") ) after some drawings.
The png filesize is always 0. May be the origin of error is the result of the warnings in the compile (see sdk forum/ subject sdk cairo).
The same happens with cairo_image_surface_create_from_png, if I read the width and height of the surface, they are equal to 0.
I have no clue because I have no compile error and no error during execution.

Second as png didn't work, I tried svg. It is better, that worked almost...
In fact, during my testing procedures, I created two contexts to use composition.
Except for two operators (clear and over), the result was a corrupted svg file. The size is 330 bytes and if I want to see it, I have a window which opens to ask me to give an assign to data:.
My cairo code is good because as soon as I changed the surface creation by cairo_pdf_surface_create, all worked.

Third, it is about cairo_amigaos_surface_create(BitMap *) function.
I didn't see any docs about it, so I don't know how to use it.
I used a previous code which displays an image on a private screen. In there, I created and initialize a bitmap codeI tried to create and initialize with :

Code: Select all

bitmap = IGraphics->AllocBitMap(width, height, depth, BMF_CLEAR | BMF_DISPLAYABLE, NULL);
surface = cairo_amigaos_surface_create (bitmap);
//Now I pass the bitmap pointer to window previously created
IGraphics->BltBitMapRastPort(bitmap, 0, 0, window->RPort, 0, 0, width, height, 0xc0);
Nothing is displayed, here too, I have no error so no clue how to change that. :?

Yes I know, there is a lot of questions, may be the answers are going to be difficult to give.
I hope that at last someone has the solution. :?:

Thanks,
YesCop
chris
Posts: 562
Joined: Sat Jun 18, 2011 11:05 am
Contact:

Re: Cairo development

Post by chris »

It works something like this:

surface = cairo_amigaos_surface_create(rp->BitMap);
cr = cairo_create(surface);
/* draw to your surface here - it will write to rp->BitMap or whatever was specified above */
cairo_destroy(cr);
cairo_surface_destroy(surface);

One word of caution - the BitMap must be a 32-bit ARGB BitMap or it won't work properly. It's best to create one and then blit it to your window , rather than using the window as the Cairo surface - the blit then takes care of the formats (although it is quite slow if where you are blitting to isn't 32-bit ARGB)
User avatar
YesCop
Posts: 44
Joined: Tue Oct 25, 2011 11:45 pm
Location: Caen, France

Re: Cairo development

Post by YesCop »

Hi Chris,

I post my code and is similar to yours, I think. The only thing I didn't care was the depth of 32. Thanks to that.
I added also a palette to see what happens.
But I have no success, nothing is drawn.
Any hints ?

Code: Select all

	width = 800;
	height = 600;
	depth = 32;

	modeID = 0x50001300; //800x600 ARGB32
// I give directly modeID beause Getmodeid didn't give any mode.

	screen = IIntuition->OpenScreenTags(NULL,
			SA_Width, width,
			SA_Height, height,
			SA_Title, (ULONG)"Cairo Test",
			SA_ShowTitle, FALSE,
			SA_DisplayID, modeID,
			SA_Depth, depth,
			SA_Type, CUSTOMSCREEN,
			SA_Interleaved, TRUE,
			SA_FullPalette, TRUE,
			TAG_END);

	window = IIntuition->OpenWindowTags(NULL,
			WA_Left, 0,
			WA_Top, 0,
			WA_Width, width,
			WA_Height, height,
			WA_IDCMP, IDCMP_RAWKEY | IDCMP_MOUSEBUTTONS,
			WA_CustomScreen, (ULONG)screen,
			WA_SizeGadget, FALSE,
			WA_DepthGadget, FALSE,
			WA_CloseGadget, FALSE,
			WA_Borderless, TRUE,
			WA_RMBTrap, TRUE,
			WA_SimpleRefresh, TRUE,
			WA_InnerWidth, width,
			WA_InnerHeight, height,
			TAG_DONE);

        cairo_surface_t *surface;
        cairo_t *cr;

	bitmap = IGraphics->AllocBitMap(width, height, depth, BMF_CLEAR | BMF_DISPLAYABLE, NULL);
	if(bitmap){
		surface = cairo_amigaos_surface_create (bitmap);        
		cr = cairo_create (surface);

	/* Drawing code goes here */
		cairo_set_line_width (cr, 10);
		cairo_set_source_rgba (cr, 1, 0, 0, 1);
		cairo_rectangle (cr, 30, 10, 10, 10);
		cairo_stroke (cr);

	/* Write output and clean up */
	cairo_destroy (cr);
	        cairo_surface_destroy (surface);

/* End Cairo functions */

			ULONG palette[] = {1 << 16 + 0, 0xffffffff, 0, 0, 0, 0xffffffff, 0, 0};
			IGraphics->LoadRGB32(&screen->ViewPort, palette);
			IGraphics->BltBitMapRastPort(bitmap, 0, 0, window->RPort, 0, 0, width, height, 0xc0);
chris
Posts: 562
Joined: Sat Jun 18, 2011 11:05 am
Contact:

Re: Cairo development

Post by chris »

I can't see anything immediately wrong. Instead of AllocBitMap, try using p96AllocBitMap with a type of RGBFB_A8R8G8B8 (and NULL for friend), that will force it into the correct format.

You don't need to load the palette btw, 32-bit BitMaps don't have one. That could be upsetting things.
User avatar
salass00
AmigaOS Core Developer
AmigaOS Core Developer
Posts: 530
Joined: Sat Jun 18, 2011 3:12 pm
Location: Finland
Contact:

Re: Cairo development

Post by salass00 »

chris wrote:You don't need to load the palette btw, 32-bit BitMaps don't have one. That could be upsetting things.
Hi-color and true-color screens in AmigaOS still need to have a palette for pen-based drawing.
User avatar
YesCop
Posts: 44
Joined: Tue Oct 25, 2011 11:45 pm
Location: Caen, France

Re: Cairo development

Post by YesCop »

Hi Chris,

Well Thank you :P , you gave the right tip.
Without you, I will never look into Picaso96 library because I thought it was obsolete in OS4, just there for compatibility with 3.0.
Why did Hyperion team integrate all that stuff in graphics library ?

In regards to the palette, I don't need it as I use RGB numbers to choose colors.

What is the next step ?
I must succeed in loading png files !
chris
Posts: 562
Joined: Sat Jun 18, 2011 11:05 am
Contact:

Re: Cairo development

Post by chris »

YesCop wrote:Hi Chris,

Well Thank you :P , you gave the right tip.
Without you, I will never look into Picaso96 library because I thought it was obsolete in OS4, just there for compatibility with 3.0.
Why did Hyperion team integrate all that stuff in graphics library ?
Most of it is, but there are a couple of things that I still have to use from Picasso96:
1. Allocating a BitMap with a particular pixel format (I supose Cairo needs updating to remove the need for this, as usually the pixel format should be irrelevant)
2. p96WritePixelArray, because it supports RGBA, which BltBitMapTags doesn't.
3. p96EncodeColour, to convert between different formats (easy enough to do manually, but I'm lazy)

OS4 devs - can these be added to graphics.library please?
What is the next step ?
I must succeed in loading png files !
No idea how to do that with Cairo, I would use datatypes to load the image and draw it either using datatypes.library functions, or by directly blitting it from the pixel data (which I tend to have more luck with). Alternatively you can use BOOPSI and add it to the window that way, or even try Intuition's new ObtainBitMap... functions. Many ways. If you need to use Cairo though, it will be the same as Cairo on any other platform.
User avatar
YesCop
Posts: 44
Joined: Tue Oct 25, 2011 11:45 pm
Location: Caen, France

Re: Cairo development

Post by YesCop »

Chris,

Thanks for the info concerning p96 functions, I will remember if needed.
For the png problem, yes I suppose I could use datatypes to load png files. I have already tested this routine alone.
Yes, I could retrieve the pixel datas and transfer to a cairo image (though seems not too easy because of the format ARGB).
This choice will be the last possibility.
I wanted to use directly png functions from cairo, there are two, one for loading (cairo_image_surface_create_from_png) and one for saving (cairo_surface_write_to_png).
I tested them but as I already wrote somewhere, the png file doesn't seem to be loaded as I want to retrieve the width and height, they are equal to 0.
The same for saving, the filesize is 0.
I did my tests with very simple cases and even with sources from cairo sites.
That's the main reason of my post about cairo in sdk section. Something must be missing.
User avatar
salass00
AmigaOS Core Developer
AmigaOS Core Developer
Posts: 530
Joined: Sat Jun 18, 2011 3:12 pm
Location: Finland
Contact:

Re: Cairo development

Post by salass00 »

YesCop wrote:For the png problem, yes I suppose I could use datatypes to load png files. I have already tested this routine alone.
Yes, I could retrieve the pixel datas and transfer to a cairo image (though seems not too easy because of the format ARGB).
Why do you think the ARGB format is a problem? Just use PDTM_READPIXELARRAY with PBPAFMT_ARGB to read the pixel data from the datatype object into your surface buffer.
User avatar
YesCop
Posts: 44
Joined: Tue Oct 25, 2011 11:45 pm
Location: Caen, France

Re: Cairo development

Post by YesCop »

Salass00,

I thought it was difficult when the formats are different.
For example, if I load a jgp file (with no alpha layer) with datatypes and use your method, will I obtain a ARGB pixel data directly, without creating an extra space for allocating the extra bits from alpha channel ?

I don't know if you understood my explanation, a bit difficult to explain in english ! :oops:

Thanks again for your interest
Post Reply