WWPalette.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /*****************************************************************************/
  2. /* ここから */
  3. /*****************************************************************************/
  4. #include "WWPaletteP.h"
  5. /*****************************************************************************/
  6. /* メンバ関数の定義 */
  7. /*****************************************************************************/
  8. int WWPalette_GetNumber(WWPalette p) { return (p->number); }
  9. int WWPalette_SetNumber(WWPalette p, int n) { return (p->number = n); }
  10. int WWPalette_GetTransparent(WWPalette p) { return (p->transparent); }
  11. int WWPalette_SetTransparent(WWPalette p, int f)
  12. { return (p->transparent = f); }
  13. WWPalette WWPalette_Create(int number, int * mapped_colors, int transparent)
  14. {
  15. WWPalette palette;
  16. palette = (WWPalette)malloc(sizeof(_WWPalette));
  17. if (palette == NULL) Error("WWPalette_Create", "Cannot allocate memory");
  18. WWPalette_SetNumber(palette, number);
  19. WWPalette_SetTransparent(palette, transparent);
  20. WWPalette_SetMappedColors(palette, mapped_colors);
  21. return (palette);
  22. }
  23. WWPalette WWPalette_Destroy(WWPalette palette)
  24. {
  25. if (palette == NULL) return (NULL);
  26. free(palette);
  27. return (NULL);
  28. }
  29. int * WWPalette_GetMappedColors(WWPalette palette, int * mapped_colors)
  30. {
  31. int i;
  32. for (i = 0; i < 4; i++) {
  33. mapped_colors[i] = WWPalette_GetMappedColor(palette, i);
  34. }
  35. return (mapped_colors);
  36. }
  37. int WWPalette_SetMappedColors(WWPalette palette, int * mapped_colors)
  38. {
  39. int i;
  40. for (i = 0; i < 4; i++) {
  41. if (mapped_colors == NULL) {
  42. WWPalette_SetMappedColor(palette, i, (i * 2) + ((i == 3) ? 1 : 0));
  43. } else {
  44. WWPalette_SetMappedColor(palette, i, mapped_colors[i]);
  45. }
  46. }
  47. return (0);
  48. }
  49. int WWPalette_GetMappedColor(WWPalette palette, int color)
  50. {
  51. int pixel;
  52. pixel = palette->mapped_color[color];
  53. if (WWPalette_GetTransparent(palette) && (pixel == 0)) {
  54. pixel = -1;
  55. }
  56. return (pixel);
  57. }
  58. int WWPalette_SetMappedColor(WWPalette palette, int color, int mapped_color)
  59. {
  60. if (mapped_color == -1) mapped_color = 0;
  61. return (palette->mapped_color[color] = mapped_color);
  62. }
  63. int WWPalette_PrintData(WWPalette p, FILE * f)
  64. {
  65. int i, n;
  66. n = WWPalette_GetNumber(p);
  67. fprintf(f, "\n");
  68. fprintf(f, "palette[%d] :\tnumber = %d\n", n, WWPalette_GetNumber(p));
  69. fprintf(f, "palette[%d] :\ttransparent = %s\n",
  70. n, true_false(WWPalette_GetTransparent(p)));
  71. for (i = 0; i < 4; i++) {
  72. fprintf(f, "palette[%d] :\tcolor[%d] = %d\n",
  73. n, i, WWPalette_GetMappedColor(p, i));
  74. }
  75. fflush(f);
  76. return (0);
  77. }
  78. /*****************************************************************************/
  79. /* ここまで */
  80. /*****************************************************************************/
  81. /*****************************************************************************/
  82. /* End of File. */
  83. /*****************************************************************************/