[futurebasic] Re: [FB] Conversion

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : May 1999 : Group Archive : Group : All Groups

From: tedd <tedd@...>
Date: Fri, 21 May 1999 11:00:55 -0400
Mel:

>I don't even know what language this is, but if someone knows what the
>commands do and can let me know, I'd appreciate it. The routine is for
>reading my Sony Mavica (digital camera) preview images (called .411 files).

It's C. The following is my "translation". I'm a bit rusty.

Comments --

>/*
> * 4112bmp.c - Converts a Mavica .411 file into a .bmp file
> *
> * A .411 file contains 64x48 pixels, where each 4 horizontal
> * pixels is represented by Y1,Y2,Y3,Y3,Cb,Cr.  The Cb and Cr
> * values are the same for these 4 pixels.
> *
> * Standard CCIR 601 color conversion is used to convert from
> * Y,Cb,Cr to R,G,B.
> */

--- This includes standard IO and Library functions ---

>#include <stdio.h>
>#include <stdlib.h>

--- Set constants ---

>#define WIDTH  64
>#define HEIGHT 48

--- DIM bmpheader and load it array with stuff---

>unsigned char bmpheader[] = {0x42, 0x4D, 0x36, 0x24, 0x00, 0x00, 0x00, 0x00,
>                             0x00, 0x00, 0x36, 0x00, 0x00, 0x00, 0x28, 0x00,
>                             0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x30, 0x00,
>                             0x00, 0x00, 0x01, 0x00, 0x18, 0x00, 0x00, 0x00,
>                             0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00, 0x00,
>                             0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
>                             0x00, 0x00, 0x00, 0x00, 0x00, 0x00};

--- Set up the main function --- The argc and **argv variables are the
standard first variables into the program -- like a command line input or
from another program. The void is the variable that may return a result.
The start of every function begins with a "void FN (arguments) {" and ends
with a "}". ---

>void main(int argc, char **argv)
>{

--- Open files input and output pointers and set to null ---

>  FILE *inp = NULL;
>  FILE *out = NULL;
>

--- Define a string that is 512 characters long -- There are no strings in
C, as we know them in FB, they are just arrays. ---

>  char name[512];

--- If the variable argc is not equal to 2 then do the stuff in between the
{ and }. The "if {" --> "}" is the C from of our "LONG IF" --> "END IF". If
it is equal to 2, then print "Usage..." .---

>  if (argc != 2)
>  {
>    printf("Usage: 4112bmp mvc-nnnx\n");
>    return;
>  }

--- Copy the string array argv(1) into the string array name. Note,
"strcpy" and other such routines , are routines found in the library
include---

>  strcpy(name, argv[1]);

--- Add the suffix ".411" to the name variable.---

>  strcat(name, ".411");

--- Open a file and name it "rb" and the dump name into it.

>  inp = fopen(name, "rb");

--- Another LONG IF -- THEN statement. The start is the "{" and the other
end is "}". Similar copy and add to and get file as before---

>  if (inp)
>  {
>    strcpy(name, argv[1]);
>    strcat(name, ".bmp");
>    out = fopen(name, "wb");

--- Another LONG IF --

>    if (out)
>    {

--- DIM some integers, i, j, k, l, array y(4), cb, and cr.

>      int i, j, k, y[4], cb, cr;

---Write out the file bmpheader, starting at 1, with the size of the
bmpheader. ---

>      fwrite(bmpheader, 1, sizeof(bmpheader), out);

--- The following is a FOR NEXT loop. In C it's a little different - FOR k
= 0 TO HEIGHT-1 STEP 1 -- is a rough translation. The "NEXT" is the next
"}" which is some way down.

>      for (k=0; k<HEIGHT; k++)
>      {
>        fseek(out, sizeof(bmpheader) + (HEIGHT-k-1) * 3 * WIDTH, SEEK_SET);
>
>        for (j=0; j<WIDTH/4; j++)
>        {

--- The fgetc is a get character function. The rest is pretty
straightforward C. ---

>          y[0] = fgetc(inp);
>          y[1] = fgetc(inp);
>          y[2] = fgetc(inp);
>          y[3] = fgetc(inp);
>          cb   = fgetc(inp) - 128;
>          cr   = fgetc(inp) - 128;
>
>          for (i=0; i<4; i++)
>          {
>            int r, g, b;
>
>            r = y[i]                + 1.40200 * cr;
>            g = y[i] - 0.34414 * cb - 0.71414 * cr;
>            b = y[i] + 1.77200 * cb               ;
>

--- The following is a short version of our IF statement. For exmaple, IF
r<0 THEN r = 0 ---

>            if (r < 0) r = 0;
>            if (g < 0) g = 0;
>            if (b < 0) b = 0;
>
>            if (r > 255) r = 255;
>            if (g > 255) g = 255;
>            if (b > 255) b = 255;
>
>            fputc(b, out);
>            fputc(g, out);
>            fputc(r, out);
>          }
>        }
>      }
>      fclose(out);
>    }
>    fclose(inp);
>  }
>}


tedd

PS: I did a bitmap routine in FB. If I can find it, I'll send it to you.


___________________________________________________________________
<mailto:tedd@...>	               http://sperling.com/