// ipgToppm.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"    
#include <stdio.h>    
#include <iostream>    
#include <cv.h>    
#include <highgui.h>    
#include <fstream>    
using namespace std;   
   
void jpg2ppm(char* input, char* output)   
{   
 IplImage* jpg;   
 jpg = cvLoadImage(input, -1);   
 uchar ptrBlue, ptrGreen, ptrRed;   
    
 ofstream pppp;   
 ofstream ppm(output, ios::app | ios::binary);   
 ppm<<"P6"<<endl<<jpg->width<<" "<<jpg->height<<endl<<255<<endl;   
   
 for(int j = 0; j<jpg->height; j++)   
  for(int i = 0; i<jpg->width ; i++)     
  {   
   uchar* temp_ptr = &((uchar*)(jpg->imageData + jpg->widthStep*j))[i*3];   
   ptrBlue = temp_ptr[0];   
   ptrGreen = temp_ptr[1];   
   ptrRed = temp_ptr[2];   
   
   ppm << ptrRed << ptrGreen << ptrBlue;   
  }   
   
 ppm.close();   
}   
   
int _tmain(int argc, _TCHAR* argv[])   
{   
    jpg2ppm("0.jpg","0.ppm");   
    return 0;   
}