CpSc 101, Fall 2015 Lab7: Image File Creation

Similar documents
Representation of image data

CpSc 1111 Lab 4 Formatting and Flow Control

CpSc 1111 Lab 5 Formatting and Flow Control

CpSc 111 Lab 3 Integer Variables, Mathematical Operations, & Redirection

CpSc 1010, Fall 2014 Lab 10: Command-Line Parameters (Week of 10/27/2014)

CpSc 1011 Lab 3 Integer Variables, Mathematical Operations, & Redirection

CpSc 1111 Lab 4 Part a Flow Control, Branching, and Formatting

Graphics Overview ECE2893. Lecture 19. ECE2893 Graphics Overview Spring / 15

CpSc 1111 Lab 9 2-D Arrays

Color Customer Display

CpSc 1011 Lab 4 Formatting and Flow Control Windchill Temps

Week 5: Files and Streams

CpSc 1011 Lab 5 Conditional Statements, Loops, ASCII code, and Redirecting Input Characters and Hurricanes

Programming Project 1

CpSc 111 Lab 5 Conditional Statements, Loops, the Math Library, and Redirecting Input

Effective Programming in C and UNIX Lab 6 Image Manipulation with BMP Images Due Date: Sunday April 3rd, 2011 by 11:59pm

An Introduction to Video Compression in C/C++ Fore June

Setting Up the Fotosizer Software

255, 255, 0 0, 255, 255 XHTML:

CP SC 4040/6040 Computer Graphics Images. Joshua Levine

ECE 3331, Dr. Hebert, Summer-3, 2016 HW 11 Hardcopy HW due Tues 07/19 Program due Sunday 07/17. Problem 1. Section 10.6, Exercise 3.

Lab 2.2. Out: 9 February 2005

Project #1 Seam Carving

Introduction to Computer Science (I1100) Data Storage

MCS 2514 Fall 2012 Programming Assignment 3 Image Processing Pointers, Class & Dynamic Data Due: Nov 25, 11:59 pm.

COS 116 The Computational Universe Laboratory 10: Computer Graphics

C introduction: part 1

CPSC 217 Assignment 3

BMP file format. Contents. Pixel storage. The BMP file format, sometimes called bitmap. or DIB file format (for device-independent

This is not yellow. Image Files - Center for Graphics and Geometric Computing, Technion 2

Day 1: Introduction to MATLAB and Colorizing Images CURIE Academy 2015: Computational Photography Sign-Off Sheet

Bridging Graphics. Lori Scarlatos, January 2007

Chapter 3. Texture mapping. Learning Goals: Assignment Lab 3: Implement a single program, which fulfills the requirements:

Data Representation From 0s and 1s to images CPSC 101

Manual Bitmap Fixture v

Ascii Art. CS 1301 Individual Homework 7 Ascii Art Due: Monday April 4 th, before 11:55pm Out of 100 points

Common File Formats. Need a standard to store images Raster data Photos Synthetic renderings. Vector Graphic Illustrations Fonts

Standard File Formats

Slide Set 8. for ENCM 339 Fall 2017 Section 01. Steve Norman, PhD, PEng

CS 315 Data Structures Fall Figure 1

CSC 101: Lab Manual#11 Programming Turtle Graphics in Python Lab due date: 5:00pm, day after lab session

SlickEdit Gadgets. SlickEdit Gadgets

Digital Signage Content Creation Guidelines

Lecture 8: Structs & File I/O

ClipArt and Image Files

The following is a table that shows the storage requirements of each data type and format:

CMPT 165 Graphics Part 2. Nov 3 rd, 2015

SFPL Reference Manual

CS 112 Project Assignment: Visual Password

Lecture 03 Bits, Bytes and Data Types

1/25/2018. ECE 220: Computer Systems & Programming. Write Output Using printf. Use Backslash to Include Special ASCII Characters

Customisation and production of Badges. Getting started with I-Color System Basic Light

To start, open or build a simple solid model. The bracket from a previous exercise will be used for demonstration purposes.

Binghamton University. CS-211 Fall Input and Output. Streams and Stream IO

CpSc 1111 Lab 6 Conditional Statements, Loops, the Math Library, and Random Numbers What s the Point?

Graphics File Formats

Binghamton University. CS-211 Fall Input and Output. Streams and Stream IO

Lesson 3 Creating and Using Graphics

1. Introduction to the OpenCV library

BMP file format - Wikipedia

Digital Image Fundamentals. Prof. George Wolberg Dept. of Computer Science City College of New York

PIXEL SPREADSHEET USER MANUAL April 2011

CS 160: Lecture 10. Professor John Canny Spring 2004 Feb 25 2/25/2004 1

Warping & Blending AP

C-Programming. CSC209: Software Tools and Systems Programming. Paul Vrbik. University of Toronto Mississauga

Lecture 3. More About C

Software Requirements Specification BRIC. for. Requirements for Version Prepared by Panagiotis Vasileiadis

Parallel Image Processing

CS103L PA4. March 25, 2018

Problem Solving: Storyboards for User Interaction

Introduction: The Unix shell and C programming

CISC 1115 (Science Section) Brooklyn College Professor Langsam. Assignment #5

CpSc 1111 Lab 1 Introduction to Unix Systems, Editors, and C

PRINCIPLES OF OPERATING SYSTEMS

CS 100 Python commands, computing concepts, and algorithmic approaches for final Fall 2015

3Picture Fundamentals

Format Type Support Thru. vector (with embedded bitmaps)

OptimiData. JPEG2000 Software Development Kit for C/C++ Reference Manual. Version 1.6. from

Title and Modify Page Properties

Input / Output Functions

CSE 351: The Hardware/Software Interface. Section 2 Integer representations, two s complement, and bitwise operators

6.096 Introduction to C++ January (IAP) 2009

SU 2017 May 11/16 LAB 2: Character and integer literals, number systems, character arrays manipulation, relational operator

EEN118 LAB TWO. 1. A Five-Pointed Star.

How to Prepare Your Cards for Press Using Scribus

Press-Ready Cookbook Page Guidelines

Lesson 11: Visualization

Cropping an Image for the Web

Introduction to C. CS2023 Winter 2004

CP SC 4040/6040 Computer Graphics Images. Joshua Levine

CMPT 102 Introduction to Scientific Computer Programming. Input and Output. Your first program

Objectives. Learn how to read and write from memory using C-pointers Implement the very first TOS functions

Binghamton University. CS-211 Fall Syntax. What the Compiler needs to understand your program

CS 220: Introduction to Parallel Computing. Beginning C. Lecture 2

CS16 Exam #1 7/17/ Minutes 100 Points total

Creating a PDF/X-1a from InDesign

Lab 09 - Virtual Memory

Fall Harris & Harris

Introduction to the MODx Manager

An Introduction to Digital Video Data Compression in Java. Fore June

Transcription:

CpSc 101, Fall 2015 Lab7: Image File Creation Goals Construct a C language program that will produce images of the flags of Poland, Netherland, and Italy. Image files Images (e.g. digital photos) consist of a rectangular array of discrete picture elements called pixels. An image consisting of 200 rows of 300 columns (or pixels per row) contains 300 x 200 = 60,000 individual pixels. The height of the image in pixels is the number of pixel rows, and the width is the number of columns, or pixels in each row. A color image requires 3 bytes per pixel or 180,000 total bytes! The Portable PixMap (.ppm) format is a particularly simple way used to encode a rectangular image (picture) as uncompressed data file. Other well known formats include JPEG (.jpg), TIFF (.tif), GIF (.gif), bitmap (.bmp), and PNG (.png) The.ppm file can viewed with a number of tools including display and gimp. MS Windows systems have no built-in.ppm viewer. Several freeware viewers are available on the web though. See (www.gimp.org/downloads) for downloading gimp onto your own laptop. You ll see a link for use on a Mac at the top of that page. For Windows, click on Show Other Downloads, which is about 1/3 of the way down (right below Fink ). Another image viewer/editor is irfanview, though there is no version for Macs. See (www.irfanview.com) for more information.

PPM file format ppm files: ppm is a very simple image file format. A ppm image consists of two components: 1. The header: the header contains 1) a label to identify the file format as a color ppm file ("P6"), 2) the width of the image in pixels, 3) the height of the image in pixels and 4) the maximum pixel value (always 255). 5) the header ends with a single \n newline character 2. Binary image data: the data consists of unsigned char (eight-bits == one-byte) binary values defining the color of each pixel. Example ppm header: The header of a color image of 800 pixels wide and 600 pixels high has the following format: P6 800 600 255 Then the very next line after the 255 is where the pixel data begins. You can open the.ppm file using vim or some other editor, and you ll be able to see and makes sense of the header; but since the pixel data is binary, the rest of the file after the header will look like a bunch of weird, unreadable characters. Pixel data format: each pixel consists of 3 one-byte values of type unsigned char the first three bytes of image data in the.ppm file define the color of the pixel in the upper left corner of the image the last three bytes in the file define the color of the pixel in the lower right pixel values defining each horizontal row of the image are adjacent NO spaces, tabs, newlines may be embedded in the file.

red/green/blue image encoding this format is called RGB. The three bytes of each pixel represent the color intensities of the: red component green component blue component (255, 0, 0) is bright red (0, 255, 0) is bright green (0, 0, 255) is bright blue Colors are additive (255, 255, 0) = red + green = bright yellow (255, 0, 255) = red + blue = magenta (purple) (0, 255, 255) = blue + green = cyan (turquoise) (255, 255, 255) = red + green + blue = white when red == green == blue (lower than 255), a gray color is produced; for example, (25, 25, 25) would be a light shade of gray, and (200, 200, 200) would be a darker shade of gray Writing a pixel value The %c format code tells fprintf() NOT to convert the value being printed to ASCII format. Since pixel values are binary, the %c code must be used. The following statement can be used to write a red pixel: fprintf(stdout, "%c%c%c", 255, 0, 0); NO spaces or newlines are permitted in the format string!!

Assignment Write a program called lab7.c that is capable of creating an image of the flags of Poland, Netherland, and Italy. Two integer values should be read from the standard input: country_code: 0 - Poland 1 - Netherland 2 - Italy width: The width of the flag in pixels. You should use the proper colors as defined in Wikipedia based upon a google search for "Flag of Poland", etc. Google rgb colors to find the r, g, & b values for each color that you will need for the above flags. You should use the proper ratio of height to width as specified by proportion in Wikipedia to compute the height of the image you produce. Poland: https://en.wikipedia.org/wiki/flag_of_poland (RGB: white (255, 255, 255), red (255, 0, 0)) Netherland: https://en.wikipedia.org/wiki/flag_of_the_netherlands Italy: https://en.wikipedia.org/wiki/flag_of_italy Use the make_pixel() function provided below: void make_pixel ( int r, // red intensity int g, // green intensity int b ) // blue intensity { fprintf(stdout, "%c%c%c", r, g, b); } Use the make_ppm_header() function provided below: void make_ppm_header (int width, int height) { fprintf(stdout, "P6\n"); fprintf(stdout, "%d %d %d\n", width, height, 255); }

Use the following main() function. #include <stdio.h> int main() { int width; int country_code; // prompt user to enter width and country_code of chosen flag /* Read image dimensions and pixel color */ fscanf(stdin, "%d %d", &country_code, &width); fprintf(stderr, "Making country %d with width %d \n", country_code, width); /* Write the image data */ make_ppm_image(country_code, width); } return(0); You will need to write the function make_ppm_image(country_code, width) to create the chosen flag. You can do this one of two ways: 1. use an if-else, or switch, statement based on the country code and put the code to create the flags within each part of the if-else (or switch) 2. use an if-else, or switch, statement to call one of 3 other functions depending on which country code was sent in (this is preferable because this keeps the make_ppm_image() function smaller by breaking each task up and putting the code for each flag into other separate, smaller functions) Whichever way you choose to do it, work on the Poland one first (because it is the easier one of the three); make sure it works before continuing on to Netherland s flag; make sure that one works, then do the last one. You should always break up your programs into small parts, doing each one incrementally, compiling in between each step before continuing on to the next step.

Producing and viewing the image 1. Write the C program to produce the image. In your program, you will have statements to write the header information. You are provided with the function HINTS: called make_ppm_header() which will write the header information to stdout. 2. Then your program will include statements to write the r, g, b pixel data to the file. You are provided with the function called make_pixel() to which you will send the r, g, b values. This function will be called from another function that you will be writing. 3. Don t forget to put all your prototypes at the top of your lab7.c file underneath the #include statement(s). 4. You will compile your program as you normally compile C programs: gcc -Wall -g lab7.c 5. When you run the program, you will redirect the output to a specified ppm filename. For example, if you are going to test the Poland flag, you would type the following:./a.out > poland.ppm 6. You will be prompted to enter the width and the country code for the flag, and then the.ppm file will be created. 7. To view the image, you can use one of the methods mentioned above on page 1. You will probably end up using nested for loops. You may utilize whatever lecture notes were provided to you. There are different ways of producing the images. For example: some lecture notes show examples of the nested for loops to control the rows and columns (the outer for loop is for each row; and the inner for loop(s) produce the pixels along the row). Other notes may show examples of using the modulus operator with an if statement to determine the row/column that you are currently looking at. Either approach is fine. Your program should compile WITHOUT warnings with gcc -Wall -g lab7.c Turn In Work Show your TA that you completed the assignment. Then turn in your lab7.c program using the handin page at http://handin.cs.clemson.edu