Task 081: An image with 16 million colours

The task here is to generate an interesting image that includes all 24-bit colors! (i.e. it must have a minimum of 16M pixels). You can generate an image via a function of your choosing (according to specified parameters), or you can use some other bitmap as template. However, you must in any case ensure that the output will have a total of 2^24 different RGB colors!

Overview

The template application 081fullcolor from the repository grcis serves as the basis of this project. This is a simple application in which it is possible to load an input image, enter a text parameter, and generate an output image. Within the application, the method Generator.Recompute() is responsible for calculating the output image. This method must be re-written, and the relevant location in the source Generator.cs indicated via comment brackets:

  // !!!{{
  // !!!}}

Screenshot

Technical details

The function Generator.Recompute() has the following parameters:
  • Bitmap input optional input image, may be null
  • out Bitmap output - output image in which the result will be stored
  • bool fast - a flag to enable fast, unsafe memory access. DO NOT USE THIS!
  • string param - an optional string parameter that you can use to pass parameters to the algorithm you implement (the template implementation expects the image dimensions, separated by commas, here)

After generating the image, the application automatically calculates the number of colours in the result image, and outputs information about this in the bottom right corner of the window. In addition to the calculation time, it informs you how many colours you are still missing to reach the full amount of 2^24 colours. If you did everything right, and all the colours are there, it just writes "Ok" instead of a number.

In order to keep the code nice and organised, please modify the initialisation procedure InitParams() if you are using a text parameter to control output appearance. This function is called once during startup of the application, and currently reads the image dimensions from the string.

When handing in this assignment, please send us only the modified source file Generator.cs! We do not accept entire Visual Studio projects!
On the first line of the source file, please place your name in a comment.

Programming details

The template implementation showcases some interesting technical details:
  1. creation of an output image instance for the pixel format Format24bppRgb
  2. quick access to binary data pixels - via the method Bitmap.LockBits() and unsafe blocks for direct memory access
  3. calculations in a separate thread - inter-thread control via the variable Form1.cont (if this is set to false the algorithm should terminate as soon as possible)
  4. Drag & Drop of input images - the input file can be transferred via mouse input from any Windows application that supports D&D.

What to hand in

You have to send us the file Generator.cs.
In the first line, put your name in a comment
In the procedure InitParams() you can read any parameters you need.
If you use this string parameter param as input, do not forget to define and describe its semantics.
If you are using images to drive the input, and if you have achieved a nice result with a particular input image, you can also send us that image. But please watch the size of the mail attachment, and use some web upload service if it is too large (Dropbox, GoogleDrive, uloz.to), and just send us the URL instead.

Deadline

Hand in the assignment until: 15. 11. 2015

Points

Basic: 6 points, plus a potential bonus of 4 points for using an input image to drive the algorithm (it has to work with any input image you load and yield a sensible result), and a further possible bonus of 5 points (innovation, aesthetics, speed, ...).

Project

Visual Studio project: 081fullcolor.

Source file

Modify and hand in the source file: Generator.cs
As a comment in the first line, please include your name!


Copyright (C) 2015 J. Pelikán & A. Wilkie, last change: 2019-05-09 17:52:59 +0200 (Thu, 09 May 2019)