~ubuntu-branches/ubuntu/maverick/blender/maverick

« back to all changes in this revision

Viewing changes to source/blender/imbuf/intern/dds/DirectDrawSurface.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Khashayar Naderehvandi, Khashayar Naderehvandi, Alessio Treglia
  • Date: 2009-01-22 16:53:59 UTC
  • mfrom: (14.1.1 experimental)
  • Revision ID: james.westby@ubuntu.com-20090122165359-v0996tn7fbit64ni
Tags: 2.48a+dfsg-1ubuntu1
[ Khashayar Naderehvandi ]
* Merge from debian experimental (LP: #320045), Ubuntu remaining changes:
  - Add patch correcting header file locations.
  - Add libvorbis-dev and libgsm1-dev to Build-Depends.
  - Use avcodec_decode_audio2() in source/blender/src/hddaudio.c

[ Alessio Treglia ]
* Add missing previous changelog entries.

Show diffs side-by-side

added added

removed removed

Lines of Context:
80
80
static const uint FOURCC_ATI1 = MAKEFOURCC('A', 'T', 'I', '1');
81
81
static const uint FOURCC_ATI2 = MAKEFOURCC('A', 'T', 'I', '2');
82
82
 
 
83
static const uint FOURCC_A2XY = MAKEFOURCC('A', '2', 'X', 'Y');
 
84
        
 
85
static const uint FOURCC_DX10 = MAKEFOURCC('D', 'X', '1', '0');
 
86
 
83
87
// 32 bit RGB formats.
84
88
static const uint D3DFMT_R8G8B8 = 20;
85
89
static const uint D3DFMT_A8R8G8B8 = 21;
279
283
                D3D10_RESOURCE_DIMENSION_TEXTURE3D = 4,
280
284
        };
281
285
 
 
286
 
 
287
        const char * getDxgiFormatString(DXGI_FORMAT dxgiFormat)
 
288
        {
 
289
#define CASE(format) case DXGI_FORMAT_##format: return #format
 
290
                switch(dxgiFormat)
 
291
                {
 
292
                        CASE(UNKNOWN);
 
293
                        
 
294
                        CASE(R32G32B32A32_TYPELESS);
 
295
                        CASE(R32G32B32A32_FLOAT);
 
296
                        CASE(R32G32B32A32_UINT);
 
297
                        CASE(R32G32B32A32_SINT);
 
298
                        
 
299
                        CASE(R32G32B32_TYPELESS);
 
300
                        CASE(R32G32B32_FLOAT);
 
301
                        CASE(R32G32B32_UINT);
 
302
                        CASE(R32G32B32_SINT);
 
303
                        
 
304
                        CASE(R16G16B16A16_TYPELESS);
 
305
                        CASE(R16G16B16A16_FLOAT);
 
306
                        CASE(R16G16B16A16_UNORM);
 
307
                        CASE(R16G16B16A16_UINT);
 
308
                        CASE(R16G16B16A16_SNORM);
 
309
                        CASE(R16G16B16A16_SINT);
 
310
                        
 
311
                        CASE(R32G32_TYPELESS);
 
312
                        CASE(R32G32_FLOAT);
 
313
                        CASE(R32G32_UINT);
 
314
                        CASE(R32G32_SINT);
 
315
                        
 
316
                        CASE(R32G8X24_TYPELESS);
 
317
                        CASE(D32_FLOAT_S8X24_UINT);
 
318
                        CASE(R32_FLOAT_X8X24_TYPELESS);
 
319
                        CASE(X32_TYPELESS_G8X24_UINT);
 
320
                        
 
321
                        CASE(R10G10B10A2_TYPELESS);
 
322
                        CASE(R10G10B10A2_UNORM);
 
323
                        CASE(R10G10B10A2_UINT);
 
324
                        
 
325
                        CASE(R11G11B10_FLOAT);
 
326
                        
 
327
                        CASE(R8G8B8A8_TYPELESS);
 
328
                        CASE(R8G8B8A8_UNORM);
 
329
                        CASE(R8G8B8A8_UNORM_SRGB);
 
330
                        CASE(R8G8B8A8_UINT);
 
331
                        CASE(R8G8B8A8_SNORM);
 
332
                        CASE(R8G8B8A8_SINT);
 
333
                        
 
334
                        CASE(R16G16_TYPELESS);
 
335
                        CASE(R16G16_FLOAT);
 
336
                        CASE(R16G16_UNORM);
 
337
                        CASE(R16G16_UINT);
 
338
                        CASE(R16G16_SNORM);
 
339
                        CASE(R16G16_SINT);
 
340
                        
 
341
                        CASE(R32_TYPELESS);
 
342
                        CASE(D32_FLOAT);
 
343
                        CASE(R32_FLOAT);
 
344
                        CASE(R32_UINT);
 
345
                        CASE(R32_SINT);
 
346
                        
 
347
                        CASE(R24G8_TYPELESS);
 
348
                        CASE(D24_UNORM_S8_UINT);
 
349
                        CASE(R24_UNORM_X8_TYPELESS);
 
350
                        CASE(X24_TYPELESS_G8_UINT);
 
351
                        
 
352
                        CASE(R8G8_TYPELESS);
 
353
                        CASE(R8G8_UNORM);
 
354
                        CASE(R8G8_UINT);
 
355
                        CASE(R8G8_SNORM);
 
356
                        CASE(R8G8_SINT);
 
357
                        
 
358
                        CASE(R16_TYPELESS);
 
359
                        CASE(R16_FLOAT);
 
360
                        CASE(D16_UNORM);
 
361
                        CASE(R16_UNORM);
 
362
                        CASE(R16_UINT);
 
363
                        CASE(R16_SNORM);
 
364
                        CASE(R16_SINT);
 
365
                        
 
366
                        CASE(R8_TYPELESS);
 
367
                        CASE(R8_UNORM);
 
368
                        CASE(R8_UINT);
 
369
                        CASE(R8_SNORM);
 
370
                        CASE(R8_SINT);
 
371
                        CASE(A8_UNORM);
 
372
 
 
373
                        CASE(R1_UNORM);
 
374
                
 
375
                        CASE(R9G9B9E5_SHAREDEXP);
 
376
                        
 
377
                        CASE(R8G8_B8G8_UNORM);
 
378
                        CASE(G8R8_G8B8_UNORM);
 
379
 
 
380
                        CASE(BC1_TYPELESS);
 
381
                        CASE(BC1_UNORM);
 
382
                        CASE(BC1_UNORM_SRGB);
 
383
                
 
384
                        CASE(BC2_TYPELESS);
 
385
                        CASE(BC2_UNORM);
 
386
                        CASE(BC2_UNORM_SRGB);
 
387
                
 
388
                        CASE(BC3_TYPELESS);
 
389
                        CASE(BC3_UNORM);
 
390
                        CASE(BC3_UNORM_SRGB);
 
391
                
 
392
                        CASE(BC4_TYPELESS);
 
393
                        CASE(BC4_UNORM);
 
394
                        CASE(BC4_SNORM);
 
395
                
 
396
                        CASE(BC5_TYPELESS);
 
397
                        CASE(BC5_UNORM);
 
398
                        CASE(BC5_SNORM);
 
399
 
 
400
                        CASE(B5G6R5_UNORM);
 
401
                        CASE(B5G5R5A1_UNORM);
 
402
                        CASE(B8G8R8A8_UNORM);
 
403
                        CASE(B8G8R8X8_UNORM);
 
404
 
 
405
                        default: 
 
406
                                return "UNKNOWN";
 
407
                }
 
408
#undef CASE
 
409
        }
 
410
        
 
411
        const char * getD3d10ResourceDimensionString(D3D10_RESOURCE_DIMENSION resourceDimension)
 
412
        {
 
413
                switch(resourceDimension)
 
414
                {
 
415
                        default:
 
416
                        case D3D10_RESOURCE_DIMENSION_UNKNOWN: return "UNKNOWN";
 
417
                        case D3D10_RESOURCE_DIMENSION_BUFFER: return "BUFFER";
 
418
                        case D3D10_RESOURCE_DIMENSION_TEXTURE1D: return "TEXTURE1D";
 
419
                        case D3D10_RESOURCE_DIMENSION_TEXTURE2D: return "TEXTURE2D";
 
420
                        case D3D10_RESOURCE_DIMENSION_TEXTURE3D: return "TEXTURE3D";
 
421
                }
 
422
        }
 
423
 
282
424
/*** implementation ***/
283
425
 
284
426
void mem_read(Stream & mem, DDSPixelFormat & pf)
451
593
        // set fourcc pixel format.
452
594
        this->pf.flags = DDPF_FOURCC;
453
595
        this->pf.fourcc = MAKEFOURCC(c0, c1, c2, c3);
454
 
        this->pf.bitcount = 0;
 
596
 
 
597
        if (this->pf.fourcc == FOURCC_ATI2)
 
598
        {
 
599
                this->pf.bitcount = FOURCC_A2XY;
 
600
        }
 
601
        else
 
602
        {
 
603
                this->pf.bitcount = 0;
 
604
        }
 
605
        
455
606
        this->pf.rmask = 0;
456
607
        this->pf.gmask = 0;
457
608
        this->pf.bmask = 0;
508
659
 
509
660
void DDSHeader::setDX10Format(uint format)
510
661
{
511
 
        this->pf.flags = 0;
 
662
        //this->pf.flags = 0;
 
663
        this->pf.fourcc = FOURCC_DX10;
512
664
        this->header10.dxgiFormat = format;
513
665
}
514
666
 
520
672
 
521
673
bool DDSHeader::hasDX10Header() const
522
674
{
523
 
        return this->pf.flags == 0;
 
675
        return this->pf.fourcc == FOURCC_DX10;  // @@ This is according to AMD
 
676
        //return this->pf.flags == 0;             // @@ This is according to MS
524
677
}
525
678
 
526
679
DirectDrawSurface::DirectDrawSurface(unsigned char *mem, uint size) : stream(mem, size), header()
527
680
{
528
681
        mem_read(stream, header);
 
682
 
 
683
        // some ATI2 compressed normal maps do not have their
 
684
        // normal flag set, so force it here (the original nvtt don't do
 
685
        // this, but the decompressor has a -forcenormal flag)
 
686
        if (header.pf.fourcc == FOURCC_ATI2) header.setNormalFlag(true);
529
687
}
530
688
 
531
689
DirectDrawSurface::~DirectDrawSurface()
539
697
                return false;
540
698
        }
541
699
        
542
 
        const uint required = (DDSD_WIDTH|DDSD_HEIGHT|DDSD_CAPS|DDSD_PIXELFORMAT);
 
700
        const uint required = (DDSD_WIDTH|DDSD_HEIGHT/*|DDSD_CAPS|DDSD_PIXELFORMAT*/);
543
701
        if( (header.flags & required) != required ) {
544
702
                return false;
545
703
        }
560
718
 
561
719
bool DirectDrawSurface::isSupported() const
562
720
{
563
 
        if (header.pf.flags & DDPF_FOURCC)
564
 
        {
565
 
                if (header.pf.fourcc != FOURCC_DXT1 &&
566
 
                    header.pf.fourcc != FOURCC_DXT2 &&
567
 
                    header.pf.fourcc != FOURCC_DXT3 &&
568
 
                    header.pf.fourcc != FOURCC_DXT4 &&
569
 
                    header.pf.fourcc != FOURCC_DXT5 &&
570
 
                    header.pf.fourcc != FOURCC_RXGB &&
571
 
                    header.pf.fourcc != FOURCC_ATI1 &&
572
 
                    header.pf.fourcc != FOURCC_ATI2)
573
 
                {
574
 
                        // Unknown fourcc code.
575
 
                        return false;
576
 
                }
577
 
        }
578
 
        else if (header.pf.flags & DDPF_RGB)
579
 
        {
580
 
                // All RGB formats are supported now.
 
721
        if (header.hasDX10Header())
 
722
        {
581
723
        }
582
724
        else
583
725
        {
584
 
                return false;
585
 
        }
586
 
        
587
 
        if (isTextureCube() && (header.caps.caps2 & DDSCAPS2_CUBEMAP_ALL_FACES) != DDSCAPS2_CUBEMAP_ALL_FACES)
588
 
        {
589
 
                // Cubemaps must contain all faces.
590
 
                return false;
591
 
        }
592
 
        
593
 
        if (isTexture3D())
594
 
        {
595
 
                // @@ 3D textures not supported yet.
596
 
                return false;
 
726
                if (header.pf.flags & DDPF_FOURCC)
 
727
                {
 
728
                        if (header.pf.fourcc != FOURCC_DXT1 &&
 
729
                            header.pf.fourcc != FOURCC_DXT2 &&
 
730
                            header.pf.fourcc != FOURCC_DXT3 &&
 
731
                            header.pf.fourcc != FOURCC_DXT4 &&
 
732
                            header.pf.fourcc != FOURCC_DXT5 &&
 
733
                            header.pf.fourcc != FOURCC_RXGB &&
 
734
                            header.pf.fourcc != FOURCC_ATI1 &&
 
735
                            header.pf.fourcc != FOURCC_ATI2)
 
736
                        {
 
737
                                // Unknown fourcc code.
 
738
                                return false;
 
739
                        }
 
740
                }
 
741
                else if (header.pf.flags & DDPF_RGB)
 
742
                {
 
743
                        // All RGB formats are supported now.
 
744
                }
 
745
                else
 
746
                {
 
747
                        return false;
 
748
                }
 
749
                
 
750
                if (isTextureCube() && (header.caps.caps2 & DDSCAPS2_CUBEMAP_ALL_FACES) != DDSCAPS2_CUBEMAP_ALL_FACES)
 
751
                {
 
752
                        // Cubemaps must contain all faces.
 
753
                        return false;
 
754
                }
 
755
        
 
756
                if (isTexture3D())
 
757
                {
 
758
                        // @@ 3D textures not supported yet.
 
759
                        return false;
 
760
                }
597
761
        }
598
762
        
599
763
        return true;
641
805
        }
642
806
}
643
807
 
 
808
bool DirectDrawSurface::isTexture1D() const
 
809
{
 
810
        if (header.hasDX10Header())
 
811
        {
 
812
                return header.header10.resourceDimension == D3D10_RESOURCE_DIMENSION_TEXTURE1D;
 
813
        }
 
814
        return false;
 
815
}
 
816
 
644
817
bool DirectDrawSurface::isTexture2D() const
645
818
{
646
 
        return !isTexture3D() && !isTextureCube();
 
819
        if (header.hasDX10Header())
 
820
        {
 
821
                return header.header10.resourceDimension == D3D10_RESOURCE_DIMENSION_TEXTURE2D;
 
822
        }
 
823
        else
 
824
        {
 
825
                return !isTexture3D() && !isTextureCube();
 
826
        }
647
827
}
648
828
 
649
829
bool DirectDrawSurface::isTexture3D() const
650
830
{
 
831
        if (header.hasDX10Header())
 
832
        {
 
833
                return header.header10.resourceDimension == D3D10_RESOURCE_DIMENSION_TEXTURE3D;
 
834
        }
 
835
        else
 
836
        {
651
837
        return (header.caps.caps2 & DDSCAPS2_VOLUME) != 0;
 
838
        }
652
839
}
653
840
 
654
841
bool DirectDrawSurface::isTextureCube() const
656
843
        return (header.caps.caps2 & DDSCAPS2_CUBEMAP) != 0;
657
844
}
658
845
 
 
846
void DirectDrawSurface::setNormalFlag(bool b)
 
847
{
 
848
        header.setNormalFlag(b);
 
849
}
 
850
 
659
851
void DirectDrawSurface::mipmap(Image * img, uint face, uint mipmap)
660
852
{
661
853
        stream.seek(offset(face, mipmap));
709
901
                return;
710
902
        }
711
903
 
712
 
        if (header.pf.amask != 0)
 
904
        // set image format: RGB or ARGB
 
905
        // alpha channel exists if and only if the alpha mask is non-zero
 
906
        if (header.pf.amask == 0)
 
907
        {
 
908
                img->setFormat(Image::Format_RGB);
 
909
        }
 
910
        else
713
911
        {
714
912
                img->setFormat(Image::Format_ARGB);
715
913
        }
735
933
 
736
934
void DirectDrawSurface::readBlockImage(Image * img)
737
935
{
 
936
 
 
937
        // set image format: RGB or ARGB
 
938
        if (header.pf.fourcc == FOURCC_RXGB ||
 
939
                header.pf.fourcc == FOURCC_ATI1 ||
 
940
                header.pf.fourcc == FOURCC_ATI2 ||
 
941
                header.pf.flags & DDPF_NORMAL)
 
942
        {
 
943
                img->setFormat(Image::Format_RGB);
 
944
        }
 
945
        else
 
946
        {
 
947
                img->setFormat(Image::Format_ARGB);
 
948
        }
 
949
 
738
950
        const uint w = img->width();
739
951
        const uint h = img->height();
740
952
        
971
1183
        if (header.pf.flags & DDPF_ALPHAPREMULT) printf("\t\tDDPF_ALPHAPREMULT\n");
972
1184
        if (header.pf.flags & DDPF_NORMAL) printf("\t\tDDPF_NORMAL\n");
973
1185
        
974
 
        printf("\tFourCC: '%c%c%c%c'\n", ((header.pf.fourcc >> 0) & 0xFF), ((header.pf.fourcc >> 8) & 0xFF), ((header.pf.fourcc >> 16) & 0xFF), ((header.pf.fourcc >> 24) & 0xFF));
975
 
        printf("\tBit count: %d\n", header.pf.bitcount);
 
1186
        printf("\tFourCC: '%c%c%c%c'\n",
 
1187
                ((header.pf.fourcc >> 0) & 0xFF),
 
1188
                ((header.pf.fourcc >> 8) & 0xFF),
 
1189
                ((header.pf.fourcc >> 16) & 0xFF),
 
1190
                ((header.pf.fourcc >> 24) & 0xFF));
 
1191
        if ((header.pf.fourcc & DDPF_FOURCC) && (header.pf.bitcount != 0))
 
1192
        {
 
1193
                printf("\tSwizzle: '%c%c%c%c'\n", 
 
1194
                        (header.pf.bitcount >> 0) & 0xFF,
 
1195
                        (header.pf.bitcount >> 8) & 0xFF,
 
1196
                        (header.pf.bitcount >> 16) & 0xFF,
 
1197
                        (header.pf.bitcount >> 24) & 0xFF);
 
1198
        }
 
1199
        else
 
1200
        {
 
1201
                printf("\tBit count: %d\n", header.pf.bitcount);
 
1202
        }
976
1203
        printf("\tRed mask: 0x%.8X\n", header.pf.rmask);
977
1204
        printf("\tGreen mask: 0x%.8X\n", header.pf.gmask);
978
1205
        printf("\tBlue mask: 0x%.8X\n", header.pf.bmask);
1003
1230
        printf("\tCaps 3: 0x%.8X\n", header.caps.caps3);
1004
1231
        printf("\tCaps 4: 0x%.8X\n", header.caps.caps4);
1005
1232
 
1006
 
        if (header.pf.flags == 0)
 
1233
        if (header.hasDX10Header())
1007
1234
        {
1008
1235
                printf("DX10 Header:\n");
1009
 
                printf("\tDXGI Format: %u\n", header.header10.dxgiFormat);
1010
 
                printf("\tResource dimension: %u\n", header.header10.resourceDimension);
 
1236
                printf("\tDXGI Format: %u (%s)\n", header.header10.dxgiFormat, getDxgiFormatString((DXGI_FORMAT)header.header10.dxgiFormat));
 
1237
                printf("\tResource dimension: %u (%s)\n", header.header10.resourceDimension, getD3d10ResourceDimensionString((D3D10_RESOURCE_DIMENSION)header.header10.resourceDimension));
1011
1238
                printf("\tMisc flag: %u\n", header.header10.miscFlag);
1012
1239
                printf("\tArray size: %u\n", header.header10.arraySize);
1013
1240
        }