By skipping 12 bytes in, what you're doing is seeking straight to the
header where the file format spec states the height and width reside -
essentially, the file format spec says say so.

The specific bits you're implementing:
- A DDS file begins with a DWORD sized magic number (you want to look
  for the magic 0x20534444) and then a header block.
- Within the header block itself, there are two DWORDs you're then
  skipping past which are the elements dwSize (always set to 124), and
  dwFlags (describes what elements exist)


file format:
https://msdn.microsoft.com/en-us/library/windows/desktop/bb943991%28v=vs.85%29.aspx
header detail :
https://msdn.microsoft.com/en-us/library/windows/desktop/bb943982(v=vs.85).asp[1]




On Thu, May 21, 2015, at 10:32 AM, Benjam901 wrote:
> Hey guys,
>
> I got there in the end.
>
> ddsFile = open(filePath, 'rb')
>
> ddsFile.read(4) # Read the magic
>
> ddsFile.read(8) # Skip 8 bytes in
>
> height = struct.unpack('i', ddsFile.read(4))[0]
>
> width = struct.unpack('i', ddsFile.read(4))[0]
>
>
> Could anyone explain to me why we have to skip 4 bytes in and then 8
> bytes also. I understand there are various magic numbers in headers
> but thats about it, being able to understand what is going on properly
> for future reference would be brilliant!!
>
> On Wednesday, 20 May 2015 12:24:16 UTC-7, Benjam901 wrote:
>> OK so here is an image I just converted that has BC5u compression and
>> cannot be read by my image library. Thank you for the help! :)
>>
>> On Wednesday, 20 May 2015 12:18:18 UTC-7, Benjam901 wrote:
>>> Scratch that, the converter popped out a DXT5. Fixing that now
>>>
>>> On Wednesday, 20 May 2015 12:01:38 UTC-7, Benjam901 wrote:
>>>> Yeah of course, see attached. I was thinking decoding it manually
>>>> also, some help on it would be much appreciated!
>>>>
>>>> The image attached is encoded in the correct image format BC5(DX10)
>>>>
>>>> On Wednesday, 20 May 2015 11:47:23 UTC-7, damonshelton wrote:
>>>>> can you provide a test dds with that compression. might be able to
>>>>> parse the data yourself form the binary directly
>>>>>
>>>>>
>>>>> On Wed, May 20, 2015 at 11:44 AM, Benjam901 <[email protected]>
>>>>> wrote:
>>>>>> Hello all,
>>>>>>
>>>>>> I am having a few troubles trying to load up a whole bunch of
>>>>>> .dds files into python to check their size before downscale.
>>>>>>
>>>>>> I am batch downsizing them to test memory, normally using DXT5
>>>>>> compression wouldn't be a huge issue because various python image
>>>>>> libraries can load them like Pyglet (which I am trying to use)
>>>>>>
>>>>>> *However* the issue I am having is that we are using the newer
>>>>>> BC5 compression and it is rather new (so new in fact Maya won't
>>>>>> load the images) and neither will the image library pyglet. This
>>>>>> would indicate to me that there is little support for the image
>>>>>> formats yet.
>>>>>>
>>>>>> I have tried to install PyFFI to test but it requires python 3.0
>>>>>> and devIL does not seem to have any solid documentation on how to
>>>>>> use it.
>>>>>>
>>>>>> Has anyone worked with this image compression before and if so
>>>>>> which library did you use to load the images?
>>>>>>
>>>>>> Cheers,
>>>>>>
>>>>>> Ben
>>>>>>
>>>>>>


>>>>>>

--
>>>>>>
You received this message because you are subscribed to the Google
Groups "Python Programming for Autodesk Maya" group.
>>>>>>
To unsubscribe from this group and stop receiving emails from it, send
an email to [email protected].
>>>>>>
To view this discussion on the web visit
https://groups.google.com/d/msgid/python_inside_maya/3a4148c0-3458-42c7-9023-608d87830b9d%40googlegroups.com[2].
>>>>>>
For more options, visit https://groups.google.com/d/optout.
>>>>>
>


> --
> You received this message because you are subscribed to the Google
> Groups "Python Programming for Autodesk Maya" group. To unsubscribe
> from this group and stop receiving emails from it, send an email to
> [email protected]. To view this
> discussion on the web visit
> https://groups.google.com/d/msgid/python_inside_maya/44604730-d6da-40d4-a535-fecfe4fbb993%40googlegroups.com[3].
> For more options, visit https://groups.google.com/d/optout.



Links:

  1. 
https://msdn.microsoft.com/en-us/library/windows/desktop/bb943982(v=vs.85).aspx
  2. 
https://groups.google.com/d/msgid/python_inside_maya/3a4148c0-3458-42c7-9023-608d87830b9d%40googlegroups.com?utm_medium=email&utm_source=footer
  3. 
https://groups.google.com/d/msgid/python_inside_maya/44604730-d6da-40d4-a535-fecfe4fbb993%40googlegroups.com?utm_medium=email&utm_source=footer

-- 
You received this message because you are subscribed to the Google Groups 
"Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/python_inside_maya/1432169900.3976379.274328921.48DC2A3A%40webmail.messagingengine.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to