\hypertarget{_myro_c-image-file_8c}{}\section{Myro\+C-\/image-\/file.c File Reference}
\label{_myro_c-image-file_8c}\index{Myro\+C-\/image-\/file.\+c@{Myro\+C-\/image-\/file.\+c}}


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


{\ttfamily \#include \char`\"{}Myro\+C.\+h\char`\"{}}\newline
{\ttfamily \#include \char`\"{}Myro\+C-\/utilities.\+h\char`\"{}}\newline
{\ttfamily \#include $<$stdio.\+h$>$}\newline
{\ttfamily \#include $<$stdlib.\+h$>$}\newline
{\ttfamily \#include $<$ctype.\+h$>$}\newline
{\ttfamily \#include $<$string.\+h$>$}\newline
{\ttfamily \#include $<$fcntl.\+h$>$}\newline
{\ttfamily \#include $<$unistd.\+h$>$}\newline
{\ttfamily \#include $<$jpeglib.\+h$>$}\newline
{\ttfamily \#include $<$setjmp.\+h$>$}\newline
Include dependency graph for Myro\+C-\/image-\/file.c\+:\nopagebreak
\begin{figure}[H]
\begin{center}
\leavevmode
\includegraphics[width=350pt]{_myro_c-image-file_8c__incl}
\end{center}
\end{figure}
\subsection*{Data Structures}
\begin{DoxyCompactItemize}
\item 
struct \hyperlink{structmy__error__mgr}{my\+\_\+error\+\_\+mgr}
\end{DoxyCompactItemize}
\subsection*{Typedefs}
\begin{DoxyCompactItemize}
\item 
\mbox{\Hypertarget{_myro_c-image-file_8c_a17bb08c876725fc3608be875c457af71}\label{_myro_c-image-file_8c_a17bb08c876725fc3608be875c457af71}} 
typedef struct \hyperlink{structmy__error__mgr}{my\+\_\+error\+\_\+mgr} $\ast$ {\bfseries my\+\_\+error\+\_\+ptr}
\end{DoxyCompactItemize}
\subsection*{Functions}
\begin{DoxyCompactItemize}
\item 
\mbox{\Hypertarget{_myro_c-image-file_8c_a4de3ecd55401b56f0cdd500fac21c655}\label{_myro_c-image-file_8c_a4de3ecd55401b56f0cdd500fac21c655}} 
void {\bfseries my\+\_\+error\+\_\+exit} (j\+\_\+common\+\_\+ptr cinfo)
\item 
void \hyperlink{_myro_c-image-file_8c_ace59c91f90d0bd811b3df1d3ddcf14e3}{r\+Save\+Picture} (\hyperlink{struct_picture}{Picture} $\ast$pic, char $\ast$filename)
\begin{DoxyCompactList}\small\item\em Save a \hyperlink{struct_picture}{Picture} to a .jpeg. \end{DoxyCompactList}\item 
\hyperlink{struct_picture}{Picture} \hyperlink{_myro_c-image-file_8c_a22bed206f3ae7563a116be255e91906e}{r\+Load\+Picture} (char $\ast$filename)
\begin{DoxyCompactList}\small\item\em Load a picture from a .jpeg file. \end{DoxyCompactList}\end{DoxyCompactItemize}


\subsection{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\textquotesingle{}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 De\+Witt 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 Open\+GL used to display images, replacing Image\+Magick same \mbox{[}new\mbox{]} 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

\hyperlink{struct_picture}{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 \href{http://creativecommons.org/licenses/by-nc-sa/3.0/us/}{\tt http\+://creativecommons.\+org/licenses/by-\/nc-\/sa/3.\+0/us/}

Revisions for Version 3.\+2 Henry M. Walker

Practical range of r\+Beep duration identified as $<$= 3.\+0014 seconds Image display and processing resolves several matters and adds functionality function r\+Display\+Picture completely rewritten over time Open\+GL rountines had encountered troubles on Linux, specifically glut\+Hide\+Window() 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 r\+Display\+Image\+Processing\+Errors added function r\+Wait\+Timed\+Image\+Display 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 r\+Get\+Light\+Txt expanded to \char`\"{}\+Middle\char`\"{} as well as \char`\"{}\+Center\char`\"{}

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 \href{http://creativecommons.org/licenses/by-nc-sa/3.0/us/}{\tt http\+://creativecommons.\+org/licenses/by-\/nc-\/sa/3.\+0/us/}

\begin{DoxyVerb}                    implementation overview *************************
\end{DoxyVerb}


\begin{quote}
indicates functions implemented in this file \end{quote}


0. L\+O\+W-\/\+L\+E\+V\+EL U\+T\+I\+L\+I\+TY (defined in \hyperlink{_myro_c-utilities_8h_source}{Myro\+C-\/utilities.\+h} implemented in Myro\+C-\/utilities.\+c) r\+Send r\+Receive r\+Set\+Opening\+Exchange r\+Set\+Bluetooth\+Echo r\+Set\+Echo\+Mode r\+Check\+Hardware\+Version\+Set\+Camera\+Size


\begin{DoxyEnumerate}
\item G\+E\+N\+E\+R\+AL (mostly Myro\+C-\/general.\+c) 2. S\+E\+N\+S\+OR (Myro\+C-\/sensors.\+c) r\+Connect ($\ast$ Myro\+C-\/connect.\+c) a.\+Scribbler Sensors r\+Disconnect ($\ast$ Myro\+C-\/connect.\+c) r\+Get\+Lights\+All r\+Set\+Connection r\+Get\+Light\+Txt r\+Finish\+Processing r\+Get\+I\+R\+All r\+Set\+Volume r\+Get\+I\+R\+Txt r\+Beep r\+Get\+Line r\+Beep2 r\+Set\+Name b.\+Fluke Sensors r\+Get\+Name r\+Get\+Obstacle\+All r\+Set\+Forwardness r\+Get\+Obstacle\+Txt r\+Get\+Forwardness r\+Get\+Bright\+All r\+Set\+L\+E\+D\+Front r\+Get\+Bright\+Txt r\+Set\+L\+E\+D\+Back r\+Set\+I\+R\+Power r\+Get\+Battery r\+Get\+Stall
\end{DoxyEnumerate}

\begin{DoxyVerb}  Note:
     MyroC-connect requires special
     knowledge of a Mac or Linux
     environment, yielding two versions:
     MyroC-connect-mac.c
     MyroC-connect-linux.c
\end{DoxyVerb}



\begin{DoxyEnumerate}
\item M\+O\+V\+E\+M\+E\+NT (Myro\+C-\/movement.\+c) 4. P\+I\+C\+T\+U\+R\+ES (files as indicated) r\+Turn\+Left r\+Get\+Camera\+Size (Myro\+C-\/camera.\+c) r\+Turn\+Right r\+Take\+Picture (Myro\+C-\/camera.\+c) r\+Turn\+Speed r\+Display\+Picture (Myro\+C-\/display.\+c) r\+Forward r\+Wait\+Timed\+Image\+Display(Myro\+C-\/display.\+c) r\+Fast\+Forward $>$ r\+Save\+Picture (\hyperlink{_myro_c-image-file_8c}{Myro\+C-\/image-\/file.\+c}) r\+Backward $>$ r\+Load\+Picture (\hyperlink{_myro_c-image-file_8c}{Myro\+C-\/image-\/file.\+c}) r\+Motors r\+Stop r\+Hard\+Stop 
\end{DoxyEnumerate}

\subsection{Function Documentation}
\mbox{\Hypertarget{_myro_c-image-file_8c_a22bed206f3ae7563a116be255e91906e}\label{_myro_c-image-file_8c_a22bed206f3ae7563a116be255e91906e}} 
\index{Myro\+C-\/image-\/file.\+c@{Myro\+C-\/image-\/file.\+c}!r\+Load\+Picture@{r\+Load\+Picture}}
\index{r\+Load\+Picture@{r\+Load\+Picture}!Myro\+C-\/image-\/file.\+c@{Myro\+C-\/image-\/file.\+c}}
\subsubsection{\texorpdfstring{r\+Load\+Picture()}{rLoadPicture()}}
{\footnotesize\ttfamily \hyperlink{struct_picture}{Picture} r\+Load\+Picture (\begin{DoxyParamCaption}\item[{char $\ast$}]{filename }\end{DoxyParamCaption})}



Load a picture from a .jpeg file. 


\begin{DoxyParams}{Parameters}
{\em filename} & the name of the file \\
\hline
\end{DoxyParams}
\begin{DoxyPrecond}{Precondition}
file must exist 

file extension must be .jpeg or .jpg 

file must be no larger than 266 by 427 
\end{DoxyPrecond}
\begin{DoxyReturn}{Returns}
locally-\/declared \hyperlink{struct_picture}{Picture} 
\end{DoxyReturn}
\begin{DoxyPostcond}{Postcondition}
calling program should store returned \hyperlink{struct_picture}{Picture} in a previously-\/declared struct 
\end{DoxyPostcond}
\mbox{\Hypertarget{_myro_c-image-file_8c_ace59c91f90d0bd811b3df1d3ddcf14e3}\label{_myro_c-image-file_8c_ace59c91f90d0bd811b3df1d3ddcf14e3}} 
\index{Myro\+C-\/image-\/file.\+c@{Myro\+C-\/image-\/file.\+c}!r\+Save\+Picture@{r\+Save\+Picture}}
\index{r\+Save\+Picture@{r\+Save\+Picture}!Myro\+C-\/image-\/file.\+c@{Myro\+C-\/image-\/file.\+c}}
\subsubsection{\texorpdfstring{r\+Save\+Picture()}{rSavePicture()}}
{\footnotesize\ttfamily void r\+Save\+Picture (\begin{DoxyParamCaption}\item[{\hyperlink{struct_picture}{Picture} $\ast$}]{pic,  }\item[{char $\ast$}]{filename }\end{DoxyParamCaption})}



Save a \hyperlink{struct_picture}{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

B\+A\+S\+ED ON T\+I\+M\+I\+N\+GS A\+ND M\+E\+M\+O\+RY C\+O\+N\+S\+I\+D\+E\+R\+A\+T\+I\+O\+NS, Myro C A\+L\+L\+O\+WS O\+N\+LY L\+OW R\+E\+S\+O\+L\+U\+T\+I\+ON I\+M\+A\+G\+ES

the \hyperlink{struct_picture}{Picture} struct allows direct access to \hyperlink{struct_pixel}{Pixel} data Pictures can be saved and loaded as .jpeg files

\begin{DoxyNote}{Note}
Following standard mathematical convention for a 2D matrix, all references to a pixel are given within an array as \mbox{[}row\mbox{]}\mbox{[}col\mbox{]} 

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 \mbox{[}row\mbox{]}\mbox{[}col\mbox{]}
\end{DoxyNote}
\begin{DoxyWarning}{Warning}
The \hyperlink{struct_picture}{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 \hyperlink{struct_picture}{Picture} variables, the issue may involve lack of space on the runtime stack. To utilize a modest number of Pictures, use \char`\"{}ulimit -\/s\char`\"{} 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 \hyperlink{struct_picture}{Picture} to a .jpeg 
\end{DoxyWarning}

\begin{DoxyParams}{Parameters}
{\em pic} & pointer to an R\+GB picture struct from Scribbler 2 camera \\
\hline
{\em filename} & the name of the file \\
\hline
\end{DoxyParams}
\begin{DoxyPrecond}{Precondition}
filename ends with .jpeg or .jpg. 
\end{DoxyPrecond}
\begin{DoxyPostcond}{Postcondition}
If the file does not exist, a new file will be created. 

If the file exists, the file will be overwritten.
\end{DoxyPostcond}
this code is a slightly modified version of write\+\_\+\+J\+P\+E\+G\+\_\+file(char $\ast$, int) from example.\+c from the libjpeg.\+v8d library directory. 