M
mathog
I am having one of those days - what I am doing wrong here?
1. The Microsoft EMF+ specification, section 2.2.2.19
http://msdn.microsoft.com/en-us/library/cc231004.aspx
says that GraphicsVersion objects are 32 bits as:
0-19 Metafile Signature
20-31 GraphicsVersion enumeration
2. So I defined what I thought would be the corresponding struct, at
least for Intel platforms. This assumes bitfields are listed in the
struct from least to most significant bits, perhaps they are the other
way around? Or is this one of those areas where the compiler can do
anything it wants?
typedef struct {
unsigned int Signature : 20;
unsigned int GrfVersion : 12;
} U_PMF_GRAPHICSVERSION;
3. Opened a file with EMF+ records and found the corresponding 32 bits.
This is on an Intel architecture machine and the file was made by
Powerpoint on this machine. Examine the value various ways with this code:
U_PMF_GRAPHICSVERSION Version;
printf("DEBUG at offset:%8.8X\n",
*(uint32_t *)contents);
printf("DEBUG at offset by byte:%2.2X %2.2X %2.2X %2.2X\n",
*(uint8_t *)(contents + 0),
*(uint8_t *)(contents + 1),
*(uint8_t *)(contents + 2),
*(uint8_t *)(contents + 3)
);
memcpy(&Version, contents, sizeof(U_PMF_GRAPHICSVERSION));
printf("DEBUG Sig:%X GrfV:%X\n",
Version.Signature, Version.GrfVersion);
The output is
DEBUG at offsetBC01002
DEBUG at offset by byte:02 10 C0 DB
DEBUG Sig:1002 GrfVBC
For an EMF+ file signature must be 0xDBC01, and version can be 2.
I must be screwing up somewhere, but where? The first two DEBUG lines
are consistent with this being a little endian system. "DB" is clearly
at the most significant bit end of the
32 bits, but the EMF+ specification appears to say that it should be
somewhere in the middle. For a little endian machine, doesn't (1) say
that for sig == DBC01 sig and version == 002 the bytes in the file
should be: 01 BC 2D 00 ?? Swapping the order of the bit fields in the
struct above does put DBC01 in Sig and 2 in GrfV, but it does not seem
to be consistent with the documentation.
Thanks,
David Mathog
1. The Microsoft EMF+ specification, section 2.2.2.19
http://msdn.microsoft.com/en-us/library/cc231004.aspx
says that GraphicsVersion objects are 32 bits as:
0-19 Metafile Signature
20-31 GraphicsVersion enumeration
2. So I defined what I thought would be the corresponding struct, at
least for Intel platforms. This assumes bitfields are listed in the
struct from least to most significant bits, perhaps they are the other
way around? Or is this one of those areas where the compiler can do
anything it wants?
typedef struct {
unsigned int Signature : 20;
unsigned int GrfVersion : 12;
} U_PMF_GRAPHICSVERSION;
3. Opened a file with EMF+ records and found the corresponding 32 bits.
This is on an Intel architecture machine and the file was made by
Powerpoint on this machine. Examine the value various ways with this code:
U_PMF_GRAPHICSVERSION Version;
printf("DEBUG at offset:%8.8X\n",
*(uint32_t *)contents);
printf("DEBUG at offset by byte:%2.2X %2.2X %2.2X %2.2X\n",
*(uint8_t *)(contents + 0),
*(uint8_t *)(contents + 1),
*(uint8_t *)(contents + 2),
*(uint8_t *)(contents + 3)
);
memcpy(&Version, contents, sizeof(U_PMF_GRAPHICSVERSION));
printf("DEBUG Sig:%X GrfV:%X\n",
Version.Signature, Version.GrfVersion);
The output is
DEBUG at offsetBC01002
DEBUG at offset by byte:02 10 C0 DB
DEBUG Sig:1002 GrfVBC
For an EMF+ file signature must be 0xDBC01, and version can be 2.
I must be screwing up somewhere, but where? The first two DEBUG lines
are consistent with this being a little endian system. "DB" is clearly
at the most significant bit end of the
32 bits, but the EMF+ specification appears to say that it should be
somewhere in the middle. For a little endian machine, doesn't (1) say
that for sig == DBC01 sig and version == 002 the bytes in the file
should be: 01 BC 2D 00 ?? Swapping the order of the bit fields in the
struct above does put DBC01 in Sig and 2 in GrfV, but it does not seem
to be consistent with the documentation.
Thanks,
David Mathog