Frames containing 32bpp bitmaps apparently take longer to encode than frames containing 8bpp bitmaps. Investigate whether encoding can be speeded up by converting images to 8bpp before encoding.
This sounded like a really good idea, after all a colour table in a GIF image can only have a maximum of 256 colours so 8bpp is a more sensible colour depth to use than anything higher. However while I've been looking at this I've come across a few problems...
It doesn't seem to be possible to programatically create a bitmap with a colour depth of less than 16bpp. All of the the System.Drawing.Imaging.PixelFormat enumeration members which indicate 8bpp or lower (there are 8, 4 and 1bpp members available) are for indexed pixel formats (i.e. the pixel data is an index into the image's palette rather than the actual colour of the pixel), and the Bitmap.SetPixel method throws an exception when used on a bitmap which has been created using those PixelFormats.
So I haven't been able to compare encoding times for 8bpp images with those for other colour depths, although I was able to compare encoding times for all the PixelFormats for which I could programmatically create bitmaps. (see attached .cs files - I've also added them to the code repository).
Basically, what the test does is to loop through all the members of System.Drawing.Imaging.PixelFormat which can be used to instantiate a Bitmap, and for which the SetPixel method doesn't throw an exception, and for each one create 10 bitmaps of 50x50 pixels, and then time how long it takes AnimatedGifEncoder.WriteToFile to create a GIF file out of each set of 10 bitmaps.
The console output is:
Encoding Format16bppArgb1555 took 00:00:05.5780208
Encoding Format16bppRgb555 took 00:00:02.9542480
Encoding Format16bppRgb565 took 00:00:03.1645504
Encoding Format24bppRgb took 00:00:02.7038880
Encoding Format32bppArgb took 00:00:02.7639744
Encoding Format32bppPArgb took 00:00:02.6037440
Encoding Format32bppRgb took 00:00:02.9442336
Encoding Format48bppRgb took 00:00:04.2561200
Encoding Format64bppArgb took 00:00:02.9141904
Encoding Format64bppPArgb took 00:00:03.1244928
Encoding Format16bppArgb1555 took 00:00:03.4649824
Encoding Format16bppRgb555 took 00:00:01.9427936
Encoding Format16bppRgb565 took 00:00:02.9842912
Encoding Format24bppRgb took 00:00:02.7639744
Encoding Format32bppArgb took 00:00:01.7825632
Encoding Format32bppPArgb took 00:00:02.8541040
Encoding Format32bppRgb took 00:00:01.9227648
Encoding Format48bppRgb took 00:00:03.8855872
Encoding Format64bppArgb took 00:00:03.2747088
Encoding Format64bppPArgb took 00:00:03.5851552
Encoding Format16bppArgb1555 took 00:00:02.8641184
Encoding Format16bppRgb555 took 00:00:02.9742768
Encoding Format16bppRgb565 took 00:00:03.3347952
Encoding Format24bppRgb took 00:00:02.7339312
Encoding Format32bppArgb took 00:00:02.4835712
Encoding Format32bppPArgb took 00:00:03.2747088
Encoding Format32bppRgb took 00:00:03.6452416
Encoding Format48bppRgb took 00:00:04.1659904
Encoding Format64bppArgb took 00:00:02.8440896
Encoding Format64bppPArgb took 00:00:04.0458176
Encoding Format16bppArgb1555 took 00:00:02.7439456
Encoding Format16bppRgb555 took 00:00:03.1445216
Encoding Format16bppRgb565 took 00:00:03.3247808
Encoding Format24bppRgb took 00:00:03.2847232
Encoding Format32bppArgb took 00:00:02.6638304
Encoding Format32bppPArgb took 00:00:02.5136144
Encoding Format32bppRgb took 00:00:03.1745648
Encoding Format48bppRgb took 00:00:02.5737008
Encoding Format64bppArgb took 00:00:03.6352272
Encoding Format64bppPArgb took 00:00:03.7554000
Encoding Format16bppArgb1555 took 00:00:03.2046080
Encoding Format16bppRgb555 took 00:00:02.7339312
Encoding Format16bppRgb565 took 00:00:02.5937296
Encoding Format24bppRgb took 00:00:02.9642624
Encoding Format32bppArgb took 00:00:02.3333552
Encoding Format32bppPArgb took 00:00:02.6237728
Encoding Format32bppRgb took 00:00:02.3133264
Encoding Format48bppRgb took 00:00:03.2246368
Encoding Format64bppArgb took 00:00:03.4149104
Encoding Format64bppPArgb took 00:00:03.3347952
Encoding Format16bppArgb1555 took 00:00:03.5551120
Encoding Format16bppRgb555 took 00:00:02.7239168
Encoding Format16bppRgb565 took 00:00:03.3848672
Encoding Format24bppRgb took 00:00:02.5837152
Encoding Format32bppArgb took 00:00:01.8025920
Encoding Format32bppPArgb took 00:00:02.6538160
Encoding Format32bppRgb took 00:00:03.5050400
Encoding Format48bppRgb took 00:00:03.0343632
Encoding Format64bppArgb took 00:00:02.5536720
Encoding Format64bppPArgb took 00:00:03.0844352
Encoding Format16bppArgb1555 took 00:00:02.4334992
Encoding Format16bppRgb555 took 00:00:02.5036000
Encoding Format16bppRgb565 took 00:00:02.4635424
Encoding Format24bppRgb took 00:00:03.2146224
Encoding Format32bppArgb took 00:00:02.8240608
Encoding Format32bppPArgb took 00:00:03.2346512
Encoding Format32bppRgb took 00:00:02.6137584
Encoding Format48bppRgb took 00:00:03.0143344
Encoding Format64bppArgb took 00:00:02.9342192
Encoding Format64bppPArgb took 00:00:02.5236288
Encoding Format16bppArgb1555 took 00:00:02.4735568
Encoding Format16bppRgb555 took 00:00:02.9742768
Encoding Format16bppRgb565 took 00:00:02.3133264
Encoding Format24bppRgb took 00:00:02.1130384
Encoding Format32bppArgb took 00:00:02.5536720
Encoding Format32bppPArgb took 00:00:02.6838592
Encoding Format32bppRgb took 00:00:02.8340752
Encoding Format48bppRgb took 00:00:03.5651264
Encoding Format64bppArgb took 00:00:03.0443776
Encoding Format64bppPArgb took 00:00:02.6738448
Encoding Format16bppArgb1555 took 00:00:02.2632544
Encoding Format16bppRgb555 took 00:00:03.3748528
Encoding Format16bppRgb565 took 00:00:02.7739888
Encoding Format24bppRgb took 00:00:02.5937296
Encoding Format32bppArgb took 00:00:02.6638304
Encoding Format32bppPArgb took 00:00:03.0043200
Encoding Format32bppRgb took 00:00:02.3433696
Encoding Format48bppRgb took 00:00:02.8741328
Encoding Format64bppArgb took 00:00:02.4535280
Encoding Format64bppPArgb took 00:00:02.9642624
Encoding Format16bppArgb1555 took 00:00:02.9242048
Encoding Format16bppRgb555 took 00:00:02.6738448
Encoding Format16bppRgb565 took 00:00:02.5937296
Encoding Format24bppRgb took 00:00:03.3648384
Encoding Format32bppArgb took 00:00:02.6938736
Encoding Format32bppPArgb took 00:00:02.3233408
Encoding Format32bppRgb took 00:00:03.3548240
Encoding Format48bppRgb took 00:00:03.2046080
Encoding Format64bppArgb took 00:00:02.6037440
Encoding Format64bppPArgb took 00:00:02.4435136
Consolidating all that into a spreadsheet (also attached), it looks like there isn't much difference between the time taken to encode a set of 64bpp bitmaps and the time taken to encode a set of 16bpp bitmaps, so I'm not sure that reducing the colour depth to 8-bit would make any difference.
Here's the consolidated results from the spreadsheet:
Format Sum of Time to encode Average of Time to encode
Format16bppArgb1555 00:00:31 00:00:03
Format16bppRgb555 00:00:29 00:00:03
Format16bppRgb565 00:00:28 00:00:03
Format24bppRgb 00:00:29 00:00:03
Format32bppArgb 00:00:26 00:00:03
Format32bppPArgb 00:00:29 00:00:03
Format32bppRgb 00:00:29 00:00:03
Format48bppRgb 00:00:34 00:00:03
Format64bppArgb 00:00:30 00:00:03
Format64bppPArgb 00:00:32 00:00:03
So, unless anyone can suggest a way to compare encoding times for 8bpp bitmaps with those for 16bpp, 24bpp, etc bitmaps, I think this request is unfeasible.
Simon.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
AnimatedGifEncoderSpeedTests test fixture
RandomBitmap class for creating random bitmaps at runtime
Results of comparing time taken to encode bitmaps of various colour depths
This sounded like a really good idea, after all a colour table in a GIF image can only have a maximum of 256 colours so 8bpp is a more sensible colour depth to use than anything higher. However while I've been looking at this I've come across a few problems...
It doesn't seem to be possible to programatically create a bitmap with a colour depth of less than 16bpp. All of the the System.Drawing.Imaging.PixelFormat enumeration members which indicate 8bpp or lower (there are 8, 4 and 1bpp members available) are for indexed pixel formats (i.e. the pixel data is an index into the image's palette rather than the actual colour of the pixel), and the Bitmap.SetPixel method throws an exception when used on a bitmap which has been created using those PixelFormats.
So I haven't been able to compare encoding times for 8bpp images with those for other colour depths, although I was able to compare encoding times for all the PixelFormats for which I could programmatically create bitmaps. (see attached .cs files - I've also added them to the code repository).
Basically, what the test does is to loop through all the members of System.Drawing.Imaging.PixelFormat which can be used to instantiate a Bitmap, and for which the SetPixel method doesn't throw an exception, and for each one create 10 bitmaps of 50x50 pixels, and then time how long it takes AnimatedGifEncoder.WriteToFile to create a GIF file out of each set of 10 bitmaps.
The console output is:
Encoding Format16bppArgb1555 took 00:00:05.5780208
Encoding Format16bppRgb555 took 00:00:02.9542480
Encoding Format16bppRgb565 took 00:00:03.1645504
Encoding Format24bppRgb took 00:00:02.7038880
Encoding Format32bppArgb took 00:00:02.7639744
Encoding Format32bppPArgb took 00:00:02.6037440
Encoding Format32bppRgb took 00:00:02.9442336
Encoding Format48bppRgb took 00:00:04.2561200
Encoding Format64bppArgb took 00:00:02.9141904
Encoding Format64bppPArgb took 00:00:03.1244928
Encoding Format16bppArgb1555 took 00:00:03.4649824
Encoding Format16bppRgb555 took 00:00:01.9427936
Encoding Format16bppRgb565 took 00:00:02.9842912
Encoding Format24bppRgb took 00:00:02.7639744
Encoding Format32bppArgb took 00:00:01.7825632
Encoding Format32bppPArgb took 00:00:02.8541040
Encoding Format32bppRgb took 00:00:01.9227648
Encoding Format48bppRgb took 00:00:03.8855872
Encoding Format64bppArgb took 00:00:03.2747088
Encoding Format64bppPArgb took 00:00:03.5851552
Encoding Format16bppArgb1555 took 00:00:02.8641184
Encoding Format16bppRgb555 took 00:00:02.9742768
Encoding Format16bppRgb565 took 00:00:03.3347952
Encoding Format24bppRgb took 00:00:02.7339312
Encoding Format32bppArgb took 00:00:02.4835712
Encoding Format32bppPArgb took 00:00:03.2747088
Encoding Format32bppRgb took 00:00:03.6452416
Encoding Format48bppRgb took 00:00:04.1659904
Encoding Format64bppArgb took 00:00:02.8440896
Encoding Format64bppPArgb took 00:00:04.0458176
Encoding Format16bppArgb1555 took 00:00:02.7439456
Encoding Format16bppRgb555 took 00:00:03.1445216
Encoding Format16bppRgb565 took 00:00:03.3247808
Encoding Format24bppRgb took 00:00:03.2847232
Encoding Format32bppArgb took 00:00:02.6638304
Encoding Format32bppPArgb took 00:00:02.5136144
Encoding Format32bppRgb took 00:00:03.1745648
Encoding Format48bppRgb took 00:00:02.5737008
Encoding Format64bppArgb took 00:00:03.6352272
Encoding Format64bppPArgb took 00:00:03.7554000
Encoding Format16bppArgb1555 took 00:00:03.2046080
Encoding Format16bppRgb555 took 00:00:02.7339312
Encoding Format16bppRgb565 took 00:00:02.5937296
Encoding Format24bppRgb took 00:00:02.9642624
Encoding Format32bppArgb took 00:00:02.3333552
Encoding Format32bppPArgb took 00:00:02.6237728
Encoding Format32bppRgb took 00:00:02.3133264
Encoding Format48bppRgb took 00:00:03.2246368
Encoding Format64bppArgb took 00:00:03.4149104
Encoding Format64bppPArgb took 00:00:03.3347952
Encoding Format16bppArgb1555 took 00:00:03.5551120
Encoding Format16bppRgb555 took 00:00:02.7239168
Encoding Format16bppRgb565 took 00:00:03.3848672
Encoding Format24bppRgb took 00:00:02.5837152
Encoding Format32bppArgb took 00:00:01.8025920
Encoding Format32bppPArgb took 00:00:02.6538160
Encoding Format32bppRgb took 00:00:03.5050400
Encoding Format48bppRgb took 00:00:03.0343632
Encoding Format64bppArgb took 00:00:02.5536720
Encoding Format64bppPArgb took 00:00:03.0844352
Encoding Format16bppArgb1555 took 00:00:02.4334992
Encoding Format16bppRgb555 took 00:00:02.5036000
Encoding Format16bppRgb565 took 00:00:02.4635424
Encoding Format24bppRgb took 00:00:03.2146224
Encoding Format32bppArgb took 00:00:02.8240608
Encoding Format32bppPArgb took 00:00:03.2346512
Encoding Format32bppRgb took 00:00:02.6137584
Encoding Format48bppRgb took 00:00:03.0143344
Encoding Format64bppArgb took 00:00:02.9342192
Encoding Format64bppPArgb took 00:00:02.5236288
Encoding Format16bppArgb1555 took 00:00:02.4735568
Encoding Format16bppRgb555 took 00:00:02.9742768
Encoding Format16bppRgb565 took 00:00:02.3133264
Encoding Format24bppRgb took 00:00:02.1130384
Encoding Format32bppArgb took 00:00:02.5536720
Encoding Format32bppPArgb took 00:00:02.6838592
Encoding Format32bppRgb took 00:00:02.8340752
Encoding Format48bppRgb took 00:00:03.5651264
Encoding Format64bppArgb took 00:00:03.0443776
Encoding Format64bppPArgb took 00:00:02.6738448
Encoding Format16bppArgb1555 took 00:00:02.2632544
Encoding Format16bppRgb555 took 00:00:03.3748528
Encoding Format16bppRgb565 took 00:00:02.7739888
Encoding Format24bppRgb took 00:00:02.5937296
Encoding Format32bppArgb took 00:00:02.6638304
Encoding Format32bppPArgb took 00:00:03.0043200
Encoding Format32bppRgb took 00:00:02.3433696
Encoding Format48bppRgb took 00:00:02.8741328
Encoding Format64bppArgb took 00:00:02.4535280
Encoding Format64bppPArgb took 00:00:02.9642624
Encoding Format16bppArgb1555 took 00:00:02.9242048
Encoding Format16bppRgb555 took 00:00:02.6738448
Encoding Format16bppRgb565 took 00:00:02.5937296
Encoding Format24bppRgb took 00:00:03.3648384
Encoding Format32bppArgb took 00:00:02.6938736
Encoding Format32bppPArgb took 00:00:02.3233408
Encoding Format32bppRgb took 00:00:03.3548240
Encoding Format48bppRgb took 00:00:03.2046080
Encoding Format64bppArgb took 00:00:02.6037440
Encoding Format64bppPArgb took 00:00:02.4435136
Consolidating all that into a spreadsheet (also attached), it looks like there isn't much difference between the time taken to encode a set of 64bpp bitmaps and the time taken to encode a set of 16bpp bitmaps, so I'm not sure that reducing the colour depth to 8-bit would make any difference.
Here's the consolidated results from the spreadsheet:
Format Sum of Time to encode Average of Time to encode
Format16bppArgb1555 00:00:31 00:00:03
Format16bppRgb555 00:00:29 00:00:03
Format16bppRgb565 00:00:28 00:00:03
Format24bppRgb 00:00:29 00:00:03
Format32bppArgb 00:00:26 00:00:03
Format32bppPArgb 00:00:29 00:00:03
Format32bppRgb 00:00:29 00:00:03
Format48bppRgb 00:00:34 00:00:03
Format64bppArgb 00:00:30 00:00:03
Format64bppPArgb 00:00:32 00:00:03
So, unless anyone can suggest a way to compare encoding times for 8bpp bitmaps with those for 16bpp, 24bpp, etc bitmaps, I think this request is unfeasible.
Simon.