17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/Counter/instance_factory.hpp:
--------------------------------------------------------------------------------
1 | #ifndef INSTANCE_FACTORY_HPP
2 | #define INSTANCE_FACTORY_HPP
3 |
4 | #include "ppapi/cpp/instance.h"
5 | #include "ppapi/cpp/module.h"
6 | #include "ppapi/cpp/var.h"
7 |
8 | // Factory method called by the browser when first loaded
9 | namespace pp {
10 | Module* CreateModule();
11 | };
12 |
13 | // Module used to create instance of NaCl module on webpage
14 | template
15 | class InstanceFactory : public pp::Module {
16 | public:
17 | InstanceFactory( ){};
18 | virtual ~InstanceFactory(){};
19 | virtual pp::Instance* CreateInstance( PP_Instance instance ) {
20 | return new T(instance);
21 | };
22 | };
23 |
24 | #endif
25 |
--------------------------------------------------------------------------------
/GettingStarted/Makefile:
--------------------------------------------------------------------------------
1 | # Copyright (c) 2013 The Native Client Authors. All rights reserved.
2 | # Use of this source code is governed by a BSD-style license that can be
3 | # found in the LICENSE file.
4 |
5 | #
6 | # GNU Make based build file. For details on GNU Make see:
7 | # http://www.gnu.org/software/make/manual/make.html
8 | #
9 |
10 | #
11 | # Get pepper directory for toolchain and includes.
12 | #
13 | # If NACL_SDK_ROOT is not set, then assume it can be found three directories up.
14 | #
15 | THIS_MAKEFILE := $(abspath $(lastword $(MAKEFILE_LIST)))
16 | NACL_SDK_ROOT ?= $(abspath $(dir $(THIS_MAKEFILE))../..)
17 |
18 | # Project Build flags
19 | WARNINGS := -Wno-long-long -Wall -Wswitch-enum -pedantic -Werror
20 | # CXXFLAGS := -pthread -std=gnu++98 $(WARNINGS)
21 | CXXFLAGS := -pthread -std=c++11 $(WARNINGS)
22 |
23 | #
24 | # Compute tool paths
25 | #
26 | GETOS := python $(NACL_SDK_ROOT)/tools/getos.py
27 | OSHELPERS = python $(NACL_SDK_ROOT)/tools/oshelpers.py
28 | OSNAME := $(shell $(GETOS))
29 | RM := $(OSHELPERS) rm
30 |
31 | PNACL_TC_PATH := $(abspath $(NACL_SDK_ROOT)/toolchain/$(OSNAME)_pnacl)
32 | PNACL_CXX := $(PNACL_TC_PATH)/bin/pnacl-clang++
33 | PNACL_FINALIZE := $(PNACL_TC_PATH)/bin/pnacl-finalize
34 | CXXFLAGS := -I$(NACL_SDK_ROOT)/include -std=c++11
35 | LDFLAGS := -L$(NACL_SDK_ROOT)/lib/pnacl/Release -lppapi_cpp -lppapi
36 |
37 | #
38 | # Disable DOS PATH warning when using Cygwin based tools Windows
39 | #
40 | CYGWIN ?= nodosfilewarning
41 | export CYGWIN
42 |
43 |
44 | # Declare the ALL target first, to make the 'all' target the default build
45 | all: hello_tutorial.pexe
46 |
47 | clean:
48 | $(RM) hello_tutorial.pexe hello_tutorial.bc
49 |
50 | hello_tutorial.bc: hello_tutorial.cc
51 | $(PNACL_CXX) -o $@ $< -O2 $(CXXFLAGS) $(LDFLAGS)
52 |
53 | hello_tutorial.pexe: hello_tutorial.bc
54 | $(PNACL_FINALIZE) -o $@ $<
55 |
56 |
57 | #
58 | # Makefile target to run the SDK's simple HTTP server and serve this example.
59 | #
60 | HTTPD_PY := python httpd.py
61 |
62 | .PHONY: serve
63 | serve: all
64 | $(HTTPD_PY) -C $(CURDIR)
65 |
--------------------------------------------------------------------------------
/GettingStarted/README.md:
--------------------------------------------------------------------------------
1 | Getting Started
2 | ===============
3 | Getting Started example from Pepper 31.
4 | Includes the modifications described in the tutorial, plus use of
5 | some C++11 features.
6 |
--------------------------------------------------------------------------------
/GettingStarted/hello_tutorial.cc:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style license that can be
3 | // found in the LICENSE file.
4 |
5 | /// @file hello_tutorial.cc
6 | /// This example demonstrates loading, running and scripting a very simple NaCl
7 | /// module. To load the NaCl module, the browser first looks for the
8 | /// CreateModule() factory method (at the end of this file). It calls
9 | /// CreateModule() once to load the module code. After the code is loaded,
10 | /// CreateModule() is not called again.
11 | ///
12 | /// Once the code is loaded, the browser calls the CreateInstance()
13 | /// method on the object returned by CreateModule(). It calls CreateInstance()
14 | /// each time it encounters an
94 |
95 |
Status NO-STATUS
96 |
97 |
98 |
--------------------------------------------------------------------------------
/ImageProc/Makefile:
--------------------------------------------------------------------------------
1 | # Project Build flags
2 | WARNINGS := -Wno-long-long -Wall -pedantic -Werror # -Wswitch-enum -pedantic -Werror
3 | CXXFLAGS := -pthread -std=gnu++11 $(WARNINGS)
4 |
5 | #
6 | # Compute tool paths
7 | #
8 | GETOS := python $(NACL_SDK_ROOT)/tools/getos.py
9 | OSHELPERS = python $(NACL_SDK_ROOT)/tools/oshelpers.py
10 | OSNAME := $(shell $(GETOS))
11 | RM := $(OSHELPERS) rm
12 |
13 | PNACL_TC_PATH := $(abspath $(NACL_SDK_ROOT)/toolchain/$(OSNAME)_pnacl)
14 | PNACL_CXX := $(PNACL_TC_PATH)/bin/pnacl-clang++
15 | PNACL_FINALIZE := $(PNACL_TC_PATH)/bin/pnacl-finalize
16 | PNACL_CXXFLAGS := -I$(NACL_SDK_ROOT)/include $(CXXFLAGS)
17 | LDFLAGS := -lopencv_objdetect -lopencv_imgproc -lopencv_core -lz
18 | PNACL_LDFLAGS := -L$(NACL_SDK_ROOT)/lib/pnacl/Release -lppapi_cpp -lppapi -lpthread $(LDFLAGS)
19 |
20 | PROCESSORS := $(wildcard processor_*.cpp)
21 | PROC_OBJECTS := $(PROCESSORS:.cpp=.bc)
22 |
23 | IMPROC_HEADERS := image_proc.cpp image_proc.hpp instance_factory.hpp improc_instance.hpp singleton_factory.hpp
24 |
25 | # Declare the ALL target first, to make the 'all' target the default build
26 | all: image_proc.pexe
27 |
28 | # Create individual test
29 | .PHONY: test
30 | test:
31 | g++ -g -o test_display test_display.cpp $(PROC) -std=c++0x -lopencv_highgui $(LDFLAGS)
32 |
33 | .PHONY: test_processor
34 | test_processor: test_processor.cpp singleton_factory.hpp $(PROCESSORS)
35 | g++ -g -o test_processor test_processor.cpp $(PROCESSORS) -std=c++0x $(LDFLAGS)
36 |
37 | clean:
38 | $(RM) image_proc.pexe image_proc.bc
39 |
40 | #$(PROC_OBJECTS): $(PROCESSORS) singleton_factory.hpp
41 | # $(PNACL_CXX) -o $@ $< -O2 $(CXXFLAGS) $(LDFLAGS)
42 |
43 | image_proc.bc: $(IMPROC_HEADERS) $(PROCESSORS) url_loader_handler.cpp
44 | $(PNACL_CXX) -o $@ $< $(PROCESSORS) url_loader_handler.cpp -O2 $(PNACL_CXXFLAGS) $(PNACL_LDFLAGS)
45 |
46 | image_proc.pexe: image_proc.bc
47 | $(PNACL_FINALIZE) -o $@ $<
48 |
49 | serve:
50 | python -m SimpleHTTPServer 8000
51 |
--------------------------------------------------------------------------------
/ImageProc/README.md:
--------------------------------------------------------------------------------
1 | Image Processing
2 | ================
3 | Image processing using Native Client. The goal of this project is to use
4 | the C++ OpenCV image processing library to do realtime image processing of
5 | the webcam feed.
6 |
7 | Implementation
8 | --------------
9 | Rough plan for next few commits:
10 |
11 | - [x] Hidden HTML5 __video__ element sourced from navigator.getUserMedia (webcam).
12 | - [x] Canvas element samples video every 20ms and draws on the canvas.
13 | - [x] Send canvas image as ArrayBuffer to Native Client.
14 | - [x] NaCl echoes image that has been received.
15 | - [x] Javascript puts echoed image to __processed__ canvas.
16 | - [x] Start playing with OpenCV image processing.
17 | - [x] Use strategy pattern on the C++ side to register new image
18 | processors.
19 | - [x] Modify NaCl getVersion interface to return list of available processors.
20 | - [x] Use returned list of processors to populate js list selector.
21 | - [ ] Get the [Pulse Detection](http://people.csail.mit.edu/mrub/vidmag/) filter working.
22 | - [x] Get the [Detecting
23 | Barcodes](http://www.pyimagesearch.com/2014/11/24/detecting-barcodes-images-python-opencv) demo working.
24 | - [x] Simple cartoon filter.
25 | - [x] Face detection.
26 |
27 | [Try it out!](https://www.matt-mcdonnell.com/code/NaCl/ImageProc/index.html) - you may need
28 | to clear the cache to see any updates. To do this open Chrome Developer Tools (Ctrl-Shift-i or F12),
29 | then click and hold Reload, choose "Empty Cache and Hard Reload" from the popup menu. Popup menu may
30 | only appear if you have a cached page i.e. have previously visited.
31 |
32 | Build Setup
33 | -----------
34 | UPDATED: Please see setup.txt in parent directory for a step by step setup on a new Ubuntu server.
35 |
36 | There are a few steps needed to configure in order to use OpenCV with NaCl.
37 | Fortunately, once you become aware of the existence of [NaCl Ports](https://code.google.com/p/naclports/)
38 | they are fairly straight forward.
39 |
40 | 1. Install [Depo Tools](http://dev.chromium.org/developers/how-tos/install-depot-tools).
41 | 2. [Check out the NaCl Ports](https://code.google.com/p/naclports/wiki/HowTo_Checkout).
42 | 2. ~~Follow the [Install guide for SDL](https://code.google.com/p/naclports/wiki/InstallingSDL),
43 | replacing __sdl__ with __opencv__ and choosing pnacl as the architecture to
44 | build.~~
45 | Seems like the original instructions have been deleted, and didn't cover
46 | which branch to use in any event. cd to the dir where you've checked
47 | out nacl_ports (for me ~/Work/ExternCode/nacl_ports/src ) with depotools
48 | then change to the branch that matches NACL_SDK_ROOT
49 |
50 | git checkout pepper_40
51 | NACL_ARCH=pnacl make opencv
52 |
53 | The build itself took about 15 minutes on my Intel i3 dual core laptop.
54 |
55 | 3. Add the opencv libraries and zlib to the build arguments:
56 |
57 | LDFLAGS := -L$(NACL_SDK_ROOT)/lib/pnacl/Release -lppapi_cpp -lppapi -lopencv_core -lz
58 |
59 | Updating NaCl and NaCl Ports
60 | ----------------------------
61 | NaCl updates on around the same release cycle as the Chrome browser.
62 | Chrome itself is backwards compatible but it's still a good idea to keep
63 | roughly up to date.
64 |
65 | Here we assume that the NaCl SDK has been installed in NACL_ROOT
66 | (NACL_SDK_ROOT will be under this), and NaCl ports has been installed in
67 | PORTS_ROOT. On my machine these are ~/Work/ExternCode/nacl_sdk and
68 | ~/Work/ExternCode/nacl_ports respectively.
69 |
70 | 1. Update NaCl SDK
71 | - cd NACL_ROOT
72 | - ./naclsdk update
73 | 2. Update NACL_SDK_ROOT environment variable e.g. NACL_ROOT/pepper_41
74 | 3. Update ports
75 | - cd PORTS_ROOT
76 | - cd src
77 | - git checkout -b pepper_41 origin/pepper_41
78 | - gclient sync
79 | - (If that fails, cd .. vim .gclient and set managed=False)
80 |
81 | LICENSE
82 | -------
83 | BSD
84 |
--------------------------------------------------------------------------------
/ImageProc/deploy:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | sshfs $SERVER_ID:$SERVER_IMAGEPROC_LOC $SERVER_MOUNT
3 | echo Copying files to server
4 | cp $LOCAL_IMAGEPROC_LOC/{image_proc.pexe,image_proc.nmf,index.html,video.js,video_img.js,smiley_200x200.png} $SERVER_MOUNT
5 | echo Unmounting sshfs
6 | fusermount -u $SERVER_MOUNT
7 |
--------------------------------------------------------------------------------
/ImageProc/face_detector.hpp:
--------------------------------------------------------------------------------
1 | #ifndef FACE_DETECTOR_HPP
2 | #define FACE_DETECTOR_HPP
3 |
4 | #include "processor.hpp"
5 |
6 | class FaceDetector : public Processor {
7 | public:
8 | virtual void detectFaces(const cv::Mat, std::vector&)=0;
9 | };
10 |
11 | #endif
12 |
--------------------------------------------------------------------------------
/ImageProc/image_proc.cpp:
--------------------------------------------------------------------------------
1 | #include "improc_instance.hpp"
2 | #include "singleton_factory.hpp"
3 | #include "url_loader_handler.hpp"
4 | #include
5 | #include
6 | #include
7 |
8 | pp::Module* pp::CreateModule()
9 | {
10 | return new InstanceFactory();
11 | }
12 |
13 | void ImageProcInstance::Process( cv::Mat im)
14 | {
15 | auto result = (*processor)( im );
16 | auto nBytes = result.elemSize() * result.total();
17 | pp::VarDictionary msg;
18 | pp::VarArrayBuffer data(nBytes);
19 | uint8_t* copy = static_cast( data.Map());
20 | memcpy( copy, result.data, nBytes );
21 |
22 | msg.Set( "Type", "completed" );
23 | msg.Set( "Data", data );
24 | msg.Set( "Parameters", processor->getParameters());
25 | PostMessage( msg );
26 | }
27 |
28 | void ImageProcInstance::PostTest()
29 | {
30 | pp::VarDictionary msg;
31 | msg.Set( "Type", "completed" );
32 | msg.Set( "Data", "Processed ok" );
33 | PostMessage( msg );
34 | }
35 |
36 | void ImageProcInstance::SendStatus(const std::string& status)
37 | {
38 | pp::VarDictionary msg;
39 | msg.Set( "Type", "status" );
40 | msg.Set( "Message", status );
41 | PostMessage( msg );
42 | }
43 |
44 |
45 | void ImageProcInstance::HandleMessage( const pp::Var& var_message )
46 | {
47 | // Interface: receive a { cmd: ..., args... } dictionary
48 | pp::VarDictionary var_dict( var_message );
49 | auto cmd = var_dict.Get( "cmd" ).AsString();
50 | if ( cmd == "process" ) {
51 |
52 | // Message is number of simulations to run
53 | auto width = var_dict.Get("width").AsInt();
54 | auto height = var_dict.Get("height").AsInt();
55 | auto data = pp::VarArrayBuffer( var_dict.Get("data") );
56 | auto selectedProcessor = var_dict.Get("processor").AsString();
57 | bool newProcessor = selectedProcessor != processorName;
58 | if ( newProcessor ) {
59 | SendStatus("Creating processor factory");
60 | auto processorFactory = SingletonFactory<
61 | std::function()> >::getInstance();
62 | SendStatus("Creating processor");
63 | processor = processorFactory.getObject( selectedProcessor )();
64 | processorName = selectedProcessor;
65 | } else {
66 | SendStatus("Reusing processor");
67 | }
68 | // Convert data to CMat
69 | // SendStatus("Casting to byte array");
70 | uint8_t* byteData = static_cast(data.Map());
71 | // SendStatus("Creating cv::Mat");
72 | auto Img = cv::Mat(height, width, CV_8UC4, byteData );
73 | // SendStatus("Calling processing");
74 |
75 | // Special case: Smiley
76 | if ( (selectedProcessor == "Smiley!") && newProcessor ) {
77 | // Only send the image data for overlay on the first time we change
78 | // processor
79 | pp::VarDictionary sm_var_dict( var_dict.Get( "args" ));
80 | auto sm_width = sm_var_dict.Get("width").AsInt();
81 | auto sm_height = sm_var_dict.Get("height").AsInt();
82 | auto sm_data = pp::VarArrayBuffer( sm_var_dict.Get("data") );
83 | uint8_t* sm_byteData = static_cast(sm_data.Map());
84 | auto sm_Img = cv::Mat(sm_height, sm_width, CV_8UC4, sm_byteData );
85 | processor->init( sm_Img );
86 | } else if ( var_dict.HasKey( "args" ) ) {
87 | // Args key is json string that processor will parse
88 | auto json = var_dict.Get("args").AsString();
89 | processor->init( json.c_str() );
90 | }
91 | Process( Img );
92 | } else if ( cmd == "test" ) {
93 | PostTest();
94 | } else if ( cmd == "echo" ) {
95 | auto data = pp::VarArrayBuffer( var_dict.Get("data") );
96 | // auto result = data.is_array_buffer();
97 | pp::VarDictionary msg;
98 | msg.Set( "Type", "completed" );
99 | msg.Set( "Data", data );
100 | PostMessage( msg );
101 | } else if ( cmd == "load" ) {
102 | // Load resource URL
103 | auto url = var_dict.Get( "url" ).AsString();
104 | URLLoaderHandler* handler = URLLoaderHandler::Create(this, url);
105 | if (handler != NULL) {
106 | // Starts asynchronous download. When download is finished or when an
107 | // error occurs, |handler| posts the results back to the browser
108 | // vis PostMessage and self-destroys.
109 | handler->Start();
110 | }
111 | } else {
112 | // Disable simulation - background thread will see this at start of
113 | // next iteration and terminate early
114 | run_simulation_ = false;
115 | }
116 | }
117 |
--------------------------------------------------------------------------------
/ImageProc/image_proc.hpp:
--------------------------------------------------------------------------------
1 | #ifndef IMAGE_PROC_HPP
2 | #define IMAGE_PROC_HPP
3 |
4 | #include
5 |
6 | class ImageProc {
7 | public:
8 | explicit ImageProc() {
9 | };
10 | virtual ~ImageProc() {};
11 | cv::Mat process( std::function const& f, cv::Mat im ) {
12 | return f(im);
13 | };
14 | cv::Mat process(cv::Mat im) {
15 | auto f = [](cv::Mat x){ return x; };
16 | return process(f,im);
17 | }
18 | };
19 |
20 | #endif
21 |
--------------------------------------------------------------------------------
/ImageProc/image_proc.nmf:
--------------------------------------------------------------------------------
1 | { "program" :
2 | { "portable" :
3 | { "pnacl-translate" :
4 | { "url" : "image_proc.pexe"
5 | }
6 | }
7 | }
8 | }
9 |
--------------------------------------------------------------------------------
/ImageProc/improc_instance.hpp:
--------------------------------------------------------------------------------
1 | #ifndef IMPROC_INSTANCE
2 | #define IMPROC_INSTANCE
3 |
4 | #include "singleton_factory.hpp"
5 | #include "instance_factory.hpp"
6 | #include "image_proc.hpp"
7 | #include "ppapi/cpp/var_dictionary.h"
8 | #include "ppapi/cpp/var_array.h"
9 | #include "ppapi/cpp/var_array_buffer.h"
10 | #include "ppapi/utility/completion_callback_factory.h"
11 | #include "ppapi/utility/threading/simple_thread.h"
12 |
13 | // The ImageProcInstance that stores
14 | class ImageProcInstance : public pp::Instance {
15 | public:
16 | explicit ImageProcInstance( PP_Instance instance )
17 | : pp::Instance(instance), callback_factory_(this), proc_thread_(this) {};
18 | virtual ~ImageProcInstance( ){ proc_thread_.Join(); };
19 | virtual void HandleMessage( const pp::Var& );
20 | virtual bool Init(uint32_t /*argc*/,
21 | const char * /*argn*/ [],
22 | const char * /*argv*/ []) {
23 | proc_thread_.Start();
24 | proc_thread_.message_loop().PostWork(
25 | callback_factory_.NewCallback( &ImageProcInstance::Version ));
26 | return true;
27 | }
28 |
29 | private:
30 | bool run_simulation_;
31 | std::string processorName; // Name of currently selected processor
32 | std::unique_ptr processor;
33 | pp::CompletionCallbackFactory callback_factory_;
34 | pp::SimpleThread proc_thread_; // Thread for image processor
35 | void Process(cv::Mat);
36 | void PostTest();
37 | void SendStatus(const std::string& status);
38 | pp::VarDictionary PostResponse( cv::Mat );
39 | void Version( int32_t ) {
40 | pp::VarDictionary msg;
41 | msg.Set( "Type", "version" );
42 | msg.Set( "Version", "Image Processor 0.4.1" );
43 | // Get processor
44 | auto processorFactory = SingletonFactory()>>::getInstance();
45 | auto processorList = processorFactory.getNames();
46 | pp::VarArray msgProcessorList;
47 | for ( size_t i=0; i < processorList.size(); i ++ ) {
48 | msgProcessorList.Set( i, processorList[i] );
49 | }
50 | msg.Set( "Processors", msgProcessorList );
51 | PostMessage( msg );
52 | }
53 | };
54 |
55 | #endif
56 |
--------------------------------------------------------------------------------
/ImageProc/include/catch/LICENSE_1_0.txt:
--------------------------------------------------------------------------------
1 | Boost Software License - Version 1.0 - August 17th, 2003
2 |
3 | Permission is hereby granted, free of charge, to any person or organization
4 | obtaining a copy of the software and accompanying documentation covered by
5 | this license (the "Software") to use, reproduce, display, distribute,
6 | execute, and transmit the Software, and to prepare derivative works of the
7 | Software, and to permit third-parties to whom the Software is furnished to
8 | do so, all subject to the following:
9 |
10 | The copyright notices in the Software and this entire statement, including
11 | the above license grant, this restriction and the following disclaimer,
12 | must be included in all copies of the Software, in whole or in part, and
13 | all derivative works of the Software, unless such copies or derivative
14 | works are solely in the form of machine-executable object code generated by
15 | a source language processor.
16 |
17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 | FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
20 | SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
21 | FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
22 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23 | DEALINGS IN THE SOFTWARE.
24 |
--------------------------------------------------------------------------------
/ImageProc/include/rapidjson/error/en.h:
--------------------------------------------------------------------------------
1 | // Tencent is pleased to support the open source community by making RapidJSON available.
2 | //
3 | // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved.
4 | //
5 | // Licensed under the MIT License (the "License"); you may not use this file except
6 | // in compliance with the License. You may obtain a copy of the License at
7 | //
8 | // http://opensource.org/licenses/MIT
9 | //
10 | // Unless required by applicable law or agreed to in writing, software distributed
11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
13 | // specific language governing permissions and limitations under the License.
14 |
15 | #ifndef RAPIDJSON_ERROR_EN_H__
16 | #define RAPIDJSON_ERROR_EN_H__
17 |
18 | #include "error.h"
19 |
20 | RAPIDJSON_NAMESPACE_BEGIN
21 |
22 | //! Maps error code of parsing into error message.
23 | /*!
24 | \ingroup RAPIDJSON_ERRORS
25 | \param parseErrorCode Error code obtained in parsing.
26 | \return the error message.
27 | \note User can make a copy of this function for localization.
28 | Using switch-case is safer for future modification of error codes.
29 | */
30 | inline const RAPIDJSON_ERROR_CHARTYPE* GetParseError_En(ParseErrorCode parseErrorCode) {
31 | switch (parseErrorCode) {
32 | case kParseErrorNone: return RAPIDJSON_ERROR_STRING("No error.");
33 |
34 | case kParseErrorDocumentEmpty: return RAPIDJSON_ERROR_STRING("The document is empty.");
35 | case kParseErrorDocumentRootNotSingular: return RAPIDJSON_ERROR_STRING("The document root must not follow by other values.");
36 |
37 | case kParseErrorValueInvalid: return RAPIDJSON_ERROR_STRING("Invalid value.");
38 |
39 | case kParseErrorObjectMissName: return RAPIDJSON_ERROR_STRING("Missing a name for object member.");
40 | case kParseErrorObjectMissColon: return RAPIDJSON_ERROR_STRING("Missing a colon after a name of object member.");
41 | case kParseErrorObjectMissCommaOrCurlyBracket: return RAPIDJSON_ERROR_STRING("Missing a comma or '}' after an object member.");
42 |
43 | case kParseErrorArrayMissCommaOrSquareBracket: return RAPIDJSON_ERROR_STRING("Missing a comma or ']' after an array element.");
44 |
45 | case kParseErrorStringUnicodeEscapeInvalidHex: return RAPIDJSON_ERROR_STRING("Incorrect hex digit after \\u escape in string.");
46 | case kParseErrorStringUnicodeSurrogateInvalid: return RAPIDJSON_ERROR_STRING("The surrogate pair in string is invalid.");
47 | case kParseErrorStringEscapeInvalid: return RAPIDJSON_ERROR_STRING("Invalid escape character in string.");
48 | case kParseErrorStringMissQuotationMark: return RAPIDJSON_ERROR_STRING("Missing a closing quotation mark in string.");
49 | case kParseErrorStringInvalidEncoding: return RAPIDJSON_ERROR_STRING("Invalid encoding in string.");
50 |
51 | case kParseErrorNumberTooBig: return RAPIDJSON_ERROR_STRING("Number too big to be stored in double.");
52 | case kParseErrorNumberMissFraction: return RAPIDJSON_ERROR_STRING("Miss fraction part in number.");
53 | case kParseErrorNumberMissExponent: return RAPIDJSON_ERROR_STRING("Miss exponent in number.");
54 |
55 | case kParseErrorTermination: return RAPIDJSON_ERROR_STRING("Terminate parsing due to Handler error.");
56 | case kParseErrorUnspecificSyntaxError: return RAPIDJSON_ERROR_STRING("Unspecific syntax error.");
57 |
58 | default:
59 | return RAPIDJSON_ERROR_STRING("Unknown error.");
60 | }
61 | }
62 |
63 | RAPIDJSON_NAMESPACE_END
64 |
65 | #endif // RAPIDJSON_ERROR_EN_H__
66 |
--------------------------------------------------------------------------------
/ImageProc/include/rapidjson/error/error.h:
--------------------------------------------------------------------------------
1 | // Tencent is pleased to support the open source community by making RapidJSON available.
2 | //
3 | // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved.
4 | //
5 | // Licensed under the MIT License (the "License"); you may not use this file except
6 | // in compliance with the License. You may obtain a copy of the License at
7 | //
8 | // http://opensource.org/licenses/MIT
9 | //
10 | // Unless required by applicable law or agreed to in writing, software distributed
11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
13 | // specific language governing permissions and limitations under the License.
14 |
15 | #ifndef RAPIDJSON_ERROR_ERROR_H__
16 | #define RAPIDJSON_ERROR_ERROR_H__
17 |
18 | #include "../rapidjson.h"
19 |
20 | /*! \file error.h */
21 |
22 | /*! \defgroup RAPIDJSON_ERRORS RapidJSON error handling */
23 |
24 | ///////////////////////////////////////////////////////////////////////////////
25 | // RAPIDJSON_ERROR_CHARTYPE
26 |
27 | //! Character type of error messages.
28 | /*! \ingroup RAPIDJSON_ERRORS
29 | The default character type is \c char.
30 | On Windows, user can define this macro as \c TCHAR for supporting both
31 | unicode/non-unicode settings.
32 | */
33 | #ifndef RAPIDJSON_ERROR_CHARTYPE
34 | #define RAPIDJSON_ERROR_CHARTYPE char
35 | #endif
36 |
37 | ///////////////////////////////////////////////////////////////////////////////
38 | // RAPIDJSON_ERROR_STRING
39 |
40 | //! Macro for converting string literial to \ref RAPIDJSON_ERROR_CHARTYPE[].
41 | /*! \ingroup RAPIDJSON_ERRORS
42 | By default this conversion macro does nothing.
43 | On Windows, user can define this macro as \c _T(x) for supporting both
44 | unicode/non-unicode settings.
45 | */
46 | #ifndef RAPIDJSON_ERROR_STRING
47 | #define RAPIDJSON_ERROR_STRING(x) x
48 | #endif
49 |
50 | RAPIDJSON_NAMESPACE_BEGIN
51 |
52 | ///////////////////////////////////////////////////////////////////////////////
53 | // ParseErrorCode
54 |
55 | //! Error code of parsing.
56 | /*! \ingroup RAPIDJSON_ERRORS
57 | \see GenericReader::Parse, GenericReader::GetParseErrorCode
58 | */
59 | enum ParseErrorCode {
60 | kParseErrorNone = 0, //!< No error.
61 |
62 | kParseErrorDocumentEmpty, //!< The document is empty.
63 | kParseErrorDocumentRootNotSingular, //!< The document root must not follow by other values.
64 |
65 | kParseErrorValueInvalid, //!< Invalid value.
66 |
67 | kParseErrorObjectMissName, //!< Missing a name for object member.
68 | kParseErrorObjectMissColon, //!< Missing a colon after a name of object member.
69 | kParseErrorObjectMissCommaOrCurlyBracket, //!< Missing a comma or '}' after an object member.
70 |
71 | kParseErrorArrayMissCommaOrSquareBracket, //!< Missing a comma or ']' after an array element.
72 |
73 | kParseErrorStringUnicodeEscapeInvalidHex, //!< Incorrect hex digit after \\u escape in string.
74 | kParseErrorStringUnicodeSurrogateInvalid, //!< The surrogate pair in string is invalid.
75 | kParseErrorStringEscapeInvalid, //!< Invalid escape character in string.
76 | kParseErrorStringMissQuotationMark, //!< Missing a closing quotation mark in string.
77 | kParseErrorStringInvalidEncoding, //!< Invalid encoding in string.
78 |
79 | kParseErrorNumberTooBig, //!< Number too big to be stored in double.
80 | kParseErrorNumberMissFraction, //!< Miss fraction part in number.
81 | kParseErrorNumberMissExponent, //!< Miss exponent in number.
82 |
83 | kParseErrorTermination, //!< Parsing was terminated.
84 | kParseErrorUnspecificSyntaxError //!< Unspecific syntax error.
85 | };
86 |
87 | //! Result of parsing (wraps ParseErrorCode)
88 | /*!
89 | \ingroup RAPIDJSON_ERRORS
90 | \code
91 | Document doc;
92 | ParseResult ok = doc.Parse("[42]");
93 | if (!ok) {
94 | fprintf(stderr, "JSON parse error: %s (%u)",
95 | GetParseError_En(ok.Code()), ok.Offset());
96 | exit(EXIT_FAILURE);
97 | }
98 | \endcode
99 | \see GenericReader::Parse, GenericDocument::Parse
100 | */
101 | struct ParseResult {
102 |
103 | //! Default constructor, no error.
104 | ParseResult() : code_(kParseErrorNone), offset_(0) {}
105 | //! Constructor to set an error.
106 | ParseResult(ParseErrorCode code, size_t offset) : code_(code), offset_(offset) {}
107 |
108 | //! Get the error code.
109 | ParseErrorCode Code() const { return code_; }
110 | //! Get the error offset, if \ref IsError(), 0 otherwise.
111 | size_t Offset() const { return offset_; }
112 |
113 | //! Conversion to \c bool, returns \c true, iff !\ref IsError().
114 | operator bool() const { return !IsError(); }
115 | //! Whether the result is an error.
116 | bool IsError() const { return code_ != kParseErrorNone; }
117 |
118 | bool operator==(const ParseResult& that) const { return code_ == that.code_; }
119 | bool operator==(ParseErrorCode code) const { return code_ == code; }
120 | friend bool operator==(ParseErrorCode code, const ParseResult & err) { return code == err.code_; }
121 |
122 | //! Reset error code.
123 | void Clear() { Set(kParseErrorNone); }
124 | //! Update error code and offset.
125 | void Set(ParseErrorCode code, size_t offset = 0) { code_ = code; offset_ = offset; }
126 |
127 | private:
128 | ParseErrorCode code_;
129 | size_t offset_;
130 | };
131 |
132 | //! Function pointer type of GetParseError().
133 | /*! \ingroup RAPIDJSON_ERRORS
134 |
135 | This is the prototype for \c GetParseError_X(), where \c X is a locale.
136 | User can dynamically change locale in runtime, e.g.:
137 | \code
138 | GetParseErrorFunc GetParseError = GetParseError_En; // or whatever
139 | const RAPIDJSON_ERROR_CHARTYPE* s = GetParseError(document.GetParseErrorCode());
140 | \endcode
141 | */
142 | typedef const RAPIDJSON_ERROR_CHARTYPE* (*GetParseErrorFunc)(ParseErrorCode);
143 |
144 | RAPIDJSON_NAMESPACE_END
145 |
146 | #endif // RAPIDJSON_ERROR_ERROR_H__
147 |
--------------------------------------------------------------------------------
/ImageProc/include/rapidjson/filereadstream.h:
--------------------------------------------------------------------------------
1 | // Tencent is pleased to support the open source community by making RapidJSON available.
2 | //
3 | // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved.
4 | //
5 | // Licensed under the MIT License (the "License"); you may not use this file except
6 | // in compliance with the License. You may obtain a copy of the License at
7 | //
8 | // http://opensource.org/licenses/MIT
9 | //
10 | // Unless required by applicable law or agreed to in writing, software distributed
11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
13 | // specific language governing permissions and limitations under the License.
14 |
15 | #ifndef RAPIDJSON_FILEREADSTREAM_H_
16 | #define RAPIDJSON_FILEREADSTREAM_H_
17 |
18 | #include "rapidjson.h"
19 | #include
20 |
21 | RAPIDJSON_NAMESPACE_BEGIN
22 |
23 | //! File byte stream for input using fread().
24 | /*!
25 | \note implements Stream concept
26 | */
27 | class FileReadStream {
28 | public:
29 | typedef char Ch; //!< Character type (byte).
30 |
31 | //! Constructor.
32 | /*!
33 | \param fp File pointer opened for read.
34 | \param buffer user-supplied buffer.
35 | \param bufferSize size of buffer in bytes. Must >=4 bytes.
36 | */
37 | FileReadStream(std::FILE* fp, char* buffer, size_t bufferSize) : fp_(fp), buffer_(buffer), bufferSize_(bufferSize), bufferLast_(0), current_(buffer_), readCount_(0), count_(0), eof_(false) {
38 | RAPIDJSON_ASSERT(fp_ != 0);
39 | RAPIDJSON_ASSERT(bufferSize >= 4);
40 | Read();
41 | }
42 |
43 | Ch Peek() const { return *current_; }
44 | Ch Take() { Ch c = *current_; Read(); return c; }
45 | size_t Tell() const { return count_ + static_cast(current_ - buffer_); }
46 |
47 | // Not implemented
48 | void Put(Ch) { RAPIDJSON_ASSERT(false); }
49 | void Flush() { RAPIDJSON_ASSERT(false); }
50 | Ch* PutBegin() { RAPIDJSON_ASSERT(false); return 0; }
51 | size_t PutEnd(Ch*) { RAPIDJSON_ASSERT(false); return 0; }
52 |
53 | // For encoding detection only.
54 | const Ch* Peek4() const {
55 | return (current_ + 4 <= bufferLast_) ? current_ : 0;
56 | }
57 |
58 | private:
59 | void Read() {
60 | if (current_ < bufferLast_)
61 | ++current_;
62 | else if (!eof_) {
63 | count_ += readCount_;
64 | readCount_ = fread(buffer_, 1, bufferSize_, fp_);
65 | bufferLast_ = buffer_ + readCount_ - 1;
66 | current_ = buffer_;
67 |
68 | if (readCount_ < bufferSize_) {
69 | buffer_[readCount_] = '\0';
70 | ++bufferLast_;
71 | eof_ = true;
72 | }
73 | }
74 | }
75 |
76 | std::FILE* fp_;
77 | Ch *buffer_;
78 | size_t bufferSize_;
79 | Ch *bufferLast_;
80 | Ch *current_;
81 | size_t readCount_;
82 | size_t count_; //!< Number of characters read
83 | bool eof_;
84 | };
85 |
86 | RAPIDJSON_NAMESPACE_END
87 |
88 | #endif // RAPIDJSON_FILESTREAM_H_
89 |
--------------------------------------------------------------------------------
/ImageProc/include/rapidjson/filewritestream.h:
--------------------------------------------------------------------------------
1 | // Tencent is pleased to support the open source community by making RapidJSON available.
2 | //
3 | // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved.
4 | //
5 | // Licensed under the MIT License (the "License"); you may not use this file except
6 | // in compliance with the License. You may obtain a copy of the License at
7 | //
8 | // http://opensource.org/licenses/MIT
9 | //
10 | // Unless required by applicable law or agreed to in writing, software distributed
11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
13 | // specific language governing permissions and limitations under the License.
14 |
15 | #ifndef RAPIDJSON_FILEWRITESTREAM_H_
16 | #define RAPIDJSON_FILEWRITESTREAM_H_
17 |
18 | #include "rapidjson.h"
19 | #include
20 |
21 | RAPIDJSON_NAMESPACE_BEGIN
22 |
23 | //! Wrapper of C file stream for input using fread().
24 | /*!
25 | \note implements Stream concept
26 | */
27 | class FileWriteStream {
28 | public:
29 | typedef char Ch; //!< Character type. Only support char.
30 |
31 | FileWriteStream(std::FILE* fp, char* buffer, size_t bufferSize) : fp_(fp), buffer_(buffer), bufferEnd_(buffer + bufferSize), current_(buffer_) {
32 | RAPIDJSON_ASSERT(fp_ != 0);
33 | }
34 |
35 | void Put(char c) {
36 | if (current_ >= bufferEnd_)
37 | Flush();
38 |
39 | *current_++ = c;
40 | }
41 |
42 | void PutN(char c, size_t n) {
43 | size_t avail = static_cast(bufferEnd_ - current_);
44 | while (n > avail) {
45 | std::memset(current_, c, avail);
46 | current_ += avail;
47 | Flush();
48 | n -= avail;
49 | avail = static_cast(bufferEnd_ - current_);
50 | }
51 |
52 | if (n > 0) {
53 | std::memset(current_, c, n);
54 | current_ += n;
55 | }
56 | }
57 |
58 | void Flush() {
59 | if (current_ != buffer_) {
60 | size_t result = fwrite(buffer_, 1, static_cast(current_ - buffer_), fp_);
61 | if (result < static_cast(current_ - buffer_)) {
62 | // failure deliberately ignored at this time
63 | // added to avoid warn_unused_result build errors
64 | }
65 | current_ = buffer_;
66 | }
67 | }
68 |
69 | // Not implemented
70 | char Peek() const { RAPIDJSON_ASSERT(false); return 0; }
71 | char Take() { RAPIDJSON_ASSERT(false); return 0; }
72 | size_t Tell() const { RAPIDJSON_ASSERT(false); return 0; }
73 | char* PutBegin() { RAPIDJSON_ASSERT(false); return 0; }
74 | size_t PutEnd(char*) { RAPIDJSON_ASSERT(false); return 0; }
75 |
76 | private:
77 | // Prohibit copy constructor & assignment operator.
78 | FileWriteStream(const FileWriteStream&);
79 | FileWriteStream& operator=(const FileWriteStream&);
80 |
81 | std::FILE* fp_;
82 | char *buffer_;
83 | char *bufferEnd_;
84 | char *current_;
85 | };
86 |
87 | //! Implement specialized version of PutN() with memset() for better performance.
88 | template<>
89 | inline void PutN(FileWriteStream& stream, char c, size_t n) {
90 | stream.PutN(c, n);
91 | }
92 |
93 | RAPIDJSON_NAMESPACE_END
94 |
95 | #endif // RAPIDJSON_FILESTREAM_H_
96 |
--------------------------------------------------------------------------------
/ImageProc/include/rapidjson/internal/dtoa.h:
--------------------------------------------------------------------------------
1 | // Tencent is pleased to support the open source community by making RapidJSON available.
2 | //
3 | // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved.
4 | //
5 | // Licensed under the MIT License (the "License"); you may not use this file except
6 | // in compliance with the License. You may obtain a copy of the License at
7 | //
8 | // http://opensource.org/licenses/MIT
9 | //
10 | // Unless required by applicable law or agreed to in writing, software distributed
11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
13 | // specific language governing permissions and limitations under the License.
14 |
15 | // This is a C++ header-only implementation of Grisu2 algorithm from the publication:
16 | // Loitsch, Florian. "Printing floating-point numbers quickly and accurately with
17 | // integers." ACM Sigplan Notices 45.6 (2010): 233-243.
18 |
19 | #ifndef RAPIDJSON_DTOA_
20 | #define RAPIDJSON_DTOA_
21 |
22 | #include "itoa.h" // GetDigitsLut()
23 | #include "diyfp.h"
24 | #include "ieee754.h"
25 |
26 | RAPIDJSON_NAMESPACE_BEGIN
27 | namespace internal {
28 |
29 | #ifdef __GNUC__
30 | RAPIDJSON_DIAG_PUSH
31 | RAPIDJSON_DIAG_OFF(effc++)
32 | #endif
33 |
34 | inline void GrisuRound(char* buffer, int len, uint64_t delta, uint64_t rest, uint64_t ten_kappa, uint64_t wp_w) {
35 | while (rest < wp_w && delta - rest >= ten_kappa &&
36 | (rest + ten_kappa < wp_w || /// closer
37 | wp_w - rest > rest + ten_kappa - wp_w)) {
38 | buffer[len - 1]--;
39 | rest += ten_kappa;
40 | }
41 | }
42 |
43 | inline unsigned CountDecimalDigit32(uint32_t n) {
44 | // Simple pure C++ implementation was faster than __builtin_clz version in this situation.
45 | if (n < 10) return 1;
46 | if (n < 100) return 2;
47 | if (n < 1000) return 3;
48 | if (n < 10000) return 4;
49 | if (n < 100000) return 5;
50 | if (n < 1000000) return 6;
51 | if (n < 10000000) return 7;
52 | if (n < 100000000) return 8;
53 | // Will not reach 10 digits in DigitGen()
54 | //if (n < 1000000000) return 9;
55 | //return 10;
56 | return 9;
57 | }
58 |
59 | inline void DigitGen(const DiyFp& W, const DiyFp& Mp, uint64_t delta, char* buffer, int* len, int* K) {
60 | static const uint32_t kPow10[] = { 1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000 };
61 | const DiyFp one(uint64_t(1) << -Mp.e, Mp.e);
62 | const DiyFp wp_w = Mp - W;
63 | uint32_t p1 = static_cast(Mp.f >> -one.e);
64 | uint64_t p2 = Mp.f & (one.f - 1);
65 | unsigned kappa = CountDecimalDigit32(p1); // kappa in [0, 9]
66 | *len = 0;
67 |
68 | while (kappa > 0) {
69 | uint32_t d = 0;
70 | switch (kappa) {
71 | case 9: d = p1 / 100000000; p1 %= 100000000; break;
72 | case 8: d = p1 / 10000000; p1 %= 10000000; break;
73 | case 7: d = p1 / 1000000; p1 %= 1000000; break;
74 | case 6: d = p1 / 100000; p1 %= 100000; break;
75 | case 5: d = p1 / 10000; p1 %= 10000; break;
76 | case 4: d = p1 / 1000; p1 %= 1000; break;
77 | case 3: d = p1 / 100; p1 %= 100; break;
78 | case 2: d = p1 / 10; p1 %= 10; break;
79 | case 1: d = p1; p1 = 0; break;
80 | default:;
81 | }
82 | if (d || *len)
83 | buffer[(*len)++] = static_cast('0' + static_cast(d));
84 | kappa--;
85 | uint64_t tmp = (static_cast(p1) << -one.e) + p2;
86 | if (tmp <= delta) {
87 | *K += kappa;
88 | GrisuRound(buffer, *len, delta, tmp, static_cast(kPow10[kappa]) << -one.e, wp_w.f);
89 | return;
90 | }
91 | }
92 |
93 | // kappa = 0
94 | for (;;) {
95 | p2 *= 10;
96 | delta *= 10;
97 | char d = static_cast(p2 >> -one.e);
98 | if (d || *len)
99 | buffer[(*len)++] = static_cast('0' + d);
100 | p2 &= one.f - 1;
101 | kappa--;
102 | if (p2 < delta) {
103 | *K += kappa;
104 | GrisuRound(buffer, *len, delta, p2, one.f, wp_w.f * kPow10[-static_cast(kappa)]);
105 | return;
106 | }
107 | }
108 | }
109 |
110 | inline void Grisu2(double value, char* buffer, int* length, int* K) {
111 | const DiyFp v(value);
112 | DiyFp w_m, w_p;
113 | v.NormalizedBoundaries(&w_m, &w_p);
114 |
115 | const DiyFp c_mk = GetCachedPower(w_p.e, K);
116 | const DiyFp W = v.Normalize() * c_mk;
117 | DiyFp Wp = w_p * c_mk;
118 | DiyFp Wm = w_m * c_mk;
119 | Wm.f++;
120 | Wp.f--;
121 | DigitGen(W, Wp, Wp.f - Wm.f, buffer, length, K);
122 | }
123 |
124 | inline char* WriteExponent(int K, char* buffer) {
125 | if (K < 0) {
126 | *buffer++ = '-';
127 | K = -K;
128 | }
129 |
130 | if (K >= 100) {
131 | *buffer++ = static_cast('0' + static_cast(K / 100));
132 | K %= 100;
133 | const char* d = GetDigitsLut() + K * 2;
134 | *buffer++ = d[0];
135 | *buffer++ = d[1];
136 | }
137 | else if (K >= 10) {
138 | const char* d = GetDigitsLut() + K * 2;
139 | *buffer++ = d[0];
140 | *buffer++ = d[1];
141 | }
142 | else
143 | *buffer++ = static_cast('0' + static_cast(K));
144 |
145 | return buffer;
146 | }
147 |
148 | inline char* Prettify(char* buffer, int length, int k) {
149 | const int kk = length + k; // 10^(kk-1) <= v < 10^kk
150 |
151 | if (length <= kk && kk <= 21) {
152 | // 1234e7 -> 12340000000
153 | for (int i = length; i < kk; i++)
154 | buffer[i] = '0';
155 | buffer[kk] = '.';
156 | buffer[kk + 1] = '0';
157 | return &buffer[kk + 2];
158 | }
159 | else if (0 < kk && kk <= 21) {
160 | // 1234e-2 -> 12.34
161 | std::memmove(&buffer[kk + 1], &buffer[kk], static_cast(length - kk));
162 | buffer[kk] = '.';
163 | return &buffer[length + 1];
164 | }
165 | else if (-6 < kk && kk <= 0) {
166 | // 1234e-6 -> 0.001234
167 | const int offset = 2 - kk;
168 | std::memmove(&buffer[offset], &buffer[0], static_cast(length));
169 | buffer[0] = '0';
170 | buffer[1] = '.';
171 | for (int i = 2; i < offset; i++)
172 | buffer[i] = '0';
173 | return &buffer[length + offset];
174 | }
175 | else if (length == 1) {
176 | // 1e30
177 | buffer[1] = 'e';
178 | return WriteExponent(kk - 1, &buffer[2]);
179 | }
180 | else {
181 | // 1234e30 -> 1.234e33
182 | std::memmove(&buffer[2], &buffer[1], static_cast(length - 1));
183 | buffer[1] = '.';
184 | buffer[length + 1] = 'e';
185 | return WriteExponent(kk - 1, &buffer[0 + length + 2]);
186 | }
187 | }
188 |
189 | inline char* dtoa(double value, char* buffer) {
190 | Double d(value);
191 | if (d.IsZero()) {
192 | if (d.Sign())
193 | *buffer++ = '-'; // -0.0, Issue #289
194 | buffer[0] = '0';
195 | buffer[1] = '.';
196 | buffer[2] = '0';
197 | return &buffer[3];
198 | }
199 | else {
200 | if (value < 0) {
201 | *buffer++ = '-';
202 | value = -value;
203 | }
204 | int length, K;
205 | Grisu2(value, buffer, &length, &K);
206 | return Prettify(buffer, length, K);
207 | }
208 | }
209 |
210 | #ifdef __GNUC__
211 | RAPIDJSON_DIAG_POP
212 | #endif
213 |
214 | } // namespace internal
215 | RAPIDJSON_NAMESPACE_END
216 |
217 | #endif // RAPIDJSON_DTOA_
218 |
--------------------------------------------------------------------------------
/ImageProc/include/rapidjson/internal/ieee754.h:
--------------------------------------------------------------------------------
1 | // Tencent is pleased to support the open source community by making RapidJSON available.
2 | //
3 | // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved.
4 | //
5 | // Licensed under the MIT License (the "License"); you may not use this file except
6 | // in compliance with the License. You may obtain a copy of the License at
7 | //
8 | // http://opensource.org/licenses/MIT
9 | //
10 | // Unless required by applicable law or agreed to in writing, software distributed
11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
13 | // specific language governing permissions and limitations under the License.
14 |
15 | #ifndef RAPIDJSON_IEEE754_
16 | #define RAPIDJSON_IEEE754_
17 |
18 | #include "../rapidjson.h"
19 |
20 | RAPIDJSON_NAMESPACE_BEGIN
21 | namespace internal {
22 |
23 | class Double {
24 | public:
25 | Double() {}
26 | Double(double d) : d_(d) {}
27 | Double(uint64_t u) : u_(u) {}
28 |
29 | double Value() const { return d_; }
30 | uint64_t Uint64Value() const { return u_; }
31 |
32 | double NextPositiveDouble() const {
33 | RAPIDJSON_ASSERT(!Sign());
34 | return Double(u_ + 1).Value();
35 | }
36 |
37 | bool Sign() const { return (u_ & kSignMask) != 0; }
38 | uint64_t Significand() const { return u_ & kSignificandMask; }
39 | int Exponent() const { return static_cast(((u_ & kExponentMask) >> kSignificandSize) - kExponentBias); }
40 |
41 | bool IsNan() const { return (u_ & kExponentMask) == kExponentMask && Significand() != 0; }
42 | bool IsInf() const { return (u_ & kExponentMask) == kExponentMask && Significand() == 0; }
43 | bool IsNormal() const { return (u_ & kExponentMask) != 0 || Significand() == 0; }
44 | bool IsZero() const { return (u_ & (kExponentMask | kSignificandMask)) == 0; }
45 |
46 | uint64_t IntegerSignificand() const { return IsNormal() ? Significand() | kHiddenBit : Significand(); }
47 | int IntegerExponent() const { return (IsNormal() ? Exponent() : kDenormalExponent) - kSignificandSize; }
48 | uint64_t ToBias() const { return (u_ & kSignMask) ? ~u_ + 1 : u_ | kSignMask; }
49 |
50 | static unsigned EffectiveSignificandSize(int order) {
51 | if (order >= -1021)
52 | return 53;
53 | else if (order <= -1074)
54 | return 0;
55 | else
56 | return (unsigned)order + 1074;
57 | }
58 |
59 | private:
60 | static const int kSignificandSize = 52;
61 | static const int kExponentBias = 0x3FF;
62 | static const int kDenormalExponent = 1 - kExponentBias;
63 | static const uint64_t kSignMask = RAPIDJSON_UINT64_C2(0x80000000, 0x00000000);
64 | static const uint64_t kExponentMask = RAPIDJSON_UINT64_C2(0x7FF00000, 0x00000000);
65 | static const uint64_t kSignificandMask = RAPIDJSON_UINT64_C2(0x000FFFFF, 0xFFFFFFFF);
66 | static const uint64_t kHiddenBit = RAPIDJSON_UINT64_C2(0x00100000, 0x00000000);
67 |
68 | union {
69 | double d_;
70 | uint64_t u_;
71 | };
72 | };
73 |
74 | } // namespace internal
75 | RAPIDJSON_NAMESPACE_END
76 |
77 | #endif // RAPIDJSON_IEEE754_
78 |
--------------------------------------------------------------------------------
/ImageProc/include/rapidjson/internal/meta.h:
--------------------------------------------------------------------------------
1 | // Tencent is pleased to support the open source community by making RapidJSON available.
2 | //
3 | // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved.
4 | //
5 | // Licensed under the MIT License (the "License"); you may not use this file except
6 | // in compliance with the License. You may obtain a copy of the License at
7 | //
8 | // http://opensource.org/licenses/MIT
9 | //
10 | // Unless required by applicable law or agreed to in writing, software distributed
11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
13 | // specific language governing permissions and limitations under the License.
14 |
15 | #ifndef RAPIDJSON_INTERNAL_META_H_
16 | #define RAPIDJSON_INTERNAL_META_H_
17 |
18 | #include "../rapidjson.h"
19 |
20 | #ifdef __GNUC__
21 | RAPIDJSON_DIAG_PUSH
22 | RAPIDJSON_DIAG_OFF(effc++)
23 | #endif
24 | #if defined(_MSC_VER)
25 | RAPIDJSON_DIAG_PUSH
26 | RAPIDJSON_DIAG_OFF(6334)
27 | #endif
28 |
29 | #if RAPIDJSON_HAS_CXX11_TYPETRAITS
30 | #include
31 | #endif
32 |
33 | //@cond RAPIDJSON_INTERNAL
34 | RAPIDJSON_NAMESPACE_BEGIN
35 | namespace internal {
36 |
37 | // Helper to wrap/convert arbitrary types to void, useful for arbitrary type matching
38 | template struct Void { typedef void Type; };
39 |
40 | ///////////////////////////////////////////////////////////////////////////////
41 | // BoolType, TrueType, FalseType
42 | //
43 | template struct BoolType {
44 | static const bool Value = Cond;
45 | typedef BoolType Type;
46 | };
47 | typedef BoolType TrueType;
48 | typedef BoolType FalseType;
49 |
50 |
51 | ///////////////////////////////////////////////////////////////////////////////
52 | // SelectIf, BoolExpr, NotExpr, AndExpr, OrExpr
53 | //
54 |
55 | template struct SelectIfImpl { template struct Apply { typedef T1 Type; }; };
56 | template <> struct SelectIfImpl { template struct Apply { typedef T2 Type; }; };
57 | template struct SelectIfCond : SelectIfImpl::template Apply {};
58 | template struct SelectIf : SelectIfCond {};
59 |
60 | template struct AndExprCond : FalseType {};
61 | template <> struct AndExprCond : TrueType {};
62 | template struct OrExprCond : TrueType {};
63 | template <> struct OrExprCond : FalseType {};
64 |
65 | template struct BoolExpr : SelectIf::Type {};
66 | template struct NotExpr : SelectIf::Type {};
67 | template struct AndExpr : AndExprCond::Type {};
68 | template struct OrExpr : OrExprCond::Type {};
69 |
70 |
71 | ///////////////////////////////////////////////////////////////////////////////
72 | // AddConst, MaybeAddConst, RemoveConst
73 | template struct AddConst { typedef const T Type; };
74 | template struct MaybeAddConst : SelectIfCond {};
75 | template struct RemoveConst { typedef T Type; };
76 | template struct RemoveConst { typedef T Type; };
77 |
78 |
79 | ///////////////////////////////////////////////////////////////////////////////
80 | // IsSame, IsConst, IsMoreConst, IsPointer
81 | //
82 | template struct IsSame : FalseType {};
83 | template struct IsSame : TrueType {};
84 |
85 | template struct IsConst : FalseType {};
86 | template struct IsConst : TrueType {};
87 |
88 | template
89 | struct IsMoreConst
90 | : AndExpr::Type, typename RemoveConst::Type>,
91 | BoolType::Value >= IsConst::Value> >::Type {};
92 |
93 | template struct IsPointer : FalseType {};
94 | template struct IsPointer : TrueType {};
95 |
96 | ///////////////////////////////////////////////////////////////////////////////
97 | // IsBaseOf
98 | //
99 | #if RAPIDJSON_HAS_CXX11_TYPETRAITS
100 |
101 | template struct IsBaseOf
102 | : BoolType< ::std::is_base_of::value> {};
103 |
104 | #else // simplified version adopted from Boost
105 |
106 | template struct IsBaseOfImpl {
107 | RAPIDJSON_STATIC_ASSERT(sizeof(B) != 0);
108 | RAPIDJSON_STATIC_ASSERT(sizeof(D) != 0);
109 |
110 | typedef char (&Yes)[1];
111 | typedef char (&No) [2];
112 |
113 | template
114 | static Yes Check(const D*, T);
115 | static No Check(const B*, int);
116 |
117 | struct Host {
118 | operator const B*() const;
119 | operator const D*();
120 | };
121 |
122 | enum { Value = (sizeof(Check(Host(), 0)) == sizeof(Yes)) };
123 | };
124 |
125 | template struct IsBaseOf
126 | : OrExpr, BoolExpr > >::Type {};
127 |
128 | #endif // RAPIDJSON_HAS_CXX11_TYPETRAITS
129 |
130 |
131 | //////////////////////////////////////////////////////////////////////////
132 | // EnableIf / DisableIf
133 | //
134 | template struct EnableIfCond { typedef T Type; };
135 | template struct EnableIfCond { /* empty */ };
136 |
137 | template struct DisableIfCond { typedef T Type; };
138 | template struct DisableIfCond { /* empty */ };
139 |
140 | template
141 | struct EnableIf : EnableIfCond {};
142 |
143 | template
144 | struct DisableIf : DisableIfCond {};
145 |
146 | // SFINAE helpers
147 | struct SfinaeTag {};
148 | template struct RemoveSfinaeTag;
149 | template struct RemoveSfinaeTag { typedef T Type; };
150 |
151 | #define RAPIDJSON_REMOVEFPTR_(type) \
152 | typename ::RAPIDJSON_NAMESPACE::internal::RemoveSfinaeTag \
153 | < ::RAPIDJSON_NAMESPACE::internal::SfinaeTag&(*) type>::Type
154 |
155 | #define RAPIDJSON_ENABLEIF(cond) \
156 | typename ::RAPIDJSON_NAMESPACE::internal::EnableIf \
157 | ::Type * = NULL
158 |
159 | #define RAPIDJSON_DISABLEIF(cond) \
160 | typename ::RAPIDJSON_NAMESPACE::internal::DisableIf \
161 | ::Type * = NULL
162 |
163 | #define RAPIDJSON_ENABLEIF_RETURN(cond,returntype) \
164 | typename ::RAPIDJSON_NAMESPACE::internal::EnableIf \
165 | ::Type
167 |
168 | #define RAPIDJSON_DISABLEIF_RETURN(cond,returntype) \
169 | typename ::RAPIDJSON_NAMESPACE::internal::DisableIf \
170 | ::Type
172 |
173 | } // namespace internal
174 | RAPIDJSON_NAMESPACE_END
175 | //@endcond
176 |
177 | #if defined(__GNUC__) || defined(_MSC_VER)
178 | RAPIDJSON_DIAG_POP
179 | #endif
180 |
181 | #endif // RAPIDJSON_INTERNAL_META_H_
182 |
--------------------------------------------------------------------------------
/ImageProc/include/rapidjson/internal/pow10.h:
--------------------------------------------------------------------------------
1 | // Tencent is pleased to support the open source community by making RapidJSON available.
2 | //
3 | // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved.
4 | //
5 | // Licensed under the MIT License (the "License"); you may not use this file except
6 | // in compliance with the License. You may obtain a copy of the License at
7 | //
8 | // http://opensource.org/licenses/MIT
9 | //
10 | // Unless required by applicable law or agreed to in writing, software distributed
11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
13 | // specific language governing permissions and limitations under the License.
14 |
15 | #ifndef RAPIDJSON_POW10_
16 | #define RAPIDJSON_POW10_
17 |
18 | #include "../rapidjson.h"
19 |
20 | RAPIDJSON_NAMESPACE_BEGIN
21 | namespace internal {
22 |
23 | //! Computes integer powers of 10 in double (10.0^n).
24 | /*! This function uses lookup table for fast and accurate results.
25 | \param n non-negative exponent. Must <= 308.
26 | \return 10.0^n
27 | */
28 | inline double Pow10(int n) {
29 | static const double e[] = { // 1e-0...1e308: 309 * 8 bytes = 2472 bytes
30 | 1e+0,
31 | 1e+1, 1e+2, 1e+3, 1e+4, 1e+5, 1e+6, 1e+7, 1e+8, 1e+9, 1e+10, 1e+11, 1e+12, 1e+13, 1e+14, 1e+15, 1e+16, 1e+17, 1e+18, 1e+19, 1e+20,
32 | 1e+21, 1e+22, 1e+23, 1e+24, 1e+25, 1e+26, 1e+27, 1e+28, 1e+29, 1e+30, 1e+31, 1e+32, 1e+33, 1e+34, 1e+35, 1e+36, 1e+37, 1e+38, 1e+39, 1e+40,
33 | 1e+41, 1e+42, 1e+43, 1e+44, 1e+45, 1e+46, 1e+47, 1e+48, 1e+49, 1e+50, 1e+51, 1e+52, 1e+53, 1e+54, 1e+55, 1e+56, 1e+57, 1e+58, 1e+59, 1e+60,
34 | 1e+61, 1e+62, 1e+63, 1e+64, 1e+65, 1e+66, 1e+67, 1e+68, 1e+69, 1e+70, 1e+71, 1e+72, 1e+73, 1e+74, 1e+75, 1e+76, 1e+77, 1e+78, 1e+79, 1e+80,
35 | 1e+81, 1e+82, 1e+83, 1e+84, 1e+85, 1e+86, 1e+87, 1e+88, 1e+89, 1e+90, 1e+91, 1e+92, 1e+93, 1e+94, 1e+95, 1e+96, 1e+97, 1e+98, 1e+99, 1e+100,
36 | 1e+101,1e+102,1e+103,1e+104,1e+105,1e+106,1e+107,1e+108,1e+109,1e+110,1e+111,1e+112,1e+113,1e+114,1e+115,1e+116,1e+117,1e+118,1e+119,1e+120,
37 | 1e+121,1e+122,1e+123,1e+124,1e+125,1e+126,1e+127,1e+128,1e+129,1e+130,1e+131,1e+132,1e+133,1e+134,1e+135,1e+136,1e+137,1e+138,1e+139,1e+140,
38 | 1e+141,1e+142,1e+143,1e+144,1e+145,1e+146,1e+147,1e+148,1e+149,1e+150,1e+151,1e+152,1e+153,1e+154,1e+155,1e+156,1e+157,1e+158,1e+159,1e+160,
39 | 1e+161,1e+162,1e+163,1e+164,1e+165,1e+166,1e+167,1e+168,1e+169,1e+170,1e+171,1e+172,1e+173,1e+174,1e+175,1e+176,1e+177,1e+178,1e+179,1e+180,
40 | 1e+181,1e+182,1e+183,1e+184,1e+185,1e+186,1e+187,1e+188,1e+189,1e+190,1e+191,1e+192,1e+193,1e+194,1e+195,1e+196,1e+197,1e+198,1e+199,1e+200,
41 | 1e+201,1e+202,1e+203,1e+204,1e+205,1e+206,1e+207,1e+208,1e+209,1e+210,1e+211,1e+212,1e+213,1e+214,1e+215,1e+216,1e+217,1e+218,1e+219,1e+220,
42 | 1e+221,1e+222,1e+223,1e+224,1e+225,1e+226,1e+227,1e+228,1e+229,1e+230,1e+231,1e+232,1e+233,1e+234,1e+235,1e+236,1e+237,1e+238,1e+239,1e+240,
43 | 1e+241,1e+242,1e+243,1e+244,1e+245,1e+246,1e+247,1e+248,1e+249,1e+250,1e+251,1e+252,1e+253,1e+254,1e+255,1e+256,1e+257,1e+258,1e+259,1e+260,
44 | 1e+261,1e+262,1e+263,1e+264,1e+265,1e+266,1e+267,1e+268,1e+269,1e+270,1e+271,1e+272,1e+273,1e+274,1e+275,1e+276,1e+277,1e+278,1e+279,1e+280,
45 | 1e+281,1e+282,1e+283,1e+284,1e+285,1e+286,1e+287,1e+288,1e+289,1e+290,1e+291,1e+292,1e+293,1e+294,1e+295,1e+296,1e+297,1e+298,1e+299,1e+300,
46 | 1e+301,1e+302,1e+303,1e+304,1e+305,1e+306,1e+307,1e+308
47 | };
48 | RAPIDJSON_ASSERT(n >= 0 && n <= 308);
49 | return e[n];
50 | }
51 |
52 | } // namespace internal
53 | RAPIDJSON_NAMESPACE_END
54 |
55 | #endif // RAPIDJSON_POW10_
56 |
--------------------------------------------------------------------------------
/ImageProc/include/rapidjson/internal/stack.h:
--------------------------------------------------------------------------------
1 | // Tencent is pleased to support the open source community by making RapidJSON available.
2 | //
3 | // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved.
4 | //
5 | // Licensed under the MIT License (the "License"); you may not use this file except
6 | // in compliance with the License. You may obtain a copy of the License at
7 | //
8 | // http://opensource.org/licenses/MIT
9 | //
10 | // Unless required by applicable law or agreed to in writing, software distributed
11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
13 | // specific language governing permissions and limitations under the License.
14 |
15 | #ifndef RAPIDJSON_INTERNAL_STACK_H_
16 | #define RAPIDJSON_INTERNAL_STACK_H_
17 |
18 | #include "../rapidjson.h"
19 | #include "swap.h"
20 |
21 | RAPIDJSON_NAMESPACE_BEGIN
22 | namespace internal {
23 |
24 | ///////////////////////////////////////////////////////////////////////////////
25 | // Stack
26 |
27 | //! A type-unsafe stack for storing different types of data.
28 | /*! \tparam Allocator Allocator for allocating stack memory.
29 | */
30 | template
31 | class Stack {
32 | public:
33 | // Optimization note: Do not allocate memory for stack_ in constructor.
34 | // Do it lazily when first Push() -> Expand() -> Resize().
35 | Stack(Allocator* allocator, size_t stackCapacity) : allocator_(allocator), ownAllocator_(0), stack_(0), stackTop_(0), stackEnd_(0), initialCapacity_(stackCapacity) {
36 | RAPIDJSON_ASSERT(stackCapacity > 0);
37 | }
38 |
39 | #if RAPIDJSON_HAS_CXX11_RVALUE_REFS
40 | Stack(Stack&& rhs)
41 | : allocator_(rhs.allocator_),
42 | ownAllocator_(rhs.ownAllocator_),
43 | stack_(rhs.stack_),
44 | stackTop_(rhs.stackTop_),
45 | stackEnd_(rhs.stackEnd_),
46 | initialCapacity_(rhs.initialCapacity_)
47 | {
48 | rhs.allocator_ = 0;
49 | rhs.ownAllocator_ = 0;
50 | rhs.stack_ = 0;
51 | rhs.stackTop_ = 0;
52 | rhs.stackEnd_ = 0;
53 | rhs.initialCapacity_ = 0;
54 | }
55 | #endif
56 |
57 | ~Stack() {
58 | Destroy();
59 | }
60 |
61 | #if RAPIDJSON_HAS_CXX11_RVALUE_REFS
62 | Stack& operator=(Stack&& rhs) {
63 | if (&rhs != this)
64 | {
65 | Destroy();
66 |
67 | allocator_ = rhs.allocator_;
68 | ownAllocator_ = rhs.ownAllocator_;
69 | stack_ = rhs.stack_;
70 | stackTop_ = rhs.stackTop_;
71 | stackEnd_ = rhs.stackEnd_;
72 | initialCapacity_ = rhs.initialCapacity_;
73 |
74 | rhs.allocator_ = 0;
75 | rhs.ownAllocator_ = 0;
76 | rhs.stack_ = 0;
77 | rhs.stackTop_ = 0;
78 | rhs.stackEnd_ = 0;
79 | rhs.initialCapacity_ = 0;
80 | }
81 | return *this;
82 | }
83 | #endif
84 |
85 | void Swap(Stack& rhs) RAPIDJSON_NOEXCEPT {
86 | internal::Swap(allocator_, rhs.allocator_);
87 | internal::Swap(ownAllocator_, rhs.ownAllocator_);
88 | internal::Swap(stack_, rhs.stack_);
89 | internal::Swap(stackTop_, rhs.stackTop_);
90 | internal::Swap(stackEnd_, rhs.stackEnd_);
91 | internal::Swap(initialCapacity_, rhs.initialCapacity_);
92 | }
93 |
94 | void Clear() { stackTop_ = stack_; }
95 |
96 | void ShrinkToFit() {
97 | if (Empty()) {
98 | // If the stack is empty, completely deallocate the memory.
99 | Allocator::Free(stack_);
100 | stack_ = 0;
101 | stackTop_ = 0;
102 | stackEnd_ = 0;
103 | }
104 | else
105 | Resize(GetSize());
106 | }
107 |
108 | // Optimization note: try to minimize the size of this function for force inline.
109 | // Expansion is run very infrequently, so it is moved to another (probably non-inline) function.
110 | template
111 | RAPIDJSON_FORCEINLINE T* Push(size_t count = 1) {
112 | // Expand the stack if needed
113 | if (stackTop_ + sizeof(T) * count >= stackEnd_)
114 | Expand(count);
115 |
116 | T* ret = reinterpret_cast(stackTop_);
117 | stackTop_ += sizeof(T) * count;
118 | return ret;
119 | }
120 |
121 | template
122 | T* Pop(size_t count) {
123 | RAPIDJSON_ASSERT(GetSize() >= count * sizeof(T));
124 | stackTop_ -= count * sizeof(T);
125 | return reinterpret_cast(stackTop_);
126 | }
127 |
128 | template
129 | T* Top() {
130 | RAPIDJSON_ASSERT(GetSize() >= sizeof(T));
131 | return reinterpret_cast(stackTop_ - sizeof(T));
132 | }
133 |
134 | template
135 | T* Bottom() { return (T*)stack_; }
136 |
137 | Allocator& GetAllocator() { return *allocator_; }
138 | bool Empty() const { return stackTop_ == stack_; }
139 | size_t GetSize() const { return static_cast(stackTop_ - stack_); }
140 | size_t GetCapacity() const { return static_cast(stackEnd_ - stack_); }
141 |
142 | private:
143 | template
144 | void Expand(size_t count) {
145 | // Only expand the capacity if the current stack exists. Otherwise just create a stack with initial capacity.
146 | size_t newCapacity;
147 | if (stack_ == 0) {
148 | if (!allocator_)
149 | ownAllocator_ = allocator_ = RAPIDJSON_NEW(Allocator());
150 | newCapacity = initialCapacity_;
151 | } else {
152 | newCapacity = GetCapacity();
153 | newCapacity += (newCapacity + 1) / 2;
154 | }
155 | size_t newSize = GetSize() + sizeof(T) * count;
156 | if (newCapacity < newSize)
157 | newCapacity = newSize;
158 |
159 | Resize(newCapacity);
160 | }
161 |
162 | void Resize(size_t newCapacity) {
163 | const size_t size = GetSize(); // Backup the current size
164 | stack_ = (char*)allocator_->Realloc(stack_, GetCapacity(), newCapacity);
165 | stackTop_ = stack_ + size;
166 | stackEnd_ = stack_ + newCapacity;
167 | }
168 |
169 | void Destroy() {
170 | Allocator::Free(stack_);
171 | RAPIDJSON_DELETE(ownAllocator_); // Only delete if it is owned by the stack
172 | }
173 |
174 | // Prohibit copy constructor & assignment operator.
175 | Stack(const Stack&);
176 | Stack& operator=(const Stack&);
177 |
178 | Allocator* allocator_;
179 | Allocator* ownAllocator_;
180 | char *stack_;
181 | char *stackTop_;
182 | char *stackEnd_;
183 | size_t initialCapacity_;
184 | };
185 |
186 | } // namespace internal
187 | RAPIDJSON_NAMESPACE_END
188 |
189 | #endif // RAPIDJSON_STACK_H_
190 |
--------------------------------------------------------------------------------
/ImageProc/include/rapidjson/internal/strfunc.h:
--------------------------------------------------------------------------------
1 | // Tencent is pleased to support the open source community by making RapidJSON available.
2 | //
3 | // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved.
4 | //
5 | // Licensed under the MIT License (the "License"); you may not use this file except
6 | // in compliance with the License. You may obtain a copy of the License at
7 | //
8 | // http://opensource.org/licenses/MIT
9 | //
10 | // Unless required by applicable law or agreed to in writing, software distributed
11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
13 | // specific language governing permissions and limitations under the License.
14 |
15 | #ifndef RAPIDJSON_INTERNAL_STRFUNC_H_
16 | #define RAPIDJSON_INTERNAL_STRFUNC_H_
17 |
18 | #include "../rapidjson.h"
19 |
20 | RAPIDJSON_NAMESPACE_BEGIN
21 | namespace internal {
22 |
23 | //! Custom strlen() which works on different character types.
24 | /*! \tparam Ch Character type (e.g. char, wchar_t, short)
25 | \param s Null-terminated input string.
26 | \return Number of characters in the string.
27 | \note This has the same semantics as strlen(), the return value is not number of Unicode codepoints.
28 | */
29 | template
30 | inline SizeType StrLen(const Ch* s) {
31 | const Ch* p = s;
32 | while (*p) ++p;
33 | return SizeType(p - s);
34 | }
35 |
36 | } // namespace internal
37 | RAPIDJSON_NAMESPACE_END
38 |
39 | #endif // RAPIDJSON_INTERNAL_STRFUNC_H_
40 |
--------------------------------------------------------------------------------
/ImageProc/include/rapidjson/internal/strtod.h:
--------------------------------------------------------------------------------
1 | // Tencent is pleased to support the open source community by making RapidJSON available.
2 | //
3 | // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved.
4 | //
5 | // Licensed under the MIT License (the "License"); you may not use this file except
6 | // in compliance with the License. You may obtain a copy of the License at
7 | //
8 | // http://opensource.org/licenses/MIT
9 | //
10 | // Unless required by applicable law or agreed to in writing, software distributed
11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
13 | // specific language governing permissions and limitations under the License.
14 |
15 | #ifndef RAPIDJSON_STRTOD_
16 | #define RAPIDJSON_STRTOD_
17 |
18 | #include "../rapidjson.h"
19 | #include "ieee754.h"
20 | #include "biginteger.h"
21 | #include "diyfp.h"
22 | #include "pow10.h"
23 |
24 | RAPIDJSON_NAMESPACE_BEGIN
25 | namespace internal {
26 |
27 | inline double FastPath(double significand, int exp) {
28 | if (exp < -308)
29 | return 0.0;
30 | else if (exp >= 0)
31 | return significand * internal::Pow10(exp);
32 | else
33 | return significand / internal::Pow10(-exp);
34 | }
35 |
36 | inline double StrtodNormalPrecision(double d, int p) {
37 | if (p < -308) {
38 | // Prevent expSum < -308, making Pow10(p) = 0
39 | d = FastPath(d, -308);
40 | d = FastPath(d, p + 308);
41 | }
42 | else
43 | d = FastPath(d, p);
44 | return d;
45 | }
46 |
47 | template
48 | inline T Min3(T a, T b, T c) {
49 | T m = a;
50 | if (m > b) m = b;
51 | if (m > c) m = c;
52 | return m;
53 | }
54 |
55 | inline int CheckWithinHalfULP(double b, const BigInteger& d, int dExp) {
56 | const Double db(b);
57 | const uint64_t bInt = db.IntegerSignificand();
58 | const int bExp = db.IntegerExponent();
59 | const int hExp = bExp - 1;
60 |
61 | int dS_Exp2 = 0, dS_Exp5 = 0, bS_Exp2 = 0, bS_Exp5 = 0, hS_Exp2 = 0, hS_Exp5 = 0;
62 |
63 | // Adjust for decimal exponent
64 | if (dExp >= 0) {
65 | dS_Exp2 += dExp;
66 | dS_Exp5 += dExp;
67 | }
68 | else {
69 | bS_Exp2 -= dExp;
70 | bS_Exp5 -= dExp;
71 | hS_Exp2 -= dExp;
72 | hS_Exp5 -= dExp;
73 | }
74 |
75 | // Adjust for binary exponent
76 | if (bExp >= 0)
77 | bS_Exp2 += bExp;
78 | else {
79 | dS_Exp2 -= bExp;
80 | hS_Exp2 -= bExp;
81 | }
82 |
83 | // Adjust for half ulp exponent
84 | if (hExp >= 0)
85 | hS_Exp2 += hExp;
86 | else {
87 | dS_Exp2 -= hExp;
88 | bS_Exp2 -= hExp;
89 | }
90 |
91 | // Remove common power of two factor from all three scaled values
92 | int common_Exp2 = Min3(dS_Exp2, bS_Exp2, hS_Exp2);
93 | dS_Exp2 -= common_Exp2;
94 | bS_Exp2 -= common_Exp2;
95 | hS_Exp2 -= common_Exp2;
96 |
97 | BigInteger dS = d;
98 | dS.MultiplyPow5(static_cast(dS_Exp5)) <<= static_cast(dS_Exp2);
99 |
100 | BigInteger bS(bInt);
101 | bS.MultiplyPow5(static_cast(bS_Exp5)) <<= static_cast(bS_Exp2);
102 |
103 | BigInteger hS(1);
104 | hS.MultiplyPow5(static_cast(hS_Exp5)) <<= static_cast(hS_Exp2);
105 |
106 | BigInteger delta(0);
107 | dS.Difference(bS, &delta);
108 |
109 | return delta.Compare(hS);
110 | }
111 |
112 | inline bool StrtodFast(double d, int p, double* result) {
113 | // Use fast path for string-to-double conversion if possible
114 | // see http://www.exploringbinary.com/fast-path-decimal-to-floating-point-conversion/
115 | if (p > 22 && p < 22 + 16) {
116 | // Fast Path Cases In Disguise
117 | d *= internal::Pow10(p - 22);
118 | p = 22;
119 | }
120 |
121 | if (p >= -22 && p <= 22 && d <= 9007199254740991.0) { // 2^53 - 1
122 | *result = FastPath(d, p);
123 | return true;
124 | }
125 | else
126 | return false;
127 | }
128 |
129 | // Compute an approximation and see if it is within 1/2 ULP
130 | inline bool StrtodDiyFp(const char* decimals, size_t length, size_t decimalPosition, int exp, double* result) {
131 | uint64_t significand = 0;
132 | size_t i = 0; // 2^64 - 1 = 18446744073709551615, 1844674407370955161 = 0x1999999999999999
133 | for (; i < length; i++) {
134 | if (significand > RAPIDJSON_UINT64_C2(0x19999999, 0x99999999) ||
135 | (significand == RAPIDJSON_UINT64_C2(0x19999999, 0x99999999) && decimals[i] > '5'))
136 | break;
137 | significand = significand * 10u + static_cast(decimals[i] - '0');
138 | }
139 |
140 | if (i < length && decimals[i] >= '5') // Rounding
141 | significand++;
142 |
143 | size_t remaining = length - i;
144 | const unsigned kUlpShift = 3;
145 | const unsigned kUlp = 1 << kUlpShift;
146 | int error = (remaining == 0) ? 0 : kUlp / 2;
147 |
148 | DiyFp v(significand, 0);
149 | v = v.Normalize();
150 | error <<= -v.e;
151 |
152 | const int dExp = (int)decimalPosition - (int)i + exp;
153 |
154 | int actualExp;
155 | DiyFp cachedPower = GetCachedPower10(dExp, &actualExp);
156 | if (actualExp != dExp) {
157 | static const DiyFp kPow10[] = {
158 | DiyFp(RAPIDJSON_UINT64_C2(0xa0000000, 00000000), -60), // 10^1
159 | DiyFp(RAPIDJSON_UINT64_C2(0xc8000000, 00000000), -57), // 10^2
160 | DiyFp(RAPIDJSON_UINT64_C2(0xfa000000, 00000000), -54), // 10^3
161 | DiyFp(RAPIDJSON_UINT64_C2(0x9c400000, 00000000), -50), // 10^4
162 | DiyFp(RAPIDJSON_UINT64_C2(0xc3500000, 00000000), -47), // 10^5
163 | DiyFp(RAPIDJSON_UINT64_C2(0xf4240000, 00000000), -44), // 10^6
164 | DiyFp(RAPIDJSON_UINT64_C2(0x98968000, 00000000), -40) // 10^7
165 | };
166 | int adjustment = dExp - actualExp - 1;
167 | RAPIDJSON_ASSERT(adjustment >= 0 && adjustment < 7);
168 | v = v * kPow10[adjustment];
169 | if (length + static_cast(adjustment)> 19u) // has more digits than decimal digits in 64-bit
170 | error += kUlp / 2;
171 | }
172 |
173 | v = v * cachedPower;
174 |
175 | error += kUlp + (error == 0 ? 0 : 1);
176 |
177 | const int oldExp = v.e;
178 | v = v.Normalize();
179 | error <<= oldExp - v.e;
180 |
181 | const unsigned effectiveSignificandSize = Double::EffectiveSignificandSize(64 + v.e);
182 | unsigned precisionSize = 64 - effectiveSignificandSize;
183 | if (precisionSize + kUlpShift >= 64) {
184 | unsigned scaleExp = (precisionSize + kUlpShift) - 63;
185 | v.f >>= scaleExp;
186 | v.e += scaleExp;
187 | error = (error >> scaleExp) + 1 + static_cast(kUlp);
188 | precisionSize -= scaleExp;
189 | }
190 |
191 | DiyFp rounded(v.f >> precisionSize, v.e + static_cast(precisionSize));
192 | const uint64_t precisionBits = (v.f & ((uint64_t(1) << precisionSize) - 1)) * kUlp;
193 | const uint64_t halfWay = (uint64_t(1) << (precisionSize - 1)) * kUlp;
194 | if (precisionBits >= halfWay + static_cast(error)) {
195 | rounded.f++;
196 | if (rounded.f & (DiyFp::kDpHiddenBit << 1)) { // rounding overflows mantissa (issue #340)
197 | rounded.f >>= 1;
198 | rounded.e++;
199 | }
200 | }
201 |
202 | *result = rounded.ToDouble();
203 |
204 | return halfWay - static_cast(error) >= precisionBits || precisionBits >= halfWay + static_cast(error);
205 | }
206 |
207 | inline double StrtodBigInteger(double approx, const char* decimals, size_t length, size_t decimalPosition, int exp) {
208 | const BigInteger dInt(decimals, length);
209 | const int dExp = (int)decimalPosition - (int)length + exp;
210 | Double a(approx);
211 | int cmp = CheckWithinHalfULP(a.Value(), dInt, dExp);
212 | if (cmp < 0)
213 | return a.Value(); // within half ULP
214 | else if (cmp == 0) {
215 | // Round towards even
216 | if (a.Significand() & 1)
217 | return a.NextPositiveDouble();
218 | else
219 | return a.Value();
220 | }
221 | else // adjustment
222 | return a.NextPositiveDouble();
223 | }
224 |
225 | inline double StrtodFullPrecision(double d, int p, const char* decimals, size_t length, size_t decimalPosition, int exp) {
226 | RAPIDJSON_ASSERT(d >= 0.0);
227 | RAPIDJSON_ASSERT(length >= 1);
228 |
229 | double result;
230 | if (StrtodFast(d, p, &result))
231 | return result;
232 |
233 | // Trim leading zeros
234 | while (*decimals == '0' && length > 1) {
235 | length--;
236 | decimals++;
237 | decimalPosition--;
238 | }
239 |
240 | // Trim trailing zeros
241 | while (decimals[length - 1] == '0' && length > 1) {
242 | length--;
243 | decimalPosition--;
244 | exp++;
245 | }
246 |
247 | // Trim right-most digits
248 | const int kMaxDecimalDigit = 780;
249 | if ((int)length > kMaxDecimalDigit) {
250 | int delta = (int(length) - kMaxDecimalDigit);
251 | exp += delta;
252 | decimalPosition -= static_cast(delta);
253 | length = kMaxDecimalDigit;
254 | }
255 |
256 | // If too small, underflow to zero
257 | if (int(length) + exp < -324)
258 | return 0.0;
259 |
260 | if (StrtodDiyFp(decimals, length, decimalPosition, exp, &result))
261 | return result;
262 |
263 | // Use approximation from StrtodDiyFp and make adjustment with BigInteger comparison
264 | return StrtodBigInteger(result, decimals, length, decimalPosition, exp);
265 | }
266 |
267 | } // namespace internal
268 | RAPIDJSON_NAMESPACE_END
269 |
270 | #endif // RAPIDJSON_STRTOD_
271 |
--------------------------------------------------------------------------------
/ImageProc/include/rapidjson/internal/swap.h:
--------------------------------------------------------------------------------
1 | // Tencent is pleased to support the open source community by making RapidJSON available.
2 | //
3 | // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved.
4 | //
5 | // Licensed under the MIT License (the "License"); you may not use this file except
6 | // in compliance with the License. You may obtain a copy of the License at
7 | //
8 | // http://opensource.org/licenses/MIT
9 | //
10 | // Unless required by applicable law or agreed to in writing, software distributed
11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
13 | // specific language governing permissions and limitations under the License.
14 |
15 | #ifndef RAPIDJSON_INTERNAL_SWAP_H_
16 | #define RAPIDJSON_INTERNAL_SWAP_H_
17 |
18 | #include "../rapidjson.h"
19 |
20 | RAPIDJSON_NAMESPACE_BEGIN
21 | namespace internal {
22 |
23 | //! Custom swap() to avoid dependency on C++ header
24 | /*! \tparam T Type of the arguments to swap, should be instantiated with primitive C++ types only.
25 | \note This has the same semantics as std::swap().
26 | */
27 | template
28 | inline void Swap(T& a, T& b) RAPIDJSON_NOEXCEPT {
29 | T tmp = a;
30 | a = b;
31 | b = tmp;
32 | }
33 |
34 | } // namespace internal
35 | RAPIDJSON_NAMESPACE_END
36 |
37 | #endif // RAPIDJSON_INTERNAL_SWAP_H_
38 |
--------------------------------------------------------------------------------
/ImageProc/include/rapidjson/license.txt:
--------------------------------------------------------------------------------
1 | Tencent is pleased to support the open source community by making RapidJSON available.
2 |
3 | Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved.
4 |
5 | If you have downloaded a copy of the RapidJSON binary from Tencent, please note that the RapidJSON binary is licensed under the MIT License.
6 | If you have downloaded a copy of the RapidJSON source code from Tencent, please note that RapidJSON source code is licensed under the MIT License, except for the third-party components listed below which are subject to different license terms. Your integration of RapidJSON into your own projects may require compliance with the MIT License, as well as the other licenses applicable to the third-party components included within RapidJSON. To avoid the problematic JSON license in your own projects, it's sufficient to exclude the bin/jsonchecker/ directory, as it's the only code under the JSON license.
7 | A copy of the MIT License is included in this file.
8 |
9 | Other dependencies and licenses:
10 |
11 | Open Source Software Licensed Under the BSD License:
12 | --------------------------------------------------------------------
13 |
14 | The msinttypes r29
15 | Copyright (c) 2006-2013 Alexander Chemeris
16 | All rights reserved.
17 |
18 | Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
19 |
20 | * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
21 | * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
22 | * Neither the name of copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
23 |
24 | THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 |
26 | Open Source Software Licensed Under the JSON License:
27 | --------------------------------------------------------------------
28 |
29 | json.org
30 | Copyright (c) 2002 JSON.org
31 | All Rights Reserved.
32 |
33 | JSON_checker
34 | Copyright (c) 2002 JSON.org
35 | All Rights Reserved.
36 |
37 |
38 | Terms of the JSON License:
39 | ---------------------------------------------------
40 |
41 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
42 |
43 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
44 |
45 | The Software shall be used for Good, not Evil.
46 |
47 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
48 |
49 |
50 | Terms of the MIT License:
51 | --------------------------------------------------------------------
52 |
53 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
54 |
55 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
56 |
57 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
58 |
--------------------------------------------------------------------------------
/ImageProc/include/rapidjson/memorybuffer.h:
--------------------------------------------------------------------------------
1 | // Tencent is pleased to support the open source community by making RapidJSON available.
2 | //
3 | // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved.
4 | //
5 | // Licensed under the MIT License (the "License"); you may not use this file except
6 | // in compliance with the License. You may obtain a copy of the License at
7 | //
8 | // http://opensource.org/licenses/MIT
9 | //
10 | // Unless required by applicable law or agreed to in writing, software distributed
11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
13 | // specific language governing permissions and limitations under the License.
14 |
15 | #ifndef RAPIDJSON_MEMORYBUFFER_H_
16 | #define RAPIDJSON_MEMORYBUFFER_H_
17 |
18 | #include "rapidjson.h"
19 | #include "internal/stack.h"
20 |
21 | RAPIDJSON_NAMESPACE_BEGIN
22 |
23 | //! Represents an in-memory output byte stream.
24 | /*!
25 | This class is mainly for being wrapped by EncodedOutputStream or AutoUTFOutputStream.
26 |
27 | It is similar to FileWriteBuffer but the destination is an in-memory buffer instead of a file.
28 |
29 | Differences between MemoryBuffer and StringBuffer:
30 | 1. StringBuffer has Encoding but MemoryBuffer is only a byte buffer.
31 | 2. StringBuffer::GetString() returns a null-terminated string. MemoryBuffer::GetBuffer() returns a buffer without terminator.
32 |
33 | \tparam Allocator type for allocating memory buffer.
34 | \note implements Stream concept
35 | */
36 | template
37 | struct GenericMemoryBuffer {
38 | typedef char Ch; // byte
39 |
40 | GenericMemoryBuffer(Allocator* allocator = 0, size_t capacity = kDefaultCapacity) : stack_(allocator, capacity) {}
41 |
42 | void Put(Ch c) { *stack_.template Push() = c; }
43 | void Flush() {}
44 |
45 | void Clear() { stack_.Clear(); }
46 | void ShrinkToFit() { stack_.ShrinkToFit(); }
47 | Ch* Push(size_t count) { return stack_.template Push(count); }
48 | void Pop(size_t count) { stack_.template Pop(count); }
49 |
50 | const Ch* GetBuffer() const {
51 | return stack_.template Bottom();
52 | }
53 |
54 | size_t GetSize() const { return stack_.GetSize(); }
55 |
56 | static const size_t kDefaultCapacity = 256;
57 | mutable internal::Stack stack_;
58 | };
59 |
60 | typedef GenericMemoryBuffer<> MemoryBuffer;
61 |
62 | //! Implement specialized version of PutN() with memset() for better performance.
63 | template<>
64 | inline void PutN(MemoryBuffer& memoryBuffer, char c, size_t n) {
65 | std::memset(memoryBuffer.stack_.Push(n), c, n * sizeof(c));
66 | }
67 |
68 | RAPIDJSON_NAMESPACE_END
69 |
70 | #endif // RAPIDJSON_MEMORYBUFFER_H_
71 |
--------------------------------------------------------------------------------
/ImageProc/include/rapidjson/memorystream.h:
--------------------------------------------------------------------------------
1 | // Tencent is pleased to support the open source community by making RapidJSON available.
2 | //
3 | // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved.
4 | //
5 | // Licensed under the MIT License (the "License"); you may not use this file except
6 | // in compliance with the License. You may obtain a copy of the License at
7 | //
8 | // http://opensource.org/licenses/MIT
9 | //
10 | // Unless required by applicable law or agreed to in writing, software distributed
11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
13 | // specific language governing permissions and limitations under the License.
14 |
15 | #ifndef RAPIDJSON_MEMORYSTREAM_H_
16 | #define RAPIDJSON_MEMORYSTREAM_H_
17 |
18 | #include "rapidjson.h"
19 |
20 | RAPIDJSON_NAMESPACE_BEGIN
21 |
22 | //! Represents an in-memory input byte stream.
23 | /*!
24 | This class is mainly for being wrapped by EncodedInputStream or AutoUTFInputStream.
25 |
26 | It is similar to FileReadBuffer but the source is an in-memory buffer instead of a file.
27 |
28 | Differences between MemoryStream and StringStream:
29 | 1. StringStream has encoding but MemoryStream is a byte stream.
30 | 2. MemoryStream needs size of the source buffer and the buffer don't need to be null terminated. StringStream assume null-terminated string as source.
31 | 3. MemoryStream supports Peek4() for encoding detection. StringStream is specified with an encoding so it should not have Peek4().
32 | \note implements Stream concept
33 | */
34 | struct MemoryStream {
35 | typedef char Ch; // byte
36 |
37 | MemoryStream(const Ch *src, size_t size) : src_(src), begin_(src), end_(src + size), size_(size) {}
38 |
39 | Ch Peek() const { return (src_ == end_) ? '\0' : *src_; }
40 | Ch Take() { return (src_ == end_) ? '\0' : *src_++; }
41 | size_t Tell() const { return static_cast(src_ - begin_); }
42 |
43 | Ch* PutBegin() { RAPIDJSON_ASSERT(false); return 0; }
44 | void Put(Ch) { RAPIDJSON_ASSERT(false); }
45 | void Flush() { RAPIDJSON_ASSERT(false); }
46 | size_t PutEnd(Ch*) { RAPIDJSON_ASSERT(false); return 0; }
47 |
48 | // For encoding detection only.
49 | const Ch* Peek4() const {
50 | return Tell() + 4 <= size_ ? src_ : 0;
51 | }
52 |
53 | const Ch* src_; //!< Current read position.
54 | const Ch* begin_; //!< Original head of the string.
55 | const Ch* end_; //!< End of stream.
56 | size_t size_; //!< Size of the stream.
57 | };
58 |
59 | RAPIDJSON_NAMESPACE_END
60 |
61 | #endif // RAPIDJSON_MEMORYBUFFER_H_
62 |
--------------------------------------------------------------------------------
/ImageProc/include/rapidjson/msinttypes/inttypes.h:
--------------------------------------------------------------------------------
1 | // ISO C9x compliant inttypes.h for Microsoft Visual Studio
2 | // Based on ISO/IEC 9899:TC2 Committee draft (May 6, 2005) WG14/N1124
3 | //
4 | // Copyright (c) 2006-2013 Alexander Chemeris
5 | //
6 | // Redistribution and use in source and binary forms, with or without
7 | // modification, are permitted provided that the following conditions are met:
8 | //
9 | // 1. Redistributions of source code must retain the above copyright notice,
10 | // this list of conditions and the following disclaimer.
11 | //
12 | // 2. Redistributions in binary form must reproduce the above copyright
13 | // notice, this list of conditions and the following disclaimer in the
14 | // documentation and/or other materials provided with the distribution.
15 | //
16 | // 3. Neither the name of the product nor the names of its contributors may
17 | // be used to endorse or promote products derived from this software
18 | // without specific prior written permission.
19 | //
20 | // THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
21 | // WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
22 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
23 | // EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
26 | // OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
27 | // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
28 | // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
29 | // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 | //
31 | ///////////////////////////////////////////////////////////////////////////////
32 |
33 | // The above software in this distribution may have been modified by
34 | // THL A29 Limited ("Tencent Modifications").
35 | // All Tencent Modifications are Copyright (C) 2015 THL A29 Limited.
36 |
37 | #ifndef _MSC_VER // [
38 | #error "Use this header only with Microsoft Visual C++ compilers!"
39 | #endif // _MSC_VER ]
40 |
41 | #ifndef _MSC_INTTYPES_H_ // [
42 | #define _MSC_INTTYPES_H_
43 |
44 | #if _MSC_VER > 1000
45 | #pragma once
46 | #endif
47 |
48 | #include "stdint.h"
49 |
50 | // miloyip: VC supports inttypes.h since VC2013
51 | #if _MSC_VER >= 1800
52 | #include
53 | #else
54 |
55 | // 7.8 Format conversion of integer types
56 |
57 | typedef struct {
58 | intmax_t quot;
59 | intmax_t rem;
60 | } imaxdiv_t;
61 |
62 | // 7.8.1 Macros for format specifiers
63 |
64 | #if !defined(__cplusplus) || defined(__STDC_FORMAT_MACROS) // [ See footnote 185 at page 198
65 |
66 | // The fprintf macros for signed integers are:
67 | #define PRId8 "d"
68 | #define PRIi8 "i"
69 | #define PRIdLEAST8 "d"
70 | #define PRIiLEAST8 "i"
71 | #define PRIdFAST8 "d"
72 | #define PRIiFAST8 "i"
73 |
74 | #define PRId16 "hd"
75 | #define PRIi16 "hi"
76 | #define PRIdLEAST16 "hd"
77 | #define PRIiLEAST16 "hi"
78 | #define PRIdFAST16 "hd"
79 | #define PRIiFAST16 "hi"
80 |
81 | #define PRId32 "I32d"
82 | #define PRIi32 "I32i"
83 | #define PRIdLEAST32 "I32d"
84 | #define PRIiLEAST32 "I32i"
85 | #define PRIdFAST32 "I32d"
86 | #define PRIiFAST32 "I32i"
87 |
88 | #define PRId64 "I64d"
89 | #define PRIi64 "I64i"
90 | #define PRIdLEAST64 "I64d"
91 | #define PRIiLEAST64 "I64i"
92 | #define PRIdFAST64 "I64d"
93 | #define PRIiFAST64 "I64i"
94 |
95 | #define PRIdMAX "I64d"
96 | #define PRIiMAX "I64i"
97 |
98 | #define PRIdPTR "Id"
99 | #define PRIiPTR "Ii"
100 |
101 | // The fprintf macros for unsigned integers are:
102 | #define PRIo8 "o"
103 | #define PRIu8 "u"
104 | #define PRIx8 "x"
105 | #define PRIX8 "X"
106 | #define PRIoLEAST8 "o"
107 | #define PRIuLEAST8 "u"
108 | #define PRIxLEAST8 "x"
109 | #define PRIXLEAST8 "X"
110 | #define PRIoFAST8 "o"
111 | #define PRIuFAST8 "u"
112 | #define PRIxFAST8 "x"
113 | #define PRIXFAST8 "X"
114 |
115 | #define PRIo16 "ho"
116 | #define PRIu16 "hu"
117 | #define PRIx16 "hx"
118 | #define PRIX16 "hX"
119 | #define PRIoLEAST16 "ho"
120 | #define PRIuLEAST16 "hu"
121 | #define PRIxLEAST16 "hx"
122 | #define PRIXLEAST16 "hX"
123 | #define PRIoFAST16 "ho"
124 | #define PRIuFAST16 "hu"
125 | #define PRIxFAST16 "hx"
126 | #define PRIXFAST16 "hX"
127 |
128 | #define PRIo32 "I32o"
129 | #define PRIu32 "I32u"
130 | #define PRIx32 "I32x"
131 | #define PRIX32 "I32X"
132 | #define PRIoLEAST32 "I32o"
133 | #define PRIuLEAST32 "I32u"
134 | #define PRIxLEAST32 "I32x"
135 | #define PRIXLEAST32 "I32X"
136 | #define PRIoFAST32 "I32o"
137 | #define PRIuFAST32 "I32u"
138 | #define PRIxFAST32 "I32x"
139 | #define PRIXFAST32 "I32X"
140 |
141 | #define PRIo64 "I64o"
142 | #define PRIu64 "I64u"
143 | #define PRIx64 "I64x"
144 | #define PRIX64 "I64X"
145 | #define PRIoLEAST64 "I64o"
146 | #define PRIuLEAST64 "I64u"
147 | #define PRIxLEAST64 "I64x"
148 | #define PRIXLEAST64 "I64X"
149 | #define PRIoFAST64 "I64o"
150 | #define PRIuFAST64 "I64u"
151 | #define PRIxFAST64 "I64x"
152 | #define PRIXFAST64 "I64X"
153 |
154 | #define PRIoMAX "I64o"
155 | #define PRIuMAX "I64u"
156 | #define PRIxMAX "I64x"
157 | #define PRIXMAX "I64X"
158 |
159 | #define PRIoPTR "Io"
160 | #define PRIuPTR "Iu"
161 | #define PRIxPTR "Ix"
162 | #define PRIXPTR "IX"
163 |
164 | // The fscanf macros for signed integers are:
165 | #define SCNd8 "d"
166 | #define SCNi8 "i"
167 | #define SCNdLEAST8 "d"
168 | #define SCNiLEAST8 "i"
169 | #define SCNdFAST8 "d"
170 | #define SCNiFAST8 "i"
171 |
172 | #define SCNd16 "hd"
173 | #define SCNi16 "hi"
174 | #define SCNdLEAST16 "hd"
175 | #define SCNiLEAST16 "hi"
176 | #define SCNdFAST16 "hd"
177 | #define SCNiFAST16 "hi"
178 |
179 | #define SCNd32 "ld"
180 | #define SCNi32 "li"
181 | #define SCNdLEAST32 "ld"
182 | #define SCNiLEAST32 "li"
183 | #define SCNdFAST32 "ld"
184 | #define SCNiFAST32 "li"
185 |
186 | #define SCNd64 "I64d"
187 | #define SCNi64 "I64i"
188 | #define SCNdLEAST64 "I64d"
189 | #define SCNiLEAST64 "I64i"
190 | #define SCNdFAST64 "I64d"
191 | #define SCNiFAST64 "I64i"
192 |
193 | #define SCNdMAX "I64d"
194 | #define SCNiMAX "I64i"
195 |
196 | #ifdef _WIN64 // [
197 | # define SCNdPTR "I64d"
198 | # define SCNiPTR "I64i"
199 | #else // _WIN64 ][
200 | # define SCNdPTR "ld"
201 | # define SCNiPTR "li"
202 | #endif // _WIN64 ]
203 |
204 | // The fscanf macros for unsigned integers are:
205 | #define SCNo8 "o"
206 | #define SCNu8 "u"
207 | #define SCNx8 "x"
208 | #define SCNX8 "X"
209 | #define SCNoLEAST8 "o"
210 | #define SCNuLEAST8 "u"
211 | #define SCNxLEAST8 "x"
212 | #define SCNXLEAST8 "X"
213 | #define SCNoFAST8 "o"
214 | #define SCNuFAST8 "u"
215 | #define SCNxFAST8 "x"
216 | #define SCNXFAST8 "X"
217 |
218 | #define SCNo16 "ho"
219 | #define SCNu16 "hu"
220 | #define SCNx16 "hx"
221 | #define SCNX16 "hX"
222 | #define SCNoLEAST16 "ho"
223 | #define SCNuLEAST16 "hu"
224 | #define SCNxLEAST16 "hx"
225 | #define SCNXLEAST16 "hX"
226 | #define SCNoFAST16 "ho"
227 | #define SCNuFAST16 "hu"
228 | #define SCNxFAST16 "hx"
229 | #define SCNXFAST16 "hX"
230 |
231 | #define SCNo32 "lo"
232 | #define SCNu32 "lu"
233 | #define SCNx32 "lx"
234 | #define SCNX32 "lX"
235 | #define SCNoLEAST32 "lo"
236 | #define SCNuLEAST32 "lu"
237 | #define SCNxLEAST32 "lx"
238 | #define SCNXLEAST32 "lX"
239 | #define SCNoFAST32 "lo"
240 | #define SCNuFAST32 "lu"
241 | #define SCNxFAST32 "lx"
242 | #define SCNXFAST32 "lX"
243 |
244 | #define SCNo64 "I64o"
245 | #define SCNu64 "I64u"
246 | #define SCNx64 "I64x"
247 | #define SCNX64 "I64X"
248 | #define SCNoLEAST64 "I64o"
249 | #define SCNuLEAST64 "I64u"
250 | #define SCNxLEAST64 "I64x"
251 | #define SCNXLEAST64 "I64X"
252 | #define SCNoFAST64 "I64o"
253 | #define SCNuFAST64 "I64u"
254 | #define SCNxFAST64 "I64x"
255 | #define SCNXFAST64 "I64X"
256 |
257 | #define SCNoMAX "I64o"
258 | #define SCNuMAX "I64u"
259 | #define SCNxMAX "I64x"
260 | #define SCNXMAX "I64X"
261 |
262 | #ifdef _WIN64 // [
263 | # define SCNoPTR "I64o"
264 | # define SCNuPTR "I64u"
265 | # define SCNxPTR "I64x"
266 | # define SCNXPTR "I64X"
267 | #else // _WIN64 ][
268 | # define SCNoPTR "lo"
269 | # define SCNuPTR "lu"
270 | # define SCNxPTR "lx"
271 | # define SCNXPTR "lX"
272 | #endif // _WIN64 ]
273 |
274 | #endif // __STDC_FORMAT_MACROS ]
275 |
276 | // 7.8.2 Functions for greatest-width integer types
277 |
278 | // 7.8.2.1 The imaxabs function
279 | #define imaxabs _abs64
280 |
281 | // 7.8.2.2 The imaxdiv function
282 |
283 | // This is modified version of div() function from Microsoft's div.c found
284 | // in %MSVC.NET%\crt\src\div.c
285 | #ifdef STATIC_IMAXDIV // [
286 | static
287 | #else // STATIC_IMAXDIV ][
288 | _inline
289 | #endif // STATIC_IMAXDIV ]
290 | imaxdiv_t __cdecl imaxdiv(intmax_t numer, intmax_t denom)
291 | {
292 | imaxdiv_t result;
293 |
294 | result.quot = numer / denom;
295 | result.rem = numer % denom;
296 |
297 | if (numer < 0 && result.rem > 0) {
298 | // did division wrong; must fix up
299 | ++result.quot;
300 | result.rem -= denom;
301 | }
302 |
303 | return result;
304 | }
305 |
306 | // 7.8.2.3 The strtoimax and strtoumax functions
307 | #define strtoimax _strtoi64
308 | #define strtoumax _strtoui64
309 |
310 | // 7.8.2.4 The wcstoimax and wcstoumax functions
311 | #define wcstoimax _wcstoi64
312 | #define wcstoumax _wcstoui64
313 |
314 | #endif // _MSC_VER >= 1800
315 |
316 | #endif // _MSC_INTTYPES_H_ ]
317 |
--------------------------------------------------------------------------------
/ImageProc/include/rapidjson/prettywriter.h:
--------------------------------------------------------------------------------
1 | // Tencent is pleased to support the open source community by making RapidJSON available.
2 | //
3 | // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved.
4 | //
5 | // Licensed under the MIT License (the "License"); you may not use this file except
6 | // in compliance with the License. You may obtain a copy of the License at
7 | //
8 | // http://opensource.org/licenses/MIT
9 | //
10 | // Unless required by applicable law or agreed to in writing, software distributed
11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
13 | // specific language governing permissions and limitations under the License.
14 |
15 | #ifndef RAPIDJSON_PRETTYWRITER_H_
16 | #define RAPIDJSON_PRETTYWRITER_H_
17 |
18 | #include "writer.h"
19 |
20 | #ifdef __GNUC__
21 | RAPIDJSON_DIAG_PUSH
22 | RAPIDJSON_DIAG_OFF(effc++)
23 | #endif
24 |
25 | RAPIDJSON_NAMESPACE_BEGIN
26 |
27 | //! Writer with indentation and spacing.
28 | /*!
29 | \tparam OutputStream Type of ouptut os.
30 | \tparam SourceEncoding Encoding of source string.
31 | \tparam TargetEncoding Encoding of output stream.
32 | \tparam StackAllocator Type of allocator for allocating memory of stack.
33 | */
34 | template, typename TargetEncoding = UTF8<>, typename StackAllocator = CrtAllocator>
35 | class PrettyWriter : public Writer {
36 | public:
37 | typedef Writer Base;
38 | typedef typename Base::Ch Ch;
39 |
40 | //! Constructor
41 | /*! \param os Output stream.
42 | \param allocator User supplied allocator. If it is null, it will create a private one.
43 | \param levelDepth Initial capacity of stack.
44 | */
45 | PrettyWriter(OutputStream& os, StackAllocator* allocator = 0, size_t levelDepth = Base::kDefaultLevelDepth) :
46 | Base(os, allocator, levelDepth), indentChar_(' '), indentCharCount_(4) {}
47 |
48 | //! Set custom indentation.
49 | /*! \param indentChar Character for indentation. Must be whitespace character (' ', '\\t', '\\n', '\\r').
50 | \param indentCharCount Number of indent characters for each indentation level.
51 | \note The default indentation is 4 spaces.
52 | */
53 | PrettyWriter& SetIndent(Ch indentChar, unsigned indentCharCount) {
54 | RAPIDJSON_ASSERT(indentChar == ' ' || indentChar == '\t' || indentChar == '\n' || indentChar == '\r');
55 | indentChar_ = indentChar;
56 | indentCharCount_ = indentCharCount;
57 | return *this;
58 | }
59 |
60 | /*! @name Implementation of Handler
61 | \see Handler
62 | */
63 | //@{
64 |
65 | bool Null() { PrettyPrefix(kNullType); return Base::WriteNull(); }
66 | bool Bool(bool b) { PrettyPrefix(b ? kTrueType : kFalseType); return Base::WriteBool(b); }
67 | bool Int(int i) { PrettyPrefix(kNumberType); return Base::WriteInt(i); }
68 | bool Uint(unsigned u) { PrettyPrefix(kNumberType); return Base::WriteUint(u); }
69 | bool Int64(int64_t i64) { PrettyPrefix(kNumberType); return Base::WriteInt64(i64); }
70 | bool Uint64(uint64_t u64) { PrettyPrefix(kNumberType); return Base::WriteUint64(u64); }
71 | bool Double(double d) { PrettyPrefix(kNumberType); return Base::WriteDouble(d); }
72 |
73 | bool String(const Ch* str, SizeType length, bool copy = false) {
74 | (void)copy;
75 | PrettyPrefix(kStringType);
76 | return Base::WriteString(str, length);
77 | }
78 |
79 | #if RAPIDJSON_HAS_STDSTRING
80 | bool String(const std::basic_string& str) {
81 | return String(str.data(), SizeType(str.size()));
82 | }
83 | #endif
84 |
85 | bool StartObject() {
86 | PrettyPrefix(kObjectType);
87 | new (Base::level_stack_.template Push()) typename Base::Level(false);
88 | return Base::WriteStartObject();
89 | }
90 |
91 | bool Key(const Ch* str, SizeType length, bool copy = false) { return String(str, length, copy); }
92 |
93 | bool EndObject(SizeType memberCount = 0) {
94 | (void)memberCount;
95 | RAPIDJSON_ASSERT(Base::level_stack_.GetSize() >= sizeof(typename Base::Level));
96 | RAPIDJSON_ASSERT(!Base::level_stack_.template Top()->inArray);
97 | bool empty = Base::level_stack_.template Pop(1)->valueCount == 0;
98 |
99 | if (!empty) {
100 | Base::os_->Put('\n');
101 | WriteIndent();
102 | }
103 | bool ret = Base::WriteEndObject();
104 | (void)ret;
105 | RAPIDJSON_ASSERT(ret == true);
106 | if (Base::level_stack_.Empty()) // end of json text
107 | Base::os_->Flush();
108 | return true;
109 | }
110 |
111 | bool StartArray() {
112 | PrettyPrefix(kArrayType);
113 | new (Base::level_stack_.template Push()) typename Base::Level(true);
114 | return Base::WriteStartArray();
115 | }
116 |
117 | bool EndArray(SizeType memberCount = 0) {
118 | (void)memberCount;
119 | RAPIDJSON_ASSERT(Base::level_stack_.GetSize() >= sizeof(typename Base::Level));
120 | RAPIDJSON_ASSERT(Base::level_stack_.template Top()->inArray);
121 | bool empty = Base::level_stack_.template Pop(1)->valueCount == 0;
122 |
123 | if (!empty) {
124 | Base::os_->Put('\n');
125 | WriteIndent();
126 | }
127 | bool ret = Base::WriteEndArray();
128 | (void)ret;
129 | RAPIDJSON_ASSERT(ret == true);
130 | if (Base::level_stack_.Empty()) // end of json text
131 | Base::os_->Flush();
132 | return true;
133 | }
134 |
135 | //@}
136 |
137 | /*! @name Convenience extensions */
138 | //@{
139 |
140 | //! Simpler but slower overload.
141 | bool String(const Ch* str) { return String(str, internal::StrLen(str)); }
142 | bool Key(const Ch* str) { return Key(str, internal::StrLen(str)); }
143 |
144 | //@}
145 | protected:
146 | void PrettyPrefix(Type type) {
147 | (void)type;
148 | if (Base::level_stack_.GetSize() != 0) { // this value is not at root
149 | typename Base::Level* level = Base::level_stack_.template Top();
150 |
151 | if (level->inArray) {
152 | if (level->valueCount > 0) {
153 | Base::os_->Put(','); // add comma if it is not the first element in array
154 | Base::os_->Put('\n');
155 | }
156 | else
157 | Base::os_->Put('\n');
158 | WriteIndent();
159 | }
160 | else { // in object
161 | if (level->valueCount > 0) {
162 | if (level->valueCount % 2 == 0) {
163 | Base::os_->Put(',');
164 | Base::os_->Put('\n');
165 | }
166 | else {
167 | Base::os_->Put(':');
168 | Base::os_->Put(' ');
169 | }
170 | }
171 | else
172 | Base::os_->Put('\n');
173 |
174 | if (level->valueCount % 2 == 0)
175 | WriteIndent();
176 | }
177 | if (!level->inArray && level->valueCount % 2 == 0)
178 | RAPIDJSON_ASSERT(type == kStringType); // if it's in object, then even number should be a name
179 | level->valueCount++;
180 | }
181 | else {
182 | RAPIDJSON_ASSERT(!Base::hasRoot_); // Should only has one and only one root.
183 | Base::hasRoot_ = true;
184 | }
185 | }
186 |
187 | void WriteIndent() {
188 | size_t count = (Base::level_stack_.GetSize() / sizeof(typename Base::Level)) * indentCharCount_;
189 | PutN(*Base::os_, indentChar_, count);
190 | }
191 |
192 | Ch indentChar_;
193 | unsigned indentCharCount_;
194 |
195 | private:
196 | // Prohibit copy constructor & assignment operator.
197 | PrettyWriter(const PrettyWriter&);
198 | PrettyWriter& operator=(const PrettyWriter&);
199 | };
200 |
201 | RAPIDJSON_NAMESPACE_END
202 |
203 | #ifdef __GNUC__
204 | RAPIDJSON_DIAG_POP
205 | #endif
206 |
207 | #endif // RAPIDJSON_RAPIDJSON_H_
208 |
--------------------------------------------------------------------------------
/ImageProc/include/rapidjson/stringbuffer.h:
--------------------------------------------------------------------------------
1 | // Tencent is pleased to support the open source community by making RapidJSON available.
2 | //
3 | // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved.
4 | //
5 | // Licensed under the MIT License (the "License"); you may not use this file except
6 | // in compliance with the License. You may obtain a copy of the License at
7 | //
8 | // http://opensource.org/licenses/MIT
9 | //
10 | // Unless required by applicable law or agreed to in writing, software distributed
11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
13 | // specific language governing permissions and limitations under the License.
14 |
15 | #ifndef RAPIDJSON_STRINGBUFFER_H_
16 | #define RAPIDJSON_STRINGBUFFER_H_
17 |
18 | #include "rapidjson.h"
19 |
20 | #if RAPIDJSON_HAS_CXX11_RVALUE_REFS
21 | #include // std::move
22 | #endif
23 |
24 | #include "internal/stack.h"
25 |
26 | RAPIDJSON_NAMESPACE_BEGIN
27 |
28 | //! Represents an in-memory output stream.
29 | /*!
30 | \tparam Encoding Encoding of the stream.
31 | \tparam Allocator type for allocating memory buffer.
32 | \note implements Stream concept
33 | */
34 | template
35 | class GenericStringBuffer {
36 | public:
37 | typedef typename Encoding::Ch Ch;
38 |
39 | GenericStringBuffer(Allocator* allocator = 0, size_t capacity = kDefaultCapacity) : stack_(allocator, capacity) {}
40 |
41 | #if RAPIDJSON_HAS_CXX11_RVALUE_REFS
42 | GenericStringBuffer(GenericStringBuffer&& rhs) : stack_(std::move(rhs.stack_)) {}
43 | GenericStringBuffer& operator=(GenericStringBuffer&& rhs) {
44 | if (&rhs != this)
45 | stack_ = std::move(rhs.stack_);
46 | return *this;
47 | }
48 | #endif
49 |
50 | void Put(Ch c) { *stack_.template Push() = c; }
51 | void Flush() {}
52 |
53 | void Clear() { stack_.Clear(); }
54 | void ShrinkToFit() {
55 | // Push and pop a null terminator. This is safe.
56 | *stack_.template Push() = '\0';
57 | stack_.ShrinkToFit();
58 | stack_.template Pop(1);
59 | }
60 | Ch* Push(size_t count) { return stack_.template Push(count); }
61 | void Pop(size_t count) { stack_.template Pop(count); }
62 |
63 | const Ch* GetString() const {
64 | // Push and pop a null terminator. This is safe.
65 | *stack_.template Push() = '\0';
66 | stack_.template Pop(1);
67 |
68 | return stack_.template Bottom();
69 | }
70 |
71 | size_t GetSize() const { return stack_.GetSize(); }
72 |
73 | static const size_t kDefaultCapacity = 256;
74 | mutable internal::Stack stack_;
75 |
76 | private:
77 | // Prohibit copy constructor & assignment operator.
78 | GenericStringBuffer(const GenericStringBuffer&);
79 | GenericStringBuffer& operator=(const GenericStringBuffer&);
80 | };
81 |
82 | //! String buffer with UTF8 encoding
83 | typedef GenericStringBuffer > StringBuffer;
84 |
85 | //! Implement specialized version of PutN() with memset() for better performance.
86 | template<>
87 | inline void PutN(GenericStringBuffer >& stream, char c, size_t n) {
88 | std::memset(stream.stack_.Push(n), c, n * sizeof(c));
89 | }
90 |
91 | RAPIDJSON_NAMESPACE_END
92 |
93 | #endif // RAPIDJSON_STRINGBUFFER_H_
94 |
--------------------------------------------------------------------------------
/ImageProc/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | OpenCV in Chrome using NaCl
5 |
6 |
7 |
8 |
9 |
OpenCV in Chrome using NaCl
10 |
11 |
This page uses
13 | Google Native Client to tie in to the C++ OpenCV computer vision library.
15 | This allows realtime image processing of the webcam feed from within the
16 | browser.
17 |
18 | NB: No data is sent back to this website.
19 |
20 |
21 |
Requires Chrome web browser version 44 or above (not Android app)