Show image in bitmap crash my system

5 posts / 0 new
Last post
walkero
walkero's picture
Offline
Last seen: 3 months 3 weeks ago
Joined: 2009-05-03 16:54
Show image in bitmap crash my system

Hello guys,
I have a problem with a project I work on. The project has a list of files which are all images. When the user clicks on one of them the image should be loaded at a bitmap.image I have.

I set the bitmap lika that

  1. LAYOUT_AddImage, objects[OID_Bitmap_Pic] = IIntuition->NewObject(NULL, "bitmap.image",
  2. BITMAP_SourceFile, "logo.png",
  3. BITMAP_Screen, screen,
  4. BITMAP_Precision, PRECISION_EXACT,
  5. BITMAP_Masking, TRUE,
  6. BITMAP_Width, 250,
  7. BITMAP_Height, 250,
  8. TAG_END),
  9. CHILD_NoDispose, TRUE,

Later in the code I set these:

  1. Object *dt_Obj;
  2. struct dtFrameBox dtf = {0};
  3. struct FrameInfo fri = {0};
  4. struct pdtScale pdt;
  5. struct gpLayout gpl;
  6. struct BitMap *dt_Bitmap;
  7. struct BitMapHeader *bmh = NULL;
  8. int srcimagewidth, srcimageheight, srcimagedepth;
  9. int DestWidth, DestHeight;

The code to read the selected file:

  1. dt_Obj = IDataTypes->NewDTObject((APTR) filename,
  2. DTA_SourceType, DTST_FILE,
  3. DTA_GroupID, GID_PICTURE,
  4. PDTA_DestMode, PMODE_V43,
  5. //PDTA_Remap, TRUE,
  6. PDTA_Screen, screen,
  7. PDTA_FreeSourceBitMap, TRUE,
  8. PDTA_ScaleQuality, scalequality,
  9. TAG_DONE);
  10.  
  11. if(dt_Obj)
  12. {
  13. dtf.MethodID = DTM_FRAMEBOX;
  14. dtf.dtf_FrameInfo = &fri;
  15. dtf.dtf_ContentsInfo = &fri;
  16. dtf.dtf_SizeFrameInfo = sizeof(struct FrameInfo);
  17. if(IIntuition->IDoMethodA(dt_Obj,(Msg)&dtf) && fri.fri_Dimensions.Depth)
  18. {
  19. pdt.MethodID = PDTM_SCALE;
  20. pdt.ps_NewWidth = width;
  21. pdt.ps_NewHeight = height;
  22. pdt.ps_Flags = 0;
  23. if(!(IIntuition->IDoMethodA(dt_Obj,(Msg)&pdt)))
  24. printf("Datatype scaling missed\n");
  25.  
  26. gpl.MethodID = DTM_PROCLAYOUT;
  27. gpl.gpl_GInfo = NULL;
  28. gpl.gpl_Initial = 1;
  29. if(IIntuition->IDoMethodA(dt_Obj,(Msg)&gpl))
  30. {
  31. IDataTypes->GetDTAttrs(dt_Obj,
  32. PDTA_DestBitMap, &dt_Bitmap,
  33. PDTA_BitMapHeader, (ULONG)&bmh,
  34. TAG_DONE);
  35. //if(dt_Bitmap)
  36. //{
  37.  
  38.  
  39. //Determine the source image size
  40. srcimagewidth = bmh->bmh_Width;
  41. srcimageheight = bmh->bmh_Height;
  42. srcimagedepth = bmh->bmh_Depth;
  43.  
  44. printf("Display-Photo: Starting image size imagewidth %d, imageheight %d\n", srcimagewidth,srcimageheight);
  45.  
  46. //dt_Bitmap = IP96->p96AllocBitMap( srcimagewidth, srcimageheight, 32, BMF_DISPLAYABLE, NULL, RGBFB_A8R8G8B8 );
  47. //dt_Bitmap = IGraphics->AllocBitMap( srcimagewidth, srcimageheight, 32, BMF_CLEAR|BMF_DISPLAYABLE, screen->RastPort.BitMap);
  48.  
  49. /*
  50.   struct RenderInfo renderInfo;
  51. lock = IP96->p96LockBitMap(dt_Bitmap,
  52. (UBYTE*)&renderInfo, sizeof(renderInfo));
  53.  
  54. srcBytesPerRow = IP96->p96GetBitMapAttr(dt_Bitmap, P96BMA_BYTESPERROW);
  55.  
  56. IIntuition->IDoMethod(dt_Obj,
  57. PDTM_READPIXELARRAY,
  58. renderInfo.Memory,
  59. PBPAFMT_ARGB,
  60. srcBytesPerRow,
  61. 0,
  62. 0,
  63. srcimagewidth,
  64. srcimageheight,
  65. TAG_END);
  66.  
  67. //Unlock the bitmap
  68. IP96->p96UnlockBitMap(dt_Bitmap, lock);*/
  69. if(dt_Bitmap) {
  70. //printf("%u\n", objects[OID_Bitmap_Pic]->Width);
  71. IIntuition->GetAttrs(objects[OID_Bitmap_Pic],
  72. BITMAP_Width, &DestWidth,
  73. BITMAP_Height, &DestHeight,
  74. TAG_DONE);
  75. printf("Display-Photo: Destination gadget image size imagewidth %d, imageheight %d\n", DestWidth,DestHeight);
  76.  
  77. IIntuition->RefreshSetGadgetAttrs((struct Gadget *)objects[OID_Bitmap_Pic], (struct Window *)wins[WIN_COMICA_MAIN], NULL,
  78. LAYOUT_ModifyChild, objects[OID_Bitmap_Pic],
  79. CHILD_ReplaceObject, dt_Bitmap,
  80. TAG_DONE);
  81.  
  82. /*IIntuition->RefreshSetGadgetAttrs((struct Gadget *)objects[OID_LAYOUT_MAIN], (struct Window *)wins[WIN_COMICA_MAIN], NULL,
  83. LAYOUT_ModifyChild, objects[OID_Bitmap_Pic],
  84. CHILD_ReplaceObject, dt_Bitmap,
  85. TAG_END );
  86. */
  87. }
  88.  
  89.  
  90. //}
  91. //else printf("It isn't a bitmap\n");
  92. }
  93. else printf("The picture cannot be displayed\n");
  94. }
  95. else printf("Cannot use the datatype\n");
  96.  
  97. IDataTypes->DisposeDTObject(dt_Obj);
  98. }
  99. else printf("No suitable datatype\n");

I left here the remarked codes to see the various tests I did.
Unfortunately, as soon as the IIntuition->RefreshSetGadgetAttrs is executed, the program hangs the whole system and I can't get why this happens. As you can see I tested a lot of codes.

Can you please help me to ovveride this problem? Is it OK to use the bitmap.image for this job? Can I also change it's size to match the size of the outer layout?

Thanks in advance for your kind help.

thomas
thomas's picture
Offline
Last seen: 3 months 1 week ago
Joined: 2011-05-16 14:23
1. you are trying to replace

1. you are trying to replace an image by a bitmap. It is seldomly possible to replace an object by one of a different type. Surely not in this case.

2. you are trying to replace a BOOPSI object by a piece of storage. ReAction expects to work on BOOPSI objects in most places, so that methods can be executed on them. But the bitmap you use is just an area of memory without a BOOPSI class around it.

I would suggest to simply set the BITMAP_SourceFile attribute of the image object to the new file name. This saves you a lot of work with datatypes and such.

walkero
walkero's picture
Offline
Last seen: 3 months 3 weeks ago
Joined: 2009-05-03 16:54
Re: Show image in bitmap crash my system

Thanks Thomas for your reply.
I see what you are saying to me, but I also get a hard freeze of the system even when I try to simple remove the bitmap object, with the following code. I guess that the problem is somewhere else in my code.

  1. IIntuition->RefreshSetGadgetAttrs((struct Gadget *)objects[OID_LAYOUT_MAIN], (struct Window *)wins[WIN_COMICA_MAIN], NULL,
  2. LAYOUT_RemoveChild, objects[OID_Bitmap_Pic],
  3. TAG_DONE);
thomas
thomas's picture
Offline
Last seen: 3 months 1 week ago
Joined: 2011-05-16 14:23
Without seeing the entire

Without seeing the entire code I have two guesses:

- OID_Bitmap_PIC is not a member of OID_LAYOUT_MAIN but of another layout group.

- instead of RefreshSetGadgetAttrs you might have to use SetAttrs and then call RethinkLayout or WM_RETHINK.

You should also be aware that after using LAYOUT_RemoveChild OID_Bitmap_Pic no longer exists and the pointer stored in objects[OID_Bitmap_Pic] is invalid. Do not try to dispose of the object again later.

broadblues
broadblues's picture
Offline
Last seen: 4 years 9 months ago
Joined: 2012-05-02 21:48
2. LAYOUT_RemoveChild,

2. LAYOUT_RemoveChild, objects[OID_Bitmap_Pic],

Don't use LAYOUT_RemoveChild on a layout attached to a window.

Use instead the method LM_REMOVECHILD.

Log in or register to post comments