image.hpp 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. #ifndef _IMGAE_HPP_
  2. #define _IMGAE_HPP_
  3. #include <stdlib.h>
  4. #include "linked.hpp"
  5. #include "palette.hpp"
  6. #include "system.h"
  7. #include "specs.hpp"
  8. #define MAX_DIRTY 200
  9. #define Inew(pointer,type); { make_block(sizeof(type)); pointer=new type; }
  10. extern char *imerr_messages[]; // correspond to imERRORS
  11. #define imREAD_ERROR 1
  12. #define imINCORRECT_FILETYPE 2
  13. #define imFILE_CORRUPTED 3
  14. #define imFILE_NOT_FOUND 4
  15. #define imMEMORY_ERROR 5
  16. #define imNOT_SUPPORTED 6
  17. #define imWRITE_ERROR 7
  18. #define imMAX_ERROR 7
  19. short current_error();
  20. void clear_errors();
  21. void set_error(short x);
  22. short last_error();
  23. void make_block(size_t size);
  24. void image_init();
  25. void image_uninit();
  26. extern linked_list image_list;
  27. class filter;
  28. class dirty_rect : public linked_node
  29. {
  30. public :
  31. short dx1,dy1,dx2,dy2;
  32. dirty_rect(short x1, short y1, short x2, short y2)
  33. { dx1=x1; dy1=y1; dx2=x2; dy2=y2;
  34. if (x2<x1 || y2<y1)
  35. printf("add inccorect dirty\n");
  36. }
  37. virtual short compare(void *n1, short field)
  38. { return ((dirty_rect *)n1)->dy1>dy1; }
  39. } ;
  40. class image_descriptor
  41. {
  42. short l,h;
  43. short clipx1, clipy1, clipx2, clipy2;
  44. public :
  45. unsigned char keep_dirt,
  46. static_mem; // if this flag is set then don't free memory on exit
  47. linked_list dirties;
  48. void *extended_descriptor; // type depends on current system
  49. image_descriptor(short length, short height,
  50. int keep_dirties=1, int static_memory=0);
  51. short bound_x1(short x1) { return x1<clipx1 ? clipx1 : x1; }
  52. short bound_y1(short y1) { return y1<clipy1 ? clipy1 : y1; }
  53. short bound_x2(short x2) { return x2>clipx2 ? clipx2 : x2; }
  54. short bound_y2(short y2) { return y2>clipy2 ? clipy2 : y2; }
  55. short x1_clip() { return clipx1; }
  56. short y1_clip() { return clipy1; }
  57. short x2_clip() { return clipx2; }
  58. short y2_clip() { return clipy2; }
  59. void dirty_area(short x1, short y1, short x2, short y2) { ;}
  60. void clean_area(short x1, short y1, short x2, short y2) { ; }
  61. void clear_dirties();
  62. short get_dirty_area(short &x1, short &y1, short &x2, short &y2) { return 0; }
  63. void get_clip(short &x1, short &y1, short &x2, short &y2)
  64. { x1=clipx1; y1=clipy1; x2=clipx2; y2=clipy2; }
  65. void set_clip(short x1, short y1, short x2, short y2)
  66. { if (x2<x1) x2=x1;
  67. if (y2<y1) y2=y1;
  68. if (x1<0) clipx1=0; else clipx1=x1;
  69. if (y1<0) clipy1=0; else clipy1=y1;
  70. if (x2>=l) clipx2=l-1; else clipx2=x2;
  71. if (y2>=h) clipy2=h-1; else clipy2=y2;
  72. }
  73. void reduce_dirties();
  74. void add_dirty(int x1, int y1, int x2, int y2);
  75. void delete_dirty(int x1, int y1, int x2, int y2);
  76. void resize(short length, short height)
  77. { l=length; h=height; clipx1=0; clipy1=0; clipx2=l-1; clipy2=h-1; }
  78. } ;
  79. class image : public linked_node
  80. {
  81. unsigned char *data;
  82. short w,h;
  83. void make_page(short width, short height, unsigned char *page_buffer);
  84. void delete_page();
  85. public :
  86. image_descriptor *special;
  87. image(spec_entry *e, bFILE *fp);
  88. image(bFILE *fp);
  89. image(short width, short height, // required
  90. unsigned char *page_buffer=NULL,
  91. short create_descriptor=0); // 0=no, 1=yes, 2=yes & keep dirties
  92. unsigned char pixel (short x, short y);
  93. void putpixel (short x, short y, char color);
  94. unsigned char *scan_line (short y) { return data+y*w; }
  95. unsigned char *next_line (short lasty, unsigned char *last_scan)
  96. { return last_scan+w; }
  97. long total_pixels (unsigned char background=0);
  98. image *copy (); // makes a copy of an image
  99. void clear (short color=-1); // -1 is background color
  100. void to_24bit (palette &pal);
  101. short width () { return (short)w; }
  102. short height () { return (short)h; }
  103. void scroll (short x1, short y1, short x2, short y2, short xd, short yd);
  104. void fill_image (image *screen, short x1, short y1, short x2, short y2,
  105. short allign=1);
  106. void put_image (image *screen, short x, short y, char transparent=0);
  107. void put_part (image *screen, short x, short y, short x1, short y1,
  108. short x2, short y2, char transparent=0);
  109. void put_part_xrev (image *screen, short x, short y, short x1, short y1,
  110. short x2, short y2, char transparent=0);
  111. void put_part_masked (image *screen, image *mask, short x, short y,
  112. short maskx, short masky, short x1, short y1, short x2, short y2);
  113. image *copy_part_dithered (short x1, short y1, short x2, short y2);
  114. void bar (short x1, short y1, short x2, short y2, unsigned char color);
  115. void xor_bar (short x1, short y1, short x2, short y2, unsigned char color);
  116. void wiget_bar (short x1, short y1, short x2, short y2,
  117. unsigned char light, unsigned char med, unsigned char dark);
  118. void line (short x1, short y1, short x2, short y2, unsigned char color);
  119. void rectangle (short x1, short y1, short x2, short y2, unsigned char color);
  120. void burn_led (short x, short y, long num, short color, short scale=1);
  121. void set_clip (short x1, short y1, short x2, short y2);
  122. void get_clip (short &x1,short &y1,short &x2,short &y2);
  123. void in_clip (short x1, short y1, short x2, short y2);
  124. void dirt_off () { if (special && special->keep_dirt) special->keep_dirt=0; }
  125. void dirt_on () { if (special) special->keep_dirt=1; }
  126. void add_dirty (int x1, int y1, int x2, int y2)
  127. { if (special) special->add_dirty(x1,y1,x2,y2); }
  128. void delete_dirty (int x1, int y1, int x2, int y2)
  129. { if (special) special->delete_dirty(x1,y1,x2,y2); }
  130. void clear_dirties () { if (special) special->clear_dirties(); }
  131. void dither (palette *pal); // use a b&w palette!
  132. void resize (short new_width, short new_height);
  133. void change_size (short new_width, short new_height, unsigned char *page=NULL);
  134. void flood_fill (short x, short y, unsigned char color);
  135. image *create_smooth (short smoothness=1); // 0 no smoothness
  136. void unpack_scanline (short line, char bitsperpixel=1);
  137. unsigned char brightest_color (palette *pal);
  138. void flip_x ();
  139. void flip_y ();
  140. void make_color (unsigned char color);
  141. unsigned char darkest_color (palette *pal, short noblack=0);
  142. ~image();
  143. } ;
  144. class image_controller
  145. {
  146. public :
  147. image_controller() { image_init(); }
  148. ~image_controller()
  149. {
  150. image_uninit();
  151. }
  152. } ;
  153. #endif