Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

97 lines
1.9 KiB

  1. //
  2. // mxToolKit (c) 1999 by Mete Ciragan
  3. //
  4. // file: mxPcx.cpp
  5. // implementation: all
  6. // last modified: Apr 15 1999, Mete Ciragan
  7. // copyright: The programs and associated files contained in this
  8. // distribution were developed by Mete Ciragan. The programs
  9. // are not in the public domain, but they are freely
  10. // distributable without licensing fees. These programs are
  11. // provided without guarantee or warrantee expressed or
  12. // implied.
  13. //
  14. #include "mxtk/mxPcx.h"
  15. #include <stdio.h>
  16. #include <stdlib.h>
  17. mxImage *
  18. mxPcxRead (const char *filename)
  19. {
  20. FILE *file = fopen (filename, "rb");
  21. if (!file)
  22. return 0;
  23. mxPcxHeader header;
  24. if (fread (&header, sizeof (mxPcxHeader), 1, file) == -1)
  25. {
  26. fclose (file);
  27. return 0;
  28. }
  29. /*
  30. if (header.bitsPerPixel != 8 ||
  31. header.version != 5)
  32. {
  33. fclose (file);
  34. return 0;
  35. }
  36. (void) fseek (file, -769, SEEK_END);
  37. if (fgetc (file) != 12) {
  38. fclose (file);
  39. return NULL;
  40. }
  41. */
  42. (void) fseek (file, -768, SEEK_END);
  43. int w = header.xmax - header.xmin + 1;
  44. int h = header.ymax - header.ymin + 1;
  45. mxImage *image = new mxImage ();
  46. if (!image->create (w, h, 8))
  47. {
  48. delete image;
  49. fclose (file);
  50. return 0;
  51. }
  52. if (fread ((byte *) image->palette, sizeof (byte), 768, file) == -1)
  53. {
  54. fclose (file);
  55. return 0;
  56. }
  57. (void) fseek(file, sizeof (mxPcxHeader), SEEK_SET);
  58. int ptr = 0;
  59. int ch, rep;
  60. byte *data = (byte *) image->data;
  61. int size = w * h;
  62. while (ptr < size)
  63. {
  64. ch = fgetc(file);
  65. if (ch >= 192)
  66. {
  67. rep = ch - 192;
  68. ch = fgetc(file);
  69. }
  70. else {
  71. rep = 1;
  72. }
  73. while (rep--)
  74. data[ptr++] = (byte)ch;
  75. }
  76. fclose(file);
  77. return image;
  78. }
  79. bool
  80. mxPcxWrite (const char * /*filename*/, mxImage * /*image*/)
  81. {
  82. return false;
  83. }