16BIT 转为RGB

static void 16BitToRGB(unsigned char *dst,unsigned char *src,bool isGray)
{
        int i, j;
           int min = 9999999, max = 0;
           int total = src->i32Width * src->i32Height;
           unsigned short *irptr = (unsigned short *)src;
            for (i = 0; i < total; i++) {
                 if (min > irptr[i]) {
                        min = irptr[i];
                 }
                  if (max < irptr[i]) {
                       max = irptr[i];
                  }
              }

              if(!isGray)
              {
                   for (i = 0, j = 0; i < total; i++, j += 3) {
                     dst[j] = ((irptr[i] - min) * 255 / (max - min)) ;
                     dst[j + 1] = dst[j];
                     dst[j + 2] = dst[j];
                   }
              }else
              {
                   for (i = 0; i < total; i++) {
                       ds[i] = ((irptr[i] - min) * 255 / (max - min)) ;
                    }
              }
}

你可能感兴趣的:(16BIT 转为RGB)