void _compositeOutputStreamFlush(OutputStream* outputStream) {
    int i;
    CompositeOutputStream* compositeOutputStream = getCompositeOutputStream(outputStream);
    int size = compositeOutputStream->size;
    for (i = 0; i < size; i++) {
        OutputStream* childOutputStream = getChildOutputStream(compositeOutputStream, i);
        childOutputStream->flush(childOutputStream);
    }
}
Esempio n. 2
0
void pipeStream(InputStream &source, OutputStream &dest)
{
    for (;;)
        {
        int ch = source.get();
        if (ch<0)
            break;
        dest.put(ch);
        }
    dest.flush();
}
Esempio n. 3
0
void BufferedConnectionWriter::write(OutputStream& os)
{
    stopWrite();
    for (size_t i = 0; i < header_used; i++) {
        yarp::os::ManagedBytes& b = *(header[i]);
        os.write(b.usedBytes());
    }
    for (size_t i = 0; i < lst_used; i++) {
        yarp::os::ManagedBytes& b = *(lst[i]);
        os.write(b.usedBytes());
    }
    os.flush();
}
Esempio n. 4
0
void save_image(Image::ConstRefArg image, OutputStream& out,
                std::string target_name, std::string format_name,
                Logger* logger, FileFormat::ProgressTracker* tracker,
                FileFormat::Registry::ConstRefArg r)
{
    FileFormat::Registry::ConstRef registry = r;
    if (!registry)
        registry = FileFormat::Registry::get_default_registry();

    if (format_name.empty()) {
        // Determine format by suffix
        std::string suffix = ascii_tolower(file::suffix_of(target_name));
        if (!suffix.empty()) {
            for (int i = 0; i < registry->get_num_formats(); ++i) {
                FileFormat::ConstRef f = registry->get_format(i);
                if (!f->check_suffix(suffix))
                    continue;
                format_name = f->get_name();
                break;
            }
        }
    }

    if (format_name.empty()) {
        throw UnresolvableFormatException("Image format could not be "
                                          "detected from the file name"
                                          ": \"" + target_name + "\"");
    }

    for (int i = 0; i < registry->get_num_formats(); ++i) {
        FileFormat::ConstRef f = registry->get_format(i);
        if (format_name != f->get_name())
            continue;
        f->save(image, out, logger, tracker);
        out.flush();
        return;
    }

    throw UnknownFormatException("Unrecognized format "
                                 "specifier: \""+format_name+"\"");
}
Esempio n. 5
0
void Command::save(OutputStream& stream) const {
    stream.writeUint8(playerID);
	stream.writeUint32((Uint32) commandID);
	stream.writeUint32Vector(parameter);
	stream.flush();
}
Esempio n. 6
0
bool JPEGImageFormat::writeImageToStream (const Image& image, OutputStream& out)
{
    using namespace jpeglibNamespace;
    using namespace JPEGHelpers;

    if (image.hasAlphaChannel())
    {
        // this method could fill the background in white and still save the image..
        jassertfalse;
        return true;
    }

    struct jpeg_compress_struct jpegCompStruct;

    struct jpeg_error_mgr jerr;
    setupSilentErrorHandler (jerr);
    jpegCompStruct.err = &jerr;

    jpeg_create_compress (&jpegCompStruct);

    JuceJpegDest dest;
    jpegCompStruct.dest = &dest;

    dest.output = &out;
    HeapBlock <char> tempBuffer (jpegBufferSize);
    dest.buffer = tempBuffer;
    dest.next_output_byte = (JOCTET*) dest.buffer;
    dest.free_in_buffer = jpegBufferSize;
    dest.init_destination = jpegWriteInit;
    dest.empty_output_buffer = jpegWriteFlush;
    dest.term_destination = jpegWriteTerminate;

    jpegCompStruct.image_width = image.getWidth();
    jpegCompStruct.image_height = image.getHeight();
    jpegCompStruct.input_components = 3;
    jpegCompStruct.in_color_space = JCS_RGB;
    jpegCompStruct.write_JFIF_header = 1;

    jpegCompStruct.X_density = 72;
    jpegCompStruct.Y_density = 72;

    jpeg_set_defaults (&jpegCompStruct);

    jpegCompStruct.dct_method = JDCT_FLOAT;
    jpegCompStruct.optimize_coding = 1;
    //jpegCompStruct.smoothing_factor = 10;

    if (quality < 0.0f)
        quality = 0.85f;

    jpeg_set_quality (&jpegCompStruct, jlimit (0, 100, roundToInt (quality * 100.0f)), TRUE);

    jpeg_start_compress (&jpegCompStruct, TRUE);

    const int strideBytes = jpegCompStruct.image_width * jpegCompStruct.input_components;

    JSAMPARRAY buffer = (*jpegCompStruct.mem->alloc_sarray) ((j_common_ptr) &jpegCompStruct,
                                                             JPOOL_IMAGE, strideBytes, 1);

    const Image::BitmapData srcData (image, Image::BitmapData::readOnly);

    while (jpegCompStruct.next_scanline < jpegCompStruct.image_height)
    {
        const uint8* src = srcData.getLinePointer (jpegCompStruct.next_scanline);
        uint8* dst = *buffer;

        for (int i = jpegCompStruct.image_width; --i >= 0;)
        {
            *dst++ = ((const PixelRGB*) src)->getRed();
            *dst++ = ((const PixelRGB*) src)->getGreen();
            *dst++ = ((const PixelRGB*) src)->getBlue();
            src += srcData.pixelStride;
        }

        jpeg_write_scanlines (&jpegCompStruct, buffer, 1);
    }

    jpeg_finish_compress (&jpegCompStruct);
    jpeg_destroy_compress (&jpegCompStruct);

    out.flush();

    return true;
}
Esempio n. 7
0
bool PNGImageFormat::writeImageToStream (const Image& image, OutputStream& out)
{
    using namespace pnglibNamespace;
    const int width = image.getWidth();
    const int height = image.getHeight();

    png_structp pngWriteStruct = png_create_write_struct (PNG_LIBPNG_VER_STRING, 0, 0, 0);

    if (pngWriteStruct == 0)
        return false;

    png_infop pngInfoStruct = png_create_info_struct (pngWriteStruct);

    if (pngInfoStruct == 0)
    {
        png_destroy_write_struct (&pngWriteStruct, (png_infopp) 0);
        return false;
    }

    png_set_write_fn (pngWriteStruct, &out, PNGHelpers::writeDataCallback, 0);

    png_set_IHDR (pngWriteStruct, pngInfoStruct, width, height, 8,
                  image.hasAlphaChannel() ? PNG_COLOR_TYPE_RGB_ALPHA
                                          : PNG_COLOR_TYPE_RGB,
                  PNG_INTERLACE_NONE,
                  PNG_COMPRESSION_TYPE_BASE,
                  PNG_FILTER_TYPE_BASE);

    HeapBlock <uint8> rowData (width * 4);

    png_color_8 sig_bit;
    sig_bit.red = 8;
    sig_bit.green = 8;
    sig_bit.blue = 8;
    sig_bit.alpha = 8;
    png_set_sBIT (pngWriteStruct, pngInfoStruct, &sig_bit);

    png_write_info (pngWriteStruct, pngInfoStruct);

    png_set_shift (pngWriteStruct, &sig_bit);
    png_set_packing (pngWriteStruct);

    const Image::BitmapData srcData (image, Image::BitmapData::readOnly);

    for (int y = 0; y < height; ++y)
    {
        uint8* dst = rowData;
        const uint8* src = srcData.getLinePointer (y);

        if (image.hasAlphaChannel())
        {
            for (int i = width; --i >= 0;)
            {
                PixelARGB p (*(const PixelARGB*) src);
                p.unpremultiply();

                *dst++ = p.getRed();
                *dst++ = p.getGreen();
                *dst++ = p.getBlue();
                *dst++ = p.getAlpha();
                src += srcData.pixelStride;
            }
        }
        else
        {
            for (int i = width; --i >= 0;)
            {
                *dst++ = ((const PixelRGB*) src)->getRed();
                *dst++ = ((const PixelRGB*) src)->getGreen();
                *dst++ = ((const PixelRGB*) src)->getBlue();
                src += srcData.pixelStride;
            }
        }

        png_bytep rowPtr = rowData;
        png_write_rows (pngWriteStruct, &rowPtr, 1);
    }

    png_write_end (pngWriteStruct, pngInfoStruct);
    png_destroy_write_struct (&pngWriteStruct, &pngInfoStruct);

    out.flush();

    return true;
}