Subversion Repositories HelenOS

Rev

Rev 2787 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2787 Rev 4377
Line 90... Line 90...
90
    unsigned int width, height;
90
    unsigned int width, height;
91
    unsigned int maxcolor;
91
    unsigned int maxcolor;
92
    int i;
92
    int i;
93
    unsigned int color;
93
    unsigned int color;
94
    unsigned int coef;
94
    unsigned int coef;
95
 
95
   
96
    /* Read magic */
96
    /* Read magic */
97
    if (data[0] != 'P' || data[1] != '6')
97
    if ((data[0] != 'P') || (data[1] != '6'))
98
        return EINVAL;
98
        return EINVAL;
99
 
99
   
100
    data+=2;
100
    data += 2;
101
    skip_whitespace(&data);
101
    skip_whitespace(&data);
102
    read_num(&data, &width);
102
    read_num(&data, &width);
103
    skip_whitespace(&data);
103
    skip_whitespace(&data);
104
    read_num(&data,&height);
104
    read_num(&data, &height);
105
    skip_whitespace(&data);
105
    skip_whitespace(&data);
106
    read_num(&data,&maxcolor);
106
    read_num(&data, &maxcolor);
107
    data++;
107
    data++;
108
 
108
   
109
    if (maxcolor == 0 || maxcolor > 255 || width * height > datasz) {
109
    if ((maxcolor == 0) || (maxcolor > 255) || (width * height > datasz))
110
        return EINVAL;
110
        return EINVAL;
111
    }
111
   
112
    coef = 255 / maxcolor;
112
    coef = 255 / maxcolor;
113
    if (coef * maxcolor > 255)
113
    if (coef * maxcolor > 255)
114
        coef -= 1;
114
        coef -= 1;
115
   
115
   
116
    for (i = 0; i < width * height; i++) {
116
    for (i = 0; i < width * height; i++) {
Line 123... Line 123...
123
            data[2] * coef;
123
            data[2] * coef;
124
       
124
       
125
        (*putpixel)(vport, sx + (i % width), sy + (i / width), color);
125
        (*putpixel)(vport, sx + (i % width), sy + (i / width), color);
126
        data += 3;
126
        data += 3;
127
    }
127
    }
128
 
128
   
129
    return 0;
129
    return 0;
130
}
130
}