gradiant.cc 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /********************************************************************** <BR>
  2. This file is part of Crack dot Com's free source code release of
  3. Golgotha. <a href="http://www.crack.com/golgotha_release"> <BR> for
  4. information about compiling & licensing issues visit this URL</a>
  5. <PRE> If that doesn't help, contact Jonathan Clark at
  6. golgotha_source@usa.net (Subject should have "GOLG" in it)
  7. ***********************************************************************/
  8. #include "image/image.hh"
  9. #include "palette/pal.hh"
  10. #include "image/context.hh"
  11. void i4_gradiant_bar(i4_image_class *im, int x1, int y1, int x2, int y2,
  12. i4_color start_color, i4_color end_color,
  13. i4_draw_context_class &context)
  14. {
  15. context.add_both_dirty(x1,y1,x2,y2);
  16. float sr=(start_color>>16)&0xff, sg=(start_color>>8)&0xff, sb=(start_color)&0xff;
  17. float er=(end_color>>16)&0xff, eg=(end_color>>8)&0xff, eb=(end_color)&0xff;
  18. im->add_dirty(x1,y1,x2,y2, context);
  19. float t=1.0/(x2-x1+1);
  20. float r_step=(er-sr)*t;
  21. float g_step=(eg-sg)*t;
  22. float b_step=(eb-sb)*t;
  23. int w=(x2-x1+1);
  24. int h=(y2-y1+1);
  25. if (w*h*4<32*1024) // do it fast if it's small than 32k
  26. {
  27. i4_image_class *fast=i4_create_image(w,h, i4_pal_man.default_no_alpha_32());
  28. for (int x=0; x<w; x++)
  29. {
  30. w32 c=(((int)sr)<<16) | (((int)sg)<<8) | (((int)sb));
  31. w32 *sl=((w32 *)fast->data)+x;
  32. for (int y=0; y<h; y++)
  33. {
  34. *sl=c;
  35. sl+=w;
  36. }
  37. sr+=r_step; sg+=g_step; sb+=b_step;
  38. }
  39. fast->put_image(im, x1,y1, context);
  40. delete fast;
  41. }
  42. else
  43. {
  44. for (int x=x1; x<=x2; x++)
  45. {
  46. w32 c=(((int)sr)<<16) | (((int)sg)<<8) | (((int)sb));
  47. im->bar(x,y1,x,y2, c, context);
  48. sr+=r_step; sg+=g_step; sb+=b_step;
  49. }
  50. }
  51. }