Coverage Report

Created: 2024-08-18 16:21

/home/liu/actions-runner/_work/ccv/ccv/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
    /* only support 24-bit bmp */
20
0
  } else if (size == 12) {
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
    /* TODO: not finished */
26
0
  }
27
0
  if (width == 0 || height == 0 || bpp == 0)
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) ? type : CCV_8U | ((bpp > 8) ? CCV_C3 : CCV_C1), 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 && CCV_GET_CHANNEL(im->type) == CCV_C1) || (bpp == 24 && CCV_GET_CHANNEL(im->type) == CCV_C3))
36
0
  {
37
0
    if (CCV_GET_CHANNEL(im->type) == CCV_C1)
38
0
    {
39
0
      for (i = 0; i < im->rows; i++)
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->rows; i++)
46
0
      {
47
0
        (void) fread(ptr, 1, im->step, in);
48
0
        for (j = 0; j < im->cols * 3; j += 3)
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 && CCV_GET_CHANNEL(im->type) == CCV_C1)
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->rows; i++)
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->cols; j++, rgb += 3, g++)
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 (bpp == 8 && CCV_GET_CHANNEL(im->type) == CCV_C3) {
72
0
      int bufstep = (im->cols + 3) & -4;
73
0
      unsigned char* buffer = (unsigned char*)alloca(bufstep);
74
0
      for (i = 0; i < im->rows; i++)
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->cols; j++, rgb += 3, g++)
80
0
          rgb[2] = rgb[1] = rgb[0] = *g;
81
0
        ptr -= im->step;
82
0
      }
83
0
    }
84
0
  }
85
0
}