]> git.sesse.net Git - casparcg/commitdiff
added missing files for psd
authorniklaspandersson <niklas.p.andersson@svt.se>
Fri, 5 Jul 2013 07:06:15 +0000 (09:06 +0200)
committerniklaspandersson <niklas.p.andersson@svt.se>
Fri, 5 Jul 2013 07:06:15 +0000 (09:06 +0200)
modules/psd/doc.h
modules/psd/layer.cpp
modules/psd/psd.cpp [new file with mode: 0644]
modules/psd/psd.h [new file with mode: 0644]
test/psd-test/psd-test.cpp
test/psd-test/psd-test.vcxproj.filters [new file with mode: 0644]

index 6a936d9e74dd1255f131c096e51b1e1e965a6c15..d382b7193146c233044e1c94da7363782fadd944 100644 (file)
@@ -42,15 +42,34 @@ public:
        {
                return layers_;
        }
-       unsigned long width()
+       unsigned long width() const
        {
                return width_;
        }
-       unsigned long height()
+       unsigned long height() const
        {
                return height_;
        }
 
+       psd::color_mode color_mode() const
+       {
+               return color_mode_;
+       }
+
+       unsigned short color_depth() const
+       {
+               return depth_;
+       }
+       unsigned short channels_count() const
+       {
+               return channels_;
+       }
+       const std::wstring& filename() const
+       {
+               return filename_;
+       }
+
+
        bool parse(const std::wstring& s);
 
 private:
@@ -68,7 +87,7 @@ private:
        unsigned long                           width_;
        unsigned long                           height_;
        unsigned short                          depth_;
-       color_mode                                      color_mode_;
+       psd::color_mode                         color_mode_;
 };
 
 }      //namespace psd
index b03db00036425cebe49acea499ca3a5e25b7cbd1..d118317773479558a5b7e5ed2e437b9eb5e93c22 100644 (file)
@@ -198,14 +198,14 @@ void Layer::read_channel_data(BEFileInputStream& stream)
                //determine target bitmap and offset
                if((*it)->id() >= 3)
                        discard_channel = true; //discard channels that doesn't contribute to the final image
-               else if((*it)->id() >= -1)      //RGBA-data
+               else if((*it)->id() >= -1)      //BGRA-data
                {
                        target = img;
                        offset = ((*it)->id() >= 0) ? 2 - (*it)->id() : 3;
                }
                else if(mask)   //mask
                {
-                       if((*it)->id() == -2 && masks_ == 2)    //if there are two mask-channels, discard the the one that's not the total mask for now
+                       if((*it)->id() == -2 && masks_ == 2)    //if there are two mask-channels, discard the the one that's not the total mask
                                discard_channel = true;
                        else
                        {
@@ -214,7 +214,7 @@ void Layer::read_channel_data(BEFileInputStream& stream)
                        }
                }
 
-               unsigned long cp = stream.current_position();   //TODO: remove, for debug purposes only
+               //unsigned long cp = stream.current_position(); //for debug purposes only
                //std::clog << std::dec << "channel_id: " << (*it)->id() << ", reading data from: " << std::hex << cp << ", data_length: " << (*it)->data_length() << std::endl;
 
                if(!target)
@@ -310,34 +310,5 @@ void Layer::read_rle_image_data(BEFileInputStream& stream, const channel_ptr& ch
        }
 }
 
-//
-//image_ptr Layer::read_image(BEFileInputStream& stream)
-//{
-//     if(image == NULL)
-//     {
-//             unsigned char channels = (channels_.size() > 3) ? 4 : 3;
-//
-//             image = std::make_shared<Image>(static_cast<unsigned short>(rect_.width()), static_cast<unsigned short>(rect_.height()),  channels);
-//
-//             channel_ptr pChannel = get_channel(ColorRed);
-//             if(pChannel != NULL)
-//                     pChannel->GetChannelImageData(stream, image, 0);
-//
-//             pChannel = get_channel(ColorGreen);
-//             if(pChannel != NULL)
-//                     pChannel->GetChannelImageData(stream, image, 1);
-//
-//             pChannel = get_channel(ColorBlue);
-//             if(pChannel != NULL)
-//                     pChannel->GetChannelImageData(stream, image, 2);
-//
-//             pChannel = get_channel(Transparency);
-//             if(channels == 4 && pChannel != NULL)
-//                     pChannel->GetChannelImageData(stream, image, 3);
-//     }
-//
-//     return image;
-//}
-
 }      //namespace psd
 }      //namespace caspar
\ No newline at end of file
diff --git a/modules/psd/psd.cpp b/modules/psd/psd.cpp
new file mode 100644 (file)
index 0000000..a0e947c
--- /dev/null
@@ -0,0 +1,77 @@
+/*
+* Copyright (c) 2011 Sveriges Television AB <info@casparcg.com>
+*
+* This file is part of CasparCG (www.casparcg.com).
+*
+* CasparCG 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 3 of the License, or
+* (at your option) any later version.
+*
+* CasparCG 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 CasparCG. If not, see <http://www.gnu.org/licenses/>.
+*
+* Author: Niklas P Andersson, niklas.p.andersson@svt.se
+*/
+
+#include "psd.h"
+#include "layer.h"
+#include "doc.h"
+
+#include <core/frame/pixel_format.h>
+#include <core/frame/frame_factory.h>
+#include <core/producer/frame_producer.h>
+#include <core/producer/scene/scene_producer.h>
+#include <core/producer/scene/const_producer.h>
+#include <core/frame/draw_frame.h>
+
+#include <common/env.h>
+
+#include <boost/filesystem.hpp>
+
+namespace caspar { namespace psd {
+
+void init()
+{
+       core::register_producer_factory(create_producer);
+}
+
+spl::shared_ptr<core::frame_producer> create_producer(const spl::shared_ptr<core::frame_factory>& frame_factory, const core::video_format_desc& format_desc, const std::vector<std::wstring>& params)
+{
+       std::wstring filename = env::media_folder() + L"\\" + params[0] + L".psd";
+       if(!boost::filesystem::is_regular_file(boost::filesystem::path(filename)))
+               return core::frame_producer::empty();
+
+       psd_document doc;
+       if(!doc.parse(filename))
+               return core::frame_producer::empty();
+
+       spl::shared_ptr<core::scene::scene_producer> root(spl::make_shared<core::scene::scene_producer>(doc.width(), doc.height()));
+
+       auto layers_end = doc.layers().end();
+       int cnt = 0;
+       for(auto it = doc.layers().begin(); it != layers_end; ++it)
+       {
+               if((*it)->image())
+               {
+                       core::pixel_format_desc pfd(core::pixel_format::bgra);
+                       pfd.planes.push_back(core::pixel_format_desc::plane((*it)->rect().width(), (*it)->rect().height(), 4));
+
+                       auto frame = frame_factory->create_frame(it->get(), pfd);
+                       memcpy(frame.image_data().data(), (*it)->image()->data(), frame.image_data().size());
+
+                       auto layer_producer = core::create_const_producer(core::draw_frame(std::move(frame)), (*it)->rect().width(), (*it)->rect().height());
+                       root->create_layer(layer_producer, (*it)->rect().left, (*it)->rect().top);
+               }
+       }
+       
+       return root;
+//     return spl::make_shared<scene_producer>(frame_factory, filename + *ext);
+}
+
+}}
\ No newline at end of file
diff --git a/modules/psd/psd.h b/modules/psd/psd.h
new file mode 100644 (file)
index 0000000..7c1245b
--- /dev/null
@@ -0,0 +1,36 @@
+/*
+* Copyright (c) 2011 Sveriges Television AB <info@casparcg.com>
+*
+* This file is part of CasparCG (www.casparcg.com).
+*
+* CasparCG 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 3 of the License, or
+* (at your option) any later version.
+*
+* CasparCG 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 CasparCG. If not, see <http://www.gnu.org/licenses/>.
+*
+* Author: Niklas P Andersson, niklas.p.andersson@svt.se
+*/
+
+#pragma once
+
+#include <core/producer/frame_producer.h>
+
+#include <string>
+#include <vector>
+#include <common/memory.h>
+
+namespace caspar { namespace psd {
+
+void init();
+
+spl::shared_ptr<core::frame_producer> create_producer(const spl::shared_ptr<core::frame_factory>& frame_factory, const core::video_format_desc& format_desc, const std::vector<std::wstring>& params);
+
+}}
\ No newline at end of file
index a3d9a14ef5aa356877d14f856bb4647fc01fccc5..911357daf38bc7558127b320e589b3e2c33f9df4 100644 (file)
@@ -3,11 +3,16 @@
 
 #include "stdafx.h"
 #include "../../modules/psd/doc.h"
+#include <sstream>
 
 int _tmain(int argc, _TCHAR* argv[])
 {
-       caspar::psd::Document doc;
+       caspar::psd::psd_document doc;
        doc.parse(L"C:\\Lokala Filer\\Utveckling\\CasparCG\\Server 2.1\\test\\data\\test1.psd");
+
+       std::wstringstream trace;
+
+       trace << L"<doc filename=\"" << doc.filename() << L"\" channel_count=\"" << doc.channels_count() << L"\" width=\"" << doc.width() << "\" 
        int a = 42;
        return 0;
 }
diff --git a/test/psd-test/psd-test.vcxproj.filters b/test/psd-test/psd-test.vcxproj.filters
new file mode 100644 (file)
index 0000000..6dbdae7
--- /dev/null
@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <ItemGroup>
+    <Filter Include="Source Files">
+      <UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
+      <Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
+    </Filter>
+    <Filter Include="Header Files">
+      <UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
+      <Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions>
+    </Filter>
+    <Filter Include="Resource Files">
+      <UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
+      <Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
+    </Filter>
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="ReadMe.txt" />
+  </ItemGroup>
+  <ItemGroup>
+    <ClInclude Include="stdafx.h">
+      <Filter>Header Files</Filter>
+    </ClInclude>
+    <ClInclude Include="targetver.h">
+      <Filter>Header Files</Filter>
+    </ClInclude>
+  </ItemGroup>
+  <ItemGroup>
+    <ClCompile Include="stdafx.cpp">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+    <ClCompile Include="psd-test.cpp">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+  </ItemGroup>
+</Project>
\ No newline at end of file