c - Converting pixels in this code -


i seem have hit stump in small programming assignment. (please don't tell me how entire problem; want know how set every byte red).

the code have following:

#include <stdio.h> #include <stdlib.h> #include <cs50.h>  #include "bmp.h"  int main(int argc, char* argv[]) {     // ensure proper usage     //if (argc != 3)     //{     //   printf("usage: copy infile outfile\n");     //    return 1;     //}      // remember filenames     //char* infile = argv[1];     //char* outfile = argv[2];     char* infile = getstring();     char* outfile = getstring();      // open input file      file* inptr = fopen(infile, "r");     if (inptr == null)     {         printf("could not open %s.\n", infile);         return 2;     }      // open output file     file* outptr = fopen(outfile, "w");     if (outptr == null)     {         fclose(inptr);         fprintf(stderr, "could not create %s.\n", outfile);         return 3;     }      // read infile's bitmapfileheader     bitmapfileheader bf;     fread(&bf, sizeof(bitmapfileheader), 1, inptr);      // read infile's bitmapinfoheader     bitmapinfoheader bi;     fread(&bi, sizeof(bitmapinfoheader), 1, inptr);      // ensure infile (likely) 24-bit uncompressed bmp 4.0     if (bf.bftype != 0x4d42 || bf.bfoffbits != 54 || bi.bisize != 40 ||          bi.bibitcount != 24 || bi.bicompression != 0)     {         fclose(outptr);         fclose(inptr);         fprintf(stderr, "unsupported file format.\n");         return 4;     }      // write outfile's bitmapfileheader     fwrite(&bf, sizeof(bitmapfileheader), 1, outptr);      // write outfile's bitmapinfoheader     fwrite(&bi, sizeof(bitmapinfoheader), 1, outptr);      // determine padding scanlines     int padding =  (4 - (bi.biwidth * sizeof(rgbtriple)) % 4) % 4;      // iterate on infile's scanlines     (int = 0, biheight = abs(bi.biheight); < biheight; i++)     {         // iterate on pixels in scanline         (int j = 0; j < bi.biwidth; j++)         {             // temporary storage             rgbtriple triple;              // read rgb triple infile             fread(&triple, sizeof(rgbtriple), 1, inptr);             triple.rgbtred = 'ff'             // write rgb triple outfile             fwrite(&triple, sizeof(rgbtriple), 1, outptr);         }          // skip on padding, if         fseek(inptr, padding, seek_cur);          // add (to demonstrate how)         (int k = 0; k < padding; k++)             fputc(0x00, outptr);     }      // close infile     fclose(inptr);      // close outfile     fclose(outptr);      // that's folks     return 0; } 

and bmp.h is

#include <stdint.h>  /**  * common data types   *  * data types in section aliases c/c++   * primitive data types.  *  * adapted http://msdn.microsoft.com/en-us/library/cc230309(prot.10).aspx.  * see http://en.wikipedia.org/wiki/stdint.h more on stdint.h.  */ typedef uint8_t  byte; typedef uint32_t dword; typedef int32_t  long; typedef uint16_t word;  /**  * bitmapfileheader  *  * bitmapfileheader structure contains information type, size,  * , layout of file contains dib [device-independent bitmap].  *  * adapted http://msdn.microsoft.com/en-us/library/dd183374(vs.85).aspx.  */ typedef struct  {      word   bftype;      dword  bfsize;      word   bfreserved1;      word   bfreserved2;      dword  bfoffbits;  } __attribute__((__packed__))  bitmapfileheader;   /**  * bitmapinfoheader  *  * bitmapinfoheader structure contains information   * dimensions , color format of dib [device-independent bitmap].  *  * adapted http://msdn.microsoft.com/en-us/library/dd183376(vs.85).aspx.  */ typedef struct {     dword  bisize;      long   biwidth;      long   biheight;      word   biplanes;      word   bibitcount;      dword  bicompression;      dword  bisizeimage;      long   bixpelspermeter;      long   biypelspermeter;      dword  biclrused;      dword  biclrimportant;  } __attribute__((__packed__)) bitmapinfoheader;   /**  * rgbtriple  *  * structure describes color consisting of relative intensities of  * red, green, , blue.  *  * adapted http://msdn.microsoft.com/en-us/library/aa922590.aspx.  */ typedef struct {     byte  rgbtblue;     byte  rgbtgreen;     byte  rgbtred; } __attribute__((__packed__)) rgbtriple; 

note: don't have code getstring, please assume return string char*.

the problem have trying convert every pixel's rgbtred value extreme red; have no idea how it. please provide me how can convert rgbtred?

update: puzzle

welcome tudor mansion. host, mr. john boddy, has met untimely end—he's victim of foul play. win game, must determine whodunit.

unfortunately (though more unfortunately mr. boddy), evidence have 24-bit bmp file called clue.bmp, pictured below, mr. boddy whipped on computer in final moments. hidden among file's red "noise" drawing of whodunit.

enter image description here

you long ago threw away piece of red plastic childhood solve mystery you, , must attack computer scientist instead.

remove single quotes. 'ff' implementation-defined (or undefined) integer, 0xff hexadecimal constant.

the line question should read

            triple.rgbtred = 0xff; 

Comments

Popular posts from this blog

android - getbluetoothservice() called with no bluetoothmanagercallback -

sql - ASP.NET SqlDataSource, like on SelectCommand -

ios - Undefined symbols for architecture armv7: "_OBJC_CLASS_$_SSZipArchive" -