[futurebasic] Re: Conversion

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

From: Brian Victor <bhv1@...>
Date: Fri, 21 May 1999 08:22:01 -0400
>I don't even know what language this is, but if someone knows what the

I'll give it a shot... (It's C, FWIW.)

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

Not necessary in FB.

>#define WIDTH  64
>#define HEIGHT 48

_width  = 64
_height = 48

>unsigned char bmpheader[] = {0x42, 0x4D, 0x36, 0x24, 0x00, 0x00, 0x00, 0x00,
[snip]

This shouldn't be necessary if you're just writing to the screen and not to
a bmp file.  It's an array containing the header information for the bmp
file, in hex.

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

main is the starting point for C programs.

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

imp and out are pointers to files.  I've done very little work with files
in FB, and I don't have my manuals in front of me, so I don't know what the
proper translation would be.  This just DIM's whatever variables you use to
keep track of the files.

>  char name[512];

DIM name$.512

512 is overkill.  The Mac filesystem won't currently take more than 32(?)
anyway, so your standard 255 char string should work fine.  (Especially
since 512 char strings won't work in FB. ;)

>  if (argc != 2)
[snip]

UNIXy stuff.  argc and argv take arguments to the program, in this case the
name of the file to be translated.  Use a dialog box instead.

>  strcpy(name, argv[1]);

name$ = (name of file returned from file open dialog.  sorry I don't have
the syntax.)

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

Open the file name$.

>  if (inp)

If the open succeeded...

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

This deals with the output file.  Not necessary if you won't have one.

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

DIM i%, j%, k%, y%(4), cb%, cr%

In C you can declare variables at the beginning of any block.  You'll
probably have to declare these at the beginning of the function instead.

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

This outputs the aforementioned header information to the output file.
Again not necessary for screen output.

>      for (k=0; k<HEIGHT; k++)

FOR k%=0 to _height-1

>      {
>        fseek(out, sizeof(bmpheader) + (HEIGHT-k-1) * 3 * WIDTH, SEEK_SET);

Seeks the appropriate place in the output file.  Not necessary.

>        for (j=0; j<WIDTH/4; j++)

FOR j%=0 to (_width/4)-1

>        {
>          y[0] = fgetc(inp);
>          y[1] = fgetc(inp);
>          y[2] = fgetc(inp);
>          y[3] = fgetc(inp);
>          cb   = fgetc(inp) - 128;
>          cr   = fgetc(inp) - 128;

fgetc reads a single char from the input file.  This doesn't convert quite
as prettily as some... basically, these six lines read in six characters
from the file, assigning them to y%(0), y%(1), y%(2), y%(3), cb%, and cr%,
respectively.  Note that cb% and cr% are assiged the value of the input
minus 128.

>          for (i=0; i<4; i++)

FOR i=0 to 3

>          {
>            int r, g, b;

DIM r%,g%,b%

>            r = y[i]                + 1.40200 * cr;
>            g = y[i] - 0.34414 * cb - 0.71414 * cr;
>            b = y[i] + 1.77200 * cb               ;

r% = y%(i) + 1.40200 * cr%
g% = y%(i) - 0.34414 * cb% - 0.71414 * cr%
b% = y%(i) + 1.77200 * cb%

>            if (r < 0) r = 0;
[snip 5 lines]

IF r%<0 then r% = 0

etc.

>            fputc(b, out);
>            fputc(g, out);
>            fputc(r, out);

Output rgb values to bmp file.  In your case, throw them into a LONG COLOR
and smack 'em up on the screen.

>          }

NEXT i

>        }

NEXT j

>      }

NEXT k

>      fclose(out);

Close output file

>    }

END IF   ' out

>    fclose(inp);

Close input file

>  }

END IF   ' inp

>}

END FN


Hope this helps.  If you have any questions I'll try to answer them.  (I'm
on digest mode, though, so if you want a faster answer, cc me in a reply.)

>Mel Patrick

Brian