1 // This is core/vil1/file_formats/vil1_gif.h 2 #ifndef vil1_gif_h_ 3 #define vil1_gif_h_ 4 //: 5 // \file 6 // \author fsm 7 // 8 // This is an ad hoc hack. If you write a better one, you are most 9 // welcome to replace mine with yours. 10 // 11 //\verbatim 12 // Modifications 13 // 3 October 2001 Peter Vanroose - Implemented get_property("top_row_first") 14 //\endverbatim 15 16 class vil1_stream; 17 #include <vector> 18 #ifdef _MSC_VER 19 # include <vcl_msvc_warnings.h> 20 #endif 21 #include <vil1/vil1_file_format.h> 22 #include <vil1/vil1_image_impl.h> 23 #include <vil1/vil1_image.h> 24 25 bool vil1_gif_probe(vil1_stream *s); 26 27 struct vil1_gif_file_format : public vil1_file_format 28 { 29 char const* tag() const override; 30 vil1_image_impl *make_input_image(vil1_stream* vs) override; 31 vil1_image_impl *make_output_image(vil1_stream*, int, int, int, int, int, vil1_component_format) override; 32 }; 33 34 struct vil1_gif_color_map 35 { 36 int size; 37 char *cmap; vil1_gif_color_mapvil1_gif_color_map38 vil1_gif_color_map(int sz) : size(sz), cmap(new char [3*size]) { } ~vil1_gif_color_mapvil1_gif_color_map39 ~vil1_gif_color_map() { delete [] cmap; cmap = nullptr; } 40 }; 41 42 struct vil1_gif_image_record 43 { 44 int offset; 45 int x0, y0; 46 int w, h; 47 vil1_gif_color_map *color_map; 48 bool interlaced; 49 int bits_per_pixel; 50 int bitmap_start; 51 }; 52 53 struct vil1_gif_loader_saver : public vil1_image_impl 54 { 55 vil1_gif_loader_saver(vil1_stream *); 56 #if 0 57 vil1_gif_loader_saver(vil1_stream *is, 58 int planes, 59 int width, 60 int height, 61 int components, 62 int bits_per_component, 63 vil1_component_format format); 64 #endif 65 ~vil1_gif_loader_saver() override; 66 planesvil1_gif_loader_saver67 int planes() const override { return int(images.size()); } widthvil1_gif_loader_saver68 int width() const override { return screen_width_; } heightvil1_gif_loader_saver69 int height() const override { return screen_height_; } componentsvil1_gif_loader_saver70 int components() const override { return is_grey ? 1 : 3; } bits_per_componentvil1_gif_loader_saver71 int bits_per_component() const override { return 8; } component_formatvil1_gif_loader_saver72 enum vil1_component_format component_format() const override { return VIL1_COMPONENT_FORMAT_UNSIGNED_INT; } 73 74 vil1_image get_plane(unsigned int p) const override; 75 bool get_section(void *buf, int x0, int y0, int width, int height) const override; 76 bool get_section(int image, void *buf, int x0, int y0, int width, int height) const; 77 bool put_section(void const *, int, int, int, int) override; put_sectionvil1_gif_loader_saver78 bool put_section(int, void const *, int, int, int, int) { return false; } 79 80 char const *file_format() const override; 81 bool get_property(char const *tag, void *prop = nullptr) const override; 82 83 private: 84 vil1_stream *s; 85 int screen_width_; 86 int screen_height_; 87 bool is_grey; // set to true if all entries in the colour map are grey 88 89 vil1_gif_color_map *global_color_map; 90 int background_index; 91 92 std::vector<void*> images; 93 }; 94 95 struct vil1_gif_loader_saver_proxy : public vil1_image_impl 96 { 97 int image; 98 vil1_gif_loader_saver *other; 99 vil1_image up_ref_is_private; 100 vil1_gif_loader_saver_proxyvil1_gif_loader_saver_proxy101 vil1_gif_loader_saver_proxy(int image_, vil1_gif_loader_saver *other_) 102 : image(image_), other(other_) { 103 // why doesn't this work? 104 //up_ref_is_private(other); 105 } 106 107 ~vil1_gif_loader_saver_proxy() override = default; 108 planesvil1_gif_loader_saver_proxy109 int planes() const override { return 1; } widthvil1_gif_loader_saver_proxy110 int width() const override { return other->width(); } heightvil1_gif_loader_saver_proxy111 int height() const override { return other->height(); } componentsvil1_gif_loader_saver_proxy112 int components() const override { return other->components(); } bits_per_componentvil1_gif_loader_saver_proxy113 int bits_per_component() const override { return other->bits_per_component(); } 114 component_formatvil1_gif_loader_saver_proxy115 enum vil1_component_format component_format() const override { return other->component_format(); } 116 get_sectionvil1_gif_loader_saver_proxy117 bool get_section(void *buf, int x0, int y0, int w, int h) const override 118 { return other->get_section(image, buf, x0, y0, w, h); } 119 put_sectionvil1_gif_loader_saver_proxy120 bool put_section(void const *buf, int x0, int y0, int w, int h) override 121 { return other->put_section(image, buf, x0, y0, w, h); } 122 file_formatvil1_gif_loader_saver_proxy123 char const *file_format() const override { return other->file_format(); } 124 }; 125 126 #endif // vil1_gif_h_ 127