Coverage Report

Created: 2017-11-12 13:27

/home/liu/buildslave/linux-x64-runtests/build/lib/io/_ccv_io_bmp.inc
Line
Count
Source (jump to first uncovered line)
1
static void _ccv_read_bmp_fd(FILE* in, ccv_dense_matrix_t** x, int type)
2
0
{
3
0
  fseek(in, 10, SEEK_SET);
4
0
  int offset;
5
0
  (void) fread(&offset, 4, 1, in);
6
0
  int size;
7
0
  (void) fread(&size, 4, 1, in);
8
0
  int width = 0, height = 0, bpp = 0, rle_code = 0, clrused = 0;
9
0
  if (size >= 36)
10
0
  {
11
0
    (void) fread(&width, 4, 1, in);
12
0
    (void) fread(&height, 4, 1, in);
13
0
    (void) fread(&bpp, 4, 1, in);
14
0
    bpp = bpp >> 16;
15
0
    (void) fread(&rle_code, 4, 1, in);
16
0
    fseek(in, 12, SEEK_CUR);
17
0
    (void) fread(&clrused, 4, 1, in);
18
0
    fseek(in, size - 36, SEEK_CUR);
19
0
    /* only support 24-bit bmp */
20
0
  } else 
if (0
size == 120
)
{0
21
0
    (void) fread(&width, 4, 1, in);
22
0
    (void) fread(&height, 4, 1, in);
23
0
    (void) fread(&bpp, 4, 1, in);
24
0
    bpp = bpp >> 16;
25
0
    /* TODO: not finished */
26
0
  }
27
0
  if (
width == 0 || 0
height == 00
||
bpp == 00
)
28
0
    return;
29
0
  ccv_dense_matrix_t* im = *x;
30
0
  if (im == 0)
31
0
    
*x = im = ccv_dense_matrix_new(height, width, (type) ? 0
type0
:
CCV_8U | ((bpp > 8) ? 0
CCV_C30
:
CCV_C10
), 0, 0);
32
0
  fseek(in, offset, SEEK_SET);
33
0
  int i, j;
34
0
  unsigned char* ptr = im->data.u8 + (im->rows - 1) * im->step;
35
0
  if (
(bpp == 8 && 0
CCV_GET_CHANNEL0
(im->type) == CCV_C10
) ||
(bpp == 24 && 0
CCV_GET_CHANNEL0
(im->type) == CCV_C30
))
36
0
  {
37
0
    if (
CCV_GET_CHANNEL0
(im->type) == CCV_C10
)
38
0
    {
39
0
      for (i = 0; 
i < im->rows0
;
i++0
)
40
0
      {
41
0
        (void) fread(ptr, 1, im->step, in);
42
0
        ptr -= im->step;
43
0
      }
44
0
    } else {
45
0
      for (i = 0; 
i < im->rows0
;
i++0
)
46
0
      {
47
0
        (void) fread(ptr, 1, im->step, in);
48
0
        for (j = 0; 
j < im->cols * 30
;
j += 30
)
49
0
        {
50
0
          unsigned char t = ptr[j];
51
0
          ptr[j] = ptr[j + 2];
52
0
          ptr[j + 2] = t;
53
0
        }
54
0
        ptr -= im->step;
55
0
      }
56
0
    }
57
0
  } else {
58
0
    if (
bpp == 24 && 0
CCV_GET_CHANNEL0
(im->type) == CCV_C10
)
59
0
    {
60
0
      int bufstep = (im->cols * 3 + 3) & -4;
61
0
      unsigned char* buffer = (unsigned char*)alloca(bufstep);
62
0
      for (i = 0; 
i < im->rows0
;
i++0
)
63
0
      {
64
0
        (void) fread(buffer, 1, bufstep, in);
65
0
        unsigned char* rgb = buffer;
66
0
        unsigned char* g = ptr;
67
0
        for(j = 0; 
j < im->cols0
;
j++, rgb += 3, g++0
)
68
0
          *g = (unsigned char)((rgb[2] * 6969 + rgb[1] * 23434 + rgb[0] * 2365) >> 15);
69
0
        ptr -= im->step;
70
0
      }
71
0
    } else 
if (0
bpp == 8 && 0
CCV_GET_CHANNEL0
(im->type) == CCV_C30
)
{0
72
0
      int bufstep = (im->cols + 3) & -4;
73
0
      unsigned char* buffer = (unsigned char*)alloca(bufstep);
74
0
      for (i = 0; 
i < im->rows0
;
i++0
)
75
0
      {
76
0
        (void) fread(buffer, 1, bufstep, in);
77
0
        unsigned char* g = buffer;
78
0
        unsigned char* rgb = ptr;
79
0
        for(j = 0; 
j < im->cols0
;
j++, rgb += 3, g++0
)
80
0
          rgb[2] = rgb[1] = rgb[0] = *g;
81
0
        ptr -= im->step;
82
0
      }
83
0
    }
84
0
  }
85
0
}