image8.cc 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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/image8.hh"
  9. #include "memory/malloc.hh"
  10. #include "palette/pal.hh"
  11. #include <string.h>
  12. i4_color i4_image8::get_pixel(i4_coord x, i4_coord y)
  13. {
  14. return i4_pal_man.convert_to_32(*(typed_data() + bpl*y + x), pal);
  15. }
  16. void i4_image8::put_pixel(i4_coord x, i4_coord y, w32 color)
  17. {
  18. *(typed_data() + bpl*y + x)=i4_pal_man.convert_32_to(color, &pal->source);
  19. }
  20. i4_image8::i4_image8(w16 _w, w16 _h, const i4_pal *_pal)
  21. {
  22. w=_w;
  23. h=_h;
  24. bpl=_w;
  25. set_pal(_pal);
  26. data=i4_malloc(w*h,"");
  27. }
  28. i4_image8::i4_image8(w16 _w, w16 _h, const i4_pal *_pal,
  29. void *_data, int _bpl)
  30. {
  31. data=_data;
  32. bpl=_bpl;
  33. pal=_pal;
  34. w=_w;
  35. h=_h;
  36. dont_free_data=i4_T;
  37. }
  38. i4_image8::~i4_image8()
  39. {
  40. if (!dont_free_data)
  41. i4_free(data);
  42. }
  43. i4_image_class *i4_image8::copy()
  44. {
  45. i4_image_class *im=i4_create_image(width(), height(), pal);
  46. for (int y=0; y<h; y++)
  47. memcpy(((w8 *)im->data) + y*im->bpl,
  48. ((w8 *)data) + y*bpl,
  49. w);
  50. return im;
  51. }