Recent

Author Topic: How to handle DDS Files?  (Read 3682 times)

knuckles

  • Full Member
  • ***
  • Posts: 122
How to handle DDS Files?
« on: September 29, 2017, 12:58:26 am »
I need to work with some DDS (direct draw surface i believe?) Files. What I need is to be able to load and save them, but also convert to and from bitmap or at the very least be able to draw my own bitmap and convert and save in DDF format.

I came across this https://git.bergmann89.de/opengl/glBitmap which looks promising, I am able to test and load the DDS File, and save to memory stream and save back to file (i test memory stream to see if i can load the file in a TImage for example).

So in summary:

- Load DDS File
- Save DDS File

these functions are provided and work from the link above.

All I need now is the ability to convert it to TBitmap for displaying in TImage etc and also for drawing on, and then I need to save my modified bitmap back to DDS File.

I see no obvious way of working with bitmaps from the code provided in the link above but I will play around some more and see what I can find. Failing that, is there any other solutions that might help me with DDS File IO and conversion to and from TBitmap?

Thanks

knuckles

  • Full Member
  • ***
  • Posts: 122
Re: How to handle DDS Files?
« Reply #1 on: September 29, 2017, 01:23:05 am »
Ok so I just discovered how to load in as TBitmap into the TImage control,

Code: Pascal  [Select]
  1. var
  2.   data: TglBitmapData;
  3. begin
  4.   //...
  5.   data.SaveToStream(MS, ftBMP); //ftBMP not ftDDS
  6.   //...
  7. end;

Once I test editing bitmap and hopefully saving back to dds format I will post all the code, which I originally took from one of the examples on the link above.

Akira1364

  • Hero Member
  • *****
  • Posts: 539
Re: How to handle DDS Files?
« Reply #2 on: September 30, 2017, 11:50:55 pm »
The Vampyre Imaging Library (written in Delphi/FPC) is also capable of loading DDS files, if I recall correctly.... the trunk for it is found here, if you want to check it out:

https://sourceforge.net/p/imaginglib/code/ci/default/tree/
« Last Edit: October 01, 2017, 02:07:15 am by Akira1364 »

Eugene Loza

  • Hero Member
  • *****
  • Posts: 562
    • My "almost daily" development blog
Re: How to handle DDS Files?
« Reply #3 on: October 01, 2017, 12:19:07 am »
As far as I've investigated the question, the best quality is provided by NVidia plugin called NVCompress (and decompression is available too, but I don't remember the name), which is Free and Open-Source, MIT-licensed. Thou originally it's command-line, so you'll have to call it through TProcess to generate intermediate files.
Lazarus 1.9 + FPC 3.1.1 Debian Jessie 64 bit.

My Free and Open Source games in Lazarus/FreePascal/CastleGameEngine:
https://decoherence.itch.io/
(and some ancient games in Turbo Pascal too)
Sources are here: https://github.com/eugeneloza?tab=repositories

Akira1364

  • Hero Member
  • *****
  • Posts: 539
Re: How to handle DDS Files?
« Reply #4 on: October 01, 2017, 12:57:16 am »
As far as I've investigated the question, the best quality is provided by NVidia plugin called NVCompress (and decompression is available too, but I don't remember the name), which is Free and Open-Source, MIT-licensed. Thou originally it's command-line, so you'll have to call it through TProcess to generate intermediate files.

I don't see how NVCompress would help him load DDS files that already exist into memory in an application written in Object Pascal. NVCompress creates (with compression, as the name says) images and outputs them to disk.

Eugene Loza

  • Hero Member
  • *****
  • Posts: 562
    • My "almost daily" development blog
Re: How to handle DDS Files?
« Reply #5 on: October 01, 2017, 01:04:56 am »
I don't see how NVCompress would help him load DDS files that already exist into memory in an application written in Object Pascal. NVCompress creates (with compression, as the name says) images and outputs them to disk.
And nvdecompress (had to double-check the name) does the reverse. It decompresses a DDS file to disk which can be read by any software, including loading into a TImage.
In raw case it'd require storing an intermediate/temporary BMP file.
However, as nvidia texture tools is MIT, anybody can make them into a library / unit. There's already a compiled nvtt.lib in the folder, thou I've never used libraries before, and I can't advice on how to load it in FreePascal.
Lazarus 1.9 + FPC 3.1.1 Debian Jessie 64 bit.

My Free and Open Source games in Lazarus/FreePascal/CastleGameEngine:
https://decoherence.itch.io/
(and some ancient games in Turbo Pascal too)
Sources are here: https://github.com/eugeneloza?tab=repositories

Akira1364

  • Hero Member
  • *****
  • Posts: 539
Re: How to handle DDS Files?
« Reply #6 on: October 01, 2017, 02:20:54 am »
I don't see how NVCompress would help him load DDS files that already exist into memory in an application written in Object Pascal. NVCompress creates (with compression, as the name says) images and outputs them to disk.
And nvdecompress (had to double-check the name) does the reverse. It decompresses a DDS file to disk which can be read by any software, including loading into a TImage.
In raw case it'd require storing an intermediate/temporary BMP file.
However, as nvidia texture tools is MIT, anybody can make them into a library / unit. There's already a compiled nvtt.lib in the folder, thou I've never used libraries before, and I can't advice on how to load it in FreePascal.

Well, that's technically true, yes. Just seems extremely strange to recommend a command line tool written in C++ specically meant for development in C++, when there are "code-only" (as in no external binaries required) native options written in Pascal...

Also, FPC is incapable of linking against static libraries that were compiled with MSVC in Visual Studio (for reasons I'm not sure of... it sure would be nice if it could!) so using the lib file would be a no-go from the outset. You would need a version of the library compiled with some form of MinGW to be able to link against it on Windows.

The most "long-term useful" option for someone who really wanted to use NVTT with Pascal, frankly, would be to simply translate the original C++ source to Pascal as it could then be directly used in any project.
« Last Edit: October 01, 2017, 04:02:36 am by Akira1364 »

Eugene Loza

  • Hero Member
  • *****
  • Posts: 562
    • My "almost daily" development blog
Re: How to handle DDS Files?
« Reply #7 on: October 01, 2017, 08:04:16 am »
(no external binaries required) native options written in Pascal...
I can't pretend to be 100% true in this case, however, as far as I've read Nvidia Texture Tools is said to offer the best (encoding) quality for lossy DDS types (namely, I use BC1/BC3). That's not something I've tested myself, I just have read a lot of articles over Internet and most articles say that it's visibly better than most "available" plugins. I know (tested) that XnView messes up with DDS color and GIMP export/import plugin had some issues (I don't remember which ones), Photoshop plugin is equivocally said to be of "bad quality". So, my guess is that it's not so simple to encode DDS with proper quality and therefore I'd recommend compressing it with a nvcompress (or test against native Pascal option - maybe Pascal option is of equal quality?). And yes, I've investigated only "compression" issue, so I don't have any idea is there any difference for decompression as it's straight-forward.
Lazarus 1.9 + FPC 3.1.1 Debian Jessie 64 bit.

My Free and Open Source games in Lazarus/FreePascal/CastleGameEngine:
https://decoherence.itch.io/
(and some ancient games in Turbo Pascal too)
Sources are here: https://github.com/eugeneloza?tab=repositories