Commits

FennecFox committed cac2a19

Both flags are functioning, lack of style

  • Participants
  • Parent commits cfebe4e

Comments (0)

Files changed (3)

     
     bmp libyanFlag;
     
-    libyanFlag.width = 64 * ENLARGMENT_FACTOR;
+    libyanFlag.width = 64 * ENLARGEMENT_FACTOR;
     libyanFlag.height = 32 * ENLARGEMENT_FACTOR;
     libyanFlag.colorsPerPixel = 3;
     libyanFlag.pixelArraySize = libyanFlag.width * libyanFlag.height *
-    libyanFlag.colorsPerPixel;
+                                libyanFlag.colorsPerPixel;
     libyanFlag.fileSize = HEADER_SIZE * libyanFlag.pixelArraySize;
     
     
         j = 0;
                          
         while (j < libyanFlag.width) {
-            memcpy(pixelArray[curPixel], &greenPixel, 
-                   sizeof (greenPixel)); 
+            /*memcpy(&pixelArray[curPixel], &greenPixel, 
+                   sizeof (greenPixel)); */
+            pixelArray[curPixel] = greenPixel.red;
+            pixelArray[curPixel+1] = greenPixel.green;
+            pixelArray[curPixel+2] = greenPixel.blue;
+            
             j++;
-            curPixel += libyanFlag.colorsPerPixel;
+            //curPixel += sizeof (greenPixel);
+            curPixel += 3;
         }
                          
         i++;
     }
                      
     serveBitmapHeader (libyanFlag, socket);
-    write (socket, pixels, sizeof (pixels));                 
+    write (socket, pixelArray, sizeof (pixelArray));                 
     printf ("Old Libyan flag sent!\n");
    
 }
 
 void serveDenmark (int socket) {
+
+    
+    bmp danishFlag;
+    
+    // Danish flag in ratio of 37:28
+    danishFlag.width = 36 * ENLARGEMENT_FACTOR; //usually 37
+    danishFlag.height = 28 * ENLARGEMENT_FACTOR;
+    danishFlag.colorsPerPixel = 3;
+    danishFlag.pixelArraySize = danishFlag.width * danishFlag.height *
+                                danishFlag.colorsPerPixel;
+    danishFlag.fileSize = HEADER_SIZE * danishFlag.pixelArraySize;
+    
+    
     printf("Danish flag requested...\n");
-    serveHTTPHeader (socket, "200 OK", FILE_SIZE, "image/bmp");
+    serveHTTPHeader (socket, "200 OK", danishFlag.fileSize,
+                     "image/bmp");
+    
     
     pixelColor redPixel;
     pixelColor whitePixel;
     
-    redPixel.red = 255;
+    redPixel.red = 0;
     redPixel.green = 0;
-    redPixel.blue = 0;
+    redPixel.blue = 255;
     
     whitePixel.red = 255;
     whitePixel.green = 255;
     whitePixel.blue = 255;
     
-    char pixelArraylibyanFlag.pixelArraySize];  
+    char pixelArray[danishFlag.pixelArraySize];  
+      
+    int x, y;
+    y = 0;
+    int curPixel = 0;
     
-    int width = 37 * ENLARGEMENT_FACTOR;
-    int height = 28 * ENLARGEMENT_FACTOR;
+    int whiteStripeStart = 12 * ENLARGEMENT_FACTOR;
+    int whiteStripeEnd = 17 * ENLARGEMENT_FACTOR;
     
-    int x, y;
+    
+    while (y < danishFlag.height) {
     x = 0;
-    y = 0;
-    while (y <= height) {
-    
-        while (x <= width) {    
-            if (x > 12 && x < 17) || (y >12 && y < 17) {
-                     
-                memcpy(pixelArray[curPixel], &whitePixel, 
-                       sizeof (whitePixel)); 
+        while (x < danishFlag.width) {    
+            if ((x > whiteStripeStart && x < whiteStripeEnd) || (y >
+                 whiteStripeStart && y < whiteStripeEnd)) {
+                
+                //if(1) {
+                pixelArray[curPixel] = whitePixel.red;
+                pixelArray[curPixel+1] = whitePixel.green;
+                pixelArray[curPixel+2] = whitePixel.blue;
             } else {
-                memcpy(pixelArray[curPixel], &redPixel, 
-                       sizeof (redPixel));
+                pixelArray[curPixel] = redPixel.red;
+                pixelArray[curPixel+1] = redPixel.green;
+                pixelArray[curPixel+2] = redPixel.blue;
 
             }
-            curPixel+= COLORS PER PIXEL;
-            x+=;
+            curPixel+= 3;
+            x++;
         }
     y++;
     }
+    
+    serveBitmapHeader (danishFlag, socket);
+    write (socket, pixelArray, sizeof (pixelArray));                 
+    printf ("Danish flag sent!\n");
+   
+    
 }
 
 void serveBitmapHeader (bmp imageInfo, int socket) {
 #define MAX_HEADER_SIZE         1024
 
 // BMP data
-#define ENLARGEMENT_FACTOR 1
+#define ENLARGEMENT_FACTOR 10
 #define BMP_HEADER_SIZE     14
 #define DIB_HEADER_SIZE     40
 #define HEADER_SIZE         (BMP_HEADER_SIZE + DIB_HEADER_SIZE)
 #include <assert.h>
 #include <unistd.h>
 #include <string.h>
+#include <stdio.h>
 
 #include "flag.h"
 
     char message[MAX_HEADER_SIZE];
     char *format = "HTTP/1.0 %s\n"
         "Content-Type: %s\n"
-        "Content-Length: %o\n" //length in octets
+        "Content-Length: %d\n" //length in octets
         "\n";
   
     snprintf (message, sizeof (message), format, statusMessage,