MyroC Project
Package to control Scribbler 2 robots via Bluetooth
Data Structures | Typedefs | Functions
MyroC-image-file.c File Reference

Implementation file for saving/loading jpeg images to/from a file. More...

#include "MyroC.h"
#include "MyroC-utilities.h"
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <fcntl.h>
#include <unistd.h>
#include <jpeglib.h>
#include <setjmp.h>
Include dependency graph for MyroC-image-file.c:

Data Structures

struct  my_error_mgr
 

Typedefs

typedef struct my_error_mgrmy_error_ptr
 

Functions

void my_error_exit (j_common_ptr cinfo)
 
void rSavePicture (Picture *pic, char *filename)
 Save a Picture to a .jpeg. More...
 
Picture rLoadPicture (char *filename)
 Load a picture from a .jpeg file. More...
 

Detailed Description

Implementation file for saving/loading jpeg images to/from a file.

Revision History

Version 1.0 based on a C++ package by April O'Neill, David Cowden, Dilan Ustek, Erik Opavsky, and Henry M. Walker

Developers of the C package for Linux: Creators Version 2.0 (C functions for utilities,general,sensors,movement): Spencer Liberto Dilan Ustek Jordan Yuan Henry M. Walker Contributors Version 2.2-2.3: (C functions for image processing) Anita DeWitt Jason Liu Nick Knoebber Vasilisa Bashlovkina Revision for Version 2.4: (image row/column made to match matrix notation) Henry M. Walker

Revisions for Version 3.0 Henry M. Walker

C ported to Macintosh Linux/Mac differences required for connections — otherwise same code OpenGL used to display images, replacing ImageMagick same [new] code used for both Linux and Macintosh 1 process for robot control 1 process needed for each titled window (not each image, as in 2.2-2.4) Blocking options (negative duration parameter) utilize separate thread timer MyroC implementation files organized by user function as follows:

Revisions for Version 3.1 Henry M. Walker

Picture struct and image functions revised to allow 192 by 256 images from origial Fluke camera 266 x 427 low-resolution images from Fluke 2 (high-resolution (800 x 1280) too large for more than 2-4 variables on run-time stack) storage , retrieval, and display of any images up to 266 x 427

This program and all MyroC software is licensed under the Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License. Details available at http://creativecommons.org/licenses/by-nc-sa/3.0/us/

Revisions for Version 3.2 Henry M. Walker

Practical range of rBeep duration identified as <= 3.0014 seconds Image display and processing resolves several matters and adds functionality function rDisplayPicture completely rewritten over time OpenGL rountines had encountered troubles on Linux, specifically glutHideWindow() hid images, but could not be restored, with difficulties depending on the graphics card on Mac, High Sierra generated compile warnings and restricted threads that could display images function rDisplayImageProcessingErrors added function rWaitTimedImageDisplay updated substantially

Revisions for Version 3.3 Henry M. Walker

MyroC ported to Windows 10, in addition to Linux and Mac OS X Additional refinements text parameter for rGetLightTxt expanded to "Middle" as well as "Center"

This program and all MyroC software is licensed under the Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License. Details may be found at http://creativecommons.org/licenses/by-nc-sa/3.0/us/

                    implementation overview *************************

indicates functions implemented in this file

0. LOW-LEVEL UTILITY (defined in MyroC-utilities.h implemented in MyroC-utilities.c) rSend rReceive rSetOpeningExchange rSetBluetoothEcho rSetEchoMode rCheckHardwareVersionSetCameraSize

  1. GENERAL (mostly MyroC-general.c) 2. SENSOR (MyroC-sensors.c) rConnect (* MyroC-connect.c) a.Scribbler Sensors rDisconnect (* MyroC-connect.c) rGetLightsAll rSetConnection rGetLightTxt rFinishProcessing rGetIRAll rSetVolume rGetIRTxt rBeep rGetLine rBeep2 rSetName b.Fluke Sensors rGetName rGetObstacleAll rSetForwardness rGetObstacleTxt rGetForwardness rGetBrightAll rSetLEDFront rGetBrightTxt rSetLEDBack rSetIRPower rGetBattery rGetStall
  Note:
     MyroC-connect requires special
     knowledge of a Mac or Linux
     environment, yielding two versions:
     MyroC-connect-mac.c
     MyroC-connect-linux.c
  1. MOVEMENT (MyroC-movement.c) 4. PICTURES (files as indicated) rTurnLeft rGetCameraSize (MyroC-camera.c) rTurnRight rTakePicture (MyroC-camera.c) rTurnSpeed rDisplayPicture (MyroC-display.c) rForward rWaitTimedImageDisplay(MyroC-display.c) rFastForward > rSavePicture (MyroC-image-file.c) rBackward > rLoadPicture (MyroC-image-file.c) rMotors rStop rHardStop

Function Documentation

◆ rLoadPicture()

Picture rLoadPicture ( char *  filename)

Load a picture from a .jpeg file.

Parameters
filenamethe name of the file
Precondition
file must exist
file extension must be .jpeg or .jpg
file must be no larger than 266 by 427
Returns
locally-declared Picture
Postcondition
calling program should store returned Picture in a previously-declared struct

◆ rSavePicture()

void rSavePicture ( Picture pic,
char *  filename 
)

Save a Picture to a .jpeg.

This section contains functions for taking and manipulating images All images are constrained with height <= 266 and width <= 427

images from robot cameras have varying sizes, depending on the Fluke images for the original Fluke are 192 (height) by 256 (width) low-resolution images for the Fluke 2 are 266 by 427 high-resolution images for the fluke 2 are 800 by 1280 (not supported)

Bluetooth communication constrains the time required for the Fluke to take a picture Typical times: original fluke: 2- 4 seconds Fluke 2 (low res): 4- 6 seconds Fluke 2 (high res): 25-30 seconds

BASED ON TIMINGS AND MEMORY CONSIDERATIONS, Myro C ALLOWS ONLY LOW RESOLUTION IMAGES

the Picture struct allows direct access to Pixel data Pictures can be saved and loaded as .jpeg files

Note
Following standard mathematical convention for a 2D matrix, all references to a pixel are given within an array as [row][col]
user-defined images may have any size, as long as height <= 266 and width <= 427
Following standard mathematical convention for a 2D matrix, all references to a pixel are given within an array as [row][col]
Warning
The Picture struct is defined to be sufficiently large to store several low-resolution camera images (340756 bytes each) Experimentally, an array of up to 94 (not 95) Pictures is allowed However, the display of images requires that image data be copied, so display of many images may not work If a program hangs when working with Picture variables, the issue may involve lack of space on the runtime stack. To utilize a modest number of Pictures, use "ulimit -s" command, as needed, in a terminal window For example, ulimit -s 32768 Sizes above 32768 may not be allowed in Linux or Mac OS X Save a Picture to a .jpeg
Parameters
picpointer to an RGB picture struct from Scribbler 2 camera
filenamethe name of the file
Precondition
filename ends with .jpeg or .jpg.
Postcondition
If the file does not exist, a new file will be created.
If the file exists, the file will be overwritten.

this code is a slightly modified version of write_JPEG_file(char *, int) from example.c from the libjpeg.v8d library directory.