WWPalette.c 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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)
  63. WonX_Error("WWPalette_Destroy", "Object is not created.");
  64. free(palette);
  65. return (NULL);
  66. }
  67. int * WWPalette_GetMappedColors(WWPalette palette, int * mapped_colors)
  68. {
  69. int i;
  70. for (i = 0; i < 4; i++) {
  71. mapped_colors[i] = WWPalette_GetMappedColor(palette, i);
  72. }
  73. return (mapped_colors);
  74. }
  75. int WWPalette_SetMappedColors(WWPalette palette, int * mapped_colors)
  76. {
  77. int i;
  78. for (i = 0; i < 4; i++) {
  79. if (mapped_colors == NULL) {
  80. WWPalette_SetMappedColor(palette, i, (i * 2) + ((i == 3) ? 1 : 0));
  81. } else {
  82. WWPalette_SetMappedColor(palette, i, mapped_colors[i]);
  83. }
  84. }
  85. return (0);
  86. }
  87. int WWPalette_GetMappedColor(WWPalette palette, int color)
  88. {
  89. int pixel;
  90. pixel = palette->mapped_color[color];
  91. /*
  92. * WonX-2.0 以降から,透明色の判定は WWDisplay で行うように変更したので,
  93. * WWPalette で透明色を管理する必要は無くなった.一応コードを残しておく.
  94. */
  95. #if 0
  96. if (WWPalette_GetTransparent(palette) && (pixel == 0)) {
  97. pixel = -1;
  98. }
  99. #endif
  100. return (pixel);
  101. }
  102. int WWPalette_SetMappedColor(WWPalette palette, int color, int mapped_color)
  103. {
  104. /*
  105. * WonX-2.0 以降から,透明色の判定は WWDisplay で行うように変更したので,
  106. * WWPalette で透明色を管理する必要は無くなった.一応コードを残しておく.
  107. */
  108. #if 0
  109. if (mapped_color == -1) mapped_color = 0;
  110. #endif
  111. return (palette->mapped_color[color] = mapped_color);
  112. }
  113. int WWPalette_PrintData(WWPalette p, WWDisplay display, FILE * f)
  114. {
  115. int i, n;
  116. int transparent;
  117. int red, green, blue;
  118. n = WWPalette_GetNumber(p);
  119. fprintf(f, "\n");
  120. fprintf(f, "palette[%02d] :\tnumber = %d\n", n, WWPalette_GetNumber(p));
  121. /*
  122. * WonX-2.0 以降から,透明色の判定は WWDisplay で行うように変更したので,
  123. * WWPalette で透明色を管理する必要は無くなった.一応コードを残しておく.
  124. */
  125. #if 1
  126. transparent = WWDisplay_IsTransparent(display, p, 0);
  127. fprintf(f, "palette[%02d] :\ttransparent = %s\n",
  128. n, wonx_true_false(transparent));
  129. #else
  130. fprintf(f, "palette[%02d] :\ttransparent = %s\n",
  131. n, wonx_true_false(WWPalette_GetTransparent(p)));
  132. #endif
  133. for (i = 0; i < 4; i++) {
  134. fprintf(f, "palette[%02d] :\tcolor[%01d] = %d\n",
  135. n, i, WWPalette_GetMappedColor(p, i));
  136. }
  137. for (i = 0; i < 16; i++) {
  138. red = WWPalette_GetRed( p, i);
  139. green = WWPalette_GetGreen(p, i);
  140. blue = WWPalette_GetBlue( p, i);
  141. fprintf(f, "palette[%02d] :\tRGB[%02d] = 0x%c%c%c\n",
  142. n, i,
  143. wonx_dec_to_hex(red),
  144. wonx_dec_to_hex(green),
  145. wonx_dec_to_hex(blue));
  146. }
  147. fflush(f);
  148. return (0);
  149. }
  150. /*****************************************************************************/
  151. /* ここまで */
  152. /*****************************************************************************/
  153. /*****************************************************************************/
  154. /* End of File. */
  155. /*****************************************************************************/