+
+
+#ifdef NBVTF_AS_SO
+__attribute__((visibility("default")))
+#endif
+int nbvtf_write_dds_dxt1( uint8_t *reference, int w, int h, int qual, const char *dest )
+{
+ if( !nbvtf_power2x(w,h) )
+ {
+ NBVTF_ERR( "nbvtf_write:err image dimentions were not power of two (%d %d)\n", w, h );
+ return 0;
+ }
+
+ struct DDS_HEADER header = {0};
+ header.dwSize = DDS_HEADER_SIZE;
+ header.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_PIXELFORMAT;
+ header.dwHeight = h;
+ header.dwWidth = w;
+ header.dwPitchOrLinearSize = nbvtf__max(1, ((w + 3) / 4)) * BLOCK_SIZE_DXT1;
+ header.ddspf.dwSize = DDS_HEADER_PFSIZE;
+ header.ddspf.dwFlags |= DDPF_FOURCC;
+ header.ddspf.dwFourCC = ((uint32_t)'D'<<0) |
+ ((uint32_t)'X'<<8) |
+ ((uint32_t)'T'<<16) |
+ ((uint32_t)'1'<<24);
+
+ header.dwFlags |= DDSD_LINEARSIZE;
+ header.dwMipMapCount = 0;
+ header.dwCaps = DDSCAPS_TEXTURE;
+
+ // Magic number
+ uint32_t magic = DDS_MAGICNUM;
+
+ FILE *file = fopen( dest, "wb" );
+ fwrite( &magic, sizeof(uint32_t), 1, file );
+ fwrite( &header, DDS_HEADER_SIZE, 1, file );
+
+ uint32_t size_highres = nbvtf_sizeimg( w, h, k_EImageFormat_DXT1 );
+ uint8_t *working_buffer = malloc( size_highres );
+
+ nbvtf_compress_dxt( reference, w, h, 0, qual, working_buffer );
+ fwrite( working_buffer, size_highres, 1, file );
+
+ free( working_buffer );
+ fclose( file );
+ return 1;
+}
+