MCPcopy Create free account
hub / github.com/ZDoom/Raze / CopyPixels

Method CopyPixels

source/common/textures/formats/pcxtexture.cpp:436–500  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

434//===========================================================================
435
436int FPCXTexture::CopyPixels(FBitmap *bmp, int conversion, int frame)
437{
438 PalEntry pe[256];
439 PCXHeader header;
440 int bitcount;
441 TArray<uint8_t> Pixels;
442
443 auto lump = fileSystem.OpenFileReader(SourceLump);
444
445 lump.Read(&header, sizeof(header));
446
447 bitcount = header.bitsPerPixel * header.numColorPlanes;
448
449 if (bitcount < 24)
450 {
451 Pixels.Resize(Width*Height);
452 if (bitcount < 8)
453 {
454 switch (bitcount)
455 {
456 default:
457 case 1:
458 pe[0] = PalEntry(255, 0, 0, 0);
459 pe[1] = PalEntry(255, 255, 255, 255);
460 ReadPCX1bit (Pixels.Data(), lump, &header);
461 break;
462
463 case 4:
464 for (int i = 0; i<16; i++)
465 {
466 pe[i] = PalEntry(255, header.palette[i * 3], header.palette[i * 3 + 1], header.palette[i * 3 + 2]);
467 }
468 ReadPCX4bits (Pixels.Data(), lump, &header);
469 break;
470 }
471 }
472 else if (bitcount == 8)
473 {
474 lump.Seek(-769, FileReader::SeekEnd);
475 uint8_t c = lump.ReadUInt8();
476 c=0x0c; // Apparently there's many non-compliant PCXs out there...
477 if (c !=0x0c)
478 {
479 for(int i=0;i<256;i++) pe[i]=PalEntry(255,i,i,i); // default to a gray map
480 }
481 else for(int i=0;i<256;i++)
482 {
483 uint8_t r = lump.ReadUInt8();
484 uint8_t g = lump.ReadUInt8();
485 uint8_t b = lump.ReadUInt8();
486 pe[i] = PalEntry(255, r,g,b);
487 }
488 lump.Seek(sizeof(header), FileReader::SeekSet);
489 ReadPCX8bits (Pixels.Data(), lump, &header);
490 }
491 bmp->CopyPixelData(0, 0, Pixels.Data(), Width, Height, 1, Width, 0, pe);
492 }
493 else

Callers

nothing calls this directly

Calls 9

CopyPixelDataMethod · 0.80
CopyPixelDataRGBMethod · 0.80
PalEntryClass · 0.50
OpenFileReaderMethod · 0.45
ReadMethod · 0.45
ResizeMethod · 0.45
DataMethod · 0.45
SeekMethod · 0.45
ReadUInt8Method · 0.45

Tested by

no test coverage detected