WWPalette.c 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. /*****************************************************************************/
  2. /* ここから */
  3. /*****************************************************************************/
  4. #include "WWPaletteP.h"
  5. #include "WonX.h"
  6. #include "etc.h"
  7. /*****************************************************************************/
  8. /* メンバ関数の定義 */
  9. /*****************************************************************************/
  10. int WWPalette_GetNumber(WWPalette p) { return (p->number); }
  11. int WWPalette_SetNumber(WWPalette p, int n) { return (p->number = n); }
  12. /*
  13. * WonX-2.0 以降から,透明色の判定は WWDisplay で行うように変更したので,
  14. * WWPalette で透明色を管理する必要は無くなった.一応コードを残しておく.
  15. */
  16. #if 0
  17. int WWPalette_GetTransparent(WWPalette p) { return (p->transparent); }
  18. int WWPalette_SetTransparent(WWPalette p, int f)
  19. { return (p->transparent = f); }
  20. #endif
  21. int WWPalette_GetRed( WWPalette p, int n) { return (p->red[ n]); }
  22. int WWPalette_GetGreen(WWPalette p, int n) { return (p->green[n]); }
  23. int WWPalette_GetBlue( WWPalette p, int n) { return (p->blue[ n]); }
  24. int WWPalette_SetRed( WWPalette p, int n, int value)
  25. { return (p->red[ n] = value); }
  26. int WWPalette_SetGreen(WWPalette p, int n, int value)
  27. { return (p->green[n] = value); }
  28. int WWPalette_SetBlue( WWPalette p, int n, int value)
  29. { return (p->blue[ n] = value); }
  30. /*
  31. * WonX-2.0 以降から,透明色の判定は WWDisplay で行うように変更したので,
  32. * WWPalette で透明色を管理する必要は無くなった.
  33. * もともとは,
  34. * WWPalette WWPalette_Create(int number, int * mapped_colors, int transparent)
  35. * のように,引数 transparent があった.
  36. */
  37. WWPalette WWPalette_Create(int number, int * mapped_colors)
  38. {
  39. WWPalette palette;
  40. int i;
  41. palette = (WWPalette)malloc(sizeof(_WWPalette));
  42. if (palette == NULL)
  43. WonX_Error("WWPalette_Create", "Cannot allocate memory");
  44. WWPalette_SetNumber(palette, number);
  45. /*
  46. * WonX-2.0 以降から,透明色の判定は WWDisplay で行うように変更したので,
  47. * WWPalette で透明色を管理する必要は無くなった.一応コードを残しておく.
  48. */
  49. #if 0
  50. WWPalette_SetTransparent(palette, transparent);
  51. #endif
  52. for (i = 0; i < 16; i++) {
  53. WWPalette_SetRed( palette, i, 0);
  54. WWPalette_SetGreen(palette, i, 0);
  55. WWPalette_SetBlue( palette, i, 0);
  56. }
  57. WWPalette_SetMappedColors(palette, mapped_colors);
  58. return (palette);
  59. }
  60. WWPalette WWPalette_Destroy(WWPalette palette)
  61. {
  62. if (palette == NULL) return (NULL);
  63. free(palette);
  64. return (NULL);
  65. }
  66. int * WWPalette_GetMappedColors(WWPalette palette, int * mapped_colors)
  67. {
  68. int i;
  69. for (i = 0; i < 4; i++) {
  70. mapped_colors[i] = WWPalette_GetMappedColor(palette, i);
  71. }
  72. return (mapped_colors);
  73. }
  74. int WWPalette_SetMappedColors(WWPalette palette, int * mapped_colors)
  75. {
  76. int i;
  77. for (i = 0; i < 4; i++) {
  78. if (mapped_colors == NULL) {
  79. WWPalette_SetMappedColor(palette, i, (i * 2) + ((i == 3) ? 1 : 0));
  80. } else {
  81. WWPalette_SetMappedColor(palette, i, mapped_colors[i]);
  82. }
  83. }
  84. return (0);
  85. }
  86. int WWPalette_GetMappedColor(WWPalette palette, int color)
  87. {
  88. int pixel;
  89. pixel = palette->mapped_color[color];
  90. /*
  91. * WonX-2.0 以降から,透明色の判定は WWDisplay で行うように変更したので,
  92. * WWPalette で透明色を管理する必要は無くなった.一応コードを残しておく.
  93. */
  94. #if 0
  95. if (WWPalette_GetTransparent(palette) && (pixel == 0)) {
  96. pixel = -1;
  97. }
  98. #endif
  99. return (pixel);
  100. }
  101. int WWPalette_SetMappedColor(WWPalette palette, int color, int mapped_color)
  102. {
  103. /*
  104. * WonX-2.0 以降から,透明色の判定は WWDisplay で行うように変更したので,
  105. * WWPalette で透明色を管理する必要は無くなった.一応コードを残しておく.
  106. */
  107. #if 0
  108. if (mapped_color == -1) mapped_color = 0;
  109. #endif
  110. return (palette->mapped_color[color] = mapped_color);
  111. }
  112. int WWPalette_PrintData(WWPalette p, WWDisplay display, FILE * f)
  113. {
  114. int i, n;
  115. int transparent;
  116. int red, green, blue;
  117. n = WWPalette_GetNumber(p);
  118. fprintf(f, "\n");
  119. fprintf(f, "palette[%02d] :\tnumber = %d\n", n, WWPalette_GetNumber(p));
  120. /*
  121. * WonX-2.0 以降から,透明色の判定は WWDisplay で行うように変更したので,
  122. * WWPalette で透明色を管理する必要は無くなった.一応コードを残しておく.
  123. */
  124. #if 1
  125. transparent = WWDisplay_IsTransparent(display, p, 0);
  126. fprintf(f, "palette[%02d] :\ttransparent = %s\n",
  127. n, wonx_true_false(transparent));
  128. #else
  129. fprintf(f, "palette[%02d] :\ttransparent = %s\n",
  130. n, wonx_true_false(WWPalette_GetTransparent(p)));
  131. #endif
  132. for (i = 0; i < 4; i++) {
  133. fprintf(f, "palette[%02d] :\tcolor[%01d] = %d\n",
  134. n, i, WWPalette_GetMappedColor(p, i));
  135. }
  136. for (i = 0; i < 16; i++) {
  137. red = WWPalette_GetRed( p, i);
  138. green = WWPalette_GetGreen(p, i);
  139. blue = WWPalette_GetBlue( p, i);
  140. fprintf(f, "palette[%02d] :\tRGB[%02d] = 0x%c%c%c\n",
  141. n, i,
  142. wonx_dec_to_hex(red),
  143. wonx_dec_to_hex(green),
  144. wonx_dec_to_hex(blue));
  145. }
  146. fflush(f);
  147. return (0);
  148. }
  149. /*****************************************************************************/
  150. /* ここまで */
  151. /*****************************************************************************/
  152. /*****************************************************************************/
  153. /* End of File. */
  154. /*****************************************************************************/