CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Create a bmp

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Guest








Create a bmp
PostPosted: Mon Oct 01, 2007 5:28 am     Reply with quote

Hello,
I'm working with a PIC 18f4550 and a camera and i want to test it.
Is there any library to create a bmp or similar?
thanks
jma_1



Joined: 08 Feb 2005
Posts: 147
Location: Wisconsin

View user's profile Send private message

PostPosted: Tue Oct 02, 2007 11:42 am     Reply with quote

Please be more specific with the question. Do you want to load a file from the camera to the pic? Why?

Bit maps are inherently large. Images like TIF, GIF, JPEG contain image compression and are smaller. What format is the data in on the camera? I believe most digital cameras use JPG by default. Are you trying to convert an image format in the pic? Are you trying to write an image onto an LCD?

Without specifics, I can only reply with questions.

JMA
SherpaDoug



Joined: 07 Sep 2003
Posts: 1640
Location: Cape Cod Mass USA

View user's profile Send private message

PostPosted: Wed Oct 03, 2007 7:48 am     Reply with quote

Here is some code I wrote a long time ago for a PIC to send a small .BMP file to a PC. The project never worked but I THINK this code is OK.
Code:
void Frame_Capture();
int Read_SPI(int Addr);
int Write_SPI(int Addr, int Data);
int MBurst();
int Address;
int j,k;
void Put4(int32 value);  //sends value as 4 bytes

// setup image size
#define width        30
#define height       30


          //Send .BMP bitmapfileheader
          putc('B');       //Fixed 'BM'
          putc('M');
          Put4(2814);       //four bytes of file size = 14+40+30*92=2814=0x00000AFE
          Put4(0);          //2 reserved words 2 bytes each = 0
          Put4(54);       //offset from the beginning of the file to the bitmap data
                           // = 14+40=54=0x00000036
          //Send .BMP bitmapinfoheader
          Put4(40);         //size of bitmapinfoheader
          Put4(width);      //image width in pixels
          Put4(height);     //image height in pixels
          Put4(0x00180001);      //1 plane + 24 bits/pixel * 2^16=1572865
          Put4(0);          //No compression
          Put4(2760);        //size on image in bytes ((30*3)+2)*30
          Put4(15748);      //pixels/meter horiz 400 DPI
          Put4(15748);      //pixels/meter vert 400 DPI
          Put4(0);         //Colors/pixel used
          Put4(0);          //"important" colors????

          //No color table with 24 bits/pixel

          Frame_Capture();

     } //End if(kbhit())
   } //End While(1)
}

void Frame_Capture(){    // Gets a frame and sends in .BMP format
   int row;
   int column;
   int pixel;
   int Addr = 0x40;     //Pixel_Burst register
   int I;

   Write_SPI(0x13, 0);  //Write something to Frame Capture register
   delay_ms(7);         //worst case frame time

   output_low(SPI_NCS);  //Send Address
   for (I=0; I<8; I++) { /* bit-bash 8 bits */
      delay_us(1);
      output_low(SCLK);
      (Addr & 0x80) ? output_float(MOSI) : output_low(MOSI);
      Addr<<=1;         /* Shift out Addr bit by bit */
      delay_us(1);      /* Tsetup, MOSI */
      output_float(SCLK);
   }
   delay_us(50);           /* Tsrad */

   // Read 900 pixel results
   for(row=0; row<height; row++){
      for(column=0; column<width; column++){
         for (I=0; I<8; I++) {   /* read bits */
            delay_us(1);
            output_low(SCLK);
            delay_us(1);
            shift_left(&pixel,1,input(MISO));
            output_float(SCLK);
         }
         pixel <<= 2;    //shift pixels to 8 bits
         putc(pixel), putc(pixel), putc(pixel);
         //for grayscale use same value for RG&B
      }
      putc(0), putc(0);    //need to pad each row to 4 byte boundry
      //30*3+2=92 bytes  assumes 30x30 pixel image
   }
   output_float(SPI_NCS);
}

void Put4(int32 value){  //sends value as 4 bytes
   putc(make8(value, 0));
   putc(make8(value, 1));
   putc(make8(value, 2));
   putc(make8(value, 3));
}

_________________
The search for better is endless. Instead simply find very good and get the job done.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group