void Z_DumpMemMap_f(void) { # define WRITECHAR(C) \ Sys_Log("memmap.txt", C, 1, false); \ cur += 1024; \ if ((++counter) % 81 == 0) Sys_Log("memmap.txt", "\n", 1, false); unsigned int cur = (unsigned int)s_PoolBase; unsigned int counter = 0; for (ZoneFreeBlock* fblock = &s_FreeStart; fblock != &s_FreeEnd; fblock = fblock->m_Next) { while (fblock->m_Address > cur + 1024) { WRITECHAR("*"); } if (fblock->m_Address > cur && fblock->m_Address < cur + 1024) { WRITECHAR("+"); } while (fblock->m_Address + fblock->m_Size > cur + 1024) { WRITECHAR("-"); } if (fblock->m_Address + fblock->m_Size > cur && fblock->m_Address + fblock->m_Size < cur + 1024) { WRITECHAR("+"); } } Sys_Log("memmap.txt", "\n"); }
ImageIO::errorType ImageIO::saveTGA(const char * filename) { // This routine writes the result as a uncompressed TGA file FILE *file = fopen(filename, "wb"); if (!file) { printf("Error in saveTGA: Cannot open file %s.\n", filename); return IO_ERROR; } // we write the header in little endian manner, // namely, information is stored with the low order byte followed by the high order byte. unsigned char buf; #define WRITECHAR(ch)\ buf = (ch);\ fwrite(&buf, sizeof(unsigned char), 1, file); WRITECHAR(0); // id length, length of a string located after the header, 0 = no string WRITECHAR(0); // color map type WRITECHAR(IMAGE_IO_UNCOMPRESSED_RGB); // data type code WRITECHAR(0); WRITECHAR(0); // short integer, color map origin (little endian) WRITECHAR(0); WRITECHAR(0); // short integer, color map length (little endian) WRITECHAR(0); // color map depth WRITECHAR(0); WRITECHAR(0); // short integer, x origin (little endian) WRITECHAR(0); WRITECHAR(0); // short integer, y origin (little endian) WRITECHAR(width % 256); WRITECHAR((width / 256) % 256); // image width (little endian) WRITECHAR(height % 256); WRITECHAR((height / 256) % 256); // image height (little endian) switch (bytesPerPixel) { case IMAGE_IO_RGB_ALPHA: WRITECHAR(32); // 32 bit bitmap break; case IMAGE_IO_RGB: WRITECHAR(24); // 24 bit map break; default: printf("Error in saveTGA: cannot handle the case where bytes per pixel is neither 3 nor 4.\n"); fclose(file); return IO_ERROR; break; } WRITECHAR(0); // image descriptor unsigned char * pixelBuf = (unsigned char*) malloc (sizeof(unsigned char) * width * height * bytesPerPixel); if (pixelBuf == NULL) { printf("Error in saveTGA: cannot allocate memory for pixel buffer.\n"); fclose(file); return IO_ERROR; } memcpy(pixelBuf, pixels, sizeof(unsigned char) * width * height * bytesPerPixel); // The order of the color is BGR(A) not RGB(A) for(unsigned int pixelIndex = 0; pixelIndex < width * height; pixelIndex++) { unsigned int offset = pixelIndex * bytesPerPixel; unsigned char temp; enum{R, G, B, A}; temp = pixelBuf[offset + R]; pixelBuf[offset + R] = pixelBuf[offset + B]; pixelBuf[offset + B] = temp; } fwrite(pixelBuf, sizeof(unsigned char), width * height * bytesPerPixel, file); free(pixelBuf); fclose(file); return OK; #undef WRITECHAR }