edith_codecs
Clone
https://git.tahinli.com/Tahinli/edith_codecs.git
0 watching0 forksRust370.3 MiBef9e91aTahinli2 months ago2795 commits
| 1 | """Write the BMP shapes ImageMagick will not emit. |
| 2 | |
| 3 | ImageMagick covers the ordinary files (1/4/8-bit palettes, RLE8, 24-bit), but |
| 4 | it has no switch for a 16-bit bitfield file, a top-down row order, a 32-bit |
| 5 | file with an alpha channel, or the 12-byte OS/2 header -- all of which are |
| 6 | shapes a decoder meets in the wild. Each is written here from a raw RGBA dump |
| 7 | so the pixels are the same picture as the rest of the corpus. |
| 8 | """ |
| 9 | |
| 10 | |
| 11 | |
| 12 | |
| 13 | , , , = , , , |
| 14 | = |
| 15 | = |
| 16 | |
| 17 | |
| 18 | |
| 19 | = * 4 |
| 20 | return , , , |
| 21 | |
| 22 | |
| 23 | |
| 24 | = |
| 25 | = |
| 26 | return |
| 27 | |
| 28 | |
| 29 | |
| 30 | return b + |
| 31 | |
| 32 | |
| 33 | |
| 34 | = |
| 35 | |
| 36 | |
| 37 | |
| 38 | return |
| 39 | |
| 40 | |
| 41 | |
| 42 | = 14 + + |
| 43 | = + + + |
| 44 | |
| 45 | |
| 46 | |
| 47 | |
| 48 | """Pack rows to the format's four-byte row alignment.""" |
| 49 | = * 4 |
| 50 | = |
| 51 | |
| 52 | = |
| 53 | |
| 54 | += |
| 55 | += b * |
| 56 | += |
| 57 | return |
| 58 | |
| 59 | |
| 60 | # 16-bit, 5-6-5, declared through BI_BITFIELDS masks. |
| 61 | = |
| 62 | = |
| 63 | |
| 64 | |
| 65 | |
| 66 | # 16-bit, 5-5-5, the layout BI_RGB implies at this depth (no mask block). |
| 67 | = |
| 68 | |
| 69 | |
| 70 | |
| 71 | # 32-bit with an alpha channel: the fourth mask only has a home in the |
| 72 | # BITMAPV4HEADER, whose 108 bytes carry all four masks plus a colour space. |
| 73 | = |
| 74 | = |
| 75 | |
| 76 | + |
| 77 | |
| 78 | + b + b * 48 |
| 79 | |
| 80 | |
| 81 | # Top-down rows: a negative height, first row stored first. |
| 82 | = |
| 83 | = |
| 84 | |
| 85 | |
| 86 | # RLE4, from the 4-bit palette file ImageMagick wrote: same palette, same |
| 87 | # indices, only the run encoding differs -- ImageMagick's RLE switch produces |
| 88 | # an 8-bit file whatever the colour count, so the 4-bit run path has no other |
| 89 | # source. |
| 90 | |
| 91 | = |
| 92 | , = |
| 93 | , = |
| 94 | , = |
| 95 | = or 16 |
| 96 | = |
| 97 | = * 4 |
| 98 | = |
| 99 | |
| 100 | = |
| 101 | = |
| 102 | |
| 103 | = |
| 104 | |
| 105 | = 0 |
| 106 | |
| 107 | = 1 |
| 108 | |
| 109 | += 1 |
| 110 | |
| 111 | += |
| 112 | += |
| 113 | continue |
| 114 | # A literal run needs at least three pixels to be legal; below that |
| 115 | # the encoded form is a run of one. |
| 116 | = |
| 117 | |
| 118 | = 1 |
| 119 | |
| 120 | += 1 |
| 121 | |
| 122 | break |
| 123 | += |
| 124 | = - |
| 125 | |
| 126 | += |
| 127 | += 1 |
| 128 | continue |
| 129 | = |
| 130 | |
| 131 | = << 4 |
| 132 | = |
| 133 | |
| 134 | |
| 135 | |
| 136 | += + |
| 137 | = |
| 138 | += b |
| 139 | = + b |
| 140 | = |
| 141 | |
| 142 | |
| 143 | |
| 144 | |
| 145 | |
| 146 | |
| 147 | # BI_PNG and BI_JPEG: a BMP file header and info header wrapped around a whole |
| 148 | # file of another format, which is what a printer driver or a clipboard writes. |
| 149 | |
| 150 | = |
| 151 | = |
| 152 | |
| 153 | |
| 154 | |
| 155 | |
| 156 | |
| 157 | |
| 158 | |
| 159 | |
| 160 | |
| 161 | # The OS/2 v2 header, in the 16-byte form writers actually emit: 32-bit |
| 162 | # dimensions like a Windows header, and nothing after them. |
| 163 | = |
| 164 | |
| 165 | |
| 166 | # The 12-byte OS/2 v1 header, whose dimensions are 16-bit and unsigned. |
| 167 | = |
| 168 |