- /* grayscale or RGB */
- case 1:
- case 3:
- {
- byte *pixels = img->pixels;
- for (uns r = img->rows; r--; )
- {
- jpeg_read_scanlines(&i->cinfo, (JSAMPLE **)&pixels, 1);
- pixels += img->row_size;
- }
- }
- break;
- /* grayscale with alpha */
- case 2:
- {
- byte buf[img->cols], *src;
-# define IMAGE_WALK_PREFIX(x) walk_##x
-# define IMAGE_WALK_INLINE
-# define IMAGE_WALK_IMAGE img
-# define IMAGE_WALK_UNROLL 4
-# define IMAGE_WALK_COL_STEP 2
-# define IMAGE_WALK_DO_ROW_START do{ src = buf; jpeg_read_scanlines(&i->cinfo, (JSAMPLE **)&src, 1); }while(0)
-# define IMAGE_WALK_DO_STEP do{ walk_pos[0] = *src++; walk_pos[1] = 255; }while(0)
-# include "images/image-walk.h"
- }
- break;
- /* RGBA or aligned RGB */
- case 4:
- {
- byte buf[img->cols * 3], *src;
-# define IMAGE_WALK_PREFIX(x) walk_##x
-# define IMAGE_WALK_INLINE
-# define IMAGE_WALK_IMAGE img
-# define IMAGE_WALK_UNROLL 4
-# define IMAGE_WALK_COL_STEP 4
-# define IMAGE_WALK_DO_ROW_START do{ src = buf; jpeg_read_scanlines(&i->cinfo, (JSAMPLE **)&src, 1); }while(0)
-# define IMAGE_WALK_DO_STEP do{ *(u32 *)walk_pos = *(u32 *)src; walk_pos[3] = 255; src += 3; }while(0)
-# include "images/image-walk.h"
+ byte *pixels = img->pixels;
+ for (uns r = img->rows; r--; )
+ {
+ jpeg_read_scanlines(&i->cinfo, (JSAMPLE **)&pixels, 1);
+ pixels += img->row_size;
+ }
+ }
+ else
+ {
+ switch (img->pixel_size)
+ {
+ case 2: /* Grayscale -> Grayscale+Alpha */
+ {
+ ASSERT(i->cinfo.output_components == 1);
+ byte buf[img->cols], *src;
+# define IMAGE_WALK_PREFIX(x) walk_##x
+# define IMAGE_WALK_INLINE
+# define IMAGE_WALK_IMAGE img
+# define IMAGE_WALK_UNROLL 4
+# define IMAGE_WALK_COL_STEP 2
+# define IMAGE_WALK_DO_ROW_START do{ src = buf; jpeg_read_scanlines(&i->cinfo, (JSAMPLE **)&src, 1); }while(0)
+# define IMAGE_WALK_DO_STEP do{ walk_pos[0] = *src++; walk_pos[1] = 255; }while(0)
+# include <images/image-walk.h>
+ }
+ break;
+ case 4: /* * -> *+Alpha or aligned * */
+ {
+ ASSERT(i->cinfo.output_components == 3);
+ byte buf[img->cols * 3], *src;
+# define IMAGE_WALK_PREFIX(x) walk_##x
+# define IMAGE_WALK_INLINE
+# define IMAGE_WALK_IMAGE img
+# define IMAGE_WALK_UNROLL 4
+# define IMAGE_WALK_COL_STEP 4
+# define IMAGE_WALK_DO_ROW_START do{ src = buf; jpeg_read_scanlines(&i->cinfo, (JSAMPLE **)&src, 1); }while(0)
+# define IMAGE_WALK_DO_STEP do{ *(u32 *)walk_pos = *(u32 *)src; walk_pos[3] = 255; src += 3; }while(0)
+# include <images/image-walk.h>
+ }
+ break;
+ default:
+ ASSERT(0);