Texture_import.cpp 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /* Import textur
  2. */
  3. #include "3d_all.h"
  4. static KFILE *file_load;
  5. /*
  6. Importni interface soubory pro textury DDS
  7. vraci pocet plan -> 3/4
  8. */
  9. int txt_dds_to_bmp(APAK_HANDLE * pHandle, char *p_file, void **p_return)
  10. {
  11. /*
  12. unsigned char *p_data;
  13. unsigned char *p_rd;
  14. AUX_RGBImageRec *p_rec;
  15. RBITMAP *p_bmp;
  16. byte *p_src,r;
  17. int width;
  18. int height;
  19. int planes;
  20. int lTotalWidth;
  21. int rowBytes;
  22. int x,y,dl;
  23. if((file_load = kopen(pHandle,p_file,"rb")) == NULL) {
  24. return(FALSE);
  25. }
  26. p_data = nvDXTdecompress(width, height, planes, lTotalWidth, rowBytes);
  27. assert(width == lTotalWidth);
  28. // prehodi r<->b
  29. for(y = 0; y < height; y ++ ) {
  30. for(x = 0; x < width; x++) {
  31. p_src = p_data+(y*width*planes)+x*planes;
  32. r = p_src[2];
  33. p_src[2] = p_src[0];
  34. p_src[0] = r;
  35. }
  36. }
  37. // prehodi radky
  38. dl = sizeof(byte)*width*planes;
  39. p_rd = (byte *)malloc(dl*height);
  40. for(y = 0; y < height; y++ ) {
  41. memcpy(p_rd+(height-y-1)*dl,p_data+y*dl,dl);
  42. }
  43. memcpy(p_data,p_rd,dl*height);
  44. if(planes == 3) {
  45. p_rec = (AUX_RGBImageRec *)malloc(sizeof(*p_rec));
  46. assert(p_rec);
  47. p_rec->sizeX = width;
  48. p_rec->sizeY = height;
  49. p_rec->data = p_data;
  50. *p_return = p_rec;
  51. } else {
  52. p_bmp = (RBITMAP *)malloc(sizeof(*p_bmp));
  53. assert(p_bmp);
  54. p_bmp->x = width;
  55. p_bmp->y = height;
  56. p_bmp->data = (DWORD *)p_data;
  57. *p_return = p_bmp;
  58. }
  59. free(p_rd);
  60. kclose(file_load);
  61. return(planes);
  62. */
  63. *p_return = NULL;
  64. return (0);
  65. }
  66. void WriteDTXnFile(DWORD count, void *buffer)
  67. {
  68. } void ReadDTXnFile(DWORD count, void *buffer)
  69. {
  70. kread(buffer, sizeof(byte), count, file_load);
  71. }