Tuesday, August 5, 2014

Laptop slows down /increased CPU consumption when connected to power

I came across this issue in my dell laptop (linux) where the laptop slowed down as soon as I was putting it to charging. This is generally counter-intuitive where you would expect the performance to increase on connecting it to power. I believe Windows OS even has settings where your laptop can move to high performance if plugged to a power source.

On searching the internet and going through my system logs, I was finally able to resolve the issue.

The solution turned out to be pretty simple:

Open the local.conf file, typically in the location-> /etc/modprobe.d/local.conf

Edit the file and add the following line:

drm_kms_helper poll=N  

You need to save the file and restart your computer.
It worked like magic for me :)

Have come to know from a friend that the problem is not restricted to Linux OS but also extends to windows. We are trying to investigate the issue and will post if we get a solution to it.

Saturday, July 26, 2014

Code for reading bmp image files directly in C/C++

We have discussed the process of reading BMP files in earlier post1 and post2 in detail. You can find the code below:

unsigned char* ReadBMP(char* filename, int* array)


 FILE* img = fopen(filename, "rb");   //read the file

unsigned char header[54];
fread(header, sizeof(unsigned char), 54, img); // read the 54-byte header

   // extract image height and width from header
 int width = *(int*)&header[18];    
 int height = *(int*)&header[22];    
 int padding=0; while (width*3+padding) % 4!=0 padding++;

 int widthnew=width*3+padding;

 unsigned char* data = new unsigned char[widthnew];

 for (int i=0; i<height; i++ ) {                                    

 fread( data, sizeof(unsigned char), widhthnew, img);

 for (int j=0; j<width*3; j+=3)                                

 { //Convert BGR to RGB and store                      

array[i*width+j+0] = data[j+2];                              

array[i*width+j+1] = data[j+1];                              

array[i* width+j+2] = data[j+0]; }}                        

fclose(img); //close the file

Please post incase you face any difficulty in running the codes.