Use ScratchImage as a workspace object, as it uses memory in exactly the layout that is required by .DDS files.
ScratchImage
Header: Declared in directxtex.h.