Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial implementation of RAW image loading plug-in based on PhotoFlow #1

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 4 additions & 3 deletions plugins/impex/CMakeLists.txt
Expand Up @@ -12,6 +12,7 @@ endif()

if(TIFF_FOUND)
add_subdirectory(tiff)
add_subdirectory(phf)
endif()

if(PNG_FOUND)
Expand All @@ -27,9 +28,9 @@ if(POPPLER_FOUND)
add_subdirectory(pdf)
endif()

if(LIBRAW_FOUND)
add_subdirectory(raw)
endif()
#if(LIBRAW_FOUND)
# add_subdirectory(raw)
#endif()

add_subdirectory(bmp)
add_subdirectory(ora)
Expand Down
27 changes: 27 additions & 0 deletions plugins/impex/phf/CMakeLists.txt
@@ -0,0 +1,27 @@
if(OPENEXR_FOUND)
include_directories(${OPENEXR_INCLUDE_DIR})
endif()

set(libkritatiffconverter_LIB_SRCS
kis_tiff_converter.cc
kis_tiff_writer_visitor.cpp
kis_tiff_reader.cc
kis_tiff_ycbcr_reader.cc
kis_buffer_stream.cc
)

set(krita_phf_import_SOURCES
${libkritatiffconverter_LIB_SRCS}
kis_phf_import.cpp
)

ki18n_wrap_ui(krita_phf_import_SOURCES
wdgphfimport.ui
)

add_library(krita_phf_import MODULE ${krita_phf_import_SOURCES})
target_link_libraries(krita_phf_import kritaui ${TIFF_LIBRARIES})

install(TARGETS krita_phf_import DESTINATION ${KRITA_PLUGIN_INSTALL_DIR})
install( PROGRAMS krita_phf.desktop DESTINATION ${XDG_APPS_INSTALL_DIR})

152 changes: 152 additions & 0 deletions plugins/impex/phf/kis_buffer_stream.cc
@@ -0,0 +1,152 @@
/*
* Copyright (c) 2005-2006 Cyrille Berger <cberger@cberger.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/

#include "kis_buffer_stream.h"

KisBufferStreamContigBase::KisBufferStreamContigBase(uint8* src, uint16 depth, uint32 lineSize) : KisBufferStreamBase(depth), m_src(src), m_lineSize(lineSize)
{
restart();
}

void KisBufferStreamContigBase::restart()
{
m_srcIt = m_src;
m_posinc = 8;
}

void KisBufferStreamContigBase::moveToLine(uint32 lineNumber)
{
m_srcIt = m_src + lineNumber * m_lineSize;
m_posinc = 8;
}

uint32 KisBufferStreamContigBelow16::nextValue()
{
uint8 remain;
uint32 value;
remain = (uint8) m_depth;
value = 0;
while (remain > 0) {
uint8 toread;
toread = remain;
if (toread > m_posinc) toread = m_posinc;
remain -= toread;
m_posinc -= toread;
value = (value << toread) | (((*m_srcIt) >> (m_posinc)) & ((1 << toread) - 1));
if (m_posinc == 0) {
m_srcIt++;
m_posinc = 8;
}
}
return value;
}

uint32 KisBufferStreamContigBelow32::nextValue()
{
uint8 remain;
uint32 value;
remain = (uint8) m_depth;
value = 0;
while (remain > 0) {
uint8 toread;
toread = remain;
if (toread > m_posinc) toread = m_posinc;
remain -= toread;
m_posinc -= toread;
value = (value) | ((((*m_srcIt) >> (m_posinc)) & ((1 << toread) - 1)) << (m_depth - 8 - remain));
if (m_posinc == 0) {
m_srcIt++;
m_posinc = 8;
}
}
return value;
}

uint32 KisBufferStreamContigAbove32::nextValue()
{
uint8 remain;
uint32 value;
remain = (uint8) m_depth;
value = 0;
while (remain > 0) {
uint8 toread;
toread = remain;
if (toread > m_posinc) toread = m_posinc;
remain -= toread;
m_posinc -= toread;
if (remain < 32) {
value = (value) | ((((*m_srcIt) >> (m_posinc)) & ((1 << toread) - 1)) << (24 - remain));
}
if (m_posinc == 0) {
m_srcIt++;
m_posinc = 8;
}
}
return value;
}

KisBufferStreamSeperate::KisBufferStreamSeperate(uint8** srcs, uint8 nb_samples , uint16 depth, uint32* lineSize) : KisBufferStreamBase(depth), m_nb_samples(nb_samples)
{
streams = new KisBufferStreamContigBase*[nb_samples];
if (depth < 16) {
for (uint8 i = 0; i < m_nb_samples; i++) {
streams[i] = new KisBufferStreamContigBelow16(srcs[i], depth, lineSize[i]);
}
} else if (depth < 32) {
for (uint8 i = 0; i < m_nb_samples; i++) {
streams[i] = new KisBufferStreamContigBelow32(srcs[i], depth, lineSize[i]);
}
} else {
for (uint8 i = 0; i < m_nb_samples; i++) {
streams[i] = new KisBufferStreamContigAbove32(srcs[i], depth, lineSize[i]);
}
}
restart();
}

KisBufferStreamSeperate::~KisBufferStreamSeperate()
{
for (uint8 i = 0; i < m_nb_samples; i++) {
delete streams[i];
}
delete[] streams;
}

uint32 KisBufferStreamSeperate::nextValue()
{
uint32 value = streams[ m_current_sample ]->nextValue();
if ((++m_current_sample) >= m_nb_samples)
m_current_sample = 0;
return value;
}

void KisBufferStreamSeperate::restart()
{
m_current_sample = 0;
for (uint8 i = 0; i < m_nb_samples; i++) {
streams[i]->restart();
}
}

void KisBufferStreamSeperate::moveToLine(uint32 lineNumber)
{
for (uint8 i = 0; i < m_nb_samples; i++) {
streams[i]->moveToLine(lineNumber);
}
}
97 changes: 97 additions & 0 deletions plugins/impex/phf/kis_buffer_stream.h
@@ -0,0 +1,97 @@
/*
* Copyright (c) 2005-2006 Cyrille Berger <cberger@cberger.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/

#ifndef _KIS_BUFFER_STREAM_H_
#define _KIS_BUFFER_STREAM_H_

#ifdef _MSC_VER
#define KDEWIN_STDIO_H // Remove KDEWIN extensions to stdio.h
#include <stdio.h>
#endif

#include <tiffio.h>

class KisBufferStreamBase
{
public:
KisBufferStreamBase(uint16 depth) : m_depth(depth) {}
virtual uint32 nextValue() = 0;
virtual void restart() = 0;
virtual void moveToLine(uint32 lineNumber) = 0;
virtual ~KisBufferStreamBase() {}
protected:
uint16 m_depth;
};

class KisBufferStreamContigBase : public KisBufferStreamBase
{
public:
KisBufferStreamContigBase(uint8* src, uint16 depth, uint32 lineSize);
virtual void restart();
virtual void moveToLine(uint32 lineNumber);
virtual ~KisBufferStreamContigBase() {}
protected:
uint8* m_src;
uint8* m_srcIt;
uint8 m_posinc;
uint32 m_lineSize;
};

class KisBufferStreamContigBelow16 : public KisBufferStreamContigBase
{
public:
KisBufferStreamContigBelow16(uint8* src, uint16 depth, uint32 lineSize) : KisBufferStreamContigBase(src, depth, lineSize) { }
public:
virtual ~KisBufferStreamContigBelow16() {}
virtual uint32 nextValue();
};

class KisBufferStreamContigBelow32 : public KisBufferStreamContigBase
{
public:
KisBufferStreamContigBelow32(uint8* src, uint16 depth, uint32 lineSize) : KisBufferStreamContigBase(src, depth, lineSize) { }
public:
virtual ~KisBufferStreamContigBelow32() {}
virtual uint32 nextValue();
};

class KisBufferStreamContigAbove32 : public KisBufferStreamContigBase
{
public:
KisBufferStreamContigAbove32(uint8* src, uint16 depth, uint32 lineSize) : KisBufferStreamContigBase(src, depth, lineSize) { }
public:
virtual ~KisBufferStreamContigAbove32() {}
virtual uint32 nextValue();
};


class KisBufferStreamSeperate : public KisBufferStreamBase
{
public:
KisBufferStreamSeperate(uint8** srcs, uint8 nb_samples , uint16 depth, uint32* lineSize);
virtual ~KisBufferStreamSeperate();
virtual uint32 nextValue();
virtual void restart();
virtual void moveToLine(uint32 lineNumber);
private:
KisBufferStreamContigBase** streams;
uint8 m_current_sample, m_nb_samples;
};

#endif