Jack Jansen | e6f49ec | 1993-01-27 11:39:37 +0000 | [diff] [blame^] | 1 | import imageop |
| 2 | |
| 3 | error = 'imgconv.error' |
| 4 | |
| 5 | LOSSY = 1 |
| 6 | NOT_LOSSY = 0 |
| 7 | |
| 8 | def null(img, x, y): |
| 9 | return img |
| 10 | |
| 11 | def mono2grey(img, x, y): |
| 12 | imageop.mono2grey(img, x, y, 0, 255) |
| 13 | |
| 14 | converters = [ \ |
| 15 | ('grey', 'grey4', imageop.grey2grey4, LOSSY), \ |
| 16 | ('grey', 'grey2', imageop.dither2grey2, LOSSY), \ |
| 17 | ('grey', 'mono', imageop.dither2mono, LOSSY), \ |
| 18 | ('mono', 'grey', mono2grey, NOT_LOSSY), \ |
| 19 | ('grey2', 'grey', imageop.grey22grey, NOT_LOSSY), \ |
| 20 | ('grey4', 'grey', imageop.grey42grey, NOT_LOSSY), \ |
| 21 | ] |
| 22 | |
| 23 | def addconverter(fcs, tcs, lossy, func): |
| 24 | for i in range(len(converters)): |
| 25 | ifcs, itcs, irtn, ilossy = converters[i] |
| 26 | if (fcs, tcs) == (ifcs, itcs): |
| 27 | converters[i] = (fcs, tcs, func, lossy) |
| 28 | return |
| 29 | converters.append((fcs,tcs,lossy,func)) |
| 30 | |
| 31 | def getconverter(fcs, tcs): |
| 32 | if fcs == tcs: return null |
| 33 | |
| 34 | for ifcs, itcs, irtn, ilossy in converters: |
| 35 | if (fcs, tcs) == (ifcs, itcs): |
| 36 | return irtn |
| 37 | raise error, 'Sorry, that conversion is not implemented' |
| 38 | |