Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

fcolor.c 2.6 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. #include <stdio.h>
  2. #include <math.h>
  3. typedef struct {
  4. float h,s,v;
  5. } hsvpix_t;
  6. static void HSVtoRGB( float *r, float *g, float *b, hsvpix_t pix )
  7. {
  8. int i;
  9. double f, p, q, t, h;
  10. if( pix.s == 0 ) {
  11. // achromatic (grey)
  12. *r = *g = *b = pix.v;
  13. return;
  14. }
  15. h = pix.h/60; // sector 0 to 5
  16. i = floor( h );
  17. f = h - i; // factorial part of h
  18. p = pix.v * ( 1 - pix.s );
  19. q = pix.v * ( 1 - pix.s * f );
  20. t = pix.v * ( 1 - pix.s * ( 1 - f ) );
  21. switch( i ) {
  22. case 0:
  23. *r = pix.v; *g = t; *b = p;
  24. break;
  25. case 1:
  26. *r = q; *g = pix.v; *b = p;
  27. break;
  28. case 2:
  29. *r = p; *g = pix.v; *b = t;
  30. break;
  31. case 3:
  32. *r = p; *g = q; *b = pix.v;
  33. break;
  34. case 4:
  35. *r = t; *g = p; *b = pix.v;
  36. break;
  37. default: // case 5:
  38. *r = pix.v; *g = p; *b = q;
  39. break;
  40. }
  41. }
  42. static struct {
  43. float Seathresold;
  44. float Landthresold;
  45. float Tthresold;
  46. hsvpix_t CloudTop;
  47. hsvpix_t CloudBot;
  48. hsvpix_t SeaTop;
  49. hsvpix_t SeaBot;
  50. hsvpix_t GroundTop;
  51. hsvpix_t GroundBot;
  52. } fcinfo= {
  53. 30.0,
  54. 90.0,
  55. 100.0,
  56. {230,0.2,0.3},{230,0.0,1.0},
  57. {200.0,0.7,0.6},{240.0,0.6,0.4},
  58. {60.0,0.6,0.2},{100.0,0.0,0.5}
  59. };
  60. void readfconf(char *file)
  61. {
  62. FILE * fin;
  63. fin=fopen(file,"r");
  64. if(fin==NULL) return;
  65. fscanf(fin,"%g\n",&fcinfo.Seathresold);
  66. fscanf(fin,"%g\n",&fcinfo.Landthresold);
  67. fscanf(fin,"%g\n",&fcinfo.Tthresold);
  68. fscanf(fin,"%g %g %g\n",&fcinfo.CloudTop.h,&fcinfo.CloudTop.s,&fcinfo.CloudTop.v);
  69. fscanf(fin,"%g %g %g\n",&fcinfo.CloudBot.h,&fcinfo.CloudBot.s,&fcinfo.CloudBot.v);
  70. fscanf(fin,"%g %g %g\n",&fcinfo.SeaTop.h,&fcinfo.SeaTop.s,&fcinfo.SeaTop.v);
  71. fscanf(fin,"%g %g %g\n",&fcinfo.SeaBot.h,&fcinfo.SeaBot.s,&fcinfo.SeaBot.v);
  72. fscanf(fin,"%g %g %g\n",&fcinfo.GroundTop.h,&fcinfo.GroundTop.s,&fcinfo.GroundTop.v);
  73. fscanf(fin,"%g %g %g\n",&fcinfo.GroundBot.h,&fcinfo.GroundBot.s,&fcinfo.GroundBot.v);
  74. fclose(fin);
  75. };
  76. void falsecolor(double v, double t, float *r, float *g, float *b)
  77. {
  78. hsvpix_t top,bot,c;
  79. double scv,sct;
  80. if(t<fcinfo.Tthresold) {
  81. if(v < fcinfo.Seathresold) {
  82. /* sea */
  83. top=fcinfo.SeaTop,bot=fcinfo.SeaBot;
  84. scv=v/fcinfo.Seathresold;
  85. sct=t/fcinfo.Tthresold;
  86. } else {
  87. /* ground */
  88. top=fcinfo.GroundTop,bot=fcinfo.GroundBot;
  89. scv=(v-fcinfo.Seathresold)/(fcinfo.Landthresold-fcinfo.Seathresold);
  90. sct=t/fcinfo.Tthresold;
  91. }
  92. } else {
  93. /* clouds */
  94. top=fcinfo.CloudTop,bot=fcinfo.CloudBot;
  95. scv=v/255.0;
  96. sct=t/255.0;
  97. }
  98. c.s=top.s+sct*(bot.s-top.s);
  99. c.v=top.v+scv*(bot.v-top.v);
  100. c.h=top.h+scv*sct*(bot.h-top.h);
  101. HSVtoRGB( r, g, b, c );
  102. };