\hypertarget{ecore_evas_buffer_example_01_8c-example}{}\doxysection{ecore\+\_\+evas\+\_\+buffer\+\_\+example\+\_\+01.\+c}

\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{preprocessor}{\#ifdef HAVE\_CONFIG\_H}}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{preprocessor}{\#include "config.h"}}
\DoxyCodeLine{\textcolor{preprocessor}{\#else}}
\DoxyCodeLine{\textcolor{preprocessor}{\#define EINA\_UNUSED}}
\DoxyCodeLine{\textcolor{preprocessor}{\#endif}}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{preprocessor}{\#include <\mbox{\hyperlink{Ecore__Evas_8h}{Ecore\_Evas.h}}>}}
\DoxyCodeLine{\textcolor{preprocessor}{\#include <stdio.h>}}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{preprocessor}{\#define WIDTH  (320)}}
\DoxyCodeLine{\textcolor{preprocessor}{\#define HEIGHT (240)}}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{keyword}{static} Ecore\_Evas *ee;}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{comment}{/* support function to save scene as PPM image */}}
\DoxyCodeLine{\textcolor{keyword}{static} \textcolor{keywordtype}{void}}
\DoxyCodeLine{\_scene\_save(\mbox{\hyperlink{group__Evas__Canvas_ga5ff87cc4ce6bc43e3b640a6d37f73043}{Evas}} *canvas,}
\DoxyCodeLine{            \textcolor{keyword}{const} \textcolor{keywordtype}{char} *dest)}
\DoxyCodeLine{\{}
\DoxyCodeLine{   \textcolor{keyword}{const} \textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{int} *pixels, *pixels\_end;}
\DoxyCodeLine{   \textcolor{keywordtype}{int} width, height;}
\DoxyCodeLine{   FILE *f;}
\DoxyCodeLine{}
\DoxyCodeLine{   \mbox{\hyperlink{group__Evas__Canvas_gadd22b11c786b3b00448ef58550aa55c4}{evas\_output\_size\_get}}(canvas, \&width, \&height);}
\DoxyCodeLine{}
\DoxyCodeLine{   f = fopen(dest, \textcolor{stringliteral}{"wb+"});}
\DoxyCodeLine{   \textcolor{keywordflow}{if} (!f)}
\DoxyCodeLine{     \{}
\DoxyCodeLine{        fprintf(stderr, \textcolor{stringliteral}{"ERROR: could not open for writing '\%s': \%s\(\backslash\)n"},}
\DoxyCodeLine{                dest, strerror(errno));}
\DoxyCodeLine{        \textcolor{keywordflow}{return};}
\DoxyCodeLine{     \}}
\DoxyCodeLine{}
\DoxyCodeLine{   pixels = \mbox{\hyperlink{group__Ecore__Evas__Group_ga32886f8b6752c4fc17d4037cb1b7bfad}{ecore\_evas\_buffer\_pixels\_get}}(ee);}
\DoxyCodeLine{   pixels\_end = pixels + (width * height);}
\DoxyCodeLine{}
\DoxyCodeLine{   \textcolor{comment}{/* PPM P6 format is dead simple to write: */}}
\DoxyCodeLine{   fprintf(f, \textcolor{stringliteral}{"P6\(\backslash\)n\%d \%d\(\backslash\)n255\(\backslash\)n"}, width, height);}
\DoxyCodeLine{   \textcolor{keywordflow}{for} (; pixels < pixels\_end; pixels++)}
\DoxyCodeLine{     \{}
\DoxyCodeLine{        \textcolor{keywordtype}{int} r, g, b;}
\DoxyCodeLine{}
\DoxyCodeLine{        r = ((*pixels) \& 0xff0000) >> 16;}
\DoxyCodeLine{        g = ((*pixels) \& 0x00ff00) >> 8;}
\DoxyCodeLine{        b = (*pixels) \& 0x0000ff;}
\DoxyCodeLine{}
\DoxyCodeLine{        fprintf(f, \textcolor{stringliteral}{"\%c\%c\%c"}, r, g, b);}
\DoxyCodeLine{     \}}
\DoxyCodeLine{}
\DoxyCodeLine{   fclose(f);}
\DoxyCodeLine{   printf(\textcolor{stringliteral}{"Saved scene as '\%s'\(\backslash\)n"}, dest);}
\DoxyCodeLine{\}}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{keywordtype}{int}}
\DoxyCodeLine{main(\textcolor{keywordtype}{void})}
\DoxyCodeLine{\{}
\DoxyCodeLine{   \mbox{\hyperlink{group__Evas__Canvas_ga5ff87cc4ce6bc43e3b640a6d37f73043}{Evas}} *canvas;}
\DoxyCodeLine{   \mbox{\hyperlink{group__Evas__Object__Group_ga9e19e6dd1f517a0ba437c0114d3e7c97}{Evas\_Object}} *bg, *r1, *r2, *r3;}
\DoxyCodeLine{}
\DoxyCodeLine{   \mbox{\hyperlink{group__Ecore__Evas__Group_ga32ddbb6457033ad435a177eb0c4fe235}{ecore\_evas\_init}}();}
\DoxyCodeLine{}
\DoxyCodeLine{   ee = \mbox{\hyperlink{group__Ecore__Evas__Group_gac2e1f186eb493faf7cee9771fb16f49e}{ecore\_evas\_buffer\_new}}(WIDTH, HEIGHT);}
\DoxyCodeLine{   \textcolor{keywordflow}{if} (!ee) \textcolor{keywordflow}{goto} error;}
\DoxyCodeLine{}
\DoxyCodeLine{   canvas = \mbox{\hyperlink{group__Ecore__Evas__Group_ga75a7cc694b6069e78df47dab0b0f2d20}{ecore\_evas\_get}}(ee);}
\DoxyCodeLine{}
\DoxyCodeLine{   bg = \mbox{\hyperlink{group__Evas__Object__Rectangle_ga4d80fc32ad1cac28428cebd65d746751}{evas\_object\_rectangle\_add}}(canvas);}
\DoxyCodeLine{   \mbox{\hyperlink{group__Evas__Object__Group__Basic_gae34bdcfd7f5100151f6ea8ef4a392949}{evas\_object\_color\_set}}(bg, 255, 255, 255, 255); \textcolor{comment}{/* white bg */}}
\DoxyCodeLine{   evas\_object\_move(bg, 0, 0); \textcolor{comment}{/* at origin */}}
\DoxyCodeLine{   evas\_object\_resize(bg, WIDTH, HEIGHT); \textcolor{comment}{/* covers full canvas */}}
\DoxyCodeLine{   \mbox{\hyperlink{group__Evas__Object__Group__Basic_ga9cbc13661584e49fb9d9cdab514a1eeb}{evas\_object\_show}}(bg);}
\DoxyCodeLine{}
\DoxyCodeLine{   r1 = \mbox{\hyperlink{group__Evas__Object__Rectangle_ga4d80fc32ad1cac28428cebd65d746751}{evas\_object\_rectangle\_add}}(canvas);}
\DoxyCodeLine{   \mbox{\hyperlink{group__Evas__Object__Group__Basic_gae34bdcfd7f5100151f6ea8ef4a392949}{evas\_object\_color\_set}}(r1, 255, 0, 0, 255); \textcolor{comment}{/* 100\% opaque red */}}
\DoxyCodeLine{   evas\_object\_move(r1, 10, 10);}
\DoxyCodeLine{   evas\_object\_resize(r1, 100, 100);}
\DoxyCodeLine{   \mbox{\hyperlink{group__Evas__Object__Group__Basic_ga9cbc13661584e49fb9d9cdab514a1eeb}{evas\_object\_show}}(r1);}
\DoxyCodeLine{}
\DoxyCodeLine{   r2 = \mbox{\hyperlink{group__Evas__Object__Rectangle_ga4d80fc32ad1cac28428cebd65d746751}{evas\_object\_rectangle\_add}}(canvas);}
\DoxyCodeLine{   \mbox{\hyperlink{group__Evas__Object__Group__Basic_gae34bdcfd7f5100151f6ea8ef4a392949}{evas\_object\_color\_set}}(r2, 0, 128, 0, 128); \textcolor{comment}{/* 50\% opaque green */}}
\DoxyCodeLine{   evas\_object\_move(r2, 10, 10);}
\DoxyCodeLine{   evas\_object\_resize(r2, 50, 50);}
\DoxyCodeLine{   \mbox{\hyperlink{group__Evas__Object__Group__Basic_ga9cbc13661584e49fb9d9cdab514a1eeb}{evas\_object\_show}}(r2);}
\DoxyCodeLine{}
\DoxyCodeLine{   r3 = \mbox{\hyperlink{group__Evas__Object__Rectangle_ga4d80fc32ad1cac28428cebd65d746751}{evas\_object\_rectangle\_add}}(canvas);}
\DoxyCodeLine{   \mbox{\hyperlink{group__Evas__Object__Group__Basic_gae34bdcfd7f5100151f6ea8ef4a392949}{evas\_object\_color\_set}}(r3, 0, 128, 0, 255); \textcolor{comment}{/* 100\% opaque dark green */}}
\DoxyCodeLine{   evas\_object\_move(r3, 60, 60);}
\DoxyCodeLine{   evas\_object\_resize(r3, 50, 50);}
\DoxyCodeLine{   \mbox{\hyperlink{group__Evas__Object__Group__Basic_ga9cbc13661584e49fb9d9cdab514a1eeb}{evas\_object\_show}}(r3);}
\DoxyCodeLine{}
\DoxyCodeLine{   \mbox{\hyperlink{group__Ecore__Evas__Group_ga93a1c660785fbb2ded46e2bd184e1c04}{ecore\_evas\_manual\_render}}(ee);}
\DoxyCodeLine{   \_scene\_save(canvas, \textcolor{stringliteral}{"/tmp/evas-\/buffer-\/simple-\/render.ppm"});}
\DoxyCodeLine{}
\DoxyCodeLine{   \mbox{\hyperlink{group__Ecore__Evas__Group_gad3ec61f2aa03df4d3dbfd0d311e0c8dc}{ecore\_evas\_free}}(ee);}
\DoxyCodeLine{   \mbox{\hyperlink{group__Ecore__Evas__Group_gab8fa311077f749190c9b622f672b2214}{ecore\_evas\_shutdown}}();}
\DoxyCodeLine{}
\DoxyCodeLine{   \textcolor{keywordflow}{return} 0;}
\DoxyCodeLine{}
\DoxyCodeLine{error:}
\DoxyCodeLine{   fprintf(stderr, \textcolor{stringliteral}{"error: Requires at least one Evas engine built"}}
\DoxyCodeLine{                   \textcolor{stringliteral}{" and linked to ecore-\/evas for this example to run"}}
\DoxyCodeLine{                   \textcolor{stringliteral}{" properly.\(\backslash\)n"});}
\DoxyCodeLine{   \mbox{\hyperlink{group__Ecore__Evas__Group_gab8fa311077f749190c9b622f672b2214}{ecore\_evas\_shutdown}}();}
\DoxyCodeLine{   \textcolor{keywordflow}{return} -\/1;}
\DoxyCodeLine{\}}
\DoxyCodeLine{}
\end{DoxyCodeInclude}
 