MCPcopy Create free account
hub / github.com/demoth/jake2 / LoadTGA

Method LoadTGA

client/src/main/java/jake2/client/render/fast/Image.java:528–695  ·  view source on GitHub ↗
(String name, Dimension dim)

Source from the content-addressed store, hash-verified

526 =============
527 */
528 byte[] LoadTGA(String name, Dimension dim) {
529 int columns, rows, numPixels;
530 int pixbuf; // index into pic
531 int row, column;
532 byte[] raw;
533 ByteBuffer buf_p;
534 qfiles.tga_t targa_header;
535 byte[] pic = null;
536
537 //
538 // load the file
539 //
540 raw = FS.LoadFile(name);
541
542 if (raw == null)
543 {
544 Com.Printf(Defines.PRINT_DEVELOPER, "Bad tga file "+ name +'\n');
545 return null;
546 }
547
548 targa_header = new qfiles.tga_t(raw);
549
550 if (targa_header.image_type != 2 && targa_header.image_type != 10)
551 Com.Error(Defines.ERR_DROP, "LoadTGA: Only type 2 and 10 targa RGB images supported\n");
552
553 if (targa_header.colormap_type != 0 || (targa_header.pixel_size != 32 && targa_header.pixel_size != 24))
554 Com.Error (Defines.ERR_DROP, "LoadTGA: Only 32 or 24 bit images supported (no colormaps)\n");
555
556 columns = targa_header.width;
557 rows = targa_header.height;
558 numPixels = columns * rows;
559
560 if (dim != null) {
561 dim.width = columns;
562 dim.height = rows;
563 }
564
565 pic = new byte[numPixels * 4]; // targa_rgba;
566
567 if (targa_header.id_length != 0)
568 targa_header.data.position(targa_header.id_length); // skip TARGA image comment
569
570 buf_p = targa_header.data;
571
572 byte red,green,blue,alphabyte;
573 red = green = blue = alphabyte = 0;
574 int packetHeader, packetSize, j;
575
576 if (targa_header.image_type==2) { // Uncompressed, RGB images
577 for(row=rows-1; row>=0; row--) {
578
579 pixbuf = row * columns * 4;
580
581 for(column=0; column<columns; column++) {
582 switch (targa_header.pixel_size) {
583 case 24:
584
585 blue = buf_p.get();

Callers 1

GL_FindImageMethod · 0.95

Calls 4

LoadFileMethod · 0.95
PrintfMethod · 0.95
ErrorMethod · 0.95
getMethod · 0.45

Tested by

no test coverage detected