[2] | 1 | /* image-24.cpp : a 24-bit implementation of the image class */ |
---|
| 2 | |
---|
| 3 | #include "image.hpp" |
---|
| 4 | |
---|
| 5 | // |
---|
| 6 | // Constructor |
---|
| 7 | // |
---|
| 8 | image::image( short width, short height, unsigned char *page_buffer, short create_descriptor ) |
---|
| 9 | { |
---|
| 10 | w = width; |
---|
| 11 | h = height; |
---|
| 12 | |
---|
| 13 | if( create_descriptor || page_buffer ) |
---|
| 14 | { |
---|
| 15 | if( create_descriptor == 2 ) |
---|
| 16 | { |
---|
| 17 | special = new image_descriptor( width, height, 1, ( page_buffer != NULL ) ); |
---|
| 18 | } |
---|
| 19 | else |
---|
| 20 | { |
---|
| 21 | special = new image_descriptor( width, height, 0, ( page_buffer != NULL ) ); |
---|
| 22 | } |
---|
| 23 | } |
---|
| 24 | else |
---|
| 25 | { |
---|
| 26 | special = NULL; |
---|
| 27 | } |
---|
| 28 | |
---|
| 29 | make_page( width, height, page_buffer ); |
---|
| 30 | image_list.add_end( (linked_node *)this ); |
---|
| 31 | } |
---|
| 32 | |
---|
| 33 | // |
---|
| 34 | // Constructor |
---|
| 35 | // |
---|
| 36 | image::image( spec_entry *e, bFILE *fp ) |
---|
| 37 | { |
---|
| 38 | short ii; |
---|
| 39 | |
---|
| 40 | fp->seek( e->offset, 0 ); |
---|
| 41 | w = fp->read_short(); |
---|
| 42 | h = fp->read_short(); |
---|
| 43 | special = NULL; |
---|
| 44 | make_page( w, h, NULL ); |
---|
| 45 | |
---|
| 46 | for( ii = 0; ii < h; ii++ ) |
---|
| 47 | { |
---|
| 48 | fp->read( scan_line( ii ), w ); |
---|
| 49 | } |
---|
| 50 | |
---|
| 51 | image_list.add_end( (linked_node *)this ); |
---|
| 52 | } |
---|
| 53 | |
---|
| 54 | // |
---|
| 55 | // Constructor |
---|
| 56 | // |
---|
| 57 | image::image( bFILE *fp ) |
---|
| 58 | { |
---|
| 59 | short ii; |
---|
| 60 | |
---|
| 61 | w = fp->read_short(); |
---|
| 62 | h = fp->read_short(); |
---|
| 63 | special = NULL; |
---|
| 64 | make_page( w, h, NULL ); |
---|
| 65 | |
---|
| 66 | for( ii = 0; ii < h; ii++ ) |
---|
| 67 | { |
---|
| 68 | fp->read( scan_line( ii ), w ); |
---|
| 69 | } |
---|
| 70 | |
---|
| 71 | image_list.add_end( (linked_node *)this ); |
---|
| 72 | } |
---|
| 73 | |
---|
| 74 | // |
---|
| 75 | // Destructor |
---|
| 76 | // |
---|
| 77 | image::~image() |
---|
| 78 | { |
---|
| 79 | image_list.unlink( (linked_node *)this ); |
---|
| 80 | delete_page(); |
---|
| 81 | if( special ) |
---|
| 82 | { |
---|
| 83 | delete special; |
---|
| 84 | } |
---|
| 85 | } |
---|
| 86 | |
---|
| 87 | // |
---|
| 88 | // total_pixels |
---|
| 89 | // |
---|
| 90 | long image::total_pixels( unsigned char background ) |
---|
| 91 | { |
---|
| 92 | short ii, jj; |
---|
| 93 | long count; |
---|
| 94 | unsigned char *c; |
---|
| 95 | |
---|
| 96 | count = 0; |
---|
| 97 | for( ii = height() - 1; ii >= 0; ii-- ) |
---|
| 98 | { |
---|
| 99 | c = scan_line( ii ); |
---|
| 100 | for( jj = width() - 1; j >= 0; jj--, c++ ) |
---|
| 101 | { |
---|
| 102 | if( *c != background ) |
---|
| 103 | { |
---|
| 104 | count++; |
---|
| 105 | } |
---|
| 106 | } |
---|
| 107 | } |
---|
| 108 | |
---|
| 109 | return count; |
---|
| 110 | } |
---|
| 111 | |
---|
| 112 | // |
---|
| 113 | // clear |
---|
| 114 | // |
---|
| 115 | void image::clear( short color ) |
---|
| 116 | { |
---|
| 117 | |
---|
| 118 | } |
---|
| 119 | |
---|