]> git.sesse.net Git - casparcg/blobdiff - modules/psd/descriptor.cpp
[scene_producer] Added possibility to CALL/CG PLAY/CG STOP/CG NEXT/CG INVOKE layers...
[casparcg] / modules / psd / descriptor.cpp
index c512b20734d556da1c3615f01d883d2fa3a730f5..56a3ed6681976010241b6046ab7fbe5c8a24bfaa 100644 (file)
 * Author: Niklas P Andersson, niklas.p.andersson@svt.se
 */
 
-#include <memory>
 #include "descriptor.h"
-#include <boost\property_tree\ptree.hpp>
 #include "misc.h"
+#include "util/pdf_reader.h"
+
+#include <common/log.h>
+
+#include <boost/property_tree/ptree.hpp>
+#include <boost/property_tree/xml_parser.hpp>
+#include <boost/locale.hpp>
+
+#include <memory>
 
 namespace caspar { namespace psd {
 
@@ -42,7 +49,7 @@ namespace caspar { namespace psd {
                }
        };
 
-       descriptor::descriptor() : context_(std::make_shared<context>())
+       descriptor::descriptor(const std::wstring& debug_name) : context_(std::make_shared<context>(debug_name))
        {
                context_->stack.push_back(&context_->root);
        }
@@ -57,34 +64,26 @@ namespace caspar { namespace psd {
                context_->stack.pop_back();
        }
 
-bool descriptor::populate(BEFileInputStream& stream)
+void descriptor::populate(bigendian_file_input_stream& stream)
 {
-       bool result = true;
-
-       try
-       {
-               stream.read_unicode_string();
-               stream.read_id_string();
-               unsigned long element_count = stream.read_long();
-               for(int element_index = 0; element_index < element_count; ++element_index)
-               {
-                       std::wstring key = stream.read_id_string();
-                       read_value(key, stream);
-               }
-       }
-       catch(std::exception& ex)
+       stream.read_unicode_string();
+       stream.read_id_string();
+       int element_count = stream.read_long();
+       for (int element_index = 0; element_index < element_count; ++element_index)
        {
-               result = false;
+               std::wstring key = stream.read_id_string();
+               read_value(key, stream);
        }
 
-       return result;
+       if (context_->stack.size() == 1)
+               log::print_child(boost::log::trivial::trace, context_->debug_name + L": ", L"", context_->root);
 }
 
-void descriptor::read_value(const std::wstring& key, BEFileInputStream& stream)
+void descriptor::read_value(const std::wstring& key, bigendian_file_input_stream& stream)
 {
-       unsigned int type = stream.read_long();
+       auto value_type = stream.read_long();
 
-       switch(type)
+       switch(value_type)
        {
        case 'Objc': 
                {
@@ -107,13 +106,16 @@ void descriptor::read_value(const std::wstring& key, BEFileInputStream& stream)
 
        case 'enum':
                {
-                       context_->stack.back()->put(stream.read_id_string(), stream.read_id_string());
+                       auto k = stream.read_id_string();
+                       auto v = stream.read_id_string();
+                       context_->stack.back()->put(k, v);
                }
                break;
 
        case 'long':
                {
-                       context_->stack.back()->put(key, stream.read_long());
+                       std::int32_t value = stream.read_long();
+                       context_->stack.back()->put(key, value);
                }
                break;
 
@@ -126,36 +128,45 @@ void descriptor::read_value(const std::wstring& key, BEFileInputStream& stream)
        case 'VlLs': 
                {
                        context::scoped_holder list(key, context_);
-                       unsigned long count = stream.read_long();
-                       for(int i = 0; i < count; ++i)
+                       int count = stream.read_long();
+
+                       for (int i = 0; i < count; ++i)
                        {
-                               read_value(L"", stream);
+                               read_value(L"li", stream);
                        }
                }
                break;
 
        case 'tdta':
                {
-                       unsigned long rawdata_length = stream.read_long();
+                       auto rawdata_length = stream.read_long();
                        std::vector<char> rawdata(rawdata_length);
                        stream.read(rawdata.data(), rawdata_length);
-
                        std::wstring data_str(rawdata.begin(), rawdata.end());
                        context_->stack.back()->put(key, data_str);
                }
                break;
 
-       case 'obj ': 
        case 'UntF': 
+               {
+                       context::scoped_holder list(key, context_);
+                       auto unit = stream.read_long();
+                       std::string type(reinterpret_cast<char*>(&unit), 4);
+                       std::wstring wtype(type.rbegin(), type.rend());
+                       context_->stack.back()->put(wtype, stream.read_double());
+               }
+               break;
+
+       case 'obj ': 
        case 'GlbO': 
        case 'type':
        case 'GlbC':
        case 'alis':
        default:
                //descriptor type not supported yet
-               throw PSDFileFormatException();
+               CASPAR_THROW_EXCEPTION(psd_file_format_exception() << msg_info("descriptor type not supported yet"));
        }
 }
 
 }      //namespace psd
-}      //namespace caspar
\ No newline at end of file
+}      //namespace caspar