Thread: Write .ucf image into .ppm format

  1. #1
    Registered User
    Join Date
    Aug 2012
    Posts
    78

    Write .ucf image into .ppm format

    Hi there!

    I'm dealing with a very interesting problem today.
    I'm given an image in .ucf format (Universal Communication Format), which is read by the following code snippet:
    Code:
    /*********************************************************/
    /* UCFReadPic.c                                          */
    /*********************************************************/
    
    PIC UCFReadPic(infile)
    FILE *infile;
    {
       PIC temp;
       unsigned char byte1,byte2,byte3,byte4;
    
       /* getting Type from image data */
    
       fread(&byte1,sizeof(BYTE),1,infile);
       fread(&byte2,sizeof(BYTE),1,infile);
       fread(&byte3,sizeof(BYTE),1,infile);
       fread(&byte4,sizeof(BYTE),1,infile);
       temp.type= byte1*16777216+byte2*65536+byte3*256+byte4;
       switch (temp.type)
       {
          case 0xF10F:
          case 0xF200:
          case 0xF201:
          case 0xF204:
          case 0x0000:
          {  
    
            fread(&byte1,sizeof(BYTE),1,infile);
            fread(&byte2,sizeof(BYTE),1,infile);
            fread(&byte3,sizeof(BYTE),1,infile);
            fread(&byte4,sizeof(BYTE),1,infile);
            temp.maxX= byte1*16777216+byte2*65536+byte3*256+byte4;
            fread(&byte1,sizeof(BYTE),1,infile);
            fread(&byte2,sizeof(BYTE),1,infile);
            fread(&byte3,sizeof(BYTE),1,infile);
            fread(&byte4,sizeof(BYTE),1,infile);
            temp.maxY= byte1*16777216+byte2*65536+byte3*256+byte4;
            break;
          }
          case 0x8000:
          case 0x8001:
          case 0xB003:
          default  :
          {
            printf("****** Unknown image type *****\n");
            exit(1);
          }
       }
    
       if((temp.image=(BYTE*)calloc(temp.maxX*temp.maxY, sizeof(BYTE)))==NULL)
       {
          printf("***** NOT enough memory *****\n");
          exit(1);
       }
    
       fread(temp.image,sizeof(BYTE),temp.maxX * temp.maxY,infile);
       return(temp);
    }
    Unfortunately though, I am unable to open the .ucf format in any editor (Photoshop, GIMP, etc). Thus, I would like to build in a function, which writes this image into .ppm format (or any other format, which is readable by an editor).

    Any ideas of how to proceed?

    Thanks!
    Last edited by in_ship; 08-19-2012 at 07:16 AM.

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Hmm... I notice rather outdated syntax:
    Code:
    PIC UCFReadPic(infile)
    FILE *infile;
    {
    I suggest that you change the above code to:
    Code:
    PIC UCFReadPic(FILE *infile)
    {
    Anyway, you need to find out what is this PIC type and how to write it "into .ppm format (or any other format, which is readable by an editor)". Once you know that, it is a matter of calling this function then doing that with the return value.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Aug 2012
    Posts
    78
    Quote Originally Posted by laserlight View Post
    Hmm... I notice rather outdated syntax:
    Code:
    PIC UCFReadPic(infile)
    FILE *infile;
    {
    I suggest that you change the above code to:
    Code:
    PIC UCFReadPic(FILE *infile)
    {
    Thanks for the remark - I just modified it accordingly!

    I still have no idea what ucf is - I opened the image using 'vi' and the output says nothing to me at all.

    ^@^@^@^@^@^@^@<80>^@^@^@<80>úúúúúúúúúúúúúúúúúúúúúú úúúúúúúúúúúúúúúúúúúúúúú;d~<92>¢°¼ÆÐ×Þäéîñôö÷øø÷öôñ îéäÞ×ÏƼ°¢<91>}d9úúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúú úúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúú úúúúúúú3`{<8f> ®ºÄÎÖÜâèìïòôööööôòïìçâÜÕÍĺ..<9f><8f>z_úúúúúúúúúúú úúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúú úúúúúúúúúúúúúúúúúúúúúúúúúúúúúúú[w<8c><9d>«·ÂËÓÚàåêíðòóôôóòðíêåàÚÓËÁ·ª<9c><8b>vYúúú úúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúú úúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúSq<87><99>§ ´¿ÈÑØÞãçëîðñòòñðîëçãÝ×ÐȾ³§<98><86>pQúúúúúúúúúúúúú úúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúú úúúúúúúúúúúúúúúúúúúúúúúúúúúúúIk<82><94>¤±¼ÆÎÕÜáåéì îïððïîìéåàÛÕÍÅ»°£<93><80>hDúúúúúúúúúúúúúúúúúúúúúúú úúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúú úúúúúúúúúúúúúúúúúúú;c|<90> ..¹ÃËÓÙßãçêìîîîîìêçãÞÙÒ˸¬<9e><8e>z`úúúúúúúúúúúúú úúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúú úúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúZv<8b><9b>ª¶ÀÉÑ×Ýâæ éëìííìëèåáÝ×ÐÈ¿µ¨<9a><89>sUúúúúúúúúúúúúúúúúúúúúúúú úúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúú úúúúúúúúúúúúúúúúúúúúúNn<85><97>¦³¾ÇÏÖÜáåèêìììëêçäà ÛÕÎƼ±¤<95><83>kGúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúú úúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúú úúúúúúúúúúú>f^?<92>¢°»ÅÍÕÛàäçêëììëéçãßÚÔÌĺ®¡<90>| búúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúú úúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúú\x< 8d><9e>..¹ÃÌÓÚßãçéëììëéçãßÙÓË·«<9d><8b>uWúúúúúúúú úúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúú úúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúOq<88><9a>ª¶ ÁËÓÙßãçêëììëéçãÞÙÒÊÀµ¨<99><86>mGúúúúúúúúúúúúúúúúúú úúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúú úúúúúúúúúúúúúúúúúúúúúúúúúúúú>h<82><96>§´ÀÊÒÙßäçêìí íìêçãÞØÑÉ¿³¥<94><80>dúúúúúúúúúúúúúúúúúúúúúúúúúúúúú úúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúú úúúúúúúúúúúúúúúúúúú^|<92>¤²¾ÉÒÙßäèëíîîíëèäßØÑȽ±¢< 90>yZúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúú úúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúú úúúSu<8d> °½ÈÑÙßåéìîïïîìèäßØÐǼ¯<9f><8b>sMúúúúúúúúúúúúúúúúúú úúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúú úúúúúúúúúúúúúúúúúúúúúúúúúúúúúúDn<89><9d>®¼ÇÑÙàåêíï ððïíéåàÙÐÆ»..<9c><87>kúúúúúúúúúúúúúúúúúúúúúúúúúúúú úúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúú úúúúúúúúúúúúúúúúúúúúúúf<84><9a>¬ºÇÑÚáæëîðññðîëæàÙРƹ«<99><82>cúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúú úúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúú úúúúúúúúúúúú]^?<97>ª¹ÆÑÚáçìïòóóòïìçáÙП©<95>}Zúúúúúúúúúúúúúúúú úúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúú úúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúTy<93>¨¸ÆÑÚâèíñó ôôóñíèâÚÐÅ·§<92>xPúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúú úúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúú úúúúúúúúúúúúúúúúúúHt<90>¦·ÅÑÛãéîòôööôòîéâÚÐŶ¥<8f> sDúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúú úúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúú úú<8d>¤¶ÅÑÛãêïóö÷÷öóïêãÛÑĵ£<8d>oúúúúúúúúúúúúúúúúúúú úúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúú úúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúk<8b>¢µÄÑÛäëðô÷øø ÷ôðëäÛÑĵ¢<8a>júúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúú úúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúú úúúúúúúúúúúúúúúúúg<89>¡´ÄÑÛäëñõ÷ùù÷õñëäÛÑÄ´¡<88>gú úúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúú úúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúú úd<87> ´ÃÑÛäëñõøùùøõñëäÛÑó <87>dúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúú úúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúú úúúúúúúc<86><9f>³ÃÐÛäìñõøùùøõñìäÛÐó<9f><86>cúúúúú úúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúú úúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúc<8 6><9f>³ÃÐÛäëñõøùùøõñëäÛÐó<9f><86>cúúúúúúúúúúúúúúú úúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúú úúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúd<87><9f>³ÃÐÛ äëñõ÷ùù÷õñëäÛÐó<9f><86>dúúúúúúúúúúúúúúúúúúúúúúúúú úúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúú úúúúúúúúúúúúúúúúúúúúúúúúúúúf<88> ³ÃÐÛãêðô÷øø÷ôðêãÛÐó <87>fúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúú úúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúú úúúúúúúj<8a>¡´ÃÐÚãêïóö÷÷öóïêãÚÐô¡<89>iúúúúúúúúúúú úúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúú úúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúú6n<8c>£µÃÐ ÚâéîòôõõôòîèâÙÏô¢<8b>m3úúúúúúúúúúúúúúúúúúúúúúúúúú úúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúú úúúúúúúúúúúúúúúúúúúúúúúúFs<8f>¤µÄÏÙáçíðóôôóðìçáÙÏà µ£<8e>rDúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúú úúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúú úúúúúúúúRx<92>¦¶ÄÏØàæëîñòòñîëæàØÎõ¥<91>wPúúúúúúúú úúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúú úúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúú\}<95>¨· ÄÏ×ßåéíïððïìéäÞ×Îö§<94>|Zúúúúúúúúúúúúúúúúúúúúúúúú úúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúú úúúúúúúúúúúúúúúúúúúúúúúúúúf<83><98>ª¸ÄÎÖÝãçëíîîíêç ãÝÖÍ÷¨<97><81>cúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúú úúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúú úúúúúúúúúúúúúúúGn<88><9c>¬¹ÄÎÕÜáåèêëëêèåáÛÕÍøª<9a ><86>kCúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúú úúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúú úúúúúVv<8d><9f>..ºÄÍÔÛàãæèééèæãßÚÔÌø¬<9d><8a>sRúú úúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúú úúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúb}<9 1>¡¯ºÄÌÓÙÞáäæççæäáÝØÒËù..<9f><8f>z^úúúúúúúúúúúúúú úúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúú úúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúJl<83><95>¤°»ÄÌÒØ ÜàâäääãâßÛ×ÑËú¯¢<93><80>hEúúúúúúúúúúúúúúúúúúúúúúú úúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúú úúúúúúúúúúúúúúúúúúúúúúúYt<89><99>¦²¼ÄËÑÖÚÞàáââáàÝÚ ÕÐÊú°¤<96><86>qUúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúú úúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúú úúúúúúúúúúúúCe|<8e><9c>©³¼ÄËÐÕÙÜÞßààßÞÛØÔÏÉû±¦<9a ><8b>xa=úúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúú úúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúú úúTo<82><92><9f>«´½ÄÊÏÔ×ÚÜÝÞÞÝÜÙ×ÓÎÉ»²¨<9d><8f>^? kOúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúú úúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúú@aw<8 8><96>¢¬µ½ÄÉÎÒÖØÚÛÜÜÛÚØÕÒÍÈ»³ª <93><85>s]:úúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúú úúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúSk~<8d> <9a>¥®¶½ÄÉÍÑÔ×ÙÚÚÚÚØÖÔÐÌȼ´¬¢<97><8a>zgMúúúúúúúúú úúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúú úúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúB`t<84><91><9d>§°· ¾ÃÈÍÐÓÕ×ØÙÙØ×ÕÒÏÌǼµ®¥<9a><8f><81>p[<úúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúú úúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúSj{<89><9 5> ©±¸¾ÃÈÌÏÒÔÖ××××ÕÔÑÏËǽ¶¯§<9e><93><86>xeNúúúúúúúúú úúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúú úúúúúúúúúúúúúúúúúúúúúúúúúúúúúúE_r<81><8e><99>£«²¹¾ ÃÈËÏÑÓÕÕÖÖÕÔÓÐÎËǽ·±© <97><8b>~n[?úúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúú úúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúú3Uiz<87><92> <9c>¥..´º¿ÄÈËÎÐÒÓÔÕÕÔÓÒÐÍÊǾ¸²«£<9a><90><84>veP,ú úúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúú úúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúI`r<80><8c><96> <9f>§¯µº¿ÄÇËÍÐÑÓÓÔÔÓÒÑÏÍÊÆþ¹³..¥<9d><94><89>}n\Dú úúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúú úúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúú<Wjy<85><90><9a> ¢ª°¶»ÀÄÇÊÍÏÑÒÓÓÓÓÒÐÏÌÊÇÿºµ®¨ <97><8e><82>ufR6úúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúú úúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúú$ Nbr^?<8a><94><9d>¥¬²·¼ÀÄÈÊÍÏÐÒÒÓÓÒÑÐÎÌÊÇÿ»¶°ª£<9b ><92><88>|n^H^]úúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúú úúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúCZky<85><8f><98> §®³¹½ÁÅÈËÍÏÐÑÒÒÒÒÑÐÎÌÊÇÄÀ¼·²¬¥<9e><96><8c><82>vgU= úúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúú úúúúúúúúúúúúúúúúúúúúúúúúúúúúúúú6Rds^?<8a><93><9b>£ ª°µº¾ÂÅÈËÍÏÐÑÒÒÒÒÑÐÎÌÊÈÄÁ½¹´®¨¡<99><91><87>|o`M/úúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúú úúúúúúúúúúúúúúúúúúúúúúúúúúúúúúH]ly<85><8e><97><9f>¦¬²·»¿ÃÆÉËÍÏÐÑÒÒÒÒÑÐÏÍËÈžºµ°ª¤ <9d><95><8c><82>viXCúúúúúúúúúúúúúúúúúúúúúúúúúúúúúú úúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúú> Uft^?<8a><93><9b>¢¨®´¸½ÀÄÇÊÌÎÏÑÒÒÒÒÒÑÐÏÍËÉÆÿ»·².. § <99><90><87>|pbQ8úúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúú úúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúú0M_nz< 85><8e><97><9e>¥«°µº¾ÂÅÈÊÍÎÐÑÒÓÓÓÒÒÑÐÎÌÊÇÄÁ½¹´¯©£< 9c><94><8c><82>wk[H*úúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúú úúúúúúúúúúúúúúúúúúúúúúúúúúúúDXhu<80><8a><93><9a>¡¨ ..³·¼ÀÃÆÉËÍÏÑÒÓÓÓÓÓÒÒÐÏÍËÈÅ¿»¶±¬¦ <98><90><87>}rdT?úúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúú úúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúú9Qbp{<85 ><8e><97><9e>¥«°µ¹¾ÁÅÈÊÌÎÐÒÓÓÔÔÔÔÓÒÑÐÎÌÊÇÄÀ¼¸´¯©£< 9c><95><8c><83>xl^L3úúúúúúúúúúúúúúúúúúúúúúúúúúúúúú úúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúú(H[jv<81><8a><93><9a>¡¨..²·¼¿ÃÆÉÌÎÐÑÓÔÔÕÕÕÕÔÓÒÑÏÍËÈÅ ¾º¶±¬¦ <99><91><88>~sgWD"úúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúú úúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúú>Tdq|<86>< 8f><97><9e>¥«°µº¾ÁÅÈËÍÏÑÓÔÕÖÖÖÖÖÕÕÔÒÑÏÌÊÇÄÀ½¸´¯©£< 9c><95><8d><84>zn`P9úúúúúúúúúúúúúúúúúúúúúúúúúúúúúú úúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúú1L]kw<82><8b><93><9b>¢¨®³¸¼ÀÃÇÊÌÏÑÒÔÕÖ××ØØ××ÖÕÔÒÐÎÌ
    Last edited by in_ship; 08-19-2012 at 07:25 AM.

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by in_ship
    I still have no idea what ucf is
    You could always ask the person who gave you this file, and it may indeed be useful to know what it is. However, my point is that if the given function works as advertised, then you don't need to worry about what is the file format; you need to worry about what is the PIC type and how to use it.

    Quote Originally Posted by in_ship
    I opened the image using 'vi' and the output says nothing to me at all.
    Binary file format. You can get a sense that that is so just by looking at the implementation of UCFReadPic.
    Last edited by laserlight; 08-19-2012 at 07:57 AM.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    Registered User kryptkat's Avatar
    Join Date
    Dec 2002
    Posts
    638
    .ucf reader by epson
    All Programmable Technologies from Xilinx Inc.

    Xilinx: Downloads

    epson salts again with 6.2 gb prog ! just to view a pic. meow !
    <whiteflags> You foolishly believe in people and this feeling must be crushed.

    i have gotta get me a bunch of monsantos gmos == genetically modified orgasms .

  6. #6
    Registered User
    Join Date
    May 2012
    Location
    Arizona, USA
    Posts
    948
    I would start by looking up the ppm file format, if you're not already familiar with it. Then I would see that the PIC image structure has everything needed to write a ppm image: maxX, maxY, and image. I would write all of those pieces of information to the ppm file and then see if the image looks correct when it's opened in an image viewer.

    By the way, the ucf format appears to have a header consisting of type, width, and height, each a four-byte big-endian value. The header is then followed by the image data in an 8-bit pixel format. I'm not familiar with the ucf format, so I can't say whether those 8 bits represent grayscale, indexed, or "true color" data. Grayscale would be the easiest to write to a ppm file. Just write it in the pgm format, which is almost the same as ppm, except it takes grayscale pixel data instead of color pixel data.

  7. #7
    Registered User
    Join Date
    Aug 2012
    Posts
    78
    Quote Originally Posted by christop View Post
    I would start by looking up the ppm file format, if you're not already familiar with it. Then I would see that the PIC image structure has everything needed to write a ppm image: maxX, maxY, and image. I would write all of those pieces of information to the ppm file and then see if the image looks correct when it's opened in an image viewer.
    I this these three values can indeed be read. The code snippet above contains the following lines at the end:
    Code:
    fread(temp.image,sizeof(BYTE),temp.maxX * temp.maxY,infile);
    return(temp);
    I have been reading about the PPM format.
    So, ideally, this is the snippet I would have to add to the preexisting lines of code:

    Code:
    fread(temp.image,sizeof(BYTE),temp.maxX * temp.maxY,infile);
    
    -------- new code --------
    // open new image file
    FILE *fp = fopen("ppmimage.ppm", "wb");
    
    if (!fp) {
       fprintf(stderr, "Unable to open file '%s'\n", filename);
       exit(1);
    }
    
    // write the header for pgm image format
    fprintf(fp, "P6\n");
    
    
    //image size
    fprintf(fp, "%d %d\n",temp.maxX, temp.maxY);
    
    // rgb component depth
    fprintf(fp, "%d\n", 255);
    
    // write image
    fwrite(temp.image, sizeof(BYTE), temp.maxX *temp.maxY, fp);
    
    fclose(fp);
     
    -------- eoc --------
    
    
    return(temp);
    Last edited by in_ship; 08-19-2012 at 01:15 PM.

  8. #8
    Registered User
    Join Date
    May 2012
    Location
    Arizona, USA
    Posts
    948
    The ppm format expects three bytes for each pixel (width * height * 3 bytes for a complete image), but you're writing only one byte per pixel (width * height bytes). As I mentioned in my last post, you could write it as a pgm file instead of ppm. Simply use P5 instead of P6 in the header.

    I also wouldn't add code to the existing function (a function should do only one thing and do it well). It already returns a pointer to a PIC structure, so you can just as easily write a ppm file after calling UCFReadPIC.

  9. #9
    Registered User
    Join Date
    Aug 2012
    Posts
    78
    Quote Originally Posted by christop View Post
    The ppm format expects three bytes for each pixel (width * height * 3 bytes for a complete image), but you're writing only one byte per pixel (width * height bytes). As I mentioned in my last post, you could write it as a pgm file instead of ppm. Simply use P5 instead of P6 in the header.

    I also wouldn't add code to the existing function (a function should do only one thing and do it well). It already returns a pointer to a PIC structure, so you can just as easily write a ppm file after calling UCFReadPIC.
    I do have a pgm version of the file already. I would like to see whether pgm and ppm match or not.

    So, after heeding your advice; here goes my implementation

    Code:
    invocation from main.c
    PIC pic1 = UCFReadPic(infile);
    PPMWritePic(pic1);    
    
    PPMWritePic.c
    void PPMWritePic(PIC temp)
    
    {
        
        // open new image file
        FILE *fp = fopen("ppmimage.ppm", "wb");
     
        if (!fp)
        {
               fprintf(stderr, "Unable to open file '%s'\n", filename);
               exit(1);
        }
     
        // write the header for ppm image format
        fprintf(fp, "P6\n");
      
        // image size
        fprintf(fp, "%d %d\n",temp.maxX, temp.maxY);
     
        // rgb component depth
        fprintf(fp, "%d\n", 255);
     
        // write image
        fwrite(temp.image, sizeof(BYTE), 3*temp.maxX*temp.maxY, fp);
     
        fclose(fp);
    
    }
    The resulting image contains 3x the original image (back-to-back) and the lower portion of it is just entirely black.

    Here's the vim output:
    vim ppmimage.ppm

    P6
    128 128
    255
    @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @
    "ppmimage.ppm" [noeol][converted] 7L, 68617C
    Any ideas of what could have gone wrong here?

  10. #10
    Registered User
    Join Date
    May 2012
    Location
    Arizona, USA
    Posts
    948
    Quote Originally Posted by in_ship View Post
    Code:
        // write image
        fwrite(temp.image, sizeof(BYTE), 3*temp.maxX*temp.maxY, fp);
    Yes. The memory at temp.image has only maxX*maxY bytes allocated to it, but you're writing 3 times that much to the ppm file. When I said that ppm takes 3 bytes per pixel, I meant that you would have to convert each byte in the original image to 3 bytes, whether it's by repeating a byte 3 times (easy), using a byte as an index into a colormap (which you would have to build beforehand), or splitting up the byte into 3 separate components (you would have to know how many bits each component has). It depends on what pixel format the UCF image uses, which you will need to find out. Start by repeating each byte 3 times (not by writing the complete image 3 times) because it's the easiest, and probably the most likely format used by UCF.

  11. #11
    Registered User
    Join Date
    Aug 2012
    Posts
    78
    Thanks for your help, christop!
    The issue has been resolved now!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How to write image data to binary PGM file format(P5)?
    By tommy_chai in forum C Programming
    Replies: 6
    Last Post: 11-03-2007, 10:52 PM
  2. What image format to use?
    By Kennedy in forum Tech Board
    Replies: 21
    Last Post: 10-16-2006, 08:10 AM
  3. Convert Pdf to Image format!
    By Dilmerv in forum C# Programming
    Replies: 4
    Last Post: 05-22-2006, 10:31 PM
  4. Reading text in an Image format
    By loko in forum C Programming
    Replies: 0
    Last Post: 09-29-2005, 06:38 PM
  5. image format
    By linuxdude in forum Game Programming
    Replies: 5
    Last Post: 08-09-2004, 09:31 AM