Exemplo n.º 1
0
void ScanGallery::slotExportFile()
{
    FileTreeViewItem *curr = highlightedFileTreeViewItem();
    if (curr==NULL) return;

    if (curr->isDir())
    {
        kDebug() << "Not yet implemented!";
        return;
    }

    KUrl fromUrl(curr->url());

    QString filter;
    ImageFormat format = getImgFormat(curr);
    if (format.isValid()) filter = "*."+format.extension()+"|"+format.mime()->comment()+"\n";
// TODO: do we need the below?
    filter += "*|"+i18n("All Files");

    QString initial = "kfiledialog:///exportImage/"+fromUrl.fileName();
    KUrl fileName = KFileDialog::getSaveUrl(KUrl(initial), filter, this);
    if (!fileName.isValid()) return;			// didn't get a file name
    if (fromUrl==fileName) return;			// can't save over myself

    /* Since it is asynchron, we will never know if it succeeded. */
    ImgSaver::copyImage(fromUrl, fileName);
}
Exemplo n.º 2
0
static GLenum getImgIFormat(const ilA_img *img)
{
    unsigned i;
    static const struct {
        ilA_imgchannel chans;
        ilA_imgformat fmt;
        GLenum format;
    } mapping_table[] = {
        {ILA_IMG_R,    ILA_IMG_U8,  GL_R8},
        {ILA_IMG_R,    ILA_IMG_U16, GL_R16},
        {ILA_IMG_R,    ILA_IMG_F32, GL_R32F},

        {ILA_IMG_RG,   ILA_IMG_U8,  GL_RG8},
        {ILA_IMG_RG,   ILA_IMG_U16, GL_RG16},
        {ILA_IMG_RG,   ILA_IMG_F32, GL_RG32F},

        {ILA_IMG_RGB,  ILA_IMG_U8,  GL_RGB8},
        {ILA_IMG_RGB,  ILA_IMG_U16, GL_RGB16},
        {ILA_IMG_RGB,  ILA_IMG_F32, GL_RGB32F},

        {ILA_IMG_RGBA, ILA_IMG_U8,  GL_RGBA8},
        {ILA_IMG_RGBA, ILA_IMG_U16, GL_RGBA16},
        {ILA_IMG_RGBA, ILA_IMG_F32, GL_RGBA32F},

        {0, 0, 0}
    };

    for (i = 0; mapping_table[i].chans; i++) {
        if (mapping_table[i].chans == img->channels && mapping_table[i].fmt == img->format) {
            return mapping_table[i].format;
        }
    }

    return getImgFormat(img);
}
Exemplo n.º 3
0
void ilG_tex_loadimage(ilG_tex *self, struct ilA_img *img)
{
    GLenum format, internalformat, type;

    format = getImgFormat(img);
    type = getImgType(img);
    internalformat = getImgIFormat(img);
    ilG_tex_loaddata(self, GL_TEXTURE_2D, internalformat, img->width, img->height, 1, format, type, img->data);
}
Exemplo n.º 4
0
void ilG_tex_loadimage(ilG_tex *tex, struct ilA_img img)
{
    GLenum format, internalformat, type;

    format = getImgFormat(&img);
    type = getImgType(&img);
    internalformat = getImgIFormat(&img);
    ilG_tex_loaddata(tex, GL_TEXTURE_2D, internalformat,
                     img.width, img.height, 1,
                     format, type, img.data);
}
Exemplo n.º 5
0
void ScanGallery::slotDecorate(FileTreeViewItem *item)
{
    if (item==NULL) return;

    if (!item->isDir())					// dir is done in another slot
    {
        ImageFormat format = getImgFormat(item);	// this is safe for any file
        item->setText(2,(" "+format.name()+" "));

        const KookaImage *img = imageForItem(item);
        if (img!=NULL)					// image appears to be loaded
        {						// set image depth pixmap
            if (img->depth()==1) item->setIcon(0, mPixBw);
            else
            {
                if (img->isGrayscale()) item->setIcon(0, mPixGray);
                else item->setIcon(0, mPixColor);
            }
							// set image size column
            QString t = i18n(" %1 x %2", img->width(), img->height());
            item->setText(1,t);
        }
        else						// not yet loaded, show file info
        {
            if (format.isValid())			// if a valid image file
            {
                item->setIcon(0, mPixFloppy);
                const KFileItem *kfi = item->fileItem();
                if (!kfi->isNull()) item->setText(1, (" "+KIO::convertSize(kfi->size())));
            }
            else
            {
                item->setIcon(0, KIO::pixmapForUrl(item->url(), 0, KIconLoader::Small));
            }
        }
    }

    // This code is quite similar to m_nextUrlToSelect in FileTreeView::slotNewTreeViewItems
    // When scanning a new image, we wait for the KDirLister to notice the new file,
    // and then we have the FileTreeViewItem that we need to display the image.
    if (!m_nextUrlToShow.isEmpty())
    {
        if (m_nextUrlToShow.equals(item->url(), KUrl::CompareWithoutTrailingSlash))
        {
            m_nextUrlToShow = KUrl();			// do this first to prevent recursion
            slotItemActivated(item);
            setCurrentItem(item);			// neccessary in case of new file from D&D
        }
    }
}
Exemplo n.º 6
0
int KSaneWidgetPrivate::getBytesPerLines(SANE_Parameters &params)
{
    switch (getImgFormat(params)) {
    case KSaneWidget::FormatBlackWhite:
    case KSaneWidget::FormatGrayScale8:
    case KSaneWidget::FormatGrayScale16:
        return params.bytes_per_line;

    case KSaneWidget::FormatRGB_8_C:
        return params.pixels_per_line * 3;

    case KSaneWidget::FormatRGB_16_C:
        return params.pixels_per_line * 6;

    case KSaneWidget::FormatNone:
    case KSaneWidget::FormatBMP: // to remove warning (BMP is omly valid in the twain wrapper)
        return 0;
    }
    return 0;
}
Exemplo n.º 7
0
static void tex_cube_build(ilG_tex *self, struct ilG_context *context)
{
    (void)context;
    ilA_img **faces = self->data;
    static const GLenum targets[6] = {
        GL_TEXTURE_CUBE_MAP_POSITIVE_X,
        GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
        GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
        GL_TEXTURE_CUBE_MAP_NEGATIVE_Y,
        GL_TEXTURE_CUBE_MAP_POSITIVE_Z,
        GL_TEXTURE_CUBE_MAP_NEGATIVE_Z,
    };

    glGenTextures(1, &self->object);
    glBindTexture(GL_TEXTURE_CUBE_MAP, self->object);
    for (unsigned i = 0; i < 6; i++) {
        glTexImage2D(targets[i], 0, getImgIFormat(faces[i]), faces[i]->width, 
                     faces[i]->height, 0, getImgFormat(faces[i]), 
                     getImgType(faces[i]), faces[i]->data);
    }
    glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
    glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
}
Exemplo n.º 8
0
void ilG_tex_loadcube(ilG_tex *tex, struct ilA_img faces[6])
{
    static const GLenum targets[6] = {
        GL_TEXTURE_CUBE_MAP_POSITIVE_X,
        GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
        GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
        GL_TEXTURE_CUBE_MAP_NEGATIVE_Y,
        GL_TEXTURE_CUBE_MAP_POSITIVE_Z,
        GL_TEXTURE_CUBE_MAP_NEGATIVE_Z,
    };

    tex->target = GL_TEXTURE_CUBE_MAP;
    glGenTextures(1, &tex->object);
    glBindTexture(GL_TEXTURE_CUBE_MAP, tex->object);
    for (unsigned i = 0; i < 6; i++) {
        glTexImage2D(targets[i], 0, getImgIFormat(&faces[i]),
                     faces[i].width, faces[i].height, 0,
                     getImgFormat(&faces[i]),
                     getImgType(&faces[i]), faces[i].data);
        ilA_img_free(faces[i]);
    }
    glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
    glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
}
Exemplo n.º 9
0
static GLenum getImgIFormat(const ilA_img *img)
{
    unsigned i;
    static const struct {
        enum ilA_imgchannels channels;
        unsigned depth;
        unsigned fp;
        GLenum format;
    } mapping_table[] = {
        {ILA_IMG_R,     8,  0,  GL_R8},
        {ILA_IMG_R,     16, 0,  GL_R16},
        {ILA_IMG_R,     32, 1,  GL_R32F},

        {ILA_IMG_RG,    8,  0,  GL_RG8},
        {ILA_IMG_RG,    16, 0,  GL_RG16},
        {ILA_IMG_RG,    32, 1,  GL_RG32F},

        {ILA_IMG_RGB,   8,  0, GL_RGB8},
        {ILA_IMG_RGB,   16, 0, GL_RGB16},
        {ILA_IMG_RGB,   32, 1, GL_RGB32F},

        {ILA_IMG_RGBA,  8,  0, GL_RGBA8},
        {ILA_IMG_RGBA,  16, 0, GL_RGBA16},
        {ILA_IMG_RGBA,  32, 1, GL_RGBA32F},

        {0, 0, 0, 0}
    };

    for (i = 0; mapping_table[i].depth; i++) {
        if (mapping_table[i].channels == img->channels && mapping_table[i].fp == img->fp && mapping_table[i].depth == img->depth) {
            return mapping_table[i].format;
        }
    }
    
    return getImgFormat(img);
}
Exemplo n.º 10
0
void ScanGallery::loadImageForItem(FileTreeViewItem *item)
{
    if (item==NULL) return;

    const KFileItem *kfi = item->fileItem();
    if (kfi->isNull()) return;

    kDebug() << "loading" << item->url();

    QString ret = QString::null;			// no error so far

    ImageFormat format = getImgFormat(item);		// check for valid image format
    if (!format.isValid())
    {
        ret = i18n("Not a valid image format");
    }
    else
    {
        KookaImage *img = imageForItem(item);
        if (img==NULL)					// image not already loaded
        {
            // The image needs to be loaded. Possibly it is a multi-page image.
            // If it is, the kookaImage has a subImageCount larger than one. We
            // create an subimage-item for every subimage, but do not yet load
            // them.

            img = new KookaImage();
            ret = img->loadFromUrl(item->url());
            if (ret.isEmpty())				// image loaded OK
            {
                img->setFileItem(kfi);			// store the fileitem

                kDebug() << "subImage-count" << img->subImagesCount();
                if (img->subImagesCount()>1)		// look for subimages,
                {					// create items for them
                    KIconLoader *loader = KIconLoader::global();

                    // Start at the image with index 1, that makes one less than
                    // are actually in the image. But image 0 was already created above.
                    FileTreeViewItem *prevItem = NULL;
                    for (int i = 1; i<img->subImagesCount(); i++)
                    {
                        kDebug() << "Creating subimage" << i;
                        KFileItem newKfi(*kfi);
                        FileTreeViewItem *subImgItem = new FileTreeViewItem(item,newKfi,item->branch());

                        // TODO: what's the equivalent?
                        //if (prevItem!=NULL) subImgItem->moveItem(prevItem);
                        prevItem = subImgItem;

                        subImgItem->setIcon(0, loader->loadIcon("editcopy", KIconLoader::Small));
                        subImgItem->setText(0, i18n("Sub-image %1", i));
                        KookaImage *subImgImg = new KookaImage(i, img);
                        subImgImg->setFileItem(&newKfi);
                        subImgItem->setClientData(subImgImg);
                    }
                }

                if (img->isSubImage())			// this is a subimage
                {
                    kDebug() << "it is a subimage";
                    if (img->isNull())			// if not already loaded,
                    {
                        kDebug() << "extracting subimage";
                        img->extractNow();		// load it now
                    }
                }

                slotImageArrived(item, img);
            }
            else
            {
                delete img;				// nothing to load
            }
        }
    }

    if (!ret.isEmpty()) KMessageBox::error(this,	// image loading failed
                                           i18n("<qt>"
                                                "<p>Unable to load the image<br>"
                                                "<filename>%2</filename><br>"
                                                "<br>"
                                                "%1",
                                                ret,
                                                item->url().prettyUrl()),
                                           i18n("Image Load Error"));
}