Changeset 1391:e70d408b12e2


Ignore:
Timestamp:
11/05/09 17:54:00 (2 years ago)
Author:
niam
Branch:
default
Message:

{issue #54[resolved] graphics::image use io:: as input and output sources}

Location:
src
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • src/examples/image/test.cc

    r1386 r1391  
    77 
    88#include <libdodo/dodo.h> 
     9 
    910#include <math.h> 
    1011#include <iostream> 
     
    5455#endif 
    5556 
    56         im.readFile("test.png"); 
     57        im.read(file::regular("test.png", file::regular::OPEN_MODE_READ_ONLY)); 
    5758        cout << im.compression() << " " << im.encoder() << " " << im.quality() << endl; 
    5859 
     
    6263        draw::circle(im, point(300, 300), 50, color::blue, color::white, 5); 
    6364 
    64         im.writeFile("test.jpg"); 
     65        im.write(file::regular("test-0.jpg", file::regular::OPEN_MODE_READ_WRITE_TRUNCATE)); 
    6566 
    6667#ifndef GRAPHICS_WO_XEXEC 
     
    7475        im.setQuality(4); 
    7576        im.setColorSpecification(image::COLOR_SPECIFICATION_GRAYSCALE); 
    76         im.writeMemory(img); 
    77  
    78         file::regular io; 
    79         io.open("my.png", file::regular::OPEN_MODE_READ_WRITE_TRUNCATE); 
    80         io.blockSize = img.size(); 
    81         io.write(img); 
    82  
    83         cout << img.size() << endl; 
     77        im.write(file::regular("test-1.jpg", file::regular::OPEN_MODE_READ_WRITE_TRUNCATE)); 
    8478 
    8579        im.create(400, 400); 
     
    8781        draw::circle(im, point(200, 200), 50, color::blue, color::white, 5); 
    8882        draw::rectangle(im, point(200, 200), point(300, 300), color::green, color::red, 15); 
    89         im.writeFile("new.png"); 
     83        im.write(file::regular("new-0.png", file::regular::OPEN_MODE_READ_WRITE_TRUNCATE)); 
    9084 
    91         im.readFile("new.png"); 
     85        im.read(file::regular("new-0.png", file::regular::OPEN_MODE_READ_ONLY)); 
    9286        im.removeAlpha(); 
    93         im.writeFile("new-1.png"); 
     87        im.write(file::regular("new-1.png", file::regular::OPEN_MODE_READ_WRITE_TRUNCATE)); 
    9488 
    95         im.readFile("new-1.png"); 
     89        im.read(file::regular("new-1.png", file::regular::OPEN_MODE_READ_ONLY)); 
    9690        im.setBackgroundColor(color::transparent); 
    9791        draw::circle(im, point(200, 200), 100, color::red, color::green, 5); 
     
    10296        green.opacity = 65535 / 2; 
    10397        draw::circle(im, point(250, 250), 50, green, color::white, 5); 
    104         im.writeFile("new-2.png"); 
     98        im.write(file::regular("new-2.png", file::regular::OPEN_MODE_READ_WRITE_TRUNCATE)); 
    10599 
    106100        im.create(400, 400); 
     
    114108        for (int i = 0; i < 360; ++i) 
    115109            draw::point(im, point((unsigned long)(cos(i) * 100 + 150), (unsigned long)(200 - sin(i) * 100)), color::black); 
    116         im.writeFile("new-3.png"); 
     110        im.write(file::regular("new-3.png", file::regular::OPEN_MODE_READ_WRITE_TRUNCATE)); 
    117111 
    118112        im.create(400, 400); 
     
    122116        draw::text(im, point(150, 150), "libdodo", "Arial", 50, color::blue, color::green, 2, 180); 
    123117        draw::text(im, point(150, 200), "libdodo", "Arial", 50, color::blue, color::green, 2, 90); 
    124         im.writeFile("new-4.png"); 
     118        im.write(file::regular("new-4.png", file::regular::OPEN_MODE_READ_WRITE_TRUNCATE)); 
    125119 
    126120        image wm; 
    127         wm.readFile("new-4.png"); 
     121        wm.read(file::regular("new-4.png", file::regular::OPEN_MODE_READ_ONLY)); 
    128122 
    129123        im.create(600, 600); 
    130124        draw::image(im, point(100, 100), wm, 45); 
    131125        im.setOpacity(65535 / 2); 
    132         im.writeFile("new-5.png"); 
     126        im.write(file::regular("new-5.png", file::regular::OPEN_MODE_READ_WRITE_TRUNCATE)); 
    133127#endif 
    134128    } catch (dodo::exception::basic &ex)   { 
  • src/include/libdodo/graphicsImage.h

    r1386 r1391  
    3939 
    4040namespace dodo { 
     41    namespace io { 
     42        class channel; 
     43    }; 
     44 
    4145    namespace graphics { 
    4246        struct __image__; 
     
    126130 
    127131                COMPRESSION_ENUMSIZE 
    128             }; 
    129  
    130             /** 
    131              * @struct __info__ 
    132              * @brief defines image information 
    133              */ 
    134             struct __info__ { 
    135                 void          *data;            ///< 2D array of pixels 
    136                 unsigned long width;            ///< width of the image 
    137                 unsigned long height;           ///< height of the image 
    138                 short         mapping;          ///< type of mapping, @see image::mappingEnum 
    139                 short         pixelSize;        ///< type of pixel 
    140132            }; 
    141133 
     
    216208            /** 
    217209             * read image 
    218              * @param path defines path to image 
    219              */ 
    220             void readFile(const dodoString &path); 
    221  
    222             /** 
    223              * read image 
    224              * @param info defines image info 
    225              */ 
    226             void readMemory(const __info__ &info); 
    227  
    228             /** 
    229              * read image 
    230              * @param data defines image data 
    231              */ 
    232             void readMemory(const dodoString &data); 
     210             * @param img defines source for reading image 
     211             */ 
     212            void read(const io::channel &img); 
    233213 
    234214            /** 
    235215             * write image 
    236              * @param path describes path to image 
    237              */ 
    238             void writeFile(const dodoString &path); 
    239  
    240             /** 
    241              * write image 
    242              * @param data defines image data 
    243              */ 
    244             void writeMemory(dodoString &data); 
     216             * @param img defines source for writing image 
     217             */ 
     218            void write(const io::channel &img); 
    245219 
    246220            /** 
  • src/src/graphicsImage.cc

    r1386 r1391  
    4646#include <libdodo/graphicsImageEx.h> 
    4747#include <libdodo/xexec.h> 
     48#include <libdodo/ioChannel.h> 
    4849 
    4950namespace dodo { 
     
    252253 
    253254void 
    254 image::readFile(const dodoString &str) 
     255image::read(const io::channel &img) 
    255256{ 
    256257#ifndef GRAPHICS_WO_XEXEC 
    257258    performPreExec(OPERATION_READ); 
    258259#endif 
    259  
    260     unsigned long size = str.size() + 1; 
    261  
    262     if (size >= MaxTextExtent) 
    263         throw exception::basic(exception::MODULE_GRAPHICSIMAGE, IMAGEEX_READ, exception::ERRNO_LIBDODO, IMAGEEX_LONGPATH, GRAPHICSIMAGEEX_LONGPATH_STR, __LINE__, __FILE__); 
    264260 
    265261    GetExceptionInfo((ExceptionInfo *)exInfo); 
    266262    GetImageInfo(collectedData.handle->imInfo); 
    267263 
    268     strncpy(collectedData.handle->imInfo->filename, str.data(), size); 
    269  
    270264    if (collectedData.handle->im != NULL) 
    271265        DestroyImage(collectedData.handle->im); 
    272266 
    273     collectedData.handle->im = ReadImage(collectedData.handle->imInfo, (ExceptionInfo *)exInfo); 
    274     if (collectedData.handle->im == NULL) 
    275         throw exception::basic(exception::MODULE_GRAPHICSIMAGE, IMAGEEX_READ, exception::ERRNO_IMAGEMAGICK, ((ExceptionInfo *)exInfo)->error_number, ((ExceptionInfo *)exInfo)->reason, __LINE__, __FILE__, ((ExceptionInfo *)exInfo)->description ? ((ExceptionInfo *)exInfo)->description : __dodostring__); 
    276  
    277     collectedData.handle->imInfo->compression = collectedData.handle->im->compression; 
    278     collectedData.handle->imInfo->quality = collectedData.handle->im->quality; 
    279  
    280     strcpy(collectedData.handle->imInfo->magick, collectedData.handle->im->magick); 
    281  
    282 #ifndef GRAPHICS_WO_XEXEC 
    283     performPostExec(OPERATION_READ); 
    284 #endif 
    285 } 
    286  
    287 //------------------------------------------------------------------- 
    288  
    289 void 
    290 image::readMemory(const dodoString &data) 
    291 { 
    292 #ifndef GRAPHICS_WO_XEXEC 
    293     performPreExec(OPERATION_READ); 
    294 #endif 
    295  
    296     GetExceptionInfo((ExceptionInfo *)exInfo); 
    297     GetImageInfo(collectedData.handle->imInfo); 
    298  
    299     if (collectedData.handle->im != NULL) 
    300         DestroyImage(collectedData.handle->im); 
     267    dodoString data, dataPart; 
     268 
     269    while (true) { 
     270        dataPart = img.read(); 
     271        if (dataPart.size() == 0) 
     272            break; 
     273 
     274        data.append(dataPart); 
     275    } 
     276    dataPart.clear(); 
    301277 
    302278    collectedData.handle->im = BlobToImage(collectedData.handle->imInfo, data.data(), data.size(), (ExceptionInfo *)exInfo); 
    303     if (collectedData.handle->im == NULL) 
    304         throw exception::basic(exception::MODULE_GRAPHICSIMAGE, IMAGEEX_READ, exception::ERRNO_IMAGEMAGICK, ((ExceptionInfo *)exInfo)->error_number, ((ExceptionInfo *)exInfo)->reason, __LINE__, __FILE__, ((ExceptionInfo *)exInfo)->description ? ((ExceptionInfo *)exInfo)->description : __dodostring__); 
    305  
    306     collectedData.handle->imInfo->compression = collectedData.handle->im->compression; 
    307     collectedData.handle->imInfo->quality = collectedData.handle->im->quality; 
    308  
    309     strcpy(collectedData.handle->imInfo->magick, collectedData.handle->im->magick); 
    310  
    311 #ifndef GRAPHICS_WO_XEXEC 
    312     performPostExec(OPERATION_READ); 
    313 #endif 
    314 } 
    315  
    316 //------------------------------------------------------------------- 
    317  
    318 void 
    319 image::readMemory(const __info__ &info) 
    320 { 
    321 #ifndef GRAPHICS_WO_XEXEC 
    322     performPreExec(OPERATION_READ); 
    323 #endif 
    324  
    325     if (info.mapping < 0 || info.mapping >= MAPPING_ENUMSIZE || info.pixelSize < 0 || info.pixelSize >= PIXEL_SIZE_ENUMSIZE) 
    326         throw exception::basic(exception::MODULE_GRAPHICSIMAGE, IMAGEEX_READ, exception::ERRNO_LIBDODO, IMAGEEX_BADINFO, GRAPHICSIMAGEEX_BADINFO_STR, __LINE__, __FILE__); 
    327  
    328     GetExceptionInfo((ExceptionInfo *)exInfo); 
    329     GetImageInfo(collectedData.handle->imInfo); 
    330  
    331     if (collectedData.handle->im != NULL) 
    332         DestroyImage(collectedData.handle->im); 
    333  
    334     collectedData.handle->im = ConstituteImage(info.width, info.height, mappingStatements[info.mapping], (StorageType)pixelSizeStatements[info.pixelSize], info.data, (ExceptionInfo *)exInfo); 
    335279    if (collectedData.handle->im == NULL) 
    336280        throw exception::basic(exception::MODULE_GRAPHICSIMAGE, IMAGEEX_READ, exception::ERRNO_IMAGEMAGICK, ((ExceptionInfo *)exInfo)->error_number, ((ExceptionInfo *)exInfo)->reason, __LINE__, __FILE__, ((ExceptionInfo *)exInfo)->description ? ((ExceptionInfo *)exInfo)->description : __dodostring__); 
     
    470414 
    471415void 
    472 image::writeFile(const dodoString &str) 
    473 { 
    474 #ifndef GRAPHICS_WO_XEXEC 
    475     performPreExec(OPERATION_WRITE); 
    476 #endif 
    477  
    478     if (collectedData.handle->im == NULL) 
    479         throw exception::basic(exception::MODULE_GRAPHICSIMAGE, IMAGEEX_WRITE, exception::ERRNO_IMAGEMAGICK, IMAGEEX_EMPTYIMAGE, GRAPHICSIMAGEEX_EMPTYIMAGE_STR, __LINE__, __FILE__); 
    480  
    481     unsigned long size = str.size() + 1; 
    482  
    483     if (size >= MaxTextExtent) 
    484         throw exception::basic(exception::MODULE_GRAPHICSIMAGE, IMAGEEX_WRITE, exception::ERRNO_LIBDODO, IMAGEEX_LONGPATH, GRAPHICSIMAGEEX_LONGPATH_STR, __LINE__, __FILE__); 
    485  
    486     strncpy(collectedData.handle->im->filename, str.data(), size); 
    487  
    488     GetExceptionInfo((ExceptionInfo *)exInfo); 
    489  
    490     if (WriteImage(collectedData.handle->imInfo, collectedData.handle->im) == MagickFalse) 
    491         throw exception::basic(exception::MODULE_GRAPHICSIMAGE, IMAGEEX_WRITE, exception::ERRNO_IMAGEMAGICK, collectedData.handle->im->exception.error_number, ((ExceptionInfo *)exInfo)->reason, __LINE__, __FILE__, ((ExceptionInfo *)exInfo)->description ? ((ExceptionInfo *)exInfo)->description : __dodostring__); 
    492  
    493 #ifndef GRAPHICS_WO_XEXEC 
    494     performPostExec(OPERATION_WRITE); 
    495 #endif 
    496 } 
    497  
    498 //------------------------------------------------------------------- 
    499  
    500 void 
    501 image::writeMemory(dodoString &data) 
     416image::write(const io::channel &img) 
    502417{ 
    503418#ifndef GRAPHICS_WO_XEXEC 
     
    515430        throw exception::basic(exception::MODULE_GRAPHICSIMAGE, IMAGEEX_WRITE, exception::ERRNO_IMAGEMAGICK, ((ExceptionInfo *)exInfo)->error_number, ((ExceptionInfo *)exInfo)->reason, __LINE__, __FILE__, ((ExceptionInfo *)exInfo)->description ? ((ExceptionInfo *)exInfo)->description : __dodostring__); 
    516431 
    517     data.assign((char *)imData, size); 
     432    img.blockSize = size; 
     433    img.write((char *)imData); 
    518434 
    519435#ifndef GRAPHICS_WO_XEXEC 
  • src/src/ioFileRegular.cc

    r1386 r1391  
    396396        break; 
    397397    } 
     398 
     399    this->pos += blockSize; 
    398400} 
    399401 
     
    430432        break; 
    431433    } 
     434 
     435    this->pos += blockSize; 
    432436} 
    433437 
Note: See TracChangeset for help on using the changeset viewer.