| 80 | } |
| 81 | |
| 82 | int |
| 83 | convert(MFDB *image, long size) |
| 84 | { |
| 85 | int plane, mplanes; |
| 86 | char *line_addr, *buf_addr, *new_addr, *new1_addr, *image_addr, |
| 87 | *screen_addr; |
| 88 | MFDB dev_form, tmp; |
| 89 | long new_size; |
| 90 | |
| 91 | /* convert size from words to bytes */ |
| 92 | size <<= 1; |
| 93 | |
| 94 | /* memory for the device raster */ |
| 95 | new_size = size * (long) planes; |
| 96 | if ((new_addr = (char *) calloc(1, new_size)) == NULL) |
| 97 | return (FALSE); |
| 98 | |
| 99 | /* initialize MFDBs */ |
| 100 | tmp = *image; |
| 101 | tmp.fd_nplanes = planes; |
| 102 | tmp.fd_addr = new_addr; |
| 103 | tmp.fd_stand = 1; /* standard format */ |
| 104 | dev_form = tmp; |
| 105 | screen_addr = new_addr; |
| 106 | dev_form.fd_stand = 0; /* device format */ |
| 107 | image_addr = (char *) image->fd_addr; |
| 108 | |
| 109 | /* initialize some variables and zero temp. line buffer */ |
| 110 | mplanes = min(image->fd_nplanes, planes); |
| 111 | /* convert image */ |
| 112 | line_addr = image_addr; |
| 113 | buf_addr = screen_addr; |
| 114 | if (mplanes > 1) { |
| 115 | /* cut/pad color planes into temp buf */ |
| 116 | for (plane = 0; plane < mplanes; plane++) { |
| 117 | memcpy(buf_addr, line_addr, size); |
| 118 | line_addr += size; |
| 119 | buf_addr += size; |
| 120 | } |
| 121 | } else { |
| 122 | /* fill temp line bitplanes with a b&w line */ |
| 123 | for (plane = 0; plane < planes; plane++) { |
| 124 | memcpy(buf_addr, line_addr, size); |
| 125 | buf_addr += size; |
| 126 | } |
| 127 | } |
| 128 | free(image->fd_addr); |
| 129 | /* convert image line in temp into current device raster format */ |
| 130 | if ((new1_addr = (char *) calloc(1, new_size)) == NULL) |
| 131 | return (FALSE); |
| 132 | dev_form.fd_addr = new1_addr; |
| 133 | vr_trnfm(x_handle, &tmp, &dev_form); |
| 134 | free(new_addr); |
| 135 | |
| 136 | /* change image description */ |
| 137 | image->fd_stand = 0; /* device format */ |
| 138 | image->fd_addr = new1_addr; |
| 139 | image->fd_nplanes = planes; |