byte **p
byte *q,*d
*q = p[0]
*d = p[1]
//怎么改成delphi的?type pbyte = ^byte;
ppbyte = ^pbyte;
end;
//声明
var p:ppbyte;
q,d:pbyte;//赋值
q := pbyte(p^); //我这么理解的
d := //怎么弄?
byte *q,*d
*q = p[0]
*d = p[1]
//怎么改成delphi的?type pbyte = ^byte;
ppbyte = ^pbyte;
end;
//声明
var p:ppbyte;
q,d:pbyte;//赋值
q := pbyte(p^); //我这么理解的
d := //怎么弄?
//声明
type
pbyte = ^byte; //pbyte可以不自己定义,Windows单元里已经有定义了
ppbyte = ^pbyte;var
p: ppbyte;
q,d: pbyte;//赋值
q := p^;
inc(p);
d := p^;
d := pbyte(integer(p)+sizeof(byte))^;
TPByteArray = packed array[0..(MaxLongint div SizeOf(PByte))-1] of PByte;
PPByteArray = ^TPByteArray;
var
p: PPByteArray;
q,d: PByte;
begin
q^ := Byte(p[0]);
d^ := Byte(p[1]);
end;
建议楼主还是把最原始的C代码发出来,否则得到的结果,可能并非预期的。
pbyte = ^byte;
ppbyte = ^pbyte;procedure TForm1.Button1Click(Sender: TObject);
var
a: array [0..1] of pbyte;
p: ppbyte;
q,d: pbyte;
begin
new(a[0]);
new(a[1]);
a[0]^ := 100;
a[1]^ := 200; p := @a[0];
q := p^;
ShowMessage(IntToStr(q^));
d := ppbyte(integer(p) + sizeof(p^))^;
ShowMessage(IntToStr(d^));
inc(p);
d := p^;
ShowMessage(IntToStr(d^));
end;
byte **p
byte *q,*d
*q = p[0]
*d = p[1]
这样的代码,而极有可能是:
result_type function_name(byte *q,byte *d)
{
...
}byte **p...result_type ret = function_name(p[0],p[1]);
如果是这样,那跟楼主贴出的代码就是天壤之别了。
//
typedef struct AVPicture {
uint8_t *data[4];
int linesize[4]; ///< number of bytes per line
} AVPicture;
/* The YUV hardware video overlay */
typedef struct SDL_Overlay {
Uint32 format; /* Read-only */
int w, h; /* Read-only */
int planes; /* Read-only */
Uint16 *pitches; /* Read-only */
Uint8 **pixels; /* Read-write */ /* Hardware-specific surface info */
struct private_yuvhwfuncs *hwfuncs;
struct private_yuvhwdata *hwdata; /* Special flags */
Uint32 hw_overlay :1; /* Flag: This overlay hardware accelerated? */
Uint32 UnusedBits :31;
} SDL_Overlay;//----------------------------------------- SDL_Overlay *bmp; AVPicture pict; pict.data[0] = bmp->pixels[0];
pict.data[1] = bmp->pixels[2];
pict.data[2] = bmp->pixels[1]; pict.linesize[0] = bmp->pitches[0];
pict.linesize[1] = bmp->pitches[2];
pict.linesize[2] = bmp->pitches[1];
PSDL_Overlay = ^TSDL_Overlay;
TSDL_Overlay = record
format: UInt32; // Overlay format
w, h: Integer; // Width and height of overlay
planes: Integer; // Number of planes in the overlay. Usually either 1 or 3
pitches: PUInt16;
// An array of pitches, one for each plane. Pitch is the length of a row in bytes.
pixels: PPUInt8;
// An array of pointers to the data of each plane. The overlay should be locked before these pointers are used.
hw_overlay: UInt32;
// This will be set to 1 if the overlay is hardware accelerated.
end; PAVPicture = ^TAVPicture;
TAVPicture = record
data: array[0..3] of PByte;
linesize: array[0..3] of int; ///< number of bytes per line
end;
//---------------------var
bmp: PSDL_Overlay;
pict: TAVPicture;
pict.data[0] := system.pbyte(bmp.pixels^); // system.PByte(bmp.pixels^);
inc(bmp.pixels); inc(bmp.pixels);
pict.data[1] := system.pbyte(bmp.pixels^);
dec(bmp.pixels);
pict.data[2] := system.pbyte(bmp.pixels^);
dec(bmp.pixels);
pict.linesize[0] := (bmp.pitches^); // Integer(bmp.pitches^ );
inc(bmp.pitches); inc(bmp.pitches);
pict.linesize[1] := (bmp.pitches^);
dec(bmp.pitches);
pict.linesize[2] := (bmp.pitches^);
dec(bmp.pitches); // pict.linesize[1] := Pint(integer(bmp.pitches) + 1 * sizeof(int))^;
// pict.linesize[2] := Pint(integer(bmp.pitches) + sizeof(int))^; //我这么用的。不过感觉不爽。总觉得哪里不对。
type
TPByteArray = packed array[0..(MaxLongint div SizeOf(PByte))-1] of PByte;
PPByteArray = ^TPByteArray;
//
//typedef struct AVPicture {\
type
AVPicture = record
//uint8_t *data[4];
data: array[0..4-1] of PByte;
//int linesize[4]; ///< number of bytes per line
linesize: Array[0..4-1] of Integer;
//} AVPicture;
end;
LPAVPicture = ^AVPicture;
type
lp_private_yuvhwfuncs = ^private_yuvhwfuncs;
lp_private_yuvhwdata = ^private_yuvhwdata;
(* The YUV hardware video overlay *)
//typedef struct SDL_Overlay {
type
SDL_Overlay = record
//Uint32 format; /* Read-only */
format: LongWord;
//int w, h; /* Read-only */
w: Integer;
h: Integer;
//int planes; /* Read-only */
planes: Integer;
//Uint16 *pitches; /* Read-only */
pitches: PWORD;
//Uint8 **pixels; /* Read-write */
pixels: PPByteArray; (* Hardware-specific surface info *)
//struct private_yuvhwfuncs *hwfuncs;
hwfuncs: lp_private_yuvhwfuncs;
//struct private_yuvhwdata *hwdata;
hwdata: lp_private_yuvhwdata; (* Special flags *)
//Uint32 hw_overlay :1; /* Flag: This overlay hardware accelerated? */
//Uint32 UnusedBits :31;
hw_overlay_containt: LongWord; //使用时这里需要注意取相应的bit
//} SDL_Overlay;
end;
LP_SDL_Overlay = ^SDL_Overlay;
//-----------------------------------------// SDL_Overlay *bmp;
var
bmp: LP_SDL_Overlay; //AVPicture pict;
pict: AVPicture;
begin
// pict.data[0] = bmp->pixels[0];
// pict.data[1] = bmp->pixels[2];
// pict.data[2] = bmp->pixels[1];
//
// pict.linesize[0] = bmp->pitches[0];
// pict.linesize[1] = bmp->pitches[2];
// pict.linesize[2] = bmp->pitches[1];
pict.data[0] := bmp^.pixels[0];
...end;
您理解错我了,我的那种方式是可以实现,这个是一个FFMPEG和SDL的解码的代码。
我后来的那个写法是可以解码的,当然把 pixels 弄成指针数组也是可以的,但是SDL是c语言写的,处理的时候怕会有问题。
c里面pict.data[0] = bmp->pixels[0];这样写,是因为c这样弱类语言指针使用的灵活导致,并不是真正的数组吧?pict.data[1]:= pbyte(integer(bmp.pixels)+8)^; //指针是整形的,长度4位。
pict.data[2]:= pbyte(integer(bmp.pixels)+4)^;
我这样写也是可以的,或许这样写才是对的,不知道为什么的,SDL库处理bmp的时候总司报错,我用
inc(bmp.pixels); inc(bmp.pixels);
pict.data[1] := system.pbyte(bmp.pixels^);
dec(bmp.pixels);
pict.data[2] := system.pbyte(bmp.pixels^);
dec(bmp.pixels);
这种方式才能编译通过,不知道为什么的。
// pict.data[0] = bmp->pixels[0];
// pict.data[1] = bmp->pixels[2];
// pict.data[2] = bmp->pixels[1];
//
// pict.linesize[0] = bmp->pitches[0];
// pict.linesize[1] = bmp->pitches[2];
// pict.linesize[2] = bmp->pitches[1];以上函数 可是 SDL 窗口还是一片漆黑,,,纠结死了 转换成 RGB 保存 是有图像的 - -.