Delphi-PRAXiS
Seite 4 von 6   « Erste     234 56      

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Programmieren allgemein (https://www.delphipraxis.net/40-programmieren-allgemein/)
-   -   Array of Integer und crash (https://www.delphipraxis.net/192085-array-integer-und-crash.html)

Uwe Raabe 19. Mär 2017 22:32

AW: Array of Integer und crash
 
Versuch doch mal so (value ist doch ein Pointer auf den Datenbereich):

Delphi-Quellcode:
CopyMemory(@Prop[0], PropItem.value, PropItem.length);

EWeiss 19. Mär 2017 22:35

AW: Array of Integer und crash
 
Zitat:

Zitat von Uwe Raabe (Beitrag 1364792)
Versuch doch mal so (value ist doch ein Pointer auf den Datenbereich):

Delphi-Quellcode:
CopyMemory(@Prop[0], PropItem.value, PropItem.length);

Geht auch ohne Pointer aber die Daten sind immer noch durcheinander.

gruss

Uwe Raabe 19. Mär 2017 22:47

AW: Array of Integer und crash
 
Das sieht aber immer noch nicht so aus, wie ich das gezeigt hatte:

Delphi-Quellcode:
var
  p: Pointer;
//###############
// Bytearray dimensionieren
p := @PropItem;
GetMem(p, PropSize);

SetLength(Prop, (PropItem.length - 1));
CopyMemory(@Prop[0], @PropItem.value, PropItem.length);

FreeMem(p);

So sollte es auch mit dem Prop-Array gehen:

Delphi-Quellcode:
   PropSize: UINT;
   PropItem: PPropertyItem; // dynamischer Pointer auf Record, deswegen PPropertyItem und nicht TPropertyItem


  if GDIP_GetPropertyItemSize(InGifImage, PropertyTagFrameDelay, PropSize) = S_OK then
  begin
    GetMem(PropItem, PropSize); // Record in passender Größe bereitstellen
    // Daten auslesen
    if GetPropertyItem(InGifImage, PropertyTagFrameDelay, PropSize, PropItem^) = S_OK then begin
      SetLength(Prop, PropItem.length); // nix -1 !!!
      CopyMemory(@Prop[0], PropItem.value, PropItem.length);    
      ...
    end;
    FreeMem(PropItem); // Delphi merkt sich die Size intern

EWeiss 19. Mär 2017 22:58

AW: Array of Integer und crash
 
Zitat:

Zitat von Uwe Raabe (Beitrag 1364794)
Das sieht aber immer noch nicht so aus, wie ich das gezeigt hatte:


Sorry das mit GetMem funktioniert nicht.
GetMem erwartet einen Pointer PropItem ist aber als TPropertyItem definiert.
Was aber korrekt ist ich muss den Speicher vor GetPropertyItem allokieren ich habe es nachher gemacht.


EDIT:
OK hab dich verstanden funktioniert jetzt ;)
Danke für deine Mühe und Zeit.
Habe wieder einiges gelernt. :)

So soll es sein das Ergebniss.. jedes Frame läuft 80ms.
Hier nochmal das gesamt Ergebnis vielleicht kann es ja mal jemand brauchen.

Delphi-Quellcode:
procedure TAnimateGif.GetGifFrameDelays(GifImage: Cardinal; FrameCount: UINT;
  var FrameDelay: TFrameDelay);
var
  ISize: integer;
  PropSize: UINT;
  Prop: TProp;
  PropCount: integer;
begin

  ISize := 0;

  // Datengröße vom EXIF-Tag PropertyTagFrameDelay ermitteln
  if GDIP_GetPropertyItemSize(GifImage, PropertyTagFrameDelay, PropSize) = S_OK then
  begin
    // Speicher allokieren
    GetMem(PropItem, PropSize);
   
    // Daten auslesen
    if GetPropertyItem(GifImage, PropertyTagFrameDelay, PropSize, PropItem) = S_OK then
    begin
      // Bytearray dimensionieren
      SetLength(Prop, (PropItem.length + 1));
      CopyMemory(@Prop[0], PropItem.value, PropItem.length);

      // PropertyTyp ermitteln
      case PropItem.type_ of
        PropertyTagTypeByte:
          ISize := 1;

        PropertyTagTypeShort:
          ISize := 2;

        PropertyTagTypeLong:
          ISize := 4;
      end;

      // Array zur Aufnahme der Pausenzeiten dimensionieren
      SetLength(FrameDelay, FrameCount);
      // Pausenzeiten der einzelnen Bilder aus Bytearray kopieren
      for PropCount := 0 to (FrameCount - 1) do
      begin
        CopyMemory(@FrameDelay[PropCount], @Prop[PropCount * ISize], ISize);
        FrameDelay[PropCount] := FrameDelay[PropCount] * 10;
      end;
    end;
    FreeMem(PropItem);
  end;

end;
gruss

EWeiss 26. Sep 2018 13:28

AW: Array of Integer und crash
 
Muss das nochmal aufgreifen..

Habe das Projekt nach 64 Bit umgelegt bekomme aber jetzt fortlaufend "Inaccessible value"
Delphi-Quellcode:
function TAnimateGif.GetPropertyItem(GifImage: LONG_PTR; PropertyID: ULONG; PropertyItemSize: UINT;
  var PropertyItemData: PPropertyItem): GPSTATUS;
begin

  // Daten auslesen
  Result := GDIP_GetPropertyItem(GifImage, PropertyID, PropertyItemSize, PropertyItemData);
end;
Delphi-Quellcode:
function GDIP_GetPropertyItem(Img: LONG_PTR; propId: PROPID; propSize: UINT;
  var buffer: PPROPERTYITEM
): GPSTATUS; stdcall;
begin

  result := GdipGetPropertyItem(Img, propId, propSize, buffer);
end;
bevor GdipGetPropertyItem aufgerufen wird ist der Buffer gefüllt.
Nach dem Aufruf von GdipGetPropertyItem ist der buffer Inaccessible.

Wie immer tritt nur unter 64 Bit auf.

Die Funktion ist diese.
Delphi-Quellcode:
GdipGetPropertyItem: function(Image: LONG_PTR; propId: PROPID; propSize: UINT; var buffer: PPROPERTYITEM): GPSTATUS; stdcall;


Und der Record der..
Delphi-Quellcode:
  PropertyItem = record // NOT PACKED !!
    id      : PROPID; // ID of this property
    length  : ULONG;  // Length of the property value, in bytes
    type_    : WORD;   // Type of the value, as one of TAG_TYPE_XXX
    value   : Pointer; // property value
  end;
  TPropertyItem = PropertyItem;
  PPropertyItem = ^TPropertyItem;
es kracht dann hier
Delphi-Quellcode:
    // Daten auslesen
    if GetPropertyItem(GifImage, PropertyTagFrameDelay, PropSize, FPropItem) = OK then
    begin
      // Bytearray dimensionieren
      SetLength(Prop, PropItem.Length);
      CopyMemory(@Prop[0], PropItem.value, PropItem.Length);
weil PropItem bzw. vorher schon PropertyItemData nicht zugänglich ist.

PS:
Es hat nichts mit dem setzen der Optimierung zu tun!

gruss

TiGü 26. Sep 2018 14:11

AW: Array of Integer und crash
 
Zitat:

Zitat von EWeiss (Beitrag 1414255)
Delphi-Quellcode:
    // Daten auslesen
    if GetPropertyItem(GifImage, PropertyTagFrameDelay, PropSize, FPropItem) = OK then
    begin
      // Bytearray dimensionieren
      SetLength(Prop, PropItem.Length);
      CopyMemory(@Prop[0], PropItem.value, PropItem.Length);

Du füllst FPropItem und greifst dann auf PropItem (ohne F) zu.

EWeiss 26. Sep 2018 14:15

AW: Array of Integer und crash
 
Zitat:

Zitat von TiGü (Beitrag 1414260)
Zitat:

Zitat von EWeiss (Beitrag 1414255)
Delphi-Quellcode:
    // Daten auslesen
    if GetPropertyItem(GifImage, PropertyTagFrameDelay, PropSize, FPropItem) = OK then
    begin
      // Bytearray dimensionieren
      SetLength(Prop, PropItem.Length);
      CopyMemory(@Prop[0], PropItem.value, PropItem.Length);

Du füllst FPropItem und greifst dann auf PropItem (ohne F) zu.

FPropItem ist nicht zugänglich. (Inaccessible)
Und ja das gleiche tue ich auch unter 32 Bit ohne Probleme..

Danke.
Der Fehler den ich bekomme ist EInOutError..

zudem es ist ein Property
Delphi-Quellcode:
property PropItem: PPropertyItem read FPropItem write FPropItem;


FPropItem liest und weist das Result PropItem zu beide haben also den gleichen Wert.

gruss

TiGü 26. Sep 2018 14:20

AW: Array of Integer und crash
 
Reservierst du denn vorher Speicher von der Größe, die dir GdipGetPropertyItemSize liefert, für deine Membervariable FPropItem bzw. für das dahinterliegende Record?

EWeiss 26. Sep 2018 14:23

AW: Array of Integer und crash
 
Zitat:

Zitat von TiGü (Beitrag 1414262)
Reservierst du denn vorher Speicher von der Größe, die dir GdipGetPropertyItemSize liefert, für deine Membervariable FPropItem bzw. für das dahinterliegende Record?

Ja..
Delphi-Quellcode:
  // Datengröße vom EXIF-Tag PropertyTagFrameDelay ermitteln
  if GDIP_GetPropertyItemSize(GifImage, PropertyTagFrameDelay, PropSize) = OK then
  begin
    // Speicher allokieren
    GetMem(FPropItem, PropSize);
gruss

TiGü 26. Sep 2018 14:39

AW: Array of Integer und crash
 
Ein kleines 20-50 Zeilenprogramm zum nachvollziehen und selber kompilieren?


Alle Zeitangaben in WEZ +1. Es ist jetzt 12:00 Uhr.
Seite 4 von 6   « Erste     234 56      

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz