- if (image->bitmap_bit_order != MSBFirst
- || (image->byte_order != MSBFirst
- && image->bitmap_unit != 8))
- {
- /* We must adjust image->data for PBM. */
- int bytes_per_unit = image->bitmap_unit / 8;
-
- for (y = 0; y < image->height; y++, data += image->bytes_per_line)
- {
- char b;
-
- if (image->byte_order != MSBFirst)
- {
- if (reverse_bit_order[0] == 0)
- init_reverse_bit_order ();
- if (bytes_per_unit == 2)
- for (x = 0; x < image->bytes_per_line; x += 2)
- b = data[x], data[x] = data[x + 1], data[x + 1] = b;
- else if (bytes_per_unit == 6)
- for (x = 0; x < image->bytes_per_line; x += 3)
- {
- b = data[x], data[x] = data[x + 3], data[x + 3] = b;
- x++;
- b = data[x], data[x] = data[x + 1], data[x + 1] = b;
- }
- }
-
- if (image->bitmap_bit_order != MSBFirst)
- for (x = 0; x < image->bytes_per_line; x++)
- data[x] = reverse_bit_order[(unsigned char) data[x]];
- if (! white_is_zero)
- for (x = 0; x < image->bytes_per_line; x++)
- data[x] = ~data[x];
- }
- /* Reset DATA. */
- data = image->data;
- }
-
- /* Generate PBM (Portable Bitmap File Format) of P4 format. */
- fprintf (fp, "P4\n%d %d\n", image->width, image->height);
- pbm_bytes_per_line = (image->width + 7) / 8;
- for (y = 0; y < image->height; y++, data += image->bytes_per_line)
- fwrite (data, 1, pbm_bytes_per_line, fp);
-